@@ -71,6 +71,7 @@ type Client struct {
7171 sessionsMux sync.Mutex
7272 isExternalServer bool
7373 conn interface {} // stores net.Conn for external TCP connections
74+ useStdio bool // resolved value from options
7475 autoStart bool // resolved value from options
7576 autoRestart bool // resolved value from options
7677}
@@ -95,7 +96,6 @@ func NewClient(options *ClientOptions) *Client {
9596 CLIPath : "copilot" ,
9697 Cwd : "" ,
9798 Port : 0 ,
98- UseStdio : true ,
9999 LogLevel : "info" ,
100100 }
101101
@@ -105,13 +105,14 @@ func NewClient(options *ClientOptions) *Client {
105105 sessions : make (map [string ]* Session ),
106106 actualHost : "localhost" ,
107107 isExternalServer : false ,
108+ useStdio : true ,
108109 autoStart : true , // default
109110 autoRestart : true , // default
110111 }
111112
112113 if options != nil {
113114 // Validate mutually exclusive options
114- if options .CLIUrl != "" && (options .UseStdio || options .CLIPath != "" ) {
115+ if options .CLIUrl != "" && (( options .UseStdio != nil && * options . UseStdio ) || options .CLIPath != "" ) {
115116 panic ("CLIUrl is mutually exclusive with UseStdio and CLIPath" )
116117 }
117118
@@ -126,7 +127,7 @@ func NewClient(options *ClientOptions) *Client {
126127 client .actualHost = host
127128 client .actualPort = port
128129 client .isExternalServer = true
129- opts . UseStdio = false
130+ client . useStdio = false
130131 opts .CLIUrl = options .CLIUrl
131132 }
132133
@@ -139,14 +140,17 @@ func NewClient(options *ClientOptions) *Client {
139140 if options .Port > 0 {
140141 opts .Port = options .Port
141142 // If port is specified, switch to TCP mode
142- opts . UseStdio = false
143+ client . useStdio = false
143144 }
144145 if options .LogLevel != "" {
145146 opts .LogLevel = options .LogLevel
146147 }
147148 if len (options .Env ) > 0 {
148149 opts .Env = options .Env
149150 }
151+ if options .UseStdio != nil {
152+ client .useStdio = * options .UseStdio
153+ }
150154 if options .AutoStart != nil {
151155 client .autoStart = * options .AutoStart
152156 }
@@ -1050,7 +1054,7 @@ func (c *Client) startCLIServer() error {
10501054 args := []string {"--server" , "--log-level" , c .options .LogLevel }
10511055
10521056 // Choose transport mode
1053- if c .options . UseStdio {
1057+ if c .useStdio {
10541058 args = append (args , "--stdio" )
10551059 } else if c .options .Port > 0 {
10561060 args = append (args , "--port" , strconv .Itoa (c .options .Port ))
@@ -1096,7 +1100,7 @@ func (c *Client) startCLIServer() error {
10961100 c .process .Env = append (c .process .Env , "COPILOT_SDK_AUTH_TOKEN=" + c .options .GithubToken )
10971101 }
10981102
1099- if c .options . UseStdio {
1103+ if c .useStdio {
11001104 // For stdio mode, we need stdin/stdout pipes
11011105 stdin , err := c .process .StdinPipe ()
11021106 if err != nil {
@@ -1171,7 +1175,7 @@ func (c *Client) startCLIServer() error {
11711175
11721176// connectToServer establishes a connection to the server.
11731177func (c * Client ) connectToServer () error {
1174- if c .options . UseStdio {
1178+ if c .useStdio {
11751179 // Already connected via stdio in startCLIServer
11761180 return nil
11771181 }
0 commit comments