akm-cli
Version:
akm (Agent Knowledge Manager) — a portable, local-first capability library for AI agents. Discover, load, share, and improve reusable skills, scripts, workflows, and knowledge across any shell-capable coding agent, including Claude Code, OpenCode, and Cur
44 lines (43 loc) • 2.01 kB
JavaScript
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
/**
* Agent command builder strategy (v1 spec §12.2).
*
* Each supported agent CLI platform has its own `AgentCommandBuilder` that
* translates a platform-agnostic `AgentDispatchRequest` into the exact argv
* the CLI expects. This keeps all per-platform arg differences out of the
* spawn wrapper and profiles.
*
* Adding a new platform: implement `AgentCommandBuilder`, add to
* `BUILTIN_BUILDERS`. Nothing else changes.
*/
import { ConfigError } from "../../core/errors.js";
import { HARNESS_REGISTRY } from "../harnesses/index.js";
// ── Registry ──────────────────────────────────────────────────────────────────
/**
* DERIVED from `HARNESS_REGISTRY` (P0.5 registry-drift fix): each harness that
* owns an `agentBuilder` is registered under its canonical id. Named engines
* are schema-validated to canonical harness ids before reaching this boundary.
*/
const BUILTIN_BUILDERS = (() => {
const registry = {};
for (const harness of HARNESS_REGISTRY) {
if (!harness.agentBuilder)
continue;
registry[harness.id] = harness.agentBuilder;
}
return Object.freeze(registry);
})();
/**
* Return the builder for the given platform name.
*
* Unknown platforms are rejected: there is no safe generic CLI flag shape.
* Custom builders injected by tests can be passed as `registry`.
*/
export function getCommandBuilder(platform, registry = BUILTIN_BUILDERS) {
const found = registry[platform];
if (found)
return found;
throw new ConfigError(`Agent platform "${platform}" has no registered command builder.`, "INVALID_CONFIG_FILE", "Select a canonical agent platform in engines.<name>.platform.");
}