Skip to content

The agent that grows with you

fix(desktop): do not prune the desktop half of a package folder the app cannot read

teknium1b74f158b0d1d
diff --git a/apps/desktop/electron/desktop-plugins-root.test.ts b/apps/desktop/electron/desktop-plugins-root.test.ts
index c51fd7a394f..7874644ac65 100644
--- a/apps/desktop/electron/desktop-plugins-root.test.ts
+++ b/apps/desktop/electron/desktop-plugins-root.test.ts
@@ -124,6 +124,31 @@ describe('reconcileUnifiedDesktopHalves', () => {
}
)
+ it.skipIf(process.platform === 'win32' || process.getuid?.() === 0)(
+ 'keeps (and warns about) the desktop half of a package folder it can no longer read',
+ async () => {
+ // A source the app cannot stat (Windows ACL EPERM, mode-000 folder) is not
+ // an uninstall: the ghost-prune loop must not rm the materialized half.
+ const home = makeHome()
+ const appRoot = path.join(home, 'desktop-plugins')
+ const denied = path.join(home, 'plugins', 'denied')
+ write(path.join(denied, 'desktop', 'plugin.js'), 'x')
+ await reconcileUnifiedDesktopHalves(home, appRoot)
+ expect(fs.existsSync(path.join(appRoot, 'denied'))).toBe(true)
+ fs.chmodSync(denied, 0)
+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => undefined)
+
+ try {
+ expect(await reconcileUnifiedDesktopHalves(home, appRoot)).toEqual([])
+ expect(fs.existsSync(path.join(appRoot, 'denied'))).toBe(true)
+ expect(warn).toHaveBeenCalledWith(expect.stringContaining('unreadable package denied'))
+ } finally {
+ warn.mockRestore()
+ fs.chmodSync(denied, 0o700)
+ }
+ }
+ )
+
it('stamps the package origin (catalog sidecar, else git remote) so "Install here" can reinstall the agent half', async () => {
const home = makeHome()
const appRoot = path.join(home, 'desktop-plugins')
diff --git a/apps/desktop/electron/desktop-plugins-root.ts b/apps/desktop/electron/desktop-plugins-root.ts
index f3864af68bf..527bbc664ad 100644
--- a/apps/desktop/electron/desktop-plugins-root.ts
+++ b/apps/desktop/electron/desktop-plugins-root.ts
@@ -164,7 +164,11 @@ export async function materializeDesktopHalf(
try {
stat = await fs.promises.stat(entry)
- } catch {
+ } catch (error) {
+ if (!isMissing(error)) {
+ console.warn(`[desktop-plugins] cannot read ${packageName}: ${String(error)}`)
+ }
+
return null
}
@@ -202,6 +206,31 @@ export async function materializeDesktopHalf(
return target
}
+function isMissing(error: unknown): boolean {
+ const code = (error as NodeJS.ErrnoException | null)?.code
+
+ return code === 'ENOENT' || code === 'ENOTDIR'
+}
+
+/** `true` only when the package's `desktop/plugin.js` is genuinely gone. A
+ * source the app is not ALLOWED to stat (Windows ACL EPERM, a mode-000 folder)
+ * is not an uninstall — pruning its root copy would silently drop the pane. */
+async function sourceGone(name: string, entry: string): Promise<boolean> {
+ try {
+ await fs.promises.stat(entry)
+
+ return false
+ } catch (error) {
+ if (isMissing(error)) {
+ return true
+ }
+
+ console.warn(`[desktop-plugins] keeping desktop half of unreadable package ${name}: ${String(error)}`)
+
+ return false
+ }
+}
+
/** Walk every local home's `plugins/` root and materialize each package's
* desktop half. First home wins for a name that appears in several profiles
* (the default home is first). Also drops root copies whose source package
@@ -245,7 +274,7 @@ export async function reconcileUnifiedDesktopHalves(hermesHome: string, appRoot:
const dir = path.join(appRoot, name)
const marker = await readMarker(dir)
- if (marker && !fs.existsSync(path.join(marker.source, 'plugin.js'))) {
+ if (marker && (await sourceGone(name, path.join(marker.source, 'plugin.js')))) {
await fs.promises.rm(dir, { force: true, recursive: true })
touched.push(dir)
}