* feat: add project actions in header with reliable terminal run flow - Add per-project Actions settings with icons, platform filters, and default action - Run/stop actions from header using terminal tabs, including Ctrl+C then force-kill fallback - Improve terminal UX with stable selection, resize handling, and smarter URL auto-open for localhost ports * feat: add project actions UI with refined header dropdown behavior * feat: add parent-session back button in chat * fix: make web and desktop dev modes reliable and conflict-free - Separate desktop and web dev ports to avoid collisions - Add robust process-tree shutdown so Ctrl+C cleans sidecars - Add true web HMR mode and keep service worker out of dev * fix: linux safe scripts for dev * feat: run project actions on web and add desktop SSH forward URL opening * feat: add mobile project actions button with terminal tabs and tighter tab UI * revert: remove experimental mobile terminal selection UI * feat: show Add action button in header when empty * fix: make retry countdown human-readable in status row * fix: prevent nav rail actions from firing through overlays
137 lines
3.5 KiB
JavaScript
137 lines
3.5 KiB
JavaScript
#!/usr/bin/env node
|
|
import { spawn } from 'node:child_process';
|
|
import path from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = path.dirname(__filename);
|
|
const repoRoot = path.resolve(__dirname, '..');
|
|
const useDetachedChildren = process.platform === 'darwin';
|
|
|
|
function run(label, command, args, env = {}, options = {}) {
|
|
return spawn(command, args, {
|
|
cwd: options.cwd || repoRoot,
|
|
stdio: 'inherit',
|
|
env: { ...process.env, ...env },
|
|
detached: useDetachedChildren,
|
|
}).on('error', (error) => {
|
|
console.error(`[dev:web:hmr] Failed to start ${label}:`, error);
|
|
});
|
|
}
|
|
|
|
function waitForExit(child, timeoutMs) {
|
|
return new Promise((resolve) => {
|
|
if (!child || child.exitCode !== null || child.signalCode !== null) {
|
|
resolve();
|
|
return;
|
|
}
|
|
|
|
const onExit = () => {
|
|
clearTimeout(timer);
|
|
resolve();
|
|
};
|
|
|
|
const timer = setTimeout(() => {
|
|
child.off('exit', onExit);
|
|
resolve();
|
|
}, timeoutMs);
|
|
|
|
child.once('exit', onExit);
|
|
});
|
|
}
|
|
|
|
function signalChild(child, signal) {
|
|
if (!child || child.exitCode !== null || child.signalCode !== null) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
if (useDetachedChildren && process.platform !== 'win32') {
|
|
process.kill(-child.pid, signal);
|
|
return;
|
|
}
|
|
} catch {
|
|
}
|
|
|
|
try {
|
|
child.kill(signal);
|
|
} catch {
|
|
}
|
|
}
|
|
|
|
async function stopChildTree(child) {
|
|
if (!child || child.exitCode !== null || child.signalCode !== null) {
|
|
return;
|
|
}
|
|
|
|
signalChild(child, 'SIGINT');
|
|
await waitForExit(child, 2500);
|
|
|
|
if (child.exitCode === null && child.signalCode === null) {
|
|
signalChild(child, 'SIGTERM');
|
|
await waitForExit(child, 2500);
|
|
}
|
|
|
|
if (child.exitCode === null && child.signalCode === null) {
|
|
signalChild(child, 'SIGKILL');
|
|
await waitForExit(child, 1000);
|
|
}
|
|
}
|
|
|
|
const uiPort = process.env.OPENCHAMBER_HMR_UI_PORT || '5180';
|
|
const backendPort = process.env.OPENCHAMBER_HMR_API_PORT || '3902';
|
|
|
|
const api = run('api', 'bun', ['run', '--cwd', 'packages/web', 'dev:server:watch'], {
|
|
OPENCHAMBER_PORT: backendPort,
|
|
});
|
|
const vite = run(
|
|
'vite',
|
|
'bun',
|
|
['x', 'vite', '--host', '127.0.0.1', '--port', uiPort, '--strictPort'],
|
|
{
|
|
OPENCHAMBER_PORT: backendPort,
|
|
OPENCHAMBER_DISABLE_PWA_DEV: '1',
|
|
},
|
|
{ cwd: path.join(repoRoot, 'packages/web') },
|
|
);
|
|
|
|
console.log(`[dev:web:hmr] UI with HMR: http://127.0.0.1:${uiPort}`);
|
|
console.log(`[dev:web:hmr] API: http://127.0.0.1:${backendPort}`);
|
|
console.log('[dev:web:hmr] IMPORTANT: open UI URL above for HMR; backend URL has no HMR');
|
|
|
|
let shuttingDown = false;
|
|
|
|
async function shutdown(exitCode = 0) {
|
|
if (shuttingDown) return;
|
|
shuttingDown = true;
|
|
await Promise.all([stopChildTree(api), stopChildTree(vite)]);
|
|
process.exit(exitCode);
|
|
}
|
|
|
|
function onChildExit(label) {
|
|
return (code, signal) => {
|
|
if (shuttingDown) return;
|
|
|
|
if (code !== 0 || signal) {
|
|
console.error(`[dev:web:hmr] ${label} exited unexpectedly (code=${code ?? 'null'} signal=${signal ?? 'none'})`);
|
|
shutdown(typeof code === 'number' ? code : 1).catch(() => process.exit(1));
|
|
return;
|
|
}
|
|
|
|
shutdown(0).catch(() => process.exit(1));
|
|
};
|
|
}
|
|
|
|
api.on('exit', onChildExit('api'));
|
|
vite.on('exit', onChildExit('vite'));
|
|
|
|
process.on('SIGINT', () => {
|
|
shutdown(130).catch(() => process.exit(130));
|
|
});
|
|
process.on('SIGTERM', () => {
|
|
shutdown(143).catch(() => process.exit(143));
|
|
});
|
|
process.on('SIGHUP', () => {
|
|
shutdown(129).catch(() => process.exit(129));
|
|
});
|