synabun 2.4.3 → 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 (153) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +1 -1
  3. package/docs/browser-extension-bridge.md +61 -32
  4. package/mcp-server/dist/http.d.ts.map +1 -1
  5. package/mcp-server/dist/http.js +8 -1
  6. package/mcp-server/dist/http.js.map +1 -1
  7. package/mcp-server/dist/services/identity.d.ts +2 -0
  8. package/mcp-server/dist/services/identity.d.ts.map +1 -1
  9. package/mcp-server/dist/services/identity.js +4 -0
  10. package/mcp-server/dist/services/identity.js.map +1 -1
  11. package/mcp-server/dist/services/memory-client.d.ts +5 -0
  12. package/mcp-server/dist/services/memory-client.d.ts.map +1 -1
  13. package/mcp-server/dist/services/memory-client.js +21 -2
  14. package/mcp-server/dist/services/memory-client.js.map +1 -1
  15. package/mcp-server/dist/services/memory-writer.d.ts +3 -0
  16. package/mcp-server/dist/services/memory-writer.d.ts.map +1 -1
  17. package/mcp-server/dist/services/memory-writer.js +7 -1
  18. package/mcp-server/dist/services/memory-writer.js.map +1 -1
  19. package/mcp-server/dist/services/neural-interface.d.ts +11 -1
  20. package/mcp-server/dist/services/neural-interface.d.ts.map +1 -1
  21. package/mcp-server/dist/services/neural-interface.js +67 -17
  22. package/mcp-server/dist/services/neural-interface.js.map +1 -1
  23. package/mcp-server/dist/services/typesafe-config.d.ts +38 -2
  24. package/mcp-server/dist/services/typesafe-config.d.ts.map +1 -1
  25. package/mcp-server/dist/services/typesafe-config.js +260 -8
  26. package/mcp-server/dist/services/typesafe-config.js.map +1 -1
  27. package/mcp-server/dist/tools/agent-definition.d.ts +2 -2
  28. package/mcp-server/dist/tools/agents.d.ts +3 -1
  29. package/mcp-server/dist/tools/agents.d.ts.map +1 -1
  30. package/mcp-server/dist/tools/agents.js +11 -6
  31. package/mcp-server/dist/tools/agents.js.map +1 -1
  32. package/mcp-server/dist/tools/browser-observe.d.ts +11 -0
  33. package/mcp-server/dist/tools/browser-observe.d.ts.map +1 -1
  34. package/mcp-server/dist/tools/browser-observe.js +113 -27
  35. package/mcp-server/dist/tools/browser-observe.js.map +1 -1
  36. package/mcp-server/dist/tools/browser-readers.d.ts +6 -0
  37. package/mcp-server/dist/tools/browser-readers.d.ts.map +1 -0
  38. package/mcp-server/dist/tools/browser-readers.js +17 -0
  39. package/mcp-server/dist/tools/browser-readers.js.map +1 -0
  40. package/mcp-server/dist/tools/remember.d.ts.map +1 -1
  41. package/mcp-server/dist/tools/remember.js +6 -2
  42. package/mcp-server/dist/tools/remember.js.map +1 -1
  43. package/mcp-server/dist/tools/youtube/analytics.d.ts +4 -0
  44. package/mcp-server/dist/tools/youtube/analytics.d.ts.map +1 -1
  45. package/mcp-server/dist/tools/youtube/analytics.js +25 -20
  46. package/mcp-server/dist/tools/youtube/analytics.js.map +1 -1
  47. package/mcp-server/dist/tools/youtube/helpers.d.ts +5 -1
  48. package/mcp-server/dist/tools/youtube/helpers.d.ts.map +1 -1
  49. package/mcp-server/dist/tools/youtube/helpers.js +7 -3
  50. package/mcp-server/dist/tools/youtube/helpers.js.map +1 -1
  51. package/mcp-server/dist/tools/youtube/navigate.d.ts +2 -0
  52. package/mcp-server/dist/tools/youtube/navigate.d.ts.map +1 -1
  53. package/mcp-server/dist/tools/youtube/navigate.js +5 -3
  54. package/mcp-server/dist/tools/youtube/navigate.js.map +1 -1
  55. package/mcp-server/dist/tools/youtube/playlist.js +2 -2
  56. package/mcp-server/dist/tools/youtube/playlist.js.map +1 -1
  57. package/mcp-server/dist/tools/youtube/readers.d.ts +4 -0
  58. package/mcp-server/dist/tools/youtube/readers.d.ts.map +1 -0
  59. package/mcp-server/dist/tools/youtube/readers.js +15 -0
  60. package/mcp-server/dist/tools/youtube/readers.js.map +1 -0
  61. package/mcp-server/package-lock.json +2 -2
  62. package/mcp-server/package.json +1 -1
  63. package/mcp-server/src/http.ts +8 -1
  64. package/mcp-server/src/services/identity.ts +5 -0
  65. package/mcp-server/src/services/memory-client.ts +32 -12
  66. package/mcp-server/src/services/memory-writer.ts +5 -2
  67. package/mcp-server/src/services/neural-interface.ts +65 -18
  68. package/mcp-server/src/services/typesafe-config.ts +268 -7
  69. package/mcp-server/src/tools/agents.ts +12 -6
  70. package/mcp-server/src/tools/browser-observe.ts +117 -28
  71. package/mcp-server/src/tools/browser-readers.ts +19 -0
  72. package/mcp-server/src/tools/remember.ts +6 -1
  73. package/mcp-server/src/tools/youtube/analytics.ts +26 -28
  74. package/mcp-server/src/tools/youtube/helpers.ts +8 -2
  75. package/mcp-server/src/tools/youtube/navigate.ts +6 -7
  76. package/mcp-server/src/tools/youtube/playlist.ts +2 -2
  77. package/mcp-server/src/tools/youtube/readers.ts +15 -0
  78. package/neural-interface/i18n/en.json +139 -0
  79. package/neural-interface/i18n/pt-BR.json +139 -0
  80. package/neural-interface/lib/assistant-api.js +90 -0
  81. package/neural-interface/lib/assistant-brains/claude.js +10 -0
  82. package/neural-interface/lib/assistant-dispatch.js +276 -42
  83. package/neural-interface/lib/assistant-memory.js +3 -1
  84. package/neural-interface/lib/assistant-persona.js +6 -0
  85. package/neural-interface/lib/assistant-router.js +18 -8
  86. package/neural-interface/lib/assistant-runtime.js +87 -1
  87. package/neural-interface/lib/assistant-task-prompt.js +15 -2
  88. package/neural-interface/lib/browser-connection-state.js +20 -0
  89. package/neural-interface/lib/browser-extension-adapter.js +221 -15
  90. package/neural-interface/lib/browser-extension-bridge.js +40 -7
  91. package/neural-interface/lib/browser-extension-folder.js +50 -11
  92. package/neural-interface/lib/browser-extension-package.js +6 -5
  93. package/neural-interface/lib/browser-extension-pin.json +15 -13
  94. package/neural-interface/lib/browser-extension-protocol.js +111 -13
  95. package/neural-interface/lib/browser-extension-setup.js +7 -5
  96. package/neural-interface/lib/browser-extension-update.js +104 -0
  97. package/neural-interface/lib/browser-extraction.js +38 -14
  98. package/neural-interface/lib/claude-bg-tasks.js +183 -0
  99. package/neural-interface/lib/claude-history.js +12 -1
  100. package/neural-interface/lib/confined-fs.js +25 -0
  101. package/neural-interface/lib/coordination/operations.js +2 -0
  102. package/neural-interface/lib/db.js +39 -16
  103. package/neural-interface/lib/editor-completion-opencode.js +2 -2
  104. package/neural-interface/lib/git-bash/manager.js +28 -3
  105. package/neural-interface/lib/git-status-runner.js +31 -3
  106. package/neural-interface/lib/loop-inventory.js +162 -0
  107. package/neural-interface/lib/loop-stall.js +74 -4
  108. package/neural-interface/lib/memory-session-capture.js +157 -66
  109. package/neural-interface/lib/native-loop-providers.js +73 -13
  110. package/neural-interface/lib/native-loop-runtime.js +3 -0
  111. package/neural-interface/lib/opencode-protocol.js +4 -2
  112. package/neural-interface/lib/peer-identity.js +62 -16
  113. package/neural-interface/lib/session-cache-builder.js +66 -18
  114. package/neural-interface/lib/session-capture-gate.js +42 -0
  115. package/neural-interface/lib/session-indexer.js +28 -20
  116. package/neural-interface/lib/teams/scheduler.js +3 -2
  117. package/neural-interface/lib/ui-blob-api.js +14 -5
  118. package/neural-interface/lib/ui-blob-store.js +302 -39
  119. package/neural-interface/package-lock.json +2 -2
  120. package/neural-interface/package.json +1 -1
  121. package/neural-interface/public/extension-setup.html +1 -0
  122. package/neural-interface/public/shared/assistant/asst-agents-dock.js +4 -0
  123. package/neural-interface/public/shared/assistant/asst-api.js +42 -0
  124. package/neural-interface/public/shared/assistant/asst-composer.js +85 -12
  125. package/neural-interface/public/shared/assistant/asst-panel.js +285 -10
  126. package/neural-interface/public/shared/assistant/asst-render.js +205 -4
  127. package/neural-interface/public/shared/assistant/asst-scenes.js +12 -0
  128. package/neural-interface/public/shared/assistant/asst-sidepanel.js +18 -1
  129. package/neural-interface/public/shared/assistant/asst-state.js +241 -2
  130. package/neural-interface/public/shared/assistant/asst-steer.js +294 -0
  131. package/neural-interface/public/shared/assistant/asst-styles.js +20 -0
  132. package/neural-interface/public/shared/bg-tasks/bg-tasks-claude.js +147 -0
  133. package/neural-interface/public/shared/bg-tasks/bg-tasks-model.js +527 -0
  134. package/neural-interface/public/shared/bg-tasks/bg-tasks-panel.js +161 -0
  135. package/neural-interface/public/shared/bg-tasks/bg-tasks-view.js +508 -0
  136. package/neural-interface/public/shared/browser-extension-updates.js +88 -0
  137. package/neural-interface/public/shared/cp/cp-bg-tasks.js +130 -0
  138. package/neural-interface/public/shared/extension-setup/es-page.js +18 -11
  139. package/neural-interface/public/shared/extension-update-view.js +34 -0
  140. package/neural-interface/public/shared/ocp-v2/ocp-v2-shell-logic.js +8 -4
  141. package/neural-interface/public/shared/settings/settings-browser-extension.js +10 -4
  142. package/neural-interface/public/shared/settings/settings-extension-update.js +114 -0
  143. package/neural-interface/public/shared/styles.css +4 -0
  144. package/neural-interface/public/shared/ui-claude-panel.js +110 -1
  145. package/neural-interface/public/shared/ui-notifications.js +23 -4
  146. package/neural-interface/public/shared/ui-settings-entry.js +6 -0
  147. package/neural-interface/public/shared/ui-tray-columns.js +9 -2
  148. package/neural-interface/public/shared/worker-end.js +18 -0
  149. package/neural-interface/scripts/patch-node-pty.mjs +151 -0
  150. package/neural-interface/scripts/rebuild-pty.js +10 -0
  151. package/neural-interface/server.js +483 -280
  152. package/npm-shrinkwrap.json +2 -2
  153. package/package.json +1 -1
@@ -30,7 +30,7 @@ import { fetchToolCatalog } from '../agent-runtime-options.js';
30
30
  import { emit, on, state as appState } from '../state.js';
31
31
  import { storage } from '../storage.js';
32
32
  import { KEYS } from '../constants.js';
33
- import { t } from '../i18n.js';
33
+ import { getLocale, t } from '../i18n.js';
34
34
  // The account words of the brain picker and the accounts manager (account-view.js) in the page's language.
35
35
  // Here, not in those modules: node tests load them, and i18n.js reads the page's storage.
36
36
  import '../account-i18n.js';
@@ -60,6 +60,9 @@ import { createRovingToolbar } from './asst-roving.js';
60
60
  import { openAccountsManager } from './asst-accounts.js';
61
61
  import { createAgentsDock } from './asst-agents-dock.js';
62
62
  import { activityOf } from './asst-scenes.js';
63
+ import { steerBreakBefore, steerNoticeText, steerTranslator } from './asst-state.js'; // steer's boot part (asst-steer.js loads on demand: steerModule)
64
+ import { registerLaunchPrefetch } from '../launch-prefetch.js';
65
+ import { createLazyModule } from '../lazy-module.js';
63
66
  import { createUsageGauge } from './asst-usage.js';
64
67
  import { closeMenu, currentMenuAnchor, isMenuOpen, openMenu } from './asst-menu.js';
65
68
  import { createRouteModeControl, openModelsManager, openRoutesEditor, refreshModelsManager, renderRouteCard, routeModeLabel } from './asst-route.js';
@@ -67,11 +70,12 @@ import { prewarmRoutesEditor } from './asst-route-models.js';
67
70
  import { budgetChipText, budgetSpendText, budgetTone, closeBudgetEditor, createBudgetController, mountBudgetChip, openBudgetEditor } from './asst-budget.js';
68
71
  import { computerRemoteView, createComputerPanel, createComputerToggle, normalizeComputerRemote, openFrameLightbox, closeFrameLightbox, requestDesktopStatus, requestDesktopStop } from './asst-computer.js';
69
72
  import {
70
- applyLimit, applyLimitPacket, applyUsagePacket, BRAIN_PROVIDERS, brainLabel, createRenameWriter, createTabState, DEFAULT_ROUTE_MODE, deserializeTabState, fmtCost, fmtRunLine, limitExpiresIn, limitNoticeText, modelShortName,
73
+ applyLimit, applyLimitPacket, applyUsagePacket, usagePacketValid, BRAIN_PROVIDERS, brainLabel, createRenameWriter, createTabState, DEFAULT_ROUTE_MODE, deserializeTabState, fmtCost, fmtRunLine, limitExpiresIn, limitNoticeText, modelShortName,
71
74
  brainModePatch, isBrainProvider, normalizeBrain, normalizeComputerMode, permissionModeLabel, normalizeRouteMode, normalizeTestDensity, projectLabel, providerMeta, providerShortLabel, readStoredBrain, runFromPayload,
72
75
  serializeTabState, sessionStatus, slashBrainEffort, tabStorageKey, userSessionTitle, conversationCanWait,
73
76
  } from './asst-state.js';
74
77
  import { idleQueue } from '../idle-queue.js';
78
+ import { listAssistantBackgroundTasks, readAssistantBackgroundOutput, stopAssistantBackgroundTask } from './asst-api.js';
75
79
  import { watchTranscriptRows } from '../transcript-rows.js';
76
80
  import { createMarkSettle } from './asst-motion-gate.js';
77
81
  import {
@@ -90,6 +94,17 @@ const ICON_CLOSE = '<svg viewBox="0 0 24 24"><line x1="18" y1="6" x2="6" y2="18"
90
94
  const ICON_TRASH = '<svg viewBox="0 0 24 24"><path d="M3 6h18M8 6V4.5A1.5 1.5 0 0 1 9.5 3h5A1.5 1.5 0 0 1 16 4.5V6M18.5 6l-.8 13a2 2 0 0 1-2 1.9H8.3a2 2 0 0 1-2-1.9L5.5 6M10 11v6M14 11v6"/></svg>';
91
95
  const REPLAY_WAIT_MS = 1500; // a replay that stops short of its count is drawn after this long
92
96
 
97
+ // Steer's controller and its POST (asst-steer.js) load in an idle moment after the page is shown or at the first
98
+ // steer, whichever comes first (lazy-module.js), so the page does not wait for them at boot; what the panel draws
99
+ // with from the first frame is in asst-state.js. A browser keeps a failed module address failed for the life of the
100
+ // page (a server restart can refuse the idle load), so a later attempt asks under a new address.
101
+ let steerAttempts = 0;
102
+ const steerModule = createLazyModule(() => {
103
+ const attempt = steerAttempts++;
104
+ return attempt ? import(`./asst-steer.js?retry=${attempt}`) : import('./asst-steer.js');
105
+ }, { name: 'Assistant steer' });
106
+ if (typeof document !== 'undefined') registerLaunchPrefetch('assistant-steer', () => steerModule.load(), { order: 17 });
107
+
93
108
  function el(tag, className, text) {
94
109
  const node = document.createElement(tag);
95
110
  if (className) node.className = className;
@@ -223,6 +238,7 @@ export function mountAssistant(viewport, { sessionId, brain, host = {}, session
223
238
  <div class="asst-bar-group" data-group="computer"></div>
224
239
  </div>
225
240
  <div class="asst-bar-right">
241
+ <button type="button" class="asst-iconbtn asst-act-bgtasks" hidden aria-pressed="false" data-tooltip="${esc(tt('bgTasks.toggle', 'Background tasks'))}" aria-label="${esc(tt('bgTasks.toggle', 'Background tasks'))}"><svg viewBox="0 0 24 24"><polyline points="22 12 18 12 15 21 9 3 6 12 2 12"/></svg></button>
226
242
  <button type="button" class="asst-iconbtn asst-act-agents" hidden aria-pressed="false" data-tooltip="${esc(tt('assistant.topbar.agents', 'Dispatched agents'))}" aria-label="${esc(tt('assistant.topbar.agents', 'Dispatched agents'))}">${ICON_AGENTS}<span class="asst-count">0</span></button>
227
243
  <button type="button" class="asst-cost" hidden aria-label="${esc(tt('assistant.budget.title', 'Budget'))}"></button>
228
244
  <button type="button" class="asst-iconbtn asst-act-sessions" data-tooltip="${esc(tt('assistant.topbar.sessions', 'Sessions'))}" aria-label="${esc(tt('assistant.topbar.sessions', 'Sessions'))}" aria-haspopup="menu" aria-expanded="false">${ICON_SESSIONS}</button>
@@ -252,12 +268,88 @@ export function mountAssistant(viewport, { sessionId, brain, host = {}, session
252
268
  const announcer = root.querySelector('.asst-announce');
253
269
  const agentsBtn = root.querySelector('.asst-act-agents');
254
270
  const agentsCount = agentsBtn.querySelector('.asst-count');
271
+ const bgBtn = root.querySelector('.asst-act-bgtasks');
255
272
  const sessionsBtn = root.querySelector('.asst-act-sessions');
256
273
  const newBtn = root.querySelector('.asst-act-new');
257
274
  const moreBtn = root.querySelector('.asst-act-more');
258
275
  // Every bar element is held above: from here on the bar may live outside the root.
259
276
  if (host.toolbarSlot) host.toolbarSlot.appendChild(barEl);
260
277
 
278
+ // ── Background tasks (public/shared/bg-tasks/): the Claude brain's background shells and watches ──
279
+ // The view takes the transcript's place in the panel; the bar's toggle and the host's pill carry "⟳ N".
280
+ // Its modules load on first use, for a Claude brain only: never before the page is shown
281
+ // (tests/boot-critical-path.test.mjs). Events that arrive while they load wait in order.
282
+ let bg = null;
283
+ let bgLoad = null;
284
+ let bgPending = [];
285
+ let bgScroll = 0;
286
+ let paintBadge = null;
287
+ const bgClaude = () => (st.brain?.provider || 'claude-code') === 'claude-code';
288
+ function ensureBg() {
289
+ if (bg || destroyed) return Promise.resolve(bg);
290
+ bgLoad ||= Promise.all([import('../bg-tasks/bg-tasks-panel.js'), import('../bg-tasks/bg-tasks-claude.js'), import('../bg-tasks/bg-tasks-view.js'), import('../cp/cp-bg-tasks.js')])
291
+ .then(([panelMod, claudeMod, viewMod, cpMod]) => {
292
+ if (destroyed) return null;
293
+ paintBadge = viewMod.paintBgBadge;
294
+ bg = panelMod.createBgTasksPanel({
295
+ key: `assistant:${sessionId}`,
296
+ factsOf: (ev) => (bgClaude() ? claudeMod.claudeFactsFromEvent(ev) : []),
297
+ liveFactOf: (tasks) => claudeMod.claudeLiveFact(tasks),
298
+ storage,
299
+ t,
300
+ overlay: false,
301
+ api: {
302
+ list: () => listAssistantBackgroundTasks(sessionId),
303
+ output: ({ taskId, cursor, tail, limit }) => readAssistantBackgroundOutput(sessionId, { taskId, cursor, tail, limit }),
304
+ stop: (taskId) => stopAssistantBackgroundTask(sessionId, taskId),
305
+ },
306
+ onChange: () => paintBgButton(),
307
+ onShownChange: (shown) => {
308
+ // In place of the transcript: the transcript keeps its place for when the view closes.
309
+ if (shown) { bgScroll = transcriptEl.scrollTop; transcriptEl.hidden = true; }
310
+ else { transcriptEl.hidden = false; transcriptEl.scrollTop = bgScroll; }
311
+ paintBgButton();
312
+ },
313
+ });
314
+ cpMod.wireNoticeCardClicks(transcriptEl, (taskId) => openBg(taskId));
315
+ const pending = bgPending;
316
+ bgPending = [];
317
+ for (const ev of pending) feedBg(ev);
318
+ return bg;
319
+ })
320
+ .catch(() => { bgLoad = null; return null; });
321
+ return bgLoad;
322
+ }
323
+ /** One live event of the brain: its facts, and a task's report as a card. */
324
+ function feedBg(ev) {
325
+ if (!bg) { if (bgPending.length < 500) bgPending.push(ev); ensureBg(); return; }
326
+ let cards = [];
327
+ try { cards = bg.onEvent(ev); } catch { cards = []; }
328
+ for (const { view } of cards) if (view) renderer.appendNode(bg.card(view));
329
+ }
330
+ const bgRelevant = (ev) => ev.type === 'assistant' || ev.type === 'user'
331
+ || (ev.type === 'system' && (String(ev.subtype || '').startsWith('task_') || ev.subtype === 'background_tasks_changed'));
332
+ function rebuildBg() { if (bgClaude()) ensureBg().then((b) => b?.rebuild()).catch(() => {}); }
333
+ function paintBgButton() {
334
+ if (destroyed || !bg) return;
335
+ const counts = bg.counts();
336
+ const open = bg.isShown();
337
+ bgBtn.hidden = !counts.total && !open;
338
+ bgBtn.classList.toggle('active', open);
339
+ bgBtn.setAttribute('aria-pressed', String(open));
340
+ paintBadge?.(bgBtn, counts.running, { t, corner: true, onClick: () => toggleBg() });
341
+ try { host.setBackgroundTasks?.(counts.running, () => openBg()); } catch { /* an older host */ }
342
+ }
343
+ function openBg(taskId = null) {
344
+ if (!bg) return;
345
+ bg.show(root, taskId);
346
+ // Right where the transcript is (the host appends it last).
347
+ const view = root.querySelector(':scope > .sbt-view');
348
+ if (view && view.previousElementSibling !== transcriptEl) transcriptEl.after(view);
349
+ }
350
+ function toggleBg() { if (!bg) return; if (bg.isShown()) bg.hide(); else openBg(); }
351
+ bgBtn.addEventListener('click', () => toggleBg());
352
+
261
353
  // ── Helpers ──
262
354
  // A worker-only provider provider-icons.js does not know yet keeps its own name (asst-state.js providerMeta).
263
355
  const providerIcon = (p) => providerMeta(p).icon;
@@ -563,6 +655,8 @@ export function mountAssistant(viewport, { sessionId, brain, host = {}, session
563
655
  }
564
656
  const renderer = createRenderer(transcriptEl, {
565
657
  t,
658
+ // A steer read from the journal: "Interrupted.", the break and the notice, as the live view drew them.
659
+ onSteerEntry: (steer) => steerEntry(steer),
566
660
  shells: {
567
661
  forCall: (id) => shellTracker?.forCall(id) || null,
568
662
  view: (id) => shellTracker?.view(id) || null,
@@ -578,6 +672,10 @@ export function mountAssistant(viewport, { sessionId, brain, host = {}, session
578
672
  onStopRun: (runId) => stopRun(runId),
579
673
  onReadRun: (runId) => readRun(runId),
580
674
  onEscalateRun: (runId, target) => escalateRun(runId, target),
675
+ // Steer (asst-steer.js): the card's one-line input, or the composer's target chip.
676
+ onSteerRun: (runId, text) => steerRunFromCard(runId, text),
677
+ onSteerRunInComposer: (runId, text) => steerTargetFromCard(runId, text),
678
+ locale: () => getLocale(),
581
679
  onMemoryClick: (id) => { if (id) emit('memory:open', { id }); },
582
680
  onMotionMark: (el) => { markSettle.hold(transcriptRowOf(el)); },
583
681
  onRackFolded: (row) => { rowWatcher.reconsider(row); },
@@ -679,6 +777,7 @@ export function mountAssistant(viewport, { sessionId, brain, host = {}, session
679
777
  onToast: toast,
680
778
  onRemoveQueued: (idx) => { if (idx >= 0) { st.queue.splice(idx, 1); composer.setQueue(st.queue); } },
681
779
  onSubmit: (payload) => submit(payload),
780
+ locale: () => getLocale(),
682
781
  // Files that do not go inline: saved on the server, the prompt carries the path.
683
782
  uploadFile: (file, opts) => uploadAssistantAttachment(file, { ...opts, sessionId }),
684
783
  });
@@ -775,6 +874,9 @@ export function mountAssistant(viewport, { sessionId, brain, host = {}, session
775
874
  onStop: (runId) => stopRun(runId),
776
875
  onRead: (runId) => readRun(runId),
777
876
  onEscalate: (runId, target) => escalateRun(runId, target),
877
+ onSteer: (runId, text) => steerRunFromCard(runId, text),
878
+ onSteerInComposer: (runId, text) => steerTargetFromCard(runId, text),
879
+ locale: () => getLocale(),
778
880
  onStopAll: () => stopAll(),
779
881
  onRemove: (runId) => removeRun(runId),
780
882
  onClearFinished: () => clearFinished(),
@@ -826,19 +928,20 @@ export function mountAssistant(viewport, { sessionId, brain, host = {}, session
826
928
  }).catch(() => { /* older servers do not expose usage */ });
827
929
  }
828
930
  function applyUsage(packet) {
829
- if (packet?.sessionId === sessionId && (!packet.task?.id || !Number.isSafeInteger(packet.task?.tokens?.total) || packet.task.tokens.total < 0)) {
931
+ if (packet?.sessionId === sessionId && !usagePacketValid(packet)) {
830
932
  if (!usageWarned) { console.warn('[assistant] invalid usage packet'); usageWarned = true; }
831
933
  return;
832
934
  }
833
935
  const was = st.usageView;
834
936
  if (!applyUsagePacket(st, packet)) return;
835
937
  if (!usage.apply(st.usageView)) { st.usageView = was; return; }
836
- for (const agent of st.usageView.task.agents || []) {
938
+ for (const agent of st.usageView.task?.agents || []) {
837
939
  if (agent.scope !== 'run' || !agent.runId) continue;
838
940
  const tokens = agent.tokens || null;
839
941
  const fidelity = agent.fidelity || st.usageView.task.fidelity;
840
942
  dock.patchUsageRun(agent.runId, tokens, fidelity);
841
943
  renderer.patchRunUsage(agent.runId, tokens, fidelity);
944
+ if (Number.isSafeInteger(tokens?.total)) steer.onRunTokens(agent.runId, tokens.total);
842
945
  }
843
946
  persist();
844
947
  }
@@ -953,6 +1056,7 @@ export function mountAssistant(viewport, { sessionId, brain, host = {}, session
953
1056
  lockControl(packet.request_id, resolvedLabel(packet.origin, tt('assistant.control.state.answered', 'Answered')));
954
1057
  return;
955
1058
  case 'reattach_result':
1059
+ rebuildBg();
956
1060
  // Whether a turn runs now: a route the journal left open is that turn's, or nobody's.
957
1061
  renderer.reattached(!!(packet.ok && packet.running));
958
1062
  if (packet.ok) {
@@ -971,6 +1075,11 @@ export function mountAssistant(viewport, { sessionId, brain, host = {}, session
971
1075
  case 'stderr':
972
1076
  if (packet.text?.trim()) renderer.appendStatus(packet.text.trim());
973
1077
  return;
1078
+ case 'steered':
1079
+ // The brain's turn was cut by a steer (lib/assistant-runtime.js: { target: 'brain', text, at }): one notice
1080
+ // where it was cut (this window's own steer drew it already), from the journal too.
1081
+ steer.onSteered(packet);
1082
+ return;
974
1083
  case 'turn_started':
975
1084
  // The CLI began a turn on its own (a background agent finished, a
976
1085
  // scheduled wakeup fired); its `done` finishes it.
@@ -1032,6 +1141,7 @@ export function mountAssistant(viewport, { sessionId, brain, host = {}, session
1032
1141
  applySessionMeta(packet.session || packet);
1033
1142
  return;
1034
1143
  case 'assistant:dispatch': {
1144
+ steer.onSteered(packet); // a 'steered' run event rides here too
1035
1145
  const run = runFromPayload(packet);
1036
1146
  if (run) { dock.upsertRun(run); renderer.upsertRunCard(dock.getRun(run.runId) || run); tip('run', () => renderer.getRunCard(run.runId)); }
1037
1147
  return;
@@ -1073,6 +1183,8 @@ export function mountAssistant(viewport, { sessionId, brain, host = {}, session
1073
1183
  if (!ev?.type) return;
1074
1184
  // One registry for what is on screen (the renderer's): the journal snapshot registers there too.
1075
1185
  if (!renderer.claimEvent(ev)) return;
1186
+ // The Background tasks registry hears every live event; a replayed one is history (the rebuild reads it).
1187
+ if (!replaying && bgClaude() && bgRelevant(ev)) feedBg(ev);
1076
1188
  const draw = (event) => renderer.handleEvent(event, replaying ? { replay: true } : undefined);
1077
1189
  switch (ev.type) {
1078
1190
  case 'synabun.dispatch': {
@@ -1117,6 +1229,11 @@ export function mountAssistant(viewport, { sessionId, brain, host = {}, session
1117
1229
  case 'synabun.cost':
1118
1230
  applyCost(ev);
1119
1231
  return;
1232
+ case 'steered':
1233
+ case 'synabun.steered':
1234
+ // The brain's turn was cut by a steer (this window's, another's, WhatsApp's): one notice where it was cut.
1235
+ if (!replaying) steer.onSteered(ev);
1236
+ return;
1120
1237
  default:
1121
1238
  draw(ev);
1122
1239
  }
@@ -1567,6 +1684,147 @@ export function mountAssistant(viewport, { sessionId, brain, host = {}, session
1567
1684
  syncBlocked();
1568
1685
  }
1569
1686
 
1687
+ // ── Steer: redirect work under way (asst-steer.js) ──
1688
+ const steerT = steerTranslator(t, getLocale());
1689
+ let steerAvailable = true; // an older server answers without the route: then Enter while busy queues
1690
+ /** The kinds of the transcript rows above `row`, nearest first (steerBreakBefore reads them). */
1691
+ function rowKindsAbove(row, max = 6) {
1692
+ const kinds = [];
1693
+ for (let node = row?.previousElementSibling; node && kinds.length < max; node = node.previousElementSibling) {
1694
+ const c = node.classList;
1695
+ // The cut turn's own rows under its reply (its usage / automation line, a route line) are 'route'.
1696
+ kinds.push(c.contains('msg-assistant') ? 'assistant' : c.contains('asst-divider') ? 'divider' : c.contains('msg-user') ? 'user' : c.contains('asst-status') ? 'status' : c.contains('asst-route-line') ? 'route' : 'other');
1697
+ }
1698
+ return kinds;
1699
+ }
1700
+ /** "#2 Fix the login bug": the run as the tray numbers it. */
1701
+ function runLabelOf(run) {
1702
+ if (!run) return '';
1703
+ const index = dock.getRuns().findIndex((r) => r.runId === run.runId);
1704
+ const title = String(run.title || run.task || run.runId || '').replace(/\s+/g, ' ').trim().slice(0, 60);
1705
+ return index >= 0 ? `#${index + 1} ${title}` : title;
1706
+ }
1707
+ function steerNotice(text, { kind = 'steer', action = null, cut = false, quiet = false } = {}) {
1708
+ const row = renderer.appendStatus(text, kind === 'steer' ? 'info' : kind === 'error' ? 'error' : 'warn');
1709
+ if (!row) return null;
1710
+ // A steer that cut the Assistant's own reply: a break between that reply and what follows (asst-state.js).
1711
+ if (steerBreakBefore({ kind, cut, prevKinds: rowKindsAbove(row) })) {
1712
+ const rule = document.createElement('div');
1713
+ rule.className = 'asst-divider asst-steer-break';
1714
+ rule.setAttribute('role', 'separator');
1715
+ row.before(rule);
1716
+ }
1717
+ row.classList.add('asst-steer-notice');
1718
+ row.dataset.steer = kind;
1719
+ if (action?.label && typeof action.run === 'function') {
1720
+ const button = document.createElement('button');
1721
+ button.type = 'button';
1722
+ button.className = 'asst-btn asst-btn-secondary asst-steer-retry';
1723
+ button.textContent = action.label;
1724
+ button.addEventListener('click', async () => {
1725
+ button.disabled = true;
1726
+ const outcome = await action.run();
1727
+ if (outcome === false) button.disabled = false;
1728
+ else button.remove();
1729
+ });
1730
+ row.appendChild(button);
1731
+ }
1732
+ if (!quiet) announce(text);
1733
+ return row;
1734
+ }
1735
+ /** A steer read from the journal (asst-render.js drawSteer): what the live view drew for it, in the same order. */
1736
+ function steerEntry({ target = 'brain', runId = null, title = '', text = '', cut = false } = {}) {
1737
+ if (!String(text).trim()) return;
1738
+ if (target === 'run') {
1739
+ const run = runId ? dock.getRun(runId) : null;
1740
+ steerNotice(steerNoticeText(text, steerT, { run: runLabelOf(run) || String(title || runId || '').slice(0, 60) }), { kind: 'steer', quiet: true });
1741
+ return;
1742
+ }
1743
+ // The cut turn ended "Interrupted." live (its 'aborted' is not journaled), above that turn's usage / route lines;
1744
+ // a saved one there already is not drawn twice.
1745
+ if (cut) {
1746
+ const aborted = tt('assistant.status.aborted', 'Aborted.');
1747
+ const row = renderer.appendStatus(aborted);
1748
+ let above = row?.previousElementSibling || null;
1749
+ let firstRoute = null;
1750
+ while (above?.classList.contains('asst-route-line')) { firstRoute = above; above = above.previousElementSibling; }
1751
+ if (row && above?.classList.contains('asst-status') && String(above.textContent || '').trim() === aborted) row.remove();
1752
+ else if (row && firstRoute) firstRoute.before(row);
1753
+ }
1754
+ steerNotice(steerNoticeText(text, steerT), { kind: 'steer', cut, quiet: true });
1755
+ }
1756
+ // The controller is made once asst-steer.js has loaded (steerModule); until then `steer` waits for the load, and a
1757
+ // load that fails leaves the plain path: the words are sent, or queued behind the turn that runs.
1758
+ let steerCtl = null;
1759
+ const makeSteer = ({ createSteerController, postSteer }) => (steerCtl ||= createSteerController({
1760
+ t: steerT,
1761
+ sessionId: () => sessionId,
1762
+ isRunning: () => st.running,
1763
+ steerable: () => steerAvailable,
1764
+ setSteerable: (value) => { steerAvailable = value !== false; composer.setSteerable(steerAvailable); },
1765
+ post: (body) => postSteer(body),
1766
+ queue: (payload) => { st.queue.push(payload); composer.setQueue(st.queue); return 'queued'; },
1767
+ send: (payload) => (sendQuery(payload) ? 'sent' : false),
1768
+ promptText: (payload) => buildPromptText(payload),
1769
+ getRun: (runId) => dock.getRun(runId),
1770
+ runLabel: runLabelOf,
1771
+ patchRun: (runId, patch) => { const run = dock.patchRun(runId, patch); if (run) renderer.syncRun(run); return run; },
1772
+ setActivity: (runId, activity) => { renderer.setRunActivity(runId, activity); dock.setRunActivity(runId, activity); },
1773
+ notice: steerNotice,
1774
+ setTarget: (target, text = '') => {
1775
+ composer.setSteerTarget(target);
1776
+ if (target && text && !composer.getText().trim()) composer.setText(text);
1777
+ },
1778
+ focusComposer: () => composer.focus(),
1779
+ }));
1780
+ const steerNow = () => steerCtl || (steerModule.module ? makeSteer(steerModule.module) : null);
1781
+ const steerLoaded = () => steerModule.load().then(makeSteer);
1782
+ /** Run `fn(controller)` now when it is there, else after the load (in order); nothing when the load fails. */
1783
+ const withSteer = (fn) => {
1784
+ const ctl = steerNow();
1785
+ if (ctl) return fn(ctl);
1786
+ steerLoaded().then((c) => { if (!destroyed) fn(c); }, () => {});
1787
+ return undefined;
1788
+ };
1789
+ const steerUnavailable = (err) => steerNotice(steerT('failed', { error: err?.message || String(err || '?') }), { kind: 'error' });
1790
+ const steer = {
1791
+ async submit(payload) {
1792
+ let ctl = steerNow();
1793
+ if (!ctl) {
1794
+ try { ctl = await steerLoaded(); } catch (err) {
1795
+ if (payload.steerTarget?.runId) { steerUnavailable(err); return false; } // the words stay in the composer
1796
+ if (st.running) { st.queue.push(payload); composer.setQueue(st.queue); return 'queued'; }
1797
+ return sendQuery(payload) ? 'sent' : false;
1798
+ }
1799
+ }
1800
+ return ctl.submit(payload);
1801
+ },
1802
+ async steerRun(runId, text) {
1803
+ let ctl = steerNow();
1804
+ if (!ctl) { try { ctl = await steerLoaded(); } catch (err) { steerUnavailable(err); return false; } }
1805
+ return ctl.steerRun(runId, text);
1806
+ },
1807
+ targetRun: (runId, text, opts) => withSteer((ctl) => ctl.targetRun(runId, text, opts)),
1808
+ // Before the load nothing of this panel is marked steering: the packet is read once the controller is there.
1809
+ onSteered: (packet) => withSteer((ctl) => ctl.onSteered(packet)) === true,
1810
+ onTurnStarted: (runId) => withSteer((ctl) => ctl.onTurnStarted(runId)) === true,
1811
+ // Only a loaded controller has marked a run: before the load there is nothing to take away.
1812
+ onRunOutput: (runId, payload, activity) => steerNow()?.onRunOutput(runId, payload, activity) === true,
1813
+ onRunTokens: (runId, total) => steerNow()?.onRunTokens(runId, total) === true,
1814
+ };
1815
+ /** The card's one-line input: true when the steer went (the input closes). */
1816
+ async function steerRunFromCard(runId, text) {
1817
+ const outcome = await steer.steerRun(runId, text);
1818
+ const went = outcome === 'steered' || outcome === 'ended';
1819
+ if (went) composer.focus(); // the input closes: focus goes back to the composer
1820
+ return went;
1821
+ }
1822
+ /** The card hands its run to the composer: the next message steers it. */
1823
+ function steerTargetFromCard(runId, text = '') {
1824
+ const index = dock.getRuns().findIndex((r) => r.runId === runId);
1825
+ return steer.targetRun(runId, text, { index: index >= 0 ? index + 1 : null });
1826
+ }
1827
+
1570
1828
  // ── Sending ──
1571
1829
  function sendQuery(payload) {
1572
1830
  if (guestBlocked()) return false;
@@ -1615,11 +1873,9 @@ export function mountAssistant(viewport, { sessionId, brain, host = {}, session
1615
1873
  const handled = await runSlash(parsed, payload);
1616
1874
  return handled === false ? false : 'sent';
1617
1875
  }
1618
- if (st.running) {
1619
- st.queue.push(payload);
1620
- composer.setQueue(st.queue);
1621
- return 'queued';
1622
- }
1876
+ // Steer (asst-steer.js): Enter while a turn runs cuts it and sends now, a targeted run is steered,
1877
+ // Queue (Alt+Enter, or a server that cannot steer) waits for the turn as before.
1878
+ if (payload.mode || payload.steerTarget || st.running) return steer.submit(payload);
1623
1879
  return sendQuery(payload) ? 'sent' : false;
1624
1880
  }
1625
1881
 
@@ -2309,6 +2565,10 @@ export function mountAssistant(viewport, { sessionId, brain, host = {}, session
2309
2565
  surfaces.forEach((node) => node.addEventListener('focusin', onFocusIn));
2310
2566
 
2311
2567
  // ── Bus ──
2568
+ // A panel banner has no transcript row, focus change, sound or effect on the running turn.
2569
+ if (!isGuest()) void import('../browser-extension-updates.js').then(({ watchExtensionUpdateMention }) => {
2570
+ if (!destroyed) unsubs.push(watchExtensionUpdateMention(t, (text, action) => banner('extension-update', text, { tone: 'info', action })));
2571
+ }).catch(error => console.warn('[assistant] Browser extension notice unavailable:', error.message));
2312
2572
  unsubs.push(on('sync:assistant:session-updated', (msg) => { const s = msg?.session || msg; if (s?.id === sessionId) applySessionMeta(s); }));
2313
2573
  unsubs.push(on('sync:assistant:budget', (msg) => { if ((msg?.assistantSessionId || msg?.sessionId) === sessionId) budgetController.receiveSession(msg.budget); }));
2314
2574
  unsubs.push(on('sync:assistant:budget-changed', () => budgetController.load()));
@@ -2342,12 +2602,26 @@ export function mountAssistant(viewport, { sessionId, brain, host = {}, session
2342
2602
  unsubs.push(on('sync:sidepanel:provider-event', (msg) => {
2343
2603
  const runId = msg?.run?.runId;
2344
2604
  if (!runId || !dock.getRun(runId)) return;
2605
+ // A steered run's next turn begins: "Steering…" goes, it works as usual.
2606
+ const evType = msg.event?.type;
2607
+ if (evType === 'turn_started' || evType === 'turn.started' || (evType === 'system' && msg.event?.subtype === 'init')) steer.onTurnStarted(runId);
2608
+ if (steer.onSteered(msg.event ? { ...msg.event, runId } : null)) return;
2345
2609
  const activity = activityOf(msg.event);
2610
+ // The steer's turn shows something (text, a call, thinking): "Steering…" goes.
2611
+ steer.onRunOutput(runId, msg.event, activity);
2346
2612
  if (!activity) return;
2347
2613
  const stamped = { ...activity, at: Date.now() };
2348
2614
  renderer.setRunActivity(runId, stamped);
2349
2615
  dock.setRunActivity(runId, stamped);
2350
2616
  }));
2617
+ // A run of this session steered (here, in another window, by the brain's agent_send steer:true): "Steering…" and
2618
+ // the notice, once. The run event may come on its own or inside a dispatch update.
2619
+ for (const name of ['sync:assistant:steered', 'sync:assistant:run-steered', 'sync:assistant:dispatch']) {
2620
+ unsubs.push(on(name, (msg) => {
2621
+ const owned = !msg?.assistantSessionId || msg.assistantSessionId === sessionId;
2622
+ if (owned) steer.onSteered(name === 'sync:assistant:dispatch' ? msg : { ...msg, type: 'steered' });
2623
+ }));
2624
+ }
2351
2625
  unsubs.push(on('sync:assistant:desktop', (msg) => computerPanel.applyDesktop(msg)));
2352
2626
  unsubs.push(on('sync:assistant:desktop-setup', (msg) => computerPanel.applySetup(msg)));
2353
2627
  // Models switched on/off elsewhere: the open Models manager reloads (the menus drop their cache on their own).
@@ -2517,13 +2791,14 @@ export function mountAssistant(viewport, { sessionId, brain, host = {}, session
2517
2791
  /** The session's status as its host shows it: the brain's own with its dispatched agents' (sessionStatus). */
2518
2792
  getStatus: () => st.shownStatus || 'idle',
2519
2793
  focus: () => composer.focus(),
2520
- onShown: () => { loadConversation(); syncTabLabel(); renderer.scrollEnd(true); if (visible()) composer.focus(); director.touch(); },
2794
+ onShown: () => { loadConversation(); syncTabLabel(); renderer.scrollEnd(true); if (visible()) composer.focus(); director.touch(); rebuildBg(); },
2521
2795
  /** The tab is wanted (shown, or about to be used): its conversation loads now instead of in idle time. */
2522
2796
  wake: () => loadConversation(),
2523
2797
  onHidden: () => { closeMenu(); picker.close(); director.stopTyping(); },
2524
2798
  counts: () => dock.counts(),
2525
2799
  destroy: ({ closeServer = false } = {}) => {
2526
2800
  if (destroyed) return;
2801
+ try { bg?.dispose({ forget: closeServer }); } catch { /* ignore */ }
2527
2802
  destroyed = true;
2528
2803
  cancelIdleLoad?.();
2529
2804
  cancelIdleLoad = null;