# Command Extraction

## Context

Module: {{MODULE_NAME}}
Feature docs: {{FEATURE_DOCS}}

## Instructions

Read ALL feature docs and extract command (write operation) definitions.

1. Read ALL feature docs at the paths above
2. For each feature, identify operations that change state
3. For each operation, extract:
   - Command name (following naming convention)
   - Input parameters
   - Business rules and validations
   - Error scenarios
   - Process flow (step-by-step)

## Naming Convention

See [naming.md](naming.md) for the full canonical verb vocabulary.

Key mappings:

| Feature Operation    | Command Name   |
| -------------------- | -------------- |
| "Create X" / "Add X" | `createX`      |
| "Update X"           | `updateX`      |
| "Delete X"           | `deleteX`      |
| "Deactivate X"       | `deactivateX`  |
| "Activate X"         | `activateX`    |
| "Reactivate X"       | `reactivateX`  |
| "Set default X"      | `setDefaultX`  |
| "Assign X to Y"      | `assignXToY`   |
| "Remove X from Y"    | `removeXFromY` |
| "Revoke X from Y"    | `revokeXFromY` |
| "Move X"             | `moveX`        |
| "Log X"              | `logX`         |

**Banned verbs**: `archive`, `unarchive`, `disable`, `enable`, `add...To...`, `unlink`

## Document Commands (header + lines)

When the target model is a transactional document (header + line items: orders, bills, receipts, requisitions, …), describe its update/amend commands as **incremental line changes** — individual lines added, updated, or removed, with unreferenced lines left untouched — not a full-replacement of the line set. Capture that behavior in `## Business Rules`.

## Permission Scope

Each command must specify a `## Permission Scope` section in its doc. The scope becomes the middle segment of the permission key: `module:scope:command`.

- Group by **capability** (what gets granted/revoked together), not by resource
- Different access levels for the same resource = different scopes (e.g., audit: "log recording" vs "log configuration")

## Extraction Rules

### Business Rules

- Extract explicit validation rules from feature scenarios
- Extract implicit rules from test cases ("should not allow X when Y")
- Map each rule to an error scenario

### Error Scenarios

- For each business rule violation, define an error code
- Follow SCREAMING_SNAKE_CASE convention
- Categories: NOT_FOUND, DUPLICATE, LOCKED/INACTIVE, INVALID_STATE, NO_OP

### Process Flow

- Extract step-by-step flow from feature scenarios
- Identify branching points (conditional logic)
- Map to validate → query → mutate pattern

## Output Format

Return your extraction as a structured markdown report:

### Commands

For each command:

#### <commandName>

- **Source features:** list of feature files
- **Target model:** ModelName
- **Inputs:**

| Param | Type | Required | Description |
| ----- | ---- | -------- | ----------- |

- **Business Rules:**

| Rule | Error Code | Error Message |
| ---- | ---------- | ------------- |

- **Process Flow:** numbered steps
- **Permission Scope:** scopeName
