Skip to content

The agent that grows with you

fix(desktop): keep a git-installed desktop half without a local package

686f6c61f039f028f2bd
diff --git a/apps/desktop/electron/desktop-plugin-install.test.ts b/apps/desktop/electron/desktop-plugin-install.test.ts
index deab5f7b4a2..8f85372edd8 100644
--- a/apps/desktop/electron/desktop-plugin-install.test.ts
+++ b/apps/desktop/electron/desktop-plugin-install.test.ts
@@ -15,7 +15,7 @@ import {
resolvePluginGitUrl,
resolveSubdirWithin
} from './desktop-plugin-install'
-import { PACKAGE_MARKER } from './desktop-plugins-root'
+import { PACKAGE_MARKER, reconcileUnifiedDesktopHalves } from './desktop-plugins-root'
const here = path.dirname(fileURLToPath(import.meta.url))
@@ -201,6 +201,48 @@ describe('installDesktopPluginFromGit', () => {
expect(marker.repo).toBe(pathToFileURL(repo).href)
})
+ it('keeps a git-installed unified half when no local agent package exists', async () => {
+ // Remote backends (and a Desktop-only install) never have
+ // plugins/<name>/desktop locally. The marker used to name the temp clone,
+ // which this function deletes, so the next reconcile ghost-pruned the half.
+ const repo = pluginRepo('hermes-talk')
+ const home = mkdtemp('hermes-plugin-home-')
+ roots.push(home)
+ const appRoot = path.join(home, 'desktop-plugins')
+
+ const result = await installDesktopPluginFromGit('git', pathToFileURL(repo).href, appRoot)
+
+ expect(result).toMatchObject({ ok: true, pluginName: 'hermes-talk' })
+ const published = path.join(appRoot, 'hermes-talk')
+ const marker = JSON.parse(fs.readFileSync(path.join(published, PACKAGE_MARKER), 'utf8'))
+ expect(marker.source).toBe(published)
+ expect(fs.existsSync(path.join(marker.source, 'plugin.js'))).toBe(true)
+
+ const touched = await reconcileUnifiedDesktopHalves(home, appRoot)
+
+ expect(fs.existsSync(path.join(published, 'plugin.js'))).toBe(true)
+ expect(touched).not.toContain(published)
+ })
+
+ it('lets a local agent package replace the git-installed half on reconcile', async () => {
+ const repo = pluginRepo('hermes-talk')
+ const home = mkdtemp('hermes-plugin-home-')
+ roots.push(home)
+ const appRoot = path.join(home, 'desktop-plugins')
+
+ await installDesktopPluginFromGit('git', pathToFileURL(repo).href, appRoot)
+
+ const packageDesktop = path.join(home, 'plugins', 'hermes-talk', 'desktop')
+ fs.mkdirSync(packageDesktop, { recursive: true })
+ fs.writeFileSync(path.join(packageDesktop, 'plugin.js'), 'from the agent package\n')
+
+ await reconcileUnifiedDesktopHalves(home, appRoot)
+
+ expect(fs.readFileSync(path.join(appRoot, 'hermes-talk', 'plugin.js'), 'utf8')).toBe('from the agent package\n')
+ const marker = JSON.parse(fs.readFileSync(path.join(appRoot, 'hermes-talk', PACKAGE_MARKER), 'utf8'))
+ expect(marker.source).toBe(packageDesktop)
+ })
+
it('leaves a desktop-only repo unmarked so it stays a standalone plugin', async () => {
const repo = pluginRepo(null)
const appRoot = mkdtemp('hermes-plugin-root-')
diff --git a/apps/desktop/electron/desktop-plugin-install.ts b/apps/desktop/electron/desktop-plugin-install.ts
index ad6d5497dac..528f7e096cf 100644
--- a/apps/desktop/electron/desktop-plugin-install.ts
+++ b/apps/desktop/electron/desktop-plugin-install.ts
@@ -465,12 +465,14 @@ export async function installDesktopPluginFromGit(
await writeDesktopHalfMarker(staged, {
package: packageName,
repo: gitUrl,
- // The clone is deleted below, so this source never matches a local
- // package's `desktop/` dir: the first reconcile that finds the agent
- // half re-copies from there and the package folder takes over as the
- // single source of truth.
- source: sourceDir,
- sourceMtimeMs: (await fsp.stat(path.join(sourceDir, 'plugin.js'))).mtimeMs
+ // The published folder, not the temp clone. The clone is deleted
+ // below; a source that disappears is ghost-pruned on the next
+ // reconcile when no local `plugins/<name>/desktop` exists to
+ // re-copy from (remote backend, or Desktop UI only). A later pass
+ // that does find the agent package still replaces this copy,
+ // because this path is not that package's `desktop/` dir.
+ source: targetDir,
+ sourceMtimeMs: (await fsp.stat(path.join(staged, 'plugin.js'))).mtimeMs
})
})