WIP: A simple cli for daily tangled use cases and AI integration. This is for my personal use right now, but happy if others get mileage fro

Detect locked keychain and provide better auth error message #17

Closed markbennett.ca
Closed opened by markbennett.ca

Context #

When a Mac is locked (screen saver, sleep), the OS keychain may become temporarily inaccessible. @napi-rs/keyring's getPassword() returns undefined for a missing entry but throws for a platform failure (locked keychain, access denied).

Currently resumeSession() in api-client.ts catches all errors and calls clearCurrentSessionMetadata(). This incorrectly wipes stored credentials when the keychain is just temporarily locked, forcing the user to run tangled auth login again unnecessarily.

macOS keychain behaviour #

  • CLI tools (unsigned) do not automatically get an unlock dialog (unlike GUI apps)
  • When the screen is locked, no interactive prompts are possible; on screen unlock the login keychain typically auto-unlocks
  • The macOS security CLI tool can unlock the keychain interactively: security unlock-keychain

Tasks #

Notes #

On macOS, execSync('security unlock-keychain', { stdio: 'inherit' }) passes the terminal TTY through so the user is prompted for their keychain password. This only works in an interactive terminal; SSH sessions or locked screens will fall through to the error message with instructions to run security unlock-keychain manually.