Commit Graph

49 Commits

Author SHA1 Message Date
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
Lukas May
c32bc553d0 test(03-02): add comprehensive tests for WorktreeManager adapter
- 23 tests covering all WorktreeManager operations
- Test setup creates temp git repos with initial commit
- CRUD tests: create, remove, list, get operations
- Diff tests: clean worktree, added/modified/deleted files
- Merge tests: clean merge, conflict detection, abort/cleanup
- Event emission tests for all 4 worktree events
- Edge case tests: no eventBus, uncommitted changes on remove
2026-01-30 19:30:30 +01:00
Lukas May
0cf2849993 feat(03-02): install simple-git and create WorktreeManager adapter with CRUD
- Install simple-git dependency for git operations
- Create SimpleGitWorktreeManager class implementing WorktreeManager port
- Implement create(), remove(), list(), get() methods
- EventBus optional dependency injection for emitting worktree events
- Worktrees stored in .cw-worktrees directory
2026-01-30 19:27:35 +01:00
Lukas May
99e44425a3 feat(03-01): create WorktreeManager port interface
- Worktree type for representing git worktrees
- WorktreeDiff type for change preview
- MergeResult type for merge operation results
- WorktreeManager interface (PORT) with CRUD, diff, and merge methods
- Full JSDoc documentation explaining port-adapter relationship

Covers requirements: GIT-01, GIT-02, GIT-03, GIT-04
2026-01-30 19:23:59 +01:00
Lukas May
9d7b90b238 feat(03-01): add git domain events to event system
- WorktreeCreatedEvent for worktree creation tracking
- WorktreeRemovedEvent for worktree cleanup tracking
- WorktreeMergedEvent for successful merge tracking
- WorktreeConflictEvent for merge conflict notification
- All events added to DomainEventMap union type
2026-01-30 19:23:06 +01:00
Lukas May
112cc231c7 feat(02-02): update exports and add cascade delete tests
- src/db/index.ts exports repository interfaces and adapters
- cascade.test.ts tests full hierarchy cascade behavior:
  - Delete initiative removes all phases, plans, tasks
  - Delete phase removes only its plans and tasks
  - Delete plan removes only its tasks
- All 45 repository tests passing
2026-01-30 19:11:31 +01:00
Lukas May
830aa4b03f test(02-02): add repository adapter tests
- createTestDatabase helper with in-memory SQLite schema
- initiative.test.ts: CRUD, defaults, not-found errors
- phase.test.ts: CRUD, FK constraint, findByInitiativeId ordering
- plan.test.ts: CRUD, FK constraint, findByPhaseId ordering
- task.test.ts: CRUD, FK constraint, findByPlanId ordering
- Fixed adapters to apply defaults and fetch inserted records
- All 42 tests passing
2026-01-30 14:53:15 +01:00
Lukas May
14e0f6f0f5 feat(02-02): create Drizzle repository adapters
- DrizzleInitiativeRepository: CRUD with nanoid ID generation
- DrizzlePhaseRepository: findByInitiativeId ordered by number
- DrizzlePlanRepository: findByPhaseId ordered by number
- DrizzleTaskRepository: findByPlanId ordered by order field
- All adapters use DI for DrizzleDatabase instance
- Timestamps set automatically on create/update
- Throws on update/delete of non-existent entities
2026-01-30 14:49:36 +01:00
Lukas May
5e5bca3d01 feat(02-02): create repository port interfaces
- InitiativeRepository: CRUD for initiative aggregate
- PhaseRepository: CRUD with findByInitiativeId ordered by number
- PlanRepository: CRUD with findByPhaseId ordered by number
- TaskRepository: CRUD with findByPlanId ordered by order field
- Re-export all interfaces from repositories/index.ts
2026-01-30 14:46:16 +01:00
Lukas May
b492f64348 feat(02-01): define task hierarchy schema
Schema defines 5 tables with proper foreign key relationships:
- initiatives: Top-level projects (active/completed/archived)
- phases: Major milestones within initiatives
- plans: Groups of related tasks within phases
- tasks: Individual work items with type, priority, status, order
- task_dependencies: Dependency relationships between tasks

All tables have cascade deletes and Unix timestamp fields.
Types exported: Initiative, Phase, Plan, Task, TaskDependency + New* variants.
Relations exported for Drizzle relational queries.
2026-01-30 14:24:41 +01:00
Lukas May
d7e4649e47 feat(02-01): create database connection factory
- src/db/config.ts: getDbPath() returns ~/.cw/data/cw.db with CW_DB_PATH override
- src/db/index.ts: createDatabase() factory with WAL mode and foreign keys
- drizzle.config.ts: Drizzle Kit configuration for migrations

Pattern: Factory function (not singleton) allows isolated test instances
2026-01-30 14:23:42 +01:00
Lukas May
d893fc5ede feat(01.1-06): update CLI status command and add integration tests
- Update status command to use tRPC client for server communication
- Display health status, uptime, and process count
- Handle connection errors gracefully with helpful message
- Add 7 integration tests proving full CLI-server tRPC flow
- Tests cover health procedure, status procedure, and error handling
2026-01-30 14:08:33 +01:00
Lukas May
9da12a890d feat(01.1-06): add tRPC HTTP adapter and CLI client
- Create src/server/trpc-adapter.ts with fetch adapter for node:http
- Create src/cli/trpc-client.ts with typed client factory functions
- Update CoordinationServer to route /trpc/* to tRPC handler
- Move @trpc/client from devDeps to regular deps
- Keep /health and /status HTTP endpoints for backwards compatibility
2026-01-30 14:07:31 +01:00
Lukas May
3b24cf2c9d feat(01.1-03): add event emission to ProcessManager
- ProcessManager accepts optional eventBus parameter
- Emit ProcessSpawned event after successful spawn
- Emit ProcessStopped event on normal exit (code 0)
- Emit ProcessCrashed event on non-zero exit with signal
- Add 4 tests verifying event emission behavior
- Backwards compatible: events only emitted if eventBus provided
2026-01-30 14:03:45 +01:00
Lukas May
bac133db7a feat(01.1-04): add event emission to ProcessLogWriter
- ProcessLogWriter accepts optional EventBus parameter
- Emits LogEntry events on writeStdout and writeStderr
- createLogger convenience function passes through eventBus
- Backwards compatible (eventBus is optional)
- 6 new tests verify event emission and optional behavior
2026-01-30 14:03:24 +01:00
Lukas May
1f255ee8e3 feat(01.1-05): add event emission to server and shutdown handler
- CoordinationServer accepts optional EventBus parameter
- Emit ServerStarted event on start (port, host, pid)
- Emit ServerStopped event on stop (uptime)
- Add event emission tests to server tests
- Add GracefulShutdown tests for shutdown() and install()
2026-01-30 14:03:24 +01:00
Lukas May
b556c10a69 test(01.1-03): add unit tests for ProcessRegistry and ProcessManager
- ProcessRegistry: 15 tests covering register, get, getAll, updateStatus, unregister, getByPid, clear
- ProcessManager: 16 tests covering spawn, stop, stopAll, restart, isRunning
- Mock execa module to avoid spawning real processes
- Test exit handler behavior for both normal exit and crash scenarios
2026-01-30 14:02:19 +01:00
Lukas May
17f4e61713 test(01.1-04): add unit tests for LogManager and ProcessLogWriter
- LogManager tests: ensureLogDir, ensureProcessDir, getProcessDir, getLogPath, listLogs, cleanOldLogs, getBaseDir
- ProcessLogWriter tests: open, writeStdout, writeStderr, close, append mode
- Uses temp directories for file system tests with proper cleanup
- 35 new tests covering all logging module functionality
2026-01-30 14:01:59 +01:00
Lukas May
ea79b3bf08 test(01.1-05): add comprehensive tests for CoordinationServer
- Test server lifecycle (start, stop, isRunning)
- Test HTTP endpoints (GET /health, GET /status, 404, 405)
- Test PID file management (create, remove, stale cleanup)
- Verify server throws on double-start or existing PID file
2026-01-30 14:01:48 +01:00
Lukas May
551e5163f0 feat(01.1-02): define tRPC procedures with Zod validation and tests
- Add health procedure: returns { status, uptime, processCount }
- Add status procedure: returns { server: {...}, processes: [] }
- Add Zod schemas for runtime output validation
- Export AppRouter type for client type-safety
- Add 16 tests for procedures and schema validation

SUMMARY: Type-safe tRPC contract established for CLI-server communication
2026-01-30 13:58:11 +01:00
Lukas May
437e76ed78 feat(01.1-01): define domain events with typed payloads and tests
- Add ProcessSpawnedEvent, ProcessStoppedEvent, ProcessCrashedEvent
- Add ServerStartedEvent, ServerStoppedEvent
- Add LogEntryEvent for stdout/stderr capture
- Create DomainEventMap union type for type-safe handling
- Add comprehensive tests for emit/on, once, off, multiple handlers
- Verify typed event payloads work correctly
2026-01-30 13:54:40 +01:00
Lukas May
83e6adb0f8 feat(01.1-01): create EventBus port interface and EventEmitter adapter
- Define EventBus interface (PORT) with emit, on, off, once methods
- Define base DomainEvent interface with type, timestamp, payload
- Implement EventEmitterBus class (ADAPTER) using Node.js EventEmitter
- Export createEventBus() factory function for easy instantiation
2026-01-30 13:53:43 +01:00
Lukas May
59b233792a feat(01-05): implement graceful shutdown with signal handlers
- GracefulShutdown class handles SIGTERM, SIGINT, SIGHUP
- 10-second timeout before force exit
- Double SIGINT forces immediate exit
- Shutdown sequence: stop HTTP server, stop processes, cleanup
- Integrates with CoordinationServer and ProcessManager
2026-01-30 13:23:58 +01:00
Lukas May
bec46aa234 feat(01-05): add HTTP server with health endpoint and PID file
- CoordinationServer class using node:http
- GET /health returns status, uptime, processCount
- GET /status returns full server state and process list
- PID file at ~/.cw/server.pid prevents duplicate servers
- CLI --server flag and --port option for server mode
- CW_PORT env var support for custom port
2026-01-30 13:22:35 +01:00
Lukas May
2f3df1d529 feat(01-03): create process manager with spawn/stop
- ProcessManager class with execa for child process spawning
- spawn() starts detached background processes
- stop() graceful shutdown with SIGTERM then SIGKILL after 5s timeout
- stopAll() terminates all managed processes
- restart() stops and respawns with same config
- isRunning() probes actual process state
- Proper promise handling for killed processes
2026-01-30 13:15:31 +01:00
Lukas May
fc410e212a feat(01-04): create per-process log writer
- ProcessLogWriter class for stdout/stderr capture
- Timestamps each line with [YYYY-MM-DD HH:mm:ss.SSS] format
- Backpressure handling via drain events
- getStdoutStream/getStderrStream for direct piping
- Module index exports types, classes, and createLogger helper
- createLogger convenience function for default config
2026-01-30 13:13:37 +01:00
Lukas May
40a66175a2 feat(01-03): create process types and registry
- ProcessInfo interface for tracking process metadata
- SpawnOptions interface for spawn configuration
- ProcessRegistry class with Map-based storage
- CRUD operations: register, unregister, get, getAll, getByPid, clear
- Additional helpers: updateStatus, size getter
2026-01-30 13:13:06 +01:00
Lukas May
e64e243407 feat(01-04): create log directory management
- LogLevel, LogEntry, LogConfig types in types.ts
- LogManager class with directory management
- Cross-platform paths using node:os and node:path
- ensureLogDir/ensureProcessDir for directory creation
- getLogPath returns ~/.cw/logs/{processId}/{stream}.log
- cleanOldLogs removes directories older than N days
- listLogs enumerates all process log directories
2026-01-30 13:12:55 +01:00
Lukas May
bf7ba668b1 feat(01-02): create CLI with commander
- Add createCli() function with commander configuration
- Register placeholder commands: status, agent, task
- Add graceful error handling for uncaught exceptions
- Read version from package.json via index.ts export
2026-01-30 13:12:54 +01:00
Lukas May
d284603694 chore(01-01): initialize TypeScript project with ESM
- Configure package.json with type: module, ESM-compatible setup
- Add dependencies: commander, execa
- Add devDependencies: typescript, tsx, rimraf, @types/node
- Configure tsconfig.json for ES2022/NodeNext
- Add .gitignore with node_modules and dist
- Create src/index.ts and src/bin/cw.ts placeholders
2026-01-30 13:09:43 +01:00