---
phase: 01-core-infrastructure
plan: 04
type: execute
wave: 2
depends_on: ["01-01"]
files_modified: [src/logging/types.ts, src/logging/writer.ts, src/logging/manager.ts, src/logging/index.ts]
autonomous: true
---
Create file-based logging infrastructure for per-process stdout/stderr capture.
Purpose: Each agent process needs its own log files. This creates the logging infrastructure that agent processes will use.
Output: LogManager that creates and manages per-process log files in a dedicated directory.
@~/.claude/get-shit-done/workflows/execute-plan.md
@~/.claude/get-shit-done/templates/summary.md
@.planning/PROJECT.md
@.planning/ROADMAP.md
@.planning/STATE.md
Task 1: Create log directory management
src/logging/types.ts, src/logging/manager.ts
Create src/logging/types.ts:
- LogLevel: 'debug' | 'info' | 'warn' | 'error'
- LogEntry: { timestamp: Date, level: LogLevel, processId: string, message: string }
- LogConfig: { baseDir: string, maxFileSize?: number, retainDays?: number }
Create src/logging/manager.ts:
- LogManager class:
- constructor(config: LogConfig) - baseDir defaults to ~/.cw/logs
- ensureLogDir(): Promise - creates log directory if not exists
- getLogPath(processId: string, stream: 'stdout' | 'stderr'): string
- cleanOldLogs(retainDays: number): Promise - removes logs older than N days
- listLogs(): Promise - lists all log files
Use node:fs/promises for all file operations.
Use node:path and node:os for cross-platform paths.
Log directory structure: ~/.cw/logs/{processId}/stdout.log, stderr.log
LogManager creates ~/.cw/logs directory, returns correct paths
Log directory management works, paths are cross-platform correct
Task 2: Create per-process log writer
src/logging/writer.ts, src/logging/index.ts
Create src/logging/writer.ts:
- ProcessLogWriter class:
- constructor(processId: string, logManager: LogManager)
- open(): Promise - opens file handles for stdout/stderr
- writeStdout(data: string | Buffer): Promise
- writeStderr(data: string | Buffer): Promise
- close(): Promise - flushes and closes file handles
- getStdoutStream(): fs.WriteStream
- getStderrStream(): fs.WriteStream
Use fs.createWriteStream with { flags: 'a' } for append mode.
Add timestamps to each line of output.
Handle backpressure properly (pause source if drain needed).
Create src/logging/index.ts:
- Export LogManager, ProcessLogWriter, types
- Export createLogger(processId: string) convenience function
ProcessLogWriter creates files, writes stdout/stderr with timestamps
Per-process logging captures output to separate files with timestamps
Before declaring plan complete:
- [ ] `npm run build` succeeds
- [ ] LogManager creates ~/.cw/logs/ directory
- [ ] ProcessLogWriter creates per-process log files
- [ ] Stdout and stderr go to separate files
- [ ] Log entries include timestamps
- [ ] File handles close properly (no resource leaks)
- All tasks completed
- All verification checks pass
- Logging infrastructure ready for agent process output capture
- Satisfies INFRA-05 (basic logging captures stdout/stderr per agent)