Skip to content

Commit 9a376f1

Browse files
sahrizviclaude
andcommitted
fix(tui): /skills opens the Altimate skills browser, and its actions work
`/skills` was owned twice: the core prompt's `prompt.skills` (upstream's plain selector — Enter inserts `/<skill>`, no actions) and the Altimate plugin's `altimate.skill.list` both registered that slash name, so the autocomplete listed two `/skills` rows and Enter took the first. Users were in the plain selector, where ctrl+a is the input's line-home, and the only TUI route to "Publish to workspace" was unreachable (#1328). - The core command keeps its palette entry and loses the slash name; the Altimate browser is `/skills`. - Enter in the browser now USES the skill — inserts `/<skill> ` into the prompt, as the docs said and the core selector did. The action picker is `ctrl+a` and an "Actions" footer button. - Actions, New and Install are `DialogSelect` actions with in-dialog bindings (`ctrl+a` / `ctrl+e` / `ctrl+i`) rather than a plugin-level keymap layer the open dialog outranks; they render as Tab-reachable footer buttons, so none of them depends on a chord. New is `ctrl+e` because `ctrl+n` is every dialog's "next". The dialog actions carry their own command names so the footer labels show the chords that work there. - The plugin `DialogSelect` API gains `actions` and `bindings`, forwarded by the adapter. - `DialogSelect` computed its action list eagerly, before `selected` was declared; a function-valued `disabled` (which the browser needs to keep the synthetic Install row out of the picker) threw "Cannot access 'selected' before initialization". Evaluated lazily now. Verified under vhs on a local build: the footer reads "Actions ctrl+a · New ctrl+e · Install ctrl+i"; Down then ctrl+a opens "Actions: dbt-pr-review"; Enter on a row leaves "/dbt-pr-review " in the prompt without submitting. Six tests mount a real DialogSelect in the provider stack and press the keys (including with the global layer registered and with a function-valued `disabled`). Closes #1328 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012Q51zFUmPg1WwtS5CrGJE6
1 parent 13cab51 commit 9a376f1

7 files changed

Lines changed: 301 additions & 11 deletions

File tree

‎docs/docs/configure/skills.md‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,21 +201,22 @@ altimate-code skill publish my-tool # upload every file in the skill dir
201201

202202
### TUI
203203

204-
Open the skill browser with `ctrl+i` when no other dialog is open, or type `/skills` in the prompt:
204+
Open the skill browser by typing `/skills` in the prompt (or `<leader>k`):
205205

206206
![Skill Browser](../assets/images/skills/tui-skill-browser.png)
207207

208208
**Keyboard shortcuts:**
209209

210210
| Key | Action |
211211
|-----|--------|
212-
| `ctrl+i` | Open skill browser (when no dialog is open) / Install skill (when inside browser) |
213212
| Enter | Use — inserts `/<skill-name>` into the prompt |
214213
| `ctrl+a` | Actions — show, edit, test, remove, or publish the selected skill to the linked workspace (the publish row appears only with `ALTIMATE_WORKSPACE=1`) |
215-
| `ctrl+n` | New — scaffold a new skill + CLI tool |
214+
| `ctrl+e` | New — scaffold a new skill + CLI tool (`ctrl+n` moves down the list, as in every dialog) |
215+
| `ctrl+i` | Install a skill from a GitHub repo, URL, or local path |
216+
| Tab / Shift+Tab | Move between the **Actions · New · Install** buttons in the footer, then Enter — the same three without a chord |
216217
| Esc | Back — returns to previous screen |
217218

218-
**Create skill** (`ctrl+n`):
219+
**Create skill** (`ctrl+e`, or the **New** footer button):
219220

220221
![Create Skill Dialog](../assets/images/skills/tui-skill-create.png)
221222

‎packages/opencode/src/plugin/tui/altimate/skill-ops.tsx‎

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,9 +781,55 @@ function DialogSkillList(props: { api: TuiPluginApi; onCurrent: (skill: string |
781781
}
782782
// altimate_change end
783783
props.onCurrent(item.value)
784-
// Selecting a skill opens its action picker (the pre-merge default action was the picker).
784+
// altimate_change start — Enter USES the skill: it inserts `/<skill> ` into the
785+
// prompt, as the docs say and as the core selector this dialog now replaces did
786+
// (#1328). The action picker moved to ctrl+a and the "Actions" footer button.
787+
const ref = api.prompt.active()
788+
if (ref) {
789+
ref.set({ ...ref.current, input: `/${item.value} `, parts: [] })
790+
api.ui.dialog.clear()
791+
ref.focus()
792+
return
793+
}
794+
// No prompt to write into (no session mounted): fall back to the picker.
785795
openActionPicker(api, skillMap().get(item.value), item.value, () => showList(api))
796+
// altimate_change end
786797
}}
798+
// altimate_change start — the picker, create and install as DIALOG actions (#1328).
799+
// The plugin's global keymap layer registers ctrl+a / ctrl+n / ctrl+i too, but while
800+
// this dialog is open its own layer outranks that one: ctrl+a went to the filter
801+
// input's line-home and ctrl+n to `dialog.select.next`. Declared here they are bound
802+
// inside the dialog (the model dialog binds ctrl+a the same way) and rendered as
803+
// footer buttons reachable with Tab, so the picker no longer depends on a chord at
804+
// all. ctrl+n stays the dialog's own "next"; New is ctrl+e in here.
805+
actions={[
806+
{
807+
command: "altimate.skill.list.actions",
808+
title: "Actions",
809+
disabled: (option) => option === undefined || option.value === INSTALL_ACTION_VALUE,
810+
onTrigger: (item) => {
811+
if (item.value === INSTALL_ACTION_VALUE) return
812+
props.onCurrent(item.value)
813+
openActionPicker(api, skillMap().get(item.value), item.value, () => showList(api))
814+
},
815+
},
816+
{
817+
command: "altimate.skill.list.create",
818+
title: "New",
819+
onTrigger: () => showCreate(api, filter().trim() || undefined),
820+
},
821+
{
822+
command: "altimate.skill.list.install",
823+
title: "Install",
824+
onTrigger: () => showInstall(api, filter().trim() || undefined),
825+
},
826+
]}
827+
bindings={[
828+
{ key: "ctrl+a", cmd: "altimate.skill.list.actions" },
829+
{ key: "ctrl+e", cmd: "altimate.skill.list.create" },
830+
{ key: "ctrl+i", cmd: "altimate.skill.list.install" },
831+
]}
832+
// altimate_change end
787833
/>
788834
)
789835
}

‎packages/plugin/src/tui.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,27 @@ export type TuiDialogSelectProps<Value = unknown> = {
183183
// altimate_change start — a fixed-option dialog can hide the filter box entirely
184184
renderFilter?: boolean
185185
// altimate_change end
186+
// altimate_change start — dialog-level actions: footer buttons (Tab-reachable) with
187+
// keybinds that are live INSIDE the dialog, where the dialog's own layer outranks a
188+
// plugin's global keymap layer. Mirrors the host DialogSelect `actions`/`bindings`.
189+
actions?: TuiDialogSelectAction<Value>[]
190+
bindings?: { key: string; cmd: string }[]
191+
// altimate_change end
186192
current?: Value
187193
}
188194

195+
// altimate_change start
196+
export type TuiDialogSelectAction<Value = unknown> = {
197+
/** Command name the `bindings` entries refer to. */
198+
command: string
199+
title: string
200+
side?: "left" | "right"
201+
hidden?: boolean
202+
disabled?: boolean | ((option: TuiDialogSelectOption<Value> | undefined) => boolean)
203+
onTrigger: (option: TuiDialogSelectOption<Value>) => void
204+
}
205+
// altimate_change end
206+
189207
export type TuiPromptInfo = {
190208
input: string
191209
mode?: "normal" | "shell"

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,12 @@ export function Prompt(props: PromptProps) {
593593
title: "Skills",
594594
name: "prompt.skills",
595595
category: "Prompt",
596-
slashName: "skills",
596+
// altimate_change start — `/skills` belongs to the Altimate skills browser
597+
// (`altimate.skill.list`: browse, actions, create, install). This command kept the
598+
// same slash name, so autocomplete listed two `/skills` rows and Enter took this
599+
// one — the plain selector with no actions — which is why ctrl+a never opened the
600+
// picker (#1328). The command stays in the palette without a slash name.
601+
// altimate_change end
597602
run: () => {
598603
dialog.replace(() => (
599604
<DialogSkill

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import type { TuiDialogSelectOption, TuiPluginApi, TuiPromptRef, TuiSlotProps } from "@opencode-ai/plugin/tui"
1+
// altimate_change start — TuiDialogSelectProps for the generic DialogSelect adapter
2+
import type { TuiDialogSelectOption, TuiDialogSelectProps, TuiPluginApi, TuiPromptRef, TuiSlotProps } from "@opencode-ai/plugin/tui"
3+
// altimate_change end
24
import type { TuiConfig } from "../config"
35
import type { useEvent } from "../context/event"
46
import type { usePromptRef } from "../context/prompt"
@@ -234,7 +236,10 @@ export function createTuiApiAdapters(input: Input): Omit<TuiPluginApi, "lifecycl
234236
DialogPrompt(props) {
235237
return <DialogPrompt {...props} description={props.description} />
236238
},
237-
DialogSelect(props) {
239+
// altimate_change start — generic over the option value so the dialog-level
240+
// actions below can be typed against it
241+
DialogSelect<Value>(props: TuiDialogSelectProps<Value>) {
242+
// altimate_change end
238243
return (
239244
<DialogSelect
240245
title={props.title}
@@ -248,6 +253,23 @@ export function createTuiApiAdapters(input: Input): Omit<TuiPluginApi, "lifecycl
248253
// altimate_change start — pass the filter-box switch through to the component
249254
renderFilter={props.renderFilter}
250255
// altimate_change end
256+
// altimate_change start — dialog-level actions and their in-dialog keybinds
257+
actions={props.actions?.map((action) => ({
258+
command: action.command,
259+
title: action.title,
260+
side: action.side,
261+
hidden: action.hidden,
262+
disabled:
263+
typeof action.disabled === "function"
264+
? (option: SelectOption<Value> | undefined) =>
265+
(action.disabled as (o: TuiDialogSelectOption<Value> | undefined) => boolean)(
266+
option ? pickOption(option) : undefined,
267+
)
268+
: action.disabled,
269+
onTrigger: (option: SelectOption<Value>) => action.onTrigger(pickOption(option)),
270+
}))}
271+
bindings={props.bindings}
272+
// altimate_change end
251273
current={props.current}
252274
/>
253275
)

‎packages/tui/src/ui/dialog-select.tsx‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,15 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
135135
.filter((item) => item.label),
136136
...(props.footerHints ?? []),
137137
])
138-
const actionItems = createMemo(() =>
138+
// altimate_change start — evaluated lazily rather than as an eager memo: `isActionDisabled`
139+
// reads `selected()`, which is declared further down, so a function-valued `disabled`
140+
// (the Skills browser's, #1328) threw "Cannot access 'selected' before initialization"
141+
// during setup. Every existing caller passed a boolean, which never touched `selected`.
142+
const actionItems = () =>
139143
visibleActions()
140144
.filter(isActionItem)
141-
.filter((item) => !isActionDisabled(item)),
142-
)
145+
.filter((item) => !isActionDisabled(item))
146+
// altimate_change end
143147

144148
createEffect(() => {
145149
const index = focusedAction()
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
/** @jsxImportSource @opentui/solid */
2+
// altimate_change — dialog-level actions with in-dialog keybinds (#1328).
3+
//
4+
// The Skills browser's "Actions" picker was reachable only through a plugin-registered
5+
// global keymap layer, which the open dialog's own layer (and its focused filter input)
6+
// outranked, so ctrl+a never opened it. Declared as DialogSelect `actions` with `bindings`
7+
// the chord is handled inside the dialog. This mounts a real DialogSelect in the provider
8+
// stack and presses the key.
9+
import { createDefaultOpenTuiKeymap } from "@opentui/keymap/opentui"
10+
import { testRender, useRenderer } from "@opentui/solid"
11+
import { expect, test } from "bun:test"
12+
import { onCleanup } from "solid-js"
13+
import { createTuiResolvedConfig } from "../fixture/tui-runtime"
14+
import { TestTuiContexts } from "../fixture/tui-environment"
15+
16+
async function wait(fn: () => boolean, timeout = 2000) {
17+
const start = Date.now()
18+
while (!fn()) {
19+
if (Date.now() - start > timeout) throw new Error("timed out waiting for condition")
20+
await Bun.sleep(10)
21+
}
22+
}
23+
24+
async function mount(opts: { bindings?: { key: string; cmd: string }[]; globalLayer?: boolean } = {}) {
25+
const [
26+
{ DialogProvider, useDialog },
27+
{ DialogSelect },
28+
{ ThemeProvider },
29+
{ TuiConfigProvider },
30+
{ OpencodeKeymapProvider, registerOpencodeKeymap },
31+
{ KVProvider },
32+
{ ArgsProvider },
33+
{ ToastProvider },
34+
] = await Promise.all([
35+
import("../../src/ui/dialog"),
36+
import("../../src/ui/dialog-select"),
37+
import("../../src/context/theme"),
38+
import("../../src/config"),
39+
import("../../src/keymap"),
40+
import("../../src/context/kv"),
41+
import("../../src/context/args"),
42+
import("../../src/ui/toast"),
43+
])
44+
const triggered: string[] = []
45+
46+
function Opener() {
47+
const dialog = useDialog()
48+
dialog.replace(() => (
49+
<DialogSelect
50+
title="Skills"
51+
options={[
52+
{ title: "alpha", value: "alpha" },
53+
{ title: "beta", value: "beta" },
54+
]}
55+
actions={[
56+
{
57+
command: "altimate.skill.actions",
58+
title: "Actions",
59+
// A function-valued `disabled`, as the Skills browser passes (the synthetic
60+
// Install row must not open the picker).
61+
disabled: (o) => o === undefined || o.value === "__install__",
62+
onTrigger: (o) => triggered.push(`actions:${o.value}`),
63+
},
64+
{ command: "altimate.skill.create", title: "New", onTrigger: () => triggered.push("create") },
65+
]}
66+
bindings={
67+
opts.bindings ?? [
68+
{ key: "ctrl+a", cmd: "altimate.skill.actions" },
69+
{ key: "ctrl+e", cmd: "altimate.skill.create" },
70+
]
71+
}
72+
/>
73+
))
74+
return <box />
75+
}
76+
77+
function Harness() {
78+
const renderer = useRenderer()
79+
const keymap = createDefaultOpenTuiKeymap(renderer)
80+
const resolvedConfig = createTuiResolvedConfig({ leader_timeout: 1000 })
81+
const off = registerOpencodeKeymap(keymap, renderer, resolvedConfig)
82+
onCleanup(off)
83+
// The plugin's global layer, as skill-ops.tsx registers it at plugin init: the same
84+
// command name, bound to the same chord, active everywhere.
85+
if (opts.globalLayer) {
86+
const offGlobal = keymap.registerLayer({
87+
commands: [
88+
{
89+
name: "altimate.skill.actions",
90+
title: "Skill actions",
91+
run() {
92+
triggered.push("global")
93+
},
94+
},
95+
],
96+
bindings: [{ key: "ctrl+a", cmd: "altimate.skill.actions" }],
97+
})
98+
onCleanup(offGlobal)
99+
}
100+
return (
101+
<TestTuiContexts>
102+
<OpencodeKeymapProvider keymap={keymap}>
103+
<TuiConfigProvider config={resolvedConfig}>
104+
<ArgsProvider>
105+
<KVProvider>
106+
<ToastProvider>
107+
<ThemeProvider mode="dark">
108+
<DialogProvider>
109+
<Opener />
110+
</DialogProvider>
111+
</ThemeProvider>
112+
</ToastProvider>
113+
</KVProvider>
114+
</ArgsProvider>
115+
</TuiConfigProvider>
116+
</OpencodeKeymapProvider>
117+
</TestTuiContexts>
118+
)
119+
}
120+
121+
const app = await testRender(() => <Harness />)
122+
await Bun.sleep(50)
123+
return { app, triggered }
124+
}
125+
126+
test("ctrl+a inside an open DialogSelect triggers the declared action for the highlighted row", async () => {
127+
const { app, triggered } = await mount()
128+
try {
129+
app.mockInput.pressKey("a", { ctrl: true })
130+
await wait(() => triggered.length > 0)
131+
expect(triggered).toEqual(["actions:alpha"])
132+
} finally {
133+
app.renderer.destroy()
134+
}
135+
})
136+
137+
test("the action follows the highlight: Down then ctrl+a names the second row", async () => {
138+
const { app, triggered } = await mount()
139+
try {
140+
app.mockInput.pressKey("ARROW_DOWN")
141+
await Bun.sleep(20)
142+
app.mockInput.pressKey("a", { ctrl: true })
143+
await wait(() => triggered.length > 0)
144+
expect(triggered).toEqual(["actions:beta"])
145+
} finally {
146+
app.renderer.destroy()
147+
}
148+
})
149+
150+
test("a second action with its own chord fires independently", async () => {
151+
const { app, triggered } = await mount()
152+
try {
153+
app.mockInput.pressKey("e", { ctrl: true })
154+
await wait(() => triggered.length > 0)
155+
expect(triggered).toEqual(["create"])
156+
} finally {
157+
app.renderer.destroy()
158+
}
159+
})
160+
161+
test("without a binding the chord does nothing — the test proves the binding is what carries it", async () => {
162+
const { app, triggered } = await mount({ bindings: [] })
163+
try {
164+
app.mockInput.pressKey("a", { ctrl: true })
165+
await Bun.sleep(150)
166+
expect(triggered).toEqual([])
167+
} finally {
168+
app.renderer.destroy()
169+
}
170+
})
171+
172+
test("REPRO: with the plugin's global layer registering the same command name, the dialog action is what fires", async () => {
173+
const { app, triggered } = await mount({ globalLayer: true })
174+
try {
175+
app.mockInput.pressKey("a", { ctrl: true })
176+
await Bun.sleep(200)
177+
expect(triggered).toEqual(["actions:alpha"])
178+
} finally {
179+
app.renderer.destroy()
180+
}
181+
})
182+
183+
test("the actions render as footer buttons with their chords, so the picker is discoverable without one", async () => {
184+
const { app } = await mount({ globalLayer: true })
185+
try {
186+
await app.renderOnce()
187+
const frame = app.captureCharFrame()
188+
expect(frame).toContain("Actions")
189+
expect(frame).toContain("New")
190+
expect(frame).toMatch(/ctrl\+a|\^a/i)
191+
} finally {
192+
app.renderer.destroy()
193+
}
194+
})

0 commit comments

Comments
 (0)