mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-20 18:57:17 +03:00
fix(app): keep new timeline status below reports and shorten file lists (#63686)
This commit is contained in:
committed by
GitHub
Unverified
parent
a554d70499
commit
688b60c078
@@ -513,7 +513,7 @@ function MessageTimelineView(
|
||||
// The lane keeps its height while empty, so Working and the hint come and go without moving the rows around it.
|
||||
// The bottom lane also keeps its height while live status moves into the Activity row, so the tail the activity pill
|
||||
// floats in never closes and a pinned timeline does not shift when input waits.
|
||||
const activity = (live: () => boolean) => (
|
||||
const activity = (live: () => boolean, inRow = false) => (
|
||||
<div
|
||||
classList={{
|
||||
"min-w-0 w-full max-w-full": true,
|
||||
@@ -538,6 +538,7 @@ function MessageTimelineView(
|
||||
<StatusLane
|
||||
class={turnPadding()}
|
||||
spacing={laneSpacing()}
|
||||
inRow={inRow}
|
||||
label={live() && working() ? language.t(`session.timeline.status.${nextStatus() ?? "working"}`) : undefined}
|
||||
collapsed={live() && liveThought() && !working() && !backgroundHintPresence.present()}
|
||||
>
|
||||
@@ -567,7 +568,7 @@ function MessageTimelineView(
|
||||
// row: Working hides and returns several times in one step, and each change would move that input 36px.
|
||||
const shown = createMemo((was) => was || working() || backgroundHintPresence.present(), false)
|
||||
|
||||
return <Show when={shown()}>{activity(() => true)}</Show>
|
||||
return <Show when={shown()}>{activity(() => true, true)}</Show>
|
||||
}}
|
||||
</Show>
|
||||
)}
|
||||
|
||||
@@ -2,6 +2,7 @@ import { describe, expect, test } from "bun:test"
|
||||
import type { SessionMessageAssistant, SessionMessageInfo, SessionMessageUser } from "@opencode/client/promise"
|
||||
import { Predicate } from "effect"
|
||||
import { createRoot } from "solid-js"
|
||||
import { subagentReport } from "../storybook/current-session-fixtures"
|
||||
import { timelinePresets } from "../timeline/detail"
|
||||
import { createNextTimelineProjection, workedDuration } from "./projection"
|
||||
import { replayScript, scenarios } from "./stories/session-replay"
|
||||
@@ -87,6 +88,67 @@ describe("New timeline projection", () => {
|
||||
|
||||
expect(groups).toEqual(["first", "notice", "second"])
|
||||
})
|
||||
|
||||
test("a subagent's report shows above the status line before the agent takes it, and the user's input below", () => {
|
||||
const steer = { id: "steer", type: "user", text: "Also check the tests", time: { created: 2 } } as const
|
||||
|
||||
const messages: SessionMessageInfo[] = [
|
||||
{ id: "user", type: "user", text: "Go", time: { created: 0 } },
|
||||
step("working", 1, {
|
||||
content: [
|
||||
{
|
||||
id: "shell",
|
||||
type: "tool",
|
||||
name: "shell",
|
||||
state: { status: "running", input: { command: "sleep 60" }, metadata: {} },
|
||||
time: { created: 1 },
|
||||
},
|
||||
],
|
||||
}),
|
||||
steer,
|
||||
subagentReport("report", 3, {
|
||||
childID: "child",
|
||||
agent: "explore",
|
||||
state: "completed",
|
||||
description: "Trace the bug",
|
||||
body: "Found it.",
|
||||
}),
|
||||
]
|
||||
|
||||
const rows = (messages: SessionMessageInfo[], pending: ReadonlySet<string>) =>
|
||||
createRoot((dispose) => {
|
||||
const projection = createNextTimelineProjection({
|
||||
sessionMessages: () => messages,
|
||||
status: () => ({ type: "busy" }),
|
||||
timelineDetail: () => detailed,
|
||||
pendingInputIDs: () => pending,
|
||||
})
|
||||
|
||||
const result = projection.rows().map((row) => {
|
||||
if (!Predicate.isTagged(row, "AssistantPart")) return row._tag
|
||||
|
||||
return row.group.type === "part"
|
||||
? row.group.ref.messageID
|
||||
: row.group.refs.map((ref) => ref.messageID).join("+")
|
||||
})
|
||||
|
||||
dispose()
|
||||
|
||||
return result
|
||||
})
|
||||
|
||||
const alone = messages.filter((message) => message !== steer)
|
||||
|
||||
expect(rows(alone, new Set(["report"]))).toEqual(["UserMessage", "working", "report"])
|
||||
expect(rows(messages, new Set(["steer", "report"]))).toEqual([
|
||||
"UserMessage",
|
||||
"working",
|
||||
"report",
|
||||
"Activity",
|
||||
"TurnGap",
|
||||
"UserMessage",
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
describe("workedDuration", () => {
|
||||
|
||||
@@ -314,18 +314,14 @@ function constructRows(input: Input) {
|
||||
}),
|
||||
]
|
||||
|
||||
// Like the TUI, a queued compaction waits after the active turn and ahead of every undelivered input:
|
||||
// steers, which own turns, and synthetic notices, which ride at the end of the active one.
|
||||
const pendingAt = rows.findIndex(
|
||||
(row) =>
|
||||
input.pendingInputIDs?.has(row.userMessageID) ||
|
||||
(Predicate.isTagged(row, "Notice") && input.pendingInputIDs?.has(row.messageID)),
|
||||
)
|
||||
// Like the TUI, a queued compaction waits after the active turn and ahead of every steer still waiting for delivery.
|
||||
// Notices waiting for delivery are already in the active turn, since they report what happened.
|
||||
const pendingAt = rows.findIndex((row) => input.pendingInputIDs?.has(row.userMessageID))
|
||||
|
||||
rows.splice(
|
||||
pendingAt < 0 ? rows.length : pendingAt,
|
||||
0,
|
||||
// Live status ends the work the model has seen, so it stays above everything still waiting for delivery.
|
||||
// Live status ends the turn, so it stays above the input the user steered in, which waits for the agent to reply.
|
||||
...(input.status.type !== "idle" && activeMessageID && (pendingAt >= 0 || input.queuedCompactionIDs.length > 0)
|
||||
? [new TimelineRow.Activity({ userMessageID: activeMessageID })]
|
||||
: []),
|
||||
@@ -380,7 +376,11 @@ function constructTurns(input: Input) {
|
||||
if (echoesUserShell(message, userShellIDs)) return
|
||||
|
||||
if (isNotice(message)) {
|
||||
if (current) current.entries.push({ type: "notice", message })
|
||||
// A notice still waiting for delivery, such as a subagent reporting back, already happened, so it joins the
|
||||
// working turn above the status line, even when input the user steered in meanwhile waits below it.
|
||||
const turn = input.pendingInputIDs?.has(message.id) ? (execution?.turn ?? current) : current
|
||||
|
||||
if (turn) turn.entries.push({ type: "notice", message })
|
||||
else leading.push(message)
|
||||
|
||||
return
|
||||
|
||||
@@ -460,6 +460,7 @@ export function createNextTimelineRowRenderer(input: {
|
||||
return (
|
||||
<SessionReadToolGroup
|
||||
tools={tools()}
|
||||
names={2}
|
||||
open={input.disclosure.value(row().group.key)}
|
||||
onOpenChange={(open) => input.disclosure.set(row().group.key, open)}
|
||||
onSizeChange={onSizeChange}
|
||||
|
||||
@@ -12,6 +12,8 @@ export function StatusLane(props: {
|
||||
collapsed?: boolean
|
||||
/** The space above the next row of the turn, so the line sits where that row will. */
|
||||
spacing?: TimelineGap
|
||||
/** The lane sits in a row of the timeline, which clips what reaches past it, rather than in its open tail. */
|
||||
inRow?: boolean
|
||||
class?: string
|
||||
children?: JSX.Element
|
||||
}) {
|
||||
@@ -21,6 +23,7 @@ export function StatusLane(props: {
|
||||
data-component="timeline-status-lane"
|
||||
data-collapsed={props.collapsed ? "" : undefined}
|
||||
data-spacing={props.spacing}
|
||||
data-in-row={props.inRow ? "" : undefined}
|
||||
class={props.class}
|
||||
>
|
||||
<Show when={props.label}>
|
||||
|
||||
@@ -581,9 +581,19 @@
|
||||
--timeline-status-space: var(--timeline-gap-l);
|
||||
}
|
||||
|
||||
/* The background hint's 24px button is centred on the 16px line and reaches 4px past it. A row clips at its own
|
||||
height, so in a row the lane keeps that room below the line, whether or not the hint shows, so the input waiting
|
||||
below does not move when it comes and goes. */
|
||||
&[data-in-row] {
|
||||
--timeline-status-hint-overflow: calc((24px - var(--line-height-compact)) / 2);
|
||||
height: calc(var(--line-height-compact) + var(--timeline-status-space) + var(--timeline-status-hint-overflow));
|
||||
padding-bottom: var(--timeline-status-hint-overflow);
|
||||
}
|
||||
|
||||
&[data-collapsed] {
|
||||
height: 0;
|
||||
padding-top: 0;
|
||||
padding-bottom: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
|
||||
@@ -285,6 +285,7 @@ function GroupItem(props: {
|
||||
<Match when={currentToolGroupedRead(tool())}>
|
||||
<CurrentReadToolGroup
|
||||
tools={props.tools}
|
||||
names={2}
|
||||
open={props.toolOpen?.(tool().id)}
|
||||
onOpenChange={(open) => props.onToolOpenChange?.(tool().id, open)}
|
||||
onSizeChange={props.onSizeChange}
|
||||
@@ -542,7 +543,7 @@ function activityLabel(group: SessionMessageAssistantTool[], i18n: UiI18n) {
|
||||
const main = {
|
||||
// A few files read better by name; past that, the count says more than a list that truncates.
|
||||
edit:
|
||||
files.length <= 3
|
||||
files.length <= 2
|
||||
? files.map((path) => getFilename(path)).join(", ")
|
||||
: i18n.plural("ui.timeline.activity.files", files.length),
|
||||
run: commands[0]!,
|
||||
|
||||
@@ -865,26 +865,48 @@ export function CurrentReadToolGroup(props: {
|
||||
open?: boolean
|
||||
onOpenChange?: (open: boolean) => void
|
||||
onSizeChange?: () => void
|
||||
/** Names each file once, and up to this many while closed; past that the closed row says how many files. */
|
||||
names?: number
|
||||
}) {
|
||||
const i18n = useI18n()
|
||||
const [state, setState] = createStore({ truncated: false })
|
||||
const disclosure = createDisclosure({ open: () => props.open, onOpenChange: (open) => props.onOpenChange?.(open) })
|
||||
const open = disclosure.open
|
||||
const expandable = () => open() || state.truncated
|
||||
|
||||
const pending = createMemo(() =>
|
||||
props.tools.some((tool) => tool.state.status === "streaming" || tool.state.status === "running"),
|
||||
)
|
||||
|
||||
const files = createMemo(() =>
|
||||
props.tools.flatMap((tool) => {
|
||||
const files = createMemo(() => {
|
||||
const reads = props.tools.flatMap((tool) => {
|
||||
const input = toolInput(currentToolInput(tool))
|
||||
const name = getFilename(input.path ?? "")
|
||||
|
||||
return name ? [{ id: tool.id, name, args: readArgs(input) }] : []
|
||||
}),
|
||||
return name ? [{ id: tool.id, path: input.path ?? "", name, args: readArgs(input) }] : []
|
||||
})
|
||||
|
||||
if (props.names === undefined) return reads
|
||||
|
||||
// A file read in several ranges is named once, without one range standing for the rest.
|
||||
return [
|
||||
...reads
|
||||
.reduce((unique, file) => {
|
||||
const seen = unique.get(file.path)
|
||||
|
||||
return unique.set(file.path, seen ? { ...seen, args: [] } : file)
|
||||
}, new Map<string, (typeof reads)[number]>())
|
||||
.values(),
|
||||
]
|
||||
})
|
||||
|
||||
const summary = createMemo(() =>
|
||||
props.names !== undefined && !open() && files().length > props.names
|
||||
? i18n.plural("ui.timeline.activity.files", files().length)
|
||||
: undefined,
|
||||
)
|
||||
|
||||
const expandable = () => open() || state.truncated || !!summary()
|
||||
|
||||
let list: HTMLSpanElement | undefined
|
||||
|
||||
const measure = () => {
|
||||
@@ -925,20 +947,27 @@ export function CurrentReadToolGroup(props: {
|
||||
<TextShimmer text={i18n.t("ui.tool.read")} active={pending()} />
|
||||
</span>
|
||||
<span ref={list} data-slot="basic-tool-tool-subtitle">
|
||||
<Index each={files()}>
|
||||
{(file, index) => (
|
||||
<>
|
||||
<Show when={index > 0}> </Show>
|
||||
<span data-slot="read-tool-group-file" data-timeline-part-id={file().id}>
|
||||
{file().name}
|
||||
<For each={file().args}>
|
||||
{(arg) => <span data-slot="basic-tool-tool-arg">{` ${arg}`}</span>}
|
||||
</For>
|
||||
<Show when={index < files().length - 1}>,</Show>
|
||||
</span>
|
||||
</>
|
||||
)}
|
||||
</Index>
|
||||
<Show
|
||||
when={summary()}
|
||||
fallback={
|
||||
<Index each={files()}>
|
||||
{(file, index) => (
|
||||
<>
|
||||
<Show when={index > 0}> </Show>
|
||||
<span data-slot="read-tool-group-file" data-timeline-part-id={file().id}>
|
||||
{file().name}
|
||||
<For each={file().args}>
|
||||
{(arg) => <span data-slot="basic-tool-tool-arg">{` ${arg}`}</span>}
|
||||
</For>
|
||||
<Show when={index < files().length - 1}>,</Show>
|
||||
</span>
|
||||
</>
|
||||
)}
|
||||
</Index>
|
||||
}
|
||||
>
|
||||
{(text) => text()}
|
||||
</Show>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user