@@ -247,6 +247,7 @@ function makeProviderThread(input: {
247247 readonly appThreadId : OrchestrationV2ProviderThread [ "appThreadId" ] ;
248248 readonly providerSessionId : OrchestrationV2ProviderThread [ "providerSessionId" ] ;
249249 readonly nativeThreadId : string ;
250+ readonly storeCwd : string ;
250251 readonly ownerNodeId ?: OrchestrationV2ProviderThread [ "ownerNodeId" ] ;
251252 readonly forkedFrom ?: OrchestrationV2ProviderThread [ "forkedFrom" ] ;
252253 readonly now : DateTime . Utc ;
@@ -267,6 +268,7 @@ function makeProviderThread(input: {
267268 strength : "strong" ,
268269 } ,
269270 nativeConversationHeadRef : null ,
271+ nativeMetadata : { cursorStoreCwd : input . storeCwd } ,
270272 status : "idle" ,
271273 firstRunOrdinal : null ,
272274 lastRunOrdinal : null ,
@@ -960,6 +962,7 @@ interface ActiveCursorTurn {
960962
961963interface CursorLiveAgent {
962964 readonly nativeThreadId : string ;
965+ readonly storeCwd : string ;
963966 readonly session : CursorAgentSdk . CursorAgentSdkSession ;
964967}
965968
@@ -2246,8 +2249,18 @@ export const makeCursorAdapterV2 = Effect.fn("makeCursorAdapterV2")(function* (
22462249 readonly modelSelection : ModelSelection ;
22472250 readonly runtimePolicy : ProviderAdapter . ProviderAdapterV2RuntimePolicy ;
22482251 readonly agentId ?: string ;
2252+ readonly storeCwd ?: string | undefined ;
22492253 } ) {
22502254 const existing = yield * Ref . get ( liveAgent ) ;
2255+ const cwd = openInput . runtimePolicy . cwd ?? process . cwd ( ) ;
2256+ const storeCwd =
2257+ openInput . storeCwd ??
2258+ ( openInput . operation === "resume"
2259+ ? existing !== null && existing . nativeThreadId === openInput . agentId
2260+ ? existing . storeCwd
2261+ : input . resumeFromSession ?. cwd
2262+ : undefined ) ??
2263+ cwd ;
22512264 if (
22522265 existing !== null &&
22532266 openInput . operation === "resume" &&
@@ -2282,13 +2295,15 @@ export const makeCursorAdapterV2 = Effect.fn("makeCursorAdapterV2")(function* (
22822295 . open ( {
22832296 operation : openInput . operation ,
22842297 ...( openInput . agentId === undefined ? { } : { agentId : openInput . agentId } ) ,
2298+ storeCwd,
22852299 options,
22862300 threadId : openInput . threadId ,
22872301 providerSessionId : input . providerSessionId ,
22882302 } )
22892303 . pipe ( Effect . mapError ( classifyCursorModelRejection ( openInput . modelSelection ) ) ) ;
22902304 const next = {
22912305 nativeThreadId : sdkSession . agentId ,
2306+ storeCwd,
22922307 session : sdkSession ,
22932308 } satisfies CursorLiveAgent ;
22942309 yield * Ref . set ( liveAgent , next ) ;
@@ -2400,6 +2415,7 @@ export const makeCursorAdapterV2 = Effect.fn("makeCursorAdapterV2")(function* (
24002415 const agent = yield * openAgent ( {
24012416 operation : "resume" ,
24022417 agentId,
2418+ storeCwd : turnInput . providerThread . nativeMetadata ?. cursorStoreCwd ,
24032419 threadId : turnInput . threadId ,
24042420 modelSelection : turnInput . modelSelection ,
24052421 runtimePolicy : turnInput . runtimePolicy ,
@@ -2655,6 +2671,7 @@ export const makeCursorAdapterV2 = Effect.fn("makeCursorAdapterV2")(function* (
26552671 appThreadId : threadInput . threadId ,
26562672 providerSessionId : input . providerSessionId ,
26572673 nativeThreadId : opened . nativeThreadId ,
2674+ storeCwd : opened . storeCwd ,
26582675 now,
26592676 } ) ;
26602677 } ,
@@ -2673,16 +2690,21 @@ export const makeCursorAdapterV2 = Effect.fn("makeCursorAdapterV2")(function* (
26732690 resumeThread : Effect . fn ( "CursorAdapterV2.resumeThread" ) (
26742691 function * ( threadInput : { readonly providerThread : OrchestrationV2ProviderThread } ) {
26752692 const agentId = nativeThreadId ( threadInput . providerThread ) ;
2676- yield * openAgent ( {
2693+ const opened = yield * openAgent ( {
26772694 operation : "resume" ,
26782695 agentId,
2696+ storeCwd : threadInput . providerThread . nativeMetadata ?. cursorStoreCwd ,
26792697 threadId : threadInput . providerThread . appThreadId ?? input . threadId ,
26802698 modelSelection : input . modelSelection ,
26812699 runtimePolicy : input . runtimePolicy ,
26822700 } ) ;
26832701 const now = yield * DateTime . now ;
26842702 return {
26852703 ...threadInput . providerThread ,
2704+ nativeMetadata : {
2705+ ...threadInput . providerThread . nativeMetadata ,
2706+ cursorStoreCwd : opened . storeCwd ,
2707+ } ,
26862708 providerSessionId : input . providerSessionId ,
26872709 status : "idle" as const ,
26882710 updatedAt : now ,
@@ -2824,6 +2846,7 @@ export const makeCursorAdapterV2 = Effect.fn("makeCursorAdapterV2")(function* (
28242846 const agent = yield * openAgent ( {
28252847 operation : "resume" ,
28262848 agentId : requestedAgentId ,
2849+ storeCwd : snapshotInput . providerThread . nativeMetadata ?. cursorStoreCwd ,
28272850 threadId : snapshotInput . providerThread . appThreadId ?? input . threadId ,
28282851 modelSelection : input . modelSelection ,
28292852 runtimePolicy : input . runtimePolicy ,
0 commit comments