@webpieces/agent-workflow-rules 0.0.0-stage → 0.4.846

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 (299) hide show
  1. package/README.md +23 -2
  2. package/package.json +45 -4
  3. package/src/adapters/agent-response.d.ts +5 -0
  4. package/src/adapters/agent-response.js +86 -0
  5. package/src/adapters/agent-response.js.map +1 -0
  6. package/src/adapters/codex-subagent-guard.d.ts +45 -0
  7. package/src/adapters/codex-subagent-guard.js +88 -0
  8. package/src/adapters/codex-subagent-guard.js.map +1 -0
  9. package/src/adapters/guards-hook.d.ts +3 -0
  10. package/src/adapters/guards-hook.js +30 -0
  11. package/src/adapters/guards-hook.js.map +1 -0
  12. package/src/adapters/hook-app-fixtures.d.ts +68 -0
  13. package/src/adapters/hook-app-fixtures.js +170 -0
  14. package/src/adapters/hook-app-fixtures.js.map +1 -0
  15. package/src/adapters/hook-core.d.ts +22 -0
  16. package/src/adapters/hook-core.js +359 -0
  17. package/src/adapters/hook-core.js.map +1 -0
  18. package/src/adapters/hook-pipeline-evaluator.d.ts +5 -0
  19. package/src/adapters/hook-pipeline-evaluator.js +18 -0
  20. package/src/adapters/hook-pipeline-evaluator.js.map +1 -0
  21. package/src/adapters/review-identity-stamper.d.ts +20 -0
  22. package/src/adapters/review-identity-stamper.js +34 -0
  23. package/src/adapters/review-identity-stamper.js.map +1 -0
  24. package/src/bin/codex-trust.d.ts +105 -0
  25. package/src/bin/codex-trust.js +205 -0
  26. package/src/bin/codex-trust.js.map +1 -0
  27. package/src/bin/dev-hook-install.d.ts +1 -0
  28. package/src/bin/dev-hook-install.js +80 -0
  29. package/src/bin/dev-hook-install.js.map +1 -0
  30. package/src/bin/dev-hook-uninstall.d.ts +1 -0
  31. package/src/bin/dev-hook-uninstall.js +45 -0
  32. package/src/bin/dev-hook-uninstall.js.map +1 -0
  33. package/src/bin/hook-registration.d.ts +429 -0
  34. package/src/bin/hook-registration.js +661 -0
  35. package/src/bin/hook-registration.js.map +1 -0
  36. package/src/bin/install-entry.d.ts +19 -0
  37. package/src/bin/install-entry.js +128 -0
  38. package/src/bin/install-entry.js.map +1 -0
  39. package/src/bin/l0-allowlist.d.ts +46 -0
  40. package/src/bin/l0-allowlist.js +527 -0
  41. package/src/bin/l0-allowlist.js.map +1 -0
  42. package/src/bin/l0-codex-read.d.ts +20 -0
  43. package/src/bin/l0-codex-read.js +108 -0
  44. package/src/bin/l0-codex-read.js.map +1 -0
  45. package/src/bin/l0-decide.d.ts +49 -0
  46. package/src/bin/l0-decide.js +90 -0
  47. package/src/bin/l0-decide.js.map +1 -0
  48. package/src/bin/l0-entry.d.ts +103 -0
  49. package/src/bin/l0-entry.js +98 -0
  50. package/src/bin/l0-entry.js.map +1 -0
  51. package/src/bin/l0-ignored-tools.d.ts +38 -0
  52. package/src/bin/l0-ignored-tools.js +44 -0
  53. package/src/bin/l0-ignored-tools.js.map +1 -0
  54. package/src/bin/managed-env.d.ts +46 -0
  55. package/src/bin/managed-env.js +50 -0
  56. package/src/bin/managed-env.js.map +1 -0
  57. package/src/bin/neighbour-hooks.d.ts +42 -0
  58. package/src/bin/neighbour-hooks.js +177 -0
  59. package/src/bin/neighbour-hooks.js.map +1 -0
  60. package/src/bin/reviewer-agent.d.ts +19 -0
  61. package/src/bin/reviewer-agent.js +135 -0
  62. package/src/bin/reviewer-agent.js.map +1 -0
  63. package/src/bin/settings-shape.d.ts +37 -0
  64. package/src/bin/settings-shape.js +17 -0
  65. package/src/bin/settings-shape.js.map +1 -0
  66. package/src/bin/setup-config.d.ts +20 -0
  67. package/src/bin/setup-config.js +371 -0
  68. package/src/bin/setup-config.js.map +1 -0
  69. package/src/bin/setup.d.ts +78 -0
  70. package/src/bin/setup.js +411 -0
  71. package/src/bin/setup.js.map +1 -0
  72. package/src/bin/shim-audit-log.d.ts +119 -0
  73. package/src/bin/shim-audit-log.js +286 -0
  74. package/src/bin/shim-audit-log.js.map +1 -0
  75. package/src/bin/shim-deny-reason.d.ts +1 -0
  76. package/src/bin/shim-deny-reason.js +244 -0
  77. package/src/bin/shim-deny-reason.js.map +1 -0
  78. package/src/bin/shim-drift-fix.d.ts +1 -0
  79. package/src/bin/shim-drift-fix.js +73 -0
  80. package/src/bin/shim-drift-fix.js.map +1 -0
  81. package/src/bin/shim-testkit.d.ts +107 -0
  82. package/src/bin/shim-testkit.js +197 -0
  83. package/src/bin/shim-testkit.js.map +1 -0
  84. package/src/bin/shim-version-drift.d.ts +1 -0
  85. package/src/bin/shim-version-drift.js +164 -0
  86. package/src/bin/shim-version-drift.js.map +1 -0
  87. package/src/bin/shim.d.ts +16 -0
  88. package/src/bin/shim.js +641 -0
  89. package/src/bin/shim.js.map +1 -0
  90. package/src/bin/upgrade-shim.d.ts +18 -0
  91. package/src/bin/upgrade-shim.js +283 -0
  92. package/src/bin/upgrade-shim.js.map +1 -0
  93. package/src/configs/main-sync-guard-configs.d.ts +38 -0
  94. package/src/configs/main-sync-guard-configs.js +54 -0
  95. package/src/configs/main-sync-guard-configs.js.map +1 -0
  96. package/src/configs/rule-configs.d.ts +47 -0
  97. package/src/configs/rule-configs.js +96 -0
  98. package/src/configs/rule-configs.js.map +1 -0
  99. package/src/core/ai-type-context.d.ts +36 -0
  100. package/src/core/ai-type-context.js +45 -0
  101. package/src/core/ai-type-context.js.map +1 -0
  102. package/src/core/decision-log.d.ts +190 -0
  103. package/src/core/decision-log.js +409 -0
  104. package/src/core/decision-log.js.map +1 -0
  105. package/src/core/excluded-path-escape.d.ts +101 -0
  106. package/src/core/excluded-path-escape.js +236 -0
  107. package/src/core/excluded-path-escape.js.map +1 -0
  108. package/src/core/force-to-root.d.ts +32 -0
  109. package/src/core/force-to-root.js +60 -0
  110. package/src/core/force-to-root.js.map +1 -0
  111. package/src/core/guard-index-doc.d.ts +63 -0
  112. package/src/core/guard-index-doc.js +172 -0
  113. package/src/core/guard-index-doc.js.map +1 -0
  114. package/src/core/instruct-ai-writer.d.ts +1 -0
  115. package/src/core/instruct-ai-writer.js +6 -0
  116. package/src/core/instruct-ai-writer.js.map +1 -0
  117. package/src/core/l0-matrix.d.ts +102 -0
  118. package/src/core/l0-matrix.js +357 -0
  119. package/src/core/l0-matrix.js.map +1 -0
  120. package/src/core/l0-tooling-doc.d.ts +45 -0
  121. package/src/core/l0-tooling-doc.js +258 -0
  122. package/src/core/l0-tooling-doc.js.map +1 -0
  123. package/src/core/l1-doc.d.ts +7 -0
  124. package/src/core/l1-doc.js +340 -0
  125. package/src/core/l1-doc.js.map +1 -0
  126. package/src/core/l1-matrix-doc.d.ts +31 -0
  127. package/src/core/l1-matrix-doc.js +111 -0
  128. package/src/core/l1-matrix-doc.js.map +1 -0
  129. package/src/core/l1-rows.d.ts +167 -0
  130. package/src/core/l1-rows.js +262 -0
  131. package/src/core/l1-rows.js.map +1 -0
  132. package/src/core/l2-doc.d.ts +7 -0
  133. package/src/core/l2-doc.js +385 -0
  134. package/src/core/l2-doc.js.map +1 -0
  135. package/src/core/l2-matrix-doc.d.ts +23 -0
  136. package/src/core/l2-matrix-doc.js +72 -0
  137. package/src/core/l2-matrix-doc.js.map +1 -0
  138. package/src/core/l2-row.d.ts +54 -0
  139. package/src/core/l2-row.js +75 -0
  140. package/src/core/l2-row.js.map +1 -0
  141. package/src/core/l2-rows.d.ts +56 -0
  142. package/src/core/l2-rows.js +272 -0
  143. package/src/core/l2-rows.js.map +1 -0
  144. package/src/core/load-rules.d.ts +9 -0
  145. package/src/core/load-rules.js +65 -0
  146. package/src/core/load-rules.js.map +1 -0
  147. package/src/core/log-stream.d.ts +117 -0
  148. package/src/core/log-stream.js +156 -0
  149. package/src/core/log-stream.js.map +1 -0
  150. package/src/core/log-streams.d.ts +48 -0
  151. package/src/core/log-streams.js +55 -0
  152. package/src/core/log-streams.js.map +1 -0
  153. package/src/core/log-target.d.ts +21 -0
  154. package/src/core/log-target.js +29 -0
  155. package/src/core/log-target.js.map +1 -0
  156. package/src/core/main-sync-log.d.ts +16 -0
  157. package/src/core/main-sync-log.js +108 -0
  158. package/src/core/main-sync-log.js.map +1 -0
  159. package/src/core/main-sync-refresh.d.ts +39 -0
  160. package/src/core/main-sync-refresh.js +96 -0
  161. package/src/core/main-sync-refresh.js.map +1 -0
  162. package/src/core/main-sync-timeout.d.ts +33 -0
  163. package/src/core/main-sync-timeout.js +95 -0
  164. package/src/core/main-sync-timeout.js.map +1 -0
  165. package/src/core/matrix-cures.d.ts +12 -0
  166. package/src/core/matrix-cures.js +56 -0
  167. package/src/core/matrix-cures.js.map +1 -0
  168. package/src/core/missing-directory.d.ts +38 -0
  169. package/src/core/missing-directory.js +66 -0
  170. package/src/core/missing-directory.js.map +1 -0
  171. package/src/core/read-only-inspection.d.ts +34 -0
  172. package/src/core/read-only-inspection.js +88 -0
  173. package/src/core/read-only-inspection.js.map +1 -0
  174. package/src/core/rejection-log.d.ts +9 -0
  175. package/src/core/rejection-log.js +262 -0
  176. package/src/core/rejection-log.js.map +1 -0
  177. package/src/core/rules/branch-creation-guard.d.ts +113 -0
  178. package/src/core/rules/branch-creation-guard.js +425 -0
  179. package/src/core/rules/branch-creation-guard.js.map +1 -0
  180. package/src/core/rules/branch-switch-scan.d.ts +43 -0
  181. package/src/core/rules/branch-switch-scan.js +132 -0
  182. package/src/core/rules/branch-switch-scan.js.map +1 -0
  183. package/src/core/rules/build-output-pipe-guard.d.ts +56 -0
  184. package/src/core/rules/build-output-pipe-guard.js +120 -0
  185. package/src/core/rules/build-output-pipe-guard.js.map +1 -0
  186. package/src/core/rules/build-output-pipe-scan.d.ts +47 -0
  187. package/src/core/rules/build-output-pipe-scan.js +84 -0
  188. package/src/core/rules/build-output-pipe-scan.js.map +1 -0
  189. package/src/core/rules/cap-remedies.d.ts +39 -0
  190. package/src/core/rules/cap-remedies.js +59 -0
  191. package/src/core/rules/cap-remedies.js.map +1 -0
  192. package/src/core/rules/commit-message-substitution-guard.d.ts +72 -0
  193. package/src/core/rules/commit-message-substitution-guard.js +134 -0
  194. package/src/core/rules/commit-message-substitution-guard.js.map +1 -0
  195. package/src/core/rules/commit-message-substitution-scan.d.ts +42 -0
  196. package/src/core/rules/commit-message-substitution-scan.js +145 -0
  197. package/src/core/rules/commit-message-substitution-scan.js.map +1 -0
  198. package/src/core/rules/content-read-scan.d.ts +76 -0
  199. package/src/core/rules/content-read-scan.js +176 -0
  200. package/src/core/rules/content-read-scan.js.map +1 -0
  201. package/src/core/rules/cure-prefix-scan.d.ts +64 -0
  202. package/src/core/rules/cure-prefix-scan.js +133 -0
  203. package/src/core/rules/cure-prefix-scan.js.map +1 -0
  204. package/src/core/rules/feature-branch-guard.d.ts +121 -0
  205. package/src/core/rules/feature-branch-guard.js +327 -0
  206. package/src/core/rules/feature-branch-guard.js.map +1 -0
  207. package/src/core/rules/index.d.ts +1 -0
  208. package/src/core/rules/index.js +5 -0
  209. package/src/core/rules/index.js.map +1 -0
  210. package/src/core/rules/judged-tree.d.ts +66 -0
  211. package/src/core/rules/judged-tree.js +97 -0
  212. package/src/core/rules/judged-tree.js.map +1 -0
  213. package/src/core/rules/main-freshness.d.ts +37 -0
  214. package/src/core/rules/main-freshness.js +61 -0
  215. package/src/core/rules/main-freshness.js.map +1 -0
  216. package/src/core/rules/merge-in-progress-guard.d.ts +17 -0
  217. package/src/core/rules/merge-in-progress-guard.js +124 -0
  218. package/src/core/rules/merge-in-progress-guard.js.map +1 -0
  219. package/src/core/rules/merged-branch-bash-guard.d.ts +62 -0
  220. package/src/core/rules/merged-branch-bash-guard.js +171 -0
  221. package/src/core/rules/merged-branch-bash-guard.js.map +1 -0
  222. package/src/core/rules/merged-branch-message.d.ts +59 -0
  223. package/src/core/rules/merged-branch-message.js +137 -0
  224. package/src/core/rules/merged-branch-message.js.map +1 -0
  225. package/src/core/rules/pr-creation-or-push-guard.d.ts +26 -0
  226. package/src/core/rules/pr-creation-or-push-guard.js +150 -0
  227. package/src/core/rules/pr-creation-or-push-guard.js.map +1 -0
  228. package/src/core/rules/pr-merge-guard.d.ts +36 -0
  229. package/src/core/rules/pr-merge-guard.js +87 -0
  230. package/src/core/rules/pr-merge-guard.js.map +1 -0
  231. package/src/core/rules/read-stale-guard.d.ts +136 -0
  232. package/src/core/rules/read-stale-guard.js +328 -0
  233. package/src/core/rules/read-stale-guard.js.map +1 -0
  234. package/src/core/rules/recovery-allowlist.d.ts +49 -0
  235. package/src/core/rules/recovery-allowlist.js +187 -0
  236. package/src/core/rules/recovery-allowlist.js.map +1 -0
  237. package/src/core/rules/redirect-how-to-merge-main.d.ts +16 -0
  238. package/src/core/rules/redirect-how-to-merge-main.js +159 -0
  239. package/src/core/rules/redirect-how-to-merge-main.js.map +1 -0
  240. package/src/core/rules/stale-main-bash-guard.d.ts +198 -0
  241. package/src/core/rules/stale-main-bash-guard.js +363 -0
  242. package/src/core/rules/stale-main-bash-guard.js.map +1 -0
  243. package/src/core/rules/stale-main-message.d.ts +62 -0
  244. package/src/core/rules/stale-main-message.js +102 -0
  245. package/src/core/rules/stale-main-message.js.map +1 -0
  246. package/src/core/rules/tree-recovery.d.ts +92 -0
  247. package/src/core/rules/tree-recovery.js +165 -0
  248. package/src/core/rules/tree-recovery.js.map +1 -0
  249. package/src/core/rules/wait-spin-guard.d.ts +128 -0
  250. package/src/core/rules/wait-spin-guard.js +211 -0
  251. package/src/core/rules/wait-spin-guard.js.map +1 -0
  252. package/src/core/rules/wait-spin-scan.d.ts +118 -0
  253. package/src/core/rules/wait-spin-scan.js +203 -0
  254. package/src/core/rules/wait-spin-scan.js.map +1 -0
  255. package/src/core/rules/whole-repo-build-guard.d.ts +125 -0
  256. package/src/core/rules/whole-repo-build-guard.js +257 -0
  257. package/src/core/rules/whole-repo-build-guard.js.map +1 -0
  258. package/src/core/rules/whole-repo-build-scan.d.ts +28 -0
  259. package/src/core/rules/whole-repo-build-scan.js +198 -0
  260. package/src/core/rules/whole-repo-build-scan.js.map +1 -0
  261. package/src/core/runner.d.ts +19 -0
  262. package/src/core/runner.js +482 -0
  263. package/src/core/runner.js.map +1 -0
  264. package/src/core/session-call-history.d.ts +44 -0
  265. package/src/core/session-call-history.js +79 -0
  266. package/src/core/session-call-history.js.map +1 -0
  267. package/src/core/sync-main.d.ts +46 -0
  268. package/src/core/sync-main.js +176 -0
  269. package/src/core/sync-main.js.map +1 -0
  270. package/src/core/version-sync.d.ts +219 -0
  271. package/src/core/version-sync.js +558 -0
  272. package/src/core/version-sync.js.map +1 -0
  273. package/src/core/webpieces-versions.d.ts +98 -0
  274. package/src/core/webpieces-versions.js +206 -0
  275. package/src/core/webpieces-versions.js.map +1 -0
  276. package/src/core/workflow-hook-rules.d.ts +5 -0
  277. package/src/core/workflow-hook-rules.js +15 -0
  278. package/src/core/workflow-hook-rules.js.map +1 -0
  279. package/src/index.d.ts +11 -0
  280. package/src/index.js +28 -0
  281. package/src/index.js.map +1 -0
  282. package/src/policy-keys.d.ts +2 -0
  283. package/src/policy-keys.js +6 -0
  284. package/src/policy-keys.js.map +1 -0
  285. package/src/rule-migrations.d.ts +3 -0
  286. package/src/rule-migrations.js +22 -0
  287. package/src/rule-migrations.js.map +1 -0
  288. package/src/rule-pack.d.ts +2 -0
  289. package/src/rule-pack.js +20 -0
  290. package/src/rule-pack.js.map +1 -0
  291. package/src/rule-settings.d.ts +5 -0
  292. package/src/rule-settings.js +31 -0
  293. package/src/rule-settings.js.map +1 -0
  294. package/src/safeguard-catalog.d.ts +3 -0
  295. package/src/safeguard-catalog.js +16 -0
  296. package/src/safeguard-catalog.js.map +1 -0
  297. package/templates/ai-hook.sh +497 -0
  298. package/templates/claude-settings-hook.json +28 -0
  299. package/templates/webpieces-reviewer.md +60 -0
package/README.md CHANGED
@@ -1,3 +1,24 @@
1
- # Temporary Holding Version
1
+ # @webpieces/agent-workflow-rules
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Workflow guard policy and hook installation for AI coding agents, contributed independently to the shared hook runtime.
4
+
5
+ ## In Scope
6
+
7
+ - Branch creation, branch state and PR lifecycle rule registration, plus fixed Bash guards.
8
+ - Guard pipeline, logging, main-sync refresh and version synchronization.
9
+ - Codex shared-tree protection, read parity enforcement and review identity stamping.
10
+ - `wp-ai-guards-hook`, hook installation, shim renderers and upgrade commands.
11
+ - Guard golden fixtures and L0 shell regression tests.
12
+
13
+ ## Out of Scope
14
+
15
+ - Source rule implementations and their registry (ai-hook-rules).
16
+ - Generic protocol and rule evaluation (hook-runtime).
17
+ - Git/worktree primitives and state paths (repo-workflow-core and tooling-common).
18
+ - Generic config loading and validation (rules-config), PR orchestration (pr-gate), and aggregate packaging (nx-webpieces-rules).
19
+
20
+ The public source and guard hooks keep their existing binary names. Import shared rule contracts from `@webpieces/hook-runtime`, pure schema/value contracts from `@webpieces/rules-sdk` and concrete configuration types from their owner package, and errors from `@webpieces/tooling-common`. Workflow APIs previously imported from `ai-hook-rules` now belong to `agent-workflow-rules`. OpenClaw composition is provided by the umbrella package.
21
+
22
+ The committed dispatcher is upgraded from the installed published release; this extraction does not regenerate it from unreleased source.
23
+
24
+ This pack owns its concrete policy schemas, mode enums, optional tuning, and reviewed seeds. Workflow rule/field retirements and keyless safeguard metadata are published by the workflow owner.
package/package.json CHANGED
@@ -1,6 +1,47 @@
1
1
  {
2
2
  "name": "@webpieces/agent-workflow-rules",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.4.846",
4
+ "description": "Independent workflow guards, guard hook, installation and shim management for AI coding agents.",
5
+ "type": "commonjs",
6
+ "main": "./src/index.js",
7
+ "exports": {
8
+ ".": "./src/index.js",
9
+ "./package.json": "./package.json",
10
+ "./claude-code-guards": "./src/adapters/guards-hook.js",
11
+ "./rule-pack": "./src/rule-pack.js"
12
+ },
13
+ "files": [
14
+ "src/**/*",
15
+ "templates/**/*",
16
+ "README.md"
17
+ ],
18
+ "author": "Dean Hiller",
19
+ "license": "Apache-2.0",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "https://github.com/deanhiller/webpieces-ts.git",
23
+ "directory": "packages/tooling/agent-workflow-rules"
24
+ },
25
+ "dependencies": {
26
+ "@webpieces/hook-runtime": "0.4.846",
27
+ "@webpieces/rules-config": "0.4.846",
28
+ "inversify": "7.10.4",
29
+ "reflect-metadata": "0.2.2",
30
+ "@webpieces/tooling-common": "0.4.846",
31
+ "@webpieces/repo-workflow-core": "0.4.846",
32
+ "tslib": "2.8.1",
33
+ "@webpieces/rules-sdk": "0.4.846"
34
+ },
35
+ "publishConfig": {
36
+ "access": "public"
37
+ },
38
+ "devDependencies": {
39
+ "@webpieces/tooling-testkit": "0.4.846"
40
+ },
41
+ "types": "./src/index.d.ts",
42
+ "bin": {
43
+ "wp-ai-guards-hook": "./src/adapters/guards-hook.js",
44
+ "wp-install-ai-hooks": "./src/bin/install-entry.js",
45
+ "wp-upgrade-shim": "./src/bin/upgrade-shim.js"
46
+ }
47
+ }
@@ -0,0 +1,5 @@
1
+ import { AgentHookEvent, HookOutcome } from '@webpieces/hook-runtime';
2
+ export { denyJson } from '@webpieces/hook-runtime';
3
+ export declare function denyOutcome(event: AgentHookEvent | null, reason: string, rule?: string, fault?: string): HookOutcome;
4
+ export declare function emitDeny(event: AgentHookEvent | null, reason: string, rule?: string, fault?: string): never;
5
+ export declare function emitAllow(): never;
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ // The single place that knows the PreToolUse decision protocol, so every deny is emitted identically
3
+ // — and identically to the checked-in shim
4
+ // (.claude/webpieces/ai-hook.sh, rendered by renderShim() in ../bin/shim.ts), which emits the same JSON.
5
+ //
6
+ // A block is signalled by `permissionDecision: "deny"` JSON on STDOUT with exit 0 — NOT exit 2.
7
+ // Claude Code only parses the JSON on exit 0; exit 2 would ignore stdout and the reason would not
8
+ // surface in the terminal UI. "deny" still blocks the tool, so this remains fail-closed: it is not the
9
+ // silent-allow a bare exit 0 with no JSON would be.
10
+ //
11
+ // WHY the tool-conditional `systemMessage` (verified by live tests against Claude Code v2.1.x — the
12
+ // docs are wrong here; do NOT re-derive from them):
13
+ //
14
+ // | deny field | Bash tool | Write/Edit/MultiEdit tool |
15
+ // |-----------------------------------|-----------------------------------|-------------------------------|
16
+ // | permissionDecisionReason (plain) | model sees it; USER SEES NOTHING | model + RED "Error:" block ok |
17
+ // | systemMessage | ONLY user-visible field; grey | grey extra line (redundant) |
18
+ // | systemMessage wrapped in ANSI red | RED + visible to the user (fix) | redundant 2nd red line |
19
+ //
20
+ // So: on a **Bash** deny we ALSO emit a top-level `systemMessage` wrapped in ANSI red (ESC[31;1m …
21
+ // ESC[0m) — it is the only field a Bash deny shows the human, and it honors ANSI. On
22
+ // Write/Edit/MultiEdit we add NO `systemMessage` (the reason already renders red natively — a second
23
+ // line is just noise). `permissionDecisionReason` is always plain text (never ANSI): it's what the
24
+ // model reads and what Write/Edit renders red. JSON.stringify serializes the ESC char as the valid
25
+ // \u escape, so the payload stays valid JSON — we build the ESC via String.fromCharCode(0x1b) so no
26
+ // raw ESC (0x1b) byte ever lives in this source file. Do NOT use exit 2 (stdout JSON ignored;
27
+ // stderr invisible to the user on Bash).
28
+ // Refs: Claude Code GitHub issues #31592, #40380, #17356 (asymmetry "closed / not planned").
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ exports.denyJson = void 0;
31
+ exports.denyOutcome = denyOutcome;
32
+ exports.emitDeny = emitDeny;
33
+ exports.emitAllow = emitAllow;
34
+ const decision_log_1 = require("../core/decision-log");
35
+ const rules_config_1 = require("@webpieces/rules-config");
36
+ const hook_runtime_1 = require("@webpieces/hook-runtime");
37
+ var hook_runtime_2 = require("@webpieces/hook-runtime");
38
+ Object.defineProperty(exports, "denyJson", { enumerable: true, get: function () { return hook_runtime_2.denyJson; } });
39
+ // THE DENY, AS A VALUE. `reason` is surfaced to both the user (terminal UI) and the model; the event's
40
+ // kind selects whether the red `systemMessage` is added (Bash) or omitted (file tools) — see denyJson.
41
+ //
42
+ // This is the ONE boundary every blocking path passes through, which is why the per-invocation audit
43
+ // line is flushed HERE: the `calls/` stream carries the outcome of its own call, and the outcome is not
44
+ // known until this point. `rule` names what blocked (or '-'), for the line's `rule=` field.
45
+ //
46
+ // `fault` is the L0 fault code when the block IS an L0 fault (S/C/Y — the three decided here in JS,
47
+ // where the sh shim's own `fault=` stamp can never reach), else '-'. Stamping it at this ONE boundary is
48
+ // what makes `grep 'fault=S'` span the whole audit trail rather than only its sh half.
49
+ //
50
+ // It RETURNS the outcome instead of writing it. The write and the exit belong to HookApp, which owns
51
+ // the injected stdout/exit ports — that separation is what lets a golden test read the exact bytes a
52
+ // composed run produces. `denyForCrash` (hook-core) needs the value rather than the throw, because it
53
+ // is already INSIDE the catch that would swallow one.
54
+ // webpieces-disable no-function-outside-class -- the Claude Code PreToolUse protocol boundary; module-scope beside denyJson/allowOutcome by design, and it must stay callable from a tree too broken to build a DI container.
55
+ function denyOutcome(event, reason, rule = '-', fault = rules_config_1.L0_FAULT_NONE) {
56
+ // BLOCK_AI_CURE: every deny that reaches this boundary prints a cure the agent can act on — the
57
+ // L0 faults name a command on the allowlist, and the L1/L2 guards print theirs. A deny needing a
58
+ // HUMAN would have to say so at its own site; none does today, and inventing one here would be
59
+ // guessing at the boundary rather than at the decision.
60
+ decision_log_1.invocationLog.finish('BLOCK_AI_CURE', rule, fault);
61
+ return new hook_runtime_1.HookOutcome((0, hook_runtime_1.denyJson)(event, reason) + '\n', 0);
62
+ }
63
+ // The ALLOW, as a value. No JSON — a silent exit 0 is "allow" in the PreToolUse protocol.
64
+ //
65
+ // NOT exported, deliberately, where denyOutcome is: `denyForCrash` genuinely needs the deny in value
66
+ // form because it is already inside the catch a throw would land in, and nothing needs the allow that
67
+ // way. An exported one would be a second, externally-pickable spelling of "allow" sitting three lines
68
+ // from `emitAllow` — precisely the shape an agent picks by accident.
69
+ // webpieces-disable no-function-outside-class -- the PreToolUse protocol boundary, module-scope beside denyJson/denyOutcome by design, and it must stay callable from a tree too broken to build a DI container
70
+ function allowOutcome() {
71
+ decision_log_1.invocationLog.finish('ALLOW', '-');
72
+ return new hook_runtime_1.HookOutcome('', 0);
73
+ }
74
+ // Block the tool call and END the invocation from wherever in the pipeline we are — see HookTerminated
75
+ // for why the terminal control flow is a throw now rather than a `process.exit` at the call site. Still
76
+ // typed `never`: nothing after a call to this runs.
77
+ // webpieces-disable no-function-outside-class -- the Claude Code PreToolUse protocol boundary; module-scope beside denyJson/emitAllow by design, and it must stay callable from a tree too broken to build a DI container.
78
+ function emitDeny(event, reason, rule = '-', fault = rules_config_1.L0_FAULT_NONE) {
79
+ throw new hook_runtime_1.HookTerminated(denyOutcome(event, reason, rule, fault));
80
+ }
81
+ // Allow the tool call and END the invocation. See emitDeny.
82
+ // webpieces-disable no-function-outside-class -- the PreToolUse protocol boundary, module-scope beside denyJson/emitDeny by design, and it must stay callable from a tree too broken to build a DI container
83
+ function emitAllow() {
84
+ throw new hook_runtime_1.HookTerminated(allowOutcome());
85
+ }
86
+ //# sourceMappingURL=agent-response.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-response.js","sourceRoot":"","sources":["../../../../../../packages/tooling/agent-workflow-rules/src/adapters/agent-response.ts"],"names":[],"mappings":";AAAA,qGAAqG;AACrG,2CAA2C;AAC3C,yGAAyG;AACzG,EAAE;AACF,gGAAgG;AAChG,kGAAkG;AAClG,uGAAuG;AACvG,oDAAoD;AACpD,EAAE;AACF,oGAAoG;AACpG,oDAAoD;AACpD,EAAE;AACF,8GAA8G;AAC9G,8GAA8G;AAC9G,8GAA8G;AAC9G,8GAA8G;AAC9G,8GAA8G;AAC9G,EAAE;AACF,mGAAmG;AACnG,qFAAqF;AACrF,qGAAqG;AACrG,mGAAmG;AACnG,mGAAmG;AACnG,oGAAoG;AACpG,8FAA8F;AAC9F,yCAAyC;AACzC,6FAA6F;;;AAuB7F,kCAOC;AAkBD,4BAEC;AAID,8BAEC;AAtDD,uDAAqD;AACrD,0DAAwD;AACxD,0DAAgG;AAChG,wDAAmD;AAA1C,wGAAA,QAAQ,OAAA;AAEjB,uGAAuG;AACvG,uGAAuG;AACvG,EAAE;AACF,qGAAqG;AACrG,wGAAwG;AACxG,4FAA4F;AAC5F,EAAE;AACF,oGAAoG;AACpG,yGAAyG;AACzG,uFAAuF;AACvF,EAAE;AACF,qGAAqG;AACrG,qGAAqG;AACrG,sGAAsG;AACtG,sDAAsD;AACtD,8NAA8N;AAC9N,SAAgB,WAAW,CAAC,KAA4B,EAAE,MAAc,EAAE,OAAe,GAAG,EAAE,QAAgB,4BAAa;IACvH,gGAAgG;IAChG,iGAAiG;IACjG,+FAA+F;IAC/F,wDAAwD;IACxD,4BAAa,CAAC,MAAM,CAAC,eAAe,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;IACnD,OAAO,IAAI,0BAAW,CAAC,IAAA,uBAAQ,EAAC,KAAK,EAAE,MAAM,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,CAAC;AAC9D,CAAC;AAED,0FAA0F;AAC1F,EAAE;AACF,qGAAqG;AACrG,sGAAsG;AACtG,sGAAsG;AACtG,qEAAqE;AACrE,gNAAgN;AAChN,SAAS,YAAY;IACjB,4BAAa,CAAC,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;IACnC,OAAO,IAAI,0BAAW,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;AAClC,CAAC;AAED,uGAAuG;AACvG,wGAAwG;AACxG,oDAAoD;AACpD,2NAA2N;AAC3N,SAAgB,QAAQ,CAAC,KAA4B,EAAE,MAAc,EAAE,OAAe,GAAG,EAAE,QAAgB,4BAAa;IACpH,MAAM,IAAI,6BAAc,CAAC,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;AACtE,CAAC;AAED,4DAA4D;AAC5D,6MAA6M;AAC7M,SAAgB,SAAS;IACrB,MAAM,IAAI,6BAAc,CAAC,YAAY,EAAE,CAAC,CAAC;AAC7C,CAAC","sourcesContent":["// The single place that knows the PreToolUse decision protocol, so every deny is emitted identically\n// — and identically to the checked-in shim\n// (.claude/webpieces/ai-hook.sh, rendered by renderShim() in ../bin/shim.ts), which emits the same JSON.\n//\n// A block is signalled by `permissionDecision: \"deny\"` JSON on STDOUT with exit 0 — NOT exit 2.\n// Claude Code only parses the JSON on exit 0; exit 2 would ignore stdout and the reason would not\n// surface in the terminal UI. \"deny\" still blocks the tool, so this remains fail-closed: it is not the\n// silent-allow a bare exit 0 with no JSON would be.\n//\n// WHY the tool-conditional `systemMessage` (verified by live tests against Claude Code v2.1.x — the\n// docs are wrong here; do NOT re-derive from them):\n//\n// | deny field | Bash tool | Write/Edit/MultiEdit tool |\n// |-----------------------------------|-----------------------------------|-------------------------------|\n// | permissionDecisionReason (plain) | model sees it; USER SEES NOTHING | model + RED \"Error:\" block ok |\n// | systemMessage | ONLY user-visible field; grey | grey extra line (redundant) |\n// | systemMessage wrapped in ANSI red | RED + visible to the user (fix) | redundant 2nd red line |\n//\n// So: on a **Bash** deny we ALSO emit a top-level `systemMessage` wrapped in ANSI red (ESC[31;1m …\n// ESC[0m) — it is the only field a Bash deny shows the human, and it honors ANSI. On\n// Write/Edit/MultiEdit we add NO `systemMessage` (the reason already renders red natively — a second\n// line is just noise). `permissionDecisionReason` is always plain text (never ANSI): it's what the\n// model reads and what Write/Edit renders red. JSON.stringify serializes the ESC char as the valid\n// \\u escape, so the payload stays valid JSON — we build the ESC via String.fromCharCode(0x1b) so no\n// raw ESC (0x1b) byte ever lives in this source file. Do NOT use exit 2 (stdout JSON ignored;\n// stderr invisible to the user on Bash).\n// Refs: Claude Code GitHub issues #31592, #40380, #17356 (asymmetry \"closed / not planned\").\n\nimport { invocationLog } from '../core/decision-log';\nimport { L0_FAULT_NONE } from '@webpieces/rules-config';\nimport { AgentHookEvent, HookOutcome, HookTerminated, denyJson } from '@webpieces/hook-runtime';\nexport { denyJson } from '@webpieces/hook-runtime';\n\n// THE DENY, AS A VALUE. `reason` is surfaced to both the user (terminal UI) and the model; the event's\n// kind selects whether the red `systemMessage` is added (Bash) or omitted (file tools) — see denyJson.\n//\n// This is the ONE boundary every blocking path passes through, which is why the per-invocation audit\n// line is flushed HERE: the `calls/` stream carries the outcome of its own call, and the outcome is not\n// known until this point. `rule` names what blocked (or '-'), for the line's `rule=` field.\n//\n// `fault` is the L0 fault code when the block IS an L0 fault (S/C/Y — the three decided here in JS,\n// where the sh shim's own `fault=` stamp can never reach), else '-'. Stamping it at this ONE boundary is\n// what makes `grep 'fault=S'` span the whole audit trail rather than only its sh half.\n//\n// It RETURNS the outcome instead of writing it. The write and the exit belong to HookApp, which owns\n// the injected stdout/exit ports — that separation is what lets a golden test read the exact bytes a\n// composed run produces. `denyForCrash` (hook-core) needs the value rather than the throw, because it\n// is already INSIDE the catch that would swallow one.\n// webpieces-disable no-function-outside-class -- the Claude Code PreToolUse protocol boundary; module-scope beside denyJson/allowOutcome by design, and it must stay callable from a tree too broken to build a DI container.\nexport function denyOutcome(event: AgentHookEvent | null, reason: string, rule: string = '-', fault: string = L0_FAULT_NONE): HookOutcome {\n // BLOCK_AI_CURE: every deny that reaches this boundary prints a cure the agent can act on — the\n // L0 faults name a command on the allowlist, and the L1/L2 guards print theirs. A deny needing a\n // HUMAN would have to say so at its own site; none does today, and inventing one here would be\n // guessing at the boundary rather than at the decision.\n invocationLog.finish('BLOCK_AI_CURE', rule, fault);\n return new HookOutcome(denyJson(event, reason) + '\\n', 0);\n}\n\n// The ALLOW, as a value. No JSON — a silent exit 0 is \"allow\" in the PreToolUse protocol.\n//\n// NOT exported, deliberately, where denyOutcome is: `denyForCrash` genuinely needs the deny in value\n// form because it is already inside the catch a throw would land in, and nothing needs the allow that\n// way. An exported one would be a second, externally-pickable spelling of \"allow\" sitting three lines\n// from `emitAllow` — precisely the shape an agent picks by accident.\n// webpieces-disable no-function-outside-class -- the PreToolUse protocol boundary, module-scope beside denyJson/denyOutcome by design, and it must stay callable from a tree too broken to build a DI container\nfunction allowOutcome(): HookOutcome {\n invocationLog.finish('ALLOW', '-');\n return new HookOutcome('', 0);\n}\n\n// Block the tool call and END the invocation from wherever in the pipeline we are — see HookTerminated\n// for why the terminal control flow is a throw now rather than a `process.exit` at the call site. Still\n// typed `never`: nothing after a call to this runs.\n// webpieces-disable no-function-outside-class -- the Claude Code PreToolUse protocol boundary; module-scope beside denyJson/emitAllow by design, and it must stay callable from a tree too broken to build a DI container.\nexport function emitDeny(event: AgentHookEvent | null, reason: string, rule: string = '-', fault: string = L0_FAULT_NONE): never {\n throw new HookTerminated(denyOutcome(event, reason, rule, fault));\n}\n\n// Allow the tool call and END the invocation. See emitDeny.\n// webpieces-disable no-function-outside-class -- the PreToolUse protocol boundary, module-scope beside denyJson/emitDeny by design, and it must stay callable from a tree too broken to build a DI container\nexport function emitAllow(): never {\n throw new HookTerminated(allowOutcome());\n}\n"]}
@@ -0,0 +1,45 @@
1
+ import { AgentHookEvent } from '@webpieces/hook-runtime';
2
+ import { BlockedResult } from '@webpieces/hook-runtime';
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
+ }
@@ -0,0 +1,88 @@
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 hook_runtime_1 = require("@webpieces/hook-runtime");
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 hook_runtime_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 hook_runtime_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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codex-subagent-guard.js","sourceRoot":"","sources":["../../../../../../packages/tooling/agent-workflow-rules/src/adapters/codex-subagent-guard.ts"],"names":[],"mappings":";;;;AAAA,mDAA6B;AAE7B,0DAAqF;AACrF,8DAA6E;AAC7E,sEAAiE;AAGjE,0DAAwD;AAE3C,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,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC3G,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAgB,EAAW,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,EAAE,CAAC;YACzF,OAAO,IAAI,4BAAa,CAAC,IAAA,kCAAmB,EAAC,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QACnF,CAAC;QACD,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,gBAAgB,CAAC,CAAC;QACjE,MAAM,KAAK,GAAG,IAAI,4BAAa,CAC3B,2BAAmB,EACnB,6EAA6E,OAAO,MAAM;YAC1F,8FAA8F;YAC9F,8FAA8F;YAC9F,yDAAyD,EACzD,SAAS,EACT,SAAS,EACT;YACI,IAAI,qBAAM,CAAC,wGAAwG,QAAQ,cAAc,EAAE,IAAI,CAAC;YAChJ,IAAI,qBAAM,CAAC,wGAAwG,CAAC;SACvH,CACJ,CAAC;QACF,OAAO,IAAI,4BAAa,CAAC,IAAA,kCAAmB,EAAC,KAAK,CAAC,CAAC,CAAC;IACzD,CAAC;IAED;;;;;OAKG;IACK,iBAAiB,CAAC,OAAe;QACrC,OAAO,IAAI,4BAAa,CACpB,2BAAmB,EACnB,sDAAsD,OAAO,MAAM;YACnE,oEAAoE,qCAAgB,UAAU;YAC9F,wGAAwG;YACxG,8BAA8B,EAC9B,SAAS,EACT,SAAS,EACT;YACI,IAAI,qBAAM,CAAC,0CAA0C,qCAAgB,wEAAwE,EAAE,IAAI,CAAC;SACvJ,CACJ,CAAC;IACN,CAAC;IAEO,aAAa,CAAC,QAAgB,EAAE,IAAY;QAChD,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,kCAAiB,EAAE,8BAAa,CAAC,GAAG,IAAI,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 '@webpieces/hook-runtime';\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"]}
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ import 'reflect-metadata';
3
+ export declare function main(): Promise<void>;
@@ -0,0 +1,30 @@
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guards-hook.js","sourceRoot":"","sources":["../../../../../../packages/tooling/agent-workflow-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,uEAAoE;AAEpE,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"]}
@@ -0,0 +1,68 @@
1
+ import { HookMode } from '@webpieces/hook-runtime';
2
+ /**
3
+ * THE WIRE BYTES the golden tests drive, and the throwaway repo they are judged against.
4
+ *
5
+ * Everything here exists so a reader can see EXACTLY what a harness sends: the payloads are built from
6
+ * the measured envelope key sets (see the fixture docs on GoldenFixture below), not from anything the
7
+ * hook itself produces, and the repo is a real `git init` with a frozen webpieces.config.json rather
8
+ * than whatever tree the suite happens to be running in. A golden computed against the live repo would
9
+ * change verdict with the branch you are standing on.
10
+ *
11
+ * This is NOT a spec file, deliberately: `tsconfig.lib.json` excludes `*.spec.ts`, so a payload builder
12
+ * living in one would never be type-checked by the build.
13
+ */
14
+ /** How one PreToolUse call is presented to the hook. Data class per CLAUDE.md rule 1. */
15
+ export declare class GoldenFixture {
16
+ /** Stable key into `__goldens__/hook-app-goldens.json`. */
17
+ readonly name: string;
18
+ /** Which hook binary's mode — `guards` or `rules`. */
19
+ readonly mode: HookMode;
20
+ /**
21
+ * The raw stdin bytes. A STRING, never an object, because malformed stdin is one of the fixtures
22
+ * and a shape that cannot express "not JSON" would quietly drop the case that matters most.
23
+ */
24
+ readonly stdin: string;
25
+ /** True ⇒ the fixture repo also gets a `rulesDir` whose one module throws when required. */
26
+ readonly crashingRulesDir: boolean;
27
+ constructor(name: string, mode: HookMode, stdin: string, crashingRulesDir?: boolean);
28
+ }
29
+ /** A built fixture repo: where it lives, and the stdin bytes with `<REPO>` resolved into it. */
30
+ export declare class PreparedFixture {
31
+ readonly repo: string;
32
+ readonly root: string;
33
+ readonly stdin: string;
34
+ constructor(repo: string, root: string, stdin: string);
35
+ }
36
+ /**
37
+ * The placeholder that stands for the fixture repo's absolute path, in BOTH directions: payloads are
38
+ * written with it and it is substituted in before the run; golden bytes are compared with the real
39
+ * path substituted back out. Guard reports legitimately name absolute paths (the git-workflow doc
40
+ * pointer, the blocked file), and a golden that hard-coded one machine's `/var/folders/...` would be
41
+ * a golden nobody else could run.
42
+ */
43
+ export declare const REPO_TOKEN = "<REPO>";
44
+ /**
45
+ * ONE fixture per row of the coverage the composed pipeline had none of before: for BOTH harnesses a
46
+ * Bash deny (the ANSI-red systemMessage), a file-tool deny (NO systemMessage), an allow, a read-only
47
+ * tool, malformed stdin, and a fail-closed crash.
48
+ */
49
+ export declare const GOLDEN_FIXTURES: readonly GoldenFixture[];
50
+ /**
51
+ * Builds ONE throwaway git repo per fixture and returns it with the payload's `<REPO>` resolved.
52
+ *
53
+ * A FRESH repo per fixture, not one shared: the hook writes `.webpieces/` state (the decision log, the
54
+ * main-sync cache) as it runs, so a shared tree would let fixture N's leftovers decide fixture N+1's
55
+ * verdict — an order-dependent suite, which is the one kind of golden test worse than none.
56
+ *
57
+ * `realpathSync` matters on macOS: `os.tmpdir()` hands back `/var/folders/...` which resolves to
58
+ * `/private/var/...`, and the L1 location guard compares the payload's cwd against the resolved repo
59
+ * root. Without it every fixture denies with "run git from the repo root" instead of the verdict under
60
+ * test.
61
+ */
62
+ export declare class GoldenRepoBuilder {
63
+ private readonly configJson;
64
+ constructor();
65
+ build(fixture: GoldenFixture): PreparedFixture;
66
+ private repoConfig;
67
+ private git;
68
+ }