diff --git a/packages/cli/src/ui/hooks/useExecutionLifecycle.test.tsx b/packages/cli/src/ui/hooks/useExecutionLifecycle.test.tsx index b472114c35..410778514a 100644 --- a/packages/cli/src/ui/hooks/useExecutionLifecycle.test.tsx +++ b/packages/cli/src/ui/hooks/useExecutionLifecycle.test.tsx @@ -256,7 +256,7 @@ describe('useExecutionLifecycle', () => { }); const tmpFile = path.join('/tmp/gemini-shell-abcdef', 'pwd.tmp'); const escapedTmpFile = escapeShellArg(tmpFile, 'bash'); - const wrappedCommand = `{\nls -l\n}; __code=$?; pwd > ${escapedTmpFile}; exit $__code`; + const wrappedCommand = `{\nls -l\n}\n__code=$?; pwd > ${escapedTmpFile}; exit $__code`; expect(mockShellExecutionService).toHaveBeenCalledWith( wrappedCommand, '/test/dir', @@ -367,7 +367,7 @@ describe('useExecutionLifecycle', () => { const tmpFile = path.join('/tmp/gemini-shell-abcdef', 'pwd.tmp'); const escapedTmpFile = escapeShellArg(tmpFile, 'bash'); - const wrappedCommand = `{\nstream\n}; __code=$?; pwd > ${escapedTmpFile}; exit $__code`; + const wrappedCommand = `{\nstream\n}\n__code=$?; pwd > ${escapedTmpFile}; exit $__code`; expect(mockShellExecutionService).toHaveBeenCalledWith( wrappedCommand, '/test/dir', diff --git a/packages/cli/src/ui/hooks/useExecutionLifecycle.ts b/packages/cli/src/ui/hooks/useExecutionLifecycle.ts index 64dbe42a4b..884ab544de 100644 --- a/packages/cli/src/ui/hooks/useExecutionLifecycle.ts +++ b/packages/cli/src/ui/hooks/useExecutionLifecycle.ts @@ -403,7 +403,7 @@ export const useExecutionLifecycle = ( ); pwdFilePath = path.join(tmpDir, 'pwd.tmp'); const escapedPwdFilePath = escapeShellArg(pwdFilePath, 'bash'); - commandToExecute = `{\n${command}\n}; __code=$?; pwd > ${escapedPwdFilePath}; exit $__code`; + commandToExecute = `{\n${command}\n}\n__code=$?; pwd > ${escapedPwdFilePath}; exit $__code`; } onDebugMessage(`Executing in ${targetDir}: ${commandToExecute}`); diff --git a/packages/core/src/tools/shell.test.ts b/packages/core/src/tools/shell.test.ts index 431f3482de..9f83b00bb6 100644 --- a/packages/core/src/tools/shell.test.ts +++ b/packages/core/src/tools/shell.test.ts @@ -483,7 +483,7 @@ EOF`; false, expect.any(Object), ); - expect(mockShellExecutionService.mock.calls[0][0]).toMatch(/\nEOF\n\);/); + expect(mockShellExecutionService.mock.calls[0][0]).toMatch(/\nEOF\n\)\n/); }); it('should format error messages correctly', async () => { diff --git a/packages/core/src/tools/shell.ts b/packages/core/src/tools/shell.ts index d65f186343..0390f65ee4 100644 --- a/packages/core/src/tools/shell.ts +++ b/packages/core/src/tools/shell.ts @@ -112,7 +112,7 @@ export class ShellToolInvocation extends BaseToolInvocation< trimmed += ' '; } const escapedTempFilePath = escapeShellArg(tempFilePath, 'bash'); - return `(\n${trimmed}\n); __code=$?; pgrep -g 0 >${escapedTempFilePath} 2>&1; exit $__code;`; + return `(\n${trimmed}\n)\n__code=$?; pgrep -g 0 >${escapedTempFilePath} 2>&1; exit $__code;`; } private getContextualDetails(): string {