aboutsummaryrefslogtreecommitdiff
path: root/src/domains/js.ts
diff options
context:
space:
mode:
authoramankumarsingh77 <amankumarsingh7702@gmail.com>2026-07-28 22:29:16 +0530
committerAman Kumar <145339995+amankumarsingh77@users.noreply.github.com>2026-08-02 19:12:46 +0530
commitb484c017807acb902eaaaa4e242f8b79f8e8eba6 (patch)
tree4bd58916c7642e8211b4b86ab6162aa5c7a202d2 /src/domains/js.ts
parent1b5c4240a5e679a322f636098a4b370cac084875 (diff)
refactor: act on the fallow audit
Unused exports it found that my own sweep missed, because I had grepped by name and these names occur as local variables elsewhere: deadline and the Deadline type in util/time.ts were genuinely unreferenced and are gone; isWireMessage, resolveUserDataDir, CLEAR_SELECTION_LABEL and the ExpandableText type are used only inside their own file and no longer export. isWireMessage became internal when server.ts moved to the shared serialize/deserialize codec. Duplication: console-buffer and network-buffer were the same capacity-bounded map with an overflow flag, sharing eviction, the drain tail and clear() across three clone groups. That is now cdp/record-store.ts, with tests — neither buffer had any. The three Network follow-up events also repeated the same decode-and-find preamble; one `update` helper covers them, and drops the redundant optional chaining that survived a `!id` guard. formatBytes existed verbatim in js.ts and network.ts; it is now util/bytes.ts. Duplication overall: 2.7% to 2.0%, and none of the remainder is in src. .fallowrc.json records the two entry points the tool cannot infer — the pi extension (declared under pi.extensions) and the daemon (spawned by path) — without which five reachable files read as dead. sharp is ignored because it is loaded through a variable specifier in a dynamic import so it can stay optional. agentDir is exported solely for a test's dynamic import, so it is suppressed by name rather than globally enabling ignoreExportsUsedInFile, which would have hidden four of the five findings above. Not acted on: the "split high-impact file" suggestions for session.ts, client.ts and ref-resolve.ts (119 LOC) are size and fan-in heuristics with no defect behind them, and splitting them would add the indirection this refactor set out to remove. The claim that state.ts is 100% dead is an artifact of the missing entry point. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'src/domains/js.ts')
-rw-r--r--src/domains/js.ts7
1 files changed, 1 insertions, 6 deletions
diff --git a/src/domains/js.ts b/src/domains/js.ts
index b43387c..d2588d0 100644
--- a/src/domains/js.ts
+++ b/src/domains/js.ts
@@ -6,6 +6,7 @@ import { Type } from "typebox";
import { Markdown, Text } from "@mariozechner/pi-tui";
import { getMarkdownTheme, keyHint } from "@mariozechner/pi-coding-agent";
import { type Result, err, ok } from "../util/result";
+import { formatBytes } from "../util/bytes";
import { defineBrowserTool, type ToolErr, type ToolOk } from "../util/tool";
import { evalJs } from "./cdp-call";
import { applyTruncation } from "../util/truncate";
@@ -13,12 +14,6 @@ import { asNumber, asRecord, asString, isRecord } from "../util/guards";
const COMPACT_PREVIEW_BYTES = 120;
-const formatBytes = (n: number): string => {
- if (n >= 1_048_576) return `${(n / 1_048_576).toFixed(1)} MB`;
- if (n >= 1024) return `${(n / 1024).toFixed(1)} KB`;
- return `${n} B`;
-};
-
// 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<string>) => (...args: ReadonlyArray<unknown>) => Promise<unknown>;