@@ -62,8 +62,7 @@ export function ContextGroup(props: { |
62 | 62 | const tools = createMemo(() => props.parts.filter((part) => part.type === "tool")) |
63 | 63 | const reasoning = createMemo(() => props.parts.flatMap((part) => (part.type === "reasoning" ? [part] : []))) |
64 | 64 | const thoughtsOnly = createMemo(() => reasoning().length > 0 && reasoning().length === props.parts.length) |
65 | | - const partEvents = createMemo(() => workEvents(props.parts)) |
66 | | - const events = createMemo(() => [...partEvents().values()]) |
| 65 | + const events = createMemo(() => [...workEvents(props.parts).values()]) |
67 | 66 |
|
68 | 67 | // A group of only subagents and work reporting back reads as the events row it is, not a group around one. Until a |
69 | 68 | // call has anything to count, it stays a group, so the row never renders empty. |
@@ -97,16 +96,27 @@ export function ContextGroup(props: { |
97 | 96 | const previous = groups.at(-1) |
98 | 97 |
|
99 | 98 | // Subagents started one after another, and work reporting back, read as one events row nested in the group: |
100 | | - // "Started 3 subagents". |
| 99 | + // "Started 3 subagents". The rows keep the order things happened in, which the label does not. |
101 | 100 | if (tool.type === "event" || (tool.type === "tool" && toolRule(tool).name === "subagent")) { |
102 | | - // A subagent still being asked for has nothing to list yet, and a report its launch already says is not |
103 | | - // listed twice. |
104 | | - const event = partEvents().get(tool) |
| 101 | + // A subagent still being asked for has nothing to list yet. |
| 102 | + const event = tool.type === "event" ? tool.event : toolEvent(tool) |
105 | 103 |
|
106 | 104 | if (!event) return groups |
| 105 | + const run = previous && !Array.isArray(previous) && previous.type === "work" ? previous : undefined |
| 106 | + const key = tool.type === "event" ? workKey(event) : undefined |
107 | 107 |
|
108 | | - if (previous && !Array.isArray(previous) && previous.type === "work") { |
109 | | - previous.events.push(event) |
| 108 | + // Work reporting back right after its launch, with nothing between, finishes the launch's row. With |
| 109 | + // anything between, the launch and the report each keep their row. |
| 110 | + const launch = key && run ? run.events.findIndex((item) => item.verb === "started" && workKey(item) === key) : -1 |
| 111 | + |
| 112 | + if (run && launch >= 0) { |
| 113 | + run.events[launch] = { ...run.events[launch]!, verb: event.verb, failed: event.failed } |
| 114 | + |
| 115 | + return groups |
| 116 | + } |
| 117 | + |
| 118 | + if (run) { |
| 119 | + run.events.push(event) |
110 | 120 |
|
111 | 121 | return groups |
112 | 122 | } |
@@ -534,8 +544,8 @@ function usedLabel(parts: ActivityGroupPart[], i18n: UiI18n) { |
534 | 544 | } |
535 | 545 |
|
536 | 546 | /** |
537 | | - * What each subagent or background shell in a group did, in order. Work that reports back in the group that started |
538 | | - * it reads once, as how it ended: the launch says "Finished" and the report is not counted again. |
| 547 | + * What each subagent or background shell in a group did, for its label. Work that reports back anywhere in the group |
| 548 | + * that started it is counted once, as how it ended: "Finished", not "Started" and "Finished". |
539 | 549 | */ |
540 | 550 | function workEvents(parts: ActivityGroupPart[]) { |
541 | 551 | const launch = (part: ActivityGroupPart) => |
|