fix(cli): make interactive vault unlock persistent
Some checks failed
CI / build (push) Has been cancelled
Deploy to dev2 / deploy (push) Has been cancelled
test / test (push) Has been cancelled

This commit is contained in:
Anthony Ettinger 2026-10-29 16:18:04 +00:00
parent 2c65baecbb
commit 0cf528fd07
2 changed files with 13 additions and 6 deletions

View file

@ -39,7 +39,8 @@ Team secrets, the everyday commands:
Personal vault: Personal vault:
logicsrc vault init create it (once) logicsrc vault init create it (once)
eval "$(logicsrc vault unlock)" unlock for this shell logicsrc vault unlock unlock interactively for 15 minutes
eval "$(logicsrc vault unlock --shell)" export a session into this shell
logicsrc vault add login --name GitHub --username me --password - logicsrc vault add login --name GitHub --username me --password -
logicsrc vault list --category social never shows values logicsrc vault list --category social never shows values
logicsrc vault get GitHub --field login.password --reveal logicsrc vault get GitHub --field login.password --reveal

View file

@ -371,12 +371,14 @@ export function registerCredsCommands(parent: Command, options: RegisterOptions
.command("unlock") .command("unlock")
.description("start a session") .description("start a session")
.addHelpText("after", examples(` .addHelpText("after", examples(`
eval "$($CLI unlock)" unlock for this shell only (nothing written to disk) $CLI unlock unlock interactively for 15 minutes; \`lock\` ends it
$CLI unlock --persist --timeout 30 unlock for scripts for 30 minutes; \`lock\` ends it`)) eval "$($CLI unlock --shell)" export a session into this shell (nothing written to disk)
.option("--persist", "write the session to a 0600 file instead of printing a token") $CLI unlock --persist --timeout 30 choose a persisted session lifetime`))
.option("--persist", "write the session to a 0600 file (the default in an interactive terminal)")
.option("--shell", "print an export command for the current shell instead of writing a session file")
.option("--password-stdin", "read the master password from stdin") .option("--password-stdin", "read the master password from stdin")
.option("--timeout <minutes>", "session lifetime when persisted", (v: string) => Number.parseInt(v, 10), 15) .option("--timeout <minutes>", "session lifetime when persisted", (v: string) => Number.parseInt(v, 10), 15)
.action(async function (this: Command, opts: { persist?: boolean; timeout: number; passwordStdin?: boolean }) { .action(async function (this: Command, opts: { persist?: boolean; shell?: boolean; timeout: number; passwordStdin?: boolean }) {
await run(async () => { await run(async () => {
const store = storeFor(this); const store = storeFor(this);
const meta = requireMeta(store); const meta = requireMeta(store);
@ -392,7 +394,11 @@ export function registerCredsCommands(parent: Command, options: RegisterOptions
} }
store.appendAudit(auditEvent({ action: "vault.unlock", namespace: meta.namespace, profile: meta.profile })); store.appendAudit(auditEvent({ action: "vault.unlock", namespace: meta.namespace, profile: meta.profile }));
if (opts.persist) { // A plain interactive `unlock` should do what people expect: unlock
// the vault for subsequent commands. The export-only behavior remains
// available behind --shell and for non-interactive/scripted use.
const persist = Boolean(opts.persist) || (!opts.shell && Boolean(process.stdin.isTTY) && !opts.passwordStdin);
if (persist) {
const path = persistSession(userKey, opts.timeout, store.baseDir); const path = persistSession(userKey, opts.timeout, store.baseDir);
process.stdout.write(`Session written to ${path}, expiring in ${opts.timeout} minutes.\n`); process.stdout.write(`Session written to ${path}, expiring in ${opts.timeout} minutes.\n`);
process.stdout.write( process.stdout.write(