mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-30 16:00:41 -07:00
fix(core): remove shell outputChunks buffer caching to prevent memory bloat and sanitize prompt input (#23751)
This commit is contained in:
@@ -45,20 +45,18 @@ function addShellCommandToGeminiHistory(
|
||||
? resultText.substring(0, MAX_OUTPUT_LENGTH) + '\n... (truncated)'
|
||||
: resultText;
|
||||
|
||||
// Escape backticks to prevent prompt injection breakouts
|
||||
const safeQuery = rawQuery.replace(/\\/g, '\\\\').replace(/\x60/g, '\\\x60');
|
||||
const safeModelContent = modelContent
|
||||
.replace(/\\/g, '\\\\')
|
||||
.replace(/\x60/g, '\\\x60');
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
geminiClient.addHistory({
|
||||
role: 'user',
|
||||
parts: [
|
||||
{
|
||||
text: `I ran the following shell command:
|
||||
\`\`\`sh
|
||||
${rawQuery}
|
||||
\`\`\`
|
||||
|
||||
This produced the following result:
|
||||
\`\`\`
|
||||
${modelContent}
|
||||
\`\`\``,
|
||||
text: `I ran the following shell command:\n\`\`\`sh\n${safeQuery}\n\`\`\`\n\nThis produced the following result:\n\`\`\`\n${safeModelContent}\n\`\`\``,
|
||||
},
|
||||
],
|
||||
});
|
||||
@@ -444,7 +442,7 @@ export const useShellCommandProcessor = (
|
||||
}
|
||||
|
||||
let mainContent: string;
|
||||
if (isBinary(result.rawOutput)) {
|
||||
if (isBinaryStream || isBinary(result.rawOutput)) {
|
||||
mainContent =
|
||||
'[Command produced binary output, which is not shown.]';
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user