@webpieces/agent-workflow-rules 0.0.0-stage → 0.0.1

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 (299) hide show
  1. package/README.md +23 -2
  2. package/package.json +45 -4
  3. package/src/adapters/agent-response.d.ts +5 -0
  4. package/src/adapters/agent-response.js +86 -0
  5. package/src/adapters/agent-response.js.map +1 -0
  6. package/src/adapters/codex-subagent-guard.d.ts +45 -0
  7. package/src/adapters/codex-subagent-guard.js +88 -0
  8. package/src/adapters/codex-subagent-guard.js.map +1 -0
  9. package/src/adapters/guards-hook.d.ts +3 -0
  10. package/src/adapters/guards-hook.js +30 -0
  11. package/src/adapters/guards-hook.js.map +1 -0
  12. package/src/adapters/hook-app-fixtures.d.ts +68 -0
  13. package/src/adapters/hook-app-fixtures.js +170 -0
  14. package/src/adapters/hook-app-fixtures.js.map +1 -0
  15. package/src/adapters/hook-core.d.ts +22 -0
  16. package/src/adapters/hook-core.js +359 -0
  17. package/src/adapters/hook-core.js.map +1 -0
  18. package/src/adapters/hook-pipeline-evaluator.d.ts +5 -0
  19. package/src/adapters/hook-pipeline-evaluator.js +18 -0
  20. package/src/adapters/hook-pipeline-evaluator.js.map +1 -0
  21. package/src/adapters/review-identity-stamper.d.ts +20 -0
  22. package/src/adapters/review-identity-stamper.js +34 -0
  23. package/src/adapters/review-identity-stamper.js.map +1 -0
  24. package/src/bin/codex-trust.d.ts +105 -0
  25. package/src/bin/codex-trust.js +205 -0
  26. package/src/bin/codex-trust.js.map +1 -0
  27. package/src/bin/dev-hook-install.d.ts +1 -0
  28. package/src/bin/dev-hook-install.js +80 -0
  29. package/src/bin/dev-hook-install.js.map +1 -0
  30. package/src/bin/dev-hook-uninstall.d.ts +1 -0
  31. package/src/bin/dev-hook-uninstall.js +45 -0
  32. package/src/bin/dev-hook-uninstall.js.map +1 -0
  33. package/src/bin/hook-registration.d.ts +429 -0
  34. package/src/bin/hook-registration.js +661 -0
  35. package/src/bin/hook-registration.js.map +1 -0
  36. package/src/bin/install-entry.d.ts +19 -0
  37. package/src/bin/install-entry.js +128 -0
  38. package/src/bin/install-entry.js.map +1 -0
  39. package/src/bin/l0-allowlist.d.ts +46 -0
  40. package/src/bin/l0-allowlist.js +527 -0
  41. package/src/bin/l0-allowlist.js.map +1 -0
  42. package/src/bin/l0-codex-read.d.ts +20 -0
  43. package/src/bin/l0-codex-read.js +108 -0
  44. package/src/bin/l0-codex-read.js.map +1 -0
  45. package/src/bin/l0-decide.d.ts +49 -0
  46. package/src/bin/l0-decide.js +90 -0
  47. package/src/bin/l0-decide.js.map +1 -0
  48. package/src/bin/l0-entry.d.ts +103 -0
  49. package/src/bin/l0-entry.js +98 -0
  50. package/src/bin/l0-entry.js.map +1 -0
  51. package/src/bin/l0-ignored-tools.d.ts +38 -0
  52. package/src/bin/l0-ignored-tools.js +44 -0
  53. package/src/bin/l0-ignored-tools.js.map +1 -0
  54. package/src/bin/managed-env.d.ts +46 -0
  55. package/src/bin/managed-env.js +50 -0
  56. package/src/bin/managed-env.js.map +1 -0
  57. package/src/bin/neighbour-hooks.d.ts +42 -0
  58. package/src/bin/neighbour-hooks.js +177 -0
  59. package/src/bin/neighbour-hooks.js.map +1 -0
  60. package/src/bin/reviewer-agent.d.ts +19 -0
  61. package/src/bin/reviewer-agent.js +135 -0
  62. package/src/bin/reviewer-agent.js.map +1 -0
  63. package/src/bin/settings-shape.d.ts +37 -0
  64. package/src/bin/settings-shape.js +17 -0
  65. package/src/bin/settings-shape.js.map +1 -0
  66. package/src/bin/setup-config.d.ts +20 -0
  67. package/src/bin/setup-config.js +371 -0
  68. package/src/bin/setup-config.js.map +1 -0
  69. package/src/bin/setup.d.ts +78 -0
  70. package/src/bin/setup.js +411 -0
  71. package/src/bin/setup.js.map +1 -0
  72. package/src/bin/shim-audit-log.d.ts +119 -0
  73. package/src/bin/shim-audit-log.js +286 -0
  74. package/src/bin/shim-audit-log.js.map +1 -0
  75. package/src/bin/shim-deny-reason.d.ts +1 -0
  76. package/src/bin/shim-deny-reason.js +244 -0
  77. package/src/bin/shim-deny-reason.js.map +1 -0
  78. package/src/bin/shim-drift-fix.d.ts +1 -0
  79. package/src/bin/shim-drift-fix.js +73 -0
  80. package/src/bin/shim-drift-fix.js.map +1 -0
  81. package/src/bin/shim-testkit.d.ts +107 -0
  82. package/src/bin/shim-testkit.js +197 -0
  83. package/src/bin/shim-testkit.js.map +1 -0
  84. package/src/bin/shim-version-drift.d.ts +1 -0
  85. package/src/bin/shim-version-drift.js +164 -0
  86. package/src/bin/shim-version-drift.js.map +1 -0
  87. package/src/bin/shim.d.ts +16 -0
  88. package/src/bin/shim.js +641 -0
  89. package/src/bin/shim.js.map +1 -0
  90. package/src/bin/upgrade-shim.d.ts +18 -0
  91. package/src/bin/upgrade-shim.js +283 -0
  92. package/src/bin/upgrade-shim.js.map +1 -0
  93. package/src/configs/main-sync-guard-configs.d.ts +38 -0
  94. package/src/configs/main-sync-guard-configs.js +54 -0
  95. package/src/configs/main-sync-guard-configs.js.map +1 -0
  96. package/src/configs/rule-configs.d.ts +47 -0
  97. package/src/configs/rule-configs.js +96 -0
  98. package/src/configs/rule-configs.js.map +1 -0
  99. package/src/core/ai-type-context.d.ts +36 -0
  100. package/src/core/ai-type-context.js +45 -0
  101. package/src/core/ai-type-context.js.map +1 -0
  102. package/src/core/decision-log.d.ts +190 -0
  103. package/src/core/decision-log.js +409 -0
  104. package/src/core/decision-log.js.map +1 -0
  105. package/src/core/excluded-path-escape.d.ts +101 -0
  106. package/src/core/excluded-path-escape.js +236 -0
  107. package/src/core/excluded-path-escape.js.map +1 -0
  108. package/src/core/force-to-root.d.ts +32 -0
  109. package/src/core/force-to-root.js +60 -0
  110. package/src/core/force-to-root.js.map +1 -0
  111. package/src/core/guard-index-doc.d.ts +63 -0
  112. package/src/core/guard-index-doc.js +172 -0
  113. package/src/core/guard-index-doc.js.map +1 -0
  114. package/src/core/instruct-ai-writer.d.ts +1 -0
  115. package/src/core/instruct-ai-writer.js +6 -0
  116. package/src/core/instruct-ai-writer.js.map +1 -0
  117. package/src/core/l0-matrix.d.ts +102 -0
  118. package/src/core/l0-matrix.js +357 -0
  119. package/src/core/l0-matrix.js.map +1 -0
  120. package/src/core/l0-tooling-doc.d.ts +45 -0
  121. package/src/core/l0-tooling-doc.js +258 -0
  122. package/src/core/l0-tooling-doc.js.map +1 -0
  123. package/src/core/l1-doc.d.ts +7 -0
  124. package/src/core/l1-doc.js +340 -0
  125. package/src/core/l1-doc.js.map +1 -0
  126. package/src/core/l1-matrix-doc.d.ts +31 -0
  127. package/src/core/l1-matrix-doc.js +111 -0
  128. package/src/core/l1-matrix-doc.js.map +1 -0
  129. package/src/core/l1-rows.d.ts +167 -0
  130. package/src/core/l1-rows.js +262 -0
  131. package/src/core/l1-rows.js.map +1 -0
  132. package/src/core/l2-doc.d.ts +7 -0
  133. package/src/core/l2-doc.js +385 -0
  134. package/src/core/l2-doc.js.map +1 -0
  135. package/src/core/l2-matrix-doc.d.ts +23 -0
  136. package/src/core/l2-matrix-doc.js +72 -0
  137. package/src/core/l2-matrix-doc.js.map +1 -0
  138. package/src/core/l2-row.d.ts +54 -0
  139. package/src/core/l2-row.js +75 -0
  140. package/src/core/l2-row.js.map +1 -0
  141. package/src/core/l2-rows.d.ts +56 -0
  142. package/src/core/l2-rows.js +272 -0
  143. package/src/core/l2-rows.js.map +1 -0
  144. package/src/core/load-rules.d.ts +9 -0
  145. package/src/core/load-rules.js +65 -0
  146. package/src/core/load-rules.js.map +1 -0
  147. package/src/core/log-stream.d.ts +117 -0
  148. package/src/core/log-stream.js +156 -0
  149. package/src/core/log-stream.js.map +1 -0
  150. package/src/core/log-streams.d.ts +48 -0
  151. package/src/core/log-streams.js +55 -0
  152. package/src/core/log-streams.js.map +1 -0
  153. package/src/core/log-target.d.ts +21 -0
  154. package/src/core/log-target.js +29 -0
  155. package/src/core/log-target.js.map +1 -0
  156. package/src/core/main-sync-log.d.ts +16 -0
  157. package/src/core/main-sync-log.js +108 -0
  158. package/src/core/main-sync-log.js.map +1 -0
  159. package/src/core/main-sync-refresh.d.ts +39 -0
  160. package/src/core/main-sync-refresh.js +96 -0
  161. package/src/core/main-sync-refresh.js.map +1 -0
  162. package/src/core/main-sync-timeout.d.ts +33 -0
  163. package/src/core/main-sync-timeout.js +95 -0
  164. package/src/core/main-sync-timeout.js.map +1 -0
  165. package/src/core/matrix-cures.d.ts +12 -0
  166. package/src/core/matrix-cures.js +56 -0
  167. package/src/core/matrix-cures.js.map +1 -0
  168. package/src/core/missing-directory.d.ts +38 -0
  169. package/src/core/missing-directory.js +66 -0
  170. package/src/core/missing-directory.js.map +1 -0
  171. package/src/core/read-only-inspection.d.ts +34 -0
  172. package/src/core/read-only-inspection.js +88 -0
  173. package/src/core/read-only-inspection.js.map +1 -0
  174. package/src/core/rejection-log.d.ts +9 -0
  175. package/src/core/rejection-log.js +262 -0
  176. package/src/core/rejection-log.js.map +1 -0
  177. package/src/core/rules/branch-creation-guard.d.ts +113 -0
  178. package/src/core/rules/branch-creation-guard.js +425 -0
  179. package/src/core/rules/branch-creation-guard.js.map +1 -0
  180. package/src/core/rules/branch-switch-scan.d.ts +43 -0
  181. package/src/core/rules/branch-switch-scan.js +132 -0
  182. package/src/core/rules/branch-switch-scan.js.map +1 -0
  183. package/src/core/rules/build-output-pipe-guard.d.ts +56 -0
  184. package/src/core/rules/build-output-pipe-guard.js +120 -0
  185. package/src/core/rules/build-output-pipe-guard.js.map +1 -0
  186. package/src/core/rules/build-output-pipe-scan.d.ts +47 -0
  187. package/src/core/rules/build-output-pipe-scan.js +84 -0
  188. package/src/core/rules/build-output-pipe-scan.js.map +1 -0
  189. package/src/core/rules/cap-remedies.d.ts +39 -0
  190. package/src/core/rules/cap-remedies.js +59 -0
  191. package/src/core/rules/cap-remedies.js.map +1 -0
  192. package/src/core/rules/commit-message-substitution-guard.d.ts +72 -0
  193. package/src/core/rules/commit-message-substitution-guard.js +134 -0
  194. package/src/core/rules/commit-message-substitution-guard.js.map +1 -0
  195. package/src/core/rules/commit-message-substitution-scan.d.ts +42 -0
  196. package/src/core/rules/commit-message-substitution-scan.js +145 -0
  197. package/src/core/rules/commit-message-substitution-scan.js.map +1 -0
  198. package/src/core/rules/content-read-scan.d.ts +76 -0
  199. package/src/core/rules/content-read-scan.js +176 -0
  200. package/src/core/rules/content-read-scan.js.map +1 -0
  201. package/src/core/rules/cure-prefix-scan.d.ts +64 -0
  202. package/src/core/rules/cure-prefix-scan.js +133 -0
  203. package/src/core/rules/cure-prefix-scan.js.map +1 -0
  204. package/src/core/rules/feature-branch-guard.d.ts +121 -0
  205. package/src/core/rules/feature-branch-guard.js +327 -0
  206. package/src/core/rules/feature-branch-guard.js.map +1 -0
  207. package/src/core/rules/index.d.ts +1 -0
  208. package/src/core/rules/index.js +5 -0
  209. package/src/core/rules/index.js.map +1 -0
  210. package/src/core/rules/judged-tree.d.ts +66 -0
  211. package/src/core/rules/judged-tree.js +97 -0
  212. package/src/core/rules/judged-tree.js.map +1 -0
  213. package/src/core/rules/main-freshness.d.ts +37 -0
  214. package/src/core/rules/main-freshness.js +61 -0
  215. package/src/core/rules/main-freshness.js.map +1 -0
  216. package/src/core/rules/merge-in-progress-guard.d.ts +17 -0
  217. package/src/core/rules/merge-in-progress-guard.js +124 -0
  218. package/src/core/rules/merge-in-progress-guard.js.map +1 -0
  219. package/src/core/rules/merged-branch-bash-guard.d.ts +62 -0
  220. package/src/core/rules/merged-branch-bash-guard.js +171 -0
  221. package/src/core/rules/merged-branch-bash-guard.js.map +1 -0
  222. package/src/core/rules/merged-branch-message.d.ts +59 -0
  223. package/src/core/rules/merged-branch-message.js +137 -0
  224. package/src/core/rules/merged-branch-message.js.map +1 -0
  225. package/src/core/rules/pr-creation-or-push-guard.d.ts +26 -0
  226. package/src/core/rules/pr-creation-or-push-guard.js +150 -0
  227. package/src/core/rules/pr-creation-or-push-guard.js.map +1 -0
  228. package/src/core/rules/pr-merge-guard.d.ts +36 -0
  229. package/src/core/rules/pr-merge-guard.js +87 -0
  230. package/src/core/rules/pr-merge-guard.js.map +1 -0
  231. package/src/core/rules/read-stale-guard.d.ts +136 -0
  232. package/src/core/rules/read-stale-guard.js +328 -0
  233. package/src/core/rules/read-stale-guard.js.map +1 -0
  234. package/src/core/rules/recovery-allowlist.d.ts +49 -0
  235. package/src/core/rules/recovery-allowlist.js +187 -0
  236. package/src/core/rules/recovery-allowlist.js.map +1 -0
  237. package/src/core/rules/redirect-how-to-merge-main.d.ts +16 -0
  238. package/src/core/rules/redirect-how-to-merge-main.js +159 -0
  239. package/src/core/rules/redirect-how-to-merge-main.js.map +1 -0
  240. package/src/core/rules/stale-main-bash-guard.d.ts +198 -0
  241. package/src/core/rules/stale-main-bash-guard.js +363 -0
  242. package/src/core/rules/stale-main-bash-guard.js.map +1 -0
  243. package/src/core/rules/stale-main-message.d.ts +62 -0
  244. package/src/core/rules/stale-main-message.js +102 -0
  245. package/src/core/rules/stale-main-message.js.map +1 -0
  246. package/src/core/rules/tree-recovery.d.ts +92 -0
  247. package/src/core/rules/tree-recovery.js +165 -0
  248. package/src/core/rules/tree-recovery.js.map +1 -0
  249. package/src/core/rules/wait-spin-guard.d.ts +128 -0
  250. package/src/core/rules/wait-spin-guard.js +211 -0
  251. package/src/core/rules/wait-spin-guard.js.map +1 -0
  252. package/src/core/rules/wait-spin-scan.d.ts +118 -0
  253. package/src/core/rules/wait-spin-scan.js +203 -0
  254. package/src/core/rules/wait-spin-scan.js.map +1 -0
  255. package/src/core/rules/whole-repo-build-guard.d.ts +125 -0
  256. package/src/core/rules/whole-repo-build-guard.js +257 -0
  257. package/src/core/rules/whole-repo-build-guard.js.map +1 -0
  258. package/src/core/rules/whole-repo-build-scan.d.ts +28 -0
  259. package/src/core/rules/whole-repo-build-scan.js +198 -0
  260. package/src/core/rules/whole-repo-build-scan.js.map +1 -0
  261. package/src/core/runner.d.ts +19 -0
  262. package/src/core/runner.js +482 -0
  263. package/src/core/runner.js.map +1 -0
  264. package/src/core/session-call-history.d.ts +44 -0
  265. package/src/core/session-call-history.js +79 -0
  266. package/src/core/session-call-history.js.map +1 -0
  267. package/src/core/sync-main.d.ts +46 -0
  268. package/src/core/sync-main.js +176 -0
  269. package/src/core/sync-main.js.map +1 -0
  270. package/src/core/version-sync.d.ts +219 -0
  271. package/src/core/version-sync.js +558 -0
  272. package/src/core/version-sync.js.map +1 -0
  273. package/src/core/webpieces-versions.d.ts +98 -0
  274. package/src/core/webpieces-versions.js +206 -0
  275. package/src/core/webpieces-versions.js.map +1 -0
  276. package/src/core/workflow-hook-rules.d.ts +5 -0
  277. package/src/core/workflow-hook-rules.js +15 -0
  278. package/src/core/workflow-hook-rules.js.map +1 -0
  279. package/src/index.d.ts +11 -0
  280. package/src/index.js +28 -0
  281. package/src/index.js.map +1 -0
  282. package/src/policy-keys.d.ts +2 -0
  283. package/src/policy-keys.js +6 -0
  284. package/src/policy-keys.js.map +1 -0
  285. package/src/rule-migrations.d.ts +3 -0
  286. package/src/rule-migrations.js +22 -0
  287. package/src/rule-migrations.js.map +1 -0
  288. package/src/rule-pack.d.ts +2 -0
  289. package/src/rule-pack.js +20 -0
  290. package/src/rule-pack.js.map +1 -0
  291. package/src/rule-settings.d.ts +5 -0
  292. package/src/rule-settings.js +31 -0
  293. package/src/rule-settings.js.map +1 -0
  294. package/src/safeguard-catalog.d.ts +3 -0
  295. package/src/safeguard-catalog.js +16 -0
  296. package/src/safeguard-catalog.js.map +1 -0
  297. package/templates/ai-hook.sh +497 -0
  298. package/templates/claude-settings-hook.json +28 -0
  299. package/templates/webpieces-reviewer.md +60 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guard-index-doc.js","sourceRoot":"","sources":["../../../../../../packages/tooling/agent-workflow-rules/src/core/guard-index-doc.ts"],"names":[],"mappings":";AAAA,8EAA8E;AAC9E,qFAAqF;AACrF,EAAE;AACF,mGAAmG;AACnG,sGAAsG;AACtG,sGAAsG;AACtG,sGAAsG;AACtG,uGAAuG;AACvG,8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AAiE;YACjE,EAAE;SACL,CAAC;IACN,CAAC;IAEO,UAAU;QACd,OAAO;YACH,eAAe;YACf,EAAE;YACF,+DAA+D;YAC/D,mBAAmB;YACnB,GAAG,wBAAgB,CAAC,GAAG,CAAC,CAAC,KAAsB,EAAU,EAAE,CACvD,OAAO,KAAK,CAAC,KAAK,QAAQ,KAAK,CAAC,IAAI,MAAM,KAAK,CAAC,OAAO,EAAE,OAAO,KAAK,CAAC,KAAK,KAAK,KAAK,CAAC,GAAG,KAAK,CAAC;YACnG,EAAE;SACL,CAAC;IACN,CAAC;IAED,oGAAoG;IACpG,mGAAmG;IAC3F,mBAAmB;QACvB,OAAO,MAAM,CAAC,wBAAgB,CAAC,MAAM,CAAC,CAAC,KAAsB,EAAW,EAAE,CACtE,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IAC1D,CAAC;CACJ;AA9FD,sCA8FC","sourcesContent":["// ---------------------------------------------------------------------------\n// GUARD_MATRIX.md's generation-status block, rendered from the one array that knows.\n//\n// THE BUG THIS FIXES IS IN THE FILE ITSELF. GUARD_MATRIX.md is the INDEX — the page that tells you\n// which layer docs are generated and which are hand-written — and it was hand-written, so it went out\n// of date about generation. It ended up contradicting itself inside ten lines: a blockquote asserting\n// \"L1's table ... generated\" and \"EVERY REMAINING LAYER FILE IS HAND-WRITTEN TODAY\", directly above a\n// table listing L2 as generated and byte-locked. Both were once true; L2 was converted and only one of\n// the two places was updated.\n//\n// A doc that describes generation is exactly the doc that must be generated, because it is the one\n// place a reader goes to find out whether to trust the others. So the STATUS is data here, the block\n// between the markers is spliced from it, and a spec byte-locks the result — the same treatment\n// guards/L0-tooling.md gets, and for the same reason: everything outside the markers stays\n// hand-written prose that the splice preserves byte for byte.\n//\n// WHAT IS DELIBERATELY NOT GENERATED: the rest of GUARD_MATRIX.md — the action codebook, the launch\n// guarantee, the two rules that constrain guard changes. Those are prose about DESIGN, not facts about\n// the code, and a generator that owns them would be inventing a schema for essays.\n// ---------------------------------------------------------------------------\n\n/** Opening marker of the generated block, as it appears in GUARD_MATRIX.md. */\nexport const GUARD_INDEX_BEGIN = '<!-- BEGIN GENERATED — GuardIndexDoc.render() in agent-workflow-rules/src/core/guard-index-doc.ts; run `pnpm guards:generate` -->';\n\n/** Closing marker. Everything between the two is machine-owned; everything outside is prose. */\nexport const GUARD_INDEX_END = '<!-- END GENERATED — hand-written prose resumes here -->';\n\n/** How much of a layer's doc is rendered from code. Data-only → a class, per CLAUDE.md. */\nexport class LayerGeneration {\n // eslint-disable-next-line @typescript-eslint/max-params -- the five cells of one status row\n constructor(\n /** `L0`, `L1`, … as the doc prints it. */\n readonly layer: string,\n /** The question this layer answers, for the layer table. */\n readonly goal: string,\n /** The `webpieces.config.json` key, or '' when the layer has none on purpose. */\n readonly configKey: string,\n /** Repo-relative path of the layer's doc. */\n readonly doc: string,\n /** The array the doc is rendered FROM, or '' when nothing is generated yet. */\n readonly source: string,\n /** The status cell, verbatim. */\n readonly status: string,\n ) {}\n\n /** The config-key cell — layers with no key say so, and say it is deliberate. */\n keyCell(): string {\n return this.configKey === '' ? '*(none — deliberate, see below)*' : `\\`${this.configKey}\\``;\n }\n\n sourceCell(): string {\n return this.source === '' ? '—' : `\\`${this.source}\\``;\n }\n}\n\n/**\n * THE FIVE LAYERS, and how much of each doc is machine-owned.\n *\n * Adding a layer, or converting one to generated, is an edit HERE and nowhere else — the index table,\n * the layer table and the one-command sentence all render from this array, so they cannot disagree\n * with each other the way the hand-written version did.\n */\nexport const LAYER_GENERATION: readonly LayerGeneration[] = [\n new LayerGeneration('L0', 'Is webpieces itself trustworthy right now?', '', 'guards/L0-tooling.md',\n 'L0_FAULTS + L0_ALLOWLIST',\n '**PARTLY generated, byte-locked** — only the block between the `L0_DOC_BEGIN` / `L0_DOC_END` markers; every byte outside it is hand-written prose the splice preserves'),\n new LayerGeneration('L1', 'Is this call ours to judge, are the versions in sync, and is git run from the root?', '', 'guards/L1-location.md',\n 'L1_ROWS',\n '**generated whole, byte-locked** — table, use cases and cures all render from the array the runner dispatches on'),\n new LayerGeneration('L2', 'May I work here, and is what I read current?', 'branch-state-guard', 'guards/L2-branch-state.md',\n 'L2_ROWS',\n '**generated whole, byte-locked** — table, use cases and the \"Not done\" gaps all render from the rows'),\n new LayerGeneration('L3', 'Which dead branches and worktrees get reaped?', 'branch-creation-guard', 'guards/L3-branch-cleanup.md',\n '',\n '**hand-written** — not yet converted, so it CAN go out of date; the code is the authority'),\n new LayerGeneration('L4', 'Does every merge and PR go through the gated flow?', 'pr-lifecycle-guard', 'guards/L4-pr-lifecycle.md',\n '',\n '**hand-written** — not yet converted, so it CAN go out of date; the code is the authority'),\n];\n\n/**\n * The generated block of GUARD_MATRIX.md, and the splice that puts it there.\n *\n * Same class shape as L0ToolingDoc — renderer, extractor and splicer as one unit, driven by one spec.\n */\nexport class GuardIndexDoc {\n /** The whole generated block, WITHOUT the markers — those belong to the file, not the renderer. */\n render(): string {\n return [\n ...this.preamble(),\n ...this.statusTable(),\n ...this.layerTable(),\n ].join('\\n');\n }\n\n /**\n * The generated text of `doc`, exactly as committed. Throws when a marker is missing or doubled —\n * a silently-unspliced doc is the drift this arrangement exists to end.\n */\n extract(doc: string): string {\n const opens = doc.split(GUARD_INDEX_BEGIN).length - 1;\n const closes = doc.split(GUARD_INDEX_END).length - 1;\n if (opens !== 1 || closes !== 1) {\n throw new Error(`GUARD_MATRIX.md must carry exactly one BEGIN/END marker pair, found ${String(opens)}/${String(closes)}`);\n }\n const afterBegin = doc.slice(doc.indexOf(GUARD_INDEX_BEGIN) + GUARD_INDEX_BEGIN.length);\n return afterBegin.slice(0, afterBegin.indexOf(GUARD_INDEX_END)).replace(/^\\n/, '').replace(/\\n$/, '');\n }\n\n /** `doc` with the generated block replaced by today's render. Preserves every byte outside it. */\n splice(doc: string): string {\n const head = doc.slice(0, doc.indexOf(GUARD_INDEX_BEGIN) + GUARD_INDEX_BEGIN.length);\n const tail = doc.slice(doc.indexOf(GUARD_INDEX_END));\n // extract() is called for its VALIDATION — one marker pair — before anything is rewritten.\n this.extract(doc);\n return `${head}\\n${this.render()}\\n${tail}`;\n }\n\n private preamble(): string[] {\n return [\n '> **GENERATED — do not hand-edit between the markers.** Rendered by `GuardIndexDoc.render()`',\n '> from `LAYER_GENERATION` (`agent-workflow-rules/src/core/guard-index-doc.ts`); regenerate with',\n '> `pnpm guards:generate`. A spec byte-locks it.',\n '>',\n '> This block used to be prose, and it drifted about the one subject it exists to report: it',\n '> claimed every layer but L0 and L1 was hand-written, ten lines above a table listing L2 as',\n '> generated. The index that tells you which docs to trust is the last place that can afford',\n '> to be wrong, so it is data now.',\n '',\n '## Generation status',\n '',\n ];\n }\n\n private statusTable(): string[] {\n return [\n '| layer | source of truth | doc |',\n '|---|---|---|',\n ...LAYER_GENERATION.map((entry: LayerGeneration): string =>\n `| ${entry.layer} | ${entry.sourceCell()} | ${entry.status} |`),\n '',\n `One command regenerates every generated artifact: \\`pnpm guards:generate\\`. It rewrites the`,\n `${this.generatedWholeCount()} whole-file docs, SPLICES the marked blocks in L0's doc and in this file, writes the`,\n 'AI-facing copy of the L2 matrix, and renders the POSIX-sh shim template.',\n '',\n 'For a WHOLE-file layer the split is: **row data** lives in the array, **prose** lives as literal',\n 'lines inside the renderer, there is no third place, and the byte-lock spec fails on any hand',\n 'edit. **The two SPLICED files are the exception**: everything outside their marker pairs is',\n 'hand-written prose the splice preserves byte for byte, and the spec deliberately permits you to',\n 'edit it.',\n '',\n '**L1 and L2 differ in one way worth knowing.** L1 DISPATCHES from its rows — the runner takes the',\n 'first matching row and switches on its `blockId`, so deleting a row deletes a block. L2\\'s four',\n 'guard classes each own their own ladder (they diverge in polarity, quantifier and empty-command',\n 'handling, deliberately), so L2 joins to its rows by REASON instead: every decision-log line carries',\n '`row=<n>` derived from the reason the guard logged, plus the `cure=` that row prescribed, and a spec',\n 'asserts the reason map is exhaustive against the guard sources.',\n '',\n ];\n }\n\n private layerTable(): string[] {\n return [\n '## The layers',\n '',\n '| layer | goal — the question it answers | config key | doc |',\n '|---|---|---|---|',\n ...LAYER_GENERATION.map((entry: LayerGeneration): string =>\n `| **${entry.layer}** | ${entry.goal} | ${entry.keyCell()} | [${entry.layer}](${entry.doc}) |`),\n '',\n ];\n }\n\n // Rendered into the prose so the sentence cannot claim a count the array disagrees with — the exact\n // failure mode this file is fixing (\"One command regenerates all three\" survived L2's conversion).\n private generatedWholeCount(): string {\n return String(LAYER_GENERATION.filter((entry: LayerGeneration): boolean =>\n entry.status.includes('generated whole')).length);\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ export { writeTemplateIfMissing } from '@webpieces/rules-config';
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.writeTemplateIfMissing = void 0;
4
+ var rules_config_1 = require("@webpieces/rules-config");
5
+ Object.defineProperty(exports, "writeTemplateIfMissing", { enumerable: true, get: function () { return rules_config_1.writeTemplateIfMissing; } });
6
+ //# sourceMappingURL=instruct-ai-writer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instruct-ai-writer.js","sourceRoot":"","sources":["../../../../../../packages/tooling/agent-workflow-rules/src/core/instruct-ai-writer.ts"],"names":[],"mappings":";;;AAAA,wDAAiE;AAAxD,sHAAA,sBAAsB,OAAA","sourcesContent":["export { writeTemplateIfMissing } from '@webpieces/rules-config';\n"]}
@@ -0,0 +1,102 @@
1
+ import { L0Call } from '../bin/shim';
2
+ import { L0FaultCode } from '@webpieces/rules-config';
3
+ /**
4
+ * The doc L0's deny messages point at. Lives in @webpieces/rules-config/templates alongside the others,
5
+ * and is written to <root>/.webpieces/instruct-ai/ lazily, only on an L0 BLOCK.
6
+ *
7
+ * That generated doc is the AUTHORITY for the fault table and the allowlist (same arrays, cannot
8
+ * drift). guards/L0-tooling.md is the hand-written companion: it adds L0's evaluation
9
+ * ORDER, the use cases and the known gaps, and it documents L1, none of which are rendered from code.
10
+ * Change L0_FAULTS or L0_ALLOWLIST and the generated doc follows automatically — guards/L0-tooling.md does
11
+ * not, so update it in the same PR.
12
+ */
13
+ export { GUARD_MATRIX_DOC, writeGuardMatrixDoc, guardMatrixPointer } from '@webpieces/rules-config';
14
+ /**
15
+ * One CURE for a fault: the exact call, plus the `mention` that must appear in that fault's deny text.
16
+ *
17
+ * Both halves are asserted (l0-matrix.spec.ts): the call must be accepted by isAllowed(), and the deny
18
+ * message must actually name it. That pairing is the anti-deadlock invariant — a message that
19
+ * prescribes a command the allowlist rejects is exactly the shape of the three deadlocks
20
+ * `.claude/rules/*.md` records, and it is how the dead `wp-setup-ai-hooks` bin in the config-missing text was caught.
21
+ */
22
+ export declare class L0Cure {
23
+ readonly mention: string;
24
+ readonly call: L0Call;
25
+ /**
26
+ * The one to reach for first when a fault has several. Exactly one cure per fault carries it,
27
+ * so the rendered Fix section never asks the reader to choose between equals.
28
+ */
29
+ readonly preferred: boolean;
30
+ /**
31
+ * WHEN to pick this cure over its siblings — the sentence that makes a list of commands
32
+ * actionable instead of a menu ("when the PIN is the stale side", not "an alternative").
33
+ */
34
+ readonly discriminator: string;
35
+ constructor(mention: string, call: L0Call,
36
+ /**
37
+ * The one to reach for first when a fault has several. Exactly one cure per fault carries it,
38
+ * so the rendered Fix section never asks the reader to choose between equals.
39
+ */
40
+ preferred: boolean,
41
+ /**
42
+ * WHEN to pick this cure over its siblings — the sentence that makes a list of commands
43
+ * actionable instead of a menu ("when the PIN is the stale side", not "an alternative").
44
+ */
45
+ discriminator: string);
46
+ /** A Bash cure renders as a literal command; a tool-shaped one renders as the edit it stands for. */
47
+ isCommand(): boolean;
48
+ }
49
+ /** One L0 fault. Data-only → a class, per CLAUDE.md. */
50
+ export declare class L0Fault {
51
+ /**
52
+ * The codebook's letter — typed as the UNION of every declared code, not `string`, so
53
+ * `L0_FAULT_NAMES[code]` is total and neither this module nor the deny builders need a
54
+ * `?? 'unknown'` fallback. A fault added without a name fails to compile.
55
+ */
56
+ readonly code: L0FaultCode;
57
+ readonly name: string;
58
+ readonly detectedBy: string;
59
+ readonly enforcedIn: string;
60
+ readonly cures: readonly L0Cure[];
61
+ /**
62
+ * The artifact carrying this fault's deny text. For S/C/Y that is the deny string itself; for
63
+ * D/X/U/K the text is built in POSIX sh inside the rendered shim, so it is the rendered shim —
64
+ * the same bytes the consumer runs, which is what the mention assertion needs to search.
65
+ */
66
+ readonly denyText: string;
67
+ constructor(
68
+ /**
69
+ * The codebook's letter — typed as the UNION of every declared code, not `string`, so
70
+ * `L0_FAULT_NAMES[code]` is total and neither this module nor the deny builders need a
71
+ * `?? 'unknown'` fallback. A fault added without a name fails to compile.
72
+ */
73
+ code: L0FaultCode, name: string, detectedBy: string, enforcedIn: string, cures: readonly L0Cure[],
74
+ /**
75
+ * The artifact carrying this fault's deny text. For S/C/Y that is the deny string itself; for
76
+ * D/X/U/K the text is built in POSIX sh inside the rendered shim, so it is the rendered shim —
77
+ * the same bytes the consumer runs, which is what the mention assertion needs to search.
78
+ */
79
+ denyText: string);
80
+ }
81
+ /**
82
+ * THE L0 faults, in first-match-wins order. D/X/U/K are decided in POSIX sh BEFORE the bin runs (a
83
+ * stale, missing or broken validator cannot be trusted to validate itself); S/C/Y are decided inside
84
+ * the bin, in JS. One model, two enforcement points.
85
+ */
86
+ export declare const L0_FAULTS: readonly L0Fault[];
87
+ /**
88
+ * Render webpieces.guard-matrix.md from L0_FAULTS + L0_ALLOWLIST.
89
+ *
90
+ * A unit test locks the committed template byte-identical to this output, the same way
91
+ * templates/ai-hook.sh is locked to renderShim(). That is what makes the doc assertable instead of
92
+ * aspirational: the table in the doc IS the array the guard consults.
93
+ */
94
+ export declare function renderGuardMatrixDoc(): string;
95
+ /**
96
+ * Drop the matrix doc where the AI can read it, and return its absolute path ('' if it could not be
97
+ * written). Called from the L0 BLOCK path so the deny can say `READ <path>`.
98
+ *
99
+ * Best-effort by design: this runs while the tree is already known-broken, and a missing template (an
100
+ * @webpieces/rules-config older than this package) must degrade the deny message, never replace it
101
+ * with a crash.
102
+ */
@@ -0,0 +1,357 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.L0_FAULTS = exports.L0Fault = exports.L0Cure = exports.guardMatrixPointer = exports.writeGuardMatrixDoc = exports.GUARD_MATRIX_DOC = void 0;
4
+ exports.renderGuardMatrixDoc = renderGuardMatrixDoc;
5
+ const rules_config_1 = require("@webpieces/rules-config");
6
+ const rules_config_2 = require("@webpieces/rules-config");
7
+ const shim_1 = require("../bin/shim");
8
+ const rules_config_3 = require("@webpieces/rules-config");
9
+ const hook_registration_1 = require("../bin/hook-registration");
10
+ const shim_deny_reason_1 = require("../bin/shim-deny-reason");
11
+ const rules_config_4 = require("@webpieces/rules-config");
12
+ // ---------------------------------------------------------------------------
13
+ // L0 — the TOOLING-INTEGRITY layer, as data.
14
+ //
15
+ // L0 is the outermost guard: it blocks work while node_modules, the committed shim, or
16
+ // webpieces.config.json are in a state that makes every OTHER guard untrustworthy. Its faults are
17
+ // enumerated in L0_FAULTS below and — drawn as a decision matrix — have NO genuine second dimension:
18
+ //
19
+ // fault present AND call not on the allowlist -> BLOCK(messageFor(fault))
20
+ //
21
+ // so the only thing that varies per fault is the MESSAGE. This module holds the fault table and
22
+ // renders it, together with L0_ALLOWLIST (../bin/shim), into webpieces.guard-matrix.md — the doc the
23
+ // deny messages point the AI at. Doc and code come from the SAME arrays, so they cannot drift.
24
+ // ---------------------------------------------------------------------------
25
+ /**
26
+ * The doc L0's deny messages point at. Lives in @webpieces/rules-config/templates alongside the others,
27
+ * and is written to <root>/.webpieces/instruct-ai/ lazily, only on an L0 BLOCK.
28
+ *
29
+ * That generated doc is the AUTHORITY for the fault table and the allowlist (same arrays, cannot
30
+ * drift). guards/L0-tooling.md is the hand-written companion: it adds L0's evaluation
31
+ * ORDER, the use cases and the known gaps, and it documents L1, none of which are rendered from code.
32
+ * Change L0_FAULTS or L0_ALLOWLIST and the generated doc follows automatically — guards/L0-tooling.md does
33
+ * not, so update it in the same PR.
34
+ */
35
+ var rules_config_5 = require("@webpieces/rules-config");
36
+ Object.defineProperty(exports, "GUARD_MATRIX_DOC", { enumerable: true, get: function () { return rules_config_5.GUARD_MATRIX_DOC; } });
37
+ Object.defineProperty(exports, "writeGuardMatrixDoc", { enumerable: true, get: function () { return rules_config_5.writeGuardMatrixDoc; } });
38
+ Object.defineProperty(exports, "guardMatrixPointer", { enumerable: true, get: function () { return rules_config_5.guardMatrixPointer; } });
39
+ /**
40
+ * One CURE for a fault: the exact call, plus the `mention` that must appear in that fault's deny text.
41
+ *
42
+ * Both halves are asserted (l0-matrix.spec.ts): the call must be accepted by isAllowed(), and the deny
43
+ * message must actually name it. That pairing is the anti-deadlock invariant — a message that
44
+ * prescribes a command the allowlist rejects is exactly the shape of the three deadlocks
45
+ * `.claude/rules/*.md` records, and it is how the dead `wp-setup-ai-hooks` bin in the config-missing text was caught.
46
+ */
47
+ class L0Cure {
48
+ mention;
49
+ call;
50
+ preferred;
51
+ discriminator;
52
+ // eslint-disable-next-line @typescript-eslint/max-params
53
+ constructor(mention, call,
54
+ /**
55
+ * The one to reach for first when a fault has several. Exactly one cure per fault carries it,
56
+ * so the rendered Fix section never asks the reader to choose between equals.
57
+ */
58
+ preferred,
59
+ /**
60
+ * WHEN to pick this cure over its siblings — the sentence that makes a list of commands
61
+ * actionable instead of a menu ("when the PIN is the stale side", not "an alternative").
62
+ */
63
+ discriminator) {
64
+ this.mention = mention;
65
+ this.call = call;
66
+ this.preferred = preferred;
67
+ this.discriminator = discriminator;
68
+ }
69
+ /** A Bash cure renders as a literal command; a tool-shaped one renders as the edit it stands for. */
70
+ isCommand() {
71
+ return this.call.toolName === 'Bash';
72
+ }
73
+ }
74
+ exports.L0Cure = L0Cure;
75
+ /** One L0 fault. Data-only → a class, per CLAUDE.md. */
76
+ class L0Fault {
77
+ code;
78
+ name;
79
+ detectedBy;
80
+ enforcedIn;
81
+ cures;
82
+ denyText;
83
+ constructor(
84
+ /**
85
+ * The codebook's letter — typed as the UNION of every declared code, not `string`, so
86
+ * `L0_FAULT_NAMES[code]` is total and neither this module nor the deny builders need a
87
+ * `?? 'unknown'` fallback. A fault added without a name fails to compile.
88
+ */
89
+ code, name, detectedBy, enforcedIn, cures,
90
+ /**
91
+ * The artifact carrying this fault's deny text. For S/C/Y that is the deny string itself; for
92
+ * D/X/U/K the text is built in POSIX sh inside the rendered shim, so it is the rendered shim —
93
+ * the same bytes the consumer runs, which is what the mention assertion needs to search.
94
+ */
95
+ denyText) {
96
+ this.code = code;
97
+ this.name = name;
98
+ this.detectedBy = detectedBy;
99
+ this.enforcedIn = enforcedIn;
100
+ this.cures = cures;
101
+ this.denyText = denyText;
102
+ }
103
+ }
104
+ exports.L0Fault = L0Fault;
105
+ // The deny for fault C, and the ONLY message L0 has for a repo with no webpieces.config.json at all.
106
+ // Moved here from runner.ts so the fault table and the runner cannot state different cures.
107
+ //
108
+ // It used to name `./node_modules/.bin/wp-setup-ai-hooks` — a bin that HAS NOT EXISTED since it was
109
+ // renamed to wp-install-ai-hooks. So the one command this deny prescribed was (a) not installable and
110
+ // (b) not on the L0 allowlist in that spelling, i.e. the AI was handed a cure it could neither run nor
111
+ // get past the guard. Now it names the installer that actually seeds the config AND is entry 8 of the
112
+ // allowlist, and it says out loud that writing the config yourself is allowed through.
113
+ //
114
+ // ORDERING (2026-08-02): writing the file yourself now LEADS. The bare installer used to be OPTION 1,
115
+ // but it seeds the config and then PROMPTS twice for a hook target, which hangs a non-interactive
116
+ // agent. Writing the file is the one cure that always works, and it is the same cure every other config
117
+ // problem has (see the config-validation invariant in guards/L0-tooling.md): the validator reports every
118
+ // error at once, so the write/validate loop converges in a couple of passes.
119
+ // Writing/repairing the file yourself. PREFERRED for both config faults, per the config-validation
120
+ // invariant in guards/L0-tooling.md: every config problem cures to "make the file right", the validator
121
+ // reports all errors at once so the loop converges in a couple of passes, and allowlist entry 2 permits
122
+ // this edit unconditionally. (That section is the authority — do not restate its reasoning here.)
123
+ const CONFIG_WRITE_CURE = new L0Cure(rules_config_2.CONFIG_FILENAME, new shim_1.L0Call('Edit', '', `/repo/${rules_config_2.CONFIG_FILENAME}`), true, 'this fault fires at all — it is the only cure that needs no other tool, and it is never denied');
124
+ // Cure calls are spelled exactly as the deny messages spell them, so the mention assertion is a real
125
+ // string search rather than a paraphrase.
126
+ // webpieces-disable no-function-outside-class -- pure constructor helper for the L0_FAULTS literal below, in this data module
127
+ function bashCure(command, preferred, discriminator) {
128
+ return new L0Cure(command, new shim_1.L0Call('Bash', command, ''), preferred, discriminator);
129
+ }
130
+ /**
131
+ * THE L0 faults, in first-match-wins order. D/X/U/K are decided in POSIX sh BEFORE the bin runs (a
132
+ * stale, missing or broken validator cannot be trusted to validate itself); S/C/Y are decided inside
133
+ * the bin, in JS. One model, two enforcement points.
134
+ */
135
+ exports.L0_FAULTS = [
136
+ new L0Fault(rules_config_4.L0_FAULT_DRIFT, 'version drift — root package.json pin != installed version', 'sh, before the bin runs', 'sh', [
137
+ // `pnpm install` clears D in BOTH directions — it makes installed == pin by definition — so
138
+ // it is always the preferred cure. The direction only decides whether the PIN is the version
139
+ // you WANT, which is what the second cure is for.
140
+ bashCure('pnpm install', true, 'node_modules is OLDER than the pin, OR you are on a feature branch and want YOUR '
141
+ + 'branch pin (usually the case) — it always clears the drift'),
142
+ // The on-main sync is spelled `git checkout main && git pull origin main` and NOT `git pull`:
143
+ // a raw pull on a FEATURE branch merges main into it and destroys the fork point, so it is
144
+ // no longer on the L0 allowlist at all (see CHECKOUT_MAIN_PULL_BODY_ERE). This spelling ends
145
+ // ON main, which is why it is safe from any branch — and it is a no-op checkout when you are
146
+ // already there.
147
+ //
148
+ // And it is RAW GIT on purpose, where the workflow guards now say `pnpm wp-sync-main`
149
+ // instead. The fault being cured here is `node_modules` disagreeing with the pin, so
150
+ // `node_modules` is the untrustworthy thing — and every `pnpm wp-*` bin resolves through it.
151
+ // An L0 cure may never be a command that has to load the package it is repairing. See the
152
+ // long note on CHECKOUT_MAIN_PULL_BODY_ERE in bin/l0-allowlist.ts.
153
+ bashCure(shim_1.CHECKOUT_MAIN_PULL_CMD, false, 'node_modules is NEWER than the pin AND you are on main — the PIN is the stale side, so '
154
+ + 'sync first and install second; a bare install would downgrade you'),
155
+ ], (0, shim_1.renderShim)()),
156
+ new L0Fault(rules_config_4.L0_FAULT_BIN_MISSING, 'guard bin missing (fresh clone / new worktree / package removed)', 'sh, before the bin runs', 'sh', [bashCure('pnpm install', true, 'this fault fires at all — nothing is installed in THIS tree, and a new git worktree '
157
+ + 'copies no node_modules')], (0, shim_1.renderShim)()),
158
+ // U is X with the ONE input that inverts X's cure, which is why it is a separate fault and not a
159
+ // sentence inside X's message: a BARE `pnpm install` is not a weaker fix here, it is a PROVABLE
160
+ // no-op, and an agent that trusts the X text will run it until it gives up. See the ADD_HOOK_PKG
161
+ // entry in l0-allowlist.ts for the incident.
162
+ //
163
+ // The ORDER of these three is the correction bought by a second incident. `pnpm add` used to be the
164
+ // preferred cure, and it is the one cure that CANNOT be committed: a direct root dependency on
165
+ // HOOK_PKG violates the umbrella rule (the root manifest depends on the umbrella ALONE), and the
166
+ // message never said to revert it — so it was followed, and the workaround landed in a real
167
+ // package.json. The package normally arrives WITH the umbrella, so a tree that is merely BEHIND is
168
+ // the common cause and syncing is the cure that leaves a committable tree. The add stays last,
169
+ // reachable, and explicitly labelled as a session unblock rather than a fix.
170
+ new L0Fault(rules_config_4.L0_FAULT_UNDECLARED, `guard bin missing AND ${shim_1.HOOK_PKG} is not declared in package.json`, 'sh, before the bin runs', 'sh', [
171
+ bashCure(shim_1.CHECKOUT_MAIN_PULL_CMD, true, `${shim_1.HOOK_PKG} arrives WITH the umbrella, so a tree that is behind explains this without `
172
+ + 'anything being mis-declared — sync first, then install'),
173
+ bashCure('pnpm install', false, 'the sync (or a raised catalog pin in ' + rules_config_3.WORKSPACE_MANIFEST + ', which is editable '
174
+ + 'while the block is up) gave the installer something new to do — a BARE install with '
175
+ + 'nothing changed reports "Lockfile is up to date" and leaves the tree as broken as it '
176
+ + 'found it'),
177
+ bashCure(shim_1.ADD_HOOK_PKG_CMD, false, 'nothing else worked and you need this session back — it is a session unblock, NOT a '
178
+ + `fix: revert it with 'pnpm remove ${shim_1.HOOK_PKG}' before committing, because a direct `
179
+ + 'root dependency on it violates the umbrella rule'),
180
+ ], (0, shim_1.renderShim)()),
181
+ new L0Fault(rules_config_4.L0_FAULT_BIN_BROKEN, 'guard bin present but CRASHED (exit code not 0 or 2 — corrupt node_modules)', 'sh, before the bin runs', 'sh', [bashCure(shim_1.RECOVERY_CMD, true, 'this fault fires at all — a BARE pnpm install SKIPS the corrupt package, because pnpm sees '
182
+ + 'the right version on disk and considers it installed; only the delete forces a rewrite')], (0, shim_1.renderShim)()),
183
+ // S covers the WHOLE managed hook surface, not just the shim: the committed ai-hook.sh, the
184
+ // .claude/settings.json entries that register them AND the managed `env` entry that pins the Bash
185
+ // cwd so the hooks resolve identically for every subagent. They only work as a set — a settings file left
186
+ // on a superseded form silently changes who governs, re-pinning every tree to the
187
+ // primary's release — and nothing validated the registration at all before it joined this fault.
188
+ new L0Fault(rules_config_4.L0_FAULT_SHIM_STALE, 'a webpieces-managed hook file, one of the harness hook registrations (.claude/settings.json, .codex/hooks.json) or the managed env entry does not match this release', 'the guard bin', 'JS', [
189
+ // wp-upgrade-shim leads because it is the ONLY cure that repairs EVERY managed surface, and
190
+ // it is still surgical: it rewrites ai-hook.sh, each harness's registration and the env entry
191
+ // and touches no config, and it imports only fs/path so it runs on a tree too broken to load
192
+ // the rule engine. The INSTALLER is deliberately NOT a cure here: it also migrates the config
193
+ // and prompts for a target twice, which hangs a non-interactive agent.
194
+ bashCure(shim_1.UPGRADE_SHIM_CMD, true, 'this fault fires at all — it is the only cure that repairs EVERY managed surface '
195
+ + '(ai-hook.sh, each harness hook registration, the anchoring of the neighbour hook '
196
+ + 'commands registered beside ours, and the Claude settings env entry), and it also '
197
+ + 'deletes the retired guarantee-root.sh and any entry still naming it, and it '
198
+ + 'touches no config; needs installed @webpieces/agent-workflow-rules 0.4.408 or newer'),
199
+ // 2026-07-21: the version gap below caused a real "command not found" deadlock.
200
+ bashCure(shim_1.RESTORE_SHIM_CMD, false, 'the installed @webpieces/agent-workflow-rules is OLDER than 0.4.408, so wp-upgrade-shim does '
201
+ + 'not exist yet — it is PARTIAL (it repairs ai-hook.sh and NOTHING else), so upgrade '
202
+ + '@webpieces afterwards and run Option 1 to finish'),
203
+ ],
204
+ // The SAMPLE deny renders EVERY managed surface, built from HARNESS_REGISTRATIONS rather than
205
+ // a hand-written trio — a doc that shows a three-surface deny while the guard can report four
206
+ // is exactly the drift this generated-doc arrangement exists to make impossible.
207
+ (0, shim_deny_reason_1.shimStaleDenyReason)('', '', [
208
+ shim_1.SHIM_MARKER,
209
+ ...hook_registration_1.HARNESS_REGISTRATIONS.flatMap((h) => [h.registrationSurface, h.neighbourSurface]),
210
+ hook_registration_1.ENV_SURFACE,
211
+ hook_registration_1.REVIEWER_AGENT_SURFACE,
212
+ ], false)),
213
+ new L0Fault(rules_config_4.L0_FAULT_CONFIG_MISSING, `${rules_config_2.CONFIG_FILENAME} missing`, 'the guard bin', 'JS', [
214
+ CONFIG_WRITE_CURE,
215
+ // Kept, but demoted: it seeds the file and then PROMPTS twice for a hook target.
216
+ bashCure(shim_1.INSTALL_HOOKS_CMD, false, 'you are at an INTERACTIVE terminal and can answer its two hook-target prompts'),
217
+ ], rules_config_1.CONFIG_MISSING_REPORT),
218
+ new L0Fault(rules_config_4.L0_FAULT_CONFIG_OUT_OF_SYNC, `a loaded rule has no ${rules_config_2.CONFIG_FILENAME} key`, 'the guard bin', 'JS', [CONFIG_WRITE_CURE], rules_config_1.CONFIG_OUT_OF_SYNC_HEADER),
219
+ ];
220
+ /**
221
+ * One fault's FIX section, rendered from its `cures` array — literal commands only, never prose.
222
+ *
223
+ * This is the half that used to live in hand-written docs and drift. The three fields of L0Cure map
224
+ * onto the three things a blocked reader needs and nothing else: WHAT to type (the call), WHETHER it is
225
+ * the default (preferred), and WHEN to pick a sibling instead (discriminator). A cure with no
226
+ * discriminator would render as a menu of equals, which is how an agent picks the wrong one.
227
+ */
228
+ // webpieces-disable no-function-outside-class -- pure string builder for renderGuardMatrixDoc below, beside the arrays it reads
229
+ function renderFixSection(fault) {
230
+ const options = fault.cures.map((cure, i) => {
231
+ // A Bash cure is the command verbatim; a tool-shaped one is the file it edits (allowlist entry 2).
232
+ const literal = cure.isCommand() ? `\`${cure.call.command}\`` : `edit \`${cure.mention}\` yourself`;
233
+ const label = cure.preferred ? `Option ${i + 1} (preferred)` : `Option ${i + 1}`;
234
+ return `- **${label}**: ${literal} ← pick this when ${cure.discriminator}`;
235
+ });
236
+ return [`### \`${fault.code}\` — ${fault.name}`, '', ...options, ''];
237
+ }
238
+ /**
239
+ * Render webpieces.guard-matrix.md from L0_FAULTS + L0_ALLOWLIST.
240
+ *
241
+ * A unit test locks the committed template byte-identical to this output, the same way
242
+ * templates/ai-hook.sh is locked to renderShim(). That is what makes the doc assertable instead of
243
+ * aspirational: the table in the doc IS the array the guard consults.
244
+ */
245
+ // webpieces-disable no-function-outside-class -- pure string builder over the two exported arrays, beside them in this module
246
+ function renderGuardMatrixDoc() {
247
+ return [
248
+ '# webpieces guard matrix — L0 (tooling integrity)',
249
+ '',
250
+ 'GENERATED from `L0_FAULTS` + `L0_ALLOWLIST` in `@webpieces/agent-workflow-rules`. Do not hand-edit —',
251
+ 'a unit test locks this file byte-identical to `renderGuardMatrixDoc()`, so the table below is',
252
+ 'the array the guard actually consults, not a description of it.',
253
+ '',
254
+ 'L0 is the OUTERMOST guard layer. It blocks work while `node_modules`, the committed shim, or',
255
+ '`webpieces.config.json` are in a state that makes every other guard untrustworthy. If you are',
256
+ 'reading this, one of the faults below fired and named this file.',
257
+ '',
258
+ '## The faults',
259
+ '',
260
+ 'THE JOIN KEYS ARE `guard`, `fault=` and `row=`. Every L0 deny opens',
261
+ '`[<guard>] (layer=L0 fault=<code> row=3, …)`, and every audit line — from BOTH halves of L0, the',
262
+ '`sh` shim and the guard bin — carries `layer=L0 row=<n> fault=<code>`. So one grep lands you in',
263
+ 'the deny, the log line and the row below. The guard names come from `L0_FAULT_NAMES` and the row',
264
+ 'numbers from `L0_ROW_*`, both spelled in exactly one place (`core/l0-fault-codes.ts`).',
265
+ '',
266
+ '| code | guard | fault | detected by | enforced in |',
267
+ '|---|---|---|---|---|',
268
+ ...exports.L0_FAULTS.map((f) => `| \`${f.code}\` | \`${rules_config_4.L0_FAULT_NAMES[f.code]}\` | ${f.name} | ${f.detectedBy} | ${f.enforcedIn} |`),
269
+ '',
270
+ 'First match wins. `D`/`X`/`U`/`K` are decided in POSIX `sh` inside the committed shim, BEFORE the',
271
+ 'guard bin runs — a stale, missing or broken validator cannot be trusted to validate itself.',
272
+ '',
273
+ '## The fix, per fault',
274
+ '',
275
+ 'Every command below is rendered from that fault\'s `cures` array and is asserted, by unit test,',
276
+ 'to be accepted by `isAllowed()` — so nothing here can be a command the guard then rejects. Type',
277
+ 'the option you pick EXACTLY as written and run nothing else on that line.',
278
+ '',
279
+ ...exports.L0_FAULTS.flatMap(renderFixSection),
280
+ ...renderMatrixAndAllowlist(),
281
+ ].join('\n');
282
+ }
283
+ /**
284
+ * The second half of the doc: the three-row matrix and the ONE allowlist. Split out of
285
+ * renderGuardMatrixDoc solely to keep it inside the method-line budget — the join order is what makes
286
+ * the two halves one file, so keep them adjacent and keep the byte-lock test as the arbiter.
287
+ */
288
+ // webpieces-disable no-function-outside-class -- second half of renderGuardMatrixDoc's string, beside it in this module
289
+ function renderMatrixAndAllowlist() {
290
+ return [
291
+ '## The matrix',
292
+ '',
293
+ 'L0 has NO genuine second dimension. Every branch reduces to one question:',
294
+ '',
295
+ '| # | fault | on the allowlist? | outcome |',
296
+ '|---|---|---|---|',
297
+ '| 1 | none | — | hand down to the next guard layer |',
298
+ `| ${rules_config_4.L0_ROW_ALLOWLISTED} | any | yes | PASS or ALLOW (see the entry) |`,
299
+ `| ${rules_config_4.L0_ROW_BLOCKED} | any | no | BLOCK — **only the message varies by fault** |`,
300
+ '',
301
+ `Row ${rules_config_4.L0_ROW_BLOCKED} is the only row that blocks, so every L0 deny cites it — \`row=${rules_config_4.L0_ROW_BLOCKED}\` in the`,
302
+ 'deny header, `row=' + rules_config_4.L0_ROW_BLOCKED + '` on the audit line, and this row here. Same numbers as L1 uses for',
303
+ 'its own rows (see `L1_ROWS`), and for the same reason: a row number is IDENTITY, so it is never reused.',
304
+ '',
305
+ 'The tool is not a dimension either: "any Read" is an allowlist ENTRY, not a tool check.',
306
+ '',
307
+ '## The allowlist',
308
+ '',
309
+ 'ONE list, consulted identically by every fault. A cure that cannot help a given fault also',
310
+ 'cannot hurt it, and gating each entry on a fault is what produced four real defects (a stale',
311
+ 'shim that denied `pnpm install` and every git sync; faults that denied every Read; a config fault',
312
+ 'that denied `rm -rf node_modules && pnpm install` while allowing a bare `pnpm install`).',
313
+ '',
314
+ '| # | allowed | outcome |',
315
+ '|---|---|---|',
316
+ ...shim_1.L0_ALLOWLIST.map((e, i) => `| ${i + 1} | ${e.label} | ${e.kind.toUpperCase()} |`),
317
+ '',
318
+ '- **PASS** — L0 has no objection; the call falls THROUGH so the downstream guards still judge it.',
319
+ '- **ALLOW** — terminal; bypasses everything, because a cure must stay reachable even when a',
320
+ ' downstream guard would block it.',
321
+ '',
322
+ 'Every Bash entry is anchored to the WHOLE command. Appending `&& git status` makes it a DIFFERENT',
323
+ 'command and it is rejected again — that is not the guard refusing its own cure.',
324
+ '',
325
+ 'On an UNGATED entry a leading `cd <dir> &&`, a trailing `2>&1` and a pipe into `tail`/`head` are',
326
+ 'tolerated; nothing else is. **The harness-gated read row tolerates NONE of the three** — not the',
327
+ '`cd` prefix, not the redirect, not the pipe — so `cat f 2>&1` and `cat f | head -20` are both',
328
+ 'rejected. That is deliberate, not an oversight: the row means exactly what',
329
+ '`core/shell-read-parity.ts` means by "this is a read", and that module treats a pipe or a redirect',
330
+ 'as proof the command is more than one. Type the bare command.',
331
+ '',
332
+ '`git merge` is deliberately NOT on this list. Main is merged ONLY through the 3-point fork merge',
333
+ '(`pnpm wp-start-update`, or `pnpm wp-start-upsert-pr` when a PR is already open).',
334
+ '',
335
+ '## Known asymmetry',
336
+ '',
337
+ 'Under `S`/`C`/`Y` the guard bin IS running, so a PASS really does fall through to the downstream',
338
+ 'guards. Under `D`/`X`/`U`/`K` the bin is never executed, so there is nothing to fall through to and a',
339
+ 'PASS degenerates into a terminal allow — reads are unguarded during those three faults.',
340
+ '',
341
+ '## Widening L0',
342
+ '',
343
+ 'Add an entry to `L0_ALLOWLIST` in `packages/tooling/agent-workflow-rules/src/bin/shim.ts`. That array is',
344
+ 'the single source for the JS allowlist, the `grep -E` inside the rendered shim, and this file.',
345
+ '',
346
+ ];
347
+ }
348
+ /**
349
+ * Drop the matrix doc where the AI can read it, and return its absolute path ('' if it could not be
350
+ * written). Called from the L0 BLOCK path so the deny can say `READ <path>`.
351
+ *
352
+ * Best-effort by design: this runs while the tree is already known-broken, and a missing template (an
353
+ * @webpieces/rules-config older than this package) must degrade the deny message, never replace it
354
+ * with a crash.
355
+ */
356
+ // webpieces-disable no-function-outside-class -- sibling of renderGuardMatrixDoc in this module
357
+ //# sourceMappingURL=l0-matrix.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"l0-matrix.js","sourceRoot":"","sources":["../../../../../../packages/tooling/agent-workflow-rules/src/core/l0-matrix.ts"],"names":[],"mappings":";;;AA0QA,oDAqCC;AA/SD,0DAA2F;AAC3F,0DAAyE;AAEzE,sCAAmN;AACnN,0DAA6D;AAE7D,gEAA2H;AAC3H,8DAA8D;AAC9D,0DAAsS;AAGtS,8EAA8E;AAC9E,6CAA6C;AAC7C,EAAE;AACF,uFAAuF;AACvF,kGAAkG;AAClG,qGAAqG;AACrG,EAAE;AACF,gFAAgF;AAChF,EAAE;AACF,gGAAgG;AAChG,qGAAqG;AACrG,+FAA+F;AAC/F,8EAA8E;AAE9E;;;;;;;;;GASG;A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F,8FAA8F;QAC9F,mGAAmG;QACnG,0FAA0F;QAC1F,EAAE;QACF,2BAA2B;QAC3B,eAAe;QACf,GAAG,mBAAY,CAAC,GAAG,CAAC,CAAC,CAAe,EAAE,CAAS,EAAU,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,KAAK,MAAM,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC;QAClH,EAAE;QACF,mGAAmG;QACnG,6FAA6F;QAC7F,oCAAoC;QACpC,EAAE;QACF,mGAAmG;QACnG,iFAAiF;QACjF,EAAE;QACF,kGAAkG;QAClG,kGAAkG;QAClG,+FAA+F;QAC/F,4EAA4E;QAC5E,oGAAoG;QACpG,+DAA+D;QAC/D,EAAE;QACF,kGAAkG;QAClG,mFAAmF;QACnF,EAAE;QACF,oBAAoB;QACpB,EAAE;QACF,kGAAkG;QAClG,uGAAuG;QACvG,yFAAyF;QACzF,EAAE;QACF,gBAAgB;QAChB,EAAE;QACF,0GAA0G;QAC1G,gGAAgG;QAChG,EAAE;KACL,CAAC;AACN,CAAC;AAED;;;;;;;GAOG;AACH,gGAAgG","sourcesContent":["import { CONFIG_MISSING_REPORT, CONFIG_OUT_OF_SYNC_HEADER } from '@webpieces/rules-config';\nimport { CONFIG_FILENAME, writeTemplate } from '@webpieces/rules-config';\n\nimport { ADD_HOOK_PKG_CMD, CHECKOUT_MAIN_PULL_CMD, HOOK_PKG, INSTALL_HOOKS_CMD, L0AllowEntry, L0Call, L0_ALLOWLIST, RECOVERY_CMD, RESTORE_SHIM_CMD, SHIM_MARKER, UPGRADE_SHIM_CMD, renderShim } from '../bin/shim';\nimport { WORKSPACE_MANIFEST } from '@webpieces/rules-config';\nimport { CODEX_READ_STILL_ALLOWED } from '@webpieces/rules-config';\nimport { ENV_SURFACE, HARNESS_REGISTRATIONS, HarnessRegistration, REVIEWER_AGENT_SURFACE } from '../bin/hook-registration';\nimport { shimStaleDenyReason } from '../bin/shim-deny-reason';\nimport { L0_FAULT_BIN_BROKEN, L0_FAULT_BIN_MISSING, L0_FAULT_CONFIG_MISSING, L0_FAULT_CONFIG_OUT_OF_SYNC, L0_FAULT_DRIFT, L0_FAULT_NAMES, L0_FAULT_SHIM_STALE, L0_FAULT_UNDECLARED, L0FaultCode, L0_ROW_ALLOWLISTED, L0_ROW_BLOCKED, l0GuardHeader, l0MatrixCitation } from '@webpieces/rules-config';\nimport { toError } from '@webpieces/tooling-common/to-error';\n\n// ---------------------------------------------------------------------------\n// L0 — the TOOLING-INTEGRITY layer, as data.\n//\n// L0 is the outermost guard: it blocks work while node_modules, the committed shim, or\n// webpieces.config.json are in a state that makes every OTHER guard untrustworthy. Its faults are\n// enumerated in L0_FAULTS below and — drawn as a decision matrix — have NO genuine second dimension:\n//\n// fault present AND call not on the allowlist -> BLOCK(messageFor(fault))\n//\n// so the only thing that varies per fault is the MESSAGE. This module holds the fault table and\n// renders it, together with L0_ALLOWLIST (../bin/shim), into webpieces.guard-matrix.md — the doc the\n// deny messages point the AI at. Doc and code come from the SAME arrays, so they cannot drift.\n// ---------------------------------------------------------------------------\n\n/**\n * The doc L0's deny messages point at. Lives in @webpieces/rules-config/templates alongside the others,\n * and is written to <root>/.webpieces/instruct-ai/ lazily, only on an L0 BLOCK.\n *\n * That generated doc is the AUTHORITY for the fault table and the allowlist (same arrays, cannot\n * drift). guards/L0-tooling.md is the hand-written companion: it adds L0's evaluation\n * ORDER, the use cases and the known gaps, and it documents L1, none of which are rendered from code.\n * Change L0_FAULTS or L0_ALLOWLIST and the generated doc follows automatically — guards/L0-tooling.md does\n * not, so update it in the same PR.\n */\nexport { GUARD_MATRIX_DOC, writeGuardMatrixDoc, guardMatrixPointer } from '@webpieces/rules-config';\nimport { GUARD_MATRIX_DOC } from '@webpieces/rules-config';\n\n/**\n * One CURE for a fault: the exact call, plus the `mention` that must appear in that fault's deny text.\n *\n * Both halves are asserted (l0-matrix.spec.ts): the call must be accepted by isAllowed(), and the deny\n * message must actually name it. That pairing is the anti-deadlock invariant — a message that\n * prescribes a command the allowlist rejects is exactly the shape of the three deadlocks\n * `.claude/rules/*.md` records, and it is how the dead `wp-setup-ai-hooks` bin in the config-missing text was caught.\n */\nexport class L0Cure {\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(\n readonly mention: string,\n readonly call: L0Call,\n /**\n * The one to reach for first when a fault has several. Exactly one cure per fault carries it,\n * so the rendered Fix section never asks the reader to choose between equals.\n */\n readonly preferred: boolean,\n /**\n * WHEN to pick this cure over its siblings — the sentence that makes a list of commands\n * actionable instead of a menu (\"when the PIN is the stale side\", not \"an alternative\").\n */\n readonly discriminator: string,\n ) {}\n\n /** A Bash cure renders as a literal command; a tool-shaped one renders as the edit it stands for. */\n isCommand(): boolean {\n return this.call.toolName === 'Bash';\n }\n}\n\n/** One L0 fault. Data-only → a class, per CLAUDE.md. */\nexport class L0Fault {\n constructor(\n /**\n * The codebook's letter — typed as the UNION of every declared code, not `string`, so\n * `L0_FAULT_NAMES[code]` is total and neither this module nor the deny builders need a\n * `?? 'unknown'` fallback. A fault added without a name fails to compile.\n */\n readonly code: L0FaultCode,\n readonly name: string,\n readonly detectedBy: string,\n readonly enforcedIn: string,\n readonly cures: readonly L0Cure[],\n /**\n * The artifact carrying this fault's deny text. For S/C/Y that is the deny string itself; for\n * D/X/U/K the text is built in POSIX sh inside the rendered shim, so it is the rendered shim —\n * the same bytes the consumer runs, which is what the mention assertion needs to search.\n */\n readonly denyText: string,\n ) {}\n}\n\n// The deny for fault C, and the ONLY message L0 has for a repo with no webpieces.config.json at all.\n// Moved here from runner.ts so the fault table and the runner cannot state different cures.\n//\n// It used to name `./node_modules/.bin/wp-setup-ai-hooks` — a bin that HAS NOT EXISTED since it was\n// renamed to wp-install-ai-hooks. So the one command this deny prescribed was (a) not installable and\n// (b) not on the L0 allowlist in that spelling, i.e. the AI was handed a cure it could neither run nor\n// get past the guard. Now it names the installer that actually seeds the config AND is entry 8 of the\n// allowlist, and it says out loud that writing the config yourself is allowed through.\n//\n// ORDERING (2026-08-02): writing the file yourself now LEADS. The bare installer used to be OPTION 1,\n// but it seeds the config and then PROMPTS twice for a hook target, which hangs a non-interactive\n// agent. Writing the file is the one cure that always works, and it is the same cure every other config\n// problem has (see the config-validation invariant in guards/L0-tooling.md): the validator reports every\n// error at once, so the write/validate loop converges in a couple of passes.\n// Writing/repairing the file yourself. PREFERRED for both config faults, per the config-validation\n// invariant in guards/L0-tooling.md: every config problem cures to \"make the file right\", the validator\n// reports all errors at once so the loop converges in a couple of passes, and allowlist entry 2 permits\n// this edit unconditionally. (That section is the authority — do not restate its reasoning here.)\nconst CONFIG_WRITE_CURE = new L0Cure(\n CONFIG_FILENAME, new L0Call('Edit', '', `/repo/${CONFIG_FILENAME}`), true,\n 'this fault fires at all — it is the only cure that needs no other tool, and it is never denied',\n);\n\n// Cure calls are spelled exactly as the deny messages spell them, so the mention assertion is a real\n// string search rather than a paraphrase.\n// webpieces-disable no-function-outside-class -- pure constructor helper for the L0_FAULTS literal below, in this data module\nfunction bashCure(command: string, preferred: boolean, discriminator: string): L0Cure {\n return new L0Cure(command, new L0Call('Bash', command, ''), preferred, discriminator);\n}\n\n/**\n * THE L0 faults, in first-match-wins order. D/X/U/K are decided in POSIX sh BEFORE the bin runs (a\n * stale, missing or broken validator cannot be trusted to validate itself); S/C/Y are decided inside\n * the bin, in JS. One model, two enforcement points.\n */\nexport const L0_FAULTS: readonly L0Fault[] = [\n new L0Fault(L0_FAULT_DRIFT, 'version drift — root package.json pin != installed version',\n 'sh, before the bin runs', 'sh',\n [\n // `pnpm install` clears D in BOTH directions — it makes installed == pin by definition — so\n // it is always the preferred cure. The direction only decides whether the PIN is the version\n // you WANT, which is what the second cure is for.\n bashCure('pnpm install', true,\n 'node_modules is OLDER than the pin, OR you are on a feature branch and want YOUR '\n + 'branch pin (usually the case) — it always clears the drift'),\n // The on-main sync is spelled `git checkout main && git pull origin main` and NOT `git pull`:\n // a raw pull on a FEATURE branch merges main into it and destroys the fork point, so it is\n // no longer on the L0 allowlist at all (see CHECKOUT_MAIN_PULL_BODY_ERE). This spelling ends\n // ON main, which is why it is safe from any branch — and it is a no-op checkout when you are\n // already there.\n //\n // And it is RAW GIT on purpose, where the workflow guards now say `pnpm wp-sync-main`\n // instead. The fault being cured here is `node_modules` disagreeing with the pin, so\n // `node_modules` is the untrustworthy thing — and every `pnpm wp-*` bin resolves through it.\n // An L0 cure may never be a command that has to load the package it is repairing. See the\n // long note on CHECKOUT_MAIN_PULL_BODY_ERE in bin/l0-allowlist.ts.\n bashCure(CHECKOUT_MAIN_PULL_CMD, false,\n 'node_modules is NEWER than the pin AND you are on main — the PIN is the stale side, so '\n + 'sync first and install second; a bare install would downgrade you'),\n ], renderShim()),\n new L0Fault(L0_FAULT_BIN_MISSING, 'guard bin missing (fresh clone / new worktree / package removed)',\n 'sh, before the bin runs', 'sh',\n [bashCure('pnpm install', true,\n 'this fault fires at all — nothing is installed in THIS tree, and a new git worktree '\n + 'copies no node_modules')],\n renderShim()),\n // U is X with the ONE input that inverts X's cure, which is why it is a separate fault and not a\n // sentence inside X's message: a BARE `pnpm install` is not a weaker fix here, it is a PROVABLE\n // no-op, and an agent that trusts the X text will run it until it gives up. See the ADD_HOOK_PKG\n // entry in l0-allowlist.ts for the incident.\n //\n // The ORDER of these three is the correction bought by a second incident. `pnpm add` used to be the\n // preferred cure, and it is the one cure that CANNOT be committed: a direct root dependency on\n // HOOK_PKG violates the umbrella rule (the root manifest depends on the umbrella ALONE), and the\n // message never said to revert it — so it was followed, and the workaround landed in a real\n // package.json. The package normally arrives WITH the umbrella, so a tree that is merely BEHIND is\n // the common cause and syncing is the cure that leaves a committable tree. The add stays last,\n // reachable, and explicitly labelled as a session unblock rather than a fix.\n new L0Fault(L0_FAULT_UNDECLARED, `guard bin missing AND ${HOOK_PKG} is not declared in package.json`,\n 'sh, before the bin runs', 'sh',\n [\n bashCure(CHECKOUT_MAIN_PULL_CMD, true,\n `${HOOK_PKG} arrives WITH the umbrella, so a tree that is behind explains this without `\n + 'anything being mis-declared — sync first, then install'),\n bashCure('pnpm install', false,\n 'the sync (or a raised catalog pin in ' + WORKSPACE_MANIFEST + ', which is editable '\n + 'while the block is up) gave the installer something new to do — a BARE install with '\n + 'nothing changed reports \"Lockfile is up to date\" and leaves the tree as broken as it '\n + 'found it'),\n bashCure(ADD_HOOK_PKG_CMD, false,\n 'nothing else worked and you need this session back — it is a session unblock, NOT a '\n + `fix: revert it with 'pnpm remove ${HOOK_PKG}' before committing, because a direct `\n + 'root dependency on it violates the umbrella rule'),\n ],\n renderShim()),\n new L0Fault(L0_FAULT_BIN_BROKEN, 'guard bin present but CRASHED (exit code not 0 or 2 — corrupt node_modules)',\n 'sh, before the bin runs', 'sh',\n [bashCure(RECOVERY_CMD, true,\n 'this fault fires at all — a BARE pnpm install SKIPS the corrupt package, because pnpm sees '\n + 'the right version on disk and considers it installed; only the delete forces a rewrite')],\n renderShim()),\n // S covers the WHOLE managed hook surface, not just the shim: the committed ai-hook.sh, the\n // .claude/settings.json entries that register them AND the managed `env` entry that pins the Bash\n // cwd so the hooks resolve identically for every subagent. They only work as a set — a settings file left\n // on a superseded form silently changes who governs, re-pinning every tree to the\n // primary's release — and nothing validated the registration at all before it joined this fault.\n new L0Fault(L0_FAULT_SHIM_STALE, 'a webpieces-managed hook file, one of the harness hook registrations (.claude/settings.json, .codex/hooks.json) or the managed env entry does not match this release',\n 'the guard bin', 'JS',\n [\n // wp-upgrade-shim leads because it is the ONLY cure that repairs EVERY managed surface, and\n // it is still surgical: it rewrites ai-hook.sh, each harness's registration and the env entry\n // and touches no config, and it imports only fs/path so it runs on a tree too broken to load\n // the rule engine. The INSTALLER is deliberately NOT a cure here: it also migrates the config\n // and prompts for a target twice, which hangs a non-interactive agent.\n bashCure(UPGRADE_SHIM_CMD, true,\n 'this fault fires at all — it is the only cure that repairs EVERY managed surface '\n + '(ai-hook.sh, each harness hook registration, the anchoring of the neighbour hook '\n + 'commands registered beside ours, and the Claude settings env entry), and it also '\n + 'deletes the retired guarantee-root.sh and any entry still naming it, and it '\n + 'touches no config; needs installed @webpieces/agent-workflow-rules 0.4.408 or newer'),\n // 2026-07-21: the version gap below caused a real \"command not found\" deadlock.\n bashCure(RESTORE_SHIM_CMD, false,\n 'the installed @webpieces/agent-workflow-rules is OLDER than 0.4.408, so wp-upgrade-shim does '\n + 'not exist yet — it is PARTIAL (it repairs ai-hook.sh and NOTHING else), so upgrade '\n + '@webpieces afterwards and run Option 1 to finish'),\n ],\n // The SAMPLE deny renders EVERY managed surface, built from HARNESS_REGISTRATIONS rather than\n // a hand-written trio — a doc that shows a three-surface deny while the guard can report four\n // is exactly the drift this generated-doc arrangement exists to make impossible.\n shimStaleDenyReason('', '', [\n SHIM_MARKER,\n ...HARNESS_REGISTRATIONS.flatMap((h: HarnessRegistration): readonly string[] => [h.registrationSurface, h.neighbourSurface]),\n ENV_SURFACE,\n REVIEWER_AGENT_SURFACE,\n ], false)),\n new L0Fault(L0_FAULT_CONFIG_MISSING, `${CONFIG_FILENAME} missing`,\n 'the guard bin', 'JS',\n [\n CONFIG_WRITE_CURE,\n // Kept, but demoted: it seeds the file and then PROMPTS twice for a hook target.\n bashCure(INSTALL_HOOKS_CMD, false,\n 'you are at an INTERACTIVE terminal and can answer its two hook-target prompts'),\n ], CONFIG_MISSING_REPORT),\n new L0Fault(L0_FAULT_CONFIG_OUT_OF_SYNC, `a loaded rule has no ${CONFIG_FILENAME} key`,\n 'the guard bin', 'JS',\n [CONFIG_WRITE_CURE], CONFIG_OUT_OF_SYNC_HEADER),\n];\n\n/**\n * One fault's FIX section, rendered from its `cures` array — literal commands only, never prose.\n *\n * This is the half that used to live in hand-written docs and drift. The three fields of L0Cure map\n * onto the three things a blocked reader needs and nothing else: WHAT to type (the call), WHETHER it is\n * the default (preferred), and WHEN to pick a sibling instead (discriminator). A cure with no\n * discriminator would render as a menu of equals, which is how an agent picks the wrong one.\n */\n// webpieces-disable no-function-outside-class -- pure string builder for renderGuardMatrixDoc below, beside the arrays it reads\nfunction renderFixSection(fault: L0Fault): string[] {\n const options = fault.cures.map((cure: L0Cure, i: number): string => {\n // A Bash cure is the command verbatim; a tool-shaped one is the file it edits (allowlist entry 2).\n const literal = cure.isCommand() ? `\\`${cure.call.command}\\`` : `edit \\`${cure.mention}\\` yourself`;\n const label = cure.preferred ? `Option ${i + 1} (preferred)` : `Option ${i + 1}`;\n return `- **${label}**: ${literal} ← pick this when ${cure.discriminator}`;\n });\n return [`### \\`${fault.code}\\` — ${fault.name}`, '', ...options, ''];\n}\n\n/**\n * Render webpieces.guard-matrix.md from L0_FAULTS + L0_ALLOWLIST.\n *\n * A unit test locks the committed template byte-identical to this output, the same way\n * templates/ai-hook.sh is locked to renderShim(). That is what makes the doc assertable instead of\n * aspirational: the table in the doc IS the array the guard consults.\n */\n// webpieces-disable no-function-outside-class -- pure string builder over the two exported arrays, beside them in this module\nexport function renderGuardMatrixDoc(): string {\n return [\n '# webpieces guard matrix — L0 (tooling integrity)',\n '',\n 'GENERATED from `L0_FAULTS` + `L0_ALLOWLIST` in `@webpieces/agent-workflow-rules`. Do not hand-edit —',\n 'a unit test locks this file byte-identical to `renderGuardMatrixDoc()`, so the table below is',\n 'the array the guard actually consults, not a description of it.',\n '',\n 'L0 is the OUTERMOST guard layer. It blocks work while `node_modules`, the committed shim, or',\n '`webpieces.config.json` are in a state that makes every other guard untrustworthy. If you are',\n 'reading this, one of the faults below fired and named this file.',\n '',\n '## The faults',\n '',\n 'THE JOIN KEYS ARE `guard`, `fault=` and `row=`. Every L0 deny opens',\n '`[<guard>] (layer=L0 fault=<code> row=3, …)`, and every audit line — from BOTH halves of L0, the',\n '`sh` shim and the guard bin — carries `layer=L0 row=<n> fault=<code>`. So one grep lands you in',\n 'the deny, the log line and the row below. The guard names come from `L0_FAULT_NAMES` and the row',\n 'numbers from `L0_ROW_*`, both spelled in exactly one place (`core/l0-fault-codes.ts`).',\n '',\n '| code | guard | fault | detected by | enforced in |',\n '|---|---|---|---|---|',\n ...L0_FAULTS.map((f: L0Fault): string =>\n `| \\`${f.code}\\` | \\`${L0_FAULT_NAMES[f.code]}\\` | ${f.name} | ${f.detectedBy} | ${f.enforcedIn} |`),\n '',\n 'First match wins. `D`/`X`/`U`/`K` are decided in POSIX `sh` inside the committed shim, BEFORE the',\n 'guard bin runs — a stale, missing or broken validator cannot be trusted to validate itself.',\n '',\n '## The fix, per fault',\n '',\n 'Every command below is rendered from that fault\\'s `cures` array and is asserted, by unit test,',\n 'to be accepted by `isAllowed()` — so nothing here can be a command the guard then rejects. Type',\n 'the option you pick EXACTLY as written and run nothing else on that line.',\n '',\n ...L0_FAULTS.flatMap(renderFixSection),\n ...renderMatrixAndAllowlist(),\n ].join('\\n');\n}\n\n/**\n * The second half of the doc: the three-row matrix and the ONE allowlist. Split out of\n * renderGuardMatrixDoc solely to keep it inside the method-line budget — the join order is what makes\n * the two halves one file, so keep them adjacent and keep the byte-lock test as the arbiter.\n */\n// webpieces-disable no-function-outside-class -- second half of renderGuardMatrixDoc's string, beside it in this module\nfunction renderMatrixAndAllowlist(): string[] {\n return [\n '## The matrix',\n '',\n 'L0 has NO genuine second dimension. Every branch reduces to one question:',\n '',\n '| # | fault | on the allowlist? | outcome |',\n '|---|---|---|---|',\n '| 1 | none | — | hand down to the next guard layer |',\n `| ${L0_ROW_ALLOWLISTED} | any | yes | PASS or ALLOW (see the entry) |`,\n `| ${L0_ROW_BLOCKED} | any | no | BLOCK — **only the message varies by fault** |`,\n '',\n `Row ${L0_ROW_BLOCKED} is the only row that blocks, so every L0 deny cites it — \\`row=${L0_ROW_BLOCKED}\\` in the`,\n 'deny header, `row=' + L0_ROW_BLOCKED + '` on the audit line, and this row here. Same numbers as L1 uses for',\n 'its own rows (see `L1_ROWS`), and for the same reason: a row number is IDENTITY, so it is never reused.',\n '',\n 'The tool is not a dimension either: \"any Read\" is an allowlist ENTRY, not a tool check.',\n '',\n '## The allowlist',\n '',\n 'ONE list, consulted identically by every fault. A cure that cannot help a given fault also',\n 'cannot hurt it, and gating each entry on a fault is what produced four real defects (a stale',\n 'shim that denied `pnpm install` and every git sync; faults that denied every Read; a config fault',\n 'that denied `rm -rf node_modules && pnpm install` while allowing a bare `pnpm install`).',\n '',\n '| # | allowed | outcome |',\n '|---|---|---|',\n ...L0_ALLOWLIST.map((e: L0AllowEntry, i: number): string => `| ${i + 1} | ${e.label} | ${e.kind.toUpperCase()} |`),\n '',\n '- **PASS** — L0 has no objection; the call falls THROUGH so the downstream guards still judge it.',\n '- **ALLOW** — terminal; bypasses everything, because a cure must stay reachable even when a',\n ' downstream guard would block it.',\n '',\n 'Every Bash entry is anchored to the WHOLE command. Appending `&& git status` makes it a DIFFERENT',\n 'command and it is rejected again — that is not the guard refusing its own cure.',\n '',\n 'On an UNGATED entry a leading `cd <dir> &&`, a trailing `2>&1` and a pipe into `tail`/`head` are',\n 'tolerated; nothing else is. **The harness-gated read row tolerates NONE of the three** — not the',\n '`cd` prefix, not the redirect, not the pipe — so `cat f 2>&1` and `cat f | head -20` are both',\n 'rejected. That is deliberate, not an oversight: the row means exactly what',\n '`core/shell-read-parity.ts` means by \"this is a read\", and that module treats a pipe or a redirect',\n 'as proof the command is more than one. Type the bare command.',\n '',\n '`git merge` is deliberately NOT on this list. Main is merged ONLY through the 3-point fork merge',\n '(`pnpm wp-start-update`, or `pnpm wp-start-upsert-pr` when a PR is already open).',\n '',\n '## Known asymmetry',\n '',\n 'Under `S`/`C`/`Y` the guard bin IS running, so a PASS really does fall through to the downstream',\n 'guards. Under `D`/`X`/`U`/`K` the bin is never executed, so there is nothing to fall through to and a',\n 'PASS degenerates into a terminal allow — reads are unguarded during those three faults.',\n '',\n '## Widening L0',\n '',\n 'Add an entry to `L0_ALLOWLIST` in `packages/tooling/agent-workflow-rules/src/bin/shim.ts`. That array is',\n 'the single source for the JS allowlist, the `grep -E` inside the rendered shim, and this file.',\n '',\n ];\n}\n\n/**\n * Drop the matrix doc where the AI can read it, and return its absolute path ('' if it could not be\n * written). Called from the L0 BLOCK path so the deny can say `READ <path>`.\n *\n * Best-effort by design: this runs while the tree is already known-broken, and a missing template (an\n * @webpieces/rules-config older than this package) must degrade the deny message, never replace it\n * with a crash.\n */\n// webpieces-disable no-function-outside-class -- sibling of renderGuardMatrixDoc in this module\n\n"]}