Skip to content

The agent that grows with you

fix(desktop): root-layout git installs no longer count .git toward the 64 MB cap

kshitijk4poor2c9946a6c5f2
diff --git a/apps/desktop/electron/desktop-plugin-install.test.ts b/apps/desktop/electron/desktop-plugin-install.test.ts
index f529f4e6b78..c80d4d6040c 100644
--- a/apps/desktop/electron/desktop-plugin-install.test.ts
+++ b/apps/desktop/electron/desktop-plugin-install.test.ts
@@ -1,4 +1,5 @@
import { execFileSync } from 'node:child_process'
+import { randomBytes } from 'node:crypto'
import fs from 'node:fs'
import os from 'node:os'
import path from 'node:path'
@@ -289,7 +290,10 @@ describe('installDesktopPluginFromGit', () => {
})
it.each([
- ['a symlinked file inside it', (repo: string) => fs.symlinkSync('/etc/hostname', path.join(repo, 'desktop', 'leak.txt'))],
+ [
+ 'a symlinked file inside it',
+ (repo: string) => fs.symlinkSync('/etc/hostname', path.join(repo, 'desktop', 'leak.txt'))
+ ],
[
'a symlinked desktop folder',
(repo: string, outside: string) => {
@@ -341,11 +345,31 @@ describe('installDesktopPluginFromGit', () => {
fs.writeFileSync(path.join(repo, 'desktop', 'panel.js'), 'replaced\n')
git('add', '-A')
git('-c', '[email protected]', '-c', 'user.name=F', 'commit', '-qm', 'plain')
- expect(await installDesktopPluginFromGit('git', pathToFileURL(repo).href, appRoot, true)).toMatchObject({ ok: true })
+ expect(await installDesktopPluginFromGit('git', pathToFileURL(repo).href, appRoot, true)).toMatchObject({
+ ok: true
+ })
expect(fs.readdirSync(appRoot)).toEqual([installed.pluginName])
expect(fs.readFileSync(path.join(appRoot, installed.pluginName!, 'panel.js'), 'utf8')).toBe('replaced\n')
})
+ it("leaves the clone's .git out of a root-layout half and out of its size cap", async () => {
+ // 36 MB of incompressible payload is under the 64 MB cap; counted twice (files + packed .git) it is over.
+ const repo = mkdtemp('hermes-plugin-install-')
+ const appRoot = mkdtemp('hermes-plugin-root-')
+ roots.push(repo, appRoot)
+ const git = (...args: string[]) => execFileSync('git', args, { cwd: repo, stdio: 'pipe' })
+ fs.writeFileSync(path.join(repo, 'plugin.js'), 'export function register() {}\n')
+ fs.writeFileSync(path.join(repo, 'asset.bin'), randomBytes(36 * 1024 * 1024))
+ git('init', '-q')
+ git('add', '.')
+ git('-c', '[email protected]', '-c', 'user.name=Fixture', 'commit', '-qm', 'init')
+
+ const result = await installDesktopPluginFromGit('git', pathToFileURL(repo).href, appRoot)
+
+ expect(result).toMatchObject({ ok: true })
+ expect(fs.readdirSync(path.join(appRoot, result.pluginName!)).sort()).toEqual(['asset.bin', 'plugin.js'])
+ }, 60_000)
+
it('stamps the package marker on a unified package half and names the folder after the agent package', async () => {
// Without the marker the Plugins page has no evidence that this copy is the
// agent row's desktop half: the row sits on "copying…" while the copy shows
diff --git a/apps/desktop/electron/desktop-plugin-install.ts b/apps/desktop/electron/desktop-plugin-install.ts
index 485f3970cb9..a3aa6b8bc50 100644
--- a/apps/desktop/electron/desktop-plugin-install.ts
+++ b/apps/desktop/electron/desktop-plugin-install.ts
@@ -16,6 +16,7 @@ import {
desktopHalfSource,
PACKAGE_MARKER,
publishDesktopTree,
+ rootLayoutFilter,
withDesktopPluginsRoot,
writeDesktopHalfMarker
} from './desktop-plugins-root'
@@ -549,30 +550,35 @@ export async function installDesktopPluginFromGit(
// part of that publication — without it the Plugins page cannot tell this
// copy belongs to the agent row (it sits on "copying…" forever) and the
// half loads default-enabled instead of opt-in.
- await publishDesktopTree({ dir: sourceDir, plainWithin: cloneRoot }, targetDir, async staged => {
- if (!packageName) {
- // A desktop-only repo is a standalone plugin. A package marker it
- // ships would name another package's agent half as its own (pairing
- // it on the Plugins page and letting it render that package's tool
- // media), so only this installer or the reconcile pass writes one.
- await fsp.rm(path.join(staged, PACKAGE_MARKER), { force: true })
-
- return
- }
-
- await writeDesktopHalfMarker(staged, {
- package: packageName,
- repo: gitUrl,
- // 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
- })
- })
+ await publishDesktopTree(
+ { dir: sourceDir, plainWithin: cloneRoot },
+ targetDir,
+ async staged => {
+ if (!packageName) {
+ // A desktop-only repo is a standalone plugin. A package marker it
+ // ships would name another package's agent half as its own (pairing
+ // it on the Plugins page and letting it render that package's tool
+ // media), so only this installer or the reconcile pass writes one.
+ await fsp.rm(path.join(staged, PACKAGE_MARKER), { force: true })
+
+ return
+ }
+
+ await writeDesktopHalfMarker(staged, {
+ package: packageName,
+ repo: gitUrl,
+ // 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
+ })
+ },
+ detected.desktopSourceSubdir === '.' ? rootLayoutFilter : undefined
+ )
if (!(await pathIsFile(targetPlugin))) {
return { ok: false, error: `Install completed but ${targetPlugin} is missing.` }
diff --git a/apps/desktop/electron/desktop-plugins-root.ts b/apps/desktop/electron/desktop-plugins-root.ts
index d4283c11d5c..46628ded4e1 100644
--- a/apps/desktop/electron/desktop-plugins-root.ts
+++ b/apps/desktop/electron/desktop-plugins-root.ts
@@ -268,7 +268,7 @@ async function desktopHalfEntry(
* the agent half's `__pycache__` (the gateway's `ROOT_LAYOUT_SKIP`). */
const ROOT_LAYOUT_SKIP = new Set(['.git', '__pycache__'])
-const rootLayoutFilter = (src: string) => !ROOT_LAYOUT_SKIP.has(path.basename(src))
+export const rootLayoutFilter = (src: string) => !ROOT_LAYOUT_SKIP.has(path.basename(src))
/** Copy one unified package's desktop half into the app root as
* `<appRoot>/<packageName>/`, stamping the marker: its `desktop/` folder, or