---
phase: 11-architect-agent
plan: 01
type: execute
wave: 1
depends_on: []
files_modified:
  - src/agent/schema.ts
  - src/agent/types.ts
  - src/db/schema.ts
  - src/agent/mock-manager.ts
autonomous: true
---

<objective>
Add agent mode/role support to track what type of work an agent is performing.

Purpose: Enable different agent behaviors (discuss, breakdown, execute) with mode-specific output schemas so the system knows how to interpret agent output.

Output: Extended agent schema with mode field, mode-specific output schemas, updated types.
</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

# Prior phase context
@.planning/phases/10-multi-question-schema/10-01-SUMMARY.md

# Source files to modify
@src/agent/schema.ts
@src/agent/types.ts
@src/db/schema.ts
@src/agent/mock-manager.ts
</context>

<tasks>

<task type="auto">
  <name>Task 1: Add AgentMode type and database column</name>
  <files>src/agent/types.ts, src/db/schema.ts</files>
  <action>
1. In src/agent/types.ts, add AgentMode type:
   ```typescript
   export type AgentMode = 'execute' | 'discuss' | 'breakdown';
   ```

2. In src/db/schema.ts, add mode column to agents table:
   ```typescript
   mode: text('mode', { enum: ['execute', 'discuss', 'breakdown'] })
     .notNull()
     .default('execute'),
   ```

3. Update SpawnAgentOptions in types.ts to include optional mode:
   ```typescript
   /** Agent operation mode (defaults to 'execute') */
   mode?: AgentMode;
   ```

4. Update AgentInfo in types.ts to include mode:
   ```typescript
   /** Current operation mode */
   mode: AgentMode;
   ```
  </action>
  <verify>npm run build passes with no type errors</verify>
  <done>AgentMode type exists, database schema has mode column, types updated</done>
</task>

<task type="auto">
  <name>Task 2: Create mode-specific output schemas</name>
  <files>src/agent/schema.ts</files>
  <action>
Add mode-specific output schemas following the existing discriminated union pattern.

**IMPORTANT:** These schemas define the contract between the agent prompt and the system.
The prompt tells the agent what format to output; these schemas validate that output.

1. Keep existing agentOutputSchema as 'execute' mode schema (already handles done/questions/error)

2. Add decisionSchema for reuse:
   ```typescript
   /**
    * A decision captured during discussion.
    * Prompt instructs: { "topic": "Auth", "decision": "JWT", "reason": "Stateless" }
    */
   const decisionSchema = z.object({
     topic: z.string(),
     decision: z.string(),
     reason: z.string(),
   });

   export type Decision = z.infer<typeof decisionSchema>;
   ```

3. Add phaseBreakdownSchema for reuse:
   ```typescript
   /**
    * A phase from breakdown output.
    * Prompt instructs: { "number": 1, "name": "...", "description": "...", "dependencies": [0] }
    */
   const phaseBreakdownSchema = z.object({
     number: z.number().int().positive(),
     name: z.string().min(1),
     description: z.string(),
     dependencies: z.array(z.number().int()).optional().default([]),
   });

   export type PhaseBreakdown = z.infer<typeof phaseBreakdownSchema>;
   ```

4. Add discussOutputSchema for discussion mode:
   ```typescript
   /**
    * Discuss mode output schema.
    * Agent asks questions OR completes with decisions.
    *
    * Prompt tells agent:
    * - Output "questions" status with questions array when needing input
    * - Output "context_complete" status with decisions array when done
    */
   export const discussOutputSchema = z.discriminatedUnion('status', [
     // Agent needs more information
     z.object({
       status: z.literal('questions'),
       questions: z.array(questionItemSchema),
     }),
     // Agent has captured all decisions
     z.object({
       status: z.literal('context_complete'),
       decisions: z.array(decisionSchema),
       summary: z.string(), // Brief summary of all decisions
     }),
     // Unrecoverable error
     z.object({
       status: z.literal('unrecoverable_error'),
       error: z.string(),
     }),
   ]);

   export type DiscussOutput = z.infer<typeof discussOutputSchema>;
   ```

5. Add breakdownOutputSchema for breakdown mode:
   ```typescript
   /**
    * Breakdown mode output schema.
    * Agent asks questions OR completes with phases.
    *
    * Prompt tells agent:
    * - Output "questions" status when needing clarification
    * - Output "breakdown_complete" status with phases array when done
    */
   export const breakdownOutputSchema = z.discriminatedUnion('status', [
     // Agent needs clarification
     z.object({
       status: z.literal('questions'),
       questions: z.array(questionItemSchema),
     }),
     // Agent has decomposed initiative into phases
     z.object({
       status: z.literal('breakdown_complete'),
       phases: z.array(phaseBreakdownSchema),
     }),
     // Unrecoverable error
     z.object({
       status: z.literal('unrecoverable_error'),
       error: z.string(),
     }),
   ]);

   export type BreakdownOutput = z.infer<typeof breakdownOutputSchema>;
   ```

6. Create JSON schema versions for --json-schema flag:
   ```typescript
   /**
    * JSON Schema for discuss mode (passed to Claude CLI --json-schema)
    */
   export const discussOutputJsonSchema = {
     type: 'object',
     oneOf: [
       {
         properties: {
           status: { const: 'questions' },
           questions: {
             type: 'array',
             items: {
               type: 'object',
               properties: {
                 id: { type: 'string' },
                 question: { type: 'string' },
                 options: {
                   type: 'array',
                   items: {
                     type: 'object',
                     properties: {
                       label: { type: 'string' },
                       description: { type: 'string' },
                     },
                     required: ['label'],
                   },
                 },
                 multiSelect: { type: 'boolean' },
               },
               required: ['id', 'question'],
             },
           },
         },
         required: ['status', 'questions'],
       },
       {
         properties: {
           status: { const: 'context_complete' },
           decisions: {
             type: 'array',
             items: {
               type: 'object',
               properties: {
                 topic: { type: 'string' },
                 decision: { type: 'string' },
                 reason: { type: 'string' },
               },
               required: ['topic', 'decision', 'reason'],
             },
           },
           summary: { type: 'string' },
         },
         required: ['status', 'decisions', 'summary'],
       },
       {
         properties: {
           status: { const: 'unrecoverable_error' },
           error: { type: 'string' },
         },
         required: ['status', 'error'],
       },
     ],
   };

   /**
    * JSON Schema for breakdown mode (passed to Claude CLI --json-schema)
    */
   export const breakdownOutputJsonSchema = {
     type: 'object',
     oneOf: [
       {
         properties: {
           status: { const: 'questions' },
           questions: {
             type: 'array',
             items: {
               type: 'object',
               properties: {
                 id: { type: 'string' },
                 question: { type: 'string' },
                 options: {
                   type: 'array',
                   items: {
                     type: 'object',
                     properties: {
                       label: { type: 'string' },
                       description: { type: 'string' },
                     },
                     required: ['label'],
                   },
                 },
               },
               required: ['id', 'question'],
             },
           },
         },
         required: ['status', 'questions'],
       },
       {
         properties: {
           status: { const: 'breakdown_complete' },
           phases: {
             type: 'array',
             items: {
               type: 'object',
               properties: {
                 number: { type: 'integer', minimum: 1 },
                 name: { type: 'string', minLength: 1 },
                 description: { type: 'string' },
                 dependencies: {
                   type: 'array',
                   items: { type: 'integer' },
                 },
               },
               required: ['number', 'name', 'description'],
             },
           },
         },
         required: ['status', 'phases'],
       },
       {
         properties: {
           status: { const: 'unrecoverable_error' },
           error: { type: 'string' },
         },
         required: ['status', 'error'],
       },
     ],
   };
   ```

7. Export all schemas, types, and JSON schemas.
  </action>
  <verify>npm run build passes, new schemas are exported</verify>
  <done>Three mode-specific output schemas with JSON schema versions, aligned with agent prompts</done>
</task>

<task type="auto">
  <name>Task 3: Update MockAgentManager for mode support</name>
  <files>src/agent/mock-manager.ts</files>
  <action>
1. Update MockAgentScenario to support mode-specific scenarios:
   - Add 'discuss' and 'breakdown' status types to the union
   - For discuss mode: 'questions' or 'context_complete'
   - For breakdown mode: 'questions' or 'breakdown_complete'

2. Update spawn() to accept mode in SpawnAgentOptions (defaults to 'execute')

3. Store mode in agent record

4. Update toAgentInfo() to include mode field

5. Ensure handleCompletion properly handles mode-specific statuses:
   - 'context_complete' → agent:stopped with reason 'context_complete'
   - 'breakdown_complete' → agent:stopped with reason 'breakdown_complete'

Note: Keep backwards compatible with existing tests by defaulting to 'execute' mode.
  </action>
  <verify>npm test passes for mock-manager.test.ts</verify>
  <done>MockAgentManager supports all three modes with proper status handling</done>
</task>

</tasks>

<verification>
Before declaring plan complete:
- [ ] npm run build succeeds without errors
- [ ] npm test passes (all existing tests still work)
- [ ] AgentMode type is exported from src/agent/types.ts
- [ ] All three output schemas are exported from src/agent/schema.ts
- [ ] JSON schemas (discussOutputJsonSchema, breakdownOutputJsonSchema) are exported
- [ ] Decision and PhaseBreakdown types are exported for use by other modules
- [ ] MockAgentManager handles mode parameter
</verification>

<success_criteria>

- All tasks completed
- Agent mode tracking works end-to-end
- Mode-specific output schemas match the prompt output format:
  - discuss: questions OR context_complete with decisions array
  - breakdown: questions OR breakdown_complete with phases array
  - execute: done/questions/unrecoverable_error (existing)
- JSON schemas can be passed to Claude CLI --json-schema flag
- Existing tests pass (backwards compatible)
- No TypeScript errors
</success_criteria>

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