[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6DT7P6KWAMXPH4933661G36":3,"skill-same:01M6DT7P6KWAMXPH4933661G36":54},{"skillNo":4,"name":5,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":21,"linkOnly":22,"markdownContent":23,"markdownBody":23,"frontMatter":24,"refName":25,"commitSha":26,"skillDirectory":27,"forksCount":28,"repositoryHtmlUrl":29,"repositoryHomepageUrl":30,"ownerHtmlUrl":31,"ownerBlogUrl":32,"ownerDescription":6,"updatedAt":33,"install":34,"resources":47},"01M6DT7P6KWAMXPH4933661G36","plugin-creation",null,"liwusen\u002FFaustBot-llm-vtuber","liwusen","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F33620294?v=4","01M6DT6ES2QEX7T1WFY1MQ0K1A","allenlee","01M6DT6EWK9J0J4ZMC27B7XK2Z",45,"GPL-3.0","https:\u002F\u002Fgithub.com\u002Fliwusen\u002FFaustBot-llm-vtuber\u002Fblob\u002Fmain\u002Fbackend\u002Fskill_template\u002Fplugin-creation\u002FSKILL.md",[],[18,19,20],"plugin","creation","plugin creation","2026-11-10 10:12:30",false,"# Agent 自建插件技能\n\n本技能指导 AI 如何为自己创建 FaustBot 插件，扩展功能、工具、中间件或定时任务。\n\n## 强制工作流\n\n在开始写任何插件代码前，必须先读取两类资料：\n\n1. 先读取插件文档：`read(\"faustbot:\u002F\u002Ftool_use.md\")` 与 `read(\"sourceCode:\u002F\u002Fdocument\u002Fplugin.md\")`\n2. 再读取源码：至少阅读以下一个或多个入口，再决定如何实现\n    - `read(\"sourceCode:\u002F\u002Fbackend\u002Ffaust_backend\u002Fplugin_system\u002Finterfaces.py\")`\n    - `read(\"sourceCode:\u002F\u002Fbackend\u002Ffaust_backend\u002Fplugin_system\u002Fmanager.py\")`\n    - `read(\"sourceCode:\u002F\u002Fbackend\u002Ffaust_backend\u002Fplugin_system\u002Fplugin_base.py\")`\n    - `read(\"sourceCode:\u002F\u002Fbackend\u002Ffaust_backend\u002Froutes\u002Fadmin_plugins.py\")`\n\n不要在没有阅读 `sourceCode:\u002F\u002F...` 源码的情况下直接生成插件代码。\n\n## 目录结构\n\n```\n~\u002F.faustbot\u002Fplugins\u002Fmy-plugin\u002F\n├── plugin.json    # 插件元数据\n├── impl.py        # 插件代码（推荐）\n├── data\u002F          # 插件数据目录（可选）\n└── frontend\u002F      # 前端资源（可选）\n    ├── panel.js\n    ├── app-hook.js\n    └── panel.css\n```\n\n## plugin.json 字段\n\n```json\n{\n  \"id\": \"my-plugin\",\n  \"name\": \"My Plugin\",\n  \"version\": \"1.0.0\",\n  \"description\": \"插件功能描述\",\n  \"author\": \"FaustBot\",\n  \"enabled\": true,\n  \"entry\": \"impl.py\",\n  \"permissions\": [],\n  \"priority\": 500\n}\n```\n\n| 字段 | 类型 | 必需 | 默认值 | 说明 |\n|------|------|------|--------|------|\n| `id` | string | 是 | - | 插件唯一标识符 |\n| `name` | string | 是 | - | 显示名称 |\n| `version` | string | 否 | `\"0.1.0\"` | 语义化版本号 |\n| `description` | string | 否 | `\"\"` | 功能描述 |\n| `author` | string | 否 | `\"\"` | 作者 |\n| `enabled` | bool | 否 | `true` | 是否启用 |\n| `entry` | string | 否 | `\"main.py\"` | 入口文件名 |\n| `permissions` | list | 否 | `[]` | 所需权限声明 |\n| `priority` | int | 否 | `100` | 加载优先级（越小越先） |\n\n## 新风格插件（推荐）：FaustPlugin 基类\n\n继承 `faust_backend.plugin_system.FaustPlugin`，覆写需要的 hook：\n\n```python\nfrom faust_backend.plugin_system import FaustPlugin, PluginContext, ToolSpec, hookimpl\nfrom langchain.tools import tool\n\nclass Plugin(FaustPlugin):\n    def startup(self, ctx: PluginContext) -> None:\n        \"\"\"插件启动时调用\"\"\"\n        self.ctx = ctx\n        # 注册配置\n        ctx.register_config([\n            {\"key\": \"MY_KEY\", \"type\": \"str\", \"label\": \"我的配置\", \"default\": \"value\"},\n            # type \"llm\"：配置中心显示\"当前模型标识符 + 模型选择按钮\"，\n            # 值存 \"provider::model\" 字符串，未选择时缺省为主对话模型\n            {\"key\": \"MY_MODEL\", \"type\": \"llm\", \"label\": \"使用的模型\"},\n        ])\n        # 写入 VFS 文档\n        ctx.vfs_write(\"\u002Fplugins\u002Fmy-plugin.md\", \"# My Plugin\\n\\nAgent 读取此文件了解插件能力\")\n\n    @hookimpl\n    def plugin_loaded(self, ctx: PluginContext) -> None:\n        \"\"\"插件加载后初始化\"\"\"\n        global _PLUGIN\n        _PLUGIN = self\n\n    @hookimpl\n    def plugin_unloaded(self, ctx: PluginContext) -> None:\n        \"\"\"插件卸载前清理\"\"\"\n        global _PLUGIN\n        if _PLUGIN is self:\n            _PLUGIN = None\n\n    # 1. 注册工具\n    def register_tools(self, ctx: PluginContext) -> list:\n        @tool\n        def myTool(param: str) -> str:\n            \"\"\"工具描述，Agent 会看到这个描述。\"\"\"\n            return \"结果\"\n        return [ToolSpec(name=\"myTool\", tool=myTool)]\n\n    # 2. 注册定时任务\n    def register_schedules(self) -> list[dict]:\n        return [\n            {\"id\": \"poll\", \"interval\": 300, \"callback\": self.do_poll, \"description\": \"每5分钟轮询\"},\n        ]\n\n    async def do_poll(self):\n        pass\n\n    # 3. 心跳处理\n    @hookimpl\n    def heartbeat(self, ctx: PluginContext) -> None:\n        \"\"\"每10秒调用一次\"\"\"\n        pass\n\n    # 4. 前端资源\n    def register_frontend(self) -> list[dict]:\n        return [\n            {\"type\": \"js\", \"path\": \"\u002Ffaust\u002Fplugins\u002Fmy-plugin\u002Ffrontend\u002Fpanel.js\"},\n            {\"type\": \"css\", \"path\": \"\u002Ffaust\u002Fplugins\u002Fmy-plugin\u002Ffrontend\u002Fpanel.css\"},\n        ]\n\n    # 5. 前后端通信\n    def communicate_handler(self, payload: dict, ctx: PluginContext) -> dict | None:\n        action = payload.get(\"action\")\n        if action == \"get_state\":\n            return {\"status\": \"ok\", \"state\": {}}\n        return {\"status\": \"error\", \"detail\": f\"unknown action: {action}\"}\n\n    # 6. 注入 Agent 提示\n    def register_prompt_suffix(self) -> list[str]:\n        return [\"\\n[My Plugin]\\n本插件提供 XXX 功能...\\n\"]\n\n    # 7. 健康检查\n    def health_check(self) -> dict | None:\n        return {\"status\": \"ok\", \"plugin\": \"my-plugin\"}\n\ndef get_plugin():\n    return Plugin()\n```\n\n## 旧风格插件（兼容）：Plugin 类\n\n```python\nfrom faust_backend.plugin_system import PluginManifest, PluginContext, ToolSpec\n\nclass Plugin:\n    manifest = PluginManifest(plugin_id=\"my-plugin\", name=\"My Plugin\")\n\n    def on_load(self, ctx: PluginContext) -> None: pass\n    def on_unload(self, ctx: PluginContext) -> None: pass\n    def startup(self, ctx: PluginContext) -> None: pass\n\n    def register_tools(self, ctx):\n        return [ToolSpec(name=\"myTool\", tool=my_function)]\n\n    def register_middlewares(self, ctx):\n        return []\n\n    def health_check(self):\n        return {\"status\": \"ok\"}\n\ndef get_plugin():\n    return Plugin()\n```\n\n## 支持的 Hook 一览\n\n### 生命周期\n\n| Hook | 用途 |\n|------|------|\n| `plugin_loaded(ctx)` | 插件加载后初始化 |\n| `plugin_unloaded(ctx)` | 插件卸载前清理 |\n| `startup(ctx)` | 插件启动时调用 |\n| `heartbeat(ctx)` | 周期性心跳（约每10秒） |\n| `health_check()` | 返回健康状态 |\n\n### 前端\n\n| Hook | 用途 |\n|------|------|\n| `register_frontend()` | 声明前端 JS\u002FCSS 资源 |\n| `communicate_handler(payload, ctx)` | 处理前端 POST 请求 |\n\n配置中心的面板脚本（`window.pluginUI`）必须用 `api.registerPersistence({ plugin, save, apply?, reload? })`\n把面板草稿交给配置中心右上角的「保存 \u002F 应用 \u002F 重新加载」，并用返回 handle 的 `setDirty()` 报告未保存状态；\n**不要**在面板里再放一个独立的保存按钮（详见 `read(\"sourceCode:\u002F\u002Fdocs\u002Fplugin-api-reference.md\")` 的「配置中心统一保存」）。\n\n### 工具与中间件\n\n| Hook | 用途 |\n|------|------|\n| `register_tools(ctx)` | 注册 Agent 可用工具 |\n| `register_middlewares(ctx)` | 注册 Agent 中间件 |\n| `tool_call_pre(name, args, ctx)` | 工具调用前拦截 |\n| `tool_call_post(name, args, result, ctx)` | 工具调用后处理 |\n\n### 消息与记忆\n\n| Hook | 用途 |\n|------|------|\n| `message_received(msg, history, ctx)` | 拦截\u002F修改用户消息（**洋葱模型**：多个实现按 `priority` 升序逐层串联，每层入参是上一层的结果；返回 `None` 不改，返回字符串传给下一层，返回 `\"__IGNORED__\"` 拦截。用户消息与所有触发器路径都会经过这里） |\n| `agent_event_sent(event, current_history, ctx)` | 拦截\u002F抑制 Agent 事件 |\n| `memory_read_pre(query, filters, ctx)` | 记忆读取前重写查询 |\n| `memory_read_post(query, results, ctx)` | 记忆读取后重排结果 |\n| `memory_write_pre(content, metadata, ctx)` | 记忆写入前拦截 |\n| `memory_write_post(content, metadata, id, ctx)` | 记忆写入后通知 |\n\n### 触发器\n\n| Hook | 用途 |\n|------|------|\n| `trigger_append(payload, ctx)` | 触发器追加前过滤 |\n| `trigger_fire(payload, ctx)` | 触发器触发前过滤 |\n\n### Prompt 与配置\n\n| Hook | 用途 |\n|------|------|\n| `register_prompt_suffix()` | 注入 Agent 系统提示后缀 |\n| `config_changed(key, old, new, ctx)` | 配置值变更时调用 |\n\n### 定时任务\n\n| Hook | 用途 |\n|------|------|\n| `register_schedules()` | 注册定时任务（cron\u002Finterval） |\n| `register_pip_deps()` | 声明 pip 依赖 |\n\n## PluginContext API\n\n### 触发器管理\n\n```python\nctx.trigger_create(payload)      # 创建触发器\nctx.trigger_list()               # 列出所有触发器\nctx.trigger_get(trigger_id)      # 获取单个触发器\nctx.trigger_update(trigger_id, payload)  # 更新触发器\nctx.trigger_delete(trigger_id)   # 删除触发器\n```\n\n### 配置管理\n\n```python\nctx.register_config(schema)      # 注册配置 schema\nctx.get_config(key, default)     # 读取配置\nctx.set_config(key, value)       # 写入配置\nctx.list_configs()               # 列出所有配置\n```\n\n### 虚拟文件系统（VFS）\n\n```python\nctx.vfs_read_text(path, default)  # 读取文本\nctx.vfs_write(path, content, description=\"节点用途\")  # 写入文本（description 同 vfs_write_symbolic，会展示在 read(..., with_metadata=True) 的列举里）\nctx.vfs_write_symbolic(path, func, search=True, description=\"节点用途\")  # 写入动态内容（description 会展示在 read(..., with_metadata=True) 的列举里）\nctx.vfs_delete(path)              # 删除文件\nctx.vfs_list(path)                # 列出目录\n```\n\n## 实现要求\n\n- 优先使用新风格 `FaustPlugin` 基类，不要新建旧风格示例\n- 若插件需要工具、配置、路由、前端资源，请逐项对照源码接口后再实现\n- 如果要调用现有后端能力，优先通过 `sourceCode:\u002F\u002Fbackend\u002Ffaust_backend\u002F...` 阅读真实实现（目录可直接列出）\n- 如果要暴露前端资源，必须同时检查插件管理路由与前端资源收集逻辑\n- 插件前端面板不要自建保存按钮：保存\u002F应用\u002F重新加载统一走配置中心的 `registerPersistence`\n- 如果要落地配置，必须先注册 schema，再读写配置值\n\n## 安装\u002F重载流程\n\n```bash\n# 1. 写文件\nwrite(\"plugins\u002Fmy-plugin\u002Fplugin.json\", json_content)\nwrite(\"plugins\u002Fmy-plugin\u002Fimpl.py\", python_content)\n\n# 2. 重载插件\nexecute(\"curl -X POST http:\u002F\u002Flocalhost:13900\u002Ffaust\u002Fadmin\u002Fplugins\u002Freload\")\n\n# 3. 检查错误\nread(\"plugins\u002Fmy-plugin\u002F__error__\")  # 如有错误\n\n# 4. 启用插件\nexecute(\"curl -X POST http:\u002F\u002Flocalhost:13900\u002Ffaust\u002Fadmin\u002Fplugins\u002Fmy-plugin\u002Fenable\")\n```\n\n## 注意事项\n\n- 插件代码在 Agent 进程内执行，无沙箱隔离\n- 工具名冲突时跳过插件工具（内置优先）\n- 定时任务 interval 单位为秒\n- 路由挂载路径自动加 `\u002Ffaust\u002Fplugins\u002F{plugin_id}\u002F` 前缀\n- 插件真实存储目录位于 `~\u002F.faustbot\u002Fplugins\u002F`，不是仓库内 `backend\u002Fplugins\u002F`\n- 写插件前必须先读取 `document\u002Fplugin.md` 和 `plugin_system` 源码，确认 API 后再编码\n",{},"main","9b6375444e3dd715ef960debd9a6a23875aa3e31","backend\u002Fskill_template\u002Fplugin-creation",4,"https:\u002F\u002Fgithub.com\u002Fliwusen\u002FFaustBot-llm-vtuber","https:\u002F\u002Ffaustbot.allenlee.xyz","https:\u002F\u002Fgithub.com\u002Fliwusen","https:\u002F\u002Fallenlee.xyz","2026-10-29 21:25:43",{"source":7,"skillName":5,"commands":35,"prompt":45,"zipAvailable":46},[36,39,42],{"tool":37,"command":38},"npx","npx skills add liwusen\u002FFaustBot-llm-vtuber --skill plugin-creation",{"tool":40,"command":41},"bunx","bunx skills add liwusen\u002FFaustBot-llm-vtuber --skill plugin-creation",{"tool":43,"command":44},"pnpm","pnpm dlx skills add liwusen\u002FFaustBot-llm-vtuber --skill plugin-creation","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fliwusen\u002FFaustBot-llm-vtuber\u002Fblob\u002Fmain\u002Fbackend\u002Fskill_template\u002Fplugin-creation\u002FSKILL.md",true,[48],{"path":49,"resourceType":50,"resourceTypeDesc":51,"sizeBytes":52,"sourceHtmlUrl":53},"_meta.json","REFERENCE","参考文档",318,"https:\u002F\u002Fgithub.com\u002Fliwusen\u002FFaustBot-llm-vtuber\u002Fblob\u002Fmain\u002Fbackend\u002Fskill_template\u002Fplugin-creation\u002F_meta.json",[55,65,72,78,84,92],{"skillNo":56,"name":57,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":58,"categories":59,"keywords":60,"publishedAt":21},"01M6DT7RGPMB7EERSG4H3RV3DR","self-improvement-using-agile","https:\u002F\u002Fgithub.com\u002Fliwusen\u002FFaustBot-llm-vtuber\u002Fblob\u002Fmain\u002Fbackend\u002Fskill_template\u002Fself-improvement-using-agile\u002FSKILL.md",[],[61,62,63,64],"agile","self improvement","self","self improvement using agile",{"skillNo":66,"name":67,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":68,"categories":69,"keywords":70,"publishedAt":21},"01M6DT7KEAVA6PFXMA391GWWSE","nimble-window","https:\u002F\u002Fgithub.com\u002Fliwusen\u002FFaustBot-llm-vtuber\u002Fblob\u002Fmain\u002Fbackend\u002Fskill_template\u002Fnimble-window\u002FSKILL.md",[],[71],"nimble window",{"skillNo":73,"name":74,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":75,"categories":76,"keywords":77,"publishedAt":21},"01M6DT7F7C525SCTH5D3DXTEJK","minecraft","https:\u002F\u002Fgithub.com\u002Fliwusen\u002FFaustBot-llm-vtuber\u002Fblob\u002Fmain\u002Fbackend\u002Fskill_template\u002Fminecraft\u002FSKILL.md",[],[74],{"skillNo":79,"name":80,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":81,"categories":82,"keywords":83,"publishedAt":21},"01M6DT7CKB243AY1S7KC7569EV","gesellschaft","https:\u002F\u002Fgithub.com\u002Fliwusen\u002FFaustBot-llm-vtuber\u002Fblob\u002Fmain\u002Fbackend\u002Fskill_template\u002Fgesellschaft\u002FSKILL.md",[],[80],{"skillNo":85,"name":86,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":87,"categories":88,"keywords":89,"publishedAt":21},"01M6DT7ANWB1F7DX98BV8XFY1S","faustbot-using-guide","https:\u002F\u002Fgithub.com\u002Fliwusen\u002FFaustBot-llm-vtuber\u002Fblob\u002Fmain\u002Fbackend\u002Fskill_template\u002Ffaustbot-using-guide\u002FSKILL.md",[],[90,91],"guide","faustbot using guide",{"skillNo":93,"name":94,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":95,"categories":96,"keywords":97,"publishedAt":21},"01M6DT76MTHWPVXS99266PQCBX","desktop-mood-rules","https:\u002F\u002Fgithub.com\u002Fliwusen\u002FFaustBot-llm-vtuber\u002Fblob\u002Fmain\u002Fbackend\u002Fskill_template\u002Fdesktop-mood-rules\u002FSKILL.md",[],[98,99,100],"desktop","Rules","desktop mood rules"]