Skip to content

Add the interactive Ink setup TUI #1602

Closed

Description

@propr-dev

Context

The setup screen must be interactive using Ink when the terminal supports it. The TUI should show setup progress, current step details, choices, and blocking warnings without forcing the user to inspect raw command output.

Requirements

  • Add an Ink component for setup progress.
  • Show every setup step with status, title, and current detail.
  • Provide a simple prompt bridge for confirm, input, single choice, and multi choice.
  • Use keyboard navigation for choices and text entry for inputs.
  • Exit cleanly when setup completes or is cancelled.

Implementation Specification

Create packages/cli/src/tui/SetupApp.tsx and add renderSetupWizard() to packages/cli/src/tui/app.tsx.

Acceptance Criteria

  • renderSetupWizard() resolves with final setup state.
  • The TUI updates as the engine emits state.
  • Ctrl-C cancels without leaving an Ink session running.

Created by ProPR AI Planner

Activity

  1. propr-dev commented on Jun 22, 2026

    @propr-dev
    ContributorAuthor

    Suggested Implementation:

    Implementation Approach

    The TUI wraps the setup engine rather than implementing setup behavior itself. This keeps the interactive path and fallback path consistent. A fully custom form framework was considered, but a compact prompt bridge is enough for this wizard and avoids adding another dependency. The trade-off is that text input is basic, but the first version remains maintainable.

    File: packages/cli/src/tui/SetupApp.tsx (new file)

    Why this file: This component is the setup-specific Ink presentation layer. It renders progress and bridges engine prompt requests to keyboard input.

    import React, { useEffect, useMemo, useState } from 'react';
    import { Box, Text, useApp, useInput } from 'ink';
    import { runSetupEngine, type SetupPrompts } from '../commands/setup/engine.js';
    import { createInitialSetupState } from '../commands/setup/state.js';
    import type { SetupDecision, SetupRunOptions, SetupWizardState } from '../commands/setup/types.js';
    
    interface Props {
      rootDir: string;
      options: SetupRunOptions;
      onDone: (state: SetupWizardState) => void;
    }
    
    type PromptRequest =
      | { kind: 'confirm'; message: string; defaultValue: boolean; resolve: (value: boolean) => void }
      | { kind: 'input'; message: string; value: string; resolve: (value: string) => void }
      | { kind: 'choose'; message: string; choices: Array<SetupDecision<string>>; selected: number; resolve: (value: string) => void }
      | { kind: 'multi'; message: string; choices: Array<SetupDecision<string>>; selected: number; values: Set<string>; resolve: (value: string[]) => void };
    
    const STATUS_TEXT = {
      pending: '[ ]',
      running: '[~]',
      complete: '[OK]',
      warning: '[!]',
      blocked: '[X]',
      skipped: '[-]',
    };
    
    function statusColor(status: string): string | undefined {
      if (status === 'complete') return 'green';
      if (status === 'warning') return 'yellow';
      if (status === 'blocked') return 'red';
      if (status === 'running') return 'cyan';
      return undefined;
    }
    
    export function SetupApp({ rootDir, options, onDone }: Props): React.ReactElement {
      const { exit } = useApp();
      const [state, setState] = useState(() => createInitialSetupState(rootDir, true));
      const [message, setMessage] = useState('');
      const [prompt, setPrompt] = useState<PromptRequest | null>(null);
    
      const prompts = useMemo<SetupPrompts>(() => ({
        confirm: (messageText, defaultValue = false) => new Promise((resolve) => {
          // Store the resolver in React state so the key handler can complete the
          // engine's promise without coupling engine code to Ink APIs.
          setPrompt({ kind: 'confirm', message: messageText, defaultValue, resolve });
        }),
        input: (messageText, defaultValue = '') => new Promise((resolve) => {
          setPrompt({ kind: 'input', message: messageText, value: defaultValue, resolve });
        }),
        choose: (messageText, choices, defaultValue) => new Promise((resolve) => {
          const selected = Math.max(0, choices.findIndex((choice) => choice.value === defaultValue));
          setPrompt({ kind: 'choose', message: messageText, choices, selected, resolve });
        }),
        multiChoose: (messageText, choices, defaults) => new Promise((resolve) => {
          setPrompt({ kind: 'multi', message: messageText, choices, selected: 0, values: new Set(defaults), resolve });
        }),
      }), []);
    
      useEffect(() => {
        let cancelled = false;
        void runSetupEngine(state, options, prompts, {
          onState: (next) => { if (!cancelled) setState(next); },
          onMessage: (nextMessage) => { if (!cancelled) setMessage(nextMessage); },
        }).then((finalState) => {
          if (cancelled) return;
          onDone(finalState);
          exit();
        }).catch((error: Error) => {
          if (cancelled) return;
          setMessage(`Setup failed: ${error.message}`);
        });
        return () => { cancelled = true; };
      // Run once. The engine owns progression and reports state through hooks.
      // eslint-disable-next-line react-hooks/exhaustive-deps
      }, []);
    
      useInput((input, key) => {
        if (key.ctrl && input === 'c') {
          exit();
          return;
        }
        if (!prompt) return;
    
        if (prompt.kind === 'confirm') {
          if (input.toLowerCase() === 'y') { prompt.resolve(true); setPrompt(null); }
          if (input.toLowerCase() === 'n') { prompt.resolve(false); setPrompt(null); }
          if (key.return) { prompt.resolve(prompt.defaultValue); setPrompt(null); }
          return;
        }
    
        if (prompt.kind === 'input') {
          if (key.return) { prompt.resolve(prompt.value); setPrompt(null); return; }
          if (key.backspace || key.delete) { setPrompt({ ...prompt, value: prompt.value.slice(0, -1) }); return; }
          if (input && !key.ctrl && !key.meta) setPrompt({ ...prompt, value: `${prompt.value}${input}` });
          return;
        }
    
        if (prompt.kind === 'choose' || prompt.kind === 'multi') {
          if (key.upArrow) setPrompt({ ...prompt, selected: (prompt.selected - 1 + prompt.choices.length) % prompt.choices.length });
          if (key.downArrow) setPrompt({ ...prompt, selected: (prompt.selected + 1) % prompt.choices.length });
          if (prompt.kind === 'multi' && input === ' ') {
            const value = prompt.choices[prompt.selected]?.value;
            const values = new Set(prompt.values);
            // Toggle instead of appending duplicates so the selected agent list stays
            // deterministic for image pulling and agent configuration later.
            if (values.has(value)) values.delete(value);
            else values.add(value);
            setPrompt({ ...prompt, values });
          }
          if (key.return) {
            if (prompt.kind === 'choose') prompt.resolve(prompt.choices[prompt.selected]!.value);
            else prompt.resolve([...prompt.values]);
            setPrompt(null);
          }
        }
      });
    
      return (
        <Box flexDirection="column">
          <Text bold>ProPR setup</Text>
          <Text dimColor>Stack root: {state.rootDir}</Text>
          <Box marginTop={1} flexDirection="column">
            {state.steps.map((step) => (
              <Text key={step.id} color={statusColor(step.status)}>
                {STATUS_TEXT[step.status]} {step.title}{step.detail ? ` - ${step.detail}` : ''}
              </Text>
            ))}
          </Box>
          {message ? <Box marginTop={1}><Text color="magenta">{message}</Text></Box> : null}
          {prompt ? (
            <Box marginTop={1} flexDirection="column">
              <Text color="cyan" bold>{prompt.message}</Text>
              {prompt.kind === 'confirm' ? <Text>Press y/n, or Enter for {prompt.defaultValue ? 'yes' : 'no'}.</Text> : null}
              {prompt.kind === 'input' ? <Text>&gt; {prompt.value}</Text> : null}
              {(prompt.kind === 'choose' || prompt.kind === 'multi') ? prompt.choices.map((choice, index) => {
                const active = index === prompt.selected;
                const checked = prompt.kind === 'multi' && prompt.values.has(choice.value);
                return <Text key={choice.value} color={active ? 'cyan' : undefined}>{active ? '>' : ' '} {prompt.kind === 'multi' ? (checked ? '[x]' : '[ ]') : ' '} {choice.label} - {choice.detail}</Text>;
              }) : null}
              {prompt.kind === 'multi' ? <Text dimColor>Space toggles, Enter continues.</Text> : null}
            </Box>
          ) : null}
        </Box>
      );
    }

    File: packages/cli/src/tui/app.tsx

    Why this file: This is the existing Ink entry layer. Adding renderSetupWizard here keeps all terminal UI render functions discoverable from one module.

    --- a/packages/cli/src/tui/app.tsx
    +++ b/packages/cli/src/tui/app.tsx
    @@
     import { AgentTableApp, AgentTableHub } from './AgentTableApp.js';
    +import { SetupApp } from './SetupApp.js';
    +import type { SetupRunOptions, SetupWizardState } from '../commands/setup/types.js';
    @@
     export async function renderAgentValidation(
    @@
     }
    +
    +export async function renderSetupWizard(rootDir: string, options: SetupRunOptions): Promise<SetupWizardState> {
    +  let finalState: SetupWizardState | undefined;
    +  const instance = render(
    +    <SetupApp rootDir={rootDir} options={options} onDone={(state) => { finalState = state; }} />,
    +    { exitOnCtrlC: false }
    +  );
    +  await instance.waitUntilExit();
    +  if (!finalState) {
    +    // Surface cancellation as an ordinary Error so the command action can print
    +    // a concise message and avoid pretending setup completed.
    +    throw new Error('setup cancelled');
    +  }
    +  return finalState;
    +}
  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: 1602/claude-opus-4-8-add-the-interactive-ink-s-20260622-1013-eiq
    • Base Branch: 1599-epic-build-comprehensive-b5c
    • Worktree: issue-1602-20260622-1013-claude-opus-4-8-eiq

    🔍 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