Add architect workflow E2E tests for discuss mode:
- Test spawning architect in discuss mode with context_complete
- Test pause on questions and resume with answers flow
Add convenience methods for architect mode testing:
- setArchitectDiscussComplete for context_complete scenarios
- setArchitectDiscussQuestions for discuss mode questions
- setArchitectBreakdownComplete for breakdown_complete scenarios
- getInitiative, getPhases, createInitiative, createPhasesFromBreakdown
- mockAgentManager alias, advanceTimers, getEmittedEvents helpers
- Wire up initiative/phase repositories and tRPC caller to harness
Also fix pre-existing test issues with dependencies and type casting.
- Test findByNumber with matching/non-matching initiative and number
- Test getNextNumber returns 1 for empty initiative
- Test getNextNumber returns max + 1 with existing phases
- Test getNextNumber handles gaps in numbering
- Test default execute mode on spawn
- Test discuss mode with context_complete scenario
- Test breakdown mode with breakdown_complete scenario
- Verify stopped event reasons for each mode
Add CLI commands for initiative management:
- cw initiative create <name> - create with optional description
- cw initiative list - list all with optional status filter
- cw initiative get <id> - get details by ID
- Add spawnArchitectDiscuss for context-gathering mode
- Add spawnArchitectBreakdown for phase decomposition mode
- Both procedures validate initiative exists before spawning
- Use comprehensive prompts from agent/prompts module
- Add buildDiscussPrompt for context gathering mode
- Add buildBreakdownPrompt for phase decomposition mode
- Add buildExecutePrompt for standard task execution
- Export prompts from agent module index
- Import all mode-specific JSON schemas (discuss, breakdown)
- Add getJsonSchemaForMode() helper to select schema by mode
- Update spawn() to pass mode to repository and use mode-specific schema
- Refactor handleAgentCompletion() to route to mode-specific handlers
- Add handleExecuteOutput() for execute mode (existing behavior)
- Add handleDiscussOutput() for discuss mode (context_complete status)
- Add handleBreakdownOutput() for breakdown mode (breakdown_complete status)
- Update resume() to use mode-specific JSON schema
- Add context_complete scenario for discuss mode
- Add breakdown_complete scenario for breakdown mode
- Import Decision and PhaseBreakdown types from schema
- Handle context_complete status with decisions array
- Handle breakdown_complete status with phases array
- Extend AgentStoppedEvent reason type for new completion reasons
- Export questionItemSchema and add QuestionItem type
- Add Decision type for discuss mode (topic/decision/reason)
- Add PhaseBreakdown type for breakdown mode
- Create discussOutputSchema (questions/context_complete/error)
- Create breakdownOutputSchema (questions/breakdown_complete/error)
- Add discussOutputJsonSchema for Claude CLI --json-schema
- Add breakdownOutputJsonSchema for Claude CLI --json-schema
- Add findByNumber method to lookup phase by initiative and number
- Add getNextNumber method to get next available phase number
- Implement both methods in DrizzlePhaseRepository adapter
- Use drizzle-orm max() and and() for query construction
- Add AgentMode type: 'execute' | 'discuss' | 'breakdown'
- Add mode column to agents table with 'execute' default
- Update SpawnAgentOptions to accept optional mode
- Update AgentInfo interface to include mode field
- Update ClaudeAgentManager.toAgentInfo to map mode
- Fix MockAgentManager to include mode in spawn
- Fix dispatch manager tests to include mode
- Add findByStatus method to InitiativeRepository port interface
- Implement findByStatus in DrizzleInitiativeRepository adapter
- Filter initiatives by status (active/completed/archived)
- Tests agent asking two questions at once
- Verifies both questions present in pending questions
- Validates resume with answers for all questions
- Confirms task completes after batched answer resume
- Change resume() signature from (agentId, prompt) to (agentId, answers)
- Accept Record<string, string> mapping question IDs to user answers
- Clear pendingQuestions on resume
- Update mock-manager tests for new signature
- Change resume() signature from (agentId, prompt) to (agentId, answers)
- Accept Record<string, string> mapping question IDs to user answers
- Format answers as structured prompt for Claude CLI
- Update AgentManager interface in types.ts
- Update manager tests for new signature
- Change status from 'question' to 'questions' (plural)
- Add QuestionItem with id field for answer matching
- Update PendingQuestion to PendingQuestions with questions array
- Update AgentWaitingEvent payload to questions array
- Update ClaudeAgentManager and MockAgentManager adapters
- Update TestHarness and all test files
- Queue state survives in database (source of truth)
- In-progress task recoverable after agent crash
- Blocked task state persists and can be unblocked
- Merge queue state recoverable
- Question enters waiting state and completes after resume
- Question surfaces as structured PendingQuestion
- Agent resumes with answer and completes successfully
- Waiting agent status transitions correctly through full cycle
- Update MockAgentManager tests to use status-based scenarios
- Change outcome:'crash' to status:'unrecoverable_error' with error field
- Change outcome:'waiting_for_input' to status:'question' with question field
- Change outcome:'success' to status:'done' with result field
- Add tests for structured question data (options, multiSelect)
- Add tests for getPendingQuestion and resume clearing pending question
- Update E2E edge-cases tests with new scenario format
- Update harness tests with new scenario format
- Add setAgentDone() for done status scenarios
- Add setAgentQuestion() for question status scenarios
- Add setAgentError() for unrecoverable_error scenarios
- Add getPendingQuestion() to harness interface
- Import PendingQuestion type from agent/types
- Change MockAgentScenario from outcome-based to status-based discriminated union
- Align with agent output schema: done/question/unrecoverable_error
- Update completeAgent() to handle new status types
- Update resume() to use new scenario format
- Pass --json-schema flag to Claude CLI for validated output
- Parse discriminated union (done/question/unrecoverable_error) in handleAgentCompletion
- Add getPendingQuestion method to AgentManager interface
- Add PendingQuestion type for structured question data
- Store pending question in ActiveAgent for later retrieval
- Remove hacky string matching for waiting_for_input detection
- Update MockAgentManager with getPendingQuestion and options support
- Update tests for new CLI arguments and result format
- Discriminated union with done/question/unrecoverable_error status
- Options schema for structured question choices
- JSON schema export for Claude CLI --json-schema flag
- Type export for runtime validation
- Merge conflict detection with merge:conflicted event
- Conflict appears in queue state as conflicted
- handleConflict creates conflict-resolution task
- Successful merge after separate task without conflict
- Add 19 comprehensive test cases for TestHarness
- Test createTestHarness() returns all components
- Test seedFixture() creates hierarchies with correct IDs
- Test task dependencies resolved correctly
- Test event capture via getEventsByType/clearEvents
- Test dispatch flow with MockAgentManager
- Test agent completion triggers expected events
- Test full dispatch -> complete flow end-to-end
- Test MockWorktreeManager create/merge/setMergeResult
- Add TestHarness interface with all system components and helpers
- Add createTestHarness() factory wiring full system with mocks
- Add MockWorktreeManager (in-memory worktree simulation)
- Add CapturingEventBus (event capture for verification)
- Wire real DispatchManager and CoordinationManager with mocks
- Export all components via src/test/index.ts
- Add cw merge queue <taskId> to queue tasks for merge
- Add cw merge status to show merge queue status
- Add cw merge next to show next task ready to merge
- Add cw coordinate [--target <branch>] to process all ready merges
- Add coordinationManager to TRPCContext and CreateContextOptions
- Add requireCoordinationManager helper function
- Add queueMerge mutation for queuing tasks for merge
- Add processMerges mutation for processing merges in dependency order
- Add getMergeQueueStatus query for queue state inspection
- Add getNextMergeable query for next mergeable task
Adds MessageRepository to DefaultCoordinationManager for conflict notification:
- Creates info message to agent when merge conflict occurs
- Message includes conflicting file list and resolution instructions
- System-generated messages use senderType='user' with null senderId
- Refactors conflict description into cleaner array.join format