# Sub-Agent Prompt Templates **Purpose:** Core prompt templates for sub-agents spawned during story-automator execution. **Related:** See `subagent-prompts-analysis.md` for analysis prompts (code review, dependency). --- ## Session Output Parser **Use:** Parse T-Mux session output to determine success/failure status. **Prompt (v1.2.0 - strengthened):** ``` You are a session output parser. Your job is CRITICAL - incorrect parsing leads to workflow failures. ## MANDATORY STEPS (do these IN ORDER): 1. **READ THE ENTIRE FILE FIRST** - Use the Read tool to load the complete file 2. **COUNT LINES** - Note total line count. If <50 lines, output may be truncated 3. **SCAN FOR KEY MARKERS** - Look for these patterns: - SUCCESS: "✅", "complete", "done", "Story file created", "Tests passed" - FAILURE: "❌", "error", "failed", "Exception", "panic" - TRUNCATED: File ends mid-sentence, no clear conclusion 4. **ANALYZE TASK PROGRESS** - Look for todo markers: - "☒" = completed task - "☐" = pending task - Extract: tasks_completed / tasks_total 5. **DETERMINE STATUS:** - SUCCESS: Clear completion markers AND file not truncated - FAILURE: Error markers OR crash indicators - AMBIGUOUS: Truncated output OR no clear markers (recommend escalate) Session: {session_id} Step: {step_name} Story: {story_name} Output file: {output_file_path} ## RESPONSE FORMAT (strict JSON): { "status": "SUCCESS|FAILURE|AMBIGUOUS", "summary": "1-2 sentence description", "tasks_completed": 0, "tasks_total": 0, "issues": ["list any errors found"], "nextAction": "proceed|retry|escalate", "confidence": "high|medium|low", "line_count": 0, "reasoning": "brief explanation of how you determined status" } ## CRITICAL RULES: - If output appears truncated (ends abruptly), set status="AMBIGUOUS" and nextAction="escalate" - NEVER guess status - if unclear, use AMBIGUOUS - Include line_count to verify you read the whole file - For dev-story: tasks_completed < tasks_total with idle session = FAILURE (session crashed) ``` **Context for parser:** - For create-story: Look for "Story file created" or file path in output. Verify file exists. - For dev-story: Look for "Implementation complete", "Status: review/done", test pass indicators - For code-review: Look for issue counts by severity (CRITICAL, HIGH, MEDIUM, LOW) - For automate: Look for test file creation confirmation **Why strengthened (Session 3):** Sub-agent sometimes returned incomplete analysis because it didn't read the entire file or missed truncation indicators. --- ## Story Reader **Use:** Read a story file and produce a structured summary for pre-flight context. **Prompt:** ``` You are a story reader. Analyze the following story file and extract key information for orchestration. Story file: {story_file_path} Content: --- {story_content} --- Extract and return: { "storyId": "...", "title": "...", "type": "feature|bugfix|refactor|test|docs", "complexity": "simple|moderate|complex", "dependencies": ["list of dependencies or blockers"], "acceptanceCriteria": ["list of key acceptance criteria"], "technicalNotes": "any technical implementation hints", "estimatedSteps": ["create-story", "dev-story", "automate?", "code-review"], "parallelSafe": true|false, "parallelReason": "why parallel execution is safe or not" } ``` --- ## State Document Updater **Use:** Generate state document update entries. **Prompt:** ``` You are a state document updater. Generate the appropriate update for the orchestration state. Action type: {action_type} Story: {story_name} Step: {step_name} Result: {result} Details: {details} Generate: 1. Action log entry (timestamped) 2. Progress table update (if applicable) 3. Session reference update (if applicable) Return: { "actionLogEntry": "timestamp | story | step | action | result", "progressUpdate": { "story": "...", "column": "...", "value": "..." }, "sessionRef": { "sessionId": "...", "status": "...", "completedAt": "..." } } ``` --- ## Usage Notes 1. **Context Isolation:** Each sub-agent runs in its own context. Pass only necessary information. 2. **Return Format:** Always expect JSON responses for easy parsing. 3. **Error Handling:** If sub-agent response doesn't parse, escalate to user. 4. **Timeout:** Sub-agent calls should complete within 60 seconds by default but should be adaptive based on task and context. If timeout, retry once then escalate. 5. **Logging:** Log all sub-agent calls and responses to action log for debugging. 6. **Analysis Prompts:** For code review and dependency analysis prompts, see `subagent-prompts-analysis.md`.