Commit Graph

146 Commits

Author SHA1 Message Date
Lukas May
e5d8dbb583 feat(20): add SSE streaming support and subscription procedures
Fix tRPC HTTP adapter to stream ReadableStream responses instead of
buffering (required for SSE). Create subscriptions module that bridges
EventBus domain events into tRPC async generator subscriptions using a
queue-based pattern. Add three subscription procedures: onEvent (all
events), onAgentUpdate (agent lifecycle), onTaskUpdate (task/phase).
2026-02-04 22:16:14 +01:00
Lukas May
9d7002d2bd fix(19): wire AgentManager into server tRPC context
AgentManager was never instantiated or passed to the CoordinationServer,
causing all agent-related tRPC procedures to throw "Agent manager not
available". Creates DrizzleAgentRepository, SimpleGitWorktreeManager,
and ClaudeAgentManager in startServer() and passes agentManager into
the server context deps.
2026-02-04 22:03:09 +01:00
Lukas May
049810ffae fix(19): gracefully handle missing agentManager in read-only agent procedures
listWaitingAgents, listAgents, and getAgentQuestions now return empty
results instead of throwing when agentManager is not wired into the
tRPC context. Mutation procedures (spawn, stop, resume) still throw.
2026-02-04 22:00:34 +01:00
Lukas May
004140ea83 feat(19-01): add getAgentQuestions and listWaitingAgents tRPC procedures
- getAgentQuestions returns structured PendingQuestions from AgentManager
- listWaitingAgents filters agents to waiting_for_input status
- Updated JSDoc procedure list with both new procedures
2026-02-04 21:51:25 +01:00
Lukas May
cbf0ed28cb fix: wire database and repositories into server startup for tRPC context
The server never created a database or instantiated repositories, so all
tRPC procedures requiring initiativeRepository (and other repos) threw
"Initiative repository not available" on every request.

- Create ensureSchema() for shared database table initialization
- Extend TrpcAdapterOptions to accept all repository/manager dependencies
- Add ServerContextDeps to CoordinationServer for dependency injection
- Wire database, schema, and repositories in CLI startServer()
- Refactor test-helpers to use shared ensureSchema()
2026-02-04 21:18:30 +01:00
Lukas May
93f2b0f5ee fix(16-05): wire eventBus into CLI server startup
startServer() was creating CoordinationServer without an EventBus,
causing all tRPC requests to fail with "Server not initialized or
missing eventBus". Create and pass EventBus through to both
ProcessManager and CoordinationServer.
2026-02-04 20:48:37 +01:00
Lukas May
0d5645f9c8 feat(16-03): wire tRPC React Query client with providers
Create tRPC client with httpBatchLink targeting /trpc (Vite proxy).
Wrap app in trpc.Provider and QueryClientProvider with sensible
defaults. Add health check query to App.tsx for connection
verification. Add vite-env.d.ts for CSS module types. Remove
unused Plan import from backend router.
2026-02-04 18:07:15 +01:00
Lukas May
1aac486f48 test(14-07): add DefaultPhaseDispatchManager tests
- Add queuePhase tests (add to queue, emit event, include deps)
- Add getNextDispatchablePhase tests (empty, no deps first, skip incomplete, oldest)
- Add dispatchNextPhase tests (update status, emit event, remove from queue)
- Add completePhase tests (update status, remove from queue, emit event)
- Add blockPhase tests (update status, add to blocked, emit event)
- Add dependency scenario test (diamond dependency pattern)
2026-02-02 13:48:35 +01:00
Lukas May
03fefd896a test(14-08): add phase dispatch E2E tests
- Test independent phases dispatch in parallel
- Test dependent phase waits for prerequisite
- Test diamond dependency pattern (A -> B,C -> D)
- Test blocked phase prevents dispatch
- Test blocked phase propagates down dependency chain
2026-02-02 13:48:28 +01:00
Lukas May
38ee2d17c4 feat(14-08): add phaseDispatchManager to TestHarness
- Import PhaseDispatchManager type and DefaultPhaseDispatchManager
- Add phaseDispatchManager property to TestHarness interface
- Wire DefaultPhaseDispatchManager with phaseRepository and eventBus
2026-02-02 13:47:09 +01:00
Lukas May
26778c60f5 test(14-07): add PhaseRepository dependency tests
- Add createDependency tests (create, FK constraint, multiple deps)
- Add getDependencies tests (empty, with deps, direct only)
- Add getDependents tests (empty, with dependents, direct only)
- Add phase_dependencies table to test-helpers.ts
2026-02-02 13:46:53 +01:00
Lukas May
8ad262d05e feat(cli): add phase dependency and dispatch commands
Add phase command group with dependency management and dispatch operations:
- cw phase add-dependency: Create dependency between phases
- cw phase dependencies: List dependencies for a phase
- cw phase queue: Queue phase for execution
- cw phase dispatch: Dispatch next available phase
- cw phase queue-status: Show queued, ready, and blocked phases
2026-02-02 13:43:52 +01:00
Lukas May
5e6d507eb8 feat(14-05): add phase dependency and dispatch procedures
- Import PhaseDispatchManager type from dispatch module
- Add requirePhaseDispatchManager helper function
- Add createPhaseDependency: creates dependency between two phases
- Add getPhaseDependencies: returns phase IDs that a phase depends on
- Add queuePhase: queues phase for dispatch
- Add dispatchNextPhase: dispatches next available phase
- Add getPhaseQueueState: returns phase queue state

All procedures follow existing naming conventions and error handling patterns.
2026-02-02 13:40:51 +01:00
Lukas May
053168f6cf feat(14-04): export DefaultPhaseDispatchManager from dispatch module
- Add export for phase dispatch adapter
- Consistent with DefaultDispatchManager export pattern
2026-02-02 13:40:33 +01:00
Lukas May
1ba95871f5 feat(14-04): implement DefaultPhaseDispatchManager adapter
- In-memory queue with Map<string, QueuedPhase>
- Dependency checking via phaseRepository.getDependencies()
- queuePhase: fetch phase, get dependencies, emit PhaseQueuedEvent
- getNextDispatchablePhase: filter queue, sort by queuedAt
- dispatchNextPhase: update status to in_progress, emit PhaseStartedEvent
- completePhase: update status to completed, emit PhaseCompletedEvent
- blockPhase: update status to blocked, emit PhaseBlockedEvent
- getPhaseQueueState: return queued, ready, blocked arrays
2026-02-02 13:40:17 +01:00
Lukas May
28622cbd04 feat(14-05): add PhaseDispatchManager to tRPC context
- Import PhaseDispatchManager type from dispatch module
- Add optional phaseDispatchManager to TRPCContext interface
- Add phaseDispatchManager to CreateContextOptions
- Wire phaseDispatchManager through createContext function

Includes blocking fix: added 'blocked' status to phases schema enum
2026-02-02 13:39:47 +01:00
Lukas May
a890df75d5 feat(14-03): export phase dispatch types from dispatch module
- Export QueuedPhase interface
- Export PhaseDispatchResult interface
- Export PhaseDispatchManager port interface
2026-02-02 13:36:25 +01:00
Lukas May
22cd82da40 feat(14-03): define PhaseDispatchManager port interface
- Add QueuedPhase interface (phaseId, initiativeId, queuedAt, dependsOn)
- Add PhaseDispatchResult interface (success, phaseId, reason)
- Add PhaseDispatchManager interface with queue/dispatch operations
- Methods mirror DispatchManager for consistency
2026-02-02 13:36:12 +01:00
Lukas May
e8ee7f39d7 feat(14-02): export phase events from events module
- PhaseQueuedEvent
- PhaseStartedEvent
- PhaseCompletedEvent
- PhaseBlockedEvent
2026-02-02 13:33:32 +01:00
Lukas May
8e68a6e89e feat(14-01): add dependency methods to PhaseRepository
- Add createDependency(phaseId, dependsOnPhaseId) to interface and adapter
- Add getDependencies(phaseId) returning IDs of phases this phase depends on
- Add getDependents(phaseId) returning IDs of phases that depend on this phase
- Import phaseDependencies table in DrizzlePhaseRepository
- Follow exact pattern from DrizzleTaskRepository.createDependency
2026-02-02 13:33:16 +01:00
Lukas May
cd02439ca9 feat(14-02): add phase domain events
- PhaseQueuedEvent for tracking phases awaiting execution
- PhaseStartedEvent for phase execution start
- PhaseCompletedEvent for phase completion with success flag
- PhaseBlockedEvent for blocked phases with reason
2026-02-02 13:32:24 +01:00
Lukas May
a55d08fffe feat(14-01): add phase_dependencies table to schema
- Add phase_dependencies table mirroring task_dependencies pattern
- Add phaseId and dependsOnPhaseId FK columns with cascade delete
- Add phasesRelations with dependsOn and dependents many relations
- Add phaseDependenciesRelations with phase and dependsOnPhase one relations
- Export PhaseDependency and NewPhaseDependency types
2026-02-02 13:32:19 +01:00
Lukas May
accbaca49d docs(13-01): document Claude CLI structured_output findings
- Add proper test timeouts (120s for real API calls)
- Document key finding: result field is empty, structured_output has data
- Add validation cost estimates (~$0.025 per simple call)
- Confirm MockAgentManager accurately simulates real CLI behavior
2026-02-02 10:40:05 +01:00
Lukas May
5605547aea fix(13-01): parse structured_output from Claude CLI response
- Add structured_output field to ClaudeCliResult interface
- Read from structured_output when present (--json-schema response)
- Fall back to parsing result for backwards compatibility
2026-02-02 10:38:10 +01:00
Lukas May
3c98dbe541 test(13-01): create real Claude CLI integration tests
- Add test file for validating JSON schemas with real Claude CLI
- Tests are skipped by default (REAL_CLAUDE_TESTS=1 to enable)
- Covers execute, discuss, breakdown, and decompose modes
- Helper function callClaudeCli() handles CLI invocation
2026-02-02 10:37:40 +01:00
Lukas May
9b370a2617 test(12-08): add E2E tests for decompose workflow
- Add tests for spawn decompose agent with completion
- Add tests for Q&A flow with questions and resume
- Add tests for multiple questions handling
- Add tests for task persistence from decomposition
- Add tests for all task types (auto, checkpoint variants)
- Add tests for task dependencies
- Add full workflow test: initiative -> phase -> plan -> decompose -> tasks
2026-02-01 11:56:55 +01:00
Lukas May
4263c0884e feat(12-08): add TestHarness decompose mode helpers
- Add setArchitectDecomposeComplete and setArchitectDecomposeQuestions helpers
- Add planRepository to harness for plan operations
- Add createPlan and getTasksForPlan convenience methods
- Import TaskBreakdown and Plan types
2026-02-01 11:55:28 +01:00
Lukas May
a61530359a test(12-07): add PlanRepository getNextNumber tests
Add tests for getNextNumber method:
- Returns 1 for phase with no plans
- Returns max + 1 for phase with existing plans
- Not affected by plans in other phases
2026-02-01 11:54:43 +01:00
Lukas May
a79b15376e test(12-07): add MockAgentManager decompose mode tests
Add tests for decompose mode scenarios:
- Spawn agent in decompose mode
- Complete with tasks on decompose_complete
- Pause on questions in decompose mode
- Emit stopped event with decompose_complete reason
- Set result message with task count
2026-02-01 11:54:20 +01:00
Lukas May
6a2b835fdf feat(12-06): add plan CLI commands and architect decompose command
Add CLI commands for plan management:
- cw plan list --phase <id>: List plans in a phase
- cw plan create --phase <id> --name <name>: Create a plan
- cw plan get <id>: Get plan details
- cw plan tasks <id>: List tasks in a plan

Add architect decompose command:
- cw architect decompose <planId>: Spawn agent to decompose plan into tasks
2026-02-01 11:51:54 +01:00
Lukas May
1fcbdf5e10 feat(12-05): add spawnArchitectDecompose tRPC procedure
- Import buildDecomposePrompt from agent prompts
- Add spawnArchitectDecompose procedure for decompose mode
- Validates plan and phase exist before spawning
- Spawns agent with decompose mode and comprehensive prompt
2026-02-01 11:50:35 +01:00
Lukas May
7ff979becf feat(12-05): export buildDecomposePrompt from agent module
- Add buildDecomposePrompt to public exports
2026-02-01 11:49:57 +01:00
Lukas May
48336ec39d feat(12-05): create buildDecomposePrompt function
- Add buildDecomposePrompt for decompose mode agent operations
- Import Phase and Plan types from schema
- Comprehensive prompt explaining task breakdown rules, types, and output format
2026-02-01 11:49:45 +01:00
Lukas May
66ad2ec6ef feat(12-04): add createTasksFromDecomposition procedure
- Add createDependency method to TaskRepository interface
- Implement createDependency in DrizzleTaskRepository
- Add createTasksFromDecomposition procedure for bulk task creation
- Procedure verifies plan exists before creating tasks
- Creates tasks in order, building number-to-ID map
- Creates task dependencies after all tasks exist
- Dependencies mapped from task numbers to IDs
2026-02-01 11:46:49 +01:00
Lukas May
612744580e feat(12-04): add Plan tRPC procedures
- Import PlanRepository type
- Add requirePlanRepository helper
- Add createPlan procedure (auto-assigns number if not provided)
- Add listPlans procedure (returns plans ordered by number)
- Add getPlan procedure (throws NOT_FOUND if not found)
- Add updatePlan procedure (name, description, status)
2026-02-01 11:45:32 +01:00
Lukas May
c98e9df486 feat(12-04): add PlanRepository to tRPC context
- Import PlanRepository type from repositories
- Add planRepository?: PlanRepository to TRPCContext type
- Add planRepository to CreateContextOptions
- Update createContext to include planRepository
2026-02-01 11:44:46 +01:00
Lukas May
2bd0bc52a3 feat(12-03): add decompose mode support to MockAgentManager
- Import TaskBreakdown from schema.ts
- Add decompose_complete status to MockAgentScenario type
- Update completeAgent() to handle decompose_complete scenarios
- Emit agent:stopped with reason 'decompose_complete' for E2E testing
2026-02-01 11:44:40 +01:00
Lukas May
8754cdea98 feat(12-03): add decompose mode support to ClaudeAgentManager
- Import decomposeOutputSchema and decomposeOutputJsonSchema from schema.ts
- Update getJsonSchemaForMode() to handle 'decompose' mode
- Add handleDecomposeOutput() method following pattern of handleBreakdownOutput()
- Update handleAgentCompletion() switch to call handleDecomposeOutput for decompose mode
- Handle decompose_complete/questions/unrecoverable_error statuses
2026-02-01 11:43:55 +01:00
Lukas May
fe3fed077e feat(12-03): extend AgentStoppedEvent reason with decompose_complete
- Add 'decompose_complete' to AgentStoppedEvent reason type union
- Follows pattern established in Phase 11 for context_complete/breakdown_complete
2026-02-01 11:38:56 +01:00
Lukas May
8ffa54a531 feat(12-01): create decompose output schema
- Add TaskBreakdown type with number, name, description, type, dependencies
- Create decomposeOutputSchema discriminated union (questions/decompose_complete/error)
- Create decomposeOutputJsonSchema for Claude CLI --json-schema flag
- Update module docstring to include decompose mode
2026-02-01 11:34:31 +01:00
Lukas May
8da4e71075 feat(12-01): extend AgentMode with 'decompose'
- Add 'decompose' to AgentMode union type
- Update agents table mode column enum in database schema
- Update test-helpers.ts CREATE_TABLES_SQL with CHECK constraint
- Add missing getNextNumber implementation (blocking fix)
2026-02-01 11:32:18 +01:00
Lukas May
3187e2ab01 feat(12-02): implement getNextNumber in DrizzlePlanRepository
- Import max from drizzle-orm for aggregate query
- Query MAX(number) where phase_id matches
- Return max + 1, or 1 if no plans exist
- Pattern follows DrizzlePhaseRepository.getNextNumber
2026-02-01 11:31:30 +01:00
Lukas May
0044fbfc6e feat(12-02): add getNextNumber to PlanRepository interface
- Add getNextNumber(phaseId) method signature
- Returns MAX(number) + 1, or 1 if no plans exist
- Following pattern from PhaseRepository.getNextNumber
2026-02-01 11:30:27 +01:00
Lukas May
47b462362a test(11-08): add E2E tests for breakdown mode and full workflow
Add architect workflow E2E tests:
- Breakdown mode: spawn architect, complete with phases
- Phase persistence: create and retrieve phases from breakdown output
- Full workflow: discuss -> breakdown -> phase persistence
2026-01-31 19:28:22 +01:00
Lukas May
ae130e919f test(11-08): add E2E tests for architect discuss mode
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
2026-01-31 19:27:26 +01:00
Lukas May
021937c28d feat(test): add TestHarness architect mode helpers and tRPC caller
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.
2026-01-31 19:26:46 +01:00
Lukas May
1f4a95df4a test(db): add PhaseRepository findByNumber and getNextNumber tests
- 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
2026-01-31 19:24:09 +01:00
Lukas May
de57c15666 test(db): add InitiativeRepository findByStatus tests
- Test empty array for no matches
- Test filtering by active/completed/archived status
2026-01-31 19:23:44 +01:00
Lukas May
567d863a4a test(agent): add MockAgentManager mode tests
- 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
2026-01-31 19:23:22 +01:00
Lukas May
173ed57d2c feat(cli): add initiative phases command
Add cw initiative phases <initiativeId> to list phases for an initiative.
Displays phase number, name, status, and description.
2026-01-31 19:20:38 +01:00