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
54 lines (53 loc) • 1.86 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/.
// ── Registry ─────────────────────────────────────────────────────────────────
/** Renderer lookup by name. */
const renderers = new Map();
/**
* Ensure that all built-in indexer contributors are registered.
*
* Delegates to the single `initIndexer()` composition root (see
* `src/indexer/init.ts`). Imported dynamically to keep this a lazy gate and to
* avoid a static import cycle (init -> renderers -> file-context). Called on
* first use of getRenderer/getAllRenderers; idempotent.
*/
async function ensureBuiltinsRegistered() {
const { initIndexer } = await import("../indexer/init.js");
await initIndexer();
}
/**
* Register an AssetRenderer.
*
* If a renderer with the same name already exists it is silently replaced.
*/
export function registerRenderer(renderer) {
renderers.set(renderer.name, renderer);
}
/**
* Look up a renderer by name.
*/
export async function getRenderer(name) {
await ensureBuiltinsRegistered();
return renderers.get(name);
}
/**
* Return all registered renderers (snapshot, safe to iterate).
*/
export async function getAllRenderers() {
await ensureBuiltinsRegistered();
return Array.from(renderers.values());
}
/**
* Build a RenderContext by merging a FileContext with its winning MatchResult
* and the list of stash search paths.
*/
export function buildRenderContext(ctx, match, stashDirs, origin, defaultBundle) {
return {
...ctx,
matchResult: match,
stashDirs,
origin,
defaultBundle,
};
}