/** * useSpecGenerator - Event-based SpecGenerator wrapper for React/Ink TUI * * Wraps the existing SpecGenerator to emit events and manage state: * - phase_change -> update PhaseHeader * - tool_start / tool_end -> show ToolCallCard * - text_delta -> stream to StreamingText * - question -> prompt user input * - done -> complete flow */ import type { Message, ToolCall } from '../components/MessageList.js'; /** * Generator phases matching SpecGenerator */ export type GeneratorPhase = 'context' | 'goals' | 'interview' | 'generation' | 'complete'; /** * Phase configuration for display */ export interface PhaseConfig { /** Phase number (1-based) */ number: number; /** Human-readable phase name */ name: string; /** Description of what happens in this phase */ description: string; } /** * Phase configurations for display */ export declare const PHASE_CONFIGS: Record; /** * Total number of display phases (excludes 'complete' in progress bar) */ export declare const TOTAL_DISPLAY_PHASES = 4; /** * State managed by the useSpecGenerator hook */ export interface SpecGeneratorState { /** Current phase of the generation process */ phase: GeneratorPhase; /** Conversation history for MessageList */ messages: Message[]; /** Whether the AI is currently working (thinking/executing) */ isWorking: boolean; /** Status message for working indicator ("Thinking...", "Reading files...", etc.) */ workingStatus: string; /** Current AI question waiting for user answer */ currentQuestion: string; /** Whether waiting for user input */ awaitingInput: boolean; /** Final generated spec when done */ generatedSpec: string | null; /** Error message if something went wrong */ error: string | null; /** Number of interview questions completed */ questionCount: number; /** References added during context phase */ references: Array<{ source: string; content: string; }>; } /** * Options for initializing the spec generator */ export interface SpecGeneratorOptions { /** Name of the feature being specified */ featureName: string; /** Project root directory path */ projectRoot: string; /** AI provider to use */ provider?: string; /** Model ID to use */ model?: string; } /** * Return value from useSpecGenerator hook */ export interface UseSpecGeneratorReturn { /** Current state */ state: SpecGeneratorState; /** * Submit user's answer to the current question * Used during interview phase */ submitAnswer: (answer: string) => Promise; /** * Add a reference URL or file path during context phase */ addReference: (refUrl: string) => Promise; /** * Skip context/interview and go directly to generation */ skipToGeneration: () => Promise; /** * Move to the next phase */ advancePhase: () => void; /** * Reset to initial state */ reset: () => void; /** * Initialize the generator with options */ initialize: (options: SpecGeneratorOptions) => void; /** * Add a message to the conversation */ addMessage: (role: 'user' | 'assistant' | 'system', content: string, toolCalls?: ToolCall[]) => void; /** * Add a streaming message (assistant) that will be updated */ addStreamingMessage: (initialContent?: string, toolCalls?: ToolCall[]) => string; /** * Update the streaming message content */ updateStreamingMessage: (content: string) => void; /** * Mark the current streaming message as complete */ completeStreamingMessage: () => void; /** * Clear working state and re-enable input * Call this when AI response is complete and ready for next user input */ setReady: () => void; /** * Start a tool execution (shows ToolCallCard) */ startToolCall: (toolName: string, input: Record) => string; /** * Complete a tool execution */ completeToolCall: (toolId: string, output?: string, error?: string) => void; /** * Set the current phase (used by orchestrator) */ setPhase: (phase: GeneratorPhase) => void; /** * Set the generated spec (used by orchestrator on completion) */ setGeneratedSpec: (spec: string) => void; /** * Set an error state (used by orchestrator on error) */ setError: (error: string) => void; /** * Set working state with status message (used by orchestrator) */ setWorking: (isWorking: boolean, status: string) => void; } /** * useSpecGenerator - React hook wrapping SpecGenerator for TUI use * * This hook manages the state and provides actions for running the * spec generation flow in a React/Ink application. * * The hook does not directly instantiate SpecGenerator; instead, it * provides the state management and action handlers that a screen * component can use to orchestrate the flow. * * @example * ```tsx * function SpecGeneratorScreen({ featureName }: Props) { * const { state, submitAnswer, addReference, initialize } = useSpecGenerator(); * * useEffect(() => { * initialize({ featureName, projectRoot: process.cwd() }); * }, []); * * return ( * * * * {state.isWorking && } * {state.awaitingInput && } * * ); * } * ``` */ export declare function useSpecGenerator(): UseSpecGeneratorReturn;