# 为 GitHub Copilot CLI 创建插件

创建插件以在易于安装的包中共享自定义项。

## 介绍

插件是用于扩展Copilot CLI功能的包。 请参阅“[关于 GitHub Copilot 插件](/zh/copilot/concepts/agents/about-plugins)”。

> \[!NOTE]
> 可以通过在终端中输入 `copilot plugin [SUBCOMMAND] --help` 来查找有关使用插件的帮助。

## 插件结构

插件由具有特定结构的目录组成。 它必须至少在目录的根目录中包含一个`plugin.json`清单文件。 它还可以包含代理、技能、挂钩和 MCP 服务器配置的任意组合。

### 示例插件结构

```text
my-plugin/
├── plugin.json           # Required manifest
├── agents/               # Custom agents (optional)
│   └── helper.agent.md
├── skills/               # Skills (optional)
│   └── deploy/
│       └── SKILL.md
├── hooks.json            # Hook configuration (optional)
└── .mcp.json             # MCP server config (optional)
```

## 创建插件

1. 为插件创建目录。

2. 将 `plugin.json` 清单文件添加到目录的根目录。

**示例 `plugin.json` 文件**

```json copy
{
  "name": "my-dev-tools",
  "description": "React development utilities",
  "version": "1.2.0",
  "author": {
    "name": "Jane Doe",
    "email": "jane@example.com"
  },
  "license": "MIT",
  "keywords": ["react", "frontend"],
  "agents": "agents/",
  "skills": ["skills/", "extra-skills/"],
  "hooks": "hooks.json",
  "mcpServers": ".mcp.json"
}
```

有关可包含在此文件中的完整字段集的详细信息，请参阅 [GitHub Copilot CLI 插件参考](/zh/copilot/reference/copilot-cli-reference/cli-plugin-reference#pluginjson)。

1. 通过为代理、技能、挂钩和 MCP 服务器配置创建适当的文件和目录，将某些组件添加到插件。

   例如：

   1. 通过在子目录中创建 `NAME.agent.md` 文件 `agents` 来添加代理。

      ```markdown copy
      ---
      name: my-agent
      description: Helps with specific tasks
      tools: ["bash", "edit", "view"]
      ---

      You are a specialized assistant that...
      ```

   2. 通过在插件目录中创建一个名为`skills/NAME`的子目录来添加技能，其中`skills/NAME`是技能的名称。 然后，在此子目录中，创建定义 `SKILL.md` 技能的文件。

      例如，若要创建“部署”技能，请创建 `skills/deploy/SKILL.md`：

      ```markdown copy
      ---
      name: deploy
      description: Deploy the current project to...
      ---

      Instructions for the skill...
      ```

2. 在本地安装插件，以便在开发插件时对其进行测试。

   例如，其中 `./my-plugin` 是您的插件目录的路径，请输入：

   ```shell copy
   copilot plugin install ./my-plugin
   ```

3. 查看已安装的插件列表，验证插件是否已成功加载：

   ```shell copy
   copilot plugin list
   ```

   或者，可以启动新的交互式会话并输入：

   ```copilot copy
   /plugin list
   ```

4. 验证是否已正确加载定义的代理、技能、挂钩和 MCP 服务器配置。

   例如，在交互式会话中，若要检查插件中定义的自定义代理是否已加载，请输入：

   ```copilot copy
   /agent
   ```

   若要检查插件中定义的技能是否已加载，请输入：

   ```copilot copy
   /skills list
   ```

5. 使用插件组件提供的功能来验证每个组件是否按预期工作。

6. 根据需要迭代您的插件开发。

   > \[!IMPORTANT]
   > 安装插件时，会缓存其组件，CLI 会从缓存中读取后续会话。 若要使对本地插件的更改生效，请再次安装插件。
   >
   > ```shell copy
   > copilot plugin install ./my-plugin
   > ```

7. 测试完成后，可以通过输入以下内容卸载插件的本地版本：

   ```shell copy
   copilot plugin uninstall NAME
   ```

   > \[!NOTE]
   > 若要卸载插件，请使用插件清单文件字段中指定的 `name` 插件 `plugin.json` 名称，而不是插件目录的路径。

## 分发插件

若要分发插件，可以将其添加到市场。 请参阅“[为 GitHub Copilot CLI 创建插件市场](/zh/copilot/how-tos/copilot-cli/customize-copilot/plugins-marketplace)”。

## 延伸阅读

* [查找并安装插件适用于GitHub Copilot CLI](/zh/copilot/how-tos/copilot-cli/customize-copilot/plugins-finding-installing)
* [GitHub Copilot CLI 插件参考](/zh/copilot/reference/copilot-cli-reference/cli-plugin-reference)