@devries-cameron20 / t3code-1 / commits / 11d456f6c8
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Support multi-select pending user inputs (#1797)

Julius Marminge committed Apr 6, 2026 at 16:08 UTC 11d456f6c8404be6617b7299a9db9ad5538ee061
9 files changed +398 -129
apps/server/src/provider/Layers/CodexAdapter.test.ts
+2
@@ -723,6 +723,7 @@ lifecycleLayer("CodexAdapterLive lifecycle", (it) => {
723 description: "Allow workspace writes only",
724 },
725 ],
726 + multiSelect: true,
727 },
728 ],
729 },
@@ -749,6 +750,7 @@ lifecycleLayer("CodexAdapterLive lifecycle", (it) => {
750 if (events[0]?.type === "user-input.requested") {
751 assert.equal(events[0].requestId, "req-user-input-1");
752 assert.equal(events[0].payload.questions[0]?.id, "sandbox_mode");
753 + assert.equal(events[0].payload.questions[0]?.multiSelect, true);
754 }
755
756 assert.equal(events[1]?.type, "user-input.resolved");
apps/server/src/provider/Layers/CodexAdapter.ts
+2
@@ -382,6 +382,7 @@ function toUserInputQuestions(payload: Record<string, unknown> | undefined) {
382 header,
383 question: prompt,
384 options,
385 + multiSelect: question.multiSelect === true,
386 };
387 })
388 .filter(
@@ -392,6 +393,7 @@ function toUserInputQuestions(payload: Record<string, unknown> | undefined) {
393 header: string;
394 question: string;
395 options: Array<{ label: string; description: string }>;
396 + multiSelect: boolean;
397 } => question !== undefined,
398 );
399
apps/web/src/components/ChatView.browser.tsx
+179 -33
@@ -12,6 +12,7 @@ import {
12 type ServerLifecycleWelcomePayload,
13 type ThreadId,
14 type TurnId,
15 + type UserInputQuestion,
16 WS_METHODS,
17 OrchestrationSessionStatus,
18 DEFAULT_SERVER_SETTINGS,
@@ -541,12 +542,51 @@ function createSnapshotWithLongProposedPlan(): OrchestrationReadModel {
542 };
543 }
544
544 -function createSnapshotWithPendingUserInput(): OrchestrationReadModel {
545 +function createSnapshotWithPendingUserInput(options?: {
546 + questions?: ReadonlyArray<UserInputQuestion>;
547 +}): OrchestrationReadModel {
548 const snapshot = createSnapshotForTargetUser({
549 targetMessageId: "msg-user-pending-input-target" as MessageId,
550 targetText: "question thread",
551 });
552
553 + const questions =
554 + options?.questions ??
555 + ([
556 + {
557 + id: "scope",
558 + header: "Scope",
559 + question: "What should this change cover?",
560 + options: [
561 + {
562 + label: "Tight",
563 + description: "Touch only the footer layout logic.",
564 + },
565 + {
566 + label: "Broad",
567 + description: "Also adjust the related composer controls.",
568 + },
569 + ],
570 + multiSelect: false,
571 + },
572 + {
573 + id: "risk",
574 + header: "Risk",
575 + question: "How aggressive should the imaginary plan be?",
576 + options: [
577 + {
578 + label: "Conservative",
579 + description: "Favor reliability and low-risk changes.",
580 + },
581 + {
582 + label: "Balanced",
583 + description: "Mix quick wins with one structural improvement.",
584 + },
585 + ],
586 + multiSelect: false,
587 + },
588 + ] satisfies ReadonlyArray<UserInputQuestion>);
589 +
590 return {
591 ...snapshot,
592 threads: snapshot.threads.map((thread) =>
@@ -561,38 +601,7 @@ function createSnapshotWithPendingUserInput(): OrchestrationReadModel {
601 summary: "User input requested",
602 payload: {
603 requestId: "req-browser-user-input",
564 - questions: [
565 - {
566 - id: "scope",
567 - header: "Scope",
568 - question: "What should this change cover?",
569 - options: [
570 - {
571 - label: "Tight",
572 - description: "Touch only the footer layout logic.",
573 - },
574 - {
575 - label: "Broad",
576 - description: "Also adjust the related composer controls.",
577 - },
578 - ],
579 - },
580 - {
581 - id: "risk",
582 - header: "Risk",
583 - question: "How aggressive should the imaginary plan be?",
584 - options: [
585 - {
586 - label: "Conservative",
587 - description: "Favor reliability and low-risk changes.",
588 - },
589 - {
590 - label: "Balanced",
591 - description: "Mix quick wins with one structural improvement.",
592 - },
593 - ],
594 - },
595 - ],
604 + questions,
605 },
606 turnId: null,
607 sequence: 1,
@@ -2902,6 +2911,143 @@ describe("ChatView timeline estimator parity (full app)", () => {
2911 }
2912 });
2913
2914 + it("does not trigger numeric option shortcuts while the composer is focused", async () => {
2915 + const mounted = await mountChatView({
2916 + viewport: WIDE_FOOTER_VIEWPORT,
2917 + snapshot: createSnapshotWithPendingUserInput(),
2918 + });
2919 +
2920 + try {
2921 + const composerEditor = await waitForComposerEditor();
2922 + composerEditor.focus();
2923 +
2924 + const event = new KeyboardEvent("keydown", {
2925 + key: "2",
2926 + bubbles: true,
2927 + cancelable: true,
2928 + });
2929 + composerEditor.dispatchEvent(event);
2930 + await waitForLayout();
2931 +
2932 + expect(event.defaultPrevented).toBe(false);
2933 + expect(document.body.textContent).toContain("What should this change cover?");
2934 + expect(document.body.textContent).not.toContain(
2935 + "How aggressive should the imaginary plan be?",
2936 + );
2937 + await waitForButtonByText("Next question");
2938 + } finally {
2939 + await mounted.cleanup();
2940 + }
2941 + });
2942 +
2943 + it("submits multi-select questionnaire answers as arrays", async () => {
2944 + const mounted = await mountChatView({
2945 + viewport: WIDE_FOOTER_VIEWPORT,
2946 + snapshot: createSnapshotWithPendingUserInput({
2947 + questions: [
2948 + {
2949 + id: "scope",
2950 + header: "Scope",
2951 + question: "Which areas should this change cover?",
2952 + options: [
2953 + {
2954 + label: "Server",
2955 + description: "Touch server orchestration.",
2956 + },
2957 + {
2958 + label: "Web",
2959 + description: "Touch the browser UI.",
2960 + },
2961 + ],
2962 + multiSelect: true,
2963 + },
2964 + {
2965 + id: "risk",
2966 + header: "Risk",
2967 + question: "How aggressive should the imaginary plan be?",
2968 + options: [
2969 + {
2970 + label: "Balanced",
2971 + description: "Mix quick wins with one structural improvement.",
2972 + },
2973 + ],
2974 + multiSelect: false,
2975 + },
2976 + ],
2977 + }),
2978 + resolveRpc: (body) => {
2979 + if (body._tag === ORCHESTRATION_WS_METHODS.dispatchCommand) {
2980 + return {
2981 + sequence: fixture.snapshot.snapshotSequence + 1,
2982 + };
2983 + }
2984 + return undefined;
2985 + },
2986 + });
2987 +
2988 + try {
2989 + const serverOption = await waitForButtonContainingText("Server");
2990 + serverOption.click();
2991 + await waitForLayout();
2992 +
2993 + expect(document.body.textContent).toContain("Which areas should this change cover?");
2994 +
2995 + const webOption = await waitForButtonContainingText("Web");
2996 + webOption.click();
2997 + await waitForLayout();
2998 +
2999 + expect(document.body.textContent).toContain("Which areas should this change cover?");
3000 +
3001 + const nextButton = await waitForButtonByText("Next question");
3002 + expect(nextButton.disabled).toBe(false);
3003 + nextButton.click();
3004 +
3005 + await vi.waitFor(
3006 + () => {
3007 + expect(document.body.textContent).toContain(
3008 + "How aggressive should the imaginary plan be?",
3009 + );
3010 + },
3011 + { timeout: 8_000, interval: 16 },
3012 + );
3013 +
3014 + const balancedOption = await waitForButtonContainingText("Balanced");
3015 + balancedOption.click();
3016 +
3017 + const submitButton = await waitForButtonByText("Submit answers");
3018 + expect(submitButton.disabled).toBe(false);
3019 + submitButton.click();
3020 +
3021 + await vi.waitFor(
3022 + () => {
3023 + const dispatchRequest = wsRequests.find(
3024 + (request) =>
3025 + request._tag === ORCHESTRATION_WS_METHODS.dispatchCommand &&
3026 + request.type === "thread.user-input.respond",
3027 + ) as
3028 + | {
3029 + _tag: string;
3030 + type?: string;
3031 + answers?: Record<string, unknown>;
3032 + }
3033 + | undefined;
3034 +
3035 + expect(dispatchRequest).toMatchObject({
3036 + _tag: ORCHESTRATION_WS_METHODS.dispatchCommand,
3037 + type: "thread.user-input.respond",
3038 + answers: {
3039 + scope: ["Server", "Web"],
3040 + risk: "Balanced",
3041 + },
3042 + });
3043 + },
3044 + { timeout: 8_000, interval: 16 },
3045 + );
3046 + } finally {
3047 + await mounted.cleanup();
3048 + }
3049 + });
3050 +
3051 it("keeps plan follow-up footer actions fused and aligned after a real resize", async () => {
3052 const mounted = await mountChatView({
3053 viewport: WIDE_FOOTER_VIEWPORT,
apps/web/src/components/ChatView.tsx
+12 -6
@@ -61,6 +61,7 @@ import {
61 buildPendingUserInputAnswers,
62 derivePendingUserInputProgress,
63 setPendingUserInputCustomAnswer,
64 + togglePendingUserInputOptionSelection,
65 type PendingUserInputDraftAnswer,
66 } from "../pendingUserInput";
67 import { useStore } from "../store";
@@ -3207,19 +3208,24 @@ export default function ChatView({ threadId }: ChatViewProps) {
3208 [activePendingUserInput],
3209 );
3210
3210 - const onSelectActivePendingUserInputOption = useCallback(
3211 + const onToggleActivePendingUserInputOption = useCallback(
3212 (questionId: string, optionLabel: string) => {
3213 if (!activePendingUserInput) {
3214 return;
3215 }
3216 + const question = activePendingUserInput.questions.find((entry) => entry.id === questionId);
3217 + if (!question) {
3218 + return;
3219 + }
3220 setPendingUserInputAnswersByRequestId((existing) => ({
3221 ...existing,
3222 [activePendingUserInput.requestId]: {
3223 ...existing[activePendingUserInput.requestId],
3219 - [questionId]: {
3220 - selectedOptionLabel: optionLabel,
3221 - customAnswer: "",
3222 - },
3224 + [questionId]: togglePendingUserInputOptionSelection(
3225 + question,
3226 + existing[activePendingUserInput.requestId]?.[questionId],
3227 + optionLabel,
3228 + ),
3229 },
3230 }));
3231 promptRef.current = "";
@@ -4063,7 +4069,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
4069 respondingRequestIds={respondingRequestIds}
4070 answers={activePendingDraftAnswers}
4071 questionIndex={activePendingQuestionIndex}
4066 - onSelectOption={onSelectActivePendingUserInputOption}
4072 + onToggleOption={onToggleActivePendingUserInputOption}
4073 onAdvance={onAdvanceActivePendingUserInput}
4074 />
4075 </div>
apps/web/src/components/chat/ComposerPendingUserInputPanel.tsx
+22 -20
@@ -13,7 +13,7 @@ interface PendingUserInputPanelProps {
13 respondingRequestIds: ApprovalRequestId[];
14 answers: Record<string, PendingUserInputDraftAnswer>;
15 questionIndex: number;
16 - onSelectOption: (questionId: string, optionLabel: string) => void;
16 + onToggleOption: (questionId: string, optionLabel: string) => void;
17 onAdvance: () => void;
18 }
19
@@ -22,7 +22,7 @@ export const ComposerPendingUserInputPanel = memo(function ComposerPendingUserIn
22 respondingRequestIds,
23 answers,
24 questionIndex,
25 - onSelectOption,
25 + onToggleOption,
26 onAdvance,
27 }: PendingUserInputPanelProps) {
28 if (pendingUserInputs.length === 0) return null;
@@ -36,7 +36,7 @@ export const ComposerPendingUserInputPanel = memo(function ComposerPendingUserIn
36 isResponding={respondingRequestIds.includes(activePrompt.requestId)}
37 answers={answers}
38 questionIndex={questionIndex}
39 - onSelectOption={onSelectOption}
39 + onToggleOption={onToggleOption}
40 onAdvance={onAdvance}
41 />
42 );
@@ -47,14 +47,14 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
47 isResponding,
48 answers,
49 questionIndex,
50 - onSelectOption,
50 + onToggleOption,
51 onAdvance,
52 }: {
53 prompt: PendingUserInput;
54 isResponding: boolean;
55 answers: Record<string, PendingUserInputDraftAnswer>;
56 questionIndex: number;
57 - onSelectOption: (questionId: string, optionLabel: string) => void;
57 + onToggleOption: (questionId: string, optionLabel: string) => void;
58 onAdvance: () => void;
59 }) {
60 const progress = derivePendingUserInputProgress(prompt.questions, answers, questionIndex);
@@ -70,9 +70,12 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
70 };
71 }, []);
72
73 - const selectOptionAndAutoAdvance = useCallback(
73 + const handleOptionSelection = useCallback(
74 (questionId: string, optionLabel: string) => {
75 - onSelectOption(questionId, optionLabel);
75 + onToggleOption(questionId, optionLabel);
76 + if (activeQuestion?.multiSelect) {
77 + return;
78 + }
79 if (autoAdvanceTimerRef.current !== null) {
80 window.clearTimeout(autoAdvanceTimerRef.current);
81 }
@@ -81,13 +84,12 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
84 onAdvance();
85 }, 200);
86 },
84 - [onSelectOption, onAdvance],
87 + [activeQuestion?.multiSelect, onAdvance, onToggleOption],
88 );
89
87 - // Keyboard shortcut: number keys 1-9 select corresponding option and auto-advance.
88 - // Works even when the Lexical composer (contenteditable) has focus — the composer
89 - // doubles as a custom-answer field during user input, and when it's empty the digit
90 - // keys should pick options instead of typing into the editor.
90 + // Keyboard shortcut: number keys 1-9 select corresponding options when focus is
91 + // outside editable fields. Multi-select prompts toggle options in place; single-
92 + // select prompts keep the existing auto-advance behavior.
93 useEffect(() => {
94 if (!activeQuestion || isResponding) return;
95 const handler = (event: globalThis.KeyboardEvent) => {
@@ -96,11 +98,8 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
98 if (target instanceof HTMLInputElement || target instanceof HTMLTextAreaElement) {
99 return;
100 }
99 - // If the user has started typing a custom answer in the contenteditable
100 - // composer, let digit keys pass through so they can type numbers.
101 if (target instanceof HTMLElement && target.isContentEditable) {
102 - const hasCustomText = progress.customAnswer.length > 0;
103 - if (hasCustomText) return;
102 + return;
103 }
104 const digit = Number.parseInt(event.key, 10);
105 if (Number.isNaN(digit) || digit < 1 || digit > 9) return;
@@ -109,11 +108,11 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
108 const option = activeQuestion.options[optionIndex];
109 if (!option) return;
110 event.preventDefault();
112 - selectOptionAndAutoAdvance(activeQuestion.id, option.label);
111 + handleOptionSelection(activeQuestion.id, option.label);
112 };
113 document.addEventListener("keydown", handler);
114 return () => document.removeEventListener("keydown", handler);
116 - }, [activeQuestion, isResponding, selectOptionAndAutoAdvance, progress.customAnswer.length]);
115 + }, [activeQuestion, handleOptionSelection, isResponding]);
116
117 if (!activeQuestion) {
118 return null;
@@ -134,16 +133,19 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
133 </div>
134 </div>
135 <p className="mt-1.5 text-sm text-foreground/90">{activeQuestion.question}</p>
136 + {activeQuestion.multiSelect ? (
137 + <p className="mt-1 text-xs text-muted-foreground/65">Select one or more options.</p>
138 + ) : null}
139 <div className="mt-3 space-y-1">
140 {activeQuestion.options.map((option, index) => {
139 - const isSelected = progress.selectedOptionLabel === option.label;
141 + const isSelected = progress.selectedOptionLabels.includes(option.label);
142 const shortcutKey = index < 9 ? index + 1 : null;
143 return (
144 <button
145 key={`${activeQuestion.id}:${option.label}`}
146 type="button"
147 disabled={isResponding}
146 - onClick={() => selectOptionAndAutoAdvance(activeQuestion.id, option.label)}
148 + onClick={() => handleOptionSelection(activeQuestion.id, option.label)}
149 className={cn(
150 "group flex w-full items-center gap-3 rounded-lg border px-3 py-2 text-left transition-all duration-150",
151 isSelected
apps/web/src/pendingUserInput.test.ts
+113 -55
@@ -7,57 +7,109 @@ import {
7 findFirstUnansweredPendingUserInputQuestionIndex,
8 resolvePendingUserInputAnswer,
9 setPendingUserInputCustomAnswer,
10 + togglePendingUserInputOptionSelection,
11 } from "./pendingUserInput";
12
13 +const singleSelectQuestion = {
14 + id: "scope",
15 + header: "Scope",
16 + question: "What should the plan target first?",
17 + options: [
18 + {
19 + label: "Orchestration-first",
20 + description: "Focus on orchestration first",
21 + },
22 + ],
23 + multiSelect: false,
24 +} as const;
25 +
26 +const multiSelectQuestion = {
27 + id: "areas",
28 + header: "Areas",
29 + question: "Which areas should this change cover?",
30 + options: [
31 + {
32 + label: "Server",
33 + description: "Server",
34 + },
35 + {
36 + label: "Web",
37 + description: "Web",
38 + },
39 + ],
40 + multiSelect: true,
41 +} as const;
42 +
43 describe("resolvePendingUserInputAnswer", () => {
13 - it("prefers a custom answer over a selected option", () => {
44 + it("prefers a custom answer over selected options", () => {
45 expect(
15 - resolvePendingUserInputAnswer({
16 - selectedOptionLabel: "Keep current envelope",
46 + resolvePendingUserInputAnswer(singleSelectQuestion, {
47 + selectedOptionLabels: ["Orchestration-first"],
48 customAnswer: "Keep the existing envelope for one release",
49 }),
50 ).toBe("Keep the existing envelope for one release");
51 });
52
22 - it("falls back to the selected option", () => {
53 + it("falls back to the selected option for single-select questions", () => {
54 expect(
24 - resolvePendingUserInputAnswer({
25 - selectedOptionLabel: "Scaffold only",
55 + resolvePendingUserInputAnswer(singleSelectQuestion, {
56 + selectedOptionLabels: ["Orchestration-first"],
57 }),
27 - ).toBe("Scaffold only");
58 + ).toBe("Orchestration-first");
59 + });
60 +
61 + it("returns all selected labels for multi-select questions", () => {
62 + expect(
63 + resolvePendingUserInputAnswer(multiSelectQuestion, {
64 + selectedOptionLabels: ["Server", "Web"],
65 + }),
66 + ).toEqual(["Server", "Web"]);
67 });
68
69 it("clears the preset selection when a custom answer is entered", () => {
70 expect(
71 setPendingUserInputCustomAnswer(
72 {
34 - selectedOptionLabel: "Preserve existing tags",
73 + selectedOptionLabels: ["Server", "Web"],
74 },
75 "doesn't matter",
76 ),
77 ).toEqual({
39 - selectedOptionLabel: undefined,
78 customAnswer: "doesn't matter",
79 });
80 });
81 });
82
83 +describe("togglePendingUserInputOptionSelection", () => {
84 + it("toggles options for multi-select questions", () => {
85 + expect(togglePendingUserInputOptionSelection(multiSelectQuestion, undefined, "Server")).toEqual(
86 + {
87 + customAnswer: "",
88 + selectedOptionLabels: ["Server"],
89 + },
90 + );
91 +
92 + expect(
93 + togglePendingUserInputOptionSelection(
94 + multiSelectQuestion,
95 + {
96 + selectedOptionLabels: ["Server", "Web"],
97 + },
98 + "Server",
99 + ),
100 + ).toEqual({
101 + customAnswer: "",
102 + selectedOptionLabels: ["Web"],
103 + });
104 + });
105 +});
106 +
107 describe("buildPendingUserInputAnswers", () => {
108 it("returns a canonical answer map for complete prompts", () => {
109 expect(
110 buildPendingUserInputAnswers(
111 [
50 - {
51 - id: "scope",
52 - header: "Scope",
53 - question: "What should the plan target first?",
54 - options: [
55 - {
56 - label: "Orchestration-first",
57 - description: "Focus on orchestration first",
58 - },
59 - ],
60 - },
112 + singleSelectQuestion,
113 {
114 id: "compat",
115 header: "Compat",
@@ -68,11 +120,12 @@ describe("buildPendingUserInputAnswers", () => {
120 description: "Preserve current wire format",
121 },
122 ],
123 + multiSelect: false,
124 },
125 ],
126 {
127 scope: {
75 - selectedOptionLabel: "Orchestration-first",
128 + selectedOptionLabels: ["Orchestration-first"],
129 },
130 compat: {
131 customAnswer: "Keep the current envelope for one release window",
@@ -85,41 +138,26 @@ describe("buildPendingUserInputAnswers", () => {
138 });
139 });
140
88 - it("returns null when any question is unanswered", () => {
141 + it("returns arrays for answered multi-select prompts", () => {
142 expect(
90 - buildPendingUserInputAnswers(
91 - [
92 - {
93 - id: "scope",
94 - header: "Scope",
95 - question: "What should the plan target first?",
96 - options: [
97 - {
98 - label: "Orchestration-first",
99 - description: "Focus on orchestration first",
100 - },
101 - ],
102 - },
103 - ],
104 - {},
105 - ),
106 - ).toBeNull();
143 + buildPendingUserInputAnswers([multiSelectQuestion], {
144 + areas: {
145 + selectedOptionLabels: ["Server", "Web"],
146 + },
147 + }),
148 + ).toEqual({
149 + areas: ["Server", "Web"],
150 + });
151 + });
152 +
153 + it("returns null when any question is unanswered", () => {
154 + expect(buildPendingUserInputAnswers([singleSelectQuestion], {})).toBeNull();
155 });
156 });
157
158 describe("pending user input question progress", () => {
159 const questions = [
112 - {
113 - id: "scope",
114 - header: "Scope",
115 - question: "What should the plan target first?",
116 - options: [
117 - {
118 - label: "Orchestration-first",
119 - description: "Focus on orchestration first",
120 - },
121 - ],
122 - },
160 + singleSelectQuestion,
161 {
162 id: "compat",
163 header: "Compat",
@@ -130,6 +168,7 @@ describe("pending user input question progress", () => {
168 description: "Preserve current wire format",
169 },
170 ],
171 + multiSelect: false,
172 },
173 ] as const;
174
@@ -137,7 +176,7 @@ describe("pending user input question progress", () => {
176 expect(
177 countAnsweredPendingUserInputQuestions(questions, {
178 scope: {
140 - selectedOptionLabel: "Orchestration-first",
179 + selectedOptionLabels: ["Orchestration-first"],
180 },
181 }),
182 ).toBe(1);
@@ -147,7 +186,7 @@ describe("pending user input question progress", () => {
186 expect(
187 findFirstUnansweredPendingUserInputQuestionIndex(questions, {
188 scope: {
150 - selectedOptionLabel: "Orchestration-first",
189 + selectedOptionLabels: ["Orchestration-first"],
190 },
191 }),
192 ).toBe(1);
@@ -157,7 +196,7 @@ describe("pending user input question progress", () => {
196 expect(
197 findFirstUnansweredPendingUserInputQuestionIndex(questions, {
198 scope: {
160 - selectedOptionLabel: "Orchestration-first",
199 + selectedOptionLabels: ["Orchestration-first"],
200 },
201 compat: {
202 customAnswer: "Keep it for one release window",
@@ -172,7 +211,7 @@ describe("pending user input question progress", () => {
211 questions,
212 {
213 scope: {
175 - selectedOptionLabel: "Orchestration-first",
214 + selectedOptionLabels: ["Orchestration-first"],
215 },
216 },
217 0,
@@ -180,7 +219,7 @@ describe("pending user input question progress", () => {
219 ).toMatchObject({
220 questionIndex: 0,
221 activeQuestion: questions[0],
183 - selectedOptionLabel: "Orchestration-first",
222 + selectedOptionLabels: ["Orchestration-first"],
223 customAnswer: "",
224 resolvedAnswer: "Orchestration-first",
225 answeredQuestionCount: 1,
@@ -189,4 +228,23 @@ describe("pending user input question progress", () => {
228 canAdvance: true,
229 });
230 });
231 +
232 + it("treats multi-select questions as answered when they have selected options", () => {
233 + expect(
234 + derivePendingUserInputProgress(
235 + [multiSelectQuestion],
236 + {
237 + areas: {
238 + selectedOptionLabels: ["Server", "Web"],
239 + },
240 + },
241 + 0,
242 + ),
243 + ).toMatchObject({
244 + selectedOptionLabels: ["Server", "Web"],
245 + resolvedAnswer: ["Server", "Web"],
246 + canAdvance: true,
247 + isComplete: true,
248 + });
249 + });
250 });
apps/web/src/pendingUserInput.ts
+63 -15
@@ -1,7 +1,7 @@
1 import type { UserInputQuestion } from "@t3tools/contracts";
2
3 export interface PendingUserInputDraftAnswer {
4 - selectedOptionLabel?: string;
4 + selectedOptionLabels?: string[];
5 customAnswer?: string;
6 }
7
@@ -9,9 +9,9 @@ export interface PendingUserInputProgress {
9 questionIndex: number;
10 activeQuestion: UserInputQuestion | null;
11 activeDraft: PendingUserInputDraftAnswer | undefined;
12 - selectedOptionLabel: string | undefined;
12 + selectedOptionLabels: string[];
13 customAnswer: string;
14 - resolvedAnswer: string | null;
14 + resolvedAnswer: string | string[] | null;
15 usingCustomAnswer: boolean;
16 answeredQuestionCount: number;
17 isLastQuestion: boolean;
@@ -28,38 +28,84 @@ function normalizeDraftAnswer(value: string | undefined): string | null {
28 return trimmed.length > 0 ? trimmed : null;
29 }
30
31 +function normalizeSelectedOptionLabels(value: string[] | undefined): string[] {
32 + if (!Array.isArray(value)) {
33 + return [];
34 + }
35 +
36 + const normalized = value
37 + .filter((entry): entry is string => typeof entry === "string")
38 + .map((entry) => entry.trim())
39 + .filter((entry) => entry.length > 0);
40 +
41 + return Array.from(new Set(normalized));
42 +}
43 +
44 export function resolvePendingUserInputAnswer(
45 + question: UserInputQuestion,
46 draft: PendingUserInputDraftAnswer | undefined,
33 -): string | null {
47 +): string | string[] | null {
48 const customAnswer = normalizeDraftAnswer(draft?.customAnswer);
49 if (customAnswer) {
50 return customAnswer;
51 }
52
39 - return normalizeDraftAnswer(draft?.selectedOptionLabel);
53 + const selectedOptionLabels = normalizeSelectedOptionLabels(draft?.selectedOptionLabels);
54 + if (question.multiSelect) {
55 + return selectedOptionLabels.length > 0 ? selectedOptionLabels : null;
56 + }
57 +
58 + return selectedOptionLabels[0] ?? null;
59 }
60
61 export function setPendingUserInputCustomAnswer(
62 draft: PendingUserInputDraftAnswer | undefined,
63 customAnswer: string,
64 ): PendingUserInputDraftAnswer {
46 - const selectedOptionLabel =
47 - customAnswer.trim().length > 0 ? undefined : draft?.selectedOptionLabel;
65 + const selectedOptionLabels =
66 + customAnswer.trim().length > 0
67 + ? undefined
68 + : normalizeSelectedOptionLabels(draft?.selectedOptionLabels);
69
70 return {
71 customAnswer,
51 - ...(selectedOptionLabel ? { selectedOptionLabel } : {}),
72 + ...(selectedOptionLabels && selectedOptionLabels.length > 0 ? { selectedOptionLabels } : {}),
73 + };
74 +}
75 +
76 +export function togglePendingUserInputOptionSelection(
77 + question: UserInputQuestion,
78 + draft: PendingUserInputDraftAnswer | undefined,
79 + optionLabel: string,
80 +): PendingUserInputDraftAnswer {
81 + if (question.multiSelect) {
82 + const selectedOptionLabels = normalizeSelectedOptionLabels(draft?.selectedOptionLabels);
83 + const nextSelectedOptionLabels = selectedOptionLabels.includes(optionLabel)
84 + ? selectedOptionLabels.filter((label) => label !== optionLabel)
85 + : [...selectedOptionLabels, optionLabel];
86 +
87 + return {
88 + customAnswer: "",
89 + ...(nextSelectedOptionLabels.length > 0
90 + ? { selectedOptionLabels: nextSelectedOptionLabels }
91 + : {}),
92 + };
93 + }
94 +
95 + return {
96 + customAnswer: "",
97 + selectedOptionLabels: [optionLabel],
98 };
99 }
100
101 export function buildPendingUserInputAnswers(
102 questions: ReadonlyArray<UserInputQuestion>,
103 draftAnswers: Record<string, PendingUserInputDraftAnswer>,
58 -): Record<string, string> | null {
59 - const answers: Record<string, string> = {};
104 +): Record<string, string | string[]> | null {
105 + const answers: Record<string, string | string[]> = {};
106
107 for (const question of questions) {
62 - const answer = resolvePendingUserInputAnswer(draftAnswers[question.id]);
108 + const answer = resolvePendingUserInputAnswer(question, draftAnswers[question.id]);
109 if (!answer) {
110 return null;
111 }
@@ -74,7 +120,7 @@ export function countAnsweredPendingUserInputQuestions(
120 draftAnswers: Record<string, PendingUserInputDraftAnswer>,
121 ): number {
122 return questions.reduce((count, question) => {
77 - return resolvePendingUserInputAnswer(draftAnswers[question.id]) ? count + 1 : count;
123 + return resolvePendingUserInputAnswer(question, draftAnswers[question.id]) ? count + 1 : count;
124 }, 0);
125 }
126
@@ -83,7 +129,7 @@ export function findFirstUnansweredPendingUserInputQuestionIndex(
129 draftAnswers: Record<string, PendingUserInputDraftAnswer>,
130 ): number {
131 const unansweredIndex = questions.findIndex(
86 - (question) => !resolvePendingUserInputAnswer(draftAnswers[question.id]),
132 + (question) => !resolvePendingUserInputAnswer(question, draftAnswers[question.id]),
133 );
134
135 return unansweredIndex === -1 ? Math.max(questions.length - 1, 0) : unansweredIndex;
@@ -98,7 +144,9 @@ export function derivePendingUserInputProgress(
144 questions.length === 0 ? 0 : Math.max(0, Math.min(questionIndex, questions.length - 1));
145 const activeQuestion = questions[normalizedQuestionIndex] ?? null;
146 const activeDraft = activeQuestion ? draftAnswers[activeQuestion.id] : undefined;
101 - const resolvedAnswer = resolvePendingUserInputAnswer(activeDraft);
147 + const resolvedAnswer = activeQuestion
148 + ? resolvePendingUserInputAnswer(activeQuestion, activeDraft)
149 + : null;
150 const customAnswer = activeDraft?.customAnswer ?? "";
151 const answeredQuestionCount = countAnsweredPendingUserInputQuestions(questions, draftAnswers);
152 const isLastQuestion =
@@ -108,7 +156,7 @@ export function derivePendingUserInputProgress(
156 questionIndex: normalizedQuestionIndex,
157 activeQuestion,
158 activeDraft,
111 - selectedOptionLabel: activeDraft?.selectedOptionLabel,
159 + selectedOptionLabels: normalizeSelectedOptionLabels(activeDraft?.selectedOptionLabels),
160 customAnswer,
161 resolvedAnswer,
162 usingCustomAnswer: customAnswer.trim().length > 0,
apps/web/src/session-logic.test.ts
+4
@@ -197,6 +197,7 @@ describe("derivePendingUserInputs", () => {
197 description: "Allow workspace writes only",
198 },
199 ],
200 + multiSelect: true,
201 },
202 ],
203 },
@@ -233,6 +234,7 @@ describe("derivePendingUserInputs", () => {
234 description: "Continue execution",
235 },
236 ],
237 + multiSelect: false,
238 },
239 ],
240 },
@@ -254,6 +256,7 @@ describe("derivePendingUserInputs", () => {
256 description: "Allow workspace writes only",
257 },
258 ],
259 + multiSelect: true,
260 },
261 ],
262 },
@@ -281,6 +284,7 @@ describe("derivePendingUserInputs", () => {
284 description: "Allow workspace writes only",
285 },
286 ],
287 + multiSelect: false,
288 },
289 ],
290 },
apps/web/src/session-logic.ts
+1
@@ -279,6 +279,7 @@ function parseUserInputQuestions(
279 header: question.header,
280 question: question.question,
281 options,
282 + multiSelect: question.multiSelect === true,
283 };
284 })
285 .filter((question): question is UserInputQuestion => question !== null);