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

test: prove mind visibility projection is privacy-safe and federation-free (#5154)

[._.]/ Adam Eivy941f30451752
diff --git a/server/services/persistentMindVisibility.test.js b/server/services/persistentMindVisibility.test.js
index 2742a92025..f06ba5bec1 100644
--- a/server/services/persistentMindVisibility.test.js
+++ b/server/services/persistentMindVisibility.test.js
@@ -1,3 +1,4 @@
+import { readFile } from 'fs/promises';
import { beforeEach, describe, expect, it, vi } from 'vitest';
const mocks = vi.hoisted(() => ({
@@ -102,4 +103,103 @@ describe('persistent mind visibility', () => {
expect(visibility.characterBudget).toMatchObject({ maxChars: 20_000, truncated: true });
expect(JSON.stringify(visibility).length).toBeLessThanOrEqual(21_000);
});
+
+ // #5154 privacy contract. Every forbidden value below is fed in through a
+ // DIFFERENT input surface (config, live records, error text, prompt, provider
+ // credentials, runtime probe, app registry) so a projection that starts
+ // spreading a whole source object fails here rather than in production.
+ it('never projects identity, secrets, network addresses, paths, or live-record contents', async () => {
+ mocks.inspectRuntime.mockResolvedValue({
+ inference: { active: false, residency: { status: 'provider-managed' }, endpoint: 'http://192.0.2.10:11434' },
+ context: { chars: 100, maxChars: 1_000, approximateTokens: 25, summaryState: 'current', lastMessage: 'private live record' },
+ system: { memory: { usagePercent: 40 }, hostname: 'private-hostname' },
+ });
+
+ const visibility = await readPersistentMindVisibility({
+ root: {
+ config: {
+ persistentMindCapabilities: { createTasks: true },
+ domainAutonomy: { cos: 'execute' },
+ secret: 'private-config-value',
+ pgPassword: 'private-db-password',
+ },
+ queuedTasks: [{ prompt: 'private live record' }],
+ },
+ state: { agents: {}, status: 'idle', lastError: 'private-token' },
+ profile: { providerId: 'example-provider', model: 'example-model' },
+ prompt: { identity: 'Private Person', instructions: 'Read /Users/private-user/private-file' },
+ provider: { id: 'example-provider', type: 'api', apiKey: 'private-api-key', endpoint: 'http://192.0.2.10:1234/v1' },
+ apps: [{ id: 'example-app', name: 'Example App', repoPath: '/private/example-app', remote: '[email protected]:acme/private.git' }],
+ now: 1_000,
+ });
+
+ const serialized = JSON.stringify(visibility);
+ const prompt = buildPersistentMindVisibilityPrompt(visibility);
+ for (const forbidden of [
+ 'private-config-value', 'private-db-password', 'private live record', 'private-token',
+ 'Private Person', '/Users/private-user', 'private-api-key', '192.0.2.10',
+ 'private-hostname', '/private/example-app', 'git@',
+ ]) {
+ expect(serialized).not.toContain(forbidden);
+ expect(prompt).not.toContain(forbidden);
+ }
+ });
+
+ // #5154: "unknown" must mean "the probe did not answer", never "the probe
+ // answered nothing". Collapsing the two would let the mind read a failed
+ // health check as a clean empty one.
+ it('keeps failed probes distinct from a legitimately empty projection', async () => {
+ mocks.readPreflights.mockResolvedValue([]);
+ const empty = await readPersistentMindVisibility({ apps: [], now: 1_000 });
+ expect(empty.sections).toMatchObject({ runtime: { freshness: 'fresh' }, workspace: { freshness: 'fresh' } });
+ expect(empty.workspaces).toEqual([]);
+ expect(empty.runtime.status).toBe('ready');
+ expect(empty.readiness).toBe('ready');
+ expect(empty.reasonCodes).toEqual([]);
+
+ mocks.inspectRuntime.mockRejectedValue(new Error('runtime probe failed'));
+ mocks.readPreflights.mockRejectedValue(new Error('preflight probe failed'));
+ const failed = await readPersistentMindVisibility({ apps: [], now: 1_000 });
+ expect(failed.sections).toMatchObject({ runtime: { freshness: 'unknown' }, workspace: { freshness: 'unknown' } });
+ expect(failed.runtime).toMatchObject({ status: 'unknown', context: { pressure: 'unknown' }, model: { residency: 'unknown' } });
+ expect(failed.readiness).toBe('unknown');
+ expect(failed.health).toMatchObject({ system: 'unknown', provider: 'unknown', database: 'unknown', forge: 'unknown' });
+ expect(failed.reasonCodes).toEqual(expect.arrayContaining(['runtime-unknown', 'workspace-unknown']));
+ });
+
+ it('collects read-only, makes no provider inference call, and never enters a federation payload', async () => {
+ const root = { config: { persistentMindCapabilities: { createTasks: true }, domainAutonomy: { cos: 'execute' } } };
+ const state = { agents: {}, status: 'idle' };
+ const rootBefore = structuredClone(root);
+ const stateBefore = structuredClone(state);
+ await readPersistentMindVisibility({ root, state, apps: [], now: 1_000 });
+ expect(root).toEqual(rootBefore);
+ expect(state).toEqual(stateBefore);
+ expect(mocks.readPreflights).toHaveBeenCalledWith([], expect.objectContaining({ force: false }));
+
+ // Deliberately an exact allowlist, not a denylist: the read-only and
+ // no-inference guarantees hold only while this module depends on nothing
+ // but these five readers. Adding a dependency should fail here and force a
+ // re-read of the privacy contract above - especially an LLM runner, which
+ // would turn a diagnostic read into a billed provider call.
+ const source = await readFile(new URL('./persistentMindVisibility.js', import.meta.url), 'utf8');
+ const imports = [...source.matchAll(/^import[^;]*?from '([^']+)';/gm)].map(([, id]) => id);
+ expect(imports.sort()).toEqual([
+ '../lib/domainAutonomy.js',
+ '../lib/persistentMindCapabilities.js',
+ './apps.js',
+ './persistentMindRuntime.js',
+ './persistentMindWorkspacePreflight.js',
+ ]);
+
+ // Privacy records stay machine-local: the projection must not be reachable
+ // from any outbound federation path.
+ const federation = await Promise.all([
+ './sharing/peerSyncPush.js',
+ './sharing/peerCosSync.js',
+ './sharing/peerSyncShared.js',
+ '../routes/peerSync.js',
+ ].map((rel) => readFile(new URL(rel, import.meta.url), 'utf8')));
+ expect(federation.join('\n')).not.toMatch(/persistentMindVisibility|mindVisibility/i);
+ });
});