Repository navigation
refactor(session-ui): derive timeline summaries from facts - #65012
Conversation
User decisions: - Compute timeline counts from message facts, not from rendered groups - Headers match current production output - Both timelines use it
User decisions: - Compute timeline counts from message facts, not from rendered groups
There was a problem hiding this comment.
Behaviour looks unchanged. I ran dev's own label functions over your fixtures in the base checkout, and every New timeline label matches your snapshot. The timeline tests pass and tsc -b is clean. Reading the current timeline's "Used N …" count, its tool names and the read group's file count against the removed code, they work the same as before.
Public API is unchanged; everything here is internal to session-ui.
The main concern is that facts.ts copies logic that still lives in rules.ts and events.ts (see inline). For a change whose goal is "one place that counts", two places that each decide a call's mode or launch verb is worth folding together now. Smaller point: several fields in facts.ts (categoryOf, time, toolCalls, matches, the files' line counts and by/via, the text/error facts, failed) aren't read outside tests yet, so they could come with the PR that needs them.
| } | ||
|
|
||
| // How a call that launches background work ended. Older sessions marked a foreground subagent's result as completed. | ||
| function launch(tool: Tool, name: string): FactOutcome | undefined { |
There was a problem hiding this comment.
launch() is a copy of toolEvent() in timeline-next/events.ts (same streaming/running/error/followUp/background branches), and stopped() below copies toolStopped() in rules.ts. Both originals are still used: workEvents in context-group.tsx and the event rows still go through toolEvent. If one changes, for example how an old-style foreground subagent result is detected, the label and the rows will disagree. Could toolEvent/toolStopped be built on these, or the other way round, so there's one definition?
| return renamed.get(name) ?? name | ||
| } | ||
|
|
||
| const modes = new Map<string, FactMode>( |
There was a problem hiding this comment.
This map copies the mode column of the tools table in timeline-next/rules.ts. If a tool is added or moved there, toolRule (placement) and summarize (labels) will disagree on its mode. Could the facts read the mode from one shared table instead?
User decisions: - Compute timeline counts from message facts, not from rendered groups
There was a problem hiding this comment.
The new commit is a correct fix. Before, a script's toolCalls list made the combined metadata decode fail, which also dropped provider and matches. Each field is now read on its own, and the new test covers that case. The timeline tests pass (154) and tsc -b is clean. The public API is unchanged.
Neither earlier thread is addressed. launch()/stopped() still copy toolEvent()/toolStopped(), and the mode map still copies rules.ts, so both threads stay open.
Issue for this PR
Closes #
Type of change
What does this PR do?
Both timelines counted what the agent did from the groups they render, so any row that isn't one call per tool threw the counts off. This adds
timeline/facts.ts:factsOf(parts)reads message parts into facts (calls, files, thoughts, text, outcomes), memoized per part, andsummarize(facts)is now the only place that counts. These now read fromsummarize: the current timeline's "Used N …" label, the New timeline's activity and used labels, background shell counts (summarizeShellsis gone), the shell event row, and the read group's "N files". The label logic moved into plain.tsfiles (tools/context-group-label.ts,timeline-next/tools/activity-label.ts) so tests can import it.Nothing should look different. Placement is unchanged, and
showWorkingin the app is left for the next PR because it depends on row structure.How did you verify your code works?
Label snapshots for representative groups (reads and searches, edits, background shells, mixed tools, thoughts, failed calls, skills, v1 tool names). They were recorded from dev's code before the refactor and pass unchanged after it. Also ran
tsc -bin session-ui and thetimelineandtimeline-nexttests.Screenshots / recordings
No visual change.
Checklist