@@ -14,6 +14,7 @@ import type {
1414 MessagingToolSend ,
1515 MessagingToolSourceReplyPayload ,
1616} from "./embedded-agent-messaging.types.js" ;
17+ import type { ToolSummaryTrace } from "./embedded-agent-runner/types.js" ;
1718
1819export type CliUsage = {
1920 input ?: number ;
@@ -51,6 +52,7 @@ export type CliOutput = {
5152 usage ?: CliUsage ;
5253 /** Terminal cumulative turn usage for diagnostics; reply accounting keeps using `usage`. */
5354 diagnosticUsage ?: CliUsage ;
55+ toolSummary ?: ToolSummaryTrace ;
5456 errorText ?: string ;
5557 terminalFailure ?: CliTerminalFailure ;
5658 diagnostics ?: {
@@ -154,6 +156,11 @@ function isGeminiCliProvider(providerId: string): boolean {
154156 return normalizeLowercaseStringOrEmpty ( providerId ) === "google-gemini-cli" ;
155157}
156158
159+ function isCodexExecJsonlProvider ( providerId : string ) : boolean {
160+ const normalized = normalizeLowercaseStringOrEmpty ( providerId ) ;
161+ return normalized === "codex" || normalized === "codex-cli" ;
162+ }
163+
157164function isGeminiStreamJsonDialect ( params : {
158165 backend : CliBackendConfig ;
159166 providerId : string ;
@@ -1167,6 +1174,128 @@ function dispatchGeminiCliStreamingToolEvent(params: {
11671174 }
11681175}
11691176
1177+ type CodexToolEvent = {
1178+ toolCallId : string ;
1179+ name : string ;
1180+ kind : CliToolUseStartDelta [ "kind" ] ;
1181+ args : Record < string , unknown > ;
1182+ result ?: unknown ;
1183+ isError : boolean ;
1184+ } ;
1185+
1186+ function readCodexToolEvent ( item : Record < string , unknown > ) : CodexToolEvent | null {
1187+ const toolCallId = typeof item . id === "string" ? item . id . trim ( ) : "" ;
1188+ if ( ! toolCallId ) {
1189+ return null ;
1190+ }
1191+ const type = normalizeLowercaseStringOrEmpty ( item . type ) ;
1192+ if ( type === "command_execution" ) {
1193+ return {
1194+ toolCallId,
1195+ name : "bash" ,
1196+ kind : "tool_use" ,
1197+ args : typeof item . command === "string" ? { command : item . command } : { } ,
1198+ result : item . aggregated_output ,
1199+ isError : item . status === "failed" || item . status === "declined" ,
1200+ } ;
1201+ }
1202+ if ( type === "file_change" ) {
1203+ return {
1204+ toolCallId,
1205+ name : "apply_patch" ,
1206+ kind : "tool_use" ,
1207+ args : Array . isArray ( item . changes ) ? { changes : item . changes } : { } ,
1208+ result : item . changes ,
1209+ isError : item . status === "failed" ,
1210+ } ;
1211+ }
1212+ if ( type === "web_search" ) {
1213+ return {
1214+ toolCallId,
1215+ name : "web_search" ,
1216+ kind : "server_tool_use" ,
1217+ args : typeof item . query === "string" ? { query : item . query } : { } ,
1218+ result : item . query ,
1219+ isError : false ,
1220+ } ;
1221+ }
1222+ if ( type !== "mcp_tool_call" ) {
1223+ if ( type !== "collab_tool_call" ) {
1224+ return null ;
1225+ }
1226+ const tool = typeof item . tool === "string" ? item . tool . trim ( ) : "" ;
1227+ if ( ! tool ) {
1228+ return null ;
1229+ }
1230+ return {
1231+ toolCallId,
1232+ name : `collab.${ tool } ` ,
1233+ kind : "server_tool_use" ,
1234+ args : {
1235+ ...( typeof item . sender_thread_id === "string"
1236+ ? { sender_thread_id : item . sender_thread_id }
1237+ : { } ) ,
1238+ ...( Array . isArray ( item . receiver_thread_ids )
1239+ ? { receiver_thread_ids : item . receiver_thread_ids }
1240+ : { } ) ,
1241+ ...( typeof item . prompt === "string" ? { prompt : item . prompt } : { } ) ,
1242+ } ,
1243+ result : item . agents_states ,
1244+ isError : item . status === "failed" ,
1245+ } ;
1246+ }
1247+ const server = typeof item . server === "string" ? item . server . trim ( ) : "" ;
1248+ const tool = typeof item . tool === "string" ? item . tool . trim ( ) : "" ;
1249+ if ( ! tool ) {
1250+ return null ;
1251+ }
1252+ return {
1253+ toolCallId,
1254+ name : server ? `${ server } .${ tool } ` : tool ,
1255+ kind : "mcp_tool_use" ,
1256+ args : isRecord ( item . arguments ) ? item . arguments : { } ,
1257+ result : item . status === "failed" ? item . error : item . result ,
1258+ isError : item . status === "failed" ,
1259+ } ;
1260+ }
1261+
1262+ function dispatchCodexCliStreamingToolEvent ( params : {
1263+ providerId : string ;
1264+ parsed : Record < string , unknown > ;
1265+ tracker : ToolUseTracker ;
1266+ onToolUseStart ?: ( delta : CliToolUseStartDelta ) => void ;
1267+ onToolResult ?: ( delta : CliToolResultDelta ) => void ;
1268+ } ) : void {
1269+ if (
1270+ ! isCodexExecJsonlProvider ( params . providerId ) ||
1271+ ( params . parsed . type !== "item.started" && params . parsed . type !== "item.completed" ) ||
1272+ ! isRecord ( params . parsed . item )
1273+ ) {
1274+ return ;
1275+ }
1276+ const event = readCodexToolEvent ( params . parsed . item ) ;
1277+ if ( ! event ) {
1278+ return ;
1279+ }
1280+ emitToolStartOnce (
1281+ params . tracker ,
1282+ event . toolCallId ,
1283+ event . name ,
1284+ event . kind ,
1285+ event . args ,
1286+ params . onToolUseStart ,
1287+ ) ;
1288+ if ( params . parsed . type === "item.completed" ) {
1289+ emitToolResultOnce (
1290+ params . tracker ,
1291+ event . toolCallId ,
1292+ event . isError ,
1293+ event . result ,
1294+ params . onToolResult ,
1295+ ) ;
1296+ }
1297+ }
1298+
11701299const GEMINI_CLI_ERROR_EVENT_FALLBACK = "Gemini CLI emitted an error event." ;
11711300const GEMINI_CLI_RESULT_ERROR_FALLBACK = "Gemini CLI result status was error." ;
11721301
@@ -1398,6 +1527,13 @@ export function createCliJsonlStreamingParser(params: {
13981527 }
13991528
14001529 if ( params . onToolUseStart || params . onToolResult ) {
1530+ dispatchCodexCliStreamingToolEvent ( {
1531+ providerId : params . providerId ,
1532+ parsed,
1533+ tracker : toolTracker ,
1534+ onToolUseStart : params . onToolUseStart ,
1535+ onToolResult : params . onToolResult ,
1536+ } ) ;
14011537 dispatchGeminiCliStreamingToolEvent ( {
14021538 backend : params . backend ,
14031539 providerId : params . providerId ,
0 commit comments