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
@@ -3,7 +3,8 @@ import {
} from 'node:fs';
import { randomUUID } from 'node:crypto';
let lastWrite = null;
const MAX_TRACKED_CACHE_FILES = 16;
const lastWritesByPath = new Map();
function isSameFile(a, b) {
return b.ino !== 0n && a.dev === b.dev && a.ino === b.ino &&
@@ -29,7 +30,7 @@ function readReusableBytes(filePath, expected) {
// 只复用上次确认写入的步骤字节。扫描器用新数组替换变更步骤,每次仍重新序列化会话元数据。
export function writeTrajectoryCacheFile(filePath, data) {
const previous = lastWrite?.filePath === filePath ? lastWrite : null;
const previous = lastWritesByPath.get(filePath) || null;
const bytes = previous ? readReusableBytes(filePath, previous.file) : null;
const ranges = new WeakMap();
const parts = [];
@@ -72,7 +73,14 @@ export function writeTrajectoryCacheFile(filePath, data) {
const written = statSync(temporaryPath, { bigint: true });
renameSync(temporaryPath, filePath);
const file = statSync(filePath, { bigint: true });
lastWrite = isSameFile(written, file) ? { filePath, file, ranges } : null;
lastWritesByPath.delete(filePath);
if (isSameFile(written, file)) {
if (lastWritesByPath.size >= MAX_TRACKED_CACHE_FILES) {
const oldestPath = lastWritesByPath.keys().next().value;
if (oldestPath !== undefined) lastWritesByPath.delete(oldestPath);
}
lastWritesByPath.set(filePath, { filePath, file, ranges });
}
} finally {
try { unlinkSync(temporaryPath); } catch {}
}