编写插件
插件把工具、钩子、生命周期脚本打包在一个 plugin.json
背后。DSCC 启动时发现插件,把它们的工具并入 agent
工具面,并把钩子与用户钩子一起执行。
清单位置
| 布局 | 路径 |
|---|---|
| 平铺 | 插件根目录的 plugin.json |
| 打包 | ./.dscc-plugin/plugin.json |
解析位置:crates/plugins/src/lib.rs:107–122。
清单 schema
| 字段 | 类型 | 用途 |
|---|---|---|
name |
string(必填) | 插件 id |
version |
string(必填) | Semver |
description |
string | 一行描述 |
permissions |
string[] | 声明 read/write/execute |
defaultEnabled |
bool | 安装后是否默认启用(默认 false) |
hooks.PreToolUse |
string[] | 钩子脚本路径 |
hooks.PostToolUse |
string[] | 钩子脚本路径 |
lifecycle.Init |
string[] | 启用时运行 |
lifecycle.Shutdown |
string[] | 停用时运行 |
tools[] |
object[] | 贡献给 agent 的工具 |
commands[] |
object[] | 具名 shell 命令 |
工具条目
{
"name": "my-tool",
"description": "...",
"inputSchema": {"type": "object", "properties": {}},
"command": "/absolute/path/to/executable",
"args": ["--flag"],
"requiredPermission": "read-only"
}
合法
requiredPermission:read-only、workspace-write、danger-full-access。
插件种类
来自 plugins/lib.rs:25–50。
| 种类 | 来源 |
|---|---|
builtin |
随 DSCC 一起编译 |
bundled |
随发行包分发,同步到 install root |
external |
用户通过 /plugin install 安装 |
发现
由 plugins/lib.rs:1097–1150 解析:
- 扫描
install_root(默认~/.dscc/plugins/)找合法清单。 - 从
installed.json注册表加载;失效条目标记为 stale。 - 从配置中的
plugins.externalDirectories加载。 - 按插件 id 去重。
生命周期 CLI
来自 commands/lib.rs:692–801。
| 命令 | 用途 |
|---|---|
/plugin list(别名
/plugins、/marketplace) |
列出已安装插件 |
/plugin install <path> |
从本地路径安装 |
/plugin enable <name> |
启用 |
/plugin disable <name> |
停用 |
/plugin uninstall <id> |
卸载 |
/plugin update <id> |
从源更新 |
钩子
定义于 plugins/hooks.rs:11–22。事件、stdin
负载、环境变量与运行时钩子一致(见 guides/hooks.md)。
| 行为 | 规则 |
|---|---|
| 顺序 | 多个插件的钩子按顺序合并 |
| Deny | 第一个 exit 2 拒绝这次工具调用 |
| 其它非零 | 告警,但允许通过 |
最小可用示例
./my-plugin/plugin.json:
{
"name": "hello-plugin",
"version": "0.1.0",
"description": "Adds a greet tool and a PreToolUse audit hook",
"defaultEnabled": true,
"tools": [
{"name": "greet", "description": "Print hello", "command": "./bin/greet.sh", "requiredPermission": "read-only"}
],
"hooks": {"PreToolUse": ["./hooks/audit.sh"]}
}
脚本用相对路径时,以插件根目录为基准解析。
测试你的插件
插件安装走 REPL 斜杠命令,没有
dscc plugin … CLI 子命令(见
crates/commands/src/lib.rs:692-801)。
/plugin install ./my-plugin/ # [交互] 在 REPL 内执行
在 DSCC 中:
| 步骤 | 检查点 |
|---|---|
/plugin list |
hello-plugin 出现并已启用 |
让模型调用 greet |
工具运行,audit.sh 在 PreToolUse 触发 |
/plugin disable hello-plugin |
工具从工具面消失 |
另见
- guides/hooks.md —— 钩子完整契约(stdin、env、exit)。
- guides/slash-commands.md
——
/plugin等命令。