@webpieces/ai-hook-rules 0.4.839 → 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,17 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GuardHintCommands = void 0;
4
3
  exports.loadRules = loadRules;
5
- exports.loadKeylessBashRules = loadKeylessBashRules;
6
4
  exports.loadMatchRules = loadMatchRules;
7
- exports.globMatches = globMatches;
5
+ exports.loadBuiltInRules = loadBuiltInRules;
6
+ exports.loadCustomRules = loadCustomRules;
8
7
  const tslib_1 = require("tslib");
9
8
  const fs = tslib_1.__importStar(require("fs"));
10
9
  const path = tslib_1.__importStar(require("path"));
11
- const types_1 = require("./types");
12
- const to_error_1 = require("./to-error");
13
- const rule_base_1 = require("./rule-base");
14
- const custom_rule_adapter_1 = require("./custom-rule-adapter");
10
+ const tooling_common_1 = require("@webpieces/tooling-common");
11
+ const to_error_1 = require("@webpieces/tooling-common/to-error");
12
+ const hook_runtime_1 = require("@webpieces/hook-runtime");
13
+ const hook_runtime_2 = require("@webpieces/hook-runtime");
15
14
  const index_1 = require("./rules/index");
16
15
  const no_any_unknown_1 = require("./rules/no-any-unknown");
17
16
  const no_implicit_any_1 = require("./rules/no-implicit-any");
@@ -25,33 +24,10 @@ const throw_cause_required_1 = require("./rules/throw-cause-required");
25
24
  const no_symbol_di_tokens_1 = require("./rules/no-symbol-di-tokens");
26
25
  const no_custom_css_1 = require("./rules/no-custom-css");
27
26
  const no_process_exit_outside_main_1 = require("./rules/no-process-exit-outside-main");
28
- const branch_creation_guard_1 = require("./rules/branch-creation-guard");
29
- const pr_creation_or_push_guard_1 = require("./rules/pr-creation-or-push-guard");
30
- const merge_in_progress_guard_1 = require("./rules/merge-in-progress-guard");
31
- const build_output_pipe_guard_1 = require("./rules/build-output-pipe-guard");
32
- const wait_spin_guard_1 = require("./rules/wait-spin-guard");
33
- const pr_merge_guard_1 = require("./rules/pr-merge-guard");
34
- const redirect_how_to_merge_main_1 = require("./rules/redirect-how-to-merge-main");
35
27
  const no_js_files_1 = require("./rules/no-js-files");
36
- const feature_branch_guard_1 = require("./rules/feature-branch-guard");
37
- const read_stale_guard_1 = require("./rules/read-stale-guard");
38
- const merged_branch_bash_guard_1 = require("./rules/merged-branch-bash-guard");
39
- const stale_main_bash_guard_1 = require("./rules/stale-main-bash-guard");
40
- const whole_repo_build_guard_1 = require("./rules/whole-repo-build-guard");
41
- const commit_message_substitution_guard_1 = require("./rules/commit-message-substitution-guard");
42
28
  const match_rule_1 = require("./rules/match-rule");
43
29
  const REQUIRED_FIELDS = ['name', 'description', 'scope', 'files', 'check'];
44
30
  const VALID_SCOPES = new Set(['edit', 'file', 'bash']);
45
- /** The two gated-command strings guards print, resolved from `commands.guardHints`. Data-only. */
46
- class GuardHintCommands {
47
- upsertPr;
48
- mergeComplete;
49
- constructor(upsertPr, mergeComplete) {
50
- this.upsertPr = upsertPr;
51
- this.mergeComplete = mergeComplete;
52
- }
53
- }
54
- exports.GuardHintCommands = GuardHintCommands;
55
31
  const BUILT_IN_RULE_MAP = {
56
32
  'no-any-unknown': (c) => [new no_any_unknown_1.NoAnyUnknownRule(c)],
57
33
  'no-implicit-any': (c) => [new no_implicit_any_1.NoImplicitAnyRule(c)],
@@ -66,21 +42,6 @@ const BUILT_IN_RULE_MAP = {
66
42
  'no-custom-css': (c) => [new no_custom_css_1.NoCustomCssRule(c)],
67
43
  'no-process-exit-outside-main': (c) => [new no_process_exit_outside_main_1.NoProcessExitOutsideMainRule(c)],
68
44
  'no-js-files': (c) => [new no_js_files_1.NoJsFilesRule(c)],
69
- 'branch-creation-guard': (c) => [new branch_creation_guard_1.BranchCreationGuardRule(c)],
70
- // THE TWO COLLAPSED POLICIES. Order inside each array is the order the rules run in, and it is the
71
- // same order the previous per-key registry produced.
72
- 'pr-lifecycle-guard': (c, hints) => [
73
- new pr_creation_or_push_guard_1.PrCreationOrPushGuardRule(c, hints.upsertPr),
74
- new merge_in_progress_guard_1.MergeInProgressGuardRule(c, hints.mergeComplete),
75
- new pr_merge_guard_1.PrMergeGuardRule(c),
76
- new redirect_how_to_merge_main_1.RedirectHowToMergeMainRule(c),
77
- ],
78
- 'branch-state-guard': (c) => [
79
- new feature_branch_guard_1.FeatureBranchGuardRule(c),
80
- new read_stale_guard_1.ReadStaleGuardRule(c),
81
- new merged_branch_bash_guard_1.MergedBranchBashGuardRule(c),
82
- new stale_main_bash_guard_1.StaleMainBashGuardRule(c),
83
- ],
84
45
  };
85
46
  // Index the typed config by rule name. Each value is the rule's *Config (a plain object from
86
47
  // JSON), or undefined when the rule has no entry yet (the sync check reports those).
@@ -89,49 +50,11 @@ function asConfigMap(config) {
89
50
  return config;
90
51
  }
91
52
  // webpieces-disable no-function-outside-class -- the module's entry point, beside loadMatchRules/loadKeylessBashRules; this whole loader is module-scope functions and a lone class for one of them would break the file's shape
92
- function loadRules(config, workspaceRoot, guardHints) {
93
- const builtIns = loadBuiltInRules(config, guardHints);
53
+ function loadRules(config, workspaceRoot) {
54
+ const builtIns = loadBuiltInRules(config);
94
55
  const custom = loadCustomRules(config, workspaceRoot);
95
56
  return [...builtIns, ...custom];
96
57
  }
97
- /**
98
- * The KEYLESS bash guards: rules that have NO webpieces.config.json entry, and are therefore
99
- * deliberately kept out of `builtInConfigKeys`/`BUILT_IN_RULE_MAP` — so the config-sync check (fault Y,
100
- * "every built-in rule needs an entry, or every Bash call is blocked") can never see them. That
101
- * containment is the whole point: whole-repo-build-guard shipped inside the config-driven set once and
102
- * took every upgrading consumer's shell down with it.
103
- *
104
- * Each rule here decides for ITSELF whether it acts, and the two do it differently on purpose:
105
- *
106
- * - `whole-repo-build-guard` is EXPERIMENTAL and inert unless the optional machine-local
107
- * `~/.webpieces/config.json` opts IN with `experimental.whole-repo-build-guard: true`. Every
108
- * experimental flag defaults OFF, and it takes no file and no key to be in that default state —
109
- * which is the difference between this and the required-key release that blocked every upgrading
110
- * consumer's shell.
111
- * - `commit-message-substitution-guard` acts unconditionally. Nobody legitimately wants a backtick
112
- * expanded inside a commit message, and its cure (`git commit -F <file>`) is available for every
113
- * input and can never itself match the guard — so there is nothing for a switch to rescue.
114
- * - `build-output-pipe-guard` acts unconditionally, on the same test. Piping `wp-build` /
115
- * `wp-review-upsert-pr` / `wp-finish-upsert-pr` withholds their heartbeat until they exit and gets
116
- * the build killed by the 600s watchdog; the cure is the SAME command with less typing, available
117
- * for every input, and it cannot itself match the guard.
118
- * - `wait-spin-guard` acts unconditionally, on the same test again. An `echo .` keep-alive spends a
119
- * whole turn (~557k tokens) to do nothing, and its cure — `pnpm wp-await-reviews` /
120
- * `pnpm wp-await-checks` for a worktree subagent, a Monitor or the backgrounded command itself for a
121
- * main agent — is available for every input and can never itself match the guard.
122
- *
123
- * `affectedBuildCommand` is the project's gate command, passed through so a refusal quotes what THIS
124
- * repo's gate actually runs.
125
- */
126
- // webpieces-disable no-function-outside-class -- sibling of loadRules/loadMatchRules in this module; the whole loader is module-scope functions and a lone class for this one would break the file's shape
127
- function loadKeylessBashRules(affectedBuildCommand) {
128
- return [
129
- new whole_repo_build_guard_1.WholeRepoBuildGuardRule(affectedBuildCommand),
130
- new commit_message_substitution_guard_1.CommitMessageSubstitutionGuardRule(),
131
- new build_output_pipe_guard_1.BuildOutputPipeGuardRule(),
132
- new wait_spin_guard_1.WaitSpinGuardRule(),
133
- ];
134
- }
135
58
  // One MatchRule per entry of the `match-rules` array. Kept separate from loadRules (built-ins/custom)
136
59
  // because match-rules live in their own validated section — they must NOT flow through the
137
60
  // config-sync check, which compares rule names against the `rules`/`hookGuards` map.
@@ -140,7 +63,7 @@ function loadMatchRules(matchRules) {
140
63
  }
141
64
  // Iterates CONFIG KEYS, not rule names — one entry can yield several rules (see BUILT_IN_RULE_MAP).
142
65
  // webpieces-disable no-function-outside-class -- the body of loadRules above, in the same module of loader functions
143
- function loadBuiltInRules(config, guardHints) {
66
+ function loadBuiltInRules(config) {
144
67
  const map = asConfigMap(config);
145
68
  const rules = [];
146
69
  for (const configKey of index_1.builtInConfigKeys) {
@@ -149,11 +72,12 @@ function loadBuiltInRules(config, guardHints) {
149
72
  process.stderr.write(`[ai-hooks] unknown built-in config key: ${configKey}\n`);
150
73
  continue;
151
74
  }
152
- const ruleConfig = map[configKey] ?? new rule_base_1.EmptyRuleConfig();
153
- rules.push(...factory(ruleConfig, guardHints));
75
+ const ruleConfig = map[configKey] ?? new hook_runtime_1.EmptyRuleConfig();
76
+ rules.push(...factory(ruleConfig));
154
77
  }
155
78
  return rules;
156
79
  }
80
+ // webpieces-disable no-function-outside-class -- existing source registry helper contributed to both source and umbrella runners
157
81
  function loadCustomRules(config, workspaceRoot) {
158
82
  const dirs = config.rulesDir ?? [];
159
83
  // webpieces-disable no-any-unknown -- index the typed config by dynamic custom-rule name
@@ -161,7 +85,7 @@ function loadCustomRules(config, workspaceRoot) {
161
85
  const rules = [];
162
86
  for (const plain of loadCustomPlainRules(dirs, workspaceRoot)) {
163
87
  const rawConfig = map[plain.name] ?? {};
164
- rules.push(new custom_rule_adapter_1.CustomRuleAdapter(plain, rawConfig));
88
+ rules.push(new hook_runtime_2.CustomRuleAdapter(plain, rawConfig));
165
89
  }
166
90
  return rules;
167
91
  }
@@ -180,7 +104,7 @@ function loadCustomPlainRules(rulesDirs, workspaceRoot) {
180
104
  }
181
105
  catch (err) {
182
106
  const error = (0, to_error_1.toError)(err);
183
- throw new types_1.InformAiError(`Cannot read custom rules directory '${absDir}'`, { cause: error });
107
+ throw new tooling_common_1.InformAiError(`Cannot read custom rules directory '${absDir}'`, { cause: error });
184
108
  }
185
109
  for (const entry of entries) {
186
110
  const full = path.join(absDir, entry);
@@ -193,7 +117,7 @@ function loadCustomPlainRules(rulesDirs, workspaceRoot) {
193
117
  }
194
118
  catch (err) {
195
119
  const error = (0, to_error_1.toError)(err);
196
- throw new types_1.InformAiError(`Cannot load custom rule '${full}'`, { cause: error });
120
+ throw new tooling_common_1.InformAiError(`Cannot load custom rule '${full}'`, { cause: error });
197
121
  }
198
122
  }
199
123
  }
@@ -228,40 +152,4 @@ function validateRule(rule) {
228
152
  }
229
153
  return true;
230
154
  }
231
- function globMatches(pattern, filePath) {
232
- const regex = globToRegex(pattern);
233
- return regex.test(filePath);
234
- }
235
- function globToRegex(pattern) {
236
- let re = '';
237
- let i = 0;
238
- while (i < pattern.length) {
239
- const ch = pattern[i];
240
- if (ch === '*') {
241
- if (pattern[i + 1] === '*') {
242
- re += '.*';
243
- i += 2;
244
- if (pattern[i] === '/')
245
- i += 1;
246
- continue;
247
- }
248
- re += '[^/]*';
249
- i += 1;
250
- continue;
251
- }
252
- if (ch === '?') {
253
- re += '[^/]';
254
- i += 1;
255
- continue;
256
- }
257
- if ('.+^$(){}|[]\\'.includes(ch)) {
258
- re += '\\' + ch;
259
- i += 1;
260
- continue;
261
- }
262
- re += ch;
263
- i += 1;
264
- }
265
- return new RegExp('^' + re + '$');
266
- }
267
155
  //# sourceMappingURL=load-rules.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"load-rules.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/core/load-rules.ts"],"names":[],"mappings":";;;AAiHA,8BAQC;AAgCD,oDAOC;AAKD,wCAEC;AA6FD,kCAGC;;AAvQD,+CAAyB;AACzB,mDAA6B;AAa7B,mCAAwC;AACxC,yCAAqC;AACrC,2CAA8C;AAC9C,+DAA0D;AAC1D,yCAAkD;AAClD,2DAA0D;AAC1D,6DAA4D;AAC5D,2DAA0D;AAC1D,mEAAiE;AACjE,2DAA2D;AAC3D,qEAAoE;AACpE,6EAA4E;AAC5E,qEAAoE;AACpE,uEAAsE;AACtE,qEAAmE;AACnE,yDAAwD;AACxD,uFAAoF;AACpF,yEAAwE;AACxE,iFAA8E;AAC9E,6EAA2E;AAC3E,6EAA2E;AAC3E,6DAA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AC;IACnC,OAAO,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AAChC,CAAC;AAED,SAAS,WAAW,CAAC,OAAe;IAChC,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;QACxB,MAAM,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;QACtB,IAAI,EAAE,KAAK,GAAG,EAAE,CAAC;YACb,IAAI,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;gBACzB,EAAE,IAAI,IAAI,CAAC;gBACX,CAAC,IAAI,CAAC,CAAC;gBACP,IAAI,OAAO,CAAC,CAAC,CAAC,KAAK,GAAG;oBAAE,CAAC,IAAI,CAAC,CAAC;gBAC/B,SAAS;YACb,CAAC;YACD,EAAE,IAAI,OAAO,CAAC;YACd,CAAC,IAAI,CAAC,CAAC;YACP,SAAS;QACb,CAAC;QACD,IAAI,EAAE,KAAK,GAAG,EAAE,CAAC;YACb,EAAE,IAAI,MAAM,CAAC;YACb,CAAC,IAAI,CAAC,CAAC;YACP,SAAS;QACb,CAAC;QACD,IAAI,eAAe,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;YAC/B,EAAE,IAAI,IAAI,GAAG,EAAE,CAAC;YAChB,CAAC,IAAI,CAAC,CAAC;YACP,SAAS;QACb,CAAC;QACD,EAAE,IAAI,EAAE,CAAC;QACT,CAAC,IAAI,CAAC,CAAC;IACX,CAAC;IACD,OAAO,IAAI,MAAM,CAAC,GAAG,GAAG,EAAE,GAAG,GAAG,CAAC,CAAC;AACtC,CAAC","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\n\nimport {\n BaseRuleConfig, RuleOptions, WebpiecesRulesConfig,\n NoAnyUnknownConfig, NoImplicitAnyConfig, MaxFileLinesConfig, ValidateTsInSrcConfig,\n NoDestructureConfig, RequireReturnTypeConfig, NoUnmanagedExceptionsConfig,\n CatchErrorPatternConfig, ThrowCauseRequiredConfig,\n NoSymbolDiTokensConfig, NoCustomCssConfig, NoProcessExitOutsideMainConfig, BranchCreationGuardConfig,\n PrLifecycleGuardConfig, BranchStateGuardConfig,\n NoJsFilesConfig, MatchRuleConfig,\n} from '@webpieces/rules-config';\n\nimport type { Rule, PlainRule } from './types';\nimport { InformAiError } from './types';\nimport { toError } from './to-error';\nimport { EmptyRuleConfig } from './rule-base';\nimport { CustomRuleAdapter } from './custom-rule-adapter';\nimport { builtInConfigKeys } from './rules/index';\nimport { NoAnyUnknownRule } from './rules/no-any-unknown';\nimport { NoImplicitAnyRule } from './rules/no-implicit-any';\nimport { MaxFileLinesRule } from './rules/max-file-lines';\nimport { ValidateTsInSrcRule } from './rules/validate-ts-in-src';\nimport { NoDestructureRule } from './rules/no-destructure';\nimport { RequireReturnTypeRule } from './rules/require-return-type';\nimport { NoUnmanagedExceptionsRule } from './rules/no-unmanaged-exceptions';\nimport { CatchErrorPatternRule } from './rules/catch-error-pattern';\nimport { ThrowCauseRequiredRule } from './rules/throw-cause-required';\nimport { NoSymbolDiTokensRule } from './rules/no-symbol-di-tokens';\nimport { NoCustomCssRule } from './rules/no-custom-css';\nimport { NoProcessExitOutsideMainRule } from './rules/no-process-exit-outside-main';\nimport { BranchCreationGuardRule } from './rules/branch-creation-guard';\nimport { PrCreationOrPushGuardRule } from './rules/pr-creation-or-push-guard';\nimport { MergeInProgressGuardRule } from './rules/merge-in-progress-guard';\nimport { BuildOutputPipeGuardRule } from './rules/build-output-pipe-guard';\nimport { WaitSpinGuardRule } from './rules/wait-spin-guard';\nimport { PrMergeGuardRule } from './rules/pr-merge-guard';\nimport { RedirectHowToMergeMainRule } from './rules/redirect-how-to-merge-main';\nimport { NoJsFilesRule } from './rules/no-js-files';\nimport { FeatureBranchGuardRule } from './rules/feature-branch-guard';\nimport { ReadStaleGuardRule } from './rules/read-stale-guard';\nimport { MergedBranchBashGuardRule } from './rules/merged-branch-bash-guard';\nimport { StaleMainBashGuardRule } from './rules/stale-main-bash-guard';\nimport { WholeRepoBuildGuardRule } from './rules/whole-repo-build-guard';\nimport { CommitMessageSubstitutionGuardRule } from './rules/commit-message-substitution-guard';\nimport { MatchRule } from './rules/match-rule';\n\nconst REQUIRED_FIELDS: readonly string[] = ['name', 'description', 'scope', 'files', 'check'];\nconst VALID_SCOPES = new Set(['edit', 'file', 'bash']);\n\n/**\n * ONE CONFIG KEY → N RULES.\n *\n * Each built-in rule is constructed from its typed *Config (the entry in webpieces.config.json). The\n * config arrives as a plain object structurally typed as the *Config class, so the `as` narrows the\n * shared BaseRuleConfig param back to the concrete config the rule consumes.\n *\n * The map is keyed by CONFIG KEY and each factory returns an ARRAY, because a hookGuards key names a\n * POLICY and a policy may be implemented by several classes: `branch-state-guard` builds all four\n * branch-state guards from one entry, `pr-lifecycle-guard` all four PR-lifecycle guards. It used to be\n * `Record<string, (c) => Rule>` — one factory per key — which is precisely why four classes could not\n * share a key and why the config had to carry nine switches for three decisions.\n *\n * `guardHints` are the resolved `commands.guardHints` strings, handed to the two rules that print a\n * gated command. They arrive as a constructor argument rather than a config field, so there is exactly\n * one spelling of each command in the config (see PrLifecycleGuardConfig).\n */\ntype RuleFactory = (config: BaseRuleConfig, guardHints: GuardHintCommands) => readonly Rule[];\n\n/** The two gated-command strings guards print, resolved from `commands.guardHints`. Data-only. */\nexport class GuardHintCommands {\n constructor(readonly upsertPr: string, readonly mergeComplete: string) {}\n}\n\nconst BUILT_IN_RULE_MAP: Record<string, RuleFactory> = {\n 'no-any-unknown': (c: BaseRuleConfig) => [new NoAnyUnknownRule(c as NoAnyUnknownConfig)],\n 'no-implicit-any': (c: BaseRuleConfig) => [new NoImplicitAnyRule(c as NoImplicitAnyConfig)],\n 'max-file-lines': (c: BaseRuleConfig) => [new MaxFileLinesRule(c as MaxFileLinesConfig)],\n 'validate-ts-in-src': (c: BaseRuleConfig) => [new ValidateTsInSrcRule(c as ValidateTsInSrcConfig)],\n 'no-destructure': (c: BaseRuleConfig) => [new NoDestructureRule(c as NoDestructureConfig)],\n 'require-return-type': (c: BaseRuleConfig) => [new RequireReturnTypeRule(c as RequireReturnTypeConfig)],\n 'no-unmanaged-exceptions': (c: BaseRuleConfig) => [new NoUnmanagedExceptionsRule(c as NoUnmanagedExceptionsConfig)],\n 'catch-error-pattern': (c: BaseRuleConfig) => [new CatchErrorPatternRule(c as CatchErrorPatternConfig)],\n 'throw-cause-required': (c: BaseRuleConfig) => [new ThrowCauseRequiredRule(c as ThrowCauseRequiredConfig)],\n 'no-symbol-di-tokens': (c: BaseRuleConfig) => [new NoSymbolDiTokensRule(c as NoSymbolDiTokensConfig)],\n 'no-custom-css': (c: BaseRuleConfig) => [new NoCustomCssRule(c as NoCustomCssConfig)],\n 'no-process-exit-outside-main': (c: BaseRuleConfig) => [new NoProcessExitOutsideMainRule(c as NoProcessExitOutsideMainConfig)],\n 'no-js-files': (c: BaseRuleConfig) => [new NoJsFilesRule(c as NoJsFilesConfig)],\n 'branch-creation-guard': (c: BaseRuleConfig) => [new BranchCreationGuardRule(c as BranchCreationGuardConfig)],\n // THE TWO COLLAPSED POLICIES. Order inside each array is the order the rules run in, and it is the\n // same order the previous per-key registry produced.\n 'pr-lifecycle-guard': (c: BaseRuleConfig, hints: GuardHintCommands) => [\n new PrCreationOrPushGuardRule(c as PrLifecycleGuardConfig, hints.upsertPr),\n new MergeInProgressGuardRule(c as PrLifecycleGuardConfig, hints.mergeComplete),\n new PrMergeGuardRule(c as PrLifecycleGuardConfig),\n new RedirectHowToMergeMainRule(c as PrLifecycleGuardConfig),\n ],\n 'branch-state-guard': (c: BaseRuleConfig) => [\n new FeatureBranchGuardRule(c as BranchStateGuardConfig),\n new ReadStaleGuardRule(c as BranchStateGuardConfig),\n new MergedBranchBashGuardRule(c as BranchStateGuardConfig),\n new StaleMainBashGuardRule(c as BranchStateGuardConfig),\n ],\n};\n\n// Index the typed config by rule name. Each value is the rule's *Config (a plain object from\n// JSON), or undefined when the rule has no entry yet (the sync check reports those).\nfunction asConfigMap(config: WebpiecesRulesConfig): Record<string, BaseRuleConfig | undefined> {\n // webpieces-disable no-any-unknown -- index the typed config by dynamic rule name\n return config as unknown as Record<string, BaseRuleConfig | undefined>;\n}\n\n// webpieces-disable no-function-outside-class -- the module's entry point, beside loadMatchRules/loadKeylessBashRules; this whole loader is module-scope functions and a lone class for one of them would break the file's shape\nexport function loadRules(\n config: WebpiecesRulesConfig,\n workspaceRoot: string,\n guardHints: GuardHintCommands,\n): readonly Rule[] {\n const builtIns = loadBuiltInRules(config, guardHints);\n const custom = loadCustomRules(config, workspaceRoot);\n return [...builtIns, ...custom];\n}\n\n/**\n * The KEYLESS bash guards: rules that have NO webpieces.config.json entry, and are therefore\n * deliberately kept out of `builtInConfigKeys`/`BUILT_IN_RULE_MAP` — so the config-sync check (fault Y,\n * \"every built-in rule needs an entry, or every Bash call is blocked\") can never see them. That\n * containment is the whole point: whole-repo-build-guard shipped inside the config-driven set once and\n * took every upgrading consumer's shell down with it.\n *\n * Each rule here decides for ITSELF whether it acts, and the two do it differently on purpose:\n *\n * - `whole-repo-build-guard` is EXPERIMENTAL and inert unless the optional machine-local\n * `~/.webpieces/config.json` opts IN with `experimental.whole-repo-build-guard: true`. Every\n * experimental flag defaults OFF, and it takes no file and no key to be in that default state —\n * which is the difference between this and the required-key release that blocked every upgrading\n * consumer's shell.\n * - `commit-message-substitution-guard` acts unconditionally. Nobody legitimately wants a backtick\n * expanded inside a commit message, and its cure (`git commit -F <file>`) is available for every\n * input and can never itself match the guard — so there is nothing for a switch to rescue.\n * - `build-output-pipe-guard` acts unconditionally, on the same test. Piping `wp-build` /\n * `wp-review-upsert-pr` / `wp-finish-upsert-pr` withholds their heartbeat until they exit and gets\n * the build killed by the 600s watchdog; the cure is the SAME command with less typing, available\n * for every input, and it cannot itself match the guard.\n * - `wait-spin-guard` acts unconditionally, on the same test again. An `echo .` keep-alive spends a\n * whole turn (~557k tokens) to do nothing, and its cure — `pnpm wp-await-reviews` /\n * `pnpm wp-await-checks` for a worktree subagent, a Monitor or the backgrounded command itself for a\n * main agent — is available for every input and can never itself match the guard.\n *\n * `affectedBuildCommand` is the project's gate command, passed through so a refusal quotes what THIS\n * repo's gate actually runs.\n */\n// webpieces-disable no-function-outside-class -- sibling of loadRules/loadMatchRules in this module; the whole loader is module-scope functions and a lone class for this one would break the file's shape\nexport function loadKeylessBashRules(affectedBuildCommand: string): Rule[] {\n return [\n new WholeRepoBuildGuardRule(affectedBuildCommand),\n new CommitMessageSubstitutionGuardRule(),\n new BuildOutputPipeGuardRule(),\n new WaitSpinGuardRule(),\n ];\n}\n\n// One MatchRule per entry of the `match-rules` array. Kept separate from loadRules (built-ins/custom)\n// because match-rules live in their own validated section — they must NOT flow through the\n// config-sync check, which compares rule names against the `rules`/`hookGuards` map.\nexport function loadMatchRules(matchRules: readonly MatchRuleConfig[]): Rule[] {\n return matchRules.map((c: MatchRuleConfig) => new MatchRule(c));\n}\n\n// Iterates CONFIG KEYS, not rule names — one entry can yield several rules (see BUILT_IN_RULE_MAP).\n// webpieces-disable no-function-outside-class -- the body of loadRules above, in the same module of loader functions\nfunction loadBuiltInRules(config: WebpiecesRulesConfig, guardHints: GuardHintCommands): Rule[] {\n const map = asConfigMap(config);\n const rules: Rule[] = [];\n for (const configKey of builtInConfigKeys) {\n const factory = BUILT_IN_RULE_MAP[configKey];\n if (!factory) {\n process.stderr.write(`[ai-hooks] unknown built-in config key: ${configKey}\\n`);\n continue;\n }\n const ruleConfig = map[configKey] ?? new EmptyRuleConfig();\n rules.push(...factory(ruleConfig, guardHints));\n }\n return rules;\n}\n\nfunction loadCustomRules(config: WebpiecesRulesConfig, workspaceRoot: string): Rule[] {\n const dirs = config.rulesDir ?? [];\n // webpieces-disable no-any-unknown -- index the typed config by dynamic custom-rule name\n const map = config as unknown as Record<string, RuleOptions | undefined>;\n const rules: Rule[] = [];\n for (const plain of loadCustomPlainRules(dirs, workspaceRoot)) {\n const rawConfig = map[plain.name] ?? {};\n rules.push(new CustomRuleAdapter(plain, rawConfig));\n }\n return rules;\n}\n\nfunction loadCustomPlainRules(rulesDirs: readonly string[], workspaceRoot: string): PlainRule[] {\n const modules: PlainRule[] = [];\n for (const dir of rulesDirs) {\n const absDir = path.isAbsolute(dir) ? dir : path.join(workspaceRoot, dir);\n if (!fs.existsSync(absDir)) {\n process.stderr.write(`[ai-hooks] rulesDir not found: ${absDir}\\n`);\n continue;\n }\n let entries: string[];\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n entries = fs.readdirSync(absDir).filter((e: string) => e.endsWith('.js'));\n } catch (err: unknown) {\n const error = toError(err);\n throw new InformAiError(`Cannot read custom rules directory '${absDir}'`, { cause: error });\n }\n for (const entry of entries) {\n const full = path.join(absDir, entry);\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n const mod = require(full);\n const candidate = mod.default || mod;\n if (validateRule(candidate)) modules.push(candidate);\n } catch (err: unknown) {\n const error = toError(err);\n throw new InformAiError(`Cannot load custom rule '${full}'`, { cause: error });\n }\n }\n }\n return modules;\n}\n\n// webpieces-disable no-any-unknown -- validates untrusted require() output at system boundary\nfunction validateRule(rule: unknown): rule is PlainRule {\n if (!rule || typeof rule !== 'object') {\n process.stderr.write('[ai-hooks] rule is not an object, skipping\\n');\n return false;\n }\n // webpieces-disable no-any-unknown -- narrowing from unknown at system boundary\n const obj = rule as Record<string, unknown>;\n for (const field of REQUIRED_FIELDS) {\n if (obj[field] === undefined) {\n const name = typeof obj['name'] === 'string' ? obj['name'] : '<unnamed>';\n process.stderr.write(`[ai-hooks] rule \"${name}\" missing required field: ${field}\\n`);\n return false;\n }\n }\n if (!VALID_SCOPES.has(obj['scope'] as string)) {\n process.stderr.write(`[ai-hooks] rule \"${obj['name']}\" has invalid scope: ${String(obj['scope'])}\\n`);\n return false;\n }\n if (!Array.isArray(obj['files'])) {\n process.stderr.write(`[ai-hooks] rule \"${obj['name']}\" files must be an array\\n`);\n return false;\n }\n if (typeof obj['check'] !== 'function') {\n process.stderr.write(`[ai-hooks] rule \"${obj['name']}\" check must be a function\\n`);\n return false;\n }\n return true;\n}\n\nexport function globMatches(pattern: string, filePath: string): boolean {\n const regex = globToRegex(pattern);\n return regex.test(filePath);\n}\n\nfunction globToRegex(pattern: string): RegExp {\n let re = '';\n let i = 0;\n while (i < pattern.length) {\n const ch = pattern[i];\n if (ch === '*') {\n if (pattern[i + 1] === '*') {\n re += '.*';\n i += 2;\n if (pattern[i] === '/') i += 1;\n continue;\n }\n re += '[^/]*';\n i += 1;\n continue;\n }\n if (ch === '?') {\n re += '[^/]';\n i += 1;\n continue;\n }\n if ('.+^$(){}|[]\\\\'.includes(ch)) {\n re += '\\\\' + ch;\n i += 1;\n continue;\n }\n re += ch;\n i += 1;\n }\n return new RegExp('^' + re + '$');\n}\n"]}
1
+ {"version":3,"file":"load-rules.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/core/load-rules.ts"],"names":[],"mappings":";;AAmEA,8BAOC;AAKD,wCAEC;AAID,4CAaC;AAGD,0CAUC;;AA/GD,+CAAyB;AACzB,mDAA6B;AAK7B,8DAA0D;AAC1D,iEAA6D;AAC7D,0DAA0D;AAC1D,0DAA4D;AAC5D,yCAAkD;AAClD,2DAA0D;AAC1D,6DAA4D;AAC5D,2DAA0D;AAC1D,mEAAiE;AACjE,2DAA2D;AAC3D,qEAAoE;AACpE,6EAA4E;AAC5E,qEAAoE;AACpE,uEAAsE;AACtE,qEAAmE;AACnE,yDAAwD;AACxD,uFAAoF;AACpF,qDAAoD;AACpD,mDAA+C;AAE/C,MAAM,eAAe,GAAsB,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AAC9F,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAevD,MAAM,iBAAiB,GAA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AAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC;YACzE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,oBAAoB,IAAI,6BAA6B,KAAK,IAAI,CAAC,CAAC;YACrF,OAAO,KAAK,CAAC;QACjB,CAAC;IACL,CAAC;IACD,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAW,CAAC,EAAE,CAAC;QAC5C,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,oBAAoB,GAAG,CAAC,MAAM,CAAC,wBAAwB,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC;QACtG,OAAO,KAAK,CAAC;IACjB,CAAC;IACD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC;QAC/B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,oBAAoB,GAAG,CAAC,MAAM,CAAC,4BAA4B,CAAC,CAAC;QAClF,OAAO,KAAK,CAAC;IACjB,CAAC;IACD,IAAI,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,UAAU,EAAE,CAAC;QACrC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,oBAAoB,GAAG,CAAC,MAAM,CAAC,8BAA8B,CAAC,CAAC;QACpF,OAAO,KAAK,CAAC;IACjB,CAAC;IACD,OAAO,IAAI,CAAC;AAChB,CAAC","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\n\nimport { BaseRuleConfig, RuleOptions, WebpiecesRulesConfig, NoAnyUnknownConfig, NoImplicitAnyConfig, MaxFileLinesConfig, ValidateTsInSrcConfig, NoDestructureConfig, RequireReturnTypeConfig, NoUnmanagedExceptionsConfig, CatchErrorPatternConfig, ThrowCauseRequiredConfig, NoSymbolDiTokensConfig, NoCustomCssConfig, NoProcessExitOutsideMainConfig, NoJsFilesConfig, MatchRuleConfig } from '@webpieces/rules-config';\n\nimport type { Rule, PlainRule } from '@webpieces/hook-runtime';\nimport { InformAiError } from '@webpieces/tooling-common';\nimport { toError } from '@webpieces/tooling-common/to-error';\nimport { EmptyRuleConfig } from '@webpieces/hook-runtime';\nimport { CustomRuleAdapter } from '@webpieces/hook-runtime';\nimport { builtInConfigKeys } from './rules/index';\nimport { NoAnyUnknownRule } from './rules/no-any-unknown';\nimport { NoImplicitAnyRule } from './rules/no-implicit-any';\nimport { MaxFileLinesRule } from './rules/max-file-lines';\nimport { ValidateTsInSrcRule } from './rules/validate-ts-in-src';\nimport { NoDestructureRule } from './rules/no-destructure';\nimport { RequireReturnTypeRule } from './rules/require-return-type';\nimport { NoUnmanagedExceptionsRule } from './rules/no-unmanaged-exceptions';\nimport { CatchErrorPatternRule } from './rules/catch-error-pattern';\nimport { ThrowCauseRequiredRule } from './rules/throw-cause-required';\nimport { NoSymbolDiTokensRule } from './rules/no-symbol-di-tokens';\nimport { NoCustomCssRule } from './rules/no-custom-css';\nimport { NoProcessExitOutsideMainRule } from './rules/no-process-exit-outside-main';\nimport { NoJsFilesRule } from './rules/no-js-files';\nimport { MatchRule } from './rules/match-rule';\n\nconst REQUIRED_FIELDS: readonly string[] = ['name', 'description', 'scope', 'files', 'check'];\nconst VALID_SCOPES = new Set(['edit', 'file', 'bash']);\n\n/**\n * ONE CONFIG KEY → N RULES.\n *\n * Each built-in rule is constructed from its typed *Config (the entry in webpieces.config.json). The\n * config arrives as a plain object structurally typed as the *Config class, so the `as` narrows the\n * shared BaseRuleConfig param back to the concrete config the rule consumes.\n *\n * This registry contains source-rule factories only. Each accepts BaseRuleConfig and returns an\n * array of source rule instances for its config key. Workflow policies and command hints are owned\n * by agent-workflow-rules and are not inputs to this loader.\n */\ntype RuleFactory = (config: BaseRuleConfig) => readonly Rule[];\n\nconst BUILT_IN_RULE_MAP: Record<string, RuleFactory> = {\n 'no-any-unknown': (c: BaseRuleConfig) => [new NoAnyUnknownRule(c as NoAnyUnknownConfig)],\n 'no-implicit-any': (c: BaseRuleConfig) => [new NoImplicitAnyRule(c as NoImplicitAnyConfig)],\n 'max-file-lines': (c: BaseRuleConfig) => [new MaxFileLinesRule(c as MaxFileLinesConfig)],\n 'validate-ts-in-src': (c: BaseRuleConfig) => [new ValidateTsInSrcRule(c as ValidateTsInSrcConfig)],\n 'no-destructure': (c: BaseRuleConfig) => [new NoDestructureRule(c as NoDestructureConfig)],\n 'require-return-type': (c: BaseRuleConfig) => [new RequireReturnTypeRule(c as RequireReturnTypeConfig)],\n 'no-unmanaged-exceptions': (c: BaseRuleConfig) => [new NoUnmanagedExceptionsRule(c as NoUnmanagedExceptionsConfig)],\n 'catch-error-pattern': (c: BaseRuleConfig) => [new CatchErrorPatternRule(c as CatchErrorPatternConfig)],\n 'throw-cause-required': (c: BaseRuleConfig) => [new ThrowCauseRequiredRule(c as ThrowCauseRequiredConfig)],\n 'no-symbol-di-tokens': (c: BaseRuleConfig) => [new NoSymbolDiTokensRule(c as NoSymbolDiTokensConfig)],\n 'no-custom-css': (c: BaseRuleConfig) => [new NoCustomCssRule(c as NoCustomCssConfig)],\n 'no-process-exit-outside-main': (c: BaseRuleConfig) => [new NoProcessExitOutsideMainRule(c as NoProcessExitOutsideMainConfig)],\n 'no-js-files': (c: BaseRuleConfig) => [new NoJsFilesRule(c as NoJsFilesConfig)],\n\n};\n\n// Index the typed config by rule name. Each value is the rule's *Config (a plain object from\n// JSON), or undefined when the rule has no entry yet (the sync check reports those).\nfunction asConfigMap(config: WebpiecesRulesConfig): Record<string, BaseRuleConfig | undefined> {\n // webpieces-disable no-any-unknown -- index the typed config by dynamic rule name\n return config as unknown as Record<string, BaseRuleConfig | undefined>;\n}\n\n// webpieces-disable no-function-outside-class -- the module's entry point, beside loadMatchRules/loadKeylessBashRules; this whole loader is module-scope functions and a lone class for one of them would break the file's shape\nexport function loadRules(\n config: WebpiecesRulesConfig,\n workspaceRoot: string,\n): readonly Rule[] {\n const builtIns = loadBuiltInRules(config);\n const custom = loadCustomRules(config, workspaceRoot);\n return [...builtIns, ...custom];\n}\n\n// One MatchRule per entry of the `match-rules` array. Kept separate from loadRules (built-ins/custom)\n// because match-rules live in their own validated section — they must NOT flow through the\n// config-sync check, which compares rule names against the `rules`/`hookGuards` map.\nexport function loadMatchRules(matchRules: readonly MatchRuleConfig[]): Rule[] {\n return matchRules.map((c: MatchRuleConfig) => new MatchRule(c));\n}\n\n// Iterates CONFIG KEYS, not rule names — one entry can yield several rules (see BUILT_IN_RULE_MAP).\n// webpieces-disable no-function-outside-class -- the body of loadRules above, in the same module of loader functions\nexport function loadBuiltInRules(config: WebpiecesRulesConfig): Rule[] {\n const map = asConfigMap(config);\n const rules: Rule[] = [];\n for (const configKey of builtInConfigKeys) {\n const factory = BUILT_IN_RULE_MAP[configKey];\n if (!factory) {\n process.stderr.write(`[ai-hooks] unknown built-in config key: ${configKey}\\n`);\n continue;\n }\n const ruleConfig = map[configKey] ?? new EmptyRuleConfig();\n rules.push(...factory(ruleConfig));\n }\n return rules;\n}\n\n// webpieces-disable no-function-outside-class -- existing source registry helper contributed to both source and umbrella runners\nexport function loadCustomRules(config: WebpiecesRulesConfig, workspaceRoot: string): Rule[] {\n const dirs = config.rulesDir ?? [];\n // webpieces-disable no-any-unknown -- index the typed config by dynamic custom-rule name\n const map = config as unknown as Record<string, RuleOptions | undefined>;\n const rules: Rule[] = [];\n for (const plain of loadCustomPlainRules(dirs, workspaceRoot)) {\n const rawConfig = map[plain.name] ?? {};\n rules.push(new CustomRuleAdapter(plain, rawConfig));\n }\n return rules;\n}\n\nfunction loadCustomPlainRules(rulesDirs: readonly string[], workspaceRoot: string): PlainRule[] {\n const modules: PlainRule[] = [];\n for (const dir of rulesDirs) {\n const absDir = path.isAbsolute(dir) ? dir : path.join(workspaceRoot, dir);\n if (!fs.existsSync(absDir)) {\n process.stderr.write(`[ai-hooks] rulesDir not found: ${absDir}\\n`);\n continue;\n }\n let entries: string[];\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n entries = fs.readdirSync(absDir).filter((e: string) => e.endsWith('.js'));\n } catch (err: unknown) {\n const error = toError(err);\n throw new InformAiError(`Cannot read custom rules directory '${absDir}'`, { cause: error });\n }\n for (const entry of entries) {\n const full = path.join(absDir, entry);\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n const mod = require(full);\n const candidate = mod.default || mod;\n if (validateRule(candidate)) modules.push(candidate);\n } catch (err: unknown) {\n const error = toError(err);\n throw new InformAiError(`Cannot load custom rule '${full}'`, { cause: error });\n }\n }\n }\n return modules;\n}\n\n// webpieces-disable no-any-unknown -- validates untrusted require() output at system boundary\nfunction validateRule(rule: unknown): rule is PlainRule {\n if (!rule || typeof rule !== 'object') {\n process.stderr.write('[ai-hooks] rule is not an object, skipping\\n');\n return false;\n }\n // webpieces-disable no-any-unknown -- narrowing from unknown at system boundary\n const obj = rule as Record<string, unknown>;\n for (const field of REQUIRED_FIELDS) {\n if (obj[field] === undefined) {\n const name = typeof obj['name'] === 'string' ? obj['name'] : '<unnamed>';\n process.stderr.write(`[ai-hooks] rule \"${name}\" missing required field: ${field}\\n`);\n return false;\n }\n }\n if (!VALID_SCOPES.has(obj['scope'] as string)) {\n process.stderr.write(`[ai-hooks] rule \"${obj['name']}\" has invalid scope: ${String(obj['scope'])}\\n`);\n return false;\n }\n if (!Array.isArray(obj['files'])) {\n process.stderr.write(`[ai-hooks] rule \"${obj['name']}\" files must be an array\\n`);\n return false;\n }\n if (typeof obj['check'] !== 'function') {\n process.stderr.write(`[ai-hooks] rule \"${obj['name']}\" check must be a function\\n`);\n return false;\n }\n return true;\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  import { CatchErrorPatternConfig } from '@webpieces/rules-config';
2
- import type { EditContext, Violation } from '../types';
3
- import { EditRuleBase } from '../rule-base';
4
- import { FixHint } from '../fix-hint';
2
+ import type { EditContext, Violation } from '@webpieces/hook-runtime';
3
+ import { EditRuleBase } from '@webpieces/hook-runtime';
4
+ import { FixHint } from '@webpieces/hook-runtime';
5
5
  export declare class CatchErrorPatternRule extends EditRuleBase<CatchErrorPatternConfig> {
6
6
  constructor(config: CatchErrorPatternConfig);
7
7
  readonly description = "Catch blocks must use: catch (err: unknown) { const error = toError(err); }";
@@ -2,10 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CatchErrorPatternRule = void 0;
4
4
  const rules_config_1 = require("@webpieces/rules-config");
5
- const types_1 = require("../types");
6
- const rule_base_1 = require("../rule-base");
7
- const fix_hint_1 = require("../fix-hint");
8
- const instruct_ai_writer_1 = require("../instruct-ai-writer");
5
+ const hook_runtime_1 = require("@webpieces/hook-runtime");
6
+ const hook_runtime_2 = require("@webpieces/hook-runtime");
7
+ const hook_runtime_3 = require("@webpieces/hook-runtime");
8
+ const rules_config_2 = require("@webpieces/rules-config");
9
9
  /**
10
10
  * Matches a catch clause opening: } catch (paramName: typeAnnotation) {
11
11
  * Captures: group 1 = param name, group 2 = type annotation (if present)
@@ -25,15 +25,15 @@ const TO_ERROR_PATTERN = /^\s*(?:\/\/\s*)?const\s+(\w+)\s*=\s*toError\(\s*(\w+)\
25
25
  * the line. Trimming a stripped comment line therefore yields `//`, not `''`. See findToErrorStatement().
26
26
  */
27
27
  const COMMENT_REMNANT = /\/\/\s*$/;
28
- class CatchErrorPatternRule extends rule_base_1.EditRuleBase {
28
+ class CatchErrorPatternRule extends hook_runtime_2.EditRuleBase {
29
29
  constructor(config) { super(config, 'catch-error-pattern', 'catch-error-pattern'); }
30
30
  description = 'Catch blocks must use: catch (err: unknown) { const error = toError(err); }'; // webpieces-disable catch-error-pattern -- example text in a description string
31
31
  files = ['**/*.ts', '**/*.tsx'];
32
32
  get fixHint() {
33
- return new fix_hint_1.FixHint('Catch block does not follow the toError(err) pattern.', 'Name the catch parameter err (err2/err3 when nested), then pick one:', [
33
+ return new hook_runtime_3.FixHint('Catch block does not follow the toError(err) pattern.', 'Name the catch parameter err (err2/err3 when nested), then pick one:', [
34
34
  new rules_config_1.Option('Add as the first statement in the catch block: const error = toError(err);', true),
35
35
  new rules_config_1.Option('To explicitly ignore the error: //const error = toError(err);'),
36
- ], new fix_hint_1.DisableEscape(this.config.disableAllowed ?? true, '// webpieces-disable catch-error-pattern -- <reason>'));
36
+ ], new hook_runtime_3.DisableEscape(this.config.disableAllowed ?? true, '// webpieces-disable catch-error-pattern -- <reason>'));
37
37
  }
38
38
  check(ctx) {
39
39
  const disableAllowed = this.config.disableAllowed ?? true;
@@ -56,34 +56,34 @@ class CatchErrorPatternRule extends rule_base_1.EditRuleBase {
56
56
  const expectedVar = 'error' + suffix;
57
57
  // Check parameter name
58
58
  if (actualParam !== expectedParam) {
59
- violations.push(new types_1.Violation(lineNum, ctx.lines[i].trim(), `Catch parameter must be named "${expectedParam}" (or "err2", "err3" for nested catches), got "${actualParam}"`));
59
+ violations.push(new hook_runtime_1.Violation(lineNum, ctx.lines[i].trim(), `Catch parameter must be named "${expectedParam}" (or "err2", "err3" for nested catches), got "${actualParam}"`));
60
60
  }
61
61
  // Check type annotation is unknown
62
62
  if (typeAnnotation !== 'unknown') {
63
63
  const msg = typeAnnotation
64
64
  ? `Catch parameter must be typed as "unknown": catch (${expectedParam}: unknown), got "${typeAnnotation}"`
65
65
  : `Catch parameter must be typed as "unknown": catch (${expectedParam}: unknown)`;
66
- violations.push(new types_1.Violation(lineNum, ctx.lines[i].trim(), msg));
66
+ violations.push(new hook_runtime_1.Violation(lineNum, ctx.lines[i].trim(), msg));
67
67
  }
68
68
  // Find next non-blank line after the catch opening to check for toError
69
69
  const toErrorResult = this.findToErrorStatement(ctx, i + 1);
70
70
  if (toErrorResult === 'not-found') {
71
- violations.push(new types_1.Violation(lineNum, ctx.lines[i].trim(), `Catch block must call toError(${actualParam}) as first statement: const ${expectedVar} = toError(${actualParam}); or //const ${expectedVar} = toError(${actualParam});`));
71
+ violations.push(new hook_runtime_1.Violation(lineNum, ctx.lines[i].trim(), `Catch block must call toError(${actualParam}) as first statement: const ${expectedVar} = toError(${actualParam}); or //const ${expectedVar} = toError(${actualParam});`));
72
72
  }
73
73
  else if (toErrorResult !== 'end-of-content') {
74
74
  // Validate variable name and param match
75
75
  if (toErrorResult.varName !== expectedVar) {
76
76
  const toErrorLineNum = toErrorResult.lineIndex + 1;
77
- violations.push(new types_1.Violation(toErrorLineNum, ctx.lines[toErrorResult.lineIndex].trim(), `Error variable must be named "${expectedVar}", got "${toErrorResult.varName}"`));
77
+ violations.push(new hook_runtime_1.Violation(toErrorLineNum, ctx.lines[toErrorResult.lineIndex].trim(), `Error variable must be named "${expectedVar}", got "${toErrorResult.varName}"`));
78
78
  }
79
79
  if (toErrorResult.paramName !== actualParam) {
80
80
  const toErrorLineNum = toErrorResult.lineIndex + 1;
81
- violations.push(new types_1.Violation(toErrorLineNum, ctx.lines[toErrorResult.lineIndex].trim(), `toError() must be called with "${actualParam}", got "${toErrorResult.paramName}"`));
81
+ violations.push(new hook_runtime_1.Violation(toErrorLineNum, ctx.lines[toErrorResult.lineIndex].trim(), `toError() must be called with "${actualParam}", got "${toErrorResult.paramName}"`));
82
82
  }
83
83
  }
84
84
  }
85
85
  if (violations.length > 0)
86
- (0, instruct_ai_writer_1.writeTemplateIfMissing)(ctx.workspaceRoot, 'webpieces.exceptions.md');
86
+ (0, rules_config_2.writeTemplateIfMissing)(ctx.workspaceRoot, 'webpieces.exceptions.md');
87
87
  return violations;
88
88
  }
89
89
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"catch-error-pattern.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/ai-hook-rules/src/core/rules/catch-error-pattern.ts"],"names":[],"mappings":";;;AAAA,0DAAsF;AAGtF,oCAA0C;AAC1C,4CAA4C;AAC5C,0CAAqD;AACrD,8DAA+D;AAE/D;;;GAGG;AACH,MAAM,aAAa,GAAG,4CAA4C,CAAC;AAEnE;;;;;;;GAOG;AACH,MAAM,gBAAgB,GAAG,qEAAqE,CAAC;AAE/F;;;GAGG;AACH,MAAM,eAAe,GAAG,UAAU,CAAC;AAQnC,MA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CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;YACpE,IAAI,QAAQ;gBAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC;YAEpF,MAAM,IAAI,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;YAC7D,4FAA4F;YAC5F,8BAA8B;YAC9B,IAAI,IAAI,KAAK,EAAE,IAAI,IAAI,KAAK,GAAG;gBAAE,SAAS;YAE1C,MAAM,KAAK,GAAG,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC1C,IAAI,KAAK;gBAAE,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC;YAC3E,6CAA6C;YAC7C,OAAO,WAAW,CAAC;QACvB,CAAC;QACD,+DAA+D;QAC/D,OAAO,gBAAgB,CAAC;IAC5B,CAAC;CACJ;AAnID,sDAmIC","sourcesContent":["import { CatchErrorPatternConfig, RULE_NAMES, Option } from '@webpieces/rules-config';\n\nimport type { EditContext, Violation } from '../types';\nimport { Violation as V } from '../types';\nimport { EditRuleBase } from '../rule-base';\nimport { FixHint, DisableEscape } from '../fix-hint';\nimport { writeTemplateIfMissing } from '../instruct-ai-writer';\n\n/**\n * Matches a catch clause opening: } catch (paramName: typeAnnotation) {\n * Captures: group 1 = param name, group 2 = type annotation (if present)\n */\nconst CATCH_PATTERN = /\\bcatch\\s*\\(\\s*(\\w+)(?:\\s*:\\s*(\\w+))?\\s*\\)/;\n\n/**\n * Matches the required toError first statement (with or without comment-out).\n * Group 1 = variable name, group 2 = param passed to toError\n *\n * The optional `//` prefix is what makes Fix Option 2 — \"to explicitly ignore the error, write\n * `//const error = toError(err);`\" — a real escape. It is only reachable when the pattern is tested\n * against the RAW source line; see findToErrorStatement() for why both line arrays are needed.\n */\nconst TO_ERROR_PATTERN = /^\\s*(?:\\/\\/\\s*)?const\\s+(\\w+)\\s*=\\s*toError\\(\\s*(\\w+)\\s*\\)\\s*;?\\s*$/;\n\n/**\n * What `stripTsNoise` leaves behind where a `//` comment was: the two slashes, then blanks to the end of\n * the line. Trimming a stripped comment line therefore yields `//`, not `''`. See findToErrorStatement().\n */\nconst COMMENT_REMNANT = /\\/\\/\\s*$/;\n\ninterface ToErrorMatch {\n varName: string;\n paramName: string;\n lineIndex: number;\n}\n\nexport class CatchErrorPatternRule extends EditRuleBase<CatchErrorPatternConfig> {\n constructor(config: CatchErrorPatternConfig) { super(config, 'catch-error-pattern', 'catch-error-pattern'); }\n\n readonly description = 'Catch blocks must use: catch (err: unknown) { const error = toError(err); }'; // webpieces-disable catch-error-pattern -- example text in a description string\n override readonly files = ['**/*.ts', '**/*.tsx'];\n get fixHint(): FixHint {\n return new FixHint(\n 'Catch block does not follow the toError(err) pattern.',\n 'Name the catch parameter err (err2/err3 when nested), then pick one:',\n [\n new Option('Add as the first statement in the catch block: const error = toError(err);', true),\n new Option('To explicitly ignore the error: //const error = toError(err);'),\n ],\n new DisableEscape(this.config.disableAllowed ?? true, '// webpieces-disable catch-error-pattern -- <reason>'), // webpieces-disable catch-error-pattern -- example text in a hint string\n );\n }\n\n check(ctx: EditContext): readonly Violation[] {\n const disableAllowed = this.config.disableAllowed ?? true;\n const violations: V[] = [];\n const lines = ctx.strippedLines;\n\n for (let i = 0; i < lines.length; i += 1) {\n const stripped = lines[i];\n const catchMatch = CATCH_PATTERN.exec(stripped);\n if (!catchMatch) continue;\n\n const lineNum = i + 1;\n if (disableAllowed && ctx.isLineDisabled(lineNum, RULE_NAMES.CATCH_ERROR_PATTERN)) continue;\n\n const actualParam = catchMatch[1];\n const typeAnnotation = catchMatch[2];\n\n // Determine expected names from suffix on the actual param (err, err2, err3...)\n const suffixMatch = actualParam.match(/^err(\\d*)$/);\n const suffix = suffixMatch ? suffixMatch[1] : '';\n const expectedParam = 'err' + suffix;\n const expectedVar = 'error' + suffix;\n\n // Check parameter name\n if (actualParam !== expectedParam) {\n violations.push(new V(\n lineNum,\n ctx.lines[i].trim(),\n `Catch parameter must be named \"${expectedParam}\" (or \"err2\", \"err3\" for nested catches), got \"${actualParam}\"`,\n ));\n }\n\n // Check type annotation is unknown\n if (typeAnnotation !== 'unknown') {\n const msg = typeAnnotation\n ? `Catch parameter must be typed as \"unknown\": catch (${expectedParam}: unknown), got \"${typeAnnotation}\"`\n : `Catch parameter must be typed as \"unknown\": catch (${expectedParam}: unknown)`;\n violations.push(new V(lineNum, ctx.lines[i].trim(), msg));\n }\n\n // Find next non-blank line after the catch opening to check for toError\n const toErrorResult = this.findToErrorStatement(ctx, i + 1);\n if (toErrorResult === 'not-found') {\n violations.push(new V(\n lineNum,\n ctx.lines[i].trim(),\n `Catch block must call toError(${actualParam}) as first statement: const ${expectedVar} = toError(${actualParam}); or //const ${expectedVar} = toError(${actualParam});`,\n ));\n } else if (toErrorResult !== 'end-of-content') {\n // Validate variable name and param match\n if (toErrorResult.varName !== expectedVar) {\n const toErrorLineNum = toErrorResult.lineIndex + 1;\n violations.push(new V(\n toErrorLineNum,\n ctx.lines[toErrorResult.lineIndex].trim(),\n `Error variable must be named \"${expectedVar}\", got \"${toErrorResult.varName}\"`,\n ));\n }\n if (toErrorResult.paramName !== actualParam) {\n const toErrorLineNum = toErrorResult.lineIndex + 1;\n violations.push(new V(\n toErrorLineNum,\n ctx.lines[toErrorResult.lineIndex].trim(),\n `toError() must be called with \"${actualParam}\", got \"${toErrorResult.paramName}\"`,\n ));\n }\n }\n }\n if (violations.length > 0) writeTemplateIfMissing(ctx.workspaceRoot, 'webpieces.exceptions.md');\n return violations;\n }\n\n /**\n * The first statement of the catch block, judged against BOTH line arrays — and that pairing is the\n * whole fix for a bug that made this rule refuse the exact cure it prescribes.\n *\n * The rule FINDS catch clauses in `ctx.strippedLines`, which is right: a `catch (e) {` inside a\n * comment is not a catch clause. But it used to also LOOK FOR the toError statement there, and\n * stripping deletes `//const error = toError(err);` down to an empty line — so Fix Option 2, the\n * documented way to say \"this error is deliberately ignored\", was reported as \"no toError statement\"\n * every single time. TO_ERROR_PATTERN's optional `//` prefix could never match, because nothing\n * carrying a `//` ever reached it. 34 catches in this repo already use that form.\n *\n * So: the RAW line decides whether the commented form is present, and the STRIPPED line decides what\n * counts as \"the first statement\" (a blank line, a `{`, or an unrelated comment is skipped past).\n * Raw is tested first because it is the only array in which the comment form survives; a live\n * statement with a trailing comment (`const error = toError(err); // why`) fails the raw test on the\n * `$` anchor and is then matched on its stripped form, which is exactly the intent.\n *\n * COMMENT_REMNANT is the other half of that, and it is a property of the stripper: `stripTsNoise`\n * KEEPS the `//` marker and blanks only what follows it, so a stripped comment line trims to `//`\n * rather than to the empty string. Without normalizing that away, `//` is neither blank nor a `{`,\n * so it was taken for the first statement — which is the mechanical reason a commented-out toError\n * reported \"no toError statement\", and the reason a trailing `// why` on a LIVE toError reported the\n * same. One replace fixes both, in the one place the question is asked.\n */\n private findToErrorStatement(ctx: EditContext, startIndex: number): ToErrorMatch | 'not-found' | 'end-of-content' {\n const stripped = ctx.strippedLines;\n for (let j = startIndex; j < stripped.length; j += 1) {\n const rawMatch = TO_ERROR_PATTERN.exec((ctx.lines[j] ?? '').trim());\n if (rawMatch) return { varName: rawMatch[1], paramName: rawMatch[2], lineIndex: j };\n\n const line = stripped[j].replace(COMMENT_REMNANT, '').trim();\n // Blank, an opening brace, or a comment that stripping emptied — none of these is the first\n // statement, so keep looking.\n if (line === '' || line === '{') continue;\n\n const match = TO_ERROR_PATTERN.exec(line);\n if (match) return { varName: match[1], paramName: match[2], lineIndex: j };\n // First real statement is not a toError call\n return 'not-found';\n }\n // Ran off the end of the edit content — can't validate further\n return 'end-of-content';\n }\n}\n"]}
1
+ {"version":3,"file":"catch-error-pattern.js","sourceRo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;;;;;;;;;OAuBG;IACK,oBAAoB,CAAC,GAAgB,EAAE,UAAkB;QAC7D,MAAM,QAAQ,GAAG,GAAG,CAAC,aAAa,CAAC;QACnC,KAAK,IAAI,CAAC,GAAG,UAAU,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;YACnD,MAAM,QAAQ,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;YACpE,IAAI,QAAQ;gBAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC;YAEpF,MAAM,IAAI,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;YAC7D,4FAA4F;YAC5F,8BAA8B;YAC9B,IAAI,IAAI,KAAK,EAAE,IAAI,IAAI,KAAK,GAAG;gBAAE,SAAS;YAE1C,MAAM,KAAK,GAAG,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC1C,IAAI,KAAK;gBAAE,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC;YAC3E,6CAA6C;YAC7C,OAAO,WAAW,CAAC;QACvB,CAAC;QACD,+DAA+D;QAC/D,OAAO,gBAAgB,CAAC;IAC5B,CAAC;CACJ;AAnID,sDAmIC","sourcesContent":["import { CatchErrorPatternConfig, RULE_NAMES, Option } from '@webpieces/rules-config';\n\nimport type { EditContext, Violation } from '@webpieces/hook-runtime';\nimport { Violation as V } from '@webpieces/hook-runtime';\nimport { EditRuleBase } from '@webpieces/hook-runtime';\nimport { FixHint, DisableEscape } from '@webpieces/hook-runtime';\nimport { writeTemplateIfMissing } from '@webpieces/rules-config';\n\n/**\n * Matches a catch clause opening: } catch (paramName: typeAnnotation) {\n * Captures: group 1 = param name, group 2 = type annotation (if present)\n */\nconst CATCH_PATTERN = /\\bcatch\\s*\\(\\s*(\\w+)(?:\\s*:\\s*(\\w+))?\\s*\\)/;\n\n/**\n * Matches the required toError first statement (with or without comment-out).\n * Group 1 = variable name, group 2 = param passed to toError\n *\n * The optional `//` prefix is what makes Fix Option 2 — \"to explicitly ignore the error, write\n * `//const error = toError(err);`\" — a real escape. It is only reachable when the pattern is tested\n * against the RAW source line; see findToErrorStatement() for why both line arrays are needed.\n */\nconst TO_ERROR_PATTERN = /^\\s*(?:\\/\\/\\s*)?const\\s+(\\w+)\\s*=\\s*toError\\(\\s*(\\w+)\\s*\\)\\s*;?\\s*$/;\n\n/**\n * What `stripTsNoise` leaves behind where a `//` comment was: the two slashes, then blanks to the end of\n * the line. Trimming a stripped comment line therefore yields `//`, not `''`. See findToErrorStatement().\n */\nconst COMMENT_REMNANT = /\\/\\/\\s*$/;\n\ninterface ToErrorMatch {\n varName: string;\n paramName: string;\n lineIndex: number;\n}\n\nexport class CatchErrorPatternRule extends EditRuleBase<CatchErrorPatternConfig> {\n constructor(config: CatchErrorPatternConfig) { super(config, 'catch-error-pattern', 'catch-error-pattern'); }\n\n readonly description = 'Catch blocks must use: catch (err: unknown) { const error = toError(err); }'; // webpieces-disable catch-error-pattern -- example text in a description string\n override readonly files = ['**/*.ts', '**/*.tsx'];\n get fixHint(): FixHint {\n return new FixHint(\n 'Catch block does not follow the toError(err) pattern.',\n 'Name the catch parameter err (err2/err3 when nested), then pick one:',\n [\n new Option('Add as the first statement in the catch block: const error = toError(err);', true),\n new Option('To explicitly ignore the error: //const error = toError(err);'),\n ],\n new DisableEscape(this.config.disableAllowed ?? true, '// webpieces-disable catch-error-pattern -- <reason>'), // webpieces-disable catch-error-pattern -- example text in a hint string\n );\n }\n\n check(ctx: EditContext): readonly Violation[] {\n const disableAllowed = this.config.disableAllowed ?? true;\n const violations: V[] = [];\n const lines = ctx.strippedLines;\n\n for (let i = 0; i < lines.length; i += 1) {\n const stripped = lines[i];\n const catchMatch = CATCH_PATTERN.exec(stripped);\n if (!catchMatch) continue;\n\n const lineNum = i + 1;\n if (disableAllowed && ctx.isLineDisabled(lineNum, RULE_NAMES.CATCH_ERROR_PATTERN)) continue;\n\n const actualParam = catchMatch[1];\n const typeAnnotation = catchMatch[2];\n\n // Determine expected names from suffix on the actual param (err, err2, err3...)\n const suffixMatch = actualParam.match(/^err(\\d*)$/);\n const suffix = suffixMatch ? suffixMatch[1] : '';\n const expectedParam = 'err' + suffix;\n const expectedVar = 'error' + suffix;\n\n // Check parameter name\n if (actualParam !== expectedParam) {\n violations.push(new V(\n lineNum,\n ctx.lines[i].trim(),\n `Catch parameter must be named \"${expectedParam}\" (or \"err2\", \"err3\" for nested catches), got \"${actualParam}\"`,\n ));\n }\n\n // Check type annotation is unknown\n if (typeAnnotation !== 'unknown') {\n const msg = typeAnnotation\n ? `Catch parameter must be typed as \"unknown\": catch (${expectedParam}: unknown), got \"${typeAnnotation}\"`\n : `Catch parameter must be typed as \"unknown\": catch (${expectedParam}: unknown)`;\n violations.push(new V(lineNum, ctx.lines[i].trim(), msg));\n }\n\n // Find next non-blank line after the catch opening to check for toError\n const toErrorResult = this.findToErrorStatement(ctx, i + 1);\n if (toErrorResult === 'not-found') {\n violations.push(new V(\n lineNum,\n ctx.lines[i].trim(),\n `Catch block must call toError(${actualParam}) as first statement: const ${expectedVar} = toError(${actualParam}); or //const ${expectedVar} = toError(${actualParam});`,\n ));\n } else if (toErrorResult !== 'end-of-content') {\n // Validate variable name and param match\n if (toErrorResult.varName !== expectedVar) {\n const toErrorLineNum = toErrorResult.lineIndex + 1;\n violations.push(new V(\n toErrorLineNum,\n ctx.lines[toErrorResult.lineIndex].trim(),\n `Error variable must be named \"${expectedVar}\", got \"${toErrorResult.varName}\"`,\n ));\n }\n if (toErrorResult.paramName !== actualParam) {\n const toErrorLineNum = toErrorResult.lineIndex + 1;\n violations.push(new V(\n toErrorLineNum,\n ctx.lines[toErrorResult.lineIndex].trim(),\n `toError() must be called with \"${actualParam}\", got \"${toErrorResult.paramName}\"`,\n ));\n }\n }\n }\n if (violations.length > 0) writeTemplateIfMissing(ctx.workspaceRoot, 'webpieces.exceptions.md');\n return violations;\n }\n\n /**\n * The first statement of the catch block, judged against BOTH line arrays — and that pairing is the\n * whole fix for a bug that made this rule refuse the exact cure it prescribes.\n *\n * The rule FINDS catch clauses in `ctx.strippedLines`, which is right: a `catch (e) {` inside a\n * comment is not a catch clause. But it used to also LOOK FOR the toError statement there, and\n * stripping deletes `//const error = toError(err);` down to an empty line — so Fix Option 2, the\n * documented way to say \"this error is deliberately ignored\", was reported as \"no toError statement\"\n * every single time. TO_ERROR_PATTERN's optional `//` prefix could never match, because nothing\n * carrying a `//` ever reached it. 34 catches in this repo already use that form.\n *\n * So: the RAW line decides whether the commented form is present, and the STRIPPED line decides what\n * counts as \"the first statement\" (a blank line, a `{`, or an unrelated comment is skipped past).\n * Raw is tested first because it is the only array in which the comment form survives; a live\n * statement with a trailing comment (`const error = toError(err); // why`) fails the raw test on the\n * `$` anchor and is then matched on its stripped form, which is exactly the intent.\n *\n * COMMENT_REMNANT is the other half of that, and it is a property of the stripper: `stripTsNoise`\n * KEEPS the `//` marker and blanks only what follows it, so a stripped comment line trims to `//`\n * rather than to the empty string. Without normalizing that away, `//` is neither blank nor a `{`,\n * so it was taken for the first statement — which is the mechanical reason a commented-out toError\n * reported \"no toError statement\", and the reason a trailing `// why` on a LIVE toError reported the\n * same. One replace fixes both, in the one place the question is asked.\n */\n private findToErrorStatement(ctx: EditContext, startIndex: number): ToErrorMatch | 'not-found' | 'end-of-content' {\n const stripped = ctx.strippedLines;\n for (let j = startIndex; j < stripped.length; j += 1) {\n const rawMatch = TO_ERROR_PATTERN.exec((ctx.lines[j] ?? '').trim());\n if (rawMatch) return { varName: rawMatch[1], paramName: rawMatch[2], lineIndex: j };\n\n const line = stripped[j].replace(COMMENT_REMNANT, '').trim();\n // Blank, an opening brace, or a comment that stripping emptied — none of these is the first\n // statement, so keep looking.\n if (line === '' || line === '{') continue;\n\n const match = TO_ERROR_PATTERN.exec(line);\n if (match) return { varName: match[1], paramName: match[2], lineIndex: j };\n // First real statement is not a toError call\n return 'not-found';\n }\n // Ran off the end of the edit content — can't validate further\n return 'end-of-content';\n }\n}\n"]}
@@ -1,15 +1,2 @@
1
- /**
2
- * Every built-in CONFIG KEY, i.e. every key that must have an entry under `rules` / `hookGuards`.
3
- *
4
- * This is the KEY set, not the CLASS set, and the distinction is the whole point of the collapse: the
5
- * four branch-state classes contribute the single key `branch-state-guard`, the four PR-lifecycle
6
- * classes the single key `pr-lifecycle-guard`. The loader iterates this array and asks
7
- * BUILT_IN_RULE_MAP for the rules each key builds, and the config-sync check (fault Y) compares a
8
- * loaded rule's `configKey` — never its `name` — against the keys present in the config.
9
- *
10
- * It used to be `builtInRuleNames`, one entry per class, which is the same list only because name and
11
- * key happened to coincide for every rule. Naming it for what it is stops that coincidence being
12
- * re-assumed: a rule NAME appearing here would be an entry every consumer is forced to configure for a
13
- * class that has no switch of its own.
14
- */
1
+ /** The thirteen source configuration keys owned by this rule provider. */
15
2
  export declare const builtInConfigKeys: readonly string[];
@@ -1,20 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.builtInConfigKeys = void 0;
4
- /**
5
- * Every built-in CONFIG KEY, i.e. every key that must have an entry under `rules` / `hookGuards`.
6
- *
7
- * This is the KEY set, not the CLASS set, and the distinction is the whole point of the collapse: the
8
- * four branch-state classes contribute the single key `branch-state-guard`, the four PR-lifecycle
9
- * classes the single key `pr-lifecycle-guard`. The loader iterates this array and asks
10
- * BUILT_IN_RULE_MAP for the rules each key builds, and the config-sync check (fault Y) compares a
11
- * loaded rule's `configKey` — never its `name` — against the keys present in the config.
12
- *
13
- * It used to be `builtInRuleNames`, one entry per class, which is the same list only because name and
14
- * key happened to coincide for every rule. Naming it for what it is stops that coincidence being
15
- * re-assumed: a rule NAME appearing here would be an entry every consumer is forced to configure for a
16
- * class that has no switch of its own.
17
- */
4
+ /** The thirteen source configuration keys owned by this rule provider. */
18
5
  exports.builtInConfigKeys = [
19
6
  'no-any-unknown',
20
7
  'no-implicit-any',
@@ -29,8 +16,5 @@ exports.builtInConfigKeys = [
29
16
  'no-symbol-di-tokens',
30
17
  'no-custom-css',
31
18
  'no-process-exit-outside-main',
32
- 'branch-creation-guard',
33
- 'pr-lifecycle-guard',
34
- 'branch-state-guard',
35
19
  ];
36
20
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/ai-hook-rules/src/core/rules/index.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;GAaG;AACU,QAAA,iBAAiB,GAAsB;IAChD,gBAAgB;IAChB,iBAAiB;IACjB,gBAAgB;IAChB,oBAAoB;IACpB,aAAa;IACb,gBAAgB;IAChB,qBAAqB;IACrB,yBAAyB;IACzB,qBAAqB;IACrB,sBAAsB;IACtB,qBAAqB;IACrB,eAAe;IACf,8BAA8B;IAC9B,uBAAuB;IACvB,oBAAoB;IACpB,oBAAoB;CACvB,CAAC","sourcesContent":["/**\n * Every built-in CONFIG KEY, i.e. every key that must have an entry under `rules` / `hookGuards`.\n *\n * This is the KEY set, not the CLASS set, and the distinction is the whole point of the collapse: the\n * four branch-state classes contribute the single key `branch-state-guard`, the four PR-lifecycle\n * classes the single key `pr-lifecycle-guard`. The loader iterates this array and asks\n * BUILT_IN_RULE_MAP for the rules each key builds, and the config-sync check (fault Y) compares a\n * loaded rule's `configKey` — never its `name` — against the keys present in the config.\n *\n * It used to be `builtInRuleNames`, one entry per class, which is the same list only because name and\n * key happened to coincide for every rule. Naming it for what it is stops that coincidence being\n * re-assumed: a rule NAME appearing here would be an entry every consumer is forced to configure for a\n * class that has no switch of its own.\n */\nexport const builtInConfigKeys: readonly string[] = [\n 'no-any-unknown',\n 'no-implicit-any',\n 'max-file-lines',\n 'validate-ts-in-src',\n 'no-js-files',\n 'no-destructure',\n 'require-return-type',\n 'no-unmanaged-exceptions',\n 'catch-error-pattern',\n 'throw-cause-required',\n 'no-symbol-di-tokens',\n 'no-custom-css',\n 'no-process-exit-outside-main',\n 'branch-creation-guard',\n 'pr-lifecycle-guard',\n 'branch-state-guard',\n];\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/ai-hook-rules/src/core/rules/index.ts"],"names":[],"mappings":";;;AAAA,0EAA0E;AAC7D,QAAA,iBAAiB,GAAsB;IAChD,gBAAgB;IAChB,iBAAiB;IACjB,gBAAgB;IAChB,oBAAoB;IACpB,aAAa;IACb,gBAAgB;IAChB,qBAAqB;IACrB,yBAAyB;IACzB,qBAAqB;IACrB,sBAAsB;IACtB,qBAAqB;IACrB,eAAe;IACf,8BAA8B;CACjC,CAAC","sourcesContent":["/** The thirteen source configuration keys owned by this rule provider. */\nexport const builtInConfigKeys: readonly string[] = [\n 'no-any-unknown',\n 'no-implicit-any',\n 'max-file-lines',\n 'validate-ts-in-src',\n 'no-js-files',\n 'no-destructure',\n 'require-return-type',\n 'no-unmanaged-exceptions',\n 'catch-error-pattern',\n 'throw-cause-required',\n 'no-symbol-di-tokens',\n 'no-custom-css',\n 'no-process-exit-outside-main',\n];\n"]}
@@ -1,7 +1,7 @@
1
1
  import { MatchRuleConfig } from '@webpieces/rules-config';
2
- import type { EditContext, Violation } from '../types';
3
- import { EditRuleBase } from '../rule-base';
4
- import { FixHint } from '../fix-hint';
2
+ import type { EditContext, Violation } from '@webpieces/hook-runtime';
3
+ import { EditRuleBase } from '@webpieces/hook-runtime';
4
+ import { FixHint } from '@webpieces/hook-runtime';
5
5
  /**
6
6
  * A single client-authored content guard from the `match-rules` array. Unlike the framework's
7
7
  * keyed rules, its regexes and message live entirely in webpieces.config.json — one MatchRule is
@@ -2,15 +2,15 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MatchRule = void 0;
4
4
  const rules_config_1 = require("@webpieces/rules-config");
5
- const types_1 = require("../types");
6
- const rule_base_1 = require("../rule-base");
7
- const fix_hint_1 = require("../fix-hint");
5
+ const hook_runtime_1 = require("@webpieces/hook-runtime");
6
+ const hook_runtime_2 = require("@webpieces/hook-runtime");
7
+ const hook_runtime_3 = require("@webpieces/hook-runtime");
8
8
  /**
9
9
  * A single client-authored content guard from the `match-rules` array. Unlike the framework's
10
10
  * keyed rules, its regexes and message live entirely in webpieces.config.json — one MatchRule is
11
11
  * instantiated per array entry (see loadMatchRules). `name` doubles as the disable token.
12
12
  */
13
- class MatchRule extends rule_base_1.EditRuleBase {
13
+ class MatchRule extends hook_runtime_2.EditRuleBase {
14
14
  // A match-rule is its OWN key: it lives in the `match-rules` array, not in `rules`/`hookGuards`,
15
15
  // so name and configKey are the same string here and always will be. Passed explicitly all the
16
16
  // same — there is no defaulted spelling of this decision anywhere.
@@ -21,7 +21,7 @@ class MatchRule extends rule_base_1.EditRuleBase {
21
21
  }
22
22
  get fixHint() {
23
23
  const c = this.config;
24
- return new fix_hint_1.FixHint(`${c.name}: matched a disallowed pattern.`, c.mainMessage, (c.options ?? []).map((o) => new rules_config_1.Option(o)), new fix_hint_1.DisableEscape(c.disableAllowed ?? true, `// webpieces-disable ${c.name} -- <reason>`));
24
+ return new hook_runtime_3.FixHint(`${c.name}: matched a disallowed pattern.`, c.mainMessage, (c.options ?? []).map((o) => new rules_config_1.Option(o)), new hook_runtime_3.DisableEscape(c.disableAllowed ?? true, `// webpieces-disable ${c.name} -- <reason>`));
25
25
  }
26
26
  check(ctx) {
27
27
  const c = this.config;
@@ -30,7 +30,7 @@ class MatchRule extends rule_base_1.EditRuleBase {
30
30
  for (const hit of (0, rules_config_1.findMatchRuleViolations)(ctx.lines, ctx.relativePath, c)) {
31
31
  if (disableAllowed && ctx.isLineDisabled(hit.line, c.name))
32
32
  continue;
33
- violations.push(new types_1.Violation(hit.line, hit.context));
33
+ violations.push(new hook_runtime_1.Violation(hit.line, hit.context));
34
34
  }
35
35
  return violations;
36
36
  }
@@ -1 +1 @@
1
- {"version":3,"file":"match-rule.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/ai-hook-rules/src/core/rules/match-rule.ts"],"names":[],"mappings":";;;AAAA,0DAA2F;AAG3F,oCAA0C;AAC1C,4CAA4C;AAC5C,0CAAqD;AAErD;;;;GAIG;AACH,MAAa,SAAU,SAAQ,wBAA6B;IACxD,iGAAiG;IACjG,+FAA+F;IAC/F,mEAAmE;IACnE,YAAY,MAAuB,IAAI,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAE/D,KAAK,GAAG,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;IAElD,IAAI,WAAW;QACX,OAAO,kBAAkB,IAAI,CAAC,MAAM,CAAC,IAAI,6EAA6E,CAAC;IAC3H,CAAC;IAED,IAAI,OAAO;QACP,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC;QACtB,OAAO,IAAI,kBAAO,CACd,GAAG,CAAC,CAAC,IAAI,iCAAiC,EAC1C,CAAC,CAAC,WAAW,EACb,CAAC,CAAC,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,IAAI,qBAAM,CAAC,CAAC,CAAC,CAAC,EACnD,IAAI,wBAAa,CAAC,CAAC,CAAC,cAAc,IAAI,IAAI,EAAE,wBAAwB,CAAC,CAAC,IAAI,cAAc,CAAC,CAC5F,CAAC;IACN,CAAC;IAED,KAAK,CAAC,GAAgB;QAClB,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC;QACtB,MAAM,cAAc,GAAG,CAAC,CAAC,cAAc,IAAI,IAAI,CAAC;QAChD,MAAM,UAAU,GAAQ,EAAE,CAAC;QAC3B,KAAK,MAAM,GAAG,IAAI,IAAA,sCAAuB,EAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,YAAY,EAAE,CAAC,CAAC,EAAE,CAAC;YACxE,IAAI,cAAc,IAAI,GAAG,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC;gBAAE,SAAS;YACrE,UAAU,CAAC,IAAI,CAAC,IAAI,iBAAC,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC;QAClD,CAAC;QACD,OAAO,UAAU,CAAC;IACtB,CAAC;CACJ;AAhCD,8BAgCC","sourcesContent":["import { MatchRuleConfig, findMatchRuleViolations, Option } from '@webpieces/rules-config';\n\nimport type { EditContext, Violation } from '../types';\nimport { Violation as V } from '../types';\nimport { EditRuleBase } from '../rule-base';\nimport { FixHint, DisableEscape } from '../fix-hint';\n\n/**\n * A single client-authored content guard from the `match-rules` array. Unlike the framework's\n * keyed rules, its regexes and message live entirely in webpieces.config.json — one MatchRule is\n * instantiated per array entry (see loadMatchRules). `name` doubles as the disable token.\n */\nexport class MatchRule extends EditRuleBase<MatchRuleConfig> {\n // A match-rule is its OWN key: it lives in the `match-rules` array, not in `rules`/`hookGuards`,\n // so name and configKey are the same string here and always will be. Passed explicitly all the\n // same — there is no defaulted spelling of this decision anywhere.\n constructor(config: MatchRuleConfig) { super(config, config.name, config.name); }\n\n override readonly files = ['**/*.ts', '**/*.tsx'];\n\n get description(): string {\n return `Content guard \"${this.config.name}\" — flags configured regex patterns that bypass this project's conventions.`;\n }\n\n get fixHint(): FixHint {\n const c = this.config;\n return new FixHint(\n `${c.name}: matched a disallowed pattern.`,\n c.mainMessage,\n (c.options ?? []).map((o: string) => new Option(o)),\n new DisableEscape(c.disableAllowed ?? true, `// webpieces-disable ${c.name} -- <reason>`),\n );\n }\n\n check(ctx: EditContext): readonly Violation[] {\n const c = this.config;\n const disableAllowed = c.disableAllowed ?? true;\n const violations: V[] = [];\n for (const hit of findMatchRuleViolations(ctx.lines, ctx.relativePath, c)) {\n if (disableAllowed && ctx.isLineDisabled(hit.line, c.name)) continue;\n violations.push(new V(hit.line, hit.context));\n }\n return violations;\n }\n}\n"]}
1
+ {"version":3,"file":"match-rule.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/ai-hook-rules/src/core/rules/match-rule.ts"],"names":[],"mappings":";;;AAAA,0DAA2F;AAG3F,0DAAyD;AACzD,0DAAuD;AACvD,0DAAiE;AAEjE;;;;GAIG;AACH,MAAa,SAAU,SAAQ,2BAA6B;IACxD,iGAAiG;IACjG,+FAA+F;IAC/F,mEAAmE;IACnE,YAAY,MAAuB,IAAI,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAE/D,KAAK,GAAG,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;IAElD,IAAI,WAAW;QACX,OAAO,kBAAkB,IAAI,CAAC,MAAM,CAAC,IAAI,6EAA6E,CAAC;IAC3H,CAAC;IAED,IAAI,OAAO;QACP,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC;QACtB,OAAO,IAAI,sBAAO,CACd,GAAG,CAAC,CAAC,IAAI,iCAAiC,EAC1C,CAAC,CAAC,WAAW,EACb,CAAC,CAAC,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,IAAI,qBAAM,CAAC,CAAC,CAAC,CAAC,EACnD,IAAI,4BAAa,CAAC,CAAC,CAAC,cAAc,IAAI,IAAI,EAAE,wBAAwB,CAAC,CAAC,IAAI,cAAc,CAAC,CAC5F,CAAC;IACN,CAAC;IAED,KAAK,CAAC,GAAgB;QAClB,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC;QACtB,MAAM,cAAc,GAAG,CAAC,CAAC,cAAc,IAAI,IAAI,CAAC;QAChD,MAAM,UAAU,GAAQ,EAAE,CAAC;QAC3B,KAAK,MAAM,GAAG,IAAI,IAAA,sCAAuB,EAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,YAAY,EAAE,CAAC,CAAC,EAAE,CAAC;YACxE,IAAI,cAAc,IAAI,GAAG,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC;gBAAE,SAAS;YACrE,UAAU,CAAC,IAAI,CAAC,IAAI,wBAAC,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC;QAClD,CAAC;QACD,OAAO,UAAU,CAAC;IACtB,CAAC;CACJ;AAhCD,8BAgCC","sourcesContent":["import { MatchRuleConfig, findMatchRuleViolations, Option } from '@webpieces/rules-config';\n\nimport type { EditContext, Violation } from '@webpieces/hook-runtime';\nimport { Violation as V } from '@webpieces/hook-runtime';\nimport { EditRuleBase } from '@webpieces/hook-runtime';\nimport { FixHint, DisableEscape } from '@webpieces/hook-runtime';\n\n/**\n * A single client-authored content guard from the `match-rules` array. Unlike the framework's\n * keyed rules, its regexes and message live entirely in webpieces.config.json — one MatchRule is\n * instantiated per array entry (see loadMatchRules). `name` doubles as the disable token.\n */\nexport class MatchRule extends EditRuleBase<MatchRuleConfig> {\n // A match-rule is its OWN key: it lives in the `match-rules` array, not in `rules`/`hookGuards`,\n // so name and configKey are the same string here and always will be. Passed explicitly all the\n // same — there is no defaulted spelling of this decision anywhere.\n constructor(config: MatchRuleConfig) { super(config, config.name, config.name); }\n\n override readonly files = ['**/*.ts', '**/*.tsx'];\n\n get description(): string {\n return `Content guard \"${this.config.name}\" — flags configured regex patterns that bypass this project's conventions.`;\n }\n\n get fixHint(): FixHint {\n const c = this.config;\n return new FixHint(\n `${c.name}: matched a disallowed pattern.`,\n c.mainMessage,\n (c.options ?? []).map((o: string) => new Option(o)),\n new DisableEscape(c.disableAllowed ?? true, `// webpieces-disable ${c.name} -- <reason>`),\n );\n }\n\n check(ctx: EditContext): readonly Violation[] {\n const c = this.config;\n const disableAllowed = c.disableAllowed ?? true;\n const violations: V[] = [];\n for (const hit of findMatchRuleViolations(ctx.lines, ctx.relativePath, c)) {\n if (disableAllowed && ctx.isLineDisabled(hit.line, c.name)) continue;\n violations.push(new V(hit.line, hit.context));\n }\n return violations;\n }\n}\n"]}