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/mcp-build.js
ADDED
|
@@ -0,0 +1,519 @@
|
|
|
1
|
+
// The MCP server's build after an install, an update or a pull: mcp-server/src compiled with TypeScript, so the
|
|
2
|
+
// running dist always matches the source on disk.
|
|
3
|
+
//
|
|
4
|
+
// - postinstall.js (every `npm i -g synabun`, `npm update -g`, the in-app updater's npm run, `npm install` in a
|
|
5
|
+
// checkout) builds always (`force`): an update is exactly when the shipped or old dist may not match.
|
|
6
|
+
// - setup.js (every launch, and before the supervisor starts the server again) builds when the stamp in dist says
|
|
7
|
+
// another version or another source built it: that is what catches a `git pull` on a clone.
|
|
8
|
+
// - The Neural Interface's POST /api/setup/build (the onboarding wizard) and the auto-build after POST
|
|
9
|
+
// /api/system/restore use the async entry (buildMcpServerSafelyAsync), so the server keeps answering while tsc runs.
|
|
10
|
+
// - A packaged application (`packaged: true`) has its dist built by the packaging (packaging/lib/stage.mjs writes
|
|
11
|
+
// the same stamp) and is replaced whole: it only asks whether its dist is whole, and never compiles.
|
|
12
|
+
//
|
|
13
|
+
// A build never leaves the user without a server: tsc writes into a fresh folder next to dist
|
|
14
|
+
// (mcp-server/.dist-build-<pid>-<time>), and only a build that exited 0 with every runtime entry of dist
|
|
15
|
+
// (lib/mcp-dist.js MCP_RUNTIME_ENTRIES: index.js, preload.js, preload-http.js) and every module they import present
|
|
16
|
+
// replaces dist. The swap renames the old dist aside (mcp-server/.dist-old-<pid>-<time>), renames the new one in, puts
|
|
17
|
+
// the old one back when the second rename fails, and removes the old one only after the swap succeeded. A build that
|
|
18
|
+
// is stopped between the two renames (or whose rollback failed) leaves dist missing and the old one aside: the next
|
|
19
|
+
// build puts that old one back before it does anything else (recoverDist), so a leftover is never the only good copy
|
|
20
|
+
// that a sweep removes. On any failure the previous dist stays as it was.
|
|
21
|
+
//
|
|
22
|
+
// One build at a time: every build holds mcp-server/.dist-build.lock (written whole to a temp file and linked into
|
|
23
|
+
// place, so it never exists empty; its owner's pid, token and start time inside) from before it sweeps until it
|
|
24
|
+
// swapped or gave up. A lock whose owner is gone, or older than LOCK_STALE_MS, is taken over through one exclusive
|
|
25
|
+
// claim per judged lock, and removed only when it is still the lock that was judged (tryBuildLock). A second builder waits up to `waitMs` (postinstall.js and setup.js wait; the Neural
|
|
26
|
+
// Interface's routes pass 0 and report `busy`). The sweep removes only temp and old folders no live build owns.
|
|
27
|
+
//
|
|
28
|
+
// The stamp (dist/.synabun-build.json) is the package version plus a SHA-256 over mcp-server/src, tsconfig.json and
|
|
29
|
+
// mcp-server/package.json: any change of version or source differs from it, so a check never skips a needed build.
|
|
30
|
+
//
|
|
31
|
+
// Nothing here throws for a build problem: every entry returns { status: 'failed', reason, output } instead, because
|
|
32
|
+
// a throw would exit the Neural Interface (its unhandled-rejection handler), fail setup.js's launch or, in
|
|
33
|
+
// postinstall.js, make npm roll the whole install back. Only plain node: modules: postinstall.js and setup.js import
|
|
34
|
+
// this on any Node.
|
|
35
|
+
|
|
36
|
+
import { execFile, execFileSync } from 'node:child_process';
|
|
37
|
+
import { createHash, randomBytes } from 'node:crypto';
|
|
38
|
+
import { closeSync, existsSync, linkSync, mkdirSync, openSync, readdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
39
|
+
import { join, relative, resolve, sep } from 'node:path';
|
|
40
|
+
import { MCP_RUNTIME_ENTRIES, mcpDistMissing } from './mcp-dist.js';
|
|
41
|
+
import { mcpCompiler } from './runtime-dependencies.js';
|
|
42
|
+
|
|
43
|
+
export const BUILD_STAMP = '.synabun-build.json';
|
|
44
|
+
export const BUILD_LOCK = '.dist-build.lock';
|
|
45
|
+
const TEMP_PREFIX = '.dist-build-';
|
|
46
|
+
const OLD_PREFIX = '.dist-old-';
|
|
47
|
+
/** A lock older than this is taken over even when its owner still lives (a hung compiler). */
|
|
48
|
+
export const LOCK_STALE_MS = 30 * 60_000;
|
|
49
|
+
const LOCK_POLL_MS = 250;
|
|
50
|
+
|
|
51
|
+
export const MCP_RESTART_HINT = 'Restart your AI clients\' SynaBun MCP server (in Claude Code: /mcp) so they load the new build.';
|
|
52
|
+
|
|
53
|
+
function listFiles(dir, out = []) {
|
|
54
|
+
let entries;
|
|
55
|
+
try { entries = readdirSync(dir, { withFileTypes: true }); } catch { return out; }
|
|
56
|
+
for (const entry of entries) {
|
|
57
|
+
const full = join(dir, entry.name);
|
|
58
|
+
if (entry.isDirectory()) listFiles(full, out);
|
|
59
|
+
else if (entry.isFile()) out.push(full);
|
|
60
|
+
}
|
|
61
|
+
return out;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Whether dist (or `distDir`) holds every runtime entry and every module they import. */
|
|
65
|
+
export function mcpDistWhole(packageRoot, distDir = null) {
|
|
66
|
+
return mcpDistMissing(packageRoot, { entries: MCP_RUNTIME_ENTRIES, ...(distDir ? { distDir } : {}) });
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* What the build of this checkout should be stamped with: { version, sourceHash }, or null without a source.
|
|
71
|
+
* Throws when a source file cannot be read (mcpBuildNeeded and the builders turn that into a result).
|
|
72
|
+
*/
|
|
73
|
+
export function mcpSourceStamp(packageRoot) {
|
|
74
|
+
const root = resolve(packageRoot);
|
|
75
|
+
const mcp = join(root, 'mcp-server');
|
|
76
|
+
const src = join(mcp, 'src');
|
|
77
|
+
if (!existsSync(src)) return null;
|
|
78
|
+
let version = null;
|
|
79
|
+
try { version = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8')).version ?? null; } catch {}
|
|
80
|
+
const files = [...listFiles(src), join(mcp, 'tsconfig.json'), join(mcp, 'package.json')]
|
|
81
|
+
.filter(existsSync)
|
|
82
|
+
.map(file => ({ file, name: relative(mcp, file).split(sep).join('/') }))
|
|
83
|
+
.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
|
84
|
+
const hash = createHash('sha256');
|
|
85
|
+
for (const { file, name } of files) {
|
|
86
|
+
hash.update(name); hash.update('\0');
|
|
87
|
+
hash.update(readFileSync(file)); hash.update('\0');
|
|
88
|
+
}
|
|
89
|
+
return { version, sourceHash: hash.digest('hex') };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** The stamp the current dist carries, or null. */
|
|
93
|
+
export function readBuildStamp(packageRoot) {
|
|
94
|
+
try { return JSON.parse(readFileSync(join(resolve(packageRoot), 'mcp-server', 'dist', BUILD_STAMP), 'utf8')); } catch { return null; }
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Write the stamp of this source into a dist folder (the one of the package root by default). The packaging
|
|
99
|
+
* (packaging/lib/stage.mjs) writes it after its own compile, so the application's dist is "current", never
|
|
100
|
+
* "unstamped". Returns the stamp, or null without a source.
|
|
101
|
+
*/
|
|
102
|
+
export function writeBuildStamp(packageRoot, distDir = null) {
|
|
103
|
+
const root = resolve(packageRoot);
|
|
104
|
+
const stamp = mcpSourceStamp(root);
|
|
105
|
+
if (!stamp) return null;
|
|
106
|
+
const dist = distDir ? resolve(distDir) : join(root, 'mcp-server', 'dist');
|
|
107
|
+
writeFileSync(join(dist, BUILD_STAMP), `${JSON.stringify({ ...stamp, builtAt: new Date().toISOString() }, null, 2)}\n`);
|
|
108
|
+
return stamp;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Whether dist must be built: { needed, reason }. Needed when it is incomplete, or when a source is present and the
|
|
113
|
+
* stamp is missing or names another version or source. A copy with no source keeps its dist. A packaged application
|
|
114
|
+
* (`packaged`) is replaced whole and has no compiler: only completeness counts there. Never throws: a source that
|
|
115
|
+
* cannot be read is `needed` with reason 'unreadable' (the build then fails with the same error, as a result).
|
|
116
|
+
*/
|
|
117
|
+
export function mcpBuildNeeded(packageRoot, { packaged = false } = {}) {
|
|
118
|
+
try {
|
|
119
|
+
const { complete } = mcpDistWhole(packageRoot);
|
|
120
|
+
if (!complete) return { needed: true, reason: 'incomplete' };
|
|
121
|
+
if (packaged) return { needed: false, reason: 'packaged' };
|
|
122
|
+
const want = mcpSourceStamp(packageRoot);
|
|
123
|
+
if (!want) return { needed: false, reason: 'no-source' };
|
|
124
|
+
const have = readBuildStamp(packageRoot);
|
|
125
|
+
if (!have) return { needed: true, reason: 'unstamped' };
|
|
126
|
+
if (have.version !== want.version) return { needed: true, reason: 'version' };
|
|
127
|
+
if (have.sourceHash !== want.sourceHash) return { needed: true, reason: 'source' };
|
|
128
|
+
return { needed: false, reason: 'current' };
|
|
129
|
+
} catch (err) {
|
|
130
|
+
return { needed: true, reason: 'unreadable', error: err?.message || String(err) };
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const COMPILE_OPTIONS = (cwd, windowsHide) => ({ cwd, windowsHide, timeout: 180_000, maxBuffer: 32 * 1024 * 1024 });
|
|
135
|
+
|
|
136
|
+
function defaultCompile({ tsc, project, outDir, cwd, windowsHide }) {
|
|
137
|
+
execFileSync(process.execPath, [tsc, '-p', project, '--outDir', outDir], { ...COMPILE_OPTIONS(cwd, windowsHide), stdio: ['ignore', 'pipe', 'pipe'] });
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** The same compile without blocking the caller's event loop (the Neural Interface's routes). */
|
|
141
|
+
function defaultCompileAsync({ tsc, project, outDir, cwd, windowsHide }) {
|
|
142
|
+
return new Promise((done, fail) => {
|
|
143
|
+
execFile(process.execPath, [tsc, '-p', project, '--outDir', outDir], COMPILE_OPTIONS(cwd, windowsHide), (err, stdout, stderr) => {
|
|
144
|
+
if (err) { err.stdout = stdout; err.stderr = stderr; fail(err); } else done({ stdout, stderr });
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// ── The lock ──
|
|
150
|
+
|
|
151
|
+
function pidAlive(pid) {
|
|
152
|
+
if (!Number.isInteger(pid) || pid <= 0) return false;
|
|
153
|
+
try { process.kill(pid, 0); return true; } catch (err) { return err?.code === 'EPERM'; }
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** Before any build writes its JSON in: a lock with no readable content younger than this is a build being taken. */
|
|
157
|
+
export const LOCK_EMPTY_GRACE_MS = 5_000;
|
|
158
|
+
const CLAIM_INFIX = '.takeover-';
|
|
159
|
+
/** A takeover claim older than this belongs to a waiter that died mid-takeover. */
|
|
160
|
+
const CLAIM_STALE_MS = 60_000;
|
|
161
|
+
const TEMP_INFIX = '.tmp-';
|
|
162
|
+
|
|
163
|
+
function readLockInfo(path) {
|
|
164
|
+
try { return JSON.parse(readFileSync(path, 'utf8')); } catch { return null; }
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* What is at the lock path right now: null when nothing, else { id, stale }. `id` names this very lock (its token,
|
|
169
|
+
* or for a lock without readable content its inode and change time), so a takeover can tell it from a later one.
|
|
170
|
+
* A lock is stale when its owner is gone or it is older than LOCK_STALE_MS; a lock without readable content (an
|
|
171
|
+
* older SynaBun's lock caught between its create and its write) is held for LOCK_EMPTY_GRACE_MS, then stale.
|
|
172
|
+
*/
|
|
173
|
+
function lockState(path, now = Date.now()) {
|
|
174
|
+
let st;
|
|
175
|
+
try { st = statSync(path); } catch { return null; }
|
|
176
|
+
const info = readLockInfo(path);
|
|
177
|
+
if (!info || typeof info !== 'object' || typeof info.token !== 'string' || !info.token) {
|
|
178
|
+
return { id: `ino-${st.ino}-${st.ctimeMs}`, stale: now - st.mtimeMs > LOCK_EMPTY_GRACE_MS };
|
|
179
|
+
}
|
|
180
|
+
const id = `tok-${info.token.replace(/[^0-9A-Za-z_-]/g, '_')}`;
|
|
181
|
+
let startedAt = Number(info.startedAt);
|
|
182
|
+
if (!Number.isFinite(startedAt)) startedAt = st.mtimeMs;
|
|
183
|
+
if (now - startedAt > LOCK_STALE_MS) return { id, stale: true };
|
|
184
|
+
return { id, stale: !pidAlive(Number(info.pid)) };
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** The id of the lock at `path` as lockState names it, or null. */
|
|
188
|
+
export const lockId = (path) => lockState(path, 0)?.id ?? null;
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Remove the stale lock `judged` names, and only that one. Every waiter that judged the same lock stale races for
|
|
192
|
+
* one claim file named after it (created exclusively); only the winner removes, and only after it read the lock
|
|
193
|
+
* again and found the very lock it judged: a lock taken meanwhile has another id and is left alone. A claim
|
|
194
|
+
* whose lock is gone is swept by the next build that takes the lock.
|
|
195
|
+
*/
|
|
196
|
+
export function removeStaleLock(path, judged) {
|
|
197
|
+
const claim = `${path}${CLAIM_INFIX}${judged}`;
|
|
198
|
+
try { closeSync(openSync(claim, 'wx')); } catch (err) {
|
|
199
|
+
// Another waiter is taking this one over. A claim older than CLAIM_STALE_MS is one whose waiter died between
|
|
200
|
+
// its create and its removal (a takeover takes milliseconds): cleared, so the lock is not stuck for ever; the
|
|
201
|
+
// next attempt claims again.
|
|
202
|
+
if (err?.code === 'EEXIST') {
|
|
203
|
+
try { if (Date.now() - statSync(claim).mtimeMs > CLAIM_STALE_MS) rmSync(claim, { force: true }); } catch {}
|
|
204
|
+
}
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
try {
|
|
208
|
+
if (lockId(path) === judged) rmSync(path, { force: true });
|
|
209
|
+
} finally {
|
|
210
|
+
try { rmSync(claim, { force: true }); } catch {}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** Claims and temp files of the lock left by a process that stopped mid-way, now that this build holds it. */
|
|
215
|
+
function sweepLockLeftovers(mcp, ownId) {
|
|
216
|
+
let names = [];
|
|
217
|
+
try { names = readdirSync(mcp); } catch { return; }
|
|
218
|
+
for (const name of names) {
|
|
219
|
+
if (name.startsWith(`${BUILD_LOCK}${CLAIM_INFIX}`)) {
|
|
220
|
+
if (name === `${BUILD_LOCK}${CLAIM_INFIX}${ownId}`) continue;
|
|
221
|
+
try { if (Date.now() - statSync(join(mcp, name)).mtimeMs > CLAIM_STALE_MS) rmSync(join(mcp, name), { force: true }); } catch {}
|
|
222
|
+
} else if (name.startsWith(`${BUILD_LOCK}${TEMP_INFIX}`)) {
|
|
223
|
+
const pid = Number(/\.tmp-(\d+)-/.exec(name)?.[1]);
|
|
224
|
+
if (pid !== process.pid && pidAlive(pid)) continue;
|
|
225
|
+
try { if (Date.now() - statSync(join(mcp, name)).mtimeMs > LOCK_EMPTY_GRACE_MS) rmSync(join(mcp, name), { force: true }); } catch {}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Take mcp-server/.dist-build.lock once, without waiting: the lock, or null when another build holds it.
|
|
232
|
+
* The lock appears whole: its JSON is written to a temp file first and linked to the lock path (link fails with
|
|
233
|
+
* EEXIST while one is there). A stale lock is removed (removeStaleLock) and the take tried again.
|
|
234
|
+
* Throws only for an error that is not "already there" (the folder is missing).
|
|
235
|
+
*/
|
|
236
|
+
export function tryBuildLock(mcp) {
|
|
237
|
+
const path = join(mcp, BUILD_LOCK);
|
|
238
|
+
const token = randomBytes(8).toString('hex');
|
|
239
|
+
const temp = `${path}${TEMP_INFIX}${process.pid}-${token}`;
|
|
240
|
+
writeFileSync(temp, JSON.stringify({ pid: process.pid, token, startedAt: Date.now() }), { flag: 'wx' });
|
|
241
|
+
try {
|
|
242
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
243
|
+
try {
|
|
244
|
+
linkSync(temp, path);
|
|
245
|
+
} catch (err) {
|
|
246
|
+
if (err?.code !== 'EEXIST') throw err;
|
|
247
|
+
const state = lockState(path);
|
|
248
|
+
if (state && !state.stale) return null;
|
|
249
|
+
if (state) removeStaleLock(path, state.id);
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
sweepLockLeftovers(mcp, `tok-${token}`);
|
|
253
|
+
return {
|
|
254
|
+
path,
|
|
255
|
+
pid: process.pid,
|
|
256
|
+
token,
|
|
257
|
+
// Only the very lock this build wrote is removed: never one a later build took over.
|
|
258
|
+
release() { try { if (readLockInfo(path)?.token === token) rmSync(path, { force: true }); } catch {} },
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
return null;
|
|
262
|
+
} finally {
|
|
263
|
+
try { rmSync(temp, { force: true }); } catch {}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function sleepSync(ms) {
|
|
268
|
+
try { Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms); } catch { /* a runtime without it: no wait */ }
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/** The lock, waiting up to waitMs (a sync caller: setup.js, postinstall.js). null when still held after that. */
|
|
272
|
+
function lockSync(mcp, waitMs) {
|
|
273
|
+
const until = Date.now() + Math.max(0, waitMs);
|
|
274
|
+
for (;;) {
|
|
275
|
+
const lock = tryBuildLock(mcp);
|
|
276
|
+
if (lock) return lock;
|
|
277
|
+
if (Date.now() >= until) return null;
|
|
278
|
+
sleepSync(Math.min(LOCK_POLL_MS, Math.max(1, until - Date.now())));
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
async function lockAsync(mcp, waitMs) {
|
|
283
|
+
const until = Date.now() + Math.max(0, waitMs);
|
|
284
|
+
for (;;) {
|
|
285
|
+
const lock = tryBuildLock(mcp);
|
|
286
|
+
if (lock) return lock;
|
|
287
|
+
if (Date.now() >= until) return null;
|
|
288
|
+
await new Promise(r => setTimeout(r, Math.min(LOCK_POLL_MS, Math.max(1, until - Date.now()))));
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/** Whether mcp-server/.dist-build.lock is held by a live build right now (a route can say "busy" before it starts). */
|
|
293
|
+
export function mcpBuildRunning(packageRoot) {
|
|
294
|
+
const path = join(resolve(packageRoot), 'mcp-server', BUILD_LOCK);
|
|
295
|
+
const state = lockState(path);
|
|
296
|
+
return !!state && !state.stale;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// ── Leftovers ──
|
|
300
|
+
|
|
301
|
+
/** The pid in a `.dist-build-<pid>-<time>` or `.dist-old-<pid>-<time>` name, or null. */
|
|
302
|
+
function ownerPid(name) {
|
|
303
|
+
const m = /^\.dist-(?:build|old)-(\d+)-\d+$/.exec(name);
|
|
304
|
+
return m ? Number(m[1]) : null;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
const byMtimeDesc = (dir) => (a, b) => {
|
|
308
|
+
const t = (n) => { try { return statSync(join(dir, n)).mtimeMs; } catch { return 0; } };
|
|
309
|
+
return t(b) - t(a);
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* dist missing or incomplete while a whole old dist lies aside (an update stopped between its two renames, or a
|
|
314
|
+
* rollback that failed): the newest whole old one becomes dist again. Returns true when it did.
|
|
315
|
+
*/
|
|
316
|
+
function recoverDist(root, mcp, dist, log) {
|
|
317
|
+
if (mcpDistWhole(root).complete) return false;
|
|
318
|
+
let names = [];
|
|
319
|
+
try { names = readdirSync(mcp).filter(n => n.startsWith(OLD_PREFIX)); } catch { return false; }
|
|
320
|
+
for (const name of names.sort(byMtimeDesc(mcp))) {
|
|
321
|
+
const old = join(mcp, name);
|
|
322
|
+
if (!mcpDistWhole(root, old).complete) continue;
|
|
323
|
+
try {
|
|
324
|
+
if (existsSync(dist)) rmSync(dist, { recursive: true, force: true });
|
|
325
|
+
renameSync(old, dist);
|
|
326
|
+
} catch (err) {
|
|
327
|
+
log.warn(`Could not put back the previous MCP server build that an interrupted update left aside (${err?.code || err?.message}).`);
|
|
328
|
+
continue;
|
|
329
|
+
}
|
|
330
|
+
log.warn('Put back the previous MCP server build that an interrupted update left aside.');
|
|
331
|
+
return true;
|
|
332
|
+
}
|
|
333
|
+
return false;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/** Leftovers of a build or swap that was stopped (a temp folder, an old dist set aside): never one a live build owns. */
|
|
337
|
+
function sweep(mcp) {
|
|
338
|
+
let entries = [];
|
|
339
|
+
try { entries = readdirSync(mcp); } catch { return; }
|
|
340
|
+
for (const name of entries) {
|
|
341
|
+
if (!name.startsWith(TEMP_PREFIX) && !name.startsWith(OLD_PREFIX)) continue;
|
|
342
|
+
const pid = ownerPid(name);
|
|
343
|
+
// Another process still building (its folder, while it lives). This build holds the lock, so its own earlier
|
|
344
|
+
// folders, and those of a build whose process is gone, are leftovers.
|
|
345
|
+
if (pid !== null && pid !== process.pid && pidAlive(pid)) continue;
|
|
346
|
+
try { rmSync(join(mcp, name), { recursive: true, force: true }); } catch {}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// ── The build ──
|
|
351
|
+
|
|
352
|
+
/** The messages of a result, for the callers that print: one sentence each. */
|
|
353
|
+
const FAILED = (reason, keep) => ({
|
|
354
|
+
'no-compiler': `MCP server build failed: TypeScript is not installed (npm install at the package root installs it).${keep}`,
|
|
355
|
+
'no-source': 'MCP server build is incomplete and this copy has no source to build it from',
|
|
356
|
+
busy: 'MCP server build skipped: another SynaBun process is building it right now.',
|
|
357
|
+
lock: `MCP server build failed: the build lock could not be taken.${keep}`,
|
|
358
|
+
error: `MCP server build failed.${keep}`,
|
|
359
|
+
})[reason];
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Everything of a build but the compile itself: the lock, the recovery, the decision, the temp folder, and (`finish`)
|
|
363
|
+
* the check, the stamp and the swap. The compile is the only step that may be awaited, so the sync entry
|
|
364
|
+
* (postinstall.js, setup.js) and the async one (the Neural Interface's routes) share this and differ only in how
|
|
365
|
+
* they take the lock and run `compile`. `lock` is already held (or null: busy). Never throws.
|
|
366
|
+
* @returns {{ done: object } | { args: object, finish: (err: Error|null, compiled?: { stdout?: string }) => object }}
|
|
367
|
+
*/
|
|
368
|
+
function startBuild(packageRoot, { force, packaged, compiler, windowsHide, rename, log, lock }) {
|
|
369
|
+
const root = resolve(packageRoot);
|
|
370
|
+
const mcp = join(root, 'mcp-server');
|
|
371
|
+
const dist = join(mcp, 'dist');
|
|
372
|
+
const release = () => { try { lock?.release(); } catch {} };
|
|
373
|
+
const failed = (reason, extra = {}) => { release(); return { done: { status: 'failed', reason, ...extra } }; };
|
|
374
|
+
try {
|
|
375
|
+
if (!lock) {
|
|
376
|
+
log.warn(FAILED('busy'));
|
|
377
|
+
return failed('busy');
|
|
378
|
+
}
|
|
379
|
+
recoverDist(root, mcp, dist, log);
|
|
380
|
+
sweep(mcp);
|
|
381
|
+
const check = mcpBuildNeeded(root, { packaged });
|
|
382
|
+
if (check.reason === 'unreadable') {
|
|
383
|
+
log.fail(`MCP server build failed: the source could not be read (${check.error}).${mcpDistWhole(root).complete ? ' The previous build is kept.' : ''}`);
|
|
384
|
+
return failed('error', { output: check.error });
|
|
385
|
+
}
|
|
386
|
+
if (packaged) {
|
|
387
|
+
// Replaced whole, no compiler: whole is current; not whole is a damaged application, nothing to build it with.
|
|
388
|
+
if (!check.needed) { log.ok('MCP server build shipped with this application'); release(); return { done: { status: 'current', reason: 'packaged' } }; }
|
|
389
|
+
log.fail('MCP server build is incomplete and this application has no compiler: reinstall SynaBun.');
|
|
390
|
+
return failed('no-source');
|
|
391
|
+
}
|
|
392
|
+
if (!force && !check.needed) {
|
|
393
|
+
log.ok(check.reason === 'no-source' ? 'MCP server build shipped with this copy' : 'MCP server build matches the installed source');
|
|
394
|
+
release();
|
|
395
|
+
return { done: { status: 'current', reason: check.reason } };
|
|
396
|
+
}
|
|
397
|
+
const stamp = mcpSourceStamp(root);
|
|
398
|
+
if (!stamp) {
|
|
399
|
+
if (check.needed) log.fail(FAILED('no-source'));
|
|
400
|
+
release();
|
|
401
|
+
return { done: { status: check.needed ? 'failed' : 'current', reason: 'no-source' } };
|
|
402
|
+
}
|
|
403
|
+
const hadDist = mcpDistWhole(root).complete;
|
|
404
|
+
log.info(force ? 'Building the MCP server from the installed source...'
|
|
405
|
+
: `Building the MCP server (${({ incomplete: 'the build is incomplete', unstamped: 'the build has no record of its source', version: 'the version changed', source: 'the source changed' })[check.reason] || check.reason})...`);
|
|
406
|
+
const tsc = compiler === undefined ? mcpCompiler(root) : compiler;
|
|
407
|
+
const keep = hadDist ? ' The previous build is kept.' : '';
|
|
408
|
+
if (!tsc) {
|
|
409
|
+
log.fail(FAILED('no-compiler', keep));
|
|
410
|
+
return failed('no-compiler');
|
|
411
|
+
}
|
|
412
|
+
const temp = join(mcp, `${TEMP_PREFIX}${process.pid}-${Date.now()}`);
|
|
413
|
+
mkdirSync(temp, { recursive: true }); // this build's folder, visible (and spared by every other build's sweep) from here on
|
|
414
|
+
const discard = () => { try { rmSync(temp, { recursive: true, force: true }); } catch {} };
|
|
415
|
+
const finish = (err, compiled = {}) => {
|
|
416
|
+
try {
|
|
417
|
+
if (err) {
|
|
418
|
+
const output = [err.stdout?.toString().trim(), err.stderr?.toString().trim()].filter(Boolean).join('\n') || err.message;
|
|
419
|
+
log.fail(`MCP server build failed.${keep}`);
|
|
420
|
+
log.error(output);
|
|
421
|
+
discard();
|
|
422
|
+
return { status: 'failed', reason: 'compile', output };
|
|
423
|
+
}
|
|
424
|
+
// The new build must be whole before it replaces anything: every runtime entry, checked as if it were dist.
|
|
425
|
+
const missing = mcpDistWhole(root, temp);
|
|
426
|
+
if (!missing.complete) {
|
|
427
|
+
log.fail(`MCP server build failed: the compiler wrote an incomplete build.${keep}`);
|
|
428
|
+
discard();
|
|
429
|
+
return { status: 'failed', reason: 'incomplete-output', output: missing.missing.join('\n') };
|
|
430
|
+
}
|
|
431
|
+
writeFileSync(join(temp, BUILD_STAMP), `${JSON.stringify({ ...stamp, builtAt: new Date().toISOString() }, null, 2)}\n`);
|
|
432
|
+
const old = join(mcp, `${OLD_PREFIX}${process.pid}-${Date.now()}`);
|
|
433
|
+
let movedAside = false;
|
|
434
|
+
try {
|
|
435
|
+
if (existsSync(dist)) { rename(dist, old); movedAside = true; }
|
|
436
|
+
rename(temp, dist);
|
|
437
|
+
} catch (swapErr) {
|
|
438
|
+
if (movedAside && !existsSync(dist)) { try { rename(old, dist); } catch {} }
|
|
439
|
+
discard();
|
|
440
|
+
log.fail(`MCP server build could not replace the previous one (${swapErr.code || swapErr.message}).${keep}`);
|
|
441
|
+
return { status: 'failed', reason: 'swap', output: swapErr.message };
|
|
442
|
+
}
|
|
443
|
+
// Only now, with the new dist in place, is the old one no longer needed.
|
|
444
|
+
if (movedAside) { try { rmSync(old, { recursive: true, force: true }); } catch {} }
|
|
445
|
+
log.ok('MCP server built');
|
|
446
|
+
if (hadDist) log.info(MCP_RESTART_HINT);
|
|
447
|
+
const output = compiled?.stdout ? String(compiled.stdout).trim() : '';
|
|
448
|
+
return { status: 'built', reason: force ? 'forced' : check.reason, ...(output ? { output } : {}) };
|
|
449
|
+
} catch (unexpected) {
|
|
450
|
+
discard();
|
|
451
|
+
log.fail(`MCP server build failed (${unexpected?.message || unexpected}).${keep}`);
|
|
452
|
+
return { status: 'failed', reason: 'error', output: unexpected?.message || String(unexpected) };
|
|
453
|
+
} finally {
|
|
454
|
+
release();
|
|
455
|
+
}
|
|
456
|
+
};
|
|
457
|
+
return { args: { tsc, project: mcp, outDir: temp, cwd: mcp, windowsHide }, finish };
|
|
458
|
+
} catch (unexpected) {
|
|
459
|
+
log.fail(`MCP server build failed (${unexpected?.message || unexpected}).`);
|
|
460
|
+
return failed('error', { output: unexpected?.message || String(unexpected) });
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
const QUIET = { ok() {}, info() {}, warn() {}, fail() {}, error() {} };
|
|
465
|
+
|
|
466
|
+
/** The lock for a build of `packageRoot`, or null when busy; a lock that cannot be created at all is an error result. */
|
|
467
|
+
function takeLockSync(packageRoot, waitMs) {
|
|
468
|
+
try { return { lock: lockSync(join(resolve(packageRoot), 'mcp-server'), waitMs) }; } catch (err) { return { error: err }; }
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
/**
|
|
472
|
+
* Build mcp-server into a temp folder and swap it in only when it succeeded. Never throws.
|
|
473
|
+
* @param {string} packageRoot
|
|
474
|
+
* @param {{ force?: boolean, packaged?: boolean, waitMs?: number, compile?: Function, compiler?: string|null, windowsHide?: boolean,
|
|
475
|
+
* rename?: Function, log?: { ok: Function, info: Function, warn: Function, fail: Function, error: Function } }} [o]
|
|
476
|
+
* `waitMs`: how long to wait for another build to finish (0: report `busy` at once).
|
|
477
|
+
* @returns {{ status: 'built'|'current'|'failed', reason: string, output?: string }}
|
|
478
|
+
*/
|
|
479
|
+
export function buildMcpServerSafely(packageRoot, {
|
|
480
|
+
force = false,
|
|
481
|
+
packaged = false,
|
|
482
|
+
waitMs = 0,
|
|
483
|
+
compile = defaultCompile,
|
|
484
|
+
compiler,
|
|
485
|
+
windowsHide = false,
|
|
486
|
+
rename = renameSync,
|
|
487
|
+
log = QUIET,
|
|
488
|
+
} = {}) {
|
|
489
|
+
const taken = takeLockSync(packageRoot, waitMs);
|
|
490
|
+
if (taken.error) { log.fail(FAILED('lock', '')); return { status: 'failed', reason: 'lock', output: taken.error.message }; }
|
|
491
|
+
const build = startBuild(packageRoot, { force, packaged, compiler, windowsHide, rename, log, lock: taken.lock });
|
|
492
|
+
if (build.done) return build.done;
|
|
493
|
+
let compiled;
|
|
494
|
+
try { compiled = compile(build.args); } catch (err) { return build.finish(err); }
|
|
495
|
+
return build.finish(null, compiled);
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* The same build with the compile awaited (`compile` may return a promise), for a server that must keep answering
|
|
500
|
+
* while the compiler runs. Same result shape; never rejects.
|
|
501
|
+
*/
|
|
502
|
+
export async function buildMcpServerSafelyAsync(packageRoot, {
|
|
503
|
+
force = false,
|
|
504
|
+
packaged = false,
|
|
505
|
+
waitMs = 0,
|
|
506
|
+
compile = defaultCompileAsync,
|
|
507
|
+
compiler,
|
|
508
|
+
windowsHide = false,
|
|
509
|
+
rename = renameSync,
|
|
510
|
+
log = QUIET,
|
|
511
|
+
} = {}) {
|
|
512
|
+
let lock;
|
|
513
|
+
try { lock = await lockAsync(join(resolve(packageRoot), 'mcp-server'), waitMs); } catch (err) { log.fail(FAILED('lock', '')); return { status: 'failed', reason: 'lock', output: err.message }; }
|
|
514
|
+
const build = startBuild(packageRoot, { force, packaged, compiler, windowsHide, rename, log, lock });
|
|
515
|
+
if (build.done) return build.done;
|
|
516
|
+
let compiled;
|
|
517
|
+
try { compiled = await compile(build.args); } catch (err) { return build.finish(err); }
|
|
518
|
+
return build.finish(null, compiled);
|
|
519
|
+
}
|
package/lib/mcp-dist.js
CHANGED
|
@@ -13,6 +13,10 @@ import { existsSync, readFileSync, statSync } from 'node:fs';
|
|
|
13
13
|
import { dirname, join, relative, resolve, sep } from 'node:path';
|
|
14
14
|
|
|
15
15
|
const MAX_MODULES = 5000;
|
|
16
|
+
// Every file something starts in dist: `node dist/index.js`, run.mjs (the MCP command every client runs) loads
|
|
17
|
+
// dist/preload.js, `npm run start:http` and the Neural Interface's HTTP MCP load dist/preload-http.js. A build is
|
|
18
|
+
// whole only with all of them (lib/mcp-build.js checks a new build and dist by this list).
|
|
19
|
+
export const MCP_RUNTIME_ENTRIES = ['index.js', 'preload.js', 'preload-http.js'];
|
|
16
20
|
const MAX_MODULE_BYTES = 8 * 1024 * 1024;
|
|
17
21
|
const CODE_EXT = /\.(?:m?js|cjs)$/i;
|
|
18
22
|
// After one of these a `/` starts a regular expression, after anything else it divides.
|
|
@@ -133,12 +137,14 @@ const posix = (p) => p.split(sep).join('/');
|
|
|
133
137
|
* Every module dist/index.js needs that is not on disk (or cannot be read), as paths from the package root.
|
|
134
138
|
* Modules inside mcp-server/dist are followed; one outside it (the package's lib/) is only looked for.
|
|
135
139
|
* @param {string} packageRoot
|
|
136
|
-
* @param {{ exists?: (p: string) => boolean, readText?: (p: string) => string, entry?: string }} [o]
|
|
140
|
+
* @param {{ exists?: (p: string) => boolean, readText?: (p: string) => string, entry?: string, entries?: string[], distDir?: string }} [o]
|
|
141
|
+
* `entries`: every file to start from (MCP_RUNTIME_ENTRIES for the whole runtime); default the one `entry`.
|
|
137
142
|
* @returns {{ complete: boolean, missing: string[], checked: number }}
|
|
138
143
|
*/
|
|
139
|
-
export function mcpDistMissing(packageRoot, { exists = existsSync, readText = null, entry = 'index.js' } = {}) {
|
|
144
|
+
export function mcpDistMissing(packageRoot, { exists = existsSync, readText = null, entry = 'index.js', entries = null, distDir = null } = {}) {
|
|
140
145
|
const root = resolve(packageRoot);
|
|
141
|
-
|
|
146
|
+
// distDir: another folder checked as if it were dist (lib/mcp-build.js checks a new build before it swaps it in).
|
|
147
|
+
const dist = distDir ? resolve(distDir) : join(root, 'mcp-server', 'dist');
|
|
142
148
|
const read = readText || ((p) => {
|
|
143
149
|
const st = statSync(p);
|
|
144
150
|
if (!st.isFile()) throw new Error('not a regular file');
|
|
@@ -147,7 +153,7 @@ export function mcpDistMissing(packageRoot, { exists = existsSync, readText = nu
|
|
|
147
153
|
});
|
|
148
154
|
const missing = new Set();
|
|
149
155
|
const seen = new Set();
|
|
150
|
-
const queue = [join(dist,
|
|
156
|
+
const queue = (entries || [entry]).map(name => join(dist, name));
|
|
151
157
|
let checked = 0;
|
|
152
158
|
while (queue.length && checked < MAX_MODULES) {
|
|
153
159
|
const file = queue.shift();
|
package/lib/release-scan.mjs
CHANGED
|
@@ -5,24 +5,37 @@ import { basename, resolve } from 'node:path';
|
|
|
5
5
|
import { pathToFileURL } from 'node:url';
|
|
6
6
|
import { applyReviews, credentials, hashFile, reports, VirusTotal } from './virustotal.mjs';
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* `fallback(items)` (optional) runs after every scan of this run and may only turn
|
|
10
|
+
* an error item into an auditable status approved() checks on its own
|
|
11
|
+
* (the desktop gate's dmg equivalence, scripts/release/lib/dmg-equivalence.mjs).
|
|
12
|
+
*/
|
|
13
|
+
export async function scanRelease({ files = [], urls = [], out, prefix = 'virustotal', reviewFile, client = new VirusTotal(), now = Date.now(), fallback }) {
|
|
9
14
|
if (!files.length && !urls.length) throw new Error('No scan subjects supplied');
|
|
10
|
-
|
|
15
|
+
// Missing/mismatched local bytes are hard errors, never reviewable detections:
|
|
16
|
+
// every file is checked before the first VirusTotal request.
|
|
17
|
+
const subjects = [];
|
|
11
18
|
for (const file of files) {
|
|
12
19
|
const path = typeof file === 'string' ? file : file.path;
|
|
13
20
|
const expected = typeof file === 'string' ? undefined : file.sha256;
|
|
14
|
-
// Missing/mismatched local bytes are hard errors, never reviewable detections.
|
|
15
21
|
const sha256 = await hashFile(path);
|
|
16
22
|
if (expected && sha256 !== expected) throw new Error(`SHA-256 mismatch: ${basename(path)}`);
|
|
17
|
-
|
|
18
|
-
catch (error) { items.push({ kind: 'file', name: basename(path), sha256, status: 'error', analysis_status: 'unavailable', error: error.message }); }
|
|
19
|
-
}
|
|
20
|
-
for (const url of urls) {
|
|
21
|
-
try { items.push(await client.url(url)); }
|
|
22
|
-
catch (error) { items.push({ kind: 'url', name: url, status: 'error', analysis_status: 'unavailable', error: error.message }); }
|
|
23
|
+
subjects.push({ path, sha256 });
|
|
23
24
|
}
|
|
25
|
+
// Scans run concurrently so slow analyses (large dmgs) wait at the same time;
|
|
26
|
+
// the client's pace() still starts requests one at a time at the API rate.
|
|
27
|
+
// Items keep input order (files, then URLs) whatever finishes first.
|
|
28
|
+
const items = await Promise.all([
|
|
29
|
+
...subjects.map(({ path, sha256 }) => client.file(path, sha256)
|
|
30
|
+
.catch(error => ({ kind: 'file', name: basename(path), sha256, status: 'error', analysis_status: 'unavailable', error: error.message }))),
|
|
31
|
+
...urls.map(url => client.url(url)
|
|
32
|
+
.catch(error => ({ kind: 'url', name: url, status: 'error', analysis_status: 'unavailable', error: error.message }))),
|
|
33
|
+
]);
|
|
24
34
|
const reviews = reviewFile ? JSON.parse(await readFile(reviewFile, 'utf8')) : [];
|
|
25
|
-
const
|
|
35
|
+
const settled = fallback ? await fallback(items) : items;
|
|
36
|
+
// A fallback may change error items only: a verdict VirusTotal gave is never rewritten.
|
|
37
|
+
if (!Array.isArray(settled) || settled.length !== items.length || settled.some((item, i) => item !== items[i] && (items[i].status !== 'error' || !['error', 'equivalent-to-clean'].includes(item?.status) || item.name !== items[i].name || item.sha256 !== items[i].sha256))) throw new Error('VirusTotal fallback may only settle error items');
|
|
38
|
+
const result = reports(applyReviews(settled, reviews, now));
|
|
26
39
|
await mkdir(out, { recursive: true });
|
|
27
40
|
await writeFile(resolve(out, `${prefix}.json`), result.json);
|
|
28
41
|
await writeFile(resolve(out, `${prefix}.md`), result.markdown);
|
package/lib/server-supervisor.js
CHANGED
|
@@ -131,6 +131,7 @@ function within(promise, ms) {
|
|
|
131
131
|
* @param {(code: string, message: string, extra?: object) => void} [o.onFailed] the record's failure
|
|
132
132
|
* @param {(o: { port: number|null, first: boolean }) => void} [o.onListening] the server said it listens
|
|
133
133
|
* @param {{ reopen: (port: number) => void, failed: (error: object) => Promise<void> }} [o.reports] the restart report
|
|
134
|
+
* @param {() => void} [o.beforeRestart] runs before the server is started again (setup.js: the MCP build check); never fatal
|
|
134
135
|
* @param {(code: number) => void} [o.exit]
|
|
135
136
|
*/
|
|
136
137
|
export function superviseServer({
|
|
@@ -151,6 +152,7 @@ export function superviseServer({
|
|
|
151
152
|
onListening = () => {},
|
|
152
153
|
reports = { reopen() {}, async failed() {} },
|
|
153
154
|
resolvePort = () => null,
|
|
155
|
+
beforeRestart = () => {},
|
|
154
156
|
lookupWindowsCrash = nodeLookupWindowsCrash,
|
|
155
157
|
exit = (code) => process.exit(code),
|
|
156
158
|
windowMs = CRASH_WINDOW_MS,
|
|
@@ -385,7 +387,11 @@ export function superviseServer({
|
|
|
385
387
|
print.info(`Starting it again (${count} of ${limit} restarts within ${seconds} s).`);
|
|
386
388
|
}
|
|
387
389
|
state.firstLaunch = false;
|
|
388
|
-
setTimeout(
|
|
390
|
+
setTimeout(() => {
|
|
391
|
+
// A restart after a `git pull` must not load the old MCP build: setup.js checks (and builds) here.
|
|
392
|
+
try { beforeRestart(); } catch (error) { print.warn(`Before the restart: ${error?.message || error}`); }
|
|
393
|
+
spawnOnce();
|
|
394
|
+
}, respawnDelayMs);
|
|
389
395
|
return;
|
|
390
396
|
}
|
|
391
397
|
|