---
phase: 11-architect-agent
plan: 03
type: execute
wave: 2
depends_on: ["11-01", "11-02"]
files_modified:
  - src/agent/manager.ts
  - src/db/repositories/agent-repository.ts
  - src/db/repositories/drizzle-agent-repository.ts
autonomous: true
---

<objective>
Update ClaudeAgentManager and AgentRepository to support agent modes.

Purpose: Enable spawning agents in different modes (execute, discuss, breakdown) with mode-specific JSON schemas passed to Claude CLI.

Output: Mode-aware agent spawning with correct output schema per mode.
</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

# Depends on Plan 01 for mode schemas
@.planning/phases/11-architect-agent/11-01-SUMMARY.md

# Source files to modify
@src/agent/manager.ts
@src/agent/schema.ts
@src/db/repositories/agent-repository.ts
@src/db/repositories/drizzle-agent-repository.ts
</context>

<tasks>

<task type="auto">
  <name>Task 1: Update AgentRepository for mode field</name>
  <files>src/db/repositories/agent-repository.ts, src/db/repositories/drizzle-agent-repository.ts</files>
  <action>
1. In agent-repository.ts, update CreateAgentData to include mode:
   ```typescript
   export type CreateAgentData = {
     name: string;
     taskId: string | null;
     sessionId: string | null;
     worktreeId: string;
     status: AgentStatus;
     mode?: AgentMode; // Defaults to 'execute' if not provided
   };
   ```

2. Import AgentMode from '../agent/types.js'

3. In drizzle-agent-repository.ts:
   - Import AgentMode type
   - Update create() to handle mode field (default to 'execute' if not provided)
   - Ensure toAgentRecord() includes mode in return type
  </action>
  <verify>npm run build passes</verify>
  <done>AgentRepository handles mode field with 'execute' default</done>
</task>

<task type="auto">
  <name>Task 2: Update ClaudeAgentManager for mode-specific schemas</name>
  <files>src/agent/manager.ts</files>
  <action>
1. Import all output JSON schemas:
   ```typescript
   import {
     agentOutputSchema,
     agentOutputJsonSchema,
     discussOutputJsonSchema,
     breakdownOutputJsonSchema,
     discussOutputSchema,
     breakdownOutputSchema,
   } from './schema.js';
   ```

2. Add helper function to get JSON schema by mode:
   ```typescript
   private getJsonSchemaForMode(mode: AgentMode): object {
     switch (mode) {
       case 'discuss': return discussOutputJsonSchema;
       case 'breakdown': return breakdownOutputJsonSchema;
       case 'execute':
       default: return agentOutputJsonSchema;
     }
   }
   ```

3. Update spawn() to:
   - Extract mode from options (default to 'execute')
   - Pass mode to repository.create()
   - Use getJsonSchemaForMode(mode) when constructing CLI args

4. Update handleAgentCompletion() to parse output based on agent mode:
   - Fetch agent to get its mode
   - Use appropriate schema (discussOutputSchema, breakdownOutputSchema, or agentOutputSchema)
   - Handle mode-specific statuses:
     - 'context_complete' → emit agent:stopped with reason 'context_complete'
     - 'breakdown_complete' → emit agent:stopped with reason 'breakdown_complete'

5. Update toAgentInfo() to include mode field from agent record.
  </action>
  <verify>npm run build passes</verify>
  <done>ClaudeAgentManager spawns agents with mode-specific JSON schemas</done>
</task>

<task type="auto">
  <name>Task 3: Add mode to AgentStoppedEvent reasons</name>
  <files>src/events/types.ts</files>
  <action>
1. Update AgentStoppedEvent payload to support new stop reasons:
   ```typescript
   export interface AgentStoppedEvent extends BaseEvent {
     type: 'agent:stopped';
     payload: {
       agentId: string;
       name: string;
       taskId: string;
       reason: 'task_complete' | 'user_requested' | 'context_complete' | 'breakdown_complete';
     };
   }
   ```

Note: This expands the union type - existing code using 'task_complete' and 'user_requested' continues to work.
  </action>
  <verify>npm run build passes, existing tests pass</verify>
  <done>AgentStoppedEvent supports mode-specific completion reasons</done>
</task>

</tasks>

<verification>
Before declaring plan complete:
- [ ] npm run build succeeds without errors
- [ ] npm test passes (all existing tests still work)
- [ ] Agent can be spawned with mode='discuss' and receives discuss JSON schema
- [ ] Agent can be spawned with mode='breakdown' and receives breakdown JSON schema
- [ ] Default mode='execute' works as before (backwards compatible)
</verification>

<success_criteria>

- All tasks completed
- Mode-specific JSON schemas passed to Claude CLI
- Mode stored in database and returned in AgentInfo
- Existing tests pass (backwards compatible with execute mode)
</success_criteria>

<output>
After completion, create `.planning/phases/11-architect-agent/11-03-SUMMARY.md`
</output>
