Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
fix(chat): cap the JOINED multi-select answer; keep focus on sent controls
review8e35027ca173
diff --git a/src/renderer/lib/chatAnswer.test.ts b/src/renderer/lib/chatAnswer.test.tsindex 869539aad..947e97862 100644--- a/src/renderer/lib/chatAnswer.test.ts+++ b/src/renderer/lib/chatAnswer.test.ts@@ -5,6 +5,8 @@ import {PLAN_CHOICES,activeAnswerCard,emptySelection,+ CHAT_ANSWER_TEXT_MAX,+ answerTooLong,planReviseAnswer,questionAnswerFrom,toggleLabel@@ -130,6 +132,28 @@ describe('questionAnswerFrom — UI selection → the structured answer core valexpect(questionAnswerFrom([SINGLE], sel)).toBeNull()expect(questionAnswerFrom([FREE], emptySelection([FREE]))).toBeNull()})+ it('the JOINED multi-select + Other text is what the cap applies to (core refuses past it)', () => {+ const sel = emptySelection([MULTI])+ sel[0].labels = ['Desktop', 'Server']+ sel[0].other = true+ // The typed text alone fits; "Desktop, Server, " pushes the joined answer over the cap.+ sel[0].otherText = 'x'.repeat(CHAT_ANSWER_TEXT_MAX - 5)+ expect(questionAnswerFrom([MULTI], sel)).toBeNull()+ expect(answerTooLong([MULTI], sel)).toBe('Which surfaces?')+ // Just under: sent, and nothing is flagged.+ sel[0].otherText = 'x'.repeat(CHAT_ANSWER_TEXT_MAX - 'Desktop, Server, '.length)+ expect(questionAnswerFrom([MULTI], sel)).not.toBeNull()+ expect(answerTooLong([MULTI], sel)).toBeNull()+ })++ it('a single-choice "Other" over the cap is flagged too', () => {+ const sel = emptySelection([SINGLE])+ sel[0].other = true+ sel[0].otherText = 'y'.repeat(CHAT_ANSWER_TEXT_MAX + 1)+ expect(questionAnswerFrom([SINGLE], sel)).toBeNull()+ expect(answerTooLong([SINGLE], sel)).toBe('Pick one?')+ })+it('a label that is not one of the question\'s options is never sent', () => {const sel = emptySelection([SINGLE])sel[0].labels = ['Z']diff --git a/src/renderer/lib/chatAnswer.ts b/src/renderer/lib/chatAnswer.tsindex 0f57f29b6..ba1022161 100644--- a/src/renderer/lib/chatAnswer.ts+++ b/src/renderer/lib/chatAnswer.ts@@ -76,13 +76,39 @@ export function toggleLabel(labels: readonly string[], label: string, on: boolea}/**- * The structured answer for a set of selections, or null while any question is unanswered or a- * pick is not one of that question's own options (never sent — core would refuse it anyway).+ * The free text a question's answer would carry, or null when it is not a free-text answer. ONE+ * definition, so the text that is capped is the text that is sent: on a multi choice with "Other" it+ * is the ticked labels (in option order) plus the typed text, joined with ", " — the TUI's own+ * multi-select format, and one string because core carries one free-text answer per question.+ * Core caps THAT string, so capping only the typed part let a long answer through to a refusal.+ */+function freeTextOf(q: ChatQuestion, sel: QuestionSelection): string | null {+ if (!sel.other && q.options.length > 0) return null+ const typed = sel.otherText.trim()+ const labels = q.options.map((o) => o.label).filter((l) => sel.labels.includes(l))+ return q.multiSelect && labels.length && typed ? [...labels, typed].join(', ') : typed+}++/** The first question whose free-text answer is over the shared cap (core would refuse it), or null.+ * The controls name it instead of leaving Submit disabled without a reason. */+export function answerTooLong(+ questions: readonly ChatQuestion[],+ selections: readonly QuestionSelection[]+): string | null {+ for (let i = 0; i < questions.length && i < selections.length; i++) {+ const text = freeTextOf(questions[i], selections[i])+ if (text !== null && text.length > CHAT_ANSWER_TEXT_MAX) return questions[i].question+ }+ return null+}++/**+ * The structured answer for a set of selections, or null while any question is unanswered, a pick is+ * not one of that question's own options, or a free-text answer is over the cap (never sent — core+ * would refuse it anyway).** - single choice → the label; multi choice → its labels in OPTION order;- * - "Other" (or a question with no options) → the typed text, listed in `freeText`. On a multi- * choice the ticked labels come first, joined with ", " — the TUI's own multi-select format —- * because core carries one free-text string per question, not labels plus text.+ * - "Other" (or a question with no options) → `freeTextOf`, listed in `freeText`.*/export function questionAnswerFrom(questions: readonly ChatQuestion[],@@ -97,11 +123,10 @@ export function questionAnswerFrom(const known = q.options.map((o) => o.label)if (!sel.labels.every((l) => known.includes(l))) return nullconst labels = known.filter((l) => sel.labels.includes(l))- const typed = sel.otherText.trim()- const wantsText = sel.other || q.options.length === 0- if (wantsText) {- if (!typed || typed.length > CHAT_ANSWER_TEXT_MAX) return null- answers[q.question] = q.multiSelect && labels.length ? [...labels, typed].join(', ') : typed+ const text = freeTextOf(q, sel)+ if (text !== null) {+ if (!text || text.length > CHAT_ANSWER_TEXT_MAX) return null+ answers[q.question] = textfreeText.push(q.question)} else if (q.multiSelect) {if (labels.length === 0) return nulldiff --git a/src/renderer/nodes/ChatAnswerControls.tsx b/src/renderer/nodes/ChatAnswerControls.tsxindex 03b2e5a74..87494e73b 100644--- a/src/renderer/nodes/ChatAnswerControls.tsx+++ b/src/renderer/nodes/ChatAnswerControls.tsx@@ -3,6 +3,7 @@ import type { ChatQuestion, PermissionAnswer } from '@shared/agents/permission-aimport {CHAT_ANSWER_TEXT_MAX,PLAN_CHOICES,+ answerTooLong,emptySelection,planReviseAnswer,questionAnswerFrom,@@ -21,6 +22,10 @@ import {* "Sent" cannot outlive the hold), and on a refusal (`false`: an expired hold, a ticket core has no* record of, a hook script too old to read it) or a rejected call, one line that names the terminal* path — the TUI dialog is still up and still works — with every control usable again for a retry.+ *+ * Unavailable controls are `aria-disabled` + guarded, never `disabled`: a disabled element drops+ * keyboard focus to <body> the moment the user activates it, which strands a keyboard user outside+ * the card exactly when the status line is telling them what happened.*/type SubmitStatus = 'idle' | 'sending' | 'sent' | 'error'@@ -100,13 +105,22 @@ export function PlanAnswerControls({ onSubmit, agentLabel, chip }: Common) {type="button"className={`term-chat__answer-btn${i === 0 ? ' term-chat__answer-btn--primary' : ''}`}title={c.hint}- disabled={busy}- onClick={() => void submit({ kind: 'plan', mode: c.mode })}+ aria-disabled={busy}+ onClick={() => {+ if (!busy) void submit({ kind: 'plan', mode: c.mode })+ }}>{c.label}</button>))}- <button type="button" className="term-chat__answer-btn" disabled={busy} onClick={() => setRevising(true)}>+ <button+ type="button"+ className="term-chat__answer-btn"+ aria-disabled={busy}+ onClick={() => {+ if (!busy) setRevising(true)+ }}+ >Revise…</button></div>@@ -121,7 +135,7 @@ export function PlanAnswerControls({ onSubmit, agentLabel, chip }: Common) {rows={3}maxLength={CHAT_ANSWER_TEXT_MAX}value={feedback}- disabled={busy}+ readOnly={busy}autoFocusonChange={(e) => setFeedback(e.target.value)}onKeyDown={(e) => {@@ -132,10 +146,21 @@ export function PlanAnswerControls({ onSubmit, agentLabel, chip }: Common) {}}/><div className="term-chat__answer-row">- <button type="submit" className="term-chat__answer-btn term-chat__answer-btn--primary" disabled={busy || !revise}>+ <button+ type="submit"+ className="term-chat__answer-btn term-chat__answer-btn--primary"+ aria-disabled={busy || !revise}+ >Send feedback</button>- <button type="button" className="term-chat__answer-btn" disabled={busy} onClick={() => setRevising(false)}>+ <button+ type="button"+ className="term-chat__answer-btn"+ aria-disabled={busy}+ onClick={() => {+ if (!busy) setRevising(false)+ }}+ >Cancel</button></div>@@ -150,10 +175,15 @@ export function QuestionAnswerControls({ questions, onSubmit, agentLabel, chip }const { status, submit, busy } = useSubmit(onSubmit)const [sel, setSel] = useState<QuestionSelection[]>(() => emptySelection(questions))const answer = questionAnswerFrom(questions, sel)+ const tooLong = answerTooLong(questions, sel)const baseId = useId()- const update = (i: number, next: Partial<QuestionSelection>) =>+ // Guarded rather than disabled (see the file header): after a send the choices stay focusable but+ // no longer change.+ const update = (i: number, next: Partial<QuestionSelection>) => {+ if (busy) returnsetSel((s) => s.map((x, k) => (k === i ? { ...x, ...next } : x)))+ }const onFormSubmit = (e: FormEvent) => {e.preventDefault()@@ -168,7 +198,7 @@ export function QuestionAnswerControls({ questions, onSubmit, agentLabel, chip }const otherId = `${name}-other`const noOptions = q.options.length === 0return (- <fieldset key={q.question} className="term-chat__answer-q" disabled={busy}>+ <fieldset key={q.question} className="term-chat__answer-q" aria-disabled={busy}><legend className="term-chat__answer-label">{q.question}</legend>{q.options.map((o) => (<label key={o.label} className="term-chat__answer-option">@@ -208,6 +238,7 @@ export function QuestionAnswerControls({ questions, onSubmit, agentLabel, chip }placeholder={noOptions ? 'Your answer' : 'Type another answer'}id={otherId}maxLength={CHAT_ANSWER_TEXT_MAX}+ readOnly={busy}value={s.otherText}// Typing is choosing "Other" (on a single choice it replaces the picked option).onChange={(e) =>@@ -218,10 +249,21 @@ export function QuestionAnswerControls({ questions, onSubmit, agentLabel, chip })})}<div className="term-chat__answer-row">- <button type="submit" className="term-chat__answer-btn term-chat__answer-btn--primary" disabled={busy || !answer}>+ <button+ type="submit"+ className="term-chat__answer-btn term-chat__answer-btn--primary"+ aria-disabled={busy || !answer}+ >Submit</button></div>+ {tooLong && (+ // The only incomplete state that is not visible on its own: the ticked labels plus the typed+ // "Other" text are sent as ONE answer, and it is that joined text core caps.+ <div className="term-chat__answer-hint">+ {`The answer to “${tooLong}” is too long — keep it under ${CHAT_ANSWER_TEXT_MAX.toLocaleString('en-US')} characters, labels included.`}+ </div>+ )}<StatusLine status={status} agentLabel={agentLabel} chip={chip} /></form>)diff --git a/src/renderer/nodes/ChatPanel.answers.test.tsx b/src/renderer/nodes/ChatPanel.answers.test.tsxindex acf89b927..8c1ca6ddc 100644--- a/src/renderer/nodes/ChatPanel.answers.test.tsx+++ b/src/renderer/nodes/ChatPanel.answers.test.tsx@@ -81,6 +81,8 @@ const type = async (el: HTMLInputElement | HTMLTextAreaElement, text: string): P})}const sent = (): AnswerPermissionPayload => answerPermission.mock.calls.at(-1)![0] as AnswerPermissionPayload+/** Unavailable controls are aria-disabled (they keep keyboard focus), never `disabled`. */+const off = (b: HTMLButtonElement): boolean => b.disabled || b.getAttribute('aria-disabled') === 'true'const statusText = (): string => host.querySelector('.term-chat__answer-status')?.textContent ?? ''beforeEach(() => {@@ -116,8 +118,12 @@ describe('plan card', () => {await click(button(card, 'Approve · accept edits'))expect(sent()).toEqual({ nodeId: NODE, pendingId: 'n-p-1', answer: { kind: 'plan', mode: 'acceptEdits' } })expect(statusText()).toBe('Sent — waiting for Claude Code…')- // Sent: the controls lock, so a second click cannot send a second answer.- expect(button(card, 'Approve · previous mode').disabled).toBe(true)+ // Sent: the controls lock, so a second click cannot send a second answer…+ expect(off(button(card, 'Approve · previous mode'))).toBe(true)+ await click(button(card, 'Approve · previous mode'))+ expect(answerPermission).toHaveBeenCalledTimes(1)+ // …and they stay FOCUSABLE (aria-disabled, not disabled), so keyboard focus is not dropped to <body>.+ expect(button(card, 'Approve · accept edits').disabled).toBe(false)})it('"Revise…" opens a feedback box; Send feedback sends plan-revise', async () => {@@ -125,7 +131,7 @@ describe('plan card', () => {await mount([planMsg(0)])await click(button(cards()[0], 'Revise…'))const ta = cards()[0].querySelector('textarea') as HTMLTextAreaElement- expect(button(cards()[0], 'Send feedback').disabled).toBe(true) // nothing typed yet+ expect(off(button(cards()[0], 'Send feedback'))).toBe(true) // nothing typed yetawait type(ta, ' split step 2 ')await click(button(cards()[0], 'Send feedback'))expect(sent().answer).toEqual({ kind: 'plan-revise', message: 'split step 2' })@@ -138,7 +144,7 @@ describe('plan card', () => {await click(button(cards()[0], 'Approve · previous mode'))expect(statusText()).toMatch(/^Couldn't send — answer in the terminal/)expect(statusText()).not.toContain('Sent')- expect(button(cards()[0], 'Approve · previous mode').disabled).toBe(false)+ expect(off(button(cards()[0], 'Approve · previous mode'))).toBe(false)// Retry works.await click(button(cards()[0], 'Approve · previous mode'))expect(answerPermission).toHaveBeenCalledTimes(2)@@ -202,9 +208,9 @@ describe('question card', () => {await mount([askMsg(0, [SINGLE])])expect(radio('A').type).toBe('radio')const submit = button(cards()[0], 'Submit')- expect(submit.disabled).toBe(true)+ expect(off(submit)).toBe(true)await click(radio('B'))- expect(submit.disabled).toBe(false)+ expect(off(submit)).toBe(false)await click(submit)expect(sent()).toEqual({nodeId: NODE,@@ -238,12 +244,55 @@ describe('question card', () => {await hold('waiting', held(['Pick one?', 'Which surfaces?']))await mount([askMsg(0, [SINGLE, MULTI])])await click(radio('A'))- expect(button(cards()[0], 'Submit').disabled).toBe(true)+ expect(off(button(cards()[0], 'Submit'))).toBe(true)await click(radio('Server'))await click(button(cards()[0], 'Submit'))expect(sent().answer).toEqual({ kind: 'question', answers: { 'Pick one?': 'A', 'Which surfaces?': ['Server'] } })})+ it('multi choice + "Other": ticked labels and the typed text go as ONE free-text answer', async () => {+ await hold('waiting', held(['Which surfaces?']))+ await mount([askMsg(0, [MULTI])])+ expect(radio('Other').type).toBe('checkbox')+ await click(radio('Server'))+ await type(host.querySelector('.term-chat__answer-text') as HTMLInputElement, 'Watch')+ expect(radio('Other').checked).toBe(true)+ expect(radio('Server').checked).toBe(true) // a multi choice keeps its ticks+ await click(button(cards()[0], 'Submit'))+ expect(sent().answer).toEqual({+ kind: 'question',+ answers: { 'Which surfaces?': 'Server, Watch' },+ freeText: ['Which surfaces?']+ })+ })++ it('multi choice + "Other" whose JOINED answer is over the cap: Submit is off and says why', async () => {+ const { CHAT_ANSWER_TEXT_MAX } = await import('../lib/chatAnswer')+ await hold('waiting', held(['Which surfaces?']))+ await mount([askMsg(0, [MULTI])])+ await click(radio('Desktop'))+ await click(radio('Server'))+ // The typed part alone fits the field's own maxLength; with the labels it does not.+ await type(host.querySelector('.term-chat__answer-text') as HTMLInputElement, 'x'.repeat(CHAT_ANSWER_TEXT_MAX - 5))+ expect(off(button(cards()[0], 'Submit'))).toBe(true)+ expect(host.querySelector('.term-chat__answer-hint')?.textContent).toContain('too long')+ await click(button(cards()[0], 'Submit'))+ expect(answerPermission).not.toHaveBeenCalled()+ })++ it('a question with no options is answered by its text field alone', async () => {+ const FREE: ChatQuestion = { question: 'Name?', multiSelect: false, options: [] }+ await hold('waiting', held(['Name?']))+ await mount([askMsg(0, [FREE])])+ expect(host.querySelectorAll('.term-chat__answer-option')).toHaveLength(0) // no radios, no "Other"+ const field = host.querySelector('.term-chat__answer-text') as HTMLInputElement+ expect(field.getAttribute('aria-label')).toBe('Your answer: Name?')+ expect(off(button(cards()[0], 'Submit'))).toBe(true)+ await type(field, ' Ada ')+ await click(button(cards()[0], 'Submit'))+ expect(sent().answer).toEqual({ kind: 'question', answers: { 'Name?': 'Ada' }, freeText: ['Name?'] })+ })+it('a card whose questions do not match the held request stays read-only', async () => {await hold('waiting', held(['Something else?']))await mount([askMsg(0, [SINGLE])])diff --git a/src/renderer/styles.css b/src/renderer/styles.cssindex edbaa7b8a..159ae48bc 100644--- a/src/renderer/styles.css+++ b/src/renderer/styles.css@@ -3311,7 +3311,7 @@ body,border-radius: 6px;cursor: pointer;}-.term-chat__answer-btn:hover:not(:disabled) {+.term-chat__answer-btn:hover:not([aria-disabled='true']) {background: rgba(var(--tint-rgb), 0.12);}.term-chat__answer-btn--primary {@@ -3319,14 +3319,21 @@ body,background: var(--accent);border-color: transparent;}-.term-chat__answer-btn--primary:hover:not(:disabled) {+.term-chat__answer-btn--primary:hover:not([aria-disabled='true']) {background: var(--accent);filter: brightness(1.1);}-.term-chat__answer-btn:disabled {+.term-chat__answer-btn[aria-disabled='true'] {opacity: 0.5;cursor: default;}+.term-chat__answer-q[aria-disabled='true'] {+ opacity: 0.7;+}+.term-chat__answer-hint {+ font-size: 11px;+ color: var(--danger);+}.term-chat__answer-btn:focus-visible,.term-chat__answer-option input:focus-visible {outline: 2px solid var(--accent);