planflow-ai 1.3.2 → 1.3.5
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/discovery-plan.md +11 -0
- package/.claude/commands/execute-plan.md +26 -2
- package/.claude/commands/flow.md +7 -2
- package/.claude/commands/learn.md +3 -5
- package/.claude/commands/review-code.md +8 -1
- package/.claude/commands/review-pr.md +8 -1
- package/.claude/commands/setup.md +11 -1
- package/.claude/resources/core/_index.md +54 -2
- package/.claude/resources/core/compaction-guide.md +111 -0
- package/.claude/resources/core/discovery-sub-agents.md +266 -0
- package/.claude/resources/core/model-routing.md +6 -2
- package/.claude/resources/core/phase-isolation.md +222 -0
- package/.claude/resources/core/session-scratchpad.md +105 -0
- package/.claude/resources/skills/_index.md +99 -41
- package/.claude/resources/skills/discovery-skill.md +50 -6
- package/.claude/resources/skills/execute-plan-skill.md +15 -7
- package/.claude/rules/core/forbidden-patterns.md +38 -0
- 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/types.d.ts +1 -0
- package/dist/cli/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/templates/shared/CLAUDE.md.template +10 -0
|
@@ -278,6 +278,7 @@ This command uses hierarchical context loading to reduce context consumption. In
|
|
|
278
278
|
| SKL-DIS-1 | Discovery skill workflow | Understanding full process |
|
|
279
279
|
| TLS-IQ-2 | How to switch to Plan mode | Before asking questions |
|
|
280
280
|
| TLS-IQ-3 | How to ask questions | When gathering requirements |
|
|
281
|
+
| COR-CG-1 | Compaction guide | Load when compacting mid-discovery |
|
|
281
282
|
|
|
282
283
|
### Expansion Instructions
|
|
283
284
|
|
|
@@ -389,6 +390,16 @@ Only save if the user approves. Do not re-ask if declined.
|
|
|
389
390
|
|
|
390
391
|
---
|
|
391
392
|
|
|
393
|
+
## Discovery Sub-Agents
|
|
394
|
+
|
|
395
|
+
After reading referenced documents (Step 1), three parallel Agent sub-agents explore the codebase simultaneously: **Similar Features** (finds related existing code), **API/Data Patterns** (maps endpoints and service patterns), and **Schema/Types** (explores type definitions and schemas). All use haiku model.
|
|
396
|
+
|
|
397
|
+
Each sub-agent returns condensed JSON findings (under 2K tokens) that the coordinator merges into a `## Codebase Analysis` section in the discovery document. Findings also inform the clarifying questions in Step 2.
|
|
398
|
+
|
|
399
|
+
Always-on — no configuration needed. See `.claude/resources/core/discovery-sub-agents.md` for full rules.
|
|
400
|
+
|
|
401
|
+
---
|
|
402
|
+
|
|
392
403
|
## Design Awareness
|
|
393
404
|
|
|
394
405
|
During discovery, always ask whether the feature involves UI work. If confirmed, follow the design question flow to capture structured design tokens (colors, typography, spacing, component patterns) into a `## Design Context` section in the discovery document.
|
|
@@ -328,11 +328,25 @@ This command uses hierarchical context loading to reduce context consumption. In
|
|
|
328
328
|
|
|
329
329
|
| Code | Description | When to Expand |
|
|
330
330
|
|------|-------------|----------------|
|
|
331
|
-
| SKL-EXEC-
|
|
332
|
-
| SKL-EXEC-
|
|
331
|
+
| SKL-EXEC-2 | Critical rules (build, DB) | Need build/DB command restrictions |
|
|
332
|
+
| SKL-EXEC-4 | Analyze complexity | Determining execution strategy |
|
|
333
|
+
| SKL-EXEC-6 | Execute phase with Plan mode | Running a specific phase |
|
|
334
|
+
| SKL-EXEC-8 | Phase-boundary compaction | Compacting between phases |
|
|
335
|
+
| SKL-EXEC-9 | Handle tests phase | Executing the tests phase |
|
|
336
|
+
| SKL-EXEC-10 | Build and test verification | Final verification step |
|
|
337
|
+
| SKL-EXEC-11 | Complexity-based behavior | Need low/medium/high behavior details |
|
|
338
|
+
| SKL-EXEC-12 | Error handling | Build/test failure or cancellation |
|
|
333
339
|
| COR-CS-1 | Complexity scoring table | Interpreting phase complexity |
|
|
334
340
|
| TLS-PLN-1 | Plan mode switching | Before each phase |
|
|
335
341
|
| TLS-PLN-2 | Plan mode workflow | Presenting phase details |
|
|
342
|
+
| COR-CG-1 | Compaction guide purpose | When compacting at phase boundaries |
|
|
343
|
+
| COR-CG-2 | Preserve rules | Crafting compact summary — what to keep |
|
|
344
|
+
| COR-CG-3 | Discard rules | Crafting compact summary — what to drop |
|
|
345
|
+
| COR-CG-4 | Compact summary template | Structuring compact instructions |
|
|
346
|
+
| COR-PI-1 | Phase isolation architecture | Understanding isolated sub-agent flow |
|
|
347
|
+
| COR-PI-2 | Sub-agent context template | Preparing focused prompt for sub-agent |
|
|
348
|
+
| COR-PI-3 | Return format schema | Parsing sub-agent JSON response |
|
|
349
|
+
| COR-PI-4 | Coordinator processing rules | Handling success/failure/partial returns |
|
|
336
350
|
|
|
337
351
|
### Expansion Instructions
|
|
338
352
|
|
|
@@ -465,3 +479,13 @@ Routing happens at Step 4 of the execution skill — the phase implementation is
|
|
|
465
479
|
|
|
466
480
|
Disable with `/flow model_routing=false`. See `.claude/resources/core/model-routing.md` for full tier table, platform mappings, and aggregation rules.
|
|
467
481
|
|
|
482
|
+
---
|
|
483
|
+
|
|
484
|
+
## Phase Isolation
|
|
485
|
+
|
|
486
|
+
When `phase_isolation: true` in `flow/.flowconfig` (default), each phase implementation runs in an **isolated Agent sub-agent** with a clean context window. The sub-agent receives only: phase spec, files modified so far, pattern file paths, and design context (if UI phase). It returns a structured JSON summary (1-2K tokens) with status, files changed, decisions, errors, and captured patterns.
|
|
487
|
+
|
|
488
|
+
This eliminates context rot — phase 7 has the same quality as phase 1. Planning/approval stays in the main session; only the implementation step is isolated.
|
|
489
|
+
|
|
490
|
+
Disable with `/flow phase_isolation=false`. See `.claude/resources/core/phase-isolation.md` for the full context template, return format schema, and coordinator processing rules.
|
|
491
|
+
|
package/.claude/commands/flow.md
CHANGED
|
@@ -39,7 +39,8 @@ SETTINGS:
|
|
|
39
39
|
commit=true|false Auto-commit after each completed phase (default: false)
|
|
40
40
|
push=true|false Auto-push after all phases + build/test pass (default: false)
|
|
41
41
|
branch=<name> Target branch for git operations (default: current branch)
|
|
42
|
-
model_routing=true|false Auto-select model per phase based on complexity (default:
|
|
42
|
+
model_routing=true|false Auto-select model per phase based on complexity (default: false)
|
|
43
|
+
phase_isolation=true|false Run each phase in isolated sub-agent with clean context (default: true)
|
|
43
44
|
|
|
44
45
|
COST REPORTING:
|
|
45
46
|
/flow cost Last 7 days summary (default)
|
|
@@ -57,6 +58,7 @@ EXAMPLES:
|
|
|
57
58
|
/flow branch=development # Set target branch
|
|
58
59
|
/flow commit=false push=false # Disable git control
|
|
59
60
|
/flow model_routing=false # Disable model routing (use session model for all phases)
|
|
61
|
+
/flow phase_isolation=false # Disable phase isolation (inline execution, for debugging)
|
|
60
62
|
/flow cost # Show cost report (last 7 days)
|
|
61
63
|
/flow cost --today --detail # Today's costs with model breakdown
|
|
62
64
|
/flow -status # Show current config
|
|
@@ -109,7 +111,8 @@ Parse the user input to determine what action to take:
|
|
|
109
111
|
| `commit` | `true`, `false` | `false` | Auto-commit after each phase |
|
|
110
112
|
| `push` | `true`, `false` | `false` | Auto-push after completion |
|
|
111
113
|
| `branch` | any string | current branch | Target branch for git ops |
|
|
112
|
-
| `model_routing` | `true`, `false` | `
|
|
114
|
+
| `model_routing` | `true`, `false` | `false` | Auto-select model per phase based on complexity |
|
|
115
|
+
| `phase_isolation` | `true`, `false` | `true` | Run each phase in isolated sub-agent with clean context |
|
|
113
116
|
|
|
114
117
|
---
|
|
115
118
|
|
|
@@ -239,6 +242,8 @@ autopilot: false
|
|
|
239
242
|
commit: false
|
|
240
243
|
push: false
|
|
241
244
|
branch: ""
|
|
245
|
+
model_routing: false
|
|
246
|
+
phase_isolation: true
|
|
242
247
|
```
|
|
243
248
|
|
|
244
249
|
**Location**: `flow/.flowconfig`
|
|
@@ -26,11 +26,10 @@ This command has two modes:
|
|
|
26
26
|
| User Input | Mode | What To Do |
|
|
27
27
|
|------------|------|------------|
|
|
28
28
|
| `/learn` (no arguments) | **Pattern Extraction** | Scan session for reusable patterns (Steps 1-4 below) |
|
|
29
|
-
| `/learn
|
|
30
|
-
| `/learn <topic>` (any text after /learn) | **Teaching Mode** | Same as above — treat any argument as a topic to teach |
|
|
29
|
+
| `/learn <topic>` (any text after /learn) | **Teaching Mode** | Create a step-by-step curriculum to TEACH the user about `<topic>` |
|
|
31
30
|
| `/learn -help` | Help | Show help and stop |
|
|
32
31
|
|
|
33
|
-
**Rule**: If the user provides ANY
|
|
32
|
+
**Rule**: If the user provides ANY text after `/learn`, you are in **Teaching Mode**. The ONLY way to trigger Pattern Extraction is `/learn` with no arguments.
|
|
34
33
|
|
|
35
34
|
**Teaching Mode means**: You are a TEACHER. You create a structured curriculum and teach the user step by step. You do NOT extract patterns from the session. You do NOT create `learned-*.md` files. You CREATE a curriculum and TEACH.
|
|
36
35
|
|
|
@@ -49,8 +48,7 @@ DESCRIPTION:
|
|
|
49
48
|
|
|
50
49
|
USAGE:
|
|
51
50
|
/learn Analyze session and suggest patterns to extract
|
|
52
|
-
/learn
|
|
53
|
-
/learn <topic> Same as above — teach me about <topic>
|
|
51
|
+
/learn <topic> Teach me about <topic> step by step
|
|
54
52
|
/learn -help Show this help
|
|
55
53
|
|
|
56
54
|
PATTERN EXTRACTION MODE (/learn):
|
|
@@ -150,7 +150,13 @@ This command uses hierarchical context loading to reduce context consumption. In
|
|
|
150
150
|
|
|
151
151
|
| Code | Description | When to Expand |
|
|
152
152
|
|------|-------------|----------------|
|
|
153
|
-
| SKL-REV-1 |
|
|
153
|
+
| SKL-REV-1 | Purpose and restrictions | Understanding allowed actions |
|
|
154
|
+
| SKL-REV-2 | Identify changed files | Starting the review |
|
|
155
|
+
| SKL-REV-3 | Determine review depth | Adaptive depth selection |
|
|
156
|
+
| SKL-REV-5 | Find similar implementations | Searching for comparable code |
|
|
157
|
+
| SKL-REV-7 | Pattern conflicts + verify + re-rank | Processing findings |
|
|
158
|
+
| SKL-REV-8 | Generate review document | Creating the output file |
|
|
159
|
+
| SKL-REV-9 | Severity and conflict resolution | Severity levels and resolution options |
|
|
154
160
|
| PTN-REV-1 | Review document structure | Creating review output |
|
|
155
161
|
| COR-AP-1 | Allowed patterns overview | Checking pattern compliance |
|
|
156
162
|
| COR-FP-1 | Forbidden patterns overview | Identifying anti-patterns |
|
|
@@ -161,6 +167,7 @@ This command uses hierarchical context loading to reduce context consumption. In
|
|
|
161
167
|
| COR-AD-1 | Adaptive depth size detection | Determining review mode |
|
|
162
168
|
| COR-AD-2 | Lightweight review mode | Changeset < 50 lines |
|
|
163
169
|
| COR-AD-3 | Deep review mode | Changeset 500+ lines |
|
|
170
|
+
| COR-CG-1 | Compaction guide | Load when compacting mid-review |
|
|
164
171
|
|
|
165
172
|
### Expansion Instructions
|
|
166
173
|
|
|
@@ -145,7 +145,14 @@ This command uses hierarchical context loading to reduce context consumption. In
|
|
|
145
145
|
|
|
146
146
|
| Code | Description | When to Expand |
|
|
147
147
|
|------|-------------|----------------|
|
|
148
|
-
| SKL-PR-1 |
|
|
148
|
+
| SKL-PR-1 | Purpose and restrictions | Understanding allowed actions |
|
|
149
|
+
| SKL-PR-2 | Authenticate for PR access | Setting up authentication |
|
|
150
|
+
| SKL-PR-3 | Fetch PR info + determine depth | Getting PR data and review mode |
|
|
151
|
+
| SKL-PR-5 | Analyze + verify + re-rank | Processing findings |
|
|
152
|
+
| SKL-PR-6 | Generate review document | Creating the output file |
|
|
153
|
+
| SKL-PR-7 | Output template | Review document structure |
|
|
154
|
+
| SKL-PR-8 | Fix complexity scoring | Severity and complexity details |
|
|
155
|
+
| SKL-PR-9 | Link format (GitHub/Azure DevOps) | Platform-specific link formats |
|
|
149
156
|
| TLS-AUTH-1 | Auth tool configuration | Setting up authentication |
|
|
150
157
|
| TLS-AUTH-2 | Authentication workflow | Authenticating to platform |
|
|
151
158
|
| PTN-PR-1 | PR review patterns | Creating review output |
|
|
@@ -673,7 +673,17 @@ This command uses hierarchical context loading to reduce context consumption. In
|
|
|
673
673
|
|
|
674
674
|
| Code | Description | When to Expand |
|
|
675
675
|
|------|-------------|----------------|
|
|
676
|
-
| SKL-SETUP-1 |
|
|
676
|
+
| SKL-SETUP-1 | Purpose and critical approach | Understanding setup goals |
|
|
677
|
+
| SKL-SETUP-2 | Scan project structure | Scanning files and directories |
|
|
678
|
+
| SKL-SETUP-3 | Deep dependency analysis | Analyzing package dependencies |
|
|
679
|
+
| SKL-SETUP-4 | Deep code analysis | Sampling files and extracting patterns |
|
|
680
|
+
| SKL-SETUP-7 | Ask confirming questions | Presenting questions via Plan mode |
|
|
681
|
+
| SKL-SETUP-8 | Generate pattern files | Creating framework/library pattern files |
|
|
682
|
+
| SKL-SETUP-9 | Update core pattern files | Updating allowed/forbidden patterns |
|
|
683
|
+
| SKL-SETUP-11 | Create analysis document | Generating project analysis doc |
|
|
684
|
+
| SKL-SETUP-12 | Index documentation | Indexing project docs with reference codes |
|
|
685
|
+
| SKL-SETUP-13 | Create flow folder | Setting up flow/ directory structure |
|
|
686
|
+
| SKL-SETUP-14 | Present summary | Final setup summary output |
|
|
677
687
|
| TLS-IQ-1 | Interactive questions overview | Before asking questions |
|
|
678
688
|
| TLS-IQ-2 | Switch to Plan mode | Starting question session |
|
|
679
689
|
| TLS-IQ-3 | Ask questions format | Asking confirmation questions |
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
|
|
6
6
|
Core rules define the foundational coding standards that apply across the entire project. These include best practices to follow (allowed patterns), anti-patterns to avoid (forbidden patterns), and complexity scoring for implementation planning.
|
|
7
7
|
|
|
8
|
-
**Total Files**:
|
|
9
|
-
**Reference Codes**: COR-AP-1 through COR-
|
|
8
|
+
**Total Files**: 22 files, ~3580 lines
|
|
9
|
+
**Reference Codes**: COR-AP-1 through COR-DSA-3
|
|
10
10
|
|
|
11
11
|
---
|
|
12
12
|
|
|
@@ -143,6 +143,40 @@ Core rules define the foundational coding standards that apply across the entire
|
|
|
143
143
|
| COR-SR-3 | Executive summary trigger and risk level derivation | review-severity-ranking.md | 90-120 |
|
|
144
144
|
| COR-SR-4 | Output structure and insertion points | review-severity-ranking.md | 122-150 |
|
|
145
145
|
|
|
146
|
+
### Compaction Guide (`compaction-guide.md`)
|
|
147
|
+
|
|
148
|
+
| Code | Description | Source | Lines |
|
|
149
|
+
|------|-------------|--------|-------|
|
|
150
|
+
| COR-CG-1 | Purpose, core principle, and when to compact | compaction-guide.md | 3-20 |
|
|
151
|
+
| COR-CG-2 | Preserve rules — what to keep during compaction | compaction-guide.md | 22-38 |
|
|
152
|
+
| COR-CG-3 | Discard rules — what to drop during compaction | compaction-guide.md | 40-55 |
|
|
153
|
+
| COR-CG-4 | Compact summary template and skill-specific examples | compaction-guide.md | 57-110 |
|
|
154
|
+
|
|
155
|
+
### Session Scratchpad (`session-scratchpad.md`)
|
|
156
|
+
|
|
157
|
+
| Code | Description | Source | Lines |
|
|
158
|
+
|------|-------------|--------|-------|
|
|
159
|
+
| COR-SS-1 | Purpose, session start behavior, and write triggers | session-scratchpad.md | 3-45 |
|
|
160
|
+
| COR-SS-2 | File format and 50-line limit | session-scratchpad.md | 47-68 |
|
|
161
|
+
| COR-SS-3 | Promotion rules, targets, and compaction integration | session-scratchpad.md | 70-95 |
|
|
162
|
+
|
|
163
|
+
### Phase Isolation (`phase-isolation.md`)
|
|
164
|
+
|
|
165
|
+
| Code | Description | Source | Lines |
|
|
166
|
+
|------|-------------|--------|-------|
|
|
167
|
+
| COR-PI-1 | Purpose, architecture overview, and coordinator flow | phase-isolation.md | 3-40 |
|
|
168
|
+
| COR-PI-2 | Context template — what to include in sub-agent prompt | phase-isolation.md | 42-85 |
|
|
169
|
+
| COR-PI-3 | Return format schema (JSON), field descriptions, failure example | phase-isolation.md | 87-140 |
|
|
170
|
+
| COR-PI-4 | Coordinator processing (success/failure/partial), config, and rules | phase-isolation.md | 142-180 |
|
|
171
|
+
|
|
172
|
+
### Discovery Sub-Agents (`discovery-sub-agents.md`)
|
|
173
|
+
|
|
174
|
+
| Code | Description | Source | Lines |
|
|
175
|
+
|------|-------------|--------|-------|
|
|
176
|
+
| COR-DSA-1 | Agent definitions with prompt templates (Similar Features, API/Data, Schema/Types) | discovery-sub-agents.md | 30-130 |
|
|
177
|
+
| COR-DSA-2 | Return format schema and Codebase Analysis section template | discovery-sub-agents.md | 132-190 |
|
|
178
|
+
| COR-DSA-3 | Coordinator behavior (spawn, collect, merge, error handling) | discovery-sub-agents.md | 192-240 |
|
|
179
|
+
|
|
146
180
|
### Review Adaptive Depth (`review-adaptive-depth.md`)
|
|
147
181
|
|
|
148
182
|
| Code | Description | Source | Lines |
|
|
@@ -204,10 +238,24 @@ Core rules define the foundational coding standards that apply across the entire
|
|
|
204
238
|
| COR-SR-2 | Need grouping rules for related findings |
|
|
205
239
|
| COR-SR-3 | Need executive summary trigger conditions |
|
|
206
240
|
| COR-SR-4 | Need severity re-ranking output structure or insertion points |
|
|
241
|
+
| COR-CG-1 | Need to understand when and why to compact |
|
|
242
|
+
| COR-CG-2 | Need preserve rules for crafting compact summaries |
|
|
243
|
+
| COR-CG-3 | Need discard rules for dropping low-signal tokens |
|
|
244
|
+
| COR-CG-4 | Need compact summary template or skill-specific examples |
|
|
207
245
|
| COR-AD-1 | Need size detection thresholds or line counting rules |
|
|
208
246
|
| COR-AD-2 | Need lightweight review mode behavior |
|
|
209
247
|
| COR-AD-3 | Need deep review mode behavior (categorization, passes, executive summary) |
|
|
210
248
|
| COR-AD-4 | Need insertion points for adaptive depth in review skills |
|
|
249
|
+
| COR-SS-1 | Need scratchpad purpose, session start behavior, or write triggers |
|
|
250
|
+
| COR-SS-2 | Need scratchpad file format or size limit |
|
|
251
|
+
| COR-SS-3 | Need scratchpad promotion rules or compaction integration |
|
|
252
|
+
| COR-PI-1 | Need phase isolation architecture or coordinator flow |
|
|
253
|
+
| COR-PI-2 | Need sub-agent context template (what to include in prompt) |
|
|
254
|
+
| COR-PI-3 | Need return format schema or field descriptions |
|
|
255
|
+
| COR-PI-4 | Need coordinator processing rules or config settings |
|
|
256
|
+
| COR-DSA-1 | Need discovery sub-agent definitions or prompt templates |
|
|
257
|
+
| COR-DSA-2 | Need return format schema or Codebase Analysis section template |
|
|
258
|
+
| COR-DSA-3 | Need coordinator spawn/collect/merge behavior or error handling |
|
|
211
259
|
|
|
212
260
|
---
|
|
213
261
|
|
|
@@ -248,5 +296,9 @@ Core rules define the foundational coding standards that apply across the entire
|
|
|
248
296
|
- `pattern-capture.md` is loaded on-demand - silently captures patterns during skill execution and presents for approval
|
|
249
297
|
- `model-routing.md` is loaded on-demand - automatic model selection per phase based on complexity scores during `/execute-plan`
|
|
250
298
|
- `project-tasklist.md` is loaded on-demand - session start tasklist behavior
|
|
299
|
+
- `compaction-guide.md` is loaded on-demand - preserve/discard rules and summary template for `/compact`
|
|
300
|
+
- `session-scratchpad.md` is loaded on-demand - ephemeral per-session notes with promotion to permanent storage
|
|
301
|
+
- `phase-isolation.md` is loaded on-demand - isolated sub-agent execution per phase during `/execute-plan`
|
|
251
302
|
- `project-memory.md` is loaded on-demand - artifact tracking and 7-day session loading
|
|
252
303
|
- `heartbeat.md` is loaded on-demand - scheduled task daemon configuration
|
|
304
|
+
- `discovery-sub-agents.md` is loaded on-demand - parallel codebase exploration sub-agents during `/discovery-plan`
|
|
@@ -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 |
|