From b67faca60b21b0cf74d5c967f0f8d215ad601e93 Mon Sep 17 00:00:00 2001 From: amankumarsingh77 Date: Tue, 28 Jul 2026 20:30:49 +0530 Subject: refactor(domains): strip comment noise Removes module banners, step markers, and comments restating the code. Keeps one-line notes for safeJs's trust boundary, the select-match null sentinels, the TUI width clamp, the single-window tab rule, the input synthesis quirks (char events, keyCode, mousemove, focus, compositor), the stale AX value, ignored-wrapper recursion, and isolated-tab routing. Co-Authored-By: Claude Opus 5 (1M context) --- src/domains/click.ts | 4 +-- src/domains/console.ts | 2 +- src/domains/drag.ts | 1 - src/domains/files.ts | 3 -- src/domains/form.ts | 15 +--------- src/domains/isolated-tab.ts | 24 +-------------- src/domains/js.ts | 17 ++--------- src/domains/keyboard.ts | 10 ++----- src/domains/navigate.ts | 17 ++--------- src/domains/network.ts | 3 +- src/domains/readpage/capture.ts | 11 ------- src/domains/readpage/readability.ts | 23 --------------- src/domains/ref-resolve.ts | 30 ------------------- src/domains/render.ts | 17 ----------- src/domains/screenshot.ts | 6 +--- src/domains/scroll.ts | 7 ++--- src/domains/search/extract.ts | 15 ---------- src/domains/search/google-serp.ts | 28 ------------------ src/domains/setup.ts | 10 ------- src/domains/snapshot.ts | 58 ++----------------------------------- src/domains/tabs.ts | 2 -- 21 files changed, 18 insertions(+), 285 deletions(-) (limited to 'src') diff --git a/src/domains/click.ts b/src/domains/click.ts index 0215d9a..cb4b007 100644 --- a/src/domains/click.ts +++ b/src/domains/click.ts @@ -36,9 +36,7 @@ const dispatchClick = async ( button: "left" | "right" | "middle", count: number, ): Promise> => { - // Move the pointer to the target first. Some focus/hover handlers (and React - // synthetic events) only fire when a mousemove precedes the press, so without - // it a click can land without focusing the element. + // Some focus/hover handlers and React synthetic events only fire when a mousemove precedes the press, so without it a click lands without focusing. const moved = await cdpCall(client, "Input.dispatchMouseEvent", { type: "mouseMoved", x, y }); if (!moved.success) return moved; const pressed = await cdpCall(client, "Input.dispatchMouseEvent", { diff --git a/src/domains/console.ts b/src/domains/console.ts index c38da2a..7809f77 100644 --- a/src/domains/console.ts +++ b/src/domains/console.ts @@ -182,7 +182,7 @@ export const consoleTool = defineBrowserTool({ const text = renderConsoleMarkdown(drained.records, { total: drained.total, bufferOverflowed: drained.bufferOverflowed, - expanded: true, // full text always returned to the LLM; renderResult handles compact view for humans + expanded: true, nextCursor, }); const trunc = await applyTruncation(text, "console"); diff --git a/src/domains/drag.ts b/src/domains/drag.ts index 49a5a58..34a0154 100644 --- a/src/domains/drag.ts +++ b/src/domains/drag.ts @@ -40,7 +40,6 @@ export const dragAndDropTool = defineBrowserTool({ const calls: ReadonlyArray = [ ["Input.dispatchMouseEvent", { type: "mousePressed", x: args.startX, y: args.startY, button: "left", clickCount: 1 }], ["Input.dispatchDragEvent", { type: "dragEnter", x: args.startX, y: args.startY, data, modifiers: 0 }], - // 5 interpolated dragOver steps from start → end so the page sees a smooth drag. ...Array.from({ length: 5 }, (_, i): InputCall => { const t = (i + 1) / 5; return [ diff --git a/src/domains/files.ts b/src/domains/files.ts index ebc5a83..534a674 100644 --- a/src/domains/files.ts +++ b/src/domains/files.ts @@ -17,8 +17,6 @@ const UploadArgs = Type.Object({ filePath: Type.String({ description: "Absolute path to the file to upload" }), }); -// Ref path: set files directly on the resolved backendNodeId via CDP — simplest -// and most reliable, no selector needed. const tryRefUpload = async ( client: BrowserClient, backendId: number, @@ -115,7 +113,6 @@ export const uploadFileTool = defineBrowserTool({ const readable = await verifyReadable(args.filePath); if (!readable.success) return readable; - // Ref path: resolve to backendNodeId and set files directly via CDP. if (args.ref !== undefined) { const backendId = resolveRefToBackendId(client, args.ref); if (!backendId.success) return backendId; diff --git a/src/domains/form.ts b/src/domains/form.ts index 78e3db1..b97b22d 100644 --- a/src/domains/form.ts +++ b/src/domains/form.ts @@ -18,16 +18,6 @@ const FillArgs = Type.Object({ value: Type.String({ description: "Value to set in the field" }), }); -/** - * Run an element-scoped function either against a CSS selector (querySelector + - * apply) or a ref (resolve to objectId, callFunctionOn with element as `this`). - * The shared `fnBody` is a function body where `this` is the target element and - * the single argument is the value — identical logic on both paths. Returns the - * function's return value (parsed) or a ToolErr. - * - * On the ref path a detached node yields a stale-ref error; on the selector path - * a missing element returns { status: "not_found" } from the function body. - */ const runOnElement = async ( client: BrowserClient, opts: { @@ -60,9 +50,7 @@ const runOnElement = async ( if (opts.selector === undefined) { return err({ kind: "invalid_state", message: "Provide either `ref` or `selector`." }); } - // Selector path: bind the same trusted function body to the matched element - // via .call(). fnBody is harness-authored (not user input); only the selector - // and value are interpolated, and those go through safeJs. + // fnBody is harness-authored, not user input; only the selector and value are interpolated, and those go through safeJs. const prelude = safeJs` (() => { const el = document.querySelector(${opts.selector}); @@ -232,7 +220,6 @@ const isSelectResult = (v: unknown): v is SelectResult => { return false; }; -// `this` is the