@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
@@ -0,0 +1,640 @@
1
+ /**
2
+ * `lib/cli-build.ts` — the module that builds the CLI inside a new worktree (#123).
3
+ *
4
+ * One test per item of the security design pre-ruling on issue #207 (comment
5
+ * 5430622857), named by item number so a reviewer can walk the ruling and this
6
+ * file side by side. `child_process` is mocked, so nothing here spawns npm and
7
+ * nothing reaches the network.
8
+ *
9
+ * I1: `$HOME/.npmrc` exists on this machine and npm reads it on every provision,
10
+ * because M7 keeps `HOME` in the allowlist. No test in this file reads, prints,
11
+ * copies or measures that file, and none dumps npm's resolved configuration: the
12
+ * allowlist is proven from the `env` argument captured at the mock, never from
13
+ * npm's own output.
14
+ */
15
+ import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
16
+ import { mkdirSync, mkdtempSync, rmSync, symlinkSync, writeFileSync } from 'fs';
17
+ import { join } from 'path';
18
+ import { tmpdir } from 'os';
19
+ vi.mock('child_process', () => ({
20
+ spawnSync: vi.fn(),
21
+ }));
22
+ import { spawnSync } from 'child_process';
23
+ import { buildCliInWorktree, buildEnv, excerpt, resolveNpm, ORPHAN_WARNING, REBUILD_REMEDY, ORPHAN_REMEDY, } from '../lib/cli-build.js';
24
+ let root;
25
+ /** The worktree fixture: `<root>/wt` holding `mx-agent-system/cli`. */
26
+ let worktree;
27
+ let cliDir;
28
+ /** Queued answers, consumed one per spawn in order: ci, build, probe. */
29
+ let answers = [];
30
+ const OK = { status: 0, stdout: '', stderr: '' };
31
+ const PROBE_OK = { status: 0, stdout: '0.1.72\n', stderr: '' };
32
+ /** Every spawn's arguments, in call order. */
33
+ function calls() {
34
+ return vi.mocked(spawnSync).mock.calls.map((c) => ({
35
+ command: String(c[0]),
36
+ args: c[1] ?? [],
37
+ options: c[2] ?? {},
38
+ }));
39
+ }
40
+ /** A worktree that passes every pre-spawn check. */
41
+ function makeWorktree() {
42
+ cliDir = join(worktree, 'mx-agent-system', 'cli');
43
+ mkdirSync(cliDir, { recursive: true });
44
+ writeFileSync(join(cliDir, 'package.json'), '{"name":"x","version":"0.1.72"}\n');
45
+ writeFileSync(join(cliDir, 'package-lock.json'), '{"lockfileVersion":3}\n');
46
+ }
47
+ /** A directory holding an executable file named `npm`, for the M2 seam. */
48
+ function fakeNodeDir(withNpm) {
49
+ const dir = mkdtempSync(join(root, 'exec-'));
50
+ if (withNpm)
51
+ writeFileSync(join(dir, 'npm'), '#!/bin/sh\n', { mode: 0o755 });
52
+ return join(dir, 'node');
53
+ }
54
+ beforeEach(() => {
55
+ root = mkdtempSync(join(tmpdir(), 'mx-cli-build-'));
56
+ worktree = join(root, 'wt');
57
+ mkdirSync(worktree, { recursive: true });
58
+ makeWorktree();
59
+ answers = [OK, OK, PROBE_OK];
60
+ vi.mocked(spawnSync).mockReset();
61
+ vi.mocked(spawnSync).mockImplementation((() => {
62
+ const next = answers.shift();
63
+ return next ?? OK;
64
+ }));
65
+ });
66
+ afterEach(() => {
67
+ rmSync(root, { recursive: true, force: true });
68
+ });
69
+ // ── M1. Lifecycle scripts are off, on the argv, on both commands ────────────
70
+ describe('M1 — --ignore-scripts on the argv of both commands', () => {
71
+ it('passes the flag on both, and never through the environment', () => {
72
+ const result = buildCliInWorktree(worktree);
73
+ expect(result.kind).toBe('built');
74
+ const [ci, build] = calls();
75
+ expect(ci.args).toContain('--ignore-scripts');
76
+ expect(build.args).toContain('--ignore-scripts');
77
+ // An argv flag beats a project `.npmrc`; an environment variable does not.
78
+ for (const c of calls()) {
79
+ const env = c.options.env;
80
+ expect(env.npm_config_ignore_scripts).toBeUndefined();
81
+ }
82
+ });
83
+ it('never spawns install, rebuild, link or publish', () => {
84
+ buildCliInWorktree(worktree);
85
+ for (const c of calls()) {
86
+ expect(['install', 'rebuild', 'link', 'publish']).not.toContain(c.args[0]);
87
+ }
88
+ });
89
+ });
90
+ // ── M2. npm resolved beside node first, PATH second ─────────────────────────
91
+ describe('M2 — npm is resolved from dirname(process.execPath) first', () => {
92
+ it('spawns the absolute path when npm sits beside node', () => {
93
+ const execPath = fakeNodeDir(true);
94
+ const result = buildCliInWorktree(worktree, { execPath });
95
+ expect(result.kind).toBe('built');
96
+ expect(calls()[0].command).toBe(join(execPath, '..', 'npm'));
97
+ });
98
+ it('falls back to PATH when nothing sits beside node, and says which was used', () => {
99
+ const execPath = fakeNodeDir(false);
100
+ answers = [{ status: 1, stdout: '', stderr: 'boom' }];
101
+ const result = buildCliInWorktree(worktree, { execPath });
102
+ expect(calls()[0].command).toBe('npm');
103
+ expect(result.kind).toBe('could-not-run');
104
+ if (result.kind !== 'could-not-run')
105
+ throw new Error('unreachable');
106
+ expect(result.detail).toContain('npm from PATH');
107
+ });
108
+ it('reports the node-adjacent npm in the failure detail when that one was used', () => {
109
+ const execPath = fakeNodeDir(true);
110
+ answers = [{ status: 1, stdout: '', stderr: 'boom' }];
111
+ const result = buildCliInWorktree(worktree, { execPath });
112
+ if (result.kind !== 'could-not-run')
113
+ throw new Error('unreachable');
114
+ expect(result.detail).toContain('beside node');
115
+ });
116
+ it('never spawns npm.cmd and never sets shell', () => {
117
+ buildCliInWorktree(worktree);
118
+ for (const c of calls()) {
119
+ expect(c.command).not.toContain('npm.cmd');
120
+ expect(c.options.shell).toBeUndefined();
121
+ }
122
+ });
123
+ it('falls back when the node-adjacent npm is a directory', () => {
124
+ const dir = mkdtempSync(join(root, 'exec-'));
125
+ mkdirSync(join(dir, 'npm'));
126
+ expect(resolveNpm(join(dir, 'node'))).toEqual({ command: 'npm', source: 'PATH' });
127
+ });
128
+ });
129
+ // ── M3. Every symlinked component refuses, before any spawn ─────────────────
130
+ describe('M3 — the containment gate', () => {
131
+ it('refuses when the PARENT mx-agent-system is a symlink, naming it, with zero spawns', () => {
132
+ // The case the last-component check misses: the lexical join still starts
133
+ // with the worktree prefix and `lstatSync(cliDir)` follows the parent and
134
+ // reports a real directory.
135
+ const outside = join(root, 'elsewhere');
136
+ mkdirSync(join(outside, 'cli'), { recursive: true });
137
+ writeFileSync(join(outside, 'cli', 'package.json'), '{}\n');
138
+ writeFileSync(join(outside, 'cli', 'package-lock.json'), '{}\n');
139
+ const wt = join(root, 'wt2');
140
+ mkdirSync(wt, { recursive: true });
141
+ symlinkSync(outside, join(wt, 'mx-agent-system'));
142
+ const result = buildCliInWorktree(wt);
143
+ expect(result.kind).toBe('could-not-run');
144
+ if (result.kind !== 'could-not-run')
145
+ throw new Error('unreachable');
146
+ expect(result.detail).toContain('symlink');
147
+ expect(result.detail).toContain('mx-agent-system');
148
+ expect(spawnSync).not.toHaveBeenCalled();
149
+ });
150
+ it('refuses when the LAST component mx-agent-system/cli is a symlink', () => {
151
+ const outside = join(root, 'elsewhere2');
152
+ mkdirSync(outside, { recursive: true });
153
+ writeFileSync(join(outside, 'package.json'), '{}\n');
154
+ const wt = join(root, 'wt3');
155
+ mkdirSync(join(wt, 'mx-agent-system'), { recursive: true });
156
+ symlinkSync(outside, join(wt, 'mx-agent-system', 'cli'));
157
+ const result = buildCliInWorktree(wt);
158
+ expect(result.kind).toBe('could-not-run');
159
+ if (result.kind !== 'could-not-run')
160
+ throw new Error('unreachable');
161
+ expect(result.detail).toContain('symlink');
162
+ expect(result.detail).toContain('cli');
163
+ expect(spawnSync).not.toHaveBeenCalled();
164
+ });
165
+ it('refuses a component that resolves outside the worktree through ..', () => {
166
+ // `realpathSync(worktreePath)` normalises a literal `..` inside the
167
+ // worktree path itself, so the reachable form of that case is a component
168
+ // whose target climbs out with `..`. The equality check catches it.
169
+ const outside = join(root, 'sibling');
170
+ mkdirSync(join(outside, 'cli'), { recursive: true });
171
+ writeFileSync(join(outside, 'cli', 'package.json'), '{}\n');
172
+ const wt = join(root, 'wt4');
173
+ mkdirSync(wt, { recursive: true });
174
+ symlinkSync('../sibling', join(wt, 'mx-agent-system'));
175
+ const result = buildCliInWorktree(wt);
176
+ expect(result.kind).toBe('could-not-run');
177
+ if (result.kind !== 'could-not-run')
178
+ throw new Error('unreachable');
179
+ expect(result.detail).toContain('symlink');
180
+ expect(spawnSync).not.toHaveBeenCalled();
181
+ });
182
+ it('passes cwd and --prefix= as one byte-identical absolute path', () => {
183
+ buildCliInWorktree(worktree);
184
+ for (const c of calls().slice(0, 2)) {
185
+ const prefix = c.args.find((a) => a.startsWith('--prefix='));
186
+ expect(prefix).toBeDefined();
187
+ const value = prefix.slice('--prefix='.length);
188
+ expect(value).toBe(c.options.cwd);
189
+ expect(value.startsWith('/')).toBe(true);
190
+ }
191
+ });
192
+ });
193
+ // ── M4. .npmrc, shrinkwrap, and the required lockfile ───────────────────────
194
+ describe('M4 — refusals that precede the first spawn', () => {
195
+ const forbidden = [
196
+ ['the worktree .npmrc', ['.npmrc']],
197
+ ['the mx-agent-system .npmrc', ['mx-agent-system', '.npmrc']],
198
+ ['the cli .npmrc', ['mx-agent-system', 'cli', '.npmrc']],
199
+ ['a shrinkwrap', ['mx-agent-system', 'cli', 'npm-shrinkwrap.json']],
200
+ ];
201
+ for (const [name, parts] of forbidden) {
202
+ it(`refuses on ${name}, naming the path, with zero spawns`, () => {
203
+ const path = join(worktree, ...parts);
204
+ writeFileSync(path, 'registry=https://example.invalid/\n');
205
+ const result = buildCliInWorktree(worktree);
206
+ expect(result.kind).toBe('could-not-run');
207
+ if (result.kind !== 'could-not-run')
208
+ throw new Error('unreachable');
209
+ expect(result.detail).toContain(path);
210
+ expect(spawnSync).not.toHaveBeenCalled();
211
+ });
212
+ }
213
+ it('refuses a SYMLINKED .npmrc, which an existence check would follow', () => {
214
+ // `lstatSync`, not `existsSync`: the point of the item is that a `.npmrc`
215
+ // symlinked to a file outside the tree passes an existence check aimed at
216
+ // catching it.
217
+ const path = join(worktree, 'mx-agent-system', 'cli', '.npmrc');
218
+ symlinkSync('/dev/null', path);
219
+ const result = buildCliInWorktree(worktree);
220
+ expect(result.kind).toBe('could-not-run');
221
+ if (result.kind !== 'could-not-run')
222
+ throw new Error('unreachable');
223
+ expect(result.detail).toContain(path);
224
+ expect(spawnSync).not.toHaveBeenCalled();
225
+ });
226
+ it('refuses when package-lock.json is absent, naming the lock file', () => {
227
+ rmSync(join(cliDir, 'package-lock.json'));
228
+ const result = buildCliInWorktree(worktree);
229
+ expect(result.kind).toBe('could-not-run');
230
+ if (result.kind !== 'could-not-run')
231
+ throw new Error('unreachable');
232
+ expect(result.detail).toContain('package-lock.json');
233
+ expect(spawnSync).not.toHaveBeenCalled();
234
+ });
235
+ });
236
+ // ── M5. The stages are gated on each other ──────────────────────────────────
237
+ describe('M5 — a failed npm ci stops the module', () => {
238
+ it('stops after one spawn on a non-zero ci exit', () => {
239
+ answers = [{ status: 1, stdout: '', stderr: 'E404 not found' }];
240
+ const result = buildCliInWorktree(worktree);
241
+ expect(vi.mocked(spawnSync)).toHaveBeenCalledTimes(1);
242
+ expect(result).toMatchObject({ kind: 'could-not-run', stage: 'ci' });
243
+ });
244
+ it('stops after one spawn on a killed ci', () => {
245
+ answers = [{ status: null, signal: 'SIGKILL', stdout: '', stderr: '', error: Object.assign(new Error('timed out'), { code: 'ETIMEDOUT' }) }];
246
+ const result = buildCliInWorktree(worktree);
247
+ expect(vi.mocked(spawnSync)).toHaveBeenCalledTimes(1);
248
+ expect(result).toMatchObject({ kind: 'could-not-run', stage: 'ci' });
249
+ });
250
+ it('never runs the probe after a failed build', () => {
251
+ answers = [OK, { status: 2, stdout: '', stderr: 'tsc failed' }];
252
+ const result = buildCliInWorktree(worktree);
253
+ expect(vi.mocked(spawnSync)).toHaveBeenCalledTimes(2);
254
+ expect(result).toMatchObject({ kind: 'could-not-run', stage: 'build' });
255
+ });
256
+ });
257
+ // ── M6. The excerpt pipeline ────────────────────────────────────────────────
258
+ describe('M6 — the stderr excerpt is bounded, stripped and redacted', () => {
259
+ it('caps one enormous line at 8192 bytes', () => {
260
+ const huge = 'x'.repeat(200_000);
261
+ answers = [{ status: 1, stdout: '', stderr: huge }];
262
+ const result = buildCliInWorktree(worktree);
263
+ if (result.kind !== 'could-not-run')
264
+ throw new Error('unreachable');
265
+ expect(Buffer.from(result.detail, 'utf8').byteLength).toBeLessThanOrEqual(8192 + 300);
266
+ expect(result.detail).not.toContain(huge);
267
+ });
268
+ it('caps 100 lines at 20', () => {
269
+ const lines = Array.from({ length: 100 }, (_, i) => `line-${i}`);
270
+ answers = [{ status: 1, stdout: '', stderr: lines.join('\n') }];
271
+ const result = buildCliInWorktree(worktree);
272
+ if (result.kind !== 'could-not-run')
273
+ throw new Error('unreachable');
274
+ expect(result.detail).toContain('line-99');
275
+ expect(result.detail).not.toContain('line-79');
276
+ });
277
+ it('strips escape sequences that could rewrite the lines above them', () => {
278
+ const esc = String.fromCharCode(27);
279
+ answers = [{ status: 1, stdout: '', stderr: `${esc}[2J${esc}[Hnpm ERR! failed` }];
280
+ const result = buildCliInWorktree(worktree);
281
+ if (result.kind !== 'could-not-run')
282
+ throw new Error('unreachable');
283
+ expect(result.detail).not.toContain(esc);
284
+ expect(result.detail).toContain('npm ERR! failed');
285
+ });
286
+ const secrets = [
287
+ ['URL credentials', 'https://user:tok@registry.example/', 'tok'],
288
+ ['an _authToken', '//registry.example/:_authToken=abcdef123', 'abcdef123'],
289
+ ['an _auth', '_auth=abcdef123', 'abcdef123'],
290
+ ['a _password', '_password=hunter2hunter2', 'hunter2hunter2'],
291
+ ['an Authorization header', 'Authorization: Bearer abcdef123', 'abcdef123'],
292
+ ['a bare Bearer token', 'Bearer abcdef123456', 'abcdef123456'],
293
+ ['a ghp_ token', 'ghp_AAAABBBBCCCCDDDD', 'ghp_AAAABBBBCCCCDDDD'],
294
+ ['a github_pat_ token', 'github_pat_AAAABBBB', 'github_pat_AAAABBBB'],
295
+ ['an sk-ant- key', 'sk-ant-AAAABBBBCCCC', 'sk-ant-AAAABBBBCCCC'],
296
+ ];
297
+ for (const [name, line, leaked] of secrets) {
298
+ it(`redacts ${name}`, () => {
299
+ answers = [{ status: 1, stdout: '', stderr: `npm ERR! ${line}` }];
300
+ const result = buildCliInWorktree(worktree);
301
+ if (result.kind !== 'could-not-run')
302
+ throw new Error('unreachable');
303
+ expect(result.detail).not.toContain(leaked);
304
+ expect(result.detail).toContain('<redacted>');
305
+ });
306
+ }
307
+ it('runs the pipeline on the DETAIL, not only on a logged line', () => {
308
+ // `detail` is what a status report or a PR body copies, so it reaches
309
+ // further than the log does. This whole file asserts against `detail`.
310
+ answers = [{ status: 1, stdout: '', stderr: 'npm ERR! https://u:leaked@r.example/' }];
311
+ const result = buildCliInWorktree(worktree);
312
+ if (result.kind !== 'could-not-run')
313
+ throw new Error('unreachable');
314
+ expect(result.detail).not.toContain('leaked');
315
+ });
316
+ it('redacts BEFORE the cut, so removing a prefix cannot orphan a secret body', () => {
317
+ // The residual that redact-last leaves on its own. The truncation keeps the
318
+ // tail, so it removes the fixed literal prefix first: once `https://` is
319
+ // gone the remainder no longer matches and the secret body would print.
320
+ // Swept across every offset where the 8,192-byte cut lands inside or beside
321
+ // the prefix, so this cannot pass by landing on a lucky alignment.
322
+ const secret = 'SUPERSECRETTOKEN';
323
+ for (let suffixLen = 8180; suffixLen <= 8215; suffixLen++) {
324
+ const credential = `https://user:${secret}@registry.example/x`;
325
+ const payload = credential + 'T'.repeat(Math.max(0, suffixLen - credential.length));
326
+ answers = [{ status: 1, stdout: '', stderr: 'H'.repeat(12_000) + payload }];
327
+ vi.mocked(spawnSync).mockClear();
328
+ const result = buildCliInWorktree(worktree);
329
+ if (result.kind !== 'could-not-run')
330
+ throw new Error('unreachable');
331
+ expect(result.detail, `leaked at suffix length ${suffixLen}`).not.toContain(secret);
332
+ }
333
+ });
334
+ it('redacts a ghp_ token whose prefix the cut removes', () => {
335
+ const body = 'AAAABBBBCCCCDDDDEEEEFFFF';
336
+ for (let suffixLen = 8185; suffixLen <= 8200; suffixLen++) {
337
+ const token = `ghp_${body}`;
338
+ const payload = token + 'T'.repeat(Math.max(0, suffixLen - token.length));
339
+ answers = [{ status: 1, stdout: '', stderr: 'H'.repeat(12_000) + payload }];
340
+ vi.mocked(spawnSync).mockClear();
341
+ const result = buildCliInWorktree(worktree);
342
+ if (result.kind !== 'could-not-run')
343
+ throw new Error('unreachable');
344
+ expect(result.detail, `leaked at suffix length ${suffixLen}`).not.toContain(body);
345
+ }
346
+ });
347
+ it('leaves no secret when the cut splits a redaction marker instead', () => {
348
+ // The residual that redact-first leaves on its own, and the reason the
349
+ // ruling put redaction last. With a pass at each end, a cut can divide only
350
+ // marker text, so what survives is at worst a fragment of `<redacted>`.
351
+ const secret = 'SUPERSECRETTOKEN';
352
+ for (let suffixLen = 8180; suffixLen <= 8200; suffixLen++) {
353
+ const credential = `https://user:${secret}@registry.example/x`;
354
+ const payload = 'T'.repeat(Math.max(0, suffixLen - credential.length)) + credential;
355
+ answers = [{ status: 1, stdout: '', stderr: 'H'.repeat(12_000) + payload }];
356
+ vi.mocked(spawnSync).mockClear();
357
+ const result = buildCliInWorktree(worktree);
358
+ if (result.kind !== 'could-not-run')
359
+ throw new Error('unreachable');
360
+ expect(result.detail, `leaked at suffix length ${suffixLen}`).not.toContain(secret);
361
+ }
362
+ });
363
+ it('redacts a pattern the control strip reassembles, which needs the final pass', () => {
364
+ // A NUL inside the prefix stops the first pass matching. The strip removes
365
+ // it, and the pass after the strip is what catches the result.
366
+ const body = 'AAAABBBBCCCCDDDD';
367
+ answers = [{ status: 1, stdout: '', stderr: `npm ERR! ghp${String.fromCharCode(0)}_${body}` }];
368
+ const result = buildCliInWorktree(worktree);
369
+ if (result.kind !== 'could-not-run')
370
+ throw new Error('unreachable');
371
+ expect(result.detail).not.toContain(body);
372
+ });
373
+ it('exposes the pipeline directly for the two budgets', () => {
374
+ expect(Buffer.from(excerpt('y'.repeat(100_000)), 'utf8').byteLength).toBeLessThanOrEqual(8192);
375
+ expect(excerpt(Array.from({ length: 50 }, (_, i) => `l${i}`).join('\n')).split('\n')).toHaveLength(20);
376
+ });
377
+ });
378
+ // ── M7. The environment allowlist ───────────────────────────────────────────
379
+ describe('M7 — the child environment', () => {
380
+ const DECOYS = [
381
+ 'NODE_ENV',
382
+ 'NODE_PATH',
383
+ 'NODE_OPTIONS',
384
+ 'GIT_DIR',
385
+ 'npm_config_cache',
386
+ 'npm_config_ignore_scripts',
387
+ 'npm_config_registry',
388
+ 'GH_TOKEN',
389
+ 'GITHUB_TOKEN',
390
+ 'ANTHROPIC_API_KEY',
391
+ 'MX_AGENT_OBSERVABILITY_TOKEN',
392
+ ];
393
+ it('drops every decoy and keeps only the allowlist plus the two colour keys', () => {
394
+ const source = { PATH: '/usr/bin', HOME: '/home/node', LANG: 'C' };
395
+ for (const key of DECOYS)
396
+ source[key] = 'decoy-value';
397
+ const env = buildEnv(source);
398
+ for (const key of DECOYS)
399
+ expect(env[key]).toBeUndefined();
400
+ expect(Object.keys(env).sort()).toEqual(['HOME', 'LANG', 'NO_COLOR', 'PATH', 'npm_config_color'].sort());
401
+ expect(env.NO_COLOR).toBe('1');
402
+ expect(env.npm_config_color).toBe('false');
403
+ });
404
+ it('gives every spawn that environment, proven from the captured argument', () => {
405
+ // Proven from what the mock received, never from npm's own output: a test
406
+ // that dumped npm's resolved configuration would put the contents of the
407
+ // user config file into a fleet-readable transcript (I1).
408
+ buildCliInWorktree(worktree, { env: { PATH: '/usr/bin', GH_TOKEN: 'decoy-value' } });
409
+ for (const c of calls()) {
410
+ const env = c.options.env;
411
+ expect(env.GH_TOKEN).toBeUndefined();
412
+ expect(env.NO_COLOR).toBe('1');
413
+ }
414
+ });
415
+ it('passes --include=dev and a fixed --loglevel=error, and never a verbose level', () => {
416
+ buildCliInWorktree(worktree);
417
+ const [ci, build] = calls();
418
+ expect(ci.args).toContain('--include=dev');
419
+ expect(ci.args).toContain('--loglevel=error');
420
+ expect(build.args).toContain('--loglevel=error');
421
+ for (const c of calls()) {
422
+ for (const bad of ['--loglevel=verbose', '--loglevel=silly', '--foreground-scripts', '--verbose']) {
423
+ expect(c.args).not.toContain(bad);
424
+ }
425
+ }
426
+ });
427
+ });
428
+ // ── S1. maxBuffer, and no cache pin ─────────────────────────────────────────
429
+ describe('S1 — the buffer bound and the refused cache pin', () => {
430
+ it('bounds every spawn at 8 MiB', () => {
431
+ buildCliInWorktree(worktree);
432
+ for (const c of calls())
433
+ expect(c.options.maxBuffer).toBe(8 * 1024 * 1024);
434
+ });
435
+ it('pins no npm cache, in the environment or on the argv', () => {
436
+ // Refused: npm's cache is content-addressed and verified on read, and a pin
437
+ // would force a 315 MB download per creation. What matters is that
438
+ // `npm_config_cache` cannot be injected, which the allowlist closes.
439
+ buildCliInWorktree(worktree);
440
+ for (const c of calls()) {
441
+ expect(c.options.env.npm_config_cache).toBeUndefined();
442
+ expect(c.args.some((a) => a.includes('cache'))).toBe(false);
443
+ }
444
+ });
445
+ });
446
+ // ── S2. A build-stage kill leaves a grandchild ──────────────────────────────
447
+ describe('S2 — the build-stage timeout names the orphan and changes the remedy', () => {
448
+ it('warns about a surviving tsc and gives the clearing remedy', () => {
449
+ answers = [OK, { status: null, signal: 'SIGKILL', stdout: '', stderr: '', error: Object.assign(new Error('timed out'), { code: 'ETIMEDOUT' }) }];
450
+ const result = buildCliInWorktree(worktree);
451
+ if (result.kind !== 'could-not-run')
452
+ throw new Error('unreachable');
453
+ expect(result.stage).toBe('build');
454
+ expect(result.detail).toContain(ORPHAN_WARNING);
455
+ expect(result.detail).toContain(ORPHAN_REMEDY);
456
+ expect(ORPHAN_REMEDY).not.toBe(REBUILD_REMEDY);
457
+ });
458
+ it('gives the ordinary remedy on a plain non-zero build exit', () => {
459
+ answers = [OK, { status: 2, stdout: '', stderr: 'tsc error' }];
460
+ const result = buildCliInWorktree(worktree);
461
+ if (result.kind !== 'could-not-run')
462
+ throw new Error('unreachable');
463
+ expect(result.detail).not.toContain(ORPHAN_WARNING);
464
+ expect(result.detail).toContain(REBUILD_REMEDY);
465
+ });
466
+ it('does not let npm stderr choose the remedy', () => {
467
+ // The remedy used to be picked by matching `/timed out|was killed/` against
468
+ // a detail string that already carries npm's stderr, so npm's own words
469
+ // selected the destructive `rm -rf` hint. The verdict comes from the spawn
470
+ // result now, which no output can reach.
471
+ answers = [OK, { status: 1, stdout: '', stderr: 'npm ERR! upstream process was killed by the registry' }];
472
+ const result = buildCliInWorktree(worktree);
473
+ if (result.kind !== 'could-not-run')
474
+ throw new Error('unreachable');
475
+ expect(result.detail).not.toContain(ORPHAN_WARNING);
476
+ expect(result.detail).not.toContain(ORPHAN_REMEDY);
477
+ expect(result.detail).toContain(REBUILD_REMEDY);
478
+ });
479
+ });
480
+ // ── The maxBuffer overflow is not a timeout ─────────────────────────────────
481
+ describe('S1/S2 — a maxBuffer overflow is reported as itself', () => {
482
+ it('names the output bound instead of claiming a timeout', () => {
483
+ // Measured on Node v22.16.0: an overflow gives status null, signal SIGKILL
484
+ // and error.code ENOBUFS, so the signal alone cannot tell it from a timeout.
485
+ answers = [{ status: null, signal: 'SIGKILL', stdout: '', stderr: '', error: Object.assign(new Error('spawnSync ENOBUFS'), { code: 'ENOBUFS' }) }];
486
+ const result = buildCliInWorktree(worktree);
487
+ expect(result).toMatchObject({ kind: 'could-not-run', stage: 'ci' });
488
+ if (result.kind !== 'could-not-run')
489
+ throw new Error('unreachable');
490
+ expect(result.detail).toContain('more than 8 MiB of output');
491
+ expect(result.detail).not.toContain('timed out');
492
+ });
493
+ it('still warns about the orphan when the build stage overflows', () => {
494
+ // The child was signalled, so a grandchild can outlive it exactly as on a
495
+ // timeout. The warning is right here; only the timeout sentence was wrong.
496
+ answers = [OK, { status: null, signal: 'SIGKILL', stdout: '', stderr: '', error: Object.assign(new Error('spawnSync ENOBUFS'), { code: 'ENOBUFS' }) }];
497
+ const result = buildCliInWorktree(worktree);
498
+ if (result.kind !== 'could-not-run')
499
+ throw new Error('unreachable');
500
+ expect(result.stage).toBe('build');
501
+ expect(result.detail).toContain('more than 8 MiB of output');
502
+ expect(result.detail).not.toContain('timed out');
503
+ expect(result.detail).toContain(ORPHAN_WARNING);
504
+ });
505
+ });
506
+ // ── S3. The version probe is parsed, not trusted ────────────────────────────
507
+ describe('S3 — the version probe', () => {
508
+ it('accepts a semver first line and ignores what follows it', () => {
509
+ answers = [OK, OK, { status: 0, stdout: '1.2.3\nnoise\n', stderr: '' }];
510
+ const result = buildCliInWorktree(worktree);
511
+ expect(result).toMatchObject({ kind: 'built', version: '1.2.3' });
512
+ });
513
+ it('accepts a prerelease alone', () => {
514
+ answers = [OK, OK, { status: 0, stdout: '1.2.3-rc.1\n', stderr: '' }];
515
+ expect(buildCliInWorktree(worktree)).toMatchObject({ kind: 'built', version: '1.2.3-rc.1' });
516
+ });
517
+ it('accepts build metadata alone', () => {
518
+ answers = [OK, OK, { status: 0, stdout: '1.2.3+build.5\n', stderr: '' }];
519
+ expect(buildCliInWorktree(worktree)).toMatchObject({ kind: 'built', version: '1.2.3+build.5' });
520
+ });
521
+ it('accepts a prerelease AND build metadata together', () => {
522
+ // The ruling's character class omitted `+` from the suffix, so this legal
523
+ // semver was refused and a good provision read could-not-run.
524
+ answers = [OK, OK, { status: 0, stdout: '1.2.3-rc.1+build.5\n', stderr: '' }];
525
+ expect(buildCliInWorktree(worktree)).toMatchObject({ kind: 'built', version: '1.2.3-rc.1+build.5' });
526
+ });
527
+ it('still refuses the shapes that are not versions', () => {
528
+ for (const bad of ['v1.2.3', '1.2', '1.2.3-', '1.2.3 rubbish', '1.2.3-rc.1+build.5+extra']) {
529
+ answers = [OK, OK, { status: 0, stdout: `${bad}\n`, stderr: '' }];
530
+ vi.mocked(spawnSync).mockClear();
531
+ expect(buildCliInWorktree(worktree), bad).toMatchObject({ kind: 'could-not-run', stage: 'probe' });
532
+ }
533
+ });
534
+ it('refuses output that is not a version, and never prints it', () => {
535
+ const attack = 'not-a-version-but-a-sentence-someone-wrote';
536
+ answers = [OK, OK, { status: 0, stdout: `${attack}\n`, stderr: '' }];
537
+ const result = buildCliInWorktree(worktree);
538
+ expect(result).toMatchObject({ kind: 'could-not-run', stage: 'probe' });
539
+ if (result.kind !== 'could-not-run')
540
+ throw new Error('unreachable');
541
+ expect(result.detail).not.toContain(attack);
542
+ expect(result.detail).toContain(String(attack.length));
543
+ });
544
+ it('refuses a version line longer than 64 characters', () => {
545
+ answers = [OK, OK, { status: 0, stdout: `1.2.3-${'a'.repeat(100)}\n`, stderr: '' }];
546
+ expect(buildCliInWorktree(worktree)).toMatchObject({ kind: 'could-not-run', stage: 'probe' });
547
+ });
548
+ it('runs the probe with the same env, containment and no shell as the other two', () => {
549
+ buildCliInWorktree(worktree);
550
+ const probe = calls()[2];
551
+ expect(probe.args[0]).toBe('--');
552
+ expect(probe.args[2]).toBe('--version');
553
+ expect(probe.options.cwd).toBe(cliDir);
554
+ expect(probe.options.shell).toBeUndefined();
555
+ expect(probe.options.env.NO_COLOR).toBe('1');
556
+ });
557
+ });
558
+ // ── S4. Both versions ───────────────────────────────────────────────────────
559
+ describe('S4 — the built version and the running binary version', () => {
560
+ it('returns the runner version alongside the built one', () => {
561
+ answers = [OK, OK, { status: 0, stdout: '9.9.9\n', stderr: '' }];
562
+ const result = buildCliInWorktree(worktree);
563
+ if (result.kind !== 'built')
564
+ throw new Error('unreachable');
565
+ expect(result.version).toBe('9.9.9');
566
+ // Resolved from the package.json shipping beside this module, the same way
567
+ // `src/index.ts` resolves it. Two different codebases, two fields.
568
+ expect(result.runnerVersion).toMatch(/^\d+\.\d+\.\d+/);
569
+ expect(Object.keys(result)).toContain('runnerVersion');
570
+ });
571
+ });
572
+ // ── S5. The -- separator stays ──────────────────────────────────────────────
573
+ describe('S5 — the run build separator', () => {
574
+ it('keeps -- on the run build argv', () => {
575
+ // Pinned so a later reader who finds the corrected reason does not remove
576
+ // the flag along with the wrong explanation. It separates npm's arguments
577
+ // from the script's; it does not end npm's option parsing.
578
+ buildCliInWorktree(worktree);
579
+ expect(calls()[1].args).toContain('--');
580
+ expect(calls()[1].args[0]).toBe('run');
581
+ expect(calls()[1].args[1]).toBe('build');
582
+ });
583
+ });
584
+ // ── S6. Four kinds and no others ────────────────────────────────────────────
585
+ describe('S6 — the result kinds', () => {
586
+ it('reports not-applicable when the worktree holds no CLI source', () => {
587
+ const wt = join(root, 'consumer');
588
+ mkdirSync(wt, { recursive: true });
589
+ const result = buildCliInWorktree(wt);
590
+ expect(result.kind).toBe('not-applicable');
591
+ expect(spawnSync).not.toHaveBeenCalled();
592
+ });
593
+ it('reports not-applicable when package.json is absent from an existing cli dir', () => {
594
+ rmSync(join(cliDir, 'package.json'));
595
+ expect(buildCliInWorktree(worktree).kind).toBe('not-applicable');
596
+ expect(spawnSync).not.toHaveBeenCalled();
597
+ });
598
+ it('refuses on win32 rather than guessing an extension', () => {
599
+ const result = buildCliInWorktree(worktree, { platform: 'win32' });
600
+ expect(result).toMatchObject({ kind: 'could-not-run', stage: 'ci' });
601
+ expect(spawnSync).not.toHaveBeenCalled();
602
+ });
603
+ it('reports could-not-run on ENOENT from the spawn itself', () => {
604
+ answers = [{ status: null, stdout: '', stderr: '', error: Object.assign(new Error('spawn npm ENOENT'), { code: 'ENOENT' }) }];
605
+ expect(buildCliInWorktree(worktree)).toMatchObject({ kind: 'could-not-run', stage: 'ci' });
606
+ });
607
+ it('never returns a kind outside the four', () => {
608
+ const kinds = new Set();
609
+ kinds.add(buildCliInWorktree(worktree).kind);
610
+ answers = [{ status: 1, stdout: '', stderr: 'x' }];
611
+ kinds.add(buildCliInWorktree(worktree).kind);
612
+ const wt = join(root, 'consumer2');
613
+ mkdirSync(wt, { recursive: true });
614
+ kinds.add(buildCliInWorktree(wt).kind);
615
+ for (const kind of kinds) {
616
+ expect(['built', 'not-applicable', 'not-reached', 'could-not-run']).toContain(kind);
617
+ }
618
+ });
619
+ it('does not let a thrown spawn escape as an exception', () => {
620
+ vi.mocked(spawnSync).mockImplementation((() => {
621
+ throw new Error('spawn exploded');
622
+ }));
623
+ // The module does not catch this itself; `create.ts` step 6e does, and this
624
+ // pins that the throw is what it has to catch rather than a silent success.
625
+ expect(() => buildCliInWorktree(worktree)).toThrow('spawn exploded');
626
+ });
627
+ });
628
+ // ── I1. The constraint that belongs in the test file ────────────────────────
629
+ describe('I1 — no test reads the user npm config', () => {
630
+ it('proves the allowlist from the captured env argument alone', () => {
631
+ // `$HOME/.npmrc` exists on this machine and npm reads it on every provision,
632
+ // because M7 keeps `HOME`. Nothing here reads, prints, copies or measures
633
+ // that file, and nothing dumps npm's resolved configuration.
634
+ buildCliInWorktree(worktree, { env: { PATH: '/usr/bin', HOME: '/home/node' } });
635
+ const env = calls()[0].options.env;
636
+ expect(env.HOME).toBe('/home/node');
637
+ expect(Object.keys(env)).not.toContain('npm_config_userconfig');
638
+ });
639
+ });
640
+ //# sourceMappingURL=cli-build.test.js.map