feat(tui): group sequential thinking (#36901) · argszero/opencode@0165455 · GitHub
Skip to content

Commit 0165455

Browse files
feat(tui): group sequential thinking (anomalyco#36901)
Co-authored-by: Kit Langton <7587245+kitlangton@users.noreply.github.com>
1 parent b67bed0 commit 0165455

8 files changed

Lines changed: 262 additions & 99 deletions

File tree

Binary file not shown.

packages/tui/src/routes/session/index.tsx

Lines changed: 112 additions & 1 deletion

packages/tui/src/routes/session/rows.ts

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ export type SessionRow =
1212
| { type: "message"; messageID: string }
1313
| { type: "compaction-queued"; inputID: string }
1414
| { type: "part"; ref: PartRef }
15+
| {
16+
type: "group"
17+
kind: "reasoning"
18+
refs: PartRef[]
19+
completed: boolean
20+
}
1521
| {
1622
type: "group"
1723
kind: "exploration"
@@ -131,6 +137,16 @@ export function createSessionRows(sessionID: Accessor<string>) {
131137
produce((draft) => {
132138
if (hasPart(draft, ref)) return
133139
const index = queuedStart(draft)
140+
if (ref.partID.startsWith("reasoning:")) {
141+
const previous = draft[index - 1]
142+
if (previous?.type === "group" && previous.kind === "reasoning") {
143+
previous.refs.push(ref)
144+
return
145+
}
146+
completePrevious(draft, index)
147+
draft.splice(index, 0, { type: "group", kind: "reasoning", refs: [ref], completed: false })
148+
return
149+
}
134150
if (name && exploration(name)) {
135151
const previous = draft[index - 1]
136152
if (previous?.type === "group" && previous.kind === "exploration") {
@@ -213,7 +229,7 @@ export function createSessionRows(sessionID: Accessor<string>) {
213229
data.on("session.agent.selected", message),
214230
data.on("session.model.selected", message),
215231
data.on("session.text.delta", (event) => {
216-
if (event.data.sessionID === sessionID())
232+
if (event.data.sessionID === sessionID() && event.data.delta.trim())
217233
appendPart({ messageID: event.data.assistantMessageID, partID: `text:${event.data.ordinal}` })
218234
}),
219235
data.on("session.text.ended", (event) => {
@@ -290,6 +306,16 @@ export function resolvePart(message: SessionMessageAssistant, partID: string) {
290306
}
291307

292308
function append(rows: SessionRow[], ref: PartRef, part: SessionMessageAssistant["content"][number]) {
309+
if (part.type === "reasoning") {
310+
const previous = rows.at(-1)
311+
if (previous?.type === "group" && previous.kind === "reasoning") {
312+
previous.refs.push(ref)
313+
return
314+
}
315+
completePrevious(rows)
316+
rows.push({ type: "group", kind: "reasoning", refs: [ref], completed: false })
317+
return
318+
}
293319
if (part.type === "tool") {
294320
if (exploration(part.name)) {
295321
const previous = rows.at(-1)
@@ -313,7 +339,7 @@ function completePrevious(rows: SessionRow[], index = rows.length) {
313339

314340
function partitionPending(rows: SessionRow[], pending: Set<string>) {
315341
rows.forEach((row) => {
316-
if (row.type !== "group") return
342+
if (row.type !== "group" || row.kind !== "exploration") return
317343
const refs = [...row.refs, ...row.pending]
318344
row.refs = refs.filter((ref) => !pending.has(ref.partID))
319345
row.pending = refs.filter((ref) => pending.has(ref.partID))
@@ -328,6 +354,7 @@ function hasPart(rows: SessionRow[], ref: PartRef) {
328354
return rows.some((row) => {
329355
if (row.type === "part") return row.ref.messageID === ref.messageID && row.ref.partID === ref.partID
330356
if (row.type !== "group") return false
331-
return [...row.refs, ...row.pending].some((item) => item.messageID === ref.messageID && item.partID === ref.partID)
357+
const refs = row.kind === "exploration" ? [...row.refs, ...row.pending] : row.refs
358+
return refs.some((item) => item.messageID === ref.messageID && item.partID === ref.partID)
332359
})
333360
}

packages/tui/src/ui/dialog-prompt.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export function DialogPrompt(props: DialogPromptProps) {
3838
{
3939
id: "dialog.prompt.submit",
4040
title: "Submit dialog prompt",
41+
bind: "return",
4142
group: "Dialog",
4243
run: confirm,
4344
},

packages/tui/test/cli/tui/dialog-prompt.test.tsx

Lines changed: 21 additions & 26 deletions

0 commit comments

Comments
 (0)