Skip to content
Merged
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
2 changes: 1 addition & 1 deletion docs/features/mcp.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func main() {
"my-local-server": copilot.MCPStdioServerConfig{
Command: "node",
Args: []string{"./mcp-server.js"},
Tools: []string{"*"},
Tools: &[]string{"*"},
},
},
})
Expand Down
2 changes: 1 addition & 1 deletion docs/features/streaming-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func main() {

session, _ := client.CreateSession(ctx, &copilot.SessionConfig{
Model: "gpt-4.1",
Streaming: true,
Streaming: copilot.Bool(true),
OnPermissionRequest: func(req copilot.PermissionRequest, inv copilot.PermissionInvocation) (copilot.PermissionRequestResult, error) {
return copilot.PermissionRequestResult{Kind: copilot.PermissionRequestResultKindApproved}, nil
},
Expand Down
12 changes: 6 additions & 6 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ func main() {

session, err := client.CreateSession(ctx, &copilot.SessionConfig{
Model: "gpt-4.1",
Streaming: true,
Streaming: copilot.Bool(true),
})
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -1046,7 +1046,7 @@ func main() {

session, err := client.CreateSession(ctx, &copilot.SessionConfig{
Model: "gpt-4.1",
Streaming: true,
Streaming: copilot.Bool(true),
Tools: []copilot.Tool{getWeather},
})
if err != nil {
Expand Down Expand Up @@ -1482,7 +1482,7 @@ func main() {

session, err := client.CreateSession(ctx, &copilot.SessionConfig{
Model: "gpt-4.1",
Streaming: true,
Streaming: copilot.Bool(true),
Tools: []copilot.Tool{getWeather},
})
if err != nil {
Expand Down Expand Up @@ -2001,7 +2001,7 @@ func main() {
ctx := context.Background()

client := copilot.NewClient(&copilot.ClientOptions{
CLIUrl: "localhost:4321",
Connection: copilot.UriConnection{URL: "localhost:4321"},
})

if err := client.Start(ctx); err != nil {
Expand All @@ -2021,7 +2021,7 @@ func main() {
import copilot "github.com/github/copilot-sdk/go"

client := copilot.NewClient(&copilot.ClientOptions{
CLIUrl: "localhost:4321",
Connection: copilot.UriConnection{URL: "localhost:4321"},
})

if err := client.Start(ctx); err != nil {
Expand Down Expand Up @@ -2105,7 +2105,7 @@ var session = client.createSession(

</details>

**Note:** When `cli_url` / `cliUrl` / `CLIUrl` is provided, or Rust uses `Transport::External`, the SDK will not spawn or manage a CLI process - it will only connect to the existing server at the specified URL.
**Note:** When `cli_url` / `cliUrl` / Go's `UriConnection` is provided, or Rust uses `Transport::External`, the SDK will not spawn or manage a CLI process - it will only connect to the existing server at the specified URL.

## Telemetry and observability

Expand Down
6 changes: 3 additions & 3 deletions docs/setup/backend-services.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Run the Copilot SDK in server-side applications—APIs, web backends, microservi

## How it works

Instead of the SDK spawning a CLI child process, you run the CLI independently in **headless server mode**. Your backend connects to it over TCP using the `cliUrl` option.
Instead of the SDK spawning a CLI child process, you run the CLI independently in **headless server mode**. Your backend connects to it over TCP using the `Connection` option (`UriConnection`).

```mermaid
flowchart TB
Expand Down Expand Up @@ -177,7 +177,7 @@ func main() {
message := "Hello"

client := copilot.NewClient(&copilot.ClientOptions{
CLIUrl: "localhost:4321",
Connection: copilot.UriConnection{URL: "localhost:4321"},
})
client.Start(ctx)
defer client.Stop()
Expand All @@ -195,7 +195,7 @@ func main() {

```go
client := copilot.NewClient(&copilot.ClientOptions{
CLIUrl:"localhost:4321",
Connection: copilot.UriConnection{URL: "localhost:4321"},
})
client.Start(ctx)
defer client.Stop()
Expand Down
4 changes: 2 additions & 2 deletions docs/setup/bundled-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ await client.stop()
<summary><strong>Go</strong></summary>

> [!NOTE]
> The Go SDK does not bundle the CLI. You must install the CLI separately or set `CLIPath` to point to an existing binary. See [Local CLI Setup](./local-cli.md) for details.
> The Go SDK does not bundle the CLI. You must install the CLI separately or set `Connection` to point to an existing binary. See [Local CLI Setup](./local-cli.md) for details.

<!-- docs-validate: hidden -->
```go
Expand Down Expand Up @@ -137,7 +137,7 @@ Console.WriteLine(response?.Data.Content);
<summary><strong>Java</strong></summary>

> [!NOTE]
> The Java SDK does not bundle or embed the Copilot CLI. You must install the CLI separately and configure its path via `cliPath` or the `COPILOT_CLI_PATH` environment variable.
> The Java SDK does not bundle or embed the Copilot CLI. You must install the CLI separately and configure its path via `Connection` or the `COPILOT_CLI_PATH` environment variable.

```java
import com.github.copilot.sdk.CopilotClient;
Expand Down
8 changes: 4 additions & 4 deletions docs/setup/local-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Use a specific CLI binary instead of the SDK's bundled CLI. This is an advanced

## How it works

By default, the Node.js, Python, and .NET SDKs include their own CLI dependency (see [Default Setup](./bundled-cli.md)). If you need to override this—for example, to use a system-installed CLI—you can use the `cliPath` option.
By default, the Node.js, Python, and .NET SDKs include their own CLI dependency (see [Default Setup](./bundled-cli.md)). If you need to override this—for example, to use a system-installed CLI—you can use the `Connection` option.

```mermaid
flowchart LR
Expand Down Expand Up @@ -78,7 +78,7 @@ await client.stop()
<summary><strong>Go</strong></summary>

> [!NOTE]
> The Go SDK does not bundle a CLI, so you must always provide `CLIPath`.
> The Go SDK does not bundle a CLI, so you must always provide `Connection`.

<!-- docs-validate: hidden -->
```go
Expand All @@ -95,7 +95,7 @@ func main() {
ctx := context.Background()

client := copilot.NewClient(&copilot.ClientOptions{
CLIPath: "/usr/local/bin/copilot",
Connection: copilot.StdioConnection{Path: "/usr/local/bin/copilot"},
})
if err := client.Start(ctx); err != nil {
log.Fatal(err)
Expand All @@ -115,7 +115,7 @@ func main() {

```go
client := copilot.NewClient(&copilot.ClientOptions{
CLIPath: "/usr/local/bin/copilot",
Connection: copilot.StdioConnection{Path: "/usr/local/bin/copilot"},
})
if err := client.Start(ctx); err != nil {
log.Fatal(err)
Expand Down
21 changes: 14 additions & 7 deletions docs/troubleshooting/debugging.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,25 @@ const client = new CopilotClient({
```go
package main

import copilot "github.com/github/copilot-sdk/go"

func main() {
// The Go SDK does not currently support passing extra CLI arguments.
// For custom log directories, run the CLI manually with --log-dir
// and connect via CLIUrl option.
client := copilot.NewClient(&copilot.ClientOptions{
Connection: copilot.StdioConnection{
Args: []string{"--log-dir", "/path/to/logs"},
},
})
_ = client
}
Comment thread
SteveSandersonMS marked this conversation as resolved.
```
<!-- /docs-validate: hidden -->

```go
// The Go SDK does not currently support passing extra CLI arguments.
// For custom log directories, run the CLI manually with --log-dir
// and connect via CLIUrl option.
client := copilot.NewClient(&copilot.ClientOptions{
Connection: copilot.StdioConnection{
Args: []string{"--log-dir", "/path/to/logs"},
},
})
```

</details>
Expand Down Expand Up @@ -221,7 +228,7 @@ var client = new CopilotClient(new CopilotClientOptions

```go
client := copilot.NewClient(&copilot.ClientOptions{
CLIPath: "/usr/local/bin/copilot",
Connection: copilot.StdioConnection{Path: "/usr/local/bin/copilot"},
})
```
</details>
Expand Down
43 changes: 22 additions & 21 deletions go/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Follow these steps to embed the CLI:
1. Run `go get -tool github.com/github/copilot-sdk/go/cmd/bundler`. This is a one-time setup step per project.
2. Run `go tool bundler` in your build environment just before building your application.

That's it! When your application calls `copilot.NewClient` without a `CLIPath` nor the `COPILOT_CLI_PATH` environment variable, the SDK will automatically install the embedded CLI to a cache directory and use it for all operations.
That's it! When your application calls `copilot.NewClient` without a `Connection` field (or with an empty `StdioConnection{}`) and no `COPILOT_CLI_PATH` environment variable, the SDK will automatically install the embedded CLI to a cache directory and use it for all operations.

## API Reference

Expand All @@ -110,8 +110,8 @@ That's it! When your application calls `copilot.NewClient` without a `CLIPath` n
- `ListSessions(filter *SessionListFilter) ([]SessionMetadata, error)` - List sessions (with optional filter)
- `DeleteSession(sessionID string) error` - Delete a session permanently
- `GetLastSessionID(ctx context.Context) (*string, error)` - Get the ID of the most recently updated session
- `GetState() ConnectionState` - Get connection state
- `Ping(message string) (*PingResponse, error)` - Ping the server
- `RuntimePort() int` - TCP port the runtime is listening on (0 if stdio)
- `GetForegroundSessionID(ctx context.Context) (*string, error)` - Get the session ID currently displayed in TUI (TUI+server mode only)
- `SetForegroundSessionID(ctx context.Context, sessionID string) error` - Request TUI to display a specific session (TUI+server mode only)
- `On(handler SessionLifecycleHandler) func()` - Subscribe to all lifecycle events; returns unsubscribe function
Expand All @@ -136,18 +136,20 @@ Event types: `SessionLifecycleCreated`, `SessionLifecycleDeleted`, `SessionLifec

**ClientOptions:**

- `CLIPath` (string): Path to CLI executable (default: "copilot" or `COPILOT_CLI_PATH` env var)
- `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
- `CopilotHome` (string): Base directory for Copilot data (session state, config, etc.). Sets `COPILOT_HOME` on the spawned CLI process. When empty, the CLI defaults to `~/.copilot`. Useful in restricted environments where only specific directories are writable. Ignored when using `CLIUrl`. This does **not** affect where the Go SDK extracts the embedded CLI binary; use `embeddedcli.Config.Dir` for the extraction/cache location. You can vary `CopilotHome` per client independently of the shared extracted binary location.
- `Port` (int): Server port for TCP mode (default: 0 for random)
- `UseStdio` (bool): Use stdio transport instead of TCP (default: true)
- `LogLevel` (string): Log level (default: "info")
- `AutoStart` (\*bool): Auto-start server on first use (default: true). Use `Bool(false)` to disable.
- `Env` ([]string): Environment variables for CLI process (default: inherits from current process)
- `Connection` (RuntimeConnection): How the SDK connects to the runtime. Construct via one of:
- `StdioConnection{Path, Args}` — spawn a runtime over stdio (the default if `Connection` is nil)
- `TcpConnection{Port, ConnectionToken, Path, Args}` — spawn a runtime that listens on TCP
- `UriConnection{URL, ConnectionToken}` — connect to an already-running runtime (no process spawned)

When `Path` is empty for stdio/tcp, the SDK uses the bundled CLI (or `COPILOT_CLI_PATH` env var).
- `Cwd` (string): Working directory for the runtime process
- `BaseDirectory` (string): Base directory for Copilot data (session state, config, etc.). Sets `COPILOT_HOME` on the spawned runtime. When empty, the runtime defaults to `~/.copilot`. Ignored with `UriConnection`. This does **not** affect where the Go SDK extracts the embedded CLI binary; use `embeddedcli.Config.Dir` for the extraction/cache location.
- `LogLevel` (string): Log level. When empty (default), the runtime uses its own default level (the SDK does not pass `--log-level`).
- `Env` ([]string): Environment variables for the runtime process (default: inherits from current process)
- `GitHubToken` (string): GitHub token for authentication. When provided, takes priority over other auth methods.
- `UseLoggedInUser` (\*bool): Whether to use logged-in user for authentication (default: true, but false when `GitHubToken` is provided). Cannot be used with `CLIUrl`.
- `Telemetry` (\*TelemetryConfig): OpenTelemetry configuration for the CLI process. Providing this enables telemetry — no separate flag needed. See [Telemetry](#telemetry) below.
- `UseLoggedInUser` (\*bool): Whether to use logged-in user for authentication (default: true, but false when `GitHubToken` is provided). Cannot be used with `UriConnection`.
- `EnableRemoteSessions` (bool): Enable remote session support (Mission Control integration). Ignored with `UriConnection`.
- `Telemetry` (\*TelemetryConfig): OpenTelemetry configuration for the runtime. Providing this enables telemetry — no separate flag needed. See [Telemetry](#telemetry) below.

**SessionConfig:**

Expand All @@ -160,7 +162,7 @@ Event types: `SessionLifecycleCreated`, `SessionLifecycleDeleted`, `SessionLifec
- **replace**: Replaces the entire prompt with `Content`
- **customize**: Selectively override individual sections via `Sections` map (keys: `SectionIdentity`, `SectionTone`, `SectionToolEfficiency`, `SectionEnvironmentContext`, `SectionCodeChangeRules`, `SectionGuidelines`, `SectionSafety`, `SectionToolInstructions`, `SectionCustomInstructions`, `SectionLastInstructions`; values: `SectionOverride` with `Action` and optional `Content`)
- `Provider` (\*ProviderConfig): Custom API provider configuration (BYOK). See [Custom Providers](#custom-providers) section.
- `Streaming` (bool): Enable streaming delta events
- `Streaming` (*bool): Enable streaming delta events (nil = runtime default)
- `InfiniteSessions` (\*InfiniteSessionConfig): Automatic context compaction configuration
- `OnPermissionRequest` (PermissionHandlerFunc): Optional handler called before each tool execution to approve or deny it. When nil, permission requests are emitted as events and left pending for manual resolution. Use `copilot.PermissionHandler.ApproveAll` to allow everything, or provide a custom function for fine-grained control. See [Permission Handling](#permission-handling) section.
- `OnUserInputRequest` (UserInputHandler): Handler for user input requests from the agent (enables ask_user tool). See [User Input Requests](#user-input-requests) section.
Expand All @@ -174,7 +176,7 @@ Event types: `SessionLifecycleCreated`, `SessionLifecycleDeleted`, `SessionLifec
- `Tools` ([]Tool): Tools to expose when resuming
- `ReasoningEffort` (string): Reasoning effort level for models that support it
- `Provider` (\*ProviderConfig): Custom API provider configuration (BYOK). See [Custom Providers](#custom-providers) section.
- `Streaming` (bool): Enable streaming delta events
- `Streaming` (*bool): Enable streaming delta events (nil = runtime default)
- `Commands` ([]CommandDefinition): Slash-commands. See [Commands](#commands) section.
- `OnElicitationRequest` (ElicitationHandler): Elicitation handler. See [Elicitation Requests](#elicitation-requests-serverclient) section.

Expand All @@ -183,15 +185,14 @@ Event types: `SessionLifecycleCreated`, `SessionLifecycleDeleted`, `SessionLifec
- `Send(ctx context.Context, options MessageOptions) (string, error)` - Send a message
- `On(handler SessionEventHandler) func()` - Subscribe to events (returns unsubscribe function)
- `Abort(ctx context.Context) error` - Abort the currently processing message
- `GetMessages(ctx context.Context) ([]SessionEvent, error)` - Get message history
- `GetEvents(ctx context.Context) ([]SessionEvent, error)` - Get event history
- `Disconnect() error` - Disconnect the session (releases in-memory resources, preserves disk state)
- `Destroy() error` - _(Deprecated)_ Use `Disconnect()` instead
- `UI() *SessionUI` - Interactive UI API for elicitation dialogs
- `Capabilities() SessionCapabilities` - Host capabilities (e.g. elicitation support)

### Helper Functions

- `Bool(v bool) *bool` - Helper to create bool pointers for `AutoStart` option
- `Bool(v bool) *bool` - Helper to create bool pointers (e.g. for `Streaming`)
- `Int(v int) *int` - Helper to create int pointers for `MinLength`, `MaxLength`
- `String(v string) *string` - Helper to create string pointers
- `Float64(v float64) *float64` - Helper to create float64 pointers
Expand Down Expand Up @@ -398,7 +399,7 @@ func main() {

session, err := client.CreateSession(context.Background(), &copilot.SessionConfig{
Model: "gpt-5",
Streaming: true,
Streaming: copilot.Bool(true),
})
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -439,7 +440,7 @@ func main() {
}
```

When `Streaming: true`:
When `Streaming: copilot.Bool(true)`:

- `assistant.message_delta` events are sent with `DeltaContent` containing incremental text
- `assistant.reasoning_delta` events are sent with `DeltaContent` for reasoning/chain-of-thought (model-dependent)
Expand Down Expand Up @@ -797,7 +798,7 @@ confirmed, err := ui.Confirm(ctx, "Deploy to production?")
choice, ok, err := ui.Select(ctx, "Pick an environment", []string{"staging", "production"})

// Text input — returns (text, ok bool, error)
name, ok, err := ui.Input(ctx, "Enter the release name", &copilot.InputOptions{
name, ok, err := ui.Input(ctx, "Enter the release name", &copilot.UiInputOptions{
Title: "Release Name",
Description: "A short name for the release",
MinLength: copilot.Int(1),
Expand Down
Loading
Loading