@devries-cameron20 / t3code Mirror · read-only / commits / 9791bce798
Fork 0

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 21, 12:15 UTC

fix(effect-acp): reject elicitation modes the client did not advertise (#35839)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Nov 14, 2026 at 20:42 UTC 9791bce79865c0a54d24e940f35569233231231a
2 files changed +89 -21
packages/effect-acp/src/client.test.ts
+57 -3
@@ -388,6 +388,7 @@ it.layer(NodeServices.layer)("effect-acp client", (it) => {
388 clientCapabilities: {
389 fs: { readTextFile: false, writeTextFile: false },
390 terminal: false,
391 + elicitation: { form: {} },
392 },
393 clientInfo: {
394 name: "effect-acp-test",
@@ -486,6 +487,7 @@ it.layer(NodeServices.layer)("effect-acp client", (it) => {
487 clientCapabilities: {
488 fs: { readTextFile: false, writeTextFile: false },
489 terminal: false,
490 + elicitation: { form: {} },
491 },
492 clientInfo: {
493 name: "effect-acp-test",
@@ -541,7 +543,10 @@ it.layer(NodeServices.layer)("effect-acp client", (it) => {
543 Ref.update(updates, (current) => [...current, notification]),
544 );
545
544 - yield* acp.agent.initialize({ protocolVersion: 2 });
546 + yield* acp.agent.initialize({
547 + protocolVersion: 2,
548 + clientCapabilities: { elicitation: { form: {} } },
549 + });
550 yield* acp.agent.authenticate({ methodId: "cursor_login" });
551 const session = yield* acp.agent.createSession({ cwd: process.cwd(), mcpServers: [] });
552 yield* acp.agent.prompt({
@@ -664,6 +669,7 @@ it.layer(NodeServices.layer)("effect-acp client", (it) => {
669 clientCapabilities: {
670 fs: { readTextFile: false, writeTextFile: false },
671 terminal: false,
672 + elicitation: { form: {} },
673 },
674 clientInfo: {
675 name: "effect-acp-test",
@@ -1533,7 +1539,7 @@ it.layer(NodeServices.layer)("effect-acp client", (it) => {
1539 );
1540 yield* acp.agent.initialize({
1541 protocolVersion: 2,
1536 - clientCapabilities: {},
1542 + clientCapabilities: { elicitation: { form: {} } },
1543 clientInfo: { name: "effect-acp-test", version: "0.0.0" },
1544 });
1545 const session = yield* acp.agent.createSession({ cwd: process.cwd(), mcpServers: [] });
@@ -1580,7 +1586,7 @@ it.layer(NodeServices.layer)("effect-acp client", (it) => {
1586 );
1587 yield* acp.agent.initialize({
1588 protocolVersion: 2,
1583 - clientCapabilities: {},
1589 + clientCapabilities: { elicitation: { form: {} } },
1590 clientInfo: { name: "effect-acp-test", version: "0.0.0" },
1591 });
1592 const session = yield* acp.agent.createSession({ cwd: process.cwd(), mcpServers: [] });
@@ -1716,6 +1722,54 @@ it.effect.each(["accept", "decline", "cancel"] as const)(
1722 }),
1723 );
1724
1725 +it.effect.each([1, 2] as const)(
1726 + "rejects a URL elicitation the client did not advertise on wire v%s",
1727 + (wireVersion) =>
1728 + Effect.gen(function* () {
1729 + const { stdio, input, output } = yield* makeInMemoryStdio();
1730 + const acp = yield* AcpClient.make(stdio);
1731 + const init = yield* acp.agent
1732 + .initialize({ protocolVersion: 2, clientCapabilities: { elicitation: { form: {} } } })
1733 + .pipe(Effect.forkChild);
1734 + const initialize = yield* decodeWireResponse(yield* Queue.take(output));
1735 + yield* Queue.offer(
1736 + input,
1737 + yield* encodeJsonl(jsonRpcResponse(Schema.Unknown), {
1738 + jsonrpc: "2.0",
1739 + id: (initialize as { id: number }).id,
1740 + result:
1741 + wireVersion === 2
1742 + ? { protocolVersion: 2, info: { name: "fixture", version: "1" }, capabilities: {} }
1743 + : { protocolVersion: 1, agentCapabilities: {} },
1744 + }),
1745 + );
1746 + yield* Fiber.join(init);
1747 + const calls = yield* Ref.make(0);
1748 + yield* acp.handleElicitation(() =>
1749 + Ref.update(calls, (n) => n + 1).pipe(Effect.as({ action: "accept" as const })),
1750 + );
1751 + yield* Queue.offer(
1752 + input,
1753 + yield* encodeJsonl(jsonRpcRequest("elicitation/create", Schema.Unknown), {
1754 + jsonrpc: "2.0",
1755 + id: 81,
1756 + headers: [],
1757 + method: "elicitation/create",
1758 + params: {
1759 + sessionId: "session-1",
1760 + mode: "url",
1761 + message: "Sign in",
1762 + url: "https://example.test/auth",
1763 + elicitationId: "auth-1",
1764 + },
1765 + }),
1766 + );
1767 + const response = yield* decodeWireError(yield* Queue.take(output));
1768 + assert.equal(response.error.code, -32602);
1769 + assert.equal(yield* Ref.get(calls), 0);
1770 + }).pipe(Effect.scoped),
1771 +);
1772 +
1773 it.effect.each(["elicitation/complete", "session/elicitation/complete"])(
1774 "delivers %s notifications to the completion handler",
1775 (method) =>
packages/effect-acp/src/client.ts
+32 -18
@@ -797,6 +797,7 @@ export const make = Effect.fn("effect-acp/AcpClient.make")(function* (
797 | undefined;
798 let negotiatedProtocolGeneration: 1 | 2 | undefined;
799 let sessionDeleteSupported = false;
800 + let advertisedClientCapabilities: AcpSchema.InitializeRequest["clientCapabilities"] | undefined;
801
802 const runNotificationHandlers = <A>(
803 registration: BufferedNotificationHandler<A>,
@@ -984,6 +985,16 @@ export const make = Effect.fn("effect-acp/AcpClient.make")(function* (
985 cause,
986 ).toProtocolError(),
987 ),
988 + Effect.filterOrFail(
989 + (request) =>
990 + advertisedClientCapabilities === undefined ||
991 + (request.mode !== "form" && request.mode !== "url") ||
992 + advertisedClientCapabilities.elicitation?.[request.mode] != null,
993 + (request) =>
994 + AcpError.AcpRequestError.invalidParams(
995 + `Elicitation mode '${request.mode}' was not advertised by the client.`,
996 + ).toProtocolError(),
997 + ),
998 Effect.flatMap((request) =>
999 runHandler(
1000 coreHandlers.elicitation,
@@ -1088,24 +1099,27 @@ export const make = Effect.fn("effect-acp/AcpClient.make")(function* (
1099 },
1100 agent: {
1101 initialize: (payload) =>
1091 - callRpc(
1092 - AGENT_METHODS.initialize,
1093 - rpc[AGENT_METHODS.initialize](toNegotiatingInitializeRequest(payload)),
1094 - ).pipe(
1095 - Effect.map((response) => {
1096 - // ACP v1 protocolVersion values were not generation identifiers in
1097 - // every shipped agent. Antigravity, for example, reports version 2
1098 - // with the v1 agentInfo/agentCapabilities response shape.
1099 - const isV2 = isV2InitializeResponse(response);
1100 - negotiatedProtocolGeneration = isV2 ? 2 : 1;
1101 - const normalized = isV2
1102 - ? normalizeInitializeResponse(response)
1103 - : (response as AcpSchema.InitializeResponse);
1104 - sessionDeleteSupported =
1105 - normalized.agentCapabilities?.sessionCapabilities?.delete != null;
1106 - return normalized;
1107 - }),
1108 - ),
1102 + Effect.suspend(() => {
1103 + advertisedClientCapabilities = payload.clientCapabilities ?? {};
1104 + return callRpc(
1105 + AGENT_METHODS.initialize,
1106 + rpc[AGENT_METHODS.initialize](toNegotiatingInitializeRequest(payload)),
1107 + ).pipe(
1108 + Effect.map((response) => {
1109 + // ACP v1 protocolVersion values were not generation identifiers in
1110 + // every shipped agent. Antigravity, for example, reports version 2
1111 + // with the v1 agentInfo/agentCapabilities response shape.
1112 + const isV2 = isV2InitializeResponse(response);
1113 + negotiatedProtocolGeneration = isV2 ? 2 : 1;
1114 + const normalized = isV2
1115 + ? normalizeInitializeResponse(response)
1116 + : (response as AcpSchema.InitializeResponse);
1117 + sessionDeleteSupported =
1118 + normalized.agentCapabilities?.sessionCapabilities?.delete != null;
1119 + return normalized;
1120 + }),
1121 + );
1122 + }),
1123 authenticate: (payload) =>
1124 negotiatedProtocolGeneration === 1
1125 ? callRpc(