diff --git a/CLAUDE.md b/CLAUDE.md index fbec108..2371195 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -162,6 +162,24 @@ 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 — the chat's title, not TUI wording (residual: a chat titled exactly +like a labeled dialog header sitting right above its caret; none is known on 2.1.311); +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, before counting its +24-line tail, so no draft hides a widget above the box, however long; 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 873568a..cb52b19 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 2d5450c..a29c6fc 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,30 @@ 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 from = Math.max(0, lines.length - AWAIT_TAIL_LINES); - let numbered = 0, caretAt = -1; - for (let i = from; i < lines.length; i++) { + const label = opts && opts.boxLabel; + // 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, and + // BEFORE the tail window is counted: a widget above the box still counts, so a + // draft — however long — can never push a real prompt out of view. + let numbered = 0, caret = false; + 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; numbered++; - if (m[1]) caretAt = i; + if (m[1]) caret = true; } - // 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 && caret) return true; + return paneAwaitingSelection(pane, opts); } // Non-blank lines, trailing space dropped, a leading box border turned into indent so @@ -292,10 +299,27 @@ 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