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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: stop shipping config seeds that duplicate DEFAULT_CONFIG (#8444)
[._.]/ Adam Eivy087fe78b73be
diff --git a/data.reference/browser-config.json b/data.reference/browser-config.jsondeleted file mode 100644index 2e90a46da8..0000000000--- a/data.reference/browser-config.json+++ /dev/null@@ -1,8 +0,0 @@-{- "cdpPort": 5556,- "cdpHost": "127.0.0.1",- "healthPort": 5557,- "autoConnect": true,- "headless": false,- "userDataDir": ""-}diff --git a/data.reference/memory-classifier-config.json b/data.reference/memory-classifier-config.jsondeleted file mode 100644index ff0d507420..0000000000--- a/data.reference/memory-classifier-config.json+++ /dev/null@@ -1,10 +0,0 @@-{- "enabled": true,- "provider": "lmstudio",- "endpoint": "http://localhost:1234/v1/chat/completions",- "model": "gptoss-20b",- "timeout": 60000,- "maxOutputLength": 10000,- "minConfidence": 0.6,- "fallbackToPatterns": true-}diff --git a/scripts/lib/migrationOwnedPaths.js b/scripts/lib/migrationOwnedPaths.jsindex 4edc8bae2c..e98b62940e 100644--- a/scripts/lib/migrationOwnedPaths.js+++ b/scripts/lib/migrationOwnedPaths.js@@ -42,6 +42,12 @@ export const MIGRATION_OWNED_PATHS = new Set([// runs before migrations) and the backfill would then merge this install's// runs into another machine's rows.'cos/agents/index.order.json',+ // Migration 412 prunes memory-classifier-config.json and browser-config.json+ // to remove keys that equal the shipped seed values. Both files are derived+ // from user edits; a shipped seed would shadow environment-derived defaults+ // (LM_STUDIO_URL, CDP_HOST) and cause the service to ignore those env vars.+ 'memory-classifier-config.json',+ 'browser-config.json',]);/**diff --git a/scripts/migrations/412-prune-config-seed-duplicates.js b/scripts/migrations/412-prune-config-seed-duplicates.jsnew file mode 100644index 0000000000..a630d055bb--- /dev/null+++ b/scripts/migrations/412-prune-config-seed-duplicates.js@@ -0,0 +1,135 @@+/**+ * Prune memory-classifier-config.json and browser-config.json to remove keys+ * that match the shipped seed values.+ *+ * Both seeds duplicated their service's DEFAULT_CONFIG key for key. Services+ * merge the stored file over the in-code defaults (`{ ...DEFAULT_CONFIG, ...parsed }`),+ * so on every install that `npm run setup:data` seeded, the copied values+ * permanently won over the code. That includes values the code derives from+ * the environment:+ *+ * - memory-classifier-config.json: `endpoint` was hard-coded to+ * `http://localhost:1234/v1/chat/completions`, but the code derives it from+ * `LM_STUDIO_URL`. `minConfidence` was `0.6` in the seed but `0.7` in code.+ * - browser-config.json: `cdpHost` was hard-coded to `127.0.0.1`, but the code+ * reads `CDP_HOST`.+ *+ * Both files are now migration-owned (declared in migrationOwnedPaths.js), so+ * their seeds will not re-appear on future setups. This migration cleans up+ * existing installs by removing every key whose value equals the retired seed,+ * keeping any key the user changed. The file is deleted if nothing is left.+ */++import { readFile, rm } from 'fs/promises';+import { existsSync } from 'fs';+import { join } from 'path';+import { writeJsonAtomic } from './_lib.js';++/**+ * Values from the retired data.reference/memory-classifier-config.json seed.+ * These keys should be removed from the installed file if they match.+ */+const RETIRED_MEMORY_CLASSIFIER_SEED = {+ enabled: true,+ provider: 'lmstudio',+ endpoint: 'http://localhost:1234/v1/chat/completions',+ model: 'gptoss-20b',+ timeout: 60000,+ maxOutputLength: 10000,+ minConfidence: 0.6,+ fallbackToPatterns: true,+};++/**+ * Values from the retired data.reference/browser-config.json seed.+ * These keys should be removed from the installed file if they match.+ */+const RETIRED_BROWSER_SEED = {+ cdpPort: 5556,+ cdpHost: '127.0.0.1',+ healthPort: 5557,+ autoConnect: true,+ headless: false,+ userDataDir: '',+};++async function readJson(path) {+ if (!existsSync(path)) return null;+ try {+ const content = await readFile(path, 'utf-8');+ return JSON.parse(content);+ } catch {+ return null;+ }+}++/**+ * Prune a config object by removing keys that equal the retired seed values.+ * Returns the pruned object or null if all keys were removed.+ */+function pruneConfig(config, retiredSeed) {+ if (!config || typeof config !== 'object') return null;++ const pruned = {};+ for (const [key, value] of Object.entries(config)) {+ // Keep the key if it's not in the seed or if the value differs+ if (!(key in retiredSeed) || retiredSeed[key] !== value) {+ pruned[key] = value;+ }+ }++ return Object.keys(pruned).length > 0 ? pruned : null;+}++export default {+ async up({ rootDir }) {+ const results = {+ memoryClassifier: null,+ browser: null,+ };++ // Process memory-classifier-config.json+ const memoryConfigPath = join(rootDir, 'data', 'memory-classifier-config.json');+ const memoryConfig = await readJson(memoryConfigPath);+ if (memoryConfig) {+ const pruned = pruneConfig(memoryConfig, RETIRED_MEMORY_CLASSIFIER_SEED);+ if (pruned === null) {+ // File was entirely seed values, remove it+ await rm(memoryConfigPath, { force: true });+ results.memoryClassifier = 'removed';+ console.log('🧹 Removed data/memory-classifier-config.json (contained only seed defaults)');+ } else if (Object.keys(pruned).length < Object.keys(memoryConfig).length) {+ // File had some user changes, keep only those+ await writeJsonAtomic(memoryConfigPath, pruned);+ const removed = Object.keys(memoryConfig).length - Object.keys(pruned).length;+ results.memoryClassifier = `pruned (${removed} keys removed)`;+ console.log(`✂️ data/memory-classifier-config.json: removed ${removed} seed-default keys, kept ${Object.keys(pruned).length}`);+ } else {+ results.memoryClassifier = 'unchanged';+ }+ }++ // Process browser-config.json+ const browserConfigPath = join(rootDir, 'data', 'browser-config.json');+ const browserConfig = await readJson(browserConfigPath);+ if (browserConfig) {+ const pruned = pruneConfig(browserConfig, RETIRED_BROWSER_SEED);+ if (pruned === null) {+ // File was entirely seed values, remove it+ await rm(browserConfigPath, { force: true });+ results.browser = 'removed';+ console.log('🧹 Removed data/browser-config.json (contained only seed defaults)');+ } else if (Object.keys(pruned).length < Object.keys(browserConfig).length) {+ // File had some user changes, keep only those+ await writeJsonAtomic(browserConfigPath, pruned);+ const removed = Object.keys(browserConfig).length - Object.keys(pruned).length;+ results.browser = `pruned (${removed} keys removed)`;+ console.log(`✂️ data/browser-config.json: removed ${removed} seed-default keys, kept ${Object.keys(pruned).length}`);+ } else {+ results.browser = 'unchanged';+ }+ }++ return results;+ },+};diff --git a/scripts/migrations/412-prune-config-seed-duplicates.test.js b/scripts/migrations/412-prune-config-seed-duplicates.test.jsnew file mode 100644index 0000000000..a74699041e--- /dev/null+++ b/scripts/migrations/412-prune-config-seed-duplicates.test.js@@ -0,0 +1,188 @@+import { describe, it, expect, beforeEach, afterEach } from 'vitest';+import { mkdtempSync, rmSync, writeFileSync, readFileSync, mkdirSync, existsSync } from 'fs';+import { tmpdir } from 'os';+import { join } from 'path';++import migration from './412-prune-config-seed-duplicates.js';++const writeJson = (path, value) => writeFileSync(path, `${JSON.stringify(value, null, 2)}\n`);+const readJson = (path) => (existsSync(path) ? JSON.parse(readFileSync(path, 'utf-8')) : null);++describe('migration 412 — prune config seeds that duplicate DEFAULT_CONFIG', () => {+ let rootDir;+ let dataDir;+ let memoryConfigPath;+ let browserConfigPath;++ beforeEach(() => {+ rootDir = mkdtempSync(join(tmpdir(), 'migration-412-'));+ dataDir = join(rootDir, 'data');+ mkdirSync(dataDir, { recursive: true });+ memoryConfigPath = join(dataDir, 'memory-classifier-config.json');+ browserConfigPath = join(dataDir, 'browser-config.json');+ });++ afterEach(() => {+ rmSync(rootDir, { recursive: true, force: true });+ });++ describe('memory-classifier-config.json', () => {+ it('removes the file if it contains only seed defaults', async () => {+ writeJson(memoryConfigPath, {+ enabled: true,+ provider: 'lmstudio',+ endpoint: 'http://localhost:1234/v1/chat/completions',+ model: 'gptoss-20b',+ timeout: 60000,+ maxOutputLength: 10000,+ minConfidence: 0.6,+ fallbackToPatterns: true,+ });++ const result = await migration.up({ rootDir });++ expect(result.memoryClassifier).toBe('removed');+ expect(existsSync(memoryConfigPath)).toBe(false);+ });++ it('keeps only customized keys', async () => {+ writeJson(memoryConfigPath, {+ enabled: true,+ provider: 'lmstudio',+ endpoint: 'http://localhost:1234/v1/chat/completions',+ model: 'custom-model', // User changed this+ timeout: 60000,+ maxOutputLength: 10000,+ minConfidence: 0.6,+ fallbackToPatterns: true,+ });++ const result = await migration.up({ rootDir });++ expect(result.memoryClassifier).toContain('pruned');+ expect(readJson(memoryConfigPath)).toEqual({ model: 'custom-model' });+ });++ it('keeps multiple user customizations', async () => {+ writeJson(memoryConfigPath, {+ enabled: false, // User disabled it+ provider: 'ollama', // User changed provider+ endpoint: 'http://localhost:1234/v1/chat/completions',+ model: 'gptoss-20b',+ timeout: 30000, // User reduced timeout+ maxOutputLength: 10000,+ minConfidence: 0.6,+ fallbackToPatterns: false, // User disabled fallback+ });++ const result = await migration.up({ rootDir });++ expect(result.memoryClassifier).toContain('pruned');+ expect(readJson(memoryConfigPath)).toEqual({+ enabled: false,+ provider: 'ollama',+ timeout: 30000,+ fallbackToPatterns: false,+ });+ });++ it('does nothing if file does not exist', async () => {+ const result = await migration.up({ rootDir });++ expect(result.memoryClassifier).toBeNull();+ expect(existsSync(memoryConfigPath)).toBe(false);+ });+ });++ describe('browser-config.json', () => {+ it('removes the file if it contains only seed defaults', async () => {+ writeJson(browserConfigPath, {+ cdpPort: 5556,+ cdpHost: '127.0.0.1',+ healthPort: 5557,+ autoConnect: true,+ headless: false,+ userDataDir: '',+ });++ const result = await migration.up({ rootDir });++ expect(result.browser).toBe('removed');+ expect(existsSync(browserConfigPath)).toBe(false);+ });++ it('keeps only customized keys', async () => {+ writeJson(browserConfigPath, {+ cdpPort: 5556,+ cdpHost: '192.168.1.100', // User changed this+ healthPort: 5557,+ autoConnect: true,+ headless: false,+ userDataDir: '',+ });++ const result = await migration.up({ rootDir });++ expect(result.browser).toContain('pruned');+ expect(readJson(browserConfigPath)).toEqual({ cdpHost: '192.168.1.100' });+ });++ it('keeps multiple user customizations', async () => {+ writeJson(browserConfigPath, {+ cdpPort: 5556,+ cdpHost: '0.0.0.0', // User changed host+ healthPort: 5558, // User changed health port+ autoConnect: false, // User disabled autoConnect+ headless: true, // User enabled headless+ userDataDir: '',+ });++ const result = await migration.up({ rootDir });++ expect(result.browser).toContain('pruned');+ expect(readJson(browserConfigPath)).toEqual({+ cdpHost: '0.0.0.0',+ healthPort: 5558,+ autoConnect: false,+ headless: true,+ });+ });++ it('does nothing if file does not exist', async () => {+ const result = await migration.up({ rootDir });++ expect(result.browser).toBeNull();+ expect(existsSync(browserConfigPath)).toBe(false);+ });+ });++ it('handles both files in the same run', async () => {+ // Both files with seed values + one user change each+ writeJson(memoryConfigPath, {+ enabled: true,+ provider: 'lmstudio',+ endpoint: 'http://localhost:1234/v1/chat/completions',+ model: 'custom-llm',+ timeout: 60000,+ maxOutputLength: 10000,+ minConfidence: 0.6,+ fallbackToPatterns: true,+ });++ writeJson(browserConfigPath, {+ cdpPort: 5556,+ cdpHost: 'custom-host',+ healthPort: 5557,+ autoConnect: true,+ headless: false,+ userDataDir: '',+ });++ const result = await migration.up({ rootDir });++ expect(result.memoryClassifier).toContain('pruned');+ expect(result.browser).toContain('pruned');+ expect(readJson(memoryConfigPath)).toEqual({ model: 'custom-llm' });+ expect(readJson(browserConfigPath)).toEqual({ cdpHost: 'custom-host' });+ });+});diff --git a/server/services/memoryClassifier.js b/server/services/memoryClassifier.jsindex 4e1b0d60aa..31ccfb2ec4 100644--- a/server/services/memoryClassifier.js+++ b/server/services/memoryClassifier.js@@ -29,7 +29,6 @@ const DEFAULT_CONFIG = {model: 'gptoss-20b',timeout: 60000,maxOutputLength: 10000,- minConfidence: 0.7,fallbackToPatterns: true};diff --git a/server/services/memoryClassifier.test.js b/server/services/memoryClassifier.test.jsnew file mode 100644index 0000000000..2ff9c75553--- /dev/null+++ b/server/services/memoryClassifier.test.js@@ -0,0 +1,81 @@+import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';+import { mkdtempSync, rmSync } from 'fs';+import { tmpdir } from 'os';+import { join } from 'path';+import * as path from 'path';++describe('memoryClassifier — config env-derived defaults', () => {+ let tempDir;++ beforeEach(() => {+ tempDir = mkdtempSync(join(tmpdir(), 'memory-classifier-test-'));+ // Mock PATHS.data to point to our temp directory+ vi.resetModules();+ });++ afterEach(() => {+ rmSync(tempDir, { recursive: true, force: true });+ vi.resetModules();+ });++ it('honors LM_STUDIO_URL env var when no config file exists', async () => {+ const customLmStudioUrl = 'http://192.168.1.100:1234';+ const oldLmStudioUrl = process.env.LM_STUDIO_URL;++ try {+ process.env.LM_STUDIO_URL = customLmStudioUrl;++ // Dynamically import with the env var set+ const module = await import('./memoryClassifier.js');+ const DEFAULT_CONFIG = module.DEFAULT_CONFIG;++ // The endpoint should be derived from LM_STUDIO_URL+ const expectedEndpoint = `${customLmStudioUrl}/v1/chat/completions`;+ expect(DEFAULT_CONFIG.endpoint).toBe(expectedEndpoint);+ } finally {+ if (oldLmStudioUrl) {+ process.env.LM_STUDIO_URL = oldLmStudioUrl;+ } else {+ delete process.env.LM_STUDIO_URL;+ }+ }+ });++ it('uses default endpoint when LM_STUDIO_URL is not set', async () => {+ const oldLmStudioUrl = process.env.LM_STUDIO_URL;++ try {+ delete process.env.LM_STUDIO_URL;++ // Dynamically import with no env var+ const module = await import('./memoryClassifier.js');+ const DEFAULT_CONFIG = module.DEFAULT_CONFIG;++ expect(DEFAULT_CONFIG.endpoint).toBe('http://localhost:1234/v1/chat/completions');+ } finally {+ if (oldLmStudioUrl) {+ process.env.LM_STUDIO_URL = oldLmStudioUrl;+ }+ }+ });++ it('strips trailing slashes and /v1 from LM_STUDIO_URL', async () => {+ const oldLmStudioUrl = process.env.LM_STUDIO_URL;++ try {+ process.env.LM_STUDIO_URL = 'http://192.168.1.100:1234/v1/';++ // Force re-evaluation by dynamic import+ const module = await import('./memoryClassifier.js');+ const DEFAULT_CONFIG = module.DEFAULT_CONFIG;++ expect(DEFAULT_CONFIG.endpoint).toBe('http://192.168.1.100:1234/v1/chat/completions');+ } finally {+ if (oldLmStudioUrl) {+ process.env.LM_STUDIO_URL = oldLmStudioUrl;+ } else {+ delete process.env.LM_STUDIO_URL;+ }+ }+ });+});