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

63 lines (62 loc) • 3.06 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/. /** * Map every top-level task source v4 execution control and D2-N7 survivor * into v3's `akm.*` shape, one field at a time (never a whole-object copy, * so a field task source v4 does not represent — such as `inputs` — can * never leak in by accident). Returns `undefined` when * nothing maps, matching v3's own * convention of omitting the `akm` key entirely rather than emitting an * always-present empty object (`source-v3.ts:789`). */ function projectAkm(document) { const out = {}; if (document.description !== undefined) out.description = document.description; if (document.when_to_use !== undefined) out.when_to_use = document.when_to_use; if (document.tags !== undefined) out.tags = document.tags; const execution = document.execution; if (execution.agent !== undefined) out.agent = execution.agent; if (execution.engine !== undefined) out.engine = execution.engine; if (execution.model !== undefined) out.model = execution.model; if (execution.inference !== undefined) out.inference = execution.inference; if (execution.tools !== undefined) out.tools = execution.tools; if (execution.timeout !== undefined) out.timeout = execution.timeout; if (execution.redact !== undefined) out.redact = execution.redact; if (execution.maxSteps !== undefined) out.maxSteps = execution.maxSteps; if (execution.maxRetries !== undefined) out.maxRetries = execution.maxRetries; if (document.output !== undefined) out.outputSchema = document.output; return Object.keys(out).length > 0 ? Object.freeze(out) : undefined; } /** Project one parsed task source v4 document into the prepare seam's existing input shape (spec §3.5). */ export function projectTaskSourceV4(document) { const akm = projectAkm(document); const schedules = Object.freeze(document.schedule.map((entry) => Object.freeze({ cron: entry.cron, source: entry.source, ordinal: entry.ordinal }))); return Object.freeze({ // The literal `3` is the prepare seam's own discriminant // (PreparableTaskDocument = TaskV3SourceDocument), not an assertion that // the source this was projected from was task v3 — `TASK_V3_SCHEMA_VERSION` // is gone (P4 deleted task v3 acceptance from src), and this projection // only ever runs on a task source v4 document (P2a §3.5's recorded wart). version: 3, ...(document.name !== undefined ? { name: document.name } : {}), target: document.target, ...(document.env !== undefined ? { env: document.env } : {}), ...(akm !== undefined ? { akm } : {}), triggers: Object.freeze({ manual: document.manualOnly, schedules }), source: Object.freeze({ path: document.source.path }), }); }