Skip to content

The agent that grows with you

fix(desktop): stop silently dropping long and multi-line clarify choices

Brooklyn Nicholson056da73d0ba5
diff --git a/apps/desktop/src/store/clarify.test.ts b/apps/desktop/src/store/clarify.test.ts
index 27e2ef74295..9dccd7dfd0b 100644
--- a/apps/desktop/src/store/clarify.test.ts
+++ b/apps/desktop/src/store/clarify.test.ts
@@ -149,14 +149,20 @@ describe('normalizeChoices', () => {
expect(normalizeChoices(['a', '', 'b', ' ', 'c'])).toEqual(['a', 'b', 'c'])
})
- it('drops strings with newlines', () => {
- expect(normalizeChoices(['a', 'b\nc', 'd'])).toEqual(['a', 'd'])
+ it('keeps strings with newlines so option reasons can wrap', () => {
+ expect(normalizeChoices(['a', 'b\nc', 'd'])).toEqual(['a', 'b\nc', 'd'])
})
- it('drops strings over 200 chars', () => {
- const long = 'x'.repeat(201)
- const ok = 'y'.repeat(200)
- expect(normalizeChoices(['a', long, ok])).toEqual(['a', ok])
+ it('keeps long strings and only drops them past the abuse cap', () => {
+ const long = 'x'.repeat(1500)
+ const atCap = 'y'.repeat(8000)
+ const over = 'z'.repeat(8001)
+ expect(normalizeChoices(['a', long, atCap, over])).toEqual(['a', long, atCap])
+ })
+
+ it('measures the cap on the bare text, discounting the (Recommended) label', () => {
+ const atCap = 'x'.repeat(8000) + ' (Recommended)'
+ expect(normalizeChoices([atCap])).toEqual([atCap])
})
})
diff --git a/apps/desktop/src/store/clarify.ts b/apps/desktop/src/store/clarify.ts
index bd265a7e13c..baf8a4688f6 100644
--- a/apps/desktop/src/store/clarify.ts
+++ b/apps/desktop/src/store/clarify.ts
@@ -31,12 +31,23 @@ export const RECOMMENDED_LABEL = '(Recommended)'
export const bareChoice = (choice: string): string =>
choice.endsWith(RECOMMENDED_LABEL) ? choice.slice(0, -RECOMMENDED_LABEL.length).trim() : choice
+/**
+ * Per-choice display cap. The clarify tool enforces the same limit at the
+ * source (`tools/clarify_tool.py::MAX_CHOICE_CHARS`) and declares it in the
+ * schema, so an over-limit choice is rejected before any surface renders;
+ * this filter is the last line of defence against a stale/other producer.
+ * Not a one-line label limit — long option text wraps (`wrap-anywhere`),
+ * newlines are kept so option reasons can read as multiple lines.
+ */
+export const MAX_CHOICE_CHARS = 8000
+
/**
* Validate and normalize a choices array.
*
- * Keeps non-blank, newline-free strings of length ≤ 200; drops everything else
- * and returns an empty array when nothing usable survives — the caller then
- * falls back to a free-text answer instead of dead buttons.
+ * Keeps non-blank strings (newlines allowed) whose bare text is within
+ * MAX_CHOICE_CHARS; drops everything else and returns an empty array when
+ * nothing usable survives — the caller then falls back to a free-text
+ * answer instead of dead buttons.
*/
export function normalizeChoices(choices: unknown): string[] {
if (!Array.isArray(choices)) {
@@ -44,7 +55,7 @@ export function normalizeChoices(choices: unknown): string[] {
}
return choices.filter(
- (c): c is string => typeof c === 'string' && c.trim().length > 0 && bareChoice(c).length <= 200 && !c.includes('\n')
+ (c): c is string => typeof c === 'string' && c.trim().length > 0 && bareChoice(c).length <= MAX_CHOICE_CHARS
)
}