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

69 lines (68 loc) • 2.11 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 { akmLocations, withoutLauncherVars } from "../../core/paths.js"; /** * What `env run --clean` / `secret run --clean` keeps of the parent environment. The user typed * the flag to get a minimal one; without the last eight names Windows cannot create the process. */ const CLEAN_ENV_ALLOWLIST = [ "HOME", "PATH", "PWD", "SHELL", "TERM", "TMPDIR", "TEMP", "TMP", "USER", "LOGNAME", "LANG", "LANGUAGE", "LC_ALL", "LC_CTYPE", "LC_COLLATE", "LC_MESSAGES", "LC_MONETARY", "LC_NUMERIC", "LC_TIME", "LC_PAPER", "LC_NAME", "LC_ADDRESS", "LC_TELEPHONE", "LC_MEASUREMENT", "LC_IDENTIFICATION", "TZ", "NO_COLOR", "COLORTERM", "SystemRoot", "SystemDrive", "WINDIR", "COMSPEC", "PATHEXT", "USERPROFILE", "HOMEDRIVE", "HOMEPATH", ]; export function buildChildEnv(parentEnv, options) { const base = options.clean ? {} : { ...withoutLauncherVars(parentEnv) }; if (options.clean) { for (const key of CLEAN_ENV_ALLOWLIST) { if (parentEnv[key] !== undefined) base[key] = parentEnv[key]; } // The child that runs `akm` must find this installation; AKM_BUNDLE_DIR is a retired selector, not a location to keep. const { AKM_BUNDLE_DIR: _bundleDir, ...locations } = akmLocations(); Object.assign(base, locations); } for (const key of options.inherit) { if (parentEnv[key] !== undefined) base[key] = parentEnv[key]; } return base; } /** The child environment for `--clean` and `--inherit <VAR,...>`; `--inherit` alone starts clean. */ export function childEnvFromFlags(parentEnv, flags) { const inherit = (flags.inherit ?? "").split(/[,\s]+/).filter(Boolean); return buildChildEnv(parentEnv, { clean: flags.clean || flags.inherit !== undefined, inherit }); }