mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-20 01:08:31 +03:00
fix(app): tidy New timeline questions, moves, compaction and shells (#63751)
This commit is contained in:
committed by
GitHub
Unverified
parent
f352f5e875
commit
191a69ad45
@@ -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 (
|
||||
<div data-component="session-compaction-message">
|
||||
<Separator label={i18n.t("ui.messagePart.compaction.queued")} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 (
|
||||
<Show
|
||||
when={!data.backgroundCompaction || props.message.reason === "manual" || props.message.status === "failed"}
|
||||
fallback={
|
||||
<QuietCompaction
|
||||
id={props.message.id}
|
||||
created={props.message.time.created}
|
||||
running={props.message.status === "running"}
|
||||
summary={summary()}
|
||||
usage={usage()}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<div data-component="session-compaction-message" class="flex flex-col gap-[var(--timeline-gap-m)]">
|
||||
<Separator label={i18n.t("ui.messagePart.compaction.started")} />
|
||||
<Show when={summary().trim()}>
|
||||
<div data-component="text-part" data-timeline-part-id={props.message.id}>
|
||||
<div data-slot="text-part-body">
|
||||
<PacedMarkdown
|
||||
text={summary()}
|
||||
cacheKey={props.message.id}
|
||||
streaming={props.message.status === "running"}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Show>
|
||||
<Show when={props.message.status === "running"}>
|
||||
<div role="status">
|
||||
<BasicTool
|
||||
icon="archive"
|
||||
trigger={{ title: i18n.t("ui.messagePart.compaction.running") }}
|
||||
status="running"
|
||||
locked
|
||||
hideDetails
|
||||
/>
|
||||
</div>
|
||||
</Show>
|
||||
<Show when={props.message.status !== "running"}>
|
||||
<Separator label={label()} />
|
||||
</Show>
|
||||
<Show when={error()}>
|
||||
<Card variant="error" class="error-card">
|
||||
<LinkedText text={error()} />
|
||||
</Card>
|
||||
</Show>
|
||||
</div>
|
||||
</Show>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 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<typeof setTimeout> | 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 (
|
||||
<div
|
||||
data-component="session-compaction-message"
|
||||
data-quiet=""
|
||||
data-enter={enter()}
|
||||
class="flex flex-col gap-[var(--timeline-gap-m)]"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
data-slot="session-compaction-divider"
|
||||
data-state={props.running ? "running" : "done"}
|
||||
class="flex h-4 w-full items-center gap-3 text-v2-text-text-faint"
|
||||
disabled={!expandable()}
|
||||
aria-busy={props.running}
|
||||
aria-expanded={expandable() ? open() : undefined}
|
||||
aria-controls={expandable() && open() ? `${props.id}-summary` : undefined}
|
||||
aria-label={props.running ? label().running : label().done}
|
||||
onClick={() => setOpen((value) => !value)}
|
||||
>
|
||||
<span data-slot="session-compaction-line" data-side="start" class="h-px min-w-0 flex-1">
|
||||
<span data-slot="session-compaction-light" />
|
||||
</span>
|
||||
<span
|
||||
data-slot="session-compaction-label"
|
||||
class="relative flex shrink-0 whitespace-nowrap text-[13px] font-[440] leading-text-compact tracking-[-0.04px]"
|
||||
>
|
||||
<span>{label().stem}</span>
|
||||
<span data-slot="session-compaction-ending" class="grid justify-items-start">
|
||||
<span data-slot="session-compaction-running">{label().ending.running}</span>
|
||||
<span data-slot="session-compaction-done">{label().ending.done}</span>
|
||||
</span>
|
||||
<span data-slot="session-compaction-glint" aria-hidden="true">
|
||||
<span data-slot="session-compaction-glint-stem">{label().stem}</span>
|
||||
<span data-slot="session-compaction-glint-ending">{label().ending.running}</span>
|
||||
</span>
|
||||
</span>
|
||||
<span data-slot="session-compaction-line" data-side="end" class="h-px min-w-0 flex-1">
|
||||
<span data-slot="session-compaction-light" />
|
||||
</span>
|
||||
</button>
|
||||
<Show when={expandable() && open()}>
|
||||
<div id={`${props.id}-summary`} data-slot="session-compaction-summary">
|
||||
<div data-component="text-part" data-timeline-part-id={props.id}>
|
||||
<div data-slot="text-part-body">
|
||||
<PacedMarkdown text={props.summary} cacheKey={props.id} streaming={false} />
|
||||
</div>
|
||||
</div>
|
||||
<Show when={props.usage}>
|
||||
<div class="mt-2 text-[13px] leading-text-compact text-v2-text-text-faint tabular-nums">{props.usage}</div>
|
||||
</Show>
|
||||
</div>
|
||||
</Show>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/** 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) } }
|
||||
}
|
||||
@@ -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", () => {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) => (
|
||||
<div data-slot="session-turn-message-container" class={`w-full ${inset()}`}>
|
||||
<div data-slot="session-turn-compaction">
|
||||
<SessionCompactionMessage message={message()} error={compactionError()} />
|
||||
<CompactionMessage message={message()} error={compactionError()} />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
@@ -925,11 +927,7 @@ export function createNextTimelineRowRenderer(input: {
|
||||
<Show when={message()}>
|
||||
{(message) => (
|
||||
<div data-slot="session-turn-message-container" class={`w-full ${padding()}`}>
|
||||
<ShellMessage
|
||||
message={message()}
|
||||
open={input.disclosure.value(message().id) ?? userShellOpens(input.timelineDetail())}
|
||||
onOpenChange={(open) => input.disclosure.set(message().id, open)}
|
||||
/>
|
||||
<ShellMessage message={message()} />
|
||||
</div>
|
||||
)}
|
||||
</Show>
|
||||
@@ -1174,7 +1172,7 @@ export function createNextTimelineRowRenderer(input: {
|
||||
<Frame row={current()}>
|
||||
<div data-slot="session-turn-message-container" class={`w-full ${padding()}`}>
|
||||
<div data-slot="session-turn-compaction">
|
||||
<SessionCompactionQueued />
|
||||
<CompactionQueued />
|
||||
</div>
|
||||
</div>
|
||||
</Frame>
|
||||
|
||||
@@ -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", () => {
|
||||
|
||||
@@ -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<string>) {
|
||||
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,
|
||||
|
||||
@@ -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. */
|
||||
|
||||
@@ -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 (
|
||||
<div
|
||||
ref={frame}
|
||||
data-component="clamped-content"
|
||||
data-clamped={props.expanded ? undefined : ""}
|
||||
data-overflow={!props.expanded && overflow() ? "" : undefined}
|
||||
>
|
||||
<div ref={content}>{props.children}</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -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) {
|
||||
</Show>
|
||||
}
|
||||
>
|
||||
<ShellOutput
|
||||
command={run.view().command}
|
||||
output={run.view().output}
|
||||
expanded={open()}
|
||||
outcome={outcome()}
|
||||
onToggle={() => {
|
||||
const next = !open()
|
||||
|
||||
setExpanded(next)
|
||||
props.onOpenChange?.(next)
|
||||
}}
|
||||
/>
|
||||
<ConsoleOutput command={run.view().command} output={run.view().output} />
|
||||
</Show>
|
||||
</div>
|
||||
)
|
||||
@@ -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 (
|
||||
<div data-component="session-shell-message" data-timeline-part-id={props.message.id}>
|
||||
<ShellCard
|
||||
@@ -209,91 +180,7 @@ export function ShellMessage(props: {
|
||||
}}
|
||||
output={props.message.output?.output}
|
||||
status={props.message.status === "running" ? "running" : "completed"}
|
||||
open={props.open}
|
||||
onOpenChange={props.onOpenChange}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// 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 (
|
||||
<div
|
||||
data-component="bash-output"
|
||||
data-variant="shell"
|
||||
data-clamp=""
|
||||
data-expanded={props.expanded ? "" : undefined}
|
||||
dir="ltr"
|
||||
>
|
||||
<div
|
||||
data-slot="bash-scroll"
|
||||
data-scrollable
|
||||
tabIndex={0}
|
||||
role="region"
|
||||
aria-label={i18n.t("ui.scrollView.ariaLabel")}
|
||||
>
|
||||
<Show when={props.command}>
|
||||
{(command) => (
|
||||
<div data-slot="bash-command">
|
||||
<Show when={props.outcome || overflow() || props.expanded}>
|
||||
<div data-slot="bash-actions">
|
||||
<Show when={props.outcome}>
|
||||
{(outcome) => (
|
||||
<span data-slot="bash-outcome" data-tone={outcome().tone}>
|
||||
{outcome().label}
|
||||
</span>
|
||||
)}
|
||||
</Show>
|
||||
<Show when={overflow() || props.expanded}>
|
||||
<div data-slot="bash-toggle">
|
||||
<Tooltip value={toggleLabel()} placement="top">
|
||||
<button
|
||||
type="button"
|
||||
data-slot="bash-toggle-button"
|
||||
aria-label={toggleLabel()}
|
||||
aria-expanded={props.expanded}
|
||||
onClick={() => props.onToggle()}
|
||||
>
|
||||
<Icon name="chevron-grabber-vertical" size="small" />
|
||||
</button>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</Show>
|
||||
</div>
|
||||
</Show>
|
||||
<pre data-slot="bash-pre">
|
||||
<code>{command()}</code>
|
||||
</pre>
|
||||
</div>
|
||||
)}
|
||||
</Show>
|
||||
<Show when={props.output}>
|
||||
{(output) => (
|
||||
<div data-slot="bash-result">
|
||||
<ConsoleCopy text={output()} label={i18n.t("ui.message.copyOutput")} />
|
||||
<ClampedContent expanded={props.expanded} onOverflowChange={setOverflow}>
|
||||
<pre data-slot="bash-pre">
|
||||
<code>
|
||||
<LinkedText text={output()} />
|
||||
</code>
|
||||
</pre>
|
||||
</ClampedContent>
|
||||
</div>
|
||||
)}
|
||||
</Show>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user