mirror of
https://github.com/anomalyco/opencode.git
synced 2026-05-25 06:35:35 +00:00
fix(tui): surface streaming reasoning titles
This commit is contained in:
parent
009065f430
commit
ce84bc60b2
2 changed files with 18 additions and 4 deletions
|
|
@ -6,12 +6,12 @@ export type ThinkingMode = "show" | "hide"
|
|||
const MODES: readonly ThinkingMode[] = ["show", "hide"] as const
|
||||
|
||||
// OpenAI's Responses API surfaces reasoning summaries that start with a bolded
|
||||
// title block: "**Inspecting PR workflow**\n\n<body>". Treat that first block
|
||||
// as disclosure metadata so the TUI can style its header independently from
|
||||
// the remaining markdown body.
|
||||
// title block: "**Inspecting PR workflow**\n\n<body>". Treat that first block,
|
||||
// or a complete title still awaiting its body while streaming, as disclosure
|
||||
// metadata so the TUI can style its header independently from the markdown body.
|
||||
export function reasoningSummary(text: string) {
|
||||
const content = text.trim()
|
||||
const match = content.match(/^\*\*([^*\n]+)\*\*\r?\n\r?\n/)
|
||||
const match = content.match(/^\*\*([^*\n]+)\*\*(?:\r?\n\r?\n|$)/)
|
||||
if (!match) return { title: null, body: content }
|
||||
return { title: match[1].trim(), body: content.slice(match[0].length).trim() }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,20 @@ describe("reasoningSummary", () => {
|
|||
})
|
||||
})
|
||||
|
||||
test("extracts a completed title before its streamed body arrives", () => {
|
||||
expect(reasoningSummary("**Continuing Quality Review**")).toEqual({
|
||||
title: "Continuing Quality Review",
|
||||
body: "",
|
||||
})
|
||||
})
|
||||
|
||||
test("does not consume ordinary leading bold content", () => {
|
||||
expect(reasoningSummary("**Important:** keep this in the body.")).toEqual({
|
||||
title: null,
|
||||
body: "**Important:** keep this in the body.",
|
||||
})
|
||||
})
|
||||
|
||||
test("leaves content without a leading title in its body", () => {
|
||||
expect(reasoningSummary("Details only.")).toEqual({ title: null, body: "Details only." })
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue