synabun 2.4.3 → 2.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +36 -0
- package/README.md +1 -1
- package/docs/browser-extension-bridge.md +66 -36
- package/docs/whatsapp.md +3 -3
- package/mcp-server/dist/http.d.ts.map +1 -1
- package/mcp-server/dist/http.js +8 -1
- package/mcp-server/dist/http.js.map +1 -1
- package/mcp-server/dist/services/identity.d.ts +2 -0
- package/mcp-server/dist/services/identity.d.ts.map +1 -1
- package/mcp-server/dist/services/identity.js +4 -0
- package/mcp-server/dist/services/identity.js.map +1 -1
- package/mcp-server/dist/services/memory-client.d.ts +5 -0
- package/mcp-server/dist/services/memory-client.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-client.js +21 -2
- package/mcp-server/dist/services/memory-client.js.map +1 -1
- package/mcp-server/dist/services/memory-writer.d.ts +3 -0
- package/mcp-server/dist/services/memory-writer.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-writer.js +7 -1
- package/mcp-server/dist/services/memory-writer.js.map +1 -1
- package/mcp-server/dist/services/neural-interface.d.ts +12 -1
- package/mcp-server/dist/services/neural-interface.d.ts.map +1 -1
- package/mcp-server/dist/services/neural-interface.js +68 -17
- package/mcp-server/dist/services/neural-interface.js.map +1 -1
- package/mcp-server/dist/services/typesafe-config.d.ts +38 -2
- package/mcp-server/dist/services/typesafe-config.d.ts.map +1 -1
- package/mcp-server/dist/services/typesafe-config.js +260 -8
- package/mcp-server/dist/services/typesafe-config.js.map +1 -1
- package/mcp-server/dist/tools/agent-definition.d.ts +2 -2
- package/mcp-server/dist/tools/agents.d.ts +19 -4
- package/mcp-server/dist/tools/agents.d.ts.map +1 -1
- package/mcp-server/dist/tools/agents.js +85 -17
- package/mcp-server/dist/tools/agents.js.map +1 -1
- package/mcp-server/dist/tools/browser-observe.d.ts +11 -0
- package/mcp-server/dist/tools/browser-observe.d.ts.map +1 -1
- package/mcp-server/dist/tools/browser-observe.js +113 -27
- package/mcp-server/dist/tools/browser-observe.js.map +1 -1
- package/mcp-server/dist/tools/browser-readers.d.ts +6 -0
- package/mcp-server/dist/tools/browser-readers.d.ts.map +1 -0
- package/mcp-server/dist/tools/browser-readers.js +17 -0
- package/mcp-server/dist/tools/browser-readers.js.map +1 -0
- package/mcp-server/dist/tools/remember.d.ts.map +1 -1
- package/mcp-server/dist/tools/remember.js +6 -2
- package/mcp-server/dist/tools/remember.js.map +1 -1
- package/mcp-server/dist/tools/youtube/analytics.d.ts +4 -0
- package/mcp-server/dist/tools/youtube/analytics.d.ts.map +1 -1
- package/mcp-server/dist/tools/youtube/analytics.js +25 -20
- package/mcp-server/dist/tools/youtube/analytics.js.map +1 -1
- package/mcp-server/dist/tools/youtube/helpers.d.ts +5 -1
- package/mcp-server/dist/tools/youtube/helpers.d.ts.map +1 -1
- package/mcp-server/dist/tools/youtube/helpers.js +7 -3
- package/mcp-server/dist/tools/youtube/helpers.js.map +1 -1
- package/mcp-server/dist/tools/youtube/navigate.d.ts +2 -0
- package/mcp-server/dist/tools/youtube/navigate.d.ts.map +1 -1
- package/mcp-server/dist/tools/youtube/navigate.js +5 -3
- package/mcp-server/dist/tools/youtube/navigate.js.map +1 -1
- package/mcp-server/dist/tools/youtube/playlist.js +2 -2
- package/mcp-server/dist/tools/youtube/playlist.js.map +1 -1
- package/mcp-server/dist/tools/youtube/readers.d.ts +4 -0
- package/mcp-server/dist/tools/youtube/readers.d.ts.map +1 -0
- package/mcp-server/dist/tools/youtube/readers.js +15 -0
- package/mcp-server/dist/tools/youtube/readers.js.map +1 -0
- package/mcp-server/package-lock.json +2 -2
- package/mcp-server/package.json +1 -1
- package/mcp-server/src/http.ts +8 -1
- package/mcp-server/src/services/identity.ts +5 -0
- package/mcp-server/src/services/memory-client.ts +32 -12
- package/mcp-server/src/services/memory-writer.ts +5 -2
- package/mcp-server/src/services/neural-interface.ts +67 -19
- package/mcp-server/src/services/typesafe-config.ts +268 -7
- package/mcp-server/src/tools/agents.ts +79 -17
- package/mcp-server/src/tools/browser-observe.ts +117 -28
- package/mcp-server/src/tools/browser-readers.ts +19 -0
- package/mcp-server/src/tools/remember.ts +6 -1
- package/mcp-server/src/tools/youtube/analytics.ts +26 -28
- package/mcp-server/src/tools/youtube/helpers.ts +8 -2
- package/mcp-server/src/tools/youtube/navigate.ts +6 -7
- package/mcp-server/src/tools/youtube/playlist.ts +2 -2
- package/mcp-server/src/tools/youtube/readers.ts +15 -0
- package/neural-interface/i18n/en.json +487 -8
- package/neural-interface/i18n/pt-BR.json +487 -8
- package/neural-interface/lib/agents-studio-api.js +7 -2
- package/neural-interface/lib/antigravity/home.js +43 -8
- package/neural-interface/lib/antigravity/tool-call.js +14 -0
- package/neural-interface/lib/assistant-api.js +90 -0
- package/neural-interface/lib/assistant-brains/antigravity.js +4 -2
- package/neural-interface/lib/assistant-brains/claude.js +10 -0
- package/neural-interface/lib/assistant-dispatch.js +276 -42
- package/neural-interface/lib/assistant-memory.js +3 -1
- package/neural-interface/lib/assistant-persona.js +14 -3
- package/neural-interface/lib/assistant-route-gate.js +11 -2
- package/neural-interface/lib/assistant-router.js +18 -8
- package/neural-interface/lib/assistant-runtime.js +103 -6
- package/neural-interface/lib/assistant-spilled-output.js +53 -0
- package/neural-interface/lib/assistant-task-prompt.js +15 -2
- package/neural-interface/lib/browser-connection-state.js +20 -0
- package/neural-interface/lib/browser-default.js +22 -2
- package/neural-interface/lib/browser-extension-adapter.js +221 -15
- package/neural-interface/lib/browser-extension-bridge.js +89 -9
- package/neural-interface/lib/browser-extension-folder.js +50 -11
- package/neural-interface/lib/browser-extension-package.js +6 -5
- package/neural-interface/lib/browser-extension-pin.json +15 -13
- package/neural-interface/lib/browser-extension-protocol.js +141 -14
- package/neural-interface/lib/browser-extension-setup.js +210 -40
- package/neural-interface/lib/browser-extension-update.js +104 -0
- package/neural-interface/lib/browser-extraction.js +38 -14
- package/neural-interface/lib/claude-bg-tasks.js +183 -0
- package/neural-interface/lib/claude-history.js +12 -1
- package/neural-interface/lib/confined-fs.js +25 -0
- package/neural-interface/lib/coordination/operations.js +2 -0
- package/neural-interface/lib/db.js +39 -16
- package/neural-interface/lib/editor-completion-opencode.js +2 -2
- package/neural-interface/lib/git-bash/manager.js +28 -3
- package/neural-interface/lib/git-status-runner.js +31 -3
- package/neural-interface/lib/loop-inventory.js +162 -0
- package/neural-interface/lib/loop-stall.js +74 -4
- package/neural-interface/lib/memory-session-capture.js +157 -66
- package/neural-interface/lib/native-loop-providers.js +73 -13
- package/neural-interface/lib/native-loop-runtime.js +3 -0
- package/neural-interface/lib/opencode-protocol.js +4 -2
- package/neural-interface/lib/peer-identity.js +62 -16
- package/neural-interface/lib/remote-policy.js +24 -7
- package/neural-interface/lib/session-cache-builder.js +66 -18
- package/neural-interface/lib/session-capture-gate.js +42 -0
- package/neural-interface/lib/session-indexer.js +28 -20
- package/neural-interface/lib/teams/README.md +22 -1
- package/neural-interface/lib/teams/api.js +79 -6
- package/neural-interface/lib/teams/index.js +2 -0
- package/neural-interface/lib/teams/recovery.js +68 -0
- package/neural-interface/lib/teams/scheduler.js +352 -31
- package/neural-interface/lib/teams/worktrees.js +123 -30
- package/neural-interface/lib/ui-blob-api.js +14 -5
- package/neural-interface/lib/ui-blob-store.js +302 -39
- package/neural-interface/package-lock.json +2 -2
- package/neural-interface/package.json +1 -1
- package/neural-interface/public/extension-setup.html +7 -2
- package/neural-interface/public/shared/agents/studio/ax-api.js +16 -0
- package/neural-interface/public/shared/agents/studio/ax-teams-view.js +318 -13
- package/neural-interface/public/shared/agents/studio/ax-teams.js +141 -9
- package/neural-interface/public/shared/assistant/asst-agents-dock.js +4 -0
- package/neural-interface/public/shared/assistant/asst-api.js +42 -0
- package/neural-interface/public/shared/assistant/asst-composer.js +85 -12
- package/neural-interface/public/shared/assistant/asst-panel.js +285 -10
- package/neural-interface/public/shared/assistant/asst-render.js +205 -4
- package/neural-interface/public/shared/assistant/asst-scenes.js +12 -0
- package/neural-interface/public/shared/assistant/asst-sidepanel.js +18 -1
- package/neural-interface/public/shared/assistant/asst-state.js +241 -2
- package/neural-interface/public/shared/assistant/asst-steer.js +294 -0
- package/neural-interface/public/shared/assistant/asst-styles.js +20 -0
- package/neural-interface/public/shared/bg-tasks/bg-tasks-claude.js +147 -0
- package/neural-interface/public/shared/bg-tasks/bg-tasks-model.js +527 -0
- package/neural-interface/public/shared/bg-tasks/bg-tasks-panel.js +161 -0
- package/neural-interface/public/shared/bg-tasks/bg-tasks-view.js +508 -0
- package/neural-interface/public/shared/browser-extension-updates.js +90 -0
- package/neural-interface/public/shared/cp/cp-bg-tasks.js +130 -0
- package/neural-interface/public/shared/extension-setup/es-page.js +41 -15
- package/neural-interface/public/shared/extension-setup/es-view.js +51 -11
- package/neural-interface/public/shared/extension-update-view.js +34 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-shell-logic.js +8 -4
- package/neural-interface/public/shared/settings/settings-ai-browser.js +23 -3
- package/neural-interface/public/shared/settings/settings-browser-extension.js +581 -197
- package/neural-interface/public/shared/settings/settings-extension-diagrams.js +116 -0
- package/neural-interface/public/shared/settings/settings-extension-guide.js +222 -0
- package/neural-interface/public/shared/settings/settings-extension-update.js +114 -0
- package/neural-interface/public/shared/settings/settings-ia.js +2 -2
- package/neural-interface/public/shared/settings/settings-shell.js +5 -0
- package/neural-interface/public/shared/styles.css +200 -13
- package/neural-interface/public/shared/ui-claude-panel.js +110 -1
- package/neural-interface/public/shared/ui-notifications.js +23 -4
- package/neural-interface/public/shared/ui-settings-entry.js +6 -0
- package/neural-interface/public/shared/ui-settings.js +48 -11
- package/neural-interface/public/shared/ui-tray-columns.js +9 -2
- package/neural-interface/public/shared/worker-end.js +18 -0
- package/neural-interface/scripts/patch-node-pty.mjs +151 -0
- package/neural-interface/scripts/rebuild-pty.js +10 -0
- package/neural-interface/server.js +503 -281
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { extensionUpdateView } from './extension-update-view.js';
|
|
2
|
+
|
|
3
|
+
const listeners = new Set();
|
|
4
|
+
let current = null, revision = 0, reading = null;
|
|
5
|
+
export function acceptExtensionUpdate(update) {
|
|
6
|
+
revision++;
|
|
7
|
+
current = update;
|
|
8
|
+
for (const show of listeners) show(update);
|
|
9
|
+
}
|
|
10
|
+
export function watchExtensionUpdate(show) {
|
|
11
|
+
listeners.add(show); show(current);
|
|
12
|
+
return () => listeners.delete(show);
|
|
13
|
+
}
|
|
14
|
+
// Capture this before a read of either the full Settings card or the small notice endpoint.
|
|
15
|
+
// A slower response cannot overwrite a newer read or the response to an explicit action.
|
|
16
|
+
export function beginExtensionUpdateRead() {
|
|
17
|
+
const started = revision;
|
|
18
|
+
return update => { if (revision === started) acceptExtensionUpdate(update); };
|
|
19
|
+
}
|
|
20
|
+
// One owner-only read for all the notices. A slow read started before a click cannot undo its response.
|
|
21
|
+
export function refreshExtensionUpdate() {
|
|
22
|
+
if (reading) return reading;
|
|
23
|
+
const accept = beginExtensionUpdateRead();
|
|
24
|
+
reading = fetch('/api/browser/extension/update/status', { cache: 'no-store' }).then(async response => {
|
|
25
|
+
if (response.ok) {
|
|
26
|
+
const update = await response.json();
|
|
27
|
+
accept(update);
|
|
28
|
+
} else if ([401, 403, 404].includes(response.status)) accept(null);
|
|
29
|
+
}).catch(() => {}).finally(() => { reading = null; });
|
|
30
|
+
return reading;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// The update flow heads the extension card, in the Browser page's first card (Browser choice). An open setup guide
|
|
34
|
+
// steps aside for it (settings-browser-extension.js listens for settings-shell.js's settings-reveal).
|
|
35
|
+
export const extensionUpdateSettings = { tab: 'browser', expand: 'setup-browser', scrollTo: 'bc-extension-update-flow' };
|
|
36
|
+
export function openExtensionUpdate() {
|
|
37
|
+
return import('./ui-settings-entry.js').then(({ openSettingsModal }) => openSettingsModal(extensionUpdateSettings));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Emit only a change in the short banner, so progress polls cannot replace a focused action.
|
|
41
|
+
export function watchExtensionUpdateMention(tx, show) {
|
|
42
|
+
let previous = '';
|
|
43
|
+
return watchExtensionUpdate(update => {
|
|
44
|
+
const view = extensionUpdateView(update, tx);
|
|
45
|
+
const text = view?.due ? view.title : '';
|
|
46
|
+
if (text === previous) return;
|
|
47
|
+
previous = text;
|
|
48
|
+
show(text, { label: tx('browserExtension.updateFlow.review'), onClick: openExtensionUpdate });
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Only closing the notification dismisses it. Settings and the Assistant still offer the update in this session.
|
|
53
|
+
export function extensionUpdateToast({ tx, showNotice, session, open = openExtensionUpdate }) {
|
|
54
|
+
const storageKey = 'synabun-extension-update-dismissed';
|
|
55
|
+
let dismissed, visible, clear;
|
|
56
|
+
try { dismissed = session?.getItem(storageKey); } catch {}
|
|
57
|
+
return update => {
|
|
58
|
+
const view = extensionUpdateView(update, tx);
|
|
59
|
+
const show = view?.due && view.key !== dismissed;
|
|
60
|
+
const signature = show ? JSON.stringify([view.key, view.title]) : null;
|
|
61
|
+
if (signature === visible) return;
|
|
62
|
+
clear?.(); clear = null; visible = signature;
|
|
63
|
+
if (show) clear = showNotice({
|
|
64
|
+
title: view.title, action: tx('browserExtension.updateFlow.review'), closeLabel: tx('browserExtension.updateFlow.dismiss'),
|
|
65
|
+
onAction: open, onClose() {
|
|
66
|
+
dismissed = view.key;
|
|
67
|
+
try { session?.setItem(storageKey, dismissed); } catch {}
|
|
68
|
+
clear?.(); clear = null; visible = null;
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
export function startExtensionUpdateNotices({ tx, showNotice }) {
|
|
74
|
+
let session;
|
|
75
|
+
try { session = window.sessionStorage; } catch {}
|
|
76
|
+
watchExtensionUpdate(extensionUpdateToast({ tx, showNotice, session }));
|
|
77
|
+
let timer;
|
|
78
|
+
async function poll() {
|
|
79
|
+
clearTimeout(timer);
|
|
80
|
+
if (!document.hidden) await refreshExtensionUpdate();
|
|
81
|
+
clearTimeout(timer);
|
|
82
|
+
timer = setTimeout(poll, current && !['idle', 'done'].includes(current.phase) ? 2000 : 30000);
|
|
83
|
+
}
|
|
84
|
+
document.addEventListener('visibilitychange', poll);
|
|
85
|
+
if (window.location.hash === '#browser-extension-update') {
|
|
86
|
+
history.replaceState(history.state, '', location.pathname + location.search);
|
|
87
|
+
void refreshExtensionUpdate().then(openExtensionUpdate);
|
|
88
|
+
}
|
|
89
|
+
return poll();
|
|
90
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// ── Background tasks of a Claude Code panel tab (glue over public/shared/bg-tasks/) ──
|
|
2
|
+
//
|
|
3
|
+
// The registry, the view and the badges are the shared module's; this file only says where a Claude tab's
|
|
4
|
+
// pieces are: its session's routes (GET …/background-tasks and its output pages), the bridge's own Stop
|
|
5
|
+
// (`stop_task` on the tab's socket → the SDK's stopTask) and the tab's transcript for the notice cards.
|
|
6
|
+
|
|
7
|
+
import { createBgTasksPanel } from '../bg-tasks/bg-tasks-panel.js';
|
|
8
|
+
import { claudeFactsFromEvent, claudeLiveFact } from '../bg-tasks/bg-tasks-claude.js';
|
|
9
|
+
import { exitCodeOf, noticeCardView } from '../bg-tasks/bg-tasks-model.js';
|
|
10
|
+
import { markStaleNoticeCards, renderBgNoticeCard } from '../bg-tasks/bg-tasks-view.js';
|
|
11
|
+
|
|
12
|
+
const STOP_WAIT_MS = 15_000;
|
|
13
|
+
|
|
14
|
+
async function getJson(url) {
|
|
15
|
+
const res = await fetch(url, { headers: { Accept: 'application/json' }, credentials: 'same-origin' });
|
|
16
|
+
let body = null;
|
|
17
|
+
try { body = await res.json(); } catch { body = null; }
|
|
18
|
+
return { res, body };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The tab's background tasks: `tab.bg`. `project()` is the project its transcript is read under (the panel's
|
|
23
|
+
* _historyProject), `onChange` repaints its badges.
|
|
24
|
+
*/
|
|
25
|
+
export function attachClaudeBgTasks(tab, { storage = null, t = null, project = () => '', onChange = () => {}, onShownChange = () => {} } = {}) {
|
|
26
|
+
const query = () => {
|
|
27
|
+
const p = new URLSearchParams();
|
|
28
|
+
const proj = project() || '';
|
|
29
|
+
if (proj) p.set('project', proj);
|
|
30
|
+
if (tab.accountId) p.set('account', tab.accountId);
|
|
31
|
+
return p;
|
|
32
|
+
};
|
|
33
|
+
const base = () => (tab.sessionId ? `/api/claude-code/sessions/${encodeURIComponent(tab.sessionId)}/background-tasks` : '');
|
|
34
|
+
tab._bgStopWaits = tab._bgStopWaits || new Map();
|
|
35
|
+
tab.bg = createBgTasksPanel({
|
|
36
|
+
key: tab.sessionId ? `claude:${tab.sessionId}` : '',
|
|
37
|
+
factsOf: (ev) => claudeFactsFromEvent(ev),
|
|
38
|
+
liveFactOf: (tasks) => claudeLiveFact(tasks),
|
|
39
|
+
storage,
|
|
40
|
+
t,
|
|
41
|
+
onChange,
|
|
42
|
+
onShownChange,
|
|
43
|
+
api: {
|
|
44
|
+
async list() {
|
|
45
|
+
const url = base();
|
|
46
|
+
if (!url) return null;
|
|
47
|
+
const { res, body } = await getJson(`${url}?${query()}`);
|
|
48
|
+
// A server from before this view has no such route (its 404 names no code): its output waits for a restart.
|
|
49
|
+
if (res.status === 404 && !body?.code) return { unsupported: true };
|
|
50
|
+
return res.ok && body?.ok ? body : null;
|
|
51
|
+
},
|
|
52
|
+
async output({ taskId, cursor, tail, limit, running }) {
|
|
53
|
+
const url = base();
|
|
54
|
+
if (!url) return { ok: false, status: 404, error: 'No session yet.' };
|
|
55
|
+
const p = query();
|
|
56
|
+
if (cursor != null) p.set('cursor', String(cursor));
|
|
57
|
+
if (tail != null) p.set('tail', String(tail));
|
|
58
|
+
if (limit != null) p.set('limit', String(limit));
|
|
59
|
+
if (typeof running === 'boolean') p.set('running', running ? '1' : '0');
|
|
60
|
+
try {
|
|
61
|
+
const { res, body } = await getJson(`${url}/${encodeURIComponent(taskId)}/output?${p}`);
|
|
62
|
+
if (!res.ok || !body?.ok) return { ok: false, status: res.status, error: body?.error || 'The output could not be read.' };
|
|
63
|
+
return { status: 200, data: body };
|
|
64
|
+
} catch (err) { return { ok: false, status: 502, error: err?.message || 'The output could not be read.' }; }
|
|
65
|
+
},
|
|
66
|
+
// The bridge's own stop (the SDK's stopTask), never a kill typed by hand.
|
|
67
|
+
stop(taskId) {
|
|
68
|
+
const ws = tab.ws;
|
|
69
|
+
if (!ws || ws.readyState !== 1) return Promise.resolve({ ok: false, error: 'The session is not connected.' });
|
|
70
|
+
if (tab.capabilities instanceof Set && !tab.capabilities.has('task_control')) return Promise.resolve({ ok: false, error: 'Stopping a task from here needs the SynaBun server restart.' });
|
|
71
|
+
return new Promise((resolve) => {
|
|
72
|
+
const timer = setTimeout(() => { tab._bgStopWaits.delete(taskId); resolve({ ok: false, error: 'No answer from the session.' }); }, STOP_WAIT_MS);
|
|
73
|
+
tab._bgStopWaits.set(taskId, (out) => { clearTimeout(timer); resolve(out); });
|
|
74
|
+
try { ws.send(JSON.stringify({ type: 'stop_task', taskId })); }
|
|
75
|
+
catch (err) { clearTimeout(timer); tab._bgStopWaits.delete(taskId); resolve({ ok: false, error: err?.message || String(err) }); }
|
|
76
|
+
});
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
return tab.bg;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** The bridge answered a `stop_task` (task_control_result): the Stop that waited for it hears. → whether one did. */
|
|
84
|
+
export function settleClaudeBgStop(tab, msg) {
|
|
85
|
+
if (msg?.action !== 'stop_task' || !tab?._bgStopWaits?.size) return false;
|
|
86
|
+
const id = msg.taskId && tab._bgStopWaits.has(msg.taskId) ? msg.taskId : [...tab._bgStopWaits.keys()][0];
|
|
87
|
+
const done = tab._bgStopWaits.get(id);
|
|
88
|
+
tab._bgStopWaits.delete(id);
|
|
89
|
+
done?.({ ok: !!msg.ok, error: msg.error || '' });
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* The cards of a replayed `origin` row whose notices the server read (lib/claude-history.js `notifications`),
|
|
95
|
+
* linked to the task the registry knows (or what the notice says).
|
|
96
|
+
*/
|
|
97
|
+
export function historyNoticeCards(tab, row, t = null) {
|
|
98
|
+
const out = [];
|
|
99
|
+
const at = Date.parse(row?.timestamp || '') || 0;
|
|
100
|
+
for (const n of Array.isArray(row?.notifications) ? row.notifications : []) {
|
|
101
|
+
if (!n?.taskId) continue;
|
|
102
|
+
const task = tab?.bg?.registry?.().tasks.get(n.taskId) || null;
|
|
103
|
+
const view = noticeCardView({ taskId: n.taskId, type: n.event || /^monitor\b/i.test(n.summary || '') ? 'watch' : 'shell', status: n.status || (n.event ? 'event' : ''), summary: n.summary || '', event: n.event || '', exitCode: exitCodeOf(n.summary), stale: false }, task);
|
|
104
|
+
const card = renderBgNoticeCard(view, { t });
|
|
105
|
+
if (at) card.dataset.at = String(at);
|
|
106
|
+
if (view.isEvent) card.dataset.event = '1';
|
|
107
|
+
out.push(card);
|
|
108
|
+
}
|
|
109
|
+
return out;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** After a rebuild, the replayed cards of events that came after their task's end say they are stale. */
|
|
113
|
+
export function markClaudeStaleCards(tab) {
|
|
114
|
+
if (tab?.messagesEl && tab.bg) markStaleNoticeCards(tab.messagesEl, tab.bg.registry());
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* One click listener per transcript (a transcript put back from a stored snapshot has no listeners of its own):
|
|
119
|
+
* a notice card opens its task in the view.
|
|
120
|
+
*/
|
|
121
|
+
export function wireNoticeCardClicks(container, open) {
|
|
122
|
+
if (!container || container._sbtNoticeWired) return;
|
|
123
|
+
container._sbtNoticeWired = true;
|
|
124
|
+
container.addEventListener('click', (event) => {
|
|
125
|
+
const card = event.target?.closest?.('.sbt-notice[data-task-id]');
|
|
126
|
+
if (!card || !container.contains(card)) return;
|
|
127
|
+
event.preventDefault();
|
|
128
|
+
open(card.dataset.taskId);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
// this reads the server's setup status, renders, and does the page's few actions. The one-time token goes into
|
|
3
3
|
// #synabun-setup-ticket only while the extension's content script is on this page and the server waits for it, and is
|
|
4
4
|
// taken out again as soon as the setup moves on.
|
|
5
|
-
import {
|
|
5
|
+
import { extensionUpdateView } from '../extension-update-view.js';
|
|
6
|
+
import { makeTranslator, pageLocale, pageTurns, revealKey, setupView, wantsTicket } from './es-view.js';
|
|
6
7
|
|
|
7
8
|
const $ = id => document.getElementById(id);
|
|
8
9
|
let t = key => key;
|
|
@@ -21,6 +22,17 @@ const extensionSeen = () => document.documentElement.dataset.synabunExtension ||
|
|
|
21
22
|
const pairAnswer = () => document.documentElement.dataset.synabunPair || '';
|
|
22
23
|
function clearTicket() { const node = $('synabun-setup-ticket'); delete node.dataset.token; delete node.dataset.bridgePort; }
|
|
23
24
|
|
|
25
|
+
// ── One pairing page at a time ──
|
|
26
|
+
// The guide's "Copy address & open <Browser>" opens this page with ?focus=1 only to bring the browser forward: the
|
|
27
|
+
// owner pastes the extensions address over it. That page never asks for a token (es-view.js `focus`).
|
|
28
|
+
const FOCUS_ONLY = (() => { try { return new URLSearchParams(globalThis.location?.search || '').get('focus') === '1'; } catch { return false; } })();
|
|
29
|
+
// The pairing page may still be open more than once: only the newest one that sees the extension asks for tokens
|
|
30
|
+
// (es-view.js pageTurns). The others wait with no token on the page, and ask afresh once their turn comes back.
|
|
31
|
+
let peers = null, waitingTurn = false;
|
|
32
|
+
try { if (!FOCUS_ONLY && typeof BroadcastChannel === 'function') { peers = new BroadcastChannel('synabun-extension-setup'); peers.unref?.(); } } catch { peers = null; }
|
|
33
|
+
const turns = pageTurns({ id: `${Date.now().toString(36)}${Math.random().toString(36).slice(2)}`, born: Date.now(), channel: peers });
|
|
34
|
+
globalThis.addEventListener?.('pagehide', () => turns.gone());
|
|
35
|
+
|
|
24
36
|
// Text that changed only: the same words set again would be read out again by a screen reader on every poll.
|
|
25
37
|
const put = (node, text) => { if (node.textContent !== text) node.textContent = text; };
|
|
26
38
|
// The words that never change while the page is open.
|
|
@@ -35,19 +47,24 @@ function fixedText() {
|
|
|
35
47
|
put($('es-trouble-title'), tx('needHelp')); put($('es-trouble-help'), tx('helpText')); put($('es-moved-help'), tx('movedText')); put($('es-policy-help'), tx('policyText'));
|
|
36
48
|
}
|
|
37
49
|
function render() {
|
|
38
|
-
const view = setupView(status, { extensionVersion: extensionSeen(), pairAnswer: pairAnswer() });
|
|
50
|
+
const view = setupView(status, { extensionVersion: extensionSeen(), pairAnswer: pairAnswer(), focus: FOCUS_ONLY });
|
|
51
|
+
const update = extensionUpdateView(status.update, t);
|
|
52
|
+
const updating = update && ['idle', 'connected'].includes(view.state);
|
|
39
53
|
const main = $('es-setup');
|
|
40
54
|
main.dataset.state = view.state; main.dataset.layout = view.layout; main.setAttribute('aria-busy', 'false');
|
|
41
|
-
|
|
55
|
+
// The Settings guide's companion: the same page, its steps left to Settings (es-view.js `companion`).
|
|
56
|
+
main.dataset.companion = String(view.companion);
|
|
57
|
+
put($('es-title'), updating ? update.title : tx(view.title));
|
|
58
|
+
$('es-lead').hidden = !!updating;
|
|
42
59
|
put($('es-lead'), tx(view.lead, { browser: view.browser }));
|
|
43
60
|
$('es-eyebrow').hidden = !view.eyebrow; put($('es-eyebrow'), view.eyebrow ? tx(view.eyebrow, { browser: view.browser }) : '');
|
|
44
|
-
const live = $('es-live'); put(live, tx(view.live, view.liveParams)); live.dataset.tone = view.tone;
|
|
45
|
-
$('es-status').dataset.tone =
|
|
46
|
-
put($('es-status-title'), tx(view.statusTitle));
|
|
47
|
-
$('es-help').hidden = !view.help; put($('es-help'), view.help ? tx(view.help) : '');
|
|
61
|
+
const live = $('es-live'); put(live, updating ? update.message : tx(view.live, view.liveParams)); live.dataset.tone = updating ? (update.due ? 'warn' : 'ok') : view.tone;
|
|
62
|
+
$('es-status').dataset.tone = live.dataset.tone || 'idle';
|
|
63
|
+
put($('es-status-title'), updating ? t('browserExtension.statusTitle') : tx(view.statusTitle));
|
|
64
|
+
$('es-help').hidden = !!updating || !view.help; put($('es-help'), view.help ? tx(view.help) : '');
|
|
48
65
|
$('es-progress').hidden = !view.progress; put($('es-progress'), view.progress ? tx('downloadProgress', view.progress) : '');
|
|
49
66
|
$('es-browser').hidden = !view.browser; put($('es-browser-name'), view.browser);
|
|
50
|
-
$('es-steps').hidden = !view.showSteps;
|
|
67
|
+
$('es-steps').hidden = !!updating || !view.showSteps;
|
|
51
68
|
for (const step of view.steps) {
|
|
52
69
|
const id = { stepOpenTitle: 'open', stepDeveloperTitle: 'developer', stepLoadTitle: 'load', stepPairTitle: 'pair' }[step.title];
|
|
53
70
|
put($(`es-step-${id}-title`), tx(step.title));
|
|
@@ -68,11 +85,14 @@ function render() {
|
|
|
68
85
|
list.append(button);
|
|
69
86
|
}
|
|
70
87
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
$('es-
|
|
88
|
+
const note = update ? (!updating && update.due ? [update.title, update.message].join(' ') : '')
|
|
89
|
+
: view.reloadNeeded || view.updateNeeded ? tx(view.updateNeeded ? 'updateNeeded' : view.reloadRepaired ? 'reloadRepaired' : 'reloadNeeded', { browser: view.browser }) : '';
|
|
90
|
+
$('es-reload').hidden = !note; put($('es-reload'), note);
|
|
91
|
+
$('es-update-flow').hidden = !update?.due; put($('es-update-flow'), t('browserExtension.updateFlow.review'));
|
|
92
|
+
$('es-restart').hidden = !!updating || !view.restart; put($('es-restart'), tx(view.restartLabel));
|
|
93
|
+
$('es-back').hidden = updating ? update.due : !view.back; $('es-pin').hidden = !!updating || !view.pinTip;
|
|
74
94
|
// The row is hidden by the code that fills it (never found by a :has(), which every hidden toggle re-checks).
|
|
75
|
-
$('es-actions').hidden =
|
|
95
|
+
$('es-actions').hidden = $('es-restart').hidden && $('es-back').hidden && $('es-update-flow').hidden;
|
|
76
96
|
if (!['waiting-for-extension', 'extension-found'].includes(view.state)) clearTicket();
|
|
77
97
|
}
|
|
78
98
|
|
|
@@ -85,8 +105,13 @@ async function poll() {
|
|
|
85
105
|
// the Reload a port change asked for is done (the server keeps saying "reload" until then). Never for a repair: the
|
|
86
106
|
// copy the browser still runs would answer the same, so this page only says to confirm in SynaBun Settings (and the
|
|
87
107
|
// server ignores `seen` for it anyway).
|
|
88
|
-
if (status.reloadNeeded && !status.reloadRepaired && extensionSeen() && extensionSeen() === status.folderVersion) status = await call('seen', {});
|
|
89
|
-
if (
|
|
108
|
+
if (status.reloadNeeded && !status.reloadRepaired && (!status.update || status.update.reason === 'port') && extensionSeen() && extensionSeen() === status.folderVersion) status = await call('seen', {});
|
|
109
|
+
if (extensionSeen()) turns.here();
|
|
110
|
+
const turn = !FOCUS_ONLY && turns.mine();
|
|
111
|
+
// A newer pairing page took over: this one's token comes off the page. Its turn again: a fresh token, at once.
|
|
112
|
+
if (!turn) { waitingTurn = true; clearTicket(); }
|
|
113
|
+
else if (waitingTurn) { waitingTurn = false; offeredAt = 0; }
|
|
114
|
+
if (turn && wantsTicket(status, { extensionVersion: extensionSeen(), pairAnswer: pairAnswer(), offeredAt, tickets })) {
|
|
90
115
|
tickets++;
|
|
91
116
|
const ticket = await call('ticket', {});
|
|
92
117
|
delete document.documentElement.dataset.synabunPair;
|
|
@@ -104,7 +129,8 @@ async function act(action, target) {
|
|
|
104
129
|
else if (action === 'copy-folder') { await navigator.clipboard.writeText(status.folder || '').then(() => { note.textContent = tx('copiedFolder'); }, () => { note.textContent = tx('copyFailed'); }); }
|
|
105
130
|
else if (action === 'reveal') { const r = await call('reveal', {}); note.textContent = tx(r.ok === false ? 'revealFailed' : 'revealed'); }
|
|
106
131
|
else if (action === 'open-in') { status = await call('start', { browser: target.dataset.browser }); offeredAt = 0; tickets = 0; note.textContent = tx('openedIn', { browser: status.browser?.name || '' }); }
|
|
107
|
-
|
|
132
|
+
// Beside the Settings guide this starts the guide's kind of setup again (nothing opened); otherwise the page's own.
|
|
133
|
+
else if (action === 'restart') { status = await call('start', setupView(status).restartBody); offeredAt = 0; tickets = 0; note.textContent = ''; }
|
|
108
134
|
} catch (error) { note.textContent = error.message; }
|
|
109
135
|
render();
|
|
110
136
|
}
|
|
@@ -21,13 +21,16 @@ const RETRY_AFTER = Object.freeze({ ALREADY_PAIRED: 8000, BUSY: 2500, REFUSED: 5
|
|
|
21
21
|
* The page's view of a status (GET /api/browser/extension/setup/status) and what the page saw of the extension:
|
|
22
22
|
* `extensionVersion` (data-synabun-extension, '' when absent) and `pairAnswer` (data-synabun-pair).
|
|
23
23
|
* Returns { state, title, lead, steps, browser, extensionsUrl, folder, alternatives, live, tone, reloadNeeded, reloadRepaired, updateNeeded,
|
|
24
|
-
* progress, restart, restartLabel }.
|
|
24
|
+
* progress, restart, restartLabel, companion, restartBody, focus }. `companion`: the status says `guided` (the steps are in
|
|
25
|
+
* SynaBun Settings); `restartBody`: what "Start again" sends to …/setup/start. `focus`: the page was opened by the
|
|
26
|
+
* guide's "Copy address & open" (?focus=1) only to bring the browser forward for the paste that replaces it: it shows
|
|
27
|
+
* where to paste, never pairs (no token, no "Extension found") and starts nothing.
|
|
25
28
|
* Strings are i18n keys under browserExtension.setup (the page translates them); `params` fill their {placeholders}.
|
|
26
29
|
*/
|
|
27
|
-
export function setupView(status = {}, { extensionVersion = '', pairAnswer = '' } = {}) {
|
|
30
|
+
export function setupView(status = {}, { extensionVersion = '', pairAnswer = '', focus = false } = {}) {
|
|
28
31
|
const server = SETUP_STATES.includes(status.state) ? status.state : 'error';
|
|
29
32
|
const found = !!extensionVersion;
|
|
30
|
-
const state = server === 'waiting-for-extension' && found ? 'extension-found' : server;
|
|
33
|
+
const state = server === 'waiting-for-extension' && found && !focus ? 'extension-found' : server;
|
|
31
34
|
const browser = status.browser || null;
|
|
32
35
|
const name = browser?.name || '';
|
|
33
36
|
const extensionsUrl = browser?.supported ? browser.extensionsUrl || null : null;
|
|
@@ -58,25 +61,33 @@ export function setupView(status = {}, { extensionVersion = '', pairAnswer = ''
|
|
|
58
61
|
const layout = showSteps && state !== 'connected' ? 'guide' : 'result';
|
|
59
62
|
const statusTitle = { downloading: 'downloadingTitle', 'waiting-for-extension': 'waitingTitle', 'extension-found': 'foundTitle', pairing: 'pairingTitle', connected: 'titleConnected',
|
|
60
63
|
unsupported: 'titleUnsupported', idle: 'idleTitle', error: downloadFailed ? 'downloadErrorTitle' : 'errorTitle' }[state];
|
|
64
|
+
// The Settings guide's companion (a setup started with `present: 'none'`, status `guided`): the steps are in SynaBun
|
|
65
|
+
// Settings, so this page is one card with the live status only (no steps, folder or other browsers), and it stays
|
|
66
|
+
// open to pair the extension by itself. "Start again" here starts the guide's kind of setup for the same browser,
|
|
67
|
+
// which opens nothing.
|
|
68
|
+
const companion = status.guided === true || focus;
|
|
69
|
+
const installedIds = (status.installedBrowsers || []).filter(b => b?.supported).map(b => b.id);
|
|
70
|
+
const restartBody = companion ? { present: 'none', ...(browser?.supported && installedIds.includes(browser.id) ? { browser: browser.id } : {}) } : {};
|
|
61
71
|
return {
|
|
62
|
-
|
|
72
|
+
companion, restartBody, focus,
|
|
73
|
+
layout: companion ? 'result' : layout, statusTitle, eyebrow: name ? 'eyebrow' : '',
|
|
63
74
|
help: state === 'connected' ? 'connectedHelp' : state === 'downloading' ? 'downloadingHelp' : '',
|
|
64
75
|
progress,
|
|
65
|
-
state, title: state === 'connected' ? 'titleConnected' : state === 'unsupported' ? 'titleUnsupported' : 'title',
|
|
66
|
-
lead: state === 'unsupported' ? 'leadUnsupported' : 'lead', steps, browser: name, extensionsUrl,
|
|
67
|
-
folder: typeof status.folder === 'string' ? status.folder : '', alternatives, live, liveParams: { browser: name }, tone,
|
|
76
|
+
state, title: focus ? 'focusTitle' : companion ? 'companionTitle' : state === 'connected' ? 'titleConnected' : state === 'unsupported' ? 'titleUnsupported' : 'title',
|
|
77
|
+
lead: focus ? 'focusLead' : companion ? 'companionLead' : state === 'unsupported' ? 'leadUnsupported' : 'lead', steps, browser: name, extensionsUrl,
|
|
78
|
+
folder: !companion && typeof status.folder === 'string' ? status.folder : '', alternatives: companion ? [] : alternatives, live, liveParams: { browser: name }, tone,
|
|
68
79
|
reloadNeeded: status.reloadNeeded === true,
|
|
69
80
|
// SynaBun replaced files that were not its extension: the same Reload, in the words of a repair.
|
|
70
81
|
reloadRepaired: status.reloadNeeded === true && status.reloadRepaired === true,
|
|
71
82
|
// The folder holds an older extension than this release's: SynaBun downloads the new one; a Reload comes after.
|
|
72
83
|
updateNeeded: status.updateNeeded === true && status.reloadNeeded !== true,
|
|
73
|
-
showSteps,
|
|
84
|
+
showSteps: showSteps && !companion,
|
|
74
85
|
// What the page offers: start again (idle, error), back to SynaBun and the pin tip (connected).
|
|
75
|
-
restart: ['error', 'idle'].includes(state), back: state === 'connected', pinTip: state === 'connected',
|
|
86
|
+
restart: !focus && ['error', 'idle'].includes(state), back: state === 'connected', pinTip: state === 'connected',
|
|
76
87
|
// A download that failed is tried again by the same button, under its own words.
|
|
77
88
|
restartLabel: downloadFailed ? 'retryDownload' : 'restart',
|
|
78
|
-
// "Open in X instead" while there is still something to install here; never once pairing began.
|
|
79
|
-
showAlternatives: alternatives.length > 0 && !['pairing', 'connected'].includes(state),
|
|
89
|
+
// "Open in X instead" while there is still something to install here; never once pairing began, never beside the guide.
|
|
90
|
+
showAlternatives: !companion && alternatives.length > 0 && !['pairing', 'connected'].includes(state),
|
|
80
91
|
};
|
|
81
92
|
}
|
|
82
93
|
/** The words for "show the folder" on this computer: Finder, Explorer or the file manager. */
|
|
@@ -96,6 +107,35 @@ export function wantsTicket(status = {}, { extensionVersion = '', pairAnswer = '
|
|
|
96
107
|
return wait !== undefined && now - offeredAt >= wait;
|
|
97
108
|
}
|
|
98
109
|
|
|
110
|
+
/** How long a newer pairing page keeps its turn without being heard from (it speaks at every poll, 1.5 s). */
|
|
111
|
+
export const PEER_SILENT_MS = 5000;
|
|
112
|
+
/**
|
|
113
|
+
* Which of SynaBun's pairing pages asks for tokens (es-page.js). The pairing page may be open more than once (the
|
|
114
|
+
* guide's companion, then Pair in <Browser>): each would ask for its own token, and each token replaces the last, so
|
|
115
|
+
* they would undo each other's pairing and spend the setup's five tokens. The pages that see the extension say so on
|
|
116
|
+
* `channel` (a BroadcastChannel of this origin; null: the page is alone) and only the newest of them asks. `here()`:
|
|
117
|
+
* this page sees the extension (at every poll); `gone()`: it is leaving; `mine()`: no newer page was heard from in the
|
|
118
|
+
* last `silentMs`. A message that is not one of these two shapes is ignored.
|
|
119
|
+
*/
|
|
120
|
+
export function pageTurns({ id, born, channel = null, now = Date.now, silentMs = PEER_SILENT_MS }) {
|
|
121
|
+
const newer = new Map();
|
|
122
|
+
channel?.addEventListener?.('message', ({ data } = {}) => {
|
|
123
|
+
if (!data || typeof data !== 'object' || typeof data.id !== 'string' || data.id === id) return;
|
|
124
|
+
if (data.type === 'gone') newer.delete(data.id);
|
|
125
|
+
else if (data.type === 'here' && Number.isFinite(data.born) && (data.born > born || (data.born === born && data.id > id))) newer.set(data.id, now());
|
|
126
|
+
});
|
|
127
|
+
const say = message => { try { channel?.postMessage?.(message); } catch { /* a closed channel: alone */ } };
|
|
128
|
+
return {
|
|
129
|
+
here: () => say({ type: 'here', id, born }),
|
|
130
|
+
gone: () => say({ type: 'gone', id }),
|
|
131
|
+
mine() {
|
|
132
|
+
const at = now();
|
|
133
|
+
for (const [peer, heard] of newer) if (at - heard > silentMs) newer.delete(peer);
|
|
134
|
+
return newer.size === 0;
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
99
139
|
/**
|
|
100
140
|
* The page's translator: the active locale's strings with English behind them, key by key, `{name}` filled from
|
|
101
141
|
* params. The page loads the two JSON files itself (es-page.js), never the app's i18n module: that one brings the
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Shared words and actions for Settings, the setup page, the notification and the Assistant.
|
|
2
|
+
const releaseNotes = { '1.5.0': 'notes.v1_5_0', '1.6.0': 'notes.v1_6_0' };
|
|
3
|
+
const downloadErrors = {
|
|
4
|
+
EXTENSION_DOWNLOAD_OFFLINE: 'offline', EXTENSION_DOWNLOAD_UNAVAILABLE: 'unavailable',
|
|
5
|
+
EXTENSION_VERIFY_FAILED: 'unverified', EXTENSION_FOLDER_UNSAFE: 'unsafe',
|
|
6
|
+
EXTENSION_DOWNLOAD_CANCELLED: 'cancelled',
|
|
7
|
+
};
|
|
8
|
+
export function extensionUpdateView(update, tx) {
|
|
9
|
+
if (!update?.targetVersion || !['downloading', 'ready', 'reloading', 'failed', 'done'].includes(update.phase)) return null;
|
|
10
|
+
const { phase, reason, recovery, code, targetVersion: version } = update;
|
|
11
|
+
const from = update.runningVersion || update.fromVersion;
|
|
12
|
+
const params = { from, version, percent: update.percent ?? 0 };
|
|
13
|
+
const t = key => tx(`browserExtension.updateFlow.${key}`, params);
|
|
14
|
+
const done = phase === 'done';
|
|
15
|
+
const same = from && from === version;
|
|
16
|
+
const title = done ? t('done') : from && !same ? t('versions')
|
|
17
|
+
: reason === 'repair' ? t('repairTitle') : reason === 'port' ? t('portTitle') : t('target');
|
|
18
|
+
const notes = !done && reason === 'version' && !same && Object.hasOwn(releaseNotes, version) ? t(releaseNotes[version]) : '';
|
|
19
|
+
const guided = (phase === 'ready' && !update.canReload) || (phase === 'failed' && recovery === 'guided');
|
|
20
|
+
let message = '';
|
|
21
|
+
if (phase === 'downloading') message = t(update.pending ? 'pending' : update.percent === 100 ? 'verifying' : 'progress');
|
|
22
|
+
if (phase === 'reloading') message = t('reloading');
|
|
23
|
+
if (phase === 'ready') message = t(reason === 'repair' ? 'repaired' : reason === 'port' ? 'port' : update.canReload ? 'ready' : 'manual');
|
|
24
|
+
if (phase === 'failed') message = t(guided ? (code === 'RELOAD_OLD_VERSION' ? 'oldVersion' : code === 'RELOAD_TIMEOUT' ? 'timeout' : 'reloadFailed') : downloadErrors[code] || 'downloadFailed');
|
|
25
|
+
return {
|
|
26
|
+
title, message, notes, due: !done, guided, updateNow: phase === 'ready' && update.canReload,
|
|
27
|
+
download: phase === 'downloading' && update.pending,
|
|
28
|
+
retry: phase === 'failed' && recovery === 'download',
|
|
29
|
+
busy: !!(update.claimedTabs || update.runsActive || update.confirmBusy),
|
|
30
|
+
confirmRepair: reason === 'repair' && (phase === 'ready' || guided),
|
|
31
|
+
checkPort: reason === 'port' && (phase === 'ready' || guided),
|
|
32
|
+
key: `${version}/${reason}`,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -95,7 +95,11 @@ const replyFailed = (res) => !res || res.ok === false || (typeof res.status ===
|
|
|
95
95
|
export function createShellFollower({
|
|
96
96
|
api, sessionId, shellId, cwd, isRunning = () => false, isCurrent = () => true, onUpdate = () => {},
|
|
97
97
|
windowChars = SHELL_WINDOW_CHARS, setTimer = setTimeout, clearTimer = clearTimeout,
|
|
98
|
+
// How often a running command is asked again (a caller may ask less often: the Background tasks view, 1 s).
|
|
99
|
+
pollMinMs = SHELL_POLL_MIN_MS, pollMaxMs = SHELL_POLL_MAX_MS,
|
|
98
100
|
} = {}) {
|
|
101
|
+
const POLL_MIN = Math.max(SHELL_POLL_MIN_MS, Number(pollMinMs) || SHELL_POLL_MIN_MS);
|
|
102
|
+
const POLL_MAX = Math.max(POLL_MIN, Number(pollMaxMs) || SHELL_POLL_MAX_MS);
|
|
99
103
|
const buffer = createTerminalBuffer({ maxChars: windowChars });
|
|
100
104
|
let cursor = null; // null: nothing read yet (the first read asks for the tail)
|
|
101
105
|
let from = 0; // the byte the kept text starts at, as far as the server said
|
|
@@ -108,7 +112,7 @@ export function createShellFollower({
|
|
|
108
112
|
let error = '';
|
|
109
113
|
let full = false;
|
|
110
114
|
let capped = false;
|
|
111
|
-
let delay =
|
|
115
|
+
let delay = POLL_MIN;
|
|
112
116
|
let failures = 0;
|
|
113
117
|
let generation = 0; // a read begun before loadAll() belongs to the reading it replaced
|
|
114
118
|
|
|
@@ -148,7 +152,7 @@ export function createShellFollower({
|
|
|
148
152
|
error = (typeof res?.error === 'string' && res.error) || 'The output could not be read.';
|
|
149
153
|
if (failures >= 5 && !isRunning()) { done = true; publish(); return; }
|
|
150
154
|
publish();
|
|
151
|
-
schedule(Math.min(
|
|
155
|
+
schedule(Math.min(POLL_MAX * 2, POLL_MIN * 2 ** failures));
|
|
152
156
|
return;
|
|
153
157
|
}
|
|
154
158
|
failures = 0;
|
|
@@ -168,8 +172,8 @@ export function createShellFollower({
|
|
|
168
172
|
else if (!wasRunning && !isRunning() && !behind) { publish(); schedule(0); return; }
|
|
169
173
|
publish();
|
|
170
174
|
if (done) return;
|
|
171
|
-
if (behind) { delay =
|
|
172
|
-
delay = moved && text ?
|
|
175
|
+
if (behind) { delay = POLL_MIN; schedule(0); return; }
|
|
176
|
+
delay = moved && text ? POLL_MIN : Math.min(POLL_MAX, Math.round(delay * 1.5));
|
|
173
177
|
schedule(isRunning() ? delay : 0);
|
|
174
178
|
}
|
|
175
179
|
|
|
@@ -17,6 +17,24 @@ export const LOCAL_CONNECT_OPTIONS = Object.freeze(['attach', 'extension']);
|
|
|
17
17
|
/** Deprecated in the menu. Still supported for saved configs and as the server's local default. */
|
|
18
18
|
export const LOCAL_DEFAULT_MODE = 'mirror';
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* The Browser tab's Connection mode menu, in reading order: my browser through the extension, the local browser, and
|
|
22
|
+
* a MoreLogin / SynaBun profile. The last one is a view only: it shows where a profile is chosen (Connected tools) and
|
|
23
|
+
* is never saved from here (browserSaveFields keeps the local mode the server holds).
|
|
24
|
+
*/
|
|
25
|
+
export const CONNECT_MENU_OPTIONS = Object.freeze(['extension', 'attach', 'morelogin']);
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Which parts of the Browser tab a Connection mode shows. A profile that is the AI browser wins over the form: the menu
|
|
29
|
+
* then shows the profile choice, disabled, with the banner that names it.
|
|
30
|
+
* @returns {{ mode: string, extension: boolean, local: boolean, profile: boolean, active: boolean }}
|
|
31
|
+
*/
|
|
32
|
+
export function connectionParts(formMode, current) {
|
|
33
|
+
const active = !!(current && typeof current === 'object' && current.moreLogin === true);
|
|
34
|
+
const mode = active ? 'morelogin' : (CONNECT_MENU_OPTIONS.includes(formMode) || formMode === LOCAL_DEFAULT_MODE ? formMode : LOCAL_DEFAULT_MODE);
|
|
35
|
+
return { mode, extension: mode === 'extension', local: mode === 'attach' || mode === LOCAL_DEFAULT_MODE, profile: mode === 'morelogin' && !active, active };
|
|
36
|
+
}
|
|
37
|
+
|
|
20
38
|
const idOf = (value) => (value === undefined || value === null || value === '' ? null : String(value));
|
|
21
39
|
|
|
22
40
|
/**
|
|
@@ -47,14 +65,16 @@ export function localConnectModeOf(cfg) {
|
|
|
47
65
|
* The connection fields of a Browser tab save. `formMode`: its Connection dropdown. `current`: the AI browser as the
|
|
48
66
|
* server holds it now (aiBrowserOf of a fresh read; the last one known when that read failed). A MoreLogin AI browser
|
|
49
67
|
* stays exactly as it is, profile included; otherwise the local mode is the form's and the remembered profile id is
|
|
50
|
-
* kept (never cleared from here).
|
|
68
|
+
* kept (never cleared from here). `savedLocal`: the local mode the last read held, kept when the form only shows the
|
|
69
|
+
* profile choice (that choice is never saved from the Browser tab: a profile is turned on in Connected tools).
|
|
51
70
|
* @returns {{ connectMode: string, moreloginEnvId: string|null }}
|
|
52
71
|
*/
|
|
53
|
-
export function browserSaveFields(formMode, current) {
|
|
72
|
+
export function browserSaveFields(formMode, current, savedLocal = LOCAL_DEFAULT_MODE) {
|
|
54
73
|
const now = current && typeof current === 'object' ? current : {};
|
|
55
74
|
const envId = idOf(now.envId);
|
|
56
75
|
if (now.moreLogin === true) return { connectMode: 'morelogin', moreloginEnvId: envId };
|
|
57
|
-
|
|
76
|
+
const kept = LOCAL_CONNECT_OPTIONS.includes(savedLocal) ? savedLocal : LOCAL_DEFAULT_MODE;
|
|
77
|
+
return { connectMode: LOCAL_CONNECT_OPTIONS.includes(formMode) ? formMode : formMode === 'morelogin' ? kept : LOCAL_DEFAULT_MODE, moreloginEnvId: envId };
|
|
58
78
|
}
|
|
59
79
|
|
|
60
80
|
/**
|