synabun 2.4.2 → 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.
Files changed (103) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +1 -1
  3. package/docs/browser-extension-bridge.md +23 -3
  4. package/lib/release-npm-ci.mjs +23 -1
  5. package/mcp-server/dist/services/neural-interface.js +1 -1
  6. package/mcp-server/dist/services/neural-interface.js.map +1 -1
  7. package/mcp-server/dist/tools/browser-extension-setup.d.ts.map +1 -1
  8. package/mcp-server/dist/tools/browser-extension-setup.js +8 -2
  9. package/mcp-server/dist/tools/browser-extension-setup.js.map +1 -1
  10. package/mcp-server/package-lock.json +5 -5
  11. package/mcp-server/package.json +1 -1
  12. package/mcp-server/src/services/neural-interface.ts +1 -1
  13. package/mcp-server/src/tools/browser-extension-setup.ts +8 -2
  14. package/neural-interface/i18n/en.json +50 -1
  15. package/neural-interface/i18n/pt-BR.json +57 -8
  16. package/neural-interface/lib/assistant-api.js +33 -0
  17. package/neural-interface/lib/assistant-brains/opencode.js +121 -7
  18. package/neural-interface/lib/assistant-dispatch.js +26 -2
  19. package/neural-interface/lib/assistant-envelope.js +40 -0
  20. package/neural-interface/lib/assistant-runtime.js +95 -10
  21. package/neural-interface/lib/browser-extension-adapter.js +1 -3
  22. package/neural-interface/lib/browser-extension-archive.js +149 -0
  23. package/neural-interface/lib/browser-extension-bridge.js +7 -4
  24. package/neural-interface/lib/browser-extension-folder.js +596 -76
  25. package/neural-interface/lib/browser-extension-package.js +200 -0
  26. package/neural-interface/lib/browser-extension-pin.js +84 -0
  27. package/neural-interface/lib/browser-extension-pin.json +33 -0
  28. package/neural-interface/lib/browser-extension-setup.js +105 -18
  29. package/neural-interface/lib/cli-install.js +23 -3
  30. package/neural-interface/lib/cli-update-planner.js +67 -4
  31. package/neural-interface/lib/native-loop-providers.js +10 -1
  32. package/neural-interface/lib/native-loop-runtime.js +20 -2
  33. package/neural-interface/lib/opencode-shell-read.js +107 -0
  34. package/neural-interface/lib/opencode-stop-failures.js +40 -0
  35. package/neural-interface/lib/opencode-turn-release.js +173 -0
  36. package/neural-interface/lib/opencode-v2-client.js +4 -1
  37. package/neural-interface/lib/opencode-v2-ws-requests.js +34 -0
  38. package/neural-interface/lib/opencode2-client.js +341 -6
  39. package/neural-interface/lib/opencode2-translate.js +161 -4
  40. package/neural-interface/lib/terminal-token-redaction.js +83 -0
  41. package/neural-interface/lib/whatsapp/bridge.js +52 -6
  42. package/neural-interface/package-lock.json +5 -5
  43. package/neural-interface/package.json +1 -1
  44. package/neural-interface/public/extension-setup.html +5 -2
  45. package/neural-interface/public/shared/agy/agy-panel.js +38 -10
  46. package/neural-interface/public/shared/assistant/asst-api.js +25 -0
  47. package/neural-interface/public/shared/assistant/asst-panel.js +69 -1
  48. package/neural-interface/public/shared/assistant/asst-rack-styles.js +23 -0
  49. package/neural-interface/public/shared/assistant/asst-render.js +138 -6
  50. package/neural-interface/public/shared/assistant/asst-shell-logic.js +200 -0
  51. package/neural-interface/public/shared/assistant/asst-shell.js +111 -0
  52. package/neural-interface/public/shared/assistant/asst-styles.js +1 -0
  53. package/neural-interface/public/shared/cdx/cdx-tabs.js +25 -0
  54. package/neural-interface/public/shared/extension-setup/es-page.js +10 -4
  55. package/neural-interface/public/shared/extension-setup/es-view.js +25 -10
  56. package/neural-interface/public/shared/mtc/mtc-panel.js +17 -2
  57. package/neural-interface/public/shared/ocp-v2/ocp-v2-events.js +5 -0
  58. package/neural-interface/public/shared/ocp-v2/ocp-v2-manager.js +1 -0
  59. package/neural-interface/public/shared/ocp-v2/ocp-v2-panel.js +34 -2
  60. package/neural-interface/public/shared/ocp-v2/ocp-v2-rehydrate.js +7 -1
  61. package/neural-interface/public/shared/ocp-v2/ocp-v2-render.js +26 -1
  62. package/neural-interface/public/shared/ocp-v2/ocp-v2-send.js +39 -6
  63. package/neural-interface/public/shared/ocp-v2/ocp-v2-session-actions.js +20 -1
  64. package/neural-interface/public/shared/ocp-v2/ocp-v2-shell-block.js +165 -0
  65. package/neural-interface/public/shared/ocp-v2/ocp-v2-shell-logic.js +346 -0
  66. package/neural-interface/public/shared/ocp-v2/ocp-v2-shell.js +108 -0
  67. package/neural-interface/public/shared/ocp-v2/ocp-v2-state.js +49 -3
  68. package/neural-interface/public/shared/ocp-v2/ocp-v2-styles.js +40 -0
  69. package/neural-interface/public/shared/ocp-v2/ocp-v2-tools-logic.js +20 -5
  70. package/neural-interface/public/shared/ocp-v2/ocp-v2-tools.js +7 -1
  71. package/neural-interface/public/shared/ocp-v2/ocp-v2-ws.js +7 -2
  72. package/neural-interface/public/shared/settings/settings-browser-extension.js +54 -12
  73. package/neural-interface/public/shared/shell-stop-view.js +83 -0
  74. package/neural-interface/public/shared/tour/tour-actor.js +14 -3
  75. package/neural-interface/public/shared/tray-auto-close.js +36 -6
  76. package/neural-interface/public/shared/ui-claude-panel.js +20 -0
  77. package/neural-interface/public/shared/ui-native-loop-router.js +45 -3
  78. package/neural-interface/public/shared/ui-scroll-follow.js +4 -0
  79. package/neural-interface/server.js +249 -35
  80. package/npm-shrinkwrap.json +5 -5
  81. package/package.json +1 -2
  82. package/browser-extension/content.js +0 -231
  83. package/browser-extension/engine.js +0 -658
  84. package/browser-extension/icons/icon-128.png +0 -0
  85. package/browser-extension/icons/icon-16.png +0 -0
  86. package/browser-extension/icons/icon-32.png +0 -0
  87. package/browser-extension/icons/icon-48.png +0 -0
  88. package/browser-extension/icons/status-off-16.png +0 -0
  89. package/browser-extension/icons/status-off-32.png +0 -0
  90. package/browser-extension/icons/status-off-48.png +0 -0
  91. package/browser-extension/icons/status-on-16.png +0 -0
  92. package/browser-extension/icons/status-on-32.png +0 -0
  93. package/browser-extension/icons/status-on-48.png +0 -0
  94. package/browser-extension/manifest.json +0 -58
  95. package/browser-extension/popup-strings.js +0 -250
  96. package/browser-extension/popup-view.js +0 -151
  97. package/browser-extension/popup.css +0 -166
  98. package/browser-extension/popup.html +0 -108
  99. package/browser-extension/popup.js +0 -359
  100. package/browser-extension/service-worker.js +0 -283
  101. package/browser-extension/setup-content.js +0 -36
  102. package/browser-extension/tokens.css +0 -326
  103. /package/{browser-extension/protocol.js → neural-interface/lib/browser-extension-protocol.js} +0 -0
@@ -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
+ }
@@ -78,6 +78,13 @@ export function createPanelStore() {
78
78
  todos: [],
79
79
  // What the session changed on disk (session.diff): SnapshotFileDiff[].
80
80
  sessionDiff: [],
81
+ // The shell commands of the session's tool calls (shell.updated, shell:list):
82
+ // shellId → { id, status, command, callID, messageID, background, waited,
83
+ // exit, time }. A command can outlive its tool call ("in the background").
84
+ shells: new Map(),
85
+ // What each command has printed, as far as it was read (ocp-v2-shell-logic.js):
86
+ // shellId → { text, from, size, done, gone, error }.
87
+ shellOutput: new Map(),
81
88
 
82
89
  mode: 'build',
83
90
  agent: 'build',
@@ -112,7 +119,7 @@ export function createPanelStore() {
112
119
  // `binding` counts how often the store moved to another session: an answer
113
120
  // that was asked for under an older binding belongs to a session the panel
114
121
  // has left (or left and came back to) and is dropped by whoever asked.
115
- const _rev = { status: 0, permissions: 0, questions: 0, todos: 0, binding: 0 };
122
+ const _rev = { status: 0, permissions: 0, questions: 0, todos: 0, shells: 0, binding: 0 };
116
123
  function getRevisions() { return { ..._rev }; }
117
124
  // The binding identity on its own: it changes every time the store is bound
118
125
  // to another session (a new one, a switch, a project change, no session),
@@ -175,7 +182,7 @@ export function createPanelStore() {
175
182
  // left is gone before any listener runs, so nobody sees the new session
176
183
  // with the old one's run state or requests.
177
184
  _rev.binding += 1;
178
- _rev.status += 1; _rev.todos += 1; _rev.permissions += 1; _rev.questions += 1;
185
+ _rev.status += 1; _rev.todos += 1; _rev.permissions += 1; _rev.questions += 1; _rev.shells += 1;
179
186
  const wasRunning = _state.running;
180
187
  _state.running = false;
181
188
  _state.sessionStatus = { type: 'idle' };
@@ -183,6 +190,9 @@ export function createPanelStore() {
183
190
  _state.autoAccept = false;
184
191
  _state.todos = [];
185
192
  _state.sessionDiff = [];
193
+ // A command belongs to the session that ran it, and so does what it printed.
194
+ _state.shells = new Map();
195
+ _state.shellOutput = new Map();
186
196
  _state.contextGauge = createDefaultContextGauge(sessionId ? 'pending' : 'idle');
187
197
  // A request waiting for an answer belongs to the session it was raised
188
198
  // in. One that arrived while the next session was still being created
@@ -409,6 +419,42 @@ export function createPanelStore() {
409
419
  notify({ type: 'diff:set' });
410
420
  }
411
421
 
422
+ // One command changed (shell.updated): it started with its call, went on in
423
+ // the background, or ended. A command of another session is not this store's.
424
+ function upsertShell(shell) {
425
+ const id = shell && typeof shell.id === 'string' ? shell.id : '';
426
+ if (!id) return false;
427
+ if (shell.sessionID && _state.sessionId && shell.sessionID !== _state.sessionId) return false;
428
+ _rev.shells += 1;
429
+ _state.shells.set(id, { ..._state.shells.get(id), ...shell });
430
+ notify({ type: 'shell:update', shellId: id });
431
+ return true;
432
+ }
433
+
434
+ // The server's list of the session's commands (after a reload or a reconnect):
435
+ // what it knows replaces what the store held, what it printed is kept.
436
+ function setShells(list) {
437
+ _rev.shells += 1;
438
+ const next = new Map();
439
+ for (const shell of Array.isArray(list) ? list : []) {
440
+ if (!shell || typeof shell.id !== 'string' || !shell.id) continue;
441
+ if (shell.sessionID && _state.sessionId && shell.sessionID !== _state.sessionId) continue;
442
+ next.set(shell.id, { ..._state.shells.get(shell.id), ...shell });
443
+ }
444
+ _state.shells = next;
445
+ notify({ type: 'shell:update', shellId: null });
446
+ }
447
+
448
+ // What a command printed, as far as it was read. Only the transcript's
449
+ // terminal blocks read this (they draw it themselves): no slice of the
450
+ // rehydrated state depends on it.
451
+ function setShellOutput(shellId, view) {
452
+ if (!shellId) return;
453
+ if (view) _state.shellOutput.set(shellId, view);
454
+ else _state.shellOutput.delete(shellId);
455
+ notify({ type: 'shell:output', shellId });
456
+ }
457
+
412
458
  function setAutoAccept(value) {
413
459
  const next = !!value;
414
460
  if (_state.autoAccept === next) return;
@@ -661,7 +707,7 @@ export function createPanelStore() {
661
707
  appendPartDelta, removePart, hydrateMessages,
662
708
  setRunning, setSessionStatus, setCompacting,
663
709
  setPendingPermission, setPendingPermissions, addPendingPermission, removePendingPermission,
664
- setAutoAccept, setTodos, setSessionDiff,
710
+ setAutoAccept, setTodos, setSessionDiff, upsertShell, setShells, setShellOutput,
665
711
  setPendingQuestions, addPendingQuestion, removePendingQuestion,
666
712
  pushError, dismissError, clearErrors, setHealing, setKnownSessions,
667
713
  setHelpCard,
@@ -3353,6 +3353,46 @@ const PARITY_CSS = `
3353
3353
  padding: 6px 12px;
3354
3354
  border-top: 1px solid rgba(255,255,255,0.05);
3355
3355
  }
3356
+ /* A command's output as it is printed (ocp-v2-shell.js). The block scrolls by itself, so a long test run
3357
+ never stretches the transcript; its colours and type are the tool output's. */
3358
+ .ocpv2-term { display: flex; flex-direction: column; min-width: 0; }
3359
+ .ocpv2-term-out {
3360
+ max-height: 340px;
3361
+ overflow: auto;
3362
+ overscroll-behavior: contain;
3363
+ tab-size: 4;
3364
+ }
3365
+ .ocpv2-term-out:focus-visible { outline: 1px solid rgba(255,255,255,0.28); outline-offset: -1px; }
3366
+ .ocpv2-term-note,
3367
+ .ocpv2-term-foot {
3368
+ display: flex;
3369
+ align-items: center;
3370
+ gap: 10px;
3371
+ padding: 6px 12px;
3372
+ border-top: 1px solid rgba(255,255,255,0.05);
3373
+ font-size: 10.5px;
3374
+ line-height: 1.5;
3375
+ color: rgba(255,255,255,0.55);
3376
+ }
3377
+ /* What the block hides is gone, whatever its own class says about display (a button of the card is a block). */
3378
+ .ocpv2-term [hidden] { display: none; }
3379
+ .ocpv2-term-note .ocpv2-tc-more,
3380
+ .ocpv2-term-foot .ocpv2-tc-more { margin-top: 0; flex-shrink: 0; }
3381
+ .ocpv2-term-state { flex: 1; min-width: 0; }
3382
+ .ocpv2-term[data-running="true"] .ocpv2-term-state::after {
3383
+ content: '';
3384
+ display: inline-block;
3385
+ width: 5px;
3386
+ height: 5px;
3387
+ margin-left: 6px;
3388
+ border-radius: 50%;
3389
+ background: rgba(232,224,220,0.75);
3390
+ vertical-align: middle;
3391
+ animation: ocpv2-term-pulse 1.2s ease-in-out infinite;
3392
+ }
3393
+ @keyframes ocpv2-term-pulse { 0%, 100% { opacity: 0.25; } 50% { opacity: 1; } }
3394
+ @media (prefers-reduced-motion: reduce) { .ocpv2-term[data-running="true"] .ocpv2-term-state::after { animation: none; } }
3395
+ .ocpv2-term-foot .ocpv2-msg-action { opacity: 1; }
3356
3396
  .ocpv2-tc-diff { white-space: pre; overflow-x: auto; }
3357
3397
  .ocpv2-diff-line { min-height: 1.5em; }
3358
3398
  .ocpv2-diff-add { color: rgba(140,200,160,0.85); background: rgba(140,200,160,0.04); }
@@ -8,6 +8,8 @@
8
8
  // tool this file does not know falls back to its input and output as text.
9
9
  // ─────────────────────────────────────────────────────────────────────────────
10
10
 
11
+ import { shellCardState } from './ocp-v2-shell-logic.js';
12
+
11
13
  export const TOOL_OUTPUT_MAX_LINES = 24;
12
14
  export const TOOL_OUTPUT_MAX_CHARS = 4000;
13
15
 
@@ -133,9 +135,15 @@ function diffSection(lines) {
133
135
  * Everything a tool card shows.
134
136
  * { tool, label, iconKey, status, title, meta, sections, defaultExpanded,
135
137
  * copyText, childSessionId, attachments }
136
- * sections: { kind: 'code' | 'output' | 'error' | 'diff' | 'todos', … }
138
+ * sections: { kind: 'code' | 'output' | 'error' | 'diff' | 'todos' | 'terminal', … }
139
+ * `context.shell`: the shell command of a bash call as the panel knows it live
140
+ * (ocp-v2-state.js `shells`), with `context.live` when its output can be read
141
+ * as it is printed: the card then shows a terminal block instead of the text
142
+ * the call returned, and says whether the command still runs. OpenCode ends a
143
+ * call whose command runs on in the background: the call is "completed" then,
144
+ * the command is not.
137
145
  */
138
- export function toolCardView(part) {
146
+ export function toolCardView(part, context = {}) {
139
147
  const state = part?.state && typeof part.state === 'object' ? part.state : {};
140
148
  const input = state.input && typeof state.input === 'object' ? state.input : (part?.input && typeof part.input === 'object' ? part.input : {});
141
149
  const metadata = state.metadata && typeof state.metadata === 'object' ? state.metadata : {};
@@ -165,11 +173,18 @@ export function toolCardView(part) {
165
173
  const command = str(input.command);
166
174
  view.title = oneLine(input.description) || view.title || oneLine(command);
167
175
  if (command) view.sections.push({ kind: 'code', text: command, prompt: '$' });
168
- addOutput(str(metadata.output) || output);
176
+ const shell = context.shell && typeof context.shell === 'object' ? context.shell : null;
177
+ const live = shell ? shellCardState(shell) : null;
178
+ if (shell && context.live) view.sections.push({ kind: 'terminal', shellId: str(shell.id), text: `${shell.status}:${shell.exit ?? ''}` });
179
+ else addOutput(str(metadata.output) || output);
169
180
  view.copyText = command;
181
+ if (live?.status) view.status = live.status;
182
+ const exit = typeof shell?.exit === 'number' ? shell.exit : (typeof metadata.exit === 'number' ? metadata.exit : null);
183
+ const note = live?.note || (exit != null && exit !== 0 ? `exit ${exit}` : '');
184
+ if (live?.running && Number.isFinite(start)) view.meta = '';
185
+ if (note) view.meta = [view.meta, note].filter(Boolean).join(' · ');
170
186
  // A command that is running or failed is what the user is waiting on.
171
- view.defaultExpanded = status !== 'completed';
172
- if (typeof metadata.exit === 'number' && metadata.exit !== 0) view.meta = [view.meta, `exit ${metadata.exit}`].filter(Boolean).join(' · ');
187
+ view.defaultExpanded = view.status !== 'completed' || (exit != null && exit !== 0);
173
188
  break;
174
189
  }
175
190
  case 'edit':
@@ -87,9 +87,11 @@ function attachmentNode(file) {
87
87
  * helpers:
88
88
  * contentBlocks(output) → a node for MCP content blocks, or null
89
89
  * onOpenChild(sessionId) → open the sub-agent session of a task card
90
+ * shell → the shell command of a bash call, as the panel knows it live
91
+ * terminal(shellId) → the node that shows that command's output as it is printed
90
92
  */
91
93
  export function renderToolCard(part, helpers = {}) {
92
- const view = toolCardView(part);
94
+ const view = toolCardView(part, { shell: helpers.shell || null, live: typeof helpers.terminal === 'function' });
93
95
  const callId = part.callID || part.id || `${view.tool}-${part.messageID || ''}`;
94
96
  const expanded = _expandedByUser.has(callId) ? _expandedByUser.get(callId) : view.defaultExpanded;
95
97
 
@@ -119,6 +121,8 @@ export function renderToolCard(part, helpers = {}) {
119
121
  const next = !wrap.classList.contains('ocpv2-tool-expanded');
120
122
  _expandedByUser.set(callId, next);
121
123
  wrap.classList.toggle('ocpv2-tool-expanded', next);
124
+ // A terminal block has a size only once its card is open.
125
+ if (next) for (const term of wrap.querySelectorAll('.ocpv2-term')) term.dispatchEvent(new Event('ocpv2-term-show'));
122
126
  });
123
127
  wrap.appendChild(head);
124
128
 
@@ -126,6 +130,8 @@ export function renderToolCard(part, helpers = {}) {
126
130
  for (const section of view.sections) {
127
131
  if (section.kind === 'code') {
128
132
  body.appendChild(el('div', 'ocpv2-tool-input', section.prompt ? `${section.prompt} ${section.text}` : section.text));
133
+ } else if (section.kind === 'terminal') {
134
+ body.appendChild(helpers.terminal(section.shellId));
129
135
  } else if (section.kind === 'output') {
130
136
  body.appendChild(outputSection(section, helpers));
131
137
  } else if (section.kind === 'diff') {
@@ -718,10 +718,12 @@ async function settleAsk(eventType, sessionId, requestId, response) {
718
718
  return result;
719
719
  }
720
720
 
721
- async function abortSession(sessionId) {
721
+ // `force`: "Stop anyway" (offered after a second Stop that could not end a command): the turn ends even while that
722
+ // command may still run. A server from before it ignores the flag (a plain Stop).
723
+ async function abortSession(sessionId, { force = false } = {}) {
722
724
  const pending = _asks.openAsksOf(sessionId);
723
725
  const stored = storedAsks((owner) => owner === sessionId || knownDescendant(owner, sessionId, _parentOf));
724
- const result = await request({ type: 'message:abort', sessionId });
726
+ const result = await request({ type: 'message:abort', sessionId, ...(force ? { force: true } : {}) });
725
727
  if (!replyFailed(result)) {
726
728
  // Stop can finish after a new turn has started. Clear only the requests seen when Stop was pressed.
727
729
  for (const ask of pending) _asks.note(`${ask.kind}.replied`, { requestID: ask.id, sessionID: ask.owner });
@@ -766,6 +768,9 @@ export const api = {
766
768
  sessionStatus: ({ sessionId, cwd } = {}) => gated({ type: 'session:status', sessionId, cwd }),
767
769
  permissionList: ({ sessionId, cwd } = {}) => gated({ type: 'permission:list', sessionId, cwd }),
768
770
  sessionTodo: ({ sessionId, cwd } = {}) => gated({ type: 'session:todo', sessionId, cwd }),
771
+ // The shell commands of the session's tool calls, and a page of what one printed (ocp-v2-shell-logic.js).
772
+ shellList: ({ sessionId, cwd } = {}) => gated({ type: 'shell:list', sessionId, cwd }),
773
+ shellOutput: ({ sessionId, shellId, cwd, cursor, tail, limit } = {}) => gated({ type: 'shell:output', sessionId, shellId, cwd, cursor, tail, limit }),
769
774
  sessionRevert: ({ sessionId, messageID, partID, cwd } = {}) => gated({ type: 'session:revert', sessionId, messageID, partID, cwd }),
770
775
  sessionUnrevert: ({ sessionId, cwd } = {}) => gated({ type: 'session:unrevert', sessionId, cwd }),
771
776
  sessionFork: ({ sessionId, messageID, cwd } = {}) => gated({ type: 'session:fork', sessionId, messageID, cwd }),
@@ -37,6 +37,7 @@ export function extensionSettingsHTML(kit) {
37
37
  <span class="stg-badge bc-ext-status" id="bc-extension-status" role="status" aria-live="polite" aria-labelledby="bc-extension-status-label"></span>
38
38
  </div>
39
39
  <p class="stg-help bc-ext-text bc-ext-status-help" id="bc-extension-status-help"></p>
40
+ <p class="stg-help bc-ext-text bc-ext-note" id="bc-extension-moved" hidden>${c('movedHelp')}</p>
40
41
  <div class="bc-inline-group bc-ext-actions" id="bc-extension-status-actions" hidden>
41
42
  <button type="button" class="cli-detect-btn bc-ext-primary" data-extension-action="resume">${c('reconnect')}</button>
42
43
  <button type="button" class="cli-detect-btn" data-extension-action="retry" hidden>${c('retry')}</button>
@@ -71,7 +72,14 @@ export function extensionSettingsHTML(kit) {
71
72
  <p class="stg-help bc-ext-text" id="bc-extension-setup-status" role="status" aria-live="polite"></p>
72
73
  <div class="bc-inline-group bc-ext-actions" id="bc-extension-setup-alternatives" hidden></div>
73
74
  <p class="stg-help bc-ext-text bc-ext-note" id="bc-extension-setup-default">${c('setupDefault')}</p>
74
- <p class="stg-help bc-ext-text bc-ext-note" id="bc-extension-reload" data-tone="warn" hidden>${t('reloadNeeded')}</p>
75
+ <p class="stg-help bc-ext-text bc-ext-note" id="bc-extension-reload" data-tone="warn" data-reload-text="${t('reloadNeeded')}" data-repaired-text="${t('reloadRepaired')}" hidden>${t('reloadNeeded')}</p>
76
+ <div class="bc-inline-group bc-ext-actions" id="bc-extension-reload-actions" hidden>
77
+ <button type="button" class="cli-detect-btn" data-extension-action="reload-confirm">${c('reloadConfirm')}</button>
78
+ </div>
79
+ <p class="stg-help bc-ext-text bc-ext-note" id="bc-extension-update" data-tone="warn" role="status" data-updating-text="${c('updating')}" data-failed-text="${c('updateFailed')}" hidden></p>
80
+ <div class="bc-inline-group bc-ext-actions" id="bc-extension-update-actions" hidden>
81
+ <button type="button" class="cli-detect-btn" data-extension-action="update">${c('retry')}</button>
82
+ </div>
75
83
  </section>
76
84
  <details class="stg-advanced bc-ext-advanced" id="bc-extension-files" data-extension-section="files">
77
85
  <summary>${CHEVRON}<span>${c('advanced')}</span></summary>
@@ -90,7 +98,7 @@ export function extensionSettingsHTML(kit) {
90
98
  <p class="stg-help bc-ext-text">${t('install')}</p>
91
99
  <label class="bc-ext-label" for="bc-extension-folder">${t('folder')}</label>
92
100
  <div class="bc-ext-control-row">
93
- <input class="browser-cfg-input bc-ext-path" id="bc-extension-folder" readonly spellcheck="false" autocomplete="off">
101
+ <input class="browser-cfg-input bc-ext-path" id="bc-extension-folder" readonly spellcheck="false" autocomplete="off" placeholder="${c('folderPending')}">
94
102
  <div class="bc-inline-group bc-ext-actions">${button('copy', 'copy')}${button('refresh', 'refresh')}</div>
95
103
  </div>
96
104
  </section>
@@ -130,6 +138,7 @@ export function cardState(data, setup = null, { failed = false, launching = fals
130
138
  const running = setup?.state || data?.setup;
131
139
  if (launching) return 'launching';
132
140
  if (data?.connected) return failed ? 'error' : 'connected';
141
+ if (running === 'downloading') return 'downloading';
133
142
  if (running === 'waiting-for-extension') return 'setup';
134
143
  if (running === 'pairing') return 'pairing';
135
144
  if (running === 'unsupported') return 'unsupported';
@@ -137,6 +146,22 @@ export function cardState(data, setup = null, { failed = false, launching = fals
137
146
  if (data?.paired) return 'disconnected';
138
147
  return 'unpaired';
139
148
  }
149
+ /** The setup's download errors (lib/browser-extension-setup.js DOWNLOAD_ERRORS): each has its own sentence, and Try again. */
150
+ export const DOWNLOAD_ERRORS = Object.freeze(['EXTENSION_DOWNLOAD_OFFLINE', 'EXTENSION_DOWNLOAD_UNAVAILABLE', 'EXTENSION_VERIFY_FAILED']);
151
+ /** How far a download is, 0 to 100 (0 while the size is not known). */
152
+ export function downloadPercent(download) {
153
+ const total = Number(download?.total) || 0, received = Number(download?.received) || 0;
154
+ return total > 0 ? Math.max(0, Math.min(100, Math.floor(received / total * 100))) : 0;
155
+ }
156
+ /**
157
+ * What the card says about the folder's own update (a folder older than this release's extension, which SynaBun
158
+ * downloads by itself): 'updating' while it is on its way or about to be, 'failed' when it did not arrive, else null.
159
+ */
160
+ export function updateNote(data) {
161
+ const pkg = data?.package;
162
+ if (!pkg || pkg.needs !== 'update') return null;
163
+ return pkg.phase === 'failed' ? 'failed' : 'updating';
164
+ }
140
165
  /** Host and path of an address: the query and fragment (sign-in challenges, tokens) are never shown. */
141
166
  export function shownAddress(url) {
142
167
  let u;
@@ -161,7 +186,7 @@ export function groupByAgent(tabs = []) {
161
186
  const STATUS_TONES = ['stg-badge-ok', 'stg-badge-warn', 'stg-badge-err'];
162
187
  const HEAD = {
163
188
  connected: ['ok', 'connectedHelp'], disconnected: ['warn', 'disconnectedHelp'], unpaired: ['off', 'unpairedHelp'],
164
- launching: ['sync', 'launchingHelp'], setup: ['sync', 'setupRunningHelp'], pairing: ['sync', 'pairingHelp'],
189
+ launching: ['sync', 'launchingHelp'], downloading: ['sync', 'downloadingHelp'], setup: ['sync', 'setupRunningHelp'], pairing: ['sync', 'pairingHelp'],
165
190
  unsupported: ['err', 'unsupportedHelp'], error: ['err', 'errorHelp'],
166
191
  };
167
192
  const CONFIRMS = {
@@ -288,24 +313,26 @@ export function wireExtensionSettings(root, { tx, signal }) {
288
313
  if (section.hidden) return;
289
314
  const running = setup?.state || data.setup;
290
315
  section.dataset.state = running;
291
- const again = !!data.paired && !['setup', 'pairing', 'unsupported', 'launching'].includes(state);
316
+ const again = !!data.paired && !['setup', 'pairing', 'unsupported', 'launching', 'downloading'].includes(state);
292
317
  section.dataset.mode = again ? 'again' : 'connect';
293
318
  const title = query('setup-title'), help = query('setup-help');
294
319
  title.textContent = again ? title.dataset.againText : title.dataset.connectText;
295
320
  help.textContent = again ? help.dataset.againText : help.dataset.connectText;
296
321
  const start = query('setup-start');
297
- start.textContent = data.connected ? start.dataset.reinstallText : data.paired ? start.dataset.reconnectText : start.dataset.connectText;
322
+ // A download that failed is tried again by the same button, under its own words.
323
+ const downloadFailed = running === 'error' && DOWNLOAD_ERRORS.includes(setup?.code);
324
+ start.textContent = downloadFailed ? c('retry') : data.connected ? start.dataset.reinstallText : data.paired ? start.dataset.reconnectText : start.dataset.connectText;
298
325
  start.classList.toggle('bc-ext-primary', !data.paired);
299
326
  start.disabled = launching;
300
327
  const active = !['idle', 'connected'].includes(running);
301
- start.hidden = ['waiting-for-extension', 'pairing'].includes(running);
328
+ start.hidden = ['downloading', 'waiting-for-extension', 'pairing'].includes(running);
302
329
  query('setup-cancel').hidden = !active;
303
330
  query('setup-reopen').hidden = running !== 'waiting-for-extension';
304
331
  query('setup-default').hidden = again || active;
305
332
  const name = setup?.browser?.name || '';
306
- const known = ['waiting-for-extension', 'pairing', 'connected', 'unsupported'].includes(running);
307
- query('setup-status').textContent = launching ? c('launching') : running === 'idle' ? '' : known ? tx(`browserExtension.setup.settings_${running.replace(/-/g, '_')}`, { browser: name })
308
- : tx('browserExtension.setup.settings_error', { code: setup?.code || '' });
333
+ const known = ['downloading', 'waiting-for-extension', 'pairing', 'connected', 'unsupported'].includes(running);
334
+ query('setup-status').textContent = launching ? c('launching') : running === 'idle' ? '' : known ? tx(`browserExtension.setup.settings_${running.replace(/-/g, '_')}`, { browser: name, percent: downloadPercent(setup?.download) })
335
+ : downloadFailed ? tx(`browserExtension.setup.error${setup.code}`) : tx('browserExtension.setup.settings_error', { code: setup?.code || '' });
309
336
  const alternatives = query('setup-alternatives'); alternatives.replaceChildren();
310
337
  const others = running === 'unsupported' ? (setup?.installedBrowsers || []).filter(b => b?.supported && b.id !== setup?.browser?.id) : [];
311
338
  for (const browser of others) {
@@ -314,7 +341,19 @@ export function wireExtensionSettings(root, { tx, signal }) {
314
341
  alternatives.append(option);
315
342
  }
316
343
  alternatives.hidden = !others.length;
317
- query('reload').hidden = !(data.reloadNeeded === true);
344
+ // The browser's Reload: for an older copy or a port change, or in a repair's own words (files that were not the
345
+ // extension were replaced, and the browser may still run them). Said until the setup page sees the extension (a port change) or
346
+ // the owner confirms the Reload below (a repair).
347
+ const reload = query('reload'), reloadText = data.reloadRepaired === true ? reload.dataset.repairedText : reload.dataset.reloadText;
348
+ reload.hidden = !(data.reloadNeeded === true);
349
+ if (reloadText && reload.textContent !== reloadText) reload.textContent = reloadText;
350
+ // A repair's Reload ends only by the owner's click here (POST reload/confirm): the copy the browser still runs
351
+ // would answer the setup page just the same, so nothing it says, nor any refresh of this card, clears it.
352
+ query('reload-actions').hidden = !(data.reloadNeeded === true && data.reloadRepaired === true);
353
+ // The folder's own update (never while a setup shows its own download): on its way, or failed with Try again.
354
+ const update = active ? null : updateNote(data), note = query('update');
355
+ note.hidden = !update; note.textContent = update ? (update === 'failed' ? note.dataset.failedText : note.dataset.updatingText) : '';
356
+ query('update-actions').hidden = update !== 'failed';
318
357
  }
319
358
  // The status at the top: a symbol, the word (Settings' badge), what it means, the one action that helps.
320
359
  function showHead(state, data, error) {
@@ -325,13 +364,15 @@ export function wireExtensionSettings(root, { tx, signal }) {
325
364
  if (error) setStatus(`${t('restart')} ${error}`, 'err');
326
365
  else if (state === 'connected') setStatus(`${t('connected')}${modeWord}`, 'ok');
327
366
  else if (state === 'disconnected') setStatus(`${t('disconnected')}${modeWord}`, 'warn');
328
- else if (['setup', 'pairing', 'launching'].includes(state)) setStatus(c(state === 'setup' ? 'setupRunningTitle' : state, { browser: lastSetup?.browser?.name || '' }));
367
+ else if (['setup', 'pairing', 'launching', 'downloading'].includes(state)) setStatus(c(state === 'setup' ? 'setupRunningTitle' : state, { browser: lastSetup?.browser?.name || '' }));
329
368
  else if (state === 'unsupported') setStatus(c('unsupported'));
330
369
  else setStatus(t('unpaired'));
331
370
  query('status-help').textContent = c(help, { browser: lastSetup?.browser?.name || '' });
332
371
  const actions = query('status-actions');
333
372
  const resume = actions.querySelector('[data-extension-action="resume"]'), retry = actions.querySelector('[data-extension-action="retry"]');
334
373
  resume.hidden = state !== 'disconnected'; retry.hidden = !error;
374
+ // Paired, and the browser stays away: the extension may have been loaded from the old folder inside the app.
375
+ query('moved').hidden = !(state === 'disconnected' && !error);
335
376
  actions.hidden = resume.hidden && retry.hidden;
336
377
  query('footer').hidden = !data?.paired;
337
378
  query('files').hidden = !data?.paired;
@@ -397,13 +438,14 @@ export function wireExtensionSettings(root, { tx, signal }) {
397
438
  if (busy) { if (action === 'mode') queuedMode = body; return; }
398
439
  busy = true;
399
440
  try {
400
- if (action === 'copy') { await navigator.clipboard.writeText(folder); }
441
+ if (action === 'copy') { if (folder) await navigator.clipboard.writeText(folder); }
401
442
  else if (action === 'setup-start' || action === 'setup-open-in') {
402
443
  launching = true; render();
403
444
  try { await api('setup/start', action === 'setup-open-in' ? { browser: body?.browser } : {}); } finally { launching = false; }
404
445
  }
405
446
  else if (action === 'setup-cancel') await api('setup/cancel', {});
406
447
  else if (action === 'setup-reopen') await api('setup/reopen', {});
448
+ else if (action === 'reload-confirm') await api('reload/confirm', { reloaded: true });
407
449
  else if (!['refresh', 'retry'].includes(action)) {
408
450
  const data = await api(action, body || (action === 'pair' ? { port: Number(query('port').value) } : {}));
409
451
  if (action !== 'mode') showCode(action === 'pair' ? data.code : null);
@@ -0,0 +1,83 @@
1
+ // What a Stop that could not end a command in the background says, in the OpenCode side panel and the Assistant
2
+ // panel alike. DOM-free, no imports (node --test loads it). SHELL_STOP_COPY is the English and must equal
3
+ // `shellStop.*` in i18n/*.json (tests/opencode-stop-anyway.test.mjs checks it).
4
+ //
5
+ // The server's answer to a failed Stop (server.js message:abort, lib/assistant-runtime.js stopTurn) carries
6
+ // `shells: [{ id, command, reason }]`, `failures` (how many Stops of this turn failed) and `canForce` (from the second
7
+ // one on): "Stop anyway" is offered then. A Stop anyway that ended the turn while a command may still run answers
8
+ // `abandoned: [{ id, command }]`.
9
+
10
+ export const SHELL_STOP_COPY = Object.freeze({
11
+ failed: 'Stop could not end {commands} ({reason}). It is still running, so this turn goes on. Press Stop again.',
12
+ failedAgain: 'Stop could not end {commands} again ({reason}). It is still running. Press Stop again, or Stop anyway to end this turn here.',
13
+ anyway: 'Stop anyway',
14
+ abandoned: 'Turn stopped. {commands} may still be running on this machine: SynaBun keeps trying to end it in the background.',
15
+ unknownReason: 'no reason given',
16
+ });
17
+
18
+ const fill = (text, vars = {}) => String(text).replace(/\{(\w+)\}/g, (_, key) => (vars[key] != null ? String(vars[key]) : `{${key}}`));
19
+
20
+ /** The string `key` in the active locale through `translate(key, vars)` (a missing key comes back as itself), else the English. */
21
+ export function shellStopText(key, vars = {}, translate = null) {
22
+ const full = `shellStop.${key}`;
23
+ let said = null;
24
+ try { said = typeof translate === 'function' ? translate(full, vars) : null; } catch { said = null; }
25
+ if (typeof said === 'string' && said && said !== full) return said;
26
+ return fill(SHELL_STOP_COPY[key] ?? '', vars);
27
+ }
28
+
29
+ const named = (shells) => (Array.isArray(shells) ? shells : [])
30
+ .map((shell) => String(shell?.command || shell?.id || '').trim())
31
+ .filter(Boolean)
32
+ .map((name) => `“${name.length > 80 ? `${name.slice(0, 79)}…` : name}”`)
33
+ .join(', ');
34
+
35
+ /**
36
+ * A failed Stop's answer → `{ message, canForce }`, or null when the answer is no such failure. An answer of a server
37
+ * from before this (no `shells`) keeps its own sentence.
38
+ */
39
+ export function describeStopFailure(result, translate = null) {
40
+ if (!result || (result.code !== 'SHELL_STOP_FAILED' && result.code !== 'STOP_FAILED')) return null;
41
+ const shells = Array.isArray(result.shells) ? result.shells : [];
42
+ const canForce = result.canForce === true;
43
+ if (!shells.length) {
44
+ const fallback = String(result.error || result.message || '').trim();
45
+ return { message: fallback || shellStopText('failed', { commands: '—', reason: shellStopText('unknownReason', {}, translate) }, translate), canForce };
46
+ }
47
+ const reasons = [...new Set(shells.map((shell) => String(shell?.reason || '').trim()).filter(Boolean))].join('; ');
48
+ const vars = { commands: named(shells), reason: reasons || shellStopText('unknownReason', {}, translate) };
49
+ return { message: shellStopText(canForce ? 'failedAgain' : 'failed', vars, translate), canForce };
50
+ }
51
+
52
+ // Words in front of the program that are not it: a variable set for the command, and the runners that start another.
53
+ const ASSIGNMENT = /^[A-Za-z_][A-Za-z0-9_]*=/;
54
+ const RUNNERS = new Set(['sudo', 'env', 'nohup', 'time', 'exec', 'command', 'nice', 'caffeinate', 'stdbuf', 'timeout']);
55
+ // A shell's own words (a loop, a test): no program is named by them, so the command is "a command".
56
+ const SHELL_WORDS = new Set(['for', 'while', 'until', 'if', 'case', 'select', 'function', 'do', 'then']);
57
+
58
+ /**
59
+ * The program a command line starts, by its name only (`npm`, `curl`): what a place outside the machine (a phone, a
60
+ * run's result, a memory) may be told. Nothing after it (arguments, a URL, a header, a token) and nothing before it
61
+ * (`TOKEN=… cmd`, `sudo`) is kept, nor a folder. A name that is not plainly a program's is `''`.
62
+ */
63
+ export function commandProgram(command) {
64
+ const words = String(command || '').trim().split(/\s+/).filter(Boolean);
65
+ let index = 0;
66
+ while (index < words.length && (ASSIGNMENT.test(words[index]) || RUNNERS.has(words[index]) || /^-/.test(words[index]) || (index > 0 && /^\d+[smhd]?$/.test(words[index])))) index += 1;
67
+ const word = (words[index] || '').replace(/^["'(]+|["');&|]+$/g, '');
68
+ const name = word.split(/[\\/]/).pop() || '';
69
+ if (SHELL_WORDS.has(name)) return '';
70
+ return /^[A-Za-z0-9][A-Za-z0-9._+-]{0,39}$/.test(name) ? name : '';
71
+ }
72
+
73
+ /** The program names of `shells` (`{ command }`), each once, in order; a command whose name is unclear is "a command". */
74
+ export function abandonedPrograms(shells) {
75
+ const names = (Array.isArray(shells) ? shells : []).map((shell) => commandProgram(shell?.command) || 'command');
76
+ return [...new Set(names)];
77
+ }
78
+
79
+ /** A Stop anyway's answer → the sentence about the commands that may still run, or null when none was left. */
80
+ export function describeAbandoned(abandoned, translate = null) {
81
+ const commands = named(abandoned);
82
+ return commands ? shellStopText('abandoned', { commands }, translate) : null;
83
+ }