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
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
2
|
+
// SynaBun Assistant — the shell commands of an OpenCode brain (no DOM, no socket)
|
|
3
|
+
//
|
|
4
|
+
// The runtime tells a panel which commands the brain's tool calls started and how
|
|
5
|
+
// they ended (`assistant:shell`, `assistant:shells`). What a command printed is
|
|
6
|
+
// never in those packets: it is read in pages over REST, only while a terminal
|
|
7
|
+
// block shows that command, by the same follower and terminal buffer as the
|
|
8
|
+
// OpenCode side panel (ocp-v2-shell-logic.js). Everything here is display data:
|
|
9
|
+
// nothing of it goes to the model, the transcript, a memory or a meter.
|
|
10
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
11
|
+
|
|
12
|
+
import { createShellFollower, formatBytes, shellCardState } from '../ocp-v2/ocp-v2-shell-logic.js';
|
|
13
|
+
|
|
14
|
+
/** How many finished commands keep their read output once no block shows them (the next look reads it again). */
|
|
15
|
+
export const SHELL_KEPT_FINISHED = 12;
|
|
16
|
+
|
|
17
|
+
const GONE_VIEW = Object.freeze({ text: '', from: 0, size: 0, done: true, gone: true, error: '', full: false, capped: false, partial: false });
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* createShellTracker({ read })
|
|
21
|
+
* read({ shellId, cursor, tail, limit }) → { status, data: { output, cursor, size, from } } or { ok: false, status, error }
|
|
22
|
+
* apply / applyList take what the runtime says; open(id) + subscribe(id, fn) follow one command for as long as a
|
|
23
|
+
* block shows it; onChange(fn) hears that a command's state changed.
|
|
24
|
+
*/
|
|
25
|
+
export function createShellTracker({ read, setTimer, clearTimer, kept = SHELL_KEPT_FINISHED } = {}) {
|
|
26
|
+
const shells = new Map(); // shellId → the runtime's view of it
|
|
27
|
+
const byCall = new Map(); // the tool call's id → shellId
|
|
28
|
+
const entries = new Map(); // shellId → { follower, view, usedAt }
|
|
29
|
+
const listeners = new Map(); // shellId → Set of what draws it
|
|
30
|
+
const places = new Map(); // shellId → { follow, top }: where the reader left its block
|
|
31
|
+
const changes = new Set();
|
|
32
|
+
let clock = 0;
|
|
33
|
+
let destroyed = false;
|
|
34
|
+
|
|
35
|
+
const tell = (shellId) => {
|
|
36
|
+
for (const fn of [...(listeners.get(shellId) || [])]) { try { fn(); } catch (err) { console.warn('[asst-shell] draw failed', err); } }
|
|
37
|
+
};
|
|
38
|
+
const changed = (shell) => {
|
|
39
|
+
for (const fn of [...changes]) { try { fn(shell); } catch (err) { console.warn('[asst-shell] update failed', err); } }
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// Stop removes a command from OpenCode, so its next read is a 404. What was read up to then is what it printed
|
|
43
|
+
// before it was stopped: nothing to apologise for, unless the start of a long output is out of reach.
|
|
44
|
+
const settledView = (shellId, view) => (view.gone && view.text && !view.partial && shells.get(shellId)?.status === 'killed'
|
|
45
|
+
? { ...view, gone: false, done: true }
|
|
46
|
+
: view);
|
|
47
|
+
|
|
48
|
+
function dropEntry(shellId) {
|
|
49
|
+
entries.get(shellId)?.follower?.stop();
|
|
50
|
+
entries.delete(shellId);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Finished commands nobody looks at keep their text up to `kept`; the oldest goes first. */
|
|
54
|
+
function evict() {
|
|
55
|
+
const idle = [...entries].filter(([id]) => !listeners.get(id)?.size).sort((a, b) => a[1].usedAt - b[1].usedAt);
|
|
56
|
+
while (idle.length > kept) {
|
|
57
|
+
const [id] = idle.shift();
|
|
58
|
+
dropEntry(id);
|
|
59
|
+
places.delete(id);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function apply(shell) {
|
|
64
|
+
if (destroyed || !shell?.id) return;
|
|
65
|
+
const known = shells.get(shell.id);
|
|
66
|
+
// Named again after it was lost (a brain that came back to its serve): it is read afresh.
|
|
67
|
+
if (known?.lost) dropEntry(shell.id);
|
|
68
|
+
shells.set(shell.id, shell);
|
|
69
|
+
if (shell.callID) byCall.set(shell.callID, shell.id);
|
|
70
|
+
if (shell.status !== 'running') entries.get(shell.id)?.follower?.poke();
|
|
71
|
+
tell(shell.id);
|
|
72
|
+
changed(shell);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** The brain no longer has this command (it was replaced, or its serve ended). What was read stays on screen. */
|
|
76
|
+
function lose(shellId) {
|
|
77
|
+
const shell = shells.get(shellId);
|
|
78
|
+
if (!shell || shell.lost) return;
|
|
79
|
+
const next = { ...shell, lost: true, status: shell.status === 'running' ? 'killed' : shell.status };
|
|
80
|
+
shells.set(shellId, next);
|
|
81
|
+
const entry = entries.get(shellId);
|
|
82
|
+
if (entry) {
|
|
83
|
+
entry.follower?.stop();
|
|
84
|
+
entry.follower = null;
|
|
85
|
+
const view = entry.view;
|
|
86
|
+
// Read to its end, the text on screen is the whole output: nothing is missing from it.
|
|
87
|
+
if (!view) entry.view = { ...GONE_VIEW };
|
|
88
|
+
else if (!view.done || view.partial) entry.view = { ...view, done: true, gone: true };
|
|
89
|
+
}
|
|
90
|
+
tell(shellId);
|
|
91
|
+
changed(next);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** The whole list as the runtime knows it now: a command it no longer names is gone. */
|
|
95
|
+
function applyList(list) {
|
|
96
|
+
if (destroyed) return;
|
|
97
|
+
const named = new Set();
|
|
98
|
+
for (const shell of Array.isArray(list) ? list : []) {
|
|
99
|
+
if (!shell?.id) continue;
|
|
100
|
+
named.add(shell.id);
|
|
101
|
+
apply(shell);
|
|
102
|
+
}
|
|
103
|
+
for (const id of [...shells.keys()]) if (!named.has(id)) lose(id);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Start reading a command for a block that shows it. */
|
|
107
|
+
function open(shellId) {
|
|
108
|
+
if (destroyed || !shells.has(shellId)) return;
|
|
109
|
+
let entry = entries.get(shellId);
|
|
110
|
+
if (!entry) {
|
|
111
|
+
entry = { follower: null, view: null, usedAt: 0 };
|
|
112
|
+
entries.set(shellId, entry);
|
|
113
|
+
if (shells.get(shellId).lost) entry.view = { ...GONE_VIEW };
|
|
114
|
+
else {
|
|
115
|
+
const mine = entry;
|
|
116
|
+
const options = {
|
|
117
|
+
api: { shellOutput: ({ shellId: id, cursor, tail, limit }) => read({ shellId: id, cursor, tail, limit }) },
|
|
118
|
+
sessionId: 'assistant', shellId,
|
|
119
|
+
isRunning: () => shells.get(shellId)?.status === 'running',
|
|
120
|
+
onUpdate: (view) => { if (entries.get(shellId) === mine) { mine.view = settledView(shellId, view); tell(shellId); } },
|
|
121
|
+
};
|
|
122
|
+
if (setTimer) options.setTimer = setTimer;
|
|
123
|
+
if (clearTimer) options.clearTimer = clearTimer;
|
|
124
|
+
entry.follower = createShellFollower(options);
|
|
125
|
+
entry.follower.start();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
entry.usedAt = ++clock;
|
|
129
|
+
evict();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function subscribe(shellId, fn) {
|
|
133
|
+
let set = listeners.get(shellId);
|
|
134
|
+
if (!set) { set = new Set(); listeners.set(shellId, set); }
|
|
135
|
+
set.add(fn);
|
|
136
|
+
return () => {
|
|
137
|
+
set.delete(fn);
|
|
138
|
+
if (set.size) return;
|
|
139
|
+
listeners.delete(shellId);
|
|
140
|
+
// Nobody looks: nothing is polled. A command that ended and was read keeps its text for the next look.
|
|
141
|
+
const entry = entries.get(shellId);
|
|
142
|
+
if (entry?.follower && !entry.follower.isDone()) dropEntry(shellId);
|
|
143
|
+
evict();
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return {
|
|
148
|
+
apply,
|
|
149
|
+
applyList,
|
|
150
|
+
open,
|
|
151
|
+
subscribe,
|
|
152
|
+
loadAll(shellId) { entries.get(shellId)?.follower?.loadAll(); },
|
|
153
|
+
forCall: (callId) => shells.get(byCall.get(callId)) || null,
|
|
154
|
+
shell: (shellId) => shells.get(shellId) || null,
|
|
155
|
+
view: (shellId) => entries.get(shellId)?.view || null,
|
|
156
|
+
placeOf(shellId) {
|
|
157
|
+
let place = places.get(shellId);
|
|
158
|
+
if (!place) { place = { follow: true, top: 0 }; places.set(shellId, place); }
|
|
159
|
+
return place;
|
|
160
|
+
},
|
|
161
|
+
onChange(fn) { changes.add(fn); return () => changes.delete(fn); },
|
|
162
|
+
/** For tests: which commands are being read now. */
|
|
163
|
+
reading: () => [...entries].filter(([, entry]) => entry.follower && !entry.follower.isDone()).map(([id]) => id),
|
|
164
|
+
destroy() {
|
|
165
|
+
destroyed = true;
|
|
166
|
+
for (const id of [...entries.keys()]) dropEntry(id);
|
|
167
|
+
listeners.clear();
|
|
168
|
+
changes.clear();
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** The word on a call's row for its command ('' when the call's own state says it). */
|
|
174
|
+
export function shellStateLabel(shell, t) {
|
|
175
|
+
if (!shell) return '';
|
|
176
|
+
if (shell.status === 'running') {
|
|
177
|
+
return shell.background ? t('assistant.rack.shell.background', 'in the background') : t('assistant.rack.shell.running', 'running');
|
|
178
|
+
}
|
|
179
|
+
if (shell.status === 'killed') return t('assistant.rack.shell.stopped', 'stopped');
|
|
180
|
+
if (shell.status === 'timeout') return t('assistant.rack.shell.timedOut', 'timed out');
|
|
181
|
+
if (typeof shell.exit === 'number') return t('assistant.rack.shell.exit', 'exit {code}', { code: shell.exit });
|
|
182
|
+
return '';
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** A command the model no longer waits for failed after its tool call had already answered. */
|
|
186
|
+
export function shellFailedLate(shell) {
|
|
187
|
+
return shellCardState(shell).status === 'error';
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** The line above a terminal block when it does not show everything: '' when it does. */
|
|
191
|
+
export function shellNoteText(view, t) {
|
|
192
|
+
if (!view) return '';
|
|
193
|
+
if (view.gone) return t('assistant.rack.shell.gone', 'OpenCode no longer keeps the output of this command.');
|
|
194
|
+
const shown = formatBytes(view.text.length);
|
|
195
|
+
const size = formatBytes(view.size);
|
|
196
|
+
if (view.capped) return t('assistant.rack.shell.capped', 'Showing the last {shown} of {size}: the whole output is too long to show here.', { shown, size });
|
|
197
|
+
if (view.partial) return t('assistant.rack.shell.partial', 'Showing the last {shown} of {size}.', { shown, size });
|
|
198
|
+
return '';
|
|
199
|
+
}
|
|
200
|
+
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
2
|
+
// SynaBun Assistant — a shell call's live terminal block
|
|
3
|
+
//
|
|
4
|
+
// The block itself is the OpenCode panel's (ocp-v2-shell-block.js) in the rack's
|
|
5
|
+
// classes and words; the command's state and output come from the tracker
|
|
6
|
+
// (asst-shell-logic.js). A long test run must not cost the conversation
|
|
7
|
+
// anything: drawing is coalesced to one frame, and a block that is off screen or
|
|
8
|
+
// in a closed panel does no DOM work at all until it is seen again.
|
|
9
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
10
|
+
|
|
11
|
+
import { createTerminalBlock } from '../ocp-v2/ocp-v2-shell-block.js';
|
|
12
|
+
import { shellNoteText } from './asst-shell-logic.js';
|
|
13
|
+
|
|
14
|
+
const SHOW_EVENT = 'asst-term-show';
|
|
15
|
+
|
|
16
|
+
const CLASSES = Object.freeze({
|
|
17
|
+
wrap: 'asst-term',
|
|
18
|
+
note: 'asst-term-note',
|
|
19
|
+
noteText: 'asst-term-note-text',
|
|
20
|
+
load: 'asst-tool-more asst-term-load',
|
|
21
|
+
out: 'asst-tool-section asst-term-out',
|
|
22
|
+
foot: 'asst-term-foot',
|
|
23
|
+
state: 'asst-term-state',
|
|
24
|
+
jump: 'asst-tool-more asst-term-jump',
|
|
25
|
+
copy: 'asst-copy asst-term-copy',
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* mountShellTerminal(tracker, shellId, { t, onDraw, onGone }) → { el, show(), dispose() }
|
|
30
|
+
* `onDraw`: the block was drawn (its height may have changed); `onGone`: OpenCode no longer has this output.
|
|
31
|
+
*/
|
|
32
|
+
export function mountShellTerminal(tracker, shellId, { t, onDraw = () => {}, onGone = () => {} } = {}) {
|
|
33
|
+
let drawBlock = null;
|
|
34
|
+
let frame = 0;
|
|
35
|
+
let dirty = false;
|
|
36
|
+
let seen = true;
|
|
37
|
+
let disposed = false;
|
|
38
|
+
let wasGone = !!tracker.view(shellId)?.gone;
|
|
39
|
+
let wrap = null;
|
|
40
|
+
|
|
41
|
+
const flush = () => {
|
|
42
|
+
frame = 0;
|
|
43
|
+
if (disposed || !dirty || !seen || !wrap?.isConnected) return;
|
|
44
|
+
dirty = false;
|
|
45
|
+
drawBlock?.();
|
|
46
|
+
onDraw();
|
|
47
|
+
const gone = !!tracker.view(shellId)?.gone;
|
|
48
|
+
if (gone && !wasGone) { wasGone = true; onGone(); }
|
|
49
|
+
};
|
|
50
|
+
const request = () => {
|
|
51
|
+
dirty = true;
|
|
52
|
+
if (frame || !seen) return;
|
|
53
|
+
frame = requestAnimationFrame(flush);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
tracker.open(shellId);
|
|
57
|
+
wrap = createTerminalBlock({
|
|
58
|
+
shellId,
|
|
59
|
+
place: tracker.placeOf(shellId),
|
|
60
|
+
showEvent: SHOW_EVENT,
|
|
61
|
+
read: () => ({ view: tracker.view(shellId), shell: tracker.shell(shellId) }),
|
|
62
|
+
// Told through `request` below, for as long as this mount lives (dispose ends it).
|
|
63
|
+
subscribe: (draw) => {
|
|
64
|
+
drawBlock = draw;
|
|
65
|
+
return () => {};
|
|
66
|
+
},
|
|
67
|
+
loadAll: () => tracker.loadAll(shellId),
|
|
68
|
+
classes: CLASSES,
|
|
69
|
+
words: {
|
|
70
|
+
load: t('assistant.rack.shell.loadFull', 'Load full output'),
|
|
71
|
+
loading: t('assistant.rack.shell.loading', 'Loading…'),
|
|
72
|
+
jump: t('assistant.rack.shell.jump', 'Jump to latest'),
|
|
73
|
+
copy: t('assistant.rack.shell.copy', 'Copy output'),
|
|
74
|
+
copied: t('assistant.rack.shell.copied', 'Copied'),
|
|
75
|
+
label: t('assistant.rack.shell.label', 'Command output'),
|
|
76
|
+
noOutputYet: t('assistant.rack.shell.noOutputYet', 'No output yet'),
|
|
77
|
+
noOutput: t('assistant.rack.shell.noOutput', 'No output'),
|
|
78
|
+
reading: t('assistant.rack.shell.reading', 'Reading the output…'),
|
|
79
|
+
running: t('assistant.rack.shell.runningNow', 'Running'),
|
|
80
|
+
note: (view) => shellNoteText(view, t),
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// Not tied to being in the page: a row can be out of it for a moment while it is rebuilt.
|
|
85
|
+
const release = tracker.subscribe(shellId, request);
|
|
86
|
+
const watcher = typeof IntersectionObserver === 'function'
|
|
87
|
+
? new IntersectionObserver((entries) => {
|
|
88
|
+
seen = entries[entries.length - 1].isIntersecting;
|
|
89
|
+
if (seen && dirty && !frame) frame = requestAnimationFrame(flush);
|
|
90
|
+
})
|
|
91
|
+
: null;
|
|
92
|
+
watcher?.observe(wrap);
|
|
93
|
+
|
|
94
|
+
return {
|
|
95
|
+
el: wrap,
|
|
96
|
+
/** The block is in the page again (a body rebuilt, a row opened): it measures itself and catches up. */
|
|
97
|
+
show() {
|
|
98
|
+
wrap.dispatchEvent(new Event(SHOW_EVENT));
|
|
99
|
+
request();
|
|
100
|
+
},
|
|
101
|
+
dispose() {
|
|
102
|
+
if (disposed) return;
|
|
103
|
+
disposed = true;
|
|
104
|
+
if (frame) cancelAnimationFrame(frame);
|
|
105
|
+
frame = 0;
|
|
106
|
+
watcher?.disconnect();
|
|
107
|
+
release();
|
|
108
|
+
wrap.remove();
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
}
|
|
@@ -324,6 +324,12 @@ function mountTab({ sessionId, meta = null, brain = null, label = '', userRename
|
|
|
324
324
|
renderPills();
|
|
325
325
|
},
|
|
326
326
|
setBrain(next) { tab.brain = next || null; renderPills(); },
|
|
327
|
+
// The Background tasks view (bg-tasks/): how many still run, and how to open it from the pill.
|
|
328
|
+
setBackgroundTasks(count, open) {
|
|
329
|
+
tab.bgRunning = Math.max(0, Number(count) || 0);
|
|
330
|
+
tab.openBg = typeof open === 'function' ? open : null;
|
|
331
|
+
renderPills();
|
|
332
|
+
},
|
|
327
333
|
isVisible: () => isTabVisible(tab),
|
|
328
334
|
toolbarSlot: toolbar,
|
|
329
335
|
takeHeroOrigin() {
|
|
@@ -448,6 +454,16 @@ async function startSession(prompt = '') {
|
|
|
448
454
|
|
|
449
455
|
// ── Tray pills ───────────────────────────────────────────────────────────────
|
|
450
456
|
|
|
457
|
+
// The pill's "⟳ N" while background tasks run (bg-tasks-view.js), loaded once a tab has had one: never before the
|
|
458
|
+
// page is shown (tests/boot-critical-path.test.mjs).
|
|
459
|
+
let _paintBgBadge = null;
|
|
460
|
+
function paintPillBadge(tab) {
|
|
461
|
+
if (!tab?.pill || (!tab.bgRunning && !_paintBgBadge)) return;
|
|
462
|
+
const paint = () => { if (tab.pill) _paintBgBadge(tab.pill, tab.bgRunning || 0, { t, onClick: () => { focusSession(tab.sessionId); tab.openBg?.(); } }); };
|
|
463
|
+
if (_paintBgBadge) { paint(); return; }
|
|
464
|
+
import('../bg-tasks/bg-tasks-view.js').then((m) => { _paintBgBadge = m.paintBgBadge; paint(); }).catch(() => {});
|
|
465
|
+
}
|
|
466
|
+
|
|
451
467
|
function createPill(tab) {
|
|
452
468
|
const tray = document.getElementById('term-minimized-tray');
|
|
453
469
|
if (!tray) return null;
|
|
@@ -489,7 +505,8 @@ function renderPills() {
|
|
|
489
505
|
tab.pill.setAttribute('aria-label', `${tab.label} — ${statusLabel(tab.status)}`);
|
|
490
506
|
tab.pill.classList.toggle('asp-pill-running', tab.status === 'working');
|
|
491
507
|
tab.pill.classList.toggle('asp-pill-attention', tab.status === 'action');
|
|
492
|
-
tab.pill.classList.toggle('asp-pill-done', tab.status === 'done');
|
|
508
|
+
tab.pill.classList.toggle('asp-pill-done', tab.status === 'done' && !tab.bgRunning);
|
|
509
|
+
paintPillBadge(tab);
|
|
493
510
|
tab.pill.style.display = (!_visible || tab !== active) ? '' : 'none';
|
|
494
511
|
}
|
|
495
512
|
}
|
|
@@ -470,7 +470,8 @@ export function mergeRunDescriptor(current, next) {
|
|
|
470
470
|
out.costUsd = Math.max(Number.isFinite(costA) ? costA : 0, Number.isFinite(costB) ? costB : 0);
|
|
471
471
|
}
|
|
472
472
|
if (!out.title && (a.title || b.title)) out.title = a.title || b.title;
|
|
473
|
-
|
|
473
|
+
// A run this panel steered keeps saying so until the steer's turn shows output (settleSteering, at the end of this file).
|
|
474
|
+
return settleSteering(out, next, { previous: a });
|
|
474
475
|
}
|
|
475
476
|
|
|
476
477
|
function stripUndefined(obj) {
|
|
@@ -1048,6 +1049,14 @@ export function compactUsageView(view) {
|
|
|
1048
1049
|
};
|
|
1049
1050
|
}
|
|
1050
1051
|
|
|
1052
|
+
/** Whether a usage view can be shown: a task with an id and an exact total, or no task and a session headline. */
|
|
1053
|
+
export function usagePacketValid(packet) {
|
|
1054
|
+
const count = (n) => Number.isSafeInteger(n) && n >= 0;
|
|
1055
|
+
// A session with no task yet (the view a socket gets when it attaches before the first prompt) has its headline only.
|
|
1056
|
+
if (packet?.task == null) return count(packet?.session?.tokens?.total);
|
|
1057
|
+
return !!packet.task.id && count(packet.task.tokens?.total);
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1051
1060
|
/**
|
|
1052
1061
|
* Apply server usage. A view computed earlier than the one shown never replaces it: the
|
|
1053
1062
|
* session's settled tokens only grow, so fewer of them means an older view (see
|
|
@@ -1055,7 +1064,7 @@ export function compactUsageView(view) {
|
|
|
1055
1064
|
*/
|
|
1056
1065
|
export function applyUsagePacket(state, packet) {
|
|
1057
1066
|
const view = packet?.type === 'assistant:usage' ? packet : { ...packet, type: 'assistant:usage' };
|
|
1058
|
-
if (view.sessionId !== state.sessionId || !
|
|
1067
|
+
if (view.sessionId !== state.sessionId || !usagePacketValid(view)) return false;
|
|
1059
1068
|
if (usagePacketIsStale(state.usageView, view)) return false;
|
|
1060
1069
|
state.usageView = view;
|
|
1061
1070
|
return true;
|
|
@@ -1132,3 +1141,233 @@ export function runFromPayload(payload) {
|
|
|
1132
1141
|
if (payload.runId) return normalizeRunDescriptor(payload);
|
|
1133
1142
|
return null;
|
|
1134
1143
|
}
|
|
1144
|
+
|
|
1145
|
+
// ── Steer: what the panel draws with from the first frame ─────────────────
|
|
1146
|
+
// The sentences, the composer's keys, the target chip and the run's steering
|
|
1147
|
+
// mark (settled at every merge, mergeRunDescriptor). The steer itself (the
|
|
1148
|
+
// controller, its POST, the notices) is asst-steer.js, which the panel loads
|
|
1149
|
+
// on demand; it re-exports these names, so either module answers for them.
|
|
1150
|
+
// STEER_COPY holds the English and Portuguese of every sentence; the page's
|
|
1151
|
+
// translator (`assistant.steer.*`) wins when it has the key.
|
|
1152
|
+
|
|
1153
|
+
export const STEER_COPY = Object.freeze({
|
|
1154
|
+
en: Object.freeze({
|
|
1155
|
+
steer: 'Steer',
|
|
1156
|
+
steerNow: 'Steer now (Enter): stop this turn and send',
|
|
1157
|
+
queue: 'Queue',
|
|
1158
|
+
queueTip: 'Queue instead (Alt+Enter): send when this turn finishes',
|
|
1159
|
+
notice: 'Steered: {text}',
|
|
1160
|
+
noticeRun: 'Steered {run}: {text}',
|
|
1161
|
+
steering: 'Steering…',
|
|
1162
|
+
steeringChip: 'steering…',
|
|
1163
|
+
runSteer: 'Steer this run',
|
|
1164
|
+
runSteerPlaceholder: 'Tell this agent what to change…',
|
|
1165
|
+
runSteerSend: 'Send steer',
|
|
1166
|
+
runSteerCancel: 'Cancel',
|
|
1167
|
+
useComposer: 'Write it in the composer',
|
|
1168
|
+
targetChip: '→ #{n} {title}',
|
|
1169
|
+
targetLabel: 'Steering run {title}',
|
|
1170
|
+
targetClear: 'Send to the Assistant instead',
|
|
1171
|
+
targetPlaceholder: 'Steer {title}: what should change?',
|
|
1172
|
+
runEnded: 'That run already ended.',
|
|
1173
|
+
sendToAssistant: 'Send it to the Assistant',
|
|
1174
|
+
failed: 'Could not steer: {error}',
|
|
1175
|
+
unavailable: 'Steering needs a server restart; your message was queued.',
|
|
1176
|
+
emptyText: 'Type what should change first.',
|
|
1177
|
+
}),
|
|
1178
|
+
'pt-BR': Object.freeze({
|
|
1179
|
+
steer: 'Redirecionar',
|
|
1180
|
+
steerNow: 'Redirecionar agora (Enter): parar este turno e enviar',
|
|
1181
|
+
queue: 'Na fila',
|
|
1182
|
+
queueTip: 'Pôr na fila (Alt+Enter): enviar quando este turno terminar',
|
|
1183
|
+
notice: 'Redirecionado: {text}',
|
|
1184
|
+
noticeRun: '{run} redirecionado: {text}',
|
|
1185
|
+
steering: 'Redirecionando…',
|
|
1186
|
+
steeringChip: 'redirecionando…',
|
|
1187
|
+
runSteer: 'Redirecionar esta execução',
|
|
1188
|
+
runSteerPlaceholder: 'Diga a este agente o que mudar…',
|
|
1189
|
+
runSteerSend: 'Enviar redirecionamento',
|
|
1190
|
+
runSteerCancel: 'Cancelar',
|
|
1191
|
+
useComposer: 'Escrever no campo de mensagem',
|
|
1192
|
+
targetChip: '→ #{n} {title}',
|
|
1193
|
+
targetLabel: 'Redirecionando a execução {title}',
|
|
1194
|
+
targetClear: 'Enviar ao Assistente',
|
|
1195
|
+
targetPlaceholder: 'Redirecionar {title}: o que deve mudar?',
|
|
1196
|
+
runEnded: 'Essa execução já terminou.',
|
|
1197
|
+
sendToAssistant: 'Enviar ao Assistente',
|
|
1198
|
+
failed: 'Não foi possível redirecionar: {error}',
|
|
1199
|
+
unavailable: 'Redirecionar precisa reiniciar o servidor; sua mensagem entrou na fila.',
|
|
1200
|
+
emptyText: 'Escreva primeiro o que deve mudar.',
|
|
1201
|
+
}),
|
|
1202
|
+
});
|
|
1203
|
+
|
|
1204
|
+
const steerFill = (text, params) => String(text).replace(/\{(\w+)\}/g, (whole, k) => (params && params[k] != null ? params[k] : whole));
|
|
1205
|
+
|
|
1206
|
+
/**
|
|
1207
|
+
* A translator for the steer sentences: the page's `assistant.steer.<key>` when it has one, else STEER_COPY in
|
|
1208
|
+
* `locale` (Portuguese for any pt locale), else the English.
|
|
1209
|
+
*/
|
|
1210
|
+
export function steerTranslator(pageT = null, locale = 'en') {
|
|
1211
|
+
const table = /^pt/i.test(String(locale || '')) ? STEER_COPY['pt-BR'] : STEER_COPY.en;
|
|
1212
|
+
return (key, params) => {
|
|
1213
|
+
const full = `assistant.steer.${key}`;
|
|
1214
|
+
const v = typeof pageT === 'function' ? pageT(full, params) : undefined;
|
|
1215
|
+
if (typeof v === 'string' && v && v !== full) return v;
|
|
1216
|
+
return steerFill(table[key] ?? STEER_COPY.en[key] ?? key, params);
|
|
1217
|
+
};
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
/**
|
|
1221
|
+
* What a key press in the composer means: 'steer' (Enter while the Assistant works, or while a run is targeted),
|
|
1222
|
+
* 'queue' (Alt+Enter while it works), 'send' (Enter otherwise), or null (not a send key: Shift+Enter is a newline,
|
|
1223
|
+
* an IME composition is still typing).
|
|
1224
|
+
*/
|
|
1225
|
+
export function composerKeyIntent(e, { running = false, targeted = false, steerable = true } = {}) {
|
|
1226
|
+
if (!e || e.key !== 'Enter' || e.shiftKey || e.isComposing) return null;
|
|
1227
|
+
if (targeted) return 'steer';
|
|
1228
|
+
if (!running) return 'send';
|
|
1229
|
+
if (e.altKey) return 'queue';
|
|
1230
|
+
return steerable ? 'steer' : 'queue';
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1233
|
+
/**
|
|
1234
|
+
* Whether a steer notice gets the transcript's break (an `.asst-divider`) in front of it: only when the steer cut the
|
|
1235
|
+
* Assistant's own reply (`cut`), and that reply is what came last before the notice (status rows such as "Aborted."
|
|
1236
|
+
* between them do not count). `prevKinds` are the classes of the rows above, nearest first: 'assistant', 'status',
|
|
1237
|
+
* 'divider', 'user', 'route' (a usage / automation / route line), 'other'. A normal turn, a worker's steer and a notice after a break already drawn get none.
|
|
1238
|
+
*/
|
|
1239
|
+
export function steerBreakBefore({ kind = 'steer', cut = false, prevKinds = [] } = {}) {
|
|
1240
|
+
if (kind !== 'steer' || !cut) return false;
|
|
1241
|
+
for (const k of prevKinds) {
|
|
1242
|
+
// "Interrupted." and the cut turn's usage / automation line sit between its reply and the notice.
|
|
1243
|
+
if (k === 'status' || k === 'route') continue;
|
|
1244
|
+
return k === 'assistant';
|
|
1245
|
+
}
|
|
1246
|
+
return false;
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
/** A turn (or a result, a run end) that ended because it was steered: never "Task complete", never a failure. */
|
|
1250
|
+
export function isSteeredEnd(value) {
|
|
1251
|
+
if (!value || typeof value !== 'object') return false;
|
|
1252
|
+
const reasons = [value.reason, value.turnEndReason, value.endReason, value.stopReason, value.lastTurn?.reason, value.lastResult?.reason, value.result?.reason, value.subtype];
|
|
1253
|
+
return reasons.some((r) => r === 'steered');
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
/** The run is between its interrupted turn and the steer's turn: the card says "Steering…". */
|
|
1257
|
+
export function isSteering(run) {
|
|
1258
|
+
if (!run || typeof run !== 'object') return false;
|
|
1259
|
+
if (STEER_TERMINAL.has(String(run.status || '')) || STEER_TERMINAL.has(String(run.state || ''))) return false;
|
|
1260
|
+
return run.steering === true;
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
const STEER_TERMINAL = new Set(['completed', 'failed', 'stopped', 'interrupted', 'cancelled', 'canceled', 'removed']);
|
|
1264
|
+
|
|
1265
|
+
/** The transcript line where a turn was cut: "Steered: <text>" (one line, clipped). Live and on replay. */
|
|
1266
|
+
export function steerNoticeText(text, t = steerTranslator(), { run = '' } = {}) {
|
|
1267
|
+
const flat = String(text ?? '').replace(/\s+/g, ' ').trim();
|
|
1268
|
+
const clipped = flat.length > 160 ? `${flat.slice(0, 159).trimEnd()}…` : flat;
|
|
1269
|
+
return run ? t('noticeRun', { run, text: clipped }) : t('notice', { text: clipped });
|
|
1270
|
+
}
|
|
1271
|
+
|
|
1272
|
+
/** The line the runtime puts above a steer of the brain's own turn (lib/assistant-runtime.js STEER_BRAIN_LINE). */
|
|
1273
|
+
export const STEER_BRAIN_LINE = '[SynaBun Steer] The user interrupted your current turn to change it:';
|
|
1274
|
+
|
|
1275
|
+
/** A prompt the runtime sent for a steer → the user's words (the model's line taken off), else null. */
|
|
1276
|
+
export function steerPromptText(text) {
|
|
1277
|
+
const value = String(text ?? '');
|
|
1278
|
+
if (!value.startsWith(STEER_BRAIN_LINE)) return null;
|
|
1279
|
+
return value.slice(STEER_BRAIN_LINE.length).replace(/^\s*\n?/, '').trim();
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
/** The longest a run says "Steering…": whatever the panel hears or misses, the mark never stays longer. */
|
|
1283
|
+
export const STEER_MARK_MAX_MS = 30_000;
|
|
1284
|
+
|
|
1285
|
+
/** The run's token count as the card shows it (usage packets first), or null. */
|
|
1286
|
+
export function steerTokensOf(run) {
|
|
1287
|
+
const total = Number(run?.usageTokens?.total ?? run?.tokens?.total);
|
|
1288
|
+
return Number.isFinite(total) && total >= 0 ? total : null;
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1291
|
+
/** The patch that takes a run's "Steering…" away (steeredAt null: a later merge never brings the mark back). */
|
|
1292
|
+
export const STEER_CLEARED = Object.freeze({ steering: false, steeredAt: null, steerTurnStarted: false });
|
|
1293
|
+
|
|
1294
|
+
/**
|
|
1295
|
+
* After a descriptor merged into a run the panel marked steering: is the steer's turn showing anything yet? Only
|
|
1296
|
+
* then does the mark go, so "Steering…" is seen: the steer's turn starts well under a second after the steer.
|
|
1297
|
+
* The steer's turn has STARTED on the server's `steering: false`, a turn_started, a turn start after the mark or a
|
|
1298
|
+
* higher currentIteration (the mark then records `steerTurnStarted` and the tokens at that moment); once started, the
|
|
1299
|
+
* mark goes when the run's tokens grow past that count (the panel's controller also takes it away at the turn's
|
|
1300
|
+
* first text, call or activity: onRunOutput). It always goes when the run ends and STEER_MARK_MAX_MS after the
|
|
1301
|
+
* steer. `previous` is the run before the merge: the server's own `steering: false` overwrote the mark in `merged`,
|
|
1302
|
+
* and a mark the panel made (its steeredAt) is held through it. A patch that names `steeredAt` itself (STEER_CLEARED)
|
|
1303
|
+
* is the panel's own word. A mark without a steeredAt (another window's, seen in a descriptor) follows the server.
|
|
1304
|
+
* Returns the run to keep (the same object when nothing changes).
|
|
1305
|
+
*/
|
|
1306
|
+
export function settleSteering(merged, update = null, { previous = null, now = Date.now() } = {}) {
|
|
1307
|
+
if (!merged) return merged;
|
|
1308
|
+
const u = update && typeof update === 'object' ? update : {};
|
|
1309
|
+
const terminal = (run) => STEER_TERMINAL.has(String(run?.status || '')) || STEER_TERMINAL.has(String(run?.state || ''));
|
|
1310
|
+
let out = merged;
|
|
1311
|
+
if (out.steering !== true && previous?.steering === true && previous.steeredAt && u.steeredAt === undefined && !terminal(out)) {
|
|
1312
|
+
out = {
|
|
1313
|
+
...out, steering: true, steeredAt: previous.steeredAt, steerText: previous.steerText, steerIteration: previous.steerIteration,
|
|
1314
|
+
steerTokens: previous.steerTokens ?? null, steerTurnStarted: previous.steerTurnStarted === true,
|
|
1315
|
+
};
|
|
1316
|
+
}
|
|
1317
|
+
if (out.steering !== true) return out;
|
|
1318
|
+
const clear = () => ({ ...out, ...STEER_CLEARED });
|
|
1319
|
+
if (terminal(out)) return clear();
|
|
1320
|
+
const markAt = Date.parse(out.steeredAt || '') || 0;
|
|
1321
|
+
if (!markAt) return u.steering === false ? clear() : out;
|
|
1322
|
+
if (now - markAt > STEER_MARK_MAX_MS) return clear();
|
|
1323
|
+
const turnAt = Date.parse(u.turnStartedAt || u.lastTurnStartedAt || '') || 0;
|
|
1324
|
+
const base = Number(out.steerIteration);
|
|
1325
|
+
const iteration = Number(u.currentIteration);
|
|
1326
|
+
const startsNow = u.steering === false || u.type === 'turn_started' || u.event === 'turn_started' || u.reason === 'turn_started'
|
|
1327
|
+
|| (turnAt > markAt) || (Number.isFinite(base) && Number.isFinite(iteration) && iteration > base);
|
|
1328
|
+
if (out.steerTurnStarted !== true) {
|
|
1329
|
+
if (!startsNow) return out;
|
|
1330
|
+
// The tokens the cut turn booked so far are not the steer's turn's output: counted from here.
|
|
1331
|
+
return { ...out, steerTurnStarted: true, steerTokens: steerTokensOf(out) ?? out.steerTokens ?? null };
|
|
1332
|
+
}
|
|
1333
|
+
const tokens = steerTokensOf(out);
|
|
1334
|
+
const at = Number(out.steerTokens);
|
|
1335
|
+
if (tokens !== null && Number.isFinite(at) && tokens > at) return clear();
|
|
1336
|
+
return out;
|
|
1337
|
+
}
|
|
1338
|
+
|
|
1339
|
+
/**
|
|
1340
|
+
* Whether a worker's provider event is output of its turn (text, a call, thinking): what ends "Steering…" once the
|
|
1341
|
+
* steer's turn has started. `activity` is what activityOf (asst-scenes.js) found in it, when the caller has it.
|
|
1342
|
+
*/
|
|
1343
|
+
export function isRunOutputEvent(payload, activity = null) {
|
|
1344
|
+
if (activity) return true;
|
|
1345
|
+
const event = payload?.event && typeof payload.event === 'object' ? payload.event : null;
|
|
1346
|
+
if (!event) return false;
|
|
1347
|
+
const type = String(payload.eventType || event.type || '');
|
|
1348
|
+
if (event.type === 'assistant') return Array.isArray(event.message?.content) && event.message.content.length > 0; // Claude Code
|
|
1349
|
+
if (event.type === 'stream_event') return /delta|content_block_start/.test(String(event.event?.type || ''));
|
|
1350
|
+
if (/^item\.(started|updated|completed)$/.test(type)) return !!event.item && event.item.type !== 'user_message'; // Codex
|
|
1351
|
+
if (/^message[.:]part[.:](updated|delta)$/i.test(type)) { // OpenCode
|
|
1352
|
+
const part = event.part || {};
|
|
1353
|
+
return /^(text|tool|reasoning)$/.test(String(part.type || '')) || /^message[.:]part[.:]delta$/i.test(type);
|
|
1354
|
+
}
|
|
1355
|
+
return /^(agent_message_chunk|agent_thought_chunk|tool_call|tool_call_update)$/.test(type); // Antigravity (ACP)
|
|
1356
|
+
}
|
|
1357
|
+
|
|
1358
|
+
/** Whether a run card offers Steer: a run that is not over (queued and starting runs too: the server answers). */
|
|
1359
|
+
export function canSteerRun(run) {
|
|
1360
|
+
if (!run?.runId) return false;
|
|
1361
|
+
const status = String(run.status || '');
|
|
1362
|
+
const state = String(run.state || '');
|
|
1363
|
+
if (STEER_TERMINAL.has(status) || STEER_TERMINAL.has(state)) return false;
|
|
1364
|
+
if (run.removed === true) return false;
|
|
1365
|
+
return true;
|
|
1366
|
+
}
|
|
1367
|
+
|
|
1368
|
+
/** The composer's target chip: "→ #2 Fix the login bug" (title clipped). */
|
|
1369
|
+
export function targetChipText(target, t = steerTranslator()) {
|
|
1370
|
+
const title = String(target?.title || target?.runId || '').replace(/\s+/g, ' ').trim();
|
|
1371
|
+
const short = title.length > 40 ? `${title.slice(0, 39).trimEnd()}…` : title;
|
|
1372
|
+
return t('targetChip', { n: target?.index ?? '?', title: short }).replace(/#\?\s*/, '');
|
|
1373
|
+
}
|