synabun 2.4.6 → 2.4.7

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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neural-memory-interface",
3
- "version": "2.4.6",
3
+ "version": "2.4.7",
4
4
  "private": true,
5
5
  "description": "Private local SynaBun interface for memory visualization and multi-agent workflows",
6
6
  "license": "Apache-2.0",
@@ -0,0 +1,124 @@
1
+ // ═══════════════════════════════════════════
2
+ // SynaBun Neural Interface — the notice that launches keep failing on a browser profile: what it says
3
+ // ═══════════════════════════════════════════
4
+ //
5
+ // When the launches of one browser profile (a MoreLogin profile, a local one) fail several times in a row, the
6
+ // server keeps one notice for it (lib/morelogin-launch-recovery.js, GET /api/system/launch-blocks): which profile,
7
+ // how many launches, the error, what SynaBun did about it and what fixes it. The owner's pages show it until a
8
+ // launch works there again or the owner dismisses it: one notice for the streak, never one per run. This module
9
+ // decides the words; ui-launch-block-notice.js asks the server and draws them.
10
+ //
11
+ // The fix it names is the one that matches what failed:
12
+ // - restart: the profile's browser does not answer, or a tab in it froze (SynaBun restarts such a profile itself
13
+ // once; it is named when that did not help, or was not allowed: another automation had a tab there);
14
+ // - start-limit: MoreLogin's plan allows no more starts today;
15
+ // - check: anything else (the profile is gone, MoreLogin is closed, …).
16
+ //
17
+ // No imports and no DOM: `node --test` loads this file as it is (tests/launch-block-view.test.mjs).
18
+ // LAUNCH_BLOCK_COPY is the English of every sentence; `launchBlock.*` in i18n/en.json must equal it and
19
+ // i18n/pt-BR.json must have the same keys.
20
+
21
+ export const LAUNCH_BLOCK_COPY = Object.freeze({
22
+ label: 'Runs keep failing to start in a browser profile',
23
+ title: 'Runs in {profile} keep failing to start.',
24
+ countToday: '{count} launches in a row failed, the last at {time}.',
25
+ countEarlier: '{count} launches in a row failed, the last on {date} at {time}.',
26
+ launches: 'Last affected: {names}.',
27
+ errorTitle: 'What the browser answered',
28
+ restartedFailed: 'SynaBun restarted the profile once at {time} and the next launch failed too.',
29
+ restartFailed: 'SynaBun tried to restart the profile at {time} and could not.',
30
+ notRestarted: 'SynaBun did not restart the profile.',
31
+ fixTitle: 'How to fix it',
32
+ fixRestart: 'Stop the profile and start it again, in MoreLogin or in Settings → Connected tools → MoreLogin. If the tab the error names opens again and freezes, close it.',
33
+ fixStartLimit: 'MoreLogin allows no more starts of this profile today. Wait for its daily reset, raise the plan, or keep the profile open so runs need no new start.',
34
+ fixCheck: 'Check the profile in MoreLogin or in Settings → Connected tools → MoreLogin: that it still exists, that MoreLogin is open, and that it starts.',
35
+ profileNamed: '"{name}"',
36
+ profileById: 'profile {id}',
37
+ dismiss: 'Dismiss',
38
+ });
39
+
40
+ /** The fix sentence for each fix the server names. */
41
+ export const LAUNCH_BLOCK_FIX_KEYS = Object.freeze({ restart: 'fixRestart', 'start-limit': 'fixStartLimit', check: 'fixCheck' });
42
+
43
+ /** A sentence of LAUNCH_BLOCK_COPY in English with its {values} filled; an unknown key is itself. */
44
+ export function fillLaunchBlockCopy(key, params = {}) {
45
+ const text = Object.prototype.hasOwnProperty.call(LAUNCH_BLOCK_COPY, key) ? LAUNCH_BLOCK_COPY[key] : key;
46
+ return text.replace(/\{(\w+)\}/g, (whole, name) => (params[name] != null ? String(params[name]) : whole));
47
+ }
48
+
49
+ const ID = /^[0-9a-f]{16,32}$/;
50
+ const FIXES = new Set(Object.keys(LAUNCH_BLOCK_FIX_KEYS));
51
+ const FAILED_RESTARTS = new Set(['stop-failed', 'start-failed']);
52
+ const line = (value, max) => (typeof value === 'string' ? value.replace(/[\u0000-\u001f]+/g, ' ').trim().slice(0, max) : '');
53
+ const time = (value) => (Number.isFinite(Number(value)) && Number(value) > 0 ? Number(value) : null);
54
+
55
+ /**
56
+ * The notices in an answer of GET /api/system/launch-blocks (or a `schedule:launch-blocked` message: both carry
57
+ * `notices`), each checked field by field; what is not a notice is left out.
58
+ */
59
+ export function readLaunchBlockNotices(answer) {
60
+ const list = answer && typeof answer === 'object' && Array.isArray(answer.notices) ? answer.notices : [];
61
+ const out = [];
62
+ for (const notice of list) {
63
+ if (!notice || typeof notice !== 'object' || typeof notice.id !== 'string' || !ID.test(notice.id)) continue;
64
+ const envId = line(String(notice.envId ?? ''), 128);
65
+ if (!envId) continue;
66
+ const recovery = notice.recovery && typeof notice.recovery === 'object' && time(notice.recovery.at) && typeof notice.recovery.outcome === 'string'
67
+ ? { at: time(notice.recovery.at), outcome: line(notice.recovery.outcome, 32) } : null;
68
+ out.push({
69
+ id: notice.id, envId, name: line(notice.name, 200),
70
+ count: Number.isInteger(notice.count) && notice.count > 0 ? Math.min(notice.count, 9999) : 1,
71
+ lastAt: time(notice.lastAt), error: line(notice.error, 600),
72
+ fix: FIXES.has(notice.fix) ? notice.fix : 'check',
73
+ launches: (Array.isArray(notice.launches) ? notice.launches : []).map((name) => line(name, 120)).filter(Boolean).slice(0, 5),
74
+ recovery,
75
+ });
76
+ if (out.length >= 10) break;
77
+ }
78
+ return out;
79
+ }
80
+
81
+ /** When something happened, in the reader's locale: { today, date, time } (the date is for another day). */
82
+ export function launchBlockTimeParts(at, { now = Date.now(), locale = undefined } = {}) {
83
+ const when = new Date(at);
84
+ if (!Number.isFinite(when.getTime())) return null;
85
+ const day = new Date(now);
86
+ const today = when.getFullYear() === day.getFullYear() && when.getMonth() === day.getMonth() && when.getDate() === day.getDate();
87
+ const format = (fn, options, fallback) => { try { return fn.call(when, locale, options); } catch { return fallback; } };
88
+ return {
89
+ today,
90
+ date: format(Date.prototype.toLocaleDateString, { dateStyle: 'medium' }, when.toISOString().slice(0, 10)),
91
+ time: format(Date.prototype.toLocaleTimeString, { hour: '2-digit', minute: '2-digit' }, when.toISOString().slice(11, 16)),
92
+ };
93
+ }
94
+
95
+ /**
96
+ * What one notice shows, or null: { id, label, title, count, launches, errorTitle, error, did, fixTitle, fix,
97
+ * actions[] }. `t(key, params)` is a sentence of LAUNCH_BLOCK_COPY in the page's language.
98
+ */
99
+ export function launchBlockView(notice, { t = fillLaunchBlockCopy, now = Date.now(), locale = undefined } = {}) {
100
+ if (!notice || typeof notice !== 'object' || !notice.id) return null;
101
+ const profile = notice.name ? t('profileNamed', { name: notice.name }) : t('profileById', { id: notice.envId });
102
+ const last = launchBlockTimeParts(notice.lastAt, { now, locale }) || { today: true, date: '', time: '' };
103
+ const restart = notice.recovery ? launchBlockTimeParts(notice.recovery.at, { now, locale }) : null;
104
+ // What SynaBun did is said only for the fix it belongs to: a restart that did not help, or one it could not make.
105
+ let did = '';
106
+ if (notice.fix === 'restart') {
107
+ if (notice.recovery?.outcome === 'restarted-retry-failed' && restart) did = t('restartedFailed', { time: restart.time });
108
+ else if (FAILED_RESTARTS.has(notice.recovery?.outcome) && restart) did = t('restartFailed', { time: restart.time });
109
+ else did = t('notRestarted');
110
+ }
111
+ return {
112
+ id: notice.id,
113
+ label: t('label'),
114
+ title: t('title', { profile }),
115
+ count: t(last.today ? 'countToday' : 'countEarlier', { count: notice.count, date: last.date, time: last.time }),
116
+ launches: notice.launches?.length ? t('launches', { names: notice.launches.join(', ') }) : '',
117
+ errorTitle: t('errorTitle'),
118
+ error: notice.error || '',
119
+ did,
120
+ fixTitle: t('fixTitle'),
121
+ fix: t(LAUNCH_BLOCK_FIX_KEYS[notice.fix] || 'fixCheck'),
122
+ actions: [{ id: 'dismiss', label: t('dismiss') }],
123
+ };
124
+ }
@@ -30012,6 +30012,23 @@
30012
30012
  .update-check-toast:not(.crash-notice) ~ .crash-notice,
30013
30013
  .crash-notice:has(~ .update-check-toast:not(.crash-notice)) { bottom: auto; top: 64px; }
30014
30014
  @media (prefers-reduced-motion: reduce) { .crash-notice { transition: none; } }
30015
+ /* The notice that launches keep failing on a browser profile (ui-launch-block-notice.js): the crash notice's toast,
30016
+ one per profile, stacked at the top right so the bottom right stays the update toasts' and the crash notice's. */
30017
+ .launch-block-stack {
30018
+ position: fixed;
30019
+ top: 64px;
30020
+ right: 20px;
30021
+ z-index: 300050;
30022
+ display: flex;
30023
+ flex-direction: column;
30024
+ gap: var(--s-sm, 8px);
30025
+ max-height: calc(100vh - 84px);
30026
+ overflow-y: auto;
30027
+ pointer-events: none;
30028
+ }
30029
+ .launch-block-stack .launch-block-notice { position: static; max-height: none; pointer-events: auto; }
30030
+ .launch-block-notice .launch-block-error { color: var(--t-primary); }
30031
+ .launch-block-notice .launch-block-did { margin-top: 6px; }
30015
30032
  /* The banner of a degraded owner authority (ui-owner-authority.js): the update toast's glass and type (DESIGN.md
30016
30033
  `toast`), at the top centre of the page so it never meets the bottom-right toasts, which replace each other (it is
30017
30034
  not an .update-check-toast for that reason), non-modal (nothing behind it is blocked), with the warning tint of the
@@ -0,0 +1,155 @@
1
+ // ═══════════════════════════════════════════
2
+ // SynaBun Neural Interface — the notice that launches keep failing on a browser profile: the page side
3
+ // ═══════════════════════════════════════════
4
+ //
5
+ // Asks GET /api/system/launch-blocks when the page starts and every time its sync socket connects, and is told of
6
+ // every change at once (`schedule:launch-blocked`, ui-sync.js). What launch-block-view.js says is drawn in the crash
7
+ // notice's shape (styles.css .update-check-toast, .crash-notice, .launch-block-notice: top right, so the bottom
8
+ // right stays the update toasts'), one notice per profile, once the loading screen is gone. It stays until a launch
9
+ // works on the profile again (the server then sends a list without it) or the owner dismisses it (POST
10
+ // /api/system/launch-blocks/dismiss, which tells every other window). Never asked by an invite guest and never
11
+ // drawn for one: /api/system is the owner's, and the server sends `schedule:` messages to the owner's pages only.
12
+ // An older server answers 404: then there is nothing to show.
13
+
14
+ import { on } from './state.js';
15
+ import { getLocale, t } from './i18n.js';
16
+ import { isGuest } from './ui-sync.js';
17
+ import { launchBlockView, readLaunchBlockNotices } from './launch-block-view.js';
18
+
19
+ const NOTICE_URL = '/api/system/launch-blocks';
20
+ const WRITE = Object.freeze({ 'Content-Type': 'application/json', 'X-SynaBun-UI': '1', Accept: 'application/json' });
21
+ const STACK_ID = 'launch-block-notices';
22
+
23
+ const translate = (key, params) => t(`launchBlock.${key}`, params);
24
+
25
+ let _wired = false;
26
+ let _asking = null;
27
+ let _guest = false;
28
+ let _notices = []; // what the server last said
29
+ const _dismissed = new Set(); // dismissed here while the server is asked
30
+
31
+ const guestPage = () => _guest || isGuest();
32
+
33
+ function esc(value) {
34
+ return String(value ?? '').replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
35
+ }
36
+
37
+ /** The loading screen covers the page while it starts: the notices wait for it to go. */
38
+ function whenPageShown(run) {
39
+ const overlay = document.getElementById('loading-overlay');
40
+ if (!overlay || overlay.classList.contains('hidden')) { run(); return; }
41
+ const watch = new MutationObserver(() => {
42
+ if (!overlay.classList.contains('hidden')) return;
43
+ watch.disconnect();
44
+ run();
45
+ });
46
+ watch.observe(overlay, { attributes: true, attributeFilter: ['class'] });
47
+ }
48
+
49
+ function stack() {
50
+ let el = document.getElementById(STACK_ID);
51
+ if (!el) {
52
+ el = document.createElement('div');
53
+ el.id = STACK_ID;
54
+ el.className = 'launch-block-stack';
55
+ document.body.appendChild(el);
56
+ }
57
+ return el;
58
+ }
59
+
60
+ function card(view) {
61
+ const el = document.createElement('div');
62
+ el.className = 'update-check-toast crash-notice launch-block-notice';
63
+ el.setAttribute('role', 'status');
64
+ el.setAttribute('aria-label', view.label);
65
+ el.dataset.noticeId = view.id;
66
+ el.innerHTML = `
67
+ <div class="utc-icon utc-icon--err" aria-hidden="true">!</div>
68
+ <div class="utc-body">
69
+ <div class="utc-title">${esc(view.title)}</div>
70
+ <div class="utc-sub">${esc(view.count)}</div>
71
+ ${view.launches ? `<div class="utc-sub">${esc(view.launches)}</div>` : ''}
72
+ ${view.error ? `<div class="crash-notice-lost-title">${esc(view.errorTitle)}</div><div class="utc-sub launch-block-error">${esc(view.error)}</div>` : ''}
73
+ ${view.did ? `<div class="utc-sub launch-block-did">${esc(view.did)}</div>` : ''}
74
+ <div class="crash-notice-lost-title">${esc(view.fixTitle)}</div>
75
+ <div class="utc-sub">${esc(view.fix)}</div>
76
+ <div class="update-notice-actions">${view.actions.map((item) => `<button class="action-btn action-btn--ghost crash-notice-btn" type="button" data-launch-block-action="${esc(item.id)}">${esc(item.label)}</button>`).join('')}</div>
77
+ </div>`;
78
+ el.querySelector('[data-launch-block-action="dismiss"]')?.addEventListener('click', (event) => {
79
+ event.stopPropagation();
80
+ dismiss(view.id);
81
+ });
82
+ return el;
83
+ }
84
+
85
+ /** Draw exactly the notices that hold now: a card that is still wanted stays as it is (no flicker, focus kept). */
86
+ function draw() {
87
+ const wanted = guestPage() ? [] : _notices.filter((notice) => !_dismissed.has(notice.id));
88
+ const existing = document.getElementById(STACK_ID);
89
+ if (!wanted.length) { existing?.remove(); return; }
90
+ const host = stack();
91
+ const keep = new Set(wanted.map((notice) => notice.id));
92
+ for (const el of [...host.children]) if (!keep.has(el.dataset.noticeId)) el.remove();
93
+ for (const notice of wanted) {
94
+ const view = launchBlockView(notice, { t: translate, locale: getLocale() });
95
+ if (!view) continue;
96
+ const fresh = card(view);
97
+ const old = [...host.children].find((el) => el.dataset.noticeId === notice.id);
98
+ if (old) {
99
+ // Same notice, newer numbers: its text is replaced in place.
100
+ if (old.innerHTML !== fresh.innerHTML) {
101
+ fresh.classList.add('show');
102
+ old.replaceWith(fresh);
103
+ }
104
+ } else {
105
+ host.appendChild(fresh);
106
+ requestAnimationFrame(() => fresh.classList.add('show'));
107
+ }
108
+ }
109
+ }
110
+
111
+ function present(notices) {
112
+ _notices = notices;
113
+ for (const id of [..._dismissed]) if (!notices.some((notice) => notice.id === id)) _dismissed.delete(id);
114
+ whenPageShown(draw);
115
+ }
116
+
117
+ /** Ask the server; an older server (404) or a guest (403) has nothing to say. */
118
+ export function checkLaunchBlocks() {
119
+ if (guestPage()) return Promise.resolve([]);
120
+ if (_asking) return _asking;
121
+ _asking = (async () => {
122
+ try {
123
+ const res = await fetch(NOTICE_URL, { headers: { Accept: 'application/json' }, cache: 'no-store' });
124
+ if (!res.ok) return [];
125
+ const notices = readLaunchBlockNotices(await res.json());
126
+ present(notices);
127
+ return notices;
128
+ } catch {
129
+ return [];
130
+ }
131
+ })().finally(() => { _asking = null; });
132
+ return _asking;
133
+ }
134
+
135
+ async function dismiss(id) {
136
+ _dismissed.add(id);
137
+ draw();
138
+ try {
139
+ const res = await fetch(`${NOTICE_URL}/dismiss`, { method: 'POST', headers: WRITE, body: JSON.stringify({ id }) });
140
+ if (res.ok) present(readLaunchBlockNotices(await res.json()));
141
+ } catch { /* the server is away: this page keeps it dismissed */ }
142
+ }
143
+
144
+ /** Wire the notices once: ask now, and again every time the sync socket connects. */
145
+ export function initLaunchBlockNotice() {
146
+ if (_wired) return;
147
+ _wired = true;
148
+ on('session:info', (info) => {
149
+ _guest = !!info?.isGuest;
150
+ if (_guest) present([]);
151
+ else checkLaunchBlocks();
152
+ });
153
+ on('sync:schedule:launch-blocked', (message) => { if (!guestPage()) present(readLaunchBlockNotices(message)); });
154
+ checkLaunchBlocks();
155
+ }
@@ -431,6 +431,17 @@ export function initNavbar() {
431
431
  initToolUpdates();
432
432
  // ── The notice after an automatic restart (the server crashed and its supervisor started it again) ──
433
433
  initCrashNotice();
434
+ // ── The notice that launches keep failing on a browser profile (one per profile, not one per run). It loads
435
+ // once the page is idle: nothing before the page is shown waits for it (tests/boot-critical-path.test.mjs),
436
+ // and it asks the server as it starts, so a notice raised meanwhile is not missed. The idle wait has a
437
+ // timeout: a page left in a hidden tab may never be idle, and still loads it within a few seconds ──
438
+ const LAUNCH_BLOCK_NOTICE_WITHIN_MS = 3000;
439
+ const whenIdle = typeof window.requestIdleCallback === 'function'
440
+ ? (run) => window.requestIdleCallback(run, { timeout: LAUNCH_BLOCK_NOTICE_WITHIN_MS })
441
+ : (run) => setTimeout(run, 1200);
442
+ whenIdle(() => {
443
+ import('./ui-launch-block-notice.js').then((notice) => notice.initLaunchBlockNotice()).catch(() => {});
444
+ });
434
445
  // ── The banner while the server cannot identify its callers (macOS: the owner's actions are paused, 503) ──
435
446
  initOwnerAuthorityNotice();
436
447
  // ── The banner on a page the server refuses the owner's access (SynaBun's automation browser opened it) ──
@@ -196,6 +196,8 @@ const SYNC_HANDLERS = {
196
196
  'schedule:fired': (msg) => emit('sync:schedule:fired', msg),
197
197
  'schedule:completed': (msg) => emit('sync:schedule:completed', msg),
198
198
  'schedule:failed': (msg) => emit('sync:schedule:failed', msg),
199
+ // Launches keep failing on a browser profile, or no longer do: the one notice per profile (ui-launch-block-notice.js)
200
+ 'schedule:launch-blocked': (msg) => emit('sync:schedule:launch-blocked', msg),
199
201
  'schedule:deferred': (msg) => emit('sync:schedule:deferred', msg),
200
202
  'schedule:deferred-expired':(msg) => emit('sync:schedule:deferred-expired', msg),
201
203
  'schedule:timer-set': (msg) => emit('sync:schedule:timer-set', msg),