synabun 2.2.1 → 2.3.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/CHANGELOG.md +53 -0
- package/README.md +1 -1
- package/docs/whatsapp.md +52 -20
- package/hooks/claude-code/pre-websearch.mjs +4 -1
- package/hooks/claude-code/prompt-submit.mjs +7 -0
- package/lib/mcp-build.js +519 -0
- package/lib/mcp-dist.js +10 -4
- package/lib/release-scan.mjs +23 -10
- package/lib/server-supervisor.js +7 -1
- package/lib/virustotal.mjs +146 -40
- package/mcp-server/dist/http.d.ts +57 -0
- package/mcp-server/dist/http.d.ts.map +1 -1
- package/mcp-server/dist/http.js +128 -18
- package/mcp-server/dist/http.js.map +1 -1
- package/mcp-server/dist/index.d.ts.map +1 -1
- package/mcp-server/dist/index.js +14 -9
- package/mcp-server/dist/index.js.map +1 -1
- package/mcp-server/dist/services/browser-route-flow.d.ts +119 -0
- package/mcp-server/dist/services/browser-route-flow.d.ts.map +1 -0
- package/mcp-server/dist/services/browser-route-flow.js +340 -0
- package/mcp-server/dist/services/browser-route-flow.js.map +1 -0
- package/mcp-server/dist/services/desktop-client.js +2 -2
- package/mcp-server/dist/services/desktop-client.js.map +1 -1
- package/mcp-server/dist/services/embedding-service.d.ts.map +1 -1
- package/mcp-server/dist/services/embedding-service.js +2 -1
- package/mcp-server/dist/services/embedding-service.js.map +1 -1
- package/mcp-server/dist/services/identity.d.ts +66 -3
- package/mcp-server/dist/services/identity.d.ts.map +1 -1
- package/mcp-server/dist/services/identity.js +61 -4
- package/mcp-server/dist/services/identity.js.map +1 -1
- package/mcp-server/dist/services/neural-interface.d.ts +133 -1
- package/mcp-server/dist/services/neural-interface.d.ts.map +1 -1
- package/mcp-server/dist/services/neural-interface.js +630 -64
- package/mcp-server/dist/services/neural-interface.js.map +1 -1
- package/mcp-server/dist/services/tool-catalog.js +2 -2
- package/mcp-server/dist/services/tool-catalog.js.map +1 -1
- package/mcp-server/dist/tools/agents.d.ts +3 -2
- package/mcp-server/dist/tools/agents.d.ts.map +1 -1
- package/mcp-server/dist/tools/agents.js +6 -4
- package/mcp-server/dist/tools/agents.js.map +1 -1
- package/mcp-server/dist/tools/bluesky.d.ts +20 -7
- package/mcp-server/dist/tools/bluesky.d.ts.map +1 -1
- package/mcp-server/dist/tools/bluesky.js +147 -45
- package/mcp-server/dist/tools/bluesky.js.map +1 -1
- package/mcp-server/dist/tools/browser-advanced.d.ts +13 -2
- package/mcp-server/dist/tools/browser-advanced.d.ts.map +1 -1
- package/mcp-server/dist/tools/browser-advanced.js +153 -18
- package/mcp-server/dist/tools/browser-advanced.js.map +1 -1
- package/mcp-server/dist/tools/browser-cheatsheet.d.ts +2 -0
- package/mcp-server/dist/tools/browser-cheatsheet.d.ts.map +1 -1
- package/mcp-server/dist/tools/browser-cheatsheet.js +3 -0
- package/mcp-server/dist/tools/browser-cheatsheet.js.map +1 -1
- package/mcp-server/dist/tools/browser-navigate.d.ts +3 -3
- package/mcp-server/dist/tools/browser-navigate.d.ts.map +1 -1
- package/mcp-server/dist/tools/browser-navigate.js +19 -16
- package/mcp-server/dist/tools/browser-navigate.js.map +1 -1
- package/mcp-server/dist/tools/browser-observe.d.ts +2 -1
- package/mcp-server/dist/tools/browser-observe.d.ts.map +1 -1
- package/mcp-server/dist/tools/browser-observe.js +61 -20
- package/mcp-server/dist/tools/browser-observe.js.map +1 -1
- package/mcp-server/dist/tools/morelogin.d.ts +13 -3
- package/mcp-server/dist/tools/morelogin.d.ts.map +1 -1
- package/mcp-server/dist/tools/morelogin.js +82 -19
- package/mcp-server/dist/tools/morelogin.js.map +1 -1
- package/mcp-server/dist/tools/skill-tools.d.ts +4 -4
- package/mcp-server/dist/tools/youtube/helpers.d.ts +1 -0
- package/mcp-server/dist/tools/youtube/helpers.d.ts.map +1 -1
- package/mcp-server/dist/tools/youtube/helpers.js +1 -1
- package/mcp-server/dist/tools/youtube/helpers.js.map +1 -1
- package/mcp-server/dist/tools/youtube/upload.d.ts.map +1 -1
- package/mcp-server/dist/tools/youtube/upload.js +225 -88
- package/mcp-server/dist/tools/youtube/upload.js.map +1 -1
- package/mcp-server/package-lock.json +2 -2
- package/mcp-server/package.json +1 -1
- package/mcp-server/src/http.ts +135 -17
- package/mcp-server/src/index.ts +15 -9
- package/mcp-server/src/services/browser-route-flow.ts +403 -0
- package/mcp-server/src/services/desktop-client.ts +2 -2
- package/mcp-server/src/services/embedding-service.ts +2 -1
- package/mcp-server/src/services/identity.ts +80 -4
- package/mcp-server/src/services/neural-interface.ts +648 -73
- package/mcp-server/src/services/tool-catalog.ts +2 -2
- package/mcp-server/src/tools/agents.ts +8 -4
- package/mcp-server/src/tools/bluesky.ts +164 -51
- package/mcp-server/src/tools/browser-advanced.ts +142 -17
- package/mcp-server/src/tools/browser-cheatsheet.ts +3 -0
- package/mcp-server/src/tools/browser-navigate.ts +19 -16
- package/mcp-server/src/tools/browser-observe.ts +62 -20
- package/mcp-server/src/tools/morelogin.ts +82 -19
- package/mcp-server/src/tools/youtube/helpers.ts +2 -2
- package/mcp-server/src/tools/youtube/upload.ts +218 -99
- package/neural-interface/i18n/en.json +655 -123
- package/neural-interface/i18n/pt-BR.json +542 -10
- package/neural-interface/lib/assistant-api.js +90 -23
- package/neural-interface/lib/assistant-brains/claude.js +5 -0
- package/neural-interface/lib/assistant-catalog.js +134 -3
- package/neural-interface/lib/assistant-dispatch.js +97 -1
- package/neural-interface/lib/assistant-persona.js +15 -7
- package/neural-interface/lib/assistant-router.js +6 -4
- package/neural-interface/lib/assistant-runtime.js +18 -1
- package/neural-interface/lib/assistant-task-prompt.js +5 -0
- package/neural-interface/lib/assistant-tools.js +10 -1
- package/neural-interface/lib/automation-approval.js +249 -0
- package/neural-interface/lib/automation-browser-owner-access.js +82 -0
- package/neural-interface/lib/backup-service.js +16 -1
- package/neural-interface/lib/browser-automation-routes.js +84 -0
- package/neural-interface/lib/browser-background-tab.js +72 -3
- package/neural-interface/lib/browser-execution.js +16 -3
- package/neural-interface/lib/browser-extraction.js +106 -45
- package/neural-interface/lib/browser-owner.js +48 -0
- package/neural-interface/lib/browser-profile-choices.js +143 -0
- package/neural-interface/lib/browser-profiles.js +142 -0
- package/neural-interface/lib/browser-session-close.js +84 -0
- package/neural-interface/lib/browser-start-handoff.js +202 -0
- package/neural-interface/lib/browser-tab-recovery.js +153 -0
- package/neural-interface/lib/browser-tool-policy.js +23 -4
- package/neural-interface/lib/browser-wedge-retire.js +64 -0
- package/neural-interface/lib/chromium-on-device-model.js +67 -0
- package/neural-interface/lib/claude-agent-bridge.js +43 -5
- package/neural-interface/lib/claude-background-hold.js +239 -0
- package/neural-interface/lib/claude-model-catalog.js +12 -0
- package/neural-interface/lib/effort-levels.js +28 -2
- package/neural-interface/lib/exec-loop-command.js +8 -0
- package/neural-interface/lib/http-guards.js +11 -6
- package/neural-interface/lib/local-profile-proxy.js +362 -0
- package/neural-interface/lib/local-profiles.js +929 -0
- package/neural-interface/lib/loop-logger.js +31 -5
- package/neural-interface/lib/maritaca/api.js +179 -0
- package/neural-interface/lib/maritaca/attachments.js +44 -0
- package/neural-interface/lib/maritaca/client.js +362 -0
- package/neural-interface/lib/maritaca/key-store.js +122 -0
- package/neural-interface/lib/maritaca/models.js +181 -0
- package/neural-interface/lib/maritaca/modes.js +39 -0
- package/neural-interface/lib/maritaca/opencode-proxy.js +236 -0
- package/neural-interface/lib/maritaca/opencode-stream.js +345 -0
- package/neural-interface/lib/maritaca/opencode.js +218 -0
- package/neural-interface/lib/maritaca/panel-bridge.js +273 -0
- package/neural-interface/lib/maritaca/sessions.js +198 -0
- package/neural-interface/lib/mcp-external-servers.js +37 -10
- package/neural-interface/lib/morelogin-agent-profiles.js +149 -0
- package/neural-interface/lib/morelogin.js +278 -14
- package/neural-interface/lib/native-loop-providers.js +124 -11
- package/neural-interface/lib/native-loop-runtime.js +112 -11
- package/neural-interface/lib/owner-authority.js +137 -43
- package/neural-interface/lib/page-session.js +111 -27
- package/neural-interface/lib/peer-identity.js +263 -43
- package/neural-interface/lib/provider-panel-api-key-auth.js +7 -2
- package/neural-interface/lib/pty-host/core.js +36 -0
- package/neural-interface/lib/pty-host/protocol.js +2 -0
- package/neural-interface/lib/request-gate.js +2 -0
- package/neural-interface/lib/skills/api-v2.js +13 -2
- package/neural-interface/lib/skills/creation-api.js +3 -1
- package/neural-interface/lib/skills/evals-api.js +5 -1
- package/neural-interface/lib/social-write-pacing.js +151 -0
- package/neural-interface/lib/system-activity.js +1 -1
- package/neural-interface/lib/terminal-token-redaction.js +293 -0
- package/neural-interface/lib/terminal-tokens.js +436 -0
- package/neural-interface/lib/worker-mcp-channel.js +45 -10
- package/neural-interface/package-lock.json +3 -2
- package/neural-interface/package.json +2 -1
- package/neural-interface/public/assets/mascot/README.md +11 -0
- package/neural-interface/public/assets/mascot/ask.gif +0 -0
- package/neural-interface/public/assets/mascot/ask.png +0 -0
- package/neural-interface/public/assets/mascot/blocked.gif +0 -0
- package/neural-interface/public/assets/mascot/blocked.png +0 -0
- package/neural-interface/public/assets/mascot/budget.gif +0 -0
- package/neural-interface/public/assets/mascot/budget.png +0 -0
- package/neural-interface/public/assets/mascot/computer.gif +0 -0
- package/neural-interface/public/assets/mascot/computer.png +0 -0
- package/neural-interface/public/assets/mascot/edit.gif +0 -0
- package/neural-interface/public/assets/mascot/edit.png +0 -0
- package/neural-interface/public/assets/mascot/error.gif +0 -0
- package/neural-interface/public/assets/mascot/error.png +0 -0
- package/neural-interface/public/assets/mascot/hover-attention.gif +0 -0
- package/neural-interface/public/assets/mascot/hover-attention.png +0 -0
- package/neural-interface/public/assets/mascot/idle-hero.gif +0 -0
- package/neural-interface/public/assets/mascot/idle-hero.png +0 -0
- package/neural-interface/public/assets/mascot/idle.gif +0 -0
- package/neural-interface/public/assets/mascot/idle.png +0 -0
- package/neural-interface/public/assets/mascot/manifest.json +254 -0
- package/neural-interface/public/assets/mascot/mcp.gif +0 -0
- package/neural-interface/public/assets/mascot/mcp.png +0 -0
- package/neural-interface/public/assets/mascot/memory.gif +0 -0
- package/neural-interface/public/assets/mascot/memory.png +0 -0
- package/neural-interface/public/assets/mascot/offline.gif +0 -0
- package/neural-interface/public/assets/mascot/offline.png +0 -0
- package/neural-interface/public/assets/mascot/pick.gif +0 -0
- package/neural-interface/public/assets/mascot/pick.png +0 -0
- package/neural-interface/public/assets/mascot/plan.gif +0 -0
- package/neural-interface/public/assets/mascot/plan.png +0 -0
- package/neural-interface/public/assets/mascot/present.gif +0 -0
- package/neural-interface/public/assets/mascot/present.png +0 -0
- package/neural-interface/public/assets/mascot/project.gif +0 -0
- package/neural-interface/public/assets/mascot/project.png +0 -0
- package/neural-interface/public/assets/mascot/read.gif +0 -0
- package/neural-interface/public/assets/mascot/read.png +0 -0
- package/neural-interface/public/assets/mascot/runs.gif +0 -0
- package/neural-interface/public/assets/mascot/runs.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/automation.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/automation.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/browser.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/browser.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/code.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/code.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/complex.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/complex.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/computer.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/computer.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/design.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/design.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/edit.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/edit.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/generic.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/generic.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/image_gen.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/image_gen.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/manifest.json +173 -0
- package/neural-interface/public/assets/mascot/scenes/memory.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/memory.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/quick.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/quick.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/read.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/read.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/research.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/research.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/review.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/review.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/search.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/search.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/shell.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/shell.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/thinking.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/thinking.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/video_gen.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/video_gen.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/web.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/web.png +0 -0
- package/neural-interface/public/assets/mascot/search.gif +0 -0
- package/neural-interface/public/assets/mascot/search.png +0 -0
- package/neural-interface/public/assets/mascot/shell.gif +0 -0
- package/neural-interface/public/assets/mascot/shell.png +0 -0
- package/neural-interface/public/assets/mascot/skill.gif +0 -0
- package/neural-interface/public/assets/mascot/skill.png +0 -0
- package/neural-interface/public/assets/mascot/sleep.gif +0 -0
- package/neural-interface/public/assets/mascot/sleep.png +0 -0
- package/neural-interface/public/assets/mascot/subagent.gif +0 -0
- package/neural-interface/public/assets/mascot/subagent.png +0 -0
- package/neural-interface/public/assets/mascot/success.gif +0 -0
- package/neural-interface/public/assets/mascot/success.png +0 -0
- package/neural-interface/public/assets/mascot/think.gif +0 -0
- package/neural-interface/public/assets/mascot/think.png +0 -0
- package/neural-interface/public/assets/mascot/wait.gif +0 -0
- package/neural-interface/public/assets/mascot/wait.png +0 -0
- package/neural-interface/public/assets/mascot/watch.gif +0 -0
- package/neural-interface/public/assets/mascot/watch.png +0 -0
- package/neural-interface/public/assets/mascot/web.gif +0 -0
- package/neural-interface/public/assets/mascot/web.png +0 -0
- package/neural-interface/public/onboarding.html +14 -1
- package/neural-interface/public/shared/agent-runtime-options.js +49 -8
- package/neural-interface/public/shared/agy/agy-panel.js +2 -2
- package/neural-interface/public/shared/agy/agy-render.js +41 -1
- package/neural-interface/public/shared/agy/agy-styles.js +5 -0
- package/neural-interface/public/shared/api.js +5 -4
- package/neural-interface/public/shared/assistant/asst-ask-styles.js +8 -8
- package/neural-interface/public/shared/assistant/asst-ask.js +1 -1
- package/neural-interface/public/shared/assistant/asst-brain-picker.js +99 -9
- package/neural-interface/public/shared/assistant/asst-computer.js +47 -2
- package/neural-interface/public/shared/assistant/asst-control.js +1 -1
- package/neural-interface/public/shared/assistant/asst-limit-wait.js +7 -5
- package/neural-interface/public/shared/assistant/asst-panel.js +13 -5
- package/neural-interface/public/shared/assistant/asst-rack-styles.js +4 -4
- package/neural-interface/public/shared/assistant/asst-render.js +16 -10
- package/neural-interface/public/shared/assistant/asst-route-models.js +64 -4
- package/neural-interface/public/shared/assistant/asst-route.js +24 -7
- package/neural-interface/public/shared/assistant/asst-routes-editor.js +154 -39
- package/neural-interface/public/shared/assistant/asst-run-stage.js +3 -3
- package/neural-interface/public/shared/assistant/asst-scene-styles.js +8 -111
- package/neural-interface/public/shared/assistant/asst-scenes.js +46 -318
- package/neural-interface/public/shared/assistant/asst-sidepanel.js +2 -2
- package/neural-interface/public/shared/assistant/asst-state.js +72 -2
- package/neural-interface/public/shared/assistant/asst-styles.js +60 -15
- package/neural-interface/public/shared/automation-approval-view.js +75 -0
- package/neural-interface/public/shared/cdx/cdx-panel.js +2 -2
- package/neural-interface/public/shared/cdx/cdx-render.js +73 -7
- package/neural-interface/public/shared/cdx/cdx-tabs.js +3 -3
- package/neural-interface/public/shared/context-menu-model.js +2 -0
- package/neural-interface/public/shared/cp/cp-agents.js +8 -0
- package/neural-interface/public/shared/cp/cp-permissions.js +6 -2
- package/neural-interface/public/shared/cp/cp-rehydrate.js +25 -1
- package/neural-interface/public/shared/cp/cp-tasks-model.js +33 -0
- package/neural-interface/public/shared/editor/editor-panel-logic.js +10 -0
- package/neural-interface/public/shared/editor/editor-panel.js +10 -2
- package/neural-interface/public/shared/html-shell.js +30 -22
- package/neural-interface/public/shared/judgments-log-origins.js +29 -0
- package/neural-interface/public/shared/morelogin-profile-choices.js +107 -0
- package/neural-interface/public/shared/morelogin-profile-field.js +186 -0
- package/neural-interface/public/shared/mtc/mtc-client.js +181 -0
- package/neural-interface/public/shared/mtc/mtc-compose.js +40 -0
- package/neural-interface/public/shared/mtc/mtc-copy.js +253 -0
- package/neural-interface/public/shared/mtc/mtc-logic.js +478 -0
- package/neural-interface/public/shared/mtc/mtc-panel.js +1354 -0
- package/neural-interface/public/shared/mtc/mtc-render.js +172 -0
- package/neural-interface/public/shared/mtc/mtc-styles.js +437 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-automation-ownership.js +23 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-events.js +13 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-icons.js +3 -1
- package/neural-interface/public/shared/ocp-v2/ocp-v2-panel.js +10 -4
- package/neural-interface/public/shared/ocp-v2/ocp-v2-render.js +6 -86
- package/neural-interface/public/shared/ocp-v2/ocp-v2-ws.js +5 -2
- package/neural-interface/public/shared/owner-access.js +134 -0
- package/neural-interface/public/shared/owner-authority-view.js +92 -0
- package/neural-interface/public/shared/page-session.js +143 -14
- package/neural-interface/public/shared/poll-backoff.js +59 -0
- package/neural-interface/public/shared/provider-icons.js +3 -0
- package/neural-interface/public/shared/schedules-view.js +7 -0
- package/neural-interface/public/shared/server-back.js +50 -0
- package/neural-interface/public/shared/settings/settings-browser-owner-access.js +72 -0
- package/neural-interface/public/shared/settings/settings-data.js +7 -1
- package/neural-interface/public/shared/settings/settings-ia.js +3 -1
- package/neural-interface/public/shared/settings/settings-kit.js +11 -3
- package/neural-interface/public/shared/settings/settings-local-profiles.js +153 -0
- package/neural-interface/public/shared/settings/settings-maritaca-opencode.js +105 -0
- package/neural-interface/public/shared/settings/settings-shell.js +7 -0
- package/neural-interface/public/shared/shown-children.js +72 -0
- package/neural-interface/public/shared/sidepanel-session-status.js +16 -2
- package/neural-interface/public/shared/state.js +1 -1
- package/neural-interface/public/shared/static-bg-state.js +22 -0
- package/neural-interface/public/shared/styles.css +457 -164
- package/neural-interface/public/shared/synabun-mascot-assets.js +67 -0
- package/neural-interface/public/shared/synabun-mascot.js +136 -12
- package/neural-interface/public/shared/synabun-ticker.js +3 -0
- package/neural-interface/public/shared/synabun-tools.js +173 -0
- package/neural-interface/public/shared/tool-heartbeat.js +43 -0
- package/neural-interface/public/shared/tool-list-picker.js +3 -1
- package/neural-interface/public/shared/tool-list-view.js +23 -4
- package/neural-interface/public/shared/topright-overflow-logic.js +1 -0
- package/neural-interface/public/shared/ui-automation-approval.js +188 -0
- package/neural-interface/public/shared/ui-automation-studio.js +138 -91
- package/neural-interface/public/shared/ui-claude-panel.js +209 -31
- package/neural-interface/public/shared/ui-judgments.js +37 -10
- package/neural-interface/public/shared/ui-maritaca-panel.js +15 -0
- package/neural-interface/public/shared/ui-navbar.js +23 -0
- package/neural-interface/public/shared/ui-owner-access.js +191 -0
- package/neural-interface/public/shared/ui-owner-authority.js +162 -0
- package/neural-interface/public/shared/ui-panels.js +3 -1
- package/neural-interface/public/shared/ui-schedules-studio.js +118 -17
- package/neural-interface/public/shared/ui-scroll-follow.js +3 -0
- package/neural-interface/public/shared/ui-sessions.js +45 -16
- package/neural-interface/public/shared/ui-settings.js +676 -42
- package/neural-interface/public/shared/ui-sidepanel-session-entry.js +8 -2
- package/neural-interface/public/shared/ui-sidepanel-sessions.js +3 -3
- package/neural-interface/public/shared/ui-sidepanel-tray.js +24 -0
- package/neural-interface/public/shared/ui-sidepanel-windows.js +1 -1
- package/neural-interface/public/shared/ui-terminal.js +15 -7
- package/neural-interface/public/shared/ui-tutorial-preview.js +4 -0
- package/neural-interface/public/shared/ui-update.js +3 -0
- package/neural-interface/public/shared/ui-whiteboard.js +4 -0
- package/neural-interface/public/shared/window-keys.js +38 -0
- package/neural-interface/scripts/build-mascot-assets.mjs +30 -0
- package/neural-interface/server.js +2903 -359
- package/npm-shrinkwrap.json +5 -17
- package/package.json +5 -6
- package/postinstall.js +38 -39
- package/setup.js +33 -31
- package/skills/synabun/modules/changelog.md +14 -0
package/lib/virustotal.mjs
CHANGED
|
@@ -6,6 +6,17 @@ import { basename } from 'node:path';
|
|
|
6
6
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
7
7
|
|
|
8
8
|
export const DIRECT_LIMIT = 32 * 1024 * 1024;
|
|
9
|
+
// Files above this size go through the large-upload URL, where VirusTotal can take
|
|
10
|
+
// long to show the analysis; they get the large deadline when it is the longer one.
|
|
11
|
+
export const LARGE_FILE = DIRECT_LIMIT;
|
|
12
|
+
export const MAX_SCAN_MINUTES = 240;
|
|
13
|
+
/** A deadline in minutes from the environment: a number above 0, at most MAX_SCAN_MINUTES. */
|
|
14
|
+
export function scanMinutes(value, fallback, name) {
|
|
15
|
+
if (value === undefined || value === null || String(value).trim() === '') return fallback;
|
|
16
|
+
const text = String(value).trim(); const minutes = Number(text);
|
|
17
|
+
if (!/^\d+(\.\d+)?$/.test(text) || !(minutes > 0) || minutes > MAX_SCAN_MINUTES) throw new Error(`${name} must be a number of minutes above 0 and at most ${MAX_SCAN_MINUTES}`);
|
|
18
|
+
return minutes;
|
|
19
|
+
}
|
|
9
20
|
export const UPLOAD_LIMIT = 650 * 1024 * 1024;
|
|
10
21
|
export const API = 'https://www.virustotal.com/api/v3/';
|
|
11
22
|
export const README_VERIFICATION = '<!-- synabun:verification:start -->\nPackage verification: [downloadable VirusTotal reports and SHA-256 hashes](https://github.com/danilokhury/Synabun/releases/latest). Match the report to your exact version and file hash. Reports record engine coverage and analysis dates; they are not a guarantee of safety. Website results describe URL reputation, not a vulnerability audit.\n<!-- synabun:verification:end -->';
|
|
@@ -43,28 +54,38 @@ export async function* multipart(path, boundary) {
|
|
|
43
54
|
}
|
|
44
55
|
|
|
45
56
|
export class VirusTotal {
|
|
46
|
-
constructor({ key, fetchImpl = globalThis.fetch, sleep = delay, now = Date.now, intervalMs = 15500, requestMs = 120000,
|
|
57
|
+
constructor({ key, env = process.env, fetchImpl = globalThis.fetch, sleep = delay, now = Date.now, intervalMs = 15500, requestMs = 120000,
|
|
58
|
+
uploadMs = scanMinutes(env.SYNABUN_VT_UPLOAD_MINUTES, 15, 'SYNABUN_VT_UPLOAD_MINUTES') * 60000,
|
|
59
|
+
scanMs = scanMinutes(env.SYNABUN_VT_SCAN_MINUTES, 15, 'SYNABUN_VT_SCAN_MINUTES') * 60000,
|
|
60
|
+
largeScanMs = scanMinutes(env.SYNABUN_VT_LARGE_SCAN_MINUTES, 15, 'SYNABUN_VT_LARGE_SCAN_MINUTES') * 60000,
|
|
61
|
+
largeFileBytes = LARGE_FILE, pollMs = 30000, retries = 3 } = {}) {
|
|
47
62
|
this.key = credentials(key); this.fetch = fetchImpl; this.sleep = sleep; this.now = now;
|
|
48
|
-
Object.
|
|
63
|
+
for (const [name, value] of Object.entries({ scanMs, largeScanMs, uploadMs, pollMs })) if (!Number.isFinite(value) || value <= 0) throw new Error(`VirusTotal ${name} must be a positive number`);
|
|
64
|
+
Object.assign(this, { intervalMs, requestMs, uploadMs, scanMs, largeScanMs, largeFileBytes, pollMs, retries }); this.nextRequest = 0; this.queue = Promise.resolve();
|
|
49
65
|
}
|
|
50
|
-
|
|
51
|
-
|
|
66
|
+
/** The analysis deadline for one file (it starts once the upload is done): large files get the longer one, never a shorter one. */
|
|
67
|
+
scanMsFor(size) { return size > this.largeFileBytes ? Math.max(this.scanMs, this.largeScanMs) : this.scanMs; }
|
|
68
|
+
/** How many polls fit before `until`; bounds every waiting loop even if the clock stalls. */
|
|
69
|
+
pollLimit(until) { return Math.min(10000, Math.max(1, Math.ceil((until - this.now()) / this.pollMs) + 1)); }
|
|
70
|
+
/** `phase` names the clock in the error: 'upload' (lookup, upload URL, upload) or 'analysis'. */
|
|
71
|
+
async wait(ms, deadline, phase = 'analysis') {
|
|
72
|
+
if (this.now() + ms >= deadline) throw new Error(`VirusTotal ${phase} deadline exceeded; retry the same bytes later`);
|
|
52
73
|
if (ms > 0) await this.sleep(ms);
|
|
53
74
|
}
|
|
54
|
-
async pace(deadline) {
|
|
75
|
+
async pace(deadline, phase = 'analysis') {
|
|
55
76
|
// Reserve request starts serially, even when library callers scan concurrently.
|
|
56
77
|
const turn = this.queue.then(async () => {
|
|
57
|
-
await this.wait(Math.max(0, this.nextRequest - this.now()), deadline);
|
|
58
|
-
if (this.now() >= deadline) throw new Error(
|
|
78
|
+
await this.wait(Math.max(0, this.nextRequest - this.now()), deadline, phase);
|
|
79
|
+
if (this.now() >= deadline) throw new Error(`VirusTotal ${phase} deadline exceeded`);
|
|
59
80
|
this.nextRequest = this.now() + this.intervalMs;
|
|
60
81
|
});
|
|
61
82
|
this.queue = turn.catch(() => {});
|
|
62
83
|
await turn;
|
|
63
84
|
}
|
|
64
|
-
async request(path, { method = 'GET', body, headers = {}, deadline = this.now() + this.scanMs, notFound = false, timeoutMs = this.requestMs } = {}) {
|
|
85
|
+
async request(path, { method = 'GET', body, headers = {}, deadline = this.now() + this.scanMs, phase = 'analysis', notFound = false, timeoutMs = this.requestMs } = {}) {
|
|
65
86
|
const url = trustedUrl(path.startsWith('https:') ? path : API + path);
|
|
66
87
|
for (let attempt = 0; attempt <= this.retries; attempt++) {
|
|
67
|
-
await this.pace(deadline);
|
|
88
|
+
await this.pace(deadline, phase);
|
|
68
89
|
let response;
|
|
69
90
|
let payload;
|
|
70
91
|
try {
|
|
@@ -80,59 +101,126 @@ export class VirusTotal {
|
|
|
80
101
|
}
|
|
81
102
|
payload = Buffer.concat(chunks).toString('utf8');
|
|
82
103
|
} catch {
|
|
104
|
+
if (this.now() >= deadline) throw new Error(`VirusTotal ${phase} deadline exceeded; retry the same bytes later`);
|
|
83
105
|
if (attempt === this.retries) throw new Error('VirusTotal request failed or timed out; no verdict available');
|
|
84
|
-
await this.wait(1000 * 2 ** attempt, deadline); continue;
|
|
106
|
+
await this.wait(1000 * 2 ** attempt, deadline, phase); continue;
|
|
85
107
|
}
|
|
86
108
|
if (response.status === 404 && notFound) return null;
|
|
87
109
|
if (response.status === 429 || response.status >= 500) {
|
|
88
110
|
if (attempt === this.retries) throw new Error(`VirusTotal HTTP ${response.status}; retry budget exhausted`);
|
|
89
111
|
const retry = response.headers.get('retry-after');
|
|
90
112
|
const ms = retry && /^\d+(\.\d+)?$/.test(retry) ? Number(retry) * 1000 : retry ? Date.parse(retry) - this.now() : 1000 * 2 ** attempt;
|
|
91
|
-
await this.wait(Math.max(1000, Number.isFinite(ms) ? ms : 1000), deadline); continue;
|
|
113
|
+
await this.wait(Math.max(1000, Number.isFinite(ms) ? ms : 1000), deadline, phase); continue;
|
|
92
114
|
}
|
|
93
|
-
if (!response.ok) throw new Error(`VirusTotal HTTP ${response.status}; no verdict available`);
|
|
115
|
+
if (!response.ok) throw Object.assign(new Error(`VirusTotal HTTP ${response.status}; no verdict available`), { status: response.status });
|
|
94
116
|
try { return JSON.parse(payload); } catch { throw new Error('VirusTotal returned invalid JSON'); }
|
|
95
117
|
}
|
|
96
118
|
}
|
|
97
|
-
|
|
119
|
+
/**
|
|
120
|
+
* Polls analyses/{id}. A 404 there is an analysis VirusTotal has accepted but
|
|
121
|
+
* does not show yet (a large upload takes a while to appear): it counts as
|
|
122
|
+
* queued. With `settle` the poll stops at `until` and returns null, so the
|
|
123
|
+
* caller can look at the file object instead; without it, it throws.
|
|
124
|
+
*/
|
|
125
|
+
async poll(id, deadline, { until = deadline, settle = false } = {}) {
|
|
98
126
|
if (typeof id !== 'string' || !id) throw new Error('VirusTotal did not return an analysis ID');
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const
|
|
127
|
+
const limit = this.pollLimit(until);
|
|
128
|
+
for (let count = 0; count < limit; count++) {
|
|
129
|
+
const result = await this.request(`analyses/${encodeURIComponent(id)}`, { deadline, notFound: true });
|
|
130
|
+
const status = result === null ? 'queued' : result?.data?.attributes?.status;
|
|
102
131
|
if (status === 'completed') return result;
|
|
103
132
|
if (!['queued', 'in-progress'].includes(status)) throw new Error('VirusTotal returned an unknown analysis status');
|
|
133
|
+
if (this.now() + this.pollMs >= until) break;
|
|
134
|
+
await this.wait(this.pollMs, deadline);
|
|
135
|
+
}
|
|
136
|
+
if (settle) return null;
|
|
137
|
+
throw new Error(`VirusTotal analysis unfinished after ${limit} polls; retry later`);
|
|
138
|
+
}
|
|
139
|
+
/** The file object, identity-checked; null while VirusTotal does not have it. */
|
|
140
|
+
async fileObject(sha256, deadline, phase = 'analysis') {
|
|
141
|
+
const object = await this.request(`files/${sha256}`, { deadline, phase, notFound: true });
|
|
142
|
+
if (object && (object.data?.id !== sha256 || object.data?.attributes?.sha256 !== sha256)) throw new Error('VirusTotal file SHA-256 mismatch');
|
|
143
|
+
return object;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Waits on files/{sha256} until it carries a fresh analysis (the same fresh()
|
|
147
|
+
* rule and evidence checks as a cached verdict). Used when VirusTotal says the
|
|
148
|
+
* file is already submitted (409), when an analysis never showed as completed,
|
|
149
|
+
* and when the object exists but is still being analysed. Returns null at
|
|
150
|
+
* `until`; past `deadline` it throws like every other wait.
|
|
151
|
+
*/
|
|
152
|
+
async awaitFile(subject, deadline, { until = deadline, analysisId = null } = {}) {
|
|
153
|
+
const limit = this.pollLimit(until);
|
|
154
|
+
for (let count = 0; count < limit; count++) {
|
|
155
|
+
const a = (await this.fileObject(subject.sha256, deadline))?.data?.attributes;
|
|
156
|
+
if (a && this.fresh(a.last_analysis_date)) return this.evidence(subject, a.last_analysis_stats, a.last_analysis_results, a.last_analysis_date, 'awaited', analysisId);
|
|
157
|
+
if (this.now() + this.pollMs >= until) break;
|
|
104
158
|
await this.wait(this.pollMs, deadline);
|
|
105
159
|
}
|
|
106
|
-
|
|
160
|
+
return null;
|
|
107
161
|
}
|
|
108
162
|
async file(path, expectedHash) {
|
|
109
163
|
const size = (await stat(path)).size;
|
|
110
164
|
if (size > UPLOAD_LIMIT) throw new Error(`VirusTotal 650 MB upload limit exceeded: ${basename(path)}`);
|
|
111
165
|
const sha256 = await hashFile(path);
|
|
112
166
|
if (expectedHash && sha256 !== expectedHash) throw new Error(`SHA-256 mismatch: ${basename(path)}`);
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
167
|
+
// Two clocks, one after the other, so the wall time of a file is at most uploadMs + scanMsFor(size):
|
|
168
|
+
// - the upload clock (uploadMs) runs from here and covers what comes before VirusTotal has the
|
|
169
|
+
// bytes: the files/{sha} lookup, files/upload_url, the upload POST (or files/{sha}/analyse),
|
|
170
|
+
// their pace() turns and retries. The upload request's timeout is what is left of it.
|
|
171
|
+
// - the analysis clock (scanMsFor(size)) starts when that phase ends: right after the lookup when
|
|
172
|
+
// the object is cached without an analysis date (it is awaited, and a reanalysis asked for after
|
|
173
|
+
// that runs on the analysis clock already started), else when the upload or analyse POST answers,
|
|
174
|
+
// 409 AlreadySubmitted included. It covers the polls, the settle fallback and awaitFile.
|
|
175
|
+
const budget = this.scanMsFor(size);
|
|
176
|
+
const uploadDeadline = this.now() + this.uploadMs;
|
|
177
|
+
let deadline = null, settle = null;
|
|
178
|
+
const startAnalysis = () => {
|
|
179
|
+
if (deadline !== null) return;
|
|
180
|
+
deadline = this.now() + budget;
|
|
181
|
+
// The last quarter of the deadline is kept for the file object, whatever the analysis did.
|
|
182
|
+
settle = deadline - Math.floor(budget / 4);
|
|
183
|
+
};
|
|
184
|
+
const before = () => deadline === null ? { deadline: uploadDeadline, phase: 'upload' } : { deadline, phase: 'analysis' };
|
|
185
|
+
const subject = { kind: 'file', name: basename(path), sha256, size };
|
|
186
|
+
const cached = await this.fileObject(sha256, uploadDeadline, 'upload');
|
|
116
187
|
const a = cached?.data?.attributes;
|
|
117
|
-
|
|
188
|
+
let report = null;
|
|
118
189
|
if (cached && this.fresh(a?.last_analysis_date)) {
|
|
119
|
-
report = this.evidence(
|
|
190
|
+
report = this.evidence(subject, a.last_analysis_stats, a.last_analysis_results, a.last_analysis_date, 'cached');
|
|
120
191
|
} else {
|
|
121
|
-
|
|
122
|
-
if (cached)
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
192
|
+
// An object without an analysis date is still being analysed: wait for it before asking again.
|
|
193
|
+
if (cached && a?.last_analysis_date == null) { startAnalysis(); report = await this.awaitFile(subject, deadline, { until: settle }); }
|
|
194
|
+
if (!report) {
|
|
195
|
+
let analysis = null;
|
|
196
|
+
try {
|
|
197
|
+
if (cached) analysis = await this.request(`files/${sha256}/analyse`, { method: 'POST', ...before() });
|
|
198
|
+
else {
|
|
199
|
+
const upload = size > DIRECT_LIMIT ? (await this.request('files/upload_url', before()))?.data : API + 'files';
|
|
200
|
+
if (typeof upload !== 'string') throw new Error('VirusTotal did not return an upload URL');
|
|
201
|
+
const boundary = `synabun-${sha256}`;
|
|
202
|
+
const head = `--${boundary}\r\nContent-Disposition: form-data; name="file"; filename="${safeName(basename(path))}"\r\nContent-Type: application/octet-stream\r\n\r\n`;
|
|
203
|
+
const tail = `\r\n--${boundary}--\r\n`;
|
|
204
|
+
analysis = await this.request(upload, { method: 'POST', ...before(), timeoutMs: this.uploadMs, body: () => multipart(path, boundary),
|
|
205
|
+
headers: { 'content-type': `multipart/form-data; boundary=${boundary}`, 'content-length': String(Buffer.byteLength(head) + size + Buffer.byteLength(tail)) } });
|
|
206
|
+
}
|
|
207
|
+
} catch (error) {
|
|
208
|
+
// 409 AlreadySubmitted: these bytes are already being analysed. Never upload again; wait for the file object.
|
|
209
|
+
if (error.status !== 409) throw error;
|
|
210
|
+
}
|
|
211
|
+
startAnalysis();
|
|
212
|
+
const analysisId = analysis ? analysis.data?.id : null;
|
|
213
|
+
if (analysis && (typeof analysisId !== 'string' || !analysisId)) throw new Error('VirusTotal did not return an analysis ID');
|
|
214
|
+
const result = analysisId ? await this.poll(analysisId, deadline, { until: settle, settle: true }) : null;
|
|
215
|
+
if (result) {
|
|
216
|
+
if (result.meta?.file_info?.sha256 !== sha256) throw new Error('VirusTotal analysis SHA-256 mismatch');
|
|
217
|
+
const attrs = result.data.attributes;
|
|
218
|
+
report = this.evidence(subject, attrs.stats, attrs.results, attrs.date, cached ? 'reanalysed' : 'uploaded', analysisId);
|
|
219
|
+
} else {
|
|
220
|
+
report = await this.awaitFile(subject, deadline, { analysisId });
|
|
221
|
+
if (!report) throw new Error('VirusTotal analysis unfinished before the deadline; retry the same bytes later');
|
|
222
|
+
}
|
|
131
223
|
}
|
|
132
|
-
const result = await this.poll(analysis?.data?.id, deadline);
|
|
133
|
-
if (result.meta?.file_info?.sha256 !== sha256) throw new Error('VirusTotal analysis SHA-256 mismatch');
|
|
134
|
-
const attrs = result.data.attributes;
|
|
135
|
-
report = this.evidence({ kind: 'file', name: basename(path), sha256, size }, attrs.stats, attrs.results, attrs.date, cached ? 'reanalysed' : 'uploaded', analysis.data.id);
|
|
136
224
|
}
|
|
137
225
|
if (await hashFile(path) !== sha256 || (await stat(path)).size !== size) throw new Error(`Artifact changed during scanning: ${basename(path)}`);
|
|
138
226
|
return report;
|
|
@@ -189,15 +277,33 @@ export function applyReviews(items, reviews = [], now = Date.now()) {
|
|
|
189
277
|
return { ...item, review: { reviewer: review.reviewer, reason: review.reason, reference: review.reference, reviewed_at: review.reviewed_at, expires_at: review.expires_at } };
|
|
190
278
|
});
|
|
191
279
|
}
|
|
192
|
-
export const
|
|
280
|
+
export const EQUIVALENT_TO_CLEAN = 'equivalent-to-clean';
|
|
281
|
+
/**
|
|
282
|
+
* A macOS dmg VirusTotal gave no verdict for passes only as 'equivalent-to-clean':
|
|
283
|
+
* the release gate found its .app byte-identical to the .app of the same-arch zip,
|
|
284
|
+
* and that zip, by the exact name and SHA-256 recorded, is in the same report
|
|
285
|
+
* with no detections (an owner-reviewed detection does not count).
|
|
286
|
+
*/
|
|
287
|
+
export function equivalentToClean(item, items) {
|
|
288
|
+
const e = item?.equivalence, zip = e?.matched_zip;
|
|
289
|
+
if (item?.status !== EQUIVALENT_TO_CLEAN || item.kind !== 'file' || !/\.dmg$/.test(item.name ?? '') || !/^[a-f0-9]{64}$/.test(item.sha256 ?? '')) return false;
|
|
290
|
+
if (!zip || typeof zip.name !== 'string' || zip.name !== item.name.replace(/\.dmg$/, '.zip') || !/^[a-f0-9]{64}$/.test(zip.sha256 ?? '')) return false;
|
|
291
|
+
if (!/^[a-f0-9]{64}$/.test(e.app_manifest_digest ?? '') || !Number.isInteger(e.file_count) || e.file_count < 1) return false;
|
|
292
|
+
return items.some(other => other.kind === 'file' && other.name === zip.name && other.sha256 === zip.sha256 && other.status === 'no-detections');
|
|
293
|
+
}
|
|
294
|
+
export const approved = items => items.length > 0 && items.every(item => item.status === 'no-detections' || (item.status === 'detections' && item.review) || equivalentToClean(item, items));
|
|
193
295
|
const md = value => String(value).replace(/[|\r\n<>`\[\]\\]/g, ' ');
|
|
194
296
|
export function reports(items) {
|
|
195
297
|
const sorted = [...items].sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
196
|
-
const report = { schema: 1, policy: { minimum_file_engines: 10, minimum_url_engines: 20, max_age_days: 7
|
|
298
|
+
const report = { schema: 1, policy: { minimum_file_engines: 10, minimum_url_engines: 20, max_age_days: 7,
|
|
299
|
+
dmg_without_verdict: 'accepted only as equivalent-to-clean: its .app is byte-identical to the .app of the same-arch zip, which has no detections in this report' }, approved: approved(sorted), items: sorted };
|
|
197
300
|
const markdown = ['## VirusTotal verification', '', 'Match the exact file and SHA-256. Results describe engine detections and coverage at the analysis date, not a guarantee of safety. Website results describe URL reputation, not a vulnerability audit.', '',
|
|
198
|
-
|
|
199
|
-
|
|
301
|
+
// Five short columns, so the table reads on GitHub; the 64-character hashes go in a code block below it.
|
|
302
|
+
'| File or URL | Status | Engines | Analysis date | Report |', '| --- | --- | --- | --- | --- |',
|
|
303
|
+
...sorted.map(i => `| ${md(i.name)} | ${i.status}${i.review ? ' (owner reviewed)' : ''}${i.status === EQUIVALENT_TO_CLEAN ? ' (no VirusTotal verdict; see below)' : ''} | ${i.supported_engines ?? 0} / ${i.total_engines ?? 0} | ${md(i.analysis_date ?? 'unavailable')} | ${i.permalink ? `[VirusTotal](${i.permalink})` : 'unavailable'} |`), '',
|
|
304
|
+
...(sorted.some(i => i.sha256) ? ['SHA-256 of each file (as in `SHA256SUMS`):', '', '```', ...sorted.filter(i => i.sha256).map(i => `${i.sha256} ${md(i.name)}`), '```', ''] : []),
|
|
200
305
|
...sorted.filter(i => i.review).map(i => `Review for ${md(i.name)} (${i.sha256}), evidence ${i.evidence_digest}: ${md(i.review.reviewer)}; ${md(i.review.reason)}; reference ${md(i.review.reference)}; expires ${md(i.review.expires_at)}.`),
|
|
306
|
+
...sorted.filter(i => i.status === EQUIVALENT_TO_CLEAN).map(i => `${md(i.name)} (${i.sha256}): no VirusTotal verdict (${md(i.virustotal_error ?? 'unavailable')}); app identical to clean-scanned ${md(i.equivalence?.matched_zip?.name)} (${md(i.equivalence?.matched_zip?.sha256)}): ${md(i.equivalence?.app)}, ${i.equivalence?.file_count} entries, app tree digest ${md(i.equivalence?.app_manifest_digest)}.`),
|
|
201
307
|
...sorted.filter(i => i.error).map(i => `${md(i.name)}: ${md(i.error)}`), ''].join('\n');
|
|
202
308
|
return { json: JSON.stringify(report, null, 2) + '\n', markdown, report };
|
|
203
309
|
}
|
|
@@ -27,14 +27,71 @@ export interface McpRoutesOptions {
|
|
|
27
27
|
* answers, the session has exactly that selection and X-Synabun-Tools is ignored.
|
|
28
28
|
*/
|
|
29
29
|
selectionFor?: (req: Request) => McpSessionSelection | null | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* The host's check of a run's pin (the Neural Interface's terminal tokens, neural-interface/lib/terminal-tokens.js):
|
|
32
|
+
* true when this request may route as `pin` with the X-Synabun-Terminal-Token it carries (`token`, or null). A pin
|
|
33
|
+
* it refuses (a run SynaBun gave a token to, named without that token) is not this caller's: the request routes as
|
|
34
|
+
* its own MCP session, so it never shares that run's identity (its browser pins, its recovered tab) and never sends
|
|
35
|
+
* the run's id to the Neural Interface. Without it, every pin is taken as it is said (the standalone server).
|
|
36
|
+
*/
|
|
37
|
+
terminalAuth?: (pin: string, token: string | null) => boolean;
|
|
38
|
+
/**
|
|
39
|
+
* The host's proof for a plain MCP session (neural-interface/lib/terminal-tokens.js issueSession / revokeSession):
|
|
40
|
+
* a CLI window's Claude Code or Codex that SynaBun did not start names no run, so its id to the Neural Interface is
|
|
41
|
+
* its Mcp-Session-Id. `issue` is asked once, when such a session initializes from this computer (loopback, no pin,
|
|
42
|
+
* not through the tunnel), and the session then sends its proof with its id on every Neural Interface request it
|
|
43
|
+
* makes (callerTerminalToken), so no other process can act as it there, and the Neural Interface can let it pick its
|
|
44
|
+
* own MoreLogin profile (`morelogin` `use`). The proof never leaves this process: it is not sent to the MCP client.
|
|
45
|
+
* `revoke` is called when the session closes or is evicted. Without it (the standalone server, the worker-only
|
|
46
|
+
* channel) a plain session has no proof, as before.
|
|
47
|
+
* `eligible` is the host's own answer for the initializing request, asked after wantsSessionProof and before
|
|
48
|
+
* `issue`: the Neural Interface says yes only on its plain /mcp mount (never /mcp/<key>, which shares this router),
|
|
49
|
+
* for a request that is not from outside by its own rules and whose peer process is not a relay or a proxy (review
|
|
50
|
+
* b6631e9d, finding 5: a loopback socket without CF-Connecting-IP is also what a local reverse proxy in front of the
|
|
51
|
+
* keyed mount looks like). A host that gives `issue` without `eligible` gets no proof issued: fail closed.
|
|
52
|
+
*/
|
|
53
|
+
sessionProof?: {
|
|
54
|
+
issue: (sessionId: string) => string | null;
|
|
55
|
+
revoke: (sessionId: string) => void;
|
|
56
|
+
eligible?: (req: Request) => boolean;
|
|
57
|
+
};
|
|
30
58
|
}
|
|
31
59
|
/**
|
|
32
60
|
* A session's tools, decided once, at initialize: the resolver's answer (strict), else the X-Synabun-Tools header
|
|
33
61
|
* (focus only: it steers the instructions, never what the session can reach), else focus on every group.
|
|
34
62
|
*/
|
|
35
63
|
export declare function sessionSelection(req: Request, options?: McpRoutesOptions): ToolSelection;
|
|
64
|
+
/**
|
|
65
|
+
* What proves this request's X-Synabun-Terminal pin: its X-Synabun-Terminal-Token, else (an Assistant brain, whose pin
|
|
66
|
+
* the Neural Interface binds to its launch credential) its X-Synabun-Brain-Token. None for a tunnel caller (a remote
|
|
67
|
+
* MCP-key holder) or a malformed one.
|
|
68
|
+
*/
|
|
69
|
+
export declare function requestTerminalToken(req: Pick<Request, 'get'>): string | null;
|
|
70
|
+
/**
|
|
71
|
+
* The X-Synabun-Terminal pin this request may route as: the header's, unless the host's terminalAuth refuses it (a
|
|
72
|
+
* run's pin without that run's token, or a check that threw: fail closed), then none.
|
|
73
|
+
*/
|
|
74
|
+
export declare function acceptedTerminalPin(req: Pick<Request, 'get'>, options?: McpRoutesOptions): string | null;
|
|
36
75
|
/** The X-Synabun-Brain-Token of one request (whatsapp_send_file); none for a tunnel caller (a remote MCP-key holder). */
|
|
37
76
|
export declare function requestBrainCredential(req: Pick<Request, 'get'>): string | null;
|
|
77
|
+
/**
|
|
78
|
+
* Whether a session initializing with `req` may get the host's proof (McpRoutesOptions.sessionProof): no accepted
|
|
79
|
+
* pin (a run or a panel routes as its pin and proves it with its own token), from this computer's loopback, and not
|
|
80
|
+
* through the tunnel (a remote MCP-key holder).
|
|
81
|
+
*/
|
|
82
|
+
export declare function wantsSessionProof(req: Pick<Request, 'get'> & {
|
|
83
|
+
socket?: {
|
|
84
|
+
remoteAddress?: string;
|
|
85
|
+
};
|
|
86
|
+
}, pin: string | null): boolean;
|
|
87
|
+
/** The host's own check of the initializing request (McpRoutesOptions.sessionProof.eligible): absent or failing is no. */
|
|
88
|
+
export declare function hostAllowsSessionProof(req: Request, options: McpRoutesOptions): boolean;
|
|
89
|
+
/**
|
|
90
|
+
* A session id as the log shows it: its first 8 characters. The Mcp-Session-Id is all a client needs to send requests
|
|
91
|
+
* on a session (the SDK checks nothing else), and a session with a proof can pick its MoreLogin profile, so the whole
|
|
92
|
+
* id is a bearer and never goes to stderr (which the background launch writes to launcher.log; review b6631e9d, note 8).
|
|
93
|
+
*/
|
|
94
|
+
export declare function sessionLogId(sid: string | undefined | null): string;
|
|
38
95
|
/**
|
|
39
96
|
* Initialize DB, categories, and warm up the embedding model.
|
|
40
97
|
* Safe to call multiple times — only runs once.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;;;;;GAcG;AAGH,OAAgB,EAAE,KAAK,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,SAAS,CAAC;AAU7D,OAAO,EAA0C,KAAK,QAAQ,EAAE,KAAK,aAAa,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;;;;;GAcG;AAGH,OAAgB,EAAE,KAAK,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,SAAS,CAAC;AAU7D,OAAO,EAA0C,KAAK,QAAQ,EAAE,KAAK,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAyCvH,mGAAmG;AACnG,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1B,IAAI,CAAC,EAAE,QAAQ,CAAC;CACjB;AAED,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,mBAAmB,GAAG,IAAI,GAAG,SAAS,CAAC;IACxE;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,KAAK,OAAO,CAAC;IAC9D;;;;;;;;;;;;;;OAcG;IACH,YAAY,CAAC,EAAE;QAAE,KAAK,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC;QAAC,MAAM,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;QAAC,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAA;KAAE,CAAC;CAC3I;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,GAAE,gBAAqB,GAAG,aAAa,CAsB5F;AA2CD;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,GAAG,MAAM,GAAG,IAAI,CAG7E;AAGD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE,OAAO,GAAE,gBAAqB,GAAG,MAAM,GAAG,IAAI,CAc5G;AA6CD,yHAAyH;AACzH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,GAAG,MAAM,GAAG,IAAI,CAE/E;AAuBD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,GAAG;IAAE,MAAM,CAAC,EAAE;QAAE,aAAa,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAKlI;AAED,0HAA0H;AAC1H,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAIvF;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,MAAM,CAGnE;AAMD;;;;GAIG;AACH,wBAAsB,UAAU,kBAU/B;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,OAAO,GAAE,gBAAqB,GAAG,MAAM,CAmItE"}
|
package/mcp-server/dist/http.js
CHANGED
|
@@ -25,7 +25,7 @@ import { createMcpServer, refreshServerSchemas, onSchemaRefresh, setServerRole,
|
|
|
25
25
|
import { ToolListRefreshBarrier } from './services/tool-list-refresh-barrier.js';
|
|
26
26
|
import { selectionFromList, unreadableSelection } from './services/tool-runtime.js';
|
|
27
27
|
import { TOOL_LIST_LIMITS } from './services/tool-catalog.js';
|
|
28
|
-
import { markHttpMode, obtainIdentity, sanitizeBrainCredential, sanitizeDesktopGrant, sanitizePin, sanitizeRole, runWithBrainCredential, runWithIdentity, releaseIdentity, startIdentitySweeper, } from './services/identity.js';
|
|
28
|
+
import { markHttpMode, obtainIdentity, sanitizeBrainCredential, sanitizeDesktopGrant, sanitizePin, sanitizeRole, sanitizeTerminalToken, runWithBrainCredential, runWithIdentity, runWithTerminalToken, releaseIdentity, startIdentitySweeper, } from './services/identity.js';
|
|
29
29
|
let initialized = false;
|
|
30
30
|
let initPromise = null;
|
|
31
31
|
// Warm-server pool: registering 100+ tools (with Zod schema construction)
|
|
@@ -78,6 +78,8 @@ export function sessionSelection(req, options = {}) {
|
|
|
78
78
|
return selection.listError ? { ...selection, mode: 'focus', hostMode: 'focus' } : selection;
|
|
79
79
|
}
|
|
80
80
|
const mcpSessions = new Map();
|
|
81
|
+
/** sid → the host's revoke for the proof it gave that session (the router that initialized it), or null. */
|
|
82
|
+
const revokeProof = new Map();
|
|
81
83
|
const MCP_SESSION_TTL_MS = parseInt(process.env.SYNABUN_MCP_SESSION_TTL_MS || '', 10) || 60 * 60 * 1000;
|
|
82
84
|
let sessionSweeperStarted = false;
|
|
83
85
|
function startSessionSweeper() {
|
|
@@ -88,7 +90,7 @@ function startSessionSweeper() {
|
|
|
88
90
|
const now = Date.now();
|
|
89
91
|
for (const [sid, entry] of mcpSessions) {
|
|
90
92
|
if (now - entry.lastSeen > MCP_SESSION_TTL_MS) {
|
|
91
|
-
console.error(`[mcp-http] session ${sid} evicted after ${Math.round((now - entry.lastSeen) / 60000)}min idle (${mcpSessions.size - 1} remain)`);
|
|
93
|
+
console.error(`[mcp-http] session ${sessionLogId(sid)} evicted after ${Math.round((now - entry.lastSeen) / 60000)}min idle (${mcpSessions.size - 1} remain)`);
|
|
92
94
|
// transport.close() fires onclose → map cleanup + releaseIdentity + server.close.
|
|
93
95
|
try {
|
|
94
96
|
entry.transport.close();
|
|
@@ -111,12 +113,52 @@ onSchemaRefresh(() => {
|
|
|
111
113
|
catch { /* per-session best-effort */ }
|
|
112
114
|
}
|
|
113
115
|
});
|
|
116
|
+
/**
|
|
117
|
+
* What proves this request's X-Synabun-Terminal pin: its X-Synabun-Terminal-Token, else (an Assistant brain, whose pin
|
|
118
|
+
* the Neural Interface binds to its launch credential) its X-Synabun-Brain-Token. None for a tunnel caller (a remote
|
|
119
|
+
* MCP-key holder) or a malformed one.
|
|
120
|
+
*/
|
|
121
|
+
export function requestTerminalToken(req) {
|
|
122
|
+
if (req.get('cf-connecting-ip'))
|
|
123
|
+
return null;
|
|
124
|
+
return sanitizeTerminalToken(req.get('x-synabun-terminal-token')) ?? sanitizeBrainCredential(req.get('x-synabun-brain-token'));
|
|
125
|
+
}
|
|
126
|
+
const refusedPinsLogged = new Set();
|
|
127
|
+
/**
|
|
128
|
+
* The X-Synabun-Terminal pin this request may route as: the header's, unless the host's terminalAuth refuses it (a
|
|
129
|
+
* run's pin without that run's token, or a check that threw: fail closed), then none.
|
|
130
|
+
*/
|
|
131
|
+
export function acceptedTerminalPin(req, options = {}) {
|
|
132
|
+
const pin = sanitizePin(req.get('x-synabun-terminal'));
|
|
133
|
+
if (!pin || typeof options.terminalAuth !== 'function')
|
|
134
|
+
return pin;
|
|
135
|
+
let accepted = false;
|
|
136
|
+
try {
|
|
137
|
+
accepted = options.terminalAuth(pin, requestTerminalToken(req)) === true;
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
accepted = false;
|
|
141
|
+
}
|
|
142
|
+
if (accepted)
|
|
143
|
+
return pin;
|
|
144
|
+
if (!refusedPinsLogged.has(pin)) {
|
|
145
|
+
refusedPinsLogged.add(pin);
|
|
146
|
+
if (refusedPinsLogged.size > 1000)
|
|
147
|
+
refusedPinsLogged.delete(refusedPinsLogged.values().next().value);
|
|
148
|
+
// Finding 4 (re-review of 2026-11-11): the refused value may be a live Mcp-Session-Id (a bearer for that session),
|
|
149
|
+
// so the log line carries its short form only, never the whole value.
|
|
150
|
+
console.error(`[mcp-http] X-Synabun-Terminal ${sessionLogId(pin)} came without that run's terminal token: routed as its own MCP session`);
|
|
151
|
+
}
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
114
154
|
/**
|
|
115
155
|
* Per-request caller identity. Explicit X-Synabun-* headers (injected into the
|
|
116
156
|
* launch config of loops, scheduled loops, and sidepanel sessions) win; plain
|
|
117
|
-
* CLI windows fall back to their unique Mcp-Session-Id.
|
|
157
|
+
* CLI windows fall back to their unique Mcp-Session-Id. A pin the host's
|
|
158
|
+
* terminalAuth refused (`pin` null) counts as no pin, and so do the browser
|
|
159
|
+
* pins that came with it.
|
|
118
160
|
*/
|
|
119
|
-
function deriveIdentity(req, sid) {
|
|
161
|
+
function deriveIdentity(req, sid, pin = sanitizePin(req.get('x-synabun-terminal'))) {
|
|
120
162
|
const memoryContext = {
|
|
121
163
|
project: req.get('x-synabun-project')?.slice(0, 200),
|
|
122
164
|
session: req.get('x-synabun-memory-session')?.slice(0, 200),
|
|
@@ -129,7 +171,7 @@ function deriveIdentity(req, sid) {
|
|
|
129
171
|
const remote = !!req.get('cf-connecting-ip');
|
|
130
172
|
const role = remote ? null : sanitizeRole(req.get('x-synabun-role'));
|
|
131
173
|
const desktopGrant = remote ? null : sanitizeDesktopGrant(req.get('x-synabun-desktop-grant'));
|
|
132
|
-
const headerTerminal =
|
|
174
|
+
const headerTerminal = pin;
|
|
133
175
|
if (headerTerminal) {
|
|
134
176
|
const identity = obtainIdentity(headerTerminal, {
|
|
135
177
|
source: 'header',
|
|
@@ -156,11 +198,56 @@ export function requestBrainCredential(req) {
|
|
|
156
198
|
return req.get('cf-connecting-ip') ? null : sanitizeBrainCredential(req.get('x-synabun-brain-token'));
|
|
157
199
|
}
|
|
158
200
|
/**
|
|
159
|
-
* Handle one request inside its caller identity and its own
|
|
160
|
-
* X-Synabun-
|
|
201
|
+
* Handle one request inside its caller identity and its own credential contexts: the X-Synabun-Brain-Token and the
|
|
202
|
+
* X-Synabun-Terminal-Token of THIS request (the latter only with the pin it came with, which the host accepted),
|
|
203
|
+
* never one another request left on a shared identity.
|
|
204
|
+
*/
|
|
205
|
+
function runRequest(req, sid, options, fn) {
|
|
206
|
+
const pin = acceptedTerminalPin(req, options);
|
|
207
|
+
const token = pin ? requestTerminalToken(req) : null;
|
|
208
|
+
// A plain session (no accepted pin) routes as its Mcp-Session-Id: the proof the host gave that id at its initialize
|
|
209
|
+
// goes with it. Only the session's own transport (this sid, which the SDK checked) ever carries it.
|
|
210
|
+
const own = !pin && sid ? sessionProofGrant(sid) : null;
|
|
211
|
+
return runWithTerminalToken(pin && token ? { terminal: pin, token } : own, () => runWithBrainCredential(requestBrainCredential(req), () => runWithIdentity(deriveIdentity(req, sid, pin), fn)));
|
|
212
|
+
}
|
|
213
|
+
/** The proof of plain session `sid` as a grant for its own id, or null. */
|
|
214
|
+
function sessionProofGrant(sid) {
|
|
215
|
+
const proof = mcpSessions.get(sid)?.proof;
|
|
216
|
+
return proof ? { terminal: sid, token: proof } : null;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Whether a session initializing with `req` may get the host's proof (McpRoutesOptions.sessionProof): no accepted
|
|
220
|
+
* pin (a run or a panel routes as its pin and proves it with its own token), from this computer's loopback, and not
|
|
221
|
+
* through the tunnel (a remote MCP-key holder).
|
|
222
|
+
*/
|
|
223
|
+
export function wantsSessionProof(req, pin) {
|
|
224
|
+
if (pin)
|
|
225
|
+
return false;
|
|
226
|
+
if (req.get('cf-connecting-ip'))
|
|
227
|
+
return false;
|
|
228
|
+
const addr = String(req.socket?.remoteAddress || '');
|
|
229
|
+
return /^(?:::ffff:)?127\.\d+\.\d+\.\d+$/.test(addr) || addr === '::1';
|
|
230
|
+
}
|
|
231
|
+
/** The host's own check of the initializing request (McpRoutesOptions.sessionProof.eligible): absent or failing is no. */
|
|
232
|
+
export function hostAllowsSessionProof(req, options) {
|
|
233
|
+
const eligible = options.sessionProof?.eligible;
|
|
234
|
+
if (typeof eligible !== 'function')
|
|
235
|
+
return false;
|
|
236
|
+
try {
|
|
237
|
+
return eligible(req) === true;
|
|
238
|
+
}
|
|
239
|
+
catch {
|
|
240
|
+
return false;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* A session id as the log shows it: its first 8 characters. The Mcp-Session-Id is all a client needs to send requests
|
|
245
|
+
* on a session (the SDK checks nothing else), and a session with a proof can pick its MoreLogin profile, so the whole
|
|
246
|
+
* id is a bearer and never goes to stderr (which the background launch writes to launcher.log; review b6631e9d, note 8).
|
|
161
247
|
*/
|
|
162
|
-
function
|
|
163
|
-
|
|
248
|
+
export function sessionLogId(sid) {
|
|
249
|
+
const text = String(sid || '');
|
|
250
|
+
return text.length > 8 ? `${text.slice(0, 8)}…` : text;
|
|
164
251
|
}
|
|
165
252
|
function jsonRpcError(res, status, code, message) {
|
|
166
253
|
res.status(status).json({ jsonrpc: '2.0', error: { code, message }, id: null });
|
|
@@ -217,7 +304,7 @@ export function createMcpRoutes(options = {}) {
|
|
|
217
304
|
res.once('finish', () => { if (res.statusCode === 200)
|
|
218
305
|
toolListBarriers.get(entry.server)?.listed(); });
|
|
219
306
|
}
|
|
220
|
-
await runRequest(req, sid, () => entry.transport.handleRequest(req, res, req.body));
|
|
307
|
+
await runRequest(req, sid, options, () => entry.transport.handleRequest(req, res, req.body));
|
|
221
308
|
return;
|
|
222
309
|
}
|
|
223
310
|
// New client — must be an initialize request.
|
|
@@ -231,9 +318,20 @@ export function createMcpRoutes(options = {}) {
|
|
|
231
318
|
const transport = new StreamableHTTPServerTransport({
|
|
232
319
|
sessionIdGenerator: () => randomUUID(),
|
|
233
320
|
onsessioninitialized: (newSid) => {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
321
|
+
// The pin the host accepted (terminalAuth): a refused one is no pin, here as on every later request.
|
|
322
|
+
const terminal = acceptedTerminalPin(req, options);
|
|
323
|
+
let proof = null;
|
|
324
|
+
if (options.sessionProof && wantsSessionProof(req, terminal) && hostAllowsSessionProof(req, options)) {
|
|
325
|
+
try {
|
|
326
|
+
proof = options.sessionProof.issue(newSid) || null;
|
|
327
|
+
}
|
|
328
|
+
catch {
|
|
329
|
+
proof = null;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
mcpSessions.set(newSid, { transport, server, lastSeen: Date.now(), proof });
|
|
333
|
+
revokeProof.set(newSid, proof && options.sessionProof ? options.sessionProof.revoke : null);
|
|
334
|
+
deriveIdentity(req, newSid, terminal);
|
|
237
335
|
// The warm server was built role-less, on focus. The SDK awaits this
|
|
238
336
|
// hook BEFORE dispatching the initialize request, so binding the
|
|
239
337
|
// selection and the role here makes the handshake instructions and
|
|
@@ -250,7 +348,7 @@ export function createMcpRoutes(options = {}) {
|
|
|
250
348
|
if (grant)
|
|
251
349
|
setServerCapabilities(server, { computer: true });
|
|
252
350
|
const tools = selection.source === 'http' ? '' : `, tools=${selection.mode}:${selection.groups.join(',') || 'memory'}${selection.listError ? ' (unreadable)' : ''}`;
|
|
253
|
-
console.error(`[mcp-http] session ${newSid} init (terminal=${terminal || 'none'}${role ? `, role=${role}` : ''}${grant ? ', computer' : ''}${tools}, sessions=${mcpSessions.size})`);
|
|
351
|
+
console.error(`[mcp-http] session ${sessionLogId(newSid)} init (terminal=${terminal || 'none'}${role ? `, role=${role}` : ''}${grant ? ', computer' : ''}${tools}, sessions=${mcpSessions.size})`);
|
|
254
352
|
},
|
|
255
353
|
});
|
|
256
354
|
// Re-entry guard: server.close() closes its transport, which fires
|
|
@@ -262,11 +360,23 @@ export function createMcpRoutes(options = {}) {
|
|
|
262
360
|
tornDown = true;
|
|
263
361
|
const closedSid = transport.sessionId;
|
|
264
362
|
if (closedSid && mcpSessions.has(closedSid)) {
|
|
363
|
+
// Its tab is released as the session itself (its proof, while it still holds one), then the proof stops
|
|
364
|
+
// working (the id stays refused: nobody can be this session afterwards). The host releases what the
|
|
365
|
+
// session still held in its revoke too, so a release that arrives after it is no loss.
|
|
366
|
+
const grant = sessionProofGrant(closedSid);
|
|
367
|
+
const revoke = revokeProof.get(closedSid);
|
|
368
|
+
revokeProof.delete(closedSid);
|
|
265
369
|
mcpSessions.delete(closedSid);
|
|
266
370
|
// Releases the identity's acquired browser tab (if any). Header-keyed
|
|
267
371
|
// identities (loops) are keyed by terminal id, not sid — untouched.
|
|
268
|
-
releaseIdentity(closedSid);
|
|
269
|
-
|
|
372
|
+
runWithTerminalToken(grant, () => releaseIdentity(closedSid));
|
|
373
|
+
if (revoke) {
|
|
374
|
+
try {
|
|
375
|
+
revoke(closedSid);
|
|
376
|
+
}
|
|
377
|
+
catch { /* the host's own failure */ }
|
|
378
|
+
}
|
|
379
|
+
console.error(`[mcp-http] session ${sessionLogId(closedSid)} closed (${mcpSessions.size} remain)`);
|
|
270
380
|
}
|
|
271
381
|
try {
|
|
272
382
|
server.close();
|
|
@@ -274,7 +384,7 @@ export function createMcpRoutes(options = {}) {
|
|
|
274
384
|
catch { /* already closed */ }
|
|
275
385
|
};
|
|
276
386
|
await server.connect(transport);
|
|
277
|
-
await runRequest(req, undefined, () => transport.handleRequest(req, res, req.body));
|
|
387
|
+
await runRequest(req, undefined, options, () => transport.handleRequest(req, res, req.body));
|
|
278
388
|
}
|
|
279
389
|
catch (error) {
|
|
280
390
|
console.error('MCP HTTP error:', error);
|
|
@@ -293,7 +403,7 @@ export function createMcpRoutes(options = {}) {
|
|
|
293
403
|
}
|
|
294
404
|
entry.lastSeen = Date.now();
|
|
295
405
|
try {
|
|
296
|
-
await runRequest(req, sid, () => entry.transport.handleRequest(req, res));
|
|
406
|
+
await runRequest(req, sid, options, () => entry.transport.handleRequest(req, res));
|
|
297
407
|
}
|
|
298
408
|
catch (error) {
|
|
299
409
|
console.error('MCP HTTP error:', error);
|