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

review: persist layeredIntelligence on createApp (was silently dropped) (#2262)

Adam Eivya6ad6adb184c
diff --git a/server/services/apps.js b/server/services/apps.js
index 43ca31c84b..27c128a852 100644
--- a/server/services/apps.js
+++ b/server/services/apps.js
@@ -324,6 +324,14 @@ export async function createApp(appData) {
updatedAt: now
};
+ // Persist an explicitly-provided Layered Intelligence config on create; when
+ // omitted the app has no key and the config accessor supplies the baseline on
+ // first read (no per-app seed write). Only set it when present so absent stays
+ // absent — createApp otherwise builds the object field-by-field and would drop it.
+ if (appData.layeredIntelligence && typeof appData.layeredIntelligence === 'object') {
+ app.layeredIntelligence = appData.layeredIntelligence;
+ }
+
data.apps[id] = app;
await saveApps(data);
diff --git a/server/services/apps.layeredIntelligence.test.js b/server/services/apps.layeredIntelligence.test.js
index a6882e6cd0..72e95ffc72 100644
--- a/server/services/apps.layeredIntelligence.test.js
+++ b/server/services/apps.layeredIntelligence.test.js
@@ -18,7 +18,7 @@ vi.mock('../lib/ports.js', () => ({ PORTS: { API: 5555, API_LOCAL: 5553, UI: 555
vi.mock('./taskSchedule.js', () => ({ SELF_IMPROVEMENT_TASK_TYPES: [] }));
vi.mock('./pm2.js', () => ({ listProcessesStrict: vi.fn().mockResolvedValue([]) }));
-import { getAppLayeredIntelligenceConfig, updateAppLayeredIntelligence, invalidateCache, PORTOS_APP_ID } from './apps.js';
+import { getAppLayeredIntelligenceConfig, updateAppLayeredIntelligence, createApp, getAppById, invalidateCache, PORTOS_APP_ID } from './apps.js';
beforeEach(() => {
invalidateCache();
@@ -74,3 +74,25 @@ describe('updateAppLayeredIntelligence', () => {
expect(await updateAppLayeredIntelligence('nope', { enabled: true })).toBe(null);
});
});
+
+describe('createApp persists layeredIntelligence', () => {
+ it('stores an explicitly-provided config on create', async () => {
+ const created = await createApp({
+ name: 'New App', repoPath: '/new', type: 'express',
+ layeredIntelligence: { enabled: true, allowedScopes: ['app-improvement'] }
+ });
+ invalidateCache();
+ const fetched = await getAppById(created.id);
+ expect(fetched.layeredIntelligence).toEqual({ enabled: true, allowedScopes: ['app-improvement'] });
+ });
+
+ it('leaves no layeredIntelligence key when omitted (baseline resolves on read)', async () => {
+ const created = await createApp({ name: 'Bare App', repoPath: '/bare', type: 'express' });
+ invalidateCache();
+ const fetched = await getAppById(created.id);
+ expect(fetched.layeredIntelligence).toBeUndefined();
+ // …and the accessor still supplies the baseline default.
+ const cfg = await getAppLayeredIntelligenceConfig(created.id);
+ expect(cfg.enabled).toBe(false);
+ });
+});