---
phase: 01-core-infrastructure
plan: 03
type: execute
wave: 2
depends_on: ["01-01"]
files_modified: [src/process/registry.ts, src/process/manager.ts, src/process/types.ts]
autonomous: true
---

<objective>
Create process management utilities for spawning, tracking, and stopping child processes.

Purpose: Infrastructure for managing agent processes in later phases. Agents are child processes that need lifecycle management.
Output: ProcessManager class with spawn, stop, list, and restart operations.
</objective>

<execution_context>
@~/.claude/get-shit-done/workflows/execute-plan.md
@~/.claude/get-shit-done/templates/summary.md
</execution_context>

<context>
@.planning/PROJECT.md
@.planning/ROADMAP.md
@.planning/STATE.md
</context>

<tasks>

<task type="auto">
  <name>Task 1: Create process types and registry</name>
  <files>src/process/types.ts, src/process/registry.ts</files>
  <action>
    Create src/process/types.ts:
    - ProcessInfo interface: { id: string, pid: number, command: string, args: string[], startedAt: Date, status: 'running' | 'stopped' | 'crashed' }
    - SpawnOptions: { id: string, command: string, args?: string[], cwd?: string, env?: Record<string, string> }

    Create src/process/registry.ts:
    - ProcessRegistry class with Map<string, ProcessInfo> storage
    - register(info: ProcessInfo): void
    - unregister(id: string): void
    - get(id: string): ProcessInfo | undefined
    - getAll(): ProcessInfo[]
    - getByPid(pid: number): ProcessInfo | undefined
    - clear(): void

    Registry is in-memory for now (Phase 2 adds SQLite persistence).
  </action>
  <verify>TypeScript compiles, registry can add/remove/list processes</verify>
  <done>ProcessRegistry class works with full CRUD operations</done>
</task>

<task type="auto">
  <name>Task 2: Create process manager with spawn/stop</name>
  <files>src/process/manager.ts, src/process/index.ts</files>
  <action>
    Create src/process/manager.ts:
    - Import execa for process spawning
    - ProcessManager class:
      - constructor takes ProcessRegistry instance
      - spawn(options: SpawnOptions): Promise<ProcessInfo> - spawns detached child, registers in registry, returns info
      - stop(id: string): Promise<void> - sends SIGTERM, waits up to 5s, then SIGKILL if needed
      - stopAll(): Promise<void> - stops all registered processes
      - restart(id: string): Promise<ProcessInfo> - stops then respawns with same config
      - isRunning(id: string): boolean - checks if process is alive

    Use execa with { detached: true } for background processes.
    Store spawned process reference to enable stop/restart.
    Handle process exit events to update registry status.

    Create src/process/index.ts - export ProcessManager, ProcessRegistry, types.
  </action>
  <verify>Can spawn a simple process (e.g., sleep 10), list it, stop it</verify>
  <done>ProcessManager can spawn, stop, restart, and list child processes</done>
</task>

</tasks>

<verification>
Before declaring plan complete:
- [ ] `npm run build` succeeds
- [ ] ProcessRegistry correctly tracks process info
- [ ] ProcessManager.spawn() starts a detached process
- [ ] ProcessManager.stop() terminates running process
- [ ] ProcessManager.isRunning() correctly reports status
- [ ] Process exit updates registry status automatically
</verification>

<success_criteria>

- All tasks completed
- All verification checks pass
- Process lifecycle (spawn → track → stop) works end-to-end
- Infrastructure ready for agent management in Phase 4
</success_criteria>

<output>
After completion, create `.planning/phases/01-core-infrastructure/01-03-SUMMARY.md`
</output>
