@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,176 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ContentReadScan = void 0;
4
- const tslib_1 = require("tslib");
5
- const path = tslib_1.__importStar(require("path"));
6
- const shell_segment_scan_1 = require("./shell-segment-scan");
7
- /**
8
- * Decides the one question stale-main-bash-guard asks of a command: does this segment put stale
9
- * WORKSPACE FILE CONTENT into the agent's context?
10
- *
11
- * The distinction that matters is content vs metadata, not shell vs tool. `git log`, `git diff`,
12
- * `git status`, builds, tests and the cure itself are all fine on a stale main — none of them hands
13
- * you the text of a file that upstream has moved past. `cat src/x.ts` does, and so does
14
- * `grep -r foo services/`, `ls .github/workflows/` (the incident's actual wrong answer: a listing
15
- * missing a workflow that existed upstream) and `git show HEAD:file`.
16
- *
17
- * Three things keep this from over-blocking:
18
- * 1. A piped consumer reads stdin, not the tree — `git log | grep fix` is metadata, so it passes.
19
- * 2. A reader with no path operand that does not default to the cwd reads stdin — `cat` alone,
20
- * `grep pattern` alone.
21
- * 3. Only paths INSIDE the workspace count. `cat /etc/hosts`, `cat ~/.zshrc`, `cat /tmp/out.log`
22
- * are nothing to do with this repo's staleness.
23
- */
24
- class ContentReadScan {
25
- scanner;
26
- workspaceRoot;
27
- shell;
28
- baseDir;
29
- /**
30
- * `effectiveCwd` is the directory the command really runs in — after its own leading `cd`, which
31
- * is how an agent reaches a linked worktree, since the harness resets a cwd that left the workspace.
32
- * RELATIVE operands are resolved against it, not against workspaceRoot: `cd /tmp/scratch && cat
33
- * notes.md` reads `/tmp/scratch/notes.md`, which is nothing to do with this repo's staleness,
34
- * while `cd /tmp/scratch && cat /repo/src/x.ts` still names repo content and is still caught.
35
- * Defaults to workspaceRoot, which is exactly the old behaviour (relative = inside the repo).
36
- */
37
- constructor(scanner, workspaceRoot, effectiveCwd) {
38
- this.scanner = scanner;
39
- this.workspaceRoot = workspaceRoot;
40
- this.shell = new shell_segment_scan_1.ShellSegmentScan(scanner);
41
- this.baseDir = effectiveCwd ?? workspaceRoot;
42
- }
43
- /**
44
- * True when this segment's ONLY job is reading content, and nothing it reads is in the workspace —
45
- * `ls -la ~/.claude/projects/`, `cat /tmp/out.log`, `grep -r x /other/repo`.
46
- *
47
- * merged-branch-bash-guard needs this: it default-denies bash on a merged branch, and denied an
48
- * `ls` of a directory outside every git repo on the grounds that the branch was merged. Nothing
49
- * about a read that never touches the tree is affected by which branch the tree is on. The
50
- * "content reader" restriction is what keeps this from becoming a general escape hatch: a build,
51
- * a server or a git write is not a content reader and never qualifies, however its paths look.
52
- */
53
- readsOnlyOutsideContent(segment) {
54
- return this.isContentReader(segment) && this.readsStaleContent(segment) === null;
55
- }
56
- // Is this segment one of the CONTENT_READERS at all (as opposed to a build, a server, a git write)?
57
- isContentReader(segment) {
58
- const words = this.shell.effectiveWords(segment.text);
59
- if (words.length === 0)
60
- return false;
61
- if (this.scanner.gitSubcommandOf(words) !== null)
62
- return false;
63
- return CONTENT_READERS.has(this.baseName(words[0]));
64
- }
65
- /**
66
- * The command word that reads stale workspace content, or null when this segment does not.
67
- * The returned string is only a log/diagnostic label.
68
- *
69
- * Judged on the segment's EFFECTIVE words: `for f in a b; do cat $f; done` splits into segments
70
- * whose middle one is literally `do cat $f`, and taking `do` as the command name let every loop
71
- * body read the stale tree unseen.
72
- */
73
- readsStaleContent(segment) {
74
- const words = this.shell.effectiveWords(segment.text);
75
- if (words.length === 0)
76
- return null;
77
- const gitSub = this.scanner.gitSubcommandOf(words);
78
- if (gitSub !== null)
79
- return this.gitContentRead(gitSub, words);
80
- const command = this.baseName(words[0]);
81
- if (!CONTENT_READERS.has(command))
82
- return null;
83
- const operands = this.pathOperands(command, words.slice(1));
84
- if (operands.length === 0) {
85
- // No path given: either it reads stdin (fine — and doubly fine when piped into), or it
86
- // walks the cwd. That only reads the stale tree when the cwd IS in it — `cd /tmp && ls`
87
- // walks /tmp, which this repo's staleness has nothing to do with.
88
- const walksTree = segment.join !== '|' && CWD_WALKERS.has(command) && this.isInWorkspace(this.baseDir);
89
- return walksTree ? command : null;
90
- }
91
- return operands.some((operand) => this.isWorkspacePath(operand)) ? command : null;
92
- }
93
- /**
94
- * git's own content readers. `git grep` searches tracked CONTENT and `git show <rev>:<path>`
95
- * prints a file — both stale when the rev is local. Against an `origin/…` rev they read the
96
- * CURRENT upstream tree, which is exactly what we want the agent doing, so those pass.
97
- */
98
- gitContentRead(gitSub, words) {
99
- if (gitSub !== 'grep' && gitSub !== 'show')
100
- return null;
101
- const args = words.slice(words.indexOf(gitSub) + 1);
102
- if (args.some((arg) => arg.startsWith('origin/')))
103
- return null;
104
- // `git show` without a `<rev>:<path>` operand is a commit view — metadata, not file content.
105
- if (gitSub === 'show' && !args.some((arg) => /^[^-].*:./.test(arg)))
106
- return null;
107
- return `git ${gitSub}`;
108
- }
109
- // The operands of a reader that are PATHS: flags dropped, and the leading pattern/script dropped
110
- // for the commands that take one (`grep RE file`, `sed -e prog file`, `awk prog file`).
111
- pathOperands(command, args) {
112
- const positional = [];
113
- for (const arg of args) {
114
- if (arg.startsWith('-'))
115
- continue; // a flag, or its attached value
116
- positional.push(arg);
117
- }
118
- if (PATTERN_FIRST.has(command) && positional.length > 0)
119
- return positional.slice(1);
120
- return positional;
121
- }
122
- /**
123
- * Is this operand a path inside the workspace? A RELATIVE operand is resolved against the
124
- * directory the command actually runs in (`baseDir`), so it counts only when that directory is
125
- * itself in the tree — the old code assumed every relative path meant "inside the repo", which is
126
- * how a command run in a `/private/tmp` scratchpad got judged as reading a stale repo. An
127
- * absolute path counts only when it is genuinely under workspaceRoot, so `/etc/hosts`,
128
- * `~/notes.md` and `/tmp/x` are not this repo's problem.
129
- *
130
- * Deliberately NOT filesystem-checked: whether the path exists says nothing about staleness, and
131
- * a stat per operand on the blocking hook path is exactly the cost these guards avoid.
132
- */
133
- isWorkspacePath(operand) {
134
- if (operand.startsWith('~'))
135
- return false;
136
- // The escape hatches are checked on the operand AS TYPED as well, so `cat webpieces.config.json`
137
- // stays readable from any directory — never wedge the file that turns the guard off.
138
- if (this.isEscapeHatchPath(operand))
139
- return false;
140
- const absolute = path.isAbsolute(operand) ? operand : path.resolve(this.baseDir, operand);
141
- const relative = path.relative(this.workspaceRoot, absolute);
142
- if (relative.startsWith('..'))
143
- return false;
144
- return !this.isEscapeHatchPath(relative);
145
- }
146
- // The cwd-walk question: is the directory this command runs in inside the tree being judged?
147
- isInWorkspace(dir) {
148
- const relative = path.relative(this.workspaceRoot, path.resolve(dir));
149
- return !relative.startsWith('..');
150
- }
151
- // Always-readable paths: webpieces.config.json is the mode-OFF escape hatch (never block the
152
- // file that turns the guard off), and `.webpieces/` is the guards' own logs/caches — orientation
153
- // data this guard writes itself, not source that upstream has moved past.
154
- isEscapeHatchPath(relative) {
155
- const normalized = relative.replace(/^\.\//, '');
156
- return normalized === 'webpieces.config.json' || normalized.startsWith('.webpieces/');
157
- }
158
- // `/usr/bin/cat` and `./scripts/cat` both invoke a program named cat; match on the base name.
159
- baseName(word) {
160
- return path.basename(word);
161
- }
162
- }
163
- exports.ContentReadScan = ContentReadScan;
164
- // Commands whose whole job is surfacing file CONTENT or file LISTINGS. Builds, test runners, package
165
- // managers and git metadata are deliberately absent — they are not how stale bytes enter context.
166
- const CONTENT_READERS = new Set([
167
- 'cat', 'bat', 'head', 'tail', 'less', 'more', 'nl', 'strings', 'xxd', 'od',
168
- 'grep', 'egrep', 'fgrep', 'rg', 'ag', 'ack', 'sed', 'awk', 'jq', 'yq',
169
- 'ls', 'find', 'tree', 'wc', 'diff',
170
- ]);
171
- // Readers that, given no path, walk the CURRENT DIRECTORY rather than reading stdin — so on a stale
172
- // main they read the stale tree even with no operand at all.
173
- const CWD_WALKERS = new Set(['ls', 'find', 'tree', 'rg', 'ag', 'ack']);
174
- // Readers whose FIRST positional argument is a pattern/program, not a path.
175
- const PATTERN_FIRST = new Set(['grep', 'egrep', 'fgrep', 'rg', 'ag', 'ack', 'sed', 'awk', 'jq', 'yq']);
176
- //# sourceMappingURL=content-read-scan.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"content-read-scan.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/ai-hook-rules/src/core/rules/content-read-scan.ts"],"names":[],"mappings":";;;;AAAA,mDAA6B;AAG7B,6DAAwD;AAExD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAa,eAAe;IAaH;IACA;IAbJ,KAAK,CAAmB;IACxB,OAAO,CAAS;IAEjC;;;;;;;OAOG;IACH,YACqB,OAAuB,EACvB,aAAqB,EACtC,YAAqB;QAFJ,YAAO,GAAP,OAAO,CAAgB;QACvB,kBAAa,GAAb,aAAa,CAAQ;QAGtC,IAAI,CAAC,KAAK,GAAG,IAAI,qCAAgB,CAAC,OAAO,CAAC,CAAC;QAC3C,IAAI,CAAC,OAAO,GAAG,YAAY,IAAI,aAAa,CAAC;IACjD,CAAC;IAED;;;;;;;;;OASG;IACH,uBAAuB,CAAC,OAAuB;QAC3C,OAAO,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC;IACrF,CAAC;IAED,oGAAoG;IAC5F,eAAe,CAAC,OAAuB;QAC3C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACtD,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;QACrC,IAAI,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,KAAK,CAAC,KAAK,IAAI;YAAE,OAAO,KAAK,CAAC;QAC/D,OAAO,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,C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,EAAE,KAAK,EAAE,IAAI;IAC1E,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI;IACrE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;CACrC,CAAC,CAAC;AAEH,oGAAoG;AACpG,6DAA6D;AAC7D,MAAM,WAAW,GAAwB,IAAI,GAAG,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;AAE5F,4EAA4E;AAC5E,MAAM,aAAa,GAAwB,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC","sourcesContent":["import * as path from 'path';\n\nimport { CommandScanner, CommandSegment } from '../command-scan';\nimport { ShellSegmentScan } from './shell-segment-scan';\n\n/**\n * Decides the one question stale-main-bash-guard asks of a command: does this segment put stale\n * WORKSPACE FILE CONTENT into the agent's context?\n *\n * The distinction that matters is content vs metadata, not shell vs tool. `git log`, `git diff`,\n * `git status`, builds, tests and the cure itself are all fine on a stale main — none of them hands\n * you the text of a file that upstream has moved past. `cat src/x.ts` does, and so does\n * `grep -r foo services/`, `ls .github/workflows/` (the incident's actual wrong answer: a listing\n * missing a workflow that existed upstream) and `git show HEAD:file`.\n *\n * Three things keep this from over-blocking:\n * 1. A piped consumer reads stdin, not the tree — `git log | grep fix` is metadata, so it passes.\n * 2. A reader with no path operand that does not default to the cwd reads stdin — `cat` alone,\n * `grep pattern` alone.\n * 3. Only paths INSIDE the workspace count. `cat /etc/hosts`, `cat ~/.zshrc`, `cat /tmp/out.log`\n * are nothing to do with this repo's staleness.\n */\nexport class ContentReadScan {\n private readonly shell: ShellSegmentScan;\n private readonly baseDir: string;\n\n /**\n * `effectiveCwd` is the directory the command really runs in — after its own leading `cd`, which\n * is how an agent reaches a linked worktree, since the harness resets a cwd that left the workspace.\n * RELATIVE operands are resolved against it, not against workspaceRoot: `cd /tmp/scratch && cat\n * notes.md` reads `/tmp/scratch/notes.md`, which is nothing to do with this repo's staleness,\n * while `cd /tmp/scratch && cat /repo/src/x.ts` still names repo content and is still caught.\n * Defaults to workspaceRoot, which is exactly the old behaviour (relative = inside the repo).\n */\n constructor(\n private readonly scanner: CommandScanner,\n private readonly workspaceRoot: string,\n effectiveCwd?: string,\n ) {\n this.shell = new ShellSegmentScan(scanner);\n this.baseDir = effectiveCwd ?? workspaceRoot;\n }\n\n /**\n * True when this segment's ONLY job is reading content, and nothing it reads is in the workspace —\n * `ls -la ~/.claude/projects/`, `cat /tmp/out.log`, `grep -r x /other/repo`.\n *\n * merged-branch-bash-guard needs this: it default-denies bash on a merged branch, and denied an\n * `ls` of a directory outside every git repo on the grounds that the branch was merged. Nothing\n * about a read that never touches the tree is affected by which branch the tree is on. The\n * \"content reader\" restriction is what keeps this from becoming a general escape hatch: a build,\n * a server or a git write is not a content reader and never qualifies, however its paths look.\n */\n readsOnlyOutsideContent(segment: CommandSegment): boolean {\n return this.isContentReader(segment) && this.readsStaleContent(segment) === null;\n }\n\n // Is this segment one of the CONTENT_READERS at all (as opposed to a build, a server, a git write)?\n private isContentReader(segment: CommandSegment): boolean {\n const words = this.shell.effectiveWords(segment.text);\n if (words.length === 0) return false;\n if (this.scanner.gitSubcommandOf(words) !== null) return false;\n return CONTENT_READERS.has(this.baseName(words[0]));\n }\n\n /**\n * The command word that reads stale workspace content, or null when this segment does not.\n * The returned string is only a log/diagnostic label.\n *\n * Judged on the segment's EFFECTIVE words: `for f in a b; do cat $f; done` splits into segments\n * whose middle one is literally `do cat $f`, and taking `do` as the command name let every loop\n * body read the stale tree unseen.\n */\n readsStaleContent(segment: CommandSegment): string | null {\n const words = this.shell.effectiveWords(segment.text);\n if (words.length === 0) return null;\n\n const gitSub = this.scanner.gitSubcommandOf(words);\n if (gitSub !== null) return this.gitContentRead(gitSub, words);\n\n const command = this.baseName(words[0]);\n if (!CONTENT_READERS.has(command)) return null;\n\n const operands = this.pathOperands(command, words.slice(1));\n if (operands.length === 0) {\n // No path given: either it reads stdin (fine — and doubly fine when piped into), or it\n // walks the cwd. That only reads the stale tree when the cwd IS in it — `cd /tmp && ls`\n // walks /tmp, which this repo's staleness has nothing to do with.\n const walksTree = segment.join !== '|' && CWD_WALKERS.has(command) && this.isInWorkspace(this.baseDir);\n return walksTree ? command : null;\n }\n return operands.some((operand: string): boolean => this.isWorkspacePath(operand)) ? command : null;\n }\n\n /**\n * git's own content readers. `git grep` searches tracked CONTENT and `git show <rev>:<path>`\n * prints a file — both stale when the rev is local. Against an `origin/…` rev they read the\n * CURRENT upstream tree, which is exactly what we want the agent doing, so those pass.\n */\n private gitContentRead(gitSub: string, words: readonly string[]): string | null {\n if (gitSub !== 'grep' && gitSub !== 'show') return null;\n const args = words.slice(words.indexOf(gitSub) + 1);\n if (args.some((arg: string): boolean => arg.startsWith('origin/'))) return null;\n // `git show` without a `<rev>:<path>` operand is a commit view — metadata, not file content.\n if (gitSub === 'show' && !args.some((arg: string): boolean => /^[^-].*:./.test(arg))) return null;\n return `git ${gitSub}`;\n }\n\n // The operands of a reader that are PATHS: flags dropped, and the leading pattern/script dropped\n // for the commands that take one (`grep RE file`, `sed -e prog file`, `awk prog file`).\n private pathOperands(command: string, args: readonly string[]): readonly string[] {\n const positional: string[] = [];\n for (const arg of args) {\n if (arg.startsWith('-')) continue; // a flag, or its attached value\n positional.push(arg);\n }\n if (PATTERN_FIRST.has(command) && positional.length > 0) return positional.slice(1);\n return positional;\n }\n\n /**\n * Is this operand a path inside the workspace? A RELATIVE operand is resolved against the\n * directory the command actually runs in (`baseDir`), so it counts only when that directory is\n * itself in the tree — the old code assumed every relative path meant \"inside the repo\", which is\n * how a command run in a `/private/tmp` scratchpad got judged as reading a stale repo. An\n * absolute path counts only when it is genuinely under workspaceRoot, so `/etc/hosts`,\n * `~/notes.md` and `/tmp/x` are not this repo's problem.\n *\n * Deliberately NOT filesystem-checked: whether the path exists says nothing about staleness, and\n * a stat per operand on the blocking hook path is exactly the cost these guards avoid.\n */\n private isWorkspacePath(operand: string): boolean {\n if (operand.startsWith('~')) return false;\n // The escape hatches are checked on the operand AS TYPED as well, so `cat webpieces.config.json`\n // stays readable from any directory — never wedge the file that turns the guard off.\n if (this.isEscapeHatchPath(operand)) return false;\n const absolute = path.isAbsolute(operand) ? operand : path.resolve(this.baseDir, operand);\n const relative = path.relative(this.workspaceRoot, absolute);\n if (relative.startsWith('..')) return false;\n return !this.isEscapeHatchPath(relative);\n }\n\n // The cwd-walk question: is the directory this command runs in inside the tree being judged?\n private isInWorkspace(dir: string): boolean {\n const relative = path.relative(this.workspaceRoot, path.resolve(dir));\n return !relative.startsWith('..');\n }\n\n // Always-readable paths: webpieces.config.json is the mode-OFF escape hatch (never block the\n // file that turns the guard off), and `.webpieces/` is the guards' own logs/caches — orientation\n // data this guard writes itself, not source that upstream has moved past.\n private isEscapeHatchPath(relative: string): boolean {\n const normalized = relative.replace(/^\\.\\//, '');\n return normalized === 'webpieces.config.json' || normalized.startsWith('.webpieces/');\n }\n\n // `/usr/bin/cat` and `./scripts/cat` both invoke a program named cat; match on the base name.\n private baseName(word: string): string {\n return path.basename(word);\n }\n}\n\n// Commands whose whole job is surfacing file CONTENT or file LISTINGS. Builds, test runners, package\n// managers and git metadata are deliberately absent — they are not how stale bytes enter context.\nconst CONTENT_READERS: ReadonlySet<string> = new Set([\n 'cat', 'bat', 'head', 'tail', 'less', 'more', 'nl', 'strings', 'xxd', 'od',\n 'grep', 'egrep', 'fgrep', 'rg', 'ag', 'ack', 'sed', 'awk', 'jq', 'yq',\n 'ls', 'find', 'tree', 'wc', 'diff',\n]);\n\n// Readers that, given no path, walk the CURRENT DIRECTORY rather than reading stdin — so on a stale\n// main they read the stale tree even with no operand at all.\nconst CWD_WALKERS: ReadonlySet<string> = new Set(['ls', 'find', 'tree', 'rg', 'ag', 'ack']);\n\n// Readers whose FIRST positional argument is a pattern/program, not a path.\nconst PATTERN_FIRST: ReadonlySet<string> = new Set(['grep', 'egrep', 'fgrep', 'rg', 'ag', 'ack', 'sed', 'awk', 'jq', 'yq']);\n"]}
@@ -1,64 +0,0 @@
1
- import { CommandScanner, SegmentJoin } from '../command-scan';
2
- /**
3
- * How a leading refresh-main cure is joined to the work behind it.
4
- *
5
- * `none` the command does not start with a cure at all (or is nothing BUT cure, which the
6
- * row 4 skip list already allowed before this class is ever consulted)
7
- * `short-circuits` `&&` — the work is skipped when the cure fails
8
- * `runs-anyway` `;`, `||`, `&`, a newline — the cure's exit code is discarded
9
- */
10
- export type CureJoinKind = 'none' | 'short-circuits' | 'runs-anyway';
11
- /**
12
- * What the scan found. Data-only, so a class (per CLAUDE.md).
13
- *
14
- * `operator` is the literal shell operator, carried because the refusal message must NAME it: an
15
- * agent that is told "use `&&`" without being told which character it actually typed has to diff the
16
- * two spellings itself, and the whole point of this block is to hand over the one edit that fixes it.
17
- */
18
- export declare class CurePrefix {
19
- readonly kind: CureJoinKind;
20
- readonly operator: SegmentJoin;
21
- constructor(kind: CureJoinKind, operator: SegmentJoin);
22
- }
23
- export declare class CurePrefixScan {
24
- private readonly scanner;
25
- private readonly shell;
26
- constructor(scanner?: CommandScanner);
27
- /**
28
- * Classify the LEADING run of segments as a refresh-main cure, and report the operator that joins
29
- * that run to whatever follows.
30
- *
31
- * The run may carry inert company — a leading `cd '<root>'` (which is how every guard renders a
32
- * remedy that must survive a reset cwd), an `echo`, and the `2>&1 | tail -3` an agent appends by
33
- * reflex. None of those changes what the cure does, and refusing a command because it was piped
34
- * into `tail` is the exact defect ShellSegmentScan was written to end.
35
- */
36
- classify(command: string): CurePrefix;
37
- /**
38
- * Does this segment bring local `main` forward — `git pull`, or the `pnpm wp-sync-main`
39
- * that wraps it?
40
- *
41
- * A `> file` redirect disqualifies it, with `/dev/null` carved out. `>/dev/null 2>&1` on the cure
42
- * is only ever an agent muting chatter, and under `&&` the exit code — the thing that matters —
43
- * still governs. A redirect to a REAL path is a write, and a segment that writes the tree is not
44
- * something to wave a following command through on the strength of.
45
- */
46
- private advancesLocalMain;
47
- /**
48
- * Does this `git pull` bring `origin/main` in, rather than some other branch?
49
- *
50
- * The LAST positional argument is the refspec (`git pull [flags] [remote] [refspec…]`); with no
51
- * refspec at all the pull takes the current branch's upstream, and the current branch is `main`
52
- * wherever this class is consulted, so that form is the cure. `git pull origin some-feature`
53
- * is not: it merges a feature branch into `main` and leaves local `main` still not containing
54
- * `origin/main`, so the work behind the `&&` would read the same stale tree the block is about.
55
- */
56
- private pullsMain;
57
- /**
58
- * Segments that ride along with the cure without being it: shell structure, a `cd`/`echo`, a
59
- * filter the cure was piped into, and a leading `git fetch`. Anything a pipe fed cannot touch the
60
- * tree, and a `cd` is how every guard renders a remedy that must survive a reset cwd — so none of
61
- * them turns a cure prefix into work, and none of them is a cure either.
62
- */
63
- private accompaniesTheCure;
64
- }
@@ -1,133 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CurePrefixScan = exports.CurePrefix = void 0;
4
- const tslib_1 = require("tslib");
5
- const path = tslib_1.__importStar(require("path"));
6
- const command_scan_1 = require("../command-scan");
7
- const shell_segment_scan_1 = require("./shell-segment-scan");
8
- /**
9
- * What the scan found. Data-only, so a class (per CLAUDE.md).
10
- *
11
- * `operator` is the literal shell operator, carried because the refusal message must NAME it: an
12
- * agent that is told "use `&&`" without being told which character it actually typed has to diff the
13
- * two spellings itself, and the whole point of this block is to hand over the one edit that fixes it.
14
- */
15
- class CurePrefix {
16
- kind;
17
- operator;
18
- constructor(kind, operator) {
19
- this.kind = kind;
20
- this.operator = operator;
21
- }
22
- }
23
- exports.CurePrefix = CurePrefix;
24
- const NO_CURE_PREFIX = new CurePrefix('none', 'none');
25
- // The commands that ADVANCE local `main` — the one this repo prescribes, and the raw git verb it
26
- // wraps. Deliberately NOT every `wp-*` bin: a prefix earns the composition allowance because it makes
27
- // the tree fresh, and `pnpm wp-cleanup` does not.
28
- const ADVANCING_BINS = new Set(['wp-sync-main']);
29
- // The refs a pull may name and still be the CURE. `git pull origin some-feature` advances local
30
- // `main` by merging a feature branch into it — which is a different and worse thing than being stale,
31
- // and leaves the work reading a `main` that still does not contain `origin/main`. A pull with NO
32
- // explicit ref takes the current branch's upstream, and the current branch here is `main` by the time
33
- // this class is consulted, so the bare forms are the cure and are covered by the empty case below.
34
- const MAIN_REFS = new Set(['main', 'origin/main', 'main:main', 'origin/main:main']);
35
- // `git fetch` may LEAD the prefix — `git fetch --prune origin main && git pull --ff-only origin main`
36
- // is the shape agents actually type — but it is not itself a cure and never satisfies the prefix on
37
- // its own. A fetch moves the remote-tracking ref and leaves local `main` exactly as far behind as it
38
- // was, so `git fetch && <work>` short-circuits on nothing: the work still reads the stale tree. That
39
- // command gets the ordinary row 6 block, whose message says what a fetch alone does not fix.
40
- const ACCOMPANYING_GIT_SUBCOMMANDS = new Set(['fetch']);
41
- class CurePrefixScan {
42
- scanner;
43
- shell;
44
- constructor(scanner = new command_scan_1.CommandScanner()) {
45
- this.scanner = scanner;
46
- this.shell = new shell_segment_scan_1.ShellSegmentScan(this.scanner);
47
- }
48
- /**
49
- * Classify the LEADING run of segments as a refresh-main cure, and report the operator that joins
50
- * that run to whatever follows.
51
- *
52
- * The run may carry inert company — a leading `cd '<root>'` (which is how every guard renders a
53
- * remedy that must survive a reset cwd), an `echo`, and the `2>&1 | tail -3` an agent appends by
54
- * reflex. None of those changes what the cure does, and refusing a command because it was piped
55
- * into `tail` is the exact defect ShellSegmentScan was written to end.
56
- */
57
- classify(command) {
58
- const segments = this.scanner.segmentsWithJoins(command);
59
- let advanced = false;
60
- for (const segment of segments) {
61
- if (this.advancesLocalMain(segment)) {
62
- advanced = true;
63
- continue;
64
- }
65
- if (this.accompaniesTheCure(segment))
66
- continue;
67
- // The first segment that is neither. Its join is the verdict — but only once something in
68
- // the prefix has actually advanced local `main`; otherwise this is an ordinary command
69
- // that happens to open with a `cd` or a fetch, and row 6 judges it as it always did.
70
- if (!advanced)
71
- return NO_CURE_PREFIX;
72
- return new CurePrefix(segment.join === '&&' ? 'short-circuits' : 'runs-anyway', segment.join);
73
- }
74
- // Nothing but cure and its company — there is no work to protect, and the row 4 skip list has
75
- // already spoken. Never reached from a blocked path; kept explicit rather than implied.
76
- return NO_CURE_PREFIX;
77
- }
78
- /**
79
- * Does this segment bring local `main` forward — `git pull`, or the `pnpm wp-sync-main`
80
- * that wraps it?
81
- *
82
- * A `> file` redirect disqualifies it, with `/dev/null` carved out. `>/dev/null 2>&1` on the cure
83
- * is only ever an agent muting chatter, and under `&&` the exit code — the thing that matters —
84
- * still governs. A redirect to a REAL path is a write, and a segment that writes the tree is not
85
- * something to wave a following command through on the strength of.
86
- */
87
- advancesLocalMain(segment) {
88
- const words = this.shell.effectiveWords(segment.text);
89
- if (words.length === 0)
90
- return false;
91
- if (this.shell.redirectsToFile(words) && !words.some((w) => w.includes('/dev/null'))) {
92
- return false;
93
- }
94
- const gitSub = this.scanner.gitSubcommandOf(words);
95
- if (gitSub !== null)
96
- return gitSub === 'pull' && this.pullsMain(segment);
97
- return this.scanner.runnerStrippedWords(segment.text)
98
- .some((word) => ADVANCING_BINS.has(path.basename(word)));
99
- }
100
- /**
101
- * Does this `git pull` bring `origin/main` in, rather than some other branch?
102
- *
103
- * The LAST positional argument is the refspec (`git pull [flags] [remote] [refspec…]`); with no
104
- * refspec at all the pull takes the current branch's upstream, and the current branch is `main`
105
- * wherever this class is consulted, so that form is the cure. `git pull origin some-feature`
106
- * is not: it merges a feature branch into `main` and leaves local `main` still not containing
107
- * `origin/main`, so the work behind the `&&` would read the same stale tree the block is about.
108
- */
109
- pullsMain(segment) {
110
- const args = this.scanner.gitSubcommandArgs(segment.text, 'pull') ?? [];
111
- // Flags are not positional, and neither is a REDIRECTION token — `2>&1` and `>/dev/null` are
112
- // the two decorations an agent appends by reflex, and reading `2>&1` as the refspec would
113
- // reject the single most common spelling of the cure.
114
- const positional = args.filter((arg) => !arg.startsWith('-') && !/[<>]/.test(arg));
115
- if (positional.length <= 1)
116
- return true;
117
- return MAIN_REFS.has(positional[positional.length - 1]);
118
- }
119
- /**
120
- * Segments that ride along with the cure without being it: shell structure, a `cd`/`echo`, a
121
- * filter the cure was piped into, and a leading `git fetch`. Anything a pipe fed cannot touch the
122
- * tree, and a `cd` is how every guard renders a remedy that must survive a reset cwd — so none of
123
- * them turns a cure prefix into work, and none of them is a cure either.
124
- */
125
- accompaniesTheCure(segment) {
126
- if (this.shell.classify(segment).role !== 'command')
127
- return true;
128
- const gitSub = this.scanner.gitSubcommandOf(this.shell.effectiveWords(segment.text));
129
- return gitSub !== null && ACCOMPANYING_GIT_SUBCOMMANDS.has(gitSub);
130
- }
131
- }
132
- exports.CurePrefixScan = CurePrefixScan;
133
- //# sourceMappingURL=cure-prefix-scan.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cure-prefix-scan.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/ai-hook-rules/src/core/rules/cure-prefix-scan.ts"],"names":[],"mappings":";;;;AAAA,mDAA6B;AAE7B,kDAA8E;AAC9E,6DAAwD;AAoCxD;;;;;;GAMG;AACH,MAAa,UAAU;IACE;IAA6B;IAAlD,YAAqB,IAAkB,EAAW,QAAqB;QAAlD,SAAI,GAAJ,IAAI,CAAc;QAAW,aAAQ,GAAR,QAAQ,CAAa;IAAG,CAAC;CAC9E;AAFD,gCAEC;AAED,MAAM,cAAc,GAAG,IAAI,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAEtD,iGAAiG;AACjG,sGAAsG;AACtG,kDAAkD;AAClD,MAAM,cAAc,GAAwB,IAAI,GAAG,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC;AAEtE,gGAAgG;AAChG,sGAAsG;AACtG,iGAAiG;AACjG,sGAAsG;AACtG,mG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,CAAC;QACxC,OAAO,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;IAC5D,CAAC;IAED;;;;;OAKG;IACK,kBAAkB,CAAC,OAAuB;QAC9C,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,IAAI,KAAK,SAAS;YAAE,OAAO,IAAI,CAAC;QACjE,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;QACrF,OAAO,MAAM,KAAK,IAAI,IAAI,4BAA4B,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACvE,CAAC;CACJ;AApFD,wCAoFC","sourcesContent":["import * as path from 'path';\n\nimport { CommandScanner, CommandSegment, SegmentJoin } from '../command-scan';\nimport { ShellSegmentScan } from './shell-segment-scan';\n\n// ---------------------------------------------------------------------------\n// COMPOSITION — `<cure> && <work>`, and why `<cure> ; <work>` is a different command.\n//\n// Measured, not guessed. Across three days of fleet guard logs an agent blocked on a stale `main`\n// bundled the cure into the same shell call as the work SIXTEEN times, in two shapes:\n//\n// pnpm wp-sync-main >/dev/null 2>&1; git log --oneline -1; sed -n '598,612p' …\n// git fetch --prune origin main -q && git pull --ff-only origin main 2>&1 | tail -1 && sed -n …\n//\n// The FIRST is genuinely unsafe and stays blocked. `;` discards the cure's exit code, so the `sed`\n// runs against still-stale content whether the pull hit a conflict, a dirty tree or no network — and\n// in 7 of the 9 observed cases the agent had also written `>/dev/null 2>&1`, so the failure was\n// invisible as well as ignored. The two-step really is safer there, and not for a bureaucratic\n// reason: the NEXT tool call is a fresh guard evaluation that recomputes `localMain` against\n// `originMain`, so a pull that failed re-blocks. An allowed `;` compound never gets that second look.\n//\n// The SECOND is the shell already enforcing exactly the property the guard wants. `&&` short-circuits:\n// if the cure exits non-zero the work never runs. Blocking it bought nothing and cost a round trip,\n// which is why the fleet audit files it as a TOOLING defect rather than an agent one.\n//\n// So this class answers one question — *does this command START with a refresh-main cure, and what\n// operator joins it to the rest?* — and the guard turns that into allow / refuse-and-say-which.\n// ---------------------------------------------------------------------------\n\n/**\n * How a leading refresh-main cure is joined to the work behind it.\n *\n * `none` the command does not start with a cure at all (or is nothing BUT cure, which the\n * row 4 skip list already allowed before this class is ever consulted)\n * `short-circuits` `&&` — the work is skipped when the cure fails\n * `runs-anyway` `;`, `||`, `&`, a newline — the cure's exit code is discarded\n */\nexport type CureJoinKind = 'none' | 'short-circuits' | 'runs-anyway';\n\n/**\n * What the scan found. Data-only, so a class (per CLAUDE.md).\n *\n * `operator` is the literal shell operator, carried because the refusal message must NAME it: an\n * agent that is told \"use `&&`\" without being told which character it actually typed has to diff the\n * two spellings itself, and the whole point of this block is to hand over the one edit that fixes it.\n */\nexport class CurePrefix {\n constructor(readonly kind: CureJoinKind, readonly operator: SegmentJoin) {}\n}\n\nconst NO_CURE_PREFIX = new CurePrefix('none', 'none');\n\n// The commands that ADVANCE local `main` — the one this repo prescribes, and the raw git verb it\n// wraps. Deliberately NOT every `wp-*` bin: a prefix earns the composition allowance because it makes\n// the tree fresh, and `pnpm wp-cleanup` does not.\nconst ADVANCING_BINS: ReadonlySet<string> = new Set(['wp-sync-main']);\n\n// The refs a pull may name and still be the CURE. `git pull origin some-feature` advances local\n// `main` by merging a feature branch into it — which is a different and worse thing than being stale,\n// and leaves the work reading a `main` that still does not contain `origin/main`. A pull with NO\n// explicit ref takes the current branch's upstream, and the current branch here is `main` by the time\n// this class is consulted, so the bare forms are the cure and are covered by the empty case below.\nconst MAIN_REFS: ReadonlySet<string> = new Set(['main', 'origin/main', 'main:main', 'origin/main:main']);\n\n// `git fetch` may LEAD the prefix — `git fetch --prune origin main && git pull --ff-only origin main`\n// is the shape agents actually type — but it is not itself a cure and never satisfies the prefix on\n// its own. A fetch moves the remote-tracking ref and leaves local `main` exactly as far behind as it\n// was, so `git fetch && <work>` short-circuits on nothing: the work still reads the stale tree. That\n// command gets the ordinary row 6 block, whose message says what a fetch alone does not fix.\nconst ACCOMPANYING_GIT_SUBCOMMANDS: ReadonlySet<string> = new Set(['fetch']);\n\nexport class CurePrefixScan {\n private readonly shell: ShellSegmentScan;\n\n constructor(private readonly scanner: CommandScanner = new CommandScanner()) {\n this.shell = new ShellSegmentScan(this.scanner);\n }\n\n /**\n * Classify the LEADING run of segments as a refresh-main cure, and report the operator that joins\n * that run to whatever follows.\n *\n * The run may carry inert company — a leading `cd '<root>'` (which is how every guard renders a\n * remedy that must survive a reset cwd), an `echo`, and the `2>&1 | tail -3` an agent appends by\n * reflex. None of those changes what the cure does, and refusing a command because it was piped\n * into `tail` is the exact defect ShellSegmentScan was written to end.\n */\n classify(command: string): CurePrefix {\n const segments = this.scanner.segmentsWithJoins(command);\n let advanced = false;\n for (const segment of segments) {\n if (this.advancesLocalMain(segment)) { advanced = true; continue; }\n if (this.accompaniesTheCure(segment)) continue;\n // The first segment that is neither. Its join is the verdict — but only once something in\n // the prefix has actually advanced local `main`; otherwise this is an ordinary command\n // that happens to open with a `cd` or a fetch, and row 6 judges it as it always did.\n if (!advanced) return NO_CURE_PREFIX;\n return new CurePrefix(segment.join === '&&' ? 'short-circuits' : 'runs-anyway', segment.join);\n }\n // Nothing but cure and its company — there is no work to protect, and the row 4 skip list has\n // already spoken. Never reached from a blocked path; kept explicit rather than implied.\n return NO_CURE_PREFIX;\n }\n\n /**\n * Does this segment bring local `main` forward — `git pull`, or the `pnpm wp-sync-main`\n * that wraps it?\n *\n * A `> file` redirect disqualifies it, with `/dev/null` carved out. `>/dev/null 2>&1` on the cure\n * is only ever an agent muting chatter, and under `&&` the exit code — the thing that matters —\n * still governs. A redirect to a REAL path is a write, and a segment that writes the tree is not\n * something to wave a following command through on the strength of.\n */\n private advancesLocalMain(segment: CommandSegment): boolean {\n const words = this.shell.effectiveWords(segment.text);\n if (words.length === 0) return false;\n if (this.shell.redirectsToFile(words) && !words.some((w: string): boolean => w.includes('/dev/null'))) {\n return false;\n }\n const gitSub = this.scanner.gitSubcommandOf(words);\n if (gitSub !== null) return gitSub === 'pull' && this.pullsMain(segment);\n return this.scanner.runnerStrippedWords(segment.text)\n .some((word: string): boolean => ADVANCING_BINS.has(path.basename(word)));\n }\n\n /**\n * Does this `git pull` bring `origin/main` in, rather than some other branch?\n *\n * The LAST positional argument is the refspec (`git pull [flags] [remote] [refspec…]`); with no\n * refspec at all the pull takes the current branch's upstream, and the current branch is `main`\n * wherever this class is consulted, so that form is the cure. `git pull origin some-feature`\n * is not: it merges a feature branch into `main` and leaves local `main` still not containing\n * `origin/main`, so the work behind the `&&` would read the same stale tree the block is about.\n */\n private pullsMain(segment: CommandSegment): boolean {\n const args = this.scanner.gitSubcommandArgs(segment.text, 'pull') ?? [];\n // Flags are not positional, and neither is a REDIRECTION token — `2>&1` and `>/dev/null` are\n // the two decorations an agent appends by reflex, and reading `2>&1` as the refspec would\n // reject the single most common spelling of the cure.\n const positional = args.filter((arg: string): boolean => !arg.startsWith('-') && !/[<>]/.test(arg));\n if (positional.length <= 1) return true;\n return MAIN_REFS.has(positional[positional.length - 1]);\n }\n\n /**\n * Segments that ride along with the cure without being it: shell structure, a `cd`/`echo`, a\n * filter the cure was piped into, and a leading `git fetch`. Anything a pipe fed cannot touch the\n * tree, and a `cd` is how every guard renders a remedy that must survive a reset cwd — so none of\n * them turns a cure prefix into work, and none of them is a cure either.\n */\n private accompaniesTheCure(segment: CommandSegment): boolean {\n if (this.shell.classify(segment).role !== 'command') return true;\n const gitSub = this.scanner.gitSubcommandOf(this.shell.effectiveWords(segment.text));\n return gitSub !== null && ACCOMPANYING_GIT_SUBCOMMANDS.has(gitSub);\n }\n}\n"]}
@@ -1,121 +0,0 @@
1
- import { BranchStateGuardConfig } from '@webpieces/rules-config';
2
- import type { FileContext, Violation } from '../types';
3
- import { FileRuleBase } from '../rule-base';
4
- import { FixHint } from '../fix-hint';
5
- /**
6
- * Comprehensive "are you on a proper feature branch?" guard — the single rule that blocks edits when
7
- * the branch isn't a healthy place to work. Four states, in priority order:
8
- * 1. On main (checked SYNCHRONOUSLY here) → block: create a feature branch.
9
- * 2. Branch already merged into main (merged PR) → block: your work is in main, branch off fresh.
10
- * 3. No fork point with origin/main → block: squash onto a new branch.
11
- * 4. origin/main moved & touches your files → block: merge main first.
12
- * States 2–4 are PRECOMPUTED into `.webpieces/main-sync-status.json` by the detached refresher, so
13
- * this check does NO network git (only a fast local `git rev-parse` for state 1). On every call it
14
- * fire-and-forget spawns the refresher so the NEXT call is fresh. Runs in the GUARDS hook (it's a
15
- * hookGuard); file-scoped, so only Write/Edit/MultiEdit are guarded — Bash passes through so the AI
16
- * can still run `pnpm wp-start-upsert-pr` and the rest of the recovery flow.
17
- *
18
- * ── STATE 1 IS UNCONDITIONAL, AND `B` NO LONGER TRACKS `E` HERE ──────────────────────────────────
19
- *
20
- * Earlier docblocks in this family argued that the Bash half of "on `main`" should match this one
21
- * exactly — one `git rev-parse`, no cache, so it fires on the first call of a session. That argument
22
- * has been split, deliberately, and the two halves now differ:
23
- *
24
- * `E` (here) blocks on ANY `main`, current or stale.
25
- * `B` (stale-main-bash-guard) blocks only once local `main` is KNOWN BEHIND `origin/main`.
26
- *
27
- * The hazards are not the same hazard. A WRITE on `main` puts work where it cannot be reviewed, cannot
28
- * be reverted as a unit, and is one `git checkout` from being lost — none of which depends on how
29
- * current `main` is, so nothing about freshness could make this block right or wrong. A READ or a
30
- * BUILD on a CURRENT `main` harms nothing at all, and denying it strands the agent immediately after
31
- * `pnpm wp-sync-main` — the very command this repo prescribes — put it there.
32
- *
33
- * So do NOT "restore the symmetry" by gating this on the cache. That would make writes on `main`
34
- * permitted for the whole first call of every session (the cache is populated for the NEXT call), and
35
- * permanently in a multi-worktree repo where another tree can hold the refresh lock. That ordering is
36
- * the most load-bearing thing in the L2 table, which is why row 5 sits ABOVE the cache divider.
37
- *
38
- * ── WHICH TREE IS JUDGED: THE ONE THAT OWNS THE FILE, NEVER THE ONE THE SESSION SITS IN ─────────────
39
- *
40
- * Every state above is a property of A BRANCH IN A CHECKOUT, so the first question this guard answers is
41
- * WHICH checkout — and the answer comes from the TARGET PATH, through TargetTreeResolver, which is
42
- * EffectiveTreeResolver asked about a file instead of a cwd. It is emphatically NOT `ctx.workspaceRoot`:
43
- * that is the walk-up from the session's cwd to the governing `webpieces.config.json`, and for a
44
- * main-session edit into an agent worktree it names the PRIMARY clone.
45
- *
46
- * Issue #851 is the incident. Claude Code checks a worktree out INSIDE the repo at
47
- * `<repo>/.claude/worktrees/agent-XXXX`, so a containment test answers "primary" for a path that is
48
- * plainly the worktree's. This guard then read the branch-keyed main-sync cache under the PRIMARY's
49
- * branch and enforced that verdict on a file belonging to a clean branch in another tree. The cache was
50
- * not stale and was not wrong — the correct entry sat in the same JSON file, one key over. Only the
51
- * lookup key was. Four tool calls were refused, including the `summary.json` that `wp-review-upsert-pr`
52
- * requires before `wp-finish-upsert-pr` will open a PR, which is the shape where this wedges the
53
- * sanctioned flow rather than merely annoying somebody.
54
- *
55
- * Two consequences worth stating out loud, because both were argued the other way at some point:
56
- *
57
- * - The DENY NAMES THE TREE (JudgedTree.header) and, when the judged tree is not the session's, the
58
- * `pnpm --dir=<tree>` form of the cure. A resolution nobody can see is a resolution nobody can
59
- * contradict, and the printed cure was measurably a no-op for the tree it was aimed at.
60
- * - DETACHED HEAD in the target tree fails OPEN, logged. There is no branch name, so there is no map
61
- * key and nothing to judge — matrix row 14. It used to reach here as the literal branch `HEAD`, miss
62
- * in the cache and fail open as `no-sync-cache`, which is the right verdict recorded under a reason
63
- * that says something else happened.
64
- */
65
- export declare class FeatureBranchGuardRule extends FileRuleBase<BranchStateGuardConfig> {
66
- constructor(config: BranchStateGuardConfig);
67
- readonly description = "Block edits unless you are on a proper feature branch (not main, not already-merged, forked, in sync with main).";
68
- readonly files: string[];
69
- readonly defaultOptions: {
70
- branchNamingConvention: string;
71
- hangTimeoutMinutes: number;
72
- };
73
- readonly fixHint: FixHint;
74
- check(ctx: FileContext): readonly Violation[];
75
- /**
76
- * WHICH TREE this decision was judged against, for the log.
77
- *
78
- * The trail already carried a `tree=` field, but it is stamped from the root the decision is LOGGED
79
- * to (the session's), so during issue #851 every misfired block recorded `tree=primary` for a path
80
- * under `.claude/worktrees/` and read as perfectly ordinary. This one is the root the verdict was
81
- * actually computed from, so the two disagreeing is the defect, visible in one grep.
82
- */
83
- private treeSummary;
84
- private cacheSummary;
85
- /**
86
- * The guard could not ESTABLISH the state it judges on, so it judged nothing.
87
- *
88
- * A sibling of allow() rather than a reason string passed to it, because the difference has to
89
- * reach the LOG as a value: `ALLOW_FAIL_OPEN` vs `ALLOW`. It was previously a `' (fail-open)'`
90
- * suffix on the free-text reason, which meant an abstention and a real approval were the same
91
- * verdict and the abstentions could not be counted — so nobody could tell whether these guards
92
- * were protecting anything or quietly standing down. Never block on data you could not
93
- * establish; but say out loud, in a field, that you did not establish it.
94
- */
95
- private failOpen;
96
- private allow;
97
- private block;
98
- private logDecision;
99
- private currentBranch;
100
- /**
101
- * The Write/Edit half of row 5. Same three points as stale-main-bash-guard's deny, told for THIS
102
- * surface: reading main while you plan is legitimate and is not what got blocked; the feature
103
- * branch is the unit of work; and a `main` that is behind makes the reads wrong too, so getting
104
- * current is not an extra step, it is what makes the plan you are about to write against correct.
105
- *
106
- * Per-surface, deliberately: this guard sees only Write/Edit, so it says the WRITE was blocked.
107
- * (read-stale-guard is the one that can close Read, and only once `main` falls behind.)
108
- *
109
- * ONE CURE, and it is the dirty-safe one. This half used to print `git pull origin main` and then
110
- * "create a feature branch" — but this guard fires on a WRITE, so uncommitted work is the LIKELY
111
- * state, and a pull is exactly the form that is not a clean fast-forward there. Its two siblings
112
- * (stale-main-bash-guard's rows-6/7 deny, StaleMainMessage.forReads) both prescribe
113
- * `git fetch origin main && git checkout -b <new> origin/main`, which fetches AND carries the
114
- * uncommitted work onto the new branch. Three halves of one row printing one cure is the point:
115
- * a fragile cure is a defect here even when it often happens to work.
116
- */
117
- private onMainMessage;
118
- private alreadyMergedMessage;
119
- private conflictMessage;
120
- private noForkPointMessage;
121
- }