Skip to content

Commit a5a70a2

Browse files
committed
refactor: change options to _options in CopilotClient for consistency
1 parent f9144f1 commit a5a70a2

File tree

3 files changed

+30
-30
lines changed

3 files changed

+30
-30
lines changed

python/copilot/client.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def __init__(self, options: Optional[CopilotClientOptions] = None):
178178
if use_logged_in_user is None:
179179
use_logged_in_user = False if github_token else True
180180

181-
self.options: CopilotClientOptions = {
181+
self._options: CopilotClientOptions = {
182182
"cli_path": default_cli_path,
183183
"cwd": opts.get("cwd", os.getcwd()),
184184
"port": opts.get("port", 0),
@@ -189,13 +189,13 @@ def __init__(self, options: Optional[CopilotClientOptions] = None):
189189
"use_logged_in_user": use_logged_in_user,
190190
}
191191
if opts.get("cli_args"):
192-
self.options["cli_args"] = opts["cli_args"]
192+
self._options["cli_args"] = opts["cli_args"]
193193
if opts.get("cli_url"):
194-
self.options["cli_url"] = opts["cli_url"]
194+
self._options["cli_url"] = opts["cli_url"]
195195
if opts.get("env"):
196-
self.options["env"] = opts["env"]
196+
self._options["env"] = opts["env"]
197197
if github_token:
198-
self.options["github_token"] = github_token
198+
self._options["github_token"] = github_token
199199

200200
self._process: Optional[subprocess.Popen] = None
201201
self._client: Optional[JsonRpcClient] = None
@@ -448,7 +448,7 @@ async def create_session(self, config: SessionConfig) -> CopilotSession:
448448
... })
449449
"""
450450
if not self._client:
451-
if self.options["auto_start"]:
451+
if self._options["auto_start"]:
452452
await self.start()
453453
else:
454454
raise RuntimeError("Client not connected. Call start() first.")
@@ -620,7 +620,7 @@ async def resume_session(self, session_id: str, config: ResumeSessionConfig) ->
620620
... })
621621
"""
622622
if not self._client:
623-
if self.options["auto_start"]:
623+
if self._options["auto_start"]:
624624
await self.start()
625625
else:
626626
raise RuntimeError("Client not connected. Call start() first.")
@@ -1174,25 +1174,25 @@ async def _start_cli_server(self) -> None:
11741174
Raises:
11751175
RuntimeError: If the server fails to start or times out.
11761176
"""
1177-
cli_path = self.options["cli_path"]
1177+
cli_path = self._options["cli_path"]
11781178

11791179
# Verify CLI exists
11801180
if not os.path.exists(cli_path):
11811181
raise RuntimeError(f"Copilot CLI not found at {cli_path}")
11821182

11831183
# Start with user-provided cli_args, then add SDK-managed args
1184-
cli_args = self.options.get("cli_args") or []
1184+
cli_args = self._options.get("cli_args") or []
11851185
args = list(cli_args) + [
11861186
"--headless",
11871187
"--no-auto-update",
11881188
"--log-level",
1189-
self.options["log_level"],
1189+
self._options["log_level"],
11901190
]
11911191

11921192
# Add auth-related flags
1193-
if self.options.get("github_token"):
1193+
if self._options.get("github_token"):
11941194
args.extend(["--auth-token-env", "COPILOT_SDK_AUTH_TOKEN"])
1195-
if not self.options.get("use_logged_in_user", True):
1195+
if not self._options.get("use_logged_in_user", True):
11961196
args.append("--no-auto-login")
11971197

11981198
# If cli_path is a .js file, run it with node
@@ -1203,21 +1203,21 @@ async def _start_cli_server(self) -> None:
12031203
args = [cli_path] + args
12041204

12051205
# Get environment variables
1206-
env = self.options.get("env")
1206+
env = self._options.get("env")
12071207
if env is None:
12081208
env = dict(os.environ)
12091209
else:
12101210
env = dict(env)
12111211

12121212
# Set auth token in environment if provided
1213-
if self.options.get("github_token"):
1214-
env["COPILOT_SDK_AUTH_TOKEN"] = self.options["github_token"]
1213+
if self._options.get("github_token"):
1214+
env["COPILOT_SDK_AUTH_TOKEN"] = self._options["github_token"]
12151215

12161216
# On Windows, hide the console window to avoid distracting users in GUI apps
12171217
creationflags = subprocess.CREATE_NO_WINDOW if sys.platform == "win32" else 0
12181218

12191219
# Choose transport mode
1220-
if self.options["use_stdio"]:
1220+
if self._options["use_stdio"]:
12211221
args.append("--stdio")
12221222
# Use regular Popen with pipes (buffering=0 for unbuffered)
12231223
self._process = subprocess.Popen(
@@ -1226,25 +1226,25 @@ async def _start_cli_server(self) -> None:
12261226
stdout=subprocess.PIPE,
12271227
stderr=subprocess.PIPE,
12281228
bufsize=0,
1229-
cwd=self.options["cwd"],
1229+
cwd=self._options["cwd"],
12301230
env=env,
12311231
creationflags=creationflags,
12321232
)
12331233
else:
1234-
if self.options["port"] > 0:
1235-
args.extend(["--port", str(self.options["port"])])
1234+
if self._options["port"] > 0:
1235+
args.extend(["--port", str(self._options["port"])])
12361236
self._process = subprocess.Popen(
12371237
args,
12381238
stdin=subprocess.DEVNULL,
12391239
stdout=subprocess.PIPE,
12401240
stderr=subprocess.PIPE,
1241-
cwd=self.options["cwd"],
1241+
cwd=self._options["cwd"],
12421242
env=env,
12431243
creationflags=creationflags,
12441244
)
12451245

12461246
# For stdio mode, we're ready immediately
1247-
if self.options["use_stdio"]:
1247+
if self._options["use_stdio"]:
12481248
return
12491249

12501250
# For TCP mode, wait for port announcement
@@ -1279,7 +1279,7 @@ async def _connect_to_server(self) -> None:
12791279
Raises:
12801280
RuntimeError: If the connection fails.
12811281
"""
1282-
if self.options["use_stdio"]:
1282+
if self._options["use_stdio"]:
12831283
await self._connect_via_stdio()
12841284
else:
12851285
await self._connect_via_tcp()

python/copilot/generated/rpc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,9 +480,9 @@ def to_dict(self) -> dict:
480480

481481
class Mode(Enum):
482482
"""The current agent mode.
483-
483+
484484
The agent mode after switching.
485-
485+
486486
The mode to switch to. Valid values: "interactive", "plan", "autopilot".
487487
"""
488488
AUTOPILOT = "autopilot"

python/test_client.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def test_cli_url_with_cli_path(self):
114114

115115
def test_use_stdio_false_when_cli_url(self):
116116
client = CopilotClient({"cli_url": "8080", "log_level": "error"})
117-
assert not client.options["use_stdio"]
117+
assert not client._options["use_stdio"]
118118

119119
def test_is_external_server_true(self):
120120
client = CopilotClient({"cli_url": "localhost:8080", "log_level": "error"})
@@ -126,17 +126,17 @@ def test_accepts_github_token(self):
126126
client = CopilotClient(
127127
{"cli_path": CLI_PATH, "github_token": "gho_test_token", "log_level": "error"}
128128
)
129-
assert client.options.get("github_token") == "gho_test_token"
129+
assert client._options.get("github_token") == "gho_test_token"
130130

131131
def test_default_use_logged_in_user_true_without_token(self):
132132
client = CopilotClient({"cli_path": CLI_PATH, "log_level": "error"})
133-
assert client.options.get("use_logged_in_user") is True
133+
assert client._options.get("use_logged_in_user") is True
134134

135135
def test_default_use_logged_in_user_false_with_token(self):
136136
client = CopilotClient(
137137
{"cli_path": CLI_PATH, "github_token": "gho_test_token", "log_level": "error"}
138138
)
139-
assert client.options.get("use_logged_in_user") is False
139+
assert client._options.get("use_logged_in_user") is False
140140

141141
def test_explicit_use_logged_in_user_true_with_token(self):
142142
client = CopilotClient(
@@ -147,13 +147,13 @@ def test_explicit_use_logged_in_user_true_with_token(self):
147147
"log_level": "error",
148148
}
149149
)
150-
assert client.options.get("use_logged_in_user") is True
150+
assert client._options.get("use_logged_in_user") is True
151151

152152
def test_explicit_use_logged_in_user_false_without_token(self):
153153
client = CopilotClient(
154154
{"cli_path": CLI_PATH, "use_logged_in_user": False, "log_level": "error"}
155155
)
156-
assert client.options.get("use_logged_in_user") is False
156+
assert client._options.get("use_logged_in_user") is False
157157

158158
def test_github_token_with_cli_url_raises(self):
159159
with pytest.raises(

0 commit comments

Comments
 (0)