@@ -17,6 +17,7 @@ function event(type: string, data: unknown): ReactorEmittedEvent {
1717function observeOneTurnWithToolResult (
1818 collector : ReturnType < typeof createTurnContextCollector > ,
1919 toolResultContent : string ,
20+ toolResultDetail ?: unknown ,
2021) : void {
2122 collector . observe (
2223 event ( "inference.done" , {
@@ -34,7 +35,11 @@ function observeOneTurnWithToolResult(
3435 ) ;
3536 collector . observe (
3637 event ( "tool.done" , {
37- result : { callId : "call-1" , content : toolResultContent } ,
38+ result : {
39+ callId : "call-1" ,
40+ content : toolResultContent ,
41+ ...( toolResultDetail !== undefined ? { detail : toolResultDetail } : { } ) ,
42+ } ,
3843 } ) ,
3944 ) ;
4045}
@@ -64,6 +69,33 @@ describe("createTurnContextCollector tool result truncation", () => {
6469 const [ turn ] = collector . getTurns ( ) ;
6570 expect ( turn ?. toolResults [ 0 ] ?. content ) . toBe ( smallOutput ) ;
6671 } ) ;
72+
73+ test ( "preserves small structured detail in hook payloads" , ( ) => {
74+ const collector = createTurnContextCollector ( ( ) => undefined ) ;
75+ const detail = { answer : 42 } ;
76+
77+ observeOneTurnWithToolResult ( collector , "exit code 0" , detail ) ;
78+
79+ const [ turn ] = collector . getTurns ( ) ;
80+ expect ( turn ?. toolResults [ 0 ] ?. detail ) . toEqual ( detail ) ;
81+ } ) ;
82+
83+ test ( "omits oversized structured detail while keeping the content cap" , ( ) => {
84+ const collector = createTurnContextCollector ( ( ) => undefined ) ;
85+ const hugeOutput = "x" . repeat ( HOOK_PAYLOAD_TOOL_RESULT_CHARS * 4 ) ;
86+ const hugeDetail = { blob : "y" . repeat ( HOOK_PAYLOAD_TOOL_RESULT_CHARS * 4 ) } ;
87+
88+ observeOneTurnWithToolResult ( collector , hugeOutput , hugeDetail ) ;
89+
90+ const [ turn ] = collector . getTurns ( ) ;
91+ const result = turn ?. toolResults [ 0 ] ;
92+ expect ( result ?. detail ) . toBeUndefined ( ) ;
93+ const content = result ?. content ;
94+ expect ( typeof content ) . toBe ( "string" ) ;
95+ expect ( ( content as string ) . length ) . toBeLessThanOrEqual (
96+ HOOK_PAYLOAD_TOOL_RESULT_CHARS + 64 ,
97+ ) ;
98+ } ) ;
6799} ) ;
68100
69101describe ( "lifecycle hook payload delivery" , ( ) => {
0 commit comments