aboutsummaryrefslogtreecommitdiff
path: root/src/profile/store.ts
diff options
context:
space:
mode:
authoramankumarsingh77 <amankumarsingh7702@gmail.com>2026-07-28 20:29:29 +0530
committerAman Kumar <145339995+amankumarsingh77@users.noreply.github.com>2026-08-02 19:12:46 +0530
commita6ec1d0915106b127affbd6b5fcc9efec48ef712 (patch)
tree120b16ede45c1c8863291d3c7f139449c5638b28 /src/profile/store.ts
parenta2588bb315a56a8dfcd3aa8a261cdc19b160d079 (diff)
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) <noreply@anthropic.com>
Diffstat (limited to 'src/profile/store.ts')
-rw-r--r--src/profile/store.ts32
1 files changed, 1 insertions, 31 deletions
diff --git a/src/profile/store.ts b/src/profile/store.ts
index e38ff2e..6e1b342 100644
--- a/src/profile/store.ts
+++ b/src/profile/store.ts
@@ -1,19 +1,4 @@
-/**
- * Durable persistence for the selected browser profile.
- *
- * The pin must outlive session termination, so it cannot live in pi's session
- * entries (`pi.appendEntry`, see src/state.ts) — those die with the session.
- * It is a small JSON file in pi's agent config dir instead, shared by every
- * project on the machine.
- *
- * The pin deliberately stores only `{ userDataDir, profileDir }`. A
- * `browserContextId` is NOT persisted: Chrome mints fresh context ids on every
- * browser run, so a stored one would be a stale pointer at best and a pointer
- * into the wrong profile at worst. The context is re-resolved on each connect.
- *
- * Every read failure degrades to "no pin" rather than throwing — a corrupt
- * file must never break browser control.
- */
+// A `browserContextId` is deliberately NOT persisted: Chrome mints fresh context ids per browser run, so a stored one could point into the wrong profile.
import { mkdir, readFile, rename, unlink, writeFile } from "node:fs/promises";
import { randomUUID } from "node:crypto";
@@ -25,13 +10,9 @@ import { type Result, err, ok } from "../util/result";
import { pinFilePath } from "./paths";
export type ProfilePin = {
- /** User-data-dir the profile belongs to — guards against browser switches. */
readonly userDataDir: string;
- /** Profile subdirectory, e.g. "Profile 1". */
readonly profileDir: string;
- /** Label captured at selection time, for display without a disk re-read. */
readonly label: string;
- /** ISO timestamp of the selection. */
readonly savedAt: string;
};
@@ -63,11 +44,6 @@ const PinFileSchema = Type.Object(
const pinFileValidator = Compile(PinFileSchema);
-/**
- * The persisted pin, or null when nothing is pinned, the file is missing, or
- * it cannot be parsed. A file written by a newer version is treated as "no
- * pin" rather than guessed at.
- */
export const readPin = async (): Promise<ProfilePin | null> => {
let raw: string;
try {
@@ -88,10 +64,6 @@ export const readPin = async (): Promise<ProfilePin | null> => {
};
};
-/**
- * Replace the pin atomically: a sibling temp file plus rename, so a crash
- * mid-write can never leave a half-written pin behind.
- */
const writePinFile = async (profile: ProfilePin | null): Promise<Result<void, string>> => {
const target = pinFilePath();
const tmp = `${target}.${randomUUID()}.tmp`;
@@ -107,8 +79,6 @@ const writePinFile = async (profile: ProfilePin | null): Promise<Result<void, st
}
};
-/** Persist the selected profile. */
export const writePin = (pin: ProfilePin): Promise<Result<void, string>> => writePinFile(pin);
-/** Clear the selection, restoring the harness's unpinned behavior. */
export const clearPin = (): Promise<Result<void, string>> => writePinFile(null);