@webpieces/ai-hook-rules 0.4.839 → 0.4.841

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (390) hide show
  1. package/README.md +12 -140
  2. package/package.json +7 -15
  3. package/src/adapters/hook-app-fixtures.d.ts +1 -1
  4. package/src/adapters/hook-app-fixtures.js +0 -8
  5. package/src/adapters/hook-app-fixtures.js.map +1 -1
  6. package/src/adapters/hook-core.d.ts +1 -21
  7. package/src/adapters/hook-core.js +22 -341
  8. package/src/adapters/hook-core.js.map +1 -1
  9. package/src/core/load-rules.d.ts +4 -39
  10. package/src/core/load-rules.js +15 -127
  11. package/src/core/load-rules.js.map +1 -1
  12. package/src/core/rules/catch-error-pattern.d.ts +3 -3
  13. package/src/core/rules/catch-error-pattern.js +13 -13
  14. package/src/core/rules/catch-error-pattern.js.map +1 -1
  15. package/src/core/rules/index.d.ts +1 -14
  16. package/src/core/rules/index.js +1 -17
  17. package/src/core/rules/index.js.map +1 -1
  18. package/src/core/rules/match-rule.d.ts +3 -3
  19. package/src/core/rules/match-rule.js +6 -6
  20. package/src/core/rules/match-rule.js.map +1 -1
  21. package/src/core/rules/max-file-lines.d.ts +3 -3
  22. package/src/core/rules/max-file-lines.js +7 -7
  23. package/src/core/rules/max-file-lines.js.map +1 -1
  24. package/src/core/rules/no-any-unknown.d.ts +3 -3
  25. package/src/core/rules/no-any-unknown.js +6 -6
  26. package/src/core/rules/no-any-unknown.js.map +1 -1
  27. package/src/core/rules/no-custom-css.d.ts +3 -3
  28. package/src/core/rules/no-custom-css.js +7 -7
  29. package/src/core/rules/no-custom-css.js.map +1 -1
  30. package/src/core/rules/no-destructure.d.ts +3 -3
  31. package/src/core/rules/no-destructure.js +7 -7
  32. package/src/core/rules/no-destructure.js.map +1 -1
  33. package/src/core/rules/no-implicit-any.d.ts +3 -3
  34. package/src/core/rules/no-implicit-any.js +6 -6
  35. package/src/core/rules/no-implicit-any.js.map +1 -1
  36. package/src/core/rules/no-js-files.d.ts +3 -3
  37. package/src/core/rules/no-js-files.js +6 -6
  38. package/src/core/rules/no-js-files.js.map +1 -1
  39. package/src/core/rules/no-process-exit-outside-main.d.ts +3 -3
  40. package/src/core/rules/no-process-exit-outside-main.js +7 -7
  41. package/src/core/rules/no-process-exit-outside-main.js.map +1 -1
  42. package/src/core/rules/no-symbol-di-tokens.d.ts +3 -3
  43. package/src/core/rules/no-symbol-di-tokens.js +7 -7
  44. package/src/core/rules/no-symbol-di-tokens.js.map +1 -1
  45. package/src/core/rules/no-unmanaged-exceptions.d.ts +3 -3
  46. package/src/core/rules/no-unmanaged-exceptions.js +9 -9
  47. package/src/core/rules/no-unmanaged-exceptions.js.map +1 -1
  48. package/src/core/rules/require-return-type.d.ts +3 -3
  49. package/src/core/rules/require-return-type.js +6 -6
  50. package/src/core/rules/require-return-type.js.map +1 -1
  51. package/src/core/rules/throw-cause-required.d.ts +3 -3
  52. package/src/core/rules/throw-cause-required.js +9 -9
  53. package/src/core/rules/throw-cause-required.js.map +1 -1
  54. package/src/core/rules/validate-ts-in-src.d.ts +3 -3
  55. package/src/core/rules/validate-ts-in-src.js +7 -7
  56. package/src/core/rules/validate-ts-in-src.js.map +1 -1
  57. package/src/core/runner.d.ts +10 -19
  58. package/src/core/runner.js +24 -622
  59. package/src/core/runner.js.map +1 -1
  60. package/src/index.d.ts +2 -15
  61. package/src/index.js +4 -54
  62. package/src/index.js.map +1 -1
  63. package/openclaw.plugin.json +0 -15
  64. package/src/adapters/agent-adapters.d.ts +0 -13
  65. package/src/adapters/agent-adapters.js +0 -23
  66. package/src/adapters/agent-adapters.js.map +0 -1
  67. package/src/adapters/agent-payload.d.ts +0 -48
  68. package/src/adapters/agent-payload.js +0 -30
  69. package/src/adapters/agent-payload.js.map +0 -1
  70. package/src/adapters/agent-response.d.ts +0 -5
  71. package/src/adapters/agent-response.js +0 -86
  72. package/src/adapters/agent-response.js.map +0 -1
  73. package/src/adapters/claude-code-adapter.d.ts +0 -26
  74. package/src/adapters/claude-code-adapter.js +0 -69
  75. package/src/adapters/claude-code-adapter.js.map +0 -1
  76. package/src/adapters/codex-adapter.d.ts +0 -19
  77. package/src/adapters/codex-adapter.js +0 -48
  78. package/src/adapters/codex-adapter.js.map +0 -1
  79. package/src/adapters/codex-subagent-guard.d.ts +0 -45
  80. package/src/adapters/codex-subagent-guard.js +0 -88
  81. package/src/adapters/codex-subagent-guard.js.map +0 -1
  82. package/src/adapters/detect-ai.d.ts +0 -70
  83. package/src/adapters/detect-ai.js +0 -82
  84. package/src/adapters/detect-ai.js.map +0 -1
  85. package/src/adapters/guards-hook.d.ts +0 -3
  86. package/src/adapters/guards-hook.js +0 -30
  87. package/src/adapters/guards-hook.js.map +0 -1
  88. package/src/adapters/openclaw-plugin.d.ts +0 -14
  89. package/src/adapters/openclaw-plugin.js +0 -87
  90. package/src/adapters/openclaw-plugin.js.map +0 -1
  91. package/src/adapters/review-identity-stamper.d.ts +0 -20
  92. package/src/adapters/review-identity-stamper.js +0 -34
  93. package/src/adapters/review-identity-stamper.js.map +0 -1
  94. package/src/bin/codex-trust.d.ts +0 -105
  95. package/src/bin/codex-trust.js +0 -205
  96. package/src/bin/codex-trust.js.map +0 -1
  97. package/src/bin/dev-hook-install.d.ts +0 -1
  98. package/src/bin/dev-hook-install.js +0 -82
  99. package/src/bin/dev-hook-install.js.map +0 -1
  100. package/src/bin/dev-hook-uninstall.d.ts +0 -1
  101. package/src/bin/dev-hook-uninstall.js +0 -45
  102. package/src/bin/dev-hook-uninstall.js.map +0 -1
  103. package/src/bin/hook-registration.d.ts +0 -429
  104. package/src/bin/hook-registration.js +0 -661
  105. package/src/bin/hook-registration.js.map +0 -1
  106. package/src/bin/install-entry.d.ts +0 -19
  107. package/src/bin/install-entry.js +0 -128
  108. package/src/bin/install-entry.js.map +0 -1
  109. package/src/bin/l0-allowlist.d.ts +0 -49
  110. package/src/bin/l0-allowlist.js +0 -528
  111. package/src/bin/l0-allowlist.js.map +0 -1
  112. package/src/bin/l0-codex-read.d.ts +0 -21
  113. package/src/bin/l0-codex-read.js +0 -109
  114. package/src/bin/l0-codex-read.js.map +0 -1
  115. package/src/bin/l0-decide.d.ts +0 -50
  116. package/src/bin/l0-decide.js +0 -103
  117. package/src/bin/l0-decide.js.map +0 -1
  118. package/src/bin/l0-entry.d.ts +0 -103
  119. package/src/bin/l0-entry.js +0 -98
  120. package/src/bin/l0-entry.js.map +0 -1
  121. package/src/bin/l0-ignored-tools.d.ts +0 -38
  122. package/src/bin/l0-ignored-tools.js +0 -44
  123. package/src/bin/l0-ignored-tools.js.map +0 -1
  124. package/src/bin/managed-env.d.ts +0 -46
  125. package/src/bin/managed-env.js +0 -50
  126. package/src/bin/managed-env.js.map +0 -1
  127. package/src/bin/neighbour-hooks.d.ts +0 -42
  128. package/src/bin/neighbour-hooks.js +0 -177
  129. package/src/bin/neighbour-hooks.js.map +0 -1
  130. package/src/bin/reviewer-agent.d.ts +0 -19
  131. package/src/bin/reviewer-agent.js +0 -135
  132. package/src/bin/reviewer-agent.js.map +0 -1
  133. package/src/bin/settings-shape.d.ts +0 -37
  134. package/src/bin/settings-shape.js +0 -17
  135. package/src/bin/settings-shape.js.map +0 -1
  136. package/src/bin/setup-config.d.ts +0 -19
  137. package/src/bin/setup-config.js +0 -370
  138. package/src/bin/setup-config.js.map +0 -1
  139. package/src/bin/setup.d.ts +0 -78
  140. package/src/bin/setup.js +0 -400
  141. package/src/bin/setup.js.map +0 -1
  142. package/src/bin/shim-audit-log.d.ts +0 -119
  143. package/src/bin/shim-audit-log.js +0 -286
  144. package/src/bin/shim-audit-log.js.map +0 -1
  145. package/src/bin/shim-deny-reason.d.ts +0 -1
  146. package/src/bin/shim-deny-reason.js +0 -244
  147. package/src/bin/shim-deny-reason.js.map +0 -1
  148. package/src/bin/shim-drift-fix.d.ts +0 -1
  149. package/src/bin/shim-drift-fix.js +0 -72
  150. package/src/bin/shim-drift-fix.js.map +0 -1
  151. package/src/bin/shim-testkit.d.ts +0 -107
  152. package/src/bin/shim-testkit.js +0 -197
  153. package/src/bin/shim-testkit.js.map +0 -1
  154. package/src/bin/shim-version-drift.d.ts +0 -1
  155. package/src/bin/shim-version-drift.js +0 -164
  156. package/src/bin/shim-version-drift.js.map +0 -1
  157. package/src/bin/shim.d.ts +0 -16
  158. package/src/bin/shim.js +0 -636
  159. package/src/bin/shim.js.map +0 -1
  160. package/src/bin/upgrade-shim.d.ts +0 -18
  161. package/src/bin/upgrade-shim.js +0 -283
  162. package/src/bin/upgrade-shim.js.map +0 -1
  163. package/src/core/ai-type-context.d.ts +0 -36
  164. package/src/core/ai-type-context.js +0 -45
  165. package/src/core/ai-type-context.js.map +0 -1
  166. package/src/core/apply-patch-parse.d.ts +0 -36
  167. package/src/core/apply-patch-parse.js +0 -154
  168. package/src/core/apply-patch-parse.js.map +0 -1
  169. package/src/core/build-context.d.ts +0 -10
  170. package/src/core/build-context.js +0 -66
  171. package/src/core/build-context.js.map +0 -1
  172. package/src/core/command-scan.d.ts +0 -122
  173. package/src/core/command-scan.js +0 -282
  174. package/src/core/command-scan.js.map +0 -1
  175. package/src/core/custom-rule-adapter.d.ts +0 -22
  176. package/src/core/custom-rule-adapter.js +0 -50
  177. package/src/core/custom-rule-adapter.js.map +0 -1
  178. package/src/core/decision-log.d.ts +0 -190
  179. package/src/core/decision-log.js +0 -406
  180. package/src/core/decision-log.js.map +0 -1
  181. package/src/core/delete-scoped-rules.d.ts +0 -8
  182. package/src/core/delete-scoped-rules.js +0 -31
  183. package/src/core/delete-scoped-rules.js.map +0 -1
  184. package/src/core/disable-directives.d.ts +0 -8
  185. package/src/core/disable-directives.js +0 -80
  186. package/src/core/disable-directives.js.map +0 -1
  187. package/src/core/effective-tree.d.ts +0 -204
  188. package/src/core/effective-tree.js +0 -277
  189. package/src/core/effective-tree.js.map +0 -1
  190. package/src/core/excluded-path-escape.d.ts +0 -101
  191. package/src/core/excluded-path-escape.js +0 -236
  192. package/src/core/excluded-path-escape.js.map +0 -1
  193. package/src/core/excluded-paths.d.ts +0 -23
  194. package/src/core/excluded-paths.js +0 -54
  195. package/src/core/excluded-paths.js.map +0 -1
  196. package/src/core/fix-hint.d.ts +0 -40
  197. package/src/core/fix-hint.js +0 -53
  198. package/src/core/fix-hint.js.map +0 -1
  199. package/src/core/force-to-root.d.ts +0 -32
  200. package/src/core/force-to-root.js +0 -60
  201. package/src/core/force-to-root.js.map +0 -1
  202. package/src/core/guard-index-doc.d.ts +0 -63
  203. package/src/core/guard-index-doc.js +0 -172
  204. package/src/core/guard-index-doc.js.map +0 -1
  205. package/src/core/instruct-ai-writer.d.ts +0 -1
  206. package/src/core/instruct-ai-writer.js +0 -6
  207. package/src/core/instruct-ai-writer.js.map +0 -1
  208. package/src/core/l0-fault-codes.d.ts +0 -85
  209. package/src/core/l0-fault-codes.js +0 -121
  210. package/src/core/l0-fault-codes.js.map +0 -1
  211. package/src/core/l0-matrix.d.ts +0 -114
  212. package/src/core/l0-matrix.js +0 -416
  213. package/src/core/l0-matrix.js.map +0 -1
  214. package/src/core/l0-tooling-doc.d.ts +0 -45
  215. package/src/core/l0-tooling-doc.js +0 -258
  216. package/src/core/l0-tooling-doc.js.map +0 -1
  217. package/src/core/l1-doc.d.ts +0 -7
  218. package/src/core/l1-doc.js +0 -340
  219. package/src/core/l1-doc.js.map +0 -1
  220. package/src/core/l1-matrix-doc.d.ts +0 -31
  221. package/src/core/l1-matrix-doc.js +0 -111
  222. package/src/core/l1-matrix-doc.js.map +0 -1
  223. package/src/core/l1-rows.d.ts +0 -167
  224. package/src/core/l1-rows.js +0 -262
  225. package/src/core/l1-rows.js.map +0 -1
  226. package/src/core/l2-doc.d.ts +0 -7
  227. package/src/core/l2-doc.js +0 -385
  228. package/src/core/l2-doc.js.map +0 -1
  229. package/src/core/l2-matrix-doc.d.ts +0 -23
  230. package/src/core/l2-matrix-doc.js +0 -72
  231. package/src/core/l2-matrix-doc.js.map +0 -1
  232. package/src/core/l2-row.d.ts +0 -54
  233. package/src/core/l2-row.js +0 -75
  234. package/src/core/l2-row.js.map +0 -1
  235. package/src/core/l2-rows.d.ts +0 -56
  236. package/src/core/l2-rows.js +0 -272
  237. package/src/core/l2-rows.js.map +0 -1
  238. package/src/core/load-config.d.ts +0 -1
  239. package/src/core/load-config.js +0 -9
  240. package/src/core/load-config.js.map +0 -1
  241. package/src/core/log-stream.d.ts +0 -117
  242. package/src/core/log-stream.js +0 -156
  243. package/src/core/log-stream.js.map +0 -1
  244. package/src/core/log-streams.d.ts +0 -48
  245. package/src/core/log-streams.js +0 -55
  246. package/src/core/log-streams.js.map +0 -1
  247. package/src/core/log-target.d.ts +0 -21
  248. package/src/core/log-target.js +0 -29
  249. package/src/core/log-target.js.map +0 -1
  250. package/src/core/main-sync-log.d.ts +0 -16
  251. package/src/core/main-sync-log.js +0 -105
  252. package/src/core/main-sync-log.js.map +0 -1
  253. package/src/core/main-sync-refresh.d.ts +0 -39
  254. package/src/core/main-sync-refresh.js +0 -96
  255. package/src/core/main-sync-refresh.js.map +0 -1
  256. package/src/core/main-sync-timeout.d.ts +0 -32
  257. package/src/core/main-sync-timeout.js +0 -94
  258. package/src/core/main-sync-timeout.js.map +0 -1
  259. package/src/core/matrix-cures.d.ts +0 -12
  260. package/src/core/matrix-cures.js +0 -56
  261. package/src/core/matrix-cures.js.map +0 -1
  262. package/src/core/missing-directory.d.ts +0 -38
  263. package/src/core/missing-directory.js +0 -66
  264. package/src/core/missing-directory.js.map +0 -1
  265. package/src/core/read-only-inspection.d.ts +0 -34
  266. package/src/core/read-only-inspection.js +0 -88
  267. package/src/core/read-only-inspection.js.map +0 -1
  268. package/src/core/rejection-log.d.ts +0 -9
  269. package/src/core/rejection-log.js +0 -258
  270. package/src/core/rejection-log.js.map +0 -1
  271. package/src/core/report.d.ts +0 -21
  272. package/src/core/report.js +0 -73
  273. package/src/core/report.js.map +0 -1
  274. package/src/core/rule-base.d.ts +0 -39
  275. package/src/core/rule-base.js +0 -36
  276. package/src/core/rule-base.js.map +0 -1
  277. package/src/core/rules/branch-creation-guard.d.ts +0 -113
  278. package/src/core/rules/branch-creation-guard.js +0 -422
  279. package/src/core/rules/branch-creation-guard.js.map +0 -1
  280. package/src/core/rules/branch-switch-scan.d.ts +0 -43
  281. package/src/core/rules/branch-switch-scan.js +0 -132
  282. package/src/core/rules/branch-switch-scan.js.map +0 -1
  283. package/src/core/rules/build-output-pipe-guard.d.ts +0 -56
  284. package/src/core/rules/build-output-pipe-guard.js +0 -120
  285. package/src/core/rules/build-output-pipe-guard.js.map +0 -1
  286. package/src/core/rules/build-output-pipe-scan.d.ts +0 -47
  287. package/src/core/rules/build-output-pipe-scan.js +0 -84
  288. package/src/core/rules/build-output-pipe-scan.js.map +0 -1
  289. package/src/core/rules/cap-remedies.d.ts +0 -39
  290. package/src/core/rules/cap-remedies.js +0 -59
  291. package/src/core/rules/cap-remedies.js.map +0 -1
  292. package/src/core/rules/commit-message-substitution-guard.d.ts +0 -72
  293. package/src/core/rules/commit-message-substitution-guard.js +0 -134
  294. package/src/core/rules/commit-message-substitution-guard.js.map +0 -1
  295. package/src/core/rules/commit-message-substitution-scan.d.ts +0 -42
  296. package/src/core/rules/commit-message-substitution-scan.js +0 -145
  297. package/src/core/rules/commit-message-substitution-scan.js.map +0 -1
  298. package/src/core/rules/content-read-scan.d.ts +0 -76
  299. package/src/core/rules/content-read-scan.js +0 -176
  300. package/src/core/rules/content-read-scan.js.map +0 -1
  301. package/src/core/rules/cure-prefix-scan.d.ts +0 -64
  302. package/src/core/rules/cure-prefix-scan.js +0 -133
  303. package/src/core/rules/cure-prefix-scan.js.map +0 -1
  304. package/src/core/rules/feature-branch-guard.d.ts +0 -121
  305. package/src/core/rules/feature-branch-guard.js +0 -326
  306. package/src/core/rules/feature-branch-guard.js.map +0 -1
  307. package/src/core/rules/judged-tree.d.ts +0 -66
  308. package/src/core/rules/judged-tree.js +0 -97
  309. package/src/core/rules/judged-tree.js.map +0 -1
  310. package/src/core/rules/main-freshness.d.ts +0 -37
  311. package/src/core/rules/main-freshness.js +0 -61
  312. package/src/core/rules/main-freshness.js.map +0 -1
  313. package/src/core/rules/merge-in-progress-guard.d.ts +0 -17
  314. package/src/core/rules/merge-in-progress-guard.js +0 -122
  315. package/src/core/rules/merge-in-progress-guard.js.map +0 -1
  316. package/src/core/rules/merged-branch-bash-guard.d.ts +0 -62
  317. package/src/core/rules/merged-branch-bash-guard.js +0 -170
  318. package/src/core/rules/merged-branch-bash-guard.js.map +0 -1
  319. package/src/core/rules/merged-branch-message.d.ts +0 -59
  320. package/src/core/rules/merged-branch-message.js +0 -137
  321. package/src/core/rules/merged-branch-message.js.map +0 -1
  322. package/src/core/rules/pr-creation-or-push-guard.d.ts +0 -26
  323. package/src/core/rules/pr-creation-or-push-guard.js +0 -146
  324. package/src/core/rules/pr-creation-or-push-guard.js.map +0 -1
  325. package/src/core/rules/pr-merge-guard.d.ts +0 -36
  326. package/src/core/rules/pr-merge-guard.js +0 -86
  327. package/src/core/rules/pr-merge-guard.js.map +0 -1
  328. package/src/core/rules/read-stale-guard.d.ts +0 -136
  329. package/src/core/rules/read-stale-guard.js +0 -326
  330. package/src/core/rules/read-stale-guard.js.map +0 -1
  331. package/src/core/rules/recovery-allowlist.d.ts +0 -49
  332. package/src/core/rules/recovery-allowlist.js +0 -187
  333. package/src/core/rules/recovery-allowlist.js.map +0 -1
  334. package/src/core/rules/redirect-how-to-merge-main.d.ts +0 -16
  335. package/src/core/rules/redirect-how-to-merge-main.js +0 -157
  336. package/src/core/rules/redirect-how-to-merge-main.js.map +0 -1
  337. package/src/core/rules/shell-segment-scan.d.ts +0 -64
  338. package/src/core/rules/shell-segment-scan.js +0 -88
  339. package/src/core/rules/shell-segment-scan.js.map +0 -1
  340. package/src/core/rules/stale-main-bash-guard.d.ts +0 -198
  341. package/src/core/rules/stale-main-bash-guard.js +0 -361
  342. package/src/core/rules/stale-main-bash-guard.js.map +0 -1
  343. package/src/core/rules/stale-main-message.d.ts +0 -62
  344. package/src/core/rules/stale-main-message.js +0 -102
  345. package/src/core/rules/stale-main-message.js.map +0 -1
  346. package/src/core/rules/tree-recovery.d.ts +0 -92
  347. package/src/core/rules/tree-recovery.js +0 -165
  348. package/src/core/rules/tree-recovery.js.map +0 -1
  349. package/src/core/rules/wait-spin-guard.d.ts +0 -128
  350. package/src/core/rules/wait-spin-guard.js +0 -211
  351. package/src/core/rules/wait-spin-guard.js.map +0 -1
  352. package/src/core/rules/wait-spin-scan.d.ts +0 -118
  353. package/src/core/rules/wait-spin-scan.js +0 -203
  354. package/src/core/rules/wait-spin-scan.js.map +0 -1
  355. package/src/core/rules/whole-repo-build-guard.d.ts +0 -125
  356. package/src/core/rules/whole-repo-build-guard.js +0 -257
  357. package/src/core/rules/whole-repo-build-guard.js.map +0 -1
  358. package/src/core/rules/whole-repo-build-scan.d.ts +0 -28
  359. package/src/core/rules/whole-repo-build-scan.js +0 -198
  360. package/src/core/rules/whole-repo-build-scan.js.map +0 -1
  361. package/src/core/session-call-history.d.ts +0 -44
  362. package/src/core/session-call-history.js +0 -79
  363. package/src/core/session-call-history.js.map +0 -1
  364. package/src/core/shell-read-parity.d.ts +0 -56
  365. package/src/core/shell-read-parity.js +0 -155
  366. package/src/core/shell-read-parity.js.map +0 -1
  367. package/src/core/strip-ts-noise.d.ts +0 -1
  368. package/src/core/strip-ts-noise.js +0 -185
  369. package/src/core/strip-ts-noise.js.map +0 -1
  370. package/src/core/sync-main.d.ts +0 -46
  371. package/src/core/sync-main.js +0 -175
  372. package/src/core/sync-main.js.map +0 -1
  373. package/src/core/target-tree.d.ts +0 -84
  374. package/src/core/target-tree.js +0 -148
  375. package/src/core/target-tree.js.map +0 -1
  376. package/src/core/to-error.d.ts +0 -5
  377. package/src/core/to-error.js +0 -37
  378. package/src/core/to-error.js.map +0 -1
  379. package/src/core/types.d.ts +0 -152
  380. package/src/core/types.js +0 -200
  381. package/src/core/types.js.map +0 -1
  382. package/src/core/version-sync.d.ts +0 -219
  383. package/src/core/version-sync.js +0 -558
  384. package/src/core/version-sync.js.map +0 -1
  385. package/src/core/webpieces-versions.d.ts +0 -98
  386. package/src/core/webpieces-versions.js +0 -206
  387. package/src/core/webpieces-versions.js.map +0 -1
  388. package/templates/ai-hook.sh +0 -497
  389. package/templates/claude-settings-hook.json +0 -28
  390. package/templates/webpieces-reviewer.md +0 -60
@@ -1,198 +0,0 @@
1
- import { BranchStateGuardConfig } from '@webpieces/rules-config';
2
- import type { BashContext, Violation } from '../types';
3
- import { BashRuleBase } from '../rule-base';
4
- import { FixHint } from '../fix-hint';
5
- /**
6
- * The BASH half of the STALE-MAIN protection (read-stale-guard's State A), in two halves of its own:
7
- * a PREVENTIVE check that stops a session landing on a stale `main`, and the REACTIVE check that
8
- * contains the damage once it is already there.
9
- *
10
- * ── PREVENTIVE: a bare `git checkout main` is blocked; the pull must ride along ──────────────────
11
- *
12
- * Everything below this paragraph fires only once the session is ALREADY sitting on a stale `main`.
13
- * Nothing stopped it ARRIVING there, and arriving is one keystroke. In the incident that added this
14
- * half, an agent ran `git checkout main` after a merge, in a clone whose local `main` was **157
15
- * commits behind** origin. That checkout did not merely produce stale files — it reverted:
16
- *
17
- * 1. `package.json`'s `@webpieces` pin, to a version OLDER than the installed `node_modules`;
18
- * 2. `.claude/webpieces/ai-hook.sh` — the version-drift guard ITSELF — to a 157-commit-old copy
19
- * whose message stated the drift BACKWARDS ("your installed webpieces is older than required")
20
- * and named a single cure, `pnpm install`;
21
- * 3. and so the agent's judgment: it ran that `pnpm install`, DOWNGRADING `node_modules` to match
22
- * the stale pin, and had to undo it with the `git pull` that should have come first.
23
- *
24
- * The shim on current main already diagnoses drift correctly — it distinguishes "the pin is newer"
25
- * from "the pin is stale, and `pnpm install` would downgrade you". None of that helped, because the
26
- * checkout had replaced the shim with the version that could not say it. **A guard a stale checkout
27
- * can revert cannot be relied on to catch a stale checkout**, which is why this check is preventive
28
- * and why it lives here rather than in a second rule: same failure, one step earlier, one switch.
29
- *
30
- * It matches on command TEXT alone and asks git nothing. That is not laziness — this runs BEFORE the
31
- * checkout, so the only `main` it could measure is the one it is about to leave. The interesting
32
- * `main` does not exist yet, and consulting HEAD-at-hook-time is the exact trap
33
- * `redirect-how-to-merge-main` documents at length. Pairing is unconditionally correct instead: when
34
- * `main` is already current the chained pull is a sub-second no-op, so no exception is worth carving.
35
- *
36
- * BLOCKED `git checkout main`, `git switch main` — with or without flags — when no `git pull`
37
- * appears anywhere in the SAME command.
38
- * ALLOWED `git checkout main && git pull origin main`, the pairing this forces — and
39
- * `pnpm wp-sync-main`, which IS that pairing with the cleanup and the
40
- * orphan-directory sweep welded on. The message prescribes the one command; the raw pair
41
- * stays legal because it is plain git and because it is the L0 recovery cure, where
42
- * `node_modules` is the thing in doubt and no `pnpm` bin can be relied on.
43
- * ALLOWED `git checkout -b <x> origin/main` (current by construction), `git checkout <sha>`,
44
- * `git checkout -- <file>`, and any other branch.
45
- *
46
- * ── ROWS 6/7: the block fires only beyond the configured stale threshold ────────────────────
47
- *
48
- * The finding is not "you are on `main`" — it is **"what you would read here is out of date"**. So the
49
- * ladder below asks the main-sync cache, exactly as read-stale-guard's State A does, and BLOCKS only
50
- * when cached `commitsBehind` is greater than `maxCommitsBehind`. Unknown → allow. At or below
51
- * the threshold → allow. The detached refresher computes the count; this hot path never does.
52
- *
53
- * WHY, when this guard spent a release judging the branch alone: because the branch alone denies
54
- * everything off a narrow allowlist on a PERFECTLY CURRENT `main`, and a current `main` is exactly
55
- * where the prescribed cure leaves you. An agent lands a PR, runs `pnpm wp-sync-main` — the
56
- * command this repo tells it to run — and the next `curl`, `gh pr close` or test run is refused by a
57
- * guard whose own name says STALE. The tool that got it there could not be the cure for being there,
58
- * and the refusal had nothing to do with staleness, which is the confusion reported from the field.
59
- *
60
- * THE ASYMMETRY WITH `E` IS DELIBERATE, and the docblocks that argued `B` should track `E` were right
61
- * about the mechanism and wrong about the policy. A WRITE on `main` creates work in the wrong place
62
- * whatever `main`'s freshness — unreviewable, and unrevertable as a unit — so feature-branch-guard
63
- * stays unconditional and keeps its one `git rev-parse`. A READ or a BUILD on a CURRENT `main` harms
64
- * nothing, and blocking it strands the agent at the exact moment the prescribed cure put it there.
65
- * Same tree, different hazard, so one precondition was never right for both.
66
- *
67
- * THE ANCESTRY TEST, NOT HASH EQUALITY. `MainFreshness.containsOriginMain` asks "does local `main`
68
- * already contain the cached `origin/main`?", so the block lifts the instant a pull lands rather than
69
- * waiting for the detached refresher to catch up. It is the SAME object read-stale-guard uses — one
70
- * implementation, so the Read and Bash halves of one state can never disagree about whether the pull
71
- * took.
72
- *
73
- * FAIL-OPEN ON EVERYTHING NOT ESTABLISHED, logged as `ALLOW_FAIL_OPEN` so abstentions stay countable:
74
- * no cache (the first call of every session), a cache for another branch, an empty `originMain`
75
- * (offline), no local `main` at all (fresh clone / worktree), branch undeterminable. The refresher is
76
- * fired detached on every call to keep the cache warm for the NEXT one; it is never waited on, and no
77
- * synchronous `git fetch` is ever run on the blocking path.
78
- *
79
- * THE POLARITY INSIDE THE BLOCKED STATE IS UNCHANGED: default-DENY plus row 4's skip list, the shape
80
- * merged-branch-bash-guard uses for state B, via the same shared RecoveryAllowlist. A content-read
81
- * BLOCKLIST could not replace it — enumerating readers catches `cat` and `grep`, and structurally
82
- * cannot catch `pnpm install`, `npx expo install`, a formatter, codegen or a `>` redirect: commands
83
- * whose stated purpose is something else and whose effect is to modify tracked files. What changed is
84
- * WHEN that polarity applies, not the polarity.
85
- *
86
- * BLOCKED on a `main` known beyond the configured threshold: anything not on the skip list — builds, tests,
87
- * installers, formatters, codegen, `cat`/`grep`/`ls` of the tree, git writes.
88
- * ALLOWED every command on a `main` that is current or whose freshness is unknown — and, in the
89
- * blocked state, everything that gets you OUT or tells you where you are:
90
- * `git checkout -b <new> origin/main`, `git switch`, `git pull`/`fetch`,
91
- * `git status|log|diff|show|branch`, `git stash`, `gh` (it talks to GitHub, not to this
92
- * tree), `curl`/`wget`, every `wp-*` bin, installs.
93
- *
94
- * ── ROWS 12/13: the cure may be COMPOSED with the work, but only with `&&` ───────────────────────
95
- *
96
- * `pnpm wp-sync-main && cat src/app.ts` is allowed and `pnpm wp-sync-main ; cat
97
- * src/app.ts` is not, and the difference is the shell's rather than this guard's: `&&` short-circuits,
98
- * so the work cannot run when the cure failed — the exact property the block is here to guarantee. `;`
99
- * discards the exit code and runs the work anyway. See cure-prefix-scan.ts for the measured shapes.
100
- *
101
- * There is no dirty-tree valve here and none in read-stale-guard either: the cure is
102
- * `git checkout -b`, which CARRIES uncommitted work onto the new branch, so a dirty tree traps nobody
103
- * in any L2 state. (`git stash` covers the residual where origin/main touched the same files.)
104
- */
105
- export declare class StaleMainBashGuardRule extends BashRuleBase<BranchStateGuardConfig> {
106
- constructor(config: BranchStateGuardConfig);
107
- private readonly scanner;
108
- private readonly recovery;
109
- private readonly switches;
110
- private readonly recoveryList;
111
- private readonly freshness;
112
- private readonly curePrefix;
113
- readonly description: string;
114
- readonly defaultOptions: {
115
- hangTimeoutMinutes: number;
116
- };
117
- readonly fixHint: FixHint;
118
- check(ctx: BashContext): readonly Violation[];
119
- /**
120
- * ROWS 6/7 — block ONLY when cached `commitsBehind` exceeds `maxCommitsBehind`.
121
- *
122
- * Read this beside read-stale-guard.checkStaleMain: it is the same ladder over the same cache, and
123
- * that is on purpose — the Read and the Bash halves of one state must not disagree about whether
124
- * `main` is stale. What differs is the VERDICT SHAPE once it is stale, because a Read names one
125
- * file and a Bash command is opaque: the Read is judged per file, Bash is default-deny plus the
126
- * row 4 skip list already applied above.
127
- *
128
- * Every exit that is not "established BEHIND" is an ALLOW, and the not-established ones are
129
- * `ALLOW_FAIL_OPEN` so they stay countable. A guard that cannot see the state judges nothing.
130
- */
131
- private checkFreshness;
132
- /**
133
- * ROWS 12/13 — `<cure> && <work>` is allowed; `<cure> ; <work>` is not.
134
- *
135
- * The distinction is the shell's, not this guard's invention. `&&` short-circuits, so the work
136
- * cannot run when the cure exits non-zero — which is precisely the property the block exists to
137
- * guarantee, already enforced by the interpreter. Refusing it bought nothing and cost a round
138
- * trip, and the fleet audit files that as a TOOLING defect.
139
- *
140
- * `;` discards the exit code and runs the work regardless, and it was measured with
141
- * `>/dev/null 2>&1` on the cure in 7 of 9 observed cases — so the failure was invisible as well as
142
- * ignored. The two-step is genuinely safer there: the NEXT tool call is a fresh evaluation that
143
- * recomputes `localMain` against `originMain`, so a pull that failed re-blocks. An allowed `;`
144
- * compound never gets that second look.
145
- */
146
- private judgeComposition;
147
- /**
148
- * The first segment that switches to the `main` BRANCH with no `git pull` anywhere in the same
149
- * command, or null. The pull is looked for across the WHOLE command, not the matched segment,
150
- * because `git checkout main && git pull origin main` splits into two segments and the pairing is
151
- * the point.
152
- */
153
- private bareCheckoutOfMain;
154
- /**
155
- * The stale-`main` deny. Deliberately SHORT, and now deliberately ABOUT STALENESS — which is what
156
- * the guard's name promised all along.
157
- *
158
- * The two versions before this one are both instructive. The oldest opened with how many commits
159
- * behind `main` was, which invited the wrong cure: an agent that reads "behind" reaches for a pull,
160
- * lands on a CURRENT `main`, and is still on `main`. The one after it swung the other way and said
161
- * `main` is not a place to work "whether or not it is current" — true of a WRITE, but this guard
162
- * does not see writes, and it made every refusal on a freshly-pulled `main` unanswerable.
163
- *
164
- * So the text says what is now actually true and nothing more: local `main` is BEHIND, so what you
165
- * read here is out of date; Bash is default-deny in this state rather than a list of readers,
166
- * because a command's stated purpose never says whether it also WRITES; and the branch cure fetches,
167
- * so it makes the reads true as well as moving the work somewhere reviewable. Reading `main` to PLAN
168
- * stays legitimate — on a CURRENT `main` nothing here fires at all.
169
- *
170
- * ONE cure, and it is the dirty-safe one, the same call feature-branch-guard made: `git checkout -b`
171
- * carries uncommitted work onto the new branch. (Row 6 also lists the pull, and read-stale-guard
172
- * prints it, because a Read really can be cured by staying put. A Bash session cannot — the next
173
- * command is as likely to write as to read.)
174
- */
175
- private staleMainMessage;
176
- /**
177
- * ROW 13's deny. It NAMES the operator the agent typed, because the fix is a one-character edit
178
- * and an agent told only "use `&&`" has to diff the two spellings itself to find where.
179
- */
180
- private compositionMessage;
181
- private pairingMessage;
182
- /**
183
- * The guard could not ESTABLISH the state it judges on, so it judged nothing.
184
- *
185
- * A sibling of allow() rather than a reason string passed to it, because the difference has to
186
- * reach the LOG as a value: `ALLOW_FAIL_OPEN` vs `ALLOW`. It was previously a `' (fail-open)'`
187
- * suffix on the free-text reason, which meant an abstention and a real approval were the same
188
- * verdict and the abstentions could not be counted — so nobody could tell whether these guards
189
- * were protecting anything or quietly standing down. Never block on data you could not
190
- * establish; but say out loud, in a field, that you did not establish it.
191
- */
192
- private failOpen;
193
- private allow;
194
- private block;
195
- private truncate;
196
- private logDecision;
197
- private currentBranch;
198
- }
@@ -1,361 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StaleMainBashGuardRule = void 0;
4
- const child_process_1 = require("child_process");
5
- const rules_config_1 = require("@webpieces/rules-config");
6
- const repo_workflow_core_1 = require("@webpieces/repo-workflow-core");
7
- const types_1 = require("../types");
8
- const rule_base_1 = require("../rule-base");
9
- const fix_hint_1 = require("../fix-hint");
10
- const to_error_1 = require("../to-error");
11
- const main_sync_refresh_1 = require("../main-sync-refresh");
12
- const main_sync_timeout_1 = require("../main-sync-timeout");
13
- const decision_log_1 = require("../decision-log");
14
- const l2_matrix_doc_1 = require("../l2-matrix-doc");
15
- const l0_fault_codes_1 = require("../l0-fault-codes");
16
- const command_scan_1 = require("../command-scan");
17
- const tree_recovery_1 = require("./tree-recovery");
18
- const branch_switch_scan_1 = require("./branch-switch-scan");
19
- const recovery_allowlist_1 = require("./recovery-allowlist");
20
- const main_freshness_1 = require("./main-freshness");
21
- const cure_prefix_scan_1 = require("./cure-prefix-scan");
22
- /**
23
- * The BASH half of the STALE-MAIN protection (read-stale-guard's State A), in two halves of its own:
24
- * a PREVENTIVE check that stops a session landing on a stale `main`, and the REACTIVE check that
25
- * contains the damage once it is already there.
26
- *
27
- * ── PREVENTIVE: a bare `git checkout main` is blocked; the pull must ride along ──────────────────
28
- *
29
- * Everything below this paragraph fires only once the session is ALREADY sitting on a stale `main`.
30
- * Nothing stopped it ARRIVING there, and arriving is one keystroke. In the incident that added this
31
- * half, an agent ran `git checkout main` after a merge, in a clone whose local `main` was **157
32
- * commits behind** origin. That checkout did not merely produce stale files — it reverted:
33
- *
34
- * 1. `package.json`'s `@webpieces` pin, to a version OLDER than the installed `node_modules`;
35
- * 2. `.claude/webpieces/ai-hook.sh` — the version-drift guard ITSELF — to a 157-commit-old copy
36
- * whose message stated the drift BACKWARDS ("your installed webpieces is older than required")
37
- * and named a single cure, `pnpm install`;
38
- * 3. and so the agent's judgment: it ran that `pnpm install`, DOWNGRADING `node_modules` to match
39
- * the stale pin, and had to undo it with the `git pull` that should have come first.
40
- *
41
- * The shim on current main already diagnoses drift correctly — it distinguishes "the pin is newer"
42
- * from "the pin is stale, and `pnpm install` would downgrade you". None of that helped, because the
43
- * checkout had replaced the shim with the version that could not say it. **A guard a stale checkout
44
- * can revert cannot be relied on to catch a stale checkout**, which is why this check is preventive
45
- * and why it lives here rather than in a second rule: same failure, one step earlier, one switch.
46
- *
47
- * It matches on command TEXT alone and asks git nothing. That is not laziness — this runs BEFORE the
48
- * checkout, so the only `main` it could measure is the one it is about to leave. The interesting
49
- * `main` does not exist yet, and consulting HEAD-at-hook-time is the exact trap
50
- * `redirect-how-to-merge-main` documents at length. Pairing is unconditionally correct instead: when
51
- * `main` is already current the chained pull is a sub-second no-op, so no exception is worth carving.
52
- *
53
- * BLOCKED `git checkout main`, `git switch main` — with or without flags — when no `git pull`
54
- * appears anywhere in the SAME command.
55
- * ALLOWED `git checkout main && git pull origin main`, the pairing this forces — and
56
- * `pnpm wp-sync-main`, which IS that pairing with the cleanup and the
57
- * orphan-directory sweep welded on. The message prescribes the one command; the raw pair
58
- * stays legal because it is plain git and because it is the L0 recovery cure, where
59
- * `node_modules` is the thing in doubt and no `pnpm` bin can be relied on.
60
- * ALLOWED `git checkout -b <x> origin/main` (current by construction), `git checkout <sha>`,
61
- * `git checkout -- <file>`, and any other branch.
62
- *
63
- * ── ROWS 6/7: the block fires only beyond the configured stale threshold ────────────────────
64
- *
65
- * The finding is not "you are on `main`" — it is **"what you would read here is out of date"**. So the
66
- * ladder below asks the main-sync cache, exactly as read-stale-guard's State A does, and BLOCKS only
67
- * when cached `commitsBehind` is greater than `maxCommitsBehind`. Unknown → allow. At or below
68
- * the threshold → allow. The detached refresher computes the count; this hot path never does.
69
- *
70
- * WHY, when this guard spent a release judging the branch alone: because the branch alone denies
71
- * everything off a narrow allowlist on a PERFECTLY CURRENT `main`, and a current `main` is exactly
72
- * where the prescribed cure leaves you. An agent lands a PR, runs `pnpm wp-sync-main` — the
73
- * command this repo tells it to run — and the next `curl`, `gh pr close` or test run is refused by a
74
- * guard whose own name says STALE. The tool that got it there could not be the cure for being there,
75
- * and the refusal had nothing to do with staleness, which is the confusion reported from the field.
76
- *
77
- * THE ASYMMETRY WITH `E` IS DELIBERATE, and the docblocks that argued `B` should track `E` were right
78
- * about the mechanism and wrong about the policy. A WRITE on `main` creates work in the wrong place
79
- * whatever `main`'s freshness — unreviewable, and unrevertable as a unit — so feature-branch-guard
80
- * stays unconditional and keeps its one `git rev-parse`. A READ or a BUILD on a CURRENT `main` harms
81
- * nothing, and blocking it strands the agent at the exact moment the prescribed cure put it there.
82
- * Same tree, different hazard, so one precondition was never right for both.
83
- *
84
- * THE ANCESTRY TEST, NOT HASH EQUALITY. `MainFreshness.containsOriginMain` asks "does local `main`
85
- * already contain the cached `origin/main`?", so the block lifts the instant a pull lands rather than
86
- * waiting for the detached refresher to catch up. It is the SAME object read-stale-guard uses — one
87
- * implementation, so the Read and Bash halves of one state can never disagree about whether the pull
88
- * took.
89
- *
90
- * FAIL-OPEN ON EVERYTHING NOT ESTABLISHED, logged as `ALLOW_FAIL_OPEN` so abstentions stay countable:
91
- * no cache (the first call of every session), a cache for another branch, an empty `originMain`
92
- * (offline), no local `main` at all (fresh clone / worktree), branch undeterminable. The refresher is
93
- * fired detached on every call to keep the cache warm for the NEXT one; it is never waited on, and no
94
- * synchronous `git fetch` is ever run on the blocking path.
95
- *
96
- * THE POLARITY INSIDE THE BLOCKED STATE IS UNCHANGED: default-DENY plus row 4's skip list, the shape
97
- * merged-branch-bash-guard uses for state B, via the same shared RecoveryAllowlist. A content-read
98
- * BLOCKLIST could not replace it — enumerating readers catches `cat` and `grep`, and structurally
99
- * cannot catch `pnpm install`, `npx expo install`, a formatter, codegen or a `>` redirect: commands
100
- * whose stated purpose is something else and whose effect is to modify tracked files. What changed is
101
- * WHEN that polarity applies, not the polarity.
102
- *
103
- * BLOCKED on a `main` known beyond the configured threshold: anything not on the skip list — builds, tests,
104
- * installers, formatters, codegen, `cat`/`grep`/`ls` of the tree, git writes.
105
- * ALLOWED every command on a `main` that is current or whose freshness is unknown — and, in the
106
- * blocked state, everything that gets you OUT or tells you where you are:
107
- * `git checkout -b <new> origin/main`, `git switch`, `git pull`/`fetch`,
108
- * `git status|log|diff|show|branch`, `git stash`, `gh` (it talks to GitHub, not to this
109
- * tree), `curl`/`wget`, every `wp-*` bin, installs.
110
- *
111
- * ── ROWS 12/13: the cure may be COMPOSED with the work, but only with `&&` ───────────────────────
112
- *
113
- * `pnpm wp-sync-main && cat src/app.ts` is allowed and `pnpm wp-sync-main ; cat
114
- * src/app.ts` is not, and the difference is the shell's rather than this guard's: `&&` short-circuits,
115
- * so the work cannot run when the cure failed — the exact property the block is here to guarantee. `;`
116
- * discards the exit code and runs the work anyway. See cure-prefix-scan.ts for the measured shapes.
117
- *
118
- * There is no dirty-tree valve here and none in read-stale-guard either: the cure is
119
- * `git checkout -b`, which CARRIES uncommitted work onto the new branch, so a dirty tree traps nobody
120
- * in any L2 state. (`git stash` covers the residual where origin/main touched the same files.)
121
- */
122
- class StaleMainBashGuardRule extends rule_base_1.BashRuleBase {
123
- constructor(config) { super(config, 'stale-main-bash-guard', rules_config_1.BRANCH_STATE_GUARD_KEY); }
124
- scanner = new command_scan_1.CommandScanner();
125
- recovery = new tree_recovery_1.TreeRecovery();
126
- switches = new branch_switch_scan_1.BranchSwitchScan(this.scanner);
127
- // ROW 4, the skip list — the SAME instance-shape merged-branch-bash-guard uses, so the two states
128
- // cannot drift apart about what "gets you out" means. See recovery-allowlist.ts.
129
- recoveryList = new recovery_allowlist_1.RecoveryAllowlist(this.scanner);
130
- // The ancestry test and the cache summary, shared with read-stale-guard — see main-freshness.ts.
131
- freshness = new main_freshness_1.MainFreshness();
132
- // ROWS 12/13 — `<cure> && <work>` vs `<cure> ; <work>`. See cure-prefix-scan.ts.
133
- curePrefix = new cure_prefix_scan_1.CurePrefixScan(this.scanner);
134
- description = 'Block a bare `git checkout main` (use `pnpm wp-sync-main`, or chain the pull into ' +
135
- 'the same command), and — once local main is beyond maxCommitsBehind — block Bash ' +
136
- 'there, allowlisting only the commands that get you off it. A main that is current, or whose ' +
137
- 'freshness is unknown, is left alone.';
138
- defaultOptions = {
139
- hangTimeoutMinutes: repo_workflow_core_1.DEFAULT_HANG_TIMEOUT_MINUTES,
140
- };
141
- fixHint = new fix_hint_1.FixHint('Landing on `main` without pulling, or working on `main` at all, both put your work somewhere it does not belong.', 'Get onto a feature branch, or go to main with the one command that pulls it too:', [
142
- // TREE-SHAPED, from the one source of tree-shaped cures. A static rule-level hint has no
143
- // workspace root, so it renders the 'unknown' kind — TreeRecovery's deliberate answer for
144
- // "we cannot detect the tree": both forms, each labelled. That matters here because the
145
- // primary-clone form goes to `main`, and a linked worktree has no `main` to go to — it is
146
- // checked out in the primary clone — so a preferred option naming it unconditionally hands
147
- // the AI a cure that cannot work where it is standing. The per-block message
148
- // (pairingMessage) is detected and prints exactly one form; this is the fallback for the
149
- // hint that cannot look.
150
- new rules_config_1.Option(this.recovery.updateMainSteps('unknown').join('\n')
151
- + '\nIf you hand-roll the git instead, the pull must be in the SAME command as the checkout.', true),
152
- new rules_config_1.Option('Already on main: pnpm wp-sync-main (then re-run) — it pulls main and takes the trash out in the one command this repo prescribes. You may chain your command onto it with && (pnpm wp-sync-main && <your command>), which is skipped if the pull fails; a ; instead runs your command anyway and is refused.'),
153
- new rules_config_1.Option('Still allowed: every BASH command, on a main at or below branch-state-guard.maxCommitsBehind or whose commit distance is not known. (Write/Edit on main is a different policy and is blocked by feature-branch-guard however current main is.) Beyond that threshold you keep the commands that get you OUT or tell you where you are: git checkout -b <new> origin/main, git switch, git pull/fetch, git status|log|diff|show|branch, git stash, gh, curl/wget, every wp-* bin, installs, and reading webpieces.config.json.'),
154
- new rules_config_1.Option('Disable in webpieces.config.json under hookGuards → branch-state-guard (mode OFF) if intentional — that one key governs the Write, Read and Bash halves of this policy together.'),
155
- ]);
156
- check(ctx) {
157
- // PREVENTIVE half, FIRST and unconditional. Deliberately ahead of every fail-open bailout
158
- // below: those all ask "is the main we are ON stale?", and this asks about the main we are
159
- // about to MOVE TO — a different branch, and one no cache can describe yet.
160
- const bare = this.bareCheckoutOfMain(ctx);
161
- if (bare !== null) {
162
- return this.block(ctx, 'any', `bare checkout of main (${bare})`, this.pairingMessage(ctx), '-');
163
- }
164
- const branch = this.currentBranch(ctx.workspaceRoot);
165
- if (branch === null)
166
- return this.failOpen(ctx, branch, 'branch-undeterminable');
167
- // Keep the shared cache warm for the next call. Detached; never blocks this command.
168
- (0, main_sync_refresh_1.triggerMainSyncRefresh)(ctx.workspaceRoot, (0, main_sync_timeout_1.hangTimeoutOf)(this.config));
169
- // State A is on `main` only. A merged feature branch is merged-branch-bash-guard's job.
170
- if (branch !== 'main')
171
- return this.allow(ctx, branch, 'not-on-main (state B is another guard)');
172
- // ROW 4 — the skip list, ahead of the block, so no command that gets you OUT is ever denied.
173
- if (this.recoveryList.isFullyRecovery(ctx)) {
174
- return this.allow(ctx, branch, 'not-a-content-read (cure/build/metadata)');
175
- }
176
- return this.checkFreshness(ctx, branch);
177
- }
178
- /**
179
- * ROWS 6/7 — block ONLY when cached `commitsBehind` exceeds `maxCommitsBehind`.
180
- *
181
- * Read this beside read-stale-guard.checkStaleMain: it is the same ladder over the same cache, and
182
- * that is on purpose — the Read and the Bash halves of one state must not disagree about whether
183
- * `main` is stale. What differs is the VERDICT SHAPE once it is stale, because a Read names one
184
- * file and a Bash command is opaque: the Read is judged per file, Bash is default-deny plus the
185
- * row 4 skip list already applied above.
186
- *
187
- * Every exit that is not "established BEHIND" is an ALLOW, and the not-established ones are
188
- * `ALLOW_FAIL_OPEN` so they stay countable. A guard that cannot see the state judges nothing.
189
- */
190
- checkFreshness(ctx, branch) {
191
- const status = (0, repo_workflow_core_1.readMainSyncStatus)(ctx.workspaceRoot, 'main');
192
- // The first call of every session, and every call while another worktree holds the refresh
193
- // lock. The refresher fired above populates it for the NEXT call; nothing waits here.
194
- if (status === null)
195
- return this.failOpen(ctx, branch, 'no-sync-cache', 'cache=none');
196
- const cache = this.freshness.summarize(status);
197
- // BELT-AND-BRACES since the cache became branch-keyed: we asked for the 'main' entry BY KEY, so
198
- // a mismatch means the map's key and the entry's own `branch` disagree — a shape bug. Kept so
199
- // that degrades to an allow. Unreachable in normal operation.
200
- if (status.branch !== 'main')
201
- return this.failOpen(ctx, branch, 'stale-cross-branch-cache', cache);
202
- // Offline / origin unresolvable, or no local main to compare against.
203
- if (status.originMain === '')
204
- return this.failOpen(ctx, branch, 'origin-main-unknown', cache);
205
- // ANCESTRY, not equality — the line that makes a pull take effect immediately. See
206
- // MainFreshness.containsOriginMain.
207
- if (this.freshness.containsOriginMain(ctx.workspaceRoot, status.originMain)) {
208
- return this.allow(ctx, branch, 'local-main-contains-origin (up to date)', cache);
209
- }
210
- const maxCommitsBehind = this.config.maxCommitsBehind ?? rules_config_1.DEFAULT_MAX_COMMITS_BEHIND;
211
- const withinThreshold = this.freshness.isWithinAllowedDrift(status, maxCommitsBehind);
212
- if (withinThreshold === null)
213
- return this.failOpen(ctx, branch, 'commit-distance-unknown', cache);
214
- if (withinThreshold)
215
- return this.allow(ctx, branch, 'within-max-commits-behind', cache);
216
- // ESTABLISHED BEYOND THE CONFIGURED THRESHOLD. Only now does default-deny apply.
217
- return this.judgeComposition(ctx, branch, cache, status.commitsBehind ?? 0, maxCommitsBehind);
218
- }
219
- /**
220
- * ROWS 12/13 — `<cure> && <work>` is allowed; `<cure> ; <work>` is not.
221
- *
222
- * The distinction is the shell's, not this guard's invention. `&&` short-circuits, so the work
223
- * cannot run when the cure exits non-zero — which is precisely the property the block exists to
224
- * guarantee, already enforced by the interpreter. Refusing it bought nothing and cost a round
225
- * trip, and the fleet audit files that as a TOOLING defect.
226
- *
227
- * `;` discards the exit code and runs the work regardless, and it was measured with
228
- * `>/dev/null 2>&1` on the cure in 7 of 9 observed cases — so the failure was invisible as well as
229
- * ignored. The two-step is genuinely safer there: the NEXT tool call is a fresh evaluation that
230
- * recomputes `localMain` against `originMain`, so a pull that failed re-blocks. An allowed `;`
231
- * compound never gets that second look.
232
- */
233
- judgeComposition(ctx, branch, cache, commitsBehind, maxCommitsBehind) {
234
- const prefix = this.curePrefix.classify(ctx.command);
235
- if (prefix.kind === 'short-circuits') {
236
- return this.allow(ctx, branch, 'cure-prefixed, && short-circuits the work', cache);
237
- }
238
- if (prefix.kind === 'runs-anyway') {
239
- return this.block(ctx, branch, 'cure-prefixed, work runs anyway', this.compositionMessage(prefix), cache);
240
- }
241
- return this.block(ctx, branch, 'on-stale-main', this.staleMainMessage(ctx.workspaceRoot, commitsBehind, maxCommitsBehind), cache);
242
- }
243
- /**
244
- * The first segment that switches to the `main` BRANCH with no `git pull` anywhere in the same
245
- * command, or null. The pull is looked for across the WHOLE command, not the matched segment,
246
- * because `git checkout main && git pull origin main` splits into two segments and the pairing is
247
- * the point.
248
- */
249
- bareCheckoutOfMain(ctx) {
250
- for (const segment of this.scanner.commandSegments(ctx.command)) {
251
- // BranchSwitchScan answers "which branch does this land on" for both guards, flag-tolerantly:
252
- // `git checkout -q main` lands on main exactly as the bare form does, while
253
- // `git checkout -b x origin/main` (creates), `git checkout -- main` (pathspec) and
254
- // `git checkout <sha>` do not. See branch-switch-scan.ts for why that lives in one place.
255
- if (!this.switches.landsOnExistingMain(segment))
256
- continue;
257
- return this.scanner.commandInvokesAnyGit(ctx.command, ['pull']) ? null : segment;
258
- }
259
- return null;
260
- }
261
- /**
262
- * The stale-`main` deny. Deliberately SHORT, and now deliberately ABOUT STALENESS — which is what
263
- * the guard's name promised all along.
264
- *
265
- * The two versions before this one are both instructive. The oldest opened with how many commits
266
- * behind `main` was, which invited the wrong cure: an agent that reads "behind" reaches for a pull,
267
- * lands on a CURRENT `main`, and is still on `main`. The one after it swung the other way and said
268
- * `main` is not a place to work "whether or not it is current" — true of a WRITE, but this guard
269
- * does not see writes, and it made every refusal on a freshly-pulled `main` unanswerable.
270
- *
271
- * So the text says what is now actually true and nothing more: local `main` is BEHIND, so what you
272
- * read here is out of date; Bash is default-deny in this state rather than a list of readers,
273
- * because a command's stated purpose never says whether it also WRITES; and the branch cure fetches,
274
- * so it makes the reads true as well as moving the work somewhere reviewable. Reading `main` to PLAN
275
- * stays legitimate — on a CURRENT `main` nothing here fires at all.
276
- *
277
- * ONE cure, and it is the dirty-safe one, the same call feature-branch-guard made: `git checkout -b`
278
- * carries uncommitted work onto the new branch. (Row 6 also lists the pull, and read-stale-guard
279
- * prints it, because a Read really can be cured by staying put. A Bash session cannot — the next
280
- * command is as likely to write as to read.)
281
- */
282
- staleMainMessage(workspaceRoot, commitsBehind, maxCommitsBehind) {
283
- return `Blocked: local \`main\` is ${commitsBehind} commits behind origin/main, exceeding `
284
- + `branch-state-guard.maxCommitsBehind=${maxCommitsBehind}, so what you would read here is out of `
285
- + 'date and a plan built on it is built on code upstream has moved past. A CURRENT main is '
286
- + 'not blocked — reading main to PLAN is fine, and this fires only once being behind is '
287
- + 'established. Bash is default-deny in this state rather than a list of readers, because a '
288
- + "command's stated purpose never says whether it also WRITES. The feature branch is the "
289
- + 'unit of work in any case: reviewable, revertable — and the cure fetches, so it makes '
290
- + 'your reads true as well as moving you off main.\n'
291
- + `Start a branch (uncommitted work comes with you):\n cd '${workspaceRoot}' && git fetch origin main && git checkout -b <new-branch> origin/main`;
292
- }
293
- /**
294
- * ROW 13's deny. It NAMES the operator the agent typed, because the fix is a one-character edit
295
- * and an agent told only "use `&&`" has to diff the two spellings itself to find where.
296
- */
297
- compositionMessage(prefix) {
298
- return `Your cure is joined with \`${prefix.operator}\` — the work runs even if the pull fails. `
299
- + 'Use `&&` so it is skipped:\n'
300
- + '\n pnpm wp-sync-main && <your command>\n\n'
301
- + 'Or run the cure alone and re-issue your command in the next call.';
302
- }
303
- pairingMessage(ctx) {
304
- const steps = this.recovery.updateMainSteps(this.recovery.kindOf(ctx.workspaceRoot)).join('\n');
305
- // Deliberately SHORT. The incident that bought this guard (a main 157 commits behind; the
306
- // downgrade the reverted shim then prescribed) is maintainer material and lives in the class
307
- // docblock above — the reader of THIS text needs only what changes what they type.
308
- return 'Blocked: a bare `git checkout main` lands you on whatever local `main` you last had — '
309
- + 'stale files, plus a reverted @webpieces pin and guard shim, so the drift guard then '
310
- + 'reports the drift BACKWARDS. Go to main with the one command that also pulls it:\n' + steps;
311
- }
312
- /**
313
- * The guard could not ESTABLISH the state it judges on, so it judged nothing.
314
- *
315
- * A sibling of allow() rather than a reason string passed to it, because the difference has to
316
- * reach the LOG as a value: `ALLOW_FAIL_OPEN` vs `ALLOW`. It was previously a `' (fail-open)'`
317
- * suffix on the free-text reason, which meant an abstention and a real approval were the same
318
- * verdict and the abstentions could not be counted — so nobody could tell whether these guards
319
- * were protecting anything or quietly standing down. Never block on data you could not
320
- * establish; but say out loud, in a field, that you did not establish it.
321
- */
322
- failOpen(ctx, branch, reason, cache = '-') {
323
- this.logDecision(ctx, branch, 'ALLOW_FAIL_OPEN', reason, cache);
324
- return [];
325
- }
326
- allow(ctx, branch, reason, cache = '-') {
327
- this.logDecision(ctx, branch, 'ALLOW', reason, cache);
328
- return [];
329
- }
330
- block(ctx, branch, reason, message, cache) {
331
- this.logDecision(ctx, branch, 'BLOCK_AI_CURE', reason, cache);
332
- // Deliver the matrix and name the row, the same way an L0 block does. The doc is written
333
- // LAZILY here rather than up front: only a blocked agent needs it, and this is the one path
334
- // that knows the row it should be opened at.
335
- const row = (0, decision_log_1.matrixL2Row)(reason).row;
336
- const pointer = (0, l2_matrix_doc_1.branchStateMatrixPointer)((0, l2_matrix_doc_1.writeBranchStateMatrixDoc)(ctx.workspaceRoot), row);
337
- return [new types_1.Violation(1, this.truncate(ctx.command), message + pointer)];
338
- }
339
- truncate(s) {
340
- const MAX = 120;
341
- return s.length <= MAX ? s : s.slice(0, MAX) + '…';
342
- }
343
- logDecision(ctx, branch, verdict, reason, cache) {
344
- (0, decision_log_1.logGuardDecision)(ctx.workspaceRoot, new decision_log_1.GuardDecision('stale-main-bash-guard', 'Bash', ctx.command, branch ?? 'unknown', verdict, reason, cache, l0_fault_codes_1.L0_FAULT_NONE, (0, decision_log_1.matrixL2Row)(reason)));
345
- }
346
- currentBranch(workspaceRoot) {
347
- // eslint-disable-next-line @webpieces/no-unmanaged-exceptions
348
- try {
349
- return (0, child_process_1.execSync)('git rev-parse --abbrev-ref HEAD', {
350
- cwd: workspaceRoot, encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'],
351
- }).trim();
352
- }
353
- catch (err) {
354
- const error = (0, to_error_1.toError)(err);
355
- void error;
356
- return null;
357
- }
358
- }
359
- }
360
- exports.StaleMainBashGuardRule = StaleMainBashGuardRule;
361
- //# sourceMappingURL=stale-main-bash-guard.js.map