planflow-ai 1.3.0 → 1.3.4
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/.claude/commands/brainstorm.md +2 -2
- package/.claude/commands/discovery-plan.md +11 -0
- package/.claude/commands/execute-plan.md +26 -2
- package/.claude/commands/flow.md +5 -0
- package/.claude/commands/heartbeat.md +1 -1
- package/.claude/commands/learn.md +4 -6
- package/.claude/commands/{brain.md → note.md} +12 -12
- package/.claude/commands/review-code.md +61 -1
- package/.claude/commands/review-pr.md +61 -1
- package/.claude/commands/setup.md +11 -1
- package/.claude/resources/core/_index.md +102 -2
- package/.claude/resources/core/compaction-guide.md +111 -0
- package/.claude/resources/core/discovery-sub-agents.md +266 -0
- package/.claude/resources/core/phase-isolation.md +222 -0
- package/.claude/resources/core/resource-capture.md +1 -1
- package/.claude/resources/core/review-adaptive-depth.md +217 -0
- package/.claude/resources/core/review-multi-agent.md +289 -0
- package/.claude/resources/core/review-severity-ranking.md +149 -0
- package/.claude/resources/core/review-verification.md +158 -0
- package/.claude/resources/core/session-scratchpad.md +105 -0
- package/.claude/resources/patterns/review-code-templates.md +315 -2
- package/.claude/resources/skills/_index.md +108 -42
- package/.claude/resources/skills/brain-skill.md +3 -3
- package/.claude/resources/skills/discovery-skill.md +50 -6
- package/.claude/resources/skills/execute-plan-skill.md +14 -6
- package/.claude/resources/skills/review-code-skill.md +73 -0
- package/.claude/resources/skills/review-pr-skill.md +58 -0
- package/README.md +38 -3
- package/dist/cli/commands/heartbeat.js.map +1 -1
- package/dist/cli/daemon/heartbeat-daemon.js +31 -1
- package/dist/cli/daemon/heartbeat-daemon.js.map +1 -1
- package/dist/cli/daemon/heartbeat-parser.d.ts.map +1 -1
- package/dist/cli/daemon/heartbeat-parser.js +6 -0
- package/dist/cli/daemon/heartbeat-parser.js.map +1 -1
- package/dist/cli/handlers/claude.js +20 -12
- package/dist/cli/handlers/claude.js.map +1 -1
- package/dist/cli/types.d.ts +1 -0
- package/dist/cli/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/rules/skills/brain-skill.mdc +4 -4
- package/skills/plan-flow/SKILL.md +1 -1
- package/skills/plan-flow/brain/SKILL.md +1 -1
- package/templates/shared/AGENTS.md.template +1 -1
- package/templates/shared/CLAUDE.md.template +11 -1
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
|
|
2
|
+
# Compaction Guide
|
|
3
|
+
|
|
4
|
+
## Purpose
|
|
5
|
+
|
|
6
|
+
When a plan-flow session runs `/compact`, the compaction model summarizes the conversation history. Without guidance, it may discard critical state (phase progress, decisions) or keep low-value tokens (old file reads, resolved searches).
|
|
7
|
+
|
|
8
|
+
**Core principle**: Preserve decisions, discard outputs.
|
|
9
|
+
|
|
10
|
+
### When to Compact
|
|
11
|
+
|
|
12
|
+
- At **phase boundaries** during `/execute-plan` (between phases, never mid-phase)
|
|
13
|
+
- When context feels heavy (many tool calls, large file reads accumulated)
|
|
14
|
+
- Before starting a complex phase (complexity >= 6)
|
|
15
|
+
- During long `/review-code` or `/discovery-plan` sessions with many file reads
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Preserve Rules (High-Signal Tokens)
|
|
20
|
+
|
|
21
|
+
Always include these in the compact summary:
|
|
22
|
+
|
|
23
|
+
| Category | What to Keep | Examples |
|
|
24
|
+
|----------|-------------|----------|
|
|
25
|
+
| **Execution state** | Current skill, phase number, plan slug, completed vs pending phases | "Executing plan_user_auth_v1.md, phase 3 of 5 complete" |
|
|
26
|
+
| **Decision log** | Architecture choices, pattern selections, user preferences, rejected alternatives | "Chose JWT over sessions (discovery DR-4). User rejected Redis caching." |
|
|
27
|
+
| **Error context** | Unresolved errors, failed attempts, workarounds in progress, retry count | "Build fails on type mismatch in auth.ts:42 — tried 2 approaches" |
|
|
28
|
+
| **User requirements** | Original request, clarified constraints, acceptance criteria | "User wants OAuth2 with Google only, no email/password" |
|
|
29
|
+
| **Tasklist state** | Current in-progress items from `flow/tasklist.md` | "In progress: Execute user-auth" |
|
|
30
|
+
| **Pattern buffer** | Pending pattern captures not yet saved | "Buffered: async error handling pattern for approval" |
|
|
31
|
+
| **Active file list** | Files created or modified during the session | "Modified: src/auth/middleware.ts, src/auth/types.ts" |
|
|
32
|
+
| **Scratchpad notes** | Contents of `flow/.scratchpad.md` — ephemeral session notes not yet promoted | "Scratchpad: 3 notes, 1 open question" |
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## Discard Rules (Low-Signal Tokens)
|
|
37
|
+
|
|
38
|
+
Safe to drop from the compact summary:
|
|
39
|
+
|
|
40
|
+
| Category | What to Drop | Why |
|
|
41
|
+
|----------|-------------|-----|
|
|
42
|
+
| **Completed tool results** | File reads from resolved steps, grep results already acted on | Can be re-read if needed |
|
|
43
|
+
| **Superseded content** | Earlier versions of files that were subsequently edited | Only the final state matters |
|
|
44
|
+
| **Verbose output** | Full build logs, test output — keep only pass/fail + error messages | Details can be regenerated |
|
|
45
|
+
| **Exploration dead-ends** | Files read but found irrelevant, abandoned approaches | No future value |
|
|
46
|
+
| **Redundant context** | Content repeated across multiple tool calls | One copy is enough |
|
|
47
|
+
| **Index file contents** | `_index.md` files read for navigation | Re-read on demand |
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## Compact Summary Template
|
|
52
|
+
|
|
53
|
+
When crafting `/compact` instructions, use this structure:
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
## Session State
|
|
57
|
+
- **Active skill**: {skill name — e.g., execute-plan, review-code, discovery}
|
|
58
|
+
- **Active plan**: {plan file path or "none"}
|
|
59
|
+
- **Current phase**: {N of M} — {phase name}
|
|
60
|
+
- **Completed phases**: {list with brief outcomes}
|
|
61
|
+
|
|
62
|
+
## Decisions Made
|
|
63
|
+
- {decision}: {choice} (reason: {why})
|
|
64
|
+
|
|
65
|
+
## Unresolved Issues
|
|
66
|
+
- {error/issue}: {status, what was tried}
|
|
67
|
+
|
|
68
|
+
## Files Modified
|
|
69
|
+
- {file path}: {what changed}
|
|
70
|
+
|
|
71
|
+
## Next Action
|
|
72
|
+
{What to do immediately after compaction}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## Skill-Specific Examples
|
|
78
|
+
|
|
79
|
+
### Execute-Plan Compaction
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
/compact Executing plan_user_auth_v1.md. Completed: Phase 1 (types — done),
|
|
83
|
+
Phase 2 (API endpoints — done). Next: Phase 3 of 5 (Frontend UI, complexity 6).
|
|
84
|
+
Decisions: JWT auth (not sessions), Zod validation. Files modified:
|
|
85
|
+
src/auth/types.ts, src/api/auth.ts. Resume from Phase 3.
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Review-Code Compaction
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
/compact Reviewing 47 changed files. Completed: file categorization, security scan
|
|
92
|
+
(2 findings), logic analysis (3 findings). Next: performance scan. Findings so far:
|
|
93
|
+
1 critical (SQL injection in query.ts), 4 minor. Resume with performance analysis.
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Discovery Compaction
|
|
97
|
+
|
|
98
|
+
```
|
|
99
|
+
/compact Discovery for payment-integration. Questions answered: 5 of 8.
|
|
100
|
+
Key requirements: Stripe only, webhook verification required, idempotency keys.
|
|
101
|
+
Open questions: retry policy, refund flow. Resume with remaining questions.
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## Rules
|
|
107
|
+
|
|
108
|
+
1. **Never compact mid-phase** — only at phase boundaries
|
|
109
|
+
2. **Always include enough context to resume** — the model after compaction should know exactly what to do next
|
|
110
|
+
3. **After compaction, re-read the plan file** — don't rely on memory of plan contents
|
|
111
|
+
4. **Default to preserving** — when in doubt, keep it. It's better to preserve something unnecessary than lose something critical.
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
|
|
2
|
+
# Discovery Sub-Agents
|
|
3
|
+
|
|
4
|
+
## Purpose
|
|
5
|
+
|
|
6
|
+
During `/discovery-plan`, three parallel Agent sub-agents explore the codebase simultaneously. Each focuses on a specific aspect (similar features, API/data patterns, schema/types) and returns condensed JSON findings. The coordinator merges these into a **Codebase Analysis** section in the discovery document, enabling better-informed clarifying questions.
|
|
7
|
+
|
|
8
|
+
**Core principle**: Parallel exploration, condensed returns, cleaner context.
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Architecture
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
Discovery Skill (main session)
|
|
16
|
+
│
|
|
17
|
+
├─ Step 1: Read referenced documents (unchanged)
|
|
18
|
+
│
|
|
19
|
+
├─ Step 1b: Spawn exploration sub-agents in parallel
|
|
20
|
+
│ ├─► Agent: Similar Features (model: haiku)
|
|
21
|
+
│ ├─► Agent: API/Data Patterns (model: haiku)
|
|
22
|
+
│ └─► Agent: Schema/Types (model: haiku)
|
|
23
|
+
│
|
|
24
|
+
├─ Step 1c: Collect and merge findings into Codebase Analysis
|
|
25
|
+
│
|
|
26
|
+
├─ Step 2: Ask clarifying questions (informed by findings)
|
|
27
|
+
│ ... (rest of discovery unchanged)
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
All three sub-agents use **haiku** — exploration is search-heavy (Glob, Grep, Read) with lightweight summarization.
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## Agent Definitions
|
|
35
|
+
|
|
36
|
+
### 1. Similar Features Agent
|
|
37
|
+
|
|
38
|
+
**Focus**: Find existing features or code that does something similar to the proposed feature.
|
|
39
|
+
|
|
40
|
+
**Prompt template**:
|
|
41
|
+
```
|
|
42
|
+
You are a codebase explorer. Your task is to find existing code that is similar to a proposed feature.
|
|
43
|
+
|
|
44
|
+
Feature: {feature_name}
|
|
45
|
+
Context: {context_summary_from_step_1}
|
|
46
|
+
|
|
47
|
+
Search for:
|
|
48
|
+
- Components, modules, or services that handle related functionality
|
|
49
|
+
- Route handlers or endpoints with similar purpose
|
|
50
|
+
- Existing UI patterns that address similar use cases
|
|
51
|
+
- Utility functions that could be reused
|
|
52
|
+
|
|
53
|
+
Use Glob and Grep to search the codebase. Read relevant files to understand their purpose.
|
|
54
|
+
|
|
55
|
+
Return your findings as JSON:
|
|
56
|
+
{
|
|
57
|
+
"agent": "similar-features",
|
|
58
|
+
"status": "success",
|
|
59
|
+
"findings": [
|
|
60
|
+
{
|
|
61
|
+
"file": "path/to/file.ts",
|
|
62
|
+
"description": "Brief description of what this file does and how it relates",
|
|
63
|
+
"relevance": "high" | "medium" | "low"
|
|
64
|
+
}
|
|
65
|
+
],
|
|
66
|
+
"summary": "2-3 sentence overview of similar features found",
|
|
67
|
+
"patterns_noticed": ["List of coding conventions or patterns observed"]
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
Rules:
|
|
71
|
+
- Only READ files (Glob, Grep, Read) — never write or edit
|
|
72
|
+
- Return at most 10 findings, sorted by relevance
|
|
73
|
+
- Keep the summary under 200 words
|
|
74
|
+
- Focus on HIGH relevance findings
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### 2. API/Data Patterns Agent
|
|
78
|
+
|
|
79
|
+
**Focus**: Scan for existing API endpoints, data models, service patterns, and integration points.
|
|
80
|
+
|
|
81
|
+
**Prompt template**:
|
|
82
|
+
```
|
|
83
|
+
You are a codebase explorer. Your task is to map the API and data patterns in this project.
|
|
84
|
+
|
|
85
|
+
Feature: {feature_name}
|
|
86
|
+
Context: {context_summary_from_step_1}
|
|
87
|
+
|
|
88
|
+
Search for:
|
|
89
|
+
- API route definitions and endpoint patterns (REST, GraphQL, tRPC)
|
|
90
|
+
- Controller/handler organization and naming conventions
|
|
91
|
+
- Service layer patterns (repository pattern, direct DB access, etc.)
|
|
92
|
+
- Data flow: how requests are processed from route → handler → service → response
|
|
93
|
+
- Middleware patterns (auth, validation, error handling)
|
|
94
|
+
- API response shapes and error formats
|
|
95
|
+
|
|
96
|
+
Use Glob and Grep to search the codebase. Read relevant files to understand patterns.
|
|
97
|
+
|
|
98
|
+
Return your findings as JSON:
|
|
99
|
+
{
|
|
100
|
+
"agent": "api-data-patterns",
|
|
101
|
+
"status": "success",
|
|
102
|
+
"findings": [
|
|
103
|
+
{
|
|
104
|
+
"file": "path/to/file.ts",
|
|
105
|
+
"description": "Brief description of the API/data pattern found",
|
|
106
|
+
"relevance": "high" | "medium" | "low"
|
|
107
|
+
}
|
|
108
|
+
],
|
|
109
|
+
"summary": "2-3 sentence overview of API architecture and data flow patterns",
|
|
110
|
+
"patterns_noticed": ["List of API/data conventions observed"]
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
Rules:
|
|
114
|
+
- Only READ files (Glob, Grep, Read) — never write or edit
|
|
115
|
+
- Return at most 10 findings, sorted by relevance
|
|
116
|
+
- Keep the summary under 200 words
|
|
117
|
+
- Focus on patterns the new feature would need to follow
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### 3. Schema/Types Agent
|
|
121
|
+
|
|
122
|
+
**Focus**: Explore type definitions, database schemas, shared interfaces, and data structures.
|
|
123
|
+
|
|
124
|
+
**Prompt template**:
|
|
125
|
+
```
|
|
126
|
+
You are a codebase explorer. Your task is to map the type system and data schemas in this project.
|
|
127
|
+
|
|
128
|
+
Feature: {feature_name}
|
|
129
|
+
Context: {context_summary_from_step_1}
|
|
130
|
+
|
|
131
|
+
Search for:
|
|
132
|
+
- TypeScript interfaces and type definitions relevant to the feature
|
|
133
|
+
- Database schemas (Prisma, TypeORM, Drizzle, raw SQL migrations)
|
|
134
|
+
- Shared types and enums used across the codebase
|
|
135
|
+
- Zod/Yup/Joi validation schemas
|
|
136
|
+
- API request/response type definitions
|
|
137
|
+
|
|
138
|
+
Use Glob and Grep to search the codebase. Read relevant files to understand the type system.
|
|
139
|
+
|
|
140
|
+
Return your findings as JSON:
|
|
141
|
+
{
|
|
142
|
+
"agent": "schema-types",
|
|
143
|
+
"status": "success",
|
|
144
|
+
"findings": [
|
|
145
|
+
{
|
|
146
|
+
"file": "path/to/file.ts",
|
|
147
|
+
"description": "Brief description of the type/schema and its relevance",
|
|
148
|
+
"relevance": "high" | "medium" | "low"
|
|
149
|
+
}
|
|
150
|
+
],
|
|
151
|
+
"summary": "2-3 sentence overview of relevant type system and schemas",
|
|
152
|
+
"patterns_noticed": ["List of type/schema conventions observed"]
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
Rules:
|
|
156
|
+
- Only READ files (Glob, Grep, Read) — never write or edit
|
|
157
|
+
- Return at most 10 findings, sorted by relevance
|
|
158
|
+
- Keep the summary under 200 words
|
|
159
|
+
- Focus on types the new feature would interact with
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
## Return Format
|
|
165
|
+
|
|
166
|
+
Each sub-agent returns structured JSON:
|
|
167
|
+
|
|
168
|
+
```json
|
|
169
|
+
{
|
|
170
|
+
"agent": "similar-features" | "api-data-patterns" | "schema-types",
|
|
171
|
+
"status": "success" | "failure",
|
|
172
|
+
"findings": [
|
|
173
|
+
{
|
|
174
|
+
"file": "string — relative file path",
|
|
175
|
+
"description": "string — what this file does and how it relates to the feature",
|
|
176
|
+
"relevance": "high" | "medium" | "low"
|
|
177
|
+
}
|
|
178
|
+
],
|
|
179
|
+
"summary": "string — 2-3 sentence overview (under 200 words)",
|
|
180
|
+
"patterns_noticed": ["string — coding conventions or patterns observed"]
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
**Size target**: Each return should be under 2K tokens.
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
## Coordinator Behavior
|
|
189
|
+
|
|
190
|
+
### Step 1b: Spawn Sub-Agents
|
|
191
|
+
|
|
192
|
+
Launch all 3 sub-agents in parallel using the Agent tool:
|
|
193
|
+
|
|
194
|
+
```
|
|
195
|
+
Launch in parallel:
|
|
196
|
+
- Agent(model: "haiku", subagent_type: "Explore", prompt: similar_features_prompt)
|
|
197
|
+
- Agent(model: "haiku", subagent_type: "Explore", prompt: api_data_prompt)
|
|
198
|
+
- Agent(model: "haiku", subagent_type: "Explore", prompt: schema_types_prompt)
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
Each sub-agent receives:
|
|
202
|
+
1. **Feature name** — from the user's input
|
|
203
|
+
2. **Context summary** — brief summary of what Step 1 found in referenced documents
|
|
204
|
+
3. **Exploration instructions** — the agent-specific prompt template above
|
|
205
|
+
|
|
206
|
+
### Step 1c: Collect and Merge Findings
|
|
207
|
+
|
|
208
|
+
1. **Parse returns**: Extract JSON from each sub-agent response
|
|
209
|
+
2. **Handle failures**: If a sub-agent returns `status: "failure"` or fails to return valid JSON, skip its findings and continue. Log the failure but do not block discovery.
|
|
210
|
+
3. **Filter**: Remove findings with `relevance: "low"` if there are more than 15 total findings
|
|
211
|
+
4. **Merge patterns**: Collect all `patterns_noticed` entries across agents, deduplicate, and append to `flow/resources/pending-patterns.md`
|
|
212
|
+
5. **Format Codebase Analysis**: Build the section for the discovery document
|
|
213
|
+
|
|
214
|
+
### Codebase Analysis Section Format
|
|
215
|
+
|
|
216
|
+
```markdown
|
|
217
|
+
## Codebase Analysis
|
|
218
|
+
|
|
219
|
+
### Similar Features
|
|
220
|
+
{summary from similar-features agent}
|
|
221
|
+
|
|
222
|
+
| File | Description | Relevance |
|
|
223
|
+
|------|-------------|-----------|
|
|
224
|
+
| `path/to/file.ts` | Description | High |
|
|
225
|
+
| ... | ... | ... |
|
|
226
|
+
|
|
227
|
+
### API & Data Patterns
|
|
228
|
+
{summary from api-data-patterns agent}
|
|
229
|
+
|
|
230
|
+
| File | Description | Relevance |
|
|
231
|
+
|------|-------------|-----------|
|
|
232
|
+
| ... | ... | ... |
|
|
233
|
+
|
|
234
|
+
### Schema & Types
|
|
235
|
+
{summary from schema-types agent}
|
|
236
|
+
|
|
237
|
+
| File | Description | Relevance |
|
|
238
|
+
|------|-------------|-----------|
|
|
239
|
+
| ... | ... | ... |
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
If a sub-agent returned no findings or failed, omit its subsection entirely.
|
|
243
|
+
|
|
244
|
+
---
|
|
245
|
+
|
|
246
|
+
## Error Handling
|
|
247
|
+
|
|
248
|
+
| Scenario | Behavior |
|
|
249
|
+
|----------|----------|
|
|
250
|
+
| Sub-agent fails (timeout, error) | Skip its findings, continue with other agents' results |
|
|
251
|
+
| Sub-agent returns invalid JSON | Skip its findings, log warning |
|
|
252
|
+
| All sub-agents fail | Continue discovery without Codebase Analysis section |
|
|
253
|
+
| No relevant findings | Omit Codebase Analysis section — discovery proceeds normally |
|
|
254
|
+
|
|
255
|
+
Discovery must never be blocked by sub-agent failures. Findings are supplementary.
|
|
256
|
+
|
|
257
|
+
---
|
|
258
|
+
|
|
259
|
+
## Related Files
|
|
260
|
+
|
|
261
|
+
| File | Purpose |
|
|
262
|
+
|------|---------|
|
|
263
|
+
| `.claude/resources/skills/discovery-skill.md` | Discovery skill (Steps 1b + 1c added) |
|
|
264
|
+
| `.claude/resources/core/review-multi-agent.md` | Similar pattern: parallel specialized subagents |
|
|
265
|
+
| `.claude/resources/core/phase-isolation.md` | Similar pattern: sub-agent with focused prompt → JSON return |
|
|
266
|
+
| `.claude/resources/core/pattern-capture.md` | patterns_noticed entries routed to pending-patterns.md |
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
|
|
2
|
+
# Phase Isolation
|
|
3
|
+
|
|
4
|
+
## Purpose
|
|
5
|
+
|
|
6
|
+
When `phase_isolation: true` in `flow/.flowconfig` (default), each `/execute-plan` phase implementation runs in an **isolated Agent sub-agent** with a clean context window. The sub-agent receives only the context it needs and returns a structured JSON summary. This eliminates context rot — phase 7 has the same quality as phase 1.
|
|
7
|
+
|
|
8
|
+
**Core principle**: Clean context in, structured summary out.
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Architecture
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
Coordinator (main session)
|
|
16
|
+
│
|
|
17
|
+
├─ Present phase in Plan Mode → User approves
|
|
18
|
+
│
|
|
19
|
+
├─ Prepare isolated context (see Context Template below)
|
|
20
|
+
│
|
|
21
|
+
├─ Spawn Agent sub-agent:
|
|
22
|
+
│ model: [tier from model routing]
|
|
23
|
+
│ mode: "auto"
|
|
24
|
+
│ prompt: [focused context + instructions + return format]
|
|
25
|
+
│
|
|
26
|
+
├─ Receive structured JSON summary (1-2K tokens)
|
|
27
|
+
│
|
|
28
|
+
├─ Process summary:
|
|
29
|
+
│ ├─ Update plan file (mark tasks [x])
|
|
30
|
+
│ ├─ Accumulate files_modified list
|
|
31
|
+
│ ├─ Append patterns to pending-patterns.md
|
|
32
|
+
│ ├─ Git commit (if enabled)
|
|
33
|
+
│ └─ Handle errors (present to user if status != success)
|
|
34
|
+
│
|
|
35
|
+
└─ Next phase...
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Planning and user approval always happen in the **main session** (full context). Only the **implementation step** is isolated.
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## Context Template
|
|
43
|
+
|
|
44
|
+
The Agent sub-agent prompt must include exactly these sections:
|
|
45
|
+
|
|
46
|
+
```markdown
|
|
47
|
+
# Phase Implementation: {Phase N — Phase Name}
|
|
48
|
+
|
|
49
|
+
## Plan
|
|
50
|
+
**Feature**: {feature name}
|
|
51
|
+
**Plan file**: {path to plan file}
|
|
52
|
+
|
|
53
|
+
## Phase Scope
|
|
54
|
+
{Scope description from plan}
|
|
55
|
+
|
|
56
|
+
## Tasks
|
|
57
|
+
{Task list from plan, as checklist}
|
|
58
|
+
|
|
59
|
+
## Files Modified in Previous Phases
|
|
60
|
+
{List of file paths created/modified so far, or "None — this is Phase 1"}
|
|
61
|
+
|
|
62
|
+
## Project Patterns
|
|
63
|
+
Read these files before implementing:
|
|
64
|
+
- `.claude/rules/core/allowed-patterns.md`
|
|
65
|
+
- `.claude/rules/core/forbidden-patterns.md`
|
|
66
|
+
|
|
67
|
+
## Design Context
|
|
68
|
+
{Only if UI phase — include design tokens from discovery doc}
|
|
69
|
+
{Otherwise omit this section entirely}
|
|
70
|
+
|
|
71
|
+
## Instructions
|
|
72
|
+
1. Read the plan file to understand the full feature context
|
|
73
|
+
2. Implement all tasks listed above
|
|
74
|
+
3. Follow the project patterns from the files listed
|
|
75
|
+
4. Return a JSON summary in the exact format below — do NOT return markdown
|
|
76
|
+
|
|
77
|
+
## Return Format
|
|
78
|
+
Return ONLY a JSON object (no markdown fences, no explanation):
|
|
79
|
+
{see Return Format Schema below}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Context Size Target
|
|
83
|
+
|
|
84
|
+
The prompt should be **under 2K tokens** (excluding files the sub-agent reads itself via the Read tool). Keep it focused — the sub-agent will read project files as needed during implementation.
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## Return Format Schema
|
|
89
|
+
|
|
90
|
+
The sub-agent must return a JSON object with this structure:
|
|
91
|
+
|
|
92
|
+
```json
|
|
93
|
+
{
|
|
94
|
+
"status": "success",
|
|
95
|
+
"phase": "Phase 1: Create Core Resource",
|
|
96
|
+
"summary": "One-paragraph description of what was implemented and any notable decisions.",
|
|
97
|
+
"files_created": [
|
|
98
|
+
"src/types/auth.ts"
|
|
99
|
+
],
|
|
100
|
+
"files_modified": [
|
|
101
|
+
"src/api/routes.ts",
|
|
102
|
+
"src/utils/helpers.ts"
|
|
103
|
+
],
|
|
104
|
+
"decisions": [
|
|
105
|
+
"Chose JWT over sessions because discovery DR-4 specified stateless auth"
|
|
106
|
+
],
|
|
107
|
+
"deviations": [
|
|
108
|
+
"Task 3 deferred — requires database migration first"
|
|
109
|
+
],
|
|
110
|
+
"errors": [],
|
|
111
|
+
"patterns_captured": [
|
|
112
|
+
{
|
|
113
|
+
"category": "allowed",
|
|
114
|
+
"name": "Zod schema co-location",
|
|
115
|
+
"description": "All Zod schemas live next to their type definitions",
|
|
116
|
+
"confidence": "high"
|
|
117
|
+
}
|
|
118
|
+
]
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Field Descriptions
|
|
123
|
+
|
|
124
|
+
| Field | Type | Required | Description |
|
|
125
|
+
|-------|------|----------|-------------|
|
|
126
|
+
| `status` | `"success" \| "failure" \| "partial"` | Yes | Overall phase outcome |
|
|
127
|
+
| `phase` | string | Yes | Phase number and name |
|
|
128
|
+
| `summary` | string | Yes | 1-3 sentence description of what was done |
|
|
129
|
+
| `files_created` | string[] | Yes | Paths of new files created (empty array if none) |
|
|
130
|
+
| `files_modified` | string[] | Yes | Paths of existing files modified (empty array if none) |
|
|
131
|
+
| `decisions` | string[] | No | Architecture/design decisions made during implementation |
|
|
132
|
+
| `deviations` | string[] | No | Tasks skipped or changed from plan |
|
|
133
|
+
| `errors` | string[] | No | Errors encountered (even if resolved) |
|
|
134
|
+
| `patterns_captured` | object[] | No | Patterns observed during implementation |
|
|
135
|
+
|
|
136
|
+
### Failure Return Example
|
|
137
|
+
|
|
138
|
+
```json
|
|
139
|
+
{
|
|
140
|
+
"status": "failure",
|
|
141
|
+
"phase": "Phase 3: API Integration",
|
|
142
|
+
"summary": "Failed to implement API routes. Missing dependency '@auth/core' not in package.json.",
|
|
143
|
+
"files_created": [],
|
|
144
|
+
"files_modified": ["src/api/auth.ts"],
|
|
145
|
+
"decisions": [],
|
|
146
|
+
"deviations": [],
|
|
147
|
+
"errors": [
|
|
148
|
+
"Cannot find module '@auth/core' — dependency not installed",
|
|
149
|
+
"Partial implementation in src/api/auth.ts — needs cleanup"
|
|
150
|
+
],
|
|
151
|
+
"patterns_captured": []
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
## Coordinator Processing
|
|
158
|
+
|
|
159
|
+
After receiving the sub-agent's JSON summary, the coordinator:
|
|
160
|
+
|
|
161
|
+
### On Success (`status: "success"`)
|
|
162
|
+
|
|
163
|
+
1. **Update plan file**: Mark all phase tasks as `[x]`
|
|
164
|
+
2. **Accumulate file list**: Merge `files_created` and `files_modified` into running list
|
|
165
|
+
3. **Buffer patterns**: Append `patterns_captured` entries to `flow/resources/pending-patterns.md`
|
|
166
|
+
4. **Git commit**: If `commit: true`, run `git add -A && git commit -m "Phase N: {name} — {feature}"`
|
|
167
|
+
5. **Log decisions**: Include `decisions` in phase completion message
|
|
168
|
+
6. **Proceed**: Move to next phase
|
|
169
|
+
|
|
170
|
+
### On Failure (`status: "failure"`)
|
|
171
|
+
|
|
172
|
+
1. **Present error**: Show `errors` array to user
|
|
173
|
+
2. **Show partial work**: List `files_modified` so user knows what was touched
|
|
174
|
+
3. **Ask user**: "Phase failed. Options: (1) Retry phase, (2) Skip and continue, (3) Stop execution"
|
|
175
|
+
4. **Do NOT auto-retry**: Let user decide
|
|
176
|
+
|
|
177
|
+
### On Partial (`status: "partial"`)
|
|
178
|
+
|
|
179
|
+
1. **Present summary**: Show what was completed and what wasn't
|
|
180
|
+
2. **Show deviations**: List `deviations` explaining what was skipped
|
|
181
|
+
3. **Ask user**: "Phase partially complete. Continue to next phase or retry remaining tasks?"
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
## Aggregated Phases
|
|
186
|
+
|
|
187
|
+
When phases are aggregated (combined complexity ≤ 6), they run as **one sub-agent call** with all tasks from all aggregated phases. The context template lists all phases and tasks together. The return uses the highest phase number as the `phase` field.
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
## Configuration
|
|
192
|
+
|
|
193
|
+
### `.flowconfig` Setting
|
|
194
|
+
|
|
195
|
+
```yaml
|
|
196
|
+
phase_isolation: true # Run phases in isolated sub-agents (default: true)
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
- `true` (default): Each phase runs in an isolated Agent sub-agent
|
|
200
|
+
- `false`: Phases execute inline in the main session (legacy behavior, useful for debugging)
|
|
201
|
+
|
|
202
|
+
### Interaction with Model Routing
|
|
203
|
+
|
|
204
|
+
Phase isolation **enhances** model routing — it doesn't replace it:
|
|
205
|
+
|
|
206
|
+
| Setting | Behavior |
|
|
207
|
+
|---------|----------|
|
|
208
|
+
| `model_routing: true` + `phase_isolation: true` | Sub-agent spawned with correct tier model AND clean context |
|
|
209
|
+
| `model_routing: true` + `phase_isolation: false` | Sub-agent spawned with correct tier model, inherits session context |
|
|
210
|
+
| `model_routing: false` + `phase_isolation: true` | Sub-agent spawned with session model, clean context |
|
|
211
|
+
| `model_routing: false` + `phase_isolation: false` | Inline execution, no sub-agents (original behavior) |
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
## Rules
|
|
216
|
+
|
|
217
|
+
1. **Planning stays in session** — only implementation is isolated
|
|
218
|
+
2. **Under 2K token prompts** — keep context focused, let sub-agent read files
|
|
219
|
+
3. **JSON return only** — no markdown in the return, pure JSON
|
|
220
|
+
4. **Coordinator validates** — check status field before proceeding
|
|
221
|
+
5. **Never auto-retry** — on failure, present to user and ask
|
|
222
|
+
6. **Pass paths, not content** — give file paths, sub-agent reads them
|
|
@@ -13,7 +13,7 @@ During any skill execution, the LLM watches for information that could be valuab
|
|
|
13
13
|
|
|
14
14
|
### During Any Skill Execution
|
|
15
15
|
|
|
16
|
-
While executing any plan-flow skill (`/setup`, `/discovery-plan`, `/create-plan`, `/execute-plan`, `/review-code`, `/review-pr`, `/write-tests`, `/create-contract`, `/
|
|
16
|
+
While executing any plan-flow skill (`/setup`, `/discovery-plan`, `/create-plan`, `/execute-plan`, `/review-code`, `/review-pr`, `/write-tests`, `/create-contract`, `/note`), watch for information that meets the capture criteria below.
|
|
17
17
|
|
|
18
18
|
When you identify something worth preserving:
|
|
19
19
|
|