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
69 lines (68 loc) • 2.88 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/.
/**
* The improve passes iterate index rows (a snapshot: its membership and order) and read each row's asset through the
* facade. A row whose asset no bundle holds any more, or whose bytes cannot be read, is a stale row: it reads as absent.
*/
import { makeBundleRef, parseBundleRef } from "../../core/asset/asset-ref.js";
import { bundleNameOf } from "../../core/assets/gate.js";
import { findAsset, lookupAsset } from "../../core/assets/read.js";
import { bundleAt } from "../../core/bundle-at-dir.js";
/** The asset an index row names, or undefined when no bundle holds it. A stored row is not the caller's to fix, so an outdated spelling resolves quietly. */
export function indexedAsset(bundleId, conceptId) {
try {
const ref = makeBundleRef(bundleId, conceptId);
return bundleId === undefined ? lookupAsset(ref) : findAsset(ref);
}
catch {
return undefined;
}
}
/** The text of the asset an index row names; undefined when it is gone or cannot be read. */
export function indexedContent(bundleId, conceptId) {
try {
return indexedAsset(bundleId, conceptId)?.entry.content();
}
catch {
return undefined;
}
}
/** When the asset an index row names last changed (ms); undefined when it is gone or its bundle does not know. */
export function indexedModifiedMs(bundleId, conceptId) {
try {
return indexedAsset(bundleId, conceptId)?.entry.modified?.().getTime();
}
catch {
return undefined;
}
}
/**
* The asset a planned ref names: its qualified spelling when the planner recorded one, else the ref as written (a
* qualified spelling no bundle holds any more is gone, not another bundle's copy), in the bundles of `stashDir` when given.
*/
export function plannedAsset(planned, stashDir) {
try {
const ref = planned.itemRef ?? planned.ref;
const bundle = stashDir === undefined ? undefined : bundleAt(stashDir);
if (parseBundleRef(ref).bundle !== undefined)
return findAsset(ref, bundle);
return lookupAsset(ref, bundle === undefined ? undefined : { bundle });
}
catch {
return undefined;
}
}
/** The asset `ref` names in the bundle at `stashDir` (a ref that names another bundle is not found here). */
export function assetInStash(stashDir, ref) {
try {
const bundle = bundleAt(stashDir);
const parsed = parseBundleRef(ref);
if (parsed.bundle !== undefined && parsed.bundle !== bundleNameOf(bundle))
return undefined;
return findAsset(makeBundleRef(bundleNameOf(bundle), parsed.conceptId), bundle);
}
catch {
return undefined;
}
}