@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
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ /**
3
+ * THE L0 ENTRY TYPES — the shape of one allowlist entry, split out of ./l0-allowlist.
4
+ *
5
+ * Same reason `./l0-codex-read` and `./l0-ignored-tools` are their own modules: the LIST is long and
6
+ * every entry carries a paragraph of reasoning, so the types that describe an entry get crowded out
7
+ * by the entries themselves. Nothing here knows what is on the list; `./l0-allowlist` owns that and
8
+ * imports these, so the dependency runs one way and there is no cycle.
9
+ *
10
+ * NOT re-exported from here onward — `./shim` is the ONE name that gathers L0, and it stars this
11
+ * module alongside the others.
12
+ */
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.L0AllowEntry = exports.L0Call = exports.EVERY_HARNESS = void 0;
15
+ /**
16
+ * The token an L0 entry uses to say it serves EVERY harness — SAID OUT LOUD.
17
+ *
18
+ * This used to be `null`, and `null` is shim shape #5 from `.claude/rules/no-backwards-compat.md`: a widening expressed as an
19
+ * ABSENCE. It made the widest setting the shortest thing to type and, worse, impossible to grep —
20
+ * there is no search that lists "the entries every harness gets", because they were identified by
21
+ * a field that was not there. `grep -n EVERY_HARNESS` now lists every one of them.
22
+ *
23
+ * It is a REAL VALUE in exactly the sense `AI_TYPE_UNKNOWN` is: countable, greppable, and typed.
24
+ */
25
+ exports.EVERY_HARNESS = 'every-harness';
26
+ /** One tool call as L0 judges it: the tool name, the Bash command (or ''), the file target (or ''). */
27
+ class L0Call {
28
+ toolName;
29
+ command;
30
+ filePath;
31
+ constructor(toolName, command, filePath) {
32
+ this.toolName = toolName;
33
+ this.command = command;
34
+ this.filePath = filePath;
35
+ }
36
+ }
37
+ exports.L0Call = L0Call;
38
+ /**
39
+ * One entry of THE L0 allowlist. Data-only → a class, per CLAUDE.md.
40
+ *
41
+ * `ere`/`js` are the twin regex BODIES for a Bash entry, or null for a tool-shaped entry (Read, the
42
+ * webpieces.config.json target) that no regex can express. `sample` is a call this entry must accept —
43
+ * it is what the matrix-coverage and cure-reachability tests drive isAllowed() with.
44
+ *
45
+ * `extraSamples` pins ADDITIONAL spellings the same entry must accept. A spelling that some deny
46
+ * message prescribes belongs here, or nothing stops a later tightening of the pattern from making that
47
+ * message's cure untypable again — which is the deadlock shape this whole module exists to prevent.
48
+ *
49
+ * `cure` is the ONE thing that is not uniform across the list, and it is not about L0 at all — see
50
+ * L0_CURE_ALLOW_JS below. Every entry is judged identically while an L0 fault is up; `cure` decides
51
+ * only whether the entry ALSO bypasses the downstream (L1) guards on a HEALTHY tree.
52
+ */
53
+ class L0AllowEntry {
54
+ label;
55
+ kind;
56
+ cure;
57
+ ere;
58
+ js;
59
+ harness;
60
+ sample;
61
+ extraSamples;
62
+ // eslint-disable-next-line @typescript-eslint/max-params
63
+ constructor(label, kind,
64
+ /**
65
+ * True when this entry REPAIRS the tooling (install, sync, shim restore). A cure has to run
66
+ * before webpieces.config.json can even be loaded, so it bypasses everything, always. A
67
+ * non-cure (read-only orientation) is allowed while a fault is up and is otherwise an ordinary
68
+ * command the downstream guards still judge.
69
+ */
70
+ cure, ere, js,
71
+ /**
72
+ * The ONE harness this entry exists for, or `EVERY_HARNESS` for the entries every harness gets.
73
+ * There is no default and no absence: an entry must say which it is, or it does not compile.
74
+ *
75
+ * A gated entry is unreachable from any other harness — it is spliced into its own union, which
76
+ * both halves of L0 consult only after answering "which harness sent this call?". It exists
77
+ * because the two harnesses do not have the same TOOLS: `Read` is entry 1 for Claude Code and
78
+ * Codex has no such tool, so read parity at L0 can only be expressed per harness. Anything added
79
+ * here later must satisfy the property stated on AI_TYPE_SH: the sh half's answer is an
80
+ * approximation, so a gated entry may never grant more than the OTHER harness already has.
81
+ */
82
+ harness, sample, extraSamples = []) {
83
+ this.label = label;
84
+ this.kind = kind;
85
+ this.cure = cure;
86
+ this.ere = ere;
87
+ this.js = js;
88
+ this.harness = harness;
89
+ this.sample = sample;
90
+ this.extraSamples = extraSamples;
91
+ }
92
+ /** Every call this entry pins: the canonical sample plus every extra spelling. */
93
+ allSamples() {
94
+ return [this.sample, ...this.extraSamples];
95
+ }
96
+ }
97
+ exports.L0AllowEntry = L0AllowEntry;
98
+ //# sourceMappingURL=l0-entry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"l0-entry.js","sourceRoot":"","sources":["../../../../../../packages/tooling/agent-workflow-rules/src/bin/l0-entry.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;AAIH;;;;;;;;;GASG;AACU,QAAA,aAAa,GAAG,eAAe,CAAC;AAY7C,uGAAuG;AACvG,MAAa,MAAM;IAEF;IACA;IACA;IAHb,YACa,QAAgB,EAChB,OAAe,EACf,QAAgB;QAFhB,aAAQ,GAAR,QAAQ,CAAQ;QAChB,YAAO,GAAP,OAAO,CAAQ;QACf,aAAQ,GAAR,QAAQ,CAAQ;IAC1B,CAAC;CACP;AAND,wBAMC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAa,YAAY;IAGR;IACA;IAOA;IACA;IACA;IAYA;IACA;IACA;IA1Bb,yDAAyD;IACzD,YACa,KAAa,EACb,IAAsB;IAC/B;;;;;OAKG;IACM,IAAa,EACb,GAAkB,EAClB,EAAiB;IAC1B;;;;;;;;;;OAUG;IACM,OAAkB,EAClB,MAAc,EACd,eAAkC,EAAE;QAxBpC,UAAK,GAAL,KAAK,CAAQ;QACb,SAAI,GAAJ,IAAI,CAAkB;QAOtB,SAAI,GAAJ,IAAI,CAAS;QACb,QAAG,GAAH,GAAG,CAAe;QAClB,OAAE,GAAF,EAAE,CAAe;QAYjB,YAAO,GAAP,OAAO,CAAW;QAClB,WAAM,GAAN,MAAM,CAAQ;QACd,iBAAY,GAAZ,YAAY,CAAwB;IAC9C,CAAC;IAEJ,kFAAkF;IAClF,UAAU;QACN,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,YAAY,CAAC,CAAC;IAC/C,CAAC;CACJ;AAlCD,oCAkCC","sourcesContent":["/**\n * THE L0 ENTRY TYPES — the shape of one allowlist entry, split out of ./l0-allowlist.\n *\n * Same reason `./l0-codex-read` and `./l0-ignored-tools` are their own modules: the LIST is long and\n * every entry carries a paragraph of reasoning, so the types that describe an entry get crowded out\n * by the entries themselves. Nothing here knows what is on the list; `./l0-allowlist` owns that and\n * imports these, so the dependency runs one way and there is no cycle.\n *\n * NOT re-exported from here onward — `./shim` is the ONE name that gathers L0, and it stars this\n * module alongside the others.\n */\n\nimport { AiType } from '@webpieces/hook-runtime';\n\n/**\n * The token an L0 entry uses to say it serves EVERY harness — SAID OUT LOUD.\n *\n * This used to be `null`, and `null` is shim shape #5 from `.claude/rules/no-backwards-compat.md`: a widening expressed as an\n * ABSENCE. It made the widest setting the shortest thing to type and, worse, impossible to grep —\n * there is no search that lists \"the entries every harness gets\", because they were identified by\n * a field that was not there. `grep -n EVERY_HARNESS` now lists every one of them.\n *\n * It is a REAL VALUE in exactly the sense `AI_TYPE_UNKNOWN` is: countable, greppable, and typed.\n */\nexport const EVERY_HARNESS = 'every-harness';\n\n/**\n * Who one L0 entry is FOR: exactly one harness, or — named, never implied — all of them.\n *\n * Deliberately NOT `readonly AiType[]`. A list re-opens the hole this closed from the other side:\n * `[]` would be a second way to write \"nobody\", and `['claude-code', 'codex']` a second way to write\n * EVERY_HARNESS — two spellings of one decision, which is shim shape #1. Dean's rule is the whole\n * type: we only support codex or claudecode or FAIL.\n */\nexport type L0Harness = AiType | typeof EVERY_HARNESS;\n\n/** One tool call as L0 judges it: the tool name, the Bash command (or ''), the file target (or ''). */\nexport class L0Call {\n constructor(\n readonly toolName: string,\n readonly command: string,\n readonly filePath: string,\n ) {}\n}\n\n/**\n * One entry of THE L0 allowlist. Data-only → a class, per CLAUDE.md.\n *\n * `ere`/`js` are the twin regex BODIES for a Bash entry, or null for a tool-shaped entry (Read, the\n * webpieces.config.json target) that no regex can express. `sample` is a call this entry must accept —\n * it is what the matrix-coverage and cure-reachability tests drive isAllowed() with.\n *\n * `extraSamples` pins ADDITIONAL spellings the same entry must accept. A spelling that some deny\n * message prescribes belongs here, or nothing stops a later tightening of the pattern from making that\n * message's cure untypable again — which is the deadlock shape this whole module exists to prevent.\n *\n * `cure` is the ONE thing that is not uniform across the list, and it is not about L0 at all — see\n * L0_CURE_ALLOW_JS below. Every entry is judged identically while an L0 fault is up; `cure` decides\n * only whether the entry ALSO bypasses the downstream (L1) guards on a HEALTHY tree.\n */\nexport class L0AllowEntry {\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(\n readonly label: string,\n readonly kind: 'pass' | 'allow',\n /**\n * True when this entry REPAIRS the tooling (install, sync, shim restore). A cure has to run\n * before webpieces.config.json can even be loaded, so it bypasses everything, always. A\n * non-cure (read-only orientation) is allowed while a fault is up and is otherwise an ordinary\n * command the downstream guards still judge.\n */\n readonly cure: boolean,\n readonly ere: string | null,\n readonly js: string | null,\n /**\n * The ONE harness this entry exists for, or `EVERY_HARNESS` for the entries every harness gets.\n * There is no default and no absence: an entry must say which it is, or it does not compile.\n *\n * A gated entry is unreachable from any other harness — it is spliced into its own union, which\n * both halves of L0 consult only after answering \"which harness sent this call?\". It exists\n * because the two harnesses do not have the same TOOLS: `Read` is entry 1 for Claude Code and\n * Codex has no such tool, so read parity at L0 can only be expressed per harness. Anything added\n * here later must satisfy the property stated on AI_TYPE_SH: the sh half's answer is an\n * approximation, so a gated entry may never grant more than the OTHER harness already has.\n */\n readonly harness: L0Harness,\n readonly sample: L0Call,\n readonly extraSamples: readonly L0Call[] = [],\n ) {}\n\n /** Every call this entry pins: the canonical sample plus every extra spelling. */\n allSamples(): readonly L0Call[] {\n return [this.sample, ...this.extraSamples];\n }\n}\n\n"]}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * THE CODEX TOOLS L0 HAS NOTHING TO SAY ABOUT — its own module because BOTH halves of L0 read it and
3
+ * neither may reach the other: `l0-allowlist.ts` splices the sh alternation into the rendered shim, and
4
+ * `l0-decide.ts` asks the JS predicate. A set that lived in either one would make the other import it
5
+ * for a reason unrelated to that file's job.
6
+ *
7
+ * Dependency-free on purpose, like every other L0 module: it has to load on a tree too broken to build a
8
+ * DI container.
9
+ */
10
+ /**
11
+ * TOOLS WITH NOTHING TO JUDGE — the Codex tools that are neither a shell command nor a file edit.
12
+ *
13
+ * MEASURED in a live codex-cli 0.151.0 session: `webrun`, `collaborationspawn_agent`,
14
+ * `collaborationwait_agent`, `view_image`, `update_plan`. The CodexAdapter already maps them to the
15
+ * `Ignored` routing kind on a HEALTHY tree; this is the same answer one layer out, for the fail-CLOSED
16
+ * path, where the guard bin never runs and the shim decides alone.
17
+ *
18
+ * Without it, an L0 fault (D/X/U/K/S) turns every one of these into a DENY: `update_plan` is how a Codex
19
+ * agent records what it intends to do next, so the agent would be blocked from RECORDING the cure while
20
+ * being told to run it. That is the deadlock shape the whole allowlist exists to remove, and it is why
21
+ * this is a set and not a comment.
22
+ *
23
+ * AN EXPLICIT LIST, NOT "anything unrecognised" — and that asymmetry with CodexAdapter.kindOf() is
24
+ * deliberate. The adapter's default is safe because a healthy tree still has every guard behind it; L0's
25
+ * default must be DENY, or a future write-capable Codex tool would be waved straight past a fault the
26
+ * day it ships. So `apply_patch` is deliberately ABSENT: it is Codex's only WRITE, it is not a cure, and
27
+ * under a fault it must fail closed exactly as `Write`/`Edit` do.
28
+ *
29
+ * Keep in sync with L0_IGNORED_TOOLS_SH below (locked by the twin unit test).
30
+ */
31
+ export declare const L0_IGNORED_TOOLS: ReadonlySet<string>;
32
+ /**
33
+ * sh twin of L0_IGNORED_TOOLS — the alternation the rendered shim splices into a `case` pattern.
34
+ *
35
+ * BUILT from the set rather than retyped, for the reason every other twin in this file is: two hand-kept
36
+ * lists is two answers to one question, and the one that drifts is always the one nobody is reading.
37
+ */
38
+ export declare const L0_IGNORED_TOOLS_SH: string;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.L0_IGNORED_TOOLS_SH = exports.L0_IGNORED_TOOLS = void 0;
4
+ /**
5
+ * THE CODEX TOOLS L0 HAS NOTHING TO SAY ABOUT — its own module because BOTH halves of L0 read it and
6
+ * neither may reach the other: `l0-allowlist.ts` splices the sh alternation into the rendered shim, and
7
+ * `l0-decide.ts` asks the JS predicate. A set that lived in either one would make the other import it
8
+ * for a reason unrelated to that file's job.
9
+ *
10
+ * Dependency-free on purpose, like every other L0 module: it has to load on a tree too broken to build a
11
+ * DI container.
12
+ */
13
+ /**
14
+ * TOOLS WITH NOTHING TO JUDGE — the Codex tools that are neither a shell command nor a file edit.
15
+ *
16
+ * MEASURED in a live codex-cli 0.151.0 session: `webrun`, `collaborationspawn_agent`,
17
+ * `collaborationwait_agent`, `view_image`, `update_plan`. The CodexAdapter already maps them to the
18
+ * `Ignored` routing kind on a HEALTHY tree; this is the same answer one layer out, for the fail-CLOSED
19
+ * path, where the guard bin never runs and the shim decides alone.
20
+ *
21
+ * Without it, an L0 fault (D/X/U/K/S) turns every one of these into a DENY: `update_plan` is how a Codex
22
+ * agent records what it intends to do next, so the agent would be blocked from RECORDING the cure while
23
+ * being told to run it. That is the deadlock shape the whole allowlist exists to remove, and it is why
24
+ * this is a set and not a comment.
25
+ *
26
+ * AN EXPLICIT LIST, NOT "anything unrecognised" — and that asymmetry with CodexAdapter.kindOf() is
27
+ * deliberate. The adapter's default is safe because a healthy tree still has every guard behind it; L0's
28
+ * default must be DENY, or a future write-capable Codex tool would be waved straight past a fault the
29
+ * day it ships. So `apply_patch` is deliberately ABSENT: it is Codex's only WRITE, it is not a cure, and
30
+ * under a fault it must fail closed exactly as `Write`/`Edit` do.
31
+ *
32
+ * Keep in sync with L0_IGNORED_TOOLS_SH below (locked by the twin unit test).
33
+ */
34
+ exports.L0_IGNORED_TOOLS = new Set([
35
+ 'webrun', 'collaborationspawn_agent', 'collaborationwait_agent', 'view_image', 'update_plan',
36
+ ]);
37
+ /**
38
+ * sh twin of L0_IGNORED_TOOLS — the alternation the rendered shim splices into a `case` pattern.
39
+ *
40
+ * BUILT from the set rather than retyped, for the reason every other twin in this file is: two hand-kept
41
+ * lists is two answers to one question, and the one that drifts is always the one nobody is reading.
42
+ */
43
+ exports.L0_IGNORED_TOOLS_SH = [...exports.L0_IGNORED_TOOLS].join('|');
44
+ //# sourceMappingURL=l0-ignored-tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"l0-ignored-tools.js","sourceRoot":"","sources":["../../../../../../packages/tooling/agent-workflow-rules/src/bin/l0-ignored-tools.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;GAQG;AACH;;;;;;;;;;;;;;;;;;;;GAoBG;AACU,QAAA,gBAAgB,GAAwB,IAAI,GAAG,CAAC;IACzD,QAAQ,EAAE,0BAA0B,EAAE,yBAAyB,EAAE,YAAY,EAAE,aAAa;CAC/F,CAAC,CAAC;AAEH;;;;;GAKG;AACU,QAAA,mBAAmB,GAAG,CAAC,GAAG,wBAAgB,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC","sourcesContent":["/**\n * THE CODEX TOOLS L0 HAS NOTHING TO SAY ABOUT — its own module because BOTH halves of L0 read it and\n * neither may reach the other: `l0-allowlist.ts` splices the sh alternation into the rendered shim, and\n * `l0-decide.ts` asks the JS predicate. A set that lived in either one would make the other import it\n * for a reason unrelated to that file's job.\n *\n * Dependency-free on purpose, like every other L0 module: it has to load on a tree too broken to build a\n * DI container.\n */\n/**\n * TOOLS WITH NOTHING TO JUDGE — the Codex tools that are neither a shell command nor a file edit.\n *\n * MEASURED in a live codex-cli 0.151.0 session: `webrun`, `collaborationspawn_agent`,\n * `collaborationwait_agent`, `view_image`, `update_plan`. The CodexAdapter already maps them to the\n * `Ignored` routing kind on a HEALTHY tree; this is the same answer one layer out, for the fail-CLOSED\n * path, where the guard bin never runs and the shim decides alone.\n *\n * Without it, an L0 fault (D/X/U/K/S) turns every one of these into a DENY: `update_plan` is how a Codex\n * agent records what it intends to do next, so the agent would be blocked from RECORDING the cure while\n * being told to run it. That is the deadlock shape the whole allowlist exists to remove, and it is why\n * this is a set and not a comment.\n *\n * AN EXPLICIT LIST, NOT \"anything unrecognised\" — and that asymmetry with CodexAdapter.kindOf() is\n * deliberate. The adapter's default is safe because a healthy tree still has every guard behind it; L0's\n * default must be DENY, or a future write-capable Codex tool would be waved straight past a fault the\n * day it ships. So `apply_patch` is deliberately ABSENT: it is Codex's only WRITE, it is not a cure, and\n * under a fault it must fail closed exactly as `Write`/`Edit` do.\n *\n * Keep in sync with L0_IGNORED_TOOLS_SH below (locked by the twin unit test).\n */\nexport const L0_IGNORED_TOOLS: ReadonlySet<string> = new Set([\n 'webrun', 'collaborationspawn_agent', 'collaborationwait_agent', 'view_image', 'update_plan',\n]);\n\n/**\n * sh twin of L0_IGNORED_TOOLS — the alternation the rendered shim splices into a `case` pattern.\n *\n * BUILT from the set rather than retyped, for the reason every other twin in this file is: two hand-kept\n * lists is two answers to one question, and the one that drifts is always the one nobody is reading.\n */\nexport const L0_IGNORED_TOOLS_SH = [...L0_IGNORED_TOOLS].join('|');\n"]}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * THE MANAGED `env` ENTRY — `CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR=1`, the FOURTH managed surface.
3
+ *
4
+ * Claude Code reads this variable once per Bash tool call and, when it is truthy, resets the shell's
5
+ * cwd back to the project directory after EVERY call. With it unset, the reset is CONDITIONAL (only
6
+ * when the cwd drifted to a dir that is not an allowed one) and prints a visible "Shell cwd was reset
7
+ * to …" notice, so an ordinary `cd` persists from one Bash call to the next. Verified against the
8
+ * 2.1.226 binary, where the variable also appears in the settings-`env` allowlist beside
9
+ * `BASH_DEFAULT_TIMEOUT_MS` — which is what makes `.claude/settings.json` → `env` a supported home for
10
+ * it rather than a guess.
11
+ *
12
+ * WHY WEBPIECES MANAGES IT — it is VERDICT STABILITY, not ergonomics:
13
+ *
14
+ * 1. A guard's answer must not depend on where an earlier, unrelated command left the shell. Every
15
+ * location guard reasons about the tree a call acts on; with the cwd pinned, that is a function of
16
+ * the COMMAND alone rather than of session history. Same command, same verdict, every time.
17
+ * 2. Settings `env` is INHERITED, so the main agent and every subagent it spawns share one cwd — and
18
+ * therefore one verdict — instead of each carrying whatever `cd` happened earlier in its own
19
+ * session. Consistency across agents is the point, and it is why this lives in settings rather
20
+ * than in a shell profile.
21
+ * 3. It mechanically enforces the long-standing "do not `cd` into a sub-package and leave the shell
22
+ * there" rule, rather than relying on an agent remembering it.
23
+ *
24
+ * WHAT IT NO LONGER HAS TO DO. This entry was originally justified by hook RESOLUTION: the guard hooks
25
+ * were registered RELATIVE, a relative hook that cannot resolve exits 127 (a NON-BLOCKING error, i.e. a
26
+ * SILENT UNGUARDED ALLOW), and pinning the cwd kept them resolvable. That job is gone — both hooks are
27
+ * registered ABSOLUTE via `$CLAUDE_PROJECT_DIR` now, so they resolve from any cwd by construction and
28
+ * the L-1 hook that policed the same hazard is deleted. The reasons above are what remain, and they are
29
+ * sufficient on their own; the entry is NOT load-bearing for guard integrity any more.
30
+ *
31
+ * THE TRADE, said out loud: with the flag ON the cwd reset is SILENT and UNCONDITIONAL, where without
32
+ * it the reset is conditional and prints a notice. A deliberate `cd` therefore no longer persists
33
+ * across Bash calls. That is the intended cost of (1) and (2), not an oversight — chain into the
34
+ * directory you need (`cd <dir> && <cmd>`) instead of relying on a sticky cwd.
35
+ *
36
+ * ONE spelling, one required value: the entry is either exactly `1` or it is drift. There is no
37
+ * "accepted alternative truthy value" and no legacy key — `envStale()` in hook-registration.ts is the
38
+ * whole contract, and `applyManagedEnv()` brings any other value (including a user-set `0`) to `1`.
39
+ *
40
+ * WHY THESE TWO CONSTANTS LIVE IN THEIR OWN MODULE: `shim.ts` names them in the fault-S deny text and
41
+ * `hook-registration.ts` owns the predicate that reads them, and hook-registration already imports
42
+ * shim. Defining them here — a leaf with no imports at all — keeps that graph acyclic while leaving
43
+ * exactly one definition of each, in the same way SHIM_MARKER lives in shim.ts.
44
+ */
45
+ export declare const BASH_CWD_ENV_KEY = "CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR";
46
+ export declare const BASH_CWD_ENV_VALUE = "1";
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BASH_CWD_ENV_VALUE = exports.BASH_CWD_ENV_KEY = void 0;
4
+ /**
5
+ * THE MANAGED `env` ENTRY — `CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR=1`, the FOURTH managed surface.
6
+ *
7
+ * Claude Code reads this variable once per Bash tool call and, when it is truthy, resets the shell's
8
+ * cwd back to the project directory after EVERY call. With it unset, the reset is CONDITIONAL (only
9
+ * when the cwd drifted to a dir that is not an allowed one) and prints a visible "Shell cwd was reset
10
+ * to …" notice, so an ordinary `cd` persists from one Bash call to the next. Verified against the
11
+ * 2.1.226 binary, where the variable also appears in the settings-`env` allowlist beside
12
+ * `BASH_DEFAULT_TIMEOUT_MS` — which is what makes `.claude/settings.json` → `env` a supported home for
13
+ * it rather than a guess.
14
+ *
15
+ * WHY WEBPIECES MANAGES IT — it is VERDICT STABILITY, not ergonomics:
16
+ *
17
+ * 1. A guard's answer must not depend on where an earlier, unrelated command left the shell. Every
18
+ * location guard reasons about the tree a call acts on; with the cwd pinned, that is a function of
19
+ * the COMMAND alone rather than of session history. Same command, same verdict, every time.
20
+ * 2. Settings `env` is INHERITED, so the main agent and every subagent it spawns share one cwd — and
21
+ * therefore one verdict — instead of each carrying whatever `cd` happened earlier in its own
22
+ * session. Consistency across agents is the point, and it is why this lives in settings rather
23
+ * than in a shell profile.
24
+ * 3. It mechanically enforces the long-standing "do not `cd` into a sub-package and leave the shell
25
+ * there" rule, rather than relying on an agent remembering it.
26
+ *
27
+ * WHAT IT NO LONGER HAS TO DO. This entry was originally justified by hook RESOLUTION: the guard hooks
28
+ * were registered RELATIVE, a relative hook that cannot resolve exits 127 (a NON-BLOCKING error, i.e. a
29
+ * SILENT UNGUARDED ALLOW), and pinning the cwd kept them resolvable. That job is gone — both hooks are
30
+ * registered ABSOLUTE via `$CLAUDE_PROJECT_DIR` now, so they resolve from any cwd by construction and
31
+ * the L-1 hook that policed the same hazard is deleted. The reasons above are what remain, and they are
32
+ * sufficient on their own; the entry is NOT load-bearing for guard integrity any more.
33
+ *
34
+ * THE TRADE, said out loud: with the flag ON the cwd reset is SILENT and UNCONDITIONAL, where without
35
+ * it the reset is conditional and prints a notice. A deliberate `cd` therefore no longer persists
36
+ * across Bash calls. That is the intended cost of (1) and (2), not an oversight — chain into the
37
+ * directory you need (`cd <dir> && <cmd>`) instead of relying on a sticky cwd.
38
+ *
39
+ * ONE spelling, one required value: the entry is either exactly `1` or it is drift. There is no
40
+ * "accepted alternative truthy value" and no legacy key — `envStale()` in hook-registration.ts is the
41
+ * whole contract, and `applyManagedEnv()` brings any other value (including a user-set `0`) to `1`.
42
+ *
43
+ * WHY THESE TWO CONSTANTS LIVE IN THEIR OWN MODULE: `shim.ts` names them in the fault-S deny text and
44
+ * `hook-registration.ts` owns the predicate that reads them, and hook-registration already imports
45
+ * shim. Defining them here — a leaf with no imports at all — keeps that graph acyclic while leaving
46
+ * exactly one definition of each, in the same way SHIM_MARKER lives in shim.ts.
47
+ */
48
+ exports.BASH_CWD_ENV_KEY = 'CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR';
49
+ exports.BASH_CWD_ENV_VALUE = '1';
50
+ //# sourceMappingURL=managed-env.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"managed-env.js","sourceRoot":"","sources":["../../../../../../packages/tooling/agent-workflow-rules/src/bin/managed-env.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACU,QAAA,gBAAgB,GAAG,0CAA0C,CAAC;AAC9D,QAAA,kBAAkB,GAAG,GAAG,CAAC","sourcesContent":["/**\n * THE MANAGED `env` ENTRY — `CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR=1`, the FOURTH managed surface.\n *\n * Claude Code reads this variable once per Bash tool call and, when it is truthy, resets the shell's\n * cwd back to the project directory after EVERY call. With it unset, the reset is CONDITIONAL (only\n * when the cwd drifted to a dir that is not an allowed one) and prints a visible \"Shell cwd was reset\n * to …\" notice, so an ordinary `cd` persists from one Bash call to the next. Verified against the\n * 2.1.226 binary, where the variable also appears in the settings-`env` allowlist beside\n * `BASH_DEFAULT_TIMEOUT_MS` — which is what makes `.claude/settings.json` → `env` a supported home for\n * it rather than a guess.\n *\n * WHY WEBPIECES MANAGES IT — it is VERDICT STABILITY, not ergonomics:\n *\n * 1. A guard's answer must not depend on where an earlier, unrelated command left the shell. Every\n * location guard reasons about the tree a call acts on; with the cwd pinned, that is a function of\n * the COMMAND alone rather than of session history. Same command, same verdict, every time.\n * 2. Settings `env` is INHERITED, so the main agent and every subagent it spawns share one cwd — and\n * therefore one verdict — instead of each carrying whatever `cd` happened earlier in its own\n * session. Consistency across agents is the point, and it is why this lives in settings rather\n * than in a shell profile.\n * 3. It mechanically enforces the long-standing \"do not `cd` into a sub-package and leave the shell\n * there\" rule, rather than relying on an agent remembering it.\n *\n * WHAT IT NO LONGER HAS TO DO. This entry was originally justified by hook RESOLUTION: the guard hooks\n * were registered RELATIVE, a relative hook that cannot resolve exits 127 (a NON-BLOCKING error, i.e. a\n * SILENT UNGUARDED ALLOW), and pinning the cwd kept them resolvable. That job is gone — both hooks are\n * registered ABSOLUTE via `$CLAUDE_PROJECT_DIR` now, so they resolve from any cwd by construction and\n * the L-1 hook that policed the same hazard is deleted. The reasons above are what remain, and they are\n * sufficient on their own; the entry is NOT load-bearing for guard integrity any more.\n *\n * THE TRADE, said out loud: with the flag ON the cwd reset is SILENT and UNCONDITIONAL, where without\n * it the reset is conditional and prints a notice. A deliberate `cd` therefore no longer persists\n * across Bash calls. That is the intended cost of (1) and (2), not an oversight — chain into the\n * directory you need (`cd <dir> && <cmd>`) instead of relying on a sticky cwd.\n *\n * ONE spelling, one required value: the entry is either exactly `1` or it is drift. There is no\n * \"accepted alternative truthy value\" and no legacy key — `envStale()` in hook-registration.ts is the\n * whole contract, and `applyManagedEnv()` brings any other value (including a user-set `0`) to `1`.\n *\n * WHY THESE TWO CONSTANTS LIVE IN THEIR OWN MODULE: `shim.ts` names them in the fault-S deny text and\n * `hook-registration.ts` owns the predicate that reads them, and hook-registration already imports\n * shim. Defining them here — a leaf with no imports at all — keeps that graph acyclic while leaving\n * exactly one definition of each, in the same way SHIM_MARKER lives in shim.ts.\n */\nexport const BASH_CWD_ENV_KEY = 'CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR';\nexport const BASH_CWD_ENV_VALUE = '1';\n"]}
@@ -0,0 +1,42 @@
1
+ import type { ClaudeSettings } from './settings-shape';
2
+ /**
3
+ * How a drifted NEIGHBOUR surface is spelled, and the ONE place that spelling lives.
4
+ *
5
+ * `HarnessRegistration.neighbourSurface` builds a name ending in this, and the fault-S deny tests the
6
+ * drift list against it to decide whether to spend a line teaching this failure mode. Two literals would
7
+ * be two spellings of one thing: the deny would go quietly wrong — printing nothing for the one surface
8
+ * it exists to explain — with no test able to see it.
9
+ */
10
+ export declare const NEIGHBOUR_SURFACE_SUFFIX = "relative hook commands";
11
+ /**
12
+ * Rewrites the repo-relative entry paths in ONE hook command to `<anchor>/<path>`.
13
+ *
14
+ * `anchor` is the harness's own — `$CLAUDE_PROJECT_DIR` for Claude Code, `$PWD` for Codex — so a
15
+ * neighbour hook is anchored exactly the way webpieces anchors its own, and the MAIN tree governs every
16
+ * tree for the consumer's guards too.
17
+ */
18
+ export declare class NeighbourHookAnchor {
19
+ private readonly anchor;
20
+ private readonly root;
21
+ constructor(anchor: string, root: string);
22
+ /** The command with every anchorable token anchored; returns the input unchanged when there is none. */
23
+ rewrite(command: string): string;
24
+ /** The anchored spelling of one token, or null when this token must be left exactly as it is. */
25
+ private anchorToken;
26
+ }
27
+ /**
28
+ * Anchor every neighbour hook command IN PLACE; returns the NEW spelling of each one that changed.
29
+ *
30
+ * The return value is the rewritten commands rather than a boolean so the cure can print what it did to
31
+ * a file it does not own. A cure that silently edits a consumer's own hook lines is worse than one that
32
+ * does not edit them at all.
33
+ */
34
+ export declare function anchorNeighbourHooks(anchor: string, settings: ClaudeSettings, root: string): readonly string[];
35
+ /**
36
+ * True when this settings file carries a neighbour hook the repair WOULD anchor.
37
+ *
38
+ * Gated on `registeredBins()` by its caller for the same reason `registrationStale()` is: a settings
39
+ * file that registers no webpieces hooks is not a webpieces install, and rewriting somebody's unrelated
40
+ * hooks in it would be webpieces editing a file it was never given.
41
+ */
42
+ export declare function neighbourHooksStale(anchor: string, settings: ClaudeSettings, root: string): boolean;
@@ -0,0 +1,177 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NeighbourHookAnchor = exports.NEIGHBOUR_SURFACE_SUFFIX = void 0;
4
+ exports.anchorNeighbourHooks = anchorNeighbourHooks;
5
+ exports.neighbourHooksStale = neighbourHooksStale;
6
+ const tslib_1 = require("tslib");
7
+ const fs = tslib_1.__importStar(require("fs"));
8
+ const path = tslib_1.__importStar(require("path"));
9
+ const shim_1 = require("./shim");
10
+ /**
11
+ * NEIGHBOUR HOOKS — the hooks a CONSUMER repo registers in the SAME settings file webpieces manages,
12
+ * and the one thing about them webpieces must own: their entry path has to be ABSOLUTE.
13
+ *
14
+ * ─── The defect (issue #852, MEASURED in a consumer repo) ─────────────────────────────────────────
15
+ * A repo registered five of its own guards RELATIVE, beside webpieces' one absolute entry:
16
+ *
17
+ * { "type": "command", "command": "node \".claude/hooks/guard-deploy.mjs\"" }
18
+ *
19
+ * A relative entry path resolves against the HOOK PROCESS's cwd. The moment that cwd is not the repo
20
+ * root, node cannot resolve the entry module and the guard dies before running a line:
21
+ *
22
+ * $ cd <repo>/services && echo '{}' | node ".claude/hooks/guard-deploy.mjs"
23
+ * Error: Cannot find module '<repo>/services/.claude/hooks/guard-deploy.mjs'
24
+ *
25
+ * Per the hooks reference that non-zero exit is a NON-BLOCKING error — a SILENT UNGUARDED ALLOW. So
26
+ * every Bash call printed five `PreToolUse:Bash hook error` stack-trace fragments, carrying no rule
27
+ * name and no verdict, and then RAN ANYWAY. The guards that stopped running were the security ones: a
28
+ * cleartext-credentials blocker, a `gcloud` blocker (the CLI ignores GOOGLE_APPLICATION_CREDENTIALS and
29
+ * would otherwise run as the developer's OWNER account) and a raw-deploy blocker. That is the exact
30
+ * inverse of the fail-closed property those guards are documented to have.
31
+ *
32
+ * ─── Why webpieces owns the fix rather than the consumer ──────────────────────────────────────────
33
+ * 1. The consumer is told `.claude/settings.json` is GENERATED and must never be hand-edited, so it
34
+ * cannot fix its own registration without fighting `wp-upgrade-shim` on the next bump.
35
+ * 2. webpieces already learned this lesson for its OWN hook — the relative→absolute reversal documented
36
+ * at length in hook-registration.ts's header, which cost an entire guard layer (L-1) before it was
37
+ * reversed. That reasoning was never extended to the entries co-registered beside it, and the
38
+ * failure mode is identical because it is a property of the FILE, not of who wrote the line.
39
+ *
40
+ * ─── The conservative rule, and why the cure always converges ─────────────────────────────────────
41
+ * A token is anchored ONLY when every one of these holds: it is not already absolute, variable-anchored
42
+ * or `~`-anchored; it contains a `/`; it does not escape the root with `..`; and — the load-bearing
43
+ * one — `<root>/<token>` EXISTS ON DISK. That last test is what keeps `npm run build/foo` and every
44
+ * other slash-carrying non-path untouched, and it is why drift is defined as "the repair would change
45
+ * something" rather than "a relative-looking token is present": a token this module declines to anchor
46
+ * never becomes drift, so fault S can never name a surface its own cure cannot repair.
47
+ *
48
+ * This is deliberately NOT a second spelling of the managed registration. Anything under the managed
49
+ * directory — `MANAGED_DIR`, derived below from `SHIM_MARKER` itself rather than re-spelled — is skipped
50
+ * here, so every webpieces-owned command is left to `repairRegistration()`, which is the ONE place their
51
+ * spelling is defined. The test is the DIRECTORY and not `isManagedCommand()`: this module holds no edge
52
+ * back to hook-registration.ts, precisely so the file-import cycle stays broken.
53
+ */
54
+ /**
55
+ * The webpieces-MANAGED directory, derived from the shim's own path so there is never a second spelling
56
+ * of it. Everything under it is rewritten wholesale by `repairRegistration()`, which is the ONE place
57
+ * the managed commands' shape is defined — anchoring a token there from here would be a second spelling
58
+ * of one registration, exactly the shim shape the compatibility policy rejects.
59
+ */
60
+ const MANAGED_DIR = `${shim_1.SHIM_MARKER.slice(0, shim_1.SHIM_MARKER.lastIndexOf('/'))}/`;
61
+ /**
62
+ * How a drifted NEIGHBOUR surface is spelled, and the ONE place that spelling lives.
63
+ *
64
+ * `HarnessRegistration.neighbourSurface` builds a name ending in this, and the fault-S deny tests the
65
+ * drift list against it to decide whether to spend a line teaching this failure mode. Two literals would
66
+ * be two spellings of one thing: the deny would go quietly wrong — printing nothing for the one surface
67
+ * it exists to explain — with no test able to see it.
68
+ */
69
+ exports.NEIGHBOUR_SURFACE_SUFFIX = 'relative hook commands';
70
+ /** A token that is already anchored (absolute, `$VAR`, `~`) or is a flag — never a relative entry path. */
71
+ const ALREADY_ANCHORED = /^[/~$-]/;
72
+ /** Quoted-or-bare token scan. Quotes are tried first so a quoted path is one token, not several. */
73
+ const COMMAND_TOKEN = /"([^"]*)"|'([^']*)'|(\S+)/g;
74
+ /**
75
+ * Rewrites the repo-relative entry paths in ONE hook command to `<anchor>/<path>`.
76
+ *
77
+ * `anchor` is the harness's own — `$CLAUDE_PROJECT_DIR` for Claude Code, `$PWD` for Codex — so a
78
+ * neighbour hook is anchored exactly the way webpieces anchors its own, and the MAIN tree governs every
79
+ * tree for the consumer's guards too.
80
+ */
81
+ class NeighbourHookAnchor {
82
+ anchor;
83
+ root;
84
+ constructor(anchor, root) {
85
+ this.anchor = anchor;
86
+ this.root = root;
87
+ }
88
+ /** The command with every anchorable token anchored; returns the input unchanged when there is none. */
89
+ rewrite(command) {
90
+ return command.replace(COMMAND_TOKEN, (whole, dq, sq, bare) => {
91
+ const token = dq ?? sq ?? bare ?? '';
92
+ const anchored = this.anchorToken(token);
93
+ if (anchored === null)
94
+ return whole;
95
+ if (sq !== undefined)
96
+ return `'${anchored}'`;
97
+ // A bare token is QUOTED on the way out, not left bare: the anchor expands to a real
98
+ // filesystem path, and a checkout under a directory with a space in it would otherwise be
99
+ // split into two arguments — which fails exactly as silently as the bug being fixed.
100
+ return `"${anchored}"`;
101
+ });
102
+ }
103
+ /** The anchored spelling of one token, or null when this token must be left exactly as it is. */
104
+ anchorToken(token) {
105
+ if (token === '' || ALREADY_ANCHORED.test(token))
106
+ return null;
107
+ if (!token.includes('/') || token.includes('$') || token.includes('~'))
108
+ return null;
109
+ const rel = token.startsWith('./') ? token.slice(2) : token;
110
+ // `..` escapes the root, so the anchor would not name what the author meant. Leave it and let
111
+ // the drift check stay silent about it — a surface the cure cannot repair must never be reported.
112
+ if (rel === '' || rel.startsWith('../') || rel.startsWith(MANAGED_DIR))
113
+ return null;
114
+ if (!fs.existsSync(path.join(this.root, ...rel.split('/'))))
115
+ return null;
116
+ return `${this.anchor}/${rel}`;
117
+ }
118
+ }
119
+ exports.NeighbourHookAnchor = NeighbourHookAnchor;
120
+ /**
121
+ * Every hook entry in a settings file, across EVERY event (PreToolUse, PostToolUse, Stop, …).
122
+ *
123
+ * Not scoped to PreToolUse, because the defect is not: a `PostToolUse` hook registered relative dies the
124
+ * same way from the same cwd, and scoping the repair to one event would leave a half-fixed file that
125
+ * reports success — the failure shape upgrade-shim.ts's header exists to prevent.
126
+ */
127
+ // webpieces-disable no-function-outside-class -- module-scope sibling of hook-registration.ts's readers, in the deliberately dependency-free bin layer
128
+ function allHookCommands(settings) {
129
+ const events = settings.hooks;
130
+ if (events === undefined)
131
+ return [];
132
+ const found = [];
133
+ for (const entries of Object.values(events)) {
134
+ if (!Array.isArray(entries))
135
+ continue;
136
+ for (const entry of entries) {
137
+ if (Array.isArray(entry.hooks))
138
+ found.push(...entry.hooks);
139
+ }
140
+ }
141
+ return found;
142
+ }
143
+ /**
144
+ * Anchor every neighbour hook command IN PLACE; returns the NEW spelling of each one that changed.
145
+ *
146
+ * The return value is the rewritten commands rather than a boolean so the cure can print what it did to
147
+ * a file it does not own. A cure that silently edits a consumer's own hook lines is worse than one that
148
+ * does not edit them at all.
149
+ */
150
+ // webpieces-disable no-function-outside-class -- module-scope sibling of hook-registration.ts's repairs, in the deliberately dependency-free bin layer
151
+ function anchorNeighbourHooks(anchor, settings, root) {
152
+ const anchorer = new NeighbourHookAnchor(anchor, root);
153
+ const rewritten = [];
154
+ for (const hook of allHookCommands(settings)) {
155
+ if (typeof hook.command !== 'string')
156
+ continue;
157
+ const anchored = anchorer.rewrite(hook.command);
158
+ if (anchored === hook.command)
159
+ continue;
160
+ hook.command = anchored;
161
+ rewritten.push(anchored);
162
+ }
163
+ return rewritten;
164
+ }
165
+ /**
166
+ * True when this settings file carries a neighbour hook the repair WOULD anchor.
167
+ *
168
+ * Gated on `registeredBins()` by its caller for the same reason `registrationStale()` is: a settings
169
+ * file that registers no webpieces hooks is not a webpieces install, and rewriting somebody's unrelated
170
+ * hooks in it would be webpieces editing a file it was never given.
171
+ */
172
+ // webpieces-disable no-function-outside-class -- module-scope sibling of hook-registration.ts's drift checks, in the deliberately dependency-free bin layer
173
+ function neighbourHooksStale(anchor, settings, root) {
174
+ const anchorer = new NeighbourHookAnchor(anchor, root);
175
+ return allHookCommands(settings).some((h) => typeof h.command === 'string' && anchorer.rewrite(h.command) !== h.command);
176
+ }
177
+ //# sourceMappingURL=neighbour-hooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"neighbour-hooks.js","sourceRoot":"","sources":["../../../../../../packages/tooling/agent-workflow-rules/src/bin/neighbour-hooks.ts"],"names":[],"mappings":"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","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\n\nimport { SHIM_MARKER } from './shim';\n// The SHAPE only, from the leaf module both this file and hook-registration.ts point at. This module\n// deliberately knows nothing about `HarnessRegistration`: it takes the harness's ANCHOR as a string, so\n// there is no edge back to hook-registration at all — not even a type-only one, which\n// `validate-no-file-import-cycles` counts as a cycle just the same.\nimport type { ClaudeSettings, HookCommand, HookEntry } from './settings-shape';\n\n/**\n * NEIGHBOUR HOOKS — the hooks a CONSUMER repo registers in the SAME settings file webpieces manages,\n * and the one thing about them webpieces must own: their entry path has to be ABSOLUTE.\n *\n * ─── The defect (issue #852, MEASURED in a consumer repo) ─────────────────────────────────────────\n * A repo registered five of its own guards RELATIVE, beside webpieces' one absolute entry:\n *\n * { \"type\": \"command\", \"command\": \"node \\\".claude/hooks/guard-deploy.mjs\\\"\" }\n *\n * A relative entry path resolves against the HOOK PROCESS's cwd. The moment that cwd is not the repo\n * root, node cannot resolve the entry module and the guard dies before running a line:\n *\n * $ cd <repo>/services && echo '{}' | node \".claude/hooks/guard-deploy.mjs\"\n * Error: Cannot find module '<repo>/services/.claude/hooks/guard-deploy.mjs'\n *\n * Per the hooks reference that non-zero exit is a NON-BLOCKING error — a SILENT UNGUARDED ALLOW. So\n * every Bash call printed five `PreToolUse:Bash hook error` stack-trace fragments, carrying no rule\n * name and no verdict, and then RAN ANYWAY. The guards that stopped running were the security ones: a\n * cleartext-credentials blocker, a `gcloud` blocker (the CLI ignores GOOGLE_APPLICATION_CREDENTIALS and\n * would otherwise run as the developer's OWNER account) and a raw-deploy blocker. That is the exact\n * inverse of the fail-closed property those guards are documented to have.\n *\n * ─── Why webpieces owns the fix rather than the consumer ──────────────────────────────────────────\n * 1. The consumer is told `.claude/settings.json` is GENERATED and must never be hand-edited, so it\n * cannot fix its own registration without fighting `wp-upgrade-shim` on the next bump.\n * 2. webpieces already learned this lesson for its OWN hook — the relative→absolute reversal documented\n * at length in hook-registration.ts's header, which cost an entire guard layer (L-1) before it was\n * reversed. That reasoning was never extended to the entries co-registered beside it, and the\n * failure mode is identical because it is a property of the FILE, not of who wrote the line.\n *\n * ─── The conservative rule, and why the cure always converges ─────────────────────────────────────\n * A token is anchored ONLY when every one of these holds: it is not already absolute, variable-anchored\n * or `~`-anchored; it contains a `/`; it does not escape the root with `..`; and — the load-bearing\n * one — `<root>/<token>` EXISTS ON DISK. That last test is what keeps `npm run build/foo` and every\n * other slash-carrying non-path untouched, and it is why drift is defined as \"the repair would change\n * something\" rather than \"a relative-looking token is present\": a token this module declines to anchor\n * never becomes drift, so fault S can never name a surface its own cure cannot repair.\n *\n * This is deliberately NOT a second spelling of the managed registration. Anything under the managed\n * directory — `MANAGED_DIR`, derived below from `SHIM_MARKER` itself rather than re-spelled — is skipped\n * here, so every webpieces-owned command is left to `repairRegistration()`, which is the ONE place their\n * spelling is defined. The test is the DIRECTORY and not `isManagedCommand()`: this module holds no edge\n * back to hook-registration.ts, precisely so the file-import cycle stays broken.\n */\n\n/**\n * The webpieces-MANAGED directory, derived from the shim's own path so there is never a second spelling\n * of it. Everything under it is rewritten wholesale by `repairRegistration()`, which is the ONE place\n * the managed commands' shape is defined — anchoring a token there from here would be a second spelling\n * of one registration, exactly the shim shape the compatibility policy rejects.\n */\nconst MANAGED_DIR = `${SHIM_MARKER.slice(0, SHIM_MARKER.lastIndexOf('/'))}/`;\n\n/**\n * How a drifted NEIGHBOUR surface is spelled, and the ONE place that spelling lives.\n *\n * `HarnessRegistration.neighbourSurface` builds a name ending in this, and the fault-S deny tests the\n * drift list against it to decide whether to spend a line teaching this failure mode. Two literals would\n * be two spellings of one thing: the deny would go quietly wrong — printing nothing for the one surface\n * it exists to explain — with no test able to see it.\n */\nexport const NEIGHBOUR_SURFACE_SUFFIX = 'relative hook commands';\n\n/** A token that is already anchored (absolute, `$VAR`, `~`) or is a flag — never a relative entry path. */\nconst ALREADY_ANCHORED = /^[/~$-]/;\n\n/** Quoted-or-bare token scan. Quotes are tried first so a quoted path is one token, not several. */\nconst COMMAND_TOKEN = /\"([^\"]*)\"|'([^']*)'|(\\S+)/g;\n\n/**\n * Rewrites the repo-relative entry paths in ONE hook command to `<anchor>/<path>`.\n *\n * `anchor` is the harness's own — `$CLAUDE_PROJECT_DIR` for Claude Code, `$PWD` for Codex — so a\n * neighbour hook is anchored exactly the way webpieces anchors its own, and the MAIN tree governs every\n * tree for the consumer's guards too.\n */\nexport class NeighbourHookAnchor {\n constructor(\n private readonly anchor: string,\n private readonly root: string,\n ) {}\n\n /** The command with every anchorable token anchored; returns the input unchanged when there is none. */\n rewrite(command: string): string {\n return command.replace(COMMAND_TOKEN, (whole: string, dq?: string, sq?: string, bare?: string): string => {\n const token = dq ?? sq ?? bare ?? '';\n const anchored = this.anchorToken(token);\n if (anchored === null) return whole;\n if (sq !== undefined) return `'${anchored}'`;\n // A bare token is QUOTED on the way out, not left bare: the anchor expands to a real\n // filesystem path, and a checkout under a directory with a space in it would otherwise be\n // split into two arguments — which fails exactly as silently as the bug being fixed.\n return `\"${anchored}\"`;\n });\n }\n\n /** The anchored spelling of one token, or null when this token must be left exactly as it is. */\n private anchorToken(token: string): string | null {\n if (token === '' || ALREADY_ANCHORED.test(token)) return null;\n if (!token.includes('/') || token.includes('$') || token.includes('~')) return null;\n const rel = token.startsWith('./') ? token.slice(2) : token;\n // `..` escapes the root, so the anchor would not name what the author meant. Leave it and let\n // the drift check stay silent about it — a surface the cure cannot repair must never be reported.\n if (rel === '' || rel.startsWith('../') || rel.startsWith(MANAGED_DIR)) return null;\n if (!fs.existsSync(path.join(this.root, ...rel.split('/')))) return null;\n return `${this.anchor}/${rel}`;\n }\n}\n\n/**\n * Every hook entry in a settings file, across EVERY event (PreToolUse, PostToolUse, Stop, …).\n *\n * Not scoped to PreToolUse, because the defect is not: a `PostToolUse` hook registered relative dies the\n * same way from the same cwd, and scoping the repair to one event would leave a half-fixed file that\n * reports success — the failure shape upgrade-shim.ts's header exists to prevent.\n */\n// webpieces-disable no-function-outside-class -- module-scope sibling of hook-registration.ts's readers, in the deliberately dependency-free bin layer\nfunction allHookCommands(settings: ClaudeSettings): readonly HookCommand[] {\n const events = settings.hooks;\n if (events === undefined) return [];\n const found: HookCommand[] = [];\n for (const entries of Object.values(events)) {\n if (!Array.isArray(entries)) continue;\n for (const entry of entries as readonly HookEntry[]) {\n if (Array.isArray(entry.hooks)) found.push(...entry.hooks);\n }\n }\n return found;\n}\n\n/**\n * Anchor every neighbour hook command IN PLACE; returns the NEW spelling of each one that changed.\n *\n * The return value is the rewritten commands rather than a boolean so the cure can print what it did to\n * a file it does not own. A cure that silently edits a consumer's own hook lines is worse than one that\n * does not edit them at all.\n */\n// webpieces-disable no-function-outside-class -- module-scope sibling of hook-registration.ts's repairs, in the deliberately dependency-free bin layer\nexport function anchorNeighbourHooks(anchor: string, settings: ClaudeSettings, root: string): readonly string[] {\n const anchorer = new NeighbourHookAnchor(anchor, root);\n const rewritten: string[] = [];\n for (const hook of allHookCommands(settings)) {\n if (typeof hook.command !== 'string') continue;\n const anchored = anchorer.rewrite(hook.command);\n if (anchored === hook.command) continue;\n hook.command = anchored;\n rewritten.push(anchored);\n }\n return rewritten;\n}\n\n/**\n * True when this settings file carries a neighbour hook the repair WOULD anchor.\n *\n * Gated on `registeredBins()` by its caller for the same reason `registrationStale()` is: a settings\n * file that registers no webpieces hooks is not a webpieces install, and rewriting somebody's unrelated\n * hooks in it would be webpieces editing a file it was never given.\n */\n// webpieces-disable no-function-outside-class -- module-scope sibling of hook-registration.ts's drift checks, in the deliberately dependency-free bin layer\nexport function neighbourHooksStale(anchor: string, settings: ClaudeSettings, root: string): boolean {\n const anchorer = new NeighbourHookAnchor(anchor, root);\n return allHookCommands(settings).some((h: HookCommand): boolean => typeof h.command === 'string' && anchorer.rewrite(h.command) !== h.command);\n}\n"]}
@@ -0,0 +1,19 @@
1
+ /** The agent type this file registers — the reviewer every repo gets unless it sets `overrideReviewerAgent`. */
2
+ export declare const REVIEWER_AGENT_NAME = "webpieces-reviewer";
3
+ /** The committed file, repo-relative — also the name the drift check reports it under. */
4
+ export declare const REVIEWER_AGENT_MARKER = ".claude/agents/webpieces-reviewer.md";
5
+ /** The copy that ships in the package, byte-identical to renderReviewerAgent() (locked by a unit test). */
6
+ export declare const REVIEWER_AGENT_TEMPLATE = "webpieces-reviewer.md";
7
+ export declare function reviewerAgentPath(projectRoot: string): string;
8
+ export declare function renderReviewerAgent(): string;
9
+ /**
10
+ * True when this tree is webpieces-hooked (its committed shim exists) and the reviewer agent is MISSING or
11
+ * differs from renderReviewerAgent(). Gated on the shim for the same reason `committedShimStale` is gated
12
+ * on its own file: a tree webpieces never installed into has no managed surface to police.
13
+ */
14
+ export declare function reviewerAgentStale(root: string | null): boolean;
15
+ /**
16
+ * Write the reviewer agent under `root`, returning true when the file changed. Creates `.claude/agents/`
17
+ * when it is absent — that directory is what a Claude Code session scans for agent types.
18
+ */
19
+ export declare function writeReviewerAgent(root: string): boolean;