@@ -105,7 +105,7 @@ export async function ensureZCodeBroker(options) {
105105 const endpoint = brokerEndpointFor ( { platform : options . platform , dataRoot : options . dataRoot , workspace : storage . workspacePath , ...( profile ? { identity : profile } : { } ) } ) ;
106106 if ( ( options . platform ?? process . platform ) !== 'win32' ) await unlink ( endpoint ) . catch ( ( ) => { } ) ;
107107 const configPath = join ( brokerDirectory , `config-${ instanceId } .json` ) ;
108- await atomicWriteJson ( configPath , { endpoint, instanceId, brokerToken, launch : options . launch , workspace : storage . workspacePath , idleTimeoutMs : options . idleTimeoutMs , maxFrameBytes : options . maxFrameBytes , maxOutboundBytes : options . maxOutboundBytes , drainTimeoutMs : options . drainTimeoutMs , ownershipPath : join ( brokerDirectory , profile ? `session-owners-${ profile } .json` : 'session-owners.json' ) , identityPath } ) ;
108+ await atomicWriteJson ( configPath , { endpoint, instanceId, brokerToken, launch : options . launch , workspace : storage . workspacePath , launchCwd : ( options . platform ?? process . platform ) === 'win32' ? tmpdir ( ) : storage . workspacePath , idleTimeoutMs : options . idleTimeoutMs , maxFrameBytes : options . maxFrameBytes , maxOutboundBytes : options . maxOutboundBytes , drainTimeoutMs : options . drainTimeoutMs , ownershipPath : join ( brokerDirectory , profile ? `session-owners-${ profile } .json` : 'session-owners.json' ) , identityPath } ) ;
109109 // Keep the daemon's process cwd outside the workspace. Windows holds the
110110 // cwd directory open for the lifetime of the process, which otherwise
111111 // prevents callers from removing short-lived workspace fixtures (and can
@@ -123,7 +123,7 @@ export async function ensureZCodeBroker(options) {
123123}
124124
125125export class ZCodeBroker {
126- /** @param {{endpoint:string,ownershipPath?:string,brokerToken:string,launch:{command:string,args:string[],target?:string},workspace:string,env?:NodeJS.ProcessEnv,idleTimeoutMs?:number,maxFrameBytes?:number,maxOutboundBytes?:number,drainTimeoutMs?:number,instanceId?:string} } options */
126+ /** @param {{endpoint:string,ownershipPath?:string,brokerToken:string,launch:{command:string,args:string[],target?:string},workspace:string,launchCwd?:string, env?:NodeJS.ProcessEnv,idleTimeoutMs?:number,maxFrameBytes?:number,maxOutboundBytes?:number,drainTimeoutMs?:number,instanceId?:string} } options */
127127 constructor ( options ) { if ( typeof options ?. brokerToken !== 'string' || options . brokerToken . length < 32 || ! validWireOption ( options ?. maxFrameBytes , 16 * 1024 * 1024 ) || ! validWireOption ( options ?. maxOutboundBytes , 64 * 1024 * 1024 ) || ! validDrainOption ( options ?. drainTimeoutMs ) || isWindowsNamedPipe ( options ?. endpoint ) && ( typeof options ?. ownershipPath !== 'string' || ! options . ownershipPath ) ) throw brokerInputError ( ) ; this . options = options ; this . ownershipPath = options . ownershipPath ?? `${ options . endpoint } .owners.json` ; this . ownershipStoreEstablished = false ; this . server = null ; this . protocol = null ; this . protocolPromise = null ; this . sockets = new Set ( ) ; this . socketWriters = new WeakMap ( ) ; this . authenticated = new WeakSet ( ) ; this . socketOwnerIds = new WeakMap ( ) ; this . sessionOwners = new Map ( ) ; this . permissionPending = new Map ( ) ; this . localTasks = new Set ( ) ; this . nextPermissionId = 1_000_000_000 ; this . owners = 0 ; this . activeSessions = new Set ( ) ; this . fastIdleRequested = false ; this . idleTimer = null ; this . closing = false ; this . closePromise = null ; }
128128
129129 async start ( ) {
@@ -241,7 +241,7 @@ export class ZCodeBroker {
241241
242242 async getProtocol ( ) {
243243 if ( this . protocol ) return this . protocol ;
244- if ( ! this . protocolPromise ) this . protocolPromise = spawnZCodeProtocol ( this . options . launch , { cwd : this . options . workspace , env : this . options . env , maxFrameBytes : this . options . maxFrameBytes , maxOutboundBytes : this . options . maxOutboundBytes , drainTimeoutMs : this . options . drainTimeoutMs } ) ;
244+ if ( ! this . protocolPromise ) this . protocolPromise = spawnZCodeProtocol ( this . options . launch , { cwd : this . options . launchCwd ?? this . options . workspace , env : this . options . env , maxFrameBytes : this . options . maxFrameBytes , maxOutboundBytes : this . options . maxOutboundBytes , drainTimeoutMs : this . options . drainTimeoutMs } ) ;
245245 const attempt = this . protocolPromise ;
246246 try { const protocol = await attempt ; if ( this . closing ) { await protocol . close ( ) ; throw new PluginError ( 'ZCODE_BROKER_CLOSING' , 'The ZCode broker is closing.' , { category : 'state' , remedy : 'Reconnect to a healthy broker.' } ) ; } this . protocol = protocol ; } catch ( error ) { if ( this . protocolPromise === attempt ) this . protocolPromise = null ; this . protocol = null ; this . scheduleIdleShutdown ( ) ; throw error ; }
247247 this . protocol . subscribe ( ( message ) => {
0 commit comments