substrate-ai 0.1.14 → 0.1.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -42,45 +42,33 @@ substrate --version # global install
42
42
 
43
43
  ## Quick Start
44
44
 
45
- ### Autonomous Pipeline (recommended)
45
+ ### Using Substrate from Claude Code
46
46
 
47
- Got an idea? Substrate can take it from concept to working code.
47
+ The primary way to use Substrate is from inside a Claude Code session. Substrate teaches Claude how to operate the pipeline automatically — no manual configuration needed.
48
48
 
49
- 1. **Brainstorm** explore your idea with a multi-persona AI session:
50
-
51
- ```bash
52
- [npx] substrate brainstorm
53
- ```
54
-
55
- 2. **Initialize the pipeline** — set up the methodology pack and decision store:
49
+ 1. **Install and initialize** in your project:
56
50
 
57
51
  ```bash
52
+ npm install substrate-ai
58
53
  [npx] substrate auto init
59
54
  ```
60
55
 
61
- 3. **Run the full pipeline** analysis, planning, solutioning, and implementation:
62
-
63
- ```bash
64
- [npx] substrate auto run
65
- ```
56
+ This scaffolds CLAUDE.md with a `## Substrate Pipeline` section containing behavioral directives. Claude Code reads this on session start.
66
57
 
67
- Substrate walks through the entire software development lifecycle autonomously:
68
- - **Analysis** — generates a product brief from your brainstorm
69
- - **Planning** — creates a PRD with requirements
70
- - **Solutioning** — produces architecture, epics, and stories
71
- - **Implementation** — dispatches agents to build, test, and code-review each story
58
+ 2. **Start a Claude Code session.** Claude sees the substrate instructions automatically and knows to run `substrate auto run --help-agent` on first use to learn the full event protocol, commands, and interaction patterns.
72
59
 
73
- You can start from any phase or resume an interrupted run:
60
+ 3. **Tell Claude what to build.** Claude drives the pipeline conversationally — running stories, parsing structured events, handling escalations, offering to fix review issues, and summarizing results. You stay in control: Claude always asks before re-running failed stories or applying fixes.
74
61
 
75
62
  ```bash
76
- [npx] substrate auto run --from solutioning # Skip to a specific phase
77
- [npx] substrate auto resume # Pick up where you left off
78
- [npx] substrate auto status # Check pipeline progress
63
+ # What Claude runs under the hood:
64
+ substrate auto run --events --stories 7-1,7-2 # Structured NDJSON for Claude to parse
65
+ substrate auto run # Human-readable progress (default)
66
+ substrate auto run --help-agent # Full protocol reference (<2000 tokens)
79
67
  ```
80
68
 
81
69
  ### Pick Up an Existing BMAD Project
82
70
 
83
- Already have a project with BMAD artifacts (vanilla BMAD or the Beads-based ai-toolkit)? Substrate can pick up the remaining implementation work. It reads one directory `_bmad-output/` — and doesn't care which tool created it.
71
+ Already have a project with BMAD artifacts (from vanilla BMAD, the Beads-based ai-toolkit, or any other tool)? Substrate can pick up the remaining implementation work from inside a Claude Code session.
84
72
 
85
73
  **What Substrate needs from your project:**
86
74
 
@@ -91,26 +79,136 @@ Already have a project with BMAD artifacts (vanilla BMAD or the Beads-based ai-t
91
79
  | `_bmad-output/implementation-artifacts/*.md` | Optional | Existing story files — Substrate skips create-story for any it finds |
92
80
  | `package.json` | Optional | Test framework detection |
93
81
 
94
- **Three commands:**
82
+ **Setup (one-time):**
95
83
 
96
84
  ```bash
97
85
  npm install substrate-ai
98
- [npx] substrate auto init # Seeds context from _bmad-output/
99
- [npx] substrate auto run --stories 5-3,5-4,6-1 # Only the unfinished story keys
86
+ [npx] substrate auto init
87
+ ```
88
+
89
+ **Then start a Claude Code session and tell it what to do:**
90
+
91
+ > "Run the substrate pipeline to implement the remaining stories."
92
+
93
+ Claude reads the CLAUDE.md scaffold, discovers the substrate commands, and drives the pipeline — implementing stories, handling code review cycles, and summarizing results. You stay in the loop for escalations and failed stories.
94
+
95
+ Substrate reads one directory — `_bmad-output/` — and doesn't care which tool created it. It does not read `sprint-status.yaml` or `.beads/` — you decide what's left by choosing which story keys to pass.
96
+
97
+ ### Autonomous Pipeline (standalone)
98
+
99
+ Substrate also runs standalone without an AI agent driving it:
100
+
101
+ ```bash
102
+ [npx] substrate brainstorm # Explore your idea
103
+ [npx] substrate auto init # Set up methodology pack
104
+ [npx] substrate auto run # Full pipeline: analysis → implement
105
+ [npx] substrate auto run --from solutioning # Skip to a specific phase
106
+ [npx] substrate auto resume # Pick up where you left off
107
+ [npx] substrate auto status # Check pipeline progress
100
108
  ```
101
109
 
102
- For each story, Substrate runs: **create-story** (skipped if story file exists) **dev-story** (implement) **code-review** (adversarial review). Non-conflicting stories run in parallel automatically.
110
+ The pipeline walks through the full software development lifecycle: analysis, planning, solutioning, and implementation dispatching agents to build, test, and code-review each story.
103
111
 
104
- Substrate does not read `sprint-status.yaml` or `.beads/` — you decide what's left by choosing which story keys to pass.
112
+ ## Supported Worker Agents
105
113
 
106
- ## Supported Agents
114
+ Substrate dispatches work to CLI-based AI agents running as child processes. It never calls LLMs directly — all implementation, code review, and story generation is delegated to these worker agents.
107
115
 
108
116
  | Agent ID | CLI Tool | Billing |
109
117
  |----------|----------|---------|
110
- | `claude-code` | Claude Code | Subscription (Max) or API key |
111
- | `codex` | Codex CLI | Subscription (ChatGPT Plus/Pro) or API key |
118
+ | `claude-code` | [Claude Code](https://docs.anthropic.com/en/docs/claude-code) | Subscription (Max) or API key |
119
+ | `codex` | [Codex CLI](https://github.com/openai/codex) | Subscription (ChatGPT Plus/Pro) or API key |
112
120
  | `gemini` | Gemini CLI | Subscription or API key |
113
121
 
122
+ All three agents are fully supported as worker targets. Substrate auto-discovers available agents and routes work based on adapter health checks and configuration.
123
+
124
+ > **Note on agent scaffolding:** Separately from worker dispatch, Substrate can also scaffold instruction files that teach an AI agent how to *drive* the pipeline as a front-end. Today, `substrate auto init` generates a CLAUDE.md scaffold for Claude Code (see [AI Agent Integration](#ai-agent-integration)). Equivalent scaffolds for Codex (`AGENTS.md`) and Gemini (`GEMINI.md`) are planned.
125
+
126
+ ## Pipeline Observability
127
+
128
+ Substrate provides multiple output modes for monitoring pipeline execution.
129
+
130
+ ### Human-Readable Progress (default)
131
+
132
+ `substrate auto run` displays compact, updating progress lines with color:
133
+
134
+ ```
135
+ substrate auto run — 6 stories, concurrency 3
136
+
137
+ [create] 7-1 creating story...
138
+ [dev] 7-2 implementing...
139
+ [review] 7-3 SHIP_IT (1 cycle)
140
+ [fix] 7-4 fixing minor issues...
141
+ [done] 7-5 SHIP_IT (2 cycles)
142
+ [wait] 1-9 queued
143
+
144
+ Pipeline complete: 5 succeeded, 0 failed, 1 escalated
145
+ ```
146
+
147
+ - **TTY mode**: ANSI cursor control for in-place line updates
148
+ - **Non-TTY mode**: plain text, one line per update (CI-friendly)
149
+ - Respects `NO_COLOR` environment variable
150
+ - Pino JSON logs suppressed by default — use `--verbose` to restore them
151
+
152
+ ### NDJSON Event Protocol (`--events`)
153
+
154
+ For programmatic consumption, `--events` emits newline-delimited JSON events on stdout:
155
+
156
+ ```bash
157
+ [npx] substrate auto run --events
158
+ [npx] substrate auto run --events --stories 7-1,7-2
159
+ ```
160
+
161
+ Seven event types form a discriminated union on the `type` field:
162
+
163
+ | Event | Description |
164
+ |-------|-------------|
165
+ | `pipeline:start` | Pipeline begins — includes `run_id`, `stories[]`, `concurrency` |
166
+ | `pipeline:complete` | Pipeline ends — includes `succeeded[]`, `failed[]`, `escalated[]` |
167
+ | `story:phase` | Story transitions between phases (`create-story`, `dev-story`, `code-review`, `fix`) |
168
+ | `story:done` | Story reaches terminal success state with `review_cycles` count |
169
+ | `story:escalation` | Story escalated after exhausting review cycles — includes issue list with severities |
170
+ | `story:warn` | Non-fatal warning (e.g., token ceiling truncation) |
171
+ | `story:log` | Informational progress message |
172
+
173
+ All events carry a `ts` (ISO-8601 timestamp) field. The full TypeScript types are exported from the package:
174
+
175
+ ```typescript
176
+ import type { PipelineEvent, StoryEscalationEvent } from 'substrate-ai'
177
+
178
+ const event: PipelineEvent = JSON.parse(line)
179
+ if (event.type === 'story:escalation') {
180
+ for (const issue of event.issues) {
181
+ console.log(`[${issue.severity}] ${issue.file}: ${issue.desc}`)
182
+ }
183
+ }
184
+ ```
185
+
186
+ ## AI Agent Integration
187
+
188
+ Substrate is designed to be operated by AI agents, not just humans. Two mechanisms teach agents how to interact with the pipeline at runtime:
189
+
190
+ ### Self-Describing CLI (`--help-agent`)
191
+
192
+ ```bash
193
+ [npx] substrate auto run --help-agent
194
+ ```
195
+
196
+ Outputs a machine-optimized markdown prompt fragment (<2000 tokens) that an AI agent can ingest as a system prompt. Generated from the same TypeScript type definitions as the event emitter, so documentation never drifts from implementation. Includes:
197
+
198
+ - All available commands and flags with examples
199
+ - Complete event protocol schema
200
+ - Decision flowchart for handling each event type
201
+ - Version stamp for detecting stale cached instructions
202
+
203
+ ### CLAUDE.md Scaffold
204
+
205
+ `substrate auto init` injects a `## Substrate Pipeline` section into your project's CLAUDE.md with behavioral directives for Claude Code:
206
+
207
+ - Instructions to run `--help-agent` on first use
208
+ - Event-driven interaction patterns (escalation handling, fix offers, confirmation requirements)
209
+ - Section is wrapped in `<!-- substrate:start/end -->` markers for idempotent updates
210
+ - Re-running `init` updates the substrate section while preserving all other CLAUDE.md content
211
+
114
212
  ## Commands
115
213
 
116
214
  ### Pipeline
@@ -120,6 +218,9 @@ Substrate does not read `sprint-status.yaml` or `.beads/` — you decide what's
120
218
  | `substrate brainstorm` | Interactive multi-persona ideation session |
121
219
  | `substrate auto init` | Initialize methodology pack for autonomous pipeline |
122
220
  | `substrate auto run` | Run the full pipeline (analysis → implement) |
221
+ | `substrate auto run --events` | Emit NDJSON event stream on stdout |
222
+ | `substrate auto run --verbose` | Show full pino log output on stderr |
223
+ | `substrate auto run --help-agent` | Print agent instruction prompt fragment and exit |
123
224
  | `substrate auto run --from <phase>` | Start from a specific phase |
124
225
  | `substrate auto resume` | Resume an interrupted pipeline run |
125
226
  | `substrate auto status` | Show pipeline run status |