aboutsummaryrefslogtreecommitdiff
path: root/src/daemon/index.ts
diff options
context:
space:
mode:
authoramankumarsingh77 <amankumarsingh7702@gmail.com>2026-07-28 20:27:07 +0530
committerAman Kumar <145339995+amankumarsingh77@users.noreply.github.com>2026-08-02 19:12:46 +0530
commita2588bb315a56a8dfcd3aa8a261cdc19b160d079 (patch)
tree2a65cfab8af322d076000026f9b42f98eecff42f /src/daemon/index.ts
parent330767d862458386e804bde240a1f0d7835b9b8e (diff)
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) <noreply@anthropic.com>
Diffstat (limited to 'src/daemon/index.ts')
-rw-r--r--src/daemon/index.ts23
1 files changed, 0 insertions, 23 deletions
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<typeof setTimeout> | 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...");