feat(panel): support SSH remote windows with per-endpoint isolation and context window overrides

- Add per-endpoint registry and isolated caches (endpoint-registry.mjs, multi-path trajectory-cache-file.mjs) so local and SSH remote windows maintain independent conversations, telemetry, quotas, and consumption analytics (Antigravity SSH) without remote plugin installation
- Classify local vs. SSH Desktop targets via two-pass hub port and metadata probing in window-bridge.mjs and ls-discovery.mjs, routing HTTP/CDP requests with authoritative X-Usage-Monitor-Endpoint headers and preventing local data leaks or 503-triggered CDP downgrades
- Implement two-tier read-only remote LS RPC transport in ls-rpc.mjs (loopback HTTP/HTTPS with size/wall-clock limits and 60s circuit breaker falling back to stateless same-origin window.fetch / connect-websocket via CDP)
- Enable per-endpoint verified context window overrides in SSH Desktop windows (context-windows.mjs, window-bridge.mjs, api-actions.mjs) without double-wrapping window.fetch
- Surface an SSH badge in TopSessionHeader, cleanly flush stale requests/queues on endpoint rebind, rebuild app.js/styles.css, and add 13 unit/E2E tests in test/ssh-remote-endpoints.test.mjs (157/157 passing)
This commit is contained in:
hejun01
2026-11-20 11:41:39 +08:00
parent d371dc1ed5
commit 253da45607
22 changed files with 4095 additions and 310 deletions
+22 -9
View File
@@ -121,18 +121,19 @@ export async function syncHostContextWindows(
rules,
bootId,
key = '__AGUsageMonitorContextWindows',
fallbackRules = {}
fallbackRules = {},
allowRemoteHost = false
) {
let state = window[key];
const appConfig = window.__APP_CONFIG__;
const csrfToken = appConfig?.csrfToken;
const csrfToken = appConfig?.csrfToken || state?.observedCsrfToken || '';
const hasPrefs = Boolean(rules && Object.keys(rules).length > 0);
const safeFallback =
fallbackRules && typeof fallbackRules === 'object' && !Array.isArray(fallbackRules)
? fallbackRules
: {};
const hasFallback = Object.keys(safeFallback).length > 0;
if (!hasPrefs || appConfig?.isRemoteControl || (!csrfToken && !hasFallback)) {
if (!hasPrefs || (!allowRemoteHost && appConfig?.isRemoteControl) || (!csrfToken && !hasFallback)) {
state?.dispose();
return { attached: false, ruleCount: 0 };
}
@@ -207,10 +208,17 @@ export async function syncHostContextWindows(
: '';
if (rawUrl && init?.method === 'POST') {
const url = new URL(rawUrl, window.location.href);
if (url.origin === window.location.origin && isTargetProcedure(url.pathname)) {
const type = new Headers(init.headers).get('content-type')?.split(';')[0].trim();
const body = rewriteBody(init.body, type);
if (body !== init.body) nextInit = { ...init, body };
if (url.origin === window.location.origin && url.pathname.startsWith(servicePath)) {
const hdrs = new Headers(init.headers);
const seenCsrf = hdrs.get('x-codeium-csrf-token')?.trim();
if (seenCsrf && state) {
state.observedCsrfToken = seenCsrf;
}
if (isTargetProcedure(url.pathname)) {
const type = hdrs.get('content-type')?.split(';')[0].trim();
const body = rewriteBody(init.body, type);
if (body !== init.body) nextInit = { ...init, body };
}
}
}
} catch {
@@ -312,7 +320,12 @@ export async function syncHostContextWindows(
return { attached: Boolean(state.isAttached?.()), ruleCount: Object.keys(state.rules).length };
}
export function createContextWindowSyncExpression(preferences, bootId, fallbackRules = {}) {
export function createContextWindowSyncExpression(
preferences,
bootId,
fallbackRules = {},
allowRemoteHost = false
) {
return `(() => {
${isContextWindowModelId.toString()}
${isContextWindowSettingId.toString()}
@@ -321,6 +334,6 @@ export function createContextWindowSyncExpression(preferences, bootId, fallbackR
${getContextWindowGroups.toString()}
${resolveContextWindowOption.toString()}
${resolveContextWindowRules.toString()}
return (${syncHostContextWindows.toString()})(${JSON.stringify(preferences)}, ${JSON.stringify(bootId)}, ${JSON.stringify(CONTEXT_WINDOWS_GLOBAL_KEY)}, ${JSON.stringify(fallbackRules || {})});
return (${syncHostContextWindows.toString()})(${JSON.stringify(preferences)}, ${JSON.stringify(bootId)}, ${JSON.stringify(CONTEXT_WINDOWS_GLOBAL_KEY)}, ${JSON.stringify(fallbackRules || {})}, ${JSON.stringify(Boolean(allowRemoteHost))});
})()`;
}