mofox-plugin-dev-toolkit 0.3.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mofox_plugin_dev_toolkit-0.3.3.dist-info/METADATA +730 -0
- mofox_plugin_dev_toolkit-0.3.3.dist-info/RECORD +46 -0
- mofox_plugin_dev_toolkit-0.3.3.dist-info/WHEEL +5 -0
- mofox_plugin_dev_toolkit-0.3.3.dist-info/entry_points.txt +2 -0
- mofox_plugin_dev_toolkit-0.3.3.dist-info/licenses/LICENSE +674 -0
- mofox_plugin_dev_toolkit-0.3.3.dist-info/top_level.txt +1 -0
- mpdt/__init__.py +15 -0
- mpdt/__main__.py +8 -0
- mpdt/cli.py +316 -0
- mpdt/commands/__init__.py +9 -0
- mpdt/commands/check.py +498 -0
- mpdt/commands/dev.py +318 -0
- mpdt/commands/generate.py +448 -0
- mpdt/commands/init.py +686 -0
- mpdt/dev/bridge_plugin/__init__.py +17 -0
- mpdt/dev/bridge_plugin/cleanup_handler.py +65 -0
- mpdt/dev/bridge_plugin/dev_config.py +24 -0
- mpdt/dev/bridge_plugin/file_watcher.py +169 -0
- mpdt/dev/bridge_plugin/plugin.py +219 -0
- mpdt/templates/__init__.py +165 -0
- mpdt/templates/action_template.py +102 -0
- mpdt/templates/adapter_template.py +129 -0
- mpdt/templates/chatter_template.py +103 -0
- mpdt/templates/event_template.py +116 -0
- mpdt/templates/plus_command_template.py +150 -0
- mpdt/templates/prompt_template.py +92 -0
- mpdt/templates/router_template.py +175 -0
- mpdt/templates/tool_template.py +98 -0
- mpdt/utils/__init__.py +10 -0
- mpdt/utils/code_parser.py +401 -0
- mpdt/utils/color_printer.py +99 -0
- mpdt/utils/config_loader.py +171 -0
- mpdt/utils/config_manager.py +297 -0
- mpdt/utils/file_ops.py +207 -0
- mpdt/utils/license_generator.py +980 -0
- mpdt/utils/plugin_parser.py +195 -0
- mpdt/utils/template_engine.py +112 -0
- mpdt/validators/__init__.py +26 -0
- mpdt/validators/auto_fix_validator.py +990 -0
- mpdt/validators/base.py +129 -0
- mpdt/validators/component_validator.py +842 -0
- mpdt/validators/config_validator.py +119 -0
- mpdt/validators/metadata_validator.py +107 -0
- mpdt/validators/structure_validator.py +72 -0
- mpdt/validators/style_validator.py +117 -0
- mpdt/validators/type_validator.py +206 -0
|
@@ -0,0 +1,730 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mofox-plugin-dev-toolkit
|
|
3
|
+
Version: 0.3.3
|
|
4
|
+
Summary: 开发工具集,用于快速创建、开发和测试 MoFox-Bot 插件
|
|
5
|
+
Author-email: MoFox-Studio <wwwww95915@qq.com>
|
|
6
|
+
License: GPL-3.0-or-later
|
|
7
|
+
Project-URL: Homepage, https://github.com/MoFox-Studio/mofox-plugin-toolkit
|
|
8
|
+
Project-URL: Documentation, https://docs.mofox.studio/mpdt
|
|
9
|
+
Project-URL: Repository, https://github.com/MoFox-Studio/mofox-plugin-toolkit
|
|
10
|
+
Project-URL: Bug Tracker, https://github.com/MoFox-Studio/mofox-plugin-toolkit/issues
|
|
11
|
+
Keywords: mofox,plugin,toolkit,cli,development
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Requires-Python: >=3.11
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: click>=8.1.7
|
|
22
|
+
Requires-Dist: rich>=13.7.0
|
|
23
|
+
Requires-Dist: questionary>=2.0.1
|
|
24
|
+
Requires-Dist: jinja2>=3.1.2
|
|
25
|
+
Requires-Dist: toml>=0.10.2
|
|
26
|
+
Requires-Dist: tomli>=2.0.1
|
|
27
|
+
Requires-Dist: tomli-w>=1.0.0
|
|
28
|
+
Requires-Dist: pydantic>=2.5.0
|
|
29
|
+
Requires-Dist: watchdog>=3.0.0
|
|
30
|
+
Requires-Dist: websockets>=12.0
|
|
31
|
+
Requires-Dist: libcst>=1.8.6
|
|
32
|
+
Requires-Dist: aiohttp>=3.9.0
|
|
33
|
+
Requires-Dist: uvicorn>=0.24.0
|
|
34
|
+
Requires-Dist: fastapi>=0.104.0
|
|
35
|
+
Requires-Dist: ruff>=0.1.6
|
|
36
|
+
Requires-Dist: mypy>=1.7.0
|
|
37
|
+
Provides-Extra: dev
|
|
38
|
+
Requires-Dist: pytest>=7.4.3; extra == "dev"
|
|
39
|
+
Requires-Dist: pytest-cov>=4.1.0; extra == "dev"
|
|
40
|
+
Requires-Dist: pytest-asyncio>=0.21.1; extra == "dev"
|
|
41
|
+
Requires-Dist: pytest-mock>=3.12.0; extra == "dev"
|
|
42
|
+
Requires-Dist: mypy>=1.7.0; extra == "dev"
|
|
43
|
+
Requires-Dist: ruff>=0.1.6; extra == "dev"
|
|
44
|
+
Provides-Extra: check
|
|
45
|
+
Requires-Dist: mypy>=1.7.0; extra == "check"
|
|
46
|
+
Requires-Dist: ruff>=0.1.6; extra == "check"
|
|
47
|
+
Requires-Dist: bandit>=1.7.5; extra == "check"
|
|
48
|
+
Provides-Extra: docs
|
|
49
|
+
Requires-Dist: mkdocs>=1.5.3; extra == "docs"
|
|
50
|
+
Requires-Dist: mkdocs-material>=9.4.0; extra == "docs"
|
|
51
|
+
Dynamic: license-file
|
|
52
|
+
|
|
53
|
+
# MoFox Plugin Dev Toolkit (MPDT)
|
|
54
|
+
|
|
55
|
+
[](https://www.python.org/downloads/)
|
|
56
|
+
[](LICENSE)
|
|
57
|
+
[](https://github.com/MoFox-Studio/mofox-plugin-toolkit)
|
|
58
|
+
|
|
59
|
+
一个类似于 Vite 的 Python 开发工具,专门为 MoFox-Bot 插件系统设计,提供快速创建、开发、检查和热重载的完整工具链。
|
|
60
|
+
|
|
61
|
+
## ✨ 特性
|
|
62
|
+
|
|
63
|
+
### 核心功能
|
|
64
|
+
|
|
65
|
+
- 🚀 **快速初始化** - 一键创建标准化的插件项目结构,支持 6 种模板(basic、action、tool、plus_command、full、adapter)
|
|
66
|
+
- 🎨 **代码生成** - 快速生成 8 种组件类型(Action、Tool、Event、Adapter、Prompt、PlusCommand、Router、Chatter),始终生成异步方法
|
|
67
|
+
- 🔍 **完整的静态检查系统** - 集成 7 层验证体系:
|
|
68
|
+
- ✅ **结构检查** - 验证插件目录结构、必需文件和推荐文件
|
|
69
|
+
- ✅ **元数据检查** - 检查 `__plugin_meta__` 配置的完整性和正确性
|
|
70
|
+
- ✅ **组件检查** - 验证组件注册、命名规范和导入路径
|
|
71
|
+
- ✅ **配置检查** - 检查 `config.toml` 的语法和必需配置
|
|
72
|
+
- ✅ **类型检查** - 使用 mypy 进行严格的类型检查
|
|
73
|
+
- ✅ **代码风格检查** - 使用 ruff 检查代码规范并自动修复
|
|
74
|
+
- ✅ **自动修复** - 智能修复可自动处理的问题
|
|
75
|
+
- 🔥 **热重载开发模式** - 基于 DevBridge 插件的实时热重载系统:
|
|
76
|
+
- 🔄 文件变化自动检测和重载
|
|
77
|
+
- 📦 自动注入开发桥接插件
|
|
78
|
+
- 🚦 自动管理插件生命周期
|
|
79
|
+
- 📊 实时显示重载状态和日志
|
|
80
|
+
- 🎯 **Git 集成** - 支持自动初始化 Git 仓库和提取用户信息
|
|
81
|
+
- 🎨 **美观的交互界面** - 基于 Rich 和 Questionary 的现代化命令行体验
|
|
82
|
+
- 📜 **多种许可证** - 支持 GPL-v3.0、MIT、Apache-2.0、BSD-3-Clause
|
|
83
|
+
- 🛠️ **配置管理** - 完整的配置管理命令,支持交互式配置和验证
|
|
84
|
+
|
|
85
|
+
## 📦 安装
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
# 从源码安装
|
|
89
|
+
cd mofox-plugin-toolkit
|
|
90
|
+
pip install -e .
|
|
91
|
+
|
|
92
|
+
# 安装开发依赖
|
|
93
|
+
pip install -e ".[dev]"
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## 🚀 快速开始
|
|
97
|
+
|
|
98
|
+
### 1. 创建新插件
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
# 交互式创建
|
|
102
|
+
mpdt init
|
|
103
|
+
|
|
104
|
+
# 或直接指定插件名和模板
|
|
105
|
+
mpdt init my_awesome_plugin --template action
|
|
106
|
+
|
|
107
|
+
# 创建带示例和文档的完整插件
|
|
108
|
+
mpdt init my_plugin --template full --with-examples --with-docs
|
|
109
|
+
|
|
110
|
+
# 指定作者和许可证
|
|
111
|
+
mpdt init my_plugin --author "Your Name" --license MIT
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
支持的模板类型:
|
|
115
|
+
- `basic` - 基础插件模板(最小化结构)
|
|
116
|
+
- `action` - 包含 Action 组件的模板
|
|
117
|
+
- `tool` - 包含 Tool 组件的模板
|
|
118
|
+
- `plus_command` - 包含 PlusCommand 组件的模板
|
|
119
|
+
- `full` - 完整功能模板(包含多种组件示例)
|
|
120
|
+
- `adapter` - 适配器模板(用于创建平台适配器)
|
|
121
|
+
|
|
122
|
+
### 2. 生成组件
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
cd my_awesome_plugin
|
|
126
|
+
|
|
127
|
+
# 交互式生成(推荐)- 通过问答选择组件类型和配置
|
|
128
|
+
mpdt generate
|
|
129
|
+
|
|
130
|
+
# 生成 Action 组件
|
|
131
|
+
mpdt generate action SendMessage --description "发送消息"
|
|
132
|
+
|
|
133
|
+
# 生成 Tool 组件
|
|
134
|
+
mpdt generate tool MessageFormatter --description "消息格式化工具"
|
|
135
|
+
|
|
136
|
+
# 生成 PlusCommand 组件(用于 Plus 系统)
|
|
137
|
+
mpdt generate plus-command CustomCommand --description "自定义 Plus 命令"
|
|
138
|
+
|
|
139
|
+
# 生成其他组件
|
|
140
|
+
mpdt generate event MessageReceived --description "消息接收事件处理器"
|
|
141
|
+
mpdt generate adapter CustomAdapter --description "自定义适配器"
|
|
142
|
+
mpdt generate prompt SystemPrompt --description "系统提示词"
|
|
143
|
+
mpdt generate router MessageRouter --description "消息路由器"
|
|
144
|
+
mpdt generate chatter ChatHandler --description "对话处理器"
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
**支持的组件类型**:
|
|
148
|
+
- `action` - Action 组件(用于执行具体操作)
|
|
149
|
+
- `tool` - Tool 组件(可供 AI 调用的工具)
|
|
150
|
+
- `event` - Event Handler 组件(事件处理器)
|
|
151
|
+
- `adapter` - Adapter 组件(平台适配器)
|
|
152
|
+
- `prompt` - Prompt 组件(提示词模板)
|
|
153
|
+
- `plus-command` - PlusCommand 组件(Plus 系统命令)
|
|
154
|
+
- `router` - Router 组件(路由器)
|
|
155
|
+
- `chatter` - Chatter 组件(对话处理器)
|
|
156
|
+
|
|
157
|
+
**注意**:所有生成的组件方法都是异步的(async),符合 MoFox-Bot 的异步架构。
|
|
158
|
+
|
|
159
|
+
### 3. 开发模式(热重载)
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
# 启动开发模式(需要先配置 MoFox-Bot 主程序路径)
|
|
163
|
+
mpdt dev
|
|
164
|
+
|
|
165
|
+
# 指定主程序路径
|
|
166
|
+
mpdt dev --mmc-path /path/to/mofox
|
|
167
|
+
|
|
168
|
+
# 指定插件路径
|
|
169
|
+
mpdt dev --plugin-path /path/to/plugin
|
|
170
|
+
|
|
171
|
+
# 首次运行会提示配置
|
|
172
|
+
# 之后会自动:
|
|
173
|
+
# 1. 注入目标插件到主程序 plugins 目录
|
|
174
|
+
# 2. 注入 DevBridge 插件(包含文件监控和热重载逻辑)
|
|
175
|
+
# 3. 启动主程序
|
|
176
|
+
# 4. DevBridge 插件自动监控文件变化并热重载
|
|
177
|
+
|
|
178
|
+
# 开发模式功能:
|
|
179
|
+
# - 🔄 文件保存后自动重载插件
|
|
180
|
+
# - 📊 实时显示重载状态和耗时
|
|
181
|
+
# - 🚦 自动管理插件生命周期
|
|
182
|
+
# - 📝 实时查看主程序日志
|
|
183
|
+
# - ⚡ 无需手动重启主程序
|
|
184
|
+
# - 🧹 主程序退出时自动清理 DevBridge 插件
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### 4. 检查插件
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
# 运行所有检查(包含 7 个检查器)
|
|
191
|
+
mpdt check
|
|
192
|
+
|
|
193
|
+
# 自动修复可修复的问题
|
|
194
|
+
mpdt check --fix
|
|
195
|
+
|
|
196
|
+
# 只显示错误级别的问题
|
|
197
|
+
mpdt check --level error
|
|
198
|
+
|
|
199
|
+
# 生成 Markdown 或 JSON 格式的检查报告
|
|
200
|
+
mpdt check --report markdown --output check_report.md
|
|
201
|
+
mpdt check --report json --output check_report.json
|
|
202
|
+
|
|
203
|
+
# 跳过特定检查
|
|
204
|
+
mpdt check --no-type # 跳过类型检查
|
|
205
|
+
mpdt check --no-style # 跳过代码风格检查
|
|
206
|
+
mpdt check --no-component # 跳过组件检查
|
|
207
|
+
mpdt check --no-structure # 跳过结构检查
|
|
208
|
+
mpdt check --no-metadata # 跳过元数据检查
|
|
209
|
+
|
|
210
|
+
# 组合使用
|
|
211
|
+
mpdt check --fix --level warning --report markdown -o report.md
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### 5. 配置管理
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
# 交互式配置向导
|
|
218
|
+
mpdt config init
|
|
219
|
+
|
|
220
|
+
# 显示当前配置
|
|
221
|
+
mpdt config show
|
|
222
|
+
|
|
223
|
+
# 测试配置是否有效
|
|
224
|
+
mpdt config test
|
|
225
|
+
|
|
226
|
+
# 设置 MoFox 主程序路径
|
|
227
|
+
mpdt config set-mofox /path/to/mofox
|
|
228
|
+
|
|
229
|
+
# 设置虚拟环境
|
|
230
|
+
mpdt config set-venv /path/to/venv --type venv
|
|
231
|
+
mpdt config set-venv --type none # 使用系统 Python
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
**检查项说明**:
|
|
235
|
+
- **结构检查** (structure) - 验证目录结构、必需文件(`__init__.py`、`plugin.py`、`config/config.toml`)和推荐文件(`README.md`、`pyproject.toml`、`tests/`)
|
|
236
|
+
- **元数据检查** (metadata) - 检查 `__plugin_meta__` 的存在性、类型和必需字段(name、description、usage)
|
|
237
|
+
- **组件检查** (component) - 验证组件注册、命名规范、导入路径和类型正确性
|
|
238
|
+
- **配置检查** (config) - 检查 `config.toml` 的语法、必需配置项和数据类型
|
|
239
|
+
- **类型检查** (type) - 使用 mypy 进行严格的类型检查,确保类型安全
|
|
240
|
+
- **代码风格检查** (style) - 使用 ruff 检查代码规范,支持自动修复格式问题
|
|
241
|
+
- **自动修复** (autofix) - 智能分析并自动修复可处理的问题
|
|
242
|
+
|
|
243
|
+
## 📖 命令参考
|
|
244
|
+
|
|
245
|
+
### `mpdt` - 主命令
|
|
246
|
+
|
|
247
|
+
```bash
|
|
248
|
+
mpdt [OPTIONS] COMMAND [ARGS]...
|
|
249
|
+
|
|
250
|
+
选项:
|
|
251
|
+
-v, --verbose 详细输出模式
|
|
252
|
+
--no-color 禁用彩色输出
|
|
253
|
+
--version 显示版本信息
|
|
254
|
+
--help 显示帮助信息
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
### `mpdt init` - 初始化插件
|
|
258
|
+
|
|
259
|
+
创建新的插件项目,支持多种模板和自动化配置。
|
|
260
|
+
|
|
261
|
+
```bash
|
|
262
|
+
mpdt init [PLUGIN_NAME] [OPTIONS]
|
|
263
|
+
|
|
264
|
+
选项:
|
|
265
|
+
-t, --template TEXT 模板类型: basic, action, tool, plus_command, full, adapter
|
|
266
|
+
-a, --author TEXT 作者名称(可从 Git 配置自动获取)
|
|
267
|
+
-l, --license TEXT 开源协议: GPL-v3.0, MIT, Apache-2.0, BSD-3-Clause
|
|
268
|
+
--with-examples 包含示例代码和用法说明
|
|
269
|
+
--with-docs 创建文档目录和基础文档文件
|
|
270
|
+
--init-git 初始化 Git 仓库(默认)
|
|
271
|
+
--no-init-git 不初始化 Git 仓库
|
|
272
|
+
-o, --output PATH 输出目录(默认为当前目录)
|
|
273
|
+
|
|
274
|
+
示例:
|
|
275
|
+
mpdt init my_plugin # 交互式创建
|
|
276
|
+
mpdt init my_plugin -t action -a "张三" # 指定参数创建
|
|
277
|
+
mpdt init my_plugin -t full --with-examples # 创建完整模板
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
### `mpdt generate` - 生成组件
|
|
281
|
+
|
|
282
|
+
生成插件组件代码,始终生成异步方法,支持交互式和命令行两种模式。
|
|
283
|
+
|
|
284
|
+
```bash
|
|
285
|
+
mpdt generate [COMPONENT_TYPE] [COMPONENT_NAME] [OPTIONS]
|
|
286
|
+
|
|
287
|
+
组件类型:
|
|
288
|
+
action Action 组件 - 执行具体操作
|
|
289
|
+
tool Tool 组件 - 可供 AI 调用的工具
|
|
290
|
+
event Event Handler 组件 - 事件处理器
|
|
291
|
+
adapter Adapter 组件 - 平台适配器
|
|
292
|
+
prompt Prompt 组件 - 提示词模板
|
|
293
|
+
plus-command PlusCommand 组件 - Plus 系统命令
|
|
294
|
+
router Router 组件 - 路由器
|
|
295
|
+
chatter Chatter 组件 - 对话处理器
|
|
296
|
+
|
|
297
|
+
选项:
|
|
298
|
+
-d, --description TEXT 组件描述信息
|
|
299
|
+
-o, --output PATH 输出目录(默认自动选择对应组件目录)
|
|
300
|
+
-f, --force 覆盖已存在的文件
|
|
301
|
+
|
|
302
|
+
示例:
|
|
303
|
+
mpdt generate # 交互式生成
|
|
304
|
+
mpdt generate action SendMsg -d "发送消息" # 命令行生成
|
|
305
|
+
mpdt generate tool Formatter --force # 强制覆盖
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
**注意**:不提供参数时将进入交互式问答模式,更易于使用。
|
|
309
|
+
|
|
310
|
+
### `mpdt dev` - 开发模式
|
|
311
|
+
|
|
312
|
+
启动带热重载的开发模式,实时监控文件变化并自动重载插件。
|
|
313
|
+
|
|
314
|
+
```bash
|
|
315
|
+
mpdt dev [OPTIONS]
|
|
316
|
+
|
|
317
|
+
选项:
|
|
318
|
+
--mmc-path PATH MoFox 主程序路径
|
|
319
|
+
--plugin-path PATH 插件路径(默认当前目录)
|
|
320
|
+
|
|
321
|
+
功能特性:
|
|
322
|
+
- 🔄 自动检测文件变化并热重载
|
|
323
|
+
- 📦 自动注入 DevBridge 开发桥接插件
|
|
324
|
+
- 🚦 自动管理插件生命周期
|
|
325
|
+
- 📊 实时显示重载状态和耗时
|
|
326
|
+
- 📝 显示主程序运行日志
|
|
327
|
+
- 🧹 主程序退出时自动清理
|
|
328
|
+
|
|
329
|
+
首次运行:
|
|
330
|
+
首次运行会提示配置 MoFox 主程序路径
|
|
331
|
+
配置将保存到 ~/.mpdt/config.toml
|
|
332
|
+
|
|
333
|
+
工作流程:
|
|
334
|
+
1. 自动将目标插件复制到主程序 plugins 目录
|
|
335
|
+
2. 注入 DevBridge 插件(包含文件监控逻辑)
|
|
336
|
+
3. 启动主程序
|
|
337
|
+
4. DevBridge 插件监控文件变化
|
|
338
|
+
5. 检测到变化时自动卸载旧版本并加载新版本
|
|
339
|
+
|
|
340
|
+
示例:
|
|
341
|
+
mpdt dev # 在插件目录中运行
|
|
342
|
+
mpdt dev --mmc-path /path/to/mofox # 指定主程序路径
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
### `mpdt check` - 检查插件
|
|
346
|
+
|
|
347
|
+
对插件进行全面的静态检查,包括 6 个检查器。
|
|
348
|
+
|
|
349
|
+
```bash
|
|
350
|
+
mpdt check [PATH] [OPTIONS]
|
|
351
|
+
|
|
352
|
+
选项:
|
|
353
|
+
-l, --level TEXT 显示问题级别: error, warning, info(默认显示所有)
|
|
354
|
+
--fix 自动修复可修复的问题(主要是代码风格)
|
|
355
|
+
--report TEXT 报告格式: console(默认), markdown
|
|
356
|
+
-o, --output PATH 报告输出路径(仅用于 markdown 格式)
|
|
357
|
+
--no-structure 跳过结构检查
|
|
358
|
+
--no-metadata 跳过元数据检查
|
|
359
|
+
--no-component 跳过组件检查
|
|
360
|
+
--no-config 跳过配置检查
|
|
361
|
+
--no-type 跳过类型检查
|
|
362
|
+
--no-style 跳过代码风格检查
|
|
363
|
+
|
|
364
|
+
检查器说明:
|
|
365
|
+
structure - 检查目录结构、必需文件和推荐文件
|
|
366
|
+
metadata - 检查 __plugin_meta__ 的完整性
|
|
367
|
+
component - 检查组件注册和命名规范
|
|
368
|
+
config - 检查 config.toml 配置文件
|
|
369
|
+
type - 使用 mypy 进行类型检查
|
|
370
|
+
style - 使用 ruff 进行代码风格检查
|
|
371
|
+
autofix - 自动修复可处理的问题
|
|
372
|
+
|
|
373
|
+
示例:
|
|
374
|
+
mpdt check # 运行所有检查
|
|
375
|
+
mpdt check --fix # 自动修复问题
|
|
376
|
+
mpdt check --level error # 只显示错误
|
|
377
|
+
mpdt check --report markdown -o report.md # 生成 Markdown 报告
|
|
378
|
+
mpdt check --report json -o report.json # 生成 JSON 报告
|
|
379
|
+
mpdt check --no-type --no-style # 跳过耗时检查
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
### `mpdt config` - 配置管理
|
|
383
|
+
|
|
384
|
+
管理 MPDT 的配置信息。
|
|
385
|
+
|
|
386
|
+
```bash
|
|
387
|
+
# 子命令
|
|
388
|
+
mpdt config init # 交互式配置向导
|
|
389
|
+
mpdt config show # 显示当前配置
|
|
390
|
+
mpdt config test # 测试配置是否有效
|
|
391
|
+
mpdt config set-mofox # 设置 MoFox 主程序路径
|
|
392
|
+
mpdt config set-venv # 设置虚拟环境
|
|
393
|
+
|
|
394
|
+
# 设置 MoFox 路径
|
|
395
|
+
mpdt config set-mofox /path/to/mofox
|
|
396
|
+
|
|
397
|
+
# 设置虚拟环境
|
|
398
|
+
mpdt config set-venv /path/to/venv --type venv
|
|
399
|
+
mpdt config set-venv /path/to/venv --type uv
|
|
400
|
+
mpdt config set-venv /path/to/venv --type conda
|
|
401
|
+
mpdt config set-venv /path/to/venv --type poetry
|
|
402
|
+
mpdt config set-venv --type none # 使用系统 Python
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
配置项说明:
|
|
406
|
+
- **MoFox 路径** - MoFox-Bot 主程序的安装路径
|
|
407
|
+
- **虚拟环境类型** - venv、uv、conda、poetry 或 none
|
|
408
|
+
- **虚拟环境路径** - 虚拟环境目录路径
|
|
409
|
+
- **自动重载** - 是否启用自动重载功能
|
|
410
|
+
- **重载延迟** - 文件变化后的重载延迟时间
|
|
411
|
+
|
|
412
|
+
---
|
|
413
|
+
|
|
414
|
+
## 🏗️ 插件结构
|
|
415
|
+
|
|
416
|
+
MPDT 创建的插件遵循 MoFox-Bot 标准结构:
|
|
417
|
+
|
|
418
|
+
```
|
|
419
|
+
my_plugin/ # 插件根目录
|
|
420
|
+
├── __init__.py # ⭐ 插件元数据(必需)
|
|
421
|
+
│ # 必须包含 __plugin_meta__ 变量
|
|
422
|
+
├── plugin.py # ⭐ 插件主类(必需)
|
|
423
|
+
│ # 继承自 BasePlugin
|
|
424
|
+
├── config/ # ⭐ 配置目录(必需)
|
|
425
|
+
│ └── config.toml # ⭐ 配置文件(必需)
|
|
426
|
+
├── components/ # 组件目录(可选但推荐)
|
|
427
|
+
│ ├── actions/ # Action 组件目录
|
|
428
|
+
│ │ └── send_message.py
|
|
429
|
+
│ ├── tools/ # Tool 组件目录
|
|
430
|
+
│ │ └── formatter.py
|
|
431
|
+
│ ├── events/ # Event Handler 目录
|
|
432
|
+
│ ├── adapters/ # Adapter 目录
|
|
433
|
+
│ ├── prompts/ # Prompt 目录
|
|
434
|
+
│ ├── plus_commands/ # PlusCommand 目录
|
|
435
|
+
│ ├── routers/ # Router 目录
|
|
436
|
+
│ └── chatters/ # Chatter 目录
|
|
437
|
+
├── utils/ # 工具函数目录(可选)
|
|
438
|
+
│ └── helpers.py
|
|
439
|
+
├── tests/ # 📋 测试目录(推荐)
|
|
440
|
+
│ ├── conftest.py
|
|
441
|
+
│ └── test_plugin.py
|
|
442
|
+
├── docs/ # 📋 文档目录(推荐)
|
|
443
|
+
│ └── README.md
|
|
444
|
+
├── pyproject.toml # 📋 项目配置(推荐)
|
|
445
|
+
├── requirements.txt # 📋 依赖列表(推荐)
|
|
446
|
+
├── .gitignore # Git 忽略文件
|
|
447
|
+
├── LICENSE # 开源许可证
|
|
448
|
+
└── README.md # 📋 插件说明(推荐)
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
## 🎯 开发状态
|
|
453
|
+
|
|
454
|
+
### ✅ 已完成功能(v0.3.3)
|
|
455
|
+
|
|
456
|
+
#### 1. ✅ 插件初始化 (`mpdt init`)
|
|
457
|
+
- 支持 6 种模板类型(basic、action、tool、plus_command、full、adapter)
|
|
458
|
+
- 交互式问答模式
|
|
459
|
+
- Git 自动初始化和用户信息提取
|
|
460
|
+
- 多种开源协议支持(GPL-v3.0、MIT、Apache-2.0、BSD-3-Clause)
|
|
461
|
+
- 自动生成标准化项目结构
|
|
462
|
+
|
|
463
|
+
#### 2. ✅ 组件生成 (`mpdt generate`)
|
|
464
|
+
- 支持 8 种组件类型(action、tool、event、adapter、prompt、plus-command、router、chatter)
|
|
465
|
+
- 所有方法自动生成为异步
|
|
466
|
+
- 基于 libcst 的智能代码解析和注入
|
|
467
|
+
- 自动更新插件主类注册代码
|
|
468
|
+
- 交互式和命令行两种模式
|
|
469
|
+
- 组件文件自动放置到正确目录
|
|
470
|
+
|
|
471
|
+
#### 3. ✅ 静态检查系统 (`mpdt check`)
|
|
472
|
+
- **结构验证器** - 目录和文件完整性检查
|
|
473
|
+
- **元数据验证器** - `__plugin_meta__` 验证
|
|
474
|
+
- **组件验证器** - 组件注册和规范检查
|
|
475
|
+
- **配置验证器** - `config.toml` 验证
|
|
476
|
+
- **类型检查器** - mypy 集成,严格类型检查
|
|
477
|
+
- **代码风格检查器** - ruff 集成,自动修复
|
|
478
|
+
- **自动修复验证器** - 智能问题修复
|
|
479
|
+
- 支持生成 Markdown 和 JSON 格式报告
|
|
480
|
+
- 灵活的级别过滤(error/warning/info)
|
|
481
|
+
|
|
482
|
+
#### 4. ✅ 热重载开发模式 (`mpdt dev`)
|
|
483
|
+
- 基于 DevBridge 插件的热重载机制
|
|
484
|
+
- 自动注入目标插件和开发桥接插件
|
|
485
|
+
- 文件变化自动检测(使用 watchdog)
|
|
486
|
+
- 插件生命周期自动管理
|
|
487
|
+
- 实时状态显示和日志查看
|
|
488
|
+
- 主程序退出时自动清理
|
|
489
|
+
|
|
490
|
+
#### 5. ✅ 配置管理 (`mpdt config`)
|
|
491
|
+
- 交互式配置向导 (`mpdt config init`)
|
|
492
|
+
- 配置显示 (`mpdt config show`)
|
|
493
|
+
- 配置验证 (`mpdt config test`)
|
|
494
|
+
- MoFox 路径设置 (`mpdt config set-mofox`)
|
|
495
|
+
- 虚拟环境设置 (`mpdt config set-venv`)
|
|
496
|
+
- 支持多种虚拟环境类型(venv、uv、conda、poetry)
|
|
497
|
+
|
|
498
|
+
### 🚧 计划中功能
|
|
499
|
+
|
|
500
|
+
#### 测试框架 (`mpdt test`)
|
|
501
|
+
- 自动运行插件测试
|
|
502
|
+
- 覆盖率报告生成
|
|
503
|
+
- 并行测试执行
|
|
504
|
+
- 测试报告输出
|
|
505
|
+
|
|
506
|
+
#### 构建打包 (`mpdt build`)
|
|
507
|
+
- 插件打包为发布格式(zip、tar.gz、wheel)
|
|
508
|
+
- 版本号自动管理(major、minor、patch)
|
|
509
|
+
- 依赖项打包
|
|
510
|
+
- 文档包含选项
|
|
511
|
+
|
|
512
|
+
#### 插件市场集成
|
|
513
|
+
- 插件上传和发布
|
|
514
|
+
- 版本管理
|
|
515
|
+
- 依赖解析
|
|
516
|
+
|
|
517
|
+
---
|
|
518
|
+
|
|
519
|
+
## 🤝 贡献指南
|
|
520
|
+
|
|
521
|
+
欢迎贡献代码和建议!
|
|
522
|
+
|
|
523
|
+
### 贡献方式
|
|
524
|
+
1. Fork 项目仓库
|
|
525
|
+
2. 创建特性分支 (`git checkout -b feature/AmazingFeature`)
|
|
526
|
+
3. 提交更改 (`git commit -m 'Add some AmazingFeature'`)
|
|
527
|
+
4. 推送到分支 (`git push origin feature/AmazingFeature`)
|
|
528
|
+
5. 创建 Pull Request
|
|
529
|
+
|
|
530
|
+
### 开发环境设置
|
|
531
|
+
```bash
|
|
532
|
+
# 克隆仓库
|
|
533
|
+
git clone https://github.com/MoFox-Studio/mofox-plugin-toolkit.git
|
|
534
|
+
cd mofox-plugin-toolkit
|
|
535
|
+
|
|
536
|
+
# 安装开发依赖
|
|
537
|
+
pip install -e ".[dev]"
|
|
538
|
+
|
|
539
|
+
# 运行测试
|
|
540
|
+
pytest
|
|
541
|
+
|
|
542
|
+
# 代码检查
|
|
543
|
+
ruff check .
|
|
544
|
+
mypy mpdt
|
|
545
|
+
```
|
|
546
|
+
|
|
547
|
+
---
|
|
548
|
+
|
|
549
|
+
## 📄 许可证
|
|
550
|
+
|
|
551
|
+
本项目采用 GPL-3.0-or-later 许可证。详见 [LICENSE](LICENSE) 文件。
|
|
552
|
+
|
|
553
|
+
---
|
|
554
|
+
|
|
555
|
+
## 🔗 相关链接
|
|
556
|
+
|
|
557
|
+
- [MoFox-Bot 主仓库](https://github.com/MoFox-Studio/MoFox-Core)
|
|
558
|
+
- [插件开发文档](https://docs.mofox.studio/plugin-development)
|
|
559
|
+
- [问题反馈](https://github.com/MoFox-Studio/mofox-plugin-toolkit/issues)
|
|
560
|
+
- [更新日志](CHANGELOG.md)
|
|
561
|
+
|
|
562
|
+
---
|
|
563
|
+
|
|
564
|
+
## 📊 技术栈
|
|
565
|
+
|
|
566
|
+
### 核心框架
|
|
567
|
+
- **CLI 框架**: [Click](https://click.palletsprojects.com/) - 强大的命令行工具框架
|
|
568
|
+
- **交互式界面**: [Questionary](https://github.com/tmbo/questionary) - 美观的交互式问答
|
|
569
|
+
- **美化输出**: [Rich](https://github.com/Textualize/rich) - 富文本终端输出
|
|
570
|
+
|
|
571
|
+
### 开发工具
|
|
572
|
+
- **模板引擎**: [Jinja2](https://jinja.palletsprojects.com/) - 灵活的模板系统
|
|
573
|
+
- **配置管理**: [TOML](https://toml.io/), [Pydantic](https://docs.pydantic.dev/) - 配置解析和验证
|
|
574
|
+
- **代码解析**: [libcst](https://libcst.readthedocs.io/) - Python 具体语法树解析和修改
|
|
575
|
+
- **代码检查**:
|
|
576
|
+
- [Mypy](https://mypy.readthedocs.io/) - 静态类型检查
|
|
577
|
+
- [Ruff](https://docs.astral.sh/ruff/) - 快速的 Python 代码检查器和格式化工具
|
|
578
|
+
|
|
579
|
+
### 开发模式
|
|
580
|
+
- **文件监控**: [Watchdog](https://python-watchdog.readthedocs.io/) - 跨平台文件系统监控
|
|
581
|
+
- **WebSocket**: [websockets](https://websockets.readthedocs.io/) - 异步 WebSocket 库
|
|
582
|
+
- **HTTP 客户端**: [aiohttp](https://docs.aiohttp.org/) - 异步 HTTP 客户端/服务器
|
|
583
|
+
|
|
584
|
+
## 🏗️ 项目结构
|
|
585
|
+
|
|
586
|
+
```
|
|
587
|
+
mofox-plugin-toolkit/
|
|
588
|
+
├── mpdt/ # 主包
|
|
589
|
+
│ ├── __init__.py # 版本信息
|
|
590
|
+
│ ├── __main__.py # 入口点
|
|
591
|
+
│ ├── cli.py # CLI 主入口
|
|
592
|
+
│ ├── commands/ # 命令实现
|
|
593
|
+
│ │ ├── init.py # 插件初始化
|
|
594
|
+
│ │ ├── generate.py # 组件生成
|
|
595
|
+
│ │ ├── check.py # 静态检查
|
|
596
|
+
│ │ └── dev.py # 开发模式
|
|
597
|
+
│ ├── validators/ # 验证器
|
|
598
|
+
│ │ ├── base.py # 基础验证器
|
|
599
|
+
│ │ ├── structure_validator.py # 结构验证
|
|
600
|
+
│ │ ├── metadata_validator.py # 元数据验证
|
|
601
|
+
│ │ ├── component_validator.py # 组件验证
|
|
602
|
+
│ │ ├── config_validator.py # 配置验证
|
|
603
|
+
│ │ ├── type_validator.py # 类型检查
|
|
604
|
+
│ │ ├── style_validator.py # 代码风格
|
|
605
|
+
│ │ └── auto_fix_validator.py # 自动修复
|
|
606
|
+
│ ├── templates/ # 组件模板
|
|
607
|
+
│ │ ├── action_template.py
|
|
608
|
+
│ │ ├── tool_template.py
|
|
609
|
+
│ │ ├── event_template.py
|
|
610
|
+
│ │ ├── adapter_template.py
|
|
611
|
+
│ │ ├── prompt_template.py
|
|
612
|
+
│ │ ├── plus_command_template.py
|
|
613
|
+
│ │ ├── router_template.py
|
|
614
|
+
│ │ └── chatter_template.py
|
|
615
|
+
│ ├── utils/ # 工具函数
|
|
616
|
+
│ │ ├── code_parser.py # 代码解析
|
|
617
|
+
│ │ ├── color_printer.py # 彩色输出
|
|
618
|
+
│ │ ├── config_loader.py # 配置加载
|
|
619
|
+
│ │ ├── config_manager.py # 配置管理
|
|
620
|
+
│ │ ├── file_ops.py # 文件操作
|
|
621
|
+
│ │ ├── license_generator.py # 许可证生成
|
|
622
|
+
│ │ ├── plugin_parser.py # 插件解析
|
|
623
|
+
│ │ └── template_engine.py # 模板引擎
|
|
624
|
+
│ └── dev/ # 开发模式相关
|
|
625
|
+
├── docs/ # 文档
|
|
626
|
+
├── examples/ # 示例
|
|
627
|
+
├── plugin_dev_toolkit_design/ # 设计文档
|
|
628
|
+
├── pyproject.toml # 项目配置
|
|
629
|
+
├── README.md # 说明文档
|
|
630
|
+
└── LICENSE # 许可证
|
|
631
|
+
```
|
|
632
|
+
|
|
633
|
+
---
|
|
634
|
+
|
|
635
|
+
## 🛠️ 完整依赖清单
|
|
636
|
+
|
|
637
|
+
```toml
|
|
638
|
+
dependencies = [
|
|
639
|
+
"click>=8.1.7", # CLI 框架
|
|
640
|
+
"rich>=13.7.0", # 终端美化
|
|
641
|
+
"questionary>=2.0.1", # 交互式问答
|
|
642
|
+
"jinja2>=3.1.2", # 模板引擎
|
|
643
|
+
"toml>=0.10.2", # TOML 解析
|
|
644
|
+
"tomli>=2.0.1", # TOML 读取
|
|
645
|
+
"tomli-w>=1.0.0", # TOML 写入
|
|
646
|
+
"pydantic>=2.5.0", # 数据验证
|
|
647
|
+
"watchdog>=3.0.0", # 文件监控
|
|
648
|
+
"websockets>=12.0", # WebSocket
|
|
649
|
+
"libcst>=1.8.6", # Python CST 解析(代码智能注入)
|
|
650
|
+
"aiohttp>=3.9.0", # 异步 HTTP
|
|
651
|
+
"uvicorn>=0.24.0", # ASGI 服务器
|
|
652
|
+
"fastapi>=0.104.0", # Web 框架
|
|
653
|
+
"ruff>=0.1.6", # 代码检查
|
|
654
|
+
"mypy>=1.7.0" # 类型检查
|
|
655
|
+
]
|
|
656
|
+
```
|
|
657
|
+
|
|
658
|
+
---
|
|
659
|
+
|
|
660
|
+
## 💡 常见问题
|
|
661
|
+
|
|
662
|
+
### Q: 如何配置开发模式?
|
|
663
|
+
A: 首次运行 `mpdt dev` 时会提示输入 MoFox 主程序路径,配置会保存到 `~/.mpdt/config.toml`。也可以使用 `mpdt config init` 进行交互式配置。
|
|
664
|
+
|
|
665
|
+
### Q: 检查器报错怎么办?
|
|
666
|
+
A: 首先尝试使用 `mpdt check --fix` 自动修复。如果仍有问题,查看具体错误信息和建议。
|
|
667
|
+
|
|
668
|
+
### Q: 如何跳过某些检查?
|
|
669
|
+
A: 使用 `--no-<checker>` 选项,例如 `mpdt check --no-type --no-style`。
|
|
670
|
+
|
|
671
|
+
### Q: 生成的组件在哪里?
|
|
672
|
+
A: 组件会自动放置到对应的目录,例如 Action 放在 `components/actions/`。
|
|
673
|
+
|
|
674
|
+
### Q: 如何更新工具?
|
|
675
|
+
A: 如果是从源码安装,执行 `git pull && pip install -e .`。
|
|
676
|
+
|
|
677
|
+
### Q: 支持哪些虚拟环境类型?
|
|
678
|
+
A: 支持 venv、uv、conda、poetry,也可以设置为 none 使用系统 Python。
|
|
679
|
+
|
|
680
|
+
### Q: 开发模式如何工作?
|
|
681
|
+
A: MPDT 会将 DevBridge 插件注入到主程序,该插件负责监控文件变化并自动热重载目标插件。主程序退出时会自动清理 DevBridge。
|
|
682
|
+
|
|
683
|
+
---
|
|
684
|
+
|
|
685
|
+
## 📝 更新日志
|
|
686
|
+
|
|
687
|
+
### v0.3.3 (2026-01-02)
|
|
688
|
+
- ✅ 更新项目文档
|
|
689
|
+
- ✅ 完善配置管理功能
|
|
690
|
+
- ✅ 优化代码结构
|
|
691
|
+
|
|
692
|
+
### v0.3.x
|
|
693
|
+
- ✅ 添加 libcst 代码解析支持
|
|
694
|
+
- ✅ 实现自动修复验证器 (AutoFixValidator)
|
|
695
|
+
- ✅ 支持 JSON 格式报告输出
|
|
696
|
+
- ✅ 改进组件代码注入机制
|
|
697
|
+
|
|
698
|
+
### v0.2.1 (2025-12-14)
|
|
699
|
+
- ✅ 实现完整的热重载开发模式 (`mpdt dev`)
|
|
700
|
+
- ✅ 添加 DevBridge 插件注入机制
|
|
701
|
+
- ✅ 实现开发桥接插件自动注入
|
|
702
|
+
- ✅ 改进文件监控和自动重载
|
|
703
|
+
- ✅ 优化用户交互体验
|
|
704
|
+
|
|
705
|
+
### v0.2.0
|
|
706
|
+
- ✅ 完成 6 个检查器实现
|
|
707
|
+
- ✅ 添加自动修复功能
|
|
708
|
+
- ✅ 支持 Markdown 报告生成
|
|
709
|
+
- ✅ 改进错误提示和建议
|
|
710
|
+
|
|
711
|
+
### v0.1.x
|
|
712
|
+
- ✅ 基础插件初始化功能
|
|
713
|
+
- ✅ 组件生成功能
|
|
714
|
+
- ✅ 交互式问答模式
|
|
715
|
+
|
|
716
|
+
---
|
|
717
|
+
|
|
718
|
+
## 🎉 致谢
|
|
719
|
+
|
|
720
|
+
感谢所有为 MoFox Plugin Dev Toolkit 贡献的开发者!
|
|
721
|
+
|
|
722
|
+
---
|
|
723
|
+
|
|
724
|
+
<div align="center">
|
|
725
|
+
|
|
726
|
+
**[⬆ 回到顶部](#mofox-plugin-dev-toolkit-mpdt)**
|
|
727
|
+
|
|
728
|
+
Made with ❤️ by MoFox-Studio
|
|
729
|
+
|
|
730
|
+
</div>
|