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

106 lines (105 loc) • 4.89 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 { writeStdout } from "./stdout.js"; import { addFormatters } from "./text/add.js"; import { bundleCreateFormatters } from "./text/bundle-create.js"; import { bundleRenameFormatters } from "./text/bundle-rename.js"; import { bundleShowFormatters } from "./text/bundle-show.js"; import { cloneFormatters } from "./text/clone.js"; import { configFormatters } from "./text/config.js"; import { curateFormatters } from "./text/curate.js"; import { envFormatters } from "./text/env.js"; import { eventsFormatters } from "./text/events.js"; import { feedbackFormatters } from "./text/feedback.js"; import { healthFormatters } from "./text/health.js"; import { importFormatters } from "./text/import.js"; import { improveReportFormatters } from "./text/improve-report.js"; import { indexFormatters } from "./text/index.js"; import { infoFormatters } from "./text/info.js"; import { lintFormatters } from "./text/lint.js"; import { listFormatters } from "./text/list.js"; import { migrateFormatters } from "./text/migrate.js"; import { modelsFormatters } from "./text/models.js"; import { proposalProducerFormatters } from "./text/proposal/producer.js"; import { proposalFormatters } from "./text/proposal/proposal.js"; import { getTextFormatterHandler, registerTextFormatters } from "./text/registry.js"; import { registryCommandFormatters } from "./text/registry-commands.js"; import { rememberFormatters } from "./text/remember.js"; import { removeFormatters } from "./text/remove.js"; import { searchFormatters } from "./text/search.js"; import { showFormatters } from "./text/show.js"; import { syncFormatters } from "./text/sync.js"; import { updateFormatters } from "./text/update.js"; import { upgradeFormatters } from "./text/upgrade.js"; import { workflowFormatters } from "./text/workflow.js"; // ── Explicit built-in formatter assembly ────────────────────────────────────── // Each entry below is a pure exported `TextFormatterEntry[]` from a per-command // module. The set is registered ONCE, deterministically, with no reliance on // import order. Removing a module from this list removes its registration — // and because each name is referenced statically, a deleted export fails to // compile instead of silently disappearing at runtime. const BUILT_IN_TEXT_FORMATTERS = [ ...bundleCreateFormatters, ...bundleRenameFormatters, ...bundleShowFormatters, ...indexFormatters, ...showFormatters, ...searchFormatters, ...curateFormatters, ...workflowFormatters, ...listFormatters, ...addFormatters, ...removeFormatters, ...updateFormatters, ...upgradeFormatters, ...cloneFormatters, ...eventsFormatters, ...proposalFormatters, ...proposalProducerFormatters, ...infoFormatters, ...healthFormatters, ...improveReportFormatters, ...lintFormatters, ...configFormatters, ...feedbackFormatters, ...rememberFormatters, ...importFormatters, ...syncFormatters, ...registryCommandFormatters, ...envFormatters, ...migrateFormatters, ...modelsFormatters, ]; registerTextFormatters(BUILT_IN_TEXT_FORMATTERS); // ── JSONL output (unchanged — not part of the formatPlain dispatch) ─────────── export function outputJsonl(command, shaped) { if (command === "search" || command === "registry-search") { const r = shaped; const hits = Array.isArray(r.hits) ? r.hits : []; for (const hit of hits) { writeStdout(JSON.stringify(hit)); } const registryHits = Array.isArray(r.registryHits) ? r.registryHits : []; for (const hit of registryHits) { writeStdout(JSON.stringify(hit)); } return; } // For non-search commands, output the whole object as a single JSONL line writeStdout(JSON.stringify(shaped)); } // ── Dispatcher ──────────────────────────────────────────────────────────────── /** * Return a plain-text string for commands that are better as short messages, * or null to fall through to the generic text rendering of the shaped * envelope (`renderGenericText`, applied in `output()` in * `src/cli/shared.ts` — this module stays dependency-free of that renderer). */ export function formatPlain(command, result, detail) { const handler = getTextFormatterHandler(command); if (handler) { return handler(result, detail); } return null; // fall through to the generic text renderer, not YAML }