Skip to content

engine: answer a TUI prompt from the banner's buttons (#131) - #148

Merged
Lexus2016 merged 1 commit into
mainfrom
feat/131-prompt-answer-buttons
Nov 16, 2026
Merged

Lexus2016 merged 1 commit into
mainfrom
feat/131-prompt-answer-buttons

Conversation

@Lexus2016

Copy link
Copy Markdown
Owner

Answer buttons on the "Claude is waiting for your answer" banner for the subscription engine. This is proposal 8 in #131: on a phone, most prompts no longer need the terminal.

What changes

  • input_needed from the poll loop now carries options and promptKey when promptOptions() finds one numbered widget: the last run 1..k in the tail, exactly one caret, 2 to 9 options. The banner renders one button per option.
  • The engine re-announces when the question changes in place. A multi-question AskUserQuestion goes Q1 → Q2 → "Submit answers" without ever leaving the awaiting state.
  • The browser sends only {type:'engine_prompt_answer', promptKey, choice}. The server refuses the answer unless that key belongs to the open prompt of a live turn. answerPrompt() then:
    • re-captures the pane through an exact tmux target (=ccs-<id>:, because a bare -t prefix-matches);
    • re-parses it;
    • types one digit it computed itself, and only if the same question is still on screen.
  • A digit that went in consumes the prompt for the rest of the turn.
    • Neither a reload nor a second window can redraw its buttons.
    • A re-announcement after a transient input_resolved arrives without options, both on the wire and in replay.
    • engine_prompt_consumed clears every watcher's banner and tab state.
    • The engine's finally reports the end of the turn separately (onPromptState(null, {turnEnded:true})), and only that edge forgets the answered keys.
  • advanced:false means the widget did not move. "Type something." opens a text field, and a checkbox only toggles. In that case the banner sends the user to the live pane.

Measured, not assumed (CLI 2.1.311)

New fixtures test/fixtures/claude-tui/askuserquestion-{multi,multi-q2,submit,single}.txt were captured from a live pane:

  • A digit selects and confirms an option.
  • After the last question, a numbered "Submit answers / Cancel" screen follows.
  • Choosing "Type something." with its digit focuses a text field; the typed text replaces the label, and Enter submits it.

Verification

  • Unit tests. test/prompt-answer.test.js (69 checks) covers:
    • the parser against all the captured screens;
    • key collisions: descriptions, labels past the display cut, distant context, and the last option's description;
    • framed dialogs;
    • the store's consume/turn-end lifecycle;
    • the server wiring;
    • answerPrompt against real tmux panes that record every byte. Stale, foreign, malformed and prefix-matched answers send nothing.
  • Render tests. test/render/prompt-buttons.test.mjs (13 tests) checks what reaches the wire, that replies are matched to their banner by key, and that a consumed prompt clears both the screen and the tab state.
  • Mutation checks. Each guard was removed in turn, and a test failed every time.
  • Full suite. TEST_PORT=4391 npm test exits 0.
  • Live run. A real server with real claude (haiku) answered a two-question AskUserQuestion entirely through these frames: Q1 → Q2 → Submit → done. A second tap with Q1's key was refused as stale.
  • Peer review. Three Consilium rounds (codex, agy). Every confirmed finding was fixed and has a regression test. Findings that were checked and rejected are listed in the PR conversation.

Not closed (also stated in CLAUDE.md)

  • Capture and send are two tmux calls. A person answering in the live pane in that same instant would move the digit to the next question.
  • Two identical prompts in a row share a key. The second one gets "Open pane" only, never a second answer.
  • Panes started before engine: a numbered draft in a named chat is not a permission prompt #147 have no CCS_NAME. They still read a numbered draft in the input box as a widget.
  • Startup screens carry no options. This is on purpose.
  • The public-tunnel rule does not apply here. That rule withholds a shell; this socket can already steer the same agent with a chat message.

Refs #131

The 'Claude is waiting' banner now offers the numbered widget's options as
buttons. Measured on CLI 2.1.311: a digit selects and confirms an option, so
one digit is a whole answer; a multi-question AskUserQuestion moves through its
questions and a numbered Submit screen without leaving the awaiting state, so
the engine re-announces when the question changes in place.

The browser sends only {promptKey, choice}. The server refuses unless that key
is the open prompt of a live turn, re-captures the pane through an exact tmux
target and types one digit it computed itself only if the same question is
still on screen. A digit that went in consumes the prompt for the turn: no
reload, second window or re-announcement brings its buttons back.

Startup screens get no buttons. Residuals stated in CLAUDE.md: capture and
send-keys are two tmux calls; identical consecutive prompts get Open pane only;
pre-#147 panes still read a numbered draft as a widget.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-16T17:13:56.705752Z f8c0a4f PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f8c0a4fc41

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread claude-interactive.js
Comment on lines +425 to +429
const text = lines.slice(from, to + 1)
.map(l => _unframe(l).replace(/^[❯➤►▶›»>](?=\s*\d{1,2}[.)]\s)/, ''))
.map(l => l.trim()).filter(Boolean);
const options = run.map(h => ({ n: h.n, label: h.label.slice(0, 200) }));
return { options, key: JSON.stringify(text) };

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep an edited free-text answer from becoming a new prompt

After choosing “Type something.” and entering a custom answer in the live pane, the typed text replaces that option’s label, changing this key even though the same question is still open. The poll loop consequently re-announces it with buttons, and the store accepts the new key because only the original key was consumed. Another window can then send an answer digit into the focused text field, modifying the user’s answer instead of selecting an option. Preserve the consumed state across free-text editing, or suppress answer buttons while that field is focused.

Useful? React with 👍 / 👎.

@Lexus2016
Lexus2016 merged commit 32fa765 into main Nov 16, 2026
3 checks passed
@Lexus2016
Lexus2016 deleted the feat/131-prompt-answer-buttons branch November 16, 2026 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant