plugin-develop
FreeNo executable scriptsNot checkedImplement Zhin.js plugin features with Plugin Runtime: defineCommand, defineAgentTool, middleware, pages. Use when asked to add a command, register a tool…
by zhinjs★ 136 GitHub starsAbout this skill
Plugin Develop(Plugin Runtime)
在已有 Zhin 插件包内实现功能增量。能力按约定目录发现,一个文件一个能力;不要再写 MessageCommand / usePlugin() / addCommand(new …)。
何时使用
- 用户要在插件里「加一个命令 / 工具 / 定时任务 / 控制台页」
- 插件骨架已存在(
plugin-init或zhin new) - 大改目录 → 用仓库内
zhin-plugin-standard-development或迁移 skill
工作流
第 1 步:定位入口与范围
- 找到插件入口:
plugin.ts(或单文件 bot 的bot.ts) - 确认改动类型(只选一种主路径):
| 能力 | 做法 | 目录 / 位置 |
|---|---|---|
| 聊天命令 | defineCommand() default export |
commands/**/*/index.ts($ 入口路径即路由) |
| AI 工具 | defineAgentTool() |
tools/<name>/index.ts |
| 中间件 | defineMiddleware() |
middlewares/*/index.ts |
| 组件 | defineComponent() |
components/*/index.tsx |
| 定时任务 | scheduleHostToken.register(...) + lifecycle |
plugin.ts setup |
| 控制台页 | definePage() |
pages/*/index.tsx |
| 单文件 demo | setup({ addCommand }) |
仅 examples/single-file-bot 风格 |
- 确认
package.json#zhin.features已挂对应 Feature(如@zhin.js/command) - 输出:要新增/修改的文件清单
第 2 步:实现(禁止旧 API)
- 禁止:
usePlugin、getPlugin、MessageCommand、plugin.addCommand、addCron(new Cron)、useContext('web')旧写法 - 命令:文件路径是路由 SSOT;参数用 Next.js 风格文件名(
[name].ts必需 /name.ts可选 /[...name].ts捕获所有),类型与默认值在defineCommand({ params })中声明;execute读params/args/input - 出站:走统一发送链(
$reply/ Adapter.sendMessage),禁止直调平台 Bot - 本地导入带
.js扩展名
命令示例 commands/greet/[name]/index.ts:
import { defineCommand } from 'zhin.js/command';
export default defineCommand({
description: '问候用户',
params: {
name: { type: 'string', description: '用户名字' },
},
execute({ params }) {
return `你好,${params.name}!`;
},
});
工具示例 tools/get_weather/index.ts:
import { defineAgentTool } from '@zhin.js/tool';
export default defineAgentTool({
description: '查询天气',
inputSchema: {
type: 'object',
properties: { city: { type: 'string', description: '城市名' } },
required: ['city'],
},
async execute({ city }) {
return `${city}:晴,25°C`;
},
});
定时任务(在 plugin.ts setup;完整骨架见仓库 skill assets/cron-template.ts):
import { definePlugin, scheduleHostToken } from 'zhin.js';
export default definePlugin({
name: 'my-plugin',
setup(context) {
if (!context.resources.has(scheduleHostToken)) return;
const schedule = context.resources.use(scheduleHostToken);
context.lifecycle.add(
schedule.register({
id: 'my-plugin/hourly',
cron: '0 * * * *',
async execute() { /* ... */ },
}),
);
},
});
第 3 步:验证
pnpm --filter <plugin-package> build # 若包有 build
pnpm --filter <plugin-package> test
# 手测:pnpm dev(zhin start --foreground)+ Sandbox 发命令原文
第 4 步:输出格式
## 改动摘要
- 插件:`<package-name>`
- 类型:命令 | 工具 | cron | 中间件 | 控制台页
## 修改文件
- `commands/...` — 作用
## 验证
- `pnpm --filter <pkg> test`
- 手测:Sandbox 发 `命令原文` / 工具名
## 风险
- (仅列与本次改动相关的未测项)
文档
docs/authoring/define-plugin.mddocs/getting-started/first-plugin.md.github/instructions/zhin-plugin.instructions.md
Install plugin-develop in Claude Code & Claude Desktop
Sign up to install this skill
Create a free account to reveal the install command and save the skill to your library.
- Reveal the one-line install command
- Save skills to your synced library
- Get notified when skills update
Allowed tools
Tools this skill is permitted to call.
No restriction — this skill can use any tool.
Bundled files
FAQ
What does the plugin-develop skill do?
Implement Zhin.js plugin features with Plugin Runtime: defineCommand, defineAgentTool, middleware, pages. Use when asked to add a command, register a tool, wire cron, extend middleware, or build a console page. Triggers: 插件开发, add command, 加命令, 写插件功能, defineCommand.
How do I install the plugin-develop skill?
Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.
Does the plugin-develop skill run scripts?
No, this skill is instructions only (SKILL.md) with no executable scripts.
Related skills
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
by Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
by Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
by Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
by Anthropic