synabun 2.3.1 → 2.4.1
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 +41 -0
- package/README.md +1 -1
- package/browser-extension/content.js +189 -0
- package/browser-extension/engine.js +508 -0
- package/browser-extension/icons/icon-128.png +0 -0
- package/browser-extension/icons/icon-16.png +0 -0
- package/browser-extension/icons/icon-32.png +0 -0
- package/browser-extension/icons/icon-48.png +0 -0
- package/browser-extension/icons/status-off-16.png +0 -0
- package/browser-extension/icons/status-off-32.png +0 -0
- package/browser-extension/icons/status-off-48.png +0 -0
- package/browser-extension/icons/status-on-16.png +0 -0
- package/browser-extension/icons/status-on-32.png +0 -0
- package/browser-extension/icons/status-on-48.png +0 -0
- package/browser-extension/manifest.json +56 -0
- package/browser-extension/popup-strings.js +250 -0
- package/browser-extension/popup-view.js +151 -0
- package/browser-extension/popup.css +166 -0
- package/browser-extension/popup.html +108 -0
- package/browser-extension/popup.js +359 -0
- package/browser-extension/protocol.js +232 -0
- package/browser-extension/service-worker.js +275 -0
- package/browser-extension/setup-content.js +36 -0
- package/browser-extension/tokens.css +326 -0
- package/docs/browser-extension-bridge.md +84 -0
- package/docs/whatsapp.md +1 -1
- package/lib/data-home-files.js +45 -0
- package/lib/data-home-migration.js +34 -58
- package/mcp-server/dist/http.d.ts +2 -0
- package/mcp-server/dist/http.d.ts.map +1 -1
- package/mcp-server/dist/http.js +9 -1
- package/mcp-server/dist/http.js.map +1 -1
- package/mcp-server/dist/index.d.ts +11 -0
- package/mcp-server/dist/index.d.ts.map +1 -1
- package/mcp-server/dist/index.js +38 -3
- package/mcp-server/dist/index.js.map +1 -1
- package/mcp-server/dist/services/browser-route-flow.d.ts +6 -2
- package/mcp-server/dist/services/browser-route-flow.d.ts.map +1 -1
- package/mcp-server/dist/services/browser-route-flow.js +10 -3
- package/mcp-server/dist/services/browser-route-flow.js.map +1 -1
- package/mcp-server/dist/services/codex-config-heal.d.ts.map +1 -1
- package/mcp-server/dist/services/codex-config-heal.js +7 -0
- package/mcp-server/dist/services/codex-config-heal.js.map +1 -1
- package/mcp-server/dist/services/neural-interface.d.ts +95 -3
- package/mcp-server/dist/services/neural-interface.d.ts.map +1 -1
- package/mcp-server/dist/services/neural-interface.js +168 -23
- package/mcp-server/dist/services/neural-interface.js.map +1 -1
- package/mcp-server/dist/services/team-context.d.ts +18 -0
- package/mcp-server/dist/services/team-context.d.ts.map +1 -0
- package/mcp-server/dist/services/team-context.js +29 -0
- package/mcp-server/dist/services/team-context.js.map +1 -0
- package/mcp-server/dist/services/tool-catalog.d.ts +5 -2
- package/mcp-server/dist/services/tool-catalog.d.ts.map +1 -1
- package/mcp-server/dist/services/tool-catalog.js +22 -6
- package/mcp-server/dist/services/tool-catalog.js.map +1 -1
- package/mcp-server/dist/services/tool-list.d.ts.map +1 -1
- package/mcp-server/dist/services/tool-list.js +4 -0
- package/mcp-server/dist/services/tool-list.js.map +1 -1
- package/mcp-server/dist/services/tool-runtime.d.ts +8 -1
- package/mcp-server/dist/services/tool-runtime.d.ts.map +1 -1
- package/mcp-server/dist/services/tool-runtime.js +18 -1
- package/mcp-server/dist/services/tool-runtime.js.map +1 -1
- package/mcp-server/dist/tools/agent-definition.d.ts +133 -0
- package/mcp-server/dist/tools/agent-definition.d.ts.map +1 -0
- package/mcp-server/dist/tools/agent-definition.js +483 -0
- package/mcp-server/dist/tools/agent-definition.js.map +1 -0
- package/mcp-server/dist/tools/agents.d.ts +92 -9
- package/mcp-server/dist/tools/agents.d.ts.map +1 -1
- package/mcp-server/dist/tools/agents.js +163 -20
- package/mcp-server/dist/tools/agents.js.map +1 -1
- package/mcp-server/dist/tools/browser-advanced.d.ts +8 -1
- package/mcp-server/dist/tools/browser-advanced.d.ts.map +1 -1
- package/mcp-server/dist/tools/browser-advanced.js +70 -6
- package/mcp-server/dist/tools/browser-advanced.js.map +1 -1
- package/mcp-server/dist/tools/git-tools.d.ts +4 -2
- package/mcp-server/dist/tools/git-tools.d.ts.map +1 -1
- package/mcp-server/dist/tools/git-tools.js +283 -2
- package/mcp-server/dist/tools/git-tools.js.map +1 -1
- package/mcp-server/dist/tools/morelogin.d.ts +8 -2
- package/mcp-server/dist/tools/morelogin.d.ts.map +1 -1
- package/mcp-server/dist/tools/morelogin.js +22 -5
- package/mcp-server/dist/tools/morelogin.js.map +1 -1
- package/mcp-server/dist/tools/team.d.ts +32 -0
- package/mcp-server/dist/tools/team.d.ts.map +1 -0
- package/mcp-server/dist/tools/team.js +87 -0
- package/mcp-server/dist/tools/team.js.map +1 -0
- package/mcp-server/package-lock.json +2 -2
- package/mcp-server/package.json +1 -1
- package/mcp-server/src/http.ts +9 -1
- package/mcp-server/src/index.ts +34 -4
- package/mcp-server/src/services/browser-route-flow.ts +12 -5
- package/mcp-server/src/services/codex-config-heal.ts +7 -0
- package/mcp-server/src/services/neural-interface.ts +191 -29
- package/mcp-server/src/services/team-context.ts +27 -0
- package/mcp-server/src/services/tool-catalog.ts +26 -8
- package/mcp-server/src/services/tool-list.ts +4 -0
- package/mcp-server/src/services/tool-runtime.ts +21 -2
- package/mcp-server/src/tools/agent-definition.ts +458 -0
- package/mcp-server/src/tools/agents.ts +177 -19
- package/mcp-server/src/tools/browser-advanced.ts +60 -6
- package/mcp-server/src/tools/git-tools.ts +249 -3
- package/mcp-server/src/tools/morelogin.ts +20 -5
- package/mcp-server/src/tools/team.ts +97 -0
- package/neural-interface/i18n/en.json +1119 -47
- package/neural-interface/i18n/pt-BR.json +1119 -47
- package/neural-interface/lib/account-usage.js +1 -1
- package/neural-interface/lib/agents/builtins.json +207 -0
- package/neural-interface/lib/agents/density.js +101 -0
- package/neural-interface/lib/agents/forge-host.js +223 -0
- package/neural-interface/lib/agents/native-export-targets.js +190 -0
- package/neural-interface/lib/agents/native-export.js +365 -0
- package/neural-interface/lib/agents/registry.js +885 -0
- package/neural-interface/lib/agents/resolve.js +603 -0
- package/neural-interface/lib/agents/schema.js +642 -0
- package/neural-interface/lib/agents/split.js +37 -0
- package/neural-interface/lib/agents-studio-api.js +591 -0
- package/neural-interface/lib/assistant-api.js +76 -7
- package/neural-interface/lib/assistant-brains/opencode.js +60 -11
- package/neural-interface/lib/assistant-catalog.js +2 -0
- package/neural-interface/lib/assistant-continuity.js +49 -0
- package/neural-interface/lib/assistant-dispatch.js +351 -121
- package/neural-interface/lib/assistant-persona.js +105 -8
- package/neural-interface/lib/assistant-route-gate.js +24 -9
- package/neural-interface/lib/assistant-router.js +432 -47
- package/neural-interface/lib/assistant-run-tail.js +151 -0
- package/neural-interface/lib/assistant-run-wait.js +183 -0
- package/neural-interface/lib/assistant-runtime.js +449 -94
- package/neural-interface/lib/assistant-task-prompt.js +11 -2
- package/neural-interface/lib/assistant-usage.js +3 -2
- package/neural-interface/lib/automation-approval.js +2 -2
- package/neural-interface/lib/backup-service.js +64 -105
- package/neural-interface/lib/browser-close-evidence.js +80 -0
- package/neural-interface/lib/browser-default.js +210 -0
- package/neural-interface/lib/browser-extension-adapter.js +264 -0
- package/neural-interface/lib/browser-extension-bridge.js +441 -0
- package/neural-interface/lib/browser-extension-folder.js +116 -0
- package/neural-interface/lib/browser-extension-setup.js +140 -0
- package/neural-interface/lib/browser-profile-choices.js +3 -3
- package/neural-interface/lib/browser-tool-policy.js +1 -1
- package/neural-interface/lib/claude-account-links.js +301 -0
- package/neural-interface/lib/claude-accounts.js +45 -20
- package/neural-interface/lib/claude-agent-bridge.js +142 -10
- package/neural-interface/lib/claude-model-catalog.js +6 -0
- package/neural-interface/lib/claude-panel-session.js +33 -0
- package/neural-interface/lib/codex-accounts.js +67 -24
- package/neural-interface/lib/coordination/README.md +384 -0
- package/neural-interface/lib/coordination/service.js +563 -0
- package/neural-interface/lib/coordination/store.js +1138 -0
- package/neural-interface/lib/db.js +22 -1
- package/neural-interface/lib/effort-levels.js +10 -1
- package/neural-interface/lib/memory-list-page.js +49 -0
- package/neural-interface/lib/memory-list-stamp.js +60 -0
- package/neural-interface/lib/morelogin-outside-close.js +186 -0
- package/neural-interface/lib/morelogin-profile-failures.js +206 -0
- package/neural-interface/lib/morelogin-start-cooldown.js +160 -0
- package/neural-interface/lib/morelogin.js +194 -8
- package/neural-interface/lib/native-loop-runtime.js +26 -7
- package/neural-interface/lib/opencode-build-preflight.js +28 -8
- package/neural-interface/lib/opencode-native-boundary.js +83 -13
- package/neural-interface/lib/opencode-serve-records.js +14 -9
- package/neural-interface/lib/page-session.js +1 -1
- package/neural-interface/lib/peer-identity.js +73 -29
- package/neural-interface/lib/process-identity.js +68 -7
- package/neural-interface/lib/request-gate.js +3 -0
- package/neural-interface/lib/screenshot-location.js +33 -0
- package/neural-interface/lib/session-cache-builder.js +41 -3
- package/neural-interface/lib/skills/creation.js +1 -1
- package/neural-interface/lib/skills/known-bridge-digests.json +40 -0
- package/neural-interface/lib/studio-attention.js +56 -0
- package/neural-interface/lib/teams/README.md +382 -0
- package/neural-interface/lib/teams/api.js +287 -0
- package/neural-interface/lib/teams/brief.js +185 -0
- package/neural-interface/lib/teams/claims.js +315 -0
- package/neural-interface/lib/teams/git.js +293 -0
- package/neural-interface/lib/teams/index.js +122 -0
- package/neural-interface/lib/teams/integration.js +580 -0
- package/neural-interface/lib/teams/landing.js +184 -0
- package/neural-interface/lib/teams/recovery.js +256 -0
- package/neural-interface/lib/teams/scheduler.js +1474 -0
- package/neural-interface/lib/teams/schema.js +559 -0
- package/neural-interface/lib/teams/state.js +181 -0
- package/neural-interface/lib/teams/test-runner.js +86 -0
- package/neural-interface/lib/teams/test-sandbox.js +99 -0
- package/neural-interface/lib/teams/worktrees.js +757 -0
- package/neural-interface/lib/tool-permission-choices.js +226 -0
- package/neural-interface/lib/whatsapp/cards.js +24 -10
- package/neural-interface/lib/worker-confinement.js +206 -6
- package/neural-interface/package-lock.json +2 -2
- package/neural-interface/package.json +1 -1
- package/neural-interface/public/extension-setup.html +107 -0
- package/neural-interface/public/index.html +103 -12
- package/neural-interface/public/offline.html +4 -3
- package/neural-interface/public/shared/agent-runtime-options.js +3 -1
- package/neural-interface/public/shared/agents/studio/ax-agent-view.js +614 -0
- package/neural-interface/public/shared/agents/studio/ax-api.js +198 -0
- package/neural-interface/public/shared/agents/studio/ax-create-view.js +221 -0
- package/neural-interface/public/shared/agents/studio/ax-diff.js +143 -0
- package/neural-interface/public/shared/agents/studio/ax-editor-view.js +392 -0
- package/neural-interface/public/shared/agents/studio/ax-export-view.js +94 -0
- package/neural-interface/public/shared/agents/studio/ax-form.js +191 -0
- package/neural-interface/public/shared/agents/studio/ax-icons.js +87 -0
- package/neural-interface/public/shared/agents/studio/ax-library-view.js +158 -0
- package/neural-interface/public/shared/agents/studio/ax-library.js +162 -0
- package/neural-interface/public/shared/agents/studio/ax-main.js +712 -0
- package/neural-interface/public/shared/agents/studio/ax-native-export.js +35 -0
- package/neural-interface/public/shared/agents/studio/ax-options.js +198 -0
- package/neural-interface/public/shared/agents/studio/ax-review-view.js +175 -0
- package/neural-interface/public/shared/agents/studio/ax-revisions-view.js +189 -0
- package/neural-interface/public/shared/agents/studio/ax-runs-view.js +202 -0
- package/neural-interface/public/shared/agents/studio/ax-runs.js +82 -0
- package/neural-interface/public/shared/agents/studio/ax-teams-view.js +256 -0
- package/neural-interface/public/shared/agents/studio/ax-teams.js +200 -0
- package/neural-interface/public/shared/agents/studio/ax-templates.js +50 -0
- package/neural-interface/public/shared/agents/studio/ax-ui.js +194 -0
- package/neural-interface/public/shared/agents/studio/ax-views.js +170 -0
- package/neural-interface/public/shared/agy/agy-panel.js +142 -28
- package/neural-interface/public/shared/agy/agy-styles.js +25 -5
- package/neural-interface/public/shared/api.js +2 -1
- package/neural-interface/public/shared/assistant/asst-account-menu.js +13 -13
- package/neural-interface/public/shared/assistant/asst-ask-styles.js +2 -3
- package/neural-interface/public/shared/assistant/asst-brain-picker.js +91 -9
- package/neural-interface/public/shared/assistant/asst-control.js +3 -0
- package/neural-interface/public/shared/assistant/asst-interaction-hold.js +99 -0
- package/neural-interface/public/shared/assistant/asst-limit-dismissals.js +111 -0
- package/neural-interface/public/shared/assistant/asst-limit-dock.js +37 -3
- package/neural-interface/public/shared/assistant/asst-limit-wait.js +30 -7
- package/neural-interface/public/shared/assistant/asst-panel.js +177 -30
- package/neural-interface/public/shared/assistant/asst-rack-styles.js +15 -8
- package/neural-interface/public/shared/assistant/asst-render.js +37 -6
- package/neural-interface/public/shared/assistant/asst-route.js +80 -12
- package/neural-interface/public/shared/assistant/asst-routes-editor.js +148 -70
- package/neural-interface/public/shared/assistant/asst-roving.js +17 -1
- package/neural-interface/public/shared/assistant/asst-scene-styles.js +7 -2
- package/neural-interface/public/shared/assistant/asst-scenes.js +12 -1
- package/neural-interface/public/shared/assistant/asst-sidepanel.js +12 -2
- package/neural-interface/public/shared/assistant/asst-state.js +66 -1
- package/neural-interface/public/shared/assistant/asst-styles.js +98 -44
- package/neural-interface/public/shared/assistant/route-identity.js +16 -0
- package/neural-interface/public/shared/cc-dropdown.js +21 -15
- package/neural-interface/public/shared/cdx/cdx-output.js +10 -0
- package/neural-interface/public/shared/cdx/cdx-panel.js +18 -16
- package/neural-interface/public/shared/cdx/cdx-plan.js +3 -2
- package/neural-interface/public/shared/cdx/cdx-render.js +122 -45
- package/neural-interface/public/shared/cdx/cdx-requests.js +4 -4
- package/neural-interface/public/shared/cdx/cdx-styles.js +8 -36
- package/neural-interface/public/shared/cdx/cdx-tabs.js +110 -42
- package/neural-interface/public/shared/claude-panel-lazy.js +12 -0
- package/neural-interface/public/shared/code-copy.js +120 -0
- package/neural-interface/public/shared/constants.js +7 -0
- package/neural-interface/public/shared/context-menu-model.js +1 -0
- package/neural-interface/public/shared/cp/cp-markdown.js +7 -2
- package/neural-interface/public/shared/cp/cp-session-model.js +86 -5
- package/neural-interface/public/shared/cp/cp-session-settings.js +58 -30
- package/neural-interface/public/shared/cp/cp-styles.js +9 -0
- package/neural-interface/public/shared/dom-change-flag.js +66 -0
- package/neural-interface/public/shared/dom-morph.js +124 -0
- package/neural-interface/public/shared/extension-setup/es-page.css +134 -0
- package/neural-interface/public/shared/extension-setup/es-page.js +120 -0
- package/neural-interface/public/shared/extension-setup/es-view.js +100 -0
- package/neural-interface/public/shared/html-shell.js +34 -4
- package/neural-interface/public/shared/i18n.js +14 -1
- package/neural-interface/public/shared/idle-queue.js +78 -0
- package/neural-interface/public/shared/iface-config.js +227 -0
- package/neural-interface/public/shared/lazy-module.js +108 -0
- package/neural-interface/public/shared/memory-list.js +117 -0
- package/neural-interface/public/shared/morelogin-profile-choices.js +1 -1
- package/neural-interface/public/shared/morelogin-profile-field.js +3 -3
- package/neural-interface/public/shared/mtc/mtc-panel.js +3 -1
- package/neural-interface/public/shared/mtc/mtc-styles.js +4 -1
- package/neural-interface/public/shared/ocp-v2/ocp-v2-manager.js +35 -15
- package/neural-interface/public/shared/ocp-v2/ocp-v2-panel.js +77 -23
- package/neural-interface/public/shared/ocp-v2/ocp-v2-projectbar.js +3 -6
- package/neural-interface/public/shared/ocp-v2/ocp-v2-render.js +24 -21
- package/neural-interface/public/shared/ocp-v2/ocp-v2-send-logic.js +16 -5
- package/neural-interface/public/shared/ocp-v2/ocp-v2-sessions-logic.js +16 -2
- package/neural-interface/public/shared/ocp-v2/ocp-v2-styles.js +27 -43
- package/neural-interface/public/shared/ocp-v2/ocp-v2-ws.js +73 -9
- package/neural-interface/public/shared/owner-authority-view.js +4 -10
- package/neural-interface/public/shared/page-session.js +1 -1
- package/neural-interface/public/shared/schedules-view.js +2 -2
- package/neural-interface/public/shared/session-project-items.js +11 -0
- package/neural-interface/public/shared/settings/settings-ai-browser.js +119 -0
- package/neural-interface/public/shared/settings/settings-browser-extension.js +446 -0
- package/neural-interface/public/shared/settings/settings-ia.js +4 -2
- package/neural-interface/public/shared/settings/settings-morelogin-cooldown.js +63 -0
- package/neural-interface/public/shared/settings/settings-tool-permissions.js +70 -0
- package/neural-interface/public/shared/sidepanel-lazy.js +40 -0
- package/neural-interface/public/shared/sidepanel-session-status.js +8 -14
- package/neural-interface/public/shared/sidepanel-shown.js +73 -0
- package/neural-interface/public/shared/start-bridge.js +2 -2
- package/neural-interface/public/shared/storage.js +6 -1
- package/neural-interface/public/shared/studio-attention.js +83 -0
- package/neural-interface/public/shared/styles.css +694 -50
- package/neural-interface/public/shared/term-browser-tabs.js +34 -0
- package/neural-interface/public/shared/transcript-rows.js +334 -0
- package/neural-interface/public/shared/tray-auto-close.js +106 -0
- package/neural-interface/public/shared/ui-agents.js +97 -0
- package/neural-interface/public/shared/ui-antigravity-panel.js +16 -14
- package/neural-interface/public/shared/ui-automation-studio.js +3 -3
- package/neural-interface/public/shared/ui-claude-panel.js +162 -95
- package/neural-interface/public/shared/ui-code-copy.js +256 -0
- package/neural-interface/public/shared/ui-codex-panel.js +14 -10
- package/neural-interface/public/shared/ui-context-menu.js +1 -1
- package/neural-interface/public/shared/ui-file-explorer.js +2 -3
- package/neural-interface/public/shared/ui-games.js +1 -1
- package/neural-interface/public/shared/ui-loading.js +83 -19
- package/neural-interface/public/shared/ui-maritaca-panel.js +12 -11
- package/neural-interface/public/shared/ui-menubar.js +23 -0
- package/neural-interface/public/shared/ui-native-loop-router.js +50 -21
- package/neural-interface/public/shared/ui-navbar.js +15 -9
- package/neural-interface/public/shared/ui-opencode-panel-v2.js +13 -11
- package/neural-interface/public/shared/ui-owner-authority.js +48 -25
- package/neural-interface/public/shared/ui-schedules-studio.js +3 -3
- package/neural-interface/public/shared/ui-scroll-follow.js +39 -0
- package/neural-interface/public/shared/ui-sessions.js +3 -3
- package/neural-interface/public/shared/ui-settings-entry.js +55 -0
- package/neural-interface/public/shared/ui-settings.js +363 -400
- package/neural-interface/public/shared/ui-sidepanel-layout.js +44 -25
- package/neural-interface/public/shared/ui-sidepanel-session-entry.js +22 -9
- package/neural-interface/public/shared/ui-sidepanel-sessions.js +10 -2
- package/neural-interface/public/shared/ui-sidepanel-tray.js +36 -41
- package/neural-interface/public/shared/ui-sidepanel-windows.js +14 -1
- package/neural-interface/public/shared/ui-styleguide.js +10 -2
- package/neural-interface/public/shared/ui-sync.js +6 -0
- package/neural-interface/public/shared/ui-terminal.js +13 -9
- package/neural-interface/public/shared/ui-tooltip.js +28 -7
- package/neural-interface/public/shared/ui-topright-overflow.js +26 -4
- package/neural-interface/public/shared/ui-tray-columns.js +375 -0
- package/neural-interface/public/shared/ui-whiteboard.js +51 -6
- package/neural-interface/public/shared/ui-worker-end.js +28 -1
- package/neural-interface/public/shared/ui-workspaces.js +13 -0
- package/neural-interface/public/shared/window-keys.js +71 -0
- package/neural-interface/public/sw.js +4 -3
- package/neural-interface/public/variant/2d/main.js +2 -0
- package/neural-interface/public/variant/3d/app.js +620 -0
- package/neural-interface/public/variant/3d/boot-reveal.js +47 -0
- package/neural-interface/public/variant/3d/main.js +30 -544
- package/neural-interface/public/variant/3d/map-controls.js +4 -2
- package/neural-interface/public/vendor/fonts/fonts.css +508 -0
- package/neural-interface/public/vendor/fonts/inter-OFL.txt +93 -0
- package/neural-interface/public/vendor/fonts/inter-cyrillic-ext.woff2 +0 -0
- package/neural-interface/public/vendor/fonts/inter-cyrillic.woff2 +0 -0
- package/neural-interface/public/vendor/fonts/inter-greek-ext.woff2 +0 -0
- package/neural-interface/public/vendor/fonts/inter-greek.woff2 +0 -0
- package/neural-interface/public/vendor/fonts/inter-latin-ext.woff2 +0 -0
- package/neural-interface/public/vendor/fonts/inter-latin.woff2 +0 -0
- package/neural-interface/public/vendor/fonts/inter-vietnamese.woff2 +0 -0
- package/neural-interface/public/vendor/fonts/jetbrains-mono-OFL.txt +93 -0
- package/neural-interface/public/vendor/fonts/jetbrains-mono-cyrillic-ext.woff2 +0 -0
- package/neural-interface/public/vendor/fonts/jetbrains-mono-cyrillic.woff2 +0 -0
- package/neural-interface/public/vendor/fonts/jetbrains-mono-greek.woff2 +0 -0
- package/neural-interface/public/vendor/fonts/jetbrains-mono-latin-ext.woff2 +0 -0
- package/neural-interface/public/vendor/fonts/jetbrains-mono-latin.woff2 +0 -0
- package/neural-interface/public/vendor/fonts/jetbrains-mono-vietnamese.woff2 +0 -0
- package/neural-interface/public/vendor/fonts/manifest.json +142 -0
- package/neural-interface/public/vendor/fonts/space-grotesk-OFL.txt +93 -0
- package/neural-interface/public/vendor/fonts/space-grotesk-latin-ext.woff2 +0 -0
- package/neural-interface/public/vendor/fonts/space-grotesk-latin.woff2 +0 -0
- package/neural-interface/public/vendor/fonts/space-grotesk-vietnamese.woff2 +0 -0
- package/neural-interface/scripts/boot-graph.mjs +270 -0
- package/neural-interface/scripts/vendor-fonts.mjs +124 -0
- package/neural-interface/server.js +1083 -164
- package/npm-shrinkwrap.json +2 -2
- package/package.json +4 -1
- package/skills/agent-forge/SKILL.md +182 -0
- package/skills/agent-forge/evals/evals.json +56 -0
- package/skills/agent-forge/references/definition-fields.md +61 -0
- package/skills/agent-forge/references/examples.md +105 -0
- package/skills/agent-forge/references/instructions.md +51 -0
- package/skills/agent-forge/references/review-and-export.md +84 -0
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
// Shared, dependency-free wire contract. Never send credentials or page content to a logger.
|
|
2
|
+
export const VERSION = 1;
|
|
3
|
+
export const MAX_MESSAGE = 4 * 1024 * 1024;
|
|
4
|
+
export const MAX_FILE = 50 * 1024 * 1024;
|
|
5
|
+
export const ID = /^[a-zA-Z0-9_-]{1,128}$/;
|
|
6
|
+
// How long the server waits for the answer to one command (COMMAND_WAIT). Every command carries what is left of that
|
|
7
|
+
// wait when it is sent (`deadline`, relative milliseconds, so the two clocks never have to agree; the HMAC protects it).
|
|
8
|
+
// The extension turns it into a local deadline the moment the message arrives, less a safety margin (localDeadline), and
|
|
9
|
+
// never starts or continues a command past it: queued, running, or as a content-script action already dispatched.
|
|
10
|
+
export const COMMAND_WAIT = 25000;
|
|
11
|
+
export const DEADLINE_MARGIN = 1000;
|
|
12
|
+
// The safety margin for a budget: 1 s, or a tenth of a shorter one.
|
|
13
|
+
export function reserve(deadline) { return Math.min(DEADLINE_MARGIN, Math.floor(deadline / 10)); }
|
|
14
|
+
// The local time (on `now`'s clock) at which a command received at `receivedAt` with `deadline` ms left must stop, one
|
|
15
|
+
// margin early, so the extension always stops before the server gives up. The worker's queue also never starts a command
|
|
16
|
+
// in the last margin before that (a command freed only by the one ahead of it reaching its own deadline gets no sliver).
|
|
17
|
+
export function localDeadline(receivedAt, deadline) { return receivedAt + deadline - reserve(deadline); }
|
|
18
|
+
// The watchdog for a browser call that never returns: once a command runs, the queue waits at most this long for it.
|
|
19
|
+
// It never gives a command more time than its deadline; the effective limit is the earlier of the two.
|
|
20
|
+
export const QUEUE_LIMIT = 30000;
|
|
21
|
+
export function fail(code, message = code) { throw Object.assign(new Error(message), { code }); }
|
|
22
|
+
export function object(value, keys) {
|
|
23
|
+
if (!value || typeof value !== 'object' || Array.isArray(value) || Object.keys(value).some(k => !keys.includes(k))) fail('INVALID_MESSAGE');
|
|
24
|
+
}
|
|
25
|
+
export function string(value, max = 128) { if (typeof value !== 'string' || value.length > max) fail('INVALID_MESSAGE'); return value; }
|
|
26
|
+
export function handle(value) { if (!ID.test(string(value))) fail('INVALID_MESSAGE'); return value; }
|
|
27
|
+
export function parse(raw, max = MAX_MESSAGE) {
|
|
28
|
+
if (typeof raw !== 'string' || new TextEncoder().encode(raw).length > max) fail('MESSAGE_TOO_LARGE');
|
|
29
|
+
try { return JSON.parse(raw); } catch { fail('INVALID_MESSAGE'); }
|
|
30
|
+
}
|
|
31
|
+
export function nonce() { return crypto.randomUUID().replaceAll('-', ''); }
|
|
32
|
+
const bytes = s => new TextEncoder().encode(s);
|
|
33
|
+
export async function mac(key, value) {
|
|
34
|
+
const k = await crypto.subtle.importKey('raw', bytes(key), { name: 'HMAC', hash: 'SHA-256' }, false, ['sign']);
|
|
35
|
+
return Array.from(new Uint8Array(await crypto.subtle.sign('HMAC', k, bytes(value))), b => b.toString(16).padStart(2, '0')).join('');
|
|
36
|
+
}
|
|
37
|
+
export async function equalMac(key, value, supplied) {
|
|
38
|
+
if (typeof supplied !== 'string' || !/^[a-f0-9]{64}$/.test(supplied)) return false;
|
|
39
|
+
const expected = await mac(key, value);
|
|
40
|
+
let diff = 0; for (let i = 0; i < 64; i++) diff |= expected.charCodeAt(i) ^ supplied.charCodeAt(i);
|
|
41
|
+
return diff === 0;
|
|
42
|
+
}
|
|
43
|
+
export async function pairingKey(code) { return mac(code.replaceAll('-', '').trim().toLowerCase(), 'synabun-extension-pair-v1'); }
|
|
44
|
+
export function channel(key, session, sendDirection) {
|
|
45
|
+
let sent = 0, received = 0;
|
|
46
|
+
return {
|
|
47
|
+
// `deliver(raw)`, when given, runs synchronously right after signing; if it throws, the sequence number is not
|
|
48
|
+
// used, so a message refused at the last moment (cancelled, timed out) never leaves a gap the peer would reject.
|
|
49
|
+
async encode(payload, deliver) {
|
|
50
|
+
const msg = { v: VERSION, session, direction: sendDirection, seq: sent + 1, payload };
|
|
51
|
+
const signed = { ...msg, mac: await mac(key, JSON.stringify(msg)) };
|
|
52
|
+
const raw = JSON.stringify(signed); parse(raw);
|
|
53
|
+
if (signed.seq !== sent + 1) fail('REPLAY_REJECTED');
|
|
54
|
+
deliver?.(raw); sent++; return raw;
|
|
55
|
+
},
|
|
56
|
+
async decode(raw) {
|
|
57
|
+
const msg = parse(raw); object(msg, ['v', 'session', 'direction', 'seq', 'payload', 'mac']);
|
|
58
|
+
if (msg.v !== VERSION || msg.session !== session || msg.direction === sendDirection || !['server', 'extension'].includes(msg.direction)
|
|
59
|
+
|| !Number.isSafeInteger(msg.seq) || msg.seq !== received + 1) fail('REPLAY_REJECTED');
|
|
60
|
+
const { mac: signature, ...body } = msg;
|
|
61
|
+
if (!await equalMac(key, JSON.stringify(body), signature)) fail('AUTH_FAILED');
|
|
62
|
+
received = msg.seq; return msg.payload;
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
// Deliberately excludes local/private IP literals and single-label hosts, browser stores and control surfaces.
|
|
67
|
+
// Exact origins are approved; DNS rebinding is additionally blocked server-side at each command.
|
|
68
|
+
export function publicOrigin(url) {
|
|
69
|
+
let u; try { u = new URL(string(url, 8192)); } catch { fail('SITE_NOT_APPROVED'); }
|
|
70
|
+
const h = u.hostname.toLowerCase();
|
|
71
|
+
if (!['https:', 'http:'].includes(u.protocol) || u.username || u.password || !h.includes('.') || h.includes(':')
|
|
72
|
+
|| /(^|\.)(localhost|local|internal|test|invalid)$/.test(h) || /^\d+(\.\d+){3}$/.test(h)
|
|
73
|
+
|| ['chromewebstore.google.com', 'chrome.google.com', 'microsoftedge.microsoft.com'].includes(h)) fail('SITE_NOT_APPROVED');
|
|
74
|
+
return u.origin;
|
|
75
|
+
}
|
|
76
|
+
export function hostPattern(url) { const u = new URL(publicOrigin(url)); return `${u.protocol}//${u.hostname}/*`; }
|
|
77
|
+
// Pages no extension may script or capture, whatever its permissions (an API limit of Chrome and Edge, not a setting).
|
|
78
|
+
export const RESTRICTED_HOSTS = ['chromewebstore.google.com', 'chrome.google.com', 'microsoftedge.microsoft.com'];
|
|
79
|
+
// Full control: any http(s) page, or the blank start page. Returns the URL's origin ('about:blank' for that page).
|
|
80
|
+
// Everything else (chrome://, edge://, extension pages, file:, view-source:, the Web Store) is RESTRICTED_PAGE.
|
|
81
|
+
export function anyOrigin(url) {
|
|
82
|
+
let u; try { u = new URL(string(url, 8192)); } catch { fail('RESTRICTED_PAGE'); }
|
|
83
|
+
if (u.href === 'about:blank') return 'about:blank';
|
|
84
|
+
if (!['https:', 'http:'].includes(u.protocol) || RESTRICTED_HOSTS.includes(u.hostname.toLowerCase())) fail('RESTRICTED_PAGE');
|
|
85
|
+
return u.origin;
|
|
86
|
+
}
|
|
87
|
+
const bare = h => String(h || '').toLowerCase().replace(/^\[|\]$/g, '').replace(/\.$/, '');
|
|
88
|
+
// A host name that is this computer by its form alone: localhost (and *.localhost), a loopback or unspecified address,
|
|
89
|
+
// or one of `selfHosts` (the server's names and interface addresses, sent with every command). The server also asks DNS.
|
|
90
|
+
export function localHost(hostname, selfHosts = []) {
|
|
91
|
+
const h = bare(hostname);
|
|
92
|
+
if (!h) return false;
|
|
93
|
+
if (h === 'localhost' || h.endsWith('.localhost') || h === '0.0.0.0' || h === '::' || h === '::1') return true;
|
|
94
|
+
if (/^127\.\d+\.\d+\.\d+$/.test(h) || /^::ffff:(127\.|0\.0\.0\.0$)/.test(h) || /^::ffff:7f[0-9a-f]{2}:/.test(h) || h === '::ffff:0:0') return true;
|
|
95
|
+
return selfHosts.some(x => bare(x) === h);
|
|
96
|
+
}
|
|
97
|
+
// The port a URL reaches (its default when it names none).
|
|
98
|
+
export function portOf(u) { return Number(u.port || (u.protocol === 'https:' ? 443 : u.protocol === 'http:' ? 80 : 0)); }
|
|
99
|
+
// SynaBun's own interface and API (its ports on this computer) and its public aliases (the tunnel, the invite proxy:
|
|
100
|
+
// `blockedHosts`, any port) stay behind SynaBun's owner rules: an agent never reaches them through the owner's browser.
|
|
101
|
+
export function controlSurface(url, { blockedHosts = [], blockedPorts = [], selfHosts = [] } = {}) {
|
|
102
|
+
if (!url || url === 'about:blank') return false;
|
|
103
|
+
let u; try { u = new URL(url); } catch { return false; }
|
|
104
|
+
if (!['https:', 'http:'].includes(u.protocol)) return false;
|
|
105
|
+
const host = bare(u.hostname);
|
|
106
|
+
if (blockedHosts.some(x => bare(x) === host)) return true;
|
|
107
|
+
return blockedPorts.includes(portOf(u)) && localHost(host, selfHosts);
|
|
108
|
+
}
|
|
109
|
+
// How many tabs an inventory lists (the ones agents control first; in full control the owner's other tabs after).
|
|
110
|
+
export const MAX_TABS = 200;
|
|
111
|
+
// `versions[i]` is the approval version of `sites[i]`: raised only by the owner's gesture in the popup, so the server can
|
|
112
|
+
// tell a fresh approval of a site it revoked from an inventory that predates the revocation.
|
|
113
|
+
export function inventory(value) {
|
|
114
|
+
object(value, ['tabs', 'sites', 'versions', 'allowNewTabs', 'uploads', 'downloads', 'fullControl', 'modeVersion']);
|
|
115
|
+
if (!Array.isArray(value.tabs) || value.tabs.length > MAX_TABS || !Array.isArray(value.sites) || value.sites.length > 100) fail('INVALID_MESSAGE');
|
|
116
|
+
for (const key of ['allowNewTabs', 'uploads', 'downloads']) if (typeof value[key] !== 'boolean') fail('INVALID_MESSAGE');
|
|
117
|
+
// The mode (full control or restricted) and its version. Optional, so an extension from before full control still
|
|
118
|
+
// connects (it is then treated as restricted, which is what it enforces); the two come together.
|
|
119
|
+
if ((value.fullControl === undefined) !== (value.modeVersion === undefined)) fail('INVALID_MESSAGE');
|
|
120
|
+
if (value.fullControl !== undefined && (typeof value.fullControl !== 'boolean' || !Number.isSafeInteger(value.modeVersion) || value.modeVersion < 0)) fail('INVALID_MESSAGE');
|
|
121
|
+
for (const site of value.sites) if (publicOrigin(site) !== site) fail('INVALID_MESSAGE');
|
|
122
|
+
if (value.versions !== undefined && (!Array.isArray(value.versions) || value.versions.length !== value.sites.length
|
|
123
|
+
|| value.versions.some(v => !Number.isSafeInteger(v) || v < 0))) fail('INVALID_MESSAGE');
|
|
124
|
+
const seen = new Set();
|
|
125
|
+
for (const t of value.tabs) {
|
|
126
|
+
object(t, ['handle', 'url', 'owner', 'created', 'title']); handle(t.handle); string(t.url, 8192);
|
|
127
|
+
if (t.title !== undefined) string(t.title, 300);
|
|
128
|
+
if (t.owner !== null) handle(t.owner);
|
|
129
|
+
if (typeof t.created !== 'boolean' || seen.has(t.handle)) fail('INVALID_MESSAGE');
|
|
130
|
+
seen.add(t.handle);
|
|
131
|
+
}
|
|
132
|
+
return value;
|
|
133
|
+
}
|
|
134
|
+
export const COMMANDS = ['create', 'claim', 'release', 'navigate', 'back', 'forward', 'reload', 'snapshot', 'click', 'hover', 'fill', 'type', 'press', 'select', 'scroll', 'wait', 'content', 'screenshot', 'upload', 'download', 'revokeTab', 'revokeSite', 'disconnect', 'revoke', 'mode', 'reset'];
|
|
135
|
+
export const HISTORY = ['back', 'forward'];
|
|
136
|
+
// The owner's control messages: revocations, the mode (full control or restricted) and `reset` (a restarted server
|
|
137
|
+
// hands back every tab agents of its previous process held). They overtake queued commands on both sides, are never
|
|
138
|
+
// cancelled themselves, and carry the owner's name only: nothing an agent sends can be one.
|
|
139
|
+
export const CONTROL = ['revokeTab', 'revokeSite', 'disconnect', 'revoke', 'mode', 'reset'];
|
|
140
|
+
export function command(value) {
|
|
141
|
+
object(value, ['type', 'id', 'op', 'tab', 'owner', 'args', 'blockedHosts', 'blockedPorts', 'selfHosts', 'deadline']);
|
|
142
|
+
if (value.type !== 'command' || !COMMANDS.includes(value.op)) fail('UNSUPPORTED_IN_EXTENSION_MODE');
|
|
143
|
+
handle(value.id); if (value.tab !== null) handle(value.tab); handle(value.owner);
|
|
144
|
+
// Required on every command: whole milliseconds, 1 to COMMAND_WAIT (the server never has more left than its wait).
|
|
145
|
+
if (!Number.isSafeInteger(value.deadline) || value.deadline < 1 || value.deadline > COMMAND_WAIT) fail('INVALID_MESSAGE');
|
|
146
|
+
// SynaBun's own addresses, which no command may reach (controlSurface): its public aliases (any port), its ports,
|
|
147
|
+
// and this computer's names and interface addresses.
|
|
148
|
+
for (const key of ['blockedHosts', 'selfHosts']) {
|
|
149
|
+
if (value[key] !== undefined && (!Array.isArray(value[key]) || value[key].length > 200 || value[key].some(h => typeof h !== 'string' || h.length > 253 || !/^[a-zA-Z0-9.:%-]+$/.test(h)))) fail('INVALID_MESSAGE');
|
|
150
|
+
}
|
|
151
|
+
if (value.blockedPorts !== undefined && (!Array.isArray(value.blockedPorts) || value.blockedPorts.length > 32 || value.blockedPorts.some(p => !Number.isSafeInteger(p) || p < 1 || p > 65535))) fail('INVALID_MESSAGE');
|
|
152
|
+
const a = value.args; object(a, ['url', 'ref', 'selector', 'nthMatch', 'value', 'text', 'key', 'direction', 'distance', 'maxChars', 'offset', 'timeout', 'state', 'files', 'site', 'fullControl', 'version']);
|
|
153
|
+
for (const [k, v] of Object.entries(a)) {
|
|
154
|
+
if (k === 'fullControl') { if (typeof v !== 'boolean') fail('INVALID_MESSAGE'); }
|
|
155
|
+
else if (k === 'version') { if (!Number.isSafeInteger(v) || v < 0) fail('INVALID_MESSAGE'); }
|
|
156
|
+
else if (['nthMatch', 'distance', 'maxChars', 'offset', 'timeout'].includes(k)) {
|
|
157
|
+
if (!Number.isSafeInteger(v) || v < 0 || v > 1000000) fail('INVALID_MESSAGE');
|
|
158
|
+
} else if (k === 'files') {
|
|
159
|
+
if (!Array.isArray(v) || v.length < 1 || v.length > 4) fail('INVALID_MESSAGE');
|
|
160
|
+
if (value.op !== 'upload') fail('INVALID_MESSAGE');
|
|
161
|
+
for (const name of v) {
|
|
162
|
+
string(name, 255);
|
|
163
|
+
if (!name || /[\\/]/.test(name)) fail('INVALID_MESSAGE');
|
|
164
|
+
}
|
|
165
|
+
} else string(v, k === 'text' || k === 'value' ? 100000 : 8192);
|
|
166
|
+
}
|
|
167
|
+
const required = { navigate: 'url', download: 'url', revokeSite: 'site', fill: 'value', type: 'text', select: 'value', press: 'key' }[value.op];
|
|
168
|
+
if (required && typeof a[required] !== 'string') fail('INVALID_MESSAGE');
|
|
169
|
+
// The mode travels only as the owner's `mode` message, with its version.
|
|
170
|
+
if (value.op === 'mode' && (typeof a.fullControl !== 'boolean' || a.version === undefined || value.owner !== 'owner')) fail('INVALID_MESSAGE');
|
|
171
|
+
if ((a.fullControl !== undefined || a.version !== undefined) && value.op !== 'mode') fail('INVALID_MESSAGE');
|
|
172
|
+
if (['click', 'hover', 'fill', 'select', 'upload'].includes(value.op) && !a.ref && !a.selector) fail('INVALID_MESSAGE');
|
|
173
|
+
if (value.op === 'upload' && !a.files) fail('INVALID_MESSAGE');
|
|
174
|
+
// History traversal names no destination: it carries a tab and nothing else.
|
|
175
|
+
if (HISTORY.includes(value.op) && (value.tab === null || Object.keys(a).length)) fail('INVALID_MESSAGE');
|
|
176
|
+
if (a.direction !== undefined && !['up', 'down', 'left', 'right'].includes(a.direction)) fail('INVALID_MESSAGE');
|
|
177
|
+
if (a.state !== undefined && !['visible', 'hidden', 'attached', 'detached'].includes(a.state)) fail('INVALID_MESSAGE');
|
|
178
|
+
return value;
|
|
179
|
+
}
|
|
180
|
+
export function payload(value) {
|
|
181
|
+
if (value?.type === 'state') { object(value, ['type', 'inventory']); inventory(value.inventory); }
|
|
182
|
+
else if (value?.type === 'result') {
|
|
183
|
+
object(value, ['type', 'id', 'result', 'inventory']); handle(value.id); inventory(value.inventory);
|
|
184
|
+
object(value.result, ['ok', 'code', 'error', 'url', 'title', 'snapshotText', 'mode', 'snapshotId', 'content', 'text', 'base64', 'mimeType', 'tab', 'downloadId']);
|
|
185
|
+
if (typeof value.result.ok !== 'boolean') fail('INVALID_MESSAGE');
|
|
186
|
+
for (const [k, v] of Object.entries(value.result)) {
|
|
187
|
+
if (k === 'ok') continue;
|
|
188
|
+
if (k === 'downloadId') { if (!Number.isSafeInteger(v)) fail('INVALID_MESSAGE'); }
|
|
189
|
+
else string(v, k === 'base64' ? MAX_MESSAGE - 4096 : ['content', 'text', 'snapshotText'].includes(k) ? 1000000 : 8192);
|
|
190
|
+
}
|
|
191
|
+
} else if (value?.type === 'ping' || value?.type === 'pong' || value?.type === 'unpair') object(value, ['type']);
|
|
192
|
+
// The server gave up on a command (its wait ended): the extension stops it, queued or running, and never starts it.
|
|
193
|
+
else if (value?.type === 'cancel') { object(value, ['type', 'id']); handle(value.id); }
|
|
194
|
+
else command(value);
|
|
195
|
+
return value;
|
|
196
|
+
}
|
|
197
|
+
export const ERROR_TEXT = Object.freeze({
|
|
198
|
+
EXTENSION_NOT_CONNECTED: 'The browser extension is not connected. Open its popup and reconnect (after a SynaBun restart it reconnects by itself).',
|
|
199
|
+
NOT_CONNECTED: 'The extension disconnected. Reconnect from its popup.',
|
|
200
|
+
AUTH_FAILED: 'Authentication failed. Revoke pairing and pair again on both sides.',
|
|
201
|
+
PAIRING_EXPIRED: 'Start a new pairing window in SynaBun Browser settings.',
|
|
202
|
+
INVALID_MESSAGE: 'Invalid extension bridge message.', MESSAGE_TOO_LARGE: 'Extension bridge message exceeds its size limit.',
|
|
203
|
+
REPLAY_REJECTED: 'Stale or replayed extension message rejected.',
|
|
204
|
+
SITE_NOT_APPROVED: 'The owner chose "Only sites and tabs I share": this public HTTP(S) site must be shared in the extension popup first.',
|
|
205
|
+
TAB_NOT_APPROVED: 'The tab changed, or an approval was withdrawn, while this command ran. Nothing more was done; observe the tab before retrying.',
|
|
206
|
+
NOT_OWNED: 'This tab belongs to another agent.',
|
|
207
|
+
RESTRICTED_PAGE: 'This is a browser page no extension can read or control (chrome://, edge://, extension pages, local files, the Web Store). Navigate the tab to an http(s) site.',
|
|
208
|
+
SYNABUN_PAGE_BLOCKED: 'This address is SynaBun’s own interface or API. Agents cannot reach it through the owner’s browser unless the owner lets the automation browser act as owner (Settings → Browser).',
|
|
209
|
+
TAB_CLOSED: 'The tab closed, or the owner took it back. Create a new session, or take over another tab (browser_session list).',
|
|
210
|
+
NO_HISTORY_ENTRY: 'There is no page to go back or forward to in this tab. Nothing was done.',
|
|
211
|
+
STALE_REF: 'This element reference is stale. Take a fresh snapshot; no action was performed.',
|
|
212
|
+
UNSUPPORTED_IN_EXTENSION_MODE: 'This operation is unavailable with the extension backend. See docs/browser-extension-bridge.md.',
|
|
213
|
+
ACTIVE_TAB_REQUIRED: 'Screenshots capture the visible part of the active tab only, and the tab was not (or stopped being) the active one while capturing. Retry; in restricted mode, activate the tab first.',
|
|
214
|
+
TAB_LIMIT: 'This bridge already controls 200 tabs. Close an agent tab before opening another.',
|
|
215
|
+
TAB_BUSY: 'Chrome is editing tabs (for example during a drag). Retry navigation after the tab strip settles.',
|
|
216
|
+
NAVIGATION_FAILED: 'Chrome refused tabs.update for this navigation. Check the browser site-access policy and destination, then retry.',
|
|
217
|
+
NAVIGATION_NOT_COMMITTED: 'The navigation did not commit before its deadline: the tab still shows its previous page (the site may still be loading, or the browser dropped the navigation). Nothing was reported as navigated; take a snapshot, then navigate again.',
|
|
218
|
+
SCREENSHOT_PATH_REFUSED: 'The screenshot path is outside the allowed output locations or is protected.',
|
|
219
|
+
NO_MATCH: 'No element matches the target.', AMBIGUOUS_TARGET: 'The selector must match one element or specify nthMatch.',
|
|
220
|
+
UPLOAD_RELOAD_REQUIRED: 'Reload the updated SynaBun Browser Bridge extension to upload files.',
|
|
221
|
+
UPLOAD_FILE_MISSING: 'File not found in the extension upload folder.',
|
|
222
|
+
UPLOAD_TOO_LARGE: 'The selected files exceed the 50 MB total upload limit.',
|
|
223
|
+
UPLOAD_FILE_REFUSED: 'Choose readable regular files inside the extension upload folder shown in Settings → Browser.',
|
|
224
|
+
UPLOAD_MULTIPLE: 'This file input accepts only one file.',
|
|
225
|
+
PERMISSION_REQUIRED: 'Enable this feature in the extension popup first (downloads; in restricted mode also agent-created tabs).', OPERATION_FAILED: 'The browser refused this operation.',
|
|
226
|
+
TIMEOUT: 'The operation timed out. Its outcome may be uncertain; observe before retrying.',
|
|
227
|
+
CANCELLED: 'An approval was revoked or the connection ended while this command was pending. It was stopped before its next browser action; one already under way may have happened, so observe before retrying.',
|
|
228
|
+
});
|
|
229
|
+
export function safeError(error) {
|
|
230
|
+
const code = Object.hasOwn(ERROR_TEXT, error?.code) ? error.code : 'OPERATION_FAILED';
|
|
231
|
+
return { ok: false, code, error: `${code}: ${ERROR_TEXT[code]}` };
|
|
232
|
+
}
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import { channel, command, CONTROL, equalMac, fail, hostPattern, localDeadline, mac, nonce, object, pairingKey, parse, payload, QUEUE_LIMIT, reserve, safeError } from './protocol.js';
|
|
2
|
+
import { createEngine } from './engine.js';
|
|
3
|
+
import { badgeFor } from './popup-view.js';
|
|
4
|
+
import { popupLocale, translator } from './popup-strings.js';
|
|
5
|
+
let socket = null, wire = null, credential = null, port = 3345, paused = false, pairing = false;
|
|
6
|
+
// Handshakes in a row the server refused for the stored credential (it closed the socket after our resume hello):
|
|
7
|
+
// the server no longer takes that pairing (revoked, expired, a server that lost it), so SynaBun's setup page may pair
|
|
8
|
+
// this extension again (setupPair). Reset by every connection that authenticates.
|
|
9
|
+
let refusals = 0;
|
|
10
|
+
// The manifest version, sent in the hello so SynaBun can tell the owner when the browser runs an older copy than its
|
|
11
|
+
// extension folder holds (Reload needed). Absent where the runtime has no manifest (tests).
|
|
12
|
+
const extensionVersion = (() => { try { return String(chrome.runtime.getManifest?.()?.version || '') || null; } catch { return null; } })();
|
|
13
|
+
// `incoming` authenticates messages in order and is never held up by a command; `work` runs ordinary commands one at a time.
|
|
14
|
+
let delay = 1000, reconnectTimer, retryAt = 0, status = 'Disconnected', outbound = Promise.resolve(), incoming = Promise.resolve(), work = Promise.resolve();
|
|
15
|
+
// Bind queued sends to their original channel. A late signature must never go to a replacement socket.
|
|
16
|
+
const send = value => {
|
|
17
|
+
const ws = socket, channelOut = wire;
|
|
18
|
+
outbound = outbound.catch(() => {}).then(async () => {
|
|
19
|
+
if (!channelOut || socket !== ws || wire !== channelOut || ws?.readyState !== WebSocket.OPEN) return;
|
|
20
|
+
payload(value);
|
|
21
|
+
await channelOut.encode(value, raw => {
|
|
22
|
+
if (socket !== ws || wire !== channelOut || ws.readyState !== WebSocket.OPEN) fail('NOT_CONNECTED');
|
|
23
|
+
ws.send(raw);
|
|
24
|
+
});
|
|
25
|
+
}); return outbound;
|
|
26
|
+
};
|
|
27
|
+
const engine = createEngine(chrome, {
|
|
28
|
+
async readUpload(id, index, timeout) {
|
|
29
|
+
const response = await fetch(`http://127.0.0.1:${port}/upload/${index}`, {
|
|
30
|
+
method: 'POST', headers: { Authorization: `Bearer ${id}` }, redirect: 'error',
|
|
31
|
+
credentials: 'omit', cache: 'no-store', signal: AbortSignal.timeout(Math.ceil(timeout)),
|
|
32
|
+
});
|
|
33
|
+
if (!response.ok) fail(response.status === 400 ? await response.text() : 'CANCELLED');
|
|
34
|
+
return response.blob();
|
|
35
|
+
},
|
|
36
|
+
save: async value => {
|
|
37
|
+
const { tabs, ...prefs } = value;
|
|
38
|
+
await chrome.storage.session.set({ bridgeTabs: tabs });
|
|
39
|
+
await chrome.storage.local.set({ bridgePrefs: prefs });
|
|
40
|
+
},
|
|
41
|
+
changed: inventory => { if (wire) void send({ type: 'state', inventory }).catch(() => {}); void badge().catch(() => {}); },
|
|
42
|
+
});
|
|
43
|
+
// The toolbar icon and its tooltip (docs/design/browser-extension → Toolbar badge): no badge text, a status dot in the
|
|
44
|
+
// icon's corner instead: green while connected to SynaBun (agents holding tabs or not), red otherwise (connecting,
|
|
45
|
+
// reconnecting, paused, not paired, refused). The tooltip says the exact state and the number of agent tabs in the
|
|
46
|
+
// browser's language. Only what this worker already knows is read; nothing here changes the connection.
|
|
47
|
+
const badgeText = translator(popupLocale([(() => { try { return chrome.i18n?.getUILanguage?.(); } catch { return ''; } })(), globalThis.navigator?.language].filter(Boolean)));
|
|
48
|
+
async function badge() {
|
|
49
|
+
let controlled = 0;
|
|
50
|
+
try { controlled = engine.current().tabs.filter(tab => tab.owner).length; } catch {}
|
|
51
|
+
const shown = badgeFor({ connected: !!wire, paired: !!credential, paused, connecting: status === 'Connecting', refused: refusals, controlled }, badgeText);
|
|
52
|
+
// Side by side: one call that never settles (a busy toolbar) holds up neither of the others.
|
|
53
|
+
await Promise.all([
|
|
54
|
+
chrome.action.setIcon({ path: { ...shown.icon } }),
|
|
55
|
+
chrome.action.setBadgeText({ text: '' }),
|
|
56
|
+
chrome.action.setTitle({ title: shown.title }),
|
|
57
|
+
]);
|
|
58
|
+
}
|
|
59
|
+
const ready = (async () => {
|
|
60
|
+
await chrome.storage.local.setAccessLevel({ accessLevel: 'TRUSTED_CONTEXTS' });
|
|
61
|
+
const saved = await chrome.storage.local.get(['credential', 'port', 'paused', 'bridgePrefs']);
|
|
62
|
+
const session = await chrome.storage.session.get('bridgeTabs');
|
|
63
|
+
credential = saved.credential || null; port = saved.port || 3345; paused = saved.paused === true;
|
|
64
|
+
await engine.restore({ ...saved.bridgePrefs, tabs: session.bridgeTabs || [] });
|
|
65
|
+
await chrome.alarms.create('synabun-reconnect', { periodInMinutes: 0.5 });
|
|
66
|
+
void badge().catch(() => {});
|
|
67
|
+
})();
|
|
68
|
+
// Ends a connection. The engine's connection generation moves first, synchronously, so nothing that came on it does
|
|
69
|
+
// anything more: a queued command is refused before it starts, a running one before its next browser action.
|
|
70
|
+
function drop(ws) { if (socket === ws) engine.disconnected(); ws.close(); }
|
|
71
|
+
const coded = code => Object.assign(new Error(code), { code });
|
|
72
|
+
// Runs a command and answers on the connection it came on, if that connection is still the current one. A server
|
|
73
|
+
// revoke or disconnect ends that connection only: a pairing, resume or pause made in the popup meanwhile is newer and
|
|
74
|
+
// wins (`connection` is the generation the control message itself set).
|
|
75
|
+
async function answer(ws, message, running, connection) {
|
|
76
|
+
let result;
|
|
77
|
+
try { result = await running; } catch (error) { result = safeError(error); }
|
|
78
|
+
if (socket === ws && wire) {
|
|
79
|
+
try { await send({ type: 'result', id: message.id, result, inventory: engine.current() }); }
|
|
80
|
+
catch (error) { await send({ type: 'result', id: message.id, result: safeError(error), inventory: engine.current() }).catch(() => {}); }
|
|
81
|
+
}
|
|
82
|
+
const current = () => socket === ws && engine.ticket().connection === connection;
|
|
83
|
+
if (message.op === 'revoke' && current()) { credential = null; await chrome.storage.local.remove('credential'); drop(ws); }
|
|
84
|
+
if (message.op === 'disconnect' && current()) { paused = true; await chrome.storage.local.set({ paused }); drop(ws); }
|
|
85
|
+
}
|
|
86
|
+
// Ordinary commands not yet finished, by id, so the server's cancel can stop one ahead of the queue.
|
|
87
|
+
const commands = new Map();
|
|
88
|
+
// Queues an ordinary command under its deadline (`held.expires`, set when the message arrived). One timer, armed at
|
|
89
|
+
// arrival: at the deadline the command's ticket is stopped (so nothing it would still do reaches the browser) and it is
|
|
90
|
+
// answered TIMEOUT on its own channel if that is still current. A command still queued then is dropped and never starts,
|
|
91
|
+
// and so is one whose turn comes later than `held.startBy` (one margin before its deadline). Once it starts, the timer
|
|
92
|
+
// is re-armed for the earlier of the deadline and QUEUE_LIMIT, the watchdog for a browser call that never returns;
|
|
93
|
+
// either way the queue moves on to the next command at once. The server's cancel calls the same `expire`.
|
|
94
|
+
function enqueue(ws, message, held) {
|
|
95
|
+
let timer, started = false, expire;
|
|
96
|
+
const limit = new Promise((_resolve, reject) => { expire = () => { held.stopped = true; reject(coded('TIMEOUT')); }; });
|
|
97
|
+
limit.catch(() => { if (!started) void answer(ws, message, limit).catch(() => {}); });
|
|
98
|
+
// A delay above 2^31-1 ms would fire at once; no real deadline comes near it.
|
|
99
|
+
const arm = ms => { clearTimeout(timer); timer = setTimeout(expire, Math.min(2147483647, Math.max(0, ms))); };
|
|
100
|
+
const done = () => { clearTimeout(timer); if (commands.get(message.id) === expire) commands.delete(message.id); };
|
|
101
|
+
commands.set(message.id, expire);
|
|
102
|
+
arm(held.expires - engine.now());
|
|
103
|
+
work = work.catch(() => {}).then(() => {
|
|
104
|
+
if (!held.stopped && engine.now() >= held.startBy) expire();
|
|
105
|
+
if (held.stopped) { done(); return; }
|
|
106
|
+
started = true; arm(Math.min(QUEUE_LIMIT, held.expires - engine.now()));
|
|
107
|
+
return answer(ws, message, Promise.race([engine.execute(message, held), limit]).finally(done));
|
|
108
|
+
}).catch(() => {}); // A command failure is an answer, never a transport revocation.
|
|
109
|
+
}
|
|
110
|
+
function schedule() {
|
|
111
|
+
clearTimeout(reconnectTimer);
|
|
112
|
+
if (!paused && credential) {
|
|
113
|
+
retryAt = Date.now() + delay;
|
|
114
|
+
// Alarms wake a suspended MV3 worker; the timer gives a live worker the shorter backoff.
|
|
115
|
+
void chrome.alarms.create('synabun-retry', { when: retryAt });
|
|
116
|
+
reconnectTimer = setTimeout(() => { void connect(); }, delay); delay = Math.min(delay * 2, 30000);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
async function connect() {
|
|
120
|
+
await ready;
|
|
121
|
+
if (paused || !credential || socket && [0, 1].includes(socket.readyState)) return;
|
|
122
|
+
let ws;
|
|
123
|
+
try { ws = new WebSocket(`ws://127.0.0.1:${port}/bridge`); } catch { schedule(); return; }
|
|
124
|
+
socket = ws;
|
|
125
|
+
let session, key, client = nonce(), hello = null; wire = null; status = 'Connecting';
|
|
126
|
+
// Register socket callbacks before any Chrome API await: a delayed badge must not lose the challenge.
|
|
127
|
+
void badge().catch(() => {});
|
|
128
|
+
const timer = setTimeout(() => { if (!wire) ws.close(); }, 10000);
|
|
129
|
+
ws.onmessage = event => {
|
|
130
|
+
// A command's deadline counts from here, before it waits to be authenticated.
|
|
131
|
+
const receivedAt = engine.now();
|
|
132
|
+
incoming = incoming.catch(() => {}).then(async () => {
|
|
133
|
+
if (socket !== ws) return;
|
|
134
|
+
if (!wire) {
|
|
135
|
+
const msg = parse(event.data, 2048);
|
|
136
|
+
if (msg.type === 'challenge' && !session) {
|
|
137
|
+
object(msg, ['type', 'session']); if (!/^[a-f0-9]{32}$/.test(msg.session)) fail('INVALID_MESSAGE');
|
|
138
|
+
session = msg.session; key = credential; hello = pairing ? 'pair' : 'resume';
|
|
139
|
+
ws.send(JSON.stringify({ type: 'hello', mode: hello, client, proof: await mac(key, `hello:${session}:${client}`), ...(extensionVersion ? { version: extensionVersion } : {}) }));
|
|
140
|
+
} else {
|
|
141
|
+
object(msg, ['type', 'proof']);
|
|
142
|
+
if (msg.type !== 'welcome' || !session || !await equalMac(key, `welcome:${session}:${client}`, msg.proof)) fail('AUTH_FAILED');
|
|
143
|
+
// A pairing, revoke or pause in the popup during that await replaced or ended this socket's authority.
|
|
144
|
+
if (socket !== ws || credential !== key || paused) fail('AUTH_FAILED');
|
|
145
|
+
wire = channel(key, session, 'extension'); pairing = false; refusals = 0; delay = 1000; retryAt = 0; clearTimeout(timer); clearTimeout(reconnectTimer);
|
|
146
|
+
await chrome.storage.local.set({ credential: key, port, paused: false });
|
|
147
|
+
status = 'Connected'; void badge().catch(() => {}); await send({ type: 'state', inventory: engine.current() });
|
|
148
|
+
}
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
// The socket, its channel and the generations are taken before decoding: a pause, unpairing or new pairing
|
|
152
|
+
// that completes during the await ends this message's authority, and nothing of it reaches the browser.
|
|
153
|
+
const channelIn = wire, arrived = engine.ticket();
|
|
154
|
+
const message = payload(await channelIn.decode(event.data));
|
|
155
|
+
if (socket !== ws || wire !== channelIn || engine.ticket().connection !== arrived.connection) {
|
|
156
|
+
// Refused with no effect, control messages included; an answer goes only to the channel it came on, if open.
|
|
157
|
+
if (message.type === 'command' && socket === ws && wire === channelIn) {
|
|
158
|
+
await send({ type: 'result', id: message.id, result: safeError(coded('NOT_CONNECTED')), inventory: engine.current() });
|
|
159
|
+
}
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
if (message.type === 'ping') { await send({ type: 'pong' }); return; }
|
|
163
|
+
// The server stopped waiting for a command: stop it now, ahead of the queue, as at its deadline.
|
|
164
|
+
if (message.type === 'cancel') { commands.get(message.id)?.(); return; }
|
|
165
|
+
command(message);
|
|
166
|
+
// Owner revocations apply at once, ahead of commands still queued or running; those then find their ticket stale.
|
|
167
|
+
if (CONTROL.includes(message.op)) {
|
|
168
|
+
const running = engine.execute(message);
|
|
169
|
+
await answer(ws, message, running, engine.ticket().connection); return;
|
|
170
|
+
}
|
|
171
|
+
// An ordinary command keeps the approval and connection generations of the moment it arrived (before its
|
|
172
|
+
// decoding) and its deadline from that same moment, then waits its turn (enqueue).
|
|
173
|
+
const expires = localDeadline(receivedAt, message.deadline);
|
|
174
|
+
enqueue(ws, message, { ...arrived, stopped: false, expires, startBy: expires - reserve(message.deadline) });
|
|
175
|
+
}).catch(() => { status = 'Connection refused — pair again'; drop(ws); });
|
|
176
|
+
};
|
|
177
|
+
ws.onerror = () => { status = 'Not connected — check SynaBun and the port'; };
|
|
178
|
+
ws.onclose = () => {
|
|
179
|
+
clearTimeout(timer); if (socket !== ws) return;
|
|
180
|
+
// Closed after our resume hello and before a welcome: the server refused the stored credential.
|
|
181
|
+
if (!wire && hello === 'resume') refusals++;
|
|
182
|
+
engine.disconnected(); socket = wire = null; status = paused ? 'Paused' : 'Disconnected — reconnecting'; void badge().catch(() => {}); schedule();
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
chrome.alarms.onAlarm.addListener(alarm => {
|
|
186
|
+
if (['synabun-reconnect', 'synabun-retry'].includes(alarm.name)) {
|
|
187
|
+
if (Date.now() >= retryAt) void connect();
|
|
188
|
+
void ready.then(() => engine.opened()).catch(() => {});
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
chrome.tabs.onActivated.addListener(() => engine.activated());
|
|
192
|
+
chrome.tabs.onRemoved.addListener(id => { void ready.then(() => engine.closed(id)); });
|
|
193
|
+
chrome.tabs.onUpdated.addListener((id, change) => {
|
|
194
|
+
if (change.url) void ready.then(() => engine.updated(id));
|
|
195
|
+
else if (change.title !== undefined) void ready.then(() => engine.retitled(id));
|
|
196
|
+
});
|
|
197
|
+
// Full control lists every tab of the browser: a new one is listed as soon as it opens.
|
|
198
|
+
chrome.tabs.onCreated.addListener(() => { void ready.then(() => engine.opened()); });
|
|
199
|
+
chrome.permissions.onRemoved.addListener(() => { engine.withdrawn(); void ready.then(async () => {
|
|
200
|
+
for (const site of engine.current().sites) if (!await chrome.permissions.contains({ origins: [hostPattern(site)] })) await engine.revokeSite(site);
|
|
201
|
+
}); });
|
|
202
|
+
// ── One-button setup: SynaBun's "Connect your browser" page hands over a one-time token (setup-content.js) ──
|
|
203
|
+
// Accepted only from this extension's own content script, in the top frame of a tab, on exactly the setup page's origin
|
|
204
|
+
// and path as this manifest names them (SynaBun's app port on 127.0.0.1 and localhost), from a tab no agent holds, and
|
|
205
|
+
// only while this extension needs pairing: never paired, or the server refused its stored credential twice in a row.
|
|
206
|
+
// A paired, working or paused extension is never re-paired by a page (the popup and SynaBun's typed code still can).
|
|
207
|
+
// The token is used exactly like a typed code (pairingKey, the same HMAC handshake): it never crosses the socket, and
|
|
208
|
+
// the server accepts it once. Nothing of it is stored but the credential the handshake derives, as with a typed code.
|
|
209
|
+
const SETUP_KIND = 'synabun-setup-pair';
|
|
210
|
+
function setupPages() {
|
|
211
|
+
try {
|
|
212
|
+
return (chrome.runtime.getManifest?.()?.content_scripts || []).flatMap(entry => entry.js?.includes('setup-content.js') ? entry.matches || [] : [])
|
|
213
|
+
.map(pattern => { const u = new URL(pattern.replace(/\*$/, '')); return `${u.origin}${u.pathname}`; });
|
|
214
|
+
} catch { return []; }
|
|
215
|
+
}
|
|
216
|
+
function setupSender(sender) {
|
|
217
|
+
if (sender?.id !== chrome.runtime.id || !sender.tab || !Number.isSafeInteger(sender.tab.id) || sender.frameId !== 0) return false;
|
|
218
|
+
let u; try { u = new URL(sender.url); } catch { return false; }
|
|
219
|
+
if (u.protocol !== 'http:' || u.username || u.password) return false;
|
|
220
|
+
if (sender.origin !== undefined && sender.origin !== u.origin) return false;
|
|
221
|
+
return setupPages().includes(`${u.origin}${u.pathname}`);
|
|
222
|
+
}
|
|
223
|
+
let setupAt = 0;
|
|
224
|
+
async function setupPair(msg, sender) {
|
|
225
|
+
await ready;
|
|
226
|
+
const refuse = code => ({ ok: false, code });
|
|
227
|
+
try { object(msg, ['kind', 'token', 'bridgePort']); } catch { return refuse('INVALID_MESSAGE'); }
|
|
228
|
+
if (msg.kind !== SETUP_KIND || typeof msg.token !== 'string' || !/^[a-f0-9]{64}$/.test(msg.token)
|
|
229
|
+
|| !Number.isInteger(msg.bridgePort) || msg.bridgePort < 1024 || msg.bridgePort > 65535) return refuse('INVALID_MESSAGE');
|
|
230
|
+
// A tab an agent holds is never where pairing comes from (agents never reach SynaBun's pages anyway).
|
|
231
|
+
if (engine.heldByAgent(sender.tab.id)) return refuse('NOT_OWNED');
|
|
232
|
+
if (wire) return refuse('ALREADY_CONNECTED');
|
|
233
|
+
if (credential && paused) return refuse('PAUSED');
|
|
234
|
+
if (credential && !pairing && refusals < 2) return refuse('ALREADY_PAIRED');
|
|
235
|
+
if (Date.now() - setupAt < 2000) return refuse('BUSY');
|
|
236
|
+
setupAt = Date.now();
|
|
237
|
+
// A new pairing ends what the old one allowed, before anything is awaited (as the popup's pair does).
|
|
238
|
+
engine.disconnected(); socket?.close(); socket = wire = null; await engine.clear();
|
|
239
|
+
credential = await pairingKey(msg.token); port = msg.bridgePort; pairing = true; paused = false; refusals = 0; void connect();
|
|
240
|
+
return { ok: true };
|
|
241
|
+
}
|
|
242
|
+
chrome.runtime.onMessage.addListener((msg, sender, respond) => {
|
|
243
|
+
if (sender.tab) {
|
|
244
|
+
if (msg?.kind !== SETUP_KIND || !setupSender(sender)) return;
|
|
245
|
+
setupPair(msg, sender).then(respond, () => respond({ ok: false, code: 'REFUSED' }));
|
|
246
|
+
return true;
|
|
247
|
+
}
|
|
248
|
+
if (sender.id !== chrome.runtime.id || sender.url !== chrome.runtime.getURL('popup.html') || sender.tab) return;
|
|
249
|
+
(async () => {
|
|
250
|
+
await ready; object(msg, ['action', 'code', 'port', 'tab', 'site', 'options', 'siteOnly', 'fullControl']);
|
|
251
|
+
if (msg.action === 'pair') {
|
|
252
|
+
if (!/^[a-fA-F0-9-]{20,24}$/.test(msg.code) || !Number.isInteger(msg.port) || msg.port < 1024 || msg.port > 65535) fail('INVALID_MESSAGE');
|
|
253
|
+
// A new pairing ends what the old one allowed, before anything is awaited.
|
|
254
|
+
engine.disconnected(); socket?.close(); socket = wire = null; await engine.clear();
|
|
255
|
+
credential = await pairingKey(msg.code); port = msg.port; pairing = true; paused = false; void connect();
|
|
256
|
+
} else if (msg.action === 'share') await engine.share(msg.tab, msg.siteOnly === true);
|
|
257
|
+
else if (msg.action === 'revokeTab') await engine.revokeTab(msg.tab);
|
|
258
|
+
else if (msg.action === 'revokeSite') await engine.revokeSite(msg.site);
|
|
259
|
+
else if (msg.action === 'options') await engine.options(msg.options);
|
|
260
|
+
// The owner's mode switch. Restricted takes effect here at once (a revocation); the server hears it with the
|
|
261
|
+
// next inventory, which carries the newer mode version.
|
|
262
|
+
else if (msg.action === 'mode') { if (typeof msg.fullControl !== 'boolean') fail('INVALID_MESSAGE'); await engine.setMode(msg.fullControl); }
|
|
263
|
+
else if (msg.action === 'disconnect') { engine.disconnected(); paused = true; await chrome.storage.local.set({ paused }); socket?.close(); }
|
|
264
|
+
else if (msg.action === 'resume') { paused = false; await chrome.storage.local.set({ paused }); void connect(); }
|
|
265
|
+
else if (msg.action === 'revoke') {
|
|
266
|
+
engine.disconnected(); const cleared = engine.clear();
|
|
267
|
+
await send({ type: 'unpair' }); credential = null; paused = true; socket?.close(); await cleared;
|
|
268
|
+
await chrome.storage.local.remove('credential'); await chrome.storage.local.set({ paused });
|
|
269
|
+
} else if (msg.action !== 'status') fail('INVALID_MESSAGE');
|
|
270
|
+
if (msg.action !== 'status') void badge().catch(() => {});
|
|
271
|
+
return { ok: true, status, connected: !!wire, port, ...engine.current() };
|
|
272
|
+
})().then(respond, error => respond(safeError(error)));
|
|
273
|
+
return true;
|
|
274
|
+
});
|
|
275
|
+
void connect();
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// SynaBun's "Connect your browser" page (/extension-setup on SynaBun's own app port; the manifest's content_scripts
|
|
2
|
+
// names exactly that origin and path, and the copy SynaBun prepares names the port it runs on). This script tells the
|
|
3
|
+
// page the extension is installed, and hands the service worker the page's one-time pairing token. Nothing else.
|
|
4
|
+
//
|
|
5
|
+
// It runs in the isolated world, top frame only, and acts only on that exact origin and path (checked again here and
|
|
6
|
+
// by the service worker against sender.url). It never reads anything but the one ticket element the page fills in,
|
|
7
|
+
// sends nothing anywhere but to this extension's service worker, and keeps no token: the service worker decides
|
|
8
|
+
// whether to pair (only an extension that needs pairing does) and the server accepts a token once.
|
|
9
|
+
(() => {
|
|
10
|
+
const allowed = (() => {
|
|
11
|
+
try {
|
|
12
|
+
const own = chrome.runtime.getManifest().content_scripts || [];
|
|
13
|
+
return own.flatMap(entry => entry.js?.includes('setup-content.js') ? entry.matches || [] : [])
|
|
14
|
+
.map(pattern => { const u = new URL(pattern.replace(/\*$/, '')); return `${u.origin}${u.pathname}`; });
|
|
15
|
+
} catch { return []; }
|
|
16
|
+
})();
|
|
17
|
+
if (window.top !== window || location.protocol !== 'http:' || !allowed.includes(`${location.origin}${location.pathname}`)) return;
|
|
18
|
+
const root = document.documentElement;
|
|
19
|
+
// The page shows "Extension found" from this; it holds the version only.
|
|
20
|
+
root.dataset.synabunExtension = String(chrome.runtime.getManifest().version || '');
|
|
21
|
+
let sent = '';
|
|
22
|
+
async function offer() {
|
|
23
|
+
const ticket = document.getElementById('synabun-setup-ticket');
|
|
24
|
+
const token = ticket?.dataset.token || '', bridgePort = Number(ticket?.dataset.bridgePort);
|
|
25
|
+
if (!/^[a-f0-9]{64}$/.test(token) || token === sent) return;
|
|
26
|
+
sent = token;
|
|
27
|
+
root.dataset.synabunPair = 'sent';
|
|
28
|
+
let answer;
|
|
29
|
+
try { answer = await chrome.runtime.sendMessage({ kind: 'synabun-setup-pair', token, bridgePort }); }
|
|
30
|
+
catch { answer = { ok: false, code: 'EXTENSION_UNAVAILABLE' }; }
|
|
31
|
+
// The page reads the outcome's code only (pairing itself is reported by the server's status).
|
|
32
|
+
root.dataset.synabunPair = answer?.ok ? 'started' : String(answer?.code || 'REFUSED').replace(/[^A-Z_]/g, '').slice(0, 40);
|
|
33
|
+
}
|
|
34
|
+
new MutationObserver(() => { void offer(); }).observe(root, { subtree: true, childList: true, attributes: true, attributeFilter: ['data-token'] });
|
|
35
|
+
void offer();
|
|
36
|
+
})();
|