mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-06-11 03:46:49 -07:00
fix(watcher): initialize status file and correct turn counting to prevent subagent loops
This commit is contained in:
@@ -618,8 +618,6 @@ export class GeminiClient {
|
||||
): AsyncGenerator<ServerGeminiStreamEvent, Turn> {
|
||||
let turn = new Turn(this.getChat(), prompt_id);
|
||||
|
||||
this.sessionTurnCount++;
|
||||
|
||||
const watcherInterval = this.config.getExperimentalWatcherInterval();
|
||||
if (
|
||||
this.config.isExperimentalWatcherEnabled() &&
|
||||
@@ -928,6 +926,7 @@ export class GeminiClient {
|
||||
): AsyncGenerator<ServerGeminiStreamEvent, Turn> {
|
||||
if (!isInvalidStreamRetry) {
|
||||
this.config.resetTurn();
|
||||
this.sessionTurnCount++;
|
||||
}
|
||||
|
||||
const hooksEnabled = this.config.getEnableHooks();
|
||||
@@ -1327,6 +1326,22 @@ export class GeminiClient {
|
||||
}
|
||||
|
||||
const interval = this.config.getExperimentalWatcherInterval();
|
||||
|
||||
const projectTempDir = this.config.storage.getProjectTempDir();
|
||||
const statusFilePath = path.join(projectTempDir, 'watcher_status.md');
|
||||
|
||||
// Ensure the file exists before the subagent tries to read it
|
||||
if (!fs.existsSync(statusFilePath)) {
|
||||
try {
|
||||
if (!fs.existsSync(projectTempDir)) {
|
||||
fs.mkdirSync(projectTempDir, { recursive: true });
|
||||
}
|
||||
fs.writeFileSync(statusFilePath, 'EMPTY', 'utf-8');
|
||||
} catch (e) {
|
||||
debugLogger.warn('Failed to initialize watcher status file', e);
|
||||
}
|
||||
}
|
||||
|
||||
const history = this.getHistory();
|
||||
// Get last N turns (approx)
|
||||
const recentHistory = history
|
||||
|
||||
@@ -137,7 +137,7 @@ describe('GeminiClient Watcher Integration', () => {
|
||||
'gemini-pro',
|
||||
);
|
||||
|
||||
clientAccess.sessionTurnCount = 0; // Will become 1 inside processTurn
|
||||
clientAccess.sessionTurnCount = 1;
|
||||
|
||||
const promptId = 'test-prompt';
|
||||
const signal = new AbortController().signal;
|
||||
@@ -214,7 +214,7 @@ describe('GeminiClient Watcher Integration', () => {
|
||||
'gemini-pro',
|
||||
);
|
||||
|
||||
clientAccess.sessionTurnCount = 0; // Will become 1 inside processTurn
|
||||
clientAccess.sessionTurnCount = 1;
|
||||
|
||||
const promptId = 'test-prompt';
|
||||
const signal = new AbortController().signal;
|
||||
@@ -323,7 +323,7 @@ describe('GeminiClient Watcher Integration', () => {
|
||||
|
||||
// Simulate 11 turns
|
||||
for (let i = 1; i <= 11; i++) {
|
||||
clientAccess.sessionTurnCount = i - 1; // Will become i inside processTurn
|
||||
clientAccess.sessionTurnCount = i;
|
||||
|
||||
const generator = clientAccess.processTurn(
|
||||
[{ text: `turn ${i}` }],
|
||||
|
||||
Reference in New Issue
Block a user