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
53 lines (52 loc) • 2.43 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 { assetOf } from "./asset.js";
import { assetBundleOf, sourceBundle } from "./bundle.js";
/**
* What the bundle's adapter reports for the assets it lists, each checked as an `update` in the adapter's listing
* order; `keep` narrows them by their entries. This is `akm lint`'s scan of a bundle as it stands.
*/
export function validateBundleAssets(bundle, options = {}) {
const held = assetBundleOf(bundle);
const edits = held
.list()
.assets.filter(({ entry }) => options.keep === undefined || options.keep(entry))
.map(({ conceptId }) => ({ conceptId, op: "update" }));
return held.validate(edits, options.ctx ?? {});
}
/**
* What the keyrings and vaults among `sources` report about their stores, as the last `akm index` recorded it: the
* entries their adapters cannot list, and the names more than one entry holds. A bundle kept in files has none, and a
* store that cannot be reached, or fails, has nothing to report.
*/
export async function storeFindings(sources, ctx) {
const found = [];
for (const source of sources) {
if (source.unresolved)
continue;
try {
const held = assetBundleOf(sourceBundle(source));
if (!held.isStore)
continue;
const edits = held.list().assets.map(({ conceptId }) => ({ conceptId, op: "update" }));
found.push(...(await held.validate(edits, ctx)));
}
catch {
// A store that cannot be reached or fails has nothing to check: lint skips it silently, as in hooks and CI.
}
}
return found;
}
/** Every asset the bundle's adapter lists, one per concept, in the adapter's listing order. */
export function listBundleAssets(bundle) {
const held = assetBundleOf(bundle);
return held.list().assets.map((found) => assetOf(held, found));
}
/** The asset the bundle holds at the stored `key`, when it holds one there. */
export function assetAtStoredKey(bundle, key) {
const held = assetBundleOf(bundle);
const conceptId = held.identifyKey(key);
const found = conceptId === null ? undefined : held.read(conceptId);
return found?.entry.key === key ? assetOf(held, found) : undefined;
}