mirror of
https://github.com/affaan-m/ECC.git
synced 2026-09-22 01:25:10 +02:00
scripts/plan-canvas.js and scripts/control-pane.js both define their own
openBrowser helpers for launching the user's default browser. The two
implementations have diverged:
- plan-canvas.js dispatches across darwin/win32/linux but its
try/spawn try/catch does not catch async child errors (ENOENT/EACCES
on hosts without the launcher command). Returns a bare true/false.
- control-pane.js is darwin-only and silently returns early on
Windows/Linux, so the two scripts behave inconsistently across
platforms.
When the launcher command is missing (e.g. headless CI without xdg-open)
the JSON output still says 'browser: opened', lying to the agent.
Changes:
- scripts/lib/platform-launch.js: shared openBrowser helper that
dispatches per platform, wires child 'error' so ENOENT/EACCES
propagate, and returns {opened, reason} instead of a bare boolean.
- scripts/plan-canvas.js: drops its local helper, imports the shared
one, and adds browserReason to its JSON output.
- scripts/control-pane.js: replaces its darwin-only branch with the
shared helper and logs the structured reason on failure.
- tests/lib/platform-launch.test.js: 7 node:test cases covering
opener-command selection, invalid-URL guard, structured-result
shape, and a smoke run for the actual spawn.
Verification: node --test tests/lib/platform-launch.test.js → 7/7 pass.
Co-authored-by: auyua9 <auyua9@users.noreply.github.com>
66 lines
1.6 KiB
JavaScript
Executable File
66 lines
1.6 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
'use strict';
|
|
|
|
const { spawn } = require('child_process');
|
|
|
|
const {
|
|
createControlPaneServer,
|
|
parseArgs,
|
|
usage,
|
|
} = require('./lib/control-pane/server');
|
|
const { describeMissingDependencyError } = require('./lib/missing-dependency');
|
|
|
|
// openBrowser is now in scripts/lib/platform-launch.js — keep a thin wrapper
|
|
// for backwards compatibility, but surface the structured result.
|
|
const { openBrowser: launchOpenBrowser } = require('./lib/platform-launch');
|
|
function openBrowser(url) {
|
|
const result = launchOpenBrowser(url);
|
|
if (!result.opened) {
|
|
console.error(`[control-pane] failed to open browser: ${result.reason}`);
|
|
}
|
|
}
|
|
|
|
async function main(argv = process.argv) {
|
|
const args = parseArgs(argv);
|
|
|
|
if (args.help) {
|
|
console.log(usage());
|
|
return;
|
|
}
|
|
|
|
const app = createControlPaneServer(args);
|
|
await app.listen();
|
|
|
|
console.log(`ECC Control Pane: ${app.url}`);
|
|
console.log(`ECC2 database: ${app.config.dbPath}`);
|
|
console.log(`ECC state database: ${app.config.stateDbPath}`);
|
|
console.log(args.allowActions ? 'Actions: enabled for local allowlist' : 'Actions: read-only');
|
|
|
|
if (args.openBrowser) {
|
|
openBrowser(app.url);
|
|
}
|
|
|
|
const shutdown = async () => {
|
|
try {
|
|
await app.close();
|
|
} finally {
|
|
process.exit(0);
|
|
}
|
|
};
|
|
|
|
process.on('SIGINT', shutdown);
|
|
process.on('SIGTERM', shutdown);
|
|
}
|
|
|
|
if (require.main === module) {
|
|
main().catch(error => {
|
|
console.error(`[control-pane] ${describeMissingDependencyError(error) || error.message}`);
|
|
process.exit(1);
|
|
});
|
|
}
|
|
|
|
module.exports = {
|
|
main,
|
|
openBrowser,
|
|
};
|