@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,203 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WaitSpinScan = exports.WaitSpinHit = exports.BLOCKING_WATCH_FLAG = exports.PAGER_PROGRAMS = exports.POLLED_GH_SUBCOMMANDS = exports.NOOP_PROGRAMS = exports.SPIN_POLL = exports.SPIN_NOOP = void 0;
4
- /**
5
- * Decides the one question `wait-spin-guard` asks of a command's TEXT: is this command, all by itself,
6
- * a way of staying alive rather than a way of doing something?
7
- *
8
- * ─── The two shapes, and why only these ────────────────────────────────────────────────────────────
9
- *
10
- * NO-OP the whole command produces no effect an agent could act on — `echo .`, `echo idle3`,
11
- * `true`, `:`, `date -u +%H:%M`. Measured across the fleet in the 24h to 2026-09-07: ten
12
- * agent runs spun this way, 920M tokens (18.3% of fleet tokens) burned, because every turn
13
- * resends the whole conversation at ~557k tokens. Nobody types these to learn anything.
14
- *
15
- * POLL an identical `gh pr checks <n>` / `gh pr view <n>`, run over and over. ONE of these is a
16
- * legitimate snapshot and must stay allowed — it is the difference between asking a
17
- * question and refusing to stop asking it — so this scan only CLASSIFIES the shape, and
18
- * the guard decides on the session's own call history whether it has been asked before.
19
- *
20
- * ─── What is NOT a hit, and why the carve-outs are the whole risk ──────────────────────────────────
21
- * `echo` is everywhere in legitimate work, and a false positive here breaks ordinary commands rather
22
- * than merely annoying somebody. Three rules keep it honest, and every one of them is drawn from real
23
- * lines in this repo's own guard logs:
24
- *
25
- * ONE SEGMENT ONLY `echo "=== IN-SCOPE DIFF ===" && git diff …` and
26
- * `sed -n 1,50p f.ts; echo ---; sed -n 60,90p f.ts` are compound commands that DO
27
- * something. A command with a second segment is never a hit, whatever the first
28
- * segment is.
29
- * NO REDIRECT `echo "$body" > /tmp/pr-body.md` writes a file. `ShellSegmentScan.redirectsToFile`
30
- * owns that test (and its `2>&1` carve-out), shared rather than re-spelled here.
31
- * NO PIPE a pipe is a second segment, so this falls out of the segment rule; `date | xargs …`
32
- * is a real command and is allowed by construction.
33
- *
34
- * The argument shape is deliberately narrow too: at most ONE argument, and it must be a short bare
35
- * token (`.`, `idle4`, `waiting-for-reviewers`). `echo $PATH` and `echo -n .` are allowed — missing a
36
- * spin costs one turn, and refusing a real command costs the task.
37
- *
38
- * ─── The ONE exception to ONE SEGMENT ONLY, and it is POLL-shaped only (issue #878) ────────────────
39
- * A pipe on a NO-OP is a second command doing work, and that carve-out stays exactly as written. A
40
- * TRAILING PAGER on a POLL is not: `gh pr checks 1058 2>&1 | head` asks the identical question as
41
- * `gh pr checks 1058 2>&1` and is the same spin wearing a hat. Measured over 30 days it is the
42
- * majority form — `gh pr checks 464 2>&1 | head` 173 times, `gh pr checks 1058 2>&1 | head` 81,
43
- * `gh pr checks 428 2>&1 | head -10` 72 — worth 15.5% of one repo's wait waste and 7.4% of another's,
44
- * all of it invisible to the single-segment rule.
45
- *
46
- * So a trailing {@link PAGER_PROGRAMS} segment is normalised away before the head segment is
47
- * classified, and the result is then accepted ONLY when it is a POLL. `date | xargs …` and
48
- * `echo x | head` stay allowed, because a NO-OP hit reached through a pipe is discarded — the
49
- * single-segment rule is not relaxed, it is bypassed for one shape whose repeat count is the defect.
50
- */
51
- /** The whole command does nothing — an `echo`/`true`/`:`/`date` keep-alive. */
52
- exports.SPIN_NOOP = 'noop';
53
- /** The whole command is a PR/CI status read. Only a REPEAT of one is a spin; the guard decides that. */
54
- exports.SPIN_POLL = 'poll';
55
- /** Programs whose bare invocation is a keep-alive and nothing else. */
56
- exports.NOOP_PROGRAMS = ['echo', 'true', ':', 'date'];
57
- /** `gh pr <subcommand>` reads that say nothing new when repeated against an unchanged PR. */
58
- exports.POLLED_GH_SUBCOMMANDS = ['checks', 'view'];
59
- /**
60
- * Pagers that may trail a POLL through a pipe without changing the question it asks. Narrow on
61
- * purpose: every one of these only TRUNCATES its input, so the command in front of it is still the
62
- * whole command. `grep`, `jq` and `awk` are deliberately absent — `gh pr checks 874 | grep fail` asks
63
- * a narrower question than the bare poll, somebody is reading the answer, and it stays allowed.
64
- */
65
- exports.PAGER_PROGRAMS = ['head', 'tail', 'cat', 'wc'];
66
- /**
67
- * The flag that turns `gh pr checks` from a poll into a BLOCKING wait, and is therefore never a spin.
68
- *
69
- * Measured over the same window: 224 subagent calls and 84 main-agent calls carried it. It is a
70
- * legitimate wait primitive — one call that blocks — which is the very thing this guard exists to push
71
- * agents towards, so refusing it however often it appears would refuse the cure. (`wp-await-checks`
72
- * still earns its place beside it: `--watch` has no bounded exit and the harness kills it at 600s
73
- * having printed nothing, whereas `wp-await-checks` heartbeats and returns cleanly at 540s.)
74
- */
75
- exports.BLOCKING_WATCH_FLAG = '--watch';
76
- const NOOP_SET = new Set(exports.NOOP_PROGRAMS);
77
- const POLLED_SET = new Set(exports.POLLED_GH_SUBCOMMANDS);
78
- const PAGER_SET = new Set(exports.PAGER_PROGRAMS);
79
- /**
80
- * The KEEP-ALIVE TOKENS, and nothing wider.
81
- *
82
- * This started as "any short bare token" and that was measurably too wide. Two real commands matched:
83
- * `echo hi`, which is a benign line in this package's own golden fixtures, and the prose-stripped
84
- * remains of an `echo "<a sentence>"`, which `runner.spec.ts` asserts is NOT blocked. Both are commands
85
- * somebody meant, and a guard that refuses those is a guard someone turns off.
86
- *
87
- * So the family is NAMED rather than inferred: the dot runs, plus the words the measured spins actually
88
- * used, each free to carry a numeric or hyphenated tail (`idle3`, `waiting-for-reviewers`). Anything
89
- * else `echo` prints is content, and content is allowed.
90
- */
91
- const KEEP_ALIVE_TOKEN = /^(?:\.{1,3}|(?:idle|ok|okay|waiting|wait|standby|still|alive|ping|pong|tick|noop|nop|heartbeat|zzz)[a-z0-9_-]*)$/i;
92
- /** One spin-shaped command: WHICH shape, and the program that produced it. Data-only (per CLAUDE.md). */
93
- class WaitSpinHit {
94
- shape;
95
- program;
96
- constructor(shape, program) {
97
- this.shape = shape;
98
- this.program = program;
99
- }
100
- }
101
- exports.WaitSpinHit = WaitSpinHit;
102
- class WaitSpinScan {
103
- scanner;
104
- segments;
105
- constructor(scanner, segments) {
106
- this.scanner = scanner;
107
- this.segments = segments;
108
- }
109
- /** The spin shape this whole command is, or null when it is a real command. */
110
- classify(command) {
111
- const parts = this.scanner.segmentsWithJoins(command);
112
- if (parts.length === 1)
113
- return this.classifySegment(parts[0].text, false);
114
- if (this.endsInPager(parts))
115
- return this.classifySegment(parts[0].text, true);
116
- return null;
117
- }
118
- /**
119
- * Classify ONE segment's words. `pollOnly` is set when the segment was reached by stripping a
120
- * trailing pager, and it discards a NO-OP hit: `echo . | head` is a pipe into a real program and
121
- * must stay allowed, while `gh pr checks 5 | head` is the same poll as `gh pr checks 5`.
122
- */
123
- classifySegment(text, pollOnly) {
124
- const words = this.scanner.runnerStrippedWords(text);
125
- if (words.length === 0)
126
- return null;
127
- if (this.segments.redirectsToFile(words))
128
- return null;
129
- const hit = this.classifyWords(words);
130
- if (hit === null)
131
- return null;
132
- return pollOnly && hit.shape !== exports.SPIN_POLL ? null : hit;
133
- }
134
- classifyWords(words) {
135
- const program = this.scanner.programName(words[0]);
136
- if (this.isPoll(program, words))
137
- return new WaitSpinHit(exports.SPIN_POLL, this.pollLabel(words));
138
- if (!NOOP_SET.has(program))
139
- return null;
140
- return this.isNoop(program, words) ? new WaitSpinHit(exports.SPIN_NOOP, program) : null;
141
- }
142
- /** Exactly two segments, joined by a pipe, the second of which only truncates its input. */
143
- endsInPager(parts) {
144
- if (parts.length !== 2 || parts[1].join !== '|')
145
- return false;
146
- const words = this.scanner.runnerStrippedWords(parts[1].text);
147
- return words.length > 0 && this.isPagerWords(words);
148
- }
149
- /**
150
- * `head`, `tail`, `cat`, `wc -l` — and ONLY with the argument shapes that keep them pure
151
- * truncations. `head -c 1 file` names a file and `wc -c` counts something else, so an unrecognised
152
- * argument means "not a pager", which means the whole command falls back to the segment rule and
153
- * is allowed. Missing a spin costs one turn; refusing a real command costs the task.
154
- */
155
- isPagerWords(words) {
156
- const program = this.scanner.programName(words[0]);
157
- if (!PAGER_SET.has(program))
158
- return false;
159
- const args = words.slice(1);
160
- if (program === 'cat')
161
- return args.length === 0;
162
- if (program === 'wc')
163
- return args.length === 1 && args[0] === '-l';
164
- if (args.length === 0)
165
- return true;
166
- if (args.length === 1)
167
- return /^-\d+$/.test(args[0]);
168
- return args.length === 2 && args[0] === '-n' && /^\d+$/.test(args[1]);
169
- }
170
- /**
171
- * `echo` must carry EXACTLY ONE keep-alive token. A BARE `echo` is deliberately not a hit: quoted
172
- * prose is stripped out of `commandCode`, so `echo "<any sentence>"` arrives here as a bare `echo`,
173
- * and blocking that shape refuses a command whose content nobody ever looked at.
174
- *
175
- * `true`, `:` and `date` are judged whole: `date -u +%H:%M` prints the clock and nothing else,
176
- * whatever its format string.
177
- */
178
- isNoop(program, words) {
179
- if (program === 'true' || program === ':')
180
- return words.length === 1;
181
- if (program === 'date')
182
- return true;
183
- return words.length === 2 && KEEP_ALIVE_TOKEN.test(words[1]);
184
- }
185
- /**
186
- * A `gh pr checks/view` read — EXCEPT when it carries {@link BLOCKING_WATCH_FLAG}, which makes it
187
- * one blocking call rather than a poll. See that constant for why that exception is load-bearing.
188
- */
189
- isPoll(program, words) {
190
- if (program !== 'gh' || words.length < 3 || words[1] !== 'pr')
191
- return false;
192
- if (!POLLED_SET.has(words[2]))
193
- return false;
194
- return !words.includes(exports.BLOCKING_WATCH_FLAG);
195
- }
196
- // `gh pr checks` / `gh pr view` — the label the refusal prints, without the PR number or the flags,
197
- // which the guard already has in the raw command.
198
- pollLabel(words) {
199
- return `gh pr ${words[2]}`;
200
- }
201
- }
202
- exports.WaitSpinScan = WaitSpinScan;
203
- //# sourceMappingURL=wait-spin-scan.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"wait-spin-scan.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/ai-hook-rules/src/core/rules/wait-spin-scan.ts"],"names":[],"mappings":"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","sourcesContent":["import { CommandScanner, CommandSegment } from '../command-scan';\nimport { ShellSegmentScan } from './shell-segment-scan';\n\n/**\n * Decides the one question `wait-spin-guard` asks of a command's TEXT: is this command, all by itself,\n * a way of staying alive rather than a way of doing something?\n *\n * ─── The two shapes, and why only these ────────────────────────────────────────────────────────────\n *\n * NO-OP the whole command produces no effect an agent could act on — `echo .`, `echo idle3`,\n * `true`, `:`, `date -u +%H:%M`. Measured across the fleet in the 24h to 2026-09-07: ten\n * agent runs spun this way, 920M tokens (18.3% of fleet tokens) burned, because every turn\n * resends the whole conversation at ~557k tokens. Nobody types these to learn anything.\n *\n * POLL an identical `gh pr checks <n>` / `gh pr view <n>`, run over and over. ONE of these is a\n * legitimate snapshot and must stay allowed — it is the difference between asking a\n * question and refusing to stop asking it — so this scan only CLASSIFIES the shape, and\n * the guard decides on the session's own call history whether it has been asked before.\n *\n * ─── What is NOT a hit, and why the carve-outs are the whole risk ──────────────────────────────────\n * `echo` is everywhere in legitimate work, and a false positive here breaks ordinary commands rather\n * than merely annoying somebody. Three rules keep it honest, and every one of them is drawn from real\n * lines in this repo's own guard logs:\n *\n * ONE SEGMENT ONLY `echo \"=== IN-SCOPE DIFF ===\" && git diff …` and\n * `sed -n 1,50p f.ts; echo ---; sed -n 60,90p f.ts` are compound commands that DO\n * something. A command with a second segment is never a hit, whatever the first\n * segment is.\n * NO REDIRECT `echo \"$body\" > /tmp/pr-body.md` writes a file. `ShellSegmentScan.redirectsToFile`\n * owns that test (and its `2>&1` carve-out), shared rather than re-spelled here.\n * NO PIPE a pipe is a second segment, so this falls out of the segment rule; `date | xargs …`\n * is a real command and is allowed by construction.\n *\n * The argument shape is deliberately narrow too: at most ONE argument, and it must be a short bare\n * token (`.`, `idle4`, `waiting-for-reviewers`). `echo $PATH` and `echo -n .` are allowed — missing a\n * spin costs one turn, and refusing a real command costs the task.\n *\n * ─── The ONE exception to ONE SEGMENT ONLY, and it is POLL-shaped only (issue #878) ────────────────\n * A pipe on a NO-OP is a second command doing work, and that carve-out stays exactly as written. A\n * TRAILING PAGER on a POLL is not: `gh pr checks 1058 2>&1 | head` asks the identical question as\n * `gh pr checks 1058 2>&1` and is the same spin wearing a hat. Measured over 30 days it is the\n * majority form — `gh pr checks 464 2>&1 | head` 173 times, `gh pr checks 1058 2>&1 | head` 81,\n * `gh pr checks 428 2>&1 | head -10` 72 — worth 15.5% of one repo's wait waste and 7.4% of another's,\n * all of it invisible to the single-segment rule.\n *\n * So a trailing {@link PAGER_PROGRAMS} segment is normalised away before the head segment is\n * classified, and the result is then accepted ONLY when it is a POLL. `date | xargs …` and\n * `echo x | head` stay allowed, because a NO-OP hit reached through a pipe is discarded — the\n * single-segment rule is not relaxed, it is bypassed for one shape whose repeat count is the defect.\n */\n\n/** The whole command does nothing — an `echo`/`true`/`:`/`date` keep-alive. */\nexport const SPIN_NOOP = 'noop';\n/** The whole command is a PR/CI status read. Only a REPEAT of one is a spin; the guard decides that. */\nexport const SPIN_POLL = 'poll';\n\n/** Programs whose bare invocation is a keep-alive and nothing else. */\nexport const NOOP_PROGRAMS: readonly string[] = ['echo', 'true', ':', 'date'];\n\n/** `gh pr <subcommand>` reads that say nothing new when repeated against an unchanged PR. */\nexport const POLLED_GH_SUBCOMMANDS: readonly string[] = ['checks', 'view'];\n\n/**\n * Pagers that may trail a POLL through a pipe without changing the question it asks. Narrow on\n * purpose: every one of these only TRUNCATES its input, so the command in front of it is still the\n * whole command. `grep`, `jq` and `awk` are deliberately absent — `gh pr checks 874 | grep fail` asks\n * a narrower question than the bare poll, somebody is reading the answer, and it stays allowed.\n */\nexport const PAGER_PROGRAMS: readonly string[] = ['head', 'tail', 'cat', 'wc'];\n\n/**\n * The flag that turns `gh pr checks` from a poll into a BLOCKING wait, and is therefore never a spin.\n *\n * Measured over the same window: 224 subagent calls and 84 main-agent calls carried it. It is a\n * legitimate wait primitive — one call that blocks — which is the very thing this guard exists to push\n * agents towards, so refusing it however often it appears would refuse the cure. (`wp-await-checks`\n * still earns its place beside it: `--watch` has no bounded exit and the harness kills it at 600s\n * having printed nothing, whereas `wp-await-checks` heartbeats and returns cleanly at 540s.)\n */\nexport const BLOCKING_WATCH_FLAG = '--watch';\n\nconst NOOP_SET: ReadonlySet<string> = new Set(NOOP_PROGRAMS);\nconst POLLED_SET: ReadonlySet<string> = new Set(POLLED_GH_SUBCOMMANDS);\nconst PAGER_SET: ReadonlySet<string> = new Set(PAGER_PROGRAMS);\n\n/**\n * The KEEP-ALIVE TOKENS, and nothing wider.\n *\n * This started as \"any short bare token\" and that was measurably too wide. Two real commands matched:\n * `echo hi`, which is a benign line in this package's own golden fixtures, and the prose-stripped\n * remains of an `echo \"<a sentence>\"`, which `runner.spec.ts` asserts is NOT blocked. Both are commands\n * somebody meant, and a guard that refuses those is a guard someone turns off.\n *\n * So the family is NAMED rather than inferred: the dot runs, plus the words the measured spins actually\n * used, each free to carry a numeric or hyphenated tail (`idle3`, `waiting-for-reviewers`). Anything\n * else `echo` prints is content, and content is allowed.\n */\nconst KEEP_ALIVE_TOKEN =\n /^(?:\\.{1,3}|(?:idle|ok|okay|waiting|wait|standby|still|alive|ping|pong|tick|noop|nop|heartbeat|zzz)[a-z0-9_-]*)$/i;\n\n/** One spin-shaped command: WHICH shape, and the program that produced it. Data-only (per CLAUDE.md). */\nexport class WaitSpinHit {\n shape: string;\n program: string;\n\n constructor(shape: string, program: string) {\n this.shape = shape;\n this.program = program;\n }\n}\n\nexport class WaitSpinScan {\n constructor(\n private readonly scanner: CommandScanner,\n private readonly segments: ShellSegmentScan,\n ) {}\n\n /** The spin shape this whole command is, or null when it is a real command. */\n classify(command: string): WaitSpinHit | null {\n const parts = this.scanner.segmentsWithJoins(command);\n if (parts.length === 1) return this.classifySegment(parts[0].text, false);\n if (this.endsInPager(parts)) return this.classifySegment(parts[0].text, true);\n return null;\n }\n\n /**\n * Classify ONE segment's words. `pollOnly` is set when the segment was reached by stripping a\n * trailing pager, and it discards a NO-OP hit: `echo . | head` is a pipe into a real program and\n * must stay allowed, while `gh pr checks 5 | head` is the same poll as `gh pr checks 5`.\n */\n private classifySegment(text: string, pollOnly: boolean): WaitSpinHit | null {\n const words = this.scanner.runnerStrippedWords(text);\n if (words.length === 0) return null;\n if (this.segments.redirectsToFile(words)) return null;\n const hit = this.classifyWords(words);\n if (hit === null) return null;\n return pollOnly && hit.shape !== SPIN_POLL ? null : hit;\n }\n\n private classifyWords(words: readonly string[]): WaitSpinHit | null {\n const program = this.scanner.programName(words[0]);\n if (this.isPoll(program, words)) return new WaitSpinHit(SPIN_POLL, this.pollLabel(words));\n if (!NOOP_SET.has(program)) return null;\n return this.isNoop(program, words) ? new WaitSpinHit(SPIN_NOOP, program) : null;\n }\n\n /** Exactly two segments, joined by a pipe, the second of which only truncates its input. */\n private endsInPager(parts: readonly CommandSegment[]): boolean {\n if (parts.length !== 2 || parts[1].join !== '|') return false;\n const words = this.scanner.runnerStrippedWords(parts[1].text);\n return words.length > 0 && this.isPagerWords(words);\n }\n\n /**\n * `head`, `tail`, `cat`, `wc -l` — and ONLY with the argument shapes that keep them pure\n * truncations. `head -c 1 file` names a file and `wc -c` counts something else, so an unrecognised\n * argument means \"not a pager\", which means the whole command falls back to the segment rule and\n * is allowed. Missing a spin costs one turn; refusing a real command costs the task.\n */\n private isPagerWords(words: readonly string[]): boolean {\n const program = this.scanner.programName(words[0]);\n if (!PAGER_SET.has(program)) return false;\n const args = words.slice(1);\n if (program === 'cat') return args.length === 0;\n if (program === 'wc') return args.length === 1 && args[0] === '-l';\n if (args.length === 0) return true;\n if (args.length === 1) return /^-\\d+$/.test(args[0]);\n return args.length === 2 && args[0] === '-n' && /^\\d+$/.test(args[1]);\n }\n\n /**\n * `echo` must carry EXACTLY ONE keep-alive token. A BARE `echo` is deliberately not a hit: quoted\n * prose is stripped out of `commandCode`, so `echo \"<any sentence>\"` arrives here as a bare `echo`,\n * and blocking that shape refuses a command whose content nobody ever looked at.\n *\n * `true`, `:` and `date` are judged whole: `date -u +%H:%M` prints the clock and nothing else,\n * whatever its format string.\n */\n private isNoop(program: string, words: readonly string[]): boolean {\n if (program === 'true' || program === ':') return words.length === 1;\n if (program === 'date') return true;\n return words.length === 2 && KEEP_ALIVE_TOKEN.test(words[1]);\n }\n\n /**\n * A `gh pr checks/view` read — EXCEPT when it carries {@link BLOCKING_WATCH_FLAG}, which makes it\n * one blocking call rather than a poll. See that constant for why that exception is load-bearing.\n */\n private isPoll(program: string, words: readonly string[]): boolean {\n if (program !== 'gh' || words.length < 3 || words[1] !== 'pr') return false;\n if (!POLLED_SET.has(words[2])) return false;\n return !words.includes(BLOCKING_WATCH_FLAG);\n }\n\n // `gh pr checks` / `gh pr view` — the label the refusal prints, without the PR number or the flags,\n // which the guard already has in the raw command.\n private pollLabel(words: readonly string[]): string {\n return `gh pr ${words[2]}`;\n }\n}\n"]}
@@ -1,125 +0,0 @@
1
- import type { BashContext, Violation } from '../types';
2
- import { BashRuleBase, EmptyRuleConfig } from '../rule-base';
3
- import { FixHint } from '../fix-hint';
4
- /**
5
- * Blocks a Bash command that would build or test the WHOLE monorepo, and hands back the narrow
6
- * command to run instead. Which shapes count is `WholeRepoBuildScan`'s job; this rule owns the
7
- * decision, the log line and the two refusal messages.
8
- *
9
- * ─── Why: SCOPE and AGREEMENT, not a speed claim ───────────────────────────────────────────────────
10
- * `nx affected --target=ci --base=<fork point>` is the command the PR gate itself runs
11
- * (`commands.pr-gate.buildCommand`), so a green local result is evidence about the gate. A whole-repo
12
- * build is a different, wider command whose green says nothing extra — it just also compiles projects
13
- * the change cannot reach.
14
- *
15
- * It is NOT automatically faster, and this guard deliberately does not claim it is. Measured on a
16
- * `core-util` change, `affected` selected the IDENTICAL 20 projects / 104 tasks as the whole-repo
17
- * build: a package at the BASE of the dependency graph prunes nothing. The pruning win is real for
18
- * LEAF projects and absent for base ones. The long builds people blamed on scope were caused by a cold
19
- * nx cache and by CPU contention between agents running full sweeps at once (measured: ~3.2x total
20
- * test time under contention) — neither of which a narrower target list fixes on its own.
21
- *
22
- * So what this guard buys is the scope being right by default. Building the world is never the
23
- * correct inner-loop move in a monorepo; the correct one has existed all along, and nothing stopped
24
- * the wide one.
25
- *
26
- * ─── The message is READ FROM CONFIG, and it is RESOLVED ───────────────────────────────────────────
27
- * The replacement command comes from `commands.pr-gate.buildCommand` (injected into this guard's
28
- * config by load-config), so the refusal follows the project when the gate command changes. The `$(…)`
29
- * in it is EXPANDED before printing: handing an agent `--base=$(git merge-base origin/main HEAD)` is
30
- * handing it a template, and a template pasted where no shell expands it produces a confusing failure
31
- * that reads like the guard's advice was wrong. Only `$(git …)` is expanded, and only read-only git;
32
- * anything else is left verbatim.
33
- *
34
- * ─── EXPERIMENTAL, OFF by default, with ONE machine-local opt-in ───────────────────────────────────
35
- * `experimental.whole-repo-build-guard` in `~/.webpieces/config.json` is this guard's only switch, and
36
- * it is an OPT-IN: ON requires the explicit boolean `true`. Absent key, absent `experimental` section,
37
- * absent file, and an explicit `false` are ONE state, and that state is OFF.
38
- *
39
- * That direction is a standing policy, not a per-flag judgement: EVERY `experimental.*` flag in this
40
- * codebase ships OFF and stays OFF for two years. A flag that defaults ON is not an experiment — it is
41
- * a shipped behaviour that skipped its soak period, and it changes what every agent on every machine
42
- * can do the moment they upgrade. If few machines opt in, that is information about the experiment; it
43
- * is not a reason to force it on everybody.
44
- *
45
- * There is also NO webpieces.config.json entry, for a separate reason: a live incident. This guard
46
- * first shipped with `mode: 'ON'` by default AND a REQUIRED entry under `hookGuards`, and every
47
- * consumer that upgraded hit fault Y — EVERY Bash call blocked — for a feature they had never asked
48
- * for. The fault was the REQUIRED KEY: the failure was at config LOAD, before any command was judged,
49
- * and the cure was "edit a file to get your shell back". Keeping the switch in an OPTIONAL
50
- * machine-local file is what makes the default state need no file, no key and no edit.
51
- *
52
- * Three states, and only three:
53
- * - the file does not exist (essentially every machine), or exists without the key → the guard is
54
- * OFF, and inert: no block, no log, no message. Every key in that file is optional, because it is
55
- * MACHINE-GLOBAL and the repos on one machine pin different webpieces releases — a required key
56
- * there is unsatisfiable (see home-config.ts).
57
- * - the key is present → its boolean decides, and only `true` arms the guard.
58
- * - the file exists and is unparseable, or a key it DOES define has the wrong type → HARD FAILURE
59
- * naming the edit. That is a file somebody wrote wrongly, not one written for another release.
60
- * Editing that file is an unconditional PASS in the guards, so the block is always self-curable.
61
- *
62
- * ─── ONE message, because the gate now always captures ─────────────────────────────────────────────
63
- * There used to be two refusals here, chosen by `experimental.buildGateLogCapture`: one naming the
64
- * narrower build to run, and one saying "do not build at all — stage ② already builds and you can READ
65
- * the result". That key is gone, because capturing the build's full output to a file is no longer
66
- * optional. What survived is the FIRST of those, now carrying the log pointer the second one existed to
67
- * offer: a refusal still has to answer "so what do I run?", and "run nothing" is only an answer when the
68
- * caller was already inside the PR flow.
69
- *
70
- * ─── Humans are not affected, by construction ──────────────────────────────────────────────────────
71
- * This is a PreToolUse hook. It sees the AI's Bash tool calls and nothing else — a human typing
72
- * `pnpm run build-all` in their own terminal never reaches a hook, and the `build-all` script itself is
73
- * deliberately left in package.json for exactly that reason. The guard is about what the AI does in a
74
- * loop, not about the command being wrong for a person who chooses to run it once.
75
- */
76
- export declare class WholeRepoBuildGuardRule extends BashRuleBase<EmptyRuleConfig> {
77
- private readonly affectedBuildCommand;
78
- /**
79
- * `affectedBuildCommand` is the project's gate command (`commands.pr-gate.buildCommand`), handed in
80
- * by the runner off the loaded config. It is a CONSTRUCTOR ARGUMENT rather than a config field
81
- * because this guard has no config entry to read one from — and that is the point.
82
- */
83
- constructor(affectedBuildCommand: string);
84
- private readonly scanner;
85
- private readonly homeConfig;
86
- /** Set by check() when the home config is unreadable, so the fix hint names the same repair. */
87
- private homeConfigError;
88
- readonly description: string;
89
- /**
90
- * The command this rule last printed, so the fix hint and the violation message are one string and
91
- * cannot disagree. Empty until check() runs (fixHint is also read without it), at which point the
92
- * getter falls back to the configured TEMPLATE — never to a second literal, which is exactly the
93
- * drift this guard's own docstring says a duplicated command string causes.
94
- */
95
- private resolvedCommand;
96
- get fixHint(): FixHint;
97
- check(ctx: BashContext): readonly Violation[];
98
- /**
99
- * The home config, or the Error explaining why it is unusable. NOT a boolean: "absent" is already
100
- * folded into the returned HomeConfig (each key's default — for this guard, OFF), so the only thing
101
- * left to distinguish is "present and wrong", which must be reported rather than swallowed.
102
- */
103
- private loadHome;
104
- private blockOnBrokenHomeConfig;
105
- private brokenHomeConfigMessage;
106
- private message;
107
- /**
108
- * The project's build command, unexpanded. ONE source: `commands.pr-gate.buildCommand`, handed to
109
- * the constructor by the runner, falling back to the same DEFAULT_BUILD_COMMAND the gate itself
110
- * falls back to. This guard never spells a build command of its own — a second copy is how a refusal
111
- * starts teaching a command the gate does not run.
112
- */
113
- private buildCommandTemplate;
114
- /**
115
- * The configured build command with its `$(git …)` substitutions expanded, so what is printed is
116
- * runnable as-is. Expansion is limited to git, and any failure leaves the template untouched — a
117
- * guard may degrade its own message, never fail the tool call it is judging.
118
- */
119
- private resolvedBuildCommand;
120
- private capture;
121
- private allow;
122
- private block;
123
- private truncate;
124
- private logDecision;
125
- }
@@ -1,257 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WholeRepoBuildGuardRule = void 0;
4
- const child_process_1 = require("child_process");
5
- const rules_config_1 = require("@webpieces/rules-config");
6
- const tooling_common_1 = require("@webpieces/tooling-common");
7
- const types_1 = require("../types");
8
- const rule_base_1 = require("../rule-base");
9
- const fix_hint_1 = require("../fix-hint");
10
- const to_error_1 = require("../to-error");
11
- const l0_fault_codes_1 = require("../l0-fault-codes");
12
- const decision_log_1 = require("../decision-log");
13
- const command_scan_1 = require("../command-scan");
14
- const whole_repo_build_scan_1 = require("./whole-repo-build-scan");
15
- /**
16
- * Blocks a Bash command that would build or test the WHOLE monorepo, and hands back the narrow
17
- * command to run instead. Which shapes count is `WholeRepoBuildScan`'s job; this rule owns the
18
- * decision, the log line and the two refusal messages.
19
- *
20
- * ─── Why: SCOPE and AGREEMENT, not a speed claim ───────────────────────────────────────────────────
21
- * `nx affected --target=ci --base=<fork point>` is the command the PR gate itself runs
22
- * (`commands.pr-gate.buildCommand`), so a green local result is evidence about the gate. A whole-repo
23
- * build is a different, wider command whose green says nothing extra — it just also compiles projects
24
- * the change cannot reach.
25
- *
26
- * It is NOT automatically faster, and this guard deliberately does not claim it is. Measured on a
27
- * `core-util` change, `affected` selected the IDENTICAL 20 projects / 104 tasks as the whole-repo
28
- * build: a package at the BASE of the dependency graph prunes nothing. The pruning win is real for
29
- * LEAF projects and absent for base ones. The long builds people blamed on scope were caused by a cold
30
- * nx cache and by CPU contention between agents running full sweeps at once (measured: ~3.2x total
31
- * test time under contention) — neither of which a narrower target list fixes on its own.
32
- *
33
- * So what this guard buys is the scope being right by default. Building the world is never the
34
- * correct inner-loop move in a monorepo; the correct one has existed all along, and nothing stopped
35
- * the wide one.
36
- *
37
- * ─── The message is READ FROM CONFIG, and it is RESOLVED ───────────────────────────────────────────
38
- * The replacement command comes from `commands.pr-gate.buildCommand` (injected into this guard's
39
- * config by load-config), so the refusal follows the project when the gate command changes. The `$(…)`
40
- * in it is EXPANDED before printing: handing an agent `--base=$(git merge-base origin/main HEAD)` is
41
- * handing it a template, and a template pasted where no shell expands it produces a confusing failure
42
- * that reads like the guard's advice was wrong. Only `$(git …)` is expanded, and only read-only git;
43
- * anything else is left verbatim.
44
- *
45
- * ─── EXPERIMENTAL, OFF by default, with ONE machine-local opt-in ───────────────────────────────────
46
- * `experimental.whole-repo-build-guard` in `~/.webpieces/config.json` is this guard's only switch, and
47
- * it is an OPT-IN: ON requires the explicit boolean `true`. Absent key, absent `experimental` section,
48
- * absent file, and an explicit `false` are ONE state, and that state is OFF.
49
- *
50
- * That direction is a standing policy, not a per-flag judgement: EVERY `experimental.*` flag in this
51
- * codebase ships OFF and stays OFF for two years. A flag that defaults ON is not an experiment — it is
52
- * a shipped behaviour that skipped its soak period, and it changes what every agent on every machine
53
- * can do the moment they upgrade. If few machines opt in, that is information about the experiment; it
54
- * is not a reason to force it on everybody.
55
- *
56
- * There is also NO webpieces.config.json entry, for a separate reason: a live incident. This guard
57
- * first shipped with `mode: 'ON'` by default AND a REQUIRED entry under `hookGuards`, and every
58
- * consumer that upgraded hit fault Y — EVERY Bash call blocked — for a feature they had never asked
59
- * for. The fault was the REQUIRED KEY: the failure was at config LOAD, before any command was judged,
60
- * and the cure was "edit a file to get your shell back". Keeping the switch in an OPTIONAL
61
- * machine-local file is what makes the default state need no file, no key and no edit.
62
- *
63
- * Three states, and only three:
64
- * - the file does not exist (essentially every machine), or exists without the key → the guard is
65
- * OFF, and inert: no block, no log, no message. Every key in that file is optional, because it is
66
- * MACHINE-GLOBAL and the repos on one machine pin different webpieces releases — a required key
67
- * there is unsatisfiable (see home-config.ts).
68
- * - the key is present → its boolean decides, and only `true` arms the guard.
69
- * - the file exists and is unparseable, or a key it DOES define has the wrong type → HARD FAILURE
70
- * naming the edit. That is a file somebody wrote wrongly, not one written for another release.
71
- * Editing that file is an unconditional PASS in the guards, so the block is always self-curable.
72
- *
73
- * ─── ONE message, because the gate now always captures ─────────────────────────────────────────────
74
- * There used to be two refusals here, chosen by `experimental.buildGateLogCapture`: one naming the
75
- * narrower build to run, and one saying "do not build at all — stage ② already builds and you can READ
76
- * the result". That key is gone, because capturing the build's full output to a file is no longer
77
- * optional. What survived is the FIRST of those, now carrying the log pointer the second one existed to
78
- * offer: a refusal still has to answer "so what do I run?", and "run nothing" is only an answer when the
79
- * caller was already inside the PR flow.
80
- *
81
- * ─── Humans are not affected, by construction ──────────────────────────────────────────────────────
82
- * This is a PreToolUse hook. It sees the AI's Bash tool calls and nothing else — a human typing
83
- * `pnpm run build-all` in their own terminal never reaches a hook, and the `build-all` script itself is
84
- * deliberately left in package.json for exactly that reason. The guard is about what the AI does in a
85
- * loop, not about the command being wrong for a person who chooses to run it once.
86
- */
87
- class WholeRepoBuildGuardRule extends rule_base_1.BashRuleBase {
88
- affectedBuildCommand;
89
- /**
90
- * `affectedBuildCommand` is the project's gate command (`commands.pr-gate.buildCommand`), handed in
91
- * by the runner off the loaded config. It is a CONSTRUCTOR ARGUMENT rather than a config field
92
- * because this guard has no config entry to read one from — and that is the point.
93
- */
94
- constructor(affectedBuildCommand) {
95
- // configKey === name and is DELIBERATELY not a real key: this guard has no
96
- // webpieces.config.json entry at all (see RETIRED_CONFIG_KEYS), and it is loaded outside the
97
- // config-driven set so the fault-Y sync check never sees it. Naming it here keeps the
98
- // AbstractRule contract honest without putting the string in HOOK_GUARD_NAMES.
99
- super(new rule_base_1.EmptyRuleConfig(), 'whole-repo-build-guard', 'whole-repo-build-guard');
100
- this.affectedBuildCommand = affectedBuildCommand;
101
- }
102
- scanner = new command_scan_1.CommandScanner();
103
- homeConfig = new rules_config_1.HomeConfigService();
104
- /** Set by check() when the home config is unreadable, so the fix hint names the same repair. */
105
- homeConfigError = '';
106
- description = 'Block a whole-monorepo build (build-all, an unnarrowed nx run-many, nx affected with no ' +
107
- '--base, a bare vitest run) and name the affected-scoped command to run instead.';
108
- /**
109
- * The command this rule last printed, so the fix hint and the violation message are one string and
110
- * cannot disagree. Empty until check() runs (fixHint is also read without it), at which point the
111
- * getter falls back to the configured TEMPLATE — never to a second literal, which is exactly the
112
- * drift this guard's own docstring says a duplicated command string causes.
113
- */
114
- resolvedCommand = '';
115
- get fixHint() {
116
- if (this.homeConfigError !== '') {
117
- return new fix_hint_1.FixHint('~/.webpieces/config.json exists but cannot be read.', 'Edit ~/.webpieces/config.json (editing it is always permitted, including right now), or ' +
118
- 'delete it outright — with no such file every webpieces command behaves exactly as it ' +
119
- 'does by default.');
120
- }
121
- const command = this.resolvedCommand !== '' ? this.resolvedCommand : this.buildCommandTemplate();
122
- return new fix_hint_1.FixHint('That command builds the WHOLE monorepo. Build only what your change affects.', 'Build the affected projects, or one project, or one spec file — never the workspace:\n' +
123
- ` pnpm wp-build # the gate's own build; runs: ${command}\n` +
124
- ' pnpm nx run <project>:ci # one project\n' +
125
- ' pnpm exec vitest run <path> # one suite\n' +
126
- 'This guard is OFF unless a machine opts in with "experimental": ' +
127
- '{ "whole-repo-build-guard": true } in ~/.webpieces/config.json — remove that line to turn ' +
128
- 'it off again (there is no webpieces.config.json entry for it).');
129
- }
130
- check(ctx) {
131
- const home = this.loadHome();
132
- // A file someone deliberately created must be correct — see the class docstring. Reported for
133
- // whatever command happens to be running, because a broken opt-in file is not a build question.
134
- if (home instanceof Error)
135
- return this.blockOnBrokenHomeConfig(ctx, home);
136
- // THE OPT-IN. False for every machine that has not said `true` out loud, including every machine
137
- // with no `~/.webpieces/config.json` at all. Being off is silent on purpose: no block, no log, no
138
- // file touched — the default must be indistinguishable from "this guard does not exist".
139
- this.homeConfigError = '';
140
- if (!home.wholeRepoBuildGuard)
141
- return [];
142
- // Blocklist-shaped, so match on commandCode: stripping heredocs and quoted prose can only ever
143
- // block LESS, and this repo's own commit messages are full of the command names above.
144
- const hit = new whole_repo_build_scan_1.WholeRepoBuildScan(this.scanner, ctx.effectiveCwd === ctx.workspaceRoot)
145
- .firstHit(ctx.commandCode);
146
- if (hit === null)
147
- return this.allow(ctx, 'not-a-whole-repo-build');
148
- // Resolved ONCE, here, and read by both the violation message and the fix hint.
149
- this.resolvedCommand = this.resolvedBuildCommand(ctx.workspaceRoot);
150
- return this.block(ctx, hit, this.message());
151
- }
152
- /**
153
- * The home config, or the Error explaining why it is unusable. NOT a boolean: "absent" is already
154
- * folded into the returned HomeConfig (each key's default — for this guard, OFF), so the only thing
155
- * left to distinguish is "present and wrong", which must be reported rather than swallowed.
156
- */
157
- loadHome() {
158
- // webpieces-disable no-unmanaged-exceptions -- chokepoint: a rejected home config is converted
159
- // into this guard's own block, which carries the loader's fix instruction verbatim
160
- // eslint-disable-next-line @webpieces/no-unmanaged-exceptions
161
- try {
162
- return this.homeConfig.load();
163
- }
164
- catch (err) {
165
- const error = (0, to_error_1.toError)(err);
166
- return error;
167
- }
168
- }
169
- blockOnBrokenHomeConfig(ctx, error) {
170
- this.homeConfigError = error.message;
171
- this.logDecision(ctx, 'BLOCK_AI_CURE', 'home-config-invalid');
172
- return [new types_1.Violation(1, this.truncate(ctx.command), this.brokenHomeConfigMessage(error))];
173
- }
174
- brokenHomeConfigMessage(error) {
175
- const detail = error instanceof tooling_common_1.InformAiError
176
- ? error.message
177
- : `~/.webpieces/config.json could not be read: ${error.message}`;
178
- return `Blocked: ~/.webpieces/config.json is present but unusable.\n\n${detail}`;
179
- }
180
- // The whole refusal. Short on purpose: it is read mid-task by an agent that needs the ONE command
181
- // to run next, and a guard message long enough to skim is a guard message that gets skimmed.
182
- //
183
- // `pnpm wp-build` FIRST, with the command it resolves to shown beside it. One thing to type, and it
184
- // runs `commands.pr-gate.buildCommand` through the gate's own resolver — so this refusal can never
185
- // teach a command the gate does not run, however the project reconfigures it.
186
- //
187
- // The log note is attached to the `wp-build` line ONLY, and that placement is the whole point. A
188
- // `FullLog :` pointer is written by `GateLogFile.pointer`, which is reachable solely through
189
- // `BuildGateLog` / `StageOutputLog` — i.e. through the gate. A bare `nx run <project>:ci` or
190
- // `vitest run <path>` writes no such file, so a blanket "whichever you run" claim would send an
191
- // agent to grep a path that does not exist while this same message forbids the re-run that is its
192
- // only remaining option. A cure that names an artifact the command does not produce is worse than
193
- // no cure at all.
194
- message() {
195
- return 'Blocked: that builds the WHOLE monorepo. Build only what your change affects:\n\n'
196
- + ` pnpm wp-build # runs: ${this.resolvedCommand}\n`
197
- + ' (its full output goes to a FILE — it prints "FullLog : <path>"; grep THAT instead of\n'
198
- + ' rebuilding. Never re-run a build to read a different slice of it.)\n\n'
199
- + 'Narrower still: pnpm nx run <project>:ci, or pnpm exec vitest run <path>.';
200
- }
201
- /**
202
- * The project's build command, unexpanded. ONE source: `commands.pr-gate.buildCommand`, handed to
203
- * the constructor by the runner, falling back to the same DEFAULT_BUILD_COMMAND the gate itself
204
- * falls back to. This guard never spells a build command of its own — a second copy is how a refusal
205
- * starts teaching a command the gate does not run.
206
- */
207
- buildCommandTemplate() {
208
- return this.affectedBuildCommand.trim() === '' ? rules_config_1.DEFAULT_BUILD_COMMAND : this.affectedBuildCommand;
209
- }
210
- /**
211
- * The configured build command with its `$(git …)` substitutions expanded, so what is printed is
212
- * runnable as-is. Expansion is limited to git, and any failure leaves the template untouched — a
213
- * guard may degrade its own message, never fail the tool call it is judging.
214
- */
215
- resolvedBuildCommand(workspaceRoot) {
216
- const template = this.buildCommandTemplate();
217
- return template.replace(/\$\(([^()]*)\)/g, (match, inner) => {
218
- const trimmed = inner.trim();
219
- if (!trimmed.startsWith('git '))
220
- return match;
221
- const output = this.capture(trimmed, workspaceRoot);
222
- return output === null ? match : output;
223
- });
224
- }
225
- capture(command, workspaceRoot) {
226
- // eslint-disable-next-line @webpieces/no-unmanaged-exceptions
227
- try {
228
- return (0, child_process_1.execSync)(command, {
229
- cwd: workspaceRoot, encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'],
230
- }).trim();
231
- }
232
- catch (err) {
233
- const error = (0, to_error_1.toError)(err);
234
- void error;
235
- return null;
236
- }
237
- }
238
- allow(ctx, reason) {
239
- this.logDecision(ctx, 'ALLOW', reason);
240
- return [];
241
- }
242
- block(ctx, hit, message) {
243
- // BLOCK_AI_CURE, not BLOCK_HUMAN: the cure is one command the agent runs itself, and the
244
- // refusal hands it over already resolved.
245
- this.logDecision(ctx, 'BLOCK_AI_CURE', hit.shape);
246
- return [new types_1.Violation(1, this.truncate(ctx.command), message)];
247
- }
248
- truncate(s) {
249
- const MAX = 120;
250
- return s.length <= MAX ? s : s.slice(0, MAX) + '…';
251
- }
252
- logDecision(ctx, verdict, reason) {
253
- (0, decision_log_1.logGuardDecision)(ctx.workspaceRoot, new decision_log_1.GuardDecision('whole-repo-build-guard', 'Bash', ctx.command, '-', verdict, reason, '-', l0_fault_codes_1.L0_FAULT_NONE, decision_log_1.MATRIX_L2_UNROWED));
254
- }
255
- }
256
- exports.WholeRepoBuildGuardRule = WholeRepoBuildGuardRule;
257
- //# sourceMappingURL=whole-repo-build-guard.js.map