From 3c484782ec1d1026c8d63653e948cb041d9e3e43 Mon Sep 17 00:00:00 2001 From: DennisYu07 <617072224@qq.com> Date: Tue, 31 Mar 2026 19:32:42 +0800 Subject: [PATCH] fix: replace .claude paths with .qwen in markdown files during extension install Previously, only shell scripts (.sh) had .claude -> .qwen path replacement. Markdown files (.md) like cancel-ralph.md and help.md were missing this conversion, causing incorrect paths like .claude/ralph-loop.local.md. Now performVariableReplacement also replaces .claude directory references in markdown files using the same regex pattern as shell scripts. --- packages/core/src/extension/variables.test.ts | 28 +++++++++++++++++++ packages/core/src/extension/variables.ts | 12 ++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/packages/core/src/extension/variables.test.ts b/packages/core/src/extension/variables.test.ts index 685a70064..7f2366497 100644 --- a/packages/core/src/extension/variables.test.ts +++ b/packages/core/src/extension/variables.test.ts @@ -263,6 +263,34 @@ describe('performVariableReplacement', () => { expect(result).not.toContain('```!'); }); + it('should replace .claude with .qwen in markdown files', () => { + const extDir = path.join(testDir, 'ext'); + fs.mkdirSync(extDir, { recursive: true }); + + const mdContent = [ + '---', + 'description: "Cancel active loop"', + '---', + '', + '# Cancel', + '', + 'Check if `.claude/loop.local.md` exists.', + 'Remove the file: `rm .claude/loop.local.md`', + 'Path: `$HOME/.claude/cache`', + 'Local: `./.claude/local`', + ].join('\n'); + fs.writeFileSync(path.join(extDir, 'cancel.md'), mdContent, 'utf-8'); + + performVariableReplacement(extDir); + + const result = fs.readFileSync(path.join(extDir, 'cancel.md'), 'utf-8'); + expect(result).toContain('.qwen/loop.local.md'); + expect(result).toContain('rm .qwen/loop.local.md'); + expect(result).toContain('$HOME/.qwen/cache'); + expect(result).toContain('./.qwen/local'); + expect(result).not.toContain('.claude/'); + }); + it('should replace "role":"assistant" with "type":"assistant" in shell scripts', () => { const extDir = path.join(testDir, 'ext'); fs.mkdirSync(extDir, { recursive: true }); diff --git a/packages/core/src/extension/variables.ts b/packages/core/src/extension/variables.ts index d9c623e78..63fe7e558 100644 --- a/packages/core/src/extension/variables.ts +++ b/packages/core/src/extension/variables.ts @@ -148,16 +148,24 @@ export function performVariableReplacement(extensionPath: string): void { // Replace Markdown shell syntax ```! ... ``` with system-recognized !{...} syntax // This regex finds code blocks with ! language identifier and captures their content - const updatedMdContent = updatedContent.replace( + const syntaxUpdatedContent = updatedContent.replace( /```!(?:\s*\n)?([\s\S]*?)\n*```/g, '!{$1}', ); + // Replace references to ".claude" directory with ".qwen" in markdown files + // Only match path references (e.g., ~/.claude/, $HOME/.claude, ./.claude/) + // Avoid matching URLs, comments, or string literals containing .claude + const updatedMdContent = syntaxUpdatedContent.replace( + /(\$\{?HOME\}?\/|~\/)?\.claude(\/|$)/g, + '$1.qwen$2', + ); + // Only write if content was actually changed if (updatedMdContent !== content) { fs.writeFileSync(filePath, updatedMdContent, 'utf8'); debugLogger.debug( - `Updated variables and syntax in file: ${filePath}`, + `Updated variables, syntax, and .claude paths in file: ${filePath}`, ); } } catch (error) {