@memnexus-ai/mx-agent-cli 0.1.294 → 0.1.296-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 (649) 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__/claude-local-sanitizer.test.d.ts +24 -0
  26. package/dist/__tests__/claude-local-sanitizer.test.d.ts.map +1 -0
  27. package/dist/__tests__/claude-local-sanitizer.test.js +906 -0
  28. package/dist/__tests__/claude-local-sanitizer.test.js.map +1 -0
  29. package/dist/__tests__/cli-build-integration.test.d.ts +2 -0
  30. package/dist/__tests__/cli-build-integration.test.d.ts.map +1 -0
  31. package/dist/__tests__/cli-build-integration.test.js +64 -0
  32. package/dist/__tests__/cli-build-integration.test.js.map +1 -0
  33. package/dist/__tests__/cli-build.test.d.ts +2 -0
  34. package/dist/__tests__/cli-build.test.d.ts.map +1 -0
  35. package/dist/__tests__/cli-build.test.js +640 -0
  36. package/dist/__tests__/cli-build.test.js.map +1 -0
  37. package/dist/__tests__/codex-deploy-config.test.js +60 -0
  38. package/dist/__tests__/codex-deploy-config.test.js.map +1 -1
  39. package/dist/__tests__/completion-rows-discriminate.test.d.ts +20 -0
  40. package/dist/__tests__/completion-rows-discriminate.test.d.ts.map +1 -0
  41. package/dist/__tests__/completion-rows-discriminate.test.js +481 -0
  42. package/dist/__tests__/completion-rows-discriminate.test.js.map +1 -0
  43. package/dist/__tests__/config-fidelity-archived-symlinks.test.d.ts +2 -0
  44. package/dist/__tests__/config-fidelity-archived-symlinks.test.d.ts.map +1 -0
  45. package/dist/__tests__/config-fidelity-archived-symlinks.test.js +127 -0
  46. package/dist/__tests__/config-fidelity-archived-symlinks.test.js.map +1 -0
  47. package/dist/__tests__/config-fidelity-display.test.d.ts +2 -0
  48. package/dist/__tests__/config-fidelity-display.test.d.ts.map +1 -0
  49. package/dist/__tests__/config-fidelity-display.test.js +77 -0
  50. package/dist/__tests__/config-fidelity-display.test.js.map +1 -0
  51. package/dist/__tests__/config-fidelity.test.js +166 -33
  52. package/dist/__tests__/config-fidelity.test.js.map +1 -1
  53. package/dist/__tests__/config-generation-gate.test.js +78 -0
  54. package/dist/__tests__/config-generation-gate.test.js.map +1 -1
  55. package/dist/__tests__/config-sync.test.js +89 -1
  56. package/dist/__tests__/config-sync.test.js.map +1 -1
  57. package/dist/__tests__/coordination-401-production-wiring.test.js +12 -7
  58. package/dist/__tests__/coordination-401-production-wiring.test.js.map +1 -1
  59. package/dist/__tests__/coordination-401-recovery.test.js +39 -32
  60. package/dist/__tests__/coordination-401-recovery.test.js.map +1 -1
  61. package/dist/__tests__/coordination-brief-pin.test.js +21 -8
  62. package/dist/__tests__/coordination-brief-pin.test.js.map +1 -1
  63. package/dist/__tests__/coordination-client.test.js +316 -3
  64. package/dist/__tests__/coordination-client.test.js.map +1 -1
  65. package/dist/__tests__/coordination-credential-endpoint.test.d.ts +24 -0
  66. package/dist/__tests__/coordination-credential-endpoint.test.d.ts.map +1 -0
  67. package/dist/__tests__/coordination-credential-endpoint.test.js +1290 -0
  68. package/dist/__tests__/coordination-credential-endpoint.test.js.map +1 -0
  69. package/dist/__tests__/coordination-memory.test.js +20 -4
  70. package/dist/__tests__/coordination-memory.test.js.map +1 -1
  71. package/dist/__tests__/coordination-provision.test.js +22 -14
  72. package/dist/__tests__/coordination-provision.test.js.map +1 -1
  73. package/dist/__tests__/coordination-status-registration.test.d.ts +16 -0
  74. package/dist/__tests__/coordination-status-registration.test.d.ts.map +1 -0
  75. package/dist/__tests__/coordination-status-registration.test.js +480 -0
  76. package/dist/__tests__/coordination-status-registration.test.js.map +1 -0
  77. package/dist/__tests__/coordination-token-multitenant.test.js +24 -24
  78. package/dist/__tests__/coordination-token-multitenant.test.js.map +1 -1
  79. package/dist/__tests__/coordination-token.test.js +35 -28
  80. package/dist/__tests__/coordination-token.test.js.map +1 -1
  81. package/dist/__tests__/creation-pr-class-check.test.d.ts +17 -0
  82. package/dist/__tests__/creation-pr-class-check.test.d.ts.map +1 -0
  83. package/dist/__tests__/creation-pr-class-check.test.js +346 -0
  84. package/dist/__tests__/creation-pr-class-check.test.js.map +1 -0
  85. package/dist/__tests__/decision-check.test.d.ts +2 -0
  86. package/dist/__tests__/decision-check.test.d.ts.map +1 -0
  87. package/dist/__tests__/decision-check.test.js +105 -0
  88. package/dist/__tests__/decision-check.test.js.map +1 -0
  89. package/dist/__tests__/digest-team-omission.test.d.ts +15 -0
  90. package/dist/__tests__/digest-team-omission.test.d.ts.map +1 -0
  91. package/dist/__tests__/digest-team-omission.test.js +247 -0
  92. package/dist/__tests__/digest-team-omission.test.js.map +1 -0
  93. package/dist/__tests__/doctor-worktree-path.test.d.ts +17 -0
  94. package/dist/__tests__/doctor-worktree-path.test.d.ts.map +1 -0
  95. package/dist/__tests__/doctor-worktree-path.test.js +158 -0
  96. package/dist/__tests__/doctor-worktree-path.test.js.map +1 -0
  97. package/dist/__tests__/fleet-data.test.js +40 -7
  98. package/dist/__tests__/fleet-data.test.js.map +1 -1
  99. package/dist/__tests__/fleet-tmux.test.js +2 -2
  100. package/dist/__tests__/fleet-tmux.test.js.map +1 -1
  101. package/dist/__tests__/generate-claude.test.js +137 -3
  102. package/dist/__tests__/generate-claude.test.js.map +1 -1
  103. package/dist/__tests__/git-env.test.d.ts +14 -0
  104. package/dist/__tests__/git-env.test.d.ts.map +1 -0
  105. package/dist/__tests__/git-env.test.js +131 -0
  106. package/dist/__tests__/git-env.test.js.map +1 -0
  107. package/dist/__tests__/git-identity-isolation.test.d.ts +33 -0
  108. package/dist/__tests__/git-identity-isolation.test.d.ts.map +1 -0
  109. package/dist/__tests__/git-identity-isolation.test.js +626 -0
  110. package/dist/__tests__/git-identity-isolation.test.js.map +1 -0
  111. package/dist/__tests__/harness-extract.test.d.ts +19 -0
  112. package/dist/__tests__/harness-extract.test.d.ts.map +1 -0
  113. package/dist/__tests__/harness-extract.test.js +566 -0
  114. package/dist/__tests__/harness-extract.test.js.map +1 -0
  115. package/dist/__tests__/harness-wiring.test.d.ts +16 -0
  116. package/dist/__tests__/harness-wiring.test.d.ts.map +1 -0
  117. package/dist/__tests__/harness-wiring.test.js +469 -0
  118. package/dist/__tests__/harness-wiring.test.js.map +1 -0
  119. package/dist/__tests__/hook-heal.test.js +17 -0
  120. package/dist/__tests__/hook-heal.test.js.map +1 -1
  121. package/dist/__tests__/init-coordination-url.test.d.ts +11 -0
  122. package/dist/__tests__/init-coordination-url.test.d.ts.map +1 -0
  123. package/dist/__tests__/init-coordination-url.test.js +114 -0
  124. package/dist/__tests__/init-coordination-url.test.js.map +1 -0
  125. package/dist/__tests__/memory-autocreate.test.js +574 -8
  126. package/dist/__tests__/memory-autocreate.test.js.map +1 -1
  127. package/dist/__tests__/memory-log-result.test.d.ts +13 -0
  128. package/dist/__tests__/memory-log-result.test.d.ts.map +1 -0
  129. package/dist/__tests__/memory-log-result.test.js +113 -0
  130. package/dist/__tests__/memory-log-result.test.js.map +1 -0
  131. package/dist/__tests__/memory-named-exists.test.d.ts +16 -0
  132. package/dist/__tests__/memory-named-exists.test.d.ts.map +1 -0
  133. package/dist/__tests__/memory-named-exists.test.js +288 -0
  134. package/dist/__tests__/memory-named-exists.test.js.map +1 -0
  135. package/dist/__tests__/mx-agent-cli-pin-validation.test.js +23 -47
  136. package/dist/__tests__/mx-agent-cli-pin-validation.test.js.map +1 -1
  137. package/dist/__tests__/mx-agent-cli-version-pin.test.js +34 -88
  138. package/dist/__tests__/mx-agent-cli-version-pin.test.js.map +1 -1
  139. package/dist/__tests__/new-project-first-team.test.d.ts +15 -0
  140. package/dist/__tests__/new-project-first-team.test.d.ts.map +1 -0
  141. package/dist/__tests__/new-project-first-team.test.js +263 -0
  142. package/dist/__tests__/new-project-first-team.test.js.map +1 -0
  143. package/dist/__tests__/otel-env.test.d.ts +2 -0
  144. package/dist/__tests__/otel-env.test.d.ts.map +1 -0
  145. package/dist/__tests__/otel-env.test.js +127 -0
  146. package/dist/__tests__/otel-env.test.js.map +1 -0
  147. package/dist/__tests__/project-config.test.js +283 -1
  148. package/dist/__tests__/project-config.test.js.map +1 -1
  149. package/dist/__tests__/provision-behavioral-contract.test.js +96 -4
  150. package/dist/__tests__/provision-behavioral-contract.test.js.map +1 -1
  151. package/dist/__tests__/provision-catalog-precondition.test.d.ts +26 -0
  152. package/dist/__tests__/provision-catalog-precondition.test.d.ts.map +1 -0
  153. package/dist/__tests__/provision-catalog-precondition.test.js +620 -0
  154. package/dist/__tests__/provision-catalog-precondition.test.js.map +1 -0
  155. package/dist/__tests__/provision-completion-rows.test.d.ts +17 -0
  156. package/dist/__tests__/provision-completion-rows.test.d.ts.map +1 -0
  157. package/dist/__tests__/provision-completion-rows.test.js +3187 -0
  158. package/dist/__tests__/provision-completion-rows.test.js.map +1 -0
  159. package/dist/__tests__/provision-identity-gate.test.d.ts +20 -0
  160. package/dist/__tests__/provision-identity-gate.test.d.ts.map +1 -0
  161. package/dist/__tests__/provision-identity-gate.test.js +600 -0
  162. package/dist/__tests__/provision-identity-gate.test.js.map +1 -0
  163. package/dist/__tests__/provision-resume.test.d.ts +26 -0
  164. package/dist/__tests__/provision-resume.test.d.ts.map +1 -0
  165. package/dist/__tests__/provision-resume.test.js +1164 -0
  166. package/dist/__tests__/provision-resume.test.js.map +1 -0
  167. package/dist/__tests__/provision-roleguide-anchors.test.d.ts +27 -0
  168. package/dist/__tests__/provision-roleguide-anchors.test.d.ts.map +1 -0
  169. package/dist/__tests__/provision-roleguide-anchors.test.js +747 -0
  170. package/dist/__tests__/provision-roleguide-anchors.test.js.map +1 -0
  171. package/dist/__tests__/provision-skeleton-fill.test.d.ts +16 -0
  172. package/dist/__tests__/provision-skeleton-fill.test.d.ts.map +1 -0
  173. package/dist/__tests__/provision-skeleton-fill.test.js +488 -0
  174. package/dist/__tests__/provision-skeleton-fill.test.js.map +1 -0
  175. package/dist/__tests__/provision-teambuilder-flow.test.js +93 -7
  176. package/dist/__tests__/provision-teambuilder-flow.test.js.map +1 -1
  177. package/dist/__tests__/repo-guard-wiring.test.d.ts +21 -0
  178. package/dist/__tests__/repo-guard-wiring.test.d.ts.map +1 -0
  179. package/dist/__tests__/repo-guard-wiring.test.js +638 -0
  180. package/dist/__tests__/repo-guard-wiring.test.js.map +1 -0
  181. package/dist/__tests__/report-format.test.d.ts +2 -0
  182. package/dist/__tests__/report-format.test.d.ts.map +1 -0
  183. package/dist/__tests__/report-format.test.js +219 -0
  184. package/dist/__tests__/report-format.test.js.map +1 -0
  185. package/dist/__tests__/row15-detail-sanitizer.test.d.ts +20 -0
  186. package/dist/__tests__/row15-detail-sanitizer.test.d.ts.map +1 -0
  187. package/dist/__tests__/row15-detail-sanitizer.test.js +61 -0
  188. package/dist/__tests__/row15-detail-sanitizer.test.js.map +1 -0
  189. package/dist/__tests__/runtime-codex-gateway-pilot.test.d.ts +2 -0
  190. package/dist/__tests__/runtime-codex-gateway-pilot.test.d.ts.map +1 -0
  191. package/dist/__tests__/runtime-codex-gateway-pilot.test.js +309 -0
  192. package/dist/__tests__/runtime-codex-gateway-pilot.test.js.map +1 -0
  193. package/dist/__tests__/runtime-codex-gateway-provider.test.d.ts +2 -0
  194. package/dist/__tests__/runtime-codex-gateway-provider.test.d.ts.map +1 -0
  195. package/dist/__tests__/runtime-codex-gateway-provider.test.js +163 -0
  196. package/dist/__tests__/runtime-codex-gateway-provider.test.js.map +1 -0
  197. package/dist/__tests__/runtime-identity.test.d.ts +2 -0
  198. package/dist/__tests__/runtime-identity.test.d.ts.map +1 -0
  199. package/dist/__tests__/runtime-identity.test.js +117 -0
  200. package/dist/__tests__/runtime-identity.test.js.map +1 -0
  201. package/dist/__tests__/session-pause-provisioning.test.js +6 -1
  202. package/dist/__tests__/session-pause-provisioning.test.js.map +1 -1
  203. package/dist/__tests__/session-record-disclosure.test.d.ts +24 -0
  204. package/dist/__tests__/session-record-disclosure.test.d.ts.map +1 -0
  205. package/dist/__tests__/session-record-disclosure.test.js +494 -0
  206. package/dist/__tests__/session-record-disclosure.test.js.map +1 -0
  207. package/dist/__tests__/session.test.js +35 -0
  208. package/dist/__tests__/session.test.js.map +1 -1
  209. package/dist/__tests__/slug-validation.test.js +27 -21
  210. package/dist/__tests__/slug-validation.test.js.map +1 -1
  211. package/dist/__tests__/standards-injection.test.d.ts +2 -0
  212. package/dist/__tests__/standards-injection.test.d.ts.map +1 -0
  213. package/dist/__tests__/standards-injection.test.js +179 -0
  214. package/dist/__tests__/standards-injection.test.js.map +1 -0
  215. package/dist/__tests__/start-interactive-role.test.d.ts +22 -0
  216. package/dist/__tests__/start-interactive-role.test.d.ts.map +1 -0
  217. package/dist/__tests__/start-interactive-role.test.js +204 -0
  218. package/dist/__tests__/start-interactive-role.test.js.map +1 -0
  219. package/dist/__tests__/start-team-identity.test.d.ts +25 -0
  220. package/dist/__tests__/start-team-identity.test.d.ts.map +1 -0
  221. package/dist/__tests__/start-team-identity.test.js +307 -0
  222. package/dist/__tests__/start-team-identity.test.js.map +1 -0
  223. package/dist/__tests__/team-memory-commands.test.js +142 -19
  224. package/dist/__tests__/team-memory-commands.test.js.map +1 -1
  225. package/dist/__tests__/template-sync.test.d.ts +19 -0
  226. package/dist/__tests__/template-sync.test.d.ts.map +1 -0
  227. package/dist/__tests__/template-sync.test.js +270 -0
  228. package/dist/__tests__/template-sync.test.js.map +1 -0
  229. package/dist/__tests__/test-project.test.d.ts +18 -0
  230. package/dist/__tests__/test-project.test.d.ts.map +1 -0
  231. package/dist/__tests__/test-project.test.js +465 -0
  232. package/dist/__tests__/test-project.test.js.map +1 -0
  233. package/dist/__tests__/usage-per-call-grouping.test.d.ts +25 -0
  234. package/dist/__tests__/usage-per-call-grouping.test.d.ts.map +1 -0
  235. package/dist/__tests__/usage-per-call-grouping.test.js +952 -0
  236. package/dist/__tests__/usage-per-call-grouping.test.js.map +1 -0
  237. package/dist/__tests__/verify-hooks-check-all.test.d.ts +32 -0
  238. package/dist/__tests__/verify-hooks-check-all.test.d.ts.map +1 -0
  239. package/dist/__tests__/verify-hooks-check-all.test.js +553 -0
  240. package/dist/__tests__/verify-hooks-check-all.test.js.map +1 -0
  241. package/dist/__tests__/worktree-sync-fixture.test.d.ts +17 -0
  242. package/dist/__tests__/worktree-sync-fixture.test.d.ts.map +1 -0
  243. package/dist/__tests__/worktree-sync-fixture.test.js +519 -0
  244. package/dist/__tests__/worktree-sync-fixture.test.js.map +1 -0
  245. package/dist/__tests__/worktree-sync-hardening.test.d.ts +13 -0
  246. package/dist/__tests__/worktree-sync-hardening.test.d.ts.map +1 -0
  247. package/dist/__tests__/worktree-sync-hardening.test.js +919 -0
  248. package/dist/__tests__/worktree-sync-hardening.test.js.map +1 -0
  249. package/dist/__tests__/worktree-sync-shell-free.test.d.ts +25 -0
  250. package/dist/__tests__/worktree-sync-shell-free.test.d.ts.map +1 -0
  251. package/dist/__tests__/worktree-sync-shell-free.test.js +185 -0
  252. package/dist/__tests__/worktree-sync-shell-free.test.js.map +1 -0
  253. package/dist/__tests__/worktree.test.js +75 -1
  254. package/dist/__tests__/worktree.test.js.map +1 -1
  255. package/dist/agent-config/.mx-config-generation.json +2 -2
  256. package/dist/agent-config/AGENTS.md.template +2 -2
  257. package/dist/agent-config/agents/bar-raiser.md +34 -1
  258. package/dist/agent-config/agents/red-team.md +34 -1
  259. package/dist/agent-config/agents/security-reviewer.md +22 -1
  260. package/dist/agent-config/claude-md/CLAUDE.core.md +6 -1
  261. package/dist/agent-config/claude-md/CLAUDE.overlay.memnexus.md +1 -3
  262. package/dist/agent-config/coordination-rosters.generated.json +10 -0
  263. package/dist/agent-config/hooks/HOOK-TIMEOUTS.md +27 -1
  264. package/dist/agent-config/hooks/OR-TRUE-AUDIT.md +8 -8
  265. package/dist/agent-config/hooks/auto-capture-precompact.sh +180 -83
  266. package/dist/agent-config/hooks/auto-capture-session-end.sh +216 -87
  267. package/dist/agent-config/hooks/auto-checkpoint.sh +75 -5
  268. package/dist/agent-config/hooks/coordination-brief.sh +290 -245
  269. package/dist/agent-config/hooks/deploy-verification-reminder.sh +359 -22
  270. package/dist/agent-config/hooks/git-mutation-guard.sh +85 -13
  271. package/dist/agent-config/hooks/observability-sync.sh +46 -9
  272. package/dist/agent-config/hooks/session-idle-gate.sh +177 -12
  273. package/dist/agent-config/hooks/subagent-write-guard.sh +670 -0
  274. package/dist/agent-config/hooks/worktree-guard.sh +36 -7
  275. package/dist/agent-config/settings.json +15 -2
  276. package/dist/agent-config/shared/creation-pr-review-checklist.md +317 -0
  277. package/dist/commands/bootstrap.d.ts.map +1 -1
  278. package/dist/commands/bootstrap.js +22 -10
  279. package/dist/commands/bootstrap.js.map +1 -1
  280. package/dist/commands/config-sync.d.ts +37 -0
  281. package/dist/commands/config-sync.d.ts.map +1 -1
  282. package/dist/commands/config-sync.js +36 -18
  283. package/dist/commands/config-sync.js.map +1 -1
  284. package/dist/commands/config.d.ts.map +1 -1
  285. package/dist/commands/config.js +28 -1
  286. package/dist/commands/config.js.map +1 -1
  287. package/dist/commands/coordination.d.ts +150 -8
  288. package/dist/commands/coordination.d.ts.map +1 -1
  289. package/dist/commands/coordination.js +524 -25
  290. package/dist/commands/coordination.js.map +1 -1
  291. package/dist/commands/create.d.ts +922 -1
  292. package/dist/commands/create.d.ts.map +1 -1
  293. package/dist/commands/create.js +4934 -345
  294. package/dist/commands/create.js.map +1 -1
  295. package/dist/commands/dashboard.d.ts.map +1 -1
  296. package/dist/commands/dashboard.js +10 -2
  297. package/dist/commands/dashboard.js.map +1 -1
  298. package/dist/commands/decision.d.ts +20 -0
  299. package/dist/commands/decision.d.ts.map +1 -0
  300. package/dist/commands/decision.js +54 -0
  301. package/dist/commands/decision.js.map +1 -0
  302. package/dist/commands/digest.d.ts.map +1 -1
  303. package/dist/commands/digest.js +91 -7
  304. package/dist/commands/digest.js.map +1 -1
  305. package/dist/commands/fleet-tmux.js +1 -1
  306. package/dist/commands/fleet-tmux.js.map +1 -1
  307. package/dist/commands/init.d.ts +8 -0
  308. package/dist/commands/init.d.ts.map +1 -1
  309. package/dist/commands/init.js +26 -1
  310. package/dist/commands/init.js.map +1 -1
  311. package/dist/commands/list.d.ts +32 -1
  312. package/dist/commands/list.d.ts.map +1 -1
  313. package/dist/commands/list.js +98 -5
  314. package/dist/commands/list.js.map +1 -1
  315. package/dist/commands/monitor.d.ts.map +1 -1
  316. package/dist/commands/monitor.js +8 -2
  317. package/dist/commands/monitor.js.map +1 -1
  318. package/dist/commands/new.d.ts +2 -0
  319. package/dist/commands/new.d.ts.map +1 -1
  320. package/dist/commands/new.js +114 -21
  321. package/dist/commands/new.js.map +1 -1
  322. package/dist/commands/report.d.ts +33 -0
  323. package/dist/commands/report.d.ts.map +1 -0
  324. package/dist/commands/report.js +73 -0
  325. package/dist/commands/report.js.map +1 -0
  326. package/dist/commands/session.js +1 -1
  327. package/dist/commands/session.js.map +1 -1
  328. package/dist/commands/start.d.ts +42 -0
  329. package/dist/commands/start.d.ts.map +1 -1
  330. package/dist/commands/start.js +183 -8
  331. package/dist/commands/start.js.map +1 -1
  332. package/dist/commands/sync.d.ts +57 -0
  333. package/dist/commands/sync.d.ts.map +1 -1
  334. package/dist/commands/sync.js +117 -3
  335. package/dist/commands/sync.js.map +1 -1
  336. package/dist/commands/update.d.ts +13 -1
  337. package/dist/commands/update.d.ts.map +1 -1
  338. package/dist/commands/update.js +50 -1
  339. package/dist/commands/update.js.map +1 -1
  340. package/dist/commands/usage.d.ts +64 -0
  341. package/dist/commands/usage.d.ts.map +1 -1
  342. package/dist/commands/usage.js +96 -3
  343. package/dist/commands/usage.js.map +1 -1
  344. package/dist/commands/verify-hooks.d.ts +37 -1
  345. package/dist/commands/verify-hooks.d.ts.map +1 -1
  346. package/dist/commands/verify-hooks.js +114 -2
  347. package/dist/commands/verify-hooks.js.map +1 -1
  348. package/dist/commands/window.d.ts +10 -0
  349. package/dist/commands/window.d.ts.map +1 -0
  350. package/dist/commands/window.js +265 -0
  351. package/dist/commands/window.js.map +1 -0
  352. package/dist/commands/worktree-sync.d.ts +54 -0
  353. package/dist/commands/worktree-sync.d.ts.map +1 -0
  354. package/dist/commands/worktree-sync.js +135 -0
  355. package/dist/commands/worktree-sync.js.map +1 -0
  356. package/dist/index.d.ts.map +1 -1
  357. package/dist/index.js +189 -14
  358. package/dist/index.js.map +1 -1
  359. package/dist/lib/agent-session.d.ts +12 -0
  360. package/dist/lib/agent-session.d.ts.map +1 -1
  361. package/dist/lib/agent-session.js +189 -42
  362. package/dist/lib/agent-session.js.map +1 -1
  363. package/dist/lib/behavioral-injection.d.ts +9 -0
  364. package/dist/lib/behavioral-injection.d.ts.map +1 -1
  365. package/dist/lib/behavioral-injection.js +10 -1
  366. package/dist/lib/behavioral-injection.js.map +1 -1
  367. package/dist/lib/catalog.d.ts +321 -2
  368. package/dist/lib/catalog.d.ts.map +1 -1
  369. package/dist/lib/catalog.js +490 -11
  370. package/dist/lib/catalog.js.map +1 -1
  371. package/dist/lib/claude.d.ts +113 -23
  372. package/dist/lib/claude.d.ts.map +1 -1
  373. package/dist/lib/claude.js +498 -32
  374. package/dist/lib/claude.js.map +1 -1
  375. package/dist/lib/cli-build.d.ts +172 -0
  376. package/dist/lib/cli-build.d.ts.map +1 -0
  377. package/dist/lib/cli-build.js +654 -0
  378. package/dist/lib/cli-build.js.map +1 -0
  379. package/dist/lib/code-context-file.d.ts +109 -0
  380. package/dist/lib/code-context-file.d.ts.map +1 -0
  381. package/dist/lib/code-context-file.js +219 -0
  382. package/dist/lib/code-context-file.js.map +1 -0
  383. package/dist/lib/code-context-file.test.d.ts +19 -0
  384. package/dist/lib/code-context-file.test.d.ts.map +1 -0
  385. package/dist/lib/code-context-file.test.js +202 -0
  386. package/dist/lib/code-context-file.test.js.map +1 -0
  387. package/dist/lib/config-fidelity.d.ts +40 -20
  388. package/dist/lib/config-fidelity.d.ts.map +1 -1
  389. package/dist/lib/config-fidelity.js +144 -56
  390. package/dist/lib/config-fidelity.js.map +1 -1
  391. package/dist/lib/coordination-client.d.ts +101 -0
  392. package/dist/lib/coordination-client.d.ts.map +1 -1
  393. package/dist/lib/coordination-client.js +232 -8
  394. package/dist/lib/coordination-client.js.map +1 -1
  395. package/dist/lib/coordination-token.d.ts +333 -6
  396. package/dist/lib/coordination-token.d.ts.map +1 -1
  397. package/dist/lib/coordination-token.js +875 -52
  398. package/dist/lib/coordination-token.js.map +1 -1
  399. package/dist/lib/decision-check.d.ts +48 -0
  400. package/dist/lib/decision-check.d.ts.map +1 -0
  401. package/dist/lib/decision-check.js +149 -0
  402. package/dist/lib/decision-check.js.map +1 -0
  403. package/dist/lib/fleet-data.d.ts +34 -0
  404. package/dist/lib/fleet-data.d.ts.map +1 -1
  405. package/dist/lib/fleet-data.js +37 -9
  406. package/dist/lib/fleet-data.js.map +1 -1
  407. package/dist/lib/fleet-render.js +1 -1
  408. package/dist/lib/fleet-render.js.map +1 -1
  409. package/dist/lib/git-identity.d.ts +302 -0
  410. package/dist/lib/git-identity.d.ts.map +1 -0
  411. package/dist/lib/git-identity.js +546 -0
  412. package/dist/lib/git-identity.js.map +1 -0
  413. package/dist/lib/harness/console/announce.d.ts +45 -0
  414. package/dist/lib/harness/console/announce.d.ts.map +1 -0
  415. package/dist/lib/harness/console/announce.js +48 -0
  416. package/dist/lib/harness/console/announce.js.map +1 -0
  417. package/dist/lib/harness/console/announce.test.d.ts +2 -0
  418. package/dist/lib/harness/console/announce.test.d.ts.map +1 -0
  419. package/dist/lib/harness/console/announce.test.js +104 -0
  420. package/dist/lib/harness/console/announce.test.js.map +1 -0
  421. package/dist/lib/harness/console/by-session.d.ts +50 -0
  422. package/dist/lib/harness/console/by-session.d.ts.map +1 -0
  423. package/dist/lib/harness/console/by-session.js +83 -0
  424. package/dist/lib/harness/console/by-session.js.map +1 -0
  425. package/dist/lib/harness/console/by-session.test.d.ts +2 -0
  426. package/dist/lib/harness/console/by-session.test.d.ts.map +1 -0
  427. package/dist/lib/harness/console/by-session.test.js +86 -0
  428. package/dist/lib/harness/console/by-session.test.js.map +1 -0
  429. package/dist/lib/harness/console/console.d.ts +67 -0
  430. package/dist/lib/harness/console/console.d.ts.map +1 -0
  431. package/dist/lib/harness/console/console.js +373 -0
  432. package/dist/lib/harness/console/console.js.map +1 -0
  433. package/dist/lib/harness/console/console.test.d.ts +2 -0
  434. package/dist/lib/harness/console/console.test.d.ts.map +1 -0
  435. package/dist/lib/harness/console/console.test.js +269 -0
  436. package/dist/lib/harness/console/console.test.js.map +1 -0
  437. package/dist/lib/harness/console/decision-request.d.ts +32 -0
  438. package/dist/lib/harness/console/decision-request.d.ts.map +1 -0
  439. package/dist/lib/harness/console/decision-request.js +112 -0
  440. package/dist/lib/harness/console/decision-request.js.map +1 -0
  441. package/dist/lib/harness/console/decision-request.test.d.ts +2 -0
  442. package/dist/lib/harness/console/decision-request.test.d.ts.map +1 -0
  443. package/dist/lib/harness/console/decision-request.test.js +75 -0
  444. package/dist/lib/harness/console/decision-request.test.js.map +1 -0
  445. package/dist/lib/harness/console/fixtures.d.ts +16 -0
  446. package/dist/lib/harness/console/fixtures.d.ts.map +1 -0
  447. package/dist/lib/harness/console/fixtures.js +49 -0
  448. package/dist/lib/harness/console/fixtures.js.map +1 -0
  449. package/dist/lib/harness/console/index.d.ts +15 -0
  450. package/dist/lib/harness/console/index.d.ts.map +1 -0
  451. package/dist/lib/harness/console/index.js +14 -0
  452. package/dist/lib/harness/console/index.js.map +1 -0
  453. package/dist/lib/harness/console/rank.d.ts +73 -0
  454. package/dist/lib/harness/console/rank.d.ts.map +1 -0
  455. package/dist/lib/harness/console/rank.js +113 -0
  456. package/dist/lib/harness/console/rank.js.map +1 -0
  457. package/dist/lib/harness/console/rank.test.d.ts +2 -0
  458. package/dist/lib/harness/console/rank.test.d.ts.map +1 -0
  459. package/dist/lib/harness/console/rank.test.js +124 -0
  460. package/dist/lib/harness/console/rank.test.js.map +1 -0
  461. package/dist/lib/harness/console/render.d.ts +22 -0
  462. package/dist/lib/harness/console/render.d.ts.map +1 -0
  463. package/dist/lib/harness/console/render.js +65 -0
  464. package/dist/lib/harness/console/render.js.map +1 -0
  465. package/dist/lib/harness/console/render.test.d.ts +2 -0
  466. package/dist/lib/harness/console/render.test.d.ts.map +1 -0
  467. package/dist/lib/harness/console/render.test.js +96 -0
  468. package/dist/lib/harness/console/render.test.js.map +1 -0
  469. package/dist/lib/harness/console/replay-cli.test.d.ts +2 -0
  470. package/dist/lib/harness/console/replay-cli.test.d.ts.map +1 -0
  471. package/dist/lib/harness/console/replay-cli.test.js +96 -0
  472. package/dist/lib/harness/console/replay-cli.test.js.map +1 -0
  473. package/dist/lib/harness/console/replay.d.ts +36 -0
  474. package/dist/lib/harness/console/replay.d.ts.map +1 -0
  475. package/dist/lib/harness/console/replay.js +59 -0
  476. package/dist/lib/harness/console/replay.js.map +1 -0
  477. package/dist/lib/harness/console/replay.test.d.ts +2 -0
  478. package/dist/lib/harness/console/replay.test.d.ts.map +1 -0
  479. package/dist/lib/harness/console/replay.test.js +81 -0
  480. package/dist/lib/harness/console/replay.test.js.map +1 -0
  481. package/dist/lib/harness/console/turn-reader.d.ts +50 -0
  482. package/dist/lib/harness/console/turn-reader.d.ts.map +1 -0
  483. package/dist/lib/harness/console/turn-reader.js +184 -0
  484. package/dist/lib/harness/console/turn-reader.js.map +1 -0
  485. package/dist/lib/harness/console/turn-reader.test.d.ts +2 -0
  486. package/dist/lib/harness/console/turn-reader.test.d.ts.map +1 -0
  487. package/dist/lib/harness/console/turn-reader.test.js +108 -0
  488. package/dist/lib/harness/console/turn-reader.test.js.map +1 -0
  489. package/dist/lib/harness/console/types.d.ts +109 -0
  490. package/dist/lib/harness/console/types.d.ts.map +1 -0
  491. package/dist/lib/harness/console/types.js +2 -0
  492. package/dist/lib/harness/console/types.js.map +1 -0
  493. package/dist/lib/harness/contract.d.ts +229 -0
  494. package/dist/lib/harness/contract.d.ts.map +1 -0
  495. package/dist/lib/harness/contract.js +22 -0
  496. package/dist/lib/harness/contract.js.map +1 -0
  497. package/dist/lib/harness/credential.d.ts +23 -0
  498. package/dist/lib/harness/credential.d.ts.map +1 -0
  499. package/dist/lib/harness/credential.js +81 -0
  500. package/dist/lib/harness/credential.js.map +1 -0
  501. package/dist/lib/harness/credential.test.d.ts +2 -0
  502. package/dist/lib/harness/credential.test.d.ts.map +1 -0
  503. package/dist/lib/harness/credential.test.js +74 -0
  504. package/dist/lib/harness/credential.test.js.map +1 -0
  505. package/dist/lib/harness/evaluate.d.ts +390 -0
  506. package/dist/lib/harness/evaluate.d.ts.map +1 -0
  507. package/dist/lib/harness/evaluate.js +988 -0
  508. package/dist/lib/harness/evaluate.js.map +1 -0
  509. package/dist/lib/harness/evaluate.test.d.ts +2 -0
  510. package/dist/lib/harness/evaluate.test.d.ts.map +1 -0
  511. package/dist/lib/harness/evaluate.test.js +621 -0
  512. package/dist/lib/harness/evaluate.test.js.map +1 -0
  513. package/dist/lib/harness/extract.d.ts +152 -0
  514. package/dist/lib/harness/extract.d.ts.map +1 -0
  515. package/dist/lib/harness/extract.js +1601 -0
  516. package/dist/lib/harness/extract.js.map +1 -0
  517. package/dist/lib/harness/gate.d.ts +48 -0
  518. package/dist/lib/harness/gate.d.ts.map +1 -0
  519. package/dist/lib/harness/gate.js +60 -0
  520. package/dist/lib/harness/gate.js.map +1 -0
  521. package/dist/lib/harness/gate.test.d.ts +2 -0
  522. package/dist/lib/harness/gate.test.d.ts.map +1 -0
  523. package/dist/lib/harness/gate.test.js +111 -0
  524. package/dist/lib/harness/gate.test.js.map +1 -0
  525. package/dist/lib/harness/self-check.d.ts +59 -0
  526. package/dist/lib/harness/self-check.d.ts.map +1 -0
  527. package/dist/lib/harness/self-check.js +56 -0
  528. package/dist/lib/harness/self-check.js.map +1 -0
  529. package/dist/lib/harness/self-check.test.d.ts +2 -0
  530. package/dist/lib/harness/self-check.test.d.ts.map +1 -0
  531. package/dist/lib/harness/self-check.test.js +43 -0
  532. package/dist/lib/harness/self-check.test.js.map +1 -0
  533. package/dist/lib/harness/transcript.d.ts +65 -0
  534. package/dist/lib/harness/transcript.d.ts.map +1 -0
  535. package/dist/lib/harness/transcript.js +144 -0
  536. package/dist/lib/harness/transcript.js.map +1 -0
  537. package/dist/lib/harness/transcript.test.d.ts +2 -0
  538. package/dist/lib/harness/transcript.test.d.ts.map +1 -0
  539. package/dist/lib/harness/transcript.test.js +118 -0
  540. package/dist/lib/harness/transcript.test.js.map +1 -0
  541. package/dist/lib/harness-wiring.d.ts +145 -0
  542. package/dist/lib/harness-wiring.d.ts.map +1 -0
  543. package/dist/lib/harness-wiring.js +280 -0
  544. package/dist/lib/harness-wiring.js.map +1 -0
  545. package/dist/lib/hook-staleness.d.ts +95 -0
  546. package/dist/lib/hook-staleness.d.ts.map +1 -0
  547. package/dist/lib/hook-staleness.js +304 -0
  548. package/dist/lib/hook-staleness.js.map +1 -0
  549. package/dist/lib/jsonl.d.ts +270 -2
  550. package/dist/lib/jsonl.d.ts.map +1 -1
  551. package/dist/lib/jsonl.js +472 -76
  552. package/dist/lib/jsonl.js.map +1 -1
  553. package/dist/lib/memory.d.ts +350 -23
  554. package/dist/lib/memory.d.ts.map +1 -1
  555. package/dist/lib/memory.js +751 -38
  556. package/dist/lib/memory.js.map +1 -1
  557. package/dist/lib/otel-env.d.ts +90 -0
  558. package/dist/lib/otel-env.d.ts.map +1 -0
  559. package/dist/lib/otel-env.js +98 -0
  560. package/dist/lib/otel-env.js.map +1 -0
  561. package/dist/lib/project-config.d.ts +167 -0
  562. package/dist/lib/project-config.d.ts.map +1 -1
  563. package/dist/lib/project-config.js +321 -5
  564. package/dist/lib/project-config.js.map +1 -1
  565. package/dist/lib/projects-registry.d.ts +82 -0
  566. package/dist/lib/projects-registry.d.ts.map +1 -0
  567. package/dist/lib/projects-registry.js +145 -0
  568. package/dist/lib/projects-registry.js.map +1 -0
  569. package/dist/lib/projects-registry.test.d.ts +2 -0
  570. package/dist/lib/projects-registry.test.d.ts.map +1 -0
  571. package/dist/lib/projects-registry.test.js +176 -0
  572. package/dist/lib/projects-registry.test.js.map +1 -0
  573. package/dist/lib/repo-guard-scope.d.ts +126 -0
  574. package/dist/lib/repo-guard-scope.d.ts.map +1 -0
  575. package/dist/lib/repo-guard-scope.js +249 -0
  576. package/dist/lib/repo-guard-scope.js.map +1 -0
  577. package/dist/lib/report-format.d.ts +132 -0
  578. package/dist/lib/report-format.d.ts.map +1 -0
  579. package/dist/lib/report-format.js +317 -0
  580. package/dist/lib/report-format.js.map +1 -0
  581. package/dist/lib/roster.d.ts +99 -0
  582. package/dist/lib/roster.d.ts.map +1 -0
  583. package/dist/lib/roster.js +336 -0
  584. package/dist/lib/roster.js.map +1 -0
  585. package/dist/lib/roster.test.d.ts +15 -0
  586. package/dist/lib/roster.test.d.ts.map +1 -0
  587. package/dist/lib/roster.test.js +299 -0
  588. package/dist/lib/roster.test.js.map +1 -0
  589. package/dist/lib/runtime/codex-adapter.d.ts.map +1 -1
  590. package/dist/lib/runtime/codex-adapter.js +5 -0
  591. package/dist/lib/runtime/codex-adapter.js.map +1 -1
  592. package/dist/lib/runtime/codex-config.d.ts +129 -0
  593. package/dist/lib/runtime/codex-config.d.ts.map +1 -1
  594. package/dist/lib/runtime/codex-config.js +225 -0
  595. package/dist/lib/runtime/codex-config.js.map +1 -1
  596. package/dist/lib/runtime/identity.d.ts +72 -0
  597. package/dist/lib/runtime/identity.d.ts.map +1 -0
  598. package/dist/lib/runtime/identity.js +128 -0
  599. package/dist/lib/runtime/identity.js.map +1 -0
  600. package/dist/lib/standards.d.ts +99 -0
  601. package/dist/lib/standards.d.ts.map +1 -0
  602. package/dist/lib/standards.js +201 -0
  603. package/dist/lib/standards.js.map +1 -0
  604. package/dist/lib/team-identity.d.ts +134 -0
  605. package/dist/lib/team-identity.d.ts.map +1 -0
  606. package/dist/lib/team-identity.js +193 -0
  607. package/dist/lib/team-identity.js.map +1 -0
  608. package/dist/lib/templates.d.ts +29 -2
  609. package/dist/lib/templates.d.ts.map +1 -1
  610. package/dist/lib/templates.js +1042 -82
  611. package/dist/lib/templates.js.map +1 -1
  612. package/dist/lib/terminal-ui.d.ts.map +1 -1
  613. package/dist/lib/terminal-ui.js +12 -1
  614. package/dist/lib/terminal-ui.js.map +1 -1
  615. package/dist/lib/test-project.d.ts +95 -0
  616. package/dist/lib/test-project.d.ts.map +1 -0
  617. package/dist/lib/test-project.js +103 -0
  618. package/dist/lib/test-project.js.map +1 -0
  619. package/dist/lib/vault.d.ts +60 -0
  620. package/dist/lib/vault.d.ts.map +1 -0
  621. package/dist/lib/vault.js +102 -0
  622. package/dist/lib/vault.js.map +1 -0
  623. package/dist/lib/vault.test.d.ts +17 -0
  624. package/dist/lib/vault.test.d.ts.map +1 -0
  625. package/dist/lib/vault.test.js +169 -0
  626. package/dist/lib/vault.test.js.map +1 -0
  627. package/dist/lib/window-view.d.ts +63 -0
  628. package/dist/lib/window-view.d.ts.map +1 -0
  629. package/dist/lib/window-view.js +217 -0
  630. package/dist/lib/window-view.js.map +1 -0
  631. package/dist/lib/window-view.test.d.ts +2 -0
  632. package/dist/lib/window-view.test.d.ts.map +1 -0
  633. package/dist/lib/window-view.test.js +168 -0
  634. package/dist/lib/window-view.test.js.map +1 -0
  635. package/dist/lib/worktree-sync.d.ts +439 -0
  636. package/dist/lib/worktree-sync.d.ts.map +1 -0
  637. package/dist/lib/worktree-sync.js +1167 -0
  638. package/dist/lib/worktree-sync.js.map +1 -0
  639. package/dist/lib/worktree.d.ts +58 -1
  640. package/dist/lib/worktree.d.ts.map +1 -1
  641. package/dist/lib/worktree.js +91 -4
  642. package/dist/lib/worktree.js.map +1 -1
  643. package/dist/standards/decision-request.md +98 -0
  644. package/dist/standards/fail-loud-standard.md +495 -0
  645. package/dist/standards/po-communication-standard.md +126 -0
  646. package/dist/standards/report-format.md +128 -0
  647. package/dist/standards/writing-standard.md +382 -0
  648. package/package.json +3 -2
  649. package/scripts/generate-claude.mjs +119 -46
@@ -10,9 +10,10 @@
10
10
  * only a local durable fallback file and flushes it on the next success.
11
11
  */
12
12
  import { existsSync, readFileSync, writeFileSync, readdirSync, statSync, realpathSync } from 'node:fs';
13
+ import { spawnSync } from 'node:child_process';
13
14
  import { join } from 'node:path';
14
15
  import { HttpCoordinationClient, resolveClientConfig, resolveCoordinationMode, ServiceUnreachableError, ServiceHttpError, CONFIG_KEY_URL, } from '../lib/coordination-client.js';
15
- import { resolveCoordinationToken, refreshCoordinationToken, } from '../lib/coordination-token.js';
16
+ import { resolveCoordinationToken, refreshCoordinationToken, usesCredentialEndpoint, ENV_KEY_EXPECT_PROJECT, ENV_KEY_EXPECT_TEAM, } from '../lib/coordination-token.js';
16
17
  import { isValidProjectSlug, invalidProjectSlugMessage } from '../lib/slug.js';
17
18
  import { appendFallbackEntry, flushFallback } from '../lib/coordination-fallback.js';
18
19
  import { renderMessages, renderRoutingDescription, renderPipelineExtractionWarning, findOverBudgetDropped, } from '../lib/coordination-render.js';
@@ -229,7 +230,7 @@ function authFailureMessage(res, retried) {
229
230
  else {
230
231
  lines.push(' No token refresh was available for this invocation.');
231
232
  }
232
- lines.push(' What to do:', ' 1. mx-agent coordination status — confirm this worktree\'s identity', ' 2. mx-agent coordination brief — run it by hand and read the full error', ' 3. Still rejected? This team\'s token needs re-issuing — tell the platform team (P1).');
233
+ lines.push(' What to do:', ' 1. mx-agent coordination status — confirm this worktree\'s identity', ' 2. mx-agent coordination brief — run it by hand and read the full error', ' 3. Still rejected? This team\'s token needs re-issuing. Run `az login` in this worktree.', ' Filing an escalation from here queues locally and will not reach `bootstrap` until a token works again.');
233
234
  return lines.join('\n');
234
235
  }
235
236
  /**
@@ -304,7 +305,9 @@ class AuthRetryingClient {
304
305
  const rejected = this.currentToken ?? process.env.MX_COORD_SERVICE_TOKEN ?? '';
305
306
  let res;
306
307
  try {
307
- res = this.refresh(rejected);
308
+ // `await` because the credential path (#288) is an HTTP request; a
309
+ // synchronous test double is awaited unchanged.
310
+ res = await this.refresh(rejected);
308
311
  }
309
312
  catch (refreshErr) {
310
313
  // refreshCoordinationToken is documented never-throws; belt and braces —
@@ -369,7 +372,7 @@ export function withTokenRefresh(inner, rebuild, refresh, initialToken) {
369
372
  * still goes through env — it is read by the session-start hook in another process,
370
373
  * which is the whole point of it.
371
374
  */
372
- export function prepareClient(deps) {
375
+ export async function prepareClient(deps) {
373
376
  if (deps?.client) {
374
377
  // Provisioning is still skipped for an injected client, but the 401 recovery
375
378
  // wrapper is NOT: it is the single path every command goes through, and a
@@ -388,7 +391,31 @@ export function prepareClient(deps) {
388
391
  // hiccup must never crash `mx-agent coordination brief` (breaks session start).
389
392
  let res = { status: 'unprovisioned', detail: 'token resolution failed' };
390
393
  try {
391
- res = resolveCoordinationToken();
394
+ // #290 Must Fix 3: arm the #220 interlock EXPLICITLY.
395
+ //
396
+ // What this changes and what it does not, stated exactly. The interlock
397
+ // already falls back to these two environment variables inside
398
+ // `identityInterlockMismatch`, so passing them here is the same comparison
399
+ // made visible at the call site rather than a new one: a mutation test that
400
+ // removes this argument still refuses when the variables are set. It is here
401
+ // so the contract is greppable and so a future caller cannot assume the
402
+ // resolver invents an assertion of its own.
403
+ //
404
+ // The substantive half of Must Fix 3 is in `start.ts`, which asserts the team
405
+ // it was ASKED to start, a value that does not come from the worktree.
406
+ //
407
+ // What neither fixes: a bare `coordination brief` in a worktree, with these
408
+ // variables unset, has no second source for the team. The marker is the
409
+ // authoritative one, and comparing it with itself proves nothing, so the
410
+ // interlock cannot fire on that path. The arming below at `??=` is exactly
411
+ // that self-comparison and is why this was reported as never armed. Closing
412
+ // that needs a source outside the worktree, which is #220's own fix.
413
+ res = await resolveCoordinationToken({
414
+ expect: {
415
+ project: process.env[ENV_KEY_EXPECT_PROJECT],
416
+ team: process.env[ENV_KEY_EXPECT_TEAM],
417
+ },
418
+ });
392
419
  let provisioned;
393
420
  if (res.status === 'resolved' && res.token) {
394
421
  // Handed to resolveClientConfig as an override — in-process, never env, never
@@ -398,7 +425,7 @@ export function prepareClient(deps) {
398
425
  // self-provisioned path, matching the hook (which set MX_COORD_EXPECT_TEAM).
399
426
  // `??=` so an explicit hook-set value is never overwritten. Not a secret.
400
427
  if (res.slug)
401
- process.env.MX_COORD_EXPECT_TEAM ??= res.slug;
428
+ process.env[ENV_KEY_EXPECT_TEAM] ??= res.slug;
402
429
  }
403
430
  const cfg = resolveClientConfig({ token: provisioned });
404
431
  // #4970: every provisioned client recovers from a rotated token — invalidate
@@ -415,6 +442,35 @@ export function prepareClient(deps) {
415
442
  ` To check status: mx-agent coordination status\n` +
416
443
  ` Falling back to memory-based coordination for this session.\n`);
417
444
  }
445
+ else if (res.status === 'identity-mismatch') {
446
+ // #220: the resolved identity is not the one the caller asserted. No
447
+ // credential was requested. Both slugs are in res.detail and neither is a
448
+ // secret.
449
+ process.stderr.write(`coordination: refusing to obtain a credential — ${res.detail}\n` +
450
+ ` Falling back to memory-based coordination for this session.\n`);
451
+ }
452
+ else if (res.status === 'invalid-key') {
453
+ // Names the KEY. Says nothing about the team.
454
+ process.stderr.write(`coordination: ${res.detail}\n` +
455
+ ` Falling back to memory-based coordination for this session.\n`);
456
+ }
457
+ else if (res.status === 'not-authorized') {
458
+ // Fixed wording, identical whether the team exists or not. Nothing is added
459
+ // here that would distinguish the two cases.
460
+ process.stderr.write(`coordination: ${res.detail}\n` +
461
+ ` Falling back to memory-based coordination for this session.\n`);
462
+ }
463
+ else if (res.status === 'limit-reached') {
464
+ // A refusal (#507): fixed wording naming the limits, never "retry".
465
+ process.stderr.write(`coordination: ${res.detail}\n` +
466
+ ` Falling back to memory-based coordination for this session.\n`);
467
+ }
468
+ else if (res.status === 'unavailable') {
469
+ // Could-not-run, reported as itself. Never "unprovisioned": nothing is
470
+ // missing and there is nothing for an operator to provision.
471
+ process.stderr.write(`coordination: ${res.detail}\n` +
472
+ ` Falling back to memory-based coordination for this session.\n`);
473
+ }
418
474
  else if (res.status === 'misconfigured') {
419
475
  // Fail-CLOSED on an invalid explicitly-set project slug: name the offending
420
476
  // value + rule (res.detail) so the operator can fix the config. We do NOT
@@ -794,7 +850,7 @@ export async function runEscalate(opts, deps) {
794
850
  }
795
851
  const team = resolveTeam(opts.team);
796
852
  const entry = { team, to: opts.to, priority: opts.priority, body, from: team };
797
- const client = prepareClient(deps);
853
+ const client = await prepareClient(deps);
798
854
  if (!client) {
799
855
  // No token/URL could be provisioned (prepareClient already printed the reason).
800
856
  // Degrade to the local fallback so the message is never lost.
@@ -866,7 +922,7 @@ export async function runDrain(opts, deps) {
866
922
  memoryModeQueueOnlyNote('drain');
867
923
  return; // exit 0 — no crash
868
924
  }
869
- const client = prepareClient(deps);
925
+ const client = await prepareClient(deps);
870
926
  if (!client)
871
927
  return; // could not provision — fall back (prepareClient printed why)
872
928
  // Flush any queued-locally entries now that the service is reachable.
@@ -920,7 +976,7 @@ export async function runBrief(opts = {}, deps) {
920
976
  if (resolveCoordinationMode() === 'memory') {
921
977
  return runBriefMemory(opts, deps);
922
978
  }
923
- const client = prepareClient(deps);
979
+ const client = await prepareClient(deps);
924
980
  if (!client)
925
981
  return; // could not provision — fall back (prepareClient printed why)
926
982
  await opportunisticFlush(client);
@@ -1024,7 +1080,7 @@ export async function runWatch(opts = {}, deps) {
1024
1080
  memoryModeQueueOnlyNote('watch');
1025
1081
  return; // exit 0 — no crash
1026
1082
  }
1027
- const client = prepareClient(deps);
1083
+ const client = await prepareClient(deps);
1028
1084
  if (!client)
1029
1085
  return; // could not provision — fall back (prepareClient printed why)
1030
1086
  const intervalMs = opts.intervalMs ?? envInt('MX_COORD_PRIORITY_POLL_MS', 15_000);
@@ -1117,7 +1173,7 @@ export async function runRespond(opts, deps) {
1117
1173
  console.error('Note: "open" and "acked" are set automatically by the system.');
1118
1174
  process.exit(1);
1119
1175
  }
1120
- const client = prepareClient(deps);
1176
+ const client = await prepareClient(deps);
1121
1177
  if (!client)
1122
1178
  return;
1123
1179
  try {
@@ -1146,7 +1202,7 @@ export async function runObligations(deps) {
1146
1202
  memoryModeQueueOnlyNote('obligations');
1147
1203
  return;
1148
1204
  }
1149
- const client = prepareClient(deps);
1205
+ const client = await prepareClient(deps);
1150
1206
  if (!client)
1151
1207
  return;
1152
1208
  try {
@@ -1189,7 +1245,7 @@ export async function runAck(messageId, deps) {
1189
1245
  memoryModeQueueOnlyNote('ack');
1190
1246
  return; // exit 0 — no crash
1191
1247
  }
1192
- const client = prepareClient(deps);
1248
+ const client = await prepareClient(deps);
1193
1249
  if (!client)
1194
1250
  return; // could not provision — fall back (prepareClient printed why)
1195
1251
  await client.ack(messageId);
@@ -1272,7 +1328,7 @@ export async function runHistory(opts = {}, deps) {
1272
1328
  memoryModeQueueOnlyNote('history');
1273
1329
  return; // exit 0 — no crash
1274
1330
  }
1275
- const client = prepareClient(deps);
1331
+ const client = await prepareClient(deps);
1276
1332
  if (!client)
1277
1333
  return; // could not provision — fall back (prepareClient printed why)
1278
1334
  const collected = [];
@@ -1460,9 +1516,20 @@ function howToGetMore(s) {
1460
1516
  return 'Re-run with --all to follow the pagination cursor through the full archive.';
1461
1517
  return 'Re-run to page further.';
1462
1518
  }
1463
- // ── status (local diagnostics, no auth required) ─────────────────────
1519
+ // ── status (diagnostics; asks the live service when a bearer resolves) ──
1464
1520
  /**
1465
- * Load the offline roster for a project from the generated roster file.
1521
+ * Load the offline roster for a project from the generated roster file at
1522
+ * `findProjectRoot()`.
1523
+ *
1524
+ * This reads a WORKING TREE, and `findProjectRoot` skips linked worktrees
1525
+ * (`worktree.ts:26-33`), so in a worktree it resolves to the shared main
1526
+ * checkout. That checkout is nobody's job to keep current and was measured 24
1527
+ * commits behind origin/main on 2026-09-02. `status` no longer uses this for
1528
+ * the registration question (#376); `resolveRegistration` does, and it prefers
1529
+ * the live service and states the provenance of every offline answer. The one
1530
+ * remaining caller is `runEscalate`, which uses it to name valid targets before
1531
+ * a send, where the service revalidates and refuses an unknown team anyway.
1532
+ *
1466
1533
  * Returns an empty array on any failure (missing file, parse error).
1467
1534
  */
1468
1535
  function loadOfflineRoster(projectSlug) {
@@ -1544,10 +1611,395 @@ export function oversizeBodyWarning(body) {
1544
1611
  `\`mx-agent coordination history\` renders up to ${HISTORY_BODY_MAX_CHARS} chars of it. Put the conclusion in the first ` +
1545
1612
  `${MESSAGE_BODY_MAX_CHARS} chars, or split the message (#5188).\n`);
1546
1613
  }
1614
+ // ── registration resolution (#376) ───────────────────────────────────
1547
1615
  /**
1548
- * `mx-agent coordination status` — display local coordination state and
1549
- * service health without requiring authentication. Designed for debugging
1550
- * "am I on the queue?" questions (PO P1 request, issue #4142).
1616
+ * The roster file, relative to a project root. Same path `resolveRoster` reads
1617
+ * in coordination-token.ts, and the same one `loadOfflineRoster` reads above.
1618
+ */
1619
+ const ROSTER_REL_PATH = join('mx-agent-system', 'agent-config', 'coordination-rosters.generated.json');
1620
+ /** Cap on the `git show` used for the origin-ref roster read. */
1621
+ const ORIGIN_ROSTER_TIMEOUT_MS = 5_000;
1622
+ const ORIGIN_ROSTER_MAX_BYTES = 1024 * 1024;
1623
+ /**
1624
+ * Read the roster from `origin/<baseBranch>` through the git object store.
1625
+ *
1626
+ * This is the ref the rest of the tooling deploys from — `syncClaudeConfig`
1627
+ * materialises `.claude/` from the same place (`claude.ts:1170`). Refs and
1628
+ * objects are shared between the main checkout and every linked worktree, so
1629
+ * this answer does not depend on which working tree the command runs in. That is
1630
+ * the whole defect in `loadOfflineRoster`: it reads a working tree, and
1631
+ * `findProjectRoot` resolves that to the shared main checkout, which nobody
1632
+ * keeps current.
1633
+ *
1634
+ * `spawnSync` with an argument array runs no shell. `baseBranch` comes from the
1635
+ * committed project config and is interpolated into the rev exactly as
1636
+ * `lib/claude.ts:1170` and `lib/config-generation.ts:55` already interpolate it.
1637
+ */
1638
+ export function readOriginRefRoster(cwd, baseBranch, projectSlug) {
1639
+ const ref = `origin/${baseBranch}`;
1640
+ let out;
1641
+ try {
1642
+ out = spawnSync('git', ['show', `${ref}:${ROSTER_REL_PATH}`], {
1643
+ cwd,
1644
+ encoding: 'utf-8',
1645
+ stdio: 'pipe',
1646
+ timeout: ORIGIN_ROSTER_TIMEOUT_MS,
1647
+ maxBuffer: ORIGIN_ROSTER_MAX_BYTES,
1648
+ env: gitChildEnv(),
1649
+ });
1650
+ }
1651
+ catch (err) {
1652
+ return { teams: null, source: ref, error: `git show failed (${err instanceof Error ? err.name : 'error'})` };
1653
+ }
1654
+ // Three failures, told apart. A missing git binary, a timeout and a killed
1655
+ // process all set `out.error`; only a nonzero exit means git ran and refused.
1656
+ // Reporting the first as "the ref does not hold this file" sends an operator
1657
+ // to look at a ref when the problem is their PATH.
1658
+ if (out.error) {
1659
+ return { teams: null, source: ref, error: `git could not be run (${out.error.name}: ${out.error.message})` };
1660
+ }
1661
+ if (out.status !== 0 || typeof out.stdout !== 'string' || out.stdout === '') {
1662
+ return { teams: null, source: ref, error: `${ref} does not hold ${ROSTER_REL_PATH} (is the remote fetched?)` };
1663
+ }
1664
+ let parsed;
1665
+ try {
1666
+ parsed = JSON.parse(out.stdout);
1667
+ }
1668
+ catch {
1669
+ return { teams: null, source: ref, error: `the roster on ${ref} is not valid JSON` };
1670
+ }
1671
+ const sha = originRefSha(cwd, ref);
1672
+ const source = `offline roster from ${ROSTER_REL_PATH} at ${ref}${sha ? ` (${sha})` : ''}`;
1673
+ const teams = parsed.projects?.[projectSlug];
1674
+ return { teams: Array.isArray(teams) ? teams : [], source };
1675
+ }
1676
+ /** Short sha for a ref, or undefined. Advisory: it makes staleness checkable. */
1677
+ function originRefSha(cwd, ref) {
1678
+ try {
1679
+ const r = spawnSync('git', ['rev-parse', '--short', ref], {
1680
+ cwd, encoding: 'utf-8', stdio: 'pipe', timeout: ORIGIN_ROSTER_TIMEOUT_MS, env: gitChildEnv(),
1681
+ });
1682
+ if (r.status !== 0 || typeof r.stdout !== 'string')
1683
+ return undefined;
1684
+ const sha = r.stdout.trim();
1685
+ return sha === '' ? undefined : sha;
1686
+ }
1687
+ catch {
1688
+ return undefined;
1689
+ }
1690
+ }
1691
+ /**
1692
+ * The environment for the git children this file spawns, with every coordination
1693
+ * bearer removed.
1694
+ *
1695
+ * `resolveClientConfig` reads a token from `process.env.MX_COORD_SERVICE_TOKEN`
1696
+ * (`coordination-client.ts:432`), so that variable can hold a live bearer, and a
1697
+ * spawned child inherits the whole environment by default. `prepareClient`'s own
1698
+ * doc comment (above, on this file) named this exact future: the env write "was
1699
+ * harmless while nothing on these paths spawned a child ... a bearer in the
1700
+ * environment is inherited by any subprocess a future change adds." This is that
1701
+ * change — `status` is the first coordination path to spawn one.
1702
+ *
1703
+ * No exfiltration path was found for these two calls: `git show` and
1704
+ * `git rev-parse` against a local object store invoke no hook, no pager and no
1705
+ * credential helper. The control is nonetheless absent rather than unnecessary,
1706
+ * and a later reader adding a third git call should inherit the stripped env by
1707
+ * default rather than rediscover the reasoning.
1708
+ */
1709
+ export function gitChildEnv() {
1710
+ const env = { ...process.env };
1711
+ delete env.MX_COORD_SERVICE_TOKEN;
1712
+ delete env.MX_COORD_ADMIN_TOKEN;
1713
+ delete env.MX_API_KEY;
1714
+ return env;
1715
+ }
1716
+ /**
1717
+ * Read the roster from a working-tree file, stating the path and its mtime.
1718
+ *
1719
+ * Every answer from here is `could-not-verify` at the caller, whatever the file
1720
+ * says. A working tree's age is not knowable from inside it, so a yes from this
1721
+ * source is exactly as unverified as a no.
1722
+ */
1723
+ export function readWorkingTreeRoster(path, projectSlug) {
1724
+ if (!existsSync(path))
1725
+ return { teams: null, source: path, error: `no roster file at ${path}` };
1726
+ let mtime = 'unknown mtime';
1727
+ try {
1728
+ mtime = statSync(path).mtime.toISOString();
1729
+ }
1730
+ catch {
1731
+ /* the read below is what matters; an unstattable file still reports its path */
1732
+ }
1733
+ const source = `offline roster from ${path} at mtime ${mtime}`;
1734
+ try {
1735
+ const parsed = JSON.parse(readFileSync(path, 'utf-8'));
1736
+ const teams = parsed.projects?.[projectSlug];
1737
+ return { teams: Array.isArray(teams) ? teams : [], source };
1738
+ }
1739
+ catch {
1740
+ return { teams: null, source, error: `${path} could not be read or parsed` };
1741
+ }
1742
+ }
1743
+ /**
1744
+ * Whether an offline roster may REFUSE for this project, or may only fail to
1745
+ * confirm.
1746
+ *
1747
+ * For `mx-agent` and `mx-agent-test` the roster file is explicitly not the
1748
+ * registration authority: `coordination-token.ts:865-869` states the service's
1749
+ * grant table authorizes, and that "a local roster file that predates a
1750
+ * registration would refuse a team the service admits". `mx-agent-test` is
1751
+ * stronger still — `coordination-token.ts:133-139` documents that NO OPERATOR
1752
+ * AUTHORISES THE TEST TEAM, because the service auto-enrols it on its first
1753
+ * credential request, so a registration can exist with no roster commit anywhere.
1754
+ *
1755
+ * The window this closes: team provisioned on the service, roster commit still in
1756
+ * an unmerged pull request, no bearer resolves. Refusing there would be #376's own
1757
+ * defect one source deeper — a confident no computed from a file that is not the
1758
+ * authority, wearing an `origin/<base> (<sha>)` provenance string that makes it
1759
+ * look checked.
1760
+ */
1761
+ function offlineRosterMayRefuse(projectSlug) {
1762
+ return !usesCredentialEndpoint(projectSlug);
1763
+ }
1764
+ /** Say WHICH of the two reasons stopped an offline absence from being a refusal. */
1765
+ function unverifiableAbsenceReason(projectSlug, teamSlugAuthoritative, liveReason) {
1766
+ const why = [];
1767
+ if (!offlineRosterMayRefuse(projectSlug)) {
1768
+ why.push(`on project "${projectSlug}" the coordination service's grant table is the registration authority, not the roster file, and it can hold a team the file does not`);
1769
+ }
1770
+ if (!teamSlugAuthoritative) {
1771
+ why.push('the team name came from the worktree name, not the .mx-coordination-team marker, so it may not be the team slug at all');
1772
+ }
1773
+ return `${why.join('; ')}. The live service was not asked: ${liveReason}`;
1774
+ }
1775
+ /**
1776
+ * Resolve the base branch to read the roster from, preferring the worktree's own
1777
+ * committed config over the shared checkout's. Defaults to `main` on any failure:
1778
+ * this is a status line, and it must never throw.
1779
+ */
1780
+ function resolveBaseBranch(worktreePath) {
1781
+ for (const root of [worktreePath, safeProjectRoot()]) {
1782
+ if (!root)
1783
+ continue;
1784
+ try {
1785
+ const branch = loadProjectConfig(root)?.baseBranch;
1786
+ if (branch)
1787
+ return branch;
1788
+ }
1789
+ catch {
1790
+ /* an unreadable or refused config is not a base branch; try the next root */
1791
+ }
1792
+ }
1793
+ return 'main';
1794
+ }
1795
+ function safeProjectRoot() {
1796
+ try {
1797
+ return findProjectRoot();
1798
+ }
1799
+ catch {
1800
+ return undefined;
1801
+ }
1802
+ }
1803
+ /**
1804
+ * Answer "is this team on the coordination queue?" and say who answered.
1805
+ *
1806
+ * Order, and the reason for it: the live service is the only authority that is
1807
+ * never stale, so it is asked first whenever a credential resolves. The offline
1808
+ * roster is a fallback, and a fallback that cannot say how old it is must not be
1809
+ * allowed to print a refusal.
1810
+ *
1811
+ * A refusal therefore needs THREE things to be true, not one. The answer must be
1812
+ * a no; the source must be entitled to refuse for this project
1813
+ * (`offlineRosterMayRefuse` — on `mx-agent` and `mx-agent-test` no offline source
1814
+ * ever is, because the service's grant table is the authority and auto-enrolment
1815
+ * can register a team with no roster commit anywhere); and the name asked about
1816
+ * must be the marker's, not the worktree's. Any other combination is
1817
+ * could-not-verify, which is why that outcome exists.
1818
+ *
1819
+ * The live probe is `GET /obligations`. It is the cheapest existing authenticated
1820
+ * read: it mutates nothing, it leases nothing (unlike `/drain`, which is what
1821
+ * `brief` calls and which hands back a batch to confirm), and it returns
1822
+ * obligation metadata with no message bodies, so a self-check never pulls
1823
+ * coordination content into the process. A 200 proves the service authenticated
1824
+ * this team's bearer and resolved it to a (project, team), which is the
1825
+ * registration question exactly. No new endpoint is added.
1826
+ *
1827
+ * Never throws.
1828
+ */
1829
+ export async function resolveRegistration(projectSlug, teamSlug, deps = {}) {
1830
+ const env = deps.env ?? process.env;
1831
+ const worktreePath = env.CLAUDE_WORKTREE_PATH;
1832
+ const teamSlugAuthoritative = deps.teamSlugAuthoritative ?? true;
1833
+ // 1. Live path. An injected client is probed directly; otherwise a credential
1834
+ // must resolve first.
1835
+ let client = deps.client ?? null;
1836
+ let credentialResolved = client !== null;
1837
+ let liveReason = 'no live check was attempted';
1838
+ if (!client) {
1839
+ let res;
1840
+ try {
1841
+ res = deps.resolveToken ? await deps.resolveToken() : await resolveCoordinationToken();
1842
+ }
1843
+ catch (err) {
1844
+ res = { status: 'unavailable', detail: `token resolution threw (${err instanceof Error ? err.name : 'error'})` };
1845
+ }
1846
+ // A 409 from the credential endpoint is the SERVICE saying this team is not
1847
+ // registered. That is a live no, and it is the one `not-on-roster` that is.
1848
+ // On a project that does not use the credential endpoint the same status
1849
+ // comes from the offline roster gate in resolveIdentity, which is a file and
1850
+ // must not print a refusal — so the source of the status decides, not its name.
1851
+ if (res.status === 'not-on-roster' && usesCredentialEndpoint(projectSlug)) {
1852
+ return {
1853
+ verdict: 'not-registered',
1854
+ kind: 'live',
1855
+ source: 'the live coordination service (credential endpoint answered: team not registered)',
1856
+ credentialResolved: false,
1857
+ };
1858
+ }
1859
+ if ((res.status === 'resolved' || res.status === 'already-configured') && res.token) {
1860
+ credentialResolved = true;
1861
+ // Build the client here rather than through `prepareClient`.
1862
+ //
1863
+ // `prepareClient` reports its own failures on stderr, including the fixed
1864
+ // line `coordination: team "<slug>" is not registered on the coordination
1865
+ // queue.` and, on its final else, `falling back to the manual channel`
1866
+ // (this file, the catch chain in prepareClient). Both bypass the verdict
1867
+ // machinery, so `status` could print `unverified` on stdout while stderr
1868
+ // asserted a refusal, and a diagnostic would be announcing a session
1869
+ // fallback it is not performing. Building here keeps ONE voice: this
1870
+ // function's return value.
1871
+ //
1872
+ // The 401 recovery is preserved verbatim — same wrapper, same rebuild, same
1873
+ // refresh — so a rotated bearer is still retried rather than reported as a
1874
+ // missing team. The bearer is passed through ClientConfig only: never the
1875
+ // process env, never the global config (SF-2 of the #5188/#5189 review).
1876
+ try {
1877
+ const cfg = resolveClientConfig({ token: res.token });
1878
+ client = withTokenRefresh(new HttpCoordinationClient(cfg), (token) => new HttpCoordinationClient({ ...cfg, token }), refreshCoordinationToken, cfg.token);
1879
+ }
1880
+ catch (err) {
1881
+ // The only throw here is resolveClientConfig's: no service URL, or a URL
1882
+ // that fails the suffix gate. Both are configuration, not registration.
1883
+ client = null;
1884
+ liveReason = `a bearer resolved but no coordination client could be built (${err instanceof Error ? err.message : 'configuration error'})`;
1885
+ }
1886
+ }
1887
+ else {
1888
+ liveReason = `no coordination credential resolved (${res.status}${res.detail ? `: ${res.detail}` : ''})`;
1889
+ }
1890
+ }
1891
+ // 2. Probe.
1892
+ if (client) {
1893
+ try {
1894
+ await client.getObligations();
1895
+ return {
1896
+ verdict: 'registered',
1897
+ kind: 'live',
1898
+ source: 'the live coordination service (GET /obligations answered for this team)',
1899
+ credentialResolved,
1900
+ };
1901
+ }
1902
+ catch (err) {
1903
+ if (err instanceof ServiceHttpError && err.status === 409) {
1904
+ return {
1905
+ verdict: 'not-registered',
1906
+ kind: 'live',
1907
+ source: 'the live coordination service (GET /obligations answered: team not registered)',
1908
+ credentialResolved,
1909
+ };
1910
+ }
1911
+ // Everything else is could-not-verify, and 403 deliberately so: the service
1912
+ // returns a byte-identical 403 whether the team exists or not
1913
+ // (coordination-token.ts:418-419), so it is not evidence either way.
1914
+ liveReason = describeLiveFailure(err);
1915
+ }
1916
+ }
1917
+ // 3. Offline fallback, in provenance order: the deploy ref first, a working
1918
+ // tree only if the ref cannot be read.
1919
+ const baseBranch = resolveBaseBranch(worktreePath);
1920
+ const gitCwd = worktreePath ?? safeProjectRoot();
1921
+ if (gitCwd) {
1922
+ const readOrigin = deps.readOriginRoster ?? readOriginRefRoster;
1923
+ const fromRef = readOrigin(gitCwd, baseBranch, projectSlug);
1924
+ if (fromRef.teams !== null) {
1925
+ if (fromRef.teams.includes(teamSlug)) {
1926
+ return {
1927
+ verdict: 'registered',
1928
+ kind: 'origin-ref',
1929
+ source: fromRef.source,
1930
+ reason: `the live service was not asked: ${liveReason}`,
1931
+ credentialResolved,
1932
+ };
1933
+ }
1934
+ // An absence on the ref is only a refusal where the file is the authority
1935
+ // and the name asked about is the real one. Neither holds for a
1936
+ // credential-endpoint project, and the second does not hold when the team
1937
+ // name came from the worktree name.
1938
+ if (offlineRosterMayRefuse(projectSlug) && teamSlugAuthoritative) {
1939
+ return {
1940
+ verdict: 'not-registered',
1941
+ kind: 'origin-ref',
1942
+ source: fromRef.source,
1943
+ reason: `the live service was not asked: ${liveReason}`,
1944
+ credentialResolved,
1945
+ };
1946
+ }
1947
+ return {
1948
+ verdict: 'could-not-verify',
1949
+ kind: 'origin-ref',
1950
+ source: `${fromRef.source} (does not list this team)`,
1951
+ reason: unverifiableAbsenceReason(projectSlug, teamSlugAuthoritative, liveReason),
1952
+ credentialResolved,
1953
+ };
1954
+ }
1955
+ liveReason = `${liveReason}; ${fromRef.error ?? 'the deploy ref could not be read'}`;
1956
+ }
1957
+ else {
1958
+ liveReason = `${liveReason}; no worktree or project root to read a git ref from`;
1959
+ }
1960
+ // 4. A working-tree file. Whatever it says, the verdict is could-not-verify.
1961
+ const filePath = join(gitCwd ?? '', ROSTER_REL_PATH);
1962
+ const readFile = deps.readFileRoster ?? readWorkingTreeRoster;
1963
+ const fromFile = gitCwd ? readFile(filePath, projectSlug) : { teams: null, source: 'no roster file', error: 'no project root' };
1964
+ const said = fromFile.teams === null
1965
+ ? 'could not be read'
1966
+ : fromFile.teams.includes(teamSlug) ? 'lists this team' : 'does not list this team';
1967
+ return {
1968
+ verdict: 'could-not-verify',
1969
+ kind: fromFile.teams === null ? 'none' : 'offline-file',
1970
+ source: `${fromFile.source} (${said})`,
1971
+ reason: liveReason,
1972
+ credentialResolved,
1973
+ };
1974
+ }
1975
+ /** Classify a live-probe failure into an operator line. Never includes a bearer. */
1976
+ function describeLiveFailure(err) {
1977
+ if (err instanceof ServiceUnreachableError)
1978
+ return 'the coordination service was unreachable';
1979
+ if (err instanceof CoordinationAuthError)
1980
+ return 'the coordination service refused this bearer (401) after a refresh';
1981
+ if (err instanceof ServiceHttpError) {
1982
+ if (err.status === 401)
1983
+ return 'the coordination service refused this bearer (401)';
1984
+ if (err.status === 403)
1985
+ return 'the coordination service answered 403, which is identical for a registered and an unregistered team';
1986
+ if (err.status === 404)
1987
+ return 'the coordination service has no /obligations route (service older than v2.55)';
1988
+ return `the coordination service answered HTTP ${err.status}`;
1989
+ }
1990
+ return `the live check failed (${err instanceof Error ? err.name : 'error'})`;
1991
+ }
1992
+ /**
1993
+ * `mx-agent coordination status` — display coordination state, service health,
1994
+ * and whether this team is on the queue. Designed for debugging "am I on the
1995
+ * queue?" questions (PO P1 request, issue #4142).
1996
+ *
1997
+ * Authentication is OPTIONAL, not absent (#376). When a bearer resolves, the
1998
+ * registration question is put to the live service, which is the only authority
1999
+ * that cannot be stale. When none resolves, the check falls back to the roster
2000
+ * on the deploy ref and then to a working-tree file, and it says which one
2001
+ * answered. Every path is crash-proof and every path terminates: a diagnostic
2002
+ * that hangs or throws is worse than one that says it could not tell.
1551
2003
  */
1552
2004
  export async function runStatus(deps) {
1553
2005
  // 1. Resolve project slug.
@@ -1556,6 +2008,11 @@ export async function runStatus(deps) {
1556
2008
  const worktreePath = process.env.CLAUDE_WORKTREE_PATH;
1557
2009
  let teamSlug = 'not set';
1558
2010
  let teamSource = '';
2011
+ // The marker is the authoritative team identity. Track whether it supplied the
2012
+ // name, because an offline roster lookup of a NON-authoritative name answers
2013
+ // about the wrong string: this box runs worktree `bootstrap-20260821` for team
2014
+ // `bootstrap`, and no roster will ever list the former.
2015
+ let teamSlugAuthoritative = false;
1559
2016
  if (worktreePath) {
1560
2017
  const markerPath = join(worktreePath, '.mx-coordination-team');
1561
2018
  try {
@@ -1564,6 +2021,7 @@ export async function runStatus(deps) {
1564
2021
  if (raw) {
1565
2022
  teamSlug = raw;
1566
2023
  teamSource = '';
2024
+ teamSlugAuthoritative = true;
1567
2025
  }
1568
2026
  }
1569
2027
  }
@@ -1614,11 +2072,21 @@ export async function runStatus(deps) {
1614
2072
  }
1615
2073
  }
1616
2074
  }
1617
- // 7. Check offline roster for this team.
1618
- const roster = loadOfflineRoster(projectSlug);
1619
- const onRoster = roster.includes(teamSlug);
1620
- // 8. Determine overall status.
1621
- const isReady = tokenCached && onRoster && serviceHealth === 'up';
2075
+ // 7. Answer the registration question, preferring the live service (#376).
2076
+ // The old check read the generated roster through findProjectRoot(), which
2077
+ // walks past a linked worktree to the shared main checkout. That checkout is
2078
+ // nobody's responsibility to keep current, so a team the service had already
2079
+ // registered read as absent and `status` printed a refusal.
2080
+ const registration = await resolveRegistration(projectSlug, teamSlug, {
2081
+ teamSlugAuthoritative,
2082
+ ...deps?.registration,
2083
+ });
2084
+ // 8. Determine overall status. A registered verdict from the live service
2085
+ // already proves a bearer worked, so the cache FILE is not required on that
2086
+ // path; it remains the signal on the offline one.
2087
+ const isReady = registration.verdict === 'registered' &&
2088
+ serviceHealth === 'up' &&
2089
+ (registration.credentialResolved || tokenCached);
1622
2090
  // 9. Print the summary.
1623
2091
  console.log('Coordination Queue Status');
1624
2092
  console.log('─'.repeat(25));
@@ -1628,6 +2096,7 @@ export async function runStatus(deps) {
1628
2096
  console.log(` Token cached: ${tokenCached ? 'yes' : 'no'}`);
1629
2097
  console.log(` Service URL: ${serviceUrl ?? 'not configured'}`);
1630
2098
  console.log(` Service health: ${serviceHealth}`);
2099
+ console.log(` Registered: ${registrationLine(registration)}`);
1631
2100
  if (isReady) {
1632
2101
  console.log(' Status: ✓ Ready — this team can send and receive coordination messages');
1633
2102
  console.log('');
@@ -1636,7 +2105,7 @@ export async function runStatus(deps) {
1636
2105
  console.log(' mx-agent coordination brief');
1637
2106
  console.log(' mx-agent coordination drain');
1638
2107
  }
1639
- else {
2108
+ else if (registration.verdict === 'not-registered') {
1640
2109
  console.log(' Status: ✗ Not registered — this team is not on the coordination queue');
1641
2110
  console.log('');
1642
2111
  console.log(' To register:');
@@ -1645,6 +2114,36 @@ export async function runStatus(deps) {
1645
2114
  console.log(' If setup fails (503), ask your project admin to provision your team,');
1646
2115
  console.log(' or set MX_COORD_ADMIN_TOKEN and retry.');
1647
2116
  }
2117
+ else if (registration.verdict === 'could-not-verify') {
2118
+ console.log(` Status: ? Could not verify — ${registration.reason ?? 'the live service did not answer'}`);
2119
+ console.log('');
2120
+ console.log(' This is not a refusal. The queue may hold this team; nothing here could');
2121
+ console.log(' confirm it. To get a live answer:');
2122
+ console.log(' mx-agent coordination brief # drains this team\'s own inbox');
2123
+ console.log(' mx-agent coordination setup # registers the team if it is absent');
2124
+ }
2125
+ else {
2126
+ // Registered, but something else is missing. Name what, rather than printing
2127
+ // a refusal for a team the check just confirmed (#376).
2128
+ const missing = [];
2129
+ if (serviceHealth !== 'up')
2130
+ missing.push(`service health is "${serviceHealth}"`);
2131
+ if (!registration.credentialResolved && !tokenCached)
2132
+ missing.push('no coordination token is cached or resolvable');
2133
+ console.log(` Status: ✓ Registered, not ready — ${missing.join('; ')}`);
2134
+ console.log('');
2135
+ console.log(' The team is on the queue. Fix the item named above, then re-run this check.');
2136
+ }
2137
+ }
2138
+ /**
2139
+ * The one line that says what the verdict is and who produced it (#344, #376).
2140
+ *
2141
+ * Verdict and source only. The `reason` is what the Status line below carries,
2142
+ * and printing it twice pushed the short answer off the top of the screen.
2143
+ */
2144
+ export function registrationLine(r) {
2145
+ const verdict = r.verdict === 'registered' ? 'yes' : r.verdict === 'not-registered' ? 'no' : 'unverified';
2146
+ return `${verdict} (source: ${r.source})`;
1648
2147
  }
1649
2148
  /**
1650
2149
  * A team file is RETIRED (a tombstone, not a live team) when its first non-empty