@devries-cameron20 / t3code Mirror · read-only / commits / 37a9ca049c
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, 13:15 UTC

fix(cursor): subagent ls, lint and MCP results no longer fail the parent run (#26592)

Refs pingdotgg/t3code#26486

Julius Marminge committed Oct 28, 2026 at 17:18 UTC 37a9ca049c9ace251835643f134251d25779eaad
2 files changed +304
packages/provider-cursor/src/server/adapter.test.ts
+221
@@ -1140,6 +1140,227 @@ describe("CursorAdapterV2", () => {
1140 ),
1141 );
1142
1143 + it.effect("projects subagent directory trees Cursor serialized without empty lists", () =>
1144 + Effect.gen(function* () {
1145 + const fileSystem = yield* FileSystem.FileSystem;
1146 + const path = yield* Path.Path;
1147 + const workspace = yield* fileSystem.makeTempDirectoryScoped({ prefix: "cursor-v2-task-ls-" });
1148 + const instanceId = ProviderInstanceId.make("cursor");
1149 + const threadId = ThreadId.make("cursor-task-ls-thread");
1150 + const modelSelection = { instanceId, model: "composer-2.5" };
1151 + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
1152 + runtimeMode: "full-access",
1153 + interactionMode: "default",
1154 + cwd: workspace,
1155 + });
1156 + // The SDK serializes subagent steps with protobuf toJson(), which omits empty repeated fields.
1157 + const conversationSteps = [
1158 + {
1159 + toolCall: {
1160 + toolCallId: "tool:ls",
1161 + lsToolCall: {
1162 + args: { path: workspace },
1163 + result: {
1164 + success: {
1165 + directoryTreeRoot: {
1166 + absPath: workspace,
1167 + childrenWereProcessed: true,
1168 + childrenDirs: [
1169 + {
1170 + absPath: path.join(workspace, "src"),
1171 + childrenFiles: [{ name: "index.ts" }],
1172 + childrenWereProcessed: true,
1173 + numFiles: 1,
1174 + },
1175 + ],
1176 + },
1177 + },
1178 + },
1179 + },
1180 + },
1181 + },
1182 + {
1183 + toolCall: {
1184 + toolCallId: "tool:lints",
1185 + readLintsToolCall: { args: {}, result: { success: {} } },
1186 + },
1187 + },
1188 + {
1189 + toolCall: {
1190 + toolCallId: "tool:lints-clean-file",
1191 + readLintsToolCall: {
1192 + args: {},
1193 + result: { success: { fileDiagnostics: [{ path: "src/clean.ts" }] } },
1194 + },
1195 + },
1196 + },
1197 + {
1198 + toolCall: {
1199 + toolCallId: "tool:mcp",
1200 + mcpToolCall: {
1201 + args: { providerIdentifier: "docs", toolName: "lookup", args: { query: "ls" } },
1202 + result: { success: {} },
1203 + },
1204 + },
1205 + },
1206 + ];
1207 + const adapter = yield* makeCursorAdapterV2({
1208 + instanceId,
1209 + environment: { HOME: workspace },
1210 + }).pipe(
1211 + Effect.provideService(CursorAgentSdk.CursorAgentSdkRunner, {
1212 + assertComplete: Effect.void,
1213 + open: () =>
1214 + Effect.succeed({
1215 + agentId: "native-cursor-task-ls",
1216 + listMessages: Effect.succeed([]),
1217 + close: Effect.void,
1218 + send: (input) =>
1219 + Effect.gen(function* () {
1220 + const args = {
1221 + description: "Explore",
1222 + prompt: "List the workspace.",
1223 + subagentType: { kind: "unspecified" as const },
1224 + agentId: "cursor-task-agent",
1225 + mode: "unspecified" as const,
1226 + };
1227 + yield* input.onDelta!({
1228 + type: "tool-call-started",
1229 + modelCallId: "model-call",
1230 + callId: "task-call",
1231 + toolCall: { type: "task", args },
1232 + });
1233 + yield* input.onDelta!({
1234 + type: "tool-call-completed",
1235 + modelCallId: "model-call",
1236 + callId: "task-call",
1237 + toolCall: {
1238 + type: "task",
1239 + args,
1240 + result: {
1241 + status: "success",
1242 + value: {
1243 + conversationSteps,
1244 + isBackground: false,
1245 + backgroundReason: "unspecified",
1246 + },
1247 + },
1248 + },
1249 + });
1250 + return {
1251 + agentId: "native-cursor-task-ls",
1252 + runId: "native-cursor-run",
1253 + wait: Effect.succeed({
1254 + id: "native-cursor-run",
1255 + requestId: "native-request",
1256 + status: "finished" as const,
1257 + model: { id: "composer-2.5" },
1258 + durationMs: 1,
1259 + }),
1260 + cancel: Effect.void,
1261 + };
1262 + }).pipe(Effect.orDie),
1263 + }),
1264 + }),
1265 + Effect.provide(TestProviderHost.layer({ cwd: workspace })),
1266 + );
1267 + const runtime = yield* adapter.openSession({
1268 + threadId,
1269 + providerSessionId: ProviderSessionId.make("cursor-task-ls-session"),
1270 + modelSelection,
1271 + runtimePolicy,
1272 + });
1273 + const providerThread = yield* runtime.ensureThread({
1274 + threadId,
1275 + modelSelection,
1276 + runtimePolicy,
1277 + });
1278 + const now = yield* DateTime.now;
1279 + yield* runtime.startTurn({
1280 + threadId,
1281 + providerThread,
1282 + modelSelection,
1283 + runtimePolicy,
1284 + runId: RunId.make("cursor-task-ls-run"),
1285 + runOrdinal: 1,
1286 + providerTurnOrdinal: 1,
1287 + attemptId: RunAttemptId.make("cursor-task-ls-attempt"),
1288 + rootNodeId: NodeId.make("cursor-task-ls-root"),
1289 + appThread: {
1290 + id: threadId,
1291 + projectId: ProjectId.make("cursor-task-ls-project"),
1292 + createdBy: "user",
1293 + creationSource: "web",
1294 + title: "Cursor subagent ls",
1295 + providerInstanceId: instanceId,
1296 + modelSelection,
1297 + runtimeMode: "full-access",
1298 + interactionMode: "default",
1299 + branch: null,
1300 + worktreePath: null,
1301 + activeProviderThreadId: providerThread.id,
1302 + lineage: { parentThreadId: null, relationshipToParent: null, rootThreadId: threadId },
1303 + forkedFrom: null,
1304 + createdAt: now,
1305 + updatedAt: now,
1306 + archivedAt: null,
1307 + settledOverride: null,
1308 + settledAt: null,
1309 + lastVisitedAt: null,
1310 + deletedAt: null,
1311 + },
1312 + message: {
1313 + messageId: MessageId.make("cursor-task-ls-message"),
1314 + createdBy: "user",
1315 + creationSource: "web",
1316 + text: "List the workspace with a subagent.",
1317 + attachments: [],
1318 + },
1319 + });
1320 + const events = yield* runtime.events.pipe(
1321 + Stream.takeUntil((event) => event.type === "turn.terminal"),
1322 + Stream.runCollect,
1323 + );
1324 + const terminal = events.find((event) => event.type === "turn.terminal");
1325 + assert.equal(terminal?.status, "completed");
1326 + const childThreadId = events.findLast((event) => event.type === "subagent.updated")?.subagent
1327 + .childThreadId;
1328 + assert.isDefined(childThreadId);
1329 + assert.deepEqual(
1330 + events.flatMap((event): ReadonlyArray<unknown> => {
1331 + if (event.type !== "turn_item.updated" || event.turnItem.threadId !== childThreadId) {
1332 + return [];
1333 + }
1334 + const item = event.turnItem;
1335 + return item.type === "file_search"
1336 + ? [{ status: item.status, pattern: item.pattern, results: item.results ?? [] }]
1337 + : item.type === "dynamic_tool"
1338 + ? [{ status: item.status, toolName: item.toolName, output: item.output }]
1339 + : [];
1340 + }),
1341 + [
1342 + {
1343 + status: "completed",
1344 + pattern: workspace,
1345 + results: [{ fileName: path.join(workspace, "src", "index.ts") }],
1346 + },
1347 + { status: "completed", pattern: "", results: [] },
1348 + { status: "completed", pattern: "", results: [] },
1349 + {
1350 + status: "completed",
1351 + toolName: "mcp__docs__lookup",
1352 + output: { content: [], isError: false },
1353 + },
1354 + ],
1355 + );
1356 + }).pipe(
1357 + Effect.scoped,
1358 + Effect.provide(
1359 + Layer.mergeAll(NodeServices.layer, IdAllocator.layer, McpProviderSessions.layer),
1360 + ),
1361 + ),
1362 + );
1363 +
1364 it.effect("names a custom model Cursor's account catalog rejects", () =>
1365 Effect.gen(function* () {
1366 const fileSystem = yield* FileSystem.FileSystem;
packages/provider-cursor/src/server/adapter.ts
+83
@@ -625,6 +625,29 @@ function nestedGrepWorkspaceResults(success: Record<string, unknown>): Record<st
625 );
626 }
627
628 +function nestedArray(value: unknown): ReadonlyArray<unknown> {
629 + return Array.isArray(value) ? value : [];
630 +}
631 +
632 +function nestedLsDirectory(rawNode: unknown): CursorLsDirectoryNode {
633 + const node = unknownRecord(rawNode);
634 + return {
635 + absPath: typeof node?.absPath === "string" ? node.absPath : "",
636 + childrenDirs: nestedArray(node?.childrenDirs).map(nestedLsDirectory),
637 + childrenFiles: nestedArray(node?.childrenFiles).flatMap((rawFile) => {
638 + const name = unknownRecord(rawFile)?.name;
639 + return typeof name === "string" ? [{ name }] : [];
640 + }),
641 + childrenWereProcessed: node?.childrenWereProcessed === true,
642 + fullSubtreeExtensionCounts: Object.fromEntries(
643 + Object.entries(unknownRecord(node?.fullSubtreeExtensionCounts) ?? {}).filter(
644 + (entry): entry is [string, number] => typeof entry[1] === "number",
645 + ),
646 + ),
647 + numFiles: typeof node?.numFiles === "number" ? node.numFiles : 0,
648 + };
649 +}
650 +
651 export function nestedToolCallFromEnvelope(
652 envelope: Record<string, unknown>,
653 ): { readonly callId: string; readonly toolCall: ToolCall } | undefined {
@@ -730,6 +753,66 @@ export function nestedToolCallFromEnvelope(
753 } as unknown as ToolCall,
754 };
755 }
756 + case "lsToolCall":
757 + return {
758 + callId: nestedCallId,
759 + toolCall: {
760 + type: "ls",
761 + args: { path: typeof args.path === "string" ? args.path : "" },
762 + result: nestedToolResult(call.result, (value) => ({
763 + directoryTreeRoot: nestedLsDirectory(value.directoryTreeRoot),
764 + })),
765 + } as unknown as ToolCall,
766 + };
767 + case "readLintsToolCall":
768 + return {
769 + callId: nestedCallId,
770 + toolCall: {
771 + type: "readLints",
772 + args: {
773 + paths: nestedArray(args.paths).filter(
774 + (path): path is string => typeof path === "string",
775 + ),
776 + },
777 + result: nestedToolResult(call.result, (value) => ({
778 + fileDiagnostics: nestedArray(value.fileDiagnostics).map((rawFile) => {
779 + const file = unknownRecord(rawFile);
780 + return {
781 + path: typeof file?.path === "string" ? file.path : "",
782 + diagnostics: nestedArray(file?.diagnostics).flatMap((rawDiagnostic) => {
783 + const diagnostic = unknownRecord(rawDiagnostic);
784 + return diagnostic === undefined
785 + ? []
786 + : [
787 + {
788 + ...diagnostic,
789 + message: typeof diagnostic.message === "string" ? diagnostic.message : "",
790 + },
791 + ];
792 + }),
793 + };
794 + }),
795 + totalFiles: typeof value.totalFiles === "number" ? value.totalFiles : 0,
796 + totalDiagnostics:
797 + typeof value.totalDiagnostics === "number" ? value.totalDiagnostics : 0,
798 + })),
799 + } as unknown as ToolCall,
800 + };
801 + case "mcpToolCall":
802 + return {
803 + callId: nestedCallId,
804 + toolCall: {
805 + type: "mcp",
806 + args,
807 + result: nestedToolResult(call.result, (value) => ({
808 + content: nestedArray(value.content).flatMap((rawPart) => {
809 + const part = unknownRecord(rawPart);
810 + return part === undefined ? [] : [part];
811 + }),
812 + isError: value.isError === true,
813 + })),
814 + } as unknown as ToolCall,
815 + };
816 default: {
817 const type = wrapperName.slice(0, -"ToolCall".length);
818 return {