Skip to content

Commit 1250467

Browse files
committed
chore(tui): instrument the dialog input path
Two attempts at making the keys work have failed, both by reasoning about the API rather than observing it. Rather than guess a third time, trace every point where the chain can break: whether openDisplayDialog is called, whether the app slot render fires and registers the layer, whether the layer factory re-runs and what its target resolves to, whether the ref callback receives a real renderable and whether focus() succeeds, and whether each key handler runs at all. That last one is the decisive split: "handler never ran" means the layer is not receiving keys, while "handler ran and did nothing" means the state is wrong. The current guess is that the layer registers fine but its target never becomes the focused renderable, which would make it permanently inert while looking perfectly healthy in the source. Temporary. Remove once the keys are confirmed.
1 parent 3e5cd79 commit 1250467

1 file changed

Lines changed: 44 additions & 5 deletions

File tree

‎tui.tsx‎

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { appendFileSync } from "node:fs"
12
import { Plugin } from "@opencode/plugin/tui"
23
import { createEffect, createSignal, onCleanup, Show } from "solid-js"
34
import type { Renderable } from "@opentui/core"
@@ -30,6 +31,14 @@ import {
3031

3132
const PANEL = "goal"
3233

34+
/** TEMPORARY: the TUI's stdout is invisible to automated checks, so the dialog
35+
* traces to a file. Remove once the keys are confirmed working. */
36+
const trace = (...parts: unknown[]) => {
37+
try {
38+
appendFileSync("/tmp/goal-dialog-trace.log", parts.map(String).join(" ") + "\n")
39+
} catch {}
40+
}
41+
3342
const PLACEMENT_HELP: Record<Placement, string> = {
3443
panel: "full view, right side",
3544
footer: "one line under the composer",
@@ -419,6 +428,7 @@ export default Plugin.define({
419428
}
420429

421430
const openDisplayDialog = () => {
431+
trace("openDisplayDialog called")
422432
setDialogDraft({ ...display })
423433
setDialogCursor(0)
424434
context.ui.dialog.set({ size: "medium", centered: true })
@@ -428,8 +438,14 @@ export default Plugin.define({
428438
flexDirection="column"
429439
focusable
430440
ref={(element: Renderable) => {
441+
trace("ref fired; element =", element ? element.constructor.name : "null")
431442
setDialogFrame(element)
432-
element?.focus?.()
443+
try {
444+
element?.focus?.()
445+
trace("after focus(), focused =", String(element?.focused))
446+
} catch (error) {
447+
trace("focus() THREW", (error as Error).message)
448+
}
433449
}}
434450
>
435451
<text fg={palette.base}>Where should the goal be shown?</text>
@@ -452,6 +468,7 @@ export default Plugin.define({
452468
// Fires on every close, including the host's own escape handling, so
453469
// this is what guarantees the layer is never left targeted.
454470
() => {
471+
trace("dialog onClose")
455472
setDialogFrame(null)
456473
setDialogDraft(null)
457474
},
@@ -463,15 +480,34 @@ export default Plugin.define({
463480
context.ui.slot({
464481
append: "app",
465482
render: () => {
466-
context.keymap.layer(() => ({
483+
trace("app slot render fired (registering layer)")
484+
context.keymap.layer(() => {
485+
const target = dialogFrame()
486+
trace("layer factory ran;>, target ? target.constructor.name : "null")
487+
return {
467488
target: () => dialogFrame(),
468489
commands: [
469-
{ id: "goal.display.up", bind: "up", run: () => moveDialogCursor(-1) },
470-
{ id: "goal.display.down", bind: "down", run: () => moveDialogCursor(1) },
490+
{
491+
id: "goal.display.up",
492+
bind: "up",
493+
run: () => {
494+
trace("KEY up")
495+
return moveDialogCursor(-1)
496+
},
497+
},
498+
{
499+
id: "goal.display.down",
500+
bind: "down",
501+
run: () => {
502+
trace("KEY down")
503+
return moveDialogCursor(1)
504+
},
505+
},
471506
{
472507
id: "goal.display.toggle",
473508
bind: "space",
474509
run: () => {
510+
trace("KEY space; draft set?", String(dialogDraft() !== null))
475511
if (!dialogDraft()) return undefined
476512
setDialogDraft((current) => toggleDraft(current!, PLACEMENTS[dialogCursor()]))
477513
return false
@@ -481,6 +517,7 @@ export default Plugin.define({
481517
id: "goal.display.apply",
482518
bind: "enter",
483519
run: () => {
520+
trace("KEY enter")
484521
if (!dialogDraft()) return undefined
485522
void commitDialog()
486523
return false
@@ -490,13 +527,15 @@ export default Plugin.define({
490527
id: "goal.display.cancel",
491528
bind: "escape",
492529
run: () => {
530+
trace("KEY escape (ours)")
493531
if (!dialogDraft()) return undefined
494532
closeDialog()
495533
return false
496534
},
497535
},
498536
],
499-
}))
537+
}
538+
})
500539
return null
501540
},
502541
}),

0 commit comments

Comments
 (0)