Skip to content

Commit 1e6a251

Browse files
nateEcmaria-rcksjuliusmarminge
authored
fix(acp): preserve OMP single-choice questions and custom answers (#24012)
Co-authored-by: maria-rcks <[email protected]> Co-authored-by: Julius Marminge <[email protected]>
1 parent aa37097 commit 1e6a251

3 files changed

Lines changed: 127 additions & 4 deletions

File tree

‎apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts‎

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ import {
102102

103103
const DEFAULT_GROK_SETTINGS = Schema.decodeSync(GrokSettings)({});
104104
const DROID_SETTINGS = Schema.decodeSync(AcpRegistrySettings)({ agentId: "factory-droid" });
105+
const OMP_SETTINGS = Schema.decodeSync(AcpRegistrySettings)({
106+
source: "local",
107+
commandPath: "/usr/local/bin/omp",
108+
commandArgs: ["acp"],
109+
});
105110
const OPENCODE_SETTINGS = Schema.decodeSync(AcpRegistrySettings)({
106111
source: "local",
107112
commandPath: "/usr/local/bin/opencode",
@@ -1698,8 +1703,55 @@ describe("AcpAdapterV2", () => {
16981703
},
16991704
];
17001705

1701-
// regression: #20417 Droid AskUser answers were sent as a cancel
1706+
// regression: #20417 Droid answers were sent as a cancel; #23505 OMP header and question were swapped
17021707
it.live.each([
1708+
...[
1709+
{ scenario: "OMP selected option", answers: { q0: "Approve" }, content: { q0: "Approve" } },
1710+
{
1711+
scenario: "OMP custom answer",
1712+
answers: { q0: "Please wait" },
1713+
content: { q0__other: "Please wait" },
1714+
},
1715+
].map((fixture) => ({
1716+
...fixture,
1717+
settings: OMP_SETTINGS,
1718+
schema: {
1719+
type: "object",
1720+
properties: {
1721+
q0: {
1722+
type: "string",
1723+
title: "Approve this exact code-only commit?",
1724+
description: "Safety-hook false positive",
1725+
oneOf: [
1726+
{ const: "Approve", title: "Approve", description: "Commit the verified fix." },
1727+
{ const: "Hold", title: "Hold" },
1728+
],
1729+
default: "Approve",
1730+
},
1731+
q0__other: { type: "string", title: "Other (type your own)" },
1732+
},
1733+
},
1734+
questions: [
1735+
{
1736+
id: "q0",
1737+
header: "Safety-hook false positive",
1738+
question: "Approve this exact code-only commit?",
1739+
options: [
1740+
{ label: "Approve", value: "Approve", description: "Commit the verified fix." },
1741+
{ label: "Hold", value: "Hold", description: "Hold" },
1742+
],
1743+
},
1744+
],
1745+
result: { action: "accept", content: fixture.content },
1746+
})),
1747+
{
1748+
scenario: "OMP unrelated form uses generic mapping",
1749+
settings: OMP_SETTINGS,
1750+
schema: { type: "object", properties: { name: { type: "string" } } },
1751+
questions: [{ id: "name", header: "Question 1", question: "Your answer?", options: [] }],
1752+
answers: { name: "Ada" },
1753+
result: { action: "accept", content: { name: "Ada" } },
1754+
},
17031755
{
17041756
scenario: "preserves selected IDs and encodes custom answers",
17051757
schema: droidSchema,

‎packages/provider-acp-registry/src/server/adapter.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
extractDevinSubagentUpdate,
1010
} from "./devinAcp.ts";
1111
import { extractDroidElicitationForm } from "./droidAcp.ts";
12+
import { extractOmpElicitationForm } from "./ompAcp.ts";
1213
import { extractOpenCodeElicitationForm } from "./opencodeAcp.ts";
1314
import {
1415
copilotClientCapabilitiesMeta,
@@ -188,6 +189,9 @@ export const makeAcpRegistryAdapterV2 = Effect.fn("makeAcpRegistryAdapterV2")(fu
188189
const startupKey =
189190
options.settings.source === "local" ? `local:${options.instanceId}` : registryAgentId;
190191
const isDevin = registryAgentId === "devin";
192+
const isOmp =
193+
options.settings.source === "local" &&
194+
/^omp(\.exe|\.cmd)?$/i.test(options.settings.commandPath.split(/[\\/]/).pop() ?? "");
191195
const isOpenCode =
192196
registryAgentId === "opencode" ||
193197
registryAgentId === "opencode-v2" ||
@@ -231,9 +235,11 @@ export const makeAcpRegistryAdapterV2 = Effect.fn("makeAcpRegistryAdapterV2")(fu
231235
promptFailure: (cause) => acpRegistryPromptFailure(registryAgentId, cause),
232236
...(registryAgentId === "factory-droid"
233237
? { extractElicitationForm: extractDroidElicitationForm }
234-
: isOpenCode
235-
? { extractElicitationForm: extractOpenCodeElicitationForm }
236-
: {}),
238+
: isOmp
239+
? { extractElicitationForm: extractOmpElicitationForm }
240+
: isOpenCode
241+
? { extractElicitationForm: extractOpenCodeElicitationForm }
242+
: {}),
237243
// glm-acp-agent is the one agent whose per-turn usage a live probe has verified.
238244
...(registryAgentId === "glm-acp-agent" ? { reportsPerTurnPromptUsage: true } : {}),
239245
...(registryAgentId === "mistral-vibe"
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { type OrchestrationV2UserInputQuestion, TrimmedNonEmptyString } from "@t3tools/contracts";
2+
import type { AcpAdapterV2Flavor } from "@t3tools/provider-acp/server/adapter";
3+
import * as Schema from "effect/Schema";
4+
5+
const isForm = Schema.is(
6+
Schema.Struct({ properties: Schema.Record(Schema.String, Schema.Unknown) }),
7+
);
8+
const choice = Schema.Struct({
9+
const: TrimmedNonEmptyString,
10+
title: TrimmedNonEmptyString,
11+
description: Schema.optional(Schema.String),
12+
});
13+
const isQuestion = Schema.is(
14+
Schema.Struct({
15+
title: TrimmedNonEmptyString,
16+
description: Schema.optional(Schema.String),
17+
type: Schema.Literal("string"),
18+
oneOf: Schema.Array(choice),
19+
}),
20+
);
21+
const isCompanion = Schema.is(
22+
Schema.Struct({ type: Schema.Literal("string"), title: Schema.Literal("Other (type your own)") }),
23+
);
24+
25+
/** OMP askDialog pairs qN choices with qN__other and puts the question in title. */
26+
export const extractOmpElicitationForm: NonNullable<
27+
AcpAdapterV2Flavor["extractElicitationForm"]
28+
> = (request) => {
29+
if (request.mode !== "form" || !isForm(request.requestedSchema)) return undefined;
30+
const { properties } = request.requestedSchema;
31+
const questions: OrchestrationV2UserInputQuestion[] = [];
32+
for (const [id, field] of Object.entries(properties)) {
33+
if (!/^q\d+$/.test(id)) continue;
34+
if (!isQuestion(field) || !isCompanion(properties[`${id}__other`])) return undefined;
35+
const choices = field.oneOf;
36+
if (choices.length === 0) return undefined;
37+
questions.push({
38+
id,
39+
header: field.description?.trim() || `Question ${questions.length + 1}`,
40+
question: field.title,
41+
options: choices.map((option) => ({
42+
label: option.title,
43+
value: option.const,
44+
description: option.description?.trim() || option.title,
45+
})),
46+
});
47+
}
48+
// Do not hide unknown fields or partially reinterpret a different form.
49+
if (questions.length === 0 || Object.keys(properties).length !== questions.length * 2)
50+
return undefined;
51+
return {
52+
questions,
53+
respond: (answers) => {
54+
const content: Record<string, string> = {};
55+
for (const question of questions) {
56+
const answer = Object.hasOwn(answers, question.id) ? answers[question.id] : undefined;
57+
if (typeof answer !== "string" || !answer.trim()) return { action: "cancel" };
58+
if (question.options.some((option) => option.value === answer))
59+
content[question.id] = answer;
60+
else content[`${question.id}__other`] = answer;
61+
}
62+
return { action: "accept", content };
63+
},
64+
};
65+
};

0 commit comments

Comments
 (0)