kaizen-agent 1.6.7 → 1.6.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli/web.ts +18 -8
- package/package.json +1 -1
package/cli/web.ts
CHANGED
|
@@ -83,14 +83,24 @@ export async function web(repoDir: string, opts: Opts = {}) {
|
|
|
83
83
|
const BOOT = Date.now().toString(36);
|
|
84
84
|
const ping = setInterval(() => { for (const c of clients) { try { c.enqueue(": ping\n\n"); } catch { clients.delete(c); } } }, 8000);
|
|
85
85
|
// A launcher clicked while a board is already up should show that board, not die.
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
86
|
+
// A bind can fail because a board is already there, or because the OS will not
|
|
87
|
+
// hand out the port at all (Windows reserves whole ranges for Hyper-V and WSL,
|
|
88
|
+
// and reports either as "in use"). Only a board that answers is "already
|
|
89
|
+
// running"; otherwise walk up to the next port that binds.
|
|
90
|
+
let port = opts.port ?? DEFAULT_PORT;
|
|
91
|
+
let server: ReturnType<typeof serve> | null = null;
|
|
92
|
+
for (let tries = 0; tries < 10 && !server; tries++, port++) {
|
|
93
|
+
try { server = serve(port); } catch (e) {
|
|
94
|
+
if (!["EADDRINUSE", "EACCES"].includes((e as { code?: string }).code ?? "")) throw e;
|
|
95
|
+
const url = `http://127.0.0.1:${port}/`;
|
|
96
|
+
const up = await fetch(url, { signal: AbortSignal.timeout(1500) }).then((r) => r.ok, () => false);
|
|
97
|
+
if (up) { console.log(`\n kaizen web already at ${url}\n`); if (opts.open !== false) await openApp(url); return; }
|
|
98
|
+
console.log(` port ${port} refused by the OS and nothing answers there; trying ${port + 1}`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (!server) { console.log(`\n kaizen web could not bind any port from ${opts.port ?? DEFAULT_PORT}\n`); return; }
|
|
102
|
+
|
|
103
|
+
function serve(port: number) { return Bun.serve({
|
|
94
104
|
hostname: "127.0.0.1",
|
|
95
105
|
port,
|
|
96
106
|
async fetch(req) {
|
package/package.json
CHANGED