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

29 lines (28 loc) • 1.63 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/. /** * Unit scheduler: a policy layer over `concurrentMap`. The effective width is * the minimum of the map request, the frozen workflow cap, the LLM engine's * frozen cap, and the current host's CPU cap (reapplied, since a run may * resume on a smaller machine). Cancellation is cooperative via AbortSignal. */ import { concurrentMap } from "../../core/concurrent.js"; import { cpuDerivedUnitConcurrency, workflowMaxConcurrency } from "../concurrency-policy.js"; export { clampMaxConcurrency, cpuDerivedUnitConcurrency, WORKFLOW_MAX_CONCURRENCY_CEILING, } from "../concurrency-policy.js"; /** * Engine-wide ceiling on concurrent units: an explicit `workflow.maxConcurrency` * clamped to `[1, 64]`, else `min(16, max(1, cores − 2))`. */ export function maxUnitConcurrency(cpuCount, configured) { return workflowMaxConcurrency(configured, cpuCount); } /** * Run `dispatch` over `items` under the concurrency caps. Failures do not * cancel siblings; a slot that threw or was never claimed after an abort * stays `undefined`. */ export async function scheduleUnits(items, dispatch, options = {}) { const concurrency = Math.max(1, Math.min(options.concurrency ?? 1, options.maxConcurrency ?? Number.POSITIVE_INFINITY, options.llmConcurrency ?? Number.POSITIVE_INFINITY, options.hostConcurrency ?? cpuDerivedUnitConcurrency())); return concurrentMap(items, dispatch, concurrency, { signal: options.signal }); }