Commit Graph

79 Commits

Author SHA1 Message Date
Lukas May
2c41e52029 fix(10-02): update downstream code for batched answers API
- Update resumeAgentInputSchema: prompt → answers (Record<string, string>)
- Update tRPC router to pass answers map
- Update CLI to accept JSON or single answer (fallback to q1 key)
- Update E2E tests for new resume signature
2026-01-31 18:03:00 +01:00
Lukas May
a9e46a2843 feat(10-02): update MockAgentManager for batched answers
- 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
2026-01-31 18:02:54 +01:00
Lukas May
d012680dbe feat(10-02): update ClaudeAgentManager for batched answers
- 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
2026-01-31 18:02:51 +01:00
Lukas May
185a125307 feat(10-03): add setAgentQuestion convenience helper
- Add single-question convenience method to TestHarness
- Wraps question in array for questions scenario
- Keeps setAgentQuestions for multi-question cases
2026-01-31 18:01:45 +01:00
Lukas May
151a4c99f7 feat(10-01): extend agent schema to multi-question array
- 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
2026-01-31 17:57:34 +01:00
Lukas May
62b13d8e84 test(09-02): add recovery and Q&A E2E scenario tests
- 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
2026-01-31 15:44:57 +01:00
Lukas May
878f2a28d7 test(09-01): create conflict hand-back round-trip E2E tests
- Full conflict cycle: detect conflict -> agent resolves -> merge succeeds
- Conflict resolution preserves original task context
- Multiple sequential conflicts resolved in order
- 3 conflict round-trip tests passing
2026-01-31 15:43:56 +01:00
Lukas May
565f9fdae9 test(08.1-02): update tests to use schema-aligned scenarios
- 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
2026-01-31 15:31:56 +01:00
Lukas May
8e38bd298b feat(08.1-02): add TestHarness convenience methods for scenarios
- 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
2026-01-31 15:29:27 +01:00
Lukas May
ead4614383 feat(08.1-02): update MockAgentManager to schema-aligned scenarios
- 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
2026-01-31 15:28:38 +01:00
Lukas May
3a3d3f4c08 feat(08.1-01): update AgentWaitingEvent with structured question data
- Add options array for predefined question choices
- Add multiSelect boolean for multi-selection questions
- Update dispatch manager test mock with getPendingQuestion
2026-01-31 15:25:11 +01:00
Lukas May
d9673d54a3 feat(08.1-01): update ClaudeAgentManager to use structured schema
- 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
2026-01-31 15:25:07 +01:00
Lukas May
41598f577f feat(08.1-01): define agent output schema with Zod
- 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
2026-01-31 15:21:09 +01:00
Lukas May
fd2f8ec9e3 test(08-01): add complex dependency flow test
- Multi-level dependency graph with COMPLEX_FIXTURE
- Complete 5 tasks sequentially with priority ordering
- Verify fixture dependencies stored in task_dependencies table
- Validate Task 4A depends on both Task 2A and Task 3A
2026-01-31 09:14:11 +01:00
Lukas May
ac0812861d docs(08-02): add E2E test module index
- Documents test module structure
- Lists test files and their purposes
2026-01-31 09:13:59 +01:00
Lukas May
ebeb538e21 test(08-02): add merge conflict scenario tests
- 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
2026-01-31 09:13:40 +01:00
Lukas May
6952e5e287 test(08-01): create E2E happy path test file
- Single task flow: queue -> dispatch -> complete
- Sequential dependencies: priority ordering, queue state
- Parallel dispatch: multiple agents, different tasks
- Full merge flow: task completion -> merge queue -> process
2026-01-31 09:13:26 +01:00
Lukas May
e0d8fc85c6 test(08-02): create E2E edge case tests for crash, waiting, and blocking
- Agent crash scenario: spawned -> crashed events, status not completed
- Agent waiting for input: waiting event with question, resume flow
- Task blocking: blocked list, event emission, not dispatchable
2026-01-31 09:12:45 +01:00
Lukas May
6cc9e7f6be test(07-02): write tests proving harness works
- 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
2026-01-31 08:49:38 +01:00
Lukas May
4424a46c80 feat(07-02): create test harness with full system wiring
- 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
2026-01-31 08:47:15 +01:00
Lukas May
ba1f7ccd62 feat(07-02): create fixture helpers for database seeding
- Add TaskFixture, PlanFixture, PhaseFixture, InitiativeFixture interfaces
- Add seedFixture() for creating complete task hierarchies with dependency resolution
- Add SeededFixture result type with name-to-ID mappings
- Add SIMPLE_FIXTURE (A -> B, C dependency chain)
- Add PARALLEL_FIXTURE (2 plans with independent tasks)
- Add COMPLEX_FIXTURE (cross-plan dependencies across 2 phases)
2026-01-31 08:46:22 +01:00
Lukas May
e305375820 test(07-01): add comprehensive tests for MockAgentManager
28 test cases covering:
- spawn() with default scenario (immediate success)
- spawn() with configured delay
- spawn() with crash scenario (agent:crashed, result.success=false)
- spawn() with waiting_for_input (agent:waiting, status='waiting_for_input')
- resume() after waiting_for_input (agent:resumed, continues scenario)
- stop() kills scheduled completion, emits agent:stopped
- list() returns all agents with correct status
- get() and getByName() lookups
- setScenario() overrides for specific agent names
- Event emission order verification (spawned before completion)
- Name uniqueness validation
- Constructor options (eventBus, defaultScenario)
- clear() cleanup

Export MockAgentManager and MockAgentScenario from src/agent/index.ts
2026-01-31 08:43:15 +01:00
Lukas May
6148af784e feat(07-01): implement MockAgentManager adapter
- MockAgentScenario interface with outcome, delay, message, filesModified, question
- Constructor takes optional eventBus and defaultScenario
- setScenario() for per-agent scenario overrides
- spawn() creates agent, schedules async completion based on scenario
- Emits all lifecycle events: agent:spawned, agent:stopped, agent:crashed, agent:waiting, agent:resumed
- stop() cancels pending completion, marks agent stopped
- resume() re-runs scenario for waiting_for_input agents
- getResult() returns stored result after completion
- clear() for test cleanup
2026-01-31 08:41:49 +01:00
Lukas May
ae8d303e5e feat(06-03): add merge and coordinate CLI commands
- 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
2026-01-30 21:13:29 +01:00
Lukas May
1a4de26966 feat(06-03): add coordination tRPC procedures
- 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
2026-01-30 21:12:48 +01:00
Lukas May
37a90db28c test(06-02): add comprehensive CoordinationManager tests
18 tests covering:
- Queue management (queueMerge, getQueueState)
- Dependency ordering (getNextMergeable with priority)
- Success path (processMerges with clean merges)
- Conflict handling (detect conflicts, create resolution task, send message)
- Error handling (missing repositories, missing agent)

Exports DefaultCoordinationManager from coordination module index.
2026-01-30 21:09:29 +01:00
Lukas May
4535707bc8 feat(06-02): enhance conflict bounce-back with agent messaging
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
2026-01-30 21:07:46 +01:00
Lukas May
6d7894bde4 feat(06-02): implement DefaultCoordinationManager adapter
Implements CoordinationManager interface with:
- In-memory merge queue with dependency tracking
- Dependency-ordered merging (getNextMergeable)
- Merge queue state tracking (queued, in_progress, merged, conflicted)
- Event emission for all merge lifecycle events
- Basic conflict handling (creates resolution task)
2026-01-30 21:06:54 +01:00
Lukas May
0570d21ad6 feat(06-01): add CoordinationManager port interface
- MergeQueueItem type for merge queue entries
- MergeStatus type: queued | in_progress | merged | conflict
- MergeResult type with task context
- CoordinationManager interface with methods:
  - queueMerge: queue completed task for merge
  - getNextMergeable: get next task with resolved dependencies
  - processMerges: process all ready merges
  - handleConflict: bounce-back for conflict resolution
  - getQueueState: query queue by status
2026-01-30 21:03:54 +01:00
Lukas May
94130a6661 feat(06-01): add coordination domain events for merge lifecycle
- MergeQueuedEvent: completed task queued for merge
- MergeStartedEvent: merge attempt begins
- MergeCompletedEvent: merge succeeds
- MergeConflictedEvent: merge has conflicts (triggers bounce-back)
2026-01-30 21:03:02 +01:00
Lukas May
211411e795 feat(05-05): add message and dispatch CLI commands
- Add message command group: list, read, respond
- Add dispatch command group: queue, next, status, complete
- Message list shows pending count and filters by agent/status
- Dispatch status shows ready tasks with priorities
2026-01-30 20:48:22 +01:00
Lukas May
e0e03eef86 feat(05-05): add message and dispatch tRPC procedures
- Add messageRepository and dispatchManager to TRPCContext
- Add requireMessageRepository and requireDispatchManager helpers
- Add message procedures: listMessages, getMessage, respondToMessage
- Add dispatch procedures: queueTask, dispatchNext, getQueueState, completeTask
2026-01-30 20:47:07 +01:00
Lukas May
364ffc357b test(05-04): add DispatchManager tests and wire up exports
- Add 14 comprehensive tests for DefaultDispatchManager
- Test queue(), getNextDispatchable(), completeTask(), blockTask()
- Test dispatchNext() with agent dispatch flow
- Test getQueueState() for queue visibility
- Test priority ordering and dependency scenario
- Export DefaultDispatchManager from dispatch module
2026-01-30 20:42:38 +01:00
Lukas May
e924fb655a feat(05-04): implement DefaultDispatchManager with dependency checking
- Add DefaultDispatchManager class implementing DispatchManager interface
- Implement queue() with task fetching and event emission
- Implement getNextDispatchable() with priority-based ordering
- Implement completeTask() and blockTask() with status updates
- Implement dispatchNext() for agent assignment
- Implement getQueueState() for queue visibility
- Use in-memory Map for queue management
2026-01-30 20:40:34 +01:00
Lukas May
19dc75c3f4 feat(05-01): add MessageRepository port and adapter
- Create MessageRepository port interface with CRUD and query methods
- Implement DrizzleMessageRepository adapter with nanoid generation
- Add findBySender/findByRecipient for participant-based queries
- Add findPendingForUser for unread user notifications
- Add findRequiringResponse for messages awaiting reply
- Add findReplies for message threading support
- Add 23 tests covering all operations and edge cases
- Update test-helpers with messages table schema
- Re-export from index files following AgentRepository pattern
2026-01-30 20:35:09 +01:00
Lukas May
586f7caa7a feat(05-02): add task CLI commands
- Add `cw task list --plan <planId>` command
  - Display tasks as table: name, status, type, priority
  - Show count of pending/in_progress/completed/blocked
- Add `cw task get <taskId>` command
  - Display full task details: id, name, description, type, priority, status, order, timestamps
- Add `cw task status <taskId> <status>` command
  - Validate status is one of: pending, in_progress, completed, blocked
  - Confirm status update
2026-01-30 20:34:57 +01:00
Lukas May
f54ec5e07e feat(05-03): add dispatch domain events
- TaskQueuedEvent for task queue operations
- TaskDispatchedEvent when task assigned to agent
- TaskCompletedEvent for task completion with success/failure
- TaskBlockedEvent for blocked tasks with reason
2026-01-30 20:33:36 +01:00
Lukas May
9f24c1ffc0 feat(05-02): add task tRPC procedures
- Add TaskRepository to TRPCContext (optional, same pattern as AgentManager)
- Add requireTaskRepository helper function
- Add listTasks procedure (query tasks by planId, ordered by order field)
- Add getTask procedure (get single task by ID, throws NOT_FOUND)
- Add updateTaskStatus procedure (update task status to pending/in_progress/completed/blocked)
2026-01-30 20:33:26 +01:00
Lukas May
b2e7c2920f feat(05-03): create DispatchManager port interface
- QueuedTask type with priority and dependencies
- DispatchResult type for dispatch operation outcomes
- DispatchManager interface with queue/dispatch/complete/block methods
- Follows hexagonal architecture pattern (same as EventBus, AgentManager)
2026-01-30 20:32:43 +01:00
Lukas May
f873a32ff4 feat(05-01): add messages table to schema
- Add messages table with sender/recipient pattern for agent-user communication
- Support message types: question, info, error, response
- Add requiresResponse flag and status tracking (pending, read, responded)
- Include parentMessageId for threading responses to original questions
- Add relations for sender/recipient agents and message threading
2026-01-30 20:32:31 +01:00
Lukas May
4d8916091f feat(04-04): add agent CLI commands
- Replace placeholder agent command with proper subcommands
- Add agent spawn command with --name, --task, --cwd options
- Add agent stop command to stop running agents
- Add agent list command to show all agents
- Add agent get command for detailed agent info
- Add agent resume command for waiting agents
- Add agent result command to get execution results
- All commands use tRPC client for type-safe communication
2026-01-30 20:13:01 +01:00
Lukas May
16f85cd22f feat(04-04): add agent procedures to tRPC router
- Add spawnAgentInputSchema for spawn input validation
- Add agentIdentifierSchema for name/id lookup
- Add resumeAgentInputSchema for resume operations
- Add resolveAgent helper for name/id resolution
- Add requireAgentManager helper for context validation
- Add 7 agent procedures: spawn, stop, list, get, getByName, resume, getResult
2026-01-30 20:11:59 +01:00
Lukas May
acf3b8dae3 feat(04-04): add AgentManager to tRPC context
- Import AgentManager type into context.ts
- Add optional agentManager field to TRPCContext interface
- Add optional agentManager to CreateContextOptions
- Update TrpcAdapterOptions with optional agentManager
- Pass agentManager through to createContext in adapter
2026-01-30 20:11:01 +01:00
Lukas May
b718d59cbf test(04-03): add comprehensive tests for ClaudeAgentManager
- Test spawn with worktree and agent record creation
- Test duplicate name rejection
- Test AgentSpawned event emission
- Test stop with subprocess kill and status update
- Test list, get, getByName operations
- Test resume with session_id and --resume flag
- Test AgentResumed event emission
- Fix: use agent.id from repository for activeAgents tracking
2026-01-30 20:07:28 +01:00
Lukas May
81934237ca feat(04-03): implement ClaudeAgentManager adapter
- Use Claude CLI with --output-format json for agent spawning
- Extract session_id from JSON result for resume capability
- Emit lifecycle events: spawned, stopped, crashed, resumed, waiting
- Handle waiting_for_input status for AskUserQuestion pauses
- Uses WorktreeManager for isolated agent workspaces
2026-01-30 20:05:03 +01:00
Lukas May
25f98fcbe1 feat(04-01): create DrizzleAgentRepository adapter with tests
- Implement DrizzleAgentRepository with all AgentRepository methods
- Add findByName, findByTaskId, findBySessionId lookups
- Add findByStatus for filtering including waiting_for_input
- Add updateStatus and updateSessionId for state changes
- Add agents table to test-helpers.ts SQL
- Export DrizzleAgentRepository from drizzle/index.ts
- 22 tests covering all operations and edge cases
2026-01-30 20:01:00 +01:00
Lukas May
ddc6f3b4e7 feat(04-02): add agent lifecycle events to events module
- AgentSpawnedEvent for new agent creation
- AgentStoppedEvent with reason (user_requested, task_complete, error, waiting_for_input)
- AgentCrashedEvent for unexpected failures
- AgentResumedEvent for session resumption
- AgentWaitingEvent when agent pauses on AskUserQuestion
- Updated DomainEventMap union with all agent events
2026-01-30 19:59:37 +01:00
Lukas May
eec5f1398e feat(04-01): create AgentRepository port interface
- Define AgentRepository interface with CRUD operations
- Add findByName, findByTaskId, findBySessionId for lookups
- Add findByStatus for filtering by agent state
- Add updateStatus and updateSessionId for state changes
- Export AgentStatus type
- Export from repositories barrel file
2026-01-30 19:59:04 +01:00
Lukas May
88889700c2 feat(04-02): define AgentManager port interface and domain types
- AgentStatus type for agent lifecycle states
- SpawnAgentOptions for spawn configuration
- AgentInfo for agent state representation
- AgentResult for execution results
- AgentManager interface with spawn, stop, list, get, getByName, resume, getResult
2026-01-30 19:58:55 +01:00
Lukas May
dfaa51076b feat(04-01): add agents table to database schema
- Define agents table with id, name (unique), taskId, sessionId, worktreeId, status
- Status enum: idle, running, waiting_for_input, stopped, crashed
- Foreign key to tasks with onDelete: 'set null' (agent may outlive task)
- Add agentsRelations linking to tasks
- Export Agent and NewAgent types
2026-01-30 19:58:35 +01:00