From a6ec1d0915106b127affbd6b5fcc9efec48ef712 Mon Sep 17 00:00:00 2001 From: amankumarsingh77 Date: Tue, 28 Jul 2026 20:29:29 +0530 Subject: refactor(profile): strip comment noise Removes module banners and comments restating the code. Keeps one-line notes for the ProcessSingleton user-data-dir rule, the sentinel-URL and async-spawn-error quirks, the replicated getAgentDir, pi's tilde-expansion mirroring, the Windows wmic removal, the macOS/Linux process-identification quirks, the picker's undefined-means-cancel contract, and the deliberately unpersisted browserContextId. Co-Authored-By: Claude Opus 5 (1M context) --- src/profile/paths.ts | 65 ++-------------------------------------------------- 1 file changed, 2 insertions(+), 63 deletions(-) (limited to 'src/profile/paths.ts') diff --git a/src/profile/paths.ts b/src/profile/paths.ts index 095687e..35cbc1f 100644 --- a/src/profile/paths.ts +++ b/src/profile/paths.ts @@ -1,92 +1,39 @@ -/** - * Filesystem locations for browser profile discovery and pin persistence. - * - * Two independent path families live here: - * - * 1. Chromium user-data-dir candidates, per platform and channel. A - * user-data-dir holds `Local State` (the profile registry) and - * `DevToolsActivePort`; individual profiles are subdirectories of it - * (`Default`, `Profile 1`, …). - * Reference: https://chromium.googlesource.com/chromium/src/+/HEAD/docs/user_data_dir.md - * - * 2. pi's agent config dir, where the profile pin is stored. - * - * On the agent dir: pi exports `getAgentDir()` from - * `@mariozechner/pi-coding-agent`, but importing it would be a RUNTIME import - * of the host package. Extensions installed via `pi install npm:...` do not - * get pi resolvable from their own node_modules (verified: the installed - * tree's `@mariozechner/` directory is empty), which is why every other import - * in this codebase is `import type` and erased at build time. So the three - * lines of `getAgentDir()` are replicated here instead — env var first, then - * `~/.pi/agent` (pi's dist/config.js: `PI_CODING_AGENT_DIR`, CONFIG_DIR_NAME - * `.pi`). - */ +// pi's `getAgentDir()` is replicated rather than imported: a runtime import of the host package does not resolve for extensions installed via `pi install npm:...`. import { homedir } from "node:os"; import { join } from "node:path"; -// ── pi agent config dir ──────────────────────────────────────────────────── -/** pi's env override for the agent dir (APP_NAME.toUpperCase() + "_CODING_AGENT_DIR"). */ const ENV_AGENT_DIR = "PI_CODING_AGENT_DIR"; -/** - * Expand a leading `~` exactly as pi's expandTildePath does — `~` and `~/…` - * only, never `~\…`, on every platform. This deliberately mirrors pi rather - * than improving on it: the pin has to land in the directory pi itself resolves - * from the same variable, so being more lenient here would put the file - * somewhere pi does not look. - */ +// Deliberately mirrors pi's expandTildePath (never `~\…`) rather than improving on it, or the pin lands somewhere pi does not look. const expandTildePiCompatible = (path: string): string => { if (path === "~") return homedir(); if (path.startsWith("~/")) return homedir() + path.slice(1); return path; }; -/** - * Tilde expansion for values this package interprets on its own. Windows users - * write `~\dir` as naturally as `~/dir`, and no compatibility constraint - * applies, so both are accepted. - */ const expandTildeLenient = (path: string): string => { if (path === "~") return homedir(); if (path.startsWith("~/") || path.startsWith("~\\")) return join(homedir(), path.slice(2)); return path; }; -/** pi's agent config directory — `$PI_CODING_AGENT_DIR` or `~/.pi/agent`. */ export const agentDir = (): string => { const fromEnv = process.env[ENV_AGENT_DIR]; if (fromEnv) return expandTildePiCompatible(fromEnv); return join(homedir(), ".pi", "agent"); }; -/** Where the selected-profile pin is persisted. */ export const pinFilePath = (): string => join(agentDir(), "browser-harness.json"); -// ── Chromium user-data-dir candidates ────────────────────────────────────── -/** - * Windows resolves its per-user data root from %LOCALAPPDATA%, which can be - * redirected on roaming / managed accounts. Fall back to the conventional - * layout only when the variable is absent. - */ const localAppData = (): string => process.env["LOCALAPPDATA"] ?? join(homedir(), "AppData", "Local"); -/** - * Every known default user-data-dir for Chromium-family browsers on the - * current platform. Order is stable but carries no priority — callers probe - * all of them. - * - * Includes paths the harness previously missed: snap Chromium (the default - * Chromium on Ubuntu) and the Linux-only `$CHROME_USER_DATA_DIR` override - * documented in user_data_dir.md. - */ export const userDataDirCandidates = (): ReadonlyArray => { const home = homedir(); const dirs: string[] = []; - // A user-set override wins a spot at the front regardless of platform. const envOverride = process.env["CHROME_USER_DATA_DIR"]; if (envOverride) dirs.push(expandTildeLenient(envOverride)); @@ -135,9 +82,7 @@ export const userDataDirCandidates = (): ReadonlyArray => { join(home, ".config/microsoft-edge"), join(home, ".config/microsoft-edge-beta"), join(home, ".config/microsoft-edge-dev"), - // snap (Ubuntu's default Chromium) — confined to ~/snap//common join(home, "snap/chromium/common/chromium"), - // flatpak join(home, ".var/app/org.chromium.Chromium/config/chromium"), join(home, ".var/app/com.google.Chrome/config/google-chrome"), join(home, ".var/app/com.brave.Browser/config/BraveSoftware/Brave-Browser"), @@ -145,15 +90,9 @@ export const userDataDirCandidates = (): ReadonlyArray => { ); } - // De-duplicate while preserving order — an env override may repeat a default. return Array.from(new Set(dirs)); }; -/** - * Human-readable browser name for a user-data-dir, used to disambiguate the - * picker when more than one browser is installed. Falls back to the directory - * name, which is already descriptive for every path we generate. - */ export const browserNameForUserDataDir = (userDataDir: string): string => { const p = userDataDir.replace(/\\/g, "/"); const has = (needle: string): boolean => p.toLowerCase().includes(needle); -- cgit v1.2.3