The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 21:00 UTC
fix(acp): ask forms with a free-text companion field show one step per question (#34867)
Julius Marminge committed
Nov 11, 2026 at 23:52 UTC
07efa5bdac56be7846270eb9fafdb75a3c19cdcd
2 files changed
+90
-6
packages/provider-acp/src/server/elicitationForm.test.ts
+53
@@ -44,4 +44,57 @@ describe("parseElicitationForm", () => {
44
},
45
);
46
}
47
+
48
+ it("asks each question once when a choice has a free-text companion field", () => {
49
+ // OMP's ask dialog follows each choice `q<n>` with a free-text `q<n>__other` field.
50
+ const ask = (question: string, header: string) => ({
51
+ type: "string",
52
+ title: question,
53
+ description: header,
54
+ oneOf: [
55
+ { const: "Yes", title: "Yes" },
56
+ { const: "No", title: "No" },
57
+ ],
58
+ });
59
+ const form = parseElicitationForm(
60
+ {
61
+ type: "object",
62
+ properties: {
63
+ q0: ask("Use Postgres for the new service?", "Database"),
64
+ q0__other: { type: "string", title: "Other (type your own)" },
65
+ q1: ask("Deploy to staging first?", "Deploy"),
66
+ q1__other: { type: "string", title: "Other (type your own)" },
67
+ },
68
+ },
69
+ "Answer 2 questions",
70
+ );
71
+ assert(form !== undefined);
72
+ assert.deepStrictEqual(
73
+ form.questions.map((question) =>
74
+ [question.header, question.question].some((text) => text.endsWith("?")),
75
+ ),
76
+ [true, true],
77
+ );
78
+ assert.deepStrictEqual(form.content({ q0: "Yes", q1: "Only on Fridays" }), {
79
+ q0: "Yes",
80
+ q1__other: "Only on Fridays",
81
+ });
82
+
83
+ // A multi-select answer can carry options and free text together, so both fields stay.
84
+ const multi = parseElicitationForm(
85
+ {
86
+ type: "object",
87
+ properties: {
88
+ q0: { type: "array", title: "Databases?", items: { anyOf: [{ const: "Postgres" }] } },
89
+ q0__other: { type: "string", title: "Other (type your own)" },
90
+ },
91
+ },
92
+ "Databases?",
93
+ );
94
+ assert(multi !== undefined);
95
+ assert.deepStrictEqual(multi.content({ q0: ["Postgres"], q0__other: "SQLite" }), {
96
+ q0: ["Postgres"],
97
+ q0__other: "SQLite",
98
+ });
99
+ });
100
});
packages/provider-acp/src/server/elicitationForm.ts
+37
-6
@@ -188,22 +188,48 @@ export function parseElicitationForm(
188
: [],
189
);
190
const fields = new Map<string, Field>();
191
- const questions: OrchestrationV2UserInputQuestion[] = [];
191
+ const parsedFields: Array<{
192
+ readonly id: string;
193
+ readonly property: Readonly<Record<string, unknown>>;
194
+ readonly options: Option[];
195
+ }> = [];
196
for (const [id, value] of Object.entries(unknownRecord(schema?.properties) ?? {})) {
197
const property = unknownRecord(value);
198
const parsed = property === undefined ? undefined : parseField(property);
199
// Question ids must survive the contract's trim to round-trip answers.
200
if (property === undefined || parsed === undefined || text(id) !== id) return undefined;
201
fields.set(id, parsed.field);
202
+ parsedFields.push({ id, property, options: parsed.options });
203
+ }
204
+ // An optional `<id>__other` text field (OMP's ask dialog) is the free-text answer to
205
+ // optional single choice `<id>`: ask them as one question and send custom text to the
206
+ // companion. Multi-select keeps both fields, since it can answer with options and text.
207
+ const companions = new Map<string, string>();
208
+ for (const [id, field] of fields) {
209
+ const companionId = `${id}__other`;
210
+ if (
211
+ field.kind === "choice" &&
212
+ fields.get(companionId)?.kind === "text" &&
213
+ !required.has(id) &&
214
+ !required.has(companionId)
215
+ ) {
216
+ companions.set(id, companionId);
217
+ }
218
+ }
219
+ const folded = new Set(companions.values());
220
+ const questions: OrchestrationV2UserInputQuestion[] = [];
221
+ for (const { id, property, options } of parsedFields) {
222
+ if (folded.has(id)) continue;
223
+ const kind = fields.get(id)?.kind;
224
questions.push({
225
id,
226
header: text(property.title) ?? `Question ${questions.length + 1}`,
227
question: text(property.description) ?? message,
202
- options: parsed.options,
203
- ...(parsed.field.kind === "text" || parsed.field.kind === "number"
228
+ options,
229
+ ...(kind === "text" || kind === "number" || companions.has(id)
230
? {}
231
: { allowCustomAnswer: false }),
206
- ...(parsed.field.kind === "multiChoice" ? { multiSelect: true } : {}),
232
+ ...(kind === "multiChoice" ? { multiSelect: true } : {}),
233
});
234
}
235
return {
@@ -211,9 +237,14 @@ export function parseElicitationForm(
237
content: (answers) => {
238
const entries: Array<[string, EffectAcpSchema.ElicitationContentValue]> = [];
239
for (const [id, field] of fields) {
214
- const typed = Object.hasOwn(answers, id) ? typedAnswer(field, answers[id]) : undefined;
240
+ if (folded.has(id)) continue;
241
+ const answer = Object.hasOwn(answers, id) ? answers[id] : undefined;
242
+ const typed = answer === undefined ? undefined : typedAnswer(field, answer);
243
+ const companionId = companions.get(id);
244
if (typed !== undefined) entries.push([id, typed]);
216
- else if (required.has(id)) return undefined;
245
+ else if (companionId !== undefined && typeof answer === "string") {
246
+ entries.push([companionId, answer]);
247
+ } else if (required.has(id)) return undefined;
248
}
249
// Own properties for every field, `__proto__` included; assigning to
250
// `{}` would hit its inherited setter instead.