# APEX Template System

## Overview

This directory contains template files used to initialize APEX workflow outputs when save mode (`-s`) is enabled.

## Template Files

| Template | Purpose | Created When |
|----------|---------|--------------|
| `00-context.md` | Workflow configuration and progress tracking | Always (if save_mode) |
| `01-analyze.md` | Analysis findings | Always (if save_mode) |
| `02-plan.md` | Implementation plan | Always (if save_mode) |
| `03-execute.md` | Implementation log | Always (if save_mode) |
| `04-validate.md` | Validation results | Always (if save_mode) |
| `05-examine.md` | Adversarial review findings | Only if examine_mode |
| `06-resolve.md` | Finding resolution log | Only if examine_mode |
| `07-tests.md` | Test analysis and creation | Only if test_mode |
| `08-run-tests.md` | Test runner log | Only if test_mode |

## Template Variables

Templates use `{{variable}}` syntax for placeholders:

| Variable | Description | Example |
|----------|-------------|---------|
| `{{task_id}}` | Kebab-case task identifier | `01-add-auth-middleware` |
| `{{task_description}}` | Plain text task description | `add authentication middleware` |
| `{{timestamp}}` | ISO 8601 timestamp | `2026-01-22T10:30:00Z` |
| `{{auto_mode}}` | Auto mode flag | `true` or `false` |
| `{{examine_mode}}` | Examine mode flag | `true` or `false` |
| `{{save_mode}}` | Save mode flag | `true` or `false` |
| `{{test_mode}}` | Test mode flag | `true` or `false` |
| `{{economy_mode}}` | Economy mode flag | `true` or `false` |
| `{{original_input}}` | Raw user input | `/apex -a -s add auth` |
| `{{examine_status}}` | Progress status for examine steps | `Pending` or `Skip` |
| `{{test_status}}` | Progress status for test steps | `Pending` or `Skip` |

## How It Works

1. **Initialization (step-00-init):**
   - Creates output directory `.claude/output/apex/{task-id}/`
   - Copies templates with variables replaced
   - All files ready for appending

2. **Each Step:**
   - Reads from pre-created file if resuming
   - Appends findings/outputs to step file
   - Updates 00-context.md progress table

3. **Benefits:**
   - Consistent formatting across all workflows
   - Easy to update templates
   - Supports resume from any step

## Output Structure

```
.claude/output/apex/{task-id}/
├── 00-context.md      # Configuration + progress
├── 01-analyze.md      # Analysis findings
├── 02-plan.md         # Implementation plan
├── 03-execute.md      # Execution log
├── 04-validate.md     # Validation results
├── 05-examine.md      # Review findings (if -x)
├── 06-resolve.md      # Resolution log (if -x)
├── 07-tests.md        # Test creation (if -t)
└── 08-run-tests.md    # Test runner (if -t)
```
