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

51 lines (50 loc) • 2.2 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 fs from "node:fs"; import { prepareScriptTarget } from "../../../tasks/prepare/prepare-script-target.js"; import { freezeEnvironment, resolveOwnedAsset } from "../environment.js"; import { gitIdentity, scriptExecutable } from "../identity.js"; import { freezeExecSpec, } from "../step-values.js"; export async function directScript(source, baseUnit, refInput, context) { const owned = await resolveOwnedAsset(refInput, "script", context); const captured = prepareScriptTarget({ ref: owned.ref, file: owned.file, bundleRoot: owned.root, readFile: () => fs.readFileSync(owned.file), }); return scriptResult(source, baseUnit, { sourceRef: captured.ref, interpreter: captured.interpreter, extension: captured.extension, bytesBase64: captured.bytesBase64, byteLength: captured.byteLength, sha256: captured.sha256, cwdIdentity: captured.cwdIdentity, }, context, []); } export function scriptResult(source, baseUnit, prepared, context, literals) { const authoredExec = { command: [scriptExecutable(prepared.interpreter), "<frozen-script>"] }; const exec = freezeExecSpec(source, authoredExec, context); const environment = Object.freeze([...literals, ...freezeEnvironment(source, authoredExec, context)]); const target = Object.freeze({ kind: "script", ref: prepared.sourceRef, contentHash: prepared.sha256, exec, interpreter: prepared.interpreter, extension: prepared.extension, bytesBase64: prepared.bytesBase64, byteLength: prepared.byteLength, cwdIdentity: prepared.cwdIdentity, materialization: "ephemeral-0700-delete", ...gitIdentity(baseUnit, prepared.cwdIdentity.realRoot), }); return { target, environment, unit: { ...baseUnit, exec: authoredExec }, instructions: source.instructions ?? `Run script ${prepared.sourceRef}.`, }; }