synabun 2.2.0 → 2.2.2
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 +45 -0
- package/README.md +1 -1
- package/hooks/claude-code/pre-websearch.mjs +4 -1
- package/hooks/claude-code/prompt-submit.mjs +7 -0
- package/lib/release-scan.mjs +23 -10
- package/lib/virustotal.mjs +143 -39
- package/mcp-server/dist/http.d.ts +19 -0
- package/mcp-server/dist/http.d.ts.map +1 -1
- package/mcp-server/dist/http.js +55 -13
- package/mcp-server/dist/http.js.map +1 -1
- package/mcp-server/dist/index.d.ts.map +1 -1
- package/mcp-server/dist/index.js +14 -9
- package/mcp-server/dist/index.js.map +1 -1
- package/mcp-server/dist/services/browser-route-flow.d.ts +118 -0
- package/mcp-server/dist/services/browser-route-flow.d.ts.map +1 -0
- package/mcp-server/dist/services/browser-route-flow.js +339 -0
- package/mcp-server/dist/services/browser-route-flow.js.map +1 -0
- package/mcp-server/dist/services/desktop-client.js +2 -2
- package/mcp-server/dist/services/desktop-client.js.map +1 -1
- package/mcp-server/dist/services/identity.d.ts +66 -3
- package/mcp-server/dist/services/identity.d.ts.map +1 -1
- package/mcp-server/dist/services/identity.js +61 -4
- package/mcp-server/dist/services/identity.js.map +1 -1
- package/mcp-server/dist/services/neural-interface.d.ts +112 -1
- package/mcp-server/dist/services/neural-interface.d.ts.map +1 -1
- package/mcp-server/dist/services/neural-interface.js +555 -61
- package/mcp-server/dist/services/neural-interface.js.map +1 -1
- package/mcp-server/dist/tools/bluesky.d.ts +20 -7
- package/mcp-server/dist/tools/bluesky.d.ts.map +1 -1
- package/mcp-server/dist/tools/bluesky.js +147 -45
- package/mcp-server/dist/tools/bluesky.js.map +1 -1
- package/mcp-server/dist/tools/browser-advanced.d.ts +11 -2
- package/mcp-server/dist/tools/browser-advanced.d.ts.map +1 -1
- package/mcp-server/dist/tools/browser-advanced.js +131 -18
- package/mcp-server/dist/tools/browser-advanced.js.map +1 -1
- package/mcp-server/dist/tools/browser-cheatsheet.d.ts +2 -0
- package/mcp-server/dist/tools/browser-cheatsheet.d.ts.map +1 -1
- package/mcp-server/dist/tools/browser-cheatsheet.js +3 -0
- package/mcp-server/dist/tools/browser-cheatsheet.js.map +1 -1
- package/mcp-server/dist/tools/morelogin.d.ts.map +1 -1
- package/mcp-server/dist/tools/morelogin.js +4 -2
- package/mcp-server/dist/tools/morelogin.js.map +1 -1
- package/mcp-server/dist/tools/skill-tools.d.ts +4 -4
- package/mcp-server/dist/tools/youtube/helpers.d.ts +1 -0
- package/mcp-server/dist/tools/youtube/helpers.d.ts.map +1 -1
- package/mcp-server/dist/tools/youtube/helpers.js +1 -1
- package/mcp-server/dist/tools/youtube/helpers.js.map +1 -1
- package/mcp-server/package-lock.json +2 -2
- package/mcp-server/package.json +1 -1
- package/mcp-server/src/http.ts +58 -12
- package/mcp-server/src/index.ts +15 -9
- package/mcp-server/src/services/browser-route-flow.ts +402 -0
- package/mcp-server/src/services/desktop-client.ts +2 -2
- package/mcp-server/src/services/identity.ts +80 -4
- package/mcp-server/src/services/neural-interface.ts +572 -70
- package/mcp-server/src/tools/bluesky.ts +164 -51
- package/mcp-server/src/tools/browser-advanced.ts +121 -17
- package/mcp-server/src/tools/browser-cheatsheet.ts +3 -0
- package/mcp-server/src/tools/morelogin.ts +4 -2
- package/mcp-server/src/tools/youtube/helpers.ts +2 -2
- package/neural-interface/i18n/en.json +27 -0
- package/neural-interface/i18n/pt-BR.json +27 -0
- package/neural-interface/lib/assistant-api.js +64 -23
- package/neural-interface/lib/assistant-brains/codex.js +6 -1
- package/neural-interface/lib/assistant-catalog.js +20 -2
- package/neural-interface/lib/assistant-dispatch.js +31 -2
- package/neural-interface/lib/assistant-persona.js +1 -0
- package/neural-interface/lib/assistant-runtime.js +15 -1
- package/neural-interface/lib/assistant-tools.js +10 -1
- package/neural-interface/lib/browser-automation-routes.js +84 -0
- package/neural-interface/lib/browser-execution.js +16 -3
- package/neural-interface/lib/browser-owner.js +48 -0
- package/neural-interface/lib/browser-session-close.js +84 -0
- package/neural-interface/lib/browser-start-handoff.js +202 -0
- package/neural-interface/lib/browser-tool-policy.js +21 -4
- package/neural-interface/lib/browser-wedge-retire.js +64 -0
- package/neural-interface/lib/claude-agent-bridge.js +36 -1
- package/neural-interface/lib/claude-background-hold.js +239 -0
- package/neural-interface/lib/exec-loop-command.js +8 -0
- package/neural-interface/lib/http-guards.js +11 -6
- package/neural-interface/lib/loop-logger.js +6 -1
- package/neural-interface/lib/mcp-external-servers.js +64 -13
- package/neural-interface/lib/native-loop-providers.js +122 -10
- package/neural-interface/lib/native-loop-runtime.js +112 -11
- package/neural-interface/lib/opencode-native-boundary.js +155 -21
- package/neural-interface/lib/owner-authority.js +113 -37
- package/neural-interface/lib/page-session.js +81 -23
- package/neural-interface/lib/peer-identity.js +311 -47
- package/neural-interface/lib/provider-panel-api-key-auth.js +7 -2
- package/neural-interface/lib/pty-host/core.js +36 -0
- package/neural-interface/lib/pty-host/protocol.js +2 -0
- package/neural-interface/lib/skills/api-v2.js +13 -2
- package/neural-interface/lib/skills/creation-api.js +3 -1
- package/neural-interface/lib/skills/evals-api.js +5 -1
- package/neural-interface/lib/social-write-pacing.js +151 -0
- package/neural-interface/lib/terminal-token-redaction.js +293 -0
- package/neural-interface/lib/terminal-tokens.js +359 -0
- package/neural-interface/lib/worker-mcp-channel.js +45 -10
- package/neural-interface/package-lock.json +2 -2
- package/neural-interface/package.json +1 -1
- package/neural-interface/public/shared/agy/agy-render.js +41 -1
- package/neural-interface/public/shared/agy/agy-styles.js +5 -0
- package/neural-interface/public/shared/api.js +1 -0
- package/neural-interface/public/shared/assistant/asst-api.js +14 -2
- package/neural-interface/public/shared/assistant/asst-computer.js +73 -4
- package/neural-interface/public/shared/assistant/asst-limit-wait.js +3 -1
- package/neural-interface/public/shared/assistant/asst-motion-gate.js +80 -0
- package/neural-interface/public/shared/assistant/asst-panel.js +8 -4
- package/neural-interface/public/shared/assistant/asst-render.js +72 -11
- package/neural-interface/public/shared/assistant/asst-scene-styles.js +55 -23
- package/neural-interface/public/shared/assistant/asst-scenes.js +225 -79
- package/neural-interface/public/shared/assistant/asst-sidepanel-styles.js +4 -4
- package/neural-interface/public/shared/assistant/asst-style-cache.js +44 -0
- package/neural-interface/public/shared/assistant/asst-styles.js +26 -5
- package/neural-interface/public/shared/cdx/cdx-render.js +73 -7
- package/neural-interface/public/shared/cdx/cdx-tabs.js +3 -3
- package/neural-interface/public/shared/cp/cp-agents.js +8 -0
- package/neural-interface/public/shared/cp/cp-permissions.js +18 -2
- package/neural-interface/public/shared/cp/cp-rehydrate.js +25 -1
- package/neural-interface/public/shared/cp/cp-tasks-model.js +33 -0
- package/neural-interface/public/shared/judgments-log-origins.js +29 -0
- package/neural-interface/public/shared/loading-teardown.js +34 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-automation-ownership.js +23 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-childpanel.js +6 -1
- package/neural-interface/public/shared/ocp-v2/ocp-v2-events.js +13 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-icons.js +3 -1
- package/neural-interface/public/shared/ocp-v2/ocp-v2-panel.js +5 -2
- package/neural-interface/public/shared/ocp-v2/ocp-v2-render.js +16 -86
- package/neural-interface/public/shared/ocp-v2/ocp-v2-send.js +6 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-styles.js +88 -72
- package/neural-interface/public/shared/ocp-v2/ocp-v2-ws.js +5 -2
- package/neural-interface/public/shared/owner-access.js +134 -0
- package/neural-interface/public/shared/owner-authority-view.js +92 -0
- package/neural-interface/public/shared/page-session.js +143 -14
- package/neural-interface/public/shared/poll-backoff.js +59 -0
- package/neural-interface/public/shared/settings/settings-data.js +6 -1
- package/neural-interface/public/shared/settings/settings-kit.js +11 -3
- package/neural-interface/public/shared/settings/settings-shell.js +7 -0
- package/neural-interface/public/shared/shown-children.js +72 -0
- package/neural-interface/public/shared/static-bg-state.js +22 -0
- package/neural-interface/public/shared/storage-retry.js +47 -0
- package/neural-interface/public/shared/storage.js +25 -4
- package/neural-interface/public/shared/styles.css +109 -8
- package/neural-interface/public/shared/synabun-mascot.js +27 -8
- package/neural-interface/public/shared/synabun-ticker.js +147 -12
- package/neural-interface/public/shared/synabun-tools.js +173 -0
- package/neural-interface/public/shared/tool-heartbeat.js +43 -0
- package/neural-interface/public/shared/tool-list-picker.js +3 -1
- package/neural-interface/public/shared/tool-list-view.js +23 -4
- package/neural-interface/public/shared/ui-automation-studio.js +8 -1
- package/neural-interface/public/shared/ui-claude-panel.js +238 -90
- package/neural-interface/public/shared/ui-judgments.js +37 -10
- package/neural-interface/public/shared/ui-loading.js +5 -4
- package/neural-interface/public/shared/ui-navbar.js +6 -0
- package/neural-interface/public/shared/ui-owner-access.js +191 -0
- package/neural-interface/public/shared/ui-owner-authority.js +162 -0
- package/neural-interface/public/shared/ui-sessions.js +45 -16
- package/neural-interface/public/shared/ui-settings.js +86 -15
- package/neural-interface/public/shared/ui-terminal.js +15 -7
- package/neural-interface/public/shared/ui-tutorial-preview.js +4 -0
- package/neural-interface/public/shared/ui-update.js +3 -0
- package/neural-interface/public/shared/ui-whiteboard.js +4 -0
- package/neural-interface/public/shared/window-keys.js +38 -0
- package/neural-interface/server.js +1240 -238
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a browser tool does when its tab goes away in the middle of the call.
|
|
3
|
+
*
|
|
4
|
+
* request() (services/neural-interface.ts) moves a step whose session or tab is gone to the run's replacement tab
|
|
5
|
+
* (`rerouted`), and the server resets a wedged tab to about:blank under the same id (`tabRecovered`) or drops it
|
|
6
|
+
* (`wedgedTabRetired`). For a single navigation that is the right answer. For a tool that read or prepared a page, every
|
|
7
|
+
* later step would run on a blank tab: an extractor reports "nothing found", a poll times out, a click finds no
|
|
8
|
+
* element, and the agent is told something about its page that is not true. The MoreLogin browser closing all its
|
|
9
|
+
* pages (about 40 times between 2026-10-21 and 2026-11-04) made that the common case.
|
|
10
|
+
*
|
|
11
|
+
* A tool call runs inside a route flow with a policy (routeFlowPolicy):
|
|
12
|
+
* - `follow`: steps may run on the replacement tab (browser_navigate); the answer says where it went.
|
|
13
|
+
* - `rerun`: a read that prepares its own page (gsc_*_report, youtube_channel list, ...): once the page is lost,
|
|
14
|
+
* nothing more runs on the blank tab; the whole call runs once more from the start on the replacement route.
|
|
15
|
+
* - `halt`: everything else (extractors, composer probes, clicks, writes): nothing more runs, and the answer says
|
|
16
|
+
* the tab was lost, what replaced it, and that steps before it may have taken effect. Never repeated by itself.
|
|
17
|
+
*
|
|
18
|
+
* Bluesky (bluesky.ts) recovers by itself and is not wrapped; browser_session and browser_batch have no flow.
|
|
19
|
+
*
|
|
20
|
+
* Every tool registered through withRouteFlows (flow or not) also gets runBrowserTool around it: a notice at the top
|
|
21
|
+
* of its answer for each replacement route that served it (noteRouteReplaced), and the check of its raw arguments
|
|
22
|
+
* (an owner-only field is refused, OWNER_ONLY_FIELDS; another unknown one is noted at the end).
|
|
23
|
+
*/
|
|
24
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
25
|
+
/** Thrown by request() inside a rerun / halt flow once the page is lost: no later step runs on a blank tab. */
|
|
26
|
+
export class BrowserRouteLost extends Error {
|
|
27
|
+
loss;
|
|
28
|
+
constructor(loss) {
|
|
29
|
+
super(`The browser tab of this call was lost at ${loss.step}`);
|
|
30
|
+
this.name = 'BrowserRouteLost';
|
|
31
|
+
this.loss = loss;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const flows = new AsyncLocalStorage();
|
|
35
|
+
export function currentRouteFlow() {
|
|
36
|
+
return flows.getStore();
|
|
37
|
+
}
|
|
38
|
+
// ── Policy ──────────────────────────────────────────────────────
|
|
39
|
+
/** Not wrapped: they recover by themselves (Bluesky), or do not depend on a page (session management, batches). */
|
|
40
|
+
const UNWRAPPED = new Set(['browser_session', 'browser_batch', 'browser_cheatsheet']);
|
|
41
|
+
const FOLLOW = new Set(['browser_navigate']);
|
|
42
|
+
/** Reads that open their own page first: running them again from the start is safe. */
|
|
43
|
+
const RERUN = new Set([
|
|
44
|
+
'gsc_navigate', 'gsc_inspect_url', 'gsc_inspect_view_crawled',
|
|
45
|
+
'gsc_performance_query', 'gsc_performance_export', 'gsc_performance_chart_screenshot',
|
|
46
|
+
'gsc_pages_report', 'gsc_videos_report', 'gsc_cwv_report', 'gsc_https_report', 'gsc_enhancements',
|
|
47
|
+
'gsc_links_report', 'gsc_links_export', 'gsc_crawl_stats', 'gsc_shopping',
|
|
48
|
+
'youtube_navigate',
|
|
49
|
+
]);
|
|
50
|
+
/** Tools with an action: a rerun only for the read actions (an absent action is the tool's default, a read). */
|
|
51
|
+
const READ_ACTIONS = {
|
|
52
|
+
gsc_property: new Set(['list', 'current']),
|
|
53
|
+
gsc_sitemap: new Set(['list', 'view_errors']),
|
|
54
|
+
gsc_removals: new Set(['list_temporary', 'list_outdated', 'list_safesearch']),
|
|
55
|
+
gsc_security_issues: new Set([undefined, 'list']),
|
|
56
|
+
gsc_manual_actions: new Set([undefined, 'list']),
|
|
57
|
+
gsc_settings: new Set([undefined, 'get']),
|
|
58
|
+
gsc_users: new Set(['list']),
|
|
59
|
+
gsc_associations: new Set(['list']),
|
|
60
|
+
gsc_disavow: new Set(['download']),
|
|
61
|
+
youtube_playlist: new Set(['list']),
|
|
62
|
+
youtube_channel: new Set(['info', 'list']),
|
|
63
|
+
};
|
|
64
|
+
/** The flow a tool call runs in; null = not wrapped. */
|
|
65
|
+
export function routeFlowPolicy(tool, args) {
|
|
66
|
+
if (UNWRAPPED.has(tool))
|
|
67
|
+
return null;
|
|
68
|
+
if (FOLLOW.has(tool))
|
|
69
|
+
return 'follow';
|
|
70
|
+
if (RERUN.has(tool))
|
|
71
|
+
return 'rerun';
|
|
72
|
+
const reads = READ_ACTIONS[tool];
|
|
73
|
+
if (reads) {
|
|
74
|
+
const action = args && typeof args === 'object' ? args.action : undefined;
|
|
75
|
+
return reads.has(typeof action === 'string' ? action : undefined) ? 'rerun' : 'halt';
|
|
76
|
+
}
|
|
77
|
+
return 'halt';
|
|
78
|
+
}
|
|
79
|
+
const describeRoute = (route) => `session ${route.sessionId}${route.tabId ? `, tab ${route.tabId}` : ''}`;
|
|
80
|
+
function lossCause(loss) {
|
|
81
|
+
if (loss.reason === 'reset')
|
|
82
|
+
return 'stopped answering, and SynaBun reset it to a blank page';
|
|
83
|
+
if (loss.reason === 'retired')
|
|
84
|
+
return 'stopped answering, and SynaBun closed it';
|
|
85
|
+
return 'was closed (the browser closed its pages, or another automation closed it)';
|
|
86
|
+
}
|
|
87
|
+
/** What the agent does next: the tab that replaced it, the start still running, or a create of its own. */
|
|
88
|
+
function lossNext(loss) {
|
|
89
|
+
// A replacement is open already: a create now would only replace it again (and close it), so the agent is told
|
|
90
|
+
// plainly not to (browserSessionLossRule says the same).
|
|
91
|
+
if (loss.to)
|
|
92
|
+
return `A new tab replaced it: ${describeRoute(loss.to)}. Your next browser calls use it${loss.to.tabId ? ` (keep using tabId ${loss.to.tabId})` : ''}; do not call browser_session create.`;
|
|
93
|
+
if (loss.recovery?.starting)
|
|
94
|
+
return `SynaBun is opening a new tab for it, and the browser is still starting: call the tool again in a moment (the tab is kept for you). ${loss.recovery.error}`.trim();
|
|
95
|
+
if (loss.recovery)
|
|
96
|
+
return `SynaBun could not open a replacement tab (${loss.recovery.error}). Call browser_session with action "create" and continue in the tab it returns; only if that fails too, stop and report it. Never switch to another browser or tool.`;
|
|
97
|
+
return 'The next browser call gets a new tab. If it answers that the session or tab is gone, call browser_session with action "create" and continue in the tab it returns; only if that fails too, stop and report it.';
|
|
98
|
+
}
|
|
99
|
+
/** The answer of a call whose page was lost and that is not repeated. */
|
|
100
|
+
export function routeLossMessage(tool, loss) {
|
|
101
|
+
const lines = [
|
|
102
|
+
`${tool} stopped: the browser tab it was working in (${describeRoute(loss.from)}) ${lossCause(loss)} during the call, at the ${loss.step} step. Nothing ran on a blank page and nothing was read from it.`,
|
|
103
|
+
lossNext(loss),
|
|
104
|
+
'Steps before that point may have taken effect: look at the page before you repeat a change. Then open the page again (browser_navigate or the tool\'s own navigation) and call the tool again.',
|
|
105
|
+
];
|
|
106
|
+
return lines.join('\n');
|
|
107
|
+
}
|
|
108
|
+
function withNote(result, note) {
|
|
109
|
+
const r = result;
|
|
110
|
+
if (!r || !Array.isArray(r.content))
|
|
111
|
+
return result;
|
|
112
|
+
return { ...r, content: [...r.content, { type: 'text', text: note }] };
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* The arguments of a rerun: a session or tab the call named that is now gone is left out, so the call resolves its
|
|
116
|
+
* route again (a pinned run gets its recovered tab; a pin would override a tab named here anyway).
|
|
117
|
+
*/
|
|
118
|
+
function rerunArgs(args, loss) {
|
|
119
|
+
if (!args || typeof args !== 'object')
|
|
120
|
+
return args;
|
|
121
|
+
const a = { ...args };
|
|
122
|
+
const namedLost = a.sessionId === loss.from.sessionId || (!!loss.from.tabId && a.tabId === loss.from.tabId);
|
|
123
|
+
if (!namedLost)
|
|
124
|
+
return args;
|
|
125
|
+
delete a.sessionId;
|
|
126
|
+
delete a.tabId;
|
|
127
|
+
return a;
|
|
128
|
+
}
|
|
129
|
+
async function runOnce(tool, policy, args, handler, extra) {
|
|
130
|
+
const flow = { tool, policy, loss: null, rerouted: null };
|
|
131
|
+
try {
|
|
132
|
+
const value = await flows.run(flow, () => handler(args, extra));
|
|
133
|
+
return { flow, value, thrown: null };
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
if (error instanceof BrowserRouteLost || flow.loss)
|
|
137
|
+
return { flow, value: undefined, thrown: error };
|
|
138
|
+
throw error;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Run one tool call in its route flow. A page lost during a `rerun` call runs it once more (never twice); during a
|
|
143
|
+
* `halt` call it answers routeLossMessage instead of whatever the tool made of the blank tab.
|
|
144
|
+
*/
|
|
145
|
+
export async function runInRouteFlow(tool, args, handler, extra) {
|
|
146
|
+
const policy = routeFlowPolicy(tool, args);
|
|
147
|
+
if (!policy)
|
|
148
|
+
return handler(args, extra);
|
|
149
|
+
const first = await runOnce(tool, policy, args, handler, extra);
|
|
150
|
+
if (!first.flow.loss) {
|
|
151
|
+
// A step request() moved to the replacement route: the call ran there (the notice at the top of the answer says
|
|
152
|
+
// so, withRouteNotices; resolution raises it too, and the same replacement is announced once).
|
|
153
|
+
if (first.flow.rerouted)
|
|
154
|
+
noteRouteReplaced({ kind: 'lost', from: null, to: first.flow.rerouted });
|
|
155
|
+
return first.value;
|
|
156
|
+
}
|
|
157
|
+
const loss = first.flow.loss;
|
|
158
|
+
if (policy !== 'rerun')
|
|
159
|
+
return { content: [{ type: 'text', text: routeLossMessage(tool, loss) }], isError: true };
|
|
160
|
+
// Once more from the start, on the replacement route; a second loss is answered, not repeated again.
|
|
161
|
+
const second = await runOnce(tool, 'halt', rerunArgs(args, loss), handler, extra);
|
|
162
|
+
if (second.flow.loss)
|
|
163
|
+
return { content: [{ type: 'text', text: routeLossMessage(tool, second.flow.loss) }], isError: true };
|
|
164
|
+
return withNote(second.value, `(The browser tab was lost during the first attempt (${describeRoute(loss.from)}, at the ${loss.step} step); the call ran again from the start${loss.to ? ` in ${describeRoute(loss.to)}` : ''}.)`);
|
|
165
|
+
}
|
|
166
|
+
const noticeScopes = new AsyncLocalStorage();
|
|
167
|
+
const sameRoute = (a, b) => !!a && !!b && a.sessionId === b.sessionId && (a.tabId || null) === (b.tabId || null);
|
|
168
|
+
/**
|
|
169
|
+
* Note that this tool call is served by a replacement route. Said once at the top of the call's answer (one notice
|
|
170
|
+
* per replacement: a second note of the same route keeps the first's lost route). Returns false outside a tool call
|
|
171
|
+
* (nobody to tell: Bluesky recovers and reports by itself).
|
|
172
|
+
*/
|
|
173
|
+
export function noteRouteReplaced(notice) {
|
|
174
|
+
const scope = noticeScopes.getStore();
|
|
175
|
+
if (!scope)
|
|
176
|
+
return false;
|
|
177
|
+
const known = scope.notices.find(n => sameRoute(n.to, notice.to));
|
|
178
|
+
if (known) {
|
|
179
|
+
if (!known.from && notice.from)
|
|
180
|
+
known.from = notice.from;
|
|
181
|
+
if (notice.kind === 'lost')
|
|
182
|
+
known.kind = 'lost';
|
|
183
|
+
return true;
|
|
184
|
+
}
|
|
185
|
+
scope.notices.push({ ...notice, from: notice.from ? { ...notice.from } : null, to: { ...notice.to } });
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
188
|
+
/** The notice's text: the first thing the agent reads in the answer. */
|
|
189
|
+
export function routeNoticeText(notice) {
|
|
190
|
+
const { to, from } = notice;
|
|
191
|
+
const where = to.tabId ? `a replacement tab ${to.tabId} is open in session ${to.sessionId}` : `a replacement is open in session ${to.sessionId}`;
|
|
192
|
+
const keep = to.tabId ? `Keep using tabId ${to.tabId}${from && from.sessionId !== to.sessionId ? ` (sessionId ${to.sessionId})` : ''}` : `Keep using sessionId ${to.sessionId}`;
|
|
193
|
+
if (notice.kind === 'moved') {
|
|
194
|
+
const was = from?.tabId ? ` (not tab ${from.tabId})` : '';
|
|
195
|
+
return `Your browser now works in tab ${to.tabId || '(the session\'s own)'} of session ${to.sessionId}${was}: SynaBun moved your route there earlier, and this call ran there. ${keep}. Do not call browser_session create.`;
|
|
196
|
+
}
|
|
197
|
+
const lost = from?.tabId ? `Your tab ${from.tabId} was lost` : from ? `Your browser session ${from.sessionId} was lost` : 'Your browser tab was lost';
|
|
198
|
+
return `${lost}; ${where} and this call ran there. ${keep}. Do not call browser_session create.`;
|
|
199
|
+
}
|
|
200
|
+
function prependNotices(result, notices) {
|
|
201
|
+
const r = result;
|
|
202
|
+
if (!notices.length || !r || !Array.isArray(r.content))
|
|
203
|
+
return result;
|
|
204
|
+
// The notice is its own content block, but some clients (Codex) join text blocks with no separator, so it ends with
|
|
205
|
+
// a blank line: without it the answer read "…Do not call browser_session create.Page: about:blank".
|
|
206
|
+
const text = `${notices.map(routeNoticeText).join('\n')}\n\n`;
|
|
207
|
+
return { ...r, content: [{ type: 'text', text }, ...r.content] };
|
|
208
|
+
}
|
|
209
|
+
// ── Fields a browser tool does not take ─────────────────────────
|
|
210
|
+
/**
|
|
211
|
+
* Which browser or profile SynaBun drives is the owner's choice (Settings → Browser), never an automation's. A tool
|
|
212
|
+
* argument naming one is refused, not silently dropped: before 2026-11-05 zod stripped unknown keys, so
|
|
213
|
+
* `browser_navigate({ profile: "other" })` ran in the default browser and the model believed it had switched profile.
|
|
214
|
+
* Mirrors OWNER_ONLY_BROWSER_FIELDS in neural-interface/lib/browser-automation-routes.js (the server refuses the same
|
|
215
|
+
* names on a session create; neural-interface/tests/browser-automation-routes.test.mjs keeps the two lists equal).
|
|
216
|
+
*/
|
|
217
|
+
export const OWNER_ONLY_FIELDS = Object.freeze([
|
|
218
|
+
'connectMode', 'moreloginEnvId', 'attachSeed', 'openTabsInBackground',
|
|
219
|
+
'config', 'profile', 'profileDir', 'profilePath', 'userDataDir', 'executablePath',
|
|
220
|
+
'moreloginProfile', 'moreloginEnv', 'moreloginEnvironment', 'cdpUrl', 'wsEndpoint',
|
|
221
|
+
]);
|
|
222
|
+
const OWNER_ONLY = new Set(OWNER_ONLY_FIELDS);
|
|
223
|
+
/** Unknown keys of one call, attached by the validation step and read (and removed) by the tool's wrapper. */
|
|
224
|
+
const UNKNOWN_FIELDS = Symbol('synabun.unknownFields');
|
|
225
|
+
export class OwnerOnlyFieldsError extends Error {
|
|
226
|
+
code = 'OWNER_ONLY_FIELDS';
|
|
227
|
+
fields;
|
|
228
|
+
constructor(tool, fields) {
|
|
229
|
+
const names = fields.map(f => `"${f}"`).join(', ');
|
|
230
|
+
super(`OWNER_ONLY_FIELDS: ${tool} does not take ${names}. Which browser, MoreLogin profile or browser settings SynaBun uses is the owner's choice (Settings → Browser); browser tools always use the default browser. Leave ${fields.length === 1 ? 'it' : 'them'} out and call ${tool} again. Nothing ran.`);
|
|
231
|
+
this.name = 'OwnerOnlyFieldsError';
|
|
232
|
+
this.fields = fields;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* The keys of a call's raw arguments: owner-only ones refused (OwnerOnlyFieldsError), other unknown ones returned
|
|
237
|
+
* (the call runs and its answer ends with a note). `known`: the tool's parameters.
|
|
238
|
+
*/
|
|
239
|
+
export function checkToolFields(tool, raw, known) {
|
|
240
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw))
|
|
241
|
+
return [];
|
|
242
|
+
const unknown = Object.keys(raw).filter(k => !known.has(k));
|
|
243
|
+
const owner = unknown.filter(k => OWNER_ONLY.has(k));
|
|
244
|
+
if (owner.length)
|
|
245
|
+
throw new OwnerOnlyFieldsError(tool, owner);
|
|
246
|
+
return unknown;
|
|
247
|
+
}
|
|
248
|
+
export function unknownFieldsNote(tool, fields) {
|
|
249
|
+
const names = fields.map(f => `"${f}"`).join(', ');
|
|
250
|
+
return `(Note: ${tool} has no parameter ${names}; ${fields.length === 1 ? 'it was' : 'they were'} ignored.)`;
|
|
251
|
+
}
|
|
252
|
+
/** The parameter names of a raw zod shape (`{ url: z.string(), ... }`), or null for anything else. */
|
|
253
|
+
function shapeKeys(value) {
|
|
254
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
255
|
+
return null;
|
|
256
|
+
const v = value;
|
|
257
|
+
if ('_def' in v || '_zod' in v)
|
|
258
|
+
return null; // a schema, not a raw shape
|
|
259
|
+
const values = Object.values(v);
|
|
260
|
+
if (values.length && !values.every(x => !!x && typeof x === 'object' && ('_def' in x || '_zod' in x)))
|
|
261
|
+
return null;
|
|
262
|
+
return new Set(Object.keys(v));
|
|
263
|
+
}
|
|
264
|
+
/** Per server: the tools registered through withRouteFlows and their parameter names. */
|
|
265
|
+
const checkedTools = new WeakMap();
|
|
266
|
+
/**
|
|
267
|
+
* The SDK validates a call's arguments before the handler sees them, and its zod objects drop unknown keys: the
|
|
268
|
+
* handler can never tell. One wrapper per server, around its validation, reads the raw arguments of the browser
|
|
269
|
+
* tools first (MCP SDK 1.29 McpServer.validateToolInput; tests/browser-tool-fields.test.ts runs it through a real
|
|
270
|
+
* client, so an SDK that renames it fails there, not in production).
|
|
271
|
+
*/
|
|
272
|
+
function guardValidation(server) {
|
|
273
|
+
let tools = checkedTools.get(server);
|
|
274
|
+
if (tools)
|
|
275
|
+
return tools;
|
|
276
|
+
tools = new Map();
|
|
277
|
+
checkedTools.set(server, tools);
|
|
278
|
+
const s = server;
|
|
279
|
+
const original = s.validateToolInput;
|
|
280
|
+
if (typeof original !== 'function')
|
|
281
|
+
return tools;
|
|
282
|
+
const known = tools;
|
|
283
|
+
s.validateToolInput = async function (tool, args, toolName) {
|
|
284
|
+
const params = known.get(toolName);
|
|
285
|
+
const unknown = params ? checkToolFields(toolName, args, params) : [];
|
|
286
|
+
const data = await original.call(this, tool, args, toolName);
|
|
287
|
+
if (unknown.length && data && typeof data === 'object') {
|
|
288
|
+
Object.defineProperty(data, UNKNOWN_FIELDS, { value: unknown, enumerable: false, configurable: true });
|
|
289
|
+
}
|
|
290
|
+
return data;
|
|
291
|
+
};
|
|
292
|
+
return tools;
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* One browser tool call: in its route flow (a tool runRouteFlow wraps), with the notices of every replacement that
|
|
296
|
+
* served it at the top of its answer, and a note at the end for parameters it does not have.
|
|
297
|
+
*/
|
|
298
|
+
export async function runBrowserTool(tool, args, handler, extra) {
|
|
299
|
+
const unknown = args && typeof args === 'object' ? args[UNKNOWN_FIELDS] : undefined;
|
|
300
|
+
const scope = { notices: [] };
|
|
301
|
+
const value = await noticeScopes.run(scope, async () => {
|
|
302
|
+
// browser_session, browser_batch and browser_cheatsheet have no route flow (runInRouteFlow calls them as they are).
|
|
303
|
+
return runInRouteFlow(tool, args, handler, extra);
|
|
304
|
+
});
|
|
305
|
+
// A loss message that names its replacement already says it: the notice for that route would say it twice.
|
|
306
|
+
const text = (value?.content || []).map(c => (typeof c.text === 'string' ? c.text : '')).join('\n');
|
|
307
|
+
const notices = scope.notices.filter(n => !(n.to.tabId && text.includes(`A new tab replaced it: ${describeRoute(n.to)}`)));
|
|
308
|
+
const noted = prependNotices(value, notices);
|
|
309
|
+
return unknown?.length ? withNote(noted, unknownFieldsNote(tool, unknown)) : noted;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* The server a browser group registers its tools on: every handler runs through runBrowserTool (its route flow when
|
|
313
|
+
* the tool has one, the replacement notices, the field check). Everything else about the server is the real one.
|
|
314
|
+
*/
|
|
315
|
+
export function withRouteFlows(server) {
|
|
316
|
+
const fields = guardValidation(server);
|
|
317
|
+
return new Proxy(server, {
|
|
318
|
+
get(target, prop, receiver) {
|
|
319
|
+
if (prop === 'tool') {
|
|
320
|
+
const tool = target.tool;
|
|
321
|
+
return (...a) => {
|
|
322
|
+
const name = a[0];
|
|
323
|
+
const last = a.length - 1;
|
|
324
|
+
if (typeof name === 'string' && typeof a[last] === 'function') {
|
|
325
|
+
const handler = a[last];
|
|
326
|
+
a[last] = (args, extra) => runBrowserTool(name, args, handler, extra);
|
|
327
|
+
const keys = a.slice(1, last).map(shapeKeys).find((k) => !!k);
|
|
328
|
+
if (keys)
|
|
329
|
+
fields.set(name, keys);
|
|
330
|
+
}
|
|
331
|
+
return tool.apply(target, a);
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
const value = Reflect.get(target, prop, receiver);
|
|
335
|
+
return typeof value === 'function' ? value.bind(target) : value;
|
|
336
|
+
},
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
//# sourceMappingURL=browser-route-flow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-route-flow.js","sourceRoot":"","sources":["../../src/services/browser-route-flow.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AA2BrD,+GAA+G;AAC/G,MAAM,OA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AAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;QAClE,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* throws — transport failures come back as { ok:false, code } data.
|
|
8
8
|
*/
|
|
9
9
|
import { randomUUID } from 'node:crypto';
|
|
10
|
-
import { callerDesktopGrant, callerRole, getIdentity,
|
|
10
|
+
import { callerDesktopGrant, callerRole, getIdentity, terminalHeaders } from './identity.js';
|
|
11
11
|
const BASE_URL = process.env.NEURAL_INTERFACE_URL
|
|
12
12
|
|| `http://localhost:${process.env.NEURAL_PORT || '3344'}`;
|
|
13
13
|
const ACTION_TIMEOUT = 45_000;
|
|
@@ -29,7 +29,7 @@ async function post(path, body, timeoutMs = ACTION_TIMEOUT, signal) {
|
|
|
29
29
|
try {
|
|
30
30
|
const headers = {
|
|
31
31
|
'Content-Type': 'application/json',
|
|
32
|
-
|
|
32
|
+
...terminalHeaders(getIdentity()),
|
|
33
33
|
'X-Synabun-Desktop-Grant': grant,
|
|
34
34
|
'X-Synabun-Request-Id': randomUUID(),
|
|
35
35
|
'X-Synabun-Deadline': String(Date.now() + timeoutMs),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"desktop-client.js","sourceRoot":"","sources":["../../src/services/desktop-client.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"desktop-client.js","sourceRoot":"","sources":["../../src/services/desktop-client.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAE7F,MAAM,QAAQ,GAAG,OAAO,CAAC,GA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E,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,sCAAsC,SAAS,yCAAyC,EAAE,CAAC;QAC5L,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,iBAAiB,EAAE,KAAK,EAAE,iCAAiC,GAAG,EAAE,EAAE,CAAC;IAC/F,CAAC;YAAS,CAAC;QACT,YAAY,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC;AACH,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,IAA6B,EAAE,SAAkB,EAAE,MAAoB;IAChG,OAAO,IAAI,CAAC,kBAAkB,EAAE,IAAI,EAAE,SAAS,IAAI,cAAc,EAAE,MAAM,CAAC,CAAC;AAC7E,CAAC;AACD,MAAM,UAAU,WAAW,CAAC,IAA6B,EAAE,MAAoB;IAC7E,OAAO,IAAI,CAAC,mBAAmB,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,CAAC,CAAC;AACjE,CAAC;AACD,MAAM,UAAU,SAAS,CAAC,IAA6B,EAAE,UAAwD,EAAE;IACjH,OAAO,IAAI,CAAC,iBAAiB,EAAE,IAAI,EAAE,OAAO,CAAC,SAAS,IAAI,cAAc,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;AAC5F,CAAC;AACD,MAAM,UAAU,aAAa,CAAC,IAA6B,EAAE,MAAoB;IAC/E,OAAO,IAAI,CAAC,2BAA2B,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AACjE,CAAC"}
|
|
@@ -9,7 +9,9 @@
|
|
|
9
9
|
* own identity object, derived per-request from:
|
|
10
10
|
*
|
|
11
11
|
* 1. X-Synabun-Terminal / X-Synabun-Browser-Session / X-Synabun-Browser-Tab
|
|
12
|
-
* headers (loops, scheduled loops, sidepanel — injected at launch
|
|
12
|
+
* headers (loops, scheduled loops, sidepanel — injected at launch; a run's
|
|
13
|
+
* pin counts only with its X-Synabun-Terminal-Token where the host checks
|
|
14
|
+
* it, http.ts terminalAuth), or
|
|
13
15
|
* 2. the stateful Mcp-Session-Id (plain CLI windows — unique per Claude
|
|
14
16
|
* Code process with zero client configuration), or
|
|
15
17
|
* 3. a per-process stdio singleton whose pins read live process.env —
|
|
@@ -35,6 +37,36 @@ export interface IdentityState {
|
|
|
35
37
|
ancestorPinnedTab: string | null;
|
|
36
38
|
ancestorPinnedTerminal: string | null;
|
|
37
39
|
ancestorAttempts: number;
|
|
40
|
+
/** A route of this caller's that went away (its own close, a session that died, a step that found it gone) and
|
|
41
|
+
* that no replacement was announced for yet: the next replacement's notice names it (neural-interface.ts). */
|
|
42
|
+
lostRoute: {
|
|
43
|
+
sessionId: string;
|
|
44
|
+
tabId: string | null;
|
|
45
|
+
} | null;
|
|
46
|
+
/** Lost tab id → the route that replaced it: a later call that still names the old tab goes to its replacement. */
|
|
47
|
+
replacedTabs: Map<string, {
|
|
48
|
+
sessionId: string;
|
|
49
|
+
tabId: string | null;
|
|
50
|
+
}>;
|
|
51
|
+
/** The last route this process served a browser call on: a server-recorded route that differs from it is a move
|
|
52
|
+
* this caller is told about (neural-interface.ts resolveSessionUncached), one it never served is not. */
|
|
53
|
+
servedRoute: {
|
|
54
|
+
sessionId: string;
|
|
55
|
+
tabId: string | null;
|
|
56
|
+
} | null;
|
|
57
|
+
/** The run's route moved in this process from a tab it knew (a recovery, its own create, a session of its own named
|
|
58
|
+
* by hand, the server-recorded route of another process): browser_session status says Replaced while it is current.
|
|
59
|
+
* Never set by adopting the route the run was launched with or the first route it learns. */
|
|
60
|
+
routeMoved: {
|
|
61
|
+
from: {
|
|
62
|
+
sessionId: string;
|
|
63
|
+
tabId: string | null;
|
|
64
|
+
};
|
|
65
|
+
to: {
|
|
66
|
+
sessionId: string;
|
|
67
|
+
tabId: string | null;
|
|
68
|
+
};
|
|
69
|
+
} | null;
|
|
38
70
|
}
|
|
39
71
|
/** Caller roles that unlock role-gated tool groups (see profiles.ts
|
|
40
72
|
* ROLE_GATED_GROUPS). Only the SynaBun assistant runtime exists today. */
|
|
@@ -72,8 +104,10 @@ export declare function peekStdioIdentity(): CallerIdentity | null;
|
|
|
72
104
|
export declare function isHttpMode(): boolean;
|
|
73
105
|
export declare function runWithIdentity<T>(identity: CallerIdentity, fn: () => T): T;
|
|
74
106
|
export declare function getIdentity(): CallerIdentity;
|
|
75
|
-
/** Pins must look like the ids we mint (hex/uuid-ish
|
|
76
|
-
* and unexpanded template junk
|
|
107
|
+
/** Pins must look like the ids we mint (hex/uuid-ish, and `agent:<uuid>` for an
|
|
108
|
+
* automation-window agent). Rejects empty strings and unexpanded template junk
|
|
109
|
+
* like "${SYNABUN_TERMINAL_SESSION}". The Neural Interface accepts the same
|
|
110
|
+
* characters (neural-interface/lib/browser-owner.js browserOwnerId). */
|
|
77
111
|
export declare function sanitizePin(v: string | undefined | null): string | null;
|
|
78
112
|
/** Only known roles are accepted; anything else (empty, template junk,
|
|
79
113
|
* invented roles) is treated as "no role" so gating fails closed. */
|
|
@@ -97,6 +131,35 @@ export declare function runWithBrainCredential<T>(credential: string | null, fn:
|
|
|
97
131
|
* env for an HTTP caller.
|
|
98
132
|
*/
|
|
99
133
|
export declare function callerBrainCredential(): string | null;
|
|
134
|
+
/** Terminal tokens look exactly like the ones the Neural Interface mints (neural-interface/lib/terminal-tokens.js). */
|
|
135
|
+
export declare function sanitizeTerminalToken(v: string | undefined | null): string | null;
|
|
136
|
+
/**
|
|
137
|
+
* What proves a pin to the Neural Interface: a terminal token, or an Assistant brain's launch credential, which the
|
|
138
|
+
* Neural Interface binds to the brain's pin (neural-interface/lib/terminal-tokens.js bind: no second secret).
|
|
139
|
+
*/
|
|
140
|
+
export declare function sanitizeTerminalProof(v: string | undefined | null): string | null;
|
|
141
|
+
/** The token a request arrived with, and the X-Synabun-Terminal pin it arrived with. */
|
|
142
|
+
export interface TerminalTokenGrant {
|
|
143
|
+
terminal: string;
|
|
144
|
+
token: string;
|
|
145
|
+
}
|
|
146
|
+
/** Run `fn` with this request's terminal token (http.ts, around every transport.handleRequest). */
|
|
147
|
+
export declare function runWithTerminalToken<T>(grant: TerminalTokenGrant | null, fn: () => T): T;
|
|
148
|
+
/**
|
|
149
|
+
* The token that proves `terminalId` is the caller's own run, sent with X-Synabun-Terminal on its requests to the
|
|
150
|
+
* Neural Interface (whose browser routes take a run's pin only with it): over HTTP the one this request arrived with,
|
|
151
|
+
* and only for the pin it arrived with; for a stdio child the SYNABUN_TERMINAL_TOKEN of its launch environment, and
|
|
152
|
+
* only for its SYNABUN_TERMINAL_SESSION. An Assistant brain's MCP has no terminal token: its launch credential is the
|
|
153
|
+
* proof of its pin (SYNABUN_BRAIN_TOKEN for a stdio child, X-Synabun-Brain-Token over HTTP: http.ts
|
|
154
|
+
* requestTerminalToken). Never the host's own environment for an HTTP caller, and never for another id (an ancestor's
|
|
155
|
+
* terminal, the process's own client id).
|
|
156
|
+
*/
|
|
157
|
+
export declare function callerTerminalToken(terminalId: string | null | undefined): string | null;
|
|
158
|
+
/**
|
|
159
|
+
* The identity headers of one request to the Neural Interface: X-Synabun-Terminal (terminalIdFor) and, when the caller
|
|
160
|
+
* holds it, that run's X-Synabun-Terminal-Token.
|
|
161
|
+
*/
|
|
162
|
+
export declare function terminalHeaders(id?: CallerIdentity): Record<string, string>;
|
|
100
163
|
/**
|
|
101
164
|
* Role of the current caller: the ALS identity's role over HTTP (derived from
|
|
102
165
|
* X-Synabun-Role on every request), or SYNABUN_ROLE for stdio children —
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../../src/services/identity.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../../src/services/identity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAKH,MAAM,WAAW,MAAM;IACrB,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,YAAY,EAAE,MAAM,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MAAM,CAAC,CAAC;IAAC,IAAI,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GACzH,cAAc,CA8BhB;AAED;mDACmD;AACnD,wBAAgB,aAAa,CAAC,EAAE,EAAE,cAAc,GAAG,MAAM,CASxD;AAED;;;yDAGyD;AACzD,wBAAgB,aAAa,CAAC,EAAE,EAAE,cAAc,GAAG,MAAM,CAExD;AAKD,KAAK,WAAW,GAAG,CAAC,EAAE,EAAE,cAAc,KAAK,IAAI,CAAC;AAEhD,wBAAgB,cAAc,CAAC,EAAE,EAAE,WAAW,GAAG,IAAI,CAAsB;AAE3E;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAOjD;AAED,wBAAgB,aAAa,IAAI,MAAM,CAA4B;AAKnE,wBAAgB,oBAAoB,IAAI,IAAI,CAiB3C"}
|
|
@@ -9,7 +9,9 @@
|
|
|
9
9
|
* own identity object, derived per-request from:
|
|
10
10
|
*
|
|
11
11
|
* 1. X-Synabun-Terminal / X-Synabun-Browser-Session / X-Synabun-Browser-Tab
|
|
12
|
-
* headers (loops, scheduled loops, sidepanel — injected at launch
|
|
12
|
+
* headers (loops, scheduled loops, sidepanel — injected at launch; a run's
|
|
13
|
+
* pin counts only with its X-Synabun-Terminal-Token where the host checks
|
|
14
|
+
* it, http.ts terminalAuth), or
|
|
13
15
|
* 2. the stateful Mcp-Session-Id (plain CLI windows — unique per Claude
|
|
14
16
|
* Code process with zero client configuration), or
|
|
15
17
|
* 3. a per-process stdio singleton whose pins read live process.env —
|
|
@@ -32,6 +34,10 @@ const emptyState = () => ({
|
|
|
32
34
|
ancestorPinnedTab: null,
|
|
33
35
|
ancestorPinnedTerminal: null,
|
|
34
36
|
ancestorAttempts: 0,
|
|
37
|
+
lostRoute: null,
|
|
38
|
+
replacedTabs: new Map(),
|
|
39
|
+
servedRoute: null,
|
|
40
|
+
routeMoved: null,
|
|
35
41
|
});
|
|
36
42
|
const als = new AsyncLocalStorage();
|
|
37
43
|
export function callerMemoryContext() {
|
|
@@ -93,12 +99,14 @@ export function getIdentity() {
|
|
|
93
99
|
}
|
|
94
100
|
return stdioIdentity();
|
|
95
101
|
}
|
|
96
|
-
/** Pins must look like the ids we mint (hex/uuid-ish
|
|
97
|
-
* and unexpanded template junk
|
|
102
|
+
/** Pins must look like the ids we mint (hex/uuid-ish, and `agent:<uuid>` for an
|
|
103
|
+
* automation-window agent). Rejects empty strings and unexpanded template junk
|
|
104
|
+
* like "${SYNABUN_TERMINAL_SESSION}". The Neural Interface accepts the same
|
|
105
|
+
* characters (neural-interface/lib/browser-owner.js browserOwnerId). */
|
|
98
106
|
export function sanitizePin(v) {
|
|
99
107
|
if (!v)
|
|
100
108
|
return null;
|
|
101
|
-
return /^[A-Za-z0-9_
|
|
109
|
+
return /^[A-Za-z0-9_:-]{1,128}$/.test(v) ? v : null;
|
|
102
110
|
}
|
|
103
111
|
/** Only known roles are accepted; anything else (empty, template junk,
|
|
104
112
|
* invented roles) is treated as "no role" so gating fails closed. */
|
|
@@ -146,6 +154,55 @@ export function callerBrainCredential() {
|
|
|
146
154
|
return credentialAls.getStore() ?? null;
|
|
147
155
|
return sanitizeBrainCredential(process.env.SYNABUN_BRAIN_TOKEN);
|
|
148
156
|
}
|
|
157
|
+
/** Terminal tokens look exactly like the ones the Neural Interface mints (neural-interface/lib/terminal-tokens.js). */
|
|
158
|
+
export function sanitizeTerminalToken(v) {
|
|
159
|
+
return typeof v === 'string' && /^sbt_[A-Za-z0-9_-]{43}$/.test(v.trim()) ? v.trim() : null;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* What proves a pin to the Neural Interface: a terminal token, or an Assistant brain's launch credential, which the
|
|
163
|
+
* Neural Interface binds to the brain's pin (neural-interface/lib/terminal-tokens.js bind: no second secret).
|
|
164
|
+
*/
|
|
165
|
+
export function sanitizeTerminalProof(v) {
|
|
166
|
+
return sanitizeTerminalToken(v) ?? sanitizeBrainCredential(v);
|
|
167
|
+
}
|
|
168
|
+
// The terminal token of the request being handled (X-Synabun-Terminal-Token): its own context per HTTP request,
|
|
169
|
+
// never a field of the CallerIdentity, for the reason the brain credential's is not (an identity is shared by every
|
|
170
|
+
// request that names its pin, which is no secret).
|
|
171
|
+
const terminalTokenAls = new AsyncLocalStorage();
|
|
172
|
+
/** Run `fn` with this request's terminal token (http.ts, around every transport.handleRequest). */
|
|
173
|
+
export function runWithTerminalToken(grant, fn) {
|
|
174
|
+
return terminalTokenAls.run(grant, fn);
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* The token that proves `terminalId` is the caller's own run, sent with X-Synabun-Terminal on its requests to the
|
|
178
|
+
* Neural Interface (whose browser routes take a run's pin only with it): over HTTP the one this request arrived with,
|
|
179
|
+
* and only for the pin it arrived with; for a stdio child the SYNABUN_TERMINAL_TOKEN of its launch environment, and
|
|
180
|
+
* only for its SYNABUN_TERMINAL_SESSION. An Assistant brain's MCP has no terminal token: its launch credential is the
|
|
181
|
+
* proof of its pin (SYNABUN_BRAIN_TOKEN for a stdio child, X-Synabun-Brain-Token over HTTP: http.ts
|
|
182
|
+
* requestTerminalToken). Never the host's own environment for an HTTP caller, and never for another id (an ancestor's
|
|
183
|
+
* terminal, the process's own client id).
|
|
184
|
+
*/
|
|
185
|
+
export function callerTerminalToken(terminalId) {
|
|
186
|
+
if (!terminalId)
|
|
187
|
+
return null;
|
|
188
|
+
if (httpMode) {
|
|
189
|
+
const grant = terminalTokenAls.getStore();
|
|
190
|
+
return grant && grant.terminal === terminalId ? grant.token : null;
|
|
191
|
+
}
|
|
192
|
+
const pin = sanitizePin(process.env.SYNABUN_TERMINAL_SESSION);
|
|
193
|
+
if (!pin || pin !== terminalId)
|
|
194
|
+
return null;
|
|
195
|
+
return sanitizeTerminalToken(process.env.SYNABUN_TERMINAL_TOKEN) ?? sanitizeBrainCredential(process.env.SYNABUN_BRAIN_TOKEN);
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* The identity headers of one request to the Neural Interface: X-Synabun-Terminal (terminalIdFor) and, when the caller
|
|
199
|
+
* holds it, that run's X-Synabun-Terminal-Token.
|
|
200
|
+
*/
|
|
201
|
+
export function terminalHeaders(id = getIdentity()) {
|
|
202
|
+
const terminal = terminalIdFor(id);
|
|
203
|
+
const token = callerTerminalToken(terminal);
|
|
204
|
+
return token ? { 'X-Synabun-Terminal': terminal, 'X-Synabun-Terminal-Token': token } : { 'X-Synabun-Terminal': terminal };
|
|
205
|
+
}
|
|
149
206
|
/**
|
|
150
207
|
* Role of the current caller: the ALS identity's role over HTTP (derived from
|
|
151
208
|
* X-Synabun-Role on every request), or SYNABUN_ROLE for stdio children —
|