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

92 lines (91 loc) • 2.64 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/. // #484: stamp schemaVersion + shape discriminator on passthrough envelopes so // third-party consumers can pin a schema version and dispatch on shape uniformly. // #918: also stamp `ok: true` so a caller branching on `.ok` sees the same // field on every success envelope that it sees on the `{ok:false,...}` error // envelope. Never overwrites an existing `shape`, `schemaVersion`, or `ok`; // a command whose exit code grades the outcome emits through // `outputWithExitCode` (src/cli/shared.ts), which sets `ok` from that code. function makeStampHandler(command) { return (result) => { if (result === null || result === undefined) return result; if (typeof result !== "object" || Array.isArray(result)) return result; const obj = result; return { // `ok` first so it heads the printed envelope instead of trailing a // (possibly large) dump — the spread below still wins with `obj`'s own // `ok` value when present, only its position is fixed here. ok: obj.ok ?? true, ...obj, shape: obj.shape ?? command, schemaVersion: obj.schemaVersion ?? 1, }; }; } const PASSTHROUGH_COMMANDS = [ "add", "agent-result", "bundle-create", "bundle-rename", "bundle-show", "clone", "command-dry-run", "config", "config-diff", "env-create", "env-export", "env-remove", "feedback", "extract", "health", "improve", "improve-judge", "improve-report", "import", "index", "info", "lint", "list", "models", "proposal-accept-batch", "proposal-drain", "proposal-reject-batch", "proposal-reopen-batch", "proposal-revert", "registry-add", "registry-list", "registry-remove", "remember", "remove", "secret-set", "setup", "sync", "task-add", "task-disable", "task-doctor", "task-enable", "task-explain", "task-history", "task-prune", "task-run", "task-sync", "task-sync-dry-run", "task-validate", "update", "upgrade", "workflow-abandon", "workflow-create", "workflow-list", "workflow-plan", "workflow-resume", "workflow-run", "workflow-status", ]; export const passthroughShapes = PASSTHROUGH_COMMANDS.map((command) => ({ command, handler: makeStampHandler(command), }));