From aedbb88a8025851067be9f77ec406b29d65599a8 Mon Sep 17 00:00:00 2001 From: amankumarsingh77 Date: Tue, 28 Jul 2026 21:47:21 +0530 Subject: refactor: delete exports and knobs that nothing calls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit isInternalUrl, SPECIAL_KEYS, andThen and mapErr had no callers in src or test. BrowserState.remoteBrowserId was parsed on restore and never written — the field that is actually read lives on DaemonStatus. IpcServer.disconnectClient and IpcServer.clients() were unreachable, as was EventRouter.allClients and a write-only lineCount counter. DAEMON_STALE_SOCKET_CLEANUP was a hardcoded true with an if around it, so the unlink now runs unconditionally. CdpBridge.isAlive and getSessionOwner look equally dead from src/ alone, but test/manual/bridge-test.ts drives both — they are the only seams that suite has, so they stay. Co-Authored-By: Claude Opus 5 (1M context) --- src/cdp/types.ts | 7 ------- src/daemon/bridge.ts | 8 -------- src/daemon/protocol.ts | 2 -- src/daemon/server.ts | 20 +++----------------- src/state.ts | 3 --- src/util/keycodes.ts | 2 -- src/util/result.ts | 6 ------ 7 files changed, 3 insertions(+), 45 deletions(-) diff --git a/src/cdp/types.ts b/src/cdp/types.ts index 33ab202..984b930 100644 --- a/src/cdp/types.ts +++ b/src/cdp/types.ts @@ -46,13 +46,6 @@ export type DaemonStatus = { readonly remoteBrowserId?: string; }; -const INTERNAL_PREFIXES: ReadonlyArray = [ - "chrome://", "chrome-untrusted://", "devtools://", "chrome-extension://", "about:", -]; - -export const isInternalUrl = (url: string): boolean => - INTERNAL_PREFIXES.some((p) => url.startsWith(p)); - export const isCdpRawMessage = (v: unknown): v is CdpRawMessage => { if (!isRecord(v)) return false; const id = v["id"]; diff --git a/src/daemon/bridge.ts b/src/daemon/bridge.ts index 95f6888..d9a54ed 100644 --- a/src/daemon/bridge.ts +++ b/src/daemon/bridge.ts @@ -17,8 +17,6 @@ export type CdpBridge = { stop(): Promise; handleRequest(req: WireRequest, clientId: string, send: SendToClient): Promise; isAlive(): boolean; - recordSession(clientId: string, sessionId: string): void; - releaseSession(sessionId: string): void; getSessionOwner(sessionId: string): string | undefined; removeClient(clientId: string): void; onEvent(handler: EventHandler): void; @@ -98,10 +96,6 @@ class EventRouter { } return [...this.clientSessions.keys()]; } - - allClients(): string[] { - return [...this.clientSessions.keys()]; - } } export const createCdpBridge = (): CdpBridge => { @@ -357,8 +351,6 @@ export const createCdpBridge = (): CdpBridge => { stop, handleRequest, isAlive: () => ws !== null && ws.readyState === WebSocket.OPEN, - recordSession: (cid, sid) => router.record(cid, sid), - releaseSession: (sid) => router.release(sid), getSessionOwner: (sid) => router.getOwner(sid), removeClient: (cid) => { mux.clearClient(cid); router.removeClient(cid); }, onEvent: (h) => { eventHandler = h; }, diff --git a/src/daemon/protocol.ts b/src/daemon/protocol.ts index 43c89de..2501980 100644 --- a/src/daemon/protocol.ts +++ b/src/daemon/protocol.ts @@ -105,8 +105,6 @@ export const DAEMON_IDLE_TIMEOUT_MS = 30 * 60 * 1000; export const DAEMON_MAX_CLIENTS = 16; -export const DAEMON_STALE_SOCKET_CLEANUP = true; - export const CDP_CONNECT_TIMEOUT_MS = 10_000; export const CDP_COMMAND_TIMEOUT_MS = 10_000; diff --git a/src/daemon/server.ts b/src/daemon/server.ts index 7c78372..142bddb 100644 --- a/src/daemon/server.ts +++ b/src/daemon/server.ts @@ -7,7 +7,6 @@ import { isWireMessage, DAEMON_SOCKET_PATH, DAEMON_MAX_CLIENTS, - DAEMON_STALE_SOCKET_CLEANUP, } from "./protocol"; export type ClientSocket = { @@ -29,8 +28,6 @@ export type IpcServer = { onDisconnect(handler: ConnectionHandler): void; send(clientId: string, msg: WireMessage): void; broadcast(msg: WireMessage): void; - disconnectClient(clientId: string): void; - clients(): ReadonlyMap; clientCount(): number; }; @@ -45,11 +42,9 @@ export const createIpcServer = (): IpcServer => { const start = (): Promise => new Promise((resolve, reject) => { - if (DAEMON_STALE_SOCKET_CLEANUP) { - try { - unlinkSync(DAEMON_SOCKET_PATH); - } catch {} - } + try { + unlinkSync(DAEMON_SOCKET_PATH); + } catch {} server = createServer({ pauseOnConnect: false }, (socket: Socket) => { if (clients.size >= DAEMON_MAX_CLIENTS) { @@ -63,10 +58,7 @@ export const createIpcServer = (): IpcServer => { sockets.set(tempId, currentClient); - let lineCount = 0; - rl.on("line", (line: string) => { - lineCount++; let msg: WireMessage | null; try { const parsed: unknown = JSON.parse(line); @@ -178,12 +170,6 @@ export const createIpcServer = (): IpcServer => { this.send(clientId, msg); } }, - disconnectClient(clientId) { - const client = clients.get(clientId); - if (!client) return; - client.socket.destroy(); - }, - clients: (): ReadonlyMap => clients, clientCount: (): number => clients.size, }; }; diff --git a/src/state.ts b/src/state.ts index 71f164b..8f25dc4 100644 --- a/src/state.ts +++ b/src/state.ts @@ -3,7 +3,6 @@ import { asArrayOf, asNumber, asString, isRecord } from "./util/guards"; export type BrowserState = { readonly namespace: string; - readonly remoteBrowserId?: string; readonly ownedTargetIds?: ReadonlyArray; readonly harnessWindowTargetId?: string; readonly harnessWindowId?: number; @@ -21,13 +20,11 @@ export const persistState = (pi: ExtensionAPI, state: BrowserState): void => { const asPersistedState = (v: unknown): Partial | undefined => { if (!isRecord(v)) return undefined; const namespace = asString(v["namespace"]); - const remoteBrowserId = asString(v["remoteBrowserId"]); const ownedTargetIds = asArrayOf(v["ownedTargetIds"], asString); const harnessWindowTargetId = asString(v["harnessWindowTargetId"]); const harnessWindowId = asNumber(v["harnessWindowId"]); return { ...(namespace !== undefined ? { namespace } : {}), - ...(remoteBrowserId !== undefined ? { remoteBrowserId } : {}), ...(ownedTargetIds !== undefined ? { ownedTargetIds } : {}), ...(harnessWindowTargetId !== undefined ? { harnessWindowTargetId } : {}), ...(harnessWindowId !== undefined ? { harnessWindowId } : {}), diff --git a/src/util/keycodes.ts b/src/util/keycodes.ts index 2445eaf..68be059 100644 --- a/src/util/keycodes.ts +++ b/src/util/keycodes.ts @@ -4,7 +4,5 @@ const VIRTUAL_KEY_CODES: Readonly> = { Home: 36, End: 35, PageUp: 33, PageDown: 34, }; -export const SPECIAL_KEYS: ReadonlyArray = Object.keys(VIRTUAL_KEY_CODES); - export const virtualKeyCode = (key: string): number => VIRTUAL_KEY_CODES[key] ?? (key.length === 1 ? key.charCodeAt(0) : 0); diff --git a/src/util/result.ts b/src/util/result.ts index ca57c2a..d57fea7 100644 --- a/src/util/result.ts +++ b/src/util/result.ts @@ -7,9 +7,3 @@ export const err = (error: E): Result => ({ success: false, error } export const map = (r: Result, f: (t: T) => U): Result => r.success ? ok(f(r.data)) : r; - -export const andThen = (r: Result, f: (t: T) => Result): Result => - r.success ? f(r.data) : r; - -export const mapErr = (r: Result, f: (e: E) => F): Result => - r.success ? r : err(f(r.error)); -- cgit v1.2.3