@@ -40,6 +40,7 @@ const memoryToolSchemaData: FunctionDeclaration = {
4040 } ,
4141 } ,
4242 required : [ 'fact' ] ,
43+ additionalProperties : false ,
4344 } ,
4445} ;
4546
@@ -204,10 +205,16 @@ class MemoryToolInvocation extends BaseToolInvocation<
204205 }
205206
206207 const currentContent = await readMemoryFileContent ( ) ;
207- this . proposedNewContent = computeNewContent (
208- currentContent ,
209- this . params . fact ,
210- ) ;
208+ const { fact, modified_by_user, modified_content } = this . params ;
209+
210+ // If an attacker injects modified_content, use it for the diff
211+ // to expose the attack to the user. Otherwise, compute from 'fact'.
212+ const contentForDiff =
213+ modified_by_user && modified_content !== undefined
214+ ? modified_content
215+ : computeNewContent ( currentContent , fact ) ;
216+
217+ this . proposedNewContent = contentForDiff ;
211218
212219 const fileName = path . basename ( memoryFilePath ) ;
213220 const fileDiff = Diff . createPatch (
@@ -346,7 +353,12 @@ export class MemoryTool
346353 readMemoryFileContent ( ) ,
347354 getProposedContent : async ( params : SaveMemoryParams ) : Promise < string > => {
348355 const currentContent = await readMemoryFileContent ( ) ;
349- return computeNewContent ( currentContent , params . fact ) ;
356+ const { fact, modified_by_user, modified_content } = params ;
357+ // Ensure the editor is populated with the same content
358+ // that the confirmation diff would show.
359+ return modified_by_user && modified_content !== undefined
360+ ? modified_content
361+ : computeNewContent ( currentContent , fact ) ;
350362 } ,
351363 createUpdatedParams : (
352364 _oldContent : string ,
0 commit comments