@webpieces/ai-hook-rules 0.4.839 → 0.4.841

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (390) hide show
  1. package/README.md +12 -140
  2. package/package.json +7 -15
  3. package/src/adapters/hook-app-fixtures.d.ts +1 -1
  4. package/src/adapters/hook-app-fixtures.js +0 -8
  5. package/src/adapters/hook-app-fixtures.js.map +1 -1
  6. package/src/adapters/hook-core.d.ts +1 -21
  7. package/src/adapters/hook-core.js +22 -341
  8. package/src/adapters/hook-core.js.map +1 -1
  9. package/src/core/load-rules.d.ts +4 -39
  10. package/src/core/load-rules.js +15 -127
  11. package/src/core/load-rules.js.map +1 -1
  12. package/src/core/rules/catch-error-pattern.d.ts +3 -3
  13. package/src/core/rules/catch-error-pattern.js +13 -13
  14. package/src/core/rules/catch-error-pattern.js.map +1 -1
  15. package/src/core/rules/index.d.ts +1 -14
  16. package/src/core/rules/index.js +1 -17
  17. package/src/core/rules/index.js.map +1 -1
  18. package/src/core/rules/match-rule.d.ts +3 -3
  19. package/src/core/rules/match-rule.js +6 -6
  20. package/src/core/rules/match-rule.js.map +1 -1
  21. package/src/core/rules/max-file-lines.d.ts +3 -3
  22. package/src/core/rules/max-file-lines.js +7 -7
  23. package/src/core/rules/max-file-lines.js.map +1 -1
  24. package/src/core/rules/no-any-unknown.d.ts +3 -3
  25. package/src/core/rules/no-any-unknown.js +6 -6
  26. package/src/core/rules/no-any-unknown.js.map +1 -1
  27. package/src/core/rules/no-custom-css.d.ts +3 -3
  28. package/src/core/rules/no-custom-css.js +7 -7
  29. package/src/core/rules/no-custom-css.js.map +1 -1
  30. package/src/core/rules/no-destructure.d.ts +3 -3
  31. package/src/core/rules/no-destructure.js +7 -7
  32. package/src/core/rules/no-destructure.js.map +1 -1
  33. package/src/core/rules/no-implicit-any.d.ts +3 -3
  34. package/src/core/rules/no-implicit-any.js +6 -6
  35. package/src/core/rules/no-implicit-any.js.map +1 -1
  36. package/src/core/rules/no-js-files.d.ts +3 -3
  37. package/src/core/rules/no-js-files.js +6 -6
  38. package/src/core/rules/no-js-files.js.map +1 -1
  39. package/src/core/rules/no-process-exit-outside-main.d.ts +3 -3
  40. package/src/core/rules/no-process-exit-outside-main.js +7 -7
  41. package/src/core/rules/no-process-exit-outside-main.js.map +1 -1
  42. package/src/core/rules/no-symbol-di-tokens.d.ts +3 -3
  43. package/src/core/rules/no-symbol-di-tokens.js +7 -7
  44. package/src/core/rules/no-symbol-di-tokens.js.map +1 -1
  45. package/src/core/rules/no-unmanaged-exceptions.d.ts +3 -3
  46. package/src/core/rules/no-unmanaged-exceptions.js +9 -9
  47. package/src/core/rules/no-unmanaged-exceptions.js.map +1 -1
  48. package/src/core/rules/require-return-type.d.ts +3 -3
  49. package/src/core/rules/require-return-type.js +6 -6
  50. package/src/core/rules/require-return-type.js.map +1 -1
  51. package/src/core/rules/throw-cause-required.d.ts +3 -3
  52. package/src/core/rules/throw-cause-required.js +9 -9
  53. package/src/core/rules/throw-cause-required.js.map +1 -1
  54. package/src/core/rules/validate-ts-in-src.d.ts +3 -3
  55. package/src/core/rules/validate-ts-in-src.js +7 -7
  56. package/src/core/rules/validate-ts-in-src.js.map +1 -1
  57. package/src/core/runner.d.ts +10 -19
  58. package/src/core/runner.js +24 -622
  59. package/src/core/runner.js.map +1 -1
  60. package/src/index.d.ts +2 -15
  61. package/src/index.js +4 -54
  62. package/src/index.js.map +1 -1
  63. package/openclaw.plugin.json +0 -15
  64. package/src/adapters/agent-adapters.d.ts +0 -13
  65. package/src/adapters/agent-adapters.js +0 -23
  66. package/src/adapters/agent-adapters.js.map +0 -1
  67. package/src/adapters/agent-payload.d.ts +0 -48
  68. package/src/adapters/agent-payload.js +0 -30
  69. package/src/adapters/agent-payload.js.map +0 -1
  70. package/src/adapters/agent-response.d.ts +0 -5
  71. package/src/adapters/agent-response.js +0 -86
  72. package/src/adapters/agent-response.js.map +0 -1
  73. package/src/adapters/claude-code-adapter.d.ts +0 -26
  74. package/src/adapters/claude-code-adapter.js +0 -69
  75. package/src/adapters/claude-code-adapter.js.map +0 -1
  76. package/src/adapters/codex-adapter.d.ts +0 -19
  77. package/src/adapters/codex-adapter.js +0 -48
  78. package/src/adapters/codex-adapter.js.map +0 -1
  79. package/src/adapters/codex-subagent-guard.d.ts +0 -45
  80. package/src/adapters/codex-subagent-guard.js +0 -88
  81. package/src/adapters/codex-subagent-guard.js.map +0 -1
  82. package/src/adapters/detect-ai.d.ts +0 -70
  83. package/src/adapters/detect-ai.js +0 -82
  84. package/src/adapters/detect-ai.js.map +0 -1
  85. package/src/adapters/guards-hook.d.ts +0 -3
  86. package/src/adapters/guards-hook.js +0 -30
  87. package/src/adapters/guards-hook.js.map +0 -1
  88. package/src/adapters/openclaw-plugin.d.ts +0 -14
  89. package/src/adapters/openclaw-plugin.js +0 -87
  90. package/src/adapters/openclaw-plugin.js.map +0 -1
  91. package/src/adapters/review-identity-stamper.d.ts +0 -20
  92. package/src/adapters/review-identity-stamper.js +0 -34
  93. package/src/adapters/review-identity-stamper.js.map +0 -1
  94. package/src/bin/codex-trust.d.ts +0 -105
  95. package/src/bin/codex-trust.js +0 -205
  96. package/src/bin/codex-trust.js.map +0 -1
  97. package/src/bin/dev-hook-install.d.ts +0 -1
  98. package/src/bin/dev-hook-install.js +0 -82
  99. package/src/bin/dev-hook-install.js.map +0 -1
  100. package/src/bin/dev-hook-uninstall.d.ts +0 -1
  101. package/src/bin/dev-hook-uninstall.js +0 -45
  102. package/src/bin/dev-hook-uninstall.js.map +0 -1
  103. package/src/bin/hook-registration.d.ts +0 -429
  104. package/src/bin/hook-registration.js +0 -661
  105. package/src/bin/hook-registration.js.map +0 -1
  106. package/src/bin/install-entry.d.ts +0 -19
  107. package/src/bin/install-entry.js +0 -128
  108. package/src/bin/install-entry.js.map +0 -1
  109. package/src/bin/l0-allowlist.d.ts +0 -49
  110. package/src/bin/l0-allowlist.js +0 -528
  111. package/src/bin/l0-allowlist.js.map +0 -1
  112. package/src/bin/l0-codex-read.d.ts +0 -21
  113. package/src/bin/l0-codex-read.js +0 -109
  114. package/src/bin/l0-codex-read.js.map +0 -1
  115. package/src/bin/l0-decide.d.ts +0 -50
  116. package/src/bin/l0-decide.js +0 -103
  117. package/src/bin/l0-decide.js.map +0 -1
  118. package/src/bin/l0-entry.d.ts +0 -103
  119. package/src/bin/l0-entry.js +0 -98
  120. package/src/bin/l0-entry.js.map +0 -1
  121. package/src/bin/l0-ignored-tools.d.ts +0 -38
  122. package/src/bin/l0-ignored-tools.js +0 -44
  123. package/src/bin/l0-ignored-tools.js.map +0 -1
  124. package/src/bin/managed-env.d.ts +0 -46
  125. package/src/bin/managed-env.js +0 -50
  126. package/src/bin/managed-env.js.map +0 -1
  127. package/src/bin/neighbour-hooks.d.ts +0 -42
  128. package/src/bin/neighbour-hooks.js +0 -177
  129. package/src/bin/neighbour-hooks.js.map +0 -1
  130. package/src/bin/reviewer-agent.d.ts +0 -19
  131. package/src/bin/reviewer-agent.js +0 -135
  132. package/src/bin/reviewer-agent.js.map +0 -1
  133. package/src/bin/settings-shape.d.ts +0 -37
  134. package/src/bin/settings-shape.js +0 -17
  135. package/src/bin/settings-shape.js.map +0 -1
  136. package/src/bin/setup-config.d.ts +0 -19
  137. package/src/bin/setup-config.js +0 -370
  138. package/src/bin/setup-config.js.map +0 -1
  139. package/src/bin/setup.d.ts +0 -78
  140. package/src/bin/setup.js +0 -400
  141. package/src/bin/setup.js.map +0 -1
  142. package/src/bin/shim-audit-log.d.ts +0 -119
  143. package/src/bin/shim-audit-log.js +0 -286
  144. package/src/bin/shim-audit-log.js.map +0 -1
  145. package/src/bin/shim-deny-reason.d.ts +0 -1
  146. package/src/bin/shim-deny-reason.js +0 -244
  147. package/src/bin/shim-deny-reason.js.map +0 -1
  148. package/src/bin/shim-drift-fix.d.ts +0 -1
  149. package/src/bin/shim-drift-fix.js +0 -72
  150. package/src/bin/shim-drift-fix.js.map +0 -1
  151. package/src/bin/shim-testkit.d.ts +0 -107
  152. package/src/bin/shim-testkit.js +0 -197
  153. package/src/bin/shim-testkit.js.map +0 -1
  154. package/src/bin/shim-version-drift.d.ts +0 -1
  155. package/src/bin/shim-version-drift.js +0 -164
  156. package/src/bin/shim-version-drift.js.map +0 -1
  157. package/src/bin/shim.d.ts +0 -16
  158. package/src/bin/shim.js +0 -636
  159. package/src/bin/shim.js.map +0 -1
  160. package/src/bin/upgrade-shim.d.ts +0 -18
  161. package/src/bin/upgrade-shim.js +0 -283
  162. package/src/bin/upgrade-shim.js.map +0 -1
  163. package/src/core/ai-type-context.d.ts +0 -36
  164. package/src/core/ai-type-context.js +0 -45
  165. package/src/core/ai-type-context.js.map +0 -1
  166. package/src/core/apply-patch-parse.d.ts +0 -36
  167. package/src/core/apply-patch-parse.js +0 -154
  168. package/src/core/apply-patch-parse.js.map +0 -1
  169. package/src/core/build-context.d.ts +0 -10
  170. package/src/core/build-context.js +0 -66
  171. package/src/core/build-context.js.map +0 -1
  172. package/src/core/command-scan.d.ts +0 -122
  173. package/src/core/command-scan.js +0 -282
  174. package/src/core/command-scan.js.map +0 -1
  175. package/src/core/custom-rule-adapter.d.ts +0 -22
  176. package/src/core/custom-rule-adapter.js +0 -50
  177. package/src/core/custom-rule-adapter.js.map +0 -1
  178. package/src/core/decision-log.d.ts +0 -190
  179. package/src/core/decision-log.js +0 -406
  180. package/src/core/decision-log.js.map +0 -1
  181. package/src/core/delete-scoped-rules.d.ts +0 -8
  182. package/src/core/delete-scoped-rules.js +0 -31
  183. package/src/core/delete-scoped-rules.js.map +0 -1
  184. package/src/core/disable-directives.d.ts +0 -8
  185. package/src/core/disable-directives.js +0 -80
  186. package/src/core/disable-directives.js.map +0 -1
  187. package/src/core/effective-tree.d.ts +0 -204
  188. package/src/core/effective-tree.js +0 -277
  189. package/src/core/effective-tree.js.map +0 -1
  190. package/src/core/excluded-path-escape.d.ts +0 -101
  191. package/src/core/excluded-path-escape.js +0 -236
  192. package/src/core/excluded-path-escape.js.map +0 -1
  193. package/src/core/excluded-paths.d.ts +0 -23
  194. package/src/core/excluded-paths.js +0 -54
  195. package/src/core/excluded-paths.js.map +0 -1
  196. package/src/core/fix-hint.d.ts +0 -40
  197. package/src/core/fix-hint.js +0 -53
  198. package/src/core/fix-hint.js.map +0 -1
  199. package/src/core/force-to-root.d.ts +0 -32
  200. package/src/core/force-to-root.js +0 -60
  201. package/src/core/force-to-root.js.map +0 -1
  202. package/src/core/guard-index-doc.d.ts +0 -63
  203. package/src/core/guard-index-doc.js +0 -172
  204. package/src/core/guard-index-doc.js.map +0 -1
  205. package/src/core/instruct-ai-writer.d.ts +0 -1
  206. package/src/core/instruct-ai-writer.js +0 -6
  207. package/src/core/instruct-ai-writer.js.map +0 -1
  208. package/src/core/l0-fault-codes.d.ts +0 -85
  209. package/src/core/l0-fault-codes.js +0 -121
  210. package/src/core/l0-fault-codes.js.map +0 -1
  211. package/src/core/l0-matrix.d.ts +0 -114
  212. package/src/core/l0-matrix.js +0 -416
  213. package/src/core/l0-matrix.js.map +0 -1
  214. package/src/core/l0-tooling-doc.d.ts +0 -45
  215. package/src/core/l0-tooling-doc.js +0 -258
  216. package/src/core/l0-tooling-doc.js.map +0 -1
  217. package/src/core/l1-doc.d.ts +0 -7
  218. package/src/core/l1-doc.js +0 -340
  219. package/src/core/l1-doc.js.map +0 -1
  220. package/src/core/l1-matrix-doc.d.ts +0 -31
  221. package/src/core/l1-matrix-doc.js +0 -111
  222. package/src/core/l1-matrix-doc.js.map +0 -1
  223. package/src/core/l1-rows.d.ts +0 -167
  224. package/src/core/l1-rows.js +0 -262
  225. package/src/core/l1-rows.js.map +0 -1
  226. package/src/core/l2-doc.d.ts +0 -7
  227. package/src/core/l2-doc.js +0 -385
  228. package/src/core/l2-doc.js.map +0 -1
  229. package/src/core/l2-matrix-doc.d.ts +0 -23
  230. package/src/core/l2-matrix-doc.js +0 -72
  231. package/src/core/l2-matrix-doc.js.map +0 -1
  232. package/src/core/l2-row.d.ts +0 -54
  233. package/src/core/l2-row.js +0 -75
  234. package/src/core/l2-row.js.map +0 -1
  235. package/src/core/l2-rows.d.ts +0 -56
  236. package/src/core/l2-rows.js +0 -272
  237. package/src/core/l2-rows.js.map +0 -1
  238. package/src/core/load-config.d.ts +0 -1
  239. package/src/core/load-config.js +0 -9
  240. package/src/core/load-config.js.map +0 -1
  241. package/src/core/log-stream.d.ts +0 -117
  242. package/src/core/log-stream.js +0 -156
  243. package/src/core/log-stream.js.map +0 -1
  244. package/src/core/log-streams.d.ts +0 -48
  245. package/src/core/log-streams.js +0 -55
  246. package/src/core/log-streams.js.map +0 -1
  247. package/src/core/log-target.d.ts +0 -21
  248. package/src/core/log-target.js +0 -29
  249. package/src/core/log-target.js.map +0 -1
  250. package/src/core/main-sync-log.d.ts +0 -16
  251. package/src/core/main-sync-log.js +0 -105
  252. package/src/core/main-sync-log.js.map +0 -1
  253. package/src/core/main-sync-refresh.d.ts +0 -39
  254. package/src/core/main-sync-refresh.js +0 -96
  255. package/src/core/main-sync-refresh.js.map +0 -1
  256. package/src/core/main-sync-timeout.d.ts +0 -32
  257. package/src/core/main-sync-timeout.js +0 -94
  258. package/src/core/main-sync-timeout.js.map +0 -1
  259. package/src/core/matrix-cures.d.ts +0 -12
  260. package/src/core/matrix-cures.js +0 -56
  261. package/src/core/matrix-cures.js.map +0 -1
  262. package/src/core/missing-directory.d.ts +0 -38
  263. package/src/core/missing-directory.js +0 -66
  264. package/src/core/missing-directory.js.map +0 -1
  265. package/src/core/read-only-inspection.d.ts +0 -34
  266. package/src/core/read-only-inspection.js +0 -88
  267. package/src/core/read-only-inspection.js.map +0 -1
  268. package/src/core/rejection-log.d.ts +0 -9
  269. package/src/core/rejection-log.js +0 -258
  270. package/src/core/rejection-log.js.map +0 -1
  271. package/src/core/report.d.ts +0 -21
  272. package/src/core/report.js +0 -73
  273. package/src/core/report.js.map +0 -1
  274. package/src/core/rule-base.d.ts +0 -39
  275. package/src/core/rule-base.js +0 -36
  276. package/src/core/rule-base.js.map +0 -1
  277. package/src/core/rules/branch-creation-guard.d.ts +0 -113
  278. package/src/core/rules/branch-creation-guard.js +0 -422
  279. package/src/core/rules/branch-creation-guard.js.map +0 -1
  280. package/src/core/rules/branch-switch-scan.d.ts +0 -43
  281. package/src/core/rules/branch-switch-scan.js +0 -132
  282. package/src/core/rules/branch-switch-scan.js.map +0 -1
  283. package/src/core/rules/build-output-pipe-guard.d.ts +0 -56
  284. package/src/core/rules/build-output-pipe-guard.js +0 -120
  285. package/src/core/rules/build-output-pipe-guard.js.map +0 -1
  286. package/src/core/rules/build-output-pipe-scan.d.ts +0 -47
  287. package/src/core/rules/build-output-pipe-scan.js +0 -84
  288. package/src/core/rules/build-output-pipe-scan.js.map +0 -1
  289. package/src/core/rules/cap-remedies.d.ts +0 -39
  290. package/src/core/rules/cap-remedies.js +0 -59
  291. package/src/core/rules/cap-remedies.js.map +0 -1
  292. package/src/core/rules/commit-message-substitution-guard.d.ts +0 -72
  293. package/src/core/rules/commit-message-substitution-guard.js +0 -134
  294. package/src/core/rules/commit-message-substitution-guard.js.map +0 -1
  295. package/src/core/rules/commit-message-substitution-scan.d.ts +0 -42
  296. package/src/core/rules/commit-message-substitution-scan.js +0 -145
  297. package/src/core/rules/commit-message-substitution-scan.js.map +0 -1
  298. package/src/core/rules/content-read-scan.d.ts +0 -76
  299. package/src/core/rules/content-read-scan.js +0 -176
  300. package/src/core/rules/content-read-scan.js.map +0 -1
  301. package/src/core/rules/cure-prefix-scan.d.ts +0 -64
  302. package/src/core/rules/cure-prefix-scan.js +0 -133
  303. package/src/core/rules/cure-prefix-scan.js.map +0 -1
  304. package/src/core/rules/feature-branch-guard.d.ts +0 -121
  305. package/src/core/rules/feature-branch-guard.js +0 -326
  306. package/src/core/rules/feature-branch-guard.js.map +0 -1
  307. package/src/core/rules/judged-tree.d.ts +0 -66
  308. package/src/core/rules/judged-tree.js +0 -97
  309. package/src/core/rules/judged-tree.js.map +0 -1
  310. package/src/core/rules/main-freshness.d.ts +0 -37
  311. package/src/core/rules/main-freshness.js +0 -61
  312. package/src/core/rules/main-freshness.js.map +0 -1
  313. package/src/core/rules/merge-in-progress-guard.d.ts +0 -17
  314. package/src/core/rules/merge-in-progress-guard.js +0 -122
  315. package/src/core/rules/merge-in-progress-guard.js.map +0 -1
  316. package/src/core/rules/merged-branch-bash-guard.d.ts +0 -62
  317. package/src/core/rules/merged-branch-bash-guard.js +0 -170
  318. package/src/core/rules/merged-branch-bash-guard.js.map +0 -1
  319. package/src/core/rules/merged-branch-message.d.ts +0 -59
  320. package/src/core/rules/merged-branch-message.js +0 -137
  321. package/src/core/rules/merged-branch-message.js.map +0 -1
  322. package/src/core/rules/pr-creation-or-push-guard.d.ts +0 -26
  323. package/src/core/rules/pr-creation-or-push-guard.js +0 -146
  324. package/src/core/rules/pr-creation-or-push-guard.js.map +0 -1
  325. package/src/core/rules/pr-merge-guard.d.ts +0 -36
  326. package/src/core/rules/pr-merge-guard.js +0 -86
  327. package/src/core/rules/pr-merge-guard.js.map +0 -1
  328. package/src/core/rules/read-stale-guard.d.ts +0 -136
  329. package/src/core/rules/read-stale-guard.js +0 -326
  330. package/src/core/rules/read-stale-guard.js.map +0 -1
  331. package/src/core/rules/recovery-allowlist.d.ts +0 -49
  332. package/src/core/rules/recovery-allowlist.js +0 -187
  333. package/src/core/rules/recovery-allowlist.js.map +0 -1
  334. package/src/core/rules/redirect-how-to-merge-main.d.ts +0 -16
  335. package/src/core/rules/redirect-how-to-merge-main.js +0 -157
  336. package/src/core/rules/redirect-how-to-merge-main.js.map +0 -1
  337. package/src/core/rules/shell-segment-scan.d.ts +0 -64
  338. package/src/core/rules/shell-segment-scan.js +0 -88
  339. package/src/core/rules/shell-segment-scan.js.map +0 -1
  340. package/src/core/rules/stale-main-bash-guard.d.ts +0 -198
  341. package/src/core/rules/stale-main-bash-guard.js +0 -361
  342. package/src/core/rules/stale-main-bash-guard.js.map +0 -1
  343. package/src/core/rules/stale-main-message.d.ts +0 -62
  344. package/src/core/rules/stale-main-message.js +0 -102
  345. package/src/core/rules/stale-main-message.js.map +0 -1
  346. package/src/core/rules/tree-recovery.d.ts +0 -92
  347. package/src/core/rules/tree-recovery.js +0 -165
  348. package/src/core/rules/tree-recovery.js.map +0 -1
  349. package/src/core/rules/wait-spin-guard.d.ts +0 -128
  350. package/src/core/rules/wait-spin-guard.js +0 -211
  351. package/src/core/rules/wait-spin-guard.js.map +0 -1
  352. package/src/core/rules/wait-spin-scan.d.ts +0 -118
  353. package/src/core/rules/wait-spin-scan.js +0 -203
  354. package/src/core/rules/wait-spin-scan.js.map +0 -1
  355. package/src/core/rules/whole-repo-build-guard.d.ts +0 -125
  356. package/src/core/rules/whole-repo-build-guard.js +0 -257
  357. package/src/core/rules/whole-repo-build-guard.js.map +0 -1
  358. package/src/core/rules/whole-repo-build-scan.d.ts +0 -28
  359. package/src/core/rules/whole-repo-build-scan.js +0 -198
  360. package/src/core/rules/whole-repo-build-scan.js.map +0 -1
  361. package/src/core/session-call-history.d.ts +0 -44
  362. package/src/core/session-call-history.js +0 -79
  363. package/src/core/session-call-history.js.map +0 -1
  364. package/src/core/shell-read-parity.d.ts +0 -56
  365. package/src/core/shell-read-parity.js +0 -155
  366. package/src/core/shell-read-parity.js.map +0 -1
  367. package/src/core/strip-ts-noise.d.ts +0 -1
  368. package/src/core/strip-ts-noise.js +0 -185
  369. package/src/core/strip-ts-noise.js.map +0 -1
  370. package/src/core/sync-main.d.ts +0 -46
  371. package/src/core/sync-main.js +0 -175
  372. package/src/core/sync-main.js.map +0 -1
  373. package/src/core/target-tree.d.ts +0 -84
  374. package/src/core/target-tree.js +0 -148
  375. package/src/core/target-tree.js.map +0 -1
  376. package/src/core/to-error.d.ts +0 -5
  377. package/src/core/to-error.js +0 -37
  378. package/src/core/to-error.js.map +0 -1
  379. package/src/core/types.d.ts +0 -152
  380. package/src/core/types.js +0 -200
  381. package/src/core/types.js.map +0 -1
  382. package/src/core/version-sync.d.ts +0 -219
  383. package/src/core/version-sync.js +0 -558
  384. package/src/core/version-sync.js.map +0 -1
  385. package/src/core/webpieces-versions.d.ts +0 -98
  386. package/src/core/webpieces-versions.js +0 -206
  387. package/src/core/webpieces-versions.js.map +0 -1
  388. package/templates/ai-hook.sh +0 -497
  389. package/templates/claude-settings-hook.json +0 -28
  390. package/templates/webpieces-reviewer.md +0 -60
@@ -1,406 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.invocationLog = exports.InvocationLog = exports.GuardInvocation = exports.GuardDecision = exports.MATRIX_L2_UNROWED = exports.MATRIX_L0_BLOCK = exports.MATRIX_L0_ALLOW = exports.MatrixRef = void 0;
4
- exports.matrixL2Row = matrixL2Row;
5
- exports.logGuardDecision = logGuardDecision;
6
- exports.logL1Decision = logL1Decision;
7
- exports.branchForLog = branchForLog;
8
- const tslib_1 = require("tslib");
9
- const child_process_1 = require("child_process");
10
- const fs = tslib_1.__importStar(require("fs"));
11
- const path = tslib_1.__importStar(require("path"));
12
- const tooling_common_1 = require("@webpieces/tooling-common");
13
- const repo_workflow_core_1 = require("@webpieces/repo-workflow-core");
14
- const rules_config_1 = require("@webpieces/rules-config");
15
- const log_streams_1 = require("./log-streams");
16
- const l0_fault_codes_1 = require("./l0-fault-codes");
17
- const to_error_1 = require("./to-error");
18
- const log_stream_1 = require("./log-stream");
19
- const log_target_1 = require("./log-target");
20
- const ai_type_context_1 = require("./ai-type-context");
21
- const l2_rows_1 = require("./l2-rows");
22
- const matrix_cures_1 = require("./matrix-cures");
23
- // The SYNC decision log — what the synchronous hook DID on each invocation and WHY. Its companion is
24
- // the ASYNC log (the `async-refresh/` stream, written by the detached refresher in main-sync-log.ts). This
25
- // one records EVERY guard decision — allow, block, config-bypass, and the fail-open cases — and CITES
26
- // the async-written cache snapshot (`cache` field) that drove the decision, so a wrong allow/block is
27
- // traceable to a stale or missing async write. Writes to `.webpieces/logs/L2-decisions/<writer>.log` —
28
- // the LAYER is the directory, the WRITER is the file (see log-streams.ts and LogStream).
29
- const MAX_LOG_BYTES = 512 * 1024; // 512 KB — rotate when exceeded (mirrors rotation in rejection-log)
30
- /**
31
- * WHICH ROW of WHICH layer's decision table produced this line. Data-only → a class, per CLAUDE.md.
32
- *
33
- * `row` is the row NUMBER from the layer's row array (`L1_ROWS[i].num`, `L2_ROWS[i].num`) — the
34
- * same number the generated doc prints, because the doc is rendered from that same array. So a log
35
- * line joins to its matrix row BY NUMBER, and checking observed behaviour against the documented use
36
- * cases becomes a lookup rather than an investigation.
37
- */
38
- class MatrixRef {
39
- layer;
40
- row;
41
- constructor(layer, row) {
42
- this.layer = layer;
43
- this.row = row;
44
- }
45
- }
46
- exports.MatrixRef = MatrixRef;
47
- /**
48
- * The layer tokens. EVERY layer now cites a row: L0 through its two decision-matrix rows, L1 through
49
- * L1_ROWS, and L2 through L2_ROWS (see `matrixL2Row`). This used to say `'-'` was for "a layer with no
50
- * row array YET (L2 is the un-converted one)" — L2 is converted, and a comment describing a state the
51
- * code left behind is exactly the kind of doc a reader trusts and should not.
52
- *
53
- * `'-'` survives for ONE case, and it is a real one: an L2 reason that no row claims. See matrixL2Row.
54
- *
55
- * These are REQUIRED at the constructor, not defaulted: a defaulted `MatrixRef` would make the
56
- * uncited case reachable by doing nothing and impossible to grep — the same defect this file's own
57
- * docblock argues against for `'BLOCK'`, where silence was the one wrong answer available.
58
- *
59
- * L0 NOW CITES ITS ROW TOO. It used to be `'-'` on the grounds that "L0's faults are a table of letters
60
- * rather than numbered rows" — but L0 has BOTH: the letter says WHICH fault, and the numbered decision
61
- * matrix (`renderGuardMatrixDoc`) says which of its three rows was taken. There is one ALLOW row and one
62
- * BLOCK row, so the pair `row=` + `fault=` pins the decision exactly, and the deny an agent reads now
63
- * carries the identical pair. That is the join: one grep spans the deny, the log line and the doc.
64
- * Two constants, not one `MATRIX_L0`, because the two call sites are a cure-bypass ALLOW and an L0
65
- * BLOCK — one token covering both is what made the row unciteable in the first place.
66
- */
67
- exports.MATRIX_L0_ALLOW = new MatrixRef('L0', l0_fault_codes_1.L0_ROW_ALLOWLISTED);
68
- exports.MATRIX_L0_BLOCK = new MatrixRef('L0', l0_fault_codes_1.L0_ROW_BLOCKED);
69
- /**
70
- * The L2 reference for one decision, with the row DERIVED FROM THE REASON.
71
- *
72
- * There is no `MATRIX_L2` constant any more, and its absence is the point: a single shared instance
73
- * meant every L2 line in the repo carried `row=-`, which reads as "L2 has no rows" rather than "this
74
- * decision was not classified". Deleting it makes every construction site name a reason, and the reason
75
- * is the only thing a call site has that identifies which row it is an instance of.
76
- *
77
- * `l2RowForReason` returns null for a reason no row claims, and that renders as `'-'` — visible in the
78
- * log, not silently absorbed into a default row. l2-matrix.spec.ts reads the four guard sources and
79
- * fails the build if any reason literal in them is unmapped, so `-` should never appear in practice;
80
- * when it does, it is a genuine hole in the table and the log says so.
81
- */
82
- // webpieces-disable no-function-outside-class -- a named constructor for MatrixRef beside it, in this module of module-scope writers
83
- function matrixL2Row(reason) {
84
- const row = (0, l2_rows_1.l2RowForReason)(reason);
85
- return new MatrixRef('L2', row === null ? '-' : String(row));
86
- }
87
- /**
88
- * The L2 stream, with NO row — for the two kinds of line that genuinely are not an instance of a row.
89
- *
90
- * 1. The runner's AGGREGATE bash lines ("no bash-guard block" / "bash-guard block"). They summarise
91
- * the whole guard set's answer for one command, not one row's verdict; the per-guard lines that
92
- * DO cite rows are written alongside them by the guards themselves.
93
- * 2. `whole-repo-build-guard`, which is not a branch-state policy at all — it is the experimental
94
- * home-config guard, has no webpieces.config.json entry, and shares this stream only because the
95
- * stream is "bash decisions", not "L2 rows".
96
- *
97
- * A NAMED constant rather than an inline `new MatrixRef('L2', '-')`, so `grep MATRIX_L2_UNROWED` lists
98
- * every uncited line and the list stays short and arguable. It is deliberately NOT called `MATRIX_L2`:
99
- * the old name was used by everything and made "L2 has no rows" indistinguishable from "this line is
100
- * not a row".
101
- */
102
- exports.MATRIX_L2_UNROWED = new MatrixRef('L2', '-');
103
- // Data-only record of one guard decision (per CLAUDE.md: classes for data, not object literals).
104
- // `cache` summarizes the async-written main-sync-status.json that drove a feature-branch-guard
105
- // decision (branch/merged/conflict/fork + the cache timestamp), or '-' when no cache was consulted
106
- // (bash guards, on-main, config-bypass).
107
- class GuardDecision {
108
- rule;
109
- tool;
110
- target; // file path (file guards) or the bash command (bash guards)
111
- branch;
112
- verdict;
113
- reason;
114
- cache;
115
- /**
116
- * The L0 fault this decision IS, in the codebook's letter (core/l0-fault-codes.ts), or `-` for an
117
- * ordinary rule decision. The `sh` shim has always stamped `fault=` on its own stream; the three
118
- * JS-side faults (S/C/Y) reached this one with no label at all, so `grep fault=S` found nothing
119
- * even while an S storm was blocking every call.
120
- */
121
- fault;
122
- /** Which layer + row decided this. See MatrixRef — it is what joins a log line to the doc. */
123
- matrix;
124
- // eslint-disable-next-line @typescript-eslint/max-params
125
- constructor(rule, tool, target, branch, verdict, reason, cache = '-', fault, matrix) {
126
- this.rule = rule;
127
- this.tool = tool;
128
- this.target = target;
129
- this.branch = branch;
130
- this.verdict = verdict;
131
- this.reason = reason;
132
- this.cache = cache;
133
- this.fault = fault;
134
- this.matrix = matrix;
135
- }
136
- }
137
- exports.GuardDecision = GuardDecision;
138
- /**
139
- * Append one tab-separated line per L2 decision to `.webpieces/logs/L2-decisions/<writer>.log`, where
140
- * <writer> is LogStream's `<sessionId>-<agentId|coordinator>-<hook>` key (a caller that never
141
- * identified renders as `unknown-coordinator-hook` — there is no un-keyed name).
142
- * `root` is
143
- * the repo/workspace root that holds `.webpieces` (callers pass workspaceRoot, or a
144
- * RepoRootFinder-resolved root at the pre-load config-bypass site — never a raw cwd, so a bypass
145
- * logged from a subdir never scatters a stray `.webpieces`). Swallows all errors — logging must never
146
- * block or fail a hook.
147
- */
148
- // webpieces-disable no-function-outside-class -- the module-scope writer this log has always been, beside branchForLog/oneLine/rotateLogFile; it must stay callable from a tree too broken to build a DI container
149
- function logGuardDecision(root, decision) {
150
- appendDecision(root, log_streams_1.L2_DECISIONS_STREAM, decision);
151
- }
152
- /**
153
- * The L1 stream — `.webpieces/logs/L1-location/<writer>.log`.
154
- *
155
- * L1 had NO stream. Its three blocking paths wrote into L2's file under an implementation name
156
- * (`force-to-root`, `trinary-version-skew`, `cd-must-be-first`), and its NON-blocking outcomes —
157
- * the exempt row and the three hand-down rows — wrote nothing at all. So "L1 had no objection" was
158
- * unobservable, and "show me every L1 decision" had no answer: L1 existed in the trail only as the
159
- * `root=` / `projectDir=` / `tree=` columns stapled onto somebody else's line.
160
- *
161
- * A SIBLING rather than a `base` parameter on logGuardDecision, deliberately: that signature is what
162
- * the process-wide `logStream` singleton exists to keep unchanged (see LogStream's docblock), and
163
- * `INVOCATION_LOG_FILE` already establishes the pattern of a second stream owning its own name in
164
- * this same module.
165
- */
166
- // webpieces-disable no-function-outside-class -- sibling of logGuardDecision, same module-scope writer shape and same reason
167
- function logL1Decision(root, decision) {
168
- appendDecision(root, log_streams_1.L1_LOCATION_STREAM, decision);
169
- }
170
- // The one appender both streams share. `streamDir` is the LAYER; the writer key inside it is
171
- // logStream's session/agent/hook, which is what keeps one writer per file.
172
- // webpieces-disable no-function-outside-class -- the shared body of the two module-scope writers above
173
- function appendDecision(root, streamDir, decision) {
174
- // eslint-disable-next-line @webpieces/no-unmanaged-exceptions
175
- try {
176
- const timestamp = new Date().toISOString();
177
- // LOCAL scope: a guard decision belongs to the tree it judged. WHO made the call is answered
178
- // by the filename, which logStream names with session/agent/hook.
179
- const logsDir = tooling_common_1.dotWebpieces.logsFile(root, streamDir);
180
- fs.mkdirSync(logsDir, { recursive: true });
181
- const logPath = path.join(logsDir, log_stream_1.logStream.writerFile('.log'));
182
- rotateLogFile(logPath, path.join(logsDir, log_stream_1.logStream.writerFile('.1.log')));
183
- const line = [
184
- `[${timestamp}]`,
185
- decision.verdict,
186
- decision.tool,
187
- oneLine(decision.target),
188
- decision.branch,
189
- decision.rule,
190
- oneLine(decision.reason),
191
- oneLine(decision.cache),
192
- // WHICH ROW of WHICH table decided this. The directory already carries the layer, but a
193
- // line quoted out of its file must still say what judged it — and `row=` is the join key
194
- // to the generated doc, which is the point of the whole exercise.
195
- `layer=${decision.matrix.layer}`,
196
- `row=${decision.matrix.row}`,
197
- // The tree this decision was actually made against, and what Claude Code told the hook the
198
- // project was. Appended (never reordered) for the same reason as on the invocation line —
199
- // see ClaudeEnv: when these two disagree, that disagreement is the bug.
200
- `root=${root}`,
201
- `projectDir=${rules_config_1.claudeEnv.projectDirForLog()}`,
202
- // git's name for that tree — `primary`, else the worktree name. Same literal and same
203
- // derivation as the L0 shim log's `tree=` (shim-audit-log.ts), so one grep spans both
204
- // streams: L0 carries tree without projectDir, L1 now carries both.
205
- `tree=${tooling_common_1.dotWebpieces.worktreeName(root) || 'primary'}`,
206
- // APPEND-ONLY, same spelling as the invocation line and the L0 shim log: which L0 fault
207
- // this was, or `-`.
208
- `fault=${decision.fault}`,
209
- // WHAT THE AGENT WAS TOLD TO DO — looked up from the row above, never passed in, so it is
210
- // by construction the same literal the generated matrix prints for that row (see
211
- // matrix-cures.ts). `row=` says which row judged the call; this says what that row
212
- // prescribed, which is what makes the trail auditable against the doc without opening it.
213
- // APPEND-ONLY, like every field before it.
214
- `cure=${oneLine((0, matrix_cures_1.cureForMatrix)(decision.matrix.layer, decision.matrix.row))}`,
215
- // WHICH HARNESS made the call, spelled exactly as the L0 sh shim spells it on its own
216
- // stream — so ONE grep (`ai=codex`) spans all five streams and "is Codex actually being
217
- // guarded?" is a question the trail can answer. APPEND-ONLY, like every field before it; a
218
- // row from a release that predates this carries no `ai=` and reads as `unknown`.
219
- `ai=${ai_type_context_1.aiTypeContext.forLog()}`,
220
- ].join('\t') + '\n';
221
- fs.appendFileSync(logPath, line);
222
- }
223
- catch (err) {
224
- const error = (0, to_error_1.toError)(err);
225
- void error;
226
- }
227
- }
228
- /**
229
- * What the guard SAW on one invocation, captured up front and held until the outcome is known.
230
- * Data-only (per CLAUDE.md: classes for data, explicit construction).
231
- */
232
- class GuardInvocation {
233
- root;
234
- timestamp;
235
- tool;
236
- target;
237
- branch;
238
- sync;
239
- projectDir;
240
- // eslint-disable-next-line @typescript-eslint/max-params
241
- constructor(root, timestamp, tool, target, branch, sync, projectDir) {
242
- this.root = root;
243
- this.timestamp = timestamp;
244
- this.tool = tool;
245
- this.target = target;
246
- this.branch = branch;
247
- this.sync = sync;
248
- this.projectDir = projectDir;
249
- }
250
- }
251
- exports.GuardInvocation = GuardInvocation;
252
- /**
253
- * The per-INVOCATION stream — `.webpieces/logs/calls/<writer>.log` (see LogStream for the writer
254
- * key), one line for EVERY guards-hook
255
- * call (allow or block, bash or file), unlike `L2-decisions/` which records only the calls a
256
- * rule actually judged. It captures the tool, the command/file, the live git branch, the async-written
257
- * main-sync-status.json snapshot (branch / merged / fork-point / conflict), and — since this class
258
- * replaced a bare log-and-forget function — HOW THE CALL ENDED.
259
- *
260
- * WHY IT IS TWO CALLS. The line used to be written the moment the hook started, so it could not carry
261
- * a verdict: the decision had not been made yet. Answering "what happened to this call?" therefore
262
- * meant joining this file against the L2 decision stream BY TIMESTAMP, which is exactly the kind of
263
- * reconstruction a log exists to make unnecessary. So {@link begin} now only CAPTURES (including the
264
- * git/cache reads, which must still happen while the hook is running), and {@link finish} — called
265
- * from the hook's single terminal boundary, emitAllow/emitDeny — writes the whole line once the
266
- * outcome is known. The two streams stay distinct in purpose: this one is "every call and how it
267
- * ended", the decision log remains "every judgement and why".
268
- *
269
- * Every error is swallowed: logging must never block or fail a hook.
270
- */
271
- class InvocationLog {
272
- pending = null;
273
- /**
274
- * Capture the context of one invocation. `cwd` is the AI's working dir; the repo root that owns
275
- * `.webpieces` is resolved from it. Writes NOTHING — {@link finish} does that.
276
- */
277
- begin(cwd, tool, target) {
278
- // eslint-disable-next-line @webpieces/no-unmanaged-exceptions
279
- try {
280
- const root = new rules_config_1.RepoRootFinder().resolveRepoRoot(cwd);
281
- const branch = branchForLog(root);
282
- // The cache is branch-keyed, so the entry to log is the one for the branch we are standing
283
- // on. 'unknown' (branchForLog's failure value) simply misses and logs 'sync=none'.
284
- const sync = summarizeSyncStatus((0, repo_workflow_core_1.readMainSyncStatus)(root, branch));
285
- this.pending = new GuardInvocation(root, new Date().toISOString(), tool, oneLine(target), branch, sync, rules_config_1.claudeEnv.projectDirForLog());
286
- }
287
- catch (err) {
288
- const error = (0, to_error_1.toError)(err);
289
- void error;
290
- }
291
- }
292
- /**
293
- * Write the captured line, now stamped with the outcome. A no-op when nothing was captured (the
294
- * 'rules' hook, or a terminal boundary reached before begin()), and it clears the pending entry so
295
- * a second emit cannot double-log.
296
- *
297
- * `rule` is the rule that blocked, or '-' when there is none; `fault` is the L0 fault code when this
298
- * call ended on one (S/C/Y — the JS-side faults), else '-'. FIELD ORDER IS APPEND-ONLY: the five
299
- * original fields keep their positions (cleanup automation mines this file), and `guards=` /
300
- * `rule=` / … / `fault=` are added at the end.
301
- */
302
- finish(verdict, rule, fault = l0_fault_codes_1.L0_FAULT_NONE) {
303
- const invocation = this.pending;
304
- this.pending = null;
305
- if (invocation === null)
306
- return;
307
- // eslint-disable-next-line @webpieces/no-unmanaged-exceptions
308
- try {
309
- const logsDir = tooling_common_1.dotWebpieces.logsFile(invocation.root, log_streams_1.CALLS_STREAM);
310
- fs.mkdirSync(logsDir, { recursive: true });
311
- const logPath = path.join(logsDir, log_stream_1.logStream.writerFile('.log'));
312
- rotateLogFile(logPath, path.join(logsDir, log_stream_1.logStream.writerFile('.1.log')));
313
- const line = [
314
- `[${invocation.timestamp}]`,
315
- invocation.tool,
316
- invocation.target,
317
- `branch=${invocation.branch}`,
318
- invocation.sync,
319
- // `guards=`, NOT `verdict=`. This hook can only report on ITSELF. Claude Code runs all
320
- // its PreToolUse hooks IN PARALLEL, so another hook process may deny a call this one
321
- // had no objection to, and neither can see the other's answer. Measured under the
322
- // RETIRED three-hook form: `cd <repo>/packages && ls` was DENIED by L-1 and recorded
323
- // here three times as `verdict=ALLOW`. The old field name promised an outcome it
324
- // structurally cannot know, so the name stayed even though L-1 is gone: the two
325
- // surviving hooks still run in parallel and still cannot see each other.
326
- `guards=${verdict}`,
327
- `rule=${oneLine(rule) || '-'}`,
328
- // The tree the guard ACTED in, next to what Claude Code said the project was. Both, on
329
- // every line, because the diagnostic value is entirely in comparing them — see
330
- // ClaudeEnv for the open question this field exists to settle empirically.
331
- `root=${invocation.root}`,
332
- `projectDir=${invocation.projectDir}`,
333
- // See logGuardDecision: the short tree label, so `tree=primary` with a matching
334
- // projectDir reads as healthy at a glance and `tree=<worktree>` beside a projectDir
335
- // pointing at the primary is the straddle, without diffing two absolute paths.
336
- `tree=${tooling_common_1.dotWebpieces.worktreeName(invocation.root) || 'primary'}`,
337
- // WHICH L0 fault ended this call, in the same letters and the same field name the L0 sh
338
- // shim uses (the `L0-shim/` stream) — so ONE grep spans the whole trail.
339
- `fault=${fault}`,
340
- // WHICH HARNESS made the call — same field name and same vocabulary as the L0 sh shim's
341
- // `ai=` and the decision stream's, so one grep spans the whole trail. APPEND-ONLY.
342
- `ai=${ai_type_context_1.aiTypeContext.forLog()}`,
343
- ].join('\t') + '\n';
344
- fs.appendFileSync(logPath, line);
345
- }
346
- catch (err) {
347
- const error = (0, to_error_1.toError)(err);
348
- void error;
349
- }
350
- }
351
- }
352
- exports.InvocationLog = InvocationLog;
353
- // Process-wide instance: one hook process handles exactly one tool call, so a single pending entry is
354
- // the whole state there is. Module-scope (rather than DI) because the terminal boundary that flushes
355
- // it — emitAllow/emitDeny — is itself module-scope protocol code with no container in reach.
356
- exports.invocationLog = new InvocationLog();
357
- // One-field summary of main-sync-status.json for the invocation log: the branch the cache is FOR,
358
- // whether it is already merged (and its PR), fork-point presence, and conflict state — the signals a
359
- // cleanup step keys off. 'sync=none' when the cache has not been written yet (first call of a session).
360
- function summarizeSyncStatus(status) {
361
- if (status === null)
362
- return 'sync=none';
363
- const merged = status.branchAlreadyMerged ? `PR#${status.mergedPr !== '' ? status.mergedPr : '?'}` : 'no';
364
- return `sync=${status.branch} merged=${merged} fork=${String(status.hasForkPoint)} conflict=${String(status.conflict)} ts=${status.timestamp}`;
365
- }
366
- // Best-effort current branch for the log line. Returns 'unknown' on any failure (e.g. not a git
367
- // repo) — this is for display only, never for a control decision.
368
- function branchForLog(root) {
369
- // eslint-disable-next-line @webpieces/no-unmanaged-exceptions
370
- try {
371
- return (0, child_process_1.execSync)('git rev-parse --abbrev-ref HEAD', {
372
- cwd: root,
373
- encoding: 'utf8',
374
- stdio: ['pipe', 'pipe', 'pipe'],
375
- }).trim() || 'unknown';
376
- }
377
- catch (err) {
378
- const error = (0, to_error_1.toError)(err);
379
- void error;
380
- return 'unknown';
381
- }
382
- }
383
- // Collapse newlines/tabs and cap length so one decision is always one log line. The collapse itself
384
- // lives in LogTarget, because SessionCallHistory READS this format back and the two must agree byte
385
- // for byte — a second private copy of the cap is a silent way for a long command to stop matching
386
- // itself.
387
- // webpieces-disable no-function-outside-class -- the module's own leaf helper, beside branchForLog/rotateLogFile
388
- function oneLine(value) {
389
- return log_target_1.logTarget.oneLine(value);
390
- }
391
- function rotateLogFile(logPath, prevPath) {
392
- // eslint-disable-next-line @webpieces/no-unmanaged-exceptions
393
- try {
394
- const stat = fs.statSync(logPath);
395
- if (stat.size > MAX_LOG_BYTES) {
396
- if (fs.existsSync(prevPath))
397
- fs.unlinkSync(prevPath);
398
- fs.renameSync(logPath, prevPath);
399
- }
400
- }
401
- catch (err) {
402
- const error = (0, to_error_1.toError)(err);
403
- void error;
404
- }
405
- }
406
- //# sourceMappingURL=decision-log.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"decision-log.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/core/decision-log.ts"],"names":[],"mappings":";;;AAqGA,kCAGC;AAkED,4CAEC;AAiBD,sCAEC;AAoMD,oCAaC;;AAhZD,iDAAyC;AACzC,+CAAyB;AACzB,mDAA6B;AAE7B,8DAAyD;AACzD,sEAAmF;AACnF,0DAAoE;AACpE,+CAAsF;AAEtF,qDAAqF;AACrF,yCAAqC;AACrC,6CAAyC;AACzC,6CA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CAAC,CAAC;QAC3B,KAAK,KAAK,CAAC;IACf,CAAC;AACL,CAAC","sourcesContent":["import { execSync } from 'child_process';\nimport * as fs from 'fs';\nimport * as path from 'path';\n\nimport { dotWebpieces } from '@webpieces/tooling-common';\nimport { readMainSyncStatus, MainSyncStatus } from '@webpieces/repo-workflow-core';\nimport { RepoRootFinder, claudeEnv } from '@webpieces/rules-config';\nimport { L1_LOCATION_STREAM, L2_DECISIONS_STREAM, CALLS_STREAM } from './log-streams';\n\nimport { L0_FAULT_NONE, L0_ROW_ALLOWLISTED, L0_ROW_BLOCKED } from './l0-fault-codes';\nimport { toError } from './to-error';\nimport { logStream } from './log-stream';\nimport { logTarget } from './log-target';\nimport { aiTypeContext } from './ai-type-context';\nimport { l2RowForReason } from './l2-rows';\nimport { cureForMatrix } from './matrix-cures';\n\n// The SYNC decision log — what the synchronous hook DID on each invocation and WHY. Its companion is\n// the ASYNC log (the `async-refresh/` stream, written by the detached refresher in main-sync-log.ts). This\n// one records EVERY guard decision — allow, block, config-bypass, and the fail-open cases — and CITES\n// the async-written cache snapshot (`cache` field) that drove the decision, so a wrong allow/block is\n// traceable to a stale or missing async write. Writes to `.webpieces/logs/L2-decisions/<writer>.log` —\n// the LAYER is the directory, the WRITER is the file (see log-streams.ts and LogStream).\nconst MAX_LOG_BYTES = 512 * 1024; // 512 KB — rotate when exceeded (mirrors rotation in rejection-log)\n\n/**\n * THE ACTION CODEBOOK, as a type. These are the five actions GUARD_MATRIX.md numbers 1-5, and they\n * are the vocabulary EVERY layer reports in — so one grep spans L-1, L0, L1 and L2.\n *\n * The three distinctions this exists to make, none of which `'ALLOW' | 'BLOCK'` could:\n *\n * ALLOW no objection — the call was HANDED DOWN to the next layer. A layer saying ALLOW\n * is NOT saying the call ran: the layer below it, or the OTHER parallel hook, may\n * still deny. This is L1's `ACT_DOWN`.\n * ALLOW_EXEMPT out of scope by construction — allowed, and evaluation STOPS here. L1's\n * `ACT_EXEMPT`.\n * ALLOW_FAIL_OPEN state could not be established, so nothing was judged. Keeping this distinct\n * from ALLOW is the entire point of the type: a fail-open allow and a real allow\n * that look identical make it impossible to tell whether the guards are protecting\n * anything or quietly abstaining. It used to be a `' (fail-open)'` SUBSTRING on the\n * reason field, which is exactly why the abstentions were never countable.\n * BLOCK_AI_CURE blocked, and the printed cure is a command the AI can run itself.\n * BLOCK_HUMAN blocked, and it needs a human decision — or a delegation (spawn a subagent) that\n * the blocked agent cannot perform for itself.\n *\n * Hard cut, per `.claude/rules/no-backwards-compat.md`: `'BLOCK'` is GONE rather than aliased, so every\n * construction site fails to\n * compile and has to say which kind of block it is. Before, that question had exactly one wrong\n * answer available — silence.\n */\nexport type Verdict = 'ALLOW' | 'ALLOW_EXEMPT' | 'ALLOW_FAIL_OPEN' | 'BLOCK_AI_CURE' | 'BLOCK_HUMAN';\n\n/**\n * WHICH ROW of WHICH layer's decision table produced this line. Data-only → a class, per CLAUDE.md.\n *\n * `row` is the row NUMBER from the layer's row array (`L1_ROWS[i].num`, `L2_ROWS[i].num`) — the\n * same number the generated doc prints, because the doc is rendered from that same array. So a log\n * line joins to its matrix row BY NUMBER, and checking observed behaviour against the documented use\n * cases becomes a lookup rather than an investigation.\n */\nexport class MatrixRef {\n constructor(readonly layer: string, readonly row: string) {}\n}\n\n/**\n * The layer tokens. EVERY layer now cites a row: L0 through its two decision-matrix rows, L1 through\n * L1_ROWS, and L2 through L2_ROWS (see `matrixL2Row`). This used to say `'-'` was for \"a layer with no\n * row array YET (L2 is the un-converted one)\" — L2 is converted, and a comment describing a state the\n * code left behind is exactly the kind of doc a reader trusts and should not.\n *\n * `'-'` survives for ONE case, and it is a real one: an L2 reason that no row claims. See matrixL2Row.\n *\n * These are REQUIRED at the constructor, not defaulted: a defaulted `MatrixRef` would make the\n * uncited case reachable by doing nothing and impossible to grep — the same defect this file's own\n * docblock argues against for `'BLOCK'`, where silence was the one wrong answer available.\n *\n * L0 NOW CITES ITS ROW TOO. It used to be `'-'` on the grounds that \"L0's faults are a table of letters\n * rather than numbered rows\" — but L0 has BOTH: the letter says WHICH fault, and the numbered decision\n * matrix (`renderGuardMatrixDoc`) says which of its three rows was taken. There is one ALLOW row and one\n * BLOCK row, so the pair `row=` + `fault=` pins the decision exactly, and the deny an agent reads now\n * carries the identical pair. That is the join: one grep spans the deny, the log line and the doc.\n * Two constants, not one `MATRIX_L0`, because the two call sites are a cure-bypass ALLOW and an L0\n * BLOCK — one token covering both is what made the row unciteable in the first place.\n */\nexport const MATRIX_L0_ALLOW = new MatrixRef('L0', L0_ROW_ALLOWLISTED);\nexport const MATRIX_L0_BLOCK = new MatrixRef('L0', L0_ROW_BLOCKED);\n\n/**\n * The L2 reference for one decision, with the row DERIVED FROM THE REASON.\n *\n * There is no `MATRIX_L2` constant any more, and its absence is the point: a single shared instance\n * meant every L2 line in the repo carried `row=-`, which reads as \"L2 has no rows\" rather than \"this\n * decision was not classified\". Deleting it makes every construction site name a reason, and the reason\n * is the only thing a call site has that identifies which row it is an instance of.\n *\n * `l2RowForReason` returns null for a reason no row claims, and that renders as `'-'` — visible in the\n * log, not silently absorbed into a default row. l2-matrix.spec.ts reads the four guard sources and\n * fails the build if any reason literal in them is unmapped, so `-` should never appear in practice;\n * when it does, it is a genuine hole in the table and the log says so.\n */\n// webpieces-disable no-function-outside-class -- a named constructor for MatrixRef beside it, in this module of module-scope writers\nexport function matrixL2Row(reason: string): MatrixRef {\n const row = l2RowForReason(reason);\n return new MatrixRef('L2', row === null ? '-' : String(row));\n}\n\n/**\n * The L2 stream, with NO row — for the two kinds of line that genuinely are not an instance of a row.\n *\n * 1. The runner's AGGREGATE bash lines (\"no bash-guard block\" / \"bash-guard block\"). They summarise\n * the whole guard set's answer for one command, not one row's verdict; the per-guard lines that\n * DO cite rows are written alongside them by the guards themselves.\n * 2. `whole-repo-build-guard`, which is not a branch-state policy at all — it is the experimental\n * home-config guard, has no webpieces.config.json entry, and shares this stream only because the\n * stream is \"bash decisions\", not \"L2 rows\".\n *\n * A NAMED constant rather than an inline `new MatrixRef('L2', '-')`, so `grep MATRIX_L2_UNROWED` lists\n * every uncited line and the list stays short and arguable. It is deliberately NOT called `MATRIX_L2`:\n * the old name was used by everything and made \"L2 has no rows\" indistinguishable from \"this line is\n * not a row\".\n */\nexport const MATRIX_L2_UNROWED = new MatrixRef('L2', '-');\n\n// Data-only record of one guard decision (per CLAUDE.md: classes for data, not object literals).\n// `cache` summarizes the async-written main-sync-status.json that drove a feature-branch-guard\n// decision (branch/merged/conflict/fork + the cache timestamp), or '-' when no cache was consulted\n// (bash guards, on-main, config-bypass).\nexport class GuardDecision {\n rule: string;\n tool: string;\n target: string; // file path (file guards) or the bash command (bash guards)\n branch: string;\n verdict: Verdict;\n reason: string;\n cache: string;\n /**\n * The L0 fault this decision IS, in the codebook's letter (core/l0-fault-codes.ts), or `-` for an\n * ordinary rule decision. The `sh` shim has always stamped `fault=` on its own stream; the three\n * JS-side faults (S/C/Y) reached this one with no label at all, so `grep fault=S` found nothing\n * even while an S storm was blocking every call.\n */\n fault: string;\n /** Which layer + row decided this. See MatrixRef — it is what joins a log line to the doc. */\n matrix: MatrixRef;\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(rule: string, tool: string, target: string, branch: string, verdict: Verdict, reason: string, cache: string = '-', fault: string, matrix: MatrixRef) {\n this.rule = rule;\n this.tool = tool;\n this.target = target;\n this.branch = branch;\n this.verdict = verdict;\n this.reason = reason;\n this.cache = cache;\n this.fault = fault;\n this.matrix = matrix;\n }\n}\n\n/**\n * Append one tab-separated line per L2 decision to `.webpieces/logs/L2-decisions/<writer>.log`, where\n * <writer> is LogStream's `<sessionId>-<agentId|coordinator>-<hook>` key (a caller that never\n * identified renders as `unknown-coordinator-hook` — there is no un-keyed name).\n * `root` is\n * the repo/workspace root that holds `.webpieces` (callers pass workspaceRoot, or a\n * RepoRootFinder-resolved root at the pre-load config-bypass site — never a raw cwd, so a bypass\n * logged from a subdir never scatters a stray `.webpieces`). Swallows all errors — logging must never\n * block or fail a hook.\n */\n// webpieces-disable no-function-outside-class -- the module-scope writer this log has always been, beside branchForLog/oneLine/rotateLogFile; it must stay callable from a tree too broken to build a DI container\nexport function logGuardDecision(root: string, decision: GuardDecision): void {\n appendDecision(root, L2_DECISIONS_STREAM, decision);\n}\n\n/**\n * The L1 stream — `.webpieces/logs/L1-location/<writer>.log`.\n *\n * L1 had NO stream. Its three blocking paths wrote into L2's file under an implementation name\n * (`force-to-root`, `trinary-version-skew`, `cd-must-be-first`), and its NON-blocking outcomes —\n * the exempt row and the three hand-down rows — wrote nothing at all. So \"L1 had no objection\" was\n * unobservable, and \"show me every L1 decision\" had no answer: L1 existed in the trail only as the\n * `root=` / `projectDir=` / `tree=` columns stapled onto somebody else's line.\n *\n * A SIBLING rather than a `base` parameter on logGuardDecision, deliberately: that signature is what\n * the process-wide `logStream` singleton exists to keep unchanged (see LogStream's docblock), and\n * `INVOCATION_LOG_FILE` already establishes the pattern of a second stream owning its own name in\n * this same module.\n */\n// webpieces-disable no-function-outside-class -- sibling of logGuardDecision, same module-scope writer shape and same reason\nexport function logL1Decision(root: string, decision: GuardDecision): void {\n appendDecision(root, L1_LOCATION_STREAM, decision);\n}\n\n// The one appender both streams share. `streamDir` is the LAYER; the writer key inside it is\n// logStream's session/agent/hook, which is what keeps one writer per file.\n// webpieces-disable no-function-outside-class -- the shared body of the two module-scope writers above\nfunction appendDecision(root: string, streamDir: string, decision: GuardDecision): void {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n const timestamp = new Date().toISOString();\n // LOCAL scope: a guard decision belongs to the tree it judged. WHO made the call is answered\n // by the filename, which logStream names with session/agent/hook.\n const logsDir = dotWebpieces.logsFile(root, streamDir);\n fs.mkdirSync(logsDir, { recursive: true });\n\n const logPath = path.join(logsDir, logStream.writerFile('.log'));\n rotateLogFile(logPath, path.join(logsDir, logStream.writerFile('.1.log')));\n\n const line = [\n `[${timestamp}]`,\n decision.verdict,\n decision.tool,\n oneLine(decision.target),\n decision.branch,\n decision.rule,\n oneLine(decision.reason),\n oneLine(decision.cache),\n // WHICH ROW of WHICH table decided this. The directory already carries the layer, but a\n // line quoted out of its file must still say what judged it — and `row=` is the join key\n // to the generated doc, which is the point of the whole exercise.\n `layer=${decision.matrix.layer}`,\n `row=${decision.matrix.row}`,\n // The tree this decision was actually made against, and what Claude Code told the hook the\n // project was. Appended (never reordered) for the same reason as on the invocation line —\n // see ClaudeEnv: when these two disagree, that disagreement is the bug.\n `root=${root}`,\n `projectDir=${claudeEnv.projectDirForLog()}`,\n // git's name for that tree — `primary`, else the worktree name. Same literal and same\n // derivation as the L0 shim log's `tree=` (shim-audit-log.ts), so one grep spans both\n // streams: L0 carries tree without projectDir, L1 now carries both.\n `tree=${dotWebpieces.worktreeName(root) || 'primary'}`,\n // APPEND-ONLY, same spelling as the invocation line and the L0 shim log: which L0 fault\n // this was, or `-`.\n `fault=${decision.fault}`,\n // WHAT THE AGENT WAS TOLD TO DO — looked up from the row above, never passed in, so it is\n // by construction the same literal the generated matrix prints for that row (see\n // matrix-cures.ts). `row=` says which row judged the call; this says what that row\n // prescribed, which is what makes the trail auditable against the doc without opening it.\n // APPEND-ONLY, like every field before it.\n `cure=${oneLine(cureForMatrix(decision.matrix.layer, decision.matrix.row))}`,\n // WHICH HARNESS made the call, spelled exactly as the L0 sh shim spells it on its own\n // stream — so ONE grep (`ai=codex`) spans all five streams and \"is Codex actually being\n // guarded?\" is a question the trail can answer. APPEND-ONLY, like every field before it; a\n // row from a release that predates this carries no `ai=` and reads as `unknown`.\n `ai=${aiTypeContext.forLog()}`,\n ].join('\\t') + '\\n';\n fs.appendFileSync(logPath, line);\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n }\n}\n\n/**\n * What the guard SAW on one invocation, captured up front and held until the outcome is known.\n * Data-only (per CLAUDE.md: classes for data, explicit construction).\n */\nexport class GuardInvocation {\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(\n public readonly root: string,\n public readonly timestamp: string,\n public readonly tool: string,\n public readonly target: string,\n public readonly branch: string,\n public readonly sync: string,\n public readonly projectDir: string,\n ) {}\n}\n\n/**\n * The per-INVOCATION stream — `.webpieces/logs/calls/<writer>.log` (see LogStream for the writer\n * key), one line for EVERY guards-hook\n * call (allow or block, bash or file), unlike `L2-decisions/` which records only the calls a\n * rule actually judged. It captures the tool, the command/file, the live git branch, the async-written\n * main-sync-status.json snapshot (branch / merged / fork-point / conflict), and — since this class\n * replaced a bare log-and-forget function — HOW THE CALL ENDED.\n *\n * WHY IT IS TWO CALLS. The line used to be written the moment the hook started, so it could not carry\n * a verdict: the decision had not been made yet. Answering \"what happened to this call?\" therefore\n * meant joining this file against the L2 decision stream BY TIMESTAMP, which is exactly the kind of\n * reconstruction a log exists to make unnecessary. So {@link begin} now only CAPTURES (including the\n * git/cache reads, which must still happen while the hook is running), and {@link finish} — called\n * from the hook's single terminal boundary, emitAllow/emitDeny — writes the whole line once the\n * outcome is known. The two streams stay distinct in purpose: this one is \"every call and how it\n * ended\", the decision log remains \"every judgement and why\".\n *\n * Every error is swallowed: logging must never block or fail a hook.\n */\nexport class InvocationLog {\n private pending: GuardInvocation | null = null;\n\n /**\n * Capture the context of one invocation. `cwd` is the AI's working dir; the repo root that owns\n * `.webpieces` is resolved from it. Writes NOTHING — {@link finish} does that.\n */\n begin(cwd: string, tool: string, target: string): void {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n const root = new RepoRootFinder().resolveRepoRoot(cwd);\n const branch = branchForLog(root);\n // The cache is branch-keyed, so the entry to log is the one for the branch we are standing\n // on. 'unknown' (branchForLog's failure value) simply misses and logs 'sync=none'.\n const sync = summarizeSyncStatus(readMainSyncStatus(root, branch));\n this.pending = new GuardInvocation(root, new Date().toISOString(), tool, oneLine(target), branch, sync, claudeEnv.projectDirForLog());\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n }\n }\n\n /**\n * Write the captured line, now stamped with the outcome. A no-op when nothing was captured (the\n * 'rules' hook, or a terminal boundary reached before begin()), and it clears the pending entry so\n * a second emit cannot double-log.\n *\n * `rule` is the rule that blocked, or '-' when there is none; `fault` is the L0 fault code when this\n * call ended on one (S/C/Y — the JS-side faults), else '-'. FIELD ORDER IS APPEND-ONLY: the five\n * original fields keep their positions (cleanup automation mines this file), and `guards=` /\n * `rule=` / … / `fault=` are added at the end.\n */\n finish(verdict: Verdict, rule: string, fault: string = L0_FAULT_NONE): void {\n const invocation = this.pending;\n this.pending = null;\n if (invocation === null) return;\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n const logsDir = dotWebpieces.logsFile(invocation.root, CALLS_STREAM);\n fs.mkdirSync(logsDir, { recursive: true });\n const logPath = path.join(logsDir, logStream.writerFile('.log'));\n rotateLogFile(logPath, path.join(logsDir, logStream.writerFile('.1.log')));\n\n const line = [\n `[${invocation.timestamp}]`,\n invocation.tool,\n invocation.target,\n `branch=${invocation.branch}`,\n invocation.sync,\n // `guards=`, NOT `verdict=`. This hook can only report on ITSELF. Claude Code runs all\n // its PreToolUse hooks IN PARALLEL, so another hook process may deny a call this one\n // had no objection to, and neither can see the other's answer. Measured under the\n // RETIRED three-hook form: `cd <repo>/packages && ls` was DENIED by L-1 and recorded\n // here three times as `verdict=ALLOW`. The old field name promised an outcome it\n // structurally cannot know, so the name stayed even though L-1 is gone: the two\n // surviving hooks still run in parallel and still cannot see each other.\n `guards=${verdict}`,\n `rule=${oneLine(rule) || '-'}`,\n // The tree the guard ACTED in, next to what Claude Code said the project was. Both, on\n // every line, because the diagnostic value is entirely in comparing them — see\n // ClaudeEnv for the open question this field exists to settle empirically.\n `root=${invocation.root}`,\n `projectDir=${invocation.projectDir}`,\n // See logGuardDecision: the short tree label, so `tree=primary` with a matching\n // projectDir reads as healthy at a glance and `tree=<worktree>` beside a projectDir\n // pointing at the primary is the straddle, without diffing two absolute paths.\n `tree=${dotWebpieces.worktreeName(invocation.root) || 'primary'}`,\n // WHICH L0 fault ended this call, in the same letters and the same field name the L0 sh\n // shim uses (the `L0-shim/` stream) — so ONE grep spans the whole trail.\n `fault=${fault}`,\n // WHICH HARNESS made the call — same field name and same vocabulary as the L0 sh shim's\n // `ai=` and the decision stream's, so one grep spans the whole trail. APPEND-ONLY.\n `ai=${aiTypeContext.forLog()}`,\n ].join('\\t') + '\\n';\n fs.appendFileSync(logPath, line);\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n }\n }\n}\n\n// Process-wide instance: one hook process handles exactly one tool call, so a single pending entry is\n// the whole state there is. Module-scope (rather than DI) because the terminal boundary that flushes\n// it — emitAllow/emitDeny — is itself module-scope protocol code with no container in reach.\nexport const invocationLog = new InvocationLog();\n\n// One-field summary of main-sync-status.json for the invocation log: the branch the cache is FOR,\n// whether it is already merged (and its PR), fork-point presence, and conflict state — the signals a\n// cleanup step keys off. 'sync=none' when the cache has not been written yet (first call of a session).\nfunction summarizeSyncStatus(status: MainSyncStatus | null): string {\n if (status === null) return 'sync=none';\n const merged = status.branchAlreadyMerged ? `PR#${status.mergedPr !== '' ? status.mergedPr : '?'}` : 'no';\n return `sync=${status.branch} merged=${merged} fork=${String(status.hasForkPoint)} conflict=${String(status.conflict)} ts=${status.timestamp}`;\n}\n\n// Best-effort current branch for the log line. Returns 'unknown' on any failure (e.g. not a git\n// repo) — this is for display only, never for a control decision.\nexport function branchForLog(root: string): string {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n return execSync('git rev-parse --abbrev-ref HEAD', {\n cwd: root,\n encoding: 'utf8',\n stdio: ['pipe', 'pipe', 'pipe'],\n }).trim() || 'unknown';\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return 'unknown';\n }\n}\n\n// Collapse newlines/tabs and cap length so one decision is always one log line. The collapse itself\n// lives in LogTarget, because SessionCallHistory READS this format back and the two must agree byte\n// for byte — a second private copy of the cap is a silent way for a long command to stop matching\n// itself.\n// webpieces-disable no-function-outside-class -- the module's own leaf helper, beside branchForLog/rotateLogFile\nfunction oneLine(value: string): string {\n return logTarget.oneLine(value);\n}\n\nfunction rotateLogFile(logPath: string, prevPath: string): void {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n const stat = fs.statSync(logPath);\n if (stat.size > MAX_LOG_BYTES) {\n if (fs.existsSync(prevPath)) fs.unlinkSync(prevPath);\n fs.renameSync(logPath, prevPath);\n }\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n }\n}\n"]}
@@ -1,8 +0,0 @@
1
- import { Rule, ToolKind } from './types';
2
- export declare class DeleteScopedRules {
3
- /**
4
- * `rules` unchanged for every other ToolKind; for a Delete, narrowed to the rules that opted into
5
- * judging one — today, none of them, so a delete is always allowed.
6
- */
7
- narrow(toolKind: ToolKind, rules: readonly Rule[]): readonly Rule[];
8
- }
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DeleteScopedRules = void 0;
4
- /**
5
- * The rules that judge a FILE DELETION. Empty, deliberately, and changing that is a human's call.
6
- *
7
- * `Delete` is a new ToolKind, reachable only from Codex's `apply_patch` `*** Delete File:` directive —
8
- * Claude Code has no delete tool at all. Every rule in this engine was written against the bytes an
9
- * edit ADDS (an EditContext's `addedContent`), and a deletion has none, so running them on one would
10
- * either produce nothing or produce a verdict about content that is going away. Defaulting all of them
11
- * OFF keeps every existing rule's behaviour exactly what it was.
12
- *
13
- * Two families would arguably be RIGHT to fire here, and are listed rather than enabled because the
14
- * decision is a policy call, not a refactor: rules that keep a barrel/index in step with the files it
15
- * exports, and rules that keep a doc in step with the file it documents. Deleting a file is precisely
16
- * when those two go stale.
17
- */
18
- const DELETE_SCOPED_RULES = new Set([]);
19
- class DeleteScopedRules {
20
- /**
21
- * `rules` unchanged for every other ToolKind; for a Delete, narrowed to the rules that opted into
22
- * judging one — today, none of them, so a delete is always allowed.
23
- */
24
- narrow(toolKind, rules) {
25
- if (toolKind !== 'Delete')
26
- return rules;
27
- return rules.filter((r) => DELETE_SCOPED_RULES.has(r.name));
28
- }
29
- }
30
- exports.DeleteScopedRules = DeleteScopedRules;
31
- //# sourceMappingURL=delete-scoped-rules.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"delete-scoped-rules.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/core/delete-scoped-rules.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;;;;;GAaG;AACH,MAAM,mBAAmB,GAAwB,IAAI,GAAG,CAAC,EAAE,CAAC,CAAC;AAE7D,MAAa,iBAAiB;IAC1B;;;OAGG;IACH,MAAM,CAAC,QAAkB,EAAE,KAAsB;QAC7C,IAAI,QAAQ,KAAK,QAAQ;YAAE,OAAO,KAAK,CAAC;QACxC,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAO,EAAW,EAAE,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IAC/E,CAAC;CACJ;AATD,8CASC","sourcesContent":["import { Rule, ToolKind } from './types';\n\n/**\n * The rules that judge a FILE DELETION. Empty, deliberately, and changing that is a human's call.\n *\n * `Delete` is a new ToolKind, reachable only from Codex's `apply_patch` `*** Delete File:` directive —\n * Claude Code has no delete tool at all. Every rule in this engine was written against the bytes an\n * edit ADDS (an EditContext's `addedContent`), and a deletion has none, so running them on one would\n * either produce nothing or produce a verdict about content that is going away. Defaulting all of them\n * OFF keeps every existing rule's behaviour exactly what it was.\n *\n * Two families would arguably be RIGHT to fire here, and are listed rather than enabled because the\n * decision is a policy call, not a refactor: rules that keep a barrel/index in step with the files it\n * exports, and rules that keep a doc in step with the file it documents. Deleting a file is precisely\n * when those two go stale.\n */\nconst DELETE_SCOPED_RULES: ReadonlySet<string> = new Set([]);\n\nexport class DeleteScopedRules {\n /**\n * `rules` unchanged for every other ToolKind; for a Delete, narrowed to the rules that opted into\n * judging one — today, none of them, so a delete is always allowed.\n */\n narrow(toolKind: ToolKind, rules: readonly Rule[]): readonly Rule[] {\n if (toolKind !== 'Delete') return rules;\n return rules.filter((r: Rule): boolean => DELETE_SCOPED_RULES.has(r.name));\n }\n}\n"]}
@@ -1,8 +0,0 @@
1
- import type { IsLineDisabled } from './types';
2
- export declare class DirectiveIndex {
3
- private readonly lineDisables;
4
- constructor(lineDisables: Map<number, Set<string>>);
5
- isLineDisabled(lineNum: number, ruleName: string): boolean;
6
- }
7
- export declare function parseDirectives(source: string): DirectiveIndex;
8
- export declare function createIsLineDisabled(source: string): IsLineDisabled;
@@ -1,80 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DirectiveIndex = void 0;
4
- exports.parseDirectives = parseDirectives;
5
- exports.createIsLineDisabled = createIsLineDisabled;
6
- const rules_config_1 = require("@webpieces/rules-config");
7
- // Exactly ONE disable form: `// webpieces-disable <rule>[, <rule2>] -- reason`.
8
- // A rule (or comma-list of rules) is REQUIRED — there is no bare/`*` "disable everything",
9
- // no `ai-hook-disable` alias, and no `-file`/`-next`/`-all` variants. A disable applies to
10
- // the same line (when code precedes the `//`) or the next non-comment line.
11
- const DIRECTIVE_RE = new RegExp(`//\\s*${rules_config_1.WEBPIECES_DISABLE}\\s+([\\w-]+(?:\\s*,\\s*[\\w-]+)*)(?:\\s*--\\s*.*)?\\s*$`);
12
- const COMMENT_PREFIX_RE = new RegExp(`^//\\s*${rules_config_1.WEBPIECES_DISABLE}`);
13
- class DirectiveIndex {
14
- lineDisables;
15
- constructor(lineDisables) {
16
- this.lineDisables = lineDisables;
17
- }
18
- isLineDisabled(lineNum, ruleName) {
19
- const set = this.lineDisables.get(lineNum);
20
- if (!set)
21
- return false;
22
- return set.has(ruleName);
23
- }
24
- }
25
- exports.DirectiveIndex = DirectiveIndex;
26
- function parseRuleList(raw) {
27
- return raw
28
- .split(',')
29
- .map((s) => s.trim())
30
- .filter((s) => s.length > 0 && s !== '*');
31
- }
32
- function nextTargetLine(lines, lineIdx) {
33
- for (let j = lineIdx + 1; j < lines.length; j += 1) {
34
- const trimmed = lines[j].trim();
35
- if (trimmed === '')
36
- continue;
37
- if (COMMENT_PREFIX_RE.test(trimmed))
38
- continue;
39
- return j + 1;
40
- }
41
- return null;
42
- }
43
- function addDisable(map, lineNum, rules) {
44
- if (!map.has(lineNum))
45
- map.set(lineNum, new Set());
46
- const set = map.get(lineNum);
47
- for (const r of rules)
48
- set.add(r);
49
- }
50
- function resolveTarget(line, lines, i, map, rules) {
51
- const beforeComment = line.slice(0, line.indexOf('//')).trim();
52
- if (beforeComment !== '') {
53
- addDisable(map, i + 1, rules);
54
- }
55
- else {
56
- const target = nextTargetLine(lines, i);
57
- if (target !== null)
58
- addDisable(map, target, rules);
59
- }
60
- }
61
- function parseDirectives(source) {
62
- const lines = source.split('\n');
63
- const lineDisables = new Map();
64
- for (let i = 0; i < lines.length; i += 1) {
65
- const line = lines[i];
66
- const match = line.match(DIRECTIVE_RE);
67
- if (!match)
68
- continue;
69
- const rules = parseRuleList(match[1]);
70
- if (rules.length === 0)
71
- continue;
72
- resolveTarget(line, lines, i, lineDisables, rules);
73
- }
74
- return new DirectiveIndex(lineDisables);
75
- }
76
- function createIsLineDisabled(source) {
77
- const index = parseDirectives(source);
78
- return (lineNum, ruleName) => index.isLineDisabled(lineNum, ruleName);
79
- }
80
- //# sourceMappingURL=disable-directives.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"disable-directives.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/core/disable-directives.ts"],"names":[],"mappings":";;;AA8DA,0CAaC;AAED,oDAGC;AAhFD,0DAA4D;AAG5D,gFAAgF;AAChF,2FAA2F;AAC3F,2FAA2F;AAC3F,4EAA4E;AAC5E,MAAM,YAAY,GAAG,IAAI,MAAM,CAC3B,SAAS,gCAAiB,0DAA0D,CACvF,CAAC;AACF,MAAM,iBAAiB,GAAG,IAAI,MAAM,CAAC,UAAU,gCAAiB,EAAE,CAAC,CAAC;AAEpE,MAAa,cAAc;IACN,YAAY,CAA2B;IAExD,YAAY,YAAsC;QAC9C,IAAI,CAAC,YAAY,GAAG,YAAY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AAC,CAAC;IACvD,CAAC;IACD,OAAO,IAAI,cAAc,CAAC,YAAY,CAAC,CAAC;AAC5C,CAAC;AAED,SAAgB,oBAAoB,CAAC,MAAc;IAC/C,MAAM,KAAK,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;IACtC,OAAO,CAAC,OAAe,EAAE,QAAgB,EAAW,EAAE,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;AACnG,CAAC","sourcesContent":["import { WEBPIECES_DISABLE } from '@webpieces/rules-config';\nimport type { IsLineDisabled } from './types';\n\n// Exactly ONE disable form: `// webpieces-disable <rule>[, <rule2>] -- reason`.\n// A rule (or comma-list of rules) is REQUIRED — there is no bare/`*` \"disable everything\",\n// no `ai-hook-disable` alias, and no `-file`/`-next`/`-all` variants. A disable applies to\n// the same line (when code precedes the `//`) or the next non-comment line.\nconst DIRECTIVE_RE = new RegExp(\n `//\\\\s*${WEBPIECES_DISABLE}\\\\s+([\\\\w-]+(?:\\\\s*,\\\\s*[\\\\w-]+)*)(?:\\\\s*--\\\\s*.*)?\\\\s*$`,\n);\nconst COMMENT_PREFIX_RE = new RegExp(`^//\\\\s*${WEBPIECES_DISABLE}`);\n\nexport class DirectiveIndex {\n private readonly lineDisables: Map<number, Set<string>>;\n\n constructor(lineDisables: Map<number, Set<string>>) {\n this.lineDisables = lineDisables;\n }\n\n isLineDisabled(lineNum: number, ruleName: string): boolean {\n const set = this.lineDisables.get(lineNum);\n if (!set) return false;\n return set.has(ruleName);\n }\n}\n\nfunction parseRuleList(raw: string): readonly string[] {\n return raw\n .split(',')\n .map((s: string): string => s.trim())\n .filter((s: string): boolean => s.length > 0 && s !== '*');\n}\n\nfunction nextTargetLine(lines: readonly string[], lineIdx: number): number | null {\n for (let j = lineIdx + 1; j < lines.length; j += 1) {\n const trimmed = lines[j].trim();\n if (trimmed === '') continue;\n if (COMMENT_PREFIX_RE.test(trimmed)) continue;\n return j + 1;\n }\n return null;\n}\n\nfunction addDisable(map: Map<number, Set<string>>, lineNum: number, rules: readonly string[]): void {\n if (!map.has(lineNum)) map.set(lineNum, new Set<string>());\n const set = map.get(lineNum)!;\n for (const r of rules) set.add(r);\n}\n\nfunction resolveTarget(\n line: string, lines: readonly string[], i: number,\n map: Map<number, Set<string>>, rules: readonly string[],\n): void {\n const beforeComment = line.slice(0, line.indexOf('//')).trim();\n if (beforeComment !== '') {\n addDisable(map, i + 1, rules);\n } else {\n const target = nextTargetLine(lines, i);\n if (target !== null) addDisable(map, target, rules);\n }\n}\n\nexport function parseDirectives(source: string): DirectiveIndex {\n const lines = source.split('\\n');\n const lineDisables = new Map<number, Set<string>>();\n\n for (let i = 0; i < lines.length; i += 1) {\n const line = lines[i];\n const match = line.match(DIRECTIVE_RE);\n if (!match) continue;\n const rules = parseRuleList(match[1]);\n if (rules.length === 0) continue;\n resolveTarget(line, lines, i, lineDisables, rules);\n }\n return new DirectiveIndex(lineDisables);\n}\n\nexport function createIsLineDisabled(source: string): IsLineDisabled {\n const index = parseDirectives(source);\n return (lineNum: number, ruleName: string): boolean => index.isLineDisabled(lineNum, ruleName);\n}\n"]}