@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,69 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ClaudeCodeAdapter = void 0;
4
- const hook_runtime_1 = require("@webpieces/hook-runtime");
5
- const types_1 = require("../core/types");
6
- /**
7
- * The Claude Code tools that enter the file/edit rule pipeline. `Read` is deliberately NOT here — it
8
- * has its own fast path and only one guard may see it.
9
- */
10
- const HANDLED_FILE_TOOLS = new Set(['Write', 'Edit', 'MultiEdit']);
11
- /**
12
- * Morphs a Claude Code PreToolUse payload into the one normalized `AgentHookEvent`.
13
- *
14
- * This is the SAME `normalizeToolKind` / `normalizeToolInput` logic that used to live inline in
15
- * hook-core.ts, moved out unchanged so hook-core is written once for every harness. Claude Code is the
16
- * harness every developer uses today, so nothing about the mapping is allowed to move: `Write` still
17
- * becomes one edit of `content` against '', `Edit` one edit of `old_string`→`new_string`, `MultiEdit`
18
- * one per entry, and a file tool with no `file_path` still ends up allowed (kind `Ignored`).
19
- */
20
- class ClaudeCodeAdapter {
21
- /**
22
- * What is known from the ENVELOPE ALONE, touching nothing but `tool_name` and the identity fields.
23
- *
24
- * Not a second spelling of `toEvent` — a different question, asked at a moment when the answer to
25
- * the other one may not exist. `toEvent` reads `tool_input`, and a payload whose `tool_input` is
26
- * missing makes it throw; the crash then still has to be DENIED, and the deny still has to know
27
- * whether it is decorating a Bash block (which needs the red `systemMessage`) or a file block
28
- * (which does not). This is the shape that answers that, and it cannot fail.
29
- */
30
- envelope(payload) {
31
- return new hook_runtime_1.AgentHookEvent('claude-code', this.kindOf(payload.tool_name), payload.tool_name, payload.cwd ?? '', payload.session_id ?? '', payload.agent_id ?? '', payload.agent_type ?? '', [], null, []);
32
- }
33
- toEvent(payload, cwd) {
34
- const kind = this.kindOf(payload.tool_name);
35
- const toolInput = payload.tool_input;
36
- const bash = kind === 'Bash' ? new types_1.NormalizedBashInput(toolInput.command ?? '') : null;
37
- const reads = kind === 'Read' ? [toolInput.file_path ?? ''] : [];
38
- const files = kind === 'File' ? this.fileOperations(payload.tool_name, toolInput) : [];
39
- // A file tool that named no file has nothing to judge; fall back to Ignored so the hook allows
40
- // it, exactly as the old `if (!input) emitAllow()` did.
41
- const effective = kind === 'File' && files.length === 0 ? 'Ignored' : kind;
42
- return new hook_runtime_1.AgentHookEvent('claude-code', effective, payload.tool_name, cwd, payload.session_id ?? '', payload.agent_id ?? '', payload.agent_type ?? '', files, bash, reads);
43
- }
44
- kindOf(toolName) {
45
- if (toolName === 'Bash')
46
- return 'Bash';
47
- if (toolName === 'Read')
48
- return 'Read';
49
- if (HANDLED_FILE_TOOLS.has(toolName))
50
- return 'File';
51
- return 'Ignored';
52
- }
53
- fileOperations(toolKind, toolInput) {
54
- const filePath = toolInput.file_path;
55
- if (!filePath)
56
- return [];
57
- if (toolKind === 'Write') {
58
- return [new hook_runtime_1.FileOperation(toolKind, new types_1.NormalizedToolInput(filePath, [new types_1.NormalizedEdit('', toolInput.content || '')]))];
59
- }
60
- if (toolKind === 'Edit') {
61
- return [new hook_runtime_1.FileOperation(toolKind, new types_1.NormalizedToolInput(filePath, [new types_1.NormalizedEdit(toolInput.old_string || '', toolInput.new_string || '')]))];
62
- }
63
- const raw = Array.isArray(toolInput.edits) ? toolInput.edits : [];
64
- const edits = raw.map((e) => new types_1.NormalizedEdit(e.old_string || '', e.new_string || ''));
65
- return [new hook_runtime_1.FileOperation(toolKind, new types_1.NormalizedToolInput(filePath, edits))];
66
- }
67
- }
68
- exports.ClaudeCodeAdapter = ClaudeCodeAdapter;
69
- //# sourceMappingURL=claude-code-adapter.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"claude-code-adapter.js","sourceRoot":"","sources":["../../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IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC1J,CAAC;QACD,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;QAClE,MAAM,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,CAAiB,EAAkB,EAAE,CAAC,IAAI,sBAAc,CAAC,CAAC,CAAC,UAAU,IAAI,EAAE,EAAE,CAAC,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,CAAC;QACzH,OAAO,CAAC,IAAI,4BAAa,CAAC,QAAQ,EAAE,IAAI,2BAAmB,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;IACnF,CAAC;CACJ;AAtDD,8CAsDC","sourcesContent":["import { AgentPayload, AgentToolInput, AgentEditEntry } from './agent-payload';\nimport { AgentHookEvent, AgentEventKind, FileOperation } from '@webpieces/hook-runtime';\nimport { NormalizedBashInput, NormalizedEdit, NormalizedToolInput, ToolKind } from '../core/types';\n\n/**\n * The Claude Code tools that enter the file/edit rule pipeline. `Read` is deliberately NOT here — it\n * has its own fast path and only one guard may see it.\n */\nconst HANDLED_FILE_TOOLS: ReadonlySet<string> = new Set(['Write', 'Edit', 'MultiEdit']);\n\n/**\n * Morphs a Claude Code PreToolUse payload into the one normalized `AgentHookEvent`.\n *\n * This is the SAME `normalizeToolKind` / `normalizeToolInput` logic that used to live inline in\n * hook-core.ts, moved out unchanged so hook-core is written once for every harness. Claude Code is the\n * harness every developer uses today, so nothing about the mapping is allowed to move: `Write` still\n * becomes one edit of `content` against '', `Edit` one edit of `old_string`→`new_string`, `MultiEdit`\n * one per entry, and a file tool with no `file_path` still ends up allowed (kind `Ignored`).\n */\nexport class ClaudeCodeAdapter {\n /**\n * What is known from the ENVELOPE ALONE, touching nothing but `tool_name` and the identity fields.\n *\n * Not a second spelling of `toEvent` — a different question, asked at a moment when the answer to\n * the other one may not exist. `toEvent` reads `tool_input`, and a payload whose `tool_input` is\n * missing makes it throw; the crash then still has to be DENIED, and the deny still has to know\n * whether it is decorating a Bash block (which needs the red `systemMessage`) or a file block\n * (which does not). This is the shape that answers that, and it cannot fail.\n */\n envelope(payload: AgentPayload): AgentHookEvent {\n return new AgentHookEvent(\n 'claude-code', this.kindOf(payload.tool_name), payload.tool_name,\n payload.cwd ?? '', payload.session_id ?? '', payload.agent_id ?? '', payload.agent_type ?? '',\n [], null, [],\n );\n }\n\n toEvent(payload: AgentPayload, cwd: string): AgentHookEvent {\n const kind = this.kindOf(payload.tool_name);\n const toolInput = payload.tool_input;\n const bash = kind === 'Bash' ? new NormalizedBashInput(toolInput.command ?? '') : null;\n const reads = kind === 'Read' ? [toolInput.file_path ?? ''] : [];\n const files = kind === 'File' ? this.fileOperations(payload.tool_name as ToolKind, toolInput) : [];\n // A file tool that named no file has nothing to judge; fall back to Ignored so the hook allows\n // it, exactly as the old `if (!input) emitAllow()` did.\n const effective: AgentEventKind = kind === 'File' && files.length === 0 ? 'Ignored' : kind;\n return new AgentHookEvent(\n 'claude-code', effective, payload.tool_name,\n cwd, payload.session_id ?? '', payload.agent_id ?? '', payload.agent_type ?? '',\n files, bash, reads,\n );\n }\n\n private kindOf(toolName: string): AgentEventKind {\n if (toolName === 'Bash') return 'Bash';\n if (toolName === 'Read') return 'Read';\n if (HANDLED_FILE_TOOLS.has(toolName)) return 'File';\n return 'Ignored';\n }\n\n private fileOperations(toolKind: ToolKind, toolInput: AgentToolInput): readonly FileOperation[] {\n const filePath = toolInput.file_path;\n if (!filePath) return [];\n if (toolKind === 'Write') {\n return [new FileOperation(toolKind, new NormalizedToolInput(filePath, [new NormalizedEdit('', toolInput.content || '')]))];\n }\n if (toolKind === 'Edit') {\n return [new FileOperation(toolKind, new NormalizedToolInput(filePath, [new NormalizedEdit(toolInput.old_string || '', toolInput.new_string || '')]))];\n }\n const raw = Array.isArray(toolInput.edits) ? toolInput.edits : [];\n const edits = raw.map((e: AgentEditEntry): NormalizedEdit => new NormalizedEdit(e.old_string || '', e.new_string || ''));\n return [new FileOperation(toolKind, new NormalizedToolInput(filePath, edits))];\n }\n}\n"]}
@@ -1,19 +0,0 @@
1
- import { AgentPayload } from './agent-payload';
2
- import { AgentHookEvent } from '@webpieces/hook-runtime';
3
- /**
4
- * Morphs a Codex PreToolUse payload into the one normalized `AgentHookEvent`.
5
- *
6
- * Codex exposes exactly two tools this hook has anything to say about. Everything else measured in a
7
- * live session — `webrun`, `collaborationspawn_agent`, `collaborationwait_agent`, `view_image`,
8
- * `update_plan` — and every tool not yet seen maps to `Ignored` and is allowed immediately. That
9
- * default is chosen on purpose: an unknown tool is one we cannot judge, and inventing a mapping for it
10
- * would apply file rules to bytes that are not a file edit.
11
- */
12
- export declare class CodexAdapter {
13
- private readonly patchParser;
14
- private readonly readParity;
15
- /** See ClaudeCodeAdapter.envelope — the pre-normalization shape the crash deny needs. */
16
- envelope(payload: AgentPayload): AgentHookEvent;
17
- toEvent(payload: AgentPayload, cwd: string): AgentHookEvent;
18
- private kindOf;
19
- }
@@ -1,48 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CodexAdapter = void 0;
4
- const rules_config_1 = require("@webpieces/rules-config");
5
- const hook_runtime_1 = require("@webpieces/hook-runtime");
6
- const types_1 = require("../core/types");
7
- const apply_patch_parse_1 = require("../core/apply-patch-parse");
8
- const shell_read_parity_1 = require("../core/shell-read-parity");
9
- /** Codex's shell tool. MEASURED: it reuses Claude's name — it is `Bash`, NOT `shell`. */
10
- const CODEX_BASH = 'Bash';
11
- /** Codex's ONLY file-editing tool. One envelope, many files, mixed operations. */
12
- const CODEX_APPLY_PATCH = 'apply_patch';
13
- /**
14
- * Morphs a Codex PreToolUse payload into the one normalized `AgentHookEvent`.
15
- *
16
- * Codex exposes exactly two tools this hook has anything to say about. Everything else measured in a
17
- * live session — `webrun`, `collaborationspawn_agent`, `collaborationwait_agent`, `view_image`,
18
- * `update_plan` — and every tool not yet seen maps to `Ignored` and is allowed immediately. That
19
- * default is chosen on purpose: an unknown tool is one we cannot judge, and inventing a mapping for it
20
- * would apply file rules to bytes that are not a file edit.
21
- */
22
- class CodexAdapter {
23
- patchParser = new apply_patch_parse_1.ApplyPatchParser();
24
- readParity = new shell_read_parity_1.ShellReadParity();
25
- /** See ClaudeCodeAdapter.envelope — the pre-normalization shape the crash deny needs. */
26
- envelope(payload) {
27
- return new hook_runtime_1.AgentHookEvent('codex', this.kindOf(payload.tool_name), payload.tool_name, payload.cwd ?? '', payload.session_id ?? '', payload.agent_id ?? '', payload.agent_type ?? '', [], null, []);
28
- }
29
- toEvent(payload, cwd) {
30
- const kind = this.kindOf(payload.tool_name);
31
- const command = payload.tool_input.command ?? '';
32
- const bash = kind === 'Bash' ? new types_1.NormalizedBashInput(command) : null;
33
- // Read parity: Codex has no Read tool, so a read arrives as `Bash` running a pager. Synthesized
34
- // reads run the read guard IN ADDITION to the bash guards — see ../core/shell-read-parity.ts.
35
- const reads = kind === 'Bash' ? this.readParity.readTargets(command, cwd, new rules_config_1.RepoRootFinder().resolveRepoRoot(cwd)) : [];
36
- const files = kind === 'File' ? this.patchParser.parse(command, cwd) : [];
37
- return new hook_runtime_1.AgentHookEvent('codex', kind, payload.tool_name, cwd, payload.session_id ?? '', payload.agent_id ?? '', payload.agent_type ?? '', files, bash, reads);
38
- }
39
- kindOf(toolName) {
40
- if (toolName === CODEX_BASH)
41
- return 'Bash';
42
- if (toolName === CODEX_APPLY_PATCH)
43
- return 'File';
44
- return 'Ignored';
45
- }
46
- }
47
- exports.CodexAdapter = CodexAdapter;
48
- //# sourceMappingURL=codex-adapter.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"codex-adapter.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/adapters/codex-adapter.ts"],"names":[],"mappings":";;;AAAA,0DAAyD;AAGzD,0DAAyE;AACzE,yCAAoD;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,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC1E,OAAO,IAAI,6BAAc,CACrB,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,SAAS,EAChC,GAAG,EAAE,OAAO,CAAC,UAAU,IAAI,EAAE,EAAE,OAAO,CAAC,QAAQ,IAAI,EAAE,EAAE,OAAO,CAAC,UAAU,IAAI,EAAE,EAC/E,KAAK,EAAE,IAAI,EAAE,KAAK,CACrB,CAAC;IACN,CAAC;IAEO,MAAM,CAAC,QAAgB;QAC3B,IAAI,QAAQ,KAAK,UAAU;YAAE,OAAO,MAAM,CAAC;QAC3C,IAAI,QAAQ,KAAK,iBAAiB;YAAE,OAAO,MAAM,CAAC;QAClD,OAAO,SAAS,CAAC;IACrB,CAAC;CACJ;AAjCD,oCAiCC","sourcesContent":["import { RepoRootFinder } from '@webpieces/rules-config';\n\nimport { AgentPayload } from './agent-payload';\nimport { AgentHookEvent, AgentEventKind } from '@webpieces/hook-runtime';\nimport { NormalizedBashInput } from '../core/types';\nimport { ApplyPatchParser } from '../core/apply-patch-parse';\nimport { ShellReadParity } from '../core/shell-read-parity';\n\n/** Codex's shell tool. MEASURED: it reuses Claude's name — it is `Bash`, NOT `shell`. */\nconst CODEX_BASH = 'Bash';\n/** Codex's ONLY file-editing tool. One envelope, many files, mixed operations. */\nconst CODEX_APPLY_PATCH = 'apply_patch';\n\n/**\n * Morphs a Codex PreToolUse payload into the one normalized `AgentHookEvent`.\n *\n * Codex exposes exactly two tools this hook has anything to say about. Everything else measured in a\n * live session — `webrun`, `collaborationspawn_agent`, `collaborationwait_agent`, `view_image`,\n * `update_plan` — and every tool not yet seen maps to `Ignored` and is allowed immediately. That\n * default is chosen on purpose: an unknown tool is one we cannot judge, and inventing a mapping for it\n * would apply file rules to bytes that are not a file edit.\n */\nexport class CodexAdapter {\n private readonly patchParser = new ApplyPatchParser();\n private readonly readParity = new ShellReadParity();\n\n /** See ClaudeCodeAdapter.envelope — the pre-normalization shape the crash deny needs. */\n envelope(payload: AgentPayload): AgentHookEvent {\n return new AgentHookEvent(\n 'codex', this.kindOf(payload.tool_name), payload.tool_name,\n payload.cwd ?? '', payload.session_id ?? '', payload.agent_id ?? '', payload.agent_type ?? '',\n [], null, [],\n );\n }\n\n toEvent(payload: AgentPayload, cwd: string): AgentHookEvent {\n const kind = this.kindOf(payload.tool_name);\n const command = payload.tool_input.command ?? '';\n const bash = kind === 'Bash' ? new NormalizedBashInput(command) : null;\n // Read parity: Codex has no Read tool, so a read arrives as `Bash` running a pager. Synthesized\n // reads run the read guard IN ADDITION to the bash guards — see ../core/shell-read-parity.ts.\n const reads = kind === 'Bash' ? this.readParity.readTargets(command, cwd, new RepoRootFinder().resolveRepoRoot(cwd)) : [];\n const files = kind === 'File' ? this.patchParser.parse(command, cwd) : [];\n return new AgentHookEvent(\n 'codex', kind, payload.tool_name,\n cwd, payload.session_id ?? '', payload.agent_id ?? '', payload.agent_type ?? '',\n files, bash, reads,\n );\n }\n\n private kindOf(toolName: string): AgentEventKind {\n if (toolName === CODEX_BASH) return 'Bash';\n if (toolName === CODEX_APPLY_PATCH) return 'File';\n return 'Ignored';\n }\n}\n"]}
@@ -1,45 +0,0 @@
1
- import { AgentHookEvent } from '@webpieces/hook-runtime';
2
- import { BlockedResult } from '../core/types';
3
- export declare const CODEX_SUBAGENT_RULE = "codex-subagent-no-write-in-shared-tree";
4
- /**
5
- * A Codex SUBAGENT may not write into the tree it shares with its coordinator.
6
- *
7
- * This exists because of a MEASURED structural gap, not a style preference. Claude Code can hand a
8
- * subagent its own git worktree (`isolation: "worktree"`), so two agents editing at once are editing
9
- * two different checkouts. Codex cannot: `spawn_agent`'s schema is
10
- * `{fork_turns?, message, model?, reasoning_effort?, task_name}` — there is no cwd, workdir or
11
- * worktree parameter — and cwd resets to the repo root before every command, so a subagent cannot even
12
- * put itself somewhere else. Every Codex subagent therefore writes into the coordinator's checkout,
13
- * and concurrent subagents write into each other's.
14
- *
15
- * Reviewers WRITE too, and that is not a side detail: one verdict per checklist is a reviewer's whole
16
- * output. An earlier comment here said "reviewers are unaffected: they only read", and it was false —
17
- * this guard blocked a Codex reviewer's `review-<id>.json`, the coordinator then took this guard's own
18
- * "hand the edit back to the coordinator" option and wrote all five verdicts itself, and the gate
19
- * accepted them (issue #863). So a verdict is never a patch: every reviewer SUBMITS it through
20
- * `pnpm wp-write-review`, a Bash call this guard does not see, and a blocked write under
21
- * `.webpieces/pr-review/` names that bin — and NEVER offers the coordinator hand-back, because a
22
- * coordinator writing a reviewer's verdict is precisely the forgery the gate refuses.
23
- *
24
- * NOT a configurable rule yet, and that is deliberate. A rule registered with the engine must have an
25
- * entry in webpieces.config.json, and the validator that would accept a new key is a RELEASE behind
26
- * the source that defines it — adding both at once rejects the key as unknown and blocks every tool
27
- * call in the repo. So the guard ships here, gated on `aiType === 'codex'`, and becomes a config-keyed
28
- * rule in the follow-up PR that lands after the publish.
29
- */
30
- export declare class CodexSubagentSharedTreeGuard {
31
- /**
32
- * Returns a block when a Codex SUBAGENT's patch targets a file inside `root`, else null.
33
- * Claude Code events return null unconditionally — the harness has real isolation.
34
- */
35
- check(event: AgentHookEvent, root: string): BlockedResult | null;
36
- /**
37
- * A write under `.webpieces/pr-review/` — a verdict, or anything beside one. There is exactly one
38
- * route for it, and it is not a patch. No "hand it to the coordinator" option: the coordinator may
39
- * never write a reviewer's verdict, and `wp-finish-upsert-pr` rejects one that did not come through
40
- * the bin.
41
- */
42
- private verdictWriteError;
43
- private isReviewState;
44
- private isInside;
45
- }
@@ -1,88 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CodexSubagentSharedTreeGuard = exports.CODEX_SUBAGENT_RULE = void 0;
4
- const tslib_1 = require("tslib");
5
- const path = tslib_1.__importStar(require("path"));
6
- const rules_config_1 = require("@webpieces/rules-config");
7
- const tooling_common_1 = require("@webpieces/tooling-common");
8
- const repo_workflow_core_1 = require("@webpieces/repo-workflow-core");
9
- const types_1 = require("../core/types");
10
- exports.CODEX_SUBAGENT_RULE = 'codex-subagent-no-write-in-shared-tree';
11
- /**
12
- * A Codex SUBAGENT may not write into the tree it shares with its coordinator.
13
- *
14
- * This exists because of a MEASURED structural gap, not a style preference. Claude Code can hand a
15
- * subagent its own git worktree (`isolation: "worktree"`), so two agents editing at once are editing
16
- * two different checkouts. Codex cannot: `spawn_agent`'s schema is
17
- * `{fork_turns?, message, model?, reasoning_effort?, task_name}` — there is no cwd, workdir or
18
- * worktree parameter — and cwd resets to the repo root before every command, so a subagent cannot even
19
- * put itself somewhere else. Every Codex subagent therefore writes into the coordinator's checkout,
20
- * and concurrent subagents write into each other's.
21
- *
22
- * Reviewers WRITE too, and that is not a side detail: one verdict per checklist is a reviewer's whole
23
- * output. An earlier comment here said "reviewers are unaffected: they only read", and it was false —
24
- * this guard blocked a Codex reviewer's `review-<id>.json`, the coordinator then took this guard's own
25
- * "hand the edit back to the coordinator" option and wrote all five verdicts itself, and the gate
26
- * accepted them (issue #863). So a verdict is never a patch: every reviewer SUBMITS it through
27
- * `pnpm wp-write-review`, a Bash call this guard does not see, and a blocked write under
28
- * `.webpieces/pr-review/` names that bin — and NEVER offers the coordinator hand-back, because a
29
- * coordinator writing a reviewer's verdict is precisely the forgery the gate refuses.
30
- *
31
- * NOT a configurable rule yet, and that is deliberate. A rule registered with the engine must have an
32
- * entry in webpieces.config.json, and the validator that would accept a new key is a RELEASE behind
33
- * the source that defines it — adding both at once rejects the key as unknown and blocks every tool
34
- * call in the repo. So the guard ships here, gated on `aiType === 'codex'`, and becomes a config-keyed
35
- * rule in the follow-up PR that lands after the publish.
36
- */
37
- class CodexSubagentSharedTreeGuard {
38
- /**
39
- * Returns a block when a Codex SUBAGENT's patch targets a file inside `root`, else null.
40
- * Claude Code events return null unconditionally — the harness has real isolation.
41
- */
42
- check(event, root) {
43
- if (event.aiType !== 'codex')
44
- return null;
45
- if (event.agentId === '')
46
- return null;
47
- const inside = event.files.filter((f) => this.isInside(f.input.filePath, root));
48
- if (inside.length === 0)
49
- return null;
50
- const targets = inside.map((f) => path.relative(root, f.input.filePath)).join(', ');
51
- if (inside.some((f) => this.isReviewState(f.input.filePath, root))) {
52
- return new types_1.BlockedResult((0, rules_config_1.renderRuleFailForAi)(this.verdictWriteError(targets)));
53
- }
54
- const worktree = path.join(path.dirname(root), 'wt-<task-name>');
55
- const error = new rules_config_1.RuleFailError(exports.CODEX_SUBAGENT_RULE, `A Codex subagent is writing into the tree it shares with its coordinator: ${targets}\n\n` +
56
- `Codex cannot spawn a subagent into its own checkout — spawn_agent takes no cwd or worktree, ` +
57
- `and cwd resets to the repo root before every command — so this edit lands in the same files ` +
58
- `the coordinator and every sibling subagent are editing.`, undefined, undefined, [
59
- new rules_config_1.Option(`Give this agent its own checkout and address every file by ABSOLUTE path inside it: git worktree add ${worktree} -b <branch>`, true),
60
- new rules_config_1.Option('Hand the edit back to the coordinator and have this agent report what to change instead of changing it'),
61
- ]);
62
- return new types_1.BlockedResult((0, rules_config_1.renderRuleFailForAi)(error));
63
- }
64
- /**
65
- * A write under `.webpieces/pr-review/` — a verdict, or anything beside one. There is exactly one
66
- * route for it, and it is not a patch. No "hand it to the coordinator" option: the coordinator may
67
- * never write a reviewer's verdict, and `wp-finish-upsert-pr` rejects one that did not come through
68
- * the bin.
69
- */
70
- verdictWriteError(targets) {
71
- return new rules_config_1.RuleFailError(exports.CODEX_SUBAGENT_RULE, `A Codex subagent is writing review state directly: ${targets}\n\n` +
72
- `A reviewer verdict is never written as a file. Submit it through ${repo_workflow_core_1.WRITE_REVIEW_BIN}, which ` +
73
- `validates it and records who wrote it — a review-round<N>-<id>.json written any other way is rejected ` +
74
- `by pnpm wp-finish-upsert-pr.`, undefined, undefined, [
75
- new rules_config_1.Option(`Submit the verdict JSON on stdin: pnpm ${repo_workflow_core_1.WRITE_REVIEW_BIN} --checklist <id> <<'EOF' … EOF (or --file <a path OUTSIDE this tree>)`, true),
76
- ]);
77
- }
78
- isReviewState(filePath, root) {
79
- const reviewDir = path.join(root, tooling_common_1.WEBPIECES_TMP_DIR, tooling_common_1.PR_REVIEW_DIR) + path.sep;
80
- return path.resolve(filePath).startsWith(reviewDir);
81
- }
82
- isInside(filePath, root) {
83
- const rootWithSep = root.endsWith(path.sep) ? root : root + path.sep;
84
- return path.resolve(filePath).startsWith(rootWithSep);
85
- }
86
- }
87
- exports.CodexSubagentSharedTreeGuard = CodexSubagentSharedTreeGuard;
88
- //# sourceMappingURL=codex-subagent-guard.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"codex-subagent-guard.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/adapters/codex-subagent-guard.ts"],"names":[],"mappings":";;;;AAAA,mDAA6B;AAE7B,0DAAqF;AACrF,8DAA6E;AAC7E,sEAAiE;AAGjE,yCAA8C;AAEjC,QAAA,mBAAmB,GAAG,wCAAwC,CAAC;AAE5E;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAa,4BAA4B;IACrC;;;OAGG;IACH,KAAK,CAAC,KAAqB,EAAE,IAAY;QACrC,IAAI,KAAK,CAAC,MAAM,KAAK,OAAO;YAAE,OAAO,IAAI,CAAC;QAC1C,IAAI,KAAK,CAAC,OAAO,KAAK,EAAE;YAAE,OAAO,IAAI,CAAC;QACtC,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAgB,EAAW,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC;QACxG,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC;QACrC,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAgB,EAAU,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,QAA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AI,CAAC,GAAG,CAAC;QAC/E,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;IACxD,CAAC;IAEO,QAAQ,CAAC,QAAgB,EAAE,IAAY;QAC3C,MAAM,WAAW,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC;QACrE,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;IAC1D,CAAC;CACJ;AA7DD,oEA6DC","sourcesContent":["import * as path from 'path';\n\nimport { Option, RuleFailError, renderRuleFailForAi } from '@webpieces/rules-config';\nimport { PR_REVIEW_DIR, WEBPIECES_TMP_DIR } from '@webpieces/tooling-common';\nimport { WRITE_REVIEW_BIN } from '@webpieces/repo-workflow-core';\n\nimport { AgentHookEvent, FileOperation } from '@webpieces/hook-runtime';\nimport { BlockedResult } from '../core/types';\n\nexport const CODEX_SUBAGENT_RULE = 'codex-subagent-no-write-in-shared-tree';\n\n/**\n * A Codex SUBAGENT may not write into the tree it shares with its coordinator.\n *\n * This exists because of a MEASURED structural gap, not a style preference. Claude Code can hand a\n * subagent its own git worktree (`isolation: \"worktree\"`), so two agents editing at once are editing\n * two different checkouts. Codex cannot: `spawn_agent`'s schema is\n * `{fork_turns?, message, model?, reasoning_effort?, task_name}` — there is no cwd, workdir or\n * worktree parameter — and cwd resets to the repo root before every command, so a subagent cannot even\n * put itself somewhere else. Every Codex subagent therefore writes into the coordinator's checkout,\n * and concurrent subagents write into each other's.\n *\n * Reviewers WRITE too, and that is not a side detail: one verdict per checklist is a reviewer's whole\n * output. An earlier comment here said \"reviewers are unaffected: they only read\", and it was false —\n * this guard blocked a Codex reviewer's `review-<id>.json`, the coordinator then took this guard's own\n * \"hand the edit back to the coordinator\" option and wrote all five verdicts itself, and the gate\n * accepted them (issue #863). So a verdict is never a patch: every reviewer SUBMITS it through\n * `pnpm wp-write-review`, a Bash call this guard does not see, and a blocked write under\n * `.webpieces/pr-review/` names that bin — and NEVER offers the coordinator hand-back, because a\n * coordinator writing a reviewer's verdict is precisely the forgery the gate refuses.\n *\n * NOT a configurable rule yet, and that is deliberate. A rule registered with the engine must have an\n * entry in webpieces.config.json, and the validator that would accept a new key is a RELEASE behind\n * the source that defines it — adding both at once rejects the key as unknown and blocks every tool\n * call in the repo. So the guard ships here, gated on `aiType === 'codex'`, and becomes a config-keyed\n * rule in the follow-up PR that lands after the publish.\n */\nexport class CodexSubagentSharedTreeGuard {\n /**\n * Returns a block when a Codex SUBAGENT's patch targets a file inside `root`, else null.\n * Claude Code events return null unconditionally — the harness has real isolation.\n */\n check(event: AgentHookEvent, root: string): BlockedResult | null {\n if (event.aiType !== 'codex') return null;\n if (event.agentId === '') return null;\n const inside = event.files.filter((f: FileOperation): boolean => this.isInside(f.input.filePath, root));\n if (inside.length === 0) return null;\n const targets = inside.map((f: FileOperation): string => path.relative(root, f.input.filePath)).join(', ');\n if (inside.some((f: FileOperation): boolean => this.isReviewState(f.input.filePath, root))) {\n return new BlockedResult(renderRuleFailForAi(this.verdictWriteError(targets)));\n }\n const worktree = path.join(path.dirname(root), 'wt-<task-name>');\n const error = new RuleFailError(\n CODEX_SUBAGENT_RULE,\n `A Codex subagent is writing into the tree it shares with its coordinator: ${targets}\\n\\n` +\n `Codex cannot spawn a subagent into its own checkout — spawn_agent takes no cwd or worktree, ` +\n `and cwd resets to the repo root before every command — so this edit lands in the same files ` +\n `the coordinator and every sibling subagent are editing.`,\n undefined,\n undefined,\n [\n new Option(`Give this agent its own checkout and address every file by ABSOLUTE path inside it: git worktree add ${worktree} -b <branch>`, true),\n new Option('Hand the edit back to the coordinator and have this agent report what to change instead of changing it'),\n ],\n );\n return new BlockedResult(renderRuleFailForAi(error));\n }\n\n /**\n * A write under `.webpieces/pr-review/` — a verdict, or anything beside one. There is exactly one\n * route for it, and it is not a patch. No \"hand it to the coordinator\" option: the coordinator may\n * never write a reviewer's verdict, and `wp-finish-upsert-pr` rejects one that did not come through\n * the bin.\n */\n private verdictWriteError(targets: string): RuleFailError {\n return new RuleFailError(\n CODEX_SUBAGENT_RULE,\n `A Codex subagent is writing review state directly: ${targets}\\n\\n` +\n `A reviewer verdict is never written as a file. Submit it through ${WRITE_REVIEW_BIN}, which ` +\n `validates it and records who wrote it — a review-round<N>-<id>.json written any other way is rejected ` +\n `by pnpm wp-finish-upsert-pr.`,\n undefined,\n undefined,\n [\n new Option(`Submit the verdict JSON on stdin: pnpm ${WRITE_REVIEW_BIN} --checklist <id> <<'EOF' … EOF (or --file <a path OUTSIDE this tree>)`, true),\n ],\n );\n }\n\n private isReviewState(filePath: string, root: string): boolean {\n const reviewDir = path.join(root, WEBPIECES_TMP_DIR, PR_REVIEW_DIR) + path.sep;\n return path.resolve(filePath).startsWith(reviewDir);\n }\n\n private isInside(filePath: string, root: string): boolean {\n const rootWithSep = root.endsWith(path.sep) ? root : root + path.sep;\n return path.resolve(filePath).startsWith(rootWithSep);\n }\n}\n"]}
@@ -1,70 +0,0 @@
1
- import { AiType } from '@webpieces/hook-runtime';
2
- /**
3
- * THE discriminator, and the only one. Codex's PreToolUse envelope carries a REQUIRED `turn_id`;
4
- * Claude Code's has no such key. Everything else in the two envelopes is the same key names
5
- * (`hook_event_name`, `tool_name`, `tool_input`, `cwd`, `session_id`, `transcript_path`), which is
6
- * exactly why one positive key is the whole test rather than a shape heuristic.
7
- *
8
- * Exported as a TWIN — an sh fragment and a JS predicate — because L0 has two halves that must
9
- * answer the identical question: the rendered POSIX-sh shim (which has no JSON parser and scrapes
10
- * text) and this binary (which has the parsed object). That is the same pattern
11
- * ../bin/l0-allowlist.ts already uses for `L0_ALLOW_ERE_SH` / `L0_ALLOW_JS`, and detect-ai.spec.ts
12
- * asserts the two agree over a corpus the same way.
13
- *
14
- * ─── THE SH HALF IS AN APPROXIMATION, AND SINCE L0 BRANCHES ON IT, HERE IS EXACTLY HOW FAR OFF ──────
15
- *
16
- * The JS half asks the precise question (`turn_id` is a key of the TOP-LEVEL envelope). The sh half has
17
- * no JSON parser, so it asks a structural approximation of it: after deleting all whitespace, does the
18
- * payload contain `{` or `,` immediately followed by `"turn_id":`? That is strictly narrower than the
19
- * bare substring test it replaced, and the tightening is not cosmetic — `bin/l0-allowlist.ts` now gates
20
- * an allowlist entry on this answer, so a wrong answer is a grant.
21
- *
22
- * WHAT IT CAN AND CANNOT DISTINGUISH:
23
- *
24
- * - A Claude payload MENTIONING the key in a command — `grep '"turn_id":' x.json` — is answered
25
- * `claude-code`, and not by luck: JSON escapes every `"` inside a string value, so the bytes on the
26
- * wire are `\"turn_id\":`, which contains no `"turn_id":` at all. There is no spelling of a shell
27
- * command that puts the RAW token into the payload.
28
- * - A NESTED `turn_id` key — an MCP tool_input that happens to carry one — IS misread as `codex`.
29
- * This is the residual gap and sh cannot close it. Do not write a JSON parser in sh to try.
30
- *
31
- * WHY THE RESIDUAL GAP IS NOT A PRIVILEGE ESCALATION, stated as the property to preserve rather than
32
- * as a reassurance: the ONLY thing the harness answer gates at L0 is `L0_CODEX_ALLOW_ERE` (built from
33
- * `CODEX_READ_BODY_ERE` in ../bin/l0-codex-read.ts), which
34
- * admits nothing but a single, unredirected, unchained READ (`cat`/`head`/`tail`/`less`/`more`/`bat`,
35
- * or `sed -n '<range>p'`). Allowlist entry 1 — "any Read", with no path restriction — already grants
36
- * Claude Code the identical capability under every L0 fault. So a misclassification hands a Claude
37
- * session another SPELLING of a read it could already do, and never a capability it lacked. Anything
38
- * added to the aiType-gated set later must be checked against that property, because it is what makes
39
- * the approximation tolerable. `codex-l0-read.spec.ts` pins both halves of this.
40
- *
41
- * WHENEVER THE JS HALF IS RUNNING IT IS AUTHORITATIVE: the binary calls `detectAiType()` on the parsed
42
- * envelope (see `enforceCommittedShim`), so the approximation decides only faults D/X/U/K, where the
43
- * binary never runs at all.
44
- *
45
- * WIRED INTO THE RENDERED SHIM (`PARSE_PAYLOAD_SH` in ../bin/shim.ts), which is what makes the L0 audit
46
- * line's `ai=` field possible. Note the release ordering that governs the ARTIFACT rather than this
47
- * constant: `committedShimStale()` compares the committed `.claude/webpieces/ai-hook.sh` against
48
- * `renderShim()` of the INSTALLED release, so the committed shim is NOT regenerated in the same PR that
49
- * changes the renderer — it is regenerated after that release publishes, or by `wp-upgrade-shim`.
50
- */
51
- export declare const AI_TYPE_TOKEN_SH = "\"turn_id\":";
52
- /**
53
- * Sets `AI` to the literal `AiType` value — `codex` or `claude-code` — from `$PAYLOAD`. The values
54
- * are the SAME strings the TypeScript union carries, so the twin test can compare them byte for byte
55
- * instead of translating between two vocabularies (translation is where twins drift).
56
- *
57
- * Two steps, and both are load-bearing:
58
- * 1. `tr -d` deletes every whitespace byte into `WP_AI_ENV`, so the structural test below does not
59
- * have to spell "optional whitespace" — which a POSIX `case` glob cannot express — and a
60
- * pretty-printed envelope is read exactly like a compact one. The stripped copy is used for THIS
61
- * test only; `$PAYLOAD` itself is untouched and stays the input every `sed` scrape reads.
62
- * 2. the glob requires `{` or `,` IMMEDIATELY before the quoted key, i.e. the structural context a
63
- * real JSON key has and a mention inside a value does not.
64
- */
65
- export declare const AI_TYPE_SH = "WP_AI_ENV=\"$(printf '%s' \"$PAYLOAD\" | tr -d ' \\t\\n\\r')\"\ncase \"$WP_AI_ENV\" in *[{,]'\"turn_id\":'*) AI=codex ;; *) AI=claude-code ;; esac";
66
- /**
67
- * JS twin of AI_TYPE_SH. Asks the precise question the sh half approximates: is `turn_id` a key of
68
- * the top-level envelope?
69
- */
70
- export declare function detectAiType(payload: unknown): AiType;
@@ -1,82 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AI_TYPE_SH = exports.AI_TYPE_TOKEN_SH = void 0;
4
- exports.detectAiType = detectAiType;
5
- /**
6
- * THE discriminator, and the only one. Codex's PreToolUse envelope carries a REQUIRED `turn_id`;
7
- * Claude Code's has no such key. Everything else in the two envelopes is the same key names
8
- * (`hook_event_name`, `tool_name`, `tool_input`, `cwd`, `session_id`, `transcript_path`), which is
9
- * exactly why one positive key is the whole test rather than a shape heuristic.
10
- *
11
- * Exported as a TWIN — an sh fragment and a JS predicate — because L0 has two halves that must
12
- * answer the identical question: the rendered POSIX-sh shim (which has no JSON parser and scrapes
13
- * text) and this binary (which has the parsed object). That is the same pattern
14
- * ../bin/l0-allowlist.ts already uses for `L0_ALLOW_ERE_SH` / `L0_ALLOW_JS`, and detect-ai.spec.ts
15
- * asserts the two agree over a corpus the same way.
16
- *
17
- * ─── THE SH HALF IS AN APPROXIMATION, AND SINCE L0 BRANCHES ON IT, HERE IS EXACTLY HOW FAR OFF ──────
18
- *
19
- * The JS half asks the precise question (`turn_id` is a key of the TOP-LEVEL envelope). The sh half has
20
- * no JSON parser, so it asks a structural approximation of it: after deleting all whitespace, does the
21
- * payload contain `{` or `,` immediately followed by `"turn_id":`? That is strictly narrower than the
22
- * bare substring test it replaced, and the tightening is not cosmetic — `bin/l0-allowlist.ts` now gates
23
- * an allowlist entry on this answer, so a wrong answer is a grant.
24
- *
25
- * WHAT IT CAN AND CANNOT DISTINGUISH:
26
- *
27
- * - A Claude payload MENTIONING the key in a command — `grep '"turn_id":' x.json` — is answered
28
- * `claude-code`, and not by luck: JSON escapes every `"` inside a string value, so the bytes on the
29
- * wire are `\"turn_id\":`, which contains no `"turn_id":` at all. There is no spelling of a shell
30
- * command that puts the RAW token into the payload.
31
- * - A NESTED `turn_id` key — an MCP tool_input that happens to carry one — IS misread as `codex`.
32
- * This is the residual gap and sh cannot close it. Do not write a JSON parser in sh to try.
33
- *
34
- * WHY THE RESIDUAL GAP IS NOT A PRIVILEGE ESCALATION, stated as the property to preserve rather than
35
- * as a reassurance: the ONLY thing the harness answer gates at L0 is `L0_CODEX_ALLOW_ERE` (built from
36
- * `CODEX_READ_BODY_ERE` in ../bin/l0-codex-read.ts), which
37
- * admits nothing but a single, unredirected, unchained READ (`cat`/`head`/`tail`/`less`/`more`/`bat`,
38
- * or `sed -n '<range>p'`). Allowlist entry 1 — "any Read", with no path restriction — already grants
39
- * Claude Code the identical capability under every L0 fault. So a misclassification hands a Claude
40
- * session another SPELLING of a read it could already do, and never a capability it lacked. Anything
41
- * added to the aiType-gated set later must be checked against that property, because it is what makes
42
- * the approximation tolerable. `codex-l0-read.spec.ts` pins both halves of this.
43
- *
44
- * WHENEVER THE JS HALF IS RUNNING IT IS AUTHORITATIVE: the binary calls `detectAiType()` on the parsed
45
- * envelope (see `enforceCommittedShim`), so the approximation decides only faults D/X/U/K, where the
46
- * binary never runs at all.
47
- *
48
- * WIRED INTO THE RENDERED SHIM (`PARSE_PAYLOAD_SH` in ../bin/shim.ts), which is what makes the L0 audit
49
- * line's `ai=` field possible. Note the release ordering that governs the ARTIFACT rather than this
50
- * constant: `committedShimStale()` compares the committed `.claude/webpieces/ai-hook.sh` against
51
- * `renderShim()` of the INSTALLED release, so the committed shim is NOT regenerated in the same PR that
52
- * changes the renderer — it is regenerated after that release publishes, or by `wp-upgrade-shim`.
53
- */
54
- exports.AI_TYPE_TOKEN_SH = '"turn_id":';
55
- /**
56
- * Sets `AI` to the literal `AiType` value — `codex` or `claude-code` — from `$PAYLOAD`. The values
57
- * are the SAME strings the TypeScript union carries, so the twin test can compare them byte for byte
58
- * instead of translating between two vocabularies (translation is where twins drift).
59
- *
60
- * Two steps, and both are load-bearing:
61
- * 1. `tr -d` deletes every whitespace byte into `WP_AI_ENV`, so the structural test below does not
62
- * have to spell "optional whitespace" — which a POSIX `case` glob cannot express — and a
63
- * pretty-printed envelope is read exactly like a compact one. The stripped copy is used for THIS
64
- * test only; `$PAYLOAD` itself is untouched and stays the input every `sed` scrape reads.
65
- * 2. the glob requires `{` or `,` IMMEDIATELY before the quoted key, i.e. the structural context a
66
- * real JSON key has and a mention inside a value does not.
67
- */
68
- exports.AI_TYPE_SH = `WP_AI_ENV="$(printf '%s' "$PAYLOAD" | tr -d ' \\t\\n\\r')"
69
- case "$WP_AI_ENV" in *[{,]'${exports.AI_TYPE_TOKEN_SH}'*) AI=codex ;; *) AI=claude-code ;; esac`;
70
- /**
71
- * JS twin of AI_TYPE_SH. Asks the precise question the sh half approximates: is `turn_id` a key of
72
- * the top-level envelope?
73
- */
74
- // webpieces-disable no-any-unknown -- the argument IS unparsed JSON from another process's stdout; naming a type here would assert a shape we have not yet established, which is the question this function exists to answer
75
- // webpieces-disable no-function-outside-class -- twin of an sh fragment in the dependency-free adapter layer; it must stay callable on a tree too broken to build a DI container, exactly like isAllowed()
76
- function detectAiType(payload) {
77
- if (payload === null || typeof payload !== 'object')
78
- return 'claude-code';
79
- // webpieces-disable no-any-unknown -- narrowing the same unparsed JSON; the index signature is the widest true statement about it
80
- return 'turn_id' in payload ? 'codex' : 'claude-code';
81
- }
82
- //# sourceMappingURL=detect-ai.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"detect-ai.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/adapters/detect-ai.ts"],"names":[],"mappings":";;;AA2EA,oCAIC;AA7ED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACU,QAAA,gBAAgB,GAAG,YAAY,CAAC;AAE7C;;;;;;;;;;;;GAYG;AACU,QAAA,UAAU,GAAG;6BACG,wBAAgB,2CAA2C,CAAC;AAEzF;;;GAGG;AACH,6NAA6N;AAC7N,2MAA2M;AAC3M,SAAgB,YAAY,CAAC,OAAgB;IACzC,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,OAAO,aAAa,CAAC;IAC1E,kIAAkI;IAClI,OAAO,SAAS,IAAK,OAAmC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,aAAa,CAAC;AACvF,CAAC","sourcesContent":["import { AiType } from '@webpieces/hook-runtime';\n\n/**\n * THE discriminator, and the only one. Codex's PreToolUse envelope carries a REQUIRED `turn_id`;\n * Claude Code's has no such key. Everything else in the two envelopes is the same key names\n * (`hook_event_name`, `tool_name`, `tool_input`, `cwd`, `session_id`, `transcript_path`), which is\n * exactly why one positive key is the whole test rather than a shape heuristic.\n *\n * Exported as a TWIN — an sh fragment and a JS predicate — because L0 has two halves that must\n * answer the identical question: the rendered POSIX-sh shim (which has no JSON parser and scrapes\n * text) and this binary (which has the parsed object). That is the same pattern\n * ../bin/l0-allowlist.ts already uses for `L0_ALLOW_ERE_SH` / `L0_ALLOW_JS`, and detect-ai.spec.ts\n * asserts the two agree over a corpus the same way.\n *\n * ─── THE SH HALF IS AN APPROXIMATION, AND SINCE L0 BRANCHES ON IT, HERE IS EXACTLY HOW FAR OFF ──────\n *\n * The JS half asks the precise question (`turn_id` is a key of the TOP-LEVEL envelope). The sh half has\n * no JSON parser, so it asks a structural approximation of it: after deleting all whitespace, does the\n * payload contain `{` or `,` immediately followed by `\"turn_id\":`? That is strictly narrower than the\n * bare substring test it replaced, and the tightening is not cosmetic — `bin/l0-allowlist.ts` now gates\n * an allowlist entry on this answer, so a wrong answer is a grant.\n *\n * WHAT IT CAN AND CANNOT DISTINGUISH:\n *\n * - A Claude payload MENTIONING the key in a command — `grep '\"turn_id\":' x.json` — is answered\n * `claude-code`, and not by luck: JSON escapes every `\"` inside a string value, so the bytes on the\n * wire are `\\\"turn_id\\\":`, which contains no `\"turn_id\":` at all. There is no spelling of a shell\n * command that puts the RAW token into the payload.\n * - A NESTED `turn_id` key — an MCP tool_input that happens to carry one — IS misread as `codex`.\n * This is the residual gap and sh cannot close it. Do not write a JSON parser in sh to try.\n *\n * WHY THE RESIDUAL GAP IS NOT A PRIVILEGE ESCALATION, stated as the property to preserve rather than\n * as a reassurance: the ONLY thing the harness answer gates at L0 is `L0_CODEX_ALLOW_ERE` (built from\n * `CODEX_READ_BODY_ERE` in ../bin/l0-codex-read.ts), which\n * admits nothing but a single, unredirected, unchained READ (`cat`/`head`/`tail`/`less`/`more`/`bat`,\n * or `sed -n '<range>p'`). Allowlist entry 1 — \"any Read\", with no path restriction — already grants\n * Claude Code the identical capability under every L0 fault. So a misclassification hands a Claude\n * session another SPELLING of a read it could already do, and never a capability it lacked. Anything\n * added to the aiType-gated set later must be checked against that property, because it is what makes\n * the approximation tolerable. `codex-l0-read.spec.ts` pins both halves of this.\n *\n * WHENEVER THE JS HALF IS RUNNING IT IS AUTHORITATIVE: the binary calls `detectAiType()` on the parsed\n * envelope (see `enforceCommittedShim`), so the approximation decides only faults D/X/U/K, where the\n * binary never runs at all.\n *\n * WIRED INTO THE RENDERED SHIM (`PARSE_PAYLOAD_SH` in ../bin/shim.ts), which is what makes the L0 audit\n * line's `ai=` field possible. Note the release ordering that governs the ARTIFACT rather than this\n * constant: `committedShimStale()` compares the committed `.claude/webpieces/ai-hook.sh` against\n * `renderShim()` of the INSTALLED release, so the committed shim is NOT regenerated in the same PR that\n * changes the renderer — it is regenerated after that release publishes, or by `wp-upgrade-shim`.\n */\nexport const AI_TYPE_TOKEN_SH = '\"turn_id\":';\n\n/**\n * Sets `AI` to the literal `AiType` value — `codex` or `claude-code` — from `$PAYLOAD`. The values\n * are the SAME strings the TypeScript union carries, so the twin test can compare them byte for byte\n * instead of translating between two vocabularies (translation is where twins drift).\n *\n * Two steps, and both are load-bearing:\n * 1. `tr -d` deletes every whitespace byte into `WP_AI_ENV`, so the structural test below does not\n * have to spell \"optional whitespace\" — which a POSIX `case` glob cannot express — and a\n * pretty-printed envelope is read exactly like a compact one. The stripped copy is used for THIS\n * test only; `$PAYLOAD` itself is untouched and stays the input every `sed` scrape reads.\n * 2. the glob requires `{` or `,` IMMEDIATELY before the quoted key, i.e. the structural context a\n * real JSON key has and a mention inside a value does not.\n */\nexport const AI_TYPE_SH = `WP_AI_ENV=\"$(printf '%s' \"$PAYLOAD\" | tr -d ' \\\\t\\\\n\\\\r')\"\ncase \"$WP_AI_ENV\" in *[{,]'${AI_TYPE_TOKEN_SH}'*) AI=codex ;; *) AI=claude-code ;; esac`;\n\n/**\n * JS twin of AI_TYPE_SH. Asks the precise question the sh half approximates: is `turn_id` a key of\n * the top-level envelope?\n */\n// webpieces-disable no-any-unknown -- the argument IS unparsed JSON from another process's stdout; naming a type here would assert a shape we have not yet established, which is the question this function exists to answer\n// webpieces-disable no-function-outside-class -- twin of an sh fragment in the dependency-free adapter layer; it must stay callable on a tree too broken to build a DI container, exactly like isAllowed()\nexport function detectAiType(payload: unknown): AiType {\n if (payload === null || typeof payload !== 'object') return 'claude-code';\n // webpieces-disable no-any-unknown -- narrowing the same unparsed JSON; the index signature is the widest true statement about it\n return 'turn_id' in (payload as Record<string, unknown>) ? 'codex' : 'claude-code';\n}\n"]}
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env node
2
- import 'reflect-metadata';
3
- export declare function main(): Promise<void>;
@@ -1,30 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.main = main;
5
- // Claude Code / Codex PreToolUse adapter for the GIT/PR/BRANCH GUARDS hook (matcher Bash|Write|Edit|
6
- // MultiEdit|Read). Code-style validation is the separate rules hook.
7
- //
8
- // COMPOSITION ROOT, and deliberately nothing else: build the container, get the app, run it. Every
9
- // decision this binary makes lives behind HookApp; the only thing that distinguishes it from
10
- // rules-hook.ts is the one HookArgs it constructs.
11
- require("reflect-metadata");
12
- const inversify_1 = require("inversify");
13
- const hook_runtime_1 = require("@webpieces/hook-runtime");
14
- const hook_pipeline_evaluator_1 = require("./hook-pipeline-evaluator");
15
- // webpieces-disable no-function-outside-class -- this IS the bin's process entry point, named in package.json `exports` as ./claude-code-guards / ./claude-code-rules; a class here would be a namespace around one call and could not be the module's callable entry.
16
- async function main() {
17
- const container = new inversify_1.Container({ autobind: true });
18
- container.bind(hook_runtime_1.HookEvaluator).to(hook_pipeline_evaluator_1.HookPipelineEvaluator);
19
- const app = container.get(hook_runtime_1.HookApp);
20
- await app.run(new hook_runtime_1.HookArgs('guards'));
21
- }
22
- // `.catch` and not a bare `void main()`: a container that cannot be built throws BEFORE any HookApp
23
- // exists, and an unhandled rejection exits non-zero — which PreToolUse reads as a non-blocking error
24
- // and lets the tool call through. See HookBootFailure. `main` is async so a synchronous throw inside it
25
- // arrives here as a rejection too.
26
- if (require.main === module) {
27
- // webpieces-disable no-any-unknown -- a rejection value is `unknown` by construction; HookBootFailure narrows it through toError(), which is the one place that job belongs
28
- void main().catch((err) => { new hook_runtime_1.HookBootFailure().report(err); });
29
- }
30
- //# sourceMappingURL=guards-hook.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"guards-hook.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/adapters/guards-hook.ts"],"names":[],"mappings":";;;AAcA,oBAKC;AAlBD,qGAAqG;AACrG,qEAAqE;AACrE,EAAE;AACF,mGAAmG;AACnG,6FAA6F;AAC7F,mDAAmD;AACnD,4BAA0B;AAC1B,yCAAsC;AACtC,0DAA4F;AAE5F,uEAAkE;AAElE,uQAAuQ;AAChQ,KAAK,UAAU,IAAI;IACtB,MAAM,SAAS,GAAG,IAAI,qBAAS,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;IACpD,SAAS,CAAC,IAAI,CAAC,4BAAa,CAAC,CAAC,EAAE,CAAC,+CAAqB,CAAC,CAAC;IACxD,MAAM,GAAG,GAAG,SAAS,CAAC,GAAG,CAAC,sBAAO,CAAC,CAAC;IACnC,MAAM,GAAG,CAAC,GAAG,CAAC,IAAI,uBAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;AAC1C,CAAC;AAED,oGAAoG;AACpG,qGAAqG;AACrG,wGAAwG;AACxG,mCAAmC;AACnC,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;IAC1B,4KAA4K;IAC5K,KAAK,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAY,EAAQ,EAAE,GAAG,IAAI,8BAAe,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACtF,CAAC","sourcesContent":["#!/usr/bin/env node\n// Claude Code / Codex PreToolUse adapter for the GIT/PR/BRANCH GUARDS hook (matcher Bash|Write|Edit|\n// MultiEdit|Read). Code-style validation is the separate rules hook.\n//\n// COMPOSITION ROOT, and deliberately nothing else: build the container, get the app, run it. Every\n// decision this binary makes lives behind HookApp; the only thing that distinguishes it from\n// rules-hook.ts is the one HookArgs it constructs.\nimport 'reflect-metadata';\nimport { Container } from 'inversify';\nimport { HookApp, HookArgs, HookBootFailure, HookEvaluator } from '@webpieces/hook-runtime';\n\nimport { HookPipelineEvaluator } from './hook-pipeline-evaluator';\n\n// webpieces-disable no-function-outside-class -- this IS the bin's process entry point, named in package.json `exports` as ./claude-code-guards / ./claude-code-rules; a class here would be a namespace around one call and could not be the module's callable entry.\nexport async function main(): Promise<void> {\n const container = new Container({ autobind: true });\n container.bind(HookEvaluator).to(HookPipelineEvaluator);\n const app = container.get(HookApp);\n await app.run(new HookArgs('guards'));\n}\n\n// `.catch` and not a bare `void main()`: a container that cannot be built throws BEFORE any HookApp\n// exists, and an unhandled rejection exits non-zero — which PreToolUse reads as a non-blocking error\n// and lets the tool call through. See HookBootFailure. `main` is async so a synchronous throw inside it\n// arrives here as a rejection too.\nif (require.main === module) {\n // webpieces-disable no-any-unknown -- a rejection value is `unknown` by construction; HookBootFailure narrows it through toError(), which is the one place that job belongs\n void main().catch((err: unknown): void => { new HookBootFailure().report(err); });\n}\n"]}
@@ -1,14 +0,0 @@
1
- interface ToolCallEvent {
2
- toolName: string;
3
- arguments: Record<string, unknown>;
4
- }
5
- interface HookContext {
6
- [key: string]: unknown;
7
- }
8
- declare class OpenclawHandlerResult {
9
- readonly status: 'approved' | 'rejected';
10
- readonly reason: string | undefined;
11
- constructor(status: 'approved' | 'rejected', reason?: string);
12
- }
13
- export default function handler(event: ToolCallEvent, _context: HookContext): Promise<OpenclawHandlerResult | undefined>;
14
- export {};