@@ -130,7 +130,7 @@ function repeatedWord(word: string, count: number): string {
130130 return Array . from ( { length : count } , ( ) => word ) . join ( " " )
131131}
132132
133- test ( "injectMessageIds tags every text part and tool output in message mode " , ( ) => {
133+ test ( "injectMessageIds injects ID once into last tool output for assistant messages " , ( ) => {
134134 const sessionID = "ses_message_priority_tags"
135135 const messages : WithParts [ ] = [
136136 {
@@ -211,30 +211,14 @@ test("injectMessageIds tags every text part and tool output in message mode", ()
211211 assert . equal ( assistantToolOne ?. type , "tool" )
212212 assert . equal ( assistantTextTwo ?. type , "text" )
213213 assert . equal ( assistantToolTwo ?. type , "tool" )
214- assert . match (
215- ( userTextOne as any ) . text ,
216- / \n \n < d c p - m e s s a g e - i d p r i o r i t y = " h i g h " > m 0 0 0 1 < \/ d c p - m e s s a g e - i d > / ,
217- )
218- assert . match (
219- ( userTextTwo as any ) . text ,
220- / \n \n < d c p - m e s s a g e - i d p r i o r i t y = " h i g h " > m 0 0 0 1 < \/ d c p - m e s s a g e - i d > / ,
221- )
222- assert . match (
223- ( assistantTextOne as any ) . text ,
224- / \n \n < d c p - m e s s a g e - i d p r i o r i t y = " l o w " > m 0 0 0 2 < \/ d c p - m e s s a g e - i d > / ,
225- )
226- assert . match (
227- ( assistantToolOne as any ) . state . output ,
228- / < d c p - m e s s a g e - i d p r i o r i t y = " l o w " > m 0 0 0 2 < \/ d c p - m e s s a g e - i d > / ,
229- )
230- assert . match (
231- ( assistantTextTwo as any ) . text ,
232- / \n \n < d c p - m e s s a g e - i d p r i o r i t y = " l o w " > m 0 0 0 2 < \/ d c p - m e s s a g e - i d > / ,
233- )
234- assert . match (
235- ( assistantToolTwo as any ) . state . output ,
236- / < d c p - m e s s a g e - i d p r i o r i t y = " l o w " > m 0 0 0 2 < \/ d c p - m e s s a g e - i d > / ,
237- )
214+ // User messages: still injected into all text parts
215+ assert . match ( ( userTextOne as any ) . text , / \n \n m 0 0 0 1 < \/ d c p - m e s s a g e - i d > / )
216+ assert . match ( ( userTextTwo as any ) . text , / \n \n m 0 0 0 1 < \/ d c p - m e s s a g e - i d > / )
217+ // Assistant messages: ID injected only once into the last tool output
218+ assert . doesNotMatch ( ( assistantTextOne as any ) . text , / d c p - m e s s a g e - i d / )
219+ assert . doesNotMatch ( ( assistantToolOne as any ) . state . output , / d c p - m e s s a g e - i d / )
220+ assert . doesNotMatch ( ( assistantTextTwo as any ) . text , / d c p - m e s s a g e - i d / )
221+ assert . match ( ( assistantToolTwo as any ) . state . output , / m 0 0 0 2 < \/ d c p - m e s s a g e - i d > / )
238222} )
239223
240224test ( "injectMessageIds marks every protected user text part as BLOCKED in message mode" , ( ) => {
@@ -290,7 +274,7 @@ test("injectMessageIds marks every protected user text part as BLOCKED in messag
290274 )
291275} )
292276
293- test ( "injectMessageIds tags every text part and tool output in range mode" , ( ) => {
277+ test ( "injectMessageIds injects ID once into last tool output in range mode" , ( ) => {
294278 const sessionID = "ses_range_message_id_tags"
295279 const messages : WithParts [ ] = [
296280 buildMessage ( "msg-user-1" , "user" , sessionID , repeatedWord ( "investigate" , 6000 ) , 1 ) ,
@@ -327,10 +311,11 @@ test("injectMessageIds tags every text part and tool output in range mode", () =
327311 const assistantTextTwo = messages [ 1 ] ?. parts [ 2 ]
328312 const assistantToolTwo = messages [ 1 ] ?. parts [ 3 ]
329313
330- assert . match ( ( assistantTextOne as any ) . text , / \n \n < d c p - m e s s a g e - i d > m 0 0 0 2 < \/ d c p - m e s s a g e - i d > / )
331- assert . match ( ( assistantToolOne as any ) . state . output , / < d c p - m e s s a g e - i d > m 0 0 0 2 < \/ d c p - m e s s a g e - i d > / )
332- assert . match ( ( assistantTextTwo as any ) . text , / \n \n < d c p - m e s s a g e - i d > m 0 0 0 2 < \/ d c p - m e s s a g e - i d > / )
333- assert . match ( ( assistantToolTwo as any ) . state . output , / < d c p - m e s s a g e - i d > m 0 0 0 2 < \/ d c p - m e s s a g e - i d > / )
314+ // Only the last tool output gets the ID
315+ assert . doesNotMatch ( ( assistantTextOne as any ) . text , / d c p - m e s s a g e - i d / )
316+ assert . doesNotMatch ( ( assistantToolOne as any ) . state . output , / d c p - m e s s a g e - i d / )
317+ assert . doesNotMatch ( ( assistantTextTwo as any ) . text , / d c p - m e s s a g e - i d / )
318+ assert . match ( ( assistantToolTwo as any ) . state . output , / m 0 0 0 2 < \/ d c p - m e s s a g e - i d > / )
334319} )
335320
336321test ( "message mode marks compress tool messages as high priority even when short" , ( ) => {
@@ -370,10 +355,9 @@ test("message mode marks compress tool messages as high priority even when short
370355 const assistantText = messages [ 1 ] ?. parts [ 0 ]
371356 const assistantTool = messages [ 1 ] ?. parts [ 1 ]
372357
373- assert . match (
374- ( assistantText as any ) . text ,
375- / \n \n < d c p - m e s s a g e - i d p r i o r i t y = " h i g h " > m 0 0 0 2 < \/ d c p - m e s s a g e - i d > / ,
376- )
358+ // ID injected only into the last (only) tool output, not the text part
359+ assert . doesNotMatch ( ( assistantText as any ) . text , / d c p - m e s s a g e - i d / )
360+ assert . match ( ( assistantTool as any ) . state . output , / m 0 0 0 2 < \/ d c p - m e s s a g e - i d > / )
377361 assert . match (
378362 ( assistantTool as any ) . state . output ,
379363 / < d c p - m e s s a g e - i d p r i o r i t y = " h i g h " > m 0 0 0 2 < \/ d c p - m e s s a g e - i d > / ,
@@ -628,7 +612,7 @@ test("range-mode nudges skip assistant with only pending tool parts (issue #463)
628612 assert . equal ( messages [ 1 ] ?. parts [ 0 ] ?. type , "tool" )
629613} )
630614
631- test ( "range-mode nudges append to an assistant empty text part (issue #463)" , ( ) => {
615+ test ( "range-mode nudges skip assistant messages with only empty text parts (issue #463)" , ( ) => {
632616 const sessionID = "ses_range_nudge_empty_text"
633617 const messages : WithParts [ ] = [
634618 buildMessage ( "msg-user-1" , "user" , sessionID , "Hello" , 1 ) ,
@@ -653,16 +637,14 @@ test("range-mode nudges append to an assistant empty text part (issue #463)", ()
653637 system : "" ,
654638 compressRange : "" ,
655639 compressMessage : "" ,
656- contextLimitNudge : "<dcp-system-reminder>Base context nudge</dcp-system-reminder> " ,
657- turnNudge : "<dcp-system-reminder>Base turn nudge</dcp-system-reminder> " ,
658- iterationNudge : "<dcp-system-reminder>Base iteration nudge</dcp-system-reminder> " ,
640+ contextLimitNudge : "" ,
641+ turnNudge : "" ,
642+ iterationNudge : "" ,
659643 } )
660644
645+ // Empty text parts should not receive nudge injection
661646 assert . equal ( messages [ 1 ] ?. parts . length , 1 )
662- assert . match (
663- ( messages [ 1 ] ?. parts [ 0 ] as any ) . text ,
664- / < d c p - s y s t e m - r e m i n d e r > B a s e c o n t e x t n u d g e [ \s \S ] * C o m p r e s s e d b l o c k c o n t e x t : / ,
665- )
647+ assert . equal ( ( messages [ 1 ] ?. parts [ 0 ] as any ) . text , "" )
666648} )
667649
668650test ( "message-mode rendered compressed summaries mark block IDs as BLOCKED" , ( ) => {
0 commit comments