diff --git a/packages/session-ui/component-tests/session-tool-projection.spec.ts b/packages/session-ui/component-tests/session-tool-projection.spec.ts index a090e919d8d..4b39b88892d 100644 --- a/packages/session-ui/component-tests/session-tool-projection.spec.ts +++ b/packages/session-ui/component-tests/session-tool-projection.spec.ts @@ -47,22 +47,22 @@ story("renders every tool error outcome without leaking hidden tools", async ({ for (const name of names) await expect(timeline.locator(`[data-timeline-part-id="tool_error_${name}"]`)).toBeVisible() }) -story("keeps a failed execute inline with its neighbours' calls", async ({ mount }) => { +story("lists a failed execute's calls and keeps its error under the failed call", async ({ mount }) => { const timeline = await mount("current-session-terminal-work--execute-failed") - // Adjacent executions merge into one list, so each merged run counts once. - await timeline.getByRole("button", { name: /^Used 3 / }).click() - const merged = timeline.locator('[data-timeline-part-ids="tool_execute_search,tool_execute_failed_url"]') - const call = merged.locator('[data-slot="execute-tool-call"]') + await timeline.getByRole("button", { name: /^Used 5 / }).click() + const failed = timeline.locator('[data-timeline-part-id="tool_execute_failed_url"]') + const call = failed.locator('[data-slot="execute-tool-call"]') + // Executions open by default, so the calls show without expanding the row. await expect(call).toHaveText([/browser\.tabs\.open/]) await expect(call).toHaveAttribute("data-status", "error") await expect(timeline.locator('[data-kind="tool-error-card"]')).toHaveCount(0) // The runtime error stays collapsed under the failed call until it is expanded. - const error = merged.locator('[data-slot="execute-tool-error"]') + const error = failed.locator('[data-slot="execute-tool-error"]') await expect(error).toHaveCount(0) await call.click() await expect(call).toHaveAttribute("aria-expanded", "true") - await expect(merged.locator('[data-slot="execute-tool-call-input"]')).toContainText( + await expect(failed.locator('[data-slot="execute-tool-call-input"]')).toContainText( "url:file:///C:/tmp/opencode/throne-of-glass-luke.html", ) await expect(error).toContainText( diff --git a/packages/session-ui/src/message/current-message.tsx b/packages/session-ui/src/message/current-message.tsx index 182f0d9cce4..8605f86b52c 100644 --- a/packages/session-ui/src/message/current-message.tsx +++ b/packages/session-ui/src/message/current-message.tsx @@ -4,7 +4,6 @@ import type { SessionUserActions, SessionUserAttachmentReference, SessionUserCom import { AssistantReasoningContent, AssistantTextContent, CurrentUserMessageDisplay } from "./message-content" import { CurrentContextToolGroup, - CurrentExecuteToolGroup, CurrentFileToolGroup, CurrentReadToolGroup, ToolDisplay, @@ -108,10 +107,6 @@ export function SessionContextToolGroup(props: ComponentProps } -export function SessionExecuteToolGroup(props: ComponentProps) { - return -} - export function SessionReadToolGroup(props: ComponentProps) { return } diff --git a/packages/session-ui/src/timeline/projection.ts b/packages/session-ui/src/timeline/projection.ts index a5ab1aba640..03dffd59235 100644 --- a/packages/session-ui/src/timeline/projection.ts +++ b/packages/session-ui/src/timeline/projection.ts @@ -856,7 +856,7 @@ function groupContent( detail?: TimelineDetail, ): PartGroup[] { const groups: PartGroup[] = [] - let adjacent: { type: "context" | "file" | "read" | "execute"; refs: PartRef[]; tools: boolean } | undefined + let adjacent: { type: "context" | "file" | "read"; refs: PartRef[]; tools: boolean } | undefined const flush = () => { const current = adjacent @@ -864,8 +864,7 @@ function groupContent( if (!first) return - // A lone execution keeps its part row so a following one merges into the same group key. - if ((!current.tools && !detail) || (current.type === "execute" && current.refs.length === 1)) { + if (!current.tools && !detail) { groups.push( ...current.refs.map((ref) => ({ type: "part" as const, key: `part:${ref.messageID}:${ref.partID}`, ref })), ) @@ -935,20 +934,6 @@ function toolGroupType( editExpanded: boolean, hasContextGroup: boolean, detail?: TimelineDetail, -) { - const type = separateToolGroupType(content, shellExpanded, editExpanded, hasContextGroup, detail) - - if (type || content.name !== "execute") return type - - return "execute" -} - -function separateToolGroupType( - content: Extract, - shellExpanded: boolean, - editExpanded: boolean, - hasContextGroup: boolean, - detail?: TimelineDetail, ) { if (detail) { if (content.name === "question" && !currentToolFailed(content)) return undefined diff --git a/packages/session-ui/src/timeline/rows-current.test.ts b/packages/session-ui/src/timeline/rows-current.test.ts index 163b9f06a37..6ebf476d901 100644 --- a/packages/session-ui/src/timeline/rows-current.test.ts +++ b/packages/session-ui/src/timeline/rows-current.test.ts @@ -1176,43 +1176,6 @@ describe("current session timeline rows", () => { ]) }) - test("merges consecutive executions, including failures, into one group keyed by the first", () => { - const groups = (detail?: (typeof timelinePresets)[number]["value"]) => - Timeline.constructSessionMessageRows( - storyDocument([ - storyTool("first", "execute", "completed", {}), - storyTool("second", "execute", "completed", {}), - storyTool("failed", "execute", "completed", {}, { metadata: { error: true } }), - storyTool("third", "execute", "running", {}), - { type: "text", text: "Boundary" }, - storyTool("alone", "execute", "completed", {}), - ]).messages, - false, - { type: "busy" }, - undefined, - true, - false, - undefined, - detail, - ).rows.flatMap((row) => - Predicate.isTagged(row, "AssistantPart") - ? [ - [ - row.group.type, - ...(row.group.type === "part" ? [row.group.ref] : row.group.refs).map((ref) => ref.partID), - ], - ] - : [], - ) - - expect(groups()).toEqual([ - ["execute", "first", "second", "failed", "third"], - ["part", expect.stringContaining("text")], - ["part", "alone"], - ]) - expect(groups(timelinePresets[0]!.value)).toEqual(groups()) - }) - test("keeps active and background work standalone when no group precedes them", () => { const source: SessionMessageInfo[] = [ { id: "msg_user", type: "user", text: "work", time: { created: 1 } }, diff --git a/packages/session-ui/src/timeline/session-timeline-row.tsx b/packages/session-ui/src/timeline/session-timeline-row.tsx index 8f170deb016..27a0f815d3f 100644 --- a/packages/session-ui/src/timeline/session-timeline-row.tsx +++ b/packages/session-ui/src/timeline/session-timeline-row.tsx @@ -15,7 +15,6 @@ import { TimelineSeparator } from "../components/timeline-separator" import { SessionAssistantContent, SessionContextToolGroup, - SessionExecuteToolGroup, SessionFileToolGroup, SessionReadToolGroup, SessionShellMessage, @@ -244,7 +243,7 @@ export function createSessionTimelineRowRenderer(input: { } reasoningOpen={(id) => input.disclosure.value(id)} onReasoningOpenChange={(id, open) => input.disclosure.set(id, open)} - toolDefaultOpen={(tool) => (input.timelineDetail ? contentDefaultOpen(tool) : false)} + toolDefaultOpen={(tool) => (input.timelineDetail || tool.name === "execute" ? contentDefaultOpen(tool) : false)} toolOpen={(id) => input.disclosure.value(`${row().group.key}:tool:${id}`)} onToolOpenChange={(id, open) => input.disclosure.set(`${row().group.key}:tool:${id}`, open)} fileOpen={(path) => @@ -287,37 +286,6 @@ export function createSessionTimelineRowRenderer(input: { ) } - if (row().group.type === "execute") { - const tools = createMemo(() => { - const group = row().group - - if (group.type !== "execute") return [] - const contents = indexGroupContents(group.refs) - - return group.refs.flatMap((ref) => { - const content = contents.get(ref.messageID)?.get(ref.partID) - - return content?.type === "tool" ? [content] : [] - }) - }) - - const defaultOpen = createMemo(() => { - const tool = tools()[0] - - return tool ? contentDefaultOpen(tool) : undefined - }) - - return ( - input.disclosure.set(row().group.key, open)} - onSizeChange={onSizeChange} - /> - ) - } - if (row().group.type === "file") { const tools = createMemo(() => { const group = row().group @@ -414,6 +382,8 @@ export function createSessionTimelineRowRenderer(input: { } function contentDefaultOpen(item: SessionMessageAssistant["content"][number]) { + if (item.type === "tool" && item.name === "execute") return true + if (input.timelineDetail) { const category = timelineCategory(item) diff --git a/packages/session-ui/src/timeline/terminal-work.stories.tsx b/packages/session-ui/src/timeline/terminal-work.stories.tsx index 477fb9cb8f2..a67fdeb4dcd 100644 --- a/packages/session-ui/src/timeline/terminal-work.stories.tsx +++ b/packages/session-ui/src/timeline/terminal-work.stories.tsx @@ -184,7 +184,7 @@ export const ExecuteCode = { render: () => ( ( diff --git a/packages/session-ui/src/timeline/timeline-row.ts b/packages/session-ui/src/timeline/timeline-row.ts index 424739121e2..8d81e4db7d7 100644 --- a/packages/session-ui/src/timeline/timeline-row.ts +++ b/packages/session-ui/src/timeline/timeline-row.ts @@ -18,7 +18,7 @@ export type PartGroup = } | { key: string - type: "file" | "read" | "execute" + type: "file" | "read" refs: PartRef[] } diff --git a/packages/session-ui/src/tools/tool-renderer.tsx b/packages/session-ui/src/tools/tool-renderer.tsx index 949ed89655e..aae82a7848e 100644 --- a/packages/session-ui/src/tools/tool-renderer.tsx +++ b/packages/session-ui/src/tools/tool-renderer.tsx @@ -25,7 +25,7 @@ import { Dynamic } from "solid-js/web" import { type SessionSummary, useData } from "../context" import { useFileComponent } from "@opencode/ui/context/file" import { type UiI18n, useI18n } from "@opencode/ui/context/i18n" -import { BasicTool, GenericTool, type BasicToolProps } from "../components/basic-tool" +import { BasicTool, GenericTool } from "../components/basic-tool" import { FileIcon } from "@opencode/ui/file-icon" import { Icon } from "@opencode/ui/icon" import { ToolErrorCard } from "../components/tool-error-card" @@ -504,15 +504,7 @@ export function CurrentContextToolGroup(props: { } const title = names() || i18n.plural("ui.messagePart.context.thought", thoughts) - - // Adjacent executions render as one merged list, so they count once. - const count = - props.parts.filter( - (part, index) => - (part.type === "tool" || part.type === "shell") && - !(part.type === "tool" && part.name === "execute" && isExecute(props.parts[index - 1])), - ).length || thoughts - + const count = props.parts.filter((part) => part.type === "tool" || part.type === "shell").length || thoughts const text = i18n.plural("ui.messagePart.tools.used", count, { tools: title }) const index = text.indexOf(title) const before = text.slice(0, index).trim() @@ -561,12 +553,6 @@ export function CurrentContextToolGroup(props: { return groups } - if (tool.name === "execute" && Array.isArray(previous) && previous[0] && previous[0].name === "execute") { - previous.push(tool) - - return groups - } - if ( tool.name === "skill" && tool.state.status !== "error" && @@ -719,142 +705,129 @@ export function CurrentContextToolGroup(props: { return (
props.onToolOpenChange?.(tool().id, open)} onSizeChange={props.onSizeChange} /> } > props.onToolOpenChange?.(tool().id, open)} - onSizeChange={props.onSizeChange} - /> + 1 && skills().length === group().length + } + fallback={ + props.onToolOpenChange?.(tool().id, open)} + deferContent + virtualizeDiff={false} + onContentRendered={props.onSizeChange} + /> + } + > + props.fileOpen?.(`${patchKeys().get(tool())}:${path}`)) + } + onFileOpenChange={ + props.onFileOpenChange && + ((path, open) => + props.onFileOpenChange?.(`${patchKeys().get(tool())}:${path}`, open)) + } + onSizeChange={props.onSizeChange} + /> + + } + > +
item.id) + .join(",")} + aria-label={i18n.plural("ui.tool.loadedSkills", skills().length, { + name: skills().join(", "), + })} + > + + + + {(suffix) => ( + + )} + +
+
} > - 1 && skills().length === group().length - } - fallback={ - props.onToolOpenChange?.(tool().id, open)} - deferContent - virtualizeDiff={false} - onContentRendered={props.onSizeChange} +
+
+
+
+
+ + - } - > - props.fileOpen?.(`${patchKeys().get(tool())}:${path}`)) - } - onFileOpenChange={ - props.onFileOpenChange && - ((path, open) => - props.onFileOpenChange?.(`${patchKeys().get(tool())}:${path}`, open)) - } - onSizeChange={props.onSizeChange} - /> - - } - > -
item.id) - .join(",")} - aria-label={i18n.plural("ui.tool.loadedSkills", skills().length, { - name: skills().join(", "), - })} - > - - + + {(subtitle) => {subtitle()}} + + + {(arg) => {arg}} - - - {(suffix) => ( - +
+ + {(matches) => ( + <> + + {matches()} + )}
- - } - > -
-
-
-
-
- - - - - {(subtitle) => {subtitle()}} - - - {(arg) => {arg}} - -
- - {(matches) => ( - <> - - {matches()} - - )} - -
-
- +
@@ -870,10 +843,6 @@ export function CurrentContextToolGroup(props: { ) } -function isExecute(part: ContextGroupPart | undefined) { - return part?.type === "tool" && part.name === "execute" -} - export function CurrentReadToolGroup(props: { tools: SessionMessageAssistantTool[] open?: boolean @@ -1947,120 +1916,54 @@ ToolRegistry.register({ name: "execute", render(props) { const i18n = useI18n() + const pending = () => props.status === "streaming" || props.status === "running" + const calls = createMemo(() => executeToolCalls(props.metadata)) + const subtitle = createMemo(() => executeToolSubtitle(calls())) - return + // Like the TUI, only a runtime failure shows its output; a failed nested call is marked on its row. + const error = createMemo(() => { + if (props.status !== "error" && props.metadata.error !== true) return undefined + const fallback = i18n.t("ui.toolErrorCard.failed") + const text = stripAnsi((props.status === "error" ? props.error : undefined) || props.output || fallback) + + return text.replace(/^Error:\s*/, "").trim() || fallback + }) + + // A runtime failure belongs to the call that raised it; scripts can also fail outside any call. + const owner = createMemo(() => calls().findLastIndex((call) => call.status === "error")) + + const sawPending = pending() + + return ( + 0 || !!error()} + compact + allowOpenWhilePending + trigger={(open) => ( +
+
+ + + + {(text) => } +
+
+ )} + > +
+ + {(call, index) => } + + {(text) => } +
+
+ ) }, }) -// Consecutive Code Mode executions read as one list of the tools their scripts called. -export function CurrentExecuteToolGroup(props: { - tools: SessionMessageAssistantTool[] - defaultOpen?: boolean - open?: boolean - onOpenChange?: (open: boolean) => void - onSizeChange?: () => void -}) { - const i18n = useI18n() - - const status = createMemo( - () => - props.tools.find((tool) => tool.state.status === "streaming" || tool.state.status === "running")?.state.status ?? - "completed", - ) - - return ( -
1 ? props.tools.map((tool) => tool.id).join(",") : undefined} - > - - executeRun( - { - status: tool.state.status, - metadata: currentToolMetadata(tool), - output: currentToolOutput(tool), - error: currentToolError(tool), - }, - i18n.t("ui.toolErrorCard.failed"), - ), - )} - status={status()} - defaultOpen={props.defaultOpen} - open={props.open} - onOpenChange={(open) => { - props.onOpenChange?.(open) - props.onSizeChange?.() - }} - /> -
- ) -} - -type ExecuteRun = { calls: ExecuteToolCall[]; error?: string } - -// Like the TUI, only a runtime failure shows its output; a failed nested call is marked on its row. -function executeRun( - props: { status?: string; metadata: Record; output?: string; error?: string }, - fallback: string, -): ExecuteRun { - const calls = executeToolCalls(props.metadata) - - if (props.status !== "error" && props.metadata.error !== true) return { calls } - const error = stripAnsi((props.status === "error" ? props.error : undefined) || props.output || fallback) - - return { calls, error: error.replace(/^Error:\s*/, "").trim() || fallback } -} - -function ExecuteTool(props: Omit & { runs: ExecuteRun[] }) { - const i18n = useI18n() - const pending = () => props.status === "streaming" || props.status === "running" - const calls = createMemo(() => props.runs.flatMap((run) => run.calls)) - const subtitle = createMemo(() => executeToolSubtitle(calls())) - - const sawPending = pending() - - return ( - run.calls.length > 0 || run.error)} - compact - allowOpenWhilePending - trigger={(open) => ( -
-
- - - - {(text) => } -
-
- )} - > -
- - {(run) => { - // A runtime failure belongs to the call that raised it; scripts can also fail outside any call. - const owner = createMemo(() => run().calls.findLastIndex((call) => call.status === "error")) - - return ( - <> - - {(call, index) => } - - {(error) => } - - ) - }} - -
-
- ) -} - function ExecuteCallRow(props: { call?: ExecuteToolCall; error?: string }) { const [open, setOpen] = createSignal(false) const args = createMemo(() => (props.call ? executeToolCallArgs(props.call) : []))