@@ -1140,6 +1140,227 @@ describe("CursorAdapterV2", () => {
11401140 ) ,
11411141 ) ;
11421142
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+
11431364 it . effect ( "names a custom model Cursor's account catalog rejects" , ( ) =>
11441365 Effect . gen ( function * ( ) {
11451366 const fileSystem = yield * FileSystem . FileSystem ;
0 commit comments