@@ -238,6 +238,17 @@ private static void ValidateEnvironmentOptions(CopilotClientOptions options, Run
238238 nameof ( options ) ) ;
239239 }
240240
241+ if ( options . WorkingDirectory is not null )
242+ {
243+ throw new ArgumentException (
244+ $ "{ nameof ( CopilotClientOptions ) } .{ nameof ( CopilotClientOptions . WorkingDirectory ) } is not supported with " +
245+ $ "{ nameof ( RuntimeConnection ) } .{ nameof ( RuntimeConnection . ForInProcess ) } (): the in-process transport hosts " +
246+ "the native runtime in the shared host process and spawns the worker without a working-directory " +
247+ "parameter, so a per-client working directory cannot be honored in-process. Use a child-process " +
248+ "transport, or set the process working directory before creating the client." ,
249+ nameof ( options ) ) ;
250+ }
251+
241252 return ;
242253 }
243254
@@ -339,16 +350,49 @@ async Task<Connection> StartCoreAsync(CancellationToken ct)
339350 {
340351 if ( _connection is InProcessRuntimeConnection )
341352 {
342- // In-process FFI hosting: load the Rust cdylib and let it spawn
343- // the CLI worker, instead of the SDK launching a CLI child process.
344- // The worker reads its configuration (telemetry export, etc.) from
345- // the environment passed here, so apply the same telemetry-derived
346- // vars the child-process path sets on its startInfo.Environment.
347- var ffiEnvironment = _options . Environment ? . ToDictionary ( kvp => kvp . Key , kvp => ( string ? ) kvp . Value )
348- ?? new Dictionary < string , string ? > ( ) ;
349- ApplyTelemetryEnvironment ( ffiEnvironment , _options . Telemetry ) ;
350- var resolvedFfiEnvironment = ffiEnvironment . ToDictionary ( kvp => kvp . Key , kvp => kvp . Value ! ) ;
351- var ffiHost = FfiRuntimeHost . Create ( ResolveCliPathForFfi ( ) , GetNapiPrebuildsFolderOrThrow ( ) , resolvedFfiEnvironment , _logger ) ;
353+ var ffiEnvironment = new Dictionary < string , string > ( ) ;
354+ if ( ! string . IsNullOrEmpty ( _options . GitHubToken ) )
355+ {
356+ ffiEnvironment [ "COPILOT_SDK_AUTH_TOKEN" ] = _options . GitHubToken ! ;
357+ }
358+ if ( ! string . IsNullOrEmpty ( _options . BaseDirectory ) )
359+ {
360+ ffiEnvironment [ "COPILOT_HOME" ] = _options . BaseDirectory ! ;
361+ }
362+ if ( _options . Mode == CopilotClientMode . Empty )
363+ {
364+ ffiEnvironment [ "COPILOT_DISABLE_KEYTAR" ] = "1" ;
365+ }
366+
367+ var ffiArgs = new List < string > ( ) ;
368+ if ( _options . LogLevel is { } logLevel && ! string . IsNullOrEmpty ( logLevel . Value ) )
369+ {
370+ ffiArgs . AddRange ( [ "--log-level" , logLevel . Value ] ) ;
371+ }
372+ if ( ! string . IsNullOrEmpty ( _options . GitHubToken ) )
373+ {
374+ ffiArgs . AddRange ( [ "--auth-token-env" , "COPILOT_SDK_AUTH_TOKEN" ] ) ;
375+ }
376+ var useLoggedInUser = _options . UseLoggedInUser ?? string . IsNullOrEmpty ( _options . GitHubToken ) ;
377+ if ( ! useLoggedInUser )
378+ {
379+ ffiArgs . Add ( "--no-auto-login" ) ;
380+ }
381+ if ( _options . SessionIdleTimeoutSeconds is > 0 )
382+ {
383+ ffiArgs . AddRange ( [ "--session-idle-timeout" , _options . SessionIdleTimeoutSeconds . Value . ToString ( CultureInfo . InvariantCulture ) ] ) ;
384+ }
385+ if ( _options . EnableRemoteSessions )
386+ {
387+ ffiArgs . Add ( "--remote" ) ;
388+ }
389+
390+ var ffiHost = FfiRuntimeHost . Create (
391+ ResolveCliPathForFfi ( ) ,
392+ GetNapiPrebuildsFolderOrThrow ( ) ,
393+ ffiEnvironment ,
394+ ffiArgs ,
395+ _logger ) ;
352396 _ffiHost = ffiHost ;
353397 await ffiHost . StartAsync ( ct ) ;
354398 connection = await ConnectToServerAsync ( null , null , null , null , ct , ffiHost ) ;
@@ -1138,6 +1182,7 @@ public async Task<CopilotSession> CreateSessionAsync(SessionConfig config, Cance
11381182 InstructionDirectories : config . InstructionDirectories ,
11391183 PluginDirectories : config . PluginDirectories ,
11401184 LargeOutput : config . LargeOutput ,
1185+ ToolSearch : config . ToolSearch ,
11411186 Memory : config . Memory ,
11421187 Canvases : config . Canvases ,
11431188 RequestCanvasRenderer : config . RequestCanvasRenderer ,
@@ -1349,6 +1394,7 @@ public async Task<CopilotSession> ResumeSessionAsync(string sessionId, ResumeSes
13491394 InstructionDirectories : config . InstructionDirectories ,
13501395 PluginDirectories : config . PluginDirectories ,
13511396 LargeOutput : config . LargeOutput ,
1397+ ToolSearch : config . ToolSearch ,
13521398 Memory : config . Memory ,
13531399 Canvases : config . Canvases ,
13541400 RequestCanvasRenderer : config . RequestCanvasRenderer ,
@@ -2202,7 +2248,12 @@ private static void ApplyTelemetryEnvironment(IDictionary<string, string?> envir
22022248 {
22032249 string os ;
22042250 if ( OperatingSystem . IsWindows ( ) ) os = "win" ;
2205- else if ( OperatingSystem . IsLinux ( ) ) os = "linux" ;
2251+ else if ( OperatingSystem . IsLinux ( ) )
2252+ {
2253+ os = RuntimeInformation . RuntimeIdentifier . StartsWith ( "linux-musl-" , StringComparison . Ordinal )
2254+ ? "linux-musl"
2255+ : "linux" ;
2256+ }
22062257 else if ( OperatingSystem . IsMacOS ( ) ) os = "osx" ;
22072258 else return null ;
22082259
@@ -2249,7 +2300,12 @@ private string ResolveCliPathForFfi()
22492300 {
22502301 string platform ;
22512302 if ( OperatingSystem . IsWindows ( ) ) platform = "win32" ;
2252- else if ( OperatingSystem . IsLinux ( ) ) platform = "linux" ;
2303+ else if ( OperatingSystem . IsLinux ( ) )
2304+ {
2305+ platform = RuntimeInformation . RuntimeIdentifier . StartsWith ( "linux-musl-" , StringComparison . Ordinal )
2306+ ? "linuxmusl"
2307+ : "linux" ;
2308+ }
22532309 else if ( OperatingSystem . IsMacOS ( ) ) platform = "darwin" ;
22542310 else return null ;
22552311
@@ -2690,6 +2746,7 @@ internal record CreateSessionRequest(
26902746 IList < string > ? InstructionDirectories = null ,
26912747 IList < string > ? PluginDirectories = null ,
26922748 LargeToolOutputConfig ? LargeOutput = null ,
2749+ ToolSearchConfig ? ToolSearch = null ,
26932750 MemoryConfiguration ? Memory = null ,
26942751#pragma warning disable GHCP001
26952752 IList < CanvasDeclaration > ? Canvases = null ,
@@ -2794,6 +2851,7 @@ internal record ResumeSessionRequest(
27942851 IList < string > ? InstructionDirectories = null ,
27952852 IList < string > ? PluginDirectories = null ,
27962853 LargeToolOutputConfig ? LargeOutput = null ,
2854+ ToolSearchConfig ? ToolSearch = null ,
27972855 MemoryConfiguration ? Memory = null ,
27982856#pragma warning disable GHCP001
27992857 IList < CanvasDeclaration > ? Canvases = null ,
0 commit comments