Skip to content

Commit 4c00002

Browse files
committed
fix(tui): keep a hidden tool response one click away under the input block
With `syntax.tool_input` on, a plugin or MCP call whose input becomes a block offered nothing to click when the generic output toggle was off: the block's hint and click came only from the input's own overflow or from shown output that overflowed, so a short input such as a Perplexity search query left the stored response unreachable. Under the input block a response the toggle hides is now held rather than dropped (packages/tui/src/util/tool-input.ts `toolOutputReach`): the block shows "Click to expand", and expanding draws the response below the input; an input short enough for one line expands from its row. Without `syntax.tool_input` the toggle stays in charge, as upstream draws it. AI-Model: anthropic/claude-opus-5-5 AI-Variant: high AI-Tool: opencode 1.19.0-vt-227-dfb56f76c7 AI-Platform: linux AI-Harness: Vibeterm 41f09c2 AI-Session-ID: ses_ed1e2b932ffe6tTqhsOiGuYXRE
1 parent 602c50d commit 4c00002

3 files changed

Lines changed: 59 additions & 7 deletions

File tree

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

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ import {
8080
fitsInline,
8181
formatToolInput,
8282
inlineToolInput,
83+
toolOutputReach,
8384
type ToolInputKind,
8485
type ToolInputRow,
8586
} from "../../util/tool-input"
@@ -2268,9 +2269,19 @@ function GenericTool(props: ToolProps) {
22682269
return collapsed().output
22692270
})
22702271
const showOutput = createMemo(() => Boolean(props.output && ctx.showGenericToolOutput()))
2272+
const reach = createMemo(() =>
2273+
toolOutputReach({
2274+
output: Boolean(props.output),
2275+
toggle: ctx.showGenericToolOutput(),
2276+
toolInput: ctx.tui.syntax?.tool_input === true,
2277+
expanded: expanded(),
2278+
}),
2279+
)
2280+
const heldOutput = () => reach().held
2281+
const outputShown = () => reach().shown
22712282
// Only output that is shown is sniffed or colored.
22722283
const language = createMemo(() =>
2273-
showOutput() ? outputLanguage(ctx.tui.syntax?.tool_output, props.tool, output()) : undefined,
2284+
outputShown() ? outputLanguage(ctx.tui.syntax?.tool_output, props.tool, output()) : undefined,
22742285
)
22752286
// The block's measured width, reported on layout and on resize only; until then an estimate.
22762287
const [inputWidth, setInputWidth] = createSignal<number>()
@@ -2279,7 +2290,10 @@ function GenericTool(props: ToolProps) {
22792290
const whole = expanded() || limit() === undefined
22802291
return formatToolInput(props.input, whole ? undefined : (inputWidth() ?? Math.max(20, ctx.width - 6)))
22812292
})
2282-
const overflow = createMemo(() => Boolean(inputBlock()?.overflow || (showOutput() && collapsed().overflow)))
2293+
const overflow = createMemo(() =>
2294+
Boolean(inputBlock()?.overflow || (showOutput() && collapsed().overflow) || heldOutput()),
2295+
)
2296+
const outputOverflow = createMemo(() => collapsed().overflow || heldOutput())
22832297

22842298
return (
22852299
<Switch>
@@ -2305,21 +2319,22 @@ function GenericTool(props: ToolProps) {
23052319
fold: code().textMuted,
23062320
}}
23072321
/>
2308-
<Show when={showOutput() && limited()}>
2322+
<Show when={outputShown() && limited()}>
23092323
<Show when={language()} fallback={<text fg={theme.text}>{limited()}</text>}>
23102324
{(language) => <ToolOutputText output={output()} shown={limited()} language={language()} />}
23112325
</Show>
23122326
</Show>
23132327
</BlockTool>
23142328
)}
23152329
</Match>
2316-
<Match when={!showOutput()}>
2330+
<Match when={!outputShown()}>
23172331
<InlineTool
23182332
icon="⚙"
23192333
pending="Writing command…"
23202334
complete={true}
23212335
part={props.part}
23222336
footerBelow={input(props.input).includes("\n")}
2337+
onClick={heldOutput() ? () => setExpanded(true) : undefined}
23232338
>
23242339
{props.tool} {input(props.input)}
23252340
</InlineTool>
@@ -2328,8 +2343,8 @@ function GenericTool(props: ToolProps) {
23282343
<BlockTool
23292344
title={`# ${props.tool} ${input(props.input)}`}
23302345
part={props.part}
2331-
hint={expandHint(collapsed().overflow, expanded())}
2332-
onClick={collapsed().overflow ? () => setExpanded((prev) => !prev) : undefined}
2346+
hint={expandHint(outputOverflow(), expanded())}
2347+
onClick={outputOverflow() ? () => setExpanded((prev) => !prev) : undefined}
23332348
>
23342349
<Show when={!collapsed().overflow || expanded() || limited()}>
23352350
<box gap={1}>

‎packages/tui/src/util/tool-input.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,11 @@ function scalar(value: unknown): ToolInputSegment {
135135
function isRecord(value: unknown): value is Record<string, unknown> {
136136
return typeof value === "object" && value !== null && !Array.isArray(value)
137137
}
138+
139+
// Whether a plugin or MCP tool's response is drawn. The generic output toggle decides by default.
140+
// With the input shown as a block (`toolInput`), a response the toggle hides is held instead of
141+
// lost: the call offers to expand, and expanding draws it.
142+
export function toolOutputReach(state: { output: boolean; toggle: boolean; toolInput: boolean; expanded: boolean }) {
143+
const held = state.output && !state.toggle && state.toolInput
144+
return { held, shown: (state.output && state.toggle) || (held && state.expanded) }
145+
}

‎packages/tui/test/util/tool-input.test.ts‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { describe, expect, test } from "bun:test"
2-
import { fitsInline, formatToolInput, inlineToolInput, type ToolInputRow } from "../../src/util/tool-input"
2+
import {
3+
fitsInline,
4+
formatToolInput,
5+
inlineToolInput,
6+
toolOutputReach,
7+
type ToolInputRow,
8+
} from "../../src/util/tool-input"
39

410
const whole = (output: string) => ({ output, overflow: false })
511
const text = (rows: ToolInputRow[]) => rows.map((row) => row.map((segment) => segment.text).join(""))
@@ -127,3 +133,26 @@ describe("formatToolInput", () => {
127133
expect(text(rows)).toEqual(["k: 日本語…"])
128134
})
129135
})
136+
137+
describe("toolOutputReach", () => {
138+
const base = { output: true, toggle: false, toolInput: true, expanded: false }
139+
140+
test("holds a response the toggle hides when the input is a block, and draws it once expanded", () => {
141+
expect(toolOutputReach(base)).toEqual({ held: true, shown: false })
142+
expect(toolOutputReach({ ...base, expanded: true })).toEqual({ held: true, shown: true })
143+
})
144+
145+
test("draws a response whenever the toggle shows output", () => {
146+
expect(toolOutputReach({ ...base, toggle: true })).toEqual({ held: false, shown: true })
147+
expect(toolOutputReach({ ...base, toggle: true, toolInput: false })).toEqual({ held: false, shown: true })
148+
})
149+
150+
test("leaves the toggle in charge without the input block, as upstream does", () => {
151+
expect(toolOutputReach({ ...base, toolInput: false, expanded: true })).toEqual({ held: false, shown: false })
152+
})
153+
154+
test("has nothing to hold or draw without a response", () => {
155+
expect(toolOutputReach({ ...base, output: false, expanded: true })).toEqual({ held: false, shown: false })
156+
expect(toolOutputReach({ ...base, output: false, toggle: true })).toEqual({ held: false, shown: false })
157+
})
158+
})

0 commit comments

Comments
 (0)