11import { mkdirSync , writeFileSync , readFileSync , existsSync } from "fs" ;
22import * as path from "path" ;
3+ import * as os from "os" ;
34import { InteractiveCLI , poll } from "./interactive-cli" ;
45import { AgentTestRunner , AgentTestMatchers } from "./agent-test-runner" ;
56import {
@@ -13,6 +14,7 @@ import { throwFailure } from "./logging";
1314import { getAgentEvalsRoot , RunDirectories } from "./paths" ;
1415import { execSync } from "node:child_process" ;
1516import { ToolMockName } from "../mock/tool-mocks" ;
17+ import { appendFileSync } from "node:fs" ;
1618
1719const READY_PROMPT = "Type your message" ;
1820const INSTALL_ID = "238efa5b-efb2-44bd-9dce-9b081532681c" ;
@@ -43,7 +45,8 @@ export class GeminiCliRunner implements AgentTestRunner {
4345 private readonly cli : InteractiveCLI ;
4446 private readonly telemetryPath : string ;
4547 private readonly telemetryTimeout = 15000 ;
46- private readonly runDir : string ;
48+ readonly runDir : string ;
49+ private readonly userDir : string ;
4750
4851 // Determines which tools to start from for this turn so we don't detect tool
4952 // calls from previous turns
@@ -99,6 +102,7 @@ export class GeminiCliRunner implements AgentTestRunner {
99102 this . writeGeminiInstallId ( dirs . userDir ) ;
100103
101104 this . runDir = dirs . runDir ;
105+ this . userDir = dirs . userDir ;
102106 this . cli = new InteractiveCLI ( "gemini" , [ "--yolo" ] , {
103107 cwd : dirs . runDir ,
104108 readyPrompt : READY_PROMPT ,
@@ -122,7 +126,22 @@ export class GeminiCliRunner implements AgentTestRunner {
122126 return this . cli . type ( text ) ;
123127 }
124128
129+ async remember ( text : string ) : Promise < void > {
130+ const geminiDir = path . join ( this . userDir , ".gemini" ) ;
131+ const geminiMdFile = path . join ( geminiDir , "GEMINI.md" ) ;
132+ if ( ! existsSync ( geminiDir ) ) {
133+ mkdirSync ( geminiDir , { recursive : true } ) ;
134+ }
135+
136+ if ( ! existsSync ( geminiMdFile ) ) {
137+ writeFileSync ( geminiMdFile , "## Gemini Added Memories" + os . EOL ) ;
138+ }
125139
140+ appendFileSync ( geminiMdFile , text + os . EOL ) ;
141+ await this . type ( "/memory refresh" ) ;
142+ // Due to https://github.com/google-gemini/gemini-cli/issues/10702, we need to start a new chat
143+ await this . type ( "/clear" ) ;
144+ }
126145
127146 async exit ( ) : Promise < void > {
128147 await this . cli . kill ( ) ;
@@ -155,7 +174,7 @@ export class GeminiCliRunner implements AgentTestRunner {
155174 await this . waitForTelemetryReady ( ) ;
156175 let logs : string [ ] = [ ] ;
157176 const toolsCallsMade = await poll ( ( ) => {
158- logs = [ ]
177+ logs = [ ] ;
159178 const { success, messages } = this . checkToolCalls ( tools ) ;
160179 logs = [ ...messages ] ;
161180 return success ;
@@ -169,11 +188,10 @@ export class GeminiCliRunner implements AgentTestRunner {
169188 public async expectMemory ( text : string | RegExp ) : Promise < void > {
170189 let logs : string [ ] = [ ] ;
171190 const memoryFound = await poll ( ( ) => {
172- logs = [ ]
191+ logs = [ ] ;
173192 const { success, messages } = this . checkMemory ( text ) ;
174193 logs = [ ...messages ] ;
175- return success
176-
194+ return success ;
177195 } , this . telemetryTimeout ) ;
178196
179197 if ( ! memoryFound ) {
@@ -207,8 +225,8 @@ export class GeminiCliRunner implements AgentTestRunner {
207225 expectMemory : async ( text : string | RegExp ) => {
208226 const timeout = 1000 ;
209227 const found = await poll ( ( ) => {
210- const { success } = this . checkMemory ( text )
211- return success
228+ const { success } = this . checkMemory ( text ) ;
229+ return success ;
212230 } , timeout ) ;
213231
214232 if ( found ) {
@@ -322,7 +340,7 @@ export class GeminiCliRunner implements AgentTestRunner {
322340 }
323341
324342 private checkMemory ( text : string | RegExp ) : CheckResult {
325- const geminiMdPath = path . join ( this . runDir , ".gemini" , "GEMINI.md" ) ;
343+ const geminiMdPath = path . join ( this . userDir , ".gemini" , "GEMINI.md" ) ;
326344 const messages : string [ ] = [ ] ;
327345 if ( ! existsSync ( geminiMdPath ) ) {
328346 messages . push ( `GEMINI.md file not found at ${ geminiMdPath } ` ) ;
0 commit comments