synabun 2.2.0 → 2.2.2

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 (166) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/README.md +1 -1
  3. package/hooks/claude-code/pre-websearch.mjs +4 -1
  4. package/hooks/claude-code/prompt-submit.mjs +7 -0
  5. package/lib/release-scan.mjs +23 -10
  6. package/lib/virustotal.mjs +143 -39
  7. package/mcp-server/dist/http.d.ts +19 -0
  8. package/mcp-server/dist/http.d.ts.map +1 -1
  9. package/mcp-server/dist/http.js +55 -13
  10. package/mcp-server/dist/http.js.map +1 -1
  11. package/mcp-server/dist/index.d.ts.map +1 -1
  12. package/mcp-server/dist/index.js +14 -9
  13. package/mcp-server/dist/index.js.map +1 -1
  14. package/mcp-server/dist/services/browser-route-flow.d.ts +118 -0
  15. package/mcp-server/dist/services/browser-route-flow.d.ts.map +1 -0
  16. package/mcp-server/dist/services/browser-route-flow.js +339 -0
  17. package/mcp-server/dist/services/browser-route-flow.js.map +1 -0
  18. package/mcp-server/dist/services/desktop-client.js +2 -2
  19. package/mcp-server/dist/services/desktop-client.js.map +1 -1
  20. package/mcp-server/dist/services/identity.d.ts +66 -3
  21. package/mcp-server/dist/services/identity.d.ts.map +1 -1
  22. package/mcp-server/dist/services/identity.js +61 -4
  23. package/mcp-server/dist/services/identity.js.map +1 -1
  24. package/mcp-server/dist/services/neural-interface.d.ts +112 -1
  25. package/mcp-server/dist/services/neural-interface.d.ts.map +1 -1
  26. package/mcp-server/dist/services/neural-interface.js +555 -61
  27. package/mcp-server/dist/services/neural-interface.js.map +1 -1
  28. package/mcp-server/dist/tools/bluesky.d.ts +20 -7
  29. package/mcp-server/dist/tools/bluesky.d.ts.map +1 -1
  30. package/mcp-server/dist/tools/bluesky.js +147 -45
  31. package/mcp-server/dist/tools/bluesky.js.map +1 -1
  32. package/mcp-server/dist/tools/browser-advanced.d.ts +11 -2
  33. package/mcp-server/dist/tools/browser-advanced.d.ts.map +1 -1
  34. package/mcp-server/dist/tools/browser-advanced.js +131 -18
  35. package/mcp-server/dist/tools/browser-advanced.js.map +1 -1
  36. package/mcp-server/dist/tools/browser-cheatsheet.d.ts +2 -0
  37. package/mcp-server/dist/tools/browser-cheatsheet.d.ts.map +1 -1
  38. package/mcp-server/dist/tools/browser-cheatsheet.js +3 -0
  39. package/mcp-server/dist/tools/browser-cheatsheet.js.map +1 -1
  40. package/mcp-server/dist/tools/morelogin.d.ts.map +1 -1
  41. package/mcp-server/dist/tools/morelogin.js +4 -2
  42. package/mcp-server/dist/tools/morelogin.js.map +1 -1
  43. package/mcp-server/dist/tools/skill-tools.d.ts +4 -4
  44. package/mcp-server/dist/tools/youtube/helpers.d.ts +1 -0
  45. package/mcp-server/dist/tools/youtube/helpers.d.ts.map +1 -1
  46. package/mcp-server/dist/tools/youtube/helpers.js +1 -1
  47. package/mcp-server/dist/tools/youtube/helpers.js.map +1 -1
  48. package/mcp-server/package-lock.json +2 -2
  49. package/mcp-server/package.json +1 -1
  50. package/mcp-server/src/http.ts +58 -12
  51. package/mcp-server/src/index.ts +15 -9
  52. package/mcp-server/src/services/browser-route-flow.ts +402 -0
  53. package/mcp-server/src/services/desktop-client.ts +2 -2
  54. package/mcp-server/src/services/identity.ts +80 -4
  55. package/mcp-server/src/services/neural-interface.ts +572 -70
  56. package/mcp-server/src/tools/bluesky.ts +164 -51
  57. package/mcp-server/src/tools/browser-advanced.ts +121 -17
  58. package/mcp-server/src/tools/browser-cheatsheet.ts +3 -0
  59. package/mcp-server/src/tools/morelogin.ts +4 -2
  60. package/mcp-server/src/tools/youtube/helpers.ts +2 -2
  61. package/neural-interface/i18n/en.json +27 -0
  62. package/neural-interface/i18n/pt-BR.json +27 -0
  63. package/neural-interface/lib/assistant-api.js +64 -23
  64. package/neural-interface/lib/assistant-brains/codex.js +6 -1
  65. package/neural-interface/lib/assistant-catalog.js +20 -2
  66. package/neural-interface/lib/assistant-dispatch.js +31 -2
  67. package/neural-interface/lib/assistant-persona.js +1 -0
  68. package/neural-interface/lib/assistant-runtime.js +15 -1
  69. package/neural-interface/lib/assistant-tools.js +10 -1
  70. package/neural-interface/lib/browser-automation-routes.js +84 -0
  71. package/neural-interface/lib/browser-execution.js +16 -3
  72. package/neural-interface/lib/browser-owner.js +48 -0
  73. package/neural-interface/lib/browser-session-close.js +84 -0
  74. package/neural-interface/lib/browser-start-handoff.js +202 -0
  75. package/neural-interface/lib/browser-tool-policy.js +21 -4
  76. package/neural-interface/lib/browser-wedge-retire.js +64 -0
  77. package/neural-interface/lib/claude-agent-bridge.js +36 -1
  78. package/neural-interface/lib/claude-background-hold.js +239 -0
  79. package/neural-interface/lib/exec-loop-command.js +8 -0
  80. package/neural-interface/lib/http-guards.js +11 -6
  81. package/neural-interface/lib/loop-logger.js +6 -1
  82. package/neural-interface/lib/mcp-external-servers.js +64 -13
  83. package/neural-interface/lib/native-loop-providers.js +122 -10
  84. package/neural-interface/lib/native-loop-runtime.js +112 -11
  85. package/neural-interface/lib/opencode-native-boundary.js +155 -21
  86. package/neural-interface/lib/owner-authority.js +113 -37
  87. package/neural-interface/lib/page-session.js +81 -23
  88. package/neural-interface/lib/peer-identity.js +311 -47
  89. package/neural-interface/lib/provider-panel-api-key-auth.js +7 -2
  90. package/neural-interface/lib/pty-host/core.js +36 -0
  91. package/neural-interface/lib/pty-host/protocol.js +2 -0
  92. package/neural-interface/lib/skills/api-v2.js +13 -2
  93. package/neural-interface/lib/skills/creation-api.js +3 -1
  94. package/neural-interface/lib/skills/evals-api.js +5 -1
  95. package/neural-interface/lib/social-write-pacing.js +151 -0
  96. package/neural-interface/lib/terminal-token-redaction.js +293 -0
  97. package/neural-interface/lib/terminal-tokens.js +359 -0
  98. package/neural-interface/lib/worker-mcp-channel.js +45 -10
  99. package/neural-interface/package-lock.json +2 -2
  100. package/neural-interface/package.json +1 -1
  101. package/neural-interface/public/shared/agy/agy-render.js +41 -1
  102. package/neural-interface/public/shared/agy/agy-styles.js +5 -0
  103. package/neural-interface/public/shared/api.js +1 -0
  104. package/neural-interface/public/shared/assistant/asst-api.js +14 -2
  105. package/neural-interface/public/shared/assistant/asst-computer.js +73 -4
  106. package/neural-interface/public/shared/assistant/asst-limit-wait.js +3 -1
  107. package/neural-interface/public/shared/assistant/asst-motion-gate.js +80 -0
  108. package/neural-interface/public/shared/assistant/asst-panel.js +8 -4
  109. package/neural-interface/public/shared/assistant/asst-render.js +72 -11
  110. package/neural-interface/public/shared/assistant/asst-scene-styles.js +55 -23
  111. package/neural-interface/public/shared/assistant/asst-scenes.js +225 -79
  112. package/neural-interface/public/shared/assistant/asst-sidepanel-styles.js +4 -4
  113. package/neural-interface/public/shared/assistant/asst-style-cache.js +44 -0
  114. package/neural-interface/public/shared/assistant/asst-styles.js +26 -5
  115. package/neural-interface/public/shared/cdx/cdx-render.js +73 -7
  116. package/neural-interface/public/shared/cdx/cdx-tabs.js +3 -3
  117. package/neural-interface/public/shared/cp/cp-agents.js +8 -0
  118. package/neural-interface/public/shared/cp/cp-permissions.js +18 -2
  119. package/neural-interface/public/shared/cp/cp-rehydrate.js +25 -1
  120. package/neural-interface/public/shared/cp/cp-tasks-model.js +33 -0
  121. package/neural-interface/public/shared/judgments-log-origins.js +29 -0
  122. package/neural-interface/public/shared/loading-teardown.js +34 -0
  123. package/neural-interface/public/shared/ocp-v2/ocp-v2-automation-ownership.js +23 -0
  124. package/neural-interface/public/shared/ocp-v2/ocp-v2-childpanel.js +6 -1
  125. package/neural-interface/public/shared/ocp-v2/ocp-v2-events.js +13 -0
  126. package/neural-interface/public/shared/ocp-v2/ocp-v2-icons.js +3 -1
  127. package/neural-interface/public/shared/ocp-v2/ocp-v2-panel.js +5 -2
  128. package/neural-interface/public/shared/ocp-v2/ocp-v2-render.js +16 -86
  129. package/neural-interface/public/shared/ocp-v2/ocp-v2-send.js +6 -0
  130. package/neural-interface/public/shared/ocp-v2/ocp-v2-styles.js +88 -72
  131. package/neural-interface/public/shared/ocp-v2/ocp-v2-ws.js +5 -2
  132. package/neural-interface/public/shared/owner-access.js +134 -0
  133. package/neural-interface/public/shared/owner-authority-view.js +92 -0
  134. package/neural-interface/public/shared/page-session.js +143 -14
  135. package/neural-interface/public/shared/poll-backoff.js +59 -0
  136. package/neural-interface/public/shared/settings/settings-data.js +6 -1
  137. package/neural-interface/public/shared/settings/settings-kit.js +11 -3
  138. package/neural-interface/public/shared/settings/settings-shell.js +7 -0
  139. package/neural-interface/public/shared/shown-children.js +72 -0
  140. package/neural-interface/public/shared/static-bg-state.js +22 -0
  141. package/neural-interface/public/shared/storage-retry.js +47 -0
  142. package/neural-interface/public/shared/storage.js +25 -4
  143. package/neural-interface/public/shared/styles.css +109 -8
  144. package/neural-interface/public/shared/synabun-mascot.js +27 -8
  145. package/neural-interface/public/shared/synabun-ticker.js +147 -12
  146. package/neural-interface/public/shared/synabun-tools.js +173 -0
  147. package/neural-interface/public/shared/tool-heartbeat.js +43 -0
  148. package/neural-interface/public/shared/tool-list-picker.js +3 -1
  149. package/neural-interface/public/shared/tool-list-view.js +23 -4
  150. package/neural-interface/public/shared/ui-automation-studio.js +8 -1
  151. package/neural-interface/public/shared/ui-claude-panel.js +238 -90
  152. package/neural-interface/public/shared/ui-judgments.js +37 -10
  153. package/neural-interface/public/shared/ui-loading.js +5 -4
  154. package/neural-interface/public/shared/ui-navbar.js +6 -0
  155. package/neural-interface/public/shared/ui-owner-access.js +191 -0
  156. package/neural-interface/public/shared/ui-owner-authority.js +162 -0
  157. package/neural-interface/public/shared/ui-sessions.js +45 -16
  158. package/neural-interface/public/shared/ui-settings.js +86 -15
  159. package/neural-interface/public/shared/ui-terminal.js +15 -7
  160. package/neural-interface/public/shared/ui-tutorial-preview.js +4 -0
  161. package/neural-interface/public/shared/ui-update.js +3 -0
  162. package/neural-interface/public/shared/ui-whiteboard.js +4 -0
  163. package/neural-interface/public/shared/window-keys.js +38 -0
  164. package/neural-interface/server.js +1240 -238
  165. package/npm-shrinkwrap.json +2 -2
  166. package/package.json +1 -1
@@ -13,6 +13,9 @@
13
13
  // /api/desktop/frames/<id>/thumb.jpg; `assistant:desktop` activity events.
14
14
 
15
15
  import { desktopSetup, getDesktopStatus, resumeDesktop, stopDesktop } from './asst-api.js';
16
+ import { createPollGate } from '../poll-backoff.js';
17
+ import { refusalOfError } from '../owner-access.js';
18
+ import { OWNER_ACCESS_RESTORED_EVENT } from '../page-session.js';
16
19
 
17
20
  // ── Pure helpers ────────────────────────────────────────────────────────────
18
21
 
@@ -290,6 +293,55 @@ export function requestDesktopStop(body = { scope: 'all' }) {
290
293
  const ICON_COMPUTER = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="4" width="18" height="12" rx="2"/><path d="M8 20h8M12 16v4"/></svg>';
291
294
  const ICON_X = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>';
292
295
  const POLL_MS = 3000;
296
+
297
+ // ── The status poll, shared by every tray of the page ──
298
+ // Each Assistant tab has its own tray and timer; through one gate (poll-backoff.js) they send at most one GET
299
+ // /api/desktop/status at a time and one per POLL_MS, wait longer after every failure (exponential, capped at five
300
+ // minutes), and stop altogether on a refusal of the owner's access (403 WORKER_BROWSER and the like: SynaBun's
301
+ // automation browser opened the page) until the page gets the owner's page secret again or becomes visible again.
302
+ // Before 2026-11-05 every tray asked every 3 s whatever the answer: five per 3 s on a refused page.
303
+ export const desktopStatusGate = createPollGate({ baseMs: POLL_MS });
304
+ let _statusInFlight = null;
305
+ let _gateWired = false;
306
+
307
+ function wireStatusGate() {
308
+ if (_gateWired) return;
309
+ _gateWired = true;
310
+ if (typeof window !== 'undefined' && typeof window.addEventListener === 'function') {
311
+ window.addEventListener(OWNER_ACCESS_RESTORED_EVENT, () => desktopStatusGate.resume());
312
+ }
313
+ if (typeof document !== 'undefined' && typeof document.addEventListener === 'function') {
314
+ document.addEventListener('visibilitychange', () => { if (!document.hidden && desktopStatusGate.snapshot().halted) desktopStatusGate.resume(); });
315
+ }
316
+ }
317
+
318
+ /**
319
+ * GET /api/desktop/status once for every tray and probe that asks at the same time; the answer counts on the shared
320
+ * gate (an answer resets it, a failure backs it off, a refusal of the owner's access halts the timers' polling).
321
+ */
322
+ export function requestDesktopStatus(request = getDesktopStatus) {
323
+ if (_statusInFlight) return _statusInFlight;
324
+ wireStatusGate();
325
+ desktopStatusGate.begin();
326
+ let sent;
327
+ try { sent = Promise.resolve(request()); } catch (err) { sent = Promise.reject(err); }
328
+ const run = sent.then(
329
+ (status) => { desktopStatusGate.succeed(); return status; },
330
+ (err) => { desktopStatusGate.fail(refusalOfError(err)); throw err; },
331
+ );
332
+ _statusInFlight = run;
333
+ const clear = () => { if (_statusInFlight === run) _statusInFlight = null; };
334
+ run.then(clear, clear);
335
+ return run;
336
+ }
337
+
338
+ /** What a failed status check was: { kind: 'forbidden' | 'timeout' | 'error', message }. */
339
+ export function computerCheckFailure(err) {
340
+ const message = str(err?.message) || 'The status check failed';
341
+ if (err?.status === 401 || err?.status === 403 || err?.forbidden) return { kind: 'forbidden', message };
342
+ if (err?.timedOut || err?.code === 'TIMEOUT' || err?.name === 'AbortError') return { kind: 'timeout', message };
343
+ return { kind: 'error', message };
344
+ }
293
345
  const THUMB_MIN_INTERVAL_MS = 500; // ≤ 2 live-thumbnail updates per second
294
346
 
295
347
  function el(tag, className, text) {
@@ -411,6 +463,7 @@ export function createComputerPanel(hostEl, hooks = {}) {
411
463
  thumbTimer: null,
412
464
  thumbPending: null,
413
465
  view: '',
466
+ checkFailed: null,
414
467
  };
415
468
 
416
469
  function isEnabled() { try { return !!hooks.isEnabled?.(); } catch { return false; } }
@@ -575,7 +628,17 @@ export function createComputerPanel(hostEl, hooks = {}) {
575
628
  const note = (text) => body.appendChild(el('div', 'asst-computer-tray-note', text));
576
629
  const spinner = () => head.insertBefore(el('span', 'asst-spinner'), head.firstChild);
577
630
 
578
- switch (info.state) {
631
+ const viewState = info.state === 'loading' && state.checkFailed ? 'check_failed' : info.state;
632
+ switch (viewState) {
633
+ case 'check_failed':
634
+ title.textContent = t('assistant.computer.checkFailed', 'Could not check computer use');
635
+ note(state.checkFailed.kind === 'forbidden'
636
+ ? t('assistant.computer.checkFailedForbidden', 'This window is not allowed to read computer use.')
637
+ : state.checkFailed.kind === 'timeout'
638
+ ? t('assistant.computer.checkFailedTimeout', 'The check did not answer in time.')
639
+ : state.checkFailed.message);
640
+ button(t('assistant.computer.checkAgain', 'Check again'), 'secondary', () => { state.checkFailed = null; render(); refresh().catch(() => {}); }, 'recheck');
641
+ break;
579
642
  case 'loading':
580
643
  spinner();
581
644
  title.textContent = t('assistant.computer.checking', 'Checking computer use…');
@@ -670,6 +733,7 @@ export function createComputerPanel(hostEl, hooks = {}) {
670
733
 
671
734
  function applyStatus(status) {
672
735
  if (!status || typeof status !== 'object') return;
736
+ state.checkFailed = null;
673
737
  state.status = status;
674
738
  state.info = computerSetupState(status);
675
739
  if (status.control && typeof status.control === 'object') {
@@ -684,11 +748,13 @@ export function createComputerPanel(hostEl, hooks = {}) {
684
748
 
685
749
  async function refresh() {
686
750
  try {
687
- const status = await getDesktopStatus();
751
+ const status = await requestDesktopStatus();
688
752
  if (!state.destroyed) applyStatus(status);
689
753
  return status;
690
754
  } catch (err) {
691
- if (!state.destroyed) { state.error = ''; render(); }
755
+ // A check that failed is a settled state (Check again), never "Checking…" forever. A status already known
756
+ // stays on screen; only a tray that never got one shows the failure.
757
+ if (!state.destroyed) { state.error = ''; state.checkFailed = computerCheckFailure(err); render(); }
692
758
  throw err;
693
759
  }
694
760
  }
@@ -697,7 +763,8 @@ export function createComputerPanel(hostEl, hooks = {}) {
697
763
  const need = state.view === 'tray' && !state.destroyed;
698
764
  if (need && !state.pollTimer) {
699
765
  state.pollTimer = setInterval(() => {
700
- if (document.hidden) return;
766
+ // The shared gate decides: one request at a time for every tray, a wait after a failure, none on a refusal.
767
+ if (document.hidden || !desktopStatusGate.due()) return;
701
768
  refresh().catch(() => {});
702
769
  }, POLL_MS);
703
770
  } else if (!need && state.pollTimer) {
@@ -735,6 +802,8 @@ export function createComputerPanel(hostEl, hooks = {}) {
735
802
  stop,
736
803
  isActive: desktopActive,
737
804
  status: () => state.status,
805
+ /** A status check made elsewhere failed: settle the tray instead of leaving it on "Checking…". */
806
+ checkFailed(err) { if (state.destroyed || state.status) return; state.checkFailed = computerCheckFailure(err); render(); },
738
807
  info: () => state.info,
739
808
  destroy() {
740
809
  state.destroyed = true;
@@ -18,6 +18,7 @@
18
18
 
19
19
  import * as mascotLib from '../synabun-mascot.js';
20
20
  import { isReducedMotion, subscribe } from '../synabun-ticker.js';
21
+ import { syncEmpty } from '../shown-children.js';
21
22
  import { limitCountdown, resetMs } from './asst-limit.js';
22
23
 
23
24
  const RING_R = 24;
@@ -179,6 +180,7 @@ export function createLimitWait(opts = {}) {
179
180
  retryBtn.textContent = label;
180
181
  }
181
182
  if (switchBtn) switchBtn.hidden = !(next === 'waiting' || next === 'unknown');
183
+ syncEmpty(actions); // the row goes when none of its buttons shows (data-empty, not a :has())
182
184
  if (next === 'waiting') { setPose('sleep'); setRing(limitCountdown({ resetsAt, since }, now).progress || 0); }
183
185
  else if (next === 'unknown') { setPose('wait'); setRing(0.18, true); }
184
186
  else if (next === 'restored') { setPose(was === 'waiting' ? 'success' : 'idle'); setRing(1); }
@@ -301,7 +303,7 @@ const CSS = `
301
303
  .asst-limit-wait-clock.is-text { font-family: inherit; font-size: 13px; color: var(--asst-text-2); letter-spacing: 0; }
302
304
  .asst-limit-wait-meta { color: var(--asst-text-3); font-size: 11.5px; overflow-wrap: anywhere; }
303
305
  .asst-limit-wait-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
304
- .asst-limit-wait-actions:not(:has(> :not([hidden]))) { display: none; }
306
+ .asst-limit-wait-actions[data-empty] { display: none; }
305
307
  .asst-limit-wait-live { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
306
308
  .asst-limit-row .asst-msg-content { width: 100%; }
307
309
  .asst-run .asst-limit-wait { grid-column: 2 / span 2; margin-top: 8px; padding: 10px 12px; }
@@ -0,0 +1,80 @@
1
+ // ═══════════════════════════════════════════
2
+ // SynaBun Assistant — loops run only on screen
3
+ // ═══════════════════════════════════════════
4
+ // The transcript's decorative loops (a run card's cameo, its stage's scene and
5
+ // sweep; a live rack's sweep, ticks and scene; a route line's sweep and icon)
6
+ // run only while their holder is on screen. One IntersectionObserver per
7
+ // renderer marks a holder that is not (scrolled out of its transcript, its tab
8
+ // hidden, its window minimised to nothing) with `data-offscreen`; the
9
+ // stylesheet pauses every animation under it (asst-styles.js), and the loop
10
+ // picks up where it stopped when the holder is back. Every frame the page
11
+ // draws restyles each running animation on the main thread, composited or
12
+ // not, so a loop nobody sees is never free; the observer is the browser's own,
13
+ // so watching costs nothing while the transcript scrolls.
14
+ //
15
+ // createMotionGate({ IntersectionObserver }?) → { watch(el), unwatch(el), disconnect(), size() }
16
+ //
17
+ // No observer (an old engine, a test without one): nothing is marked, every
18
+ // loop runs as before. DOM-light on purpose: tests/assistant-motion-gate.test.mjs
19
+ // drives it with a stand-in observer.
20
+
21
+ export const OFFSCREEN_ATTR = 'data-offscreen';
22
+ const PRUNE_EVERY = 32; // watched holders between two sweeps for ones that left the document
23
+
24
+ export function createMotionGate({ IntersectionObserver: IO = globalThis.IntersectionObserver } = {}) {
25
+ const watched = new Set();
26
+ let io = null; // undefined: no observer here
27
+
28
+ function mark(el, off) {
29
+ try {
30
+ if (off) { if (!el.hasAttribute(OFFSCREEN_ATTR)) el.setAttribute(OFFSCREEN_ATTR, ''); }
31
+ else if (el.hasAttribute(OFFSCREEN_ATTR)) el.removeAttribute(OFFSCREEN_ATTR);
32
+ } catch { /* not an element */ }
33
+ }
34
+
35
+ function observer() {
36
+ if (io !== null) return io;
37
+ if (typeof IO !== 'function') { io = undefined; return io; }
38
+ try {
39
+ io = new IO((entries) => {
40
+ for (const entry of entries) {
41
+ const el = entry.target;
42
+ if (!watched.has(el)) continue;
43
+ if (el.isConnected === false) { unwatch(el); continue; }
44
+ mark(el, !entry.isIntersecting);
45
+ }
46
+ });
47
+ } catch { io = undefined; }
48
+ return io;
49
+ }
50
+
51
+ /** Holders removed while already off screen get no report: drop them now and then. */
52
+ function prune() {
53
+ for (const el of Array.from(watched)) if (el.isConnected === false) unwatch(el);
54
+ }
55
+
56
+ function watch(el) {
57
+ if (!el || watched.has(el)) return false;
58
+ const o = observer();
59
+ if (!o) return false;
60
+ watched.add(el);
61
+ try { o.observe(el); } catch { watched.delete(el); return false; }
62
+ if (watched.size % PRUNE_EVERY === 0) prune();
63
+ return true;
64
+ }
65
+
66
+ function unwatch(el) {
67
+ if (!watched.delete(el)) return;
68
+ try { io?.unobserve(el); } catch { /* already gone */ }
69
+ mark(el, false);
70
+ }
71
+
72
+ function disconnect() {
73
+ try { io?.disconnect(); } catch { /* already gone */ }
74
+ for (const el of watched) mark(el, false);
75
+ watched.clear();
76
+ if (io) io = null;
77
+ }
78
+
79
+ return { watch, unwatch, disconnect, size: () => watched.size };
80
+ }
@@ -39,6 +39,7 @@ import { isGuest, hasPermission } from '../ui-sync.js';
39
39
  import { getWhiteboardElementById } from '../ui-whiteboard.js';
40
40
  import { focusNativeLoopRun } from '../ui-native-loop-router.js';
41
41
  import { wireFileLinks } from '../ui-file-links.js';
42
+ import { watchEmpty } from '../shown-children.js';
42
43
  import { injectAssistantStyles } from './asst-styles.js';
43
44
  import { tipsSeen, tourOffered } from '../tour/tour-state.js';
44
45
  import { createAssistantSocket } from './asst-ws.js';
@@ -59,7 +60,7 @@ import { createUsageGauge } from './asst-usage.js';
59
60
  import { closeMenu, currentMenuAnchor, isMenuOpen, openMenu } from './asst-menu.js';
60
61
  import { createRouteModeControl, openModelsManager, openRoutesEditor, refreshModelsManager, renderRouteCard, routeModeLabel } from './asst-route.js';
61
62
  import { budgetChipText, budgetSpendText, budgetTone, closeBudgetEditor, createBudgetController, mountBudgetChip, openBudgetEditor } from './asst-budget.js';
62
- import { computerRemoteView, createComputerPanel, createComputerToggle, normalizeComputerRemote, openFrameLightbox, closeFrameLightbox, requestDesktopStop } from './asst-computer.js';
63
+ import { computerRemoteView, createComputerPanel, createComputerToggle, normalizeComputerRemote, openFrameLightbox, closeFrameLightbox, requestDesktopStatus, requestDesktopStop } from './asst-computer.js';
63
64
  import {
64
65
  applyLimit, applyLimitPacket, applyUsagePacket, BRAIN_PROVIDERS, brainLabel, createRenameWriter, createTabState, DEFAULT_ROUTE_MODE, deserializeTabState, fmtCost, fmtRunLine, limitExpiresIn, limitNoticeText, modelShortName,
65
66
  brainModePatch, isBrainProvider, normalizeBrain, normalizeComputerMode, permissionModeLabel, normalizeRouteMode, normalizeTestDensity, projectLabel, providerMeta, providerShortLabel, readStoredBrain, runFromPayload,
@@ -67,7 +68,7 @@ import {
67
68
  } from './asst-state.js';
68
69
  import {
69
70
  closeAssistantSession, dispatchAssistantRun, escalateAssistantRun, focusAssistantRun, getAssistantRun,
70
- fetchManageCatalog, getAssistantRunResult, getAssistantSession, getAssistantSessionUsage, getDesktopStatus, getRouting, killAllAssistantRuns, removeAssistantRun, clearFinishedAssistantRuns,
71
+ fetchManageCatalog, getAssistantRunResult, getAssistantSession, getAssistantSessionUsage, getRouting, killAllAssistantRuns, removeAssistantRun, clearFinishedAssistantRuns,
71
72
  listAssistantSessions, patchAssistantSession, patchHiddenModels, setAdminSandbox, stopAssistantRun, uploadAssistantAttachment,
72
73
  } from './asst-api.js';
73
74
 
@@ -230,6 +231,8 @@ export function mountAssistant(viewport, { sessionId, brain, host = {}, session
230
231
 
231
232
  const barEl = root.querySelector('.asst-bar');
232
233
  const barGroups = Object.fromEntries([...barEl.querySelectorAll('.asst-bar-group')].map((g) => [g.dataset.group, g]));
234
+ // A group none of whose controls shows is hidden through data-empty (shown-children.js), never a :has().
235
+ const barEmpty = watchEmpty(barEl, '.asst-bar-group');
233
236
  const costEl = root.querySelector('.asst-cost');
234
237
  const bannersEl = root.querySelector('.asst-banners');
235
238
  const transcriptEl = root.querySelector('.asst-transcript');
@@ -1111,14 +1114,14 @@ export function mountAssistant(viewport, { sessionId, brain, host = {}, session
1111
1114
  }
1112
1115
  if (st.features.computer == null && !st.desktopProbe) {
1113
1116
  st.desktopProbe = true;
1114
- getDesktopStatus()
1117
+ requestDesktopStatus()
1115
1118
  .then((status) => {
1116
1119
  st.desktopSupported = status?.supported === true;
1117
1120
  st.features.computer = status?.supported === true;
1118
1121
  computerPanel.applyStatus(status);
1119
1122
  applyFeatures();
1120
1123
  })
1121
- .catch(() => { st.features.computer = false; applyFeatures(); });
1124
+ .catch((err) => { st.features.computer = false; computerPanel.checkFailed?.(err); applyFeatures(); });
1122
1125
  }
1123
1126
  }
1124
1127
 
@@ -2322,6 +2325,7 @@ export function mountAssistant(viewport, { sessionId, brain, host = {}, session
2322
2325
  dock.destroy();
2323
2326
  composer.destroy();
2324
2327
  renderer.destroy();
2328
+ barEmpty.disconnect();
2325
2329
  barEl.remove(); // it may live in the host's header
2326
2330
  root.remove();
2327
2331
  if (closeServer) {
@@ -55,6 +55,8 @@ import { injectRackStyles } from './asst-rack-styles.js';
55
55
  import { injectSceneStyles } from './asst-scene-styles.js';
56
56
  import { activityScene, compactActivity, isLivePhase, runChip, sceneOfClass, sceneSvg, stagePhase } from './asst-scenes.js';
57
57
  import { STAGE_TIMING, createWorkerStage } from './asst-run-stage.js';
58
+ import { createMotionGate } from './asst-motion-gate.js';
59
+ import { createStyleCache } from './asst-style-cache.js';
58
60
  import { formatRunTokens } from './asst-usage.js';
59
61
  import { sanitizeHtmlString, sanitizeInto } from './asst-sanitize.js';
60
62
  import { renderStreamingMarkdown } from '../streaming-markdown.js';
@@ -65,6 +67,8 @@ import { createAskTail } from './asst-ask-tail.js';
65
67
  import { limitFromText } from './asst-limit.js';
66
68
  import { createLimitDock } from './asst-limit-dock.js';
67
69
  import { createLimitWait } from './asst-limit-wait.js';
70
+ import { synabunToolKey, synabunToolLabel } from '../synabun-tools.js';
71
+ import { normalizeToolHeartbeat } from '../tool-heartbeat.js';
68
72
 
69
73
  // ── Markdown (lazy marked, the vendored build the sidepanels use too) ───────────────
70
74
  let _marked = null;
@@ -109,9 +113,8 @@ export function mdInto(node, text) {
109
113
  export const ICON_ASSISTANT = '<svg viewBox="0 0 24 24" fill="currentColor"><rect x="8" y="5.5" width="11" height="5" rx="2.5" transform="rotate(-12 13.5 8)"/><rect x="4.5" y="12.5" width="11" height="5" rx="2.5" transform="rotate(-12 10 15)"/></svg>';
110
114
  const ICON_MEMORY = '<svg viewBox="0 0 24 24" fill="currentColor"><rect x="8" y="5.5" width="11" height="5" rx="2.5" transform="rotate(-12 13.5 8)"/><rect x="4.5" y="12.5" width="11" height="5" rx="2.5" transform="rotate(-12 10 15)"/></svg>';
111
115
  const ICON_ESCALATE = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 19V5M5 12l7-7 7 7"/></svg>';
112
- // SynaBun's own MCP tools: Claude/Codex `mcp__SynaBun__x`, OpenCode `SynaBun_x`.
113
- const SYNABUN_TOOL_RE = /^(?:mcp__synabun__|synabun_)(.+)$/i;
114
- export function synabunToolName(name) { const m = SYNABUN_TOOL_RE.exec(String(name || '')); return m ? m[1] : null; }
116
+ // SynaBun's own MCP tools: Claude/Codex `mcp__SynaBun__x`, OpenCode `SynaBun_x` (synabun-tools.js, every panel's).
117
+ export function synabunToolName(name) { return synabunToolKey(name); }
115
118
  const RESULT_ERRORS = { error_max_turns: 'Stopped: the turn limit was reached.', error_max_budget_usd: 'Stopped: the budget cap was reached.', error_during_execution: 'The turn failed.', error_max_structured_output_retries: 'Stopped: structured output kept failing.' };
116
119
  const INTERRUPTED_RE = /\b(?:interrupted|aborted|cancell?ed)\b/i;
117
120
 
@@ -574,6 +577,16 @@ export function createRenderer(transcriptEl, hooks = {}) {
574
577
  const stageWidths = new WeakMap(); // stage element → { rack, width }
575
578
  const toRecut = new Set();
576
579
  let recutTimer = 0;
580
+ // What the stylesheet decides about a bubble (--rk-cut, the line's white-space) changes only with a container
581
+ // query, so only with the stage's width: read once, forgotten when the width changes (here) or the fonts load.
582
+ const styleCache = createStyleCache();
583
+ // A web font that arrives changes every measured width: the next paint of each bubble measures again.
584
+ const onFontsLoaded = () => { styleCache.invalidate(); for (const rack of racks) rack.budgetMemo = null; };
585
+ const fontSet = typeof document !== 'undefined' ? document.fonts : null;
586
+ try { fontSet?.addEventListener?.('loadingdone', onFontsLoaded); } catch { /* no FontFaceSet events */ }
587
+ const stopFontWatch = () => { try { fontSet?.removeEventListener?.('loadingdone', onFontsLoaded); } catch { /* gone */ } };
588
+ // The transcript's loops run only while their holder is on screen (run cards, racks, route lines).
589
+ const motion = createMotionGate();
577
590
  const stageResizes = typeof ResizeObserver === 'function' ? new ResizeObserver((entries) => {
578
591
  for (const entry of entries) {
579
592
  const seen = stageWidths.get(entry.target);
@@ -582,6 +595,7 @@ export function createRenderer(transcriptEl, hooks = {}) {
582
595
  if (seen.width === null) { seen.width = width; continue; } // the first report: the width it was cut at
583
596
  if (width === seen.width) continue;
584
597
  seen.width = width;
598
+ forgetBubbleStyle(seen.rack);
585
599
  toRecut.add(seen.rack);
586
600
  }
587
601
  if (!toRecut.size) return;
@@ -1601,6 +1615,7 @@ export function createRenderer(transcriptEl, hooks = {}) {
1601
1615
  sr: { last: 0, timer: 0, pending: '' },
1602
1616
  };
1603
1617
  row._rack = rack;
1618
+ motion.watch(row); // its sweep, ticks and scene loop only while it is on screen
1604
1619
  rack.receipt.btn.addEventListener('click', () => setRackOpen(rack, !rack.open));
1605
1620
  row.querySelector('.asst-rack-view').addEventListener('click', (e) => {
1606
1621
  const btn = e.target.closest('button[data-view]');
@@ -2079,6 +2094,22 @@ export function createRenderer(transcriptEl, hooks = {}) {
2079
2094
  * head (subjectCut).
2080
2095
  */
2081
2096
  function subjectBudget(rack, verb, cut = 'middle') {
2097
+ const s = rack.stage;
2098
+ // The same inputs give the same budget: the 1 Hz clock tick reuses it instead of measuring the stage again
2099
+ // (a measure on the frame's path forces style and layout of whatever the frame dirtied). The key holds every
2100
+ // input the measure reads: the stage's width (its ResizeObserver's), the scene beside the mascot, whether the
2101
+ // bubble shows, the verb, the clock's length (tabular digits: same length, same width), the running reserve, the cut.
2102
+ const seen = stageResizes ? stageWidths.get(s.el) : null;
2103
+ const key = seen && seen.width != null
2104
+ ? `${seen.width}|${rack.sceneId}|${s.bubble.hidden ? 0 : 1}|${verb}|${s.meta.textContent.length}|${rack.bubble.step?.state === 'running' ? 1 : 0}|${cut}`
2105
+ : '';
2106
+ if (key && rack.budgetMemo?.key === key) return rack.budgetMemo.value;
2107
+ const value = measureSubjectBudget(rack, verb, cut);
2108
+ rack.budgetMemo = key ? { key, value } : null;
2109
+ return value;
2110
+ }
2111
+
2112
+ function measureSubjectBudget(rack, verb, cut) {
2082
2113
  const s = rack.stage;
2083
2114
  const width = s.el.clientWidth;
2084
2115
  if (!width) return 96;
@@ -2095,14 +2126,30 @@ export function createRenderer(transcriptEl, hooks = {}) {
2095
2126
  // Two lines, less what wrapping at token boundaries wastes (a head cut is one tail: close to two full
2096
2127
  // lines, a path's pieces wrapping at its separators); a guess on the generous side, since fitSubject
2097
2128
  // cuts what the clamp would hide or a piece would push past the edge.
2098
- const lines = getComputedStyle(s.line).whiteSpace === 'nowrap' ? 1 : cut === 'head' ? 2 : 1.85;
2129
+ const lines = bubbleStyle(rack, s.line, 'white-space') === 'nowrap' ? 1 : cut === 'head' ? 2 : 1.85;
2099
2130
  const taken = Math.ceil((verbPx + 7 + (numbersPx ? numbersPx + 7 : 0)) / 7);
2100
2131
  return Math.max(24, Math.min(240, Math.floor(perLine * lines) - taken - 1));
2101
2132
  }
2102
2133
 
2103
- /** 'head' where the stylesheet says so (≤320 px: keep the tail), else 'middle'. */
2134
+ /**
2135
+ * A computed style of the bubble, read once while the stage keeps its width (styleCache; the stage's
2136
+ * ResizeObserver forgets it). Without a ResizeObserver nothing would say when to forget: read it each time.
2137
+ */
2138
+ function bubbleStyle(rack, node, prop) {
2139
+ if (stageResizes && stageWidths.has(rack.stage.el)) return styleCache.get(node, prop);
2140
+ try { return getComputedStyle(node).getPropertyValue(prop).trim(); } catch { return ''; }
2141
+ }
2142
+
2143
+ /** The stage's width changed (or the fonts did): its cut, its line's wrap and its budget are read again. */
2144
+ function forgetBubbleStyle(rack) {
2145
+ styleCache.invalidate(rack.stage.subject);
2146
+ styleCache.invalidate(rack.stage.line);
2147
+ rack.budgetMemo = null;
2148
+ }
2149
+
2150
+ /** 'head' where the stylesheet says so (≤320 px: keep the tail), else 'middle'. Never read per frame: see bubbleStyle. */
2104
2151
  function subjectCut(rack) {
2105
- try { return getComputedStyle(rack.stage.subject).getPropertyValue('--rk-cut').trim() === 'head' ? 'head' : 'middle'; } catch { return 'middle'; }
2152
+ return bubbleStyle(rack, rack.stage.subject, '--rk-cut') === 'head' ? 'head' : 'middle';
2106
2153
  }
2107
2154
 
2108
2155
  /**
@@ -2463,7 +2510,10 @@ export function createRenderer(transcriptEl, hooks = {}) {
2463
2510
  function stepTitle(step) {
2464
2511
  if (step.type === 'think') return t('assistant.rack.kind.think', 'Thinking');
2465
2512
  if (step.kind === 'computer') { const base = computerToolName(step.name) || 'computer'; return t(`assistant.computer.tool.${base}`, COMPUTER_TOOL_TITLES[base] || 'Computer'); }
2466
- if (step.kind === 'mcp' || synabunToolName(step.name) != null) return toolWords(step.name);
2513
+ // A SynaBun tool by the name every panel gives it ('Bluesky · Post'); any other MCP tool by its words.
2514
+ const sbKey = synabunToolName(step.name);
2515
+ if (sbKey != null) return synabunToolLabel(sbKey);
2516
+ if (step.kind === 'mcp') return toolWords(step.name);
2467
2517
  return step.name || 'tool';
2468
2518
  }
2469
2519
 
@@ -2861,9 +2911,11 @@ export function createRenderer(transcriptEl, hooks = {}) {
2861
2911
  }
2862
2912
 
2863
2913
  // ── Rack upkeep ──
2914
+ // The 1 Hz beats run only while the transcript is on screen (a hidden tab, a closed panel): they paint clocks
2915
+ // and bubbles nobody would see. Back on screen, the ticker runs them at once.
2864
2916
  function needTicker() {
2865
2917
  if (unsubTick) return;
2866
- try { unsubTick = subscribe(tickRacks, { fps: 1 }); } catch { unsubTick = null; }
2918
+ try { unsubTick = subscribe(tickRacks, { fps: 1, target: $msgs }); } catch { unsubTick = null; }
2867
2919
  }
2868
2920
 
2869
2921
  function stopTicker() {
@@ -2888,6 +2940,7 @@ export function createRenderer(transcriptEl, hooks = {}) {
2888
2940
  const stage = rack.stage.el;
2889
2941
  if (on && !stageWidths.has(stage)) {
2890
2942
  stageWidths.set(stage, { rack, width: null });
2943
+ forgetBubbleStyle(rack); // read again from here on, while the observer watches the width
2891
2944
  stageResizes.observe(stage);
2892
2945
  } else if (!on && stageWidths.has(stage)) {
2893
2946
  stageWidths.delete(stage);
@@ -2914,6 +2967,7 @@ export function createRenderer(transcriptEl, hooks = {}) {
2914
2967
 
2915
2968
  function dropRack(rack) {
2916
2969
  watchStageWidth(rack, false);
2970
+ motion.unwatch(rack.row);
2917
2971
  clearTimeout(rack.stageTimer);
2918
2972
  clearTimeout(rack.clearTimer);
2919
2973
  clearTimeout(rack.sr.timer);
@@ -3178,6 +3232,7 @@ export function createRenderer(transcriptEl, hooks = {}) {
3178
3232
  runCards.set(run.runId, card);
3179
3233
  const { wrap } = assistantRow(rootScope);
3180
3234
  wrap.appendChild(card);
3235
+ motion.watch(card); // its cameo, stage, scene and sweep loop only while it is on screen
3181
3236
  syncStage(run.runId, card, run);
3182
3237
  return card;
3183
3238
  }
@@ -3220,7 +3275,7 @@ export function createRenderer(transcriptEl, hooks = {}) {
3220
3275
 
3221
3276
  function needStageTicker() {
3222
3277
  if (unsubStageTick) return;
3223
- try { unsubStageTick = subscribe(tickStages, { fps: 1 }); } catch { unsubStageTick = null; }
3278
+ try { unsubStageTick = subscribe(tickStages, { fps: 1, target: $msgs }); } catch { unsubStageTick = null; }
3224
3279
  }
3225
3280
 
3226
3281
  function stopStageTicker() {
@@ -3399,6 +3454,7 @@ export function createRenderer(transcriptEl, hooks = {}) {
3399
3454
  const line = createRouteLine(route, routeLineOpts(phase));
3400
3455
  routeLines.set(routeId, line);
3401
3456
  append(line.el);
3457
+ motion.watch(line.el); // its sweep and icon loop only while it is on screen
3402
3458
  syncRouteLive(routeId);
3403
3459
  enterRow(line.el);
3404
3460
  return line;
@@ -3409,6 +3465,7 @@ export function createRenderer(transcriptEl, hooks = {}) {
3409
3465
  if (!routeId || !line) return;
3410
3466
  const fresh = routeLines.get(routeId) !== line;
3411
3467
  routeLines.set(routeId, line);
3468
+ if (line.el) motion.watch(line.el);
3412
3469
  syncRouteLive(routeId);
3413
3470
  if (fresh && line.el?.isConnected) enterRow(line.el);
3414
3471
  }
@@ -3430,7 +3487,7 @@ export function createRenderer(transcriptEl, hooks = {}) {
3430
3487
 
3431
3488
  function removeRouteLine(routeId) {
3432
3489
  const line = routeLines.get(routeId);
3433
- if (line) { line.el.remove(); routeLines.delete(routeId); }
3490
+ if (line) { motion.unwatch(line.el); line.el.remove(); routeLines.delete(routeId); }
3434
3491
  }
3435
3492
 
3436
3493
  // ── The automation trace ──
@@ -3827,6 +3884,8 @@ export function createRenderer(transcriptEl, hooks = {}) {
3827
3884
  }
3828
3885
 
3829
3886
  function dispatch(ev, silent) {
3887
+ // A long call's heartbeat names the call as its parent: progress of that call, not a subagent's feed.
3888
+ ev = normalizeToolHeartbeat(ev);
3830
3889
  if (ev.type !== 'stream_event') for (const k of idKeys(ev)) markSeen(k); // deltas are never replayed as themselves
3831
3890
  const parentId = ev.parent_tool_use_id || ev.message?.parent_tool_use_id || null;
3832
3891
  const scope = scopeFor(parentId);
@@ -4094,6 +4153,8 @@ export function createRenderer(transcriptEl, hooks = {}) {
4094
4153
  runActivity.clear();
4095
4154
  runCards.clear();
4096
4155
  routeLines.clear();
4156
+ motion.disconnect(); // every holder it watched goes with the transcript
4157
+ styleCache.invalidate();
4097
4158
  autoRows.clear();
4098
4159
  turnFrames = [];
4099
4160
  rootScope.stream = null;
@@ -4122,7 +4183,7 @@ export function createRenderer(transcriptEl, hooks = {}) {
4122
4183
  return {
4123
4184
  el: $msgs,
4124
4185
  clear,
4125
- destroy: () => { clear(); stageResizes?.disconnect(); limitDock.destroy(); },
4186
+ destroy: () => { clear(); stageResizes?.disconnect(); limitDock.destroy(); stopFontWatch(); },
4126
4187
  appendUser,
4127
4188
  appendAssistantMarkdown,
4128
4189
  appendStatus,