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
104 lines (103 loc) • 4.67 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 { appendShowDirectives } from "./show-directives.js";
export function formatShowPlain(r, detail) {
const lines = [];
if (r.type || r.name) {
lines.push(`# ${String(r.type ?? "asset")}: ${String(r.name ?? "unknown")}`);
}
if (r.path && r.editable !== false) {
lines.push(`file: ${String(r.path)}`);
}
if (r.origin !== undefined)
lines.push(`# origin: ${String(r.origin)}`);
if (r.action)
lines.push(`# ${String(r.action)}`);
if (Array.isArray(r.keys)) {
const keys = r.keys.map(String);
lines.push(keys.length > 0 ? `keys: ${keys.join(", ")}` : "(no keys)");
}
if (r.description)
lines.push(`description: ${String(r.description)}`);
if (r.workflowTitle)
lines.push(`workflowTitle: ${String(r.workflowTitle)}`);
if (r.agent)
lines.push(`agent: ${String(r.agent)}`);
if (Array.isArray(r.parameters) && r.parameters.length > 0)
lines.push(`parameters: ${r.parameters.join(", ")}`);
if (Array.isArray(r.workflowParameters) && r.workflowParameters.length > 0) {
lines.push("workflowParameters:");
for (const parameter of r.workflowParameters) {
const name = typeof parameter.name === "string" ? parameter.name : "unknown";
const description = typeof parameter.description === "string" && parameter.description.trim() ? `: ${parameter.description}` : "";
lines.push(` - ${name}${description}`);
}
}
if (r.modelHint != null)
lines.push(`modelHint: ${String(r.modelHint)}`);
if (r.toolPolicy != null)
lines.push(`toolPolicy: ${JSON.stringify(r.toolPolicy)}`);
if (r.run)
lines.push(`run: ${String(r.run)}`);
if (r.setup)
lines.push(`setup: ${String(r.setup)}`);
if (r.cwd)
lines.push(`cwd: ${String(r.cwd)}`);
if (detail === "full") {
if (r.path)
lines.push(`path: ${String(r.path)}`);
if (r.editable !== undefined)
lines.push(`editable: ${String(r.editable)}`);
if (r.editHint)
lines.push(`editHint: ${String(r.editHint)}`);
if (r.schemaVersion !== undefined)
lines.push(`schemaVersion: ${String(r.schemaVersion)}`);
}
const links = typeof r.links === "object" && r.links !== null ? r.links : undefined;
if (links) {
lines.push("");
lines.push("links:");
for (const part of ["outgoing", "incoming", "unresolved"]) {
const groups = links[part];
if (typeof groups !== "object" || groups === null)
continue;
lines.push(` ${part}:`);
for (const [kind, group] of Object.entries(groups)) {
const refs = Array.isArray(group.refs) ? group.refs.map(String) : [];
const more = (group.total ?? refs.length) > refs.length ? ` (+${(group.total ?? 0) - refs.length} more)` : "";
lines.push(` ${kind}: ${refs.join(", ")}${more}`);
}
}
}
const payloads = [r.content, r.template, r.prompt].filter((value) => value != null).map(String);
if (Array.isArray(r.steps) && r.steps.length > 0) {
if (lines.length > 0)
lines.push("");
lines.push("steps:");
for (const [index, step] of r.steps.entries()) {
const title = typeof step.title === "string" ? step.title : "Untitled step";
const id = typeof step.id === "string" ? step.id : "unknown";
lines.push(` ${index + 1}. ${title} [${id}]`);
if (typeof step.instructions === "string" && step.instructions.trim()) {
const instrLines = step.instructions.trim().split("\n");
lines.push(` instructions: ${instrLines[0]}`);
for (const instrLine of instrLines.slice(1))
lines.push(` ${instrLine}`);
}
if (Array.isArray(step.completionCriteria) && step.completionCriteria.length > 0) {
lines.push(" completion:");
for (const criterion of step.completionCriteria) {
lines.push(` - ${String(criterion)}`);
}
}
}
}
if (payloads.length > 0) {
if (lines.length > 0)
lines.push("");
lines.push(...payloads);
}
appendShowDirectives(lines, r);
return lines.length > 0 ? lines.join("\n") : null;
}