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
31 lines (30 loc) • 1.53 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/.
/**
* Build the default task-run provenance context: `eventSource` is always
* `"task"` (D5-N1); `scheduled` carries the caller's own scheduled flag.
*/
export function createExecutionProvenanceContext(scheduled) {
return Object.freeze({ eventSource: "task", scheduled });
}
/**
* Resolve the effective provenance for one `runTask()` call: an explicit
* `RunTaskOptions.provenance` always wins; absent, this is the default
* context, so a caller that never sets `provenance` behaves as before.
*/
export function resolveProvenanceContext(explicit, scheduled) {
return explicit ?? createExecutionProvenanceContext(scheduled);
}
/** The `AKM_EVENT_SOURCE` a task's process gets: the one in akm's own environment when it is set, else the run's. */
export function taskEventSource(host, provenance) {
return host.AKM_EVENT_SOURCE ?? provenance.eventSource;
}
/**
* The provenance a task's process gets: its `AKM_EVENT_SOURCE` and `AKM_TASK_REF`, the ref of the task it runs in
* (the innermost task's, unlike the event source). akm's usage capture keeps the ref on its local per-invocation
* record only (src/cli/usage.ts); the usage report never reads it.
*/
export function taskProcessEnv(host, provenance, taskRef) {
return { AKM_EVENT_SOURCE: taskEventSource(host, provenance), AKM_TASK_REF: taskRef };
}