@memnexus-ai/mx-agent-cli 0.1.294 → 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 (637) 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 +89 -1
  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__/decision-check.test.d.ts +2 -0
  82. package/dist/__tests__/decision-check.test.d.ts.map +1 -0
  83. package/dist/__tests__/decision-check.test.js +105 -0
  84. package/dist/__tests__/decision-check.test.js.map +1 -0
  85. package/dist/__tests__/digest-team-omission.test.d.ts +15 -0
  86. package/dist/__tests__/digest-team-omission.test.d.ts.map +1 -0
  87. package/dist/__tests__/digest-team-omission.test.js +247 -0
  88. package/dist/__tests__/digest-team-omission.test.js.map +1 -0
  89. package/dist/__tests__/doctor-worktree-path.test.d.ts +17 -0
  90. package/dist/__tests__/doctor-worktree-path.test.d.ts.map +1 -0
  91. package/dist/__tests__/doctor-worktree-path.test.js +158 -0
  92. package/dist/__tests__/doctor-worktree-path.test.js.map +1 -0
  93. package/dist/__tests__/fleet-data.test.js +40 -7
  94. package/dist/__tests__/fleet-data.test.js.map +1 -1
  95. package/dist/__tests__/fleet-tmux.test.js +2 -2
  96. package/dist/__tests__/fleet-tmux.test.js.map +1 -1
  97. package/dist/__tests__/generate-claude.test.js +137 -3
  98. package/dist/__tests__/generate-claude.test.js.map +1 -1
  99. package/dist/__tests__/git-env.test.d.ts +14 -0
  100. package/dist/__tests__/git-env.test.d.ts.map +1 -0
  101. package/dist/__tests__/git-env.test.js +131 -0
  102. package/dist/__tests__/git-env.test.js.map +1 -0
  103. package/dist/__tests__/git-identity-isolation.test.d.ts +33 -0
  104. package/dist/__tests__/git-identity-isolation.test.d.ts.map +1 -0
  105. package/dist/__tests__/git-identity-isolation.test.js +626 -0
  106. package/dist/__tests__/git-identity-isolation.test.js.map +1 -0
  107. package/dist/__tests__/harness-extract.test.d.ts +19 -0
  108. package/dist/__tests__/harness-extract.test.d.ts.map +1 -0
  109. package/dist/__tests__/harness-extract.test.js +566 -0
  110. package/dist/__tests__/harness-extract.test.js.map +1 -0
  111. package/dist/__tests__/harness-wiring.test.d.ts +16 -0
  112. package/dist/__tests__/harness-wiring.test.d.ts.map +1 -0
  113. package/dist/__tests__/harness-wiring.test.js +469 -0
  114. package/dist/__tests__/harness-wiring.test.js.map +1 -0
  115. package/dist/__tests__/hook-heal.test.js +17 -0
  116. package/dist/__tests__/hook-heal.test.js.map +1 -1
  117. package/dist/__tests__/init-coordination-url.test.d.ts +11 -0
  118. package/dist/__tests__/init-coordination-url.test.d.ts.map +1 -0
  119. package/dist/__tests__/init-coordination-url.test.js +114 -0
  120. package/dist/__tests__/init-coordination-url.test.js.map +1 -0
  121. package/dist/__tests__/memory-autocreate.test.js +574 -8
  122. package/dist/__tests__/memory-autocreate.test.js.map +1 -1
  123. package/dist/__tests__/memory-log-result.test.d.ts +13 -0
  124. package/dist/__tests__/memory-log-result.test.d.ts.map +1 -0
  125. package/dist/__tests__/memory-log-result.test.js +113 -0
  126. package/dist/__tests__/memory-log-result.test.js.map +1 -0
  127. package/dist/__tests__/memory-named-exists.test.d.ts +16 -0
  128. package/dist/__tests__/memory-named-exists.test.d.ts.map +1 -0
  129. package/dist/__tests__/memory-named-exists.test.js +288 -0
  130. package/dist/__tests__/memory-named-exists.test.js.map +1 -0
  131. package/dist/__tests__/mx-agent-cli-pin-validation.test.js +23 -47
  132. package/dist/__tests__/mx-agent-cli-pin-validation.test.js.map +1 -1
  133. package/dist/__tests__/mx-agent-cli-version-pin.test.js +34 -88
  134. package/dist/__tests__/mx-agent-cli-version-pin.test.js.map +1 -1
  135. package/dist/__tests__/new-project-first-team.test.d.ts +15 -0
  136. package/dist/__tests__/new-project-first-team.test.d.ts.map +1 -0
  137. package/dist/__tests__/new-project-first-team.test.js +263 -0
  138. package/dist/__tests__/new-project-first-team.test.js.map +1 -0
  139. package/dist/__tests__/otel-env.test.d.ts +2 -0
  140. package/dist/__tests__/otel-env.test.d.ts.map +1 -0
  141. package/dist/__tests__/otel-env.test.js +127 -0
  142. package/dist/__tests__/otel-env.test.js.map +1 -0
  143. package/dist/__tests__/project-config.test.js +283 -1
  144. package/dist/__tests__/project-config.test.js.map +1 -1
  145. package/dist/__tests__/provision-behavioral-contract.test.js +96 -4
  146. package/dist/__tests__/provision-behavioral-contract.test.js.map +1 -1
  147. package/dist/__tests__/provision-catalog-precondition.test.d.ts +26 -0
  148. package/dist/__tests__/provision-catalog-precondition.test.d.ts.map +1 -0
  149. package/dist/__tests__/provision-catalog-precondition.test.js +620 -0
  150. package/dist/__tests__/provision-catalog-precondition.test.js.map +1 -0
  151. package/dist/__tests__/provision-completion-rows.test.d.ts +17 -0
  152. package/dist/__tests__/provision-completion-rows.test.d.ts.map +1 -0
  153. package/dist/__tests__/provision-completion-rows.test.js +3095 -0
  154. package/dist/__tests__/provision-completion-rows.test.js.map +1 -0
  155. package/dist/__tests__/provision-identity-gate.test.d.ts +20 -0
  156. package/dist/__tests__/provision-identity-gate.test.d.ts.map +1 -0
  157. package/dist/__tests__/provision-identity-gate.test.js +600 -0
  158. package/dist/__tests__/provision-identity-gate.test.js.map +1 -0
  159. package/dist/__tests__/provision-resume.test.d.ts +26 -0
  160. package/dist/__tests__/provision-resume.test.d.ts.map +1 -0
  161. package/dist/__tests__/provision-resume.test.js +1164 -0
  162. package/dist/__tests__/provision-resume.test.js.map +1 -0
  163. package/dist/__tests__/provision-roleguide-anchors.test.d.ts +27 -0
  164. package/dist/__tests__/provision-roleguide-anchors.test.d.ts.map +1 -0
  165. package/dist/__tests__/provision-roleguide-anchors.test.js +747 -0
  166. package/dist/__tests__/provision-roleguide-anchors.test.js.map +1 -0
  167. package/dist/__tests__/provision-skeleton-fill.test.d.ts +16 -0
  168. package/dist/__tests__/provision-skeleton-fill.test.d.ts.map +1 -0
  169. package/dist/__tests__/provision-skeleton-fill.test.js +488 -0
  170. package/dist/__tests__/provision-skeleton-fill.test.js.map +1 -0
  171. package/dist/__tests__/provision-teambuilder-flow.test.js +93 -7
  172. package/dist/__tests__/provision-teambuilder-flow.test.js.map +1 -1
  173. package/dist/__tests__/repo-guard-wiring.test.d.ts +21 -0
  174. package/dist/__tests__/repo-guard-wiring.test.d.ts.map +1 -0
  175. package/dist/__tests__/repo-guard-wiring.test.js +638 -0
  176. package/dist/__tests__/repo-guard-wiring.test.js.map +1 -0
  177. package/dist/__tests__/report-format.test.d.ts +2 -0
  178. package/dist/__tests__/report-format.test.d.ts.map +1 -0
  179. package/dist/__tests__/report-format.test.js +219 -0
  180. package/dist/__tests__/report-format.test.js.map +1 -0
  181. package/dist/__tests__/runtime-codex-gateway-pilot.test.d.ts +2 -0
  182. package/dist/__tests__/runtime-codex-gateway-pilot.test.d.ts.map +1 -0
  183. package/dist/__tests__/runtime-codex-gateway-pilot.test.js +309 -0
  184. package/dist/__tests__/runtime-codex-gateway-pilot.test.js.map +1 -0
  185. package/dist/__tests__/runtime-codex-gateway-provider.test.d.ts +2 -0
  186. package/dist/__tests__/runtime-codex-gateway-provider.test.d.ts.map +1 -0
  187. package/dist/__tests__/runtime-codex-gateway-provider.test.js +163 -0
  188. package/dist/__tests__/runtime-codex-gateway-provider.test.js.map +1 -0
  189. package/dist/__tests__/runtime-identity.test.d.ts +2 -0
  190. package/dist/__tests__/runtime-identity.test.d.ts.map +1 -0
  191. package/dist/__tests__/runtime-identity.test.js +117 -0
  192. package/dist/__tests__/runtime-identity.test.js.map +1 -0
  193. package/dist/__tests__/session-pause-provisioning.test.js +6 -1
  194. package/dist/__tests__/session-pause-provisioning.test.js.map +1 -1
  195. package/dist/__tests__/session-record-disclosure.test.d.ts +24 -0
  196. package/dist/__tests__/session-record-disclosure.test.d.ts.map +1 -0
  197. package/dist/__tests__/session-record-disclosure.test.js +494 -0
  198. package/dist/__tests__/session-record-disclosure.test.js.map +1 -0
  199. package/dist/__tests__/session.test.js +35 -0
  200. package/dist/__tests__/session.test.js.map +1 -1
  201. package/dist/__tests__/slug-validation.test.js +27 -21
  202. package/dist/__tests__/slug-validation.test.js.map +1 -1
  203. package/dist/__tests__/standards-injection.test.d.ts +2 -0
  204. package/dist/__tests__/standards-injection.test.d.ts.map +1 -0
  205. package/dist/__tests__/standards-injection.test.js +179 -0
  206. package/dist/__tests__/standards-injection.test.js.map +1 -0
  207. package/dist/__tests__/start-interactive-role.test.d.ts +22 -0
  208. package/dist/__tests__/start-interactive-role.test.d.ts.map +1 -0
  209. package/dist/__tests__/start-interactive-role.test.js +204 -0
  210. package/dist/__tests__/start-interactive-role.test.js.map +1 -0
  211. package/dist/__tests__/start-team-identity.test.d.ts +25 -0
  212. package/dist/__tests__/start-team-identity.test.d.ts.map +1 -0
  213. package/dist/__tests__/start-team-identity.test.js +307 -0
  214. package/dist/__tests__/start-team-identity.test.js.map +1 -0
  215. package/dist/__tests__/team-memory-commands.test.js +142 -19
  216. package/dist/__tests__/team-memory-commands.test.js.map +1 -1
  217. package/dist/__tests__/template-sync.test.d.ts +19 -0
  218. package/dist/__tests__/template-sync.test.d.ts.map +1 -0
  219. package/dist/__tests__/template-sync.test.js +270 -0
  220. package/dist/__tests__/template-sync.test.js.map +1 -0
  221. package/dist/__tests__/test-project.test.d.ts +18 -0
  222. package/dist/__tests__/test-project.test.d.ts.map +1 -0
  223. package/dist/__tests__/test-project.test.js +465 -0
  224. package/dist/__tests__/test-project.test.js.map +1 -0
  225. package/dist/__tests__/usage-per-call-grouping.test.d.ts +25 -0
  226. package/dist/__tests__/usage-per-call-grouping.test.d.ts.map +1 -0
  227. package/dist/__tests__/usage-per-call-grouping.test.js +952 -0
  228. package/dist/__tests__/usage-per-call-grouping.test.js.map +1 -0
  229. package/dist/__tests__/verify-hooks-check-all.test.d.ts +32 -0
  230. package/dist/__tests__/verify-hooks-check-all.test.d.ts.map +1 -0
  231. package/dist/__tests__/verify-hooks-check-all.test.js +553 -0
  232. package/dist/__tests__/verify-hooks-check-all.test.js.map +1 -0
  233. package/dist/__tests__/worktree-sync-fixture.test.d.ts +17 -0
  234. package/dist/__tests__/worktree-sync-fixture.test.d.ts.map +1 -0
  235. package/dist/__tests__/worktree-sync-fixture.test.js +519 -0
  236. package/dist/__tests__/worktree-sync-fixture.test.js.map +1 -0
  237. package/dist/__tests__/worktree-sync-hardening.test.d.ts +13 -0
  238. package/dist/__tests__/worktree-sync-hardening.test.d.ts.map +1 -0
  239. package/dist/__tests__/worktree-sync-hardening.test.js +919 -0
  240. package/dist/__tests__/worktree-sync-hardening.test.js.map +1 -0
  241. package/dist/__tests__/worktree-sync-shell-free.test.d.ts +25 -0
  242. package/dist/__tests__/worktree-sync-shell-free.test.d.ts.map +1 -0
  243. package/dist/__tests__/worktree-sync-shell-free.test.js +185 -0
  244. package/dist/__tests__/worktree-sync-shell-free.test.js.map +1 -0
  245. package/dist/__tests__/worktree.test.js +75 -1
  246. package/dist/__tests__/worktree.test.js.map +1 -1
  247. package/dist/agent-config/.mx-config-generation.json +2 -2
  248. package/dist/agent-config/AGENTS.md.template +2 -2
  249. package/dist/agent-config/agents/bar-raiser.md +34 -1
  250. package/dist/agent-config/agents/red-team.md +34 -1
  251. package/dist/agent-config/agents/security-reviewer.md +22 -1
  252. package/dist/agent-config/claude-md/CLAUDE.core.md +6 -1
  253. package/dist/agent-config/claude-md/CLAUDE.overlay.memnexus.md +1 -3
  254. package/dist/agent-config/coordination-rosters.generated.json +10 -0
  255. package/dist/agent-config/hooks/HOOK-TIMEOUTS.md +27 -1
  256. package/dist/agent-config/hooks/OR-TRUE-AUDIT.md +8 -8
  257. package/dist/agent-config/hooks/auto-capture-precompact.sh +180 -83
  258. package/dist/agent-config/hooks/auto-capture-session-end.sh +216 -87
  259. package/dist/agent-config/hooks/auto-checkpoint.sh +75 -5
  260. package/dist/agent-config/hooks/coordination-brief.sh +290 -245
  261. package/dist/agent-config/hooks/deploy-verification-reminder.sh +359 -22
  262. package/dist/agent-config/hooks/git-mutation-guard.sh +85 -13
  263. package/dist/agent-config/hooks/observability-sync.sh +46 -9
  264. package/dist/agent-config/hooks/session-idle-gate.sh +177 -12
  265. package/dist/agent-config/hooks/subagent-write-guard.sh +670 -0
  266. package/dist/agent-config/hooks/worktree-guard.sh +36 -7
  267. package/dist/agent-config/settings.json +15 -2
  268. package/dist/agent-config/shared/creation-pr-review-checklist.md +317 -0
  269. package/dist/commands/bootstrap.d.ts.map +1 -1
  270. package/dist/commands/bootstrap.js +22 -10
  271. package/dist/commands/bootstrap.js.map +1 -1
  272. package/dist/commands/config-sync.d.ts +37 -0
  273. package/dist/commands/config-sync.d.ts.map +1 -1
  274. package/dist/commands/config-sync.js +36 -18
  275. package/dist/commands/config-sync.js.map +1 -1
  276. package/dist/commands/config.d.ts.map +1 -1
  277. package/dist/commands/config.js +28 -1
  278. package/dist/commands/config.js.map +1 -1
  279. package/dist/commands/coordination.d.ts +150 -8
  280. package/dist/commands/coordination.d.ts.map +1 -1
  281. package/dist/commands/coordination.js +519 -25
  282. package/dist/commands/coordination.js.map +1 -1
  283. package/dist/commands/create.d.ts +913 -1
  284. package/dist/commands/create.d.ts.map +1 -1
  285. package/dist/commands/create.js +4879 -345
  286. package/dist/commands/create.js.map +1 -1
  287. package/dist/commands/dashboard.d.ts.map +1 -1
  288. package/dist/commands/dashboard.js +10 -2
  289. package/dist/commands/dashboard.js.map +1 -1
  290. package/dist/commands/decision.d.ts +20 -0
  291. package/dist/commands/decision.d.ts.map +1 -0
  292. package/dist/commands/decision.js +54 -0
  293. package/dist/commands/decision.js.map +1 -0
  294. package/dist/commands/digest.d.ts.map +1 -1
  295. package/dist/commands/digest.js +91 -7
  296. package/dist/commands/digest.js.map +1 -1
  297. package/dist/commands/fleet-tmux.js +1 -1
  298. package/dist/commands/fleet-tmux.js.map +1 -1
  299. package/dist/commands/init.d.ts +8 -0
  300. package/dist/commands/init.d.ts.map +1 -1
  301. package/dist/commands/init.js +26 -1
  302. package/dist/commands/init.js.map +1 -1
  303. package/dist/commands/list.d.ts +32 -1
  304. package/dist/commands/list.d.ts.map +1 -1
  305. package/dist/commands/list.js +98 -5
  306. package/dist/commands/list.js.map +1 -1
  307. package/dist/commands/monitor.d.ts.map +1 -1
  308. package/dist/commands/monitor.js +8 -2
  309. package/dist/commands/monitor.js.map +1 -1
  310. package/dist/commands/new.d.ts +2 -0
  311. package/dist/commands/new.d.ts.map +1 -1
  312. package/dist/commands/new.js +114 -21
  313. package/dist/commands/new.js.map +1 -1
  314. package/dist/commands/report.d.ts +33 -0
  315. package/dist/commands/report.d.ts.map +1 -0
  316. package/dist/commands/report.js +73 -0
  317. package/dist/commands/report.js.map +1 -0
  318. package/dist/commands/session.js +1 -1
  319. package/dist/commands/session.js.map +1 -1
  320. package/dist/commands/start.d.ts +42 -0
  321. package/dist/commands/start.d.ts.map +1 -1
  322. package/dist/commands/start.js +177 -8
  323. package/dist/commands/start.js.map +1 -1
  324. package/dist/commands/sync.d.ts +57 -0
  325. package/dist/commands/sync.d.ts.map +1 -1
  326. package/dist/commands/sync.js +117 -3
  327. package/dist/commands/sync.js.map +1 -1
  328. package/dist/commands/update.d.ts +13 -1
  329. package/dist/commands/update.d.ts.map +1 -1
  330. package/dist/commands/update.js +50 -1
  331. package/dist/commands/update.js.map +1 -1
  332. package/dist/commands/usage.d.ts +64 -0
  333. package/dist/commands/usage.d.ts.map +1 -1
  334. package/dist/commands/usage.js +96 -3
  335. package/dist/commands/usage.js.map +1 -1
  336. package/dist/commands/verify-hooks.d.ts +37 -1
  337. package/dist/commands/verify-hooks.d.ts.map +1 -1
  338. package/dist/commands/verify-hooks.js +114 -2
  339. package/dist/commands/verify-hooks.js.map +1 -1
  340. package/dist/commands/window.d.ts +10 -0
  341. package/dist/commands/window.d.ts.map +1 -0
  342. package/dist/commands/window.js +265 -0
  343. package/dist/commands/window.js.map +1 -0
  344. package/dist/commands/worktree-sync.d.ts +54 -0
  345. package/dist/commands/worktree-sync.d.ts.map +1 -0
  346. package/dist/commands/worktree-sync.js +135 -0
  347. package/dist/commands/worktree-sync.js.map +1 -0
  348. package/dist/index.d.ts.map +1 -1
  349. package/dist/index.js +189 -14
  350. package/dist/index.js.map +1 -1
  351. package/dist/lib/agent-session.d.ts +12 -0
  352. package/dist/lib/agent-session.d.ts.map +1 -1
  353. package/dist/lib/agent-session.js +189 -42
  354. package/dist/lib/agent-session.js.map +1 -1
  355. package/dist/lib/catalog.d.ts +321 -2
  356. package/dist/lib/catalog.d.ts.map +1 -1
  357. package/dist/lib/catalog.js +490 -11
  358. package/dist/lib/catalog.js.map +1 -1
  359. package/dist/lib/claude.d.ts +65 -23
  360. package/dist/lib/claude.d.ts.map +1 -1
  361. package/dist/lib/claude.js +335 -19
  362. package/dist/lib/claude.js.map +1 -1
  363. package/dist/lib/cli-build.d.ts +172 -0
  364. package/dist/lib/cli-build.d.ts.map +1 -0
  365. package/dist/lib/cli-build.js +654 -0
  366. package/dist/lib/cli-build.js.map +1 -0
  367. package/dist/lib/code-context-file.d.ts +109 -0
  368. package/dist/lib/code-context-file.d.ts.map +1 -0
  369. package/dist/lib/code-context-file.js +219 -0
  370. package/dist/lib/code-context-file.js.map +1 -0
  371. package/dist/lib/code-context-file.test.d.ts +19 -0
  372. package/dist/lib/code-context-file.test.d.ts.map +1 -0
  373. package/dist/lib/code-context-file.test.js +202 -0
  374. package/dist/lib/code-context-file.test.js.map +1 -0
  375. package/dist/lib/config-fidelity.d.ts +40 -20
  376. package/dist/lib/config-fidelity.d.ts.map +1 -1
  377. package/dist/lib/config-fidelity.js +144 -56
  378. package/dist/lib/config-fidelity.js.map +1 -1
  379. package/dist/lib/coordination-client.d.ts +73 -0
  380. package/dist/lib/coordination-client.d.ts.map +1 -1
  381. package/dist/lib/coordination-client.js +180 -8
  382. package/dist/lib/coordination-client.js.map +1 -1
  383. package/dist/lib/coordination-token.d.ts +304 -6
  384. package/dist/lib/coordination-token.d.ts.map +1 -1
  385. package/dist/lib/coordination-token.js +851 -52
  386. package/dist/lib/coordination-token.js.map +1 -1
  387. package/dist/lib/decision-check.d.ts +48 -0
  388. package/dist/lib/decision-check.d.ts.map +1 -0
  389. package/dist/lib/decision-check.js +149 -0
  390. package/dist/lib/decision-check.js.map +1 -0
  391. package/dist/lib/fleet-data.d.ts +34 -0
  392. package/dist/lib/fleet-data.d.ts.map +1 -1
  393. package/dist/lib/fleet-data.js +37 -9
  394. package/dist/lib/fleet-data.js.map +1 -1
  395. package/dist/lib/fleet-render.js +1 -1
  396. package/dist/lib/fleet-render.js.map +1 -1
  397. package/dist/lib/git-identity.d.ts +302 -0
  398. package/dist/lib/git-identity.d.ts.map +1 -0
  399. package/dist/lib/git-identity.js +546 -0
  400. package/dist/lib/git-identity.js.map +1 -0
  401. package/dist/lib/harness/console/announce.d.ts +45 -0
  402. package/dist/lib/harness/console/announce.d.ts.map +1 -0
  403. package/dist/lib/harness/console/announce.js +48 -0
  404. package/dist/lib/harness/console/announce.js.map +1 -0
  405. package/dist/lib/harness/console/announce.test.d.ts +2 -0
  406. package/dist/lib/harness/console/announce.test.d.ts.map +1 -0
  407. package/dist/lib/harness/console/announce.test.js +104 -0
  408. package/dist/lib/harness/console/announce.test.js.map +1 -0
  409. package/dist/lib/harness/console/by-session.d.ts +50 -0
  410. package/dist/lib/harness/console/by-session.d.ts.map +1 -0
  411. package/dist/lib/harness/console/by-session.js +83 -0
  412. package/dist/lib/harness/console/by-session.js.map +1 -0
  413. package/dist/lib/harness/console/by-session.test.d.ts +2 -0
  414. package/dist/lib/harness/console/by-session.test.d.ts.map +1 -0
  415. package/dist/lib/harness/console/by-session.test.js +86 -0
  416. package/dist/lib/harness/console/by-session.test.js.map +1 -0
  417. package/dist/lib/harness/console/console.d.ts +67 -0
  418. package/dist/lib/harness/console/console.d.ts.map +1 -0
  419. package/dist/lib/harness/console/console.js +373 -0
  420. package/dist/lib/harness/console/console.js.map +1 -0
  421. package/dist/lib/harness/console/console.test.d.ts +2 -0
  422. package/dist/lib/harness/console/console.test.d.ts.map +1 -0
  423. package/dist/lib/harness/console/console.test.js +269 -0
  424. package/dist/lib/harness/console/console.test.js.map +1 -0
  425. package/dist/lib/harness/console/decision-request.d.ts +32 -0
  426. package/dist/lib/harness/console/decision-request.d.ts.map +1 -0
  427. package/dist/lib/harness/console/decision-request.js +112 -0
  428. package/dist/lib/harness/console/decision-request.js.map +1 -0
  429. package/dist/lib/harness/console/decision-request.test.d.ts +2 -0
  430. package/dist/lib/harness/console/decision-request.test.d.ts.map +1 -0
  431. package/dist/lib/harness/console/decision-request.test.js +75 -0
  432. package/dist/lib/harness/console/decision-request.test.js.map +1 -0
  433. package/dist/lib/harness/console/fixtures.d.ts +16 -0
  434. package/dist/lib/harness/console/fixtures.d.ts.map +1 -0
  435. package/dist/lib/harness/console/fixtures.js +49 -0
  436. package/dist/lib/harness/console/fixtures.js.map +1 -0
  437. package/dist/lib/harness/console/index.d.ts +15 -0
  438. package/dist/lib/harness/console/index.d.ts.map +1 -0
  439. package/dist/lib/harness/console/index.js +14 -0
  440. package/dist/lib/harness/console/index.js.map +1 -0
  441. package/dist/lib/harness/console/rank.d.ts +73 -0
  442. package/dist/lib/harness/console/rank.d.ts.map +1 -0
  443. package/dist/lib/harness/console/rank.js +113 -0
  444. package/dist/lib/harness/console/rank.js.map +1 -0
  445. package/dist/lib/harness/console/rank.test.d.ts +2 -0
  446. package/dist/lib/harness/console/rank.test.d.ts.map +1 -0
  447. package/dist/lib/harness/console/rank.test.js +124 -0
  448. package/dist/lib/harness/console/rank.test.js.map +1 -0
  449. package/dist/lib/harness/console/render.d.ts +22 -0
  450. package/dist/lib/harness/console/render.d.ts.map +1 -0
  451. package/dist/lib/harness/console/render.js +65 -0
  452. package/dist/lib/harness/console/render.js.map +1 -0
  453. package/dist/lib/harness/console/render.test.d.ts +2 -0
  454. package/dist/lib/harness/console/render.test.d.ts.map +1 -0
  455. package/dist/lib/harness/console/render.test.js +96 -0
  456. package/dist/lib/harness/console/render.test.js.map +1 -0
  457. package/dist/lib/harness/console/replay-cli.test.d.ts +2 -0
  458. package/dist/lib/harness/console/replay-cli.test.d.ts.map +1 -0
  459. package/dist/lib/harness/console/replay-cli.test.js +96 -0
  460. package/dist/lib/harness/console/replay-cli.test.js.map +1 -0
  461. package/dist/lib/harness/console/replay.d.ts +36 -0
  462. package/dist/lib/harness/console/replay.d.ts.map +1 -0
  463. package/dist/lib/harness/console/replay.js +59 -0
  464. package/dist/lib/harness/console/replay.js.map +1 -0
  465. package/dist/lib/harness/console/replay.test.d.ts +2 -0
  466. package/dist/lib/harness/console/replay.test.d.ts.map +1 -0
  467. package/dist/lib/harness/console/replay.test.js +81 -0
  468. package/dist/lib/harness/console/replay.test.js.map +1 -0
  469. package/dist/lib/harness/console/turn-reader.d.ts +50 -0
  470. package/dist/lib/harness/console/turn-reader.d.ts.map +1 -0
  471. package/dist/lib/harness/console/turn-reader.js +184 -0
  472. package/dist/lib/harness/console/turn-reader.js.map +1 -0
  473. package/dist/lib/harness/console/turn-reader.test.d.ts +2 -0
  474. package/dist/lib/harness/console/turn-reader.test.d.ts.map +1 -0
  475. package/dist/lib/harness/console/turn-reader.test.js +108 -0
  476. package/dist/lib/harness/console/turn-reader.test.js.map +1 -0
  477. package/dist/lib/harness/console/types.d.ts +109 -0
  478. package/dist/lib/harness/console/types.d.ts.map +1 -0
  479. package/dist/lib/harness/console/types.js +2 -0
  480. package/dist/lib/harness/console/types.js.map +1 -0
  481. package/dist/lib/harness/contract.d.ts +229 -0
  482. package/dist/lib/harness/contract.d.ts.map +1 -0
  483. package/dist/lib/harness/contract.js +22 -0
  484. package/dist/lib/harness/contract.js.map +1 -0
  485. package/dist/lib/harness/credential.d.ts +23 -0
  486. package/dist/lib/harness/credential.d.ts.map +1 -0
  487. package/dist/lib/harness/credential.js +81 -0
  488. package/dist/lib/harness/credential.js.map +1 -0
  489. package/dist/lib/harness/credential.test.d.ts +2 -0
  490. package/dist/lib/harness/credential.test.d.ts.map +1 -0
  491. package/dist/lib/harness/credential.test.js +74 -0
  492. package/dist/lib/harness/credential.test.js.map +1 -0
  493. package/dist/lib/harness/evaluate.d.ts +390 -0
  494. package/dist/lib/harness/evaluate.d.ts.map +1 -0
  495. package/dist/lib/harness/evaluate.js +988 -0
  496. package/dist/lib/harness/evaluate.js.map +1 -0
  497. package/dist/lib/harness/evaluate.test.d.ts +2 -0
  498. package/dist/lib/harness/evaluate.test.d.ts.map +1 -0
  499. package/dist/lib/harness/evaluate.test.js +621 -0
  500. package/dist/lib/harness/evaluate.test.js.map +1 -0
  501. package/dist/lib/harness/extract.d.ts +152 -0
  502. package/dist/lib/harness/extract.d.ts.map +1 -0
  503. package/dist/lib/harness/extract.js +1601 -0
  504. package/dist/lib/harness/extract.js.map +1 -0
  505. package/dist/lib/harness/gate.d.ts +48 -0
  506. package/dist/lib/harness/gate.d.ts.map +1 -0
  507. package/dist/lib/harness/gate.js +60 -0
  508. package/dist/lib/harness/gate.js.map +1 -0
  509. package/dist/lib/harness/gate.test.d.ts +2 -0
  510. package/dist/lib/harness/gate.test.d.ts.map +1 -0
  511. package/dist/lib/harness/gate.test.js +111 -0
  512. package/dist/lib/harness/gate.test.js.map +1 -0
  513. package/dist/lib/harness/self-check.d.ts +59 -0
  514. package/dist/lib/harness/self-check.d.ts.map +1 -0
  515. package/dist/lib/harness/self-check.js +56 -0
  516. package/dist/lib/harness/self-check.js.map +1 -0
  517. package/dist/lib/harness/self-check.test.d.ts +2 -0
  518. package/dist/lib/harness/self-check.test.d.ts.map +1 -0
  519. package/dist/lib/harness/self-check.test.js +43 -0
  520. package/dist/lib/harness/self-check.test.js.map +1 -0
  521. package/dist/lib/harness/transcript.d.ts +65 -0
  522. package/dist/lib/harness/transcript.d.ts.map +1 -0
  523. package/dist/lib/harness/transcript.js +144 -0
  524. package/dist/lib/harness/transcript.js.map +1 -0
  525. package/dist/lib/harness/transcript.test.d.ts +2 -0
  526. package/dist/lib/harness/transcript.test.d.ts.map +1 -0
  527. package/dist/lib/harness/transcript.test.js +118 -0
  528. package/dist/lib/harness/transcript.test.js.map +1 -0
  529. package/dist/lib/harness-wiring.d.ts +145 -0
  530. package/dist/lib/harness-wiring.d.ts.map +1 -0
  531. package/dist/lib/harness-wiring.js +280 -0
  532. package/dist/lib/harness-wiring.js.map +1 -0
  533. package/dist/lib/hook-staleness.d.ts +95 -0
  534. package/dist/lib/hook-staleness.d.ts.map +1 -0
  535. package/dist/lib/hook-staleness.js +304 -0
  536. package/dist/lib/hook-staleness.js.map +1 -0
  537. package/dist/lib/jsonl.d.ts +270 -2
  538. package/dist/lib/jsonl.d.ts.map +1 -1
  539. package/dist/lib/jsonl.js +472 -76
  540. package/dist/lib/jsonl.js.map +1 -1
  541. package/dist/lib/memory.d.ts +350 -23
  542. package/dist/lib/memory.d.ts.map +1 -1
  543. package/dist/lib/memory.js +751 -38
  544. package/dist/lib/memory.js.map +1 -1
  545. package/dist/lib/otel-env.d.ts +90 -0
  546. package/dist/lib/otel-env.d.ts.map +1 -0
  547. package/dist/lib/otel-env.js +98 -0
  548. package/dist/lib/otel-env.js.map +1 -0
  549. package/dist/lib/project-config.d.ts +167 -0
  550. package/dist/lib/project-config.d.ts.map +1 -1
  551. package/dist/lib/project-config.js +321 -5
  552. package/dist/lib/project-config.js.map +1 -1
  553. package/dist/lib/projects-registry.d.ts +82 -0
  554. package/dist/lib/projects-registry.d.ts.map +1 -0
  555. package/dist/lib/projects-registry.js +145 -0
  556. package/dist/lib/projects-registry.js.map +1 -0
  557. package/dist/lib/projects-registry.test.d.ts +2 -0
  558. package/dist/lib/projects-registry.test.d.ts.map +1 -0
  559. package/dist/lib/projects-registry.test.js +176 -0
  560. package/dist/lib/projects-registry.test.js.map +1 -0
  561. package/dist/lib/repo-guard-scope.d.ts +126 -0
  562. package/dist/lib/repo-guard-scope.d.ts.map +1 -0
  563. package/dist/lib/repo-guard-scope.js +249 -0
  564. package/dist/lib/repo-guard-scope.js.map +1 -0
  565. package/dist/lib/report-format.d.ts +132 -0
  566. package/dist/lib/report-format.d.ts.map +1 -0
  567. package/dist/lib/report-format.js +317 -0
  568. package/dist/lib/report-format.js.map +1 -0
  569. package/dist/lib/roster.d.ts +87 -0
  570. package/dist/lib/roster.d.ts.map +1 -0
  571. package/dist/lib/roster.js +332 -0
  572. package/dist/lib/roster.js.map +1 -0
  573. package/dist/lib/roster.test.d.ts +15 -0
  574. package/dist/lib/roster.test.d.ts.map +1 -0
  575. package/dist/lib/roster.test.js +299 -0
  576. package/dist/lib/roster.test.js.map +1 -0
  577. package/dist/lib/runtime/codex-adapter.d.ts.map +1 -1
  578. package/dist/lib/runtime/codex-adapter.js +5 -0
  579. package/dist/lib/runtime/codex-adapter.js.map +1 -1
  580. package/dist/lib/runtime/codex-config.d.ts +129 -0
  581. package/dist/lib/runtime/codex-config.d.ts.map +1 -1
  582. package/dist/lib/runtime/codex-config.js +225 -0
  583. package/dist/lib/runtime/codex-config.js.map +1 -1
  584. package/dist/lib/runtime/identity.d.ts +72 -0
  585. package/dist/lib/runtime/identity.d.ts.map +1 -0
  586. package/dist/lib/runtime/identity.js +128 -0
  587. package/dist/lib/runtime/identity.js.map +1 -0
  588. package/dist/lib/standards.d.ts +99 -0
  589. package/dist/lib/standards.d.ts.map +1 -0
  590. package/dist/lib/standards.js +201 -0
  591. package/dist/lib/standards.js.map +1 -0
  592. package/dist/lib/team-identity.d.ts +134 -0
  593. package/dist/lib/team-identity.d.ts.map +1 -0
  594. package/dist/lib/team-identity.js +193 -0
  595. package/dist/lib/team-identity.js.map +1 -0
  596. package/dist/lib/templates.d.ts +29 -2
  597. package/dist/lib/templates.d.ts.map +1 -1
  598. package/dist/lib/templates.js +1042 -82
  599. package/dist/lib/templates.js.map +1 -1
  600. package/dist/lib/terminal-ui.d.ts.map +1 -1
  601. package/dist/lib/terminal-ui.js +12 -1
  602. package/dist/lib/terminal-ui.js.map +1 -1
  603. package/dist/lib/test-project.d.ts +95 -0
  604. package/dist/lib/test-project.d.ts.map +1 -0
  605. package/dist/lib/test-project.js +103 -0
  606. package/dist/lib/test-project.js.map +1 -0
  607. package/dist/lib/vault.d.ts +60 -0
  608. package/dist/lib/vault.d.ts.map +1 -0
  609. package/dist/lib/vault.js +102 -0
  610. package/dist/lib/vault.js.map +1 -0
  611. package/dist/lib/vault.test.d.ts +17 -0
  612. package/dist/lib/vault.test.d.ts.map +1 -0
  613. package/dist/lib/vault.test.js +169 -0
  614. package/dist/lib/vault.test.js.map +1 -0
  615. package/dist/lib/window-view.d.ts +63 -0
  616. package/dist/lib/window-view.d.ts.map +1 -0
  617. package/dist/lib/window-view.js +217 -0
  618. package/dist/lib/window-view.js.map +1 -0
  619. package/dist/lib/window-view.test.d.ts +2 -0
  620. package/dist/lib/window-view.test.d.ts.map +1 -0
  621. package/dist/lib/window-view.test.js +168 -0
  622. package/dist/lib/window-view.test.js.map +1 -0
  623. package/dist/lib/worktree-sync.d.ts +439 -0
  624. package/dist/lib/worktree-sync.d.ts.map +1 -0
  625. package/dist/lib/worktree-sync.js +1167 -0
  626. package/dist/lib/worktree-sync.js.map +1 -0
  627. package/dist/lib/worktree.d.ts +58 -1
  628. package/dist/lib/worktree.d.ts.map +1 -1
  629. package/dist/lib/worktree.js +91 -4
  630. package/dist/lib/worktree.js.map +1 -1
  631. package/dist/standards/decision-request.md +98 -0
  632. package/dist/standards/fail-loud-standard.md +495 -0
  633. package/dist/standards/po-communication-standard.md +126 -0
  634. package/dist/standards/report-format.md +128 -0
  635. package/dist/standards/writing-standard.md +382 -0
  636. package/package.json +3 -2
  637. package/scripts/generate-claude.mjs +119 -46
@@ -0,0 +1,654 @@
1
+ /**
2
+ * Build the CLI inside a newly provisioned worktree (#123).
3
+ *
4
+ * `mx-agent provision` used to leave a worktree whose `mx-agent-system/cli` had
5
+ * no `node_modules` and no `dist/`. The first push from that worktree is refused
6
+ * by `.githooks/pre-push` with 17 test titles that name the missing
7
+ * `dist/index.js` rather than the change, and the operator runs the build by
8
+ * hand. This module runs it at creation instead, and row 14 of the completion
9
+ * check asserts the result.
10
+ *
11
+ * ONE PLACE ON THE PROVISIONING PATH SPAWNS `npm`, and this is it. Two other
12
+ * modules spawn npm for their own purposes and are not part of this path:
13
+ * `commands/update.ts:56,64` (`npm view`, `npm install -g`) and
14
+ * `lib/framework-version.ts:243` (`npm view`), which the pre-ruling M2 names and
15
+ * leaves as it is because it reads a registry rather than building code.
16
+ * `provision-completion-rows.test.ts` stubs each
17
+ * boundary with `vi.mock('../lib/<name>.js', ...)`, the way `lib/memory.ts`,
18
+ * `lib/roster.ts` and `lib/vault.ts` are stubbed, and the build boundary joins
19
+ * that list. No test suite reaches the network through this file.
20
+ *
21
+ * Built to the security design pre-ruling on issue #207 (comment 5430622857).
22
+ * Item numbers M1 to M7 and S1 to S6 in the comments below are that ruling's,
23
+ * and each names what it is protecting rather than restating the rule.
24
+ */
25
+ import { spawnSync } from 'child_process';
26
+ import { accessSync, constants, lstatSync, realpathSync, statSync } from 'fs';
27
+ import { dirname, join, sep } from 'path';
28
+ import { runningCliVersion } from './framework-version.js';
29
+ /**
30
+ * 10 minutes copies `SUITE_TIMEOUT_MS` in `check-new-failures.mjs:52`. It exists
31
+ * to turn a hang into a reported could-not-run, not to police a slow network.
32
+ */
33
+ const CI_TIMEOUT_MS = 10 * 60 * 1000;
34
+ const BUILD_TIMEOUT_MS = 5 * 60 * 1000;
35
+ const PROBE_TIMEOUT_MS = 30 * 1000;
36
+ /**
37
+ * 8 MiB, not the 64 MiB the plan first proposed (S1). Two piped streams, up to
38
+ * three spawns, on a machine running four agent worktrees, is up to 512 MiB of
39
+ * transient buffer at 64 MiB. `--loglevel=error` output is kilobytes and the
40
+ * excerpt below truncates to 8,192 bytes anyway, so this is three orders of
41
+ * magnitude of headroom. `spawnSync` sets `error` and a null status on overflow,
42
+ * which the stage gate already reads as could-not-run.
43
+ */
44
+ const MAX_BUFFER_BYTES = 8 * 1024 * 1024;
45
+ /** M6: the line budget, applied first. */
46
+ const EXCERPT_LINES = 20;
47
+ /**
48
+ * M6: the byte budget, applied second.
49
+ *
50
+ * A line budget is not a budget. npm can emit one line of arbitrary length, and
51
+ * a registry error body is the common case, so 20 lines has no upper bound in
52
+ * bytes. The precedent in this repository is a byte budget:
53
+ * `check-new-failures.mjs:100` uses `errOut.slice(-4000)`.
54
+ */
55
+ const EXCERPT_BYTES = 8192;
56
+ /** S3: the probe's output is content from the tree being built, so it is parsed, not trusted. */
57
+ const VERSION_MAX_CHARS = 64;
58
+ /**
59
+ * Anchored and bounded, as S3 requires. Widened in one respect: the ruling's
60
+ * `(?:[-+][0-9A-Za-z.-]+)?` accepts `1.2.3-rc.1` and `1.2.3+build.5` and rejects
61
+ * `1.2.3-rc.1+build.5`, because `+` is absent from its character class. A CLI
62
+ * published with both suffixes would make row 14 read could-not-run on an
63
+ * otherwise good provision. The prerelease and the build metadata are separate
64
+ * optional groups here, which is semver's own grammar.
65
+ *
66
+ * Nothing else loosens: still anchored at both ends, still capped at 64
67
+ * characters, still only semver-legal characters, and unmatched output is still
68
+ * never printed.
69
+ */
70
+ const VERSION_RE = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
71
+ /**
72
+ * The environment the three children get. An allowlist, not a sweep (M7).
73
+ *
74
+ * Everything absent from this list is dropped, which removes every `GIT_*` (the
75
+ * `testing-tools/git-env.cjs:5-20` reason), every `npm_config_*`, `NODE_ENV`,
76
+ * `NODE_OPTIONS`, `NODE_PATH`, `MX_*`, `ANTHROPIC_*`, `AZURE_*`, `GH_TOKEN` and
77
+ * `GITHUB_TOKEN`.
78
+ *
79
+ * `HOME` stays because npm reads its cache and its user config from it. Nothing
80
+ * in this module reads that file, and no test may (I1).
81
+ */
82
+ const ENV_ALLOWLIST = [
83
+ 'PATH',
84
+ 'HOME',
85
+ 'USER',
86
+ 'LOGNAME',
87
+ 'LANG',
88
+ 'LC_ALL',
89
+ 'TMPDIR',
90
+ 'HTTP_PROXY',
91
+ 'HTTPS_PROXY',
92
+ 'NO_PROXY',
93
+ 'http_proxy',
94
+ 'https_proxy',
95
+ 'no_proxy',
96
+ 'NODE_EXTRA_CA_CERTS',
97
+ 'SSL_CERT_FILE',
98
+ ];
99
+ /**
100
+ * `NO_COLOR` is the cross-tool convention and `npm_config_color` is npm's own.
101
+ * Both are set by this module rather than inherited (M7). They are a second
102
+ * layer under the control-character strip below, not a replacement for it: npm
103
+ * suppresses colour on a non-TTY pipe today, and that is one behaviour, not a
104
+ * guarantee.
105
+ */
106
+ export function buildEnv(source) {
107
+ const env = {};
108
+ for (const key of ENV_ALLOWLIST) {
109
+ const value = source[key];
110
+ if (typeof value === 'string')
111
+ env[key] = value;
112
+ }
113
+ env.NO_COLOR = '1';
114
+ env.npm_config_color = 'false';
115
+ return env;
116
+ }
117
+ /**
118
+ * Redaction, applied LAST in the excerpt pipeline (M6).
119
+ *
120
+ * Two patterns were too few: `_auth`, `_password`, `//host/:_authToken`,
121
+ * `Authorization:` headers and the `ghp_`, `github_pat_`, `sk-ant-` prefixes
122
+ * this fleet holds are all reachable through an npm error body.
123
+ *
124
+ * `_authToken` precedes `_auth` in the alternation deliberately. Reversed, the
125
+ * shorter branch matches the prefix and leaves `Token=<value>` on the visible
126
+ * side.
127
+ */
128
+ const REDACTIONS = [
129
+ [/(:\/\/)[^/@\s]+@/g, '$1<redacted>@'],
130
+ [/(_authToken|_auth|_password)(\s*[=:]\s*)\S+/gi, '$1$2<redacted>'],
131
+ [/(Authorization\s*:\s*)\S+(\s+\S+)?/gi, '$1<redacted>'],
132
+ [/(Bearer)\s+\S+/gi, '$1 <redacted>'],
133
+ [/ghp_[A-Za-z0-9]+/g, '<redacted>'],
134
+ [/github_pat_[A-Za-z0-9_]+/g, '<redacted>'],
135
+ [/sk-ant-[A-Za-z0-9_-]+/g, '<redacted>'],
136
+ ];
137
+ function redact(text) {
138
+ let out = text;
139
+ for (const [pattern, replacement] of REDACTIONS)
140
+ out = out.replace(pattern, replacement);
141
+ return out;
142
+ }
143
+ const TAB = 9;
144
+ const NEWLINE = 10;
145
+ const C0_END = 31;
146
+ const DEL = 127;
147
+ const C1_END = 159;
148
+ /**
149
+ * Every C0 and C1 control character, except `\t` and `\n`, removed.
150
+ *
151
+ * npm's stderr can carry registry-supplied strings. Printing them unfiltered
152
+ * into a terminal is escape-sequence injection (CWE-150): an escape run can
153
+ * overwrite the lines above it, so a refusal can be made to read as a pass.
154
+ *
155
+ * Written as a code-point test rather than a character class so the two
156
+ * exemptions are named where a reader can check them. A class of raw control
157
+ * bytes in the source is unreadable and unreviewable.
158
+ */
159
+ function stripControlCharacters(text) {
160
+ let out = '';
161
+ for (const ch of text) {
162
+ const code = ch.codePointAt(0) ?? 0;
163
+ if (code === TAB || code === NEWLINE) {
164
+ out += ch;
165
+ continue;
166
+ }
167
+ if (code <= C0_END)
168
+ continue;
169
+ if (code >= DEL && code <= C1_END)
170
+ continue;
171
+ out += ch;
172
+ }
173
+ return out;
174
+ }
175
+ /**
176
+ * The excerpt pipeline: redact, last 20 lines, 8,192 bytes, strip, redact (M6).
177
+ *
178
+ * REDACTION RUNS AT BOTH ENDS, and each pass closes a residual the other leaves.
179
+ *
180
+ * The pre-ruling fixed the order as lines, bytes, strip, redact, because
181
+ * redacting only before a cut lets the cut split a `<redacted>` marker and leave
182
+ * the tail of a secret on the visible side. That reason stands, and the final
183
+ * pass is still last.
184
+ *
185
+ * Redacting only after the cut has the opposite residual, and it is the one that
186
+ * leaks the secret rather than the marker. The truncation keeps the tail, so it
187
+ * removes a pattern's fixed literal prefix first: `https://`, `ghp_`,
188
+ * `github_pat_`, `sk-ant-` and `Authorization:` are all a handful of bytes wide,
189
+ * and once the prefix is gone the remainder no longer matches and the secret
190
+ * body prints. Measured against the shipped module: a credentialed URL leaks at
191
+ * eight consecutive suffix lengths, the width of `https://`, and a `ghp_` token
192
+ * at four, the width of `ghp_`.
193
+ *
194
+ * Running the pass before any cut removes the secret while its prefix is still
195
+ * attached, so a later cut can only ever divide marker text. Running it again
196
+ * after the strip catches anything the control-character removal reassembles,
197
+ * such as a token written with a NUL inside its prefix. Neither residual
198
+ * survives both passes.
199
+ *
200
+ * The tail is kept rather than the head, the way `check-new-failures.mjs:100`
201
+ * keeps it: npm names the failure at the end of its output.
202
+ *
203
+ * No layer here is trusted alone. `--loglevel=error` keeps the volume down, the
204
+ * byte cap keeps a miss small, and the control strip keeps a miss readable.
205
+ *
206
+ * Applied to the row-14 `detail`, not only to a logged line: `detail` is what a
207
+ * status report or a PR body copies, so it reaches further than the log does.
208
+ */
209
+ export function excerpt(raw) {
210
+ if (!raw)
211
+ return '';
212
+ // Before any cut, while every prefix is still attached to its secret.
213
+ let text = redact(raw);
214
+ const lines = text.split('\n');
215
+ text = lines.slice(-EXCERPT_LINES).join('\n');
216
+ const bytes = Buffer.from(text, 'utf8');
217
+ if (bytes.byteLength > EXCERPT_BYTES) {
218
+ text = bytes.subarray(bytes.byteLength - EXCERPT_BYTES).toString('utf8');
219
+ }
220
+ text = stripControlCharacters(text);
221
+ // Last, so the strip cannot reassemble a pattern that then goes unredacted.
222
+ text = redact(text);
223
+ return text.trim();
224
+ }
225
+ /**
226
+ * Which `npm` runs, resolved from `dirname(process.execPath)` first (M2).
227
+ *
228
+ * npm ships beside node under both the system layout and nvm. `PATH` on this
229
+ * machine lists `/home/node/.npm-global/bin` first and
230
+ * `/usr/local/share/npm-global/bin` seventh, both writable by the running user
231
+ * and both ahead of `/usr/local/bin`. `AGENTS.md` instructs agents to run
232
+ * `npm install -g`, and `commands/update.ts:64` runs it from inside this CLI, so
233
+ * a package declaring a bin named `npm` would shadow the system npm for every
234
+ * later provision. Falling back to `PATH` is still correct when nothing sits
235
+ * beside node; the result records which answered either way.
236
+ */
237
+ export function resolveNpm(execPath) {
238
+ const candidate = join(dirname(execPath), 'npm');
239
+ try {
240
+ const link = lstatSync(candidate);
241
+ // A regular file, or a symlink that resolves to one. A directory or a socket
242
+ // named `npm` is not a runnable npm and falls back rather than spawning.
243
+ if (link.isSymbolicLink()) {
244
+ if (!statSync(candidate).isFile())
245
+ return { command: 'npm', source: 'PATH' };
246
+ }
247
+ else if (!link.isFile()) {
248
+ return { command: 'npm', source: 'PATH' };
249
+ }
250
+ accessSync(candidate, constants.X_OK);
251
+ return { command: candidate, source: 'node-adjacent' };
252
+ }
253
+ catch {
254
+ return { command: 'npm', source: 'PATH' };
255
+ }
256
+ }
257
+ /** The remedy an operator runs by hand when the build did not happen. */
258
+ export const REBUILD_REMEDY = 'npm ci && npm run build';
259
+ /**
260
+ * S2: a build-stage SIGKILL signals the direct child only. npm runs
261
+ * `tsc && node scripts/bundle-config.mjs` through a shell, so the shell and
262
+ * `tsc` survive and keep writing into the worktree after row 14 has printed.
263
+ * `spawnSync` cannot signal a process group, and converting this module to an
264
+ * async spawn to gain that is a larger change than the harm justifies, so the
265
+ * detail says what may still be running and the remedy clears the partial tree
266
+ * first.
267
+ */
268
+ export const ORPHAN_REMEDY = 'rm -rf node_modules dist && npm ci && npm run build';
269
+ export const ORPHAN_WARNING = 'a tsc or node process may still be writing into the worktree; check with ps before re-running';
270
+ /**
271
+ * One spawn, with the options every spawn here shares.
272
+ *
273
+ * `stdio` pipes both streams rather than inheriting them: nothing npm writes
274
+ * reaches the transcript except through `excerpt`. No `shell`, ever, on any
275
+ * path.
276
+ */
277
+ function runStage(command, args, cwd, env, timeout, stage) {
278
+ const started = Date.now();
279
+ const r = spawnSync(command, args, {
280
+ cwd,
281
+ env,
282
+ stdio: ['ignore', 'pipe', 'pipe'],
283
+ encoding: 'utf8',
284
+ maxBuffer: MAX_BUFFER_BYTES,
285
+ timeout,
286
+ killSignal: 'SIGKILL',
287
+ });
288
+ const ms = Date.now() - started;
289
+ const stderr = excerpt(typeof r?.stderr === 'string' ? r.stderr : '');
290
+ const stdout = typeof r?.stdout === 'string' ? r.stdout : '';
291
+ if (r?.error) {
292
+ const code = r.error.code ?? '';
293
+ // ENOBUFS is not a timeout, and saying so printed a false elapsed time.
294
+ // `spawnSync` reports a maxBuffer overflow as `status: null`, `signal:
295
+ // SIGKILL` and `error.code: ENOBUFS` (measured, Node v22.16.0), so the
296
+ // signal alone cannot tell the two apart. The stage is still could-not-run,
297
+ // which is what S1 says the overflow should read as; only the sentence
298
+ // changes.
299
+ if (code === 'ENOBUFS') {
300
+ const mib = Math.round(MAX_BUFFER_BYTES / (1024 * 1024));
301
+ return {
302
+ ok: false,
303
+ ms,
304
+ stdout,
305
+ killed: true,
306
+ detail: `produced more than ${mib} MiB of output and was killed${stderr ? `: ${stderr}` : ''}`,
307
+ };
308
+ }
309
+ const timedOut = code === 'ETIMEDOUT' || r.signal === 'SIGKILL';
310
+ const what = timedOut
311
+ ? `timed out after ${timeout} ms and was killed`
312
+ : `could not be spawned (${excerpt(r.error.message ?? String(code))})`;
313
+ return { ok: false, ms, stdout, killed: timedOut, detail: `${what}${stderr ? `: ${stderr}` : ''}` };
314
+ }
315
+ if (r?.status !== 0) {
316
+ const signalled = r?.status === null || r?.status === undefined;
317
+ const how = signalled
318
+ ? `was killed${r?.signal ? ` (${r.signal})` : ''}`
319
+ : `exited ${r.status}`;
320
+ return { ok: false, ms, stdout, killed: signalled, detail: `${how}${stderr ? `: ${stderr}` : ''}` };
321
+ }
322
+ return { ok: true, ms, stdout, killed: false, detail: '' };
323
+ }
324
+ /** The refusal shape shared by every pre-spawn check. Stage `ci`: nothing ran. */
325
+ function refuse(detail) {
326
+ return { kind: 'could-not-run', stage: 'ci', detail };
327
+ }
328
+ /**
329
+ * Run `npm ci` and `npm run build` inside a newly created worktree, then probe
330
+ * the result.
331
+ *
332
+ * WHERE IT WRITES IS THE WHOLE QUESTION. The installed `mx-agent` is `npm
333
+ * link`ed at `/workspace/mx-agent-system/cli` (`.devcontainer/post-create.sh:90-96`
334
+ * links the working tree rather than installing a published copy), and
335
+ * `scripts/bundle-config.mjs:84,121` call `rmSync(DEST, { recursive: true, force:
336
+ * true })` with `:149` calling `chmodSync`. A `--prefix` or `cwd` that escaped to
337
+ * that path would recursively delete and re-mode the binary every agent session
338
+ * on this machine runs, on a path `git worktree remove` does not reach. So the
339
+ * path checks below run before the first spawn, and both `cwd` and `--prefix=`
340
+ * name one realpath'd absolute path.
341
+ *
342
+ * The check-to-spawn race is not closable with a path check and this does not
343
+ * pretend otherwise: the durable control is that a component swapped after the
344
+ * check changes what is built, and cannot change where the write lands outside
345
+ * the checked prefix.
346
+ */
347
+ export function buildCliInWorktree(worktreePath, opts = {}) {
348
+ const execPath = opts.execPath ?? process.execPath;
349
+ const platform = opts.platform ?? process.platform;
350
+ const sourceEnv = opts.env ?? process.env;
351
+ // No `npm.cmd` without a shell, and this CLI is not run natively on Windows:
352
+ // `.githooks/pre-push:8-12` routes through WSL. Refusing is honest; guessing an
353
+ // extension is not.
354
+ if (platform === 'win32') {
355
+ return refuse('not supported on win32: npm.cmd needs a shell and this module never uses one');
356
+ }
357
+ let realWorktree;
358
+ try {
359
+ realWorktree = realpathSync(worktreePath);
360
+ }
361
+ catch (err) {
362
+ return refuse(`the worktree path ${worktreePath} does not resolve (${errno(err)})`);
363
+ }
364
+ const cliDir = join(realWorktree, 'mx-agent-system', 'cli');
365
+ // Absent is not refused: a project that consumes the published CLI has no
366
+ // source to build. Any other lstat failure IS refused, because a directory
367
+ // that cannot be read establishes nothing.
368
+ try {
369
+ lstatSync(cliDir);
370
+ }
371
+ catch (err) {
372
+ if (errno(err) === 'ENOENT') {
373
+ return {
374
+ kind: 'not-applicable',
375
+ detail: 'no mx-agent-system/cli in this worktree (this project installs the published CLI)',
376
+ };
377
+ }
378
+ return refuse(`mx-agent-system/cli could not be read (${errno(err)})`);
379
+ }
380
+ // M3 check 1: one syscall that catches every component at once, including any
381
+ // a per-component walk's loop bounds would miss.
382
+ let realCliDir;
383
+ try {
384
+ realCliDir = realpathSync(cliDir);
385
+ }
386
+ catch (err) {
387
+ return refuse(`mx-agent-system/cli does not resolve (${errno(err)})`);
388
+ }
389
+ if (realCliDir !== cliDir) {
390
+ // M3 check 2: the walk names WHICH component moved. It is the reporting
391
+ // half, never the gate: the equality check above is the gate.
392
+ const offender = firstSymlinkComponent(realWorktree, ['mx-agent-system', 'cli']);
393
+ return refuse(`symlink: ${offender ?? 'a component of mx-agent-system/cli'} does not resolve inside the `
394
+ + `worktree, so the build would run somewhere else; nothing was spawned`);
395
+ }
396
+ // M3 check 3: the containment `reanchorContained` applies to the roleguide copy
397
+ // (`create.ts:3573`), stated here rather than implied.
398
+ if (!(realCliDir + sep).startsWith(realWorktree + sep)) {
399
+ return refuse(`outside: ${realCliDir} is not inside ${realWorktree}; nothing was spawned`);
400
+ }
401
+ const dirStat = lstatSync(realCliDir);
402
+ if (!dirStat.isDirectory() || dirStat.isSymbolicLink()) {
403
+ return refuse('mx-agent-system/cli is not a directory; nothing was spawned');
404
+ }
405
+ if (!isRegularFile(join(realCliDir, 'package.json'))) {
406
+ return {
407
+ kind: 'not-applicable',
408
+ detail: 'no mx-agent-system/cli/package.json in this worktree (this project installs the published CLI)',
409
+ };
410
+ }
411
+ // M4. `lstatSync`, not `existsSync`: an existence check follows a symlink, so a
412
+ // `.npmrc` symlinked to a file outside the tree would pass the check aimed at
413
+ // catching it.
414
+ //
415
+ // A project `.npmrc` directs network requests to a host that is not part of
416
+ // this task, and it changes how the build fetches code, which is a decision
417
+ // that must be visible rather than silent. `npm-shrinkwrap.json` is the
418
+ // quieter one: npm prefers it over `package-lock.json` without saying so, and
419
+ // a shrinkwrap added on `origin/main` would replace the lockfile's
420
+ // integrity-pinned entries with an unreviewed set.
421
+ const forbidden = [
422
+ join(realWorktree, '.npmrc'),
423
+ join(realWorktree, 'mx-agent-system', '.npmrc'),
424
+ join(realCliDir, '.npmrc'),
425
+ join(realCliDir, 'npm-shrinkwrap.json'),
426
+ ];
427
+ for (const path of forbidden) {
428
+ if (lstatOrNull(path) !== null) {
429
+ return refuse(`${path} is present and would change where the build fetches code; nothing was spawned`);
430
+ }
431
+ }
432
+ // The lockfile IS the supply-chain control for what `npm run build` then
433
+ // executes: `npm ci` verifies a sha512 for every entry, and `--ignore-scripts`
434
+ // stops install-time execution but does not stop `node_modules/.bin/tsc` from
435
+ // running. Named here rather than left to npm's own message, so the refusal
436
+ // says which file was missing.
437
+ if (!isRegularFile(join(realCliDir, 'package-lock.json'))) {
438
+ return refuse(`${join(realCliDir, 'package-lock.json')} is absent, so npm ci has no integrity-pinned `
439
+ + `lockfile to install from; nothing was spawned`);
440
+ }
441
+ const { command: npmPath, source: npmSource } = resolveNpm(execPath);
442
+ const npmWhere = npmSource === 'node-adjacent' ? `${npmPath} (beside node)` : 'npm from PATH';
443
+ const env = buildEnv(sourceEnv);
444
+ // M1. `--ignore-scripts` on the ARGV of both commands, never through
445
+ // `npm_config_ignore_scripts` in the environment: an argv flag beats a project
446
+ // `.npmrc` and an environment variable does not.
447
+ //
448
+ // What it drops here is one config write outside the worktree. This package's
449
+ // own `prepare` is `node scripts/install-hooks.mjs`, which runs
450
+ // `git config core.hooksPath .githooks`; from a linked worktree that writes
451
+ // `/workspace/.git/config`, the shared common dir. Nothing the build needs is
452
+ // lost: `npm run build` is `tsc && node scripts/bundle-config.mjs` and neither
453
+ // uses esbuild, whose `postinstall` is the one lifecycle script `npm ci` would
454
+ // otherwise execute.
455
+ //
456
+ // `--include=dev` is on the argv because npm maps `NODE_ENV=production` to
457
+ // `omit=dev`, which drops `typescript` and makes the build fail on `tsc`.
458
+ // Dropping the variable fixes the inherited case and not a user config that
459
+ // sets `omit=dev` directly; the flag beats both (M7).
460
+ //
461
+ // `--loglevel=error` is fixed. No code path raises it: `verbose` and `silly`
462
+ // print npm's resolved configuration, including the path of the user config
463
+ // file (M7).
464
+ const ci = runStage(npmPath, ['ci', `--prefix=${realCliDir}`, '--ignore-scripts', '--include=dev', '--no-audit', '--no-fund', '--no-progress', '--loglevel=error'], realCliDir, env, CI_TIMEOUT_MS, 'ci');
465
+ // M5. The stages are gated on each other, and this is the gate. `npm run build`
466
+ // runs `tsc`, and npm prepends `node_modules/.bin` to the script's PATH; when
467
+ // `npm ci` was killed at the timeout that directory may not exist, `tsc` then
468
+ // resolves from the inherited PATH, and `/usr/local/share/npm-global/bin/tsc`
469
+ // exists on this machine. A killed install followed by a build compiles the
470
+ // tree with a global TypeScript of unrecorded version and reports success.
471
+ if (!ci.ok) {
472
+ return {
473
+ kind: 'could-not-run',
474
+ stage: 'ci',
475
+ detail: `npm ci ${ci.detail} (${npmWhere}); run: cd <worktree>/mx-agent-system/cli && ${REBUILD_REMEDY}`,
476
+ };
477
+ }
478
+ // `--` separates npm's arguments from the arguments npm passes on to the
479
+ // script. It does not end npm's own option parsing. Every argv element here is
480
+ // a literal except the absolute path inside `--prefix=`, so nothing depends on
481
+ // either reading; the flag stays and the reason for keeping it is that it is
482
+ // harmless, not that it terminates anything (S5).
483
+ const build = runStage(npmPath, ['run', 'build', `--prefix=${realCliDir}`, '--ignore-scripts', '--loglevel=error', '--'], realCliDir, env, BUILD_TIMEOUT_MS, 'build');
484
+ if (!build.ok) {
485
+ // From the spawn result, never from `detail`: that string carries npm's
486
+ // stderr, so matching on it let npm's own words choose the remedy.
487
+ const remedy = build.killed ? ORPHAN_REMEDY : REBUILD_REMEDY;
488
+ const warning = build.killed ? ` ${ORPHAN_WARNING};` : '';
489
+ return {
490
+ kind: 'could-not-run',
491
+ stage: 'build',
492
+ detail: `npm run build ${build.detail} (${npmWhere});${warning} run: cd <worktree>/mx-agent-system/cli && ${remedy}`,
493
+ };
494
+ }
495
+ const distPath = join(realCliDir, 'dist', 'index.js');
496
+ // The probe runs the freshly built import graph of the WHOLE CLI, not a parse
497
+ // check: `src/index.ts:22-64` imports 41 command modules at top level and
498
+ // commander resolves `--version` only after all of them have run. That is
499
+ // acceptable under the same argument the build rests on, because the same tree
500
+ // already supplied `tsc` and `bundle-config.mjs`, and it is stated rather than
501
+ // described as cheap (S3).
502
+ //
503
+ // `process.execPath`, not `node` from `PATH`: the binary running `provision` is
504
+ // the one that answers.
505
+ const probe = runStage(execPath, ['--', distPath, '--version'], realCliDir, env, PROBE_TIMEOUT_MS, 'probe');
506
+ if (!probe.ok) {
507
+ return {
508
+ kind: 'could-not-run',
509
+ stage: 'probe',
510
+ detail: `node dist/index.js --version ${probe.detail}; run: cd <worktree>/mx-agent-system/cli && ${REBUILD_REMEDY}`,
511
+ };
512
+ }
513
+ // S3. The probe's stdout is content from the tree being built: `src/index.ts:75`
514
+ // is `.version(pkg.version)`, read from the worktree's own `package.json`,
515
+ // which came from `origin/<baseBranch>`. Anchored, first line only, bounded.
516
+ // Unmatched text is never printed, only its length, so a crafted version string
517
+ // cannot write bytes into this line.
518
+ const firstLine = probe.stdout.split('\n')[0]?.trim() ?? '';
519
+ if (firstLine.length > VERSION_MAX_CHARS || !VERSION_RE.test(firstLine)) {
520
+ return {
521
+ kind: 'could-not-run',
522
+ stage: 'probe',
523
+ detail: `node dist/index.js --version printed ${firstLine.length} characters that are not a `
524
+ + `version; run: cd <worktree>/mx-agent-system/cli && ${REBUILD_REMEDY}`,
525
+ };
526
+ }
527
+ return {
528
+ kind: 'built',
529
+ distPath,
530
+ version: firstLine,
531
+ // S4. The running `provision` resolves to `/workspace/mx-agent-system/cli`,
532
+ // the main repository, while the tree it just built is the new worktree. Two
533
+ // different codebases produce this line and one version string cannot tell
534
+ // them apart.
535
+ runnerVersion: runningCliVersion(),
536
+ ciMs: ci.ms,
537
+ buildMs: build.ms,
538
+ npmSource,
539
+ };
540
+ }
541
+ /**
542
+ * Is the CLI in this worktree already built? Read-only (#316 change D).
543
+ *
544
+ * `mx-agent provision --recheck` writes nothing, so it cannot run `npm ci`, and
545
+ * a row that did not look is not a row that passed. This asks row 14's own
546
+ * question instead: does `mx-agent-system/cli/dist/index.js` exist, and does
547
+ * `node dist/index.js --version` exit 0 with a version-shaped line.
548
+ *
549
+ * The containment checks are the ones {@link buildCliInWorktree} makes, for the
550
+ * same reason: the probe SPAWNS the file it finds, so a `mx-agent-system/cli`
551
+ * that resolves outside the worktree must not be run. Nothing is written and no
552
+ * npm is spawned on any path.
553
+ */
554
+ export function probeBuiltCli(worktreePath, opts = {}) {
555
+ const execPath = opts.execPath ?? process.execPath;
556
+ const platform = opts.platform ?? process.platform;
557
+ const env = buildEnv(opts.env ?? process.env);
558
+ if (platform === 'win32') {
559
+ return refuse('not supported on win32: this module never uses a shell');
560
+ }
561
+ let realWorktree;
562
+ try {
563
+ realWorktree = realpathSync(worktreePath);
564
+ }
565
+ catch (err) {
566
+ return refuse(`the worktree path ${worktreePath} does not resolve (${errno(err)})`);
567
+ }
568
+ const cliDir = join(realWorktree, 'mx-agent-system', 'cli');
569
+ try {
570
+ lstatSync(cliDir);
571
+ }
572
+ catch (err) {
573
+ if (errno(err) === 'ENOENT') {
574
+ return {
575
+ kind: 'not-applicable',
576
+ detail: 'no mx-agent-system/cli in this worktree (this project installs the published CLI)',
577
+ };
578
+ }
579
+ return refuse(`mx-agent-system/cli could not be read (${errno(err)})`);
580
+ }
581
+ let realCliDir;
582
+ try {
583
+ realCliDir = realpathSync(cliDir);
584
+ }
585
+ catch (err) {
586
+ return refuse(`mx-agent-system/cli does not resolve (${errno(err)})`);
587
+ }
588
+ if (realCliDir !== cliDir || !(realCliDir + sep).startsWith(realWorktree + sep)) {
589
+ return refuse(`${realCliDir} does not resolve inside ${realWorktree}; nothing was spawned`);
590
+ }
591
+ if (!isRegularFile(join(realCliDir, 'package.json'))) {
592
+ return {
593
+ kind: 'not-applicable',
594
+ detail: 'no mx-agent-system/cli/package.json in this worktree (this project installs the published CLI)',
595
+ };
596
+ }
597
+ const distPath = join(realCliDir, 'dist', 'index.js');
598
+ if (!isRegularFile(distPath)) {
599
+ return {
600
+ kind: 'could-not-run',
601
+ stage: 'probe',
602
+ detail: `dist/index.js is not there; run: cd <worktree>/mx-agent-system/cli && ${REBUILD_REMEDY}`,
603
+ };
604
+ }
605
+ const probe = runStage(execPath, ['--', distPath, '--version'], realCliDir, env, PROBE_TIMEOUT_MS, 'probe');
606
+ if (!probe.ok) {
607
+ return {
608
+ kind: 'could-not-run',
609
+ stage: 'probe',
610
+ detail: `node dist/index.js --version ${probe.detail}; run: cd <worktree>/mx-agent-system/cli && ${REBUILD_REMEDY}`,
611
+ };
612
+ }
613
+ const firstLine = probe.stdout.split('\n')[0]?.trim() ?? '';
614
+ if (firstLine.length > VERSION_MAX_CHARS || !VERSION_RE.test(firstLine)) {
615
+ return {
616
+ kind: 'could-not-run',
617
+ stage: 'probe',
618
+ detail: `node dist/index.js --version printed ${firstLine.length} characters that are not a `
619
+ + `version; run: cd <worktree>/mx-agent-system/cli && ${REBUILD_REMEDY}`,
620
+ };
621
+ }
622
+ return { kind: 'already-built', distPath, version: firstLine, runnerVersion: runningCliVersion() };
623
+ }
624
+ /** `ENOENT`, `EACCES`, and so on. `unknown` when the error carries no code. */
625
+ function errno(err) {
626
+ const code = err?.code;
627
+ return typeof code === 'string' ? code : 'unknown';
628
+ }
629
+ function lstatOrNull(path) {
630
+ try {
631
+ return lstatSync(path);
632
+ }
633
+ catch {
634
+ return null;
635
+ }
636
+ }
637
+ function isRegularFile(path) {
638
+ const st = lstatOrNull(path);
639
+ return st !== null && st.isFile();
640
+ }
641
+ /** Which component below `root` is a symlink, for the refusal detail (M3). */
642
+ function firstSymlinkComponent(root, components) {
643
+ let walked = root;
644
+ for (const component of components) {
645
+ walked = join(walked, component);
646
+ const st = lstatOrNull(walked);
647
+ if (st === null)
648
+ return component;
649
+ if (st.isSymbolicLink())
650
+ return component;
651
+ }
652
+ return null;
653
+ }
654
+ //# sourceMappingURL=cli-build.js.map