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
@@ -9,6 +9,8 @@
*/
import {
LOCAL_ENDPOINT_ID,
WINDOW_BRIDGE_ENDPOINT_KEY,
WINDOW_BRIDGE_KEY,
WINDOW_OVERLAY_KEY,
WINDOW_OVERLAY_METHODS,
@@ -51,6 +53,7 @@ import {
normalizeClientTopbarSlots,
normalizeClientUpdateMode,
normalizeClientWindowMountMode,
resetTelemetryForEndpointSwitch,
resolveScopedConversation,
selectConversation,
startAsyncTelemetryLoop,
@@ -958,10 +961,18 @@ export function mountWindowOverlay() {
const bridgeConfig = getWindowBridgeConfig();
const bundleVersion = String(bridgeConfig?.bundleVersion || '');
const stylesCss = String(bridgeConfig?.stylesCss || '');
const activeBridgeEndpointId = String(
bridgeConfig?.[WINDOW_BRIDGE_ENDPOINT_KEY] || LOCAL_ENDPOINT_ID
);
const reusableCarryOver =
carryOverTelemetry &&
String(carryOverTelemetry?.endpoint?.id || LOCAL_ENDPOINT_ID) === activeBridgeEndpointId
? carryOverTelemetry
: null;
const seedTelemetry =
(bridgeConfig?.initialTelemetry && typeof bridgeConfig.initialTelemetry === 'object'
? bridgeConfig.initialTelemetry
: null) || carryOverTelemetry;
: null) || reusableCarryOver;
if (bridgeConfig?.initialTelemetry) {
delete bridgeConfig.initialTelemetry;
}
@@ -2741,14 +2752,49 @@ export function mountWindowOverlay() {
const token = String(nextBridge.token || '');
if (!Number.isInteger(port) || port <= 0 || !token) return false;
const cur = readInjectedWindowBridge() || {};
const prevEndpointId = String(cur[WINDOW_BRIDGE_ENDPOINT_KEY] || LOCAL_ENDPOINT_ID);
const nextEndpointId =
nextBridge[WINDOW_BRIDGE_ENDPOINT_KEY] !== undefined
? String(nextBridge[WINDOW_BRIDGE_ENDPOINT_KEY] || LOCAL_ENDPOINT_ID)
: prevEndpointId;
const portChanged = Number(cur.port || 0) !== port || String(cur.token || '') !== token;
const endpointChanged = prevEndpointId !== nextEndpointId;
cur.port = port;
cur.token = token;
if (portChanged) {
cur[WINDOW_BRIDGE_ENDPOINT_KEY] = nextEndpointId;
if (nextBridge.isRemoteEndpoint !== undefined) {
cur.isRemoteEndpoint = Boolean(nextBridge.isRemoteEndpoint);
}
if (nextBridge.endpointLabel !== undefined) {
cur.endpointLabel = String(nextBridge.endpointLabel || '');
}
if (portChanged || endpointChanged) {
cur.transportMode = 'http';
}
if (endpointChanged) {
if (Array.isArray(cur.rpcQueue)) {
cur.rpcQueue.length = 0;
}
if (cur.rpcPending instanceof Map) {
for (const pending of cur.rpcPending.values()) {
try {
const switchErr = new Error('Bridge endpoint switched');
switchErr.name = 'AbortError';
pending?.reject?.(switchErr);
} catch {
// 忽略旧端点回调异常
}
}
cur.rpcPending.clear();
}
}
window[WINDOW_BRIDGE_KEY] = cur;
void fetchTelemetry({ force: false });
if (endpointChanged) {
resetTelemetryForEndpointSwitch();
void fetchTelemetry({ force: true });
} else {
void fetchTelemetry({ force: false });
}
return true;
},
getTelemetrySnapshot() {