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
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
// ── A Claude Code turn that waits for its own background work (DOM-free) ──
|
|
2
|
+
//
|
|
3
|
+
// An unattended run (a native loop iteration, a dispatched worker turn) drives one streaming Agent SDK query and
|
|
4
|
+
// counted the iteration over at the first `result`. A turn that ends while a background shell or a Monitor it
|
|
5
|
+
// started still runs is not over: the CLI comes back by itself when that work settles (a `task_notification`
|
|
6
|
+
// queued to the idle session starts a new turn, beginning with a `system/init`), and the work continues there.
|
|
7
|
+
// Ending the iteration at the first result disposed the query, the CLI killed the waits, and the run stopped
|
|
8
|
+
// mid-task while its panel showed the waits "running" forever (a Bluesky schedule waiting out a pacing gap).
|
|
9
|
+
//
|
|
10
|
+
// This module decides, from the SDK's own events, when such a turn is really over:
|
|
11
|
+
// - a result with none of the session's background tasks live (and none just reported that would start another
|
|
12
|
+
// turn) ends it at once, exactly as before;
|
|
13
|
+
// - a result while tasks are live is held: later results join it (cost and usage summed, the last text wins);
|
|
14
|
+
// - when the tasks drain and the CLI does not come back within `resumeGraceMs`, the host pushes one continuation
|
|
15
|
+
// prompt (`nudge`);
|
|
16
|
+
// - `idleMs` without any event from the CLI, or the run's own deadline, ends the hold with the last result.
|
|
17
|
+
//
|
|
18
|
+
// The host (lib/native-loop-providers.js) feeds every SDK message to `onEvent` and asks `onResult` what to do
|
|
19
|
+
// with each result of the active turn. Clock and timers are injected, so the tests run it on a fake clock.
|
|
20
|
+
|
|
21
|
+
export const BACKGROUND_HOLD_DEFAULTS = Object.freeze({
|
|
22
|
+
// How long a held turn waits with no event at all from the CLI (a background task that never ends, a CLI that
|
|
23
|
+
// never comes back) before the iteration ends with the last result. Pacing gaps are a few minutes at most.
|
|
24
|
+
idleMs: 10 * 60_000,
|
|
25
|
+
// After the last background task ended: how long the CLI has to start its own turn before the host nudges it.
|
|
26
|
+
resumeGraceMs: 15_000,
|
|
27
|
+
// A task reported during the turn that just ended may still start a turn of its own: this long is waited for it.
|
|
28
|
+
followGraceMs: 4_000,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const RESULT_BLOCK_RE = /^#{1,3}\s*Result\b/m;
|
|
32
|
+
|
|
33
|
+
/** A dispatched worker that wrote its ## Result block has said it is done: its turn is never held. */
|
|
34
|
+
export function resultDeclaresDone(text) {
|
|
35
|
+
return RESULT_BLOCK_RE.test(String(text || ''));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const NUMERIC_USAGE_KEYS = ['input_tokens', 'output_tokens', 'cache_creation_input_tokens', 'cache_read_input_tokens'];
|
|
39
|
+
|
|
40
|
+
/** The usage of two results of one held turn, added up (unknown fields: the later one's). */
|
|
41
|
+
export function addUsage(a, b) {
|
|
42
|
+
if (!a) return b || null;
|
|
43
|
+
if (!b) return a;
|
|
44
|
+
const out = { ...a, ...b };
|
|
45
|
+
for (const key of NUMERIC_USAGE_KEYS) {
|
|
46
|
+
const x = Number(a[key]) || 0;
|
|
47
|
+
const y = Number(b[key]) || 0;
|
|
48
|
+
if (x || y) out[key] = x + y;
|
|
49
|
+
}
|
|
50
|
+
return out;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** The live background tasks of one CLI session, from its level signal and its bookends. */
|
|
54
|
+
export function createBackgroundTasks() {
|
|
55
|
+
const live = new Map(); // task_id → { id, type, description, ambient }
|
|
56
|
+
const started = new Map(); // task_id → tool_use_id (set when a tool call of the model started it)
|
|
57
|
+
const excused = new Set(); // tasks a hold already gave up on (never ending): they hold no later turn
|
|
58
|
+
let notifiedAt = 0; // last task_notification (ms, host clock)
|
|
59
|
+
return {
|
|
60
|
+
/** @returns true when the event was a task event */
|
|
61
|
+
apply(event, now) {
|
|
62
|
+
if (event?.type !== 'system') return false;
|
|
63
|
+
switch (event.subtype) {
|
|
64
|
+
case 'background_tasks_changed': {
|
|
65
|
+
live.clear();
|
|
66
|
+
for (const task of Array.isArray(event.tasks) ? event.tasks : []) {
|
|
67
|
+
if (!task?.task_id) continue;
|
|
68
|
+
const id = String(task.task_id);
|
|
69
|
+
live.set(id, { id, type: String(task.task_type || ''), description: String(task.description || ''), ambient: task.ambient === true });
|
|
70
|
+
}
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
case 'task_started':
|
|
74
|
+
if (event.task_id) started.set(String(event.task_id), event.tool_use_id ? String(event.tool_use_id) : '');
|
|
75
|
+
return true;
|
|
76
|
+
case 'task_notification':
|
|
77
|
+
if (event.task_id) live.delete(String(event.task_id));
|
|
78
|
+
notifiedAt = now;
|
|
79
|
+
return true;
|
|
80
|
+
case 'task_updated': {
|
|
81
|
+
const status = event.patch?.status;
|
|
82
|
+
if (event.task_id && ['completed', 'failed', 'killed', 'stopped'].includes(status)) live.delete(String(event.task_id));
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
default:
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
/**
|
|
90
|
+
* What a turn waits for: every live task, except ambient housekeeping nothing of the model started
|
|
91
|
+
* (a watcher the CLI runs by itself would otherwise hold every turn to its limit).
|
|
92
|
+
*/
|
|
93
|
+
holdable() {
|
|
94
|
+
return [...live.values()].filter((task) => !excused.has(task.id) && (!task.ambient || !!started.get(task.id)));
|
|
95
|
+
},
|
|
96
|
+
/** A hold ended without these tasks (idle, deadline): a later turn does not wait for them again. */
|
|
97
|
+
excuse(list) { for (const task of Array.isArray(list) ? list : []) if (task?.id) excused.add(String(task.id)); },
|
|
98
|
+
live: () => [...live.values()],
|
|
99
|
+
notifiedAt: () => notifiedAt,
|
|
100
|
+
/** The CLI process is gone: nothing of it runs any more. */
|
|
101
|
+
clear() { live.clear(); started.clear(); excused.clear(); },
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* One turn's hold. `onResult(event, value)` is called for each result of the active turn and answers 'resolve'
|
|
107
|
+
* (the turn is over: resolve it with `value()`) or 'hold' (keep waiting). Every other SDK message goes to
|
|
108
|
+
* `onEvent`. `onRelease(reason)` is the host's: called when the hold ends by itself ('drained': the CLI did not
|
|
109
|
+
* come back after its work ended, 'idle_timeout', 'deadline'); `nudge()` is the host's too: push one continuation
|
|
110
|
+
* prompt, answer whether it was sent. `shouldHold(value)` says whether a result may wait at all (a dispatched
|
|
111
|
+
* worker that wrote its ## Result block is done).
|
|
112
|
+
*/
|
|
113
|
+
export function createTurnHold({
|
|
114
|
+
tasks,
|
|
115
|
+
now = Date.now,
|
|
116
|
+
setTimer = (fn, ms) => { const t = setTimeout(fn, ms); t.unref?.(); return t; },
|
|
117
|
+
clearTimer = (t) => clearTimeout(t),
|
|
118
|
+
idleMs = BACKGROUND_HOLD_DEFAULTS.idleMs,
|
|
119
|
+
resumeGraceMs = BACKGROUND_HOLD_DEFAULTS.resumeGraceMs,
|
|
120
|
+
followGraceMs = BACKGROUND_HOLD_DEFAULTS.followGraceMs,
|
|
121
|
+
deadlineAt = null,
|
|
122
|
+
shouldHold = () => true,
|
|
123
|
+
onRelease = () => {},
|
|
124
|
+
nudge = () => false,
|
|
125
|
+
onState = () => {},
|
|
126
|
+
} = {}) {
|
|
127
|
+
let value = null; // the turn's result so far (several results merged while held)
|
|
128
|
+
let holding = false;
|
|
129
|
+
let inTurn = true; // the CLI is in a turn of this hold (the host's prompt, or one it started itself)
|
|
130
|
+
let turnStartedAt = now();
|
|
131
|
+
let drainedWhileIdle = false; // the work it waited for ended after its last result, and no turn started since
|
|
132
|
+
let nudged = false;
|
|
133
|
+
let done = false;
|
|
134
|
+
let idleTimer = null;
|
|
135
|
+
let graceTimer = null;
|
|
136
|
+
let deadlineTimer = null;
|
|
137
|
+
|
|
138
|
+
const clearAll = () => {
|
|
139
|
+
clearTimer(idleTimer); idleTimer = null;
|
|
140
|
+
clearTimer(graceTimer); graceTimer = null;
|
|
141
|
+
clearTimer(deadlineTimer); deadlineTimer = null;
|
|
142
|
+
};
|
|
143
|
+
const finish = () => { done = true; holding = false; clearAll(); return 'resolve'; };
|
|
144
|
+
const release = (reason) => {
|
|
145
|
+
if (done || !holding) return;
|
|
146
|
+
const live = tasks.holdable();
|
|
147
|
+
finish();
|
|
148
|
+
onState({ state: 'released', reason, tasks: live });
|
|
149
|
+
onRelease(reason, live);
|
|
150
|
+
};
|
|
151
|
+
const armIdle = () => {
|
|
152
|
+
clearTimer(idleTimer);
|
|
153
|
+
idleTimer = setTimer(() => release('idle_timeout'), Math.max(1, idleMs));
|
|
154
|
+
};
|
|
155
|
+
const armDeadline = () => {
|
|
156
|
+
if (deadlineTimer || !(Number(deadlineAt) > 0)) return;
|
|
157
|
+
deadlineTimer = setTimer(() => release('deadline'), Math.max(1, Number(deadlineAt) - now()));
|
|
158
|
+
};
|
|
159
|
+
/** Between turns with nothing holdable live: the CLI should come back by itself; nudge it once if it does not. */
|
|
160
|
+
const armGrace = () => {
|
|
161
|
+
clearTimer(graceTimer);
|
|
162
|
+
graceTimer = null;
|
|
163
|
+
if (done || !holding || inTurn || tasks.holdable().length) return;
|
|
164
|
+
const waitMs = drainedWhileIdle ? resumeGraceMs : Math.min(followGraceMs, resumeGraceMs);
|
|
165
|
+
graceTimer = setTimer(() => {
|
|
166
|
+
graceTimer = null;
|
|
167
|
+
if (done || inTurn || tasks.holdable().length) return;
|
|
168
|
+
if (drainedWhileIdle && !nudged && nudge()) {
|
|
169
|
+
nudged = true;
|
|
170
|
+
inTurn = true;
|
|
171
|
+
drainedWhileIdle = false;
|
|
172
|
+
turnStartedAt = now();
|
|
173
|
+
onState({ state: 'nudged', tasks: [] });
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
release('drained');
|
|
177
|
+
}, Math.max(1, waitMs));
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
return {
|
|
181
|
+
get held() { return holding && !done; },
|
|
182
|
+
get done() { return done; },
|
|
183
|
+
/** Any SDK message that is not a result of this turn (task events included: the host applied them first). */
|
|
184
|
+
onEvent(event) {
|
|
185
|
+
if (done) return;
|
|
186
|
+
if (holding) armIdle();
|
|
187
|
+
// Every turn the CLI starts by itself begins with system/init.
|
|
188
|
+
if (event?.type === 'system' && event.subtype === 'init') {
|
|
189
|
+
if (holding && !inTurn) {
|
|
190
|
+
inTurn = true;
|
|
191
|
+
drainedWhileIdle = false;
|
|
192
|
+
turnStartedAt = now();
|
|
193
|
+
clearTimer(graceTimer); graceTimer = null;
|
|
194
|
+
onState({ state: 'resumed', tasks: tasks.holdable() });
|
|
195
|
+
}
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
if (!holding || inTurn) return;
|
|
199
|
+
if (!tasks.holdable().length && !graceTimer) {
|
|
200
|
+
drainedWhileIdle = true;
|
|
201
|
+
armGrace();
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
/** A result of this turn. `turnValue` is what the turn resolves with if this is its last result. */
|
|
205
|
+
onResult(event, turnValue) {
|
|
206
|
+
if (done) return 'resolve';
|
|
207
|
+
inTurn = false;
|
|
208
|
+
value = mergeTurnValues(value, turnValue);
|
|
209
|
+
const more = Number(event?.queued_turn_count) > 0;
|
|
210
|
+
const live = tasks.holdable();
|
|
211
|
+
// A task that reported during this turn may start a turn of its own (the CLI queues it): a short wait.
|
|
212
|
+
const reportedInTurn = tasks.notifiedAt() > turnStartedAt;
|
|
213
|
+
if (!more && !live.length && !reportedInTurn) return finish();
|
|
214
|
+
if (!shouldHold(value)) return finish();
|
|
215
|
+
holding = true;
|
|
216
|
+
drainedWhileIdle = false;
|
|
217
|
+
if (live.length) onState({ state: 'holding', tasks: live });
|
|
218
|
+
armIdle();
|
|
219
|
+
armDeadline();
|
|
220
|
+
armGrace();
|
|
221
|
+
return 'hold';
|
|
222
|
+
},
|
|
223
|
+
value: () => value,
|
|
224
|
+
cancel() { if (!done) finish(); },
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** Two results of one held turn: the later one's text and event, the charges added up. */
|
|
229
|
+
export function mergeTurnValues(earlier, later) {
|
|
230
|
+
if (!earlier) return later;
|
|
231
|
+
if (!later) return earlier;
|
|
232
|
+
const cost = (Number(earlier.costUsd) || 0) + (Number(later.costUsd) || 0);
|
|
233
|
+
return {
|
|
234
|
+
...later,
|
|
235
|
+
costUsd: Number(cost.toFixed(8)),
|
|
236
|
+
usage: addUsage(earlier.usage, later.usage),
|
|
237
|
+
heldResults: (Number(earlier.heldResults) || 1) + 1,
|
|
238
|
+
};
|
|
239
|
+
}
|
|
@@ -21,6 +21,18 @@ import { withPathEnv, getAugmentedPath } from './augmented-path.js';
|
|
|
21
21
|
// and as the server-side allowlist at every spawn site.
|
|
22
22
|
export const CLAUDE_EFFORT_LEVELS = Object.freeze(['low', 'medium', 'high', 'xhigh', 'max']);
|
|
23
23
|
|
|
24
|
+
// Off for an Assistant route / dispatch / brain turn (effort-levels.js EFFORT_OFF):
|
|
25
|
+
// no --effort, and the SDK's `thinking: { type: 'disabled' }`, over any effortLevel
|
|
26
|
+
// in the user's settings. (The Claude panel's own Think toggle says 'off'.)
|
|
27
|
+
export const CLAUDE_EFFORT_OFF = 'none';
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* An effort that starts the CLI with thinking disabled: `none` for every session, 'off' only in a
|
|
31
|
+
* panel session (its Think toggle). Elsewhere (the Assistant brain, loops) 'off' is Auto, the
|
|
32
|
+
* model's default, which a live process takes without a restart.
|
|
33
|
+
*/
|
|
34
|
+
export function isThinkingOff(effort, { panel = true } = {}) { return effort === CLAUDE_EFFORT_OFF || (panel && effort === 'off'); }
|
|
35
|
+
|
|
24
36
|
// Used only when discovery fails (CLI missing, spawn error, timeout). Kept
|
|
25
37
|
// deliberately short — a stale fallback is less harmful than a stale primary,
|
|
26
38
|
// because `source: 'fallback'` tells the UI the list is unverified.
|
|
@@ -73,7 +73,27 @@ export function modelEfforts(row) {
|
|
|
73
73
|
return source ? sortEfforts(source) : null;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
/**
|
|
76
|
+
/**
|
|
77
|
+
* Off: thinking / reasoning disabled. One id across providers (Codex
|
|
78
|
+
* `model_reasoning_effort=none`, the OpenCode variant `none`, Claude Code
|
|
79
|
+
* `thinking: { type: 'disabled' }`). Only ever chosen, never reached by a
|
|
80
|
+
* correction: a level a model lacks never lands on Off.
|
|
81
|
+
*/
|
|
82
|
+
export const EFFORT_OFF = 'none';
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Can this provider/row run with thinking off? Codex and OpenCode only when the
|
|
86
|
+
* model lists `none`; Claude Code whenever the model thinks at all (the SDK
|
|
87
|
+
* disables thinking for any of them). Antigravity takes no such level.
|
|
88
|
+
*/
|
|
89
|
+
export function supportsEffortOff(provider, row) {
|
|
90
|
+
const levels = modelEfforts(row);
|
|
91
|
+
if (provider === 'claude-code') return levels ? levels.some((id) => id.toLowerCase() !== EFFORT_OFF) : !!row;
|
|
92
|
+
if (provider === 'antigravity') return false;
|
|
93
|
+
return !!levels?.some((id) => id.toLowerCase() === EFFORT_OFF);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** `effort` clamped into `levels`: kept, else the highest level below it, else the lowest (never Off). */
|
|
77
97
|
export function clampEffort(effort, levels, { fallback = null } = {}) {
|
|
78
98
|
const want = clean(effort);
|
|
79
99
|
if (!want || !levels?.length) return null;
|
|
@@ -81,7 +101,9 @@ export function clampEffort(effort, levels, { fallback = null } = {}) {
|
|
|
81
101
|
if (same) return same;
|
|
82
102
|
const rank = effortRank(want);
|
|
83
103
|
if (rank < 0) return fallback && levels.includes(fallback) ? fallback : null;
|
|
84
|
-
|
|
104
|
+
// Off is a choice, not a level to fall back on.
|
|
105
|
+
const ranked = levels.filter((id) => effortRank(id) >= 0 && id.toLowerCase() !== EFFORT_OFF);
|
|
106
|
+
if (!ranked.length) return levels.find((id) => id.toLowerCase() !== EFFORT_OFF) || null;
|
|
85
107
|
const below = ranked.filter((id) => effortRank(id) < rank);
|
|
86
108
|
if (below.length) return below[below.length - 1];
|
|
87
109
|
return ranked[0] || levels[0];
|
|
@@ -97,6 +119,8 @@ function rowFor(catalog, provider, model) {
|
|
|
97
119
|
/**
|
|
98
120
|
* Check `effort` against the model's levels. → { effort, corrected: {from, to} | null }.
|
|
99
121
|
* off/default/auto/empty → null (the model's own default). Supported → kept.
|
|
122
|
+
* `none` (Off: no thinking) is kept wherever supportsEffortOff says the model
|
|
123
|
+
* can run it, Claude Code's thinking models included.
|
|
100
124
|
* Unsupported → the highest supported level below it, else the lowest
|
|
101
125
|
* (minimal → low, ultra on a max-only model → max). A model with no levels →
|
|
102
126
|
* null. Unknown model or unverified catalog → passed through unchanged: a value
|
|
@@ -109,6 +133,8 @@ export function normalizeEffort({ provider = null, model = null, effort = null,
|
|
|
109
133
|
const row = rowFor(catalog, provider, model)?.row || null;
|
|
110
134
|
const levels = modelEfforts(row);
|
|
111
135
|
if (!levels) return { effort: raw, corrected: null };
|
|
136
|
+
// Off on a model that can switch its thinking off stays Off (Claude Code lists no `none`: see supportsEffortOff).
|
|
137
|
+
if (raw.toLowerCase() === EFFORT_OFF && supportsEffortOff(provider, row)) return { effort: EFFORT_OFF, corrected: null };
|
|
112
138
|
const next = clampEffort(raw, levels, { fallback: row?.defaultEffort || null });
|
|
113
139
|
return next === raw ? { effort: raw, corrected: null } : { effort: next, corrected: { from: raw, to: next } };
|
|
114
140
|
}
|
|
@@ -85,6 +85,9 @@ export function buildExecInvocation({
|
|
|
85
85
|
model,
|
|
86
86
|
effort,
|
|
87
87
|
mcpEnvOverrides = [],
|
|
88
|
+
// Codex: variables its SynaBun MCP server takes from the loop's environment by name (`env_vars`): a secret is never
|
|
89
|
+
// a `-c` value, because a command line is readable by every account of the computer (the run's terminal token).
|
|
90
|
+
mcpEnvVars = [],
|
|
88
91
|
// Codex: launch overrides as `-c` words (the Windows sandbox of the Admin sandbox setting).
|
|
89
92
|
codexConfigArgs = [],
|
|
90
93
|
platform = process.platform,
|
|
@@ -103,6 +106,11 @@ export function buildExecInvocation({
|
|
|
103
106
|
for (const [key, value] of mcpEnvOverrides) {
|
|
104
107
|
args.push('-c', `mcp_servers.SynaBun.env.${key}=${codexConfigString(value)}`);
|
|
105
108
|
}
|
|
109
|
+
const forwarded = [...new Set((Array.isArray(mcpEnvVars) ? mcpEnvVars : []).map(String))];
|
|
110
|
+
for (const name of forwarded) {
|
|
111
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(name)) throw new Error(`Invalid environment variable name: ${name}`);
|
|
112
|
+
}
|
|
113
|
+
if (forwarded.length) args.push('-c', `mcp_servers.SynaBun.env_vars=[${forwarded.map(codexConfigString).join(',')}]`);
|
|
106
114
|
const normalizedEffort = codexReasoningEffort(effort);
|
|
107
115
|
if (normalizedEffort) args.push('-c', `model_reasoning_effort=${codexConfigString(normalizedEffort)}`);
|
|
108
116
|
if (model) args.push('--model', String(model));
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
// isAllowedWebSocketOrigin(req, {port, allowedOrigins}) a browser's Origin must be this server, under one of its own names
|
|
26
26
|
// isAllowedHost(host, {allowedHosts, machineName}) is this Host one of our names, one DNS rebinding cannot borrow?
|
|
27
27
|
// hostNameOf(host) the name a Host header holds, as the rule compares it
|
|
28
|
-
// refuseUpgrade(socket, status)
|
|
28
|
+
// refuseUpgrade(socket, status, message?, headers?) answer the upgrade with an HTTP error, close
|
|
29
29
|
//
|
|
30
30
|
// isOwnerOrigin(origin, {port, ownNames, addresses}) a page of this server at its port, under loopback or one
|
|
31
31
|
// of this computer's names and addresses (tunnel start / stop)
|
|
@@ -51,8 +51,9 @@ import { machineNames as thisMachine } from './machine-names.js';
|
|
|
51
51
|
/** Headers that mean a proxy or tunnel forwarded the request (lower-case). */
|
|
52
52
|
export const PROXY_HEADERS = Object.freeze(['cf-connecting-ip', 'cf-ray', 'x-forwarded-for', 'x-forwarded-host', 'x-forwarded-proto', 'forwarded', 'x-real-ip', 'via']);
|
|
53
53
|
|
|
54
|
-
/** Headers that mark a request as an agent's rather than the user's (lower-case).
|
|
55
|
-
|
|
54
|
+
/** Headers that mark a request as an agent's rather than the user's (lower-case). A run's terminal token
|
|
55
|
+
* (lib/terminal-tokens.js) is one: only a run's own MCP server sends it, never the owner's page. */
|
|
56
|
+
export const AGENT_HEADERS = Object.freeze(['x-synabun-desktop-grant', 'x-synabun-terminal', 'x-synabun-role', 'x-synabun-assistant', 'x-synabun-terminal-token']);
|
|
56
57
|
|
|
57
58
|
const SAFE_METHODS = new Set(['GET', 'HEAD', 'OPTIONS']);
|
|
58
59
|
// RFC 3986 dec-octet: 0-255, no leading zeros (Node never reports them).
|
|
@@ -453,16 +454,20 @@ export function ownerRouteGuard({
|
|
|
453
454
|
return ownerRoute;
|
|
454
455
|
}
|
|
455
456
|
|
|
456
|
-
/** Answer a WebSocket upgrade with a plain HTTP error (default 403) and close the socket.
|
|
457
|
-
|
|
457
|
+
/** Answer a WebSocket upgrade with a plain HTTP error (default 403) and close the socket. `headers`: a few more
|
|
458
|
+
* (Retry-After for a 503); a name or value with a line break or a colon in the name is left out. */
|
|
459
|
+
export function refuseUpgrade(socket, status = 403, message = status === 403 ? 'Forbidden' : 'Bad Request', headers = {}) {
|
|
458
460
|
if (!socket) return;
|
|
459
461
|
// Node drops its own 'error' listener from an upgrade socket: without one, a
|
|
460
462
|
// peer reset while the answer is written would be an uncaught exception.
|
|
461
463
|
socket.on?.('error', () => { try { socket.destroy(); } catch {} });
|
|
462
464
|
if (!socket.writable) { try { socket.destroy(); } catch {} return; }
|
|
465
|
+
const extra = Object.entries(headers && typeof headers === 'object' ? headers : {})
|
|
466
|
+
.filter(([name, value]) => /^[A-Za-z0-9-]+$/.test(name) && !/[\r\n]/.test(String(value)))
|
|
467
|
+
.map(([name, value]) => `${name}: ${String(value)}\r\n`).join('');
|
|
463
468
|
try {
|
|
464
469
|
socket.once('finish', () => socket.destroy());
|
|
465
|
-
socket.end(`HTTP/1.1 ${status} ${message}\r\nConnection: close\r\
|
|
470
|
+
socket.end(`HTTP/1.1 ${status} ${message}\r\nConnection: close\r\n${extra}Content-Type: text/plain; charset=utf-8\r\nContent-Length: ${Buffer.byteLength(message)}\r\n\r\n${message}`);
|
|
466
471
|
} catch {
|
|
467
472
|
try { socket.destroy(); } catch {}
|
|
468
473
|
}
|