Skip to content

[1599 by Claude Opus 4.8] Add setup wizard domain model and idempotent stack state helpers - #1610

Merged
propr-dev[bot] merged 2 commits into
mainfrom
1599/claude-opus-4-8-add-setup-wizard-domain-m-20260622-0930-ge5
Jun 22, 2026
Merged

propr-dev[bot] merged 2 commits into
mainfrom
1599/claude-opus-4-8-add-setup-wizard-domain-m-20260622-0930-ge5

Conversation

@propr-dev

@propr-dev propr-dev Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

AI Implementation Summary

Closes #1599

Branch: 1599/claude-opus-4-8-add-setup-wizard-domain-m-20260622-0930-ge5
Commits: ✅ Changes committed (7b5bdc1)


AI Processing Completed

Execution Details:

Summary:
Everything passes. Here's a summary of what I implemented for issue #1599.

Summary

I created a setup-specific domain layer for the upcoming propr setup command, so the flow is fully testable without Ink or readline. scaffoldStack was already exported from initStack.ts, so no separate prerequisite change was needed.

New files

packages/cli/src/commands/setup/types.ts — the shared domain model:

  • SetupStepStatus (pending / active / done / skipped / error) and SetupStepId for the nine ordered steps (checks, init-stack, pull-images, agents, github-auth, start-stack, whitelist, repo, ui).
  • SETUP_STEPS definitions (title, description, optional flag) with each step documented against the existing API it reuses (runChecks, scaffoldStack, pullImages, startStack, the env helpers, etc.).
  • SetupStepState / SetupState (progress + detail/error/action for "next action"), StackState (fs-only scaffolding snapshot), and SETUP_STATUS_GLYPH / SETUP_STATUS_LABEL constants shared by both the TUI and a fallback renderer (mirroring checkCommands.ts conventions).

packages/cli/src/commands/setup/state.ts — pure helpers:

  • resolveSetupRoot (wraps the shared resolveStackRoot), getStackState / isStackInitialized (fs-only idempotency), initializeStack (idempotent scaffoldStack wrapper), and isStackRunning (lazily imports the orchestrator so the module never touches Docker on import).
  • Safe .env editing: readEnvValues / getEnvValue, isPlaceholderEnvValue (kept in sync with checkCommands.ts), writeEnvSelection (explicit choices, skips empties), and seedEnvDefaults (non-destructive — only fills missing/placeholder values, preserving real ones). Both writers reuse upsertEnvVars.
  • Step-model helpers: createSetupState, updateStep (immutable), nextActionableStep, summarizeSetup, isSetupComplete.

test/cliSetupState.test.ts — 8 node:test cases (matching the existing cliEnvFile.test.ts style) covering stack-state detection, env parsing, placeholder detection, both write helpers' preserve/overwrite semantics, and step-model advancement.

Verification

  • tsc --noEmit passes for the CLI package.
  • All 8 new tests pass; the existing cliEnvFile test still passes.

Acceptance criteria

  • ✅ Helpers import without starting Docker or rendering UI (orchestrator is loaded lazily only inside isStackRunning).
  • ✅ Existing .env values preserved unless a step explicitly writes a selected value (seedEnvDefaults vs writeEnvSelection).
  • ✅ The model carries enough (status, detail, action, summary, next-step) for both a TUI and a sequential renderer.

Detailed Logs:

  • Conversation: 87 messages
  • Session: 1ab8e64c-9164-41f1-bacd-5f22fc6a3739

Log files stored at:

  • conversation: /tmp/claude-logs/issue-1599-2026-06-22T09-37-37-091Z-conversation.json
  • output: /tmp/claude-logs/issue-1599-2026-06-22T09-37-37-091Z-output.txt
Latest Conversation Messages
ASSISTANT: [content unavailable]

ASSISTANT: Everything passes. Here's a summary of what I implemented for issue #1599.

## Summary

I created a setup-specific domain layer for the upcoming `propr setup` command, so the flow is fully testable wi...


This PR was created automatically by ProPR after processing issue #1599.


💡 Need changes?

Comment on this PR to request refinements — the AI agent monitors comments and will update the implementation based on your feedback. Keep iterating until you're satisfied!

…1599.

Summary

I created a setup-specific domain layer for the upcoming `propr setup` command, so the flow is fully testable without Ink or readline. `scaffoldStack` was already exported from `initStack.ts`, so no separate prerequisite change was needed.

New files

`packages/cli/src/commands/setup/types.ts` — the shared domain model:
- `SetupStepStatus` (`pending` / `active` / `done` / `skipped` / `error`) and `SetupStepId` for the nine ordered steps (checks, init-stack, pull-images, agents, github-auth, start-stack, whitelist, repo, ui).
- `SETUP_STEPS` definitions (title, description, `optional` flag) with each step documented against the existing API it reuses (`runChecks`, `scaffoldStack`, `pullImages`, `startStack`, the env helpers, etc.).
- `SetupStepState` / `SetupState` (progress + `detail`/`error`/`action` for "next action"), `StackState` (fs-only scaffolding snapshot), and `SETUP_STATUS_GLYPH` / `SETUP_STATUS_LABEL` constants shared by both the TUI and a fallback renderer (mirroring `checkCommands.ts` conventions).

`packages/cli/src/commands/setup/state.ts` — pure helpers:
- `resolveSetupRoot` (wraps the shared `resolveStackRoot`), `getStackState` / `isStackInitialized` (fs-only idempotency), `initializeStack` (idempotent `scaffoldStack` wrapper), and `isStackRunning` (lazily imports the orchestrator so the module never touches Docker on import).
- Safe `.env` editing: `readEnvValues` / `getEnvValue`, `isPlaceholderEnvValue` (kept in sync with `checkCommands.ts`), `writeEnvSelection` (explicit choices, skips empties), and `seedEnvDefaults` (non-destructive — only fills missing/placeholder values, preserving real ones). Both writers reuse `upsertEnvVars`.
- Step-model helpers: `createSetupState`, `updateStep` (immutable), `nextActionableStep`, `summarizeSetup`, `isSetupComplete`.

`test/cliSetupState.test.ts` — 8 `node:test` cases (matching the existing `cliEnvFile.test.ts` style) covering stack-state detection, env parsing, placeholder detection, both write helpers' preserve/overwrite semantics, and step-model advancement.

Verification
- `tsc --noEmit` passes for the CLI package.
- All 8 new tests pass; the existing `cliEnvFile` test still passes.

Acceptance criteria
- ✅ Helpers import without starting Docker or rendering UI (orchestrator is loaded lazily only inside `isStackRunning`).
- ✅ Existing `.env` values preserved unless a step explicitly writes a selected value (`seedEnvDefaults` vs `writeEnvSelection`).
- ✅ The model carries enough (status, detail, action, summary, next-step) for both a TUI and a sequential renderer.
@propr-dev

propr-dev Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

/ultrafix
Triggered automatically by Planner execution settings.

@propr-dev propr-dev Bot added the ultrafix label Jun 22, 2026
@propr-dev

propr-dev Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

🔄 Ultrafix loop started (goal: 8/10, max cycles: 10)

First action: /review

💡 Tip: Remove the ultrafix label from this PR to stop further ultrafix cycles.

@propr-dev

propr-dev Bot commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ AI Code Review Complete requested by @propr-dev[bot]

Posted 1 review:

View Task Details

@propr-dev

propr-dev Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

🔍 AI Code Review — codex:gpt-5.5

Overall Evaluation

This PR adds a clean setup wizard domain model plus stack/env state helpers and focused tests. The structure is generally sound and aligns with the issue’s goal of keeping setup logic renderer-independent.

I would mark this as needing minor changes before merge. The main concerns are around edge-case correctness in step progression and stack initialization detection.

Findings

🟡 Errored steps are skipped by nextActionableStep — In packages/cli/src/commands/setup/state.ts:218, nextActionableStep only returns pending or active steps. If a step enters error while later steps remain pending, the helper will advance to the next pending step instead of surfacing the failed step that needs user action.

🟡 Stack initialization treats files as directories — In packages/cli/src/commands/setup/state.ts:43-45, existsSync is used for data, logs, and repos. A regular file with one of those names would make initialized true, causing setup to skip scaffolding even though the stack root is invalid.

🟡 Whitespace-only env selections are written — In packages/cli/src/commands/setup/state.ts:135-137, isEmpty only rejects undefined and "". Prompt input like " " would be written as a real value, bypassing placeholder/default handling.

🟡 Top-level orchestrator import contradicts lazy-import intent — packages/cli/src/commands/setup/state.ts:21 imports resolveStackRoot from the orchestrator module at top level, while the file comment says only isStackRunning loads orchestrator lazily. If orchestrator/index.js has Docker-heavy or environment-sensitive imports, this weakens the “safe to import” goal.

🟢 Consider clearing stale fields when status changes — In packages/cli/src/commands/setup/state.ts:206-214, updateStep preserves old detail, error, and action unless explicitly overwritten. This is flexible, but a transition from error to done can leave stale error text for renderers that display those fields.

🟢 Consider validating skipped required steps — isSetupComplete in packages/cli/src/commands/setup/state.ts:228-230 treats any skipped step as complete, regardless of whether the step is optional in SETUP_STEPS. That may be intentional for idempotent no-op outcomes, but the domain model already distinguishes optional steps and could enforce that more explicitly.

✅ Good separation of domain model from UI — packages/cli/src/commands/setup/types.ts keeps setup step/status data free of Ink/readline concerns, which fits the issue requirements well.

✅ Env writes are mostly non-destructive — seedEnvDefaults and writeEnvSelection preserve unrelated .env lines by reusing upsertEnvVars, and the tests cover overwrite vs preserve behavior.

✅ Focused tests cover the core helpers — test/cliSetupState.test.ts validates stack state, env parsing, placeholder detection, env writes, and setup step progression without requiring Docker or a TTY.

Score

Solid foundation with good test coverage, but a few edge cases could cause incorrect setup flow decisions or invalid stack state detection.

Score: 7/10


🤖 Review Details

  • Model: gpt-5.5
  • Time: 44s
  • Tokens: 29,031 (27,340 in / 1,691 out)
  • Cost: $0.19

View Task


💡 Next step: Comment /fix on this PR to have the AI automatically implement the suggestions above.
The /fix command gathers all unprocessed AI review comments and applies fixes in a single pass.
You can edit or delete review comments before running /fix to control which suggestions are applied.
Add extra instructions if needed, e.g. /fix only address the critical findings.

@propr-dev

propr-dev Bot commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ Applied the requested follow-up changes in commit a6e1dee

Addressed 1 AI review comment (IDs: 4766923629)

Summary of Changes

All changes are complete and verified (12/12 tests pass, no type errors). Here's a summary of what I addressed from the review:

Changes to packages/cli/src/commands/setup/state.ts

🟡 Errored steps skipped by nextActionableStep — Now returns pending, active, or error steps, so a failed step is surfaced ahead of later pending steps and the flow waits for the user to act.

🟡 Stack initialization treats files as directories — Added type-aware isFile/isDirectory helpers (wrapping statSync, catching errors). getStackState now requires data/logs/repos to be real directories and .env to be a real file, so a regular file named data no longer makes a root look initialized.

🟡 Whitespace-only env selections written — Replaced isEmpty with a hasValue type guard that rejects undefined, "", and whitespace-only values. Used in both writeEnvSelection and seedEnvDefaults, so blank prompt input is skipped rather than written.

🟡 Top-level orchestrator import vs. lazy intent — Updated the module doc comment to accurately describe the boundary: resolveStackRoot is a pure path helper (node builtins only — importing it does not load the Docker-backed core), and the heavy orchestrator.mjs core is still loaded lazily only by isStackRunning.

🟢 Stale fields on status change — updateStep now clears a stale error when a step leaves the error state (e.g. error → done after a retry), unless the caller explicitly sets a new error in the patch.

🟢 Skipped required steps — isSetupComplete now treats a skipped step as complete only if the step is optional (using the optional flag from SETUP_STEPS); a skipped required step keeps setup incomplete.

Tests added to test/cliSetupState.test.ts

Coverage for files-masquerading-as-dirs, whitespace env values, errored-step surfacing, stale-error clearing, and skipped-required-step rejection.

I have not committed — the system will handle that.


🤖 Implementation Details

  • Model: Claude Opus 4.8
  • Requested By: @propr-ultrafix
  • Time: 4m 33s
  • Tokens: 925,045 (911,129 in / 13,916 out)
  • Cost: $1.02

View Task Execution


💡 ProPR Slash Commands
Command Description Example
/merge Merge target branch into this PR and resolve conflicts /merge
/review Request an AI code review /review or /review claude-sonnet
/fix Implement fixes for issues found by /review /fix or /fix address the null check issue
/switch Change the AI model for this PR /switch claude-opus
/use Override the model for a single follow-up run /use claude-sonnet
/ultrafix Loop review→fix cycles until score goal is met /ultrafix or /ultrafix goal=8 max=10

… type errors). Here's a summary of what I addressed from the review:

All changes are complete and verified (12/12 tests pass, no type errors). Here's a summary of what I addressed from the review:

## Changes to `packages/cli/src/commands/setup/state.ts`

**🟡 Errored steps skipped by `nextActionableStep`** — Now returns `pending`, `active`, **or `error`** steps, so a failed step is surfaced ahead of later pending steps and the flow waits for the user to act.

**🟡 Stack initialization treats files as directories** — Added type-aware `isFile`/`isDirectory` helpers (wrapping `statSync`, catching errors). `getStackState` now requires `data`/`logs`/`repos` to be real directories and `.env` to be a real file, so a regular file named `data` no longer makes a root look initialized.

**🟡 Whitespace-only env selections written** — Replaced `isEmpty` with a `hasValue` type guard that rejects `undefined`, `""`, **and whitespace-only** values. Used in both `writeEnvSelection` and `seedEnvDefaults`, so blank prompt input is skipped rather than written.

**🟡 Top-level orchestrator import vs. lazy intent** — Updated the module doc comment to accurately describe the boundary: `resolveStackRoot` is a pure path helper (node builtins only — importing it does not load the Docker-backed core), and the heavy `orchestrator.mjs` core is still loaded lazily only by `isStackRunning`.

**🟢 Stale fields on status change** — `updateStep` now clears a stale `error` when a step leaves the `error` state (e.g. `error → done` after a retry), unless the caller explicitly sets a new error in the patch.

**🟢 Skipped required steps** — `isSetupComplete` now treats a `skipped` step as complete **only if the step is optional** (using the `optional` flag from `SETUP_STEPS`); a skipped required step keeps setup incomplete.

## Tests added to `test/cliSetupState.test.ts`
Coverage for files-masquerading-as-dirs, whitespace env values, errored-step surfacing, stale-error clearing, and skipped-required-step rejection.

I have not committed — the system will handle that.

PR: #1610
Comment by: @propr-ultrafix (ID: 0)
Model: claude-opus-4-8
@propr-dev

propr-dev Bot commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ AI Code Review Complete requested by @propr-ultrafix

Posted 1 review:

View Task Details

@propr-dev

propr-dev Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

🔍 AI Code Review — codex:gpt-5.5

Overall Evaluation

This PR adds a clean setup wizard domain layer with step/status types, stack initialization state helpers, non-destructive .env writers, and focused unit coverage. The approach matches the issue well and keeps UI concerns out of the model. I’d consider it close to merge, with a couple of edge cases worth addressing before the setup flow starts depending on these helpers.

Findings

🟡 Warning — isStackRunning may not honor its documented failure behavior (packages/cli/src/commands/setup/state.ts): The comment says this returns false if Docker is unreachable, but only orch.dockerAvailable() is checked after getHostConfig() succeeds. If the dynamic import, config resolution, Docker client setup, or orch.isStackRunning(cfg) throws, callers will still get an exception. Consider wrapping Docker/orchestrator failures and returning false for the intended “safe probe” behavior.

🟡 Warning — .env duplicate handling may preserve or read the wrong effective value (packages/cli/src/commands/setup/state.ts): readEnvValues keeps the first assignment for a key. Many env parsers and shell-like workflows treat the later assignment as the effective override, and upsertEnvVars may also operate differently. If a .env contains duplicate keys, seedEnvDefaults could preserve a stale first value while the runtime uses a later placeholder, or vice versa. Add a test aligned with the project’s actual .env semantics.

🟢 Suggestion — Placeholder detection should probably normalize quotes (packages/cli/src/commands/setup/state.ts): isPlaceholderEnvValue trims whitespace but does not strip simple quotes, so "your_app_id" or 'changeme' would be treated as real values. If .env.example or user-edited files can contain quoted values, this will prevent defaults from being seeded.

🟢 Suggestion — Test initializeStack and resolveSetupRoot integration if practical (test/cliSetupState.test.ts): The pure state and env helpers are well covered, but the two helpers that connect to existing APIs are not. Even a mocked or temp-dir test for initializeStack would catch import/export drift around scaffoldStack, which is one of the issue’s explicit requirements.

✅ Positive — Good separation between domain state and rendering (packages/cli/src/commands/setup/types.ts, packages/cli/src/commands/setup/state.ts): The step model is UI-agnostic and should work for both Ink and fallback renderers without pulling in readline or terminal concerns.

✅ Positive — Non-destructive env writing is well designed (packages/cli/src/commands/setup/state.ts): Splitting explicit selections from default seeding is a good distinction, and the tests cover preservation, overwrite, and blank-value skipping.

✅ Positive — Stack initialization checks are type-aware (packages/cli/src/commands/setup/state.ts): Treating files named data, logs, or repos as invalid avoids false positives and supports safe reruns.

Score

Score: 8/10
Solid, focused implementation with useful tests and good fit for the requested setup domain layer. The main remaining risk is around edge-case runtime behavior in env parsing and the isStackRunning safe-probe contract.


🤖 Review Details

  • Model: gpt-5.5
  • Time: 33s
  • Tokens: 31,132 (29,831 in / 1,301 out)
  • Cost: $0.19

View Task


💡 Next step: Comment /fix on this PR to have the AI automatically implement the suggestions above.
The /fix command gathers all unprocessed AI review comments and applies fixes in a single pass.
You can edit or delete review comments before running /fix to control which suggestions are applied.
Add extra instructions if needed, e.g. /fix only address the critical findings.

@propr-dev propr-dev Bot removed the ultrafix label Jun 22, 2026
@propr-dev
propr-dev Bot merged commit 9719113 into main Jun 22, 2026
3 checks passed
@propr-dev
propr-dev Bot deleted the 1599/claude-opus-4-8-add-setup-wizard-domain-m-20260622-0930-ge5 branch June 22, 2026 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add setup wizard domain model and idempotent stack state helpers

0 participants