synabun 2.4.4 → 2.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/README.md +1 -1
- package/docs/browser-extension-bridge.md +5 -4
- package/docs/whatsapp.md +3 -3
- 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/tools/agents.d.ts +16 -3
- package/mcp-server/dist/tools/agents.d.ts.map +1 -1
- package/mcp-server/dist/tools/agents.js +74 -11
- package/mcp-server/dist/tools/agents.js.map +1 -1
- package/mcp-server/package-lock.json +2 -2
- package/mcp-server/package.json +1 -1
- package/mcp-server/src/services/neural-interface.ts +2 -1
- package/mcp-server/src/tools/agents.ts +67 -11
- package/neural-interface/i18n/en.json +349 -9
- package/neural-interface/i18n/pt-BR.json +349 -9
- 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-brains/antigravity.js +4 -2
- 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 +16 -5
- package/neural-interface/lib/assistant-spilled-output.js +53 -0
- 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/remote-policy.js +24 -7
- 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 +349 -29
- package/neural-interface/lib/teams/worktrees.js +123 -30
- 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/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/browser-extension-updates.js +3 -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/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/styles.css +196 -13
- package/neural-interface/public/shared/ui-settings.js +48 -11
- package/neural-interface/server.js +20 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
|
@@ -171,14 +171,18 @@ export function createRouteGate({ sessionId = null, routeTool = () => 'agent_rou
|
|
|
171
171
|
let taskKey = '';
|
|
172
172
|
let unavailable = null;
|
|
173
173
|
let cli = false;
|
|
174
|
+
let decided = [];
|
|
174
175
|
|
|
175
176
|
/**
|
|
176
177
|
* `carry` keeps the refusal count (the reactive fallback's follow-up turn still counts toward the loop guard).
|
|
177
178
|
* `cli`: Claude Code started this turn by itself (a background task, agent or wakeup reported back).
|
|
179
|
+
* `decided`: the routes the user decided for a worker that this (mailbox) turn carries ([{ routeId, target }]). The
|
|
180
|
+
* turn stays unrouted (those routes open no tools here); its refusals name them instead of saying nothing was routed.
|
|
178
181
|
*/
|
|
179
|
-
function startTurn({ open = false, carry = false, taskId: currentTask = taskId, cli: byCli = false } = {}) {
|
|
182
|
+
function startTurn({ open = false, carry = false, taskId: currentTask = taskId, cli: byCli = false, decided: decidedRoutes = null } = {}) {
|
|
180
183
|
turn += 1;
|
|
181
184
|
cli = byCli === true;
|
|
185
|
+
decided = Array.isArray(decidedRoutes) ? decidedRoutes.filter((route) => route && route.routeId).slice(0, 5) : [];
|
|
182
186
|
taskId = currentTask;
|
|
183
187
|
taskKey = '';
|
|
184
188
|
state = open ? 'open' : 'unrouted';
|
|
@@ -219,6 +223,11 @@ export function createRouteGate({ sessionId = null, routeTool = () => 'agent_rou
|
|
|
219
223
|
const cliNote = cli ? ' This turn was started by Claude Code itself (a background task, agent or wakeup reported back): route the task it belongs to again with its task_key, then read that job\'s output and carry the task on.' : '';
|
|
220
224
|
// OpenCode's Code Mode tool: a model that went looking for SynaBun's tools inside it is told where they are.
|
|
221
225
|
const codeMode = name.toLowerCase() === 'execute' ? ` SynaBun's own tools, ${routeTool()} included, are separate tools in your tool list: call them directly, never through execute.` : '';
|
|
226
|
+
// A mailbox turn that carries a route the user decided for a worker: that route is the worker's, not this turn's.
|
|
227
|
+
if (decided.length) {
|
|
228
|
+
const routes = decided.map((route) => `${route.routeId} → ${targetLabel(route.target)}`).join(', ');
|
|
229
|
+
return `SynaBun route gate: ${name} was refused. The route the user decided (${routes}) is a worker's: it opens no tools in this turn. Dispatch it with agent_dispatch and its route_id if you have not yet, then end your turn with one short line; read the worker's progress with agent_status / agent_read / agent_wait. Other work in this turn needs its own route: call ${routeTool()} first${sessionId ? ` (assistant_session_id "${sessionId}")` : ''}. Memory tools, agent_* tools and asking the user work without routing.${codeMode}`;
|
|
230
|
+
}
|
|
222
231
|
return `SynaBun route gate: ${name} was refused because this turn is not routed. Call ${routeTool()} first (task_class, one-line summary, confidence, 1-3 proposals${sessionId ? `, assistant_session_id "${sessionId}"` : ''}) and follow its status: approved + direct opens every tool for this turn. To resume an approved task, route again with the same task_key; a consumed continuation returns approved with continuation:false. Memory tools, agent_* tools and asking the user work without routing. For plain conversation, just answer in text.${cliNote}${codeMode}`;
|
|
223
232
|
}
|
|
224
233
|
/**
|
|
@@ -237,7 +246,7 @@ export function createRouteGate({ sessionId = null, routeTool = () => 'agent_rou
|
|
|
237
246
|
if (abort) aborted = true;
|
|
238
247
|
return { allow: false, state, refusals, abort, reason: refusalText(tool) };
|
|
239
248
|
}
|
|
240
|
-
function snapshot() { return { state, turn, refusals, routeId, taskId, taskKey, held: heldText, aborted, unavailable, cli }; }
|
|
249
|
+
function snapshot() { return { state, turn, refusals, routeId, taskId, taskKey, held: heldText, aborted, unavailable, cli, decided: decided.map((route) => route.routeId) }; }
|
|
241
250
|
|
|
242
251
|
return { startTurn, onRouteResult, onRouteError, onClarify, setUnavailable, check, snapshot, isOpen: () => !!unavailable || state === 'open' || state === 'failed' };
|
|
243
252
|
}
|
|
@@ -36,6 +36,7 @@ import { chooseUsageAccount } from './account-usage.js';
|
|
|
36
36
|
import { defaultIsHidden, enabledStandIn, findModel, providerAllHidden, selectSheetModels } from './assistant-catalog.js';
|
|
37
37
|
import { EFFORT_OFF, normalizeEffort } from './effort-levels.js';
|
|
38
38
|
import { claudeRouteAvailability, createRouteGate, isReplyTool, mcpStatusRouteAvailability, ROUTE_GATE_LOOP_MESSAGE } from './assistant-route-gate.js';
|
|
39
|
+
import { claudeSpilledResultRead } from './assistant-spilled-output.js';
|
|
39
40
|
import { claudeReadOnlyPermission, planDenyMessage, planToolDecision, readOnlyDenyMessage, readOnlyToolDecision } from './assistant-plan-permissions.js';
|
|
40
41
|
import { codexRouteGateBootstrap } from './assistant-route-gate-codex.js';
|
|
41
42
|
import { proposedPlanText } from './assistant-envelope.js';
|
|
@@ -2222,6 +2223,8 @@ export function createAssistantRuntime({
|
|
|
2222
2223
|
budget: budgetSetting ? { ...budgetSetting, view: money } : null,
|
|
2223
2224
|
clarify: !!clarifier,
|
|
2224
2225
|
channel: live.record.channel || live.record.remote?.channel || null,
|
|
2226
|
+
// The configured level (a turn's untrusted cap aside): a change of Autonomous restarts the brain (needsRestart).
|
|
2227
|
+
remoteLevel: (() => { const policy = remotePolicyFor(live); return policy ? effectiveLevel(policy, { now: now() }) : null; })(),
|
|
2225
2228
|
});
|
|
2226
2229
|
}
|
|
2227
2230
|
/**
|
|
@@ -2548,7 +2551,7 @@ export function createAssistantRuntime({
|
|
|
2548
2551
|
// `offerPlan`: a system turn that revises a plan still ends with a plan card.
|
|
2549
2552
|
// `work`: the scheduler entry this system turn is; `request`: { id, reply } of a
|
|
2550
2553
|
// prompt a socket sent (refuse); `turnGen`: the generation runQuery entered in.
|
|
2551
|
-
async function runTurn(live, { text, images = [], cwd = null, model = null, effort = null, permissionMode = null, planMode = null, system = false, taskId = null, turnModel = null, turnEffort = null, gateOpen = false, gateCarry = false, origin = null, authority = null, untrusted = false, offerPlan = false, work = null, request = null, turnGen = live.gen, computerRoutes = null, typed = null, greetingId = null } = {}) {
|
|
2554
|
+
async function runTurn(live, { text, images = [], cwd = null, model = null, effort = null, permissionMode = null, planMode = null, system = false, taskId = null, turnModel = null, turnEffort = null, gateOpen = false, gateCarry = false, gateDecided = null, origin = null, authority = null, untrusted = false, offerPlan = false, work = null, request = null, turnGen = live.gen, computerRoutes = null, typed = null, greetingId = null } = {}) {
|
|
2552
2555
|
const prompt = String(text || '').trim();
|
|
2553
2556
|
if (!prompt && !(Array.isArray(images) && images.length)) return refuse(live, 'EMPTY_PROMPT', 'No prompt provided', { packet: { type: 'error', message: 'No prompt provided' }, request });
|
|
2554
2557
|
// The scheduler's turn goes once a Stop, the session closing or a newer
|
|
@@ -2840,7 +2843,7 @@ export function createAssistantRuntime({
|
|
|
2840
2843
|
// Every turn starts unrouted; a continuation or a route_decided "here" turn starts open.
|
|
2841
2844
|
// Plan mode never routes: the brain explores read-only (the plan policy) and
|
|
2842
2845
|
// the approved plan is routed on the next turn.
|
|
2843
|
-
ensureGate(live)?.startTurn({ open: gateOpen || live.record.brain?.planMode === true, carry: gateCarry, taskId });
|
|
2846
|
+
ensureGate(live)?.startTurn({ open: gateOpen || live.record.brain?.planMode === true, carry: gateCarry, taskId, decided: gateDecided });
|
|
2844
2847
|
// What this turn runs on, as the router compares a re-routed task with it (routerSession `turn`). The
|
|
2845
2848
|
// brain process keeps it: a turn the CLI starts by itself afterwards (a task notification) runs on it too.
|
|
2846
2849
|
const previousRun = live.turnRun;
|
|
@@ -3042,8 +3045,10 @@ export function createAssistantRuntime({
|
|
|
3042
3045
|
const taskId = firstRun?.taskId || firstRun?.run?.turns?.find((turn) => turn.n === firstRun.turn)?.taskId || firstRun?.run?.taskId || live.record.taskId || null;
|
|
3043
3046
|
// The decided "here" routes this turn carries out (one of them may hold the owner's computer approval).
|
|
3044
3047
|
const computerRoutes = items.filter((item) => item.kind === 'route_decided' && item.route?.target?.kind === 'direct' && !(item.runIds || []).length).map((item) => String(item.route?.routeId || '')).filter(Boolean);
|
|
3048
|
+
// The routes the user decided for a worker: the turn stays unrouted, and its refusals name them (assistant-route-gate.js).
|
|
3049
|
+
const gateDecided = items.filter((item) => item.kind === 'route_decided' && item.route?.target?.kind === 'dispatch' && item.route?.routeId).map((item) => ({ routeId: String(item.route.routeId), target: item.route.target }));
|
|
3045
3050
|
let result = null;
|
|
3046
|
-
try { result = await runQuery(live, { text, system: true, taskId, gateOpen: decidedHere, computerRoutes }); }
|
|
3051
|
+
try { result = await runQuery(live, { text, system: true, taskId, gateOpen: decidedHere, gateDecided, computerRoutes }); }
|
|
3047
3052
|
catch (error) {
|
|
3048
3053
|
// A start that threw is a start that failed: its events stay open and the retry rules below apply (never a spin).
|
|
3049
3054
|
log('assistant:mailbox-error', `${live.record.id}: ${error?.message || error}`);
|
|
@@ -4298,8 +4303,10 @@ export function createAssistantRuntime({
|
|
|
4298
4303
|
* the browser policy (every session, plan mode and subagents included), then the route gate. → { decision:
|
|
4299
4304
|
* 'deny', reason } or null (no objection: the brain's approval mode decides). `call`: lib/antigravity/tool-call.js
|
|
4300
4305
|
* acpCall. Antigravity's own bookkeeping steps (task boundaries, notes to the user) are never routed.
|
|
4306
|
+
* `spilledOutput`: the brain found the call reads only tool outputs Antigravity spilled into its home
|
|
4307
|
+
* (lib/antigravity/home.js antigravitySpilledOutputRead): the route gate lets it through, every other check stays.
|
|
4301
4308
|
*/
|
|
4302
|
-
function antigravityGateCheck(live, call) {
|
|
4309
|
+
function antigravityGateCheck(live, call, { spilledOutput = false } = {}) {
|
|
4303
4310
|
const name = acpToolName(call);
|
|
4304
4311
|
const input = acpPolicyInput(call);
|
|
4305
4312
|
const planned = planGate(live, 'antigravity', name, input);
|
|
@@ -4316,6 +4323,8 @@ export function createAssistantRuntime({
|
|
|
4316
4323
|
const browserDenied = browserGate(live, name, input, { host: 'antigravity' });
|
|
4317
4324
|
if (browserDenied) return { decision: 'deny', reason: browserDenied.reason };
|
|
4318
4325
|
if (!live.gate || call.kind === 'think') return null;
|
|
4326
|
+
// The flag covers a plain read only (the brain sets it for nothing else; checked here too).
|
|
4327
|
+
if (spilledOutput === true && !call.mcp && (call.kind === 'read' || call.kind === 'search')) return null;
|
|
4319
4328
|
const decision = decide(live, name);
|
|
4320
4329
|
return decision.allow ? null : { decision: 'deny', reason: decision.reason };
|
|
4321
4330
|
}
|
|
@@ -4332,7 +4341,7 @@ export function createAssistantRuntime({
|
|
|
4332
4341
|
policyUrl: typeof ag.policyUrl === 'function' ? ag.policyUrl() : (ag.policyUrl || null),
|
|
4333
4342
|
connect: ag.connect || undefined,
|
|
4334
4343
|
userGemini: ag.userGemini || undefined,
|
|
4335
|
-
policyCheck: (call) => antigravityGateCheck(live, call),
|
|
4344
|
+
policyCheck: (call, meta) => antigravityGateCheck(live, call, meta),
|
|
4336
4345
|
// ACP counts tokens per session: what the session the record names had counted (a resume books only what follows).
|
|
4337
4346
|
sessionUsageBase: saved && saved.sessionId && saved.sessionId === live.record.providerSessionId ? saved.usage || null : null,
|
|
4338
4347
|
onAntigravitySession: (sessionId) => { if (sessionId && live.record.providerSessionId !== sessionId) { live.record.providerSessionId = sessionId; touch(live); } },
|
|
@@ -4469,6 +4478,8 @@ export function createAssistantRuntime({
|
|
|
4469
4478
|
PreToolUse: [{
|
|
4470
4479
|
hooks: [async (input) => {
|
|
4471
4480
|
if (!live.gate || input?.agent_id) return {};
|
|
4481
|
+
// A Read of a tool result Claude Code saved for this session (a long recall or agent_list): never routed.
|
|
4482
|
+
if (claudeSpilledResultRead(input)) return {};
|
|
4472
4483
|
const decision = decide(live, input?.tool_name);
|
|
4473
4484
|
if (decision.allow) return {};
|
|
4474
4485
|
return { hookSpecificOutput: { hookEventName: 'PreToolUse', permissionDecision: 'deny', permissionDecisionReason: decision.reason } };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// ═══════════════════════════════════════════
|
|
2
|
+
// SynaBun — a brain's read of a tool output its own CLI saved to a file
|
|
3
|
+
// ═══════════════════════════════════════════
|
|
4
|
+
//
|
|
5
|
+
// A CLI that cuts a long tool output short in the model's context saves the whole output to a file of its own and
|
|
6
|
+
// tells the model to read it there. The route gate lets that read through before a turn is routed: the file holds
|
|
7
|
+
// the output of a tool the model already ran, and an unrouted turn runs only the always-allowed ones (recall,
|
|
8
|
+
// agent_list, agent_read …). Exactly the CLI's own file counts, never a link to another one.
|
|
9
|
+
//
|
|
10
|
+
// Claude Code <projects>/<project>/<session>/tool-results/<name>.txt|json, beside <session>.jsonl, the
|
|
11
|
+
// transcript its hook input names (claudeSpilledResultRead, the Claude brain's PreToolUse gate hook)
|
|
12
|
+
// Antigravity <home>/antigravity-cli/brain/<conversation>/.system_generated/steps/<n>/output.txt
|
|
13
|
+
// (lib/antigravity/home.js antigravitySpilledOutputRead)
|
|
14
|
+
|
|
15
|
+
import { lstatSync, realpathSync } from 'node:fs';
|
|
16
|
+
import { basename, dirname, isAbsolute, join, relative, resolve } from 'node:path';
|
|
17
|
+
|
|
18
|
+
const CLAUDE_RESULT_NAME = '[A-Za-z0-9_][A-Za-z0-9_.-]{0,199}\\.(?:txt|json)';
|
|
19
|
+
const SESSION_ID_RE = /^[A-Za-z0-9_-]{1,128}$/;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Whether `file` lies under the CLI's own folder `anchor` at a path (relative to it) that `relRe` accepts, as a
|
|
23
|
+
* regular file with one name (no hard link) and with no symbolic link anywhere between `anchor` and it: its real
|
|
24
|
+
* path is that same relative path under the anchor's real path. Every folder level `relRe` names is checked that way,
|
|
25
|
+
* so put the anchor above them (a linked folder at the anchor itself would vouch for itself).
|
|
26
|
+
*/
|
|
27
|
+
export function ownSpilledFile(file, anchor, relRe) {
|
|
28
|
+
if (typeof file !== 'string' || !file || typeof anchor !== 'string' || !anchor) return false;
|
|
29
|
+
const full = resolve(file);
|
|
30
|
+
const rel = relative(resolve(anchor), full);
|
|
31
|
+
if (!relRe.test(rel)) return false;
|
|
32
|
+
try {
|
|
33
|
+
if (realpathSync(full) !== join(realpathSync(anchor), rel)) return false;
|
|
34
|
+
const stat = lstatSync(full);
|
|
35
|
+
return stat.isFile() && stat.nlink === 1;
|
|
36
|
+
} catch { return false; }
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* A Claude Code PreToolUse hook input ({ tool_name, tool_input, transcript_path, session_id }) that only reads one
|
|
41
|
+
* of the session's own saved tool results: Read with an absolute file_path in the tool-results folder of the
|
|
42
|
+
* transcript the hook names.
|
|
43
|
+
*/
|
|
44
|
+
export function claudeSpilledResultRead(input) {
|
|
45
|
+
if (String(input?.tool_name || '') !== 'Read') return false;
|
|
46
|
+
const file = input?.tool_input?.file_path;
|
|
47
|
+
const transcript = input?.transcript_path;
|
|
48
|
+
if (typeof file !== 'string' || !isAbsolute(file) || typeof transcript !== 'string' || !isAbsolute(transcript) || !transcript.endsWith('.jsonl')) return false;
|
|
49
|
+
const session = basename(transcript, '.jsonl');
|
|
50
|
+
if (!SESSION_ID_RE.test(session) || (input.session_id && String(input.session_id) !== session)) return false;
|
|
51
|
+
// Anchored at the transcript's folder: the session folder and tool-results must be real folders too.
|
|
52
|
+
return ownSpilledFile(file, dirname(transcript), new RegExp(`^${session}[\\\\/]tool-results[\\\\/]${CLAUDE_RESULT_NAME}$`));
|
|
53
|
+
}
|
|
@@ -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);
|