know-thy-build 0.7.1 → 0.9.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "know-thy-build",
3
- "version": "0.7.1",
3
+ "version": "0.9.0",
4
4
  "description": "Multi-agent project definition & QA framework for Claude Code — Socratic dialogue, behavioral testing axes, design intent, orchestrated review",
5
5
  "bin": {
6
6
  "know-thy-build": "./bin/cli.js"
@@ -375,6 +375,8 @@ gate:
375
375
  architect: pending
376
376
  designer: pending # set to 'skipped' for non-UI features
377
377
  qa: pending
378
+ integration: pending # set by finish — auto-passed if no conflicts
379
+ ci: pending # set by finish — runs project test command
378
380
  assumptions:
379
381
  - "{{assumption}}"
380
382
  date: {{date}}
@@ -384,10 +386,12 @@ generatedBy: know-thy-build-feature
384
386
 
385
387
  **Gate initialization rules:**
386
388
  - **Spike**: No gate field. Spikes produce answers, not implementations.
387
- - **Bounded (non-UI)**: `architect: pending`, `designer: skipped`, `qa: pending`
388
- - **Bounded (UI)**: `architect: pending`, `designer: pending`, `qa: pending`
389
+ - **Bounded (non-UI)**: `architect: pending`, `designer: skipped`, `qa: pending`, `integration: pending`, `ci: pending`
390
+ - **Bounded (UI)**: `architect: pending`, `designer: pending`, `qa: pending`, `integration: pending`, `ci: pending`
389
391
  - **Architectural**: All `pending`
390
392
 
393
+ `integration` and `ci` gates are always initialized as `pending`. They are set by `/know-thy-build:finish` during the merge pipeline — never manually.
394
+
391
395
  **Priority guide:**
392
396
  - **P0**: Must-have for MVP. Without this, the project doesn't deliver its core value.
393
397
  - **P1**: Important. Significantly improves the experience but the project works without it.
@@ -1,19 +1,19 @@
1
1
  ---
2
2
  description: Merge a completed feature — checks all review gates, squash merges to main, cleans up worktree. The final step in the feature lifecycle.
3
- allowed-tools: [Read, Write, Edit, Glob, Grep, Bash, AskUserQuestion]
3
+ allowed-tools: [Read, Write, Edit, Glob, Grep, Bash, Agent, AskUserQuestion]
4
4
  ---
5
5
 
6
6
  # Know Thy Build — Finish
7
7
 
8
- You are the **release gate**. Your job is to verify that all review gates have passed, then merge the feature to main and clean up.
8
+ You are the **release gate**. Your job is to verify that all review gates have passed, rebase on main, handle conflicts, run CI, and then merge.
9
9
 
10
- You do NOT implement, review, or test. You only verify the gate and execute the merge.
10
+ You do NOT implement features. You verify, resolve, review, and merge.
11
11
 
12
12
  ## Language
13
13
 
14
14
  **All conversation and output MUST be in: {{LANG}}**
15
15
 
16
- Technical terms (e.g. merge, squash, worktree, gate) stay in English. Everything else uses the specified language.
16
+ Technical terms (e.g. merge, squash, worktree, gate, rebase, conflict) stay in English. Everything else uses the specified language.
17
17
 
18
18
  ---
19
19
 
@@ -40,41 +40,65 @@ FEATURE_FILE="docs/features/$(printf '%03d' $FEATURE_NUM).md"
40
40
 
41
41
  Read the feature spec and extract the gate section from frontmatter.
42
42
 
43
+ ### 3. Read project operations
44
+
45
+ ```bash
46
+ # Check for project-specific merge/deploy/test requirements
47
+ grep -A 30 '## Operations' docs/PROJECT.md 2>/dev/null
48
+ ```
49
+
50
+ Extract:
51
+ - **Test command** from CI/CD table (REQUIRED for ci gate)
52
+ - **Merge strategy** (default: squash)
53
+ - **Additional gates** (informational)
54
+
55
+ If no test command is defined in Operations:
56
+ > "⚠️ No test command found in docs/PROJECT.md → Operations → CI/CD. The `ci` gate will auto-pass. Consider defining a test command to catch regressions."
57
+
43
58
  ---
44
59
 
45
- ## Gate Check
60
+ ## Phase 1: Review Gate Check
46
61
 
47
62
  Read the `gate:` section from the feature spec's YAML frontmatter.
48
63
 
49
64
  ### Display gate status
50
65
 
51
- Present a clear gate status report:
52
-
53
66
  ```
54
- 🚦 Gate Check — Feature {{NNN}}: {{title}}
67
+ 🚦 Review Gate Check — Feature {{NNN}}: {{title}}
55
68
 
56
- Architect: {{status}} {{date if passed}}
57
- Designer: {{status}} {{date if passed}}
58
- QA: {{status}} {{date if passed}}
69
+ Architect: {{status}} {{date if passed}}
70
+ Designer: {{status}} {{date if passed}}
71
+ QA: {{status}} {{date if passed}}
72
+ Integration: pending (set by this pipeline)
73
+ CI: pending (set by this pipeline)
59
74
  ```
60
75
 
61
- ### Evaluate
76
+ ### Evaluate review gates
62
77
 
63
- **All gates `passed` or `skipped`:**
64
- > "All gates passed. Ready to merge."
65
- → Proceed to Pre-merge Verification.
78
+ Check only `architect`, `designer`, and `qa` at this stage. `integration` and `ci` are set by THIS pipeline — they are expected to be `pending`.
66
79
 
67
- **Any gate is `pending`:**
80
+ **All review gates `passed` or `skipped`:**
81
+ > "Review gates passed. Starting merge pipeline."
82
+ → Proceed to Phase 2.
83
+
84
+ **Any review gate is `pending`:**
68
85
  > "Cannot merge — pending reviews:"
69
86
  > - `{{role}}`: pending — run `/know-thy-build:{{role}}` to complete
70
87
 
71
- → Stop here. Do NOT proceed with merge.
88
+ → Stop here. Do NOT proceed.
72
89
 
73
- ---
90
+ ### Project-specific gates (informational)
74
91
 
75
- ## Pre-merge Verification
92
+ If `docs/PROJECT.md` has an Operations → Additional Gates section, report them:
93
+ - **Code review required?** → Verify PR was reviewed (or inform the user)
94
+ - **CI must pass?** → Will be checked in Phase 4
95
+ - **Other gates?** → Report status
76
96
 
77
- Before merging, verify the worktree is in a clean, mergeable state:
97
+ > These are informational. know-thy-build enforces its own gates; project-specific gates are the project's responsibility.
98
+
99
+ ---
100
+
101
+ ## Phase 2: Rebase on Main
78
102
 
79
103
  ### 1. Check for uncommitted changes
80
104
 
@@ -96,68 +120,188 @@ If any remain:
96
120
  > "Implementation markers found — the feature is not fully implemented."
97
121
  → Stop here.
98
122
 
99
- ### 3. Verify tests pass
123
+ ### 3. Fetch and rebase
100
124
 
101
125
  ```bash
102
- # Detect test runner from package.json, pyproject.toml, etc.
103
- # Run appropriate test command
126
+ git fetch origin main
127
+ git rebase origin/main
104
128
  ```
105
129
 
106
- If tests fail:
107
- > "Tests are failing. Fix before merge."
108
- Stop here.
130
+ **If rebase succeeds with no conflicts:**
131
+ > " Rebased cleanly on main. No conflicts."
132
+ Set `integration: passed` in feature spec. Skip Phase 3. Proceed to Phase 4.
133
+
134
+ **If rebase produces conflicts:**
135
+ > "⚠️ Conflicts detected during rebase. Starting conflict resolution."
136
+ → Proceed to Phase 3.
137
+
138
+ ---
139
+
140
+ ## Phase 3: Conflict Resolution & Integration Review
141
+
142
+ ### Step 1: Identify conflicts
143
+
144
+ ```bash
145
+ git diff --name-only --diff-filter=U
146
+ ```
147
+
148
+ List every conflicting file. For each, show the conflict markers:
149
+
150
+ ```bash
151
+ grep -n "<<<<<<< HEAD\|=======\|>>>>>>>" {{file}} 2>/dev/null
152
+ ```
153
+
154
+ ### Step 2: Understand the other side
155
+
156
+ Before resolving, read what changed on main since the feature branched:
157
+
158
+ ```bash
159
+ # What features were merged to main while this feature was in progress?
160
+ git log --oneline origin/main --not $(git merge-base HEAD origin/main) -- docs/features/
161
+ ```
162
+
163
+ Read the specs of recently merged features to understand their intent.
164
+
165
+ ### Step 3: Resolve conflicts
166
+
167
+ For each conflict:
168
+
169
+ 1. Read both sides (ours = this feature, theirs = main)
170
+ 2. Understand the intent of both changes
171
+ 3. Resolve by preserving BOTH intents where possible
172
+ 4. If the intents are fundamentally incompatible → ask the user
109
173
 
110
- ### 4. Verify artifacts exist
174
+ After resolving each file:
175
+ ```bash
176
+ git add {{file}}
177
+ ```
178
+
179
+ After all conflicts resolved:
180
+ ```bash
181
+ git rebase --continue
182
+ ```
183
+
184
+ If additional conflicts appear in subsequent commits, repeat.
185
+
186
+ ### Step 4: Integration review agent
187
+
188
+ **Dispatch a sub-agent** to review the conflict resolution:
189
+
190
+ ```
191
+ Agent prompt:
192
+ "You are the integration reviewer. Your job is to verify that conflict resolution
193
+ preserved the intent of ALL affected features, introduced no side effects, and
194
+ maintained architectural consistency.
195
+
196
+ Context:
197
+ - This feature: docs/features/{{NNN}}.md
198
+ - Recently merged features: [list from Step 2]
199
+ - Project rules: docs/PROJECT.md, docs/TECHNICAL.md
200
+
201
+ Tasks:
202
+ 1. Read this feature's spec and all recently merged feature specs
203
+ 2. Read the conflict resolution diff: git diff HEAD~1 (or appropriate range)
204
+ 3. For each resolved conflict:
205
+ a. Does the resolution preserve BOTH features' intent?
206
+ b. Does it introduce any side effect on either feature's code paths?
207
+ c. Does it follow the patterns in TECHNICAL.md?
208
+ 4. Check if regression guard tests exist for the affected areas
209
+ 5. Report: PASSED (all clear) or FAILED (list specific issues)
210
+
211
+ Be aggressive — you are the last defense before merge. If you have doubts,
212
+ report them as failures. False negatives (missed bugs) are worse than false
213
+ positives (extra review)."
214
+ ```
215
+
216
+ **If integration review returns PASSED:**
217
+ → Set `integration: passed` in feature spec. Proceed to Phase 4.
218
+
219
+ **If integration review returns FAILED:**
220
+ > "❌ Integration review failed:"
221
+ > {{list specific issues from the agent}}
222
+ > "Fix the issues and re-run `/know-thy-build:finish`."
223
+ → Set `integration: failed` in feature spec. Stop here.
224
+
225
+ ---
226
+
227
+ ## Phase 4: CI/CD Gate
228
+
229
+ ### 1. Run test command
111
230
 
112
- Check that each role left its artifacts in the worktree:
231
+ Extract the test command from `docs/PROJECT.md` Operations CI/CD:
113
232
 
114
233
  ```bash
115
- # Architect artifacts: scaffold files, signature tests
116
- grep -rn "DO NOT MODIFY" --include="*.test.*" --include="*_test.*" . 2>/dev/null | head -5
234
+ # Example: npm test, pytest, go test ./...
235
+ {{test_command}}
236
+ ```
237
+
238
+ **If no test command is defined:** auto-pass with warning.
239
+
240
+ ### 2. Run additional CI checks (if defined)
117
241
 
118
- # QA artifacts: test cases in QA.md
119
- grep -c "Feature {{NNN}}" docs/QA.md 2>/dev/null
242
+ If Operations defines lint, type check, or other blocking checks:
243
+
244
+ ```bash
245
+ # Example: eslint ., tsc --noEmit
246
+ {{ci_check_commands}}
120
247
  ```
121
248
 
122
- Report what will be merged to main:
123
- > "The following artifacts from this feature will be merged to main:"
124
- > - Code: {{list of modified/new source files}}
125
- > - Architect: scaffold structure, signature tests
126
- > - Designer: design intent updates in feature spec (if applicable)
127
- > - QA: test cases in `docs/QA.md`
128
- > - Feature spec: gate statuses updated
249
+ ### 3. Evaluate
250
+
251
+ **All CI checks pass:**
252
+ Set `ci: passed` in feature spec. Proceed to Phase 5.
253
+
254
+ **Any CI check fails:**
255
+ > "❌ CI failed:"
256
+ > {{error output}}
257
+ > "Fix the failures and re-run `/know-thy-build:finish`."
258
+ → Set `ci: failed` in feature spec. Stop here.
129
259
 
130
260
  ---
131
261
 
132
- ## Merge
262
+ ## Phase 5: Merge
263
+
264
+ All 5 gates are now `passed` or `skipped`. Proceed with merge.
265
+
266
+ ### 1. Determine merge strategy
133
267
 
134
- ### 1. Switch to main and merge
268
+ Check `docs/PROJECT.md` Operations → Merge Strategy. Default to squash if not defined.
269
+
270
+ | Strategy | Command |
271
+ |----------|---------|
272
+ | squash (default) | `git merge --squash` |
273
+ | rebase | fast-forward merge (already rebased) |
274
+ | merge commit | `git merge --no-ff` |
275
+
276
+ ### 2. Switch to main and merge
135
277
 
136
278
  ```bash
137
279
  # Ensure main is up to date
138
280
  git checkout main
139
281
  git pull --ff-only origin main 2>/dev/null || true
140
282
 
141
- # Squash merge
283
+ # Execute the merge strategy (default: squash)
142
284
  git merge --squash "feature/{{NNN}}-{{title_kebab}}"
143
285
  ```
144
286
 
145
- ### 2. Create commit
287
+ ### 3. Create commit
146
288
 
147
289
  ```bash
148
290
  git commit -m "feat({{NNN}}): {{title}}
149
291
 
150
292
  - Architect: {{brief summary of structure decisions}}
151
293
  - Designer: {{brief summary of design decisions, or 'skipped'}}
152
- - QA: {{number}} test cases passed
294
+ - QA: {{number}} test cases, {{number}} regression guards
295
+ - Integration: {{clean / resolved N conflicts}}
296
+ - CI: all checks passed
153
297
 
154
298
  Feature spec: docs/features/{{NNN}}.md
155
- Gate: architect ✓ | designer ✓/skipped | qa ✓"
299
+ Gate: architect ✓ | designer ✓/skipped | qa ✓ | integration ✓ | ci ✓"
156
300
  ```
157
301
 
158
- ### 3. Update feature spec status
302
+ ### 4. Update feature spec status
159
303
 
160
- Switch back briefly or edit from main — update the feature spec frontmatter:
304
+ Update the feature spec frontmatter:
161
305
 
162
306
  ```yaml
163
307
  status: complete
@@ -166,9 +310,11 @@ gate:
166
310
  architect: passed
167
311
  designer: passed # or skipped
168
312
  qa: passed
313
+ integration: passed
314
+ ci: passed
169
315
  ```
170
316
 
171
- ### 4. Update Feature Registry
317
+ ### 5. Update Feature Registry
172
318
 
173
319
  In `docs/PROJECT.md`, update the Feature Registry row for this feature:
174
320
  ```
@@ -215,6 +361,13 @@ Commit: {{short hash}} feat({{NNN}}): {{title}}
215
361
  Branch: feature/{{NNN}}-{{title_kebab}} — deleted
216
362
  Worktree: {{WT_PATH}} — removed
217
363
 
364
+ Pipeline results:
365
+ Architect: ✓ passed
366
+ Designer: ✓ passed / skipped
367
+ QA: ✓ passed ({{N}} test cases, {{N}} regression guards)
368
+ Integration: ✓ {{clean / resolved N conflicts}}
369
+ CI: ✓ all checks passed
370
+
218
371
  Artifacts merged:
219
372
  - Code changes: {{file count}} files
220
373
  - Architect structure: preserved in code + signature tests
@@ -229,17 +382,30 @@ Next: /know-thy-build:feature for the next feature
229
382
 
230
383
  ## Edge Cases
231
384
 
232
- ### Merge conflicts
385
+ ### Rebase conflicts that can't be auto-resolved
386
+
387
+ If conflicts involve fundamentally incompatible changes (e.g. two features restructured the same module differently):
388
+
389
+ 1. Show both sides with full context
390
+ 2. Read both feature specs to understand intent
391
+ 3. Propose a resolution that preserves both intents
392
+ 4. Ask the user to confirm before proceeding
393
+ 5. The integration review agent will verify the resolution
394
+
395
+ ### Integration review fails repeatedly
396
+
397
+ If the integration review agent keeps finding issues after fixes:
398
+
399
+ 1. Show the full list of unresolved issues
400
+ 2. Suggest the user review the issues manually
401
+ 3. Offer to skip integration review with explicit user approval:
402
+ > "Skipping integration review at user's request. Set `integration: skipped` in feature spec."
233
403
 
234
- If `git merge --squash` produces conflicts:
404
+ ### No test command defined
235
405
 
236
- 1. List conflicting files
237
- 2. For each conflict, show the conflict markers
238
- 3. Offer resolution options:
239
- - Accept worktree version (ours)
240
- - Accept main version (theirs)
241
- - Manual resolution
242
- 4. After resolution, continue with commit
406
+ If `docs/PROJECT.md` doesn't define a test command:
407
+ - `ci` gate auto-passes with a warning
408
+ - Recommend the user runs `/know-thy-build:project` to define one
243
409
 
244
410
  ### Abandoned feature
245
411
 
@@ -551,6 +551,42 @@ Accumulate as:
551
551
 
552
552
  **Done when:** Frontier is empty. 2-7 principles captured, or user decides none are needed.
553
553
 
554
+ ### Operations — How does code ship?
555
+
556
+ > What to discover: The project's merge, deploy, and CI workflow. know-thy-build enforces quality gates (architect/designer/qa) BEFORE merge. This area defines what happens AT and AFTER merge — which is project-specific.
557
+
558
+ **Prerequisites:** Vision and Output areas settled.
559
+
560
+ Before asking, **find facts** — scan existing infrastructure:
561
+ ```bash
562
+ cat package.json 2>/dev/null | grep -E '"scripts"|"test"|"lint"|"build"|"deploy"' | head -10
563
+ ls .github/workflows/ .gitlab-ci.yml Jenkinsfile Makefile Dockerfile 2>/dev/null
564
+ cat .github/workflows/*.yml 2>/dev/null | head -40
565
+ ```
566
+
567
+ Present what you found as facts, then ask about decisions:
568
+
569
+ Frontier questions:
570
+
571
+ | Question | Depends on | Type |
572
+ |----------|-----------|------|
573
+ | How do feature branches merge to main? (squash, rebase, merge commit) | — | Decision |
574
+ | **What is the test command?** (e.g. `npm test`, `pytest`, `go test ./...`) | — | Decision (REQUIRED) |
575
+ | How does code reach users? (npm publish, docker, manual deploy, CI/CD trigger) | — | Decision |
576
+ | What other automated checks run before merge? (lint, type check) | merge-strategy | Fact (scan CI config) + Decision |
577
+ | Are there review requirements beyond know-thy-build gates? (code review, security scan) | — | Decision |
578
+
579
+ Slots to fill:
580
+ - `{{merge_strategy}}` — squash / rebase / merge commit
581
+ - `{{test_command}}` — **REQUIRED.** The command `/know-thy-build:finish` runs before merge. Without it, the `ci` gate auto-passes.
582
+ - `{{deploy_method}}` — how releases reach users
583
+ - `{{ci_checks}}` — automated quality checks (lint, type check, etc.)
584
+ - `{{additional_gates}}` — extra review requirements
585
+
586
+ **Done when:** Frontier is empty. At minimum, merge strategy and **test command** are defined. Deploy and additional gates can be "none yet" if the project is early.
587
+
588
+ > **Why this matters:** Without explicit operations definitions, sub-agents and hooks cannot enforce project-specific workflows. The merge gate hook only covers know-thy-build's built-in gates — project-specific gates (code review, CI checks) must be defined here so agents know to respect them.
589
+
554
590
  ---
555
591
 
556
592
  ## Checkpoints & State Tracking
@@ -781,6 +817,55 @@ Remove `areasRemaining`, `lastCheckpoint`, and `open` counts.
781
817
 
782
818
  **Technical Foundation:** [TECHNICAL.md](TECHNICAL.md)
783
819
 
820
+ ## Operations
821
+
822
+ <!-- How this project ships code. Each project defines its own workflow.
823
+ know-thy-build gates (architect/designer/qa) enforce quality BEFORE merge.
824
+ Everything below defines what happens AT and AFTER merge. -->
825
+
826
+ ### Merge Strategy
827
+
828
+ <!-- How feature branches become main. know-thy-build defaults to squash merge,
829
+ but your project may differ. -->
830
+
831
+ | Setting | Value |
832
+ |---------|-------|
833
+ | **Strategy** | {{squash / rebase / merge commit}} |
834
+ | **Branch naming** | `feature/NNN-slug` (know-thy-build default) |
835
+ | **Commit format** | `feat(NNN): title` |
836
+
837
+ ### Deploy
838
+
839
+ <!-- How main reaches users. Leave blank if not yet decided. -->
840
+
841
+ | Setting | Value |
842
+ |---------|-------|
843
+ | **Method** | {{npm publish / docker push / manual / CI-triggered / N/A}} |
844
+ | **Target** | {{registry, server, CDN, etc.}} |
845
+ | **Trigger** | {{on tag / on merge to main / manual}} |
846
+
847
+ ### CI/CD
848
+
849
+ <!-- Automated checks that run on push or PR.
850
+ The test command is REQUIRED — /know-thy-build:finish runs it before merge.
851
+ Without it, the ci gate auto-passes and regressions slip through. -->
852
+
853
+ | Check | Command | Blocks merge? |
854
+ |-------|---------|---------------|
855
+ | **test** | **{{test_command}}** | **yes (required)** |
856
+ | {{lint}} | {{eslint, ruff, etc.}} | {{yes/no}} |
857
+ | {{type check}} | {{tsc, mypy, etc.}} | {{yes/no}} |
858
+
859
+ ### Additional Gates
860
+
861
+ <!-- Review requirements beyond know-thy-build's built-in gates.
862
+ Only include gates that actually exist or are planned. Omit if none. -->
863
+
864
+ | Gate | Required? | Who |
865
+ |------|-----------|-----|
866
+ | {{code review}} | {{yes/no}} | {{team lead, any reviewer, etc.}} |
867
+ | {{security scan}} | {{yes/no}} | {{tool name}} |
868
+
784
869
  ---
785
870
 
786
871
  *Generated by know-thy-build | {{date}}*
@@ -930,8 +1015,13 @@ worktree (sub-agent orchestrates the entire lifecycle):
930
1015
  Designer review → gate.designer ✓
931
1016
  QA TEST → gate.qa ✓
932
1017
 
933
- Phase 4 — Finish:
934
- All gates passed → /know-thy-build:finish → squash merge + cleanup
1018
+ Phase 4 — Finish (merge pipeline):
1019
+ /know-thy-build:finish orchestrates:
1020
+ Review gates check → architect/designer/qa must be passed
1021
+ Rebase on main → surface conflicts
1022
+ Conflict resolution → resolve, then integration review agent
1023
+ CI/CD → run project test command
1024
+ Merge → squash merge + cleanup
935
1025
  ```
936
1026
 
937
1027
  ### Gate (Merge Prerequisite)
@@ -943,6 +1033,8 @@ Merge is allowed only when all gates are `passed` or `skipped`.
943
1033
  | architect | pending → passed | Architect review passes |
944
1034
  | designer | pending → passed / skipped | Designer review passes (skipped for non-UI) |
945
1035
  | qa | pending → passed | All QA test cases pass |
1036
+ | integration | pending → passed | Finish: rebase clean OR conflict review agent passes |
1037
+ | ci | pending → passed | Finish: project test command passes |
946
1038
 
947
1039
  ### Orchestrator Model
948
1040
  The user session acts as **orchestrator only** — it does NOT implement directly.
@@ -959,7 +1051,20 @@ Before any work, the sub-agent MUST read:
959
1051
  - Architect + Designer re-review if changes are structural
960
1052
  - QA re-tests failed scenarios + regression check on happy path
961
1053
  - Loop continues until ALL reviewers' criteria are `[x]`
962
- - Only when all three gates pass does `/know-thy-build:finish` proceed
1054
+ - Only when all three review gates pass does `/know-thy-build:finish` start the merge pipeline
1055
+ - Finish then handles: rebase → conflict resolution → integration review → CI → merge
1056
+
1057
+ ### Project-Specific Operations
1058
+ The merge gate hook enforces know-thy-build's built-in gates (architect/designer/qa).
1059
+ Your project may have additional requirements defined in `docs/PROJECT.md` → Operations section:
1060
+ - **Merge strategy** — the hook assumes squash merge; adjust if your project uses rebase or merge commits
1061
+ - **CI/CD checks** — if your project requires CI to pass before merge, enforce that separately
1062
+ - **Additional gates** — code review, security scan, etc. are project-level concerns, not managed by know-thy-build
1063
+ - **Deploy** — what happens after merge is entirely project-defined
1064
+
1065
+ When `/know-thy-build:finish` runs, it checks know-thy-build gates. For project-specific gates, the project should either:
1066
+ 1. Add its own hooks to `.claude/settings.json`
1067
+ 2. Or rely on CI/CD and branch protection rules
963
1068
 
964
1069
  ### Document References
965
1070
  - Project definition: `docs/PROJECT.md`
@@ -967,6 +1072,7 @@ Before any work, the sub-agent MUST read:
967
1072
  - Feature specs: `docs/features/NNN.md`
968
1073
  - QA test cases: `docs/QA.md`
969
1074
  - Feature registry: `docs/PROJECT.md` → Feature Registry section
1075
+ - Operations: `docs/PROJECT.md` → Operations section
970
1076
  ```
971
1077
 
972
1078
  ## Setup Merge Gate Hook
@@ -981,22 +1087,27 @@ After generating CLAUDE.md, set up the merge gate hook in `.claude/settings.json
981
1087
  #!/usr/bin/env bash
982
1088
  # know-thy-build merge gate — blocks git merge when feature gate is not fully passed
983
1089
 
984
- # Only check if the command contains git merge
985
- if ! echo "$TOOL_INPUT" | grep -qE 'git\s+merge'; then
986
- exit 0
987
- fi
1090
+ # Fast exit: only check commands that contain "git merge"
1091
+ echo "${TOOL_INPUT:-}" | grep -qE 'git\s+merge' || exit 0
988
1092
 
989
- # Find the active feature spec with gate
990
- FEATURE_FILE=$(ls -t docs/features/*.md 2>/dev/null | head -1)
991
- if [ -z "$FEATURE_FILE" ]; then
992
- exit 0
993
- fi
1093
+ # Identify current feature from branch name (feature/NNN-slug)
1094
+ BRANCH=$(git branch --show-current 2>/dev/null || echo "")
1095
+ echo "$BRANCH" | grep -qE '^feature/' || exit 0
1096
+
1097
+ FEATURE_NUM=$(echo "$BRANCH" | grep -oE '[0-9]+' | head -1)
1098
+ [ -z "$FEATURE_NUM" ] && exit 0
1099
+
1100
+ FEATURE_FILE="docs/features/$(printf '%03d' "$FEATURE_NUM").md"
1101
+ [ -f "$FEATURE_FILE" ] || exit 0
1102
+
1103
+ # Skip completed features — their gate is historical, not active
1104
+ grep -qE '^status:\s*complete' "$FEATURE_FILE" 2>/dev/null && exit 0
994
1105
 
995
1106
  # Check gate statuses
996
- PENDING=$(grep -cE '^\s+(architect|designer|qa):\s*pending' "$FEATURE_FILE" 2>/dev/null || echo "0")
1107
+ PENDING=$(grep -cE '^\s+(architect|designer|qa|integration|ci):\s*pending' "$FEATURE_FILE" 2>/dev/null || echo "0")
997
1108
 
998
1109
  if [ "$PENDING" -gt 0 ]; then
999
- echo "❌ Merge gate blocked — pending reviews exist:"
1110
+ echo "❌ Merge gate blocked — Feature $(printf '%03d' "$FEATURE_NUM") has pending reviews:"
1000
1111
  grep -E '^\s+(architect|designer|qa):' "$FEATURE_FILE" 2>/dev/null
1001
1112
  echo ""
1002
1113
  echo "Run /know-thy-build:finish to check gate status."
@@ -1028,6 +1139,8 @@ exit 0
1028
1139
 
1029
1140
  Make the hook script executable: `chmod +x .claude/hooks/check-merge-gate.sh`
1030
1141
 
1142
+ > **Note for projects**: The `"matcher": "Bash"` fires on every Bash tool call but exits in < 1ms for non-merge commands (first `grep` short-circuits). Claude Code does not support content-based matchers, so this is the lightest possible approach.
1143
+
1031
1144
  ## Closing
1032
1145
 
1033
1146
  **After CREATE:**
@@ -685,13 +685,49 @@ For each selected profile, generate test cases using its **turn-level instructio
685
685
  - **Profile** column traces which behavioral axis combination generated this case.
686
686
  - **Injection test cases** must specify exactly how to inject the failure state.
687
687
 
688
- ### Step 5: Update QA.md
688
+ ### Step 5: Regression Guard Tests (MANDATORY)
689
+
690
+ **Purpose:** Protect this feature's core behavior from being broken by future feature merges. When multiple agents work on features in parallel, another agent's merge can silently break your work. Regression guard tests catch that.
691
+
692
+ **Rules:**
693
+ - Each **Done When** criterion in the feature spec → at least 1 automated test
694
+ - Tests must be **independently runnable** — no cross-feature dependency
695
+ - Tests must **fail loudly** when behavior changes, not silently pass
696
+ - Test names include the feature number: `test_NNN_*` (e.g. `test_003_login_success`)
697
+ - Tests run via the project's test command defined in `docs/PROJECT.md` → Operations → CI/CD
698
+
699
+ **How to write regression guards:**
700
+
701
+ 1. Read the feature spec's **Done When** section
702
+ 2. For each criterion, write at least one automated test that:
703
+ - Sets up the precondition
704
+ - Performs the action
705
+ - Asserts the expected outcome
706
+ - Cleans up after itself (no side effects on other tests)
707
+ 3. Group tests under the feature number for traceability
708
+
709
+ **Template:**
710
+
711
+ ```
712
+ ### Regression Guards — Feature {{NNN}}: {{title}}
713
+
714
+ | # | Done-When Criterion | Test Name | What It Verifies |
715
+ |---|---------------------|-----------|------------------|
716
+ | 1 | {{criterion_1}} | test_{{NNN}}_{{name}} | {{specific assertion}} |
717
+ | 2 | {{criterion_2}} | test_{{NNN}}_{{name}} | {{specific assertion}} |
718
+ ```
719
+
720
+ **Why this matters:** When `/know-thy-build:finish` rebases on main and resolves conflicts, it runs the project's test command. If another feature's merge broke your work, your regression guard tests fail, and the merge is blocked. Without these tests, the CI gate is a formality.
721
+
722
+ ### Step 6: Update QA.md
689
723
 
690
724
  1. Append the feature section to `docs/QA.md`
691
725
  2. Add any new turn-level scenarios to the Turn-Level Scenarios section
692
- 3. Update feature spec frontmatter:
726
+ 3. Add regression guard test entries to the feature section
727
+ 4. Update feature spec frontmatter:
693
728
  ```yaml
694
729
  qaTestCases: {{count}}
730
+ qaRegressionGuards: {{count}}
695
731
  qaReviewDate: {{date}}
696
732
  ```
697
733
 
@@ -699,6 +735,7 @@ For each selected profile, generate test cases using its **turn-level instructio
699
735
  - [ ] Every AC has at least one test case
700
736
  - [ ] At least 3 profiles are represented in test cases
701
737
  - [ ] At least 2 failure state injection test cases
738
+ - [ ] **Every Done-When criterion has at least one regression guard test**
702
739
  - [ ] Access path verified
703
740
  - [ ] Test cases are concrete enough that anyone could execute them
704
741
  - [ ] Feature section appended to `docs/QA.md`