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

48 lines (47 loc) • 2.38 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 { deepMergeConfig } from "../../core/config/deep-merge.js"; import { buildExecution, resolveExecution } from "../../integrations/agent/execution.js"; function own(value, key) { return value !== undefined && Object.hasOwn(value, key); } function cascadeDefaults(layer) { if (!layer) return {}; return { ...(own(layer, "engine") ? { engine: layer.engine } : {}), ...(own(layer, "model") ? { model: layer.model } : {}), ...(own(layer, "llm") ? { inference: layer.llm } : {}), ...(own(layer, "timeoutMs") ? { timeout: layer.timeoutMs ?? null } : {}), }; } function mergeDefaults(farther, nearer) { return deepMergeConfig(farther, nearer); } /** * Resolve improve-owned model work through the canonical execution cascade: * defaults.llmEngine -> strategy -> index.<pass> -> process -> current invocation. * The engine may be of any kind that confines the model-work tool policy: one * that cannot, chosen with `--engine` say, is refused here, before any work. */ export function resolveImproveExecution(options) { const defaultEngine = options.config.defaults?.llmEngine; const profileDefaults = cascadeDefaults(options.profile); const indexDefaults = cascadeDefaults(options.index); const processDefaults = cascadeDefaults(options.process); const currentDefaults = cascadeDefaults(options.current); const selectedEngine = currentDefaults.engine ?? processDefaults.engine ?? indexDefaults.engine ?? profileDefaults.engine ?? defaultEngine; if (selectedEngine === undefined || selectedEngine === null) return null; const invocationDefaults = mergeDefaults(mergeDefaults(defaultEngine ? { engine: defaultEngine } : {}, profileDefaults), indexDefaults); const prepared = resolveExecution({ content: `improve ${options.processName} execution selection`, config: options.config, invocationDefaults, current: mergeDefaults(processDefaults, currentDefaults), modelWork: true, }); const lowered = buildExecution(prepared.request, prepared.runner); return Object.freeze({ runner: lowered.runner, notices: lowered.notices }); }