synabun 2.4.2 → 2.4.3

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 (103) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +1 -1
  3. package/docs/browser-extension-bridge.md +23 -3
  4. package/lib/release-npm-ci.mjs +23 -1
  5. package/mcp-server/dist/services/neural-interface.js +1 -1
  6. package/mcp-server/dist/services/neural-interface.js.map +1 -1
  7. package/mcp-server/dist/tools/browser-extension-setup.d.ts.map +1 -1
  8. package/mcp-server/dist/tools/browser-extension-setup.js +8 -2
  9. package/mcp-server/dist/tools/browser-extension-setup.js.map +1 -1
  10. package/mcp-server/package-lock.json +5 -5
  11. package/mcp-server/package.json +1 -1
  12. package/mcp-server/src/services/neural-interface.ts +1 -1
  13. package/mcp-server/src/tools/browser-extension-setup.ts +8 -2
  14. package/neural-interface/i18n/en.json +50 -1
  15. package/neural-interface/i18n/pt-BR.json +57 -8
  16. package/neural-interface/lib/assistant-api.js +33 -0
  17. package/neural-interface/lib/assistant-brains/opencode.js +121 -7
  18. package/neural-interface/lib/assistant-dispatch.js +26 -2
  19. package/neural-interface/lib/assistant-envelope.js +40 -0
  20. package/neural-interface/lib/assistant-runtime.js +95 -10
  21. package/neural-interface/lib/browser-extension-adapter.js +1 -3
  22. package/neural-interface/lib/browser-extension-archive.js +149 -0
  23. package/neural-interface/lib/browser-extension-bridge.js +7 -4
  24. package/neural-interface/lib/browser-extension-folder.js +596 -76
  25. package/neural-interface/lib/browser-extension-package.js +200 -0
  26. package/neural-interface/lib/browser-extension-pin.js +84 -0
  27. package/neural-interface/lib/browser-extension-pin.json +33 -0
  28. package/neural-interface/lib/browser-extension-setup.js +105 -18
  29. package/neural-interface/lib/cli-install.js +23 -3
  30. package/neural-interface/lib/cli-update-planner.js +67 -4
  31. package/neural-interface/lib/native-loop-providers.js +10 -1
  32. package/neural-interface/lib/native-loop-runtime.js +20 -2
  33. package/neural-interface/lib/opencode-shell-read.js +107 -0
  34. package/neural-interface/lib/opencode-stop-failures.js +40 -0
  35. package/neural-interface/lib/opencode-turn-release.js +173 -0
  36. package/neural-interface/lib/opencode-v2-client.js +4 -1
  37. package/neural-interface/lib/opencode-v2-ws-requests.js +34 -0
  38. package/neural-interface/lib/opencode2-client.js +341 -6
  39. package/neural-interface/lib/opencode2-translate.js +161 -4
  40. package/neural-interface/lib/terminal-token-redaction.js +83 -0
  41. package/neural-interface/lib/whatsapp/bridge.js +52 -6
  42. package/neural-interface/package-lock.json +5 -5
  43. package/neural-interface/package.json +1 -1
  44. package/neural-interface/public/extension-setup.html +5 -2
  45. package/neural-interface/public/shared/agy/agy-panel.js +38 -10
  46. package/neural-interface/public/shared/assistant/asst-api.js +25 -0
  47. package/neural-interface/public/shared/assistant/asst-panel.js +69 -1
  48. package/neural-interface/public/shared/assistant/asst-rack-styles.js +23 -0
  49. package/neural-interface/public/shared/assistant/asst-render.js +138 -6
  50. package/neural-interface/public/shared/assistant/asst-shell-logic.js +200 -0
  51. package/neural-interface/public/shared/assistant/asst-shell.js +111 -0
  52. package/neural-interface/public/shared/assistant/asst-styles.js +1 -0
  53. package/neural-interface/public/shared/cdx/cdx-tabs.js +25 -0
  54. package/neural-interface/public/shared/extension-setup/es-page.js +10 -4
  55. package/neural-interface/public/shared/extension-setup/es-view.js +25 -10
  56. package/neural-interface/public/shared/mtc/mtc-panel.js +17 -2
  57. package/neural-interface/public/shared/ocp-v2/ocp-v2-events.js +5 -0
  58. package/neural-interface/public/shared/ocp-v2/ocp-v2-manager.js +1 -0
  59. package/neural-interface/public/shared/ocp-v2/ocp-v2-panel.js +34 -2
  60. package/neural-interface/public/shared/ocp-v2/ocp-v2-rehydrate.js +7 -1
  61. package/neural-interface/public/shared/ocp-v2/ocp-v2-render.js +26 -1
  62. package/neural-interface/public/shared/ocp-v2/ocp-v2-send.js +39 -6
  63. package/neural-interface/public/shared/ocp-v2/ocp-v2-session-actions.js +20 -1
  64. package/neural-interface/public/shared/ocp-v2/ocp-v2-shell-block.js +165 -0
  65. package/neural-interface/public/shared/ocp-v2/ocp-v2-shell-logic.js +346 -0
  66. package/neural-interface/public/shared/ocp-v2/ocp-v2-shell.js +108 -0
  67. package/neural-interface/public/shared/ocp-v2/ocp-v2-state.js +49 -3
  68. package/neural-interface/public/shared/ocp-v2/ocp-v2-styles.js +40 -0
  69. package/neural-interface/public/shared/ocp-v2/ocp-v2-tools-logic.js +20 -5
  70. package/neural-interface/public/shared/ocp-v2/ocp-v2-tools.js +7 -1
  71. package/neural-interface/public/shared/ocp-v2/ocp-v2-ws.js +7 -2
  72. package/neural-interface/public/shared/settings/settings-browser-extension.js +54 -12
  73. package/neural-interface/public/shared/shell-stop-view.js +83 -0
  74. package/neural-interface/public/shared/tour/tour-actor.js +14 -3
  75. package/neural-interface/public/shared/tray-auto-close.js +36 -6
  76. package/neural-interface/public/shared/ui-claude-panel.js +20 -0
  77. package/neural-interface/public/shared/ui-native-loop-router.js +45 -3
  78. package/neural-interface/public/shared/ui-scroll-follow.js +4 -0
  79. package/neural-interface/server.js +249 -35
  80. package/npm-shrinkwrap.json +5 -5
  81. package/package.json +1 -2
  82. package/browser-extension/content.js +0 -231
  83. package/browser-extension/engine.js +0 -658
  84. package/browser-extension/icons/icon-128.png +0 -0
  85. package/browser-extension/icons/icon-16.png +0 -0
  86. package/browser-extension/icons/icon-32.png +0 -0
  87. package/browser-extension/icons/icon-48.png +0 -0
  88. package/browser-extension/icons/status-off-16.png +0 -0
  89. package/browser-extension/icons/status-off-32.png +0 -0
  90. package/browser-extension/icons/status-off-48.png +0 -0
  91. package/browser-extension/icons/status-on-16.png +0 -0
  92. package/browser-extension/icons/status-on-32.png +0 -0
  93. package/browser-extension/icons/status-on-48.png +0 -0
  94. package/browser-extension/manifest.json +0 -58
  95. package/browser-extension/popup-strings.js +0 -250
  96. package/browser-extension/popup-view.js +0 -151
  97. package/browser-extension/popup.css +0 -166
  98. package/browser-extension/popup.html +0 -108
  99. package/browser-extension/popup.js +0 -359
  100. package/browser-extension/service-worker.js +0 -283
  101. package/browser-extension/setup-content.js +0 -36
  102. package/browser-extension/tokens.css +0 -326
  103. /package/{browser-extension/protocol.js → neural-interface/lib/browser-extension-protocol.js} +0 -0
@@ -22,6 +22,10 @@ const CROUCH = [26, 0.45]; // the take-off squash, rubbery
22
22
  const SCALE = [14, 0.72];
23
23
  const ARRIVED = { px: 4, speed: 140 }; // close and slow enough for the beat to go on (the spring finishes on its own)
24
24
  const KEEP_OUT_MARGIN = 6; // px of clear board round what the mascot draws
25
+ // The face width (CSS px) the beats are choreographed for: a place's `scale` is relative to it, whatever size the
26
+ // host draws the face at (the empty state's hero is 280 × 140 since v2.3.0; the tour's places, its ink and its
27
+ // keep-outs were laid out round a 120 × 60 face, which a 320 px board has room for). Home is the face's own size.
28
+ const TOUR_FACE_W = 120;
25
29
 
26
30
  export function createActor(target, { reduced = () => false, onMove = null } = {}) {
27
31
  const rig = target.rig;
@@ -80,6 +84,13 @@ export function createActor(target, { reduced = () => false, onMove = null } = {
80
84
  return rect;
81
85
  }
82
86
 
87
+ /** The transform scale for a place: home (no point) is the face's own size, any other place the tour's face size times `scale`. */
88
+ function kFor(point, scale = 1) {
89
+ if (!point) return 1;
90
+ const w = base?.w;
91
+ return w > 0 ? scale * (TOUR_FACE_W / w) : scale;
92
+ }
93
+
83
94
  const tellMove = () => { if (onMove && base) try { onMove(boundsAt(s.x, s.y + s.arc, s.k)); } catch { /* the host's */ } };
84
95
 
85
96
  function write() {
@@ -146,7 +157,7 @@ export function createActor(target, { reduced = () => false, onMove = null } = {
146
157
  }
147
158
 
148
159
  /**
149
- * Fly to `point` (client px; null = home) at `scale`. Resolves once it has
160
+ * Fly to `point` (client px; null = home, at the face's own size) at `scale` (of TOUR_FACE_W). Resolves once it has
150
161
  * arrived closely enough for the next op (the landing finishes on its own),
151
162
  * at once under reduced motion or when there is no character on screen.
152
163
  */
@@ -154,7 +165,7 @@ export function createActor(target, { reduced = () => false, onMove = null } = {
154
165
  place = { point: point ? { ...point } : null, scale };
155
166
  if (!present()) return Promise.resolve();
156
167
  const c = readBase() ? { x: base.cx, y: base.cy } : layoutCentre();
157
- const to = { x: point ? point.x - c.x : 0, y: point ? point.y - c.y : 0, k: scale };
168
+ const to = { x: point ? point.x - c.x : 0, y: point ? point.y - c.y : 0, k: kFor(point, scale) };
158
169
  const dist = Math.hypot(to.x - s.x, to.y - s.y);
159
170
  Object.assign(goal, to);
160
171
  if (reduced()) {
@@ -196,7 +207,7 @@ export function createActor(target, { reduced = () => false, onMove = null } = {
196
207
  if (!svg) return null;
197
208
  if (!base) readBase();
198
209
  if (!base) return null;
199
- return boundsAt(point ? point.x - base.cx : 0, point ? point.y - base.cy : 0, scale, margin);
210
+ return boundsAt(point ? point.x - base.cx : 0, point ? point.y - base.cy : 0, kFor(point, scale), margin);
200
211
  }
201
212
 
202
213
  /** The face's client rect where it will land (its goal), for ink placed beside it. */
@@ -1,9 +1,35 @@
1
1
  import { KEYS } from './constants.js';
2
2
  import { trayColumnOf } from './ui-tray-columns.js';
3
3
 
4
+ // What a tray pill tells this toggle it must leave open: a tab whose close would destroy what the user cannot get
5
+ // back (a Claude Code temporary chat, an unsent draft). The panels decide; this module only asks. A pill says it
6
+ // twice: `pill.keepFromAutoClose()` is the live answer asked right before a close, and the attribute below is the
7
+ // signal the observer watches, so a reason that appears or goes away while the pill sits in Done is checked again
8
+ // at once. The user's own X asks neither. (Here, not in a module of their own: this one is loaded before the page
9
+ // is shown and the panels are not, tests/boot-critical-path.test.mjs.)
10
+ export const AUTO_CLOSE_KEEP_ATTR = 'data-auto-close-keep';
11
+
12
+ /** Whether a composer holds something unsent: text that is not only blanks, or any attachment list with an entry. */
13
+ export function composerHoldsDraft(text, ...attachments) {
14
+ return !!String(text ?? '').trim() || attachments.some(list => (list?.length || 0) > 0);
15
+ }
16
+
17
+ /** Writes a pill's reason ('' or none: nothing to keep), only when it changed (the toggle observes it). */
18
+ export function markAutoCloseKeep(pill, reason) {
19
+ if (!pill?.dataset) return;
20
+ const value = reason ? String(reason) : '';
21
+ if ((pill.dataset.autoCloseKeep || '') === value) return;
22
+ if (value) pill.dataset.autoCloseKeep = value;
23
+ else delete pill.dataset.autoCloseKeep;
24
+ }
25
+
4
26
  const agents = ['cp', 'cxp', 'ocpv2', 'agy', 'mtc'].map(prefix => prefix + '-session-pill');
5
27
  const excluded = ['asp-session-pill', 'sp-session-pill', 'sidepanel-tray-placeholder', 'ocpv2-session-pill-child'];
6
28
  const unfinishedOrFailed = /^(?:running|waiting|error|errored|failed)$/i;
29
+ // The provider a pill's automation run belongs to, by the pill's own class (a run the server no longer
30
+ // keeps names no provider: ui-native-loop-router.js autoCloseNativeLoopTab).
31
+ const runProviders = { 'cp-session-pill': 'claude-code', 'cxp-session-pill': 'codex', 'ocpv2-session-pill': 'opencode', 'agy-session-pill': 'antigravity' };
32
+ const runProviderOf = pill => runProviders[Object.keys(runProviders).find(name => pill.classList.contains(name))] || null;
7
33
 
8
34
  // Only direct provider pills can close. A collapsed Done column is still eligible.
9
35
  export function canAutoClose(pill, tray) {
@@ -12,8 +38,9 @@ export function canAutoClose(pill, tray) {
12
38
  if (!agents.some(name => classes.contains(name)) || excluded.some(name => classes.contains(name))) return false;
13
39
  if (pill.querySelector('.cli-status-badge') || unfinishedOrFailed.test(pill.dataset.status) ||
14
40
  /\S+-pill-(?:error|errored|failed)(?:\s|$)/.test(pill.className)) return false;
15
- // The producer may have started another turn or queued a prompt before the next frame.
16
- return trayColumnOf(pill) === 'done' && !pill.hasQueuedWorkerPrompts?.();
41
+ // The producer may have started another turn or queued a prompt before the next frame. A pill whose close
42
+ // would destroy what the user cannot get back (a temporary chat, an unsent draft) says so (AUTO_CLOSE_KEEP_ATTR).
43
+ return trayColumnOf(pill) === 'done' && !pill.hasQueuedWorkerPrompts?.() && !pill.keepFromAutoClose?.();
17
44
  }
18
45
 
19
46
  export function initTrayAutoClose(tray, button, storage, t, closeAutomationTab) {
@@ -49,11 +76,14 @@ export function initTrayAutoClose(tray, button, storage, t, closeAutomationTab)
49
76
  if (x) {
50
77
  requested.add(pill); // Some close handlers remove the pill asynchronously.
51
78
  const runId = pill.getAutomationRunId?.();
52
- if (!runId) { x.click(); return; }
79
+ // A pill whose X destroys something (OpenCode's deletes the session) has a close of its own for this.
80
+ if (!runId && !pill.detachForAutoClose) { x.click(); return; }
53
81
  // An idle automation also appears in Done. Its X is a deliberate stop.
54
82
  // Only the conditional completion path may dismiss it automatically.
55
- try { await closeAutomationTab?.(runId); }
56
- finally { requested.delete(pill); }
83
+ try {
84
+ if (runId) await closeAutomationTab?.(runId, runProviderOf(pill));
85
+ else await pill.detachForAutoClose();
86
+ } finally { requested.delete(pill); }
57
87
  }
58
88
  }
59
89
 
@@ -102,7 +132,7 @@ export function initTrayAutoClose(tray, button, storage, t, closeAutomationTab)
102
132
  button.classList.toggle('active', enabled);
103
133
  if (enabled) {
104
134
  observer.observe(tray, { subtree: true, childList: true, attributes: true, attributeOldValue: true,
105
- attributeFilter: ['data-tray-col', 'data-status', 'class', 'style', 'hidden'] });
135
+ attributeFilter: ['data-tray-col', 'data-status', 'class', 'style', 'hidden', AUTO_CLOSE_KEEP_ATTR] });
106
136
  for (const pill of [...tray.children]) reconcile(pill, immediate);
107
137
  } else {
108
138
  observer.disconnect();
@@ -56,6 +56,7 @@ import { historyHasResultSupport, historyResultsNotice, snapshotWantsResults, fu
56
56
  import { CP_STYLES } from './cp/cp-styles.js';
57
57
  import { TEMPORARY_CAPABILITY, keepsNothing, chooseTemporary, applyTemporary, temporaryRefusal, endTemporary, leaveTemporary, tabAfterTemporary, persistableTabs, temporaryBlocks, reattaches } from './cp/cp-temporary.js';
58
58
  import { paintTemporary } from './cp/cp-temporary-view.js';
59
+ import { composerHoldsDraft, markAutoCloseKeep } from './tray-auto-close.js';
59
60
  import { renderMarkdown } from './cp/cp-markdown.js';
60
61
  import { synabunToolKey, synabunToolLabel, synabunToolSummary, synabunToolGroup } from './synabun-tools.js';
61
62
  import { normalizeToolHeartbeat } from './tool-heartbeat.js';
@@ -3250,6 +3251,7 @@ function _createTrayPill(tab) {
3250
3251
  pill.className = 'term-minimized-pill cp-session-pill';
3251
3252
  pill.dataset.tabId = tab.id;
3252
3253
  pill.getAutomationRunId = () => tab.automationRunId;
3254
+ pill.keepFromAutoClose = () => _autoCloseKeep(tab);
3253
3255
  pill.innerHTML = `
3254
3256
  <span class="cp-pill-ring" aria-hidden="true"><i></i></span>
3255
3257
  <span class="term-minimized-pill-icon">${_CP_ICON_SVG}</span>
@@ -3344,6 +3346,22 @@ function paintPillState(pill, tab) {
3344
3346
  const needsYou = tabNeedsYou(tab);
3345
3347
  pill.classList.toggle('cp-pill-attention', needsYou);
3346
3348
  pill.classList.toggle('cp-pill-running', !needsYou && tabWorking(tab));
3349
+ markAutoCloseKeep(pill, _autoCloseKeep(tab));
3350
+ }
3351
+
3352
+ /**
3353
+ * What the tray's auto-close must leave open (tray-auto-close.js), or '': a temporary chat,
3354
+ * whose close ends it for good (it keeps no transcript), and a tab holding an unsent draft (its text, in the
3355
+ * composer while the tab is the one on screen, and its attached images and files). The user's X closes both.
3356
+ * Also a tab with prompts in its queue that were never sent: a paused queue, one stranded behind another
3357
+ * conversation, or the one being taken off it (`_queueSending`). renderQueue repaints the mark at every change.
3358
+ */
3359
+ function _autoCloseKeep(tab) {
3360
+ if (!tab) return '';
3361
+ if (keepsNothing(tab)) return 'temporary';
3362
+ if (tab.queue?.length || tab._queueSending) return 'queue';
3363
+ const $input = tab === activeTab() ? _panel?.querySelector('#cp-input') : null;
3364
+ return composerHoldsDraft($input ? $input.value : tab.draft, tab.attachedImages, tab.attachedFiles) ? 'draft' : '';
3347
3365
  }
3348
3366
 
3349
3367
  // Whether each tab was saved needing you: a change is written at once, for the placeholder a reload
@@ -9984,6 +10002,8 @@ function addToQueue(tab, text, images, files) {
9984
10002
  }
9985
10003
 
9986
10004
  function renderQueue(tab) {
10005
+ // The tray's auto-close keeps a tab while its queue holds prompts (_autoCloseKeep): said at every change.
10006
+ if (tab?.pillEl) markAutoCloseKeep(tab.pillEl, _autoCloseKeep(tab));
9987
10007
  if (tab !== activeTab()) return;
9988
10008
  const $tray = _panel?.querySelector('#cp-queue-tray');
9989
10009
  const $items = $tray?.querySelector('.cp-queue-items');
@@ -294,9 +294,51 @@ async function routeLatest(runId) {
294
294
  return false;
295
295
  }
296
296
 
297
- /** Tray timer: a missing descriptor, unfinished task or refused completion keeps its tab. */
298
- export async function autoCloseNativeLoopTab(runId) {
299
- const run = getNativeLoopRun(runId);
297
+ /**
298
+ * A run a tab still names and this window no longer follows, as the server has it: `over` when it
299
+ * ended or the server keeps it no more (its ledger never drops a live run), with its descriptor when
300
+ * there is one; null when the server did not say.
301
+ */
302
+ async function readUnfollowedRun(runId) {
303
+ try {
304
+ const response = await fetch(`/api/sidepanel-runs/${encodeURIComponent(runId)}`);
305
+ if (response.status === 404) return { over: true, run: null };
306
+ if (!response.ok) return null;
307
+ const data = await response.json();
308
+ const run = descriptorFrom(data) || descriptorFrom(data?.run);
309
+ return run?.runId === runId ? { over: TERMINAL_STATUSES.has(run.status), run } : null;
310
+ } catch {
311
+ return null;
312
+ }
313
+ }
314
+
315
+ /**
316
+ * Tray timer: an unfinished task or a refused completion keeps its tab.
317
+ *
318
+ * A tab can name a run this window follows no more: the user continued the run's session by hand
319
+ * (OpenCode keeps the run on the tab, and the tab let the run go: 'native-loop:dismissed'), or a reload
320
+ * brought the tab back and not its run (reconcileRuns restores ended runs of the last day, ten at
321
+ * most). The server is asked about such a run: once it is over its tab is detached like any ended
322
+ * run's (the session and its transcript stay with the provider; nothing is stopped or deleted), and it
323
+ * stays while the run lives or the server did not answer. `provider` is the panel the tab is in, for a
324
+ * run the server keeps no more.
325
+ */
326
+ export async function autoCloseNativeLoopTab(runId, provider = null) {
327
+ if (!runId) return;
328
+ let run = getNativeLoopRun(runId);
329
+ if (!run) {
330
+ const read = await readUnfollowedRun(runId);
331
+ // Followed again meanwhile (a reconcile attached it): decided below, like any run this window follows.
332
+ run = getNativeLoopRun(runId);
333
+ if (!run) {
334
+ const panel = read?.over ? (read.run?.provider || provider) : null;
335
+ if (!panel) return;
336
+ forgetWorkerEnd(runId);
337
+ window.dispatchEvent(new CustomEvent('native-loop:dismissed', { detail: { runId } }));
338
+ await detachProviderRun(runId, panel);
339
+ return;
340
+ }
341
+ }
300
342
  if (!(await mayAutoCloseWorkerTab(run)) || _dismissed.has(runId)) return;
301
343
  forgetWorkerEnd(runId);
302
344
  window.dispatchEvent(new CustomEvent('native-loop:dismissed', { detail: { runId } }));
@@ -194,6 +194,10 @@ export function createStickyScrollController(container, options = {}) {
194
194
  if (remaining > 0.5) scrollToBottom();
195
195
  return;
196
196
  }
197
+ // Detached: only a scroll back down near the bottom follows again. An animated key or wheel scroll upward
198
+ // (WebKit's PageUp / ArrowUp) can step 1 px or less, under movedUp's 1 px; treating that step as "near the
199
+ // bottom" re-attached and the follow frame snapped the reader back, cancelling their scroll.
200
+ if (nextScrollTop < prevScrollTop) return;
197
201
  if (refreshPosition()) scrollToBottom();
198
202
  };
199
203
  const onWheel = (event) => {