diff options
| author | Drew Ritter <drew@primeradiant.com> | 2026-06-10 16:23:13 -0700 |
|---|---|---|
| committer | Drew Ritter <drew@primeradiant.com> | 2026-06-16 10:09:45 -0700 |
| commit | 69270c9007d9f68ab2ea8867eff409fbcff58dd6 (patch) | |
| tree | 316d3e59622f9d0ea8754365d6563943861b8927 /skills/brainstorming/scripts/server.cjs | |
| parent | b17d54f839831b2345aa389e2f65f435f3a82867 (diff) | |
Harden companion Windows lifecycle coverage
Diffstat (limited to 'skills/brainstorming/scripts/server.cjs')
| -rw-r--r-- | skills/brainstorming/scripts/server.cjs | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/skills/brainstorming/scripts/server.cjs b/skills/brainstorming/scripts/server.cjs index 8728cc3..90eff80 100644 --- a/skills/brainstorming/scripts/server.cjs +++ b/skills/brainstorming/scripts/server.cjs @@ -192,6 +192,16 @@ function getNewestScreen() { return files.length > 0 ? files[0].path : null; } +function urlHostForHttp(host) { + const h = String(host); + if (h.startsWith('[') && h.endsWith(']')) return h; + return h.includes(':') ? '[' + h + ']' : h; +} + +function companionUrl() { + return 'http://' + urlHostForHttp(URL_HOST) + ':' + PORT + '/?key=' + TOKEN; +} + function isRegularFileInsideContentDir(filePath) { let stat, realContentDir, realFilePath; try { @@ -424,7 +434,7 @@ function maybeOpenBrowser() { if (!process.env.BRAINSTORM_OPEN) return; // opt-in: only after the user approves the companion if (HOST !== '127.0.0.1' && HOST !== 'localhost') return; if (clients.size > 0) return; // the user already opened it - const url = 'http://' + URL_HOST + ':' + PORT + '/?key=' + TOKEN; // must carry the key or the gate 403s it + const url = companionUrl(); // must carry the key or the gate 403s it const cp = require('child_process'); // Operator-provided launcher: run as given (this env var is trusted operator input). if (process.env.BRAINSTORM_OPEN_CMD) { @@ -572,7 +582,7 @@ function startServer() { } const info = JSON.stringify({ type: 'server-started', port: Number(PORT), host: HOST, - url_host: URL_HOST, url: 'http://' + URL_HOST + ':' + PORT + '/?key=' + TOKEN, + url_host: URL_HOST, url: companionUrl(), screen_dir: CONTENT_DIR, state_dir: STATE_DIR, idle_timeout_ms: IDLE_TIMEOUT_MS }); console.log(info); |
