fix(ui): Use execFile with absolute path to run gemini --output

This commit is contained in:
Castor Gemini 2025-08-22 08:16:56 -05:00 committed by Jeff Carr
parent 1e7a6d9e1e
commit 314cd07836
1 changed files with 10 additions and 18 deletions

View File

@ -4,9 +4,10 @@
* SPDX-License-Identifier: Apache-2.0
*/
import { appendFileSync } from 'fs';
import React, { useEffect } from 'react';
import { Text, Box } from 'ink';
import { exec } from 'child_process';
import { execFile } from 'child_process';
import { MarkdownDisplay } from '../../utils/MarkdownDisplay.js';
import { Colors } from '../../colors.js';
import { SCREEN_READER_MODEL_PREFIX } from '../../constants.js';
@ -25,33 +26,23 @@ export const GeminiMessage: React.FC<GeminiMessageProps> = ({
terminalWidth,
}) => {
// --- Start of Modification ---
// Use a useEffect hook to trigger a side effect when the component renders
// with new text. This is the correct way to handle non-UI logic in React.
useEffect(() => {
// Don't execute for pending or empty responses.
if (isPending || !text) {
return;
}
// The command to run.
const commandToRun = 'gemini --output';
// Use the absolute path to the gemini binary to avoid PATH issues.
const command = '/home/jcarr/go/bin/gemini';
const args = ['--output', text];
// IMPORTANT: Pass the AI's message via an environment variable
// to prevent shell injection vulnerabilities.
const options = {
env: {
...process.env,
GEMINI_MESSAGE: text,
},
};
exec(commandToRun, options, (error, stdout, stderr) => {
execFile(command, args, (error, stdout, stderr) => {
if (error) {
// Display errors in the debug console for visibility.
console.error(`exec error: ${error.message}`);
// For debugging, you can log errors to a file.
// appendFileSync('/tmp/gemini-cli-debug.log', `execFile error: ${error.message}\n`);
console.error(`execFile error: ${error.message}`);
return;
}
// You could also display stdout or stderr if needed.
});
}, [text, isPending]); // This hook re-runs only when `text` or `isPending` changes.
// --- End of Modification ---
@ -80,3 +71,4 @@ export const GeminiMessage: React.FC<GeminiMessageProps> = ({
</Box>
);
};