Skip to content

Add setup wizard domain model and idempotent stack state helpers #1599

Description

@propr-dev

Context

The new propr setup command needs to coordinate existing environment checks, stack initialization, image pulling, agent configuration, GitHub authentication, stack startup, whitelist setup, optional repo setup, and UI launch. Before adding UI, create a small setup-specific domain layer so the flow is testable without Ink or readline.

Requirements

  • Add setup step/status types that can be shared by Ink and fallback renderers.
  • Add helpers for resolving the stack root, checking whether the stack is already initialized, and safely editing .env.
  • Keep the command re-runnable and non-destructive by default.
  • Reuse existing runChecks, scaffoldStack, upsertEnvVars, and orchestrator APIs where possible.

Implementation Specification

Create packages/cli/src/commands/setup/types.ts and packages/cli/src/commands/setup/state.ts. If scaffoldStack is not exported from initStack.ts, export it in a separate issue before this helper calls it.

Acceptance Criteria

  • Setup state helpers can be imported without starting Docker or rendering UI.
  • Existing .env values are preserved unless a step explicitly writes a selected value.
  • The helper returns enough information for both TUI and sequential wizard renderers to show progress and next actions.

Created by ProPR AI Planner

Activity

  1. propr-dev commented on Jun 22, 2026

    @propr-dev
    ContributorAuthor

    Suggested Implementation:

    Implementation Approach

    This implementation starts with a narrow domain layer instead of putting setup logic directly inside the Commander action or Ink component. That keeps setup re-runnable and testable: the UI becomes a renderer over explicit setup state, while file and Docker mutations stay in small functions. A single monolithic command implementation was considered, but rejected because it would make the fallback wizard duplicate logic and would be hard to unit test. The trade-off is a few extra setup files, but those files establish clear ownership for a feature that will grow.

    File: packages/cli/src/commands/setup/types.ts (new file)

    Why this file: This file defines the setup wizard contract shared by the command, Ink TUI, fallback wizard, and tests. Keeping it separate prevents UI-specific concerns from leaking into the setup engine.

    import type { CheckResult } from '../checkCommands.js';
    
    export type SetupStepId =
      | 'environment'
      | 'docker'
      | 'images'
      | 'agents'
      | 'github-cli'
      | 'github-intake'
      | 'stack-init'
      | 'stack-start'
      | 'whitelist'
      | 'repository'
      | 'web-ui';
    
    export type SetupStepStatus = 'pending' | 'running' | 'complete' | 'warning' | 'blocked' | 'skipped';
    
    export interface SetupStepState {
      id: SetupStepId;
      title: string;
      status: SetupStepStatus;
      detail?: string;
      checks?: CheckResult[];
    }
    
    export interface SetupWizardState {
      rootDir: string;
      steps: SetupStepState[];
      currentStep: SetupStepId;
      isInteractive: boolean;
    }
    
    export interface SetupRunOptions {
      root?: string;
      noTui?: boolean;
      skipRemoteImageCheck?: boolean;
    }
    
    export interface SetupDecision<T extends string = string> {
      value: T;
      label: string;
      detail: string;
    }

    File: packages/cli/src/commands/setup/state.ts (new file)

    Why this file: This file centralizes setup state creation and .env mutation helpers. It connects the wizard to existing config and env-file utilities while keeping mutations explicit and idempotent.

    import { existsSync } from 'node:fs';
    import { resolve } from 'node:path';
    import { createConfigManager } from '../../config/index.js';
    import { upsertEnvVars } from '../../utils/envFile.js';
    import type { SetupStepId, SetupStepState, SetupWizardState } from './types.js';
    
    const STEP_TITLES: Record<SetupStepId, string> = {
      environment: 'Check environment',
      docker: 'Docker runtime',
      images: 'Container images',
      agents: 'Coding agents',
      'github-cli': 'GitHub CLI session',
      'github-intake': 'GitHub event intake',
      'stack-init': 'Initialize stack',
      'stack-start': 'Start and validate stack',
      whitelist: 'GitHub user whitelist',
      repository: 'Add repository',
      'web-ui': 'Open Web UI',
    };
    
    export const SETUP_STEP_ORDER = Object.keys(STEP_TITLES) as SetupStepId[];
    
    export function createInitialSetupState(rootDir: string, isInteractive: boolean): SetupWizardState {
      return {
        rootDir,
        isInteractive,
        currentStep: 'environment',
        // Keep the full step list stable so both Ink and sequential renderers can
        // display the same progress model even when individual steps are skipped.
        steps: SETUP_STEP_ORDER.map((id): SetupStepState => ({
          id,
          title: STEP_TITLES[id],
          status: 'pending',
        })),
      };
    }
    
    export function updateStep(
      state: SetupWizardState,
      id: SetupStepId,
      patch: Partial<SetupStepState>
    ): SetupWizardState {
      return {
        ...state,
        currentStep: id,
        steps: state.steps.map((step) => (step.id === id ? { ...step, ...patch } : step)),
      };
    }
    
    export async function resolveSetupRoot(root?: string): Promise<string> {
      const configManager = await createConfigManager();
      const configuredRoot = configManager.getStackRoot();
      // Prefer an explicit root because setup may be used to adjust a non-default
      // stack. Fall back to saved stackRoot, then cwd to match existing control-plane commands.
      return resolve(root ?? configuredRoot ?? process.cwd());
    }
    
    export function stackEnvExists(rootDir: string): boolean {
      return existsSync(`${rootDir}/.env`);
    }
    
    export function writeSetupEnv(rootDir: string, values: Record<string, string>): void {
      // Use the shared upsert helper so setup preserves comments and unrelated
      // operator edits instead of rewriting the whole .env file.
      upsertEnvVars(`${rootDir}/.env`, values);
    }
  2. propr-dev commented on Jun 22, 2026

    @propr-dev
    ContributorAuthor

    🤖 AI processing has started for this issue using claude agent with claude-opus-4-8 model.

    I'll analyze the problem and work on a solution. This may take a few minutes.

    Processing Details:

    • Agent: claude
    • Model: claude-opus-4-8
    • Branch: 1599/claude-opus-4-8-add-setup-wizard-domain-m-20260622-0930-ge5
    • Base Branch: main
    • Worktree: issue-1599-20260622-0930-claude-opus-4-8-ge5

    🔍 Track Task Execution

  3. propr-dev commented on Jun 22, 2026

    @propr-dev
    ContributorAuthor

    🤖 AI processing has started for this issue using claude agent with claude-opus-4-8 model.

    I'll analyze the problem and work on a solution. This may take a few minutes.

    Processing Details:

    • Agent: claude
    • Model: claude-opus-4-8
    • Branch: 1599/claude-opus-4-8-add-setup-wizard-domain-m-20260622-0930-elf
    • Base Branch: 1599-epic-build-comprehensive-b5c
    • Worktree: issue-1599-20260622-0930-claude-opus-4-8-elf

    🔍 Track Task Execution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions