@@ -23,30 +23,30 @@ const CODEX_BIN = "codex";
2323/**
2424 * Parse a JSONL line from `codex exec --json` and map it to a Linear activity.
2525 */
26- function mapCodexEventToActivity ( event : any ) : ActivityContent | null {
26+ function mapCodexEventToActivity ( event : any ) : ActivityContent [ ] {
2727 const eventType = event ?. type ;
2828 const item = event ?. item ;
2929
3030 if ( item ?. type === "reasoning" ) {
3131 const text = item . text ?? "" ;
32- return { type : "thought" , body : text ? text . slice ( 0 , 500 ) : "Reasoning..." } ;
32+ return [ { type : "thought" , body : text ? text . slice ( 0 , 500 ) : "Reasoning..." } ] ;
3333 }
3434
3535 if (
3636 ( eventType === "item.completed" || eventType === "item.started" ) &&
3737 ( item ?. type === "agent_message" || item ?. type === "message" )
3838 ) {
3939 const text = item . text ?? item . content ?? "" ;
40- if ( text ) return { type : "thought" , body : text . slice ( 0 , 1000 ) } ;
41- return null ;
40+ if ( text ) return [ { type : "thought" , body : text . slice ( 0 , 1000 ) } ] ;
41+ return [ ] ;
4242 }
4343
4444 if ( eventType === "item.started" && item ?. type === "command_execution" ) {
4545 const cmd = item . command ?? "unknown" ;
4646 const cleaned = typeof cmd === "string"
4747 ? cmd . replace ( / ^ \/ u s r \/ b i n \/ \w + - l c [ ' " ] ? / , "" ) . replace ( / [ ' " ] ? $ / , "" )
4848 : JSON . stringify ( cmd ) ;
49- return { type : "action" , action : "Running" , parameter : cleaned . slice ( 0 , 200 ) } ;
49+ return [ { type : "action" , action : "Running" , parameter : cleaned . slice ( 0 , 200 ) } ] ;
5050 }
5151
5252 if ( eventType === "item.completed" && item ?. type === "command_execution" ) {
@@ -57,19 +57,19 @@ function mapCodexEventToActivity(event: any): ActivityContent | null {
5757 ? cmd . replace ( / ^ \/ u s r \/ b i n \/ \w + - l c [ ' " ] ? / , "" ) . replace ( / [ ' " ] ? $ / , "" )
5858 : JSON . stringify ( cmd ) ;
5959 const truncated = output . length > 1000 ? output . slice ( 0 , 1000 ) + "..." : output ;
60- return {
60+ return [ {
6161 type : "action" ,
6262 action : `${ cleaned . slice ( 0 , 150 ) } ` ,
6363 parameter : `exit ${ exitCode } ` ,
6464 result : truncated || undefined ,
65- } ;
65+ } ] ;
6666 }
6767
6868 if ( eventType === "item.completed" && item ?. type === "file_changes" ) {
6969 const files = item . files ?? [ ] ;
7070 const fileList = Array . isArray ( files ) ? files . join ( ", " ) : String ( files ) ;
7171 const preview = ( item . diff ?? item . content ?? "" ) . slice ( 0 , 500 ) || undefined ;
72- return { type : "action" , action : "Modified files" , parameter : fileList || "unknown files" , result : preview } ;
72+ return [ { type : "action" , action : "Modified files" , parameter : fileList || "unknown files" , result : preview } ] ;
7373 }
7474
7575 if ( eventType === "turn.completed" ) {
@@ -78,12 +78,12 @@ function mapCodexEventToActivity(event: any): ActivityContent | null {
7878 const input = usage . input_tokens ?? 0 ;
7979 const cached = usage . cached_input_tokens ?? 0 ;
8080 const output = usage . output_tokens ?? 0 ;
81- return { type : "thought" , body : `Codex turn complete (${ input } in / ${ cached } cached / ${ output } out tokens)` } ;
81+ return [ { type : "thought" , body : `Codex turn complete (${ input } in / ${ cached } cached / ${ output } out tokens)` } ] ;
8282 }
83- return { type : "thought" , body : "Codex turn complete" } ;
83+ return [ { type : "thought" , body : "Codex turn complete" } ] ;
8484 }
8585
86- return null ;
86+ return [ ] ;
8787}
8888
8989/**
@@ -248,8 +248,8 @@ export async function runCodex(
248248 collectedCommands . push ( `\`${ cleanCmd } \` → exit ${ exitCode } ${ truncOutput ? "\n```\n" + truncOutput + "\n```" : "" } ` ) ;
249249 }
250250
251- const activity = mapCodexEventToActivity ( event ) ;
252- if ( activity ) {
251+ const activities = mapCodexEventToActivity ( event ) ;
252+ for ( const activity of activities ) {
253253 if ( linearApi && agentSessionId ) {
254254 linearApi . emitActivity ( agentSessionId , activity ) . catch ( ( err ) => {
255255 api . logger . warn ( `Failed to emit Codex activity: ${ err } ` ) ;
0 commit comments