---
name: step-00-init
description: Initialize APEX workflow - parse flags, detect continuation, setup state
next_step: steps/step-01-analyze.md
---

# Step 0: Initialization

## MANDATORY EXECUTION RULES:

- NEVER skip flag parsing
- ALWAYS parse ALL flags before any other action
- ONLY check for resume if {resume_task} is set
- YOU ARE AN INITIALIZER, not an executor
- FORBIDDEN to load step-01 until init is complete

## YOUR TASK:

Initialize the APEX workflow by parsing flags, detecting continuation state, and setting up the execution environment.

---

<defaults>
## Default Configuration

```yaml
auto_mode: false      # -a: Skip confirmations
examine_mode: false   # -x: Auto-proceed to adversarial review
save_mode: false      # -s: Save outputs to .claude/output/apex/
test_mode: false      # -t: Include test creation and runner steps
economy_mode: false   # -e: No subagents, save tokens
```
</defaults>

---

## EXECUTION SEQUENCE:

### 1. Parse Flags and Input

**Step 1: Load defaults from config above**

```
{auto_mode}    = false
{examine_mode} = false
{save_mode}    = false
{test_mode}    = false
{economy_mode} = false
```

**Step 2: Parse user input and override defaults:**

```
Enable flags (lowercase - turn ON):
  -a or --auto     -> {auto_mode} = true
  -x or --examine  -> {examine_mode} = true
  -s or --save     -> {save_mode} = true
  -t or --test     -> {test_mode} = true
  -e or --economy  -> {economy_mode} = true

Disable flags (UPPERCASE - turn OFF):
  -A or --no-auto         -> {auto_mode} = false
  -X or --no-examine      -> {examine_mode} = false
  -S or --no-save         -> {save_mode} = false
  -T or --no-test         -> {test_mode} = false
  -E or --no-economy      -> {economy_mode} = false

Other:
  -r or --resume   -> {resume_task} = <next argument>
  -i or --interactive -> {interactive_mode} = true
  Remainder        -> {task_description}
```

**Step 3: Generate feature_name and task_id:**

```
{feature_name} = kebab-case-description
Example: "add user authentication" -> "add-user-authentication"

{task_id} = NN-{feature_name}
- Auto-detect next available number from .claude/output/apex/
- Example: "01-add-user-authentication"
```

### 2. Check Resume Mode

**ONLY execute if {resume_task} is set!**

If `{resume_task}` is set:

1. Search for matching task in `.claude/output/apex/`
2. If found: Read `00-context.md` to restore state variables
3. Find last completed step (look for "Status: Complete" markers)
4. Load next incomplete step
5. **STOP** - do not continue with fresh init

If no match found: List available tasks and ask user to specify.

### 3. Interactive Mode (if -i flag)

If `{interactive_mode}` = true:

```yaml
questions:
  - header: "Configure"
    question: "Select flags to enable for this workflow:"
    options:
      - label: "Auto mode (-a)"
        description: "Skip all confirmations, use recommended options"
      - label: "Examine mode (-x)"
        description: "Include adversarial code review at end"
      - label: "Save mode (-s)"
        description: "Save all outputs to .claude/output/apex/"
      - label: "Test mode (-t)"
        description: "Include test creation and runner steps"
      - label: "Economy mode (-e)"
        description: "No subagents, direct tools only (saves tokens)"
    multiSelect: true
```

### 4. Create Output Structure (if save_mode)

**If `{save_mode}` = true:**

1. Create directory: `.claude/output/apex/{task_id}/`

2. Write `00-context.md`:

```markdown
# APEX Task: {task_id}

**Created:** {timestamp}
**Task:** {task_description}

## Configuration

| Flag | Value |
|------|-------|
| Auto mode | {auto_mode} |
| Examine mode | {examine_mode} |
| Save mode | {save_mode} |
| Test mode | {test_mode} |
| Economy mode | {economy_mode} |

## User Request

{original user input}

## Acceptance Criteria

_To be defined in step-01-analyze_

## Progress

| Step | Status |
|------|--------|
| 00-init | In Progress |
| 01-analyze | Pending |
| 02-plan | Pending |
| 03-execute | Pending |
| 04-validate | Pending |
| 05-examine | {examine_mode ? "Pending" : "Skip"} |
| 06-resolve | {examine_mode ? "Pending" : "Skip"} |
| 07-tests | {test_mode ? "Pending" : "Skip"} |
| 08-run-tests | {test_mode ? "Pending" : "Skip"} |
```

3. Mark 00-init as Complete in the Progress table

### 5. Show Summary and Proceed

**Always show COMPACT summary:**

```
APEX: {task_description}

| Variable | Value |
|----------|-------|
| {task_id} | 01-kebab-name |
| {auto_mode} | true/false |
| {examine_mode} | true/false |
| {save_mode} | true/false |
| {test_mode} | true/false |
| {economy_mode} | true/false |

-> Analyzing...
```

**Then proceed directly to step-01-analyze.md**

---

## SUCCESS METRICS:

- All flags correctly parsed
- Output is COMPACT (one table, no verbose logs)
- Variables shown with `{brackets}` notation
- Proceeded to step-01 immediately after summary
- Output folder created with 00-context.md (if save_mode)

## NEXT STEP:

After showing initialization summary, always proceed directly to `./step-01-analyze.md`
