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/js.ts | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) (limited to 'src/domains/js.ts') diff --git a/src/domains/js.ts b/src/domains/js.ts index 6d9ace0..a64b4ac 100644 --- a/src/domains/js.ts +++ b/src/domains/js.ts @@ -18,17 +18,10 @@ const formatBytes = (n: number): string => { return `${n} B`; }; -// AsyncFunction constructor — the documented Node.js mechanism for compiling -// arbitrary user-supplied source. Equivalent to `new Function` but produces an -// async function we can `await`. The full RCE risk is contained at the source -// boundary: see the path allowlist + timeout below. A plain `unknown` cast -// would lose the constructor signature; we keep this single typed cast. +// The AsyncFunction constructor is the documented way to compile user source; a plain `unknown` cast would lose the constructor signature, so this typed cast stays. const AsyncFunction = Object.getPrototypeOf(async () => {}).constructor as new (...args: ReadonlyArray) => (...args: ReadonlyArray) => Promise; -// ESNext module — bare `require` is not in scope. createRequire provides the -// CJS resolver anchored to this file's URL so scripts can require() builtins -// and installed CJS packages. const requireFromHere = createRequire(import.meta.url); const ExecuteJsArgs = Type.Object({ @@ -58,8 +51,6 @@ export const executeJsTool = defineBrowserTool({ if (!r.success) return err({ kind: "cdp_error", message: r.error.message }); const valueStr = r.data === undefined ? "undefined" : JSON.stringify(r.data); const truncated = await applyTruncation(valueStr, "js"); - // If the value is JSON, pretty-print for the expanded TUI view. Falls back - // to the raw string if parse fails (e.g. value is "undefined" sentinel). let pretty: string | undefined; try { const parsed: unknown = JSON.parse(valueStr); @@ -71,8 +62,6 @@ export const executeJsTool = defineBrowserTool({ text: truncated.text, details: { valueLength: valueStr.length, - // Full value for the expanded renderer. Capped at 200 KB so a giant - // dump doesn't bloat the conversation transcript on disk. full: valueStr.length > 200_000 ? valueStr.slice(0, 200_000) : valueStr, ...(pretty !== undefined ? { pretty: pretty.length > 200_000 ? pretty.slice(0, 200_000) : pretty } : {}), ...(truncated.fullOutputPath !== undefined ? { fullOutputPath: truncated.fullOutputPath } : {}), @@ -210,7 +199,7 @@ export const runScriptTool = defineBrowserTool({ try { const scriptPromise = executeFn( args.params ?? {}, - client, // bound as `daemon` — name preserved for back-compat + client, requireFromHere, ac.signal, (u: unknown) => { @@ -221,7 +210,7 @@ export const runScriptTool = defineBrowserTool({ if (!isRecord(first)) return; const txt = first["text"]; if (typeof txt !== "string") return; - try { onUpdate({ text: txt }); } catch { /* swallow */ } + try { onUpdate({ text: txt }); } catch {} }, extensionCtx ?? { cwd: process.cwd() }, console, fetch, JSON, Buffer, setTimeout, clearTimeout, -- cgit v1.2.3