@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,661 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.REVIEWER_AGENT_SURFACE = exports.ENV_SURFACE = exports.CODEX_REGISTRATION_SURFACE = exports.REGISTRATION_SURFACE = exports.SHIM_SURFACE = exports.SettingsRepair = exports.HARNESS_REGISTRATIONS = exports.CODEX_REGISTRATION = exports.CLAUDE_REGISTRATION = exports.HarnessRegistration = exports.GUARDS_BIN = exports.RULES_BIN = exports.HookRegistrationEntry = exports.LEGACY_MARKER_REMOVE_AFTER = exports.LEGACY_GUARANTEE_ROOT_MARKER = void 0;
4
- exports.isManagedCommand = isManagedCommand;
5
- exports.managedEntries = managedEntries;
6
- exports.registeredBins = registeredBins;
7
- exports.expectedEntries = expectedEntries;
8
- exports.registrationStale = registrationStale;
9
- exports.dropManagedEntries = dropManagedEntries;
10
- exports.addHookEntry = addHookEntry;
11
- exports.envStale = envStale;
12
- exports.applyManagedEnv = applyManagedEnv;
13
- exports.repairRegistration = repairRegistration;
14
- exports.readSettings = readSettings;
15
- exports.writeSettings = writeSettings;
16
- exports.neighbourHooksStaleAt = neighbourHooksStaleAt;
17
- exports.registrationStaleAt = registrationStaleAt;
18
- exports.envStaleAt = envStaleAt;
19
- exports.repairRegistrationAt = repairRegistrationAt;
20
- exports.managedSurfaceDrift = managedSurfaceDrift;
21
- const tslib_1 = require("tslib");
22
- const fs = tslib_1.__importStar(require("fs"));
23
- const path = tslib_1.__importStar(require("path"));
24
- const to_error_1 = require("../core/to-error");
25
- const shim_1 = require("./shim");
26
- const reviewer_agent_1 = require("./reviewer-agent");
27
- const neighbour_hooks_1 = require("./neighbour-hooks");
28
- const managed_env_1 = require("./managed-env");
29
- /**
30
- * THE INSTALLED HOOK SURFACE — two hooks per harness, all ABSOLUTE, and the ONE place their spelling is
31
- * defined. See `HarnessRegistration` below, which is what makes "per harness" data rather than four
32
- * module constants that were only ever true of Claude Code.
33
- *
34
- * ─── ONE GOVERNOR: the MAIN tree judges every tree ─────────────────────────────────────────────────
35
- *
36
- * Claude Code — .claude/settings.json
37
- * H1 sh "$CLAUDE_PROJECT_DIR/.claude/webpieces/ai-hook.sh" wp-ai-guards-hook Write|…|Bash|Read
38
- * H2 sh "$CLAUDE_PROJECT_DIR/.claude/webpieces/ai-hook.sh" wp-ai-rules-hook Write|Edit|MultiEdit
39
- * Codex — .codex/hooks.json (the SAME `hooks.PreToolUse` JSON shape, measured)
40
- * H1 sh "$PWD/.claude/webpieces/ai-hook.sh" wp-ai-guards-hook Bash|apply_patch
41
- * H2 sh "$PWD/.claude/webpieces/ai-hook.sh" wp-ai-rules-hook apply_patch
42
- *
43
- * ONE shim file serves all four: `.claude/` there is a path, not a claim about who is calling.
44
- *
45
- * This REPLACES a three-hook form in which these two were RELATIVE (`sh ".claude/webpieces/ai-hook.sh"`)
46
- * and a third hook, L-1 `guarantee-root.sh`, existed solely to guarantee that relative path resolved.
47
- *
48
- * ─── Why the relative experiment was reversed ──────────────────────────────────────────────────────
49
- * Relative registration was adopted so each git tree would be governed by "its own release, binary and
50
- * pin". MEASURED 2026-08-10: it never delivered that. A linked worktree has NO `node_modules`, so
51
- * ai-hook.sh's upward walk executes the PRIMARY's binary — `readlink -f` resolved a worktree agent's bin
52
- * to `<primary>/node_modules/@webpieces/ai-hook-rules`. A worktree ran its own SCRIPT and its own
53
- * CONFIG; it never ran its own release. Governance was already the primary's, in every tree, the whole
54
- * time.
55
- *
56
- * The price of that fiction was an entire guard layer. A relative path only resolves at a tree root, and
57
- * a hook that cannot resolve exits 127 — per the hooks reference a NON-BLOCKING error, i.e. a SILENT
58
- * UNGUARDED ALLOW. So L-1 had to deny every `cd` into a project subdirectory. That denial produced the
59
- * force-to-root bug class, the reaped-worktree `cd` prescription, and a measured hard deadlock: L-1 told
60
- * a worktree-isolated agent to `cd` to the primary clone, which the harness refuses for an isolated
61
- * agent, leaving it unable to stay or to follow the cure.
62
- *
63
- * An absolute path resolves from ANY cwd. So the launch guarantee is structural, L-1 has no job left and
64
- * is deleted, and `cd` into a subdirectory is simply allowed. What used to be true only by policing the
65
- * shell is now true by construction.
66
- *
67
- * ─── What replaces the property that was lost ──────────────────────────────────────────────────────
68
- * Nothing is lost that was ever delivered — but the case relative registration WANTED to handle (a tree
69
- * that genuinely needs a different @webpieces) is now DETECTED instead of silently mis-governed:
70
- * `VersionSyncGuard` (L1 row 8) blocks when a worktree's pin disagrees with the main tree's, and
71
- * prescribes either aligning the pins (same git hash → same tracked pin → install in each tree that has
72
- * a node_modules) or using a separate CLONE, which — unlike a worktree — gets its own GOVERNANCE. Note
73
- * what that does NOT say: a worktree may perfectly well have its own node_modules, and usually does the
74
- * moment anything installs in it. What it may not have is a DIFFERENT @webpieces version.
75
- *
76
- * ─── Why the registration is a DRIFT SURFACE, not just an install step ─────────────────────────────
77
- * Nothing used to validate `.claude/settings.json` at all, so a settings file left on a superseded form
78
- * silently changed who governs. The installed surface is FOUR things (ai-hook.sh, the registration, the
79
- * managed `env` entry — see managed-env.ts — and the ANCHORING of the NEIGHBOUR hook commands the
80
- * consumer registers beside ours, see neighbour-hooks.ts), all four are compared against this release,
81
- * and `wp-upgrade-shim` repairs all four. A cure that fixes three of four is worse than no cure, because
82
- * it reports success.
83
- */
84
- /**
85
- * The RETIRED L-1 hook's committed path. Named here, in the one module that must still recognise it, and
86
- * matched ONLY by isManagedCommand() so repairRegistration() can delete the stale entry. There is no
87
- * guarantee-root.ts any more — this literal is all that remains of it, deliberately.
88
- *
89
- * It is a one-way RECOGNISER, not a shim: nothing emits it, `expectedEntries()` never returns it, and a
90
- * settings file carrying it is reported STALE. Its only job is to make the retired entry findable so it
91
- * can be REMOVED.
92
- */
93
- exports.LEGACY_GUARANTEE_ROOT_MARKER = '.claude/webpieces/guarantee-root.sh';
94
- /**
95
- * When this recogniser may be deleted, as a value rather than a comment nobody re-reads.
96
- *
97
- * A removal-only migration is still dead weight once no consumer can be carrying the old shape. The
98
- * hazard of deleting it EARLY is severe and silent — repair would stop stripping the retired entry, and
99
- * a hook registered against a deleted file exits 127, which the Claude Code hooks reference defines as a
100
- * NON-BLOCKING error, i.e. every `cd` unjudged while the cure reports success. So it gets a stated date
101
- * and a test that fails once the date passes, instead of an intention.
102
- *
103
- * `legacy-marker-expiry.spec.ts` reads this and fails after it, which is the reminder.
104
- */
105
- exports.LEGACY_MARKER_REMOVE_AFTER = '2026-12-01';
106
- /** One PreToolUse hook entry as webpieces registers it. Data-only → a class, per CLAUDE.md. */
107
- class HookRegistrationEntry {
108
- matcher;
109
- command;
110
- constructor(matcher, command) {
111
- this.matcher = matcher;
112
- this.command = command;
113
- }
114
- sameAs(other) {
115
- return this.matcher === other.matcher && this.command === other.command;
116
- }
117
- }
118
- exports.HookRegistrationEntry = HookRegistrationEntry;
119
- /**
120
- * THE SETTINGS-FILE SHAPE lives in `./settings-shape`, a LEAF module, and is imported from THERE by
121
- * everything that needs it — this module included. It is deliberately NOT re-exported here: a second
122
- * import path for one type is the "two spellings of one thing" shim the compatibility policy rejects,
123
- * and it would keep advertising `hook-registration` as a source of the shape, which is precisely the
124
- * edge that has to stay broken (`neighbour-hooks.ts` needs the shape, this module imports the repairs
125
- * FROM it, and `validate-no-file-import-cycles` counts even a type-only edge back as a cycle).
126
- */
127
- exports.RULES_BIN = 'wp-ai-rules-hook';
128
- exports.GUARDS_BIN = 'wp-ai-guards-hook';
129
- /**
130
- * ONE HARNESS'S registration surface — where its hooks live, what they match, and how they name the
131
- * shim. Data-only → a class, per CLAUDE.md.
132
- *
133
- * ─── Why this exists ──────────────────────────────────────────────────────────────────────────────
134
- * The matchers and the shim command used to be four module constants written for Claude Code alone.
135
- * Applied to Codex they are wrong in both halves, and the way they are wrong is SILENT:
136
- *
137
- * - MATCHER. Codex's file-editing tool is `apply_patch` (MEASURED, codex-cli 0.151.0). A matcher of
138
- * `Write|Edit|MultiEdit` matches it never, so every file rule is unreachable while the settings file
139
- * looks perfectly installed. Its shell tool IS called `Bash` — Codex reuses Claude's name — which is
140
- * the trap: half the matcher works, so the hooks appear to be running.
141
- * - ANCHOR. `$CLAUDE_PROJECT_DIR` does not exist in a Codex hook's environment (measured: 46 vars, no
142
- * such key), so the command expands to `sh "/.claude/webpieces/ai-hook.sh"`, which dies — and per the
143
- * hooks protocol a non-2 non-zero exit is a NON-BLOCKING error, i.e. a silent unguarded allow.
144
- *
145
- * Both halves of that were live in real repos, written by a Codex Desktop sync that transliterated the
146
- * Claude setup. Making the registration per-harness DATA is what stops a future harness inheriting a
147
- * matcher that was never true for it.
148
- *
149
- * ─── ONE SHIM, both harnesses ─────────────────────────────────────────────────────────────────────
150
- * `SHIM_MARKER` is shared deliberately: `.claude/webpieces/ai-hook.sh` is the single fail-closed entry
151
- * point, and moving or duplicating it would double the L0 allowlist regexes, the drift surfaces and the
152
- * cures. The `.claude/` prefix is a path, not a claim about which agent is calling.
153
- */
154
- class HarnessRegistration {
155
- aiType;
156
- label;
157
- rulesMatcher;
158
- guardsMatcher;
159
- settingsFiles;
160
- shimAnchor;
161
- managesEnv;
162
- registrationSurface;
163
- // eslint-disable-next-line @typescript-eslint/max-params
164
- constructor(aiType,
165
- /** How the installer and the drift report name this harness to a human. */
166
- label,
167
- /** Which tool names the RULES hook (code-style, file-scoped) must see. */
168
- rulesMatcher,
169
- /**
170
- * Which tool names the GUARDS hook must see. Wider than the rules matcher by the shell tool and,
171
- * for Claude Code, by `Read` — Read carries no guard, but the guards hook owns the
172
- * per-invocation audit log, so matching it records every file the AI opens (log-and-allow fast
173
- * path in hook-core.ts; a Read is never blocked). Codex has no Read tool at all: a read arrives
174
- * as `Bash` running a pager, which the shell matcher already covers and read-parity synthesizes.
175
- */
176
- guardsMatcher,
177
- /** The settings files this harness's hooks can be installed into, relative to the repo root. */
178
- settingsFiles,
179
- /**
180
- * THE PREFIX THE SHIM PATH IS ANCHORED ON, and the reason each harness needs its own.
181
- *
182
- * **BYTE-STABILITY IS A HARD CONSTRAINT ON THE CODEX VALUE.** Codex trusts a hook entry
183
- * TOFU — `~/.codex/config.toml` records a `trusted_hash` per entry — so ANY change to these bytes
184
- * invalidates that trust and re-prompts the human, whose third option is `Continue without
185
- * trusting (hooks won't run)`: one keystroke to a silently unguarded session. Changing this
186
- * string is therefore never a cosmetic edit. The hash is NOT reproducible from outside Codex
187
- * (16 encodings tried against a file we authored), so the installer can never repair trust for
188
- * itself — see ./codex-trust.ts, which REPORTS and never writes.
189
- */
190
- shimAnchor,
191
- /**
192
- * True when this harness's settings file also carries the managed `env` block. Claude Code's
193
- * settings `env` is inherited by every subagent, which is what makes it the right home for the
194
- * Bash-cwd pin (see managed-env.ts). Codex has no equivalent surface — and needs none: its cwd
195
- * is MEASURED not to drift at all (`cd x && pwd` prints x, the next call is back at the repo
196
- * root, for the coordinator and for subagents alike).
197
- */
198
- managesEnv,
199
- /** What `managedSurfaceDrift()` calls this harness's registration when it has moved. */
200
- registrationSurface) {
201
- this.aiType = aiType;
202
- this.label = label;
203
- this.rulesMatcher = rulesMatcher;
204
- this.guardsMatcher = guardsMatcher;
205
- this.settingsFiles = settingsFiles;
206
- this.shimAnchor = shimAnchor;
207
- this.managesEnv = managesEnv;
208
- this.registrationSurface = registrationSurface;
209
- }
210
- /** Which matcher one guard bin registers under. */
211
- matcherFor(bin) {
212
- return bin === exports.RULES_BIN ? this.rulesMatcher : this.guardsMatcher;
213
- }
214
- /**
215
- * The guard-hook command — `sh "<anchor>/.claude/webpieces/ai-hook.sh" <bin>`.
216
- *
217
- * ABSOLUTE, in both harnesses. Claude's anchor replaced a RELATIVE spelling and that reversal is
218
- * documented at length in this file's header: relative resolves only at a tree root, a hook that
219
- * cannot resolve exits 127, and per the hooks reference that is a NON-BLOCKING error — a silent
220
- * unguarded allow. It also cost an entire guard layer (L-1) whose only job was to police the `cd`
221
- * that made the relative path resolvable.
222
- *
223
- * Invoked via `sh <file>` rather than executed directly so a missing executable bit on the
224
- * checked-in shim (fresh clone, a filesystem that drops the bit, git core.fileMode quirks) can never
225
- * break the hook with a raw `Permission denied` on every tool call. Quoted to survive spaces.
226
- */
227
- shimCommand(bin) {
228
- return `sh "${this.shimAnchor}/${shim_1.SHIM_MARKER}" ${bin}`;
229
- }
230
- /** The registration entry for one guard bin under this harness. */
231
- entryFor(bin) {
232
- return new HookRegistrationEntry(this.matcherFor(bin), this.shimCommand(bin));
233
- }
234
- /** This harness's settings files under one repo root, absolute. */
235
- settingsPaths(projectRoot) {
236
- return this.settingsFiles.map((file) => path.join(projectRoot, ...file.split('/')));
237
- }
238
- /**
239
- * What `managedSurfaceDrift()` calls this harness's NEIGHBOUR hook commands — the entries a CONSUMER
240
- * repo registers in the same file — when one of them still carries a repo-RELATIVE entry path.
241
- *
242
- * DERIVED rather than a constructor field, unlike `registrationSurface` beside it, because there is
243
- * nothing here a harness could sensibly disagree about: it is the same file, said a second way. A
244
- * constructor param would be a second place to keep in step for no decision.
245
- */
246
- get neighbourSurface() {
247
- return `${this.settingsFiles[0]} ${neighbour_hooks_1.NEIGHBOUR_SURFACE_SUFFIX}`;
248
- }
249
- }
250
- exports.HarnessRegistration = HarnessRegistration;
251
- exports.CLAUDE_REGISTRATION = new HarnessRegistration('claude-code', 'Claude Code', 'Write|Edit|MultiEdit', 'Write|Edit|MultiEdit|Bash|Read', ['.claude/settings.json', '.claude/settings.local.json'], '$CLAUDE_PROJECT_DIR', true, '.claude/settings.json hook registration');
252
- /**
253
- * Codex's registration, every value of it MEASURED against codex-cli 0.151.0 rather than assumed.
254
- *
255
- * `$PWD` is the anchor because there is no project-dir variable to use and none is needed: the payload
256
- * `cwd` and the hook process's own `PWD` are both the repo root on EVERY call — for the coordinator and
257
- * for subagents — and a `cd` inside one command never survives into the next. That was measured, not
258
- * hoped for, and it is the same effect Claude Code gets from the managed
259
- * `CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR` env entry. See `shimAnchor` for why these exact bytes are
260
- * not free to change.
261
- */
262
- exports.CODEX_REGISTRATION = new HarnessRegistration('codex', 'Codex', 'apply_patch', 'Bash|apply_patch', ['.codex/hooks.json'], '$PWD', false, '.codex/hooks.json hook registration');
263
- /**
264
- * Every harness webpieces arms, in installer order.
265
- *
266
- * The drift check, the repair and the installer all iterate THIS, so a harness cannot be armed by the
267
- * installer and then left unvalidated — which is exactly the state `.codex/hooks.json` was in before it
268
- * was a managed surface: written by something else, silently wrong, and invisible to every check.
269
- */
270
- exports.HARNESS_REGISTRATIONS = [exports.CLAUDE_REGISTRATION, exports.CODEX_REGISTRATION];
271
- /**
272
- * True when this PreToolUse command is one webpieces owns — in ANY spelling it has ever shipped.
273
- *
274
- * THE SINGLE MOST IMPORTANT LINE IN THIS RELEASE. `LEGACY_GUARANTEE_ROOT_MARKER` is matched here and
275
- * NOWHERE else: it is how `repairRegistration()` finds and REMOVES the retired H1 entry from a settings
276
- * file written by an older release. Drop it and the repair silently leaves a live L-1 hook registered
277
- * against a file this release deletes — exit 127, which the Claude Code hooks reference defines as a
278
- * NON-BLOCKING error, so every `cd` goes unjudged while `wp-upgrade-shim` reports success and no drift
279
- * check can name it. Removal-only, never emitted: it appears in no `expectedEntries()` result, so it is
280
- * a one-way migration and not a second accepted spelling.
281
- */
282
- // webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as shimCommand above
283
- function isManagedCommand(command) {
284
- return command.includes(shim_1.SHIM_MARKER) || command.includes(exports.LEGACY_GUARANTEE_ROOT_MARKER);
285
- }
286
- // webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as shimCommand above
287
- function preToolUse(settings) {
288
- return settings.hooks?.PreToolUse ?? [];
289
- }
290
- /** Every webpieces-managed entry of one settings file, flattened to matcher + command pairs. */
291
- // webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as shimCommand above
292
- function managedEntries(settings) {
293
- const found = [];
294
- for (const entry of preToolUse(settings)) {
295
- for (const hook of entry.hooks) {
296
- if (isManagedCommand(hook.command))
297
- found.push(new HookRegistrationEntry(entry.matcher, hook.command));
298
- }
299
- }
300
- return found;
301
- }
302
- /**
303
- * Which guard bins this settings file registers, in installer order. A file registering NEITHER is not
304
- * a project (relative) install and is therefore never judged — a global/absolute install names the bin
305
- * path directly and carries no shim marker at all.
306
- */
307
- // webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as shimCommand above
308
- function registeredBins(settings) {
309
- const commands = managedEntries(settings).map((e) => e.command);
310
- return [exports.GUARDS_BIN, exports.RULES_BIN].filter((bin) => commands.some((c) => c.includes(bin)));
311
- }
312
- /**
313
- * The exact set of entries THIS RELEASE expects in a settings file that registers `bins`.
314
- *
315
- * ONE entry per registered bin, and nothing else. There used to be a third, `guarantee-root.sh`, added
316
- * whenever the GUARDS bin was present; it is retired, and a settings file still carrying it is STALE —
317
- * `repairRegistration()` removes it via isManagedCommand()'s legacy marker.
318
- */
319
- // webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as HarnessRegistration's siblings
320
- function expectedEntries(harness, bins) {
321
- return bins.map((bin) => harness.entryFor(bin));
322
- }
323
- /**
324
- * True when a settings file registers webpieces hooks in a shape this release does not expect: a
325
- * RELATIVE shim command, a leftover guarantee-root entry, a stray duplicate, or a wrong matcher.
326
- *
327
- * Compared as a SET, not a sequence: Claude Code runs all matching hooks in parallel, so array order
328
- * carries no meaning and reordering must not read as drift.
329
- */
330
- // webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as shimCommand above
331
- function registrationStale(harness, settings) {
332
- const bins = registeredBins(settings);
333
- if (bins.length === 0)
334
- return false;
335
- const have = managedEntries(settings);
336
- const want = expectedEntries(harness, bins);
337
- if (have.length !== want.length)
338
- return true;
339
- return want.some((w) => !have.some((h) => h.sameAs(w)));
340
- }
341
- /** Drop every webpieces-managed PreToolUse command; returns true if anything was removed. */
342
- // webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as shimCommand above
343
- function dropManagedEntries(settings) {
344
- const entries = settings.hooks?.PreToolUse;
345
- if (!entries)
346
- return false;
347
- let changed = false;
348
- const kept = [];
349
- for (const entry of entries) {
350
- const hooks = entry.hooks.filter((h) => !isManagedCommand(h.command));
351
- if (hooks.length !== entry.hooks.length)
352
- changed = true;
353
- if (hooks.length > 0)
354
- kept.push({ matcher: entry.matcher, hooks });
355
- }
356
- if (changed)
357
- settings.hooks.PreToolUse = kept;
358
- return changed;
359
- }
360
- /** Append one PreToolUse entry. */
361
- // webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as shimCommand above
362
- function addHookEntry(settings, entry) {
363
- if (!settings.hooks)
364
- settings.hooks = {};
365
- if (!Array.isArray(settings.hooks.PreToolUse))
366
- settings.hooks.PreToolUse = [];
367
- settings.hooks.PreToolUse.push({ matcher: entry.matcher, hooks: [{ type: 'command', command: entry.command }] });
368
- }
369
- /** The settings `env` block, or null when the file carries none (or carries junk in its place). */
370
- // webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as shimCommand above
371
- function settingsEnv(settings) {
372
- // webpieces-disable no-any-unknown -- settings.json is opaque consumer JSON; `env` is only typed after this check
373
- const env = settings.env;
374
- if (typeof env !== 'object' || env === null || Array.isArray(env))
375
- return null;
376
- return env;
377
- }
378
- /**
379
- * True when a settings file that registers webpieces hooks is missing the managed `env` entry, or
380
- * carries any value other than the one required one.
381
- *
382
- * Gated on `registeredBins()` for the SAME reason `registrationStale()` is: a settings file that
383
- * registers no webpieces hooks is not a project install and is never judged — a global install names
384
- * the bin path directly and carries no shim marker at all, so there is nothing here to keep in step.
385
- *
386
- * NOTE what this entry is for NOW. It was originally justified by keeping the then-RELATIVE hook path
387
- * resolvable; that job is retired, because both hooks are absolute and resolve from any cwd. It is kept
388
- * for VERDICT STABILITY — a guard's answer must depend on the command, not on where an earlier `cd` left
389
- * the shell — and because settings `env` is inherited, every subagent shares that cwd and therefore that
390
- * verdict. See managed-env.ts, which states this at length.
391
- */
392
- // webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as shimCommand above
393
- function envStale(settings) {
394
- if (registeredBins(settings).length === 0)
395
- return false;
396
- const env = settingsEnv(settings);
397
- return env === null || env[managed_env_1.BASH_CWD_ENV_KEY] !== managed_env_1.BASH_CWD_ENV_VALUE;
398
- }
399
- /**
400
- * Set the managed `env` entry IN PLACE, whatever was there before. Returns true when it changed.
401
- *
402
- * A user-set `"0"` is BROUGHT TO `"1"`, not honoured: this is a managed surface, and "webpieces sets it
403
- * unless you disagreed" would be a second, invisible spelling of the decision. Turning it off means
404
- * uninstalling the hooks, exactly as it does for every other managed thing.
405
- *
406
- * UNGATED on purpose — the installer calls it for the file it is writing hooks into, and the gate lives
407
- * at the caller (repairRegistration / applyHook), so a file with no webpieces hooks is never touched.
408
- */
409
- // webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as shimCommand above
410
- function applyManagedEnv(settings) {
411
- const existing = settingsEnv(settings);
412
- if (existing !== null && existing[managed_env_1.BASH_CWD_ENV_KEY] === managed_env_1.BASH_CWD_ENV_VALUE)
413
- return false;
414
- const env = existing ?? {};
415
- env[managed_env_1.BASH_CWD_ENV_KEY] = managed_env_1.BASH_CWD_ENV_VALUE;
416
- settings.env = env;
417
- return true;
418
- }
419
- /**
420
- * Bring one settings object to the two-hook ABSOLUTE form AND the managed `env` entry IN PLACE. Returns
421
- * true when it changed anything.
422
- *
423
- * REMOVE-then-ADD for the hooks, never add-beside: two spellings of one registration is exactly the
424
- * compatibility shim the backwards-compat reviewer rejects, and leaving a RELATIVE entry beside the
425
- * absolute one would run two shims per call — the
426
- * straddle this whole change exists to delete.
427
- *
428
- * THE TWO REPAIRS ARE EVALUATED INDEPENDENTLY, and that is load-bearing rather than tidy: this used to
429
- * early-return on `!registrationStale(settings)`, so a repo whose hooks are already current but whose
430
- * `env` entry is missing — the state EVERY existing consumer is in the moment this release lands — would
431
- * have been reported as drifted by fault S and then left unrepaired by its own prescribed cure. A cure
432
- * that skips half the surface is the failure mode `upgrade-shim.ts`'s header exists to prevent.
433
- */
434
- // webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as shimCommand above
435
- function repairRegistration(harness, settings) {
436
- const bins = registeredBins(settings);
437
- if (bins.length === 0)
438
- return false;
439
- let changed = false;
440
- if (registrationStale(harness, settings)) {
441
- dropManagedEntries(settings);
442
- for (const entry of expectedEntries(harness, bins))
443
- addHookEntry(settings, entry);
444
- changed = true;
445
- }
446
- // Only where the harness HAS that surface. Codex's hooks.json has no `env` block to manage, and
447
- // inventing one there would write a key Codex does not read — a managed surface nothing consumes is
448
- // a surface that can drift with no consequence and no way to notice.
449
- if (harness.managesEnv && applyManagedEnv(settings))
450
- changed = true;
451
- return changed;
452
- }
453
- // webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as shimCommand above
454
- function readSettings(settingsPath) {
455
- if (!fs.existsSync(settingsPath))
456
- return {};
457
- const raw = fs.readFileSync(settingsPath, 'utf8');
458
- if (raw.trim() === '')
459
- return {};
460
- // eslint-disable-next-line @webpieces/no-unmanaged-exceptions
461
- try {
462
- return JSON.parse(raw);
463
- }
464
- catch (err) {
465
- const error = (0, to_error_1.toError)(err);
466
- throw new Error(`${settingsPath} has invalid JSON — fix it, then retry: ${error.message}`, { cause: error });
467
- }
468
- }
469
- // webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as shimCommand above
470
- function writeSettings(settingsPath, settings) {
471
- fs.mkdirSync(path.dirname(settingsPath), { recursive: true });
472
- fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 4) + '\n');
473
- }
474
- /**
475
- * True when any settings file ONE HARNESS owns under `root` carries a NEIGHBOUR hook — one the consumer
476
- * repo wrote — whose entry path is repo-RELATIVE and would therefore fail to resolve from any cwd but
477
- * the root. See neighbour-hooks.ts for the measured failure and why webpieces owns the repair.
478
- *
479
- * Judged ONLY where the file registers webpieces hooks, exactly like `registrationStaleAt` below: a
480
- * settings file with no webpieces hooks in it is not a webpieces install, and webpieces rewriting
481
- * somebody's unrelated hook lines there would be editing a file it was never given.
482
- */
483
- // webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as HarnessRegistration's siblings
484
- function neighbourHooksStaleAt(harness, root) {
485
- if (root === null)
486
- return false;
487
- // eslint-disable-next-line @webpieces/no-unmanaged-exceptions
488
- try {
489
- return harness.settingsPaths(root).some((p) => {
490
- const settings = readSettings(p);
491
- return registeredBins(settings).length > 0 && (0, neighbour_hooks_1.neighbourHooksStale)(harness.shimAnchor, settings, root);
492
- });
493
- }
494
- catch (err) {
495
- const error = (0, to_error_1.toError)(err);
496
- void error; // best-effort: unreadable/invalid settings counts as "not stale" so it never wedges a call
497
- return false;
498
- }
499
- }
500
- /**
501
- * True when any settings file ONE HARNESS owns under `root` carries a stale registration.
502
- *
503
- * Per harness, not per repo, so the drift report can NAME which one moved — `.claude/settings.json` and
504
- * `.codex/hooks.json` have different cures, and a fault that says only "the registration is stale" sends
505
- * the reader to the wrong file half the time.
506
- *
507
- * A file that does not exist, or exists and registers no webpieces hooks, is never judged (see
508
- * `registrationStale`). That is what keeps a repo which has never armed Codex from suddenly faulting on
509
- * a `.codex/hooks.json` it does not have.
510
- */
511
- // webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as HarnessRegistration's siblings
512
- function registrationStaleAt(harness, root) {
513
- if (root === null)
514
- return false;
515
- // eslint-disable-next-line @webpieces/no-unmanaged-exceptions
516
- try {
517
- return harness.settingsPaths(root).some((p) => registrationStale(harness, readSettings(p)));
518
- }
519
- catch (err) {
520
- const error = (0, to_error_1.toError)(err);
521
- void error; // best-effort: unreadable/invalid settings counts as "not stale" so it never wedges a call
522
- return false;
523
- }
524
- }
525
- /**
526
- * True when either Claude project settings file under `root` is missing the managed `env` entry.
527
- *
528
- * CLAUDE-ONLY by construction, and stated as such rather than looped over the harnesses: `env` is a
529
- * Claude Code settings surface, Codex has no equivalent, and Codex's cwd is measured not to drift, which
530
- * is the whole thing the entry is for. See HarnessRegistration.managesEnv.
531
- */
532
- // webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as HarnessRegistration's siblings
533
- function envStaleAt(root) {
534
- if (root === null)
535
- return false;
536
- // eslint-disable-next-line @webpieces/no-unmanaged-exceptions
537
- try {
538
- return exports.CLAUDE_REGISTRATION.settingsPaths(root).some((p) => envStale(readSettings(p)));
539
- }
540
- catch (err) {
541
- const error = (0, to_error_1.toError)(err);
542
- void error; // best-effort: unreadable/invalid settings counts as "not stale" so it never wedges a call
543
- return false;
544
- }
545
- }
546
- /**
547
- * WHAT was rewritten in ONE settings file. Data-only → a class, per CLAUDE.md.
548
- *
549
- * Two independent flags rather than one path, because the cure has to be able to SAY which repair it
550
- * made: "rewrote the hook registration" printed for a file whose registration was already current and
551
- * whose `env` entry was the only thing missing is a cure lying about its own work.
552
- */
553
- class SettingsRepair {
554
- settingsPath;
555
- registration;
556
- env;
557
- anchoredNeighbours;
558
- constructor(settingsPath, registration, env,
559
- /**
560
- * The NEW spelling of every NEIGHBOUR hook command this repair anchored — the consumer's own
561
- * entries, which webpieces rewrites but does not author.
562
- *
563
- * The commands themselves rather than a count or a flag, because this is the one repair that
564
- * edits lines webpieces did not write: the cure has to be able to show the consumer exactly what
565
- * it changed in their file, or it is a silent edit to somebody else's hooks.
566
- */
567
- anchoredNeighbours) {
568
- this.settingsPath = settingsPath;
569
- this.registration = registration;
570
- this.env = env;
571
- this.anchoredNeighbours = anchoredNeighbours;
572
- }
573
- }
574
- exports.SettingsRepair = SettingsRepair;
575
- /**
576
- * Rewrite every stale settings file under `root`, for EVERY harness; returns what changed, per file.
577
- *
578
- * Existing files only — this never CREATES a registration. Arming a harness is the installer's decision
579
- * (`wp-install-ai-hooks`); this is the cure for one that has already been armed and has drifted, so a
580
- * repo that has never armed Codex is left exactly as it was.
581
- */
582
- // webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as HarnessRegistration's siblings
583
- function repairRegistrationAt(root) {
584
- const repairs = [];
585
- for (const harness of exports.HARNESS_REGISTRATIONS) {
586
- for (const settingsPath of harness.settingsPaths(root)) {
587
- if (!fs.existsSync(settingsPath))
588
- continue;
589
- const settings = readSettings(settingsPath);
590
- const neededRegistration = registrationStale(harness, settings);
591
- const neededEnv = harness.managesEnv && envStale(settings);
592
- const changedManaged = repairRegistration(harness, settings);
593
- // AFTER the managed repair, never before: repairRegistration() removes the retired
594
- // guarantee-root entry and rewrites the two managed commands, so by the time the neighbour
595
- // pass runs there is nothing webpieces-owned left for it to look at. Gated on
596
- // registeredBins() for the same reason every other judgement here is — a settings file that
597
- // registers no webpieces hooks is not a webpieces install, and rewriting somebody's
598
- // unrelated hook lines in it would be webpieces editing a file it was never given.
599
- const anchored = registeredBins(settings).length === 0 ? [] : (0, neighbour_hooks_1.anchorNeighbourHooks)(harness.shimAnchor, settings, root);
600
- if (!changedManaged && anchored.length === 0)
601
- continue;
602
- writeSettings(settingsPath, settings);
603
- repairs.push(new SettingsRepair(settingsPath, neededRegistration, neededEnv, anchored));
604
- }
605
- }
606
- return repairs;
607
- }
608
- /**
609
- * The names the drift check reports, so a deny can say WHICH surface moved.
610
- *
611
- * There were four, then three, and there are now FOUR again — but the fourth is not the one that was
612
- * deleted. `GUARANTEE_ROOT_SURFACE` went with L-1 itself: an absolutely-registered shim resolves from
613
- * any cwd, so there is no launch guarantee left to police and no second .sh file to keep byte-locked. A
614
- * settings file still carrying the retired H1 entry is not its own surface — it is ordinary REGISTRATION
615
- * drift, which `registrationStaleAt()` reports and `repairRegistration()` fixes by removing it.
616
- *
617
- * The new fourth is `.codex/hooks.json`, and it is here because of what happened while it was NOT a
618
- * managed surface: something else wrote it, with a matcher that matched no Codex file tool and a shim
619
- * path anchored on a variable Codex does not set, and no check in this package could see it. A file the
620
- * guards depend on and nothing validates is the exact shape of that incident.
621
- *
622
- * Each harness's registration surface is its own name, from HarnessRegistration.registrationSurface, so
623
- * the deny sends the reader to the file that actually moved.
624
- */
625
- exports.SHIM_SURFACE = shim_1.SHIM_MARKER;
626
- exports.REGISTRATION_SURFACE = exports.CLAUDE_REGISTRATION.registrationSurface;
627
- exports.CODEX_REGISTRATION_SURFACE = exports.CODEX_REGISTRATION.registrationSurface;
628
- exports.ENV_SURFACE = `.claude/settings.json env.${managed_env_1.BASH_CWD_ENV_KEY}`;
629
- // The generic PR-gate reviewer agent (issue #938): committed, generated, byte-stable — the same contract as
630
- // the shim, so the same check and the same cure.
631
- exports.REVIEWER_AGENT_SURFACE = reviewer_agent_1.REVIEWER_AGENT_MARKER;
632
- /**
633
- * WHICH of the managed surfaces disagree with this release — the input to fault S.
634
- *
635
- * All of them are checked against the SAME root, resolved from the RUNNING MODULE (governingShimRoot),
636
- * never from cwd and never from `$CLAUDE_PROJECT_DIR`: the files we compare and the renderers we
637
- * compare them TO must come from one install, or the check straddles two trees and can never converge.
638
- */
639
- // webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as HarnessRegistration's siblings
640
- function managedSurfaceDrift(root) {
641
- const drifted = [];
642
- if ((0, shim_1.committedShimStale)(root))
643
- drifted.push(exports.SHIM_SURFACE);
644
- for (const harness of exports.HARNESS_REGISTRATIONS) {
645
- if (registrationStaleAt(harness, root))
646
- drifted.push(harness.registrationSurface);
647
- // A neighbour hook registered with a RELATIVE entry path dies from any cwd but the root, and per
648
- // the hooks reference that non-zero exit is a NON-BLOCKING error — a SILENT UNGUARDED ALLOW. It
649
- // is a drift surface for exactly the reason the managed registration is one: nothing else in
650
- // this repo can see it, and the way it fails looks like a guard that PASSED. See
651
- // neighbour-hooks.ts, and issue #852 where it silently disarmed three security guards.
652
- if (neighbourHooksStaleAt(harness, root))
653
- drifted.push(harness.neighbourSurface);
654
- }
655
- if (envStaleAt(root))
656
- drifted.push(exports.ENV_SURFACE);
657
- if ((0, reviewer_agent_1.reviewerAgentStale)(root))
658
- drifted.push(exports.REVIEWER_AGENT_SURFACE);
659
- return drifted;
660
- }
661
- //# sourceMappingURL=hook-registration.js.map