Skip to content

refactor(session-ui): derive timeline summaries from facts - #65012

Merged
jlongster merged 3 commits into
devfrom
timeline-facts
Nov 20, 2026
Merged

jlongster merged 3 commits into
devfrom
timeline-facts

Conversation

@jlongster

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

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, and summarize(facts) is now the only place that counts. These now read from summarize: the current timeline's "Used N …" label, the New timeline's activity and used labels, background shell counts (summarizeShells is gone), the shell event row, and the read group's "N files". The label logic moved into plain .ts files (tools/context-group-label.ts, timeline-next/tools/activity-label.ts) so tests can import it.

Nothing should look different. Placement is unchanged, and showWorking in 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 -b in session-ui and the timeline and timeline-next tests.

Screenshots / recordings

No visual change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

User decisions:
- Compute timeline counts from message facts, not from rendered groups
- Headers match current production output
- Both timelines use it
@jlongster
jlongster marked this pull request as ready for review November 19, 2026 23:15
User decisions:
- Compute timeline counts from message facts, not from rendered groups

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@jlongster
jlongster merged commit 07c2502 into dev Nov 20, 2026
10 checks passed
@jlongster
jlongster deleted the timeline-facts branch November 20, 2026 17:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant