Repository navigation
fix(web): expand each side of a steer's fold on its own - #13
Conversation
A steer splits the agent's turn into a fold above the user message and a fold below it. Clicking either one opened and closed both, because the timeline kept the set of expanded folds by turn id and both halves of a steered turn share one turn id. Each fold now carries its own expand key: normally the id of the first entry it hides, so the two halves of a steered turn expand on their own. Only the fold that an interrupt cut short keys by its turn id, because on Stop the timeline expands that fold knowing only which turn was stopped. Written by Claude Fable 5.1 running in Claude Code, driven from T3 Code.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
| id: string; | ||
| createdAt: string; | ||
| turnId: TurnId; | ||
| expandKey: string; |
There was a problem hiding this comment.
折叠行不再暴露 turnId,改为暴露 expandKey:它就是“展开集合”里对应这一行的那个键。组件点击时原样传回,不需要知道它是 turn id 还是 entry id。
| /** | ||
| * What the expanded-folds set holds for this fold. Normally the anchor | ||
| * entry id, so each side of a steer expands on its own; the fold that an | ||
| * interrupt cut short keys by its turn id, which is all the interrupt knows. | ||
| */ | ||
| expandKey: string; |
There was a problem hiding this comment.
这里定义了键的取法:默认用折叠里第一条被隐藏的 entry 的 id,所以同一个 turn 被 steer 切成的两段各有各的键。只有被 Stop 打断的那一段仍用 turn id,因为打断时组件只知道 turn id(见组件里的 effect)。
| }): ReadonlyMap<string, TurnFold> { | ||
| interface Segment { | ||
| /** Last turn id in the segment; folds expand per turn id. */ | ||
| /** Last turn id in the segment. */ |
There was a problem hiding this comment.
注释里删掉了“folds expand per turn id”,因为现在展开不再按 turn id。
|
|
||
| foldsByAnchorEntryId.set(firstHiddenEntry.id, { | ||
| turnId, | ||
| expandKey: turn?.state === "interrupted" ? turnId : firstHiddenEntry.id, |
There was a problem hiding this comment.
核心一行。turn 只对“最新 turn 的收尾段”非空(见上面的 latestTurnSegment),所以 turn?.state === "interrupted" 恰好只命中被打断的那一段;其余所有折叠都用锚点 entry id,键稳定且互不相同。
| latestTurn?: TimelineLatestTurn | null; | ||
| runningTurnId?: TurnId | null; | ||
| expandedTurnIds?: ReadonlySet<TurnId>; | ||
| expandedFoldKeys?: ReadonlySet<string>; |
There was a problem hiding this comment.
入参从 expandedTurnIds(turn id 集合)改成 expandedFoldKeys(键集合),类型放宽到 string,因为键可能是 entry id。
| return; | ||
| } | ||
| setExpandedTurnIds((existing) => { | ||
| setExpandedFoldKeys((existing) => { |
There was a problem hiding this comment.
下一个 turn 开始时删掉上一个 turn id,同样不变。
| latestTurn, | ||
| runningTurnId, | ||
| expandedTurnIds, | ||
| expandedFoldKeys, |
| aria-expanded={row.expanded} | ||
| data-scroll-anchor-ignore | ||
| onClick={() => ctx.onToggleTurnFold(row.turnId, row.id)} | ||
| onClick={() => ctx.onToggleTurnFold(row.expandKey, row.id)} |
There was a problem hiding this comment.
点击折叠行时传回该行自己的 expandKey。
|
|
||
| // Each side of the steer expands on its own. | ||
| const expandedSide = (keys: ReadonlyArray<string>, latestTurn?: TimelineLatestTurn) => | ||
| deriveMessagesTimelineRows({ | ||
| ...baseFoldInput, | ||
| timelineEntries, | ||
| ...(latestTurn ? { latestTurn } : {}), | ||
| expandedFoldKeys: new Set(keys), | ||
| }) | ||
| .filter((row) => row.kind === "turn-fold") | ||
| .map((row) => row.kind === "turn-fold" && row.expanded); | ||
| expect(expandedSide(["work-1-entry"])).toEqual([true, false]); | ||
| expect(expandedSide(["work-2-entry"])).toEqual([false, true]); | ||
| // An interrupt knows only the turn id; that expands the side it cut short. | ||
| expect( | ||
| expandedSide(["turn-1"], { | ||
| turnId: "turn-1" as never, | ||
| state: "interrupted", | ||
| startedAt: "2026-01-01T00:00:00Z", | ||
| completedAt: "2026-01-01T00:00:30Z", | ||
| }), | ||
| ).toEqual([false, true]); |
There was a problem hiding this comment.
新增断言:steer 前半段用自己的锚点键展开、后半段用自己的锚点键展开,两者互不影响;被打断时用 turn id 能展开被打断的那一段(后半段)。
| }, | ||
| ], | ||
| expandedTurnIds: new Set(["turn-1" as never]), | ||
| expandedFoldKeys: new Set(["assistant-thought-entry"]), |
There was a problem hiding this comment.
这些旧测试原来用 turn id 展开一个已完成 turn 的折叠;现在已完成 turn 的折叠键是锚点 entry id,所以改成对应的 entry id。其余几处(544、556、728、1313、1536、1632、1780 行)同理,只是键值替换。
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e16e7676e2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| foldsByAnchorEntryId.set(firstHiddenEntry.id, { | ||
| turnId, | ||
| expandKey: turn?.state === "interrupted" ? turnId : firstHiddenEntry.id, |
There was a problem hiding this comment.
Keep the per-fold expansion key stable across pagination
Using firstHiddenEntry.id makes an expanded fold lose its identity when older history is prepended. mergeOlderPage prepends rows in packages/client-runtime/src/state/threads.ts, and the server explicitly permits a large fan-out group to be split across pages; loading the preceding chunk of that same user-message segment therefore selects an earlier firstHiddenEntry, while expandedFoldKeys still contains the old ID, so the open fold unexpectedly snaps closed. Derive the key from a stable segment boundary or migrate the expansion state when the anchor changes.
Useful? React with 👍 / 👎.
What changed
A steer is a message you send while the agent is still working on your previous one. As of #10, a steer splits the agent's turn into two "Worked for …" folds, one above the steer and one below. Clicking either fold opened and closed both. Now each fold opens and closes on its own.
The folds moved together because the timeline tracked expanded folds by turn id, and both halves of a steered turn share one turn id. Each fold now carries its own expand key, and the timeline tracks those keys instead. A fold's key is the id of the first entry that fold hides, so no two folds share a key.
The one exception is the fold that Stop cut short. It keeps the turn id as its key, because when you press Stop the timeline expands that fold and the only thing it knows at that point is which turn you stopped. That behaviour is unchanged.
This change is web only. Mobile folds per turn and has no steer split, so there is nothing to change there. Expanded state is local to the page, as before.
Screenshots
Same script as #12, run against two Docker containers built from production bundles. The before container runs main at fa64403; the after container runs this branch on top of it. Message A asks the agent to run a 25s command and then reply "done". Message B, sent while that command is still running, asks for another 25s command and then the reply "pong". Once the turn settles, the script clicks the first "Worked for" fold once.
Checklist
Written by Claude Fable 5.1 running in Claude Code, driven from T3 Code.