Token导航 LogoToken导航TokenDH.com
研究检索操作浏览器github未标认证来源可访问许可证需确认审计提醒

build-copilot-sdk-app构建 GitHub Copilot SDK 应用

Agent Skill

build-copilot-sdk-app 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

588

周安装

24

GitHub Stars

5

下载量

188
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:build-copilot-sdk-app(构建 GitHub Copilot SDK 应用)
来源仓库:https://github.com/yigitkonur/skills-by-yigitkonur
仓库路径:skills/build-copilot-sdk-app
安装命令:
npx skills add https://github.com/yigitkonur/skills-by-yigitkonur --skill build-copilot-sdk-app
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/yigitkonur/skills-by-yigitkonur --skill build-copilot-sdk-app

简介

build-copilot-sdk-app 用于构建基于 GitHub Copilot SDK 的应用程序,支持会话管理和自定义工具注册。

  • 它通过 JSON-RPC 与 Copilot CLI 通信,提供流式响应处理和权限控制机制。
  • 使用时需初始化项目、设置传输协议(stdio 或 TCP),并定义 prompt 与工具映射关系。
  • 安装前请确认仓库权限、维护状态,以及是否会暴露网络接口或处理用户输入流。
  • 适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

SKILL.md

Build Copilot SDK App

Build applications powered by GitHub Copilot using the @github/copilot-sdk TypeScript/Node.js package (protocol v3). The SDK communicates with the Copilot CLI over JSON-RPC (stdio or TCP) and exposes a session-based API for sending prompts, receiving streamed responses, registering custom tools, handling permissions, and managing agent workflows.

Decision tree

What do you need?
│
├── New app from scratch
│   ├── Install & basic example ──────────► Quick start (below) — npm init, ESM setup, first prompt
│   ├── Client options & transport ───────► references/client-and-transport.md — stdio vs TCP, CopilotClient config
│   └── Authentication ──────────────────► references/auth-and-byok.md — OAuth, tokens, BYOK with 5 providers
│
├── Sessions
│   ├── Create / resume / disconnect ────► references/sessions.md — lifecycle, create-or-resume pattern
│   ├── Infinite sessions & compaction ──► references/sessions.md — long conversations, context window mgmt
│   └── Persistence & resumption ────────► references/sessions.md — disk persistence, resumeSession semantics
│
├── Messages & streaming
│   ├── send / sendAndWait ──────────────► Quick start (below) — blocking vs fire-and-forget
│   ├── Streaming deltas ────────────────► references/events-and-streaming.md — incremental content delivery
│   └── All 47 event types ─────────────► references/events-and-streaming.md — full event catalog
│
├── Custom tools
│   ├── defineTool with Zod ─────────────► references/tools-and-schemas.md — Zod schema, handler, auto-JSON-Schema
│   ├── JSON Schema tools ──────────────► references/tools-and-schemas.md — raw schema without Zod
│   └── Override built-in tools ────────► references/tools-and-schemas.md — replace default Copilot tools
│
├── Permissions & user input
│   ├── Permission handler ─────────────► references/permissions-and-user-input.md — approveAll or custom logic
│   ├── ask_user / onUserInputRequest ──► references/permissions-and-user-input.md — programmatic user prompts
│   └── Elicitation (MCP forms) ────────► references/permissions-and-user-input.md — structured input via MCP
│
├── Hooks (lifecycle interceptors)
│   ├── Pre/post tool use ──────────────► references/hooks.md — intercept tool calls, modify args/results
│   ├── Prompt modification ────────────► references/hooks.md — rewrite prompts before send
│   └── Session lifecycle & errors ─────► references/hooks.md — onError, onSessionStart, void return OK
│
├── Agents, MCP & skills
│   ├── Custom agents ──────────────────► references/agents-mcp-skills.md — agent registration & routing
│   ├── MCP server config ─────────────► references/agents-mcp-skills.md — connect external MCP servers
│   ├── Skills system ─────────────────► references/agents-mcp-skills.md — skill discovery & invocation
│   └── CLI extensions (.mjs) ─────────► references/agents-mcp-skills.md — extend Copilot CLI via scripts
│
├── Advanced patterns
│   ├── Plan / autopilot / interactive ─► references/advanced-patterns.md — mode switching workflow
│   ├── Fleet mode ─────────────────────► references/advanced-patterns.md — parallel session orchestration
│   ├── Multi-client architecture ──────► references/advanced-patterns.md — multiple CopilotClient instances
│   ├── Ralph loop (autonomous dev) ───► references/advanced-patterns.md — autonomous code generation loop
│   ├── Steering & queueing ───────────► references/advanced-patterns.md — prompt queueing, backpressure
│   └── System message modes ──────────► references/advanced-patterns.md — system prompt configuration
│
├── Auth & BYOK
│   ├── GitHub OAuth / tokens ──────────► references/auth-and-byok.md — token acquisition flow
│   └── Bring Your Own Key ────────────► references/auth-and-byok.md — OpenAI/Anthropic/Azure/Gemini/Ollama
│
└── Type reference
    └── All interfaces & RPC methods ──► references/types-reference.md — TypeScript interfaces, RPC API

Quick start

Prerequisites

Verify your environment:

node --version   # must be >= 20
copilot --version # Copilot CLI must be installed

Authenticate before you run the examples:

  • Local interactive auth: copilot login
  • Headless auth: set one of COPILOT_GITHUB_TOKEN, GH_TOKEN, or GITHUB_TOKEN
  • In CI or other non-interactive runs, export the token before npm start; do not expect the SDK process to complete browser login for you.

Default file layout and run command

Use this layout unless the repo already has a better convention:

mkdir -p src/lib
npm pkg set scripts.start="tsx src/index.ts"
npm pkg set scripts.dev="tsx watch src/index.ts"
  • Put the main SDK entrypoint in src/index.ts
  • Put reusable local business logic in src/lib/*.ts
  • Run the first build with npm start

Project setup

npm init -y
npm pkg set type=module   # SDK is ESM-only
npm install @github/copilot-sdk tsx zod
ESM required. The SDK only ships ESM exports. Your package.json must have "type": "module".

Common imports

// Core
import { CopilotClient, approveAll } from "@github/copilot-sdk";

// Tools
import { defineTool } from "@github/copilot-sdk";
import { z } from "zod";

// Advanced — hooks, resume, types
import type { SessionConfig, ToolInvocation } from "@github/copilot-sdk";

Minimal example

import { CopilotClient, approveAll } from "@github/copilot-sdk";

const client = new CopilotClient();
const auth = await client.getAuthStatus();

if (!auth.isAuthenticated) {
  throw new Error(
    "Authenticate with `copilot login` or set COPILOT_GITHUB_TOKEN / GH_TOKEN / GITHUB_TOKEN first."
  );
}

const session = await client.createSession({
  model: "gpt-4.1",
  onPermissionRequest: approveAll,
});

const response = await session.sendAndWait({ prompt: "What is 2 + 2?" });
console.log(response?.data.content);

await session.disconnect();
await client.stop();

Save this as src/index.ts, then run npm start.

If startup does not progress:

  • Check auth.isAuthenticated first and stop there if it is false
  • In headless environments, set COPILOT_GITHUB_TOKEN, GH_TOKEN, or GITHUB_TOKEN before launching Node
  • Re-run with new CopilotClient({logLevel: "debug"}) and follow references/auth-and-byok.md for auth preflight

With streaming

const session = await client.createSession({
  model: "gpt-4.1",
  streaming: true,
  onPermissionRequest: approveAll,
});

session.on("assistant.message_delta", (event) => {
  process.stdout.write(event.data.deltaContent);
});

session.on("session.idle", async () => {
  console.log("\n--- done ---");
  await session.disconnect();
  await client.stop();
});

await session.send({ prompt: "Explain TypeScript generics" });

With a custom tool

Create the imported helper first:

// src/lib/math.ts
export function add(a: number, b: number) {
  return a + b;
}
import { CopilotClient, defineTool, approveAll } from "@github/copilot-sdk";
import { z } from "zod";
import { add } from "./lib/math.ts";

const addNumbers = defineTool("add_numbers", {
  description: "Add two numbers using local business logic",
  parameters: z.object({
    a: z.number().describe("First number"),
    b: z.number().describe("Second number"),
  }),
  handler: async ({ a, b }) => ({ result: add(a, b) }),
});

const client = new CopilotClient();
const session = await client.createSession({
  model: "gpt-4.1",
  tools: [addNumbers],
  onPermissionRequest: approveAll,
});

const response = await session.sendAndWait({
  prompt: "Use the add_numbers tool to add 19 and 23.",
});
console.log(response?.data.content);

await session.disconnect();
await client.stop();

Default convention: keep imported domain helpers under src/lib/ and wire them into tool handlers instead of hard-coding toy data inside the handler. If the real logic lives in another package, import a workspace dependency or package entrypoint that tsx can resolve at runtime instead of a source-only deep path.

Key patterns

Send-and-wait vs fire-and-forget

// Blocking — waits for session.idle, returns last assistant.message
const response = await session.sendAndWait(
  { prompt: "Hello" },
  30_000, // optional timeout in ms
);

// Non-blocking — returns immediately, events arrive via session.on()
await session.send({ prompt: "Start a long task..." });

Event subscription (typed + wildcard)

// Typed — only fires for the specific event type
const unsub = session.on("tool.execution_complete", (event) => {
  console.log(`${event.data.toolName}: ${event.data.success}`);
});

// Wildcard — fires for every event
session.on((event) => {
  if (event.type === "session.error") {
    console.error(event.data.message);
  }
});

unsub(); // unsubscribe

Session persistence

// Create with a stable ID
const session = await client.createSession({
  sessionId: "user-123-conversation",
  model: "gpt-4.1",
  onPermissionRequest: approveAll,
});
await session.sendAndWait({ prompt: "Let's discuss TypeScript" });
await session.disconnect(); // preserves state on disk

// Resume later (same or different client)
const resumed = await client.resumeSession("user-123-conversation", {
  onPermissionRequest: approveAll,
});

Create-or-resume pattern

createSession always starts fresh — only resumeSession restores conversation context. In applications that may revisit a session:

let session;
try {
  session = await client.resumeSession(sessionId, {
    onPermissionRequest: approveAll,
  });
} catch {
  session = await client.createSession({
    sessionId,
    model: "gpt-4.1",
    onPermissionRequest: approveAll,
  });
}

Handling ask_user programmatically

const session = await client.createSession({
  onPermissionRequest: approveAll,
  onUserInputRequest: async (request) => {
    if (request.choices?.length) {
      return { answer: request.choices[0], wasFreeform: false };
    }
    return { answer: "Yes, proceed", wasFreeform: true };
  },
});

Plan / autopilot mode

await session.rpc.mode.set({ mode: "plan" });

session.on("exit_plan_mode.requested", (event) => {
  console.log("Plan ready:", event.data.summary);
  session.rpc.mode.set({ mode: "autopilot" });
});

Abort in-flight work

await session.send({ prompt: "Run sleep 100" });
await session.abort(); // cancels current work; session remains usable

Common pitfalls

PitfallFix
onPermissionRequest missingRequired on every createSession/resumeSession. Use approveAll for unattended operation.
sendAndWait timeoutDefault is 60s. Pass explicit timeout: sendAndWait(opts, 300_000). Timeout does NOT abort in-flight work.
Streaming events not arrivingSet streaming: true in SessionConfig.
cliUrl + useStdioMutually exclusive. cliUrl connects to external server; useStdio spawns child process.
console.log in extensionsstdout is reserved for JSON-RPC. Use session.log() instead.
Tool name collision in extensionsTool names must be globally unique across all extensions.
BYOK without modelmodel is required when using provider config. Session creation succeeds silently, but sendAndWait will fail.
Race condition on event registrationRegister session.on() before calling session.send().

Steering notes for AI agents

These notes are distilled from real-world testing. They address the exact points where an agent following these instructions literally will get stuck.

Project initialization

  • Always run npm init -y then npm pkg set type=module before installing. The SDK is ESM-only and will throw ERR_PACKAGE_PATH_NOT_EXPORTED without this.
  • Always install zod alongside the SDK if you plan to use defineTool. It's not bundled.
  • Verify node --version is >= 20 and copilot --version responds before writing any code.

Session lifecycle

  • createSession always starts fresh — even with the same sessionId. It does NOT restore previous messages.
  • To resume a conversation, use resumeSession(sessionId). If the session doesn't exist, it throws — catch and fall back to createSession.
  • Always call session.disconnect() then client.stop() when done. Without this, streaming processes hang indefinitely because the RPC connection keeps the event loop alive.

Streaming

  • Register all event handlers (session.on(...)) before calling session.send(). Handlers registered after send may miss early events.
  • In the session.idle handler, always include cleanup (disconnect + stop) unless you're building a multi-turn REPL.
  • When the model calls multiple tools in parallel, tool.execution_start and tool.execution_complete events interleave. Use toolCallId to correlate them.

Tools

  • defineTool requires a Zod schema for parameters. The SDK auto-detects Zod and calls toJSONSchema().
  • Tool handler errors are caught and surfaced to the model as error results — they don't crash your process.
  • Tool names must be globally unique across all extensions.

Timeouts and errors

  • sendAndWait timeout does not abort in-flight work. It only stops waiting. Call session.abort() explicitly if you need to cancel.
  • BYOK without model in provider config creates a session successfully but fails silently at send time. Always pair provider with model.

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

34.86%
按下载量换算66

Claude

29.48%
按下载量换算55

Cursor

20.44%
按下载量换算38

Gemini CLI

9.78%
按下载量换算18

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

可疑

权限和风险

操作浏览器

该 Skill 可能涉及浏览器控制能力,使用时可能读取或操作网页内容,需要在受控环境中确认权限边界。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。来源安全扫描存在 warning/failed 结果,不能写成本站确认安全。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills