From a2588bb315a56a8dfcd3aa8a261cdc19b160d079 Mon Sep 17 00:00:00 2001 From: amankumarsingh77 Date: Tue, 28 Jul 2026 20:27:07 +0530 Subject: refactor(daemon): strip comment noise Removes module banners, section dividers, reference lists, and comments restating the code. Keeps one-line notes for the Windows named-pipe endpoint, the Windows unlink no-op, the do-not-unlink-on-rejection rule, the `.cmd` shell requirement, shell-quoting of spaced paths, and the in-place client promotion. Co-Authored-By: Claude Opus 5 (1M context) --- src/daemon/index.ts | 23 ----------------------- 1 file changed, 23 deletions(-) (limited to 'src/daemon/index.ts') diff --git a/src/daemon/index.ts b/src/daemon/index.ts index d2c43a8..30a6b6e 100644 --- a/src/daemon/index.ts +++ b/src/daemon/index.ts @@ -1,12 +1,3 @@ -/** - * Browser daemon entry point — standalone long-lived process. - * - * Owns a single persistent WebSocket to Chrome. Exposes a Unix domain socket - * for pi instances to connect through. One Allow dialog ever (per Chrome - * lifetime), zero repeated prompts. - * - * Run: npx tsx src/daemon/index.ts - */ import { createIpcServer } from "./server"; import { createCdpBridge, type SendToClient } from "./bridge"; @@ -18,9 +9,7 @@ async function main() { const ipcServer = createIpcServer(); const cdpBridge = createCdpBridge(); - // ── Wire IpcServer → CdpBridge ───────────────────────────────────────── - // When a pi client sends a CDP request, proxy it through the bridge to Chrome. ipcServer.onMessage((msg, client) => { if (msg.type !== "request") return; @@ -31,19 +20,16 @@ async function main() { cdpBridge.handleRequest(msg, client.id, send); }); - // When Chrome sends an event, route it to the correct pi client(s). cdpBridge.onEvent((event, targetClientIds) => { for (const cid of targetClientIds) { ipcServer.send(cid, event); } }); - // When a client disconnects, clean up its CDP state. ipcServer.onDisconnect((client) => { cdpBridge.removeClient(client.id); }); - // When Chrome disconnects, notify all clients. cdpBridge.onClose(() => { console.log("[pi-browser-daemon] Chrome disconnected"); ipcServer.broadcast({ @@ -53,11 +39,7 @@ async function main() { }); }); - // ── Idle timeout ─────────────────────────────────────────────────────── - // The daemon exits after DAEMON_IDLE_TIMEOUT_MS with zero connected clients. - // This prevents zombie processes when pi sessions end and never reconnect. - // The timeout resets whenever a client connects. let idleTimer: ReturnType | null = null; const resetIdleTimer = (): void => { @@ -78,7 +60,6 @@ async function main() { ipcServer.onConnect(() => { cancelIdleTimer(); }); ipcServer.onDisconnect(() => { resetIdleTimer(); }); - // ── Start ────────────────────────────────────────────────────────────── try { await ipcServer.start(); @@ -88,14 +69,10 @@ async function main() { process.exit(1); } - // Connect to Chrome (auto-retries with backoff in the background). - // The daemon is ready immediately — Chrome may connect later. await cdpBridge.start(); - // Start the idle timer (no clients yet at startup). resetIdleTimer(); - // ── Graceful shutdown ────────────────────────────────────────────────── const shutdown = async () => { console.log("[pi-browser-daemon] Shutting down..."); -- cgit v1.2.3