diff options
| author | amankumarsingh77 <amankumarsingh7702@gmail.com> | 2026-07-28 20:34:49 +0530 |
|---|---|---|
| committer | Aman Kumar <145339995+amankumarsingh77@users.noreply.github.com> | 2026-08-02 19:12:46 +0530 |
| commit | a9bdbd8590801cd9c2fa0cda6203948ac19a779c (patch) | |
| tree | 060ced4709815f9415fc1172842ed25d97de545f | |
| parent | 34e5cfdcbe29bbb5f2f46ba54eb67903abd9274d (diff) | |
refactor: tidy the whitespace the comment removal left behind
Drops leading blank lines where a file header was removed, collapses
double blank lines, and closes the empty catch/handler blocks whose only
content had been a comment. Whitespace only.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
29 files changed, 22 insertions, 104 deletions
diff --git a/src/cdp/console-buffer.ts b/src/cdp/console-buffer.ts index c38f85e..53dd6c2 100644 --- a/src/cdp/console-buffer.ts +++ b/src/cdp/console-buffer.ts @@ -1,4 +1,3 @@ - import { decodeEvent } from "./events"; export type ConsoleLevel = "log" | "info" | "warn" | "error" | "debug"; @@ -43,8 +42,7 @@ const compileTextMatcher = (pattern: string): ((text: string) => boolean) => { try { const re = new RegExp(pattern.slice(1, -1)); return (text) => re.test(text); - } catch { - } + } catch {} } return (text) => text.includes(pattern); }; diff --git a/src/cdp/daemon-transport.ts b/src/cdp/daemon-transport.ts index 101108d..14f78c4 100644 --- a/src/cdp/daemon-transport.ts +++ b/src/cdp/daemon-transport.ts @@ -1,4 +1,3 @@ - import { createConnection, type Socket } from "node:net"; import { createInterface } from "node:readline"; import { type Result, err, ok } from "../util/result"; @@ -14,7 +13,6 @@ import { serialize, } from "../daemon/protocol"; - export const createDaemonTransport = (clientId: string): CdpTransport => { let socket: Socket | null = null; let rl: ReturnType<typeof createInterface> | null = null; @@ -36,7 +34,6 @@ export const createDaemonTransport = (clientId: string): CdpTransport => { for (const cb of closeListeners) cb(); }; - const connect = (_url: string, opts?: { timeoutMs?: number }): Promise<Result<void, CdpError>> => { const timeoutMs = opts?.timeoutMs ?? 10_000; @@ -117,8 +114,7 @@ export const createDaemonTransport = (clientId: string): CdpTransport => { } }); - sock.on("error", () => { - }); + sock.on("error", () => {}); sock.on("close", () => { clearTimeout(connectTimer); @@ -140,7 +136,6 @@ export const createDaemonTransport = (clientId: string): CdpTransport => { }); }; - const close = async (): Promise<void> => { if (registered && socket && !socket.destroyed) { const dereg: WireControl = { type: "control", action: "deregister", clientId }; @@ -149,7 +144,6 @@ export const createDaemonTransport = (clientId: string): CdpTransport => { cleanup("close() called"); }; - const request = ( method: string, params: Record<string, unknown>, @@ -175,10 +169,8 @@ export const createDaemonTransport = (clientId: string): CdpTransport => { return sendWithTimeout(pending, id, method, timeoutMs, "Daemon", () => sock.write(serialize(req) + "\n")); }; - const events = (): AsyncIterable<CdpEvent> => queue.iter; - const state = (): "open" | "closed" | "connecting" => { if (!socket) return "closed"; if (!registered) return "connecting"; diff --git a/src/cdp/discovery.ts b/src/cdp/discovery.ts index 7b67fe0..f33adc6 100644 --- a/src/cdp/discovery.ts +++ b/src/cdp/discovery.ts @@ -114,8 +114,7 @@ export const discoverEndpoint = async (): Promise<Result<CdpEndpoint, CdpError>> raw = await readFile(portFile, "utf8"); try { mtimeMs = (await stat(portFile)).mtimeMs; - } catch { - } + } catch {} } catch (e) { // EPERM/EACCES is common under sandboxes; remember it and fall back to network probing rather than failing the whole discovery. const code = errnoCode(e); diff --git a/src/cdp/event-queue.ts b/src/cdp/event-queue.ts index 5e154ea..330bdb8 100644 --- a/src/cdp/event-queue.ts +++ b/src/cdp/event-queue.ts @@ -1,4 +1,3 @@ - import { type Result, err } from "../util/result"; import { type CdpError, cdpError } from "./errors"; import type { CdpEvent } from "./types"; diff --git a/src/cdp/network-buffer.ts b/src/cdp/network-buffer.ts index f6ad032..0366ed4 100644 --- a/src/cdp/network-buffer.ts +++ b/src/cdp/network-buffer.ts @@ -1,4 +1,3 @@ - import { decodeEvent } from "./events"; export type NetworkRecord = { @@ -47,8 +46,7 @@ const compileUrlMatcher = (pattern: string): ((url: string) => boolean) => { try { const re = new RegExp(pattern.slice(1, -1)); return (url) => re.test(url); - } catch { - } + } catch {} } return (url) => url.includes(pattern); }; diff --git a/src/cdp/ownership.ts b/src/cdp/ownership.ts index 0a1a810..52965b0 100644 --- a/src/cdp/ownership.ts +++ b/src/cdp/ownership.ts @@ -1,4 +1,3 @@ - export type OwnershipRegistry = { add(targetId: string): void; remove(targetId: string): void; diff --git a/src/daemon/bridge.ts b/src/daemon/bridge.ts index bc162a7..95f6888 100644 --- a/src/daemon/bridge.ts +++ b/src/daemon/bridge.ts @@ -1,4 +1,3 @@ - import WebSocket from "ws"; import { discoverWsUrl } from "../cdp/discovery"; import { isCdpRawMessage } from "../cdp/types"; @@ -7,7 +6,6 @@ import type { WireRequest, WireResponse, WireEvent } from "./protocol"; import { CDP_CONNECT_TIMEOUT_MS, CDP_COMMAND_TIMEOUT_MS } from "./protocol"; import { asString, isRecord } from "../util/guards"; - export type SendToClient = (clientId: string, msg: WireResponse | WireEvent) => void; export type EventHandler = (event: WireEvent, targetClientIds: string[]) => void; @@ -27,7 +25,6 @@ export type CdpBridge = { onClose(handler: CloseHandler): void; }; - interface PendingEntry { clientId: string; localId: number; @@ -63,7 +60,6 @@ class IdMultiplexer { } } - class EventRouter { private owners = new Map<string, string>(); private clientSessions = new Map<string, Set<string>>(); @@ -108,7 +104,6 @@ class EventRouter { } } - export const createCdpBridge = (): CdpBridge => { let ws: WebSocket | null = null; let wsUrl: string | null = null; @@ -125,7 +120,6 @@ export const createCdpBridge = (): CdpBridge => { isAttach: boolean; }>(); - const onChromeMessage = (raw: string): void => { let parsed: unknown; try { parsed = JSON.parse(raw); } catch { return; } @@ -184,8 +178,6 @@ export const createCdpBridge = (): CdpBridge => { } }; - - let reconnectTimer: ReturnType<typeof setTimeout> | null = null; let reconnectAttempt = 0; let stopped = false; diff --git a/src/daemon/index.ts b/src/daemon/index.ts index 30a6b6e..226a895 100644 --- a/src/daemon/index.ts +++ b/src/daemon/index.ts @@ -1,4 +1,3 @@ - import { createIpcServer } from "./server"; import { createCdpBridge, type SendToClient } from "./bridge"; import { DAEMON_IDLE_TIMEOUT_MS } from "./protocol"; @@ -9,7 +8,6 @@ async function main() { const ipcServer = createIpcServer(); const cdpBridge = createCdpBridge(); - ipcServer.onMessage((msg, client) => { if (msg.type !== "request") return; @@ -39,7 +37,6 @@ async function main() { }); }); - let idleTimer: ReturnType<typeof setTimeout> | null = null; const resetIdleTimer = (): void => { @@ -60,7 +57,6 @@ async function main() { ipcServer.onConnect(() => { cancelIdleTimer(); }); ipcServer.onDisconnect(() => { resetIdleTimer(); }); - try { await ipcServer.start(); console.log("[pi-browser-daemon] IPC server listening"); @@ -73,7 +69,6 @@ async function main() { resetIdleTimer(); - const shutdown = async () => { console.log("[pi-browser-daemon] Shutting down..."); await cdpBridge.stop(); diff --git a/src/daemon/protocol.ts b/src/daemon/protocol.ts index d3d8297..43c89de 100644 --- a/src/daemon/protocol.ts +++ b/src/daemon/protocol.ts @@ -1,7 +1,5 @@ - import { isRecord } from "../util/guards"; - export type WireRequest = { readonly type: "request"; readonly id: number; @@ -37,7 +35,6 @@ export type WireControl = { export type WireMessage = WireRequest | WireResponse | WireEvent | WireControl; - export const isWireMessage = (v: unknown): v is WireMessage => { if (!isRecord(v)) return false; const t = v["type"]; @@ -85,7 +82,6 @@ export const isWireMessage = (v: unknown): v is WireMessage => { } }; - export const serialize = (msg: WireMessage): string => JSON.stringify(msg); export const deserialize = (line: string): WireMessage | null => { @@ -99,7 +95,6 @@ export const deserialize = (line: string): WireMessage | null => { return parsed; }; - // Windows requires a named pipe (`\\.\pipe\<name>`); a Unix path is not a valid `net` listen/connect target there. export const DAEMON_SOCKET_PATH = process.platform === "win32" diff --git a/src/daemon/server.ts b/src/daemon/server.ts index b694fc0..7c78372 100644 --- a/src/daemon/server.ts +++ b/src/daemon/server.ts @@ -1,4 +1,3 @@ - import { createServer, type Server, type Socket } from "node:net"; import { createInterface, type Interface } from "node:readline"; import { unlinkSync } from "node:fs"; @@ -11,7 +10,6 @@ import { DAEMON_STALE_SOCKET_CLEANUP, } from "./protocol"; - export type ClientSocket = { id: string; readonly socket: Socket; @@ -36,7 +34,6 @@ export type IpcServer = { clientCount(): number; }; - export const createIpcServer = (): IpcServer => { let server: Server | null = null; const sockets = new Map<string, ClientSocket>(); @@ -51,8 +48,7 @@ export const createIpcServer = (): IpcServer => { if (DAEMON_STALE_SOCKET_CLEANUP) { try { unlinkSync(DAEMON_SOCKET_PATH); - } catch { - } + } catch {} } server = createServer({ pauseOnConnect: false }, (socket: Socket) => { @@ -113,8 +109,7 @@ export const createIpcServer = (): IpcServer => { messageHandler?.(msg, currentClient); }); - socket.on("error", () => { - }); + socket.on("error", () => {}); socket.on("close", () => { const found = clients.get(currentClient.id) ?? sockets.get(tempId); @@ -176,8 +171,7 @@ export const createIpcServer = (): IpcServer => { if (!client) return; try { client.socket.write(JSON.stringify(msg) + "\n"); - } catch { - } + } catch {} }, broadcast(msg) { for (const [clientId] of clients) { diff --git a/src/daemon/spawn.ts b/src/daemon/spawn.ts index d14d234..a88855f 100644 --- a/src/daemon/spawn.ts +++ b/src/daemon/spawn.ts @@ -1,4 +1,3 @@ - import { spawn, type ChildProcess } from "node:child_process"; import { access, unlink } from "node:fs/promises"; import { existsSync } from "node:fs"; diff --git a/src/deep-research.ts b/src/deep-research.ts index 5fa596d..9445cf8 100644 --- a/src/deep-research.ts +++ b/src/deep-research.ts @@ -1,7 +1,5 @@ - import type { ExtensionAPI } from "@mariozechner/pi-coding-agent"; - export function buildDeepResearchPrompt(question: string): string { return ( `Do deep research on the following question and produce a cited Markdown report. ` + @@ -11,7 +9,6 @@ export function buildDeepResearchPrompt(question: string): string { ); } - export function registerDeepResearchCommand(pi: ExtensionAPI): void { pi.registerCommand("deep-research", { description: "Research a question on the web and write a cited report", diff --git a/src/domains/readpage/capture.ts b/src/domains/readpage/capture.ts index cf9d055..b0b7ae0 100644 --- a/src/domains/readpage/capture.ts +++ b/src/domains/readpage/capture.ts @@ -1,4 +1,3 @@ - const BODY_TEXT_LIMIT = 20_000; export const buildPageCaptureExpr = (): string => ` diff --git a/src/domains/readpage/readability.ts b/src/domains/readpage/readability.ts index b20cacd..32413e6 100644 --- a/src/domains/readpage/readability.ts +++ b/src/domains/readpage/readability.ts @@ -1,4 +1,3 @@ - export type ContentBlock = { readonly kind: "paragraph" | "heading" | "listitem" | "blockquote" | "other"; readonly text: string; diff --git a/src/domains/search/extract.ts b/src/domains/search/extract.ts index 05ee182..4d9e892 100644 --- a/src/domains/search/extract.ts +++ b/src/domains/search/extract.ts @@ -1,4 +1,3 @@ - const PAGE_TEXT_LIMIT = 4000; export const buildSerpExtractionExpr = (): string => ` diff --git a/src/domains/search/google-serp.ts b/src/domains/search/google-serp.ts index 4b8a319..bfeb1e7 100644 --- a/src/domains/search/google-serp.ts +++ b/src/domains/search/google-serp.ts @@ -1,4 +1,3 @@ - export type SerpAnchor = { readonly href: string; readonly heading: string; diff --git a/src/domains/setup.ts b/src/domains/setup.ts index 21fa3b3..9291431 100644 --- a/src/domains/setup.ts +++ b/src/domains/setup.ts @@ -1,4 +1,3 @@ - import { Type } from "typebox"; import { Text } from "@mariozechner/pi-tui"; import type { Result } from "../util/result"; diff --git a/src/index.ts b/src/index.ts index 7b35f35..e0fa750 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,3 @@ - import type { ExtensionAPI } from "@mariozechner/pi-coding-agent"; import { type BrowserClient, createBrowserClient } from "./client"; import { getBrowserSystemPrompt } from "./prompt"; @@ -119,7 +118,6 @@ export default function browserHarnessExtension(pi: ExtensionAPI): void { client.setProfilePin(profilePin); } - if (!toolsRegistered) { registerAllTools(pi, client); toolsRegistered = true; diff --git a/src/profile/bind.ts b/src/profile/bind.ts index 0909d09..ca745ca 100644 --- a/src/profile/bind.ts +++ b/src/profile/bind.ts @@ -1,4 +1,3 @@ - import type { BrowserClient } from "../client"; import { attachTo } from "../cdp/attach"; import type { ResultOf } from "../cdp/commands"; diff --git a/src/profile/browser-process.ts b/src/profile/browser-process.ts index cbf4d70..3d7bb05 100644 --- a/src/profile/browser-process.ts +++ b/src/profile/browser-process.ts @@ -106,7 +106,6 @@ export const parseUserDataDirFlag = (commandLine: string): string | undefined => return value && value.length > 0 ? value : undefined; }; - const collectLinux = async (): Promise<ReadonlyArray<BrowserCandidate>> => { let pids: string[]; try { @@ -135,8 +134,7 @@ const collectLinux = async (): Promise<ReadonlyArray<BrowserCandidate>> => { let link: string | undefined; try { link = await readlink(`/proc/${pid}/exe`); - } catch { - } + } catch {} // Chrome rewrites its argv to the bare executable path, so argv[0] is the live install location when /proc/<pid>/exe is unreadable or stale. const exePath = (link ? await spawnableExePath(link) : undefined) ?? @@ -150,7 +148,6 @@ const collectLinux = async (): Promise<ReadonlyArray<BrowserCandidate>> => { return candidates; }; - const collectDarwin = async (): Promise<ReadonlyArray<BrowserCandidate>> => { let lines: string[]; try { @@ -175,8 +172,7 @@ const collectDarwin = async (): Promise<ReadonlyArray<BrowserCandidate>> => { try { const { stdout } = await run("ps", ["-ww", "-o", "args=", "-p", pid], { timeout: EXEC_TIMEOUT_MS }); args = stdout.trim(); - } catch { - } + } catch {} if (args && hasChildProcessType(args)) continue; const explicit = args ? parseUserDataDirFlag(args) : undefined; candidates.push({ @@ -187,7 +183,6 @@ const collectDarwin = async (): Promise<ReadonlyArray<BrowserCandidate>> => { return candidates; }; - const POWERSHELL_QUERY = [ "$ErrorActionPreference='SilentlyContinue';", "Get-CimInstance Win32_Process", @@ -232,15 +227,13 @@ const collectWin32 = async (): Promise<ReadonlyArray<BrowserCandidate>> => { if (candidates.length > 0) return candidates; } } - } catch { - } + } catch {} try { const { stdout } = await run("tasklist.exe", [], { timeout: EXEC_TIMEOUT_MS, windowsHide: true }); const lower = stdout.toLowerCase(); if (WIN_IMAGE_NAMES.some((n) => lower.includes(n))) return [{}]; - } catch { - } + } catch {} return []; }; @@ -273,14 +266,12 @@ const winRegistryExecutable = async (): Promise<string | undefined> => { const match = /REG_[A-Z_]+\s+(.+)$/m.exec(stdout.trim()); const path = match?.[1]?.trim(); if (path) return path; - } catch { - } + } catch {} } } return undefined; }; - export const detectRunningBrowser = async (preferUserDataDir?: string): Promise<RunningBrowser> => { const candidates = process.platform === "darwin" @@ -323,8 +314,7 @@ export const resolveBrowserExecutable = async (running?: RunningBrowser): Promis try { await access(candidate); return candidate; - } catch { - } + } catch {} } return undefined; }; diff --git a/src/profile/command.ts b/src/profile/command.ts index d0c36d6..7475924 100644 --- a/src/profile/command.ts +++ b/src/profile/command.ts @@ -1,4 +1,3 @@ - import type { ExtensionAPI, ExtensionContext } from "@mariozechner/pi-coding-agent"; import type { BrowserClient } from "../client"; import { discoverEndpoint } from "../cdp/discovery"; diff --git a/src/profile/list.ts b/src/profile/list.ts index 6429b91..aa3d3e2 100644 --- a/src/profile/list.ts +++ b/src/profile/list.ts @@ -1,4 +1,3 @@ - import { readdir, readFile } from "node:fs/promises"; import { join } from "node:path"; import { Type } from "typebox"; diff --git a/src/profile/paths.ts b/src/profile/paths.ts index 35cbc1f..0a7c74e 100644 --- a/src/profile/paths.ts +++ b/src/profile/paths.ts @@ -3,7 +3,6 @@ import { homedir } from "node:os"; import { join } from "node:path"; - const ENV_AGENT_DIR = "PI_CODING_AGENT_DIR"; // Deliberately mirrors pi's expandTildePath (never `~\…`) rather than improving on it, or the pin lands somewhere pi does not look. @@ -27,7 +26,6 @@ export const agentDir = (): string => { export const pinFilePath = (): string => join(agentDir(), "browser-harness.json"); - const localAppData = (): string => process.env["LOCALAPPDATA"] ?? join(homedir(), "AppData", "Local"); export const userDataDirCandidates = (): ReadonlyArray<string> => { diff --git a/src/setup.ts b/src/setup.ts index d2ab7ac..395fff4 100644 --- a/src/setup.ts +++ b/src/setup.ts @@ -1,4 +1,3 @@ - import type { ExtensionAPI, ExtensionContext } from "@mariozechner/pi-coding-agent"; import type { BrowserClient } from "./client"; import { ensureDaemon } from "./daemon/spawn"; @@ -6,7 +5,6 @@ import { DAEMON_SOCKET_PATH } from "./daemon/protocol"; import { isBrowserRunning } from "./profile/browser-process"; import { promptForProfileIfUnset } from "./profile/command"; - export function registerSetupCommand(pi: ExtensionAPI, client: BrowserClient): void { pi.registerCommand("browser-setup", { description: "Connect pi to your Chrome browser", @@ -21,10 +19,8 @@ export function registerSetupCommand(pi: ExtensionAPI, client: BrowserClient): v }); } - export type SetupResult = { success: true; data: string } | { success: false; error: string }; - export async function performSetup(client: BrowserClient, ctx?: ExtensionContext): Promise<SetupResult> { const chromeRunning = await isBrowserRunning(); if (!chromeRunning) { diff --git a/src/state.ts b/src/state.ts index 05de5d3..71f164b 100644 --- a/src/state.ts +++ b/src/state.ts @@ -1,4 +1,3 @@ - import type { ExtensionAPI, ExtensionContext } from "@mariozechner/pi-coding-agent"; import { asArrayOf, asNumber, asString, isRecord } from "./util/guards"; diff --git a/test/manual/e2e-test.ts b/test/manual/e2e-test.ts index 659409f..81cb4df 100644 --- a/test/manual/e2e-test.ts +++ b/test/manual/e2e-test.ts @@ -34,7 +34,6 @@ async function main() { await ipcServer.start(); console.log("Daemon started ✓"); - console.log("\nConnecting pi client (DaemonTransport)..."); const transport = createDaemonTransport("pi-e2e-test"); @@ -42,7 +41,6 @@ async function main() { check(connectResult.success, `Client connect: ${connectResult.success ? "ok" : connectResult.error.message}`); check(transport.state() === "open", "Transport state is open"); - let rawRequests: WireRequest[] = []; ipcServer.onMessage((msg, client) => { if (msg.type === "request") { diff --git a/test/manual/profile-concurrency-test.ts b/test/manual/profile-concurrency-test.ts index 05e06bc..1a5771d 100644 --- a/test/manual/profile-concurrency-test.ts +++ b/test/manual/profile-concurrency-test.ts @@ -44,8 +44,7 @@ const killTree = (pid: number | undefined): void => { if (process.platform === "win32") { try { execFileSync("taskkill.exe", ["/pid", String(pid), "/T", "/F"], { stdio: "ignore" }); - } catch { - } + } catch {} return; } try { @@ -53,8 +52,7 @@ const killTree = (pid: number | undefined): void => { } catch { try { process.kill(pid, "SIGKILL"); - } catch { - } + } catch {} } }; @@ -81,8 +79,7 @@ async function scenario(exePath: string, label: string, pinned: boolean): Promis try { const res = await fetch(`http://127.0.0.1:${PORT}/json/version`); if (res.ok) endpoint = ((await res.json()) as { webSocketDebuggerUrl: string }).webSocketDebuggerUrl; - } catch { - } + } catch {} } if (!endpoint) { check(false, `${label}: browser exposed its DevTools endpoint`); @@ -144,8 +141,7 @@ async function scenario(exePath: string, label: string, pinned: boolean): Promis killTree(browser.pid); try { rmSync(udd, { recursive: true, force: true, maxRetries: 5, retryDelay: 200 }); - } catch { - } + } catch {} } } diff --git a/test/manual/profile-e2e-test.ts b/test/manual/profile-e2e-test.ts index 6981b7a..e1ab95c 100644 --- a/test/manual/profile-e2e-test.ts +++ b/test/manual/profile-e2e-test.ts @@ -47,8 +47,7 @@ function findBrowser(): string | undefined { try { const resolved = execFileSync("which", [name], { encoding: "utf8" }).trim(); if (resolved) return resolved; - } catch { - } + } catch {} } } return undefined; @@ -96,8 +95,7 @@ async function waitForEndpoint(deadlineMs = 30_000): Promise<boolean> { try { const res = await fetch(`http://127.0.0.1:${PORT}/json/version`); if (res.ok) return true; - } catch { - } + } catch {} await sleep(500); } return false; @@ -132,8 +130,7 @@ async function main(): Promise<void> { if (process.platform === "win32") { try { execFileSync("taskkill.exe", ["/pid", String(browser.pid), "/T", "/F"], { stdio: "ignore" }); - } catch { - } + } catch {} } else { try { // detached:true put the browser in its own process group, so the negative pid signals the whole group. @@ -141,14 +138,12 @@ async function main(): Promise<void> { } catch { try { browser.kill("SIGKILL"); - } catch { - } + } catch {} } } try { rmSync(udd, { recursive: true, force: true, maxRetries: 5, retryDelay: 200 }); - } catch { - } + } catch {} }; try { diff --git a/test/manual/socket-guard-test.ts b/test/manual/socket-guard-test.ts index 1b6c4d7..3664bb4 100644 --- a/test/manual/socket-guard-test.ts +++ b/test/manual/socket-guard-test.ts @@ -1,4 +1,3 @@ - import { access } from "node:fs/promises"; import { setTimeout as sleep } from "node:timers/promises"; import { spawn } from "node:child_process"; |
