synabun 2.4.4 → 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 (59) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +1 -1
  3. package/docs/browser-extension-bridge.md +5 -4
  4. package/docs/whatsapp.md +3 -3
  5. package/mcp-server/dist/services/neural-interface.d.ts +1 -0
  6. package/mcp-server/dist/services/neural-interface.d.ts.map +1 -1
  7. package/mcp-server/dist/services/neural-interface.js +1 -0
  8. package/mcp-server/dist/services/neural-interface.js.map +1 -1
  9. package/mcp-server/dist/tools/agents.d.ts +16 -3
  10. package/mcp-server/dist/tools/agents.d.ts.map +1 -1
  11. package/mcp-server/dist/tools/agents.js +74 -11
  12. package/mcp-server/dist/tools/agents.js.map +1 -1
  13. package/mcp-server/package-lock.json +2 -2
  14. package/mcp-server/package.json +1 -1
  15. package/mcp-server/src/services/neural-interface.ts +2 -1
  16. package/mcp-server/src/tools/agents.ts +67 -11
  17. package/neural-interface/i18n/en.json +349 -9
  18. package/neural-interface/i18n/pt-BR.json +349 -9
  19. package/neural-interface/lib/agents-studio-api.js +7 -2
  20. package/neural-interface/lib/antigravity/home.js +43 -8
  21. package/neural-interface/lib/antigravity/tool-call.js +14 -0
  22. package/neural-interface/lib/assistant-brains/antigravity.js +4 -2
  23. package/neural-interface/lib/assistant-persona.js +8 -3
  24. package/neural-interface/lib/assistant-route-gate.js +11 -2
  25. package/neural-interface/lib/assistant-runtime.js +16 -5
  26. package/neural-interface/lib/assistant-spilled-output.js +53 -0
  27. package/neural-interface/lib/browser-default.js +22 -2
  28. package/neural-interface/lib/browser-extension-bridge.js +50 -3
  29. package/neural-interface/lib/browser-extension-pin.json +7 -7
  30. package/neural-interface/lib/browser-extension-protocol.js +30 -1
  31. package/neural-interface/lib/browser-extension-setup.js +204 -36
  32. package/neural-interface/lib/remote-policy.js +24 -7
  33. package/neural-interface/lib/teams/README.md +22 -1
  34. package/neural-interface/lib/teams/api.js +79 -6
  35. package/neural-interface/lib/teams/index.js +2 -0
  36. package/neural-interface/lib/teams/recovery.js +68 -0
  37. package/neural-interface/lib/teams/scheduler.js +349 -29
  38. package/neural-interface/lib/teams/worktrees.js +123 -30
  39. package/neural-interface/package-lock.json +2 -2
  40. package/neural-interface/package.json +1 -1
  41. package/neural-interface/public/extension-setup.html +6 -2
  42. package/neural-interface/public/shared/agents/studio/ax-api.js +16 -0
  43. package/neural-interface/public/shared/agents/studio/ax-teams-view.js +318 -13
  44. package/neural-interface/public/shared/agents/studio/ax-teams.js +141 -9
  45. package/neural-interface/public/shared/browser-extension-updates.js +3 -1
  46. package/neural-interface/public/shared/extension-setup/es-page.js +23 -4
  47. package/neural-interface/public/shared/extension-setup/es-view.js +51 -11
  48. package/neural-interface/public/shared/extension-update-view.js +1 -1
  49. package/neural-interface/public/shared/settings/settings-ai-browser.js +23 -3
  50. package/neural-interface/public/shared/settings/settings-browser-extension.js +575 -197
  51. package/neural-interface/public/shared/settings/settings-extension-diagrams.js +116 -0
  52. package/neural-interface/public/shared/settings/settings-extension-guide.js +222 -0
  53. package/neural-interface/public/shared/settings/settings-ia.js +2 -2
  54. package/neural-interface/public/shared/settings/settings-shell.js +5 -0
  55. package/neural-interface/public/shared/styles.css +196 -13
  56. package/neural-interface/public/shared/ui-settings.js +48 -11
  57. package/neural-interface/server.js +20 -1
  58. package/npm-shrinkwrap.json +2 -2
  59. package/package.json +1 -1
@@ -0,0 +1,116 @@
1
+ // The guide's close-ups of a browser's Extensions page (Settings → Browser → the extension's setup guide): original
2
+ // vector drawings of the one control each step asks for, with a ring and a leader to it and its name beside it. They are
3
+ // a picture of where to look, never the instruction itself: every step says the same in HTML outside the drawing, and
4
+ // each figure carries its own caption. No imports, no DOM: node --test reads the markup.
5
+ //
6
+ // Placement is drawn only where it is known: Developer mode sits at the top right of the Extensions header in Chrome,
7
+ // Brave, Arc, Vivaldi and Chromium, and in the left sidebar in Edge. Any other browser gets the switch by its label,
8
+ // with a caption that says the picture is a Chrome-style example (developerLayout, settings-extension-guide.js).
9
+ // Colours are classes (styles.css → "browser-extension-guide"), so the drawing follows Settings' tokens.
10
+ import { developerLayout } from './settings-extension-guide.js';
11
+
12
+ const esc = s => String(s ?? '').replace(/[&<>"']/g, c => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
13
+ const rect = (x, y, w, h, cls, r = 6) => `<rect x="${x}" y="${y}" width="${w}" height="${h}" rx="${r}" class="${cls}"/>`;
14
+ const text = (x, y, value, size, cls = 'bg-t', anchor = 'start') => `<text x="${x}" y="${y}" font-size="${size}" class="${cls}"${anchor !== 'start' ? ` text-anchor="${anchor}"` : ''}>${esc(value)}</text>`;
15
+ const line = (d, cls = 'bg-ln') => `<path d="${d}" class="${cls}"/>`;
16
+ const toggle = (x, y) => `${rect(x, y, 40, 22, 'bg-track', 11)}<circle cx="${x + 29}" cy="${y + 11}" r="8" class="bg-knob"/>`;
17
+ const ring = (x, y, w, h) => `${rect(x, y, w, h, 'bg-halo', 8)}${rect(x, y, w, h, 'bg-ring', 8)}`;
18
+ // A label's width in the drawing, from its length (a little wider than the panel's fonts set it): translations run
19
+ // longer than English, and the boxes grow with them.
20
+ const textWidth = (value, size) => Math.round(String(value).length * size * 0.56);
21
+ const width = (value, size, pad = 24, max = 220) => Math.min(max, textWidth(value, size) + pad);
22
+ const button = (x, y, value, size = 12) => { const w = width(value, size); return { w, svg: `${rect(x, y, w, 27, 'bg-panel', 6)}${text(x + 12, y + 18, value, size)}` }; };
23
+ // The largest size, from `size` down to 10, at which `value` fits in `room`; past that it is squeezed into `room`
24
+ // (SVG textLength), never drawn wider.
25
+ const fitText = (value, size, room) => {
26
+ let s = size; while (s > 10 && textWidth(value, s) > room) s -= 0.5;
27
+ const w = textWidth(value, s);
28
+ return w > room ? { size: s, w: room, squeeze: true } : { size: s, w, squeeze: false };
29
+ };
30
+
31
+ // The Developer mode label where developerGeometry put it (squeezed to its width when even 10 px is too wide).
32
+ const devText = (at, value) => `<text x="${at.x}" y="${at.y}" font-size="${at.size}" class="bg-t"${at.squeeze ? ` textLength="${at.w}" lengthAdjust="spacingAndGlyphs"` : ''}>${esc(value)}</text>`;
33
+
34
+ /** The switch's track: TOGGLE_W wide. */
35
+ export const TOGGLE_W = 40;
36
+ /**
37
+ * Where the Developer mode label, its switch and the ring around both go (Step 2's drawing), from the label's own
38
+ * width: the switch always after the label with a gap, the ring around both with the same margin on each side. In
39
+ * Edge's sidebar the sidebar grows with the label (to SIDEBAR_MAX), and the divider and the installed-extensions panel
40
+ * move right with it; in the Chrome-style header the label grows to the left of the switch. All in viewBox units
41
+ * (520 × 166). Pure: the tests check that nothing overlaps in any locale.
42
+ */
43
+ export const SIDEBAR_MAX = 262;
44
+ export function developerGeometry(layout, label) {
45
+ const gap = 16;
46
+ if (layout === 'sidebar') {
47
+ const textX = 28, toggleY = 90, toggleMax = SIDEBAR_MAX - 14 - TOGGLE_W;
48
+ const fit = fitText(label, 13, toggleMax - gap - textX), textW = fit.w;
49
+ const toggleX = Math.max(146, textX + textW + gap), toggleEnd = toggleX + TOGGLE_W;
50
+ const ring = { x: textX - 8, y: 82, w: toggleEnd + 8 - (textX - 8), h: 39 };
51
+ const sideEnd = Math.max(208, toggleEnd + 14);
52
+ const panelX = sideEnd + 18;
53
+ return { layout, text: { x: textX, y: 106, w: textW, size: fit.size, squeeze: fit.squeeze }, toggle: { x: toggleX, y: toggleY, w: TOGGLE_W }, ring, sideEnd, panel: { x: panelX, w: 479 - panelX } };
54
+ }
55
+ const toggleX = 444, toggleEnd = toggleX + TOGGLE_W, pad = 10;
56
+ // The label may grow left up to the page title's end ("Extensions", 18px, at x 32) with room to spare.
57
+ const fit = fitText(label, 13, toggleX - gap - 160), textW = fit.w, textX = toggleX - gap - textW;
58
+ return { layout, text: { x: textX, y: 49, w: textW, size: fit.size, squeeze: fit.squeeze }, toggle: { x: toggleX, y: 33, w: TOGGLE_W }, ring: { x: textX - pad, y: 25, w: toggleEnd + pad - (textX - pad), h: 38 }, header: { x: 15, w: 490 } };
59
+ }
60
+
61
+ /**
62
+ * The figure for a guide step (2 Developer mode, 3 Load unpacked, 5 Details, 6 Allow user scripts), or null for a step
63
+ * without one. `t(key)` gives the translated string of browserExtension.guide.<key> (unescaped); `browser`: { id, name }.
64
+ * Returns { html, layout }: the <figure> with its header, drawing and caption.
65
+ */
66
+ export function guideFigure(step, { browser, address = '', t }) {
67
+ const id = browser?.id || '', name = browser?.name || '';
68
+ const ui = key => t(`ui.${key}`);
69
+ let art = '', caption = '', label = '', layout = '';
70
+ if (step === 2) {
71
+ layout = developerLayout(id);
72
+ const dev = ui('developerMode');
73
+ const geo = developerGeometry(layout === 'sidebar' ? 'sidebar' : 'header', dev), r = geo.ring;
74
+ if (layout === 'sidebar') {
75
+ const side = geo.sideEnd, panel = geo.panel;
76
+ art = rect(14, 12, 492, 128, 'bg-frame', 8) + rect(15, 13, side - 15, 126, 'bg-surface', 7) + line(`M${side} 13v126`) + text(28, 38, ui('extensions'), 16, 'bg-t bg-strong')
77
+ + text(28, 63, ui('manage'), 12, 'bg-t bg-muted') + line(`M28 77h${side - 46}`) + devText(geo.text, dev) + toggle(geo.toggle.x, geo.toggle.y) + ring(r.x, r.y, r.w, r.h)
78
+ + text(panel.x, 40, ui('installed'), 15) + rect(panel.x, 54, panel.w, 56, 'bg-surface', 6) + text(panel.x + 14, 86, ui('bridgeName'), 13, 'bg-t bg-muted')
79
+ + line('M108 123v28h60', 'bg-lead') + text(176, 156, t('figDeveloperCall'), 13, 'bg-t bg-call');
80
+ caption = t('figDeveloperEdge'); label = t('figDeveloperEdgeName');
81
+ } else {
82
+ art = rect(14, 17, 492, 109, 'bg-frame', 8) + rect(15, 18, 490, 50, 'bg-surface', 7) + line('M15 68h490') + text(32, 49, ui('extensions'), 18, 'bg-t bg-strong')
83
+ + devText(geo.text, dev) + toggle(geo.toggle.x, geo.toggle.y) + ring(r.x, r.y, r.w, r.h) + text(32, 100, ui('mine'), 14, 'bg-t bg-muted')
84
+ + line('M414 65v64l-11 12h-52', 'bg-lead') + text(345, 146, t('figDeveloperCall'), 14, 'bg-t bg-call', 'end');
85
+ caption = layout === 'header' ? t('figDeveloperHeader', { browser: name }) : t('figDeveloperUnverified', { browser: name });
86
+ label = t('figDeveloperName');
87
+ }
88
+ } else if (step === 3) {
89
+ const load = button(33, 74, ui('loadUnpacked')), pack = button(33 + load.w + 12, 74, ui('pack')), update = button(33 + load.w + pack.w + 24, 74, ui('update'));
90
+ art = rect(14, 15, 492, 113, 'bg-frame', 8) + text(32, 47, ui('extensions'), 18, 'bg-t bg-strong') + text(445, 45, ui('developerMode'), 12, 'bg-t bg-muted', 'end')
91
+ + rect(457, 32, 29, 16, 'bg-on', 8) + '<circle cx="478" cy="40" r="6" class="bg-knob-off"/>' + line('M15 58h490')
92
+ + load.svg + (33 + load.w + pack.w + 24 + update.w < 500 ? pack.svg + update.svg : '') + ring(28, 68, load.w + 10, 39)
93
+ + line(`M${33 + Math.round(load.w / 2)} 109v32h${Math.max(20, 122 - Math.round(load.w / 2))}`, 'bg-lead') + text(160, 146, t('figLoadCall'), 14, 'bg-t bg-call');
94
+ caption = t('figLoad'); label = t('figLoadName');
95
+ } else if (step === 5) {
96
+ const details = button(44, 85, ui('details')), remove = button(44 + details.w + 14, 85, ui('remove'));
97
+ art = rect(25, 12, 471, 119, 'bg-surface', 9) + rect(42, 28, 42, 42, 'bg-frame', 8) + '<path d="M52 44h22M52 54h22" class="bg-mark"/>'
98
+ + text(99, 45, ui('bridgeName'), 17, 'bg-t bg-strong') + text(99, 64, ui('bridgeMeta'), 12, 'bg-t bg-muted') + details.svg + remove.svg
99
+ + rect(444, 91, 32, 18, 'bg-on', 9) + '<circle cx="467" cy="100" r="6.5" class="bg-knob-off"/>' + ring(39, 79, details.w + 10, 39)
100
+ + line(`M${44 + Math.round(details.w / 2)} 120v25h${Math.max(20, 114 - Math.round(details.w / 2))}`, 'bg-lead') + text(165, 150, t('figDetailsCall'), 14, 'bg-t bg-call');
101
+ caption = t('figDetails'); label = t('figDetailsName');
102
+ } else if (step === 6) {
103
+ art = rect(14, 15, 492, 112, 'bg-frame', 8) + text(32, 43, ui('bridgeName'), 16, 'bg-t bg-strong') + text(32, 64, ui('extensionDetails'), 12, 'bg-t bg-muted')
104
+ + line('M15 75h490') + text(32, 106, ui('allowUserScripts'), 15) + toggle(444, 86) + ring(437, 81, 54, 32)
105
+ + line('M464 115v28h-74', 'bg-lead') + text(384, 148, t('figScriptsCall'), 14, 'bg-t bg-call', 'end');
106
+ caption = t('figScripts'); label = t('figScriptsName');
107
+ } else return null;
108
+ const titleId = `bc-guide-fig-${step}`;
109
+ const tour = { 2: layout === 'sidebar' ? t('tourSidebar') : layout === 'header' ? t('tourHeader') : t('tourExample'), 3: t('tourToolbar'), 5: t('tourCard'), 6: t('tourDetails') }[step];
110
+ const html = `<figure class="bc-guide-figure" data-figure-step="${step}" data-layout="${layout || 'fixed'}">
111
+ <div class="bc-guide-figure-head"><strong>${esc(name)}</strong><span>${esc(tour)}</span>${address ? `<code dir="ltr">${esc(address)}</code>` : ''}</div>
112
+ <svg class="bc-guide-art" viewBox="0 0 520 166" role="img" aria-labelledby="${titleId}" focusable="false"><title id="${titleId}">${esc(label)}</title>${art}</svg>
113
+ <figcaption>${esc(caption)}</figcaption>
114
+ </figure>`;
115
+ return { html, layout: layout || 'fixed' };
116
+ }
@@ -0,0 +1,222 @@
1
+ // Settings → Browser → My browser · use the extension: what the card and its six-step guide decide, without the DOM
2
+ // (node --test loads this file; settings-browser-extension.js renders what it returns). No imports.
3
+ //
4
+ // The finish line is not "a socket is open". It is: the expected extension, in the browser the owner chose, on a live
5
+ // bridge, running the folder's current copy, and reporting that the browser lets it use user scripts (the extension's
6
+ // own probe, browser-extension/service-worker.js: it calls chrome.userScripts.getScripts() and looks for `execute`,
7
+ // and never runs a script in a tab). Anything short of that is said as the step it still needs.
8
+ //
9
+ // Evidence comes from two reads: GET /api/browser/extension (`connected`, `paired`, `extensionVersion`, `reloadNeeded`,
10
+ // `capabilities`: the current peer's last report or null) and GET …/setup/status (`state`, `code`, `browser`,
11
+ // `pairedThrough`: the browser whose setup made the pairing). An extension from before the report (1.5.0) sends no
12
+ // `capabilities`: its scripts access is unknown, never assumed. A server from before the report (one not restarted
13
+ // after an update) has no `capabilities` key at all: its connection is only "connected", never a legacy peer.
14
+ //
15
+ // A setup's download error belongs to that setup (the guide's Step 4, Advanced): a live bridge is never shown as
16
+ // "Offline" or "Package unavailable" because a Repair or a Set up after it could not download.
17
+
18
+ /** The guide's pages, in order. Page 7 is Ready. */
19
+ export const GUIDE_STEPS = Object.freeze(['open', 'developer', 'load', 'folder', 'details', 'scripts']);
20
+ export const READY_STEP = GUIDE_STEPS.length + 1;
21
+ /** The first extension version that reports its scripts capability. */
22
+ export const CAPABILITY_VERSION = '1.6.0';
23
+ /** The setup's download errors, each with its own stage. */
24
+ const DOWNLOAD_STAGES = Object.freeze({ EXTENSION_DOWNLOAD_OFFLINE: 'offline', EXTENSION_DOWNLOAD_UNAVAILABLE: 'package-unavailable', EXTENSION_VERIFY_FAILED: 'verification-failed' });
25
+ /**
26
+ * Every stage the card can be in. The ladder is not-set-up → detected → allow-scripts → ready; the rest say why the
27
+ * ladder stopped. `rung`: how far up the ladder the stage is (the status symbol); `step`: the guide page that resolves it.
28
+ */
29
+ export const STAGES = Object.freeze({
30
+ loading: { rung: 0, tone: '', step: 1 },
31
+ 'not-set-up': { rung: 0, tone: '', step: 1 },
32
+ downloading: { rung: 0, tone: 'sync', step: 4 },
33
+ offline: { rung: 0, tone: 'err', step: 4 },
34
+ 'package-unavailable': { rung: 0, tone: 'err', step: 4 },
35
+ 'verification-failed': { rung: 0, tone: 'err', step: 4 },
36
+ pairing: { rung: 0, tone: 'sync', step: 4 },
37
+ disconnected: { rung: 0, tone: 'warn', step: 1 },
38
+ 'other-browser': { rung: 0, tone: 'warn', step: 1 },
39
+ detected: { rung: 1, tone: 'sync', step: 5 },
40
+ 'allow-scripts': { rung: 2, tone: 'warn', step: 6 },
41
+ 'reload-required': { rung: 1, tone: 'warn', step: 6 },
42
+ 'browser-update': { rung: 1, tone: 'err', step: 6 },
43
+ 'legacy-peer': { rung: 1, tone: 'warn', step: 6 },
44
+ // Connected, through a server that cannot report what the extension may do (it predates the report): no action.
45
+ connected: { rung: 1, tone: 'ok', step: READY_STEP },
46
+ ready: { rung: 3, tone: 'ok', step: READY_STEP },
47
+ error: { rung: 0, tone: 'err', step: 1 },
48
+ });
49
+
50
+ /** a.b.c version compare: negative, 0 or positive (missing parts are 0). */
51
+ export function compareVersions(a, b) {
52
+ const pa = String(a || '').split('.').map(n => Number.parseInt(n, 10) || 0), pb = String(b || '').split('.').map(n => Number.parseInt(n, 10) || 0);
53
+ for (let i = 0; i < Math.max(pa.length, pb.length); i++) { const d = (pa[i] || 0) - (pb[i] || 0); if (d) return d; }
54
+ return 0;
55
+ }
56
+
57
+ // Which installed-browser ids a reported brand can be. A Chromium build that names only "Chromium" may be Chromium,
58
+ // Arc or Vivaldi (both hide their own name from the brand list), so it rules out only the browsers that do name themselves.
59
+ const BRAND_IDS = Object.freeze([
60
+ [/^brave$/i, ['brave']], [/^microsoft edge$/i, ['edge']], [/^opera( gx)?$/i, ['opera']], [/^vivaldi$/i, ['vivaldi']],
61
+ [/^arc$/i, ['arc']], [/^google chrome$/i, ['chrome']],
62
+ ]);
63
+ const GENERIC = ['chromium', 'arc', 'vivaldi'];
64
+ /** The browser ids the peer's reported brands allow, or null when it reported none. */
65
+ export function brandCandidates(capabilities) {
66
+ const brands = Array.isArray(capabilities?.browser?.brands) ? capabilities.browser.brands.map(String) : [];
67
+ if (!brands.length) return null;
68
+ for (const [pattern, ids] of BRAND_IDS) if (brands.some(b => pattern.test(b.trim()))) return ids;
69
+ return brands.some(b => /^chromium$/i.test(b.trim())) ? GENERIC : null;
70
+ }
71
+ /**
72
+ * Whether the connected peer is in the browser the owner chose: 'match', 'mismatch' or 'unknown'. A bridge paired from
73
+ * one browser never counts for another: a brand that names another browser, or a pairing a setup made for another
74
+ * browser that the brand does not overrule, is a mismatch. A brand that only says "Chromium" names the target only
75
+ * when the setup that paired says so, or when the target is the one installed browser it could be (`installed`: the
76
+ * ids of the installed browsers, when known).
77
+ */
78
+ export function peerIdentity(target, capabilities, pairedThrough, installed = null) {
79
+ if (!target) return 'unknown';
80
+ let brands = brandCandidates(capabilities);
81
+ const through = pairedThrough?.id || null;
82
+ if (brands && !brands.includes(target)) return 'mismatch';
83
+ if (brands && brands.length > 1 && Array.isArray(installed) && installed.length) brands = brands.filter(id => installed.includes(id));
84
+ const single = !!brands && brands.length === 1 && brands[0] === target;
85
+ if (through && through !== target && !single) return 'mismatch';
86
+ if (single || through === target) return 'match';
87
+ return 'unknown';
88
+ }
89
+
90
+ /**
91
+ * The card's stage. `data`: GET /api/browser/extension (null when the read failed); `setup`: the setup status (null
92
+ * when none ran); `target`: the installed browser the owner chose; `failed`: the last read failed.
93
+ */
94
+ export function extensionStage({ data = null, setup = null, target = null, failed = false, installed = null } = {}) {
95
+ if (!data) return failed ? 'error' : 'loading';
96
+ const running = setup?.state || data.setup || 'idle';
97
+ const forTarget = !target || !setup?.browser?.id || setup.browser.id === target;
98
+ if (!data.connected) {
99
+ // Only while nothing is connected: a failed download never hides a live bridge (it stays in Step 4 and Advanced).
100
+ if (running === 'error' && forTarget && DOWNLOAD_STAGES[setup?.code]) return DOWNLOAD_STAGES[setup.code];
101
+ if (running === 'downloading' && forTarget) return 'downloading';
102
+ if (running === 'pairing' && forTarget) return 'pairing';
103
+ if (failed) return 'error';
104
+ return data.paired ? 'disconnected' : 'not-set-up';
105
+ }
106
+ if (peerIdentity(target, data.capabilities, setup?.pairedThrough, installed) === 'mismatch') return 'other-browser';
107
+ if (data.reloadNeeded === true) return 'reload-required';
108
+ // No `capabilities` key: a server from before the report, not a peer from before it (a current server sends null).
109
+ if (!Object.hasOwn(data, 'capabilities')) return 'connected';
110
+ const caps = data.capabilities;
111
+ if (!caps || !caps.userScripts) {
112
+ // An extension older than the report never sends one; a current one sends it right after it connects.
113
+ return data.extensionVersion && compareVersions(data.extensionVersion, CAPABILITY_VERSION) >= 0 ? 'detected' : 'legacy-peer';
114
+ }
115
+ const state = caps.userScripts.state;
116
+ if (state === 'unsupported') return 'browser-update';
117
+ if (state === 'ready') return peerIdentity(target, caps, setup?.pairedThrough, installed) === 'match' ? 'ready' : 'detected';
118
+ return 'allow-scripts';
119
+ }
120
+
121
+ /** The verification list of the Ready page: each check and whether the evidence holds it. */
122
+ export function readyChecks({ data = null, setup = null, target = null, installed = null } = {}) {
123
+ const caps = data?.capabilities;
124
+ return [
125
+ { key: 'peer', ok: !!data?.connected && peerIdentity(target, caps, setup?.pairedThrough, installed) === 'match' },
126
+ { key: 'live', ok: !!data?.connected },
127
+ { key: 'reload', ok: !!data?.connected && data.reloadNeeded !== true },
128
+ { key: 'scripts', ok: caps?.userScripts?.state === 'ready' },
129
+ ];
130
+ }
131
+
132
+ /**
133
+ * The page the guide moves to when the evidence changes (never backwards: the owner's Back stays where they put it).
134
+ * `step`: the page shown; `stage`: the new stage; `previous`: the stage the last move was decided on.
135
+ */
136
+ export function branchStep(step, stage, previous = null) {
137
+ if (stage === previous) return step;
138
+ if (stage === 'ready') return READY_STEP;
139
+ const wanted = STAGES[stage]?.step || 1;
140
+ // Evidence that the extension is in the browser moves an install still under way to its Details step.
141
+ if (['detected', 'allow-scripts', 'reload-required', 'browser-update', 'legacy-peer'].includes(stage) && step <= 4) return 5;
142
+ // A lapse after Ready (the extension asks for scripts again, a reload, an update) goes to the page that fixes it; a
143
+ // browser that is only away keeps the Ready page, whose checklist then names what is missing.
144
+ if (step === READY_STEP && wanted >= 4 && wanted < READY_STEP) return wanted;
145
+ return step;
146
+ }
147
+ /** The page the guide opens on for a stage (Resume setup, Review setup, Allow user scripts …). */
148
+ export function entryStep(stage, saved = 0) {
149
+ if (stage === 'ready') return READY_STEP;
150
+ const wanted = STAGES[stage]?.step || 1;
151
+ if (wanted >= 5) return wanted;
152
+ return saved >= 1 && saved < READY_STEP ? saved : wanted;
153
+ }
154
+
155
+ /** The status word, help, symbol and main action for a stage. Keys are under browserExtension.card. */
156
+ export function stageView(stage, { savedStep = 0, legacyServer = false } = {}) {
157
+ const meta = STAGES[stage] || STAGES.error;
158
+ const status = {
159
+ loading: 'stageLoading', 'not-set-up': 'stageNotSetUp', downloading: 'stageDownloading', offline: 'stageOffline',
160
+ 'package-unavailable': 'stagePackageUnavailable', 'verification-failed': 'stageVerifyFailed', pairing: 'stagePairing',
161
+ disconnected: 'stageDisconnected', 'other-browser': 'stageOtherBrowser', detected: 'stageDetected', 'allow-scripts': 'stageAllowScripts',
162
+ 'reload-required': 'stageReload', 'browser-update': 'stageBrowserUpdate', 'legacy-peer': 'stageLegacy', connected: 'stageConnected', ready: 'stageReady', error: 'stageError',
163
+ }[stage] || 'stageError';
164
+ // The chosen browser's extension is connected (rung 1 and up): never offered the older server's "Connect your
165
+ // browser", which opens the setup page and the folder again; nor any action while the server cannot check it.
166
+ const cta = stage === 'connected' ? null
167
+ : legacyServer ? (stage === 'disconnected' ? 'ctaReconnect' : stage === 'error' ? 'retry' : meta.rung >= 1 ? null : 'ctaConnect')
168
+ : stage === 'ready' ? 'ctaReview'
169
+ : stage === 'disconnected' ? 'ctaReconnect'
170
+ : stage === 'allow-scripts' ? 'ctaAllowScripts'
171
+ : stage === 'detected' ? 'ctaDetails'
172
+ : ['offline', 'package-unavailable', 'verification-failed', 'error'].includes(stage) ? 'retry'
173
+ : ['reload-required', 'browser-update', 'legacy-peer', 'pairing', 'downloading'].includes(stage) ? 'ctaResume'
174
+ : savedStep > 1 ? 'ctaResume' : 'ctaSetUp';
175
+ return { status, help: `${status}Help`, tone: meta.tone, rung: meta.rung, cta };
176
+ }
177
+
178
+ /** The keys to paste an address with, on this computer. */
179
+ export function pasteKeys(platform = '') {
180
+ return /mac|darwin|iphone|ipad/i.test(String(platform)) ? ['⌘L', '⌘V', 'Return'] : ['Ctrl+L', 'Ctrl+V', 'Enter'];
181
+ }
182
+ /** 'mac', 'windows' or 'linux' for a platform word (the server's inventory or the page's navigator). */
183
+ export function osOf(platform = '') {
184
+ const p = String(platform || '').toLowerCase();
185
+ return /mac|darwin|iphone|ipad/.test(p) ? 'mac' : /win/.test(p) ? 'windows' : 'linux';
186
+ }
187
+ /** Where Developer mode is on a browser's Extensions page: verified layouts only; anything else names the switch only. */
188
+ export function developerLayout(browserId) {
189
+ if (browserId === 'edge') return 'sidebar';
190
+ return ['chrome', 'brave', 'arc', 'vivaldi', 'chromium'].includes(browserId) ? 'header' : 'unverified';
191
+ }
192
+
193
+ /** The browser the card offers first: the saved choice while installed, else the server's suggestion, else the first. */
194
+ export function pickTarget(inventory, saved = null) {
195
+ const list = Array.isArray(inventory?.installedBrowsers) ? inventory.installedBrowsers.filter(b => b?.id) : [];
196
+ if (saved && list.some(b => b.id === saved)) return saved;
197
+ if (inventory?.suggested && list.some(b => b.id === inventory.suggested)) return inventory.suggested;
198
+ return list[0]?.id || null;
199
+ }
200
+ /** The short name the guide uses ("Brave", "Chrome", "Edge"): the catalog's names carry the vendor. */
201
+ export function shortName(browser) {
202
+ const name = String(browser?.name || '').trim();
203
+ return { 'Google Chrome': 'Chrome', 'Microsoft Edge': 'Edge' }[name] || name;
204
+ }
205
+
206
+ // ── what the guide remembers between openings (the chosen browser and how far each browser got) ──
207
+ export const GUIDE_STORE_KEY = 'synabun.browserBridgeGuide';
208
+ /** Progress older than this is not resumed (the browser is still remembered). */
209
+ export const GUIDE_STORE_MS = 6 * 60 * 60 * 1000;
210
+ export function readGuideStore(raw, now = Date.now()) {
211
+ let value; try { value = JSON.parse(raw || 'null'); } catch { value = null; }
212
+ if (!value || typeof value !== 'object') return { target: null, open: false, progress: {} };
213
+ const fresh = Number(value.at) > 0 && now - Number(value.at) < GUIDE_STORE_MS;
214
+ const progress = {};
215
+ if (fresh && value.progress && typeof value.progress === 'object') {
216
+ for (const [id, step] of Object.entries(value.progress)) if (/^[a-z]{2,12}$/.test(id) && Number.isInteger(step) && step >= 1 && step <= READY_STEP) progress[id] = step;
217
+ }
218
+ return { target: typeof value.target === 'string' && /^[a-z]{2,12}$/.test(value.target) ? value.target : null, open: fresh && value.open === true, progress };
219
+ }
220
+ export function writeGuideStore({ target, open, progress }, now = Date.now()) {
221
+ return JSON.stringify({ target: target || null, open: !!open, progress: progress || {}, at: now });
222
+ }
@@ -265,8 +265,8 @@ export const SETTINGS_CONTROLS = {
265
265
  'stg-sec-maintenance': 'MEM008 MEM012 MEM013 MEM014 MEM001 MEM015 MEM016',
266
266
  'stg-sec-workspaces': 'PRJ013 PRJ007 PRJ008 PRJ009 PRJ010 PRJ011 PRJ014 PRJ015 PRJ016 PRJ017 PRJ018',
267
267
  'project-storage-manager': 'PRJ001 PRJ012 PRJ002 PRJ003 PRJ004 PRJ005 PRJ006',
268
- 'setup-browser': 'BRW003 BRW001 BRW002 BRW084 BRW004 BRW005 BRW006 BRW007 BRW008 BRW009',
269
- 'bcg-profiles': 'BRW011 BRW012 BRW083 BRW010 BRW015 BRW016 BRW017 BRW018 BRW019 BRW020',
268
+ 'setup-browser': 'BRW011 BRW003 BRW001 BRW002 BRW084 BRW004 BRW005 BRW006 BRW007 BRW008 BRW009',
269
+ 'bcg-profiles': 'BRW012 BRW083 BRW010 BRW015 BRW016 BRW017 BRW018 BRW019 BRW020',
270
270
  'bcg-owner-access': 'BRW087',
271
271
  'bcg-identity': 'BRW021 BRW022 BRW023 BRW024 BRW025',
272
272
  'bcg-viewport': 'BRW026 BRW027 BRW028 BRW029 BRW030 BRW031 BRW032',
@@ -55,8 +55,13 @@ export function storeSectionState(section) {
55
55
  /**
56
56
  * Open every closed ancestor of `el` (collapsible cards, <details>, a project's panel, a block behind its own tab),
57
57
  * then `el` itself. Nothing is remembered: the sections the user left open or closed stay as stored.
58
+ *
59
+ * First `el` announces itself with a bubbling `settings-reveal` event: a pane that shows something in place of its
60
+ * content (the Browser page's setup guide, settings-browser-extension.js) steps aside, synchronously, for a target
61
+ * outside it, so a deep link or a search result always lands on what it names.
58
62
  */
59
63
  export function revealSettingsTarget(overlay, el) {
64
+ try { el?.dispatchEvent?.(new CustomEvent('settings-reveal', { bubbles: true })); } catch { /* no event support: nothing steps aside */ }
60
65
  for (let node = el; node && node !== overlay; node = node.parentElement) {
61
66
  if (node.matches?.('[data-collapsible].collapsed')) node.classList.remove('collapsed');
62
67
  if (node.tagName === 'DETAILS' && !node.open) node.open = true;