From b484c017807acb902eaaaa4e242f8b79f8e8eba6 Mon Sep 17 00:00:00 2001 From: amankumarsingh77 Date: Tue, 28 Jul 2026 22:29:16 +0530 Subject: refactor: act on the fallow audit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- src/cdp/console-buffer.ts | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) (limited to 'src/cdp/console-buffer.ts') diff --git a/src/cdp/console-buffer.ts b/src/cdp/console-buffer.ts index 53dd6c2..9718603 100644 --- a/src/cdp/console-buffer.ts +++ b/src/cdp/console-buffer.ts @@ -1,4 +1,5 @@ import { decodeEvent } from "./events"; +import { createRecordStore } from "./record-store"; export type ConsoleLevel = "log" | "info" | "warn" | "error" | "debug"; @@ -111,21 +112,10 @@ const formatStackTrace = ( }; export const createConsoleBuffer = (capacity = 500): ConsoleBuffer => { - const records = new Map(); + const records = createRecordStore(capacity); let nextSeq = 1; - let overflowed = false; - - const evictOldestIfFull = (): void => { - while (records.size >= capacity) { - const oldest = records.keys().next(); - if (oldest.done) return; - records.delete(oldest.value); - overflowed = true; - } - }; const insert = (rec: ConsoleRecord): void => { - evictOldestIfFull(); records.set(rec.seq, rec); }; @@ -187,20 +177,12 @@ export const createConsoleBuffer = (capacity = 500): ConsoleBuffer => { matched.push({ ...r }); } - const total = matched.length; - const limit = Math.min(filter.limit ?? 50, 500); - const limited = matched.slice(-limit); - - const bufferOverflowed = overflowed; - overflowed = false; - - return { records: limited, total, bufferOverflowed }; + return records.page(matched, filter.limit); }, clear() { records.clear(); nextSeq = 1; - overflowed = false; }, }; }; -- cgit v1.2.3