An agentic browser harness: an AI side panel & orb in your own logged-in Chrome, Edge, Arc, Brave or even Firefox run by the agent/subscription you already use (Claude Code, Codex, Antigravity). Free, open source, no API key. Also an MCP server.
TypeScript agentic-browseragentic-browsingagy-cliaiai-agentai-browser-extensionai-toolsbrave-extensionbrowser-agentbrowser-automationbrowser-extensionbrowser-usebrowserskillchrome-extensionclaude-codecodexfirefox-addonmcp-servernanobrowserweb-automation
fix(cli): uninstall goes on past a file Windows will not delete, so the pairing keys still go, and leaves the Node it runs on where the app keeps it
Shahriar5e9f9803db5b
diff --git a/src/daemon/cli.ts b/src/daemon/cli.tsindex 5c26243..e5ea6e5 100644--- a/src/daemon/cli.ts+++ b/src/daemon/cli.ts@@ -729,6 +729,7 @@ async function uninstall(argv: string[]): Promise<void> {for (const removal of plan.removals) {console.log(` ${removal.label.padEnd(11)} ${removal.path}`);console.log(` ${removal.holds}${removal.keep ? ' — keeping skills/' : ''}`);+ if (removal.inUse) console.log(` keeping ${removal.inUse}/, which holds the Node this runs on`);}for (const entry of plan.npx) {const running = entry.running ? ', the copy running right now' : '';@@ -794,7 +795,7 @@ async function uninstall(argv: string[]): Promise<void> {for (const outcome of removeAll(plan.removals)) {if (!outcome.removed) console.log(` ✗ ${outcome.removal.path} — ${outcome.error}`);- else if (outcome.kept.length) console.log(` ✓ Emptied ${outcome.removal.path} — kept ${outcome.kept.join(', ')}/`);+ else if (outcome.kept.length) console.log(` ✓ Emptied ${outcome.removal.path} — kept ${outcome.kept.map((entry) => `${entry}/`).join(', ')}`);else console.log(` ✓ Removed ${outcome.removal.path}`);}diff --git a/src/daemon/uninstall.test.ts b/src/daemon/uninstall.test.tsindex 5bc387d..45dbf0a 100644--- a/src/daemon/uninstall.test.ts+++ b/src/daemon/uninstall.test.ts@@ -67,6 +67,12 @@ describe('planning an uninstall', () => {expect(planUninstall().elsewhere).toEqual([]);});+ test('on Windows the folder holding the Node this runs on is kept, since a running program cannot be deleted there', () => {+ const runningOn = join(stateDir, 'runtime', 'node', 'node.exe');+ const inUse = (platform: NodeJS.Platform) => planUninstall({ platform, runningOn }).removals.map((removal) => removal.inUse);+ expect([inUse('win32'), inUse('darwin')]).toEqual([['runtime', undefined], [undefined, undefined]]);+ });+test('npx caches holding a copy are included', () => {const dir = npxEntry(join(homedir(), '.npm', '_npx'), 'f6', '0.6.0');expect(planUninstall().npx).toEqual([{ dir, version: '0.6.0', packages: ['browsentic@latest'], running: false }]);@@ -114,6 +120,29 @@ describe('removing', () => {});});+describe('removing on Windows', () => {+ test('the folder the running Node sits in stays, and everything around it goes', () => {+ made(join(stateDir, 'runtime', 'node'), join(stateDir, 'sessions'));+ writeFileSync(join(stateDir, 'config.json'), '{}');+ const [state] = removeAll(planUninstall({ platform: 'win32', runningOn: join(stateDir, 'runtime', 'node', 'node.exe') }).removals);+ expect([state.removed, state.kept, readdirSync(stateDir)]).toEqual([true, ['runtime'], ['runtime']]);+ });++ // A read-only folder stands in for a program Windows has open; Windows folders have no such mode.+ test.skipIf(process.platform === 'win32')('an entry that will not go leaves the rest to be deleted, the pairing keys among them', () => {+ made(join(stateDir, 'bin'));+ writeFileSync(join(stateDir, 'bin', 'browsentic.exe'), '');+ writeFileSync(join(stateDir, 'sessions.json'), '{}');+ chmodSync(join(stateDir, 'bin'), 0o555);+ try {+ const [state] = removeAll(planUninstall().removals);+ expect([state.removed, state.error, readdirSync(stateDir)]).toEqual([false, expect.stringContaining(join(stateDir, 'bin')), ['bin']]);+ } finally {+ chmodSync(join(stateDir, 'bin'), 0o755);+ }+ });+});+describe('purging npx caches', () => {test('each cache is deleted, and each outcome reported', () => {const dir = npxEntry(join(homedir(), '.npm', '_npx'), 'g7', '0.6.0');diff --git a/src/daemon/uninstall.ts b/src/daemon/uninstall.tsindex 1154eba..220f018 100644--- a/src/daemon/uninstall.ts+++ b/src/daemon/uninstall.ts@@ -1,5 +1,5 @@import { existsSync, readdirSync, rmSync } from 'node:fs';-import { isAbsolute, join, relative } from 'node:path';+import { isAbsolute, join, relative, sep } from 'node:path';import { readAgentConfig } from './agent/config';import { uploadedSkillsDir } from './agent/skills';import { downloadDir } from './downloads';@@ -13,6 +13,8 @@ export interface Removal {holds: string;/** Paths under `path` to leave behind, relative to it. */keep?: string[];+ /** The entry under `path` holding the Node this command runs on, which Windows will not delete while it runs. */+ inUse?: string;}export interface UninstallPlan {@@ -27,12 +29,24 @@ function contains(root: string, path: string): boolean {return !inside.startsWith('..') && !isAbsolute(inside);}+function entryHolding(root: string, path: string): string | undefined {+ const inside = relative(root, path);+ return inside && contains(root, path) ? inside.split(sep)[0] : undefined;+}++/** An antivirus scan on Windows holds a file it has just seen for a moment, so a delete is tried again. */+const RETRY = { maxRetries: 3, retryDelay: 200 };+/*** What removing Browsentic means on this machine, resolved rather than assumed: an install can* have been pointed elsewhere with `setup --dir`, and skills, screenshots and downloads each* take a config override.*/-export function planUninstall(options: { keepSkills?: boolean } = {}): UninstallPlan {+export function planUninstall(+ options: { keepSkills?: boolean; platform?: NodeJS.Platform; runningOn?: string } = {},+): UninstallPlan {+ const { platform = process.platform, runningOn = process.execPath } = options;+ const inUse = (root: string) => (platform === 'win32' ? entryHolding(root, runningOn) : undefined);const config = readAgentConfig();const extension = extensionDir(config.extensionDir);const roots = [stateDir, userDir];@@ -46,12 +60,14 @@ export function planUninstall(options: { keepSkills?: boolean } = {}): Uninstallpath: stateDir,holds: 'pairing keys, config, approvals, logs',keep: options.keepSkills ? ['skills'] : undefined,+ inUse: inUse(stateDir),});removals.push({label: 'files',path: userDir,holds: 'the extension, skills, site maps, screenshots, captured downloads',keep: options.keepSkills ? ['skills'] : undefined,+ inUse: inUse(userDir),});const elsewhere: Removal[] = [];@@ -80,8 +96,9 @@ export interface RemovalOutcome {export function removeAll(removals: Removal[]): RemovalOutcome[] {return removals.map((removal) => {try {- const kept = removal.keep?.length ? keepingSome(removal.path, removal.keep) : [];- if (!kept.length) rmSync(removal.path, { recursive: true, force: true });+ const { kept, refused } = emptying(removal.path, [...(removal.keep ?? []), ...(removal.inUse ? [removal.inUse] : [])]);+ if (refused.length) return { removal, removed: false, kept, error: refused.join('; ') };+ if (!kept.length) rmSync(removal.path, { recursive: true, force: true, ...RETRY });return { removal, removed: true, kept };} catch (error) {return { removal, removed: false, kept: [], error: (error as Error).message };@@ -89,14 +106,25 @@ export function removeAll(removals: Removal[]): RemovalOutcome[] {});}-/** Empties `dir` apart from `keep`, and reports what survived — nothing means delete the lot. */-function keepingSome(dir: string, keep: string[]): string[] {+/**+ * Empties `dir` apart from `spare`, and reports what survived. One entry that will not go, such as+ * a program Windows has open, leaves the rest to be deleted anyway: the pairing keys among them.+ */+function emptying(dir: string, spare: string[]): { kept: string[]; refused: string[] } {const kept: string[] = [];+ const refused: string[] = [];for (const entry of readdirSync(dir)) {- if (keep.includes(entry)) kept.push(entry);- else rmSync(join(dir, entry), { recursive: true, force: true });+ if (spare.includes(entry)) {+ kept.push(entry);+ continue;+ }+ try {+ rmSync(join(dir, entry), { recursive: true, force: true, ...RETRY });+ } catch (error) {+ refused.push((error as Error).message);+ }}- return kept;+ return { kept, refused };}export interface CachePurge {@@ -116,7 +144,7 @@ export interface CachePurge {export function purgeNpxCache(entries: NpxEntry[]): CachePurge[] {return entries.map((entry) => {try {- rmSync(entry.dir, { recursive: true, force: true });+ rmSync(entry.dir, { recursive: true, force: true, ...RETRY });return { entry, removed: true };} catch (error) {return { entry, removed: false, error: (error as Error).message };