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

67 lines (66 loc) • 2.67 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 { 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) process.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); return; } if (line) console.log(line); if (result.status !== EXIT_CODES.SUCCESS) process.exitCode = result.status; } export const migrateCommand = defineGroupCommand({ meta: { name: "migrate", description: "Inspect or apply pending migrations: legacy config, state.db, and task-v2/v3 sources to v4", }, subCommands: { status: defineJsonCommand({ meta: { name: "status", description: "Read-only check of every pending migration" }, run() { return runMigrateSubcommand("migrate-status", ["status"]); }, }), apply: defineJsonCommand({ meta: { name: "apply", description: "Back up and apply every pending migration (`akm upgrade` runs this after an install)", }, args: { "dry-run": { type: "boolean", default: false, description: "Run the same eligibility checks without mutation.", }, }, run({ args }) { return runMigrateSubcommand("migrate-apply", args.dryRun ? ["apply", "--dry-run"] : ["apply"]); }, }), }, // No `defaultRun`: bare `akm migrate` is a usage error (exit 2), the // canonical bare-group behavior shared with every other group. });