Decouple bundled UI from runtime API and add remote instance tooling (#1228)
Add a packaged-client runtime boundary so the shared UI can talk to local, desktop, remote, and VS Code runtimes through the right transport instead of assuming one same-origin web server. Centralize OpenChamber-owned API access behind RuntimeAPIs, runtimeFetch, and runtime URL helpers, while keeping official OpenCode traffic on the SDK path. Support runtime switching, remote host selection, desktop client credentials, and headless connection links for pairing packaged clients with remote OpenChamber servers. Harden the new auth model by moving long-lived client tokens out of browser URLs, introducing short-lived scoped URL tokens for browser-owned transports, restricting URL-token access to explicit readable/realtime routes, and making client-token management session-scoped or self-scoped as appropriate. Update browser-owned assets and preview proxy flows to work with the split runtime model, including authenticated project icons, preview token propagation, CSP-safe preview bridge injection, and preview proxy auth that survives short-lived URL-token expiry. Tighten Electron security boundaries for packaged clients by gating privileged preload state to trusted origins and requiring explicit confirmation before connect deep-links import or switch remote runtimes. Also refresh agent guidance and project skills so future runtime/API, auth, preview, UI, CLI, settings, locale, and drag-to-reorder work follows the new architecture.
This commit is contained in:
committed by
GitHub
parent
a4314c189b
commit
2031e3b4a8
+565
-77
File diff suppressed because it is too large
Load Diff
@@ -12,6 +12,8 @@ const readArgValue = (name) => {
|
||||
};
|
||||
|
||||
const localOrigin = readArgValue('--openchamber-local-origin');
|
||||
const apiBaseUrl = readArgValue('--openchamber-api-base-url');
|
||||
const clientToken = readArgValue('--openchamber-client-token');
|
||||
const homeDirectory = readArgValue('--openchamber-home');
|
||||
const macosMajorRaw = readArgValue('--openchamber-macos-major');
|
||||
const macosMajor = Number.parseInt(macosMajorRaw, 10);
|
||||
@@ -22,10 +24,9 @@ const macosMajor = Number.parseInt(macosMajorRaw, 10);
|
||||
// Remote UIs still need it so isDesktopShell() returns true and the
|
||||
// window renders with desktop affordances (DesktopHostSwitcher,
|
||||
// title bar offsets, etc.). Expose unconditionally.
|
||||
// - __TAURI__ is the IPC channel to the main process. Remote pages must
|
||||
// not get it — otherwise any page loaded via DesktopHostSwitcher could
|
||||
// read local files, open apps, relaunch, etc. Expose only on local
|
||||
// pages (loopback / state.localOrigin / file:// for dev).
|
||||
// - __TAURI__ is the IPC channel to the main process. The compatibility
|
||||
// shim is exposed broadly, but privileged commands are gated in main.mjs.
|
||||
// Local-only globals below stay limited to packaged UI / exact localOrigin.
|
||||
// Everything driven by localOrigin (home dir, macOS hints) also stays
|
||||
// local-only since it leaks info about the Electron host machine.
|
||||
const currentOrigin = (() => {
|
||||
@@ -35,10 +36,9 @@ const currentOrigin = (() => {
|
||||
return '';
|
||||
}
|
||||
})();
|
||||
const isLoopbackOrigin = /^https?:\/\/(localhost|127\.0\.0\.1|\[::1\])(?::\d+)?$/i.test(currentOrigin);
|
||||
const isLocalPage = currentOrigin === 'null'
|
||||
|| isLoopbackOrigin
|
||||
|| (localOrigin && currentOrigin === localOrigin);
|
||||
const isLocalPage = currentOrigin !== 'null'
|
||||
&& (currentOrigin === 'openchamber-ui://app'
|
||||
|| (localOrigin && currentOrigin === localOrigin));
|
||||
|
||||
// Remote pages need __OPENCHAMBER_LOCAL_ORIGIN__ so the HostSwitcher knows
|
||||
// the URL of the Local entry (isDesktopLocalOriginActive() falls back to
|
||||
@@ -49,6 +49,14 @@ if (localOrigin) {
|
||||
contextBridge.exposeInMainWorld('__OPENCHAMBER_LOCAL_ORIGIN__', localOrigin);
|
||||
}
|
||||
|
||||
if (apiBaseUrl) {
|
||||
contextBridge.exposeInMainWorld('__OPENCHAMBER_API_BASE_URL__', apiBaseUrl);
|
||||
}
|
||||
|
||||
if (clientToken && isLocalPage) {
|
||||
contextBridge.exposeInMainWorld('__OPENCHAMBER_CLIENT_TOKEN__', clientToken);
|
||||
}
|
||||
|
||||
// Home directory leaks the OS username — keep local-only. Remote pages
|
||||
// operate on the REMOTE server's filesystem, local home is irrelevant
|
||||
// (and would be misleading if consumed as a workspace hint).
|
||||
|
||||
@@ -45,6 +45,25 @@ function spawnProcess(command, args, options = {}) {
|
||||
});
|
||||
}
|
||||
|
||||
function runProcess(command, args, options = {}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const child = spawn(command, args, {
|
||||
cwd: repoRoot,
|
||||
env: { ...process.env, OPENCHAMBER_ELECTRON_DEV: '1' },
|
||||
stdio: 'inherit',
|
||||
...options,
|
||||
});
|
||||
child.on('error', reject);
|
||||
child.on('exit', (code, signal) => {
|
||||
if (code === 0) {
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
reject(new Error(`${command} ${args.join(' ')} exited with code ${code ?? 'null'} signal ${signal ?? 'none'}`));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function waitForExit(child, timeoutMs) {
|
||||
return new Promise((resolve) => {
|
||||
if (!child || child.exitCode !== null || child.signalCode !== null) {
|
||||
@@ -159,23 +178,33 @@ async function stopChildTree(child) {
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const hmrApiPort = String(await findAvailablePort(preferredHmrApiPort));
|
||||
const hmrUiPort = String(await findAvailablePort(preferredHmrUiPort));
|
||||
const useBundledUi = process.env.OPENCHAMBER_ELECTRON_USE_BUNDLED_UI === '1';
|
||||
let devServer = null;
|
||||
let hmrApiPort = '';
|
||||
let hmrUiPort = '';
|
||||
|
||||
if (useBundledUi) {
|
||||
await runProcess('bun', ['run', '--cwd', 'packages/electron', 'build:web-assets']);
|
||||
} else {
|
||||
hmrApiPort = String(await findAvailablePort(preferredHmrApiPort));
|
||||
hmrUiPort = String(await findAvailablePort(preferredHmrUiPort));
|
||||
devServer = spawnProcess('node', ['./scripts/dev-web-hmr.mjs'], {
|
||||
env: {
|
||||
...process.env,
|
||||
OPENCHAMBER_ELECTRON_DEV: '1',
|
||||
OPENCHAMBER_HMR_UI_PORT: hmrUiPort,
|
||||
OPENCHAMBER_HMR_API_PORT: hmrApiPort,
|
||||
OPENCHAMBER_DISABLE_PWA_DEV: '1',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const devServer = spawnProcess('node', ['./scripts/dev-web-hmr.mjs'], {
|
||||
env: {
|
||||
...process.env,
|
||||
OPENCHAMBER_ELECTRON_DEV: '1',
|
||||
OPENCHAMBER_HMR_UI_PORT: hmrUiPort,
|
||||
OPENCHAMBER_HMR_API_PORT: hmrApiPort,
|
||||
OPENCHAMBER_DISABLE_PWA_DEV: '1',
|
||||
},
|
||||
});
|
||||
const electron = spawnProcess('npx', ['electron', './main.mjs'], {
|
||||
cwd: electronDir,
|
||||
env: {
|
||||
...process.env,
|
||||
OPENCHAMBER_ELECTRON_DEV: '1',
|
||||
...(useBundledUi ? { OPENCHAMBER_ELECTRON_USE_BUNDLED_UI: '1' } : {}),
|
||||
OPENCHAMBER_HMR_UI_PORT: hmrUiPort,
|
||||
OPENCHAMBER_HMR_API_PORT: hmrApiPort,
|
||||
OPENCHAMBER_DISABLE_PWA_DEV: '1',
|
||||
@@ -200,9 +229,9 @@ async function main() {
|
||||
void teardown(code ?? 1);
|
||||
};
|
||||
|
||||
devServer.on('exit', onChildExit('dev server'));
|
||||
devServer?.on('exit', onChildExit('dev server'));
|
||||
electron.on('exit', onChildExit('electron'));
|
||||
devServer.on('error', (error) => {
|
||||
devServer?.on('error', (error) => {
|
||||
console.error('[electron:dev] failed to start dev server:', error);
|
||||
void teardown(1);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user