synabun 2.4.0 → 2.4.2
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 +47 -0
- package/README.md +1 -1
- package/browser-extension/content.js +73 -11
- package/browser-extension/engine.js +196 -15
- package/browser-extension/manifest.json +4 -2
- package/browser-extension/popup-strings.js +10 -4
- package/browser-extension/popup-view.js +1 -1
- package/browser-extension/popup.css +1 -0
- package/browser-extension/popup.html +4 -1
- package/browser-extension/popup.js +22 -10
- package/browser-extension/protocol.js +102 -11
- package/browser-extension/service-worker.js +20 -4
- package/browser-extension/tokens.css +1 -1
- package/docs/browser-extension-bridge.md +25 -5
- package/lib/data-home-files.js +47 -0
- package/lib/data-home-migration.js +34 -58
- package/lib/first-launch-protection.js +8 -2
- 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 +6 -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 +13 -8
- package/mcp-server/dist/tools/agents.d.ts.map +1 -1
- package/mcp-server/dist/tools/agents.js +35 -15
- 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 +23 -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 +2 -2
- 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 +23 -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 +33 -14
- package/mcp-server/src/tools/browser-advanced.ts +10 -3
- package/mcp-server/src/tools/browser-extension-setup.ts +30 -0
- package/mcp-server/src/tools/browser-interact.ts +5 -1
- package/neural-interface/i18n/en.json +266 -2
- package/neural-interface/i18n/pt-BR.json +267 -3
- package/neural-interface/lib/agents/builtins.json +207 -0
- package/neural-interface/lib/agents/registry.js +60 -15
- package/neural-interface/lib/agents/resolve.js +69 -10
- package/neural-interface/lib/agents/split.js +32 -4
- package/neural-interface/lib/assistant-api.js +19 -8
- package/neural-interface/lib/assistant-brains/claude.js +2 -0
- package/neural-interface/lib/assistant-brains/opencode.js +60 -11
- 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 +384 -119
- package/neural-interface/lib/assistant-persona.js +17 -5
- package/neural-interface/lib/assistant-pricing.js +65 -14
- package/neural-interface/lib/assistant-router.js +181 -54
- package/neural-interface/lib/assistant-run-wait.js +45 -28
- package/neural-interface/lib/assistant-runtime.js +48 -34
- 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 +836 -322
- 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 +109 -24
- package/neural-interface/lib/browser-extension-bridge.js +42 -8
- 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-update-planner.js +105 -6
- 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 +13 -16
- package/neural-interface/lib/native-loop-runtime.js +34 -14
- package/neural-interface/lib/opencode-build-preflight.js +30 -8
- 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-v2-ws-requests.js +31 -1
- package/neural-interface/lib/opencode2-client.js +2 -1
- package/neural-interface/lib/peer-identity.js +13 -8
- 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 +70 -44
- 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 +196 -97
- package/neural-interface/lib/teams/schema.js +1 -1
- package/neural-interface/lib/teams/state.js +14 -14
- package/neural-interface/lib/teams/worktrees.js +27 -27
- package/neural-interface/lib/whatsapp/bridge.js +2 -1
- 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 +2 -2
- package/neural-interface/package.json +1 -1
- package/neural-interface/public/index.html +260 -0
- package/neural-interface/public/offline.html +4 -3
- package/neural-interface/public/onboarding.html +259 -34
- package/neural-interface/public/shared/agents/studio/ax-agent-view.js +2 -2
- package/neural-interface/public/shared/agents/studio/ax-editor-view.js +1 -1
- 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/agents/studio/ax-ui.js +2 -2
- package/neural-interface/public/shared/agy/agy-options.js +11 -0
- package/neural-interface/public/shared/agy/agy-panel.js +29 -10
- 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 +3 -2
- package/neural-interface/public/shared/assistant/asst-api.js +3 -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 +18 -2
- package/neural-interface/public/shared/assistant/asst-rack-styles.js +4 -0
- package/neural-interface/public/shared/assistant/asst-render.js +106 -38
- package/neural-interface/public/shared/assistant/asst-route.js +102 -21
- package/neural-interface/public/shared/assistant/asst-routes-editor.js +1 -1
- 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 +10 -23
- package/neural-interface/public/shared/assistant/route-identity.js +2 -1
- package/neural-interface/public/shared/cc-dropdown.js +21 -15
- 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 +29 -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/html-shell.js +4 -51
- 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 +8 -1
- 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-location-logic.js +109 -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 +118 -6
- package/neural-interface/public/shared/ocp-v2/ocp-v2-render.js +27 -3
- package/neural-interface/public/shared/ocp-v2/ocp-v2-send.js +13 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-session-actions.js +2 -1
- package/neural-interface/public/shared/ocp-v2/ocp-v2-styles.js +27 -93
- package/neural-interface/public/shared/ocp-v2/ocp-v2-variantpicker.js +17 -6
- package/neural-interface/public/shared/output-format.js +294 -0
- package/neural-interface/public/shared/owner-authority-view.js +4 -10
- package/neural-interface/public/shared/page-session.js +1 -1
- 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-ai-browser.js +5 -5
- 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-ia.js +1 -1
- 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/start-bridge.js +2 -2
- package/neural-interface/public/shared/studio-attention.js +6 -0
- package/neural-interface/public/shared/styles.css +354 -438
- package/neural-interface/public/shared/transcript-rows.js +28 -3
- package/neural-interface/public/shared/tray-auto-close.js +18 -5
- 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 +42 -65
- package/neural-interface/public/shared/ui-loading.js +185 -25
- package/neural-interface/public/shared/ui-native-loop-router.js +59 -20
- 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-owner-authority.js +48 -25
- package/neural-interface/public/shared/ui-schedules-studio.js +165 -128
- package/neural-interface/public/shared/ui-scroll-follow.js +97 -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 +234 -67
- package/neural-interface/public/shared/ui-sidepanel-tray.js +3 -2
- package/neural-interface/public/shared/ui-sync.js +1 -0
- 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/sw.js +4 -3
- 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 +17 -4
- package/neural-interface/scripts/scratch-retention.mjs +20 -0
- package/neural-interface/server.js +507 -160
- package/npm-shrinkwrap.json +2 -2
- package/package.json +2 -1
- package/scripts/restore-data-home-from-backup.mjs +175 -8
- package/setup.js +18 -4
|
@@ -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,
|
|
@@ -273,10 +275,11 @@ export class NativeLoopRuntime {
|
|
|
273
275
|
_loadLedger() {
|
|
274
276
|
const rows = readJson(this.ledgerPath, []);
|
|
275
277
|
if (!Array.isArray(rows)) return;
|
|
278
|
+
let options;
|
|
276
279
|
for (const row of rows) {
|
|
277
280
|
if (!row?.runId) continue;
|
|
278
281
|
let stored;
|
|
279
|
-
try { stored = readStoredToolListRecord(row, this.toolListOptions()); }
|
|
282
|
+
try { stored = readStoredToolListRecord(row, options ??= this.toolListOptions()); }
|
|
280
283
|
catch (error) {
|
|
281
284
|
// A historical run may name a custom preset the owner has since deleted. Refuse that
|
|
282
285
|
// run, preserve the original selection for diagnosis, and keep the rest of the server up.
|
|
@@ -309,6 +312,7 @@ export class NativeLoopRuntime {
|
|
|
309
312
|
record.stoppedReason = 'server_restart';
|
|
310
313
|
record.completedAt = record.completedAt || iso(this.now());
|
|
311
314
|
record.updatedAt = iso(this.now());
|
|
315
|
+
record.stopProvenance = stampStopProvenance('server_restart', record.stopProvenance, record.completedAt);
|
|
312
316
|
const state = this._readState(record.runId);
|
|
313
317
|
if (state) {
|
|
314
318
|
this._writeState(record.runId, {
|
|
@@ -317,6 +321,7 @@ export class NativeLoopRuntime {
|
|
|
317
321
|
pending: false,
|
|
318
322
|
completedAt: record.completedAt,
|
|
319
323
|
stoppedReason: 'server_restart',
|
|
324
|
+
stopProvenance: record.stopProvenance,
|
|
320
325
|
});
|
|
321
326
|
}
|
|
322
327
|
}
|
|
@@ -397,7 +402,7 @@ export class NativeLoopRuntime {
|
|
|
397
402
|
_writeTerminalState(record, patch) {
|
|
398
403
|
try {
|
|
399
404
|
const state = this._readState(record.runId);
|
|
400
|
-
if (state) this._writeState(record.runId, { ...state, ...patch });
|
|
405
|
+
if (state) this._writeState(record.runId, { ...state, ...patch, ...(record.stopProvenance && { stopProvenance: record.stopProvenance }) });
|
|
401
406
|
} catch (error) {
|
|
402
407
|
this.log(record.runId, 'native:state-write-error', error?.message || String(error));
|
|
403
408
|
}
|
|
@@ -405,12 +410,13 @@ export class NativeLoopRuntime {
|
|
|
405
410
|
|
|
406
411
|
_emit(type, record, extra = {}) {
|
|
407
412
|
record.version = (Number(record.version) || 0) + 1;
|
|
408
|
-
|
|
413
|
+
const leaseChange = type === 'sidepanel:run-claimed' || extra.reason === 'claim-released';
|
|
414
|
+
if (!leaseChange) record.updatedAt = iso(this.now());
|
|
409
415
|
// Force-flush on terminal transitions (a crash between throttled flushes
|
|
410
416
|
// would otherwise leave the run listed as running after a restart), and on
|
|
411
417
|
// a suspension (the next start resumes the run from this ledger).
|
|
412
418
|
const terminal = ['completed', 'failed', 'stopped', 'interrupted', 'suspended'].includes(record.status);
|
|
413
|
-
this._persistLedger({ force: terminal });
|
|
419
|
+
this._persistLedger({ force: terminal && !leaseChange });
|
|
414
420
|
const descriptor = cleanDescriptor(record);
|
|
415
421
|
const message = { type, run: descriptor, ...extra };
|
|
416
422
|
try { this.onEvent(message); } catch {}
|
|
@@ -633,6 +639,7 @@ export class NativeLoopRuntime {
|
|
|
633
639
|
setTurnState: (turnState) => this.setTurnState(runId, turnState),
|
|
634
640
|
setPendingRequests: (requests) => this.setPendingRequests(runId, requests),
|
|
635
641
|
setOutcome: (outcome) => this.setOutcome(runId, outcome),
|
|
642
|
+
noteTabClose: provenance => { if (!record.stopping) record.stopProvenance = provenance; },
|
|
636
643
|
readState: () => this._readState(runId),
|
|
637
644
|
})
|
|
638
645
|
: adapter;
|
|
@@ -786,6 +793,7 @@ export class NativeLoopRuntime {
|
|
|
786
793
|
record.status = 'interrupted';
|
|
787
794
|
record.stoppedReason = reason || record.suspendReason || 'server_restart';
|
|
788
795
|
record.completedAt = iso(this.now());
|
|
796
|
+
record.stopProvenance = stampStopProvenance(record.stoppedReason, { actor: 'server', action: 'resume_refused' }, record.completedAt);
|
|
789
797
|
if (error) record.error = scrubTokenText(String(error));
|
|
790
798
|
this._writeTerminalState(record, { active: false, pending: false, completedAt: record.completedAt, stoppedReason: record.stoppedReason, ...(error ? { error: record.error } : {}) });
|
|
791
799
|
this._releaseRuntimeRefs(record);
|
|
@@ -813,8 +821,10 @@ export class NativeLoopRuntime {
|
|
|
813
821
|
try { await record.adapter?.dispose?.({ preserveSession: true, terminate: true }); } catch {}
|
|
814
822
|
// A suspended run has no process: nothing may act as it until its resume gives the new process a new token.
|
|
815
823
|
try { this.terminalTokens?.revoke?.(runId); } catch { /* the suspension goes on */ }
|
|
816
|
-
this._releaseRuntimeRefs(record, { turnState: 'suspended' });
|
|
817
824
|
record.stopping = false;
|
|
825
|
+
// A person stopped it while its CLI was ending: that stop already ended the record.
|
|
826
|
+
if (record.status !== 'suspended') return true;
|
|
827
|
+
this._releaseRuntimeRefs(record, { turnState: 'suspended' });
|
|
818
828
|
this._emit('sidepanel:run-updated', record, { reason: 'suspended' });
|
|
819
829
|
return true;
|
|
820
830
|
}
|
|
@@ -961,6 +971,7 @@ export class NativeLoopRuntime {
|
|
|
961
971
|
if (error?.code) { const safe = isolatedServeFailure(error); record.errorCode = safe.code; record.offenders = safe.offenders; }
|
|
962
972
|
record.stoppedReason = reason;
|
|
963
973
|
record.completedAt = iso(this.now());
|
|
974
|
+
if (record.status === 'interrupted') record.stopProvenance = stampStopProvenance(reason, null, record.completedAt);
|
|
964
975
|
if (record._resolveIdentity) { record._resolveIdentity(null); record._resolveIdentity = null; }
|
|
965
976
|
try { record.startupAbortController?.abort(reason); } catch {}
|
|
966
977
|
if (record._cancelStartup) { record._cancelStartup(reason); record._cancelStartup = null; }
|
|
@@ -974,11 +985,22 @@ export class NativeLoopRuntime {
|
|
|
974
985
|
|
|
975
986
|
/**
|
|
976
987
|
* `terminate` (a server shutdown): the provider's process is ended at once (the Claude adapter's dispose), never
|
|
977
|
-
* left to finish its tool call after the server is gone. A suspended run (waiting for its resume) ends as stopped
|
|
988
|
+
* left to finish its tool call after the server is gone. A suspended run (waiting for its resume) ends as stopped
|
|
989
|
+
* only for a caller that may end it (worker-stop.js mayEndSuspendedRun); for any other this returns false and it
|
|
990
|
+
* stays suspended. A caller that names no reason is recorded as unknown, never as the user.
|
|
978
991
|
*/
|
|
979
|
-
async stop(runId, reason = '
|
|
992
|
+
async stop(runId, reason = 'unknown', { terminate = false, stopProvenance = null } = {}) {
|
|
980
993
|
const record = this.records.get(runId);
|
|
981
|
-
if (record
|
|
994
|
+
if (!record || !LIVE_STATUSES.has(record.status)) return false;
|
|
995
|
+
// `stopping` on a suspended record is its CLI still ending: a person's stop in that moment counts.
|
|
996
|
+
if (record.stopping && record.status !== 'suspended') return false;
|
|
997
|
+
const provenance = stampStopProvenance(reason, stopProvenance, iso(this.now()));
|
|
998
|
+
if (record.status === 'suspended' && !mayEndSuspendedRun(provenance)) {
|
|
999
|
+
this.log(runId, 'native:stop-refused', 'a suspended run stays suspended: this caller may not end it', { reason, stopProvenance: provenance });
|
|
1000
|
+
return false;
|
|
1001
|
+
}
|
|
1002
|
+
record.stopProvenance = provenance;
|
|
1003
|
+
if (record.status === 'suspended') {
|
|
982
1004
|
this._clearHold(record);
|
|
983
1005
|
record.status = 'stopped';
|
|
984
1006
|
record.stoppedReason = reason;
|
|
@@ -989,7 +1011,6 @@ export class NativeLoopRuntime {
|
|
|
989
1011
|
try { await this.onFinish(cleanDescriptor(record)); } catch {}
|
|
990
1012
|
return true;
|
|
991
1013
|
}
|
|
992
|
-
if (!record || !['starting', 'running'].includes(record.status) || record.stopping) return false;
|
|
993
1014
|
record.stopping = true;
|
|
994
1015
|
clearTimeout(record.timer);
|
|
995
1016
|
record.status = 'stopped';
|
|
@@ -1042,10 +1063,7 @@ export class NativeLoopRuntime {
|
|
|
1042
1063
|
record.claimedBy = claimant;
|
|
1043
1064
|
record.claimedAt = iso(this.now());
|
|
1044
1065
|
if (changedOwner) this._emit('sidepanel:run-claimed', record);
|
|
1045
|
-
else
|
|
1046
|
-
record.updatedAt = iso(this.now());
|
|
1047
|
-
this._persistLedger();
|
|
1048
|
-
}
|
|
1066
|
+
else this._persistLedger();
|
|
1049
1067
|
return { ok: true, run: cleanDescriptor(record) };
|
|
1050
1068
|
}
|
|
1051
1069
|
|
|
@@ -1135,7 +1153,9 @@ export class NativeLoopRuntime {
|
|
|
1135
1153
|
const kept = new Set((Array.isArray(keep) ? keep : []).map(String));
|
|
1136
1154
|
await Promise.allSettled([...this.records.values()]
|
|
1137
1155
|
.filter((record) => ['starting', 'running'].includes(record.status))
|
|
1138
|
-
.map((record) => (kept.has(record.runId)
|
|
1156
|
+
.map((record) => (kept.has(record.runId)
|
|
1157
|
+
? this.suspend(record.runId, reason)
|
|
1158
|
+
: this.stop(record.runId, shutdownStopReason(reason), { terminate: true, stopProvenance: { actor: 'server', action: 'shutdown', cause: String(reason) } }))));
|
|
1139
1159
|
for (const timer of this._holdTimers.values()) clearTimeout(timer);
|
|
1140
1160
|
this._holdTimers.clear();
|
|
1141
1161
|
this._persistLedger({ force: true });
|
|
@@ -11,8 +11,8 @@ import { moreLoginProcessesRunning } from './process-identity.js';
|
|
|
11
11
|
/** Strictly parse the observed MoreLogin /api/env/detail response; never retain cookies or other profile data. */
|
|
12
12
|
export function portProtectionOf(detail) {
|
|
13
13
|
const value = detail?.advancedSetting?.port_scan_protection;
|
|
14
|
-
if (!value || ![0, 1].includes(value.switcher) || typeof value.value !== 'string') return null;
|
|
15
|
-
const words = value.value
|
|
14
|
+
if (!value || ![0, 1].includes(value.switcher) || (value.value !== null && typeof value.value !== 'string')) return null;
|
|
15
|
+
const words = value.value?.trim() ? value.value.split(',').map(s => s.trim()) : [];
|
|
16
16
|
if (words.some(s => !/^\d{1,5}$/.test(s) || +s < 1 || +s > 65535)) return null;
|
|
17
17
|
return { enabled: value.switcher === 1, ports: [...new Set(words.map(Number))] };
|
|
18
18
|
}
|
|
@@ -26,7 +26,7 @@ export function moreLoginFailureDetail(error) {
|
|
|
26
26
|
return 'API request failed';
|
|
27
27
|
}
|
|
28
28
|
function profileError(code, message, envId) {
|
|
29
|
-
return Object.assign(new Error(message), { code, offenders: envId ? [{ envId, reason: code }] : [] });
|
|
29
|
+
return Object.assign(new Error(message), { code, sharedPreflight: true, offenders: envId ? [{ envId, reason: code }] : [] });
|
|
30
30
|
}
|
|
31
31
|
export async function reconcilePreflightProfiles(profiles, list, { requested = [], allowUnavailable = false,
|
|
32
32
|
browserProcesses = moreLoginProcessesRunning, log = () => {} } = {}) {
|
|
@@ -45,12 +45,34 @@ 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
|
-
const
|
|
52
|
-
for (const id of requested) if (!
|
|
53
|
-
return profiles.
|
|
53
|
+
const byId = new Map(live.map(p => [String(p.id), p]));
|
|
54
|
+
for (const id of requested) if (!byId.has(String(id))) throw profileError('MORELOGIN_PROFILE_MISSING', `Explicitly requested MoreLogin profile ${id} is missing.`, String(id));
|
|
55
|
+
return profiles.flatMap(profile => {
|
|
56
|
+
const row = byId.get(profile.envId);
|
|
57
|
+
if (row) return [!profile.name && row.name ? { ...profile, name: row.name } : profile];
|
|
58
|
+
log(`Skipping stale MoreLogin profile ${profile.envId}: absent from the complete live listing.`);
|
|
59
|
+
return [];
|
|
60
|
+
});
|
|
61
|
+
}
|
|
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;
|
|
54
76
|
}
|
|
55
77
|
|
|
56
78
|
export async function preflightExcludedPorts(profiles, readDetail) {
|
|
@@ -60,7 +82,7 @@ export async function preflightExcludedPorts(profiles, readDetail) {
|
|
|
60
82
|
let policy, detail = 'malformed port protection policy';
|
|
61
83
|
try { policy = portProtectionOf(await readDetail(profile.envId)); } catch (error) { detail = moreLoginFailureDetail(error); }
|
|
62
84
|
if (!policy) throw profileError('MORELOGIN_POLICY_UNREADABLE', `MoreLogin profile ${name}: port protection could not be read from /api/env/detail (${detail}). Check the MoreLogin local API and try again; OpenCode build verification has not started.`, profile.envId);
|
|
63
|
-
if (!policy.enabled) throw
|
|
85
|
+
if (!policy.enabled) throw profileError('MORELOGIN_POLICY_DISABLED', `MoreLogin profile ${name}: Port scan protection is off. Edit profile → Advanced settings → Port scan protection: Enable, then retry OpenCode build verification.`, profile.envId);
|
|
64
86
|
for (const port of policy.ports) ports.add(port);
|
|
65
87
|
}
|
|
66
88
|
return ports;
|
|
@@ -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
|
}
|
|
@@ -34,6 +34,8 @@
|
|
|
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 { statSync } from 'node:fs';
|
|
38
|
+
import { LOCATION_MISSING_CODE, locationNotFoundMessage } from '../public/shared/ocp-v2/ocp-v2-location-logic.js';
|
|
37
39
|
|
|
38
40
|
// Types answered by the switch in server.js.
|
|
39
41
|
export const OPENCODE_V2_WS_INLINE_TYPES = Object.freeze([
|
|
@@ -89,13 +91,37 @@ export function canonicalizeOpencodeV2Message(msg) {
|
|
|
89
91
|
return null;
|
|
90
92
|
}
|
|
91
93
|
|
|
94
|
+
// ── A folder that does not exist ────────────────────────────────────────────
|
|
95
|
+
// OpenCode 2 creates a session in a folder that does not exist and then
|
|
96
|
+
// refuses every prompt of it (404 "Location not found: <folder>"); a session is
|
|
97
|
+
// bound to its folder for good. So a request that starts work in a folder is
|
|
98
|
+
// refused here, in OpenCode's own words (the panel reads one sentence for both:
|
|
99
|
+
// public/shared/ocp-v2/ocp-v2-location-logic.js), before a session is made
|
|
100
|
+
// that can never run or a serve is started for a turn that cannot begin.
|
|
101
|
+
export const OPENCODE_V2_WS_FOLDER_TYPES = Object.freeze(['session:create', 'message:send', 'command:run', 'session:shell']);
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Whether `folder` is certainly not a folder that exists: nothing is there, or
|
|
105
|
+
* something that is not a folder. A folder that cannot be asked (no permission,
|
|
106
|
+
* a disk that does not answer) is not called gone: OpenCode decides.
|
|
107
|
+
*/
|
|
108
|
+
export function folderIsGone(folder, stat = statSync) {
|
|
109
|
+
try {
|
|
110
|
+
return !stat(folder).isDirectory();
|
|
111
|
+
} catch (err) {
|
|
112
|
+
return err?.code === 'ENOENT' || err?.code === 'ENOTDIR';
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
92
116
|
/**
|
|
93
117
|
* Everything that must hold before a request is answered, in one place so it
|
|
94
118
|
* can be tested: a canonical session id, no write while history is being
|
|
95
119
|
* cleared, and the native-automation ownership rules. Returns null to let the
|
|
96
120
|
* request through, or `{ status, error }`.
|
|
97
121
|
* ctx: { historyClearing, historyWriteTypes, nativeMutationTypes,
|
|
98
|
-
* protectedRunFor(sessionId), ownsRun(run)
|
|
122
|
+
* protectedRunFor(sessionId), ownsRun(run),
|
|
123
|
+
* folderGone(folder) } folderIsGone, or absent to check no folder
|
|
124
|
+
* A refusal for a folder that is gone also carries `code` (LOCATION_MISSING).
|
|
99
125
|
*/
|
|
100
126
|
export function guardOpencodeV2Request(msg, ctx = {}) {
|
|
101
127
|
const malformed = canonicalizeOpencodeV2Message(msg);
|
|
@@ -111,6 +137,10 @@ export function guardOpencodeV2Request(msg, ctx = {}) {
|
|
|
111
137
|
if (protectedRun && ctx.nativeMutationTypes?.has(type)) {
|
|
112
138
|
return { status: 409, error: 'Stop the native automation before modifying its session' };
|
|
113
139
|
}
|
|
140
|
+
const folder = OPENCODE_V2_WS_FOLDER_TYPES.includes(type) ? directoryOf(msg) : undefined;
|
|
141
|
+
if (folder && ctx.folderGone?.(folder)) {
|
|
142
|
+
return { status: 404, code: LOCATION_MISSING_CODE, error: locationNotFoundMessage(folder) };
|
|
143
|
+
}
|
|
114
144
|
return null;
|
|
115
145
|
}
|
|
116
146
|
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
|
|
27
27
|
import { basicAuthHeader } from './opencode-protocol.js';
|
|
28
28
|
import { opencodeMcpServerEntry } from './opencode-config.js';
|
|
29
|
+
import { applyOpencodeCostOverride } from './assistant-pricing.js';
|
|
29
30
|
import {
|
|
30
31
|
answersToForm,
|
|
31
32
|
createEventTranslator,
|
|
@@ -446,7 +447,7 @@ export function createOpencode2Client({ baseUrl, password, fetchImpl = globalThi
|
|
|
446
447
|
output: flags(output),
|
|
447
448
|
interleaved: false,
|
|
448
449
|
},
|
|
449
|
-
cost: { input: Number(cost.input) || 0, output: Number(cost.output) || 0, cache: { read: Number(cost.cache?.read) || 0, write: Number(cost.cache?.write) || 0 } },
|
|
450
|
+
cost: applyOpencodeCostOverride(str(model.providerID), str(model.id), { input: Number(cost.input) || 0, output: Number(cost.output) || 0, cache: { read: Number(cost.cache?.read) || 0, write: Number(cost.cache?.write) || 0 } }),
|
|
450
451
|
limit: { context: Number(model.limit?.context) || 0, ...(model.limit?.input ? { input: Number(model.limit.input) } : {}), output: Number(model.limit?.output) || 0 },
|
|
451
452
|
status: str(model.status) || 'active',
|
|
452
453
|
options: {},
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
// app's pages and every other read still load). A failure that may pass (a timeout, a busy system) is tried once
|
|
39
39
|
// more at once and is kept on its connection for a moment only (NEGATIVE_TTL_MS), so an open tab recovers by
|
|
40
40
|
// itself; a client that left is never kept. The server probes netstat and ps once at start (probe()), keeps the
|
|
41
|
-
// state for GET /api/health (`ownerAuthority`: ok / degraded / unsupported / off), says the change in one loud log
|
|
41
|
+
// state for GET /api/health (`ownerAuthority`: pending / ok / degraded / unsupported / off), says the change in one loud log
|
|
42
42
|
// line, and the page shows a banner while it is degraded (public/shared/ui-owner-authority.js).
|
|
43
43
|
// Only a machine elsewhere on the network ('remote', below) still keeps the rules from before without a lookup: what to
|
|
44
44
|
// do about a LAN client is a separate decision (TODO(peer-identity-remote): decide the LAN policy).
|
|
@@ -707,15 +707,14 @@ export function createPeerIdentity({ platform = process.platform, selfPid = proc
|
|
|
707
707
|
const say = (line) => { try { log(line); } catch { /* a logger's own failure */ } };
|
|
708
708
|
|
|
709
709
|
// ── The state of the owner's authority (GET /api/health `ownerAuthority`, the page's banner) ──
|
|
710
|
-
//
|
|
711
|
-
//
|
|
712
|
-
// call, which needs netstat only). Each change is said once, loudly; a lookup that keeps failing is not said again.
|
|
710
|
+
// On macOS readiness is pending until the start probe or a whole lookup settles.
|
|
711
|
+
// This describes the verifier. Each request still needs its own peer verdict.
|
|
713
712
|
const iso = (ms) => { try { return new Date(ms).toISOString(); } catch { return null; } };
|
|
714
713
|
let authority = disabled
|
|
715
714
|
? { state: 'off', reason: 'SYNABUN_PEER_IDENTITY=off', retryable: false, since: iso(now()) }
|
|
716
715
|
: !supported
|
|
717
716
|
? { state: 'unsupported', reason: unsupportedReason, retryable: false, since: iso(now()) }
|
|
718
|
-
: { state: '
|
|
717
|
+
: { state: 'pending', reason: null, retryable: false, since: iso(now()) };
|
|
719
718
|
let probed = null; // the start probe's promise
|
|
720
719
|
function degrade(reason, { retryable = false, source = 'lookup' } = {}) {
|
|
721
720
|
if (!supported) return;
|
|
@@ -736,7 +735,7 @@ export function createPeerIdentity({ platform = process.platform, selfPid = proc
|
|
|
736
735
|
if (!supported || authority.state === 'ok') return;
|
|
737
736
|
const was = authority.reason;
|
|
738
737
|
authority = { state: 'ok', reason: null, retryable: false, since: iso(now()) };
|
|
739
|
-
say(`[peer-identity] owner authority restored (${source}): local programs are identified again
|
|
738
|
+
if (was) say(`[peer-identity] owner authority restored (${source}): local programs are identified again (it was: ${was})`);
|
|
740
739
|
}
|
|
741
740
|
/** What a lookup said about the lookup itself: a whole answer restores, a failure degrades (one about a single
|
|
742
741
|
* connection — it has no address any more — says nothing about the tools). */
|
|
@@ -745,7 +744,7 @@ export function createPeerIdentity({ platform = process.platform, selfPid = proc
|
|
|
745
744
|
if (verdict.status === 'unknown' && verdict.kind === 'failed') { if (!verdict.connection) degrade(verdict.reason, { retryable: verdict.retryable === true }); }
|
|
746
745
|
else if (verdict.status === 'ok' && !verdict.self) restore();
|
|
747
746
|
}
|
|
748
|
-
/** The state for GET /api/health: { state: 'ok'|'degraded'|'unsupported'|'off', reason, retryable, since }. */
|
|
747
|
+
/** The state for GET /api/health: { state: 'pending'|'ok'|'degraded'|'unsupported'|'off', reason, retryable, since }. */
|
|
749
748
|
function authorityState() {
|
|
750
749
|
return { state: authority.state, reason: authority.reason, retryable: authority.retryable === true, since: authority.since };
|
|
751
750
|
}
|
|
@@ -769,13 +768,19 @@ export function createPeerIdentity({ platform = process.platform, selfPid = proc
|
|
|
769
768
|
if (!parents.size) failures.push('ps listed no processes');
|
|
770
769
|
else if (!parents.has(selfPid)) failures.push('ps did not list this server');
|
|
771
770
|
} catch (error) { failures.push(`ps: ${failureText(error)}`); retryable = retryable || isTransientLookupError(error); }
|
|
771
|
+
// A request can finish its full lookup while this boot-time sample is in flight.
|
|
772
|
+
// Its observed outcome takes precedence over the preflight in either direction.
|
|
773
|
+
if (authority.state !== 'pending') return authorityState();
|
|
772
774
|
if (failures.length) degrade(failures.join('; '), { retryable, source: 'start probe' });
|
|
773
775
|
else {
|
|
774
776
|
say('[peer-identity] start probe: netstat and ps answer; the owner\'s authority is checked against the calling process');
|
|
775
777
|
restore('start probe');
|
|
776
778
|
}
|
|
777
779
|
return authorityState();
|
|
778
|
-
})().catch((error) => {
|
|
780
|
+
})().catch((error) => {
|
|
781
|
+
if (authority.state === 'pending') degrade(`the probe failed (${error?.message || error})`, { source: 'start probe' });
|
|
782
|
+
return authorityState();
|
|
783
|
+
});
|
|
779
784
|
return probed;
|
|
780
785
|
}
|
|
781
786
|
const isThisMachine = (addr) => {
|