---
phase: 07-mock-agent-test-harness
plan: 01
type: execute
wave: 1
depends_on: []
files_modified: [src/agent/mock-manager.ts, src/agent/mock-manager.test.ts, src/agent/index.ts]
autonomous: true
---

<objective>
Implement MockAgentManager adapter for test scenarios.

Purpose: Enable E2E testing of dispatch/coordination flows without spawning real Claude agents. The mock adapter simulates configurable agent behaviors (success, crash, waiting_for_input) and emits proper lifecycle events.

Output: MockAgentManager class implementing AgentManager port with scenario configuration.
</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

@src/agent/types.ts
@src/agent/manager.ts
@src/events/types.ts
</context>

<tasks>

<task type="auto">
  <name>Task 1: Implement MockAgentManager adapter</name>
  <files>src/agent/mock-manager.ts</files>
  <action>
Create MockAgentManager class implementing AgentManager interface with configurable scenarios.

**Scenario configuration interface:**
```typescript
interface MockAgentScenario {
  /** How agent completes: 'success' | 'crash' | 'waiting_for_input' */
  outcome: 'success' | 'crash' | 'waiting_for_input';
  /** Delay before completion (ms). Default 0 for synchronous tests. */
  delay?: number;
  /** Result message for success/crash */
  message?: string;
  /** Files modified (for success) */
  filesModified?: string[];
  /** Question to surface (for waiting_for_input) */
  question?: string;
}
```

**Constructor takes:**
- eventBus?: EventBus (optional, for event emission)
- defaultScenario?: MockAgentScenario (defaults to immediate success)

**Key behaviors:**
- spawn(): Create agent record in internal Map, schedule completion based on scenario
- Use per-agent scenario override via `setScenario(agentName: string, scenario: MockAgentScenario)`
- Emit all lifecycle events: agent:spawned, agent:stopped, agent:crashed, agent:waiting, agent:resumed
- store session IDs (use UUID) for resume capability testing
- stop(): Mark agent stopped, emit agent:stopped event
- resume(): Re-run scenario for resumed agent
- getResult(): Return stored result after completion

**DO NOT:**
- Use real execa/subprocess - this is all in-memory simulation
- Block on spawn() - completion happens async via setTimeout (even if delay=0)
  </action>
  <verify>npm run build succeeds, TypeScript compiles without errors</verify>
  <done>MockAgentManager implements AgentManager interface with scenario configuration</done>
</task>

<task type="auto">
  <name>Task 2: Write comprehensive tests for MockAgentManager</name>
  <files>src/agent/mock-manager.test.ts, src/agent/index.ts</files>
  <action>
Create test suite for MockAgentManager covering all scenarios.

**Test categories:**
1. spawn() with default scenario (immediate success)
2. spawn() with configured delay
3. spawn() with crash scenario - emits agent:crashed, result.success=false
4. spawn() with waiting_for_input - emits agent:waiting, status='waiting_for_input'
5. resume() after waiting_for_input - emits agent:resumed, continues with scenario
6. stop() kills scheduled completion, emits agent:stopped
7. list() returns all agents with correct status
8. get() and getByName() lookups work
9. setScenario() overrides for specific agent names
10. Event emission order verification (spawned before completion events)

**Pattern to follow:**
Use same createMockEventBus() pattern from dispatch/manager.test.ts
Use async/await with vitest's fake timers for delay testing:
```typescript
vi.useFakeTimers();
await manager.spawn({ name: 'test', taskId: 't1', prompt: 'do thing' });
await vi.advanceTimersByTimeAsync(100);
// verify completion happened
vi.useRealTimers();
```

**Export MockAgentManager from src/agent/index.ts**
  </action>
  <verify>npm test passes all MockAgentManager tests, at least 10 test cases</verify>
  <done>MockAgentManager has comprehensive test coverage for all scenario types</done>
</task>

</tasks>

<verification>
Before declaring plan complete:
- [ ] `npm run build` succeeds without errors
- [ ] `npm test` passes all tests including new MockAgentManager tests
- [ ] MockAgentManager implements full AgentManager interface
- [ ] All three outcome scenarios work: success, crash, waiting_for_input
- [ ] Events emitted correctly for each scenario
- [ ] MockAgentManager exported from src/agent/index.ts
</verification>

<success_criteria>

- All tasks completed
- MockAgentManager can simulate any agent lifecycle scenario
- Test suite proves all scenarios work correctly
- No errors or warnings introduced
  </success_criteria>

<output>
After completion, create `.planning/phases/07-mock-agent-test-harness/07-01-SUMMARY.md`
</output>
