Commit Graph

30 Commits

Author SHA1 Message Date
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