@pareto4/pp-core 1.17.1 → 1.19.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.
Files changed (199) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/README.md +5 -3
  3. package/agents/pp-code-fixer.md +9 -16
  4. package/agents/pp-code-reviewer.md +2 -78
  5. package/agents/pp-codebase-mapper.md +3 -0
  6. package/agents/pp-debugger.md +3 -2
  7. package/agents/pp-executor.md +25 -30
  8. package/agents/pp-integration-checker.md +1 -0
  9. package/agents/pp-phase-researcher.md +3 -1
  10. package/agents/pp-plan-checker.md +3 -0
  11. package/agents/pp-planner.md +16 -12
  12. package/agents/pp-research-synthesizer.md +1 -1
  13. package/agents/pp-ui-auditor.md +1 -0
  14. package/agents/pp-ui-researcher.md +3 -1
  15. package/agents/pp-vault-reviewer.md +43 -189
  16. package/agents/pp-verifier.md +10 -8
  17. package/commands/pp-add-tests.md +1 -1
  18. package/commands/pp-debug.md +1 -0
  19. package/commands/pp-init.md +4 -3
  20. package/commands/pp-ns-manage.md +1 -1
  21. package/commands/pp-ns-review.md +1 -1
  22. package/commands/pp-quick.md +3 -0
  23. package/commands/pp-review-backlog.md +2 -1
  24. package/commands/pp-vault-promote.md +7 -8
  25. package/commands/pp-vault-review.md +6 -7
  26. package/gemini-extension.json +1 -1
  27. package/package.json +3 -6
  28. package/pp-core/bin/lib/capability-registry.cjs +15 -357
  29. package/pp-core/bin/lib/capability-state.cjs +15 -79
  30. package/pp-core/bin/lib/capability-writer.cjs +2 -16
  31. package/pp-core/bin/lib/check-command-router.cjs +342 -2298
  32. package/pp-core/bin/lib/clusters.cjs +2 -2
  33. package/pp-core/bin/lib/commands.cjs +79 -4
  34. package/pp-core/bin/lib/compose-bindings.cjs +99 -16
  35. package/pp-core/bin/lib/config.cjs +3 -6
  36. package/pp-core/bin/lib/discovery-rollup.cjs +9 -6
  37. package/pp-core/bin/lib/discovery-screens.cjs +20 -2
  38. package/pp-core/bin/lib/discovery-sweep.cjs +12 -3
  39. package/pp-core/bin/lib/discovery-vault-check.cjs +37 -3
  40. package/pp-core/bin/lib/git-base-branch.cjs +10 -13
  41. package/pp-core/bin/lib/git-provider.cjs +5 -6
  42. package/pp-core/bin/lib/init-contract.cjs +55 -42
  43. package/pp-core/bin/lib/init-interactive.cjs +6 -20
  44. package/pp-core/bin/lib/io.cjs +2 -8
  45. package/pp-core/bin/lib/loop-resolver.cjs +8 -32
  46. package/pp-core/bin/lib/org-profile.cjs +16 -92
  47. package/pp-core/bin/lib/vault-command-router.cjs +174 -1206
  48. package/pp-core/bin/lib/vault-coordinates.cjs +4 -4
  49. package/pp-core/bin/lib/vault-index.cjs +44 -74
  50. package/pp-core/bin/lib/vault-seal.cjs +37 -122
  51. package/pp-core/bin/lib/vault-standards-promote.cjs +577 -0
  52. package/pp-core/bin/lib/vault-standards-review.cjs +293 -0
  53. package/pp-core/bin/lib/vault-standards.cjs +15 -16
  54. package/pp-core/bin/lib/vault-trace.cjs +40 -3016
  55. package/pp-core/bin/lib/vault-update.cjs +5 -26
  56. package/pp-core/bin/lib/vault.cjs +122 -316
  57. package/pp-core/bin/pp-tools.cjs +15 -36
  58. package/pp-core/org-profile.json +1 -1
  59. package/pp-core/references/autonomous-best-effort.md +4 -3
  60. package/pp-core/references/autonomous-lifecycle.md +1 -0
  61. package/pp-core/references/autonomous-smart-discuss.md +5 -1
  62. package/pp-core/references/discovery-id-conventions.md +35 -2
  63. package/pp-core/references/execute-mvp-tdd.md +3 -3
  64. package/pp-core/references/git-integration.md +57 -33
  65. package/pp-core/references/git-planning-commit.md +31 -9
  66. package/pp-core/references/phase-argument-parsing.md +1 -0
  67. package/pp-core/references/planner-gap-closure.md +1 -0
  68. package/pp-core/references/planner-revision.md +3 -1
  69. package/pp-core/references/planner-tdd.md +4 -4
  70. package/pp-core/references/planner-vault-standards.md +16 -25
  71. package/pp-core/references/planning-config.md +3 -3
  72. package/pp-core/references/shell-portability.md +28 -0
  73. package/pp-core/references/tdd.md +20 -16
  74. package/pp-core/references/worktree-path-safety.md +1 -0
  75. package/pp-core/templates/README.md +1 -1
  76. package/pp-core/templates/VAULT-REVIEW.md +24 -170
  77. package/pp-core/templates/milestone.md +5 -5
  78. package/pp-core/workflows/add-backlog.md +1 -1
  79. package/pp-core/workflows/add-tests.md +8 -5
  80. package/pp-core/workflows/add-todo.md +3 -1
  81. package/pp-core/workflows/ai-integration-phase.md +2 -1
  82. package/pp-core/workflows/audit-fix.md +7 -6
  83. package/pp-core/workflows/audit-milestone.md +1 -0
  84. package/pp-core/workflows/autonomous.md +6 -0
  85. package/pp-core/workflows/check-todos.md +2 -1
  86. package/pp-core/workflows/cleanup.md +3 -1
  87. package/pp-core/workflows/code-review-fix.md +15 -8
  88. package/pp-core/workflows/code-review.md +16 -58
  89. package/pp-core/workflows/complete-milestone.md +13 -3
  90. package/pp-core/workflows/debug.md +4 -2
  91. package/pp-core/workflows/diagnose-issues.md +1 -1
  92. package/pp-core/workflows/discovery-sprint/prototype.md +2 -2
  93. package/pp-core/workflows/discovery-sprint/session-13-gates.md +1 -1
  94. package/pp-core/workflows/discovery-sprint/sessions/01-kick-off.md +51 -7
  95. package/pp-core/workflows/discovery-sprint/sessions/02-as-is.md +5 -3
  96. package/pp-core/workflows/discovery-sprint/sessions/03-to-be.md +10 -8
  97. package/pp-core/workflows/discovery-sprint/sessions/04-ux-design.md +11 -2
  98. package/pp-core/workflows/discovery-sprint/sessions/05-architecture.md +5 -5
  99. package/pp-core/workflows/discovery-sprint/sessions/06-security.md +3 -3
  100. package/pp-core/workflows/discovery-sprint/sessions/07-identity.md +2 -2
  101. package/pp-core/workflows/discovery-sprint/sessions/08-integration.md +14 -2
  102. package/pp-core/workflows/discovery-sprint/sessions/09-qa.md +2 -2
  103. package/pp-core/workflows/discovery-sprint/sessions/10-infrastructure.md +10 -10
  104. package/pp-core/workflows/discovery-sprint/sessions/11-roadmap.md +11 -8
  105. package/pp-core/workflows/discovery-sprint/sessions/12-delivery-model.md +21 -18
  106. package/pp-core/workflows/discovery-sprint/sessions/13-wrap-up.md +5 -3
  107. package/pp-core/workflows/discovery-sprint/templates/context-template.md +9 -3
  108. package/pp-core/workflows/discovery-sprint/vault-context.md +17 -12
  109. package/pp-core/workflows/discovery-sprint.md +11 -8
  110. package/pp-core/workflows/discovery-to-build/steps/architecture-deliverables.md +1 -0
  111. package/pp-core/workflows/discuss-phase-assumptions.md +5 -3
  112. package/pp-core/workflows/discuss-phase.md +8 -3
  113. package/pp-core/workflows/docs-update.md +1 -0
  114. package/pp-core/workflows/eval-review.md +2 -1
  115. package/pp-core/workflows/execute-phase/steps/check-query-gate.md +13 -14
  116. package/pp-core/workflows/execute-phase/steps/cross-ai-delegation.md +1 -0
  117. package/pp-core/workflows/execute-phase/steps/execute-pre-dispatch.md +5 -25
  118. package/pp-core/workflows/execute-phase/steps/per-plan-worktree-gate.md +1 -0
  119. package/pp-core/workflows/execute-phase/steps/vault-fetch.md +18 -6
  120. package/pp-core/workflows/execute-phase/steps/vault-load-gate.md +6 -109
  121. package/pp-core/workflows/execute-phase/steps/verify-post-gate.md +1 -17
  122. package/pp-core/workflows/execute-phase.md +21 -12
  123. package/pp-core/workflows/execute-plan.md +24 -15
  124. package/pp-core/workflows/explore.md +1 -1
  125. package/pp-core/workflows/forensics.md +4 -2
  126. package/pp-core/workflows/health.md +1 -0
  127. package/pp-core/workflows/help/modes/full.md +1 -1
  128. package/pp-core/workflows/import.md +2 -1
  129. package/pp-core/workflows/ingest-docs.md +1 -0
  130. package/pp-core/workflows/init/steps/client-context-capture.md +1 -0
  131. package/pp-core/workflows/init/steps/github-provisioning.md +145 -0
  132. package/pp-core/workflows/init/steps/gitlab-provisioning.md +18 -4
  133. package/pp-core/workflows/init/steps/reachability-outcome.md +3 -1
  134. package/pp-core/workflows/init.md +56 -66
  135. package/pp-core/workflows/map-codebase.md +5 -1
  136. package/pp-core/workflows/milestone-summary.md +2 -1
  137. package/pp-core/workflows/mvp-phase.md +1 -0
  138. package/pp-core/workflows/new-milestone.md +9 -5
  139. package/pp-core/workflows/new-project.md +9 -8
  140. package/pp-core/workflows/new-workspace.md +1 -0
  141. package/pp-core/workflows/next.md +2 -1
  142. package/pp-core/workflows/pause-work.md +6 -4
  143. package/pp-core/workflows/plan-milestone-gaps.md +3 -1
  144. package/pp-core/workflows/plan-phase/steps/chunked-planning.md +1 -1
  145. package/pp-core/workflows/plan-phase.md +21 -6
  146. package/pp-core/workflows/plan-review-convergence.md +2 -0
  147. package/pp-core/workflows/plant-seed.md +4 -2
  148. package/pp-core/workflows/pr-branch.md +2 -0
  149. package/pp-core/workflows/progress.md +5 -0
  150. package/pp-core/workflows/quick.md +19 -12
  151. package/pp-core/workflows/reapply-patches.md +3 -0
  152. package/pp-core/workflows/remove-phase.md +1 -1
  153. package/pp-core/workflows/resume-project.md +3 -0
  154. package/pp-core/workflows/review.md +7 -1
  155. package/pp-core/workflows/secure-phase.md +2 -1
  156. package/pp-core/workflows/session-report.md +1 -0
  157. package/pp-core/workflows/ship.md +8 -1
  158. package/pp-core/workflows/sketch-wrap-up.md +1 -1
  159. package/pp-core/workflows/sketch.md +3 -2
  160. package/pp-core/workflows/spec-phase.md +2 -1
  161. package/pp-core/workflows/spike-wrap-up.md +1 -1
  162. package/pp-core/workflows/spike.md +4 -3
  163. package/pp-core/workflows/sync-skills.md +5 -2
  164. package/pp-core/workflows/thread.md +3 -2
  165. package/pp-core/workflows/transition.md +6 -0
  166. package/pp-core/workflows/ui-phase.md +3 -1
  167. package/pp-core/workflows/ui-review.md +2 -1
  168. package/pp-core/workflows/ultraplan-phase.md +1 -0
  169. package/pp-core/workflows/undo.md +14 -10
  170. package/pp-core/workflows/update.md +5 -0
  171. package/pp-core/workflows/validate-phase.md +9 -6
  172. package/pp-core/workflows/vault-review.md +65 -186
  173. package/pp-core/workflows/vault-write-back.md +78 -110
  174. package/pp-core/workflows/verify-phase.md +5 -0
  175. package/pp-core/workflows/verify-work.md +9 -2
  176. package/scripts/gen-capability-registry.cjs +12 -93
  177. package/scripts/lint-test-file-count.allowlist.json +1 -19
  178. package/scripts/lint-test-file-count.cjs +5 -6
  179. package/scripts/prompt-injection-scan.sh +1 -4
  180. package/scripts/sync-runtime-launcher.cjs +115 -5
  181. package/pp-core/bin/lib/practices-review-check.cjs +0 -944
  182. package/pp-core/bin/lib/vault-audit.cjs +0 -2594
  183. package/pp-core/bin/lib/vault-mode.cjs +0 -235
  184. package/pp-core/bin/lib/vault-practices.cjs +0 -2057
  185. package/pp-core/bin/lib/vault-review.cjs +0 -2102
  186. package/pp-core/bin/lib/vault-write-back.cjs +0 -905
  187. package/pp-core/references/planner-vault-practices.md +0 -95
  188. package/pp-core/references/practice-arithmetic-contract.md +0 -121
  189. package/pp-core/references/verifier-practice-verdicts.md +0 -263
  190. package/pp-core/templates/practices/README.md +0 -248
  191. package/pp-core/templates/practices/error-handling.md +0 -18
  192. package/pp-core/templates/practices/minimal-comments.md +0 -14
  193. package/pp-core/templates/practices/naming-convention.md +0 -18
  194. package/pp-core/templates/practices/practice-template.md +0 -23
  195. package/pp-core/workflows/execute-phase/steps/verifier-practice-payload.md +0 -165
  196. package/scripts/gen-practice-arithmetic-contract.cjs +0 -412
  197. package/scripts/practice-arithmetic-contract.allow.json +0 -35
  198. package/scripts/record-vault-mode-golden.cjs +0 -89
  199. package/scripts/vault-calibrate.cjs +0 -996
@@ -1,412 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * Inject the canonical practice-verdict arithmetic contract into every
4
- * instruction surface that states it.
5
- *
6
- * WHY THIS EXISTS. Phase 6 verification took seven passes and found eight gaps.
7
- * Every one had the same root cause: one contract restated in English on five
8
- * surfaces, with nothing keeping the copies true. Two of the gaps were defects
9
- * introduced while repairing another.
10
- *
11
- * WHY GENERATION AND NOT AN `@`-INCLUDE — checked, not assumed, because
12
- * ignoring the delivering surface is exactly what produced three of those
13
- * misses. `agents/pp-vault-reviewer.md` and
14
- * `pp-core/references/verifier-practice-verdicts.md` carry no `@`-includes; the
15
- * text must be physically present for the agent reading them. And
16
- * `steps/verifier-practice-payload.md` is interpolated VERBATIM into
17
- * pp-verifier's prompt (execute-phase.md:1358 -> :1382), so an `@` line there
18
- * would reach the agent as literal text. Physical copies are required, so this
19
- * follows the repo's existing answer for required-but-must-not-drift copies:
20
- * `gen-capability-registry`, `gen-platform-bindings-schema --check`.
21
- *
22
- * NOT A TARGET: `pp-core/templates/VAULT-REVIEW.md`. Its prose is a worked
23
- * sample the agent ADAPTS, not normative text — verified by diffing the
24
- * template against an artifact a reviewer actually wrote, where the wording
25
- * legitimately differs. It stays guarded mechanically instead, by the
26
- * arithmetic sweep in `tests/vault-review.test.cjs`.
27
- *
28
- * THE UNIT OF GOVERNANCE IS THE FILE, NOT THE REGION (06-16, gap G10).
29
- * Verification pass 8 reproduced the hole this originally left: it replaced
30
- * `verifier-practice-verdicts.md:98-100` — thirty lines ABOVE that file's own
31
- * generated block, outside every marker — with the contract's exact inverse,
32
- * and `--check`, `lint:ci` and the suite all stayed green. Marker-region
33
- * equality says nothing about the rest of the file, and an agent reads a file
34
- * linearly, so the hand-written copy is the one it meets first.
35
- *
36
- * So `--check` also runs a RESIDUE SCAN: for each target, the text outside its
37
- * region is scanned for the contract's load-bearing needles. The needle list is
38
- * NOT hardcoded here — it lives in a second marker region in the same single
39
- * source, so the guard cannot drift from the contract it guards. One file owns
40
- * both the canonical text and what counts as restating it.
41
- *
42
- * THE SCAN GOVERNS TEXT, NOT LINE BREAKS (06-17, W13). It runs the needles
43
- * twice: once per raw line, and once over joined normalised windows, reporting
44
- * the second as its own class only where no single line in the window matches.
45
- * Verification pass 9 measured why: the per-line pass alone was defeated by an
46
- * ordinary markdown wrap, using nothing but the needles' own phrases. See
47
- * `scanResidue`.
48
- *
49
- * `--write` deliberately does NOT scan. Generation injects; it must never
50
- * delete a surface's prose on the strength of a regex.
51
- *
52
- * Usage: --write (inject) | --check (exit 1 on drift OR residue, for lint:ci)
53
- *
54
- * Exit codes use `process.exitCode` + `return`, never `process.exit()`: the
55
- * repo's `n/no-process-exit` rule forbids the latter, and the lint scripts here
56
- * already use this form.
57
- */
58
- const fs = require('fs');
59
- const path = require('path');
60
- const crypto = require('crypto');
61
-
62
- const ROOT = path.join(__dirname, '..');
63
- const SOURCE = path.join(ROOT, 'pp-core', 'references', 'practice-arithmetic-contract.md');
64
- const ALLOWLIST = path.join(ROOT, 'scripts', 'practice-arithmetic-contract.allow.json');
65
- const S_START = '<!-- gen:practice-arithmetic-contract:source:start -->';
66
- const S_END = '<!-- gen:practice-arithmetic-contract:source:end -->';
67
- const N_START = '<!-- gen:practice-arithmetic-contract:needles:start -->';
68
- const N_END = '<!-- gen:practice-arithmetic-contract:needles:end -->';
69
- const START = '<!-- gen:practice-arithmetic-contract:start -->';
70
- const END = '<!-- gen:practice-arithmetic-contract:end -->';
71
-
72
- /** The four INSTRUCTION surfaces. The template is deliberately absent (see above). */
73
- const TARGETS = [
74
- 'pp-core/workflows/vault-review.md',
75
- 'agents/pp-vault-reviewer.md',
76
- 'pp-core/references/verifier-practice-verdicts.md',
77
- 'pp-core/workflows/execute-phase/steps/verifier-practice-payload.md',
78
- ];
79
-
80
- function readCanonical() {
81
- const text = fs.readFileSync(SOURCE, 'utf-8');
82
- const a = text.indexOf(S_START);
83
- const b = text.indexOf(S_END);
84
- if (a === -1 || b === -1 || b < a) {
85
- throw new Error(`${SOURCE}: source markers missing or inverted — cannot generate`);
86
- }
87
- const body = text.slice(a + S_START.length, b).trim();
88
- if (!body) throw new Error(`${SOURCE}: canonical block is empty — refusing to blank every target`);
89
- return body;
90
- }
91
-
92
- /**
93
- * The residue needles, read from the SAME source file as the canonical text and
94
- * with the SAME empty-block refusal. A needle line is `- ` + a backtick-quoted
95
- * regex source + ` — ` + why it is load-bearing; the description may itself
96
- * contain backticks, so only the FIRST backtick span is the pattern.
97
- *
98
- * A non-blank line that does not parse is a hard error. A silently skipped
99
- * needle is a guard that has quietly stopped guarding, which is the whole class
100
- * this file exists to end.
101
- */
102
- function readNeedles() {
103
- const text = fs.readFileSync(SOURCE, 'utf-8');
104
- const a = text.indexOf(N_START);
105
- const b = text.indexOf(N_END);
106
- if (a === -1 || b === -1 || b < a) {
107
- throw new Error(`${SOURCE}: needle markers missing or inverted — cannot scan for residue`);
108
- }
109
- const body = text.slice(a + N_START.length, b).trim();
110
- if (!body) throw new Error(`${SOURCE}: the needle list is empty — refusing to scan for nothing`);
111
-
112
- const needles = [];
113
- for (const raw of body.split(/\r?\n/)) {
114
- const line = raw.trim();
115
- if (!line) continue;
116
- const m = /^-\s+`([^`]+)`\s+—\s+(\S.*)$/.exec(line);
117
- if (!m) {
118
- throw new Error(
119
- `${SOURCE}: unparseable needle line — expected "- \`<regex>\` — <why>", got:\n ${line}`,
120
- );
121
- }
122
- let re;
123
- try {
124
- re = new RegExp(m[1], 'i');
125
- } catch (err) {
126
- throw new Error(`${SOURCE}: needle \`${m[1]}\` is not a valid regex — ${err.message}`);
127
- }
128
- needles.push({ source: m[1], re, why: m[2] });
129
- }
130
- if (!needles.length) throw new Error(`${SOURCE}: the needle list parsed to zero needles`);
131
- return needles;
132
- }
133
-
134
- const sha256 = (s) => crypto.createHash('sha256').update(s, 'utf-8').digest('hex');
135
-
136
- /**
137
- * Allowlist entries are keyed by target path and hash the EXACT allowed line.
138
- * Content-hashing is `06-02`'s mechanism for the protected `pp-vault-audit`
139
- * sites: editing an allowed line breaks its entry, so an allowance can never
140
- * quietly widen to cover text nobody justified. A `reason` is mandatory.
141
- *
142
- * An ABSENT allowlist means nothing is allowed — the fail-closed direction.
143
- */
144
- function readAllowlist() {
145
- if (!fs.existsSync(ALLOWLIST)) return {};
146
- const raw = JSON.parse(fs.readFileSync(ALLOWLIST, 'utf-8'));
147
- const out = {};
148
- for (const [file, entries] of Object.entries(raw)) {
149
- if (file.startsWith('//')) continue; // a comment key, never a path
150
- if (!TARGETS.includes(file)) {
151
- throw new Error(
152
- `${ALLOWLIST}: "${file}" is not one of the generated targets. ` +
153
- 'A stale key means the allowlist outlived the file it excused — re-justify or delete it.',
154
- );
155
- }
156
- if (!Array.isArray(entries)) throw new Error(`${ALLOWLIST}: "${file}" must map to an array`);
157
- for (const e of entries) {
158
- if (!/^[0-9a-f]{64}$/.test(String(e && e.sha256))) {
159
- throw new Error(`${ALLOWLIST}: "${file}" has an entry without a 64-hex sha256`);
160
- }
161
- if (!String((e && e.reason) || '').trim()) {
162
- throw new Error(
163
- `${ALLOWLIST}: "${file}" entry ${e.sha256.slice(0, 12)} has no reason. ` +
164
- 'An unjustified allowance is a rubber stamp; state why the line is not a restatement.',
165
- );
166
- }
167
- }
168
- out[file] = entries;
169
- }
170
- return out;
171
- }
172
-
173
- /**
174
- * Adjacent non-blank lines outside the region, joined with a single space and
175
- * whitespace-collapsed. A markdown paragraph is one window.
176
- *
177
- * Joining a whole run rather than sliding a 2-line window is not a wider net:
178
- * the needles are contiguous phrases, so the only adjacencies a join creates
179
- * are the ones at line boundaries — exactly the adjacencies the wrap destroyed.
180
- * A run simply also covers a phrase a reflow spread over three lines.
181
- */
182
- function normalisedWindows(lines, inRegion) {
183
- const windows = [];
184
- let run = [];
185
- const flush = () => {
186
- // A one-line run says nothing the per-line pass did not already say.
187
- if (run.length > 1) windows.push(run);
188
- run = [];
189
- };
190
- lines.forEach((line, i) => {
191
- if (inRegion(i) || !line.trim()) {
192
- flush();
193
- return;
194
- }
195
- run.push({ line, i });
196
- });
197
- flush();
198
- return windows;
199
- }
200
-
201
- /**
202
- * Scan one target's text OUTSIDE its generated region. Returns findings and the
203
- * set of allowlist hashes this file actually used, so an entry that matches no
204
- * line can be reported as rotted rather than sitting there looking like cover.
205
- *
206
- * TWO PASSES, and the second is additive (06-17, W13).
207
- *
208
- * The first tests each raw LINE, which is what shipped and what the three
209
- * allowlist entries hash. Verification pass 9 measured its ceiling: an ordinary
210
- * markdown wrap defeats every multi-word needle, including the needles' OWN
211
- * literal phrases — `two count` ending a line and `populations` opening the
212
- * next scanned clean, while the same words on one line failed naming all four.
213
- * The guard governed line breaks where it must govern text. Pass 9 probed all
214
- * four targets and found 0 live instances, so this was latent coverage rather
215
- * than residue at HEAD; the trigger, though, is an accidental prose reflow and
216
- * the direction of failure is silent.
217
- *
218
- * So the second pass runs the same needles over joined normalised WINDOWS, and
219
- * reports a hit only when the needle matches the window and matches NO single
220
- * line within it. That makes a wrap-only match its own named class instead of
221
- * folding it into the per-line one, and it leaves per-line semantics — and
222
- * therefore the existing allowlist hashes — exactly as they were.
223
- *
224
- * A wrap-only finding is allowlistable like any other, but its hash is of the
225
- * JOINED NORMALISED WINDOW, not of a raw line, and `--check` prints that exact
226
- * text beside the hash so nobody has to reconstruct it. That digest is stable
227
- * under a reflow of the same words, which is the right behaviour: what somebody
228
- * justified is the sentence, not where its line breaks happened to fall.
229
- */
230
- function scanResidue(file, needles, allowed) {
231
- const abs = path.join(ROOT, file);
232
- // Split on /\r?\n/, not '\n': the allowlist hashes the EXACT line, so a
233
- // CRLF checkout must not produce a different digest for the same text.
234
- const lines = fs.readFileSync(abs, 'utf-8').split(/\r?\n/);
235
- const a = lines.findIndex((l) => l.includes(START));
236
- const b = lines.findIndex((l) => l.includes(END));
237
- const inRegion = (i) => a !== -1 && b >= a && i >= a && i <= b;
238
-
239
- const allowedHashes = new Map((allowed[file] || []).map((e) => [e.sha256, e.reason]));
240
- const used = new Set();
241
- const findings = [];
242
- const wrapped = [];
243
-
244
- lines.forEach((line, i) => {
245
- if (inRegion(i)) return;
246
- const hits = needles.filter((n) => n.re.test(line));
247
- if (!hits.length) return;
248
- const h = sha256(line);
249
- if (allowedHashes.has(h)) {
250
- used.add(h);
251
- return;
252
- }
253
- findings.push({ file, line: i + 1, text: line, hits: hits.map((n) => n.source), sha256: h });
254
- });
255
-
256
- for (const run of normalisedWindows(lines, inRegion)) {
257
- const text = run
258
- .map((r) => r.line.trim())
259
- .join(' ')
260
- .replace(/\s+/g, ' ');
261
- // `n.re.test(r.line)` against the RAW line, exactly as the first pass tests
262
- // it, so "wrap-only" means precisely "the first pass could not have seen
263
- // this" — including when the first pass saw it and the allowlist excused it.
264
- const hits = needles.filter((n) => n.re.test(text) && !run.some((r) => n.re.test(r.line)));
265
- if (!hits.length) continue;
266
- const h = sha256(text);
267
- if (allowedHashes.has(h)) {
268
- used.add(h);
269
- continue;
270
- }
271
- wrapped.push({
272
- file,
273
- line: run[0].i + 1,
274
- endLine: run[run.length - 1].i + 1,
275
- text,
276
- hits: hits.map((n) => n.source),
277
- sha256: h,
278
- });
279
- }
280
-
281
- const unused = [...allowedHashes.keys()].filter((h) => !used.has(h));
282
- return { findings, wrapped, unused };
283
- }
284
-
285
- function apply(file, canonical, { write }) {
286
- const abs = path.join(ROOT, file);
287
- const text = fs.readFileSync(abs, 'utf-8');
288
- const a = text.indexOf(START);
289
- const b = text.indexOf(END);
290
- if (a === -1 || b === -1) {
291
- return { file, status: 'missing-markers' };
292
- }
293
- if (b < a) return { file, status: 'inverted-markers' };
294
-
295
- const desired = `${START}\n${canonical}\n${END}`;
296
- const current = text.slice(a, b + END.length);
297
- if (current === desired) return { file, status: 'unchanged' };
298
- if (write) {
299
- fs.writeFileSync(abs, text.slice(0, a) + desired + text.slice(b + END.length), 'utf-8');
300
- return { file, status: 'transformed' };
301
- }
302
- return { file, status: 'drifted' };
303
- }
304
-
305
- function main() {
306
- const write = process.argv.includes('--write');
307
- const check = process.argv.includes('--check');
308
- if (write === check) {
309
- console.error('usage: gen-practice-arithmetic-contract.cjs (--write | --check)');
310
- process.exitCode = 2;
311
- return;
312
- }
313
-
314
- const canonical = readCanonical();
315
- const results = TARGETS.map((f) => apply(f, canonical, { write }));
316
-
317
- const bad = results.filter((r) => r.status !== 'unchanged' && r.status !== 'transformed');
318
- for (const r of bad) console.error(` ${r.status}: ${r.file}`);
319
-
320
- if (check) {
321
- if (bad.length) {
322
- console.error(
323
- `\nFAIL: ${bad.length} surface(s) drifted from ${path.relative(ROOT, SOURCE)}.\n` +
324
- 'Edit that file, then run: npm run gen:practice-arithmetic-contract',
325
- );
326
- process.exitCode = 1;
327
- return;
328
- }
329
-
330
- // The residue scan. Region equality is necessary and not sufficient: a
331
- // surface can restate the contract by hand ANYWHERE ELSE in the same file,
332
- // where the region comparison never looks. That is G10.
333
- const needles = readNeedles();
334
- const allowed = readAllowlist();
335
- const findings = [];
336
- const wrapped = [];
337
- const rotted = [];
338
- for (const file of TARGETS) {
339
- const r = scanResidue(file, needles, allowed);
340
- findings.push(...r.findings);
341
- wrapped.push(...r.wrapped);
342
- for (const h of r.unused) rotted.push({ file, sha256: h });
343
- }
344
-
345
- if (findings.length || wrapped.length) {
346
- console.error(
347
- `\nFAIL: ${findings.length + wrapped.length} hand-written restatement(s) of the contract, OUTSIDE the generated region:\n`,
348
- );
349
- for (const f of findings) {
350
- console.error(` residue: ${f.file}:${f.line} [${f.hits.join(', ')}]`);
351
- console.error(` ${f.text.trim()}`);
352
- }
353
- // Named as its own class: the phrase is only visible once the lines are
354
- // joined, so the line number is a RANGE and the hash below is of the
355
- // joined text, not of any line you can see in the file (06-17, W13).
356
- for (const f of wrapped) {
357
- console.error(` wrapped residue: ${f.file}:${f.line}-${f.endLine} [${f.hits.join(', ')}]`);
358
- console.error(` ${f.text}`);
359
- }
360
- console.error(
361
- '\nREMEDY: replace the sentence with a POINTER to the generated block in the same file\n' +
362
- '("§7 states the rule; it is not restated here"), keeping only what the canonical block\n' +
363
- 'does not say — a per-tier destination, for instance. The facts stay physically present\n' +
364
- 'in the file, in the generated block the agent also reads.\n' +
365
- `If the line genuinely restates nothing, allowlist it in ${path.relative(ROOT, ALLOWLIST)}\n` +
366
- 'with its sha256 and a stated reason:\n',
367
- );
368
- for (const f of findings) console.error(` "${f.file}": [{ "sha256": "${f.sha256}", "reason": "…" }]`);
369
- if (wrapped.length) {
370
- console.error(
371
- '\nA WRAPPED finding is hashed over the JOINED, whitespace-collapsed text printed above —\n' +
372
- 'not over any single line of the file. The digest therefore survives a reflow of the same\n' +
373
- 'words, because what an allowance justifies is the sentence, not its line breaks:\n',
374
- );
375
- for (const f of wrapped) console.error(` "${f.file}": [{ "sha256": "${f.sha256}", "reason": "…" }]`);
376
- }
377
- process.exitCode = 1;
378
- return;
379
- }
380
-
381
- if (rotted.length) {
382
- console.error(
383
- `\nFAIL: ${rotted.length} allowlist entr(ies) match no line or window in their file:\n`,
384
- );
385
- for (const r of rotted) console.error(` rotted: ${r.file} ${r.sha256}`);
386
- console.error(
387
- '\nThe allowed line was edited or removed. Re-justify the new line or delete the entry —\n' +
388
- 'an allowance nobody can point at is exactly the rubber stamp content-hashing prevents.',
389
- );
390
- process.exitCode = 1;
391
- return;
392
- }
393
-
394
- const allowCount = Object.values(allowed).reduce((n, e) => n + e.length, 0);
395
- console.log(
396
- `ok practice-arithmetic-contract: ${results.length} surface(s) match the source; ` +
397
- `no residue outside the regions, per line or across a wrap (${needles.length} needles, ` +
398
- `${allowCount} allowlisted).`,
399
- );
400
- return;
401
- }
402
-
403
- const t = results.filter((r) => r.status === 'transformed').length;
404
- const u = results.filter((r) => r.status === 'unchanged').length;
405
- if (bad.length) {
406
- process.exitCode = 1;
407
- return;
408
- }
409
- console.log(`Done. ${t} transformed, ${u} unchanged.`);
410
- }
411
-
412
- main();
@@ -1,35 +0,0 @@
1
- {
2
- "//": [
3
- "Lines that carry a residue needle but restate NO fact the canonical block states.",
4
- "Read by scripts/gen-practice-arithmetic-contract.cjs --check. Keys starting with // are comments.",
5
- "sha256 is of the EXACT allowed line. Editing that line breaks its entry and forces re-justification;",
6
- "an entry matching no line in its file fails as rotted. A reason is mandatory.",
7
- "A WRAPPED finding — one visible only once adjacent lines are joined — is hashed over the joined,",
8
- "whitespace-collapsed window text that --check prints beside it, not over any single line of the",
9
- "file. That digest survives a reflow of the same words, because what an allowance justifies is the",
10
- "sentence and not where its line breaks fell. All three entries below are per-LINE. 06-17, W13.",
11
- "Every entry below is the same shape: a payload-KEY INVENTORY, where `derivedCounts` /",
12
- "`derivedRateLine` are named as things the CLI hands the agent, and the very next clause points at",
13
- "the generated contract block rather than saying what they mean. Naming a key is not restating a",
14
- "contract. Keep this file as close to empty as the prose allows.",
15
- "06-16, gap G10."
16
- ],
17
- "pp-core/workflows/vault-review.md": [
18
- {
19
- "sha256": "1766709dca03a214fb8fa5496fe6b2aef06fc1b02e67832a6048eeac78e29d6a",
20
- "reason": "Section 4 is the inventory of what REVIEW_PAYLOAD carries; this line names the two keys and its own continuation says what they describe is stated once in the contract block carried into the spawn prompt below. It states nothing itself."
21
- }
22
- ],
23
- "agents/pp-vault-reviewer.md": [
24
- {
25
- "sha256": "1fac53fb5988ab5278f2a262f1564b5dbef830531ec0a82f7200c9b940b45b8d",
26
- "reason": "The left cell of the supplied-fact table, where the key name IS the row's subject. The right cell is a pointer to the contract block twelve lines below, in the same <derived_facts> element."
27
- }
28
- ],
29
- "pp-core/references/verifier-practice-verdicts.md": [
30
- {
31
- "sha256": "52872e6f4b821944e026667c5bd48a3c2319f6876e805e8721865cbf6eb27816",
32
- "reason": "Section 6's inventory of what the check vault-review arm hands the verifier. The sentence that follows it points at section 7 and says explicitly that the rule is not restated here."
33
- }
34
- ]
35
- }
@@ -1,89 +0,0 @@
1
- #!/usr/bin/env node
2
- 'use strict';
3
-
4
- /**
5
- * scripts/record-vault-mode-golden.cjs — the vault-mode golden recorder
6
- * (Vault Assurance v1.2, phase 13; MODE-01, PARK-04; D-01).
7
- *
8
- * --write record every enablement cell (key absent — the canonical
9
- * recording), normalise, and write tests/fixtures/vault-mode-golden/<cell>.json
10
- * --check record the same and compare against the committed files; print
11
- * every differing path and exit 1 on any difference
12
- *
13
- * Neither or both flags: usage, exit 2. No path argument: the golden directory
14
- * is the harness's `GOLDEN_DIR`, so the recorder and the test cannot disagree
15
- * about where the goldens live.
16
- *
17
- * A THIN CLI. Every fixture, capture, normalisation and comparison rule lives in
18
- * the shared harness module required below, which the golden test requires too.
19
- * This script is never run by the test suite: a re-record is a deliberate,
20
- * reviewable re-baseline (D-01), and it must run on a tree whose practices-mode
21
- * behaviour is the one being pinned.
22
- */
23
-
24
- const fs = require('node:fs');
25
- const path = require('node:path');
26
- const harness = require('../tests/helpers/vault-mode-golden-harness.cjs');
27
-
28
- const ROOT = path.resolve(__dirname, '..');
29
- const USAGE = 'usage: record-vault-mode-golden.cjs (--write | --check)';
30
-
31
- function describeDiff(d) {
32
- const at = d.firstDiffAt === undefined ? '' : ` (first differing byte at ${d.firstDiffAt})`;
33
- const show = (v) => (v === undefined ? '<absent>' : JSON.stringify(v).slice(0, 200));
34
- return ` ${d.path}${at}\n expected: ${show(d.expected)}\n actual: ${show(d.actual)}`;
35
- }
36
-
37
- function main() {
38
- const write = process.argv.includes('--write');
39
- const check = process.argv.includes('--check');
40
- if (write === check) {
41
- console.error(USAGE);
42
- process.exitCode = 2;
43
- return;
44
- }
45
-
46
- let failed = 0;
47
- for (const cell of harness.ENABLEMENT_CELLS) {
48
- const raw = harness.recordCell({ cell: cell.name, modeKey: harness.KEY_CONFIGS.absent });
49
- const normalised = harness.normaliseRecording(raw);
50
- const count = Object.keys(normalised.commands).length;
51
- const dropped = Object.entries(raw.meta.droppedHookCounts)
52
- .map(([id, n]) => `${id}=${n}`)
53
- .join(' ');
54
- const target = harness.goldenPathFor(cell.name);
55
- const rel = path.relative(ROOT, target);
56
- console.log(`${cell.name}: ${count} commands recorded (render-hooks projection dropped: ${dropped})`);
57
-
58
- if (write) {
59
- fs.mkdirSync(path.dirname(target), { recursive: true });
60
- fs.writeFileSync(target, harness.serialise(normalised), 'utf8');
61
- console.log(` wrote ${rel}`);
62
- continue;
63
- }
64
-
65
- let expected;
66
- try {
67
- expected = JSON.parse(fs.readFileSync(target, 'utf8'));
68
- } catch (e) {
69
- console.error(` FAIL: ${rel} could not be read as JSON (${e.message})`);
70
- failed++;
71
- continue;
72
- }
73
- const { equal, diffs } = harness.compareRecordings(expected, normalised);
74
- if (equal) {
75
- console.log(` matches ${rel}`);
76
- } else {
77
- failed++;
78
- console.error(` FAIL: ${rel} differs at ${diffs.length} path(s):`);
79
- for (const d of diffs) console.error(describeDiff(d));
80
- }
81
- }
82
-
83
- if (check && failed > 0) {
84
- console.error(`\nFAIL: ${failed} golden cell(s) differ from a fresh recording.`);
85
- process.exitCode = 1;
86
- }
87
- }
88
-
89
- main();