foliko 1.0.83 → 1.0.85
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.
- package/.agent/.shared/ui-ux-pro-max/data/charts.csv +26 -0
- package/.agent/.shared/ui-ux-pro-max/data/colors.csv +97 -0
- package/.agent/.shared/ui-ux-pro-max/data/icons.csv +101 -0
- package/.agent/.shared/ui-ux-pro-max/data/landing.csv +31 -0
- package/.agent/.shared/ui-ux-pro-max/data/products.csv +97 -0
- package/.agent/.shared/ui-ux-pro-max/data/prompts.csv +24 -0
- package/.agent/.shared/ui-ux-pro-max/data/react-performance.csv +45 -0
- package/.agent/.shared/ui-ux-pro-max/data/stacks/flutter.csv +53 -0
- package/.agent/.shared/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -0
- package/.agent/.shared/ui-ux-pro-max/data/stacks/jetpack-compose.csv +53 -0
- package/.agent/.shared/ui-ux-pro-max/data/stacks/nextjs.csv +53 -0
- package/.agent/.shared/ui-ux-pro-max/data/stacks/nuxt-ui.csv +51 -0
- package/.agent/.shared/ui-ux-pro-max/data/stacks/nuxtjs.csv +59 -0
- package/.agent/.shared/ui-ux-pro-max/data/stacks/react-native.csv +52 -0
- package/.agent/.shared/ui-ux-pro-max/data/stacks/react.csv +54 -0
- package/.agent/.shared/ui-ux-pro-max/data/stacks/shadcn.csv +61 -0
- package/.agent/.shared/ui-ux-pro-max/data/stacks/svelte.csv +54 -0
- package/.agent/.shared/ui-ux-pro-max/data/stacks/swiftui.csv +51 -0
- package/.agent/.shared/ui-ux-pro-max/data/stacks/vue.csv +50 -0
- package/.agent/.shared/ui-ux-pro-max/data/styles.csv +59 -0
- package/.agent/.shared/ui-ux-pro-max/data/typography.csv +58 -0
- package/.agent/.shared/ui-ux-pro-max/data/ui-reasoning.csv +101 -0
- package/.agent/.shared/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
- package/.agent/.shared/ui-ux-pro-max/data/web-interface.csv +31 -0
- package/.agent/.shared/ui-ux-pro-max/scripts/__pycache__/core.cpython-313.pyc +0 -0
- package/.agent/.shared/ui-ux-pro-max/scripts/__pycache__/design_system.cpython-313.pyc +0 -0
- package/.agent/.shared/ui-ux-pro-max/scripts/core.py +258 -0
- package/.agent/.shared/ui-ux-pro-max/scripts/design_system.py +1067 -0
- package/.agent/.shared/ui-ux-pro-max/scripts/search.py +106 -0
- package/.agent/ARCHITECTURE.md +288 -0
- package/.agent/agents/ambient-agent.md +57 -0
- package/.agent/agents/debugger.md +55 -0
- package/.agent/agents/email-assistant.md +49 -0
- package/.agent/agents/file-manager.md +42 -0
- package/.agent/agents/python-developer.md +60 -0
- package/.agent/agents/scheduler.md +59 -0
- package/.agent/agents/web-developer.md +45 -0
- package/.agent/data/default.json +355 -6
- package/.agent/data/plugins-state.json +185 -146
- package/.agent/data/puppeteer-sessions/undefined.json +6 -0
- package/.agent/mcp_config.json +0 -1
- package/.agent/mcp_config_updated.json +12 -0
- package/.agent/plugins/puppeteer-plugin/README.md +147 -0
- package/.agent/plugins/puppeteer-plugin/index.js +1418 -0
- package/.agent/plugins/puppeteer-plugin/package.json +9 -0
- package/.agent/plugins.json +5 -14
- package/.agent/rules/GEMINI.md +273 -0
- package/.agent/rules/allow-rule.md +77 -0
- package/.agent/rules/log-rule.md +83 -0
- package/.agent/rules/security-rule.md +93 -0
- package/.agent/scripts/auto_preview.py +148 -0
- package/.agent/scripts/checklist.py +217 -0
- package/.agent/scripts/session_manager.py +120 -0
- package/.agent/scripts/verify_all.py +327 -0
- package/.agent/skills/api-patterns/SKILL.md +81 -0
- package/.agent/skills/api-patterns/api-style.md +42 -0
- package/.agent/skills/api-patterns/auth.md +24 -0
- package/.agent/skills/api-patterns/documentation.md +26 -0
- package/.agent/skills/api-patterns/graphql.md +41 -0
- package/.agent/skills/api-patterns/rate-limiting.md +31 -0
- package/.agent/skills/api-patterns/response.md +37 -0
- package/.agent/skills/api-patterns/rest.md +40 -0
- package/.agent/skills/api-patterns/scripts/api_validator.py +211 -0
- package/.agent/skills/api-patterns/security-testing.md +122 -0
- package/.agent/skills/api-patterns/trpc.md +41 -0
- package/.agent/skills/api-patterns/versioning.md +22 -0
- package/.agent/skills/app-builder/SKILL.md +75 -0
- package/.agent/skills/app-builder/agent-coordination.md +71 -0
- package/.agent/skills/app-builder/feature-building.md +53 -0
- package/.agent/skills/app-builder/project-detection.md +34 -0
- package/.agent/skills/app-builder/scaffolding.md +118 -0
- package/.agent/skills/app-builder/tech-stack.md +40 -0
- package/.agent/skills/app-builder/templates/SKILL.md +39 -0
- package/.agent/skills/app-builder/templates/astro-static/TEMPLATE.md +76 -0
- package/.agent/skills/app-builder/templates/chrome-extension/TEMPLATE.md +92 -0
- package/.agent/skills/app-builder/templates/cli-tool/TEMPLATE.md +88 -0
- package/.agent/skills/app-builder/templates/electron-desktop/TEMPLATE.md +88 -0
- package/.agent/skills/app-builder/templates/express-api/TEMPLATE.md +83 -0
- package/.agent/skills/app-builder/templates/flutter-app/TEMPLATE.md +90 -0
- package/.agent/skills/app-builder/templates/monorepo-turborepo/TEMPLATE.md +90 -0
- package/.agent/skills/app-builder/templates/nextjs-fullstack/TEMPLATE.md +122 -0
- package/.agent/skills/app-builder/templates/nextjs-saas/TEMPLATE.md +122 -0
- package/.agent/skills/app-builder/templates/nextjs-static/TEMPLATE.md +169 -0
- package/.agent/skills/app-builder/templates/nuxt-app/TEMPLATE.md +134 -0
- package/.agent/skills/app-builder/templates/python-fastapi/TEMPLATE.md +83 -0
- package/.agent/skills/app-builder/templates/react-native-app/TEMPLATE.md +119 -0
- package/.agent/skills/architecture/SKILL.md +55 -0
- package/.agent/skills/architecture/context-discovery.md +43 -0
- package/.agent/skills/architecture/examples.md +94 -0
- package/.agent/skills/architecture/pattern-selection.md +68 -0
- package/.agent/skills/architecture/patterns-reference.md +50 -0
- package/.agent/skills/architecture/trade-off-analysis.md +77 -0
- package/.agent/skills/clean-code/SKILL.md +201 -0
- package/.agent/skills/doc.md +177 -0
- package/.agent/skills/frontend-design/SKILL.md +418 -0
- package/.agent/skills/frontend-design/animation-guide.md +331 -0
- package/.agent/skills/frontend-design/color-system.md +311 -0
- package/.agent/skills/frontend-design/decision-trees.md +418 -0
- package/.agent/skills/frontend-design/motion-graphics.md +306 -0
- package/.agent/skills/frontend-design/scripts/accessibility_checker.py +183 -0
- package/.agent/skills/frontend-design/scripts/ux_audit.py +722 -0
- package/.agent/skills/frontend-design/typography-system.md +345 -0
- package/.agent/skills/frontend-design/ux-psychology.md +1116 -0
- package/.agent/skills/frontend-design/visual-effects.md +383 -0
- package/.agent/skills/i18n-localization/SKILL.md +154 -0
- package/.agent/skills/i18n-localization/scripts/i18n_checker.py +241 -0
- package/.agent/skills/mcp-builder/SKILL.md +176 -0
- package/.agent/skills/web-design-guidelines/SKILL.md +57 -0
- package/.agent/workflows/brainstorm.md +113 -0
- package/.agent/workflows/create.md +59 -0
- package/.agent/workflows/debug.md +103 -0
- package/.agent/workflows/deploy.md +176 -0
- package/.agent/workflows/enhance.md +63 -0
- package/.agent/workflows/orchestrate.md +237 -0
- package/.agent/workflows/plan.md +89 -0
- package/.agent/workflows/preview.md +81 -0
- package/.agent/workflows/simple-test.md +42 -0
- package/.agent/workflows/status.md +86 -0
- package/.agent/workflows/structured-orchestrate.md +180 -0
- package/.agent/workflows/test.md +144 -0
- package/.agent/workflows/ui-ux-pro-max.md +296 -0
- package/.claude/settings.local.json +178 -171
- package/.env.example +56 -56
- package/cli/src/commands/plugin.js +482 -0
- package/cli/src/index.js +7 -0
- package/cli/src/utils/plugin-config.js +50 -0
- package/package.json +1 -1
- package/plugins/audit-plugin.js +2 -0
- package/plugins/extension-executor-plugin.js +38 -0
- package/plugins/plugin-manager-plugin.js +402 -0
- package/plugins/session-plugin.js +3 -3
- package/skills/find-skills/AGENTS.md +162 -162
- package/skills/find-skills/SKILL.md +133 -133
- package/skills/foliko-dev/SKILL.md +563 -563
- package/skills/plugin-guide/SKILL.md +139 -0
- package/skills/python-plugin-dev/SKILL.md +238 -238
- package/src/core/agent-chat.js +103 -45
- package/src/core/framework.js +42 -1
- package/src/executors/mcp-executor.js +33 -0
- package/src/utils/index.js +153 -0
- package/xhs_auth.json +268 -0
- package/.agent/agents/code-assistant.json +0 -14
- package/.agent/agents/email-assistant.json +0 -14
- package/.agent/agents/file-assistant.json +0 -15
- package/.agent/agents/system-assistant.json +0 -15
- package/.agent/agents/web-assistant.json +0 -12
- package/.agent/data/ambient/goals.json +0 -50
- package/.agent/data/ambient/memories.json +0 -7
- package/.agent/data/scheduler/tasks.json +0 -1
- package/.agent/package.json +0 -8
- package/.agent/plugins/__pycache__/test_plugin.cpython-312.pyc +0 -0
- package/.agent/plugins/system-info/index.js +0 -387
- package/.agent/plugins/system-info/package.json +0 -4
- package/.agent/plugins/system-info/test.js +0 -40
- package/.agent/plugins/test_plugin.py +0 -304
- package/.agent/python-scripts/test_sample.py +0 -24
- package/.agent/skills/sysinfo/SKILL.md +0 -38
- package/.agent/skills/sysinfo/system-info.sh +0 -130
- package/.agent/skills/workflow/SKILL.md +0 -324
- package/.agent/workflows/email-digest.json +0 -50
- package/.agent/workflows/file-backup.json +0 -21
- package/.agent/workflows/get-ip-notify.json +0 -32
- package/.agent/workflows/news-aggregator.json +0 -93
- package/.agent/workflows/news-dashboard-v2.json +0 -94
- package/.agent/workflows/notification-batch.json +0 -32
- package/reports/system-health-report-20260401.md +0 -79
- package/test/tool-registry-validation.test.js +0 -218
- package/test_report.md +0 -70
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: plugin-guide
|
|
3
|
+
description: Foliko 插件管理指南。用于列出远程插件、安装插件、发布插件到远程仓库。当用户说"查看插件列表"、"安装插件"、"发布插件"时使用。
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Foliko 插件管理指南
|
|
7
|
+
|
|
8
|
+
## 概念区分
|
|
9
|
+
|
|
10
|
+
| 类型 | 存储位置 | 安装命令 | 说明 |
|
|
11
|
+
| ------------------ | ----------------- | ----------------------------------- | ------------------------- |
|
|
12
|
+
| **Skill(技能)** | `.agent/skills/` | `npx skills add xxx -a openclaw -y` | 知识包,为 Agent 提供指导 |
|
|
13
|
+
| **Plugin(插件)** | `.agent/plugins/` | `foliko plugin install xxx` | 扩展功能模块 |
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## 列出远程插件
|
|
18
|
+
|
|
19
|
+
查看远程插件仓库中所有可用的插件:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
foliko plugin list
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
或使用 Agent 工具:
|
|
26
|
+
|
|
27
|
+
- 调用 `plugin_list` 工具查看远程插件列表
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## 安装插件
|
|
32
|
+
|
|
33
|
+
从远程仓库安装插件到本地 `.agent/plugins/` 目录:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
foliko plugin install <plugin-name>
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
**示例**:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
# 安装 puppeteer 插件
|
|
43
|
+
foliko plugin install puppeteer-plugin
|
|
44
|
+
|
|
45
|
+
# 安装 gate-trading 插件
|
|
46
|
+
foliko plugin install gate-trading
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
安装后需要**重启**或**重载插件**使新插件生效:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
foliko reload
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## 发布插件到远程仓库
|
|
58
|
+
|
|
59
|
+
将本地插件发布到远程 Git 仓库(需要仓库写权限)。
|
|
60
|
+
|
|
61
|
+
### 发布命令
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
foliko plugin publish <plugin-name> --repo <repo-url>
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### 详细步骤
|
|
68
|
+
|
|
69
|
+
1. **准备插件目录**
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
.agent/plugins/my-plugin/
|
|
73
|
+
├── index.js # 插件入口文件(必须)
|
|
74
|
+
├── package.json # 包配置(必须)
|
|
75
|
+
├── README.md # 使用说明(建议)
|
|
76
|
+
└── ... # 其他文件
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
2. **创建 README.md**(必需)
|
|
80
|
+
|
|
81
|
+
```markdown
|
|
82
|
+
# My Plugin
|
|
83
|
+
|
|
84
|
+
插件描述...
|
|
85
|
+
|
|
86
|
+
## 安装
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
foliko plugin install my-plugin
|
|
90
|
+
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## 使用
|
|
94
|
+
插件功能说明...
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
3. **确保远程仓库存在**
|
|
98
|
+
- 默认仓库:`https://github.com/chnak/foliko-plugins.git`
|
|
99
|
+
- 或指定其他仓库:`--repo https://github.com/user/repo.git`
|
|
100
|
+
|
|
101
|
+
4. **执行发布**
|
|
102
|
+
```bash
|
|
103
|
+
foliko plugin publish my-plugin
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## 重载插件
|
|
109
|
+
|
|
110
|
+
发布或安装插件后,需要重载使更改生效:
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
foliko reload
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
或使用工具:
|
|
117
|
+
|
|
118
|
+
- `reload_plugins` - 重载所有插件
|
|
119
|
+
- `reload_plugins({ pluginName: "xxx" })` - 重载指定插件
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## 常用命令速查
|
|
124
|
+
|
|
125
|
+
| 操作 | 命令 |
|
|
126
|
+
| ------------ | ------------------------------------------ |
|
|
127
|
+
| 列出远程插件 | `foliko plugin list` 或 `plugin_list` 工具 |
|
|
128
|
+
| 安装插件 | `foliko plugin install <name>` |
|
|
129
|
+
| 发布插件 | `foliko plugin publish <name>` |
|
|
130
|
+
| 重载插件 | `foliko reload` |
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
## 注意事项
|
|
135
|
+
|
|
136
|
+
1. **插件 vs 技能**:确保区分插件(Plugin)和技能(Skill),不要混淆
|
|
137
|
+
2. **发布权限**:发布到远程仓库需要有仓库的写权限
|
|
138
|
+
3. **README 必需**:发布的插件必须包含 README.md
|
|
139
|
+
4. **重载生效**:安装/发布后必须重载插件
|
|
@@ -1,238 +1,238 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: python-plugin-dev
|
|
3
|
-
description: Python 插件开发指南。当用户说"创建 Python 插件"、"用 Python 写插件"时立即调用此 skill。
|
|
4
|
-
allowed-tools: Read, Write, Edit, Glob, Grep, Bash
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
# Python 插件开发
|
|
8
|
-
|
|
9
|
-
## 概述
|
|
10
|
-
|
|
11
|
-
Python 插件允许用 Python 语言开发工具,插件代码运行在 Python 环境中,可以调用所有 Python 库。
|
|
12
|
-
|
|
13
|
-
## 插件存放位置
|
|
14
|
-
|
|
15
|
-
`.agent/plugins/*.py`
|
|
16
|
-
|
|
17
|
-
## 插件结构
|
|
18
|
-
|
|
19
|
-
```python
|
|
20
|
-
# .agent/plugins/my-plugin.py
|
|
21
|
-
|
|
22
|
-
PLUGIN = {
|
|
23
|
-
"name": "my-plugin",
|
|
24
|
-
"version": "1.0.0",
|
|
25
|
-
"description": "我的 Python 插件"
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
TOOLS = [
|
|
29
|
-
{
|
|
30
|
-
"name": "hello",
|
|
31
|
-
"description": "问候工具",
|
|
32
|
-
"params": {"name": "string"}
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
"name": "calc",
|
|
36
|
-
"description": "计算器工具",
|
|
37
|
-
"params": {"a": "number", "b": "number", "op": "string"}
|
|
38
|
-
}
|
|
39
|
-
]
|
|
40
|
-
|
|
41
|
-
# === 工具实现 ===
|
|
42
|
-
|
|
43
|
-
def hello(params):
|
|
44
|
-
"""问候工具"""
|
|
45
|
-
name = params.get("name", "World")
|
|
46
|
-
return {"success": True, "result": f"Hello, {name}!"}
|
|
47
|
-
|
|
48
|
-
def calc(params):
|
|
49
|
-
"""计算器工具"""
|
|
50
|
-
a = params.get("a", 0)
|
|
51
|
-
b = params.get("b", 0)
|
|
52
|
-
op = params.get("op", "add")
|
|
53
|
-
|
|
54
|
-
if op == "add":
|
|
55
|
-
result = a + b
|
|
56
|
-
elif op == "sub":
|
|
57
|
-
result = a - b
|
|
58
|
-
elif op == "mul":
|
|
59
|
-
result = a * b
|
|
60
|
-
elif op == "div":
|
|
61
|
-
if b == 0:
|
|
62
|
-
return {"success": False, "error": "Division by zero"}
|
|
63
|
-
result = a / b
|
|
64
|
-
else:
|
|
65
|
-
return {"success": False, "error": f"Unknown operation: {op}"}
|
|
66
|
-
|
|
67
|
-
return {"success": True, "result": result}
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
**重要**:`tools` 字段定义了插件提供的所有工具。框架会自动:
|
|
71
|
-
|
|
72
|
-
1. 将这些工具注册到 ExtensionExecutor
|
|
73
|
-
2. 附加到系统提示词【Extensions 扩展工具】部分
|
|
74
|
-
3. 可通过 `ext_call` 调用
|
|
75
|
-
|
|
76
|
-
## 工具函数规范
|
|
77
|
-
|
|
78
|
-
| 规范 | 说明 |
|
|
79
|
-
| ------------ | -------------------- |
|
|
80
|
-
| 返回 dict | 必须是 Python 字典 |
|
|
81
|
-
| success 字段 | `true` 或 `false` |
|
|
82
|
-
| result 字段 | 成功时返回的结果 |
|
|
83
|
-
| error 字段 | 失败时返回的错误信息 |
|
|
84
|
-
|
|
85
|
-
## 返回值格式
|
|
86
|
-
|
|
87
|
-
```python
|
|
88
|
-
# 成功
|
|
89
|
-
{"success": True, "result": "返回值"}
|
|
90
|
-
|
|
91
|
-
# 失败
|
|
92
|
-
{"success": False, "error": "错误信息"}
|
|
93
|
-
|
|
94
|
-
# 返回复杂数据
|
|
95
|
-
{"success": True, "result": {"key": "value", "list": [1, 2, 3]}}
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
## 使用方式
|
|
99
|
-
|
|
100
|
-
通过 `ext_call` 调用:
|
|
101
|
-
|
|
102
|
-
```javascript
|
|
103
|
-
ext_call({
|
|
104
|
-
plugin: 'my-plugin', // 插件名称
|
|
105
|
-
tool: 'hello', // 工具名称
|
|
106
|
-
args: { name: 'Foliko' }, // 工具参数
|
|
107
|
-
});
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
工具会自动出现在系统提示词的【Extensions 扩展工具】部分。
|
|
111
|
-
|
|
112
|
-
## 示例:天气查询插件
|
|
113
|
-
|
|
114
|
-
```python
|
|
115
|
-
# .agent/plugins/weather.py
|
|
116
|
-
|
|
117
|
-
PLUGIN = {
|
|
118
|
-
"name": "weather",
|
|
119
|
-
"version": "1.0.0",
|
|
120
|
-
"description": "天气查询插件"
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
TOOLS = [
|
|
124
|
-
{
|
|
125
|
-
"name": "get_weather",
|
|
126
|
-
"description": "查询天气",
|
|
127
|
-
"params": {"city": "string"}
|
|
128
|
-
}
|
|
129
|
-
]
|
|
130
|
-
|
|
131
|
-
def get_weather(params):
|
|
132
|
-
import requests
|
|
133
|
-
|
|
134
|
-
city = params.get("city", "北京")
|
|
135
|
-
|
|
136
|
-
try:
|
|
137
|
-
response = requests.get(
|
|
138
|
-
f"https://wttr.in/{city}?format=j1",
|
|
139
|
-
timeout=5
|
|
140
|
-
)
|
|
141
|
-
data = response.json()
|
|
142
|
-
|
|
143
|
-
return {
|
|
144
|
-
"success": True,
|
|
145
|
-
"result": {
|
|
146
|
-
"city": city,
|
|
147
|
-
"temperature": data["current_condition"][0]["temp_C"],
|
|
148
|
-
"weather": data["current_condition"][0]["weatherDesc"][0]["value"]
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
except Exception as e:
|
|
152
|
-
return {"success": False, "error": str(e)}
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
## 示例:文件处理插件
|
|
156
|
-
|
|
157
|
-
```python
|
|
158
|
-
# .agent/plugins/file_processor.py
|
|
159
|
-
|
|
160
|
-
PLUGIN = {
|
|
161
|
-
"name": "file_processor",
|
|
162
|
-
"version": "1.0.0",
|
|
163
|
-
"description": "文件处理插件"
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
TOOLS = [
|
|
167
|
-
{
|
|
168
|
-
"name": "read_file",
|
|
169
|
-
"description": "读取文件",
|
|
170
|
-
"params": {"path": "string"}
|
|
171
|
-
},
|
|
172
|
-
{
|
|
173
|
-
"name": "write_file",
|
|
174
|
-
"description": "写入文件",
|
|
175
|
-
"params": {"path": "string", "content": "string"}
|
|
176
|
-
}
|
|
177
|
-
]
|
|
178
|
-
|
|
179
|
-
def read_file(params):
|
|
180
|
-
import os
|
|
181
|
-
|
|
182
|
-
filepath = params.get("path")
|
|
183
|
-
if not filepath:
|
|
184
|
-
return {"success": False, "error": "path is required"}
|
|
185
|
-
|
|
186
|
-
try:
|
|
187
|
-
with open(filepath, "r", encoding="utf-8") as f:
|
|
188
|
-
content = f.read()
|
|
189
|
-
return {"success": True, "result": content}
|
|
190
|
-
except Exception as e:
|
|
191
|
-
return {"success": False, "error": str(e)}
|
|
192
|
-
|
|
193
|
-
def write_file(params):
|
|
194
|
-
import os
|
|
195
|
-
|
|
196
|
-
filepath = params.get("path")
|
|
197
|
-
content = params.get("content", "")
|
|
198
|
-
|
|
199
|
-
if not filepath:
|
|
200
|
-
return {"success": False, "error": "path is required"}
|
|
201
|
-
|
|
202
|
-
try:
|
|
203
|
-
os.makedirs(os.path.dirname(filepath), exist_ok=True)
|
|
204
|
-
with open(filepath, "w", encoding="utf-8") as f:
|
|
205
|
-
f.write(content)
|
|
206
|
-
return {"success": True, "result": f"Written to {filepath}"}
|
|
207
|
-
except Exception as e:
|
|
208
|
-
return {"success": False, "error": str(e)}
|
|
209
|
-
```
|
|
210
|
-
|
|
211
|
-
## 注意事项
|
|
212
|
-
|
|
213
|
-
1. **文件格式** - 必须是单个 `.py` 文件
|
|
214
|
-
2. **必须定义 `PLUGIN`** - 插件元信息
|
|
215
|
-
3. **必须定义 `TOOLS`** - 工具列表
|
|
216
|
-
4. **工具函数名** - 必须与 TOOLS 中定义的 name 一致
|
|
217
|
-
5. **异常处理** - 所有可能出错的地方都要 try-except
|
|
218
|
-
6. **编码** - 文件使用 UTF-8 编码
|
|
219
|
-
|
|
220
|
-
## 开发流程
|
|
221
|
-
|
|
222
|
-
1. **编写插件代码** - 在 `.agent/plugins/` 下创建 `.py` 文件
|
|
223
|
-
2. **自动加载** - 框架启动时自动注册工具
|
|
224
|
-
3. **调试** - 查看返回的 `success` 和 `error` 信息
|
|
225
|
-
|
|
226
|
-
## 常用 Python 库
|
|
227
|
-
|
|
228
|
-
插件中可以使用的常用库:
|
|
229
|
-
|
|
230
|
-
| 库 | 用途 | 导入方式 |
|
|
231
|
-
| -------- | ---------- | ------------------------------- |
|
|
232
|
-
| requests | HTTP 请求 | `import requests` |
|
|
233
|
-
| json | JSON 处理 | `import json` |
|
|
234
|
-
| os | 系统操作 | `import os` |
|
|
235
|
-
| pathlib | 路径处理 | `from pathlib import Path` |
|
|
236
|
-
| datetime | 日期时间 | `from datetime import datetime` |
|
|
237
|
-
| re | 正则表达式 | `import re` |
|
|
238
|
-
| csv | CSV 处理 | `import csv` |
|
|
1
|
+
---
|
|
2
|
+
name: python-plugin-dev
|
|
3
|
+
description: Python 插件开发指南。当用户说"创建 Python 插件"、"用 Python 写插件"时立即调用此 skill。
|
|
4
|
+
allowed-tools: Read, Write, Edit, Glob, Grep, Bash
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Python 插件开发
|
|
8
|
+
|
|
9
|
+
## 概述
|
|
10
|
+
|
|
11
|
+
Python 插件允许用 Python 语言开发工具,插件代码运行在 Python 环境中,可以调用所有 Python 库。
|
|
12
|
+
|
|
13
|
+
## 插件存放位置
|
|
14
|
+
|
|
15
|
+
`.agent/plugins/*.py`
|
|
16
|
+
|
|
17
|
+
## 插件结构
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
# .agent/plugins/my-plugin.py
|
|
21
|
+
|
|
22
|
+
PLUGIN = {
|
|
23
|
+
"name": "my-plugin",
|
|
24
|
+
"version": "1.0.0",
|
|
25
|
+
"description": "我的 Python 插件"
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
TOOLS = [
|
|
29
|
+
{
|
|
30
|
+
"name": "hello",
|
|
31
|
+
"description": "问候工具",
|
|
32
|
+
"params": {"name": "string"}
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"name": "calc",
|
|
36
|
+
"description": "计算器工具",
|
|
37
|
+
"params": {"a": "number", "b": "number", "op": "string"}
|
|
38
|
+
}
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
# === 工具实现 ===
|
|
42
|
+
|
|
43
|
+
def hello(params):
|
|
44
|
+
"""问候工具"""
|
|
45
|
+
name = params.get("name", "World")
|
|
46
|
+
return {"success": True, "result": f"Hello, {name}!"}
|
|
47
|
+
|
|
48
|
+
def calc(params):
|
|
49
|
+
"""计算器工具"""
|
|
50
|
+
a = params.get("a", 0)
|
|
51
|
+
b = params.get("b", 0)
|
|
52
|
+
op = params.get("op", "add")
|
|
53
|
+
|
|
54
|
+
if op == "add":
|
|
55
|
+
result = a + b
|
|
56
|
+
elif op == "sub":
|
|
57
|
+
result = a - b
|
|
58
|
+
elif op == "mul":
|
|
59
|
+
result = a * b
|
|
60
|
+
elif op == "div":
|
|
61
|
+
if b == 0:
|
|
62
|
+
return {"success": False, "error": "Division by zero"}
|
|
63
|
+
result = a / b
|
|
64
|
+
else:
|
|
65
|
+
return {"success": False, "error": f"Unknown operation: {op}"}
|
|
66
|
+
|
|
67
|
+
return {"success": True, "result": result}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
**重要**:`tools` 字段定义了插件提供的所有工具。框架会自动:
|
|
71
|
+
|
|
72
|
+
1. 将这些工具注册到 ExtensionExecutor
|
|
73
|
+
2. 附加到系统提示词【Extensions 扩展工具】部分
|
|
74
|
+
3. 可通过 `ext_call` 调用
|
|
75
|
+
|
|
76
|
+
## 工具函数规范
|
|
77
|
+
|
|
78
|
+
| 规范 | 说明 |
|
|
79
|
+
| ------------ | -------------------- |
|
|
80
|
+
| 返回 dict | 必须是 Python 字典 |
|
|
81
|
+
| success 字段 | `true` 或 `false` |
|
|
82
|
+
| result 字段 | 成功时返回的结果 |
|
|
83
|
+
| error 字段 | 失败时返回的错误信息 |
|
|
84
|
+
|
|
85
|
+
## 返回值格式
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
# 成功
|
|
89
|
+
{"success": True, "result": "返回值"}
|
|
90
|
+
|
|
91
|
+
# 失败
|
|
92
|
+
{"success": False, "error": "错误信息"}
|
|
93
|
+
|
|
94
|
+
# 返回复杂数据
|
|
95
|
+
{"success": True, "result": {"key": "value", "list": [1, 2, 3]}}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## 使用方式
|
|
99
|
+
|
|
100
|
+
通过 `ext_call` 调用:
|
|
101
|
+
|
|
102
|
+
```javascript
|
|
103
|
+
ext_call({
|
|
104
|
+
plugin: 'my-plugin', // 插件名称
|
|
105
|
+
tool: 'hello', // 工具名称
|
|
106
|
+
args: { name: 'Foliko' }, // 工具参数
|
|
107
|
+
});
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
工具会自动出现在系统提示词的【Extensions 扩展工具】部分。
|
|
111
|
+
|
|
112
|
+
## 示例:天气查询插件
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
# .agent/plugins/weather.py
|
|
116
|
+
|
|
117
|
+
PLUGIN = {
|
|
118
|
+
"name": "weather",
|
|
119
|
+
"version": "1.0.0",
|
|
120
|
+
"description": "天气查询插件"
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
TOOLS = [
|
|
124
|
+
{
|
|
125
|
+
"name": "get_weather",
|
|
126
|
+
"description": "查询天气",
|
|
127
|
+
"params": {"city": "string"}
|
|
128
|
+
}
|
|
129
|
+
]
|
|
130
|
+
|
|
131
|
+
def get_weather(params):
|
|
132
|
+
import requests
|
|
133
|
+
|
|
134
|
+
city = params.get("city", "北京")
|
|
135
|
+
|
|
136
|
+
try:
|
|
137
|
+
response = requests.get(
|
|
138
|
+
f"https://wttr.in/{city}?format=j1",
|
|
139
|
+
timeout=5
|
|
140
|
+
)
|
|
141
|
+
data = response.json()
|
|
142
|
+
|
|
143
|
+
return {
|
|
144
|
+
"success": True,
|
|
145
|
+
"result": {
|
|
146
|
+
"city": city,
|
|
147
|
+
"temperature": data["current_condition"][0]["temp_C"],
|
|
148
|
+
"weather": data["current_condition"][0]["weatherDesc"][0]["value"]
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
except Exception as e:
|
|
152
|
+
return {"success": False, "error": str(e)}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## 示例:文件处理插件
|
|
156
|
+
|
|
157
|
+
```python
|
|
158
|
+
# .agent/plugins/file_processor.py
|
|
159
|
+
|
|
160
|
+
PLUGIN = {
|
|
161
|
+
"name": "file_processor",
|
|
162
|
+
"version": "1.0.0",
|
|
163
|
+
"description": "文件处理插件"
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
TOOLS = [
|
|
167
|
+
{
|
|
168
|
+
"name": "read_file",
|
|
169
|
+
"description": "读取文件",
|
|
170
|
+
"params": {"path": "string"}
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
"name": "write_file",
|
|
174
|
+
"description": "写入文件",
|
|
175
|
+
"params": {"path": "string", "content": "string"}
|
|
176
|
+
}
|
|
177
|
+
]
|
|
178
|
+
|
|
179
|
+
def read_file(params):
|
|
180
|
+
import os
|
|
181
|
+
|
|
182
|
+
filepath = params.get("path")
|
|
183
|
+
if not filepath:
|
|
184
|
+
return {"success": False, "error": "path is required"}
|
|
185
|
+
|
|
186
|
+
try:
|
|
187
|
+
with open(filepath, "r", encoding="utf-8") as f:
|
|
188
|
+
content = f.read()
|
|
189
|
+
return {"success": True, "result": content}
|
|
190
|
+
except Exception as e:
|
|
191
|
+
return {"success": False, "error": str(e)}
|
|
192
|
+
|
|
193
|
+
def write_file(params):
|
|
194
|
+
import os
|
|
195
|
+
|
|
196
|
+
filepath = params.get("path")
|
|
197
|
+
content = params.get("content", "")
|
|
198
|
+
|
|
199
|
+
if not filepath:
|
|
200
|
+
return {"success": False, "error": "path is required"}
|
|
201
|
+
|
|
202
|
+
try:
|
|
203
|
+
os.makedirs(os.path.dirname(filepath), exist_ok=True)
|
|
204
|
+
with open(filepath, "w", encoding="utf-8") as f:
|
|
205
|
+
f.write(content)
|
|
206
|
+
return {"success": True, "result": f"Written to {filepath}"}
|
|
207
|
+
except Exception as e:
|
|
208
|
+
return {"success": False, "error": str(e)}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## 注意事项
|
|
212
|
+
|
|
213
|
+
1. **文件格式** - 必须是单个 `.py` 文件
|
|
214
|
+
2. **必须定义 `PLUGIN`** - 插件元信息
|
|
215
|
+
3. **必须定义 `TOOLS`** - 工具列表
|
|
216
|
+
4. **工具函数名** - 必须与 TOOLS 中定义的 name 一致
|
|
217
|
+
5. **异常处理** - 所有可能出错的地方都要 try-except
|
|
218
|
+
6. **编码** - 文件使用 UTF-8 编码
|
|
219
|
+
|
|
220
|
+
## 开发流程
|
|
221
|
+
|
|
222
|
+
1. **编写插件代码** - 在 `.agent/plugins/` 下创建 `.py` 文件
|
|
223
|
+
2. **自动加载** - 框架启动时自动注册工具
|
|
224
|
+
3. **调试** - 查看返回的 `success` 和 `error` 信息
|
|
225
|
+
|
|
226
|
+
## 常用 Python 库
|
|
227
|
+
|
|
228
|
+
插件中可以使用的常用库:
|
|
229
|
+
|
|
230
|
+
| 库 | 用途 | 导入方式 |
|
|
231
|
+
| -------- | ---------- | ------------------------------- |
|
|
232
|
+
| requests | HTTP 请求 | `import requests` |
|
|
233
|
+
| json | JSON 处理 | `import json` |
|
|
234
|
+
| os | 系统操作 | `import os` |
|
|
235
|
+
| pathlib | 路径处理 | `from pathlib import Path` |
|
|
236
|
+
| datetime | 日期时间 | `from datetime import datetime` |
|
|
237
|
+
| re | 正则表达式 | `import re` |
|
|
238
|
+
| csv | CSV 处理 | `import csv` |
|