@@ -467,10 +467,6 @@ async function ensureDaemonClient(options: { pluginError?: boolean } = {}) {
467467 fail ( "daemon-start-failed" , "Timed out waiting for the Plannotator daemon to start." ) ;
468468}
469469
470- async function runDaemonSessionRequest ( request : PluginRequest ) : Promise < {
471- result : PluginActionResult ;
472- session : PluginSessionInfo ;
473- } > ;
474470function registerDaemonSessionInterruptCleanup ( cancelSession : ( ) => Promise < void > ) : ( ) => void {
475471 let cancelling = false ;
476472 const handleSignal = ( exitCode : number ) => {
@@ -488,13 +484,26 @@ function registerDaemonSessionInterruptCleanup(cancelSession: () => Promise<void
488484 } ;
489485}
490486
487+ async function withProcessCwd < T > ( cwd : string | undefined , fn : ( ) => Promise < T > ) : Promise < T > {
488+ if ( ! cwd ) return fn ( ) ;
489+ const original = process . cwd ( ) ;
490+ const target = path . resolve ( cwd ) ;
491+ if ( target === original ) return fn ( ) ;
492+ process . chdir ( target ) ;
493+ try {
494+ return await fn ( ) ;
495+ } finally {
496+ process . chdir ( original ) ;
497+ }
498+ }
499+
491500async function runDaemonSessionRequest ( request : PluginRequest , options : { pluginError ?: boolean } = { } ) : Promise < {
492501 result : PluginActionResult ;
493502 session : PluginSessionInfo ;
494503} > {
495504 const fail = options . pluginError ? emitPluginError : emitCommandError ;
496505 const daemon = await ensureDaemonClient ( options ) ;
497- const created = await daemon . createSession ( { request, wait : true } ) ;
506+ const created = await daemon . createSession ( { request } ) ;
498507 if ( created . ok !== true ) {
499508 fail ( created . error . code , created . error . message ) ;
500509 }
@@ -520,13 +529,15 @@ async function runDaemonSessionRequest(request: PluginRequest, options: { plugin
520529 }
521530
522531 try {
523- if ( request . action === "review" ) {
524- await handleReviewServerReady ( created . session . url , daemon . state . isRemote , sessionPort ) ;
525- } else if ( request . action === "annotate" || request . action === "annotate-last" ) {
526- await handleAnnotateServerReady ( created . session . url , daemon . state . isRemote , sessionPort ) ;
527- } else {
528- await handleServerReady ( created . session . url , daemon . state . isRemote , sessionPort ) ;
529- }
532+ await withProcessCwd ( request . cwd , async ( ) => {
533+ if ( request . action === "review" ) {
534+ await handleReviewServerReady ( created . session . url , daemon . state . isRemote , sessionPort ) ;
535+ } else if ( request . action === "annotate" || request . action === "annotate-last" ) {
536+ await handleAnnotateServerReady ( created . session . url , daemon . state . isRemote , sessionPort ) ;
537+ } else {
538+ await handleServerReady ( created . session . url , daemon . state . isRemote , sessionPort ) ;
539+ }
540+ } ) ;
530541
531542 const completed = await daemon . waitForResult < PluginActionResult > ( created . session . id ) ;
532543 if ( completed . ok !== true ) {
0 commit comments