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
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
2
|
+
// Does a running OpenCode serve really require its password? Asked of the serve itself, not of its version number.
|
|
3
|
+
//
|
|
4
|
+
// A native browser context (MoreLogin) cannot have its pages' WebSockets routed, so a page there can open
|
|
5
|
+
// ws://127.0.0.1:<port>/api/pty/… of a local OpenCode serve: an unauthenticated serve would hand any web page a
|
|
6
|
+
// shell, files and sessions (lib/opencode-native-boundary.js). This probe is the evidence the boundary admits a serve
|
|
7
|
+
// on. Every check must pass; anything else (a timeout, a connection error, a status nobody expected, an answer that
|
|
8
|
+
// cannot be read) is a failure: fail closed.
|
|
9
|
+
//
|
|
10
|
+
// THE ROUTE MATRIX, and where it comes from. OpenCode 2.3.0 (Homebrew opencode-v2, /opt/homebrew/bin/opencode,
|
|
11
|
+
// checked 2026-11-14):
|
|
12
|
+
// - its OpenAPI document, GET /openapi.json with the serve's password ("opencode HttpApi"), which lists every
|
|
13
|
+
// /api route and /auth/connect/{code};
|
|
14
|
+
// - its authentication middleware, read from the binary's bundled server: the password is taken from a Basic
|
|
15
|
+
// Authorization header, from the query parameter `auth_token` (base64 of user:password: a page CAN set that on a
|
|
16
|
+
// WebSocket URL) or from an `opencode_session_<port>` cookie signed with the password (only when the Origin's host
|
|
17
|
+
// is the Host); it runs before the router (an unknown /api path answers 401) and EXEMPTS
|
|
18
|
+
// /auth/connect/:code (a pairing code the route itself checks) and, when `?ticket=` is present,
|
|
19
|
+
// /api/pty/:ptyID/connect, /api/experimental/persistent-pty/:ptyID/connect and /api/experimental/client-mcp
|
|
20
|
+
// (the route checks the ticket). Those exemptions are probed with a ticket / a code the serve never issued.
|
|
21
|
+
// SENSITIVE_ROUTES below is the fixed part (sessions, shell, files, terminals, configuration, MCP, events, credentials,
|
|
22
|
+
// RPC); for a serve SynaBun holds the password of, every operation of its own /openapi.json is added (`surface`), so
|
|
23
|
+
// a route a later build adds is asked too. A build whose document cannot be read is refused: its surface is unknown.
|
|
24
|
+
//
|
|
25
|
+
// NOTHING SENT HERE CAN ACT, even on a serve that turned out to be open: GETs read; every other method goes only to
|
|
26
|
+
// a route with a path parameter (filled with an id no serve has: ses_synabunprobe, pty_synabunprobe, …) or a
|
|
27
|
+
// request body, and carries the malformed JSON body `{`, which OpenCode 2.3.0 answers 400 "Expected a valid JSON
|
|
28
|
+
// body" / 404 "not found" even WITH the password (checked live on every mutating route of SENSITIVE_ROUTES). An
|
|
29
|
+
// operation that takes neither (POST /api/vcs/init, /api/pair, /api/location/reload, /api/debug/heap-dump, …) is
|
|
30
|
+
// never sent: on an open serve it would run. It is covered by the `routing` check instead: an unknown path and a
|
|
31
|
+
// wrong method under /api must be refused too, which proves the password is asked before the router picks a route.
|
|
32
|
+
//
|
|
33
|
+
// Checks (PROBE_CHECKS order):
|
|
34
|
+
// loopback the serve's process listens only on loopback addresses (its sockets as the OS reports them, never
|
|
35
|
+
// what its command line says), on the probed port among them
|
|
36
|
+
// surface the route list: the serve's /openapi.json read with SynaBun's password (a serve without one is
|
|
37
|
+
// asked SENSITIVE_ROUTES only, and the check says so)
|
|
38
|
+
// http-anonymous every route, without credentials: 401 or 403. A 2xx that is not a web page (JSON, an event
|
|
39
|
+
// stream) is an open API; a web page under /api, a 400 / 404 (the router answered: no password was
|
|
40
|
+
// asked), a redirect or any other status is refused as unexpected. Only /api paths, /openapi.json
|
|
41
|
+
// and /auth/connect are asked: every other path is OpenCode's web app (200 text/html), which is not
|
|
42
|
+
// an authentication hole and is never read as one.
|
|
43
|
+
// http-wrong-password the same with credentials that are not the serve's: Basic, `?auth_token=`, a forged session
|
|
44
|
+
// cookie, a ticket on the ticket routes and a pairing code that was never issued: 401 or 403
|
|
45
|
+
// ws-anonymous a WebSocket upgrade without credentials, from a page's Origin, to every WebSocket route: never 101
|
|
46
|
+
// ws-wrong-password the same upgrades with each wrong credential and a forged ticket: never 101
|
|
47
|
+
// routing an unknown /api path and a wrong method on a real route, without credentials: 401 or 403
|
|
48
|
+
// weak-password (a serve SynaBun did not start) a handful of guessable passwords do not open GET /api/info
|
|
49
|
+
// credentials the password SynaBun holds for a serve it started opens /api/info (200 JSON with a version).
|
|
50
|
+
// A serve SynaBun holds no password for cannot pass, unless asked as a foreign serve.
|
|
51
|
+
//
|
|
52
|
+
// A real credential is sent twice (GET /openapi.json, GET /api/info), in a header, never in a URL, and never
|
|
53
|
+
// appears in a result.
|
|
54
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
55
|
+
|
|
56
|
+
import { randomBytes } from 'node:crypto';
|
|
57
|
+
import { request as httpRequest } from 'node:http';
|
|
58
|
+
import { openSync, readSync, closeSync, realpathSync, statSync } from 'node:fs';
|
|
59
|
+
import { basicAuthHeader } from './opencode-protocol.js';
|
|
60
|
+
import { listListenAddressesAsync } from './process-identity.js';
|
|
61
|
+
|
|
62
|
+
export const PROBE_CHECKS = Object.freeze(['loopback', 'surface', 'http-anonymous', 'http-wrong-password', 'ws-anonymous',
|
|
63
|
+
'ws-wrong-password', 'routing', 'weak-password', 'credentials']);
|
|
64
|
+
|
|
65
|
+
// Ids no serve has: a mutating request that reached a route would find nothing to act on.
|
|
66
|
+
const PROBE_IDS = Object.freeze({ sessionID: 'ses_synabunprobe', ptyID: 'pty_synabunprobe' });
|
|
67
|
+
const PROBE_ID = 'synabun-auth-probe';
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* The fixed part of the matrix (see the head of this file). `body`: sent with the malformed JSON body `{`;
|
|
71
|
+
* `ws`: asked as a WebSocket upgrade too; `ticket`: a route OpenCode exempts from the password when `?ticket=` is
|
|
72
|
+
* present, asked with a forged ticket.
|
|
73
|
+
*/
|
|
74
|
+
export const SENSITIVE_ROUTES = Object.freeze([
|
|
75
|
+
{ id: 'session.list', method: 'GET', path: '/api/session' },
|
|
76
|
+
{ id: 'session.create', method: 'POST', path: '/api/session', body: true },
|
|
77
|
+
{ id: 'session.prompt', method: 'POST', path: '/api/session/ses_synabunprobe/prompt', body: true },
|
|
78
|
+
{ id: 'session.shell', method: 'POST', path: '/api/session/ses_synabunprobe/shell', body: true },
|
|
79
|
+
{ id: 'shell.list', method: 'GET', path: '/api/shell' },
|
|
80
|
+
{ id: 'shell.create', method: 'POST', path: '/api/shell', body: true },
|
|
81
|
+
{ id: 'fs.list', method: 'GET', path: '/api/fs/list' },
|
|
82
|
+
{ id: 'fs.read', method: 'GET', path: '/api/fs/read/synabun-auth-probe' },
|
|
83
|
+
{ id: 'fs.find', method: 'GET', path: '/api/fs/find' },
|
|
84
|
+
{ id: 'fs.write', method: 'POST', path: '/api/experimental/fs/write', body: true },
|
|
85
|
+
{ id: 'pty.list', method: 'GET', path: '/api/pty' },
|
|
86
|
+
{ id: 'pty.create', method: 'POST', path: '/api/pty', body: true },
|
|
87
|
+
{ id: 'pty.connect', method: 'GET', path: '/api/pty/pty_synabunprobe/connect', ws: true, ticket: true },
|
|
88
|
+
{ id: 'persistent-pty.connect', method: 'GET', path: '/api/experimental/persistent-pty/pty_synabunprobe/connect', ws: true, ticket: true },
|
|
89
|
+
{ id: 'config', method: 'GET', path: '/api/config' },
|
|
90
|
+
{ id: 'config.patch', method: 'PATCH', path: '/api/experimental/config', body: true },
|
|
91
|
+
{ id: 'mcp', method: 'GET', path: '/api/mcp' },
|
|
92
|
+
{ id: 'mcp.put', method: 'PUT', path: '/api/experimental/mcp/synabun-probe', body: true },
|
|
93
|
+
{ id: 'mcp.connect', method: 'POST', path: '/api/experimental/mcp/synabun-probe/connect', body: true },
|
|
94
|
+
{ id: 'client-mcp', method: 'GET', path: '/api/experimental/client-mcp?name=synabun-probe', ws: true, ticket: true },
|
|
95
|
+
{ id: 'credential', method: 'GET', path: '/api/credential' },
|
|
96
|
+
{ id: 'event', method: 'GET', path: '/api/event', ws: true },
|
|
97
|
+
{ id: 'rpc', method: 'POST', path: '/api/rpc/synabun-probe/probe', body: true },
|
|
98
|
+
{ id: 'info', method: 'GET', path: '/api/info' },
|
|
99
|
+
{ id: 'openapi', method: 'GET', path: '/openapi.json' },
|
|
100
|
+
]);
|
|
101
|
+
// Proof that the password is asked before the router: a path no build has, and a method /api/info does not take.
|
|
102
|
+
export const ROUTING_PROBES = Object.freeze([
|
|
103
|
+
{ id: 'routing.unknown', method: 'GET', path: '/api/synabun-auth-probe' },
|
|
104
|
+
{ id: 'routing.method', method: 'DELETE', path: '/api/info' },
|
|
105
|
+
]);
|
|
106
|
+
// A pairing code no serve issued: /auth/connect/:code is exempt from the password and must refuse it itself.
|
|
107
|
+
export const PAIRING_PROBE = Object.freeze({ id: 'pairing', method: 'GET', path: '/auth/connect/synabun-auth-probe' });
|
|
108
|
+
// Passwords a page could guess, tried on a serve SynaBun did not start (its password is not SynaBun's to know).
|
|
109
|
+
export const WEAK_PASSWORDS = Object.freeze(['', 'opencode', 'password', 'admin', '1234', '123456', '12345678', 'changeme', 'secret', 'letmein']);
|
|
110
|
+
// The Origin a web page in the browser would send: OpenCode 2 accepts any http://localhost:* origin.
|
|
111
|
+
const PAGE_ORIGIN = 'http://localhost:1';
|
|
112
|
+
const MALFORMED_BODY = '{';
|
|
113
|
+
const WS_PATH = /\/connect$|^\/api\/event$|\/terminal(\/|$)|client-mcp|\/ws(\/|$)/;
|
|
114
|
+
|
|
115
|
+
export const PROBE_REQUEST_MS = 1500;
|
|
116
|
+
export const PROBE_TOTAL_MS = 10_000;
|
|
117
|
+
const PROBE_CONCURRENCY = 16;
|
|
118
|
+
|
|
119
|
+
/** Is a listening address one only this computer can reach? 127.0.0.0/8, ::1 and their IPv4-mapped forms. */
|
|
120
|
+
export function isLoopbackHost(host) {
|
|
121
|
+
const h = String(host ?? '').trim().toLowerCase().replace(/^\[|\]$/g, '');
|
|
122
|
+
if (h === '::1' || h === '0:0:0:0:0:0:0:1') return true;
|
|
123
|
+
const v4 = h.startsWith('::ffff:') ? h.slice(7) : h;
|
|
124
|
+
const m = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(v4);
|
|
125
|
+
return !!m && m.slice(1).every((x) => Number(x) <= 255) && Number(m[1]) === 127;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* What one answer without the right credentials means: 'refused' (401 / 403: what passes), 'open' (a 2xx that is not
|
|
130
|
+
* a web page, or a WebSocket accepted), 'unexpected' (a web page, a redirect, a 400 / 404 / 5xx: anything else) or
|
|
131
|
+
* 'no-answer' (timeout, connection error).
|
|
132
|
+
*/
|
|
133
|
+
export function classifyAnonymousAnswer({ status, contentType = '', upgraded = false } = {}) {
|
|
134
|
+
if (upgraded || status === 101) return 'open';
|
|
135
|
+
if (status == null) return 'no-answer';
|
|
136
|
+
if (status === 401 || status === 403) return 'refused';
|
|
137
|
+
if (status >= 200 && status < 300) return /text\/html/i.test(String(contentType)) ? 'unexpected' : 'open';
|
|
138
|
+
return 'unexpected';
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* One request to the serve; resolves `{ status, contentType, upgraded, error }`, never rejects, never reads a body.
|
|
143
|
+
* `body` is sent as JSON (the malformed body of a mutating probe).
|
|
144
|
+
*/
|
|
145
|
+
export function probeRequest({ port, path, method = 'GET', host = '127.0.0.1', headers = {}, upgrade = false, body = null, timeoutMs = PROBE_REQUEST_MS } = {}) {
|
|
146
|
+
return new Promise((resolve) => {
|
|
147
|
+
let settled = false;
|
|
148
|
+
const done = (value) => { if (!settled) { settled = true; resolve(value); } };
|
|
149
|
+
let req;
|
|
150
|
+
try {
|
|
151
|
+
const base = upgrade
|
|
152
|
+
? { connection: 'Upgrade', upgrade: 'websocket', 'sec-websocket-version': '13', 'sec-websocket-key': randomBytes(16).toString('base64'), origin: PAGE_ORIGIN }
|
|
153
|
+
: { accept: 'application/json', origin: PAGE_ORIGIN };
|
|
154
|
+
const all = { ...base, ...headers };
|
|
155
|
+
if (body != null) { all['content-type'] = 'application/json'; all['content-length'] = String(Buffer.byteLength(body)); }
|
|
156
|
+
req = httpRequest({ hostname: host, port, path, method: upgrade ? 'GET' : method, agent: false, headers: all });
|
|
157
|
+
} catch (error) { done({ status: null, contentType: '', upgraded: false, error: String(error?.message || error) }); return; }
|
|
158
|
+
req.on('response', (res) => {
|
|
159
|
+
const value = { status: res.statusCode ?? null, contentType: String(res.headers['content-type'] || ''), upgraded: false, error: null };
|
|
160
|
+
res.destroy();
|
|
161
|
+
req.destroy();
|
|
162
|
+
done(value);
|
|
163
|
+
});
|
|
164
|
+
req.on('upgrade', (res, socket) => { socket.destroy(); done({ status: 101, contentType: '', upgraded: true, error: null }); });
|
|
165
|
+
req.on('error', (error) => done({ status: null, contentType: '', upgraded: false, error: String(error?.code || error?.message || error) }));
|
|
166
|
+
req.setTimeout(timeoutMs, () => { req.destroy(); done({ status: null, contentType: '', upgraded: false, error: `no answer within ${timeoutMs} ms` }); });
|
|
167
|
+
req.end(body ?? undefined);
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** An OpenAPI path template filled with the probe's ids: {sessionID} → ses_synabunprobe, `*` → synabun-auth-probe. */
|
|
172
|
+
export function fillProbePath(template) {
|
|
173
|
+
return String(template).replace(/\{([^}/]+)\}/g, (whole, name) => PROBE_IDS[name] || PROBE_ID).replace(/\*/g, PROBE_ID);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* The operations of a serve's OpenAPI document as probe routes: `{ routes, skipped }`, or null when the document is
|
|
178
|
+
* not one (no `paths` object, or no operation in it). GETs are asked (and as a WebSocket when the path is one of
|
|
179
|
+
* OpenCode's socket paths); another method only with a path parameter or a request body (with the malformed body);
|
|
180
|
+
* the rest are `skipped` (they could act: the routing check covers them).
|
|
181
|
+
*/
|
|
182
|
+
export function routesFromOpenApi(doc) {
|
|
183
|
+
const paths = doc && typeof doc === 'object' && doc.paths && typeof doc.paths === 'object' && !Array.isArray(doc.paths) ? doc.paths : null;
|
|
184
|
+
if (!paths) return null;
|
|
185
|
+
const routes = [];
|
|
186
|
+
const skipped = [];
|
|
187
|
+
for (const [template, item] of Object.entries(paths)) {
|
|
188
|
+
if (!template.startsWith('/') || !item || typeof item !== 'object') continue;
|
|
189
|
+
for (const method of ['get', 'post', 'put', 'patch', 'delete']) {
|
|
190
|
+
const op = item[method];
|
|
191
|
+
if (!op || typeof op !== 'object') continue;
|
|
192
|
+
const path = fillProbePath(template);
|
|
193
|
+
if (method === 'get') { routes.push({ id: `${method} ${template}`, method: 'GET', path, ...(WS_PATH.test(template) ? { ws: true } : {}) }); continue; }
|
|
194
|
+
const inputs = /\{[^}]+\}|\*/.test(template) || !!op.requestBody;
|
|
195
|
+
if (inputs) routes.push({ id: `${method} ${template}`, method: method.toUpperCase(), path, body: true });
|
|
196
|
+
else skipped.push({ method: method.toUpperCase(), path: template });
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return routes.length ? { routes, skipped } : null;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const routeKey = (r) => `${r.method} ${r.path}`;
|
|
203
|
+
function mergeRoutes(...lists) {
|
|
204
|
+
const seen = new Map();
|
|
205
|
+
for (const list of lists) for (const r of list) {
|
|
206
|
+
const k = routeKey(r);
|
|
207
|
+
const prev = seen.get(k);
|
|
208
|
+
seen.set(k, prev ? { ...prev, ws: prev.ws || r.ws, ticket: prev.ticket || r.ticket, body: prev.body || r.body } : r);
|
|
209
|
+
}
|
|
210
|
+
return [...seen.values()];
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const withQuery = (path, query) => (query ? `${path}${path.includes('?') ? '&' : '?'}${query}` : path);
|
|
214
|
+
|
|
215
|
+
/** The wrong credentials a page could present, each in a way OpenCode 2.3.0 reads a password. */
|
|
216
|
+
function wrongCredentials(port) {
|
|
217
|
+
const fake = `synabun-probe-${randomBytes(12).toString('base64url')}`;
|
|
218
|
+
const cookieValue = `${Math.floor(Date.now() / 1000) + 3600}.${randomBytes(32).toString('base64url')}`;
|
|
219
|
+
return [
|
|
220
|
+
{ id: 'basic', label: 'a wrong password (Basic)', headers: { authorization: basicAuthHeader(fake) } },
|
|
221
|
+
{ id: 'auth_token', label: 'a wrong password (?auth_token=)', query: `auth_token=${encodeURIComponent(Buffer.from(`opencode:${fake}`).toString('base64'))}` },
|
|
222
|
+
{ id: 'cookie', label: 'a forged session cookie', headers: { cookie: `opencode_session_${port}=${cookieValue}; opencode_session=${cookieValue}`, origin: `http://127.0.0.1:${port}` } },
|
|
223
|
+
];
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const describeAnswer = (a) => (a.upgraded ? 'accepted the WebSocket (101)' : a.status == null ? `did not answer (${a.error || 'no answer'})`
|
|
227
|
+
: `answered ${a.status}${a.contentType ? ` ${a.contentType.split(';')[0].trim()}` : ''}`);
|
|
228
|
+
|
|
229
|
+
// A check over many answers: the first that is not a refusal is the failure (an open answer before an unexpected
|
|
230
|
+
// one, so the sentence names the worst). `exposed`: an answer proved the serve open (a page could use it).
|
|
231
|
+
function judge(id, answers) {
|
|
232
|
+
const verdicts = answers.map((a) => ({ ...a, verdict: classifyAnonymousAnswer(a.answer) }));
|
|
233
|
+
const bad = verdicts.find((a) => a.verdict === 'open') || verdicts.find((a) => a.verdict === 'unexpected') || verdicts.find((a) => a.verdict === 'no-answer');
|
|
234
|
+
if (!bad) return { id, ok: true, detail: `${answers.length} request${answers.length === 1 ? '' : 's'} refused (401/403)` };
|
|
235
|
+
const what = bad.upgrade ? `a WebSocket upgrade to ${bad.path.split('?')[0]}` : `${bad.method} ${bad.path.split('?')[0]}`;
|
|
236
|
+
const how = bad.label ? ` with ${bad.label}` : '';
|
|
237
|
+
const why = bad.verdict === 'open' ? (id === 'weak-password' ? ': a web page could guess its password' : `${bad.label ? '' : ' without credentials'}: this serve does not require its password`)
|
|
238
|
+
: bad.verdict === 'no-answer' ? '' : ' (expected 401 or 403)';
|
|
239
|
+
// 'unexpected' too: a 400 / 404 means a route ran without the password being asked.
|
|
240
|
+
const exposed = bad.verdict === 'open' || (bad.verdict === 'unexpected' && bad.answer.status != null && !/text\/html/i.test(bad.answer.contentType || ''));
|
|
241
|
+
return { id, ok: false, verdict: bad.verdict, exposed, transient: bad.verdict === 'no-answer', detail: `${what}${how} ${describeAnswer(bad.answer)}${why}` };
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// Run `fn` over `items`, at most `limit` at a time, until `stop()` says so (the probe's deadline passed, or the serve
|
|
245
|
+
// stopped answering): what was not asked then is left out (the probe has failed by then).
|
|
246
|
+
async function pool(items, limit, fn, stop = () => false) {
|
|
247
|
+
const out = [];
|
|
248
|
+
let next = 0;
|
|
249
|
+
const worker = async () => { while (next < items.length && !stop()) { const k = next++; out[k] = await fn(items[k]); } };
|
|
250
|
+
await Promise.all(Array.from({ length: Math.max(1, Math.min(limit, items.length)) }, worker));
|
|
251
|
+
return out.filter(Boolean);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
async function loopbackCheck({ pid, port, listenAddresses }) {
|
|
255
|
+
if (!(Number.isInteger(pid) && pid > 0)) return { id: 'loopback', ok: false, detail: 'the process that answers on the port is not known, so its sockets cannot be read' };
|
|
256
|
+
let addresses;
|
|
257
|
+
try { addresses = await listenAddresses(pid); } catch { addresses = null; }
|
|
258
|
+
if (!Array.isArray(addresses)) return { id: 'loopback', ok: false, transient: true, detail: `the sockets pid ${pid} listens on could not be read` };
|
|
259
|
+
if (!addresses.length) return { id: 'loopback', ok: false, transient: true, detail: `pid ${pid} listens on no TCP socket` };
|
|
260
|
+
const outside = addresses.filter((a) => !isLoopbackHost(a.host));
|
|
261
|
+
if (outside.length) {
|
|
262
|
+
const list = outside.map((a) => `${a.host === '*' ? '*' : a.host.includes(':') ? `[${a.host}]` : a.host}:${a.port}`).join(', ');
|
|
263
|
+
return { id: 'loopback', ok: false, exposed: true, detail: `pid ${pid} listens on ${list}, reachable from other computers (only 127.0.0.1 or ::1 is allowed)` };
|
|
264
|
+
}
|
|
265
|
+
if (!addresses.some((a) => a.port === Number(port))) return { id: 'loopback', ok: false, detail: `pid ${pid} does not listen on port ${port}` };
|
|
266
|
+
return { id: 'loopback', ok: true, detail: `pid ${pid} listens on loopback only` };
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// GET with SynaBun's password: `{ status, type, json }` or `{ error }`. Never rejects.
|
|
270
|
+
async function authorizedGet(fetchImpl, url, password, timeoutMs) {
|
|
271
|
+
try {
|
|
272
|
+
const res = await fetchImpl(url, { headers: { accept: 'application/json', authorization: basicAuthHeader(password) }, redirect: 'manual', signal: AbortSignal.timeout(timeoutMs) });
|
|
273
|
+
const type = String(res.headers?.get?.('content-type') || '');
|
|
274
|
+
if (res.status !== 200 || !/application\/json/i.test(type)) { await res.body?.cancel?.().catch?.(() => {}); return { status: res.status, type, json: null }; }
|
|
275
|
+
let json = null;
|
|
276
|
+
try { json = await res.json(); } catch { json = null; }
|
|
277
|
+
return { status: res.status, type, json };
|
|
278
|
+
} catch (error) {
|
|
279
|
+
return { error: String(error?.name === 'TimeoutError' ? `no answer within ${timeoutMs} ms` : error?.message || error) };
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
async function surfaceCheck({ port, password, host, timeoutMs, fetchImpl, foreign }) {
|
|
284
|
+
if (!password) {
|
|
285
|
+
return foreign
|
|
286
|
+
? { id: 'surface', ok: true, skipped: true, routes: [], detail: `no password held: the ${SENSITIVE_ROUTES.length} routes SynaBun knows (OpenCode 2.3.0's) are asked` }
|
|
287
|
+
: { id: 'surface', ok: false, routes: [], detail: 'SynaBun holds no password for this serve, so its route list cannot be read' };
|
|
288
|
+
}
|
|
289
|
+
const got = await authorizedGet(fetchImpl, `http://${host}:${port}/openapi.json`, password, timeoutMs);
|
|
290
|
+
if (got.error) return { id: 'surface', ok: false, transient: true, routes: [], detail: `GET /openapi.json with SynaBun's password failed: ${got.error}` };
|
|
291
|
+
const parsed = got.json ? routesFromOpenApi(got.json) : null;
|
|
292
|
+
if (!parsed) {
|
|
293
|
+
return { id: 'surface', ok: false, routes: [], detail: `GET /openapi.json with SynaBun's password answered ${got.status}${got.type ? ` ${got.type.split(';')[0]}` : ''} without a route list: this build's API cannot be established` };
|
|
294
|
+
}
|
|
295
|
+
return { id: 'surface', ok: true, routes: parsed.routes, notSent: parsed.skipped,
|
|
296
|
+
detail: `${parsed.routes.length} operations from the serve's /openapi.json${parsed.skipped.length ? ` (${parsed.skipped.length} that take no input are not sent: ${parsed.skipped.map((s) => `${s.method} ${s.path}`).join(', ')})` : ''}` };
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
async function credentialsCheck({ port, password, host, timeoutMs, fetchImpl }) {
|
|
300
|
+
if (!password) return { id: 'credentials', ok: false, detail: 'SynaBun holds no password for this serve (it did not start it)' };
|
|
301
|
+
const got = await authorizedGet(fetchImpl, `http://${host}:${port}/api/info`, password, timeoutMs);
|
|
302
|
+
if (got.error) return { id: 'credentials', ok: false, transient: true, detail: `GET /api/info with SynaBun's password failed: ${got.error}` };
|
|
303
|
+
if (got.status !== 200 || !/application\/json/i.test(got.type || '')) {
|
|
304
|
+
return { id: 'credentials', ok: false, detail: `GET /api/info with SynaBun's password answered ${got.status}${got.type ? ` ${got.type.split(';')[0]}` : ''} (expected 200 JSON)` };
|
|
305
|
+
}
|
|
306
|
+
if (!got.json || typeof got.json.version !== 'string') return { id: 'credentials', ok: false, detail: 'GET /api/info with SynaBun\'s password did not answer OpenCode 2\'s info (no version)' };
|
|
307
|
+
return { id: 'credentials', ok: true, detail: `SynaBun's password is accepted (OpenCode ${got.json.version})`, version: got.json.version };
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Probe one serve. `{ ok, failed, checks, version, detail, transient, exposed, matrix }`: `ok` only when every check
|
|
312
|
+
* passed; `failed` the id of the first check that did not (PROBE_CHECKS order), `detail` its sentence; `transient`
|
|
313
|
+
* when that failure was a missing answer (a timeout, a socket that could not be read), which a later attempt may ask
|
|
314
|
+
* again; `exposed` when a failed check proved the serve reachable without its password (open answers, a socket
|
|
315
|
+
* other computers reach). `foreign`: a serve SynaBun did not start (no password): no credential or surface check,
|
|
316
|
+
* the weak-password check instead. Never throws. Bounded: `timeoutMs` per request, `totalMs` for the whole probe.
|
|
317
|
+
* @param {{ port: number, pid?: number|null, password?: string|null, host?: string, timeoutMs?: number, totalMs?: number,
|
|
318
|
+
* foreign?: boolean, requireCredentials?: boolean, listenAddresses?: (pid: number) => Promise<Array<{host: string, port: number}>|null>,
|
|
319
|
+
* request?: typeof probeRequest, fetchImpl?: typeof fetch }} o
|
|
320
|
+
*/
|
|
321
|
+
export async function probeOpencodeServe({ port, pid = null, password = null, host = '127.0.0.1', timeoutMs = PROBE_REQUEST_MS, totalMs = PROBE_TOTAL_MS,
|
|
322
|
+
foreign = false, requireCredentials = !foreign, listenAddresses = listListenAddressesAsync, request = probeRequest, fetchImpl = globalThis.fetch } = {}) {
|
|
323
|
+
const p = Number(port);
|
|
324
|
+
if (!Number.isInteger(p) || p <= 0 || p > 65535) {
|
|
325
|
+
return { ok: false, failed: 'loopback', transient: false, exposed: false, version: null, detail: 'no valid port to probe', checks: [{ id: 'loopback', ok: false, detail: 'no valid port to probe' }], matrix: null };
|
|
326
|
+
}
|
|
327
|
+
const ask = (route, { label = null, headers = {}, query = null, upgrade = false } = {}) => {
|
|
328
|
+
const path = withQuery(route.path, query);
|
|
329
|
+
return request({ port: p, host, path, method: route.method, headers, upgrade, body: !upgrade && route.body ? MALFORMED_BODY : null, timeoutMs })
|
|
330
|
+
.then((answer) => ({ path, method: upgrade ? 'GET' : route.method, label, upgrade, answer }));
|
|
331
|
+
};
|
|
332
|
+
let cancelled = false;
|
|
333
|
+
const work = (async () => {
|
|
334
|
+
const [loopback, surface] = await Promise.all([
|
|
335
|
+
loopbackCheck({ pid: Number(pid) || null, port: p, listenAddresses }),
|
|
336
|
+
surfaceCheck({ port: p, password, host, timeoutMs, fetchImpl, foreign }),
|
|
337
|
+
]);
|
|
338
|
+
const routes = mergeRoutes(SENSITIVE_ROUTES, surface.routes || []);
|
|
339
|
+
const wsRoutes = routes.filter((r) => r.ws);
|
|
340
|
+
const fixed = new Set(SENSITIVE_ROUTES.map(routeKey));
|
|
341
|
+
const wrong = wrongCredentials(p);
|
|
342
|
+
const forgedTicket = `ticket=${randomBytes(18).toString('base64url')}`;
|
|
343
|
+
// Every request of the matrix, tagged with the check it answers.
|
|
344
|
+
const plan = [];
|
|
345
|
+
for (const r of routes) plan.push(['http-anonymous', r, {}]);
|
|
346
|
+
for (const r of routes) for (const w of fixed.has(routeKey(r)) ? wrong : wrong.slice(0, 1)) plan.push(['http-wrong-password', r, w]);
|
|
347
|
+
for (const r of routes.filter((x) => x.ticket)) plan.push(['http-wrong-password', r, { label: 'a ticket the serve never issued', query: forgedTicket }]);
|
|
348
|
+
plan.push(['http-wrong-password', PAIRING_PROBE, { label: 'a pairing code the serve never issued' }]);
|
|
349
|
+
for (const r of wsRoutes) plan.push(['ws-anonymous', r, { upgrade: true }]);
|
|
350
|
+
for (const r of wsRoutes) for (const w of wrong) plan.push(['ws-wrong-password', r, { ...w, upgrade: true }]);
|
|
351
|
+
for (const r of wsRoutes.filter((x) => x.ticket)) plan.push(['ws-wrong-password', r, { label: 'a ticket the serve never issued', query: forgedTicket, upgrade: true }]);
|
|
352
|
+
for (const r of ROUTING_PROBES) plan.push(['routing', r, {}]);
|
|
353
|
+
if (foreign) for (const guess of WEAK_PASSWORDS) plan.push(['weak-password', SENSITIVE_ROUTES.find((r) => r.id === 'info'), { label: guess ? `the guessable password "${guess}"` : 'an empty password', headers: { authorization: basicAuthHeader(guess) } }]);
|
|
354
|
+
let silent = 0;
|
|
355
|
+
const answers = await pool(plan, PROBE_CONCURRENCY, ([check, route, opts]) => ask(route, opts).then((a) => {
|
|
356
|
+
if (a.answer.status == null && !a.answer.upgraded) silent++;
|
|
357
|
+
return { check, ...a };
|
|
358
|
+
}), () => cancelled || silent >= PROBE_CONCURRENCY);
|
|
359
|
+
const of = (id) => answers.filter((a) => a.check === id);
|
|
360
|
+
const checks = [loopback, surface];
|
|
361
|
+
for (const id of ['http-anonymous', 'http-wrong-password', 'ws-anonymous', 'ws-wrong-password', 'routing']) checks.push(judge(id, of(id)));
|
|
362
|
+
checks.push(foreign ? judge('weak-password', of('weak-password')) : { id: 'weak-password', ok: true, skipped: true, detail: 'not asked (SynaBun made this serve\'s password)' });
|
|
363
|
+
checks.push(requireCredentials || password ? await credentialsCheck({ port: p, password, host, timeoutMs, fetchImpl }) : { id: 'credentials', ok: true, skipped: true, detail: 'not asked (no password held)' });
|
|
364
|
+
return { checks, matrix: { source: surface.ok && !surface.skipped ? 'openapi' : 'fixed', routes: routes.length, requests: plan.length, notSent: Array.isArray(surface.notSent) ? surface.notSent.map((s) => `${s.method} ${s.path}`) : [] } };
|
|
365
|
+
})();
|
|
366
|
+
let timer;
|
|
367
|
+
const late = new Promise((resolve) => { timer = setTimeout(() => resolve(null), totalMs); timer.unref?.(); });
|
|
368
|
+
let outcome;
|
|
369
|
+
try { outcome = await Promise.race([work, late]); } catch (error) {
|
|
370
|
+
outcome = { checks: [{ id: 'loopback', ok: false, detail: `the probe failed: ${String(error?.message || error)}` }], matrix: null };
|
|
371
|
+
} finally { clearTimeout(timer); cancelled = true; }
|
|
372
|
+
if (!outcome) {
|
|
373
|
+
const detail = `the probe did not finish within ${totalMs} ms`;
|
|
374
|
+
return { ok: false, failed: 'loopback', transient: true, exposed: false, version: null, detail, checks: PROBE_CHECKS.map((id) => ({ id, ok: false, detail })), matrix: null };
|
|
375
|
+
}
|
|
376
|
+
const checks = PROBE_CHECKS.map((id) => outcome.checks.find((c) => c.id === id)).filter(Boolean);
|
|
377
|
+
// The failure named is one that proved the serve open when there is one (a page could use it), else the first.
|
|
378
|
+
const first = checks.find((c) => !c.ok && c.exposed) || checks.find((c) => !c.ok) || null;
|
|
379
|
+
return {
|
|
380
|
+
ok: !first,
|
|
381
|
+
failed: first?.id || null,
|
|
382
|
+
transient: !!first?.transient,
|
|
383
|
+
exposed: checks.some((c) => !c.ok && c.exposed),
|
|
384
|
+
version: checks.find((c) => c.id === 'credentials')?.version || null,
|
|
385
|
+
detail: first ? first.detail : 'every check passed',
|
|
386
|
+
checks: checks.map(({ id, ok, detail, skipped }) => ({ id, ok, detail, ...(skipped ? { skipped: true } : {}) })),
|
|
387
|
+
matrix: outcome.matrix,
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// Mach-O (both byte orders, 32/64-bit, universal) and ELF: a file the kernel runs itself. A script (#!) is run by an
|
|
392
|
+
// interpreter, whose process is not the file: what listens is checked another way (lib/opencode-native-boundary.js).
|
|
393
|
+
const NATIVE_MAGIC = [[0xcf, 0xfa, 0xed, 0xfe], [0xce, 0xfa, 0xed, 0xfe], [0xfe, 0xed, 0xfa, 0xcf], [0xfe, 0xed, 0xfa, 0xce], [0xca, 0xfe, 0xba, 0xbe], [0x7f, 0x45, 0x4c, 0x46], [0x4d, 0x5a]];
|
|
394
|
+
function readMagic(path) {
|
|
395
|
+
let fd = null;
|
|
396
|
+
try {
|
|
397
|
+
fd = openSync(path, 'r');
|
|
398
|
+
const buf = Buffer.alloc(4);
|
|
399
|
+
const n = readSync(fd, buf, 0, 4, 0);
|
|
400
|
+
return buf.subarray(0, n);
|
|
401
|
+
} catch { return null; } finally { if (fd != null) { try { closeSync(fd); } catch { /* closed */ } } }
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* The file a serve runs, as the file system has it now: `{ path, realpath, size, mtimeMs, ino, dev, native }`, or null
|
|
406
|
+
* when it cannot be read. A Homebrew update changes the real path (a new Cellar folder) and the times; an update in
|
|
407
|
+
* place changes the times and the size: any of them is a different binary, whose serves are probed again. `native`:
|
|
408
|
+
* the file is an executable the kernel runs itself (Mach-O, ELF, PE), not a script.
|
|
409
|
+
*/
|
|
410
|
+
export function binaryIdentity(path, { realpath = realpathSync, stat = statSync, magic = readMagic } = {}) {
|
|
411
|
+
if (!path || typeof path !== 'string') return null;
|
|
412
|
+
try {
|
|
413
|
+
const real = realpath(path);
|
|
414
|
+
const st = stat(real);
|
|
415
|
+
if (!st.isFile()) return null;
|
|
416
|
+
const head = magic(real);
|
|
417
|
+
const native = !!head && NATIVE_MAGIC.some((m) => m.every((b, i) => head[i] === b));
|
|
418
|
+
return { path, realpath: real, size: st.size, mtimeMs: st.mtimeMs, ino: Number(st.ino) || 0, dev: Number(st.dev) || 0, native };
|
|
419
|
+
} catch { return null; }
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/** The key of a binary and its version: what a verdict about a build is filed under. null without both. */
|
|
423
|
+
export function binaryKey(identity, version) {
|
|
424
|
+
if (!identity || !version) return null;
|
|
425
|
+
return [identity.realpath, identity.size, identity.mtimeMs, identity.ino, identity.dev, String(version).trim()].join('|');
|
|
426
|
+
}
|
|
@@ -429,29 +429,32 @@ export function createServeRecords({
|
|
|
429
429
|
* not carry this start's token (macOS, Linux), or whose start time is not to the fraction of a second (Windows);
|
|
430
430
|
* nor while the machine, the user or the boot cannot be told. A live record of another start under the same pid
|
|
431
431
|
* is never written over. Resolves the record or null.
|
|
432
|
+
* `quiet`: why nothing was recorded is not logged. For the try right after the spawn, which can come before the
|
|
433
|
+
* process shows its environment, when a second try follows once it answers (and logs if that one fails too).
|
|
432
434
|
*/
|
|
433
|
-
async function record({ kind, id = null, port, pid, token } = {}) {
|
|
435
|
+
async function record({ kind, id = null, port, pid, token, quiet = false } = {}) {
|
|
434
436
|
const n = Number(pid);
|
|
435
437
|
if (!kinds.includes(kind) || !isPid(n) || !isPort(Number(port)) || !TOKEN.test(str(token))) return null;
|
|
438
|
+
const say = quiet ? () => {} : log;
|
|
436
439
|
const at = await scopeLater();
|
|
437
|
-
if (!at) {
|
|
440
|
+
if (!at) { say(`no record for the ${kind} ${noun} on port ${port}: the machine, the user or the boot could not be read`); return null; }
|
|
438
441
|
const identity = await readIdentityAsync(n);
|
|
439
|
-
if (!identity) {
|
|
442
|
+
if (!identity) { say(`no record for the ${kind} ${noun} on port ${port}: the identity of process ${n} could not be read`); return null; }
|
|
440
443
|
const entry = {
|
|
441
444
|
v: RECORD_VERSION, kind, id: id == null ? null : String(id), port: Number(port),
|
|
442
445
|
pid: n, startedAt: identity.startedAt, command: identity.command, token,
|
|
443
446
|
scope: { ...at }, owner: owner(), recordedAt: new Date(now()).toISOString(),
|
|
444
447
|
};
|
|
445
|
-
if (!whole(entry)) {
|
|
448
|
+
if (!whole(entry)) { say(`no record for the ${kind} ${noun} on port ${port}: process ${n} is not a ${noun} on that port (${identity.command})`); return null; }
|
|
446
449
|
if (platform === 'win32') {
|
|
447
|
-
if (!FINE_START.test(entry.startedAt)) {
|
|
450
|
+
if (!FINE_START.test(entry.startedAt)) { say(`no record for the ${kind} ${noun} on port ${port}: the start time of process ${n} is not precise enough to tell it apart`); return null; }
|
|
448
451
|
} else {
|
|
449
|
-
if (String(identity.uid ?? '') !== at.uid) {
|
|
450
|
-
if (await readTokenAsync(n, token, identity.command) !== true) {
|
|
452
|
+
if (String(identity.uid ?? '') !== at.uid) { say(`no record for the ${kind} ${noun} on port ${port}: process ${n} is not this user's`); return null; }
|
|
453
|
+
if (await readTokenAsync(n, token, identity.command) !== true) { say(`no record for the ${kind} ${noun} on port ${port}: process ${n} does not carry this start's token`); return null; }
|
|
451
454
|
}
|
|
452
455
|
const onFile = readFile(`${n}.json`);
|
|
453
456
|
if (onFile && str(onFile.token) && onFile.token !== token && !issued.has(onFile.token) && await verify(onFile) === 'same') {
|
|
454
|
-
|
|
457
|
+
say(`no record for the ${kind} ${noun} on port ${port}: process ${n} is on record for another start`);
|
|
455
458
|
return null;
|
|
456
459
|
}
|
|
457
460
|
if (!write(entry)) return null;
|
|
@@ -521,7 +524,9 @@ export function createServeRecords({
|
|
|
521
524
|
const pids = await listeners(Number(port));
|
|
522
525
|
if (exited()) return { state: 'foreign' };
|
|
523
526
|
if (!Array.isArray(pids)) return { state: 'unknown' };
|
|
524
|
-
|
|
527
|
+
// Windows can miss a listener that just answered. This is not evidence of a competing process; the native
|
|
528
|
+
// boundary still consumes [] directly when confirming that a stopped listener is gone.
|
|
529
|
+
if (!pids.length) return { state: platform === 'win32' ? 'unknown' : 'foreign' };
|
|
525
530
|
let ours = null;
|
|
526
531
|
for (const listener of pids) {
|
|
527
532
|
if (listener !== n && await descendsFrom(listener, n) !== true) return { state: 'foreign', pids };
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
2
|
+
// Every OpenCode listening on this computer, SynaBun's or not.
|
|
3
|
+
//
|
|
4
|
+
// The native browser boundary (lib/opencode-native-boundary.js) must know about an OpenCode serve someone started in a
|
|
5
|
+
// terminal, another app or an earlier SynaBun on ANY port, not only the ports SynaBun chose: a page of a native
|
|
6
|
+
// (MoreLogin) context reaches all of them. This module asks the OS which processes listen on TCP (lsof / PowerShell,
|
|
7
|
+
// lib/process-identity.js listTcpListenersAsync) and which of them are OpenCode, by what the OS says each process is:
|
|
8
|
+
// its name, the executable file it runs and its command line. OpenCode is recognised when installed by Homebrew
|
|
9
|
+
// (/opt/homebrew/bin/opencode → Cellar/opencode*/…), by its install script (~/.opencode/bin/opencode), by npm
|
|
10
|
+
// (node …/node_modules/opencode-ai/bin/opencode, the platform package opencode-darwin-arm64/bin/opencode) and run from
|
|
11
|
+
// source (bun …/packages/opencode/src/index.ts). What it finds is only named, never signalled: SynaBun never stops a
|
|
12
|
+
// serve it did not start.
|
|
13
|
+
//
|
|
14
|
+
// Fail closed: when the OS cannot be asked, answers in part, or a listening process cannot be identified while it
|
|
15
|
+
// still runs, the scan is not ok and the boundary refuses the native browser with the reason.
|
|
16
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
17
|
+
|
|
18
|
+
import { listTcpListenersAsync, pidExists, readProcessExecutableAsync, readProcessIdentitiesAsync } from './process-identity.js';
|
|
19
|
+
|
|
20
|
+
// A file name that is OpenCode: opencode, opencode.exe, opencode.js / .mjs / .cjs / .ts, opencode-darwin-arm64 …
|
|
21
|
+
const OPENCODE_FILE = /^opencode(?:-(?:darwin|linux|windows|win32)(?:-[\w.]+)*)?(?:\.(?:exe|js|mjs|cjs|ts))?$/i;
|
|
22
|
+
// A folder on the way to OpenCode: the npm package, a platform package, a Homebrew keg, a source checkout.
|
|
23
|
+
const OPENCODE_DIR = /(?:^|[\\/])(?:opencode-ai|opencode-v\d+|opencode-(?:darwin|linux|windows|win32)(?:-[\w.]+)*|\.opencode|packages[\\/]opencode)(?:[\\/]|$)/i;
|
|
24
|
+
// The interpreters OpenCode is run through when it is not its own binary.
|
|
25
|
+
const WRAPPER = /^(?:node|nodejs|bun|bunx|deno|npx|tsx|ts-node)(?:\.exe)?$/i;
|
|
26
|
+
|
|
27
|
+
const baseName = (path) => String(path ?? '').split(/[\\/]/).filter(Boolean).pop() || '';
|
|
28
|
+
|
|
29
|
+
/** Does a path name an OpenCode program (its file, or a file inside an OpenCode package)? */
|
|
30
|
+
export function isOpencodePath(path) {
|
|
31
|
+
const text = String(path ?? '').trim().replace(/^["']|["']$/g, '');
|
|
32
|
+
if (!text) return false;
|
|
33
|
+
// A script inside an OpenCode package (…/opencode-ai/dist/cli.js, …/packages/opencode/src/index.ts) counts; another
|
|
34
|
+
// program that merely lives in such a folder (a language server OpenCode installed) does not.
|
|
35
|
+
return OPENCODE_FILE.test(baseName(text)) || (OPENCODE_DIR.test(text) && /\.(?:[mc]?js|ts)$/i.test(baseName(text)));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Is a process OpenCode? `{ name, executable, command }` as the OS reports them: its name or executable is OpenCode,
|
|
40
|
+
* or it is an interpreter (node, bun, deno …) whose first script argument is.
|
|
41
|
+
*/
|
|
42
|
+
export function isOpencodeProcess({ name = '', executable = '', command = '' } = {}) {
|
|
43
|
+
if (OPENCODE_FILE.test(baseName(name)) || isOpencodePath(executable)) return true;
|
|
44
|
+
const words = String(command ?? '').trim().split(/\s+/).filter(Boolean);
|
|
45
|
+
if (!words.length) return false;
|
|
46
|
+
if (isOpencodePath(words[0])) return true;
|
|
47
|
+
const runner = baseName(words[0]);
|
|
48
|
+
if (!WRAPPER.test(runner) && !WRAPPER.test(baseName(executable)) && !WRAPPER.test(baseName(name))) return false;
|
|
49
|
+
// node [flags] <script> …, bun run <script> …: the first word that is not a flag or "run" / "x" / "exec".
|
|
50
|
+
for (const word of words.slice(1, 8)) {
|
|
51
|
+
if (word.startsWith('-') || /^(?:run|x|exec)$/i.test(word)) continue;
|
|
52
|
+
return isOpencodePath(word);
|
|
53
|
+
}
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The OpenCode processes listening on TCP now: `{ ok: true, serves: [{ pid, name, startedAt, command, executable,
|
|
59
|
+
* addresses }] }`, or `{ ok: false, detail }` when that cannot be told (fail closed). `selfPid` (this server) is left
|
|
60
|
+
* out. Bounded by the OS queries' own timeouts (5 s each, three in a row at most).
|
|
61
|
+
*/
|
|
62
|
+
export async function scanOpencodeServes({ selfPid = process.pid, listeners = listTcpListenersAsync, identities = readProcessIdentitiesAsync,
|
|
63
|
+
executable = readProcessExecutableAsync, alive = pidExists } = {}) {
|
|
64
|
+
let listening;
|
|
65
|
+
try { listening = await listeners({ selfPid }); } catch { listening = null; }
|
|
66
|
+
if (!Array.isArray(listening)) return { ok: false, detail: 'the processes listening on TCP could not be listed (lsof, or Get-NetTCPConnection on Windows, failed or answered in part)' };
|
|
67
|
+
if (!listening.length) return { ok: true, serves: [] };
|
|
68
|
+
let ids;
|
|
69
|
+
try { ids = await identities(listening.map((l) => l.pid)); } catch { ids = null; }
|
|
70
|
+
if (!(ids instanceof Map)) return { ok: false, detail: 'the command lines of the processes listening on TCP could not be read (ps)' };
|
|
71
|
+
const serves = [];
|
|
72
|
+
const unknown = [];
|
|
73
|
+
for (const l of listening) {
|
|
74
|
+
const id = ids.get(l.pid);
|
|
75
|
+
if (!id) {
|
|
76
|
+
// Gone since lsof answered: nothing listens any more. Still running and unreadable: it could be OpenCode.
|
|
77
|
+
// pidExists answers null when it cannot tell: that is "still there" here.
|
|
78
|
+
if (alive(l.pid) !== false) unknown.push(l);
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
const name = l.name || id.name || '';
|
|
82
|
+
if (!id.command) {
|
|
83
|
+
// No command line (Windows: a process of another user, a protected one): only its name says what it is. A name
|
|
84
|
+
// that could be OpenCode, or an interpreter that could run it, cannot be ruled out: refused.
|
|
85
|
+
if (OPENCODE_FILE.test(baseName(name)) || WRAPPER.test(baseName(name)) || !name) unknown.push(l);
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
// The executable is read for a process that names OpenCode, or runs through an interpreter that could run it.
|
|
89
|
+
let exe = null;
|
|
90
|
+
const named = isOpencodeProcess({ name, command: id.command });
|
|
91
|
+
if (named || WRAPPER.test(baseName(name)) || !name) {
|
|
92
|
+
try { exe = await executable(l.pid); } catch { exe = null; }
|
|
93
|
+
}
|
|
94
|
+
if (!named && !isOpencodeProcess({ name, executable: exe || '', command: id.command })) continue;
|
|
95
|
+
serves.push({ pid: l.pid, name: name || baseName(exe) || null, startedAt: id.startedAt, command: id.command, executable: exe, addresses: l.addresses });
|
|
96
|
+
}
|
|
97
|
+
if (unknown.length) {
|
|
98
|
+
const list = unknown.map((l) => `pid ${l.pid} (${l.name || ids.get(l.pid)?.name || 'unnamed'}) on port ${l.addresses.map((a) => a.port).join(', ')}`).join('; ');
|
|
99
|
+
return { ok: false, detail: `a process listening on TCP could not be identified, so it could be an OpenCode serve: ${list}` };
|
|
100
|
+
}
|
|
101
|
+
return { ok: true, serves };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** What names one listening process at one moment: its pid, its start time and the sockets it listens on. */
|
|
105
|
+
export function listenerGenerationKey({ pid, startedAt, addresses = [] } = {}) {
|
|
106
|
+
const socks = (Array.isArray(addresses) ? addresses : []).map((a) => `${String(a.host).toLowerCase()}:${a.port}`).sort().join(',');
|
|
107
|
+
return `${pid}|${startedAt || '?'}|${socks}`;
|
|
108
|
+
}
|
|
@@ -142,7 +142,7 @@ export function isLocalMarkerHost(hostname, extraNames = []) {
|
|
|
142
142
|
* The pages the cookie is set on: the app's shells and the detached side panel's window, each the first page a
|
|
143
143
|
* browser window loads. The Studio's library read sets it too (server.js), as does GET /api/page-session.
|
|
144
144
|
*/
|
|
145
|
-
export const PAGE_SECRET_PATHS = Object.freeze(['/', '/index.html', '/index2d.html', '/onboarding.html', '/sidepanel-session.html']);
|
|
145
|
+
export const PAGE_SECRET_PATHS = Object.freeze(['/', '/index.html', '/index2d.html', '/onboarding.html', '/sidepanel-session.html', '/extension-setup']);
|
|
146
146
|
/** The route an open tab asks for this boot's cookie after a restart (public/shared/page-session.js). */
|
|
147
147
|
export const PAGE_SECRET_REFRESH_PATH = '/api/page-session';
|
|
148
148
|
/** The app's service worker (public/sw.js): a browser that may not hold the secret gets SERVICE_WORKER_NOOP instead. */
|