hello-plugin 使用指南
DSH 插件开发技能包中的最小生命周期示例,演示插件加载与 ctx.effect 自动清理的标准写法。
本文为派生内容(基于 wiki / faq / compatibility_json 自动组装),非 AI 即时创作。
本文由本站基于该插件已收录的字段自动派生(wiki / faq / compatibility_json / readme),非 AI 即时创作。每节末尾标源字段。
快速上手
dsh-plugin-dev-skills / examples/hello-plugin
— 源: plugin_wiki.wiki_content
安装与验证
dsh plugin --profile web add dsh-hello-plugin
复制以上命令在 DSH Web Profile 内运行。安装完成后在「插件列表」启用即可。
— 源: plugins.install
关键要点
examples/hello-plugin—— 最小插件(bundle 格式):dsh plugin --profile demo add ./examples/hello-plugin后dsh --profile demo启动,应看到加载日志和每 5 秒一次的心跳,卸载时自动清理。examples/greet-tool—— 最小模型工具:安装后对 agent 说 "Use the greet tool to greet Ada.",应收到 "Hello, Ada!"。- 更新任何 references 前,先核对官方文档对应页面(文档站或源码生成区块),并在 PR 中注明来源。
- 遵守 Agent Skills 约束:name 为 kebab-case 且与目录一致;description ≤ 1024 字符(DSH 目录注入提醒默认 500);正文渐进式披露。
- 欢迎 PR:修正、更多示例、扩充评测集、其它语言版本。
— 源: plugin_wiki.readme_zh (fallback readme_raw)
常见问题
安装后这个插件能做什么实际功能?
没有任何业务功能。它只在加载时打印一行日志,然后每 5 秒打印一次心跳,用来观察插件层是否被正确加载以及 ctx.effect 的清理是否被触发。
这个插件需要构建步骤吗?
不需要。index.js 是纯 ESM JavaScript,直接被宿主当 Node 模块加载;package.json 的 files 字段也只发布 index.js 和 cordis.patch.yml 两个文件。
安装后看到 [hello-plugin] plugin loaded! 之后要等多久会看到心跳?
5 秒。setInterval 间隔在 index.js:11 写死为 5000 毫秒,从插件加载完成时刻开始每 5 秒打印一次 [hello-plugin] heartbeat。
卸载插件后心跳会立即停止吗?
是的。ctx.effect 返回的清理函数会在插件卸载时被自动调用,clearInterval 会清掉这个定时器,停止继续输出心跳。
这个示例和同仓库的 greet-tool 示例有什么区别?
hello-plugin 是最简生命周期示例,演示插件加载与 ctx.effect 自动清理;greet-tool 则是模型可调用的工具示例,演示 defineTool 的三段式写法。两者侧重点不同。
为什么 cordis.patch.yml 里 id 写成 hello 而不是 hello-plugin?
这是 Cordis 层 id 的命名选择,与 index.js 里 export 的 name 字段没有强制对应关系。id 是配置图里的层标识,name 是插件在运行时的逻辑名,二者可以不同。
插件的 dsh-hello-plugin 名字是怎么来的?
来自 package.json 的 name 字段(dsh-hello-plugin),同时 cordis.patch.yml 里 insert 行的 name 字段也声明为 dsh-hello-plugin,保证 Node 模块解析能找到已安装代码。
看 hello-plugin 源码能学到的核心知识点是什么?
三个:package.json 的 dsh.bundle.patch 必须指向 cordis.patch.yml;index.js 只需要 export name 和 apply(ctx);任何通过 ctx 注册的副作用(这里是 setInterval)必须放进 ctx.effect,卸载时才不会被泄漏。
— 源: plugin_wiki.faq_json
兼容性
- DSH: 未声明
- Node: 未声明
- Platforms: 跨平台
— 源: plugin_wiki.compatibility_json
踩坑提醒
安装前请审阅上游仓库;本指南基于已收录字段自动派生,可能滞后于最新版本。如发现与官方文档冲突,请以上游为准。
— 来源:通用规则