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
45 lines (44 loc) • 2.15 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 { collectCredentialValues } from "../core/config/credentials.js";
import { collectInferredSecretValues, collectSensitiveValues } from "../core/redaction.js";
export { isInferredSecretName, MIN_INFERRED_SECRET_LENGTH } from "../core/redaction.js";
/**
* Every value that must be scrubbed from one task's persisted output.
*
* `declaredNames` comes from the task's `redact:` list. A name that is unset in
* `env` simply contributes nothing — naming a variable you do not currently
* export is not an error.
*/
export function collectTaskLogSensitiveValues(input) {
const { env, config, declaredNames } = input;
const values = new Set();
const addDeclared = (value) => {
if (value === undefined)
return;
const trimmed = value.trim();
// Both spellings: `resolveSecret` does not trim but `resolveCredentialFromEnv`
// does, so a variable with trailing whitespace reaches an output boundary in
// either form depending on which path materialized it.
if (value.length > 0)
values.add(value);
if (trimmed.length > 0)
values.add(trimmed);
};
// (1) Declared by config — every key a connection, or the embedder can resolve.
if (config) {
for (const value of collectCredentialValues(config, env))
values.add(value);
}
// (2) Declared by the task's `redact:` list — names only, never values.
for (const name of declaredNames ?? [])
addDeclared(env[name]);
// (3) Inferred from the name shape, the one guessing tier (`collectInferredSecretValues`).
for (const value of collectInferredSecretValues(env))
values.add(value);
// Expands credential-bearing URLs into their embedded components. Can yield
// needles shorter than the floor (a URL's password), which is correct: the
// operator's own value implied them.
return collectSensitiveValues(values);
}