Repository navigation
fix(web): expand each side of a steer's fold on its own #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ import { | |
| deriveMessagesTimelineRows, | ||
| normalizeCompactToolLabel, | ||
| resolveAssistantMessageCopyState, | ||
| type TimelineLatestTurn, | ||
| shouldPreserveAssistantLineBreaks, | ||
| } from "./MessagesTimeline.logic"; | ||
|
|
||
|
|
@@ -337,7 +338,7 @@ describe("deriveMessagesTimelineRows", () => { | |
| }, | ||
| }, | ||
| ], | ||
| expandedTurnIds: new Set(["turn-1" as never]), | ||
| expandedFoldKeys: new Set(["assistant-thought-entry"]), | ||
| isWorking: false, | ||
| activeTurnStartedAt: null, | ||
| turnDiffSummaryByAssistantMessageId: new Map(), | ||
|
|
@@ -540,7 +541,7 @@ describe("deriveMessagesTimelineRows", () => { | |
| (row): row is Extract<(typeof collapsedRows)[number], { kind: "turn-fold" }> => | ||
| row.kind === "turn-fold", | ||
| ); | ||
| expect(foldRow?.turnId).toBe("turn-1"); | ||
| expect(foldRow?.expandKey).toBe("assistant-first-entry"); | ||
| expect(foldRow?.expanded).toBe(false); | ||
| // User message boundary (00:00:00) → terminal message updatedAt (00:00:22). | ||
| expect(foldRow?.label).toBe("Worked for 22s"); | ||
|
|
@@ -552,7 +553,7 @@ describe("deriveMessagesTimelineRows", () => { | |
|
|
||
| const expandedRows = deriveMessagesTimelineRows({ | ||
| timelineEntries, | ||
| expandedTurnIds: new Set(["turn-1" as never]), | ||
| expandedFoldKeys: new Set(["assistant-first-entry"]), | ||
| isWorking: false, | ||
| activeTurnStartedAt: null, | ||
| turnDiffSummaryByAssistantMessageId: new Map(), | ||
|
|
@@ -724,7 +725,7 @@ describe("deriveMessagesTimelineRows", () => { | |
| row.kind === "turn-fold", | ||
| ); | ||
| // User message (00:00:00) → trailing work entry (00:00:12). | ||
| expect(foldRow?.turnId).toBe("turn-1"); | ||
| expect(foldRow?.expandKey).toBe("assistant-commentary-entry"); | ||
| expect(foldRow?.label).toBe("Worked for 12s"); | ||
| }); | ||
|
|
||
|
|
@@ -759,7 +760,7 @@ describe("deriveMessagesTimelineRows", () => { | |
| expect(rows).toEqual([ | ||
| expect.objectContaining({ | ||
| kind: "turn-fold", | ||
| turnId: "turn-1", | ||
| expandKey: "turn-1", | ||
| label: "You stopped after 47s", | ||
| expanded: false, | ||
| }), | ||
|
|
@@ -1309,8 +1310,8 @@ describe("deriveMessagesTimelineRows", () => { | |
| revertTurnCountByUserMessageId: new Map(), | ||
| }); | ||
|
|
||
| expect(rows.filter((row) => row.kind === "turn-fold").map((row) => row.turnId)).toEqual([ | ||
| "turn-1", | ||
| expect(rows.filter((row) => row.kind === "turn-fold").map((row) => row.expandKey)).toEqual([ | ||
| "previous-work-entry", | ||
| ]); | ||
| expect(rows.map((row) => row.id)).toContain("live-activity-row"); | ||
| }); | ||
|
|
@@ -1477,6 +1478,28 @@ describe("deriveMessagesTimelineRows", () => { | |
| row.kind === "message" && row.showsTurnFoldSeparator ? [row.id] : [], | ||
| ), | ||
| ).toEqual(["assistant-final-entry"]); | ||
|
|
||
| // 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]); | ||
|
Comment on lines
+1481
to
+1502
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 新增断言:steer 前半段用自己的锚点键展开、后半段用自己的锚点键展开,两者互不影响;被打断时用 turn id 能展开被打断的那一段(后半段)。 |
||
| }); | ||
|
|
||
| it("keys the fold after a user message by the new turn even when old-turn residue lands first", () => { | ||
|
|
@@ -1510,9 +1533,9 @@ describe("deriveMessagesTimelineRows", () => { | |
| "turn-fold:work-late-entry", | ||
| "assistant-two-entry", | ||
| ]); | ||
| expect(rows.filter((row) => row.kind === "turn-fold").map((row) => row.turnId)).toEqual([ | ||
| "turn-1", | ||
| "turn-2", | ||
| expect(rows.filter((row) => row.kind === "turn-fold").map((row) => row.expandKey)).toEqual([ | ||
| "work-1-entry", | ||
| "work-late-entry", | ||
| ]); | ||
| }); | ||
|
|
||
|
|
@@ -1606,7 +1629,7 @@ describe("deriveMessagesTimelineRows", () => { | |
| ...baseFoldInput, | ||
| timelineEntries, | ||
| latestTurn, | ||
| expandedTurnIds: new Set(["turn-2" as never]), | ||
| expandedFoldKeys: new Set(["work-1-entry"]), | ||
| }); | ||
| expect(expandedRows.map((row) => row.id)).toContain("work-toggle:work-1-entry"); | ||
| expect(expandedRows.map((row) => row.id)).toContain("spawn-1-entry"); | ||
|
|
@@ -1670,7 +1693,7 @@ describe("deriveMessagesTimelineRows", () => { | |
| // The segment's own entries end at 00:00:10, but this segment holds the | ||
| // latest turn's entries, so the end is latestTurn.completedAt (00:00:47). | ||
| expect(rows.filter((row) => row.kind === "turn-fold")).toEqual([ | ||
| expect.objectContaining({ turnId: "turn-2", label: "You stopped after 47s" }), | ||
| expect.objectContaining({ expandKey: "turn-2", label: "You stopped after 47s" }), | ||
| ]); | ||
| }); | ||
|
|
||
|
|
@@ -1754,7 +1777,7 @@ describe("deriveMessagesTimelineRows", () => { | |
| }, | ||
| }, | ||
| ], | ||
| expandedTurnIds: new Set(["turn-1" as never]), | ||
| expandedFoldKeys: new Set(["assistant-thought-entry"]), | ||
| isWorking: false, | ||
| activeTurnStartedAt: null, | ||
| turnDiffSummaryByAssistantMessageId: new Map(), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -225,7 +225,7 @@ export type MessagesTimelineRow = | |
| kind: "turn-fold"; | ||
| id: string; | ||
| createdAt: string; | ||
| turnId: TurnId; | ||
| expandKey: string; | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 折叠行不再暴露 turnId,改为暴露 expandKey:它就是“展开集合”里对应这一行的那个键。组件点击时原样传回,不需要知道它是 turn id 还是 entry id。 |
||
| label: string; | ||
| expanded: boolean; | ||
| } | ||
|
|
@@ -338,7 +338,12 @@ function deriveTerminalAssistantMessageIds(timelineEntries: ReadonlyArray<Timeli | |
| } | ||
|
|
||
| interface TurnFold { | ||
| turnId: TurnId; | ||
| /** | ||
| * 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; | ||
|
Comment on lines
+341
to
+346
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里定义了键的取法:默认用折叠里第一条被隐藏的 entry 的 id,所以同一个 turn 被 steer 切成的两段各有各的键。只有被 Stop 打断的那一段仍用 turn id,因为打断时组件只知道 turn id(见组件里的 effect)。 |
||
| anchorEntryId: string; | ||
| createdAt: string; | ||
| hiddenEntryIds: ReadonlySet<string>; | ||
|
|
@@ -407,7 +412,7 @@ function deriveTurnFolds(input: { | |
| unsettledTurnId: TurnId | null; | ||
| }): ReadonlyMap<string, TurnFold> { | ||
| interface Segment { | ||
| /** Last turn id in the segment; folds expand per turn id. */ | ||
| /** Last turn id in the segment. */ | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 注释里删掉了“folds expand per turn id”,因为现在展开不再按 turn id。 |
||
| turnId: TurnId | null; | ||
| entries: Array<TimelineEntry>; | ||
| /** | ||
|
|
@@ -491,7 +496,7 @@ function deriveTurnFolds(input: { | |
| : "Worked"; | ||
|
|
||
| foldsByAnchorEntryId.set(firstHiddenEntry.id, { | ||
| turnId, | ||
| expandKey: turn?.state === "interrupted" ? turnId : firstHiddenEntry.id, | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 核心一行。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Using Useful? React with 👍 / 👎. |
||
| anchorEntryId: firstHiddenEntry.id, | ||
| createdAt: firstHiddenEntry.createdAt, | ||
| hiddenEntryIds, | ||
|
|
@@ -506,7 +511,7 @@ export function deriveMessagesTimelineRows(input: { | |
| timelineEntries: ReadonlyArray<TimelineEntry>; | ||
| latestTurn?: TimelineLatestTurn | null; | ||
| runningTurnId?: TurnId | null; | ||
| expandedTurnIds?: ReadonlySet<TurnId>; | ||
| expandedFoldKeys?: ReadonlySet<string>; | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 入参从 |
||
| expandedWorkGroupIds?: ReadonlySet<string>; | ||
| isWorking: boolean; | ||
| activeTurnStartedAt: string | null; | ||
|
|
@@ -533,7 +538,7 @@ export function deriveMessagesTimelineRows(input: { | |
| if (fold.terminalEntryId !== null) { | ||
| foldTerminalEntryIds.add(fold.terminalEntryId); | ||
| } | ||
| if (!input.expandedTurnIds?.has(fold.turnId)) { | ||
| if (!input.expandedFoldKeys?.has(fold.expandKey)) { | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 判断“该不该隐藏折叠内容”时改用折叠自己的键。 |
||
| for (const entryId of fold.hiddenEntryIds) { | ||
| collapsedEntryIds.add(entryId); | ||
| } | ||
|
|
@@ -655,9 +660,9 @@ export function deriveMessagesTimelineRows(input: { | |
| kind: "turn-fold", | ||
| id: `turn-fold:${anchoredTurnFold.anchorEntryId}`, | ||
| createdAt: anchoredTurnFold.createdAt, | ||
| turnId: anchoredTurnFold.turnId, | ||
| expandKey: anchoredTurnFold.expandKey, | ||
| label: anchoredTurnFold.label, | ||
| expanded: input.expandedTurnIds?.has(anchoredTurnFold.turnId) ?? false, | ||
| expanded: input.expandedFoldKeys?.has(anchoredTurnFold.expandKey) ?? false, | ||
|
Comment on lines
+663
to
+665
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 折叠行输出改成携带 expandKey, |
||
| }); | ||
| } | ||
|
|
||
|
|
@@ -868,7 +873,7 @@ function isRowUnchanged(a: MessagesTimelineRow, b: MessagesTimelineRow): boolean | |
| case "turn-fold": { | ||
| const bf = b as typeof a; | ||
| return ( | ||
| a.turnId === bf.turnId && | ||
| a.expandKey === bf.expandKey && | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 行比较函数同步改比 expandKey:turnId 不再渲染,而点击回调用的是 expandKey,所以要比它,否则键变了行却被当成“没变”而复用旧的 onClick。 |
||
| a.createdAt === bf.createdAt && | ||
| a.label === bf.label && | ||
| a.expanded === bf.expanded | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -169,7 +169,7 @@ interface TimelineRowSharedState { | |
| onFileOpen: (attachment: ChatFileAttachment) => void; | ||
| openingVideoAttachmentId: string | null; | ||
| onOpenTurnDiff: (turnId: TurnId, filePath?: string) => void; | ||
| onToggleTurnFold: (turnId: TurnId, anchorKey: string) => void; | ||
| onToggleTurnFold: (foldKey: string, anchorKey: string) => void; | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 回调签名改成接收折叠键(string),组件不再关心它是 turn id 还是 entry id。 |
||
| onToggleWorkGroup: (groupId: string, anchorKey: string) => void; | ||
| agentPanelModel: AgentPanelModel; | ||
| onOpenAgents: () => void; | ||
|
|
@@ -314,7 +314,7 @@ export const MessagesTimeline = memo(function MessagesTimeline({ | |
| topFadeEnabled = false, | ||
| loadEarlier = null, | ||
| }: MessagesTimelineProps) { | ||
| const [expandedTurnIds, setExpandedTurnIds] = useState<ReadonlySet<TurnId>>(new Set()); | ||
| const [expandedFoldKeys, setExpandedFoldKeys] = useState<ReadonlySet<string>>(new Set()); | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 展开集合状态改名并放宽类型,存的是折叠键。 |
||
| const [expandedWorkGroupIds, setExpandedWorkGroupIds] = useState<ReadonlySet<string>>(new Set()); | ||
| const [disclosureToggleSettling, setDisclosureToggleSettling] = useState(false); | ||
| const [minimapStripMap] = useState(() => new Map<string, HTMLSpanElement>()); | ||
|
|
@@ -378,14 +378,14 @@ export const MessagesTimeline = memo(function MessagesTimeline({ | |
| ); | ||
|
|
||
| const onToggleTurnFold = useCallback( | ||
| (turnId: TurnId, anchorKey: string) => { | ||
| (foldKey: string, anchorKey: string) => { | ||
| suspendEndScrollMaintenanceForDisclosure(anchorKey); | ||
| setExpandedTurnIds((existing) => { | ||
| setExpandedFoldKeys((existing) => { | ||
| const next = new Set(existing); | ||
| if (next.has(turnId)) { | ||
| next.delete(turnId); | ||
| if (next.has(foldKey)) { | ||
| next.delete(foldKey); | ||
| } else { | ||
| next.add(turnId); | ||
| next.add(foldKey); | ||
|
Comment on lines
+381
to
+388
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 点击切换逻辑本身没变,只是把 turnId 换成 foldKey。 |
||
| } | ||
| return next; | ||
| }); | ||
|
|
@@ -419,15 +419,15 @@ export const MessagesTimeline = memo(function MessagesTimeline({ | |
| } | ||
| if (latestTurn.turnId === previous.turnId) { | ||
| if (previous.state === "running" && latestTurn.state === "interrupted") { | ||
| setExpandedTurnIds((existing) => { | ||
| setExpandedFoldKeys((existing) => { | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 打断时自动展开的 effect 逻辑不变:仍然往集合里加 latestTurn.turnId。之所以还能生效,是因为 logic.ts 里被打断那一段的键正好就是 turn id。 |
||
| const next = new Set(existing); | ||
| next.add(latestTurn.turnId); | ||
| return next; | ||
| }); | ||
| } | ||
| return; | ||
| } | ||
| setExpandedTurnIds((existing) => { | ||
| setExpandedFoldKeys((existing) => { | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 下一个 turn 开始时删掉上一个 turn id,同样不变。 |
||
| if (!existing.has(previous.turnId)) { | ||
| return existing; | ||
| } | ||
|
|
@@ -443,7 +443,7 @@ export const MessagesTimeline = memo(function MessagesTimeline({ | |
| timelineEntries, | ||
| latestTurn, | ||
| runningTurnId, | ||
| expandedTurnIds, | ||
| expandedFoldKeys, | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. useMemo 传入和依赖数组同步改名。 |
||
| expandedWorkGroupIds, | ||
| isWorking, | ||
| activeTurnStartedAt, | ||
|
|
@@ -454,7 +454,7 @@ export const MessagesTimeline = memo(function MessagesTimeline({ | |
| timelineEntries, | ||
| latestTurn, | ||
| runningTurnId, | ||
| expandedTurnIds, | ||
| expandedFoldKeys, | ||
| expandedWorkGroupIds, | ||
| isWorking, | ||
| activeTurnStartedAt, | ||
|
|
@@ -1249,7 +1249,7 @@ function TurnFoldTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "turn- | |
| type="button" | ||
| aria-expanded={row.expanded} | ||
| data-scroll-anchor-ignore | ||
| onClick={() => ctx.onToggleTurnFold(row.turnId, row.id)} | ||
| onClick={() => ctx.onToggleTurnFold(row.expandKey, row.id)} | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 点击折叠行时传回该行自己的 expandKey。 |
||
| className="flex cursor-pointer select-none items-center gap-1 rounded-md px-1 text-sm leading-relaxed text-muted-foreground tabular-nums transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70" | ||
| > | ||
| <span>{row.label}</span> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这些旧测试原来用 turn id 展开一个已完成 turn 的折叠;现在已完成 turn 的折叠键是锚点 entry id,所以改成对应的 entry id。其余几处(544、556、728、1313、1536、1632、1780 行)同理,只是键值替换。