@@ -905,6 +905,7 @@ describe("createCliJsonlStreamingParser", () => {
905905 sessionIdFields : [ "session_id" ] ,
906906 } ,
907907 providerId : "claude-cli" ,
908+ classifyCommentaryText : true ,
908909 onAssistantDelta : ( delta ) => deltas . push ( { text : delta . text , delta : delta . delta } ) ,
909910 onCommentaryText : ( text ) => commentaryTexts . push ( text ) ,
910911 } ) ;
@@ -939,8 +940,93 @@ describe("createCliJsonlStreamingParser", () => {
939940 parser . finish ( ) ;
940941
941942 expect ( commentaryTexts ) . toEqual ( [ "Let me check that for you." ] ) ;
942- expect ( deltas ) . toHaveLength ( 2 ) ;
943- expect ( deltas [ 1 ] ?. text ) . toBe ( "Let me check that for you." ) ;
943+ expect ( deltas ) . toEqual ( [ ] ) ;
944+ } ) ;
945+
946+ it ( "flushes Claude text as an assistant delta when no tool follows" , ( ) => {
947+ const commentaryTexts : string [ ] = [ ] ;
948+ const deltas : Array < { text : string ; delta : string } > = [ ] ;
949+ const parser = createCliJsonlStreamingParser ( {
950+ backend : {
951+ command : "claude" ,
952+ output : "jsonl" ,
953+ jsonlDialect : "claude-stream-json" ,
954+ sessionIdFields : [ "session_id" ] ,
955+ } ,
956+ providerId : "claude-cli" ,
957+ classifyCommentaryText : true ,
958+ onAssistantDelta : ( delta ) => deltas . push ( { text : delta . text , delta : delta . delta } ) ,
959+ onCommentaryText : ( text ) => commentaryTexts . push ( text ) ,
960+ } ) ;
961+
962+ parser . push (
963+ [
964+ JSON . stringify ( { type : "init" , session_id : "session-answer" } ) ,
965+ JSON . stringify ( {
966+ type : "stream_event" ,
967+ event : {
968+ type : "content_block_delta" ,
969+ delta : { type : "text_delta" , text : "Final " } ,
970+ } ,
971+ } ) ,
972+ JSON . stringify ( {
973+ type : "stream_event" ,
974+ event : {
975+ type : "content_block_delta" ,
976+ delta : { type : "text_delta" , text : "answer." } ,
977+ } ,
978+ } ) ,
979+ JSON . stringify ( {
980+ type : "stream_event" ,
981+ event : {
982+ type : "message_stop" ,
983+ } ,
984+ } ) ,
985+ ] . join ( "\n" ) + "\n" ,
986+ ) ;
987+ parser . finish ( ) ;
988+
989+ expect ( commentaryTexts ) . toEqual ( [ ] ) ;
990+ expect ( deltas ) . toEqual ( [ { text : "Final answer." , delta : "Final answer." } ] ) ;
991+ } ) ;
992+
993+ it ( "drops Claude commentary text when classification is enabled without delivery" , ( ) => {
994+ const deltas : Array < { text : string ; delta : string } > = [ ] ;
995+ const parser = createCliJsonlStreamingParser ( {
996+ backend : {
997+ command : "claude" ,
998+ output : "jsonl" ,
999+ jsonlDialect : "claude-stream-json" ,
1000+ sessionIdFields : [ "session_id" ] ,
1001+ } ,
1002+ providerId : "claude-cli" ,
1003+ classifyCommentaryText : true ,
1004+ onAssistantDelta : ( delta ) => deltas . push ( { text : delta . text , delta : delta . delta } ) ,
1005+ } ) ;
1006+
1007+ parser . push (
1008+ [
1009+ JSON . stringify ( { type : "init" , session_id : "session-drop-commentary" } ) ,
1010+ JSON . stringify ( {
1011+ type : "stream_event" ,
1012+ event : {
1013+ type : "content_block_delta" ,
1014+ delta : { type : "text_delta" , text : "Let me inspect the repo." } ,
1015+ } ,
1016+ } ) ,
1017+ JSON . stringify ( {
1018+ type : "stream_event" ,
1019+ event : {
1020+ type : "content_block_start" ,
1021+ index : 1 ,
1022+ content_block : { type : "tool_use" , id : "toolu_1" , name : "Read" , input : { } } ,
1023+ } ,
1024+ } ) ,
1025+ ] . join ( "\n" ) + "\n" ,
1026+ ) ;
1027+ parser . finish ( ) ;
1028+
1029+ expect ( deltas ) . toEqual ( [ ] ) ;
9441030 } ) ;
9451031
9461032 it ( "does not fire onCommentaryText when no text precedes tool_use" , ( ) => {
@@ -953,6 +1039,7 @@ describe("createCliJsonlStreamingParser", () => {
9531039 sessionIdFields : [ "session_id" ] ,
9541040 } ,
9551041 providerId : "claude-cli" ,
1042+ classifyCommentaryText : true ,
9561043 onAssistantDelta : ( ) => undefined ,
9571044 onCommentaryText : ( text ) => commentaryTexts . push ( text ) ,
9581045 } ) ;
@@ -985,6 +1072,7 @@ describe("createCliJsonlStreamingParser", () => {
9851072 sessionIdFields : [ "session_id" ] ,
9861073 } ,
9871074 providerId : "claude-cli" ,
1075+ classifyCommentaryText : true ,
9881076 onAssistantDelta : ( ) => undefined ,
9891077 onCommentaryText : ( text ) => commentaryTexts . push ( text ) ,
9901078 } ) ;
@@ -1032,6 +1120,7 @@ describe("createCliJsonlStreamingParser", () => {
10321120 sessionIdFields : [ "session_id" ] ,
10331121 } ,
10341122 providerId : "claude-cli" ,
1123+ classifyCommentaryText : true ,
10351124 onAssistantDelta : ( ) => undefined ,
10361125 onCommentaryText : ( text ) => commentaryTexts . push ( text ) ,
10371126 } ) ;
0 commit comments