synabun 2.4.4 → 2.4.6
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 +42 -0
- package/README.md +1 -1
- package/docs/browser-extension-bridge.md +5 -4
- package/docs/whatsapp.md +19 -3
- package/hooks/claude-code/session-start.mjs +21 -18
- package/lib/claude-global-config.js +214 -0
- package/lib/client-config-repair.js +17 -3
- package/mcp-server/dist/index.d.ts.map +1 -1
- package/mcp-server/dist/index.js +6 -1
- package/mcp-server/dist/index.js.map +1 -1
- package/mcp-server/dist/services/neural-interface.d.ts +1 -0
- package/mcp-server/dist/services/neural-interface.d.ts.map +1 -1
- package/mcp-server/dist/services/neural-interface.js +1 -0
- package/mcp-server/dist/services/neural-interface.js.map +1 -1
- package/mcp-server/dist/services/tool-catalog.js +1 -1
- package/mcp-server/dist/services/tool-catalog.js.map +1 -1
- package/mcp-server/dist/tools/agents.d.ts +18 -3
- package/mcp-server/dist/tools/agents.d.ts.map +1 -1
- package/mcp-server/dist/tools/agents.js +85 -16
- package/mcp-server/dist/tools/agents.js.map +1 -1
- package/mcp-server/dist/tools/skill-tools.d.ts +24 -5
- package/mcp-server/dist/tools/skill-tools.d.ts.map +1 -1
- package/mcp-server/dist/tools/skill-tools.js +88 -8
- package/mcp-server/dist/tools/skill-tools.js.map +1 -1
- package/mcp-server/dist/tools/tool-groups.d.ts.map +1 -1
- package/mcp-server/dist/tools/tool-groups.js +19 -4
- package/mcp-server/dist/tools/tool-groups.js.map +1 -1
- package/mcp-server/package-lock.json +2 -2
- package/mcp-server/package.json +1 -1
- package/mcp-server/src/index.ts +6 -1
- package/mcp-server/src/services/neural-interface.ts +2 -1
- package/mcp-server/src/services/tool-catalog.ts +1 -1
- package/mcp-server/src/tools/agents.ts +78 -16
- package/mcp-server/src/tools/skill-tools.ts +82 -9
- package/mcp-server/src/tools/tool-groups.ts +19 -4
- package/neural-interface/i18n/en.json +484 -19
- package/neural-interface/i18n/pt-BR.json +484 -19
- package/neural-interface/lib/agents-studio-api.js +7 -2
- package/neural-interface/lib/antigravity/home.js +43 -8
- package/neural-interface/lib/antigravity/panel-bridge.js +7 -3
- package/neural-interface/lib/antigravity/tool-call.js +14 -0
- package/neural-interface/lib/assistant-brains/antigravity.js +4 -2
- package/neural-interface/lib/assistant-dispatch.js +15 -1
- package/neural-interface/lib/assistant-persona.js +8 -3
- package/neural-interface/lib/assistant-route-gate.js +11 -2
- package/neural-interface/lib/assistant-runtime.js +95 -13
- package/neural-interface/lib/assistant-spilled-output.js +53 -0
- package/neural-interface/lib/assistant-user-context.js +7 -3
- package/neural-interface/lib/browser-default.js +22 -2
- package/neural-interface/lib/browser-extension-bridge.js +50 -3
- package/neural-interface/lib/browser-extension-pin.json +7 -7
- package/neural-interface/lib/browser-extension-protocol.js +30 -1
- package/neural-interface/lib/browser-extension-setup.js +204 -36
- package/neural-interface/lib/claude-agent-bridge.js +13 -2
- package/neural-interface/lib/codex-thread-history.js +144 -7
- package/neural-interface/lib/codex-worker-app-server.js +84 -30
- package/neural-interface/lib/db.js +26 -0
- package/neural-interface/lib/greeting/sources.js +7 -3
- package/neural-interface/lib/jsonl-lines.js +10 -11
- package/neural-interface/lib/line-buffer.js +88 -0
- package/neural-interface/lib/loop-stall.js +15 -1
- package/neural-interface/lib/memory-list-read.js +105 -0
- package/neural-interface/lib/memory-timers.js +4 -1
- package/neural-interface/lib/native-loop-runtime.js +7 -3
- package/neural-interface/lib/provider-panel-api-key-auth.js +33 -6
- package/neural-interface/lib/remote-policy.js +24 -7
- package/neural-interface/lib/skills/api-v2.js +18 -3
- package/neural-interface/lib/skills/bundle.js +2 -2
- package/neural-interface/lib/skills/deploy.js +169 -34
- package/neural-interface/lib/skills/digest.js +57 -3
- package/neural-interface/lib/skills/health.js +55 -1
- package/neural-interface/lib/skills/known-bridge-digests.json +12 -0
- package/neural-interface/lib/skills/runtime-checks.js +7 -4
- package/neural-interface/lib/skills/scan-shell.js +56 -7
- package/neural-interface/lib/skills/scan.js +13 -12
- package/neural-interface/lib/skills/service.js +7 -2
- package/neural-interface/lib/skills/telemetry.js +2 -2
- package/neural-interface/lib/teams/README.md +34 -6
- package/neural-interface/lib/teams/api.js +94 -10
- package/neural-interface/lib/teams/index.js +4 -0
- package/neural-interface/lib/teams/landing.js +195 -75
- package/neural-interface/lib/teams/recovery.js +68 -0
- package/neural-interface/lib/teams/scheduler.js +380 -61
- package/neural-interface/lib/teams/worktrees.js +123 -30
- package/neural-interface/lib/terminal-token-redaction.js +228 -58
- package/neural-interface/lib/terminal-tokens.js +18 -0
- package/neural-interface/lib/whatsapp/brain.js +21 -0
- package/neural-interface/lib/whatsapp/bridge.js +40 -4
- package/neural-interface/package-lock.json +2 -2
- package/neural-interface/package.json +1 -1
- package/neural-interface/public/extension-setup.html +6 -2
- package/neural-interface/public/index.html +117 -37
- package/neural-interface/public/shared/agents/studio/ax-api.js +27 -0
- package/neural-interface/public/shared/agents/studio/ax-create-view.js +1 -1
- package/neural-interface/public/shared/agents/studio/ax-icons.js +1 -0
- package/neural-interface/public/shared/agents/studio/ax-library-view.js +3 -2
- package/neural-interface/public/shared/agents/studio/ax-main.js +127 -41
- package/neural-interface/public/shared/agents/studio/ax-review-view.js +3 -2
- package/neural-interface/public/shared/agents/studio/ax-teams-view.js +436 -33
- package/neural-interface/public/shared/agents/studio/ax-teams.js +357 -10
- package/neural-interface/public/shared/agents/studio/ax-ui.js +31 -0
- package/neural-interface/public/shared/agents/studio/ax-views.js +67 -69
- package/neural-interface/public/shared/agents/studio/ax-work-answer.js +86 -0
- package/neural-interface/public/shared/agents/studio/ax-work-view.js +305 -0
- package/neural-interface/public/shared/agents/studio/ax-work.css +74 -0
- package/neural-interface/public/shared/agents/studio/ax-work.js +300 -0
- package/neural-interface/public/shared/browser-extension-updates.js +3 -1
- package/neural-interface/public/shared/cdx/cdx-deferred.js +90 -0
- package/neural-interface/public/shared/cdx/cdx-render.js +18 -7
- package/neural-interface/public/shared/cdx/cdx-tabs.js +2 -1
- package/neural-interface/public/shared/extension-setup/es-page.js +23 -4
- package/neural-interface/public/shared/extension-setup/es-view.js +51 -11
- package/neural-interface/public/shared/extension-update-view.js +1 -1
- package/neural-interface/public/shared/loading-diagnostic-entry.js +16 -1
- package/neural-interface/public/shared/settings/settings-ai-browser.js +23 -3
- package/neural-interface/public/shared/settings/settings-browser-extension.js +575 -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-ia.js +2 -2
- package/neural-interface/public/shared/settings/settings-shell.js +5 -0
- package/neural-interface/public/shared/skills/studio/sx-operations-view.js +5 -0
- package/neural-interface/public/shared/skills/studio/sx-plan.js +42 -3
- package/neural-interface/public/shared/skills/studio/sx-publish-view.js +20 -4
- package/neural-interface/public/shared/styles.css +196 -13
- package/neural-interface/public/shared/ui-settings.js +48 -11
- package/neural-interface/server.js +336 -253
- package/npm-shrinkwrap.json +2 -2
- package/package.json +2 -1
- package/skills/skill-forge/SKILL.md +7 -3
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
//
|
|
4
4
|
// Nothing here touches the system by itself: every read goes through the injected `run(cmd, args)` (a program and its
|
|
5
5
|
// arguments, never a shell), `exists(path)` and `list(dir)`, so tests feed fixtures and never read the real registry,
|
|
6
|
-
// LaunchServices database or desktop files. `launchPlan` / `revealPlan` say which program
|
|
7
|
-
// arguments; nothing here starts it. The server runs a plan with execFile (no shell; lib/browser-extension-setup.js).
|
|
6
|
+
// LaunchServices database or desktop files. `launchPlan` / `extensionsPagePlan` / `revealPlan` say which program
|
|
7
|
+
// SynaBun starts, with which arguments; nothing here starts it. The server runs a plan with execFile (no shell; lib/browser-extension-setup.js).
|
|
8
8
|
//
|
|
9
9
|
// Supported: the Chromium browsers that load an unpacked Manifest V3 extension (Chrome, Edge, Brave, Arc, Vivaldi,
|
|
10
10
|
// Opera, Chromium). Safari and Firefox are named as the default when they are, with `supported: false`, so the page can
|
|
@@ -201,6 +201,26 @@ export function launchPlan(platform, browser, url) {
|
|
|
201
201
|
if (platform === 'win32') return launch.exe ? { cmd: launch.exe, args: [url] } : { cmd: 'rundll32.exe', args: ['url.dll,FileProtocolHandler', url] };
|
|
202
202
|
return launch.desktopFile ? { cmd: 'gio', args: ['launch', launch.desktopFile, url] } : { cmd: 'xdg-open', args: [url] };
|
|
203
203
|
}
|
|
204
|
+
/** The only addresses `extensionsPagePlan` opens: a supported browser's own extensions page, exactly. */
|
|
205
|
+
export const EXTENSIONS_PAGE = /^(chrome|edge|brave|arc|vivaldi|opera):\/\/extensions$/;
|
|
206
|
+
/**
|
|
207
|
+
* The program and arguments that open the extensions page of an installed supported browser (`browser`: an entry of
|
|
208
|
+
* detectBrowsers' installedBrowsers, with its `launch`), for the Settings guide's "Open extensions page". The address
|
|
209
|
+
* is read again from BROWSERS by the browser's id and checked against EXTENSIONS_PAGE, so nothing a caller passes
|
|
210
|
+
* becomes the address. Unlike launchPlan there is no fallback to the system's default handler: only the browser itself
|
|
211
|
+
* knows its own scheme, so a browser without a `launch` entry gets no plan (INVALID_MESSAGE).
|
|
212
|
+
*/
|
|
213
|
+
export function extensionsPagePlan(platform, browser) {
|
|
214
|
+
const known = browser && typeof browser.id === 'string' && Object.hasOwn(BROWSERS, browser.id) ? BROWSERS[browser.id] : null;
|
|
215
|
+
const url = known?.supported ? known.extensionsUrl : null;
|
|
216
|
+
const refuse = () => { throw Object.assign(new Error('Only an installed browser\'s own extensions page is opened.'), { code: 'INVALID_MESSAGE' }); };
|
|
217
|
+
if (!url || !EXTENSIONS_PAGE.test(url)) refuse();
|
|
218
|
+
const launch = browser.launch || {};
|
|
219
|
+
if (platform === 'darwin') { if (typeof launch.bundleId === 'string' && launch.bundleId) return { cmd: 'open', args: ['-b', launch.bundleId, url] }; }
|
|
220
|
+
else if (platform === 'win32') { if (typeof launch.exe === 'string' && launch.exe) return { cmd: launch.exe, args: [url] }; }
|
|
221
|
+
else if (typeof launch.desktopFile === 'string' && launch.desktopFile) return { cmd: 'gio', args: ['launch', launch.desktopFile, url] };
|
|
222
|
+
return refuse();
|
|
223
|
+
}
|
|
204
224
|
/** The program and arguments that show `folder` in Finder, Explorer or the file manager. */
|
|
205
225
|
export function revealPlan(platform, folder) {
|
|
206
226
|
if (typeof folder !== 'string' || !folder || /[\r\n\0]/.test(folder)) throw Object.assign(new Error('No folder to show.'), { code: 'INVALID_MESSAGE' });
|
|
@@ -126,6 +126,9 @@ export function createExtensionBridge({ port = 3345, log = () => {}, onInventory
|
|
|
126
126
|
}
|
|
127
127
|
const pending = new Map();
|
|
128
128
|
const sockets = new Set();
|
|
129
|
+
// The probes waiting for a fresh capabilities report (probe()): each is called with the peer whose report arrived,
|
|
130
|
+
// or with ENDED when the owner ended the connection or the pairing.
|
|
131
|
+
const observers = new Set(), ENDED = Symbol('ended');
|
|
129
132
|
// One log line per command: its op, the tab's opaque handle, the outcome's code and, when the browser refused it,
|
|
130
133
|
// what the browser said (`detail`, a chrome.* error message: cleanDetail; never a page's content or a credential).
|
|
131
134
|
const note = (op, tab, code, detail) => {
|
|
@@ -183,6 +186,14 @@ export function createExtensionBridge({ port = 3345, log = () => {}, onInventory
|
|
|
183
186
|
next.sites = next.sites.filter((site, i) => !revokedSites.has(site) || (versions ? versions[i] : siteVersions.get(site) || 0) > revokedSites.get(site));
|
|
184
187
|
state = next; revision++; onInventory({ ...state, fullControl: mode.fullControl });
|
|
185
188
|
}
|
|
189
|
+
// What the extension saw of this browser (protocol.js capabilityReport), kept on the peer that said it with the time
|
|
190
|
+
// it arrived: a disconnect, a reload or a new pairing (no peer, or a new one) leaves nothing of it behind. Taken from
|
|
191
|
+
// the current peer only, once its first inventory made it the connection agents use.
|
|
192
|
+
function observe(from, report) {
|
|
193
|
+
if (!from || from !== peer || !from.ready || from.generation !== authentication) return;
|
|
194
|
+
from.capabilities = { ...structuredClone(report), observedAt: now() };
|
|
195
|
+
for (const waiter of [...observers]) waiter(from);
|
|
196
|
+
}
|
|
186
197
|
// An owner revocation begins: cancel everything issued before it, synchronously, before the extension is told.
|
|
187
198
|
function revoking() { revocations++; settle(cancelled, true); }
|
|
188
199
|
// Ends the connection and every handshake still under way; nothing admitted before acts after.
|
|
@@ -190,6 +201,7 @@ export function createExtensionBridge({ port = 3345, log = () => {}, onInventory
|
|
|
190
201
|
enabled = false; authentication++; revocations++;
|
|
191
202
|
peer = null; for (const ws of sockets) ws.close();
|
|
192
203
|
settle(notConnected);
|
|
204
|
+
for (const waiter of [...observers]) waiter(ENDED);
|
|
193
205
|
}
|
|
194
206
|
// The owner's Disconnect: kept across a restart (the bridge stays off until Resume).
|
|
195
207
|
function disconnect() { cut(); persist(); }
|
|
@@ -288,7 +300,7 @@ export function createExtensionBridge({ port = 3345, log = () => {}, onInventory
|
|
|
288
300
|
if (admitted !== authentication || !enabled || ws.readyState !== 1
|
|
289
301
|
|| (isPair ? pair !== pairWindow || pairWindow.until < now() : key !== credential || now() >= credentialUntil)) fail('AUTH_FAILED');
|
|
290
302
|
const previous = peer;
|
|
291
|
-
peer = { ws, send, session, key, generation: admitted, ready: false, pushedMode: null, version: hello.version || null }; previous?.ws.close();
|
|
303
|
+
peer = { ws, send, session, key, generation: admitted, ready: false, pushedMode: null, version: hello.version || null, capabilities: null }; previous?.ws.close();
|
|
292
304
|
if (previous) settle(notConnected);
|
|
293
305
|
// A new pairing starts from a cleared extension: nothing of a previous process to hand back.
|
|
294
306
|
// A setup's token is gone with it (single use): `pair` is cleared in this same step. A setup pairing, like a
|
|
@@ -305,6 +317,8 @@ export function createExtensionBridge({ port = 3345, log = () => {}, onInventory
|
|
|
305
317
|
const message = payload(await wire.decode(raw.toString())); lastSeen = Date.now();
|
|
306
318
|
if (message.type === 'pong') return;
|
|
307
319
|
if (message.type === 'unpair') { revoke(); return; }
|
|
320
|
+
// A report from this socket's peer only (the decoding above awaited: the peer may have changed meanwhile).
|
|
321
|
+
if (message.type === 'capabilities') { if (peer?.ws === ws) observe(peer, message.capabilities); return; }
|
|
308
322
|
if (message.type !== 'state' && message.type !== 'result') fail('INVALID_MESSAGE');
|
|
309
323
|
update(message.inventory, peer);
|
|
310
324
|
if (message.type === 'result') {
|
|
@@ -409,7 +423,33 @@ export function createExtensionBridge({ port = 3345, log = () => {}, onInventory
|
|
|
409
423
|
note(op, tab || result.tab, result.code || 'OK', result.ok === false ? errorDetail(result) : ''); return result;
|
|
410
424
|
} catch (error) { note(op, tab, safeError(error).code); throw error; }
|
|
411
425
|
}
|
|
426
|
+
// "Check again": a fresh capabilities report. Only an ordinary ping goes out (an extension from before 1.6.0 ends the
|
|
427
|
+
// connection on any type it does not know); 1.6.0 and later answer every ping with a pong and a new report. Waits for
|
|
428
|
+
// the first report that arrives after the ping was asked for, from this peer or from one that replaced it (a reload
|
|
429
|
+
// of the extension), up to `timeoutMs`. Resolves { ok: true, capabilities, legacy }: `capabilities` the fresh report
|
|
430
|
+
// (with its `observedAt`) or null, `legacy` true when none came and the extension connected now never sent one (it
|
|
431
|
+
// predates the reports); or { ok: false, code: 'NOT_CONNECTED' }. Never throws.
|
|
432
|
+
async function probe(options = {}) {
|
|
433
|
+
try {
|
|
434
|
+
const timeoutMs = options?.timeoutMs ?? 4000;
|
|
435
|
+
const wait = Number.isFinite(timeoutMs) ? Math.max(1, Math.min(60000, Math.floor(timeoutMs))) : 4000;
|
|
436
|
+
const asked = peer;
|
|
437
|
+
if (!enabled || !asked?.ready || asked.ws.readyState !== 1) return { ok: false, code: 'NOT_CONNECTED' };
|
|
438
|
+
const fresh = await new Promise(resolve => {
|
|
439
|
+
let timer = null;
|
|
440
|
+
const done = value => { clearTimeout(timer); observers.delete(done); resolve(value); };
|
|
441
|
+
observers.add(done);
|
|
442
|
+
timer = setTimeout(() => done(null), wait); timer.unref?.();
|
|
443
|
+
void asked.send({ type: 'ping' }).catch(() => {});
|
|
444
|
+
});
|
|
445
|
+
if (fresh && fresh !== ENDED && fresh.capabilities) return { ok: true, capabilities: structuredClone(fresh.capabilities), legacy: false };
|
|
446
|
+
const current = peer;
|
|
447
|
+
if (fresh === ENDED || !enabled || !current?.ready || current.ws.readyState !== 1) return { ok: false, code: 'NOT_CONNECTED' };
|
|
448
|
+
return { ok: true, capabilities: null, legacy: !current.capabilities };
|
|
449
|
+
} catch { return { ok: false, code: 'NOT_CONNECTED' }; }
|
|
450
|
+
}
|
|
412
451
|
return {
|
|
452
|
+
probe,
|
|
413
453
|
request, authorize, publishUpdate,
|
|
414
454
|
// Whether an agent may be shown or given this page in full control (the session listing): never a browser page
|
|
415
455
|
// or SynaBun's own.
|
|
@@ -471,8 +511,15 @@ export function createExtensionBridge({ port = 3345, log = () => {}, onInventory
|
|
|
471
511
|
records: () => ({ revokedTabs: revokedTabs.size, revokedSites: revokedSites.size, siteVersions: siteVersions.size }),
|
|
472
512
|
// `paused`: the owner's Disconnect in Settings → Browser holds (kept across a restart until Reconnect / Resume);
|
|
473
513
|
// the extension's own popup cannot reconnect then (AUTH_FAILED).
|
|
474
|
-
|
|
475
|
-
|
|
514
|
+
// `capabilities`: the connected extension's last report of what this browser allows (protocol.js capabilityReport,
|
|
515
|
+
// with `observedAt`, the time it arrived), or null: none connected, or one that sent none (before 1.6.0). Refreshed
|
|
516
|
+
// with every heartbeat ping, and at once by probe().
|
|
517
|
+
status: () => {
|
|
518
|
+
const connected = peer?.ws.readyState === 1 && enabled && peer.ready === true;
|
|
519
|
+
return { connected, paired: !!credential, paused: !enabled, port: server?.address()?.port || port, extensionId: EXTENSION_ID,
|
|
520
|
+
fullControl: mode.fullControl, pairedAt: credential ? pairedAt : 0, extensionVersion: peer?.ready ? peer.version : null,
|
|
521
|
+
capabilities: connected && peer.capabilities ? structuredClone(peer.capabilities) : null, ...structuredClone(state) };
|
|
522
|
+
},
|
|
476
523
|
disconnect,
|
|
477
524
|
resume: () => { enabled = true; persist(); },
|
|
478
525
|
revoke,
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
"$comment": "The one SynaBun Browser Bridge this app release works with (docs/browser-extension-bridge.md -> Where the extension comes from). The app downloads exactly this file when the owner presses \"Connect your browser\" and installs it only when its size and SHA-256 are these. files is the SHA-256 of every file in it (the manifest with its setup content script set to port 1): the folder the browser loads counts as this extension only when it holds exactly these files. version, url, sha256, size and files are written by `node scripts/extension/check-browser-extension-pin.mjs --write` from the zip built out of browser-extension/ (Dev only); never edit them by hand. key is the extension's public key (its manifest's `key`): the extension ID is derived from it and never changes.",
|
|
3
3
|
"name": "SynaBun Browser Bridge",
|
|
4
4
|
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsDPDDuBTQq9nQgulmTSvzujxyOMZ7A7ttMSXtbIwup/X3kOlbkqoJEqQRGGJeb7+cNBSiiDBA5lhS0oYc9YeFcwNCucNMvGawDGblbQzDWEmn9dDK1krFVXWqNHVPIrEWlzCD2swXmIE2FCjMd5zw6dSRmmxu7VgE6bzvuOgB/W/oeOAyCsEDhDRDLBkjmb+yCsuexiXRWoempPsvAVhxhE8zEQJ1e8ChlFMtpOXSobU+YDgKYfcFy9Fbmk/o6M6B9y5zSlzs/HYIu7xvcCwjZI457idVMRxxAT6J/kXytmfKe/zbi5IO5/i0x9SCA1HRvt8K3nJqoH03h4TOvFwOwIDAQAB",
|
|
5
|
-
"version": "1.
|
|
6
|
-
"url": "https://synabun.ai/Public/downloads/browser-extension/synabun-browser-bridge-1.
|
|
7
|
-
"sha256": "
|
|
8
|
-
"size":
|
|
5
|
+
"version": "1.6.0",
|
|
6
|
+
"url": "https://synabun.ai/Public/downloads/browser-extension/synabun-browser-bridge-1.6.0.zip",
|
|
7
|
+
"sha256": "50c51c85b1c49ae3054091cc797087850259fdc8091af4a6b5f40a5bd0fa8379",
|
|
8
|
+
"size": 321390,
|
|
9
9
|
"files": {
|
|
10
10
|
"content.js": "86db13f9688e4501e1d031491e841862382142c6bf04782f8862e1b35fb797c6",
|
|
11
11
|
"engine.js": "acd421f91f0f6fb40c2af3a09ab954c6e962e0932b641639380c094cdb736cec",
|
|
@@ -19,16 +19,16 @@
|
|
|
19
19
|
"icons/status-on-16.png": "c9cbb6e4211f918b2179a796908cf9ebcf7cb5723d9aaa38a93486c2e3b0cd3e",
|
|
20
20
|
"icons/status-on-32.png": "b67d8fb865e02754ca0d1f1f2e0ead08655340a4ad93511e52ff65db4d487ed7",
|
|
21
21
|
"icons/status-on-48.png": "c9f306fb5dcbd6a919e5169e3c87c618116bad54858b434b02245dcd1a40b269",
|
|
22
|
-
"manifest.json": "
|
|
22
|
+
"manifest.json": "6abfa17bb9c48b9779f448ba6a13d6e8ba99e3858697fec8b79921e0cde3a24b",
|
|
23
23
|
"popup-strings.js": "b9d6a147a15dae32b2513437f5de39ec77e8a1ca899086c0092ba31d30dea3d4",
|
|
24
24
|
"popup-view.js": "c5834c2ff19c2cd86fe6954c7a20f154f8804173a022d16910d893bf52491322",
|
|
25
25
|
"popup.css": "d6a6c5442942bede66f315accef476c591ad71ea4ac09b51d689a622753208f1",
|
|
26
26
|
"popup.html": "a2dc445a70a8f3430cc4219ab506c7f942bf36c1bd4f6bc85a07e3d1f619cc24",
|
|
27
27
|
"popup.js": "4d60c643c2adc7d0ee0654e9fe2c5b621259531899a52f64d3b855c98ab82f97",
|
|
28
|
-
"protocol.js": "
|
|
28
|
+
"protocol.js": "b92490cd264eb4f1eb99e8d425bd6a2d0cdf25d2bca07cd3ba313e0d292e7bef",
|
|
29
29
|
"readers-generated.js": "43c4a56f2a195f67712fea55eb12e3d5390082190d5d0b41e41751590f649619",
|
|
30
30
|
"readers.js": "19b7ed04289a2341cdca1035b7fc11bf95d35a31ff48da14097832eb2295e199",
|
|
31
|
-
"service-worker.js": "
|
|
31
|
+
"service-worker.js": "44e529ebe65ccd16b546543257197b448955ae9f11f58efed8b9de6acfd7626a",
|
|
32
32
|
"setup-content.js": "9cb56f6f046af294328c03a080cefc58052ee405366eff5f3d70bb1ea02dbabe",
|
|
33
33
|
"tokens.css": "a27f691794d844cb81b98b45e12863b102e06e9f0a3c722ba96b69b84d3c5a3f"
|
|
34
34
|
}
|
|
@@ -322,6 +322,34 @@ export function command(value) {
|
|
|
322
322
|
|| Object.keys(a).some(k => k !== 'loadState' && k !== 'timeout'))) fail('INVALID_MESSAGE');
|
|
323
323
|
return value;
|
|
324
324
|
}
|
|
325
|
+
// ── Capabilities (1.6.0): what this browser lets the extension do, as the extension saw it ──
|
|
326
|
+
// `{ type: 'capabilities', capabilities: { v, userScripts: { state, execute }, browser: { brands, major, platform } } }`,
|
|
327
|
+
// from the extension only, on the authenticated channel: after its first inventory of a connection and after every
|
|
328
|
+
// pong. It is an observation, never an action: the extension asks the user scripts API for its registered scripts
|
|
329
|
+
// (getScripts) and looks whether `execute` exists, and runs nothing in any tab to learn it. `state`: 'ready' (Allow User Scripts on, `execute` there),
|
|
330
|
+
// 'disabled' (the API is missing or refuses: the switch, before Chrome 138 Developer mode, is off), 'unsupported' (on,
|
|
331
|
+
// but the browser predates userScripts.execute, Chrome 135), 'error' (the check itself failed). `brands` are the
|
|
332
|
+
// browser's names from navigator.userAgentData without its GREASE entries, `major` its Chromium version, `platform`
|
|
333
|
+
// the operating system it names; any of them may be unknown ([] or null).
|
|
334
|
+
// The server never sends this type: an extension from before 1.6.0 ends the connection on a type it does not know, so
|
|
335
|
+
// a fresh observation is asked for with an ordinary ping.
|
|
336
|
+
export const CAPABILITIES_SINCE = '1.6.0';
|
|
337
|
+
export const CAPABILITIES_VERSION = 1;
|
|
338
|
+
export const USER_SCRIPT_STATES = Object.freeze(['ready', 'disabled', 'unsupported', 'error']);
|
|
339
|
+
export const BROWSER_BRANDS_MAX = 6;
|
|
340
|
+
export const BROWSER_NAME = /^[A-Za-z0-9 ._()-]{1,40}$/;
|
|
341
|
+
export const PLATFORM_NAME = /^[A-Za-z0-9 ._()-]{1,16}$/;
|
|
342
|
+
export function capabilityReport(value) {
|
|
343
|
+
object(value, ['v', 'userScripts', 'browser']);
|
|
344
|
+
if (value.v !== CAPABILITIES_VERSION) fail('INVALID_MESSAGE');
|
|
345
|
+
object(value.userScripts, ['state', 'execute']);
|
|
346
|
+
if (!USER_SCRIPT_STATES.includes(value.userScripts.state) || typeof value.userScripts.execute !== 'boolean') fail('INVALID_MESSAGE');
|
|
347
|
+
const b = value.browser; object(b, ['brands', 'major', 'platform']);
|
|
348
|
+
if (!Array.isArray(b.brands) || b.brands.length > BROWSER_BRANDS_MAX || b.brands.some(name => typeof name !== 'string' || !BROWSER_NAME.test(name))) fail('INVALID_MESSAGE');
|
|
349
|
+
if (b.major !== null && (!Number.isSafeInteger(b.major) || b.major < 1 || b.major > 999)) fail('INVALID_MESSAGE');
|
|
350
|
+
if (b.platform !== null && (typeof b.platform !== 'string' || !PLATFORM_NAME.test(b.platform))) fail('INVALID_MESSAGE');
|
|
351
|
+
return value;
|
|
352
|
+
}
|
|
325
353
|
export function payload(value) {
|
|
326
354
|
if (value?.type === 'updateStatus') {
|
|
327
355
|
object(value, ['type', 'version', 'runsActive']);
|
|
@@ -354,7 +382,8 @@ export function payload(value) {
|
|
|
354
382
|
else if (k === 'truncated' || k === 'loading') { if (typeof v !== 'boolean') fail('INVALID_MESSAGE'); }
|
|
355
383
|
else string(v, k === 'base64' ? MAX_MESSAGE - 4096 : ['content', 'text', 'snapshotText', 'value'].includes(k) ? EVALUATE_RESULT_MAX : 8192);
|
|
356
384
|
}
|
|
357
|
-
} else if (value?.type === '
|
|
385
|
+
} else if (value?.type === 'capabilities') { object(value, ['type', 'capabilities']); capabilityReport(value.capabilities); }
|
|
386
|
+
else if (value?.type === 'ping' || value?.type === 'pong' || value?.type === 'unpair') object(value, ['type']);
|
|
358
387
|
// The server gave up on a command (its wait ended): the extension stops it, queued or running, and never starts it.
|
|
359
388
|
else if (value?.type === 'cancel') { object(value, ['type', 'id']); handle(value.id); }
|
|
360
389
|
else command(value);
|
|
@@ -1,35 +1,77 @@
|
|
|
1
|
-
// The
|
|
2
|
-
// docs/browser-extension-bridge.md → One-button setup).
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
1
|
+
// The setup of the everyday-browser extension (Settings → Browser → "Connect your browser";
|
|
2
|
+
// docs/browser-extension-bridge.md → One-button setup). SynaBun finds the browsers, prepares the extension folder and
|
|
3
|
+
// keeps a pairing session open; the owner does the steps no app may do for them (the extensions page, Developer mode,
|
|
4
|
+
// Load unpacked, Allow user scripts); the extension then pairs by itself with a one-time token on SynaBun's own
|
|
5
|
+
// loopback page (SETUP_PAGE_PATH), which its content script recognises.
|
|
6
|
+
//
|
|
7
|
+
// Two ways in. The Settings guide (start with `present: 'none'`) shows the steps in Settings itself: the start prepares
|
|
8
|
+
// the folder and opens the pairing session but opens and shows nothing; the guide then asks, one click each, for the
|
|
9
|
+
// browser's extensions page (openExtensions: the companion page first, once, so the extension finds it when it loads),
|
|
10
|
+
// the browser brought forward for a paste (focus: that same companion page once, then a page that never pairs), the
|
|
11
|
+
// pairing page again (reopen: Pair in <Browser>) and the folder (reveal). The status says `guided`, and the companion page then
|
|
12
|
+
// draws only its pairing status. The older way (start without `present`: the extension popup, older pages) opens the
|
|
13
|
+
// page with its own four steps in the browser. Neither shows the folder by itself: only the owner's click (reveal).
|
|
6
14
|
//
|
|
7
15
|
// The folder's files are the one package this release pins, downloaded from synabun.ai and verified
|
|
8
16
|
// (lib/browser-extension-package.js). A folder that is already there is used as it is, in the same request as before.
|
|
9
17
|
// One that is not there yet, or is older than the pin, is fetched first: the setup is then `downloading` (with the
|
|
10
|
-
// bytes so far), and the
|
|
18
|
+
// bytes so far), and the older way opens its page only once the verified files are in place. A download that
|
|
11
19
|
// fails ends the setup with its code (offline, unavailable, verification failed) and Start again tries once more;
|
|
12
20
|
// nothing is ever installed that did not verify.
|
|
13
21
|
//
|
|
14
22
|
// Every route that reaches this is the owner's (server.js mounts them behind the same guard as pairing and the mode:
|
|
15
|
-
// ownerRouteGuard, this boot's page secret, no automation caller
|
|
16
|
-
//
|
|
23
|
+
// ownerRouteGuard, this boot's page secret, no automation caller; the guide's open-extensions, focus and capabilities
|
|
24
|
+
// check also need Settings' own same-origin request with X-SynaBun-UI). Nothing here starts a program by itself: `exec`
|
|
25
|
+
// is injected (server.js: spawn with an argument array, no shell, detached) and gets a plan from lib/browser-default.js.
|
|
26
|
+
// A request names a browser by its id only; the program comes from the detected install, the address from the catalog.
|
|
17
27
|
//
|
|
18
28
|
// The token: made by ticket(), only while a setup is active and still waiting for the extension, at most
|
|
19
29
|
// MAX_TICKETS times per setup (each one replaces the last), each valid TICKET_MS (and never past the setup's end). The
|
|
20
30
|
// bridge accepts it once, in its pairing handshake, and forgets it (lib/browser-extension-bridge.js
|
|
21
31
|
// beginSetupPairing). It is never logged, never in a status and never in a URL.
|
|
22
|
-
import { launchPlan, revealPlan, SUPPORTED_BROWSER_IDS } from './browser-default.js';
|
|
32
|
+
import { BROWSERS, extensionsPagePlan, launchPlan, revealPlan, SUPPORTED_BROWSER_IDS } from './browser-default.js';
|
|
23
33
|
import { compareVersions, SETUP_PAGE_PATH } from './browser-extension-folder.js';
|
|
24
34
|
import { randomBytes } from 'node:crypto';
|
|
25
35
|
|
|
26
36
|
export const SETUP_STATES = Object.freeze(['idle', 'downloading', 'waiting-for-extension', 'pairing', 'connected', 'unsupported', 'error']);
|
|
27
37
|
/** The codes a download of the extension package can end a setup with (lib/browser-extension-package.js). */
|
|
28
38
|
export const DOWNLOAD_ERRORS = Object.freeze(['EXTENSION_DOWNLOAD_OFFLINE', 'EXTENSION_DOWNLOAD_UNAVAILABLE', 'EXTENSION_VERIFY_FAILED']);
|
|
39
|
+
/** What a start may be told to show: nothing (the Settings guide). Without it, the older way opens its page. */
|
|
40
|
+
export const PRESENT_MODES = Object.freeze(['none']);
|
|
29
41
|
export const SETUP_WINDOW_MS = 15 * 60 * 1000;
|
|
30
42
|
export const TICKET_MS = 2 * 60 * 1000;
|
|
31
43
|
export const MAX_TICKETS = 5;
|
|
44
|
+
/** How long a look at the installed browsers is reused: the guide polls, and each look starts plutil or reg. */
|
|
45
|
+
export const DETECT_CACHE_MS = 30 * 1000;
|
|
46
|
+
/**
|
|
47
|
+
* The wait between the companion page and the extensions page when both are opened by one click. Each launch only
|
|
48
|
+
* starts a program that hands the address to the browser and returns at once, so two started together may arrive in
|
|
49
|
+
* either order; the extensions page should be the tab the owner sees.
|
|
50
|
+
*/
|
|
51
|
+
export const COMPANION_GAP_MS = 800;
|
|
52
|
+
/** How long the capabilities check waits for the extension (lib/browser-extension-bridge.js probe). */
|
|
53
|
+
export const PROBE_TIMEOUT_MS = 4000;
|
|
54
|
+
/** The query of the setup page opened only to bring a browser forward (focus): that page never pairs. */
|
|
55
|
+
export const FOCUS_QUERY = 'focus=1';
|
|
32
56
|
const fail = (code, message = code) => { throw Object.assign(new Error(message), { code }); };
|
|
57
|
+
const PLATFORM_NAMES = Object.freeze({ darwin: 'mac', win32: 'windows' });
|
|
58
|
+
const UNKNOWN_BROWSER = Object.freeze({ id: 'unknown', name: 'Unknown browser', supported: false });
|
|
59
|
+
/**
|
|
60
|
+
* The browser a request names: a body of exactly `{ browser: <supported id> }`. Any other key, a value that is not
|
|
61
|
+
* one of SUPPORTED_BROWSER_IDS (an address, a path, a program, an argument) is INVALID_MESSAGE: nothing of the request
|
|
62
|
+
* ever becomes a program, an argument or an address; those come from the detected install and the catalog.
|
|
63
|
+
*/
|
|
64
|
+
function requestedBrowser(body) {
|
|
65
|
+
if (!body || typeof body !== 'object' || Array.isArray(body)) fail('INVALID_MESSAGE');
|
|
66
|
+
const keys = Object.keys(body);
|
|
67
|
+
if (keys.length !== 1 || keys[0] !== 'browser' || typeof body.browser !== 'string' || !SUPPORTED_BROWSER_IDS.includes(body.browser)) fail('INVALID_MESSAGE');
|
|
68
|
+
return body.browser;
|
|
69
|
+
}
|
|
70
|
+
/** A browser by its id, named from the catalog only (never a raw bundle id, ProgId or desktop file). */
|
|
71
|
+
const named = browser => {
|
|
72
|
+
const known = browser && typeof browser.id === 'string' && Object.hasOwn(BROWSERS, browser.id) ? BROWSERS[browser.id] : null;
|
|
73
|
+
return known ? { id: known.id, name: known.name } : { id: UNKNOWN_BROWSER.id, name: UNKNOWN_BROWSER.name };
|
|
74
|
+
};
|
|
33
75
|
|
|
34
76
|
/**
|
|
35
77
|
* Whether the browser should be told to reload the extension: it is connected, the folder holds what this release
|
|
@@ -61,15 +103,53 @@ export function extensionVersions({ connected, extensionVersion, folderVersion,
|
|
|
61
103
|
* `folderVersion()` the version the folder holds, `packageStatus()` → { pinnedVersion, needs, phase, received, total,
|
|
62
104
|
* code, reloadPending } (browser-extension-package.js status; `needs` says that `prepare` will download),
|
|
63
105
|
* `confirmReload()` the setup page saw the extension's content script on this port (browser-extension-package.js; it
|
|
64
|
-
* never clears a repair's Reload).
|
|
106
|
+
* never clears a repair's Reload). `detectMs`: how long a look at the browsers is reused (DETECT_CACHE_MS);
|
|
107
|
+
* `pause(ms)` waits between two launches of one click (tests pass one that does not wait).
|
|
65
108
|
*/
|
|
66
109
|
export function createExtensionSetup({ bridge, detect, prepare, exec, appOrigin, platform = process.platform, now = Date.now,
|
|
67
|
-
windowMs = SETUP_WINDOW_MS, ticketMs = TICKET_MS, maxTickets = MAX_TICKETS, folderVersion = () => null, packageStatus = () => ({}), confirmReload = () => false, updateStatus
|
|
110
|
+
windowMs = SETUP_WINDOW_MS, ticketMs = TICKET_MS, maxTickets = MAX_TICKETS, folderVersion = () => null, packageStatus = () => ({}), confirmReload = () => false, updateStatus,
|
|
111
|
+
detectMs = DETECT_CACHE_MS, companionGapMs = COMPANION_GAP_MS, probeTimeoutMs = PROBE_TIMEOUT_MS, pause = ms => new Promise(resolve => setTimeout(resolve, ms)) } = {}) {
|
|
68
112
|
let setup = null;
|
|
69
113
|
// The latest start, from its first step: a cancel or a later start ends it before it prepares or opens anything.
|
|
70
114
|
let attempt = null;
|
|
115
|
+
// The last look at the browsers ({ at, value }) and the one under way. The Settings guide asks for the list while it
|
|
116
|
+
// is open; a look starts plutil or reg, so one is reused for `detectMs` (a start, and ?refresh=1, always look again).
|
|
117
|
+
let detection = null, detecting = null;
|
|
118
|
+
// The browser whose setup made the bridge's current pairing ({ browser: { id, name }, pairedAt }), remembered when
|
|
119
|
+
// state() first sees that pairing and reported while the bridge still holds it. In memory only: after a restart a
|
|
120
|
+
// pairing has no setup to name, and the guide then asks the owner rather than calling an earlier browser ready.
|
|
121
|
+
let pairedThrough = null;
|
|
71
122
|
const pageUrl = () => `${appOrigin()}${SETUP_PAGE_PATH}`;
|
|
123
|
+
// The same page opened only to bring the browser forward (focus): it never asks for a token (es-page.js FOCUS_ONLY).
|
|
124
|
+
const focusUrl = () => `${pageUrl()}?${FOCUS_QUERY}`;
|
|
72
125
|
const describe = browser => browser ? { id: browser.id, name: browser.name, supported: browser.supported === true, extensionsUrl: browser.extensionsUrl || null } : null;
|
|
126
|
+
// The supported browsers a look found, once each; the default as it was found (it may be unsupported or unknown).
|
|
127
|
+
const normalize = found => {
|
|
128
|
+
const installed = [];
|
|
129
|
+
for (const browser of Array.isArray(found?.installedBrowsers) ? found.installedBrowsers : []) {
|
|
130
|
+
if (browser?.supported && SUPPORTED_BROWSER_IDS.includes(browser.id) && !installed.some(b => b.id === browser.id)) installed.push(browser);
|
|
131
|
+
}
|
|
132
|
+
return { browser: found?.browser && typeof found.browser === 'object' ? found.browser : null, installedBrowsers: installed };
|
|
133
|
+
};
|
|
134
|
+
// A look that fails is no browser and none installed, never an error: the guide then says what it could not find.
|
|
135
|
+
function look() {
|
|
136
|
+
const run = Promise.resolve().then(() => detect()).then(normalize, () => normalize(null));
|
|
137
|
+
detecting = run;
|
|
138
|
+
void run.then(value => { if (detecting === run) { detecting = null; detection = { at: now(), value }; } });
|
|
139
|
+
return run;
|
|
140
|
+
}
|
|
141
|
+
function browsers({ refresh = false } = {}) {
|
|
142
|
+
const at = now();
|
|
143
|
+
if (!refresh && detection && at >= detection.at && at - detection.at < detectMs) return Promise.resolve(detection.value);
|
|
144
|
+
if (!refresh && detecting) return detecting;
|
|
145
|
+
return look();
|
|
146
|
+
}
|
|
147
|
+
// An installed supported browser by its id, with its `launch` (never shown): only what a look found is started.
|
|
148
|
+
async function installedBrowser(id) {
|
|
149
|
+
const browser = (await browsers()).installedBrowsers.find(b => b.id === id);
|
|
150
|
+
if (!browser) fail('BROWSER_NOT_INSTALLED');
|
|
151
|
+
return browser;
|
|
152
|
+
}
|
|
73
153
|
function state() {
|
|
74
154
|
if (!setup) return 'idle';
|
|
75
155
|
if (setup.error) return 'error';
|
|
@@ -77,23 +157,43 @@ export function createExtensionSetup({ bridge, detect, prepare, exec, appOrigin,
|
|
|
77
157
|
const bridgeStatus = bridge.status();
|
|
78
158
|
// Paired by this setup: a pairing made after it began (its token, or the typed code as a fallback). Connected once
|
|
79
159
|
// the extension's first inventory arrived; "Pairing…" from the token's handshake until then.
|
|
80
|
-
if (bridgeStatus.paired && bridgeStatus.pairedAt !== setup.pairedBefore)
|
|
160
|
+
if (bridgeStatus.paired && bridgeStatus.pairedAt !== setup.pairedBefore) {
|
|
161
|
+
if (pairedThrough?.pairedAt !== bridgeStatus.pairedAt) pairedThrough = setup.browser?.supported ? { browser: named(setup.browser), pairedAt: bridgeStatus.pairedAt } : null;
|
|
162
|
+
return bridgeStatus.connected ? 'connected' : 'pairing';
|
|
163
|
+
}
|
|
81
164
|
if (bridge.setupPairing().attempted) return 'pairing';
|
|
82
165
|
if (now() >= setup.until) { expire(); return 'error'; }
|
|
83
166
|
if (!setup.browser?.supported) return 'unsupported';
|
|
84
167
|
return 'waiting-for-extension';
|
|
85
168
|
}
|
|
169
|
+
// The browser that made the bridge's current pairing through a setup, or null once that pairing is gone or replaced.
|
|
170
|
+
function pairedNow(bridgeStatus) {
|
|
171
|
+
if (pairedThrough && (!bridgeStatus.paired || bridgeStatus.pairedAt !== pairedThrough.pairedAt)) pairedThrough = null;
|
|
172
|
+
return pairedThrough ? { ...pairedThrough.browser } : null;
|
|
173
|
+
}
|
|
86
174
|
function expire() {
|
|
87
175
|
if (!setup || setup.error) return;
|
|
88
176
|
bridge.endSetupPairing(); setup.error = { code: 'SETUP_EXPIRED' };
|
|
89
177
|
}
|
|
90
|
-
async function open(browser) {
|
|
91
|
-
try { const plan = launchPlan(platform, browser,
|
|
178
|
+
async function open(browser, url = pageUrl()) {
|
|
179
|
+
try { const plan = launchPlan(platform, browser, url); await exec(plan.cmd, plan.args); return true; } catch { return false; }
|
|
92
180
|
}
|
|
181
|
+
// Only on the owner's click (POST …/setup/reveal): no start shows the folder by itself.
|
|
93
182
|
async function reveal() {
|
|
94
183
|
if (!setup?.folder) fail('SETUP_NOT_ACTIVE');
|
|
95
|
-
|
|
96
|
-
|
|
184
|
+
const mine = setup;
|
|
185
|
+
try { const plan = revealPlan(platform, mine.folder); await exec(plan.cmd, plan.args); mine.revealed = true; return { ok: true, folder: mine.folder }; }
|
|
186
|
+
catch { return { ok: false, code: 'REVEAL_FAILED', folder: mine.folder }; }
|
|
187
|
+
}
|
|
188
|
+
// The companion page, before the extensions page of the same click: once per setup, only in the setup's own browser
|
|
189
|
+
// and only while the setup still waits for the extension (or downloads it), so the extension finds the page and pairs
|
|
190
|
+
// by itself once it is loaded. True when it was opened now.
|
|
191
|
+
async function openCompanion(browser) {
|
|
192
|
+
const mine = setup;
|
|
193
|
+
if (!mine || mine.opened || mine.companionOpening || mine.browser?.id !== browser.id || !['downloading', 'waiting-for-extension'].includes(state())) return false;
|
|
194
|
+
mine.companionOpening = true;
|
|
195
|
+
try { const opened = await open(browser); if (opened) mine.opened = true; return opened; }
|
|
196
|
+
finally { mine.companionOpening = false; }
|
|
97
197
|
}
|
|
98
198
|
function view() {
|
|
99
199
|
const current = state(), bridgeStatus = bridge.status();
|
|
@@ -103,10 +203,12 @@ export function createExtensionSetup({ bridge, detect, prepare, exec, appOrigin,
|
|
|
103
203
|
return {
|
|
104
204
|
state: current,
|
|
105
205
|
...(updateStatus ? { update: updateStatus(bridgeStatus, pkg) } : {}),
|
|
106
|
-
...(setup ? { setupId: setup.id, browser: describe(setup.browser), defaultBrowser: describe(setup.defaultBrowser), installedBrowsers: setup.installed.map(describe),
|
|
206
|
+
...(setup ? { setupId: setup.id, guided: setup.guided === true, browser: describe(setup.browser), defaultBrowser: describe(setup.defaultBrowser), installedBrowsers: setup.installed.map(describe),
|
|
107
207
|
folder: setup.folder, extensionsUrl: setup.browser?.extensionsUrl || null, opened: setup.opened, revealed: setup.revealed, expiresAt: setup.until } : {}),
|
|
108
208
|
...(setup?.error ? { code: setup.error.code } : {}),
|
|
109
209
|
connected: bridgeStatus.connected, paired: bridgeStatus.paired, bridgePort: bridgeStatus.port,
|
|
210
|
+
// Which browser's setup made the current pairing: the guide calls a bridge "ready" for the browser it set up only.
|
|
211
|
+
pairedThrough: pairedNow(bridgeStatus),
|
|
110
212
|
extensionVersion: bridgeStatus.extensionVersion || null, folderVersion: version, pinnedVersion,
|
|
111
213
|
// The bytes so far while the pinned package is on its way (the setup's own download, or an update's).
|
|
112
214
|
...(pkg.phase === 'downloading' ? { download: { received: Number(pkg.received) || 0, total: Number(pkg.total) || 0 } } : {}),
|
|
@@ -119,10 +221,14 @@ export function createExtensionSetup({ bridge, detect, prepare, exec, appOrigin,
|
|
|
119
221
|
/**
|
|
120
222
|
* Starts (or restarts) a setup. `browserId`: one of the installed supported browsers, for "open in X instead";
|
|
121
223
|
* without it the default browser, which may be unsupported (then the page is not opened and the state is
|
|
122
|
-
* `unsupported` with the installed browsers to choose from).
|
|
224
|
+
* `unsupported` with the installed browsers to choose from). `present: 'none'` (the Settings guide): the folder
|
|
225
|
+
* and the pairing session only, nothing opened (`guided` in the status); without it the page opens in the browser
|
|
226
|
+
* once the folder is ready. Neither shows the folder: that is reveal(), on the owner's click.
|
|
123
227
|
*/
|
|
124
|
-
async start({ browserId } = {}) {
|
|
228
|
+
async start({ browserId, present } = {}) {
|
|
125
229
|
if (browserId !== undefined && browserId !== null && !SUPPORTED_BROWSER_IDS.includes(browserId)) fail('INVALID_MESSAGE');
|
|
230
|
+
if (present !== undefined && present !== null && !PRESENT_MODES.includes(present)) fail('INVALID_MESSAGE');
|
|
231
|
+
const guided = present === 'none';
|
|
126
232
|
if (setup) { bridge.endSetupPairing(); setup.stop?.abort(); }
|
|
127
233
|
// This start is the current one before its first wait: a cancel during the browser detection, or a later start
|
|
128
234
|
// whose detection ends first, leaves this one nothing to do when its own detection ends.
|
|
@@ -130,31 +236,29 @@ export function createExtensionSetup({ bridge, detect, prepare, exec, appOrigin,
|
|
|
130
236
|
const own = { stop: new AbortController() };
|
|
131
237
|
attempt = own;
|
|
132
238
|
const superseded = () => attempt !== own || own.stop.signal.aborted;
|
|
133
|
-
|
|
134
|
-
|
|
239
|
+
// Always a fresh look: the owner may have installed a browser since the guide last asked.
|
|
240
|
+
const detected = await look();
|
|
135
241
|
if (superseded()) return view();
|
|
136
|
-
const installed =
|
|
137
|
-
const defaultBrowser = detected
|
|
242
|
+
const installed = detected.installedBrowsers;
|
|
243
|
+
const defaultBrowser = detected.browser || { ...UNKNOWN_BROWSER, extensionsUrl: null };
|
|
138
244
|
let browser = defaultBrowser;
|
|
139
245
|
if (browserId) {
|
|
140
246
|
browser = installed.find(b => b.id === browserId);
|
|
141
247
|
if (!browser) fail('BROWSER_NOT_INSTALLED');
|
|
142
248
|
}
|
|
143
|
-
setup = { id: randomBytes(12).toString('hex'), startedAt: now(), until: now() + windowMs, browser, defaultBrowser, installed,
|
|
249
|
+
setup = { id: randomBytes(12).toString('hex'), startedAt: now(), until: now() + windowMs, browser, defaultBrowser, installed, guided,
|
|
144
250
|
folder: null, opened: false, revealed: false, tickets: 0, pairedBefore: bridge.status().pairedAt || 0, error: null };
|
|
145
251
|
const mine = setup;
|
|
146
252
|
mine.stop = own.stop;
|
|
147
253
|
// A browser that cannot run the extension gets no download: the page offers the installed ones, and choosing one
|
|
148
254
|
// starts the setup again.
|
|
149
255
|
if (!browser.supported && (packageStatus() || {}).needs) return view();
|
|
150
|
-
// Once the folder is ready
|
|
151
|
-
//
|
|
152
|
-
const
|
|
153
|
-
if (!browser.supported || setup !== mine || superseded()) return;
|
|
256
|
+
// Once the folder is ready, the older way opens the page in the browser (never for a start that was cancelled or
|
|
257
|
+
// replaced meanwhile). The guide opens nothing: each of its steps is the owner's click.
|
|
258
|
+
const presentPage = async () => {
|
|
259
|
+
if (guided || !browser.supported || setup !== mine || superseded()) return;
|
|
154
260
|
mine.opened = await open(browser);
|
|
155
|
-
if (setup
|
|
156
|
-
mine.revealed = (await reveal()).ok === true;
|
|
157
|
-
if (!mine.opened) mine.error = { code: 'OPEN_FAILED' };
|
|
261
|
+
if (setup === mine && !mine.opened) mine.error = { code: 'OPEN_FAILED' };
|
|
158
262
|
};
|
|
159
263
|
// Started in this step, so the answer below already carries a download's progress.
|
|
160
264
|
let preparing;
|
|
@@ -167,15 +271,77 @@ export function createExtensionSetup({ bridge, detect, prepare, exec, appOrigin,
|
|
|
167
271
|
const needed = packageStatus() || {};
|
|
168
272
|
if (needed.needs || needed.phase === 'downloading') {
|
|
169
273
|
mine.preparing = true;
|
|
170
|
-
mine.settled = ready.then(async () => { mine.preparing = false; if (setup === mine && !mine.error) await
|
|
274
|
+
mine.settled = ready.then(async () => { mine.preparing = false; if (setup === mine && !mine.error) await presentPage(); }).catch(() => { mine.preparing = false; });
|
|
171
275
|
return view();
|
|
172
276
|
}
|
|
173
277
|
await ready;
|
|
174
278
|
if (setup !== mine || mine.error) return view();
|
|
175
|
-
await
|
|
279
|
+
await presentPage();
|
|
176
280
|
return view();
|
|
177
281
|
},
|
|
178
282
|
status: view, state,
|
|
283
|
+
/**
|
|
284
|
+
* The browsers for the Settings guide (GET …/setup/browsers): { platform, defaultBrowser: { id, name, supported },
|
|
285
|
+
* installedBrowsers: [{ id, name, extensionsUrl }], suggested }. Names and addresses come from the catalog
|
|
286
|
+
* (browser-default.js BROWSERS); no program, bundle id, path or desktop file is ever in it. `suggested`: the default
|
|
287
|
+
* when it is supported and installed, else the first installed one, else null. `refresh`: look again now.
|
|
288
|
+
*/
|
|
289
|
+
async browsers({ refresh = false } = {}) {
|
|
290
|
+
const found = await browsers({ refresh });
|
|
291
|
+
const known = found.browser && typeof found.browser.id === 'string' && Object.hasOwn(BROWSERS, found.browser.id) ? BROWSERS[found.browser.id] : null;
|
|
292
|
+
const defaultBrowser = known ? { id: known.id, name: known.name, supported: known.supported } : { ...UNKNOWN_BROWSER };
|
|
293
|
+
const installedBrowsers = found.installedBrowsers.map(b => ({ id: b.id, name: BROWSERS[b.id].name, extensionsUrl: BROWSERS[b.id].extensionsUrl }));
|
|
294
|
+
const suggested = defaultBrowser.supported && installedBrowsers.some(b => b.id === defaultBrowser.id) ? defaultBrowser.id : installedBrowsers[0]?.id ?? null;
|
|
295
|
+
return { platform: PLATFORM_NAMES[platform] || 'linux', defaultBrowser, installedBrowsers, suggested };
|
|
296
|
+
},
|
|
297
|
+
/**
|
|
298
|
+
* Opens an installed browser's own extensions page (POST …/setup/open-extensions, body exactly `{ browser }`). The
|
|
299
|
+
* address is the catalog's for that browser and the program the one its detected install names
|
|
300
|
+
* (browser-default.js extensionsPagePlan). When a setup for that browser has not opened its companion page yet, that
|
|
301
|
+
* page opens first. Answers { ok, code?, browser: { id, name }, extensionsUrl, companion }: `companion` says the
|
|
302
|
+
* companion page was opened by this click. `ok: false, code: 'OPEN_FAILED'` when the program could not be started.
|
|
303
|
+
*/
|
|
304
|
+
async openExtensions(body) {
|
|
305
|
+
const browser = await installedBrowser(requestedBrowser(body));
|
|
306
|
+
const shown = named(browser), extensionsUrl = BROWSERS[browser.id].extensionsUrl;
|
|
307
|
+
const companion = await openCompanion(browser);
|
|
308
|
+
if (companion) await pause(companionGapMs);
|
|
309
|
+
// `ok` means the program that hands the address to the browser started, never that the page appeared: a launch
|
|
310
|
+
// cannot see the browser's window, and a browser may refuse an address of its own scheme given from outside. The
|
|
311
|
+
// guide keeps its "Page didn't open?" way (copy the address) for that.
|
|
312
|
+
try { const plan = extensionsPagePlan(platform, browser); await exec(plan.cmd, plan.args); return { ok: true, browser: shown, extensionsUrl, companion }; }
|
|
313
|
+
catch { return { ok: false, code: 'OPEN_FAILED', browser: shown, extensionsUrl, companion }; }
|
|
314
|
+
},
|
|
315
|
+
/**
|
|
316
|
+
* Brings an installed browser forward for "Copy address & open <Browser>" (POST …/setup/focus, body exactly
|
|
317
|
+
* `{ browser }`): the owner pastes the copied extensions address into the tab this opens, which replaces it. So that
|
|
318
|
+
* tab is the focus-only page (SETUP_PAGE_PATH?focus=1), which never asks for a token: the paste takes no pairing with
|
|
319
|
+
* it. As with openExtensions, an active setup of that browser that has not opened its companion page yet opens it
|
|
320
|
+
* first, once, behind the focus page; nothing else counts as the companion. Answers { ok, code?, browser: { id, name },
|
|
321
|
+
* extensionsUrl, companion } (`ok` says the launch started, not that the window came forward).
|
|
322
|
+
*/
|
|
323
|
+
async focus(body) {
|
|
324
|
+
const browser = await installedBrowser(requestedBrowser(body));
|
|
325
|
+
const shown = named(browser), extensionsUrl = BROWSERS[browser.id].extensionsUrl;
|
|
326
|
+
const companion = await openCompanion(browser);
|
|
327
|
+
if (companion) await pause(companionGapMs);
|
|
328
|
+
const opened = await open(browser, focusUrl());
|
|
329
|
+
return opened ? { ok: true, browser: shown, extensionsUrl, companion } : { ok: false, code: 'OPEN_FAILED', browser: shown, extensionsUrl, companion };
|
|
330
|
+
},
|
|
331
|
+
/**
|
|
332
|
+
* What the paired extension can do now (POST …/capabilities/check, body `{}`): the bridge's probe, which asks the
|
|
333
|
+
* connected extension and never throws ({ ok, code?, capabilities, legacy }). A bridge without a probe is an older
|
|
334
|
+
* one: { ok: true, capabilities: null, legacy: true }.
|
|
335
|
+
*/
|
|
336
|
+
async capabilities(body) {
|
|
337
|
+
if (body !== undefined && body !== null && (typeof body !== 'object' || Array.isArray(body) || Object.keys(body).length)) fail('INVALID_MESSAGE');
|
|
338
|
+
if (typeof bridge.probe !== 'function') return { ok: true, capabilities: null, legacy: true };
|
|
339
|
+
let result = null;
|
|
340
|
+
try { result = await bridge.probe({ timeoutMs: probeTimeoutMs }); } catch {}
|
|
341
|
+
if (!result || typeof result !== 'object') return { ok: false, code: 'CAPABILITIES_CHECK_FAILED', capabilities: null, legacy: false };
|
|
342
|
+
// The probe's own fields only, so nothing else the bridge may carry reaches the page.
|
|
343
|
+
return { ok: result.ok === true, ...(typeof result.code === 'string' ? { code: result.code } : {}), capabilities: result.capabilities ?? null, legacy: result.legacy === true };
|
|
344
|
+
},
|
|
179
345
|
/**
|
|
180
346
|
* The setup page saw the extension's content script on this server's port (POST …/setup/seen): the browser runs
|
|
181
347
|
* the folder's manifest for this port, so the Reload a port change asked for is done. A repair's Reload is not: the
|
|
@@ -203,7 +369,8 @@ export function createExtensionSetup({ bridge, detect, prepare, exec, appOrigin,
|
|
|
203
369
|
settled: () => setup?.settled || Promise.resolve(),
|
|
204
370
|
reveal,
|
|
205
371
|
/** Opens the setup page again (in the setup's browser). */
|
|
206
|
-
|
|
372
|
+
// (The pairing page, never the focus-only one: the guide's Pair in <Browser> asks for this. `opened` is this launch's.)
|
|
373
|
+
async reopen() { const mine = setup; if (!mine?.browser?.supported) fail('SETUP_NOT_ACTIVE'); const opened = await open(mine.browser); if (setup === mine && opened) mine.opened = true; return { ...view(), opened }; },
|
|
207
374
|
};
|
|
208
375
|
}
|
|
209
376
|
|
|
@@ -219,8 +386,9 @@ export const SETUP_ERROR_TEXT = Object.freeze({
|
|
|
219
386
|
EXTENSION_DOWNLOAD_OFFLINE: 'SynaBun could not reach synabun.ai to download the extension. Check the internet connection, then start "Connect your browser" again.',
|
|
220
387
|
EXTENSION_DOWNLOAD_UNAVAILABLE: 'synabun.ai did not have the extension this SynaBun version needs. Try again later, or update SynaBun.',
|
|
221
388
|
EXTENSION_VERIFY_FAILED: 'The downloaded extension was not the file this SynaBun version expects, so it was not installed. Try again; if it keeps failing, update SynaBun.',
|
|
222
|
-
OPEN_FAILED: 'SynaBun could not open the
|
|
223
|
-
REVEAL_FAILED: 'SynaBun could not show the folder. Copy its path from
|
|
389
|
+
OPEN_FAILED: 'SynaBun could not open the page in the browser. Copy its address from Settings → Browser and open it yourself.',
|
|
390
|
+
REVEAL_FAILED: 'SynaBun could not show the folder. Copy its path from Settings → Browser.',
|
|
391
|
+
CAPABILITIES_CHECK_FAILED: 'SynaBun could not ask the extension what it can do. Try again.',
|
|
224
392
|
INVALID_MESSAGE: 'Invalid setup request.',
|
|
225
393
|
});
|
|
226
394
|
export function setupError(error) {
|