Skip to content

engine: a numbered draft in a named chat is not a permission prompt - #147

Merged
Lexus2016 merged 3 commits into
mainfrom
fix/labeled-input-box-draft
Nov 16, 2026
Merged

Lexus2016 merged 3 commits into
mainfrom
fix/labeled-input-box-draft

Conversation

@Lexus2016

Copy link
Copy Markdown
Owner

Problem

_inInputBox() recognised the subscription engine's input box only by an unlabeled top rule (RULE_RE). The TUI draws a session name into that rule (──── <name> ─). In a named chat, a numbered draft typed into the box (❯ 1. fix tests / 2. run lint) therefore read as a #20 permission widget. That caused three problems:

  • a false input_needed banner;
  • the quiet-exit budget widened by CLAUDE_PROMPT_GRACE_MS (5 min);
  • pending clarifications never typed in, because the injection gate checks !paneAwaitingInput.

What I measured first (CLI 2.1.311, own tmux sessions on the default socket, Enter never sent)

  • claude --name ccs-c-probe draws ──…── ccs-c-probe ─. With 1. fix tests / 2. run lint pasted and not submitted, origin/main's paneAwaitingInput returns true on that capture. The capture is committed as test/fixtures/claude-tui/named-draft.txt, with statusline values scrubbed; rules, caret, indentation and label are byte-exact.
  • The subscription engine never passed --name (buildInteractiveCommand). The labels in studio panes come from --resume: without --name, it draws the title an earlier -p --name run stored (shown: beta due later today). With --resume … --name ccs-c-probe, it draws ccs-c-probe. So before this PR the label was not a value the engine knew.

Change

  • The engine launches with the chat's --name. cleanSessionName() is now exported from claude-cli.js and used by both local engines. The engine records the name as CCS_NAME in the tmux session env. It stays out of cfgHash, so renaming a chat does not respawn the pane, and the pane keeps the label it was spawned with.
  • Every widget-detector call reads CCS_NAME back as { boxLabel }: the startup wait, the poll's awaiting, the injection gate and the idle reaper.
  • A labeled rule counts as the box's top rule only when its label equals that launch name. RULE_RE is not widened, so a dialog under a labeled header is still a widget. With no recorded name (a pane from an older build, or an untitled chat), behaviour is exactly as before.
  • paneAwaitingInput skips only the box's own lines, and does so before counting its 24-line tail. A draft of any length can no longer hide a real widget above the box. This also turns a former missed prompt into a detection for an unlabeled box: a widget above a box that holds a numbered draft.
  • paneAwaitingSelection still stops at a box caret, now label-aware. That is its only defence against history: tool output indented under a past ❯ prompt reads as a sibling option.
  • The task runner passes name: taskBot?.label || task.title to the engine, the same expression its api branch already passes. The chat and Telegram doors spread the params they share with runCliSingle. Telegram has no name in either engine, so it is unchanged.

Tests

test/pane-busy.test.js gains 23 cases:

  • (a) a draft under the matching label is not a widget: real capture and built pane;
  • (b) no name passed: still a widget;
  • (c) mismatching label, and a near-miss label: still a widget;
  • (d) a widget above a matching box holding a numbered draft, including one longer than the tail window, and above an unlabeled box: a widget;
  • (e) a dialog framed by a labeled header rule: a widget, even when its header equals the launch name, because the first framed line is not the caret;
  • a multi-line prose draft;
  • all captured first-run and AskUserQuestion screens still read as prompts with a label set;
  • --name in the spawn command;
  • every detector call passes the options;
  • the reaper with and without a recorded name;
  • every server.js engine door.

test/interrupt-delivery.test.js: the gate pin now requires !paneAwaitingInput(pane, promptOpts).

Each guard was reverted on its own (sources backed up and restored, verified with cmp), and each mutation turns named cases red: label ignored, box not excluded, box excluded after the window, any label accepted, RULE_RE widened, gate without label, no --name, task runner without name, reaper without label, selection without label, CCS_NAME not recorded.

Targeted runs: pane-busy 52/0, claude-firstrun 49/0, engine-pane 31/0, interrupt-delivery 21/0, engine-idle-reaper 31/0, engine-spawn-cmd 21/0. I did not run the full npm test.

Residuals

  • A chat titled exactly like a labeled dialog header that sits directly above its caret would read as the box. No such dialog is known on 2.1.311.
  • Panes spawned before this change keep their stored-title label and no CCS_NAME. They behave as before until they respawn.
  • A /rename typed in the live pane, or a label the TUI truncates, falls back to the old behaviour. That is the safe direction.

The widget detectors recognised the input box only by an unlabeled top rule
(RULE_RE). The TUI draws a session name into that rule ("──── <name> ─",
captured on CLI 2.1.311), so in a named chat a numbered draft such as
"❯ 1. fix tests" / "2. run lint" read as a #20 widget: a false input_needed,
the quiet-exit budget widened by CLAUDE_PROMPT_GRACE_MS, and pending
clarifications never typed in (the injection gate checks !paneAwaitingInput).

Measured on 2.1.311: `--resume` without --name draws whatever title an
earlier `-p --name` run stored, and `--name X` replaces it with X. The
subscription engine never passed --name, so the label was not a value it
knew.

- The engine now launches with the chat's --name (cleanSessionName, shared
  with claude-cli.js), records it as CCS_NAME in the tmux env (kept out of
  cfgHash, so a rename does not respawn), and every widget-detector call
  passes it back as { boxLabel }: the startup wait, the poll, the injection
  gate and the idle reaper. The task runner passes the same name its api
  branch already does.
- A labeled rule is a box top ONLY when its label equals that launch name.
  RULE_RE stays unlabeled, so a dialog under a labeled header is still a
  widget; no recorded name means exactly the previous behaviour.
- The numbered detector skips only the box's own lines, so a draft can no
  longer hide a real widget above the box (also for an unlabeled box, where
  that used to be a missed prompt). The unnumbered detector still stops at
  a box caret: that is its only defence against history.

test/pane-busy.test.js pins the cases on a real capture
(test/fixtures/claude-tui/named-draft.txt) and on built panes, plus every
detector call site and every server.js engine door; each guard reverted on
its own turns cases red.
Address an independent review (codex) of the previous commit:

- paneAwaitingInput counted its 24-line tail BEFORE skipping the input
  box, so a labeled box holding a 26-line numbered draft pushed a real
  widget above it out of the window and the prompt was missed. Box lines
  are now skipped before they count against the tail.
- The comment and CLAUDE.md claimed no dialog header can match the launch
  name by accident. It can, if a chat is titled exactly like a labeled
  dialog header sitting directly above its caret; none is known on CLI
  2.1.311. Stated as a residual instead.
@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-16T08:33:54.870713Z 5da8e9d 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: 5da8e9df92

ℹ️ 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 +278 to 282
for (let i = lines.length - 1, seen = 0; i >= 0 && seen < AWAIT_TAIL_LINES; i--) {
if (_inInputBox(lines, i, label)) continue;
seen++;
const m = CARET_RE.exec(lines[i].trim());
if (!m) continue;

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 Distinguish historical numbered prompts from active widgets

When a previous user message starts with a numbered list (for example, ❯ 1. inspect the repo followed by 2. summarize it), skipping the current input box lets that historical caret satisfy the widget detector. A finished conversation with that history and a numbered draft in an unlabeled input box returns false before this change but true afterward. The startup check consequently waits for a nonexistent dialog and refuses to send the next message; the polling injection gate also blocks clarifications. Preserve the distinction between historical user prompts and active option lists when scanning above the draft, and add a regression case containing both a previous numbered request and a current numbered draft.

Useful? React with 👍 / 👎.

@Lexus2016
Lexus2016 merged commit 779b817 into main Nov 16, 2026
3 checks passed
@Lexus2016
Lexus2016 deleted the fix/labeled-input-box-draft branch November 16, 2026 08:49
Lexus2016 added a commit that referenced this pull request Nov 16, 2026
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.
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