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,88 @@
1
+ import { extensionUpdateView } from './extension-update-view.js';
2
+
3
+ const listeners = new Set();
4
+ let current = null, revision = 0, reading = null;
5
+ export function acceptExtensionUpdate(update) {
6
+ revision++;
7
+ current = update;
8
+ for (const show of listeners) show(update);
9
+ }
10
+ export function watchExtensionUpdate(show) {
11
+ listeners.add(show); show(current);
12
+ return () => listeners.delete(show);
13
+ }
14
+ // Capture this before a read of either the full Settings card or the small notice endpoint.
15
+ // A slower response cannot overwrite a newer read or the response to an explicit action.
16
+ export function beginExtensionUpdateRead() {
17
+ const started = revision;
18
+ return update => { if (revision === started) acceptExtensionUpdate(update); };
19
+ }
20
+ // One owner-only read for all the notices. A slow read started before a click cannot undo its response.
21
+ export function refreshExtensionUpdate() {
22
+ if (reading) return reading;
23
+ const accept = beginExtensionUpdateRead();
24
+ reading = fetch('/api/browser/extension/update/status', { cache: 'no-store' }).then(async response => {
25
+ if (response.ok) {
26
+ const update = await response.json();
27
+ accept(update);
28
+ } else if ([401, 403, 404].includes(response.status)) accept(null);
29
+ }).catch(() => {}).finally(() => { reading = null; });
30
+ return reading;
31
+ }
32
+
33
+ export const extensionUpdateSettings = { tab: 'browser', expand: 'bcg-profiles', scrollTo: 'bc-extension-update-flow' };
34
+ export function openExtensionUpdate() {
35
+ return import('./ui-settings-entry.js').then(({ openSettingsModal }) => openSettingsModal(extensionUpdateSettings));
36
+ }
37
+
38
+ // Emit only a change in the short banner, so progress polls cannot replace a focused action.
39
+ export function watchExtensionUpdateMention(tx, show) {
40
+ let previous = '';
41
+ return watchExtensionUpdate(update => {
42
+ const view = extensionUpdateView(update, tx);
43
+ const text = view?.due ? view.title : '';
44
+ if (text === previous) return;
45
+ previous = text;
46
+ show(text, { label: tx('browserExtension.updateFlow.review'), onClick: openExtensionUpdate });
47
+ });
48
+ }
49
+
50
+ // Only closing the notification dismisses it. Settings and the Assistant still offer the update in this session.
51
+ export function extensionUpdateToast({ tx, showNotice, session, open = openExtensionUpdate }) {
52
+ const storageKey = 'synabun-extension-update-dismissed';
53
+ let dismissed, visible, clear;
54
+ try { dismissed = session?.getItem(storageKey); } catch {}
55
+ return update => {
56
+ const view = extensionUpdateView(update, tx);
57
+ const show = view?.due && view.key !== dismissed;
58
+ const signature = show ? JSON.stringify([view.key, view.title]) : null;
59
+ if (signature === visible) return;
60
+ clear?.(); clear = null; visible = signature;
61
+ if (show) clear = showNotice({
62
+ title: view.title, action: tx('browserExtension.updateFlow.review'), closeLabel: tx('browserExtension.updateFlow.dismiss'),
63
+ onAction: open, onClose() {
64
+ dismissed = view.key;
65
+ try { session?.setItem(storageKey, dismissed); } catch {}
66
+ clear?.(); clear = null; visible = null;
67
+ },
68
+ });
69
+ };
70
+ }
71
+ export function startExtensionUpdateNotices({ tx, showNotice }) {
72
+ let session;
73
+ try { session = window.sessionStorage; } catch {}
74
+ watchExtensionUpdate(extensionUpdateToast({ tx, showNotice, session }));
75
+ let timer;
76
+ async function poll() {
77
+ clearTimeout(timer);
78
+ if (!document.hidden) await refreshExtensionUpdate();
79
+ clearTimeout(timer);
80
+ timer = setTimeout(poll, current && !['idle', 'done'].includes(current.phase) ? 2000 : 30000);
81
+ }
82
+ document.addEventListener('visibilitychange', poll);
83
+ if (window.location.hash === '#browser-extension-update') {
84
+ history.replaceState(history.state, '', location.pathname + location.search);
85
+ void refreshExtensionUpdate().then(openExtensionUpdate);
86
+ }
87
+ return poll();
88
+ }
@@ -45,6 +45,7 @@ import { isFarRowStyleRecord, stripFarRowStyles, watchTranscriptRows } from '../
45
45
  import { requestGeneratedSessionTitle } from '../session-title.js';
46
46
  import { fileLinkText } from '../ui-file-links.js';
47
47
  import { WORKER_END_CLASS, buildWorkerEndCard, endWorkerRunOnClose, forgetWorkerEnd, leaveWorkerTab } from '../ui-worker-end.js';
48
+ import { composerHoldsDraft, markAutoCloseKeep } from '../tray-auto-close.js';
48
49
  import {
49
50
  CODEX_COMMANDS, CODEX_COMMAND_BY_NAME, parseCodexCommand, codexCommandHints,
50
51
  capabilityAvailability, latestCompletedCodexText, configValue,
@@ -2685,6 +2686,24 @@ function hasMeaningfulTrayState(tab) {
2685
2686
  );
2686
2687
  }
2687
2688
 
2689
+ /**
2690
+ * What the tray's auto-close must leave open (tray-auto-close.js), or '': a tab with prompts in its queue that
2691
+ * were never sent ('queue': a paused queue, or one held behind a request or a plan approval), else a tab holding
2692
+ * an unsent draft, its text (in the composer while the tab is the one on screen), images, paths and @ mentions.
2693
+ * The user's X closes it as before. markQueueKeep repaints the mark at every change of a queue.
2694
+ */
2695
+ function autoCloseKeepOf(tab) {
2696
+ if (!tab) return '';
2697
+ if (tab.queue?.length) return 'queue';
2698
+ const input = isActiveTab(tab) ? panelEl('#cxp-input') : null;
2699
+ return composerHoldsDraft(input ? input.value : tab.draft, tab.attachedImages, tab.pendingPaths, tab.pendingMentions) ? 'draft' : '';
2700
+ }
2701
+
2702
+ /** Says a tab's keep reason to its pill: wherever a queue changes, the tab on screen's or one in the background. */
2703
+ function markQueueKeep(tab) {
2704
+ if (tab?.pillEl) markAutoCloseKeep(tab.pillEl, autoCloseKeepOf(tab));
2705
+ }
2706
+
2688
2707
  function hasCustomSessionLabel(tab) {
2689
2708
  const label = normalizeSessionLabel(tab?.pendingSessionLabel || tab?.sessionLabel || '');
2690
2709
  if (!label) return false;
@@ -2769,6 +2788,7 @@ function createTrayPill(tab) {
2769
2788
  pill.className = 'term-minimized-pill cxp-session-pill';
2770
2789
  pill.dataset.tabId = tab.id;
2771
2790
  pill.getAutomationRunId = () => tab.automationRunId;
2791
+ pill.keepFromAutoClose = () => autoCloseKeepOf(tab);
2772
2792
  pill.innerHTML = `
2773
2793
  <span class="term-minimized-pill-icon">${OPENAI_ICON}</span>
2774
2794
  <span class="term-minimized-pill-label">${esc(tab.sessionLabel || 'New session')}</span>
@@ -2814,6 +2834,7 @@ export function renderPills() {
2814
2834
  const name = tab.sessionLabel || 'New session';
2815
2835
  if (label && label.textContent !== name) label.textContent = name;
2816
2836
  paintTrayPill(tab.pillEl, tab);
2837
+ markAutoCloseKeep(tab.pillEl, autoCloseKeepOf(tab));
2817
2838
  const shouldShow = hasMeaningfulTrayState(tab) && (!_getVisible() || tab !== active);
2818
2839
  tab.pillEl.style.display = shouldShow ? '' : 'none';
2819
2840
  }
@@ -7200,6 +7221,7 @@ function tabTurnRunning(tab) {
7200
7221
  export function syncQueueTray() {
7201
7222
  const tab = activeTab();
7202
7223
  if (!tab) return;
7224
+ markQueueKeep(tab);
7203
7225
  const queue = tab.queue || [];
7204
7226
  const count = queue.length;
7205
7227
  const tray = panelEl('#cxp-queue-tray');
@@ -7312,6 +7334,7 @@ export function advanceQueue(tab = activeTab()) {
7312
7334
  if (!sent) {
7313
7335
  // Not sent: it stays first in its tab's queue.
7314
7336
  tab.queue.unshift(next);
7337
+ markQueueKeep(tab);
7315
7338
  syncQueueTray();
7316
7339
  return false;
7317
7340
  }
@@ -7320,6 +7343,8 @@ export function advanceQueue(tab = activeTab()) {
7320
7343
  appendLocalUserMessage(next.text || '', queueImages);
7321
7344
  tab._pendingSendImages = queueImages;
7322
7345
  }
7346
+ // A background tab's pill too: syncQueueTray paints the tab on screen's only.
7347
+ markQueueKeep(tab);
7323
7348
  syncQueueTray();
7324
7349
  return true;
7325
7350
  }
@@ -0,0 +1,130 @@
1
+ // ── Background tasks of a Claude Code panel tab (glue over public/shared/bg-tasks/) ──
2
+ //
3
+ // The registry, the view and the badges are the shared module's; this file only says where a Claude tab's
4
+ // pieces are: its session's routes (GET …/background-tasks and its output pages), the bridge's own Stop
5
+ // (`stop_task` on the tab's socket → the SDK's stopTask) and the tab's transcript for the notice cards.
6
+
7
+ import { createBgTasksPanel } from '../bg-tasks/bg-tasks-panel.js';
8
+ import { claudeFactsFromEvent, claudeLiveFact } from '../bg-tasks/bg-tasks-claude.js';
9
+ import { exitCodeOf, noticeCardView } from '../bg-tasks/bg-tasks-model.js';
10
+ import { markStaleNoticeCards, renderBgNoticeCard } from '../bg-tasks/bg-tasks-view.js';
11
+
12
+ const STOP_WAIT_MS = 15_000;
13
+
14
+ async function getJson(url) {
15
+ const res = await fetch(url, { headers: { Accept: 'application/json' }, credentials: 'same-origin' });
16
+ let body = null;
17
+ try { body = await res.json(); } catch { body = null; }
18
+ return { res, body };
19
+ }
20
+
21
+ /**
22
+ * The tab's background tasks: `tab.bg`. `project()` is the project its transcript is read under (the panel's
23
+ * _historyProject), `onChange` repaints its badges.
24
+ */
25
+ export function attachClaudeBgTasks(tab, { storage = null, t = null, project = () => '', onChange = () => {}, onShownChange = () => {} } = {}) {
26
+ const query = () => {
27
+ const p = new URLSearchParams();
28
+ const proj = project() || '';
29
+ if (proj) p.set('project', proj);
30
+ if (tab.accountId) p.set('account', tab.accountId);
31
+ return p;
32
+ };
33
+ const base = () => (tab.sessionId ? `/api/claude-code/sessions/${encodeURIComponent(tab.sessionId)}/background-tasks` : '');
34
+ tab._bgStopWaits = tab._bgStopWaits || new Map();
35
+ tab.bg = createBgTasksPanel({
36
+ key: tab.sessionId ? `claude:${tab.sessionId}` : '',
37
+ factsOf: (ev) => claudeFactsFromEvent(ev),
38
+ liveFactOf: (tasks) => claudeLiveFact(tasks),
39
+ storage,
40
+ t,
41
+ onChange,
42
+ onShownChange,
43
+ api: {
44
+ async list() {
45
+ const url = base();
46
+ if (!url) return null;
47
+ const { res, body } = await getJson(`${url}?${query()}`);
48
+ // A server from before this view has no such route (its 404 names no code): its output waits for a restart.
49
+ if (res.status === 404 && !body?.code) return { unsupported: true };
50
+ return res.ok && body?.ok ? body : null;
51
+ },
52
+ async output({ taskId, cursor, tail, limit, running }) {
53
+ const url = base();
54
+ if (!url) return { ok: false, status: 404, error: 'No session yet.' };
55
+ const p = query();
56
+ if (cursor != null) p.set('cursor', String(cursor));
57
+ if (tail != null) p.set('tail', String(tail));
58
+ if (limit != null) p.set('limit', String(limit));
59
+ if (typeof running === 'boolean') p.set('running', running ? '1' : '0');
60
+ try {
61
+ const { res, body } = await getJson(`${url}/${encodeURIComponent(taskId)}/output?${p}`);
62
+ if (!res.ok || !body?.ok) return { ok: false, status: res.status, error: body?.error || 'The output could not be read.' };
63
+ return { status: 200, data: body };
64
+ } catch (err) { return { ok: false, status: 502, error: err?.message || 'The output could not be read.' }; }
65
+ },
66
+ // The bridge's own stop (the SDK's stopTask), never a kill typed by hand.
67
+ stop(taskId) {
68
+ const ws = tab.ws;
69
+ if (!ws || ws.readyState !== 1) return Promise.resolve({ ok: false, error: 'The session is not connected.' });
70
+ if (tab.capabilities instanceof Set && !tab.capabilities.has('task_control')) return Promise.resolve({ ok: false, error: 'Stopping a task from here needs the SynaBun server restart.' });
71
+ return new Promise((resolve) => {
72
+ const timer = setTimeout(() => { tab._bgStopWaits.delete(taskId); resolve({ ok: false, error: 'No answer from the session.' }); }, STOP_WAIT_MS);
73
+ tab._bgStopWaits.set(taskId, (out) => { clearTimeout(timer); resolve(out); });
74
+ try { ws.send(JSON.stringify({ type: 'stop_task', taskId })); }
75
+ catch (err) { clearTimeout(timer); tab._bgStopWaits.delete(taskId); resolve({ ok: false, error: err?.message || String(err) }); }
76
+ });
77
+ },
78
+ },
79
+ });
80
+ return tab.bg;
81
+ }
82
+
83
+ /** The bridge answered a `stop_task` (task_control_result): the Stop that waited for it hears. → whether one did. */
84
+ export function settleClaudeBgStop(tab, msg) {
85
+ if (msg?.action !== 'stop_task' || !tab?._bgStopWaits?.size) return false;
86
+ const id = msg.taskId && tab._bgStopWaits.has(msg.taskId) ? msg.taskId : [...tab._bgStopWaits.keys()][0];
87
+ const done = tab._bgStopWaits.get(id);
88
+ tab._bgStopWaits.delete(id);
89
+ done?.({ ok: !!msg.ok, error: msg.error || '' });
90
+ return true;
91
+ }
92
+
93
+ /**
94
+ * The cards of a replayed `origin` row whose notices the server read (lib/claude-history.js `notifications`),
95
+ * linked to the task the registry knows (or what the notice says).
96
+ */
97
+ export function historyNoticeCards(tab, row, t = null) {
98
+ const out = [];
99
+ const at = Date.parse(row?.timestamp || '') || 0;
100
+ for (const n of Array.isArray(row?.notifications) ? row.notifications : []) {
101
+ if (!n?.taskId) continue;
102
+ const task = tab?.bg?.registry?.().tasks.get(n.taskId) || null;
103
+ const view = noticeCardView({ taskId: n.taskId, type: n.event || /^monitor\b/i.test(n.summary || '') ? 'watch' : 'shell', status: n.status || (n.event ? 'event' : ''), summary: n.summary || '', event: n.event || '', exitCode: exitCodeOf(n.summary), stale: false }, task);
104
+ const card = renderBgNoticeCard(view, { t });
105
+ if (at) card.dataset.at = String(at);
106
+ if (view.isEvent) card.dataset.event = '1';
107
+ out.push(card);
108
+ }
109
+ return out;
110
+ }
111
+
112
+ /** After a rebuild, the replayed cards of events that came after their task's end say they are stale. */
113
+ export function markClaudeStaleCards(tab) {
114
+ if (tab?.messagesEl && tab.bg) markStaleNoticeCards(tab.messagesEl, tab.bg.registry());
115
+ }
116
+
117
+ /**
118
+ * One click listener per transcript (a transcript put back from a stored snapshot has no listeners of its own):
119
+ * a notice card opens its task in the view.
120
+ */
121
+ export function wireNoticeCardClicks(container, open) {
122
+ if (!container || container._sbtNoticeWired) return;
123
+ container._sbtNoticeWired = true;
124
+ container.addEventListener('click', (event) => {
125
+ const card = event.target?.closest?.('.sbt-notice[data-task-id]');
126
+ if (!card || !container.contains(card)) return;
127
+ event.preventDefault();
128
+ open(card.dataset.taskId);
129
+ });
130
+ }
@@ -2,6 +2,7 @@
2
2
  // this reads the server's setup status, renders, and does the page's few actions. The one-time token goes into
3
3
  // #synabun-setup-ticket only while the extension's content script is on this page and the server waits for it, and is
4
4
  // taken out again as soon as the setup moves on.
5
+ import { extensionUpdateView } from '../extension-update-view.js';
5
6
  import { makeTranslator, pageLocale, revealKey, setupView, wantsTicket } from './es-view.js';
6
7
 
7
8
  const $ = id => document.getElementById(id);
@@ -29,24 +30,28 @@ function fixedText() {
29
30
  put($('es-copy-url'), tx('copyAddress')); put($('es-copy-folder'), tx('copyFolder'));
30
31
  put($('es-folder-label'), tx('folderLabel'));
31
32
  put($('es-reveal'), tx(revealKey(navigator.userAgentData?.platform || navigator.platform || '')));
32
- put($('es-alternatives-title'), tx('alternativesTitle')); put($('es-restart'), tx('restart'));
33
+ put($('es-alternatives-title'), tx('alternativesTitle'));
33
34
  put($('es-back'), tx('backToApp')); put($('es-pin'), tx('pinTip'));
34
35
  put($('es-full-title'), tx('fullTitle')); put($('es-full-help'), tx('fullHelp'));
35
- put($('es-trouble-title'), tx('needHelp')); put($('es-trouble-help'), tx('helpText')); put($('es-policy-help'), tx('policyText'));
36
+ put($('es-trouble-title'), tx('needHelp')); put($('es-trouble-help'), tx('helpText')); put($('es-moved-help'), tx('movedText')); put($('es-policy-help'), tx('policyText'));
36
37
  }
37
38
  function render() {
38
39
  const view = setupView(status, { extensionVersion: extensionSeen(), pairAnswer: pairAnswer() });
40
+ const update = extensionUpdateView(status.update, t);
41
+ const updating = update && ['idle', 'connected'].includes(view.state);
39
42
  const main = $('es-setup');
40
43
  main.dataset.state = view.state; main.dataset.layout = view.layout; main.setAttribute('aria-busy', 'false');
41
- put($('es-title'), tx(view.title));
44
+ put($('es-title'), updating ? update.title : tx(view.title));
45
+ $('es-lead').hidden = !!updating;
42
46
  put($('es-lead'), tx(view.lead, { browser: view.browser }));
43
47
  $('es-eyebrow').hidden = !view.eyebrow; put($('es-eyebrow'), view.eyebrow ? tx(view.eyebrow, { browser: view.browser }) : '');
44
- const live = $('es-live'); put(live, tx(view.live, view.liveParams)); live.dataset.tone = view.tone;
45
- $('es-status').dataset.tone = view.tone || 'idle';
46
- put($('es-status-title'), tx(view.statusTitle));
47
- $('es-help').hidden = !view.help; put($('es-help'), view.help ? tx(view.help) : '');
48
+ const live = $('es-live'); put(live, updating ? update.message : tx(view.live, view.liveParams)); live.dataset.tone = updating ? (update.due ? 'warn' : 'ok') : view.tone;
49
+ $('es-status').dataset.tone = live.dataset.tone || 'idle';
50
+ put($('es-status-title'), updating ? t('browserExtension.statusTitle') : tx(view.statusTitle));
51
+ $('es-help').hidden = !!updating || !view.help; put($('es-help'), view.help ? tx(view.help) : '');
52
+ $('es-progress').hidden = !view.progress; put($('es-progress'), view.progress ? tx('downloadProgress', view.progress) : '');
48
53
  $('es-browser').hidden = !view.browser; put($('es-browser-name'), view.browser);
49
- $('es-steps').hidden = !view.showSteps;
54
+ $('es-steps').hidden = !!updating || !view.showSteps;
50
55
  for (const step of view.steps) {
51
56
  const id = { stepOpenTitle: 'open', stepDeveloperTitle: 'developer', stepLoadTitle: 'load', stepPairTitle: 'pair' }[step.title];
52
57
  put($(`es-step-${id}-title`), tx(step.title));
@@ -67,11 +72,14 @@ function render() {
67
72
  list.append(button);
68
73
  }
69
74
  }
70
- $('es-reload').hidden = !view.reloadNeeded; put($('es-reload'), tx('reloadNeeded', { browser: view.browser }));
71
- $('es-restart').hidden = !view.restart;
72
- $('es-back').hidden = !view.back; $('es-pin').hidden = !view.pinTip;
75
+ const note = update ? (!updating && update.due ? [update.title, update.message].join(' ') : '')
76
+ : view.reloadNeeded || view.updateNeeded ? tx(view.updateNeeded ? 'updateNeeded' : view.reloadRepaired ? 'reloadRepaired' : 'reloadNeeded', { browser: view.browser }) : '';
77
+ $('es-reload').hidden = !note; put($('es-reload'), note);
78
+ $('es-update-flow').hidden = !update?.due; put($('es-update-flow'), t('browserExtension.updateFlow.review'));
79
+ $('es-restart').hidden = !!updating || !view.restart; put($('es-restart'), tx(view.restartLabel));
80
+ $('es-back').hidden = updating ? update.due : !view.back; $('es-pin').hidden = !!updating || !view.pinTip;
73
81
  // The row is hidden by the code that fills it (never found by a :has(), which every hidden toggle re-checks).
74
- $('es-actions').hidden = !view.restart && !view.back;
82
+ $('es-actions').hidden = $('es-restart').hidden && $('es-back').hidden && $('es-update-flow').hidden;
75
83
  if (!['waiting-for-extension', 'extension-found'].includes(view.state)) clearTicket();
76
84
  }
77
85
 
@@ -80,6 +88,11 @@ async function poll() {
80
88
  busy = true;
81
89
  try {
82
90
  status = await call('status');
91
+ // The extension's content script ran on this page, on this port: the browser runs the folder's manifest for it, so
92
+ // the Reload a port change asked for is done (the server keeps saying "reload" until then). Never for a repair: the
93
+ // copy the browser still runs would answer the same, so this page only says to confirm in SynaBun Settings (and the
94
+ // server ignores `seen` for it anyway).
95
+ if (status.reloadNeeded && !status.reloadRepaired && (!status.update || status.update.reason === 'port') && extensionSeen() && extensionSeen() === status.folderVersion) status = await call('seen', {});
83
96
  if (wantsTicket(status, { extensionVersion: extensionSeen(), pairAnswer: pairAnswer(), offeredAt, tickets })) {
84
97
  tickets++;
85
98
  const ticket = await call('ticket', {});
@@ -1,24 +1,27 @@
1
1
  // The "Connect your browser" page's decisions (public/extension-setup.html; docs/browser-extension-bridge.md →
2
2
  // One-button setup). DOM-free and import-free: node --test loads it. The page (es-page.js) renders what this returns.
3
3
  //
4
- // Page states (data-state on <main>): the server's setup state (idle, waiting-for-extension, pairing, connected,
5
- // unsupported, error), with one page-only refinement: `extension-found` while the server still waits but the
4
+ // Page states (data-state on <main>): the server's setup state (idle, downloading, waiting-for-extension, pairing,
5
+ // connected, unsupported, error), with one page-only refinement: `extension-found` while the server still waits but the
6
6
  // extension's content script has announced itself on this page (it then gets the one-time token and pairs).
7
7
 
8
8
  /** The server's setup states, and the page's own. */
9
- export const SETUP_STATES = Object.freeze(['idle', 'waiting-for-extension', 'pairing', 'connected', 'unsupported', 'error']);
9
+ export const SETUP_STATES = Object.freeze(['idle', 'downloading', 'waiting-for-extension', 'pairing', 'connected', 'unsupported', 'error']);
10
10
  export const PAGE_STATES = Object.freeze([...SETUP_STATES, 'extension-found']);
11
11
  /** What the extension's service worker may answer the content script (setup-content.js writes it to data-synabun-pair). */
12
12
  export const PAIR_ANSWERS = Object.freeze(['sent', 'started', 'ALREADY_CONNECTED', 'ALREADY_PAIRED', 'PAUSED', 'BUSY', 'NOT_OWNED', 'INVALID_MESSAGE', 'REFUSED', 'EXTENSION_UNAVAILABLE']);
13
13
  /** Error codes the page has a sentence for (browserExtension.setup.error<CODE>); any other is `error`. */
14
- export const SETUP_ERRORS = Object.freeze(['SETUP_EXPIRED', 'EXTENSION_FOLDER_FAILED', 'OPEN_FAILED', 'SETUP_NOT_ACTIVE', 'SETUP_TICKETS_USED', 'PAGE_SECRET_REQUIRED', 'PEER_UNAVAILABLE']);
14
+ export const SETUP_ERRORS = Object.freeze(['SETUP_EXPIRED', 'EXTENSION_FOLDER_FAILED', 'EXTENSION_FOLDER_UNSAFE','EXTENSION_DOWNLOAD_OFFLINE', 'EXTENSION_DOWNLOAD_UNAVAILABLE', 'EXTENSION_VERIFY_FAILED', 'OPEN_FAILED', 'SETUP_NOT_ACTIVE', 'SETUP_TICKETS_USED', 'PAGE_SECRET_REQUIRED', 'PEER_UNAVAILABLE']);
15
+ /** The errors of the extension's download (the package was not fetched or did not verify): the page offers to try again. */
16
+ export const DOWNLOAD_ERRORS = Object.freeze(['EXTENSION_DOWNLOAD_OFFLINE', 'EXTENSION_DOWNLOAD_UNAVAILABLE', 'EXTENSION_VERIFY_FAILED']);
15
17
  /** Answers after which the page asks for a fresh ticket (a new token) once its wait has passed. */
16
18
  const RETRY_AFTER = Object.freeze({ ALREADY_PAIRED: 8000, BUSY: 2500, REFUSED: 5000, EXTENSION_UNAVAILABLE: 5000, started: 20000 });
17
19
 
18
20
  /**
19
21
  * The page's view of a status (GET /api/browser/extension/setup/status) and what the page saw of the extension:
20
22
  * `extensionVersion` (data-synabun-extension, '' when absent) and `pairAnswer` (data-synabun-pair).
21
- * Returns { state, title, lead, steps, browser, extensionsUrl, folder, alternatives, live, tone, reloadNeeded, retry }.
23
+ * Returns { state, title, lead, steps, browser, extensionsUrl, folder, alternatives, live, tone, reloadNeeded, reloadRepaired, updateNeeded,
24
+ * progress, restart, restartLabel }.
22
25
  * Strings are i18n keys under browserExtension.setup (the page translates them); `params` fill their {placeholders}.
23
26
  */
24
27
  export function setupView(status = {}, { extensionVersion = '', pairAnswer = '' } = {}) {
@@ -41,25 +44,37 @@ export function setupView(status = {}, { extensionVersion = '', pairAnswer = ''
41
44
  // "Open in X instead": the installed supported browsers other than the one this setup uses.
42
45
  const alternatives = (status.installedBrowsers || []).filter(b => b?.supported && b.id !== browser?.id).map(b => ({ id: b.id, name: b.name }));
43
46
  const live = {
44
- idle: 'liveIdle', 'waiting-for-extension': 'liveWaiting', 'extension-found': PAIR_ANSWERS.includes(pairAnswer) && pairAnswer !== 'sent' && pairAnswer !== 'started' ? `answer${pairAnswer}` : 'liveFound',
47
+ idle: 'liveIdle', downloading: 'liveDownloading', 'waiting-for-extension': 'liveWaiting', 'extension-found': PAIR_ANSWERS.includes(pairAnswer) && pairAnswer !== 'sent' && pairAnswer !== 'started' ? `answer${pairAnswer}` : 'liveFound',
45
48
  pairing: 'livePairing', connected: 'liveConnected', unsupported: 'liveUnsupported', error: `error${SETUP_ERRORS.includes(status.code) ? status.code : ''}`,
46
49
  }[state];
47
50
  const tone = state === 'connected' ? 'ok' : state === 'error' || state === 'unsupported' ? 'err' : state === 'idle' ? '' : 'warn';
48
- const showSteps = !['unsupported', 'idle'].includes(state) && !(state === 'error' && !status.folder);
51
+ // No steps while the extension is on its way: there is no folder to load yet.
52
+ const showSteps = !['unsupported', 'idle', 'downloading'].includes(state) && !(state === 'error' && !status.folder);
53
+ const downloadFailed = state === 'error' && DOWNLOAD_ERRORS.includes(status.code);
54
+ // The bytes so far, in whole KB (the page shows them beside the status; never in the live region, which would be read out at every poll).
55
+ const kb = n => Math.max(0, Math.round((Number(n) || 0) / 1024));
56
+ const progress = state === 'downloading' && status.download && Number(status.download.total) > 0 ? { received: kb(Math.min(status.download.received, status.download.total)), total: kb(status.download.total) } : null;
49
57
  // The guide (the steps beside the status) while the owner installs; one result card once there is nothing to do there.
50
58
  const layout = showSteps && state !== 'connected' ? 'guide' : 'result';
51
- const statusTitle = { 'waiting-for-extension': 'waitingTitle', 'extension-found': 'foundTitle', pairing: 'pairingTitle', connected: 'titleConnected',
52
- unsupported: 'titleUnsupported', idle: 'idleTitle', error: 'errorTitle' }[state];
59
+ const statusTitle = { downloading: 'downloadingTitle', 'waiting-for-extension': 'waitingTitle', 'extension-found': 'foundTitle', pairing: 'pairingTitle', connected: 'titleConnected',
60
+ unsupported: 'titleUnsupported', idle: 'idleTitle', error: downloadFailed ? 'downloadErrorTitle' : 'errorTitle' }[state];
53
61
  return {
54
62
  layout, statusTitle, eyebrow: name ? 'eyebrow' : '',
55
- help: state === 'connected' ? 'connectedHelp' : '',
63
+ help: state === 'connected' ? 'connectedHelp' : state === 'downloading' ? 'downloadingHelp' : '',
64
+ progress,
56
65
  state, title: state === 'connected' ? 'titleConnected' : state === 'unsupported' ? 'titleUnsupported' : 'title',
57
66
  lead: state === 'unsupported' ? 'leadUnsupported' : 'lead', steps, browser: name, extensionsUrl,
58
67
  folder: typeof status.folder === 'string' ? status.folder : '', alternatives, live, liveParams: { browser: name }, tone,
59
68
  reloadNeeded: status.reloadNeeded === true,
69
+ // SynaBun replaced files that were not its extension: the same Reload, in the words of a repair.
70
+ reloadRepaired: status.reloadNeeded === true && status.reloadRepaired === true,
71
+ // The folder holds an older extension than this release's: SynaBun downloads the new one; a Reload comes after.
72
+ updateNeeded: status.updateNeeded === true && status.reloadNeeded !== true,
60
73
  showSteps,
61
74
  // What the page offers: start again (idle, error), back to SynaBun and the pin tip (connected).
62
75
  restart: ['error', 'idle'].includes(state), back: state === 'connected', pinTip: state === 'connected',
76
+ // A download that failed is tried again by the same button, under its own words.
77
+ restartLabel: downloadFailed ? 'retryDownload' : 'restart',
63
78
  // "Open in X instead" while there is still something to install here; never once pairing began.
64
79
  showAlternatives: alternatives.length > 0 && !['pairing', 'connected'].includes(state),
65
80
  };
@@ -0,0 +1,34 @@
1
+ // Shared words and actions for Settings, the setup page, the notification and the Assistant.
2
+ const releaseNotes = { '1.5.0': 'notes.v1_5_0' };
3
+ const downloadErrors = {
4
+ EXTENSION_DOWNLOAD_OFFLINE: 'offline', EXTENSION_DOWNLOAD_UNAVAILABLE: 'unavailable',
5
+ EXTENSION_VERIFY_FAILED: 'unverified', EXTENSION_FOLDER_UNSAFE: 'unsafe',
6
+ EXTENSION_DOWNLOAD_CANCELLED: 'cancelled',
7
+ };
8
+ export function extensionUpdateView(update, tx) {
9
+ if (!update?.targetVersion || !['downloading', 'ready', 'reloading', 'failed', 'done'].includes(update.phase)) return null;
10
+ const { phase, reason, recovery, code, targetVersion: version } = update;
11
+ const from = update.runningVersion || update.fromVersion;
12
+ const params = { from, version, percent: update.percent ?? 0 };
13
+ const t = key => tx(`browserExtension.updateFlow.${key}`, params);
14
+ const done = phase === 'done';
15
+ const same = from && from === version;
16
+ const title = done ? t('done') : from && !same ? t('versions')
17
+ : reason === 'repair' ? t('repairTitle') : reason === 'port' ? t('portTitle') : t('target');
18
+ const notes = !done && reason === 'version' && !same && Object.hasOwn(releaseNotes, version) ? t(releaseNotes[version]) : '';
19
+ const guided = (phase === 'ready' && !update.canReload) || (phase === 'failed' && recovery === 'guided');
20
+ let message = '';
21
+ if (phase === 'downloading') message = t(update.pending ? 'pending' : update.percent === 100 ? 'verifying' : 'progress');
22
+ if (phase === 'reloading') message = t('reloading');
23
+ if (phase === 'ready') message = t(reason === 'repair' ? 'repaired' : reason === 'port' ? 'port' : update.canReload ? 'ready' : 'manual');
24
+ if (phase === 'failed') message = t(guided ? (code === 'RELOAD_OLD_VERSION' ? 'oldVersion' : code === 'RELOAD_TIMEOUT' ? 'timeout' : 'reloadFailed') : downloadErrors[code] || 'downloadFailed');
25
+ return {
26
+ title, message, notes, due: !done, guided, updateNow: phase === 'ready' && update.canReload,
27
+ download: phase === 'downloading' && update.pending,
28
+ retry: phase === 'failed' && recovery === 'download',
29
+ busy: !!(update.claimedTabs || update.runsActive || update.confirmBusy),
30
+ confirmRepair: reason === 'repair' && (phase === 'ready' || guided),
31
+ checkPort: reason === 'port' && (phase === 'ready' || guided),
32
+ key: `${version}/${reason}`,
33
+ };
34
+ }
@@ -33,6 +33,7 @@ import { dropdownHTML, dropdownOf, setDropdownDisabled, setDropdownItems, wireDr
33
33
  import { renderMarkdown } from '../cp/cp-markdown.js';
34
34
  import { fetchProjects } from '../api.js';
35
35
  import { createStickyScrollController } from '../ui-scroll-follow.js';
36
+ import { composerHoldsDraft, markAutoCloseKeep } from '../tray-auto-close.js';
36
37
 
37
38
  export const PANEL_OWNER = 'maritaca-sidepanel';
38
39
  const ICON = ICONS.mark;
@@ -368,7 +369,7 @@ async function stageFiles(files) {
368
369
  }
369
370
  saveTabs();
370
371
  } catch (error) { showBanner(T('attachmentFailed', { name: '', error: error.message }), 'error'); }
371
- finally { tab.pendingAttachments = false; renderComposer(); }
372
+ finally { tab.pendingAttachments = false; renderComposer(); renderPills(); }
372
373
  }
373
374
 
374
375
  async function copyText(text) {
@@ -738,6 +739,18 @@ async function switchBranch(branch) {
738
739
  await loadBranches(project);
739
740
  }
740
741
  }
742
+ // What the tray's auto-close must leave open (tray-auto-close.js), or '': a tab holding an unsent draft, its text (in
743
+ // the composer while the tab is the one on screen) or its staged attachments, and while a message is being edited the
744
+ // draft and attachments the edit put aside. Its X (closeTab) throws them away; the user's X closes it as before.
745
+ function autoCloseKeepOf(tab) {
746
+ if (!tab) return '';
747
+ const input = tab === activeTab() ? $('.mtc-input') : null;
748
+ const editing = tab.editingIndex != null;
749
+ const held = composerHoldsDraft(input ? input.value : tab.draft, tab.attachments)
750
+ || (editing && composerHoldsDraft(tab.beforeEdit, tab.beforeEditAttachments));
751
+ return held ? 'draft' : '';
752
+ }
753
+
741
754
  function renderPills() {
742
755
  const tray = document.getElementById('term-minimized-tray');
743
756
  for (const tab of _tabs) {
@@ -748,6 +761,7 @@ function renderPills() {
748
761
  pill.dataset.tabId = tab.id;
749
762
  pill.tabIndex = 0;
750
763
  pill.setAttribute('role', 'button');
764
+ pill.keepFromAutoClose = () => autoCloseKeepOf(tab);
751
765
  pill.innerHTML = `<span class="mtc-pill-ring" aria-hidden="true"><i></i></span><span class="term-minimized-pill-icon mtc-mark">${ICON}</span><span class="term-minimized-pill-label"></span><button class="term-minimized-pill-close" data-tooltip="${esc(T('closeTab'))}" aria-label="${esc(T('closeTab'))}">&times;</button>`;
752
766
  // A closed panel goes to this tab first and is shown after: showing it first drew, and loaded the session
753
767
  // of, the tab it was left on before the one that was clicked.
@@ -762,6 +776,7 @@ function renderPills() {
762
776
  const label = tab.pillEl.querySelector('.term-minimized-pill-label');
763
777
  if (label) label.textContent = tabLabel(tab, T);
764
778
  tab.pillEl.classList.toggle('mtc-pill-running', !!tab.running);
779
+ markAutoCloseKeep(tab.pillEl, autoCloseKeepOf(tab));
765
780
  const meaningful = !!(tab.sessionId || tab.running || tab.draft || tab.attachments?.length);
766
781
  tab.pillEl.style.display = meaningful && (!_visible || tab !== activeTab()) ? '' : 'none';
767
782
  }
@@ -1196,7 +1211,7 @@ function wire() {
1196
1211
  $('#mtc-model')?.addEventListener('change', (event) => { const tab = activeTab(); if (!tab) return; tab.model = event.target.value || null; tab.effort = null; saveTabs(); renderComposer(); renderHeader(); renderContextPop(); });
1197
1212
  $('.mtc-attach')?.addEventListener('click', () => $('.mtc-file-input')?.click());
1198
1213
  $('.mtc-file-input')?.addEventListener('change', (event) => { stageFiles([...event.target.files]); event.target.value = ''; });
1199
- $('.mtc-staged')?.addEventListener('click', (event) => { const remove = event.target.closest('[data-remove-attachment]'); const tab = activeTab(); if (!remove || tab?.submitting) return; tab.attachments.splice(Number(remove.dataset.removeAttachment), 1); saveTabs(); renderComposer(); });
1214
+ $('.mtc-staged')?.addEventListener('click', (event) => { const remove = event.target.closest('[data-remove-attachment]'); const tab = activeTab(); if (!remove || tab?.submitting) return; tab.attachments.splice(Number(remove.dataset.removeAttachment), 1); saveTabs(); renderComposer(); renderPills(); });
1200
1215
  input?.addEventListener('paste', (event) => { const files = [...(event.clipboardData?.files || [])]; if (files.length) { event.preventDefault(); stageFiles(files); } });
1201
1216
  let dragDepth = 0;
1202
1217
  _panel.addEventListener('dragenter', (event) => { if (![...(event.dataTransfer?.types || [])].includes('Files')) return; event.preventDefault(); dragDepth++; _panel.classList.add('mtc-dragging'); });
@@ -196,6 +196,11 @@ export function applyEvent(store, eventType, ev = {}, hooks = {}) {
196
196
  hooks.onOutcome?.(store, 'error');
197
197
  break;
198
198
  }
199
+ case 'shell.updated':
200
+ // A tool call's shell command: started, running on after its call (in the
201
+ // background), ended. What it prints is read apart (ocp-v2-shell-logic.js).
202
+ if (ev.shell) store.upsertShell?.(ev.shell);
203
+ break;
199
204
  case 'todo.updated':
200
205
  store.setTodos(ev.todos);
201
206
  break;
@@ -978,6 +978,7 @@ let _lastWaitingPill = null;
978
978
  // when it is first shown.
979
979
  const PILL_API = {
980
980
  sessionStatus: (args) => api.sessionStatus(args),
981
+ shellList: (args) => api.shellList(args),
981
982
  permissionList: (args) => api.permissionList(args),
982
983
  questionList: (args) => api.questionList(args),
983
984
  };
@@ -29,7 +29,7 @@ import {
29
29
  import {
30
30
  forkSession, undoLastTurn, restoreReverted,
31
31
  loadSelectedSession, applySessionSelections, restoreDraftAttachments,
32
- readTranscriptExport, stopForNavigation, createSessionForNavigation, renameSession,
32
+ readTranscriptExport, stopForNavigation, noteAbandoned, createSessionForNavigation, renameSession,
33
33
  navigateAfter, adoptReusableSession, landWithoutTabs, shouldNameCreatedSession, renameBox,
34
34
  } from './ocp-v2-session-actions.js';
35
35
  import { captureBinding, latestFor, createNavigation } from './ocp-v2-binding.js';
@@ -2168,8 +2168,14 @@ function deleteSessionBestEffort(sessionId, { abort = false, context = 'delete'
2168
2168
  if (!sessionId) return Promise.resolve({ ok: true });
2169
2169
  return (async () => {
2170
2170
  if (abort) {
2171
- try { await api.abort(sessionId); }
2171
+ // The tab is going: nobody is left to press Stop again, so a command Stop cannot end is given up on ("Stop
2172
+ // anyway": it is still removed in the background, and its end wakes no model turn).
2173
+ let stopped = null;
2174
+ try { stopped = await api.abort(sessionId, { force: true }); }
2172
2175
  catch (err) { console.warn(`[ocp-v2-panel] abort before ${context} failed`, err); }
2176
+ // What it gave up on may still be running: the panel, still open on another tab, says so.
2177
+ // (Best effort: the notice never holds up the deletion.)
2178
+ try { await noteAbandoned(getDefaultStore(), stopped, t); } catch { /* the close goes on */ }
2173
2179
  }
2174
2180
  let res;
2175
2181
  try { res = await api.sessionDelete(sessionId); }
@@ -2433,6 +2439,7 @@ function createTabPill(sessionId) {
2433
2439
  pill.dataset.sessionId = sessionId;
2434
2440
  pill.getAutomationRunId = () => _automationRunIds.get(sessionId);
2435
2441
  pill.hasQueuedWorkerPrompts = () => _automationRunIds.has(sessionId) && promptsWaitingFor(sessionId).length > 0;
2442
+ pill.detachForAutoClose = () => detachTabForAutoClose(sessionId);
2436
2443
  pill.innerHTML = `
2437
2444
  <span class="ocpv2-pill-ring" aria-hidden="true"><i></i></span>
2438
2445
  <span class="term-minimized-pill-icon">${OPENCODE_ICON}</span>
@@ -2470,6 +2477,20 @@ async function closeTabByUser(sessionId, context, { deleteBeforeClose = false }
2470
2477
  return true;
2471
2478
  }
2472
2479
 
2480
+ // The tray's auto-close toggle, for a session that names no run. Unlike the X,
2481
+ // which deletes the session, this only takes the tab and its pill away: the
2482
+ // session and its transcript stay in OpenCode and the session menu opens them
2483
+ // again. Nobody chose this close, so nobody is asked: a turn that started or a
2484
+ // prompt still waiting keeps the tab. Resolves whether the tab went.
2485
+ async function detachTabForAutoClose(sessionId) {
2486
+ const working = sessionId === getState().sessionId ? !!getState().running : _sessionBusy.get(sessionId) === true;
2487
+ if (!_tabSessionIds.includes(sessionId) || _automationRunIds.has(sessionId) || working
2488
+ || promptsWaitingFor(sessionId).length) return false;
2489
+ try { await handlePillClose(sessionId); }
2490
+ catch (err) { console.warn('[ocp-v2-panel] auto-close detach failed', err); }
2491
+ return true;
2492
+ }
2493
+
2473
2494
  // The end of a worker the Assistant dispatched: its button closes the tab the
2474
2495
  // way the tab's X does (a warm worker that finished its task is completed, one
2475
2496
  // still at work is stopped; its record stays for the Assistant) and shows the
@@ -2776,6 +2797,17 @@ export async function attachOpenCodeAutomation(run, { focus = !!run?.focus, isCa
2776
2797
  _tabInfoCache.set(sessionId, cachedInfo);
2777
2798
  pushError({ message: run.error });
2778
2799
  }
2800
+ // A stop of the run (a worker's, a loop's) that could not end a command in the background: it may still be
2801
+ // running, and the tab says so once (lib/native-loop-runtime.js abandonedCommands; the words are the panel Stop's).
2802
+ if (Array.isArray(run.abandonedCommands) && run.abandonedCommands.length && getState().sessionId === sessionId
2803
+ && !_tabInfoCache.get(sessionId)?._automationAbandonedShown) {
2804
+ const cachedInfo = _tabInfoCache.get(sessionId) || info;
2805
+ cachedInfo._automationAbandonedShown = true;
2806
+ _tabInfoCache.set(sessionId, cachedInfo);
2807
+ const view = await import('../shell-stop-view.js').catch(() => null);
2808
+ const left = view?.describeAbandoned(run.abandonedCommands, t) || null;
2809
+ if (left) pushError({ message: left, kind: 'shell-stop', notice: true });
2810
+ }
2779
2811
  trackWorkerEnd(run, { apply: (view) => showWorkerEnd(sessionId, view) });
2780
2812
  renderPill();
2781
2813
  syncSavedTabWaiting();