Skip to content

Commit ec6532c

Browse files
committed
fix: resolve issues anomalyco#240, anomalyco#238, and anomalyco#234 (TUI/Web bugfixes)
1 parent 486205f commit ec6532c

8 files changed

Lines changed: 1096 additions & 56 deletions

File tree

‎CONTEXT/PLAN-240-238-234-tui-web-bugfixes-2026-01-01.md‎

Lines changed: 489 additions & 0 deletions
Large diffs are not rendered by default.

‎bun.lock‎

Lines changed: 347 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/app/src/pages/layout.tsx‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { Tooltip, TooltipKeybind } from "@opencode-ai/ui/tooltip"
1717
import { Collapsible } from "@opencode-ai/ui/collapsible"
1818
import { DiffChanges } from "@opencode-ai/ui/diff-changes"
1919
import { Spinner } from "@opencode-ai/ui/spinner"
20-
import { Mark } from "@opencode-ai/ui/logo"
20+
2121
import { getFilename } from "@opencode-ai/util/path"
2222
import { DropdownMenu } from "@opencode-ai/ui/dropdown-menu"
2323
import { Session } from "@opencode-ai/sdk/v2/client"
@@ -920,11 +920,6 @@ export default function Layout(props: ParentProps) {
920920
return (
921921
<>
922922
<div class="flex flex-col items-start self-stretch gap-4 p-2 min-h-0 overflow-hidden">
923-
<Show when={!sidebarProps.mobile}>
924-
<A href="/" class="shrink-0 h-8 flex items-center justify-start px-2" data-tauri-drag-region>
925-
<Mark class="shrink-0" />
926-
</A>
927-
</Show>
928923
<Show when={!sidebarProps.mobile}>
929924
<TooltipKeybind
930925
class="shrink-0"

‎packages/app/src/pages/session.tsx‎

Lines changed: 84 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ import { DialogSelectModel } from "@/components/dialog-select-model"
5757
import { DialogSelectMcp } from "@/components/dialog-select-mcp"
5858
import { useCommand } from "@/context/command"
5959
import { A, useNavigate, useParams } from "@solidjs/router"
60-
import { UserMessage } from "@opencode-ai/sdk/v2"
60+
import { UserMessage, ToolPart } from "@opencode-ai/sdk/v2"
6161
import { useSDK } from "@/context/sdk"
6262
import { usePrompt } from "@/context/prompt"
6363
import { extractPromptFromParts } from "@/utils/prompt"
@@ -317,6 +317,57 @@ export default function Page() {
317317
)
318318
const lastUserMessage = createMemo(() => visibleUserMessages().at(-1))
319319

320+
// Detect pending askquestion tools from synced message parts (mirrors TUI logic)
321+
const pendingAskQuestion = createMemo(() => {
322+
if (!params.id) return null
323+
const sessionMessages = sync.data.message[params.id] ?? []
324+
325+
// Search backwards for the most recent pending question
326+
for (const message of [...sessionMessages].reverse()) {
327+
const parts = sync.data.part[message.id] ?? []
328+
329+
for (const part of [...parts].reverse()) {
330+
if (part.type !== "tool") continue
331+
const toolPart = part as ToolPart
332+
333+
if (toolPart.tool !== "askquestion") continue
334+
if (toolPart.state.status !== "running") continue
335+
336+
const metadata = toolPart.state.metadata as { status?: string; questions?: AskQuestionQuestion[] } | undefined
337+
338+
if (metadata?.status !== "waiting") continue
339+
340+
return {
341+
callID: toolPart.callID,
342+
messageID: toolPart.messageID,
343+
questions: (metadata.questions ?? []) as AskQuestionQuestion[],
344+
}
345+
}
346+
}
347+
348+
return null
349+
})
350+
351+
// Handlers for AskQuestion wizard
352+
const handleAskQuestionSubmit = async (answers: AskQuestionAnswer[]) => {
353+
const pending = pendingAskQuestion()
354+
if (!pending || !params.id) return
355+
await sdk.client.askquestion.respond({
356+
callID: pending.callID,
357+
sessionID: params.id,
358+
answers,
359+
})
360+
}
361+
362+
const handleAskQuestionCancel = async () => {
363+
const pending = pendingAskQuestion()
364+
if (!pending || !params.id) return
365+
await sdk.client.askquestion.cancel({
366+
callID: pending.callID,
367+
sessionID: params.id,
368+
})
369+
}
370+
320371
createEffect(
321372
on(
322373
() => lastUserMessage()?.id,
@@ -1335,11 +1386,22 @@ export default function Page() {
13351386
</Switch>
13361387
<div class="absolute inset-x-0 bottom-4 flex flex-col justify-center items-center z-50 px-4">
13371388
<div class="w-full">
1338-
<PromptInput
1339-
ref={(el) => {
1340-
inputRef = el
1341-
}}
1342-
/>
1389+
<Show when={pendingAskQuestion()}>
1390+
{(pending) => (
1391+
<AskQuestionWizard
1392+
questions={pending().questions}
1393+
onSubmit={handleAskQuestionSubmit}
1394+
onCancel={handleAskQuestionCancel}
1395+
/>
1396+
)}
1397+
</Show>
1398+
<Show when={!pendingAskQuestion()}>
1399+
<PromptInput
1400+
ref={(el) => {
1401+
inputRef = el
1402+
}}
1403+
/>
1404+
</Show>
13431405
</div>
13441406
</div>
13451407
</div>
@@ -1359,11 +1421,22 @@ export default function Page() {
13591421
"max-w-200": !showTabs(),
13601422
}}
13611423
>
1362-
<PromptInput
1363-
ref={(el) => {
1364-
inputRef = el
1365-
}}
1366-
/>
1424+
<Show when={pendingAskQuestion()}>
1425+
{(pending) => (
1426+
<AskQuestionWizard
1427+
questions={pending().questions}
1428+
onSubmit={handleAskQuestionSubmit}
1429+
onCancel={handleAskQuestionCancel}
1430+
/>
1431+
)}
1432+
</Show>
1433+
<Show when={!pendingAskQuestion()}>
1434+
<PromptInput
1435+
ref={(el) => {
1436+
inputRef = el
1437+
}}
1438+
/>
1439+
</Show>
13671440
</div>
13681441
</div>
13691442
<Show when={showTabs()}>

‎packages/opencode/src/cli/cmd/tui/component/dialog-session-list.tsx‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { useTheme } from "../context/theme"
99
import { useSDK } from "../context/sdk"
1010
import { DialogSessionRename } from "./dialog-session-rename"
1111
import { useKV } from "../context/kv"
12-
import "opentui-spinner/solid"
12+
import { getSpinnerFrame } from "../util/spinners"
1313

1414
export function DialogSessionList() {
1515
const dialog = useDialog()
@@ -25,8 +25,6 @@ export function DialogSessionList() {
2525

2626
const currentSessionID = createMemo(() => (route.data.type === "session" ? route.data.sessionID : undefined))
2727

28-
const spinnerFrames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
29-
3028
const options = createMemo(() => {
3129
const today = new Date().toDateString()
3230
return sync.data.session
@@ -49,7 +47,7 @@ export function DialogSessionList() {
4947
footer: Locale.time(x.time.updated),
5048
gutter: isWorking ? (
5149
<Show when={kv.get("animations_enabled", true)} fallback={<text fg={theme.textMuted}>[⋯]</text>}>
52-
<spinner frames={spinnerFrames} interval={80} color={theme.primary} />
50+
<text fg={theme.primary}>{getSpinnerFrame()}</text>
5351
</Show>
5452
) : undefined,
5553
}

‎packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx‎

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import type { FilePart } from "@opencode-ai/sdk/v2"
2424
import { TuiEvent } from "../../event"
2525
import { iife } from "@/util/iife"
2626
import { Locale } from "@/util/locale"
27-
import { createColors, createFrames } from "../../ui/spinner.ts"
27+
import { getSpinnerFrame } from "../../util/spinners"
2828
import { useDialog } from "@tui/ui/dialog"
2929
import { DialogProvider as DialogProviderConnect } from "../dialog-provider"
3030
import { DialogAlert } from "../../ui/dialog-alert"
@@ -758,25 +758,7 @@ export function Prompt(props: PromptProps) {
758758
return !!current
759759
})
760760

761-
const spinnerDef = createMemo(() => {
762-
const color = local.agent.color(local.agent.current().name)
763-
return {
764-
frames: createFrames({
765-
color,
766-
style: "blocks",
767-
inactiveFactor: 0.6,
768-
// enableFading: false,
769-
minAlpha: 0.3,
770-
}),
771-
color: createColors({
772-
color,
773-
style: "blocks",
774-
inactiveFactor: 0.6,
775-
// enableFading: false,
776-
minAlpha: 0.3,
777-
}),
778-
}
779-
})
761+
const spinnerColor = createMemo(() => local.agent.color(local.agent.current().name))
780762

781763
return (
782764
<>
@@ -1046,7 +1028,7 @@ export function Prompt(props: PromptProps) {
10461028
<box flexShrink={0} flexDirection="row" gap={1}>
10471029
<box marginLeft={1}>
10481030
<Show when={kv.get("animations_enabled", true)} fallback={<text fg={theme.textMuted}>[⋯]</text>}>
1049-
<spinner color={spinnerDef().color} frames={spinnerDef().frames} interval={40} />
1031+
<text fg={spinnerColor()}>{getSpinnerFrame()}</text>
10501032
</Show>
10511033
</box>
10521034
<box flexDirection="row" gap={1} flexShrink={0}>
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
import { describe, expect, test } from "bun:test"
2+
import { AskQuestion } from "../../src/askquestion"
3+
4+
describe("AskQuestion Core", () => {
5+
test("register and respond", async () => {
6+
const callID = "test-call-id"
7+
const sessionID = "test-session-id"
8+
const messageID = "test-message-id"
9+
const questions: AskQuestion.Question[] = [
10+
{
11+
id: "q1",
12+
label: "Q1",
13+
question: "How are you?",
14+
options: [
15+
{ value: "good", label: "Good" },
16+
{ value: "bad", label: "Bad" },
17+
],
18+
},
19+
]
20+
21+
const promise = AskQuestion.register(callID, sessionID, messageID, questions)
22+
23+
const pending = AskQuestion.get(callID)
24+
expect(pending).toBeDefined()
25+
expect(pending?.questions).toEqual(questions)
26+
27+
const answers: AskQuestion.Answer[] = [
28+
{ questionId: "q1", values: ["good"] },
29+
]
30+
31+
AskQuestion.respond(callID, answers)
32+
33+
const result = await promise
34+
expect(result).toEqual(answers)
35+
expect(AskQuestion.get(callID)).toBeUndefined()
36+
})
37+
38+
test("register and cancel", async () => {
39+
const callID = "test-call-id-2"
40+
const sessionID = "test-session-id"
41+
const messageID = "test-message-id"
42+
const questions: AskQuestion.Question[] = [
43+
{
44+
id: "q1",
45+
label: "Q1",
46+
question: "How are you?",
47+
options: [
48+
{ value: "good", label: "Good" },
49+
{ value: "bad", label: "Bad" },
50+
],
51+
},
52+
]
53+
54+
const promise = AskQuestion.register(callID, sessionID, messageID, questions)
55+
56+
AskQuestion.cancel(callID)
57+
58+
expect(promise).rejects.toThrow("User cancelled the question wizard")
59+
expect(AskQuestion.get(callID)).toBeUndefined()
60+
})
61+
})
62+
63+
describe("AskQuestion Detection Logic", () => {
64+
// Mock detection logic similar to TUI/Web implementation
65+
function detectPending(messages: any[], partsMap: Record<string, any[]>) {
66+
for (const message of [...messages].reverse()) {
67+
const parts = partsMap[message.id] ?? []
68+
for (const part of [...parts].reverse()) {
69+
if (part.type !== "tool") continue
70+
if (part.tool !== "askquestion") continue
71+
if (part.state.status !== "running") continue
72+
73+
const metadata = part.state.metadata
74+
if (metadata?.status !== "waiting") continue
75+
76+
return {
77+
callID: part.callID,
78+
messageId: message.id,
79+
questions: metadata.questions ?? [],
80+
}
81+
}
82+
}
83+
return null
84+
}
85+
86+
test("detects pending askquestion", () => {
87+
const messages = [{ id: "m1" }, { id: "m2" }]
88+
const partsMap = {
89+
m1: [],
90+
m2: [
91+
{
92+
type: "tool",
93+
tool: "askquestion",
94+
callID: "c1",
95+
state: {
96+
status: "running",
97+
metadata: {
98+
status: "waiting",
99+
questions: [{ id: "q1", label: "Q1" }],
100+
},
101+
},
102+
},
103+
],
104+
}
105+
106+
const result = detectPending(messages, partsMap)
107+
expect(result).not.toBeNull()
108+
expect(result?.callID).toBe("c1")
109+
expect(result?.questions[0].id).toBe("q1")
110+
})
111+
112+
test("ignores completed askquestion", () => {
113+
const messages = [{ id: "m1" }]
114+
const partsMap = {
115+
m1: [
116+
{
117+
type: "tool",
118+
tool: "askquestion",
119+
callID: "c1",
120+
state: {
121+
status: "completed",
122+
metadata: {
123+
status: "completed",
124+
},
125+
},
126+
},
127+
],
128+
}
129+
130+
const result = detectPending(messages, partsMap)
131+
expect(result).toBeNull()
132+
})
133+
134+
test("ignores askquestion in different state", () => {
135+
const messages = [{ id: "m1" }]
136+
const partsMap = {
137+
m1: [
138+
{
139+
type: "tool",
140+
tool: "askquestion",
141+
callID: "c1",
142+
state: {
143+
status: "running",
144+
metadata: {
145+
status: "something-else",
146+
},
147+
},
148+
},
149+
],
150+
}
151+
152+
const result = detectPending(messages, partsMap)
153+
expect(result).toBeNull()
154+
})
155+
})

0 commit comments

Comments
 (0)