From aad8c1b55d86a0e1338986b49eee919e93cbc163 Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Thu, 3 Dec 2026 21:05:37 +0100 Subject: [PATCH 1/7] test: ACP form choice labels distinguish an empty value from a pair of quotes Co-authored-by: Claude Opus 5.5 --- .../acp-titled-empty-choice-label.e2e.ts | 108 ++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 scripts/scenarios/acp-titled-empty-choice-label.e2e.ts diff --git a/scripts/scenarios/acp-titled-empty-choice-label.e2e.ts b/scripts/scenarios/acp-titled-empty-choice-label.e2e.ts new file mode 100644 index 0000000000000..7d4c4fdb33318 --- /dev/null +++ b/scripts/scenarios/acp-titled-empty-choice-label.e2e.ts @@ -0,0 +1,108 @@ +// @effect-diagnostics nodeBuiltinImport:off -- The scenario stages a local Replay recording. +import * as NodeFSP from "node:fs/promises"; +import * as NodePath from "node:path"; + +import { ProviderInstanceId } from "@t3tools/contracts"; +import { expect } from "e2e"; +import * as Effect from "effect/Effect"; + +import { APP_DIR, T3_HOME } from "../e2e.config.ts"; +import { rpcClient, runPromise, test, WEB } from "./t3.ts"; + +const prompt = { kind: "request", method: "session/prompt" }; +const fixture = [ + { type: "expect_outbound", frame: prompt }, + { + type: "emit_inbound", + frame: { + kind: "request", + method: "elicitation/create", + params: { + sessionId: "demo", + mode: "form", + message: "Which value should the demo save?", + requestedSchema: { + type: "object", + properties: { + value: { + type: "string", + title: "Value", + oneOf: [ + { const: "", title: "" }, + { const: '""', title: '""' }, + ], + }, + }, + required: ["value"], + }, + }, + }, + }, + { + type: "emit_inbound", + frame: { kind: "response", method: prompt.method, result: { stopReason: "end_turn" } }, + }, +] + .map((entry) => JSON.stringify(entry)) + .join("\n"); + +test( + "An ACP form distinguishes an empty choice from a pair of quotes", + WEB, + async ({ t3, app, browser }) => { + const agent = await NodeFSP.readFile( + NodePath.join(APP_DIR, "apps/server/scripts/dev-replay-agent.ts"), + "utf8", + ); + const project = await t3.project("demo", { + "replay.ts": agent, + "dev-replay/showcase_transcript.ndjson": fixture, + }); + const instanceId = ProviderInstanceId.make("devReplay"); + const original = await runPromise( + Effect.gen(function* () { + const client = yield* rpcClient(T3_HOME, app.baseUrl ?? ""); + const settings = yield* client["server.getSettings"]({}); + const instance = settings.providerInstances[instanceId]; + if (instance === undefined) throw new Error("Replay provider is missing"); + return instance; + }).pipe(Effect.scoped), + ); + const setReplay = (instance: typeof original) => + runPromise( + Effect.gen(function* () { + const client = yield* rpcClient(T3_HOME, app.baseUrl ?? ""); + yield* client["server.updateSettings"]({ + patch: {}, + providerInstanceMutation: { operation: "upsert", instanceId, instance }, + }); + }).pipe(Effect.scoped), + ); + + try { + await setReplay({ + ...original, + config: { + source: "local", + commandPath: process.execPath, + commandArgs: [NodePath.join(project, "replay.ts")], + }, + }); + const thread = await t3.thread({ + project, + title: "Choose a value", + messages: ["Ask which value to save."], + model: "showcase", + }); + await t3.open(thread); + const labels = browser.locator( + '[data-chat-composer-form="true"] button[aria-pressed] span.text-sm.font-medium', + ); + await labels.nth(1).waitFor(); + await app.screenshot("choice-labels"); + expect(await labels.nth(0).textContent()).not.toBe(await labels.nth(1).textContent()); + } finally { + await setReplay(original); + } + }, +); From 15547851a90830a3549af91d63da8c04a62adc80 Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Thu, 3 Dec 2026 21:06:29 +0100 Subject: [PATCH 2/7] fix(acp): form choices with matching titles get distinct labels Titled choices whose labels collide, such as an empty value and a pair of quotes, now fall back to quoted values like enum choices already do. Co-authored-by: Claude Opus 5.5 --- .../src/server/elicitationForm.ts | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/packages/provider-acp/src/server/elicitationForm.ts b/packages/provider-acp/src/server/elicitationForm.ts index 2b11f37f8ec12..8d5e1dca85e1e 100644 --- a/packages/provider-acp/src/server/elicitationForm.ts +++ b/packages/provider-acp/src/server/elicitationForm.ts @@ -51,7 +51,18 @@ function choiceOptions( ): Option[] | undefined { if (!Array.isArray(entries) || entries.length === 0) return undefined; const options = entries.map(toOption); - return options.every((option) => option !== undefined) ? options : undefined; + return options.every((option) => option !== undefined) ? distinctLabels(options) : undefined; +} + +/** A label can collide with another option's label; quote every value in that case. */ +function distinctLabels(options: Option[]): Option[] { + return new Set(options.map((option) => option.label)).size === options.length + ? options + : options.map((option) => { + const label = JSON.stringify(option.value); + const description = option.description === option.label ? label : option.description; + return { ...option, label, description }; + }); } function enumOptions(entries: unknown): Option[] | undefined { @@ -68,13 +79,7 @@ function enumOptions(entries: unknown): Option[] | undefined { const label = plain !== "" && counts.get(plain) === 1 ? plain : JSON.stringify(value); return { label, description: label, value }; }); - // A quoted fallback can collide with a literal label; quote every value in that case. - return new Set(options.map((option) => option.label)).size === options.length - ? options - : options.map((option) => { - const label = JSON.stringify(option.value); - return { ...option, label, description: label }; - }); + return distinctLabels(options); } /** Titled entries (`oneOf` on strings, `anyOf` on array items) carry a title for their `const`. */ From e95c4aebe0ce67453b0b1bca9f6e9014c91e86d5 Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Thu, 3 Dec 2026 21:06:29 +0100 Subject: [PATCH 3/7] test(acp): cover colliding titled choice labels Co-authored-by: Claude Opus 5.5 --- .../src/server/elicitationForm.test.ts | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/packages/provider-acp/src/server/elicitationForm.test.ts b/packages/provider-acp/src/server/elicitationForm.test.ts index 3bb0ab52bc8b3..69975b2f4fa10 100644 --- a/packages/provider-acp/src/server/elicitationForm.test.ts +++ b/packages/provider-acp/src/server/elicitationForm.test.ts @@ -80,6 +80,41 @@ describe("parseElicitationForm", () => { assert.deepStrictEqual(form.content({ mode: "", tags: [""] }), { mode: "", tags: [""] }); }); + it("quotes titled choice values when their labels collide", () => { + const choices = [ + { const: "", title: "" }, + { const: '""', title: '""' }, + { const: "fast", title: "Fast", description: "Quick run" }, + ]; + const form = parseElicitationForm( + decodeElicitationSchema({ + type: "object", + required: ["mode", "tags"], + properties: { + mode: { type: "string", oneOf: choices }, + tags: { type: "array", items: { anyOf: choices } }, + }, + }), + "Configure this run", + ); + assert(form !== undefined); + const expected = [ + ['""', '""', ""], + ['"\\"\\""', '"\\"\\""', '""'], + ['"fast"', "Quick run", "fast"], + ]; + assert.deepStrictEqual( + form.questions.map((question) => + question.options.map(({ label, description, value }) => [label, description, value]), + ), + [expected, expected], + ); + assert.deepStrictEqual(form.content({ mode: '""', tags: ["", '""'] }), { + mode: '""', + tags: ["", '""'], + }); + }); + it("asks each question once when a choice has a free-text companion field", () => { // OMP's ask dialog follows each choice `q` with a free-text `q__other` field. const ask = (question: string, header: string) => ({ From 4d57542b56b92ef907a49202f51b15a04589e1df Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Thu, 3 Dec 2026 21:14:08 +0100 Subject: [PATCH 4/7] fix(acp): keep unique choice titles when other titles collide Only the colliding titled choices show their quoted values; every value is quoted only if that still leaves two labels alike. Co-authored-by: Claude Opus 5.5 --- .../src/server/elicitationForm.ts | 34 ++++++++++++++----- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/packages/provider-acp/src/server/elicitationForm.ts b/packages/provider-acp/src/server/elicitationForm.ts index 8d5e1dca85e1e..109fc1d73e7d3 100644 --- a/packages/provider-acp/src/server/elicitationForm.ts +++ b/packages/provider-acp/src/server/elicitationForm.ts @@ -54,15 +54,25 @@ function choiceOptions( return options.every((option) => option !== undefined) ? distinctLabels(options) : undefined; } -/** A label can collide with another option's label; quote every value in that case. */ +function hasDistinctLabels(options: ReadonlyArray