UNPKG

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

49 lines (48 loc) • 2.48 kB
// 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 { withoutTypeHead } from "../asset/asset-placement.js"; import { heldAssetRef } from "../asset/asset-ref.js"; import { warnOnce } from "../warn.js"; /** The bundle each asset was found in, for `assetType` to index it on a miss. Not part of the asset: no caller gets a root. */ const bundleOfAsset = new WeakMap(); export function assetOf(bundle, found) { const asset = { bundle: bundle.name, conceptId: found.conceptId, ref: heldAssetRef(bundle.name, found.conceptId), entry: found.entry, }; bundleOfAsset.set(asset, bundle); return asset; } /** The bundle that holds `asset`, as it was found. */ export function bundleHolding(asset) { const bundle = bundleOfAsset.get(asset); if (!bundle) throw new Error(`Asset "${asset.ref}" was not found through the asset facade.`); return bundle; } /** The asset `conceptId` names in one bundle, as its adapter reads it, with no other spelling tried. */ export function readExact(bundle, conceptId) { const found = bundle.read(conceptId); return found ? assetOf(bundle, found) : undefined; } /** * Releases before path refs prefixed a loose file's ref with its type folder (`knowledge/reports/x` for * `reports/x.md`), and that spelling is still in links, memories, scripts and stored proposals. A ref nothing holds is * read once more without that head and the asset comes back under its current ref. Whatever adapter holds the bundle: * the spelling is akm's, not the format's. Only `qualifyRef` (the input boundary) warns, once, for a ref the user typed. */ export function readOutdated(conceptId, read, warnUser = false) { const current = withoutTypeHead(conceptId); const found = current === undefined ? undefined : read(current); if (found && warnUser) { warnOnce(`outdated-ref:${conceptId}`, `Ref "${conceptId}" is outdated: refs are the path inside the bundle, so it is now "${found.conceptId}". Resolved it to that asset.`); } return found; } /** The asset `conceptId` names in a bundle already held (an outdated spelling of it too): `readAsset` without the id. */ export function readFrom(held, conceptId) { return readExact(held, conceptId) ?? readOutdated(conceptId, (current) => readExact(held, current)); }