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

93 lines (92 loc) • 4.18 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 { defineGroupCommand, defineJsonCommand, EXIT_CODES, outputWithExitCode } from "../cli/shared.js"; import { noteUsage, setUsageErrorCode } from "../cli/usage-kinds.js"; import { stderr } from "../core/stdio.js"; import { runMigrationTool } from "./migration-tool.js"; /** * `akm migrate` is a thin wrapper over the standalone `akm-migrate` * executable, which owns every migration step and every historical shape * (`scripts/akm-migrate/`). This module only spawns it, re-emits its one JSON * plan through the normal output pipeline so `--format` applies, and mirrors * its exit code. `akm upgrade` calls the same executable after an install. * Passed the runner as a parameter so a test can hand it a stand-in. */ export async function runMigrateSubcommand(command, args, runTool = runMigrationTool) { const result = await runTool(args); if (result.stderr) stderr().write(result.stderr); const line = result.stdout.trim(); let plan; try { plan = line ? JSON.parse(line) : undefined; } catch { plan = undefined; } if (plan) { outputWithExitCode(command, plan, result.status, plan.status === "blocked" ? "MIGRATION_BLOCKED" : undefined); return; } if (line) console.log(line); if (result.status !== EXIT_CODES.SUCCESS) process.exitCode = result.status; // The child's own reason, for the usage report: what it printed is already on stderr above. setUsageErrorCode(result.outcome?.code); noteUsage(...(result.outcome?.notes ?? [])); } export const migrateCommand = defineGroupCommand({ meta: { name: "migrate", description: "Inspect or apply pending migrations: config, state.db, task files, and named task and workflow files to version 5", }, subCommands: { status: defineJsonCommand({ meta: { name: "status", description: "Read-only check of every pending migration; for task and workflow files named after it, what apply would convert to version 5", }, args: { files: { type: "positional", required: false, description: "Task files or workflow files (workflows/<name>.md) to check for conversion to version 5", }, "read-only": { type: "boolean", default: false, description: "Records no CLI usage, so the invocation writes nothing at all", }, }, run({ args }) { return runMigrateSubcommand("migrate-status", ["status", ...args._.map(String)]); }, }), apply: defineJsonCommand({ meta: { name: "apply", description: "Back up and apply every pending migration (`akm upgrade` runs this after an install); task files named after it are converted to version 5, and a workflow file named after it (workflows/<name>.md) becomes a new task file", }, args: { files: { type: "positional", required: false, description: "Task files or workflow files (workflows/<name>.md) to convert to version 5", }, "dry-run": { type: "boolean", default: false, description: "Deprecated: use `akm migrate status`. Run the same eligibility checks without mutation.", }, }, run({ args }) { const files = args._.map(String); return runMigrateSubcommand("migrate-apply", ["apply", ...(args.dryRun ? ["--dry-run"] : []), ...files]); }, }), }, // No `defaultRun`: bare `akm migrate` is a usage error (exit 2), the // canonical bare-group behavior shared with every other group. });