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 (
- - {(file) => { - const diff = createMemo( - () => { - const value = { - file: file().path, - patch: file().patch, - additions: file().additions ?? 0, - deletions: file().deletions ?? 0, - status: file().change ?? "modified", - } + + {(run) => { + const group = createMemo(() => { + const value = run() - return changedFileDiff(value) ? value : undefined - }, - undefined, - // A progress report reads each change again; the same diff keeps its parsed view. - { - equals: (previous, next) => - previous === next || - (!!previous && - !!next && - previous.file === next.file && - previous.patch === next.patch && - previous.additions === next.additions && - previous.deletions === next.deletions && - previous.status === next.status), - }, - ) + return value.type === "patch" ? value.files : undefined + }) + + const single = createMemo(() => { + const value = run() + + return value.type === "counts" ? value.file : undefined + }) return ( - - - - {`\u202A${displayDirectory(file().path)}\u202C`} - - {getFilename(file().path)} - - - - - {i18n.t("ui.patch.action.created")} - - - - - {i18n.t("ui.patch.action.deleted")} - - - 0}> - - - -
- } + when={group()} + fallback={{(file) => }} > - {(value) => ( -
- props.fileOpen?.(file().id))} - onFileOpenChange={ - props.onFileOpenChange && - ((_: string, open: boolean) => props.onFileOpenChange?.(file().id, open)) - } - deferContent - virtualizeDiff={false} - onContentRendered={props.onSizeChange} - /> -
+ {(files) => ( + )} ) @@ -1266,6 +1241,96 @@ export function ScriptChanges(props: { ) } +// Changes with a diff that follow one another, drawn as one patch's files are: a row per file, its diffs under it. +function ScriptChangeGroup(props: { + files: readonly FileFact[] + render: Component + fileOpen?: (key: string) => boolean | undefined + onFileOpenChange?: (key: string, open: boolean) => void + onSizeChange?: () => void +}) { + const diffs = createMemo( + () => + props.files.flatMap((file) => { + const diff = scriptChangeDiff(file) + + return diff ? [diff] : [] + }), + [], + { + // A progress report reads each change again; the same diffs keep their parsed views. + equals: (previous, next) => + previous.length === next.length && previous.every((value, index) => samePatchFile(value, next[index]!)), + }, + ) + + // A file's row opens by the id of its first change, so a later change to it keeps the row as it was. + const key = (path: string) => props.files.find((file) => file.path === path)?.id ?? path + + return ( +
1 ? props.files.map(scriptChangePartID).join(",") : undefined} + > + props.fileOpen?.(key(path)))} + onFileOpenChange={ + props.onFileOpenChange && ((path: string, open: boolean) => props.onFileOpenChange?.(key(path), open)) + } + deferContent + virtualizeDiff={false} + onContentRendered={props.onSizeChange} + /> +
+ ) +} + +// A change without a diff, shown as a patch's file header shows what it did. +function ScriptChangeCounts(props: { file: FileFact }) { + const i18n = useI18n() + + return ( +
+ + + + {`\u202A${displayDirectory(props.file.path)}\u202C`} + + {getFilename(props.file.path)} + + + + + {i18n.t("ui.patch.action.created")} + + + + + {i18n.t("ui.patch.action.deleted")} + + + 0}> + + + +
+ ) +} + export { fileRuns, runDisclosureKey, type FileRun } from "./file-runs" export function scrollParent(element: HTMLElement): HTMLElement | undefined { @@ -2323,12 +2388,7 @@ function ExecuteDetails(props: { code: string; output: string; error?: string; s ) } -function ExecuteDetailsSection(props: { - label: string - copy: string - copyLabel: string - children: JSX.Element -}) { +function ExecuteDetailsSection(props: { label: string; copy: string; copyLabel: string; children: JSX.Element }) { const i18n = useI18n() const copy = createCopyFeedback()