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
62 changes: 60 additions & 2 deletions packages/provider-cursor/src/server/adapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" };
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down
40 changes: 40 additions & 0 deletions packages/provider-cursor/src/server/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,46 @@ function nestedGrepWorkspaceResults(success: Record<string, unknown>): Record<st
return Object.fromEntries(
Object.entries(workspaces).map(([workspace, rawWorkspaceResult]) => {
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) => {
Expand Down
Loading