---
phase: 08.1-agent-output-schema
plan: 02
type: execute
wave: 2
depends_on: ["08.1-01"]
files_modified: [src/agent/mock-manager.ts, src/test/harness.ts, src/agent/mock-manager.test.ts]
autonomous: true
---

<objective>
Update MockAgentManager to use the new agent output schema, enabling proper testing of question/resume flows.

Purpose: Align mock implementation with real ClaudeAgentManager behavior for accurate E2E testing.
Output: MockAgentManager that simulates structured output schema with question/resume support.
</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
@.planning/phases/08.1-agent-output-schema/08.1-01-SUMMARY.md

@src/agent/schema.ts
@src/agent/mock-manager.ts
@src/agent/types.ts
@src/test/harness.ts
</context>

<tasks>

<task type="auto">
  <name>Task 1: Update MockAgentManager to use schema-aligned scenarios</name>
  <files>src/agent/mock-manager.ts</files>
  <action>
Update MockAgentManager to match the new schema behavior:

1. **Update MockAgentScenario to align with schema:**
   ```typescript
   export type MockAgentScenario =
     | { status: 'done'; result?: string; filesModified?: string[]; delay?: number }
     | { status: 'question'; question: string; options?: Array<{label: string; description?: string}>; multiSelect?: boolean; delay?: number }
     | { status: 'unrecoverable_error'; error: string; attempted?: string; delay?: number };
   ```

2. **Update DEFAULT_SCENARIO:**
   ```typescript
   const DEFAULT_SCENARIO: MockAgentScenario = {
     status: 'done',
     result: 'Task completed successfully',
     filesModified: [],
     delay: 0,
   };
   ```

3. **Update MockAgentRecord to store pending question:**
   ```typescript
   interface MockAgentRecord {
     info: AgentInfo;
     scenario: MockAgentScenario;
     result?: AgentResult;
     pendingQuestion?: { question: string; options?: Array<{label: string; description?: string}>; multiSelect?: boolean };
     completionTimer?: ReturnType<typeof setTimeout>;
   }
   ```

4. **Update completeAgent() to handle new schema:**
   ```typescript
   private completeAgent(agentId: string, scenario: MockAgentScenario): void {
     const record = this.agents.get(agentId);
     if (!record) return;

     switch (scenario.status) {
       case 'done':
         record.result = {
           success: true,
           message: scenario.result ?? 'Task completed successfully',
           filesModified: scenario.filesModified,
         };
         record.info.status = 'idle';
         // Emit agent:stopped event
         break;

       case 'question':
         record.info.status = 'waiting_for_input';
         record.pendingQuestion = {
           question: scenario.question,
           options: scenario.options,
           multiSelect: scenario.multiSelect,
         };
         // Emit agent:waiting event with full question data
         if (this.eventBus) {
           const event: AgentWaitingEvent = {
             type: 'agent:waiting',
             timestamp: new Date(),
             payload: {
               agentId,
               name: record.info.name,
               taskId: record.info.taskId,
               sessionId: record.info.sessionId ?? '',
               question: scenario.question,
               options: scenario.options,
               multiSelect: scenario.multiSelect,
             },
           };
           this.eventBus.emit(event);
         }
         break;

       case 'unrecoverable_error':
         record.result = {
           success: false,
           message: scenario.error,
         };
         record.info.status = 'crashed';
         // Emit agent:crashed event
         break;
     }
   }
   ```

5. **Add getPendingQuestion() method:**
   ```typescript
   async getPendingQuestion(agentId: string): Promise<{question: string; options?: Array<{label: string; description?: string}>; multiSelect?: boolean} | null> {
     const record = this.agents.get(agentId);
     return record?.pendingQuestion ?? null;
   }
   ```

6. **Update resume() to clear pending question:**
   After successful resume, clear `record.pendingQuestion = undefined`.
  </action>
  <verify>npm run typecheck</verify>
  <done>MockAgentManager uses schema-aligned scenarios with structured question support</done>
</task>

<task type="auto">
  <name>Task 2: Update TestHarness setAgentScenario helper</name>
  <files>src/test/harness.ts</files>
  <action>
Update TestHarness to use new scenario format:

1. **Update setAgentScenario type:**
   ```typescript
   import type { MockAgentScenario } from '../agent/mock-manager.js';

   // In TestHarness interface:
   setAgentScenario(agentName: string, scenario: MockAgentScenario): void;
   ```

2. **Add helper for common scenarios:**
   ```typescript
   // In TestHarness interface, add convenience methods:
   setAgentDone(agentName: string, result?: string): void;
   setAgentQuestion(agentName: string, question: string, options?: Array<{label: string; description?: string}>): void;
   setAgentError(agentName: string, error: string): void;

   // Implementation:
   setAgentDone: (name, result) => agentManager.setScenario(name, { status: 'done', result }),
   setAgentQuestion: (name, question, options) => agentManager.setScenario(name, { status: 'question', question, options }),
   setAgentError: (name, error) => agentManager.setScenario(name, { status: 'unrecoverable_error', error }),
   ```

3. **Add getPendingQuestion to harness:**
   ```typescript
   getPendingQuestion(agentId: string): Promise<{question: string; options?: ...} | null>;
   ```
  </action>
  <verify>npm run typecheck</verify>
  <done>TestHarness updated with new scenario helpers</done>
</task>

<task type="auto">
  <name>Task 3: Update MockAgentManager tests</name>
  <files>src/agent/mock-manager.test.ts</files>
  <action>
Update existing MockAgentManager tests to use new scenario format:

1. **Update scenario declarations:**
   Change from:
   ```typescript
   { outcome: 'success', message: '...' }
   { outcome: 'crash', message: '...' }
   { outcome: 'waiting_for_input', question: '...' }
   ```
   To:
   ```typescript
   { status: 'done', result: '...' }
   { status: 'unrecoverable_error', error: '...' }
   { status: 'question', question: '...', options: [...] }
   ```

2. **Add test for structured question data:**
   ```typescript
   it('emits agent:waiting with structured question data', async () => {
     vi.useFakeTimers();
     manager.setScenario('test-agent', {
       status: 'question',
       question: 'Which database?',
       options: [
         { label: 'PostgreSQL', description: 'Full-featured' },
         { label: 'SQLite', description: 'Lightweight' },
       ],
       multiSelect: false,
     });

     await manager.spawn({ name: 'test-agent', taskId: 'task-1', prompt: 'test' });
     await vi.runAllTimersAsync();

     const events = eventBus.getEventsByType('agent:waiting');
     expect(events[0].payload.options).toHaveLength(2);
     expect(events[0].payload.options[0].label).toBe('PostgreSQL');
   });
   ```

3. **Add test for getPendingQuestion:**
   ```typescript
   it('stores pending question for retrieval', async () => {
     vi.useFakeTimers();
     manager.setScenario('test-agent', {
       status: 'question',
       question: 'Which database?',
       options: [{ label: 'PostgreSQL' }],
     });

     const agent = await manager.spawn({ name: 'test-agent', taskId: 'task-1', prompt: 'test' });
     await vi.runAllTimersAsync();

     const pending = await manager.getPendingQuestion(agent.id);
     expect(pending?.question).toBe('Which database?');
     expect(pending?.options).toHaveLength(1);
   });
   ```

4. **Add test for resume clearing pending question:**
   ```typescript
   it('clears pending question after resume', async () => {
     // Setup question scenario, resume, verify pendingQuestion is null
   });
   ```
  </action>
  <verify>npm test src/agent/mock-manager.test.ts -- --run</verify>
  <done>MockAgentManager tests updated and passing with new schema</done>
</task>

</tasks>

<verification>
Before declaring plan complete:
- [ ] `npm run build` succeeds
- [ ] `npm run typecheck` passes
- [ ] `npm test src/agent/mock-manager.test.ts -- --run` passes
- [ ] Existing E2E tests still pass (may need scenario format updates)
</verification>

<success_criteria>

- All tasks completed
- All verification checks pass
- MockAgentManager matches ClaudeAgentManager behavior
- TestHarness provides convenient scenario helpers
- All mock-manager tests pass with new schema
</success_criteria>

<output>
After completion, create `.planning/phases/08.1-agent-output-schema/08.1-02-SUMMARY.md`
</output>
