From 970c5c958f435ef35ba405537e73e40967d39e99 Mon Sep 17 00:00:00 2001 From: Lexus2016 Date: Mon, 16 Nov 2026 09:28:31 +0100 Subject: [PATCH 1/2] engine: a numbered draft in a named chat is not a permission prompt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The widget detectors recognised the input box only by an unlabeled top rule (RULE_RE). The TUI draws a session name into that rule ("──── ─", 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. --- CLAUDE.md | 16 ++++ claude-cli.js | 15 +++- claude-interactive.js | 80 +++++++++++++---- server.js | 3 + test/fixtures/claude-tui/named-draft.txt | 40 +++++++++ test/interrupt-delivery.test.js | 4 +- test/pane-busy.test.js | 104 ++++++++++++++++++++++- 7 files changed, 238 insertions(+), 24 deletions(-) create mode 100644 test/fixtures/claude-tui/named-draft.txt diff --git a/CLAUDE.md b/CLAUDE.md index fbec1084..9420f464 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -162,6 +162,22 @@ watchdog stops declaring a blocked turn "done". The answer is typed through `/ws/terminal?session=&view=engine`, which ATTACHES a viewer to the engine's own `ccs-` pane — it never creates one, and ignores `resize`/`kill`. +**A draft in a named chat is not a widget.** `claude --name X` draws X into the input +box's top rule (`──── X ─`, captured in `test/fixtures/claude-tui/named-draft.txt`), and +`--resume` without `--name` draws whatever title an earlier `-p --name` run stored — +measured on 2.1.311, so studio panes were labeled before the engine passed a name. The +unlabeled `RULE_RE` did not see that box, so a numbered draft (`❯ 1. fix tests`) read as +a permission prompt: a false `input_needed`, a 5-minute grace, no clarification typed. +The engine now LAUNCHES with the chat's `--name` (`cleanSessionName`, shared with +`claude-cli.js`), records it as `CCS_NAME` in the tmux env, and every widget-detector +call passes it back as `{ boxLabel }`. A labeled rule is a box top ONLY when its label +equals that value — a name the studio chose, so no dialog header matches by accident; +no recorded name (an older pane, an untitled chat) is exactly the unlabeled rule. Two +more rules: the numbered detector skips only the box's OWN lines, so a draft never hides +a widget above the box; the unnumbered one still stops at a box caret, because that is +its only defence against history (tool output indented under a past `❯ prompt` reads as +a sibling option). `pane-busy.test.js` pins the cases and every server.js engine door. + **A false "busy" holds a finished turn open (#130).** Every exit of the poll loop except the idle watchdog requires `!paneBusy()`, so a pane that reads busy forever ends a turn the TUI finished long ago as a 10-minute timeout. When an input box is recognised diff --git a/claude-cli.js b/claude-cli.js index 873568a2..cb52b19b 100644 --- a/claude-cli.js +++ b/claude-cli.js @@ -216,10 +216,8 @@ class ClaudeCLI { // --name: display name visible in /resume picker, prompt box, and terminal title. // Pass the human-readable session title so power users mixing the Studio UI // with `claude --resume` in a terminal see meaningful labels instead of UUIDs. - if (typeof name === 'string') { - const cleanName = name.replace(/[\r\n\t]+/g, ' ').trim().slice(0, 100); - if (cleanName) args.push('--name', cleanName); - } + const cleanName = cleanSessionName(name); + if (cleanName) args.push('--name', cleanName); // --fork-session: branch from an existing session (requires --resume) if (forkSession && sessionId) args.push('--fork-session'); @@ -659,6 +657,15 @@ class ClaudeCLI { } } +// The value handed to `--name`. Shared with the subscription engine +// (claude-interactive.js), which both launches with it and recognises it as the label +// the TUI draws into the input box's top rule — two copies would drift apart, and a +// drifted copy silently stops recognising the box. +function cleanSessionName(name) { + return typeof name === 'string' ? name.replace(/[\r\n\t]+/g, ' ').trim().slice(0, 100) : ''; +} + module.exports = ClaudeCLI; +module.exports.cleanSessionName = cleanSessionName; module.exports.findClaudeBin = findClaudeBin; module.exports.claudeCliStatus = claudeCliStatus; diff --git a/claude-interactive.js b/claude-interactive.js index 2d5450c4..f4712455 100644 --- a/claude-interactive.js +++ b/claude-interactive.js @@ -29,7 +29,7 @@ const path = require('node:path'); const os = require('node:os'); const crypto = require('node:crypto'); -const { findClaudeBin } = require('./claude-cli'); +const { findClaudeBin, cleanSessionName } = require('./claude-cli'); const { agentsMdPreamble } = require('./agents-md'); const { seedClaudeFirstRun, SKIP_BYPASS_WARNING_SETTINGS } = require('./claude-firstrun'); // ONE definition of the socket name, imported — never a second copy of the string. @@ -261,23 +261,29 @@ function _conversationAboveInputBox(pane) { // a hook or an MCP server writing to the pane). Cost is the previous behaviour: // the turn ends on the idle watchdog. The live pane is still reachable by hand. // Both are why the caller ALSO requires the spinner to be stopped before believing it. +// +// `opts.boxLabel` is the name the engine launched `claude --name` with (see +// _inInputBox). Omitted, the input box is recognised only by an unlabeled top rule. const AWAIT_TAIL_LINES = 24; const CARET_RE = /^([❯➤►▶›»>])?\s*(\d{1,2})[.)]\s+\S/; -function paneAwaitingInput(pane) { +function paneAwaitingInput(pane, opts = {}) { if (typeof pane !== 'string' || !pane) return false; const lines = _paneLines(pane); + const label = opts && opts.boxLabel; const from = Math.max(0, lines.length - AWAIT_TAIL_LINES); let numbered = 0, caretAt = -1; for (let i = from; i < lines.length; i++) { const m = CARET_RE.exec(lines[i].trim()); if (!m) continue; + // A numbered list the user TYPED into the input box ("1. fix the tests") is not a + // widget, however much it looks like one. Only the box's own lines are skipped: a + // widget ABOVE the box still counts, so a draft can never hide a real prompt. + if (_inInputBox(lines, i, label)) continue; numbered++; if (m[1]) caretAt = i; } - // A numbered list the user TYPED into the input box ("1. fix the tests") is not a - // widget, however much it looks like one. - if (numbered >= 2 && caretAt >= 0 && !_inInputBox(lines, caretAt)) return true; - return paneAwaitingSelection(pane); + if (numbered >= 2 && caretAt >= 0) return true; + return paneAwaitingSelection(pane, opts); } // Non-blank lines, trailing space dropped, a leading box border turned into indent so @@ -292,10 +298,25 @@ function _paneLines(pane) { // would hide it — but its first framed line is a header ("☐ Color"), never the caret. // Searched over the WHOLE capture, not the tail: a long draft pushes the box's top // rule out of any fixed window. +// +// A chat launched with `--name