synabun 2.4.1 → 2.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +50 -0
- package/README.md +1 -1
- package/docs/browser-extension-bridge.md +46 -6
- package/lib/data-home-files.js +4 -2
- package/lib/first-launch-protection.js +8 -2
- package/lib/release-npm-ci.mjs +23 -1
- package/lib/update-snapshot.js +11 -4
- package/mcp-server/dist/http.d.ts.map +1 -1
- package/mcp-server/dist/http.js +25 -2
- package/mcp-server/dist/http.js.map +1 -1
- package/mcp-server/dist/index.d.ts.map +1 -1
- package/mcp-server/dist/index.js +62 -17
- package/mcp-server/dist/index.js.map +1 -1
- package/mcp-server/dist/services/browser-bench.d.ts +22 -22
- package/mcp-server/dist/services/memory-maintenance.d.ts +1 -0
- package/mcp-server/dist/services/memory-maintenance.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-maintenance.js +34 -45
- package/mcp-server/dist/services/memory-maintenance.js.map +1 -1
- package/mcp-server/dist/services/memory-migration-copy.d.ts +144 -0
- package/mcp-server/dist/services/memory-migration-copy.d.ts.map +1 -0
- package/mcp-server/dist/services/memory-migration-copy.js +467 -0
- package/mcp-server/dist/services/memory-migration-copy.js.map +1 -0
- package/mcp-server/dist/services/memory-migration-worker.d.ts +2 -0
- package/mcp-server/dist/services/memory-migration-worker.d.ts.map +1 -0
- package/mcp-server/dist/services/memory-migration-worker.js +60 -0
- package/mcp-server/dist/services/memory-migration-worker.js.map +1 -0
- package/mcp-server/dist/services/memory-retrieval.d.ts +4 -0
- package/mcp-server/dist/services/memory-retrieval.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-retrieval.js +188 -40
- package/mcp-server/dist/services/memory-retrieval.js.map +1 -1
- package/mcp-server/dist/services/memory-schema.d.ts +58 -2
- package/mcp-server/dist/services/memory-schema.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-schema.js +190 -13
- package/mcp-server/dist/services/memory-schema.js.map +1 -1
- package/mcp-server/dist/services/memory-sessions.d.ts +19 -1
- package/mcp-server/dist/services/memory-sessions.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-sessions.js +56 -20
- package/mcp-server/dist/services/memory-sessions.js.map +1 -1
- package/mcp-server/dist/services/memory-verification.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-verification.js +8 -5
- package/mcp-server/dist/services/memory-verification.js.map +1 -1
- package/mcp-server/dist/services/neural-interface.d.ts +5 -0
- package/mcp-server/dist/services/neural-interface.d.ts.map +1 -1
- package/mcp-server/dist/services/neural-interface.js +19 -2
- package/mcp-server/dist/services/neural-interface.js.map +1 -1
- package/mcp-server/dist/services/retrieval-reader-worker.d.ts +2 -0
- package/mcp-server/dist/services/retrieval-reader-worker.d.ts.map +1 -0
- package/mcp-server/dist/services/retrieval-reader-worker.js +76 -0
- package/mcp-server/dist/services/retrieval-reader-worker.js.map +1 -0
- package/mcp-server/dist/services/retrieval-reader.d.ts +38 -0
- package/mcp-server/dist/services/retrieval-reader.d.ts.map +1 -0
- package/mcp-server/dist/services/retrieval-reader.js +145 -0
- package/mcp-server/dist/services/retrieval-reader.js.map +1 -0
- package/mcp-server/dist/services/sqlite-write.d.ts +14 -0
- package/mcp-server/dist/services/sqlite-write.d.ts.map +1 -0
- package/mcp-server/dist/services/sqlite-write.js +94 -0
- package/mcp-server/dist/services/sqlite-write.js.map +1 -0
- package/mcp-server/dist/services/sqlite.d.ts +39 -0
- package/mcp-server/dist/services/sqlite.d.ts.map +1 -1
- package/mcp-server/dist/services/sqlite.js +249 -8
- package/mcp-server/dist/services/sqlite.js.map +1 -1
- package/mcp-server/dist/services/tool-catalog.d.ts +1 -1
- package/mcp-server/dist/services/typesafe-config.d.ts +7 -1
- package/mcp-server/dist/services/typesafe-config.d.ts.map +1 -1
- package/mcp-server/dist/services/typesafe-config.js +32 -10
- package/mcp-server/dist/services/typesafe-config.js.map +1 -1
- package/mcp-server/dist/services/typesafe.d.ts.map +1 -1
- package/mcp-server/dist/services/typesafe.js +9 -7
- package/mcp-server/dist/services/typesafe.js.map +1 -1
- package/mcp-server/dist/services/vector-cache.d.ts +32 -0
- package/mcp-server/dist/services/vector-cache.d.ts.map +1 -1
- package/mcp-server/dist/services/vector-cache.js +161 -8
- package/mcp-server/dist/services/vector-cache.js.map +1 -1
- package/mcp-server/dist/tools/agent-definition.d.ts +2 -2
- package/mcp-server/dist/tools/agents.d.ts +11 -7
- package/mcp-server/dist/tools/agents.d.ts.map +1 -1
- package/mcp-server/dist/tools/agents.js +27 -9
- package/mcp-server/dist/tools/agents.js.map +1 -1
- package/mcp-server/dist/tools/browser-advanced.d.ts +1 -1
- package/mcp-server/dist/tools/browser-advanced.d.ts.map +1 -1
- package/mcp-server/dist/tools/browser-advanced.js +10 -3
- package/mcp-server/dist/tools/browser-advanced.js.map +1 -1
- package/mcp-server/dist/tools/browser-extension-setup.d.ts +5 -0
- package/mcp-server/dist/tools/browser-extension-setup.d.ts.map +1 -0
- package/mcp-server/dist/tools/browser-extension-setup.js +29 -0
- package/mcp-server/dist/tools/browser-extension-setup.js.map +1 -0
- package/mcp-server/dist/tools/browser-interact.d.ts.map +1 -1
- package/mcp-server/dist/tools/browser-interact.js +6 -1
- package/mcp-server/dist/tools/browser-interact.js.map +1 -1
- package/mcp-server/dist/tools/fb-groups.d.ts +2 -2
- package/mcp-server/dist/tools/skill-tools.d.ts +4 -4
- package/mcp-server/dist/tools/tool-groups.d.ts +1 -1
- package/mcp-server/package-lock.json +5 -5
- package/mcp-server/package.json +1 -1
- package/mcp-server/src/http.ts +20 -2
- package/mcp-server/src/index.ts +59 -17
- package/mcp-server/src/services/memory-maintenance.ts +31 -28
- package/mcp-server/src/services/memory-migration-copy.ts +419 -0
- package/mcp-server/src/services/memory-migration-worker.ts +55 -0
- package/mcp-server/src/services/memory-retrieval.ts +173 -32
- package/mcp-server/src/services/memory-schema.ts +194 -12
- package/mcp-server/src/services/memory-sessions.ts +54 -21
- package/mcp-server/src/services/memory-verification.ts +7 -4
- package/mcp-server/src/services/neural-interface.ts +22 -2
- package/mcp-server/src/services/retrieval-reader-worker.ts +67 -0
- package/mcp-server/src/services/retrieval-reader.ts +131 -0
- package/mcp-server/src/services/sqlite-write.ts +60 -0
- package/mcp-server/src/services/sqlite.ts +246 -8
- package/mcp-server/src/services/typesafe-config.ts +25 -6
- package/mcp-server/src/services/typesafe.ts +9 -7
- package/mcp-server/src/services/vector-cache.ts +154 -9
- package/mcp-server/src/tools/agents.ts +26 -9
- package/mcp-server/src/tools/browser-advanced.ts +10 -3
- package/mcp-server/src/tools/browser-extension-setup.ts +36 -0
- package/mcp-server/src/tools/browser-interact.ts +5 -1
- package/neural-interface/i18n/en.json +313 -2
- package/neural-interface/i18n/pt-BR.json +321 -10
- package/neural-interface/lib/agents/split.js +32 -4
- package/neural-interface/lib/assistant-api.js +52 -8
- package/neural-interface/lib/assistant-brains/claude.js +2 -0
- package/neural-interface/lib/assistant-brains/opencode.js +121 -7
- package/neural-interface/lib/assistant-catalog.js +2 -2
- package/neural-interface/lib/assistant-config.js +0 -7
- package/neural-interface/lib/assistant-dispatch.js +281 -95
- package/neural-interface/lib/assistant-envelope.js +40 -0
- package/neural-interface/lib/assistant-persona.js +16 -4
- package/neural-interface/lib/assistant-pricing.js +65 -14
- package/neural-interface/lib/assistant-router.js +131 -47
- package/neural-interface/lib/assistant-run-wait.js +45 -28
- package/neural-interface/lib/assistant-runtime.js +133 -42
- package/neural-interface/lib/backup-contents.js +158 -0
- package/neural-interface/lib/backup-crypto-io.js +330 -0
- package/neural-interface/lib/backup-crypto-worker.js +130 -0
- package/neural-interface/lib/backup-crypto.js +525 -0
- package/neural-interface/lib/backup-download.js +268 -0
- package/neural-interface/lib/backup-encryption.js +318 -0
- package/neural-interface/lib/backup-groups.js +287 -0
- package/neural-interface/lib/backup-restore-session.js +176 -0
- package/neural-interface/lib/backup-restore-stage.js +60 -0
- package/neural-interface/lib/backup-service.js +788 -233
- package/neural-interface/lib/backup-zip-reader.js +30 -18
- package/neural-interface/lib/backup-zip-writer.js +34 -10
- package/neural-interface/lib/browser-extension-adapter.js +89 -15
- package/neural-interface/lib/browser-extension-archive.js +149 -0
- package/neural-interface/lib/browser-extension-bridge.js +24 -10
- package/neural-interface/lib/browser-extension-folder.js +596 -76
- package/neural-interface/lib/browser-extension-package.js +200 -0
- package/neural-interface/lib/browser-extension-pin.js +84 -0
- package/neural-interface/lib/browser-extension-pin.json +33 -0
- package/{browser-extension/protocol.js → neural-interface/lib/browser-extension-protocol.js} +91 -6
- package/neural-interface/lib/browser-extension-setup.js +105 -18
- package/neural-interface/lib/claude-agent-bridge.js +1 -0
- package/neural-interface/lib/claude-session-cleanup.js +5 -1
- package/neural-interface/lib/cli-install.js +23 -3
- package/neural-interface/lib/cli-update-planner.js +171 -9
- package/neural-interface/lib/client-diagnostics.js +42 -0
- package/neural-interface/lib/confined-fs.js +7 -2
- package/neural-interface/lib/coordination/README.md +8 -2
- package/neural-interface/lib/coordination/contract.js +161 -0
- package/neural-interface/lib/coordination/database.js +999 -0
- package/neural-interface/lib/coordination/operations.js +436 -0
- package/neural-interface/lib/coordination/service.js +68 -537
- package/neural-interface/lib/coordination/storage-worker.js +101 -0
- package/neural-interface/lib/coordination/store.js +219 -1111
- package/neural-interface/lib/db.js +70 -32
- package/neural-interface/lib/health-count.js +37 -0
- package/neural-interface/lib/loop-stall.js +139 -0
- package/neural-interface/lib/maritaca/client.js +2 -2
- package/neural-interface/lib/maritaca/models.js +12 -17
- package/neural-interface/lib/maritaca/opencode.js +4 -2
- package/neural-interface/lib/memory-api.js +9 -1
- package/neural-interface/lib/memory-session-capture.js +42 -10
- package/neural-interface/lib/memory-store-gate.js +313 -0
- package/neural-interface/lib/memory-store-migrate.js +65 -0
- package/neural-interface/lib/memory-timers.js +7 -7
- package/neural-interface/lib/native-loop-providers.js +23 -17
- package/neural-interface/lib/native-loop-runtime.js +48 -9
- package/neural-interface/lib/opencode-build-preflight.js +18 -1
- package/neural-interface/lib/opencode-native-boundary.js +69 -8
- package/neural-interface/lib/opencode-provider-view.js +14 -3
- package/neural-interface/lib/opencode-shell-read.js +107 -0
- package/neural-interface/lib/opencode-stop-failures.js +40 -0
- package/neural-interface/lib/opencode-turn-release.js +173 -0
- package/neural-interface/lib/opencode-v2-client.js +4 -1
- package/neural-interface/lib/opencode-v2-ws-requests.js +65 -1
- package/neural-interface/lib/opencode2-client.js +343 -7
- package/neural-interface/lib/opencode2-translate.js +161 -4
- package/neural-interface/lib/recall-impact.js +122 -0
- package/neural-interface/lib/scratch-evidence.js +420 -0
- package/neural-interface/lib/scratch-process-guard.js +139 -0
- package/neural-interface/lib/scratch-references.js +279 -0
- package/neural-interface/lib/scratch-retention-core.js +385 -0
- package/neural-interface/lib/scratch-retention-worker.js +37 -0
- package/neural-interface/lib/scratch-retention.js +151 -0
- package/neural-interface/lib/session-cache-builder.js +31 -43
- package/neural-interface/lib/session-cache-worker.js +157 -0
- package/neural-interface/lib/session-indexer.js +28 -21
- package/neural-interface/lib/session-search-index.js +85 -0
- package/neural-interface/lib/skills/creation.js +1 -1
- package/neural-interface/lib/sqlite-integrity-worker.js +3 -1
- package/neural-interface/lib/style-guide/store.js +43 -3
- package/neural-interface/lib/system-restore.js +50 -0
- package/neural-interface/lib/teams/api.js +15 -6
- package/neural-interface/lib/teams/claims.js +67 -31
- package/neural-interface/lib/teams/index.js +7 -7
- package/neural-interface/lib/teams/integration.js +40 -40
- package/neural-interface/lib/teams/landing.js +6 -6
- package/neural-interface/lib/teams/recovery.js +24 -23
- package/neural-interface/lib/teams/scheduler.js +194 -95
- package/neural-interface/lib/teams/state.js +14 -14
- package/neural-interface/lib/teams/worktrees.js +27 -27
- package/neural-interface/lib/terminal-token-redaction.js +83 -0
- package/neural-interface/lib/whatsapp/bridge.js +54 -7
- package/neural-interface/lib/worker-confinement.js +47 -2
- package/neural-interface/lib/worker-mcp-channel.js +2 -0
- package/neural-interface/lib/worker-resume.js +5 -0
- package/neural-interface/lib/worker-stop.js +86 -0
- package/neural-interface/package-lock.json +5 -5
- package/neural-interface/package.json +1 -1
- package/neural-interface/public/extension-setup.html +5 -2
- package/neural-interface/public/index.html +233 -24
- package/neural-interface/public/onboarding.html +259 -34
- package/neural-interface/public/shared/agents/studio/ax-library.js +0 -6
- package/neural-interface/public/shared/agents/studio/ax-main.js +14 -7
- package/neural-interface/public/shared/agy/agy-options.js +11 -0
- package/neural-interface/public/shared/agy/agy-panel.js +67 -20
- package/neural-interface/public/shared/agy/agy-styles.js +14 -12
- package/neural-interface/public/shared/agy/agy-tabs-logic.js +4 -1
- package/neural-interface/public/shared/api.js +1 -1
- package/neural-interface/public/shared/assistant/asst-api.js +28 -3
- package/neural-interface/public/shared/assistant/asst-brain-picker.js +13 -6
- package/neural-interface/public/shared/assistant/asst-control.js +2 -0
- package/neural-interface/public/shared/assistant/asst-motion-gate.js +78 -4
- package/neural-interface/public/shared/assistant/asst-panel.js +87 -3
- package/neural-interface/public/shared/assistant/asst-rack-styles.js +27 -0
- package/neural-interface/public/shared/assistant/asst-render.js +243 -44
- package/neural-interface/public/shared/assistant/asst-route.js +100 -21
- package/neural-interface/public/shared/assistant/asst-routes-editor.js +1 -1
- package/neural-interface/public/shared/assistant/asst-shell-logic.js +200 -0
- package/neural-interface/public/shared/assistant/asst-shell.js +111 -0
- package/neural-interface/public/shared/assistant/asst-sidepanel.js +4 -2
- package/neural-interface/public/shared/assistant/asst-state.js +11 -0
- package/neural-interface/public/shared/assistant/asst-styles.js +11 -23
- package/neural-interface/public/shared/assistant/route-identity.js +2 -1
- package/neural-interface/public/shared/cdx/cdx-render.js +9 -0
- package/neural-interface/public/shared/cdx/cdx-settings.js +3 -1
- package/neural-interface/public/shared/cdx/cdx-styles.js +6 -0
- package/neural-interface/public/shared/cdx/cdx-tabs.js +54 -9
- package/neural-interface/public/shared/client-diagnostics.js +94 -0
- package/neural-interface/public/shared/cp/cp-markdown.js +7 -2
- package/neural-interface/public/shared/cp/cp-styles.js +1 -1
- package/neural-interface/public/shared/effort-i18n.js +118 -0
- package/neural-interface/public/shared/extension-setup/es-page.js +10 -4
- package/neural-interface/public/shared/extension-setup/es-view.js +25 -10
- package/neural-interface/public/shared/html-shell.js +4 -52
- package/neural-interface/public/shared/loading-diagnostic-entry.js +64 -0
- package/neural-interface/public/shared/memory-store-wait.js +52 -0
- package/neural-interface/public/shared/morelogin-profile-field.js +1 -1
- package/neural-interface/public/shared/mtc/mtc-logic.js +2 -1
- package/neural-interface/public/shared/mtc/mtc-panel.js +25 -3
- package/neural-interface/public/shared/mtc/mtc-styles.js +13 -12
- package/neural-interface/public/shared/ocp-v2/ocp-v2-childpanel.js +7 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-events.js +5 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-location-logic.js +109 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-manager.js +1 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-modelpicker.js +8 -1
- package/neural-interface/public/shared/ocp-v2/ocp-v2-panel.js +152 -8
- package/neural-interface/public/shared/ocp-v2/ocp-v2-rehydrate.js +7 -1
- package/neural-interface/public/shared/ocp-v2/ocp-v2-render.js +53 -4
- package/neural-interface/public/shared/ocp-v2/ocp-v2-send.js +52 -6
- package/neural-interface/public/shared/ocp-v2/ocp-v2-session-actions.js +22 -2
- package/neural-interface/public/shared/ocp-v2/ocp-v2-shell-block.js +165 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-shell-logic.js +346 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-shell.js +108 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-state.js +49 -3
- package/neural-interface/public/shared/ocp-v2/ocp-v2-styles.js +67 -93
- package/neural-interface/public/shared/ocp-v2/ocp-v2-tools-logic.js +20 -5
- package/neural-interface/public/shared/ocp-v2/ocp-v2-tools.js +7 -1
- package/neural-interface/public/shared/ocp-v2/ocp-v2-variantpicker.js +17 -6
- package/neural-interface/public/shared/ocp-v2/ocp-v2-ws.js +7 -2
- package/neural-interface/public/shared/output-format.js +294 -0
- package/neural-interface/public/shared/provider-icons.js +6 -0
- package/neural-interface/public/shared/schedules-view.js +2 -1
- package/neural-interface/public/shared/server-presence.js +77 -0
- package/neural-interface/public/shared/settings/settings-backup-contents.js +241 -0
- package/neural-interface/public/shared/settings/settings-backup-download.js +298 -0
- package/neural-interface/public/shared/settings/settings-backup-encryption-pane.js +335 -0
- package/neural-interface/public/shared/settings/settings-backup-encryption.js +545 -0
- package/neural-interface/public/shared/settings/settings-browser-extension.js +54 -12
- package/neural-interface/public/shared/settings/settings-ia.js +1 -1
- package/neural-interface/public/shared/shell-stop-view.js +83 -0
- package/neural-interface/public/shared/skills/studio/sx-geometry.js +12 -3
- package/neural-interface/public/shared/skills/studio/sx-main.js +14 -7
- package/neural-interface/public/shared/studio-attention.js +6 -0
- package/neural-interface/public/shared/styles.css +341 -437
- package/neural-interface/public/shared/tour/tour-actor.js +14 -3
- package/neural-interface/public/shared/transcript-rows.js +28 -3
- package/neural-interface/public/shared/tray-auto-close.js +49 -6
- package/neural-interface/public/shared/ui-agents.js +1 -2
- package/neural-interface/public/shared/ui-automation-studio.js +168 -108
- package/neural-interface/public/shared/ui-claude-panel.js +62 -65
- package/neural-interface/public/shared/ui-loading.js +124 -17
- package/neural-interface/public/shared/ui-native-loop-router.js +52 -0
- package/neural-interface/public/shared/ui-navbar.js +2 -1
- package/neural-interface/public/shared/ui-output.js +533 -0
- package/neural-interface/public/shared/ui-schedules-studio.js +165 -128
- package/neural-interface/public/shared/ui-scroll-follow.js +101 -6
- package/neural-interface/public/shared/ui-sessions.js +2 -2
- package/neural-interface/public/shared/ui-settings-entry.js +18 -0
- package/neural-interface/public/shared/ui-settings.js +224 -65
- package/neural-interface/public/shared/ui-sidepanel-tray.js +3 -2
- package/neural-interface/public/shared/ui-tooltip.js +16 -0
- package/neural-interface/public/shared/ui-tutorial.js +5 -6
- package/neural-interface/public/shared/ui-worker-end.js +27 -8
- package/neural-interface/public/shared/worker-end.js +9 -4
- package/neural-interface/public/variant/2d/main.js +5 -0
- package/neural-interface/public/variant/3d/app.js +10 -0
- package/neural-interface/public/variant/3d/main.js +5 -1
- package/neural-interface/scripts/scratch-retention.mjs +20 -0
- package/neural-interface/server.js +725 -173
- package/npm-shrinkwrap.json +5 -5
- package/package.json +1 -2
- package/scripts/restore-data-home-from-backup.mjs +175 -8
- package/setup.js +18 -4
- package/browser-extension/content.js +0 -189
- package/browser-extension/engine.js +0 -508
- package/browser-extension/icons/icon-128.png +0 -0
- package/browser-extension/icons/icon-16.png +0 -0
- package/browser-extension/icons/icon-32.png +0 -0
- package/browser-extension/icons/icon-48.png +0 -0
- package/browser-extension/icons/status-off-16.png +0 -0
- package/browser-extension/icons/status-off-32.png +0 -0
- package/browser-extension/icons/status-off-48.png +0 -0
- package/browser-extension/icons/status-on-16.png +0 -0
- package/browser-extension/icons/status-on-32.png +0 -0
- package/browser-extension/icons/status-on-48.png +0 -0
- package/browser-extension/manifest.json +0 -56
- package/browser-extension/popup-strings.js +0 -250
- package/browser-extension/popup-view.js +0 -151
- package/browser-extension/popup.css +0 -166
- package/browser-extension/popup.html +0 -108
- package/browser-extension/popup.js +0 -359
- package/browser-extension/service-worker.js +0 -275
- package/browser-extension/setup-content.js +0 -36
- package/browser-extension/tokens.css +0 -326
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
// What a serve of SynaBun's does right before it is stopped: the turns still running on it are interrupted, so that
|
|
2
|
+
// no session stays claimed in OpenCode's database.
|
|
3
|
+
//
|
|
4
|
+
// Why (measured on OpenCode 2.2.7 and 2.4.1, 2026-11-23): a session whose turn is in flight has `time_suspended` set
|
|
5
|
+
// in OpenCode's `session_v2` table. A serve that ends with the turn still running leaves that mark: on SIGKILL
|
|
6
|
+
// (`taskkill /F`, what Windows gets) and on SIGTERM alike. A serve started the way SynaBun starts one (`opencode
|
|
7
|
+
// serve`) never looks at the mark again, but OpenCode's own background service (the one a plain `opencode` in a
|
|
8
|
+
// terminal starts) resumes EVERY marked session at its boot, all at once, and each one calls its model again. A
|
|
9
|
+
// session a schedule ran weeks ago wakes up then. `POST /api/session/<id>/interrupt` on the serve that runs the turn
|
|
10
|
+
// clears the mark; on any other serve it changes nothing, so the only moment to do it is before the stop.
|
|
11
|
+
//
|
|
12
|
+
// The caller's stop is never held up for long: one read of the active sessions, one interrupt for each, and a short
|
|
13
|
+
// wait for the serve to say they ended, all inside `budgetMs`. A serve that does not answer is stopped as before.
|
|
14
|
+
import { basicAuthHeader } from './opencode-protocol.js';
|
|
15
|
+
|
|
16
|
+
/** How long a stop waits for its serve's turns to end, at most. */
|
|
17
|
+
export const TURN_RELEASE_BUDGET_MS = 2500;
|
|
18
|
+
|
|
19
|
+
const pause = (ms) => new Promise((done) => { const timer = setTimeout(done, ms); timer.unref?.(); });
|
|
20
|
+
|
|
21
|
+
async function request(fetchImpl, url, { method = 'GET', password, timeoutMs }) {
|
|
22
|
+
const res = await fetchImpl(url, {
|
|
23
|
+
method,
|
|
24
|
+
headers: { accept: 'application/json', ...(password ? { authorization: basicAuthHeader(password) } : {}) },
|
|
25
|
+
signal: AbortSignal.timeout(Math.max(1, Math.round(timeoutMs))),
|
|
26
|
+
});
|
|
27
|
+
let body = null;
|
|
28
|
+
try { body = await res.json(); } catch { /* no JSON body */ }
|
|
29
|
+
return { ok: res.ok, status: res.status, body };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The sessions a serve is running a turn for right now: `{ ok, ids, error }`. `ok` false when the serve did not
|
|
34
|
+
* answer its own API (stopped already, another server on the port, a refused password): nothing is known then.
|
|
35
|
+
*/
|
|
36
|
+
export async function activeOpencodeSessions({ port, password = null, host = '127.0.0.1', fetchImpl = globalThis.fetch, timeoutMs = 1000 } = {}) {
|
|
37
|
+
if (!(Number(port) > 0)) return { ok: false, ids: [], error: 'no port' };
|
|
38
|
+
try {
|
|
39
|
+
const answer = await request(fetchImpl, `http://${host}:${port}/api/session/active`, { password, timeoutMs });
|
|
40
|
+
if (!answer.ok) return { ok: false, ids: [], error: `GET /api/session/active answered ${answer.status}` };
|
|
41
|
+
const data = answer.body?.data;
|
|
42
|
+
if (!data || typeof data !== 'object' || Array.isArray(data)) return { ok: false, ids: [], error: 'GET /api/session/active answered no list' };
|
|
43
|
+
return { ok: true, ids: Object.keys(data), error: null };
|
|
44
|
+
} catch (error) {
|
|
45
|
+
return { ok: false, ids: [], error: String(error?.message || error) };
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Interrupt every turn a serve is running and wait, inside `budgetMs`, until it reports none of them.
|
|
51
|
+
* `{ ok, active, interrupted, remaining, ms, error }`: `active` the sessions that were running, `interrupted` the
|
|
52
|
+
* ones the serve took the interrupt for, `remaining` the ones still running when the budget ended (they stay
|
|
53
|
+
* claimed). Never throws.
|
|
54
|
+
*/
|
|
55
|
+
export async function releaseOpencodeTurns({
|
|
56
|
+
port, password = null, host = '127.0.0.1', fetchImpl = globalThis.fetch,
|
|
57
|
+
budgetMs = TURN_RELEASE_BUDGET_MS, pollMs = 100, now = Date.now, sleep = pause,
|
|
58
|
+
} = {}) {
|
|
59
|
+
const started = now();
|
|
60
|
+
const left = () => budgetMs - (now() - started);
|
|
61
|
+
const done = (result) => ({ active: [], interrupted: [], remaining: [], error: null, ...result, ms: now() - started });
|
|
62
|
+
const first = await activeOpencodeSessions({ port, password, host, fetchImpl, timeoutMs: Math.min(1000, Math.max(1, budgetMs)) });
|
|
63
|
+
if (!first.ok) return done({ ok: false, error: first.error });
|
|
64
|
+
if (!first.ids.length) return done({ ok: true });
|
|
65
|
+
const interrupted = [];
|
|
66
|
+
await Promise.all(first.ids.map(async (id) => {
|
|
67
|
+
try {
|
|
68
|
+
const answer = await request(fetchImpl, `http://${host}:${port}/api/session/${encodeURIComponent(id)}/interrupt`, { method: 'POST', password, timeoutMs: Math.max(1, left()) });
|
|
69
|
+
if (answer.ok) interrupted.push(id);
|
|
70
|
+
} catch { /* it stays in `remaining` */ }
|
|
71
|
+
}));
|
|
72
|
+
let remaining = first.ids;
|
|
73
|
+
while (left() > 0) {
|
|
74
|
+
const look = await activeOpencodeSessions({ port, password, host, fetchImpl, timeoutMs: Math.max(1, Math.min(1000, left())) });
|
|
75
|
+
// A serve that stopped answering has ended: nothing more can be asked of it.
|
|
76
|
+
if (!look.ok) return done({ ok: false, active: first.ids, interrupted, remaining, error: look.error });
|
|
77
|
+
remaining = first.ids.filter((id) => look.ids.includes(id));
|
|
78
|
+
if (!remaining.length) break;
|
|
79
|
+
if (left() <= pollMs) break;
|
|
80
|
+
await sleep(pollMs);
|
|
81
|
+
}
|
|
82
|
+
return done({ ok: remaining.length === 0, active: first.ids, interrupted, remaining, error: remaining.length ? 'turns still running when the wait ended' : null });
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* How SynaBun ends its serves: `end()` releases a serve's turns and then runs its `kill`, exactly once.
|
|
87
|
+
*
|
|
88
|
+
* end({ port, password, alive, kill, label, immediate })
|
|
89
|
+
* → null when the serve was ended at once (nothing can be asked of it: no port or password, its process is
|
|
90
|
+
* gone, or `immediate`), else a promise of its end. `kill` always runs, also when the release failed.
|
|
91
|
+
* settled(timeoutMs) every end under way has finished (true), or the wait ran out (false): a shutdown waits here.
|
|
92
|
+
* killNow() the kills not run yet, now and synchronously: the process's exit handler, where nothing
|
|
93
|
+
* can be awaited, so that a serve whose release was still under way is not left running.
|
|
94
|
+
*/
|
|
95
|
+
export function createServeEnds({ release = releaseOpencodeTurns, log = () => {} } = {}) {
|
|
96
|
+
const pending = new Set();
|
|
97
|
+
const kills = new Set();
|
|
98
|
+
return {
|
|
99
|
+
end({ port = null, password = null, alive = () => true, kill, label = 'serve', immediate = false } = {}) {
|
|
100
|
+
let ran = false;
|
|
101
|
+
const once = () => {
|
|
102
|
+
if (ran) return;
|
|
103
|
+
ran = true;
|
|
104
|
+
kills.delete(once);
|
|
105
|
+
try { kill?.(); } catch { /* its process is gone */ }
|
|
106
|
+
};
|
|
107
|
+
let running = false;
|
|
108
|
+
try { running = !!alive(); } catch { running = false; }
|
|
109
|
+
if (immediate || !(Number(port) > 0) || !password || !running) { once(); return null; }
|
|
110
|
+
kills.add(once);
|
|
111
|
+
const ended = (async () => {
|
|
112
|
+
try {
|
|
113
|
+
const released = await release({ port, password });
|
|
114
|
+
if (released?.active?.length) {
|
|
115
|
+
const kept = released.remaining?.length || 0;
|
|
116
|
+
log(`${label}: ${released.active.length - kept} of ${released.active.length} running turn(s) interrupted before the stop${kept ? `; ${kept} did not end in time and may be resumed by OpenCode's own background service` : ''}`);
|
|
117
|
+
}
|
|
118
|
+
} catch { /* the serve is ended either way */ } finally { once(); }
|
|
119
|
+
})().finally(() => pending.delete(ended));
|
|
120
|
+
pending.add(ended);
|
|
121
|
+
return ended;
|
|
122
|
+
},
|
|
123
|
+
killNow() { for (const kill of [...kills]) kill(); },
|
|
124
|
+
size: () => pending.size,
|
|
125
|
+
async settled(timeoutMs = TURN_RELEASE_BUDGET_MS + 1500) {
|
|
126
|
+
if (!pending.size) return true;
|
|
127
|
+
let timer = null;
|
|
128
|
+
const timeout = new Promise((done) => { timer = setTimeout(() => done(false), timeoutMs); timer.unref?.(); });
|
|
129
|
+
const all = Promise.allSettled([...pending]).then(() => true);
|
|
130
|
+
const result = await Promise.race([all, timeout]);
|
|
131
|
+
clearTimeout(timer);
|
|
132
|
+
return result;
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// ── A serve older than the OpenCode on disk ────────────────────────────────────────────────────────────────────────
|
|
138
|
+
//
|
|
139
|
+
// An update of OpenCode replaces the file; a serve SynaBun started before keeps running the old program from memory
|
|
140
|
+
// (on Windows OpenCode's updater links the running file under another name first, so the installed path can be
|
|
141
|
+
// replaced while SynaBun's serve runs from it). Nothing told SynaBun: its shared serve, and the serve of every open
|
|
142
|
+
// session, stayed on the old version until SynaBun itself was restarted, and the panel kept showing that version.
|
|
143
|
+
// OpenCode treats the same situation in its own client as a reason to replace the server ("Restarting background
|
|
144
|
+
// server (version mismatch)").
|
|
145
|
+
|
|
146
|
+
/** A file's identity (lib/opencode-serve-probe.js binaryIdentity) as one string, or null. */
|
|
147
|
+
export function binaryFileKey(identity) {
|
|
148
|
+
if (!identity?.realpath) return null;
|
|
149
|
+
return [identity.realpath, identity.size, identity.mtimeMs, identity.ino, identity.dev].join('|');
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Which of SynaBun's serves run a file that is no longer the OpenCode on disk.
|
|
154
|
+
*
|
|
155
|
+
* current the file key of the OpenCode SynaBun would start now; null (not readable, a command line in Settings):
|
|
156
|
+
* nothing is decided
|
|
157
|
+
* shared { key, managed, ready, starting }: SynaBun's shared serve. Only one SynaBun spawned (`managed`) and
|
|
158
|
+
* that answers (`ready`, not `starting`) is restarted.
|
|
159
|
+
* isolated [{ termId, key, busy }]: the serves of sessions, loops, workers and brains. One that runs a turn, is
|
|
160
|
+
* starting, or belongs to a live run (`busy`) is left for a later look.
|
|
161
|
+
*
|
|
162
|
+
* → { shared: 'keep' | 'restart', isolated: [termId], waiting: [termId] }
|
|
163
|
+
*/
|
|
164
|
+
export function staleServePlan({ current = null, shared = null, isolated = [] } = {}) {
|
|
165
|
+
const plan = { shared: 'keep', isolated: [], waiting: [] };
|
|
166
|
+
if (!current) return plan;
|
|
167
|
+
if (shared?.managed && shared.ready && !shared.starting && shared.key && shared.key !== current) plan.shared = 'restart';
|
|
168
|
+
for (const serve of isolated) {
|
|
169
|
+
if (!serve?.termId || !serve.key || serve.key === current) continue;
|
|
170
|
+
(serve.busy ? plan.waiting : plan.isolated).push(serve.termId);
|
|
171
|
+
}
|
|
172
|
+
return plan;
|
|
173
|
+
}
|
|
@@ -88,6 +88,7 @@ export async function disconnect() {
|
|
|
88
88
|
_stopRequested = true;
|
|
89
89
|
if (_abort) { try { _abort.abort(); } catch {} }
|
|
90
90
|
_abort = null;
|
|
91
|
+
try { _client?.dispose?.(); } catch {}
|
|
91
92
|
_client = null;
|
|
92
93
|
_port = null;
|
|
93
94
|
_password = null;
|
|
@@ -211,6 +212,8 @@ export const EXTRA_CLIENT_METHODS = Object.freeze({
|
|
|
211
212
|
mcp: ['add'],
|
|
212
213
|
lsp: ['status'],
|
|
213
214
|
formatter: ['status'],
|
|
215
|
+
// The shell commands of tool calls: a session's list and a command's output in pages.
|
|
216
|
+
shell: ['list', 'output'],
|
|
214
217
|
});
|
|
215
218
|
|
|
216
219
|
function extraGroups(getRaw) {
|
|
@@ -369,7 +372,7 @@ export function createClientInstance({ port, clientFactory = createOpencode2Clie
|
|
|
369
372
|
if (!connected) throw new Error('OpenCode isolated event stream did not become ready');
|
|
370
373
|
return true;
|
|
371
374
|
},
|
|
372
|
-
stop() { stopRequested = true; if (abort) { try { abort.abort(); } catch {} } abort = null; client = null; },
|
|
375
|
+
stop() { stopRequested = true; if (abort) { try { abort.abort(); } catch {} } abort = null; try { client?.dispose?.(); } catch {} client = null; },
|
|
373
376
|
isConnected: () => connected,
|
|
374
377
|
session: {
|
|
375
378
|
list: (p = {}) => unwrap(req().session.list(clean(p))),
|
|
@@ -34,6 +34,9 @@
|
|
|
34
34
|
import { OPENCODE_SESSION_TABLES } from './opencode-db-schema.js';
|
|
35
35
|
import { opencodeMcpServerEntry } from './opencode-config.js';
|
|
36
36
|
import { storedToolList } from './tool-lists.js';
|
|
37
|
+
import { readSafeShellOutputPage, readShellOutputPage, SHELL_OUTPUT_PAGE_BYTES } from './opencode-shell-read.js';
|
|
38
|
+
import { statSync } from 'node:fs';
|
|
39
|
+
import { LOCATION_MISSING_CODE, locationNotFoundMessage } from '../public/shared/ocp-v2/ocp-v2-location-logic.js';
|
|
37
40
|
|
|
38
41
|
// Types answered by the switch in server.js.
|
|
39
42
|
export const OPENCODE_V2_WS_INLINE_TYPES = Object.freeze([
|
|
@@ -89,13 +92,37 @@ export function canonicalizeOpencodeV2Message(msg) {
|
|
|
89
92
|
return null;
|
|
90
93
|
}
|
|
91
94
|
|
|
95
|
+
// ── A folder that does not exist ────────────────────────────────────────────
|
|
96
|
+
// OpenCode 2 creates a session in a folder that does not exist and then
|
|
97
|
+
// refuses every prompt of it (404 "Location not found: <folder>"); a session is
|
|
98
|
+
// bound to its folder for good. So a request that starts work in a folder is
|
|
99
|
+
// refused here, in OpenCode's own words (the panel reads one sentence for both:
|
|
100
|
+
// public/shared/ocp-v2/ocp-v2-location-logic.js), before a session is made
|
|
101
|
+
// that can never run or a serve is started for a turn that cannot begin.
|
|
102
|
+
export const OPENCODE_V2_WS_FOLDER_TYPES = Object.freeze(['session:create', 'message:send', 'command:run', 'session:shell']);
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Whether `folder` is certainly not a folder that exists: nothing is there, or
|
|
106
|
+
* something that is not a folder. A folder that cannot be asked (no permission,
|
|
107
|
+
* a disk that does not answer) is not called gone: OpenCode decides.
|
|
108
|
+
*/
|
|
109
|
+
export function folderIsGone(folder, stat = statSync) {
|
|
110
|
+
try {
|
|
111
|
+
return !stat(folder).isDirectory();
|
|
112
|
+
} catch (err) {
|
|
113
|
+
return err?.code === 'ENOENT' || err?.code === 'ENOTDIR';
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
92
117
|
/**
|
|
93
118
|
* Everything that must hold before a request is answered, in one place so it
|
|
94
119
|
* can be tested: a canonical session id, no write while history is being
|
|
95
120
|
* cleared, and the native-automation ownership rules. Returns null to let the
|
|
96
121
|
* request through, or `{ status, error }`.
|
|
97
122
|
* ctx: { historyClearing, historyWriteTypes, nativeMutationTypes,
|
|
98
|
-
* protectedRunFor(sessionId), ownsRun(run)
|
|
123
|
+
* protectedRunFor(sessionId), ownsRun(run),
|
|
124
|
+
* folderGone(folder) } folderIsGone, or absent to check no folder
|
|
125
|
+
* A refusal for a folder that is gone also carries `code` (LOCATION_MISSING).
|
|
99
126
|
*/
|
|
100
127
|
export function guardOpencodeV2Request(msg, ctx = {}) {
|
|
101
128
|
const malformed = canonicalizeOpencodeV2Message(msg);
|
|
@@ -111,6 +138,10 @@ export function guardOpencodeV2Request(msg, ctx = {}) {
|
|
|
111
138
|
if (protectedRun && ctx.nativeMutationTypes?.has(type)) {
|
|
112
139
|
return { status: 409, error: 'Stop the native automation before modifying its session' };
|
|
113
140
|
}
|
|
141
|
+
const folder = OPENCODE_V2_WS_FOLDER_TYPES.includes(type) ? directoryOf(msg) : undefined;
|
|
142
|
+
if (folder && ctx.folderGone?.(folder)) {
|
|
143
|
+
return { status: 404, code: LOCATION_MISSING_CODE, error: locationNotFoundMessage(folder) };
|
|
144
|
+
}
|
|
114
145
|
return null;
|
|
115
146
|
}
|
|
116
147
|
|
|
@@ -223,6 +254,37 @@ async function sessionStatus(msg, deps) {
|
|
|
223
254
|
return { status: r.status, data: { status: statusForSession(r.data, sessionIdOf(msg)) } };
|
|
224
255
|
}
|
|
225
256
|
|
|
257
|
+
// ── The shell commands of a session's tool calls ────────────────────────────
|
|
258
|
+
// OpenCode 2 no longer sends a command's output with the tool call: it keeps it
|
|
259
|
+
// in a file, read in pages by byte position while the command runs and after.
|
|
260
|
+
|
|
261
|
+
/** The most a `shell:output` request reads at once. */
|
|
262
|
+
export { SHELL_OUTPUT_PAGE_BYTES };
|
|
263
|
+
|
|
264
|
+
/** The session's commands as its event stream told them (`{ id, status, command, callID, background, … }`). */
|
|
265
|
+
async function shellList(msg, deps) {
|
|
266
|
+
const r = await deps.bound(sessionKeyOf(msg)).extra.shell.list({ sessionID: sessionIdOf(msg) });
|
|
267
|
+
return { status: r.status, data: Array.isArray(r.data) ? r.data : [] };
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* A page of one command's output. Only a command of the session the request names is read (`shellId` is the
|
|
272
|
+
* page's word). `cursor`: the byte to read from; `tail`: instead, the last so many bytes (a panel that opens
|
|
273
|
+
* on a command with a long output starts at its end).
|
|
274
|
+
*/
|
|
275
|
+
async function shellOutput(msg, deps) {
|
|
276
|
+
const shellId = typeof msg.shellId === 'string' ? msg.shellId : '';
|
|
277
|
+
if (!shellId) return failure(400, 'shellId required');
|
|
278
|
+
const extra = deps.bound(sessionKeyOf(msg)).extra;
|
|
279
|
+
const listed = await extra.shell.list({ sessionID: sessionIdOf(msg) });
|
|
280
|
+
const known = (Array.isArray(listed.data) ? listed.data : []).find((shell) => shell.id === shellId);
|
|
281
|
+
if (!known) return failure(404, 'That command is not one of this session.');
|
|
282
|
+
// Scrubbed on the whole window around the page, as the Assistant reads it (lib/opencode-shell-read.js
|
|
283
|
+
// readSafeShellOutputPage): each page scrubbed on its own would let a secret through that the panel joins.
|
|
284
|
+
const read = (q) => readShellOutputPage(extra.shell, { shellID: shellId, directory: directoryOf(msg), cursor: q.cursor, limit: q.limit }, { errorText: proxyErrorText });
|
|
285
|
+
return readSafeShellOutputPage(read, { cursor: msg.cursor, tail: msg.tail, limit: msg.limit, running: known.status === 'running' });
|
|
286
|
+
}
|
|
287
|
+
|
|
226
288
|
// An MCP server as OpenCode 2 takes it (`mcp.servers.<name>`, lib/opencode-config.js), from what SynaBun
|
|
227
289
|
// describes as { command, args, env } or { url, headers }: type local with the command as one array and its
|
|
228
290
|
// `environment`, or type remote. Every word goes through as it is: an argument may be empty or carry spaces on
|
|
@@ -715,6 +777,8 @@ const HANDLERS = {
|
|
|
715
777
|
},
|
|
716
778
|
'session:compact': { session: true, run: compactSession },
|
|
717
779
|
'session:status': { session: true, run: sessionStatus },
|
|
780
|
+
'shell:list': { session: true, run: shellList },
|
|
781
|
+
'shell:output': { session: true, run: shellOutput },
|
|
718
782
|
'session:todo': { session: true, run: sessionTodo },
|
|
719
783
|
'permission:reply': { run: permissionReply },
|
|
720
784
|
'permission:list': { run: permissionList },
|