diff --git a/packages/provider-cursor/src/server/adapter.test.ts b/packages/provider-cursor/src/server/adapter.test.ts index cc8afd31311bb..e8c9b0787b21a 100644 --- a/packages/provider-cursor/src/server/adapter.test.ts +++ b/packages/provider-cursor/src/server/adapter.test.ts @@ -1262,11 +1262,13 @@ describe("CursorAdapterV2", () => { ), ); - it.effect("projects subagent directory trees Cursor serialized without empty lists", () => + it.effect("projects subagent search results Cursor serialized with protobuf toJson", () => Effect.gen(function* () { const fileSystem = yield* FileSystem.FileSystem; const path = yield* Path.Path; - const workspace = yield* fileSystem.makeTempDirectoryScoped({ prefix: "cursor-v2-task-ls-" }); + 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" }; @@ -1325,6 +1327,49 @@ describe("CursorAdapterV2", () => { }, }, }, + { + toolCall: { + toolCallId: "tool:grep-files", + grepToolCall: { + args: { pattern: "TODO", outputMode: "files_with_matches" }, + result: { + success: { + pattern: "TODO", + outputMode: "files_with_matches", + workspaceResults: { + [workspace]: { files: { files: ["src/a.ts", "src/b.ts"], totalFiles: 2 } }, + }, + }, + }, + }, + }, + }, + { + toolCall: { + toolCallId: "tool:grep-count", + grepToolCall: { + args: { pattern: "TODO", outputMode: "count" }, + result: { + success: { + pattern: "TODO", + outputMode: "count", + workspaceResults: { + [workspace]: { + count: { + counts: [ + { file: "src/a.ts", count: 1 }, + { file: "src/b.ts", count: 3 }, + ], + totalFiles: 2, + totalMatches: 4, + }, + }, + }, + }, + }, + }, + }, + }, ]; const adapter = yield* makeCursorAdapterV2({ instanceId, @@ -1473,6 +1518,19 @@ describe("CursorAdapterV2", () => { toolName: "mcp__docs__lookup", output: { content: [], isError: false }, }, + { + status: "completed", + pattern: "TODO", + results: [{ fileName: "src/a.ts" }, { fileName: "src/b.ts" }], + }, + { + status: "completed", + pattern: "TODO", + results: [ + { fileName: "src/a.ts", preview: "1 match" }, + { fileName: "src/b.ts", preview: "3 matches" }, + ], + }, ], ); }).pipe( diff --git a/packages/provider-cursor/src/server/adapter.ts b/packages/provider-cursor/src/server/adapter.ts index e5b77e1041d4a..d070ed7375491 100644 --- a/packages/provider-cursor/src/server/adapter.ts +++ b/packages/provider-cursor/src/server/adapter.ts @@ -593,6 +593,46 @@ function nestedGrepWorkspaceResults(success: Record): Record { const workspaceResult = unknownRecord(rawWorkspaceResult); + // GrepUnionResult is a oneof; files and count modes carry no `content`. + const filesResult = unknownRecord(workspaceResult?.files); + if (filesResult !== undefined) { + const files = nestedArray(filesResult.files).filter( + (file): file is string => typeof file === "string", + ); + return [ + workspace, + { + type: "files", + output: { + files, + count: + typeof filesResult.totalFiles === "number" ? filesResult.totalFiles : files.length, + }, + }, + ]; + } + const countResult = unknownRecord(workspaceResult?.count); + if (countResult !== undefined) { + const counts = nestedArray(countResult.counts).flatMap((rawCount) => { + const entry = unknownRecord(rawCount); + return typeof entry?.file === "string" && typeof entry.count === "number" + ? [{ file: entry.file, count: entry.count }] + : []; + }); + return [ + workspace, + { + type: "count", + output: { + counts, + total: + typeof countResult.totalMatches === "number" + ? countResult.totalMatches + : counts.reduce((total, entry) => total + entry.count, 0), + }, + }, + ]; + } const content = unknownRecord(workspaceResult?.content); const rawMatches = Array.isArray(content?.matches) ? content.matches : []; const matches = rawMatches.flatMap((rawFileMatch) => {