feat: 添加 Code Index MCP 提供者支持,更新相关 API 和配置

This commit is contained in:
catlog22
2025-12-25 19:58:42 +08:00
parent e8b9bcae92
commit 203100431b
7 changed files with 293 additions and 13 deletions

View File

@@ -42,6 +42,7 @@ export interface ClaudeCliToolsConfig {
nativeResume: boolean;
recursiveQuery: boolean;
cache: ClaudeCacheSettings;
codeIndexMcp: 'codexlens' | 'ace'; // Code Index MCP provider
};
}
@@ -89,7 +90,8 @@ const DEFAULT_CONFIG: ClaudeCliToolsConfig = {
injectionMode: 'auto',
defaultPrefix: '',
defaultSuffix: ''
}
},
codeIndexMcp: 'codexlens' // Default to CodexLens
}
};
@@ -298,3 +300,76 @@ export function getClaudeCliToolsInfo(projectDir: string): {
source: resolved.source
};
}
/**
* Update Code Index MCP provider and switch CLAUDE.md reference
*/
export function updateCodeIndexMcp(
projectDir: string,
provider: 'codexlens' | 'ace'
): { success: boolean; error?: string; config?: ClaudeCliToolsConfig } {
try {
// Update config
const config = loadClaudeCliTools(projectDir);
config.settings.codeIndexMcp = provider;
saveClaudeCliTools(projectDir, config);
// Update CLAUDE.md reference
const claudeMdPath = path.join(projectDir, '.claude', 'CLAUDE.md');
if (fs.existsSync(claudeMdPath)) {
let content = fs.readFileSync(claudeMdPath, 'utf-8');
// Define the file patterns
const codexlensPattern = /@~\/\.claude\/workflows\/context-tools\.md/g;
const acePattern = /@~\/\.claude\/workflows\/context-tools-ace\.md/g;
// Also handle project-level references
const codexlensPatternProject = /@\.claude\/workflows\/context-tools\.md/g;
const acePatternProject = /@\.claude\/workflows\/context-tools-ace\.md/g;
if (provider === 'ace') {
// Switch to ACE
content = content.replace(codexlensPattern, '@~/.claude/workflows/context-tools-ace.md');
content = content.replace(codexlensPatternProject, '@.claude/workflows/context-tools-ace.md');
} else {
// Switch to CodexLens
content = content.replace(acePattern, '@~/.claude/workflows/context-tools.md');
content = content.replace(acePatternProject, '@.claude/workflows/context-tools.md');
}
fs.writeFileSync(claudeMdPath, content, 'utf-8');
console.log(`[claude-cli-tools] Updated CLAUDE.md to use ${provider}`);
}
// Also update global CLAUDE.md if it exists
const globalClaudeMdPath = path.join(os.homedir(), '.claude', 'CLAUDE.md');
if (fs.existsSync(globalClaudeMdPath)) {
let content = fs.readFileSync(globalClaudeMdPath, 'utf-8');
const codexlensPattern = /@~\/\.claude\/workflows\/context-tools\.md/g;
const acePattern = /@~\/\.claude\/workflows\/context-tools-ace\.md/g;
if (provider === 'ace') {
content = content.replace(codexlensPattern, '@~/.claude/workflows/context-tools-ace.md');
} else {
content = content.replace(acePattern, '@~/.claude/workflows/context-tools.md');
}
fs.writeFileSync(globalClaudeMdPath, content, 'utf-8');
console.log(`[claude-cli-tools] Updated global CLAUDE.md to use ${provider}`);
}
return { success: true, config };
} catch (err) {
console.error('[claude-cli-tools] Error updating Code Index MCP:', err);
return { success: false, error: (err as Error).message };
}
}
/**
* Get current Code Index MCP provider
*/
export function getCodeIndexMcp(projectDir: string): 'codexlens' | 'ace' {
const config = loadClaudeCliTools(projectDir);
return config.settings.codeIndexMcp || 'codexlens';
}

View File

@@ -337,9 +337,8 @@ function buildCommand(params: {
args.push(nativeResume.sessionId);
}
// Codex resume still supports additional flags
if (dir) {
args.push('-C', dir);
}
// Note: -C is NOT used because spawn's cwd already sets the working directory
// Using both would cause path to be applied twice (e.g., codex-lens/codex-lens)
// Permission configuration based on mode:
// - analysis: --full-auto (read-only sandbox, no prompts) - safer for read operations
// - write/auto: --dangerously-bypass-approvals-and-sandbox (full access for modifications)
@@ -362,9 +361,8 @@ function buildCommand(params: {
} else {
// Standard exec mode
args.push('exec');
if (dir) {
args.push('-C', dir);
}
// Note: -C is NOT used because spawn's cwd already sets the working directory
// Using both would cause path to be applied twice (e.g., codex-lens/codex-lens)
// Permission configuration based on mode:
// - analysis: --full-auto (read-only sandbox, no prompts) - safer for read operations
// - write/auto: --dangerously-bypass-approvals-and-sandbox (full access for modifications)