From c4d394e1d726956f7bda2bdc1ce3ae9f379b257f Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Wed, 28 Oct 2026 13:59:13 +0000 Subject: [PATCH 1/3] test(cursor): reproduce subagent ls trees without empty lists (#26486) These tests reproduce pingdotgg/t3code#26486: Cursor serializes a subagent's conversationSteps with protobuf toJson(), which omits empty childrenFiles/childrenDirs, and projecting the nested ls tool throws. Co-Authored-By: Claude Opus 5.5 --- .../src/server/adapter.test.ts | 180 ++++++++++++++++++ 1 file changed, 180 insertions(+) diff --git a/packages/provider-cursor/src/server/adapter.test.ts b/packages/provider-cursor/src/server/adapter.test.ts index 7ab3aa8c1a3be..0bece360a8de6 100644 --- a/packages/provider-cursor/src/server/adapter.test.ts +++ b/packages/provider-cursor/src/server/adapter.test.ts @@ -988,6 +988,186 @@ describe("CursorAdapterV2", () => { ), ); + it.effect("projects subagent directory trees Cursor serialized without empty lists", () => + Effect.gen(function* () { + const fileSystem = yield* FileSystem.FileSystem; + const path = yield* Path.Path; + const workspace = yield* fileSystem.makeTempDirectoryScoped({ prefix: "cursor-v2-task-ls-" }); + const instanceId = ProviderInstanceId.make("cursor"); + const threadId = ThreadId.make("cursor-task-ls-thread"); + const modelSelection = { instanceId, model: "composer-2.5" }; + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ + runtimeMode: "full-access", + interactionMode: "default", + cwd: workspace, + }); + // The SDK serializes subagent steps with protobuf toJson(), which omits empty repeated fields. + const conversationSteps = [ + { + toolCall: { + toolCallId: "tool:ls", + lsToolCall: { + args: { path: workspace }, + result: { + success: { + directoryTreeRoot: { + absPath: workspace, + childrenWereProcessed: true, + childrenDirs: [ + { + absPath: path.join(workspace, "src"), + childrenFiles: [{ name: "index.ts" }], + childrenWereProcessed: true, + numFiles: 1, + }, + ], + }, + }, + }, + }, + }, + }, + ]; + const adapter = yield* makeCursorAdapterV2({ + instanceId, + environment: { HOME: workspace }, + }).pipe( + Effect.provideService(CursorAgentSdk.CursorAgentSdkRunner, { + assertComplete: Effect.void, + open: () => + Effect.succeed({ + agentId: "native-cursor-task-ls", + listMessages: Effect.succeed([]), + close: Effect.void, + send: (input) => + Effect.gen(function* () { + const args = { + description: "Explore", + prompt: "List the workspace.", + subagentType: { kind: "unspecified" as const }, + agentId: "cursor-task-agent", + mode: "unspecified" as const, + }; + yield* input.onDelta!({ + type: "tool-call-started", + modelCallId: "model-call", + callId: "task-call", + toolCall: { type: "task", args }, + }); + yield* input.onDelta!({ + type: "tool-call-completed", + modelCallId: "model-call", + callId: "task-call", + toolCall: { + type: "task", + args, + result: { + status: "success", + value: { + conversationSteps, + isBackground: false, + backgroundReason: "unspecified", + }, + }, + }, + }); + return { + agentId: "native-cursor-task-ls", + runId: "native-cursor-run", + wait: Effect.succeed({ + id: "native-cursor-run", + requestId: "native-request", + status: "finished" as const, + model: { id: "composer-2.5" }, + durationMs: 1, + }), + cancel: Effect.void, + }; + }).pipe(Effect.orDie), + }), + }), + Effect.provide(TestProviderHost.layer({ cwd: workspace })), + ); + const runtime = yield* adapter.openSession({ + threadId, + providerSessionId: ProviderSessionId.make("cursor-task-ls-session"), + modelSelection, + runtimePolicy, + }); + const providerThread = yield* runtime.ensureThread({ + threadId, + modelSelection, + runtimePolicy, + }); + const now = yield* DateTime.now; + yield* runtime.startTurn({ + threadId, + providerThread, + modelSelection, + runtimePolicy, + runId: RunId.make("cursor-task-ls-run"), + runOrdinal: 1, + providerTurnOrdinal: 1, + attemptId: RunAttemptId.make("cursor-task-ls-attempt"), + rootNodeId: NodeId.make("cursor-task-ls-root"), + appThread: { + id: threadId, + projectId: ProjectId.make("cursor-task-ls-project"), + createdBy: "user", + creationSource: "web", + title: "Cursor subagent ls", + providerInstanceId: instanceId, + modelSelection, + runtimeMode: "full-access", + interactionMode: "default", + branch: null, + worktreePath: null, + activeProviderThreadId: providerThread.id, + lineage: { parentThreadId: null, relationshipToParent: null, rootThreadId: threadId }, + forkedFrom: null, + createdAt: now, + updatedAt: now, + archivedAt: null, + settledOverride: null, + settledAt: null, + lastVisitedAt: null, + deletedAt: null, + }, + message: { + messageId: MessageId.make("cursor-task-ls-message"), + createdBy: "user", + creationSource: "web", + text: "List the workspace with a subagent.", + attachments: [], + }, + }); + const events = yield* runtime.events.pipe( + Stream.takeUntil((event) => event.type === "turn.terminal"), + Stream.runCollect, + ); + const terminal = events.find((event) => event.type === "turn.terminal"); + assert.equal(terminal?.status, "completed"); + const childThreadId = events.findLast((event) => event.type === "subagent.updated")?.subagent + .childThreadId; + assert.isDefined(childThreadId); + assert.deepEqual( + events.flatMap((event) => + event.type === "turn_item.updated" && + event.turnItem.type === "file_search" && + event.turnItem.threadId === childThreadId + ? [{ status: event.turnItem.status, results: event.turnItem.results }] + : [], + ), + [{ status: "completed", results: [{ fileName: path.join(workspace, "src", "index.ts") }] }], + ); + }).pipe( + Effect.scoped, + Effect.provide( + Layer.mergeAll(NodeServices.layer, IdAllocator.layer, McpProviderSessions.layer), + ), + ), + ); + it.effect("names a custom model Cursor's account catalog rejects", () => Effect.gen(function* () { const fileSystem = yield* FileSystem.FileSystem; From 86ee857c8cd1985eae59e789514b7d8afc25c452 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Wed, 28 Oct 2026 15:16:35 +0000 Subject: [PATCH 2/3] fix(cursor): subagent ls, lint and MCP results no longer fail the parent run Cursor serializes a subagent task's conversationSteps with protobuf toJson(), which omits empty repeated fields. Nested ls, readLints and mcp results fell through nestedToolCallFromEnvelope raw, so projecting them threw on the missing lists and failed the whole parent run. Normalize those three types where the untyped JSON enters, the way the SDK's own converter does: rebuild ls directory trees with childrenDirs and childrenFiles defaulted to [], and default readLints paths/fileDiagnostics/ diagnostics and mcp content to []. Fixes pingdotgg/t3code#26486 Co-Authored-By: Claude Opus 5.5 --- .../src/server/adapter.test.ts | 47 +++++++++-- .../provider-cursor/src/server/adapter.ts | 83 +++++++++++++++++++ 2 files changed, 122 insertions(+), 8 deletions(-) diff --git a/packages/provider-cursor/src/server/adapter.test.ts b/packages/provider-cursor/src/server/adapter.test.ts index 0bece360a8de6..b427a8e4fad1a 100644 --- a/packages/provider-cursor/src/server/adapter.test.ts +++ b/packages/provider-cursor/src/server/adapter.test.ts @@ -1027,6 +1027,21 @@ describe("CursorAdapterV2", () => { }, }, }, + { + toolCall: { + toolCallId: "tool:lints", + readLintsToolCall: { args: {}, result: { success: {} } }, + }, + }, + { + toolCall: { + toolCallId: "tool:mcp", + mcpToolCall: { + args: { providerIdentifier: "docs", toolName: "lookup", args: { query: "ls" } }, + result: { success: {} }, + }, + }, + }, ]; const adapter = yield* makeCursorAdapterV2({ instanceId, @@ -1151,14 +1166,30 @@ describe("CursorAdapterV2", () => { .childThreadId; assert.isDefined(childThreadId); assert.deepEqual( - events.flatMap((event) => - event.type === "turn_item.updated" && - event.turnItem.type === "file_search" && - event.turnItem.threadId === childThreadId - ? [{ status: event.turnItem.status, results: event.turnItem.results }] - : [], - ), - [{ status: "completed", results: [{ fileName: path.join(workspace, "src", "index.ts") }] }], + events.flatMap((event): ReadonlyArray => { + if (event.type !== "turn_item.updated" || event.turnItem.threadId !== childThreadId) { + return []; + } + const item = event.turnItem; + return item.type === "file_search" + ? [{ status: item.status, pattern: item.pattern, results: item.results ?? [] }] + : item.type === "dynamic_tool" + ? [{ status: item.status, toolName: item.toolName, output: item.output }] + : []; + }), + [ + { + status: "completed", + pattern: workspace, + results: [{ fileName: path.join(workspace, "src", "index.ts") }], + }, + { status: "completed", pattern: "", results: [] }, + { + status: "completed", + toolName: "mcp__docs__lookup", + output: { content: [], isError: false }, + }, + ], ); }).pipe( Effect.scoped, diff --git a/packages/provider-cursor/src/server/adapter.ts b/packages/provider-cursor/src/server/adapter.ts index 915c646be3001..1d5d72f76d668 100644 --- a/packages/provider-cursor/src/server/adapter.ts +++ b/packages/provider-cursor/src/server/adapter.ts @@ -625,6 +625,29 @@ function nestedGrepWorkspaceResults(success: Record): Record { + return Array.isArray(value) ? value : []; +} + +function nestedLsDirectory(rawNode: unknown): CursorLsDirectoryNode { + const node = unknownRecord(rawNode); + return { + absPath: typeof node?.absPath === "string" ? node.absPath : "", + childrenDirs: nestedArray(node?.childrenDirs).map(nestedLsDirectory), + childrenFiles: nestedArray(node?.childrenFiles).flatMap((rawFile) => { + const name = unknownRecord(rawFile)?.name; + return typeof name === "string" ? [{ name }] : []; + }), + childrenWereProcessed: node?.childrenWereProcessed === true, + fullSubtreeExtensionCounts: Object.fromEntries( + Object.entries(unknownRecord(node?.fullSubtreeExtensionCounts) ?? {}).filter( + (entry): entry is [string, number] => typeof entry[1] === "number", + ), + ), + numFiles: typeof node?.numFiles === "number" ? node.numFiles : 0, + }; +} + export function nestedToolCallFromEnvelope( envelope: Record, ): { readonly callId: string; readonly toolCall: ToolCall } | undefined { @@ -730,6 +753,66 @@ export function nestedToolCallFromEnvelope( } as unknown as ToolCall, }; } + case "lsToolCall": + return { + callId: nestedCallId, + toolCall: { + type: "ls", + args: { path: typeof args.path === "string" ? args.path : "" }, + result: nestedToolResult(call.result, (value) => ({ + directoryTreeRoot: nestedLsDirectory(value.directoryTreeRoot), + })), + } as unknown as ToolCall, + }; + case "readLintsToolCall": + return { + callId: nestedCallId, + toolCall: { + type: "readLints", + args: { + paths: nestedArray(args.paths).filter( + (path): path is string => typeof path === "string", + ), + }, + result: nestedToolResult(call.result, (value) => ({ + fileDiagnostics: nestedArray(value.fileDiagnostics).map((rawFile) => { + const file = unknownRecord(rawFile); + return { + path: typeof file?.path === "string" ? file.path : "", + diagnostics: nestedArray(file?.diagnostics).flatMap((rawDiagnostic) => { + const diagnostic = unknownRecord(rawDiagnostic); + return diagnostic === undefined + ? [] + : [ + { + ...diagnostic, + message: typeof diagnostic.message === "string" ? diagnostic.message : "", + }, + ]; + }), + }; + }), + totalFiles: typeof value.totalFiles === "number" ? value.totalFiles : 0, + totalDiagnostics: + typeof value.totalDiagnostics === "number" ? value.totalDiagnostics : 0, + })), + } as unknown as ToolCall, + }; + case "mcpToolCall": + return { + callId: nestedCallId, + toolCall: { + type: "mcp", + args, + result: nestedToolResult(call.result, (value) => ({ + content: nestedArray(value.content).flatMap((rawPart) => { + const part = unknownRecord(rawPart); + return part === undefined ? [] : [part]; + }), + isError: value.isError === true, + })), + } as unknown as ToolCall, + }; default: { const type = wrapperName.slice(0, -"ToolCall".length); return { From 97aef0d3289b8d4518f454a7aabc7932f4f2b9bc Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Wed, 28 Oct 2026 15:26:31 +0000 Subject: [PATCH 3/3] test(cursor): cover a subagent lint file without its diagnostics list Co-Authored-By: Claude Opus 5.5 --- packages/provider-cursor/src/server/adapter.test.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/provider-cursor/src/server/adapter.test.ts b/packages/provider-cursor/src/server/adapter.test.ts index b427a8e4fad1a..ada5d7966e52e 100644 --- a/packages/provider-cursor/src/server/adapter.test.ts +++ b/packages/provider-cursor/src/server/adapter.test.ts @@ -1033,6 +1033,15 @@ describe("CursorAdapterV2", () => { readLintsToolCall: { args: {}, result: { success: {} } }, }, }, + { + toolCall: { + toolCallId: "tool:lints-clean-file", + readLintsToolCall: { + args: {}, + result: { success: { fileDiagnostics: [{ path: "src/clean.ts" }] } }, + }, + }, + }, { toolCall: { toolCallId: "tool:mcp", @@ -1184,6 +1193,7 @@ describe("CursorAdapterV2", () => { results: [{ fileName: path.join(workspace, "src", "index.ts") }], }, { status: "completed", pattern: "", results: [] }, + { status: "completed", pattern: "", results: [] }, { status: "completed", toolName: "mcp__docs__lookup",