Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ Event types: `SessionLifecycleCreated`, `SessionLifecycleDeleted`, `SessionLifec
**ClientOptions:**

- `CLIPath` (string): Path to CLI executable (default: "copilot" or `COPILOT_CLI_PATH` env var)
- `CLIArgs` ([]string): Extra arguments to pass to the CLI executable (inserted before SDK-managed args)
- `CLIUrl` (string): URL of existing CLI server (e.g., `"localhost:8080"`, `"http://127.0.0.1:9000"`, or just `"8080"`). When provided, the client will not spawn a CLI process.
- `Cwd` (string): Working directory for CLI process
- `Port` (int): Server port for TCP mode (default: 0 for random)
Expand Down
9 changes: 8 additions & 1 deletion go/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ func NewClient(options *ClientOptions) *Client {
if options.CLIPath != "" {
opts.CLIPath = options.CLIPath
}
if options.CLIArgs != nil {
opts.CLIArgs = append([]string{}, options.CLIArgs...)
}
if options.Cwd != "" {
opts.Cwd = options.Cwd
}
Expand Down Expand Up @@ -994,7 +997,11 @@ func (c *Client) verifyProtocolVersion(ctx context.Context) error {
// This spawns the CLI server as a subprocess using the configured transport
// mode (stdio or TCP).
func (c *Client) startCLIServer(ctx context.Context) error {
args := []string{"--headless", "--no-auto-update", "--log-level", c.options.LogLevel}
// Start with user-provided CLI args (inserted before SDK-managed args)
args := append([]string{}, c.options.CLIArgs...)

// Add SDK-managed args
args = append(args, "--headless", "--no-auto-update", "--log-level", c.options.LogLevel)

// Choose transport mode
if c.useStdio {
Expand Down
52 changes: 52 additions & 0 deletions go/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,58 @@ func TestClient_AuthOptions(t *testing.T) {
})
}

func TestClient_CLIArgs(t *testing.T) {
t.Run("should default CLIArgs to nil when not provided", func(t *testing.T) {
client := NewClient(&ClientOptions{})

if client.options.CLIArgs != nil {
t.Errorf("Expected CLIArgs to be nil, got %v", client.options.CLIArgs)
}
})

t.Run("should accept CLIArgs option", func(t *testing.T) {
args := []string{"--custom-flag", "--another-arg", "value"}
client := NewClient(&ClientOptions{
CLIArgs: args,
})

if !reflect.DeepEqual(client.options.CLIArgs, args) {
t.Errorf("Expected CLIArgs to be %v, got %v", args, client.options.CLIArgs)
}
})

t.Run("should store empty CLIArgs slice", func(t *testing.T) {
client := NewClient(&ClientOptions{
CLIArgs: []string{},
})

if client.options.CLIArgs == nil {
t.Error("Expected CLIArgs to be non-nil empty slice")
}
if len(client.options.CLIArgs) != 0 {
t.Errorf("Expected 0 CLI args, got %d", len(client.options.CLIArgs))
}
})

t.Run("should store a copy of CLIArgs slice", func(t *testing.T) {
args := []string{"--custom-flag"}
client := NewClient(&ClientOptions{
CLIArgs: args,
})

// Modify the original slice
args = append(args, "--another-flag")

// The client's copy should not be affected
if len(client.options.CLIArgs) != 1 {
t.Errorf("Expected 1 CLI arg, got %d", len(client.options.CLIArgs))
}
if client.options.CLIArgs[0] != "--custom-flag" {
t.Errorf("Expected first arg to be '--custom-flag', got %q", client.options.CLIArgs[0])
}
})
}

func TestClient_EnvOptions(t *testing.T) {
t.Run("should store custom environment variables", func(t *testing.T) {
client := NewClient(&ClientOptions{
Expand Down
2 changes: 2 additions & 0 deletions go/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const (
type ClientOptions struct {
// CLIPath is the path to the Copilot CLI executable (default: "copilot")
CLIPath string
// CLIArgs are extra arguments to pass to the CLI executable (inserted before SDK-managed args)
CLIArgs []string
// Cwd is the working directory for the CLI process (default: "" = inherit from current process)
Cwd string
// Port for TCP transport (default: 0 = random port)
Expand Down
1 change: 1 addition & 0 deletions python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ await client.stop()
**CopilotClient Options:**

- `cli_path` (str): Path to CLI executable (default: "copilot" or `COPILOT_CLI_PATH` env var)
- `cli_args` (list[str]): Extra arguments to pass to the CLI executable (inserted before SDK-managed args)
- `cli_url` (str): URL of existing CLI server (e.g., `"localhost:8080"`, `"http://127.0.0.1:9000"`, or just `"8080"`). When provided, the client will not spawn a CLI process.
- `cwd` (str): Working directory for CLI process
- `port` (int): Server port for TCP mode (default: 0 for random)
Expand Down
7 changes: 6 additions & 1 deletion python/copilot/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ def __init__(self, options: Optional[CopilotClientOptions] = None):

self.options: CopilotClientOptions = {
"cli_path": default_cli_path,
"cli_args": list(opts.get("cli_args", [])),
"cwd": opts.get("cwd", os.getcwd()),
"port": opts.get("port", 0),
"use_stdio": False if opts.get("cli_url") else opts.get("use_stdio", True),
Expand Down Expand Up @@ -1116,7 +1117,11 @@ async def _start_cli_server(self) -> None:
if not os.path.exists(cli_path):
raise RuntimeError(f"Copilot CLI not found at {cli_path}")

args = ["--headless", "--no-auto-update", "--log-level", self.options["log_level"]]
# Start with user-provided CLI args (inserted before SDK-managed args)
args = list(self.options.get("cli_args", []))

# Add SDK-managed args
args.extend(["--headless", "--no-auto-update", "--log-level", self.options["log_level"]])

# Add auth-related flags
if self.options.get("github_token"):
Expand Down
1 change: 1 addition & 0 deletions python/copilot/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class CopilotClientOptions(TypedDict, total=False):
"""Options for creating a CopilotClient"""

cli_path: str # Path to the Copilot CLI executable (default: "copilot")
cli_args: list[str] # Extra arguments to pass to the CLI executable (inserted before SDK-managed args)
# Working directory for the CLI process (default: current process's cwd)
cwd: str
port: int # Port for the CLI server (TCP mode only, default: 0)
Expand Down
23 changes: 23 additions & 0 deletions python/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,26 @@ def test_use_logged_in_user_with_cli_url_raises(self):
CopilotClient(
{"cli_url": "localhost:8080", "use_logged_in_user": False, "log_level": "error"}
)


class TestCliArgs:
def test_default_cli_args_empty_list(self):
client = CopilotClient({"cli_path": CLI_PATH, "log_level": "error"})
assert client.options.get("cli_args") == []

def test_accepts_cli_args(self):
cli_args = ["--custom-flag", "--another-arg", "value"]
client = CopilotClient(
{"cli_path": CLI_PATH, "cli_args": cli_args, "log_level": "error"}
)
assert client.options.get("cli_args") == cli_args

def test_cli_args_list_is_separate_copy(self):
cli_args = ["--custom-flag"]
client = CopilotClient(
{"cli_path": CLI_PATH, "cli_args": cli_args, "log_level": "error"}
)
# Modifying the original list should not affect the client's copy
cli_args.append("--another-flag")
assert client.options.get("cli_args") == ["--custom-flag"]