fix(session-ui): keep a script's Output when its changes are grouped (#66638)

This commit is contained in:
James Long 2026-11-26 12:34:47 -05:00 • committed by GitHub
parent 2ae0ff0008
commit a956150945
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 59 additions and 5 deletions

View file

@ -40,6 +40,41 @@ const rows = [
}),
]
// Changes grouped into a summary row with other edits, as Quiet places them, which the row may draw closed.
const grouped = [
rows[0]!,
new TimelineRow.AssistantPart({
userMessageID: "msg_u",
group: {
key: "context:msg_a:script:file:0:a.ts",
type: "context",
refs: [
{ messageID: "msg_a", partID: "script:file:0:a.ts" },
{ messageID: "msg_a", partID: "script:file:1:b.ts" },
],
},
previousAssistantPart: true,
spacing: "tool",
}),
]
// The script and its changes as items of one group, as Compact places them.
const together = [
new TimelineRow.AssistantPart({
userMessageID: "msg_u",
group: {
key: "context:msg_a:script",
type: "context",
refs: [
{ messageID: "msg_a", partID: "script" },
{ messageID: "msg_a", partID: "script:file:0:a.ts" },
{ messageID: "msg_a", partID: "script:file:1:b.ts" },
],
},
previousAssistantPart: false,
}),
]
describe("scriptOutputLayout", () => {
test("moves a script's Output after its last change in the flat layout", () => {
const layout = scriptOutputLayout(rows, messages, true)
@ -48,6 +83,21 @@ describe("scriptOutputLayout", () => {
expect([...layout.outputAfter.keys()]).toEqual(["msg_a:script:file:1:b.ts"])
})
test("keeps a script's Output under its steps when its changes are grouped into a summary row", () => {
const layout = scriptOutputLayout(grouped, messages, true)
expect(layout.afterChanges.size).toBe(0)
expect(layout.outputAfter.size).toBe(0)
expect(TimelineRow.scriptChanges(grouped[1]!)).toBe(false)
})
test("moves a script's Output after its last change when they share its group", () => {
const layout = scriptOutputLayout(together, messages, true)
expect([...layout.afterChanges]).toEqual(["script"])
expect([...layout.outputAfter.keys()]).toEqual(["msg_a:script:file:1:b.ts"])
})
test("moves nothing without the flat layout", () => {
const layout = scriptOutputLayout(rows, messages, false)

View file

@ -6,8 +6,9 @@ type Tool = Extract<SessionMessageAssistant["content"][number], { type: "tool" }
/**
* Where each script's Output row goes. A script whose changes are drawn right after it, as the next items of its group or
* as the row after its own, reads steps, then changes, then Output: its Output row follows its last change. Anywhere
* else, as when its changes are hidden or grouped apart from it, its Output row stays under its steps.
* as the row of cards after its own, reads steps, then changes, then Output: its Output row follows its last change.
* Anywhere else, as when its changes are hidden or grouped into a summary row apart from it, its Output row stays under
* its steps.
*/
export type ScriptOutputLayout = {
/** Scripts, by part id, whose Output row follows their changes. */

View file

@ -187,10 +187,13 @@ export namespace TimelineRow {
Activity: () => (other: TimelineRow) => Predicate.isTagged(other, "Activity"),
})
/** A row of the changes a script made, which belongs to the script's block above it. */
/**
* A row of the changes a script made, drawn as their own cards, which belongs to the script's block above it. Changes
* grouped into a summary row with other edits stand apart from the script, as any other block does.
*/
export function scriptChanges(row: TimelineRow) {
if (!Predicate.isTagged(row, "AssistantPart")) return false
const refs = row.group.type === "part" ? [row.group.ref] : row.group.refs
if (!Predicate.isTagged(row, "AssistantPart") || row.group.type !== "file") return false
const refs = row.group.refs
return refs.length > 0 && refs.every((ref) => isScriptFilePartID(ref.partID))
}