@webpieces/ai-hook-rules 0.4.839 → 0.4.841

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,635 +1,37 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.effectiveBashCwd = effectiveBashCwd;
4
- exports.isGitOrGhCommand = isGitOrGhCommand;
3
+ exports.SourceHookRules = exports.SourceHookRuleSet = void 0;
5
4
  exports.run = run;
6
- exports.runBash = runBash;
7
- exports.runRead = runRead;
8
- exports.runRuleCheck = runRuleCheck;
9
5
  const tslib_1 = require("tslib");
10
6
  const path = tslib_1.__importStar(require("path"));
11
7
  const rules_config_1 = require("@webpieces/rules-config");
12
- const build_context_1 = require("./build-context");
13
- const delete_scoped_rules_1 = require("./delete-scoped-rules");
14
- const version_sync_1 = require("./version-sync");
15
- const effective_tree_1 = require("./effective-tree");
16
- const target_tree_1 = require("./target-tree");
17
- const excluded_paths_1 = require("./excluded-paths");
18
- const excluded_path_escape_1 = require("./excluded-path-escape");
19
- const force_to_root_1 = require("./force-to-root");
8
+ const hook_runtime_1 = require("@webpieces/hook-runtime");
20
9
  const load_rules_1 = require("./load-rules");
21
- const missing_directory_1 = require("./missing-directory");
22
- const match_rule_1 = require("./rules/match-rule");
23
- const main_sync_timeout_1 = require("./main-sync-timeout");
24
- const decision_log_1 = require("./decision-log");
25
- const to_error_1 = require("./to-error");
26
- const report_1 = require("./report");
27
- const read_only_inspection_1 = require("./read-only-inspection");
28
- const shim_1 = require("../bin/shim");
29
- const l0_fault_codes_1 = require("./l0-fault-codes");
30
- const l0_matrix_1 = require("./l0-matrix");
31
- const l1_rows_1 = require("./l1-rows");
32
- const l1_matrix_doc_1 = require("./l1-matrix-doc");
33
- const types_1 = require("./types");
34
- // Restrict loaded rules to the category this hook invocation runs. The two split hooks each pass a
35
- // disjoint category ('rules' = code-style, 'guards' = the hookGuards section); 'all' runs both (the
36
- // openclaw plugin adapter, a single before_tool_call hook). isHookGuard is the shared classifier in
37
- // @webpieces/rules-config.
38
- // isHookGuard is asked about the rule's CONFIG KEY, never its name. Since the collapse those differ
39
- // for every class behind a policy key — `feature-branch-guard` is a rule NAME whose key is
40
- // `branch-state-guard` — and asking about the name would classify all eight collapsed guards as
41
- // code-style rules, i.e. run them in the wrong hook and never in the guards hook at all.
42
- function filterByMode(rules, mode) {
43
- if (mode === 'all')
44
- return rules;
10
+ class SourceHookRuleSet extends hook_runtime_1.HookRuleSet {
11
+ builtInRules;
12
+ extensionRules;
13
+ constructor(builtInRules, extensionRules, configuredRules) {
14
+ super([...builtInRules, ...extensionRules], configuredRules);
15
+ this.builtInRules = builtInRules;
16
+ this.extensionRules = extensionRules;
17
+ }
18
+ }
19
+ exports.SourceHookRuleSet = SourceHookRuleSet;
20
+ class SourceHookRules {
21
+ load(loaded) {
22
+ const builtIns = (0, load_rules_1.loadBuiltInRules)(loaded.rulesConfig);
23
+ const custom = (0, load_rules_1.loadCustomRules)(loaded.rulesConfig, path.dirname(loaded.configPath ?? ''));
24
+ return new SourceHookRuleSet(builtIns, [...custom, ...(0, load_rules_1.loadMatchRules)(loaded.matchRules)], [...builtIns, ...custom]);
25
+ }
26
+ }
27
+ exports.SourceHookRules = SourceHookRules;
28
+ // webpieces-disable no-function-outside-class -- preserves the existing source runner entry point
29
+ function run(toolKind, input, cwd, mode = 'rules') {
45
30
  if (mode === 'guards')
46
- return rules.filter((r) => (0, rules_config_1.isHookGuard)(r.configKey));
47
- return rules.filter((r) => !(0, rules_config_1.isHookGuard)(r.configKey));
48
- }
49
- // The cwd a command actually runs from, after its own leading `cd`/`pushd` run. Thin delegate kept
50
- // for the callers (and specs) that only need the directory; the full tree classification — primary
51
- // clone vs linked worktree vs nested clone vs outside any repo — is EffectiveTreeResolver.resolve().
52
- // webpieces-disable no-function-outside-class -- sibling of the module-scope runner helpers; the whole file is functions and a lone class here would break its shape
53
- function effectiveBashCwd(command, cwd) {
54
- return new effective_tree_1.EffectiveTreeResolver().effectiveCwd(command, cwd);
55
- }
56
- // The resolved gated-command strings the PR-lifecycle guards print, straight off the loaded
57
- // `commands.guardHints`. Handed to the rules at construction rather than injected into their config
58
- // entries under guard-name literals — the injection this replaces could miss a rename silently.
59
- // webpieces-disable no-function-outside-class -- sibling of the module-scope runner helpers; the whole file is functions and a lone class here would break its shape
60
- function guardHintsOf(loaded) {
61
- return new load_rules_1.GuardHintCommands(loaded.commands.upsertPr, loaded.commands.mergeComplete);
62
- }
63
- // A git or gh invocation anywhere in the command (start, or after a ;/&&/|| separator or pipe).
64
- const GIT_OR_GH_RE = /(?:^|[;&|]\s*)(?:git|gh)\b/;
65
- function isGitOrGhCommand(command) {
66
- return GIT_OR_GH_RE.test(command);
67
- }
68
- // Fault C (webpieces.config.json missing) — the deny text lives in ./l0-matrix beside the rest of the
69
- // L0 fault table, so the message and the allowlist can never prescribe different cures. `cwd` is used
70
- // only to drop the matrix doc where the AI can read it (the config root does not exist yet here).
71
- //
72
- // THE ALLOWLIST ESCAPE IS THE CALLER'S (moved out 2026-09-01): behind an optional `command` it could
73
- // not see the harness, so the gated half of the list was unreachable under C while
74
- // CONFIG_MISSING_REPORT promised it. See l0FaultAllows. This has one job now: build the block.
75
- // webpieces-disable no-function-outside-class -- sibling of the module-scope runner helpers; the whole file is functions and a lone class here would break its shape
76
- function configMissingBlock(cwd) {
77
- const root = new rules_config_1.RepoRootFinder().resolveRepoRoot(cwd);
78
- // Stamped with its L0 letter so the block is greppable as fault C wherever it is recorded — the
79
- // adapter carries it to the audit line rather than re-deriving it from the report text.
80
- return new types_1.BlockedResult(l0_matrix_1.CONFIG_MISSING_REPORT + (0, l0_matrix_1.guardMatrixPointer)((0, l0_matrix_1.writeGuardMatrixDoc)(root)), l0_fault_codes_1.L0_FAULT_CONFIG_MISSING);
81
- }
82
- function run(toolKind, input, cwd, mode = 'all') {
83
- return runInternal(toolKind, input, cwd, mode);
84
- }
85
- function runInternal(toolKind, input, cwd, mode) {
86
- const loaded = (0, rules_config_1.loadAndValidate)(cwd);
87
- if (loaded.configPath === null)
88
- return configMissingBlock(cwd);
89
- const workspaceRoot = path.dirname(loaded.configPath);
90
- // Always allow edits to webpieces.config.json — it's the fix target when out of sync
91
- if (path.resolve(input.filePath) === path.resolve(loaded.configPath)) {
92
- return null;
93
- }
94
- // …and the same PASS for the machine-local `~/.webpieces/config.json` (a bad key there fails a `wp-*`
95
- // command with an instruction to edit it, so blocking the edit would wedge the agent inside the
96
- // failure) and for the two ROOT MANIFESTS a pin lives in — L1 row 8 PROMISED that edit and its cure IS
97
- // it. isRootManifest, never a basename: this returns EARLY, so basename would unrule every
98
- // package.json in the repo. It admits any tree's root (the config sits beside it), which is what a
99
- // worktree's own cure needs — the same tree `workspaceRoot` above already names.
100
- if ((0, shim_1.isRootManifest)(input.filePath) || new rules_config_1.HomeConfigService().isHomeConfigPath(input.filePath)) {
101
- return null;
102
- }
103
- // Built-in/custom rules PLUS the client-authored match-rules (content guards). Match-rules run only
104
- // in the file-edit path (they are code-style, so filterByMode keeps them out of the bash/guards path).
105
- const allRules = [...(0, load_rules_1.loadRules)(loaded.rulesConfig, workspaceRoot, guardHintsOf(loaded)), ...(0, load_rules_1.loadMatchRules)(loaded.matchRules)];
106
- const modeRules = filterByMode(allRules, mode);
107
- if (modeRules.length === 0)
108
- return null;
109
- // Suppress enforcement for files under this category's excludePaths (e.g. vendored repos under
110
- // repositories/**). Exclusion is all-or-nothing per category, so an excluded file drops the whole
111
- // rule set and is fully hands-off — no violations AND no config-sync nag on those files.
112
- const governed = new target_tree_1.TargetTreeResolver().governedPath(input.filePath, workspaceRoot);
113
- const relativePath = governed.relativePath;
114
- const rules = new delete_scoped_rules_1.DeleteScopedRules().narrow(toolKind, (0, excluded_paths_1.filterByExcludedPaths)(modeRules, governed, loaded.excludePaths));
115
- if (rules.length === 0)
116
- return null;
117
- // Config-sync applies only to built-in/custom rules; match-rules have their own validated section
118
- // (loadAndValidate already rejected an invalid `match-rules`), so they must not trip the sync nag.
119
- const outOfSync = checkConfigSync(rules.filter((r) => !(r instanceof match_rule_1.MatchRule)), loaded.rulesConfig);
120
- if (outOfSync)
121
- return outOfSync;
122
- const contexts = (0, build_context_1.buildContexts)(toolKind, input, workspaceRoot, governed);
123
- const editGroups = runEditRules(rules, contexts.editContexts);
124
- const fileGroups = runFileRules(rules, contexts.fileContext);
125
- const allGroups = [...editGroups, ...fileGroups];
126
- if (allGroups.length === 0)
127
- return null;
128
- const report = (0, report_1.formatReport)(relativePath, allGroups);
129
- return new types_1.BlockedResult(report);
130
- }
131
- // SINGLETON, deliberately: WebpiecesVersions memoizes per root, and the same two roots are asked for on
132
- // every Bash call. A fresh instance per call would spawn `git worktree list` and re-read two manifests
133
- // on the hook's blocking path each time.
134
- const VERSION_SYNC = new version_sync_1.VersionSyncGuard();
135
- // There is deliberately NO agent parameter. It existed only for CoordinatorWorktreeGuard, which asked
136
- // WHO was calling; that guard is gone and its replacement asks WHICH TREE the command acts on. Agent
137
- // identity was measured untrustworthy for that question anyway — a worktree-isolated agent auto-reaped
138
- // at a turn boundary silently resumes with its cwd on the primary clone — so a guard must never infer
139
- // a tree from who is asking.
140
- // webpieces-disable no-function-outside-class -- sibling of run()/runRead() in this module; the whole runner is module-scope functions and a lone class for this one entry point would break the file's shape
141
- function runBash(command, cwd, mode, aiType) {
142
- return runBashInternal(command, cwd, mode, aiType);
143
- }
144
- // The name of the ONLY rule permitted to block a Read. Reads are the highest-blast-radius tool
145
- // there is, so this path is an explicit single-rule allowlist rather than the general rule loop.
146
- const READ_SCOPED_GUARDS = new Set(['read-stale-guard']);
147
- /**
148
- * The Read path. Deliberately NOT `run()`:
149
- *
150
- * - NO config-sync check. A rule present in code but missing from webpieces.config.json blocks
151
- * every Write/Edit/Bash by design — but applying that to Read would mean an upgrade that adds
152
- * any new rule instantly blocks the agent from reading the very config file it must edit to fix
153
- * it. Reads must never carry that failure mode.
154
- * - NO general rule loop. Only READ_SCOPED_GUARDS run, so no code-style rule can ever see a Read.
155
- * - Fails OPEN everywhere, including on a thrown rule (the caller catches and allows).
156
- *
157
- * Returns null (allow) unless the one guard fires.
158
- */
159
- // webpieces-disable no-function-outside-class -- sibling of run()/runBash() in this module; the whole runner is module-scope functions and a lone class for this one entry point would break the file's shape
160
- function runRead(filePath, cwd, mode = 'all') {
161
- // Code-style mode has nothing to say about a read.
162
- if (mode === 'rules')
163
31
  return null;
164
32
  const loaded = (0, rules_config_1.loadAndValidate)(cwd);
165
- // No config → nothing to enforce. Unlike the edit path we do NOT block: an unconfigured repo
166
- // must still be readable.
167
33
  if (loaded.configPath === null)
168
- return null;
169
- const workspaceRoot = path.dirname(loaded.configPath);
170
- // Same git-repo-boundary governance as bash, through the SAME resolver: a read inside a different
171
- // clone is out of scope. (No command to parse here, so the shell cwd IS the effective cwd.)
172
- if (new effective_tree_1.EffectiveTreeResolver().resolve('', cwd, workspaceRoot).kind === 'foreign')
173
- return null;
174
- const governed = new target_tree_1.TargetTreeResolver().governedPath(filePath, workspaceRoot);
175
- const relativePath = governed.relativePath;
176
- const all = (0, load_rules_1.loadRules)(loaded.rulesConfig, workspaceRoot, guardHintsOf(loaded));
177
- const rules = (0, excluded_paths_1.filterByExcludedPaths)(all.filter((r) => READ_SCOPED_GUARDS.has(r.name)), governed, loaded.excludePaths);
178
- if (rules.length === 0)
179
- return null;
180
- const ctx = new types_1.FileContext('Read', filePath, relativePath, workspaceRoot, 0, 0, 0, 0);
181
- const groups = runFileRules(rules, ctx);
182
- if (groups.length === 0)
183
- return null;
184
- return new types_1.BlockedResult((0, report_1.formatReport)(relativePath, groups, report_1.READ_SUBJECT));
185
- }
186
- // L0 cure bypass — every command on THE L0 allowlist passes here, ahead of any config load. A
187
- // webpieces.config.json that is ahead of the installed validator (new rule tokens the published
188
- // binary doesn't know yet) makes loadAndValidate() throw and would deny `pnpm install` — the very
189
- // command that updates the validator (deadlock).
190
- //
191
- // This used to test INSTALLER_ALLOW_JS alone, which made the config faults (C = config missing,
192
- // Y = config out of sync) accept a bare `pnpm install` while denying `rm -rf node_modules && pnpm
193
- // install` — the one cure that works when node_modules is CORRUPT rather than merely stale. Same
194
- // intent, opposite verdict, for no reason anyone recorded. Each alternative is still anchored at both
195
- // ends, so `pnpm install && rm -rf /` still falls to the guards.
196
- //
197
- // It tests the CURE subset (L0_CURE_ALLOW_JS), not the whole list, and the distinction matters here
198
- // and nowhere else: this call site runs BEFORE any fault has been established, so whatever it accepts
199
- // is waved past the L1 guards on a perfectly healthy repo too. A repair command has to be waved past —
200
- // it runs before the config can be loaded at all. Read-only ORIENTATION does not: it fixes nothing, and
201
- // letting `git status` through here would delete force-to-root as a side effect of adding `pwd`. Under
202
- // an actual fault, l0FaultAllows() below consults the WHOLE list.
203
- // webpieces-disable no-function-outside-class -- sibling of the module-scope runner helpers; the whole file is functions and a lone class here would break its shape
204
- function isL0CureCommand(command) {
205
- return shim_1.L0_CURE_ALLOW_JS.test(command.trim());
206
- }
207
- // The FULL L0 list, asked only where this file has actually detected an L0 fault (C = config missing,
208
- // Y = config out of sync). D/X/U/K are decided in the shim, which greps the same union.
209
- // IT ASKS `isAllowed()`, not a regex: that is the ONE question both halves of L0 ask, and the only
210
- // place harness-gated entries are consulted. Testing `L0_ALLOW_JS` directly (which is what this did)
211
- // dropped the Codex read under C and Y while D/X/U/K honoured it — a per-fault carve-out again.
212
- // webpieces-disable no-function-outside-class -- sibling of the module-scope runner helpers; the whole file is functions and a lone class here would break its shape
213
- function l0FaultAllows(command, aiType) {
214
- return (0, shim_1.isAllowed)('Bash', command.trim(), '', aiType) !== null;
215
- }
216
- // The L0 cure bypass's audit line. Anchored at the repo root that owns `.webpieces` — RepoRootFinder
217
- // (config-walk-up first, then git toplevel) is the authority for that, and it is correct in a linked
218
- // worktree because each worktree checks out its own webpieces.config.json. This runs BEFORE
219
- // loadAndValidate, which is why it resolves the root itself rather than using workspaceRoot.
220
- // webpieces-disable no-function-outside-class -- sibling of the module-scope runner helpers; the whole file is functions and a lone class here would break its shape
221
- function logL0CureBypass(command, cwd) {
222
- const root = new rules_config_1.RepoRootFinder().resolveRepoRoot(cwd);
223
- (0, decision_log_1.logGuardDecision)(root, new decision_log_1.GuardDecision('-', 'Bash', command, (0, decision_log_1.branchForLog)(root), 'ALLOW', 'L0 cure bypass (always allowed)', '-', l0_fault_codes_1.L0_FAULT_NONE, decision_log_1.MATRIX_L0_ALLOW));
224
- }
225
- /**
226
- * Load the config for the bash path — but do NOT let an unloadable config trap the tools needed to
227
- * repair it.
228
- *
229
- * loadAndValidate throws an InformAiError when webpieces.config.json is unparseable (a real syntax
230
- * error, or leftover `<<<<<<< HEAD` markers mid-merge) or fails validation. That throw propagates to
231
- * the hook adapter, which fails CLOSED and denies the command — correct for work, since a config that
232
- * did not load means no guards ran. But it denied `cat`/`grep`/`sed -n` on webpieces.config.json too,
233
- * i.e. it blocked the only way to see the problem it was reporting. Observed live, twice.
234
- *
235
- * So: on a load failure, a provably-inert INSPECTION command is allowed through (returns null, "no
236
- * block"), matching the escape hatch every other layer already grants this file. Everything else —
237
- * every write, every git/gh command, every build — still hits the same hard failure as before. The
238
- * bypass cannot be widened by accident; see ReadOnlyInspectionScan for how narrow "inert" is.
239
- *
240
- * Returns the loaded config, or null meaning "allow this command without guards".
241
- */
242
- // webpieces-disable no-function-outside-class -- sibling of the module-scope runner helpers; the whole file is functions and a lone class here would break its shape
243
- function loadConfigOrAllowInspection(command, cwd) {
244
- // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- rethrown unchanged unless the command is provably inert
245
- try {
246
- return (0, rules_config_1.loadAndValidate)(cwd);
247
- }
248
- catch (err) {
249
- const error = (0, to_error_1.toError)(err);
250
- if (error instanceof types_1.InformAiError && new read_only_inspection_1.ReadOnlyInspectionScan().isReadOnlyInspection(command)) {
251
- return null;
252
- }
253
- throw error;
254
- }
255
- }
256
- // Version skew: this worktree pins a different @webpieces than the MAIN tree that governs it. The guard
257
- // hooks are absolute, so the main tree's binary judges every tree — which is fine until the two trees
258
- // disagree about which release that should be. L1 row 8; guards/L1-location.md carries the table.
259
- // webpieces-disable no-function-outside-class -- sibling of the other module-scope runner helpers; the whole file is functions and a lone class here would break its shape
260
- function versionSkewBlock(command, tree, aiType) {
261
- const report = VERSION_SYNC.block(command, tree, aiType);
262
- return report === null ? null : new types_1.BlockedResult(report);
263
- }
264
- // Where the command lands in L1's five dimensions (K/A/R/G/P). The ONE place the runner's view of the
265
- // world is translated into the matrix's vocabulary — see L1Classification.forEnforcement for why
266
- // TreeKind 'outside' currently classifies as `p`.
267
- // webpieces-disable no-function-outside-class -- sibling of the other module-scope runner helpers; the whole file is functions and a lone class here would break its shape
268
- function l1Classify(command, tree) {
269
- return l1_rows_1.L1Classification.forEnforcement(tree.kind, VERSION_SYNC.skewed(tree), new read_only_inspection_1.ReadOnlyInspectionScan().isReadOnlyInspection(command), isGitOrGhCommand(command), path.resolve(tree.effectiveCwd) === path.resolve(tree.root));
270
- }
271
- // The structural L1 blocks, in order: the misplaced-`cd` PRE-STAGE, then version skew (row 8), then
272
- // force-to-root (row 5). None is a configurable rule — they are decided from the command text, the
273
- // resolved tree and the caller, so they run as one step here rather than as three near-identical
274
- // stanzas in runBashInternal.
275
- //
276
- // For the two TREE-BASED blocks the ORDER and the CHOICE are not written here: they come from L1_ROWS
277
- // (l1-rows.ts), the same array guards/L1-location.md is rendered from. Classify, take the first
278
- // matching row, dispatch on its blockId — so a row deleted from the array is a block that stops firing,
279
- // and the doc cannot describe a table the guard does not consult. The two report builders below still
280
- // own their own predicates and their deny strings; l1-matrix.spec.ts asserts the row lookup and those
281
- // predicates agree.
282
- //
283
- // misplacedCdBlock is deliberately OUTSIDE that lookup, and runs ahead of it, for the reason its own
284
- // docblock gives: it decides from command TEXT, before a tree has been resolved, and the other two
285
- // reason FROM the resolved tree. Classifying it would mean asking L1_ROWS a question whose answer the
286
- // classification itself depends on. It is the same shape as L2's `bareCheckoutOfMain` pre-stage. It is
287
- // therefore ROW 0 — "pre-stage, decided from command text" — rather than a row among 1-6, which keeps
288
- // it IN the table (the drift this table exists to prevent) without pretending it is classified over the
289
- // same five dimensions. `L1_PRESTAGE_ROW` is the number the doc prints and `row=` logs, so the two join.
290
- //
291
- // THIS FUNCTION IS THE ONE PLACE L1 REPORTS. It is the only scope holding the classification, the
292
- // matched row, the resolved tree and the agent at once — so logging here, BEFORE the early return,
293
- // is what finally records the outcomes that were previously invisible: the exempt row and the three
294
- // hand-downs wrote nothing at all, which is why "L1 had no objection" could not be observed and
295
- // "show me every L1 decision" had no answer. The three block helpers no longer log for themselves —
296
- // and, for the same reason, none of them knows about the matrix POINTER either: every deny is stamped
297
- // with it HERE, from the same scope and the same row number, so deny and log line cannot disagree.
298
- // webpieces-disable no-function-outside-class -- sibling of the other module-scope runner helpers; the whole file is functions and a lone class here would break its shape
299
- function l1LocationBlock(command, tree, aiType) {
300
- const misplacedCd = misplacedCdBlock(command, tree);
301
- if (misplacedCd !== null) {
302
- logL1(tree, command, 'BLOCK_AI_CURE', l1_rows_1.L1_PRESTAGE_ROW, 'cd-must-be-first', 'cd not leading/literal');
303
- return (0, l1_matrix_doc_1.withLocationMatrixPointer)(misplacedCd, tree.root, l1_rows_1.L1_PRESTAGE_ROW);
304
- }
305
- const row = (0, l1_rows_1.firstMatchingL1Row)(l1Classify(command, tree));
306
- const rowNum = String(row.num);
307
- if (row.blockId === null) {
308
- // ALLOW_EXEMPT stops here; ALLOW means "no objection, handed down to L2". Recording the
309
- // difference is the point — see Verdict. Neither claims the call RAN: the other parallel hook
310
- // may still have denied it.
311
- logL1(tree, command, row.action.kind === 'exempt' ? 'ALLOW_EXEMPT' : 'ALLOW', rowNum, '-', row.why);
312
- return null;
313
- }
314
- logL1(tree, command, 'BLOCK_AI_CURE', rowNum, row.blockId, row.why);
315
- if (row.blockId === 'missing-directory')
316
- return (0, l1_matrix_doc_1.withLocationMatrixPointer)((0, missing_directory_1.missingDirectoryBlock)(command, tree), tree.root, rowNum);
317
- if (row.blockId === 'trinary-version-skew')
318
- return (0, l1_matrix_doc_1.withLocationMatrixPointer)(versionSkewBlock(command, tree, aiType), tree.root, rowNum);
319
- return (0, l1_matrix_doc_1.withLocationMatrixPointer)((0, force_to_root_1.gitFromSubdirBlock)(command, tree, isGitOrGhCommand(command)), tree.root, rowNum);
320
- }
321
- // One L1 line, into L1's OWN stream. `row` is the number the generated doc prints, so a reader who sees
322
- // `row=5` can open the L1 matrix at row 5 — the deny for that same call names it by absolute path.
323
- // eslint-disable-next-line @typescript-eslint/max-params -- the six fields of one log line, and a class here would break this file's shape
324
- // webpieces-disable no-function-outside-class -- sibling of the module-scope runner helpers; the whole file is functions
325
- function logL1(tree, command, verdict, row, rule, why) {
326
- (0, decision_log_1.logL1Decision)(tree.root, new decision_log_1.GuardDecision(rule, 'Bash', command, (0, decision_log_1.branchForLog)(tree.root), verdict, why, '-', l0_fault_codes_1.L0_FAULT_NONE, new decision_log_1.MatrixRef('L1', row)));
327
- }
328
- /**
329
- * ONE legal shape for relocating a command: `cd <literal path> && <work>`. Anything else — a `cd` after
330
- * another command or after a `VAR=…` assignment, or a `cd "$DIR"` the guard cannot expand — is refused
331
- * here instead of being silently judged from the shell cwd.
332
- *
333
- * This changes no verdict: every command it refuses was ALREADY judged from the shell cwd, so nothing
334
- * it blocks was previously being allowed on the strength of its `cd`. What changes is that the agent
335
- * finds out. Two PRs of increasingly precise near-miss wording (#596, #597) still left the fact in a
336
- * paragraph appended to an unrelated block; the rule is simpler stated as a rule.
337
- *
338
- * FIRST in the L1 chain deliberately. version skew and force-to-root both reason from the
339
- * resolved tree, and if the `cd` did not resolve, that tree is not the one the agent thinks they are
340
- * in — so their remedies would be steering from a location the command does not actually run in.
341
- */
342
- // webpieces-disable no-function-outside-class -- sibling of the other module-scope runner helpers; the whole runner is module-scope functions
343
- function misplacedCdBlock(command, tree) {
344
- const reason = new effective_tree_1.EffectiveTreeResolver().misplacedCd(command);
345
- if (reason === null)
346
- return null;
347
- const report = `❌ A \`cd\` must come FIRST in the command, with a LITERAL path.\n` +
348
- ` Why this one was rejected: ${reason}.\n` +
349
- ` \`cd <literal path> && <work>\` is the ONE shape that moves where webpieces judges a command.\n` +
350
- ` Any other \`cd\` cannot be resolved, so the command would be judged against ${tree.root}\n` +
351
- ` — not where you think it runs. That used to happen silently; this block is that silence, spoken.\n` +
352
- ` Fix Option 1: put the \`cd\` first, literal path, SAME command: cd /abs/path && <the rest>\n` +
353
- ` Fix Option 2: drop the \`cd\` — ${tree.root} is where the command is judged anyway.\n` +
354
- ` Fix Option 3: if the SECOND \`cd\` was there to point a tool at a directory, use that tool's own\n` +
355
- ` directory flag instead — \`git -C <dir>\`, \`tar -C <dir>\`, \`npm --prefix <dir>\`,\n` +
356
- ` \`npm pack --pack-destination <dir>\`, \`pnpm --dir <dir>\`. One \`cd\`, same result.\n` +
357
- ` ONLY for a dir INSIDE this tree. \`git -C <another tree>\` is REFUSED to a subagent,\n` +
358
- ` and is never the cure for a version skew — for that, tell the MAIN agent.\n` +
359
- ` Fix Option 4: split it — run the work in one call, the \`cd\` in another (a \`cd\` alone still\n` +
360
- ` moves nothing the guards judge; see EffectiveTree on why cwd cannot be assumed).`;
361
- return new types_1.BlockedResult(report);
362
- }
363
- /**
364
- * The KEYLESS bash guards, deliberately kept OUT of the config-driven rule set. They have no
365
- * webpieces.config.json entry at all, so passing them through checkConfigSync would make every
366
- * consumer's next Bash call a fault-Y block ("this rule has no entry") for a feature nobody opted into
367
- * — which is exactly what whole-repo-build-guard did on its first release. Each one decides for itself
368
- * whether it acts: whole-repo-build-guard reads ~/.webpieces/config.json for a machine-local OPT-IN
369
- * (absent means OFF); commit-message-substitution-guard and build-output-pipe-guard act unconditionally.
370
- * They still honour excludePaths, and they do not run in `rules` mode (code-style-only hook).
371
- */
372
- // webpieces-disable no-function-outside-class -- sibling of the module-scope runner helpers; the whole file is functions and a lone class here would break its shape
373
- function keylessBashRules(loaded, mode, governed) {
374
- if (mode === 'rules')
375
- return [];
376
- return (0, excluded_paths_1.filterByExcludedPaths)((0, load_rules_1.loadKeylessBashRules)(loaded.prGate.buildCommand), governed, loaded.excludePaths);
377
- }
378
- // webpieces-disable no-function-outside-class -- sibling of run()/runBash() in this module; the whole runner is module-scope functions and a lone class for this one entry point would break the file's shape
379
- function runBashInternal(command, cwd, mode, aiType) {
380
- if (isL0CureCommand(command)) {
381
- logL0CureBypass(command, cwd);
382
- return null;
383
- }
384
- const loaded = loadConfigOrAllowInspection(command, cwd);
385
- // null = the config would not load AND this command only inspects → allow, see the helper.
386
- if (loaded === null)
387
- return null;
388
- if (loaded.configPath === null)
389
- return l0FaultAllows(command, aiType) ? null : configMissingBlock(cwd);
390
- const workspaceRoot = path.dirname(loaded.configPath);
391
- // WHICH TREE does this command act on? Not the shell's cwd: a `cd` OUT of the workspace is reset
392
- // by the harness and one INSIDE it persists, so neither can be assumed (see EffectiveTree).
393
- // ONE resolver answers this for the guards AND for force-to-root below, so the two can never
394
- // disagree about which tree you are in.
395
- const tree = new effective_tree_1.EffectiveTreeResolver().resolve(command, cwd, workspaceRoot);
396
- // Git-repo-boundary governance: the command runs inside a DIFFERENT git repo than this
397
- // webpieces.config governs (e.g. a clone under repositories/). Out of scope → allow, hands-off.
398
- // Intentional, not a silent hole. A LINKED WORKTREE of this repo is deliberately NOT foreign — it
399
- // is the same project, so the guards run against THAT tree's branch and cache.
400
- if (tree.kind === 'foreign') {
401
- (0, decision_log_1.logGuardDecision)(workspaceRoot, new decision_log_1.GuardDecision('-', 'Bash', command, (0, decision_log_1.branchForLog)(workspaceRoot), 'ALLOW_EXEMPT', 'foreign git repo (out of scope)', '-', l0_fault_codes_1.L0_FAULT_NONE, new decision_log_1.MatrixRef('L1', '1')));
402
- return null;
403
- }
404
- // Honour excludePaths on the bash path too (not just Read/Edit): a command whose effective
405
- // cwd sits under an excluded tree (e.g. repositories/**) drops the whole guard set — matching how
406
- // runInternal/runRead treat file paths. The relative path is '' when there is no `cd` (root), which
407
- // matches no exclusion glob, so a plain command at the repo root is unaffected.
408
- const governedCwd = (0, excluded_paths_1.bashGovernedPath)(tree, workspaceRoot);
409
- const rules = (0, excluded_paths_1.filterByExcludedPaths)(filterByMode((0, load_rules_1.loadRules)(loaded.rulesConfig, workspaceRoot, guardHintsOf(loaded)), mode), governedCwd, loaded.excludePaths);
410
- const keyless = keylessBashRules(loaded, mode, governedCwd);
411
- if (rules.length === 0 && keyless.length === 0)
412
- return null;
413
- const outOfSync = checkConfigSync(rules, loaded.rulesConfig); // fault Y — L0 list wins, as under C
414
- if (outOfSync)
415
- return l0FaultAllows(command, aiType) ? null : outOfSync;
416
- const locationBlock = l1LocationBlock(command, tree, aiType);
417
- if (locationBlock)
418
- return locationBlock;
419
- // Keep the feature-branch-guard cache warm on EVERY command (not just Write/Edit): the AI runs
420
- // far more bash than edits, so refreshing here means the guard's next file-edit check reads a
421
- // fresh status. Detached + fire-and-forget — never blocks the command. Only when the guard is
422
- // loaded (guards/all mode) and enabled, so a project that opted out never triggers git fetches.
423
- // Keyed on the JUDGED tree, so a worktree's cache is refreshed rather than the primary clone's.
424
- (0, main_sync_timeout_1.maybeRefreshMainSync)(rules, tree.root, (0, main_sync_timeout_1.branchStateHangTimeout)(loaded.rulesConfig));
425
- const groups = runBashRules([...rules, ...keyless], (0, build_context_1.buildBashContext)(command, tree));
426
- if (groups.length === 0) {
427
- // Record the ALLOW only for git/gh commands — the operations the bash guards actually reason
428
- // about (branch create, commit, push, merge, PR). Skipping ls/cat/grep keeps the audit log
429
- // focused (the whole point of the log is "why did/didn't a guard fire?"). Blocks are always
430
- // logged below.
431
- if (/\b(?:git|gh)\b/.test(command)) {
432
- (0, decision_log_1.logGuardDecision)(tree.root, new decision_log_1.GuardDecision('-', 'Bash', command, (0, decision_log_1.branchForLog)(tree.root), 'ALLOW', 'no bash-guard block', '-', l0_fault_codes_1.L0_FAULT_NONE, decision_log_1.MATRIX_L2_UNROWED));
433
- }
434
- return null;
435
- }
436
- const ruleNames = groups.map((g) => g.ruleName).join(',');
437
- (0, decision_log_1.logGuardDecision)(tree.root, new decision_log_1.GuardDecision(ruleNames, 'Bash', command, (0, decision_log_1.branchForLog)(tree.root), 'BLOCK_AI_CURE', 'bash-guard block', '-', l0_fault_codes_1.L0_FAULT_NONE, decision_log_1.MATRIX_L2_UNROWED));
438
- const report = new excluded_path_escape_1.ExcludedPathEscapeHint(workspaceRoot, tree.effectiveCwd).render(command, loaded.excludePaths)
439
- + (0, report_1.formatReport)(commandLabel(command), groups, report_1.BASH_SUBJECT) + exemptTreesHint(groups, loaded.excludePaths.paths);
440
- return new types_1.BlockedResult(report);
441
- }
442
- // The bash report's subject line. It used to be the literal string `<bash>`, which told the agent
443
- // nothing; the command itself is what was blocked, so name it — truncated, because a heredoc-bearing
444
- // command can run to thousands of characters and the violation lines already carry the detail.
445
- // webpieces-disable no-function-outside-class -- sibling of the module-scope runner helpers; the whole file is functions and a lone class here would break its shape
446
- function commandLabel(command) {
447
- const oneLine = command.replace(/\s+/g, ' ').trim();
448
- const MAX = 100;
449
- return oneLine.length <= MAX ? oneLine : oneLine.slice(0, MAX) + '…';
450
- }
451
- // When a push/PR block fires AND the config exempts vendored/nested trees, surface the escape hatch the
452
- // AI cannot otherwise discover: git/gh run UNGUARDED inside those trees if it cd's there first (each is
453
- // governed by its own repo, not this one). Scoped to pr-creation-or-push-guard — for the other guards
454
- // "cd into an exempt tree" is not the remedy — and emitted only when such trees are actually configured,
455
- // so a repo without exemptions never sees the noise.
456
- //
457
- // The hint MUST state the precondition, not just the remedy. "cd into it first" is true only for a
458
- // LITERAL cd at the FRONT of the same command; `D=…; cd "$D"; git push` lands in the identical
459
- // directory and does NOT relocate the verdict. That used to be silent, then a near-miss paragraph
460
- // appended here; it is now misplacedCdBlock, which refuses the command outright — so by the time this
461
- // footer is reached, any `cd` in the command is already known to be leading and literal. The wording
462
- // still states the shape, because this is where an agent LEARNS it, before writing the next command.
463
- // webpieces-disable no-function-outside-class -- sibling of the module-scope runner helpers; the whole file is functions and a lone class here would break its shape
464
- function exemptTreesHint(groups, exemptGuards) {
465
- if (exemptGuards.length === 0)
466
- return '';
467
- if (!groups.some((g) => g.ruleName === 'pr-creation-or-push-guard'))
468
- return '';
469
- return `\n\nℹ️ Working in a nested repo under one of these exempt trees (${exemptGuards.join(', ')})? `
470
- + `Put a LITERAL \`cd\` at the FRONT of the SAME command — \`cd /abs/path/to/repo && git push\` — and git/gh `
471
- + `run normally there: the webpieces guards do NOT govern them (each is its own repo).`
472
- + `\n \`cd <literal path> && <work>\` is the ONE shape that moves where a command is judged. A \`cd\` `
473
- + `anywhere else in the line, or a non-literal target like \`cd "$DIR"\`, is refused outright rather than `
474
- + `judged from somewhere you did not intend.`;
475
- }
476
- // The set of CONFIG KEYS explicitly present in webpieces.config.json (every key except rulesDir).
477
- function configuredRuleNames(config) {
478
- return new Set(Object.keys(config).filter((k) => k !== 'rulesDir'));
479
- }
480
- /**
481
- * Fault Y — a loaded rule whose CONFIG KEY has no entry.
482
- *
483
- * Compared on `configKey`, not `name`. Eight of the loaded rules are classes behind two policy keys, so
484
- * comparing names here would demand entries named `feature-branch-guard`, `pr-merge-guard` and six
485
- * others — keys the validator then REJECTS as retired. That is the two-enforcement-paths deadlock this
486
- * repo has already hit once (see the narration in guards.spec.ts), and it blocks every Bash/Write/Edit.
487
- *
488
- * De-duplicated on the key too, so one missing policy entry reports ONE paste-ready snippet rather than
489
- * four copies of the same one under four different headings.
490
- */
491
- function checkConfigSync(rules, config) {
492
- const configured = configuredRuleNames(config);
493
- const seen = new Set();
494
- const unconfiguredRules = rules.filter((r) => {
495
- if (configured.has(r.configKey) || seen.has(r.configKey))
496
- return false;
497
- seen.add(r.configKey);
498
- return true;
499
- });
500
- if (unconfiguredRules.length === 0)
501
- return null;
502
- // ONE action, no menu, no escalation — the config-validation invariant (guards/L0-tooling.md): every
503
- // config problem cures to "make the file right", and editing it is never denied. This message used
504
- // to tell the agent to interview the human about each rule; agents did not do it, so the block just
505
- // stalled. Each rule now ships a paste-ready entry at its recommended mode.
506
- //
507
- // Note this is the CONFIG-BEHIND-CODE direction. The opposite one — the config names a rule the
508
- // installed validator has no schema for — is unknownRuleError() in rules-config/validate-config.ts
509
- // and surfaces in the validation banner, not here.
510
- const lines = [
511
- // Fault Y's header lives in ./l0-matrix beside the rest of the L0 fault table (same reason as
512
- // CONFIG_MISSING_REPORT: one place states what this fault is and what cures it).
513
- l0_matrix_1.CONFIG_OUT_OF_SYNC_HEADER,
514
- '',
515
- `Add an entry for each rule below to ${rules_config_1.CONFIG_FILENAME}. Editing that file is ALWAYS allowed through`,
516
- 'the guard — including right now, while this block is up — so paste the entries and retry.',
517
- '',
518
- 'Each entry below is ready to paste at its recommended mode; adjust the option values if your',
519
- 'project needs different ones.',
520
- '',
521
- `Do NOT delete a rule from ${rules_config_1.CONFIG_FILENAME} to silence it — an entry is REQUIRED for every rule,`,
522
- 'and "mode": "OFF" is how a rule is turned off.',
523
- '',
524
- ];
525
- for (const rule of unconfiguredRules) {
526
- lines.push(`--- ${rule.configKey} ---`);
527
- lines.push(`Description: ${rule.description}`);
528
- const opts = rule.defaultOptions;
529
- const optKeys = Object.keys(opts);
530
- if (optKeys.length > 0) {
531
- lines.push(`Available options (suggested defaults shown):`);
532
- for (const key of optKeys) {
533
- lines.push(` ${key}: ${JSON.stringify(opts[key])}`);
534
- }
535
- }
536
- else {
537
- lines.push('Available options: none beyond mode');
538
- }
539
- // The SAME entry the installer would seed: recommended mode, both hatches, and every other
540
- // schema-required field — so pasting it satisfies the loader in one pass.
541
- lines.push(`Entry to add to ${rules_config_1.CONFIG_FILENAME}:`);
542
- lines.push(` "${rule.configKey}": ${JSON.stringify((0, rules_config_1.seedEntryForRule)(rule.configKey))}`);
543
- lines.push('');
544
- }
545
- // Fault Y, stamped for the audit trail — see configMissingBlock for why the producer names it.
546
- return new types_1.BlockedResult(lines.join('\n'), l0_fault_codes_1.L0_FAULT_CONFIG_OUT_OF_SYNC);
547
- }
548
- // N-legs pattern: each rule runs independently so one rule can never abort the others. A rule may
549
- // EITHER return Violation[] OR throw — both accumulate here into visible violations the AI sees:
550
- // - a thrown RuleFailError → an expected, well-formed violation (its line/snippet/fixOptions kept);
551
- // - a thrown plain Error → a "crashed" violation (a bug, surfaced not swallowed).
552
- function runRuleCheck(rule, ctx) {
553
- // eslint-disable-next-line @webpieces/no-unmanaged-exceptions
554
- try {
555
- return rule.check(ctx);
556
- }
557
- catch (err) {
558
- const error = (0, to_error_1.toError)(err);
559
- if (error instanceof types_1.RuleFailError) {
560
- return [violationFromRuleFail(error)];
561
- }
562
- return [new types_1.Violation(0, '', `Rule '${rule.name}' crashed: ${error.message}`)];
563
- }
564
- }
565
- // A thrown RuleFailError carries its own AI-facing message + optional location and cures. Fold the
566
- // cures into the message because Violation has no fixHint field (RuleGroup's fixHint comes from the
567
- // rule definition, not a per-throw value). The "Fix Option N:"/"(preferred)" labels come from the ONE
568
- // framework-owned renderer, exactly as report.ts renders a rule's static FixHint — a rule never
569
- // hand-numbers its own cures.
570
- function violationFromRuleFail(error) {
571
- return new types_1.Violation(error.line ?? 0, error.snippet ?? '', (0, rules_config_1.renderRuleFailForAi)(error));
572
- }
573
- function ruleMatchesFile(rule, relativePath) {
574
- for (const pattern of rule.files) {
575
- if ((0, load_rules_1.globMatches)(pattern, relativePath))
576
- return true;
577
- }
578
- return false;
579
- }
580
- function runBashRules(rules, bashContext) {
581
- const groups = [];
582
- for (const rule of rules) {
583
- if (rule.scope !== 'bash')
584
- continue;
585
- if (!rule.shouldRun())
586
- continue;
587
- const vs = runRuleCheck(rule, bashContext);
588
- if (vs.length > 0) {
589
- groups.push(new types_1.RuleGroup(rule.name, rule.description, rule.fixHint, [...vs]));
590
- }
591
- }
592
- return groups;
593
- }
594
- function runEditRules(rules, editContexts) {
595
- const groups = [];
596
- for (const rule of rules) {
597
- if (rule.scope !== 'edit')
598
- continue;
599
- if (!rule.shouldRun())
600
- continue;
601
- const allViolations = [];
602
- for (const ctx of editContexts) {
603
- if (!ruleMatchesFile(rule, ctx.relativePath))
604
- continue;
605
- const vs = runRuleCheck(rule, ctx);
606
- for (const v of vs) {
607
- const copy = new types_1.Violation(v.line, v.snippet, v.message);
608
- copy.editIndex = ctx.editIndex;
609
- copy.editCount = ctx.editCount;
610
- allViolations.push(copy);
611
- }
612
- }
613
- if (allViolations.length > 0) {
614
- groups.push(new types_1.RuleGroup(rule.name, rule.description, rule.fixHint, allViolations));
615
- }
616
- }
617
- return groups;
618
- }
619
- function runFileRules(rules, fileContext) {
620
- const groups = [];
621
- for (const rule of rules) {
622
- if (rule.scope !== 'file')
623
- continue;
624
- if (!rule.shouldRun())
625
- continue;
626
- if (!ruleMatchesFile(rule, fileContext.relativePath))
627
- continue;
628
- const vs = runRuleCheck(rule, fileContext);
629
- if (vs.length > 0) {
630
- groups.push(new types_1.RuleGroup(rule.name, rule.description, rule.fixHint, [...vs]));
631
- }
632
- }
633
- return groups;
34
+ return new hook_runtime_1.BlockedResult(rules_config_1.CONFIG_MISSING_REPORT + (0, rules_config_1.guardMatrixPointer)((0, rules_config_1.writeGuardMatrixDoc)(new rules_config_1.RepoRootFinder().resolveRepoRoot(cwd))), rules_config_1.L0_FAULT_CONFIG_MISSING);
35
+ return new hook_runtime_1.HookFileEvaluation().evaluate(toolKind, input, loaded, new SourceHookRules().load(loaded));
634
36
  }
635
37
  //# sourceMappingURL=runner.js.map