From 63b16957587fe20566129ffc5191f66f24a70872 Mon Sep 17 00:00:00 2001 From: amankumarsingh77 Date: Wed, 29 Apr 2026 01:38:17 +0530 Subject: Replace socket daemon with direct CDP WebSocket connection Drops the Unix socket subprocess in favor of talking CDP directly over WebSocket from the extension. Removes the protocol's send/health helpers, simplifies setup to just verifying Chrome's remote debugging port, and tightens types in dynamic-tools. Bumps Node engine to >=22 and adds the ws dependency. --- src/setup.ts | 113 +++++++++-------------------------------------------------- 1 file changed, 16 insertions(+), 97 deletions(-) (limited to 'src/setup.ts') diff --git a/src/setup.ts b/src/setup.ts index 839a540..f99e9d9 100644 --- a/src/setup.ts +++ b/src/setup.ts @@ -1,18 +1,15 @@ /** - * Setup command — guides the user through installing and connecting - * browser-harness to their Chrome browser. + * Setup command — verifies Chrome is running with remote debugging + * and connects the pi agent to it. */ import type { ExtensionAPI, ExtensionContext } from "@mariozechner/pi-coding-agent"; import { execSync } from "node:child_process"; -import { existsSync } from "node:fs"; -import { homedir } from "node:os"; -import { join } from "node:path"; import type { BrowserDaemon } from "./daemon"; export function registerSetupCommand(pi: ExtensionAPI, daemon: BrowserDaemon): void { pi.registerCommand("browser-setup", { - description: "Install and connect browser-harness to Chrome", + description: "Connect pi to your Chrome browser", handler: async (_args, ctx) => { await runSetup(ctx, daemon); }, @@ -20,30 +17,9 @@ export function registerSetupCommand(pi: ExtensionAPI, daemon: BrowserDaemon): v } async function runSetup(ctx: ExtensionContext, daemon: BrowserDaemon): Promise { - ctx.ui.notify("browser-harness setup: checking installation...", "info"); + ctx.ui.notify("browser setup: checking Chrome...", "info"); - // Step 1: Check for browser-harness installation - const bhInstalled = await checkBrowserHarnessInstalled(); - if (!bhInstalled) { - ctx.ui.notify( - "browser-harness not found. Installing...", - "warning", - ); - const installed = await installBrowserHarness(ctx); - if (!installed) { - ctx.ui.notify( - "Installation failed. Please install manually:\n" + - " git clone https://github.com/browser-use/browser-harness ~/Developer/browser-harness\n" + - " cd ~/Developer/browser-harness && uv sync", - "error", - ); - return; - } - } - - ctx.ui.notify("browser-harness found ✓", "info"); - - // Step 2: Check Chrome is running + // Step 1: Check Chrome is running const chromeRunning = checkChromeRunning(); if (!chromeRunning) { ctx.ui.notify( @@ -54,23 +30,26 @@ async function runSetup(ctx: ExtensionContext, daemon: BrowserDaemon): Promise { - const searchPaths = [ - join(homedir(), "Developer", "browser-harness"), - join(homedir(), "src", "browser-harness"), - join(homedir(), "browser-harness"), - join(homedir(), "dev", "browser-harness"), - join(homedir(), "Projects", "browser-harness"), - process.cwd(), - ]; - - for (const dir of searchPaths) { - if ( - existsSync(join(dir, "daemon.py")) && - existsSync(join(dir, "helpers.py")) - ) { - return true; - } - } - - // Check if uv tool is installed globally - try { - execSync("uv tool list 2>/dev/null | grep browser-harness", { timeout: 5000 }); - return true; - } catch { - // not found via uv - } - - return false; -} - -async function installBrowserHarness(ctx: ExtensionContext): Promise { - // Try uv tool install - try { - ctx.ui.notify("Installing browser-harness via uv...", "info"); - execSync("uv tool install browser-harness", { - timeout: 60_000, - stdio: "pipe", - }); - return true; - } catch { - // uv install failed - } - - // Try git clone - try { - const targetDir = join(homedir(), "Developer", "browser-harness"); - ctx.ui.notify(`Cloning browser-harness to ${targetDir}...`, "info"); - execSync( - `git clone https://github.com/browser-use/browser-harness "${targetDir}"`, - { timeout: 30_000, stdio: "pipe" }, - ); - execSync("uv sync", { cwd: targetDir, timeout: 60_000, stdio: "pipe" }); - return true; - } catch { - return false; - } -} - function checkChromeRunning(): boolean { try { if (process.platform === "darwin" || process.platform === "linux") { -- cgit v1.2.3