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
45 lines (44 loc) • 1.82 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 { registerMdRenderer } from "../../output/render-registry.js";
import { buildMetricsView, isMetricsResult } from "./report-view.js";
/** Escape a cell so a query or reason containing `|` or a newline cannot break the table. */
function cell(value) {
return value.replace(/\\/g, "\\\\").replace(/\|/g, "\\|").replace(/\r?\n/g, " ");
}
function renderTable(table) {
const row = (cells) => `| ${cells.map(cell).join(" | ")} |`;
return [
`### ${table.title}`,
"",
row(table.headers),
row(table.headers.map(() => "---")),
...table.rows.map(row),
"",
];
}
export function renderMetricsMd(result, detail) {
if (!isMetricsResult(result))
return null;
const view = buildMetricsView(result, detail);
const lines = ["# akm metrics", "", `- **Window:** ${view.window}`, `- **Filters:** ${view.filters}`, ""];
for (const section of view.sections) {
lines.push(`## ${section.title}`, "");
for (const [label, value] of section.facts)
lines.push(`- **${label}:** ${value}`);
if (section.facts.length > 0)
lines.push("");
for (const table of section.tables) {
if (table.rows.length > 0)
lines.push(...renderTable(table));
else if (!table.hideWhenEmpty)
lines.push(`### ${table.title}`, "", "_none_", "");
}
}
if (view.notes.length > 0) {
lines.push("## Notes", "", ...view.notes.map((n) => `- ${n}`), "");
}
return lines.join("\n").trimEnd();
}
registerMdRenderer("metrics", renderMetricsMd);