synabun 2.3.0 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +38 -0
- package/README.md +1 -1
- package/browser-extension/content.js +169 -0
- package/browser-extension/engine.js +477 -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 +244 -0
- package/browser-extension/popup-view.js +151 -0
- package/browser-extension/popup.css +165 -0
- package/browser-extension/popup.html +105 -0
- package/browser-extension/popup.js +347 -0
- package/browser-extension/protocol.js +226 -0
- package/browser-extension/service-worker.js +267 -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/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 +94 -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 +91 -9
- package/mcp-server/dist/tools/agents.d.ts.map +1 -1
- package/mcp-server/dist/tools/agents.js +161 -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 +190 -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 +175 -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 +1174 -47
- package/neural-interface/i18n/pt-BR.json +1174 -47
- package/neural-interface/lib/account-usage.js +1 -1
- 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 +840 -0
- package/neural-interface/lib/agents/resolve.js +544 -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-catalog.js +2 -0
- package/neural-interface/lib/assistant-continuity.js +49 -0
- package/neural-interface/lib/assistant-dispatch.js +229 -102
- 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 +384 -42
- 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 +440 -93
- 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/browser-close-evidence.js +80 -0
- package/neural-interface/lib/browser-default.js +210 -0
- package/neural-interface/lib/browser-extension-adapter.js +255 -0
- package/neural-interface/lib/browser-extension-bridge.js +418 -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-profiles.js +1 -1
- 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/cli-install-api.js +23 -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/editor-completion-opencode.js +4 -3
- package/neural-interface/lib/effort-levels.js +10 -1
- package/neural-interface/lib/maritaca/opencode-proxy.js +7 -2
- package/neural-interface/lib/maritaca/opencode.js +35 -0
- 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 +219 -7
- package/neural-interface/lib/native-loop-runtime.js +24 -1
- package/neural-interface/lib/opencode-build-preflight.js +116 -0
- package/neural-interface/lib/opencode-launch-error.js +13 -0
- package/neural-interface/lib/opencode-native-boundary.js +800 -84
- package/neural-interface/lib/opencode-serve-probe.js +426 -0
- package/neural-interface/lib/opencode-serve-records.js +14 -9
- package/neural-interface/lib/opencode-serve-scan.js +108 -0
- package/neural-interface/lib/page-session.js +1 -1
- package/neural-interface/lib/peer-identity.js +60 -21
- package/neural-interface/lib/process-identity.js +235 -7
- package/neural-interface/lib/request-gate.js +3 -0
- package/neural-interface/lib/screenshot-location.js +33 -0
- 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/lib/worker-mcp-channel.js +38 -1
- package/neural-interface/package-lock.json +4 -2
- package/neural-interface/package.json +3 -1
- package/neural-interface/public/extension-setup.html +107 -0
- package/neural-interface/public/index.html +52 -12
- 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/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 +36 -6
- package/neural-interface/public/shared/assistant/asst-route.js +78 -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/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 +33 -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/opencode-verify-view.js +175 -0
- 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/storage.js +6 -1
- package/neural-interface/public/shared/studio-attention.js +83 -0
- package/neural-interface/public/shared/styles.css +713 -61
- 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 +12 -1
- 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 +1 -1
- 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-opencode-verify.js +120 -0
- 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 +372 -402
- 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 +5 -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/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 +21 -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 +1164 -157
- package/npm-shrinkwrap.json +2 -2
- package/package.json +3 -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
|
@@ -1,28 +1,88 @@
|
|
|
1
|
-
// Native page WebSockets are safe only behind a server boundary established at
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
|
|
1
|
+
// Native page WebSockets are safe only behind a server boundary established at listen time: a page in a native
|
|
2
|
+
// (MoreLogin) context can open ws://127.0.0.1:<port>/… of any local serve, and an unauthenticated OpenCode serve would
|
|
3
|
+
// give it a shell, files and sessions. What admits a serve is how it behaves, checked at run time
|
|
4
|
+
// (lib/opencode-serve-probe.js): it listens on loopback only, refuses every sensitive route without its password
|
|
5
|
+
// (plain HTTP and WebSocket upgrades, with no credentials and with wrong ones), and accepts the password SynaBun read
|
|
6
|
+
// from its own stdout. The version is only a precondition, checked on EVERY verification: it must read as
|
|
7
|
+
// MAJOR.MINOR.PATCH and be NATIVE_SERVE_MIN_VERSION or newer, as launched and as the serve reports it.
|
|
8
|
+
// For a foreign serve (no password for /api/info), its OS-identified executable must report that version instead;
|
|
9
|
+
// the cache includes the executable identity and version, re-read on every scan, as well as the listener generation.
|
|
10
|
+
//
|
|
11
|
+
// Admission uses build pre-flight evidence and then checks every real process. This is Option 1: a verified build
|
|
12
|
+
// may misbehave at runtime before its post-start probe fails (normally <1 s; not an atomic network boundary).
|
|
13
|
+
// - Every new build is checked in a throwaway serve before browser admission. An unverified build never starts
|
|
14
|
+
// while a native context is held: MoreLogin port protection has a 0.0.0.0 bypass, including WebSockets.
|
|
15
|
+
// Only a completed pre-flight (process and listener confirmed gone) admits later launches while attached.
|
|
16
|
+
// A new native attachment still waits for every actual serve's process-bound probe, including startup races.
|
|
17
|
+
// - A serve that fails its check is stopped: SIGTERM, then SIGKILL after a bounded wait, until the OS confirms its
|
|
18
|
+
// process and its listener are gone. Until then (and for good when that cannot be confirmed) every native
|
|
19
|
+
// attachment is refused, and contexts already attached are revoked (one page emptied to about:blank, every other
|
|
20
|
+
// page closed, the browser disconnected: the profile's window is kept, revokeNativeContext). A failure that is only
|
|
21
|
+
// a missing answer (a timeout) stops the serve when a native context is held; otherwise it blocks native
|
|
22
|
+
// attachment and is asked again.
|
|
23
|
+
// - Serves SynaBun did not start (a terminal, another app, an earlier SynaBun), on any port: found by the processes
|
|
24
|
+
// listening on TCP (lib/opencode-serve-scan.js) whenever a context is attached and every NATIVE_WATCH_MS while one
|
|
25
|
+
// is. SynaBun holds no password for them, so the probe asks them as `foreign`: loopback only, every route of the
|
|
26
|
+
// fixed matrix refused without credentials and with wrong ones (HTTP and WebSocket), the password asked before the
|
|
27
|
+
// router, and no guessable password accepted. That is accepted: the serve then answers a page nothing but 401 /
|
|
28
|
+
// 403, and SynaBun has no better evidence about a password it does not hold. A foreign serve that fails is never
|
|
29
|
+
// stopped; the browser is refused (attached contexts revoked) with its pid, port and path and the way to fix it.
|
|
30
|
+
// When the listeners cannot be listed or a listener cannot be identified, the browser is refused.
|
|
31
|
+
// NATIVE_SERVE_KNOWN_GOOD are the versions whose authentication was inspected by hand (2.1.4; 2.2.5, Homebrew
|
|
32
|
+
// anomalyco/tap/opencode-v2, 2026-11-01). They are probed like every other version: known-good only means "expected to
|
|
33
|
+
// pass", shown in Settings. Started from a Settings command line (its binary is unknown) or with a password that is
|
|
34
|
+
// not private to stdout is never admitted. There is no setting or variable that skips any of this.
|
|
35
|
+
import { mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
|
|
36
|
+
import { execFile } from 'node:child_process';
|
|
37
|
+
import { dirname } from 'node:path';
|
|
38
|
+
import { binaryIdentity, binaryKey, probeOpencodeServe } from './opencode-serve-probe.js';
|
|
39
|
+
import { isOpencodePath, listenerGenerationKey, scanOpencodeServes } from './opencode-serve-scan.js';
|
|
40
|
+
import { listListenAddressesAsync, listPortListenersAsync, pidExists, readProcessExecutableAsync, readProcessIdentityAsync } from './process-identity.js';
|
|
12
41
|
|
|
42
|
+
export const NATIVE_SERVE_KNOWN_GOOD = Object.freeze(['2.1.4', '2.2.5']);
|
|
43
|
+
// The name older callers import: the versions checked by hand.
|
|
44
|
+
export const NATIVE_SERVE_VERSIONS = NATIVE_SERVE_KNOWN_GOOD;
|
|
45
|
+
export const NATIVE_SERVE_MIN_VERSION = '2.1.0';
|
|
46
|
+
// How often the OpenCode serves of this computer are looked at again while a native context is attached.
|
|
47
|
+
export const NATIVE_WATCH_MS = 15_000;
|
|
48
|
+
// How long a watch pass waits for a foreign serve that failed only by not answering to be confirmed gone (ensureWatch).
|
|
49
|
+
export const NATIVE_EXIT_GRACE_MS = 3_000;
|
|
50
|
+
|
|
51
|
+
/** "2.3.0", "v2.3.0", "opencode v2.3.0" → "2.3.0"; null for anything else (a prerelease, four parts, extra words). */
|
|
52
|
+
export function nativeServeVersionOf(version) {
|
|
53
|
+
const bare = String(version ?? '').trim().replace(/^opencode\s+/i, '').replace(/^v(?=\d)/i, '');
|
|
54
|
+
const m = /^(\d{1,4})\.(\d{1,4})\.(\d{1,6})$/.exec(bare);
|
|
55
|
+
return m ? { text: bare, major: Number(m[1]), minor: Number(m[2]), patch: Number(m[3]) } : null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const MIN = nativeServeVersionOf(NATIVE_SERVE_MIN_VERSION);
|
|
59
|
+
const atLeastMinimum = (v) => v.major !== MIN.major ? v.major > MIN.major : v.minor !== MIN.minor ? v.minor > MIN.minor : v.patch >= MIN.patch;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* What the version alone says, before any probe: `{ ok, version, knownGood, reason }`, `reason` 'version-unreadable'
|
|
63
|
+
* or 'version-old' when `ok` is false.
|
|
64
|
+
*/
|
|
65
|
+
export function nativeServeVersionPolicy(version) {
|
|
66
|
+
const v = nativeServeVersionOf(version);
|
|
67
|
+
if (!v) return { ok: false, version: version ? String(version).trim() : null, knownGood: false, reason: 'version-unreadable' };
|
|
68
|
+
if (!atLeastMinimum(v)) return { ok: false, version: v.text, knownGood: false, reason: 'version-old' };
|
|
69
|
+
return { ok: true, version: v.text, knownGood: NATIVE_SERVE_KNOWN_GOOD.includes(v.text), reason: null };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** May a serve of this launch be admitted once its probe passes? No Settings command line, stdout password, version policy. */
|
|
13
73
|
export function nativeServeCapability({ version, commandLine = false, passwordFrom } = {}) {
|
|
14
|
-
|
|
15
|
-
return !commandLine && passwordFrom === 'stdout' && NATIVE_SERVE_VERSIONS.includes(bare);
|
|
74
|
+
return !commandLine && passwordFrom === 'stdout' && nativeServeVersionPolicy(version).ok;
|
|
16
75
|
}
|
|
17
76
|
|
|
18
|
-
// Why a serve
|
|
77
|
+
// Why a serve cannot be admitted at all (no probe would change it), in words that name what to change; null when the
|
|
78
|
+
// probe decides.
|
|
19
79
|
export function nativeServeReason({ version, commandLine = false, passwordFrom } = {}) {
|
|
20
80
|
if (commandLine) return 'command-line';
|
|
21
81
|
if (passwordFrom !== 'stdout') return 'password';
|
|
22
|
-
return
|
|
82
|
+
return nativeServeVersionPolicy(version).reason;
|
|
23
83
|
}
|
|
24
84
|
|
|
25
|
-
const BASE = `Native browser WebSockets require authenticated OpenCode ${
|
|
85
|
+
const BASE = `Native browser WebSockets require authenticated OpenCode serves: OpenCode ${NATIVE_SERVE_MIN_VERSION} or newer, started by SynaBun with its private stdout password, that pass SynaBun's runtime check (listening on loopback only, refusing every sensitive /api request and WebSocket upgrade without the password, accepting SynaBun's), and no other OpenCode serve on this computer that answers without its password; wait for startup, or act on the serve named below.`;
|
|
26
86
|
|
|
27
87
|
const MAX_COMMAND = 200;
|
|
28
88
|
const short = (text, max = MAX_COMMAND) => {
|
|
@@ -32,26 +92,49 @@ const short = (text, max = MAX_COMMAND) => {
|
|
|
32
92
|
const pidOf = (o) => (Number.isInteger(o?.pid) && o.pid > 0 ? o.pid : null);
|
|
33
93
|
|
|
34
94
|
// The fields of an offender a caller may see (a route's answer, a dispatch error): what names the serve, never its
|
|
35
|
-
// token or the rest of its record. A command line is shortened.
|
|
95
|
+
// token, its password or the rest of its record. A command line is shortened.
|
|
36
96
|
export function narrowOffenders(offenders = []) {
|
|
37
97
|
return (Array.isArray(offenders) ? offenders : []).map((o) => {
|
|
38
98
|
const out = { reason: String(o?.reason || 'unknown'), pid: pidOf(o), port: Number(o?.port) > 0 ? Number(o.port) : null };
|
|
39
99
|
if (o?.path) out.path = short(o.path, 400);
|
|
40
100
|
if (o?.command) out.command = short(o.command, 400);
|
|
41
101
|
if (o?.version) out.version = String(o.version).trim();
|
|
102
|
+
if (o?.check) out.check = String(o.check);
|
|
103
|
+
if (o?.detail) out.detail = short(o.detail, 400);
|
|
104
|
+
if (o?.state) out.state = String(o.state);
|
|
42
105
|
if (o?.reason === 'record') { out.kind = o.kind || null; out.claimable = !!o.claimable; }
|
|
43
106
|
return out;
|
|
44
107
|
});
|
|
45
108
|
}
|
|
46
109
|
|
|
110
|
+
// What a person can do about a serve SynaBun started that is not admitted.
|
|
111
|
+
function remedy(o, { report = false } = {}) {
|
|
112
|
+
const pid = pidOf(o);
|
|
113
|
+
const steps = [`stop this serve (close the OpenCode panel${pid ? ` / end pid ${pid}` : ''})`, 'choose another OpenCode under Settings → Executable paths'];
|
|
114
|
+
if (report) steps.push(`or report the incompatibility (OpenCode ${o.version ? String(o.version).trim() : 'of unknown version'}, failed check "${o.check || 'unknown'}")`);
|
|
115
|
+
return `${steps.join(', ')}. Settings → Executable paths → Verify OpenCode checks again`;
|
|
116
|
+
}
|
|
117
|
+
|
|
47
118
|
function describeOffender(o) {
|
|
48
119
|
const pid = pidOf(o);
|
|
49
120
|
const where = [pid ? `pid ${pid}` : null, o.port ? `port ${o.port}` : null].filter(Boolean).join(', ');
|
|
50
121
|
const what = [o.path || null, o.command ? `command ${short(o.command)}` : null, o.version ? `version ${String(o.version).trim()}` : null].filter(Boolean).join(', ');
|
|
51
122
|
const head = `OpenCode serve ${where || '(unknown process)'}${what ? ` (${what})` : ''}`;
|
|
52
123
|
switch (o.reason) {
|
|
53
|
-
case '
|
|
54
|
-
case '
|
|
124
|
+
case 'probe': return `${head}: failed SynaBun's runtime authentication check "${o.check || 'unknown'}": ${o.detail || 'not verified'}. Fix: ${remedy(o, { report: true })}`;
|
|
125
|
+
case 'verifying': return `${head}: its authentication is being checked; try again in a moment`;
|
|
126
|
+
case 'build-checking': return `${head}: automatic build pre-flight is running; native browser admission waits until its throwaway listener is confirmed gone`;
|
|
127
|
+
case 'exposure': return o.state === 'stuck'
|
|
128
|
+
? `${head}: failed SynaBun's runtime authentication check "${o.check || 'unknown'}" and SynaBun could not confirm that it stopped (its process or its listener is still there, or the OS could not say). Fix: end ${pid ? `pid ${pid}` : 'that serve'} (kill -9 ${pid || '<pid>'}), check that nothing listens on port ${o.port} (lsof -nP -iTCP:${o.port} -sTCP:LISTEN), then try again`
|
|
129
|
+
: `${head}: failed SynaBun's runtime authentication check "${o.check || 'unknown'}" (${o.detail || 'not verified'}) and is being stopped; the native browser waits until its listener is gone`;
|
|
130
|
+
case 'foreign': return `${head}: not started by SynaBun, and failed SynaBun's runtime authentication check "${o.check || 'unknown'}": ${o.detail || 'not verified'}. SynaBun never stops a serve it did not start. Fix: stop it yourself${pid ? ` (kill ${pid})` : ''}, update to OpenCode ${NATIVE_SERVE_MIN_VERSION} or newer (opencode upgrade), or choose another executable under Settings → Executable paths. Start it on 127.0.0.1 with both OPENCODE_PASSWORD and OPENCODE_SERVER_PASSWORD unset so it generates a private password. If the check still fails, report the incompatibility and this failed check`;
|
|
131
|
+
case 'foreign-checking': return `${head}: an OpenCode serve SynaBun did not start is being checked; try again in a moment`;
|
|
132
|
+
case 'foreign-scan': return `SynaBun could not tell which OpenCode serves run on this computer: ${o.detail || 'the listening processes could not be read'}. Fix: check that lsof works (lsof -nP -iTCP -sTCP:LISTEN), then try again`;
|
|
133
|
+
case 'unverified-build': return `${head}: this build has not completed automatic pre-flight verification. A native browser is attached, so the unverified build is not started. Verification runs before browser admission or after attached contexts finish; MoreLogin port protection alone cannot isolate it (0.0.0.0 bypass). ${o.detail || ''}`;
|
|
134
|
+
case 'version-old': return `${head}: OpenCode older than ${NATIVE_SERVE_MIN_VERSION} was never checked by SynaBun. Fix: update OpenCode (opencode upgrade), or ${remedy(o)}`;
|
|
135
|
+
case 'version-unreadable': return `${head}: its version cannot be read as MAJOR.MINOR.PATCH, so SynaBun does not admit it. Fix: ${remedy(o)}`;
|
|
136
|
+
case 'version': return `${head}: this OpenCode version is not one SynaBun admits (${NATIVE_SERVE_MIN_VERSION} or newer that passes the runtime check). Fix: ${remedy(o)}`;
|
|
137
|
+
case 'command-line': return `${head}: started from the OpenCode command line set in Settings (its version cannot be read, nor its binary checked); clear it so SynaBun starts the executable it checks, or stop this serve`;
|
|
55
138
|
case 'password': return `${head}: started without a private stdout password`;
|
|
56
139
|
case 'starting': return `${head}: still starting; try again once OpenCode answers`;
|
|
57
140
|
case 'untracked-port': return `${head}: answers on a port SynaBun did not start in this run; stop the process listening on port ${o.port}`;
|
|
@@ -77,22 +160,523 @@ export function nativeServeError(offenders = []) {
|
|
|
77
160
|
const nativeContextClosed = () => Object.assign(new Error('The browser closed while SynaBun was checking its OpenCode serves; nothing was attached.'), { code: 'NATIVE_CONTEXT_CLOSED' });
|
|
78
161
|
const nativeAttachAborted = () => Object.assign(new Error('The browser request ended while SynaBun was checking its OpenCode serves; nothing was attached.'), { code: 'NATIVE_ATTACH_ABORTED' });
|
|
79
162
|
const defaultSleep = (ms) => new Promise((done) => { const t = setTimeout(done, ms); t.unref?.(); });
|
|
163
|
+
// `work`, or null once `ms` passed (never rejects).
|
|
164
|
+
const within = (work, ms) => {
|
|
165
|
+
if (!(ms > 0)) return Promise.resolve(null);
|
|
166
|
+
let timer;
|
|
167
|
+
const late = new Promise((resolve) => { timer = setTimeout(() => resolve(null), Math.min(ms, 2_147_000_000)); timer.unref?.(); });
|
|
168
|
+
return Promise.race([Promise.resolve(work).catch(() => null), late]).finally(() => clearTimeout(timer));
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Verdicts about builds (a binary and its version, binaryKey): what Settings says about the OpenCode SynaBun would
|
|
173
|
+
* start. In memory; `createVerdictFile` keeps them across restarts. Only a definitive answer is kept (never a
|
|
174
|
+
* timeout); `get` answers `{ ok, failed, detail, version, at }` or null. A persisted diagnostic verdict never grants admission:
|
|
175
|
+
* each serve is checked itself.
|
|
176
|
+
*/
|
|
177
|
+
export function createVerdictMemory({ max = 50 } = {}) {
|
|
178
|
+
const map = new Map();
|
|
179
|
+
return {
|
|
180
|
+
get: (key) => (key && map.get(key)) || null,
|
|
181
|
+
set(key, verdict) {
|
|
182
|
+
if (!key) return;
|
|
183
|
+
map.delete(key);
|
|
184
|
+
map.set(key, { ok: !!verdict.ok, failed: verdict.failed || null, detail: verdict.detail || null, version: verdict.version || null, at: Number(verdict.at) || Date.now() });
|
|
185
|
+
while (map.size > max) map.delete(map.keys().next().value);
|
|
186
|
+
},
|
|
187
|
+
delete: (key) => { map.delete(key); },
|
|
188
|
+
entries: () => [...map.entries()],
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* createVerdictMemory kept in a JSON file (`DATA_HOME/data/opencode-serve-verdicts.json`): read once, written whole
|
|
194
|
+
* through a rename after each change. A file that cannot be read starts empty; a write that fails keeps the memory.
|
|
195
|
+
* It holds binary keys and verdict sentences, never a password.
|
|
196
|
+
*/
|
|
197
|
+
export function createVerdictFile({ file, max = 50, read = readFileSync, write = writeFileSync, rename = renameSync, mkdir = mkdirSync } = {}) {
|
|
198
|
+
// `file` may be a function: the path is asked (and the file read) on first use, so a module can build its boundary
|
|
199
|
+
// before it knows its data folder.
|
|
200
|
+
let memory = null;
|
|
201
|
+
let path = null;
|
|
202
|
+
const load = () => {
|
|
203
|
+
if (memory) return memory;
|
|
204
|
+
memory = createVerdictMemory({ max });
|
|
205
|
+
try { path = typeof file === 'function' ? file() : file; } catch { path = null; }
|
|
206
|
+
if (!path) return memory;
|
|
207
|
+
try {
|
|
208
|
+
const saved = JSON.parse(read(path, 'utf8'));
|
|
209
|
+
for (const [key, verdict] of Array.isArray(saved?.verdicts) ? saved.verdicts : []) {
|
|
210
|
+
if (typeof key === 'string' && verdict && typeof verdict === 'object') memory.set(key, verdict);
|
|
211
|
+
}
|
|
212
|
+
} catch { /* nothing kept yet */ }
|
|
213
|
+
return memory;
|
|
214
|
+
};
|
|
215
|
+
const save = () => {
|
|
216
|
+
if (!path) return;
|
|
217
|
+
try {
|
|
218
|
+
mkdir(dirname(path), { recursive: true });
|
|
219
|
+
const tmp = `${path}.${process.pid}.tmp`;
|
|
220
|
+
write(tmp, `${JSON.stringify({ version: 1, verdicts: memory.entries() }, null, 2)}\n`, { mode: 0o600 });
|
|
221
|
+
rename(tmp, path);
|
|
222
|
+
} catch { /* kept in memory for this run */ }
|
|
223
|
+
};
|
|
224
|
+
return {
|
|
225
|
+
get: (key) => load().get(key),
|
|
226
|
+
entries: () => load().entries(),
|
|
227
|
+
set(key, verdict) { if (!key) return; load().set(key, verdict); save(); },
|
|
228
|
+
delete(key) { if (!key || !load().get(key)) return; memory.delete(key); save(); },
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Which process listens, at one moment: `{ pid, startedAt, executable, addresses, key }` (`key`
|
|
234
|
+
* listenerGenerationKey: pid, start time, sockets), or null when the OS could not say (fail closed: such a serve is
|
|
235
|
+
* not verified).
|
|
236
|
+
*/
|
|
237
|
+
export async function readServeGeneration(pid, { identity = readProcessIdentityAsync, executable = readProcessExecutableAsync, addresses = listListenAddressesAsync } = {}) {
|
|
238
|
+
if (!(Number.isInteger(pid) && pid > 0)) return null;
|
|
239
|
+
const [id, exe, socks] = await Promise.all([
|
|
240
|
+
Promise.resolve().then(() => identity(pid)).catch(() => null),
|
|
241
|
+
Promise.resolve().then(() => executable(pid)).catch(() => null),
|
|
242
|
+
Promise.resolve().then(() => addresses(pid)).catch(() => null),
|
|
243
|
+
]);
|
|
244
|
+
if (!id?.startedAt || !Array.isArray(socks)) return null;
|
|
245
|
+
return { pid, startedAt: id.startedAt, executable: exe || null, addresses: socks, key: listenerGenerationKey({ pid, startedAt: id.startedAt, addresses: socks }) };
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// Contexts this process revoked: context → { at, why }. server.js reads it when the context's close event comes, so a
|
|
249
|
+
// revocation is never reported as a profile "closed outside SynaBun" and never blocks the runs that worked there.
|
|
250
|
+
const _revoked = new WeakMap();
|
|
251
|
+
|
|
252
|
+
/** When and why SynaBun revoked `context` ({ at, why }), or null. */
|
|
253
|
+
export function nativeContextRevocation(context) {
|
|
254
|
+
if (!context || (typeof context !== 'object' && typeof context !== 'function')) return null;
|
|
255
|
+
return _revoked.get(context) || null;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Take a native context's pages away from a serve that failed: no page of it runs a site's script any more, then the
|
|
260
|
+
* browser connection is closed, so SynaBun's session must attach again (through the boundary). Bounded; never throws.
|
|
261
|
+
*
|
|
262
|
+
* The browser's window is kept (2026-11-15). Before, every page was closed: closing the last tab of a MoreLogin
|
|
263
|
+
* profile closes its window, MoreLogin then closes the whole profile (envkit log: close_click + CloseBrowser), and the
|
|
264
|
+
* runs' next browser call started it again, which spends one of the plan's daily launches. On 2026-11-15 at 21:13:30
|
|
265
|
+
* one revocation (a foreign OpenCode serve, pid 21487, failed "http-anonymous" while it was exiting) closed P-1 and P-4
|
|
266
|
+
* 37 ms apart, and one at 21:14:22 (pid 54472, exiting too) closed P-1 again. Now one page is emptied
|
|
267
|
+
* (about:blank: the page that was there runs no more script) and every other page is closed; only when the emptying
|
|
268
|
+
* fails is that page closed too (the window may then go: the boundary's protection comes first).
|
|
269
|
+
*/
|
|
270
|
+
export async function revokeNativeContext(context, { timeoutMs = 5_000, why = null, stepMs = 2_000 } = {}) {
|
|
271
|
+
try { if (context && typeof context === 'object') _revoked.set(context, { at: Date.now(), why: why ? String(why).slice(0, 500) : null }); } catch { /* not markable */ }
|
|
272
|
+
const work = (async () => {
|
|
273
|
+
let pages = [];
|
|
274
|
+
try { pages = (context?.pages?.() || []).filter((page) => !page?.isClosed?.()); } catch { pages = []; }
|
|
275
|
+
const [keep, ...rest] = pages;
|
|
276
|
+
const close = (page) => Promise.resolve().then(() => page.close({ runBeforeUnload: false })).catch(() => {});
|
|
277
|
+
// The kept page: emptied within `stepMs`, else (an error, no answer) closed after all.
|
|
278
|
+
const empty = async (page) => {
|
|
279
|
+
let timer;
|
|
280
|
+
const late = new Promise((resolve) => { timer = setTimeout(() => resolve('late'), stepMs); timer.unref?.(); });
|
|
281
|
+
const done = await Promise.race([Promise.resolve().then(() => page.goto('about:blank')).then(() => 'empty', () => 'failed'), late])
|
|
282
|
+
.finally(() => clearTimeout(timer));
|
|
283
|
+
if (done !== 'empty') await close(page);
|
|
284
|
+
};
|
|
285
|
+
await Promise.all([...rest.map(close), keep ? empty(keep) : null]);
|
|
286
|
+
try { await context?.browser?.()?.close?.(); } catch { /* already gone */ }
|
|
287
|
+
})();
|
|
288
|
+
await within(work, timeoutMs);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
const sameIdentity = (a, b) => (!a && !b) || (!!a && !!b && a.realpath === b.realpath && a.size === b.size && a.mtimeMs === b.mtimeMs && a.ino === b.ino && a.dev === b.dev);
|
|
292
|
+
// No shell, no server launch and bounded output/time. A foreign listener's version is not public over HTTP when
|
|
293
|
+
// its authentication works; ask the executable the OS identified instead. Interpreters cannot identify the script
|
|
294
|
+
// they run this way, so those foreign serves fail closed rather than treating `node --version` as OpenCode.
|
|
295
|
+
export function readOpencodeBinaryVersion(identity, { run = execFile } = {}) {
|
|
296
|
+
if (!identity?.native || !isOpencodePath(identity.realpath)) return Promise.resolve(null);
|
|
297
|
+
return new Promise((resolve) => {
|
|
298
|
+
try {
|
|
299
|
+
run(identity.realpath, ['--version'], { timeout: 2000, maxBuffer: 16_384, windowsHide: true },
|
|
300
|
+
(error, stdout) => resolve(error ? null : nativeServeVersionOf(stdout)?.text || null));
|
|
301
|
+
} catch { resolve(null); }
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
const INTERPRETER = /^(?:node|nodejs|bun|deno)(?:\.exe)?$/i;
|
|
305
|
+
const exited = (proc) => !proc || proc.exitCode != null || proc.signalCode != null;
|
|
80
306
|
|
|
81
|
-
|
|
307
|
+
/**
|
|
308
|
+
* The boundary. `probe` asks a serve (lib/opencode-serve-probe.js probeOpencodeServe), `identify` reads the binary a
|
|
309
|
+
* serve was started from (binaryIdentity), `verdicts` keeps what is known about builds, `scan` lists the OpenCode
|
|
310
|
+
* serves of this computer (lib/opencode-serve-scan.js), `readGeneration` which process listens (readServeGeneration),
|
|
311
|
+
* `portListeners` / `pidAlive` / `signalPid` confirm and enforce a stop, `revoke` takes an attached context away.
|
|
312
|
+
*/
|
|
313
|
+
export function createNativeServeBoundary({ probe = probeOpencodeServe, identify = binaryIdentity, readVersion = readOpencodeBinaryVersion, verdicts = createVerdictMemory(),
|
|
314
|
+
scan = scanOpencodeServes, readGeneration = readServeGeneration, portListeners = listPortListenersAsync, pidAlive = pidExists,
|
|
315
|
+
signalPid = (pid, signal) => process.kill(pid, signal), revoke = revokeNativeContext, platform = process.platform,
|
|
316
|
+
now = Date.now, retryMs = 5_000, termMs = 3_000, killMs = 3_000, gonePollMs = 100, refreshMs = 8_000, foreignTtlMs = 5 * 60_000,
|
|
317
|
+
watchMs = NATIVE_WATCH_MS, exitGraceMs = NATIVE_EXIT_GRACE_MS, exitPollMs = 250, preflight = null, log = () => {} } = {}) {
|
|
82
318
|
const processes = new Map();
|
|
319
|
+
// Process-local admission evidence: persisted diagnostic verdicts and ordinary runtime passes cannot grant it.
|
|
320
|
+
const builds = new Map(), buildChecks = new Map();
|
|
321
|
+
let verificationEpoch = 0;
|
|
83
322
|
// Every native context that relies on the boundary, attached or still being checked (a reservation): while any is
|
|
84
|
-
// held, assertLaunch
|
|
85
|
-
//
|
|
323
|
+
// held, assertLaunch admits only builds that completed a throwaway pre-flight. A context is held from before its check until it closes, its browser
|
|
324
|
+
// disconnects, its attachment fails or it is revoked. `attached`: its check passed (its pages are SynaBun's to use).
|
|
86
325
|
const contexts = new Map();
|
|
87
|
-
|
|
326
|
+
// Serves that failed and are being stopped ('removing') or whose stop could not be confirmed ('stuck'): each blocks
|
|
327
|
+
// every native attachment until the OS confirms its process and its listener are gone.
|
|
328
|
+
const exposures = new Map();
|
|
329
|
+
// Serves SynaBun did not start: the last look (`result`), the look under way, and a verdict per listening process.
|
|
330
|
+
const foreign = { result: null, scanning: null, verdicts: new Map() };
|
|
331
|
+
let watchTimer = null;
|
|
332
|
+
|
|
333
|
+
const attachedContexts = () => [...contexts.entries()].filter(([, rec]) => rec.attached);
|
|
334
|
+
const ownPids = () => {
|
|
335
|
+
const pids = new Set();
|
|
336
|
+
for (const [proc, e] of processes) { if (proc.pid) pids.add(proc.pid); if (e.pid) pids.add(e.pid); }
|
|
337
|
+
for (const x of exposures.values()) { if (x.pid) pids.add(x.pid); if (x.procPid) pids.add(x.procPid); }
|
|
338
|
+
return pids;
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
// Every attached context is taken away (pages closed, connection closed); it stays held until that is done, so
|
|
342
|
+
// nothing starts meanwhile. A context still being checked is refused by its own attach.
|
|
343
|
+
function revokeAll(why) {
|
|
344
|
+
for (const [context, rec] of attachedContexts()) {
|
|
345
|
+
if (rec.revoking) continue;
|
|
346
|
+
rec.revoking = true;
|
|
347
|
+
log(`revoking a native browser context: ${why}`);
|
|
348
|
+
Promise.resolve().then(() => revoke(context, { why })).catch(() => {}).finally(() => rec.release());
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// Is the stopped serve gone: its process ended, the pid that listened ended, and the OS lists neither on its port?
|
|
353
|
+
async function gone(x) {
|
|
354
|
+
if (!exited(x.proc)) return false;
|
|
355
|
+
// The pid that listened, when it is not the spawned process: still there (or the OS cannot tell) is not gone.
|
|
356
|
+
if (x.pid && x.pid !== x.procPid && pidAlive(x.pid) !== false) return false;
|
|
357
|
+
let pids;
|
|
358
|
+
try { pids = await portListeners(x.port); } catch { pids = null; }
|
|
359
|
+
if (!Array.isArray(pids)) return false;
|
|
360
|
+
return !pids.includes(x.pid) && !pids.includes(x.procPid);
|
|
361
|
+
}
|
|
362
|
+
async function waitGone(x, ms) {
|
|
363
|
+
const end = now() + ms;
|
|
364
|
+
for (;;) {
|
|
365
|
+
if (await gone(x)) return true;
|
|
366
|
+
if (now() >= end) return false;
|
|
367
|
+
await defaultSleep(Math.max(1, Math.min(gonePollMs, end - now())));
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// Stop a serve that failed: SIGTERM, then SIGKILL (to the process SynaBun spawned and to the pid that listens, when
|
|
372
|
+
// that is its own), each followed by a bounded wait for the OS to confirm the process and the listener are gone.
|
|
373
|
+
function terminate(proc, entry, verdict) {
|
|
374
|
+
const id = `${entry.port}|${entry.pid || proc.pid || '?'}`;
|
|
375
|
+
const known = exposures.get(id);
|
|
376
|
+
if (known) return known.done;
|
|
377
|
+
const x = { id, proc, port: entry.port, pid: entry.pid || proc.pid || null, procPid: proc.pid || null, path: entry.path || null, version: entry.version || null,
|
|
378
|
+
check: verdict.failed, detail: verdict.detail, state: 'removing', since: now(), done: null };
|
|
379
|
+
exposures.set(id, x);
|
|
380
|
+
const send = (signal) => {
|
|
381
|
+
try { entry.kill(signal); } catch { /* the wait below tells */ }
|
|
382
|
+
if (entry.pidOwned && x.pid && x.pid !== x.procPid) { try { signalPid(x.pid, signal); } catch { /* gone, or not ours to signal */ } }
|
|
383
|
+
};
|
|
384
|
+
x.done = (async () => {
|
|
385
|
+
send('SIGTERM');
|
|
386
|
+
if (await waitGone(x, termMs)) { exposures.delete(id); log(`OpenCode serve pid ${x.pid} port ${x.port} stopped (${x.check === 'preflight-cleanup' ? 'build pre-flight finished' : `it failed the runtime check "${x.check}"`})`); return true; }
|
|
387
|
+
log(`OpenCode serve pid ${x.pid} port ${x.port} still runs ${Math.round(termMs / 1000)} s after SIGTERM: SIGKILL`);
|
|
388
|
+
send('SIGKILL');
|
|
389
|
+
if (await waitGone(x, killMs)) { exposures.delete(id); log(`OpenCode serve pid ${x.pid} port ${x.port} stopped by SIGKILL`); return true; }
|
|
390
|
+
x.state = 'stuck';
|
|
391
|
+
log(`OpenCode serve pid ${x.pid} port ${x.port} failed its runtime check and could not be confirmed stopped: native browsers stay refused`);
|
|
392
|
+
return false;
|
|
393
|
+
})();
|
|
394
|
+
return x.done;
|
|
395
|
+
}
|
|
396
|
+
// A stop that could not be confirmed is looked at again (never signalled again: the pid may be another process now).
|
|
397
|
+
async function recheckStuck(x) {
|
|
398
|
+
if (x.state !== 'stuck' || x.rechecking) return;
|
|
399
|
+
x.rechecking = true;
|
|
400
|
+
try { if (await gone(x)) { exposures.delete(x.id); log(`OpenCode serve pid ${x.pid} port ${x.port} is gone now`); } } finally { x.rechecking = false; }
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
function onFailure(proc, entry, verdict) {
|
|
404
|
+
const held = contexts.size > 0;
|
|
405
|
+
builds.delete(entry.launchKey);
|
|
406
|
+
verificationEpoch++;
|
|
407
|
+
log(`OpenCode serve pid ${entry.pid || proc.pid || '?'} port ${entry.port} (version ${entry.version || '?'}) failed the runtime check "${verdict.failed}": ${verdict.detail}`);
|
|
408
|
+
// A definitive failure is a serve SynaBun cannot vouch for: stopped. A missing answer stops it only while a
|
|
409
|
+
// native context relies on the boundary (otherwise it blocks attachment and is asked again).
|
|
410
|
+
if (!verdict.transient || held) terminate(proc, entry, verdict);
|
|
411
|
+
if (held) revokeAll(`OpenCode serve pid ${entry.pid || proc.pid || '?'} port ${entry.port} failed "${verdict.failed}"`);
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
// Is the process that listens the one SynaBun started? Its executable as the OS maps it: the very file pinned at
|
|
415
|
+
// launch when that file is a native executable (macOS / Linux, where SynaBun execs its real path); an OpenCode
|
|
416
|
+
// path or a script interpreter when the launcher is a script (npm's shim starts the platform binary); on Windows
|
|
417
|
+
// the launcher is the resolver's spec, so the executable is only required to be readable.
|
|
418
|
+
function processCheck(entry, before, after) {
|
|
419
|
+
const pid = entry.pid;
|
|
420
|
+
if (!before || !after) return { id: 'process', ok: false, transient: true, detail: `pid ${pid || '?'}: its start time or its sockets could not be read` };
|
|
421
|
+
if (before.key !== after.key) return { id: 'process', ok: false, transient: true, detail: `pid ${pid}: the process or its sockets changed while it was checked` };
|
|
422
|
+
const exe = after.executable;
|
|
423
|
+
if (!exe) return { id: 'process', ok: false, transient: true, detail: `pid ${pid}: the executable it runs could not be read` };
|
|
424
|
+
if (platform !== 'win32') {
|
|
425
|
+
const pinned = entry.identity?.native ? entry.identity.realpath : null;
|
|
426
|
+
if (pinned && exe !== pinned) return { id: 'process', ok: false, detail: `pid ${pid} runs ${exe}, not the OpenCode SynaBun started (${pinned})` };
|
|
427
|
+
if (!pinned && !isOpencodePath(exe) && !INTERPRETER.test(exe.split(/[\\/]/).pop() || '')) return { id: 'process', ok: false, detail: `pid ${pid} runs ${exe}, which is not OpenCode` };
|
|
428
|
+
}
|
|
429
|
+
return { id: 'process', ok: true, detail: `pid ${pid} (started ${after.startedAt}) runs ${exe}` };
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
// Probe one tracked serve (one probe at a time per serve), bound to the process and sockets read before and after.
|
|
433
|
+
function startProbe(proc, entry) {
|
|
434
|
+
if (entry.probing) return entry.probing;
|
|
435
|
+
const run = (async () => {
|
|
436
|
+
const before = await Promise.resolve().then(() => readGeneration(entry.pid)).catch(() => null);
|
|
437
|
+
let result;
|
|
438
|
+
try { result = await probe({ port: entry.port, pid: entry.pid, password: entry.password }); }
|
|
439
|
+
catch (error) { result = { ok: false, failed: 'loopback', transient: true, detail: `the probe failed: ${String(error?.message || error)}`, checks: [] }; }
|
|
440
|
+
if (!result || typeof result !== 'object') result = { ok: false, failed: 'loopback', transient: true, detail: 'the probe gave no answer', checks: [] };
|
|
441
|
+
const after = await Promise.resolve().then(() => readGeneration(entry.pid)).catch(() => null);
|
|
442
|
+
// What the serve says it is (GET /api/info with its password) is the version that counts, and it is checked
|
|
443
|
+
// against the policy every time, never only when it changed.
|
|
444
|
+
const reported = result.version != null ? String(result.version).trim() : null;
|
|
445
|
+
const policy = nativeServeVersionPolicy(reported);
|
|
446
|
+
if (reported) {
|
|
447
|
+
entry.version = policy.version || reported;
|
|
448
|
+
entry.knownGood = policy.knownGood;
|
|
449
|
+
entry.launchKey = binaryKey(entry.identity, entry.version);
|
|
450
|
+
}
|
|
451
|
+
const extra = [processCheck(entry, before, after),
|
|
452
|
+
policy.ok ? { id: 'version', ok: true, detail: `OpenCode ${policy.version}` }
|
|
453
|
+
: { id: 'version', ok: false, detail: reported ? `the serve reports OpenCode ${reported}, which SynaBun does not admit (${NATIVE_SERVE_MIN_VERSION} or newer, MAJOR.MINOR.PATCH)` : 'the serve did not report its version with SynaBun\'s password' }];
|
|
454
|
+
const firstExtra = extra.find((c) => !c.ok) || null;
|
|
455
|
+
const ok = !!result.ok && !firstExtra;
|
|
456
|
+
const failed = !result.ok ? (result.failed || 'unknown') : firstExtra ? firstExtra.id : null;
|
|
457
|
+
const verdict = {
|
|
458
|
+
ok, failed,
|
|
459
|
+
detail: ok ? (result.detail || 'every check passed') : !result.ok ? (result.detail || null) : firstExtra.detail,
|
|
460
|
+
transient: !ok && (!result.ok ? !!result.transient : !!firstExtra.transient),
|
|
461
|
+
exposed: !ok && !!result.exposed,
|
|
462
|
+
checks: [...(Array.isArray(result.checks) ? result.checks : []), ...extra.map(({ id, ok: pass, detail }) => ({ id, ok: pass, detail }))],
|
|
463
|
+
at: now(), version: entry.version || null, generation: after, matrix: result.matrix || null,
|
|
464
|
+
};
|
|
465
|
+
if (processes.get(proc) !== entry) return verdict;
|
|
466
|
+
entry.verdict = verdict;
|
|
467
|
+
if (!verdict.transient) verdicts.set(entry.launchKey, verdict);
|
|
468
|
+
if (!verdict.ok) onFailure(proc, entry, verdict);
|
|
469
|
+
return verdict;
|
|
470
|
+
})().finally(() => { entry.probing = null; });
|
|
471
|
+
entry.probing = run;
|
|
472
|
+
return run;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
// Where a tracked serve stands now: 'refused' (never admissible), 'starting', 'verifying', 'verified' or 'failed'.
|
|
476
|
+
// A ready serve without a verdict, one whose binary changed since its verdict, or one whose last probe got no answer
|
|
477
|
+
// a while ago is probed (again) here.
|
|
478
|
+
function stateOf(proc, e) {
|
|
479
|
+
if (!e.safe) return 'refused';
|
|
480
|
+
if (!e.ready) return 'starting';
|
|
481
|
+
if (e.probing) return 'verifying';
|
|
482
|
+
const current = e.path ? identify(e.path) : null;
|
|
483
|
+
const changed = !sameIdentity(current, e.seen);
|
|
484
|
+
if (changed) e.seen = current;
|
|
485
|
+
const v = e.verdict;
|
|
486
|
+
if (!v || changed || (!v.ok && v.transient && now() - v.at >= retryMs)) { startProbe(proc, e); return 'verifying'; }
|
|
487
|
+
return v.ok ? 'verified' : 'failed';
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
// ── Serves SynaBun did not start ──
|
|
491
|
+
async function probeForeign(serve) {
|
|
492
|
+
const key = listenerGenerationKey(serve);
|
|
493
|
+
let rec = foreign.verdicts.get(key);
|
|
494
|
+
if (rec?.probing) return rec.probing;
|
|
495
|
+
const identity = identify(serve.executable);
|
|
496
|
+
const version = await Promise.resolve().then(() => readVersion(identity)).catch(() => null);
|
|
497
|
+
const policy = nativeServeVersionPolicy(version);
|
|
498
|
+
// Read on every scan, including a cache hit: Homebrew may replace a file without changing its size or mtime,
|
|
499
|
+
// and a version change must invalidate the verdict even when those two fields stayed the same.
|
|
500
|
+
const cacheKey = identity && policy.ok ? `${key}|${serve.executable}|${binaryKey(identity, policy.version)}` : null;
|
|
501
|
+
const v = rec?.verdict;
|
|
502
|
+
if (cacheKey && rec?.cacheKey === cacheKey && v && now() - v.at < foreignTtlMs && !(v.transient && now() - v.at >= retryMs)) return v;
|
|
503
|
+
if (!rec) { rec = { serve, verdict: null, probing: null }; foreign.verdicts.set(key, rec); }
|
|
504
|
+
rec.serve = serve;
|
|
505
|
+
rec.cacheKey = cacheKey;
|
|
506
|
+
const ports = [...new Set((serve.addresses || []).map((a) => Number(a.port)).filter((p) => p > 0))];
|
|
507
|
+
rec.probing = (async () => {
|
|
508
|
+
let verdict = null;
|
|
509
|
+
if (!identity || !policy.ok) {
|
|
510
|
+
const failed = !identity ? 'binary' : 'version';
|
|
511
|
+
const detail = !identity ? `the executable of pid ${serve.pid} (${serve.executable || 'unknown path'}) could not be identified`
|
|
512
|
+
: policy.reason === 'version-old' ? `OpenCode ${policy.version} is older than ${NATIVE_SERVE_MIN_VERSION}`
|
|
513
|
+
: 'the listening executable did not report an OpenCode MAJOR.MINOR.PATCH version';
|
|
514
|
+
rec.verdict = { ok: false, failed, detail, version: policy.version, transient: !identity || policy.reason === 'version-unreadable', checks: [{ id: failed, ok: false, detail }], at: now(), port: ports[0] || null };
|
|
515
|
+
return rec.verdict;
|
|
516
|
+
}
|
|
517
|
+
const before = await Promise.resolve().then(() => readGeneration(serve.pid)).catch(() => null);
|
|
518
|
+
for (const port of ports) {
|
|
519
|
+
let result;
|
|
520
|
+
try { result = await probe({ port, pid: serve.pid, password: null, foreign: true }); }
|
|
521
|
+
catch (error) { result = { ok: false, failed: 'loopback', transient: true, detail: `the probe failed: ${String(error?.message || error)}`, checks: [] }; }
|
|
522
|
+
if (!result || typeof result !== 'object') result = { ok: false, failed: 'loopback', transient: true, detail: 'the probe gave no answer', checks: [] };
|
|
523
|
+
verdict = { ok: !!result.ok, failed: result.ok ? null : (result.failed || 'unknown'), detail: result.detail || null, transient: !result.ok && !!result.transient,
|
|
524
|
+
exposed: !result.ok && !!result.exposed, checks: Array.isArray(result.checks) ? result.checks : [], at: now(), port, matrix: result.matrix || null };
|
|
525
|
+
if (!verdict.ok) break;
|
|
526
|
+
}
|
|
527
|
+
if (!verdict) verdict = { ok: false, failed: 'loopback', detail: `pid ${serve.pid} listens on no TCP port`, transient: true, checks: [], at: now(), port: null };
|
|
528
|
+
const after = await Promise.resolve().then(() => readGeneration(serve.pid)).catch(() => null);
|
|
529
|
+
const stable = before && after && before.key === after.key && before.executable === after.executable && after.executable === serve.executable
|
|
530
|
+
&& sameIdentity(identity, identify(serve.executable));
|
|
531
|
+
const extra = [
|
|
532
|
+
{ id: 'process', ok: !!stable, detail: stable ? `pid ${serve.pid} and its executable stayed the same`
|
|
533
|
+
: `pid ${serve.pid}: its process, executable or sockets changed or could not be read during verification` },
|
|
534
|
+
{ id: 'version', ok: true, detail: `OpenCode ${policy.version}` },
|
|
535
|
+
];
|
|
536
|
+
if (verdict.ok && !stable) Object.assign(verdict, { ok: false, failed: 'process', transient: true, detail: extra[0].detail });
|
|
537
|
+
verdict.version = policy.version;
|
|
538
|
+
verdict.checks.push(...extra);
|
|
539
|
+
rec.verdict = verdict;
|
|
540
|
+
if (!verdict.ok) log(`OpenCode serve pid ${serve.pid} port ${verdict.port ?? '?'} (${serve.executable || serve.command || '?'}), not started by SynaBun, failed the runtime check "${verdict.failed}": ${verdict.detail}`);
|
|
541
|
+
return verdict;
|
|
542
|
+
})().finally(() => { rec.probing = null; });
|
|
543
|
+
return rec.probing;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
function refreshForeign() {
|
|
547
|
+
if (foreign.scanning) return foreign.scanning;
|
|
548
|
+
foreign.scanning = (async () => {
|
|
549
|
+
let result;
|
|
550
|
+
try { result = await scan(); } catch (error) { result = { ok: false, detail: String(error?.message || error) }; }
|
|
551
|
+
if (!result || typeof result !== 'object') result = { ok: false, detail: 'the scan gave no answer' };
|
|
552
|
+
if (result.ok && (!Array.isArray(result.serves) || result.serves.some((s) => !Number.isInteger(s?.pid) || s.pid <= 0
|
|
553
|
+
|| !s.startedAt || !Array.isArray(s.addresses) || !s.addresses.length))) {
|
|
554
|
+
result = { ok: false, detail: 'the listener scan returned an incomplete process or socket list' };
|
|
555
|
+
}
|
|
556
|
+
const own = ownPids();
|
|
557
|
+
const serves = result.ok ? (Array.isArray(result.serves) ? result.serves : []).filter((s) => Number.isInteger(s?.pid) && !own.has(s.pid)) : [];
|
|
558
|
+
foreign.result = { ok: !!result.ok, detail: result.ok ? null : (result.detail || 'the scan failed'), serves, at: now() };
|
|
559
|
+
const live = new Set(serves.map(listenerGenerationKey));
|
|
560
|
+
for (const key of [...foreign.verdicts.keys()]) if (!live.has(key) && !foreign.verdicts.get(key).probing) foreign.verdicts.delete(key);
|
|
561
|
+
const checked = await Promise.allSettled(serves.map(probeForeign));
|
|
562
|
+
if (checked.some((r) => r.status === 'rejected')) foreign.result = { ok: false, detail: 'an OpenCode executable or its verification result could not be read', serves: [], at: now() };
|
|
563
|
+
return foreign.result;
|
|
564
|
+
})().finally(() => { foreign.scanning = null; });
|
|
565
|
+
return foreign.scanning;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
function foreignOffenders(excluded) {
|
|
88
569
|
const out = [];
|
|
570
|
+
if (!foreign.result) { refreshForeign(); return [{ pid: null, port: null, reason: 'foreign-checking' }]; }
|
|
571
|
+
// A bounded refresh may return while lsof / --version / a probe is still pending. Its old verdict cannot
|
|
572
|
+
// admit a browser then: the very identity used as the cache key has not finished being checked.
|
|
573
|
+
if (foreign.scanning) return [{ pid: null, port: null, reason: 'foreign-checking' }];
|
|
574
|
+
if (!foreign.result.ok) return [{ pid: null, port: null, reason: 'foreign-scan', detail: foreign.result.detail }];
|
|
575
|
+
for (const s of foreign.result.serves) {
|
|
576
|
+
if (excluded.has(s.pid)) continue;
|
|
577
|
+
const rec = foreign.verdicts.get(listenerGenerationKey(s));
|
|
578
|
+
const base = { pid: s.pid, port: s.addresses?.[0]?.port || null, path: s.executable || null, command: s.command || null, version: rec?.verdict?.version || null };
|
|
579
|
+
if (!rec || rec.probing || !rec.verdict) { if (!rec?.probing) probeForeign(s); out.push({ ...base, reason: 'foreign-checking' }); continue; }
|
|
580
|
+
if (!rec.verdict.ok) out.push({ ...base, port: rec.verdict.port || base.port, reason: 'foreign', check: rec.verdict.failed, detail: rec.verdict.detail });
|
|
581
|
+
}
|
|
582
|
+
return out;
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
/**
|
|
586
|
+
* Look again at what may have changed since the last look, bounded by `refreshMs`: whether each verified serve is
|
|
587
|
+
* still the process and sockets its verdict was about (else it is probed again, and waited for), the OpenCode serves
|
|
588
|
+
* SynaBun did not start (listed and probed), and stops that could not be confirmed.
|
|
589
|
+
*/
|
|
590
|
+
async function refresh() {
|
|
591
|
+
const jobs = [];
|
|
592
|
+
for (const [proc, e] of processes) {
|
|
593
|
+
if (!e.safe || !e.ready || e.probing || !e.verdict?.ok) continue;
|
|
594
|
+
jobs.push((async () => {
|
|
595
|
+
const g = await Promise.resolve().then(() => readGeneration(e.pid)).catch(() => null);
|
|
596
|
+
if (processes.get(proc) !== e || e.probing || !e.verdict?.ok) return;
|
|
597
|
+
const current = e.path ? identify(e.path) : null;
|
|
598
|
+
if (!g || g.key !== e.verdict.generation?.key || g.executable !== e.verdict.generation?.executable || !sameIdentity(current, e.seen)) {
|
|
599
|
+
log(`OpenCode serve pid ${e.pid} port ${e.port}: ${g ? 'its process or its sockets changed' : 'its process could not be read'} since it was checked: checking again`);
|
|
600
|
+
e.seen = current;
|
|
601
|
+
e.verdict = null;
|
|
602
|
+
await startProbe(proc, e);
|
|
603
|
+
}
|
|
604
|
+
})());
|
|
605
|
+
}
|
|
606
|
+
for (const x of exposures.values()) jobs.push(recheckStuck(x));
|
|
607
|
+
jobs.push(refreshForeign());
|
|
608
|
+
await within(Promise.allSettled(jobs), refreshMs);
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
// ── A foreign serve that is going away ──
|
|
612
|
+
// On 2026-11-15 two revocations (21:13:30, 21:14:22 local) came from foreign serves that were exiting: the probe got no
|
|
613
|
+
// answer (pid 21487: "GET /api/session did not answer", its exit handler ran at 21:13:29.03) or a reset (pid 54472:
|
|
614
|
+
// ECONNRESET, exit handler at 21:14:22.60). A serve that answered nothing gave nothing away; once the OS confirms its
|
|
615
|
+
// process ended, or that it no longer listens on that port, no page can reach it. So when EVERY offender of a watch
|
|
616
|
+
// pass is such a failure (a foreign serve, `transient`, nothing `exposed`), the pass waits up to `exitGraceMs` for the
|
|
617
|
+
// OS to confirm them gone, and revokes only for those that are not. Anything else (an exposed answer, a serve still
|
|
618
|
+
// being checked, a scan that failed, a serve SynaBun started) is revoked at once, as before.
|
|
619
|
+
const foreignVerdictOf = (o) => {
|
|
620
|
+
const serve = (foreign.result?.serves || []).find((s) => s.pid === o.pid);
|
|
621
|
+
return serve ? foreign.verdicts.get(listenerGenerationKey(serve))?.verdict || null : null;
|
|
622
|
+
};
|
|
623
|
+
const settlingForeign = (o) => {
|
|
624
|
+
if (o?.reason !== 'foreign' || !Number.isInteger(o.pid) || !(o.pid > 0) || !(Number(o.port) > 0)) return false;
|
|
625
|
+
const v = foreignVerdictOf(o);
|
|
626
|
+
return !!v && !v.ok && v.transient === true && v.exposed !== true;
|
|
627
|
+
};
|
|
628
|
+
async function foreignGone(o) {
|
|
629
|
+
let alive;
|
|
630
|
+
try { alive = pidAlive(o.pid); } catch { alive = null; }
|
|
631
|
+
if (alive === false) return true;
|
|
632
|
+
let pids;
|
|
633
|
+
try { pids = await portListeners(Number(o.port)); } catch { pids = null; }
|
|
634
|
+
return Array.isArray(pids) && !pids.includes(o.pid);
|
|
635
|
+
}
|
|
636
|
+
async function withoutExitingForeign(bad) {
|
|
637
|
+
if (!(exitGraceMs > 0) || !bad.length || !bad.every(settlingForeign)) return bad;
|
|
638
|
+
const end = now() + exitGraceMs;
|
|
639
|
+
let left = bad;
|
|
640
|
+
for (;;) {
|
|
641
|
+
const gone = await Promise.all(left.map((o) => foreignGone(o).catch(() => false)));
|
|
642
|
+
const settled = left.filter((_, i) => gone[i]);
|
|
643
|
+
for (const o of settled) log(`OpenCode serve pid ${o.pid} port ${o.port}, not started by SynaBun, failed "${o.check}" while it was going away and is gone now: no browser context revoked for it`);
|
|
644
|
+
left = left.filter((_, i) => !gone[i]);
|
|
645
|
+
if (!left.length || now() >= end) return left;
|
|
646
|
+
await defaultSleep(Math.max(1, Math.min(exitPollMs, end - now())));
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
function ensureWatch() {
|
|
651
|
+
if (watchTimer || !(watchMs > 0)) return;
|
|
652
|
+
watchTimer = setInterval(() => {
|
|
653
|
+
if (!attachedContexts().length) { clearInterval(watchTimer); watchTimer = null; return; }
|
|
654
|
+
refresh().then(async () => {
|
|
655
|
+
if (!foreign.result?.ok) { revokeAll('the OpenCode listening processes could not be verified'); return; }
|
|
656
|
+
const bad = await withoutExitingForeign(foreignOffenders(new Set()));
|
|
657
|
+
if (bad.length) revokeAll(`an OpenCode serve SynaBun did not start could not be verified (pid ${bad[0].pid || '?'}, port ${bad[0].port || '?'}, check "${bad[0].check || bad[0].reason}")`);
|
|
658
|
+
}).catch(() => {});
|
|
659
|
+
}, watchMs);
|
|
660
|
+
watchTimer.unref?.();
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
function offenders({ ports = [], unverifiedRecords = [] } = {}) {
|
|
664
|
+
const out = [...buildChecks.values()].map(({ info }) => ({ reason: 'build-checking', path: info.path, version: info.version }));
|
|
89
665
|
const verified = new Set();
|
|
90
666
|
for (const [proc, e] of processes) {
|
|
91
|
-
const base = { pid: proc.pid || null, port: e.port, path: e.path || null, version: e.version || null };
|
|
92
|
-
|
|
93
|
-
|
|
667
|
+
const base = { pid: e.pid || proc.pid || null, port: e.port, path: e.path || null, version: e.version || null };
|
|
668
|
+
const state = stateOf(proc, e);
|
|
669
|
+
if (state === 'refused') out.push({ ...base, reason: e.reason || 'version' });
|
|
670
|
+
else if (state === 'starting') out.push({ ...base, reason: 'starting' });
|
|
671
|
+
else if (state === 'verifying') out.push({ ...base, reason: 'verifying' });
|
|
672
|
+
else if (state === 'failed') out.push({ ...base, reason: 'probe', check: e.verdict.failed, detail: e.verdict.detail });
|
|
94
673
|
else verified.add(e.port);
|
|
95
674
|
}
|
|
675
|
+
// A failed serve whose process has ended but whose listener is not confirmed gone yet (or never was).
|
|
676
|
+
for (const x of exposures.values()) {
|
|
677
|
+
if (out.some((o) => o.reason === 'probe' && o.port === x.port && o.pid === x.pid)) continue;
|
|
678
|
+
out.push({ pid: x.pid, port: x.port, path: x.path, version: x.version, reason: 'exposure', state: x.state, check: x.check, detail: x.detail });
|
|
679
|
+
}
|
|
96
680
|
for (const port of ports) {
|
|
97
681
|
const n = Number(port);
|
|
98
682
|
if (verified.has(n) || out.some(o => o.port === n)) continue;
|
|
@@ -100,88 +684,220 @@ export function createNativeServeBoundary() {
|
|
|
100
684
|
}
|
|
101
685
|
// A record has the serve's command line (its identity), not a path; never its token.
|
|
102
686
|
for (const r of unverifiedRecords) out.push({ pid: r?.pid || null, port: r?.port || null, kind: r?.kind || null, command: r?.command || null, claimable: !!r?.claimable, reason: 'record' });
|
|
687
|
+
const excluded = ownPids();
|
|
688
|
+
for (const r of unverifiedRecords) if (Number.isInteger(r?.pid)) excluded.add(r.pid);
|
|
689
|
+
out.push(...foreignOffenders(excluded));
|
|
103
690
|
return out;
|
|
104
691
|
}
|
|
105
692
|
function reserve(context) {
|
|
106
693
|
const held = contexts.get(context);
|
|
107
|
-
if (held) return held;
|
|
694
|
+
if (held) return held.release;
|
|
108
695
|
const browser = context.browser?.() || null;
|
|
696
|
+
const rec = { attached: false, revoking: false, release: null };
|
|
109
697
|
const release = () => {
|
|
110
|
-
if (contexts.get(context) !==
|
|
698
|
+
if (contexts.get(context) !== rec) return;
|
|
111
699
|
contexts.delete(context);
|
|
112
|
-
context.removeListener('close', release);
|
|
113
|
-
browser?.removeListener('disconnected', release);
|
|
700
|
+
context.removeListener?.('close', release);
|
|
701
|
+
browser?.removeListener?.('disconnected', release);
|
|
114
702
|
};
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
703
|
+
rec.release = release;
|
|
704
|
+
contexts.set(context, rec);
|
|
705
|
+
context.once?.('close', release);
|
|
706
|
+
browser?.once?.('disconnected', release);
|
|
118
707
|
return release;
|
|
119
708
|
}
|
|
120
|
-
function
|
|
121
|
-
const
|
|
122
|
-
|
|
709
|
+
function status() {
|
|
710
|
+
const serves = [];
|
|
711
|
+
for (const [proc, e] of processes) {
|
|
712
|
+
const state = stateOf(proc, e);
|
|
713
|
+
const v = e.verdict;
|
|
714
|
+
serves.push({
|
|
715
|
+
pid: e.pid || proc.pid || null, port: e.port, path: e.path || null, version: e.version || null, knownGood: !!e.knownGood, own: true,
|
|
716
|
+
state, reason: state === 'refused' ? (e.reason || 'version') : state === 'failed' ? 'probe' : null,
|
|
717
|
+
failed: state === 'failed' ? v.failed : null, detail: v?.detail || null, checkedAt: v?.at || null,
|
|
718
|
+
stopping: [...exposures.values()].some((x) => x.port === e.port && x.pid === (e.pid || proc.pid)),
|
|
719
|
+
checks: (v?.checks || []).map(({ id, ok, detail, skipped }) => ({ id, ok: !!ok, detail: detail || '', ...(skipped ? { skipped: true } : {}) })),
|
|
720
|
+
});
|
|
721
|
+
}
|
|
722
|
+
for (const x of exposures.values()) {
|
|
723
|
+
if (serves.some((s) => s.port === x.port && s.pid === x.pid)) continue;
|
|
724
|
+
serves.push({ pid: x.pid, port: x.port, path: x.path, version: x.version, knownGood: false, own: true, state: 'failed', reason: 'probe', failed: x.check, detail: x.detail,
|
|
725
|
+
checkedAt: x.since, stopping: x.state === 'removing', stuck: x.state === 'stuck', checks: [] });
|
|
726
|
+
}
|
|
727
|
+
const others = [];
|
|
728
|
+
for (const s of foreign.result?.ok ? foreign.result.serves : []) {
|
|
729
|
+
const rec = foreign.verdicts.get(listenerGenerationKey(s));
|
|
730
|
+
const v = rec?.verdict || null;
|
|
731
|
+
others.push({ pid: s.pid, port: v?.port || s.addresses?.[0]?.port || null, path: s.executable || null, version: v?.version || null, command: s.command ? short(s.command, 400) : null, own: false,
|
|
732
|
+
state: foreign.scanning || rec?.probing || !v ? 'verifying' : v.ok ? 'verified' : 'failed', failed: v && !v.ok ? v.failed : null, detail: v?.detail || null, checkedAt: v?.at || null,
|
|
733
|
+
checks: (v?.checks || []).map(({ id, ok, detail, skipped }) => ({ id, ok: !!ok, detail: detail || '', ...(skipped ? { skipped: true } : {}) })) });
|
|
734
|
+
}
|
|
735
|
+
return {
|
|
736
|
+
serves, foreign: others,
|
|
737
|
+
scan: foreign.result ? { ok: foreign.result.ok, detail: foreign.result.detail, at: foreign.result.at } : null,
|
|
738
|
+
nativeAttached: contexts.size, minimum: NATIVE_SERVE_MIN_VERSION, knownGood: [...NATIVE_SERVE_KNOWN_GOOD],
|
|
739
|
+
};
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
async function attach(context, { state, sweep = null, waitMs = 20_000, sweepMs = 10_000, deadline = Infinity, signal = null, pollMs = 250, now: clock = Date.now, sleep = defaultSleep } = {}) {
|
|
743
|
+
const release = reserve(context);
|
|
744
|
+
const rec = contexts.get(context);
|
|
745
|
+
const held = () => contexts.get(context) === rec;
|
|
746
|
+
try {
|
|
747
|
+
const start = clock();
|
|
748
|
+
const end = Number.isFinite(deadline) ? deadline : Infinity;
|
|
749
|
+
const waitEnd = Math.min(start + Math.max(0, waitMs), end);
|
|
750
|
+
const sweepEnd = Math.min(start + Math.max(0, sweepMs), end);
|
|
751
|
+
let current = state();
|
|
752
|
+
let sweeping = false;
|
|
753
|
+
if (sweep && current.unverifiedRecords?.length) {
|
|
754
|
+
sweeping = true;
|
|
755
|
+
Promise.resolve().then(sweep).catch(() => {}).finally(() => { sweeping = false; });
|
|
756
|
+
}
|
|
757
|
+
// Held first; then what may have changed is looked at again (the processes behind the verdicts, the serves
|
|
758
|
+
// SynaBun did not start), bounded by refreshMs and the request's deadline.
|
|
759
|
+
await within(refresh(), Math.min(refreshMs, end - clock()));
|
|
760
|
+
current = state();
|
|
761
|
+
const pending = (o) => o.reason === 'build-checking' || o.reason === 'starting' || o.reason === 'verifying' || o.reason === 'foreign-checking' || (o.reason === 'exposure' && o.state === 'removing');
|
|
762
|
+
for (;;) {
|
|
763
|
+
if (!held()) throw nativeContextClosed();
|
|
764
|
+
if (signal?.aborted) throw nativeAttachAborted();
|
|
765
|
+
const blocking = offenders(current);
|
|
766
|
+
if (!blocking.length) {
|
|
767
|
+
rec.attached = true;
|
|
768
|
+
ensureWatch();
|
|
769
|
+
return release;
|
|
770
|
+
}
|
|
771
|
+
const t = clock();
|
|
772
|
+
const waitable = (o) => (pending(o) && t < waitEnd)
|
|
773
|
+
|| (o.reason === 'record' && o.claimable && sweeping && t < sweepEnd);
|
|
774
|
+
if (!blocking.every(waitable)) throw nativeServeError(blocking);
|
|
775
|
+
const until = Math.max(...blocking.map(o => (pending(o) ? waitEnd : sweepEnd)));
|
|
776
|
+
await sleep(Math.max(1, Math.min(pollMs, until - t)));
|
|
777
|
+
current = state();
|
|
778
|
+
}
|
|
779
|
+
} catch (error) {
|
|
780
|
+
release();
|
|
781
|
+
throw error;
|
|
782
|
+
}
|
|
123
783
|
}
|
|
784
|
+
|
|
124
785
|
return {
|
|
125
786
|
offenders,
|
|
126
787
|
reserve,
|
|
788
|
+
status,
|
|
789
|
+
refresh,
|
|
127
790
|
holds: (context) => contexts.has(context),
|
|
791
|
+
// What is known about a build (binaryKey): `{ ok, failed, detail, version, at }` or null. Shown in Settings; it
|
|
792
|
+
// never admits a serve.
|
|
793
|
+
buildVerdict: (key) => verdicts.get(key),
|
|
794
|
+
// A cached runtime pass is not a pre-flight. Known-good version labels never grant launch authority.
|
|
128
795
|
assertLaunch(safe, info = {}) {
|
|
129
|
-
if (!
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
796
|
+
if (!contexts.size) return;
|
|
797
|
+
const key = binaryKey(info.identity, info.version);
|
|
798
|
+
const current = info.path ? identify(info.path) : null;
|
|
799
|
+
if (safe && key && builds.get(key)?.ok && sameIdentity(current, info.identity)
|
|
800
|
+
&& !exposures.size && ![...contexts.values()].some(r => r.revoking)) return;
|
|
801
|
+
const e = nativeServeError([{ pid: null, port: info.port || null, path: info.path || null, version: info.version || null,
|
|
802
|
+
reason: safe ? 'unverified-build' : (info.reason || 'version') }]);
|
|
803
|
+
e.message = `A native browser is attached, so this unverified OpenCode serve is not started. ${e.message}`;
|
|
804
|
+
throw e;
|
|
134
805
|
},
|
|
135
|
-
|
|
806
|
+
// Called automatically by every production launch and before a native browser is admitted. Starting a NEW
|
|
807
|
+
// build while a context is held would expose the pre-flight itself through MoreLogin's 0.0.0.0 bypass.
|
|
808
|
+
// An in-progress pre-flight precedes any subsequent attach reservation; that attach waits for its cleanup.
|
|
809
|
+
async prepareBuild(safe, info = {}) {
|
|
810
|
+
if (!safe) { this.assertLaunch(safe, info); return; }
|
|
811
|
+
const key = binaryKey(info.identity, info.version);
|
|
812
|
+
if (!info.identity?.native) throw nativeServeError([{ ...info, reason: 'unverified-build', detail: 'Choose the native OpenCode executable in Settings → Executable paths; a script launcher can change which binary it starts without changing its own identity.' }]);
|
|
813
|
+
if (!key || !sameIdentity(identify(info.path), info.identity)) throw nativeServeError([{ ...info, reason: 'unverified-build', detail: 'The executable identity changed or could not be read.' }]);
|
|
814
|
+
if (builds.get(key)?.ok) return;
|
|
815
|
+
if (buildChecks.has(key)) return buildChecks.get(key).promise;
|
|
816
|
+
this.assertLaunch(safe, info);
|
|
817
|
+
if (typeof preflight !== 'function') throw nativeServeError([{ ...info, reason: 'unverified-build', detail: 'Automatic pre-flight is unavailable.' }]);
|
|
818
|
+
const epoch = verificationEpoch;
|
|
819
|
+
const owned = new Map(); // Retain cleanup evidence even if the child exits before printing its password.
|
|
820
|
+
const rec = { info, promise: null };
|
|
821
|
+
buildChecks.set(key, rec);
|
|
822
|
+
rec.promise = Promise.resolve().then(() => preflight(info, {
|
|
823
|
+
track: (proc, detail) => { this.track(proc, detail); owned.set(proc, processes.get(proc)); },
|
|
824
|
+
verify: (proc, detail) => this.ready(proc, detail),
|
|
825
|
+
stop: async (proc) => {
|
|
826
|
+
const entry = owned.get(proc);
|
|
827
|
+
const exposure = [...exposures.values()].find(x => x.proc === proc);
|
|
828
|
+
if (exposure) return exposure.done;
|
|
829
|
+
if (!entry || !proc.pid) return true;
|
|
830
|
+
return terminate(proc, entry, { failed: 'preflight-cleanup', detail: 'the throwaway build verification has finished' });
|
|
831
|
+
},
|
|
832
|
+
})).then(result => {
|
|
833
|
+
if (!result?.ok || result.version !== info.version || !sameIdentity(identify(info.path), info.identity) || epoch !== verificationEpoch) {
|
|
834
|
+
builds.delete(key);
|
|
835
|
+
throw nativeServeError([{ ...info, reason: 'unverified-build', detail: result?.detail || 'The pre-flight failed or verification changed while it ran; retry.' }]);
|
|
836
|
+
}
|
|
837
|
+
// preflight resolves only after its process AND listener are confirmed gone.
|
|
838
|
+
const verdict = { ...result, buildPreflight: true, at: now() };
|
|
839
|
+
builds.set(key, verdict);
|
|
840
|
+
verdicts.set(key, verdict);
|
|
841
|
+
}).finally(() => { if (buildChecks.get(key) === rec) buildChecks.delete(key); });
|
|
842
|
+
return rec.promise;
|
|
843
|
+
},
|
|
844
|
+
// `kill(signal)` stops the serve (the server's own, Windows included); `stop` is the older form (SIGTERM only).
|
|
845
|
+
track(proc, { port, safe = false, version = null, path = null, reason = null, identity = undefined, knownGood = false, stop = null, kill = null }) {
|
|
136
846
|
if (!proc || proc.exitCode != null || proc.signalCode != null) return;
|
|
137
|
-
|
|
847
|
+
const id = identity === undefined ? (path ? identify(path) : null) : identity;
|
|
848
|
+
const killer = typeof kill === 'function' ? kill
|
|
849
|
+
: (signal) => (signal === 'SIGTERM' && typeof stop === 'function' ? stop() : proc.kill?.(signal));
|
|
850
|
+
processes.set(proc, { port: Number(port), safe, ready: false, version, path, reason: safe ? null : (reason || 'version'),
|
|
851
|
+
identity: id, seen: id, launchKey: binaryKey(id, version), knownGood: !!knownGood, pid: proc.pid || null, pidOwned: false, password: null,
|
|
852
|
+
verdict: null, probing: null, kill: killer });
|
|
138
853
|
const release = () => processes.delete(proc);
|
|
139
854
|
proc.once('exit', release);
|
|
140
855
|
proc.once('error', () => { if (!proc.pid) release(); });
|
|
141
856
|
},
|
|
142
|
-
|
|
143
|
-
//
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
857
|
+
// The serve answers (private HTTP/WS readiness passed): `pid` the process that listens (SynaBun's own: its spawn
|
|
858
|
+
// or a descendant the records confirmed), `password` the one it printed. Its probe starts now; until it has
|
|
859
|
+
// passed, the serve blocks a native attachment ('verifying').
|
|
860
|
+
ready(proc, { pid = null, password = null } = {}) {
|
|
861
|
+
const entry = processes.get(proc);
|
|
862
|
+
if (!entry) return null;
|
|
863
|
+
entry.ready = true;
|
|
864
|
+
if (Number.isInteger(pid) && pid > 0) { entry.pid = pid; entry.pidOwned = true; }
|
|
865
|
+
if (password) entry.password = password;
|
|
866
|
+
return entry.safe ? startProbe(proc, entry) : null;
|
|
148
867
|
},
|
|
149
|
-
//
|
|
150
|
-
// SynaBun
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
const
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
let sweeping = false;
|
|
164
|
-
if (sweep && current.unverifiedRecords?.length) {
|
|
165
|
-
sweeping = true;
|
|
166
|
-
Promise.resolve().then(sweep).catch(() => {}).finally(() => { sweeping = false; });
|
|
167
|
-
}
|
|
168
|
-
for (;;) {
|
|
169
|
-
if (!held()) throw nativeContextClosed();
|
|
170
|
-
if (signal?.aborted) throw nativeAttachAborted();
|
|
171
|
-
const blocking = offenders(current);
|
|
172
|
-
if (!blocking.length) return release;
|
|
173
|
-
const t = now();
|
|
174
|
-
const waitable = (o) => (o.reason === 'starting' && t < waitEnd)
|
|
175
|
-
|| (o.reason === 'record' && o.claimable && sweeping && t < sweepEnd);
|
|
176
|
-
if (!blocking.every(waitable)) throw nativeServeError(blocking);
|
|
177
|
-
const until = Math.max(...blocking.map(o => (o.reason === 'starting' ? waitEnd : sweepEnd)));
|
|
178
|
-
await sleep(Math.max(1, Math.min(pollMs, until - t)));
|
|
179
|
-
current = state();
|
|
180
|
-
}
|
|
181
|
-
} catch (error) {
|
|
182
|
-
release();
|
|
183
|
-
throw error;
|
|
868
|
+
// Settings → Verify OpenCode: every ready serve is probed again, its build's verdict forgotten first, and the
|
|
869
|
+
// serves SynaBun did not start are listed and probed again. Bounded by the probe's own limits.
|
|
870
|
+
async reverify() {
|
|
871
|
+
const epoch = ++verificationEpoch;
|
|
872
|
+
const priorBuilds = new Map(builds);
|
|
873
|
+
builds.clear();
|
|
874
|
+
const runs = [];
|
|
875
|
+
for (const [proc, e] of processes) {
|
|
876
|
+
if (!e.safe || !e.ready) continue;
|
|
877
|
+
verdicts.delete(e.launchKey);
|
|
878
|
+
e.verdict = null;
|
|
879
|
+
runs.push((e.probing ? e.probing.then(() => startProbe(proc, e)) : startProbe(proc, e)).then(v => {
|
|
880
|
+
if (epoch === verificationEpoch && v.ok && priorBuilds.has(e.launchKey) && sameIdentity(identify(e.path), e.identity)) builds.set(e.launchKey, priorBuilds.get(e.launchKey));
|
|
881
|
+
}));
|
|
184
882
|
}
|
|
883
|
+
foreign.verdicts.clear();
|
|
884
|
+
runs.push(refreshForeign());
|
|
885
|
+
for (const x of exposures.values()) runs.push(recheckStuck(x));
|
|
886
|
+
await Promise.allSettled(runs);
|
|
887
|
+
return status();
|
|
888
|
+
},
|
|
889
|
+
// attach without waiting: the context is held when nothing blocks now (after the bounded refresh), else refused.
|
|
890
|
+
// A context already held is returned as it is.
|
|
891
|
+
async protect(context, state) {
|
|
892
|
+
if (contexts.has(context)) return contexts.get(context).release;
|
|
893
|
+
return attach(context, { state: () => state || {}, waitMs: 0, sweepMs: 0 });
|
|
185
894
|
},
|
|
895
|
+
// The context is held (a pending reservation assertLaunch honours) before anything is waited for; then, bounded,
|
|
896
|
+
// what may have changed is looked at again (refresh) and SynaBun repairs what it can: a sweep of the records an
|
|
897
|
+
// ended SynaBun left (started at once, in the background, waited for at most `sweepMs`), SynaBun's own serves
|
|
898
|
+
// still starting or being probed, the serves SynaBun did not start being probed and a failed serve being stopped
|
|
899
|
+
// (waited for at most `waitMs`). Any other blocker refuses at once. `deadline` (an absolute time) and `signal` end
|
|
900
|
+
// the wait early. On every failure the reservation is released; the next attempt reads the live state again.
|
|
901
|
+
attach,
|
|
186
902
|
};
|
|
187
903
|
}
|