synabun 2.4.3 → 2.4.5

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 (177) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/README.md +1 -1
  3. package/docs/browser-extension-bridge.md +66 -36
  4. package/docs/whatsapp.md +3 -3
  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 +12 -1
  21. package/mcp-server/dist/services/neural-interface.d.ts.map +1 -1
  22. package/mcp-server/dist/services/neural-interface.js +68 -17
  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 +19 -4
  30. package/mcp-server/dist/tools/agents.d.ts.map +1 -1
  31. package/mcp-server/dist/tools/agents.js +85 -17
  32. package/mcp-server/dist/tools/agents.js.map +1 -1
  33. package/mcp-server/dist/tools/browser-observe.d.ts +11 -0
  34. package/mcp-server/dist/tools/browser-observe.d.ts.map +1 -1
  35. package/mcp-server/dist/tools/browser-observe.js +113 -27
  36. package/mcp-server/dist/tools/browser-observe.js.map +1 -1
  37. package/mcp-server/dist/tools/browser-readers.d.ts +6 -0
  38. package/mcp-server/dist/tools/browser-readers.d.ts.map +1 -0
  39. package/mcp-server/dist/tools/browser-readers.js +17 -0
  40. package/mcp-server/dist/tools/browser-readers.js.map +1 -0
  41. package/mcp-server/dist/tools/remember.d.ts.map +1 -1
  42. package/mcp-server/dist/tools/remember.js +6 -2
  43. package/mcp-server/dist/tools/remember.js.map +1 -1
  44. package/mcp-server/dist/tools/youtube/analytics.d.ts +4 -0
  45. package/mcp-server/dist/tools/youtube/analytics.d.ts.map +1 -1
  46. package/mcp-server/dist/tools/youtube/analytics.js +25 -20
  47. package/mcp-server/dist/tools/youtube/analytics.js.map +1 -1
  48. package/mcp-server/dist/tools/youtube/helpers.d.ts +5 -1
  49. package/mcp-server/dist/tools/youtube/helpers.d.ts.map +1 -1
  50. package/mcp-server/dist/tools/youtube/helpers.js +7 -3
  51. package/mcp-server/dist/tools/youtube/helpers.js.map +1 -1
  52. package/mcp-server/dist/tools/youtube/navigate.d.ts +2 -0
  53. package/mcp-server/dist/tools/youtube/navigate.d.ts.map +1 -1
  54. package/mcp-server/dist/tools/youtube/navigate.js +5 -3
  55. package/mcp-server/dist/tools/youtube/navigate.js.map +1 -1
  56. package/mcp-server/dist/tools/youtube/playlist.js +2 -2
  57. package/mcp-server/dist/tools/youtube/playlist.js.map +1 -1
  58. package/mcp-server/dist/tools/youtube/readers.d.ts +4 -0
  59. package/mcp-server/dist/tools/youtube/readers.d.ts.map +1 -0
  60. package/mcp-server/dist/tools/youtube/readers.js +15 -0
  61. package/mcp-server/dist/tools/youtube/readers.js.map +1 -0
  62. package/mcp-server/package-lock.json +2 -2
  63. package/mcp-server/package.json +1 -1
  64. package/mcp-server/src/http.ts +8 -1
  65. package/mcp-server/src/services/identity.ts +5 -0
  66. package/mcp-server/src/services/memory-client.ts +32 -12
  67. package/mcp-server/src/services/memory-writer.ts +5 -2
  68. package/mcp-server/src/services/neural-interface.ts +67 -19
  69. package/mcp-server/src/services/typesafe-config.ts +268 -7
  70. package/mcp-server/src/tools/agents.ts +79 -17
  71. package/mcp-server/src/tools/browser-observe.ts +117 -28
  72. package/mcp-server/src/tools/browser-readers.ts +19 -0
  73. package/mcp-server/src/tools/remember.ts +6 -1
  74. package/mcp-server/src/tools/youtube/analytics.ts +26 -28
  75. package/mcp-server/src/tools/youtube/helpers.ts +8 -2
  76. package/mcp-server/src/tools/youtube/navigate.ts +6 -7
  77. package/mcp-server/src/tools/youtube/playlist.ts +2 -2
  78. package/mcp-server/src/tools/youtube/readers.ts +15 -0
  79. package/neural-interface/i18n/en.json +487 -8
  80. package/neural-interface/i18n/pt-BR.json +487 -8
  81. package/neural-interface/lib/agents-studio-api.js +7 -2
  82. package/neural-interface/lib/antigravity/home.js +43 -8
  83. package/neural-interface/lib/antigravity/tool-call.js +14 -0
  84. package/neural-interface/lib/assistant-api.js +90 -0
  85. package/neural-interface/lib/assistant-brains/antigravity.js +4 -2
  86. package/neural-interface/lib/assistant-brains/claude.js +10 -0
  87. package/neural-interface/lib/assistant-dispatch.js +276 -42
  88. package/neural-interface/lib/assistant-memory.js +3 -1
  89. package/neural-interface/lib/assistant-persona.js +14 -3
  90. package/neural-interface/lib/assistant-route-gate.js +11 -2
  91. package/neural-interface/lib/assistant-router.js +18 -8
  92. package/neural-interface/lib/assistant-runtime.js +103 -6
  93. package/neural-interface/lib/assistant-spilled-output.js +53 -0
  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-default.js +22 -2
  97. package/neural-interface/lib/browser-extension-adapter.js +221 -15
  98. package/neural-interface/lib/browser-extension-bridge.js +89 -9
  99. package/neural-interface/lib/browser-extension-folder.js +50 -11
  100. package/neural-interface/lib/browser-extension-package.js +6 -5
  101. package/neural-interface/lib/browser-extension-pin.json +15 -13
  102. package/neural-interface/lib/browser-extension-protocol.js +141 -14
  103. package/neural-interface/lib/browser-extension-setup.js +210 -40
  104. package/neural-interface/lib/browser-extension-update.js +104 -0
  105. package/neural-interface/lib/browser-extraction.js +38 -14
  106. package/neural-interface/lib/claude-bg-tasks.js +183 -0
  107. package/neural-interface/lib/claude-history.js +12 -1
  108. package/neural-interface/lib/confined-fs.js +25 -0
  109. package/neural-interface/lib/coordination/operations.js +2 -0
  110. package/neural-interface/lib/db.js +39 -16
  111. package/neural-interface/lib/editor-completion-opencode.js +2 -2
  112. package/neural-interface/lib/git-bash/manager.js +28 -3
  113. package/neural-interface/lib/git-status-runner.js +31 -3
  114. package/neural-interface/lib/loop-inventory.js +162 -0
  115. package/neural-interface/lib/loop-stall.js +74 -4
  116. package/neural-interface/lib/memory-session-capture.js +157 -66
  117. package/neural-interface/lib/native-loop-providers.js +73 -13
  118. package/neural-interface/lib/native-loop-runtime.js +3 -0
  119. package/neural-interface/lib/opencode-protocol.js +4 -2
  120. package/neural-interface/lib/peer-identity.js +62 -16
  121. package/neural-interface/lib/remote-policy.js +24 -7
  122. package/neural-interface/lib/session-cache-builder.js +66 -18
  123. package/neural-interface/lib/session-capture-gate.js +42 -0
  124. package/neural-interface/lib/session-indexer.js +28 -20
  125. package/neural-interface/lib/teams/README.md +22 -1
  126. package/neural-interface/lib/teams/api.js +79 -6
  127. package/neural-interface/lib/teams/index.js +2 -0
  128. package/neural-interface/lib/teams/recovery.js +68 -0
  129. package/neural-interface/lib/teams/scheduler.js +352 -31
  130. package/neural-interface/lib/teams/worktrees.js +123 -30
  131. package/neural-interface/lib/ui-blob-api.js +14 -5
  132. package/neural-interface/lib/ui-blob-store.js +302 -39
  133. package/neural-interface/package-lock.json +2 -2
  134. package/neural-interface/package.json +1 -1
  135. package/neural-interface/public/extension-setup.html +7 -2
  136. package/neural-interface/public/shared/agents/studio/ax-api.js +16 -0
  137. package/neural-interface/public/shared/agents/studio/ax-teams-view.js +318 -13
  138. package/neural-interface/public/shared/agents/studio/ax-teams.js +141 -9
  139. package/neural-interface/public/shared/assistant/asst-agents-dock.js +4 -0
  140. package/neural-interface/public/shared/assistant/asst-api.js +42 -0
  141. package/neural-interface/public/shared/assistant/asst-composer.js +85 -12
  142. package/neural-interface/public/shared/assistant/asst-panel.js +285 -10
  143. package/neural-interface/public/shared/assistant/asst-render.js +205 -4
  144. package/neural-interface/public/shared/assistant/asst-scenes.js +12 -0
  145. package/neural-interface/public/shared/assistant/asst-sidepanel.js +18 -1
  146. package/neural-interface/public/shared/assistant/asst-state.js +241 -2
  147. package/neural-interface/public/shared/assistant/asst-steer.js +294 -0
  148. package/neural-interface/public/shared/assistant/asst-styles.js +20 -0
  149. package/neural-interface/public/shared/bg-tasks/bg-tasks-claude.js +147 -0
  150. package/neural-interface/public/shared/bg-tasks/bg-tasks-model.js +527 -0
  151. package/neural-interface/public/shared/bg-tasks/bg-tasks-panel.js +161 -0
  152. package/neural-interface/public/shared/bg-tasks/bg-tasks-view.js +508 -0
  153. package/neural-interface/public/shared/browser-extension-updates.js +90 -0
  154. package/neural-interface/public/shared/cp/cp-bg-tasks.js +130 -0
  155. package/neural-interface/public/shared/extension-setup/es-page.js +41 -15
  156. package/neural-interface/public/shared/extension-setup/es-view.js +51 -11
  157. package/neural-interface/public/shared/extension-update-view.js +34 -0
  158. package/neural-interface/public/shared/ocp-v2/ocp-v2-shell-logic.js +8 -4
  159. package/neural-interface/public/shared/settings/settings-ai-browser.js +23 -3
  160. package/neural-interface/public/shared/settings/settings-browser-extension.js +581 -197
  161. package/neural-interface/public/shared/settings/settings-extension-diagrams.js +116 -0
  162. package/neural-interface/public/shared/settings/settings-extension-guide.js +222 -0
  163. package/neural-interface/public/shared/settings/settings-extension-update.js +114 -0
  164. package/neural-interface/public/shared/settings/settings-ia.js +2 -2
  165. package/neural-interface/public/shared/settings/settings-shell.js +5 -0
  166. package/neural-interface/public/shared/styles.css +200 -13
  167. package/neural-interface/public/shared/ui-claude-panel.js +110 -1
  168. package/neural-interface/public/shared/ui-notifications.js +23 -4
  169. package/neural-interface/public/shared/ui-settings-entry.js +6 -0
  170. package/neural-interface/public/shared/ui-settings.js +48 -11
  171. package/neural-interface/public/shared/ui-tray-columns.js +9 -2
  172. package/neural-interface/public/shared/worker-end.js +18 -0
  173. package/neural-interface/scripts/patch-node-pty.mjs +151 -0
  174. package/neural-interface/scripts/rebuild-pty.js +10 -0
  175. package/neural-interface/server.js +503 -281
  176. package/npm-shrinkwrap.json +2 -2
  177. package/package.json +1 -1
@@ -58,6 +58,7 @@ import { STAGE_TIMING, createWorkerStage } from './asst-run-stage.js';
58
58
  import { SETTLE_FRAMES, createMotionGate } from './asst-motion-gate.js';
59
59
  import { createStyleCache } from './asst-style-cache.js';
60
60
  import { formatRunTokens } from './asst-usage.js';
61
+ import { canSteerRun, isSteeredEnd, isSteering, steerPromptText, steerTranslator } from './asst-state.js'; // steer's boot part (asst-steer.js loads on demand)
61
62
  import { sanitizeHtmlString, sanitizeInto } from './asst-sanitize.js';
62
63
  import { decorateCodeBlocks } from '../ui-code-copy.js';
63
64
  import { decorateOutput } from '../ui-output.js';
@@ -129,6 +130,7 @@ const INTERRUPTED_RE = /\b(?:interrupted|aborted|cancell?ed)\b/i;
129
130
  */
130
131
  export function resultErrorText(ev, t = (_key, fallback) => fallback) {
131
132
  if (!ev || (!ev.is_error && !String(ev.subtype || '').startsWith('error'))) return '';
133
+ if (isSteeredEnd(ev)) return ''; // a turn a steer cut is never a failure (asst-steer.js)
132
134
  if (String(ev.terminal_reason || '').startsWith('aborted')) return '';
133
135
  if (typeof ev.result === 'string' && ev.result.trim()) return ev.result.trim();
134
136
  const errors = Array.isArray(ev.errors) ? ev.errors.filter((x) => typeof x === 'string' && x.trim()) : [];
@@ -167,6 +169,74 @@ function memoryTitle(memory) {
167
169
  return String(raw || '').replace(/^#+\s*/, '').slice(0, 60) || memory?.id || 'memory';
168
170
  }
169
171
 
172
+ // ── Steer (asst-steer.js) ───────────────────────────────────────────────────
173
+ // A turning arrow: the run goes on, another way.
174
+ const ICON_STEER = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 18v-5a5 5 0 0 1 5-5h11"/><path d="m16 4 4 4-4 4"/></svg>';
175
+ const ICON_CLOSE_SMALL = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="M18 6 6 18M6 6l12 12"/></svg>';
176
+
177
+ /**
178
+ * The one-line steer input under a run card: Enter (its form's submit) sends it to the run (onSubmit(runId, text) →
179
+ * truthy when it went), Esc or Cancel closes it; "Write it in the composer" hands the run (and what was typed) to
180
+ * the composer's target chip instead. Focus goes into the input, and back to the card's Steer button when it closes
181
+ * without sending.
182
+ */
183
+ export function openRunSteerInput(card, { t: pageT = null, locale = null, onSubmit = null, onUseComposer = null } = {}) {
184
+ if (!card) return null;
185
+ const existing = card.querySelector(':scope > .asst-run-steer');
186
+ if (existing) { existing.querySelector('input')?.focus(); return existing; }
187
+ const st8 = steerTranslator(pageT, typeof locale === 'function' ? locale() : locale);
188
+ const box = el('form', 'asst-run-steer');
189
+ box.setAttribute('role', 'group');
190
+ box.setAttribute('aria-label', st8('runSteer'));
191
+ box.innerHTML = `<input type="text" class="asst-run-steer-input" autocomplete="off" spellcheck="true" aria-label="${esc(st8('runSteerPlaceholder'))}" placeholder="${esc(st8('runSteerPlaceholder'))}">`
192
+ + `<button type="submit" class="asst-btn asst-run-steer-send">${esc(st8('runSteerSend'))}</button>`
193
+ + (typeof onUseComposer === 'function' ? `<button type="button" class="asst-tb-btn asst-run-steer-composer" aria-label="${esc(st8('useComposer'))}" data-tooltip="${esc(st8('useComposer'))}">${ICON_STEER}</button>` : '')
194
+ + `<button type="button" class="asst-tb-btn asst-run-steer-cancel" aria-label="${esc(st8('runSteerCancel'))}" data-tooltip="${esc(st8('runSteerCancel'))}">${ICON_CLOSE_SMALL}</button>`;
195
+ const input = box.querySelector('input');
196
+ const close = ({ refocus = true } = {}) => {
197
+ box.remove();
198
+ if (refocus) card.querySelector('[data-action="steer"]')?.focus();
199
+ };
200
+ let sending = false;
201
+ const send = async () => {
202
+ const text = input.value.trim();
203
+ if (!text || sending) return;
204
+ sending = true;
205
+ input.disabled = true;
206
+ let ok = false;
207
+ try { ok = await onSubmit?.(card.dataset.runId, text); } catch { ok = false; }
208
+ sending = false;
209
+ input.disabled = false;
210
+ if (ok) close({ refocus: false });
211
+ else input.focus();
212
+ };
213
+ box.addEventListener('submit', (e) => { e.preventDefault(); send(); });
214
+ // Enter is read here, on the input itself, never left to the form's implicit submission: a handler of the page
215
+ // that cancels Enter (a capture-phase keydown of the document, the panel's) would stop that submission silently.
216
+ input.addEventListener('keydown', (e) => {
217
+ if (e.key !== 'Enter' || e.isComposing || e.keyCode === 229 || e.shiftKey || e.altKey) return;
218
+ e.preventDefault();
219
+ e.stopPropagation();
220
+ send();
221
+ });
222
+ box.addEventListener('keydown', (e) => {
223
+ e.stopPropagation(); // single-letter global keybinds stay out of the input
224
+ if (e.key === 'Escape') { e.preventDefault(); close(); }
225
+ });
226
+ box.addEventListener('click', (e) => e.stopPropagation());
227
+ box.querySelector('.asst-run-steer-cancel').addEventListener('click', () => close());
228
+ box.querySelector('.asst-run-steer-composer')?.addEventListener('click', () => {
229
+ const text = input.value;
230
+ close({ refocus: false });
231
+ onUseComposer(card.dataset.runId, text);
232
+ });
233
+ box._send = send; // tests
234
+ const meta = card.querySelector(':scope > .asst-run-meta');
235
+ if (meta) meta.after(box); else card.appendChild(box);
236
+ input.focus();
237
+ return box;
238
+ }
239
+
170
240
  // ── Run cards (shared with the agents dock) ────────────────────────────────
171
241
 
172
242
  /**
@@ -201,6 +271,11 @@ export function buildRunCard(run, opts = {}) {
201
271
  };
202
272
  mk('focus', t('assistant.run.focus', 'Focus in sidepanel'), '<svg viewBox="0 0 24 24"><path d="M15 3h6v6"/><path d="M10 14 21 3"/><path d="M21 14v5a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5"/></svg>', opts.onFocus);
203
273
  mk('read', t('assistant.run.read', 'Read result'), '<svg viewBox="0 0 24 24"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><path d="M14 2v6h6"/><path d="M16 13H8M16 17H8"/></svg>', opts.onRead);
274
+ // Steer: a one-line input under the card, sent to this run (asst-steer.js; only while the run is not over).
275
+ if (typeof opts.onSteer === 'function') {
276
+ const st8 = steerTranslator(opts.t, opts.locale);
277
+ mk('steer', st8('runSteer'), ICON_STEER, () => openRunSteerInput(card, { t: opts.t, locale: opts.locale, onSubmit: opts.onSteer, onUseComposer: opts.onSteerInComposer }));
278
+ }
204
279
  mk('stop', t('assistant.run.stop', 'Stop run'), '<svg viewBox="0 0 24 24"><rect x="6" y="6" width="12" height="12" rx="2"/></svg>', opts.onStop);
205
280
  // The agents tray only: a finished run can be removed from it.
206
281
  if (typeof opts.onRemove === 'function') mk('remove', t('assistant.run.remove', 'Remove from list'), '<svg viewBox="0 0 24 24"><path d="M3 6h18"/><path d="M8 6V4h8v2"/><path d="M19 6l-1 14H6L5 6"/></svg>', opts.onRemove).hidden = true;
@@ -287,6 +362,14 @@ export function updateRunCard(card, run, opts = {}) {
287
362
  if (removeBtn) { removeBtn.hidden = !removable; removeBtn.disabled = !removable; }
288
363
  const readBtn = card.querySelector('[data-action="read"]');
289
364
  if (readBtn) readBtn.disabled = run.status === 'queued';
365
+ const steerBtn = card.querySelector('[data-action="steer"]');
366
+ if (steerBtn) {
367
+ const steerable = canSteerRun(run);
368
+ steerBtn.hidden = !steerable;
369
+ steerBtn.disabled = !steerable;
370
+ if (!steerable) card.querySelector(':scope > .asst-run-steer')?.remove();
371
+ }
372
+ card.classList.toggle('is-steering', isSteering(run));
290
373
 
291
374
  // A provider's usage limit stopped it: the waiting card, whose Retry now stands in for "Retry on" the same model.
292
375
  const limitShown = syncRunLimit(card, run, opts, t);
@@ -506,6 +589,7 @@ const SUGGESTION_KINDS = { computer: 'computer', web: 'web', fix: 'edit', skill:
506
589
  /**
507
590
  * createRenderer(transcriptEl, hooks)
508
591
  * hooks: { t, providerIcon(provider), providerColor(provider), onFocusRun, onStopRun, onReadRun, onEscalateRun,
592
+ * onSteerRun(runId, text) → truthy when sent, onSteerRunInComposer(runId, text), locale() (asst-steer.js),
509
593
  * onMemoryClick(id), onResult(ev), onInit(ev), onModeChanged(mode), copy(text),
510
594
  * emptySuggestions() → [{ id, label, template }], onSuggestion(template),
511
595
  * brainLabel() → string, onChangeRoutes(), onRouteEvent(ev) → bool (true = handled by an open card),
@@ -584,6 +668,16 @@ export function createRenderer(transcriptEl, hooks = {}) {
584
668
  const askCards = new Set(); // { el, presenter, isOpen(), onChange, seq }
585
669
  let askSeq = 0;
586
670
  let lastTextRow = null; // the newest root message since the user's last prompt: the one a guess reads
671
+ // Streamed rows a turn's end sealed, by message id: the message they are can still arrive after that end (a steer
672
+ // or a Stop cut the reply; Claude Code sends the cut message late) and then takes the row's place, never the end.
673
+ const sealedRows = new Map();
674
+ // A steer of the brain read from the journal: drawn where its prompt is (after what the cut turn still sent).
675
+ let pendingSteer = null;
676
+ // The journal's own sealedRows (a replay streams nothing): where each message of the turn being read was drawn, by
677
+ // id, and the messages of the turn a steer cut, whose final can still come after the steer's prompt.
678
+ let journalMsgs = new Map();
679
+ let cutMsgs = new Map();
680
+ let lastAssistantRow = null; // what the newest assistant event drew (the journal keeps where each message is)
587
681
 
588
682
  // ── Activity racks ──
589
683
  // Every burst of agent work (tool calls, thinking, short narration) is one
@@ -1174,6 +1268,11 @@ export function createRenderer(transcriptEl, hooks = {}) {
1174
1268
  if (!s?.row || !s.bodyEl || !s.textBuf.trim()) return;
1175
1269
  s.row.classList.remove('streaming');
1176
1270
  paintMessage(s.row, s.bodyEl, s.textBuf, { scope });
1271
+ s.row._turnSealed = true; // its turn ended: what is drawn after it belongs below the reply
1272
+ if (s.msgId) {
1273
+ sealedRows.set(s.msgId, { row: s.row, bodyEl: s.bodyEl, scope });
1274
+ while (sealedRows.size > 20) sealedRows.delete(sealedRows.keys().next().value);
1275
+ }
1177
1276
  }
1178
1277
 
1179
1278
  /** The stream's text row goes (the final message renders the text again). */
@@ -1358,14 +1457,31 @@ export function createRenderer(transcriptEl, hooks = {}) {
1358
1457
  const texts = content.filter(b => b?.type === 'text' && typeof b.text === 'string');
1359
1458
  const tools = content.filter(b => b?.type === 'tool_use' && b.name !== 'AskUserQuestion'); // AskUserQuestion: a control card
1360
1459
  const ctx = { msgId: message?.id || scope.msgId || null, claude: !!ev?.uuid };
1460
+ // The final message of a reply a turn's end already sealed (a steer cut it): its text goes into that row, where
1461
+ // the reply was, whatever was drawn after it and whatever streams now.
1462
+ const sealed = message?.id && scope.stream?.msgId !== message.id ? sealedRows.get(message.id) : null;
1463
+ if (sealed && sealed.scope === scope && sealed.row.isConnected && texts.length && !tools.length && !thinks.length) {
1464
+ const rawText = texts.map(b => b.text).join('\n');
1465
+ if (rawText.trim()) {
1466
+ sealed.row._text = rawText;
1467
+ paintMessage(sealed.row, sealed.bodyEl, rawText, { scope });
1468
+ (scope.kept ||= new Set()).add(textKey(rawText));
1469
+ }
1470
+ return sealed.row;
1471
+ }
1361
1472
  // Text and thinking replace what was streamed for them. A tool-only message
1362
1473
  // (Codex/OpenCode send each call mid-stream; the SDK one per block) keeps the
1363
1474
  // streamed text as a row and closes it, so later deltas start below.
1364
1475
  const s = scope.stream;
1365
1476
  const liveText = !!s?.textBuf.trim();
1366
1477
  const streamedThink = s?.think || null;
1478
+ // The streamed row's place: the message's text row takes it (rows drawn after it, such as a status, stay below).
1479
+ // A reply whose turn already ended (a steer or a Stop cut it, its final message came late): the message takes the
1480
+ // streamed row's place, above what the end drew ("Interrupted.", the usage line, the steer's notice).
1481
+ let slot = null;
1367
1482
  if (s) {
1368
1483
  flushStream(scope);
1484
+ if (texts.length && s.row?.isConnected && s.row._turnSealed) slot = s.row.nextElementSibling || null;
1369
1485
  if (texts.length) dropStreamText(scope);
1370
1486
  else if (s.row) {
1371
1487
  s.row.classList.remove('streaming');
@@ -1394,6 +1510,7 @@ export function createRenderer(transcriptEl, hooks = {}) {
1394
1510
  foldNarration(rack, null, rawMd.trim());
1395
1511
  } else row = textRow(scope, rawMd, ctx);
1396
1512
  }
1513
+ if (slot && row && slot.isConnected && slot.parentNode === row.parentNode && slot !== row) slot.before(row);
1397
1514
  const fresh = [];
1398
1515
  for (const block of tools) {
1399
1516
  const known = block.id ? stepsById.get(block.id) : null;
@@ -3413,6 +3530,9 @@ export function createRenderer(transcriptEl, hooks = {}) {
3413
3530
  onStop: hooks.onStopRun,
3414
3531
  onRead: hooks.onReadRun,
3415
3532
  onEscalate: hooks.onEscalateRun,
3533
+ onSteer: hooks.onSteerRun,
3534
+ onSteerInComposer: hooks.onSteerRunInComposer,
3535
+ locale: hooks.locale,
3416
3536
  onLimitWait: (run, limit) => limitDock.set(`run:${run.runId}`, limit ? {
3417
3537
  resetsAt: limit.resetsAt || null,
3418
3538
  since: Date.parse(limit.detectedAt || run.completedAt || '') || nowMs(),
@@ -4125,6 +4245,7 @@ export function createRenderer(transcriptEl, hooks = {}) {
4125
4245
  return true;
4126
4246
  case 'assistant': {
4127
4247
  const row = ev.message ? renderAssistant(ev.message, scope, ev) : null;
4248
+ lastAssistantRow = row;
4128
4249
  if (row && ev.error && row.classList.contains('asst-msg')) { // a synthetic API-error message
4129
4250
  row.classList.add('asst-msg-error');
4130
4251
  const content = Array.isArray(ev.message.content) ? ev.message.content : [];
@@ -4208,7 +4329,7 @@ export function createRenderer(transcriptEl, hooks = {}) {
4208
4329
  if (ev.run) upsertRunCard(ev.run, { result: ev.result ?? null });
4209
4330
  return true;
4210
4331
  case 'synabun.user_prompt':
4211
- if ((!silent || replayDraw) && ev.text) appendUser(ev.text, { origin: ev.origin || null, imageCount: ev.images });
4332
+ if ((!silent || replayDraw) && ev.text) userPrompt(String(ev.text), { origin: ev.origin || null, imageCount: ev.images });
4212
4333
  return true;
4213
4334
  case 'synabun.error':
4214
4335
  appendError(ev.message);
@@ -4308,12 +4429,14 @@ export function createRenderer(transcriptEl, hooks = {}) {
4308
4429
  let firstError = null;
4309
4430
  // The replay a reattach sends next repeats part of this window: planReplay leaves it out.
4310
4431
  snapshot = { keys: new Set(), at: -Infinity, seq: -Infinity };
4432
+ pendingSteer = null;
4311
4433
  for (const entry of list) {
4312
4434
  if (!entry || typeof entry !== 'object') continue;
4313
4435
  // An entry that cannot be drawn costs that entry, never the rest of the history.
4314
4436
  try { renderEntry(entry); } catch (err) { failed += 1; firstError ||= err; }
4315
4437
  }
4316
4438
  if (failed) console.warn(`[assistant] ${failed} of ${list.length} transcript entries could not be drawn`, firstError);
4439
+ { const was = muted; muted = true; try { flushPendingSteer(); } finally { muted = was; } }
4317
4440
  flushStream(rootScope);
4318
4441
  sealStreamRow(rootScope);
4319
4442
  if (rootScope.stream?.row) rootScope.stream.row.classList.remove('streaming');
@@ -4335,20 +4458,96 @@ export function createRenderer(transcriptEl, hooks = {}) {
4335
4458
  finally { muted = was.muted; clockAt = was.clockAt; }
4336
4459
  }
4337
4460
 
4461
+ /**
4462
+ * A steer read from the journal or a prompt that carries one, drawn as the live view drew it: the cut turn's
4463
+ * "Interrupted.", the break and the notice (hooks.onSteerEntry, the panel's), never the model's [SynaBun Steer] line.
4464
+ */
4465
+ function drawSteer(steer) {
4466
+ if (!steer) return;
4467
+ try { hooks.onSteerEntry?.(steer); } catch { /* the panel is gone */ }
4468
+ }
4469
+ function flushPendingSteer() {
4470
+ const steer = pendingSteer;
4471
+ pendingSteer = null;
4472
+ drawSteer(steer);
4473
+ }
4474
+ /** A user prompt row, or the steer it is (its words in the notice). */
4475
+ function userPrompt(text, opts = {}) {
4476
+ const steered = steerPromptText(text);
4477
+ if (steered === null) { flushPendingSteer(); appendUser(text, opts); return; }
4478
+ // Live (and in a reattach's replay) the 'steered' packet drew the notice already; from the journal
4479
+ // (renderTranscript) it waits here (pendingSteer).
4480
+ if (!muted || replayDraw) { pendingSteer = null; return; }
4481
+ const steer = pendingSteer || { target: 'brain', text: steered, cut: true };
4482
+ // The cut reply's final message can still follow (Claude Code sends it late): the steer is drawn once it is in.
4483
+ if (cutMsgs.size) { pendingSteer = { ...steer, prompted: true }; return; }
4484
+ pendingSteer = null;
4485
+ drawSteer(steer);
4486
+ }
4487
+
4488
+ /** The message an assistant journal entry carries, or null. */
4489
+ function journalMessage(packet, role) {
4490
+ if (packet.type === 'event') return packet.event?.type === 'assistant' ? packet.event.message || null : null;
4491
+ if (role === 'assistant') return packet.message || (packet.content ? packet : null);
4492
+ return null;
4493
+ }
4494
+
4495
+ /**
4496
+ * A late final of a reply a steer cut, read from the journal: it takes the place of what that message drew (its
4497
+ * partial text row goes, a thinking rack stays above it), as renderAssistant's sealed rows do live.
4498
+ */
4499
+ function drawCutFinal(msg, draw) {
4500
+ const anchor = cutMsgs.get(msg.id)?.anchor;
4501
+ const row = draw();
4502
+ if (!row || !anchor?.isConnected || row === anchor) return;
4503
+ anchor.after(row);
4504
+ if (anchor._msgId === msg.id && anchor.classList.contains('msg-assistant') && row._text) anchor.remove();
4505
+ // The cut turn's usage / route lines (journaled before this late final; a partial that drew no row anchors on
4506
+ // its own automation row) go under the reply, as live: the panel's steerEntry then puts "Interrupted." above them.
4507
+ const trailing = [];
4508
+ for (let above = row.previousElementSibling; above?.classList.contains('asst-route-line'); above = above.previousElementSibling) trailing.unshift(above);
4509
+ if (trailing.length) row.after(...trailing);
4510
+ cutMsgs.set(msg.id, { anchor: row });
4511
+ }
4512
+
4338
4513
  function drawEntry(entry) {
4339
4514
  const packet = entry.packet && typeof entry.packet === 'object' ? entry.packet : entry;
4340
4515
  const role = packet.role || packet.type;
4516
+ const msg = journalMessage(packet, role);
4517
+ if (msg?.id && cutMsgs.has(msg.id)) { drawCutFinal(msg, () => drawEntryRow(packet, role)); return; }
4518
+ // Anything else after the steer's prompt: the cut turn is over, its steer is drawn first.
4519
+ if (pendingSteer?.prompted) { cutMsgs = new Map(); flushPendingSteer(); }
4520
+ const row = drawEntryRow(packet, role);
4521
+ if (msg?.id) journalMsgs.set(msg.id, { anchor: row || $msgs.lastElementChild || null });
4522
+ }
4523
+
4524
+ /** One journal entry drawn; an assistant message gives back the row it drew. */
4525
+ function drawEntryRow(packet, role) {
4526
+ // A steer (lib/assistant-runtime.js steerBrain, a worker run's 'steered' event): the brain's waits for its prompt,
4527
+ // so what the cut turn still sent is drawn above it; a run's is drawn where it is.
4528
+ if (packet.type === 'steered' || packet.type === 'synabun.steered') {
4529
+ const text = String(packet.text ?? '').trim();
4530
+ if (!text) return;
4531
+ if (packet.target === 'run' || packet.runId) { flushPendingSteer(); drawSteer({ target: 'run', runId: packet.runId || null, title: packet.title || '', text, cut: false }); return; }
4532
+ flushPendingSteer();
4533
+ pendingSteer = { target: 'brain', text, cut: packet.interruptedTurn !== false };
4534
+ cutMsgs = pendingSteer.cut ? journalMsgs : new Map();
4535
+ journalMsgs = new Map();
4536
+ return;
4537
+ }
4341
4538
  if (role === 'query' || role === 'user' || role === 'prompt') {
4342
4539
  const text = packet.prompt ?? packet.text ?? (typeof packet.content === 'string' ? packet.content : null);
4343
- if (text != null && !packet.event) { appendUser(String(text), { images: Array.isArray(packet.images) ? packet.images : [] }); return; }
4540
+ if (text != null && !packet.event) { userPrompt(String(text), { images: Array.isArray(packet.images) ? packet.images : [] }); journalMsgs = new Map(); return; }
4344
4541
  }
4345
4542
  // The runtime journals the user's prompts only as `synabun.user_prompt` events.
4346
4543
  if (packet.type === 'event' && packet.event?.type === 'synabun.user_prompt') {
4347
- if (packet.event.text) appendUser(String(packet.event.text), { origin: packet.event.origin || null, imageCount: packet.event.images });
4544
+ if (packet.event.text) userPrompt(String(packet.event.text), { origin: packet.event.origin || null, imageCount: packet.event.images });
4545
+ journalMsgs = new Map();
4348
4546
  return;
4349
4547
  }
4548
+ if (packet.type === 'event' && packet.event?.type === 'assistant') { lastAssistantRow = null; handleEvent(packet.event, { silent: true }); return lastAssistantRow; }
4350
4549
  if (packet.type === 'event' && packet.event) { handleEvent(packet.event, { silent: true }); return; }
4351
- if (role === 'assistant' && (packet.message || packet.content)) { renderAssistant(packet.message || packet); return; }
4550
+ if (role === 'assistant' && (packet.message || packet.content)) return renderAssistant(packet.message || packet);
4352
4551
  if (packet.type && handleEvent(packet, { silent: true })) return;
4353
4552
  if (role === 'system' && packet.text) appendStatus(packet.text);
4354
4553
  }
@@ -4374,6 +4573,8 @@ export function createRenderer(transcriptEl, hooks = {}) {
4374
4573
  offers.clear();
4375
4574
  dropAsks();
4376
4575
  lastTextRow = null;
4576
+ sealedRows.clear();
4577
+ pendingSteer = null;
4377
4578
  for (const card of runCards.values()) { try { card._limitWait?.destroy(); } catch { /* gone */ } }
4378
4579
  runActivity.clear();
4379
4580
  runCards.clear();
@@ -20,6 +20,10 @@ import { sceneAsset, SCENE_ASSET_KEYS } from '../synabun-mascot-assets.js';
20
20
  import { isRunIdle, isTerminalRunStatus, runNeedsAttention, runStatusFromState, runTone } from './asst-state.js';
21
21
  import { kindOf, parseToolName, sayCall, tFallback, verbText } from './asst-tool-kinds.js';
22
22
  import { redactSecrets, safeStepInput } from './asst-redact.js';
23
+ import { isSteering, steerTranslator } from './asst-state.js'; // steer's boot part (asst-steer.js loads on demand)
24
+
25
+ // The steer sentences through the stage's translator (`assistant.steer.*`), else STEER_COPY's own English / Portuguese.
26
+ const steerT = (t) => steerTranslator((key, params) => t(key, '', params) || key, typeof document === 'object' ? document.documentElement?.lang : 'en');
23
27
 
24
28
  /** The scenes: one per task class SynaBun dispatches, and the generic one. */
25
29
  export const SCENES = Object.freeze(['quick', 'code', 'complex', 'review', 'research', 'browser', 'computer', 'automation', 'design', 'image_gen', 'video_gen', 'generic']);
@@ -84,6 +88,8 @@ export function stagePhase(run) {
84
88
  if (status === 'stopped') return 'stopped';
85
89
  if (isTerminalRunStatus(status)) return 'done';
86
90
  if (runNeedsAttention(run) || awaitsAnswer({ ...run, status })) return 'waiting';
91
+ // A turn a steer cut is not the end of the work: the stage keeps working until the steer's turn (asst-steer.js).
92
+ if (isSteering(run)) return 'working';
87
93
  if (isRunIdle({ ...run, status })) return 'idle';
88
94
  if (status === 'queued' || run.queued === true || run.state === 'queued') return 'queued';
89
95
  if (status === 'starting' || run.state === 'starting') return 'starting';
@@ -121,6 +127,8 @@ export function runChip(run, t = tFallback) {
121
127
  return { tone: 'action', label: t('assistant.run.awaitingRoute', 'waiting for your model choice') };
122
128
  }
123
129
  if (awaitsAnswer(run)) return { tone: 'action', label: t('assistant.run.waitingInput', 'waiting for your answer') };
130
+ // Steered mid-turn: until its next turn starts (asst-steer.js), never the ended turn's outcome.
131
+ if (isSteering(run)) return { tone: 'running', label: steerT(t)('steeringChip') };
124
132
  const tone = runTone(run);
125
133
  // A held run whose card the user answered "here": the assistant does it, this worker never started.
126
134
  if (run?.completionReason === 'route_here') return { tone, label: t('assistant.run.routedHere', 'not started: done here instead') };
@@ -365,6 +373,10 @@ export function phaseLine(phase, run, scene, t = tFallback) {
365
373
  switch (phase) {
366
374
  case 'queued': return Number(run?.position) > 0 ? t('assistant.stage.queuedAt', 'Queued · position {n}', { n: run.position }) : t('assistant.stage.queued', 'Queued');
367
375
  case 'starting': return t('assistant.stage.starting', 'Starting…');
376
+ case 'working': case 'idle': if (isSteering(run)) return steerT(t)('steering'); break;
377
+ default: break;
378
+ }
379
+ switch (phase) {
368
380
  case 'waiting':
369
381
  if (run?.state === 'awaiting_route' || run?.route?.status === 'pending' || run?.awaitingRoute) return t('assistant.stage.waitingRoute', 'Waiting for your model choice');
370
382
  if (awaitsAnswer(run)) return t('assistant.stage.waitingInput', 'Waiting for your answer');
@@ -324,6 +324,12 @@ function mountTab({ sessionId, meta = null, brain = null, label = '', userRename
324
324
  renderPills();
325
325
  },
326
326
  setBrain(next) { tab.brain = next || null; renderPills(); },
327
+ // The Background tasks view (bg-tasks/): how many still run, and how to open it from the pill.
328
+ setBackgroundTasks(count, open) {
329
+ tab.bgRunning = Math.max(0, Number(count) || 0);
330
+ tab.openBg = typeof open === 'function' ? open : null;
331
+ renderPills();
332
+ },
327
333
  isVisible: () => isTabVisible(tab),
328
334
  toolbarSlot: toolbar,
329
335
  takeHeroOrigin() {
@@ -448,6 +454,16 @@ async function startSession(prompt = '') {
448
454
 
449
455
  // ── Tray pills ───────────────────────────────────────────────────────────────
450
456
 
457
+ // The pill's "⟳ N" while background tasks run (bg-tasks-view.js), loaded once a tab has had one: never before the
458
+ // page is shown (tests/boot-critical-path.test.mjs).
459
+ let _paintBgBadge = null;
460
+ function paintPillBadge(tab) {
461
+ if (!tab?.pill || (!tab.bgRunning && !_paintBgBadge)) return;
462
+ const paint = () => { if (tab.pill) _paintBgBadge(tab.pill, tab.bgRunning || 0, { t, onClick: () => { focusSession(tab.sessionId); tab.openBg?.(); } }); };
463
+ if (_paintBgBadge) { paint(); return; }
464
+ import('../bg-tasks/bg-tasks-view.js').then((m) => { _paintBgBadge = m.paintBgBadge; paint(); }).catch(() => {});
465
+ }
466
+
451
467
  function createPill(tab) {
452
468
  const tray = document.getElementById('term-minimized-tray');
453
469
  if (!tray) return null;
@@ -489,7 +505,8 @@ function renderPills() {
489
505
  tab.pill.setAttribute('aria-label', `${tab.label} — ${statusLabel(tab.status)}`);
490
506
  tab.pill.classList.toggle('asp-pill-running', tab.status === 'working');
491
507
  tab.pill.classList.toggle('asp-pill-attention', tab.status === 'action');
492
- tab.pill.classList.toggle('asp-pill-done', tab.status === 'done');
508
+ tab.pill.classList.toggle('asp-pill-done', tab.status === 'done' && !tab.bgRunning);
509
+ paintPillBadge(tab);
493
510
  tab.pill.style.display = (!_visible || tab !== active) ? '' : 'none';
494
511
  }
495
512
  }