Commit Graph

257 Commits

Author SHA1 Message Date
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
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
03d55276a6 chore(01.1-01): install and configure Vitest test framework
- Add vitest as dev dependency
- Create vitest.config.ts with globals, TypeScript support, coverage
- Add npm scripts: test, test:watch, test:coverage
2026-01-30 13:53:00 +01:00
Lukas May
655fc296b6 docs(01.1): update roadmap and state with plan details
- 6 plans in 3 waves documented
- Wave structure: parallel foundation → parallel refactors → integration
- Ready for execution
2026-01-30 13:50:10 +01:00
Lukas May
5c5632dccf docs(01.1): create phase plan
Phase 01.1: Hexagonal Architecture
- 6 plans in 3 waves
- Wave 1: Event bus + tRPC foundation (parallel)
- Wave 2: Process, logging, server module refactors (parallel)
- Wave 3: CLI tRPC integration
- Ready for execution
2026-01-30 13:49:07 +01:00
Lukas May
1da8e4f795 docs(1.1): capture phase context
Phase 1.1: Hexagonal Architecture
- Vision and goals documented
- Essential requirements identified
- Scope boundaries defined
2026-01-30 13:42:53 +01:00
Lukas May
2d021ffa02 docs(01): complete core-infrastructure phase 2026-01-30 13:29:11 +01:00
Lukas May
6f64ec3e8c docs(01-05): complete server mode plan
Tasks completed: 2/2
- HTTP server with health endpoint and PID file
- Graceful shutdown with signal handlers

SUMMARY: .planning/phases/01-core-infrastructure/01-05-SUMMARY.md

Phase 1 (Core Infrastructure) complete.
2026-01-30 13:28:15 +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
f117227fed docs(01-04): complete logging infrastructure plan
Tasks completed: 2/2
- Create log directory management
- Create per-process log writer

SUMMARY: .planning/phases/01-core-infrastructure/01-04-SUMMARY.md
2026-01-30 13:18:17 +01:00
Lukas May
3e7b9f24bd docs(01-03): complete process management plan
Tasks completed: 2/2
- Create process types and registry
- Create process manager with spawn/stop

SUMMARY: .planning/phases/01-core-infrastructure/01-03-SUMMARY.md
2026-01-30 13:17:03 +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
57a4d938fa docs(01-02): complete CLI entry point plan
Tasks completed: 2/2
- Create CLI with commander
- Enable global installation via npm link

SUMMARY: .planning/phases/01-core-infrastructure/01-02-SUMMARY.md
2026-01-30 13:14:28 +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