@webpieces/ai-hook-rules 0.4.838 → 0.4.840

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (390) hide show
  1. package/README.md +12 -140
  2. package/package.json +7 -15
  3. package/src/adapters/hook-app-fixtures.d.ts +1 -1
  4. package/src/adapters/hook-app-fixtures.js +0 -8
  5. package/src/adapters/hook-app-fixtures.js.map +1 -1
  6. package/src/adapters/hook-core.d.ts +1 -21
  7. package/src/adapters/hook-core.js +22 -341
  8. package/src/adapters/hook-core.js.map +1 -1
  9. package/src/core/load-rules.d.ts +4 -39
  10. package/src/core/load-rules.js +15 -127
  11. package/src/core/load-rules.js.map +1 -1
  12. package/src/core/rules/catch-error-pattern.d.ts +3 -3
  13. package/src/core/rules/catch-error-pattern.js +13 -13
  14. package/src/core/rules/catch-error-pattern.js.map +1 -1
  15. package/src/core/rules/index.d.ts +1 -14
  16. package/src/core/rules/index.js +1 -17
  17. package/src/core/rules/index.js.map +1 -1
  18. package/src/core/rules/match-rule.d.ts +3 -3
  19. package/src/core/rules/match-rule.js +6 -6
  20. package/src/core/rules/match-rule.js.map +1 -1
  21. package/src/core/rules/max-file-lines.d.ts +3 -3
  22. package/src/core/rules/max-file-lines.js +7 -7
  23. package/src/core/rules/max-file-lines.js.map +1 -1
  24. package/src/core/rules/no-any-unknown.d.ts +3 -3
  25. package/src/core/rules/no-any-unknown.js +6 -6
  26. package/src/core/rules/no-any-unknown.js.map +1 -1
  27. package/src/core/rules/no-custom-css.d.ts +3 -3
  28. package/src/core/rules/no-custom-css.js +7 -7
  29. package/src/core/rules/no-custom-css.js.map +1 -1
  30. package/src/core/rules/no-destructure.d.ts +3 -3
  31. package/src/core/rules/no-destructure.js +7 -7
  32. package/src/core/rules/no-destructure.js.map +1 -1
  33. package/src/core/rules/no-implicit-any.d.ts +3 -3
  34. package/src/core/rules/no-implicit-any.js +6 -6
  35. package/src/core/rules/no-implicit-any.js.map +1 -1
  36. package/src/core/rules/no-js-files.d.ts +3 -3
  37. package/src/core/rules/no-js-files.js +6 -6
  38. package/src/core/rules/no-js-files.js.map +1 -1
  39. package/src/core/rules/no-process-exit-outside-main.d.ts +3 -3
  40. package/src/core/rules/no-process-exit-outside-main.js +7 -7
  41. package/src/core/rules/no-process-exit-outside-main.js.map +1 -1
  42. package/src/core/rules/no-symbol-di-tokens.d.ts +3 -3
  43. package/src/core/rules/no-symbol-di-tokens.js +7 -7
  44. package/src/core/rules/no-symbol-di-tokens.js.map +1 -1
  45. package/src/core/rules/no-unmanaged-exceptions.d.ts +3 -3
  46. package/src/core/rules/no-unmanaged-exceptions.js +9 -9
  47. package/src/core/rules/no-unmanaged-exceptions.js.map +1 -1
  48. package/src/core/rules/require-return-type.d.ts +3 -3
  49. package/src/core/rules/require-return-type.js +6 -6
  50. package/src/core/rules/require-return-type.js.map +1 -1
  51. package/src/core/rules/throw-cause-required.d.ts +3 -3
  52. package/src/core/rules/throw-cause-required.js +9 -9
  53. package/src/core/rules/throw-cause-required.js.map +1 -1
  54. package/src/core/rules/validate-ts-in-src.d.ts +3 -3
  55. package/src/core/rules/validate-ts-in-src.js +7 -7
  56. package/src/core/rules/validate-ts-in-src.js.map +1 -1
  57. package/src/core/runner.d.ts +10 -19
  58. package/src/core/runner.js +24 -622
  59. package/src/core/runner.js.map +1 -1
  60. package/src/index.d.ts +2 -15
  61. package/src/index.js +4 -54
  62. package/src/index.js.map +1 -1
  63. package/openclaw.plugin.json +0 -15
  64. package/src/adapters/agent-adapters.d.ts +0 -13
  65. package/src/adapters/agent-adapters.js +0 -23
  66. package/src/adapters/agent-adapters.js.map +0 -1
  67. package/src/adapters/agent-payload.d.ts +0 -48
  68. package/src/adapters/agent-payload.js +0 -30
  69. package/src/adapters/agent-payload.js.map +0 -1
  70. package/src/adapters/agent-response.d.ts +0 -5
  71. package/src/adapters/agent-response.js +0 -86
  72. package/src/adapters/agent-response.js.map +0 -1
  73. package/src/adapters/claude-code-adapter.d.ts +0 -26
  74. package/src/adapters/claude-code-adapter.js +0 -69
  75. package/src/adapters/claude-code-adapter.js.map +0 -1
  76. package/src/adapters/codex-adapter.d.ts +0 -19
  77. package/src/adapters/codex-adapter.js +0 -48
  78. package/src/adapters/codex-adapter.js.map +0 -1
  79. package/src/adapters/codex-subagent-guard.d.ts +0 -45
  80. package/src/adapters/codex-subagent-guard.js +0 -88
  81. package/src/adapters/codex-subagent-guard.js.map +0 -1
  82. package/src/adapters/detect-ai.d.ts +0 -70
  83. package/src/adapters/detect-ai.js +0 -82
  84. package/src/adapters/detect-ai.js.map +0 -1
  85. package/src/adapters/guards-hook.d.ts +0 -3
  86. package/src/adapters/guards-hook.js +0 -30
  87. package/src/adapters/guards-hook.js.map +0 -1
  88. package/src/adapters/openclaw-plugin.d.ts +0 -14
  89. package/src/adapters/openclaw-plugin.js +0 -87
  90. package/src/adapters/openclaw-plugin.js.map +0 -1
  91. package/src/adapters/review-identity-stamper.d.ts +0 -20
  92. package/src/adapters/review-identity-stamper.js +0 -34
  93. package/src/adapters/review-identity-stamper.js.map +0 -1
  94. package/src/bin/codex-trust.d.ts +0 -105
  95. package/src/bin/codex-trust.js +0 -205
  96. package/src/bin/codex-trust.js.map +0 -1
  97. package/src/bin/dev-hook-install.d.ts +0 -1
  98. package/src/bin/dev-hook-install.js +0 -82
  99. package/src/bin/dev-hook-install.js.map +0 -1
  100. package/src/bin/dev-hook-uninstall.d.ts +0 -1
  101. package/src/bin/dev-hook-uninstall.js +0 -45
  102. package/src/bin/dev-hook-uninstall.js.map +0 -1
  103. package/src/bin/hook-registration.d.ts +0 -429
  104. package/src/bin/hook-registration.js +0 -661
  105. package/src/bin/hook-registration.js.map +0 -1
  106. package/src/bin/install-entry.d.ts +0 -19
  107. package/src/bin/install-entry.js +0 -128
  108. package/src/bin/install-entry.js.map +0 -1
  109. package/src/bin/l0-allowlist.d.ts +0 -49
  110. package/src/bin/l0-allowlist.js +0 -528
  111. package/src/bin/l0-allowlist.js.map +0 -1
  112. package/src/bin/l0-codex-read.d.ts +0 -21
  113. package/src/bin/l0-codex-read.js +0 -109
  114. package/src/bin/l0-codex-read.js.map +0 -1
  115. package/src/bin/l0-decide.d.ts +0 -50
  116. package/src/bin/l0-decide.js +0 -103
  117. package/src/bin/l0-decide.js.map +0 -1
  118. package/src/bin/l0-entry.d.ts +0 -103
  119. package/src/bin/l0-entry.js +0 -98
  120. package/src/bin/l0-entry.js.map +0 -1
  121. package/src/bin/l0-ignored-tools.d.ts +0 -38
  122. package/src/bin/l0-ignored-tools.js +0 -44
  123. package/src/bin/l0-ignored-tools.js.map +0 -1
  124. package/src/bin/managed-env.d.ts +0 -46
  125. package/src/bin/managed-env.js +0 -50
  126. package/src/bin/managed-env.js.map +0 -1
  127. package/src/bin/neighbour-hooks.d.ts +0 -42
  128. package/src/bin/neighbour-hooks.js +0 -177
  129. package/src/bin/neighbour-hooks.js.map +0 -1
  130. package/src/bin/reviewer-agent.d.ts +0 -19
  131. package/src/bin/reviewer-agent.js +0 -135
  132. package/src/bin/reviewer-agent.js.map +0 -1
  133. package/src/bin/settings-shape.d.ts +0 -37
  134. package/src/bin/settings-shape.js +0 -17
  135. package/src/bin/settings-shape.js.map +0 -1
  136. package/src/bin/setup-config.d.ts +0 -19
  137. package/src/bin/setup-config.js +0 -370
  138. package/src/bin/setup-config.js.map +0 -1
  139. package/src/bin/setup.d.ts +0 -78
  140. package/src/bin/setup.js +0 -400
  141. package/src/bin/setup.js.map +0 -1
  142. package/src/bin/shim-audit-log.d.ts +0 -119
  143. package/src/bin/shim-audit-log.js +0 -286
  144. package/src/bin/shim-audit-log.js.map +0 -1
  145. package/src/bin/shim-deny-reason.d.ts +0 -1
  146. package/src/bin/shim-deny-reason.js +0 -244
  147. package/src/bin/shim-deny-reason.js.map +0 -1
  148. package/src/bin/shim-drift-fix.d.ts +0 -1
  149. package/src/bin/shim-drift-fix.js +0 -72
  150. package/src/bin/shim-drift-fix.js.map +0 -1
  151. package/src/bin/shim-testkit.d.ts +0 -107
  152. package/src/bin/shim-testkit.js +0 -197
  153. package/src/bin/shim-testkit.js.map +0 -1
  154. package/src/bin/shim-version-drift.d.ts +0 -1
  155. package/src/bin/shim-version-drift.js +0 -164
  156. package/src/bin/shim-version-drift.js.map +0 -1
  157. package/src/bin/shim.d.ts +0 -16
  158. package/src/bin/shim.js +0 -636
  159. package/src/bin/shim.js.map +0 -1
  160. package/src/bin/upgrade-shim.d.ts +0 -18
  161. package/src/bin/upgrade-shim.js +0 -283
  162. package/src/bin/upgrade-shim.js.map +0 -1
  163. package/src/core/ai-type-context.d.ts +0 -36
  164. package/src/core/ai-type-context.js +0 -45
  165. package/src/core/ai-type-context.js.map +0 -1
  166. package/src/core/apply-patch-parse.d.ts +0 -36
  167. package/src/core/apply-patch-parse.js +0 -154
  168. package/src/core/apply-patch-parse.js.map +0 -1
  169. package/src/core/build-context.d.ts +0 -10
  170. package/src/core/build-context.js +0 -66
  171. package/src/core/build-context.js.map +0 -1
  172. package/src/core/command-scan.d.ts +0 -122
  173. package/src/core/command-scan.js +0 -282
  174. package/src/core/command-scan.js.map +0 -1
  175. package/src/core/custom-rule-adapter.d.ts +0 -22
  176. package/src/core/custom-rule-adapter.js +0 -50
  177. package/src/core/custom-rule-adapter.js.map +0 -1
  178. package/src/core/decision-log.d.ts +0 -190
  179. package/src/core/decision-log.js +0 -406
  180. package/src/core/decision-log.js.map +0 -1
  181. package/src/core/delete-scoped-rules.d.ts +0 -8
  182. package/src/core/delete-scoped-rules.js +0 -31
  183. package/src/core/delete-scoped-rules.js.map +0 -1
  184. package/src/core/disable-directives.d.ts +0 -8
  185. package/src/core/disable-directives.js +0 -80
  186. package/src/core/disable-directives.js.map +0 -1
  187. package/src/core/effective-tree.d.ts +0 -204
  188. package/src/core/effective-tree.js +0 -277
  189. package/src/core/effective-tree.js.map +0 -1
  190. package/src/core/excluded-path-escape.d.ts +0 -101
  191. package/src/core/excluded-path-escape.js +0 -236
  192. package/src/core/excluded-path-escape.js.map +0 -1
  193. package/src/core/excluded-paths.d.ts +0 -23
  194. package/src/core/excluded-paths.js +0 -54
  195. package/src/core/excluded-paths.js.map +0 -1
  196. package/src/core/fix-hint.d.ts +0 -40
  197. package/src/core/fix-hint.js +0 -53
  198. package/src/core/fix-hint.js.map +0 -1
  199. package/src/core/force-to-root.d.ts +0 -32
  200. package/src/core/force-to-root.js +0 -60
  201. package/src/core/force-to-root.js.map +0 -1
  202. package/src/core/guard-index-doc.d.ts +0 -63
  203. package/src/core/guard-index-doc.js +0 -172
  204. package/src/core/guard-index-doc.js.map +0 -1
  205. package/src/core/instruct-ai-writer.d.ts +0 -1
  206. package/src/core/instruct-ai-writer.js +0 -6
  207. package/src/core/instruct-ai-writer.js.map +0 -1
  208. package/src/core/l0-fault-codes.d.ts +0 -85
  209. package/src/core/l0-fault-codes.js +0 -121
  210. package/src/core/l0-fault-codes.js.map +0 -1
  211. package/src/core/l0-matrix.d.ts +0 -114
  212. package/src/core/l0-matrix.js +0 -416
  213. package/src/core/l0-matrix.js.map +0 -1
  214. package/src/core/l0-tooling-doc.d.ts +0 -45
  215. package/src/core/l0-tooling-doc.js +0 -258
  216. package/src/core/l0-tooling-doc.js.map +0 -1
  217. package/src/core/l1-doc.d.ts +0 -7
  218. package/src/core/l1-doc.js +0 -340
  219. package/src/core/l1-doc.js.map +0 -1
  220. package/src/core/l1-matrix-doc.d.ts +0 -31
  221. package/src/core/l1-matrix-doc.js +0 -111
  222. package/src/core/l1-matrix-doc.js.map +0 -1
  223. package/src/core/l1-rows.d.ts +0 -167
  224. package/src/core/l1-rows.js +0 -262
  225. package/src/core/l1-rows.js.map +0 -1
  226. package/src/core/l2-doc.d.ts +0 -7
  227. package/src/core/l2-doc.js +0 -385
  228. package/src/core/l2-doc.js.map +0 -1
  229. package/src/core/l2-matrix-doc.d.ts +0 -23
  230. package/src/core/l2-matrix-doc.js +0 -72
  231. package/src/core/l2-matrix-doc.js.map +0 -1
  232. package/src/core/l2-row.d.ts +0 -54
  233. package/src/core/l2-row.js +0 -75
  234. package/src/core/l2-row.js.map +0 -1
  235. package/src/core/l2-rows.d.ts +0 -56
  236. package/src/core/l2-rows.js +0 -272
  237. package/src/core/l2-rows.js.map +0 -1
  238. package/src/core/load-config.d.ts +0 -1
  239. package/src/core/load-config.js +0 -9
  240. package/src/core/load-config.js.map +0 -1
  241. package/src/core/log-stream.d.ts +0 -117
  242. package/src/core/log-stream.js +0 -156
  243. package/src/core/log-stream.js.map +0 -1
  244. package/src/core/log-streams.d.ts +0 -48
  245. package/src/core/log-streams.js +0 -55
  246. package/src/core/log-streams.js.map +0 -1
  247. package/src/core/log-target.d.ts +0 -21
  248. package/src/core/log-target.js +0 -29
  249. package/src/core/log-target.js.map +0 -1
  250. package/src/core/main-sync-log.d.ts +0 -16
  251. package/src/core/main-sync-log.js +0 -105
  252. package/src/core/main-sync-log.js.map +0 -1
  253. package/src/core/main-sync-refresh.d.ts +0 -39
  254. package/src/core/main-sync-refresh.js +0 -96
  255. package/src/core/main-sync-refresh.js.map +0 -1
  256. package/src/core/main-sync-timeout.d.ts +0 -32
  257. package/src/core/main-sync-timeout.js +0 -94
  258. package/src/core/main-sync-timeout.js.map +0 -1
  259. package/src/core/matrix-cures.d.ts +0 -12
  260. package/src/core/matrix-cures.js +0 -56
  261. package/src/core/matrix-cures.js.map +0 -1
  262. package/src/core/missing-directory.d.ts +0 -38
  263. package/src/core/missing-directory.js +0 -66
  264. package/src/core/missing-directory.js.map +0 -1
  265. package/src/core/read-only-inspection.d.ts +0 -34
  266. package/src/core/read-only-inspection.js +0 -88
  267. package/src/core/read-only-inspection.js.map +0 -1
  268. package/src/core/rejection-log.d.ts +0 -9
  269. package/src/core/rejection-log.js +0 -258
  270. package/src/core/rejection-log.js.map +0 -1
  271. package/src/core/report.d.ts +0 -21
  272. package/src/core/report.js +0 -73
  273. package/src/core/report.js.map +0 -1
  274. package/src/core/rule-base.d.ts +0 -39
  275. package/src/core/rule-base.js +0 -36
  276. package/src/core/rule-base.js.map +0 -1
  277. package/src/core/rules/branch-creation-guard.d.ts +0 -113
  278. package/src/core/rules/branch-creation-guard.js +0 -422
  279. package/src/core/rules/branch-creation-guard.js.map +0 -1
  280. package/src/core/rules/branch-switch-scan.d.ts +0 -43
  281. package/src/core/rules/branch-switch-scan.js +0 -132
  282. package/src/core/rules/branch-switch-scan.js.map +0 -1
  283. package/src/core/rules/build-output-pipe-guard.d.ts +0 -56
  284. package/src/core/rules/build-output-pipe-guard.js +0 -120
  285. package/src/core/rules/build-output-pipe-guard.js.map +0 -1
  286. package/src/core/rules/build-output-pipe-scan.d.ts +0 -47
  287. package/src/core/rules/build-output-pipe-scan.js +0 -84
  288. package/src/core/rules/build-output-pipe-scan.js.map +0 -1
  289. package/src/core/rules/cap-remedies.d.ts +0 -39
  290. package/src/core/rules/cap-remedies.js +0 -59
  291. package/src/core/rules/cap-remedies.js.map +0 -1
  292. package/src/core/rules/commit-message-substitution-guard.d.ts +0 -72
  293. package/src/core/rules/commit-message-substitution-guard.js +0 -134
  294. package/src/core/rules/commit-message-substitution-guard.js.map +0 -1
  295. package/src/core/rules/commit-message-substitution-scan.d.ts +0 -42
  296. package/src/core/rules/commit-message-substitution-scan.js +0 -145
  297. package/src/core/rules/commit-message-substitution-scan.js.map +0 -1
  298. package/src/core/rules/content-read-scan.d.ts +0 -76
  299. package/src/core/rules/content-read-scan.js +0 -176
  300. package/src/core/rules/content-read-scan.js.map +0 -1
  301. package/src/core/rules/cure-prefix-scan.d.ts +0 -64
  302. package/src/core/rules/cure-prefix-scan.js +0 -133
  303. package/src/core/rules/cure-prefix-scan.js.map +0 -1
  304. package/src/core/rules/feature-branch-guard.d.ts +0 -121
  305. package/src/core/rules/feature-branch-guard.js +0 -326
  306. package/src/core/rules/feature-branch-guard.js.map +0 -1
  307. package/src/core/rules/judged-tree.d.ts +0 -66
  308. package/src/core/rules/judged-tree.js +0 -97
  309. package/src/core/rules/judged-tree.js.map +0 -1
  310. package/src/core/rules/main-freshness.d.ts +0 -37
  311. package/src/core/rules/main-freshness.js +0 -61
  312. package/src/core/rules/main-freshness.js.map +0 -1
  313. package/src/core/rules/merge-in-progress-guard.d.ts +0 -17
  314. package/src/core/rules/merge-in-progress-guard.js +0 -122
  315. package/src/core/rules/merge-in-progress-guard.js.map +0 -1
  316. package/src/core/rules/merged-branch-bash-guard.d.ts +0 -62
  317. package/src/core/rules/merged-branch-bash-guard.js +0 -170
  318. package/src/core/rules/merged-branch-bash-guard.js.map +0 -1
  319. package/src/core/rules/merged-branch-message.d.ts +0 -59
  320. package/src/core/rules/merged-branch-message.js +0 -137
  321. package/src/core/rules/merged-branch-message.js.map +0 -1
  322. package/src/core/rules/pr-creation-or-push-guard.d.ts +0 -26
  323. package/src/core/rules/pr-creation-or-push-guard.js +0 -146
  324. package/src/core/rules/pr-creation-or-push-guard.js.map +0 -1
  325. package/src/core/rules/pr-merge-guard.d.ts +0 -36
  326. package/src/core/rules/pr-merge-guard.js +0 -86
  327. package/src/core/rules/pr-merge-guard.js.map +0 -1
  328. package/src/core/rules/read-stale-guard.d.ts +0 -136
  329. package/src/core/rules/read-stale-guard.js +0 -326
  330. package/src/core/rules/read-stale-guard.js.map +0 -1
  331. package/src/core/rules/recovery-allowlist.d.ts +0 -49
  332. package/src/core/rules/recovery-allowlist.js +0 -187
  333. package/src/core/rules/recovery-allowlist.js.map +0 -1
  334. package/src/core/rules/redirect-how-to-merge-main.d.ts +0 -16
  335. package/src/core/rules/redirect-how-to-merge-main.js +0 -157
  336. package/src/core/rules/redirect-how-to-merge-main.js.map +0 -1
  337. package/src/core/rules/shell-segment-scan.d.ts +0 -64
  338. package/src/core/rules/shell-segment-scan.js +0 -88
  339. package/src/core/rules/shell-segment-scan.js.map +0 -1
  340. package/src/core/rules/stale-main-bash-guard.d.ts +0 -198
  341. package/src/core/rules/stale-main-bash-guard.js +0 -361
  342. package/src/core/rules/stale-main-bash-guard.js.map +0 -1
  343. package/src/core/rules/stale-main-message.d.ts +0 -62
  344. package/src/core/rules/stale-main-message.js +0 -102
  345. package/src/core/rules/stale-main-message.js.map +0 -1
  346. package/src/core/rules/tree-recovery.d.ts +0 -92
  347. package/src/core/rules/tree-recovery.js +0 -165
  348. package/src/core/rules/tree-recovery.js.map +0 -1
  349. package/src/core/rules/wait-spin-guard.d.ts +0 -128
  350. package/src/core/rules/wait-spin-guard.js +0 -211
  351. package/src/core/rules/wait-spin-guard.js.map +0 -1
  352. package/src/core/rules/wait-spin-scan.d.ts +0 -118
  353. package/src/core/rules/wait-spin-scan.js +0 -203
  354. package/src/core/rules/wait-spin-scan.js.map +0 -1
  355. package/src/core/rules/whole-repo-build-guard.d.ts +0 -125
  356. package/src/core/rules/whole-repo-build-guard.js +0 -257
  357. package/src/core/rules/whole-repo-build-guard.js.map +0 -1
  358. package/src/core/rules/whole-repo-build-scan.d.ts +0 -28
  359. package/src/core/rules/whole-repo-build-scan.js +0 -198
  360. package/src/core/rules/whole-repo-build-scan.js.map +0 -1
  361. package/src/core/session-call-history.d.ts +0 -44
  362. package/src/core/session-call-history.js +0 -79
  363. package/src/core/session-call-history.js.map +0 -1
  364. package/src/core/shell-read-parity.d.ts +0 -56
  365. package/src/core/shell-read-parity.js +0 -155
  366. package/src/core/shell-read-parity.js.map +0 -1
  367. package/src/core/strip-ts-noise.d.ts +0 -1
  368. package/src/core/strip-ts-noise.js +0 -185
  369. package/src/core/strip-ts-noise.js.map +0 -1
  370. package/src/core/sync-main.d.ts +0 -46
  371. package/src/core/sync-main.js +0 -175
  372. package/src/core/sync-main.js.map +0 -1
  373. package/src/core/target-tree.d.ts +0 -84
  374. package/src/core/target-tree.js +0 -148
  375. package/src/core/target-tree.js.map +0 -1
  376. package/src/core/to-error.d.ts +0 -5
  377. package/src/core/to-error.js +0 -37
  378. package/src/core/to-error.js.map +0 -1
  379. package/src/core/types.d.ts +0 -152
  380. package/src/core/types.js +0 -200
  381. package/src/core/types.js.map +0 -1
  382. package/src/core/version-sync.d.ts +0 -219
  383. package/src/core/version-sync.js +0 -558
  384. package/src/core/version-sync.js.map +0 -1
  385. package/src/core/webpieces-versions.d.ts +0 -98
  386. package/src/core/webpieces-versions.js +0 -206
  387. package/src/core/webpieces-versions.js.map +0 -1
  388. package/templates/ai-hook.sh +0 -497
  389. package/templates/claude-settings-hook.json +0 -28
  390. package/templates/webpieces-reviewer.md +0 -60
@@ -1,59 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CapRemedies = void 0;
4
- const fix_hint_1 = require("../fix-hint");
5
- const rules_config_1 = require("@webpieces/rules-config");
6
- /**
7
- * What branch-creation-guard says when a CAP is what blocked. TWO SHORT LINES, and never a
8
- * destructive command.
9
- *
10
- * It used to be forty. The branch remedy printed every spared branch with its SHA, PR state, unique
11
- * commit count and prose reason, told the agent to paste that table at the human and ask which may
12
- * go, and then listed the config knobs it must not touch. The human's verdict on that, verbatim:
13
- * "I am tired of AI asking me to cleanup things it can do by itself". They were right twice over —
14
- * the wall of text buried the one actionable line, and the biggest spared group (pre-merge snapshots
15
- * of a branch that still exists) was never a judgement call at all. That group is auto-reaped now
16
- * (see CLASSIFICATION_BACKUP_OF_LIVE), so the remedy is one command.
17
- *
18
- * Everything this class used to say still exists — in `pnpm wp-cleanup`, which recomputes the
19
- * verdicts fresh, archives each branch as an `archive/<date>/<branch>` tag before deleting, logs a
20
- * `recover=` command per removal, refuses the primary clone and the tree it is standing in, never
21
- * passes `--force`, and PROMPTS about anything not provably dead. A guard that duplicates that
22
- * inventory is a second copy to keep in sync and a wall to read before running the command anyway.
23
- * So: name the command, stop talking.
24
- */
25
- class CapRemedies {
26
- /**
27
- * Deliberately takes no cache and quotes no figures. The cache is allowed to be stale by design,
28
- * and a stale table is worse than no table when the reader's next move is `wp-cleanup` — which
29
- * recomputes from scratch — either way.
30
- *
31
- * "ASK THE HUMAN" stays spelled out. Shortening it to a bare "ask" saves two words and loses the
32
- * object of the verb — and the reader is an agent, which can satisfy a bare "ask" by asking
33
- * itself. Every other guard in this codebase says ASK THE HUMAN for the same reason.
34
- */
35
- branchCap() {
36
- return new fix_hint_1.FixHint('Too many local branches.', '', [
37
- new rules_config_1.Option('Run: pnpm wp-cleanup — reaps the dead branches and the zero-commit husks.', true),
38
- new rules_config_1.Option('Only if that leaves you at the cap: ASK THE HUMAN which of the branches it spared ' +
39
- 'may go. Never delete a spared branch or edit webpieces.config.json ' +
40
- '(maxLocalBranches / turnOffRuleUntilEpoch) without their explicit yes.'),
41
- ]);
42
- }
43
- /**
44
- * Same shape for worktrees, with one extra sentence that is not boilerplate: a worktree whose
45
- * branch has no commits yet is almost always one an agent is working in RIGHT NOW. That is why
46
- * this never emits `git worktree remove` — it once printed a `prune && remove && branch -D` chain
47
- * naming three live worktrees under the words "so no work can be lost".
48
- */
49
- worktreeCap() {
50
- return new fix_hint_1.FixHint('Too many worktrees. Do NOT remove one by hand — an agent may be working in it right now.', '', [
51
- new rules_config_1.Option('Run: pnpm wp-cleanup — removes the dead worktrees and the unheld husks.', true),
52
- new rules_config_1.Option('Only if that leaves you at the cap: ASK THE HUMAN which of the worktrees it spared ' +
53
- 'may go. Never edit webpieces.config.json (maxWorktrees / turnOffRuleUntilEpoch) ' +
54
- 'without their explicit yes.'),
55
- ]);
56
- }
57
- }
58
- exports.CapRemedies = CapRemedies;
59
- //# sourceMappingURL=cap-remedies.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cap-remedies.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/ai-hook-rules/src/core/rules/cap-remedies.ts"],"names":[],"mappings":";;;AAAA,0CAAsC;AACtC,0DAAiD;AAEjD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAa,WAAW;IACpB;;;;;;;;OAQG;IACH,SAAS;QACL,OAAO,IAAI,kBAAO,CACd,0BAA0B,EAC1B,EAAE,EACF;YACI,IAAI,qBAAM,CAAC,2EAA2E,EAAE,IAAI,CAAC;YAC7F,IAAI,qBAAM,CACN,oFAAoF;gBACpF,qEAAqE;gBACrE,wEAAwE,CAC3E;SACJ,CACJ,CAAC;IACN,CAAC;IAED;;;;;OAKG;IACH,WAAW;QACP,OAAO,IAAI,kBAAO,CACd,0FAA0F,EAC1F,EAAE,EACF;YACI,IAAI,qBAAM,CAAC,yEAAyE,EAAE,IAAI,CAAC;YAC3F,IAAI,qBAAM,CACN,qFAAqF;gBACrF,kFAAkF;gBAClF,6BAA6B,CAChC;SACJ,CACJ,CAAC;IACN,CAAC;CACJ;AA7CD,kCA6CC","sourcesContent":["import { FixHint } from '../fix-hint';\nimport { Option } from '@webpieces/rules-config';\n\n/**\n * What branch-creation-guard says when a CAP is what blocked. TWO SHORT LINES, and never a\n * destructive command.\n *\n * It used to be forty. The branch remedy printed every spared branch with its SHA, PR state, unique\n * commit count and prose reason, told the agent to paste that table at the human and ask which may\n * go, and then listed the config knobs it must not touch. The human's verdict on that, verbatim:\n * \"I am tired of AI asking me to cleanup things it can do by itself\". They were right twice over —\n * the wall of text buried the one actionable line, and the biggest spared group (pre-merge snapshots\n * of a branch that still exists) was never a judgement call at all. That group is auto-reaped now\n * (see CLASSIFICATION_BACKUP_OF_LIVE), so the remedy is one command.\n *\n * Everything this class used to say still exists — in `pnpm wp-cleanup`, which recomputes the\n * verdicts fresh, archives each branch as an `archive/<date>/<branch>` tag before deleting, logs a\n * `recover=` command per removal, refuses the primary clone and the tree it is standing in, never\n * passes `--force`, and PROMPTS about anything not provably dead. A guard that duplicates that\n * inventory is a second copy to keep in sync and a wall to read before running the command anyway.\n * So: name the command, stop talking.\n */\nexport class CapRemedies {\n /**\n * Deliberately takes no cache and quotes no figures. The cache is allowed to be stale by design,\n * and a stale table is worse than no table when the reader's next move is `wp-cleanup` — which\n * recomputes from scratch — either way.\n *\n * \"ASK THE HUMAN\" stays spelled out. Shortening it to a bare \"ask\" saves two words and loses the\n * object of the verb — and the reader is an agent, which can satisfy a bare \"ask\" by asking\n * itself. Every other guard in this codebase says ASK THE HUMAN for the same reason.\n */\n branchCap(): FixHint {\n return new FixHint(\n 'Too many local branches.',\n '',\n [\n new Option('Run: pnpm wp-cleanup — reaps the dead branches and the zero-commit husks.', true),\n new Option(\n 'Only if that leaves you at the cap: ASK THE HUMAN which of the branches it spared ' +\n 'may go. Never delete a spared branch or edit webpieces.config.json ' +\n '(maxLocalBranches / turnOffRuleUntilEpoch) without their explicit yes.',\n ),\n ],\n );\n }\n\n /**\n * Same shape for worktrees, with one extra sentence that is not boilerplate: a worktree whose\n * branch has no commits yet is almost always one an agent is working in RIGHT NOW. That is why\n * this never emits `git worktree remove` — it once printed a `prune && remove && branch -D` chain\n * naming three live worktrees under the words \"so no work can be lost\".\n */\n worktreeCap(): FixHint {\n return new FixHint(\n 'Too many worktrees. Do NOT remove one by hand — an agent may be working in it right now.',\n '',\n [\n new Option('Run: pnpm wp-cleanup — removes the dead worktrees and the unheld husks.', true),\n new Option(\n 'Only if that leaves you at the cap: ASK THE HUMAN which of the worktrees it spared ' +\n 'may go. Never edit webpieces.config.json (maxWorktrees / turnOffRuleUntilEpoch) ' +\n 'without their explicit yes.',\n ),\n ],\n );\n }\n}\n"]}
@@ -1,72 +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 `git commit` whose message is passed INLINE (`-m` / `--message` / `-am`) when that message
6
- * contains a backtick, a `$(`, or a newline — and hands back `git commit -F <file>` instead.
7
- *
8
- * ─── The incident: a commit message that HUNG for ten minutes, twice ───────────────────────────────
9
- * An agent ran `git commit -q -m "…"` with a multi-paragraph message that happened to contain the
10
- * sentence: *"… `strings` on a .app built with --port 8084 contains no 8084."* The backticks are
11
- * COMMAND SUBSTITUTION. The shell ran `strings` with no arguments, `strings` read stdin, and stdin
12
- * never closed. The Bash tool SIGTERM'd it at its ten-minute cap. The retry kept the same sentence and
13
- * did it again — twenty minutes for one commit.
14
- *
15
- * ─── Why this is a GUARD and not a doc line ────────────────────────────────────────────────────────
16
- * The agent then diagnosed it as "a guard caught a commit message that quoting a blocked command",
17
- * citing an unrelated deploy-guard note. Three facts settle that it was nothing of the kind, and they
18
- * are worth writing down because they are the reason the cure has to arrive BEFORE execution:
19
- *
20
- * - a PreToolUse guard denies INSTANTLY, before the command runs. This ran for ten minutes.
21
- * - `Exit code 143` is SIGTERM delivered to a RUNNING process, not a refusal.
22
- * - the first attempt was `git add -A && git commit -m "…"`, and afterwards the 45 files were
23
- * STAGED — so the command really executed, and then blocked while expanding its second word.
24
- *
25
- * A footnote in a doc could not have reached that agent at that moment; a refusal naming `-F` does.
26
- *
27
- * ─── The trigger is the METACHARACTER, never the words ─────────────────────────────────────────────
28
- * A message is PROSE, and prose goes through the shell's expansion rules whether or not it is meant
29
- * to. A blocklist of "dangerous commands" would have missed this entirely — `strings` is an ordinary
30
- * word, and the next hang will name an ordinary word too. So the rule matches backtick, `$(` and a
31
- * newline inside the message argument, and reads nothing at all into the surrounding sentence.
32
- *
33
- * ─── It fires on a SINGLE-QUOTED message too, and that is deliberate ───────────────────────────────
34
- * `git commit -m 'a `backtick` here'` is, strictly, safe: single quotes suppress substitution, so the
35
- * shell would pass those backticks through literally. This guard blocks it anyway, and the false
36
- * positive is the point rather than an oversight — do not "fix" it. Two reasons:
37
- *
38
- * - single-quoting PROSE is fragile in the one way that matters. An English sentence eventually
39
- * contains an apostrophe ("doesn't", "the agent's"), which CLOSES the quote mid-message and drops
40
- * the rest of the sentence back into the shell's syntax — the exact state this guard exists to
41
- * prevent, reached by a message that looked safe when it was written.
42
- * - the cure is free. `-F` costs one Write tool call and works for every message, so being wrong
43
- * here spends seconds, while being right saves twenty minutes. A guard chooses its errors by what
44
- * each one COSTS, and these two costs are not close.
45
- *
46
- * `blocks a single-quoted message too` in the spec pins this, so a later reader meets the decision as
47
- * a failing test rather than as a bug report.
48
- *
49
- * ─── It matches the RAW command, and that is load-bearing ──────────────────────────────────────────
50
- * Every other bash guard here matches `ctx.commandCode`, which STRIPS heredoc bodies and quoted prose
51
- * precisely so a commit message merely MENTIONING `git push` is not read as a push. That stripping
52
- * deletes exactly the span this rule exists to inspect: on `commandCode` the message is already gone,
53
- * and the guard would be permanently blind. So it reads `ctx.command`.
54
- *
55
- * That is safe here because the rule is still blocklist-shaped and its cure can never itself be
56
- * blocked: `-F` writes the message to a file and passes a PATH, so nothing about the message text can
57
- * make the replacement command match this guard. There is no input for which an agent is left with no
58
- * accepted spelling.
59
- */
60
- export declare class CommitMessageSubstitutionGuardRule extends BashRuleBase<EmptyRuleConfig> {
61
- constructor();
62
- private readonly scan;
63
- readonly description: string;
64
- get fixHint(): FixHint;
65
- check(ctx: BashContext): readonly Violation[];
66
- private allow;
67
- private block;
68
- private message;
69
- private what;
70
- private truncate;
71
- private logDecision;
72
- }
@@ -1,134 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CommitMessageSubstitutionGuardRule = void 0;
4
- const rules_config_1 = require("@webpieces/rules-config");
5
- const types_1 = require("../types");
6
- const rule_base_1 = require("../rule-base");
7
- const fix_hint_1 = require("../fix-hint");
8
- const l0_fault_codes_1 = require("../l0-fault-codes");
9
- const decision_log_1 = require("../decision-log");
10
- const command_scan_1 = require("../command-scan");
11
- const commit_message_substitution_scan_1 = require("./commit-message-substitution-scan");
12
- /**
13
- * Blocks `git commit` whose message is passed INLINE (`-m` / `--message` / `-am`) when that message
14
- * contains a backtick, a `$(`, or a newline — and hands back `git commit -F <file>` instead.
15
- *
16
- * ─── The incident: a commit message that HUNG for ten minutes, twice ───────────────────────────────
17
- * An agent ran `git commit -q -m "…"` with a multi-paragraph message that happened to contain the
18
- * sentence: *"… `strings` on a .app built with --port 8084 contains no 8084."* The backticks are
19
- * COMMAND SUBSTITUTION. The shell ran `strings` with no arguments, `strings` read stdin, and stdin
20
- * never closed. The Bash tool SIGTERM'd it at its ten-minute cap. The retry kept the same sentence and
21
- * did it again — twenty minutes for one commit.
22
- *
23
- * ─── Why this is a GUARD and not a doc line ────────────────────────────────────────────────────────
24
- * The agent then diagnosed it as "a guard caught a commit message that quoting a blocked command",
25
- * citing an unrelated deploy-guard note. Three facts settle that it was nothing of the kind, and they
26
- * are worth writing down because they are the reason the cure has to arrive BEFORE execution:
27
- *
28
- * - a PreToolUse guard denies INSTANTLY, before the command runs. This ran for ten minutes.
29
- * - `Exit code 143` is SIGTERM delivered to a RUNNING process, not a refusal.
30
- * - the first attempt was `git add -A && git commit -m "…"`, and afterwards the 45 files were
31
- * STAGED — so the command really executed, and then blocked while expanding its second word.
32
- *
33
- * A footnote in a doc could not have reached that agent at that moment; a refusal naming `-F` does.
34
- *
35
- * ─── The trigger is the METACHARACTER, never the words ─────────────────────────────────────────────
36
- * A message is PROSE, and prose goes through the shell's expansion rules whether or not it is meant
37
- * to. A blocklist of "dangerous commands" would have missed this entirely — `strings` is an ordinary
38
- * word, and the next hang will name an ordinary word too. So the rule matches backtick, `$(` and a
39
- * newline inside the message argument, and reads nothing at all into the surrounding sentence.
40
- *
41
- * ─── It fires on a SINGLE-QUOTED message too, and that is deliberate ───────────────────────────────
42
- * `git commit -m 'a `backtick` here'` is, strictly, safe: single quotes suppress substitution, so the
43
- * shell would pass those backticks through literally. This guard blocks it anyway, and the false
44
- * positive is the point rather than an oversight — do not "fix" it. Two reasons:
45
- *
46
- * - single-quoting PROSE is fragile in the one way that matters. An English sentence eventually
47
- * contains an apostrophe ("doesn't", "the agent's"), which CLOSES the quote mid-message and drops
48
- * the rest of the sentence back into the shell's syntax — the exact state this guard exists to
49
- * prevent, reached by a message that looked safe when it was written.
50
- * - the cure is free. `-F` costs one Write tool call and works for every message, so being wrong
51
- * here spends seconds, while being right saves twenty minutes. A guard chooses its errors by what
52
- * each one COSTS, and these two costs are not close.
53
- *
54
- * `blocks a single-quoted message too` in the spec pins this, so a later reader meets the decision as
55
- * a failing test rather than as a bug report.
56
- *
57
- * ─── It matches the RAW command, and that is load-bearing ──────────────────────────────────────────
58
- * Every other bash guard here matches `ctx.commandCode`, which STRIPS heredoc bodies and quoted prose
59
- * precisely so a commit message merely MENTIONING `git push` is not read as a push. That stripping
60
- * deletes exactly the span this rule exists to inspect: on `commandCode` the message is already gone,
61
- * and the guard would be permanently blind. So it reads `ctx.command`.
62
- *
63
- * That is safe here because the rule is still blocklist-shaped and its cure can never itself be
64
- * blocked: `-F` writes the message to a file and passes a PATH, so nothing about the message text can
65
- * make the replacement command match this guard. There is no input for which an agent is left with no
66
- * accepted spelling.
67
- */
68
- class CommitMessageSubstitutionGuardRule extends rule_base_1.BashRuleBase {
69
- constructor() {
70
- // configKey === name and is DELIBERATELY not a real webpieces.config.json key. Like
71
- // whole-repo-build-guard, this guard is loaded OUTSIDE the config-driven set, so the fault-Y
72
- // config-sync check ("every built-in rule needs an entry, or every Bash call is blocked") can
73
- // never see it — a new guard that every consumer must configure to avoid being blocked is a
74
- // guard that ships an outage on upgrade, which has happened here once already.
75
- super(new rule_base_1.EmptyRuleConfig(), 'commit-message-substitution-guard', 'commit-message-substitution-guard');
76
- }
77
- scan = new commit_message_substitution_scan_1.CommitMessageSubstitutionScan(new command_scan_1.CommandScanner());
78
- description = 'Block `git commit -m` whose inline message contains a backtick, `$(` or a newline — the shell ' +
79
- 'expands those before git sees them — and name `git commit -F` instead.';
80
- get fixHint() {
81
- return new fix_hint_1.FixHint('A commit message passed with -m goes through the shell. A backtick or $( in it is COMMAND ' +
82
- 'SUBSTITUTION, and a substituted command that reads stdin hangs until the tool times out.', 'Keep the message text out of the shell\'s expansion path — pass a PATH, not prose:', [
83
- new rules_config_1.Option('Write the message to a file with the Write tool, then:\n' +
84
- 'git commit -F /tmp/commit-msg.txt', true),
85
- new rules_config_1.Option('Feed it on stdin from a QUOTED heredoc:\n' +
86
- 'git commit -F - <<\'EOF\'\n' +
87
- '<your message>\n' +
88
- 'EOF\n' +
89
- 'The quotes around EOF are what disable substitution. An unquoted <<EOF does NOT — ' +
90
- 'the body is still expanded, and you are back where you started.'),
91
- ]);
92
- }
93
- check(ctx) {
94
- // RAW, not commandCode — see the class docstring. commandCode strips the quoted prose this
95
- // rule's entire subject is, so matching on it would make the guard permanently blind.
96
- const hit = this.scan.firstHit(ctx.command);
97
- if (hit === null)
98
- return this.allow(ctx, 'no-inline-message-hazard');
99
- return this.block(ctx, hit);
100
- }
101
- allow(ctx, reason) {
102
- this.logDecision(ctx, 'ALLOW', reason);
103
- return [];
104
- }
105
- block(ctx, hit) {
106
- // BLOCK_AI_CURE: the cure is two commands the agent runs itself, both spelled out in fixHint.
107
- this.logDecision(ctx, 'BLOCK_AI_CURE', `inline-message-${hit.kind}`);
108
- return [new types_1.Violation(1, this.truncate(ctx.command), this.message(hit))];
109
- }
110
- // Short on purpose: it is read mid-task by an agent that needs the ONE next move.
111
- message(hit) {
112
- return `Blocked: the ${hit.flag} message contains ${this.what(hit.kind)}, which the SHELL acts on `
113
- + 'before git ever sees the message.\n\n'
114
- + ` ${hit.excerpt}\n\n`
115
- + 'Write the message to a file with the Write tool and commit with `git commit -F <file>`, or '
116
- + 'pipe it in with a QUOTED heredoc: `git commit -F - <<\'EOF\'`.';
117
- }
118
- what(kind) {
119
- if (kind === 'backtick')
120
- return 'a BACKTICK (command substitution — `cmd` runs cmd)';
121
- if (kind === 'command-substitution')
122
- return 'a `$(` (command substitution)';
123
- return 'a NEWLINE (a multi-paragraph message belongs in a file — that is where the backticks hide)';
124
- }
125
- truncate(s) {
126
- const MAX = 120;
127
- return s.length <= MAX ? s : s.slice(0, MAX) + '…';
128
- }
129
- logDecision(ctx, verdict, reason) {
130
- (0, decision_log_1.logGuardDecision)(ctx.workspaceRoot, new decision_log_1.GuardDecision('commit-message-substitution-guard', 'Bash', ctx.command, '-', verdict, reason, '-', l0_fault_codes_1.L0_FAULT_NONE, decision_log_1.MATRIX_L2_UNROWED));
131
- }
132
- }
133
- exports.CommitMessageSubstitutionGuardRule = CommitMessageSubstitutionGuardRule;
134
- //# sourceMappingURL=commit-message-substitution-guard.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"commit-message-substitution-guard.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/ai-hook-rules/src/core/rules/commit-message-substitution-guard.ts"],"names":[],"mappings":";;;AAAA,0DAAiD;AAGjD,oCAA0C;AAC1C,4CAA6D;AAC7D,0CAAsC;AACtC,sDAAkD;AAClD,kDAA8F;AAC9F,kDAAiD;AACjD,yFAAqH;AAErH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,MAAa,kCAAmC,SAAQ,wBAA6B;IACjF;QACI,oFAAoF;QACpF,6FAA6F;QAC7F,8FAA8F;QAC9F,4FAA4F;QAC5F,+EAA+E;QAC/E,KAAK,CAAC,IAAI,2BAAe,EAAE,EAAE,mCAAmC,EAAE,mCAAmC,CAAC,CAAC;IAC3G,CAAC;IAEgB,IAAI,GAAG,IAAI,gEAA6B,CAAC,IAAI,6BAAc,EAAE,CAAC,CAAC;IAEvE,WAAW,GAChB,gGAAgG;QAChG,wEAAwE,CAAC;IAE7E,IAAI,OAAO;QACP,OAAO,IAAI,kBAAO,CACd,4FAA4F;YAC5F,0FAA0F,EAC1F,oFAAoF,EACpF;YACI,IAAI,qBAAM,CACN,0DAA0D;gBAC1D,mCAAmC,EACnC,IAAI,CACP;YACD,IAAI,qBAAM,CACN,2CAA2C;gBAC3C,6BAA6B;gBAC7B,kBAAkB;gBAClB,OAAO;gBACP,oFAAoF;gBACpF,iEAAiE,CACpE;SACJ,CACJ,CAAC;IACN,CAAC;IAED,KAAK,CAAC,GAAgB;QAClB,2FAA2F;QAC3F,sFAAsF;QACtF,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAC5C,IAAI,GAAG,KAAK,IAAI;YAAE,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,0BAA0B,CAAC,CAAC;QACrE,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAChC,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,4BAAa,CACb,mCAAmC,EAAE,MAAM,EAAE,GAAG,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAC9E,GAAG,EAAE,8BAAa,EAAE,gCAAiB,CACxC,CACJ,CAAC;IACN,CAAC;CACJ;AAvFD,gFAuFC","sourcesContent":["import { Option } from '@webpieces/rules-config';\n\nimport type { BashContext, Violation } from '../types';\nimport { Violation as V } from '../types';\nimport { BashRuleBase, EmptyRuleConfig } from '../rule-base';\nimport { FixHint } from '../fix-hint';\nimport { L0_FAULT_NONE } from '../l0-fault-codes';\nimport { logGuardDecision, GuardDecision, Verdict, MATRIX_L2_UNROWED } from '../decision-log';\nimport { CommandScanner } from '../command-scan';\nimport { CommitMessageSubstitutionScan, MessageHazard, MessageHazardKind } from './commit-message-substitution-scan';\n\n/**\n * Blocks `git commit` whose message is passed INLINE (`-m` / `--message` / `-am`) when that message\n * contains a backtick, a `$(`, or a newline — and hands back `git commit -F <file>` instead.\n *\n * ─── The incident: a commit message that HUNG for ten minutes, twice ───────────────────────────────\n * An agent ran `git commit -q -m \"…\"` with a multi-paragraph message that happened to contain the\n * sentence: *\"… `strings` on a .app built with --port 8084 contains no 8084.\"* The backticks are\n * COMMAND SUBSTITUTION. The shell ran `strings` with no arguments, `strings` read stdin, and stdin\n * never closed. The Bash tool SIGTERM'd it at its ten-minute cap. The retry kept the same sentence and\n * did it again — twenty minutes for one commit.\n *\n * ─── Why this is a GUARD and not a doc line ────────────────────────────────────────────────────────\n * The agent then diagnosed it as \"a guard caught a commit message that quoting a blocked command\",\n * citing an unrelated deploy-guard note. Three facts settle that it was nothing of the kind, and they\n * are worth writing down because they are the reason the cure has to arrive BEFORE execution:\n *\n * - a PreToolUse guard denies INSTANTLY, before the command runs. This ran for ten minutes.\n * - `Exit code 143` is SIGTERM delivered to a RUNNING process, not a refusal.\n * - the first attempt was `git add -A && git commit -m \"…\"`, and afterwards the 45 files were\n * STAGED — so the command really executed, and then blocked while expanding its second word.\n *\n * A footnote in a doc could not have reached that agent at that moment; a refusal naming `-F` does.\n *\n * ─── The trigger is the METACHARACTER, never the words ─────────────────────────────────────────────\n * A message is PROSE, and prose goes through the shell's expansion rules whether or not it is meant\n * to. A blocklist of \"dangerous commands\" would have missed this entirely — `strings` is an ordinary\n * word, and the next hang will name an ordinary word too. So the rule matches backtick, `$(` and a\n * newline inside the message argument, and reads nothing at all into the surrounding sentence.\n *\n * ─── It fires on a SINGLE-QUOTED message too, and that is deliberate ───────────────────────────────\n * `git commit -m 'a `backtick` here'` is, strictly, safe: single quotes suppress substitution, so the\n * shell would pass those backticks through literally. This guard blocks it anyway, and the false\n * positive is the point rather than an oversight — do not \"fix\" it. Two reasons:\n *\n * - single-quoting PROSE is fragile in the one way that matters. An English sentence eventually\n * contains an apostrophe (\"doesn't\", \"the agent's\"), which CLOSES the quote mid-message and drops\n * the rest of the sentence back into the shell's syntax — the exact state this guard exists to\n * prevent, reached by a message that looked safe when it was written.\n * - the cure is free. `-F` costs one Write tool call and works for every message, so being wrong\n * here spends seconds, while being right saves twenty minutes. A guard chooses its errors by what\n * each one COSTS, and these two costs are not close.\n *\n * `blocks a single-quoted message too` in the spec pins this, so a later reader meets the decision as\n * a failing test rather than as a bug report.\n *\n * ─── It matches the RAW command, and that is load-bearing ──────────────────────────────────────────\n * Every other bash guard here matches `ctx.commandCode`, which STRIPS heredoc bodies and quoted prose\n * precisely so a commit message merely MENTIONING `git push` is not read as a push. That stripping\n * deletes exactly the span this rule exists to inspect: on `commandCode` the message is already gone,\n * and the guard would be permanently blind. So it reads `ctx.command`.\n *\n * That is safe here because the rule is still blocklist-shaped and its cure can never itself be\n * blocked: `-F` writes the message to a file and passes a PATH, so nothing about the message text can\n * make the replacement command match this guard. There is no input for which an agent is left with no\n * accepted spelling.\n */\nexport class CommitMessageSubstitutionGuardRule extends BashRuleBase<EmptyRuleConfig> {\n constructor() {\n // configKey === name and is DELIBERATELY not a real webpieces.config.json key. Like\n // whole-repo-build-guard, this guard is loaded OUTSIDE the config-driven set, so the fault-Y\n // config-sync check (\"every built-in rule needs an entry, or every Bash call is blocked\") can\n // never see it — a new guard that every consumer must configure to avoid being blocked is a\n // guard that ships an outage on upgrade, which has happened here once already.\n super(new EmptyRuleConfig(), 'commit-message-substitution-guard', 'commit-message-substitution-guard');\n }\n\n private readonly scan = new CommitMessageSubstitutionScan(new CommandScanner());\n\n readonly description =\n 'Block `git commit -m` whose inline message contains a backtick, `$(` or a newline — the shell ' +\n 'expands those before git sees them — and name `git commit -F` instead.';\n\n get fixHint(): FixHint {\n return new FixHint(\n 'A commit message passed with -m goes through the shell. A backtick or $( in it is COMMAND ' +\n 'SUBSTITUTION, and a substituted command that reads stdin hangs until the tool times out.',\n 'Keep the message text out of the shell\\'s expansion path — pass a PATH, not prose:',\n [\n new Option(\n 'Write the message to a file with the Write tool, then:\\n' +\n 'git commit -F /tmp/commit-msg.txt',\n true,\n ),\n new Option(\n 'Feed it on stdin from a QUOTED heredoc:\\n' +\n 'git commit -F - <<\\'EOF\\'\\n' +\n '<your message>\\n' +\n 'EOF\\n' +\n 'The quotes around EOF are what disable substitution. An unquoted <<EOF does NOT — ' +\n 'the body is still expanded, and you are back where you started.',\n ),\n ],\n );\n }\n\n check(ctx: BashContext): readonly Violation[] {\n // RAW, not commandCode — see the class docstring. commandCode strips the quoted prose this\n // rule's entire subject is, so matching on it would make the guard permanently blind.\n const hit = this.scan.firstHit(ctx.command);\n if (hit === null) return this.allow(ctx, 'no-inline-message-hazard');\n return this.block(ctx, hit);\n }\n\n private allow(ctx: BashContext, reason: string): readonly Violation[] {\n this.logDecision(ctx, 'ALLOW', reason);\n return [];\n }\n\n private block(ctx: BashContext, hit: MessageHazard): readonly Violation[] {\n // BLOCK_AI_CURE: the cure is two commands the agent runs itself, both spelled out in fixHint.\n this.logDecision(ctx, 'BLOCK_AI_CURE', `inline-message-${hit.kind}`);\n return [new V(1, this.truncate(ctx.command), this.message(hit))];\n }\n\n // Short on purpose: it is read mid-task by an agent that needs the ONE next move.\n private message(hit: MessageHazard): string {\n return `Blocked: the ${hit.flag} message contains ${this.what(hit.kind)}, which the SHELL acts on `\n + 'before git ever sees the message.\\n\\n'\n + ` ${hit.excerpt}\\n\\n`\n + 'Write the message to a file with the Write tool and commit with `git commit -F <file>`, or '\n + 'pipe it in with a QUOTED heredoc: `git commit -F - <<\\'EOF\\'`.';\n }\n\n private what(kind: MessageHazardKind): string {\n if (kind === 'backtick') return 'a BACKTICK (command substitution — `cmd` runs cmd)';\n if (kind === 'command-substitution') return 'a `$(` (command substitution)';\n return 'a NEWLINE (a multi-paragraph message belongs in a file — that is where the backticks hide)';\n }\n\n private truncate(s: string): string {\n const MAX = 120;\n return s.length <= MAX ? s : s.slice(0, MAX) + '…';\n }\n\n private logDecision(ctx: BashContext, verdict: Verdict, reason: string): void {\n logGuardDecision(\n ctx.workspaceRoot,\n new GuardDecision(\n 'commit-message-substitution-guard', 'Bash', ctx.command, '-', verdict, reason,\n '-', L0_FAULT_NONE, MATRIX_L2_UNROWED,\n ),\n );\n }\n}\n"]}
@@ -1,42 +0,0 @@
1
- import { CommandScanner } from '../command-scan';
2
- /** Which shell construct was found inside an inline commit message. */
3
- export type MessageHazardKind = 'backtick' | 'command-substitution' | 'newline';
4
- /**
5
- * One hazard found in one inline `-m` message: the flag that carried it, what it is, and the text
6
- * around it. Data-only → a class, per CLAUDE.md.
7
- *
8
- * `excerpt` is a short window around the hit rather than the whole message: the refusal is read
9
- * mid-task, and a 40-line commit message pasted back at the agent buries the one thing it must see.
10
- */
11
- export declare class MessageHazard {
12
- readonly flag: string;
13
- readonly kind: MessageHazardKind;
14
- readonly excerpt: string;
15
- constructor(flag: string, kind: MessageHazardKind, excerpt: string);
16
- }
17
- /**
18
- * Finds a commit message passed INLINE (`-m` / `--message` / `-am`) whose text carries a shell
19
- * construct the shell will expand before git ever sees it.
20
- *
21
- * Split out from the guard for the same reason `WholeRepoBuildScan` is: WHAT counts as a hit is a
22
- * tokenizer question with its own tests, while the guard owns the verdict, the log line and the words
23
- * of the refusal.
24
- */
25
- export declare class CommitMessageSubstitutionScan {
26
- private readonly scanner;
27
- constructor(scanner: CommandScanner);
28
- /**
29
- * The first hazard anywhere in the command, or null.
30
- *
31
- * `command` is the RAW command — see the guard's docstring for why `commandCode` cannot be used.
32
- */
33
- firstHit(command: string): MessageHazard | null;
34
- private hazardInArgs;
35
- /** The message carried IN the flag token itself (`-mfix`, `--message=fix`), or null. */
36
- private attachedMessage;
37
- /** True when the flag's message is the FOLLOWING token (`-m msg`, `-am msg`, `--message msg`). */
38
- private takesFollowingMessage;
39
- /** The EARLIEST hazard in this text, so the excerpt points at what the shell hits first. */
40
- private hazardIn;
41
- private excerpt;
42
- }
@@ -1,145 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CommitMessageSubstitutionScan = exports.MessageHazard = void 0;
4
- /**
5
- * One hazard found in one inline `-m` message: the flag that carried it, what it is, and the text
6
- * around it. Data-only → a class, per CLAUDE.md.
7
- *
8
- * `excerpt` is a short window around the hit rather than the whole message: the refusal is read
9
- * mid-task, and a 40-line commit message pasted back at the agent buries the one thing it must see.
10
- */
11
- class MessageHazard {
12
- flag;
13
- kind;
14
- excerpt;
15
- constructor(flag, kind, excerpt) {
16
- this.flag = flag;
17
- this.kind = kind;
18
- this.excerpt = excerpt;
19
- }
20
- }
21
- exports.MessageHazard = MessageHazard;
22
- /** One hazard kind and the literal text that betrays it, in the order they are reported. */
23
- class HazardNeedle {
24
- kind;
25
- needle;
26
- constructor(kind, needle) {
27
- this.kind = kind;
28
- this.needle = needle;
29
- }
30
- }
31
- /**
32
- * The three constructs that make a commit message dangerous, and NOTHING about the words around them.
33
- *
34
- * A blocklist of "dangerous commands" would have missed the incident this exists for entirely — the
35
- * word that hung was `strings`, which is as ordinary as a word gets. The hazard is the METACHARACTER.
36
- */
37
- const HAZARDS = [
38
- new HazardNeedle('backtick', '`'),
39
- new HazardNeedle('command-substitution', '$('),
40
- new HazardNeedle('newline', '\n'),
41
- ];
42
- // A short cluster of git-commit boolean short flags that may legally precede `m` in one bundle
43
- // (`-am`, `-qm`, `-asm`). Deliberately NOT `[A-Za-z]*`: `-Sabcmdef` (a gpg key id containing an `m`)
44
- // would then read as a message flag with an attached message.
45
- const SHORT_FLAG_CLUSTER = /^-([asevqnoup]*)m(.*)$/;
46
- const LONG_MESSAGE_FLAG = '--message';
47
- /**
48
- * Finds a commit message passed INLINE (`-m` / `--message` / `-am`) whose text carries a shell
49
- * construct the shell will expand before git ever sees it.
50
- *
51
- * Split out from the guard for the same reason `WholeRepoBuildScan` is: WHAT counts as a hit is a
52
- * tokenizer question with its own tests, while the guard owns the verdict, the log line and the words
53
- * of the refusal.
54
- */
55
- class CommitMessageSubstitutionScan {
56
- scanner;
57
- constructor(scanner) {
58
- this.scanner = scanner;
59
- }
60
- /**
61
- * The first hazard anywhere in the command, or null.
62
- *
63
- * `command` is the RAW command — see the guard's docstring for why `commandCode` cannot be used.
64
- */
65
- firstHit(command) {
66
- for (const segment of this.scanner.commandSegments(command)) {
67
- const args = this.scanner.gitSubcommandArgs(segment, 'commit');
68
- if (args === null)
69
- continue;
70
- const hit = this.hazardInArgs(args);
71
- if (hit !== null)
72
- return hit;
73
- }
74
- return null;
75
- }
76
- hazardInArgs(args) {
77
- for (let i = 0; i < args.length; i++) {
78
- const flag = args[i];
79
- const attached = this.attachedMessage(flag);
80
- if (attached !== null) {
81
- const hit = this.hazardIn(flag, attached);
82
- if (hit !== null)
83
- return hit;
84
- continue;
85
- }
86
- if (!this.takesFollowingMessage(flag))
87
- continue;
88
- // The value is the NEXT token, and it may be absent (`git commit -m` alone, which git
89
- // itself rejects). Nothing to inspect then — a guard never fails on a malformed command.
90
- const text = args[i + 1];
91
- i++;
92
- if (text === undefined)
93
- continue;
94
- const hit = this.hazardIn(flag, text);
95
- if (hit !== null)
96
- return hit;
97
- }
98
- return null;
99
- }
100
- /** The message carried IN the flag token itself (`-mfix`, `--message=fix`), or null. */
101
- attachedMessage(flag) {
102
- if (flag.startsWith(`${LONG_MESSAGE_FLAG}=`))
103
- return flag.slice(LONG_MESSAGE_FLAG.length + 1);
104
- // `--amend`, `--no-edit`, `--fixup=…` — every other long flag, and never a message.
105
- if (flag.startsWith('--'))
106
- return null;
107
- const cluster = SHORT_FLAG_CLUSTER.exec(flag);
108
- if (cluster === null)
109
- return null;
110
- return cluster[2] === '' ? null : cluster[2];
111
- }
112
- /** True when the flag's message is the FOLLOWING token (`-m msg`, `-am msg`, `--message msg`). */
113
- takesFollowingMessage(flag) {
114
- if (flag === LONG_MESSAGE_FLAG)
115
- return true;
116
- if (flag.startsWith('--'))
117
- return false;
118
- const cluster = SHORT_FLAG_CLUSTER.exec(flag);
119
- return cluster !== null && cluster[2] === '';
120
- }
121
- /** The EARLIEST hazard in this text, so the excerpt points at what the shell hits first. */
122
- hazardIn(flag, text) {
123
- let best = null;
124
- let bestAt = text.length;
125
- for (const hazard of HAZARDS) {
126
- const at = text.indexOf(hazard.needle);
127
- if (at === -1 || at >= bestAt)
128
- continue;
129
- bestAt = at;
130
- best = new MessageHazard(flag, hazard.kind, this.excerpt(text, at));
131
- }
132
- return best;
133
- }
134
- // A window around the hit, newlines shown as `\n` so the excerpt stays one line in the report.
135
- excerpt(text, at) {
136
- const BEFORE = 30;
137
- const AFTER = 40;
138
- const start = Math.max(0, at - BEFORE);
139
- const end = Math.min(text.length, at + AFTER);
140
- const body = text.slice(start, end).replace(/\n/g, '\\n');
141
- return `${start > 0 ? '…' : ''}${body}${end < text.length ? '…' : ''}`;
142
- }
143
- }
144
- exports.CommitMessageSubstitutionScan = CommitMessageSubstitutionScan;
145
- //# sourceMappingURL=commit-message-substitution-scan.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"commit-message-substitution-scan.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/ai-hook-rules/src/core/rules/commit-message-substitution-scan.ts"],"names":[],"mappings":";;;AAKA;;;;;;GAMG;AACH,MAAa,aAAa;I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,CAAC;QACvC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,GAAG,KAAK,CAAC,CAAC;QAC9C,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAC1D,OAAO,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;IAC3E,CAAC;CACJ;AA/ED,sEA+EC","sourcesContent":["import { CommandScanner } from '../command-scan';\n\n/** Which shell construct was found inside an inline commit message. */\nexport type MessageHazardKind = 'backtick' | 'command-substitution' | 'newline';\n\n/**\n * One hazard found in one inline `-m` message: the flag that carried it, what it is, and the text\n * around it. Data-only → a class, per CLAUDE.md.\n *\n * `excerpt` is a short window around the hit rather than the whole message: the refusal is read\n * mid-task, and a 40-line commit message pasted back at the agent buries the one thing it must see.\n */\nexport class MessageHazard {\n constructor(\n readonly flag: string,\n readonly kind: MessageHazardKind,\n readonly excerpt: string,\n ) {}\n}\n\n/** One hazard kind and the literal text that betrays it, in the order they are reported. */\nclass HazardNeedle {\n constructor(readonly kind: MessageHazardKind, readonly needle: string) {}\n}\n\n/**\n * The three constructs that make a commit message dangerous, and NOTHING about the words around them.\n *\n * A blocklist of \"dangerous commands\" would have missed the incident this exists for entirely — the\n * word that hung was `strings`, which is as ordinary as a word gets. The hazard is the METACHARACTER.\n */\nconst HAZARDS: readonly HazardNeedle[] = [\n new HazardNeedle('backtick', '`'),\n new HazardNeedle('command-substitution', '$('),\n new HazardNeedle('newline', '\\n'),\n];\n\n// A short cluster of git-commit boolean short flags that may legally precede `m` in one bundle\n// (`-am`, `-qm`, `-asm`). Deliberately NOT `[A-Za-z]*`: `-Sabcmdef` (a gpg key id containing an `m`)\n// would then read as a message flag with an attached message.\nconst SHORT_FLAG_CLUSTER = /^-([asevqnoup]*)m(.*)$/;\n\nconst LONG_MESSAGE_FLAG = '--message';\n\n/**\n * Finds a commit message passed INLINE (`-m` / `--message` / `-am`) whose text carries a shell\n * construct the shell will expand before git ever sees it.\n *\n * Split out from the guard for the same reason `WholeRepoBuildScan` is: WHAT counts as a hit is a\n * tokenizer question with its own tests, while the guard owns the verdict, the log line and the words\n * of the refusal.\n */\nexport class CommitMessageSubstitutionScan {\n constructor(private readonly scanner: CommandScanner) {}\n\n /**\n * The first hazard anywhere in the command, or null.\n *\n * `command` is the RAW command — see the guard's docstring for why `commandCode` cannot be used.\n */\n firstHit(command: string): MessageHazard | null {\n for (const segment of this.scanner.commandSegments(command)) {\n const args = this.scanner.gitSubcommandArgs(segment, 'commit');\n if (args === null) continue;\n const hit = this.hazardInArgs(args);\n if (hit !== null) return hit;\n }\n return null;\n }\n\n private hazardInArgs(args: readonly string[]): MessageHazard | null {\n for (let i = 0; i < args.length; i++) {\n const flag = args[i];\n const attached = this.attachedMessage(flag);\n if (attached !== null) {\n const hit = this.hazardIn(flag, attached);\n if (hit !== null) return hit;\n continue;\n }\n if (!this.takesFollowingMessage(flag)) continue;\n // The value is the NEXT token, and it may be absent (`git commit -m` alone, which git\n // itself rejects). Nothing to inspect then — a guard never fails on a malformed command.\n const text = args[i + 1];\n i++;\n if (text === undefined) continue;\n const hit = this.hazardIn(flag, text);\n if (hit !== null) return hit;\n }\n return null;\n }\n\n /** The message carried IN the flag token itself (`-mfix`, `--message=fix`), or null. */\n private attachedMessage(flag: string): string | null {\n if (flag.startsWith(`${LONG_MESSAGE_FLAG}=`)) return flag.slice(LONG_MESSAGE_FLAG.length + 1);\n // `--amend`, `--no-edit`, `--fixup=…` — every other long flag, and never a message.\n if (flag.startsWith('--')) return null;\n const cluster = SHORT_FLAG_CLUSTER.exec(flag);\n if (cluster === null) return null;\n return cluster[2] === '' ? null : cluster[2];\n }\n\n /** True when the flag's message is the FOLLOWING token (`-m msg`, `-am msg`, `--message msg`). */\n private takesFollowingMessage(flag: string): boolean {\n if (flag === LONG_MESSAGE_FLAG) return true;\n if (flag.startsWith('--')) return false;\n const cluster = SHORT_FLAG_CLUSTER.exec(flag);\n return cluster !== null && cluster[2] === '';\n }\n\n /** The EARLIEST hazard in this text, so the excerpt points at what the shell hits first. */\n private hazardIn(flag: string, text: string): MessageHazard | null {\n let best: MessageHazard | null = null;\n let bestAt = text.length;\n for (const hazard of HAZARDS) {\n const at = text.indexOf(hazard.needle);\n if (at === -1 || at >= bestAt) continue;\n bestAt = at;\n best = new MessageHazard(flag, hazard.kind, this.excerpt(text, at));\n }\n return best;\n }\n\n // A window around the hit, newlines shown as `\\n` so the excerpt stays one line in the report.\n private excerpt(text: string, at: number): string {\n const BEFORE = 30;\n const AFTER = 40;\n const start = Math.max(0, at - BEFORE);\n const end = Math.min(text.length, at + AFTER);\n const body = text.slice(start, end).replace(/\\n/g, '\\\\n');\n return `${start > 0 ? '…' : ''}${body}${end < text.length ? '…' : ''}`;\n }\n}\n"]}
@@ -1,76 +0,0 @@
1
- import { CommandScanner, CommandSegment } from '../command-scan';
2
- /**
3
- * Decides the one question stale-main-bash-guard asks of a command: does this segment put stale
4
- * WORKSPACE FILE CONTENT into the agent's context?
5
- *
6
- * The distinction that matters is content vs metadata, not shell vs tool. `git log`, `git diff`,
7
- * `git status`, builds, tests and the cure itself are all fine on a stale main — none of them hands
8
- * you the text of a file that upstream has moved past. `cat src/x.ts` does, and so does
9
- * `grep -r foo services/`, `ls .github/workflows/` (the incident's actual wrong answer: a listing
10
- * missing a workflow that existed upstream) and `git show HEAD:file`.
11
- *
12
- * Three things keep this from over-blocking:
13
- * 1. A piped consumer reads stdin, not the tree — `git log | grep fix` is metadata, so it passes.
14
- * 2. A reader with no path operand that does not default to the cwd reads stdin — `cat` alone,
15
- * `grep pattern` alone.
16
- * 3. Only paths INSIDE the workspace count. `cat /etc/hosts`, `cat ~/.zshrc`, `cat /tmp/out.log`
17
- * are nothing to do with this repo's staleness.
18
- */
19
- export declare class ContentReadScan {
20
- private readonly scanner;
21
- private readonly workspaceRoot;
22
- private readonly shell;
23
- private readonly baseDir;
24
- /**
25
- * `effectiveCwd` is the directory the command really runs in — after its own leading `cd`, which
26
- * is how an agent reaches a linked worktree, since the harness resets a cwd that left the workspace.
27
- * RELATIVE operands are resolved against it, not against workspaceRoot: `cd /tmp/scratch && cat
28
- * notes.md` reads `/tmp/scratch/notes.md`, which is nothing to do with this repo's staleness,
29
- * while `cd /tmp/scratch && cat /repo/src/x.ts` still names repo content and is still caught.
30
- * Defaults to workspaceRoot, which is exactly the old behaviour (relative = inside the repo).
31
- */
32
- constructor(scanner: CommandScanner, workspaceRoot: string, effectiveCwd?: string);
33
- /**
34
- * True when this segment's ONLY job is reading content, and nothing it reads is in the workspace —
35
- * `ls -la ~/.claude/projects/`, `cat /tmp/out.log`, `grep -r x /other/repo`.
36
- *
37
- * merged-branch-bash-guard needs this: it default-denies bash on a merged branch, and denied an
38
- * `ls` of a directory outside every git repo on the grounds that the branch was merged. Nothing
39
- * about a read that never touches the tree is affected by which branch the tree is on. The
40
- * "content reader" restriction is what keeps this from becoming a general escape hatch: a build,
41
- * a server or a git write is not a content reader and never qualifies, however its paths look.
42
- */
43
- readsOnlyOutsideContent(segment: CommandSegment): boolean;
44
- private isContentReader;
45
- /**
46
- * The command word that reads stale workspace content, or null when this segment does not.
47
- * The returned string is only a log/diagnostic label.
48
- *
49
- * Judged on the segment's EFFECTIVE words: `for f in a b; do cat $f; done` splits into segments
50
- * whose middle one is literally `do cat $f`, and taking `do` as the command name let every loop
51
- * body read the stale tree unseen.
52
- */
53
- readsStaleContent(segment: CommandSegment): string | null;
54
- /**
55
- * git's own content readers. `git grep` searches tracked CONTENT and `git show <rev>:<path>`
56
- * prints a file — both stale when the rev is local. Against an `origin/…` rev they read the
57
- * CURRENT upstream tree, which is exactly what we want the agent doing, so those pass.
58
- */
59
- private gitContentRead;
60
- private pathOperands;
61
- /**
62
- * Is this operand a path inside the workspace? A RELATIVE operand is resolved against the
63
- * directory the command actually runs in (`baseDir`), so it counts only when that directory is
64
- * itself in the tree — the old code assumed every relative path meant "inside the repo", which is
65
- * how a command run in a `/private/tmp` scratchpad got judged as reading a stale repo. An
66
- * absolute path counts only when it is genuinely under workspaceRoot, so `/etc/hosts`,
67
- * `~/notes.md` and `/tmp/x` are not this repo's problem.
68
- *
69
- * Deliberately NOT filesystem-checked: whether the path exists says nothing about staleness, and
70
- * a stat per operand on the blocking hook path is exactly the cost these guards avoid.
71
- */
72
- private isWorkspacePath;
73
- private isInWorkspace;
74
- private isEscapeHatchPath;
75
- private baseName;
76
- }