@memnexus-ai/mx-agent-cli 0.1.294-next.0 → 0.1.295-next.0

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 (450) hide show
  1. package/dist/__tests__/agents-md-canonicalization.test.js +31 -1
  2. package/dist/__tests__/agents-md-canonicalization.test.js.map +1 -1
  3. package/dist/__tests__/behavioral-extraction.test.js +50 -0
  4. package/dist/__tests__/behavioral-extraction.test.js.map +1 -1
  5. package/dist/__tests__/bootstrap-behavioral-contract.test.js +6 -3
  6. package/dist/__tests__/bootstrap-behavioral-contract.test.js.map +1 -1
  7. package/dist/__tests__/bundle-config.test.js +28 -2
  8. package/dist/__tests__/bundle-config.test.js.map +1 -1
  9. package/dist/__tests__/catalog-interaction.test.d.ts +25 -0
  10. package/dist/__tests__/catalog-interaction.test.d.ts.map +1 -0
  11. package/dist/__tests__/catalog-interaction.test.js +269 -0
  12. package/dist/__tests__/catalog-interaction.test.js.map +1 -0
  13. package/dist/__tests__/catalog-named-memories.test.d.ts +2 -0
  14. package/dist/__tests__/catalog-named-memories.test.d.ts.map +1 -0
  15. package/dist/__tests__/catalog-named-memories.test.js +204 -0
  16. package/dist/__tests__/catalog-named-memories.test.js.map +1 -0
  17. package/dist/__tests__/catalog-origin-main.test.d.ts +15 -0
  18. package/dist/__tests__/catalog-origin-main.test.d.ts.map +1 -0
  19. package/dist/__tests__/catalog-origin-main.test.js +296 -0
  20. package/dist/__tests__/catalog-origin-main.test.js.map +1 -0
  21. package/dist/__tests__/catalog.test.d.ts +2 -0
  22. package/dist/__tests__/catalog.test.d.ts.map +1 -0
  23. package/dist/__tests__/catalog.test.js +131 -0
  24. package/dist/__tests__/catalog.test.js.map +1 -0
  25. package/dist/__tests__/cli-build-integration.test.d.ts +2 -0
  26. package/dist/__tests__/cli-build-integration.test.d.ts.map +1 -0
  27. package/dist/__tests__/cli-build-integration.test.js +64 -0
  28. package/dist/__tests__/cli-build-integration.test.js.map +1 -0
  29. package/dist/__tests__/cli-build.test.d.ts +2 -0
  30. package/dist/__tests__/cli-build.test.d.ts.map +1 -0
  31. package/dist/__tests__/cli-build.test.js +640 -0
  32. package/dist/__tests__/cli-build.test.js.map +1 -0
  33. package/dist/__tests__/codex-deploy-config.test.js +60 -0
  34. package/dist/__tests__/codex-deploy-config.test.js.map +1 -1
  35. package/dist/__tests__/completion-rows-discriminate.test.d.ts +20 -0
  36. package/dist/__tests__/completion-rows-discriminate.test.d.ts.map +1 -0
  37. package/dist/__tests__/completion-rows-discriminate.test.js +481 -0
  38. package/dist/__tests__/completion-rows-discriminate.test.js.map +1 -0
  39. package/dist/__tests__/config-fidelity-archived-symlinks.test.d.ts +2 -0
  40. package/dist/__tests__/config-fidelity-archived-symlinks.test.d.ts.map +1 -0
  41. package/dist/__tests__/config-fidelity-archived-symlinks.test.js +127 -0
  42. package/dist/__tests__/config-fidelity-archived-symlinks.test.js.map +1 -0
  43. package/dist/__tests__/config-fidelity-display.test.d.ts +2 -0
  44. package/dist/__tests__/config-fidelity-display.test.d.ts.map +1 -0
  45. package/dist/__tests__/config-fidelity-display.test.js +77 -0
  46. package/dist/__tests__/config-fidelity-display.test.js.map +1 -0
  47. package/dist/__tests__/config-fidelity.test.js +166 -33
  48. package/dist/__tests__/config-fidelity.test.js.map +1 -1
  49. package/dist/__tests__/config-generation-gate.test.js +78 -0
  50. package/dist/__tests__/config-generation-gate.test.js.map +1 -1
  51. package/dist/__tests__/config-sync.test.js +35 -0
  52. package/dist/__tests__/config-sync.test.js.map +1 -1
  53. package/dist/__tests__/coordination-401-production-wiring.test.js +12 -7
  54. package/dist/__tests__/coordination-401-production-wiring.test.js.map +1 -1
  55. package/dist/__tests__/coordination-401-recovery.test.js +39 -32
  56. package/dist/__tests__/coordination-401-recovery.test.js.map +1 -1
  57. package/dist/__tests__/coordination-brief-pin.test.js +21 -8
  58. package/dist/__tests__/coordination-brief-pin.test.js.map +1 -1
  59. package/dist/__tests__/coordination-client.test.js +227 -3
  60. package/dist/__tests__/coordination-client.test.js.map +1 -1
  61. package/dist/__tests__/coordination-credential-endpoint.test.d.ts +24 -0
  62. package/dist/__tests__/coordination-credential-endpoint.test.d.ts.map +1 -0
  63. package/dist/__tests__/coordination-credential-endpoint.test.js +1230 -0
  64. package/dist/__tests__/coordination-credential-endpoint.test.js.map +1 -0
  65. package/dist/__tests__/coordination-memory.test.js +20 -4
  66. package/dist/__tests__/coordination-memory.test.js.map +1 -1
  67. package/dist/__tests__/coordination-provision.test.js +22 -14
  68. package/dist/__tests__/coordination-provision.test.js.map +1 -1
  69. package/dist/__tests__/coordination-status-registration.test.d.ts +16 -0
  70. package/dist/__tests__/coordination-status-registration.test.d.ts.map +1 -0
  71. package/dist/__tests__/coordination-status-registration.test.js +480 -0
  72. package/dist/__tests__/coordination-status-registration.test.js.map +1 -0
  73. package/dist/__tests__/coordination-token-multitenant.test.js +11 -11
  74. package/dist/__tests__/coordination-token-multitenant.test.js.map +1 -1
  75. package/dist/__tests__/coordination-token.test.js +35 -28
  76. package/dist/__tests__/coordination-token.test.js.map +1 -1
  77. package/dist/__tests__/creation-pr-class-check.test.d.ts +17 -0
  78. package/dist/__tests__/creation-pr-class-check.test.d.ts.map +1 -0
  79. package/dist/__tests__/creation-pr-class-check.test.js +346 -0
  80. package/dist/__tests__/creation-pr-class-check.test.js.map +1 -0
  81. package/dist/__tests__/digest-team-omission.test.d.ts +15 -0
  82. package/dist/__tests__/digest-team-omission.test.d.ts.map +1 -0
  83. package/dist/__tests__/digest-team-omission.test.js +247 -0
  84. package/dist/__tests__/digest-team-omission.test.js.map +1 -0
  85. package/dist/__tests__/doctor-worktree-path.test.d.ts +17 -0
  86. package/dist/__tests__/doctor-worktree-path.test.d.ts.map +1 -0
  87. package/dist/__tests__/doctor-worktree-path.test.js +158 -0
  88. package/dist/__tests__/doctor-worktree-path.test.js.map +1 -0
  89. package/dist/__tests__/fleet-data.test.js +40 -7
  90. package/dist/__tests__/fleet-data.test.js.map +1 -1
  91. package/dist/__tests__/fleet-tmux.test.js +2 -2
  92. package/dist/__tests__/fleet-tmux.test.js.map +1 -1
  93. package/dist/__tests__/generate-claude.test.js +137 -3
  94. package/dist/__tests__/generate-claude.test.js.map +1 -1
  95. package/dist/__tests__/git-env.test.d.ts +14 -0
  96. package/dist/__tests__/git-env.test.d.ts.map +1 -0
  97. package/dist/__tests__/git-env.test.js +131 -0
  98. package/dist/__tests__/git-env.test.js.map +1 -0
  99. package/dist/__tests__/git-identity-isolation.test.d.ts +33 -0
  100. package/dist/__tests__/git-identity-isolation.test.d.ts.map +1 -0
  101. package/dist/__tests__/git-identity-isolation.test.js +626 -0
  102. package/dist/__tests__/git-identity-isolation.test.js.map +1 -0
  103. package/dist/__tests__/hook-heal.test.js +17 -0
  104. package/dist/__tests__/hook-heal.test.js.map +1 -1
  105. package/dist/__tests__/init-coordination-url.test.d.ts +11 -0
  106. package/dist/__tests__/init-coordination-url.test.d.ts.map +1 -0
  107. package/dist/__tests__/init-coordination-url.test.js +114 -0
  108. package/dist/__tests__/init-coordination-url.test.js.map +1 -0
  109. package/dist/__tests__/memory-autocreate.test.js +574 -8
  110. package/dist/__tests__/memory-autocreate.test.js.map +1 -1
  111. package/dist/__tests__/memory-log-result.test.d.ts +13 -0
  112. package/dist/__tests__/memory-log-result.test.d.ts.map +1 -0
  113. package/dist/__tests__/memory-log-result.test.js +113 -0
  114. package/dist/__tests__/memory-log-result.test.js.map +1 -0
  115. package/dist/__tests__/memory-named-exists.test.d.ts +16 -0
  116. package/dist/__tests__/memory-named-exists.test.d.ts.map +1 -0
  117. package/dist/__tests__/memory-named-exists.test.js +288 -0
  118. package/dist/__tests__/memory-named-exists.test.js.map +1 -0
  119. package/dist/__tests__/mx-agent-cli-pin-validation.test.js +23 -47
  120. package/dist/__tests__/mx-agent-cli-pin-validation.test.js.map +1 -1
  121. package/dist/__tests__/mx-agent-cli-version-pin.test.js +34 -88
  122. package/dist/__tests__/mx-agent-cli-version-pin.test.js.map +1 -1
  123. package/dist/__tests__/new-project-first-team.test.d.ts +15 -0
  124. package/dist/__tests__/new-project-first-team.test.d.ts.map +1 -0
  125. package/dist/__tests__/new-project-first-team.test.js +263 -0
  126. package/dist/__tests__/new-project-first-team.test.js.map +1 -0
  127. package/dist/__tests__/otel-env.test.d.ts +2 -0
  128. package/dist/__tests__/otel-env.test.d.ts.map +1 -0
  129. package/dist/__tests__/otel-env.test.js +127 -0
  130. package/dist/__tests__/otel-env.test.js.map +1 -0
  131. package/dist/__tests__/project-config.test.js +283 -1
  132. package/dist/__tests__/project-config.test.js.map +1 -1
  133. package/dist/__tests__/provision-behavioral-contract.test.js +96 -4
  134. package/dist/__tests__/provision-behavioral-contract.test.js.map +1 -1
  135. package/dist/__tests__/provision-catalog-precondition.test.d.ts +26 -0
  136. package/dist/__tests__/provision-catalog-precondition.test.d.ts.map +1 -0
  137. package/dist/__tests__/provision-catalog-precondition.test.js +620 -0
  138. package/dist/__tests__/provision-catalog-precondition.test.js.map +1 -0
  139. package/dist/__tests__/provision-completion-rows.test.d.ts +17 -0
  140. package/dist/__tests__/provision-completion-rows.test.d.ts.map +1 -0
  141. package/dist/__tests__/provision-completion-rows.test.js +3095 -0
  142. package/dist/__tests__/provision-completion-rows.test.js.map +1 -0
  143. package/dist/__tests__/provision-identity-gate.test.d.ts +20 -0
  144. package/dist/__tests__/provision-identity-gate.test.d.ts.map +1 -0
  145. package/dist/__tests__/provision-identity-gate.test.js +600 -0
  146. package/dist/__tests__/provision-identity-gate.test.js.map +1 -0
  147. package/dist/__tests__/provision-resume.test.d.ts +26 -0
  148. package/dist/__tests__/provision-resume.test.d.ts.map +1 -0
  149. package/dist/__tests__/provision-resume.test.js +1164 -0
  150. package/dist/__tests__/provision-resume.test.js.map +1 -0
  151. package/dist/__tests__/provision-roleguide-anchors.test.d.ts +27 -0
  152. package/dist/__tests__/provision-roleguide-anchors.test.d.ts.map +1 -0
  153. package/dist/__tests__/provision-roleguide-anchors.test.js +747 -0
  154. package/dist/__tests__/provision-roleguide-anchors.test.js.map +1 -0
  155. package/dist/__tests__/provision-skeleton-fill.test.d.ts +16 -0
  156. package/dist/__tests__/provision-skeleton-fill.test.d.ts.map +1 -0
  157. package/dist/__tests__/provision-skeleton-fill.test.js +488 -0
  158. package/dist/__tests__/provision-skeleton-fill.test.js.map +1 -0
  159. package/dist/__tests__/provision-teambuilder-flow.test.js +93 -7
  160. package/dist/__tests__/provision-teambuilder-flow.test.js.map +1 -1
  161. package/dist/__tests__/repo-guard-wiring.test.d.ts +21 -0
  162. package/dist/__tests__/repo-guard-wiring.test.d.ts.map +1 -0
  163. package/dist/__tests__/repo-guard-wiring.test.js +638 -0
  164. package/dist/__tests__/repo-guard-wiring.test.js.map +1 -0
  165. package/dist/__tests__/runtime-codex-gateway-pilot.test.d.ts +2 -0
  166. package/dist/__tests__/runtime-codex-gateway-pilot.test.d.ts.map +1 -0
  167. package/dist/__tests__/runtime-codex-gateway-pilot.test.js +309 -0
  168. package/dist/__tests__/runtime-codex-gateway-pilot.test.js.map +1 -0
  169. package/dist/__tests__/runtime-codex-gateway-provider.test.d.ts +2 -0
  170. package/dist/__tests__/runtime-codex-gateway-provider.test.d.ts.map +1 -0
  171. package/dist/__tests__/runtime-codex-gateway-provider.test.js +163 -0
  172. package/dist/__tests__/runtime-codex-gateway-provider.test.js.map +1 -0
  173. package/dist/__tests__/runtime-identity.test.d.ts +2 -0
  174. package/dist/__tests__/runtime-identity.test.d.ts.map +1 -0
  175. package/dist/__tests__/runtime-identity.test.js +117 -0
  176. package/dist/__tests__/runtime-identity.test.js.map +1 -0
  177. package/dist/__tests__/session-pause-provisioning.test.js +6 -1
  178. package/dist/__tests__/session-pause-provisioning.test.js.map +1 -1
  179. package/dist/__tests__/session-record-disclosure.test.d.ts +24 -0
  180. package/dist/__tests__/session-record-disclosure.test.d.ts.map +1 -0
  181. package/dist/__tests__/session-record-disclosure.test.js +494 -0
  182. package/dist/__tests__/session-record-disclosure.test.js.map +1 -0
  183. package/dist/__tests__/session.test.js +35 -0
  184. package/dist/__tests__/session.test.js.map +1 -1
  185. package/dist/__tests__/slug-validation.test.js +27 -21
  186. package/dist/__tests__/slug-validation.test.js.map +1 -1
  187. package/dist/__tests__/standards-injection.test.js +23 -1
  188. package/dist/__tests__/standards-injection.test.js.map +1 -1
  189. package/dist/__tests__/start-interactive-role.test.d.ts +22 -0
  190. package/dist/__tests__/start-interactive-role.test.d.ts.map +1 -0
  191. package/dist/__tests__/start-interactive-role.test.js +204 -0
  192. package/dist/__tests__/start-interactive-role.test.js.map +1 -0
  193. package/dist/__tests__/start-team-identity.test.d.ts +25 -0
  194. package/dist/__tests__/start-team-identity.test.d.ts.map +1 -0
  195. package/dist/__tests__/start-team-identity.test.js +307 -0
  196. package/dist/__tests__/start-team-identity.test.js.map +1 -0
  197. package/dist/__tests__/team-memory-commands.test.js +142 -19
  198. package/dist/__tests__/team-memory-commands.test.js.map +1 -1
  199. package/dist/__tests__/template-sync.test.d.ts +19 -0
  200. package/dist/__tests__/template-sync.test.d.ts.map +1 -0
  201. package/dist/__tests__/template-sync.test.js +270 -0
  202. package/dist/__tests__/template-sync.test.js.map +1 -0
  203. package/dist/__tests__/test-project.test.d.ts +18 -0
  204. package/dist/__tests__/test-project.test.d.ts.map +1 -0
  205. package/dist/__tests__/test-project.test.js +465 -0
  206. package/dist/__tests__/test-project.test.js.map +1 -0
  207. package/dist/__tests__/usage-per-call-grouping.test.d.ts +25 -0
  208. package/dist/__tests__/usage-per-call-grouping.test.d.ts.map +1 -0
  209. package/dist/__tests__/usage-per-call-grouping.test.js +952 -0
  210. package/dist/__tests__/usage-per-call-grouping.test.js.map +1 -0
  211. package/dist/__tests__/verify-hooks-check-all.test.d.ts +32 -0
  212. package/dist/__tests__/verify-hooks-check-all.test.d.ts.map +1 -0
  213. package/dist/__tests__/verify-hooks-check-all.test.js +553 -0
  214. package/dist/__tests__/verify-hooks-check-all.test.js.map +1 -0
  215. package/dist/__tests__/worktree-sync-fixture.test.d.ts +17 -0
  216. package/dist/__tests__/worktree-sync-fixture.test.d.ts.map +1 -0
  217. package/dist/__tests__/worktree-sync-fixture.test.js +519 -0
  218. package/dist/__tests__/worktree-sync-fixture.test.js.map +1 -0
  219. package/dist/__tests__/worktree-sync-hardening.test.d.ts +13 -0
  220. package/dist/__tests__/worktree-sync-hardening.test.d.ts.map +1 -0
  221. package/dist/__tests__/worktree-sync-hardening.test.js +919 -0
  222. package/dist/__tests__/worktree-sync-hardening.test.js.map +1 -0
  223. package/dist/__tests__/worktree-sync-shell-free.test.d.ts +25 -0
  224. package/dist/__tests__/worktree-sync-shell-free.test.d.ts.map +1 -0
  225. package/dist/__tests__/worktree-sync-shell-free.test.js +185 -0
  226. package/dist/__tests__/worktree-sync-shell-free.test.js.map +1 -0
  227. package/dist/__tests__/worktree.test.js +75 -1
  228. package/dist/__tests__/worktree.test.js.map +1 -1
  229. package/dist/agent-config/.mx-config-generation.json +2 -2
  230. package/dist/agent-config/AGENTS.md.template +2 -2
  231. package/dist/agent-config/agents/bar-raiser.md +34 -1
  232. package/dist/agent-config/agents/red-team.md +34 -1
  233. package/dist/agent-config/agents/security-reviewer.md +22 -1
  234. package/dist/agent-config/claude-md/CLAUDE.core.md +6 -1
  235. package/dist/agent-config/claude-md/CLAUDE.overlay.memnexus.md +1 -3
  236. package/dist/agent-config/coordination-rosters.generated.json +10 -0
  237. package/dist/agent-config/hooks/HOOK-TIMEOUTS.md +27 -1
  238. package/dist/agent-config/hooks/OR-TRUE-AUDIT.md +8 -8
  239. package/dist/agent-config/hooks/auto-capture-precompact.sh +279 -0
  240. package/dist/agent-config/hooks/auto-capture-session-end.sh +277 -0
  241. package/dist/agent-config/hooks/coordination-brief.sh +290 -245
  242. package/dist/agent-config/hooks/deploy-verification-reminder.sh +359 -22
  243. package/dist/agent-config/hooks/git-mutation-guard.sh +85 -13
  244. package/dist/agent-config/hooks/session-idle-gate.sh +177 -12
  245. package/dist/agent-config/hooks/subagent-write-guard.sh +670 -0
  246. package/dist/agent-config/hooks/worktree-guard.sh +36 -7
  247. package/dist/agent-config/settings.json +15 -2
  248. package/dist/agent-config/shared/creation-pr-review-checklist.md +317 -0
  249. package/dist/commands/bootstrap.d.ts.map +1 -1
  250. package/dist/commands/bootstrap.js +22 -10
  251. package/dist/commands/bootstrap.js.map +1 -1
  252. package/dist/commands/config.d.ts.map +1 -1
  253. package/dist/commands/config.js +28 -1
  254. package/dist/commands/config.js.map +1 -1
  255. package/dist/commands/coordination.d.ts +150 -8
  256. package/dist/commands/coordination.d.ts.map +1 -1
  257. package/dist/commands/coordination.js +519 -25
  258. package/dist/commands/coordination.js.map +1 -1
  259. package/dist/commands/create.d.ts +913 -1
  260. package/dist/commands/create.d.ts.map +1 -1
  261. package/dist/commands/create.js +4879 -345
  262. package/dist/commands/create.js.map +1 -1
  263. package/dist/commands/digest.d.ts.map +1 -1
  264. package/dist/commands/digest.js +91 -7
  265. package/dist/commands/digest.js.map +1 -1
  266. package/dist/commands/fleet-tmux.js +1 -1
  267. package/dist/commands/fleet-tmux.js.map +1 -1
  268. package/dist/commands/init.d.ts +8 -0
  269. package/dist/commands/init.d.ts.map +1 -1
  270. package/dist/commands/init.js +26 -1
  271. package/dist/commands/init.js.map +1 -1
  272. package/dist/commands/list.d.ts +32 -1
  273. package/dist/commands/list.d.ts.map +1 -1
  274. package/dist/commands/list.js +98 -5
  275. package/dist/commands/list.js.map +1 -1
  276. package/dist/commands/new.d.ts +2 -0
  277. package/dist/commands/new.d.ts.map +1 -1
  278. package/dist/commands/new.js +114 -21
  279. package/dist/commands/new.js.map +1 -1
  280. package/dist/commands/session.js +1 -1
  281. package/dist/commands/session.js.map +1 -1
  282. package/dist/commands/start.d.ts +38 -0
  283. package/dist/commands/start.d.ts.map +1 -1
  284. package/dist/commands/start.js +171 -8
  285. package/dist/commands/start.js.map +1 -1
  286. package/dist/commands/sync.d.ts +57 -0
  287. package/dist/commands/sync.d.ts.map +1 -1
  288. package/dist/commands/sync.js +117 -3
  289. package/dist/commands/sync.js.map +1 -1
  290. package/dist/commands/usage.d.ts +64 -0
  291. package/dist/commands/usage.d.ts.map +1 -1
  292. package/dist/commands/usage.js +96 -3
  293. package/dist/commands/usage.js.map +1 -1
  294. package/dist/commands/verify-hooks.d.ts +37 -1
  295. package/dist/commands/verify-hooks.d.ts.map +1 -1
  296. package/dist/commands/verify-hooks.js +114 -2
  297. package/dist/commands/verify-hooks.js.map +1 -1
  298. package/dist/commands/window.d.ts +10 -0
  299. package/dist/commands/window.d.ts.map +1 -0
  300. package/dist/commands/window.js +265 -0
  301. package/dist/commands/window.js.map +1 -0
  302. package/dist/commands/worktree-sync.d.ts +54 -0
  303. package/dist/commands/worktree-sync.d.ts.map +1 -0
  304. package/dist/commands/worktree-sync.js +135 -0
  305. package/dist/commands/worktree-sync.js.map +1 -0
  306. package/dist/index.d.ts.map +1 -1
  307. package/dist/index.js +122 -11
  308. package/dist/index.js.map +1 -1
  309. package/dist/lib/agent-session.d.ts.map +1 -1
  310. package/dist/lib/agent-session.js +6 -1
  311. package/dist/lib/agent-session.js.map +1 -1
  312. package/dist/lib/catalog.d.ts +321 -2
  313. package/dist/lib/catalog.d.ts.map +1 -1
  314. package/dist/lib/catalog.js +490 -11
  315. package/dist/lib/catalog.js.map +1 -1
  316. package/dist/lib/claude.d.ts +53 -23
  317. package/dist/lib/claude.d.ts.map +1 -1
  318. package/dist/lib/claude.js +306 -17
  319. package/dist/lib/claude.js.map +1 -1
  320. package/dist/lib/cli-build.d.ts +172 -0
  321. package/dist/lib/cli-build.d.ts.map +1 -0
  322. package/dist/lib/cli-build.js +654 -0
  323. package/dist/lib/cli-build.js.map +1 -0
  324. package/dist/lib/code-context-file.d.ts +109 -0
  325. package/dist/lib/code-context-file.d.ts.map +1 -0
  326. package/dist/lib/code-context-file.js +219 -0
  327. package/dist/lib/code-context-file.js.map +1 -0
  328. package/dist/lib/code-context-file.test.d.ts +19 -0
  329. package/dist/lib/code-context-file.test.d.ts.map +1 -0
  330. package/dist/lib/code-context-file.test.js +202 -0
  331. package/dist/lib/code-context-file.test.js.map +1 -0
  332. package/dist/lib/config-fidelity.d.ts +40 -20
  333. package/dist/lib/config-fidelity.d.ts.map +1 -1
  334. package/dist/lib/config-fidelity.js +144 -56
  335. package/dist/lib/config-fidelity.js.map +1 -1
  336. package/dist/lib/coordination-client.d.ts +73 -0
  337. package/dist/lib/coordination-client.d.ts.map +1 -1
  338. package/dist/lib/coordination-client.js +180 -8
  339. package/dist/lib/coordination-client.js.map +1 -1
  340. package/dist/lib/coordination-token.d.ts +304 -6
  341. package/dist/lib/coordination-token.d.ts.map +1 -1
  342. package/dist/lib/coordination-token.js +851 -52
  343. package/dist/lib/coordination-token.js.map +1 -1
  344. package/dist/lib/fleet-data.d.ts +34 -0
  345. package/dist/lib/fleet-data.d.ts.map +1 -1
  346. package/dist/lib/fleet-data.js +37 -9
  347. package/dist/lib/fleet-data.js.map +1 -1
  348. package/dist/lib/fleet-render.js +1 -1
  349. package/dist/lib/fleet-render.js.map +1 -1
  350. package/dist/lib/git-identity.d.ts +302 -0
  351. package/dist/lib/git-identity.d.ts.map +1 -0
  352. package/dist/lib/git-identity.js +546 -0
  353. package/dist/lib/git-identity.js.map +1 -0
  354. package/dist/lib/hook-staleness.d.ts +95 -0
  355. package/dist/lib/hook-staleness.d.ts.map +1 -0
  356. package/dist/lib/hook-staleness.js +304 -0
  357. package/dist/lib/hook-staleness.js.map +1 -0
  358. package/dist/lib/jsonl.d.ts +270 -2
  359. package/dist/lib/jsonl.d.ts.map +1 -1
  360. package/dist/lib/jsonl.js +472 -76
  361. package/dist/lib/jsonl.js.map +1 -1
  362. package/dist/lib/memory.d.ts +350 -23
  363. package/dist/lib/memory.d.ts.map +1 -1
  364. package/dist/lib/memory.js +751 -38
  365. package/dist/lib/memory.js.map +1 -1
  366. package/dist/lib/otel-env.d.ts +90 -0
  367. package/dist/lib/otel-env.d.ts.map +1 -0
  368. package/dist/lib/otel-env.js +98 -0
  369. package/dist/lib/otel-env.js.map +1 -0
  370. package/dist/lib/project-config.d.ts +167 -0
  371. package/dist/lib/project-config.d.ts.map +1 -1
  372. package/dist/lib/project-config.js +321 -5
  373. package/dist/lib/project-config.js.map +1 -1
  374. package/dist/lib/projects-registry.d.ts +82 -0
  375. package/dist/lib/projects-registry.d.ts.map +1 -0
  376. package/dist/lib/projects-registry.js +145 -0
  377. package/dist/lib/projects-registry.js.map +1 -0
  378. package/dist/lib/projects-registry.test.d.ts +2 -0
  379. package/dist/lib/projects-registry.test.d.ts.map +1 -0
  380. package/dist/lib/projects-registry.test.js +176 -0
  381. package/dist/lib/projects-registry.test.js.map +1 -0
  382. package/dist/lib/repo-guard-scope.d.ts +126 -0
  383. package/dist/lib/repo-guard-scope.d.ts.map +1 -0
  384. package/dist/lib/repo-guard-scope.js +249 -0
  385. package/dist/lib/repo-guard-scope.js.map +1 -0
  386. package/dist/lib/roster.d.ts +87 -0
  387. package/dist/lib/roster.d.ts.map +1 -0
  388. package/dist/lib/roster.js +332 -0
  389. package/dist/lib/roster.js.map +1 -0
  390. package/dist/lib/roster.test.d.ts +15 -0
  391. package/dist/lib/roster.test.d.ts.map +1 -0
  392. package/dist/lib/roster.test.js +299 -0
  393. package/dist/lib/roster.test.js.map +1 -0
  394. package/dist/lib/runtime/codex-adapter.d.ts.map +1 -1
  395. package/dist/lib/runtime/codex-adapter.js +5 -0
  396. package/dist/lib/runtime/codex-adapter.js.map +1 -1
  397. package/dist/lib/runtime/codex-config.d.ts +129 -0
  398. package/dist/lib/runtime/codex-config.d.ts.map +1 -1
  399. package/dist/lib/runtime/codex-config.js +225 -0
  400. package/dist/lib/runtime/codex-config.js.map +1 -1
  401. package/dist/lib/runtime/identity.d.ts +72 -0
  402. package/dist/lib/runtime/identity.d.ts.map +1 -0
  403. package/dist/lib/runtime/identity.js +128 -0
  404. package/dist/lib/runtime/identity.js.map +1 -0
  405. package/dist/lib/standards.d.ts +10 -1
  406. package/dist/lib/standards.d.ts.map +1 -1
  407. package/dist/lib/standards.js +8 -1
  408. package/dist/lib/standards.js.map +1 -1
  409. package/dist/lib/team-identity.d.ts +134 -0
  410. package/dist/lib/team-identity.d.ts.map +1 -0
  411. package/dist/lib/team-identity.js +193 -0
  412. package/dist/lib/team-identity.js.map +1 -0
  413. package/dist/lib/templates.d.ts +29 -2
  414. package/dist/lib/templates.d.ts.map +1 -1
  415. package/dist/lib/templates.js +1042 -82
  416. package/dist/lib/templates.js.map +1 -1
  417. package/dist/lib/test-project.d.ts +95 -0
  418. package/dist/lib/test-project.d.ts.map +1 -0
  419. package/dist/lib/test-project.js +103 -0
  420. package/dist/lib/test-project.js.map +1 -0
  421. package/dist/lib/vault.d.ts +60 -0
  422. package/dist/lib/vault.d.ts.map +1 -0
  423. package/dist/lib/vault.js +102 -0
  424. package/dist/lib/vault.js.map +1 -0
  425. package/dist/lib/vault.test.d.ts +17 -0
  426. package/dist/lib/vault.test.d.ts.map +1 -0
  427. package/dist/lib/vault.test.js +169 -0
  428. package/dist/lib/vault.test.js.map +1 -0
  429. package/dist/lib/window-view.d.ts +63 -0
  430. package/dist/lib/window-view.d.ts.map +1 -0
  431. package/dist/lib/window-view.js +217 -0
  432. package/dist/lib/window-view.js.map +1 -0
  433. package/dist/lib/window-view.test.d.ts +2 -0
  434. package/dist/lib/window-view.test.d.ts.map +1 -0
  435. package/dist/lib/window-view.test.js +168 -0
  436. package/dist/lib/window-view.test.js.map +1 -0
  437. package/dist/lib/worktree-sync.d.ts +439 -0
  438. package/dist/lib/worktree-sync.d.ts.map +1 -0
  439. package/dist/lib/worktree-sync.js +1167 -0
  440. package/dist/lib/worktree-sync.js.map +1 -0
  441. package/dist/lib/worktree.d.ts +58 -1
  442. package/dist/lib/worktree.d.ts.map +1 -1
  443. package/dist/lib/worktree.js +91 -4
  444. package/dist/lib/worktree.js.map +1 -1
  445. package/dist/standards/decision-request.md +8 -0
  446. package/dist/standards/po-communication-standard.md +126 -0
  447. package/dist/standards/report-format.md +8 -0
  448. package/dist/standards/writing-standard.md +146 -4
  449. package/package.json +1 -1
  450. package/scripts/generate-claude.mjs +119 -46
@@ -0,0 +1,638 @@
1
+ /**
2
+ * The repo-mutation prevention is wired where it has to be (#10, #33).
3
+ *
4
+ * Two kinds of test live here, and the boundary between them is the point.
5
+ *
6
+ * The WIRING tests read source. The behaviour they protect only appears when a
7
+ * push runs from a linked worktree, which no unit test and no CI job can stage:
8
+ * CI checks out a plain clone, and a main worktree does not export GIT_DIR. That
9
+ * is exactly why this bug survived. So the wiring is pinned here, and the
10
+ * behaviour is evidenced by the sandbox reproduction recorded in #33.
11
+ *
12
+ * The SCOPE tests, added for #282, run the real comparison.
13
+ * src/lib/repo-guard-scope.ts holds the snapshot parsing, the writable-set
14
+ * computation and the classification as pure functions, so the seven refusals recorded on 2026-09-01
15
+ * and 2026-09-02 are replayed here as snapshot pairs. Nothing in this file
16
+ * pushes, and nothing in it writes a ref: a test that verified the hook by
17
+ * pushing would move refs in the shared store, which is the hazard the guard
18
+ * exists for.
19
+ */
20
+ import { describe, it, expect } from 'vitest';
21
+ import { readFileSync } from 'node:fs';
22
+ import { spawnSync } from 'node:child_process';
23
+ import { createRequire } from 'node:module';
24
+ import { join } from 'node:path';
25
+ import { PREPUSH_LOCAL_REFS_ENV, buildReport, classifyChanges, computeWritableRefs, isOutOfTripwireScope, parseRefs, parseWorktrees, readPushLocalRefs, } from '../lib/repo-guard-scope.js';
26
+ const CLI_ROOT = join(import.meta.dirname, '..', '..');
27
+ const read = (rel) => readFileSync(join(CLI_ROOT, rel), 'utf-8');
28
+ /**
29
+ * The guard's two source files together.
30
+ *
31
+ * vitest.repo-guard.ts is the vitest globalSetup entry point and holds the git
32
+ * calls and the lifecycle. src/lib/repo-guard-scope.ts holds the scope rule, the
33
+ * comparison and the report text, under `src/` so tsc typechecks it and this
34
+ * file can import it. A source-reading assertion about the guard's wording
35
+ * should not have to know which of the two currently holds the line.
36
+ */
37
+ const readGuard = () => `${read('vitest.repo-guard.ts')}\n${read('src/lib/repo-guard-scope.ts')}`;
38
+ describe('the inherited git environment is stripped at both chokepoints', () => {
39
+ it('vitest.config.ts strips it at module scope, before any worker is forked', () => {
40
+ const cfg = read('vitest.config.ts');
41
+ expect(cfg).toContain('git-env.cjs');
42
+ expect(cfg).toContain('stripGitEnv(process.env)');
43
+ // Module scope, not inside defineConfig: workers inherit process.env when
44
+ // they are spawned, so the deletion has to have happened already.
45
+ const stripAt = cfg.indexOf('stripGitEnv(process.env)');
46
+ const configAt = cfg.indexOf('export default defineConfig');
47
+ expect(stripAt).toBeGreaterThan(-1);
48
+ expect(stripAt).toBeLessThan(configAt);
49
+ });
50
+ it('check-new-failures.mjs hands the vitest child a cleaned environment', () => {
51
+ const script = read('scripts/check-new-failures.mjs');
52
+ expect(script).toContain('git-env.cjs');
53
+ expect(script).toContain('env: gitCleanEnv(process.env)');
54
+ });
55
+ it('check-new-failures.mjs captures stderr on success, not only on throw', () => {
56
+ const script = read('scripts/check-new-failures.mjs');
57
+ // execFileSync discards stderr when the command succeeds, and the tripwire
58
+ // reports on stderr while leaving stdout's JSON intact.
59
+ //
60
+ // Asserted on the IMPORT, not on the whole file: the script explains in a
61
+ // comment why it no longer uses execFileSync, and a bare substring check
62
+ // fails on that explanation. A test that forbids naming the thing it
63
+ // replaced is a test that punishes the comment.
64
+ expect(script).toMatch(/import \{[^}]*\bspawnSync\b[^}]*\} from 'node:child_process'/);
65
+ expect(script).not.toMatch(/import \{[^}]*\bexecFileSync\b[^}]*\} from 'node:child_process'/);
66
+ });
67
+ });
68
+ describe('a guard failure reaches the operator through the hook path', () => {
69
+ const SENTINEL = '[repo-guard] REPO_MUTATION_DETECTED';
70
+ it('the guard and the pre-push checker agree on the sentinel string', () => {
71
+ // A drifting literal would silently restore the blindness this fixed.
72
+ expect(read('vitest.repo-guard.ts')).toContain(`= '${SENTINEL}'`);
73
+ expect(read('scripts/check-new-failures.mjs')).toContain(`= '${SENTINEL}'`);
74
+ });
75
+ it('the checker refuses the push on the sentinel, matching a whole line', () => {
76
+ const script = read('scripts/check-new-failures.mjs');
77
+ expect(script).toContain('REPO_GUARD_SENTINEL');
78
+ // N1: a substring match would let any test that merely QUOTES the sentinel
79
+ // refuse a push. The guard prints it alone on its own line.
80
+ expect(script).toMatch(/\.some\(\(line\) => line\.trim\(\) === REPO_GUARD_SENTINEL\)/);
81
+ expect(script).not.toMatch(/errOut\.includes\(REPO_GUARD_SENTINEL\)/);
82
+ });
83
+ it('the guard prints the sentinel even when MX_TEST_ALLOW_REPO_MUTATION downgrades it', () => {
84
+ const guard = read('vitest.repo-guard.ts');
85
+ const sentinelAt = guard.indexOf('console.error(REPO_GUARD_SENTINEL)');
86
+ const flagAt = guard.indexOf("process.env.MX_TEST_ALLOW_REPO_MUTATION === '1'");
87
+ expect(sentinelAt).toBeGreaterThan(-1);
88
+ // Printed before the downgrade branch, so one variable cannot switch off
89
+ // both the report and the push refusal.
90
+ expect(sentinelAt).toBeLessThan(flagAt);
91
+ });
92
+ });
93
+ describe('could-not-run is reported as itself (SF-1)', () => {
94
+ it('the guard separates "not a repository" from "git ran and failed"', () => {
95
+ const guard = read('vitest.repo-guard.ts');
96
+ expect(guard).toContain("kind: 'no-repo'");
97
+ expect(guard).toContain("kind: 'no-git'");
98
+ expect(guard).toContain("kind: 'failed'");
99
+ });
100
+ it('teardown prints COULD NOT RUN when the repository could not be resolved', () => {
101
+ const guard = read('vitest.repo-guard.ts');
102
+ expect(guard).toContain('COULD NOT RUN: cannot resolve the repository');
103
+ expect(guard).toContain('Repository mutation was NOT checked');
104
+ });
105
+ it('falls back for a git with no --path-format, rather than standing down', () => {
106
+ // --path-format needs git >= 2.31 and the hook has a WSL branch that runs
107
+ // the distribution's git. Standing down there would remove the guard from
108
+ // the least CI-like environment there is.
109
+ const guard = read('vitest.repo-guard.ts');
110
+ expect(guard).toMatch(/tryGit\(\['rev-parse', '--git-common-dir'\]/);
111
+ });
112
+ it('the checker bounds the suite and calls a timeout could-not-run', () => {
113
+ const script = read('scripts/check-new-failures.mjs');
114
+ expect(script).toContain('SUITE_TIMEOUT_MS');
115
+ expect(script).toMatch(/timeout: SUITE_TIMEOUT_MS/);
116
+ expect(script).toContain("'ETIMEDOUT'");
117
+ expect(script).toContain('could-not-run, not pass');
118
+ });
119
+ });
120
+ describe('the report does not assert a cause it cannot establish (SF-2, narrowed by #282)', () => {
121
+ it('the guard no longer asks the reader to rule out a neighbour after refusing', () => {
122
+ // SUPERSEDED BY #282, deliberately. The old body told the reader to check
123
+ // whether the moved ref belonged to another team before believing the
124
+ // refusal, which made "run it again" the documented response. Seven
125
+ // recorded occurrences later, that is trained behaviour. The guard now
126
+ // excludes those refs before it refuses, so the instruction has nothing
127
+ // left to describe and its removal is asserted here rather than assumed.
128
+ const guard = readGuard();
129
+ expect(guard).not.toContain('BEFORE TREATING THIS AS CORRUPTION, RULE OUT A NEIGHBOUR');
130
+ expect(guard).not.toContain('Check whether the');
131
+ });
132
+ it('the checker describes what it observed, not what caused it', () => {
133
+ const script = read('scripts/check-new-failures.mjs');
134
+ expect(script).toContain('refs this worktree could have written changed while the test suite ran');
135
+ expect(script).not.toContain('the test suite mutated the real repository.');
136
+ });
137
+ it('the guard headline agrees with its own body and with the checker', () => {
138
+ // The headline used to assert mutation while the body directly below it
139
+ // said a sibling worktree produces the same signal. One message, two
140
+ // claims, and the reader had to pick.
141
+ const guard = readGuard();
142
+ expect(guard).toContain('Refs this worktree could have written changed while the CLI test suite ran (#10).');
143
+ expect(guard).not.toContain('The CLI test suite mutated the real repository (#10).');
144
+ });
145
+ });
146
+ describe('the pre-push hook resolves its own path without the inherited git env', () => {
147
+ const HOOK = join(CLI_ROOT, '..', '..', '.githooks', 'pre-push');
148
+ const hook = () => readFileSync(HOOK, 'utf-8');
149
+ it('unsets GIT_DIR before asking git where the worktree root is', () => {
150
+ // Under inherited GIT_DIR, --show-toplevel EXITS 0 and returns the cwd, so a
151
+ // `a || b` fallback chain never fires. Unsetting first is the only form that
152
+ // gets the right answer.
153
+ expect(hook()).toMatch(/unset GIT_DIR/);
154
+ expect(hook()).toContain('rev-parse --show-toplevel');
155
+ });
156
+ it('refuses with a message when it cannot find the checker', () => {
157
+ // A bare repository has no work tree. Dying under `set -e` with no output is
158
+ // the failure mode this hook exists to prevent.
159
+ const h = hook();
160
+ expect(h).toContain('cannot locate');
161
+ expect(h).toContain('--no-verify');
162
+ });
163
+ });
164
+ describe('the guard identifies the repository it is actually guarding', () => {
165
+ it('resolves the common dir, not --show-toplevel alone', () => {
166
+ const guard = read('vitest.repo-guard.ts');
167
+ // --show-toplevel returns the CWD under an inherited GIT_DIR, and fails
168
+ // outright on a bare repository that still holds a working tree.
169
+ expect(guard).toContain('--git-common-dir');
170
+ expect(guard).toContain('commonDir');
171
+ });
172
+ it('still reports the work tree, and says so when there is none', () => {
173
+ const guard = readGuard();
174
+ expect(guard).toContain('Work tree:');
175
+ expect(guard).toContain('bare repository');
176
+ });
177
+ });
178
+ // ---------------------------------------------------------------------------
179
+ // #282: the tripwire refuses only on refs the pushing worktree could have written
180
+ // ---------------------------------------------------------------------------
181
+ //
182
+ // These are behavioural, not source-reading. The comparison was extracted into
183
+ // pure functions so the seven refusals recorded between 2026-09-01 and
184
+ // 2026-09-02 could be replayed as snapshot pairs. Every one of them named a ref
185
+ // belonging to a worktree other than the pusher's, and every one cleared on an
186
+ // unmodified retry, which is the training effect #282 is about.
187
+ const WT = {
188
+ gateway: '/workspace/.worktrees/gateway-20260821',
189
+ bootstrap: '/workspace/.worktrees/bootstrap-20260821',
190
+ product: '/workspace/.worktrees/product-20260821',
191
+ surface: '/workspace/.worktrees/surface-20260823',
192
+ teamBuilder: '/workspace/.worktrees/team-builder-20260821',
193
+ };
194
+ const BRANCH = {
195
+ gateway: 'refs/heads/worktree/gateway-20260821',
196
+ bootstrap: 'refs/heads/worktree/bootstrap-20260821',
197
+ product: 'refs/heads/worktree/product-20260821',
198
+ surface: 'refs/heads/worktree/surface-20260823',
199
+ teamBuilder: 'refs/heads/worktree/team-builder-20260821',
200
+ };
201
+ /** The shared ref store as five active worktrees leave it. */
202
+ const BASE_REFS = {
203
+ 'refs/heads/main': '64c29120000000000000000000000000000000aa',
204
+ [BRANCH.gateway]: 'ea7e0000000000000000000000000000000000aa',
205
+ [BRANCH.bootstrap]: '1f6c39a0000000000000000000000000000000aa',
206
+ [BRANCH.product]: 'b00b0000000000000000000000000000000000aa',
207
+ [BRANCH.surface]: '5a4face000000000000000000000000000000aaa',
208
+ [BRANCH.teamBuilder]: 'fee1000000000000000000000000000000000aaa',
209
+ 'refs/heads/docs/surface-v8-closeout': 'd0c50000000000000000000000000000000000aa',
210
+ 'refs/heads/docs/307-roleguide-totals-correction': 'd3070000000000000000000000000000000000aa',
211
+ 'refs/remotes/origin/main': '462c338f00000000000000000000000000000000',
212
+ 'refs/remotes/origin/feat/255-egress-and-counter-hardening': 'a9c199310f7e28ccc8a083911fe12a8d9ccdc88f',
213
+ [`refs/remotes/origin/${BRANCH.bootstrap.replace('refs/heads/', '')}`]: '1f6c39a0000000000000000000000000000000aa',
214
+ };
215
+ const BASE_WORKTREES = [
216
+ 'worktree /workspace',
217
+ 'bare',
218
+ '',
219
+ `worktree ${WT.gateway}`,
220
+ `HEAD ${BASE_REFS[BRANCH.gateway]}`,
221
+ `branch ${BRANCH.gateway}`,
222
+ '',
223
+ `worktree ${WT.bootstrap}`,
224
+ `HEAD ${BASE_REFS[BRANCH.bootstrap]}`,
225
+ `branch ${BRANCH.bootstrap}`,
226
+ '',
227
+ `worktree ${WT.product}`,
228
+ `HEAD ${BASE_REFS[BRANCH.product]}`,
229
+ `branch ${BRANCH.product}`,
230
+ '',
231
+ `worktree ${WT.surface}`,
232
+ `HEAD ${BASE_REFS[BRANCH.surface]}`,
233
+ `branch ${BRANCH.surface}`,
234
+ '',
235
+ ].join('\n');
236
+ function renderRefs(refs) {
237
+ return `${Object.entries(refs)
238
+ .map(([ref, sha]) => `${ref} ${sha}`)
239
+ .join('\n')}\n`;
240
+ }
241
+ /** A snapshot. `null` in `refs` deletes that ref. */
242
+ function snapshot(opts) {
243
+ const refs = { ...BASE_REFS };
244
+ for (const [ref, sha] of Object.entries(opts.refs ?? {})) {
245
+ if (sha === null)
246
+ delete refs[ref];
247
+ else
248
+ refs[ref] = sha;
249
+ }
250
+ return {
251
+ head: opts.head ?? BASE_REFS[BRANCH.gateway],
252
+ refs: renderRefs(refs),
253
+ worktrees: opts.worktrees ?? BASE_WORKTREES,
254
+ };
255
+ }
256
+ function scopeFor(workTree, headRef, pushRefs = []) {
257
+ return { ...computeWritableRefs(headRef, pushRefs, workTree), workTree };
258
+ }
259
+ /** Gateway pushing `HEAD:refs/heads/docs/...`, which is how this fleet pushes. */
260
+ const GATEWAY_PUSH = scopeFor(WT.gateway, BRANCH.gateway, ['HEAD']);
261
+ describe('#282: the seven recorded refusals pass on the first attempt', () => {
262
+ const before = snapshot({});
263
+ const occurrences = [
264
+ {
265
+ name: '2026-09-01: worktree/product-20260821 moves during a gateway push',
266
+ scope: GATEWAY_PUSH,
267
+ after: snapshot({ refs: { [BRANCH.product]: 'b00b0000000000000000000000000000000000bb' } }),
268
+ },
269
+ {
270
+ name: '2026-09-02: worktree/surface-20260823 moves during a gateway push',
271
+ scope: GATEWAY_PUSH,
272
+ after: snapshot({ refs: { [BRANCH.surface]: '5a4face000000000000000000000000000000bbb' } }),
273
+ },
274
+ {
275
+ // The hard one. This branch is checked out in NO worktree, so a filter
276
+ // keyed on "another worktree has it checked out" would still refuse here.
277
+ name: '2026-09-02: docs/surface-v8-closeout, a branch no worktree has checked out',
278
+ scope: GATEWAY_PUSH,
279
+ after: snapshot({
280
+ refs: { 'refs/heads/docs/surface-v8-closeout': 'd0c50000000000000000000000000000000000bb' },
281
+ }),
282
+ },
283
+ {
284
+ name: '2026-09-02: bootstrap 1f6c39a -> 04c5cb4, during a gateway push',
285
+ scope: GATEWAY_PUSH,
286
+ after: snapshot({ refs: { [BRANCH.bootstrap]: '04c5cb40000000000000000000000000000000aa' } }),
287
+ },
288
+ {
289
+ name: '2026-09-02: bootstrap 04c5cb4 -> 11400ab, during a gateway push',
290
+ scope: GATEWAY_PUSH,
291
+ after: snapshot({ refs: { [BRANCH.bootstrap]: '11400ab0000000000000000000000000000000aa' } }),
292
+ },
293
+ {
294
+ // The third bootstrap refusal in that hour. No SHAs were captured for it,
295
+ // and an amend also rewrites the worktree's HEAD line in the porcelain.
296
+ name: '2026-09-02: bootstrap commit/amend, ref and its worktree HEAD line both move',
297
+ scope: GATEWAY_PUSH,
298
+ after: snapshot({
299
+ refs: { [BRANCH.bootstrap]: '3300aba0000000000000000000000000000000aa' },
300
+ worktrees: BASE_WORKTREES.replace(`HEAD ${BASE_REFS[BRANCH.bootstrap]}`, 'HEAD 3300aba0000000000000000000000000000000aa'),
301
+ }),
302
+ },
303
+ {
304
+ // The guard's teardown fired during a bootstrap QA run: a sibling team's
305
+ // merge landing mid-test moved the tracking ref.
306
+ name: '2026-09-02: origin/main advances 462c338f -> 55afdf23 during a bootstrap run',
307
+ scope: scopeFor(WT.bootstrap, BRANCH.bootstrap),
308
+ after: snapshot({
309
+ head: BASE_REFS[BRANCH.bootstrap],
310
+ refs: { 'refs/remotes/origin/main': '55afdf2300000000000000000000000000000000' },
311
+ }),
312
+ },
313
+ ];
314
+ it.each(occurrences)('does not refuse: $name', ({ after, scope }) => {
315
+ const verdict = classifyChanges({ ...before, head: scope.workTree === WT.bootstrap ? BASE_REFS[BRANCH.bootstrap] : before.head }, after, scope);
316
+ expect(verdict.refusals).toEqual([]);
317
+ // The movement is still reported, so nothing is hidden: it is just not the
318
+ // pusher's fault and not a reason to refuse.
319
+ expect(verdict.observations.length).toBeGreaterThan(0);
320
+ });
321
+ it('the two refusals filed on issue #282 itself also pass', () => {
322
+ // Both named refs/remotes/*, and the pushing branch was product's.
323
+ const scope = scopeFor(WT.product, BRANCH.product, ['HEAD']);
324
+ const head = BASE_REFS[BRANCH.product];
325
+ const first = classifyChanges(snapshot({ head }), snapshot({
326
+ head,
327
+ refs: {
328
+ 'refs/remotes/origin/worktree/bootstrap-20260821': '04c5cb40000000000000000000000000000000aa',
329
+ },
330
+ }), scope);
331
+ const second = classifyChanges(snapshot({ head }), snapshot({
332
+ head,
333
+ refs: {
334
+ 'refs/remotes/origin/feat/255-egress-and-counter-hardening': 'ffec40e3c17d393e34a000919a7bb2063c17562d',
335
+ },
336
+ }), scope);
337
+ expect(first.refusals).toEqual([]);
338
+ expect(second.refusals).toEqual([]);
339
+ });
340
+ it('a neighbour registering a worktree is an observation, not a refusal', () => {
341
+ // Bootstrap provisions worktrees as its ordinary work, so this happens
342
+ // during other teams' pushes by design.
343
+ const after = snapshot({
344
+ worktrees: `${BASE_WORKTREES}\nworktree /workspace/.worktrees/creation-probe-20260902\nHEAD 9999999000000000000000000000000000000aaa\nbranch refs/heads/worktree/creation-probe-20260902\n`,
345
+ });
346
+ const verdict = classifyChanges(snapshot({}), after, GATEWAY_PUSH);
347
+ expect(verdict.refusals).toEqual([]);
348
+ expect(verdict.observations.join('\n')).toContain('creation-probe-20260902');
349
+ });
350
+ });
351
+ describe('#282: the case the guard exists for still refuses', () => {
352
+ it("refuses when this worktree's own branch is repointed mid-run", () => {
353
+ const verdict = classifyChanges(snapshot({}), snapshot({ refs: { [BRANCH.gateway]: 'f1x7u4e000000000000000000000000000000aaa' } }), GATEWAY_PUSH);
354
+ expect(verdict.refusals).toHaveLength(1);
355
+ expect(verdict.refusals[0]).toContain(BRANCH.gateway);
356
+ expect(verdict.refusals[0]).toContain(WT.gateway);
357
+ });
358
+ it('refuses when a ref NAMED BY THE PUSH moves, even though HEAD is elsewhere', () => {
359
+ // `git push origin docs/307-...:refs/heads/docs/307-...` from the gateway
360
+ // worktree. The moved ref is not the checked-out branch, so a filter keyed
361
+ // on the worktree's own branch would miss it. This is the case the bootstrap
362
+ // lead flagged as the design's hard part.
363
+ const scope = scopeFor(WT.gateway, BRANCH.gateway, [
364
+ 'refs/heads/docs/307-roleguide-totals-correction',
365
+ ]);
366
+ const verdict = classifyChanges(snapshot({}), snapshot({
367
+ refs: {
368
+ 'refs/heads/docs/307-roleguide-totals-correction': 'd3070000000000000000000000000000000000bb',
369
+ // A neighbour moves in the same window. It must not be a refusal, and
370
+ // it must still be reported next to the one that is.
371
+ [BRANCH.surface]: '5a4face000000000000000000000000000000bbb',
372
+ },
373
+ }), scope);
374
+ expect(verdict.refusals).toHaveLength(1);
375
+ expect(verdict.refusals[0]).toContain('docs/307-roleguide-totals-correction');
376
+ expect(verdict.refusals[0]).toContain('named by this push');
377
+ expect(verdict.observations.join('\n')).toContain(BRANCH.surface);
378
+ });
379
+ it('refuses when a short ref name from the push refspec moves', () => {
380
+ const scope = scopeFor(WT.gateway, BRANCH.gateway, ['docs/surface-v8-closeout']);
381
+ const verdict = classifyChanges(snapshot({}), snapshot({
382
+ refs: { 'refs/heads/docs/surface-v8-closeout': 'd0c50000000000000000000000000000000000bb' },
383
+ }), scope);
384
+ expect(verdict.refusals).toHaveLength(1);
385
+ expect(verdict.refusals[0]).toContain('named by this push');
386
+ });
387
+ it("refuses when this worktree's HEAD moves, which no neighbour can do", () => {
388
+ const verdict = classifyChanges(snapshot({}), snapshot({ head: 'dead0000000000000000000000000000000000aa' }), GATEWAY_PUSH);
389
+ expect(verdict.refusals).toHaveLength(1);
390
+ expect(verdict.refusals[0]).toContain('HEAD moved');
391
+ });
392
+ it("refuses when this worktree's own entry leaves the worktree list", () => {
393
+ const after = snapshot({
394
+ worktrees: BASE_WORKTREES.split('\n\n')
395
+ .filter((block) => !block.startsWith(`worktree ${WT.gateway}`))
396
+ .join('\n\n'),
397
+ });
398
+ const verdict = classifyChanges(snapshot({}), after, GATEWAY_PUSH);
399
+ expect(verdict.refusals.join('\n')).toContain(`worktree unregistered: ${WT.gateway}`);
400
+ });
401
+ it('replays the 2026-08-21 incident and still refuses on both work-losing changes', () => {
402
+ // The push came from the team-builder worktree. HEAD moved to a fixture
403
+ // commit and worktree/team-builder-20260821 was repointed at another; both
404
+ // destroy the pusher's work and both are still refusals. The stray `f3` and
405
+ // `feature` branches from the same incident are observations now, which
406
+ // vitest.repo-guard.ts states as a deliberate loss.
407
+ const scope = scopeFor(WT.teamBuilder, BRANCH.teamBuilder, ['HEAD']);
408
+ const head = BASE_REFS[BRANCH.teamBuilder];
409
+ const verdict = classifyChanges(snapshot({ head }), snapshot({
410
+ head: '1111111000000000000000000000000000000aaa',
411
+ refs: {
412
+ [BRANCH.teamBuilder]: '2222222000000000000000000000000000000aaa',
413
+ 'refs/heads/f3': '3333333000000000000000000000000000000aaa',
414
+ 'refs/heads/feature': '4444444000000000000000000000000000000aaa',
415
+ 'refs/remotes/origin/main': '5555555000000000000000000000000000000aaa',
416
+ },
417
+ }), scope);
418
+ expect(verdict.refusals).toHaveLength(2);
419
+ expect(verdict.refusals.join('\n')).toContain('HEAD moved');
420
+ expect(verdict.refusals.join('\n')).toContain(BRANCH.teamBuilder);
421
+ expect(verdict.observations.join('\n')).toContain('refs/heads/f3');
422
+ });
423
+ it('refuses when a teammate commits in the SAME worktree, and says so', () => {
424
+ // Live evidence, 2026-09-02: 2e45a9c -> 8d115f9 -> 3cc9dbe -> ad0f27d in
425
+ // worktree/bootstrap-20260821 during one full suite run, by another session
426
+ // sharing this worktree. Under the scope rule that is a refusal, because the
427
+ // head the push reads moved underneath it. It differs from every one of the
428
+ // seven #282 cases, where the mover was a DIFFERENT worktree.
429
+ const verdict = classifyChanges(snapshot({}), snapshot({
430
+ head: 'ad0f27d1000000000000000000000000000000aa',
431
+ refs: { [BRANCH.gateway]: 'ad0f27d1000000000000000000000000000000aa' },
432
+ }), GATEWAY_PUSH);
433
+ expect(verdict.refusals).toHaveLength(2);
434
+ expect(verdict.refusals.join('\n')).toContain("this worktree's own HEAD");
435
+ expect(verdict.observations).toEqual([]);
436
+ });
437
+ it('refuses on a deleted writable ref, not only a moved one', () => {
438
+ const verdict = classifyChanges(snapshot({}), snapshot({ refs: { [BRANCH.gateway]: null } }), GATEWAY_PUSH);
439
+ expect(verdict.refusals).toHaveLength(1);
440
+ expect(verdict.refusals[0]).toContain('deleted, was');
441
+ });
442
+ it('an unchanged repository produces neither a refusal nor an observation', () => {
443
+ const verdict = classifyChanges(snapshot({}), snapshot({}), GATEWAY_PUSH);
444
+ expect(verdict).toEqual({ refusals: [], observations: [] });
445
+ });
446
+ });
447
+ describe('#282: what counts as writable, and what can never count', () => {
448
+ it("includes the branch HEAD is on, attributed to this worktree's path", () => {
449
+ const s = computeWritableRefs(BRANCH.gateway, [], WT.gateway);
450
+ expect([...s.writableRefs]).toContain(BRANCH.gateway);
451
+ expect(s.writableSources.get(BRANCH.gateway)).toContain(WT.gateway);
452
+ });
453
+ it('contributes nothing from a detached HEAD, rather than guessing', () => {
454
+ const s = computeWritableRefs(null, [], WT.gateway);
455
+ expect([...s.writableRefs]).toEqual([]);
456
+ });
457
+ it('ignores the (delete) token git writes for a delete refspec', () => {
458
+ const s = computeWritableRefs(null, ['(delete)'], WT.gateway);
459
+ expect([...s.writableRefs]).toEqual([]);
460
+ });
461
+ it('treats a bare HEAD token as already covered by the checked-out branch', () => {
462
+ const s = computeWritableRefs(BRANCH.gateway, ['HEAD'], WT.gateway);
463
+ expect([...s.writableRefs]).toEqual([BRANCH.gateway]);
464
+ });
465
+ it('qualifies a short name both ways, because a superset only widens refusal', () => {
466
+ const s = computeWritableRefs(null, ['v1.2.3'], WT.gateway);
467
+ expect([...s.writableRefs].sort()).toEqual(['refs/heads/v1.2.3', 'refs/tags/v1.2.3']);
468
+ });
469
+ it('never admits a remote-tracking ref, even when the push names one', () => {
470
+ // This guard is for local work loss (KI-SHARED-WORKTREE-GIT-MUTATION), not
471
+ // remote drift, and every team on this machine fetches into one ref store.
472
+ const s = computeWritableRefs('refs/remotes/origin/main', ['refs/remotes/origin/main'], WT.gateway);
473
+ expect([...s.writableRefs]).toEqual([]);
474
+ expect(isOutOfTripwireScope('refs/remotes/origin/main')).toBe(true);
475
+ expect(isOutOfTripwireScope('refs/heads/main')).toBe(false);
476
+ });
477
+ it('reads the push refs from the environment the hook sets', () => {
478
+ expect(PREPUSH_LOCAL_REFS_ENV).toBe('MX_PREPUSH_LOCAL_REFS');
479
+ expect(readPushLocalRefs({ [PREPUSH_LOCAL_REFS_ENV]: ' refs/heads/a refs/heads/b ' })).toEqual([
480
+ 'refs/heads/a',
481
+ 'refs/heads/b',
482
+ ]);
483
+ expect(readPushLocalRefs({})).toEqual([]);
484
+ });
485
+ });
486
+ describe('#282: the snapshot parsers attribute lines to the right owner', () => {
487
+ it('parses ref lines into names and object ids', () => {
488
+ const parsed = parseRefs('refs/heads/a aaa\nrefs/heads/b bbb\n\n');
489
+ expect(parsed.get('refs/heads/a')).toBe('aaa');
490
+ expect(parsed.size).toBe(2);
491
+ });
492
+ it('keeps each porcelain HEAD line with the worktree that owns it', () => {
493
+ // A line-set diff of the porcelain loses this, so a sibling's HEAD line
494
+ // moving was indistinguishable from this worktree's. That is the same
495
+ // misattribution #282 is about, one level down.
496
+ const parsed = parseWorktrees(BASE_WORKTREES);
497
+ expect(parsed.get(WT.bootstrap)).toContain(`branch ${BRANCH.bootstrap}`);
498
+ expect(parsed.get(WT.gateway)).not.toContain(BRANCH.bootstrap);
499
+ expect(parsed.get('/workspace')).toBe('bare');
500
+ });
501
+ });
502
+ describe('#282: the refusal text stops the reader instead of training a retry', () => {
503
+ const report = buildReport({ commonDir: '/workspace/.git', workTree: WT.gateway }, classifyChanges(snapshot({}), snapshot({
504
+ refs: {
505
+ [BRANCH.gateway]: 'f1x7u4e000000000000000000000000000000aaa',
506
+ [BRANCH.surface]: '5a4face000000000000000000000000000000bbb',
507
+ },
508
+ }), GATEWAY_PUSH));
509
+ it('says what moved and that it is in this worktree\'s writable set', () => {
510
+ expect(report).toContain("IN THIS WORKTREE'S WRITABLE SET, which is why the push is refused:");
511
+ expect(report).toContain(BRANCH.gateway);
512
+ expect(report).toContain('moved:');
513
+ });
514
+ it('tells the reader to stop, and says the retry cannot clear it', () => {
515
+ expect(report).toContain('DO NOT RETRY THIS PUSH');
516
+ expect(report).toContain('a\n second run cannot clear it');
517
+ });
518
+ it('names both causes, so the reader is not sent to grep for a teammate', () => {
519
+ // Observed live on 2026-09-02 while this fix was being written: a second
520
+ // session committed three times in this worktree during a full suite run,
521
+ // and the guard refused on HEAD, the branch and the worktree entry. That
522
+ // refusal is correct, and "find the test that did it" is the wrong first
523
+ // instruction for it.
524
+ expect(report).toContain('CAUSE 1: ANOTHER SESSION COMMITTED IN THIS WORKTREE');
525
+ expect(report).toContain('CAUSE 2: A TEST DROVE GIT AGAINST THIS REPOSITORY');
526
+ expect(report).toContain('git reflog');
527
+ });
528
+ it('makes the only push-again advice conditional on reading the reflog first', () => {
529
+ // The one sentence that mentions pushing again must not stand alone. The
530
+ // documented response for seven recorded refusals was an unconditional
531
+ // retry, and that is the habit this whole change exists to unlearn.
532
+ expect(report).toContain('Push again only after reading the reflog and\n confirming the new head is work you meant to publish.');
533
+ expect(report).not.toMatch(/run the (identical|same) command again/i);
534
+ expect(report).not.toMatch(/retry(ing)? (the|this) push\b(?!\.)/i);
535
+ });
536
+ it('names the neighbour movement separately and says it is not the reason', () => {
537
+ expect(report).toContain('ALSO OBSERVED, AND NOT THE REASON FOR THIS REFUSAL');
538
+ expect(report).toContain(BRANCH.surface);
539
+ });
540
+ it('keeps the recovery steps, which are what an operator needs after a real one', () => {
541
+ expect(report).toContain('git reflog');
542
+ expect(report).toContain('git update-ref refs/heads/<your-branch> <your-sha>');
543
+ });
544
+ });
545
+ describe('#282: the hook tells the guard which refs the push names', () => {
546
+ const HOOK = join(CLI_ROOT, '..', '..', '.githooks', 'pre-push');
547
+ const hook = () => readFileSync(HOOK, 'utf-8');
548
+ it('reads field 1 of git\'s pre-push stdin and exports it', () => {
549
+ // Simulating the contract rather than pushing: a real push to verify the
550
+ // hook would need a remote and would move refs in the shared store, which is
551
+ // the hazard this guard exists for.
552
+ const h = hook();
553
+ expect(h).toMatch(/while read -r local_ref/);
554
+ expect(h).toContain('export MX_PREPUSH_LOCAL_REFS');
555
+ // git supplies stdin; a hand-run hook must not block waiting for a terminal.
556
+ expect(h).toContain('if [ ! -t 0 ]; then');
557
+ });
558
+ /**
559
+ * Run the hook's OWN read-loop under `sh` against fixture stdin, and report
560
+ * what it exported and how it exited.
561
+ *
562
+ * Behavioural rather than source-text (security review C1). The assertion this
563
+ * replaces was `expect(h).toContain('*[!A-Za-z0-9._/-]*)')`, which passed for
564
+ * the fail-open version and would pass for any version that still contains
565
+ * that string, including one that logs and continues. It could not tell the
566
+ * two apart, and the fail-open behaviour is what shipped.
567
+ *
568
+ * The loop is extracted from the hook by its own delimiters, so this exercises
569
+ * the shipped text and not a copy that can drift away from it.
570
+ */
571
+ function runRefLoop(stdin) {
572
+ const h = hook();
573
+ const start = h.indexOf('MX_PREPUSH_LOCAL_REFS=""');
574
+ const end = h.indexOf('export MX_PREPUSH_LOCAL_REFS');
575
+ expect(start, 'the read-loop delimiters are still in the hook').toBeGreaterThan(-1);
576
+ expect(end).toBeGreaterThan(start);
577
+ const loop = h.slice(start, end);
578
+ const res = spawnSync('sh', ['-c', `${loop}\nprintf '%s' "$MX_PREPUSH_LOCAL_REFS"`], {
579
+ input: stdin,
580
+ encoding: 'utf-8',
581
+ });
582
+ return { status: res.status ?? -1, refs: res.stdout, stderr: res.stderr };
583
+ }
584
+ it('exports names inside the class and skips the (delete) token', () => {
585
+ const out = runRefLoop('refs/heads/feat/x aaa refs/heads/feat/x bbb\n'
586
+ + '(delete) 0000 refs/heads/gone 1111\n'
587
+ + 'refs/heads/main.2_v-3 ccc refs/heads/main ddd\n');
588
+ expect(out.status).toBe(0);
589
+ expect(out.refs).toBe('refs/heads/feat/x refs/heads/main.2_v-3 ');
590
+ });
591
+ it('REFUSES on a hostile name rather than dropping it, and exports nothing', () => {
592
+ // A single quote would end the quoted string run_wsl builds. The old
593
+ // behaviour logged and continued, which left the ref outside the writable
594
+ // set: `repo-guard-scope.ts:53` makes membership the thing that refuses, so
595
+ // a dropped name is a ref whose mid-run mutation would NOT be refused.
596
+ const out = runRefLoop("refs/heads/it's-fine aaa refs/heads/x bbb\n");
597
+ expect(out.status).toBe(1);
598
+ expect(out.refs).toBe('');
599
+ expect(out.stderr).toContain('REFUSED');
600
+ expect(out.stderr).toContain("refs/heads/it's-fine");
601
+ expect(out.stderr).toContain('--no-verify');
602
+ });
603
+ it('REFUSES a name git accepts but the class does not, so the gap fails closed', () => {
604
+ // Every one of these is `git check-ref-format`-legal and outside the class.
605
+ // They are the four the security review named, and they are the case the
606
+ // fail-open version was silently unprotected against.
607
+ for (const name of ['café-feature', 'a+b', 'feat@v2', "it's-fine"]) {
608
+ const out = runRefLoop(`refs/heads/${name} aaa refs/heads/${name} bbb\n`);
609
+ expect(out.status, name).toBe(1);
610
+ expect(out.refs, name).toBe('');
611
+ expect(out.stderr, name).toContain(name);
612
+ }
613
+ });
614
+ it('refuses even when a legal name precedes the offending one', () => {
615
+ // The refusal must not depend on position: an early good ref must not let a
616
+ // later bad one through on a partially-built value.
617
+ const out = runRefLoop('refs/heads/good aaa refs/heads/good bbb\nrefs/heads/a+b ccc refs/heads/a+b ddd\n');
618
+ expect(out.status).toBe(1);
619
+ expect(out.refs).toBe('');
620
+ });
621
+ it('carries the variable across the WSL boundary', () => {
622
+ expect(hook()).toContain("export MX_PREPUSH_LOCAL_REFS='$MX_PREPUSH_LOCAL_REFS';");
623
+ });
624
+ it('the guard and the hook agree on the variable name', () => {
625
+ expect(readGuard()).toContain(`= '${PREPUSH_LOCAL_REFS_ENV}'`);
626
+ expect(hook()).toContain(PREPUSH_LOCAL_REFS_ENV);
627
+ });
628
+ it('the git-env sweep does not remove it on the way to the vitest child', () => {
629
+ // gitCleanEnv strips GIT_-prefixed names. A sweep that also dropped this one
630
+ // would narrow the writable set to the checked-out branch, silently.
631
+ const require_ = createRequire(import.meta.url);
632
+ const { gitCleanEnv } = require_(join(CLI_ROOT, '..', '..', 'testing-tools', 'git-env.cjs'));
633
+ const out = gitCleanEnv({ [PREPUSH_LOCAL_REFS_ENV]: 'refs/heads/a', GIT_DIR: '/x' });
634
+ expect(out[PREPUSH_LOCAL_REFS_ENV]).toBe('refs/heads/a');
635
+ expect(out.GIT_DIR).toBeUndefined();
636
+ });
637
+ });
638
+ //# sourceMappingURL=repo-guard-wiring.test.js.map