@webpieces/ai-hook-rules 0.4.838 → 0.4.840

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 (390) hide show
  1. package/README.md +12 -140
  2. package/package.json +7 -15
  3. package/src/adapters/hook-app-fixtures.d.ts +1 -1
  4. package/src/adapters/hook-app-fixtures.js +0 -8
  5. package/src/adapters/hook-app-fixtures.js.map +1 -1
  6. package/src/adapters/hook-core.d.ts +1 -21
  7. package/src/adapters/hook-core.js +22 -341
  8. package/src/adapters/hook-core.js.map +1 -1
  9. package/src/core/load-rules.d.ts +4 -39
  10. package/src/core/load-rules.js +15 -127
  11. package/src/core/load-rules.js.map +1 -1
  12. package/src/core/rules/catch-error-pattern.d.ts +3 -3
  13. package/src/core/rules/catch-error-pattern.js +13 -13
  14. package/src/core/rules/catch-error-pattern.js.map +1 -1
  15. package/src/core/rules/index.d.ts +1 -14
  16. package/src/core/rules/index.js +1 -17
  17. package/src/core/rules/index.js.map +1 -1
  18. package/src/core/rules/match-rule.d.ts +3 -3
  19. package/src/core/rules/match-rule.js +6 -6
  20. package/src/core/rules/match-rule.js.map +1 -1
  21. package/src/core/rules/max-file-lines.d.ts +3 -3
  22. package/src/core/rules/max-file-lines.js +7 -7
  23. package/src/core/rules/max-file-lines.js.map +1 -1
  24. package/src/core/rules/no-any-unknown.d.ts +3 -3
  25. package/src/core/rules/no-any-unknown.js +6 -6
  26. package/src/core/rules/no-any-unknown.js.map +1 -1
  27. package/src/core/rules/no-custom-css.d.ts +3 -3
  28. package/src/core/rules/no-custom-css.js +7 -7
  29. package/src/core/rules/no-custom-css.js.map +1 -1
  30. package/src/core/rules/no-destructure.d.ts +3 -3
  31. package/src/core/rules/no-destructure.js +7 -7
  32. package/src/core/rules/no-destructure.js.map +1 -1
  33. package/src/core/rules/no-implicit-any.d.ts +3 -3
  34. package/src/core/rules/no-implicit-any.js +6 -6
  35. package/src/core/rules/no-implicit-any.js.map +1 -1
  36. package/src/core/rules/no-js-files.d.ts +3 -3
  37. package/src/core/rules/no-js-files.js +6 -6
  38. package/src/core/rules/no-js-files.js.map +1 -1
  39. package/src/core/rules/no-process-exit-outside-main.d.ts +3 -3
  40. package/src/core/rules/no-process-exit-outside-main.js +7 -7
  41. package/src/core/rules/no-process-exit-outside-main.js.map +1 -1
  42. package/src/core/rules/no-symbol-di-tokens.d.ts +3 -3
  43. package/src/core/rules/no-symbol-di-tokens.js +7 -7
  44. package/src/core/rules/no-symbol-di-tokens.js.map +1 -1
  45. package/src/core/rules/no-unmanaged-exceptions.d.ts +3 -3
  46. package/src/core/rules/no-unmanaged-exceptions.js +9 -9
  47. package/src/core/rules/no-unmanaged-exceptions.js.map +1 -1
  48. package/src/core/rules/require-return-type.d.ts +3 -3
  49. package/src/core/rules/require-return-type.js +6 -6
  50. package/src/core/rules/require-return-type.js.map +1 -1
  51. package/src/core/rules/throw-cause-required.d.ts +3 -3
  52. package/src/core/rules/throw-cause-required.js +9 -9
  53. package/src/core/rules/throw-cause-required.js.map +1 -1
  54. package/src/core/rules/validate-ts-in-src.d.ts +3 -3
  55. package/src/core/rules/validate-ts-in-src.js +7 -7
  56. package/src/core/rules/validate-ts-in-src.js.map +1 -1
  57. package/src/core/runner.d.ts +10 -19
  58. package/src/core/runner.js +24 -622
  59. package/src/core/runner.js.map +1 -1
  60. package/src/index.d.ts +2 -15
  61. package/src/index.js +4 -54
  62. package/src/index.js.map +1 -1
  63. package/openclaw.plugin.json +0 -15
  64. package/src/adapters/agent-adapters.d.ts +0 -13
  65. package/src/adapters/agent-adapters.js +0 -23
  66. package/src/adapters/agent-adapters.js.map +0 -1
  67. package/src/adapters/agent-payload.d.ts +0 -48
  68. package/src/adapters/agent-payload.js +0 -30
  69. package/src/adapters/agent-payload.js.map +0 -1
  70. package/src/adapters/agent-response.d.ts +0 -5
  71. package/src/adapters/agent-response.js +0 -86
  72. package/src/adapters/agent-response.js.map +0 -1
  73. package/src/adapters/claude-code-adapter.d.ts +0 -26
  74. package/src/adapters/claude-code-adapter.js +0 -69
  75. package/src/adapters/claude-code-adapter.js.map +0 -1
  76. package/src/adapters/codex-adapter.d.ts +0 -19
  77. package/src/adapters/codex-adapter.js +0 -48
  78. package/src/adapters/codex-adapter.js.map +0 -1
  79. package/src/adapters/codex-subagent-guard.d.ts +0 -45
  80. package/src/adapters/codex-subagent-guard.js +0 -88
  81. package/src/adapters/codex-subagent-guard.js.map +0 -1
  82. package/src/adapters/detect-ai.d.ts +0 -70
  83. package/src/adapters/detect-ai.js +0 -82
  84. package/src/adapters/detect-ai.js.map +0 -1
  85. package/src/adapters/guards-hook.d.ts +0 -3
  86. package/src/adapters/guards-hook.js +0 -30
  87. package/src/adapters/guards-hook.js.map +0 -1
  88. package/src/adapters/openclaw-plugin.d.ts +0 -14
  89. package/src/adapters/openclaw-plugin.js +0 -87
  90. package/src/adapters/openclaw-plugin.js.map +0 -1
  91. package/src/adapters/review-identity-stamper.d.ts +0 -20
  92. package/src/adapters/review-identity-stamper.js +0 -34
  93. package/src/adapters/review-identity-stamper.js.map +0 -1
  94. package/src/bin/codex-trust.d.ts +0 -105
  95. package/src/bin/codex-trust.js +0 -205
  96. package/src/bin/codex-trust.js.map +0 -1
  97. package/src/bin/dev-hook-install.d.ts +0 -1
  98. package/src/bin/dev-hook-install.js +0 -82
  99. package/src/bin/dev-hook-install.js.map +0 -1
  100. package/src/bin/dev-hook-uninstall.d.ts +0 -1
  101. package/src/bin/dev-hook-uninstall.js +0 -45
  102. package/src/bin/dev-hook-uninstall.js.map +0 -1
  103. package/src/bin/hook-registration.d.ts +0 -429
  104. package/src/bin/hook-registration.js +0 -661
  105. package/src/bin/hook-registration.js.map +0 -1
  106. package/src/bin/install-entry.d.ts +0 -19
  107. package/src/bin/install-entry.js +0 -128
  108. package/src/bin/install-entry.js.map +0 -1
  109. package/src/bin/l0-allowlist.d.ts +0 -49
  110. package/src/bin/l0-allowlist.js +0 -528
  111. package/src/bin/l0-allowlist.js.map +0 -1
  112. package/src/bin/l0-codex-read.d.ts +0 -21
  113. package/src/bin/l0-codex-read.js +0 -109
  114. package/src/bin/l0-codex-read.js.map +0 -1
  115. package/src/bin/l0-decide.d.ts +0 -50
  116. package/src/bin/l0-decide.js +0 -103
  117. package/src/bin/l0-decide.js.map +0 -1
  118. package/src/bin/l0-entry.d.ts +0 -103
  119. package/src/bin/l0-entry.js +0 -98
  120. package/src/bin/l0-entry.js.map +0 -1
  121. package/src/bin/l0-ignored-tools.d.ts +0 -38
  122. package/src/bin/l0-ignored-tools.js +0 -44
  123. package/src/bin/l0-ignored-tools.js.map +0 -1
  124. package/src/bin/managed-env.d.ts +0 -46
  125. package/src/bin/managed-env.js +0 -50
  126. package/src/bin/managed-env.js.map +0 -1
  127. package/src/bin/neighbour-hooks.d.ts +0 -42
  128. package/src/bin/neighbour-hooks.js +0 -177
  129. package/src/bin/neighbour-hooks.js.map +0 -1
  130. package/src/bin/reviewer-agent.d.ts +0 -19
  131. package/src/bin/reviewer-agent.js +0 -135
  132. package/src/bin/reviewer-agent.js.map +0 -1
  133. package/src/bin/settings-shape.d.ts +0 -37
  134. package/src/bin/settings-shape.js +0 -17
  135. package/src/bin/settings-shape.js.map +0 -1
  136. package/src/bin/setup-config.d.ts +0 -19
  137. package/src/bin/setup-config.js +0 -370
  138. package/src/bin/setup-config.js.map +0 -1
  139. package/src/bin/setup.d.ts +0 -78
  140. package/src/bin/setup.js +0 -400
  141. package/src/bin/setup.js.map +0 -1
  142. package/src/bin/shim-audit-log.d.ts +0 -119
  143. package/src/bin/shim-audit-log.js +0 -286
  144. package/src/bin/shim-audit-log.js.map +0 -1
  145. package/src/bin/shim-deny-reason.d.ts +0 -1
  146. package/src/bin/shim-deny-reason.js +0 -244
  147. package/src/bin/shim-deny-reason.js.map +0 -1
  148. package/src/bin/shim-drift-fix.d.ts +0 -1
  149. package/src/bin/shim-drift-fix.js +0 -72
  150. package/src/bin/shim-drift-fix.js.map +0 -1
  151. package/src/bin/shim-testkit.d.ts +0 -107
  152. package/src/bin/shim-testkit.js +0 -197
  153. package/src/bin/shim-testkit.js.map +0 -1
  154. package/src/bin/shim-version-drift.d.ts +0 -1
  155. package/src/bin/shim-version-drift.js +0 -164
  156. package/src/bin/shim-version-drift.js.map +0 -1
  157. package/src/bin/shim.d.ts +0 -16
  158. package/src/bin/shim.js +0 -636
  159. package/src/bin/shim.js.map +0 -1
  160. package/src/bin/upgrade-shim.d.ts +0 -18
  161. package/src/bin/upgrade-shim.js +0 -283
  162. package/src/bin/upgrade-shim.js.map +0 -1
  163. package/src/core/ai-type-context.d.ts +0 -36
  164. package/src/core/ai-type-context.js +0 -45
  165. package/src/core/ai-type-context.js.map +0 -1
  166. package/src/core/apply-patch-parse.d.ts +0 -36
  167. package/src/core/apply-patch-parse.js +0 -154
  168. package/src/core/apply-patch-parse.js.map +0 -1
  169. package/src/core/build-context.d.ts +0 -10
  170. package/src/core/build-context.js +0 -66
  171. package/src/core/build-context.js.map +0 -1
  172. package/src/core/command-scan.d.ts +0 -122
  173. package/src/core/command-scan.js +0 -282
  174. package/src/core/command-scan.js.map +0 -1
  175. package/src/core/custom-rule-adapter.d.ts +0 -22
  176. package/src/core/custom-rule-adapter.js +0 -50
  177. package/src/core/custom-rule-adapter.js.map +0 -1
  178. package/src/core/decision-log.d.ts +0 -190
  179. package/src/core/decision-log.js +0 -406
  180. package/src/core/decision-log.js.map +0 -1
  181. package/src/core/delete-scoped-rules.d.ts +0 -8
  182. package/src/core/delete-scoped-rules.js +0 -31
  183. package/src/core/delete-scoped-rules.js.map +0 -1
  184. package/src/core/disable-directives.d.ts +0 -8
  185. package/src/core/disable-directives.js +0 -80
  186. package/src/core/disable-directives.js.map +0 -1
  187. package/src/core/effective-tree.d.ts +0 -204
  188. package/src/core/effective-tree.js +0 -277
  189. package/src/core/effective-tree.js.map +0 -1
  190. package/src/core/excluded-path-escape.d.ts +0 -101
  191. package/src/core/excluded-path-escape.js +0 -236
  192. package/src/core/excluded-path-escape.js.map +0 -1
  193. package/src/core/excluded-paths.d.ts +0 -23
  194. package/src/core/excluded-paths.js +0 -54
  195. package/src/core/excluded-paths.js.map +0 -1
  196. package/src/core/fix-hint.d.ts +0 -40
  197. package/src/core/fix-hint.js +0 -53
  198. package/src/core/fix-hint.js.map +0 -1
  199. package/src/core/force-to-root.d.ts +0 -32
  200. package/src/core/force-to-root.js +0 -60
  201. package/src/core/force-to-root.js.map +0 -1
  202. package/src/core/guard-index-doc.d.ts +0 -63
  203. package/src/core/guard-index-doc.js +0 -172
  204. package/src/core/guard-index-doc.js.map +0 -1
  205. package/src/core/instruct-ai-writer.d.ts +0 -1
  206. package/src/core/instruct-ai-writer.js +0 -6
  207. package/src/core/instruct-ai-writer.js.map +0 -1
  208. package/src/core/l0-fault-codes.d.ts +0 -85
  209. package/src/core/l0-fault-codes.js +0 -121
  210. package/src/core/l0-fault-codes.js.map +0 -1
  211. package/src/core/l0-matrix.d.ts +0 -114
  212. package/src/core/l0-matrix.js +0 -416
  213. package/src/core/l0-matrix.js.map +0 -1
  214. package/src/core/l0-tooling-doc.d.ts +0 -45
  215. package/src/core/l0-tooling-doc.js +0 -258
  216. package/src/core/l0-tooling-doc.js.map +0 -1
  217. package/src/core/l1-doc.d.ts +0 -7
  218. package/src/core/l1-doc.js +0 -340
  219. package/src/core/l1-doc.js.map +0 -1
  220. package/src/core/l1-matrix-doc.d.ts +0 -31
  221. package/src/core/l1-matrix-doc.js +0 -111
  222. package/src/core/l1-matrix-doc.js.map +0 -1
  223. package/src/core/l1-rows.d.ts +0 -167
  224. package/src/core/l1-rows.js +0 -262
  225. package/src/core/l1-rows.js.map +0 -1
  226. package/src/core/l2-doc.d.ts +0 -7
  227. package/src/core/l2-doc.js +0 -385
  228. package/src/core/l2-doc.js.map +0 -1
  229. package/src/core/l2-matrix-doc.d.ts +0 -23
  230. package/src/core/l2-matrix-doc.js +0 -72
  231. package/src/core/l2-matrix-doc.js.map +0 -1
  232. package/src/core/l2-row.d.ts +0 -54
  233. package/src/core/l2-row.js +0 -75
  234. package/src/core/l2-row.js.map +0 -1
  235. package/src/core/l2-rows.d.ts +0 -56
  236. package/src/core/l2-rows.js +0 -272
  237. package/src/core/l2-rows.js.map +0 -1
  238. package/src/core/load-config.d.ts +0 -1
  239. package/src/core/load-config.js +0 -9
  240. package/src/core/load-config.js.map +0 -1
  241. package/src/core/log-stream.d.ts +0 -117
  242. package/src/core/log-stream.js +0 -156
  243. package/src/core/log-stream.js.map +0 -1
  244. package/src/core/log-streams.d.ts +0 -48
  245. package/src/core/log-streams.js +0 -55
  246. package/src/core/log-streams.js.map +0 -1
  247. package/src/core/log-target.d.ts +0 -21
  248. package/src/core/log-target.js +0 -29
  249. package/src/core/log-target.js.map +0 -1
  250. package/src/core/main-sync-log.d.ts +0 -16
  251. package/src/core/main-sync-log.js +0 -105
  252. package/src/core/main-sync-log.js.map +0 -1
  253. package/src/core/main-sync-refresh.d.ts +0 -39
  254. package/src/core/main-sync-refresh.js +0 -96
  255. package/src/core/main-sync-refresh.js.map +0 -1
  256. package/src/core/main-sync-timeout.d.ts +0 -32
  257. package/src/core/main-sync-timeout.js +0 -94
  258. package/src/core/main-sync-timeout.js.map +0 -1
  259. package/src/core/matrix-cures.d.ts +0 -12
  260. package/src/core/matrix-cures.js +0 -56
  261. package/src/core/matrix-cures.js.map +0 -1
  262. package/src/core/missing-directory.d.ts +0 -38
  263. package/src/core/missing-directory.js +0 -66
  264. package/src/core/missing-directory.js.map +0 -1
  265. package/src/core/read-only-inspection.d.ts +0 -34
  266. package/src/core/read-only-inspection.js +0 -88
  267. package/src/core/read-only-inspection.js.map +0 -1
  268. package/src/core/rejection-log.d.ts +0 -9
  269. package/src/core/rejection-log.js +0 -258
  270. package/src/core/rejection-log.js.map +0 -1
  271. package/src/core/report.d.ts +0 -21
  272. package/src/core/report.js +0 -73
  273. package/src/core/report.js.map +0 -1
  274. package/src/core/rule-base.d.ts +0 -39
  275. package/src/core/rule-base.js +0 -36
  276. package/src/core/rule-base.js.map +0 -1
  277. package/src/core/rules/branch-creation-guard.d.ts +0 -113
  278. package/src/core/rules/branch-creation-guard.js +0 -422
  279. package/src/core/rules/branch-creation-guard.js.map +0 -1
  280. package/src/core/rules/branch-switch-scan.d.ts +0 -43
  281. package/src/core/rules/branch-switch-scan.js +0 -132
  282. package/src/core/rules/branch-switch-scan.js.map +0 -1
  283. package/src/core/rules/build-output-pipe-guard.d.ts +0 -56
  284. package/src/core/rules/build-output-pipe-guard.js +0 -120
  285. package/src/core/rules/build-output-pipe-guard.js.map +0 -1
  286. package/src/core/rules/build-output-pipe-scan.d.ts +0 -47
  287. package/src/core/rules/build-output-pipe-scan.js +0 -84
  288. package/src/core/rules/build-output-pipe-scan.js.map +0 -1
  289. package/src/core/rules/cap-remedies.d.ts +0 -39
  290. package/src/core/rules/cap-remedies.js +0 -59
  291. package/src/core/rules/cap-remedies.js.map +0 -1
  292. package/src/core/rules/commit-message-substitution-guard.d.ts +0 -72
  293. package/src/core/rules/commit-message-substitution-guard.js +0 -134
  294. package/src/core/rules/commit-message-substitution-guard.js.map +0 -1
  295. package/src/core/rules/commit-message-substitution-scan.d.ts +0 -42
  296. package/src/core/rules/commit-message-substitution-scan.js +0 -145
  297. package/src/core/rules/commit-message-substitution-scan.js.map +0 -1
  298. package/src/core/rules/content-read-scan.d.ts +0 -76
  299. package/src/core/rules/content-read-scan.js +0 -176
  300. package/src/core/rules/content-read-scan.js.map +0 -1
  301. package/src/core/rules/cure-prefix-scan.d.ts +0 -64
  302. package/src/core/rules/cure-prefix-scan.js +0 -133
  303. package/src/core/rules/cure-prefix-scan.js.map +0 -1
  304. package/src/core/rules/feature-branch-guard.d.ts +0 -121
  305. package/src/core/rules/feature-branch-guard.js +0 -326
  306. package/src/core/rules/feature-branch-guard.js.map +0 -1
  307. package/src/core/rules/judged-tree.d.ts +0 -66
  308. package/src/core/rules/judged-tree.js +0 -97
  309. package/src/core/rules/judged-tree.js.map +0 -1
  310. package/src/core/rules/main-freshness.d.ts +0 -37
  311. package/src/core/rules/main-freshness.js +0 -61
  312. package/src/core/rules/main-freshness.js.map +0 -1
  313. package/src/core/rules/merge-in-progress-guard.d.ts +0 -17
  314. package/src/core/rules/merge-in-progress-guard.js +0 -122
  315. package/src/core/rules/merge-in-progress-guard.js.map +0 -1
  316. package/src/core/rules/merged-branch-bash-guard.d.ts +0 -62
  317. package/src/core/rules/merged-branch-bash-guard.js +0 -170
  318. package/src/core/rules/merged-branch-bash-guard.js.map +0 -1
  319. package/src/core/rules/merged-branch-message.d.ts +0 -59
  320. package/src/core/rules/merged-branch-message.js +0 -137
  321. package/src/core/rules/merged-branch-message.js.map +0 -1
  322. package/src/core/rules/pr-creation-or-push-guard.d.ts +0 -26
  323. package/src/core/rules/pr-creation-or-push-guard.js +0 -146
  324. package/src/core/rules/pr-creation-or-push-guard.js.map +0 -1
  325. package/src/core/rules/pr-merge-guard.d.ts +0 -36
  326. package/src/core/rules/pr-merge-guard.js +0 -86
  327. package/src/core/rules/pr-merge-guard.js.map +0 -1
  328. package/src/core/rules/read-stale-guard.d.ts +0 -136
  329. package/src/core/rules/read-stale-guard.js +0 -326
  330. package/src/core/rules/read-stale-guard.js.map +0 -1
  331. package/src/core/rules/recovery-allowlist.d.ts +0 -49
  332. package/src/core/rules/recovery-allowlist.js +0 -187
  333. package/src/core/rules/recovery-allowlist.js.map +0 -1
  334. package/src/core/rules/redirect-how-to-merge-main.d.ts +0 -16
  335. package/src/core/rules/redirect-how-to-merge-main.js +0 -157
  336. package/src/core/rules/redirect-how-to-merge-main.js.map +0 -1
  337. package/src/core/rules/shell-segment-scan.d.ts +0 -64
  338. package/src/core/rules/shell-segment-scan.js +0 -88
  339. package/src/core/rules/shell-segment-scan.js.map +0 -1
  340. package/src/core/rules/stale-main-bash-guard.d.ts +0 -198
  341. package/src/core/rules/stale-main-bash-guard.js +0 -361
  342. package/src/core/rules/stale-main-bash-guard.js.map +0 -1
  343. package/src/core/rules/stale-main-message.d.ts +0 -62
  344. package/src/core/rules/stale-main-message.js +0 -102
  345. package/src/core/rules/stale-main-message.js.map +0 -1
  346. package/src/core/rules/tree-recovery.d.ts +0 -92
  347. package/src/core/rules/tree-recovery.js +0 -165
  348. package/src/core/rules/tree-recovery.js.map +0 -1
  349. package/src/core/rules/wait-spin-guard.d.ts +0 -128
  350. package/src/core/rules/wait-spin-guard.js +0 -211
  351. package/src/core/rules/wait-spin-guard.js.map +0 -1
  352. package/src/core/rules/wait-spin-scan.d.ts +0 -118
  353. package/src/core/rules/wait-spin-scan.js +0 -203
  354. package/src/core/rules/wait-spin-scan.js.map +0 -1
  355. package/src/core/rules/whole-repo-build-guard.d.ts +0 -125
  356. package/src/core/rules/whole-repo-build-guard.js +0 -257
  357. package/src/core/rules/whole-repo-build-guard.js.map +0 -1
  358. package/src/core/rules/whole-repo-build-scan.d.ts +0 -28
  359. package/src/core/rules/whole-repo-build-scan.js +0 -198
  360. package/src/core/rules/whole-repo-build-scan.js.map +0 -1
  361. package/src/core/session-call-history.d.ts +0 -44
  362. package/src/core/session-call-history.js +0 -79
  363. package/src/core/session-call-history.js.map +0 -1
  364. package/src/core/shell-read-parity.d.ts +0 -56
  365. package/src/core/shell-read-parity.js +0 -155
  366. package/src/core/shell-read-parity.js.map +0 -1
  367. package/src/core/strip-ts-noise.d.ts +0 -1
  368. package/src/core/strip-ts-noise.js +0 -185
  369. package/src/core/strip-ts-noise.js.map +0 -1
  370. package/src/core/sync-main.d.ts +0 -46
  371. package/src/core/sync-main.js +0 -175
  372. package/src/core/sync-main.js.map +0 -1
  373. package/src/core/target-tree.d.ts +0 -84
  374. package/src/core/target-tree.js +0 -148
  375. package/src/core/target-tree.js.map +0 -1
  376. package/src/core/to-error.d.ts +0 -5
  377. package/src/core/to-error.js +0 -37
  378. package/src/core/to-error.js.map +0 -1
  379. package/src/core/types.d.ts +0 -152
  380. package/src/core/types.js +0 -200
  381. package/src/core/types.js.map +0 -1
  382. package/src/core/version-sync.d.ts +0 -219
  383. package/src/core/version-sync.js +0 -558
  384. package/src/core/version-sync.js.map +0 -1
  385. package/src/core/webpieces-versions.d.ts +0 -98
  386. package/src/core/webpieces-versions.js +0 -206
  387. package/src/core/webpieces-versions.js.map +0 -1
  388. package/templates/ai-hook.sh +0 -497
  389. package/templates/claude-settings-hook.json +0 -28
  390. package/templates/webpieces-reviewer.md +0 -60
@@ -1,114 +0,0 @@
1
- import { L0Call } from '../bin/shim';
2
- import { L0FaultCode } from './l0-fault-codes';
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 declare const GUARD_MATRIX_DOC = "webpieces.guard-matrix.md";
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
- export declare const CONFIG_MISSING_REPORT: string;
82
- export declare const CONFIG_OUT_OF_SYNC_HEADER: string;
83
- /**
84
- * THE L0 faults, in first-match-wins order. D/X/U/K are decided in POSIX sh BEFORE the bin runs (a
85
- * stale, missing or broken validator cannot be trusted to validate itself); S/C/Y are decided inside
86
- * the bin, in JS. One model, two enforcement points.
87
- */
88
- export declare const L0_FAULTS: readonly L0Fault[];
89
- /**
90
- * Render webpieces.guard-matrix.md from L0_FAULTS + L0_ALLOWLIST.
91
- *
92
- * A unit test locks the committed template byte-identical to this output, the same way
93
- * templates/ai-hook.sh is locked to renderShim(). That is what makes the doc assertable instead of
94
- * aspirational: the table in the doc IS the array the guard consults.
95
- */
96
- export declare function renderGuardMatrixDoc(): string;
97
- /**
98
- * Drop the matrix doc where the AI can read it, and return its absolute path ('' if it could not be
99
- * written). Called from the L0 BLOCK path so the deny can say `READ <path>`.
100
- *
101
- * Best-effort by design: this runs while the tree is already known-broken, and a missing template (an
102
- * @webpieces/rules-config older than this package) must degrade the deny message, never replace it
103
- * with a crash.
104
- */
105
- export declare function writeGuardMatrixDoc(workspaceRoot: string): string;
106
- /**
107
- * The `READ <path>` pointer appended to an L0 deny, or '' when the doc could not be written.
108
- *
109
- * It opens with a NEWLINE, not a space: the JS-side L0 denies render in the house format now (a header,
110
- * a `[guard-name]` block, `Fix Option N:` lines), so a pointer glued onto the end of the last line would
111
- * be the one place the shape broke. A real newline is safe on both call paths — denyJson() JSON.stringifies
112
- * it, exactly as it does for every multi-line L1 report.
113
- */
114
- export declare function guardMatrixPointer(docPath: string): string;
@@ -1,416 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.L0_FAULTS = exports.CONFIG_OUT_OF_SYNC_HEADER = exports.CONFIG_MISSING_REPORT = exports.L0Fault = exports.L0Cure = exports.GUARD_MATRIX_DOC = void 0;
4
- exports.renderGuardMatrixDoc = renderGuardMatrixDoc;
5
- exports.writeGuardMatrixDoc = writeGuardMatrixDoc;
6
- exports.guardMatrixPointer = guardMatrixPointer;
7
- const rules_config_1 = require("@webpieces/rules-config");
8
- const shim_1 = require("../bin/shim");
9
- const l0_codex_read_1 = require("../bin/l0-codex-read");
10
- const hook_registration_1 = require("../bin/hook-registration");
11
- const shim_deny_reason_1 = require("../bin/shim-deny-reason");
12
- const l0_fault_codes_1 = require("./l0-fault-codes");
13
- const to_error_1 = require("./to-error");
14
- // ---------------------------------------------------------------------------
15
- // L0 — the TOOLING-INTEGRITY layer, as data.
16
- //
17
- // L0 is the outermost guard: it blocks work while node_modules, the committed shim, or
18
- // webpieces.config.json are in a state that makes every OTHER guard untrustworthy. Its faults are
19
- // enumerated in L0_FAULTS below and — drawn as a decision matrix — have NO genuine second dimension:
20
- //
21
- // fault present AND call not on the allowlist -> BLOCK(messageFor(fault))
22
- //
23
- // so the only thing that varies per fault is the MESSAGE. This module holds the fault table and
24
- // renders it, together with L0_ALLOWLIST (../bin/shim), into webpieces.guard-matrix.md — the doc the
25
- // deny messages point the AI at. Doc and code come from the SAME arrays, so they cannot drift.
26
- // ---------------------------------------------------------------------------
27
- /**
28
- * The doc L0's deny messages point at. Lives in @webpieces/rules-config/templates alongside the others,
29
- * and is written to <root>/.webpieces/instruct-ai/ lazily, only on an L0 BLOCK.
30
- *
31
- * That generated doc is the AUTHORITY for the fault table and the allowlist (same arrays, cannot
32
- * drift). guards/L0-tooling.md is the hand-written companion: it adds L0's evaluation
33
- * ORDER, the use cases and the known gaps, and it documents L1, none of which are rendered from code.
34
- * Change L0_FAULTS or L0_ALLOWLIST and the generated doc follows automatically — guards/L0-tooling.md does
35
- * not, so update it in the same PR.
36
- */
37
- exports.GUARD_MATRIX_DOC = 'webpieces.guard-matrix.md';
38
- /**
39
- * One CURE for a fault: the exact call, plus the `mention` that must appear in that fault's deny text.
40
- *
41
- * Both halves are asserted (l0-matrix.spec.ts): the call must be accepted by isAllowed(), and the deny
42
- * message must actually name it. That pairing is the anti-deadlock invariant — a message that
43
- * prescribes a command the allowlist rejects is exactly the shape of the three deadlocks
44
- * `.claude/rules/*.md` records, and it is how the dead `wp-setup-ai-hooks` bin in the config-missing text was caught.
45
- */
46
- class L0Cure {
47
- mention;
48
- call;
49
- preferred;
50
- discriminator;
51
- // eslint-disable-next-line @typescript-eslint/max-params
52
- constructor(mention, call,
53
- /**
54
- * The one to reach for first when a fault has several. Exactly one cure per fault carries it,
55
- * so the rendered Fix section never asks the reader to choose between equals.
56
- */
57
- preferred,
58
- /**
59
- * WHEN to pick this cure over its siblings — the sentence that makes a list of commands
60
- * actionable instead of a menu ("when the PIN is the stale side", not "an alternative").
61
- */
62
- discriminator) {
63
- this.mention = mention;
64
- this.call = call;
65
- this.preferred = preferred;
66
- this.discriminator = discriminator;
67
- }
68
- /** A Bash cure renders as a literal command; a tool-shaped one renders as the edit it stands for. */
69
- isCommand() {
70
- return this.call.toolName === 'Bash';
71
- }
72
- }
73
- exports.L0Cure = L0Cure;
74
- /** One L0 fault. Data-only → a class, per CLAUDE.md. */
75
- class L0Fault {
76
- code;
77
- name;
78
- detectedBy;
79
- enforcedIn;
80
- cures;
81
- denyText;
82
- constructor(
83
- /**
84
- * The codebook's letter — typed as the UNION of every declared code, not `string`, so
85
- * `L0_FAULT_NAMES[code]` is total and neither this module nor the deny builders need a
86
- * `?? 'unknown'` fallback. A fault added without a name fails to compile.
87
- */
88
- code, name, detectedBy, enforcedIn, cures,
89
- /**
90
- * The artifact carrying this fault's deny text. For S/C/Y that is the deny string itself; for
91
- * D/X/U/K the text is built in POSIX sh inside the rendered shim, so it is the rendered shim —
92
- * the same bytes the consumer runs, which is what the mention assertion needs to search.
93
- */
94
- denyText) {
95
- this.code = code;
96
- this.name = name;
97
- this.detectedBy = detectedBy;
98
- this.enforcedIn = enforcedIn;
99
- this.cures = cures;
100
- this.denyText = denyText;
101
- }
102
- }
103
- exports.L0Fault = L0Fault;
104
- // The deny for fault C, and the ONLY message L0 has for a repo with no webpieces.config.json at all.
105
- // Moved here from runner.ts so the fault table and the runner cannot state different cures.
106
- //
107
- // It used to name `./node_modules/.bin/wp-setup-ai-hooks` — a bin that HAS NOT EXISTED since it was
108
- // renamed to wp-install-ai-hooks. So the one command this deny prescribed was (a) not installable and
109
- // (b) not on the L0 allowlist in that spelling, i.e. the AI was handed a cure it could neither run nor
110
- // get past the guard. Now it names the installer that actually seeds the config AND is entry 8 of the
111
- // allowlist, and it says out loud that writing the config yourself is allowed through.
112
- //
113
- // ORDERING (2026-08-02): writing the file yourself now LEADS. The bare installer used to be OPTION 1,
114
- // but it seeds the config and then PROMPTS twice for a hook target, which hangs a non-interactive
115
- // agent. Writing the file is the one cure that always works, and it is the same cure every other config
116
- // problem has (see the config-validation invariant in guards/L0-tooling.md): the validator reports every
117
- // error at once, so the write/validate loop converges in a couple of passes.
118
- exports.CONFIG_MISSING_REPORT = [
119
- `❌ webpieces ai-hooks blocked this call: ${rules_config_1.CONFIG_FILENAME} not found.`,
120
- '',
121
- (0, l0_fault_codes_1.l0GuardHeader)(l0_fault_codes_1.L0_FAULT_CONFIG_MISSING, '1 violation'),
122
- ` ${rules_config_1.CONFIG_FILENAME}`,
123
- ' → the webpieces guards cannot run without it, so every OTHER tool call is blocked.',
124
- ` → ${(0, l0_fault_codes_1.l0MatrixCitation)(l0_fault_codes_1.L0_FAULT_CONFIG_MISSING)}`,
125
- '',
126
- 'Still allowed while this block is up:',
127
- ` - any Read, and ${l0_codex_read_1.CODEX_READ_STILL_ALLOWED}`,
128
- ` - any Write/Edit whose target is ${rules_config_1.CONFIG_FILENAME}`,
129
- ' - every command on the L0 allowlist, including the Fix Options below',
130
- ' THIS IS NOT A DEADLOCK - run one YOURSELF now; do not hand it back to the human.',
131
- '',
132
- ` Fix Option 1: (preferred) it needs no other tool and it never prompts - create ${rules_config_1.CONFIG_FILENAME}`,
133
- ' yourself. The validator reports EVERY missing/invalid entry at once (each with the snippet to',
134
- ' paste), so a minimal first draft converges in about two passes.',
135
- ' Fix Option 2: pick this ONLY at an interactive terminal where you can answer its two prompts - it',
136
- ' goes on to wire the Claude Code hooks and asks for a target twice, which hangs a non-interactive',
137
- ' session.',
138
- ' run EXACTLY: `pnpm exec wp-install-ai-hooks`',
139
- '',
140
- 'Do not append anything to the option you pick — the allowlist is anchored to the whole command.',
141
- ].join('\n');
142
- // The HEADER of the fault-Y deny (built out in runner.checkConfigSync, which appends the per-rule
143
- // detail as the `[…]` block's offenders). Kept here so the fault table quotes the same text the runner
144
- // emits, and so Y opens with the same `[guard-name] (layer=L0 fault=Y row=3)` coordinates as every
145
- // other L0 fault — that triple is what joins the deny to the audit line and to the matrix row.
146
- exports.CONFIG_OUT_OF_SYNC_HEADER = [
147
- `❌ webpieces ai-hooks blocked this call: ${rules_config_1.CONFIG_FILENAME} is out of sync.`,
148
- '',
149
- (0, l0_fault_codes_1.l0GuardHeader)(l0_fault_codes_1.L0_FAULT_CONFIG_OUT_OF_SYNC, '1 violation'),
150
- ` new built-in rules are present that have no entry in ${rules_config_1.CONFIG_FILENAME}`,
151
- ` → ${(0, l0_fault_codes_1.l0MatrixCitation)(l0_fault_codes_1.L0_FAULT_CONFIG_OUT_OF_SYNC)}`,
152
- ].join('\n');
153
- // Writing/repairing the file yourself. PREFERRED for both config faults, per the config-validation
154
- // invariant in guards/L0-tooling.md: every config problem cures to "make the file right", the validator
155
- // reports all errors at once so the loop converges in a couple of passes, and allowlist entry 2 permits
156
- // this edit unconditionally. (That section is the authority — do not restate its reasoning here.)
157
- const CONFIG_WRITE_CURE = new L0Cure(rules_config_1.CONFIG_FILENAME, new shim_1.L0Call('Edit', '', `/repo/${rules_config_1.CONFIG_FILENAME}`), true, 'this fault fires at all — it is the only cure that needs no other tool, and it is never denied');
158
- // Cure calls are spelled exactly as the deny messages spell them, so the mention assertion is a real
159
- // string search rather than a paraphrase.
160
- // webpieces-disable no-function-outside-class -- pure constructor helper for the L0_FAULTS literal below, in this data module
161
- function bashCure(command, preferred, discriminator) {
162
- return new L0Cure(command, new shim_1.L0Call('Bash', command, ''), preferred, discriminator);
163
- }
164
- /**
165
- * THE L0 faults, in first-match-wins order. D/X/U/K are decided in POSIX sh BEFORE the bin runs (a
166
- * stale, missing or broken validator cannot be trusted to validate itself); S/C/Y are decided inside
167
- * the bin, in JS. One model, two enforcement points.
168
- */
169
- exports.L0_FAULTS = [
170
- new L0Fault(l0_fault_codes_1.L0_FAULT_DRIFT, 'version drift — root package.json pin != installed version', 'sh, before the bin runs', 'sh', [
171
- // `pnpm install` clears D in BOTH directions — it makes installed == pin by definition — so
172
- // it is always the preferred cure. The direction only decides whether the PIN is the version
173
- // you WANT, which is what the second cure is for.
174
- bashCure('pnpm install', true, 'node_modules is OLDER than the pin, OR you are on a feature branch and want YOUR '
175
- + 'branch pin (usually the case) — it always clears the drift'),
176
- // The on-main sync is spelled `git checkout main && git pull origin main` and NOT `git pull`:
177
- // a raw pull on a FEATURE branch merges main into it and destroys the fork point, so it is
178
- // no longer on the L0 allowlist at all (see CHECKOUT_MAIN_PULL_BODY_ERE). This spelling ends
179
- // ON main, which is why it is safe from any branch — and it is a no-op checkout when you are
180
- // already there.
181
- //
182
- // And it is RAW GIT on purpose, where the workflow guards now say `pnpm wp-sync-main`
183
- // instead. The fault being cured here is `node_modules` disagreeing with the pin, so
184
- // `node_modules` is the untrustworthy thing — and every `pnpm wp-*` bin resolves through it.
185
- // An L0 cure may never be a command that has to load the package it is repairing. See the
186
- // long note on CHECKOUT_MAIN_PULL_BODY_ERE in bin/l0-allowlist.ts.
187
- 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 '
188
- + 'sync first and install second; a bare install would downgrade you'),
189
- ], (0, shim_1.renderShim)()),
190
- new L0Fault(l0_fault_codes_1.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 '
191
- + 'copies no node_modules')], (0, shim_1.renderShim)()),
192
- // U is X with the ONE input that inverts X's cure, which is why it is a separate fault and not a
193
- // sentence inside X's message: a BARE `pnpm install` is not a weaker fix here, it is a PROVABLE
194
- // no-op, and an agent that trusts the X text will run it until it gives up. See the ADD_HOOK_PKG
195
- // entry in l0-allowlist.ts for the incident.
196
- //
197
- // The ORDER of these three is the correction bought by a second incident. `pnpm add` used to be the
198
- // preferred cure, and it is the one cure that CANNOT be committed: a direct root dependency on
199
- // HOOK_PKG violates the umbrella rule (the root manifest depends on the umbrella ALONE), and the
200
- // message never said to revert it — so it was followed, and the workaround landed in a real
201
- // package.json. The package normally arrives WITH the umbrella, so a tree that is merely BEHIND is
202
- // the common cause and syncing is the cure that leaves a committable tree. The add stays last,
203
- // reachable, and explicitly labelled as a session unblock rather than a fix.
204
- new L0Fault(l0_fault_codes_1.L0_FAULT_UNDECLARED, `guard bin missing AND ${shim_1.HOOK_PKG} is not declared in package.json`, 'sh, before the bin runs', 'sh', [
205
- 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 `
206
- + 'anything being mis-declared — sync first, then install'),
207
- bashCure('pnpm install', false, 'the sync (or a raised catalog pin in ' + shim_1.WORKSPACE_MANIFEST + ', which is editable '
208
- + 'while the block is up) gave the installer something new to do — a BARE install with '
209
- + 'nothing changed reports "Lockfile is up to date" and leaves the tree as broken as it '
210
- + 'found it'),
211
- bashCure(shim_1.ADD_HOOK_PKG_CMD, false, 'nothing else worked and you need this session back — it is a session unblock, NOT a '
212
- + `fix: revert it with 'pnpm remove ${shim_1.HOOK_PKG}' before committing, because a direct `
213
- + 'root dependency on it violates the umbrella rule'),
214
- ], (0, shim_1.renderShim)()),
215
- new L0Fault(l0_fault_codes_1.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 '
216
- + 'the right version on disk and considers it installed; only the delete forces a rewrite')], (0, shim_1.renderShim)()),
217
- // S covers the WHOLE managed hook surface, not just the shim: the committed ai-hook.sh, the
218
- // .claude/settings.json entries that register them AND the managed `env` entry that pins the Bash
219
- // cwd so the hooks resolve identically for every subagent. They only work as a set — a settings file left
220
- // on a superseded form silently changes who governs, re-pinning every tree to the
221
- // primary's release — and nothing validated the registration at all before it joined this fault.
222
- new L0Fault(l0_fault_codes_1.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', [
223
- // wp-upgrade-shim leads because it is the ONLY cure that repairs EVERY managed surface, and
224
- // it is still surgical: it rewrites ai-hook.sh, each harness's registration and the env entry
225
- // and touches no config, and it imports only fs/path so it runs on a tree too broken to load
226
- // the rule engine. The INSTALLER is deliberately NOT a cure here: it also migrates the config
227
- // and prompts for a target twice, which hangs a non-interactive agent.
228
- bashCure(shim_1.UPGRADE_SHIM_CMD, true, 'this fault fires at all — it is the only cure that repairs EVERY managed surface '
229
- + '(ai-hook.sh, each harness hook registration, the anchoring of the neighbour hook '
230
- + 'commands registered beside ours, and the Claude settings env entry), and it also '
231
- + 'deletes the retired guarantee-root.sh and any entry still naming it, and it '
232
- + 'touches no config; needs installed @webpieces/ai-hook-rules 0.4.408 or newer'),
233
- // 2026-07-21: the version gap below caused a real "command not found" deadlock.
234
- bashCure(shim_1.RESTORE_SHIM_CMD, false, 'the installed @webpieces/ai-hook-rules is OLDER than 0.4.408, so wp-upgrade-shim does '
235
- + 'not exist yet — it is PARTIAL (it repairs ai-hook.sh and NOTHING else), so upgrade '
236
- + '@webpieces afterwards and run Option 1 to finish'),
237
- ],
238
- // The SAMPLE deny renders EVERY managed surface, built from HARNESS_REGISTRATIONS rather than
239
- // a hand-written trio — a doc that shows a three-surface deny while the guard can report four
240
- // is exactly the drift this generated-doc arrangement exists to make impossible.
241
- (0, shim_deny_reason_1.shimStaleDenyReason)('', '', [
242
- shim_1.SHIM_MARKER,
243
- ...hook_registration_1.HARNESS_REGISTRATIONS.flatMap((h) => [h.registrationSurface, h.neighbourSurface]),
244
- hook_registration_1.ENV_SURFACE,
245
- hook_registration_1.REVIEWER_AGENT_SURFACE,
246
- ], false)),
247
- new L0Fault(l0_fault_codes_1.L0_FAULT_CONFIG_MISSING, `${rules_config_1.CONFIG_FILENAME} missing`, 'the guard bin', 'JS', [
248
- CONFIG_WRITE_CURE,
249
- // Kept, but demoted: it seeds the file and then PROMPTS twice for a hook target.
250
- bashCure(shim_1.INSTALL_HOOKS_CMD, false, 'you are at an INTERACTIVE terminal and can answer its two hook-target prompts'),
251
- ], exports.CONFIG_MISSING_REPORT),
252
- new L0Fault(l0_fault_codes_1.L0_FAULT_CONFIG_OUT_OF_SYNC, `a loaded rule has no ${rules_config_1.CONFIG_FILENAME} key`, 'the guard bin', 'JS', [CONFIG_WRITE_CURE], exports.CONFIG_OUT_OF_SYNC_HEADER),
253
- ];
254
- /**
255
- * One fault's FIX section, rendered from its `cures` array — literal commands only, never prose.
256
- *
257
- * This is the half that used to live in hand-written docs and drift. The three fields of L0Cure map
258
- * onto the three things a blocked reader needs and nothing else: WHAT to type (the call), WHETHER it is
259
- * the default (preferred), and WHEN to pick a sibling instead (discriminator). A cure with no
260
- * discriminator would render as a menu of equals, which is how an agent picks the wrong one.
261
- */
262
- // webpieces-disable no-function-outside-class -- pure string builder for renderGuardMatrixDoc below, beside the arrays it reads
263
- function renderFixSection(fault) {
264
- const options = fault.cures.map((cure, i) => {
265
- // A Bash cure is the command verbatim; a tool-shaped one is the file it edits (allowlist entry 2).
266
- const literal = cure.isCommand() ? `\`${cure.call.command}\`` : `edit \`${cure.mention}\` yourself`;
267
- const label = cure.preferred ? `Option ${i + 1} (preferred)` : `Option ${i + 1}`;
268
- return `- **${label}**: ${literal} ← pick this when ${cure.discriminator}`;
269
- });
270
- return [`### \`${fault.code}\` — ${fault.name}`, '', ...options, ''];
271
- }
272
- /**
273
- * Render webpieces.guard-matrix.md from L0_FAULTS + L0_ALLOWLIST.
274
- *
275
- * A unit test locks the committed template byte-identical to this output, the same way
276
- * templates/ai-hook.sh is locked to renderShim(). That is what makes the doc assertable instead of
277
- * aspirational: the table in the doc IS the array the guard consults.
278
- */
279
- // webpieces-disable no-function-outside-class -- pure string builder over the two exported arrays, beside them in this module
280
- function renderGuardMatrixDoc() {
281
- return [
282
- '# webpieces guard matrix — L0 (tooling integrity)',
283
- '',
284
- 'GENERATED from `L0_FAULTS` + `L0_ALLOWLIST` in `@webpieces/ai-hook-rules`. Do not hand-edit —',
285
- 'a unit test locks this file byte-identical to `renderGuardMatrixDoc()`, so the table below is',
286
- 'the array the guard actually consults, not a description of it.',
287
- '',
288
- 'L0 is the OUTERMOST guard layer. It blocks work while `node_modules`, the committed shim, or',
289
- '`webpieces.config.json` are in a state that makes every other guard untrustworthy. If you are',
290
- 'reading this, one of the faults below fired and named this file.',
291
- '',
292
- '## The faults',
293
- '',
294
- 'THE JOIN KEYS ARE `guard`, `fault=` and `row=`. Every L0 deny opens',
295
- '`[<guard>] (layer=L0 fault=<code> row=3, …)`, and every audit line — from BOTH halves of L0, the',
296
- '`sh` shim and the guard bin — carries `layer=L0 row=<n> fault=<code>`. So one grep lands you in',
297
- 'the deny, the log line and the row below. The guard names come from `L0_FAULT_NAMES` and the row',
298
- 'numbers from `L0_ROW_*`, both spelled in exactly one place (`core/l0-fault-codes.ts`).',
299
- '',
300
- '| code | guard | fault | detected by | enforced in |',
301
- '|---|---|---|---|---|',
302
- ...exports.L0_FAULTS.map((f) => `| \`${f.code}\` | \`${l0_fault_codes_1.L0_FAULT_NAMES[f.code]}\` | ${f.name} | ${f.detectedBy} | ${f.enforcedIn} |`),
303
- '',
304
- 'First match wins. `D`/`X`/`U`/`K` are decided in POSIX `sh` inside the committed shim, BEFORE the',
305
- 'guard bin runs — a stale, missing or broken validator cannot be trusted to validate itself.',
306
- '',
307
- '## The fix, per fault',
308
- '',
309
- 'Every command below is rendered from that fault\'s `cures` array and is asserted, by unit test,',
310
- 'to be accepted by `isAllowed()` — so nothing here can be a command the guard then rejects. Type',
311
- 'the option you pick EXACTLY as written and run nothing else on that line.',
312
- '',
313
- ...exports.L0_FAULTS.flatMap(renderFixSection),
314
- ...renderMatrixAndAllowlist(),
315
- ].join('\n');
316
- }
317
- /**
318
- * The second half of the doc: the three-row matrix and the ONE allowlist. Split out of
319
- * renderGuardMatrixDoc solely to keep it inside the method-line budget — the join order is what makes
320
- * the two halves one file, so keep them adjacent and keep the byte-lock test as the arbiter.
321
- */
322
- // webpieces-disable no-function-outside-class -- second half of renderGuardMatrixDoc's string, beside it in this module
323
- function renderMatrixAndAllowlist() {
324
- return [
325
- '## The matrix',
326
- '',
327
- 'L0 has NO genuine second dimension. Every branch reduces to one question:',
328
- '',
329
- '| # | fault | on the allowlist? | outcome |',
330
- '|---|---|---|---|',
331
- '| 1 | none | — | hand down to the next guard layer |',
332
- `| ${l0_fault_codes_1.L0_ROW_ALLOWLISTED} | any | yes | PASS or ALLOW (see the entry) |`,
333
- `| ${l0_fault_codes_1.L0_ROW_BLOCKED} | any | no | BLOCK — **only the message varies by fault** |`,
334
- '',
335
- `Row ${l0_fault_codes_1.L0_ROW_BLOCKED} is the only row that blocks, so every L0 deny cites it — \`row=${l0_fault_codes_1.L0_ROW_BLOCKED}\` in the`,
336
- 'deny header, `row=' + l0_fault_codes_1.L0_ROW_BLOCKED + '` on the audit line, and this row here. Same numbers as L1 uses for',
337
- 'its own rows (see `L1_ROWS`), and for the same reason: a row number is IDENTITY, so it is never reused.',
338
- '',
339
- 'The tool is not a dimension either: "any Read" is an allowlist ENTRY, not a tool check.',
340
- '',
341
- '## The allowlist',
342
- '',
343
- 'ONE list, consulted identically by every fault. A cure that cannot help a given fault also',
344
- 'cannot hurt it, and gating each entry on a fault is what produced four real defects (a stale',
345
- 'shim that denied `pnpm install` and every git sync; faults that denied every Read; a config fault',
346
- 'that denied `rm -rf node_modules && pnpm install` while allowing a bare `pnpm install`).',
347
- '',
348
- '| # | allowed | outcome |',
349
- '|---|---|---|',
350
- ...shim_1.L0_ALLOWLIST.map((e, i) => `| ${i + 1} | ${e.label} | ${e.kind.toUpperCase()} |`),
351
- '',
352
- '- **PASS** — L0 has no objection; the call falls THROUGH so the downstream guards still judge it.',
353
- '- **ALLOW** — terminal; bypasses everything, because a cure must stay reachable even when a',
354
- ' downstream guard would block it.',
355
- '',
356
- 'Every Bash entry is anchored to the WHOLE command. Appending `&& git status` makes it a DIFFERENT',
357
- 'command and it is rejected again — that is not the guard refusing its own cure.',
358
- '',
359
- 'On an UNGATED entry a leading `cd <dir> &&`, a trailing `2>&1` and a pipe into `tail`/`head` are',
360
- 'tolerated; nothing else is. **The harness-gated read row tolerates NONE of the three** — not the',
361
- '`cd` prefix, not the redirect, not the pipe — so `cat f 2>&1` and `cat f | head -20` are both',
362
- 'rejected. That is deliberate, not an oversight: the row means exactly what',
363
- '`core/shell-read-parity.ts` means by "this is a read", and that module treats a pipe or a redirect',
364
- 'as proof the command is more than one. Type the bare command.',
365
- '',
366
- '`git merge` is deliberately NOT on this list. Main is merged ONLY through the 3-point fork merge',
367
- '(`pnpm wp-start-update`, or `pnpm wp-start-upsert-pr` when a PR is already open).',
368
- '',
369
- '## Known asymmetry',
370
- '',
371
- 'Under `S`/`C`/`Y` the guard bin IS running, so a PASS really does fall through to the downstream',
372
- 'guards. Under `D`/`X`/`U`/`K` the bin is never executed, so there is nothing to fall through to and a',
373
- 'PASS degenerates into a terminal allow — reads are unguarded during those three faults.',
374
- '',
375
- '## Widening L0',
376
- '',
377
- 'Add an entry to `L0_ALLOWLIST` in `packages/tooling/ai-hook-rules/src/bin/shim.ts`. That array is',
378
- 'the single source for the JS allowlist, the `grep -E` inside the rendered shim, and this file.',
379
- '',
380
- ];
381
- }
382
- /**
383
- * Drop the matrix doc where the AI can read it, and return its absolute path ('' if it could not be
384
- * written). Called from the L0 BLOCK path so the deny can say `READ <path>`.
385
- *
386
- * Best-effort by design: this runs while the tree is already known-broken, and a missing template (an
387
- * @webpieces/rules-config older than this package) must degrade the deny message, never replace it
388
- * with a crash.
389
- */
390
- // webpieces-disable no-function-outside-class -- sibling of renderGuardMatrixDoc in this module
391
- function writeGuardMatrixDoc(workspaceRoot) {
392
- // eslint-disable-next-line @webpieces/no-unmanaged-exceptions
393
- try {
394
- return (0, rules_config_1.writeTemplate)(workspaceRoot, exports.GUARD_MATRIX_DOC);
395
- }
396
- catch (err) {
397
- const error = (0, to_error_1.toError)(err);
398
- void error; // best-effort: no doc → the deny simply omits the pointer
399
- return '';
400
- }
401
- }
402
- /**
403
- * The `READ <path>` pointer appended to an L0 deny, or '' when the doc could not be written.
404
- *
405
- * It opens with a NEWLINE, not a space: the JS-side L0 denies render in the house format now (a header,
406
- * a `[guard-name]` block, `Fix Option N:` lines), so a pointer glued onto the end of the last line would
407
- * be the one place the shape broke. A real newline is safe on both call paths — denyJson() JSON.stringifies
408
- * it, exactly as it does for every multi-line L1 report.
409
- */
410
- // webpieces-disable no-function-outside-class -- sibling of writeGuardMatrixDoc in this module
411
- function guardMatrixPointer(docPath) {
412
- if (docPath === '')
413
- return '';
414
- return `\nThe full L0 guard matrix - every fault and everything that is allowed through - is at ${docPath}; READ it if you are unsure why this call was blocked.`;
415
- }
416
- //# sourceMappingURL=l0-matrix.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"l0-matrix.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/core/l0-matrix.ts"],"names":[],"mappings":";;;AAoTA,oDAqCC;AA6ED,kDASC;AAWD,gDAGC;AA7bD,0DAAyE;AAEzE,sCAIqB;AACrB,wDAAgE;AAChE,gEAA2H;AAC3H,8DAA8D;AAC9D,qDAI0B;AAC1B,yCAAqC;AAErC,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;AACU,QAAA,gBAAgB,GAAG,2BAA2B,CAAC;AAE5D;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pB,EAAE;QACF,kGAAkG;QAClG,uGAAuG;QACvG,yFAAyF;QACzF,EAAE;QACF,gBAAgB;QAChB,EAAE;QACF,mGAAmG;QACnG,gGAAgG;QAChG,EAAE;KACL,CAAC;AACN,CAAC;AAED;;;;;;;GAOG;AACH,gGAAgG;AAChG,SAAgB,mBAAmB,CAAC,aAAqB;IACrD,8DAA8D;IAC9D,IAAI,CAAC;QACD,OAAO,IAAA,4BAAa,EAAC,aAAa,EAAE,wBAAgB,CAAC,CAAC;IAC1D,CAAC;IAAC,OAAO,GAAY,EAAE,CAAC;QACpB,MAAM,KAAK,GAAG,IAAA,kBAAO,EAAC,GAAG,CAAC,CAAC;QAC3B,KAAK,KAAK,CAAC,CAAC,0DAA0D;QACtE,OAAO,EAAE,CAAC;IACd,CAAC;AACL,CAAC;AAED;;;;;;;GAOG;AACH,+FAA+F;AAC/F,SAAgB,kBAAkB,CAAC,OAAe;IAC9C,IAAI,OAAO,KAAK,EAAE;QAAE,OAAO,EAAE,CAAC;IAC9B,OAAO,2FAA2F,OAAO,wDAAwD,CAAC;AACtK,CAAC","sourcesContent":["import { CONFIG_FILENAME, writeTemplate } from '@webpieces/rules-config';\n\nimport {\n ADD_HOOK_PKG_CMD, CHECKOUT_MAIN_PULL_CMD, HOOK_PKG, INSTALL_HOOKS_CMD, L0AllowEntry, L0Call,\n L0_ALLOWLIST, RECOVERY_CMD, RESTORE_SHIM_CMD, SHIM_MARKER, UPGRADE_SHIM_CMD, WORKSPACE_MANIFEST,\n renderShim,\n} from '../bin/shim';\nimport { CODEX_READ_STILL_ALLOWED } from '../bin/l0-codex-read';\nimport { ENV_SURFACE, HARNESS_REGISTRATIONS, HarnessRegistration, REVIEWER_AGENT_SURFACE } from '../bin/hook-registration';\nimport { shimStaleDenyReason } from '../bin/shim-deny-reason';\nimport {\n L0_FAULT_BIN_BROKEN, L0_FAULT_BIN_MISSING, L0_FAULT_CONFIG_MISSING, L0_FAULT_CONFIG_OUT_OF_SYNC,\n L0_FAULT_DRIFT, L0_FAULT_NAMES, L0_FAULT_SHIM_STALE, L0_FAULT_UNDECLARED, L0FaultCode,\n L0_ROW_ALLOWLISTED, L0_ROW_BLOCKED, l0GuardHeader, l0MatrixCitation,\n} from './l0-fault-codes';\nimport { toError } from './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 const GUARD_MATRIX_DOC = 'webpieces.guard-matrix.md';\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.\nexport const CONFIG_MISSING_REPORT = [\n `❌ webpieces ai-hooks blocked this call: ${CONFIG_FILENAME} not found.`,\n '',\n l0GuardHeader(L0_FAULT_CONFIG_MISSING, '1 violation'),\n ` ${CONFIG_FILENAME}`,\n ' → the webpieces guards cannot run without it, so every OTHER tool call is blocked.',\n ` → ${l0MatrixCitation(L0_FAULT_CONFIG_MISSING)}`,\n '',\n 'Still allowed while this block is up:',\n ` - any Read, and ${CODEX_READ_STILL_ALLOWED}`,\n ` - any Write/Edit whose target is ${CONFIG_FILENAME}`,\n ' - every command on the L0 allowlist, including the Fix Options below',\n ' THIS IS NOT A DEADLOCK - run one YOURSELF now; do not hand it back to the human.',\n '',\n ` Fix Option 1: (preferred) it needs no other tool and it never prompts - create ${CONFIG_FILENAME}`,\n ' yourself. The validator reports EVERY missing/invalid entry at once (each with the snippet to',\n ' paste), so a minimal first draft converges in about two passes.',\n ' Fix Option 2: pick this ONLY at an interactive terminal where you can answer its two prompts - it',\n ' goes on to wire the Claude Code hooks and asks for a target twice, which hangs a non-interactive',\n ' session.',\n ' run EXACTLY: `pnpm exec wp-install-ai-hooks`',\n '',\n 'Do not append anything to the option you pick — the allowlist is anchored to the whole command.',\n].join('\\n');\n\n// The HEADER of the fault-Y deny (built out in runner.checkConfigSync, which appends the per-rule\n// detail as the `[…]` block's offenders). Kept here so the fault table quotes the same text the runner\n// emits, and so Y opens with the same `[guard-name] (layer=L0 fault=Y row=3)` coordinates as every\n// other L0 fault — that triple is what joins the deny to the audit line and to the matrix row.\nexport const CONFIG_OUT_OF_SYNC_HEADER = [\n `❌ webpieces ai-hooks blocked this call: ${CONFIG_FILENAME} is out of sync.`,\n '',\n l0GuardHeader(L0_FAULT_CONFIG_OUT_OF_SYNC, '1 violation'),\n ` new built-in rules are present that have no entry in ${CONFIG_FILENAME}`,\n ` → ${l0MatrixCitation(L0_FAULT_CONFIG_OUT_OF_SYNC)}`,\n].join('\\n');\n\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/ai-hook-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/ai-hook-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/ai-hook-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/ai-hook-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\nexport function writeGuardMatrixDoc(workspaceRoot: string): string {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n return writeTemplate(workspaceRoot, GUARD_MATRIX_DOC);\n } catch (err: unknown) {\n const error = toError(err);\n void error; // best-effort: no doc → the deny simply omits the pointer\n return '';\n }\n}\n\n/**\n * The `READ <path>` pointer appended to an L0 deny, or '' when the doc could not be written.\n *\n * It opens with a NEWLINE, not a space: the JS-side L0 denies render in the house format now (a header,\n * a `[guard-name]` block, `Fix Option N:` lines), so a pointer glued onto the end of the last line would\n * be the one place the shape broke. A real newline is safe on both call paths — denyJson() JSON.stringifies\n * it, exactly as it does for every multi-line L1 report.\n */\n// webpieces-disable no-function-outside-class -- sibling of writeGuardMatrixDoc in this module\nexport function guardMatrixPointer(docPath: string): string {\n if (docPath === '') return '';\n return `\\nThe full L0 guard matrix - every fault and everything that is allowed through - is at ${docPath}; READ it if you are unsure why this call was blocked.`;\n}\n"]}