Refactor settings management to use ~/.claude-mem/settings.json

- Updated paths in troubleshooting documentation to reflect new settings file location.
- Modified diagnostics and reference files to read from ~/.claude-mem/settings.json.
- Introduced getWorkerPort utility for cleaner worker port retrieval.
- Enhanced ChromaSync and SDKAgent to load Python version and Claude path from settings.
- Updated SettingsRoutes to validate new settings: CLAUDE_MEM_LOG_LEVEL and CLAUDE_MEM_PYTHON_VERSION.
- Added early-settings module to load settings for logger and other early-stage modules.
- Adjusted logger to use early-loaded log level setting.
- Refactored paths to utilize early-loaded data directory setting.
This commit is contained in:
Alex Newman
2025-12-09 12:23:33 -05:00
parent b22adcca05
commit fc5c2d5e07
23 changed files with 342 additions and 166 deletions
+31
View File
@@ -0,0 +1,31 @@
import { join } from 'path';
import { homedir } from 'os';
import { existsSync, readFileSync } from 'fs';
const SETTINGS_PATH = join(homedir(), '.claude-mem', 'settings.json');
interface EarlySettings {
CLAUDE_MEM_DATA_DIR?: string;
CLAUDE_MEM_LOG_LEVEL?: string;
CLAUDE_MEM_PYTHON_VERSION?: string;
CLAUDE_CODE_PATH?: string;
}
/**
* Load settings for early-stage modules (paths, logger)
* Falls back to env vars, then defaults
*/
export function loadEarlySetting(key: keyof EarlySettings, defaultValue: string): string {
// Priority: settings.json > env var > default
try {
if (existsSync(SETTINGS_PATH)) {
const data = JSON.parse(readFileSync(SETTINGS_PATH, 'utf-8'));
const fileValue = data.env?.[key];
if (fileValue !== undefined) return fileValue;
}
} catch {
// Fail silently - fall through to env var
}
return process.env[key] || defaultValue;
}
+3 -1
View File
@@ -3,6 +3,7 @@ import { homedir } from 'os';
import { existsSync, mkdirSync } from 'fs';
import { execSync } from 'child_process';
import { fileURLToPath } from 'url';
import { loadEarlySetting } from './early-settings.js';
// Get __dirname that works in both ESM (hooks) and CJS (worker) contexts
function getDirname(): string {
@@ -22,7 +23,8 @@ const _dirname = getDirname();
*/
// Base directories
export const DATA_DIR = process.env.CLAUDE_MEM_DATA_DIR || join(homedir(), '.claude-mem');
export const DATA_DIR = loadEarlySetting('CLAUDE_MEM_DATA_DIR', join(homedir(), '.claude-mem'));
// Note: CLAUDE_CONFIG_DIR is a Claude Code setting, not claude-mem, so leave as env var
export const CLAUDE_CONFIG_DIR = process.env.CLAUDE_CONFIG_DIR || join(homedir(), '.claude');
// Data subdirectories