Skip to content

Commit 995bb3b

Browse files
sahrizviclaude
andcommitted
fix(tui): standalone New/Install, route every Skills entry to the browser, no global ctrl+g
Codex review of #1342 (gpt-5.6-sol). - `DialogSelect` refused to run any action without a highlighted row, so with a filter that matched nothing — the create-from-filter flow — ctrl+e and the New/Install footer buttons did nothing. Actions can be `standalone` (discriminated union, so every existing row-bound caller types unchanged); the plugin API and adapter carry it, and New / Install set it - The core `prompt.skills` command was still a palette row and the target of a configured `prompt_skills` keybind, both opening the plain selector. It now dispatches `altimate.skill.list` when that is registered and is hidden from the palette then, so no route lands on the selector while the browser exists - The global ctrl+g binding collided with the session route's `messages_first`; Install keeps its dialog-local chord only - `docs/configure/tools/custom.md` still said ctrl+i - Tests: standalone fires with nothing matching while the row-bound action does not; the same through the plugin API adapter (a dropped forward fails it — checked by mutation); Tab then Enter activates the focused footer button Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012Q51zFUmPg1WwtS5CrGJE6
1 parent 726a3c7 commit 995bb3b

7 files changed

Lines changed: 148 additions & 48 deletions

File tree

‎docs/docs/configure/tools/custom.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ altimate-code skill install https://github.com/owner/repo/tree/main/skills/my-sk
7373
altimate-code skill remove my-skill
7474
```
7575

76-
Or use the TUI: type `/skills`, then `ctrl+i` to install or `ctrl+a` → Remove to delete.
76+
Or use the TUI: type `/skills`, then `ctrl+g` (or the **Install** footer button) to install, or `ctrl+a` → Remove to delete.
7777

7878
### Output Conventions
7979

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -810,19 +810,23 @@ function DialogSkillList(props: { api: TuiPluginApi; onCurrent: (skill: string |
810810
title: "Actions",
811811
disabled: (option) => option === undefined || option.value === INSTALL_ACTION_VALUE,
812812
onTrigger: (item) => {
813-
if (item.value === INSTALL_ACTION_VALUE) return
813+
if (!item || item.value === INSTALL_ACTION_VALUE) return
814814
props.onCurrent(item.value)
815815
openActionPicker(api, skillMap().get(item.value), item.value, () => showList(api))
816816
},
817817
},
818+
// New and Install need no highlighted row: typing a name that matches no
819+
// installed skill and pressing ctrl+e is the create-from-filter flow.
818820
{
819821
command: "altimate.skill.list.create",
820822
title: "New",
823+
standalone: true,
821824
onTrigger: () => showCreate(api, filter().trim() || undefined),
822825
},
823826
{
824827
command: "altimate.skill.list.install",
825828
title: "Install",
829+
standalone: true,
826830
onTrigger: () => showInstall(api, filter().trim() || undefined),
827831
},
828832
]}
@@ -932,12 +936,13 @@ const tui: TuiPlugin = async (api) => {
932936
// ctrl+a -> actions · ctrl+n -> create · ctrl+i -> install.
933937
// altimate_change start — restore a default key to OPEN the skills list (pre-merge skill_list
934938
// was ctrl+i, which now collides with tab/agent-cycle; use a collision-free <leader>k instead).
935-
// Install is ctrl+g for the same reason: ctrl+i is Tab on the wire for most terminals.
939+
// Install has no global chord: ctrl+i is Tab on the wire for most terminals, and
940+
// ctrl+g is the session route's "first message". Inside the browser it is ctrl+g
941+
// (a dialog-local binding, see DialogSkillList); from anywhere else, the palette.
936942
bindings: [
937943
{ key: "<leader>k", cmd: "altimate.skill.list" },
938944
{ key: "ctrl+a", cmd: "altimate.skill.actions" },
939945
{ key: "ctrl+n", cmd: "altimate.skill.create" },
940-
{ key: "ctrl+g", cmd: "altimate.skill.install" },
941946
],
942947
// altimate_change end
943948
})

‎packages/plugin/src/tui.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,12 @@ export type TuiDialogSelectAction<Value = unknown> = {
200200
side?: "left" | "right"
201201
hidden?: boolean
202202
disabled?: boolean | ((option: TuiDialogSelectOption<Value> | undefined) => boolean)
203-
onTrigger: (option: TuiDialogSelectOption<Value>) => void
203+
/** Called with the highlighted option — or with `undefined` when `standalone` is set
204+
* and no row is highlighted (empty list, nothing matches the filter). */
205+
onTrigger: (option: TuiDialogSelectOption<Value> | undefined) => void
206+
/** The action needs no highlighted row (create, install): it fires even when the
207+
* list is empty or the filter matches nothing. */
208+
standalone?: boolean
204209
}
205210
// altimate_change end
206211

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -597,9 +597,17 @@ export function Prompt(props: PromptProps) {
597597
// (`altimate.skill.list`: browse, actions, create, install). This command kept the
598598
// same slash name, so autocomplete listed two `/skills` rows and Enter took this
599599
// 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
600+
// picker (#1328). It has no slash name now, and its other two entry points — the
601+
// palette row and a configured `prompt_skills` keybind — hand over to the browser
602+
// when it is registered, so no route lands on the plain selector while a better
603+
// one exists. Hidden from the palette then, too: two "Skills" rows invite the
604+
// wrong one.
605+
get hidden() {
606+
return keymap.getCommands({ visibility: "registered", filter: { name: "altimate.skill.list" } }).length > 0
607+
},
602608
run: () => {
609+
if (keymap.dispatchCommand("altimate.skill.list").ok) return
610+
// altimate_change end
603611
dialog.replace(() => (
604612
<DialogSkill
605613
onSelect={(skill) => {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,13 @@ export function createTuiApiAdapters(input: Input): Omit<TuiPluginApi, "lifecycl
266266
option ? pickOption(option) : undefined,
267267
)
268268
: action.disabled,
269-
onTrigger: (option: SelectOption<Value>) => action.onTrigger(pickOption(option)),
269+
standalone: true as const,
270+
onTrigger: (option: SelectOption<Value> | undefined) => {
271+
// The plugin API's shape is the row-bound one unless `standalone`; the
272+
// core gate is applied here so a plugin action without a row is not called.
273+
if (!option && !action.standalone) return
274+
action.onTrigger(option ? pickOption(option) : undefined)
275+
},
270276
}))}
271277
bindings={props.bindings}
272278
// altimate_change end

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

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@ import { getScrollAcceleration } from "../util/scroll"
2020
import { useTuiConfig } from "../config"
2121
import { formatKeyBindings, useBindings, useKeymapSelector } from "../keymap"
2222

23+
// altimate_change start — see `actions`
24+
type DialogSelectActionBase<T> = {
25+
command: string
26+
title: string
27+
side?: "left" | "right"
28+
hidden?: boolean
29+
disabled?: boolean | ((option: DialogSelectOption<T> | undefined) => boolean)
30+
}
31+
export type DialogSelectAction<T> =
32+
| (DialogSelectActionBase<T> & { standalone?: false; onTrigger: (option: DialogSelectOption<T>) => void })
33+
| (DialogSelectActionBase<T> & { standalone: true; onTrigger: (option: DialogSelectOption<T> | undefined) => void })
34+
// altimate_change end
35+
2336
export interface DialogSelectProps<T> {
2437
title: string
2538
titleView?: JSX.Element
@@ -35,14 +48,12 @@ export interface DialogSelectProps<T> {
3548
skipFilter?: boolean
3649
renderFilter?: boolean
3750
locked?: boolean
38-
actions?: {
39-
command: string
40-
title: string
41-
side?: "left" | "right"
42-
hidden?: boolean
43-
disabled?: boolean | ((option: DialogSelectOption<T> | undefined) => boolean)
44-
onTrigger: (option: DialogSelectOption<T>) => void
45-
}[]
51+
// altimate_change start — a `standalone` action needs no highlighted row (create,
52+
// install): it fires with `undefined` when the list is empty or nothing matches the
53+
// filter. The default keeps the row-bound contract every existing caller relies on,
54+
// as a discriminated union so those callers' `onTrigger` still types as row-bound.
55+
actions?: DialogSelectAction<T>[]
56+
// altimate_change end
4657
footerHints?: {
4758
title: string
4859
label: string
@@ -375,8 +386,10 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
375386
if (isActionDisabled(item)) return
376387
setStore("input", "keyboard")
377388
const option = selected()
378-
if (!option) return
379-
item.onTrigger(option)
389+
// altimate_change start — see `standalone`
390+
if (item.standalone) item.onTrigger(option)
391+
else if (option) item.onTrigger(option)
392+
// altimate_change end
380393
},
381394
})),
382395
],
@@ -438,8 +451,10 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
438451
if (!item || !isActionItem(item) || isActionDisabled(item)) return
439452
setStore("input", "keyboard")
440453
const option = selected()
441-
if (!option) return
442-
item.onTrigger(option)
454+
// altimate_change start — see `standalone`
455+
if (item.standalone) item.onTrigger(option)
456+
else if (option) item.onTrigger(option)
457+
// altimate_change end
443458
}
444459

445460
function isActionItem(item: VisibleAction): item is Action & { label: string } {

‎packages/tui/test/ui/dialog-select-actions.test.tsx‎

Lines changed: 89 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@ async function wait(fn: () => boolean, timeout = 2000) {
2121
}
2222
}
2323

24-
async function mount(opts: { bindings?: { key: string; cmd: string }[]; globalLayer?: boolean } = {}) {
24+
async function mount(
25+
opts: { bindings?: { key: string; cmd: string }[]; globalLayer?: boolean; via?: "core" | "adapter" } = {},
26+
) {
2527
const [
2628
{ DialogProvider, useDialog },
27-
{ DialogSelect },
29+
{ DialogSelect: CoreDialogSelect },
30+
{ createTuiApiAdapters },
2831
{ ThemeProvider },
2932
{ TuiConfigProvider },
3033
{ OpencodeKeymapProvider, registerOpencodeKeymap },
@@ -34,6 +37,7 @@ async function mount(opts: { bindings?: { key: string; cmd: string }[]; globalLa
3437
] = await Promise.all([
3538
import("../../src/ui/dialog"),
3639
import("../../src/ui/dialog-select"),
40+
import("../../src/plugin/adapters"),
3741
import("../../src/context/theme"),
3842
import("../../src/config"),
3943
import("../../src/keymap"),
@@ -43,34 +47,50 @@ async function mount(opts: { bindings?: { key: string; cmd: string }[]; globalLa
4347
])
4448
const triggered: string[] = []
4549

50+
// The plugin-API shape, exactly as skill-ops.tsx declares it: a function-valued
51+
// `disabled` (the synthetic Install row must not open the picker), and New / Install
52+
// `standalone` so they fire with no highlighted row.
53+
const actions = [
54+
{
55+
command: "altimate.skill.actions",
56+
title: "Actions",
57+
disabled: (o: { value: string } | undefined) => o === undefined || o.value === "__install__",
58+
onTrigger: (o: { value: string } | undefined) => triggered.push(`actions:${o?.value}`),
59+
},
60+
{ command: "altimate.skill.create", title: "New", standalone: true, onTrigger: () => triggered.push("create") },
61+
{ command: "altimate.skill.install", title: "Install", standalone: true, onTrigger: () => triggered.push("install") },
62+
]
63+
const bindings = opts.bindings ?? [
64+
{ key: "ctrl+a", cmd: "altimate.skill.actions" },
65+
{ key: "ctrl+e", cmd: "altimate.skill.create" },
66+
{ key: "ctrl+g", cmd: "altimate.skill.install" },
67+
]
68+
const options = [
69+
{ title: "alpha", value: "alpha" },
70+
{ title: "beta", value: "beta" },
71+
]
72+
4673
function Opener() {
4774
const dialog = useDialog()
75+
if (opts.via === "adapter") {
76+
// Through the plugin API adapter — the seam skill-ops.tsx really goes through —
77+
// so a dropped `actions`/`bindings`/`standalone` forward fails here. The adapter's
78+
// DialogSelect reads only its props, so the rest of the input is not needed.
79+
const api = createTuiApiAdapters({
80+
version: "0",
81+
tuiConfig: { keybinds: { gather: () => [], get: () => [] } },
82+
keymap: { registerLayer: () => () => {} },
83+
dialog,
84+
} as never)
85+
dialog.replace(() => <api.ui.DialogSelect title="Skills" options={options} actions={actions} bindings={bindings} />)
86+
return <box />
87+
}
4888
dialog.replace(() => (
49-
<DialogSelect
89+
<CoreDialogSelect
5090
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-
{ command: "altimate.skill.install", title: "Install", onTrigger: () => triggered.push("install") },
66-
]}
67-
bindings={
68-
opts.bindings ?? [
69-
{ key: "ctrl+a", cmd: "altimate.skill.actions" },
70-
{ key: "ctrl+e", cmd: "altimate.skill.create" },
71-
{ key: "ctrl+g", cmd: "altimate.skill.install" },
72-
]
73-
}
91+
options={options}
92+
actions={actions.map((a) => ({ ...a, standalone: a.standalone === true }))}
93+
bindings={bindings}
7494
/>
7595
))
7696
return <box />
@@ -198,15 +218,56 @@ test("the actions render as footer buttons with their chords, so the picker is d
198218
// Install is ctrl+g because ctrl+i is Tab on the wire for most terminals (byte 0x09), and
199219
// Tab is the footer's own key. A Tab press must move footer focus, not run Install; the
200220
// chord that runs it must be one no terminal folds into Tab. (bot review on #1342)
201-
test("Tab walks the footer and does not run Install; ctrl+g does", async () => {
221+
test("Tab walks the footer (Enter then activates the focused button) and does not run Install; ctrl+g does", async () => {
202222
const { app, triggered } = await mount()
203223
try {
204224
app.mockInput.pressKey("TAB")
205225
await Bun.sleep(150)
206226
expect(triggered).toEqual([])
227+
// Tab moved focus to the first footer button (Actions); Enter activates it.
228+
app.mockInput.pressKey("RETURN")
229+
await wait(() => triggered.length > 0)
230+
expect(triggered).toEqual(["actions:alpha"])
207231
app.mockInput.pressKey("g", { ctrl: true })
232+
await wait(() => triggered.length > 1)
233+
expect(triggered).toEqual(["actions:alpha", "install"])
234+
} finally {
235+
app.renderer.destroy()
236+
}
237+
})
238+
239+
// codex on #1342: New and Install need no highlighted row. Typing a name that matches no
240+
// installed skill and pressing ctrl+e is the create-from-filter flow, and it did nothing.
241+
test("with nothing matching the filter, ctrl+e still creates and ctrl+a (row-bound) does nothing", async () => {
242+
const { app, triggered } = await mount()
243+
try {
244+
for (const ch of "zzz") app.mockInput.pressKey(ch)
245+
await Bun.sleep(50)
246+
app.mockInput.pressKey("a", { ctrl: true })
247+
await Bun.sleep(100)
248+
expect(triggered).toEqual([])
249+
app.mockInput.pressKey("e", { ctrl: true })
250+
await wait(() => triggered.length > 0)
251+
expect(triggered).toEqual(["create"])
252+
} finally {
253+
app.renderer.destroy()
254+
}
255+
})
256+
257+
test("through the plugin API adapter: chords fire, standalone survives the mapping, row-bound gate holds", async () => {
258+
const { app, triggered } = await mount({ via: "adapter" })
259+
try {
260+
app.mockInput.pressKey("a", { ctrl: true })
208261
await wait(() => triggered.length > 0)
209-
expect(triggered).toEqual(["install"])
262+
expect(triggered).toEqual(["actions:alpha"])
263+
for (const ch of "zzz") app.mockInput.pressKey(ch)
264+
await Bun.sleep(50)
265+
app.mockInput.pressKey("a", { ctrl: true })
266+
await Bun.sleep(100)
267+
expect(triggered).toEqual(["actions:alpha"])
268+
app.mockInput.pressKey("g", { ctrl: true })
269+
await wait(() => triggered.length > 1)
270+
expect(triggered).toEqual(["actions:alpha", "install"])
210271
} finally {
211272
app.renderer.destroy()
212273
}

0 commit comments

Comments
 (0)