Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ import * as AcpRegistrySupport from "@t3tools/provider-acp-registry/server/AcpRe
import * as AcpRegistryRuntimeCoordinator from "@t3tools/provider-acp-registry/server/AcpRegistryRuntimeCoordinator";
import { ACP_SESSION_MODE_OPTION_ID } from "@t3tools/provider-acp/server/sessionConfig";
import * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime";
import { t3AcpPromptWithInstructions } from "@t3tools/provider-core/server/orchestrationInstructions";
import { buildRuntimeInstructions } from "@t3tools/provider-core/server/runtimeInstructions";
import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
import {
decodeAcpReplayTranscript,
Expand Down Expand Up @@ -1007,6 +1009,92 @@ describe("AcpRegistryAdapterV2", () => {
}).pipe(Effect.provide(layerTest), Effect.scoped),
);

it.effect.each(["before", "after"] as const)(
"reconciles a full prompt echo %s acknowledgment",
(ordering) =>
Effect.gen(function* () {
const runtimeInstructions = {
type: "text",
text: buildRuntimeInstructions({ harness: "acpRegistry", model: "default" }),
};
const promptBlocks = (ordinal: number) => [
{
type: "text",
text:
ordinal === 1
? t3AcpPromptWithInstructions({
prompt: "test prompt",
state: { interactionMode: "default", hasT3Mcp: false },
})
: "test prompt",
},
runtimeInstructions,
];
const echo = (messageId: string, content: ReadonlyArray<unknown>) =>
claudeFrames.update(CLAUDE_ROOT_SESSION, {
sessionUpdate: "user_message",
messageId,
content,
});
const promptText = (ordinal: number) =>
promptBlocks(ordinal)
.map((block) => block.text)
.join("\n");
const frames = (ordinal: number) => {
const [request, , acknowledgment] = claudeFrames.prompt(ordinal);
const matching = echo(`echo-${ordinal}`, promptBlocks(ordinal));
return [
request,
echo("different-blocks", [
{
type: "text",
text: promptText(ordinal),
},
]),
...(ordering === "before" ? [matching, acknowledgment] : [acknowledgment, matching]),
claudeFrames.update(CLAUDE_ROOT_SESSION, {
sessionUpdate: "user_message_chunk",
messageId: `echo-${ordinal}`,
content: { type: "text", text: "updated echo" },
}),
echo(`echo-${ordinal}`, [{ type: "text", text: "updated echo" }]),
echo("second-id", promptBlocks(ordinal)),
echo("unmatched", [{ type: "text", text: "Continue the review." }]),
claudeFrames.idle("end_turn"),
];
};
const session = yield* openClaudeReplaySession(
[
...claudeFrames.open,
...frames(1),
...frames(2),
claudeFrames.closeRequest,
claudeFrames.closed,
],
undefined,
false,
);
for (const ordinal of [1, 2]) {
yield* session.runtime.startTurn(session.turnInput(ordinal));
const events = yield* session.until((event) => event.type === "turn.terminal");
const messages = events.flatMap((event) =>
event.type === "message.updated" && event.message.role === "user"
? [event.message]
: [],
);
const items = events.flatMap((event) =>
event.type === "turn_item.updated" && event.turnItem.type === "user_message"
? [event.turnItem]
: [],
);
const expected = new Set([promptText(ordinal), "Continue the review."]);
assert.deepEqual(new Set(messages.map((message) => message.text)), expected);
assert.equal(new Set(messages.map((message) => message.id)).size, 3);
assert.equal(new Set(items.map((item) => item.id)).size, 3);
}
}).pipe(Effect.provide(layerTest), Effect.scoped),
);

it.effect("settles Claude's accepted foreground reply while retaining child output", () =>
Effect.gen(function* () {
const gate = makeProviderReplayGate(["accepted", "child-output", "wake"]);
Expand Down
26 changes: 26 additions & 0 deletions packages/provider-acp/src/server/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import * as DateTime from "effect/DateTime";
import * as Deferred from "effect/Deferred";
import type * as Duration from "effect/Duration";
import * as Effect from "effect/Effect";
import * as Equal from "effect/Equal";
import * as Exit from "effect/Exit";
import * as FileSystem from "effect/FileSystem";
import * as Fiber from "effect/Fiber";
Expand Down Expand Up @@ -1029,6 +1030,8 @@ interface ActiveAcpTurn {
readonly startedAt: DateTime.Utc;
readonly completed: Deferred.Deferred<void, never>;
readonly itemOrdinals: Map<string, number>;
readonly outgoingPrompt?: ReadonlyArray<EffectAcpSchema.ContentBlock> | undefined;
consumedPromptMessageId?: string;
readonly user: ActiveTextStream;
readonly assistant: ActiveTextStream;
readonly reasoning: ActiveTextStream;
Expand Down Expand Up @@ -4840,6 +4843,25 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
) {
yield* emitProviderRetry(context, "completed");
}
if (
context.outgoingPrompt !== undefined &&
(update.sessionUpdate === "user_message" ||
update.sessionUpdate === "user_message_chunk")
) {
// ACP v2 prompt acknowledgments lack a messageId; correlate one full echo by content.
if (
context.consumedPromptMessageId === undefined &&
update.sessionUpdate === "user_message" &&
Equal.equals(update.content, context.outgoingPrompt)
) {
context.consumedPromptMessageId = update.messageId;
}
if (
context.consumedPromptMessageId !== undefined &&
context.consumedPromptMessageId === update.messageId
)
return;
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
switch (update.sessionUpdate) {
case "state_update": {
const toolCallId = `${context.nativeTurnId}:requires-action`;
Expand Down Expand Up @@ -7315,6 +7337,10 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
startedAt,
completed,
itemOrdinals: new Map(),
outgoingPrompt:
(yield* Ref.get(activeSessionSetup))?.initializeResult.protocolVersion === 2
? promptParts?.prompt
: undefined,
user: { current: null, nextSegment: 0 },
assistant: { current: null, nextSegment: 0 },
reasoning: { current: null, nextSegment: 0 },
Expand Down
Loading