mirror of
https://github.com/catlog22/Claude-Code-Workflow.git
synced 2026-02-10 02:24:35 +08:00
feat: Enhance CodexLens indexing and search capabilities with new CLI options and improved error handling
This commit is contained in:
@@ -815,13 +815,10 @@ export async function handleClaudeRoutes(ctx: RouteContext): Promise<boolean> {
|
||||
enabled = chineseRefPattern.test(content);
|
||||
}
|
||||
|
||||
// Find guidelines file path (project or user level)
|
||||
const projectGuidelinesPath = join(initialPath, '.claude', 'workflows', 'chinese-response.md');
|
||||
// Find guidelines file path - always use user-level path
|
||||
const userGuidelinesPath = join(homedir(), '.claude', 'workflows', 'chinese-response.md');
|
||||
|
||||
if (existsSync(projectGuidelinesPath)) {
|
||||
guidelinesPath = projectGuidelinesPath;
|
||||
} else if (existsSync(userGuidelinesPath)) {
|
||||
if (existsSync(userGuidelinesPath)) {
|
||||
guidelinesPath = userGuidelinesPath;
|
||||
}
|
||||
|
||||
@@ -853,21 +850,15 @@ export async function handleClaudeRoutes(ctx: RouteContext): Promise<boolean> {
|
||||
const userClaudePath = join(homedir(), '.claude', 'CLAUDE.md');
|
||||
const userClaudeDir = join(homedir(), '.claude');
|
||||
|
||||
// Find guidelines file path
|
||||
const projectGuidelinesPath = join(initialPath, '.claude', 'workflows', 'chinese-response.md');
|
||||
// Find guidelines file path - always use user-level path with ~ shorthand
|
||||
const userGuidelinesPath = join(homedir(), '.claude', 'workflows', 'chinese-response.md');
|
||||
|
||||
let guidelinesRef = '';
|
||||
if (existsSync(projectGuidelinesPath)) {
|
||||
// Use project-level guidelines with absolute path
|
||||
guidelinesRef = projectGuidelinesPath.replace(/\\/g, '/');
|
||||
} else if (existsSync(userGuidelinesPath)) {
|
||||
// Use user-level guidelines with ~ shorthand
|
||||
guidelinesRef = '~/.claude/workflows/chinese-response.md';
|
||||
} else {
|
||||
return { error: 'Chinese response guidelines file not found', status: 404 };
|
||||
if (!existsSync(userGuidelinesPath)) {
|
||||
return { error: 'Chinese response guidelines file not found at ~/.claude/workflows/chinese-response.md', status: 404 };
|
||||
}
|
||||
|
||||
const guidelinesRef = '~/.claude/workflows/chinese-response.md';
|
||||
|
||||
const chineseRefLine = `- **中文回复准则**: @${guidelinesRef}`;
|
||||
const chineseRefPattern = /^- \*\*中文回复准则\*\*:.*chinese-response\.md.*$/gm;
|
||||
|
||||
@@ -922,5 +913,118 @@ export async function handleClaudeRoutes(ctx: RouteContext): Promise<boolean> {
|
||||
return true;
|
||||
}
|
||||
|
||||
// API: Get Windows platform setting status
|
||||
if (pathname === '/api/language/windows-platform' && req.method === 'GET') {
|
||||
try {
|
||||
const userClaudePath = join(homedir(), '.claude', 'CLAUDE.md');
|
||||
const windowsRefPattern = /@.*windows-platform\.md/i;
|
||||
|
||||
let enabled = false;
|
||||
let guidelinesPath = '';
|
||||
|
||||
// Check if user CLAUDE.md exists and contains Windows platform reference
|
||||
if (existsSync(userClaudePath)) {
|
||||
const content = readFileSync(userClaudePath, 'utf8');
|
||||
enabled = windowsRefPattern.test(content);
|
||||
}
|
||||
|
||||
// Find guidelines file path - always use user-level path
|
||||
const userGuidelinesPath = join(homedir(), '.claude', 'workflows', 'windows-platform.md');
|
||||
|
||||
if (existsSync(userGuidelinesPath)) {
|
||||
guidelinesPath = userGuidelinesPath;
|
||||
}
|
||||
|
||||
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||
res.end(JSON.stringify({
|
||||
enabled,
|
||||
guidelinesPath,
|
||||
guidelinesExists: !!guidelinesPath,
|
||||
userClaudeMdExists: existsSync(userClaudePath)
|
||||
}));
|
||||
return true;
|
||||
} catch (error) {
|
||||
res.writeHead(500, { 'Content-Type': 'application/json' });
|
||||
res.end(JSON.stringify({ error: (error as Error).message }));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// API: Toggle Windows platform setting
|
||||
if (pathname === '/api/language/windows-platform' && req.method === 'POST') {
|
||||
handlePostRequest(req, res, async (body: any) => {
|
||||
const { enabled } = body;
|
||||
|
||||
if (typeof enabled !== 'boolean') {
|
||||
return { error: 'Missing or invalid enabled parameter', status: 400 };
|
||||
}
|
||||
|
||||
try {
|
||||
const userClaudePath = join(homedir(), '.claude', 'CLAUDE.md');
|
||||
const userClaudeDir = join(homedir(), '.claude');
|
||||
|
||||
// Find guidelines file path - always use user-level path with ~ shorthand
|
||||
const userGuidelinesPath = join(homedir(), '.claude', 'workflows', 'windows-platform.md');
|
||||
|
||||
if (!existsSync(userGuidelinesPath)) {
|
||||
return { error: 'Windows platform guidelines file not found at ~/.claude/workflows/windows-platform.md', status: 404 };
|
||||
}
|
||||
|
||||
const guidelinesRef = '~/.claude/workflows/windows-platform.md';
|
||||
|
||||
const windowsRefLine = `- **Windows Platform**: @${guidelinesRef}`;
|
||||
const windowsRefPattern = /^- \*\*Windows Platform\*\*:.*windows-platform\.md.*$/gm;
|
||||
|
||||
// Ensure user .claude directory exists
|
||||
if (!existsSync(userClaudeDir)) {
|
||||
const fs = require('fs');
|
||||
fs.mkdirSync(userClaudeDir, { recursive: true });
|
||||
}
|
||||
|
||||
let content = '';
|
||||
if (existsSync(userClaudePath)) {
|
||||
content = readFileSync(userClaudePath, 'utf8');
|
||||
} else {
|
||||
// Create new CLAUDE.md with header
|
||||
content = '# Claude Instructions\n\n';
|
||||
}
|
||||
|
||||
if (enabled) {
|
||||
// Check if reference already exists
|
||||
if (windowsRefPattern.test(content)) {
|
||||
return { success: true, message: 'Already enabled' };
|
||||
}
|
||||
|
||||
// Add reference after the header line or at the beginning
|
||||
const headerMatch = content.match(/^# Claude Instructions\n\n?/);
|
||||
if (headerMatch) {
|
||||
const insertPosition = headerMatch[0].length;
|
||||
content = content.slice(0, insertPosition) + windowsRefLine + '\n' + content.slice(insertPosition);
|
||||
} else {
|
||||
// Add header and reference
|
||||
content = '# Claude Instructions\n\n' + windowsRefLine + '\n' + content;
|
||||
}
|
||||
} else {
|
||||
// Remove reference
|
||||
content = content.replace(windowsRefPattern, '').replace(/\n{3,}/g, '\n\n').trim();
|
||||
if (content) content += '\n';
|
||||
}
|
||||
|
||||
writeFileSync(userClaudePath, content, 'utf8');
|
||||
|
||||
// Broadcast update
|
||||
broadcastToClients({
|
||||
type: 'LANGUAGE_SETTING_CHANGED',
|
||||
data: { windowsPlatform: enabled }
|
||||
});
|
||||
|
||||
return { success: true, enabled };
|
||||
} catch (error) {
|
||||
return { error: (error as Error).message, status: 500 };
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -384,17 +384,23 @@ export async function handleCodexLensRoutes(ctx: RouteContext): Promise<boolean>
|
||||
// API: CodexLens Init (Initialize workspace index)
|
||||
if (pathname === '/api/codexlens/init' && req.method === 'POST') {
|
||||
handlePostRequest(req, res, async (body) => {
|
||||
const { path: projectPath } = body;
|
||||
const { path: projectPath, indexType = 'vector' } = body;
|
||||
const targetPath = projectPath || initialPath;
|
||||
|
||||
// Build CLI arguments based on index type
|
||||
const args = ['init', targetPath, '--json'];
|
||||
if (indexType === 'normal') {
|
||||
args.push('--no-embeddings');
|
||||
}
|
||||
|
||||
// Broadcast start event
|
||||
broadcastToClients({
|
||||
type: 'CODEXLENS_INDEX_PROGRESS',
|
||||
payload: { stage: 'start', message: 'Starting index...', percent: 0, path: targetPath }
|
||||
payload: { stage: 'start', message: 'Starting index...', percent: 0, path: targetPath, indexType }
|
||||
});
|
||||
|
||||
try {
|
||||
const result = await executeCodexLens(['init', targetPath, '--json'], {
|
||||
const result = await executeCodexLens(args, {
|
||||
cwd: targetPath,
|
||||
timeout: 1800000, // 30 minutes for large codebases
|
||||
onProgress: (progress: ProgressInfo) => {
|
||||
|
||||
Reference in New Issue
Block a user