@@ -3,16 +3,12 @@ import { Option, Schema } from "effect"
33import { currentToolInput , currentToolMetadata } from "../message/current-tool-state"
44import { toolRule } from "./rules"
55
6- /**
7- * Subagents and background shells read as events rather than tool rows: started, ran, finished and stopped, counted by
8- * kind. Titles and commands stay in the background panel above the composer.
9- */
106export type TimelineEventKind = "subagent" | "shell"
117
128export type TimelineEventVerb = "started" | "ran" | "finished" | "stopped"
139
1410export type TimelineEvent = {
15- verb : TimelineEventVerb
11+ verb : TimelineEventVerb | "updated"
1612 kind : TimelineEventKind
1713 failed : boolean
1814 /** What opening the row lists: a subagent's task or a shell's command, and where each leads. */
@@ -22,25 +18,20 @@ export type TimelineEvent = {
2218 shellID ?: string
2319}
2420
25- /** How an events row names each verb and kind: "Started 2 subagents" . */
21+ /** Status labels shared by task rows and shell summaries . */
2622export const verbKeys = {
2723 started : "ui.timeline.event.started" ,
2824 ran : "ui.timeline.activity.ran" ,
2925 finished : "ui.timeline.event.finished" ,
3026 stopped : "ui.timeline.event.stopped" ,
3127} as const
3228
33- export const kindKeys = {
34- subagent : "ui.timeline.event.subagents" ,
35- shell : "ui.timeline.event.shells" ,
36- } as const
37-
3829/** How a group's label counts work that runs on, beside its other calls: "1 command, started 1 shell". */
3930export const launchKeys = {
40- started : { shell : "ui.timeline.activity.startedShells" , subagent : "ui.timeline.activity.startedSubagents" } ,
41- ran : { shell : "ui.timeline.activity.commands" , subagent : "ui.timeline.activity.subagents" } ,
42- finished : { shell : "ui.timeline.activity.finishedShells" , subagent : "ui.timeline.activity.finishedSubagents" } ,
43- stopped : { shell : "ui.timeline.activity.stoppedShells" , subagent : "ui.timeline.activity.stoppedSubagents" } ,
31+ started : "ui.timeline.activity.startedShells" ,
32+ ran : "ui.timeline.activity.commands" ,
33+ finished : "ui.timeline.activity.finishedShells" ,
34+ stopped : "ui.timeline.activity.stoppedShells" ,
4435} as const
4536
4637// Text a call or notice carries, where it is not empty.
@@ -57,16 +48,17 @@ export function toolEvent(tool: SessionMessageAssistantTool): TimelineEvent | un
5748 if ( state . status === "streaming" ) return undefined
5849 const input = currentToolInput ( tool )
5950 const metadata = currentToolMetadata ( tool )
51+ const followUp = kind === "subagent" ? Option . getOrUndefined ( decodeText ( input . sessionID ) ) : undefined
6052
6153 const item = {
6254 kind,
6355 title : Option . getOrUndefined ( decodeText ( kind === "shell" ? input . command : input . description ) ) ,
64- agent : kind === "subagent" ? Option . getOrUndefined ( decodeText ( input . agent ) ) : undefined ,
65- sessionID : kind === "subagent" ? Option . getOrUndefined ( decodeText ( metadata . sessionID ) ) : undefined ,
56+ agent : kind === "subagent" ? Option . getOrUndefined ( decodeText ( input . agent ?? input . subagent_type ) ) : undefined ,
57+ sessionID : kind === "subagent" ? ( Option . getOrUndefined ( decodeText ( metadata . sessionID ) ) ?? followUp ) : undefined ,
6658 shellID : kind === "shell" ? Option . getOrUndefined ( decodeText ( metadata . shellID ) ) : undefined ,
6759 } as const
6860
69- if ( state . status === "running" ) return { ...item , verb : "started" , failed : false }
61+ if ( state . status === "running" ) return { ...item , verb : followUp ? "updated" : "started" , failed : false }
7062
7163 const background =
7264 kind === "subagent" ? metadata . status !== "completed" : metadata . status === "running" || input . background === true
@@ -77,6 +69,8 @@ export function toolEvent(tool: SessionMessageAssistantTool): TimelineEvent | un
7769 return { ...item , verb : background ? "started" : "ran" , failed : true }
7870 }
7971
72+ if ( followUp ) return { ...item , verb : "updated" , failed : false }
73+
8074 return { ...item , verb : background ? "started" : "ran" , failed : false }
8175}
8276
@@ -108,26 +102,16 @@ export function workKey(event: TimelineEvent) {
108102 return id ? `${ event . kind } :${ id } ` : undefined
109103}
110104
111- /**
112- * A run of events as one label: each verb once, in the order it first happened, with how many of each kind, and how
113- * many failed overall. Two finishes in a row read "Finished 2 subagents".
114- */
115- export function summarizeEvents ( events : readonly TimelineEvent [ ] ) {
116- const verbs = events . reduce < { verb : TimelineEventVerb ; kinds : { kind : TimelineEventKind ; count : number } [ ] } [ ] > (
117- ( result , event ) => {
118- const bucket = result . find ( ( item ) => item . verb === event . verb ) ?? { verb : event . verb , kinds : [ ] }
119-
120- if ( ! result . includes ( bucket ) ) result . push ( bucket )
121- const kind = bucket . kinds . find ( ( item ) => item . kind === event . kind )
122-
123- if ( kind ) kind . count += 1
124-
125- if ( ! kind ) bucket . kinds . push ( { kind : event . kind , count : 1 } )
126-
127- return result
128- } ,
129- [ ] ,
130- )
131-
132- return { verbs, failed : events . filter ( ( event ) => event . failed ) . length }
105+ /** Count background shells by verb in the order they happened. Subagents have individual task rows. */
106+ export function summarizeShells ( events : readonly TimelineEvent [ ] ) {
107+ const counts = new Map < TimelineEventVerb , number > ( )
108+ const shells = events . filter ( ( event ) => event . kind === "shell" )
109+ shells . forEach ( ( { verb } ) => {
110+ if ( verb !== "updated" ) counts . set ( verb , ( counts . get ( verb ) ?? 0 ) + 1 )
111+ } )
112+
113+ return {
114+ verbs : Array . from ( counts , ( [ verb , count ] ) => ( { verb, count } ) ) ,
115+ failed : shells . filter ( ( event ) => event . failed ) . length ,
116+ }
133117}
0 commit comments