Review the whole setup change set with one confirmation

Merged
LA
4mo ago
+639-1

What changes

sr setup installed and started the daemon with no reviewable plan and only --no-install. It now shows the complete change set and applies it on one Enter press.

Subrouter is ready to set up this computer.

  = Run Subrouter in the background after you sign in (LaunchAgent) (already done)
  = Configure Codex to route through Subrouter (already done)
  + Configure Claude Code to route through Subrouter

Press Enter to apply.
[d] details   [e] edit options   [Ctrl-C] cancel

That is real output from sr setup --plan on a configured machine: already-satisfied work is listed and marked rather than hidden, so re-running is safe and the screen still shows the whole picture.

Why one confirmation instead of per-item prompts

A question per item produces half-installed machines. A user who declines background startup individually gets a daemon that stops working at the next reboot, in a state we neither test nor support. Enter-to-apply is already opt-in because nothing changes until the key is pressed, and e keeps the uncommon choices one keystroke away.

Flags

  • --plan prints the change set and exits, and returns before the login and storage writes so it genuinely changes nothing
  • --yes applies without the review screen
  • --no-background, --no-config deselect without needing the screen

A noninteractive terminal without --yes prints the plan and exits. EOF during review cancels. Silence is not consent.

Terminal detection uses term.IsTerminal rather than a character-device check: /dev/null is a character device, and sr setup < /dev/null previously entered the interactive path and read approval from EOF. Verified both < /dev/null and a real pipe now report noninteractive terminal: re-run with --yes to apply.

Two things running it surfaced

The credential line only appears when a vault exists to hand accounts to. Previously a machine with 16 local accounts and no vault rendered a deselectable - Keep 16 existing account(s) on this machine, which implies setup might delete them when there was nothing to decide.

That line states its consequence, "stops refreshing them here", rather than calling it adoption. Handing a credential to the vault is what stops two hosts from invalidating each other's refresh tokens (see #108), so a user who reads it as a harmless copy will make the wrong choice.

Tests

Enter applies; EOF cancels; d shows the exact Codex change without applying; e toggles one option without disturbing others; an out-of-range choice is rejected and changes nothing; flags deselect; already-satisfied work is never re-applied; a fully-configured machine says "Nothing to do"; the credential item names the vault and its consequence, and is absent without one; each platform names its own mechanism; and clientRoutesToLocal reads disk rather than trusting a flag, including port mismatch and missing file.

go test ./cmd/... ./internal/... passes.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Summary by cubic

sr setup now shows a single, reviewable change set and applies everything on one Enter, preventing partial installs and making re-runs safe. Noninteractive runs print the plan and exit unless --yes is provided.

  • New Features
    • Interactive review screen: shows all actions with status markers, Enter to apply; d for details; e to toggle uncommon options; EOF cancels.
    • Flags: --plan (print and exit), --yes (apply without review), --no-background, --no-config.
    • Noninteractive safety: detects TTY with term.IsTerminal; prints plan and “noninteractive terminal: re-run with --yes to apply” instead of applying.
    • Credentials: only shows the vault option when a team vault is ready, and clearly states it “stops refreshing them here.”
    • Platform clarity: background startup names the mechanism per OS (LaunchAgent, systemd user service, scheduled task).