From 191a69ad45ef0ca4925d8b7683eacdca0e8224e0 Mon Sep 17 00:00:00 2001 From: Aarav Sareen <96787824+arvsrn@users.noreply.github.com> Date: Fri, 13 Nov 2026 18:18:43 +0530 Subject: [PATCH] fix(app): tidy New timeline questions, moves, compaction and shells (#63751) --- .../src/timeline-next/compaction.tsx | 234 ++++++++++++++++++ .../src/timeline-next/projection.test.ts | 32 +++ .../src/timeline-next/projection.ts | 3 +- packages/session-ui/src/timeline-next/row.tsx | 18 +- .../src/timeline-next/rules.test.ts | 5 +- .../session-ui/src/timeline-next/rules.ts | 10 +- .../src/timeline-next/timeline-next.css | 143 ++++------- .../timeline-next/tools/clamped-content.tsx | 51 ---- .../src/timeline-next/tools/shell.tsx | 123 +-------- 9 files changed, 330 insertions(+), 289 deletions(-) create mode 100644 packages/session-ui/src/timeline-next/compaction.tsx delete mode 100644 packages/session-ui/src/timeline-next/tools/clamped-content.tsx diff --git a/packages/session-ui/src/timeline-next/compaction.tsx b/packages/session-ui/src/timeline-next/compaction.tsx new file mode 100644 index 00000000000..492576dc235 --- /dev/null +++ b/packages/session-ui/src/timeline-next/compaction.tsx @@ -0,0 +1,234 @@ +import type { SessionMessageCompaction } from "@opencode/client/promise" +import { Card } from "@opencode/ui/card" +import { useI18n } from "@opencode/ui/context/i18n" +import { createEffect, createMemo, createSignal, onCleanup, Show, untrack } from "solid-js" +import { BasicTool } from "../components/basic-tool" +import { LinkedText } from "../components/linked-text" +import { useData } from "../context" +import { + createCompactionEntranceState, + DISPOSED_COMPACTION_ENTRANCE_EVENT, + GRACE_ELAPSED_EVENT, + selectCompactionEnter, + transitionCompactionEntrance, + type CompactionEntranceEffect, + type CompactionEntranceEvent, +} from "../message/compaction-entrance-machine" +import { PacedMarkdown } from "../message/message-content" +import { Separator } from "./separator" + +/** A compaction the server admitted but has not started, drawn as the divider a started one opens with. */ +export function CompactionQueued() { + const i18n = useI18n() + + return ( +
+ +
+ ) +} + +/** + * A compaction, drawn with the timeline's own dividers: as tall as their text, with a plain line, spaced like the rows + * around them. An automatic one with background compaction on is one quiet divider instead. + */ +export function CompactionMessage(props: { message: SessionMessageCompaction; error: string }) { + const i18n = useI18n() + const data = useData() + const summary = () => (props.message.status === "failed" ? "" : props.message.summary) + + const error = () => { + if (props.message.status !== "failed") return "" + + if (props.message.error.type === "aborted" || props.message.error.type === "compaction.interrupted") return "" + + return props.error + } + + const compact = createMemo( + () => new Intl.NumberFormat(i18n.locale(), { notation: "compact", maximumFractionDigits: 1 }), + ) + + // Usage of the compaction request itself; the resulting context size only shows on the next assistant step. + const usage = () => { + if (props.message.status === "running" || !props.message.tokens) return "" + const tokens = props.message.tokens + const input = tokens.input + tokens.cache.read + tokens.cache.write + const output = tokens.output + tokens.reasoning + + if (input + output <= 0) return "" + + return i18n.t("ui.messagePart.compaction.usage", { + input: compact().format(input), + output: compact().format(output), + }) + } + + const outcome = () => { + if (props.message.status !== "failed") + return props.message.status === "completed" && props.message.native?.messages + ? "ui.messagePart.providerCompaction" + : "ui.messagePart.compaction" + + if (props.message.error.type === "aborted") return "ui.messagePart.compaction.cancelled" + + if (props.message.error.type === "compaction.interrupted") return "ui.messagePart.compaction.interrupted" + + return "ui.messagePart.compaction.failed" + } + + const label = createMemo(() => [i18n.t(outcome()), usage()].filter(Boolean).join(" ยท ")) + + return ( + + } + > +
+ + +
+
+ +
+
+
+ +
+ +
+
+ + + + + + + + +
+
+ ) +} + +/** + * An automatic compaction, drawn as one divider that reads Compacting, then Compacted. Its height never changes, and + * clicking it opens the summary. + */ +function QuietCompaction(props: { id: string; created: number; running: boolean; summary: string; usage: string }) { + const i18n = useI18n() + const [open, setOpen] = createSignal(false) + // A new one waits out the grace before showing Compacting; one that ends inside it, as a precomputed summary does, + // only fades in as Compacted. One already running or finished when the history loads shows without an entrance. + const initial = createCompactionEntranceState({ ageMs: Date.now() - props.created, running: props.running }) + const [entrance, setEntrance] = createSignal(initial.state) + const enter = createMemo(() => selectCompactionEnter(entrance())) + let graceTimer: ReturnType | undefined + + const runEntrance = (effect: CompactionEntranceEffect) => { + clearTimeout(graceTimer) + graceTimer = undefined + + if (effect.type === "schedule-grace") + graceTimer = setTimeout(() => dispatchEntrance(GRACE_ELAPSED_EVENT), effect.delayMs) + } + + const dispatchEntrance = (event: CompactionEntranceEvent) => { + const result = transitionCompactionEntrance(untrack(entrance), event) + setEntrance(result.state) + result.effects.forEach(runEntrance) + } + + initial.effects.forEach(runEntrance) + createEffect(() => dispatchEntrance({ type: "running.changed", running: props.running })) + onCleanup(() => dispatchEntrance(DISPOSED_COMPACTION_ENTRANCE_EVENT)) + + const expandable = () => !props.running && !!props.summary.trim() + + const label = createMemo(() => + splitEnding(i18n.t("ui.messagePart.compaction.running"), i18n.t("ui.messagePart.compaction.done")), + ) + + return ( +
+ + +
+
+
+ +
+
+ +
{props.usage}
+
+
+
+
+ ) +} + +/** Splits Compacting and Compacted at their shared stem, so only the ending changes when the compaction ends. */ +function splitEnding(running: string, done: string) { + const chars = [...running] + const others = [...done] + const at = chars.findIndex((char, index) => char !== others[index]) + const stem = chars.slice(0, at === -1 ? chars.length : at).join("") + + return { running, done, stem, ending: { running: running.slice(stem.length), done: done.slice(stem.length) } } +} diff --git a/packages/session-ui/src/timeline-next/projection.test.ts b/packages/session-ui/src/timeline-next/projection.test.ts index 549e2513abb..2f07936191f 100644 --- a/packages/session-ui/src/timeline-next/projection.test.ts +++ b/packages/session-ui/src/timeline-next/projection.test.ts @@ -214,6 +214,38 @@ describe("New timeline projection", () => { expect(groups([...launched, said, report], grouped)).toEqual(["context:launch", "events:report"]) expect(groups([...launched, report], detailed)).toEqual(["events:launch", "events:report"]) }) + + test("a move shows only when it changes where the session is", () => { + const moved = (id: string, created: number, from: string, to: string): SessionMessageInfo => ({ + id, + type: "location-switched", + location: { directory: to }, + previous: { location: { directory: from } }, + time: { created }, + }) + + const messages: SessionMessageInfo[] = [ + { id: "user", type: "user", text: "Go", time: { created: 0 } }, + moved("into", 1, "/repo", "/repo-worktree"), + moved("again", 2, "/repo-worktree", "/repo-worktree"), + moved("back", 3, "/repo-worktree", "/repo"), + ] + + const notices = createRoot((dispose) => { + const projection = createNextTimelineProjection({ + sessionMessages: () => messages, + status: () => ({ type: "idle" }), + timelineDetail: () => detailed, + }) + + const result = projection.rows().flatMap((row) => (Predicate.isTagged(row, "Notice") ? [row.messageID] : [])) + dispose() + + return result + }) + + expect(notices).toEqual(["into", "back"]) + }) }) describe("workedDuration", () => { diff --git a/packages/session-ui/src/timeline-next/projection.ts b/packages/session-ui/src/timeline-next/projection.ts index 5edf5cea944..3fd26a0206a 100644 --- a/packages/session-ui/src/timeline-next/projection.ts +++ b/packages/session-ui/src/timeline-next/projection.ts @@ -29,6 +29,7 @@ import { echoesUserShell, hidesActivity, liveThinkingShows, + movedInPlace, noticePlacement, textShows, toolRule, @@ -374,7 +375,7 @@ function constructTurns(input: Input) { } input.messages.forEach((message) => { - if (echoesUserShell(message, userShellIDs)) return + if (echoesUserShell(message, userShellIDs) || movedInPlace(message)) return if (isNotice(message)) { // A notice still waiting for delivery, such as a subagent reporting back, already happened, so it joins the diff --git a/packages/session-ui/src/timeline-next/row.tsx b/packages/session-ui/src/timeline-next/row.tsx index 5b0b04ecddf..65ff02f7ee3 100644 --- a/packages/session-ui/src/timeline-next/row.tsx +++ b/packages/session-ui/src/timeline-next/row.tsx @@ -31,7 +31,6 @@ import { useData } from "../context" import { useSources } from "../context/sources" import { turnSources } from "../sources/sources" import { SessionReadToolGroup, SessionUserMessage } from "../message/current-message" -import { SessionCompactionMessage, SessionCompactionQueued } from "../message/message-content" import { taskAgentName } from "../tools/tool-renderer" import { SessionRetry } from "../components/session-retry" import { SessionError } from "../components/session-error" @@ -48,12 +47,13 @@ import { } from "../timeline/steer-arrival-machine" import { Badge } from "@opencode/ui/badge" import { attached } from "../components/message-file" +import { CompactionMessage, CompactionQueued } from "./compaction" import { unwrapErrorMessage } from "./errors" import { TimelineEventRow } from "./event-row" import { noticeEvent, toolEvent } from "./events" import { trackNestedRails } from "./nested-rail" import { contentEntries, createNextTimelineProjection, resolveContent, workedDuration } from "./projection" -import { contentOpens, diffOpens, goal as goalMessage, thoughtOpens, toolRule, userShellOpens } from "./rules" +import { contentOpens, diffOpens, goal as goalMessage, movedInPlace, thoughtOpens, toolRule } from "./rules" import { Separator } from "./separator" import { timelineGaps } from "./spacing" import { AssistantContent } from "./tools/assistant-content" @@ -144,7 +144,9 @@ export function createNextTimelineRowRenderer(input: { const messages = input.projection.messageByID() const context = input.projection.userContextByID() - return userMessageRuns(input.projection.rows(), [...messages.values()], (id) => { + const boundaries = [...messages.values()].filter((message) => !movedInPlace(message)) + + return userMessageRuns(input.projection.rows(), boundaries, (id) => { const message = messages.get(id) const user = context.get(id) @@ -816,7 +818,7 @@ export function createNextTimelineRowRenderer(input: { {(message) => (
- +
)} @@ -925,11 +927,7 @@ export function createNextTimelineRowRenderer(input: { {(message) => (
- input.disclosure.set(message().id, open)} - /> +
)}
@@ -1174,7 +1172,7 @@ export function createNextTimelineRowRenderer(input: {
- +
diff --git a/packages/session-ui/src/timeline-next/rules.test.ts b/packages/session-ui/src/timeline-next/rules.test.ts index a69a11a4454..5d33ffd7304 100644 --- a/packages/session-ui/src/timeline-next/rules.test.ts +++ b/packages/session-ui/src/timeline-next/rules.test.ts @@ -11,7 +11,6 @@ import { thoughtOpens, toolFailed, toolStopped, - userShellOpens, } from "./rules" import { timelineStatus } from "./status" @@ -110,12 +109,10 @@ describe("echoesUserShell", () => { }) describe("details", () => { - test("shell details decide whether a command's whole output shows, for the agent's commands and the user's", () => { + test("shell details decide whether an agent's command opens to its whole output", () => { expect(contentOpens(preset("everything"), tool("shell"))).toBe(true) expect(contentOpens(preset("compact"), tool("shell"))).toBe(false) expect(contentOpens(preset("compact"), tool("execute"))).toBe(false) - expect(userShellOpens(preset("everything"))).toBe(true) - expect(userShellOpens(preset("compact"))).toBe(false) }) test("thinking details stream the live thought in view, and every finished thought starts closed", () => { diff --git a/packages/session-ui/src/timeline-next/rules.ts b/packages/session-ui/src/timeline-next/rules.ts index 6b55eb4a493..e18b1ed5fac 100644 --- a/packages/session-ui/src/timeline-next/rules.ts +++ b/packages/session-ui/src/timeline-next/rules.ts @@ -189,11 +189,6 @@ export function liveThinkingShows(detail: TimelineDetail) { return detail.thinking.placement !== "hidden" } -/** A command the user ran always shows, whole where shell details expand and its last lines otherwise. */ -export function userShellOpens(detail: TimelineDetail) { - return detail.shell.details === "expanded" -} - /** The notice the agent gets about a command the user ran repeats that command's own card, so it never shows. */ export function echoesUserShell(message: SessionMessageInfo, userShellIDs: ReadonlySet) { const shellID = message.type === "synthetic" ? message.metadata?.shellID : undefined @@ -236,6 +231,11 @@ export function sessionEvent(message: SessionMessageInfo) { return goal(message) } +/** A move to where the session already is changes nothing, so it shows nothing. */ +export function movedInPlace(message: SessionMessageInfo) { + return message.type === "location-switched" && message.previous?.location.directory === message.location.directory +} + /** A goal the user set, which reads as their own message. */ export function goal( message: SessionMessageInfo | undefined, diff --git a/packages/session-ui/src/timeline-next/timeline-next.css b/packages/session-ui/src/timeline-next/timeline-next.css index 62f2b6146dd..bfae00e1812 100644 --- a/packages/session-ui/src/timeline-next/timeline-next.css +++ b/packages/session-ui/src/timeline-next/timeline-next.css @@ -76,106 +76,12 @@ } } -/* Cut output shows its last lines, fading out at the top where it is cut. */ -[data-timeline="next"] [data-component="clamped-content"] { - &[data-clamped] { - max-height: var(--clamped-content-height, 96px); - overflow: hidden; - } - - /* The fade is the code's own background, so the cut lines fade into the block rather than through it. */ - &[data-overflow] { - position: relative; - - &::after { - content: ""; - position: absolute; - inset-inline: 0; - top: 0; - height: 20px; - background: linear-gradient(var(--clamped-content-fade), transparent); - pointer-events: none; - } - } -} - -/* A command the user ran is its command and output, always showing, with the output cut to four lines. */ -[data-timeline="next"] [data-component="shell-tool"] { - [data-slot="shell-tool-writing"] { - display: block; - font-size: 13px; - line-height: var(--line-height-compact); - color: var(--v2-text-text-muted); - } - - [data-component="bash-output"][data-clamp] { - [data-slot="bash-scroll"] { - max-height: none; - } - - [data-component="clamped-content"] { - grid-area: 1 / 1; - /* The 12px top padding and four 20px lines of output, as a plain length the clamp can read back. */ - --clamped-content-height: 92px; - --clamped-content-fade: var(--bash-section-background); - } - } -} - -/* The output's toggle sits at the end of the command line, so neither block's text is a click target. */ -[data-timeline="next"] [data-component="shell-tool"] [data-slot="bash-command"] { - /* How the command ended and the output's toggle, above the command, which shares their grid cell and comes later, - so paints over it. The inset matches the file header's toggle. */ - [data-slot="bash-actions"] { - position: relative; - z-index: 1; - grid-area: 1 / 1; - justify-self: end; - align-self: center; - display: flex; - align-items: center; - gap: 8px; - margin-inline-end: 8px; - } - - [data-slot="bash-outcome"] { - font-family: var(--v2-font-family-sans); - font-size: 13px; - font-weight: 440; - line-height: var(--line-height-compact); - letter-spacing: -0.04px; - white-space: nowrap; - color: var(--v2-text-text-muted); - - &[data-tone="danger"] { - color: var(--v2-state-fg-danger); - } - } - - [data-slot="bash-toggle-button"] { - display: flex; - align-items: center; - justify-content: center; - padding: 0; - border: 0; - background: none; - color: inherit; - cursor: default; - - &:focus-visible { - outline: 1px solid var(--v2-text-text-accent); - outline-offset: 2px; - border-radius: 2px; - } - } - - &:has([data-slot="bash-toggle"]) [data-slot="bash-pre"] { - padding-inline-end: 40px; - } - - &:has([data-slot="bash-outcome"]) [data-slot="bash-pre"] { - padding-inline-end: 120px; - } +/* A command the user ran is its command and output, always showing, as an agent's command shows once opened. */ +[data-timeline="next"] [data-component="shell-tool"] [data-slot="shell-tool-writing"] { + display: block; + font-size: 13px; + line-height: var(--line-height-compact); + color: var(--v2-text-text-muted); } /* A file's change counts follow its name, showing only the side that changed; its change bars are quieter; and its @@ -509,6 +415,43 @@ height: calc(var(--line-height-compact) + 6px + var(--timeline-gap-s)); } } + + /* Answers are spaced by the row gaps and trimmed to their text, as the agent's text is. */ + [data-component="question-answers"] { + gap: var(--timeline-gap-s); + padding: 0; + line-height: var(--line-height-base); + + [data-slot="question-answer-item"] { + gap: 4px; + } + + [data-slot="question-text"], + [data-slot="answer-text"] { + text-box: trim-both text; + } + } + + /* A row's action is as tall as its line, so its button never makes the row taller. */ + [data-slot="basic-tool-action"] { + height: var(--line-height-compact); + + [data-component="icon-button-v2"] { + width: 20px; + height: 20px; + } + } + + /* The quiet compaction draws the same line as the other dividers. */ + [data-component="session-compaction-message"][data-quiet] { + [data-slot="session-compaction-line"]::before { + background: var(--v2-border-border-base); + } + + [data-slot="session-compaction-summary"] { + padding-bottom: 0; + } + } } /* The live thought sits where the row it settles into will, which its frame spaces like any other row. */ diff --git a/packages/session-ui/src/timeline-next/tools/clamped-content.tsx b/packages/session-ui/src/timeline-next/tools/clamped-content.tsx deleted file mode 100644 index f37941dd695..00000000000 --- a/packages/session-ui/src/timeline-next/tools/clamped-content.tsx +++ /dev/null @@ -1,51 +0,0 @@ -import { createEffect, createSignal, on, onCleanup, onMount, type JSX } from "solid-js" - -/** - * Output cut to its last few lines, as a command the user ran shows it, so the newest stay in view as running output - * grows. Its owner offers the control that shows the rest, so the text stays selectable. - */ -export function ClampedContent(props: { - expanded: boolean - /** Whether the content is longer than the cut, so the owner knows to offer its toggle. */ - onOverflowChange?: (overflow: boolean) => void - children: JSX.Element -}) { - const [overflow, setOverflow] = createSignal(false) - let frame: HTMLDivElement | undefined - let content: HTMLDivElement | undefined - - const measure = () => { - if (!frame || !content) return - // Measured against the cut height, so an expanded frame still knows whether it has more than the cut shows. - const limit = Number.parseFloat(getComputedStyle(frame).getPropertyValue("--clamped-content-height")) || 96 - setOverflow(content.offsetHeight > limit + 1) - - // Shifting the content rather than scrolling it keeps the fade over the frame's edge. - const shift = props.expanded ? 0 : Math.min(0, frame.clientHeight - content.offsetHeight) - - content.style.translate = shift ? `0 ${shift}px` : "" - } - - onMount(() => { - const observer = new ResizeObserver(measure) - - if (frame) observer.observe(frame) - - if (content) observer.observe(content) - onCleanup(() => observer.disconnect()) - }) - - createEffect(on(() => props.expanded, measure, { defer: true })) - createEffect(on(overflow, (value) => props.onOverflowChange?.(value))) - - return ( -
-
{props.children}
-
- ) -} diff --git a/packages/session-ui/src/timeline-next/tools/shell.tsx b/packages/session-ui/src/timeline-next/tools/shell.tsx index 17971b7fc15..c5fd9caad3c 100644 --- a/packages/session-ui/src/timeline-next/tools/shell.tsx +++ b/packages/session-ui/src/timeline-next/tools/shell.tsx @@ -2,11 +2,8 @@ import type { SessionMessageShell } from "@opencode/client/promise" import { Predicate } from "effect" import { type UiI18n, useI18n } from "@opencode/ui/context/i18n" import { Badge } from "@opencode/ui/badge" -import { Icon } from "@opencode/ui/icon" import { TextShimmer } from "@opencode/ui/text-shimmer" -import { Tooltip } from "@opencode/ui/tooltip" import { createComputed, createEffect, createMemo, createSignal, on, onCleanup, Show, untrack } from "solid-js" -import { LinkedText } from "../../components/linked-text" import { useData } from "../../context" import { createShellRunState, @@ -17,15 +14,7 @@ import { } from "../../tools/run-machine" import { createShellFollower } from "../../tools/shell-output" import { BasicTool } from "../../components/basic-tool" -import { - ConsoleCopy, - ConsoleOutput, - ShellSubmessage, - toolInput, - toolMetadata, - type ToolProps, -} from "../../tools/tool-renderer" -import { ClampedContent } from "./clamped-content" +import { ConsoleOutput, ShellSubmessage, toolInput, toolMetadata, type ToolProps } from "../../tools/tool-renderer" /** * An agent's shell call is a row of activity, as in the current timeline: Shell, then its command, cut to the row while @@ -83,15 +72,12 @@ export function ShellTool(props: ToolProps) { } /** - * A command the user ran shows as a card: its command and output, the output cut to its last lines, where a command says - * how it went, until expanded. How it ended sits on the card when it did not succeed. + * A command the user ran shows as an agent's shell call does once opened, its command and output, without the row above + * them to open it. */ function ShellCard(props: ToolProps) { const i18n = useI18n() const run = shellRun(props) - const [expanded, setExpanded] = createSignal(false) - const open = () => props.open ?? expanded() - const outcome = createMemo(() => shellOutcome(props.metadata, i18n)) run.follow() @@ -107,18 +93,7 @@ function ShellCard(props: ToolProps) { } > - { - const next = !open() - - setExpanded(next) - props.onOpenChange?.(next) - }} - /> + ) @@ -191,11 +166,7 @@ function shellOutcome(metadata: ToolProps["metadata"], i18n: UiI18n) { } /** A command the user ran. */ -export function ShellMessage(props: { - message: SessionMessageShell - open?: boolean - onOpenChange?: (open: boolean) => void -}) { +export function ShellMessage(props: { message: SessionMessageShell }) { return (
) } - -// Copy sits on the output only. The command's corner holds how the command ended, and the output's toggle once there is -// more than the cut shows. -function ShellOutput(props: { - command?: string - output: string - expanded: boolean - outcome?: { tone: "neutral" | "danger"; label: string } - onToggle: () => void -}) { - const i18n = useI18n() - const [overflow, setOverflow] = createSignal(false) - const toggleLabel = () => i18n.t(props.expanded ? "ui.common.showLess" : "ui.common.showMore") - - return ( -
-
- - {(command) => ( -
- -
- - {(outcome) => ( - - {outcome().label} - - )} - - -
- - - -
-
-
-
-
-                {command()}
-              
-
- )} -
- - {(output) => ( -
- - -
-                  
-                    
-                  
-                
-
-
- )} -
-
-
- ) -}