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:
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user