mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-10 22:21:22 -07:00
Move temp dir from system prompt to first user msg (#12895)
This commit is contained in:
committed by
GitHub
parent
c1076512d1
commit
2e2b066713
@@ -57,8 +57,8 @@ IT IS CRITICAL TO FOLLOW THESE GUIDELINES TO AVOID EXCESSIVE TOKEN CONSUMPTION.
|
||||
- Aim to minimize tool output tokens while still capturing necessary information.
|
||||
- If a command is expected to produce a lot of output, use quiet or silent flags where available and appropriate.
|
||||
- Always consider the trade-off between output verbosity and the need for information. If a command's full output is essential for understanding the result, avoid overly aggressive quieting that might obscure important details.
|
||||
- If a command does not have quiet/silent flags or for commands with potentially long output that may not be useful, redirect stdout and stderr to temp files in the project's temporary directory: /tmp/project-temp. For example: 'command > /tmp/project-temp/out.log 2> /tmp/project-temp/err.log'.
|
||||
- After the command runs, inspect the temp files (e.g. '/tmp/project-temp/out.log' and '/tmp/project-temp/err.log') using commands like 'grep', 'tail', 'head', ... (or platform equivalents). Remove the temp files when done.
|
||||
- If a command does not have quiet/silent flags or for commands with potentially long output that may not be useful, redirect stdout and stderr to temp files in the project's temporary directory. For example: 'command > <temp_dir>/out.log 2> <temp_dir>/err.log'.
|
||||
- After the command runs, inspect the temp files (e.g. '<temp_dir>/out.log' and '<temp_dir>/err.log') using commands like 'grep', 'tail', 'head', ... (or platform equivalents). Remove the temp files when done.
|
||||
|
||||
|
||||
## Tone and Style (CLI Interaction)
|
||||
@@ -159,8 +159,8 @@ IT IS CRITICAL TO FOLLOW THESE GUIDELINES TO AVOID EXCESSIVE TOKEN CONSUMPTION.
|
||||
- Aim to minimize tool output tokens while still capturing necessary information.
|
||||
- If a command is expected to produce a lot of output, use quiet or silent flags where available and appropriate.
|
||||
- Always consider the trade-off between output verbosity and the need for information. If a command's full output is essential for understanding the result, avoid overly aggressive quieting that might obscure important details.
|
||||
- If a command does not have quiet/silent flags or for commands with potentially long output that may not be useful, redirect stdout and stderr to temp files in the project's temporary directory: /tmp/project-temp. For example: 'command > /tmp/project-temp/out.log 2> /tmp/project-temp/err.log'.
|
||||
- After the command runs, inspect the temp files (e.g. '/tmp/project-temp/out.log' and '/tmp/project-temp/err.log') using commands like 'grep', 'tail', 'head', ... (or platform equivalents). Remove the temp files when done.
|
||||
- If a command does not have quiet/silent flags or for commands with potentially long output that may not be useful, redirect stdout and stderr to temp files in the project's temporary directory. For example: 'command > <temp_dir>/out.log 2> <temp_dir>/err.log'.
|
||||
- After the command runs, inspect the temp files (e.g. '<temp_dir>/out.log' and '<temp_dir>/err.log') using commands like 'grep', 'tail', 'head', ... (or platform equivalents). Remove the temp files when done.
|
||||
|
||||
|
||||
## Tone and Style (CLI Interaction)
|
||||
@@ -271,8 +271,8 @@ IT IS CRITICAL TO FOLLOW THESE GUIDELINES TO AVOID EXCESSIVE TOKEN CONSUMPTION.
|
||||
- Aim to minimize tool output tokens while still capturing necessary information.
|
||||
- If a command is expected to produce a lot of output, use quiet or silent flags where available and appropriate.
|
||||
- Always consider the trade-off between output verbosity and the need for information. If a command's full output is essential for understanding the result, avoid overly aggressive quieting that might obscure important details.
|
||||
- If a command does not have quiet/silent flags or for commands with potentially long output that may not be useful, redirect stdout and stderr to temp files in the project's temporary directory: /tmp/project-temp. For example: 'command > /tmp/project-temp/out.log 2> /tmp/project-temp/err.log'.
|
||||
- After the command runs, inspect the temp files (e.g. '/tmp/project-temp/out.log' and '/tmp/project-temp/err.log') using commands like 'grep', 'tail', 'head', ... (or platform equivalents). Remove the temp files when done.
|
||||
- If a command does not have quiet/silent flags or for commands with potentially long output that may not be useful, redirect stdout and stderr to temp files in the project's temporary directory. For example: 'command > <temp_dir>/out.log 2> <temp_dir>/err.log'.
|
||||
- After the command runs, inspect the temp files (e.g. '<temp_dir>/out.log' and '<temp_dir>/err.log') using commands like 'grep', 'tail', 'head', ... (or platform equivalents). Remove the temp files when done.
|
||||
|
||||
|
||||
## Tone and Style (CLI Interaction)
|
||||
@@ -368,8 +368,8 @@ IT IS CRITICAL TO FOLLOW THESE GUIDELINES TO AVOID EXCESSIVE TOKEN CONSUMPTION.
|
||||
- Aim to minimize tool output tokens while still capturing necessary information.
|
||||
- If a command is expected to produce a lot of output, use quiet or silent flags where available and appropriate.
|
||||
- Always consider the trade-off between output verbosity and the need for information. If a command's full output is essential for understanding the result, avoid overly aggressive quieting that might obscure important details.
|
||||
- If a command does not have quiet/silent flags or for commands with potentially long output that may not be useful, redirect stdout and stderr to temp files in the project's temporary directory: /tmp/project-temp. For example: 'command > /tmp/project-temp/out.log 2> /tmp/project-temp/err.log'.
|
||||
- After the command runs, inspect the temp files (e.g. '/tmp/project-temp/out.log' and '/tmp/project-temp/err.log') using commands like 'grep', 'tail', 'head', ... (or platform equivalents). Remove the temp files when done.
|
||||
- If a command does not have quiet/silent flags or for commands with potentially long output that may not be useful, redirect stdout and stderr to temp files in the project's temporary directory. For example: 'command > <temp_dir>/out.log 2> <temp_dir>/err.log'.
|
||||
- After the command runs, inspect the temp files (e.g. '<temp_dir>/out.log' and '<temp_dir>/err.log') using commands like 'grep', 'tail', 'head', ... (or platform equivalents). Remove the temp files when done.
|
||||
|
||||
|
||||
## Tone and Style (CLI Interaction)
|
||||
@@ -465,8 +465,8 @@ IT IS CRITICAL TO FOLLOW THESE GUIDELINES TO AVOID EXCESSIVE TOKEN CONSUMPTION.
|
||||
- Aim to minimize tool output tokens while still capturing necessary information.
|
||||
- If a command is expected to produce a lot of output, use quiet or silent flags where available and appropriate.
|
||||
- Always consider the trade-off between output verbosity and the need for information. If a command's full output is essential for understanding the result, avoid overly aggressive quieting that might obscure important details.
|
||||
- If a command does not have quiet/silent flags or for commands with potentially long output that may not be useful, redirect stdout and stderr to temp files in the project's temporary directory: /tmp/project-temp. For example: 'command > /tmp/project-temp/out.log 2> /tmp/project-temp/err.log'.
|
||||
- After the command runs, inspect the temp files (e.g. '/tmp/project-temp/out.log' and '/tmp/project-temp/err.log') using commands like 'grep', 'tail', 'head', ... (or platform equivalents). Remove the temp files when done.
|
||||
- If a command does not have quiet/silent flags or for commands with potentially long output that may not be useful, redirect stdout and stderr to temp files in the project's temporary directory. For example: 'command > <temp_dir>/out.log 2> <temp_dir>/err.log'.
|
||||
- After the command runs, inspect the temp files (e.g. '<temp_dir>/out.log' and '<temp_dir>/err.log') using commands like 'grep', 'tail', 'head', ... (or platform equivalents). Remove the temp files when done.
|
||||
|
||||
|
||||
## Tone and Style (CLI Interaction)
|
||||
@@ -562,8 +562,8 @@ IT IS CRITICAL TO FOLLOW THESE GUIDELINES TO AVOID EXCESSIVE TOKEN CONSUMPTION.
|
||||
- Aim to minimize tool output tokens while still capturing necessary information.
|
||||
- If a command is expected to produce a lot of output, use quiet or silent flags where available and appropriate.
|
||||
- Always consider the trade-off between output verbosity and the need for information. If a command's full output is essential for understanding the result, avoid overly aggressive quieting that might obscure important details.
|
||||
- If a command does not have quiet/silent flags or for commands with potentially long output that may not be useful, redirect stdout and stderr to temp files in the project's temporary directory: /tmp/project-temp. For example: 'command > /tmp/project-temp/out.log 2> /tmp/project-temp/err.log'.
|
||||
- After the command runs, inspect the temp files (e.g. '/tmp/project-temp/out.log' and '/tmp/project-temp/err.log') using commands like 'grep', 'tail', 'head', ... (or platform equivalents). Remove the temp files when done.
|
||||
- If a command does not have quiet/silent flags or for commands with potentially long output that may not be useful, redirect stdout and stderr to temp files in the project's temporary directory. For example: 'command > <temp_dir>/out.log 2> <temp_dir>/err.log'.
|
||||
- After the command runs, inspect the temp files (e.g. '<temp_dir>/out.log' and '<temp_dir>/err.log') using commands like 'grep', 'tail', 'head', ... (or platform equivalents). Remove the temp files when done.
|
||||
|
||||
|
||||
## Tone and Style (CLI Interaction)
|
||||
@@ -659,8 +659,8 @@ IT IS CRITICAL TO FOLLOW THESE GUIDELINES TO AVOID EXCESSIVE TOKEN CONSUMPTION.
|
||||
- Aim to minimize tool output tokens while still capturing necessary information.
|
||||
- If a command is expected to produce a lot of output, use quiet or silent flags where available and appropriate.
|
||||
- Always consider the trade-off between output verbosity and the need for information. If a command's full output is essential for understanding the result, avoid overly aggressive quieting that might obscure important details.
|
||||
- If a command does not have quiet/silent flags or for commands with potentially long output that may not be useful, redirect stdout and stderr to temp files in the project's temporary directory: /tmp/project-temp. For example: 'command > /tmp/project-temp/out.log 2> /tmp/project-temp/err.log'.
|
||||
- After the command runs, inspect the temp files (e.g. '/tmp/project-temp/out.log' and '/tmp/project-temp/err.log') using commands like 'grep', 'tail', 'head', ... (or platform equivalents). Remove the temp files when done.
|
||||
- If a command does not have quiet/silent flags or for commands with potentially long output that may not be useful, redirect stdout and stderr to temp files in the project's temporary directory. For example: 'command > <temp_dir>/out.log 2> <temp_dir>/err.log'.
|
||||
- After the command runs, inspect the temp files (e.g. '<temp_dir>/out.log' and '<temp_dir>/err.log') using commands like 'grep', 'tail', 'head', ... (or platform equivalents). Remove the temp files when done.
|
||||
|
||||
|
||||
## Tone and Style (CLI Interaction)
|
||||
@@ -756,8 +756,8 @@ IT IS CRITICAL TO FOLLOW THESE GUIDELINES TO AVOID EXCESSIVE TOKEN CONSUMPTION.
|
||||
- Aim to minimize tool output tokens while still capturing necessary information.
|
||||
- If a command is expected to produce a lot of output, use quiet or silent flags where available and appropriate.
|
||||
- Always consider the trade-off between output verbosity and the need for information. If a command's full output is essential for understanding the result, avoid overly aggressive quieting that might obscure important details.
|
||||
- If a command does not have quiet/silent flags or for commands with potentially long output that may not be useful, redirect stdout and stderr to temp files in the project's temporary directory: /tmp/project-temp. For example: 'command > /tmp/project-temp/out.log 2> /tmp/project-temp/err.log'.
|
||||
- After the command runs, inspect the temp files (e.g. '/tmp/project-temp/out.log' and '/tmp/project-temp/err.log') using commands like 'grep', 'tail', 'head', ... (or platform equivalents). Remove the temp files when done.
|
||||
- If a command does not have quiet/silent flags or for commands with potentially long output that may not be useful, redirect stdout and stderr to temp files in the project's temporary directory. For example: 'command > <temp_dir>/out.log 2> <temp_dir>/err.log'.
|
||||
- After the command runs, inspect the temp files (e.g. '<temp_dir>/out.log' and '<temp_dir>/err.log') using commands like 'grep', 'tail', 'head', ... (or platform equivalents). Remove the temp files when done.
|
||||
|
||||
|
||||
## Tone and Style (CLI Interaction)
|
||||
@@ -853,8 +853,8 @@ IT IS CRITICAL TO FOLLOW THESE GUIDELINES TO AVOID EXCESSIVE TOKEN CONSUMPTION.
|
||||
- Aim to minimize tool output tokens while still capturing necessary information.
|
||||
- If a command is expected to produce a lot of output, use quiet or silent flags where available and appropriate.
|
||||
- Always consider the trade-off between output verbosity and the need for information. If a command's full output is essential for understanding the result, avoid overly aggressive quieting that might obscure important details.
|
||||
- If a command does not have quiet/silent flags or for commands with potentially long output that may not be useful, redirect stdout and stderr to temp files in the project's temporary directory: /tmp/project-temp. For example: 'command > /tmp/project-temp/out.log 2> /tmp/project-temp/err.log'.
|
||||
- After the command runs, inspect the temp files (e.g. '/tmp/project-temp/out.log' and '/tmp/project-temp/err.log') using commands like 'grep', 'tail', 'head', ... (or platform equivalents). Remove the temp files when done.
|
||||
- If a command does not have quiet/silent flags or for commands with potentially long output that may not be useful, redirect stdout and stderr to temp files in the project's temporary directory. For example: 'command > <temp_dir>/out.log 2> <temp_dir>/err.log'.
|
||||
- After the command runs, inspect the temp files (e.g. '<temp_dir>/out.log' and '<temp_dir>/err.log') using commands like 'grep', 'tail', 'head', ... (or platform equivalents). Remove the temp files when done.
|
||||
|
||||
|
||||
## Tone and Style (CLI Interaction)
|
||||
|
||||
@@ -336,6 +336,29 @@ describe('Gemini Client (client.ts)', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('startChat', () => {
|
||||
it('should include environment context when resuming a session', async () => {
|
||||
const extraHistory: Content[] = [
|
||||
{ role: 'user', parts: [{ text: 'Old message' }] },
|
||||
{ role: 'model', parts: [{ text: 'Old response' }] },
|
||||
];
|
||||
|
||||
const chat = await client.startChat(extraHistory);
|
||||
const history = chat.getHistory();
|
||||
|
||||
// The first message should be the environment context
|
||||
expect(history[0].role).toBe('user');
|
||||
expect(history[0].parts?.[0]?.text).toContain('This is the Gemini CLI');
|
||||
expect(history[0].parts?.[0]?.text).toContain(
|
||||
"The project's temporary directory is:",
|
||||
);
|
||||
|
||||
// The subsequent messages should be the extra history
|
||||
expect(history[1]).toEqual(extraHistory[0]);
|
||||
expect(history[2]).toEqual(extraHistory[1]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('tryCompressChat', () => {
|
||||
const mockGetHistory = vi.fn();
|
||||
|
||||
|
||||
@@ -192,7 +192,6 @@ Mandates').
|
||||
# Operational Guidelines
|
||||
${(function () {
|
||||
if (config.getEnableShellOutputEfficiency()) {
|
||||
const tempDir = config.storage.getProjectTempDir();
|
||||
return `
|
||||
## Shell tool output token efficiency:
|
||||
|
||||
@@ -202,17 +201,8 @@ IT IS CRITICAL TO FOLLOW THESE GUIDELINES TO AVOID EXCESSIVE TOKEN CONSUMPTION.
|
||||
- Aim to minimize tool output tokens while still capturing necessary information.
|
||||
- If a command is expected to produce a lot of output, use quiet or silent flags where available and appropriate.
|
||||
- Always consider the trade-off between output verbosity and the need for information. If a command's full output is essential for understanding the result, avoid overly aggressive quieting that might obscure important details.
|
||||
- If a command does not have quiet/silent flags or for commands with potentially long output that may not be useful, redirect stdout and stderr to temp files in the project's temporary directory: ${tempDir}. For example: 'command > ${path.posix.join(
|
||||
tempDir,
|
||||
'out.log',
|
||||
)} 2> ${path.posix.join(tempDir, 'err.log')}'.
|
||||
- After the command runs, inspect the temp files (e.g. '${path.posix.join(
|
||||
tempDir,
|
||||
'out.log',
|
||||
)}' and '${path.posix.join(
|
||||
tempDir,
|
||||
'err.log',
|
||||
)}') using commands like 'grep', 'tail', 'head', ... (or platform equivalents). Remove the temp files when done.
|
||||
- If a command does not have quiet/silent flags or for commands with potentially long output that may not be useful, redirect stdout and stderr to temp files in the project's temporary directory. For example: 'command > <temp_dir>/out.log 2> <temp_dir>/err.log'.
|
||||
- After the command runs, inspect the temp files (e.g. '<temp_dir>/out.log' and '<temp_dir>/err.log') using commands like 'grep', 'tail', 'head', ... (or platform equivalents). Remove the temp files when done.
|
||||
`;
|
||||
}
|
||||
return '';
|
||||
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
getDirectoryContextString,
|
||||
} from './environmentContext.js';
|
||||
import type { Config } from '../config/config.js';
|
||||
import type { Storage } from '../config/storage.js';
|
||||
import { getFolderStructure } from './getFolderStructure.js';
|
||||
|
||||
vi.mock('../config/config.js');
|
||||
@@ -35,6 +36,9 @@ describe('getDirectoryContextString', () => {
|
||||
getDirectories: vi.fn().mockReturnValue(['/test/dir']),
|
||||
}),
|
||||
getFileService: vi.fn(),
|
||||
storage: {
|
||||
getProjectTempDir: vi.fn().mockReturnValue('/tmp/project-temp'),
|
||||
} as unknown as Storage,
|
||||
};
|
||||
vi.mocked(getFolderStructure).mockResolvedValue('Mock Folder Structure');
|
||||
});
|
||||
@@ -90,6 +94,9 @@ describe('getEnvironmentContext', () => {
|
||||
getFileService: vi.fn(),
|
||||
|
||||
getToolRegistry: vi.fn().mockReturnValue(mockToolRegistry),
|
||||
storage: {
|
||||
getProjectTempDir: vi.fn().mockReturnValue('/tmp/project-temp'),
|
||||
} as unknown as Storage,
|
||||
};
|
||||
|
||||
vi.mocked(getFolderStructure).mockResolvedValue('Mock Folder Structure');
|
||||
|
||||
@@ -59,11 +59,13 @@ export async function getEnvironmentContext(config: Config): Promise<Part[]> {
|
||||
});
|
||||
const platform = process.platform;
|
||||
const directoryContext = await getDirectoryContextString(config);
|
||||
const tempDir = config.storage.getProjectTempDir();
|
||||
|
||||
const context = `
|
||||
This is the Gemini CLI. We are setting up the context for our chat.
|
||||
Today's date is ${today} (formatted according to the user's locale).
|
||||
My operating system is: ${platform}
|
||||
The project's temporary directory is: ${tempDir}
|
||||
${directoryContext}
|
||||
`.trim();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user