From 65392a057de429e2d1933c32f9d04673ca5b52d5 Mon Sep 17 00:00:00 2001 From: Alexander Farber Date: Fri, 12 Dec 2025 11:02:29 +0100 Subject: [PATCH] Detect git commit anywhere in command, not just at start --- packages/core/src/tools/shell.test.ts | 63 +++++++++++++++++++++++++++ packages/core/src/tools/shell.ts | 6 +-- 2 files changed, 66 insertions(+), 3 deletions(-) diff --git a/packages/core/src/tools/shell.test.ts b/packages/core/src/tools/shell.test.ts index 043ab0c6..3760266a 100644 --- a/packages/core/src/tools/shell.test.ts +++ b/packages/core/src/tools/shell.test.ts @@ -768,6 +768,69 @@ describe('ShellTool', () => { {}, ); }); + + it('should add co-author when git commit is prefixed with cd command', async () => { + const command = 'cd /tmp/test && git commit -m "Test commit"'; + const invocation = shellTool.build({ command, is_background: false }); + const promise = invocation.execute(mockAbortSignal); + + resolveExecutionPromise({ + rawOutput: Buffer.from(''), + output: '', + exitCode: 0, + signal: null, + error: null, + aborted: false, + pid: 12345, + executionMethod: 'child_process', + }); + + await promise; + + expect(mockShellExecutionService).toHaveBeenCalledWith( + expect.stringContaining( + 'Co-authored-by: Qwen-Coder ', + ), + expect.any(String), + expect.any(Function), + mockAbortSignal, + false, + {}, + ); + }); + + it('should add co-author to git commit with multi-line message', async () => { + const command = `git commit -m "Fix bug + +This is a detailed description +spanning multiple lines"`; + const invocation = shellTool.build({ command, is_background: false }); + const promise = invocation.execute(mockAbortSignal); + + resolveExecutionPromise({ + rawOutput: Buffer.from(''), + output: '', + exitCode: 0, + signal: null, + error: null, + aborted: false, + pid: 12345, + executionMethod: 'child_process', + }); + + await promise; + + expect(mockShellExecutionService).toHaveBeenCalledWith( + expect.stringContaining( + 'Co-authored-by: Qwen-Coder ', + ), + expect.any(String), + expect.any(Function), + mockAbortSignal, + false, + {}, + ); + }); }); }); diff --git a/packages/core/src/tools/shell.ts b/packages/core/src/tools/shell.ts index 8ff3047e..6e92954e 100644 --- a/packages/core/src/tools/shell.ts +++ b/packages/core/src/tools/shell.ts @@ -338,9 +338,9 @@ export class ShellToolInvocation extends BaseToolInvocation< return command; } - // Check if this is a git commit command - const gitCommitPattern = /^git\s+commit/; - if (!gitCommitPattern.test(command.trim())) { + // Check if this is a git commit command (anywhere in the command, e.g., after "cd /path &&") + const gitCommitPattern = /\bgit\s+commit\b/; + if (!gitCommitPattern.test(command)) { return command; }