---
name: step-00-init
description: Initialize Business Analysis - Parse flags, create structure, setup state
model: haiku
next_step: steps/step-01-discover.md
---

<objective>
Parse command-line flags, create feature directory structure, and initialize state variables for the Business Analysis workflow.
</objective>

<defaults>
```yaml
auto_mode: false
save_mode: true      # BA always saves by default
economy_mode: false
context: business    # BA is RESTRICTED to business context
```
</defaults>

## EXECUTION SEQUENCE

### 1. Parse Flags and Input

**Step 1: Load defaults**
```
{auto_mode}    = false
{save_mode}    = true
{economy_mode} = false
{context}      = "business"
```

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

Enable flags (lowercase - turn ON):
- `-a` or `--auto`     -> `{auto_mode}` = true
- `-s` or `--save`     -> `{save_mode}` = true (already default)
- `-e` or `--economy`  -> `{economy_mode}` = true

Disable flags (UPPERCASE - turn OFF):
- `-A` or `--no-auto`     -> `{auto_mode}` = false
- `-S` or `--no-save`     -> `{save_mode}` = false
- `-E` or `--no-economy`  -> `{economy_mode}` = false

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

**Step 3: Extract feature description**
After removing flags, remaining text becomes `{feature_description}`

---

### 2. Check Resume Mode

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

If `{resume_task}` is set:
1. Search for matching feature in `.business-analyse/`
   ```bash
   find .business-analyse -type d -name "*{resume_task}*" 2>/dev/null | head -1
   ```
2. If found: Read `00-context.md` to restore state variables
3. Find last completed step (look for "Status: Complete" in progress table)
4. Load next incomplete step
5. **STOP** - do not continue with fresh init

If NOT found:
- Display error: "Feature {resume_task} not found"
- List available features for selection
- Exit or prompt for new task

---

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

If `{interactive_mode}` = true:

Use AskUserQuestion with these questions:

```json
{
  "questions": [
    {
      "question": "What execution mode do you prefer?",
      "header": "Mode",
      "options": [
        {"label": "Autonomous (-a)", "description": "No confirmations, smooth execution"},
        {"label": "Interactive", "description": "Confirmation at each step"}
      ],
      "multiSelect": false
    },
    {
      "question": "Use economy mode (without subagents)?",
      "header": "Economy",
      "options": [
        {"label": "No (Recommended)", "description": "Better quality with subagents"},
        {"label": "Yes (-e)", "description": "Token savings, lower quality"}
      ],
      "multiSelect": false
    }
  ]
}
```

---

### 4. Validate Business Context

**CRITICAL: BA is RESTRICTED to 'business' context only!**

```
IF {context} IN ['platform', 'personal', 'system'] THEN
  DISPLAY ERROR:
  "Business Analysis is restricted to 'business' context only.
   Platform/Personal/System modules use different processes.
   Contact: support@atlshub.ch"
  EXIT
END IF
```

---

### 5. Determine Application and Module

Ask user to specify:

```json
{
  "questions": [
    {
      "question": "Which business application to target?",
      "header": "Application",
      "options": [
        {"label": "New application", "description": "Create a new business application"},
        {"label": "Existing application", "description": "Add a module to an existing application"}
      ],
      "multiSelect": false
    }
  ]
}
```

If "Existing application":
- Scan `.business-analyse/business/` for existing applications
- Present list for selection

Store in:
- `{application_name}` - PascalCase (e.g., "Sales", "HR", "Inventory")
- `{module_name}` - PascalCase (e.g., "Clients", "Orders", "Products")

---

### 6. Generate Feature ID

```bash
# Read last ID from config
LAST_ID=$(grep -oP '"lastFeatureId":\s*\K\d+' .business-analyse/config.json 2>/dev/null || echo "0")

# Increment
NEW_ID=$((LAST_ID + 1))

# Format as FEAT-NNN
{feature_id} = printf "FEAT-%03d" $NEW_ID
```

---

### 7. Create Output Structure

**Create directory structure:**

```
.business-analyse/
├── config.json                    # Global config (update lastFeatureId)
└── business/
    └── {application_name}/
        └── modules/
            └── {module_name}/
                └── features/
                    └── {feature_id}/
                        ├── 00-context.md      # State + progress
                        └── tracking/
                            ├── changes/
                            ├── bugs/
                            └── hotfixes/
```

**Set output_dir:**
```
{output_dir} = .business-analyse/business/{application_name}/modules/{module_name}/features/{feature_id}
```

---

### 8. Write 00-context.md

Create initial context file with state variables:

```markdown
# Business Analysis: {{feature_id}}

**Created:** {{timestamp}}
**Feature:** {{feature_description}}
**Application:** business/{{application_name}}/{{module_name}}

## Configuration

| Setting | Value |
|---------|-------|
| Auto mode | {{auto_mode}} |
| Save mode | {{save_mode}} |
| Economy mode | {{economy_mode}} |

## Progress

| Step | Status | Started | Completed |
|------|--------|---------|-----------|
| 00-init | Complete | {{timestamp}} | {{timestamp}} |
| 01-discover | Pending | - | - |
| 02-analyse | Pending | - | - |
| 03-specify | Pending | - | - |
| 04-validate | Pending | - | - |
| 05-handoff | Pending | - | - |
| 06-doc-html | Pending | - | - |

## State Variables

| Variable | Value |
|----------|-------|
| feature_id | {{feature_id}} |
| feature_description | {{feature_description}} |
| application_name | {{application_name}} |
| module_name | {{module_name}} |
| context | business |
| permission_base | business.{{application_name}}.{{module_name}} |

## Acceptance Criteria

To be defined in step-01-discover.

---

## Notes

(Add notes during analysis)
```

---

### 9. Update Global Config

Update `.business-analyse/config.json`:

```json
{
  "project": "{ProjectName}",
  "lastFeatureId": {NEW_ID},
  "context": "business",
  "standards": ["BABOK-v3", "IEEE-830"],
  "contact": "support@atlshub.ch"
}
```

---

### 10. Display Summary and Load Next Step

**Display:**
```
INIT - {{feature_id}}
├── Application: business/{{application_name}}
├── Module: {{module_name}}
├── Output: {{output_dir}}
├── Mode: {{auto_mode ? "Autonomous" : "Interactive"}}
└── Next: step-01-discover (ULTRATHINK elicitation)
```

**Load next step:**
```
Read and execute: steps/step-01-discover.md
```

---

## OUTPUT

This step produces:
- `.business-analyse/config.json` (updated)
- `{output_dir}/00-context.md` (created)
- `{output_dir}/tracking/` directories (created)

State variables persisted for next steps.
