# @rolemodel/chains — Dynamic Chain Extension

This extension discovers `.chain.json` files and registers a slash command for each one, so you can invoke a multi-step subagent pipeline as `/<chain-name> <task>` instead of `/run-chain <chain-name> -- <task>`. It is **not** a subagent tool — it has no chaining or subagent logic of its own. The actual subagent execution comes from the [`pi-subagents`](https://github.com/nicobailon/pi-subagents) extension's chain mode. This extension is purely an alias layer: it reads chain files, translates them into a `subagent({ chain: [...] })` call, and injects that into your session.

> **Requires [`pi-subagents`](https://github.com/nicobailon/pi-subagents) installed and enabled.** If the subagent tool is not available, chain commands will fail with "Invalid parameters" errors.

## Table of Contents

- [Quick Start](#quick-start)
- [Chain File Format](#chain-file-format)
- [Configuration](#configuration)

---

## Quick Start

```bash
# 1. Install the subagent extension (required dependency)
pi install npm:pi-subagents

# 2. Install this chains extension
pi install npm:@rolemodel/pi-chains

# 3. Create a chain directory and write your first chain
mkdir -p ~/.pi/agent/chains

cat > ~/.pi/agent/chains/my-review.chain.json << 'EOF'
{
  "name": "my-review",
  "description": "Review PR and suggest improvements",
  "chain": [
    { "agent": "reviewer", "task": "Review changes: {task}" },
    { "agent": "worker", "task": "Suggest improvements: {previous}" }
  ]
}
EOF
```

Reload and use:
```
/reload
/my-review Add input validation to the auth endpoint
```

---

## Chain File Format

This follows the format from [`pi-subagents`](https://github.com/nicobailon/pi-subagents). It requires the JSON format. Any chains with the markdown syntax will not be registered.

## Configuration

### Chain Directories

The extension searches chain directories in this order:

| Priority | Location | Scope |
|----------|----------|-------|
| 1 | `~/.pi/agent/chains/` | Global (all projects) |
| 2 | `.pi/agent/chains/` (relative to cwd) | Project-local (only if it exists) |

Chains are discovered at extension startup and on `/reload`.
