Skip to content

Commit 1c472e3

Browse files
committed
refactor(plugin): drop ui.tool and the band composer chrome
No plugin uses either: the Prime look draws tool rows through the session.part.tool slot and picks the rail composer. The transcript-defaults fixture now draws its rows through that slot.
1 parent e6a7ecf commit 1c472e3

9 files changed

Lines changed: 31 additions & 98 deletions

File tree

‎packages/plugin/src/tui/context.ts‎

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -607,14 +607,12 @@ export interface Layout {
607607
readonly inset?: number
608608
/**
609609
* The composer's chrome. "bar" is the host default: a left accent bar and a
610-
* metadata row. "band" is a full-width band on raised.base with a blank row
611-
* above and below the editor and the given prefix before it. "rail" is a bare
610+
* metadata row. "rail" is a bare
612611
* left rail in the text colour (the warning colour in shell mode) with no
613612
* fill, padding or metadata row.
614613
*/
615614
readonly composer?:
616615
| { readonly chrome: "bar" }
617-
| { readonly chrome: "band"; readonly prefix?: string }
618616
| { readonly chrome: "rail" }
619617
/**
620618
* Transcript defaults for users who have not chosen. The user's `session`
@@ -628,9 +626,6 @@ export interface Layout {
628626
}
629627
}
630628

631-
/** Renders one tool call in the transcript. */
632-
export type ToolRender = (input: SessionPartInput & { readonly tool: string }) => JSX.Element
633-
634629
/** One row of a plugin's composer popup. */
635630
export interface AutocompleteItem {
636631
/** What selecting inserts after the trigger, and what the typed filter matches. */
@@ -743,13 +738,6 @@ export interface UI {
743738
readonly slot: (claim: SlotClaim) => () => void
744739
/** Sets host layout knobs until the returned cleanup runs; see Layout. */
745740
readonly layout: (layout: Layout) => () => void
746-
/**
747-
* Renders every call of one tool, by its canonical name (shell, patch,
748-
* subagent, read, ...), until the returned cleanup runs. When several
749-
* active plugins render one tool, the last-enabled one wins. A slot claim
750-
* that replaces session.part.tool still wins over it.
751-
*/
752-
readonly tool: (name: string, render: ToolRender) => () => void
753741
/**
754742
* Adds a composer popup for one trigger character until the returned cleanup
755743
* runs; see AutocompleteSource. When several active plugins claim one

‎packages/tui/src/component/prompt/index.tsx‎

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,22 +1670,12 @@ export function Prompt(props: PromptProps) {
16701670
const maxHeight = createMemo(() => Math.max(6, Math.floor(dimensions().height / 3)))
16711671

16721672
const plugins = usePlugin()
1673-
// "band" chrome: no accent bar or metadata row; the editor sits on a
1674-
// raised band with a blank row above and below and an optional prefix.
1675-
const band = createMemo(() => {
1676-
const composer = plugins.layout().composer
1677-
return composer?.chrome === "band" ? { prefix: composer.prefix } : undefined
1678-
})
16791673
// "rail" chrome: a bare left rail in the text colour (the warning colour in
16801674
// shell mode), no fill, padding or metadata row.
16811675
const rail = createMemo(() => plugins.layout().composer?.chrome === "rail")
1682-
const bare = () => band() !== undefined || rail()
1676+
const bare = rail
16831677
const promptBg = createMemo(() =>
1684-
rail()
1685-
? RGBA.fromInts(0, 0, 0, 0)
1686-
: band()
1687-
? theme.background.raised.base
1688-
: theme.decrease(theme.background.raised.base),
1678+
rail() ? RGBA.fromInts(0, 0, 0, 0) : theme.decrease(theme.background.raised.base),
16891679
)
16901680
const railColor = () => (store.mode === "shell" ? theme.text.feedback.warning.base : theme.text.base)
16911681

@@ -1695,21 +1685,16 @@ export function Prompt(props: PromptProps) {
16951685
<box
16961686
width="100%"
16971687
border={["left"]}
1698-
// Workaround: an OpenTUI box keeps its border once styled (setting
1699-
// `border` back to false leaves the bar drawn), so the band paints the
1700-
// bar in the band colour instead of removing it.
1701-
borderColor={band() ? promptBg() : rail() ? railColor() : borderHighlight()}
1702-
backgroundColor={band() ? promptBg() : undefined}
1688+
borderColor={rail() ? railColor() : borderHighlight()}
17031689
customBorderChars={{
17041690
...SplitBorder.customBorderChars,
17051691
bottomLeft: "╹",
17061692
}}
17071693
>
17081694
<box
1709-
paddingLeft={band() ? 0 : rail() ? 1 : dimensions().width < 44 ? 1 : 2}
1695+
paddingLeft={rail() ? 1 : dimensions().width < 44 ? 1 : 2}
17101696
paddingRight={dimensions().width < 44 ? 1 : 2}
17111697
paddingTop={rail() ? 0 : 1}
1712-
paddingBottom={band() ? 1 : 0}
17131698
flexShrink={0}
17141699
backgroundColor={promptBg()}
17151700
flexGrow={1}
@@ -1784,7 +1769,6 @@ export function Prompt(props: PromptProps) {
17841769
</box>
17851770
</Show>
17861771
<box flexDirection="row" width="100%">
1787-
<Show when={band()?.prefix}>{(prefix) => <text fg={theme.text.base}>{prefix()}</text>}</Show>
17881772
<textarea
17891773
flexGrow={1}
17901774
flexShrink={1}

‎packages/tui/src/plugin/api.tsx‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import type {
1010
SlotMap,
1111
SlotPath,
1212
Toast,
13-
ToolRender,
1413
AutocompleteSource,
1514
} from "@opencode/plugin/tui/context"
1615
import type { Placement, PlacementKind } from "./structure"
@@ -54,15 +53,14 @@ const placements = ["prepend", "append", "before", "after", "replace"] as const
5453
// The provider's registration store, narrowed to what a plugin context needs:
5554
// route/slot registration lands there, but ordering and lifecycle stay owned
5655
// by the provider.
57-
export type RegistryKind = "routes" | "slots" | "markdown" | "layout" | "tools" | "autocomplete"
56+
export type RegistryKind = "routes" | "slots" | "markdown" | "layout" | "autocomplete"
5857

5958
export type Registry = {
6059
has(kind: RegistryKind, name: string): boolean
6160
set(kind: "routes", name: string, page: Page): void
6261
set(kind: "slots", name: string, claim: RegisteredSlot): void
6362
set(kind: "markdown", name: string, render: MarkdownCodeBlockRenderer): void
6463
set(kind: "layout", name: string, layout: Layout): void
65-
set(kind: "tools", name: string, render: ToolRender): void
6664
set(kind: "autocomplete", name: string, source: AutocompleteSource): void
6765
remove(kind: RegistryKind, name: string): void
6866
active(): boolean
@@ -328,11 +326,6 @@ export function createPluginContext(input: {
328326
input.registry.set("layout", key, value)
329327
return registration("layout", key)
330328
},
331-
tool(name, render) {
332-
if (input.registry.has("tools", name)) throw new Error(`Tool renderer already registered: ${name}`)
333-
input.registry.set("tools", name, (toolInput) => provide(() => render(toolInput)))
334-
return registration("tools", name)
335-
},
336329
autocomplete(source) {
337330
// The host owns `/` (commands) and `@` (files, agents, skills, references).
338331
if ([...source.trigger].length !== 1 || /[\s/@]/.test(source.trigger))

‎packages/tui/src/plugin/context.tsx‎

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
import path from "path"
1717
import { stat } from "fs/promises"
1818
import { fileURLToPath } from "url"
19-
import type { AutocompleteSource, Layout, Page, ToolRender } from "@opencode/plugin/tui/context"
19+
import type { AutocompleteSource, Layout, Page } from "@opencode/plugin/tui/context"
2020
import { Host } from "@opencode/plugin/host"
2121
import { resolveSlots, type Claim } from "./structure"
2222
import { createStore, produce, reconcile as reconcileStore, unwrap } from "solid-js/store"
@@ -71,8 +71,6 @@ type Value = {
7171
readonly markdown: () => MarkdownOptions["renderNode"]
7272
/** Layout knobs merged across active plugins; later-enabled plugins win per field. */
7373
readonly layout: () => Layout
74-
/** The renderer for one canonical tool name; the last-enabled active plugin that registered one wins. */
75-
readonly tool: (name: string) => { readonly plugin: string; readonly render: ToolRender } | undefined
7674
/** Composer popups by trigger character; the last-enabled active plugin that claimed one wins. */
7775
readonly autocomplete: () => ReadonlyMap<string, AutocompleteSource>
7876
readonly activate: (id: string) => Promise<boolean>
@@ -90,7 +88,6 @@ type Registration = {
9088
slots: Record<string, RegisteredSlot>
9189
markdown: Record<string, MarkdownCodeBlockRenderer>
9290
layout: Record<string, Layout>
93-
tools: Record<string, ToolRender>
9491
autocomplete: Record<string, AutocompleteSource>
9592
cleanups: Dispose[]
9693
}
@@ -162,7 +159,6 @@ export function PluginProvider(props: ParentProps<{ packages: PackageSource; dir
162159
setStore("registrations", id, "slots", reconcileStore({}))
163160
setStore("registrations", id, "markdown", reconcileStore({}))
164161
setStore("registrations", id, "layout", reconcileStore({}))
165-
setStore("registrations", id, "tools", reconcileStore({}))
166162
setStore("registrations", id, "autocomplete", reconcileStore({}))
167163
}
168164
// Registration-store key order is enable order, so later items win.
@@ -179,14 +175,6 @@ export function PluginProvider(props: ParentProps<{ packages: PackageSource; dir
179175
{},
180176
),
181177
)
182-
const tools = createMemo(() => {
183-
const result = new Map<string, { plugin: string; render: ToolRender }>()
184-
for (const [plugin, registration] of Object.entries(store.registrations)) {
185-
if (!registration.active) continue
186-
for (const [name, render] of Object.entries(registration.tools)) result.set(name, { plugin, render })
187-
}
188-
return result
189-
})
190178
const autocomplete = createMemo(() => {
191179
const result = new Map<string, AutocompleteSource>()
192180
for (const registration of Object.values(store.registrations)) {
@@ -215,7 +203,7 @@ export function PluginProvider(props: ParentProps<{ packages: PackageSource; dir
215203
set: (
216204
kind: RegistryKind,
217205
name: string,
218-
value: Page | RegisteredSlot | MarkdownCodeBlockRenderer | Layout | ToolRender | AutocompleteSource,
206+
value: Page | RegisteredSlot | MarkdownCodeBlockRenderer | Layout | AutocompleteSource,
219207
) => setStore("registrations", id, kind, name, () => value),
220208
remove: (kind, name) =>
221209
setStore(
@@ -658,7 +646,6 @@ export function PluginProvider(props: ParentProps<{ packages: PackageSource; dir
658646
slots: { register: registerSlot, resolved },
659647
markdown,
660648
layout,
661-
tool: (name) => tools().get(name),
662649
autocomplete,
663650
// Manual dialog toggles join the same chain as reconciles so a
664651
// toggle mid-reload cannot mix registrations across generations.
@@ -761,7 +748,6 @@ function toRegistration(item: Desired): Registration {
761748
slots: {},
762749
markdown: {},
763750
layout: {},
764-
tools: {},
765751
autocomplete: {},
766752
cleanups: [],
767753
}

‎packages/tui/src/plugin/render.tsx‎

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -160,23 +160,6 @@ export function Slot<Path extends SlotPath>(props: SlotProps<Path>) {
160160
)
161161
}
162162

163-
// The renderer a plugin registered for one tool through ui.tool, contained
164-
// like a slot contribution; the host's own row when none did.
165-
export function PluginTool(props: ParentProps<{ readonly input: SlotMap["session.part.tool"] }>) {
166-
const plugins = usePlugin()
167-
const claim = createMemo(() => plugins.tool(props.input.tool))
168-
return (
169-
// Keyed so a hot reload or a new owner recreates the boundary.
170-
<Show keyed when={claim()} fallback={props.children}>
171-
{(item) => (
172-
<PluginBoundary id={item.plugin} where={`tool ${props.input.tool}`}>
173-
{createComponent(item.render, mergeProps(() => props.input))}
174-
</PluginBoundary>
175-
)}
176-
</Show>
177-
)
178-
}
179-
180163
// ui.Markdown: the transcript's markdown, with the current syntax style,
181164
// every registered code-block renderer and the user's markdown mode.
182165
export function PluginMarkdown(props: MarkdownProps) {

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ import { collapseShellOutput, collapseToolOutput } from "../../util/collapse-too
103103
import { Keymap, type KeymapCommand } from "../../context/keymap"
104104
import { usePathFormatter } from "../../context/path-format"
105105
import { useLocation } from "../../context/location"
106-
import { PluginTool, Slot } from "../../plugin/render"
106+
import { Slot } from "../../plugin/render"
107107
import { usePlugin } from "../../plugin/context"
108108
import type { TranscriptRowKind } from "@opencode/plugin/tui/context"
109109
import {
@@ -2187,9 +2187,7 @@ function SessionPartView(props: {
21872187
</Match>
21882188
<Match when={item().type === "tool"}>
21892189
<Slot path="session.part.tool" input={toolInput()}>
2190-
<PluginTool input={toolInput()}>
2191-
<ToolPart part={item() as SessionMessageAssistantTool} images={props.images} />
2192-
</PluginTool>
2190+
<ToolPart part={item() as SessionMessageAssistantTool} images={props.images} />
21932191
</Slot>
21942192
</Match>
21952193
</Switch>
Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
import { Plugin } from "@opencode/plugin/tui"
22

3-
// Renders every shell call itself and asks for an ungrouped transcript with
4-
// reasoning shown.
3+
// Draws every tool call itself through the session.part.tool slot and asks
4+
// for an ungrouped transcript with reasoning shown.
55
export default Plugin.define({
66
id: "fixture.tool-renderer",
77
setup(context) {
88
context.ui.layout({ transcript: { grouping: "none", thinking: "show" } })
9-
context.ui.tool("shell", (input) => {
10-
const part = () => context.data.session.part.get(input.sessionID, input.messageID, input.partID)
11-
const command = () => {
12-
const item = part()
13-
if (item?.type !== "tool" || typeof item.state.input === "string") return ""
14-
return String((item.state.input as { command?: unknown }).command ?? "")
15-
}
16-
return (
17-
<text>
18-
Custom {input.tool} row: {command()}
19-
</text>
20-
)
9+
context.ui.slot({
10+
replace: "session.part.tool",
11+
render: (input) => {
12+
const command = () => {
13+
const message = context.data.session.message.get(input.sessionID, input.messageID)
14+
if (message?.type !== "assistant") return ""
15+
const item = message.content.find((part) => part.type === "tool" && part.id === input.partID)
16+
if (item?.type !== "tool" || typeof item.state.input === "string") return ""
17+
return String((item.state.input as { command?: unknown }).command ?? "")
18+
}
19+
return (
20+
<text>
21+
Custom {input.tool} row: {command()}
22+
</text>
23+
)
24+
},
2125
})
2226
},
2327
})

‎packages/tui/test/fixture/plugin/transcript-chrome/tui.tsx‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@ import { Plugin } from "@opencode/plugin/tui"
22

33
// Claims the transcript's chrome: a header, a first row, the user prompt, the
44
// turn footer and a last row drawing host code, with tight rows, a one-cell
5-
// inset and a band composer.
5+
// inset.
66
export default Plugin.define({
77
id: "fixture.transcript-chrome",
88
setup(context) {
99
context.ui.layout({
1010
inset: 1,
1111
rowGap: (row) => (row.kind === "footer" ? 0 : 1),
12-
composer: { chrome: "band", prefix: "> " },
1312
})
1413
context.ui.slot({ append: "session.header", render: () => <text>Header claimed</text> })
1514
context.ui.slot({ append: "session.transcript.start", render: () => <text>Transcript start claimed</text> })

‎packages/tui/test/plugin-session-hooks.test.tsx‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ test("a plugin reads a session's context usage, goal and parts, and renders host
119119
await app.waitForFrame((frame) => frame.includes("goal none [none]"))
120120
})
121121

122-
test("a plugin renders one tool by canonical name and sets transcript defaults", async () => {
122+
test("a plugin sets transcript defaults", async () => {
123123
await using app = await openSession("tool-renderer")
124124
await app.ready
125-
// `bash` is the shell tool's canonical name; grouping "none" keeps the call its own row.
125+
// grouping "none" keeps the call its own row.
126126
// thinking "show" expands reasoning the host hides by default.
127127
await waitForHighlightedFrame(
128128
app,
@@ -186,8 +186,6 @@ test("a plugin claims the transcript's header, first and last rows, user prompt
186186
expect(lines[footer - 1]).toContain("anything")
187187
const user = lines.findIndex((line) => line.includes("User band"))
188188
expect(lines[user - 1]?.trim()).toBe("")
189-
// The band composer puts its prefix before the editor. Its bar is still drawn, in the band's colour.
190-
expect(lines.some((line) => line.startsWith(" ┃> "))).toBe(true)
191189
})
192190

193191
test("a plugin picks the bare rail composer", async () => {

0 commit comments

Comments
 (0)