# 扩展门控

```
// agent.json
{
  "tools":  {"mode": "automatic", "disabled": ["bash", "*_dangerous"]},
  "skills": {"disabled": ["devops/*"], "allowed": [], "categories": ["research", "writing"]},
  "mcp":    {"disabled": ["slack"], "allowed": [], "required": ["drawio*"]}
}
```

## 字段

| 字段 | `tools` | `skills` | `mcp` | 效果 |
| --- | --- | --- | --- | --- |
| `disabled` | 有 | 有 | 有 | 匹配的名称被拒绝 |
| `allowed` | 有 | 有 | 有 | 非空时只有匹配项通过 |
| `categories` | 无 | 有 | 无 | 非空时，声明了分类的技能必须匹配 |
| `required` | 无 | 无 | 有 | 任一模式匹配不到剩余服务时，本轮停止 |
| `mode` | 有 | 无 | 无 | `automatic`（默认）、`selected`、`none` |

模式使用 `fnmatch.fnmatchcase`：`*`、`?`、`[abc]`；精确名称是最简单的情况。`mcp` 模式匹配服务名，即 `<server>__<tool>` 中 `__` 之前的部分。`mode: selected` 时 `tools.allowed` 写精确名称。插件本身不受门控：插件是宿主级贡献者，门控作用于它贡献的技能、工具和 MCP。

### 判定顺序

1. `disabled`：匹配则拒绝。
2. `allowed` 非空时：不匹配则拒绝。
3. `categories`：非空列表拒绝不在其中的已分类技能。
4. `required`，仅 MCP，在过滤之后检查：有未匹配的模式则整轮失败。

## 为什么是这个形状

Claude Code 的按类型字段，加上 opencode 的通配表达力。每个字段说明它管什么；一个模式代替五个名称；新扩展类型就是同样形状的新块。对比见[参考实现对比](https://fzkuji.github.io/OpenProgram/docs/reference/design/extension-gating/reference-comparison.zh.html)。

## 示例

| Agent | 配置 | 模型看到 |
| --- | --- | --- |
| 客服 | `tools: {disabled: [write, edit, execute_*, apply_patch]} skills: {categories: [customer-service, writing]} mcp: {disabled: ["*"]}` | 没有编辑工具，只有这些技能分类，没有 MCP |
| DevOps | `skills: {disabled: [prod-deploy, drop-database]} mcp: {required: ["github*", "k8s*"]}` | 除两个技能外全部可用。缺少 GitHub 和 k8s MCP 时，本轮在调用供应商前失败 |
| 研究 | `tools: {allowed: [read, grep, glob, web_fetch], web_search: true} skills: {categories: [research]} mcp: {allowed: ["arxiv*", "scholar*"]}` | 这些工具加网页搜索、研究技能、这些 MCP 服务 |

`web_search` 不在默认工具列表中，只写 `allowed` 不会加入它。

## 何时不用门控

默认：全局安装技能，不配门控，让模型根据每个技能的 `description` 选择。观察到具体的不良行为后再加门控，适用于：

- 某技能需要硬隔离（`prod-deploy` 绝不出现在客服中）；
- 列出允许集比调整描述更简单；
- 没有某个 MCP 服务时该 Agent 没有意义。

[实现位置](https://fzkuji.github.io/OpenProgram/docs/reference/design/extension-gating/implementation.zh.html) · [未构建项](https://fzkuji.github.io/OpenProgram/docs/reference/design/extension-gating/future-work.zh.html) · [调用统一](https://fzkuji.github.io/OpenProgram/docs/reference/design/function/calling-unification.zh.html)（函数调用的六层门控）· [技能与插件](https://fzkuji.github.io/OpenProgram/docs/reference/design/integrations/extensions/skills-and-plugins.zh.html)（目录、发现、热加载）
