Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: keep managed app checkouts when purging Cloned Repos (#12439)

[._.]/ Adam Eivydb5b2982fbc5
diff --git a/server/services/dataManager.js b/server/services/dataManager.js
index df981999f3..69bde66801 100644
--- a/server/services/dataManager.js
+++ b/server/services/dataManager.js
@@ -12,6 +12,8 @@ import { withBackupAssetPublication } from '../lib/backupSnapshotBoundary.js';
import {
federatedMediaInboxBusy, imageCleanTmpBusy, trainingRunsBusy, updateDetachedBusy,
} from './dataManagerBusy.js';
+import { getEidoversePaths } from './eidoverse.js';
+import { getAllApps } from './apps.js';
const execFileAsync = promisify(execFile);
const DATA_DIR = PATHS.data;
@@ -180,7 +182,7 @@ export const CATEGORIES = {
// A pasted or URL-fetched book is the user's only copy — the shelf is not a
// cache of anything re-fetchable, so it is neither archivable nor deletable.
'rapid-reader-library': { label: 'Rapid Reader Shelf', description: 'Saved books for Rapid Reader — pasted and URL-imported prose kept on this machine, not regenerable', archivable: false, deletable: false },
- 'repos': { label: 'Cloned Repos', description: 'Git repositories cloned by agents', archivable: false, deletable: true, purgeScope: 'category' },
+ 'repos': { label: 'Cloned Repos', description: 'Git repositories cloned by agents. Managed app checkouts (Eidoverse Worlds and its video repo) are kept on purge',archivable: false, deletable: true, purgeScope: 'category' },
// Not deletable: user todos, pending CoS action requests and private security
// assessment reports live here and have no other copy.
'review': { label: 'Review', description: 'Review Hub todos, action requests and assessment reports', archivable: true, deletable: false },
@@ -254,6 +256,53 @@ export async function resolveCategoryBusy(categoryKey) {
return { busy: true, busyReason: result.reason || `Something is using data/${categoryKey} right now — purge once it finishes.` };
}
+// Managed app checkouts (Eidoverse worlds, its video companion, any registered
+// app repo) live under data/repos but hold installed code, .env.portos and local
+// commits, so a "Cloned Repos" purge must keep them. Fails closed: if the app
+// registry cannot be read, the purge is refused rather than run unprotected.
+async function protectedRepoPaths() {
+ const reposDir = resolve(PATHS.repos);
+ const eidoverse = getEidoversePaths();
+ const candidates = [eidoverse.worlds, eidoverse.video];
+ for (const app of await getAllApps()) {
+ if (typeof app.repoPath === 'string') candidates.push(app.repoPath);
+ for (const companion of app.companionRepoPaths || []) {
+ if (typeof companion === 'string') candidates.push(companion);
+ }
+ }
+ return candidates.map(p => resolve(p)).filter(p => isInsideDir(reposDir, p));
+}
+
+function isInsideDir(parent, child) {
+ const rel = relative(parent, child);
+ return Boolean(rel) && !rel.startsWith('..') && !isAbsolute(rel);
+}
+
+// Removes every entry under `dir` that is not protected. An ancestor of a
+// protected checkout (e.g. the owner directory holding it) is descended into,
+// never removed whole.
+async function purgeUnprotectedEntries(dir, protectedPaths) {
+ const entries = await readdir(dir, { withFileTypes: true }).catch(() => []);
+ let removed = 0;
+ let kept = 0;
+ for (const entry of entries) {
+ const full = resolve(join(dir, entry.name));
+ if (protectedPaths.includes(full)) {
+ kept++;
+ continue;
+ }
+ if (protectedPaths.some(p => isInsideDir(full, p))) {
+ const nested = await purgeUnprotectedEntries(full, protectedPaths);
+ removed += nested.removed;
+ kept += nested.kept;
+ continue;
+ }
+ await rmGuarded(full, { recursive: true, force: true });
+ removed++;
+ }
+ return { removed, kept };
+}
+
// Validate category key contains only safe characters
const SAFE_NAME = /^[a-z0-9_-]+$/;
@@ -548,6 +597,7 @@ export async function purgeCategory(categoryKey, options = {}) {
// the same fail-closed busy probe to both deletion scopes.
const { busy, busyReason } = await resolveCategoryBusy(categoryKey);
if (busy) throw new ServerError(busyReason, { status: 409, code: 'CATEGORY_BUSY' });
+ const protectedPaths = categoryKey === 'repos' ? await protectedRepoPaths() : [];
if (wantsItem) {
const resolvedRoot = resolve(dirPath);
@@ -558,6 +608,10 @@ export async function purgeCategory(categoryKey, options = {}) {
if (!rel || rel.startsWith('..') || isAbsolute(rel)) {
throw new ServerError('Invalid subPath', { status: 400, code: 'VALIDATION_ERROR' });
}
+ // Ancestor (holds a checkout) or descendant (lies inside one) — both would destroy it.
+ if (protectedPaths.some(p => p === resolvedTarget || isInsideDir(resolvedTarget, p) || isInsideDir(p, resolvedTarget))) {
+ throw new ServerError(`"${options.subPath}" is a managed app checkout and is kept`, { status: 409, code: 'PROTECTED_CHECKOUT' });
+ }
// Item-scoped categories are flat directories of assets; their only
// subdirectories are working state for other features (`data/videos/.detached`
// holds the control files of in-flight renders). A one-click recursive
@@ -579,6 +633,9 @@ export async function purgeCategory(categoryKey, options = {}) {
}
await rmGuarded(resolvedTarget, { recursive: !itemScoped, force: true });
console.log(`🗑️ Purged item from data/${categoryKey}`);
+ } else if (categoryKey === 'repos') {
+ const { removed, kept } = await purgeUnprotectedEntries(dirPath, protectedPaths);
+ console.log(`🗑️ Purged ${removed} entries from data/repos, kept ${kept} managed app checkout(s)`);
} else {
const allEntries = await readdir(dirPath).catch(() => []);
const entries = meta.purgeFilter ? allEntries.filter(meta.purgeFilter) : allEntries;
diff --git a/server/services/dataManager.reposPurge.test.js b/server/services/dataManager.reposPurge.test.js
new file mode 100644
index 0000000000..efa35f685e
--- /dev/null
+++ b/server/services/dataManager.reposPurge.test.js
@@ -0,0 +1,70 @@
+/**
+ * "Cloned Repos" purge must keep managed app checkouts (issue #12439).
+ *
+ * data/repos holds both throwaway agent clones and installed app checkouts
+ * (Eidoverse Worlds, its video companion, any registered app repo). Purging the
+ * category must remove only the clones. Runs against a temp data root so the
+ * install's real data/ is never touched.
+ */
+
+import { describe, it, expect, beforeEach, afterAll, vi } from 'vitest';
+import { mkdtempSync, rmSync, mkdirSync, writeFileSync, existsSync } from 'fs';
+import { tmpdir } from 'os';
+import { join } from 'path';
+import { makePathsProxy } from '../lib/mockPathsDataRoot.js';
+
+const TEST_DATA_ROOT = mkdtempSync(join(tmpdir(), 'datamanager-repos-purge-test-'));
+
+vi.mock('../lib/fileUtils.js', async (importOriginal) => {
+ const actual = await importOriginal();
+ return makePathsProxy(actual, { dataRoot: TEST_DATA_ROOT });
+});
+
+vi.mock('../lib/db.js', () => ({ query: vi.fn() }));
+vi.mock('./apps.js', () => ({ getAllApps: vi.fn(async () => []) }));
+// The publication gate's admission directory is resolved from paths.js, which the
+// fileUtils redirect above does not reach; this suite is about the purge rule, not admission.
+vi.mock('../lib/backupSnapshotBoundary.js', () => ({ withBackupAssetPublication: (fn) => fn() }));
+
+const { purgeCategory } = await import('./dataManager.js');
+const { getAllApps } = await import('./apps.js');
+
+afterAll(() => rmSync(TEST_DATA_ROOT, { recursive: true, force: true }));
+
+const dataPath = (...parts) => join(TEST_DATA_ROOT, ...parts);
+const writeRepoFile = (...parts) => {
+ mkdirSync(dataPath('repos', ...parts.slice(0, -1)), { recursive: true });
+ writeFileSync(dataPath('repos', ...parts), 'x');
+};
+
+beforeEach(() => {
+ rmSync(TEST_DATA_ROOT, { recursive: true, force: true });
+ vi.mocked(getAllApps).mockResolvedValue([]);
+ writeRepoFile('acme', 'agent-clone', 'README.md');
+ writeRepoFile('atomantic', 'eidoverse-worlds', '.env.portos');
+ writeRepoFile('anima-research', 'eidoverse-video', 'package.json');
+});
+
+describe('purgeCategory — repos keeps managed app checkouts (#12439)', () => {
+ it('removes an agent clone and leaves the Eidoverse worlds and video checkouts', async () => {
+ await purgeCategory('repos');
+ expect(existsSync(dataPath('repos', 'acme'))).toBe(false);
+ expect(existsSync(dataPath('repos', 'atomantic', 'eidoverse-worlds', '.env.portos'))).toBe(true);
+ expect(existsSync(dataPath('repos', 'anima-research', 'eidoverse-video', 'package.json'))).toBe(true);
+ });
+
+ it('keeps a registered app checkout that is not the Eidoverse default', async () => {
+ writeRepoFile('acme', 'managed-app', 'app.json');
+ vi.mocked(getAllApps).mockResolvedValue([{ repoPath: dataPath('repos', 'acme', 'managed-app') }]);
+ await purgeCategory('repos');
+ expect(existsSync(dataPath('repos', 'acme', 'managed-app', 'app.json'))).toBe(true);
+ expect(existsSync(dataPath('repos', 'acme', 'agent-clone'))).toBe(false);
+ });
+
+ it('refuses an item purge that would delete a protected checkout or its ancestor', async () => {
+ await expect(purgeCategory('repos', { subPath: 'anima-research' })).rejects.toThrow(/managed app checkout/);
+ await expect(purgeCategory('repos', { subPath: 'atomantic' })).rejects.toThrow(/managed app checkout/);
+ expect(existsSync(dataPath('repos', 'anima-research', 'eidoverse-video', 'package.json'))).toBe(true);
+ expect(existsSync(dataPath('repos', 'atomantic', 'eidoverse-worlds', '.env.portos'))).toBe(true);
+ });
+});