@ouro.bot/cli 0.1.0-alpha.1469 → 0.1.0-alpha.1470
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/README.md +1 -1
- package/changelog.json +6 -2
- package/deploy/unraid/sanctuary.ouro/bundle-meta.json +1 -1
- package/deploy/unraid/sanctuary.xml +1 -1
- package/desk.lock.json +8 -0
- package/dist/heart/identity.js +27 -1
- package/dist/mind/desk-section.js +33 -43
- package/dist/repertoire/desk-mcp.js +140 -0
- package/dist/repertoire/mcp-manager.js +22 -0
- package/dist/repertoire/mcp-tools.js +11 -7
- package/npm-shrinkwrap.json +2 -2
- package/package.json +4 -1
- package/vendor/desk/.claude-plugin/plugin.json +35 -0
- package/vendor/desk/.mcp.claude-codex.json +28 -0
- package/vendor/desk/.mcp.copilot.json +16 -0
- package/vendor/desk/.ouro-desk.json +6 -0
- package/vendor/desk/CHANGELOG.md +7004 -0
- package/vendor/desk/README.md +195 -0
- package/vendor/desk/activation/README.md +98 -0
- package/vendor/desk/activation/copilot-root.flattened-bundle.json +38 -0
- package/vendor/desk/activation/desk.activation.json +251 -0
- package/vendor/desk/activation/host-capability-evidence.md +46 -0
- package/vendor/desk/activation/support-matrix.json +84 -0
- package/vendor/desk/agency.json +20 -0
- package/vendor/desk/agents/observer.agent.md +26 -0
- package/vendor/desk/agents/observer.md +29 -0
- package/vendor/desk/agents/worker.agent.md +32 -0
- package/vendor/desk/agents/worker.md +40 -0
- package/vendor/desk/artifacts/tombstones/tombstone.schema.json +53 -0
- package/vendor/desk/artifacts/tombstones/tombstones.jsonl +1 -0
- package/vendor/desk/changelog.d/README.md +12 -0
- package/vendor/desk/docs/agent-files.md +104 -0
- package/vendor/desk/docs/agentic-engineering-v2-rfc.md +206 -0
- package/vendor/desk/docs/agentic-engineering-v3-rfc.md +109 -0
- package/vendor/desk/docs/browser-remote-desktops.md +69 -0
- package/vendor/desk/docs/dependency-activation-stories-and-criteria.md +500 -0
- package/vendor/desk/docs/evaluation-packet.md +363 -0
- package/vendor/desk/docs/factory-local-capture.md +651 -0
- package/vendor/desk/docs/factory-store-playbook.md +927 -0
- package/vendor/desk/docs/images/factory-site.png +0 -0
- package/vendor/desk/docs/issue-drains.md +79 -0
- package/vendor/desk/docs/lfs-inspection.md +55 -0
- package/vendor/desk/docs/preview-diagnostics.md +11 -0
- package/vendor/desk/docs/relays.md +88 -0
- package/vendor/desk/docs/schedules.md +69 -0
- package/vendor/desk/docs/search-recovery.md +22 -0
- package/vendor/desk/docs/session-labels.md +157 -0
- package/vendor/desk/docs/session-retention.md +125 -0
- package/vendor/desk/docs/sessions.md +17 -0
- package/vendor/desk/docs/stalled-nudges.md +54 -0
- package/vendor/desk/docs/webhooks.md +80 -0
- package/vendor/desk/docs/workspace-tidy.md +74 -0
- package/vendor/desk/hooks/boot-checks.cjs +7 -0
- package/vendor/desk/hooks/claude-session-start.cjs +123 -0
- package/vendor/desk/hooks/compatible-node.cjs +97 -0
- package/vendor/desk/hooks/copilot-boot-prompt.cjs +69 -0
- package/vendor/desk/hooks/copilot-durable-files.cjs +8 -0
- package/vendor/desk/hooks/copilot-hooks.json +61 -0
- package/vendor/desk/hooks/copilot-intake-context.cjs +5 -0
- package/vendor/desk/hooks/copilot-lane-model.cjs +8 -0
- package/vendor/desk/hooks/copilot-session-start.cjs +264 -0
- package/vendor/desk/hooks/copilot-skill-current.cjs +28 -0
- package/vendor/desk/hooks/factory-end.cjs +5 -0
- package/vendor/desk/hooks/factory-start.cjs +27 -0
- package/vendor/desk/hooks/hooks.json +40 -0
- package/vendor/desk/hooks/lib/boot-checks.cjs +643 -0
- package/vendor/desk/hooks/lib/child-agent.cjs +14 -0
- package/vendor/desk/hooks/lib/copilot-intake-context.cjs +73 -0
- package/vendor/desk/hooks/lib/current-release.cjs +162 -0
- package/vendor/desk/hooks/lib/delivery-stop.cjs +326 -0
- package/vendor/desk/hooks/lib/detach-worker.cjs +43 -0
- package/vendor/desk/hooks/lib/durable-files.cjs +102 -0
- package/vendor/desk/hooks/lib/factory-end.cjs +327 -0
- package/vendor/desk/hooks/lib/lane-model.cjs +82 -0
- package/vendor/desk/hooks/lib/node-required.cjs +56 -0
- package/vendor/desk/hooks/lib/orca-session-title.cjs +60 -0
- package/vendor/desk/hooks/lib/session-end.cjs +30 -0
- package/vendor/desk/hooks/lib/sync-end.cjs +89 -0
- package/vendor/desk/hooks/loop-start.cjs +105 -0
- package/vendor/desk/hooks/node-missing.sh +78 -0
- package/vendor/desk/hooks/orca-session-title.cjs +8 -0
- package/vendor/desk/hooks/session-end.cjs +8 -0
- package/vendor/desk/mcp/README.md +269 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/darwin-arm64-node-127/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.manifest.json +881 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/darwin-arm64-node-127/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.sha256 +1 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/darwin-arm64-node-127/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.tgz +0 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/darwin-arm64-node-137/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.manifest.json +881 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/darwin-arm64-node-137/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.sha256 +1 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/darwin-arm64-node-137/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.tgz +0 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/linux-x64-node-127/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.manifest.json +881 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/linux-x64-node-127/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.sha256 +1 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/linux-x64-node-127/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.tgz +0 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/linux-x64-node-137/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.manifest.json +881 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/linux-x64-node-137/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.sha256 +1 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/linux-x64-node-137/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.tgz +0 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/linux-x64-node-147/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.manifest.json +881 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/linux-x64-node-147/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.sha256 +1 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/linux-x64-node-147/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.tgz +0 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/support-matrix.json +72 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/win32-x64-node-137/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.manifest.json +881 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/win32-x64-node-137/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.sha256 +1 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/win32-x64-node-137/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.tgz +0 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/win32-x64-node-147/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.manifest.json +881 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/win32-x64-node-147/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.sha256 +1 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/win32-x64-node-147/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.tgz +0 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/README.md +25 -0
- package/vendor/desk/mcp/bootstrap.cjs +761 -0
- package/vendor/desk/mcp/docs/private-feedback.md +13 -0
- package/vendor/desk/mcp/idle-proxy.cjs +423 -0
- package/vendor/desk/mcp/index.js +813 -0
- package/vendor/desk/mcp/package-lock.json +3717 -0
- package/vendor/desk/mcp/package.json +44 -0
- package/vendor/desk/mcp/scripts/agency-desk-channel.js +7 -0
- package/vendor/desk/mcp/scripts/build-runtime-deps-pack.js +5 -0
- package/vendor/desk/mcp/scripts/crew.js +89 -0
- package/vendor/desk/mcp/scripts/drains-launcher.mjs +329 -0
- package/vendor/desk/mcp/scripts/drains.js +5 -0
- package/vendor/desk/mcp/scripts/factory.js +657 -0
- package/vendor/desk/mcp/scripts/file-desk-problem.js +9 -0
- package/vendor/desk/mcp/scripts/finish-commit.js +7 -0
- package/vendor/desk/mcp/scripts/lfs.js +37 -0
- package/vendor/desk/mcp/scripts/local-recovery.js +363 -0
- package/vendor/desk/mcp/scripts/migrations.js +11 -0
- package/vendor/desk/mcp/scripts/private-view.js +177 -0
- package/vendor/desk/mcp/scripts/resolve-desk-root.js +106 -0
- package/vendor/desk/mcp/scripts/session-boot.js +22 -0
- package/vendor/desk/mcp/scripts/session-retention.js +5 -0
- package/vendor/desk/mcp/scripts/session-sync.js +10 -0
- package/vendor/desk/mcp/scripts/sessions.js +5 -0
- package/vendor/desk/mcp/scripts/sync-push.js +13 -0
- package/vendor/desk/mcp/scripts/tidy-status.js +8 -0
- package/vendor/desk/mcp/scripts/verify-runtime-deps-pack.js +5 -0
- package/vendor/desk/mcp/src/actions/desk-read.actions.mts +73 -0
- package/vendor/desk/mcp/src/actions/desk-session.actions.mts +42 -0
- package/vendor/desk/mcp/src/actions/desk-web.actions.mts +52 -0
- package/vendor/desk/mcp/src/actions/desk.actions.mts +5 -0
- package/vendor/desk/mcp/src/actions/generated/desk/OuroActions.swift +649 -0
- package/vendor/desk/mcp/src/actions/generated/desk/OuroActionsReins.swift +61 -0
- package/vendor/desk/mcp/src/actions/generated/desk/actions.json +280 -0
- package/vendor/desk/mcp/src/actions/generated/desk/commands.json +145 -0
- package/vendor/desk/mcp/src/actions/generated/desk/mcp.json +256 -0
- package/vendor/desk/mcp/src/actions/generated/desk/web.ts +59 -0
- package/vendor/desk/mcp/src/actions/generated/desk/webmcp.json +250 -0
- package/vendor/desk/mcp/src/actions/generated/desk-web/OuroActions.swift +241 -0
- package/vendor/desk/mcp/src/actions/generated/desk-web/OuroActionsReins.swift +25 -0
- package/vendor/desk/mcp/src/actions/generated/desk-web/actions.json +73 -0
- package/vendor/desk/mcp/src/actions/generated/desk-web/commands.json +53 -0
- package/vendor/desk/mcp/src/actions/generated/desk-web/mcp.json +83 -0
- package/vendor/desk/mcp/src/actions/generated/desk-web/web.ts +47 -0
- package/vendor/desk/mcp/src/actions/generated/desk-web/webmcp.json +81 -0
- package/vendor/desk/mcp/src/actions/served.js +5 -0
- package/vendor/desk/mcp/src/activation/admit.js +77 -0
- package/vendor/desk/mcp/src/activation/failures.js +65 -0
- package/vendor/desk/mcp/src/activation/readiness-policy.js +102 -0
- package/vendor/desk/mcp/src/activation/schema.js +17 -0
- package/vendor/desk/mcp/src/activation/superpowers-context.js +265 -0
- package/vendor/desk/mcp/src/activation/validate.js +540 -0
- package/vendor/desk/mcp/src/artifacts/tombstones.js +61 -0
- package/vendor/desk/mcp/src/crew/initiative.js +287 -0
- package/vendor/desk/mcp/src/crew/workspace.js +1259 -0
- package/vendor/desk/mcp/src/db/init.js +75 -0
- package/vendor/desk/mcp/src/db/schema.sql +83 -0
- package/vendor/desk/mcp/src/desk/active-tasks.js +408 -0
- package/vendor/desk/mcp/src/desk/card-commit-guard.js +281 -0
- package/vendor/desk/mcp/src/desk/cleanup-index.js +53 -0
- package/vendor/desk/mcp/src/desk/content-home.js +246 -0
- package/vendor/desk/mcp/src/desk/crew-config.js +102 -0
- package/vendor/desk/mcp/src/desk/crew-member.js +196 -0
- package/vendor/desk/mcp/src/desk/crew-roster.js +151 -0
- package/vendor/desk/mcp/src/desk/frontmatter-lite.js +228 -0
- package/vendor/desk/mcp/src/desk/gh-logins.js +109 -0
- package/vendor/desk/mcp/src/desk/handles.js +123 -0
- package/vendor/desk/mcp/src/desk/handoff-reference.js +35 -0
- package/vendor/desk/mcp/src/desk/improvement-authority.js +3 -0
- package/vendor/desk/mcp/src/desk/improvement-cards.js +704 -0
- package/vendor/desk/mcp/src/desk/improvement-person.js +51 -0
- package/vendor/desk/mcp/src/desk/lifecycle.js +16 -0
- package/vendor/desk/mcp/src/desk/machine-desks.js +119 -0
- package/vendor/desk/mcp/src/desk/naming.js +333 -0
- package/vendor/desk/mcp/src/desk/organization.js +592 -0
- package/vendor/desk/mcp/src/desk/resources.js +274 -0
- package/vendor/desk/mcp/src/desk/runtime-resolver.js +30 -0
- package/vendor/desk/mcp/src/desk/scratch-paths.js +44 -0
- package/vendor/desk/mcp/src/desk/step-delivery.js +140 -0
- package/vendor/desk/mcp/src/desk/steps.js +263 -0
- package/vendor/desk/mcp/src/desk/tidy.js +930 -0
- package/vendor/desk/mcp/src/desk/unsigned-deliveries.js +359 -0
- package/vendor/desk/mcp/src/factory/agent-types.js +45 -0
- package/vendor/desk/mcp/src/factory/andon-watch.js +109 -0
- package/vendor/desk/mcp/src/factory/binding.js +612 -0
- package/vendor/desk/mcp/src/factory/boot-check.js +645 -0
- package/vendor/desk/mcp/src/factory/capture-classify.js +158 -0
- package/vendor/desk/mcp/src/factory/capture-count.js +183 -0
- package/vendor/desk/mcp/src/factory/capture-flush.js +268 -0
- package/vendor/desk/mcp/src/factory/capture-publish.js +141 -0
- package/vendor/desk/mcp/src/factory/capture-schema.js +193 -0
- package/vendor/desk/mcp/src/factory/capture-sweep.js +239 -0
- package/vendor/desk/mcp/src/factory/catch-point.js +60 -0
- package/vendor/desk/mcp/src/factory/commit-resolve.js +94 -0
- package/vendor/desk/mcp/src/factory/consent-answer.js +37 -0
- package/vendor/desk/mcp/src/factory/context-capability.js +15 -0
- package/vendor/desk/mcp/src/factory/context-outbox.js +885 -0
- package/vendor/desk/mcp/src/factory/context-run.js +386 -0
- package/vendor/desk/mcp/src/factory/context-schema.js +249 -0
- package/vendor/desk/mcp/src/factory/copilot-turn-index.js +93 -0
- package/vendor/desk/mcp/src/factory/copilot-usage.js +148 -0
- package/vendor/desk/mcp/src/factory/credential.js +45 -0
- package/vendor/desk/mcp/src/factory/derive-claude.js +960 -0
- package/vendor/desk/mcp/src/factory/derive-codex.js +734 -0
- package/vendor/desk/mcp/src/factory/derive-common.js +279 -0
- package/vendor/desk/mcp/src/factory/derive-copilot.js +1057 -0
- package/vendor/desk/mcp/src/factory/derive-run.js +807 -0
- package/vendor/desk/mcp/src/factory/desk-problem-file.js +310 -0
- package/vendor/desk/mcp/src/factory/desk-problem-fingerprint.js +70 -0
- package/vendor/desk/mcp/src/factory/desk-problem-known.js +246 -0
- package/vendor/desk/mcp/src/factory/desk-problem-template.js +107 -0
- package/vendor/desk/mcp/src/factory/desk-repo.js +1223 -0
- package/vendor/desk/mcp/src/factory/desk-task-line.js +28 -0
- package/vendor/desk/mcp/src/factory/desk-visibility.js +48 -0
- package/vendor/desk/mcp/src/factory/end-hook.js +14 -0
- package/vendor/desk/mcp/src/factory/evaluate-kick.js +164 -0
- package/vendor/desk/mcp/src/factory/evaluate-run.js +678 -0
- package/vendor/desk/mcp/src/factory/evaluator-step.js +484 -0
- package/vendor/desk/mcp/src/factory/filer-launch.js +79 -0
- package/vendor/desk/mcp/src/factory/flush-health.js +26 -0
- package/vendor/desk/mcp/src/factory/flush.js +1758 -0
- package/vendor/desk/mcp/src/factory/focus.js +326 -0
- package/vendor/desk/mcp/src/factory/headless-flag.cjs +32 -0
- package/vendor/desk/mcp/src/factory/headless-flag.js +25 -0
- package/vendor/desk/mcp/src/factory/headless-ledger.js +743 -0
- package/vendor/desk/mcp/src/factory/headless.js +567 -0
- package/vendor/desk/mcp/src/factory/held-route.js +93 -0
- package/vendor/desk/mcp/src/factory/host-flags.js +36 -0
- package/vendor/desk/mcp/src/factory/improvement-verify.js +429 -0
- package/vendor/desk/mcp/src/factory/kaizen-file.js +231 -0
- package/vendor/desk/mcp/src/factory/label-binding.js +90 -0
- package/vendor/desk/mcp/src/factory/label-schema.js +426 -0
- package/vendor/desk/mcp/src/factory/local-status.js +368 -0
- package/vendor/desk/mcp/src/factory/loop-conditions.js +121 -0
- package/vendor/desk/mcp/src/factory/loop-health.js +500 -0
- package/vendor/desk/mcp/src/factory/loop-slot.js +90 -0
- package/vendor/desk/mcp/src/factory/loop-status.js +100 -0
- package/vendor/desk/mcp/src/factory/loop-switch.cjs +14 -0
- package/vendor/desk/mcp/src/factory/loop-worker-state.js +96 -0
- package/vendor/desk/mcp/src/factory/loop-worker.js +290 -0
- package/vendor/desk/mcp/src/factory/marker.js +61 -0
- package/vendor/desk/mcp/src/factory/mirror-step.js +145 -0
- package/vendor/desk/mcp/src/factory/os-protect.js +243 -0
- package/vendor/desk/mcp/src/factory/outbox.js +2231 -0
- package/vendor/desk/mcp/src/factory/outcome.js +431 -0
- package/vendor/desk/mcp/src/factory/pipeline/andon.js +319 -0
- package/vendor/desk/mcp/src/factory/pipeline/attention-rollup.js +158 -0
- package/vendor/desk/mcp/src/factory/pipeline/attention.js +146 -0
- package/vendor/desk/mcp/src/factory/pipeline/build.js +299 -0
- package/vendor/desk/mcp/src/factory/pipeline/compare.js +148 -0
- package/vendor/desk/mcp/src/factory/pipeline/formulas.js +652 -0
- package/vendor/desk/mcp/src/factory/pipeline/kaizen.js +387 -0
- package/vendor/desk/mcp/src/factory/pipeline/lifecycle-clocks.js +345 -0
- package/vendor/desk/mcp/src/factory/pipeline/normalize.js +73 -0
- package/vendor/desk/mcp/src/factory/pipeline/number-states.js +154 -0
- package/vendor/desk/mcp/src/factory/pipeline/outcomes.js +268 -0
- package/vendor/desk/mcp/src/factory/pipeline/report.js +737 -0
- package/vendor/desk/mcp/src/factory/pipeline/rollups.js +883 -0
- package/vendor/desk/mcp/src/factory/pipeline/stretches.js +523 -0
- package/vendor/desk/mcp/src/factory/pipeline/timeline.js +199 -0
- package/vendor/desk/mcp/src/factory/pipeline/validate-pr.js +238 -0
- package/vendor/desk/mcp/src/factory/pipeline/versions.js +42 -0
- package/vendor/desk/mcp/src/factory/pipeline/walk.js +1177 -0
- package/vendor/desk/mcp/src/factory/plugin-registry.js +72 -0
- package/vendor/desk/mcp/src/factory/plugin-sources.cjs +249 -0
- package/vendor/desk/mcp/src/factory/pr-green.js +77 -0
- package/vendor/desk/mcp/src/factory/process-lock.js +142 -0
- package/vendor/desk/mcp/src/factory/proof-session.js +75 -0
- package/vendor/desk/mcp/src/factory/publish.js +637 -0
- package/vendor/desk/mcp/src/factory/published-schema.js +648 -0
- package/vendor/desk/mcp/src/factory/reconcile-reasons.js +22 -0
- package/vendor/desk/mcp/src/factory/reconcile-step.js +251 -0
- package/vendor/desk/mcp/src/factory/reconcile.js +808 -0
- package/vendor/desk/mcp/src/factory/release-version.js +134 -0
- package/vendor/desk/mcp/src/factory/repo-name.js +13 -0
- package/vendor/desk/mcp/src/factory/retention.js +60 -0
- package/vendor/desk/mcp/src/factory/route-desk.js +40 -0
- package/vendor/desk/mcp/src/factory/route-issues.js +251 -0
- package/vendor/desk/mcp/src/factory/route-local.js +264 -0
- package/vendor/desk/mcp/src/factory/schema.js +957 -0
- package/vendor/desk/mcp/src/factory/session-kind.js +16 -0
- package/vendor/desk/mcp/src/factory/session-lifetime.js +56 -0
- package/vendor/desk/mcp/src/factory/session-route.js +183 -0
- package/vendor/desk/mcp/src/factory/shell-git.js +500 -0
- package/vendor/desk/mcp/src/factory/store-issues.js +143 -0
- package/vendor/desk/mcp/src/factory/store-route.js +208 -0
- package/vendor/desk/mcp/src/factory/test-state-guard.js +103 -0
- package/vendor/desk/mcp/src/factory/time.js +36 -0
- package/vendor/desk/mcp/src/factory/tool-issue-file.js +84 -0
- package/vendor/desk/mcp/src/factory/tool-kinds.js +87 -0
- package/vendor/desk/mcp/src/factory/triage-schema.js +233 -0
- package/vendor/desk/mcp/src/factory/windows-acl.js +679 -0
- package/vendor/desk/mcp/src/indexer/chunk.js +232 -0
- package/vendor/desk/mcp/src/indexer/discover.js +434 -0
- package/vendor/desk/mcp/src/indexer/exclusions.js +247 -0
- package/vendor/desk/mcp/src/indexer/index.js +167 -0
- package/vendor/desk/mcp/src/indexer/refs.js +0 -0
- package/vendor/desk/mcp/src/indexer/text-hash.js +18 -0
- package/vendor/desk/mcp/src/lib/ouro-actions/actions.claims.json +75 -0
- package/vendor/desk/mcp/src/lib/ouro-actions/dist-manifest.json +70 -0
- package/vendor/desk/mcp/src/lib/ouro-actions/ouro-actions.mts +1416 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/LICENSE +21 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/ax-claims.ts +190 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/ax-command.ts +1020 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/checks.ts +343 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/cli.ts +240 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/component.ts +430 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/dev-commands.ts +204 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/doctor.ts +126 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/effects.ts +68 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/exit-codes.ts +75 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/help.ts +220 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/mcp.ts +268 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/outcome.ts +265 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/output.ts +67 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/precise-copy.ts +235 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/problem.ts +124 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/surfaces.kit.mts +8 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/surfaces.ts +568 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/terminal.ts +245 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/voice.ts +136 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/wait.ts +226 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/work-event.ts +181 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/xray.kit.mts +18 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/xray.ts +2072 -0
- package/vendor/desk/mcp/src/package-metadata.js +20 -0
- package/vendor/desk/mcp/src/protected/legacy-ledger.js +55 -0
- package/vendor/desk/mcp/src/readiness/leftovers.js +75 -0
- package/vendor/desk/mcp/src/readiness/process-start.js +149 -0
- package/vendor/desk/mcp/src/runtime/admission-worker.js +194 -0
- package/vendor/desk/mcp/src/runtime/admission.js +177 -0
- package/vendor/desk/mcp/src/runtime/agency-desk-channel.js +342 -0
- package/vendor/desk/mcp/src/runtime/agents-md.js +62 -0
- package/vendor/desk/mcp/src/runtime/append-lane.js +68 -0
- package/vendor/desk/mcp/src/runtime/argv-safe-reason.js +55 -0
- package/vendor/desk/mcp/src/runtime/boot-dependencies.js +75 -0
- package/vendor/desk/mcp/src/runtime/boot-text.js +504 -0
- package/vendor/desk/mcp/src/runtime/boot.js +1677 -0
- package/vendor/desk/mcp/src/runtime/bootstrap.js +1455 -0
- package/vendor/desk/mcp/src/runtime/chunked-import.js +102 -0
- package/vendor/desk/mcp/src/runtime/copilot-commit-trailer.js +133 -0
- package/vendor/desk/mcp/src/runtime/copilot-session.js +155 -0
- package/vendor/desk/mcp/src/runtime/deliver.js +469 -0
- package/vendor/desk/mcp/src/runtime/desk-channel.js +86 -0
- package/vendor/desk/mcp/src/runtime/desk-failure.js +26 -0
- package/vendor/desk/mcp/src/runtime/desk-health.js +168 -0
- package/vendor/desk/mcp/src/runtime/desk-session.js +1451 -0
- package/vendor/desk/mcp/src/runtime/diagnostic-server.js +72 -0
- package/vendor/desk/mcp/src/runtime/diagnostics.js +241 -0
- package/vendor/desk/mcp/src/runtime/drains-cli.js +187 -0
- package/vendor/desk/mcp/src/runtime/drains.js +781 -0
- package/vendor/desk/mcp/src/runtime/elsewhere-note.js +9 -0
- package/vendor/desk/mcp/src/runtime/failure-evidence.js +21 -0
- package/vendor/desk/mcp/src/runtime/fast-refs.js +209 -0
- package/vendor/desk/mcp/src/runtime/filer-throttle.js +66 -0
- package/vendor/desk/mcp/src/runtime/focused-card.js +147 -0
- package/vendor/desk/mcp/src/runtime/front-door.js +204 -0
- package/vendor/desk/mcp/src/runtime/gate-wait.js +2 -0
- package/vendor/desk/mcp/src/runtime/git-inspection.js +201 -0
- package/vendor/desk/mcp/src/runtime/git-read-worker.js +157 -0
- package/vendor/desk/mcp/src/runtime/health.js +50 -0
- package/vendor/desk/mcp/src/runtime/hooks.js +353 -0
- package/vendor/desk/mcp/src/runtime/hosted.js +163 -0
- package/vendor/desk/mcp/src/runtime/inbox.js +102 -0
- package/vendor/desk/mcp/src/runtime/index-drift.js +118 -0
- package/vendor/desk/mcp/src/runtime/last-start.js +133 -0
- package/vendor/desk/mcp/src/runtime/lesson-section.js +92 -0
- package/vendor/desk/mcp/src/runtime/lessons-shelf.js +100 -0
- package/vendor/desk/mcp/src/runtime/lfs.js +319 -0
- package/vendor/desk/mcp/src/runtime/native-path.js +12 -0
- package/vendor/desk/mcp/src/runtime/newest-release.js +197 -0
- package/vendor/desk/mcp/src/runtime/node-selection.js +233 -0
- package/vendor/desk/mcp/src/runtime/orca-session-title.js +225 -0
- package/vendor/desk/mcp/src/runtime/other-sessions.js +183 -0
- package/vendor/desk/mcp/src/runtime/pending-migrations.js +653 -0
- package/vendor/desk/mcp/src/runtime/plugin-update.js +215 -0
- package/vendor/desk/mcp/src/runtime/pluginless-runtimes.js +34 -0
- package/vendor/desk/mcp/src/runtime/pr-publication.js +226 -0
- package/vendor/desk/mcp/src/runtime/preview-snapshot.js +23 -0
- package/vendor/desk/mcp/src/runtime/publication-mode.js +19 -0
- package/vendor/desk/mcp/src/runtime/relays.js +974 -0
- package/vendor/desk/mcp/src/runtime/release-alert.js +148 -0
- package/vendor/desk/mcp/src/runtime/remote-identity.js +140 -0
- package/vendor/desk/mcp/src/runtime/resolve-here.js +4 -0
- package/vendor/desk/mcp/src/runtime/runtime-deps-cli.js +65 -0
- package/vendor/desk/mcp/src/runtime/runtime-deps.js +1109 -0
- package/vendor/desk/mcp/src/runtime/runtime-identity.js +22 -0
- package/vendor/desk/mcp/src/runtime/runtime-swap.js +101 -0
- package/vendor/desk/mcp/src/runtime/schedules.js +235 -0
- package/vendor/desk/mcp/src/runtime/session-activity.js +190 -0
- package/vendor/desk/mcp/src/runtime/session-label.js +30 -0
- package/vendor/desk/mcp/src/runtime/session-retention.js +662 -0
- package/vendor/desk/mcp/src/runtime/session-sync.js +333 -0
- package/vendor/desk/mcp/src/runtime/session-trailer.js +126 -0
- package/vendor/desk/mcp/src/runtime/sessions-cli.js +301 -0
- package/vendor/desk/mcp/src/runtime/signoff-listed.js +81 -0
- package/vendor/desk/mcp/src/runtime/skills.js +76 -0
- package/vendor/desk/mcp/src/runtime/stale-card-lead.js +52 -0
- package/vendor/desk/mcp/src/runtime/stale-desk-refresh.js +198 -0
- package/vendor/desk/mcp/src/runtime/stale-desk.js +219 -0
- package/vendor/desk/mcp/src/runtime/stalled.js +255 -0
- package/vendor/desk/mcp/src/runtime/standing-authority.js +79 -0
- package/vendor/desk/mcp/src/runtime/startup-boot.js +341 -0
- package/vendor/desk/mcp/src/runtime/startup-resolve.js +140 -0
- package/vendor/desk/mcp/src/runtime/state-branch.js +203 -0
- package/vendor/desk/mcp/src/runtime/status-compact.js +165 -0
- package/vendor/desk/mcp/src/runtime/status-inspection-child.js +26 -0
- package/vendor/desk/mcp/src/runtime/status-inspection.js +147 -0
- package/vendor/desk/mcp/src/runtime/status-root.js +39 -0
- package/vendor/desk/mcp/src/runtime/sync-worker.js +911 -0
- package/vendor/desk/mcp/src/runtime/test-state-guard.js +107 -0
- package/vendor/desk/mcp/src/runtime/unmerged-saves.js +247 -0
- package/vendor/desk/mcp/src/runtime/workspace-claim.js +53 -0
- package/vendor/desk/mcp/src/runtime/workspace-evidence.js +96 -0
- package/vendor/desk/mcp/src/runtime/workspace-tidy.js +509 -0
- package/vendor/desk/mcp/src/search/direct-lexical.js +54 -0
- package/vendor/desk/mcp/src/search/embedder.js +108 -0
- package/vendor/desk/mcp/src/search/engine.js +406 -0
- package/vendor/desk/mcp/src/search/files-router.js +22 -0
- package/vendor/desk/mcp/src/search/old-index.js +46 -0
- package/vendor/desk/mcp/src/search/vectors.js +60 -0
- package/vendor/desk/mcp/src/server.js +389 -0
- package/vendor/desk/mcp/src/tool-names.js +73 -0
- package/vendor/desk/mcp/src/tool-refusal.cjs +35 -0
- package/vendor/desk/mcp/src/tool-schema-parts.js +12 -0
- package/vendor/desk/mcp/src/tool-schemas.js +325 -0
- package/vendor/desk/mcp/src/tools/_card-commit.js +148 -0
- package/vendor/desk/mcp/src/tools/archive-links.js +185 -0
- package/vendor/desk/mcp/src/tools/archive-move.js +18 -0
- package/vendor/desk/mcp/src/tools/archive-native-session.js +728 -0
- package/vendor/desk/mcp/src/tools/archive-state.js +513 -0
- package/vendor/desk/mcp/src/tools/delivery-gate.js +251 -0
- package/vendor/desk/mcp/src/tools/desk-save.js +444 -0
- package/vendor/desk/mcp/src/tools/doctor.js +122 -0
- package/vendor/desk/mcp/src/tools/done-evidence.js +260 -0
- package/vendor/desk/mcp/src/tools/factory-context.js +204 -0
- package/vendor/desk/mcp/src/tools/friction.js +332 -0
- package/vendor/desk/mcp/src/tools/improvement.js +156 -0
- package/vendor/desk/mcp/src/tools/lesson-lines.js +22 -0
- package/vendor/desk/mcp/src/tools/lesson-owners.js +137 -0
- package/vendor/desk/mcp/src/tools/lesson-team.js +169 -0
- package/vendor/desk/mcp/src/tools/lesson.js +254 -0
- package/vendor/desk/mcp/src/tools/local-only.js +151 -0
- package/vendor/desk/mcp/src/tools/move.js +794 -0
- package/vendor/desk/mcp/src/tools/native-stage-context.js +32 -0
- package/vendor/desk/mcp/src/tools/note.js +267 -0
- package/vendor/desk/mcp/src/tools/search.js +634 -0
- package/vendor/desk/mcp/src/tools/shared-write.js +196 -0
- package/vendor/desk/mcp/src/tools/sibling-desk.js +37 -0
- package/vendor/desk/mcp/src/tools/status.js +233 -0
- package/vendor/desk/mcp/src/tools/task-archive-due.js +9 -0
- package/vendor/desk/mcp/src/tools/task-archived-resource.js +53 -0
- package/vendor/desk/mcp/src/tools/task-body.js +141 -0
- package/vendor/desk/mcp/src/tools/task-focus.js +164 -0
- package/vendor/desk/mcp/src/tools/task-log.js +76 -0
- package/vendor/desk/mcp/src/tools/task-signoff.js +155 -0
- package/vendor/desk/mcp/src/tools/task.js +1768 -0
- package/vendor/desk/mcp/src/tools/track-row.js +89 -0
- package/vendor/desk/mcp/src/tools/track.js +240 -0
- package/vendor/desk/mcp/src/util/agency-session.cjs +29 -0
- package/vendor/desk/mcp/src/util/archive-links.js +105 -0
- package/vendor/desk/mcp/src/util/bash.js +36 -0
- package/vendor/desk/mcp/src/util/capture-record.js +73 -0
- package/vendor/desk/mcp/src/util/cas-commit.js +252 -0
- package/vendor/desk/mcp/src/util/created-dirs.js +71 -0
- package/vendor/desk/mcp/src/util/deferred-tools.js +51 -0
- package/vendor/desk/mcp/src/util/desk-owner.js +99 -0
- package/vendor/desk/mcp/src/util/env-value.js +13 -0
- package/vendor/desk/mcp/src/util/file-identity.js +40 -0
- package/vendor/desk/mcp/src/util/finish-commit.js +145 -0
- package/vendor/desk/mcp/src/util/fm.js +410 -0
- package/vendor/desk/mcp/src/util/git-config-file.js +85 -0
- package/vendor/desk/mcp/src/util/git-stage.js +440 -0
- package/vendor/desk/mcp/src/util/main-publish.js +240 -0
- package/vendor/desk/mcp/src/util/markdown-links.cjs +555 -0
- package/vendor/desk/mcp/src/util/object-input.js +59 -0
- package/vendor/desk/mcp/src/util/paths.js +647 -0
- package/vendor/desk/mcp/src/util/rank.js +189 -0
- package/vendor/desk/mcp/src/util/redact.js +92 -0
- package/vendor/desk/mcp/src/util/remove-retry.js +35 -0
- package/vendor/desk/mcp/src/util/rename-retry.js +73 -0
- package/vendor/desk/mcp/src/util/route-around.js +265 -0
- package/vendor/desk/mcp/src/util/shell-quote.js +18 -0
- package/vendor/desk/mcp/src/util/startup-direction.js +124 -0
- package/vendor/desk/mcp/src/util/state-ignore.js +33 -0
- package/vendor/desk/mcp/src/util/tool-commits.js +64 -0
- package/vendor/desk/mcp/src/util/unicode-16/LICENSE-MIT.txt +7 -0
- package/vendor/desk/mcp/src/util/unicode-16/README.md +9 -0
- package/vendor/desk/mcp/src/util/unicode-16/letter.cjs +1 -0
- package/vendor/desk/mcp/src/util/unicode-16/mark.cjs +1 -0
- package/vendor/desk/mcp/src/util/unicode-16/number.cjs +1 -0
- package/vendor/desk/mcp/web-auth.cjs +1897 -0
- package/vendor/desk/mcp/web-browser-discovery.cjs +53 -0
- package/vendor/desk/mcp/web-catalog.json +34 -0
- package/vendor/desk/mcp/web-launch.cjs +101 -0
- package/vendor/desk/mcp/web.cjs +1239 -0
- package/vendor/desk/migrations/01-move-to-ourostack-desk.md +188 -0
- package/vendor/desk/migrations/02-tidy-desk.md +87 -0
- package/vendor/desk/migrations/03-desk-release-channel.md +38 -0
- package/vendor/desk/optional/session-label/consumer.mjs +237 -0
- package/vendor/desk/optional/session-label/extension.mjs +32 -0
- package/vendor/desk/plugin.json +54 -0
- package/vendor/desk/settings.json +3 -0
- package/vendor/desk/skills/add-workspace-mcp/SKILL.md +180 -0
- package/vendor/desk/skills/adopt-inflight-work/SKILL.md +212 -0
- package/vendor/desk/skills/archive-workflow/SKILL.md +132 -0
- package/vendor/desk/skills/content-routing/SKILL.md +95 -0
- package/vendor/desk/skills/core-meeting-capture/SKILL.md +47 -0
- package/vendor/desk/skills/core-meeting-capture/references/capture-contract.md +175 -0
- package/vendor/desk/skills/curator/SKILL.md +103 -0
- package/vendor/desk/skills/delightful-decks/SKILL.md +67 -0
- package/vendor/desk/skills/desk-problem/SKILL.md +87 -0
- package/vendor/desk/skills/directory-structure/SKILL.md +169 -0
- package/vendor/desk/skills/doc-review-rigor/SKILL.md +63 -0
- package/vendor/desk/skills/draining-issues/SKILL.md +62 -0
- package/vendor/desk/skills/evaluate-release/SKILL.md +96 -0
- package/vendor/desk/skills/evidence-discipline/SKILL.md +150 -0
- package/vendor/desk/skills/factory-evaluator/SKILL.md +122 -0
- package/vendor/desk/skills/factory-task-context/SKILL.md +116 -0
- package/vendor/desk/skills/factory-work/SKILL.md +16 -0
- package/vendor/desk/skills/fast-honest-ci/SKILL.md +70 -0
- package/vendor/desk/skills/fast-honest-ci/examples.md +49 -0
- package/vendor/desk/skills/first-run-bootstrap/SKILL.md +95 -0
- package/vendor/desk/skills/friction-management/SKILL.md +98 -0
- package/vendor/desk/skills/git-hygiene/SKILL.md +253 -0
- package/vendor/desk/skills/independent-review/SKILL.md +34 -0
- package/vendor/desk/skills/interaction-style/SKILL.md +239 -0
- package/vendor/desk/skills/lesson-capture/SKILL.md +85 -0
- package/vendor/desk/skills/lesson-capture/agents-md-budget.mjs +61 -0
- package/vendor/desk/skills/online-evaluation/SKILL.md +81 -0
- package/vendor/desk/skills/operator-voice-comments/LICENSE-humanize +21 -0
- package/vendor/desk/skills/operator-voice-comments/SKILL.md +90 -0
- package/vendor/desk/skills/operator-voice-comments/human-voice.md +43 -0
- package/vendor/desk/skills/peer-pr-review/SKILL.md +104 -0
- package/vendor/desk/skills/pr-feedback-on-own-pr/SKILL.md +145 -0
- package/vendor/desk/skills/pr-review-interrogation/SKILL.md +121 -0
- package/vendor/desk/skills/pr-reviewer-audit/SKILL.md +68 -0
- package/vendor/desk/skills/pr-reviewer-audit/helpers/audit.py +335 -0
- package/vendor/desk/skills/pr-reviewer-audit/helpers/test_audit.py +486 -0
- package/vendor/desk/skills/pr-self-review/SKILL.md +86 -0
- package/vendor/desk/skills/pr-surface-hygiene/SKILL.md +105 -0
- package/vendor/desk/skills/pr-surface-hygiene/check-visual-proof.cjs +99 -0
- package/vendor/desk/skills/pr-surface-hygiene/repository-setup.md +19 -0
- package/vendor/desk/skills/pr-surface-hygiene/resources/pr-visual-proof.yml +29 -0
- package/vendor/desk/skills/pr-surface-hygiene/resources/pull-request-template.md +5 -0
- package/vendor/desk/skills/preflight-actions/SKILL.md +60 -0
- package/vendor/desk/skills/preview-feedback/SKILL.md +70 -0
- package/vendor/desk/skills/repo-handling/SKILL.md +67 -0
- package/vendor/desk/skills/rnd-lab/SKILL.md +52 -0
- package/vendor/desk/skills/runtime-symptom-investigation/SKILL.md +106 -0
- package/vendor/desk/skills/session-resumption/SKILL.md +126 -0
- package/vendor/desk/skills/session-start/SKILL.md +54 -0
- package/vendor/desk/skills/session-start/details.md +150 -0
- package/vendor/desk/skills/session-start-migrations/README.md +71 -0
- package/vendor/desk/skills/session-start-migrations/SKILL.md +108 -0
- package/vendor/desk/skills/start-task/SKILL.md +88 -0
- package/vendor/desk/skills/task-card-format/SKILL.md +198 -0
- package/vendor/desk/skills/task-lifecycle/SKILL.md +217 -0
- package/vendor/desk/skills/track-card-format/SKILL.md +90 -0
- package/vendor/desk/skills/using-desk/SKILL.md +58 -0
- package/vendor/desk/skills/using-superpowers-with-desk/SKILL.md +156 -0
- package/vendor/desk/skills/work-orchestration/SKILL.md +162 -0
|
@@ -0,0 +1,813 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// desk MCP server entry point.
|
|
3
|
+
//
|
|
4
|
+
// Spawned by consumers as a stdio MCP server. Hosts may pass `--root <path>`
|
|
5
|
+
// directly, or pass/auto-discover an activation config that carries the root,
|
|
6
|
+
// runtime cache, and active worker/overlay identity. Consumers wire this up via
|
|
7
|
+
// the sibling `.mcp.claude-codex.json` declaration.
|
|
8
|
+
//
|
|
9
|
+
// node ./mcp/index.js --root ~/AgentBundles/slugger.ouro/desk
|
|
10
|
+
//
|
|
11
|
+
// The same binary serves every consumer (Claude Code worker, Copilot CLI,
|
|
12
|
+
// ouroboros daemon per agent). Each consumer supplies or discovers its
|
|
13
|
+
// own root/activation context without needing a bespoke Desk CLI.
|
|
14
|
+
|
|
15
|
+
// Every module imported below must stay loadable on Node releases older than the engines floor (the Node 16 matrix test in __tests__/runtime/never_exit_before_handshake.test.js proves it), because ES module imports load before any code here runs. The version check itself is the first thing main() does.
|
|
16
|
+
import { spawn } from "node:child_process"
|
|
17
|
+
import { readFileSync, realpathSync } from "node:fs"
|
|
18
|
+
import { fileURLToPath, pathToFileURL } from "node:url"
|
|
19
|
+
import * as path from "node:path"
|
|
20
|
+
import {
|
|
21
|
+
resolveStartupActivationConfigPath,
|
|
22
|
+
resolveStartupActivationContext,
|
|
23
|
+
resolveStartupDeskRoot,
|
|
24
|
+
resolveStartupReadinessPolicy,
|
|
25
|
+
resolveStartupRuntimeCacheDir,
|
|
26
|
+
resolveStartupSourceIdentity,
|
|
27
|
+
resolveStartupStateBranch,
|
|
28
|
+
} from "./src/runtime/startup-resolve.js"
|
|
29
|
+
import {
|
|
30
|
+
importRuntimeServer,
|
|
31
|
+
inspectRuntimeDependencyPack,
|
|
32
|
+
} from "./src/runtime/bootstrap.js"
|
|
33
|
+
import { startDiagnosticServer } from "./src/runtime/diagnostic-server.js"
|
|
34
|
+
import { deskVersion } from "./src/package-metadata.js"
|
|
35
|
+
import { createResolveRunner, runInWorker } from "./src/runtime/admission-worker.js"
|
|
36
|
+
import { importInChunks } from "./src/runtime/chunked-import.js"
|
|
37
|
+
import { watchCopilotSessionRecord } from "./src/runtime/copilot-session.js"
|
|
38
|
+
import { createDeskSession, LAUNCHER_READ_ONLY_CODES } from "./src/runtime/desk-session.js"
|
|
39
|
+
import { startFrontDoor } from "./src/runtime/front-door.js"
|
|
40
|
+
import { withStartupBoot } from "./src/runtime/startup-boot.js"
|
|
41
|
+
import { hostedInstructions, isHosted, withHostedStartup } from "./src/runtime/hosted.js"
|
|
42
|
+
import { resolveDeskStateDir, resolveReadinessStateHome } from "./src/runtime/last-start.js"
|
|
43
|
+
import {
|
|
44
|
+
createRuntimeDiagnostic,
|
|
45
|
+
createSetupDiagnostic,
|
|
46
|
+
createStartupExceptionDiagnostic,
|
|
47
|
+
} from "./src/runtime/diagnostics.js"
|
|
48
|
+
import {
|
|
49
|
+
discoverNodeCandidates,
|
|
50
|
+
REEXEC_ATTEMPT_ENV,
|
|
51
|
+
reexecWithCompatibleNode,
|
|
52
|
+
selectCompatibleNode,
|
|
53
|
+
} from "./src/runtime/node-selection.js"
|
|
54
|
+
import { claudeBindingPath } from "./src/util/paths.js"
|
|
55
|
+
import { applyPublicationMode, publicationArgs } from "./src/runtime/publication-mode.js"
|
|
56
|
+
import { createRuntimeRefresher } from "./src/runtime/runtime-swap.js"
|
|
57
|
+
|
|
58
|
+
export {
|
|
59
|
+
resolveStartupActivationConfigPath,
|
|
60
|
+
resolveStartupActivationContext,
|
|
61
|
+
resolveStartupDeskRoot,
|
|
62
|
+
resolveStartupReadinessPolicy,
|
|
63
|
+
resolveStartupRuntimeCacheDir,
|
|
64
|
+
resolveStartupSourceIdentity,
|
|
65
|
+
resolveStartupStateBranch,
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Used only when package.json's engines.node cannot be read as a plain ">=" floor.
|
|
69
|
+
const DEFAULT_NODE_FLOOR = [22, 18, 0]
|
|
70
|
+
const SHUTDOWN_TIMEOUT_MS = 3000
|
|
71
|
+
|
|
72
|
+
// The lowest Node that Desk supports, from engines.node in package.json (">=X[.Y[.Z]]").
|
|
73
|
+
export function resolveNodeFloor({ mcpRoot, readFile = readFileSync } = {}) {
|
|
74
|
+
try {
|
|
75
|
+
const range = JSON.parse(readFile(path.join(mcpRoot, "package.json"), "utf8")).engines.node
|
|
76
|
+
const match = /^>=\s*v?(\d+)(?:\.(\d+))?(?:\.(\d+))?$/u.exec(range.trim())
|
|
77
|
+
if (match !== null) {
|
|
78
|
+
return [Number(match[1]), Number(match[2] ?? 0), Number(match[3] ?? 0)]
|
|
79
|
+
}
|
|
80
|
+
} catch {
|
|
81
|
+
// Fall through to the default floor.
|
|
82
|
+
}
|
|
83
|
+
return DEFAULT_NODE_FLOOR
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Compare a Node version ("16.20.2") with a floor using only syntax and APIs every Node release has, because this check runs before Desk trusts the Node it was started on.
|
|
87
|
+
export function nodeMeetsFloor(version, floor) {
|
|
88
|
+
const parts = String(version).split(".")
|
|
89
|
+
for (let index = 0; index < 3; index += 1) {
|
|
90
|
+
const part = parseInt(parts[index], 10)
|
|
91
|
+
if (isNaN(part)) return false
|
|
92
|
+
if (part !== floor[index]) return part > floor[index]
|
|
93
|
+
}
|
|
94
|
+
return true
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function parseArgs(argv) {
|
|
98
|
+
const args = { root: null, person: null }
|
|
99
|
+
for (let i = 0; i < argv.length; i++) {
|
|
100
|
+
if (argv[i] === "--root" && argv[i + 1]) {
|
|
101
|
+
args.root = argv[++i]
|
|
102
|
+
} else if (argv[i] === "--host-session-root" && argv[i + 1]) {
|
|
103
|
+
args.hostSessionRoot = argv[++i]
|
|
104
|
+
} else if (argv[i] === "--onboarding" && argv[i + 1]) {
|
|
105
|
+
args.onboarding = argv[++i]
|
|
106
|
+
} else if (argv[i] === "--onboarding-reason" && argv[i + 1]) {
|
|
107
|
+
args.onboardingReason = argv[++i]
|
|
108
|
+
} else if (argv[i] === "--person" && argv[i + 1]) {
|
|
109
|
+
args.person = argv[++i]
|
|
110
|
+
} else if (argv[i] === "--activation-config" && argv[i + 1]) {
|
|
111
|
+
args.activationConfig = argv[++i]
|
|
112
|
+
} else if (argv[i] === "--state-branch" && argv[i + 1]) {
|
|
113
|
+
args.stateBranch = argv[++i]
|
|
114
|
+
} else if (argv[i] === "--degraded" && argv[i + 1]) {
|
|
115
|
+
args.degraded = argv[++i]
|
|
116
|
+
} else if (argv[i] === "--degraded-reason" && argv[i + 1]) {
|
|
117
|
+
args.degradedReason = argv[++i]
|
|
118
|
+
} else if (argv[i] === "--publication" && argv[i + 1]) {
|
|
119
|
+
args.publication = argv[++i]
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return args
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function resolveRuntimeInspector({ runtimeImporter, runtimeInspector }) {
|
|
126
|
+
if (runtimeInspector !== undefined) {
|
|
127
|
+
return runtimeInspector
|
|
128
|
+
}
|
|
129
|
+
return runtimeImporter === importRuntimeServer
|
|
130
|
+
? inspectRuntimeDependencyPack
|
|
131
|
+
: null
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export function resolveMcpServerVersion({ env = process.env } = {}) {
|
|
135
|
+
return deskVersion(env) ?? "0.0.0"
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Desk answers the MCP handshake before it does anything that can fail or take time.
|
|
139
|
+
//
|
|
140
|
+
// main always receives options (the entrypoint passes onClosed), so there is no default for a missing argument, which would bind to the real stdio and home.
|
|
141
|
+
//
|
|
142
|
+
// Before the handshake, main does only what must happen in this process before stdio is answered: check the Node version, and move to a compatible Node (re-exec) when no shipped runtime pack fits this one. Everything else (root resolution, activation, the runtime-pack restore, authority, the state branch and the search engine) runs after the handshake as background admission (src/runtime/desk-session.js), which degrades instead of failing and upgrades itself to ready in the same session.
|
|
143
|
+
export async function main({
|
|
144
|
+
argv = process.argv.slice(2),
|
|
145
|
+
env = process.env,
|
|
146
|
+
cwd = process.cwd(),
|
|
147
|
+
homeDir,
|
|
148
|
+
mcpRoot = path.dirname(fileURLToPath(import.meta.url)),
|
|
149
|
+
runtimeImporter = importRuntimeServer,
|
|
150
|
+
runtimeInspector,
|
|
151
|
+
diagnosticServerStarter = startDiagnosticServer,
|
|
152
|
+
nodeCandidateDiscoverer = discoverNodeCandidates,
|
|
153
|
+
nodeSelector = selectCompatibleNode,
|
|
154
|
+
nodeReexecutor = reexecWithCompatibleNode,
|
|
155
|
+
readinessPolicy: injectedReadinessPolicy,
|
|
156
|
+
authorityProviders = {},
|
|
157
|
+
nodeVersion = process.versions.node,
|
|
158
|
+
input = process.stdin,
|
|
159
|
+
output = process.stdout,
|
|
160
|
+
stderr = process.stderr,
|
|
161
|
+
stateHome,
|
|
162
|
+
admissionKickoffMs = 1000,
|
|
163
|
+
git,
|
|
164
|
+
watch,
|
|
165
|
+
timers,
|
|
166
|
+
offload = runInWorker,
|
|
167
|
+
newestRelease,
|
|
168
|
+
runtimeRefresher: injectedRefresher,
|
|
169
|
+
crashHandlers = false,
|
|
170
|
+
crashTarget = process,
|
|
171
|
+
parentWatcher = watchParent,
|
|
172
|
+
spawnDetached = spawn,
|
|
173
|
+
onClosed = () => {},
|
|
174
|
+
}) {
|
|
175
|
+
// The tools find the installed plugin (its hooks and the plugins beside it) through DESK_PLUGIN_ROOT. Claude's launcher sets it; Copilot's config passes no environment, and the server's code runs from a source mirror with no `hooks/` beside it, so every host gets this entrypoint's own plugin folder here.
|
|
176
|
+
if (!hasText(env.DESK_PLUGIN_ROOT)) env.DESK_PLUGIN_ROOT = path.resolve(mcpRoot, "..")
|
|
177
|
+
runtimeInspector = resolveRuntimeInspector({ runtimeImporter, runtimeInspector })
|
|
178
|
+
const serverVersion = resolveMcpServerVersion({ env })
|
|
179
|
+
const startRuntimeDiagnostic = (options) => diagnosticServerStarter({
|
|
180
|
+
...options,
|
|
181
|
+
serverVersion,
|
|
182
|
+
})
|
|
183
|
+
// The Node check comes first, before any root, activation or runtime work: on a Node older than the engines floor, Desk goes straight to finding a compatible Node (or to diagnostic mode) and never runs code that may need newer APIs.
|
|
184
|
+
if (!nodeMeetsFloor(nodeVersion, resolveNodeFloor({ mcpRoot }))) {
|
|
185
|
+
return handleUnavailableRuntime({
|
|
186
|
+
argv,
|
|
187
|
+
diagnosticServerStarter: startRuntimeDiagnostic,
|
|
188
|
+
env,
|
|
189
|
+
homeDir,
|
|
190
|
+
inspection: outdatedNodeInspection({ mcpRoot, runtimeInspector }),
|
|
191
|
+
mcpRoot,
|
|
192
|
+
nodeCandidateDiscoverer,
|
|
193
|
+
nodeReexecutor,
|
|
194
|
+
nodeSelector,
|
|
195
|
+
runtimeCacheDir: null,
|
|
196
|
+
})
|
|
197
|
+
}
|
|
198
|
+
const args = parseArgs(argv)
|
|
199
|
+
applyPublicationMode(args, env)
|
|
200
|
+
// An overlay that owns root resolution (for example a crew launcher that
|
|
201
|
+
// maps identity to a shared workspace) passes --onboarding when it could not
|
|
202
|
+
// resolve a root. Desk then goes straight to setup mode on that path rather
|
|
203
|
+
// than guessing a home fallback that belongs to a different desk.
|
|
204
|
+
if (hasText(args.onboarding) && !hasText(args.degraded) && !hasText(args.root) && !hasText(args.hostSessionRoot)) {
|
|
205
|
+
return startRuntimeDiagnostic({
|
|
206
|
+
diagnostic: createSetupDiagnostic({
|
|
207
|
+
onboardingSkill: args.onboarding,
|
|
208
|
+
reasonDetail: args.onboardingReason,
|
|
209
|
+
bindingPath: claudeBindingPath(env),
|
|
210
|
+
}),
|
|
211
|
+
})
|
|
212
|
+
}
|
|
213
|
+
// Only a Node that no shipped runtime pack supports is handled before the handshake: the fix (running under a compatible Node) needs stdio this process has not answered yet. The pack's checksum and archive are verified later, during admission.
|
|
214
|
+
const preflight = preflightInspection({ mcpRoot, runtimeInspector })
|
|
215
|
+
if (preflight !== null && !preflight.ok && (preflight.reason === "unsupported_target" || hasText(env[REEXEC_ATTEMPT_ENV]))) {
|
|
216
|
+
return handleUnavailableRuntime({
|
|
217
|
+
argv,
|
|
218
|
+
diagnosticServerStarter: startRuntimeDiagnostic,
|
|
219
|
+
env,
|
|
220
|
+
homeDir,
|
|
221
|
+
inspection: preflight,
|
|
222
|
+
mcpRoot,
|
|
223
|
+
nodeCandidateDiscoverer,
|
|
224
|
+
nodeReexecutor,
|
|
225
|
+
nodeSelector,
|
|
226
|
+
runtimeCacheDir: optional(() => resolveStartupRuntimeCacheDir({ args, cwd, env, homeDir })),
|
|
227
|
+
})
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const launcher = launcherMode(args)
|
|
231
|
+
const plainEnv = { ...env }
|
|
232
|
+
// The shipped worker keeps one resolve worker up between jobs; an injected offload (tests) runs every job itself.
|
|
233
|
+
const resolveRunner = offload === runInWorker ? createResolveRunner() : { run: offload, close() {} }
|
|
234
|
+
let frontDoor = null
|
|
235
|
+
let handshakeMs = null
|
|
236
|
+
// What a later check needs to load a newer runtime the way the first load did; set by the first load.
|
|
237
|
+
const refreshLoad = { options: null, pinned: false }
|
|
238
|
+
const log = (line) => stderr.write(`[desk-mcp] ${line}\n`)
|
|
239
|
+
// A long-running server (a host keeps one per project folder for days) loads the newest release again in the background and swaps it in between calls: see runtime-swap.js. Only the shipped importer takes part, and a pinned source is never swapped.
|
|
240
|
+
const runtimeRefresher = injectedRefresher !== undefined ? injectedRefresher
|
|
241
|
+
: runtimeImporter === importRuntimeServer || newestRelease !== undefined
|
|
242
|
+
? createRuntimeRefresher({ env: plainEnv, log, prepare: ({ running }) => prepareNewerRuntime({ running, refreshLoad, mcpRoot, homeDir, env: plainEnv, newestRelease }) })
|
|
243
|
+
: null
|
|
244
|
+
const session = createDeskSession({
|
|
245
|
+
runtimeRefresher,
|
|
246
|
+
handshakeMs: () => handshakeMs,
|
|
247
|
+
args,
|
|
248
|
+
env,
|
|
249
|
+
authorityProviders,
|
|
250
|
+
deskStateDir: stateHome ?? resolveDeskStateDir({ env, homeDir }),
|
|
251
|
+
readinessStateHome: stateHome === undefined ? resolveReadinessStateHome({ env, homeDir }) : path.join(stateHome, "readiness"),
|
|
252
|
+
git,
|
|
253
|
+
watch,
|
|
254
|
+
timers,
|
|
255
|
+
stderr,
|
|
256
|
+
notifyToolsChanged: () => frontDoor?.notifyToolsChanged(),
|
|
257
|
+
launcher,
|
|
258
|
+
// Root and activation resolution read files: they run on the admission worker, never on the thread that answers the host.
|
|
259
|
+
resolveInputs: () => resolveRunner.run({
|
|
260
|
+
kind: "resolve",
|
|
261
|
+
input: { args, env: plainEnv, cwd, homeDir, injectedReadinessPolicy },
|
|
262
|
+
}),
|
|
263
|
+
setupDiagnostic: (error) => createSetupDiagnostic({ pathsTried: error.tried, bindingPath: claudeBindingPath(env) }),
|
|
264
|
+
loadRuntime: (activation, { onPhase }) => {
|
|
265
|
+
const options = { onPhase, activation, env: plainEnv, homeDir, mcpRoot, offload, preflight, runtimeImporter, runtimeInspector, newestRelease }
|
|
266
|
+
refreshLoad.options = options
|
|
267
|
+
refreshLoad.pinned = activation.sourceIdentity != null || activation.runtimeCacheDir != null
|
|
268
|
+
return loadNewestOrCached(options)
|
|
269
|
+
},
|
|
270
|
+
})
|
|
271
|
+
let kicked = false
|
|
272
|
+
let stopRecordWatch = () => {}
|
|
273
|
+
const kick = () => {
|
|
274
|
+
if (kicked) return
|
|
275
|
+
kicked = true
|
|
276
|
+
session.start()
|
|
277
|
+
// Copilot writes the session record only after starting this server: re-admit as soon as it appears, once the attempt that is running has finished.
|
|
278
|
+
stopRecordWatch = watchCopilotSessionRecord({
|
|
279
|
+
env,
|
|
280
|
+
stateDir: stateHome ?? resolveDeskStateDir({ env, homeDir }),
|
|
281
|
+
onRecord: () => {
|
|
282
|
+
// Neither call rejects: admission turns every failure into a state.
|
|
283
|
+
void session.admission.idle({ waitMs: 60000 }).then(() => session.admission.refresh({ waitMs: 0 }))
|
|
284
|
+
},
|
|
285
|
+
})
|
|
286
|
+
}
|
|
287
|
+
// A hosted Desk (DESK_HOSTED) has no session-start hook: its initialize answer carries the startup instructions, and once the first tools/list is answered it pulls the desk the way session start does.
|
|
288
|
+
const hosted = isHosted(env)
|
|
289
|
+
const hostedRoot = hosted && hasText(args.root) ? path.resolve(cwd, args.root) : null
|
|
290
|
+
// Desk's own session-sync CLI, as a detached child: its git calls block, and they must never block the thread that answers the host.
|
|
291
|
+
const startHostedSync = () => {
|
|
292
|
+
if (hostedRoot === null) return
|
|
293
|
+
const failed = (error) => stderr.write(`[desk-mcp] hosted desk sync failed to start: ${describeError(error)}\n`)
|
|
294
|
+
try {
|
|
295
|
+
const child = spawnDetached(process.execPath, [path.join(mcpRoot, "scripts", "session-sync.js"), "--root", hostedRoot, ...publicationArgs(env)], {
|
|
296
|
+
cwd: hostedRoot,
|
|
297
|
+
detached: true,
|
|
298
|
+
stdio: "ignore",
|
|
299
|
+
windowsHide: true,
|
|
300
|
+
env: plainEnv,
|
|
301
|
+
})
|
|
302
|
+
child.on("error", failed)
|
|
303
|
+
child.unref()
|
|
304
|
+
} catch (error) {
|
|
305
|
+
failed(error)
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
const hostedInstructionsText = hosted ? hostedInstructions({ root: hostedRoot, pluginRoot: env.DESK_PLUGIN_ROOT }) : undefined
|
|
309
|
+
frontDoor = startFrontDoor({
|
|
310
|
+
input,
|
|
311
|
+
output,
|
|
312
|
+
serverVersion,
|
|
313
|
+
instructions: hostedInstructionsText,
|
|
314
|
+
serverIcons: hosted && hasText(env.DESK_MCP_ICON_URL) ? [{ src: env.DESK_MCP_ICON_URL }] : undefined,
|
|
315
|
+
callTool: hosted ? withHostedStartup({ callTool: session.callTool, instructions: hostedInstructionsText }) : withStartupBoot({ callTool: (call) => session.callTool(call), env, stateDir: stateHome ?? resolveDeskStateDir({ env, homeDir }), servingRoot: session.servingPluginRoot }),
|
|
316
|
+
onHandshake: () => {
|
|
317
|
+
handshakeMs = Math.round(performance.now())
|
|
318
|
+
kick()
|
|
319
|
+
startHostedSync()
|
|
320
|
+
},
|
|
321
|
+
})
|
|
322
|
+
// A client that never sends tools/list still gets admission.
|
|
323
|
+
const kickoff = setTimeout(kick, admissionKickoffMs)
|
|
324
|
+
kickoff.unref?.()
|
|
325
|
+
// Once the server is up, nothing that throws later may end the process: the session records it, degrades and keeps serving.
|
|
326
|
+
const removeCrashHandlers = crashHandlers ? installCrashHandlers({ session, stderr, target: crashTarget, onPeerGone: () => onClosed(0) }) : () => {}
|
|
327
|
+
// A host that is gone leaves nothing to serve: a failed write to it, or a parent that has ended, closes the session instead of keeping it alive with no client.
|
|
328
|
+
const peerGone = (why) => {
|
|
329
|
+
stderr.write(`[desk-mcp] ${why}; closing the session\n`)
|
|
330
|
+
onClosed(0)
|
|
331
|
+
}
|
|
332
|
+
if (crashHandlers) {
|
|
333
|
+
output.on?.("error", (error) => peerGone(`the host's output is gone (${describeError(error)})`))
|
|
334
|
+
parentWatcher({ onGone: () => peerGone("the parent process has ended") })
|
|
335
|
+
}
|
|
336
|
+
// The host's input failing ends the session the same way its ending does: nothing can arrive on it again.
|
|
337
|
+
const closed = frontDoor.closed.catch((error) => stderr.write(`[desk-mcp] the host's input failed (${describeError(error)}); closing the session\n`)).then(async () => {
|
|
338
|
+
clearTimeout(kickoff)
|
|
339
|
+
stopRecordWatch()
|
|
340
|
+
let deadline
|
|
341
|
+
let timedOut = false
|
|
342
|
+
try {
|
|
343
|
+
await Promise.race([
|
|
344
|
+
session.dispose(),
|
|
345
|
+
new Promise((resolve) => {
|
|
346
|
+
deadline = setTimeout(() => { timedOut = true; resolve() }, SHUTDOWN_TIMEOUT_MS)
|
|
347
|
+
}),
|
|
348
|
+
])
|
|
349
|
+
} finally {
|
|
350
|
+
clearTimeout(deadline)
|
|
351
|
+
removeCrashHandlers()
|
|
352
|
+
resolveRunner.close()
|
|
353
|
+
}
|
|
354
|
+
if (timedOut) {
|
|
355
|
+
stderr.write(`[desk-mcp] shutdown timed out after ${SHUTDOWN_TIMEOUT_MS} ms; the session did not finish closing; exiting with failure\n`)
|
|
356
|
+
}
|
|
357
|
+
onClosed(timedOut ? 1 : 0)
|
|
358
|
+
})
|
|
359
|
+
return { frontDoor, session, admission: session.admission, closed }
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// A cheap look at the runtime target before the handshake: the support matrix and the pack files, without hashing or unpacking the archive. Null when inspection itself fails (admission reports that later).
|
|
363
|
+
function preflightInspection({ mcpRoot, runtimeInspector }) {
|
|
364
|
+
if (runtimeInspector === null) return null
|
|
365
|
+
try {
|
|
366
|
+
return runtimeInspector === inspectRuntimeDependencyPack
|
|
367
|
+
? inspectRuntimeDependencyPack({ mcpRoot, verifyPack: deferPackVerification })
|
|
368
|
+
: runtimeInspector({ mcpRoot })
|
|
369
|
+
} catch {
|
|
370
|
+
return null
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
function deferPackVerification() {
|
|
375
|
+
return { ok: true, deferred: true, manifest: null, archiveEntries: [] }
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// Desk's tools run the newest release when the release channel is ahead of the copy that launched this server (src/runtime/newest-release.js): the server loads a copy of the newer `mcp` folder and falls back to this one, and says so, when that cannot finish in its budget or the copy will not load. Only the shipped importer takes part, and a pinned source or runtime cache (an activation config) is never swapped.
|
|
379
|
+
async function loadNewestOrCached(options) {
|
|
380
|
+
const { activation, env, homeDir, mcpRoot, runtimeImporter, newestRelease } = options
|
|
381
|
+
const cached = () => loadRuntime(options)
|
|
382
|
+
if ((runtimeImporter !== importRuntimeServer && newestRelease === undefined) || activation.sourceIdentity != null || activation.runtimeCacheDir != null) return cached()
|
|
383
|
+
const ensure = newestRelease ?? (await import("./src/runtime/newest-release.js")).ensureNewestRelease
|
|
384
|
+
const pluginRoot = path.resolve(mcpRoot, "..")
|
|
385
|
+
const release = await ensure({ env, pluginRoot, running: deskVersion({ DESK_PLUGIN_ROOT: pluginRoot }), homeDir })
|
|
386
|
+
const withRelease = (loaded, { state, running, latest, reason }) => ({ ...loaded, runtimeStatus: { ...loaded.runtimeStatus, newest_release: { state, plugin_copy: running, newest: latest, reason } } })
|
|
387
|
+
if (release.state !== "loaded") return withRelease(await cached(), release)
|
|
388
|
+
options.onPhase("loading_newest_release")
|
|
389
|
+
const newer = await loadRuntime({ ...options, mcpRoot: release.mcpRoot })
|
|
390
|
+
if (newer.runtimeServer !== undefined) return withRelease(newer, release)
|
|
391
|
+
return withRelease(await cached(), { ...release, state: "fell_back", reason: `the ${release.latest} copy did not load` })
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
// A newer runtime, loaded beside the serving one for runtime-swap.js: the newest release's copy, restored and imported as the first load does. `running` is the version serving now. Every outcome other than a loaded runtime leaves the serving one in place and says why.
|
|
395
|
+
async function prepareNewerRuntime({ running, refreshLoad, mcpRoot, homeDir, env, newestRelease }) {
|
|
396
|
+
// The session checks only once a runtime is serving, so the first load has set these.
|
|
397
|
+
const options = refreshLoad.options
|
|
398
|
+
if (refreshLoad.pinned) return { state: "not_applicable", reason: "this session pins its runtime source" }
|
|
399
|
+
const ensure = newestRelease ?? (await import("./src/runtime/newest-release.js")).ensureNewestRelease
|
|
400
|
+
const pluginRoot = path.resolve(mcpRoot, "..")
|
|
401
|
+
const release = await ensure({ env, pluginRoot, running, homeDir })
|
|
402
|
+
if (release.state === "not_applicable") return { state: "not_applicable", reason: release.reason }
|
|
403
|
+
if (release.state === "current") return { state: "current", latest: release.latest }
|
|
404
|
+
if (release.state === "fell_back") return { state: "failed", latest: release.latest, reason: release.reason }
|
|
405
|
+
const newer = await loadRuntime({ ...options, onPhase: () => {}, mcpRoot: release.mcpRoot })
|
|
406
|
+
if (newer.runtimeServer === undefined) return { state: "failed", latest: release.latest, reason: `the ${release.latest} copy did not load (${String(newer.outcome.summary).slice(0, 120)})` }
|
|
407
|
+
const newestStatus = { state: "loaded", plugin_copy: deskVersion({ DESK_PLUGIN_ROOT: pluginRoot }), newest: release.latest }
|
|
408
|
+
return { state: "ready", latest: release.latest, loaded: { ...newer, runtimeStatus: { ...newer.runtimeStatus, newest_release: newestStatus } } }
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
// Inspect, restore and import the runtime from the offline pack. Returns { runtimeServer, runtimeStatus }, or { outcome } naming the degraded state.
|
|
412
|
+
// With the shipped importer, the inspection (which hashes and unpacks the archive) and the restore (which can wait on another process's publication lock) run on the admission worker; only the final import runs here.
|
|
413
|
+
async function loadRuntime({ activation, env, mcpRoot, offload, preflight, runtimeImporter, runtimeInspector, onPhase }) {
|
|
414
|
+
const { runtimeCacheDir, sourceIdentity } = activation
|
|
415
|
+
let inspection = null
|
|
416
|
+
let prepared = null
|
|
417
|
+
if (runtimeImporter === importRuntimeServer) {
|
|
418
|
+
const job = await offload({
|
|
419
|
+
kind: "runtime",
|
|
420
|
+
input: { mcpRoot, env, runtimeCacheDir, sourceIdentity, inspect: runtimeInspector === inspectRuntimeDependencyPack },
|
|
421
|
+
}, { onPhase })
|
|
422
|
+
if (job.inspectionError) return inspectionFailedOutcome({ mcpRoot, runtimeCacheDir, env })
|
|
423
|
+
inspection = job.inspection ?? null
|
|
424
|
+
if (inspection !== null && !inspection.ok) return runtimeOutcome(runtimeDiagnostic({ inspection, runtimeCacheDir, env }))
|
|
425
|
+
if (job.restoreError) return restoreFailedOutcome({ inspection, job, mcpRoot, runtimeCacheDir, env })
|
|
426
|
+
prepared = job.prepared
|
|
427
|
+
} else if (runtimeInspector !== null) {
|
|
428
|
+
try {
|
|
429
|
+
inspection = preflight === null ? runtimeInspector({ mcpRoot }) : preflight
|
|
430
|
+
} catch {
|
|
431
|
+
return inspectionFailedOutcome({ mcpRoot, runtimeCacheDir, env })
|
|
432
|
+
}
|
|
433
|
+
if (!inspection.ok) {
|
|
434
|
+
return runtimeOutcome(runtimeDiagnostic({ inspection, runtimeCacheDir, env }))
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
let runtimeServer
|
|
438
|
+
onPhase("importing_runtime")
|
|
439
|
+
try {
|
|
440
|
+
runtimeServer = prepared === null
|
|
441
|
+
? await runtimeImporter({ env, mcpRoot, runtimeCacheDir, sourceIdentity })
|
|
442
|
+
: await importPreparedRuntime({ mcpRoot, prepared })
|
|
443
|
+
} catch (error) {
|
|
444
|
+
return restoreFailedOutcome({ inspection, job: { restoreError: error }, mcpRoot, runtimeCacheDir, env })
|
|
445
|
+
}
|
|
446
|
+
const importedRuntime = runtimeServer._deskRuntime ?? {
|
|
447
|
+
runtime_cache_dir: runtimeCacheDir,
|
|
448
|
+
source_mirror_path: null,
|
|
449
|
+
target: null,
|
|
450
|
+
loaded_from_source_mirror: false,
|
|
451
|
+
}
|
|
452
|
+
const runtimeStatus = inspection === null
|
|
453
|
+
? importedRuntime
|
|
454
|
+
: {
|
|
455
|
+
...inspection.runtime,
|
|
456
|
+
...importedRuntime,
|
|
457
|
+
state: "ready",
|
|
458
|
+
current_target: inspection.runtime?.current_target ?? inspection.current_target,
|
|
459
|
+
shipped_targets: inspection.runtime?.shipped_targets ?? inspection.shipped_targets ?? [],
|
|
460
|
+
paths_checked: inspection.runtime?.paths_checked ?? inspection.paths_checked ?? [],
|
|
461
|
+
runtime_cache_path: importedRuntime.runtime_cache_dir ?? runtimeCacheDir,
|
|
462
|
+
support_matrix_path: inspection.runtime?.support_matrix_path ?? inspection.support_matrix_path,
|
|
463
|
+
}
|
|
464
|
+
return { runtimeServer, runtimeStatus }
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
// Packages are resolved from inside the mirror, next to its own node_modules, so each one loaded early is the file the server's own import finds. A mirror without the resolver is imported without splitting out its packages.
|
|
468
|
+
async function importMirrorInChunks(url) {
|
|
469
|
+
let resolvePackage = null
|
|
470
|
+
try {
|
|
471
|
+
resolvePackage = (await import(new URL("./runtime/resolve-here.js", url).href)).resolvePackage
|
|
472
|
+
} catch {
|
|
473
|
+
// The server's own import reports a missing or broken mirror.
|
|
474
|
+
}
|
|
475
|
+
// The mirror's root, holding its package.json, is our own package: a `#` import resolving inside it is our source, not a package.
|
|
476
|
+
return importInChunks(url, { resolvePackage, ownPackage: new URL("../", url).href })
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
// The last step of the shipped importer, after the worker restored the runtime: load the server from the source mirror, next to its native dependencies.
|
|
480
|
+
export async function importPreparedRuntime({ mcpRoot, prepared, load = importMirrorInChunks }) {
|
|
481
|
+
const pluginRoot = path.resolve(mcpRoot, "..")
|
|
482
|
+
const runtimeServer = await load(pathToFileURL(path.join(prepared.sourceMirrorPath, "src", "server.js")).href)
|
|
483
|
+
return {
|
|
484
|
+
...runtimeServer,
|
|
485
|
+
_deskRuntime: {
|
|
486
|
+
plugin_root: pluginRoot,
|
|
487
|
+
runtime_cache_dir: prepared.runtimeCacheDir,
|
|
488
|
+
source_mirror_path: prepared.sourceMirrorPath,
|
|
489
|
+
target: prepared.target,
|
|
490
|
+
pack_dir: prepared.packDir,
|
|
491
|
+
loaded_from_source_mirror: true,
|
|
492
|
+
},
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
function inspectionFailedOutcome({ mcpRoot, runtimeCacheDir, env }) {
|
|
497
|
+
return runtimeOutcome(runtimeDiagnostic({
|
|
498
|
+
inspection: startupFailureInspection({ mcpRoot, reason: "runtime_inspection_failed" }),
|
|
499
|
+
runtimeCacheDir,
|
|
500
|
+
env,
|
|
501
|
+
}))
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
function restoreFailedOutcome({ inspection, job, mcpRoot, runtimeCacheDir, env }) {
|
|
505
|
+
const error = job.restoreError
|
|
506
|
+
if (error?.lock) return lockedOutcome(error.lock)
|
|
507
|
+
return runtimeOutcome(runtimeDiagnostic({
|
|
508
|
+
inspection: inspection ?? startupFailureInspection({ mcpRoot, reason: "runtime_restore_failed" }),
|
|
509
|
+
reason: "runtime_restore_failed",
|
|
510
|
+
runtimeCacheDir,
|
|
511
|
+
env,
|
|
512
|
+
}), error)
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
// Another process held the runtime publication lock for the whole wait: not an integrity problem, and it usually clears on its own.
|
|
516
|
+
function lockedOutcome(lock) {
|
|
517
|
+
const holder = lock.pid === null ? "a process whose owner record is unreadable" : `pid ${lock.pid}`
|
|
518
|
+
return {
|
|
519
|
+
outcome: {
|
|
520
|
+
state: "degraded",
|
|
521
|
+
code: "runtime_restore_locked",
|
|
522
|
+
summary: `Another process (${holder}) held Desk's runtime publication lock ${lock.dir} for the whole 30 s wait while restoring the same runtime. Desk retries in the background.`,
|
|
523
|
+
fix: `Wait for ${holder} to finish restoring (usually seconds), then call desk_status. If that process is not a Desk process or is stuck, stop it; once it no longer exists, Desk removes the lock itself on its next retry.`,
|
|
524
|
+
diagnostic: { mode: "degraded", lock },
|
|
525
|
+
},
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
function runtimeOutcome(diagnostic, error) {
|
|
530
|
+
return {
|
|
531
|
+
outcome: {
|
|
532
|
+
state: "degraded",
|
|
533
|
+
code: diagnostic.code,
|
|
534
|
+
summary: diagnostic.summary,
|
|
535
|
+
fix: diagnostic.fix,
|
|
536
|
+
// Errors from the admission worker are plain objects: read their message either way.
|
|
537
|
+
diagnostic: error === undefined ? diagnostic : { ...diagnostic, restore_error: typeof error?.message === "string" ? error.message : String(error) },
|
|
538
|
+
},
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
const LAUNCHER_CODE = /^[a-z][a-z0-9_]{0,63}$/u
|
|
543
|
+
|
|
544
|
+
// --degraded <code> [--degraded-reason <text>]: a launcher that found a problem it cannot fix still starts Desk connected (refuse-but-connect, ruling 3 of 2026-09-25). Crew-state, repository and identity codes keep reads; every other code, including an unknown one, refuses every data tool. A crew-state code with --state-branch hands the checkout to Desk's own state-branch check, which can recover in the session.
|
|
545
|
+
export function launcherMode(args) {
|
|
546
|
+
if (!hasText(args.degraded)) return null
|
|
547
|
+
const code = LAUNCHER_CODE.test(args.degraded) ? args.degraded : "launcher_refused"
|
|
548
|
+
const reason = hasText(args.degradedReason) ? args.degradedReason : `the launcher reported ${code}`
|
|
549
|
+
if (!LAUNCHER_READ_ONLY_CODES.includes(code)) return { code, reason, mode: "refuse", blocksWrites: true }
|
|
550
|
+
const branchChecked = code.startsWith("crew_state_") && hasText(args.stateBranch)
|
|
551
|
+
return { code, reason, mode: "read_only", blocksWrites: !branchChecked }
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
// Last-resort handlers for the process: an exception or rejection nothing caught is recorded by the session (degraded:runtime_exception, then re-admission) instead of ending the process and the host's connection with it. Returns a function that removes them.
|
|
555
|
+
export function installCrashHandlers({ session, stderr, target, onPeerGone }) {
|
|
556
|
+
// A write or read on a host connection that is gone can never succeed: ending is the only useful answer, and recording it would degrade and re-admit on every later write.
|
|
557
|
+
const handle = (kind, error) => {
|
|
558
|
+
if (isPeerGoneError(error)) {
|
|
559
|
+
stderr.write(`[desk-mcp] the host connection is gone (${describeError(error)}); closing the session\n`)
|
|
560
|
+
onPeerGone()
|
|
561
|
+
return
|
|
562
|
+
}
|
|
563
|
+
return session.recordException(kind, error)
|
|
564
|
+
}
|
|
565
|
+
const onException = (error) => handle("uncaught_exception", error)
|
|
566
|
+
const onRejection = (reason) => handle("unhandled_rejection", reason)
|
|
567
|
+
target.on("uncaughtException", onException)
|
|
568
|
+
target.on("unhandledRejection", onRejection)
|
|
569
|
+
stderr.write("[desk-mcp] crash handlers installed: an error after the handshake degrades Desk instead of ending it\n")
|
|
570
|
+
return () => {
|
|
571
|
+
target.off("uncaughtException", onException)
|
|
572
|
+
target.off("unhandledRejection", onRejection)
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
const PEER_GONE_CODES = new Set(["EPIPE", "ECONNRESET", "ERR_STREAM_DESTROYED", "ERR_STREAM_WRITE_AFTER_END"])
|
|
577
|
+
|
|
578
|
+
export function isPeerGoneError(error) {
|
|
579
|
+
return error !== null && typeof error === "object" && PEER_GONE_CODES.has(error.code)
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
export const PARENT_CHECK_MS = 5000
|
|
583
|
+
|
|
584
|
+
// Calls `onGone` once when the process that started this server has ended: its pid changed (a parent that ends leaves the process to init or a subreaper) or it no longer exists. The timer never keeps the process alive. Returns a function that stops it.
|
|
585
|
+
export function watchParent({
|
|
586
|
+
onGone,
|
|
587
|
+
initialPpid = process.ppid,
|
|
588
|
+
getPpid = () => process.ppid,
|
|
589
|
+
isAlive = (pid) => {
|
|
590
|
+
try {
|
|
591
|
+
process.kill(pid, 0)
|
|
592
|
+
return true
|
|
593
|
+
} catch (error) {
|
|
594
|
+
return error?.code === "EPERM"
|
|
595
|
+
}
|
|
596
|
+
},
|
|
597
|
+
intervalMs = PARENT_CHECK_MS,
|
|
598
|
+
setTimer = setInterval,
|
|
599
|
+
clearTimer = clearInterval,
|
|
600
|
+
}) {
|
|
601
|
+
if (!(initialPpid > 1)) return () => {}
|
|
602
|
+
const timer = setTimer(() => {
|
|
603
|
+
if (getPpid() !== initialPpid || !isAlive(initialPpid)) {
|
|
604
|
+
clearTimer(timer)
|
|
605
|
+
onGone()
|
|
606
|
+
}
|
|
607
|
+
}, intervalMs)
|
|
608
|
+
timer.unref?.()
|
|
609
|
+
return () => clearTimer(timer)
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
function optional(read) {
|
|
613
|
+
try {
|
|
614
|
+
return read()
|
|
615
|
+
} catch {
|
|
616
|
+
return null
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
// On a Node below the engines floor, inspect the shipped runtime packs so node selection can find a Node that matches one; if inspection is unavailable, selection still runs and falls back to diagnostic mode.
|
|
621
|
+
function outdatedNodeInspection({ mcpRoot, runtimeInspector }) {
|
|
622
|
+
let inspection = null
|
|
623
|
+
if (runtimeInspector !== null) {
|
|
624
|
+
try {
|
|
625
|
+
inspection = runtimeInspector({ mcpRoot })
|
|
626
|
+
} catch {
|
|
627
|
+
inspection = null
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
return {
|
|
631
|
+
...(inspection ?? startupFailureInspection({ mcpRoot, reason: "node_below_engines_floor" })),
|
|
632
|
+
ok: false,
|
|
633
|
+
reason: "node_below_engines_floor",
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
async function handleUnavailableRuntime({
|
|
638
|
+
argv,
|
|
639
|
+
diagnosticServerStarter,
|
|
640
|
+
env,
|
|
641
|
+
homeDir,
|
|
642
|
+
inspection,
|
|
643
|
+
mcpRoot,
|
|
644
|
+
nodeCandidateDiscoverer,
|
|
645
|
+
nodeReexecutor,
|
|
646
|
+
nodeSelector,
|
|
647
|
+
runtimeCacheDir,
|
|
648
|
+
}) {
|
|
649
|
+
// Only a Node below the engines floor, a target no pack supports, or a re-exec that came back still unsupported reaches this point: each needs a different Node, found before the handshake.
|
|
650
|
+
let selection
|
|
651
|
+
try {
|
|
652
|
+
selection = nodeSelector({
|
|
653
|
+
candidates: nodeCandidateDiscoverer({ env, homeDir }),
|
|
654
|
+
currentTarget: inspection.runtime?.current_target ?? inspection.current_target,
|
|
655
|
+
env,
|
|
656
|
+
shippedTargets: inspection.runtime?.shipped_targets ?? inspection.shipped_targets ?? [],
|
|
657
|
+
})
|
|
658
|
+
} catch {
|
|
659
|
+
return diagnosticServerStarter({
|
|
660
|
+
diagnostic: runtimeDiagnostic({
|
|
661
|
+
inspection,
|
|
662
|
+
reason: "node_selection_failed",
|
|
663
|
+
runtimeCacheDir,
|
|
664
|
+
env,
|
|
665
|
+
}),
|
|
666
|
+
})
|
|
667
|
+
}
|
|
668
|
+
if (selection.mode === "reexec") {
|
|
669
|
+
try {
|
|
670
|
+
const result = await nodeReexecutor({
|
|
671
|
+
argv,
|
|
672
|
+
entrypointPath: path.join(mcpRoot, "index.js"),
|
|
673
|
+
env,
|
|
674
|
+
executable: selection.executable,
|
|
675
|
+
})
|
|
676
|
+
if (result.forwardedSignal !== null && result.forwardedSignal !== undefined) {
|
|
677
|
+
return result
|
|
678
|
+
}
|
|
679
|
+
if (result.code !== 0 || result.signal !== null) {
|
|
680
|
+
throw new Error(`compatible Node exited with ${result.signal ?? result.code}`)
|
|
681
|
+
}
|
|
682
|
+
return result
|
|
683
|
+
} catch {
|
|
684
|
+
return diagnosticServerStarter({
|
|
685
|
+
diagnostic: runtimeDiagnostic({
|
|
686
|
+
inspection,
|
|
687
|
+
reason: "guarded_reexec_failure",
|
|
688
|
+
pathsChecked: selection.paths_checked,
|
|
689
|
+
runtimeCacheDir,
|
|
690
|
+
env,
|
|
691
|
+
}),
|
|
692
|
+
})
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
return diagnosticServerStarter({
|
|
696
|
+
diagnostic: runtimeDiagnostic({
|
|
697
|
+
inspection,
|
|
698
|
+
reason: selection.reason,
|
|
699
|
+
pathsChecked: selection.paths_checked,
|
|
700
|
+
runtimeCacheDir,
|
|
701
|
+
env,
|
|
702
|
+
}),
|
|
703
|
+
})
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
function startupFailureInspection({ mcpRoot, reason }) {
|
|
707
|
+
const currentTarget = {
|
|
708
|
+
id: `${process.platform}-${process.arch}-node-${process.versions.modules}`,
|
|
709
|
+
platform: process.platform,
|
|
710
|
+
arch: process.arch,
|
|
711
|
+
node_abi: process.versions.modules,
|
|
712
|
+
}
|
|
713
|
+
const runtime = {
|
|
714
|
+
current_target: currentTarget,
|
|
715
|
+
shipped_targets: [],
|
|
716
|
+
paths_checked: [mcpRoot],
|
|
717
|
+
support_matrix_path: null,
|
|
718
|
+
}
|
|
719
|
+
return {
|
|
720
|
+
ok: false,
|
|
721
|
+
mode: "diagnostic",
|
|
722
|
+
reason,
|
|
723
|
+
runtime,
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
function runtimeDiagnostic({
|
|
728
|
+
inspection,
|
|
729
|
+
reason = inspection.reason,
|
|
730
|
+
pathsChecked = [],
|
|
731
|
+
runtimeCacheDir,
|
|
732
|
+
env,
|
|
733
|
+
}) {
|
|
734
|
+
const runtime = inspection.runtime ?? inspection
|
|
735
|
+
return createRuntimeDiagnostic({
|
|
736
|
+
reason,
|
|
737
|
+
failureKind: reason === inspection.reason ? inspection.failure_kind : undefined,
|
|
738
|
+
currentTarget: runtime.current_target,
|
|
739
|
+
shippedTargets: runtime.shipped_targets ?? [],
|
|
740
|
+
pathsChecked: [...(runtime.paths_checked ?? []), ...pathsChecked],
|
|
741
|
+
runtimeCachePath: runtimeCacheDir ?? env.DESK_RUNTIME_CACHE_DIR ?? null,
|
|
742
|
+
supportMatrixPath: runtime.support_matrix_path ?? null,
|
|
743
|
+
})
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
function hasText(value) {
|
|
747
|
+
return typeof value === "string" && value.trim().length > 0
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
export function isEntrypoint({
|
|
751
|
+
argv = process.argv,
|
|
752
|
+
moduleUrl = import.meta.url,
|
|
753
|
+
realpath = realpathSync,
|
|
754
|
+
} = {}) {
|
|
755
|
+
if (!argv[1]) {
|
|
756
|
+
return false
|
|
757
|
+
}
|
|
758
|
+
const modulePath = fileURLToPath(moduleUrl)
|
|
759
|
+
try {
|
|
760
|
+
return realpath(modulePath) === realpath(argv[1])
|
|
761
|
+
} catch {
|
|
762
|
+
return path.resolve(modulePath) === path.resolve(argv[1])
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
export function runIfEntrypoint({
|
|
767
|
+
argv = process.argv,
|
|
768
|
+
moduleUrl = import.meta.url,
|
|
769
|
+
stderr = process.stderr,
|
|
770
|
+
exit = process.exit,
|
|
771
|
+
launch = main,
|
|
772
|
+
startDiagnostic = startStartupExceptionDiagnostic,
|
|
773
|
+
} = {}) {
|
|
774
|
+
if (!isEntrypoint({ argv, moduleUrl })) return null
|
|
775
|
+
// Degrade, never die: anything that throws before the server starts is served as diagnostic mode, so the host's handshake still completes and desk_status names the cause. Only a diagnostic server that cannot run at all (stdio gone) exits.
|
|
776
|
+
const handleStartupException = (err) => {
|
|
777
|
+
stderr.write(`[desk-mcp] startup exception: ${describeError(err)}; serving diagnostic mode\n`)
|
|
778
|
+
return Promise.resolve()
|
|
779
|
+
.then(() => startDiagnostic({ error: err }))
|
|
780
|
+
.catch((diagnosticError) => {
|
|
781
|
+
stderr.write(`[desk-mcp] fatal: ${describeError(diagnosticError)}\n`)
|
|
782
|
+
exit(1)
|
|
783
|
+
})
|
|
784
|
+
}
|
|
785
|
+
try {
|
|
786
|
+
// The host closing stdin ends the session: exit rather than linger on background admission or a watcher.
|
|
787
|
+
return Promise.resolve(launch({ onClosed: (code = 0) => exit(code), crashHandlers: true })).catch(handleStartupException)
|
|
788
|
+
} catch (err) {
|
|
789
|
+
return handleStartupException(err)
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
// Serve the startup-exception diagnostic on stdio (tests pass their own streams).
|
|
794
|
+
export function startStartupExceptionDiagnostic({
|
|
795
|
+
error,
|
|
796
|
+
input,
|
|
797
|
+
output,
|
|
798
|
+
}) {
|
|
799
|
+
return startDiagnosticServer({
|
|
800
|
+
diagnostic: createStartupExceptionDiagnostic({ error }),
|
|
801
|
+
serverVersion: resolveMcpServerVersion(),
|
|
802
|
+
input,
|
|
803
|
+
output,
|
|
804
|
+
})
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
function describeError(error) {
|
|
808
|
+
return error instanceof Error ? error.message : String(error)
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
// Only launch the server when run as the entry point, not when imported
|
|
812
|
+
// (tests import `parseArgs` without spawning a stdio server).
|
|
813
|
+
runIfEntrypoint()
|