@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.
- package/dist/__tests__/agents-md-canonicalization.test.js +31 -1
- package/dist/__tests__/agents-md-canonicalization.test.js.map +1 -1
- package/dist/__tests__/behavioral-extraction.test.js +50 -0
- package/dist/__tests__/behavioral-extraction.test.js.map +1 -1
- package/dist/__tests__/bootstrap-behavioral-contract.test.js +6 -3
- package/dist/__tests__/bootstrap-behavioral-contract.test.js.map +1 -1
- package/dist/__tests__/bundle-config.test.js +28 -2
- package/dist/__tests__/bundle-config.test.js.map +1 -1
- package/dist/__tests__/catalog-interaction.test.d.ts +25 -0
- package/dist/__tests__/catalog-interaction.test.d.ts.map +1 -0
- package/dist/__tests__/catalog-interaction.test.js +269 -0
- package/dist/__tests__/catalog-interaction.test.js.map +1 -0
- package/dist/__tests__/catalog-named-memories.test.d.ts +2 -0
- package/dist/__tests__/catalog-named-memories.test.d.ts.map +1 -0
- package/dist/__tests__/catalog-named-memories.test.js +204 -0
- package/dist/__tests__/catalog-named-memories.test.js.map +1 -0
- package/dist/__tests__/catalog-origin-main.test.d.ts +15 -0
- package/dist/__tests__/catalog-origin-main.test.d.ts.map +1 -0
- package/dist/__tests__/catalog-origin-main.test.js +296 -0
- package/dist/__tests__/catalog-origin-main.test.js.map +1 -0
- package/dist/__tests__/catalog.test.d.ts +2 -0
- package/dist/__tests__/catalog.test.d.ts.map +1 -0
- package/dist/__tests__/catalog.test.js +131 -0
- package/dist/__tests__/catalog.test.js.map +1 -0
- package/dist/__tests__/cli-build-integration.test.d.ts +2 -0
- package/dist/__tests__/cli-build-integration.test.d.ts.map +1 -0
- package/dist/__tests__/cli-build-integration.test.js +64 -0
- package/dist/__tests__/cli-build-integration.test.js.map +1 -0
- package/dist/__tests__/cli-build.test.d.ts +2 -0
- package/dist/__tests__/cli-build.test.d.ts.map +1 -0
- package/dist/__tests__/cli-build.test.js +640 -0
- package/dist/__tests__/cli-build.test.js.map +1 -0
- package/dist/__tests__/codex-deploy-config.test.js +60 -0
- package/dist/__tests__/codex-deploy-config.test.js.map +1 -1
- package/dist/__tests__/completion-rows-discriminate.test.d.ts +20 -0
- package/dist/__tests__/completion-rows-discriminate.test.d.ts.map +1 -0
- package/dist/__tests__/completion-rows-discriminate.test.js +481 -0
- package/dist/__tests__/completion-rows-discriminate.test.js.map +1 -0
- package/dist/__tests__/config-fidelity-archived-symlinks.test.d.ts +2 -0
- package/dist/__tests__/config-fidelity-archived-symlinks.test.d.ts.map +1 -0
- package/dist/__tests__/config-fidelity-archived-symlinks.test.js +127 -0
- package/dist/__tests__/config-fidelity-archived-symlinks.test.js.map +1 -0
- package/dist/__tests__/config-fidelity-display.test.d.ts +2 -0
- package/dist/__tests__/config-fidelity-display.test.d.ts.map +1 -0
- package/dist/__tests__/config-fidelity-display.test.js +77 -0
- package/dist/__tests__/config-fidelity-display.test.js.map +1 -0
- package/dist/__tests__/config-fidelity.test.js +166 -33
- package/dist/__tests__/config-fidelity.test.js.map +1 -1
- package/dist/__tests__/config-generation-gate.test.js +78 -0
- package/dist/__tests__/config-generation-gate.test.js.map +1 -1
- package/dist/__tests__/config-sync.test.js +89 -1
- package/dist/__tests__/config-sync.test.js.map +1 -1
- package/dist/__tests__/coordination-401-production-wiring.test.js +12 -7
- package/dist/__tests__/coordination-401-production-wiring.test.js.map +1 -1
- package/dist/__tests__/coordination-401-recovery.test.js +39 -32
- package/dist/__tests__/coordination-401-recovery.test.js.map +1 -1
- package/dist/__tests__/coordination-brief-pin.test.js +21 -8
- package/dist/__tests__/coordination-brief-pin.test.js.map +1 -1
- package/dist/__tests__/coordination-client.test.js +227 -3
- package/dist/__tests__/coordination-client.test.js.map +1 -1
- package/dist/__tests__/coordination-credential-endpoint.test.d.ts +24 -0
- package/dist/__tests__/coordination-credential-endpoint.test.d.ts.map +1 -0
- package/dist/__tests__/coordination-credential-endpoint.test.js +1230 -0
- package/dist/__tests__/coordination-credential-endpoint.test.js.map +1 -0
- package/dist/__tests__/coordination-memory.test.js +20 -4
- package/dist/__tests__/coordination-memory.test.js.map +1 -1
- package/dist/__tests__/coordination-provision.test.js +22 -14
- package/dist/__tests__/coordination-provision.test.js.map +1 -1
- package/dist/__tests__/coordination-status-registration.test.d.ts +16 -0
- package/dist/__tests__/coordination-status-registration.test.d.ts.map +1 -0
- package/dist/__tests__/coordination-status-registration.test.js +480 -0
- package/dist/__tests__/coordination-status-registration.test.js.map +1 -0
- package/dist/__tests__/coordination-token-multitenant.test.js +11 -11
- package/dist/__tests__/coordination-token-multitenant.test.js.map +1 -1
- package/dist/__tests__/coordination-token.test.js +35 -28
- package/dist/__tests__/coordination-token.test.js.map +1 -1
- package/dist/__tests__/creation-pr-class-check.test.d.ts +17 -0
- package/dist/__tests__/creation-pr-class-check.test.d.ts.map +1 -0
- package/dist/__tests__/creation-pr-class-check.test.js +346 -0
- package/dist/__tests__/creation-pr-class-check.test.js.map +1 -0
- package/dist/__tests__/decision-check.test.d.ts +2 -0
- package/dist/__tests__/decision-check.test.d.ts.map +1 -0
- package/dist/__tests__/decision-check.test.js +105 -0
- package/dist/__tests__/decision-check.test.js.map +1 -0
- package/dist/__tests__/digest-team-omission.test.d.ts +15 -0
- package/dist/__tests__/digest-team-omission.test.d.ts.map +1 -0
- package/dist/__tests__/digest-team-omission.test.js +247 -0
- package/dist/__tests__/digest-team-omission.test.js.map +1 -0
- package/dist/__tests__/doctor-worktree-path.test.d.ts +17 -0
- package/dist/__tests__/doctor-worktree-path.test.d.ts.map +1 -0
- package/dist/__tests__/doctor-worktree-path.test.js +158 -0
- package/dist/__tests__/doctor-worktree-path.test.js.map +1 -0
- package/dist/__tests__/fleet-data.test.js +40 -7
- package/dist/__tests__/fleet-data.test.js.map +1 -1
- package/dist/__tests__/fleet-tmux.test.js +2 -2
- package/dist/__tests__/fleet-tmux.test.js.map +1 -1
- package/dist/__tests__/generate-claude.test.js +137 -3
- package/dist/__tests__/generate-claude.test.js.map +1 -1
- package/dist/__tests__/git-env.test.d.ts +14 -0
- package/dist/__tests__/git-env.test.d.ts.map +1 -0
- package/dist/__tests__/git-env.test.js +131 -0
- package/dist/__tests__/git-env.test.js.map +1 -0
- package/dist/__tests__/git-identity-isolation.test.d.ts +33 -0
- package/dist/__tests__/git-identity-isolation.test.d.ts.map +1 -0
- package/dist/__tests__/git-identity-isolation.test.js +626 -0
- package/dist/__tests__/git-identity-isolation.test.js.map +1 -0
- package/dist/__tests__/harness-extract.test.d.ts +19 -0
- package/dist/__tests__/harness-extract.test.d.ts.map +1 -0
- package/dist/__tests__/harness-extract.test.js +566 -0
- package/dist/__tests__/harness-extract.test.js.map +1 -0
- package/dist/__tests__/harness-wiring.test.d.ts +16 -0
- package/dist/__tests__/harness-wiring.test.d.ts.map +1 -0
- package/dist/__tests__/harness-wiring.test.js +469 -0
- package/dist/__tests__/harness-wiring.test.js.map +1 -0
- package/dist/__tests__/hook-heal.test.js +17 -0
- package/dist/__tests__/hook-heal.test.js.map +1 -1
- package/dist/__tests__/init-coordination-url.test.d.ts +11 -0
- package/dist/__tests__/init-coordination-url.test.d.ts.map +1 -0
- package/dist/__tests__/init-coordination-url.test.js +114 -0
- package/dist/__tests__/init-coordination-url.test.js.map +1 -0
- package/dist/__tests__/memory-autocreate.test.js +574 -8
- package/dist/__tests__/memory-autocreate.test.js.map +1 -1
- package/dist/__tests__/memory-log-result.test.d.ts +13 -0
- package/dist/__tests__/memory-log-result.test.d.ts.map +1 -0
- package/dist/__tests__/memory-log-result.test.js +113 -0
- package/dist/__tests__/memory-log-result.test.js.map +1 -0
- package/dist/__tests__/memory-named-exists.test.d.ts +16 -0
- package/dist/__tests__/memory-named-exists.test.d.ts.map +1 -0
- package/dist/__tests__/memory-named-exists.test.js +288 -0
- package/dist/__tests__/memory-named-exists.test.js.map +1 -0
- package/dist/__tests__/mx-agent-cli-pin-validation.test.js +23 -47
- package/dist/__tests__/mx-agent-cli-pin-validation.test.js.map +1 -1
- package/dist/__tests__/mx-agent-cli-version-pin.test.js +34 -88
- package/dist/__tests__/mx-agent-cli-version-pin.test.js.map +1 -1
- package/dist/__tests__/new-project-first-team.test.d.ts +15 -0
- package/dist/__tests__/new-project-first-team.test.d.ts.map +1 -0
- package/dist/__tests__/new-project-first-team.test.js +263 -0
- package/dist/__tests__/new-project-first-team.test.js.map +1 -0
- package/dist/__tests__/otel-env.test.d.ts +2 -0
- package/dist/__tests__/otel-env.test.d.ts.map +1 -0
- package/dist/__tests__/otel-env.test.js +127 -0
- package/dist/__tests__/otel-env.test.js.map +1 -0
- package/dist/__tests__/project-config.test.js +283 -1
- package/dist/__tests__/project-config.test.js.map +1 -1
- package/dist/__tests__/provision-behavioral-contract.test.js +96 -4
- package/dist/__tests__/provision-behavioral-contract.test.js.map +1 -1
- package/dist/__tests__/provision-catalog-precondition.test.d.ts +26 -0
- package/dist/__tests__/provision-catalog-precondition.test.d.ts.map +1 -0
- package/dist/__tests__/provision-catalog-precondition.test.js +620 -0
- package/dist/__tests__/provision-catalog-precondition.test.js.map +1 -0
- package/dist/__tests__/provision-completion-rows.test.d.ts +17 -0
- package/dist/__tests__/provision-completion-rows.test.d.ts.map +1 -0
- package/dist/__tests__/provision-completion-rows.test.js +3095 -0
- package/dist/__tests__/provision-completion-rows.test.js.map +1 -0
- package/dist/__tests__/provision-identity-gate.test.d.ts +20 -0
- package/dist/__tests__/provision-identity-gate.test.d.ts.map +1 -0
- package/dist/__tests__/provision-identity-gate.test.js +600 -0
- package/dist/__tests__/provision-identity-gate.test.js.map +1 -0
- package/dist/__tests__/provision-resume.test.d.ts +26 -0
- package/dist/__tests__/provision-resume.test.d.ts.map +1 -0
- package/dist/__tests__/provision-resume.test.js +1164 -0
- package/dist/__tests__/provision-resume.test.js.map +1 -0
- package/dist/__tests__/provision-roleguide-anchors.test.d.ts +27 -0
- package/dist/__tests__/provision-roleguide-anchors.test.d.ts.map +1 -0
- package/dist/__tests__/provision-roleguide-anchors.test.js +747 -0
- package/dist/__tests__/provision-roleguide-anchors.test.js.map +1 -0
- package/dist/__tests__/provision-skeleton-fill.test.d.ts +16 -0
- package/dist/__tests__/provision-skeleton-fill.test.d.ts.map +1 -0
- package/dist/__tests__/provision-skeleton-fill.test.js +488 -0
- package/dist/__tests__/provision-skeleton-fill.test.js.map +1 -0
- package/dist/__tests__/provision-teambuilder-flow.test.js +93 -7
- package/dist/__tests__/provision-teambuilder-flow.test.js.map +1 -1
- package/dist/__tests__/repo-guard-wiring.test.d.ts +21 -0
- package/dist/__tests__/repo-guard-wiring.test.d.ts.map +1 -0
- package/dist/__tests__/repo-guard-wiring.test.js +638 -0
- package/dist/__tests__/repo-guard-wiring.test.js.map +1 -0
- package/dist/__tests__/report-format.test.d.ts +2 -0
- package/dist/__tests__/report-format.test.d.ts.map +1 -0
- package/dist/__tests__/report-format.test.js +219 -0
- package/dist/__tests__/report-format.test.js.map +1 -0
- package/dist/__tests__/runtime-codex-gateway-pilot.test.d.ts +2 -0
- package/dist/__tests__/runtime-codex-gateway-pilot.test.d.ts.map +1 -0
- package/dist/__tests__/runtime-codex-gateway-pilot.test.js +309 -0
- package/dist/__tests__/runtime-codex-gateway-pilot.test.js.map +1 -0
- package/dist/__tests__/runtime-codex-gateway-provider.test.d.ts +2 -0
- package/dist/__tests__/runtime-codex-gateway-provider.test.d.ts.map +1 -0
- package/dist/__tests__/runtime-codex-gateway-provider.test.js +163 -0
- package/dist/__tests__/runtime-codex-gateway-provider.test.js.map +1 -0
- package/dist/__tests__/runtime-identity.test.d.ts +2 -0
- package/dist/__tests__/runtime-identity.test.d.ts.map +1 -0
- package/dist/__tests__/runtime-identity.test.js +117 -0
- package/dist/__tests__/runtime-identity.test.js.map +1 -0
- package/dist/__tests__/session-pause-provisioning.test.js +6 -1
- package/dist/__tests__/session-pause-provisioning.test.js.map +1 -1
- package/dist/__tests__/session-record-disclosure.test.d.ts +24 -0
- package/dist/__tests__/session-record-disclosure.test.d.ts.map +1 -0
- package/dist/__tests__/session-record-disclosure.test.js +494 -0
- package/dist/__tests__/session-record-disclosure.test.js.map +1 -0
- package/dist/__tests__/session.test.js +35 -0
- package/dist/__tests__/session.test.js.map +1 -1
- package/dist/__tests__/slug-validation.test.js +27 -21
- package/dist/__tests__/slug-validation.test.js.map +1 -1
- package/dist/__tests__/standards-injection.test.d.ts +2 -0
- package/dist/__tests__/standards-injection.test.d.ts.map +1 -0
- package/dist/__tests__/standards-injection.test.js +179 -0
- package/dist/__tests__/standards-injection.test.js.map +1 -0
- package/dist/__tests__/start-interactive-role.test.d.ts +22 -0
- package/dist/__tests__/start-interactive-role.test.d.ts.map +1 -0
- package/dist/__tests__/start-interactive-role.test.js +204 -0
- package/dist/__tests__/start-interactive-role.test.js.map +1 -0
- package/dist/__tests__/start-team-identity.test.d.ts +25 -0
- package/dist/__tests__/start-team-identity.test.d.ts.map +1 -0
- package/dist/__tests__/start-team-identity.test.js +307 -0
- package/dist/__tests__/start-team-identity.test.js.map +1 -0
- package/dist/__tests__/team-memory-commands.test.js +142 -19
- package/dist/__tests__/team-memory-commands.test.js.map +1 -1
- package/dist/__tests__/template-sync.test.d.ts +19 -0
- package/dist/__tests__/template-sync.test.d.ts.map +1 -0
- package/dist/__tests__/template-sync.test.js +270 -0
- package/dist/__tests__/template-sync.test.js.map +1 -0
- package/dist/__tests__/test-project.test.d.ts +18 -0
- package/dist/__tests__/test-project.test.d.ts.map +1 -0
- package/dist/__tests__/test-project.test.js +465 -0
- package/dist/__tests__/test-project.test.js.map +1 -0
- package/dist/__tests__/usage-per-call-grouping.test.d.ts +25 -0
- package/dist/__tests__/usage-per-call-grouping.test.d.ts.map +1 -0
- package/dist/__tests__/usage-per-call-grouping.test.js +952 -0
- package/dist/__tests__/usage-per-call-grouping.test.js.map +1 -0
- package/dist/__tests__/verify-hooks-check-all.test.d.ts +32 -0
- package/dist/__tests__/verify-hooks-check-all.test.d.ts.map +1 -0
- package/dist/__tests__/verify-hooks-check-all.test.js +553 -0
- package/dist/__tests__/verify-hooks-check-all.test.js.map +1 -0
- package/dist/__tests__/worktree-sync-fixture.test.d.ts +17 -0
- package/dist/__tests__/worktree-sync-fixture.test.d.ts.map +1 -0
- package/dist/__tests__/worktree-sync-fixture.test.js +519 -0
- package/dist/__tests__/worktree-sync-fixture.test.js.map +1 -0
- package/dist/__tests__/worktree-sync-hardening.test.d.ts +13 -0
- package/dist/__tests__/worktree-sync-hardening.test.d.ts.map +1 -0
- package/dist/__tests__/worktree-sync-hardening.test.js +919 -0
- package/dist/__tests__/worktree-sync-hardening.test.js.map +1 -0
- package/dist/__tests__/worktree-sync-shell-free.test.d.ts +25 -0
- package/dist/__tests__/worktree-sync-shell-free.test.d.ts.map +1 -0
- package/dist/__tests__/worktree-sync-shell-free.test.js +185 -0
- package/dist/__tests__/worktree-sync-shell-free.test.js.map +1 -0
- package/dist/__tests__/worktree.test.js +75 -1
- package/dist/__tests__/worktree.test.js.map +1 -1
- package/dist/agent-config/.mx-config-generation.json +2 -2
- package/dist/agent-config/AGENTS.md.template +2 -2
- package/dist/agent-config/agents/bar-raiser.md +34 -1
- package/dist/agent-config/agents/red-team.md +34 -1
- package/dist/agent-config/agents/security-reviewer.md +22 -1
- package/dist/agent-config/claude-md/CLAUDE.core.md +6 -1
- package/dist/agent-config/claude-md/CLAUDE.overlay.memnexus.md +1 -3
- package/dist/agent-config/coordination-rosters.generated.json +10 -0
- package/dist/agent-config/hooks/HOOK-TIMEOUTS.md +27 -1
- package/dist/agent-config/hooks/OR-TRUE-AUDIT.md +8 -8
- package/dist/agent-config/hooks/auto-capture-precompact.sh +180 -83
- package/dist/agent-config/hooks/auto-capture-session-end.sh +216 -87
- package/dist/agent-config/hooks/auto-checkpoint.sh +75 -5
- package/dist/agent-config/hooks/coordination-brief.sh +290 -245
- package/dist/agent-config/hooks/deploy-verification-reminder.sh +359 -22
- package/dist/agent-config/hooks/git-mutation-guard.sh +85 -13
- package/dist/agent-config/hooks/observability-sync.sh +46 -9
- package/dist/agent-config/hooks/session-idle-gate.sh +177 -12
- package/dist/agent-config/hooks/subagent-write-guard.sh +670 -0
- package/dist/agent-config/hooks/worktree-guard.sh +36 -7
- package/dist/agent-config/settings.json +15 -2
- package/dist/agent-config/shared/creation-pr-review-checklist.md +317 -0
- package/dist/commands/bootstrap.d.ts.map +1 -1
- package/dist/commands/bootstrap.js +22 -10
- package/dist/commands/bootstrap.js.map +1 -1
- package/dist/commands/config-sync.d.ts +37 -0
- package/dist/commands/config-sync.d.ts.map +1 -1
- package/dist/commands/config-sync.js +36 -18
- package/dist/commands/config-sync.js.map +1 -1
- package/dist/commands/config.d.ts.map +1 -1
- package/dist/commands/config.js +28 -1
- package/dist/commands/config.js.map +1 -1
- package/dist/commands/coordination.d.ts +150 -8
- package/dist/commands/coordination.d.ts.map +1 -1
- package/dist/commands/coordination.js +519 -25
- package/dist/commands/coordination.js.map +1 -1
- package/dist/commands/create.d.ts +913 -1
- package/dist/commands/create.d.ts.map +1 -1
- package/dist/commands/create.js +4879 -345
- package/dist/commands/create.js.map +1 -1
- package/dist/commands/dashboard.d.ts.map +1 -1
- package/dist/commands/dashboard.js +10 -2
- package/dist/commands/dashboard.js.map +1 -1
- package/dist/commands/decision.d.ts +20 -0
- package/dist/commands/decision.d.ts.map +1 -0
- package/dist/commands/decision.js +54 -0
- package/dist/commands/decision.js.map +1 -0
- package/dist/commands/digest.d.ts.map +1 -1
- package/dist/commands/digest.js +91 -7
- package/dist/commands/digest.js.map +1 -1
- package/dist/commands/fleet-tmux.js +1 -1
- package/dist/commands/fleet-tmux.js.map +1 -1
- package/dist/commands/init.d.ts +8 -0
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +26 -1
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/list.d.ts +32 -1
- package/dist/commands/list.d.ts.map +1 -1
- package/dist/commands/list.js +98 -5
- package/dist/commands/list.js.map +1 -1
- package/dist/commands/monitor.d.ts.map +1 -1
- package/dist/commands/monitor.js +8 -2
- package/dist/commands/monitor.js.map +1 -1
- package/dist/commands/new.d.ts +2 -0
- package/dist/commands/new.d.ts.map +1 -1
- package/dist/commands/new.js +114 -21
- package/dist/commands/new.js.map +1 -1
- package/dist/commands/report.d.ts +33 -0
- package/dist/commands/report.d.ts.map +1 -0
- package/dist/commands/report.js +73 -0
- package/dist/commands/report.js.map +1 -0
- package/dist/commands/session.js +1 -1
- package/dist/commands/session.js.map +1 -1
- package/dist/commands/start.d.ts +42 -0
- package/dist/commands/start.d.ts.map +1 -1
- package/dist/commands/start.js +177 -8
- package/dist/commands/start.js.map +1 -1
- package/dist/commands/sync.d.ts +57 -0
- package/dist/commands/sync.d.ts.map +1 -1
- package/dist/commands/sync.js +117 -3
- package/dist/commands/sync.js.map +1 -1
- package/dist/commands/update.d.ts +13 -1
- package/dist/commands/update.d.ts.map +1 -1
- package/dist/commands/update.js +50 -1
- package/dist/commands/update.js.map +1 -1
- package/dist/commands/usage.d.ts +64 -0
- package/dist/commands/usage.d.ts.map +1 -1
- package/dist/commands/usage.js +96 -3
- package/dist/commands/usage.js.map +1 -1
- package/dist/commands/verify-hooks.d.ts +37 -1
- package/dist/commands/verify-hooks.d.ts.map +1 -1
- package/dist/commands/verify-hooks.js +114 -2
- package/dist/commands/verify-hooks.js.map +1 -1
- package/dist/commands/window.d.ts +10 -0
- package/dist/commands/window.d.ts.map +1 -0
- package/dist/commands/window.js +265 -0
- package/dist/commands/window.js.map +1 -0
- package/dist/commands/worktree-sync.d.ts +54 -0
- package/dist/commands/worktree-sync.d.ts.map +1 -0
- package/dist/commands/worktree-sync.js +135 -0
- package/dist/commands/worktree-sync.js.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +189 -14
- package/dist/index.js.map +1 -1
- package/dist/lib/agent-session.d.ts +12 -0
- package/dist/lib/agent-session.d.ts.map +1 -1
- package/dist/lib/agent-session.js +189 -42
- package/dist/lib/agent-session.js.map +1 -1
- package/dist/lib/catalog.d.ts +321 -2
- package/dist/lib/catalog.d.ts.map +1 -1
- package/dist/lib/catalog.js +490 -11
- package/dist/lib/catalog.js.map +1 -1
- package/dist/lib/claude.d.ts +65 -23
- package/dist/lib/claude.d.ts.map +1 -1
- package/dist/lib/claude.js +335 -19
- package/dist/lib/claude.js.map +1 -1
- package/dist/lib/cli-build.d.ts +172 -0
- package/dist/lib/cli-build.d.ts.map +1 -0
- package/dist/lib/cli-build.js +654 -0
- package/dist/lib/cli-build.js.map +1 -0
- package/dist/lib/code-context-file.d.ts +109 -0
- package/dist/lib/code-context-file.d.ts.map +1 -0
- package/dist/lib/code-context-file.js +219 -0
- package/dist/lib/code-context-file.js.map +1 -0
- package/dist/lib/code-context-file.test.d.ts +19 -0
- package/dist/lib/code-context-file.test.d.ts.map +1 -0
- package/dist/lib/code-context-file.test.js +202 -0
- package/dist/lib/code-context-file.test.js.map +1 -0
- package/dist/lib/config-fidelity.d.ts +40 -20
- package/dist/lib/config-fidelity.d.ts.map +1 -1
- package/dist/lib/config-fidelity.js +144 -56
- package/dist/lib/config-fidelity.js.map +1 -1
- package/dist/lib/coordination-client.d.ts +73 -0
- package/dist/lib/coordination-client.d.ts.map +1 -1
- package/dist/lib/coordination-client.js +180 -8
- package/dist/lib/coordination-client.js.map +1 -1
- package/dist/lib/coordination-token.d.ts +304 -6
- package/dist/lib/coordination-token.d.ts.map +1 -1
- package/dist/lib/coordination-token.js +851 -52
- package/dist/lib/coordination-token.js.map +1 -1
- package/dist/lib/decision-check.d.ts +48 -0
- package/dist/lib/decision-check.d.ts.map +1 -0
- package/dist/lib/decision-check.js +149 -0
- package/dist/lib/decision-check.js.map +1 -0
- package/dist/lib/fleet-data.d.ts +34 -0
- package/dist/lib/fleet-data.d.ts.map +1 -1
- package/dist/lib/fleet-data.js +37 -9
- package/dist/lib/fleet-data.js.map +1 -1
- package/dist/lib/fleet-render.js +1 -1
- package/dist/lib/fleet-render.js.map +1 -1
- package/dist/lib/git-identity.d.ts +302 -0
- package/dist/lib/git-identity.d.ts.map +1 -0
- package/dist/lib/git-identity.js +546 -0
- package/dist/lib/git-identity.js.map +1 -0
- package/dist/lib/harness/console/announce.d.ts +45 -0
- package/dist/lib/harness/console/announce.d.ts.map +1 -0
- package/dist/lib/harness/console/announce.js +48 -0
- package/dist/lib/harness/console/announce.js.map +1 -0
- package/dist/lib/harness/console/announce.test.d.ts +2 -0
- package/dist/lib/harness/console/announce.test.d.ts.map +1 -0
- package/dist/lib/harness/console/announce.test.js +104 -0
- package/dist/lib/harness/console/announce.test.js.map +1 -0
- package/dist/lib/harness/console/by-session.d.ts +50 -0
- package/dist/lib/harness/console/by-session.d.ts.map +1 -0
- package/dist/lib/harness/console/by-session.js +83 -0
- package/dist/lib/harness/console/by-session.js.map +1 -0
- package/dist/lib/harness/console/by-session.test.d.ts +2 -0
- package/dist/lib/harness/console/by-session.test.d.ts.map +1 -0
- package/dist/lib/harness/console/by-session.test.js +86 -0
- package/dist/lib/harness/console/by-session.test.js.map +1 -0
- package/dist/lib/harness/console/console.d.ts +67 -0
- package/dist/lib/harness/console/console.d.ts.map +1 -0
- package/dist/lib/harness/console/console.js +373 -0
- package/dist/lib/harness/console/console.js.map +1 -0
- package/dist/lib/harness/console/console.test.d.ts +2 -0
- package/dist/lib/harness/console/console.test.d.ts.map +1 -0
- package/dist/lib/harness/console/console.test.js +269 -0
- package/dist/lib/harness/console/console.test.js.map +1 -0
- package/dist/lib/harness/console/decision-request.d.ts +32 -0
- package/dist/lib/harness/console/decision-request.d.ts.map +1 -0
- package/dist/lib/harness/console/decision-request.js +112 -0
- package/dist/lib/harness/console/decision-request.js.map +1 -0
- package/dist/lib/harness/console/decision-request.test.d.ts +2 -0
- package/dist/lib/harness/console/decision-request.test.d.ts.map +1 -0
- package/dist/lib/harness/console/decision-request.test.js +75 -0
- package/dist/lib/harness/console/decision-request.test.js.map +1 -0
- package/dist/lib/harness/console/fixtures.d.ts +16 -0
- package/dist/lib/harness/console/fixtures.d.ts.map +1 -0
- package/dist/lib/harness/console/fixtures.js +49 -0
- package/dist/lib/harness/console/fixtures.js.map +1 -0
- package/dist/lib/harness/console/index.d.ts +15 -0
- package/dist/lib/harness/console/index.d.ts.map +1 -0
- package/dist/lib/harness/console/index.js +14 -0
- package/dist/lib/harness/console/index.js.map +1 -0
- package/dist/lib/harness/console/rank.d.ts +73 -0
- package/dist/lib/harness/console/rank.d.ts.map +1 -0
- package/dist/lib/harness/console/rank.js +113 -0
- package/dist/lib/harness/console/rank.js.map +1 -0
- package/dist/lib/harness/console/rank.test.d.ts +2 -0
- package/dist/lib/harness/console/rank.test.d.ts.map +1 -0
- package/dist/lib/harness/console/rank.test.js +124 -0
- package/dist/lib/harness/console/rank.test.js.map +1 -0
- package/dist/lib/harness/console/render.d.ts +22 -0
- package/dist/lib/harness/console/render.d.ts.map +1 -0
- package/dist/lib/harness/console/render.js +65 -0
- package/dist/lib/harness/console/render.js.map +1 -0
- package/dist/lib/harness/console/render.test.d.ts +2 -0
- package/dist/lib/harness/console/render.test.d.ts.map +1 -0
- package/dist/lib/harness/console/render.test.js +96 -0
- package/dist/lib/harness/console/render.test.js.map +1 -0
- package/dist/lib/harness/console/replay-cli.test.d.ts +2 -0
- package/dist/lib/harness/console/replay-cli.test.d.ts.map +1 -0
- package/dist/lib/harness/console/replay-cli.test.js +96 -0
- package/dist/lib/harness/console/replay-cli.test.js.map +1 -0
- package/dist/lib/harness/console/replay.d.ts +36 -0
- package/dist/lib/harness/console/replay.d.ts.map +1 -0
- package/dist/lib/harness/console/replay.js +59 -0
- package/dist/lib/harness/console/replay.js.map +1 -0
- package/dist/lib/harness/console/replay.test.d.ts +2 -0
- package/dist/lib/harness/console/replay.test.d.ts.map +1 -0
- package/dist/lib/harness/console/replay.test.js +81 -0
- package/dist/lib/harness/console/replay.test.js.map +1 -0
- package/dist/lib/harness/console/turn-reader.d.ts +50 -0
- package/dist/lib/harness/console/turn-reader.d.ts.map +1 -0
- package/dist/lib/harness/console/turn-reader.js +184 -0
- package/dist/lib/harness/console/turn-reader.js.map +1 -0
- package/dist/lib/harness/console/turn-reader.test.d.ts +2 -0
- package/dist/lib/harness/console/turn-reader.test.d.ts.map +1 -0
- package/dist/lib/harness/console/turn-reader.test.js +108 -0
- package/dist/lib/harness/console/turn-reader.test.js.map +1 -0
- package/dist/lib/harness/console/types.d.ts +109 -0
- package/dist/lib/harness/console/types.d.ts.map +1 -0
- package/dist/lib/harness/console/types.js +2 -0
- package/dist/lib/harness/console/types.js.map +1 -0
- package/dist/lib/harness/contract.d.ts +229 -0
- package/dist/lib/harness/contract.d.ts.map +1 -0
- package/dist/lib/harness/contract.js +22 -0
- package/dist/lib/harness/contract.js.map +1 -0
- package/dist/lib/harness/credential.d.ts +23 -0
- package/dist/lib/harness/credential.d.ts.map +1 -0
- package/dist/lib/harness/credential.js +81 -0
- package/dist/lib/harness/credential.js.map +1 -0
- package/dist/lib/harness/credential.test.d.ts +2 -0
- package/dist/lib/harness/credential.test.d.ts.map +1 -0
- package/dist/lib/harness/credential.test.js +74 -0
- package/dist/lib/harness/credential.test.js.map +1 -0
- package/dist/lib/harness/evaluate.d.ts +390 -0
- package/dist/lib/harness/evaluate.d.ts.map +1 -0
- package/dist/lib/harness/evaluate.js +988 -0
- package/dist/lib/harness/evaluate.js.map +1 -0
- package/dist/lib/harness/evaluate.test.d.ts +2 -0
- package/dist/lib/harness/evaluate.test.d.ts.map +1 -0
- package/dist/lib/harness/evaluate.test.js +621 -0
- package/dist/lib/harness/evaluate.test.js.map +1 -0
- package/dist/lib/harness/extract.d.ts +152 -0
- package/dist/lib/harness/extract.d.ts.map +1 -0
- package/dist/lib/harness/extract.js +1601 -0
- package/dist/lib/harness/extract.js.map +1 -0
- package/dist/lib/harness/gate.d.ts +48 -0
- package/dist/lib/harness/gate.d.ts.map +1 -0
- package/dist/lib/harness/gate.js +60 -0
- package/dist/lib/harness/gate.js.map +1 -0
- package/dist/lib/harness/gate.test.d.ts +2 -0
- package/dist/lib/harness/gate.test.d.ts.map +1 -0
- package/dist/lib/harness/gate.test.js +111 -0
- package/dist/lib/harness/gate.test.js.map +1 -0
- package/dist/lib/harness/self-check.d.ts +59 -0
- package/dist/lib/harness/self-check.d.ts.map +1 -0
- package/dist/lib/harness/self-check.js +56 -0
- package/dist/lib/harness/self-check.js.map +1 -0
- package/dist/lib/harness/self-check.test.d.ts +2 -0
- package/dist/lib/harness/self-check.test.d.ts.map +1 -0
- package/dist/lib/harness/self-check.test.js +43 -0
- package/dist/lib/harness/self-check.test.js.map +1 -0
- package/dist/lib/harness/transcript.d.ts +65 -0
- package/dist/lib/harness/transcript.d.ts.map +1 -0
- package/dist/lib/harness/transcript.js +144 -0
- package/dist/lib/harness/transcript.js.map +1 -0
- package/dist/lib/harness/transcript.test.d.ts +2 -0
- package/dist/lib/harness/transcript.test.d.ts.map +1 -0
- package/dist/lib/harness/transcript.test.js +118 -0
- package/dist/lib/harness/transcript.test.js.map +1 -0
- package/dist/lib/harness-wiring.d.ts +145 -0
- package/dist/lib/harness-wiring.d.ts.map +1 -0
- package/dist/lib/harness-wiring.js +280 -0
- package/dist/lib/harness-wiring.js.map +1 -0
- package/dist/lib/hook-staleness.d.ts +95 -0
- package/dist/lib/hook-staleness.d.ts.map +1 -0
- package/dist/lib/hook-staleness.js +304 -0
- package/dist/lib/hook-staleness.js.map +1 -0
- package/dist/lib/jsonl.d.ts +270 -2
- package/dist/lib/jsonl.d.ts.map +1 -1
- package/dist/lib/jsonl.js +472 -76
- package/dist/lib/jsonl.js.map +1 -1
- package/dist/lib/memory.d.ts +350 -23
- package/dist/lib/memory.d.ts.map +1 -1
- package/dist/lib/memory.js +751 -38
- package/dist/lib/memory.js.map +1 -1
- package/dist/lib/otel-env.d.ts +90 -0
- package/dist/lib/otel-env.d.ts.map +1 -0
- package/dist/lib/otel-env.js +98 -0
- package/dist/lib/otel-env.js.map +1 -0
- package/dist/lib/project-config.d.ts +167 -0
- package/dist/lib/project-config.d.ts.map +1 -1
- package/dist/lib/project-config.js +321 -5
- package/dist/lib/project-config.js.map +1 -1
- package/dist/lib/projects-registry.d.ts +82 -0
- package/dist/lib/projects-registry.d.ts.map +1 -0
- package/dist/lib/projects-registry.js +145 -0
- package/dist/lib/projects-registry.js.map +1 -0
- package/dist/lib/projects-registry.test.d.ts +2 -0
- package/dist/lib/projects-registry.test.d.ts.map +1 -0
- package/dist/lib/projects-registry.test.js +176 -0
- package/dist/lib/projects-registry.test.js.map +1 -0
- package/dist/lib/repo-guard-scope.d.ts +126 -0
- package/dist/lib/repo-guard-scope.d.ts.map +1 -0
- package/dist/lib/repo-guard-scope.js +249 -0
- package/dist/lib/repo-guard-scope.js.map +1 -0
- package/dist/lib/report-format.d.ts +132 -0
- package/dist/lib/report-format.d.ts.map +1 -0
- package/dist/lib/report-format.js +317 -0
- package/dist/lib/report-format.js.map +1 -0
- package/dist/lib/roster.d.ts +87 -0
- package/dist/lib/roster.d.ts.map +1 -0
- package/dist/lib/roster.js +332 -0
- package/dist/lib/roster.js.map +1 -0
- package/dist/lib/roster.test.d.ts +15 -0
- package/dist/lib/roster.test.d.ts.map +1 -0
- package/dist/lib/roster.test.js +299 -0
- package/dist/lib/roster.test.js.map +1 -0
- package/dist/lib/runtime/codex-adapter.d.ts.map +1 -1
- package/dist/lib/runtime/codex-adapter.js +5 -0
- package/dist/lib/runtime/codex-adapter.js.map +1 -1
- package/dist/lib/runtime/codex-config.d.ts +129 -0
- package/dist/lib/runtime/codex-config.d.ts.map +1 -1
- package/dist/lib/runtime/codex-config.js +225 -0
- package/dist/lib/runtime/codex-config.js.map +1 -1
- package/dist/lib/runtime/identity.d.ts +72 -0
- package/dist/lib/runtime/identity.d.ts.map +1 -0
- package/dist/lib/runtime/identity.js +128 -0
- package/dist/lib/runtime/identity.js.map +1 -0
- package/dist/lib/standards.d.ts +99 -0
- package/dist/lib/standards.d.ts.map +1 -0
- package/dist/lib/standards.js +201 -0
- package/dist/lib/standards.js.map +1 -0
- package/dist/lib/team-identity.d.ts +134 -0
- package/dist/lib/team-identity.d.ts.map +1 -0
- package/dist/lib/team-identity.js +193 -0
- package/dist/lib/team-identity.js.map +1 -0
- package/dist/lib/templates.d.ts +29 -2
- package/dist/lib/templates.d.ts.map +1 -1
- package/dist/lib/templates.js +1042 -82
- package/dist/lib/templates.js.map +1 -1
- package/dist/lib/terminal-ui.d.ts.map +1 -1
- package/dist/lib/terminal-ui.js +12 -1
- package/dist/lib/terminal-ui.js.map +1 -1
- package/dist/lib/test-project.d.ts +95 -0
- package/dist/lib/test-project.d.ts.map +1 -0
- package/dist/lib/test-project.js +103 -0
- package/dist/lib/test-project.js.map +1 -0
- package/dist/lib/vault.d.ts +60 -0
- package/dist/lib/vault.d.ts.map +1 -0
- package/dist/lib/vault.js +102 -0
- package/dist/lib/vault.js.map +1 -0
- package/dist/lib/vault.test.d.ts +17 -0
- package/dist/lib/vault.test.d.ts.map +1 -0
- package/dist/lib/vault.test.js +169 -0
- package/dist/lib/vault.test.js.map +1 -0
- package/dist/lib/window-view.d.ts +63 -0
- package/dist/lib/window-view.d.ts.map +1 -0
- package/dist/lib/window-view.js +217 -0
- package/dist/lib/window-view.js.map +1 -0
- package/dist/lib/window-view.test.d.ts +2 -0
- package/dist/lib/window-view.test.d.ts.map +1 -0
- package/dist/lib/window-view.test.js +168 -0
- package/dist/lib/window-view.test.js.map +1 -0
- package/dist/lib/worktree-sync.d.ts +439 -0
- package/dist/lib/worktree-sync.d.ts.map +1 -0
- package/dist/lib/worktree-sync.js +1167 -0
- package/dist/lib/worktree-sync.js.map +1 -0
- package/dist/lib/worktree.d.ts +58 -1
- package/dist/lib/worktree.d.ts.map +1 -1
- package/dist/lib/worktree.js +91 -4
- package/dist/lib/worktree.js.map +1 -1
- package/dist/standards/decision-request.md +98 -0
- package/dist/standards/fail-loud-standard.md +495 -0
- package/dist/standards/po-communication-standard.md +126 -0
- package/dist/standards/report-format.md +128 -0
- package/dist/standards/writing-standard.md +382 -0
- package/package.json +3 -2
- 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
|