UNPKG

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

51 lines (50 loc) • 2.56 kB
// 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/. import { createHash } from "node:crypto"; import { prepareCommandInvocation } from "../../../commands/command/command-execution.js"; import { canonicalResolvedExecutionRequest, } from "../../../execution/resolved-request.js"; import { buildExecution } from "../../../integrations/agent/execution.js"; import { freezeEnvironment } from "../environment.js"; import { durableRequest, executionUnitValues, targetConcurrency, } from "../step-values.js"; export async function commandDispatch(source, baseUnit, action, context) { const prepared = await prepareCommandInvocation({ action, config: context.config, ...(context.plan.defaults ? { invocationDefaults: executionUnitValues(context.plan.defaults) } : {}), inlineContentMode: "literal", current: executionUnitValues(source.unit), }); return commandResult(source, baseUnit, prepared); } export function commandResult(source, baseUnit, prepared, literals = []) { const request = durableRequest(prepared.request); const lowered = buildExecution(request, prepared.runner); const runner = lowered.runner; const unit = { ...baseUnit, engine: request.target.name, ...(request.model ? { model: request.model.model } : {}), ...(Object.hasOwn(request.runtime, "timeoutMs") ? { timeoutMs: request.runtime.timeoutMs } : {}), ...(request.inference ? { llm: request.inference } : {}), ...(request.outputSchema ? { output: request.outputSchema } : {}), }; const environment = Object.freeze([...literals, ...freezeEnvironment(source, undefined)]); const target = Object.freeze({ kind: "command", ref: request.command.source?.ref ?? null, contentHash: createHash("sha256").update(request.command.content).digest("hex"), request: JSON.parse(canonicalResolvedExecutionRequest(request)), runner, ...(targetConcurrency(runner) ? { concurrency: targetConcurrency(runner) } : {}), // Not a location. akm 0.10.0 and earlier decode a command-only plan and run it in the invoking directory, // but their dispatch refuses a directory identity it cannot verify, so they stop here instead. cwdIdentity: {}, }); return { target, environment, unit, instructions: request.command.content, }; }