Commit Graph

724 Commits

Author SHA1 Message Date
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
f0db74cf8c docs(04-03): complete ClaudeAgentManager adapter plan
Tasks completed: 2/2
- Implement ClaudeAgentManager adapter
- Write tests for AgentManager

SUMMARY: .planning/phases/04-agent-lifecycle/04-03-SUMMARY.md
2026-01-30 20:08:55 +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
9ab6e5eb28 docs(04-01): complete agent schema & repository plan
Tasks completed: 3/3
- Add agents table to database schema
- Create AgentRepository port interface
- Create DrizzleAgentRepository adapter with tests

SUMMARY: .planning/phases/04-agent-lifecycle/04-01-SUMMARY.md
2026-01-30 20:02:42 +01:00
Lukas May
53259afb07 docs(04-02): complete AgentManager port & events plan
Tasks completed: 2/2
- Define AgentManager port interface and domain types
- Add agent lifecycle events to events module

SUMMARY: .planning/phases/04-agent-lifecycle/04-02-SUMMARY.md
2026-01-30 20:01:35 +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
ffe5acceff docs(04): update agent plans with names and CLI approach
Key changes:
- Add agent names (human-readable like 'gastown') instead of UUID-only
- Use Claude CLI with --output-format json instead of SDK streaming
- Session ID extracted from CLI JSON output, not SDK init message
- Add waiting_for_input status for AskUserQuestion scenarios
- Resume flow is for answering agent questions, not general resumption
- CLI commands use names as primary identifier
2026-01-30 19:53:29 +01:00
Lukas May
781fbd0b23 docs(04): create agent lifecycle phase plan
Phase 04: Agent Lifecycle
- 4 plans in 3 waves
- Wave 1 (parallel): 04-01 schema/repository, 04-02 port/events
- Wave 2: 04-03 ClaudeAgentManager adapter (Claude Agent SDK)
- Wave 3: 04-04 tRPC + CLI integration

Requirements covered:
- AGENT-01: Spawn new agent with task assignment
- AGENT-02: Stop running agent
- AGENT-03: List all agents with status
- AGENT-04: Session persistence via SDK session IDs
- AGENT-05: Background mode via Node.js event loop
- AGENT-07: JSON output via Claude Agent SDK
2026-01-30 19:43:28 +01:00
Lukas May
e19b14944c docs(03): complete git-integration phase 2026-01-30 19:33:22 +01:00
Lukas May
1a9df73139 docs(03-02): complete WorktreeManager adapter plan
Tasks completed: 3/3
- Install simple-git and create WorktreeManager adapter with CRUD
- Implement diff and merge operations (merged with Task 1)
- Write tests for WorktreeManager (23 tests)

SUMMARY: .planning/phases/03-git-integration/03-02-SUMMARY.md
2026-01-30 19:32:22 +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
b70c07caf2 docs(03-01): complete git events and worktree port plan
Tasks completed: 2/2
- Add git domain events to event types
- Create WorktreeManager port interface

SUMMARY: .planning/phases/03-git-integration/03-01-SUMMARY.md
2026-01-30 19:25:21 +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
e2567ded0a docs(03): create phase plan
Phase 03: Git Integration
- 2 plans in 2 waves
- 0 parallel, 2 sequential
- Ready for execution
2026-01-30 19:20:24 +01:00
Lukas May
115866ccc6 docs(02): complete data layer phase 2026-01-30 19:14:06 +01:00
Lukas May
71b132a61e docs(02-02): complete repository layer plan
Tasks completed: 4/4
- Create repository port interfaces
- Create Drizzle repository adapters
- Write repository tests
- Update exports and test cascade deletes

SUMMARY: .planning/phases/02-data-layer/02-02-SUMMARY.md
2026-01-30 19:13:04 +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
5347d3e681 docs(02-01): complete SQLite database setup plan
Tasks completed: 3/3
- Install Drizzle ORM and SQLite dependencies
- Create database connection factory
- Define task hierarchy schema

SUMMARY: .planning/phases/02-data-layer/02-01-SUMMARY.md
2026-01-30 14:25:58 +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
caf8bb0332 chore(02-01): install Drizzle ORM and SQLite dependencies
- drizzle-orm: Type-safe ORM for database operations
- better-sqlite3: Synchronous SQLite driver for Node.js
- @types/better-sqlite3: TypeScript types for better-sqlite3
- drizzle-kit: CLI tools for migrations (dev dependency)
2026-01-30 14:22:55 +01:00
Lukas May
0cbb690201 docs(02): create data layer phase plans
Phase 02: Data Layer
- 2 plans in 2 waves
- 02-01: Database foundation (Drizzle + SQLite setup, schema)
- 02-02: Repository layer (port interface, adapter, tests)
- Ready for execution
2026-01-30 14:14:09 +01:00
Lukas May
7c2664cfb7 docs(01.1-06): complete CLI-tRPC integration plan
Tasks completed: 2/2
- Add tRPC HTTP adapter and CLI client
- Update CLI status command and add integration tests

SUMMARY: .planning/phases/01.1-hexagonal-architecture/01.1-06-SUMMARY.md
Phase 1.1 complete: 131 tests, hexagonal architecture retrofitted
2026-01-30 14:10:36 +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
5c07a4c4cf docs(01.1-03): complete process module testing and events plan
Tasks completed: 2/2
- Write unit tests for ProcessRegistry and ProcessManager
- Refactor ProcessManager to emit events via event bus

SUMMARY: .planning/phases/01.1-hexagonal-architecture/01.1-03-SUMMARY.md
2026-01-30 14:04:57 +01:00
Lukas May
573a704230 docs(01.1-04): complete logging module tests and events plan
Tasks completed: 2/2
- Write unit tests for LogManager and ProcessLogWriter
- Add event emission to ProcessLogWriter

SUMMARY: .planning/phases/01.1-hexagonal-architecture/01.1-04-SUMMARY.md
2026-01-30 14:04:56 +01:00
Lukas May
63e603709d docs(01.1-05): complete server tests and events plan
Tasks completed: 2/2
- Write unit tests for CoordinationServer
- Add event emission to server and shutdown handler

SUMMARY: .planning/phases/01.1-hexagonal-architecture/01.1-05-SUMMARY.md
2026-01-30 14:04:47 +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
f2a7b3f77a docs(01.1-02): complete tRPC foundation plan
Tasks completed: 2/2
- Install tRPC dependencies and create router foundation
- Define procedures matching HTTP endpoints with tests

SUMMARY: .planning/phases/01.1-hexagonal-architecture/01.1-02-SUMMARY.md
2026-01-30 13:59:53 +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
e72ffdd800 docs(01.1-01): complete event bus foundation plan
Tasks completed: 3/3
- Install and configure Vitest test framework
- Create EventBus port interface and EventEmitter adapter
- Define domain events with typed payloads and tests

SUMMARY: .planning/phases/01.1-hexagonal-architecture/01.1-01-SUMMARY.md
2026-01-30 13:56:20 +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