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