@@ -50,6 +50,7 @@ function buildConfig(): PluginConfig {
5050 iterationNudgeThreshold : 15 ,
5151 nudgeForce : "soft" ,
5252 protectedTools : [ "task" ] ,
53+ protectTags : false ,
5354 protectUserMessages : false ,
5455 } ,
5556 strategies : {
@@ -226,6 +227,123 @@ test("compress message mode batches individual message summaries", async () => {
226227 assert . match ( blocks [ 1 ] ?. summary || "" , / t a s k o u t p u t b o d y / )
227228} )
228229
230+ test ( "compress message mode appends protected prompt info" , async ( ) => {
231+ const sessionID = `ses_message_protect_tag_${ Date . now ( ) } `
232+ const rawMessages = buildMessages ( sessionID )
233+ const user = rawMessages . find ( ( message ) => message . info . id === "msg-user-1" )
234+ const part = user ?. parts [ 0 ]
235+ if ( part ?. type === "text" ) {
236+ part . text = "Investigate the issue. <protect>Always preserve release checklist.</protect>"
237+ }
238+
239+ const state = createSessionState ( )
240+ const logger = new Logger ( false )
241+ const config = buildConfig ( )
242+ config . compress . protectTags = true
243+ const tool = createCompressMessageTool ( {
244+ client : {
245+ session : {
246+ messages : async ( ) => ( { data : rawMessages } ) ,
247+ get : async ( ) => ( { data : { parentID : null } } ) ,
248+ } ,
249+ } ,
250+ state,
251+ logger,
252+ config,
253+ prompts : {
254+ reload ( ) { } ,
255+ getRuntimePrompts ( ) {
256+ return { compressMessage : "" , compressRange : "" }
257+ } ,
258+ } ,
259+ } as any )
260+
261+ await tool . execute (
262+ {
263+ topic : "Protected note" ,
264+ content : [
265+ {
266+ messageId : "m0001" ,
267+ topic : "User request note" ,
268+ summary : "Captured the user's investigation request." ,
269+ } ,
270+ ] ,
271+ } ,
272+ {
273+ ask : async ( ) => { } ,
274+ metadata : ( ) => { } ,
275+ sessionID,
276+ messageID : "msg-compress-protect-tag" ,
277+ } ,
278+ )
279+
280+ const block = Array . from ( state . prune . messages . blocksById . values ( ) ) [ 0 ]
281+ assert . match (
282+ block ?. summary || "" ,
283+ / T h e f o l l o w i n g p r o t e c t e d p r o m p t i n f o r m a t i o n w a s i n c l u d e d i n t h i s c o n v e r s a t i o n v e r b a t i m : / ,
284+ )
285+ assert . match ( block ?. summary || "" , / A l w a y s p r e s e r v e r e l e a s e c h e c k l i s t \. / )
286+ } )
287+
288+ test ( "compress message mode ignores protect tags on ignored user messages" , async ( ) => {
289+ const sessionID = `ses_message_ignored_protect_tag_${ Date . now ( ) } `
290+ const rawMessages = buildMessages ( sessionID )
291+ const user = rawMessages . find ( ( message ) => message . info . id === "msg-user-1" )
292+ const part = user ?. parts [ 0 ] as any
293+ if ( part ?. type === "text" ) {
294+ part . text = "Ignored notification. <protect>Do not preserve ignored note.</protect>"
295+ part . ignored = true
296+ }
297+
298+ const state = createSessionState ( )
299+ const logger = new Logger ( false )
300+ const config = buildConfig ( )
301+ config . compress . protectTags = true
302+ const tool = createCompressMessageTool ( {
303+ client : {
304+ session : {
305+ messages : async ( ) => ( { data : rawMessages } ) ,
306+ get : async ( ) => ( { data : { parentID : null } } ) ,
307+ } ,
308+ } ,
309+ state,
310+ logger,
311+ config,
312+ prompts : {
313+ reload ( ) { } ,
314+ getRuntimePrompts ( ) {
315+ return { compressMessage : "" , compressRange : "" }
316+ } ,
317+ } ,
318+ } as any )
319+
320+ await tool . execute (
321+ {
322+ topic : "Ignored protected note" ,
323+ content : [
324+ {
325+ messageId : "m0001" ,
326+ topic : "Ignored note" ,
327+ summary : "Captured the ignored user message." ,
328+ } ,
329+ ] ,
330+ } ,
331+ {
332+ ask : async ( ) => { } ,
333+ metadata : ( ) => { } ,
334+ sessionID,
335+ messageID : "msg-compress-ignored-protect-tag" ,
336+ } ,
337+ )
338+
339+ const block = Array . from ( state . prune . messages . blocksById . values ( ) ) [ 0 ]
340+ assert . doesNotMatch (
341+ block ?. summary || "" ,
342+ / T h e f o l l o w i n g p r o t e c t e d p r o m p t i n f o r m a t i o n w a s i n c l u d e d i n t h i s c o n v e r s a t i o n v e r b a t i m : / ,
343+ )
344+ assert . doesNotMatch ( block ?. summary || "" , / D o n o t p r e s e r v e i g n o r e d n o t e \. / )
345+ } )
346+
229347test ( "compress message mode stores call id for later duration attachment" , async ( ) => {
230348 const sessionID = `ses_message_compress_duration_${ Date . now ( ) } `
231349 const rawMessages = buildMessages ( sessionID )
0 commit comments