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
51 lines (50 loc) • 2.33 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 { cloneExecutionJsonObject } from "../execution/json.js";
import { buildExecution, resolveExecution } from "../integrations/agent/execution.js";
const NO_LOWERING_NOTICES = Object.freeze([]);
function own(value, key) {
return value !== undefined && Object.hasOwn(value, key);
}
/** Adapt one index invocation layer into the shared execution vocabulary. */
function indexExecutionDefaults(layer) {
if (!layer)
return {};
return {
...(own(layer, "engine") ? { engine: layer.engine } : {}),
...(own(layer, "model") ? { model: layer.model } : {}),
...(own(layer, "timeoutMs") ? { timeout: layer.timeoutMs } : {}),
...(own(layer, "llm") && layer.llm !== undefined
? { inference: cloneExecutionJsonObject(layer.llm, "index pass LLM inference") }
: {}),
};
}
/**
* Resolve standalone index passes from the index section only. Improve
* strategies own improve-triggered calls and are intentionally not consulted.
*/
export function resolveIndexPassExecution(passName, config) {
const pass = config.index?.[passName];
if (pass?.enabled === false)
return Object.freeze({ runner: undefined, notices: NO_LOWERING_NOTICES });
const defaults = config.index?.defaults;
const fallbackLlmEngine = config.defaults?.llmEngine;
const selectedEngine = pass?.engine ?? defaults?.engine ?? fallbackLlmEngine;
if (!selectedEngine)
return Object.freeze({ runner: undefined, notices: NO_LOWERING_NOTICES });
const invocationDefaults = {
...indexExecutionDefaults(defaults),
...(!own(defaults, "engine") && fallbackLlmEngine ? { engine: fallbackLlmEngine } : {}),
};
// Under the model-work tool policy, so an engine that cannot confine it is refused here.
const prepared = resolveExecution({
content: "",
config,
invocationDefaults,
current: indexExecutionDefaults(pass),
modelWork: true,
});
const lowered = buildExecution(prepared.request, prepared.runner);
return Object.freeze({ runner: lowered.runner, notices: lowered.notices });
}