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 22, 22:00 UTC
fix(acp): Droid answers no longer cancel AskUser (#20417)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
travelvector committed
Oct 20, 2026 at 13:38 UTC
4296624ddf3df6bae65909b64be8ca2ee3a1f8f2
4 files changed
+396
-25
apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts
+271
@@ -4,7 +4,11 @@ import {
4
normalizeDevinSessionUpdate,
5
normalizeDevinToolCall,
6
extractDevinSubagentUpdate,
7
+ makeAcpRegistryAdapterV2,
8
} from "@t3tools/provider-acp-registry/testing";
9
+import { AcpRegistrySettings } from "@t3tools/provider-acp-registry/settings";
10
+import { AcpRegistryCatalog } from "@t3tools/provider-acp-registry/server/AcpRegistrySupport";
11
+import { decodeAcpReplayTranscript, makeAcpReplayRuntime } from "./AcpAdapterV2.testkit.ts";
12
// @effect-diagnostics nodeBuiltinImport:off
13
import * as NodeChildProcess from "node:child_process";
14
import * as NodeFS from "node:fs";
@@ -24,6 +28,7 @@ import {
28
type OrchestrationV2ProviderThread,
29
type OrchestrationV2TurnItem,
30
type ProviderOptionDescriptor,
31
+ type ProviderUserInputAnswers,
32
} from "@t3tools/contracts";
33
import { GrokSettings } from "@t3tools/provider-grok/settings";
34
import * as HostProcess from "@t3tools/shared/HostProcess";
@@ -92,6 +97,8 @@ import {
97
type AcpAdapterV2SubagentUpdate,
98
} from "@t3tools/provider-acp/server/adapter";
99
100
+import { appendUserInputAttachmentPaths } from "../../provider/userInputAttachments.ts";
101
+
102
import { makeGrokAdapterV2, makeGrokAcpAdapterFlavor } from "@t3tools/provider-grok/testing";
103
import {
104
acpRegistryPromptFailure,
@@ -99,6 +106,7 @@ import {
106
} from "@t3tools/provider-acp-registry/testing";
107
108
const DEFAULT_GROK_SETTINGS = Schema.decodeSync(GrokSettings)({});
109
+const DROID_SETTINGS = Schema.decodeSync(AcpRegistrySettings)({ agentId: "factory-droid" });
110
111
const layerHost = TestProviderHost.layer().pipe(Layer.provide(NodeServices.layer));
112
@@ -633,6 +641,269 @@ function assertReinjectedInstructions(
641
}
642
643
describe("AcpAdapterV2", () => {
644
+ // Factory Droid 0.243.0 sends an optional text companion for every AskUser choice.
645
+ const droidChoice = {
646
+ type: "string",
647
+ title: "Format",
648
+ description: "Which reply format?",
649
+ oneOf: [
650
+ { const: "option_0", title: "JSON" },
651
+ { const: "option_1", title: "Plain text" },
652
+ { const: "other", title: "Other answer" },
653
+ ],
654
+ };
655
+ const droidSchema = {
656
+ type: "object",
657
+ properties: {
658
+ question_1: droidChoice,
659
+ question_1_other: { type: "string" },
660
+ question_2: { ...droidChoice, title: "Alternative" },
661
+ question_2_other: { type: "string" },
662
+ },
663
+ required: ["question_1", "question_2"],
664
+ };
665
+ const droidQuestions = ["question_1", "question_2"].map((id, index) => ({
666
+ id,
667
+ header: index === 0 ? "Format" : "Alternative",
668
+ question: "Which reply format?",
669
+ options: [
670
+ { label: "JSON", description: "JSON", value: "option_0" },
671
+ { label: "Plain text", description: "Plain text", value: "option_1" },
672
+ ],
673
+ }));
674
+
675
+ it.live.each([
676
+ {
677
+ scenario: "preserves selected IDs and encodes custom answers",
678
+ schema: droidSchema,
679
+ questions: droidQuestions,
680
+ answers: { question_1: "option_1", question_2: "Markdown" },
681
+ result: {
682
+ action: "accept",
683
+ content: { question_1: "option_1", question_2: "other", question_2_other: "Markdown" },
684
+ },
685
+ },
686
+ {
687
+ scenario: "preserves selected labels and attachment paths in custom answers",
688
+ schema: droidSchema,
689
+ questions: droidQuestions,
690
+ withAttachments: true,
691
+ answers: {
692
+ question_1: "option_1",
693
+ question_2: "option_1\n\nAttached notes: keep this custom text",
694
+ },
695
+ result: (directory: string) => ({
696
+ action: "accept",
697
+ content: {
698
+ question_1: "other",
699
+ question_1_other: `Plain text\n\nAttached image "shot.png": ${JSON.stringify(NodePath.join(directory, "droid-shot.png"))}\nAttached file "spec.txt": ${JSON.stringify(NodePath.join(directory, "droid-spec.txt"))}`,
700
+ question_2: "other",
701
+ question_2_other: "option_1\n\nAttached notes: keep this custom text",
702
+ },
703
+ }),
704
+ },
705
+ {
706
+ scenario: "cancels without accepting answers",
707
+ schema: droidSchema,
708
+ questions: droidQuestions,
709
+ answers: undefined,
710
+ result: { action: "cancel" },
711
+ },
712
+ {
713
+ scenario: "falls back for an unrelated form",
714
+ schema: { type: "object", properties: { name: { type: "string" } } },
715
+ questions: [{ id: "name", header: "Question 1", question: "Your answer?", options: [] }],
716
+ answers: { name: "Ada" },
717
+ result: { action: "accept", content: { name: "Ada" } },
718
+ },
719
+ {
720
+ scenario: "falls back when the companion field is missing",
721
+ schema: {
722
+ type: "object",
723
+ properties: { question_1: droidChoice },
724
+ required: ["question_1"],
725
+ },
726
+ questions: [
727
+ { id: "question_1", header: "Format", question: "Which reply format?", options: [] },
728
+ ],
729
+ answers: { question_1: "Markdown" },
730
+ result: { action: "accept", content: { question_1: "Markdown" } },
731
+ },
732
+ ])("Droid elicitation $scenario", ({ schema, questions, answers, result, withAttachments }) =>
733
+ Effect.gen(function* () {
734
+ const fileSystem = yield* FileSystem.FileSystem;
735
+ const path = yield* Path.Path;
736
+ const directory = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-droid-form-" });
737
+ const statusPath = path.join(directory, "status.json");
738
+ const expectedResult = typeof result === "function" ? result(directory) : result;
739
+ let preparedAnswers: ProviderUserInputAnswers | undefined = answers;
740
+ if (withAttachments && answers !== undefined) {
741
+ yield* fileSystem.writeFileString(path.join(directory, "droid-shot.png"), "image");
742
+ yield* fileSystem.writeFileString(path.join(directory, "droid-spec.txt"), "spec");
743
+ preparedAnswers = yield* appendUserInputAttachmentPaths({
744
+ answers,
745
+ attachmentsDir: directory,
746
+ attachmentsByQuestionId: {
747
+ question_1: [
748
+ {
749
+ type: "image",
750
+ id: "droid-shot",
751
+ name: "shot.png",
752
+ mimeType: "image/png",
753
+ sizeBytes: 5,
754
+ },
755
+ {
756
+ type: "file",
757
+ id: "droid-spec",
758
+ name: "spec.txt",
759
+ mimeType: "text/plain",
760
+ sizeBytes: 4,
761
+ },
762
+ ],
763
+ },
764
+ });
765
+ }
766
+ const driver = ProviderDriverKind.make("acpRegistry");
767
+ const transcript = yield* decodeAcpReplayTranscript(
768
+ {
769
+ provider: driver,
770
+ protocol: "acp.ndjson-jsonrpc",
771
+ version: "1",
772
+ scenario: "droid-form",
773
+ entries: [
774
+ {
775
+ type: "expect_outbound",
776
+ frame: { kind: "request", method: "initialize", params: "<any>" },
777
+ },
778
+ {
779
+ type: "emit_inbound",
780
+ frame: {
781
+ kind: "response",
782
+ method: "initialize",
783
+ result: { protocolVersion: 1, agentCapabilities: {}, authMethods: [] },
784
+ },
785
+ },
786
+ {
787
+ type: "expect_outbound",
788
+ frame: { kind: "request", method: "session/new", params: "<any>" },
789
+ },
790
+ {
791
+ type: "emit_inbound",
792
+ frame: {
793
+ kind: "response",
794
+ method: "session/new",
795
+ result: { sessionId: "droid-session" },
796
+ },
797
+ },
798
+ {
799
+ type: "expect_outbound",
800
+ frame: { kind: "request", method: "session/prompt", params: "<any>" },
801
+ },
802
+ {
803
+ type: "emit_inbound",
804
+ frame: {
805
+ kind: "request",
806
+ method: "elicitation/create",
807
+ params: {
808
+ mode: "form",
809
+ sessionId: "droid-session",
810
+ message: "Your answer?",
811
+ requestedSchema: schema,
812
+ },
813
+ },
814
+ },
815
+ {
816
+ type: "expect_outbound",
817
+ frame: {
818
+ kind: "response",
819
+ method: "elicitation/create",
820
+ result: expectedResult,
821
+ },
822
+ },
823
+ {
824
+ type: "emit_inbound",
825
+ frame: {
826
+ kind: "response",
827
+ method: "session/prompt",
828
+ result: { stopReason: "end_turn" },
829
+ },
830
+ },
831
+ { type: "runtime_exit", status: "success" },
832
+ ],
833
+ },
834
+ driver,
835
+ );
836
+ const instanceId = ProviderInstanceId.make("droid-form-test");
837
+ const adapter = yield* makeAcpRegistryAdapterV2({
838
+ instanceId,
839
+ selfInvocation: yield* resolveSelfInvocation(),
840
+ settings: DROID_SETTINGS,
841
+ environment: {},
842
+ makeRuntime: makeAcpReplayRuntime({
843
+ transcript,
844
+ statusPath,
845
+ fileSystem,
846
+ scriptPath: yield* path.fromFileUrl(
847
+ new URL("../../../scripts/acp-replay-agent.ts", import.meta.url),
848
+ ),
849
+ childProcessSpawner: yield* ChildProcessSpawner.ChildProcessSpawner,
850
+ }),
851
+ }).pipe(
852
+ Effect.provide(
853
+ Layer.mock(AcpRegistryCatalog)({ resolve: () => Effect.die("runtime is injected") }),
854
+ ),
855
+ );
856
+ const threadId = ThreadId.make("droid-form-thread");
857
+ const modelSelection = { instanceId, model: "default" } as const;
858
+ const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
859
+ runtimeMode: "approval-required",
860
+ interactionMode: "default",
861
+ cwd: directory,
862
+ });
863
+ const runtime = yield* adapter.openSession({
864
+ threadId,
865
+ modelSelection,
866
+ runtimePolicy,
867
+ providerSessionId: ProviderSessionId.make("droid-form-session"),
868
+ });
869
+ const providerThread = yield* runtime.ensureThread({
870
+ threadId,
871
+ modelSelection,
872
+ runtimePolicy,
873
+ });
874
+ yield* runtime.startTurn(
875
+ makeTurnInput({
876
+ threadId,
877
+ providerThread,
878
+ instanceId,
879
+ runtimePolicy,
880
+ now: yield* DateTime.now,
881
+ }),
882
+ );
883
+ const item = Option.getOrThrow(
884
+ yield* runtime.events.pipe(
885
+ Stream.filter(
886
+ (event) =>
887
+ event.type === "turn_item.updated" && event.turnItem.type === "user_input_request",
888
+ ),
889
+ Stream.runHead,
890
+ ),
891
+ );
892
+ if (item.type !== "turn_item.updated" || item.turnItem.type !== "user_input_request")
893
+ return yield* Effect.die("Expected Droid question");
894
+ assert.deepEqual(item.turnItem.questions, questions);
895
+ yield* runtime.respondToRuntimeRequest({
896
+ requestId: item.turnItem.requestId,
897
+ ...(preparedAnswers === undefined ? {} : { answers: preparedAnswers }),
898
+ });
899
+ const terminal = yield* runtime.events.pipe(
900
+ Stream.filter((event) => event.type === "turn.terminal"),
901
+ Stream.runHead,
902
+ );
903
+ assert.equal(Option.getOrThrow(terminal).status, "completed");
904
+ }).pipe(Effect.provide(layerTest), Effect.scoped),
905
+ );
906
+
907
it.live.each(["failed", "recovered", "completed", "cancelled"] as const)(
908
"projects Mistral retry notices and their %s outcome",
909
(outcome) =>
packages/provider-acp-registry/src/server/adapter.ts
+4
@@ -8,6 +8,7 @@ import {
8
normalizeDevinToolCall,
9
extractDevinSubagentUpdate,
10
} from "./devinAcp.ts";
11
+import { extractDroidElicitationForm } from "./droidAcp.ts";
12
import {
13
copilotClientCapabilitiesMeta,
14
extractCopilotSubagentUpdate,
@@ -212,6 +213,9 @@ export const makeAcpRegistryAdapterV2 = Effect.fn("makeAcpRegistryAdapterV2")(fu
213
capabilities: AcpProviderCapabilitiesV2,
214
customModels: readCustomModelEntries(options.settings.customModels).map((entry) => entry.slug),
215
promptFailure: (cause) => acpRegistryPromptFailure(registryAgentId, cause),
216
+ ...(registryAgentId === "factory-droid"
217
+ ? { extractElicitationForm: extractDroidElicitationForm }
218
+ : {}),
219
...(registryAgentId === "mistral-vibe"
220
? { registerExtensions: registerMistralVibeAcpExtensions }
221
: {}),
packages/provider-acp-registry/src/server/droidAcp.ts
new
+84
@@ -0,0 +1,84 @@
1
+import { type OrchestrationV2UserInputQuestion, TrimmedNonEmptyString } from "@t3tools/contracts";
2
+import type { AcpAdapterV2Flavor } from "@t3tools/provider-acp/server/adapter";
3
+import * as Predicate from "effect/Predicate";
4
+import * as Schema from "effect/Schema";
5
+
6
+const isDroidForm = Schema.is(
7
+ Schema.Struct({
8
+ properties: Schema.Record(Schema.String, Schema.Unknown),
9
+ required: Schema.Array(Schema.String),
10
+ }),
11
+);
12
+const isDroidQuestion = Schema.is(
13
+ Schema.Struct({
14
+ type: Schema.Literal("string"),
15
+ title: TrimmedNonEmptyString,
16
+ description: TrimmedNonEmptyString,
17
+ oneOf: Schema.Array(
18
+ Schema.Struct({
19
+ const: Schema.String.check(Schema.isPattern(/^(?:option_\d+|other)$/)),
20
+ title: TrimmedNonEmptyString,
21
+ }),
22
+ ),
23
+ }),
24
+);
25
+const isDroidCompanion = Schema.is(Schema.Struct({ type: Schema.Literal("string") }));
26
+
27
+// Droid pairs each choice with an optional *_other field. The client already
28
+// offers custom answers, so hide the companion and restore it in the response.
29
+export const extractDroidElicitationForm: NonNullable<
30
+ AcpAdapterV2Flavor["extractElicitationForm"]
31
+> = (request) => {
32
+ if (request.mode !== "form" || !isDroidForm(request.requestedSchema)) return undefined;
33
+ const { properties, required } = request.requestedSchema;
34
+ const questions: Array<OrchestrationV2UserInputQuestion> = [];
35
+ for (const [id, field] of Object.entries(properties)) {
36
+ if (!/^question_[1-9]\d*$/.test(id)) continue;
37
+ if (!isDroidQuestion(field) || !isDroidCompanion(properties[`${id}_other`])) return undefined;
38
+ const options = field.oneOf
39
+ .filter((option) => option.const !== "other")
40
+ .map((option) => ({ label: option.title, description: option.title, value: option.const }));
41
+ if (options.length === 0 || !field.oneOf.some((option) => option.const === "other")) {
42
+ return undefined;
43
+ }
44
+ questions.push({ id, header: field.title, question: field.description, options });
45
+ }
46
+ // Recognize only complete forms; leave every other schema to the ACP fallback.
47
+ const requiredIds = new Set(required);
48
+ if (
49
+ questions.length === 0 ||
50
+ Object.keys(properties).length !== questions.length * 2 ||
51
+ requiredIds.size !== questions.length ||
52
+ questions.some((question) => !requiredIds.has(question.id))
53
+ ) {
54
+ return undefined;
55
+ }
56
+ return {
57
+ questions,
58
+ respond: (answers) => {
59
+ const entries: Array<[string, string]> = [];
60
+ for (const question of questions) {
61
+ const answer = Object.hasOwn(answers, question.id) ? answers[question.id] : undefined;
62
+ if (!Predicate.isString(answer) || answer.trim().length === 0) return { action: "cancel" };
63
+ if (question.options.some((option) => option.value === answer)) {
64
+ entries.push([question.id, answer]);
65
+ } else {
66
+ // Intake appends server attachment references to the selected choice ID.
67
+ const attachmentStart = answer.indexOf("\n\n");
68
+ const selectedOption = question.options.find(
69
+ (option) =>
70
+ option.value === answer.slice(0, attachmentStart) &&
71
+ /^\n\nAttached (?:image|file) "(?:\\.|[^"\\\r\n])*": "/.test(
72
+ answer.slice(attachmentStart),
73
+ ),
74
+ );
75
+ const text = selectedOption
76
+ ? `${selectedOption.label}${answer.slice(attachmentStart)}`
77
+ : answer;
78
+ entries.push([question.id, "other"], [`${question.id}_other`, text]);
79
+ }
80
+ }
81
+ return { action: "accept", content: Object.fromEntries(entries) };
82
+ },
83
+ };
84
+};
packages/provider-acp/src/server/adapter.ts
+37
-25
@@ -224,6 +224,14 @@ export interface AcpAdapterV2Flavor {
224
readonly url: string;
225
readonly message: string;
226
}) => Effect.Effect<boolean>;
227
+ readonly extractElicitationForm?: (request: EffectAcpSchema.CreateElicitationRequest) =>
228
+ | {
229
+ readonly questions: ReadonlyArray<OrchestrationV2UserInputQuestion>;
230
+ readonly respond: (
231
+ answers: ProviderUserInputAnswers,
232
+ ) => EffectAcpSchema.CreateElicitationResponse;
233
+ }
234
+ | undefined;
235
readonly withRuntimeStartup?: <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
236
readonly makeRuntime: (
237
input: AcpAdapterV2RuntimeInput,
@@ -6141,31 +6149,34 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
6149
}
6150
const requestedSchema = unknownRecord(params.requestedSchema);
6151
const properties = unknownRecord(requestedSchema?.properties) ?? {};
6152
+ const nativeForm = flavor.extractElicitationForm?.(params);
6153
const elicitationScopeId =
6154
"sessionId" in params ? params.sessionId : `request:${params.requestId}`;
6146
- const questions = Object.entries(properties).map(
6147
- ([id, property], index): OrchestrationV2UserInputQuestion => {
6148
- const record = unknownRecord(property);
6149
- const enumValues = Array.isArray(record?.enum)
6150
- ? record.enum.filter((value): value is string => typeof value === "string")
6151
- : [];
6152
- const options =
6153
- enumValues.length > 0
6154
- ? enumValues.map((value) => ({ label: value, description: value }))
6155
- : record?.type === "boolean"
6156
- ? [
6157
- { label: "true", description: "Yes" },
6158
- { label: "false", description: "No" },
6159
- ]
6160
- : [];
6161
- return {
6162
- id,
6163
- header: nonEmptyText(record?.title, `Question ${index + 1}`),
6164
- question: nonEmptyText(record?.description, params.message),
6165
- options,
6166
- };
6167
- },
6168
- );
6155
+ const questions =
6156
+ nativeForm?.questions ??
6157
+ Object.entries(properties).map(
6158
+ ([id, property], index): OrchestrationV2UserInputQuestion => {
6159
+ const record = unknownRecord(property);
6160
+ const enumValues = Array.isArray(record?.enum)
6161
+ ? record.enum.filter((value): value is string => typeof value === "string")
6162
+ : [];
6163
+ const options =
6164
+ enumValues.length > 0
6165
+ ? enumValues.map((value) => ({ label: value, description: value }))
6166
+ : record?.type === "boolean"
6167
+ ? [
6168
+ { label: "true", description: "Yes" },
6169
+ { label: "false", description: "No" },
6170
+ ]
6171
+ : [];
6172
+ return {
6173
+ id,
6174
+ header: nonEmptyText(record?.title, `Question ${index + 1}`),
6175
+ question: nonEmptyText(record?.description, params.message),
6176
+ options,
6177
+ };
6178
+ },
6179
+ );
6180
const userInput = yield* requestUserInputWithAdmission(
6181
handlerGeneration,
6182
Effect.gen(function* () {
@@ -6185,13 +6196,14 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
6196
const response =
6197
userInput.answers === null
6198
? ({ action: "cancel" } as const)
6188
- : ({
6199
+ : (nativeForm?.respond(userInput.answers) ??
6200
+ ({
6201
action: "accept",
6202
content: elicitationContent(
6203
userInput.answers,
6204
new Set(Object.keys(properties)),
6205
),
6194
- } as const);
6206
+ } as const));
6207
yield* userInput.acknowledgeNativeResponse;
6208
return response;
6209
}).pipe(holdingAgentRequest(handlerGeneration)),