The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(tui): restore the earlier answer when a batch question is re-visited
ethernetd9f98fe07109
diff --git a/ui-tui/src/components/prompts.tsx b/ui-tui/src/components/prompts.tsxindex a582d1ea418..e1d47448809 100644--- a/ui-tui/src/components/prompts.tsx+++ b/ui-tui/src/components/prompts.tsx@@ -2,6 +2,7 @@ import { Box, Text, useInput, wrapAnsi } from '@hermes/ink'import { useEffect, useState } from 'react'import { isMac } from '../lib/platform.js'+import { clarifyBatchRevisitState } from '../lib/text.js'import type { Theme } from '../theme.js'import type { ApprovalReq, ClarifyReq, ConfirmReq } from '../types.js'@@ -158,9 +159,16 @@ export function ClarifyPrompt({ cols = 80, onAnswer, onCancel, onQuestionAnswer,const [active, setActive] = useState(Math.max(0, firstUnanswered))const moveActive = (delta: number) => {- setActive(a => (a + delta + batch.length) % batch.length)- setSel(0)- setCustom('')+ const next = (active + delta + batch.length) % batch.length+ const question = batch[next]+ // Re-visit restore, same model as the CLI panel: a choice answer puts+ // the cursor back on its row; a typed answer lands on Other with the+ // text staged so Enter edits it instead of retyping.+ const restored = clarifyBatchRevisitState(question?.choices ?? [], question ? answers[question.qid] : undefined)++ setActive(next)+ setSel(restored.sel)+ setCustom(restored.custom)setTyping(false)}diff --git a/ui-tui/src/lib/text.test.ts b/ui-tui/src/lib/text.test.tsindex bbbb2a382da..6c3b87e6903 100644--- a/ui-tui/src/lib/text.test.ts+++ b/ui-tui/src/lib/text.test.ts@@ -1,6 +1,6 @@import { describe, expect, it } from 'vitest'-import { formatAbandonedClarify, formatAbandonedClarifyBatch, stripTrailingPasteNewlines } from './text.js'+import { clarifyBatchRevisitState, formatAbandonedClarify, formatAbandonedClarifyBatch, stripTrailingPasteNewlines } from './text.js'describe('stripTrailingPasteNewlines', () => {it('removes trailing newline runs from pasted text', () => {@@ -74,3 +74,22 @@ describe('formatAbandonedClarifyBatch', () => {expect(out).toContain('· One? (no answer)')})})++describe('clarifyBatchRevisitState', () => {+ it('restores the cursor onto a choice answer', () => {+ expect(clarifyBatchRevisitState(['red', 'blue'], 'blue')).toEqual({ custom: '', sel: 1 })+ })++ it('stages a typed answer on the Other row for editing', () => {+ expect(clarifyBatchRevisitState(['red', 'blue'], 'chartreuse')).toEqual({ custom: 'chartreuse', sel: 2 })+ })++ it('stages a typed answer for an open-ended question (no choices)', () => {+ expect(clarifyBatchRevisitState([], 'free text')).toEqual({ custom: 'free text', sel: 0 })+ })++ it('resets cleanly for unanswered and empty answers', () => {+ expect(clarifyBatchRevisitState(['red'], undefined)).toEqual({ custom: '', sel: 0 })+ expect(clarifyBatchRevisitState(['red'], '')).toEqual({ custom: '', sel: 0 })+ })+})diff --git a/ui-tui/src/lib/text.ts b/ui-tui/src/lib/text.tsindex b850aa7b225..003930dbe28 100644--- a/ui-tui/src/lib/text.ts+++ b/ui-tui/src/lib/text.ts@@ -384,6 +384,30 @@ export const formatAbandonedClarifyBatch = (return [`ask (${questions.length} questions)`, ...lines, ` (${reason})`].join('\n')}+/**+ * Cursor/draft restore for re-visiting an answered batch clarify question+ * (Tab/Shift-Tab): a choice answer puts the cursor back on its row; an+ * answer that matches no choice was typed via Other, so the cursor lands on+ * the Other row (index = choices.length) with the text staged for editing.+ * Unanswered questions restore to a clean cursor.+ */+export const clarifyBatchRevisitState = (+ choices: readonly string[],+ answer: string | undefined+): { custom: string; sel: number } => {+ if (answer === undefined || answer === '') {+ return { custom: '', sel: 0 }+ }++ const choiceIndex = choices.indexOf(answer)++ if (choiceIndex >= 0) {+ return { custom: '', sel: choiceIndex }+ }++ return { custom: answer, sel: choices.length > 0 ? choices.length : 0 }+}+export const flat = (r: Record<string, string[]>) => Object.values(r).flat()const COMPACT_NUMBER = new Intl.NumberFormat('en-US', { maximumFractionDigits: 1, notation: 'compact' })