Refuse to prompt when nothing can answer the prompt
basecamp setup --json < /dev/null hangs forever. This is the same defect class as #646, wearing huh instead of tea, on a shipped code path.
The instrument was wrong, twice
#646 removed timeline --watch as "the only reachable tea.NewProgram without a gate." That claim came from rg 'tea.NewProgram', and the grep could not see the family:
internal/tui/forms.gowrapshuh, and huh callstea.NewPrograminside its own package. Everytui.Confirm/Select/Inputis a bubbletea launcher the grep never showed.NewSetupCmd'sRunEcalledrunWizardwith no interactivity check at all, reachingtui.Confirmatwizard.go:243.
Two things turn a reached prompt into a hang rather than a failure:
- Bubble Tea does not error on a non-terminal stdin. It opens
/dev/ttyand waits on the real terminal (tea.go:590-613). Redirecting stdin cannot escape a prompt. InteractiveStdio()testedModeCharDevice, and/dev/nullis a character device. Socmd < /dev/null— exactly how an agent says "I have nothing to type" — was classified interactive.
Point 2 means a call-site gate using the old predicate would not have fixed the reported bug at all. The fix is the instrument, not another selector.
What changed
internal/stdinarg — InteractiveStdio() now asks term.IsTerminal, from the same charmbracelet/x/term that Bubble Tea itself imports (v1 tea.go:25, v2 tea.go:34), so this floor and the /dev/tty fallback it prevents cannot disagree about what a terminal is. IsPiped keeps the character-device test — it answers a different question ("is there content on stdin?"), for which /dev/null correctly reads as nothing.
New InteractivePrompt() checks stdin + stderr, because huh draws forms to stderr (form.go:112) while the picker draws to stdout. Asking about the wrong stream would let cmd 2>somewhere render an invisible question that still blocks a terminal, and would refuse cmd | less where the prompt would have worked.
internal/tui — a floor with one guarded runner per launcher: every huh form through runForm, every bubbletea program through runPicker. Both return a typed ErrNotInteractive. This covers prompts nobody has written yet, which a call-site audit cannot — the audit is what missed setup.
basecamp setup — refuses non-interactive stdio and machine-output modes with a usage error naming what does work without a terminal (setup agents, setup claude/codex, config set account_id). The gate is on the parent's RunE only: setup claude, setup codex and setup agents stay non-interactive and keep working, asserted by unit and e2e tests. Refusing machine output leaves the wizard's structured-envelope branch unreachable, so it, its two helpers, and WizardResult's json tags go with it.
chat delete — refuses before any lookup when it would reach a confirmation stdin cannot answer, naming --force. isNonInteractiveCommand is deliberately not widened: it reads stdout, never stdin, and its other callers (missingArg, noChanges) use it to choose between help and a structured error.
Tests
A structural check fails on a bubbletea launcher or huh import outside a short allowlist, and — inside an allowlisted file — on a launch outside its named runner, so a second unguarded program cannot ride in on the file's exemption.
Its import resolver is itself tested, because getting it wrong is silent. Both bubbletea modules sit at a path ending bubbletea (or bubbletea/v2) and declare package tea, so path and package name disagree. An earlier revision derived the identifier from the path, registering bubbletea while the file binds tea — every unaliased launcher walked straight past, in both modules. Nothing in the repo would have noticed, because picker.go happens to alias its import. The resolver now records each module's declared package name and honors an explicit alias over it, with all four spellings pinned.
Also: a table over every exported prompt, AST-checked for completeness, that fails if a new prompt skips the floor. A predicate matrix whose terminal/terminal row is the baseline that keeps the negative rows from holding vacuously. And e2e cases that put a real pty on stdout with /dev/null on stdin — the only shape that reproduces the original hang, and one bats cannot produce on its own since it captures stdout. Tests that used /dev/null as a terminal stand-in now open /dev/ptmx, and each floor test points the launcher's own output stream at a pty so stdin is the variable actually under test.
Verification
Every guard was checked by reverting it and confirming the test fails. Anti-hang smoke, where exit 124 would be the bug reproducing:
setup --json < /dev/null exit=1
setup --json | cat exit=1
PTY stdout + /dev/null stdin exit=1
PTY stdout, no --json, null stdin exit=1
setup agents --json exit=0
setup claude --json exit=0
setup codex --json exit=0
bin/ci green. go.mod is unchanged (charmbracelet/x/term was already a direct dependency).
Stack
Two follow-ups are stacked on this branch: the dead-TUI cleanup this makes obvious, and a --force safety change for chat delete.
Summary by cubic
Refuses to launch TUIs when nothing can answer them, preventing hangs with redirected stdio. Old behavior: huh/bubbletea opened /dev/tty and blocked; new behavior: commands require real terminals and return usage errors with hints for non-interactive alternatives.
- Stdio detection:
internal/stdinarg.InteractiveStdio()now usesgithub.com/charmbracelet/x/term; addsInteractivePrompt()(stdin+stderr) forhuhforms;IsPiped()unchanged. - TUI floor: all
huhforms,bubbleteapickers, and the spinner run through guarded runners and returntui.ErrNotInteractive;WithAutoSelectSinglestill bypasses TUIs. - Commands:
basecamp setupgates in the parentRunE, refuses non-interactive stdio and machine-output modes, and removes the wizard’s JSON envelope/helpers.chat deletefails early when stdin/stderr can’t confirm and requires--forcefor non-interactive runs.skillreportstui.ErrNotInteractiveas a usage error with a hint; real cancellations still exit 0 and stderr redirection is handled correctly. - Predicates: interactivity checks in
appctx, CLI, and resolver now require terminals (not just character devices). - Tests/docs: PTY-based e2e anti-hang coverage; AST guards prevent unsanctioned
huhimports andbubbletealaunchers;skills/basecamp-doctor/SKILL.mddirects non-interactive setups to agent-specific commands.
Migration
- Replace
basecamp setupin non-interactive contexts: usebasecamp setup agents(orbasecamp setup claude/basecamp setup codex), or set defaults withbasecamp config set account_id <id>andbasecamp config set project_id <id>. - For non-interactive deletes, pass
--forcetobasecamp chat delete. - For non-interactive skill installs, run
basecamp skill installorbasecamp skillto print the file.