diff --git a/packages/session-ui/src/timeline-next/timeline-next.css b/packages/session-ui/src/timeline-next/timeline-next.css index 6dbb010470f..6d1ebf342e7 100644 --- a/packages/session-ui/src/timeline-next/timeline-next.css +++ b/packages/session-ui/src/timeline-next/timeline-next.css @@ -55,8 +55,8 @@ } /* Each changed file is its own accordion, rather than one stacked group, as far from the next - as any two rows. */ -[data-timeline="next"] [data-component="accordion"][data-scope="apply-patch"] { + as any two rows. A script's changes stay one stacked group, so one call's files read as one block. */ +[data-timeline="next"] [data-component="accordion"][data-scope="apply-patch"]:not([data-script-change] *) { gap: var(--timeline-gap-s); [data-slot="accordion-item"] + [data-slot="accordion-item"] { @@ -76,14 +76,16 @@ border-bottom-left-radius: var(--radius-lg); border-bottom-right-radius: var(--radius-lg); } +} - /* A created file is all new, so its code reads plain rather than as one long addition. */ +/* A created file is all new, so its code reads plain rather than as one long addition. */ +[data-timeline="next"] + [data-component="accordion"][data-scope="apply-patch"] [data-slot="accordion-item"][data-type="add"] { - --opencode-diffs-addition-bg: transparent; - --opencode-diffs-addition-number-fg: var(--v2-text-text-faint); - --opencode-diffs-addition-color: transparent; - --diffs-addition-color-override: transparent; - } + --opencode-diffs-addition-bg: transparent; + --opencode-diffs-addition-number-fg: var(--v2-text-text-faint); + --opencode-diffs-addition-color: transparent; + --diffs-addition-color-override: transparent; } /* A command the user ran is its command and output, always showing, as an agent's command shows once opened. */ diff --git a/packages/session-ui/src/tools/tool-renderer.tsx b/packages/session-ui/src/tools/tool-renderer.tsx index 8eeb716683b..80b3caa0338 100644 --- a/packages/session-ui/src/tools/tool-renderer.tsx +++ b/packages/session-ui/src/tools/tool-renderer.tsx @@ -1138,10 +1138,42 @@ function scriptChangePartID(file: FileFact) { return file.id.slice(file.id.indexOf(":") + 1) } +// A script change as the patch view draws it, or undefined for one it can't: no diff, past the size cap, binary, a +// copy or a delete. +function scriptChangeDiff(file: FileFact): FileDiffInfo | undefined { + const value = { + file: file.path, + patch: file.patch, + additions: file.additions ?? 0, + deletions: file.deletions ?? 0, + status: file.change ?? "modified", + } + + return changedFileDiff(value) ? value : undefined +} + +type ScriptChangeRun = { type: "patch"; files: FileFact[] } | { type: "counts"; file: FileFact } + +// Changes with a diff that follow one another share one group, as a patch's files do; each other change stands alone. +function scriptChangeRuns(files: readonly FileFact[]): ScriptChangeRun[] { + const runs: ScriptChangeRun[] = [] + + for (const file of files) { + const last = runs.at(-1) + + if (!scriptChangeDiff(file)) runs.push({ type: "counts", file }) + else if (last?.type === "patch") last.files.push(file) + else runs.push({ type: "patch", files: [file] }) + } + + return runs +} + /** - * The changes a script made, in order, one card each: the same file changed twice is two cards. A change without a - * diff, past the size cap, to a binary file, a copy or a delete, shows what it did as a patch's file header does. Each - * card opens by the change's own id. + * The changes a script made, in order. Changes with a diff that follow one another share one group, a row per file, as + * a patch's files do: a script that changes a file more than once lists it once per change, and the group draws each + * of those diffs under the file's one row. A change without a diff shows what it did as a patch's file header does. + * Each file opens by the id of its first change. */ export function ScriptChanges(props: { files: readonly FileFact[] @@ -1150,7 +1182,6 @@ export function ScriptChanges(props: { onFileOpenChange?: (key: string, open: boolean) => void onSizeChange?: () => void }) { - const i18n = useI18n() const placement = useContext(ScriptOutputContext) // The Output row of a script whose last change this is, when its changes are drawn right after it. @@ -1162,94 +1193,38 @@ export function ScriptChanges(props: { : undefined } + const runs = createMemo(() => scriptChangeRuns(props.files)) + // One wrapper, as a direct patch's files share one, so the turn's gap falls around the list and not between changes. return (