set_secret
Store secrets with quantum-inspired features like time-based decay, environment-specific values, and organizational tags to prevent plaintext leaks in development workflows.
Instructions
Store a secret with optional quantum metadata: TTL (decay), environment state (superposition), description, tags.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| key | Yes | The secret key name | |
| value | Yes | The secret value | |
| scope | No | Scope: global or project | global |
| projectPath | No | Project root path for project-scoped secrets | |
| env | No | If provided, sets the value for this specific environment (superposition) | |
| ttlSeconds | No | Time-to-live in seconds (quantum decay) | |
| description | No | Human-readable description | |
| tags | No | Tags for organization |
Implementation Reference
- src/core/keyring.ts:146-215 (handler)The implementation of `setSecret` which handles creating, updating, and propagating entangled secrets in the keyring.
export function setSecret( key: string, value: string, opts: SetSecretOptions = {}, ): void { const scope = opts.scope ?? "global"; const scopes = resolveScope({ ...opts, scope }); const { service } = scopes[0]; const source = opts.source ?? "cli"; // Check if there's an existing envelope to preserve metadata const existing = readEnvelope(service, key); let envelope: QuantumEnvelope; if (opts.states) { envelope = createEnvelope("", { states: opts.states, defaultEnv: opts.defaultEnv, description: opts.description, tags: opts.tags, ttlSeconds: opts.ttlSeconds, expiresAt: opts.expiresAt, entangled: existing?.meta.entangled, }); } else { envelope = createEnvelope(value, { description: opts.description, tags: opts.tags, ttlSeconds: opts.ttlSeconds, expiresAt: opts.expiresAt, entangled: existing?.meta.entangled, }); } // Preserve access count from existing if (existing) { envelope.meta.createdAt = existing.meta.createdAt; envelope.meta.accessCount = existing.meta.accessCount; } writeEnvelope(service, key, envelope); logAudit({ action: "write", key, scope, source }); // Propagate to entangled secrets const entangled = findEntangled({ service, key }); for (const target of entangled) { try { const targetEnvelope = readEnvelope(target.service, target.key); if (targetEnvelope) { if (opts.states) { targetEnvelope.states = opts.states; } else { targetEnvelope.value = value; } targetEnvelope.meta.updatedAt = new Date().toISOString(); writeEnvelope(target.service, target.key, targetEnvelope); logAudit({ action: "entangle", key: target.key, scope: "global", source, detail: `propagated from ${key}`, }); } } catch { // entangled target may not exist } } }