From cc09081a8005d6b49454dcd29f7b7e501095ac56 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 17 Jun 2026 04:13:48 +0000 Subject: [PATCH] chore: publish from staged --- .../dotnet/accessibility-report.md | 16 +++++------ cookbook/copilot-sdk/dotnet/error-handling.md | 17 +++++++---- .../dotnet/managing-local-files.md | 2 +- .../copilot-sdk/dotnet/multiple-sessions.md | 2 +- .../copilot-sdk/dotnet/persisting-sessions.md | 28 +++++++++++++++---- .../copilot-sdk/dotnet/pr-visualization.md | 4 +-- cookbook/copilot-sdk/dotnet/ralph-loop.md | 4 +-- .../dotnet/recipe/accessibility-report.cs | 8 +++--- .../dotnet/recipe/error-handling.cs | 3 +- .../dotnet/recipe/managing-local-files.cs | 3 +- .../dotnet/recipe/multiple-sessions.cs | 3 +- .../dotnet/recipe/persisting-sessions.cs | 3 +- .../dotnet/recipe/pr-visualization.cs | 5 ++-- .../copilot-sdk/dotnet/recipe/ralph-loop.cs | 3 +- 14 files changed, 65 insertions(+), 36 deletions(-) diff --git a/cookbook/copilot-sdk/dotnet/accessibility-report.md b/cookbook/copilot-sdk/dotnet/accessibility-report.md index cc2d3063..39a9ca37 100644 --- a/cookbook/copilot-sdk/dotnet/accessibility-report.md +++ b/cookbook/copilot-sdk/dotnet/accessibility-report.md @@ -32,7 +32,7 @@ dotnet run recipe/accessibility-report.cs ```csharp #:package GitHub.Copilot.SDK@* -using GitHub.Copilot.SDK; +using GitHub.Copilot; // Create and start client await using var client = new CopilotClient(); @@ -65,12 +65,11 @@ await using var session = await client.CreateSessionAsync(new SessionConfig Model = "claude-opus-4.6", Streaming = true, OnPermissionRequest = PermissionHandler.ApproveAll, - McpServers = new Dictionary() + McpServers = new Dictionary() { ["playwright"] = - new McpLocalServerConfig + new McpStdioServerConfig { - Type = "local", Command = "npx", Args = ["@playwright/mcp@latest"], Tools = ["*"] @@ -195,7 +194,7 @@ if (generateTests == "y" || generateTests == "yes") ## How it works -1. **Playwright MCP server**: Configures a local MCP server running `@playwright/mcp` to provide browser automation tools +1. **Playwright MCP server**: Configures a local stdio MCP server (`McpStdioServerConfig`, launched via `npx`) running `@playwright/mcp` to provide browser automation tools 2. **Streaming output**: Uses `Streaming = true` and `AssistantMessageDeltaEvent` for real-time token-by-token output 3. **Accessibility snapshot**: Playwright's `browser_snapshot` tool captures the full accessibility tree of the page 4. **Structured report**: The prompt engineers a consistent WCAG-aligned report format with emoji severity indicators @@ -205,15 +204,14 @@ if (generateTests == "y" || generateTests == "yes") ### MCP server configuration -The recipe configures a local MCP server that runs alongside the session: +The recipe configures a local stdio MCP server (`McpStdioServerConfig`, launched via `npx`) that runs alongside the session: ```csharp OnPermissionRequest = PermissionHandler.ApproveAll, -McpServers = new Dictionary() +McpServers = new Dictionary() { - ["playwright"] = new McpLocalServerConfig + ["playwright"] = new McpStdioServerConfig { - Type = "local", Command = "npx", Args = ["@playwright/mcp@latest"], Tools = ["*"] diff --git a/cookbook/copilot-sdk/dotnet/error-handling.md b/cookbook/copilot-sdk/dotnet/error-handling.md index 68f45e50..01f68212 100644 --- a/cookbook/copilot-sdk/dotnet/error-handling.md +++ b/cookbook/copilot-sdk/dotnet/error-handling.md @@ -15,7 +15,7 @@ You need to handle various error conditions like connection failures, timeouts, ## Basic try-catch ```csharp -using GitHub.Copilot.SDK; +using GitHub.Copilot; var client = new CopilotClient(); @@ -134,16 +134,23 @@ Console.CancelKeyPress += async (sender, e) => e.Cancel = true; Console.WriteLine("Shutting down..."); - var errors = await client.StopAsync(); - if (errors.Count > 0) + try { - Console.WriteLine($"Cleanup errors: {string.Join(", ", errors)}"); + await client.StopAsync(); + } + catch (Exception ex) + { + Console.WriteLine($"Cleanup error: {ex.Message}"); } Environment.Exit(0); }; ``` +> In 1.0, `StopAsync()` throws if it encounters errors during cleanup rather than returning a +> list of cleanup errors, so wrap it in a try/catch to log failures instead of letting them +> crash shutdown. Use `ForceStopAsync()` if a graceful stop takes too long. + ## Using await using for automatic disposal ```csharp @@ -163,7 +170,7 @@ var session = await client.CreateSessionAsync(new SessionConfig ## Best practices -Starting with Copilot SDK v0.1.28, permission handling is opt-in. If a session may need tool, file, or system access, set `OnPermissionRequest` explicitly when creating it. +Permission handling is opt-in. If a session may need tool, file, or system access, set `OnPermissionRequest` explicitly when creating it. 1. **Always clean up**: Use try-finally or `await using` to ensure `StopAsync()` is called 2. **Handle connection errors**: The CLI might not be installed or running diff --git a/cookbook/copilot-sdk/dotnet/managing-local-files.md b/cookbook/copilot-sdk/dotnet/managing-local-files.md index efe07c7d..c3b94b83 100644 --- a/cookbook/copilot-sdk/dotnet/managing-local-files.md +++ b/cookbook/copilot-sdk/dotnet/managing-local-files.md @@ -16,7 +16,7 @@ You have a folder with many files and want to organize them into subfolders base ## Example code ```csharp -using GitHub.Copilot.SDK; +using GitHub.Copilot; // Create and start client await using var client = new CopilotClient(); diff --git a/cookbook/copilot-sdk/dotnet/multiple-sessions.md b/cookbook/copilot-sdk/dotnet/multiple-sessions.md index 630301b7..4def11de 100644 --- a/cookbook/copilot-sdk/dotnet/multiple-sessions.md +++ b/cookbook/copilot-sdk/dotnet/multiple-sessions.md @@ -15,7 +15,7 @@ You need to run multiple conversations in parallel, each with its own context an ## C # ```csharp -using GitHub.Copilot.SDK; +using GitHub.Copilot; await using var client = new CopilotClient(); await client.StartAsync(); diff --git a/cookbook/copilot-sdk/dotnet/persisting-sessions.md b/cookbook/copilot-sdk/dotnet/persisting-sessions.md index d0e4e6d3..0338a730 100644 --- a/cookbook/copilot-sdk/dotnet/persisting-sessions.md +++ b/cookbook/copilot-sdk/dotnet/persisting-sessions.md @@ -16,7 +16,7 @@ You want users to be able to continue a conversation even after closing and reop ### Creating a session with a custom ID ```csharp -using GitHub.Copilot.SDK; +using GitHub.Copilot; await using var client = new CopilotClient(); await client.StartAsync(); @@ -74,16 +74,34 @@ await client.DeleteSessionAsync("user-123-conversation"); ### Getting session history -Retrieve all messages from a session: +Retrieve all events from a session: ```csharp -var messages = await session.GetMessagesAsync(); -foreach (var msg in messages) +using GitHub.Copilot; // UserMessageEvent, AssistantMessageEvent, etc. live in this namespace + +var events = await session.GetEventsAsync(); +foreach (var evt in events) { - Console.WriteLine($"[{msg.Type}] {msg.Data.Content}"); + switch (evt) + { + case UserMessageEvent user: + Console.WriteLine($"[user] {user.Data.Content}"); + break; + case AssistantMessageEvent assistant: + Console.WriteLine($"[assistant] {assistant.Data.Content}"); + break; + default: + // Sessions can also contain other events (tool calls, tool results, system events). + Console.WriteLine($"[{evt.GetType().Name}]"); + break; + } } ``` +> A session's event stream may include event kinds beyond user and assistant messages +> (for example tool calls, tool results, and system events). Handle the ones you care +> about and fall back to a default case so nothing is silently dropped. + ## Best practices 1. **Use meaningful session IDs**: Include user ID or context in the session ID diff --git a/cookbook/copilot-sdk/dotnet/pr-visualization.md b/cookbook/copilot-sdk/dotnet/pr-visualization.md index cdd6d808..6ce78669 100644 --- a/cookbook/copilot-sdk/dotnet/pr-visualization.md +++ b/cookbook/copilot-sdk/dotnet/pr-visualization.md @@ -36,7 +36,7 @@ dotnet run -- --repo github/copilot-sdk ```csharp using System.Diagnostics; -using GitHub.Copilot.SDK; +using GitHub.Copilot; // ============================================================================ // Git & GitHub Detection @@ -159,7 +159,7 @@ var owner = parts[0]; var repoName = parts[1]; // Create Copilot client - no custom tools needed! -await using var client = new CopilotClient(new CopilotClientOptions { LogLevel = "error" }); +await using var client = new CopilotClient(new CopilotClientOptions { LogLevel = CopilotLogLevel.Error }); await client.StartAsync(); var session = await client.CreateSessionAsync(new SessionConfig diff --git a/cookbook/copilot-sdk/dotnet/ralph-loop.md b/cookbook/copilot-sdk/dotnet/ralph-loop.md index 2b07b465..77aebdde 100644 --- a/cookbook/copilot-sdk/dotnet/ralph-loop.md +++ b/cookbook/copilot-sdk/dotnet/ralph-loop.md @@ -42,7 +42,7 @@ A [Ralph loop](https://ghuntley.com/ralph/) is an autonomous development workflo The minimal Ralph loop — the SDK equivalent of `while :; do cat PROMPT.md | copilot ; done`: ```csharp -using GitHub.Copilot.SDK; +using GitHub.Copilot; var client = new CopilotClient(); await client.StartAsync(); @@ -96,7 +96,7 @@ This is all you need to get started. The prompt file tells the agent what to do; The full Ralph pattern with planning and building modes, matching the [Ralph Playbook](https://github.com/ClaytonFarr/ralph-playbook) architecture: ```csharp -using GitHub.Copilot.SDK; +using GitHub.Copilot; // Parse args: dotnet run [plan] [max_iterations] var mode = args.Contains("plan") ? "plan" : "build"; diff --git a/cookbook/copilot-sdk/dotnet/recipe/accessibility-report.cs b/cookbook/copilot-sdk/dotnet/recipe/accessibility-report.cs index c5b67bcb..bfa575d7 100644 --- a/cookbook/copilot-sdk/dotnet/recipe/accessibility-report.cs +++ b/cookbook/copilot-sdk/dotnet/recipe/accessibility-report.cs @@ -1,6 +1,7 @@ #:package GitHub.Copilot.SDK@* -using GitHub.Copilot.SDK; +// The GitHub.Copilot.SDK package exposes the GitHub.Copilot namespace. +using GitHub.Copilot; // Create and start client await using var client = new CopilotClient(); @@ -33,12 +34,11 @@ await using var session = await client.CreateSessionAsync(new SessionConfig Model = "claude-opus-4.6", Streaming = true, OnPermissionRequest = PermissionHandler.ApproveAll, - McpServers = new Dictionary() + McpServers = new Dictionary() { ["playwright"] = - new McpLocalServerConfig + new McpStdioServerConfig { - Type = "local", Command = "npx", Args = ["@playwright/mcp@latest"], Tools = ["*"] diff --git a/cookbook/copilot-sdk/dotnet/recipe/error-handling.cs b/cookbook/copilot-sdk/dotnet/recipe/error-handling.cs index 5932cc88..44816830 100644 --- a/cookbook/copilot-sdk/dotnet/recipe/error-handling.cs +++ b/cookbook/copilot-sdk/dotnet/recipe/error-handling.cs @@ -1,7 +1,8 @@ #:package GitHub.Copilot.SDK@* #:property PublishAot=false -using GitHub.Copilot.SDK; +// The GitHub.Copilot.SDK package exposes the GitHub.Copilot namespace. +using GitHub.Copilot; var client = new CopilotClient(); diff --git a/cookbook/copilot-sdk/dotnet/recipe/managing-local-files.cs b/cookbook/copilot-sdk/dotnet/recipe/managing-local-files.cs index 72ff1cd6..dcc5eeff 100644 --- a/cookbook/copilot-sdk/dotnet/recipe/managing-local-files.cs +++ b/cookbook/copilot-sdk/dotnet/recipe/managing-local-files.cs @@ -1,7 +1,8 @@ #:package GitHub.Copilot.SDK@* #:property PublishAot=false -using GitHub.Copilot.SDK; +// The GitHub.Copilot.SDK package exposes the GitHub.Copilot namespace. +using GitHub.Copilot; // Create and start client await using var client = new CopilotClient(); diff --git a/cookbook/copilot-sdk/dotnet/recipe/multiple-sessions.cs b/cookbook/copilot-sdk/dotnet/recipe/multiple-sessions.cs index c65557dc..40ec3b62 100644 --- a/cookbook/copilot-sdk/dotnet/recipe/multiple-sessions.cs +++ b/cookbook/copilot-sdk/dotnet/recipe/multiple-sessions.cs @@ -1,7 +1,8 @@ #:package GitHub.Copilot.SDK@* #:property PublishAot=false -using GitHub.Copilot.SDK; +// The GitHub.Copilot.SDK package exposes the GitHub.Copilot namespace. +using GitHub.Copilot; await using var client = new CopilotClient(); await client.StartAsync(); diff --git a/cookbook/copilot-sdk/dotnet/recipe/persisting-sessions.cs b/cookbook/copilot-sdk/dotnet/recipe/persisting-sessions.cs index 138551fd..89b8d77e 100644 --- a/cookbook/copilot-sdk/dotnet/recipe/persisting-sessions.cs +++ b/cookbook/copilot-sdk/dotnet/recipe/persisting-sessions.cs @@ -1,7 +1,8 @@ #:package GitHub.Copilot.SDK@* #:property PublishAot=false -using GitHub.Copilot.SDK; +// The GitHub.Copilot.SDK package exposes the GitHub.Copilot namespace. +using GitHub.Copilot; await using var client = new CopilotClient(); await client.StartAsync(); diff --git a/cookbook/copilot-sdk/dotnet/recipe/pr-visualization.cs b/cookbook/copilot-sdk/dotnet/recipe/pr-visualization.cs index 40b7548e..afa80658 100644 --- a/cookbook/copilot-sdk/dotnet/recipe/pr-visualization.cs +++ b/cookbook/copilot-sdk/dotnet/recipe/pr-visualization.cs @@ -2,7 +2,8 @@ #:property PublishAot=false using System.Diagnostics; -using GitHub.Copilot.SDK; +// The GitHub.Copilot.SDK package exposes the GitHub.Copilot namespace. +using GitHub.Copilot; // ============================================================================ // Git & GitHub Detection @@ -126,7 +127,7 @@ var owner = parts[0]; var repoName = parts[1]; // Create Copilot client - no custom tools needed! -await using var client = new CopilotClient(new CopilotClientOptions { LogLevel = "error" }); +await using var client = new CopilotClient(new CopilotClientOptions { LogLevel = CopilotLogLevel.Error }); await client.StartAsync(); var session = await client.CreateSessionAsync(new SessionConfig diff --git a/cookbook/copilot-sdk/dotnet/recipe/ralph-loop.cs b/cookbook/copilot-sdk/dotnet/recipe/ralph-loop.cs index ed251e8d..5b6f9729 100644 --- a/cookbook/copilot-sdk/dotnet/recipe/ralph-loop.cs +++ b/cookbook/copilot-sdk/dotnet/recipe/ralph-loop.cs @@ -1,6 +1,7 @@ #:package GitHub.Copilot.SDK@* -using GitHub.Copilot.SDK; +// The GitHub.Copilot.SDK package exposes the GitHub.Copilot namespace. +using GitHub.Copilot; // Ralph loop: autonomous AI task loop with fresh context per iteration. //