Implementation:23blocks OS Ai maestro Secret Vault
| Knowledge Sources | |
|---|---|
| Domains | Security, Secret_Management |
| Last Updated | 2026-10-26 18:00 GMT |
Overview
Concrete tool for storing, retrieving, and scrubbing secrets behind OS keychains (macOS Keychain, libsecret) or an encrypted file fallback, provided by AI Maestro's `lib/secret-vault.mjs`.
Description
The secret-vault module (F033) is the local secret store. A secret is stored under an upper-case name (`^[A-Z][A-Z0-9_]{0,63}$`). Agents never receive the value directly: they run `aim-secret exec --use NAME`, which puts the value into the child's environment and scrubs it from everything the child prints before the model sees the result. Backends: macOS Keychain (`security`), libsecret (`secret-tool`), and an encrypted file used by tests and by hosts with neither. The file backend keeps its key next to the data, so it is only as safe as the file permissions; it is never chosen automatically on a desktop with a keychain. `assertSecretValue` enforces a minimum length of 6 (shorter values cannot be scrubbed without mangling output). `explainBackendFailure` translates OS keychain errors into actionable human sentences. `redactSecrets` strips quoted strings and long token-like runs from error messages so a value never reaches a card, log, or agent. Files are written atomically with mode 0600.
Usage
Call `storeSecret(name, value)` to save, `getSecret(name)` to retrieve (server-side only), and run `aim-secret exec --use NAME -- <command>` to inject a secret into a child's environment. Call `assertSecretName`/`assertSecretValue` to validate input. Use `explainBackendFailure` to produce user-facing error help.
Code Reference
Source Location
- Repository: ai-maestro
- File: lib/secret-vault.mjs
- Lines: L1-L482
Signature
export const SERVICE = 'ai-maestro'
export const MIN_SECRET_LENGTH = 6
export class VaultError extends Error { code: number }
export function assertSecretName(name: string): string
export function assertSecretValue(value: string): string
export function vaultDir(): string
export function explainBackendFailure(message: string, platform?: string): string | null
export function redactSecrets(text: string): string
export async function storeSecret(name: string, value: string, backend?: string): Promise<void>
export async function getSecret(name: string, backend?: string): Promise<string | null>
export async function deleteSecret(name: string, backend?: string): Promise<void>
export async function listSecrets(backend?: string): Promise<string[]>
export async function execWithSecret(name: string, command: string[], options?: object): Promise<{ stdout: string; stderr: string; code: number }>
Import
import { storeSecret, getSecret, assertSecretName, redactSecrets, VaultError } from '@/lib/secret-vault.mjs'
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| name | string | Yes | Upper-case secret name (validated by NAME_RE) |
| value | string | Yes (store) | Secret value (min 6 chars) |
| backend | string | No | 'libsecret' \| 'file'; auto-detected if omitted |
| command | string[] | Yes (exec) | Command to run with secret in env |
Outputs
| Name | Type | Description |
|---|---|---|
| storeSecret() returns | Promise<void> | Secret stored in chosen backend |
| getSecret() returns | null> | Value or null if not found |
| execWithSecret() returns | { stdout, stderr, code } | Scrubbed child output (value removed) |
| redactSecrets() returns | string | Text with quoted/token-like runs replaced |
Usage Examples
Store and exec a secret
import { storeSecret, execWithSecret } from '@/lib/secret-vault.mjs'
// 1. Store an API key (prompts keychain on macOS)
await storeSecret('OPENAI_API_KEY', 'sk-...long-key...')
// 2. Agent runs a command with the key in env — value is scrubbed from output
const { stdout } = await execWithSecret('OPENAI_API_KEY', ['curl', '-s', 'https://api.example.com'], {
env: { ...process.env },
})
// stdout has the secret value removed before the model sees it
Redact an error message
import { redactSecrets } from '@/lib/secret-vault.mjs'
const safe = redactSecrets(`security said: unknown command "sk-abcdef123456"`)
// 'security said: unknown command "[…]"'