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,165 @@
|
|
|
1
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
2
|
+
// A terminal block: what a shell command printed, drawn as it is read
|
|
3
|
+
//
|
|
4
|
+
// The block of the OpenCode side panel's bash card (ocp-v2-shell.js) and of the
|
|
5
|
+
// Assistant panel's shell calls (assistant/asst-shell.js). No socket, no store
|
|
6
|
+
// of its own: the caller says how to read the command's state, how to hear of a
|
|
7
|
+
// change and how to ask for the whole output, and gives the class names and the
|
|
8
|
+
// words of its own panel. The block updates itself in place (appended text,
|
|
9
|
+
// never a rebuilt card), so a long test run costs one text append per page and
|
|
10
|
+
// the reader's place in it is kept. Everything a command printed goes in as
|
|
11
|
+
// text, never as markup.
|
|
12
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
13
|
+
|
|
14
|
+
const NEAR_BOTTOM_PX = 24;
|
|
15
|
+
|
|
16
|
+
function el(tag, className, text) {
|
|
17
|
+
const node = document.createElement(tag);
|
|
18
|
+
if (className) node.className = className;
|
|
19
|
+
if (text != null) node.textContent = text;
|
|
20
|
+
return node;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* createTerminalBlock({ shellId, read, subscribe, loadAll, place, classes, words, showEvent })
|
|
25
|
+
* read() → { view, shell }: the output as far as it was read (ocp-v2-shell-logic.js
|
|
26
|
+
* createShellFollower's view) and the command ({ status, … }); either may be null
|
|
27
|
+
* subscribe(draw) → unsubscribe; `draw` is called when that command or its output changed
|
|
28
|
+
* loadAll() ask for the whole output, from its first byte
|
|
29
|
+
* place { follow, top }: where the reader left the block (kept by the caller, so a block built
|
|
30
|
+
* again for the same command opens at the same place)
|
|
31
|
+
* classes { wrap, note, noteText, load, out, foot, state, jump, copy }
|
|
32
|
+
* words { load, loading, jump, copy, copied, label, noOutputYet, noOutput, reading, running,
|
|
33
|
+
* note(view) → the line above the output when it does not show everything ('' when it does) }
|
|
34
|
+
* showEvent the event the caller dispatches on the block when it gets a size (a card opened by hand)
|
|
35
|
+
* It follows the output while the reader is at its end, and leaves the reader alone once they scrolled up.
|
|
36
|
+
*/
|
|
37
|
+
export function createTerminalBlock({ shellId, read, subscribe, loadAll, place = { follow: true, top: 0 }, classes, words, showEvent = 'shell-term-show' }) {
|
|
38
|
+
const wrap = el('div', classes.wrap);
|
|
39
|
+
wrap.dataset.shellId = shellId;
|
|
40
|
+
|
|
41
|
+
const note = el('div', classes.note);
|
|
42
|
+
const noteText = el('span', classes.noteText);
|
|
43
|
+
const loadButton = el('button', classes.load, words.load);
|
|
44
|
+
loadButton.type = 'button';
|
|
45
|
+
note.append(noteText, loadButton);
|
|
46
|
+
note.hidden = true;
|
|
47
|
+
|
|
48
|
+
const out = el('pre', classes.out);
|
|
49
|
+
out.tabIndex = 0;
|
|
50
|
+
out.setAttribute('role', 'log');
|
|
51
|
+
out.setAttribute('aria-label', words.label);
|
|
52
|
+
// A screen reader is not read every line of a test run; the card's status says when it ends.
|
|
53
|
+
out.setAttribute('aria-live', 'off');
|
|
54
|
+
const textNode = document.createTextNode('');
|
|
55
|
+
out.appendChild(textNode);
|
|
56
|
+
|
|
57
|
+
const foot = el('div', classes.foot);
|
|
58
|
+
const state = el('span', classes.state);
|
|
59
|
+
const jump = el('button', classes.jump, words.jump);
|
|
60
|
+
jump.type = 'button';
|
|
61
|
+
jump.hidden = true;
|
|
62
|
+
const copy = el('button', classes.copy, words.copy);
|
|
63
|
+
copy.type = 'button';
|
|
64
|
+
foot.append(state, jump, copy);
|
|
65
|
+
wrap.append(note, out, foot);
|
|
66
|
+
|
|
67
|
+
let shownFrom = -1;
|
|
68
|
+
let shownLength = 0;
|
|
69
|
+
let drawn = false;
|
|
70
|
+
let toTop = false; // the whole output was asked for: its first page opens at the top
|
|
71
|
+
|
|
72
|
+
const atEnd = () => out.scrollHeight - out.scrollTop - out.clientHeight < NEAR_BOTTOM_PX;
|
|
73
|
+
out.addEventListener('scroll', () => {
|
|
74
|
+
place.follow = atEnd();
|
|
75
|
+
place.top = out.scrollTop;
|
|
76
|
+
jump.hidden = place.follow;
|
|
77
|
+
});
|
|
78
|
+
jump.addEventListener('click', (event) => {
|
|
79
|
+
event.stopPropagation();
|
|
80
|
+
place.follow = true;
|
|
81
|
+
out.scrollTop = out.scrollHeight;
|
|
82
|
+
jump.hidden = true;
|
|
83
|
+
});
|
|
84
|
+
loadButton.addEventListener('click', (event) => {
|
|
85
|
+
event.stopPropagation();
|
|
86
|
+
loadButton.disabled = true;
|
|
87
|
+
loadButton.textContent = words.loading;
|
|
88
|
+
// The whole output is read from its start: the reader starts at its top.
|
|
89
|
+
place.follow = false;
|
|
90
|
+
place.top = 0;
|
|
91
|
+
toTop = true;
|
|
92
|
+
loadAll();
|
|
93
|
+
});
|
|
94
|
+
copy.addEventListener('click', async (event) => {
|
|
95
|
+
event.stopPropagation();
|
|
96
|
+
try {
|
|
97
|
+
await navigator.clipboard.writeText(textNode.data);
|
|
98
|
+
copy.textContent = words.copied;
|
|
99
|
+
setTimeout(() => { if (copy.isConnected) copy.textContent = words.copy; }, 1200);
|
|
100
|
+
} catch { /* clipboard unavailable */ }
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
function draw() {
|
|
104
|
+
const current = read() || {};
|
|
105
|
+
const view = current.view || null;
|
|
106
|
+
const running = current.shell?.status === 'running';
|
|
107
|
+
const text = view?.text || '';
|
|
108
|
+
const from = view ? view.from : 0;
|
|
109
|
+
// Appended when the kept text only grew; set anew when its start moved (a long output's window, the full output).
|
|
110
|
+
// A carriage return rewrites the line it is on and never one before it, so of what is shown only its last line
|
|
111
|
+
// can have changed: compared, and replaced when it did (review S6: a progress line of the same width or longer
|
|
112
|
+
// kept showing, and copying, its first state).
|
|
113
|
+
if (drawn && from === shownFrom && textNode.data.length === shownLength) {
|
|
114
|
+
const stable = textNode.data.lastIndexOf('\n') + 1;
|
|
115
|
+
if (text.length >= shownLength && text.slice(stable, shownLength) === textNode.data.slice(stable)) {
|
|
116
|
+
if (text.length > shownLength) textNode.appendData(text.slice(shownLength));
|
|
117
|
+
} else if (text.slice(0, stable) === textNode.data.slice(0, stable)) {
|
|
118
|
+
textNode.replaceData(stable, shownLength - stable, text.slice(stable));
|
|
119
|
+
} else {
|
|
120
|
+
textNode.data = text;
|
|
121
|
+
}
|
|
122
|
+
} else if (!drawn || from !== shownFrom || text.length !== shownLength) {
|
|
123
|
+
textNode.data = text;
|
|
124
|
+
if (toTop && view?.full) { toTop = false; out.scrollTop = 0; }
|
|
125
|
+
}
|
|
126
|
+
shownFrom = from;
|
|
127
|
+
shownLength = text.length;
|
|
128
|
+
|
|
129
|
+
const noteWords = words.note(view);
|
|
130
|
+
note.hidden = !noteWords;
|
|
131
|
+
noteText.textContent = noteWords;
|
|
132
|
+
const canLoad = !!view && view.partial && !view.full && !view.gone;
|
|
133
|
+
loadButton.hidden = !canLoad;
|
|
134
|
+
if (canLoad) { loadButton.disabled = false; loadButton.textContent = words.load; }
|
|
135
|
+
|
|
136
|
+
wrap.dataset.running = running ? 'true' : 'false';
|
|
137
|
+
state.textContent = view?.error && !view.done ? view.error
|
|
138
|
+
: !text && running ? words.noOutputYet
|
|
139
|
+
: !text && view && (view.done || view.gone) ? words.noOutput
|
|
140
|
+
: !text ? words.reading
|
|
141
|
+
: running ? words.running : '';
|
|
142
|
+
copy.hidden = !text;
|
|
143
|
+
out.hidden = !text;
|
|
144
|
+
|
|
145
|
+
if (!drawn) {
|
|
146
|
+
drawn = true;
|
|
147
|
+
out.scrollTop = place.follow ? out.scrollHeight : place.top;
|
|
148
|
+
} else if (place.follow) {
|
|
149
|
+
out.scrollTop = out.scrollHeight;
|
|
150
|
+
}
|
|
151
|
+
jump.hidden = place.follow || !text;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const unsubscribe = subscribe(() => {
|
|
155
|
+
if (!wrap.isConnected) { unsubscribe(); return; }
|
|
156
|
+
draw();
|
|
157
|
+
});
|
|
158
|
+
draw();
|
|
159
|
+
// The block is measured once it is in the page (a card built open, or opened later).
|
|
160
|
+
const settle = () => { if (wrap.isConnected) out.scrollTop = place.follow ? out.scrollHeight : place.top; };
|
|
161
|
+
globalThis.requestAnimationFrame?.(settle);
|
|
162
|
+
// A card opened by hand shows its block for the first time: it has a height only now.
|
|
163
|
+
wrap.addEventListener(showEvent, settle);
|
|
164
|
+
return wrap;
|
|
165
|
+
}
|
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
2
|
+
// OpenCode V2 — a shell command's output, live (no DOM, no socket)
|
|
3
|
+
//
|
|
4
|
+
// OpenCode 2 does not send what a command prints with its tool call: it keeps
|
|
5
|
+
// the combined stdout and stderr, in the order written, and answers pages of it
|
|
6
|
+
// by byte position while the command runs and after (`shell:output`). This
|
|
7
|
+
// module reads those pages and keeps what the transcript shows:
|
|
8
|
+
// createTerminalBuffer() the text as a terminal would leave it, windowed
|
|
9
|
+
// createShellFollower() reads one command to its end, then stops
|
|
10
|
+
// followShells() one follower per command of a store's session
|
|
11
|
+
// shellCardState() what a command means for its tool card
|
|
12
|
+
// The store holds the result (shellOutput), ocp-v2-shell.js draws it.
|
|
13
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
14
|
+
|
|
15
|
+
/** What the transcript keeps of one command's output until the reader asks for all of it. */
|
|
16
|
+
export const SHELL_WINDOW_CHARS = 256 * 1024;
|
|
17
|
+
/** The most "Load full output" keeps in the page; a longer output says so and names where it stops. */
|
|
18
|
+
export const SHELL_FULL_MAX_CHARS = 8 * 1024 * 1024;
|
|
19
|
+
/** How often a running command is asked for more: at once while it prints, slower while it is quiet. */
|
|
20
|
+
export const SHELL_POLL_MIN_MS = 400;
|
|
21
|
+
export const SHELL_POLL_MAX_MS = 2500;
|
|
22
|
+
|
|
23
|
+
// CSI / OSC sequences and the other escapes a test runner colours its lines with.
|
|
24
|
+
// eslint-disable-next-line no-control-regex
|
|
25
|
+
const ANSI = /\x1b\[[0-9;?]*[ -/]*[@-~]|\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)|\x1b[@-Z\\-_]/g;
|
|
26
|
+
// A sequence the page cut in two waits for its other half.
|
|
27
|
+
// eslint-disable-next-line no-control-regex
|
|
28
|
+
const ANSI_TAIL = /\x1b(?:\[[0-9;?]*[ -/]*|\][^\x07\x1b]*)?$/;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The text of a command as a terminal would leave it: escape sequences gone, a
|
|
32
|
+
* line rewritten with a carriage return (a progress bar) kept as its last
|
|
33
|
+
* form, CRLF as one line end. At most `maxChars` are kept: the oldest whole
|
|
34
|
+
* lines go first, and `dropped` counts the characters that went.
|
|
35
|
+
*/
|
|
36
|
+
export function createTerminalBuffer({ maxChars = SHELL_WINDOW_CHARS } = {}) {
|
|
37
|
+
let text = '';
|
|
38
|
+
let dropped = 0;
|
|
39
|
+
let pending = ''; // an escape sequence, or a lone "\r", still waiting for what follows
|
|
40
|
+
let limit = Math.max(1024, Number(maxChars) || SHELL_WINDOW_CHARS);
|
|
41
|
+
|
|
42
|
+
function trim() {
|
|
43
|
+
if (text.length <= limit) return;
|
|
44
|
+
let cut = text.length - limit;
|
|
45
|
+
const lineEnd = text.indexOf('\n', cut);
|
|
46
|
+
// The line that crosses the limit goes whole, unless it is the last one.
|
|
47
|
+
if (lineEnd !== -1 && lineEnd < text.length - 1) cut = lineEnd + 1;
|
|
48
|
+
dropped += cut;
|
|
49
|
+
text = text.slice(cut);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function append(chunk) {
|
|
53
|
+
let incoming = pending + String(chunk ?? '');
|
|
54
|
+
pending = '';
|
|
55
|
+
const tail = ANSI_TAIL.exec(incoming);
|
|
56
|
+
if (tail) { pending = tail[0]; incoming = incoming.slice(0, tail.index); }
|
|
57
|
+
if (incoming.endsWith('\r')) { pending = `\r${pending}`; incoming = incoming.slice(0, -1); }
|
|
58
|
+
incoming = incoming.replace(ANSI, '').replace(/\r\n/g, '\n');
|
|
59
|
+
if (!incoming) return;
|
|
60
|
+
if (incoming.includes('\r')) {
|
|
61
|
+
// A carriage return goes back to the start of the line: what follows replaces it.
|
|
62
|
+
for (const piece of incoming.split(/(\r)/)) {
|
|
63
|
+
if (piece === '\r') text = text.slice(0, text.lastIndexOf('\n') + 1);
|
|
64
|
+
else text += piece;
|
|
65
|
+
}
|
|
66
|
+
} else {
|
|
67
|
+
text += incoming;
|
|
68
|
+
}
|
|
69
|
+
trim();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
append,
|
|
74
|
+
text: () => text,
|
|
75
|
+
/** Characters no longer kept (the start of a long output). */
|
|
76
|
+
dropped: () => dropped,
|
|
77
|
+
setLimit(maxChars) { limit = Math.max(1024, Number(maxChars) || limit); trim(); },
|
|
78
|
+
reset() { text = ''; dropped = 0; pending = ''; },
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const replyFailed = (res) => !res || res.ok === false || (typeof res.status === 'number' && res.status >= 400);
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Reads one command's output to its end.
|
|
86
|
+
* api.shellOutput({ sessionId, shellId, cwd, cursor, tail, limit }) → { data: { output, cursor, size, from } }
|
|
87
|
+
* isRunning() the command still runs (the store's word); once it does not,
|
|
88
|
+
* a read that brings nothing new is the last one
|
|
89
|
+
* isCurrent() false once the panel left the session: nothing more is read
|
|
90
|
+
* onUpdate(view) { text, from, size, done, gone, error, full, capped } after every page
|
|
91
|
+
* The first read starts `window` characters before the end (a panel that opens
|
|
92
|
+
* on a long output shows its end at once); `loadAll()` reads it again from its
|
|
93
|
+
* first byte. Nothing is polled once the command ended and was read to its end.
|
|
94
|
+
*/
|
|
95
|
+
export function createShellFollower({
|
|
96
|
+
api, sessionId, shellId, cwd, isRunning = () => false, isCurrent = () => true, onUpdate = () => {},
|
|
97
|
+
windowChars = SHELL_WINDOW_CHARS, setTimer = setTimeout, clearTimer = clearTimeout,
|
|
98
|
+
} = {}) {
|
|
99
|
+
const buffer = createTerminalBuffer({ maxChars: windowChars });
|
|
100
|
+
let cursor = null; // null: nothing read yet (the first read asks for the tail)
|
|
101
|
+
let from = 0; // the byte the kept text starts at, as far as the server said
|
|
102
|
+
let size = 0;
|
|
103
|
+
let timer = null;
|
|
104
|
+
let reading = false;
|
|
105
|
+
let stopped = false;
|
|
106
|
+
let done = false;
|
|
107
|
+
let gone = false;
|
|
108
|
+
let error = '';
|
|
109
|
+
let full = false;
|
|
110
|
+
let capped = false;
|
|
111
|
+
let delay = SHELL_POLL_MIN_MS;
|
|
112
|
+
let failures = 0;
|
|
113
|
+
let generation = 0; // a read begun before loadAll() belongs to the reading it replaced
|
|
114
|
+
|
|
115
|
+
const view = () => ({
|
|
116
|
+
text: buffer.text(), from: from + buffer.dropped(), size, done, gone, error, full, capped,
|
|
117
|
+
// Something of the output is not in `text` (its start): the reader can ask for it.
|
|
118
|
+
partial: from + buffer.dropped() > 0,
|
|
119
|
+
});
|
|
120
|
+
const publish = () => { try { onUpdate(view()); } catch (err) { console.warn('[ocp-v2-shell] update failed', err); } };
|
|
121
|
+
|
|
122
|
+
function schedule(ms) {
|
|
123
|
+
if (stopped || done || gone) return;
|
|
124
|
+
if (timer) clearTimer(timer);
|
|
125
|
+
timer = setTimer(() => { timer = null; read(); }, ms);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async function read() {
|
|
129
|
+
if (stopped || done || gone || reading) return;
|
|
130
|
+
if (!isCurrent()) { stop(); return; }
|
|
131
|
+
reading = true;
|
|
132
|
+
const mine = generation;
|
|
133
|
+
const wasRunning = isRunning();
|
|
134
|
+
let res;
|
|
135
|
+
try {
|
|
136
|
+
res = await api.shellOutput(cursor == null
|
|
137
|
+
? { sessionId, shellId, cwd, tail: full ? undefined : windowChars, cursor: full ? 0 : undefined }
|
|
138
|
+
: { sessionId, shellId, cwd, cursor });
|
|
139
|
+
} catch (err) { res = { ok: false, error: err?.message || String(err) }; }
|
|
140
|
+
reading = false;
|
|
141
|
+
if (stopped) return;
|
|
142
|
+
if (mine !== generation) { schedule(0); return; }
|
|
143
|
+
if (!isCurrent()) { stop(); return; }
|
|
144
|
+
if (replyFailed(res) || !res.data || typeof res.data !== 'object') {
|
|
145
|
+
// OpenCode keeps a finished command's output for a while only.
|
|
146
|
+
if (res?.status === 404) { gone = true; publish(); return; }
|
|
147
|
+
failures += 1;
|
|
148
|
+
error = (typeof res?.error === 'string' && res.error) || 'The output could not be read.';
|
|
149
|
+
if (failures >= 5 && !isRunning()) { done = true; publish(); return; }
|
|
150
|
+
publish();
|
|
151
|
+
schedule(Math.min(SHELL_POLL_MAX_MS * 2, SHELL_POLL_MIN_MS * 2 ** failures));
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
failures = 0;
|
|
155
|
+
error = '';
|
|
156
|
+
const page = res.data;
|
|
157
|
+
const text = typeof page.output === 'string' ? page.output : '';
|
|
158
|
+
if (cursor == null) from = Math.max(0, Number(page.from) || 0);
|
|
159
|
+
const next = Math.max(0, Number(page.cursor) || 0);
|
|
160
|
+
size = Math.max(next, Number(page.size) || 0);
|
|
161
|
+
const moved = cursor == null || next > cursor;
|
|
162
|
+
if (text) buffer.append(text);
|
|
163
|
+
cursor = next;
|
|
164
|
+
if (full && buffer.dropped() > 0) capped = true;
|
|
165
|
+
const behind = cursor < size;
|
|
166
|
+
// Read to its end after the command stopped (as it was before this read): nothing more will come.
|
|
167
|
+
if (!wasRunning && !isRunning() && !behind && !text) done = true;
|
|
168
|
+
else if (!wasRunning && !isRunning() && !behind) { publish(); schedule(0); return; }
|
|
169
|
+
publish();
|
|
170
|
+
if (done) return;
|
|
171
|
+
if (behind) { delay = SHELL_POLL_MIN_MS; schedule(0); return; }
|
|
172
|
+
delay = moved && text ? SHELL_POLL_MIN_MS : Math.min(SHELL_POLL_MAX_MS, Math.round(delay * 1.5));
|
|
173
|
+
schedule(isRunning() ? delay : 0);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function stop() {
|
|
177
|
+
stopped = true;
|
|
178
|
+
if (timer) { clearTimer(timer); timer = null; }
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return {
|
|
182
|
+
start() { if (cursor == null && !reading) read(); },
|
|
183
|
+
stop,
|
|
184
|
+
/** The store says the command changed (it ended): read now instead of at the next tick. */
|
|
185
|
+
poke() { if (!done && !gone && !stopped) schedule(0); },
|
|
186
|
+
/** Read the whole output again, from its first byte, keeping up to SHELL_FULL_MAX_CHARS. */
|
|
187
|
+
loadAll() {
|
|
188
|
+
if (stopped) return;
|
|
189
|
+
generation += 1;
|
|
190
|
+
full = true;
|
|
191
|
+
capped = false;
|
|
192
|
+
done = false;
|
|
193
|
+
gone = false;
|
|
194
|
+
buffer.reset();
|
|
195
|
+
buffer.setLimit(SHELL_FULL_MAX_CHARS);
|
|
196
|
+
cursor = null;
|
|
197
|
+
from = 0;
|
|
198
|
+
schedule(0);
|
|
199
|
+
},
|
|
200
|
+
view,
|
|
201
|
+
isDone: () => done || gone,
|
|
202
|
+
isStopped: () => stopped,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Keeps one follower per command of the store's session, for as long as the
|
|
208
|
+
* store is on that session: started when a command appears (an event, or the
|
|
209
|
+
* server's list after a reload), stopped when the store moves to another
|
|
210
|
+
* session. `supported()`: the server answers `shell:output` (an older one does
|
|
211
|
+
* not, and the cards then show what the tool call itself returned).
|
|
212
|
+
* Finished commands no block shows keep their text up to `kept` (the oldest
|
|
213
|
+
* goes first, review S5: a long session kept up to 8 MB of text per command it
|
|
214
|
+
* ever ran); one that comes on screen again is read afresh (watch).
|
|
215
|
+
* Returns { loadAll(shellId), watch(shellId) → release, has(shellId), stop() }.
|
|
216
|
+
*/
|
|
217
|
+
export const SHELL_OUTPUT_KEPT_FINISHED = 12;
|
|
218
|
+
|
|
219
|
+
export function followShells(store, api, { supported = () => true, setTimer, clearTimer, kept = SHELL_OUTPUT_KEPT_FINISHED } = {}) {
|
|
220
|
+
const followers = new Map(); // shellId → follower
|
|
221
|
+
const usedAt = new Map(); // shellId → when its output was last read or shown
|
|
222
|
+
const watched = new Map(); // shellId → how many blocks show it
|
|
223
|
+
const evicted = new Set(); // finished commands whose text was let go: read again only when shown
|
|
224
|
+
let clock = 0;
|
|
225
|
+
let stopped = false;
|
|
226
|
+
let binding = typeof store.getBinding === 'function' ? store.getBinding() : 0;
|
|
227
|
+
const bindingNow = () => (typeof store.getBinding === 'function' ? store.getBinding() : 0);
|
|
228
|
+
|
|
229
|
+
function clear() {
|
|
230
|
+
for (const follower of followers.values()) follower.stop();
|
|
231
|
+
followers.clear();
|
|
232
|
+
usedAt.clear();
|
|
233
|
+
evicted.clear();
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/** Let go of the text of finished commands nobody looks at, beyond `kept`. */
|
|
237
|
+
function trim() {
|
|
238
|
+
const idle = [...followers].filter(([id, follower]) => follower.isDone() && !watched.get(id)
|
|
239
|
+
&& store.getState().shells.get(id)?.status !== 'running');
|
|
240
|
+
if (idle.length <= kept) return;
|
|
241
|
+
idle.sort((a, b) => (usedAt.get(a[0]) || 0) - (usedAt.get(b[0]) || 0));
|
|
242
|
+
for (const [id, follower] of idle.slice(0, idle.length - kept)) {
|
|
243
|
+
follower.stop();
|
|
244
|
+
followers.delete(id);
|
|
245
|
+
usedAt.delete(id);
|
|
246
|
+
evicted.add(id);
|
|
247
|
+
store.setShellOutput(id, null);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function follow(shellId) {
|
|
252
|
+
const state = store.getState();
|
|
253
|
+
const mine = binding;
|
|
254
|
+
const follower = createShellFollower({
|
|
255
|
+
api, sessionId: state.sessionId, shellId, cwd: state.cwd || state.sessionInfo?.directory || undefined,
|
|
256
|
+
isRunning: () => store.getState().shells.get(shellId)?.status === 'running',
|
|
257
|
+
isCurrent: () => !stopped && bindingNow() === mine,
|
|
258
|
+
onUpdate: (view) => {
|
|
259
|
+
if (stopped || bindingNow() !== mine || followers.get(shellId) !== follower) return;
|
|
260
|
+
usedAt.set(shellId, ++clock);
|
|
261
|
+
store.setShellOutput(shellId, view);
|
|
262
|
+
if (view?.done || view?.gone) trim();
|
|
263
|
+
},
|
|
264
|
+
...(setTimer ? { setTimer } : {}), ...(clearTimer ? { clearTimer } : {}),
|
|
265
|
+
});
|
|
266
|
+
followers.set(shellId, follower);
|
|
267
|
+
usedAt.set(shellId, ++clock);
|
|
268
|
+
follower.start();
|
|
269
|
+
return follower;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function sync() {
|
|
273
|
+
if (stopped) return;
|
|
274
|
+
const now = bindingNow();
|
|
275
|
+
if (now !== binding) { binding = now; clear(); }
|
|
276
|
+
const state = store.getState();
|
|
277
|
+
if (!state.sessionId || !supported() || typeof api?.shellOutput !== 'function') return;
|
|
278
|
+
for (const [shellId, shell] of state.shells) {
|
|
279
|
+
const follower = followers.get(shellId);
|
|
280
|
+
if (!follower) {
|
|
281
|
+
if (!evicted.has(shellId)) follow(shellId);
|
|
282
|
+
} else if (shell.status !== 'running') {
|
|
283
|
+
follower.poke();
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const unsubscribe = store.subscribe((event) => {
|
|
289
|
+
if (event?.type === 'shell:update' || event?.type === 'session:set') sync();
|
|
290
|
+
});
|
|
291
|
+
sync();
|
|
292
|
+
return {
|
|
293
|
+
loadAll(shellId) { followers.get(shellId)?.loadAll(); },
|
|
294
|
+
/** A block shows `shellId`: its text is kept (and read again if it was let go) until the release. */
|
|
295
|
+
watch(shellId) {
|
|
296
|
+
if (stopped) return () => {};
|
|
297
|
+
watched.set(shellId, (watched.get(shellId) || 0) + 1);
|
|
298
|
+
usedAt.set(shellId, ++clock);
|
|
299
|
+
if (evicted.delete(shellId) && store.getState().shells.has(shellId) && supported()) follow(shellId);
|
|
300
|
+
let released = false;
|
|
301
|
+
return () => {
|
|
302
|
+
if (released) return;
|
|
303
|
+
released = true;
|
|
304
|
+
const left = (watched.get(shellId) || 1) - 1;
|
|
305
|
+
if (left > 0) watched.set(shellId, left); else watched.delete(shellId);
|
|
306
|
+
trim();
|
|
307
|
+
};
|
|
308
|
+
},
|
|
309
|
+
has: (shellId) => followers.has(shellId),
|
|
310
|
+
stop() { stopped = true; try { unsubscribe(); } catch { /* gone */ } clear(); watched.clear(); },
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* What a command means for the card of its tool call.
|
|
316
|
+
* status 'running' | 'completed' | 'error' | '' (the call's own status stands)
|
|
317
|
+
* note a few words for the card's head ("in the background", "exit 1", "stopped")
|
|
318
|
+
*/
|
|
319
|
+
export function shellCardState(shell) {
|
|
320
|
+
if (!shell || typeof shell !== 'object') return { status: '', note: '', running: false };
|
|
321
|
+
if (shell.status === 'running') {
|
|
322
|
+
return { status: 'running', note: shell.background ? 'in the background' : '', running: true };
|
|
323
|
+
}
|
|
324
|
+
if (shell.status === 'killed') return { status: 'error', note: 'stopped', running: false };
|
|
325
|
+
if (shell.status === 'timeout') return { status: 'error', note: 'timed out', running: false };
|
|
326
|
+
const exit = typeof shell.exit === 'number' ? shell.exit : null;
|
|
327
|
+
if (exit != null && exit !== 0) return { status: shell.background ? 'error' : '', note: `exit ${exit}`, running: false };
|
|
328
|
+
return { status: shell.background ? 'completed' : '', note: '', running: false };
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/** "1.2 MB", "340 KB", "512 B". */
|
|
332
|
+
export function formatBytes(bytes) {
|
|
333
|
+
const n = Math.max(0, Number(bytes) || 0);
|
|
334
|
+
if (n >= 1024 * 1024) return `${(n / (1024 * 1024)).toFixed(1)} MB`;
|
|
335
|
+
if (n >= 1024) return `${Math.round(n / 1024)} KB`;
|
|
336
|
+
return `${n} B`;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/** The line above a terminal block when it does not show everything: '' when it does. */
|
|
340
|
+
export function shellOutputNote(view) {
|
|
341
|
+
if (!view) return '';
|
|
342
|
+
if (view.gone) return 'OpenCode no longer keeps the output of this command.';
|
|
343
|
+
if (view.capped) return `Showing the last ${formatBytes(view.text.length)} of ${formatBytes(view.size)}: the whole output is too long to show here.`;
|
|
344
|
+
if (view.partial) return `Showing the last ${formatBytes(view.text.length)} of ${formatBytes(view.size)}.`;
|
|
345
|
+
return '';
|
|
346
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
2
|
+
// OpenCode V2 — a tool card's terminal block
|
|
3
|
+
// What a shell command printed, live: stdout and stderr in the order written,
|
|
4
|
+
// read by ocp-v2-shell-logic.js into the store (shellOutput) and drawn here.
|
|
5
|
+
// The block updates itself in place (appended text, never a rebuilt card), so
|
|
6
|
+
// a long test run costs one text append per page and the reader's place in it
|
|
7
|
+
// is kept. Everything a command printed goes in as text, never as markup.
|
|
8
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
9
|
+
|
|
10
|
+
import { api, supports } from './ocp-v2-ws.js';
|
|
11
|
+
import { followShells, shellOutputNote } from './ocp-v2-shell-logic.js';
|
|
12
|
+
import { createTerminalBlock } from './ocp-v2-shell-block.js';
|
|
13
|
+
|
|
14
|
+
// One set of followers per store (the primary panel and every sub-agent panel), for as long as a renderer of that
|
|
15
|
+
// store is mounted (review S5: they used to outlive every view, polling a session nobody showed any more).
|
|
16
|
+
const _followers = new WeakMap();
|
|
17
|
+
const _holders = new WeakMap(); // store → how many mounted renderers hold its followers
|
|
18
|
+
// Where the reader left each block: { follow, top }. A card is built again
|
|
19
|
+
// when its command ends; the block that replaces it opens at the same place.
|
|
20
|
+
const _places = new Map();
|
|
21
|
+
|
|
22
|
+
/** Follow the commands of `store`'s session (idempotent per store). */
|
|
23
|
+
export function ensureShellFollowing(store) {
|
|
24
|
+
let following = _followers.get(store);
|
|
25
|
+
if (!following) {
|
|
26
|
+
following = followShells(store, api, { supported: () => supports('shell:output') });
|
|
27
|
+
_followers.set(store, following);
|
|
28
|
+
}
|
|
29
|
+
return following;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* A renderer of `store` is mounted: its commands are followed until every renderer that holds them released them
|
|
34
|
+
* (the last unmount stops the followers and lets their text go).
|
|
35
|
+
*/
|
|
36
|
+
export function retainShellFollowing(store) {
|
|
37
|
+
ensureShellFollowing(store);
|
|
38
|
+
_holders.set(store, (_holders.get(store) || 0) + 1);
|
|
39
|
+
let released = false;
|
|
40
|
+
return () => {
|
|
41
|
+
if (released) return;
|
|
42
|
+
released = true;
|
|
43
|
+
const left = (_holders.get(store) || 1) - 1;
|
|
44
|
+
if (left > 0) { _holders.set(store, left); return; }
|
|
45
|
+
_holders.delete(store);
|
|
46
|
+
const following = _followers.get(store);
|
|
47
|
+
_followers.delete(store);
|
|
48
|
+
following?.stop();
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Whether the server can be asked for a command's output (an older one cannot). */
|
|
53
|
+
export function shellOutputSupported() {
|
|
54
|
+
return supports('shell:output');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The terminal block of `shellId`: a note when not everything is shown, the
|
|
59
|
+
* output, and its actions (ocp-v2-shell-block.js). It follows the output while
|
|
60
|
+
* the reader is at its end, and leaves the reader alone once they scrolled up.
|
|
61
|
+
*/
|
|
62
|
+
export function renderShellTerminal(store, shellId) {
|
|
63
|
+
const following = ensureShellFollowing(store);
|
|
64
|
+
const place = _places.get(shellId) || { follow: true, top: 0 };
|
|
65
|
+
_places.set(shellId, place);
|
|
66
|
+
return createTerminalBlock({
|
|
67
|
+
shellId,
|
|
68
|
+
place,
|
|
69
|
+
showEvent: 'ocpv2-term-show',
|
|
70
|
+
read: () => {
|
|
71
|
+
const s = store.getState();
|
|
72
|
+
return { view: s.shellOutput.get(shellId) || null, shell: s.shells.get(shellId) || null };
|
|
73
|
+
},
|
|
74
|
+
// While the block is on screen its command's text is kept (and read again if it was let go).
|
|
75
|
+
subscribe: (draw) => {
|
|
76
|
+
const off = store.subscribe((event) => {
|
|
77
|
+
if (event?.type === 'shell:output' ? event.shellId === shellId : event?.type === 'shell:update') draw();
|
|
78
|
+
});
|
|
79
|
+
const release = following.watch ? following.watch(shellId) : () => {};
|
|
80
|
+
return () => { try { off(); } finally { release(); } };
|
|
81
|
+
},
|
|
82
|
+
loadAll: () => following.loadAll(shellId),
|
|
83
|
+
classes: {
|
|
84
|
+
wrap: 'ocpv2-term',
|
|
85
|
+
note: 'ocpv2-term-note',
|
|
86
|
+
noteText: 'ocpv2-term-note-text',
|
|
87
|
+
load: 'ocpv2-tc-more ocpv2-term-load',
|
|
88
|
+
out: 'ocpv2-tool-output ocpv2-term-out',
|
|
89
|
+
foot: 'ocpv2-term-foot',
|
|
90
|
+
state: 'ocpv2-term-state',
|
|
91
|
+
jump: 'ocpv2-tc-more ocpv2-term-jump',
|
|
92
|
+
copy: 'ocpv2-msg-action ocpv2-term-copy',
|
|
93
|
+
},
|
|
94
|
+
words: {
|
|
95
|
+
load: 'Load full output',
|
|
96
|
+
loading: 'Loading…',
|
|
97
|
+
jump: 'Jump to latest',
|
|
98
|
+
copy: 'Copy output',
|
|
99
|
+
copied: 'Copied',
|
|
100
|
+
label: 'Command output',
|
|
101
|
+
noOutputYet: 'No output yet',
|
|
102
|
+
noOutput: 'No output',
|
|
103
|
+
reading: 'Reading the output…',
|
|
104
|
+
running: 'Running',
|
|
105
|
+
note: shellOutputNote,
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
}
|