GeezerVison is showing github.com — feat(app): render current session timeline · anomalyco/opencode@ae72b55
File treeExpand file treeCollapse file tree Open diff view settings src/pages/session/timeline
session-ui/src/components
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/app/e2e/performance/timeline/session-parent-hydration-benchmark.spec.ts +27-6Lines changed: 27 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -41,7 +41,12 @@ const assistants = Array.from({ length: 14 }, (_, index) => { | 41 | 41 | const messages = [user, ...assistants] | 42 | 42 | const target = fixture.sessions.find((session) => session.id === fixture.targetID)! | 43 | 43 | const lastID = userID | 44 | | -const lastPartID = assistants.at(-1)!.parts.at(-1)!.id | | 44 | +const lastAssistant = assistants.at(-1)! | | 45 | +const lastPart = lastAssistant.parts.at(-1)! | | 46 | +const lastPartID = | | 47 | + lastPart.type === "tool" | | 48 | + ? lastPart.id | | 49 | + : `${lastAssistant.info.id}:${lastPart.type}:${lastAssistant.parts.filter((part) => part.type === lastPart.type).length - 1}` | 45 | 50 |
| 46 | 51 | benchmark("hydrates an orphaned latest turn after a cold session click", async ({ browser, report }, testInfo) => { | 47 | 52 | benchmark.setTimeout(180_000) | @@ -107,9 +112,25 @@ async function trial(page: Page, mode: ParentHydrationBenchmarkMode) { | 107 | 112 | return { items: items.slice(start, end), cursor: start > 0 ? items[start]!.info.id : undefined } | 108 | 113 | }, | 109 | 114 | }) | 110 | | - await page.route(`**/session/${fixture.targetID}`, (route) => | 111 | | - route.fulfill({ status: 200, contentType: "application/json", body: JSON.stringify(target) }), | 112 | | - ) | | 115 | + await page.route(`**/session/${fixture.targetID}`, (route) => { | | 116 | + const current = new URL(route.request().url()).pathname.startsWith("/api/") | | 117 | + return route.fulfill({ | | 118 | + status: 200, | | 119 | + contentType: "application/json", | | 120 | + body: JSON.stringify( | | 121 | + current | | 122 | + ? { | | 123 | + data: { | | 124 | + ...target, | | 125 | + cost: 0, | | 126 | + tokens: { input: 0, output: 0, reasoning: 0, cache: { read: 0, write: 0 } }, | | 127 | + location: { directory: target.directory }, | | 128 | + }, | | 129 | + } | | 130 | + : target, | | 131 | + ), | | 132 | + }) | | 133 | + }) | 113 | 134 | await installStressSessionTabs(page, { sessionIDs: [fixture.sourceID] }) | 114 | 135 | await page.goto(stressSessionHref(fixture.sourceID)) | 115 | 136 | await expectSessionTitle(page, fixture.expected.sourceTitle) | @@ -144,8 +165,8 @@ async function trial(page: Page, mode: ParentHydrationBenchmarkMode) { | 144 | 165 | parent: requests.filter((request) => request.type === "parent").length, | 145 | 166 | } | 146 | 167 | if (mode === "candidate") { | 147 | | - expect(requestCounts.parent).toBe(1) | 148 | | - expect(historyGates).toBe(1) | | 168 | + expect(requestCounts.parent).toBe(0) | | 169 | + expect(historyGates).toBe(0) | 149 | 170 | } | 150 | 171 | return { metrics, requestCounts, historyGateCount: historyGates } | 151 | 172 | } |
Collapse file Copy file name to clipboardExpand all lines: packages/app/src/pages/session/timeline/message-timeline.tsx +13-6Lines changed: 13 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -283,6 +283,14 @@ export function MessageTimeline(props: { | 283 | 283 | return sync().data.session_status[id] ?? idle | 284 | 284 | }) | 285 | 285 | const sessionMessages = createMemo(() => (sessionID() ? (sync().data.message[sessionID()!] ?? []) : [])) | | 286 | + const projectedMessages = createMemo(() => { | | 287 | + const id = sessionID() | | 288 | + if (!id) return [] | | 289 | + const visible = new Set(props.userMessages.map((message) => message.id)) | | 290 | + const boundary = sessionMessages().find((message) => message.role === "user" && !visible.has(message.id))?.id | | 291 | + const messages = sync().data.session_message[id] ?? [] | | 292 | + return boundary ? messages.filter((message) => message.id < boundary) : messages | | 293 | + }) | 286 | 294 | const info = createMemo(() => { | 287 | 295 | const id = sessionID() | 288 | 296 | if (!id) return | @@ -324,7 +332,7 @@ export function MessageTimeline(props: { | 324 | 332 | const showHeader = createMemo(() => !!(titleValue() || parentID())) | 325 | 333 | const projection = createTimelineProjection({ | 326 | 334 | messages: sessionMessages, | 327 | | - userMessages: () => props.userMessages, | | 335 | + sessionMessages: projectedMessages, | 328 | 336 | parts: getMsgParts, | 329 | 337 | status: sessionStatus, | 330 | 338 | showReasoningSummaries: settings.general.showReasoningSummaries, | @@ -664,8 +672,7 @@ export function MessageTimeline(props: { | 664 | 672 | })) | 665 | 673 |
| 666 | 674 | const titleMutation = useMutation(() => ({ | 667 | | - mutationFn: (input: { id: string; title: string }) => | 668 | | - sdk().client.session.update({ sessionID: input.id, title: input.title }), | | 675 | + mutationFn: (input: { id: string; title: string }) => sdk().api.session.rename({ sessionID: input.id, title: input.title }), | 669 | 676 | onSuccess: (_, input) => { | 670 | 677 | sync().set( | 671 | 678 | produce((draft) => { | @@ -809,7 +816,7 @@ export function MessageTimeline(props: { | 809 | 816 | const nextSession = index === -1 ? undefined : (sessions[index + 1] ?? sessions[index - 1]) | 810 | 817 |
| 811 | 818 | await sdk() | 812 | | - .client.session.update({ sessionID, time: { archived: Date.now() } }) | | 819 | + .api.session.archive({ sessionID }) | 813 | 820 | .then(() => { | 814 | 821 | sync().set( | 815 | 822 | produce((draft) => { | @@ -838,8 +845,8 @@ export function MessageTimeline(props: { | 838 | 845 | const nextSession = index === -1 ? undefined : (sessions[index + 1] ?? sessions[index - 1]) | 839 | 846 |
| 840 | 847 | const result = await sdk() | 841 | | - .client.session.delete({ sessionID }) | 842 | | - .then((x) => x.data) | | 848 | + .api.session.remove({ sessionID }) | | 849 | + .then(() => true) | 843 | 850 | .catch((err) => { | 844 | 851 | showToast({ | 845 | 852 | title: language.t("session.delete.failed.title"), | |
Collapse file Copy file name to clipboardExpand all lines: packages/app/src/pages/session/timeline/projection.ts +13-43Lines changed: 13 additions & 43 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -import { Binary } from "@opencode-ai/core/util/binary" | | 1 | +import type { SessionMessageInfo } from "@opencode-ai/client/promise" | 2 | 2 | import type { AssistantMessage, Message, Part, SessionStatus, UserMessage } from "@opencode-ai/sdk/v2" | 3 | | -import { createMemo, mapArray, type Accessor } from "solid-js" | | 3 | +import { createMemo, type Accessor } from "solid-js" | 4 | 4 | import { reuseTimelineRows } from "./row-reconciliation" | 5 | 5 | import { Timeline, TimelineRow } from "./rows" | 6 | 6 |
| 7 | 7 | export { reuseTimelineRows } from "./row-reconciliation" | 8 | 8 |
| 9 | | -const emptyAssistantMessages: AssistantMessage[] = [] | 10 | | - | 11 | 9 | export function createTimelineProjection(input: { | 12 | 10 | messages: Accessor<Message[]> | 13 | | - userMessages: Accessor<UserMessage[]> | | 11 | + sessionMessages: Accessor<SessionMessageInfo[]> | 14 | 12 | parts: (messageID: string) => Part[] | 15 | 13 | status: Accessor<SessionStatus> | 16 | 14 | showReasoningSummaries: Accessor<boolean> | @@ -30,47 +28,19 @@ export function createTimelineProjection(input: { | 30 | 28 | }) | 31 | 29 | return result | 32 | 30 | }) | 33 | | - const activeMessageID = createMemo(() => { | 34 | | - const parentID = input | 35 | | - .messages() | 36 | | - .findLast( | 37 | | - (message): message is AssistantMessage => | 38 | | - message.role === "assistant" && typeof message.time.completed !== "number", | 39 | | - )?.parentID | 40 | | - if (parentID) { | 41 | | - const messages = input.messages() | 42 | | - const result = Binary.search(messages, parentID, (message) => message.id) | 43 | | - const message = result.found ? messages[result.index] : messages.find((item) => item.id === parentID) | 44 | | - if (message?.role === "user") return message.id | 45 | | - } | 46 | | - | 47 | | - if (input.status().type === "idle") return | 48 | | - return input.messages().findLast((message) => message.role === "user")?.id | 49 | | - }) | 50 | | - const messageRowMemos = createMemo( | 51 | | - mapArray(input.userMessages, (userMessage, indexAccessor) => | 52 | | - createMemo((previous: TimelineRow.TimelineRow[] | undefined) => | 53 | | - reuseTimelineRows( | 54 | | - previous, | 55 | | - Timeline.constructMessageRows( | 56 | | - userMessage, | 57 | | - input.parts, | 58 | | - assistantMessagesByParent().get(userMessage.id) ?? emptyAssistantMessages, | 59 | | - indexAccessor(), | 60 | | - input.showReasoningSummaries(), | 61 | | - input.status().type, | 62 | | - activeMessageID() === userMessage.id, | 63 | | - input.inlineComments(), | 64 | | - ), | 65 | | - ), | 66 | | - ), | | 31 | + const projection = createMemo(() => | | 32 | + Timeline.constructSessionMessageRows( | | 33 | + input.sessionMessages(), | | 34 | + (messageID) => messageByID().get(messageID) as UserMessage | AssistantMessage | undefined, | | 35 | + input.parts, | | 36 | + input.showReasoningSummaries(), | | 37 | + input.status().type, | | 38 | + input.inlineComments(), | 67 | 39 | ), | 68 | 40 | ) | | 41 | + const activeMessageID = createMemo(() => projection().activeMessageID) | 69 | 42 | const rows = createMemo((previous: TimelineRow.TimelineRow[] | undefined) => | 70 | | - reuseTimelineRows( | 71 | | - previous, | 72 | | - messageRowMemos().flatMap((memo) => memo()), | 73 | | - ), | | 43 | + reuseTimelineRows(previous, projection().rows), | 74 | 44 | ) | 75 | 45 | const rowByKey = createMemo(() => new Map(rows().map((row) => [TimelineRow.key(row), row] as const))) | 76 | 46 | const messageRowIndex = createMemo(() => { | |
Collapse file Copy file name to clipboard +92Lines changed: 92 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import { describe, expect, mock, test } from "bun:test" | | 2 | +import type { SessionMessageInfo } from "@opencode-ai/client/promise" | | 3 | +import { normalizeSessionMessages } from "@/utils/session-message" | | 4 | + | | 5 | +mock.module("@opencode-ai/session-ui/message-part", () => ({ | | 6 | + renderable: () => true, | | 7 | + groupParts: (refs: Array<{ messageID: string; part: { id: string } }>) => | | 8 | + refs.map((ref) => ({ | | 9 | + type: "part" as const, | | 10 | + key: ref.part.id, | | 11 | + ref: { messageID: ref.messageID, partID: ref.part.id }, | | 12 | + })), | | 13 | +})) | | 14 | + | | 15 | +const { Timeline, TimelineRow } = await import("./rows") | | 16 | + | | 17 | +describe("current session timeline rows", () => { | | 18 | + test("derives turns and tagged rows from chronological current messages", () => { | | 19 | + const source = [ | | 20 | + { id: "msg_1", type: "user", text: "first", time: { created: 1 } }, | | 21 | + { | | 22 | + id: "msg_2", | | 23 | + type: "assistant", | | 24 | + agent: "build", | | 25 | + model: { id: "model", providerID: "provider" }, | | 26 | + content: [{ type: "text", text: "answer" }], | | 27 | + time: { created: 2, completed: 3 }, | | 28 | + }, | | 29 | + { id: "msg_3", type: "user", text: "second", time: { created: 4 } }, | | 30 | + { | | 31 | + id: "msg_4", | | 32 | + type: "assistant", | | 33 | + agent: "build", | | 34 | + model: { id: "model", providerID: "provider" }, | | 35 | + content: [{ type: "reasoning", text: "working" }], | | 36 | + time: { created: 5 }, | | 37 | + }, | | 38 | + ] satisfies SessionMessageInfo[] | | 39 | + const normalized = normalizeSessionMessages("ses_1", source) | | 40 | + const messages = new Map(normalized.messages.map((message) => [message.id, message])) | | 41 | + | | 42 | + const result = Timeline.constructSessionMessageRows( | | 43 | + source, | | 44 | + (messageID) => messages.get(messageID), | | 45 | + (messageID) => normalized.parts.get(messageID) ?? [], | | 46 | + true, | | 47 | + "busy", | | 48 | + true, | | 49 | + ) | | 50 | + | | 51 | + expect(result.activeMessageID).toBe("msg_3") | | 52 | + expect(result.rows.map(TimelineRow.key)).toEqual([ | | 53 | + "user-message:msg_1", | | 54 | + "assistant-part:msg_1:msg_2:text:0", | | 55 | + "turn-gap:msg_3", | | 56 | + "user-message:msg_3", | | 57 | + "assistant-part:msg_3:msg_4:reasoning:0", | | 58 | + ]) | | 59 | + }) | | 60 | + | | 61 | + test("renders a current shell message as a standalone turn", () => { | | 62 | + const source = [ | | 63 | + { | | 64 | + id: "msg_shell", | | 65 | + type: "shell", | | 66 | + shellID: "shell_1", | | 67 | + command: "pwd", | | 68 | + status: "exited", | | 69 | + exit: 0, | | 70 | + output: { output: "/repo", cursor: 5, size: 5, truncated: false }, | | 71 | + time: { created: 1, completed: 2 }, | | 72 | + }, | | 73 | + ] satisfies SessionMessageInfo[] | | 74 | + const normalized = normalizeSessionMessages("ses_1", source) | | 75 | + const messages = new Map(normalized.messages.map((message) => [message.id, message])) | | 76 | + | | 77 | + const result = Timeline.constructSessionMessageRows( | | 78 | + source, | | 79 | + (messageID) => messages.get(messageID), | | 80 | + (messageID) => normalized.parts.get(messageID) ?? [], | | 81 | + true, | | 82 | + "idle", | | 83 | + true, | | 84 | + ) | | 85 | + | | 86 | + expect(result.activeMessageID).toBe("msg_shell") | | 87 | + expect(result.rows.map(TimelineRow.key)).toEqual([ | | 88 | + "user-message:msg_shell", | | 89 | + "assistant-part:msg_shell:msg_shell:tool", | | 90 | + ]) | | 91 | + }) | | 92 | +}) |
Collapse file Copy file name to clipboardExpand all lines: packages/app/src/pages/session/timeline/rows.ts +42Lines changed: 42 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import { parseCommentNote, readCommentMetadata } from "@/utils/comment-note" | | 2 | +import type { SessionMessageInfo } from "@opencode-ai/client/promise" | 2 | 3 | import { AssistantMessage, Part, SessionStatus, UserMessage } from "@opencode-ai/sdk/v2" | 3 | 4 | import { groupParts, renderable, type PartGroup } from "@opencode-ai/session-ui/message-part" | 4 | 5 | import { TimelineRow, type SummaryDiff } from "./timeline-row" | @@ -31,6 +32,47 @@ export type TimelineRowMap = { | 31 | 32 | } | 32 | 33 |
| 33 | 34 | export namespace Timeline { | | 35 | + export function constructSessionMessageRows( | | 36 | + messages: SessionMessageInfo[], | | 37 | + getMessage: (messageID: string) => UserMessage | AssistantMessage | undefined, | | 38 | + getMessageParts: (messageID: string) => Part[], | | 39 | + showReasoning: boolean, | | 40 | + status: SessionStatus["type"], | | 41 | + inlineComments: boolean, | | 42 | + ) { | | 43 | + const turns = messages.reduce<{ user: UserMessage; assistants: AssistantMessage[] }[]>((result, message) => { | | 44 | + const projected = getMessage(message.id) | | 45 | + if (message.type === "shell" && projected?.role === "user") { | | 46 | + const assistant = getMessage(`${message.id}:assistant`) | | 47 | + result.push({ user: projected, assistants: assistant?.role === "assistant" ? [assistant] : [] }) | | 48 | + return result | | 49 | + } | | 50 | + if (projected?.role === "user") { | | 51 | + result.push({ user: projected, assistants: [] }) | | 52 | + return result | | 53 | + } | | 54 | + if (projected?.role !== "assistant") return result | | 55 | + result.at(-1)?.assistants.push(projected) | | 56 | + return result | | 57 | + }, []) | | 58 | + const activeMessageID = turns.at(-1)?.user.id | | 59 | + return { | | 60 | + activeMessageID, | | 61 | + rows: turns.flatMap((turn, index) => | | 62 | + constructMessageRows( | | 63 | + turn.user, | | 64 | + getMessageParts, | | 65 | + turn.assistants, | | 66 | + index, | | 67 | + showReasoning, | | 68 | + status, | | 69 | + turn.user.id === activeMessageID, | | 70 | + inlineComments, | | 71 | + ), | | 72 | + ), | | 73 | + } | | 74 | + } | | 75 | + | 34 | 76 | export function constructMessageRows( | 35 | 77 | userMessage: UserMessage, | 36 | 78 | getMessageParts: (messageID: string) => Part[], | |
Collapse file Copy file name to clipboardExpand all lines: packages/session-ui/src/components/message-part.tsx +7-5Lines changed: 7 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -521,6 +521,7 @@ export function getToolInfo( | 521 | 521 | } | 522 | 522 | } | 523 | 523 | case "bash": | | 524 | + case "shell": | 524 | 525 | return { | 525 | 526 | icon: "console", | 526 | 527 | title: i18n.t("ui.tool.shell"), | @@ -538,6 +539,7 @@ export function getToolInfo( | 538 | 539 | title: i18n.t("ui.messagePart.title.write"), | 539 | 540 | subtitle: input.filePath ? getFilename(input.filePath) : undefined, | 540 | 541 | } | | 542 | + case "patch": | 541 | 543 | case "apply_patch": | 542 | 544 | return { | 543 | 545 | icon: "code-lines", | @@ -729,8 +731,8 @@ export function renderable(part: PartType, showReasoningSummaries = true) { | 729 | 731 | } | 730 | 732 |
| 731 | 733 | function toolDefaultOpen(tool: string, shell = false, edit = false) { | 732 | | - if (tool === "bash") return shell | 733 | | - if (tool === "edit" || tool === "write" || tool === "apply_patch") return edit | | 734 | + if (tool === "bash" || tool === "shell") return shell | | 735 | + if (tool === "edit" || tool === "write" || tool === "patch" || tool === "apply_patch") return edit | 734 | 736 | } | 735 | 737 |
| 736 | 738 | export function partDefaultOpen(part: PartType, shell = false, edit = false) { | @@ -1506,7 +1508,7 @@ export function registerTool(input: { name: string; render?: ToolComponent }) { | 1506 | 1508 | } | 1507 | 1509 |
| 1508 | 1510 | export function getTool(name: string) { | 1509 | | - return state[name]?.render | | 1511 | + return state[name === "apply_patch" ? "patch" : name === "bash" ? "shell" : name]?.render | 1510 | 1512 | } | 1511 | 1513 |
| 1512 | 1514 | export const ToolRegistry = { | @@ -2101,7 +2103,7 @@ ToolRegistry.register({ | 2101 | 2103 | }) | 2102 | 2104 |
| 2103 | 2105 | ToolRegistry.register({ | 2104 | | - name: "bash", | | 2106 | + name: "shell", | 2105 | 2107 | render(props) { | 2106 | 2108 | const i18n = useI18n() | 2107 | 2109 | const pending = () => props.status === "pending" || props.status === "running" | @@ -2337,7 +2339,7 @@ ToolRegistry.register({ | 2337 | 2339 | }) | 2338 | 2340 |
| 2339 | 2341 | ToolRegistry.register({ | 2340 | | - name: "apply_patch", | | 2342 | + name: "patch", | 2341 | 2343 | render(props) { | 2342 | 2344 | const i18n = useI18n() | 2343 | 2345 | const fileComponent = useFileComponent() | |
Collapse file Copy file name to clipboardExpand all lines: packages/session-ui/src/components/tool-error-card.tsx +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -51,6 +51,8 @@ export function ToolErrorCard(props: ToolErrorCardProps) { | 51 | 51 | webfetch: "ui.tool.webfetch", | 52 | 52 | websearch: "ui.tool.websearch", | 53 | 53 | bash: "ui.tool.shell", | | 54 | + shell: "ui.tool.shell", | | 55 | + patch: "ui.tool.patch", | 54 | 56 | apply_patch: "ui.tool.patch", | 55 | 57 | question: "ui.tool.questions", | 56 | 58 | } | |
|