From faf32b5086c2a81c909a780a44b6bfc1b4544684 Mon Sep 17 00:00:00 2001 From: catlog22 Date: Thu, 8 Jan 2026 20:27:09 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=94=B9=E4=B8=BA=E5=9C=A8=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E6=9C=AB=E5=B0=BE=E6=B7=BB=E5=8A=A0=E7=8B=AC=E7=AB=8B?= =?UTF-8?q?=E7=AB=A0=E8=8A=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 启用时添加 "## 中文回复" 章节到文件末尾 - 禁用时移除整个章节 - 不再依赖标题匹配 --- ccw/src/core/routes/claude-routes.ts | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/ccw/src/core/routes/claude-routes.ts b/ccw/src/core/routes/claude-routes.ts index 884c2a19..80e3f05a 100644 --- a/ccw/src/core/routes/claude-routes.ts +++ b/ccw/src/core/routes/claude-routes.ts @@ -918,14 +918,10 @@ export async function handleClaudeRoutes(ctx: RouteContext): Promise { const isCodex = target === 'codex'; const targetDir = isCodex ? join(homedir(), '.codex') : join(homedir(), '.claude'); const targetFile = isCodex ? join(targetDir, 'AGENTS.md') : join(targetDir, 'CLAUDE.md'); - const headerText = isCodex ? '# Codex Code Guidelines\n\n' : '# Claude Instructions\n\n'; - // Match common header patterns for both tools - const headerPattern = isCodex - ? /^#\s*(Codex\s*(Code\s*)?(Guidelines|Instructions))\n\n?/i - : /^#\s*Claude\s*Instructions\n\n?/i; const chineseRefLine = `- **中文回复准则**: @${guidelinesRef}`; const chineseRefPattern = /^- \*\*中文回复准则\*\*:.*chinese-response\.md.*$/gm; + const chineseSectionPattern = /\n*## 中文回复\n+- \*\*中文回复准则\*\*:.*chinese-response\.md.*\n*/gm; // Ensure target directory exists if (!existsSync(targetDir)) { @@ -936,7 +932,8 @@ export async function handleClaudeRoutes(ctx: RouteContext): Promise { if (existsSync(targetFile)) { content = readFileSync(targetFile, 'utf8'); } else { - // Create new file with header + // Create new file with minimal header + const headerText = isCodex ? '# Codex Code Guidelines\n\n' : '# Claude Instructions\n\n'; content = headerText; } @@ -946,18 +943,12 @@ export async function handleClaudeRoutes(ctx: RouteContext): Promise { return { success: true, message: 'Already enabled' }; } - // Add reference after the header line or at the beginning - const headerMatch = content.match(headerPattern); - if (headerMatch) { - const insertPosition = headerMatch[0].length; - content = content.slice(0, insertPosition) + chineseRefLine + '\n' + content.slice(insertPosition); - } else { - // Add header and reference - content = headerText + chineseRefLine + '\n' + content; - } + // Add new section at the end of file + const newSection = `\n## 中文回复\n\n${chineseRefLine}\n`; + content = content.trimEnd() + '\n' + newSection; } else { - // Remove reference - content = content.replace(chineseRefPattern, '').replace(/\n{3,}/g, '\n\n').trim(); + // Remove the entire section + content = content.replace(chineseSectionPattern, '\n').replace(/\n{3,}/g, '\n\n').trim(); if (content) content += '\n'; }