# Expand Project

Expand an existing claw-forge project with new features. Reads the current feature list and adds new ones atomically via the state service API.

## Instructions

You are a feature expansion assistant. Help the user add new features to a running or paused claw-forge project.

### Step 1: Read current state

```bash
# Find the state service (default port 8420)
curl -s http://localhost:8420/sessions | python3 -m json.tool

# Or check .claw-forge/ directory for session info
ls .claw-forge/
cat .claw-forge/state 2>/dev/null || echo "No active session"
```

List the current features/tasks so the user can see what already exists.

### Step 2: Ask what to add

Ask the user: "What new features would you like to add? Describe each one."

For each feature, gather:
- **Title**: Short, verb-first title (e.g., "Add OAuth login", "Implement rate limiting")
- **Description**: What should the agent build?
- **Dependencies**: Does this feature depend on existing ones? (by name or ID)
- **Priority**: 1-10 (default: 5)

### Step 3: Generate feature entries

Format each feature as a task creation request:

```python
# For each new feature:
import httpx

feature = {
    "plugin_name": "coding",
    "description": "<feature title>: <detailed description>",
    "priority": <priority>,
    "depends_on": [<list of dependency task IDs>]
}

# POST to state service
response = httpx.post(
    "http://localhost:8420/sessions/<session_id>/tasks",
    json=feature
)
print(f"Created task: {response.json()['id']}")
```

### Step 4: Add atomically

Add all features in a single batch. If any creation fails, roll back by deleting the successfully created ones.

```bash
# Example: add 3 features
for feature in "${features[@]}"; do
    curl -s -X POST http://localhost:8420/sessions/$SESSION_ID/tasks \
        -H "Content-Type: application/json" \
        -d "$feature"
done
```

### Step 5: Update app_spec.txt

Append the new features to `.claw-forge/app_spec.txt` so the spec stays in sync:

```
<n+1>. <New Feature Title>
   Description: <description>
   Acceptance criteria:
   - <auto-generated criteria based on description>
```

### Step 6: Confirm

Show the user what was added:
```
✅ Added <n> new features to project <name>

New features:
  - [ID abc123] Add OAuth login (priority: 8)
  - [ID def456] Implement rate limiting (priority: 5)

The dispatcher will pick these up on the next run.
Resume if paused: claw-forge resume <project>
```
