MCPcopy Index your code
hub / github.com/github/copilot-sdk / _start_cli_server

Method _start_cli_server

python/copilot/client.py:3449–3624  ·  view source on GitHub ↗

Start the runtime process. This spawns the runtime as a subprocess using the configured transport mode (stdio or TCP). Raises: RuntimeError: If the server fails to start or times out.

(self)

Source from the content-addressed store, hash-verified

3447 return wire
3448
3449 async def _start_cli_server(self) -> None:
3450 """Start the runtime process.
3451
3452 This spawns the runtime as a subprocess using the configured transport
3453 mode (stdio or TCP).
3454
3455 Raises:
3456 RuntimeError: If the server fails to start or times out.
3457 """
3458 assert isinstance(self._connection, ChildProcessRuntimeConnection)
3459 conn = self._connection
3460 opts = self._options
3461 use_stdio = isinstance(conn, StdioRuntimeConnection)
3462 tcp_port = conn.port if isinstance(conn, TcpRuntimeConnection) else 0
3463
3464 cli_path = conn.path
3465 assert cli_path is not None # resolved in __init__
3466
3467 # Verify CLI exists
3468 if not os.path.exists(cli_path):
3469 original_path = cli_path
3470 if (cli_path := shutil.which(cli_path)) is None:
3471 raise RuntimeError(f"Copilot CLI not found at {original_path}")
3472
3473 # Start with user-provided args, then add SDK-managed args
3474 args = list(conn.args) + [
3475 "--headless",
3476 "--no-auto-update",
3477 "--log-level",
3478 opts.log_level,
3479 ]
3480
3481 # Add auth-related flags
3482 if opts.github_token:
3483 args.extend(["--auth-token-env", "COPILOT_SDK_AUTH_TOKEN"])
3484 if not opts.use_logged_in_user:
3485 args.append("--no-auto-login")
3486
3487 if opts.session_idle_timeout_seconds is not None and opts.session_idle_timeout_seconds > 0:
3488 args.extend(["--session-idle-timeout", str(opts.session_idle_timeout_seconds)])
3489
3490 if opts.enable_remote_sessions:
3491 args.append("--remote")
3492
3493 # If cli_path is a .js file, run it with node
3494 # Note that we can't rely on the shebang as Windows doesn't support it
3495 if cli_path.endswith(".js"):
3496 args = ["node", cli_path] + args
3497 else:
3498 args = [cli_path] + args
3499 logger.info(
3500 "CopilotClient._start_cli_server starting Copilot CLI",
3501 extra={
3502 "cli_path": cli_path,
3503 "executable": args[0],
3504 "cli_path_source": self._cli_path_source,
3505 "use_stdio": use_stdio,
3506 "port": None if use_stdio else tcp_port,

Callers 1

startMethod · 0.95

Calls 3

log_timingFunction · 0.85
appendMethod · 0.80
existsMethod · 0.65

Tested by

no test coverage detected