buildflow-dev 4.0.1 → 4.0.2
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 +17 -13
- package/package.json +1 -1
- package/templates/commands/build.md +221 -61
- package/templates/commands/hotfix.md +28 -3
- package/templates/commands/modify.md +212 -38
- package/templates/commands/onboard.md +246 -52
- package/templates/commands/plan.md +182 -56
- package/templates/commands/spec.md +178 -74
- package/templates/commands/think.md +186 -38
|
@@ -1,65 +1,239 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: buildflow-modify
|
|
3
|
-
description:
|
|
3
|
+
description: Surgical code change with transitive impact analysis, risk scoring, and test coverage verification
|
|
4
4
|
allowed-tools: Read, Write, Grep, Glob, Bash
|
|
5
5
|
agent: surgeon
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
# /buildflow-modify
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
Precise, safe changes to existing code. The Surgeon runs a full transitive impact analysis — not just "what files change" but the full chain of consequences — scores risk per affected file, verifies test coverage, and applies the minimum effective change.
|
|
11
|
+
|
|
12
|
+
Works for features and bugfixes equally.
|
|
11
13
|
|
|
12
14
|
## Usage
|
|
13
|
-
- `/buildflow-modify "Add
|
|
14
|
-
- `/buildflow-modify
|
|
15
|
+
- `/buildflow-modify "Add rate limiting to /api/auth/login"`
|
|
16
|
+
- `/buildflow-modify "Fix null pointer crash when user has no profile photo"`
|
|
17
|
+
- `/buildflow-modify src/auth/login.ts "Add input validation"`
|
|
15
18
|
- `/buildflow-modify --dry-run "Rename getUserById to fetchUserById"`
|
|
16
19
|
|
|
17
|
-
##
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
## Context Packet
|
|
21
|
+
- `.buildflow/codebase/MAP.md`
|
|
22
|
+
- `.buildflow/codebase/GRAPH.md` (import dependency graph — essential for impact analysis)
|
|
23
|
+
- `.buildflow/codebase/HOTSPOTS.md`
|
|
24
|
+
- `.buildflow/codebase/PATTERNS.md`
|
|
25
|
+
- Target file(s) if named in command
|
|
26
|
+
|
|
27
|
+
If not onboarded: "Run `/buildflow-onboard` first — impact analysis requires the dependency graph."
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Step 1: Understand the Change
|
|
32
|
+
Parse the description. Identify:
|
|
33
|
+
- **What** must change (behavior, data, interface)
|
|
34
|
+
- **Where** the change originates (file, function, module)
|
|
35
|
+
- **What must NOT change** (caller contracts, existing behavior outside scope)
|
|
36
|
+
- Is this a feature (new capability) or a bugfix (restoring expected behavior)?
|
|
37
|
+
|
|
38
|
+
If ambiguous: ask ONE clarifying question only.
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## Step 2: Transitive Impact Analysis
|
|
43
|
+
Using `GRAPH.md`, trace the full impact chain from the target file outward:
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
Level 0 — Direct change:
|
|
47
|
+
src/auth/login.ts ← file being modified
|
|
48
|
+
|
|
49
|
+
Level 1 — Direct dependents (imports Level 0):
|
|
50
|
+
src/routes/auth.routes.ts fan-in to login.ts
|
|
51
|
+
src/tests/auth.test.ts fan-in to login.ts
|
|
52
|
+
|
|
53
|
+
Level 2 — Transitive dependents (imports Level 1):
|
|
54
|
+
src/app.ts imports auth.routes.ts
|
|
55
|
+
src/middleware/session.ts imports auth.routes.ts
|
|
56
|
+
|
|
57
|
+
Level 3 — Entry point:
|
|
58
|
+
main.ts imports app.ts
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
For each affected file, annotate:
|
|
62
|
+
- **Risk score** (from HOTSPOTS.md, or calculate: fan-in + size + test coverage)
|
|
63
|
+
- **Test coverage**: does a test file cover this file?
|
|
64
|
+
- **Contract sensitivity**: does this file export a public API? If yes, callers may break.
|
|
65
|
+
- **Module boundary**: does this change cross a module boundary?
|
|
66
|
+
|
|
67
|
+
**Impact Summary:**
|
|
68
|
+
```
|
|
69
|
+
Impact Analysis: "Add rate limiting to /api/auth/login"
|
|
70
|
+
────────────────────────────────────────────────────────
|
|
71
|
+
Direct:
|
|
72
|
+
src/auth/login.ts risk: 4.2 tests: YES contract: INTERNAL
|
|
73
|
+
|
|
74
|
+
Level 1 — will be affected:
|
|
75
|
+
src/routes/auth.routes.ts risk: 3.1 tests: YES contract: PUBLIC ← caller may need update
|
|
76
|
+
src/tests/auth.test.ts risk: 1.0 tests: N/A contract: NONE ← will need new test case
|
|
77
|
+
|
|
78
|
+
Level 2 — may be affected:
|
|
79
|
+
src/app.ts risk: 3.8 tests: partial contract: ENTRY
|
|
80
|
+
src/middleware/session.ts risk: 2.5 tests: YES contract: INTERNAL ← verify no conflict
|
|
81
|
+
|
|
82
|
+
Blast radius: 4 files modified, 1 file needing new test, 0 public API breaks expected
|
|
83
|
+
Highest risk file touched: src/auth/login.ts (4.2)
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
If any Level 2+ file has risk ≥ 4.0: flag as "Caution — high-risk transitive impact. Consider splitting this change."
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## Step 3: API Contract Check
|
|
91
|
+
If the change modifies a function/method signature or REST endpoint:
|
|
92
|
+
|
|
93
|
+
**Before (current contract):**
|
|
94
|
+
```
|
|
95
|
+
loginUser(email: string, password: string): Promise<AuthToken>
|
|
96
|
+
POST /api/auth/login → { token: string, expiresAt: number }
|
|
97
|
+
```
|
|
20
98
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
4. Confidence in understanding the request (1-5)?
|
|
99
|
+
**After (new contract):**
|
|
100
|
+
```
|
|
101
|
+
loginUser(email: string, password: string, options?: RateLimitOptions): Promise<AuthToken>
|
|
102
|
+
POST /api/auth/login → { token: string, expiresAt: number } [+ 429 Too Many Requests]
|
|
103
|
+
```
|
|
27
104
|
|
|
28
|
-
|
|
29
|
-
Before touching any code:
|
|
30
|
-
- List all files that will be modified
|
|
31
|
-
- List all files that call or import changed code
|
|
32
|
-
- Identify test files that cover this area
|
|
33
|
-
- Flag any security-sensitive areas
|
|
105
|
+
List all callers that pass through this contract and verify they still compile/run with the new signature. If any caller will break: add fixing those callers to the task list.
|
|
34
106
|
|
|
35
|
-
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## Step 4: Test Coverage Map
|
|
110
|
+
For each file in the impact chain, verify:
|
|
111
|
+
- Does a test file exist that imports or calls it?
|
|
112
|
+
- Do those tests cover the behavior being changed?
|
|
113
|
+
- After the change, which tests will need updating?
|
|
114
|
+
|
|
115
|
+
```
|
|
116
|
+
Test Coverage for this change:
|
|
117
|
+
login.ts → src/tests/auth.test.ts (covers: login flow, invalid password)
|
|
118
|
+
MISSING: rate limit behavior — must add
|
|
119
|
+
auth.routes.ts → src/tests/routes.test.ts (covers: route registration)
|
|
120
|
+
OK: no change needed
|
|
121
|
+
session.ts → NO TESTS FOUND ← flag: untested file in impact chain
|
|
122
|
+
```
|
|
36
123
|
|
|
37
|
-
|
|
124
|
+
Flag any untested file in the impact chain as a risk.
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
## Step 5: Confirmation
|
|
129
|
+
Show the impact summary, contract change, and test coverage map. Ask:
|
|
130
|
+
|
|
131
|
+
> "This change touches [N] files with blast radius [N]. Highest-risk: [file] ([score]).
|
|
132
|
+
> Proceed, narrow scope, or investigate further?"
|
|
133
|
+
|
|
134
|
+
Only proceed on explicit confirmation.
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## Step 6: Restore Point
|
|
38
139
|
```bash
|
|
39
|
-
git stash
|
|
40
|
-
#
|
|
140
|
+
git stash push -m "pre-modify: [description]"
|
|
141
|
+
# or if nothing to stash:
|
|
142
|
+
git tag "pre-modify-$(date +%Y%m%d-%H%M)"
|
|
41
143
|
```
|
|
42
144
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
-
|
|
48
|
-
-
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## Step 7: Surgical Implementation
|
|
148
|
+
Make the minimum effective change:
|
|
149
|
+
- Change only what the impact analysis identified
|
|
150
|
+
- Follow existing code style (PATTERNS.md)
|
|
151
|
+
- Add `LEARN:` comment ONLY if introducing a pattern not present elsewhere
|
|
152
|
+
- Do NOT refactor, rename, or clean up surrounding code
|
|
153
|
+
|
|
154
|
+
For each file modified: confirm it matches the Before → After contract.
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
## Step 7b: Write / Update Tests (mandatory — part of the change, not optional)
|
|
49
159
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
160
|
+
### First: detect test framework (if not already known from onboarding)
|
|
161
|
+
```bash
|
|
162
|
+
# JS/TS
|
|
163
|
+
cat package.json | grep -E "jest|vitest|mocha|jasmine|supertest"
|
|
164
|
+
ls jest.config.* vitest.config.* 2>/dev/null
|
|
165
|
+
find . -name "*.test.ts" -o -name "*.spec.ts" | head -3
|
|
166
|
+
|
|
167
|
+
# Python
|
|
168
|
+
cat requirements.txt pyproject.toml 2>/dev/null | grep pytest
|
|
169
|
+
|
|
170
|
+
# Go: look for *_test.go files
|
|
171
|
+
# Rust: look for #[cfg(test)] blocks
|
|
172
|
+
```
|
|
54
173
|
|
|
55
|
-
|
|
174
|
+
| Framework status | Action |
|
|
175
|
+
|-----------------|--------|
|
|
176
|
+
| Found + test files exist | Follow existing conventions exactly |
|
|
177
|
+
| Found + no test files yet | Use framework, create first test file |
|
|
178
|
+
| Not found | Warn user: "No test framework detected. Tests skipped. Add [recommended framework] and re-run." Log gap to `security/DEBT.md`. |
|
|
179
|
+
|
|
180
|
+
For each source file touched in Step 7:
|
|
181
|
+
|
|
182
|
+
**If a test file already exists for this file:**
|
|
183
|
+
- Open it
|
|
184
|
+
- Add test cases for every function whose behavior changed
|
|
185
|
+
- If the function's signature changed: update the callers in the test
|
|
186
|
+
- If the bug was in a specific code path: add a regression test that names the exact scenario
|
|
187
|
+
|
|
188
|
+
**If no test file exists:**
|
|
189
|
+
- Create one following the project test convention (from PATTERNS.md):
|
|
190
|
+
- Co-located: `auth.service.ts` → `auth.service.test.ts`
|
|
191
|
+
- Or in test folder: match existing structure
|
|
192
|
+
- Cover: each function touched in this change + the specific behavior the change introduces
|
|
193
|
+
|
|
194
|
+
**For bugfixes specifically:**
|
|
195
|
+
1. Write the regression test BEFORE applying the fix
|
|
196
|
+
2. Run it — confirm it fails (proves the bug exists)
|
|
197
|
+
3. Apply the fix
|
|
198
|
+
4. Run again — confirm it passes (proves the fix works)
|
|
199
|
+
5. Name the test after the exact bug: `should not return null when profile photo is missing`
|
|
200
|
+
|
|
201
|
+
**Test coverage report after this step:**
|
|
202
|
+
```
|
|
203
|
+
Test changes for this modify
|
|
204
|
+
─────────────────────────────
|
|
205
|
+
auth.service.ts → auth.service.test.ts +3 cases (rate limit happy path, 429 response, reset after window)
|
|
206
|
+
auth.routes.ts → auth.routes.test.ts +1 case (rate limit header present)
|
|
207
|
+
session.ts → session.test.ts CREATED — 4 cases (was untested, now covered)
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
Do not proceed to Step 8 until every touched source file has corresponding test coverage.
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
## Step 8: Test + Verify
|
|
215
|
+
Run full test suite. On failure: fix and retest (max 3 attempts).
|
|
216
|
+
|
|
217
|
+
Also verify:
|
|
218
|
+
- All files in the impact chain still compile
|
|
219
|
+
- Callers of changed contracts still function
|
|
220
|
+
- The regression test (for bugfixes) now passes
|
|
221
|
+
- No previously passing tests were broken
|
|
222
|
+
|
|
223
|
+
---
|
|
224
|
+
|
|
225
|
+
## Step 9: Update Memory
|
|
56
226
|
```yaml
|
|
57
227
|
last_modify: [today]
|
|
58
|
-
change: [
|
|
59
|
-
files_changed: [
|
|
228
|
+
change: [description]
|
|
229
|
+
files_changed: [N]
|
|
230
|
+
impact_level: [direct/level1/level2]
|
|
60
231
|
```
|
|
61
232
|
|
|
233
|
+
---
|
|
234
|
+
|
|
62
235
|
## --dry-run Flag
|
|
63
|
-
Shows
|
|
236
|
+
Runs Steps 1–5 only. Shows full impact analysis and contract changes without modifying any file.
|
|
237
|
+
Use this before a risky change to understand blast radius first.
|
|
64
238
|
|
|
65
|
-
## Token Budget: ~30K
|
|
239
|
+
## Token Budget: ~30K (more if impact chain is deep)
|
|
@@ -1,78 +1,272 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: buildflow-onboard
|
|
3
|
-
description:
|
|
3
|
+
description: Deep codebase analysis — import graph, module boundaries, load-bearing files, risk scores
|
|
4
4
|
allowed-tools: Read, Bash, Glob, Grep
|
|
5
5
|
agent: cartographer
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
# /buildflow-onboard
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
Deep one-time analysis of an existing codebase. Goes beyond folder structure — maps import graphs, identifies load-bearing modules, scores file risk, and establishes module boundaries. All other agents reference these outputs.
|
|
11
11
|
|
|
12
12
|
## When to Run
|
|
13
|
-
- First time using BuildFlow on existing project
|
|
14
|
-
- After major refactor
|
|
15
|
-
-
|
|
16
|
-
- Use --update flag to refresh incrementally
|
|
13
|
+
- First time using BuildFlow on an existing project
|
|
14
|
+
- After a major refactor or framework migration
|
|
15
|
+
- `--update` flag for incremental refresh after significant changes
|
|
17
16
|
|
|
18
|
-
##
|
|
19
|
-
|
|
17
|
+
## Usage
|
|
18
|
+
- `/buildflow-onboard` — full analysis
|
|
19
|
+
- `/buildflow-onboard --update` — refresh changed files only
|
|
20
|
+
- `/buildflow-onboard --depth imports` — focus on dependency graph only
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Step 1: Prior State Check
|
|
25
|
+
If `.buildflow/codebase/MAP.md` exists:
|
|
26
|
+
- `--update` flag: skip to Step 6 (incremental refresh)
|
|
27
|
+
- Otherwise ask: "Full re-onboard or incremental update?"
|
|
28
|
+
|
|
29
|
+
---
|
|
20
30
|
|
|
21
31
|
## Step 2: Structural Analysis
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
-
|
|
31
|
-
-
|
|
32
|
-
-
|
|
33
|
-
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
-
|
|
40
|
-
-
|
|
41
|
-
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
32
|
+
```bash
|
|
33
|
+
# Entry points
|
|
34
|
+
find . -name "main.*" -o -name "index.*" -o -name "app.*" | grep -v node_modules
|
|
35
|
+
# File count by type
|
|
36
|
+
find src/ -type f | sed 's/.*\.//' | sort | uniq -c | sort -rn
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Map:
|
|
40
|
+
- Entry points (where execution begins)
|
|
41
|
+
- Top-level folder responsibilities (what each `src/` subdirectory owns)
|
|
42
|
+
- Configuration files and what they control
|
|
43
|
+
- Build/bundler setup
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Step 3: Technology & Dependency Detection
|
|
48
|
+
Parse `package.json` / `requirements.txt` / `Cargo.toml` / `go.mod`. For each major dependency:
|
|
49
|
+
- Purpose (what problem it solves)
|
|
50
|
+
- Criticality: CORE (app breaks without) / UTIL (convenience) / DEV (build-time only)
|
|
51
|
+
- Security status: check for known CVE patterns in version
|
|
52
|
+
|
|
53
|
+
### Test Framework Detection (captured here so all agents can reuse it)
|
|
54
|
+
```bash
|
|
55
|
+
# JS/TS — check deps and config
|
|
56
|
+
cat package.json | grep -E "jest|vitest|mocha|jasmine|@testing-library|supertest|cypress|playwright"
|
|
57
|
+
ls jest.config.* vitest.config.* .mocharc.* 2>/dev/null
|
|
58
|
+
find . -name "*.test.ts" -o -name "*.test.js" -o -name "*.spec.ts" -o -name "*.spec.js" | head -5
|
|
59
|
+
find . -type d -name "__tests__" | head -3
|
|
60
|
+
|
|
61
|
+
# Python
|
|
62
|
+
cat requirements.txt pyproject.toml setup.cfg 2>/dev/null | grep -E "pytest|unittest|nose"
|
|
63
|
+
find . -name "test_*.py" -o -name "*_test.py" | head -5
|
|
64
|
+
|
|
65
|
+
# Go — test files use same package
|
|
66
|
+
find . -name "*_test.go" | head -5
|
|
67
|
+
|
|
68
|
+
# Rust — tests are inline
|
|
69
|
+
grep -rn "#\[cfg(test)\]" src/ | head -5
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Record the **Test Profile** in `PATTERNS.md` under a `## Testing` section:
|
|
73
|
+
```
|
|
74
|
+
Framework: [Jest / Vitest / pytest / go test / cargo test / NONE]
|
|
75
|
+
Config: [jest.config.ts / vitest.config.ts / pytest.ini / N/A]
|
|
76
|
+
Test location: [co-located *.test.ts / __tests__/ / tests/ / inline]
|
|
77
|
+
Naming: [describe/it / test() / def test_ / #[test]]
|
|
78
|
+
Mock library: [jest.mock / vi.mock / pytest fixtures / mockall / NONE]
|
|
79
|
+
Coverage: [jest --coverage / pytest-cov / go test -cover / NONE]
|
|
80
|
+
Existing tests:[N files, N cases]
|
|
81
|
+
Has tests: [YES / NO — no framework detected]
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
If `Has tests: NO`: note in summary — "⚠ No test framework found. Tests cannot be written until one is installed."
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## Step 4: Import Graph Analysis (repo awareness core)
|
|
89
|
+
For each source file, trace its imports and exports:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
# JS/TS: find all import statements
|
|
93
|
+
grep -rn "^import\|^const.*require" src/ --include="*.ts" --include="*.js"
|
|
94
|
+
# Python
|
|
95
|
+
grep -rn "^import\|^from" src/ --include="*.py"
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Build a dependency map:
|
|
99
|
+
```
|
|
100
|
+
file-a.ts imports [auth.service.ts, db.client.ts, types.ts]
|
|
101
|
+
auth.service.ts imports [db.client.ts, crypto.ts, config.ts]
|
|
102
|
+
db.client.ts imports [config.ts]
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
From this graph, calculate for each file:
|
|
106
|
+
- **Fan-in** (how many files import THIS file) — high = load-bearing
|
|
107
|
+
- **Fan-out** (how many files THIS file imports) — high = coupled
|
|
108
|
+
- **Depth** (longest import chain to reach this file from entry point)
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## Step 5: Load-Bearing Module Identification
|
|
113
|
+
Files with fan-in ≥ 5 are **load-bearing** — changes ripple widely.
|
|
114
|
+
|
|
115
|
+
```
|
|
116
|
+
Load-Bearing Modules
|
|
117
|
+
────────────────────
|
|
118
|
+
db.client.ts fan-in: 12 ← CRITICAL — 12 files depend on this
|
|
119
|
+
auth.service.ts fan-in: 8 ← HIGH
|
|
120
|
+
config.ts fan-in: 15 ← CRITICAL
|
|
121
|
+
types.ts fan-in: 20 ← CRITICAL (type-only, lower risk)
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## Step 6: Module Boundary Mapping
|
|
127
|
+
Identify **bounded contexts** — groups of files that form a logical subsystem:
|
|
128
|
+
|
|
129
|
+
```
|
|
130
|
+
Module: Auth
|
|
131
|
+
Owns: src/auth/*.ts
|
|
132
|
+
Exports: AuthService, AuthMiddleware, JWTUtil
|
|
133
|
+
Depends on: Database, Config
|
|
134
|
+
Depended on by: API routes, WebSocket handlers
|
|
135
|
+
|
|
136
|
+
Module: Database
|
|
137
|
+
Owns: src/db/*.ts
|
|
138
|
+
Exports: DBClient, QueryBuilder, Migrations
|
|
139
|
+
Depends on: Config
|
|
140
|
+
Depended on by: Auth, Users, Orders (everything)
|
|
141
|
+
|
|
142
|
+
Module: API
|
|
143
|
+
Owns: src/routes/*.ts
|
|
144
|
+
Exports: Router
|
|
145
|
+
Depends on: Auth, Users, Orders
|
|
146
|
+
Depended on by: main.ts (entry point only)
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Flag **boundary violations**: files that import across module lines without going through the module's public export.
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## Step 7: Pattern Recognition
|
|
154
|
+
Read 2–3 representative files per module. Document:
|
|
155
|
+
- Component/class structure conventions
|
|
156
|
+
- Naming patterns (PascalCase, camelCase, snake_case, kebab-case)
|
|
157
|
+
- Import organization order (stdlib → 3rd party → internal)
|
|
158
|
+
- Error handling approach (throw vs return, error types used)
|
|
159
|
+
- Async pattern (async/await, Promise chains, callbacks)
|
|
160
|
+
- Test file conventions (co-located vs `__tests__/`, naming)
|
|
161
|
+
- Comment style (JSDoc, inline, none)
|
|
162
|
+
|
|
163
|
+
---
|
|
164
|
+
|
|
165
|
+
## Step 8: Risk Scoring
|
|
166
|
+
Score each file on a 1–5 risk scale:
|
|
167
|
+
|
|
168
|
+
| Factor | Low (1) | High (5) |
|
|
169
|
+
|--------|---------|---------|
|
|
170
|
+
| Fan-in | 0–1 dependents | 10+ dependents |
|
|
171
|
+
| File size | < 100 lines | > 500 lines |
|
|
172
|
+
| Test coverage | Tests exist | No tests found |
|
|
173
|
+
| Complexity | Simple logic | Deep nesting, many branches |
|
|
174
|
+
| Change frequency | Rarely changed | Frequently changed |
|
|
175
|
+
|
|
176
|
+
Final risk score = average of applicable factors.
|
|
177
|
+
|
|
178
|
+
```
|
|
179
|
+
File Risk Map
|
|
180
|
+
─────────────
|
|
181
|
+
db.client.ts risk: 4.8 ← touch with extreme care
|
|
182
|
+
auth.service.ts risk: 4.2 ← high-impact changes
|
|
183
|
+
config.ts risk: 4.0 ← high fan-in, usually stable
|
|
184
|
+
UserController.ts risk: 2.1 ← isolated, well-tested
|
|
185
|
+
utils/format.ts risk: 1.0 ← pure functions, low coupling
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
---
|
|
189
|
+
|
|
190
|
+
## Step 9: Write Knowledge Files
|
|
53
191
|
|
|
54
192
|
### `.buildflow/codebase/MAP.md`
|
|
55
|
-
|
|
193
|
+
```markdown
|
|
194
|
+
# Codebase Map
|
|
195
|
+
**Project:** [name] **Onboarded:** [date] **Files analyzed:** [N]
|
|
196
|
+
|
|
197
|
+
## Entry Points
|
|
198
|
+
- [file]: [purpose]
|
|
199
|
+
|
|
200
|
+
## Module Boundaries
|
|
201
|
+
[module table from Step 6]
|
|
202
|
+
|
|
203
|
+
## Load-Bearing Modules
|
|
204
|
+
[critical file list from Step 5]
|
|
205
|
+
|
|
206
|
+
## Folder Structure
|
|
207
|
+
[annotated tree — one line per folder explaining its role]
|
|
208
|
+
|
|
209
|
+
## Key Patterns
|
|
210
|
+
- [pattern name]: [brief description]
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### `.buildflow/codebase/GRAPH.md`
|
|
214
|
+
Full import dependency graph output from Step 4.
|
|
215
|
+
Includes fan-in / fan-out counts per file.
|
|
216
|
+
This is what impact analysis reads during `/buildflow-modify`.
|
|
56
217
|
|
|
57
218
|
### `.buildflow/codebase/PATTERNS.md`
|
|
58
|
-
|
|
219
|
+
All conventions from Step 7. Used by Builder and Surgeon agents to match style.
|
|
220
|
+
Each pattern has an example extracted from the actual codebase.
|
|
59
221
|
|
|
60
222
|
### `.buildflow/codebase/DEPENDENCIES.md`
|
|
61
|
-
|
|
223
|
+
All dependencies from Step 3 with purpose, criticality, and security status.
|
|
62
224
|
|
|
63
225
|
### `.buildflow/codebase/HOTSPOTS.md`
|
|
64
|
-
|
|
226
|
+
```markdown
|
|
227
|
+
# Hotspots — Handle With Care
|
|
228
|
+
Files scored 3.5+ risk. Review before any modification.
|
|
229
|
+
|
|
230
|
+
| File | Risk | Fan-in | Size | Tests | Notes |
|
|
231
|
+
|------|------|--------|------|-------|-------|
|
|
232
|
+
| db.client.ts | 4.8 | 12 | 380L | partial | Central DB abstraction |
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
---
|
|
65
236
|
|
|
66
|
-
## Step
|
|
237
|
+
## Step 10: Update Memory
|
|
67
238
|
```yaml
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
239
|
+
onboarded: true
|
|
240
|
+
onboarded_date: [today]
|
|
241
|
+
file_count: [N]
|
|
242
|
+
module_count: [N]
|
|
243
|
+
load_bearing_files: [N]
|
|
244
|
+
hotspot_count: [N]
|
|
245
|
+
codebase_summary: [2-line summary]
|
|
72
246
|
```
|
|
73
247
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
248
|
+
---
|
|
249
|
+
|
|
250
|
+
## Step 11: Onboarding Summary
|
|
251
|
+
Report:
|
|
252
|
+
```
|
|
253
|
+
Onboarding Complete
|
|
254
|
+
───────────────────
|
|
255
|
+
Files analyzed: [N]
|
|
256
|
+
Modules identified: [N]
|
|
257
|
+
Load-bearing files: [N] (fan-in ≥ 5)
|
|
258
|
+
High-risk hotspots: [N] (risk score ≥ 3.5)
|
|
259
|
+
Boundary violations: [N] (files importing across module lines)
|
|
260
|
+
Test coverage est.: [N]% (files with co-located tests)
|
|
261
|
+
Patterns captured: [N]
|
|
262
|
+
|
|
263
|
+
⚠ Caution zones: [top 3 highest-risk files]
|
|
264
|
+
✓ Safe to modify: [modules with low risk scores]
|
|
265
|
+
|
|
266
|
+
Next steps:
|
|
267
|
+
/buildflow-modify — make targeted changes
|
|
268
|
+
/buildflow-spec — define a new phase
|
|
269
|
+
/buildflow-refactor — improve code quality
|
|
270
|
+
```
|
|
77
271
|
|
|
78
|
-
## Token Budget:
|
|
272
|
+
## Token Budget: ~40K (one-time — pays back on every subsequent session)
|