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.
Files changed (220) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/README.md +1 -1
  3. package/docs/browser-extension-bridge.md +83 -34
  4. package/lib/release-npm-ci.mjs +23 -1
  5. package/mcp-server/dist/http.d.ts.map +1 -1
  6. package/mcp-server/dist/http.js +8 -1
  7. package/mcp-server/dist/http.js.map +1 -1
  8. package/mcp-server/dist/services/identity.d.ts +2 -0
  9. package/mcp-server/dist/services/identity.d.ts.map +1 -1
  10. package/mcp-server/dist/services/identity.js +4 -0
  11. package/mcp-server/dist/services/identity.js.map +1 -1
  12. package/mcp-server/dist/services/memory-client.d.ts +5 -0
  13. package/mcp-server/dist/services/memory-client.d.ts.map +1 -1
  14. package/mcp-server/dist/services/memory-client.js +21 -2
  15. package/mcp-server/dist/services/memory-client.js.map +1 -1
  16. package/mcp-server/dist/services/memory-writer.d.ts +3 -0
  17. package/mcp-server/dist/services/memory-writer.d.ts.map +1 -1
  18. package/mcp-server/dist/services/memory-writer.js +7 -1
  19. package/mcp-server/dist/services/memory-writer.js.map +1 -1
  20. package/mcp-server/dist/services/neural-interface.d.ts +11 -1
  21. package/mcp-server/dist/services/neural-interface.d.ts.map +1 -1
  22. package/mcp-server/dist/services/neural-interface.js +68 -18
  23. package/mcp-server/dist/services/neural-interface.js.map +1 -1
  24. package/mcp-server/dist/services/typesafe-config.d.ts +38 -2
  25. package/mcp-server/dist/services/typesafe-config.d.ts.map +1 -1
  26. package/mcp-server/dist/services/typesafe-config.js +260 -8
  27. package/mcp-server/dist/services/typesafe-config.js.map +1 -1
  28. package/mcp-server/dist/tools/agent-definition.d.ts +2 -2
  29. package/mcp-server/dist/tools/agents.d.ts +3 -1
  30. package/mcp-server/dist/tools/agents.d.ts.map +1 -1
  31. package/mcp-server/dist/tools/agents.js +11 -6
  32. package/mcp-server/dist/tools/agents.js.map +1 -1
  33. package/mcp-server/dist/tools/browser-extension-setup.d.ts.map +1 -1
  34. package/mcp-server/dist/tools/browser-extension-setup.js +8 -2
  35. package/mcp-server/dist/tools/browser-extension-setup.js.map +1 -1
  36. package/mcp-server/dist/tools/browser-observe.d.ts +11 -0
  37. package/mcp-server/dist/tools/browser-observe.d.ts.map +1 -1
  38. package/mcp-server/dist/tools/browser-observe.js +113 -27
  39. package/mcp-server/dist/tools/browser-observe.js.map +1 -1
  40. package/mcp-server/dist/tools/browser-readers.d.ts +6 -0
  41. package/mcp-server/dist/tools/browser-readers.d.ts.map +1 -0
  42. package/mcp-server/dist/tools/browser-readers.js +17 -0
  43. package/mcp-server/dist/tools/browser-readers.js.map +1 -0
  44. package/mcp-server/dist/tools/remember.d.ts.map +1 -1
  45. package/mcp-server/dist/tools/remember.js +6 -2
  46. package/mcp-server/dist/tools/remember.js.map +1 -1
  47. package/mcp-server/dist/tools/youtube/analytics.d.ts +4 -0
  48. package/mcp-server/dist/tools/youtube/analytics.d.ts.map +1 -1
  49. package/mcp-server/dist/tools/youtube/analytics.js +25 -20
  50. package/mcp-server/dist/tools/youtube/analytics.js.map +1 -1
  51. package/mcp-server/dist/tools/youtube/helpers.d.ts +5 -1
  52. package/mcp-server/dist/tools/youtube/helpers.d.ts.map +1 -1
  53. package/mcp-server/dist/tools/youtube/helpers.js +7 -3
  54. package/mcp-server/dist/tools/youtube/helpers.js.map +1 -1
  55. package/mcp-server/dist/tools/youtube/navigate.d.ts +2 -0
  56. package/mcp-server/dist/tools/youtube/navigate.d.ts.map +1 -1
  57. package/mcp-server/dist/tools/youtube/navigate.js +5 -3
  58. package/mcp-server/dist/tools/youtube/navigate.js.map +1 -1
  59. package/mcp-server/dist/tools/youtube/playlist.js +2 -2
  60. package/mcp-server/dist/tools/youtube/playlist.js.map +1 -1
  61. package/mcp-server/dist/tools/youtube/readers.d.ts +4 -0
  62. package/mcp-server/dist/tools/youtube/readers.d.ts.map +1 -0
  63. package/mcp-server/dist/tools/youtube/readers.js +15 -0
  64. package/mcp-server/dist/tools/youtube/readers.js.map +1 -0
  65. package/mcp-server/package-lock.json +5 -5
  66. package/mcp-server/package.json +1 -1
  67. package/mcp-server/src/http.ts +8 -1
  68. package/mcp-server/src/services/identity.ts +5 -0
  69. package/mcp-server/src/services/memory-client.ts +32 -12
  70. package/mcp-server/src/services/memory-writer.ts +5 -2
  71. package/mcp-server/src/services/neural-interface.ts +66 -19
  72. package/mcp-server/src/services/typesafe-config.ts +268 -7
  73. package/mcp-server/src/tools/agents.ts +12 -6
  74. package/mcp-server/src/tools/browser-extension-setup.ts +8 -2
  75. package/mcp-server/src/tools/browser-observe.ts +117 -28
  76. package/mcp-server/src/tools/browser-readers.ts +19 -0
  77. package/mcp-server/src/tools/remember.ts +6 -1
  78. package/mcp-server/src/tools/youtube/analytics.ts +26 -28
  79. package/mcp-server/src/tools/youtube/helpers.ts +8 -2
  80. package/mcp-server/src/tools/youtube/navigate.ts +6 -7
  81. package/mcp-server/src/tools/youtube/playlist.ts +2 -2
  82. package/mcp-server/src/tools/youtube/readers.ts +15 -0
  83. package/neural-interface/i18n/en.json +189 -1
  84. package/neural-interface/i18n/pt-BR.json +196 -8
  85. package/neural-interface/lib/assistant-api.js +123 -0
  86. package/neural-interface/lib/assistant-brains/claude.js +10 -0
  87. package/neural-interface/lib/assistant-brains/opencode.js +121 -7
  88. package/neural-interface/lib/assistant-dispatch.js +302 -44
  89. package/neural-interface/lib/assistant-envelope.js +40 -0
  90. package/neural-interface/lib/assistant-memory.js +3 -1
  91. package/neural-interface/lib/assistant-persona.js +6 -0
  92. package/neural-interface/lib/assistant-router.js +18 -8
  93. package/neural-interface/lib/assistant-runtime.js +182 -11
  94. package/neural-interface/lib/assistant-task-prompt.js +15 -2
  95. package/neural-interface/lib/browser-connection-state.js +20 -0
  96. package/neural-interface/lib/browser-extension-adapter.js +221 -17
  97. package/neural-interface/lib/browser-extension-archive.js +149 -0
  98. package/neural-interface/lib/browser-extension-bridge.js +46 -10
  99. package/neural-interface/lib/browser-extension-folder.js +635 -76
  100. package/neural-interface/lib/browser-extension-package.js +201 -0
  101. package/neural-interface/lib/browser-extension-pin.js +84 -0
  102. package/neural-interface/lib/browser-extension-pin.json +35 -0
  103. package/{browser-extension/protocol.js → neural-interface/lib/browser-extension-protocol.js} +111 -13
  104. package/neural-interface/lib/browser-extension-setup.js +108 -19
  105. package/neural-interface/lib/browser-extension-update.js +104 -0
  106. package/neural-interface/lib/browser-extraction.js +38 -14
  107. package/neural-interface/lib/claude-bg-tasks.js +183 -0
  108. package/neural-interface/lib/claude-history.js +12 -1
  109. package/neural-interface/lib/cli-install.js +23 -3
  110. package/neural-interface/lib/cli-update-planner.js +67 -4
  111. package/neural-interface/lib/confined-fs.js +25 -0
  112. package/neural-interface/lib/coordination/operations.js +2 -0
  113. package/neural-interface/lib/db.js +39 -16
  114. package/neural-interface/lib/editor-completion-opencode.js +2 -2
  115. package/neural-interface/lib/git-bash/manager.js +28 -3
  116. package/neural-interface/lib/git-status-runner.js +31 -3
  117. package/neural-interface/lib/loop-inventory.js +162 -0
  118. package/neural-interface/lib/loop-stall.js +74 -4
  119. package/neural-interface/lib/memory-session-capture.js +157 -66
  120. package/neural-interface/lib/native-loop-providers.js +82 -13
  121. package/neural-interface/lib/native-loop-runtime.js +23 -2
  122. package/neural-interface/lib/opencode-protocol.js +4 -2
  123. package/neural-interface/lib/opencode-shell-read.js +107 -0
  124. package/neural-interface/lib/opencode-stop-failures.js +40 -0
  125. package/neural-interface/lib/opencode-turn-release.js +173 -0
  126. package/neural-interface/lib/opencode-v2-client.js +4 -1
  127. package/neural-interface/lib/opencode-v2-ws-requests.js +34 -0
  128. package/neural-interface/lib/opencode2-client.js +341 -6
  129. package/neural-interface/lib/opencode2-translate.js +161 -4
  130. package/neural-interface/lib/peer-identity.js +62 -16
  131. package/neural-interface/lib/session-cache-builder.js +66 -18
  132. package/neural-interface/lib/session-capture-gate.js +42 -0
  133. package/neural-interface/lib/session-indexer.js +28 -20
  134. package/neural-interface/lib/teams/scheduler.js +3 -2
  135. package/neural-interface/lib/terminal-token-redaction.js +83 -0
  136. package/neural-interface/lib/ui-blob-api.js +14 -5
  137. package/neural-interface/lib/ui-blob-store.js +302 -39
  138. package/neural-interface/lib/whatsapp/bridge.js +52 -6
  139. package/neural-interface/package-lock.json +5 -5
  140. package/neural-interface/package.json +1 -1
  141. package/neural-interface/public/extension-setup.html +6 -2
  142. package/neural-interface/public/shared/agy/agy-panel.js +38 -10
  143. package/neural-interface/public/shared/assistant/asst-agents-dock.js +4 -0
  144. package/neural-interface/public/shared/assistant/asst-api.js +67 -0
  145. package/neural-interface/public/shared/assistant/asst-composer.js +85 -12
  146. package/neural-interface/public/shared/assistant/asst-panel.js +354 -11
  147. package/neural-interface/public/shared/assistant/asst-rack-styles.js +23 -0
  148. package/neural-interface/public/shared/assistant/asst-render.js +343 -10
  149. package/neural-interface/public/shared/assistant/asst-scenes.js +12 -0
  150. package/neural-interface/public/shared/assistant/asst-shell-logic.js +200 -0
  151. package/neural-interface/public/shared/assistant/asst-shell.js +111 -0
  152. package/neural-interface/public/shared/assistant/asst-sidepanel.js +18 -1
  153. package/neural-interface/public/shared/assistant/asst-state.js +241 -2
  154. package/neural-interface/public/shared/assistant/asst-steer.js +294 -0
  155. package/neural-interface/public/shared/assistant/asst-styles.js +21 -0
  156. package/neural-interface/public/shared/bg-tasks/bg-tasks-claude.js +147 -0
  157. package/neural-interface/public/shared/bg-tasks/bg-tasks-model.js +527 -0
  158. package/neural-interface/public/shared/bg-tasks/bg-tasks-panel.js +161 -0
  159. package/neural-interface/public/shared/bg-tasks/bg-tasks-view.js +508 -0
  160. package/neural-interface/public/shared/browser-extension-updates.js +88 -0
  161. package/neural-interface/public/shared/cdx/cdx-tabs.js +25 -0
  162. package/neural-interface/public/shared/cp/cp-bg-tasks.js +130 -0
  163. package/neural-interface/public/shared/extension-setup/es-page.js +25 -12
  164. package/neural-interface/public/shared/extension-setup/es-view.js +25 -10
  165. package/neural-interface/public/shared/extension-update-view.js +34 -0
  166. package/neural-interface/public/shared/mtc/mtc-panel.js +17 -2
  167. package/neural-interface/public/shared/ocp-v2/ocp-v2-events.js +5 -0
  168. package/neural-interface/public/shared/ocp-v2/ocp-v2-manager.js +1 -0
  169. package/neural-interface/public/shared/ocp-v2/ocp-v2-panel.js +34 -2
  170. package/neural-interface/public/shared/ocp-v2/ocp-v2-rehydrate.js +7 -1
  171. package/neural-interface/public/shared/ocp-v2/ocp-v2-render.js +26 -1
  172. package/neural-interface/public/shared/ocp-v2/ocp-v2-send.js +39 -6
  173. package/neural-interface/public/shared/ocp-v2/ocp-v2-session-actions.js +20 -1
  174. package/neural-interface/public/shared/ocp-v2/ocp-v2-shell-block.js +165 -0
  175. package/neural-interface/public/shared/ocp-v2/ocp-v2-shell-logic.js +350 -0
  176. package/neural-interface/public/shared/ocp-v2/ocp-v2-shell.js +108 -0
  177. package/neural-interface/public/shared/ocp-v2/ocp-v2-state.js +49 -3
  178. package/neural-interface/public/shared/ocp-v2/ocp-v2-styles.js +40 -0
  179. package/neural-interface/public/shared/ocp-v2/ocp-v2-tools-logic.js +20 -5
  180. package/neural-interface/public/shared/ocp-v2/ocp-v2-tools.js +7 -1
  181. package/neural-interface/public/shared/ocp-v2/ocp-v2-ws.js +7 -2
  182. package/neural-interface/public/shared/settings/settings-browser-extension.js +61 -13
  183. package/neural-interface/public/shared/settings/settings-extension-update.js +114 -0
  184. package/neural-interface/public/shared/shell-stop-view.js +83 -0
  185. package/neural-interface/public/shared/styles.css +4 -0
  186. package/neural-interface/public/shared/tour/tour-actor.js +14 -3
  187. package/neural-interface/public/shared/tray-auto-close.js +36 -6
  188. package/neural-interface/public/shared/ui-claude-panel.js +130 -1
  189. package/neural-interface/public/shared/ui-native-loop-router.js +45 -3
  190. package/neural-interface/public/shared/ui-notifications.js +23 -4
  191. package/neural-interface/public/shared/ui-scroll-follow.js +4 -0
  192. package/neural-interface/public/shared/ui-settings-entry.js +6 -0
  193. package/neural-interface/public/shared/ui-tray-columns.js +9 -2
  194. package/neural-interface/public/shared/worker-end.js +18 -0
  195. package/neural-interface/scripts/patch-node-pty.mjs +151 -0
  196. package/neural-interface/scripts/rebuild-pty.js +10 -0
  197. package/neural-interface/server.js +725 -308
  198. package/npm-shrinkwrap.json +5 -5
  199. package/package.json +1 -2
  200. package/browser-extension/content.js +0 -231
  201. package/browser-extension/engine.js +0 -658
  202. package/browser-extension/icons/icon-128.png +0 -0
  203. package/browser-extension/icons/icon-16.png +0 -0
  204. package/browser-extension/icons/icon-32.png +0 -0
  205. package/browser-extension/icons/icon-48.png +0 -0
  206. package/browser-extension/icons/status-off-16.png +0 -0
  207. package/browser-extension/icons/status-off-32.png +0 -0
  208. package/browser-extension/icons/status-off-48.png +0 -0
  209. package/browser-extension/icons/status-on-16.png +0 -0
  210. package/browser-extension/icons/status-on-32.png +0 -0
  211. package/browser-extension/icons/status-on-48.png +0 -0
  212. package/browser-extension/manifest.json +0 -58
  213. package/browser-extension/popup-strings.js +0 -250
  214. package/browser-extension/popup-view.js +0 -151
  215. package/browser-extension/popup.css +0 -166
  216. package/browser-extension/popup.html +0 -108
  217. package/browser-extension/popup.js +0 -359
  218. package/browser-extension/service-worker.js +0 -283
  219. package/browser-extension/setup-content.js +0 -36
  220. package/browser-extension/tokens.css +0 -326
@@ -0,0 +1,350 @@
1
+ // ─────────────────────────────────────────────────────────────────────────────
2
+ // OpenCode V2 — a shell command's output, live (no DOM, no socket)
3
+ //
4
+ // OpenCode 2 does not send what a command prints with its tool call: it keeps
5
+ // the combined stdout and stderr, in the order written, and answers pages of it
6
+ // by byte position while the command runs and after (`shell:output`). This
7
+ // module reads those pages and keeps what the transcript shows:
8
+ // createTerminalBuffer() the text as a terminal would leave it, windowed
9
+ // createShellFollower() reads one command to its end, then stops
10
+ // followShells() one follower per command of a store's session
11
+ // shellCardState() what a command means for its tool card
12
+ // The store holds the result (shellOutput), ocp-v2-shell.js draws it.
13
+ // ─────────────────────────────────────────────────────────────────────────────
14
+
15
+ /** What the transcript keeps of one command's output until the reader asks for all of it. */
16
+ export const SHELL_WINDOW_CHARS = 256 * 1024;
17
+ /** The most "Load full output" keeps in the page; a longer output says so and names where it stops. */
18
+ export const SHELL_FULL_MAX_CHARS = 8 * 1024 * 1024;
19
+ /** How often a running command is asked for more: at once while it prints, slower while it is quiet. */
20
+ export const SHELL_POLL_MIN_MS = 400;
21
+ export const SHELL_POLL_MAX_MS = 2500;
22
+
23
+ // CSI / OSC sequences and the other escapes a test runner colours its lines with.
24
+ // eslint-disable-next-line no-control-regex
25
+ const ANSI = /\x1b\[[0-9;?]*[ -/]*[@-~]|\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)|\x1b[@-Z\\-_]/g;
26
+ // A sequence the page cut in two waits for its other half.
27
+ // eslint-disable-next-line no-control-regex
28
+ const ANSI_TAIL = /\x1b(?:\[[0-9;?]*[ -/]*|\][^\x07\x1b]*)?$/;
29
+
30
+ /**
31
+ * The text of a command as a terminal would leave it: escape sequences gone, a
32
+ * line rewritten with a carriage return (a progress bar) kept as its last
33
+ * form, CRLF as one line end. At most `maxChars` are kept: the oldest whole
34
+ * lines go first, and `dropped` counts the characters that went.
35
+ */
36
+ export function createTerminalBuffer({ maxChars = SHELL_WINDOW_CHARS } = {}) {
37
+ let text = '';
38
+ let dropped = 0;
39
+ let pending = ''; // an escape sequence, or a lone "\r", still waiting for what follows
40
+ let limit = Math.max(1024, Number(maxChars) || SHELL_WINDOW_CHARS);
41
+
42
+ function trim() {
43
+ if (text.length <= limit) return;
44
+ let cut = text.length - limit;
45
+ const lineEnd = text.indexOf('\n', cut);
46
+ // The line that crosses the limit goes whole, unless it is the last one.
47
+ if (lineEnd !== -1 && lineEnd < text.length - 1) cut = lineEnd + 1;
48
+ dropped += cut;
49
+ text = text.slice(cut);
50
+ }
51
+
52
+ function append(chunk) {
53
+ let incoming = pending + String(chunk ?? '');
54
+ pending = '';
55
+ const tail = ANSI_TAIL.exec(incoming);
56
+ if (tail) { pending = tail[0]; incoming = incoming.slice(0, tail.index); }
57
+ if (incoming.endsWith('\r')) { pending = `\r${pending}`; incoming = incoming.slice(0, -1); }
58
+ incoming = incoming.replace(ANSI, '').replace(/\r\n/g, '\n');
59
+ if (!incoming) return;
60
+ if (incoming.includes('\r')) {
61
+ // A carriage return goes back to the start of the line: what follows replaces it.
62
+ for (const piece of incoming.split(/(\r)/)) {
63
+ if (piece === '\r') text = text.slice(0, text.lastIndexOf('\n') + 1);
64
+ else text += piece;
65
+ }
66
+ } else {
67
+ text += incoming;
68
+ }
69
+ trim();
70
+ }
71
+
72
+ return {
73
+ append,
74
+ text: () => text,
75
+ /** Characters no longer kept (the start of a long output). */
76
+ dropped: () => dropped,
77
+ setLimit(maxChars) { limit = Math.max(1024, Number(maxChars) || limit); trim(); },
78
+ reset() { text = ''; dropped = 0; pending = ''; },
79
+ };
80
+ }
81
+
82
+ const replyFailed = (res) => !res || res.ok === false || (typeof res.status === 'number' && res.status >= 400);
83
+
84
+ /**
85
+ * Reads one command's output to its end.
86
+ * api.shellOutput({ sessionId, shellId, cwd, cursor, tail, limit }) → { data: { output, cursor, size, from } }
87
+ * isRunning() the command still runs (the store's word); once it does not,
88
+ * a read that brings nothing new is the last one
89
+ * isCurrent() false once the panel left the session: nothing more is read
90
+ * onUpdate(view) { text, from, size, done, gone, error, full, capped } after every page
91
+ * The first read starts `window` characters before the end (a panel that opens
92
+ * on a long output shows its end at once); `loadAll()` reads it again from its
93
+ * first byte. Nothing is polled once the command ended and was read to its end.
94
+ */
95
+ export function createShellFollower({
96
+ api, sessionId, shellId, cwd, isRunning = () => false, isCurrent = () => true, onUpdate = () => {},
97
+ windowChars = SHELL_WINDOW_CHARS, setTimer = setTimeout, clearTimer = clearTimeout,
98
+ // How often a running command is asked again (a caller may ask less often: the Background tasks view, 1 s).
99
+ pollMinMs = SHELL_POLL_MIN_MS, pollMaxMs = SHELL_POLL_MAX_MS,
100
+ } = {}) {
101
+ const POLL_MIN = Math.max(SHELL_POLL_MIN_MS, Number(pollMinMs) || SHELL_POLL_MIN_MS);
102
+ const POLL_MAX = Math.max(POLL_MIN, Number(pollMaxMs) || SHELL_POLL_MAX_MS);
103
+ const buffer = createTerminalBuffer({ maxChars: windowChars });
104
+ let cursor = null; // null: nothing read yet (the first read asks for the tail)
105
+ let from = 0; // the byte the kept text starts at, as far as the server said
106
+ let size = 0;
107
+ let timer = null;
108
+ let reading = false;
109
+ let stopped = false;
110
+ let done = false;
111
+ let gone = false;
112
+ let error = '';
113
+ let full = false;
114
+ let capped = false;
115
+ let delay = POLL_MIN;
116
+ let failures = 0;
117
+ let generation = 0; // a read begun before loadAll() belongs to the reading it replaced
118
+
119
+ const view = () => ({
120
+ text: buffer.text(), from: from + buffer.dropped(), size, done, gone, error, full, capped,
121
+ // Something of the output is not in `text` (its start): the reader can ask for it.
122
+ partial: from + buffer.dropped() > 0,
123
+ });
124
+ const publish = () => { try { onUpdate(view()); } catch (err) { console.warn('[ocp-v2-shell] update failed', err); } };
125
+
126
+ function schedule(ms) {
127
+ if (stopped || done || gone) return;
128
+ if (timer) clearTimer(timer);
129
+ timer = setTimer(() => { timer = null; read(); }, ms);
130
+ }
131
+
132
+ async function read() {
133
+ if (stopped || done || gone || reading) return;
134
+ if (!isCurrent()) { stop(); return; }
135
+ reading = true;
136
+ const mine = generation;
137
+ const wasRunning = isRunning();
138
+ let res;
139
+ try {
140
+ res = await api.shellOutput(cursor == null
141
+ ? { sessionId, shellId, cwd, tail: full ? undefined : windowChars, cursor: full ? 0 : undefined }
142
+ : { sessionId, shellId, cwd, cursor });
143
+ } catch (err) { res = { ok: false, error: err?.message || String(err) }; }
144
+ reading = false;
145
+ if (stopped) return;
146
+ if (mine !== generation) { schedule(0); return; }
147
+ if (!isCurrent()) { stop(); return; }
148
+ if (replyFailed(res) || !res.data || typeof res.data !== 'object') {
149
+ // OpenCode keeps a finished command's output for a while only.
150
+ if (res?.status === 404) { gone = true; publish(); return; }
151
+ failures += 1;
152
+ error = (typeof res?.error === 'string' && res.error) || 'The output could not be read.';
153
+ if (failures >= 5 && !isRunning()) { done = true; publish(); return; }
154
+ publish();
155
+ schedule(Math.min(POLL_MAX * 2, POLL_MIN * 2 ** failures));
156
+ return;
157
+ }
158
+ failures = 0;
159
+ error = '';
160
+ const page = res.data;
161
+ const text = typeof page.output === 'string' ? page.output : '';
162
+ if (cursor == null) from = Math.max(0, Number(page.from) || 0);
163
+ const next = Math.max(0, Number(page.cursor) || 0);
164
+ size = Math.max(next, Number(page.size) || 0);
165
+ const moved = cursor == null || next > cursor;
166
+ if (text) buffer.append(text);
167
+ cursor = next;
168
+ if (full && buffer.dropped() > 0) capped = true;
169
+ const behind = cursor < size;
170
+ // Read to its end after the command stopped (as it was before this read): nothing more will come.
171
+ if (!wasRunning && !isRunning() && !behind && !text) done = true;
172
+ else if (!wasRunning && !isRunning() && !behind) { publish(); schedule(0); return; }
173
+ publish();
174
+ if (done) return;
175
+ if (behind) { delay = POLL_MIN; schedule(0); return; }
176
+ delay = moved && text ? POLL_MIN : Math.min(POLL_MAX, Math.round(delay * 1.5));
177
+ schedule(isRunning() ? delay : 0);
178
+ }
179
+
180
+ function stop() {
181
+ stopped = true;
182
+ if (timer) { clearTimer(timer); timer = null; }
183
+ }
184
+
185
+ return {
186
+ start() { if (cursor == null && !reading) read(); },
187
+ stop,
188
+ /** The store says the command changed (it ended): read now instead of at the next tick. */
189
+ poke() { if (!done && !gone && !stopped) schedule(0); },
190
+ /** Read the whole output again, from its first byte, keeping up to SHELL_FULL_MAX_CHARS. */
191
+ loadAll() {
192
+ if (stopped) return;
193
+ generation += 1;
194
+ full = true;
195
+ capped = false;
196
+ done = false;
197
+ gone = false;
198
+ buffer.reset();
199
+ buffer.setLimit(SHELL_FULL_MAX_CHARS);
200
+ cursor = null;
201
+ from = 0;
202
+ schedule(0);
203
+ },
204
+ view,
205
+ isDone: () => done || gone,
206
+ isStopped: () => stopped,
207
+ };
208
+ }
209
+
210
+ /**
211
+ * Keeps one follower per command of the store's session, for as long as the
212
+ * store is on that session: started when a command appears (an event, or the
213
+ * server's list after a reload), stopped when the store moves to another
214
+ * session. `supported()`: the server answers `shell:output` (an older one does
215
+ * not, and the cards then show what the tool call itself returned).
216
+ * Finished commands no block shows keep their text up to `kept` (the oldest
217
+ * goes first, review S5: a long session kept up to 8 MB of text per command it
218
+ * ever ran); one that comes on screen again is read afresh (watch).
219
+ * Returns { loadAll(shellId), watch(shellId) → release, has(shellId), stop() }.
220
+ */
221
+ export const SHELL_OUTPUT_KEPT_FINISHED = 12;
222
+
223
+ export function followShells(store, api, { supported = () => true, setTimer, clearTimer, kept = SHELL_OUTPUT_KEPT_FINISHED } = {}) {
224
+ const followers = new Map(); // shellId → follower
225
+ const usedAt = new Map(); // shellId → when its output was last read or shown
226
+ const watched = new Map(); // shellId → how many blocks show it
227
+ const evicted = new Set(); // finished commands whose text was let go: read again only when shown
228
+ let clock = 0;
229
+ let stopped = false;
230
+ let binding = typeof store.getBinding === 'function' ? store.getBinding() : 0;
231
+ const bindingNow = () => (typeof store.getBinding === 'function' ? store.getBinding() : 0);
232
+
233
+ function clear() {
234
+ for (const follower of followers.values()) follower.stop();
235
+ followers.clear();
236
+ usedAt.clear();
237
+ evicted.clear();
238
+ }
239
+
240
+ /** Let go of the text of finished commands nobody looks at, beyond `kept`. */
241
+ function trim() {
242
+ const idle = [...followers].filter(([id, follower]) => follower.isDone() && !watched.get(id)
243
+ && store.getState().shells.get(id)?.status !== 'running');
244
+ if (idle.length <= kept) return;
245
+ idle.sort((a, b) => (usedAt.get(a[0]) || 0) - (usedAt.get(b[0]) || 0));
246
+ for (const [id, follower] of idle.slice(0, idle.length - kept)) {
247
+ follower.stop();
248
+ followers.delete(id);
249
+ usedAt.delete(id);
250
+ evicted.add(id);
251
+ store.setShellOutput(id, null);
252
+ }
253
+ }
254
+
255
+ function follow(shellId) {
256
+ const state = store.getState();
257
+ const mine = binding;
258
+ const follower = createShellFollower({
259
+ api, sessionId: state.sessionId, shellId, cwd: state.cwd || state.sessionInfo?.directory || undefined,
260
+ isRunning: () => store.getState().shells.get(shellId)?.status === 'running',
261
+ isCurrent: () => !stopped && bindingNow() === mine,
262
+ onUpdate: (view) => {
263
+ if (stopped || bindingNow() !== mine || followers.get(shellId) !== follower) return;
264
+ usedAt.set(shellId, ++clock);
265
+ store.setShellOutput(shellId, view);
266
+ if (view?.done || view?.gone) trim();
267
+ },
268
+ ...(setTimer ? { setTimer } : {}), ...(clearTimer ? { clearTimer } : {}),
269
+ });
270
+ followers.set(shellId, follower);
271
+ usedAt.set(shellId, ++clock);
272
+ follower.start();
273
+ return follower;
274
+ }
275
+
276
+ function sync() {
277
+ if (stopped) return;
278
+ const now = bindingNow();
279
+ if (now !== binding) { binding = now; clear(); }
280
+ const state = store.getState();
281
+ if (!state.sessionId || !supported() || typeof api?.shellOutput !== 'function') return;
282
+ for (const [shellId, shell] of state.shells) {
283
+ const follower = followers.get(shellId);
284
+ if (!follower) {
285
+ if (!evicted.has(shellId)) follow(shellId);
286
+ } else if (shell.status !== 'running') {
287
+ follower.poke();
288
+ }
289
+ }
290
+ }
291
+
292
+ const unsubscribe = store.subscribe((event) => {
293
+ if (event?.type === 'shell:update' || event?.type === 'session:set') sync();
294
+ });
295
+ sync();
296
+ return {
297
+ loadAll(shellId) { followers.get(shellId)?.loadAll(); },
298
+ /** A block shows `shellId`: its text is kept (and read again if it was let go) until the release. */
299
+ watch(shellId) {
300
+ if (stopped) return () => {};
301
+ watched.set(shellId, (watched.get(shellId) || 0) + 1);
302
+ usedAt.set(shellId, ++clock);
303
+ if (evicted.delete(shellId) && store.getState().shells.has(shellId) && supported()) follow(shellId);
304
+ let released = false;
305
+ return () => {
306
+ if (released) return;
307
+ released = true;
308
+ const left = (watched.get(shellId) || 1) - 1;
309
+ if (left > 0) watched.set(shellId, left); else watched.delete(shellId);
310
+ trim();
311
+ };
312
+ },
313
+ has: (shellId) => followers.has(shellId),
314
+ stop() { stopped = true; try { unsubscribe(); } catch { /* gone */ } clear(); watched.clear(); },
315
+ };
316
+ }
317
+
318
+ /**
319
+ * What a command means for the card of its tool call.
320
+ * status 'running' | 'completed' | 'error' | '' (the call's own status stands)
321
+ * note a few words for the card's head ("in the background", "exit 1", "stopped")
322
+ */
323
+ export function shellCardState(shell) {
324
+ if (!shell || typeof shell !== 'object') return { status: '', note: '', running: false };
325
+ if (shell.status === 'running') {
326
+ return { status: 'running', note: shell.background ? 'in the background' : '', running: true };
327
+ }
328
+ if (shell.status === 'killed') return { status: 'error', note: 'stopped', running: false };
329
+ if (shell.status === 'timeout') return { status: 'error', note: 'timed out', running: false };
330
+ const exit = typeof shell.exit === 'number' ? shell.exit : null;
331
+ if (exit != null && exit !== 0) return { status: shell.background ? 'error' : '', note: `exit ${exit}`, running: false };
332
+ return { status: shell.background ? 'completed' : '', note: '', running: false };
333
+ }
334
+
335
+ /** "1.2 MB", "340 KB", "512 B". */
336
+ export function formatBytes(bytes) {
337
+ const n = Math.max(0, Number(bytes) || 0);
338
+ if (n >= 1024 * 1024) return `${(n / (1024 * 1024)).toFixed(1)} MB`;
339
+ if (n >= 1024) return `${Math.round(n / 1024)} KB`;
340
+ return `${n} B`;
341
+ }
342
+
343
+ /** The line above a terminal block when it does not show everything: '' when it does. */
344
+ export function shellOutputNote(view) {
345
+ if (!view) return '';
346
+ if (view.gone) return 'OpenCode no longer keeps the output of this command.';
347
+ if (view.capped) return `Showing the last ${formatBytes(view.text.length)} of ${formatBytes(view.size)}: the whole output is too long to show here.`;
348
+ if (view.partial) return `Showing the last ${formatBytes(view.text.length)} of ${formatBytes(view.size)}.`;
349
+ return '';
350
+ }
@@ -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':