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
35 lines (34 loc) • 1.69 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 { makeBundleRef, parseBundleRef } from "../../core/asset/asset-ref.js";
import { lookupAsset } from "../../core/assets/read.js";
import { parseEnvRef } from "../../core/env-secret-ref.js";
import { UsageError } from "../../core/errors.js";
/**
* A step's frozen environment: `pass_env` names, then one bundle-qualified
* ref per `unit.env` entry. The env file, its keys and the secrets it names
* are read at dispatch (`exec/environment.ts`), never frozen.
*/
export function freezeEnvironment(source, exec) {
const passThrough = (exec?.passEnv ?? []).map((name) => Object.freeze({ kind: "pass-through", name }));
const seen = new Set();
const envRefs = [];
for (const [precedence, ref] of (source.unit?.env ?? []).entries()) {
parseEnvRef(ref);
const qualified = qualifyEnvRef(ref);
if (seen.has(qualified))
continue;
seen.add(qualified);
envRefs.push(Object.freeze({ kind: "env-ref", ref: qualified, precedence }));
}
return [...passThrough, ...envRefs];
}
/** Qualify an env ref a step names with the bundle that owns it right now, through the one walk. */
function qualifyEnvRef(refInput) {
const parsed = parseBundleRef(refInput);
const asset = lookupAsset(makeBundleRef(parsed.bundle, parsed.conceptId));
if (!asset)
throw new UsageError(`Workflow source target ${refInput} was not found.`, "INVALID_FLAG_VALUE");
return makeBundleRef(asset.bundle, parsed.conceptId);
}