From dcb79fc62bdd4d9ec0cbdb2c97d3eb2b2dacdf22 Mon Sep 17 00:00:00 2001 From: amankumarsingh77 Date: Tue, 28 Jul 2026 22:41:18 +0530 Subject: refactor: merge nine files whose reason to exist was gone MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit src/ goes from 84 files to 75 at the same line count — every merge below had exactly one consumer. cdp/event-queue.ts and cdp/pending-requests.ts become daemon/queue.ts. I split these in the daemon-internals commit on the grounds that they held two unrelated concerns, but the transport commit had already deleted the second transport, so both halves had one consumer and the split bought nothing. They also sat in cdp/ while only daemon/ used them. cdp/transport.ts held only the CdpTransport interface after the second transport went; five of its six consumers import it type-only, so it moves to cdp/types.ts. cdp/evaluate.ts moves into cdp/session.ts rather than into its lone consumer isolated-tab.ts — it reaches session.call directly, so under src/domains/ it would trip the raw-cdp-call rule. util/keycodes.ts and util/time.ts fold into their only callers (keyboard.ts, page.ts); util/bytes.ts into util/truncate.ts, which already owns output-size formatting; readpage/capture.ts and search/extract.ts into the tools beside them; profile/picker.ts into profile/command.ts. Kept deliberately: mutex.ts and domains/target.ts each have their own test suite, and folding target.ts into click.ts would make a tool file export a helper. sharp-shim.ts is an isolation boundary carrying two allowlisted casts. result.ts, guards.ts, js-template.ts and paths.ts are small but have 44, 12, 8 and 3 consumers. Co-Authored-By: Claude Opus 5 (1M context) --- src/profile/command.ts | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-- src/profile/picker.ts | 50 -------------------------------------------------- 2 files changed, 48 insertions(+), 52 deletions(-) delete mode 100644 src/profile/picker.ts (limited to 'src/profile') diff --git a/src/profile/command.ts b/src/profile/command.ts index 0703ae8..270b42f 100644 --- a/src/profile/command.ts +++ b/src/profile/command.ts @@ -4,8 +4,54 @@ import { discoverEndpoint } from "../cdp/discovery"; import { type Result, err, ok } from "../util/result"; import { type BrowserProfile, listProfiles } from "./list"; import { browserNameForUserDataDir, userDataDirCandidates } from "./paths"; -import { pinFor, promptForProfile } from "./picker"; -import { clearPin, readPin, writePin } from "./store"; +import { clearPin, type ProfilePin, readPin, writePin } from "./store"; + +// `ctx.ui.select` resolves to undefined both on Escape and in non-interactive modes, so "no answer" must mean "change nothing". + +const CLEAR_SELECTION_LABEL = "— Clear selection (use whichever window is focused) —"; + +type ProfileChoice = + | { readonly kind: "profile"; readonly profile: BrowserProfile } + | { readonly kind: "clear" } + | { readonly kind: "cancelled" }; + +const disambiguate = (profiles: ReadonlyArray): ReadonlyArray => { + const counts = new Map(); + for (const p of profiles) counts.set(p.label, (counts.get(p.label) ?? 0) + 1); + return profiles.map((p) => ((counts.get(p.label) ?? 0) > 1 ? `${p.label} [${p.dir}]` : p.label)); +}; + +const promptForProfile = async ( + ctx: ExtensionContext, + profiles: ReadonlyArray, + currentPin: ProfilePin | null, + title = "Select browser profile", +): Promise => { + if (!ctx.hasUI || profiles.length === 0) return { kind: "cancelled" }; + + const labels = disambiguate(profiles); + const rows = labels.map((label, i) => { + const isPinned = currentPin?.profileDir === profiles[i]?.dir; + return isPinned ? `✓ ${label}` : ` ${label}`; + }); + const options = [...rows, CLEAR_SELECTION_LABEL]; + + const answer = await ctx.ui.select(title, options); + if (answer === undefined) return { kind: "cancelled" }; + if (answer === CLEAR_SELECTION_LABEL) return { kind: "clear" }; + + const index = options.indexOf(answer); + const profile = index >= 0 ? profiles[index] : undefined; + if (!profile) return { kind: "cancelled" }; + return { kind: "profile", profile }; +}; + +const pinFor = (userDataDir: string, profile: BrowserProfile): ProfilePin => ({ + userDataDir, + profileDir: profile.dir, + label: profile.label, + savedAt: new Date().toISOString(), +}); const resolveUserDataDir = async (client: BrowserClient): Promise> => { const connected = client.userDataDir(); diff --git a/src/profile/picker.ts b/src/profile/picker.ts deleted file mode 100644 index ede43a6..0000000 --- a/src/profile/picker.ts +++ /dev/null @@ -1,50 +0,0 @@ -// `ctx.ui.select` resolves to undefined both on Escape and in non-interactive modes, so "no answer" must mean "change nothing". - -import type { ExtensionContext } from "@mariozechner/pi-coding-agent"; -import type { BrowserProfile } from "./list"; -import type { ProfilePin } from "./store"; - -const CLEAR_SELECTION_LABEL = "— Clear selection (use whichever window is focused) —"; - -export type ProfileChoice = - | { readonly kind: "profile"; readonly profile: BrowserProfile } - | { readonly kind: "clear" } - | { readonly kind: "cancelled" }; - -const disambiguate = (profiles: ReadonlyArray): ReadonlyArray => { - const counts = new Map(); - for (const p of profiles) counts.set(p.label, (counts.get(p.label) ?? 0) + 1); - return profiles.map((p) => ((counts.get(p.label) ?? 0) > 1 ? `${p.label} [${p.dir}]` : p.label)); -}; - -export const promptForProfile = async ( - ctx: ExtensionContext, - profiles: ReadonlyArray, - currentPin: ProfilePin | null, - title = "Select browser profile", -): Promise => { - if (!ctx.hasUI || profiles.length === 0) return { kind: "cancelled" }; - - const labels = disambiguate(profiles); - const rows = labels.map((label, i) => { - const isPinned = currentPin?.profileDir === profiles[i]?.dir; - return isPinned ? `✓ ${label}` : ` ${label}`; - }); - const options = [...rows, CLEAR_SELECTION_LABEL]; - - const answer = await ctx.ui.select(title, options); - if (answer === undefined) return { kind: "cancelled" }; - if (answer === CLEAR_SELECTION_LABEL) return { kind: "clear" }; - - const index = options.indexOf(answer); - const profile = index >= 0 ? profiles[index] : undefined; - if (!profile) return { kind: "cancelled" }; - return { kind: "profile", profile }; -}; - -export const pinFor = (userDataDir: string, profile: BrowserProfile): ProfilePin => ({ - userDataDir, - profileDir: profile.dir, - label: profile.label, - savedAt: new Date().toISOString(), -}); -- cgit v1.2.3