Skip to content

Commit c0d6038

Browse files
committed
fix(acp): 正确映射 OMP 单选问题与自定义回答
在 OMP 本地命令适配边界合并自定义输入字段,保留题目、标题和选项。 将选择值和自由输入还原为 OMP 所需的响应字段,保留取消与附件引用。 通过 ACP 回放验证问题事件及返回内容,变更范围检查通过;不修改通用多选协议。
1 parent 807319c commit c0d6038

3 files changed

Lines changed: 142 additions & 3 deletions

File tree

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

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ import {
9595

9696
const DEFAULT_GROK_SETTINGS = Schema.decodeSync(GrokSettings)({});
9797
const DROID_SETTINGS = Schema.decodeSync(AcpRegistrySettings)({ agentId: "factory-droid" });
98+
const OMP_SETTINGS = Schema.decodeSync(AcpRegistrySettings)({
99+
source: "local",
100+
commandPath: "/usr/local/bin/omp",
101+
commandArgs: ["acp"],
102+
});
98103

99104
const layerHost = TestProviderHost.layer().pipe(Layer.provide(NodeServices.layer));
100105

@@ -431,6 +436,67 @@ describe("AcpAdapterV2", () => {
431436

432437
// regression: #20417 Droid AskUser answers were sent as a cancel
433438
it.live.each([
439+
...[
440+
{ scenario: "OMP selected option", answers: { q0: "Approve" }, content: { q0: "Approve" } },
441+
{
442+
scenario: "OMP custom answer",
443+
answers: { q0: "Please wait" },
444+
content: { q0__other: "Please wait" },
445+
},
446+
{ scenario: "OMP cancellation", answers: undefined, content: undefined },
447+
{
448+
scenario: "OMP missing header",
449+
answers: { q0: "Hold" },
450+
content: { q0: "Hold" },
451+
withoutHeader: true,
452+
},
453+
{
454+
scenario: "OMP selected label with attachment references",
455+
answers: { q0: 'Approve\n\nAttached file "notes.txt": "/server/notes.txt"' },
456+
content: { q0__other: 'Approve\n\nAttached file "notes.txt": "/server/notes.txt"' },
457+
},
458+
].map((fixture) => ({
459+
...fixture,
460+
settings: OMP_SETTINGS,
461+
schema: {
462+
type: "object",
463+
properties: {
464+
q0: {
465+
type: "string",
466+
title: "Approve this exact code-only commit?",
467+
...("withoutHeader" in fixture ? {} : { description: "Safety-hook false positive" }),
468+
oneOf: [
469+
{ const: "Approve", title: "Approve", description: "Commit the verified fix." },
470+
{ const: "Hold", title: "Hold" },
471+
],
472+
default: "Approve",
473+
},
474+
q0__other: { type: "string", title: "Other (type your own)" },
475+
},
476+
},
477+
questions: [
478+
{
479+
id: "q0",
480+
header: "withoutHeader" in fixture ? "Question 1" : "Safety-hook false positive",
481+
question: "Approve this exact code-only commit?",
482+
options: [
483+
{ label: "Approve", value: "Approve", description: "Commit the verified fix." },
484+
{ label: "Hold", value: "Hold", description: "Hold" },
485+
],
486+
},
487+
],
488+
result: fixture.content
489+
? { action: "accept", content: fixture.content }
490+
: { action: "cancel" },
491+
})),
492+
{
493+
scenario: "OMP unrelated form uses generic mapping",
494+
settings: OMP_SETTINGS,
495+
schema: { type: "object", properties: { name: { type: "string" } } },
496+
questions: [{ id: "name", header: "Question 1", question: "Your answer?", options: [] }],
497+
answers: { name: "Ada" },
498+
result: { action: "accept", content: { name: "Ada" } },
499+
},
434500
{
435501
scenario: "preserves selected IDs and encodes custom answers",
436502
schema: droidSchema,
@@ -474,8 +540,10 @@ describe("AcpAdapterV2", () => {
474540
answers: { name: "Ada" },
475541
result: { action: "accept", content: { name: "Ada" } },
476542
},
477-
])("Droid elicitation $scenario", ({ schema, questions, answers, result, withAttachments }) =>
543+
])("Registry elicitation $scenario", (fixture) =>
478544
Effect.gen(function* () {
545+
const { schema, questions, answers, result, settings } = fixture;
546+
const withAttachments = "withAttachments" in fixture && fixture.withAttachments;
479547
const fileSystem = yield* FileSystem.FileSystem;
480548
const path = yield* Path.Path;
481549
const directory = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-droid-form-" });
@@ -582,7 +650,7 @@ describe("AcpAdapterV2", () => {
582650
const adapter = yield* makeAcpRegistryAdapterV2({
583651
instanceId,
584652
selfInvocation: yield* resolveSelfInvocation(),
585-
settings: DROID_SETTINGS,
653+
settings: settings ?? DROID_SETTINGS,
586654
environment: {},
587655
makeRuntime: makeAcpReplayRuntime({
588656
transcript,

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

Lines changed: 7 additions & 1 deletion
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 {
1314
copilotClientCapabilitiesMeta,
1415
extractCopilotSubagentUpdate,
@@ -186,6 +187,9 @@ export const makeAcpRegistryAdapterV2 = Effect.fn("makeAcpRegistryAdapterV2")(fu
186187
const startupKey =
187188
options.settings.source === "local" ? `local:${options.instanceId}` : registryAgentId;
188189
const isDevin = registryAgentId === "devin";
190+
const isOmp =
191+
options.settings.source === "local" &&
192+
/^omp(\.exe|\.cmd)?$/i.test(options.settings.commandPath.split(/[\\/]/).pop() ?? "");
189193
// Local installs launch the `copilot` binary directly with no registry id.
190194
const isCopilot =
191195
registryAgentId === "github-copilot-cli" ||
@@ -215,7 +219,9 @@ export const makeAcpRegistryAdapterV2 = Effect.fn("makeAcpRegistryAdapterV2")(fu
215219
promptFailure: (cause) => acpRegistryPromptFailure(registryAgentId, cause),
216220
...(registryAgentId === "factory-droid"
217221
? { extractElicitationForm: extractDroidElicitationForm }
218-
: {}),
222+
: isOmp
223+
? { extractElicitationForm: extractOmpElicitationForm }
224+
: {}),
219225
...(registryAgentId === "mistral-vibe"
220226
? { registerExtensions: registerMistralVibeAcpExtensions }
221227
: {}),
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)