Skip to content

feat: first-run state guard for dot CLI#61

Open
jamesainslie wants to merge 4 commits intomainfrom
add-first-run-state-guard
Open

feat: first-run state guard for dot CLI#61
jamesainslie wants to merge 4 commits intomainfrom
add-first-run-state-guard

Conversation

@jamesainslie
Copy link
Copy Markdown
Collaborator

Summary

  • Detects existing dot state (manifest, packages, symlinks) on first mutating command (manage, adopt, clone)
  • Prompts user to continue, start fresh, or back up and start fresh
  • Auto-continues in batch mode (--batch) and non-TTY sessions
  • Writes marker file (~/.local/state/dot/.dot-acknowledged) so prompt appears exactly once
  • Silent when no existing state is found (true first-run) or marker already exists

Changes

  1. Export XDG helpersGetXDGStatePath/GetXDGDataPath in internal/config/extended.go
  2. Add SelectWithDefault to internal/cli/prompt/ — returns configurable default on empty input/EOF
  3. New internal/stateguard/ package — marker management, action handlers (continue, fresh, backup+fresh), orchestrator
  4. Wire into commandsrunStateGuard(cmd) as first call in runManage, runAdoptCommand, runClone

Test plan

  • go test ./internal/stateguard/... -race -count=1 — 23 tests pass
  • go test ./internal/cli/prompt/... -race -count=1 — all tests pass including new SelectWithDefault
  • go test ./cmd/dot/... -race -count=1 — all tests pass including integration tests
  • go test ./... -race -count=1 — full suite passes, zero regressions
  • Manual: create manifest with packages, run dot manage → verify prompt appears and each option works

Export getXDGStatePath/getXDGDataPath as public functions for use by
the stateguard package. Add SelectWithDefault method that returns a
configurable default on empty input or EOF, following the existing
ConfirmWithDefault pattern.
Detects existing dot state (manifest, packages, symlinks) before the
first mutating command and prompts the user to continue, start fresh,
or back up and reset. Marker file prevents re-prompting.

Includes marker management, three action handlers (continue, fresh,
backup+fresh), and orchestrator with full test coverage (23 tests).
Adds runStateGuard as the first call in manage, adopt, and clone.
Batch mode and non-TTY sessions auto-continue. Resolves manifest dir,
target dir, and config path from existing config infrastructure.
Use output.Formatter and render.Colorizer for styled guard output
matching the rest of the CLI. Isolate XDG_STATE_HOME in integration
tests that spawn subprocess manage commands to prevent the guard
marker from leaking to the real home directory.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant