[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill-6b9357e9-ceb6-477e-bb6c-5b0e87a0a2da":3,"$fU-UHx02OGx0W0z-mxv5BKUH51WFvHBtUSrnscmzRAts":42},{"id":4,"title":5,"description":6,"categoryId":7,"moduleId":8,"tags":9,"prompt":10,"icon":11,"source":12,"sourceUrl":13,"authorId":14,"authorName":15,"isPublic":16,"stars":17,"runs":18,"createdAt":19,"updatedAt":19,"module":20,"category":27,"packages":33},"6b9357e9-ceb6-477e-bb6c-5b0e87a0a2da","copilot-sdk","构建与GitHub Copilot程序交互的应用程序。SDK通过JSON-RPC封装Copilot CLI，提供会话管理、自定义工具、钩子、MCP服务器集成以及跨Node.js、Python、Go和.NET的流式传输。","cat_coding_backend","mod_coding","sickn33,coding","---\nname: copilot-sdk\ndescription: \"Build applications that programmatically interact with GitHub Copilot. The SDK wraps the Copilot CLI via JSON-RPC, providing session management, custom tools, hooks, MCP server integration, and streaming across Node.js, Python, Go, and .NET.\"\nrisk: unknown\nsource: community\ndate_added: \"2026-02-27\"\n---\n\n# GitHub Copilot SDK\n\nBuild applications that programmatically interact with GitHub Copilot. The SDK wraps the Copilot CLI via JSON-RPC, providing session management, custom tools, hooks, MCP server integration, and streaming across Node.js, Python, Go, and .NET.\n\n## Prerequisites\n\n- **GitHub Copilot CLI** installed and authenticated (`copilot --version` to verify)\n- **GitHub Copilot subscription** (Individual, Business, or Enterprise) — not required for BYOK\n- **Runtime:** Node.js 18+ \u002F Python 3.8+ \u002F Go 1.21+ \u002F .NET 8.0+\n\n## Installation\n\n| Language | Package | Install |\n|----------|---------|---------|\n| Node.js | `@github\u002Fcopilot-sdk` | `npm install @github\u002Fcopilot-sdk` |\n| Python | `github-copilot-sdk` | `pip install github-copilot-sdk` |\n| Go | `github.com\u002Fgithub\u002Fcopilot-sdk\u002Fgo` | `go get github.com\u002Fgithub\u002Fcopilot-sdk\u002Fgo` |\n| .NET | `GitHub.Copilot.SDK` | `dotnet add package GitHub.Copilot.SDK` |\n\n---\n\n## Core Pattern: Client → Session → Message\n\nAll SDK usage follows this pattern: create a client, create a session, send messages.\n\n### Node.js \u002F TypeScript\n\n```typescript\nimport { CopilotClient } from \"@github\u002Fcopilot-sdk\";\n\nconst client = new CopilotClient();\nconst session = await client.createSession({ model: \"gpt-4.1\" });\n\nconst response = await session.sendAndWait({ prompt: \"What is 2 + 2?\" });\nconsole.log(response?.data.content);\n\nawait client.stop();\n```\n\n### Python\n\n```python\nimport asyncio\nfrom copilot import CopilotClient\n\nasync def main():\n    client = CopilotClient()\n    await client.start()\n    session = await client.create_session({\"model\": \"gpt-4.1\"})\n    response = await session.send_and_wait({\"prompt\": \"What is 2 + 2?\"})\n    print(response.data.content)\n    await client.stop()\n\nasyncio.run(main())\n```\n\n### Go\n\n```go\nclient := copilot.NewClient(nil)\nif err := client.Start(ctx); err != nil { log.Fatal(err) }\ndefer client.Stop()\n\nsession, _ := client.CreateSession(ctx, &copilot.SessionConfig{Model: \"gpt-4.1\"})\nresponse, _ := session.SendAndWait(ctx, copilot.MessageOptions{Prompt: \"What is 2 + 2?\"})\nfmt.Println(*response.Data.Content)\n```\n\n### .NET\n\n```csharp\nawait using var client = new CopilotClient();\nawait using var session = await client.CreateSessionAsync(new SessionConfig { Model = \"gpt-4.1\" });\nvar response = await session.SendAndWaitAsync(new MessageOptions { Prompt = \"What is 2 + 2?\" });\nConsole.WriteLine(response?.Data.Content);\n```\n\n---\n\n## Streaming Responses\n\nEnable real-time output by setting `streaming: true` and subscribing to delta events.\n\n```typescript\nconst session = await client.createSession({ model: \"gpt-4.1\", streaming: true });\n\nsession.on(\"assistant.message_delta\", (event) => {\n    process.stdout.write(event.data.deltaContent);\n});\nsession.on(\"session.idle\", () => console.log());\n\nawait session.sendAndWait({ prompt: \"Tell me a joke\" });\n```\n\n**Python equivalent:**\n\n```python\nfrom copilot.generated.session_events import SessionEventType\n\nsession = await client.create_session({\"model\": \"gpt-4.1\", \"streaming\": True})\n\ndef handle_event(event):\n    if event.type == SessionEventType.ASSISTANT_MESSAGE_DELTA:\n        sys.stdout.write(event.data.delta_content)\n        sys.stdout.flush()\n\nsession.on(handle_event)\nawait session.send_and_wait({\"prompt\": \"Tell me a joke\"})\n```\n\n### Event Subscription\n\n| Method | Description |\n|--------|-------------|\n| `on(handler)` | Subscribe to all events; returns unsubscribe function |\n| `on(eventType, handler)` | Subscribe to specific event type (Node.js only) |\n\n---\n\n## Custom Tools\n\nDefine tools that Copilot can call to extend its capabilities.\n\n### Node.js\n\n```typescript\nimport { CopilotClient, defineTool } from \"@github\u002Fcopilot-sdk\";\n\nconst getWeather = defineTool(\"get_weather\", {\n    description: \"Get the current weather for a city\",\n    parameters: {\n        type: \"object\",\n        properties: { city: { type: \"string\", description: \"The city name\" } },\n        required: [\"city\"],\n    },\n    handler: async ({ city }) => ({ city, temperature: \"72°F\", condition: \"sunny\" }),\n});\n\nconst session = await client.createSession({\n    model: \"gpt-4.1\",\n    tools: [getWeather],\n});\n```\n\n### Python\n\n```python\nfrom copilot.tools import define_tool\nfrom pydantic import BaseModel, Field\n\nclass GetWeatherParams(BaseModel):\n    city: str = Field(description=\"The city name\")\n\n@define_tool(description=\"Get the current weather for a city\")\nasync def get_weather(params: GetWeatherParams) -> dict:\n    return {\"city\": params.city, \"temperature\": \"72°F\", \"condition\": \"sunny\"}\n\nsession = await client.create_session({\"model\": \"gpt-4.1\", \"tools\": [get_weather]})\n```\n\n### Go\n\n```go\ntype WeatherParams struct {\n    City string `json:\"city\" jsonschema:\"The city name\"`\n}\n\ngetWeather := copilot.DefineTool(\"get_weather\", \"Get weather for a city\",\n    func(params WeatherParams, inv copilot.ToolInvocation) (WeatherResult, error) {\n        return WeatherResult{City: params.City, Temperature: \"72°F\"}, nil\n    },\n)\n\nsession, _ := client.CreateSession(ctx, &copilot.SessionConfig{\n    Model: \"gpt-4.1\",\n    Tools: []copilot.Tool{getWeather},\n})\n```\n\n### .NET\n\n```csharp\nvar getWeather = AIFunctionFactory.Create(\n    ([Description(\"The city name\")] string city) => new { city, temperature = \"72°F\" },\n    \"get_weather\", \"Get the current weather for a city\");\n\nawait using var session = await client.CreateSessionAsync(new SessionConfig {\n    Model = \"gpt-4.1\", Tools = [getWeather],\n});\n```\n\n---\n\n## Hooks\n\nIntercept and customize session behavior at key lifecycle points.\n\n| Hook | Trigger | Use Case |\n|------|---------|----------|\n| `onPreToolUse` | Before tool executes | Permission control, argument modification |\n| `onPostToolUse` | After tool executes | Result transformation, logging |\n| `onUserPromptSubmitted` | User sends message | Prompt modification, filtering |\n| `onSessionStart` | Session begins | Add context, configure session |\n| `onSessionEnd` | Session ends | Cleanup, analytics |\n| `onErrorOccurred` | Error happens | Custom error handling, retry logic |\n\n### Example: Tool Permission Control\n\n```typescript\nconst session = await client.createSession({\n    hooks: {\n        onPreToolUse: async (input) => {\n            if ([\"shell\", \"bash\"].includes(input.toolName)) {\n                return { permissionDecision: \"deny\", permissionDecisionReason: \"Shell access not permitted\" };\n            }\n            return { permissionDecision: \"allow\" };\n        },\n    },\n});\n```\n\n### Pre-Tool Use Output\n\n| Field | Type | Description |\n|-------|------|-------------|\n| `permissionDecision` | `\"allow\"` \\| `\"deny\"` \\| `\"ask\"` | Whether to allow the tool call |\n| `permissionDecisionReason` | string | Explanation for deny\u002Fask |\n| `modifiedArgs` | object | Modified arguments to pass |\n| `additionalContext` | string | Extra context for conversation |\n| `suppressOutput` | boolean | Hide tool output from conversation |\n\n---\n\n## MCP Server Integration\n\nConnect to MCP servers for pre-built tool capabilities.\n\n### Remote HTTP Server\n\n```typescript\nconst session = await client.createSession({\n    mcpServers: {\n        github: { type: \"http\", url: \"https:\u002F\u002Fapi.githubcopilot.com\u002Fmcp\u002F\" },\n    },\n});\n```\n\n### Local Stdio Server\n\n```typescript\nconst session = await client.createSession({\n    mcpServers: {\n        filesystem: {\n            type: \"local\",\n            command: \"npx\",\n            args: [\"-y\", \"@modelcontextprotocol\u002Fserver-filesystem\", \"\u002Fallowed\u002Fpath\"],\n            tools: [\"*\"],\n        },\n    },\n});\n```\n\n### MCP Config Fields\n\n| Field | Type | Description |\n|-------|------|-------------|\n| `type` | `\"local\"` \\| `\"http\"` | Server transport type |\n| `command` | string | Executable path (local) |\n| `args` | string[] | Command arguments (local) |\n| `url` | string | Server URL (http) |\n| `tools` | string[] | `[\"*\"]` or specific tool names |\n| `env` | object | Environment variables |\n| `cwd` | string | Working directory (local) |\n| `timeout` | number | Timeout in milliseconds |\n\n---\n\n## Authentication\n\n### Methods (Priority Order)\n\n1. **Explicit token** — `githubToken` in constructor\n2. **Environment variables** — `COPILOT_GITHUB_TOKEN` → `GH_TOKEN` → `GITHUB_TOKEN`\n3. **Stored OAuth** — From `copilot auth login`\n4. **GitHub CLI** — `gh auth` credentials\n\n### Programmatic Token\n\n```typescript\nconst client = new CopilotClient({ githubToken: process.env.GITHUB_TOKEN });\n```\n\n### BYOK (Bring Your Own Key)\n\nUse your own API keys — no Copilot subscription required.\n\n```typescript\nconst session = await client.createSession({\n    model: \"gpt-5.2-codex\",\n    provider: {\n        type: \"openai\",\n        baseUrl: \"https:\u002F\u002Fyour-resource.openai.azure.com\u002Fopenai\u002Fv1\u002F\",\n        wireApi: \"responses\",\n        apiKey: process.env.FOUNDRY_API_KEY,\n    },\n});\n```\n\n| Provider | Type | Notes |\n|----------|------|-------|\n| OpenAI | `\"openai\"` | OpenAI API and compatible endpoints |\n| Azure OpenAI | `\"azure\"` | Native Azure endpoints (don't include `\u002Fopenai\u002Fv1`) |\n| Azure AI Foundry | `\"openai\"` | OpenAI-compatible Foundry endpoints |\n| Anthropic | `\"anthropic\"` | Claude models |\n| Ollama | `\"openai\"` | Local models, no API key needed |\n\n**Wire API:** Use `\"responses\"` for GPT-5 series, `\"completions\"` (default) for others.\n\n---\n\n## Session Persistence\n\nResume sessions across restarts by providing your own session ID.\n\n```typescript\n\u002F\u002F Create with explicit ID\nconst session = await client.createSession({\n    sessionId: \"user-123-task-456\",\n    model: \"gpt-4.1\",\n});\n\n\u002F\u002F Resume later\nconst resumed = await client.resumeSession(\"user-123-task-456\");\nawait resumed.sendAndWait({ prompt: \"What did we discuss?\" });\n```\n\n**Session management:**\n\n```typescript\nconst sessions = await client.listSessions();          \u002F\u002F List all\nawait client.deleteSession(\"user-123-task-456\");       \u002F\u002F Delete\nawait session.destroy();                                \u002F\u002F Destroy active\n```\n\n**BYOK sessions:** Must re-provide `provider` config on resume (keys are not persisted).\n\n### Infinite Sessions\n\nFor long-running workflows that may exceed context limits:\n\n```typescript\nconst session = await client.createSession({\n    infiniteSessions: {\n        enabled: true,\n        backgroundCompactionThreshold: 0.80,\n        bufferExhaustionThreshold: 0.95,\n    },\n});\n```\n\n---\n\n## Custom Agents\n\nDefine specialized AI personas:\n\n```typescript\nconst session = await client.createSession({\n    customAgents: [{\n        name: \"pr-reviewer\",\n        displayName: \"PR Reviewer\",\n        description: \"Reviews pull requests for best practices\",\n        prompt: \"You are an expert code reviewer. Focus on security, performance, and maintainability.\",\n    }],\n});\n```\n\n---\n\n## System Message\n\nControl AI behavior and personality:\n\n```typescript\nconst session = await client.createSession({\n    systemMessage: { content: \"You are a helpful assistant. Always be concise.\" },\n});\n```\n\n---\n\n## Skills Integration\n\nLoad skill directories to extend Copilot's capabilities:\n\n```typescript\nconst session = await client.createSession({\n    skillDirectories: [\".\u002Fskills\u002Fcode-review\", \".\u002Fskills\u002Fdocumentation\"],\n    disabledSkills: [\"experimental-feature\"],\n});\n```\n\n---\n\n## Permission & Input Handlers\n\nHandle tool permissions and user input requests programmatically:\n\n```typescript\nconst session = await client.createSession({\n    onPermissionRequest: async (request) => {\n        \u002F\u002F Auto-approve git commands only\n        if (request.kind === \"shell\") {\n            return { approved: request.command.startsWith(\"git\") };\n        }\n        return { approved: true };\n    },\n    onUserInputRequest: async (request) => {\n        \u002F\u002F Handle ask_user tool calls\n        return { response: \"yes\" };\n    },\n});\n```\n\n---\n\n## External CLI Server\n\nConnect to a separately running CLI instead of auto-managing the process:\n\n```bash\ncopilot --headless --port 4321\n```\n\n```typescript\nconst client = new CopilotClient({ cliUrl: \"localhost:4321\" });\n```\n\n---\n\n## Client Configuration\n\n| Option | Type | Description |\n|--------|------|-------------|\n| `cliPath` | string | Path to Copilot CLI executable |\n| `cliUrl` | string | URL of external CLI server |\n| `githubToken` | string | GitHub token for auth |\n| `useLoggedInUser` | boolean | Use stored CLI credentials (default: true) |\n| `logLevel` | string | `\"none\"` \\| `\"error\"` \\| `\"warning\"` \\| `\"info\"` \\| `\"debug\"` |\n| `autoRestart` | boolean | Auto-restart CLI on crash (default: true) |\n| `useStdio` | boolean | Use stdio transport (default: true) |\n\n## Session Configuration\n\n| Option | Type | Description |\n|--------|------|-------------|\n| `model` | string | Model to use (e.g., `\"gpt-4.1\"`) |\n| `sessionId` | string | Custom ID for resumable sessions |\n| `streaming` | boolean | Enable streaming responses |\n| `tools` | Tool[] | Custom tools |\n| `mcpServers` | object | MCP server configurations |\n| `hooks` | object | Session hooks |\n| `provider` | object | BYOK provider config |\n| `customAgents` | object[] | Custom agent definitions |\n| `systemMessage` | object | System message override |\n| `skillDirectories` | string[] | Directories to load skills from |\n| `disabledSkills` | string[] | Skills to disable |\n| `reasoningEffort` | string | Reasoning effort level |\n| `availableTools` | string[] | Restrict available tools |\n| `excludedTools` | string[] | Exclude specific tools |\n| `infiniteSessions` | object | Auto-compaction config |\n| `workingDirectory` | string | Working directory |\n\n---\n\n## Debugging\n\nEnable debug logging to troubleshoot issues:\n\n```typescript\nconst client = new CopilotClient({ logLevel: \"debug\" });\n```\n\n**Common issues:**\n- `CLI not found` → Install CLI or set `cliPath`\n- `Not authenticated` → Run `copilot auth login` or provide `githubToken`\n- `Session not found` → Don't use session after `destroy()`\n- `Connection refused` → Check CLI process, enable `autoRestart`\n\n---\n\n## Key API Summary\n\n| Language | Client | Session Create | Send | Stop |\n|----------|--------|---------------|------|------|\n| Node.js | `new CopilotClient()` | `client.createSession()` | `session.sendAndWait()` | `client.stop()` |\n| Python | `CopilotClient()` | `client.create_session()` | `session.send_and_wait()` | `client.stop()` |\n| Go | `copilot.NewClient(nil)` | `client.CreateSession()` | `session.SendAndWait()` | `client.Stop()` |\n| .NET | `new CopilotClient()` | `client.CreateSessionAsync()` | `session.SendAndWaitAsync()` | `client.DisposeAsync()` |\n\n## References\n\n- [GitHub Copilot SDK](https:\u002F\u002Fgithub.com\u002Fgithub\u002Fcopilot-sdk)\n- [Copilot CLI Installation](https:\u002F\u002Fdocs.github.com\u002Fen\u002Fcopilot\u002Fhow-tos\u002Fset-up\u002Finstall-copilot-cli)\n- [MCP Protocol Specification](https:\u002F\u002Fmodelcontextprotocol.io)\n\n## When to Use\nThis skill is applicable to execute the workflow or actions described in the overview.\n\n## Limitations\n- Use this skill only when the task clearly matches the scope described above.\n- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.\n- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.\n","","imported","https:\u002F\u002Fgithub.com\u002Fsickn33\u002Fantigravity-awesome-skills","user_system_seed","SkillOPIC",true,128,1088,"2026-05-16 13:13:21",{"id":8,"name":21,"slug":22,"icon":23,"description":24,"sort":25,"createdAt":26},"编程开发","coding","mdi-code-braces","代码生成、调试、审查，提升开发效率",2,"2026-05-16 12:53:40",{"id":7,"name":28,"slug":29,"icon":30,"description":31,"moduleId":8,"sort":25,"skillCount":32,"createdAt":26},"后端开发","backend","mdi-server","API、数据库、服务端架构",296,[34],{"id":35,"skillId":4,"version":36,"fileName":37,"fileSize":38,"filePath":39,"fileHash":40,"manifest":41,"createdAt":19},"7675cc29-156b-41fd-a831-ea44656ec4a1","1.0.0","copilot-sdk.zip",5417,"uploads\u002Fskills\u002F6b9357e9-ceb6-477e-bb6c-5b0e87a0a2da\u002Fcopilot-sdk.zip","a27adf8999436b0f96899d9dd625c0d34b4df079e9efaf73353cf75376791404","[{\"path\":\"SKILL.md\",\"isDirectory\":false,\"size\":15379}]",{"code":43,"message":44,"data":45},200,"success",{"items":46,"stats":47,"page":50},[],{"averageRating":48,"totalRatings":48,"ratingCounts":49},0,[48,48,48,48,48],{"limit":51,"offset":48,"hasMore":52,"nextOffset":51,"ratedOnly":16},15,false]