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