@devries-cameron20 / t3code Mirror · read-only / commits / 7e01b5420f
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 22, 08:15 UTC

fix(effect-acp): honor advertised session delete capability (#27771)

Co-authored-by: maria-rcks <maria@kuuro.net>

kamkm committed Nov 1, 2026 at 23:48 UTC 7e01b5420f0c787e515ec3d3d1bd6ddbe48f59aa
2 files changed +108 -9
packages/effect-acp/src/client.test.ts
+94
@@ -1042,6 +1042,100 @@ it.layer(NodeServices.layer)("effect-acp client", (it) => {
1042 }),
1043 );
1044
1045 + it.effect.each([
1046 + { shape: "v1", deleteCapability: {} },
1047 + { shape: "v2", deleteCapability: {} },
1048 + { shape: "v2", deleteCapability: undefined },
1049 + { shape: "v2", deleteCapability: null },
1050 + ])(
1051 + "gates session/delete for $shape with delete=$deleteCapability",
1052 + ({ shape, deleteCapability }) =>
1053 + Effect.gen(function* () {
1054 + const { stdio, input, output } = yield* makeInMemoryStdio();
1055 + const scope = yield* Scope.make();
1056 + const acp = yield* AcpClient.make(stdio).pipe(Effect.provideService(Scope.Scope, scope));
1057 + const deleteSession = acp.agent.deleteSession({ sessionId: "kiro-session-1" });
1058 +
1059 + const initializeFiber = yield* acp.agent
1060 + .initialize({
1061 + protocolVersion: 1,
1062 + clientCapabilities: {
1063 + fs: { readTextFile: false, writeTextFile: false },
1064 + terminal: false,
1065 + },
1066 + clientInfo: { name: "effect-acp-test", version: "0.0.0" },
1067 + })
1068 + .pipe(Effect.forkScoped);
1069 + const initializeRequest = yield* Queue.take(output).pipe(
1070 + Effect.flatMap(Schema.decodeEffect(Schema.fromJsonString(InitializeRequestV1))),
1071 + );
1072 + yield* Queue.offer(
1073 + input,
1074 + shape === "v1"
1075 + ? yield* encodeJsonl(InitializeResponseV1, {
1076 + jsonrpc: "2.0",
1077 + id: initializeRequest.id,
1078 + result: {
1079 + protocolVersion: 1,
1080 + agentInfo: { name: "kiro-acp", version: "0.0.0" },
1081 + agentCapabilities: {
1082 + sessionCapabilities: { list: {}, resume: {}, close: {}, delete: {} },
1083 + },
1084 + },
1085 + })
1086 + : yield* encodeJsonl(InitializeResponse, {
1087 + jsonrpc: "2.0",
1088 + id: initializeRequest.id,
1089 + result: {
1090 + protocolVersion: 2,
1091 + info: { name: "v2-agent", version: "0.0.0" },
1092 + capabilities: {
1093 + session: deleteCapability === undefined ? {} : { delete: deleteCapability },
1094 + },
1095 + },
1096 + }),
1097 + );
1098 + yield* Fiber.join(initializeFiber);
1099 +
1100 + const deleteFailed = yield* Deferred.make<AcpError.AcpError>();
1101 + const deleteFiber = yield* deleteSession.pipe(
1102 + Effect.tapError((error) => Deferred.succeed(deleteFailed, error)),
1103 + Effect.forkScoped,
1104 + );
1105 + const outcome = yield* Effect.raceFirst(
1106 + Queue.take(output).pipe(Effect.map((line) => ({ line }))),
1107 + Deferred.await(deleteFailed).pipe(Effect.map((error) => ({ error }))),
1108 + );
1109 + if ("error" in outcome) {
1110 + if (deleteCapability != null) {
1111 + return yield* outcome.error;
1112 + }
1113 + assert.equal(outcome.error._tag, "AcpRequestError");
1114 + assert.equal(
1115 + outcome.error._tag === "AcpRequestError" ? outcome.error.code : undefined,
1116 + -32601,
1117 + );
1118 + yield* Scope.close(scope, Exit.void);
1119 + return;
1120 + }
1121 + assert.exists(deleteCapability, "session/delete reached transport without its capability");
1122 + const deleteRequest = yield* Schema.decodeEffect(
1123 + Schema.fromJsonString(jsonRpcRequest("session/delete", AcpSchemaV1.DeleteSessionRequest)),
1124 + )(outcome.line);
1125 + assert.equal(deleteRequest.params.sessionId, "kiro-session-1");
1126 + yield* Queue.offer(
1127 + input,
1128 + yield* encodeJsonl(jsonRpcResponse(Schema.Unknown), {
1129 + jsonrpc: "2.0",
1130 + id: deleteRequest.id,
1131 + result: {},
1132 + }),
1133 + );
1134 + assert.deepEqual(yield* Fiber.join(deleteFiber), {});
1135 + yield* Scope.close(scope, Exit.void);
1136 + }),
1137 + );
1138 +
1139 it.effect("preserves exact ids for parallel requests with identical payloads", () =>
1140 Effect.gen(function* () {
1141 const { stdio, input, output } = yield* makeInMemoryStdio();
packages/effect-acp/src/client.ts
+14 -9
@@ -782,6 +782,7 @@ export const make = Effect.fn("effect-acp/AcpClient.make")(function* (
782 | ((method: string, params: unknown) => Effect.Effect<void, AcpError.AcpError>)
783 | undefined;
784 let negotiatedProtocolGeneration: 1 | 2 | undefined;
785 + let sessionDeleteSupported = false;
786
787 const runNotificationHandlers = <A>(
788 registration: BufferedNotificationHandler<A>,
@@ -1081,12 +1082,14 @@ export const make = Effect.fn("effect-acp/AcpClient.make")(function* (
1082 // ACP v1 protocolVersion values were not generation identifiers in
1083 // every shipped agent. Antigravity, for example, reports version 2
1084 // with the v1 agentInfo/agentCapabilities response shape.
1084 - if (isV2InitializeResponse(response)) {
1085 - negotiatedProtocolGeneration = 2;
1086 - return normalizeInitializeResponse(response);
1087 - }
1088 - negotiatedProtocolGeneration = 1;
1089 - return response as AcpSchema.InitializeResponse;
1085 + const isV2 = isV2InitializeResponse(response);
1086 + negotiatedProtocolGeneration = isV2 ? 2 : 1;
1087 + const normalized = isV2
1088 + ? normalizeInitializeResponse(response)
1089 + : (response as AcpSchema.InitializeResponse);
1090 + sessionDeleteSupported =
1091 + normalized.agentCapabilities?.sessionCapabilities?.delete != null;
1092 + return normalized;
1093 }),
1094 ),
1095 authenticate: (payload) =>
@@ -1182,9 +1185,11 @@ export const make = Effect.fn("effect-acp/AcpClient.make")(function* (
1185 Effect.map((response) => response as AcpSchema.CloseSessionResponse),
1186 ),
1187 deleteSession: (payload) =>
1185 - negotiatedProtocolGeneration === 1
1186 - ? Effect.fail(AcpError.AcpRequestError.methodNotFound(AGENT_METHODS.session_delete))
1187 - : callRpc(AGENT_METHODS.session_delete, rpc[AGENT_METHODS.session_delete](payload)),
1188 + Effect.suspend(() =>
1189 + sessionDeleteSupported
1190 + ? callRpc(AGENT_METHODS.session_delete, rpc[AGENT_METHODS.session_delete](payload))
1191 + : Effect.fail(AcpError.AcpRequestError.methodNotFound(AGENT_METHODS.session_delete)),
1192 + ),
1193 listProviders: (payload) =>
1194 negotiatedProtocolGeneration === 1
1195 ? Effect.fail(AcpError.AcpRequestError.methodNotFound(AGENT_METHODS.providers_list))