feat(auth): store a rotated CLI session credential and show the login code

TH
10h ago
+589-17

Summary

Two hardening changes to the cloud CLI login:

  • Refresh credential rotation. The refresh request sends acceptsRotatedRefreshCredential: true. A response refreshCredential replaces the stored one. A cloud that does not rotate sees no change.
  • Login code in the terminal. Browser login prints the device-flow user code to compare with the approval page. A code with unsafe characters is not printed.

Rotation contract (written at the request in auth-session.ts): a rotating cloud issues at most one replacement per credential, answers the replaced credential with an access token and no new replacement, and keeps it valid for a grace period.

Login, logout and the store of a rotated credential run under one process lock on the session file. The store re-reads the file under the lock, so a login or logout wins. A failed lock or write keeps the access token and warns.

Before / after

$ agent-device auth login
Opening https://cloud.example/authorize...
Confirm that the browser shows this code: ABCD-EFGH   # new line

Validation

  • 0756331887: src/cli tests (621 pass), typecheck, lint, layering guard.
  • New test: a rotated credential waits for a logout that holds the lock. It fails on the previous head.
  • Other tests: rotation stored and reused; parallel commands leave one replacement; a changed session is not overwritten; failed write warns; unsafe code not printed.
  • A cloud implementation of the contract was exercised against this flag.
  • No device run: CLI auth only.