mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-29 11:42:17 +00:00
feat(app): fold a finished compaction into one divider
This commit is contained in:
parent
50f410ba74
commit
58617fd920
6 changed files with 85 additions and 43 deletions
|
|
@ -59,6 +59,7 @@ for (const { width, ...profile } of [
|
|||
notices.evaluateAll((nodes) =>
|
||||
nodes.map((node) => {
|
||||
const style = getComputedStyle(node)
|
||||
// SAFETY: the locator matches only rendered timeline notices, which are HTML elements.
|
||||
const element = node as HTMLElement
|
||||
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -1449,15 +1449,17 @@ test.describe("compaction", () => {
|
|||
)
|
||||
await expect(compaction).toContainText("Final implementation details.")
|
||||
await expect(compaction).not.toContainText("Streamed implementation details.")
|
||||
await expect(compaction.getByText("Session compaction started", { exact: true })).toBeVisible()
|
||||
await expect(compaction.getByText("Session compacted", { exact: true })).toBeVisible()
|
||||
await expect(compaction.getByRole("button", { name: "Summary", exact: true })).toBeVisible()
|
||||
|
||||
// Finished, the summary sits under a single divider that folds it.
|
||||
const done = compaction.getByRole("button", { name: "Session compacted", exact: true })
|
||||
await expect(done).toHaveAttribute("aria-expanded", "true")
|
||||
await expect(compaction.getByText("Session compaction started", { exact: true })).toHaveCount(0)
|
||||
await expect
|
||||
.poll(async () => {
|
||||
const body = await summary.boundingBox()
|
||||
const done = await compaction.getByText("Session compacted", { exact: true }).boundingBox()
|
||||
const body = await compaction.locator('[data-component="text-part"]').boundingBox()
|
||||
const divider = await done.boundingBox()
|
||||
|
||||
return !!body && !!done && done.y >= body.y + body.height
|
||||
return !!body && !!divider && body.y >= divider.y + divider.height
|
||||
})
|
||||
.toBe(true)
|
||||
await expect(compaction.getByRole("status")).toHaveCount(0)
|
||||
|
|
@ -1475,9 +1477,9 @@ test.describe("compaction", () => {
|
|||
await expect(compaction.getByText("Streamed folded details.")).toBeHidden()
|
||||
|
||||
await timeline.send(compactionEnded({ sessionID, reason: "auto", text: "Final folded details." }))
|
||||
await expect(compaction.getByText("Session compacted", { exact: true })).toBeVisible()
|
||||
const trigger = compaction.getByRole("button", { name: "Summary", exact: true })
|
||||
const trigger = compaction.getByRole("button", { name: "Session compacted", exact: true })
|
||||
await expect(trigger).toHaveAttribute("aria-expanded", "false")
|
||||
await expect(compaction.getByText("Session compaction started", { exact: true })).toHaveCount(0)
|
||||
await expect(compaction.getByText("Final folded details.")).toBeHidden()
|
||||
|
||||
await trigger.click()
|
||||
|
|
@ -1518,7 +1520,10 @@ test.describe("compaction", () => {
|
|||
for (const names of [["failed", "cancelled"], ["interrupted"]] as const) {
|
||||
test(`ends running compactions as ${names.join(", then ")}`, async ({ page }) => {
|
||||
// Expanded notices show the partial summary while it streams.
|
||||
const settings = { timelineDetail: { ...detailed, notices: { placement: "grouped", details: "expanded" } } } as const
|
||||
const settings = {
|
||||
timelineDetail: { ...detailed, notices: { placement: "grouped", details: "expanded" } },
|
||||
} as const
|
||||
|
||||
const timeline = await setupTimeline(
|
||||
page,
|
||||
names[0] === "interrupted"
|
||||
|
|
|
|||
|
|
@ -37,9 +37,11 @@ describe("settings timeline detail migration", () => {
|
|||
|
||||
test("gives saved notices the compaction summary detail their placement showed", () => {
|
||||
const { details: _, ...everythingNotices } = timelinePresets[0].value.notices
|
||||
|
||||
const everything = decode({
|
||||
general: { timelineDetail: { ...timelinePresets[0].value, notices: everythingNotices } },
|
||||
})
|
||||
|
||||
const grouped = decode({ general: { timelineDetail: { notices: { placement: "grouped" } } } })
|
||||
|
||||
expect(everything.general.timelineDetail).toEqual(timelinePresets[0].value)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { ProviderIcon } from "@opencode/ui/provider-icon"
|
||||
import { Tooltip } from "@opencode/ui/tooltip"
|
||||
import { Show } from "solid-js"
|
||||
import { Show, type JSX } from "solid-js"
|
||||
|
||||
export function TimelineSeparator(props: {
|
||||
label: string
|
||||
|
|
@ -8,6 +8,8 @@ export function TimelineSeparator(props: {
|
|||
tooltip?: string
|
||||
providerID?: string
|
||||
variant?: string
|
||||
/** Shown after the label, such as a 24px disclosure arrow. */
|
||||
suffix?: JSX.Element
|
||||
}) {
|
||||
const label = () => (
|
||||
<bdi
|
||||
|
|
@ -29,6 +31,10 @@ export function TimelineSeparator(props: {
|
|||
{(providerID) => <ProviderIcon id={providerID()} class="text-v2-icon-icon-faint" aria-hidden="true" />}
|
||||
</Show>
|
||||
<span class="flex min-w-0 items-center gap-1.5">
|
||||
{/* Balances the suffix so the label stays centered on the line. */}
|
||||
<Show when={props.suffix}>
|
||||
<span class="w-6 shrink-0" aria-hidden="true" />
|
||||
</Show>
|
||||
<Show when={props.tooltip} fallback={label()}>
|
||||
{(tooltip) => (
|
||||
<Tooltip
|
||||
|
|
@ -61,6 +67,7 @@ export function TimelineSeparator(props: {
|
|||
</>
|
||||
)}
|
||||
</Show>
|
||||
{props.suffix}
|
||||
</span>
|
||||
</span>
|
||||
<span class="h-px min-w-0 flex-1 bg-v2-border-border-strong" />
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import { TextShimmer } from "@opencode/ui/text-shimmer"
|
|||
import { BasicTool } from "../components/basic-tool"
|
||||
import { reasoningHeading } from "../timeline/projection"
|
||||
import { Card } from "@opencode/ui/card"
|
||||
import { Collapsible } from "@opencode/ui/collapsible"
|
||||
import type {
|
||||
PromptAgentAttachment,
|
||||
PromptFileAttachment,
|
||||
|
|
@ -639,40 +640,67 @@ export function SessionCompactionMessage(props: {
|
|||
|
||||
const label = createMemo(() => [i18n.t(outcome()), usage()].filter(Boolean).join(" · "))
|
||||
|
||||
const setOpen = (value: boolean) => {
|
||||
setState("open", value)
|
||||
props.onOpenChange?.(value)
|
||||
}
|
||||
|
||||
return (
|
||||
<div data-component="session-compaction-message">
|
||||
<CompactionDivider label={i18n.t("ui.messagePart.compaction.started")} />
|
||||
<Show when={running() || summary().trim()}>
|
||||
<div role={running() ? "status" : undefined} class="py-2" data-timeline-part-id={props.message.id}>
|
||||
<BasicTool
|
||||
icon="archive"
|
||||
status={running() ? "running" : "completed"}
|
||||
compact
|
||||
hasContent
|
||||
allowOpenWhilePending
|
||||
hideDetails={!summary().trim()}
|
||||
open={open()}
|
||||
onOpenChange={(value) => {
|
||||
setState("open", value)
|
||||
props.onOpenChange?.(value)
|
||||
}}
|
||||
trigger={{
|
||||
title: i18n.t(running() ? "ui.messagePart.compaction.running" : "ui.messagePart.compaction.summary"),
|
||||
}}
|
||||
>
|
||||
<PacedMarkdown text={summary()} cacheKey={props.message.id} streaming={running()} />
|
||||
</BasicTool>
|
||||
</div>
|
||||
</Show>
|
||||
<Show when={props.message.status !== "running"}>
|
||||
<div class="py-2">
|
||||
<TimelineSeparator label={label()} />
|
||||
</div>
|
||||
</Show>
|
||||
<Show when={error()}>
|
||||
<Card variant="error" class="error-card">
|
||||
{error()}
|
||||
</Card>
|
||||
<Show
|
||||
when={props.message.status === "completed" && summary().trim()}
|
||||
fallback={
|
||||
<>
|
||||
<CompactionDivider label={i18n.t("ui.messagePart.compaction.started")} />
|
||||
<Show when={running()}>
|
||||
<div role="status" class="py-2" data-timeline-part-id={props.message.id}>
|
||||
<BasicTool
|
||||
icon="archive"
|
||||
status="running"
|
||||
compact
|
||||
hasContent
|
||||
allowOpenWhilePending
|
||||
hideDetails={!summary().trim()}
|
||||
open={open()}
|
||||
onOpenChange={setOpen}
|
||||
trigger={{ title: i18n.t("ui.messagePart.compaction.running") }}
|
||||
>
|
||||
<PacedMarkdown text={summary()} cacheKey={props.message.id} streaming />
|
||||
</BasicTool>
|
||||
</div>
|
||||
</Show>
|
||||
<Show when={!running()}>
|
||||
<div class="py-2">
|
||||
<TimelineSeparator label={label()} />
|
||||
</div>
|
||||
</Show>
|
||||
<Show when={error()}>
|
||||
<Card variant="error" class="error-card">
|
||||
{error()}
|
||||
</Card>
|
||||
</Show>
|
||||
</>
|
||||
}
|
||||
>
|
||||
{/* A finished summary folds into its outcome divider, which opens it. */}
|
||||
<Collapsible
|
||||
variant="ghost"
|
||||
class="py-2"
|
||||
open={open()}
|
||||
onOpenChange={setOpen}
|
||||
data-timeline-part-id={props.message.id}
|
||||
>
|
||||
<Collapsible.Trigger class="cursor-pointer">
|
||||
<TimelineSeparator label={label()} suffix={<Collapsible.Arrow style={{ opacity: 1 }} />} />
|
||||
</Collapsible.Trigger>
|
||||
<Collapsible.Content>
|
||||
<div data-component="text-part">
|
||||
<div data-slot="text-part-body">
|
||||
<PacedMarkdown text={summary()} cacheKey={props.message.id} streaming={false} />
|
||||
</div>
|
||||
</div>
|
||||
</Collapsible.Content>
|
||||
</Collapsible>
|
||||
</Show>
|
||||
</div>
|
||||
)
|
||||
|
|
|
|||
|
|
@ -113,7 +113,6 @@ const source = {
|
|||
"ui.messagePart.compaction.started": "Session compaction started",
|
||||
"ui.messagePart.compaction.queued": "Session compaction queued",
|
||||
"ui.messagePart.compaction.running": "Compacting",
|
||||
"ui.messagePart.compaction.summary": "Summary",
|
||||
"ui.messagePart.compaction.failed": "Session compaction failed",
|
||||
"ui.messagePart.compaction.cancelled": "Session compaction cancelled",
|
||||
"ui.messagePart.compaction.interrupted": "Session compaction interrupted",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue