Skip to content

vault_change

vault_change

Rekey pre-flight overlay for the vault passphrase change verb.

Sandbox's handler owns the passphrase conversation and the rekey; what it cannot know about is terok's fleet. PRAGMA rekey needs the credentials DB exclusively, and every running task's supervisor holds a connection — so the bare verb dead-ends with database is locked on a busy host. This overlay wraps the handler with the same conversation the TUI flow runs (TerokTUI._clear_rekey_blockers): offer to stop the running tasks and restart them afterwards, sweep supervisor processes orphaned by an earlier stop, and refuse — loudly, naming pids — when a foreign process pins the DB.

The prompts only run on a TTY. Piped stdin belongs to the handler's own line-per-value passphrase protocol, so a non-interactive call with blockers present fails fast with the full picture instead of consuming a line that was meant to be a passphrase.

__all__ = ['wrap_passphrase_change'] module-attribute

wrap_passphrase_change(tree)

Overlay the change verb with the rekey pre-flight conversation.

A tree without the verb (an older sandbox wheel) passes through untouched — the bare handler's database is locked error is still a correct, if less helpful, outcome.

Source code in src/terok/cli/commands/vault_change.py
def wrap_passphrase_change(tree: CommandTree) -> CommandTree:
    """Overlay the change verb with the rekey pre-flight conversation.

    A tree without the verb (an older sandbox wheel) passes through
    untouched — the bare handler's ``database is locked`` error is
    still a correct, if less helpful, outcome.
    """
    try:
        cmd = tree.find_at(_CHANGE_VERB_PATH)
    except KeyError:
        return tree
    if cmd is None or cmd.handler is None:
        return tree
    return tree.overlay({_CHANGE_VERB_PATH: _with_rekey_preflight(cmd.handler)})