GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(app): render current session timeline · anomalyco/opencode@ae72b55

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages
    • app
      • e2e/performance/timeline
        • session-parent-hydration-benchmark.spec.ts
      • src/pages/session/timeline
        • message-timeline.tsx
        • projection.ts
        • rows-current.test.ts
        • rows.ts
    • session-ui/src/components
      • message-part.tsx
      • tool-error-card.tsx
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/app/e2e/performance/timeline/session-parent-hydration-benchmark.spec.ts‎

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 numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ const assistants = Array.from({ length: 14 }, (_, index) => {
4141
const messages = [user, ...assistants]
4242
const target = fixture.sessions.find((session) => session.id === fixture.targetID)!
4343
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}`
4550

4651
benchmark("hydrates an orphaned latest turn after a cold session click", async ({ browser, report }, testInfo) => {
4752
benchmark.setTimeout(180_000)
@@ -107,9 +112,25 @@ async function trial(page: Page, mode: ParentHydrationBenchmarkMode) {
107112
return { items: items.slice(start, end), cursor: start > 0 ? items[start]!.info.id : undefined }
108113
},
109114
})
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+
})
113134
await installStressSessionTabs(page, { sessionIDs: [fixture.sourceID] })
114135
await page.goto(stressSessionHref(fixture.sourceID))
115136
await expectSessionTitle(page, fixture.expected.sourceTitle)
@@ -144,8 +165,8 @@ async function trial(page: Page, mode: ParentHydrationBenchmarkMode) {
144165
parent: requests.filter((request) => request.type === "parent").length,
145166
}
146167
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)
149170
}
150171
return { metrics, requestCounts, historyGateCount: historyGates }
151172
}
Collapse file

‎packages/app/src/pages/session/timeline/message-timeline.tsx‎

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 numberDiff line numberDiff line change
@@ -283,6 +283,14 @@ export function MessageTimeline(props: {
283283
return sync().data.session_status[id] ?? idle
284284
})
285285
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+
})
286294
const info = createMemo(() => {
287295
const id = sessionID()
288296
if (!id) return
@@ -324,7 +332,7 @@ export function MessageTimeline(props: {
324332
const showHeader = createMemo(() => !!(titleValue() || parentID()))
325333
const projection = createTimelineProjection({
326334
messages: sessionMessages,
327-
userMessages: () => props.userMessages,
335+
sessionMessages: projectedMessages,
328336
parts: getMsgParts,
329337
status: sessionStatus,
330338
showReasoningSummaries: settings.general.showReasoningSummaries,
@@ -664,8 +672,7 @@ export function MessageTimeline(props: {
664672
}))
665673

666674
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 }),
669676
onSuccess: (_, input) => {
670677
sync().set(
671678
produce((draft) => {
@@ -809,7 +816,7 @@ export function MessageTimeline(props: {
809816
const nextSession = index === -1 ? undefined : (sessions[index + 1] ?? sessions[index - 1])
810817

811818
await sdk()
812-
.client.session.update({ sessionID, time: { archived: Date.now() } })
819+
.api.session.archive({ sessionID })
813820
.then(() => {
814821
sync().set(
815822
produce((draft) => {
@@ -838,8 +845,8 @@ export function MessageTimeline(props: {
838845
const nextSession = index === -1 ? undefined : (sessions[index + 1] ?? sessions[index - 1])
839846

840847
const result = await sdk()
841-
.client.session.delete({ sessionID })
842-
.then((x) => x.data)
848+
.api.session.remove({ sessionID })
849+
.then(() => true)
843850
.catch((err) => {
844851
showToast({
845852
title: language.t("session.delete.failed.title"),
Collapse file

‎packages/app/src/pages/session/timeline/projection.ts‎

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 numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
import { Binary } from "@opencode-ai/core/util/binary"
1+
import type { SessionMessageInfo } from "@opencode-ai/client/promise"
22
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"
44
import { reuseTimelineRows } from "./row-reconciliation"
55
import { Timeline, TimelineRow } from "./rows"
66

77
export { reuseTimelineRows } from "./row-reconciliation"
88

9-
const emptyAssistantMessages: AssistantMessage[] = []
10-
119
export function createTimelineProjection(input: {
1210
messages: Accessor<Message[]>
13-
userMessages: Accessor<UserMessage[]>
11+
sessionMessages: Accessor<SessionMessageInfo[]>
1412
parts: (messageID: string) => Part[]
1513
status: Accessor<SessionStatus>
1614
showReasoningSummaries: Accessor<boolean>
@@ -30,47 +28,19 @@ export function createTimelineProjection(input: {
3028
})
3129
return result
3230
})
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(),
6739
),
6840
)
41+
const activeMessageID = createMemo(() => projection().activeMessageID)
6942
const rows = createMemo((previous: TimelineRow.TimelineRow[] | undefined) =>
70-
reuseTimelineRows(
71-
previous,
72-
messageRowMemos().flatMap((memo) => memo()),
73-
),
43+
reuseTimelineRows(previous, projection().rows),
7444
)
7545
const rowByKey = createMemo(() => new Map(rows().map((row) => [TimelineRow.key(row), row] as const)))
7646
const messageRowIndex = createMemo(() => {
Collapse file

‎packages/app/src/pages/session/timeline/rows-current.test.ts‎

Copy file name to clipboard
+92Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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

‎packages/app/src/pages/session/timeline/rows.ts‎

Copy file name to clipboardExpand all lines: packages/app/src/pages/session/timeline/rows.ts
+42Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { parseCommentNote, readCommentMetadata } from "@/utils/comment-note"
2+
import type { SessionMessageInfo } from "@opencode-ai/client/promise"
23
import { AssistantMessage, Part, SessionStatus, UserMessage } from "@opencode-ai/sdk/v2"
34
import { groupParts, renderable, type PartGroup } from "@opencode-ai/session-ui/message-part"
45
import { TimelineRow, type SummaryDiff } from "./timeline-row"
@@ -31,6 +32,47 @@ export type TimelineRowMap = {
3132
}
3233

3334
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+
3476
export function constructMessageRows(
3577
userMessage: UserMessage,
3678
getMessageParts: (messageID: string) => Part[],
Collapse file

‎packages/session-ui/src/components/message-part.tsx‎

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 numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ export function getToolInfo(
521521
}
522522
}
523523
case "bash":
524+
case "shell":
524525
return {
525526
icon: "console",
526527
title: i18n.t("ui.tool.shell"),
@@ -538,6 +539,7 @@ export function getToolInfo(
538539
title: i18n.t("ui.messagePart.title.write"),
539540
subtitle: input.filePath ? getFilename(input.filePath) : undefined,
540541
}
542+
case "patch":
541543
case "apply_patch":
542544
return {
543545
icon: "code-lines",
@@ -729,8 +731,8 @@ export function renderable(part: PartType, showReasoningSummaries = true) {
729731
}
730732

731733
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
734736
}
735737

736738
export function partDefaultOpen(part: PartType, shell = false, edit = false) {
@@ -1506,7 +1508,7 @@ export function registerTool(input: { name: string; render?: ToolComponent }) {
15061508
}
15071509

15081510
export function getTool(name: string) {
1509-
return state[name]?.render
1511+
return state[name === "apply_patch" ? "patch" : name === "bash" ? "shell" : name]?.render
15101512
}
15111513

15121514
export const ToolRegistry = {
@@ -2101,7 +2103,7 @@ ToolRegistry.register({
21012103
})
21022104

21032105
ToolRegistry.register({
2104-
name: "bash",
2106+
name: "shell",
21052107
render(props) {
21062108
const i18n = useI18n()
21072109
const pending = () => props.status === "pending" || props.status === "running"
@@ -2337,7 +2339,7 @@ ToolRegistry.register({
23372339
})
23382340

23392341
ToolRegistry.register({
2340-
name: "apply_patch",
2342+
name: "patch",
23412343
render(props) {
23422344
const i18n = useI18n()
23432345
const fileComponent = useFileComponent()
Collapse file

‎packages/session-ui/src/components/tool-error-card.tsx‎

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 numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ export function ToolErrorCard(props: ToolErrorCardProps) {
5151
webfetch: "ui.tool.webfetch",
5252
websearch: "ui.tool.websearch",
5353
bash: "ui.tool.shell",
54+
shell: "ui.tool.shell",
55+
patch: "ui.tool.patch",
5456
apply_patch: "ui.tool.patch",
5557
question: "ui.tool.questions",
5658
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.