synabun 2.4.2 → 2.4.4
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 +39 -0
- package/README.md +1 -1
- package/docs/browser-extension-bridge.md +83 -34
- package/lib/release-npm-ci.mjs +23 -1
- package/mcp-server/dist/http.d.ts.map +1 -1
- package/mcp-server/dist/http.js +8 -1
- package/mcp-server/dist/http.js.map +1 -1
- package/mcp-server/dist/services/identity.d.ts +2 -0
- package/mcp-server/dist/services/identity.d.ts.map +1 -1
- package/mcp-server/dist/services/identity.js +4 -0
- package/mcp-server/dist/services/identity.js.map +1 -1
- package/mcp-server/dist/services/memory-client.d.ts +5 -0
- package/mcp-server/dist/services/memory-client.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-client.js +21 -2
- package/mcp-server/dist/services/memory-client.js.map +1 -1
- package/mcp-server/dist/services/memory-writer.d.ts +3 -0
- package/mcp-server/dist/services/memory-writer.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-writer.js +7 -1
- package/mcp-server/dist/services/memory-writer.js.map +1 -1
- package/mcp-server/dist/services/neural-interface.d.ts +11 -1
- package/mcp-server/dist/services/neural-interface.d.ts.map +1 -1
- package/mcp-server/dist/services/neural-interface.js +68 -18
- package/mcp-server/dist/services/neural-interface.js.map +1 -1
- package/mcp-server/dist/services/typesafe-config.d.ts +38 -2
- package/mcp-server/dist/services/typesafe-config.d.ts.map +1 -1
- package/mcp-server/dist/services/typesafe-config.js +260 -8
- package/mcp-server/dist/services/typesafe-config.js.map +1 -1
- package/mcp-server/dist/tools/agent-definition.d.ts +2 -2
- package/mcp-server/dist/tools/agents.d.ts +3 -1
- package/mcp-server/dist/tools/agents.d.ts.map +1 -1
- package/mcp-server/dist/tools/agents.js +11 -6
- package/mcp-server/dist/tools/agents.js.map +1 -1
- package/mcp-server/dist/tools/browser-extension-setup.d.ts.map +1 -1
- package/mcp-server/dist/tools/browser-extension-setup.js +8 -2
- package/mcp-server/dist/tools/browser-extension-setup.js.map +1 -1
- package/mcp-server/dist/tools/browser-observe.d.ts +11 -0
- package/mcp-server/dist/tools/browser-observe.d.ts.map +1 -1
- package/mcp-server/dist/tools/browser-observe.js +113 -27
- package/mcp-server/dist/tools/browser-observe.js.map +1 -1
- package/mcp-server/dist/tools/browser-readers.d.ts +6 -0
- package/mcp-server/dist/tools/browser-readers.d.ts.map +1 -0
- package/mcp-server/dist/tools/browser-readers.js +17 -0
- package/mcp-server/dist/tools/browser-readers.js.map +1 -0
- package/mcp-server/dist/tools/remember.d.ts.map +1 -1
- package/mcp-server/dist/tools/remember.js +6 -2
- package/mcp-server/dist/tools/remember.js.map +1 -1
- package/mcp-server/dist/tools/youtube/analytics.d.ts +4 -0
- package/mcp-server/dist/tools/youtube/analytics.d.ts.map +1 -1
- package/mcp-server/dist/tools/youtube/analytics.js +25 -20
- package/mcp-server/dist/tools/youtube/analytics.js.map +1 -1
- package/mcp-server/dist/tools/youtube/helpers.d.ts +5 -1
- package/mcp-server/dist/tools/youtube/helpers.d.ts.map +1 -1
- package/mcp-server/dist/tools/youtube/helpers.js +7 -3
- package/mcp-server/dist/tools/youtube/helpers.js.map +1 -1
- package/mcp-server/dist/tools/youtube/navigate.d.ts +2 -0
- package/mcp-server/dist/tools/youtube/navigate.d.ts.map +1 -1
- package/mcp-server/dist/tools/youtube/navigate.js +5 -3
- package/mcp-server/dist/tools/youtube/navigate.js.map +1 -1
- package/mcp-server/dist/tools/youtube/playlist.js +2 -2
- package/mcp-server/dist/tools/youtube/playlist.js.map +1 -1
- package/mcp-server/dist/tools/youtube/readers.d.ts +4 -0
- package/mcp-server/dist/tools/youtube/readers.d.ts.map +1 -0
- package/mcp-server/dist/tools/youtube/readers.js +15 -0
- package/mcp-server/dist/tools/youtube/readers.js.map +1 -0
- package/mcp-server/package-lock.json +5 -5
- package/mcp-server/package.json +1 -1
- package/mcp-server/src/http.ts +8 -1
- package/mcp-server/src/services/identity.ts +5 -0
- package/mcp-server/src/services/memory-client.ts +32 -12
- package/mcp-server/src/services/memory-writer.ts +5 -2
- package/mcp-server/src/services/neural-interface.ts +66 -19
- package/mcp-server/src/services/typesafe-config.ts +268 -7
- package/mcp-server/src/tools/agents.ts +12 -6
- package/mcp-server/src/tools/browser-extension-setup.ts +8 -2
- package/mcp-server/src/tools/browser-observe.ts +117 -28
- package/mcp-server/src/tools/browser-readers.ts +19 -0
- package/mcp-server/src/tools/remember.ts +6 -1
- package/mcp-server/src/tools/youtube/analytics.ts +26 -28
- package/mcp-server/src/tools/youtube/helpers.ts +8 -2
- package/mcp-server/src/tools/youtube/navigate.ts +6 -7
- package/mcp-server/src/tools/youtube/playlist.ts +2 -2
- package/mcp-server/src/tools/youtube/readers.ts +15 -0
- package/neural-interface/i18n/en.json +189 -1
- package/neural-interface/i18n/pt-BR.json +196 -8
- package/neural-interface/lib/assistant-api.js +123 -0
- package/neural-interface/lib/assistant-brains/claude.js +10 -0
- package/neural-interface/lib/assistant-brains/opencode.js +121 -7
- package/neural-interface/lib/assistant-dispatch.js +302 -44
- package/neural-interface/lib/assistant-envelope.js +40 -0
- package/neural-interface/lib/assistant-memory.js +3 -1
- package/neural-interface/lib/assistant-persona.js +6 -0
- package/neural-interface/lib/assistant-router.js +18 -8
- package/neural-interface/lib/assistant-runtime.js +182 -11
- package/neural-interface/lib/assistant-task-prompt.js +15 -2
- package/neural-interface/lib/browser-connection-state.js +20 -0
- package/neural-interface/lib/browser-extension-adapter.js +221 -17
- package/neural-interface/lib/browser-extension-archive.js +149 -0
- package/neural-interface/lib/browser-extension-bridge.js +46 -10
- package/neural-interface/lib/browser-extension-folder.js +635 -76
- package/neural-interface/lib/browser-extension-package.js +201 -0
- package/neural-interface/lib/browser-extension-pin.js +84 -0
- package/neural-interface/lib/browser-extension-pin.json +35 -0
- package/{browser-extension/protocol.js → neural-interface/lib/browser-extension-protocol.js} +111 -13
- package/neural-interface/lib/browser-extension-setup.js +108 -19
- package/neural-interface/lib/browser-extension-update.js +104 -0
- package/neural-interface/lib/browser-extraction.js +38 -14
- package/neural-interface/lib/claude-bg-tasks.js +183 -0
- package/neural-interface/lib/claude-history.js +12 -1
- package/neural-interface/lib/cli-install.js +23 -3
- package/neural-interface/lib/cli-update-planner.js +67 -4
- package/neural-interface/lib/confined-fs.js +25 -0
- package/neural-interface/lib/coordination/operations.js +2 -0
- package/neural-interface/lib/db.js +39 -16
- package/neural-interface/lib/editor-completion-opencode.js +2 -2
- package/neural-interface/lib/git-bash/manager.js +28 -3
- package/neural-interface/lib/git-status-runner.js +31 -3
- package/neural-interface/lib/loop-inventory.js +162 -0
- package/neural-interface/lib/loop-stall.js +74 -4
- package/neural-interface/lib/memory-session-capture.js +157 -66
- package/neural-interface/lib/native-loop-providers.js +82 -13
- package/neural-interface/lib/native-loop-runtime.js +23 -2
- package/neural-interface/lib/opencode-protocol.js +4 -2
- 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 +34 -0
- package/neural-interface/lib/opencode2-client.js +341 -6
- package/neural-interface/lib/opencode2-translate.js +161 -4
- package/neural-interface/lib/peer-identity.js +62 -16
- package/neural-interface/lib/session-cache-builder.js +66 -18
- package/neural-interface/lib/session-capture-gate.js +42 -0
- package/neural-interface/lib/session-indexer.js +28 -20
- package/neural-interface/lib/teams/scheduler.js +3 -2
- package/neural-interface/lib/terminal-token-redaction.js +83 -0
- package/neural-interface/lib/ui-blob-api.js +14 -5
- package/neural-interface/lib/ui-blob-store.js +302 -39
- package/neural-interface/lib/whatsapp/bridge.js +52 -6
- package/neural-interface/package-lock.json +5 -5
- package/neural-interface/package.json +1 -1
- package/neural-interface/public/extension-setup.html +6 -2
- package/neural-interface/public/shared/agy/agy-panel.js +38 -10
- package/neural-interface/public/shared/assistant/asst-agents-dock.js +4 -0
- package/neural-interface/public/shared/assistant/asst-api.js +67 -0
- package/neural-interface/public/shared/assistant/asst-composer.js +85 -12
- package/neural-interface/public/shared/assistant/asst-panel.js +354 -11
- package/neural-interface/public/shared/assistant/asst-rack-styles.js +23 -0
- package/neural-interface/public/shared/assistant/asst-render.js +343 -10
- package/neural-interface/public/shared/assistant/asst-scenes.js +12 -0
- 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 +18 -1
- package/neural-interface/public/shared/assistant/asst-state.js +241 -2
- package/neural-interface/public/shared/assistant/asst-steer.js +294 -0
- package/neural-interface/public/shared/assistant/asst-styles.js +21 -0
- package/neural-interface/public/shared/bg-tasks/bg-tasks-claude.js +147 -0
- package/neural-interface/public/shared/bg-tasks/bg-tasks-model.js +527 -0
- package/neural-interface/public/shared/bg-tasks/bg-tasks-panel.js +161 -0
- package/neural-interface/public/shared/bg-tasks/bg-tasks-view.js +508 -0
- package/neural-interface/public/shared/browser-extension-updates.js +88 -0
- package/neural-interface/public/shared/cdx/cdx-tabs.js +25 -0
- package/neural-interface/public/shared/cp/cp-bg-tasks.js +130 -0
- package/neural-interface/public/shared/extension-setup/es-page.js +25 -12
- package/neural-interface/public/shared/extension-setup/es-view.js +25 -10
- package/neural-interface/public/shared/extension-update-view.js +34 -0
- package/neural-interface/public/shared/mtc/mtc-panel.js +17 -2
- package/neural-interface/public/shared/ocp-v2/ocp-v2-events.js +5 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-manager.js +1 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-panel.js +34 -2
- package/neural-interface/public/shared/ocp-v2/ocp-v2-rehydrate.js +7 -1
- package/neural-interface/public/shared/ocp-v2/ocp-v2-render.js +26 -1
- package/neural-interface/public/shared/ocp-v2/ocp-v2-send.js +39 -6
- package/neural-interface/public/shared/ocp-v2/ocp-v2-session-actions.js +20 -1
- 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 +350 -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 +40 -0
- 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-ws.js +7 -2
- package/neural-interface/public/shared/settings/settings-browser-extension.js +61 -13
- package/neural-interface/public/shared/settings/settings-extension-update.js +114 -0
- package/neural-interface/public/shared/shell-stop-view.js +83 -0
- package/neural-interface/public/shared/styles.css +4 -0
- package/neural-interface/public/shared/tour/tour-actor.js +14 -3
- package/neural-interface/public/shared/tray-auto-close.js +36 -6
- package/neural-interface/public/shared/ui-claude-panel.js +130 -1
- package/neural-interface/public/shared/ui-native-loop-router.js +45 -3
- package/neural-interface/public/shared/ui-notifications.js +23 -4
- package/neural-interface/public/shared/ui-scroll-follow.js +4 -0
- package/neural-interface/public/shared/ui-settings-entry.js +6 -0
- package/neural-interface/public/shared/ui-tray-columns.js +9 -2
- package/neural-interface/public/shared/worker-end.js +18 -0
- package/neural-interface/scripts/patch-node-pty.mjs +151 -0
- package/neural-interface/scripts/rebuild-pty.js +10 -0
- package/neural-interface/server.js +725 -308
- package/npm-shrinkwrap.json +5 -5
- package/package.json +1 -2
- package/browser-extension/content.js +0 -231
- package/browser-extension/engine.js +0 -658
- 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 -58
- 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 -283
- package/browser-extension/setup-content.js +0 -36
- package/browser-extension/tokens.css +0 -326
|
@@ -155,7 +155,7 @@ function bindingCheck(store, sessionId, isCurrent) {
|
|
|
155
155
|
* that was closed meanwhile. Resolves what it applied, for the caller's log.
|
|
156
156
|
*/
|
|
157
157
|
export async function rehydrateSessionState(store, api, { sessionId, cwd, hasPanel, isDescendant, isCurrent } = {}) {
|
|
158
|
-
const applied = { status: false, permissions: false, questions: false, todos: false };
|
|
158
|
+
const applied = { status: false, permissions: false, questions: false, todos: false, shells: false };
|
|
159
159
|
if (!sessionId) return applied;
|
|
160
160
|
const stillBound = bindingCheck(store, sessionId, isCurrent);
|
|
161
161
|
const revisionOf = (slice) => (typeof store.getRevisions === 'function' ? store.getRevisions()[slice] : 0);
|
|
@@ -200,6 +200,12 @@ export async function rehydrateSessionState(store, api, { sessionId, cwd, hasPan
|
|
|
200
200
|
() => (api.sessionTodo ? api.sessionTodo({ sessionId, cwd }) : { ok: false }),
|
|
201
201
|
(res) => (Array.isArray(res.data) ? res.data : undefined),
|
|
202
202
|
(todos) => store.setTodos(todos)),
|
|
203
|
+
// The commands of the session's tool calls: one that still runs (also after
|
|
204
|
+
// its call ended) is followed again, with its output, from where it is now.
|
|
205
|
+
sync('shells',
|
|
206
|
+
() => (api.shellList && typeof store.setShells === 'function' ? api.shellList({ sessionId, cwd }) : { ok: false }),
|
|
207
|
+
(res) => (Array.isArray(res.data) ? res.data : undefined),
|
|
208
|
+
(shells) => store.setShells(shells)),
|
|
203
209
|
]);
|
|
204
210
|
return applied;
|
|
205
211
|
}
|
|
@@ -42,6 +42,7 @@ import {
|
|
|
42
42
|
revertToMessage, restoreReverted, retryFromMessage, forkSession,
|
|
43
43
|
} from './ocp-v2-session-actions.js';
|
|
44
44
|
import { synabunToolKey, synabunToolLabel, synabunToolSummary } from '../synabun-tools.js';
|
|
45
|
+
import { renderShellTerminal, retainShellFollowing, shellOutputSupported } from './ocp-v2-shell.js';
|
|
45
46
|
|
|
46
47
|
const _expandedReasoningIds = new Set();
|
|
47
48
|
const _activeRenderers = new Set();
|
|
@@ -117,13 +118,22 @@ export function mountRenderer(containerEl, store = getDefaultStore(), opts = {})
|
|
|
117
118
|
// The server listed this session's open permission requests: a reason
|
|
118
119
|
// typed for one that is no longer among them has no card to come back to.
|
|
119
120
|
if (event?.type === 'permission:set' && event.listed) settlePermissionReasons(state);
|
|
121
|
+
// What a command printed is drawn by its own terminal block (ocp-v2-shell.js): no card is built again for
|
|
122
|
+
// it. The transcript only keeps its place at the end while the block grows.
|
|
123
|
+
if (event?.type === 'shell:output') {
|
|
124
|
+
requestAnimationFrame(() => { if (_container) scrollController?.scrollToBottom(); });
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
120
127
|
scheduleRender();
|
|
121
128
|
});
|
|
129
|
+
// The commands of this panel's session are followed for as long as it is on screen.
|
|
130
|
+
const releaseShells = retainShellFollowing(store);
|
|
122
131
|
|
|
123
132
|
const instance = {
|
|
124
133
|
render: doRender,
|
|
125
134
|
unmount: () => {
|
|
126
135
|
try { unsubscribe(); } catch {}
|
|
136
|
+
try { releaseShells(); } catch {}
|
|
127
137
|
scrollController?.destroy();
|
|
128
138
|
rowWatcher.disconnect();
|
|
129
139
|
_activeRenderers.delete(instance);
|
|
@@ -155,6 +165,18 @@ function _partSig(part) {
|
|
|
155
165
|
return sig;
|
|
156
166
|
}
|
|
157
167
|
|
|
168
|
+
// A bash card also shows its command as the panel knows it live (running on after the call, ended, its exit
|
|
169
|
+
// code): the card is built again when that changes, never for what the command prints.
|
|
170
|
+
function _shellOf(part, state) {
|
|
171
|
+
if (part?.type !== 'tool') return null;
|
|
172
|
+
const shellId = part.state?.metadata?.shellID;
|
|
173
|
+
return typeof shellId === 'string' && shellId ? state.shells?.get(shellId) || null : null;
|
|
174
|
+
}
|
|
175
|
+
function _shellSig(part, state) {
|
|
176
|
+
const shell = _shellOf(part, state);
|
|
177
|
+
return shell ? `|sh:${shell.status}:${shell.background ? 'b' : ''}:${shell.exit ?? ''}:${shellOutputSupported() ? 'l' : ''}` : '';
|
|
178
|
+
}
|
|
179
|
+
|
|
158
180
|
function _msgSig(msg) {
|
|
159
181
|
let sig = `m:${msg.role || 'assistant'}`;
|
|
160
182
|
for (const part of visibleParts(msg)) sig += '|' + _partSig(part);
|
|
@@ -299,7 +321,7 @@ function render(_container, store, opts = {}) {
|
|
|
299
321
|
const partKey = part.id || `${part.type}:${part.index ?? ''}`;
|
|
300
322
|
desired.push({
|
|
301
323
|
key: `a:${msg.id}:${partKey}`,
|
|
302
|
-
sig: `${isContinuation ? 'c' : 'h'}|${msg.info?.summary ? 's' : ''}|${_partSig(part)}`,
|
|
324
|
+
sig: `${isContinuation ? 'c' : 'h'}|${msg.info?.summary ? 's' : ''}|${_partSig(part)}${_shellSig(part, s)}`,
|
|
303
325
|
build: () => renderAssistantPartBubble(msg, part, isContinuation, store),
|
|
304
326
|
});
|
|
305
327
|
prevAssistantId = msg.id;
|
|
@@ -1012,6 +1034,9 @@ function renderToolPart(part, store) {
|
|
|
1012
1034
|
return holder;
|
|
1013
1035
|
},
|
|
1014
1036
|
onOpenChild: _rendererOpts.get(store)?.onOpenChild || null,
|
|
1037
|
+
shell: _shellOf(part, store.getState()),
|
|
1038
|
+
// An older server cannot be asked for a command's output: the card shows what the call returned.
|
|
1039
|
+
terminal: shellOutputSupported() ? (shellId) => renderShellTerminal(store, shellId) : null,
|
|
1015
1040
|
});
|
|
1016
1041
|
}
|
|
1017
1042
|
|
|
@@ -37,6 +37,7 @@ import {
|
|
|
37
37
|
import { hydrateTranscript } from './ocp-v2-rehydrate.js';
|
|
38
38
|
import { captureBinding, trackBinding, isBindingToken, searchOnBinding } from './ocp-v2-binding.js';
|
|
39
39
|
import { takeGreetingId } from './ocp-v2-greeting.js';
|
|
40
|
+
import { t } from '../i18n.js';
|
|
40
41
|
|
|
41
42
|
const STOR_MODE = 'opencode-v2-mode'; // the last agent picked (build / plan / a custom one)
|
|
42
43
|
const STOR_HISTORY = 'ocp-v2-prompt-history';
|
|
@@ -1564,11 +1565,16 @@ export function mountCompose(rootEl, store = getDefaultStore(), opts = {}) {
|
|
|
1564
1565
|
const unsubInner = store.subscribe((event, state) => {
|
|
1565
1566
|
if ((event?.type === 'running:set' && !state.running) || !turn.isCurrent()) cleanup();
|
|
1566
1567
|
});
|
|
1567
|
-
// Working time only: the clock stops while the session waits on the user (a permission, a question)
|
|
1568
|
+
// Working time only: the clock stops while the session waits on the user (a permission, a question) or on
|
|
1569
|
+
// a command of its own still running in the background (a long test run: `sessionStatus.background`).
|
|
1568
1570
|
clock = createTurnClock({
|
|
1569
1571
|
ms: TURN_LIMIT_MS,
|
|
1570
|
-
paused: () => sessionWaitsOnUser(turn.sessionId),
|
|
1571
|
-
subscribe:
|
|
1572
|
+
paused: () => sessionWaitsOnUser(turn.sessionId) || (turn.isCurrent() && store.getState().sessionStatus?.background === true),
|
|
1573
|
+
subscribe: (changed) => {
|
|
1574
|
+
const offAsks = onAsksChanged(changed);
|
|
1575
|
+
const offStatus = store.subscribe((event) => { if (event?.type === 'status:set') changed(); });
|
|
1576
|
+
return () => { try { offAsks?.(); } catch { /* gone */ } offStatus(); };
|
|
1577
|
+
},
|
|
1572
1578
|
onExpire: () => {
|
|
1573
1579
|
if (run.isCurrent()) store.pushError({ message: 'OpenCode turn timed out waiting for session.idle.' });
|
|
1574
1580
|
endTurn(store, run);
|
|
@@ -1580,7 +1586,7 @@ export function mountCompose(rootEl, store = getDefaultStore(), opts = {}) {
|
|
|
1580
1586
|
});
|
|
1581
1587
|
}
|
|
1582
1588
|
|
|
1583
|
-
async function doAbort() {
|
|
1589
|
+
async function doAbort({ force = false } = {}) {
|
|
1584
1590
|
// `turn` is the session Stop was pressed in, and the turn that was running
|
|
1585
1591
|
// there. The loop-stop request and the abort are for that session; what is
|
|
1586
1592
|
// cleared afterwards is cleared only while the panel is still on that
|
|
@@ -1600,15 +1606,42 @@ export function mountCompose(rootEl, store = getDefaultStore(), opts = {}) {
|
|
|
1600
1606
|
}
|
|
1601
1607
|
_suppressAbortErrorUntil = Date.now() + 15000;
|
|
1602
1608
|
_suppressAbortErrorCount += 1;
|
|
1609
|
+
let stopped = null;
|
|
1603
1610
|
try {
|
|
1604
|
-
await api.abort(turn.sessionId);
|
|
1611
|
+
stopped = await api.abort(turn.sessionId, force ? { force: true } : undefined);
|
|
1605
1612
|
} catch (err) {
|
|
1606
1613
|
console.warn('[ocp-v2-send] abort failed', err);
|
|
1607
1614
|
} finally {
|
|
1608
|
-
|
|
1615
|
+
// The banner of an earlier failed Stop of this session goes: this answer says what holds now.
|
|
1616
|
+
if (turn.isCurrent()) dismissStopNotices();
|
|
1617
|
+
// Its words are loaded only when a Stop has something to say (not before the app is shown).
|
|
1618
|
+
const view = (stopped?.code === 'SHELL_STOP_FAILED' || stopped?.abandoned?.length) ? await import('../shell-stop-view.js').catch(() => null) : null;
|
|
1619
|
+
const failure = view?.describeStopFailure(stopped, t) || null;
|
|
1620
|
+
if (stopped?.code === 'SHELL_STOP_FAILED') {
|
|
1621
|
+
// A command Stop could not end still runs: the turn stays on (its Stop button too), and the panel says which
|
|
1622
|
+
// and why. No "aborted" send failure follows (the prompt's wait goes on), so none is held back for it.
|
|
1623
|
+
_suppressAbortErrorCount = Math.max(0, _suppressAbortErrorCount - 1);
|
|
1624
|
+
if (turn.isCurrent()) {
|
|
1625
|
+
store.pushError({
|
|
1626
|
+
message: failure?.message || stopped.error || 'Stop could not end a command still running in the background. Press Stop again.',
|
|
1627
|
+
kind: STOP_NOTICE,
|
|
1628
|
+
// From the second failure on: end the turn here, telling plainly what may still run.
|
|
1629
|
+
...(failure?.canForce ? { actions: [{ label: view.shellStopText('anyway', {}, t), run: () => { doAbort({ force: true }).catch(() => {}); } }] } : {}),
|
|
1630
|
+
});
|
|
1631
|
+
}
|
|
1632
|
+
} else {
|
|
1633
|
+
clearStoppedTurn();
|
|
1634
|
+
const left = view?.describeAbandoned(stopped?.abandoned, t) || null;
|
|
1635
|
+
if (left && turn.isCurrent()) store.pushError({ message: left, kind: STOP_NOTICE, notice: true });
|
|
1636
|
+
}
|
|
1609
1637
|
}
|
|
1610
1638
|
}
|
|
1611
1639
|
|
|
1640
|
+
const STOP_NOTICE = 'shell-stop';
|
|
1641
|
+
function dismissStopNotices() {
|
|
1642
|
+
for (const err of store.getState().errors || []) if (err?.kind === STOP_NOTICE && err.id) store.dismissError(err.id);
|
|
1643
|
+
}
|
|
1644
|
+
|
|
1612
1645
|
function shouldSuppressAbortError(err) {
|
|
1613
1646
|
if (_suppressAbortErrorCount <= 0) return false;
|
|
1614
1647
|
if (Date.now() > _suppressAbortErrorUntil) return false;
|
|
@@ -252,11 +252,30 @@ export async function loadSelectedSession(store, api, sessionId, info, apply) {
|
|
|
252
252
|
*/
|
|
253
253
|
export async function stopForNavigation(store, api, nav) {
|
|
254
254
|
if (nav.sessionId && nav.isCurrent() && store.getState().running) {
|
|
255
|
-
|
|
255
|
+
// The panel leaves this session: a command Stop cannot end is given up on, as on a tab's close (Stop anyway).
|
|
256
|
+
let stopped = null;
|
|
257
|
+
try { stopped = await api.abort(nav.sessionId, { force: true }); } catch (err) { console.warn('[ocp-v2-session-actions] abort before navigation failed', err); }
|
|
258
|
+
// What it gave up on may still be running: the panel's next view says so (a notice outlives the clear).
|
|
259
|
+
await noteAbandoned(store, stopped);
|
|
256
260
|
}
|
|
257
261
|
return nav.isCurrent();
|
|
258
262
|
}
|
|
259
263
|
|
|
264
|
+
/**
|
|
265
|
+
* A forced Stop's answer that left commands running (`abandoned`): one notice in the panel, in the words of the
|
|
266
|
+
* panel's own Stop anyway (shell-stop-view.js, loaded only then). Nothing for any other answer.
|
|
267
|
+
*/
|
|
268
|
+
export async function noteAbandoned(store, stopped, translate = null) {
|
|
269
|
+
if (!Array.isArray(stopped?.abandoned) || !stopped.abandoned.length) return false;
|
|
270
|
+
const view = await import('../shell-stop-view.js').catch(() => null);
|
|
271
|
+
let tr = translate;
|
|
272
|
+
if (!tr) { try { tr = (await import('../i18n.js')).t; } catch { tr = null; } }
|
|
273
|
+
const message = view?.describeAbandoned(stopped.abandoned, tr) || null;
|
|
274
|
+
if (!message) return false;
|
|
275
|
+
store.pushError({ message, kind: 'shell-stop', notice: true });
|
|
276
|
+
return true;
|
|
277
|
+
}
|
|
278
|
+
|
|
260
279
|
/**
|
|
261
280
|
* Create the session of a navigation. Resolves `{ session, activate }`:
|
|
262
281
|
* `activate` is false when the panel was rebound while the session was being
|
|
@@ -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
|
+
}
|