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
83 lines (82 loc) • 2.76 kB
JavaScript
// 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 { capDescription, NORMAL_DESCRIPTION_LIMIT, pickFields } from "./helpers.js";
// Curation is a small, high-signal top-N. Even at `brief` we keep `followUp`
// (the actionable `akm show <ref>` command) and `reason` (why this asset was
// selected) — these are the point of curate, unlike a bulk search listing.
const BRIEF_FIELDS = ["source", "type", "name", "ref", "id", "supportRefs", "followUp", "reason"];
const NORMAL_FIELDS = [
"source",
"type",
"name",
"ref",
"path",
"editable",
"editHint",
"id",
"description",
"preview",
"keys",
"parameters",
"run",
"supportRefs",
"followUp",
"reason",
"score",
];
// Agent shape: the minimal field set an LLM needs to decide and act.
const AGENT_FIELDS = [
"source",
"type",
"name",
"ref",
"path",
"editable",
"editHint",
"id",
"description",
"supportRefs",
"followUp",
"reason",
"score",
];
function shapeCurateItem(item, detail, shape) {
if (shape === "agent") {
const shaped = pickFields(item, AGENT_FIELDS);
if (shaped.editable !== false)
delete shaped.editHint;
return capDescription(shaped, NORMAL_DESCRIPTION_LIMIT);
}
if (detail === "brief") {
return pickFields(item, BRIEF_FIELDS);
}
if (detail === "normal") {
return capDescription(pickFields(item, NORMAL_FIELDS), NORMAL_DESCRIPTION_LIMIT);
}
// full: project everything the curator emits.
return item;
}
export function shapeCurateOutput(result, detail, shape) {
const items = Array.isArray(result.items) ? result.items : [];
const shapedItems = items.map((item) => shapeCurateItem(item, detail, shape));
const base = {
// `shape`/`schemaVersion` discriminators preserve the prior passthrough
// envelope contract (#484) so consumers can pin a schema version.
schemaVersion: typeof result.schemaVersion === "number" ? result.schemaVersion : 1,
shape: "curate",
query: result.query,
summary: result.summary,
items: shapedItems,
...(typeof result.searchMode === "string" ? { searchMode: result.searchMode } : {}),
...(Array.isArray(result.warnings) && result.warnings.length > 0 ? { warnings: result.warnings } : {}),
...(result.tip ? { tip: result.tip } : {}),
};
return base;
}
export const curateShapes = [
{
command: "curate",
handler: (result, detail, shape) => shapeCurateOutput(result, detail, shape),
},
];