GeezerVison is showing github.com — Adds TUI prompt traits, refs, and plugin slots (#20741) · cavanaug/opencode@29f7dc0
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: .opencode/plugins/tui-smoke.tsx +53-7Lines changed: 53 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -653,31 +653,77 @@ const home = (api: TuiPluginApi, input: Cfg) => ({ | 653 | 653 | const skin = look(ctx.theme.current) | 654 | 654 | type Prompt = (props: { | 655 | 655 | workspaceID?: string | | 656 | + visible?: boolean | | 657 | + disabled?: boolean | | 658 | + onSubmit?: () => void | 656 | 659 | hint?: JSX.Element | | 660 | + right?: JSX.Element | | 661 | + showPlaceholder?: boolean | 657 | 662 | placeholders?: { | 658 | 663 | normal?: string[] | 659 | 664 | shell?: string[] | 660 | 665 | } | 661 | 666 | }) => JSX.Element | 662 | | - if (!("Prompt" in api.ui)) return null | 663 | | - const view = api.ui.Prompt | 664 | | - if (typeof view !== "function") return null | 665 | | - const Prompt = view as Prompt | | 667 | + type Slot = ( | | 668 | + props: { name: string; mode?: unknown; children?: JSX.Element } & Record<string, unknown>, | | 669 | + ) => JSX.Element | null | | 670 | + const ui = api.ui as TuiPluginApi["ui"] & { Prompt: Prompt; Slot: Slot } | | 671 | + const Prompt = ui.Prompt | | 672 | + const Slot = ui.Slot | 666 | 673 | const normal = [ | 667 | 674 | `[SMOKE] route check for ${input.label}`, | 668 | 675 | "[SMOKE] confirm home_prompt slot override", | 669 | | - "[SMOKE] verify api.ui.Prompt rendering", | | 676 | + "[SMOKE] verify prompt-right slot passthrough", | 670 | 677 | ] | 671 | 678 | const shell = ["printf '[SMOKE] home prompt\n'", "git status --short", "bun --version"] | 672 | | - const Hint = ( | | 679 | + const hint = ( | 673 | 680 | <box flexShrink={0} flexDirection="row" gap={1}> | 674 | 681 | <text fg={skin.muted}> | 675 | 682 | <span style={{ fg: skin.accent }}>•</span> smoke home prompt | 676 | 683 | </text> | 677 | 684 | </box> | 678 | 685 | ) | 679 | 686 |
| 680 | | - return <Prompt workspaceID={value.workspace_id} hint={Hint} placeholders={{ normal, shell }} /> | | 687 | + return ( | | 688 | + <Prompt | | 689 | + workspaceID={value.workspace_id} | | 690 | + hint={hint} | | 691 | + right={ | | 692 | + <box flexDirection="row" gap={1}> | | 693 | + <Slot name="home_prompt_right" workspace_id={value.workspace_id} /> | | 694 | + <Slot name="smoke_prompt_right" workspace_id={value.workspace_id} label={input.label} /> | | 695 | + </box> | | 696 | + } | | 697 | + placeholders={{ normal, shell }} | | 698 | + /> | | 699 | + ) | | 700 | + }, | | 701 | + home_prompt_right(ctx, value) { | | 702 | + const skin = look(ctx.theme.current) | | 703 | + const id = value.workspace_id?.slice(0, 8) ?? "none" | | 704 | + return ( | | 705 | + <text fg={skin.muted}> | | 706 | + <span style={{ fg: skin.accent }}>{input.label}</span> home:{id} | | 707 | + </text> | | 708 | + ) | | 709 | + }, | | 710 | + session_prompt_right(ctx, value) { | | 711 | + const skin = look(ctx.theme.current) | | 712 | + return ( | | 713 | + <text fg={skin.muted}> | | 714 | + <span style={{ fg: skin.accent }}>{input.label}</span> session:{value.session_id.slice(0, 8)} | | 715 | + </text> | | 716 | + ) | | 717 | + }, | | 718 | + smoke_prompt_right(ctx, value) { | | 719 | + const skin = look(ctx.theme.current) | | 720 | + const id = typeof value.workspace_id === "string" ? value.workspace_id.slice(0, 8) : "none" | | 721 | + const label = typeof value.label === "string" ? value.label : input.label | | 722 | + return ( | | 723 | + <text fg={skin.muted}> | | 724 | + <span style={{ fg: skin.accent }}>{label}</span> custom:{id} | | 725 | + </text> | | 726 | + ) | 681 | 727 | }, | 682 | 728 | home_bottom(ctx) { | 683 | 729 | const skin = look(ctx.theme.current) | |
Collapse file Copy file name to clipboardExpand all lines: bun.lock +14-14Lines changed: 14 additions & 14 deletions Collapse file Copy file name to clipboardExpand all lines: packages/opencode/package.json +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 104 | 104 | "@opencode-ai/sdk": "workspace:*", | 105 | 105 | "@opencode-ai/util": "workspace:*", | 106 | 106 | "@openrouter/ai-sdk-provider": "2.3.3", | 107 | | - "@opentui/core": "0.1.95", | 108 | | - "@opentui/solid": "0.1.95", | | 107 | + "@opentui/core": "0.1.96", | | 108 | + "@opentui/solid": "0.1.96", | 109 | 109 | "@parcel/watcher": "2.5.1", | 110 | 110 | "@pierre/diffs": "catalog:", | 111 | 111 | "@solid-primitives/event-bus": "1.1.2", | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/specs/tui-plugins.md +13-6Lines changed: 13 additions & 6 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -194,9 +194,9 @@ That is what makes local config-scoped plugins able to import `@opencode-ai/plug | 194 | 194 | Top-level API groups exposed to `tui(api, options, meta)`: | 195 | 195 |
| 196 | 196 | - `api.app.version` | 197 | | -- `api.command.register(cb)` / `api.command.trigger(value)` | | 197 | +- `api.command.register(cb)` / `api.command.trigger(value)` / `api.command.show()` | 198 | 198 | - `api.route.register(routes)` / `api.route.navigate(name, params?)` / `api.route.current` | 199 | | -- `api.ui.Dialog`, `DialogAlert`, `DialogConfirm`, `DialogPrompt`, `DialogSelect`, `Prompt`, `ui.toast`, `ui.dialog` | | 199 | +- `api.ui.Dialog`, `DialogAlert`, `DialogConfirm`, `DialogPrompt`, `DialogSelect`, `Slot`, `Prompt`, `ui.toast`, `ui.dialog` | 200 | 200 | - `api.keybind.match`, `print`, `create` | 201 | 201 | - `api.tuiConfig` | 202 | 202 | - `api.kv.get`, `set`, `ready` | @@ -225,6 +225,7 @@ Command behavior: | 225 | 225 | - Registrations are reactive. | 226 | 226 | - Later registrations win for duplicate `value` and for keybind handling. | 227 | 227 | - Hidden commands are removed from the command dialog and slash list, but still respond to keybinds and `command.trigger(value)` if `enabled !== false`. | | 228 | +- `api.command.show()` opens the host command dialog directly. | 228 | 229 |
| 229 | 230 | ### Routes | 230 | 231 |
| @@ -242,7 +243,8 @@ Command behavior: | 242 | 243 |
| 243 | 244 | - `ui.Dialog` is the base dialog wrapper. | 244 | 245 | - `ui.DialogAlert`, `ui.DialogConfirm`, `ui.DialogPrompt`, `ui.DialogSelect` are built-in dialog components. | 245 | | -- `ui.Prompt` renders the same prompt component used by the host app. | | 246 | +- `ui.Slot` renders host or plugin-defined slots by name from plugin JSX. | | 247 | +- `ui.Prompt` renders the same prompt component used by the host app and accepts `sessionID`, `workspaceID`, `ref`, and `right` for the prompt meta row's right side. | 246 | 248 | - `ui.toast(...)` shows a toast. | 247 | 249 | - `ui.dialog` exposes the host dialog stack: | 248 | 250 | - `replace(render, onClose?)` | @@ -315,8 +317,12 @@ Current host slot names: | 315 | 317 |
| 316 | 318 | - `app` | 317 | 319 | - `home_logo` | 318 | | -- `home_prompt` with props `{ workspace_id? }` | | 320 | +- `home_prompt` with props `{ workspace_id?, ref? }` | | 321 | +- `home_prompt_right` with props `{ workspace_id? }` | | 322 | +- `session_prompt` with props `{ session_id, visible?, disabled?, on_submit?, ref? }` | | 323 | +- `session_prompt_right` with props `{ session_id }` | 319 | 324 | - `home_bottom` | | 325 | +- `home_footer` | 320 | 326 | - `sidebar_title` with props `{ session_id, title, share_url? }` | 321 | 327 | - `sidebar_content` with props `{ session_id }` | 322 | 328 | - `sidebar_footer` with props `{ session_id }` | @@ -328,8 +334,8 @@ Slot notes: | 328 | 334 | - `api.slots.register(plugin)` does not return an unregister function. | 329 | 335 | - Returned ids are `pluginId`, `pluginId:1`, `pluginId:2`, and so on. | 330 | 336 | - Plugin-provided `id` is not allowed. | 331 | | -- The current host renders `home_logo` and `home_prompt` with `replace`, `sidebar_title` and `sidebar_footer` with `single_winner`, and `app`, `home_bottom`, and `sidebar_content` with the slot library default mode. | 332 | | -- Plugins cannot define new slot names in this branch. | | 337 | +- The current host renders `home_logo`, `home_prompt`, and `session_prompt` with `replace`, `home_footer`, `sidebar_title`, and `sidebar_footer` with `single_winner`, and `app`, `home_prompt_right`, `session_prompt_right`, `home_bottom`, and `sidebar_content` with the slot library default mode. | | 338 | +- Plugins can define custom slot names in `api.slots.register(...)` and render them from plugin UI with `ui.Slot`. | 333 | 339 |
| 334 | 340 | ### Plugin control and lifecycle | 335 | 341 |
| @@ -425,5 +431,6 @@ The plugin manager is exposed as a command with title `Plugins` and value `plugi | 425 | 431 | ## Current in-repo examples | 426 | 432 |
| 427 | 433 | - Local smoke plugin: `.opencode/plugins/tui-smoke.tsx` | | 434 | +- Local vim plugin: `.opencode/plugins/tui-vim.tsx` | 428 | 435 | - Local smoke config: `.opencode/tui.json` | 429 | 436 | - Local smoke theme: `.opencode/plugins/smoke-theme.json` |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx +42-21Lines changed: 42 additions & 21 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import { BoxRenderable, TextareaRenderable, MouseEvent, PasteEvent, decodePasteBytes, t, dim, fg } from "@opentui/core" | 2 | | -import { createEffect, createMemo, type JSX, onMount, createSignal, onCleanup, on, Show, Switch, Match } from "solid-js" | | 2 | +import { createEffect, createMemo, onMount, createSignal, onCleanup, on, Show, Switch, Match } from "solid-js" | 3 | 3 | import "opentui-spinner/solid" | 4 | 4 | import path from "path" | 5 | 5 | import { Filesystem } from "@/util/filesystem" | @@ -18,7 +18,7 @@ import { usePromptStash } from "./stash" | 18 | 18 | import { DialogStash } from "../dialog-stash" | 19 | 19 | import { type AutocompleteRef, Autocomplete } from "./autocomplete" | 20 | 20 | import { useCommandDialog } from "../dialog-command" | 21 | | -import { useKeyboard, useRenderer } from "@opentui/solid" | | 21 | +import { useKeyboard, useRenderer, type JSX } from "@opentui/solid" | 22 | 22 | import { Editor } from "@tui/util/editor" | 23 | 23 | import { useExit } from "../../context/exit" | 24 | 24 | import { Clipboard } from "../../util/clipboard" | @@ -42,8 +42,9 @@ export type PromptProps = { | 42 | 42 | visible?: boolean | 43 | 43 | disabled?: boolean | 44 | 44 | onSubmit?: () => void | 45 | | - ref?: (ref: PromptRef) => void | | 45 | + ref?: (ref: PromptRef | undefined) => void | 46 | 46 | hint?: JSX.Element | | 47 | + right?: JSX.Element | 47 | 48 | showPlaceholder?: boolean | 48 | 49 | placeholders?: { | 49 | 50 | normal?: string[] | @@ -92,6 +93,7 @@ export function Prompt(props: PromptProps) { | 92 | 93 | const kv = useKV() | 93 | 94 | const list = createMemo(() => props.placeholders?.normal ?? []) | 94 | 95 | const shell = createMemo(() => props.placeholders?.shell ?? []) | | 96 | + const [auto, setAuto] = createSignal<AutocompleteRef>() | 95 | 97 |
| 96 | 98 | function promptModelWarning() { | 97 | 99 | toast.show({ | @@ -435,11 +437,24 @@ export function Prompt(props: PromptProps) { | 435 | 437 | }, | 436 | 438 | } | 437 | 439 |
| | 440 | + onCleanup(() => { | | 441 | + props.ref?.(undefined) | | 442 | + }) | | 443 | + | 438 | 444 | createEffect(() => { | 439 | 445 | if (props.visible !== false) input?.focus() | 440 | 446 | if (props.visible === false) input?.blur() | 441 | 447 | }) | 442 | 448 |
| | 449 | + createEffect(() => { | | 450 | + if (!input || input.isDestroyed) return | | 451 | + input.traits = { | | 452 | + capture: auto()?.visible ? ["escape", "navigate", "submit", "tab"] : undefined, | | 453 | + suspend: !!props.disabled || store.mode === "shell", | | 454 | + status: store.mode === "shell" ? "SHELL" : undefined, | | 455 | + } | | 456 | + }) | | 457 | + | 443 | 458 | function restoreExtmarksFromParts(parts: PromptInfo["parts"]) { | 444 | 459 | input.extmarks.clear() | 445 | 460 | setStore("extmarkToPartIndex", new Map()) | @@ -844,7 +859,10 @@ export function Prompt(props: PromptProps) { | 844 | 859 | <> | 845 | 860 | <Autocomplete | 846 | 861 | sessionID={props.sessionID} | 847 | | - ref={(r) => (autocomplete = r)} | | 862 | + ref={(r) => { | | 863 | + autocomplete = r | | 864 | + setAuto(() => r) | | 865 | + }} | 848 | 866 | anchor={() => anchor} | 849 | 867 | input={() => input} | 850 | 868 | setPrompt={(cb) => { | @@ -1060,24 +1078,27 @@ export function Prompt(props: PromptProps) { | 1060 | 1078 | cursorColor={theme.text} | 1061 | 1079 | syntaxStyle={syntax()} | 1062 | 1080 | /> | 1063 | | - <box flexDirection="row" flexShrink={0} paddingTop={1} gap={1}> | 1064 | | - <text fg={highlight()}> | 1065 | | - {store.mode === "shell" ? "Shell" : Locale.titlecase(local.agent.current().name)}{" "} | 1066 | | - </text> | 1067 | | - <Show when={store.mode === "normal"}> | 1068 | | - <box flexDirection="row" gap={1}> | 1069 | | - <text flexShrink={0} fg={keybind.leader ? theme.textMuted : theme.text}> | 1070 | | - {local.model.parsed().model} | 1071 | | - </text> | 1072 | | - <text fg={theme.textMuted}>{local.model.parsed().provider}</text> | 1073 | | - <Show when={showVariant()}> | 1074 | | - <text fg={theme.textMuted}>·</text> | 1075 | | - <text> | 1076 | | - <span style={{ fg: theme.warning, bold: true }}>{local.model.variant.current()}</span> | | 1081 | + <box flexDirection="row" flexShrink={0} paddingTop={1} gap={1} justifyContent="space-between"> | | 1082 | + <box flexDirection="row" gap={1}> | | 1083 | + <text fg={highlight()}> | | 1084 | + {store.mode === "shell" ? "Shell" : Locale.titlecase(local.agent.current().name)}{" "} | | 1085 | + </text> | | 1086 | + <Show when={store.mode === "normal"}> | | 1087 | + <box flexDirection="row" gap={1}> | | 1088 | + <text flexShrink={0} fg={keybind.leader ? theme.textMuted : theme.text}> | | 1089 | + {local.model.parsed().model} | 1077 | 1090 | </text> | 1078 | | - </Show> | 1079 | | - </box> | 1080 | | - </Show> | | 1091 | + <text fg={theme.textMuted}>{local.model.parsed().provider}</text> | | 1092 | + <Show when={showVariant()}> | | 1093 | + <text fg={theme.textMuted}>·</text> | | 1094 | + <text> | | 1095 | + <span style={{ fg: theme.warning, bold: true }}>{local.model.variant.current()}</span> | | 1096 | + </text> | | 1097 | + </Show> | | 1098 | + </box> | | 1099 | + </Show> | | 1100 | + </box> | | 1101 | + {props.right} | 1081 | 1102 | </box> | 1082 | 1103 | </box> | 1083 | 1104 | </box> | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/cli/cmd/tui/plugin/api.tsx +11-1Lines changed: 11 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import type { ParsedKey } from "@opentui/core" | 2 | | -import type { TuiDialogSelectOption, TuiPluginApi, TuiRouteDefinition } from "@opencode-ai/plugin/tui" | | 2 | +import type { TuiDialogSelectOption, TuiPluginApi, TuiRouteDefinition, TuiSlotProps } from "@opencode-ai/plugin/tui" | 3 | 3 | import type { useCommandDialog } from "@tui/component/dialog-command" | 4 | 4 | import type { useKeybind } from "@tui/context/keybind" | 5 | 5 | import type { useRoute } from "@tui/context/route" | @@ -15,6 +15,7 @@ import { DialogConfirm } from "../ui/dialog-confirm" | 15 | 15 | import { DialogPrompt } from "../ui/dialog-prompt" | 16 | 16 | import { DialogSelect, type DialogSelectOption as SelectOption } from "../ui/dialog-select" | 17 | 17 | import { Prompt } from "../component/prompt" | | 18 | +import { Slot as HostSlot } from "./slots" | 18 | 19 | import type { useToast } from "../ui/toast" | 19 | 20 | import { Installation } from "@/installation" | 20 | 21 | import { createOpencodeClient, type OpencodeClient } from "@opencode-ai/sdk/v2" | @@ -244,6 +245,9 @@ export function createTuiApi(input: Input): TuiHostPluginApi { | 244 | 245 | trigger(value) { | 245 | 246 | input.command.trigger(value) | 246 | 247 | }, | | 248 | + show() { | | 249 | + input.command.show() | | 250 | + }, | 247 | 251 | }, | 248 | 252 | route: { | 249 | 253 | register(list) { | @@ -288,14 +292,20 @@ export function createTuiApi(input: Input): TuiHostPluginApi { | 288 | 292 | /> | 289 | 293 | ) | 290 | 294 | }, | | 295 | + Slot<Name extends string>(props: TuiSlotProps<Name>) { | | 296 | + return <HostSlot {...props} /> | | 297 | + }, | 291 | 298 | Prompt(props) { | 292 | 299 | return ( | 293 | 300 | <Prompt | | 301 | + sessionID={props.sessionID} | 294 | 302 | workspaceID={props.workspaceID} | 295 | 303 | visible={props.visible} | 296 | 304 | disabled={props.disabled} | 297 | 305 | onSubmit={props.onSubmit} | | 306 | + ref={props.ref} | 298 | 307 | hint={props.hint} | | 308 | + right={props.right} | 299 | 309 | showPlaceholder={props.showPlaceholder} | 300 | 310 | placeholders={props.placeholders} | 301 | 311 | /> | |
|