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
38 lines (37 loc) • 1.52 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/.
/**
* An asset's own retrieval queries from the usage log, cleaned for replay.
* The consolidate continuity check replays them against a retiring asset's
* successor.
*/
import { nonTaskInput } from "../../core/non-task-input.js";
import { listRetrievalQueries } from "../../indexer/usage/usage-events.js";
import { readLedgerDb, stripBundle } from "./ledger.js";
/** Queries kept per asset. */
const MAX_QUERIES = 5;
/** The retrieval suite treats a longer input as a paste, not a query. */
const MAX_QUERY_CHARS = 2000;
/** Up to five distinct task queries, in the given order, whitespace collapsed. */
export function usableRetrievalQueries(raw) {
const out = [];
for (const text of raw) {
const query = text.replace(/\s+/g, " ").trim();
if (!query || query.length > MAX_QUERY_CHARS || nonTaskInput(query) || out.includes(query))
continue;
out.push(query);
if (out.length === MAX_QUERIES)
break;
}
return out;
}
/** The asset's own retrieval queries from the usage log (none when state.db cannot be read). */
export function loadRetrievalQueries(access, ref) {
try {
return usableRetrievalQueries(readLedgerDb(access, (db) => listRetrievalQueries(db, stripBundle(ref))) ?? []);
}
catch {
return [];
}
}