synabun 2.4.1 → 2.4.3
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 +50 -0
- package/README.md +1 -1
- package/docs/browser-extension-bridge.md +46 -6
- package/lib/data-home-files.js +4 -2
- package/lib/first-launch-protection.js +8 -2
- package/lib/release-npm-ci.mjs +23 -1
- package/lib/update-snapshot.js +11 -4
- package/mcp-server/dist/http.d.ts.map +1 -1
- package/mcp-server/dist/http.js +25 -2
- 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 +62 -17
- package/mcp-server/dist/index.js.map +1 -1
- package/mcp-server/dist/services/browser-bench.d.ts +22 -22
- package/mcp-server/dist/services/memory-maintenance.d.ts +1 -0
- package/mcp-server/dist/services/memory-maintenance.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-maintenance.js +34 -45
- package/mcp-server/dist/services/memory-maintenance.js.map +1 -1
- package/mcp-server/dist/services/memory-migration-copy.d.ts +144 -0
- package/mcp-server/dist/services/memory-migration-copy.d.ts.map +1 -0
- package/mcp-server/dist/services/memory-migration-copy.js +467 -0
- package/mcp-server/dist/services/memory-migration-copy.js.map +1 -0
- package/mcp-server/dist/services/memory-migration-worker.d.ts +2 -0
- package/mcp-server/dist/services/memory-migration-worker.d.ts.map +1 -0
- package/mcp-server/dist/services/memory-migration-worker.js +60 -0
- package/mcp-server/dist/services/memory-migration-worker.js.map +1 -0
- package/mcp-server/dist/services/memory-retrieval.d.ts +4 -0
- package/mcp-server/dist/services/memory-retrieval.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-retrieval.js +188 -40
- package/mcp-server/dist/services/memory-retrieval.js.map +1 -1
- package/mcp-server/dist/services/memory-schema.d.ts +58 -2
- package/mcp-server/dist/services/memory-schema.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-schema.js +190 -13
- package/mcp-server/dist/services/memory-schema.js.map +1 -1
- package/mcp-server/dist/services/memory-sessions.d.ts +19 -1
- package/mcp-server/dist/services/memory-sessions.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-sessions.js +56 -20
- package/mcp-server/dist/services/memory-sessions.js.map +1 -1
- package/mcp-server/dist/services/memory-verification.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-verification.js +8 -5
- package/mcp-server/dist/services/memory-verification.js.map +1 -1
- package/mcp-server/dist/services/neural-interface.d.ts +5 -0
- package/mcp-server/dist/services/neural-interface.d.ts.map +1 -1
- package/mcp-server/dist/services/neural-interface.js +19 -2
- package/mcp-server/dist/services/neural-interface.js.map +1 -1
- package/mcp-server/dist/services/retrieval-reader-worker.d.ts +2 -0
- package/mcp-server/dist/services/retrieval-reader-worker.d.ts.map +1 -0
- package/mcp-server/dist/services/retrieval-reader-worker.js +76 -0
- package/mcp-server/dist/services/retrieval-reader-worker.js.map +1 -0
- package/mcp-server/dist/services/retrieval-reader.d.ts +38 -0
- package/mcp-server/dist/services/retrieval-reader.d.ts.map +1 -0
- package/mcp-server/dist/services/retrieval-reader.js +145 -0
- package/mcp-server/dist/services/retrieval-reader.js.map +1 -0
- package/mcp-server/dist/services/sqlite-write.d.ts +14 -0
- package/mcp-server/dist/services/sqlite-write.d.ts.map +1 -0
- package/mcp-server/dist/services/sqlite-write.js +94 -0
- package/mcp-server/dist/services/sqlite-write.js.map +1 -0
- package/mcp-server/dist/services/sqlite.d.ts +39 -0
- package/mcp-server/dist/services/sqlite.d.ts.map +1 -1
- package/mcp-server/dist/services/sqlite.js +249 -8
- package/mcp-server/dist/services/sqlite.js.map +1 -1
- package/mcp-server/dist/services/tool-catalog.d.ts +1 -1
- package/mcp-server/dist/services/typesafe-config.d.ts +7 -1
- package/mcp-server/dist/services/typesafe-config.d.ts.map +1 -1
- package/mcp-server/dist/services/typesafe-config.js +32 -10
- package/mcp-server/dist/services/typesafe-config.js.map +1 -1
- package/mcp-server/dist/services/typesafe.d.ts.map +1 -1
- package/mcp-server/dist/services/typesafe.js +9 -7
- package/mcp-server/dist/services/typesafe.js.map +1 -1
- package/mcp-server/dist/services/vector-cache.d.ts +32 -0
- package/mcp-server/dist/services/vector-cache.d.ts.map +1 -1
- package/mcp-server/dist/services/vector-cache.js +161 -8
- package/mcp-server/dist/services/vector-cache.js.map +1 -1
- package/mcp-server/dist/tools/agent-definition.d.ts +2 -2
- package/mcp-server/dist/tools/agents.d.ts +11 -7
- package/mcp-server/dist/tools/agents.d.ts.map +1 -1
- package/mcp-server/dist/tools/agents.js +27 -9
- package/mcp-server/dist/tools/agents.js.map +1 -1
- package/mcp-server/dist/tools/browser-advanced.d.ts +1 -1
- package/mcp-server/dist/tools/browser-advanced.d.ts.map +1 -1
- package/mcp-server/dist/tools/browser-advanced.js +10 -3
- package/mcp-server/dist/tools/browser-advanced.js.map +1 -1
- package/mcp-server/dist/tools/browser-extension-setup.d.ts +5 -0
- package/mcp-server/dist/tools/browser-extension-setup.d.ts.map +1 -0
- package/mcp-server/dist/tools/browser-extension-setup.js +29 -0
- package/mcp-server/dist/tools/browser-extension-setup.js.map +1 -0
- package/mcp-server/dist/tools/browser-interact.d.ts.map +1 -1
- package/mcp-server/dist/tools/browser-interact.js +6 -1
- package/mcp-server/dist/tools/browser-interact.js.map +1 -1
- package/mcp-server/dist/tools/fb-groups.d.ts +2 -2
- package/mcp-server/dist/tools/skill-tools.d.ts +4 -4
- package/mcp-server/dist/tools/tool-groups.d.ts +1 -1
- package/mcp-server/package-lock.json +5 -5
- package/mcp-server/package.json +1 -1
- package/mcp-server/src/http.ts +20 -2
- package/mcp-server/src/index.ts +59 -17
- package/mcp-server/src/services/memory-maintenance.ts +31 -28
- package/mcp-server/src/services/memory-migration-copy.ts +419 -0
- package/mcp-server/src/services/memory-migration-worker.ts +55 -0
- package/mcp-server/src/services/memory-retrieval.ts +173 -32
- package/mcp-server/src/services/memory-schema.ts +194 -12
- package/mcp-server/src/services/memory-sessions.ts +54 -21
- package/mcp-server/src/services/memory-verification.ts +7 -4
- package/mcp-server/src/services/neural-interface.ts +22 -2
- package/mcp-server/src/services/retrieval-reader-worker.ts +67 -0
- package/mcp-server/src/services/retrieval-reader.ts +131 -0
- package/mcp-server/src/services/sqlite-write.ts +60 -0
- package/mcp-server/src/services/sqlite.ts +246 -8
- package/mcp-server/src/services/typesafe-config.ts +25 -6
- package/mcp-server/src/services/typesafe.ts +9 -7
- package/mcp-server/src/services/vector-cache.ts +154 -9
- package/mcp-server/src/tools/agents.ts +26 -9
- package/mcp-server/src/tools/browser-advanced.ts +10 -3
- package/mcp-server/src/tools/browser-extension-setup.ts +36 -0
- package/mcp-server/src/tools/browser-interact.ts +5 -1
- package/neural-interface/i18n/en.json +313 -2
- package/neural-interface/i18n/pt-BR.json +321 -10
- package/neural-interface/lib/agents/split.js +32 -4
- package/neural-interface/lib/assistant-api.js +52 -8
- package/neural-interface/lib/assistant-brains/claude.js +2 -0
- package/neural-interface/lib/assistant-brains/opencode.js +121 -7
- package/neural-interface/lib/assistant-catalog.js +2 -2
- package/neural-interface/lib/assistant-config.js +0 -7
- package/neural-interface/lib/assistant-dispatch.js +281 -95
- package/neural-interface/lib/assistant-envelope.js +40 -0
- package/neural-interface/lib/assistant-persona.js +16 -4
- package/neural-interface/lib/assistant-pricing.js +65 -14
- package/neural-interface/lib/assistant-router.js +131 -47
- package/neural-interface/lib/assistant-run-wait.js +45 -28
- package/neural-interface/lib/assistant-runtime.js +133 -42
- package/neural-interface/lib/backup-contents.js +158 -0
- package/neural-interface/lib/backup-crypto-io.js +330 -0
- package/neural-interface/lib/backup-crypto-worker.js +130 -0
- package/neural-interface/lib/backup-crypto.js +525 -0
- package/neural-interface/lib/backup-download.js +268 -0
- package/neural-interface/lib/backup-encryption.js +318 -0
- package/neural-interface/lib/backup-groups.js +287 -0
- package/neural-interface/lib/backup-restore-session.js +176 -0
- package/neural-interface/lib/backup-restore-stage.js +60 -0
- package/neural-interface/lib/backup-service.js +788 -233
- package/neural-interface/lib/backup-zip-reader.js +30 -18
- package/neural-interface/lib/backup-zip-writer.js +34 -10
- package/neural-interface/lib/browser-extension-adapter.js +89 -15
- package/neural-interface/lib/browser-extension-archive.js +149 -0
- package/neural-interface/lib/browser-extension-bridge.js +24 -10
- package/neural-interface/lib/browser-extension-folder.js +596 -76
- package/neural-interface/lib/browser-extension-package.js +200 -0
- package/neural-interface/lib/browser-extension-pin.js +84 -0
- package/neural-interface/lib/browser-extension-pin.json +33 -0
- package/{browser-extension/protocol.js → neural-interface/lib/browser-extension-protocol.js} +91 -6
- package/neural-interface/lib/browser-extension-setup.js +105 -18
- package/neural-interface/lib/claude-agent-bridge.js +1 -0
- package/neural-interface/lib/claude-session-cleanup.js +5 -1
- package/neural-interface/lib/cli-install.js +23 -3
- package/neural-interface/lib/cli-update-planner.js +171 -9
- package/neural-interface/lib/client-diagnostics.js +42 -0
- package/neural-interface/lib/confined-fs.js +7 -2
- package/neural-interface/lib/coordination/README.md +8 -2
- package/neural-interface/lib/coordination/contract.js +161 -0
- package/neural-interface/lib/coordination/database.js +999 -0
- package/neural-interface/lib/coordination/operations.js +436 -0
- package/neural-interface/lib/coordination/service.js +68 -537
- package/neural-interface/lib/coordination/storage-worker.js +101 -0
- package/neural-interface/lib/coordination/store.js +219 -1111
- package/neural-interface/lib/db.js +70 -32
- package/neural-interface/lib/health-count.js +37 -0
- package/neural-interface/lib/loop-stall.js +139 -0
- package/neural-interface/lib/maritaca/client.js +2 -2
- package/neural-interface/lib/maritaca/models.js +12 -17
- package/neural-interface/lib/maritaca/opencode.js +4 -2
- package/neural-interface/lib/memory-api.js +9 -1
- package/neural-interface/lib/memory-session-capture.js +42 -10
- package/neural-interface/lib/memory-store-gate.js +313 -0
- package/neural-interface/lib/memory-store-migrate.js +65 -0
- package/neural-interface/lib/memory-timers.js +7 -7
- package/neural-interface/lib/native-loop-providers.js +23 -17
- package/neural-interface/lib/native-loop-runtime.js +48 -9
- package/neural-interface/lib/opencode-build-preflight.js +18 -1
- package/neural-interface/lib/opencode-native-boundary.js +69 -8
- package/neural-interface/lib/opencode-provider-view.js +14 -3
- package/neural-interface/lib/opencode-shell-read.js +107 -0
- package/neural-interface/lib/opencode-stop-failures.js +40 -0
- package/neural-interface/lib/opencode-turn-release.js +173 -0
- package/neural-interface/lib/opencode-v2-client.js +4 -1
- package/neural-interface/lib/opencode-v2-ws-requests.js +65 -1
- package/neural-interface/lib/opencode2-client.js +343 -7
- package/neural-interface/lib/opencode2-translate.js +161 -4
- package/neural-interface/lib/recall-impact.js +122 -0
- package/neural-interface/lib/scratch-evidence.js +420 -0
- package/neural-interface/lib/scratch-process-guard.js +139 -0
- package/neural-interface/lib/scratch-references.js +279 -0
- package/neural-interface/lib/scratch-retention-core.js +385 -0
- package/neural-interface/lib/scratch-retention-worker.js +37 -0
- package/neural-interface/lib/scratch-retention.js +151 -0
- package/neural-interface/lib/session-cache-builder.js +31 -43
- package/neural-interface/lib/session-cache-worker.js +157 -0
- package/neural-interface/lib/session-indexer.js +28 -21
- package/neural-interface/lib/session-search-index.js +85 -0
- package/neural-interface/lib/skills/creation.js +1 -1
- package/neural-interface/lib/sqlite-integrity-worker.js +3 -1
- package/neural-interface/lib/style-guide/store.js +43 -3
- package/neural-interface/lib/system-restore.js +50 -0
- package/neural-interface/lib/teams/api.js +15 -6
- package/neural-interface/lib/teams/claims.js +67 -31
- package/neural-interface/lib/teams/index.js +7 -7
- package/neural-interface/lib/teams/integration.js +40 -40
- package/neural-interface/lib/teams/landing.js +6 -6
- package/neural-interface/lib/teams/recovery.js +24 -23
- package/neural-interface/lib/teams/scheduler.js +194 -95
- package/neural-interface/lib/teams/state.js +14 -14
- package/neural-interface/lib/teams/worktrees.js +27 -27
- package/neural-interface/lib/terminal-token-redaction.js +83 -0
- package/neural-interface/lib/whatsapp/bridge.js +54 -7
- package/neural-interface/lib/worker-confinement.js +47 -2
- package/neural-interface/lib/worker-mcp-channel.js +2 -0
- package/neural-interface/lib/worker-resume.js +5 -0
- package/neural-interface/lib/worker-stop.js +86 -0
- package/neural-interface/package-lock.json +5 -5
- package/neural-interface/package.json +1 -1
- package/neural-interface/public/extension-setup.html +5 -2
- package/neural-interface/public/index.html +233 -24
- package/neural-interface/public/onboarding.html +259 -34
- package/neural-interface/public/shared/agents/studio/ax-library.js +0 -6
- package/neural-interface/public/shared/agents/studio/ax-main.js +14 -7
- package/neural-interface/public/shared/agy/agy-options.js +11 -0
- package/neural-interface/public/shared/agy/agy-panel.js +67 -20
- package/neural-interface/public/shared/agy/agy-styles.js +14 -12
- package/neural-interface/public/shared/agy/agy-tabs-logic.js +4 -1
- package/neural-interface/public/shared/api.js +1 -1
- package/neural-interface/public/shared/assistant/asst-api.js +28 -3
- package/neural-interface/public/shared/assistant/asst-brain-picker.js +13 -6
- package/neural-interface/public/shared/assistant/asst-control.js +2 -0
- package/neural-interface/public/shared/assistant/asst-motion-gate.js +78 -4
- package/neural-interface/public/shared/assistant/asst-panel.js +87 -3
- package/neural-interface/public/shared/assistant/asst-rack-styles.js +27 -0
- package/neural-interface/public/shared/assistant/asst-render.js +243 -44
- package/neural-interface/public/shared/assistant/asst-route.js +100 -21
- package/neural-interface/public/shared/assistant/asst-routes-editor.js +1 -1
- package/neural-interface/public/shared/assistant/asst-shell-logic.js +200 -0
- package/neural-interface/public/shared/assistant/asst-shell.js +111 -0
- package/neural-interface/public/shared/assistant/asst-sidepanel.js +4 -2
- package/neural-interface/public/shared/assistant/asst-state.js +11 -0
- package/neural-interface/public/shared/assistant/asst-styles.js +11 -23
- package/neural-interface/public/shared/assistant/route-identity.js +2 -1
- package/neural-interface/public/shared/cdx/cdx-render.js +9 -0
- package/neural-interface/public/shared/cdx/cdx-settings.js +3 -1
- package/neural-interface/public/shared/cdx/cdx-styles.js +6 -0
- package/neural-interface/public/shared/cdx/cdx-tabs.js +54 -9
- package/neural-interface/public/shared/client-diagnostics.js +94 -0
- package/neural-interface/public/shared/cp/cp-markdown.js +7 -2
- package/neural-interface/public/shared/cp/cp-styles.js +1 -1
- package/neural-interface/public/shared/effort-i18n.js +118 -0
- package/neural-interface/public/shared/extension-setup/es-page.js +10 -4
- package/neural-interface/public/shared/extension-setup/es-view.js +25 -10
- package/neural-interface/public/shared/html-shell.js +4 -52
- package/neural-interface/public/shared/loading-diagnostic-entry.js +64 -0
- package/neural-interface/public/shared/memory-store-wait.js +52 -0
- package/neural-interface/public/shared/morelogin-profile-field.js +1 -1
- package/neural-interface/public/shared/mtc/mtc-logic.js +2 -1
- package/neural-interface/public/shared/mtc/mtc-panel.js +25 -3
- package/neural-interface/public/shared/mtc/mtc-styles.js +13 -12
- package/neural-interface/public/shared/ocp-v2/ocp-v2-childpanel.js +7 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-events.js +5 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-location-logic.js +109 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-manager.js +1 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-modelpicker.js +8 -1
- package/neural-interface/public/shared/ocp-v2/ocp-v2-panel.js +152 -8
- package/neural-interface/public/shared/ocp-v2/ocp-v2-rehydrate.js +7 -1
- package/neural-interface/public/shared/ocp-v2/ocp-v2-render.js +53 -4
- package/neural-interface/public/shared/ocp-v2/ocp-v2-send.js +52 -6
- package/neural-interface/public/shared/ocp-v2/ocp-v2-session-actions.js +22 -2
- package/neural-interface/public/shared/ocp-v2/ocp-v2-shell-block.js +165 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-shell-logic.js +346 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-shell.js +108 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-state.js +49 -3
- package/neural-interface/public/shared/ocp-v2/ocp-v2-styles.js +67 -93
- package/neural-interface/public/shared/ocp-v2/ocp-v2-tools-logic.js +20 -5
- package/neural-interface/public/shared/ocp-v2/ocp-v2-tools.js +7 -1
- package/neural-interface/public/shared/ocp-v2/ocp-v2-variantpicker.js +17 -6
- package/neural-interface/public/shared/ocp-v2/ocp-v2-ws.js +7 -2
- package/neural-interface/public/shared/output-format.js +294 -0
- package/neural-interface/public/shared/provider-icons.js +6 -0
- package/neural-interface/public/shared/schedules-view.js +2 -1
- package/neural-interface/public/shared/server-presence.js +77 -0
- package/neural-interface/public/shared/settings/settings-backup-contents.js +241 -0
- package/neural-interface/public/shared/settings/settings-backup-download.js +298 -0
- package/neural-interface/public/shared/settings/settings-backup-encryption-pane.js +335 -0
- package/neural-interface/public/shared/settings/settings-backup-encryption.js +545 -0
- package/neural-interface/public/shared/settings/settings-browser-extension.js +54 -12
- package/neural-interface/public/shared/settings/settings-ia.js +1 -1
- package/neural-interface/public/shared/shell-stop-view.js +83 -0
- package/neural-interface/public/shared/skills/studio/sx-geometry.js +12 -3
- package/neural-interface/public/shared/skills/studio/sx-main.js +14 -7
- package/neural-interface/public/shared/studio-attention.js +6 -0
- package/neural-interface/public/shared/styles.css +341 -437
- package/neural-interface/public/shared/tour/tour-actor.js +14 -3
- package/neural-interface/public/shared/transcript-rows.js +28 -3
- package/neural-interface/public/shared/tray-auto-close.js +49 -6
- package/neural-interface/public/shared/ui-agents.js +1 -2
- package/neural-interface/public/shared/ui-automation-studio.js +168 -108
- package/neural-interface/public/shared/ui-claude-panel.js +62 -65
- package/neural-interface/public/shared/ui-loading.js +124 -17
- package/neural-interface/public/shared/ui-native-loop-router.js +52 -0
- package/neural-interface/public/shared/ui-navbar.js +2 -1
- package/neural-interface/public/shared/ui-output.js +533 -0
- package/neural-interface/public/shared/ui-schedules-studio.js +165 -128
- package/neural-interface/public/shared/ui-scroll-follow.js +101 -6
- package/neural-interface/public/shared/ui-sessions.js +2 -2
- package/neural-interface/public/shared/ui-settings-entry.js +18 -0
- package/neural-interface/public/shared/ui-settings.js +224 -65
- package/neural-interface/public/shared/ui-sidepanel-tray.js +3 -2
- package/neural-interface/public/shared/ui-tooltip.js +16 -0
- package/neural-interface/public/shared/ui-tutorial.js +5 -6
- package/neural-interface/public/shared/ui-worker-end.js +27 -8
- package/neural-interface/public/shared/worker-end.js +9 -4
- package/neural-interface/public/variant/2d/main.js +5 -0
- package/neural-interface/public/variant/3d/app.js +10 -0
- package/neural-interface/public/variant/3d/main.js +5 -1
- package/neural-interface/scripts/scratch-retention.mjs +20 -0
- package/neural-interface/server.js +725 -173
- package/npm-shrinkwrap.json +5 -5
- package/package.json +1 -2
- package/scripts/restore-data-home-from-backup.mjs +175 -8
- package/setup.js +18 -4
- package/browser-extension/content.js +0 -189
- package/browser-extension/engine.js +0 -508
- 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 +0 -56
- package/browser-extension/popup-strings.js +0 -250
- package/browser-extension/popup-view.js +0 -151
- package/browser-extension/popup.css +0 -166
- package/browser-extension/popup.html +0 -108
- package/browser-extension/popup.js +0 -359
- package/browser-extension/service-worker.js +0 -275
- package/browser-extension/setup-content.js +0 -36
- package/browser-extension/tokens.css +0 -326
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
// Where the extension's files come from: the one package this app release pins (lib/browser-extension-pin.js),
|
|
2
|
+
// downloaded from synabun.ai (docs/browser-extension-bridge.md → Where the extension comes from). The extension has
|
|
3
|
+
// broad permissions in the owner's browser, so a download is hostile until it is proven to be that exact file:
|
|
4
|
+
//
|
|
5
|
+
// transfer HTTPS only, the one host only (a redirect anywhere else, or to plain http, is not followed), the body
|
|
6
|
+
// as sent (no Content-Encoding: the pinned size bounds the bytes on the wire), nothing larger than the
|
|
7
|
+
// pinned size, a wait for the first byte and between bytes (stallMs) and for the whole transfer
|
|
8
|
+
// (totalMs). It is the hardened transfer of lib/cli-install.js (downloadFile), which aborts the request
|
|
9
|
+
// of every answer it refuses.
|
|
10
|
+
// verify the size and the SHA-256 must be the pin's, checked over the bytes that are then read, before anything
|
|
11
|
+
// looks inside the file; then SynaBun's one zip form, the pinned version and key, and exactly the files
|
|
12
|
+
// the pin lists (lib/browser-extension-folder.js verifiedPackageFiles).
|
|
13
|
+
// place lib/browser-extension-folder.js prepareExtensionFolder: under the data home's lock, a staged folder,
|
|
14
|
+
// then two renames (the live folder aside, the new one into its place), recorded so that a stopped
|
|
15
|
+
// process is finished or taken back at the next start.
|
|
16
|
+
//
|
|
17
|
+
// The folder is held to the pin, never to its marker (inspectExtensionFolder): a folder that is not exactly the
|
|
18
|
+
// pinned extension for this port is repaired, from the verified package this data home keeps when it has one (no
|
|
19
|
+
// network), else by downloading it again. The port is set from the folder's own files only once they verified.
|
|
20
|
+
//
|
|
21
|
+
// When it downloads (createExtensionPackage): with no folder yet, only when the owner starts "Connect your browser"
|
|
22
|
+
// (`ensure`); with a folder that is not the pinned extension, by itself after start-up (`refreshInBackground`), keeping
|
|
23
|
+
// the old folder on any failure. One transfer at a time. Nothing is logged with a path, and the download's working
|
|
24
|
+
// file lives beside the folder, never in it.
|
|
25
|
+
import { readFileSync, rmSync } from 'node:fs';
|
|
26
|
+
import { join } from 'node:path';
|
|
27
|
+
import { downloadFile } from './cli-install.js';
|
|
28
|
+
import { cachedExtensionPackage, confirmExtensionReload, confirmExtensionRepairReload, downloadWorkName, extensionFolderState, extensionWorkDir, inspectExtensionFolder, prepareExtensionFolder, retargetExtensionFolder, verifiedPackageFiles } from './browser-extension-folder.js';
|
|
29
|
+
import { EXTENSION_PACKAGE_HOST, EXTENSION_PIN, pinProblems } from './browser-extension-pin.js';
|
|
30
|
+
|
|
31
|
+
/** What a failed download or check is called (the setup's error codes; lib/browser-extension-setup.js has the words). */
|
|
32
|
+
export const PACKAGE_ERROR_CODES = Object.freeze(['EXTENSION_DOWNLOAD_OFFLINE', 'EXTENSION_DOWNLOAD_UNAVAILABLE', 'EXTENSION_VERIFY_FAILED', 'EXTENSION_FOLDER_FAILED', 'EXTENSION_FOLDER_UNSAFE', 'EXTENSION_DOWNLOAD_CANCELLED']);
|
|
33
|
+
export const PACKAGE_STALL_MS = 20_000;
|
|
34
|
+
export const PACKAGE_TOTAL_MS = 120_000;
|
|
35
|
+
|
|
36
|
+
const packageError = (code, message, detail) => Object.assign(new Error(message), { code, ...(detail ? { detail } : {}) });
|
|
37
|
+
// The transfer's own failure kinds (lib/cli-install.js CLI_INSTALL_ERROR_CODES) as the setup's codes.
|
|
38
|
+
const TRANSFER_CODES = Object.freeze({
|
|
39
|
+
offline: 'EXTENSION_DOWNLOAD_OFFLINE', timeout: 'EXTENSION_DOWNLOAD_OFFLINE', interrupted: 'EXTENSION_DOWNLOAD_OFFLINE',
|
|
40
|
+
http: 'EXTENSION_DOWNLOAD_UNAVAILABLE', checksum: 'EXTENSION_VERIFY_FAILED', disk: 'EXTENSION_FOLDER_FAILED', cancelled: 'EXTENSION_DOWNLOAD_CANCELLED',
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
/** Only the pinned host, on the default HTTPS port, with no credentials in the address. */
|
|
44
|
+
export function allowedPackageHost(url) {
|
|
45
|
+
return url.protocol === 'https:' && url.hostname === EXTENSION_PACKAGE_HOST && (url.port === '' || url.port === '443') && !url.username && !url.password;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// The pinned package's bytes and verified files: { zip, files }. `workDir` holds the transfer's working file, removed
|
|
49
|
+
// whatever happens. Throws one of PACKAGE_ERROR_CODES; never writes anything else.
|
|
50
|
+
async function downloadPackage({ pin = EXTENSION_PIN, workDir, fetchImpl = fetch, signal, onProgress = () => {}, stallMs = PACKAGE_STALL_MS, totalMs = PACKAGE_TOTAL_MS }) {
|
|
51
|
+
if (pinProblems(pin).length) throw packageError('EXTENSION_VERIFY_FAILED', 'This SynaBun has no valid extension pin.');
|
|
52
|
+
const file = join(workDir, downloadWorkName());
|
|
53
|
+
const stop = new AbortController();
|
|
54
|
+
let timedOut = false;
|
|
55
|
+
const timer = setTimeout(() => { timedOut = true; stop.abort(); }, totalMs); timer.unref?.();
|
|
56
|
+
const onAbort = () => stop.abort();
|
|
57
|
+
if (signal?.aborted) onAbort(); else signal?.addEventListener('abort', onAbort, { once: true });
|
|
58
|
+
try {
|
|
59
|
+
let zip;
|
|
60
|
+
try {
|
|
61
|
+
await downloadFile({ url: pin.url, allow: allowedPackageHost, destination: file, maxBytes: pin.size, expectedSize: pin.size, sha256: pin.sha256, fetchImpl, signal: stop.signal, onProgress, stallMs,
|
|
62
|
+
accept: 'application/zip, application/octet-stream', identityOnly: true });
|
|
63
|
+
} catch (error) {
|
|
64
|
+
if (timedOut) throw packageError('EXTENSION_DOWNLOAD_OFFLINE', 'The download took too long.', 'timeout');
|
|
65
|
+
throw packageError(TRANSFER_CODES[error?.code] || 'EXTENSION_FOLDER_FAILED', error?.message || 'The download failed.', error?.code === 'http' ? error.detail : error?.code);
|
|
66
|
+
}
|
|
67
|
+
try { zip = readFileSync(file); } catch { throw packageError('EXTENSION_FOLDER_FAILED', 'The download could not be read back.'); }
|
|
68
|
+
// The bytes that are read are the bytes that were checked: size and SHA-256 once more, over what is in memory.
|
|
69
|
+
let files;
|
|
70
|
+
try { files = verifiedPackageFiles(zip, pin); } catch (error) { throw packageError('EXTENSION_VERIFY_FAILED', error?.message || 'The package cannot be read.'); }
|
|
71
|
+
return { zip, files };
|
|
72
|
+
} finally {
|
|
73
|
+
clearTimeout(timer);
|
|
74
|
+
signal?.removeEventListener('abort', onAbort);
|
|
75
|
+
rmSync(file, { force: true });
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The verified files of the pinned package: [{ rel, bytes }]. `workDir` holds the transfer's working file, which is
|
|
81
|
+
* removed whatever happens. Throws one of PACKAGE_ERROR_CODES; never writes anything else.
|
|
82
|
+
*/
|
|
83
|
+
export async function fetchExtensionPackage(options) { return (await downloadPackage(options)).files; }
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* The owner's extension folder and the package it comes from. `home`: the data home; `appPort`: () => this server's
|
|
87
|
+
* port; `pin`: the release's pin. Returns { status, needs, ensure, refreshInBackground, retarget, confirmReload, confirmRepairReload }.
|
|
88
|
+
*/
|
|
89
|
+
export function createExtensionPackage({ home, appPort, pin = EXTENSION_PIN, fetchImpl = fetch, now = Date.now, log = () => {}, stallMs = PACKAGE_STALL_MS, totalMs = PACKAGE_TOTAL_MS, io }) {
|
|
90
|
+
const port = () => Number(typeof appPort === 'function' ? appPort() : appPort);
|
|
91
|
+
let job = null; // the transfer under way: { promise, reason, received, total, stop }
|
|
92
|
+
let last = null; // how the last one ended: { ok, code, reason, at }
|
|
93
|
+
|
|
94
|
+
const look = () => inspectExtensionFolder({ home, appPort: port(), pin });
|
|
95
|
+
/**
|
|
96
|
+
* What the folder needs: 'install' (no folder), 'update' (a folder that is not exactly the pinned extension: another
|
|
97
|
+
* version, or a file changed, added or deleted), 'unsafe' (its root is a link, another user's or writable by others:
|
|
98
|
+
* nothing is done there), or null (the pinned extension; at most its port is set, with no download).
|
|
99
|
+
*/
|
|
100
|
+
function needs() {
|
|
101
|
+
const state = look().state;
|
|
102
|
+
return state === 'missing' ? 'install' : state === 'other' ? 'update' : state === 'unsafe' ? 'unsafe' : null;
|
|
103
|
+
}
|
|
104
|
+
function status() {
|
|
105
|
+
const state = extensionFolderState(home), need = needs(), shown = state.present ? state : null;
|
|
106
|
+
const failed = need === 'unsafe' ? { code: 'EXTENSION_FOLDER_UNSAFE', reason: 'check', at: null } : !job && last && !last.ok && need ? last : null;
|
|
107
|
+
return {
|
|
108
|
+
pinnedVersion: pin.version, folderVersion: shown ? shown.version : null, folder: shown ? shown.folder : null, needs: need,
|
|
109
|
+
phase: job ? 'downloading' : failed ? 'failed' : 'idle',
|
|
110
|
+
...(job ? { received: job.received, total: job.total, reason: job.reason } : {}),
|
|
111
|
+
...(!job && failed ? { code: failed.code, reason: failed.reason, at: failed.at } : {}),
|
|
112
|
+
// A Reload the folder's marker asks for (a port change, or a repair: lib/browser-extension-folder.js), until the
|
|
113
|
+
// setup page sees the extension running again (confirmReload), or for a repair until the owner confirms it in
|
|
114
|
+
// Settings (confirmRepairReload).
|
|
115
|
+
...(state.reloadPending ? { reloadPending: true, reloadReason: state.reloadReason } : {}),
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
const settle = () => retargetExtensionFolder({ home, appPort: port(), pin, now, io });
|
|
119
|
+
async function run(reason, stop) {
|
|
120
|
+
const workDir = extensionWorkDir(home);
|
|
121
|
+
// A folder this data home can repair or place by itself: the verified package it keeps, with no network.
|
|
122
|
+
const kept = cachedExtensionPackage({ home, pin });
|
|
123
|
+
if (kept) return prepareExtensionFolder({ files: kept, home, appPort: port(), pin, now, io });
|
|
124
|
+
const { zip, files } = await downloadPackage({ pin, workDir, fetchImpl, signal: stop.signal, stallMs, totalMs,
|
|
125
|
+
onProgress: ({ received, total }) => { if (job) { job.received = received; job.total = total || pin.size; } } });
|
|
126
|
+
// A setup the owner cancelled while the last bytes arrived installs nothing.
|
|
127
|
+
if (stop.signal.aborted) throw packageError('EXTENSION_DOWNLOAD_CANCELLED', 'The download was stopped.');
|
|
128
|
+
return prepareExtensionFolder({ files, zip, home, appPort: port(), pin, now, io });
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* The folder, ready to load: when it is the pinned extension, as it is (its setup port set and verified, no network);
|
|
132
|
+
* else after the pinned package was verified and placed. Resolves what prepareExtensionFolder returns; rejects with
|
|
133
|
+
* one of PACKAGE_ERROR_CODES, leaving the folder that was there in place. `signal` stops the transfer.
|
|
134
|
+
*/
|
|
135
|
+
function ensure({ reason = 'setup', signal } = {}) {
|
|
136
|
+
// A transfer that was told to stop is over for whoever asks now (a setup started again): it gets its own, after it.
|
|
137
|
+
if (job?.stop.signal.aborted) {
|
|
138
|
+
const ending = job.promise;
|
|
139
|
+
return ending.then(() => {}, () => {}).then(() => ensure({ reason, signal }));
|
|
140
|
+
}
|
|
141
|
+
if (!job) {
|
|
142
|
+
const need = needs();
|
|
143
|
+
// Its message says why (no path): a link, another user's, others can write it, or a Linux group not proven private.
|
|
144
|
+
if (need === 'unsafe') { const why = look().reason; return Promise.reject(packageError('EXTENSION_FOLDER_UNSAFE', `The extension folder in the data folder is not safe to use${why ? `: ${why}` : ''}.`)); }
|
|
145
|
+
if (!need) {
|
|
146
|
+
// The pinned extension: its port set and the result verified (lib/browser-extension-folder.js), or a failure.
|
|
147
|
+
try {
|
|
148
|
+
const done = settle();
|
|
149
|
+
if (done.state !== 'current') throw packageError('EXTENSION_FOLDER_FAILED', 'The extension folder is not the pinned extension.');
|
|
150
|
+
return Promise.resolve({ folder: done.folder, version: done.version, changed: done.changed, previousVersion: done.version, appPort: port(), stale: false });
|
|
151
|
+
} catch (error) {
|
|
152
|
+
log({ event: 'package', outcome: 'failed', reason: 'port', code: error?.code || 'EXTENSION_FOLDER_FAILED' });
|
|
153
|
+
return Promise.reject(packageError(PACKAGE_ERROR_CODES.includes(error?.code) ? error.code : 'EXTENSION_FOLDER_FAILED', error?.message || 'The extension folder could not be set.'));
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
const stop = new AbortController();
|
|
157
|
+
const mine = { reason, received: 0, total: pin.size, stop, promise: null };
|
|
158
|
+
mine.promise = run(reason, stop).then(
|
|
159
|
+
result => { last = { ok: true, reason, at: now() }; log({ event: 'package', outcome: 'installed', reason, version: result.version, changed: result.changed }); return result; },
|
|
160
|
+
error => {
|
|
161
|
+
const code = PACKAGE_ERROR_CODES.includes(error?.code) ? error.code : 'EXTENSION_FOLDER_FAILED';
|
|
162
|
+
// The owner stopped it: nothing failed, and there is nothing to report. A folder that is still not the pinned
|
|
163
|
+
// extension is the exception: its update did not happen, nothing is running, and Settings has to offer Try again.
|
|
164
|
+
const cancelled = code === 'EXTENSION_DOWNLOAD_CANCELLED';
|
|
165
|
+
last = cancelled && needs() !== 'update' ? null : { ok: false, code, reason, at: now() };
|
|
166
|
+
log({ event: 'package', outcome: cancelled ? 'cancelled' : 'failed', reason, code, ...(typeof error?.detail === 'string' ? { detail: error.detail.slice(0, 40) } : {}) });
|
|
167
|
+
throw packageError(code, error?.message || code);
|
|
168
|
+
},
|
|
169
|
+
).finally(() => { if (job === mine) job = null; });
|
|
170
|
+
job = mine;
|
|
171
|
+
}
|
|
172
|
+
const current = job;
|
|
173
|
+
// A setup stops only a transfer made for a setup: one that joined the background update leaves it running.
|
|
174
|
+
if (signal && current.reason === 'setup') {
|
|
175
|
+
const onAbort = () => current.stop.abort();
|
|
176
|
+
if (signal.aborted) onAbort(); else { signal.addEventListener('abort', onAbort, { once: true }); current.promise.then(() => {}, () => {}).finally(() => signal.removeEventListener('abort', onAbort)); }
|
|
177
|
+
}
|
|
178
|
+
return current.promise;
|
|
179
|
+
}
|
|
180
|
+
return {
|
|
181
|
+
pin, needs, status, ensure,
|
|
182
|
+
/** After start-up: bring a folder that is not the pinned extension up to date. Never downloads for a folder that is not there. */
|
|
183
|
+
refreshInBackground() {
|
|
184
|
+
if (job || needs() !== 'update') return null;
|
|
185
|
+
const promise = ensure({ reason: 'update' });
|
|
186
|
+
promise.catch(() => {});
|
|
187
|
+
return promise;
|
|
188
|
+
},
|
|
189
|
+
/**
|
|
190
|
+
* At start-up (no network): a stopped replacement settled, leftovers removed, the pinned extension's setup port set
|
|
191
|
+
* to this server's, and a changed folder repaired from the verified package this data home keeps. Throws
|
|
192
|
+
* EXTENSION_FOLDER_FAILED / EXTENSION_FOLDER_UNSAFE.
|
|
193
|
+
*/
|
|
194
|
+
retarget: settle,
|
|
195
|
+
/** The setup page saw the extension on this port: a Reload a port change asked for is done (never a repair's). */
|
|
196
|
+
confirmReload: () => confirmExtensionReload({ home, appPort: port() }),
|
|
197
|
+
/** The owner confirmed in Settings that they reloaded the extension after a repair: that Reload is done. */
|
|
198
|
+
confirmRepairReload: () => confirmExtensionRepairReload({ home }),
|
|
199
|
+
};
|
|
200
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// Which SynaBun Browser Bridge this app release works with, and who the extension is.
|
|
2
|
+
//
|
|
3
|
+
// The extension is not inside the app (no npm file, no installer payload). The app knows it by two things kept here,
|
|
4
|
+
// in app-owned code, so the server starts and pairs with no extension folder and no network:
|
|
5
|
+
//
|
|
6
|
+
// identity the extension's public key (the manifest's `key`). The extension ID is derived from it (EXTENSION_ID)
|
|
7
|
+
// and is what the bridge accepts as an Origin. It never changes, so a paired browser stays paired.
|
|
8
|
+
// release one exact package per app release: its version, its address on synabun.ai, its size and SHA-256
|
|
9
|
+
// (browser-extension-pin.json). The wire contract rejects unknown fields, so app and extension move in
|
|
10
|
+
// lock-step: a download is installed only when it is exactly that file (lib/browser-extension-package.js).
|
|
11
|
+
// files the SHA-256 of every file of that package (the manifest's with its setup content script set to one
|
|
12
|
+
// fixed port, TEMPLATE_PORT of lib/browser-extension-folder.js). The folder the browser loads is current
|
|
13
|
+
// only when it holds exactly these files, byte for byte, and nothing else (inspectExtensionFolder).
|
|
14
|
+
//
|
|
15
|
+
// The pin file is written by scripts/extension/check-browser-extension-pin.mjs (Dev only) and checked by it before a
|
|
16
|
+
// release. Nothing here reads the network or the data home.
|
|
17
|
+
import { createHash } from 'node:crypto';
|
|
18
|
+
import { readFileSync } from 'node:fs';
|
|
19
|
+
import { EXTENSION_MAX_FILES, extensionFileAllowed } from './browser-extension-archive.js';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The one host an extension package may come from, and the folder its versioned, immutable files live in. The website
|
|
23
|
+
* serves its `Public/` tree under that same name (its build copies a .zip there byte for byte, and its image copies
|
|
24
|
+
* no other top-level folder), so the file `Public/downloads/browser-extension/<name>` of the website is this address.
|
|
25
|
+
*/
|
|
26
|
+
export const EXTENSION_PACKAGE_HOST = 'synabun.ai';
|
|
27
|
+
export const EXTENSION_PACKAGE_PATH = '/Public/downloads/browser-extension/';
|
|
28
|
+
/** No package is ever larger than this, whatever a pin says (the real one is about 0.2 MB). */
|
|
29
|
+
export const EXTENSION_PACKAGE_MAX_BYTES = 8 * 1024 * 1024;
|
|
30
|
+
|
|
31
|
+
/** The file name of a version's package. */
|
|
32
|
+
export function extensionPackageName(version) { return `synabun-browser-bridge-${version}.zip`; }
|
|
33
|
+
/** The address of a version's package: https, the one host, a versioned path that is never reused. */
|
|
34
|
+
export function extensionPackageUrl(version) { return `https://${EXTENSION_PACKAGE_HOST}${EXTENSION_PACKAGE_PATH}${extensionPackageName(version)}`; }
|
|
35
|
+
/** The extension ID a browser gives the extension with this public key (base64 DER): SHA-256, 16 bytes, as a-p. */
|
|
36
|
+
export function extensionIdOf(key) {
|
|
37
|
+
return createHash('sha256').update(Buffer.from(String(key), 'base64')).digest('hex').slice(0, 32).replace(/[0-9a-f]/g, c => String.fromCharCode(97 + parseInt(c, 16)));
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The extension's ID since it was first published. It is derived from the key, and a browser keeps an extension's
|
|
41
|
+
* pairing under its ID: a pin whose key gives another ID would be another extension, and every owner would pair again.
|
|
42
|
+
* scripts/extension/check-browser-extension-pin.mjs refuses to write or pass such a pin.
|
|
43
|
+
*/
|
|
44
|
+
export const HISTORICAL_EXTENSION_ID = 'hnoncohimcacnnlngchbkgpflpoefnil';
|
|
45
|
+
/** What is wrong with a pin's file list (an empty list: nothing). */
|
|
46
|
+
export function inventoryProblems(files) {
|
|
47
|
+
if (!files || typeof files !== 'object' || Array.isArray(files)) return ['files is not an object'];
|
|
48
|
+
const names = Object.keys(files), problems = [], seen = new Set();
|
|
49
|
+
if (!names.length || names.length > EXTENSION_MAX_FILES) problems.push(`files lists no file, or more than ${EXTENSION_MAX_FILES}`);
|
|
50
|
+
if (!names.includes('manifest.json')) problems.push('files has no manifest.json');
|
|
51
|
+
for (const name of names) {
|
|
52
|
+
if (!extensionFileAllowed(name)) problems.push(`files names ${JSON.stringify(name.slice(0, 80))}, which no extension folder may hold`);
|
|
53
|
+
else if (seen.has(name.toLowerCase())) problems.push(`files names ${name} twice`);
|
|
54
|
+
seen.add(name.toLowerCase());
|
|
55
|
+
if (typeof files[name] !== 'string' || !/^[a-f0-9]{64}$/.test(files[name])) problems.push(`files.${name} is not 64 lowercase hex characters`);
|
|
56
|
+
}
|
|
57
|
+
return problems;
|
|
58
|
+
}
|
|
59
|
+
/** What is wrong with a pin (an empty list: nothing). */
|
|
60
|
+
export function pinProblems(pin) {
|
|
61
|
+
const problems = [];
|
|
62
|
+
if (!pin || typeof pin !== 'object') return ['the pin is not an object'];
|
|
63
|
+
if (typeof pin.name !== 'string' || !pin.name) problems.push('name is missing');
|
|
64
|
+
if (typeof pin.key !== 'string' || !/^[A-Za-z0-9+/]{300,}={0,2}$/.test(pin.key)) problems.push('key is not a base64 public key');
|
|
65
|
+
if (typeof pin.version !== 'string' || !/^\d+(\.\d+){1,3}$/.test(pin.version)) problems.push('version is not a dotted version');
|
|
66
|
+
if (typeof pin.sha256 !== 'string' || !/^[a-f0-9]{64}$/.test(pin.sha256)) problems.push('sha256 is not 64 lowercase hex characters');
|
|
67
|
+
if (!Number.isInteger(pin.size) || pin.size < 1 || pin.size > EXTENSION_PACKAGE_MAX_BYTES) problems.push(`size is not a whole number of bytes up to ${EXTENSION_PACKAGE_MAX_BYTES}`);
|
|
68
|
+
if (typeof pin.version === 'string' && pin.url !== extensionPackageUrl(pin.version)) problems.push(`url is not ${extensionPackageUrl(pin.version)}`);
|
|
69
|
+
problems.push(...inventoryProblems(pin.files));
|
|
70
|
+
return problems;
|
|
71
|
+
}
|
|
72
|
+
/** Reads and checks a pin file. Throws with every problem named. */
|
|
73
|
+
export function readExtensionPin(path) {
|
|
74
|
+
const { $comment: _comment, ...pin } = JSON.parse(readFileSync(path, 'utf8'));
|
|
75
|
+
const problems = pinProblems(pin);
|
|
76
|
+
if (problems.length) throw Object.assign(new Error(`The browser extension pin is not valid: ${problems.join('; ')}.`), { code: 'EXTENSION_PIN_INVALID' });
|
|
77
|
+
return Object.freeze({ ...pin, files: Object.freeze({ ...pin.files }) });
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export const EXTENSION_PIN_PATH = new URL('./browser-extension-pin.json', import.meta.url);
|
|
81
|
+
/** This release's pin: { name, key, version, url, sha256, size, files }. */
|
|
82
|
+
export const EXTENSION_PIN = readExtensionPin(EXTENSION_PIN_PATH);
|
|
83
|
+
/** The extension's ID in every Chromium browser, from every folder it is loaded from. */
|
|
84
|
+
export const EXTENSION_ID = extensionIdOf(EXTENSION_PIN.key);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$comment": "The one SynaBun Browser Bridge this app release works with (docs/browser-extension-bridge.md -> Where the extension comes from). The app downloads exactly this file when the owner presses \"Connect your browser\" and installs it only when its size and SHA-256 are these. files is the SHA-256 of every file in it (the manifest with its setup content script set to port 1): the folder the browser loads counts as this extension only when it holds exactly these files. version, url, sha256, size and files are written by `node scripts/extension/check-browser-extension-pin.mjs --write` from the zip built out of browser-extension/ (Dev only); never edit them by hand. key is the extension's public key (its manifest's `key`): the extension ID is derived from it and never changes.",
|
|
3
|
+
"name": "SynaBun Browser Bridge",
|
|
4
|
+
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsDPDDuBTQq9nQgulmTSvzujxyOMZ7A7ttMSXtbIwup/X3kOlbkqoJEqQRGGJeb7+cNBSiiDBA5lhS0oYc9YeFcwNCucNMvGawDGblbQzDWEmn9dDK1krFVXWqNHVPIrEWlzCD2swXmIE2FCjMd5zw6dSRmmxu7VgE6bzvuOgB/W/oeOAyCsEDhDRDLBkjmb+yCsuexiXRWoempPsvAVhxhE8zEQJ1e8ChlFMtpOXSobU+YDgKYfcFy9Fbmk/o6M6B9y5zSlzs/HYIu7xvcCwjZI457idVMRxxAT6J/kXytmfKe/zbi5IO5/i0x9SCA1HRvt8K3nJqoH03h4TOvFwOwIDAQAB",
|
|
5
|
+
"version": "1.4.0",
|
|
6
|
+
"url": "https://synabun.ai/Public/downloads/browser-extension/synabun-browser-bridge-1.4.0.zip",
|
|
7
|
+
"sha256": "6c6fdd942c9b11173758701678571d3c60f1b56aa8712e3f754d6c7b8a7a96bb",
|
|
8
|
+
"size": 206907,
|
|
9
|
+
"files": {
|
|
10
|
+
"content.js": "5420e3bf96c4aea5c7d5f529264eedd49bae9431da3f52abb96de536a4f48944",
|
|
11
|
+
"engine.js": "653f06e353e99b7c417e61c1415925673455ffce075105ba794ae740e6a2c816",
|
|
12
|
+
"icons/icon-128.png": "0749c9c8b40090232e0a234443c634117275598630ec06f4834d20bcad2b6841",
|
|
13
|
+
"icons/icon-16.png": "e91f674029855c7ea4bc6ca045087fe867ddba706209707060379c4832c15422",
|
|
14
|
+
"icons/icon-32.png": "5cc0916b2557a8d13c479a7e3a0170584be4c2f58cf770899c1be1aea106fe53",
|
|
15
|
+
"icons/icon-48.png": "6076ff8376ddf79356adc53672524b893f35a007c1666c9b3873c15803a386d8",
|
|
16
|
+
"icons/status-off-16.png": "b860b60a99a5f89bb024fd8411c6645ca071fabc4eee807dad7d7e1a0eec6a26",
|
|
17
|
+
"icons/status-off-32.png": "9ecc6608dd8da21b3d35497aa94480bb4c8b542398d6d8b35b35d3912e72c7c1",
|
|
18
|
+
"icons/status-off-48.png": "9b1395d665df287e299b20b5ba7a0503eb880cd0797fa07c600572491e126c9a",
|
|
19
|
+
"icons/status-on-16.png": "c9cbb6e4211f918b2179a796908cf9ebcf7cb5723d9aaa38a93486c2e3b0cd3e",
|
|
20
|
+
"icons/status-on-32.png": "b67d8fb865e02754ca0d1f1f2e0ead08655340a4ad93511e52ff65db4d487ed7",
|
|
21
|
+
"icons/status-on-48.png": "c9f306fb5dcbd6a919e5169e3c87c618116bad54858b434b02245dcd1a40b269",
|
|
22
|
+
"manifest.json": "d027d047542b2affa0c2528ee1863de29767f4b2d9abdc79085022455b301735",
|
|
23
|
+
"popup-strings.js": "683063d9896a306b3abf5d19283ba38a8f0ed88a0c32db1f028262fa1d075107",
|
|
24
|
+
"popup-view.js": "c7c9bd582a893d11ca088544e64dd5661c75406920ef5f2b0609a44a58f183c4",
|
|
25
|
+
"popup.css": "d6a6c5442942bede66f315accef476c591ad71ea4ac09b51d689a622753208f1",
|
|
26
|
+
"popup.html": "b04a333f7c7db956fe30dfc760e2bb528984dcf874d5a8e5849776209b8529ec",
|
|
27
|
+
"popup.js": "62a83c93aa9657e16dbd81eb6e853cc772794b22042fca051ea8744c55602670",
|
|
28
|
+
"protocol.js": "7b29203855da05a6122565273b77094e2abfd91d2e820ac90797d6317bb8bea4",
|
|
29
|
+
"service-worker.js": "b8871ebe8b62b1e8d44c6b38757175cd8d519534ed04360597c8cc19cc956b88",
|
|
30
|
+
"setup-content.js": "9cb56f6f046af294328c03a080cefc58052ee405366eff5f3d70bb1ea02dbabe",
|
|
31
|
+
"tokens.css": "a27f691794d844cb81b98b45e12863b102e06e9f0a3c722ba96b69b84d3c5a3f"
|
|
32
|
+
}
|
|
33
|
+
}
|
package/{browser-extension/protocol.js → neural-interface/lib/browser-extension-protocol.js}
RENAMED
|
@@ -18,6 +18,38 @@ export function localDeadline(receivedAt, deadline) { return receivedAt + deadli
|
|
|
18
18
|
// The watchdog for a browser call that never returns: once a command runs, the queue waits at most this long for it.
|
|
19
19
|
// It never gives a command more time than its deadline; the effective limit is the earlier of the two.
|
|
20
20
|
export const QUEUE_LIMIT = 30000;
|
|
21
|
+
// ── Long operations (1.4.0): running page JavaScript (`evaluate`) and a load-state wait (`wait` with `loadState`) ──
|
|
22
|
+
// They may take longer than COMMAND_WAIT, so they carry a longer deadline (up to LONG_WAIT) and never hold the worker's
|
|
23
|
+
// queue: the extension runs them beside the ordinary commands, each under its own deadline. The server waits
|
|
24
|
+
// commandWait(op, args) for one: the operation's own timeout plus LONG_MARGIN, never less than COMMAND_WAIT.
|
|
25
|
+
export const LONG_WAIT = 65000;
|
|
26
|
+
export const LONG_MARGIN = 5000;
|
|
27
|
+
// evaluate: the script's own timeout (args.timeout; default, most), the script source and its JSON arguments (characters),
|
|
28
|
+
// and the JSON text of its result (characters; a longer one is cut and flagged `truncated`).
|
|
29
|
+
export const EVALUATE_TIMEOUT = 30000;
|
|
30
|
+
export const EVALUATE_TIMEOUT_MAX = 60000;
|
|
31
|
+
export const EVALUATE_SCRIPT_MAX = 500000;
|
|
32
|
+
export const EVALUATE_PARAMS_MAX = 100000;
|
|
33
|
+
export const EVALUATE_RESULT_MAX = 1000000;
|
|
34
|
+
// 'MAIN' is the page's own JavaScript world (its globals are visible); 'USER_SCRIPT' is Chrome's separate world for
|
|
35
|
+
// user scripts (the DOM, none of the page's globals, exempt from the page's CSP).
|
|
36
|
+
export const EVALUATE_WORLDS = ['MAIN', 'USER_SCRIPT'];
|
|
37
|
+
// wait with loadState: 'load' (the tab finished loading) or 'networkidle' (also no request of the tab in flight for
|
|
38
|
+
// NETWORK_IDLE_QUIET ms, as Playwright counts it), within args.timeout (default, most).
|
|
39
|
+
export const LOAD_STATES = ['load', 'networkidle'];
|
|
40
|
+
export const NETWORK_IDLE_QUIET = 500;
|
|
41
|
+
export const NETWORK_IDLE_TIMEOUT = 15000;
|
|
42
|
+
export const NETWORK_IDLE_TIMEOUT_MAX = 60000;
|
|
43
|
+
export function longOp(op, args) { return op === 'evaluate' || op === 'wait' && args?.loadState !== undefined; }
|
|
44
|
+
// The operation's own time limit (ms), from args.timeout: its default when none is given, never above its most.
|
|
45
|
+
export function longBudget(op, args = {}) {
|
|
46
|
+
const [normal, most] = op === 'evaluate' ? [EVALUATE_TIMEOUT, EVALUATE_TIMEOUT_MAX] : [NETWORK_IDLE_TIMEOUT, NETWORK_IDLE_TIMEOUT_MAX];
|
|
47
|
+
return Math.max(1, Math.min(Number.isSafeInteger(args?.timeout) ? args.timeout : normal, most));
|
|
48
|
+
}
|
|
49
|
+
// How long the server waits for the answer to a command, and the most its `deadline` may say.
|
|
50
|
+
export function commandWait(op, args = {}) {
|
|
51
|
+
return longOp(op, args) ? Math.max(COMMAND_WAIT, Math.min(LONG_WAIT, longBudget(op, args) + LONG_MARGIN)) : COMMAND_WAIT;
|
|
52
|
+
}
|
|
21
53
|
export function fail(code, message = code) { throw Object.assign(new Error(message), { code }); }
|
|
22
54
|
export function object(value, keys) {
|
|
23
55
|
if (!value || typeof value !== 'object' || Array.isArray(value) || Object.keys(value).some(k => !keys.includes(k))) fail('INVALID_MESSAGE');
|
|
@@ -131,7 +163,10 @@ export function inventory(value) {
|
|
|
131
163
|
}
|
|
132
164
|
return value;
|
|
133
165
|
}
|
|
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'];
|
|
166
|
+
export const COMMANDS = ['create', 'claim', 'release', 'navigate', 'back', 'forward', 'reload', 'snapshot', 'click', 'hover', 'fill', 'type', 'press', 'select', 'scroll', 'wait', 'content', 'screenshot', 'upload', 'download', 'evaluate', 'revokeTab', 'revokeSite', 'disconnect', 'revoke', 'mode', 'reset'];
|
|
167
|
+
// The first extension version that knows `evaluate` and `wait` with `loadState`. An older one ends the connection on a
|
|
168
|
+
// command it does not know, so the server never sends it one (it answers EXTENSION_RELOAD_REQUIRED itself).
|
|
169
|
+
export const LONG_OPS_SINCE = '1.4.0';
|
|
135
170
|
export const HISTORY = ['back', 'forward'];
|
|
136
171
|
// The owner's control messages: revocations, the mode (full control or restricted) and `reset` (a restarted server
|
|
137
172
|
// hands back every tab agents of its previous process held). They overtake queued commands on both sides, are never
|
|
@@ -142,17 +177,24 @@ export function command(value) {
|
|
|
142
177
|
if (value.type !== 'command' || !COMMANDS.includes(value.op)) fail('UNSUPPORTED_IN_EXTENSION_MODE');
|
|
143
178
|
handle(value.id); if (value.tab !== null) handle(value.tab); handle(value.owner);
|
|
144
179
|
// Required on every command: whole milliseconds, 1 to COMMAND_WAIT (the server never has more left than its wait).
|
|
145
|
-
|
|
180
|
+
// A long operation's may reach commandWait(op, args): checked below, once its arguments are known to be an object.
|
|
181
|
+
if (!Number.isSafeInteger(value.deadline) || value.deadline < 1 || value.deadline > LONG_WAIT) fail('INVALID_MESSAGE');
|
|
146
182
|
// SynaBun's own addresses, which no command may reach (controlSurface): its public aliases (any port), its ports,
|
|
147
183
|
// and this computer's names and interface addresses.
|
|
148
184
|
for (const key of ['blockedHosts', 'selfHosts']) {
|
|
149
185
|
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
186
|
}
|
|
151
187
|
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'
|
|
188
|
+
const a = value.args; object(a, ['url', 'ref', 'selector', 'nthMatch', 'value', 'text', 'key', 'direction', 'distance', 'maxChars', 'offset', 'timeout', 'state', 'files', 'site', 'fullControl', 'version',
|
|
189
|
+
'expression', 'body', 'params', 'world', 'frame', 'loadState']);
|
|
190
|
+
if (value.deadline > commandWait(value.op, a)) fail('INVALID_MESSAGE');
|
|
153
191
|
for (const [k, v] of Object.entries(a)) {
|
|
154
192
|
if (k === 'fullControl') { if (typeof v !== 'boolean') fail('INVALID_MESSAGE'); }
|
|
155
193
|
else if (k === 'version') { if (!Number.isSafeInteger(v) || v < 0) fail('INVALID_MESSAGE'); }
|
|
194
|
+
// A frame of the tab, by Chrome's frame id (0, the default, is the top document).
|
|
195
|
+
else if (k === 'frame') { if (!Number.isSafeInteger(v) || v < 0 || v > 2147483647) fail('INVALID_MESSAGE'); }
|
|
196
|
+
else if (k === 'expression' || k === 'body') string(v, EVALUATE_SCRIPT_MAX);
|
|
197
|
+
else if (k === 'params') string(v, EVALUATE_PARAMS_MAX);
|
|
156
198
|
else if (['nthMatch', 'distance', 'maxChars', 'offset', 'timeout'].includes(k)) {
|
|
157
199
|
if (!Number.isSafeInteger(v) || v < 0 || v > 1000000) fail('INVALID_MESSAGE');
|
|
158
200
|
} else if (k === 'files') {
|
|
@@ -175,18 +217,50 @@ export function command(value) {
|
|
|
175
217
|
if (HISTORY.includes(value.op) && (value.tab === null || Object.keys(a).length)) fail('INVALID_MESSAGE');
|
|
176
218
|
if (a.direction !== undefined && !['up', 'down', 'left', 'right'].includes(a.direction)) fail('INVALID_MESSAGE');
|
|
177
219
|
if (a.state !== undefined && !['visible', 'hidden', 'attached', 'detached'].includes(a.state)) fail('INVALID_MESSAGE');
|
|
220
|
+
// evaluate: exactly one of `expression` (one JavaScript expression; a function it evaluates to is called with the
|
|
221
|
+
// arguments) and `body` (the body of an async function whose parameter `args` is the array of arguments), with
|
|
222
|
+
// `params` (the arguments: the JSON text of an array), `world`, `frame`, `timeout` and `maxChars`, and nothing else.
|
|
223
|
+
const evaluate = ['expression', 'body', 'params', 'world', 'frame'];
|
|
224
|
+
if (value.op === 'evaluate') {
|
|
225
|
+
if (value.tab === null || (typeof a.expression === 'string') === (typeof a.body === 'string') || !(a.expression ?? a.body).trim()) fail('INVALID_MESSAGE');
|
|
226
|
+
if (Object.keys(a).some(k => !evaluate.includes(k) && k !== 'timeout' && k !== 'maxChars')) fail('INVALID_MESSAGE');
|
|
227
|
+
if (a.world !== undefined && !EVALUATE_WORLDS.includes(a.world)) fail('INVALID_MESSAGE');
|
|
228
|
+
if (a.params !== undefined) {
|
|
229
|
+
let list; try { list = JSON.parse(a.params); } catch { list = null; }
|
|
230
|
+
if (!Array.isArray(list)) fail('INVALID_MESSAGE');
|
|
231
|
+
}
|
|
232
|
+
} else if (evaluate.some(k => a[k] !== undefined)) fail('INVALID_MESSAGE');
|
|
233
|
+
// A load-state wait names the state and, at most, its timeout: it waits for the tab, not for an element.
|
|
234
|
+
if (a.loadState !== undefined && (value.op !== 'wait' || value.tab === null || !LOAD_STATES.includes(a.loadState)
|
|
235
|
+
|| Object.keys(a).some(k => k !== 'loadState' && k !== 'timeout'))) fail('INVALID_MESSAGE');
|
|
178
236
|
return value;
|
|
179
237
|
}
|
|
180
238
|
export function payload(value) {
|
|
181
239
|
if (value?.type === 'state') { object(value, ['type', 'inventory']); inventory(value.inventory); }
|
|
182
240
|
else if (value?.type === 'result') {
|
|
183
241
|
object(value, ['type', 'id', 'result', 'inventory']); handle(value.id); inventory(value.inventory);
|
|
184
|
-
|
|
242
|
+
// evaluate adds `value` (the JSON text of the script's result), `truncated` with `valueLength` (the result was
|
|
243
|
+
// longer than its cap: `value` is then the beginning of that JSON text, not valid JSON) and, with code PAGE_ERROR,
|
|
244
|
+
// `errorMessage` and `errorStack` (what the page's script threw). A load-state wait adds `loadState`.
|
|
245
|
+
object(value.result, ['ok', 'code', 'error', 'url', 'title', 'snapshotText', 'mode', 'snapshotId', 'content', 'text', 'base64', 'mimeType', 'tab', 'downloadId', 'files',
|
|
246
|
+
'value', 'truncated', 'valueLength', 'errorMessage', 'errorStack', 'loadState']);
|
|
185
247
|
if (typeof value.result.ok !== 'boolean') fail('INVALID_MESSAGE');
|
|
186
248
|
for (const [k, v] of Object.entries(value.result)) {
|
|
187
249
|
if (k === 'ok') continue;
|
|
188
|
-
if (k === '
|
|
189
|
-
|
|
250
|
+
if (k === 'files') {
|
|
251
|
+
if (!Array.isArray(v) || !v.length || v.length > 4) fail('INVALID_MESSAGE');
|
|
252
|
+
let total = 0;
|
|
253
|
+
for (const file of v) {
|
|
254
|
+
object(file, ['name', 'type', 'size']);
|
|
255
|
+
if (!string(file.name, 255) || /[\\/]/.test(file.name) || !string(file.type, 255)) fail('INVALID_MESSAGE');
|
|
256
|
+
if (!Number.isSafeInteger(file.size) || file.size < 0) fail('INVALID_MESSAGE');
|
|
257
|
+
total += file.size;
|
|
258
|
+
}
|
|
259
|
+
if (total > MAX_FILE) fail('INVALID_MESSAGE');
|
|
260
|
+
} else if (k === 'downloadId') { if (!Number.isSafeInteger(v)) fail('INVALID_MESSAGE'); }
|
|
261
|
+
else if (k === 'valueLength') { if (!Number.isSafeInteger(v) || v < 0) fail('INVALID_MESSAGE'); }
|
|
262
|
+
else if (k === 'truncated') { if (typeof v !== 'boolean') fail('INVALID_MESSAGE'); }
|
|
263
|
+
else string(v, k === 'base64' ? MAX_MESSAGE - 4096 : ['content', 'text', 'snapshotText', 'value'].includes(k) ? EVALUATE_RESULT_MAX : 8192);
|
|
190
264
|
}
|
|
191
265
|
} else if (value?.type === 'ping' || value?.type === 'pong' || value?.type === 'unpair') object(value, ['type']);
|
|
192
266
|
// The server gave up on a command (its wait ended): the extension stops it, queued or running, and never starts it.
|
|
@@ -222,9 +296,20 @@ export const ERROR_TEXT = Object.freeze({
|
|
|
222
296
|
UPLOAD_TOO_LARGE: 'The selected files exceed the 50 MB total upload limit.',
|
|
223
297
|
UPLOAD_FILE_REFUSED: 'Choose readable regular files inside the extension upload folder shown in Settings → Browser.',
|
|
224
298
|
UPLOAD_MULTIPLE: 'This file input accepts only one file.',
|
|
299
|
+
UPLOAD_DISABLED: 'The file input is disabled.',
|
|
300
|
+
UPLOAD_ACCEPT_MISMATCH: 'The file input’s accept filter excludes one or more selected files. Check the accepted MIME types or filename extensions.',
|
|
301
|
+
UPLOAD_ASSIGNMENT_FAILED: 'The file input did not receive the expected names, types and sizes.',
|
|
302
|
+
UPLOAD_METADATA_UNAVAILABLE: 'Restart SynaBun and reload SynaBun Browser Bridge to enable file metadata.',
|
|
225
303
|
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
304
|
TIMEOUT: 'The operation timed out. Its outcome may be uncertain; observe before retrying.',
|
|
227
305
|
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.',
|
|
306
|
+
USER_SCRIPTS_DISABLED: 'Running page JavaScript is switched off for the SynaBun extension in this browser. The owner switches it on once: open chrome://extensions (edge://extensions in Edge), choose Details on "SynaBun Browser Bridge", turn on "Allow User Scripts" (Chrome or Edge 138 and later; on an older version turn on Developer mode at the top of that page instead), then press Reload on the extension. Nothing was run.',
|
|
307
|
+
USER_SCRIPTS_UNSUPPORTED: 'This browser cannot run page JavaScript for an extension (chrome.userScripts.execute needs Chrome or Edge 135 or later). Update the browser. Nothing was run.',
|
|
308
|
+
EXTENSION_RELOAD_REQUIRED: 'The paired browser still runs an older SynaBun Browser Bridge than this operation needs. The owner reloads it on the browser’s extensions page (chrome://extensions → SynaBun Browser Bridge → Reload). Nothing was done.',
|
|
309
|
+
PAGE_ERROR: 'The page’s script threw, or did not compile (evaluate takes one expression: wrap statements in a function, (() => { …; return value; })()). errorMessage and errorStack say what the page reported; the bridge itself did not fail.',
|
|
310
|
+
BLANK_PAGE: 'The tab shows the blank start page, where no script can run. Navigate it to an http(s) page first.',
|
|
311
|
+
FRAME_NOT_FOUND: 'The tab has no frame with this id that a script can run in (frame 0 is the top document). Nothing was run.',
|
|
312
|
+
NETWORK_IDLE_UNAVAILABLE: 'The extension cannot watch this browser’s network requests (its webRequest permission is not in effect). The owner reloads SynaBun Browser Bridge on the browser’s extensions page; until then wait for a selector or a fixed time instead.',
|
|
228
313
|
});
|
|
229
314
|
export function safeError(error) {
|
|
230
315
|
const code = Object.hasOwn(ERROR_TEXT, error?.code) ? error.code : 'OPERATION_FAILED';
|