mirror of
https://github.com/tiennm99/ccs.git
synced 2026-09-03 04:17:54 +00:00
refactor(core): centralize claude paths and command parsing
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
|
||||
/**
|
||||
* Resolve Claude config directory with test/dev overrides.
|
||||
* Precedence:
|
||||
* 1. CLAUDE_CONFIG_DIR (explicit override)
|
||||
* 2. CCS_HOME compatibility path (<dirname(CCS_HOME)>/.claude)
|
||||
* 3. ~/.claude (default)
|
||||
*/
|
||||
export function getClaudeConfigDir(): string {
|
||||
if (process.env.CLAUDE_CONFIG_DIR) {
|
||||
return path.resolve(process.env.CLAUDE_CONFIG_DIR);
|
||||
}
|
||||
|
||||
if (process.env.CCS_HOME) {
|
||||
return path.join(path.dirname(path.resolve(process.env.CCS_HOME)), '.claude');
|
||||
}
|
||||
|
||||
return path.join(os.homedir(), '.claude');
|
||||
}
|
||||
|
||||
/** Resolve Claude settings.json path. */
|
||||
export function getClaudeSettingsPath(): string {
|
||||
return path.join(getClaudeConfigDir(), 'settings.json');
|
||||
}
|
||||
@@ -8,30 +8,15 @@
|
||||
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
import { info, warn } from '../ui';
|
||||
import { getWebSearchConfig } from '../../config/unified-config-loader';
|
||||
import { getCcsHooksDir } from '../config-manager';
|
||||
import { getClaudeSettingsPath } from '../claude-config-path';
|
||||
import { isCcsWebSearchHook, deduplicateCcsHooks } from './hook-utils';
|
||||
|
||||
// Hook file name
|
||||
const WEBSEARCH_HOOK = 'websearch-transformer.cjs';
|
||||
|
||||
/**
|
||||
* Get Claude settings path (respects CCS_HOME for test isolation)
|
||||
* In tests, returns path under CCS_HOME; in production, uses real ~/.claude/
|
||||
*/
|
||||
function getClaudeSettingsPath(): string {
|
||||
const ccsHome = process.env.CCS_HOME;
|
||||
if (ccsHome) {
|
||||
// Test mode: use CCS_HOME parent for .claude directory
|
||||
// This prevents tests from modifying user's real settings
|
||||
return path.join(path.dirname(ccsHome), '.claude', 'settings.json');
|
||||
}
|
||||
// Production: use real home directory
|
||||
return path.join(os.homedir(), '.claude', 'settings.json');
|
||||
}
|
||||
|
||||
// Buffer time added to max provider timeout for hook timeout (seconds)
|
||||
const HOOK_TIMEOUT_BUFFER = 30;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user