---
name: step-01-discover
description: Discovery phase - Elicitation with ULTRATHINK (load questionnaire progressively)
model: opus
prev_step: steps/step-00-init.md
next_step: steps/step-02-analyse.md
---

<objective>
Conduct comprehensive requirements elicitation using ULTRATHINK mode.
Load questionnaire categories progressively based on feature type.
</objective>

<ultrathink>
ULTRATHINK MODE ACTIVE - Critical thinking required:
- Consider ALL edge cases before formulating questions
- Challenge EVERY stakeholder assumption
- Anticipate UNEXPRESSED needs
- Validate completeness before proceeding
- DO NOT accept vague answers
- DO NOT skip question categories
</ultrathink>

## EXECUTION SEQUENCE

### 1. Read Current State

Read `{output_dir}/00-context.md` to restore:
- `{feature_id}`
- `{feature_description}`
- `{application_name}`
- `{module_name}`
- `{auto_mode}`
- `{economy_mode}`

Update progress: `01-discover` -> "In Progress"

---

### 2. Determine Feature Type

Analyze `{feature_description}` to categorize:

| Type | Indicators | Load Categories |
|------|------------|-----------------|
| **Data-centric** | "management", "CRUD", "entity", "data" | 01, 02, 03, 04, 06 |
| **Integration** | "API", "sync", "import", "export", "external" | 01, 02, 03, 05, 06 |
| **UI-centric** | "screen", "form", "dashboard", "interface" | 01, 02, 03, 06, 07 |
| **Workflow** | "process", "validation", "workflow", "steps" | 01, 02, 03, 06, 09 |
| **Reporting** | "report", "export", "statistics", "KPI" | 01, 02, 03, 04, 08 |
| **Full module** | "module", "complete", "feature" | ALL categories |

Store: `{feature_type}`

---

### 3. Load Questionnaire Categories (Progressive)

**IMPORTANT: Load ONLY relevant categories to minimize context!**

#### Always load (core):
```
Read: questionnaire/01-context.md      # ~50 lines
Read: questionnaire/02-stakeholders.md # ~40 lines
Read: questionnaire/03-scope.md        # ~35 lines
Read: questionnaire/06-security.md     # ~30 lines (minimal)
```

#### Conditional loading based on feature_type:
```
IF {feature_type} = "Data-centric" OR "Full module":
  Read: questionnaire/04-data.md       # ~45 lines

IF {feature_type} = "Integration" OR "Full module":
  Read: questionnaire/05-integrations.md # ~30 lines

IF {feature_type} = "UI-centric" OR "Full module":
  Read: questionnaire/07-ui.md         # ~20 lines

IF {feature_type} = "Reporting" OR performance-critical:
  Read: questionnaire/08-performance.md # ~25 lines

IF {feature_type} = "Workflow" OR constraints exist:
  Read: questionnaire/09-constraints.md # ~25 lines

IF documentation required:
  Read: questionnaire/10-documentation.md # ~20 lines
```

**Maximum context per discovery: ~150-200 lines** (vs 283 lines before)

---

### 4. Conduct Elicitation

#### 4.1 Category 1: Business Context (ALWAYS)

Ask questions from `01-context.md`:
- Q1.1: Business problem to solve?
- Q1.2: Current situation (AS-IS)?
- Q1.3: Target situation (TO-BE)?
- Q1.4: Measurable KPIs?
- Q1.5-Q1.8: Business value questions

**ULTRATHINK checkpoint:**
- Is the problem clearly defined?
- Are success criteria measurable?
- What happens if NOT developed?

#### 4.2 Category 2: Stakeholders (ALWAYS)

Ask questions from `02-stakeholders.md`:
- Q2.1-Q2.4: Identification
- Q2.5-Q2.8: Needs per role

**ULTRATHINK checkpoint:**
- All user types identified?
- Pain points documented per role?
- Decision maker confirmed?

#### 4.3 Category 3: Scope (ALWAYS)

Ask questions from `03-scope.md`:
- Q3.1-Q3.4: MoSCoW prioritization
- Q3.5-Q3.8: Process flows

**ULTRATHINK checkpoint:**
- Must-Have vs Should-Have clear?
- Exclusions explicit?
- Main flow documented?

#### 4.4 Additional Categories (CONDITIONAL)

For each loaded category, conduct targeted elicitation.
Document responses with:
- Source (who answered)
- Confidence level (Confirmed/To validate/Hypothesis)
- Follow-up questions

---

### 5. Explore Codebase (if economy_mode = false)

**Launch parallel exploration agents:**

```
Agent 1: Existing patterns
  "Search for similar modules in src/SmartStack.Domain/Entities/
   and src/SmartStack.Application/Features/ to understand patterns"

Agent 2: Related integrations
  "Search for existing APIs and integrations that this module
   might need to connect with"

Agent 3: UI patterns (if UI-centric)
  "Search for similar pages in web/smartstack-web/src/pages/business/
   to understand React patterns"
```

If `{economy_mode}` = true:
- Use direct Glob/Grep tools only
- Read 3-5 most relevant files
- Skip subagents

---

### 6. Synthesize Discovery

Compile all findings into structured format:

```markdown
# Discovery - {feature_id} {feature_description}

> **Module:** business/{application_name}/{module_name}
> **Version:** 1.0
> **Date:** {timestamp}
> **Author:** Business Analyst (Claude)

## 1. Business Context

### 1.1 Need Description
{Synthesized from Q1.1-Q1.4}

### 1.2 Current Problem
{From Q1.2}

### 1.3 Expected Value
{From Q1.5-Q1.7, quantified if possible}

## 2. Stakeholders

| Role | Function | Involvement | Decision Level |
|------|----------|-------------|-----------------|
{Table from Q2.x responses}

## 3. Scope

### 3.1 In Scope (Must-Have)
{From Q3.1}

### 3.2 Should-Have
{From Q3.2}

### 3.3 Out of Scope
{From Q3.4 - EXPLICIT exclusions}

## 4. Open Questions

| # | Question | Answer | Status |
|---|----------|--------|--------|
{Any unresolved questions}

## 5. Identified Constraints

| Type | Constraint | Impact |
|------|------------|--------|
{From loaded constraint categories}

## 6. Acceptance Criteria (Inferred)

- [ ] AC-001: {criterion 1}
- [ ] AC-002: {criterion 2}
...
```

---

### 7. Save Output

Write to: `{output_dir}/1-discovery.md`

Update `00-context.md`:
- Progress: `01-discover` -> "Complete"
- Add acceptance criteria to state

---

### 8. Display Summary and Load Next Step

**Display:**
```
DISCOVERY - {feature_id}
├── Status: Complete
├── Categories loaded: {list of loaded categories}
├── Questions answered: {count}
├── Open questions: {count}
├── Output: {output_dir}/1-discovery.md
└── Next: step-02-analyse (BRD formalization)
```

**If NOT auto_mode:**
Ask: "Proceed with business rules analysis?"

**Load next step:**
```
Read and execute: steps/step-02-analyse.md
```

---

## OUTPUT

This step produces:
- `{output_dir}/1-discovery.md` (created)
- `{output_dir}/00-context.md` (updated with AC)

Questionnaire categories loaded: **~150-200 lines max** (70% reduction)
