synabun 2.4.1 → 2.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +50 -0
- package/README.md +1 -1
- package/docs/browser-extension-bridge.md +46 -6
- package/lib/data-home-files.js +4 -2
- package/lib/first-launch-protection.js +8 -2
- package/lib/release-npm-ci.mjs +23 -1
- package/lib/update-snapshot.js +11 -4
- package/mcp-server/dist/http.d.ts.map +1 -1
- package/mcp-server/dist/http.js +25 -2
- package/mcp-server/dist/http.js.map +1 -1
- package/mcp-server/dist/index.d.ts.map +1 -1
- package/mcp-server/dist/index.js +62 -17
- package/mcp-server/dist/index.js.map +1 -1
- package/mcp-server/dist/services/browser-bench.d.ts +22 -22
- package/mcp-server/dist/services/memory-maintenance.d.ts +1 -0
- package/mcp-server/dist/services/memory-maintenance.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-maintenance.js +34 -45
- package/mcp-server/dist/services/memory-maintenance.js.map +1 -1
- package/mcp-server/dist/services/memory-migration-copy.d.ts +144 -0
- package/mcp-server/dist/services/memory-migration-copy.d.ts.map +1 -0
- package/mcp-server/dist/services/memory-migration-copy.js +467 -0
- package/mcp-server/dist/services/memory-migration-copy.js.map +1 -0
- package/mcp-server/dist/services/memory-migration-worker.d.ts +2 -0
- package/mcp-server/dist/services/memory-migration-worker.d.ts.map +1 -0
- package/mcp-server/dist/services/memory-migration-worker.js +60 -0
- package/mcp-server/dist/services/memory-migration-worker.js.map +1 -0
- package/mcp-server/dist/services/memory-retrieval.d.ts +4 -0
- package/mcp-server/dist/services/memory-retrieval.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-retrieval.js +188 -40
- package/mcp-server/dist/services/memory-retrieval.js.map +1 -1
- package/mcp-server/dist/services/memory-schema.d.ts +58 -2
- package/mcp-server/dist/services/memory-schema.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-schema.js +190 -13
- package/mcp-server/dist/services/memory-schema.js.map +1 -1
- package/mcp-server/dist/services/memory-sessions.d.ts +19 -1
- package/mcp-server/dist/services/memory-sessions.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-sessions.js +56 -20
- package/mcp-server/dist/services/memory-sessions.js.map +1 -1
- package/mcp-server/dist/services/memory-verification.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-verification.js +8 -5
- package/mcp-server/dist/services/memory-verification.js.map +1 -1
- package/mcp-server/dist/services/neural-interface.d.ts +5 -0
- package/mcp-server/dist/services/neural-interface.d.ts.map +1 -1
- package/mcp-server/dist/services/neural-interface.js +19 -2
- package/mcp-server/dist/services/neural-interface.js.map +1 -1
- package/mcp-server/dist/services/retrieval-reader-worker.d.ts +2 -0
- package/mcp-server/dist/services/retrieval-reader-worker.d.ts.map +1 -0
- package/mcp-server/dist/services/retrieval-reader-worker.js +76 -0
- package/mcp-server/dist/services/retrieval-reader-worker.js.map +1 -0
- package/mcp-server/dist/services/retrieval-reader.d.ts +38 -0
- package/mcp-server/dist/services/retrieval-reader.d.ts.map +1 -0
- package/mcp-server/dist/services/retrieval-reader.js +145 -0
- package/mcp-server/dist/services/retrieval-reader.js.map +1 -0
- package/mcp-server/dist/services/sqlite-write.d.ts +14 -0
- package/mcp-server/dist/services/sqlite-write.d.ts.map +1 -0
- package/mcp-server/dist/services/sqlite-write.js +94 -0
- package/mcp-server/dist/services/sqlite-write.js.map +1 -0
- package/mcp-server/dist/services/sqlite.d.ts +39 -0
- package/mcp-server/dist/services/sqlite.d.ts.map +1 -1
- package/mcp-server/dist/services/sqlite.js +249 -8
- package/mcp-server/dist/services/sqlite.js.map +1 -1
- package/mcp-server/dist/services/tool-catalog.d.ts +1 -1
- package/mcp-server/dist/services/typesafe-config.d.ts +7 -1
- package/mcp-server/dist/services/typesafe-config.d.ts.map +1 -1
- package/mcp-server/dist/services/typesafe-config.js +32 -10
- package/mcp-server/dist/services/typesafe-config.js.map +1 -1
- package/mcp-server/dist/services/typesafe.d.ts.map +1 -1
- package/mcp-server/dist/services/typesafe.js +9 -7
- package/mcp-server/dist/services/typesafe.js.map +1 -1
- package/mcp-server/dist/services/vector-cache.d.ts +32 -0
- package/mcp-server/dist/services/vector-cache.d.ts.map +1 -1
- package/mcp-server/dist/services/vector-cache.js +161 -8
- package/mcp-server/dist/services/vector-cache.js.map +1 -1
- package/mcp-server/dist/tools/agent-definition.d.ts +2 -2
- package/mcp-server/dist/tools/agents.d.ts +11 -7
- package/mcp-server/dist/tools/agents.d.ts.map +1 -1
- package/mcp-server/dist/tools/agents.js +27 -9
- package/mcp-server/dist/tools/agents.js.map +1 -1
- package/mcp-server/dist/tools/browser-advanced.d.ts +1 -1
- package/mcp-server/dist/tools/browser-advanced.d.ts.map +1 -1
- package/mcp-server/dist/tools/browser-advanced.js +10 -3
- package/mcp-server/dist/tools/browser-advanced.js.map +1 -1
- package/mcp-server/dist/tools/browser-extension-setup.d.ts +5 -0
- package/mcp-server/dist/tools/browser-extension-setup.d.ts.map +1 -0
- package/mcp-server/dist/tools/browser-extension-setup.js +29 -0
- package/mcp-server/dist/tools/browser-extension-setup.js.map +1 -0
- package/mcp-server/dist/tools/browser-interact.d.ts.map +1 -1
- package/mcp-server/dist/tools/browser-interact.js +6 -1
- package/mcp-server/dist/tools/browser-interact.js.map +1 -1
- package/mcp-server/dist/tools/fb-groups.d.ts +2 -2
- package/mcp-server/dist/tools/skill-tools.d.ts +4 -4
- package/mcp-server/dist/tools/tool-groups.d.ts +1 -1
- package/mcp-server/package-lock.json +5 -5
- package/mcp-server/package.json +1 -1
- package/mcp-server/src/http.ts +20 -2
- package/mcp-server/src/index.ts +59 -17
- package/mcp-server/src/services/memory-maintenance.ts +31 -28
- package/mcp-server/src/services/memory-migration-copy.ts +419 -0
- package/mcp-server/src/services/memory-migration-worker.ts +55 -0
- package/mcp-server/src/services/memory-retrieval.ts +173 -32
- package/mcp-server/src/services/memory-schema.ts +194 -12
- package/mcp-server/src/services/memory-sessions.ts +54 -21
- package/mcp-server/src/services/memory-verification.ts +7 -4
- package/mcp-server/src/services/neural-interface.ts +22 -2
- package/mcp-server/src/services/retrieval-reader-worker.ts +67 -0
- package/mcp-server/src/services/retrieval-reader.ts +131 -0
- package/mcp-server/src/services/sqlite-write.ts +60 -0
- package/mcp-server/src/services/sqlite.ts +246 -8
- package/mcp-server/src/services/typesafe-config.ts +25 -6
- package/mcp-server/src/services/typesafe.ts +9 -7
- package/mcp-server/src/services/vector-cache.ts +154 -9
- package/mcp-server/src/tools/agents.ts +26 -9
- package/mcp-server/src/tools/browser-advanced.ts +10 -3
- package/mcp-server/src/tools/browser-extension-setup.ts +36 -0
- package/mcp-server/src/tools/browser-interact.ts +5 -1
- package/neural-interface/i18n/en.json +313 -2
- package/neural-interface/i18n/pt-BR.json +321 -10
- package/neural-interface/lib/agents/split.js +32 -4
- package/neural-interface/lib/assistant-api.js +52 -8
- package/neural-interface/lib/assistant-brains/claude.js +2 -0
- package/neural-interface/lib/assistant-brains/opencode.js +121 -7
- package/neural-interface/lib/assistant-catalog.js +2 -2
- package/neural-interface/lib/assistant-config.js +0 -7
- package/neural-interface/lib/assistant-dispatch.js +281 -95
- package/neural-interface/lib/assistant-envelope.js +40 -0
- package/neural-interface/lib/assistant-persona.js +16 -4
- package/neural-interface/lib/assistant-pricing.js +65 -14
- package/neural-interface/lib/assistant-router.js +131 -47
- package/neural-interface/lib/assistant-run-wait.js +45 -28
- package/neural-interface/lib/assistant-runtime.js +133 -42
- package/neural-interface/lib/backup-contents.js +158 -0
- package/neural-interface/lib/backup-crypto-io.js +330 -0
- package/neural-interface/lib/backup-crypto-worker.js +130 -0
- package/neural-interface/lib/backup-crypto.js +525 -0
- package/neural-interface/lib/backup-download.js +268 -0
- package/neural-interface/lib/backup-encryption.js +318 -0
- package/neural-interface/lib/backup-groups.js +287 -0
- package/neural-interface/lib/backup-restore-session.js +176 -0
- package/neural-interface/lib/backup-restore-stage.js +60 -0
- package/neural-interface/lib/backup-service.js +788 -233
- package/neural-interface/lib/backup-zip-reader.js +30 -18
- package/neural-interface/lib/backup-zip-writer.js +34 -10
- package/neural-interface/lib/browser-extension-adapter.js +89 -15
- package/neural-interface/lib/browser-extension-archive.js +149 -0
- package/neural-interface/lib/browser-extension-bridge.js +24 -10
- package/neural-interface/lib/browser-extension-folder.js +596 -76
- package/neural-interface/lib/browser-extension-package.js +200 -0
- package/neural-interface/lib/browser-extension-pin.js +84 -0
- package/neural-interface/lib/browser-extension-pin.json +33 -0
- package/{browser-extension/protocol.js → neural-interface/lib/browser-extension-protocol.js} +91 -6
- package/neural-interface/lib/browser-extension-setup.js +105 -18
- package/neural-interface/lib/claude-agent-bridge.js +1 -0
- package/neural-interface/lib/claude-session-cleanup.js +5 -1
- package/neural-interface/lib/cli-install.js +23 -3
- package/neural-interface/lib/cli-update-planner.js +171 -9
- package/neural-interface/lib/client-diagnostics.js +42 -0
- package/neural-interface/lib/confined-fs.js +7 -2
- package/neural-interface/lib/coordination/README.md +8 -2
- package/neural-interface/lib/coordination/contract.js +161 -0
- package/neural-interface/lib/coordination/database.js +999 -0
- package/neural-interface/lib/coordination/operations.js +436 -0
- package/neural-interface/lib/coordination/service.js +68 -537
- package/neural-interface/lib/coordination/storage-worker.js +101 -0
- package/neural-interface/lib/coordination/store.js +219 -1111
- package/neural-interface/lib/db.js +70 -32
- package/neural-interface/lib/health-count.js +37 -0
- package/neural-interface/lib/loop-stall.js +139 -0
- package/neural-interface/lib/maritaca/client.js +2 -2
- package/neural-interface/lib/maritaca/models.js +12 -17
- package/neural-interface/lib/maritaca/opencode.js +4 -2
- package/neural-interface/lib/memory-api.js +9 -1
- package/neural-interface/lib/memory-session-capture.js +42 -10
- package/neural-interface/lib/memory-store-gate.js +313 -0
- package/neural-interface/lib/memory-store-migrate.js +65 -0
- package/neural-interface/lib/memory-timers.js +7 -7
- package/neural-interface/lib/native-loop-providers.js +23 -17
- package/neural-interface/lib/native-loop-runtime.js +48 -9
- package/neural-interface/lib/opencode-build-preflight.js +18 -1
- package/neural-interface/lib/opencode-native-boundary.js +69 -8
- package/neural-interface/lib/opencode-provider-view.js +14 -3
- package/neural-interface/lib/opencode-shell-read.js +107 -0
- package/neural-interface/lib/opencode-stop-failures.js +40 -0
- package/neural-interface/lib/opencode-turn-release.js +173 -0
- package/neural-interface/lib/opencode-v2-client.js +4 -1
- package/neural-interface/lib/opencode-v2-ws-requests.js +65 -1
- package/neural-interface/lib/opencode2-client.js +343 -7
- package/neural-interface/lib/opencode2-translate.js +161 -4
- package/neural-interface/lib/recall-impact.js +122 -0
- package/neural-interface/lib/scratch-evidence.js +420 -0
- package/neural-interface/lib/scratch-process-guard.js +139 -0
- package/neural-interface/lib/scratch-references.js +279 -0
- package/neural-interface/lib/scratch-retention-core.js +385 -0
- package/neural-interface/lib/scratch-retention-worker.js +37 -0
- package/neural-interface/lib/scratch-retention.js +151 -0
- package/neural-interface/lib/session-cache-builder.js +31 -43
- package/neural-interface/lib/session-cache-worker.js +157 -0
- package/neural-interface/lib/session-indexer.js +28 -21
- package/neural-interface/lib/session-search-index.js +85 -0
- package/neural-interface/lib/skills/creation.js +1 -1
- package/neural-interface/lib/sqlite-integrity-worker.js +3 -1
- package/neural-interface/lib/style-guide/store.js +43 -3
- package/neural-interface/lib/system-restore.js +50 -0
- package/neural-interface/lib/teams/api.js +15 -6
- package/neural-interface/lib/teams/claims.js +67 -31
- package/neural-interface/lib/teams/index.js +7 -7
- package/neural-interface/lib/teams/integration.js +40 -40
- package/neural-interface/lib/teams/landing.js +6 -6
- package/neural-interface/lib/teams/recovery.js +24 -23
- package/neural-interface/lib/teams/scheduler.js +194 -95
- package/neural-interface/lib/teams/state.js +14 -14
- package/neural-interface/lib/teams/worktrees.js +27 -27
- package/neural-interface/lib/terminal-token-redaction.js +83 -0
- package/neural-interface/lib/whatsapp/bridge.js +54 -7
- package/neural-interface/lib/worker-confinement.js +47 -2
- package/neural-interface/lib/worker-mcp-channel.js +2 -0
- package/neural-interface/lib/worker-resume.js +5 -0
- package/neural-interface/lib/worker-stop.js +86 -0
- package/neural-interface/package-lock.json +5 -5
- package/neural-interface/package.json +1 -1
- package/neural-interface/public/extension-setup.html +5 -2
- package/neural-interface/public/index.html +233 -24
- package/neural-interface/public/onboarding.html +259 -34
- package/neural-interface/public/shared/agents/studio/ax-library.js +0 -6
- package/neural-interface/public/shared/agents/studio/ax-main.js +14 -7
- package/neural-interface/public/shared/agy/agy-options.js +11 -0
- package/neural-interface/public/shared/agy/agy-panel.js +67 -20
- package/neural-interface/public/shared/agy/agy-styles.js +14 -12
- package/neural-interface/public/shared/agy/agy-tabs-logic.js +4 -1
- package/neural-interface/public/shared/api.js +1 -1
- package/neural-interface/public/shared/assistant/asst-api.js +28 -3
- package/neural-interface/public/shared/assistant/asst-brain-picker.js +13 -6
- package/neural-interface/public/shared/assistant/asst-control.js +2 -0
- package/neural-interface/public/shared/assistant/asst-motion-gate.js +78 -4
- package/neural-interface/public/shared/assistant/asst-panel.js +87 -3
- package/neural-interface/public/shared/assistant/asst-rack-styles.js +27 -0
- package/neural-interface/public/shared/assistant/asst-render.js +243 -44
- package/neural-interface/public/shared/assistant/asst-route.js +100 -21
- package/neural-interface/public/shared/assistant/asst-routes-editor.js +1 -1
- package/neural-interface/public/shared/assistant/asst-shell-logic.js +200 -0
- package/neural-interface/public/shared/assistant/asst-shell.js +111 -0
- package/neural-interface/public/shared/assistant/asst-sidepanel.js +4 -2
- package/neural-interface/public/shared/assistant/asst-state.js +11 -0
- package/neural-interface/public/shared/assistant/asst-styles.js +11 -23
- package/neural-interface/public/shared/assistant/route-identity.js +2 -1
- package/neural-interface/public/shared/cdx/cdx-render.js +9 -0
- package/neural-interface/public/shared/cdx/cdx-settings.js +3 -1
- package/neural-interface/public/shared/cdx/cdx-styles.js +6 -0
- package/neural-interface/public/shared/cdx/cdx-tabs.js +54 -9
- package/neural-interface/public/shared/client-diagnostics.js +94 -0
- package/neural-interface/public/shared/cp/cp-markdown.js +7 -2
- package/neural-interface/public/shared/cp/cp-styles.js +1 -1
- package/neural-interface/public/shared/effort-i18n.js +118 -0
- package/neural-interface/public/shared/extension-setup/es-page.js +10 -4
- package/neural-interface/public/shared/extension-setup/es-view.js +25 -10
- package/neural-interface/public/shared/html-shell.js +4 -52
- package/neural-interface/public/shared/loading-diagnostic-entry.js +64 -0
- package/neural-interface/public/shared/memory-store-wait.js +52 -0
- package/neural-interface/public/shared/morelogin-profile-field.js +1 -1
- package/neural-interface/public/shared/mtc/mtc-logic.js +2 -1
- package/neural-interface/public/shared/mtc/mtc-panel.js +25 -3
- package/neural-interface/public/shared/mtc/mtc-styles.js +13 -12
- package/neural-interface/public/shared/ocp-v2/ocp-v2-childpanel.js +7 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-events.js +5 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-location-logic.js +109 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-manager.js +1 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-modelpicker.js +8 -1
- package/neural-interface/public/shared/ocp-v2/ocp-v2-panel.js +152 -8
- package/neural-interface/public/shared/ocp-v2/ocp-v2-rehydrate.js +7 -1
- package/neural-interface/public/shared/ocp-v2/ocp-v2-render.js +53 -4
- package/neural-interface/public/shared/ocp-v2/ocp-v2-send.js +52 -6
- package/neural-interface/public/shared/ocp-v2/ocp-v2-session-actions.js +22 -2
- package/neural-interface/public/shared/ocp-v2/ocp-v2-shell-block.js +165 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-shell-logic.js +346 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-shell.js +108 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-state.js +49 -3
- package/neural-interface/public/shared/ocp-v2/ocp-v2-styles.js +67 -93
- package/neural-interface/public/shared/ocp-v2/ocp-v2-tools-logic.js +20 -5
- package/neural-interface/public/shared/ocp-v2/ocp-v2-tools.js +7 -1
- package/neural-interface/public/shared/ocp-v2/ocp-v2-variantpicker.js +17 -6
- package/neural-interface/public/shared/ocp-v2/ocp-v2-ws.js +7 -2
- package/neural-interface/public/shared/output-format.js +294 -0
- package/neural-interface/public/shared/provider-icons.js +6 -0
- package/neural-interface/public/shared/schedules-view.js +2 -1
- package/neural-interface/public/shared/server-presence.js +77 -0
- package/neural-interface/public/shared/settings/settings-backup-contents.js +241 -0
- package/neural-interface/public/shared/settings/settings-backup-download.js +298 -0
- package/neural-interface/public/shared/settings/settings-backup-encryption-pane.js +335 -0
- package/neural-interface/public/shared/settings/settings-backup-encryption.js +545 -0
- package/neural-interface/public/shared/settings/settings-browser-extension.js +54 -12
- package/neural-interface/public/shared/settings/settings-ia.js +1 -1
- package/neural-interface/public/shared/shell-stop-view.js +83 -0
- package/neural-interface/public/shared/skills/studio/sx-geometry.js +12 -3
- package/neural-interface/public/shared/skills/studio/sx-main.js +14 -7
- package/neural-interface/public/shared/studio-attention.js +6 -0
- package/neural-interface/public/shared/styles.css +341 -437
- package/neural-interface/public/shared/tour/tour-actor.js +14 -3
- package/neural-interface/public/shared/transcript-rows.js +28 -3
- package/neural-interface/public/shared/tray-auto-close.js +49 -6
- package/neural-interface/public/shared/ui-agents.js +1 -2
- package/neural-interface/public/shared/ui-automation-studio.js +168 -108
- package/neural-interface/public/shared/ui-claude-panel.js +62 -65
- package/neural-interface/public/shared/ui-loading.js +124 -17
- package/neural-interface/public/shared/ui-native-loop-router.js +52 -0
- package/neural-interface/public/shared/ui-navbar.js +2 -1
- package/neural-interface/public/shared/ui-output.js +533 -0
- package/neural-interface/public/shared/ui-schedules-studio.js +165 -128
- package/neural-interface/public/shared/ui-scroll-follow.js +101 -6
- package/neural-interface/public/shared/ui-sessions.js +2 -2
- package/neural-interface/public/shared/ui-settings-entry.js +18 -0
- package/neural-interface/public/shared/ui-settings.js +224 -65
- package/neural-interface/public/shared/ui-sidepanel-tray.js +3 -2
- package/neural-interface/public/shared/ui-tooltip.js +16 -0
- package/neural-interface/public/shared/ui-tutorial.js +5 -6
- package/neural-interface/public/shared/ui-worker-end.js +27 -8
- package/neural-interface/public/shared/worker-end.js +9 -4
- package/neural-interface/public/variant/2d/main.js +5 -0
- package/neural-interface/public/variant/3d/app.js +10 -0
- package/neural-interface/public/variant/3d/main.js +5 -1
- package/neural-interface/scripts/scratch-retention.mjs +20 -0
- package/neural-interface/server.js +725 -173
- package/npm-shrinkwrap.json +5 -5
- package/package.json +1 -2
- package/scripts/restore-data-home-from-backup.mjs +175 -8
- package/setup.js +18 -4
- package/browser-extension/content.js +0 -189
- package/browser-extension/engine.js +0 -508
- package/browser-extension/icons/icon-128.png +0 -0
- package/browser-extension/icons/icon-16.png +0 -0
- package/browser-extension/icons/icon-32.png +0 -0
- package/browser-extension/icons/icon-48.png +0 -0
- package/browser-extension/icons/status-off-16.png +0 -0
- package/browser-extension/icons/status-off-32.png +0 -0
- package/browser-extension/icons/status-off-48.png +0 -0
- package/browser-extension/icons/status-on-16.png +0 -0
- package/browser-extension/icons/status-on-32.png +0 -0
- package/browser-extension/icons/status-on-48.png +0 -0
- package/browser-extension/manifest.json +0 -56
- package/browser-extension/popup-strings.js +0 -250
- package/browser-extension/popup-view.js +0 -151
- package/browser-extension/popup.css +0 -166
- package/browser-extension/popup.html +0 -108
- package/browser-extension/popup.js +0 -359
- package/browser-extension/service-worker.js +0 -275
- package/browser-extension/setup-content.js +0 -36
- package/browser-extension/tokens.css +0 -326
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { mayEndSuspendedRun, shutdownStopReason, stampStopProvenance } from './worker-stop.js';
|
|
1
2
|
import { isolatedServeFailure } from './opencode-launch-error.js';
|
|
2
3
|
import { retainExternalRefs } from './mcp-external-servers.js';
|
|
3
4
|
import { storedToolList, toolListRecord, readStoredToolListRecord } from './tool-lists.js';
|
|
@@ -59,6 +60,7 @@ function rawDescriptor(record) {
|
|
|
59
60
|
updatedAt: record.updatedAt,
|
|
60
61
|
completedAt: record.completedAt || null,
|
|
61
62
|
stoppedReason: record.stoppedReason || null,
|
|
63
|
+
...(record.stopProvenance && { stopProvenance: record.stopProvenance }),
|
|
62
64
|
browserSessionId: record.browserSessionId || null,
|
|
63
65
|
browserTabId: record.browserTabId || null,
|
|
64
66
|
scheduleId: record.scheduleId || null,
|
|
@@ -66,6 +68,9 @@ function rawDescriptor(record) {
|
|
|
66
68
|
claimedAt: record.claimedAt || null,
|
|
67
69
|
error: record.error || null,
|
|
68
70
|
...(record.errorCode ? { errorCode: record.errorCode, offenders: record.offenders } : {}),
|
|
71
|
+
// The commands its stop could not end (an OpenCode command in the background): they may still be running, and the
|
|
72
|
+
// client keeps trying to end them (lib/opencode2-client.js abortSession force).
|
|
73
|
+
...(Array.isArray(record.abandonedCommands) && record.abandonedCommands.length ? { abandonedCommands: record.abandonedCommands } : {}),
|
|
69
74
|
version: Number(record.version) || 0,
|
|
70
75
|
// Task-mode (assistant dispatch) fields. Absent/null for classic loops so
|
|
71
76
|
// existing consumers (router, sidepanels, schedules) are unaffected.
|
|
@@ -310,6 +315,7 @@ export class NativeLoopRuntime {
|
|
|
310
315
|
record.stoppedReason = 'server_restart';
|
|
311
316
|
record.completedAt = record.completedAt || iso(this.now());
|
|
312
317
|
record.updatedAt = iso(this.now());
|
|
318
|
+
record.stopProvenance = stampStopProvenance('server_restart', record.stopProvenance, record.completedAt);
|
|
313
319
|
const state = this._readState(record.runId);
|
|
314
320
|
if (state) {
|
|
315
321
|
this._writeState(record.runId, {
|
|
@@ -318,6 +324,7 @@ export class NativeLoopRuntime {
|
|
|
318
324
|
pending: false,
|
|
319
325
|
completedAt: record.completedAt,
|
|
320
326
|
stoppedReason: 'server_restart',
|
|
327
|
+
stopProvenance: record.stopProvenance,
|
|
321
328
|
});
|
|
322
329
|
}
|
|
323
330
|
}
|
|
@@ -398,7 +405,7 @@ export class NativeLoopRuntime {
|
|
|
398
405
|
_writeTerminalState(record, patch) {
|
|
399
406
|
try {
|
|
400
407
|
const state = this._readState(record.runId);
|
|
401
|
-
if (state) this._writeState(record.runId, { ...state, ...patch });
|
|
408
|
+
if (state) this._writeState(record.runId, { ...state, ...patch, ...(record.stopProvenance && { stopProvenance: record.stopProvenance }) });
|
|
402
409
|
} catch (error) {
|
|
403
410
|
this.log(record.runId, 'native:state-write-error', error?.message || String(error));
|
|
404
411
|
}
|
|
@@ -635,6 +642,7 @@ export class NativeLoopRuntime {
|
|
|
635
642
|
setTurnState: (turnState) => this.setTurnState(runId, turnState),
|
|
636
643
|
setPendingRequests: (requests) => this.setPendingRequests(runId, requests),
|
|
637
644
|
setOutcome: (outcome) => this.setOutcome(runId, outcome),
|
|
645
|
+
noteTabClose: provenance => { if (!record.stopping) record.stopProvenance = provenance; },
|
|
638
646
|
readState: () => this._readState(runId),
|
|
639
647
|
})
|
|
640
648
|
: adapter;
|
|
@@ -788,6 +796,7 @@ export class NativeLoopRuntime {
|
|
|
788
796
|
record.status = 'interrupted';
|
|
789
797
|
record.stoppedReason = reason || record.suspendReason || 'server_restart';
|
|
790
798
|
record.completedAt = iso(this.now());
|
|
799
|
+
record.stopProvenance = stampStopProvenance(record.stoppedReason, { actor: 'server', action: 'resume_refused' }, record.completedAt);
|
|
791
800
|
if (error) record.error = scrubTokenText(String(error));
|
|
792
801
|
this._writeTerminalState(record, { active: false, pending: false, completedAt: record.completedAt, stoppedReason: record.stoppedReason, ...(error ? { error: record.error } : {}) });
|
|
793
802
|
this._releaseRuntimeRefs(record);
|
|
@@ -815,8 +824,10 @@ export class NativeLoopRuntime {
|
|
|
815
824
|
try { await record.adapter?.dispose?.({ preserveSession: true, terminate: true }); } catch {}
|
|
816
825
|
// A suspended run has no process: nothing may act as it until its resume gives the new process a new token.
|
|
817
826
|
try { this.terminalTokens?.revoke?.(runId); } catch { /* the suspension goes on */ }
|
|
818
|
-
this._releaseRuntimeRefs(record, { turnState: 'suspended' });
|
|
819
827
|
record.stopping = false;
|
|
828
|
+
// A person stopped it while its CLI was ending: that stop already ended the record.
|
|
829
|
+
if (record.status !== 'suspended') return true;
|
|
830
|
+
this._releaseRuntimeRefs(record, { turnState: 'suspended' });
|
|
820
831
|
this._emit('sidepanel:run-updated', record, { reason: 'suspended' });
|
|
821
832
|
return true;
|
|
822
833
|
}
|
|
@@ -924,6 +935,21 @@ export class NativeLoopRuntime {
|
|
|
924
935
|
}
|
|
925
936
|
}
|
|
926
937
|
|
|
938
|
+
/**
|
|
939
|
+
* The adapter's abort, for a run that is ending. An OpenCode adapter answers `{ abandoned: [{ id, command }] }` when
|
|
940
|
+
* a command in the background could not be ended (its stop forces, lib/native-loop-providers.js): the run keeps
|
|
941
|
+
* them (`abandonedCommands`, in its descriptor and its state file), so its result and its tab can say so.
|
|
942
|
+
*/
|
|
943
|
+
async _abortAdapter(record, reason) {
|
|
944
|
+
let answer;
|
|
945
|
+
try { answer = await record.adapter?.abort?.(reason); } catch { return; }
|
|
946
|
+
const abandoned = Array.isArray(answer?.abandoned) ? answer.abandoned.filter((shell) => shell && (shell.command || shell.id)) : [];
|
|
947
|
+
if (!abandoned.length) return;
|
|
948
|
+
record.abandonedCommands = abandoned.slice(0, 20).map((shell) => ({ id: String(shell.id || ''), command: String(shell.command || '').slice(0, 200) }));
|
|
949
|
+
this.log(record.runId, 'native:stop-abandoned', 'its stop could not end a command in the background: it may still be running, and SynaBun keeps trying to end it', { count: abandoned.length });
|
|
950
|
+
this._writeTerminalState(record, { abandonedCommands: record.abandonedCommands });
|
|
951
|
+
}
|
|
952
|
+
|
|
927
953
|
_releaseRuntimeRefs(record, { turnState = 'terminal' } = {}) {
|
|
928
954
|
if (!record) return;
|
|
929
955
|
record.adapter = null;
|
|
@@ -963,11 +989,12 @@ export class NativeLoopRuntime {
|
|
|
963
989
|
if (error?.code) { const safe = isolatedServeFailure(error); record.errorCode = safe.code; record.offenders = safe.offenders; }
|
|
964
990
|
record.stoppedReason = reason;
|
|
965
991
|
record.completedAt = iso(this.now());
|
|
992
|
+
if (record.status === 'interrupted') record.stopProvenance = stampStopProvenance(reason, null, record.completedAt);
|
|
966
993
|
if (record._resolveIdentity) { record._resolveIdentity(null); record._resolveIdentity = null; }
|
|
967
994
|
try { record.startupAbortController?.abort(reason); } catch {}
|
|
968
995
|
if (record._cancelStartup) { record._cancelStartup(reason); record._cancelStartup = null; }
|
|
969
996
|
this._writeTerminalState(record, { active: false, pending: false, completedAt: record.completedAt, stoppedReason: reason, error: record.error, errorCode: record.errorCode, offenders: record.offenders });
|
|
970
|
-
|
|
997
|
+
await this._abortAdapter(record, reason);
|
|
971
998
|
try { await record.adapter?.dispose?.({ preserveSession: true }); } catch {}
|
|
972
999
|
this._releaseRuntimeRefs(record);
|
|
973
1000
|
this._emit(record.status === 'interrupted' ? 'sidepanel:run-stopped' : 'sidepanel:run-failed', record);
|
|
@@ -976,11 +1003,22 @@ export class NativeLoopRuntime {
|
|
|
976
1003
|
|
|
977
1004
|
/**
|
|
978
1005
|
* `terminate` (a server shutdown): the provider's process is ended at once (the Claude adapter's dispose), never
|
|
979
|
-
* left to finish its tool call after the server is gone. A suspended run (waiting for its resume) ends as stopped
|
|
1006
|
+
* left to finish its tool call after the server is gone. A suspended run (waiting for its resume) ends as stopped
|
|
1007
|
+
* only for a caller that may end it (worker-stop.js mayEndSuspendedRun); for any other this returns false and it
|
|
1008
|
+
* stays suspended. A caller that names no reason is recorded as unknown, never as the user.
|
|
980
1009
|
*/
|
|
981
|
-
async stop(runId, reason = '
|
|
1010
|
+
async stop(runId, reason = 'unknown', { terminate = false, stopProvenance = null } = {}) {
|
|
982
1011
|
const record = this.records.get(runId);
|
|
983
|
-
if (record
|
|
1012
|
+
if (!record || !LIVE_STATUSES.has(record.status)) return false;
|
|
1013
|
+
// `stopping` on a suspended record is its CLI still ending: a person's stop in that moment counts.
|
|
1014
|
+
if (record.stopping && record.status !== 'suspended') return false;
|
|
1015
|
+
const provenance = stampStopProvenance(reason, stopProvenance, iso(this.now()));
|
|
1016
|
+
if (record.status === 'suspended' && !mayEndSuspendedRun(provenance)) {
|
|
1017
|
+
this.log(runId, 'native:stop-refused', 'a suspended run stays suspended: this caller may not end it', { reason, stopProvenance: provenance });
|
|
1018
|
+
return false;
|
|
1019
|
+
}
|
|
1020
|
+
record.stopProvenance = provenance;
|
|
1021
|
+
if (record.status === 'suspended') {
|
|
984
1022
|
this._clearHold(record);
|
|
985
1023
|
record.status = 'stopped';
|
|
986
1024
|
record.stoppedReason = reason;
|
|
@@ -991,7 +1029,6 @@ export class NativeLoopRuntime {
|
|
|
991
1029
|
try { await this.onFinish(cleanDescriptor(record)); } catch {}
|
|
992
1030
|
return true;
|
|
993
1031
|
}
|
|
994
|
-
if (!record || !['starting', 'running'].includes(record.status) || record.stopping) return false;
|
|
995
1032
|
record.stopping = true;
|
|
996
1033
|
clearTimeout(record.timer);
|
|
997
1034
|
record.status = 'stopped';
|
|
@@ -1001,7 +1038,7 @@ export class NativeLoopRuntime {
|
|
|
1001
1038
|
try { record.startupAbortController?.abort(reason); } catch {}
|
|
1002
1039
|
if (record._cancelStartup) { record._cancelStartup(reason); record._cancelStartup = null; }
|
|
1003
1040
|
this._writeTerminalState(record, { active: false, pending: false, completedAt: record.completedAt, stoppedReason: reason });
|
|
1004
|
-
|
|
1041
|
+
await this._abortAdapter(record, reason);
|
|
1005
1042
|
try { await record.adapter?.dispose?.({ preserveSession: true, ...(terminate ? { terminate: true } : {}) }); } catch {}
|
|
1006
1043
|
this._releaseRuntimeRefs(record);
|
|
1007
1044
|
this._emit('sidepanel:run-stopped', record);
|
|
@@ -1134,7 +1171,9 @@ export class NativeLoopRuntime {
|
|
|
1134
1171
|
const kept = new Set((Array.isArray(keep) ? keep : []).map(String));
|
|
1135
1172
|
await Promise.allSettled([...this.records.values()]
|
|
1136
1173
|
.filter((record) => ['starting', 'running'].includes(record.status))
|
|
1137
|
-
.map((record) => (kept.has(record.runId)
|
|
1174
|
+
.map((record) => (kept.has(record.runId)
|
|
1175
|
+
? this.suspend(record.runId, reason)
|
|
1176
|
+
: this.stop(record.runId, shutdownStopReason(reason), { terminate: true, stopProvenance: { actor: 'server', action: 'shutdown', cause: String(reason) } }))));
|
|
1138
1177
|
for (const timer of this._holdTimers.values()) clearTimeout(timer);
|
|
1139
1178
|
this._holdTimers.clear();
|
|
1140
1179
|
this._persistLedger({ force: true });
|
|
@@ -45,7 +45,9 @@ export async function reconcilePreflightProfiles(profiles, list, { requested = [
|
|
|
45
45
|
log('MoreLogin local API unavailable (MORELOGIN_UNREACHABLE) and no MoreLogin browser processes found; continuing OpenCode build verification without profile port exclusions. Native browser attachment still requires verified serves.');
|
|
46
46
|
return [];
|
|
47
47
|
}
|
|
48
|
-
|
|
48
|
+
// `transient`: the read got no answer (a deadline, a reset), which says nothing about the profiles.
|
|
49
|
+
throw Object.assign(profileError('MORELOGIN_LIST_UNREADABLE', `MoreLogin profile listing failed: ${moreLoginFailureDetail(error)}. OpenCode build verification has not started.`),
|
|
50
|
+
{ transient: error?.code === 'MORELOGIN_UNREACHABLE' });
|
|
49
51
|
}
|
|
50
52
|
if (!Array.isArray(live) || live.moreloginError || live.some(p => !p?.id)) throw profileError('MORELOGIN_LIST_UNREADABLE', 'MoreLogin profile listing is malformed or incomplete.');
|
|
51
53
|
const byId = new Map(live.map(p => [String(p.id), p]));
|
|
@@ -58,6 +60,21 @@ export async function reconcilePreflightProfiles(profiles, list, { requested = [
|
|
|
58
60
|
});
|
|
59
61
|
}
|
|
60
62
|
|
|
63
|
+
/**
|
|
64
|
+
* OpenCode's start at server boot. A MoreLogin read that got no answer while the server is still busy starting is no
|
|
65
|
+
* verdict: the start is tried again once things settle, a bounded number of times. Each try is a whole start with its
|
|
66
|
+
* own single bounded read, and no start lock is held while waiting. Any other refusal stands at once.
|
|
67
|
+
*/
|
|
68
|
+
export async function startOpencodeAtBoot(start, lastRefusal, { attempts = 2, delayMs = 5000,
|
|
69
|
+
wait = (ms) => new Promise((done) => setTimeout(done, ms)) } = {}) {
|
|
70
|
+
let ready = await start();
|
|
71
|
+
for (let attempt = 0; !ready && attempt < attempts && lastRefusal()?.transient === true; attempt += 1) {
|
|
72
|
+
await wait(delayMs);
|
|
73
|
+
ready = await start();
|
|
74
|
+
}
|
|
75
|
+
return ready;
|
|
76
|
+
}
|
|
77
|
+
|
|
61
78
|
export async function preflightExcludedPorts(profiles, readDetail) {
|
|
62
79
|
const ports = new Set();
|
|
63
80
|
for (const profile of profiles) {
|
|
@@ -47,6 +47,11 @@ export const NATIVE_SERVE_MIN_VERSION = '2.1.0';
|
|
|
47
47
|
export const NATIVE_WATCH_MS = 15_000;
|
|
48
48
|
// How long a watch pass waits for a foreign serve that failed only by not answering to be confirmed gone (ensureWatch).
|
|
49
49
|
export const NATIVE_EXIT_GRACE_MS = 3_000;
|
|
50
|
+
// How long a foreign serve that passed keeps its verdict while its executable cannot be asked its version (a check
|
|
51
|
+
// that could not run on a busy machine, not a finding about the serve), counted from the last version that was read.
|
|
52
|
+
export const NATIVE_VERSION_GRACE_MS = 60_000;
|
|
53
|
+
// How long a watch pass waits for a look that is still under way before it treats "not finished" as a failure.
|
|
54
|
+
export const NATIVE_CHECK_PATIENCE_MS = 20_000;
|
|
50
55
|
|
|
51
56
|
/** "2.3.0", "v2.3.0", "opencode v2.3.0" → "2.3.0"; null for anything else (a prerelease, four parts, extra words). */
|
|
52
57
|
export function nativeServeVersionOf(version) {
|
|
@@ -292,14 +297,27 @@ const sameIdentity = (a, b) => (!a && !b) || (!!a && !!b && a.realpath === b.rea
|
|
|
292
297
|
// No shell, no server launch and bounded output/time. A foreign listener's version is not public over HTTP when
|
|
293
298
|
// its authentication works; ask the executable the OS identified instead. Interpreters cannot identify the script
|
|
294
299
|
// they run this way, so those foreign serves fail closed rather than treating `node --version` as OpenCode.
|
|
295
|
-
|
|
300
|
+
// How long `--version` of an OpenCode executable may take: a first, quick try, then one patient one. The quick limit
|
|
301
|
+
// alone failed healthy checks: on 2026-11-21 a server whose loop was held for 2.8 s (and whose disk was busy with a
|
|
302
|
+
// backup) could not read a version in 2 s, and the serve it belonged to cost a live browser context.
|
|
303
|
+
export const NATIVE_VERSION_TIMEOUTS_MS = Object.freeze([2_000, 10_000]);
|
|
304
|
+
|
|
305
|
+
export function readOpencodeBinaryVersion(identity, { run = execFile, timeouts = NATIVE_VERSION_TIMEOUTS_MS } = {}) {
|
|
296
306
|
if (!identity?.native || !isOpencodePath(identity.realpath)) return Promise.resolve(null);
|
|
297
|
-
|
|
307
|
+
const once = (timeout) => new Promise((resolve) => {
|
|
298
308
|
try {
|
|
299
|
-
run(identity.realpath, ['--version'], { timeout
|
|
309
|
+
run(identity.realpath, ['--version'], { timeout, maxBuffer: 16_384, windowsHide: true },
|
|
300
310
|
(error, stdout) => resolve(error ? null : nativeServeVersionOf(stdout)?.text || null));
|
|
301
311
|
} catch { resolve(null); }
|
|
302
312
|
});
|
|
313
|
+
// An answer that is not a version is tried again too: a timer that fired late cuts the output off.
|
|
314
|
+
return (async () => {
|
|
315
|
+
for (const timeout of timeouts) {
|
|
316
|
+
const version = await once(timeout);
|
|
317
|
+
if (version) return version;
|
|
318
|
+
}
|
|
319
|
+
return null;
|
|
320
|
+
})();
|
|
303
321
|
}
|
|
304
322
|
const INTERPRETER = /^(?:node|nodejs|bun|deno)(?:\.exe)?$/i;
|
|
305
323
|
const exited = (proc) => !proc || proc.exitCode != null || proc.signalCode != null;
|
|
@@ -314,7 +332,8 @@ export function createNativeServeBoundary({ probe = probeOpencodeServe, identify
|
|
|
314
332
|
scan = scanOpencodeServes, readGeneration = readServeGeneration, portListeners = listPortListenersAsync, pidAlive = pidExists,
|
|
315
333
|
signalPid = (pid, signal) => process.kill(pid, signal), revoke = revokeNativeContext, platform = process.platform,
|
|
316
334
|
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,
|
|
335
|
+
watchMs = NATIVE_WATCH_MS, exitGraceMs = NATIVE_EXIT_GRACE_MS, exitPollMs = 250, versionGraceMs = NATIVE_VERSION_GRACE_MS,
|
|
336
|
+
checkPatienceMs = NATIVE_CHECK_PATIENCE_MS, preflight = null, log = () => {} } = {}) {
|
|
318
337
|
const processes = new Map();
|
|
319
338
|
// Process-local admission evidence: persisted diagnostic verdicts and ordinary runtime passes cannot grant it.
|
|
320
339
|
const builds = new Map(), buildChecks = new Map();
|
|
@@ -499,7 +518,18 @@ export function createNativeServeBoundary({ probe = probeOpencodeServe, identify
|
|
|
499
518
|
// and a version change must invalidate the verdict even when those two fields stayed the same.
|
|
500
519
|
const cacheKey = identity && policy.ok ? `${key}|${serve.executable}|${binaryKey(identity, policy.version)}` : null;
|
|
501
520
|
const v = rec?.verdict;
|
|
502
|
-
|
|
521
|
+
// The executable gave no version at all (readVersion already tried twice): a check that could not run, which says
|
|
522
|
+
// nothing about the serve. One that passed as this very process (the key) started from this very file keeps its
|
|
523
|
+
// verdict for `versionGraceMs` since its version was last read; after that it fails as any unreadable version.
|
|
524
|
+
if (identity && version == null && v?.ok && sameIdentity(identity, rec.identity) && now() - (rec.versionAt || 0) < versionGraceMs) {
|
|
525
|
+
if (!rec.versionLate) log(`OpenCode serve pid ${serve.pid} (${serve.executable || '?'}), not started by SynaBun: its executable did not answer --version in time; the verdict it passed with is kept for up to ${Math.round(versionGraceMs / 1000)} s while it is asked again`);
|
|
526
|
+
rec.versionLate = true;
|
|
527
|
+
return v;
|
|
528
|
+
}
|
|
529
|
+
if (cacheKey && rec?.cacheKey === cacheKey && v && now() - v.at < foreignTtlMs && !(v.transient && now() - v.at >= retryMs)) {
|
|
530
|
+
if (v.ok) { rec.versionAt = now(); rec.versionLate = false; }
|
|
531
|
+
return v;
|
|
532
|
+
}
|
|
503
533
|
if (!rec) { rec = { serve, verdict: null, probing: null }; foreign.verdicts.set(key, rec); }
|
|
504
534
|
rec.serve = serve;
|
|
505
535
|
rec.cacheKey = cacheKey;
|
|
@@ -537,6 +567,10 @@ export function createNativeServeBoundary({ probe = probeOpencodeServe, identify
|
|
|
537
567
|
verdict.version = policy.version;
|
|
538
568
|
verdict.checks.push(...extra);
|
|
539
569
|
rec.verdict = verdict;
|
|
570
|
+
// What a later pass may lean on when the executable cannot be asked (versionGraceMs): the file and the moment.
|
|
571
|
+
rec.identity = verdict.ok ? identity : null;
|
|
572
|
+
rec.versionAt = verdict.ok ? now() : 0;
|
|
573
|
+
rec.versionLate = false;
|
|
540
574
|
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
575
|
return verdict;
|
|
542
576
|
})().finally(() => { rec.probing = null; });
|
|
@@ -647,15 +681,42 @@ export function createNativeServeBoundary({ probe = probeOpencodeServe, identify
|
|
|
647
681
|
}
|
|
648
682
|
}
|
|
649
683
|
|
|
684
|
+
// A watch pass that is only late: its look is still under way (lsof, --version or a probe on a busy machine), or the
|
|
685
|
+
// list of listening processes could not be read once. Neither is a finding. The pass waits for the look, bounded by
|
|
686
|
+
// `checkPatienceMs` in all, and reads the list once more; what is still unfinished or unreadable then is revoked as
|
|
687
|
+
// before (fail closed). A finished look that found something is never waited on.
|
|
688
|
+
const onlyChecking = (list) => list.length > 0 && list.every((o) => o.reason === 'foreign-checking');
|
|
689
|
+
async function settledForeignOffenders() {
|
|
690
|
+
const end = now() + Math.max(0, checkPatienceMs);
|
|
691
|
+
let rescanned = false;
|
|
692
|
+
for (;;) {
|
|
693
|
+
if (foreign.result && !foreign.result.ok && !foreign.scanning) {
|
|
694
|
+
if (rescanned || now() >= end) return { scanFailed: true, bad: [] };
|
|
695
|
+
rescanned = true;
|
|
696
|
+
await within(refreshForeign(), Math.max(1, end - now()));
|
|
697
|
+
continue;
|
|
698
|
+
}
|
|
699
|
+
const bad = foreignOffenders(new Set());
|
|
700
|
+
if (!onlyChecking(bad) || now() >= end) return { scanFailed: !foreign.result?.ok && !foreign.scanning, bad };
|
|
701
|
+
const pending = [foreign.scanning, ...[...foreign.verdicts.values()].map((rec) => rec.probing)].filter(Boolean);
|
|
702
|
+
await within(pending.length ? Promise.allSettled(pending) : defaultSleep(exitPollMs), Math.max(1, Math.min(end - now(), pending.length ? end - now() : exitPollMs)));
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
let watching = false;
|
|
650
707
|
function ensureWatch() {
|
|
651
708
|
if (watchTimer || !(watchMs > 0)) return;
|
|
652
709
|
watchTimer = setInterval(() => {
|
|
653
710
|
if (!attachedContexts().length) { clearInterval(watchTimer); watchTimer = null; return; }
|
|
711
|
+
// One pass at a time: a patient pass must not be overtaken by the next tick's impatient one.
|
|
712
|
+
if (watching) return;
|
|
713
|
+
watching = true;
|
|
654
714
|
refresh().then(async () => {
|
|
655
|
-
|
|
656
|
-
|
|
715
|
+
const settled = await settledForeignOffenders();
|
|
716
|
+
if (settled.scanFailed) { revokeAll('the OpenCode listening processes could not be verified'); return; }
|
|
717
|
+
const bad = await withoutExitingForeign(settled.bad);
|
|
657
718
|
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(() => {});
|
|
719
|
+
}).catch(() => {}).finally(() => { watching = false; });
|
|
659
720
|
}, watchMs);
|
|
660
721
|
watchTimer.unref?.();
|
|
661
722
|
}
|
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
// out what none of them reads (credentials and request options included).
|
|
11
11
|
// Pure: no I/O, so the route, the catalog's in-process read and the tests share it.
|
|
12
12
|
|
|
13
|
+
import { applyOpencodeCostOverride } from './assistant-pricing.js';
|
|
14
|
+
|
|
13
15
|
const PROVIDER_FIELDS_LEFT_OUT = new Set(['env', 'options', 'key', 'npm', 'api']);
|
|
14
16
|
const MODEL_FIELDS_LEFT_OUT = new Set(['options', 'headers', 'provider']);
|
|
15
17
|
|
|
@@ -24,20 +26,29 @@ function providersOf(data) {
|
|
|
24
26
|
return data?.all && typeof data.all === 'object' ? Object.values(data.all) : [];
|
|
25
27
|
}
|
|
26
28
|
|
|
27
|
-
function slimModel(model) {
|
|
29
|
+
function slimModel(model, providerId = null, modelId = null) {
|
|
28
30
|
if (!model || typeof model !== 'object') return model;
|
|
29
31
|
const out = {};
|
|
30
32
|
for (const [key, value] of Object.entries(model)) if (!MODEL_FIELDS_LEFT_OUT.has(key)) out[key] = value;
|
|
33
|
+
const pid = providerId || model.providerID || null;
|
|
34
|
+
const mid = model.id || model.modelID || modelId || null;
|
|
35
|
+
// Like the catalog and the OpenCode 2 client: an overridden model gets its price even when the
|
|
36
|
+
// upstream row has no cost; a row with neither keeps no cost key.
|
|
37
|
+
if (pid && mid) {
|
|
38
|
+
const cost = applyOpencodeCostOverride(pid, mid, out.cost);
|
|
39
|
+
if (cost !== undefined) out.cost = cost;
|
|
40
|
+
}
|
|
31
41
|
return out;
|
|
32
42
|
}
|
|
33
43
|
|
|
34
44
|
function slimProvider(provider) {
|
|
35
45
|
const out = {};
|
|
46
|
+
const pid = provider?.id || provider?.providerID || null;
|
|
36
47
|
for (const [key, value] of Object.entries(provider || {})) {
|
|
37
48
|
if (PROVIDER_FIELDS_LEFT_OUT.has(key)) continue;
|
|
38
49
|
if (key === 'models') {
|
|
39
|
-
if (Array.isArray(value)) out.models = value.map(slimModel);
|
|
40
|
-
else if (value && typeof value === 'object') out.models = Object.fromEntries(Object.entries(value).map(([id, model]) => [id, slimModel(model)]));
|
|
50
|
+
if (Array.isArray(value)) out.models = value.map((model) => slimModel(model, pid));
|
|
51
|
+
else if (value && typeof value === 'object') out.models = Object.fromEntries(Object.entries(value).map(([id, model]) => [id, slimModel(model, pid, id)]));
|
|
41
52
|
else out.models = value;
|
|
42
53
|
continue;
|
|
43
54
|
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
2
|
+
// A page of what a shell command of OpenCode 2 printed
|
|
3
|
+
//
|
|
4
|
+
// OpenCode 2 keeps a command's combined stdout and stderr, in the order
|
|
5
|
+
// written, and answers pages of it by byte position while the command runs and
|
|
6
|
+
// after (GET /api/shell/:id/output, lib/opencode2-client.js `shell.output`).
|
|
7
|
+
// The OpenCode side panel (`shell:output`, lib/opencode-v2-ws-requests.js) and
|
|
8
|
+
// the Assistant's OpenCode brain (lib/assistant-brains/opencode.js) both read
|
|
9
|
+
// it through here, so a page means the same in both: at most
|
|
10
|
+
// SHELL_OUTPUT_PAGE_BYTES, from a byte `cursor`, or the last `tail` bytes.
|
|
11
|
+
// Who may read which command is the caller's to decide before it asks.
|
|
12
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
13
|
+
|
|
14
|
+
import { PAGE_CONTEXT_CHARS, scrubOutputWindow } from './terminal-token-redaction.js';
|
|
15
|
+
|
|
16
|
+
/** The most one read returns. */
|
|
17
|
+
export const SHELL_OUTPUT_PAGE_BYTES = 256 * 1024;
|
|
18
|
+
|
|
19
|
+
/** The least a scrubbed page asks for: never so small that a secret could fill it. */
|
|
20
|
+
export const SHELL_OUTPUT_PAGE_MIN_BYTES = 4096;
|
|
21
|
+
|
|
22
|
+
/** How many bytes after a page are read to tell whether a secret crosses its end (more than the longest form). */
|
|
23
|
+
const LOOKAHEAD_BYTES = PAGE_CONTEXT_CHARS * 2;
|
|
24
|
+
|
|
25
|
+
/** What a reader is told when OpenCode no longer has the output. */
|
|
26
|
+
export const SHELL_OUTPUT_GONE_TEXT = 'The output of that command is no longer available.';
|
|
27
|
+
|
|
28
|
+
const wholeNumber = (value) => Math.max(0, Math.floor(Number(value) || 0));
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* `shell`: `{ output({ shellID, directory, cursor, limit }) → { status, data: { output, cursor, size } } }`
|
|
32
|
+
* (a client's `extra.shell`). `cursor`: the byte to read from; `tail`: instead, the last so many bytes (a
|
|
33
|
+
* reader that opens on a long output starts at its end). `errorText(body, fallback)` words a refusal.
|
|
34
|
+
* → `{ status, data: { output, cursor, size, truncated, from } }`, or `{ ok: false, status, error }`.
|
|
35
|
+
* A call that throws is the caller's to catch.
|
|
36
|
+
*/
|
|
37
|
+
export async function readShellOutputPage(shell, { shellID, directory, cursor, tail, limit } = {}, { errorText = (_body, fallback) => fallback } = {}) {
|
|
38
|
+
const refused = (r) => ({ ok: false, status: r.status, error: errorText(r.data, SHELL_OUTPUT_GONE_TEXT) });
|
|
39
|
+
const size = Math.min(SHELL_OUTPUT_PAGE_BYTES, Math.max(1, Math.floor(Number(limit) || SHELL_OUTPUT_PAGE_BYTES)));
|
|
40
|
+
let from = wholeNumber(cursor);
|
|
41
|
+
const last = wholeNumber(tail);
|
|
42
|
+
if (last > 0) {
|
|
43
|
+
// The size first (one byte asked for), then the page that ends at it.
|
|
44
|
+
const probe = await shell.output({ shellID, directory, cursor: 0, limit: 1 });
|
|
45
|
+
if (probe.status >= 400) return refused(probe);
|
|
46
|
+
from = Math.max(0, (Number(probe.data?.size) || 0) - Math.min(last, size));
|
|
47
|
+
}
|
|
48
|
+
const r = await shell.output({ shellID, directory, cursor: from, limit: size });
|
|
49
|
+
if (r.status >= 400) return refused(r);
|
|
50
|
+
return { status: r.status, data: { ...r.data, from } };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* A page as a reader may be given it: scrubbed of SynaBun's run secrets with what lies on both sides of it, so that
|
|
55
|
+
* the pages a reader joins never hold a secret whole (lib/terminal-token-redaction.js scrubOutputWindow). Both the
|
|
56
|
+
* OpenCode side panel (`shell:output`) and the Assistant panel (assistant-runtime.js shellOutput) read through here.
|
|
57
|
+
* `read({ cursor, limit })` → a raw page `{ status, data: { output, cursor, size } }` or a refusal. `running`: the
|
|
58
|
+
* command may still write (an end that could become a secret waits for the next page; once it ended it is masked).
|
|
59
|
+
* → `{ status, data: { output, cursor, size, from } }`, or the refusal of the read that failed (a failed look on
|
|
60
|
+
* either side is a failed page: unread, it could let part of a secret through).
|
|
61
|
+
*/
|
|
62
|
+
export async function readSafeShellOutputPage(read, { cursor, tail, limit, running = false } = {}) {
|
|
63
|
+
const bad = (r) => !r || r.ok === false || !(Number(r.status) < 400);
|
|
64
|
+
const refusal = (r) => (r && r.ok === false ? r : { ok: false, status: Number(r?.status) >= 400 ? Number(r.status) : 502, error: r?.error || 'The output could not be read.' });
|
|
65
|
+
const size = Math.min(SHELL_OUTPUT_PAGE_BYTES, Math.max(SHELL_OUTPUT_PAGE_MIN_BYTES, Math.floor(Number(limit) || SHELL_OUTPUT_PAGE_BYTES)));
|
|
66
|
+
let from = wholeNumber(cursor);
|
|
67
|
+
const last = wholeNumber(tail);
|
|
68
|
+
if (last > 0) {
|
|
69
|
+
const probe = await read({ cursor: 0, limit: 1 });
|
|
70
|
+
if (bad(probe)) return refusal(probe);
|
|
71
|
+
from = Math.max(0, (Number(probe.data?.size) || 0) - Math.min(last, size));
|
|
72
|
+
}
|
|
73
|
+
const r = await read({ cursor: from, limit: size });
|
|
74
|
+
if (bad(r)) return refusal(r);
|
|
75
|
+
const data = r.data && typeof r.data === 'object' ? r.data : {};
|
|
76
|
+
const output = typeof data.output === 'string' ? data.output : '';
|
|
77
|
+
const next = Math.max(from, Number(data.cursor) || 0);
|
|
78
|
+
let total = Math.max(next, Number(data.size) || 0);
|
|
79
|
+
const extra = data.truncated === true ? { truncated: true } : {};
|
|
80
|
+
if (!output) return { status: r.status, data: { output: '', cursor: next, size: total, from, ...extra } };
|
|
81
|
+
let before = '';
|
|
82
|
+
if (from > 0) {
|
|
83
|
+
const start = Math.max(0, from - PAGE_CONTEXT_CHARS);
|
|
84
|
+
const context = await read({ cursor: start, limit: from - start });
|
|
85
|
+
if (bad(context)) return refusal(context);
|
|
86
|
+
before = typeof context.data?.output === 'string' ? context.data.output : '';
|
|
87
|
+
}
|
|
88
|
+
let after = '';
|
|
89
|
+
let aheadEnd = next;
|
|
90
|
+
if (next < total) {
|
|
91
|
+
const ahead = await read({ cursor: next, limit: LOOKAHEAD_BYTES });
|
|
92
|
+
if (bad(ahead)) return refusal(ahead);
|
|
93
|
+
after = typeof ahead.data?.output === 'string' ? ahead.data.output : '';
|
|
94
|
+
aheadEnd = Math.max(next, Number(ahead.data?.cursor) || next);
|
|
95
|
+
total = Math.max(total, Number(ahead.data?.size) || 0);
|
|
96
|
+
}
|
|
97
|
+
// The window reaches the end of what the command printed so far: nothing follows it once the command ended.
|
|
98
|
+
const reachesEnd = aheadEnd >= total;
|
|
99
|
+
const page = scrubOutputWindow(output, { before, after, final: reachesEnd && !running });
|
|
100
|
+
const at = page.consumed <= output.length
|
|
101
|
+
? next - Buffer.byteLength(output.slice(page.consumed), 'utf8')
|
|
102
|
+
: next + Buffer.byteLength(after.slice(0, page.consumed - output.length), 'utf8');
|
|
103
|
+
const moved = Math.max(from, at);
|
|
104
|
+
// An end held back at the end of the output: nothing more to read for now, the reader asks again at its own pace.
|
|
105
|
+
if (page.held && reachesEnd) total = moved;
|
|
106
|
+
return { status: r.status, data: { output: page.text, cursor: moved, size: Math.max(moved, total), from, ...extra } };
|
|
107
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// The Stops of an OpenCode side panel turn that could not end a command in the background (server.js
|
|
2
|
+
// handleOpencodeV2Ws, message:abort): from the second one of the same turn the panel offers "Stop anyway". One
|
|
3
|
+
// counter per socket, keyed by session, each entry naming the turn it counts for (the token of
|
|
4
|
+
// `_ocpActiveSessionTurns`). An entry goes when its turn ends or is replaced (`prune`, at every turn end and every
|
|
5
|
+
// failure), when its session is deleted (`clear`) and with the socket (`clearAll`), so a long-lived socket that
|
|
6
|
+
// works many sessions keeps at most one entry per session whose turn is still on.
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* `activeTurn(sessionId)`: the token of the turn running now in that session, or null / undefined when none.
|
|
10
|
+
*/
|
|
11
|
+
export function createStopFailures({ activeTurn = () => null } = {}) {
|
|
12
|
+
const entries = new Map();
|
|
13
|
+
const current = (sid) => activeTurn(sid) ?? null;
|
|
14
|
+
/**
|
|
15
|
+
* Drop every entry whose turn is no longer the one running in its session, and every entry counted while no turn
|
|
16
|
+
* was known (a held turn whose token is gone): it could otherwise stay for good. `keep`: a session left alone.
|
|
17
|
+
*/
|
|
18
|
+
function prune(keep = null) {
|
|
19
|
+
for (const [sid, entry] of entries) {
|
|
20
|
+
if (sid === keep) continue;
|
|
21
|
+
if (entry.turn === null || current(sid) !== entry.turn) entries.delete(sid);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
/** A Stop of `sid`'s turn failed: → how many have failed for that turn so far (1 for its first). */
|
|
26
|
+
fail(sid) {
|
|
27
|
+
prune(sid);
|
|
28
|
+
const turn = current(sid);
|
|
29
|
+
const prior = entries.get(sid);
|
|
30
|
+
const count = prior && prior.turn === turn ? prior.count + 1 : 1;
|
|
31
|
+
entries.set(sid, { turn, count });
|
|
32
|
+
return count;
|
|
33
|
+
},
|
|
34
|
+
/** The session's Stop worked, or the session is gone. */
|
|
35
|
+
clear(sid) { entries.delete(sid); },
|
|
36
|
+
prune: () => prune(),
|
|
37
|
+
clearAll() { entries.clear(); },
|
|
38
|
+
get size() { return entries.size; },
|
|
39
|
+
};
|
|
40
|
+
}
|