@devries-cameron20 / t3code-1 / commits / fd5cb99401
Fork 0

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

fix(opencode): keep ACP question choices and fold the custom answer (#25879)

Co-authored-by: Sultan U <192680428+QRpeachKZ@users.noreply.github.com> Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Увалиев Султан Ермекович <alfa@HNBA.local> Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>

Sultan U committed Nov 13, 2026 at 05:11 UTC fd5cb99401d40ffd662db8ed69b9e6589d6bd1e7
4 files changed +349 -10
apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts
+60 -9
@@ -102,6 +102,11 @@ import {
102
103 const DEFAULT_GROK_SETTINGS = Schema.decodeSync(GrokSettings)({});
104 const DROID_SETTINGS = Schema.decodeSync(AcpRegistrySettings)({ agentId: "factory-droid" });
105 +const OPENCODE_SETTINGS = Schema.decodeSync(AcpRegistrySettings)({
106 + source: "local",
107 + commandPath: "/usr/local/bin/opencode",
108 + commandArgs: ["acp"],
109 +});
110
111 const layerHost = TestProviderHost.layer().pipe(
112 Layer.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)),
@@ -1518,7 +1523,7 @@ describe("AcpAdapterV2", () => {
1523 }).pipe(Effect.provide(layerTest), Effect.scoped),
1524 );
1525
1521 - // Factory Droid 0.243.0 sends an optional text companion for every AskUser choice.
1526 + // Droid 0.243.0 and OpenCode 2.1 pair each choice with an optional free-form companion field.
1527 const droidChoice = {
1528 type: "string",
1529 title: "Format",
@@ -1549,6 +1554,41 @@ describe("AcpAdapterV2", () => {
1554 ],
1555 }));
1556
1557 + // OpenCode 2.1 pairs each qN choice with a qN_custom free-form companion.
1558 + const openCodeSchema = {
1559 + type: "object",
1560 + properties: {
1561 + q0: {
1562 + type: "string",
1563 + title: "Color preference",
1564 + description: "Which color do you prefer?",
1565 + oneOf: [
1566 + { const: "red", title: "Red", description: "Choose the color red" },
1567 + { const: "blue", title: "Blue" },
1568 + ],
1569 + default: "red",
1570 + },
1571 + q0_custom: {
1572 + type: "string",
1573 + title: "Color preference (other)",
1574 + description: "Type your own answer",
1575 + minLength: 1,
1576 + },
1577 + },
1578 + };
1579 + const openCodeQuestions = [
1580 + {
1581 + id: "q0",
1582 + header: "Color preference",
1583 + question: "Which color do you prefer?",
1584 + options: [
1585 + { label: "Red", description: "Choose the color red", value: "red" },
1586 + { label: "Blue", description: "Blue", value: "blue" },
1587 + ],
1588 + allowCustomAnswer: true,
1589 + },
1590 + ];
1591 +
1592 // regression: #20417 Droid AskUser answers were sent as a cancel
1593 it.live.each([
1594 {
@@ -1594,11 +1634,22 @@ describe("AcpAdapterV2", () => {
1634 answers: { name: "Ada" },
1635 result: { action: "accept", content: { name: "Ada" } },
1636 },
1597 - ])("Droid elicitation $scenario", ({ schema, questions, answers, result, withAttachments }) =>
1598 - Effect.gen(function* () {
1637 + {
1638 + scenario: "OpenCode keeps the selected option and hides the custom companion",
1639 + settings: OPENCODE_SETTINGS,
1640 + schema: openCodeSchema,
1641 + questions: openCodeQuestions,
1642 + answers: { q0: "blue" },
1643 + result: { action: "accept", content: { q0: "blue" } },
1644 + },
1645 + ])("Registry elicitation $scenario", (fixture) => {
1646 + const { schema, questions, answers, result } = fixture;
1647 + const withAttachments = "withAttachments" in fixture && fixture.withAttachments;
1648 + const settings = "settings" in fixture ? fixture.settings : DROID_SETTINGS;
1649 + return Effect.gen(function* () {
1650 const fileSystem = yield* FileSystem.FileSystem;
1651 const path = yield* Path.Path;
1601 - const directory = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-droid-form-" });
1652 + const directory = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-registry-form-" });
1653 const statusPath = path.join(directory, "status.json");
1654 const expectedResult = typeof result === "function" ? result(directory) : result;
1655 let preparedAnswers: ProviderUserInputAnswers | undefined = answers;
@@ -1702,7 +1753,7 @@ describe("AcpAdapterV2", () => {
1753 const adapter = yield* makeAcpRegistryAdapterV2({
1754 instanceId,
1755 selfInvocation: yield* resolveSelfInvocation(),
1705 - settings: DROID_SETTINGS,
1756 + settings,
1757 environment: {},
1758 makeRuntime: makeAcpReplayRuntime({
1759 transcript,
@@ -1718,7 +1769,7 @@ describe("AcpAdapterV2", () => {
1769 Layer.mock(AcpRegistryCatalog)({ resolve: () => Effect.die("runtime is injected") }),
1770 ),
1771 );
1721 - const threadId = ThreadId.make("droid-form-thread");
1772 + const threadId = ThreadId.make("registry-form-thread");
1773 const modelSelection = { instanceId, model: "default" } as const;
1774 const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
1775 runtimeMode: "approval-required",
@@ -1755,7 +1806,7 @@ describe("AcpAdapterV2", () => {
1806 ),
1807 );
1808 if (item.type !== "turn_item.updated" || item.turnItem.type !== "user_input_request")
1758 - return yield* Effect.die("Expected Droid question");
1809 + return yield* Effect.die("Expected a user input question");
1810 assert.deepEqual(item.turnItem.questions, questions);
1811 yield* runtime.respondToRuntimeRequest({
1812 requestId: item.turnItem.requestId,
@@ -1766,8 +1817,8 @@ describe("AcpAdapterV2", () => {
1817 Stream.runHead,
1818 );
1819 assert.equal(Option.getOrThrow(terminal).status, "completed");
1769 - }).pipe(Effect.provide(layerTest), Effect.scoped),
1770 - );
1820 + }).pipe(Effect.provide(layerTest), Effect.scoped);
1821 + });
1822
1823 it.live.each(["failed", "recovered", "cancelled"] as const)(
1824 "projects Mistral retry notices and their %s outcome",
packages/provider-acp-registry/src/server/adapter.ts
+11 -1
@@ -9,6 +9,7 @@ import {
9 extractDevinSubagentUpdate,
10 } from "./devinAcp.ts";
11 import { extractDroidElicitationForm } from "./droidAcp.ts";
12 +import { extractOpenCodeElicitationForm } from "./opencodeAcp.ts";
13 import {
14 copilotClientCapabilitiesMeta,
15 extractCopilotSubagentUpdate,
@@ -187,6 +188,13 @@ export const makeAcpRegistryAdapterV2 = Effect.fn("makeAcpRegistryAdapterV2")(fu
188 const startupKey =
189 options.settings.source === "local" ? `local:${options.instanceId}` : registryAgentId;
190 const isDevin = registryAgentId === "devin";
191 + const isOpenCode =
192 + registryAgentId === "opencode" ||
193 + registryAgentId === "opencode-v2" ||
194 + (options.settings.source === "local" &&
195 + /^opencode(?:-v2)?(\.exe|\.cmd)?$/i.test(
196 + options.settings.commandPath.split(/[\\/]/).pop() ?? "",
197 + ));
198 // Local installs launch the `copilot` binary directly with no registry id.
199 const isCopilot =
200 registryAgentId === "github-copilot-cli" ||
@@ -222,7 +230,9 @@ export const makeAcpRegistryAdapterV2 = Effect.fn("makeAcpRegistryAdapterV2")(fu
230 promptFailure: (cause) => acpRegistryPromptFailure(registryAgentId, cause),
231 ...(registryAgentId === "factory-droid"
232 ? { extractElicitationForm: extractDroidElicitationForm }
225 - : {}),
233 + : isOpenCode
234 + ? { extractElicitationForm: extractOpenCodeElicitationForm }
235 + : {}),
236 // glm-acp-agent is the one agent whose per-turn usage a live probe has verified.
237 ...(registryAgentId === "glm-acp-agent" ? { reportsPerTurnPromptUsage: true } : {}),
238 ...(registryAgentId === "mistral-vibe"
packages/provider-acp-registry/src/server/opencodeAcp.test.ts new
+143
@@ -0,0 +1,143 @@
1 +import type { AcpAdapterV2Flavor } from "@t3tools/provider-acp/server/adapter";
2 +import { describe, expect, it } from "vite-plus/test";
3 +
4 +import { extractOpenCodeElicitationForm } from "./opencodeAcp.ts";
5 +
6 +type ElicitationRequest = Parameters<NonNullable<AcpAdapterV2Flavor["extractElicitationForm"]>>[0];
7 +
8 +const request = (properties: Record<string, unknown>): ElicitationRequest =>
9 + ({
10 + mode: "form",
11 + sessionId: "session-id",
12 + message: "Questions",
13 + requestedSchema: { type: "object", properties },
14 + }) as ElicitationRequest;
15 +
16 +const colorQuestion = {
17 + type: "string",
18 + title: "Color preference",
19 + description: "Which color do you prefer?",
20 + oneOf: [
21 + { const: "red", title: "Red", description: "Choose the color red" },
22 + { const: "blue", title: "Blue" },
23 + ],
24 + default: "red",
25 +};
26 +const colorCompanion = {
27 + type: "string",
28 + title: "Color preference (other)",
29 + description: "Type your own answer",
30 + minLength: 1,
31 +};
32 +const multiColorQuestion = {
33 + type: "array",
34 + title: "Colors",
35 + description: "Which colors?",
36 + items: {
37 + anyOf: [
38 + { const: "red", title: "Red" },
39 + { const: "blue", title: "Blue" },
40 + ],
41 + },
42 +};
43 +const multiColorCompanion = { type: "string", description: "Add your own answer" };
44 +const attachment = '\n\nAttached image "shot.png": "/tmp/shot.png"';
45 +
46 +describe("OpenCode ACP question form", () => {
47 + it("folds the custom-answer companion into its question", () => {
48 + const form = extractOpenCodeElicitationForm(
49 + request({
50 + q0: colorQuestion,
51 + q0_custom: colorCompanion,
52 + q1: { type: "string", title: "Notes", description: "Anything else?" },
53 + }),
54 + );
55 +
56 + expect(form?.questions).toEqual([
57 + {
58 + id: "q0",
59 + header: "Color preference",
60 + question: "Which color do you prefer?",
61 + options: [
62 + { label: "Red", description: "Choose the color red", value: "red" },
63 + { label: "Blue", description: "Blue", value: "blue" },
64 + ],
65 + allowCustomAnswer: true,
66 + },
67 + {
68 + id: "q1",
69 + header: "Notes",
70 + question: "Anything else?",
71 + options: [],
72 + allowCustomAnswer: true,
73 + },
74 + ]);
75 + expect(form?.respond({ q0: "blue", q1: "Later" })).toEqual({
76 + action: "accept",
77 + content: { q0: "blue", q1: "Later" },
78 + });
79 + });
80 +
81 + it("prefers an option value over an earlier option label", () => {
82 + const form = extractOpenCodeElicitationForm(
83 + request({
84 + q0: {
85 + ...colorQuestion,
86 + oneOf: [
87 + { const: "a", title: "b" },
88 + { const: "b", title: "B" },
89 + ],
90 + },
91 + q0_custom: colorCompanion,
92 + }),
93 + );
94 +
95 + expect(form?.respond({ q0: "b" })).toEqual({ action: "accept", content: { q0: "b" } });
96 + });
97 +
98 + it("sends a free-form answer to the companion field", () => {
99 + const form = extractOpenCodeElicitationForm(
100 + request({ q0: colorQuestion, q0_custom: colorCompanion }),
101 + );
102 +
103 + expect(form?.respond({ q0: "green" })).toEqual({
104 + action: "accept",
105 + content: { q0_custom: "green" },
106 + });
107 + });
108 +
109 + it("keeps attachment text with the selected option", () => {
110 + const form = extractOpenCodeElicitationForm(
111 + request({ q0: colorQuestion, q0_custom: colorCompanion }),
112 + );
113 +
114 + expect(form?.respond({ q0: `blue${attachment}` })).toEqual({
115 + action: "accept",
116 + content: { q0: "blue", q0_custom: `Blue${attachment}` },
117 + });
118 + });
119 +
120 + it("cancels empty or multi-value answers to a single-select question", () => {
121 + const form = extractOpenCodeElicitationForm(
122 + request({ q0: colorQuestion, q0_custom: colorCompanion }),
123 + );
124 +
125 + expect(form?.respond({})).toEqual({ action: "cancel" });
126 + expect(form?.respond({ q0: " " })).toEqual({ action: "cancel" });
127 + expect(form?.respond({ q0: ["red", "blue"] })).toEqual({ action: "cancel" });
128 + });
129 +
130 + it.each([
131 + ["a text-only form", { q0: { type: "string", title: "Name", description: "Who?" } }],
132 + ["an unrelated field", { q0: colorQuestion, q0_custom: colorCompanion, extra: {} }],
133 + ["a multi-select choice", { q0: multiColorQuestion, q0_custom: multiColorCompanion }],
134 + ["an orphan companion", { q0_custom: colorCompanion }],
135 + ["an enum choice", { q0: colorQuestion, q1: { type: "string", title: "Size", enum: ["S"] } }],
136 + [
137 + "a choice without a title",
138 + { q0: colorQuestion, q1: { ...colorQuestion, oneOf: [{ const: "red" }] } },
139 + ],
140 + ])("leaves %s to the generic mapping", (_, properties) => {
141 + expect(extractOpenCodeElicitationForm(request(properties))).toBeUndefined();
142 + });
143 +});
packages/provider-acp-registry/src/server/opencodeAcp.ts new
+135
@@ -0,0 +1,135 @@
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 isForm = Schema.is(
7 + Schema.Struct({ properties: Schema.Record(Schema.String, Schema.Unknown) }),
8 +);
9 +const choice = Schema.Struct({
10 + const: Schema.String,
11 + title: TrimmedNonEmptyString,
12 + description: Schema.optional(Schema.String),
13 +});
14 +const isChoiceQuestion = Schema.is(
15 + Schema.Struct({
16 + type: Schema.Literal("string"),
17 + title: TrimmedNonEmptyString,
18 + description: Schema.optional(Schema.String),
19 + oneOf: Schema.Array(choice),
20 + }),
21 +);
22 +const isTextQuestion = Schema.is(
23 + Schema.Struct({
24 + type: Schema.Literal("string"),
25 + title: TrimmedNonEmptyString,
26 + description: Schema.optional(Schema.String),
27 + }),
28 +);
29 +// The companion only carries a free-form answer, never a title we can show.
30 +const isCustomCompanion = Schema.is(
31 + Schema.Struct({
32 + type: Schema.Literal("string"),
33 + description: Schema.Literals(["Type your own answer", "Add your own answer"]),
34 + }),
35 +);
36 +
37 +const questionId = /^q\d+$/;
38 +const companionSuffix = "_custom";
39 +
40 +// Intake appends file references to a user's answer; keep them with the custom text.
41 +const splitAttachments = (value: string) => {
42 + const marker = value.indexOf("\n\n");
43 + if (marker < 0) return undefined;
44 + const suffix = value.slice(marker);
45 + if (!/^\n\nAttached (?:image|file) "(?:\\.|[^"\\\r\n])*": "/.test(suffix)) return undefined;
46 + return { prefix: value.slice(0, marker), suffix };
47 +};
48 +
49 +type Option = OrchestrationV2UserInputQuestion["options"][number];
50 +
51 +const findChoice = (options: ReadonlyArray<Option>, value: string) =>
52 + options.find((option) => option.value === value);
53 +
54 +// OpenCode 2.1 asks through ACP with a `qN` choice field plus a `qN_custom` companion.
55 +// Multi-select forms stay with the generic mapping: it keeps the companion as its own
56 +// question, and clients cannot yet send selected choices and custom text as one answer.
57 +export const extractOpenCodeElicitationForm: NonNullable<
58 + AcpAdapterV2Flavor["extractElicitationForm"]
59 +> = (request) => {
60 + if (request.mode !== "form" || !isForm(request.requestedSchema)) return undefined;
61 + const { properties } = request.requestedSchema;
62 + const questions: Array<OrchestrationV2UserInputQuestion> = [];
63 + const withCompanion = new Set<string>();
64 + let choices = 0;
65 + for (const [id, field] of Object.entries(properties)) {
66 + if (!questionId.test(id)) {
67 + const owner = id.endsWith(companionSuffix) ? id.slice(0, -companionSuffix.length) : undefined;
68 + if (owner === undefined || !questionId.test(owner) || !Object.hasOwn(properties, owner)) {
69 + return undefined;
70 + }
71 + continue;
72 + }
73 + const companion = properties[`${id}${companionSuffix}`];
74 + const hasCompanion = companion !== undefined;
75 + if (hasCompanion && !isCustomCompanion(companion)) return undefined;
76 + if (!isTextQuestion(field)) return undefined;
77 + const fieldChoices = isChoiceQuestion(field) ? field.oneOf : undefined;
78 + // Unsupported choice schemas belong to the generic mapping.
79 + if (
80 + fieldChoices === undefined &&
81 + ("enum" in field || "oneOf" in field || "anyOf" in field || "items" in field)
82 + ) {
83 + return undefined;
84 + }
85 + const options = (fieldChoices ?? []).map((option) => ({
86 + label: option.title,
87 + description: option.description?.trim() || option.title,
88 + value: option.const,
89 + }));
90 + if (options.length > 0) choices += 1;
91 + if (hasCompanion) withCompanion.add(id);
92 + questions.push({
93 + id,
94 + header: field.title,
95 + question: field.description?.trim() || field.title,
96 + options,
97 + allowCustomAnswer: hasCompanion || options.length === 0,
98 + });
99 + }
100 + // Recognize only question forms with a choice; leave every other schema to the ACP fallback.
101 + if (choices === 0) return undefined;
102 + return {
103 + questions,
104 + respond: (answers) => {
105 + const content: Record<string, string> = {};
106 + for (const question of questions) {
107 + const answer = Object.hasOwn(answers, question.id) ? answers[question.id] : undefined;
108 + if (!Predicate.isString(answer)) return { action: "cancel" };
109 + const companionId = `${question.id}${companionSuffix}`;
110 + const exact = findChoice(question.options, answer);
111 + if (exact !== undefined) {
112 + content[question.id] = answer;
113 + continue;
114 + }
115 + if (answer.trim().length === 0) return { action: "cancel" };
116 + const split = splitAttachments(answer);
117 + const attached =
118 + split === undefined ? undefined : findChoice(question.options, split.prefix);
119 + if (withCompanion.has(question.id)) {
120 + if (attached !== undefined && split !== undefined) {
121 + content[question.id] = split.prefix;
122 + content[companionId] = `${attached.label}${split.suffix}`;
123 + } else {
124 + content[companionId] = answer;
125 + }
126 + } else if (question.options.length === 0) {
127 + content[question.id] = answer;
128 + } else {
129 + return { action: "cancel" };
130 + }
131 + }
132 + return { action: "accept", content };
133 + },
134 + };
135 +};