foliko 1.0.37 → 1.0.39
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/.claude/settings.local.json +4 -1
- package/cli/bin/foliko.js +1 -1
- package/cli/src/commands/chat.js +7 -3
- package/cli/src/ui/chat-ui.js +1 -1
- package/package.json +1 -1
- package/plugins/default-plugins.js +11 -1
- package/plugins/feishu-plugin.js +10 -4
- package/skills/find-skills/AGENTS.md +162 -0
- package/skills/find-skills/SKILL.md +133 -0
- package/skills/skill-guide/SKILL.md +108 -0
- package/src/capabilities/skill-manager.js +58 -11
|
@@ -77,7 +77,10 @@
|
|
|
77
77
|
"Bash(node -e \"const sdk = require\\('@larksuiteoapi/node-sdk'\\); console.log\\(Object.keys\\(sdk\\)\\);\")",
|
|
78
78
|
"Bash(node -e \"const { WSClient } = require\\('@larksuiteoapi/node-sdk'\\); const sdk = new WSClient\\({}\\); console.log\\(Object.getOwnPropertyNames\\(Object.getPrototypeOf\\(sdk\\)\\)\\);\")",
|
|
79
79
|
"Bash(node -c src/core/framework.js 2>&1)",
|
|
80
|
-
"Bash(node -c plugins/telegram-plugin.js 2>&1)"
|
|
80
|
+
"Bash(node -c plugins/telegram-plugin.js 2>&1)",
|
|
81
|
+
"Bash(node -c src/capabilities/skill-manager.js 2>&1)",
|
|
82
|
+
"Bash(node -c plugins/feishu-plugin.js 2>&1)",
|
|
83
|
+
"Bash(node debug-skills.js)"
|
|
81
84
|
]
|
|
82
85
|
}
|
|
83
86
|
}
|
package/cli/bin/foliko.js
CHANGED
package/cli/src/commands/chat.js
CHANGED
|
@@ -100,9 +100,13 @@ async function chatCommand(args) {
|
|
|
100
100
|
// 创建 Agent
|
|
101
101
|
const agent = framework.createAgent({
|
|
102
102
|
name: 'FolikoAgent',
|
|
103
|
-
systemPrompt:
|
|
104
|
-
|
|
105
|
-
|
|
103
|
+
systemPrompt: `你是一个有帮助的助手,擅长回答问题和执行任务。
|
|
104
|
+
**注意事项:**
|
|
105
|
+
1、遇到npx skills add,npx skills remove, npx skills list 命令时:
|
|
106
|
+
--添加"-a openclaw","-y"参数
|
|
107
|
+
--不要加-g 参数
|
|
108
|
+
`,
|
|
109
|
+
sharedPrompt: `工作目录: {{WORK_DIR}}`,
|
|
106
110
|
metadata: {
|
|
107
111
|
WORK_DIR: process.cwd() // 覆盖内置的 WORK_DIR
|
|
108
112
|
}
|
package/cli/src/ui/chat-ui.js
CHANGED
|
@@ -146,7 +146,7 @@ class ChatUI {
|
|
|
146
146
|
let lineBuffer = ''
|
|
147
147
|
const renderState = { inThink: false, inCodeBlock: false }
|
|
148
148
|
|
|
149
|
-
console.log(colored('
|
|
149
|
+
console.log(colored('● ', GREEN))
|
|
150
150
|
console.log()
|
|
151
151
|
|
|
152
152
|
for await (const chunk of this.agent.chatStream(message, { sessionId: this.sessionId })) {
|
package/package.json
CHANGED
|
@@ -20,7 +20,7 @@ function loadAgentConfig(agentDir = '.agent') {
|
|
|
20
20
|
skillsDirs: [],
|
|
21
21
|
agentsDir: null // 子Agent配置目录
|
|
22
22
|
}
|
|
23
|
-
|
|
23
|
+
const cmdDir=path.resolve(process.cwd())
|
|
24
24
|
const resolvedDir = path.resolve(process.cwd(), agentDir)
|
|
25
25
|
|
|
26
26
|
if (!fs.existsSync(resolvedDir)) {
|
|
@@ -135,6 +135,16 @@ function loadAgentConfig(agentDir = '.agent') {
|
|
|
135
135
|
config.skillsDirs.push(skillsDir)
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
+
// 添加 .agent/skills 目录(不存在则创建)
|
|
139
|
+
const cmdskillsDir = path.join(cmdDir, 'skills')
|
|
140
|
+
if (fs.existsSync(resolvedDir) && !fs.existsSync(cmdskillsDir)) {
|
|
141
|
+
fs.mkdirSync(cmdskillsDir, { recursive: true })
|
|
142
|
+
console.log(`[AgentConfig] Created skills directory: ${cmdskillsDir}`)
|
|
143
|
+
}
|
|
144
|
+
if (fs.existsSync(cmdskillsDir)) {
|
|
145
|
+
config.skillsDirs.push(cmdskillsDir)
|
|
146
|
+
}
|
|
147
|
+
|
|
138
148
|
// 添加 agentDir 父目录的 skills/ 目录
|
|
139
149
|
const parentDir = path.dirname(__dirname)
|
|
140
150
|
const rootSkillsDir = path.join(parentDir, 'skills')
|
package/plugins/feishu-plugin.js
CHANGED
|
@@ -128,8 +128,8 @@ module.exports = function(Plugin) {
|
|
|
128
128
|
try {
|
|
129
129
|
// 解析消息数据 - SDK 事件格式
|
|
130
130
|
// data 结构: { message: { chat_id, content, sender: { sender_id: { open_id }, ... }, message_type } }
|
|
131
|
-
if (!data || !data.message) {
|
|
132
|
-
console.log('[Feishu] Invalid message data:', JSON.stringify(data).substring(0, 500))
|
|
131
|
+
if (!data || !data.message || Object.keys(data.message).length === 0) {
|
|
132
|
+
console.log('[Feishu] Invalid or empty message data:', JSON.stringify(data).substring(0, 500))
|
|
133
133
|
return
|
|
134
134
|
}
|
|
135
135
|
|
|
@@ -140,7 +140,13 @@ module.exports = function(Plugin) {
|
|
|
140
140
|
// 注意: 群组消息可能没有 sender 字段,此时使用 chat_id 作为会话标识
|
|
141
141
|
const openId = message.sender?.sender_id?.open_id || message.sender?.open_id || message.open_id || chatId
|
|
142
142
|
const messageType = message.message_type
|
|
143
|
-
|
|
143
|
+
let content = {}
|
|
144
|
+
try {
|
|
145
|
+
content = message.content ? JSON.parse(message.content) : {}
|
|
146
|
+
} catch (e) {
|
|
147
|
+
console.log('[Feishu] Failed to parse message content:', message.content?.substring?.(0, 100))
|
|
148
|
+
return
|
|
149
|
+
}
|
|
144
150
|
|
|
145
151
|
// 消息去重
|
|
146
152
|
if (messageId && this._processedMessages.has(messageId)) {
|
|
@@ -199,7 +205,7 @@ module.exports = function(Plugin) {
|
|
|
199
205
|
}
|
|
200
206
|
|
|
201
207
|
} catch (err) {
|
|
202
|
-
console.error('[Feishu] Error handling message:', err)
|
|
208
|
+
console.error('[Feishu] Error handling message:', err.message, err.stack)
|
|
203
209
|
}
|
|
204
210
|
}
|
|
205
211
|
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# AGENTS.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to AI coding agents working on the `skills` CLI codebase.
|
|
4
|
+
|
|
5
|
+
## Project Overview
|
|
6
|
+
|
|
7
|
+
`skills` is the CLI for the open agent skills ecosystem.
|
|
8
|
+
|
|
9
|
+
## Commands
|
|
10
|
+
|
|
11
|
+
| Command | Description |
|
|
12
|
+
| ----------------------------- | --------------------------------------------------- |
|
|
13
|
+
| `skills` | Show banner with available commands |
|
|
14
|
+
| `skills add <pkg>` | Install skills from git repos, URLs, or local paths |
|
|
15
|
+
| `skills experimental_install` | Restore skills from skills-lock.json |
|
|
16
|
+
| `skills experimental_sync` | Sync skills from node_modules into agent dirs |
|
|
17
|
+
| `skills list` | List installed skills (alias: `ls`) |
|
|
18
|
+
| `skills check` | Check for available skill updates |
|
|
19
|
+
| `skills update` | Update all skills to latest versions |
|
|
20
|
+
| `skills init [name]` | Create a new SKILL.md template |
|
|
21
|
+
|
|
22
|
+
Aliases: `skills a` works for `add`. `skills i`, `skills install` (no args) restore from `skills-lock.json`. `skills ls` works for `list`. `skills experimental_install` restores from `skills-lock.json`. `skills experimental_sync` crawls `node_modules` for skills.
|
|
23
|
+
|
|
24
|
+
## Architecture
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
src/
|
|
28
|
+
├── cli.ts # Main entry point, command routing, init/check/update
|
|
29
|
+
├── cli.test.ts # CLI tests
|
|
30
|
+
├── add.ts # Core add command logic
|
|
31
|
+
├── add.test.ts # Add command tests
|
|
32
|
+
├── list.ts # List installed skills command
|
|
33
|
+
├── list.test.ts # List command tests
|
|
34
|
+
├── agents.ts # Agent definitions and detection
|
|
35
|
+
├── installer.ts # Skill installation logic (symlink/copy) + listInstalledSkills
|
|
36
|
+
├── skills.ts # Skill discovery and parsing
|
|
37
|
+
├── skill-lock.ts # Global lock file management (~/.agents/.skill-lock.json)
|
|
38
|
+
├── local-lock.ts # Local lock file management (skills-lock.json, checked in)
|
|
39
|
+
├── sync.ts # Sync command - crawl node_modules for skills
|
|
40
|
+
├── source-parser.ts # Parse git URLs, GitHub shorthand, local paths
|
|
41
|
+
├── git.ts # Git clone operations
|
|
42
|
+
├── telemetry.ts # Anonymous usage tracking
|
|
43
|
+
├── types.ts # TypeScript types
|
|
44
|
+
├── mintlify.ts # Mintlify skill fetching (legacy)
|
|
45
|
+
├── providers/ # Remote skill providers (GitHub, HuggingFace, Mintlify)
|
|
46
|
+
│ ├── index.ts
|
|
47
|
+
│ ├── registry.ts
|
|
48
|
+
│ ├── types.ts
|
|
49
|
+
│ ├── huggingface.ts
|
|
50
|
+
│ └── mintlify.ts
|
|
51
|
+
├── init.test.ts # Init command tests
|
|
52
|
+
└── test-utils.ts # Test utilities
|
|
53
|
+
|
|
54
|
+
tests/
|
|
55
|
+
├── sanitize-name.test.ts # Tests for sanitizeName (path traversal prevention)
|
|
56
|
+
├── skill-matching.test.ts # Tests for filterSkills (multi-word skill name matching)
|
|
57
|
+
├── source-parser.test.ts # Tests for URL/path parsing
|
|
58
|
+
├── installer-symlink.test.ts # Tests for symlink installation
|
|
59
|
+
├── list-installed.test.ts # Tests for listing installed skills
|
|
60
|
+
├── skill-path.test.ts # Tests for skill path handling
|
|
61
|
+
├── wellknown-provider.test.ts # Tests for well-known provider
|
|
62
|
+
└── dist.test.ts # Tests for built distribution
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Update Checking System
|
|
66
|
+
|
|
67
|
+
### How `skills check` and `skills update` Work
|
|
68
|
+
|
|
69
|
+
1. Read `~/.agents/.skill-lock.json` for installed skills
|
|
70
|
+
2. For each skill, get `skillFolderHash` from lock file
|
|
71
|
+
3. POST to `https://add-skill.vercel.sh/check-updates` with:
|
|
72
|
+
```json
|
|
73
|
+
{
|
|
74
|
+
"skills": [{ "name": "...", "source": "...", "skillFolderHash": "..." }],
|
|
75
|
+
"forceRefresh": true
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
4. API fetches fresh content from GitHub, computes hash, compares
|
|
79
|
+
5. Returns list of skills with different hashes (updates available)
|
|
80
|
+
|
|
81
|
+
### Why `forceRefresh: true`?
|
|
82
|
+
|
|
83
|
+
Both `check` and `update` always send `forceRefresh: true`. This ensures the API fetches fresh content from GitHub rather than using its Redis cache.
|
|
84
|
+
|
|
85
|
+
**Without forceRefresh:** Users saw phantom "updates available" due to stale cached hashes. The fix was to always fetch fresh.
|
|
86
|
+
|
|
87
|
+
**Tradeoff:** Slightly slower (GitHub API call per skill), but always accurate.
|
|
88
|
+
|
|
89
|
+
### Lock File Compatibility
|
|
90
|
+
|
|
91
|
+
The lock file format is v3. Key field: `skillFolderHash` (GitHub tree SHA for the skill folder).
|
|
92
|
+
|
|
93
|
+
If reading an older lock file version, it's wiped. Users must reinstall skills to populate the new format.
|
|
94
|
+
|
|
95
|
+
## Key Integration Points
|
|
96
|
+
|
|
97
|
+
| Feature | Implementation |
|
|
98
|
+
| -------------------------- | ------------------------------------------- |
|
|
99
|
+
| `skills add` | `src/add.ts` - full implementation |
|
|
100
|
+
| `skills experimental_sync` | `src/sync.ts` - crawl node_modules |
|
|
101
|
+
| `skills check` | `POST /check-updates` API |
|
|
102
|
+
| `skills update` | `POST /check-updates` + reinstall per skill |
|
|
103
|
+
|
|
104
|
+
## Development
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
# Install dependencies
|
|
108
|
+
pnpm install
|
|
109
|
+
|
|
110
|
+
# Build
|
|
111
|
+
pnpm build
|
|
112
|
+
|
|
113
|
+
# Test locally
|
|
114
|
+
pnpm dev add vercel-labs/agent-skills --list
|
|
115
|
+
pnpm dev experimental_sync
|
|
116
|
+
pnpm dev check
|
|
117
|
+
pnpm dev update
|
|
118
|
+
pnpm dev init my-skill
|
|
119
|
+
|
|
120
|
+
# Run all tests
|
|
121
|
+
pnpm test
|
|
122
|
+
|
|
123
|
+
# Run specific test file(s)
|
|
124
|
+
pnpm test tests/sanitize-name.test.ts
|
|
125
|
+
pnpm test tests/skill-matching.test.ts tests/source-parser.test.ts
|
|
126
|
+
|
|
127
|
+
# Type check
|
|
128
|
+
pnpm type-check
|
|
129
|
+
|
|
130
|
+
# Format code
|
|
131
|
+
pnpm format
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Code Style
|
|
135
|
+
|
|
136
|
+
This project uses Prettier for code formatting. **Always run `pnpm format` before committing changes** to ensure consistent formatting.
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
# Format all files
|
|
140
|
+
pnpm format
|
|
141
|
+
|
|
142
|
+
# Check formatting without fixing
|
|
143
|
+
pnpm prettier --check .
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
CI will fail if code is not properly formatted.
|
|
147
|
+
|
|
148
|
+
## Publishing
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
# 1. Bump version in package.json
|
|
152
|
+
# 2. Build
|
|
153
|
+
pnpm build
|
|
154
|
+
# 3. Publish
|
|
155
|
+
npm publish
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## Adding a New Agent
|
|
159
|
+
|
|
160
|
+
1. Add the agent definition to `src/agents.ts`
|
|
161
|
+
2. Run `pnpm run -C scripts validate-agents.ts` to validate
|
|
162
|
+
3. Run `pnpm run -C scripts sync-agents.ts` to update README.md
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: find-skills
|
|
3
|
+
description: Helps users discover and install agent skills when they ask questions like "how do I do X", "find a skill for X", "is there a skill that can...", or express interest in extending capabilities. This skill should be used when the user is looking for functionality that might exist as an installable skill.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Find Skills
|
|
7
|
+
|
|
8
|
+
This skill helps you discover and install skills from the open agent skills ecosystem.
|
|
9
|
+
|
|
10
|
+
## When to Use This Skill
|
|
11
|
+
|
|
12
|
+
Use this skill when the user:
|
|
13
|
+
|
|
14
|
+
- Asks "how do I do X" where X might be a common task with an existing skill
|
|
15
|
+
- Says "find a skill for X" or "is there a skill for X"
|
|
16
|
+
- Asks "can you do X" where X is a specialized capability
|
|
17
|
+
- Expresses interest in extending agent capabilities
|
|
18
|
+
- Wants to search for tools, templates, or workflows
|
|
19
|
+
- Mentions they wish they had help with a specific domain (design, testing, deployment, etc.)
|
|
20
|
+
|
|
21
|
+
## What is the Skills CLI?
|
|
22
|
+
|
|
23
|
+
The Skills CLI (`npx skills`) is the package manager for the open agent skills ecosystem. Skills are modular packages that extend agent capabilities with specialized knowledge, workflows, and tools.
|
|
24
|
+
|
|
25
|
+
**Key commands:**
|
|
26
|
+
|
|
27
|
+
- `npx skills find [query]` - Search for skills interactively or by keyword
|
|
28
|
+
- `npx skills add <package>` - Install a skill from GitHub or other sources
|
|
29
|
+
- `npx skills check` - Check for skill updates
|
|
30
|
+
- `npx skills update` - Update all installed skills
|
|
31
|
+
|
|
32
|
+
**Browse skills at:** https://skills.sh/
|
|
33
|
+
|
|
34
|
+
## How to Help Users Find Skills
|
|
35
|
+
|
|
36
|
+
### Step 1: Understand What They Need
|
|
37
|
+
|
|
38
|
+
When a user asks for help with something, identify:
|
|
39
|
+
|
|
40
|
+
1. The domain (e.g., React, testing, design, deployment)
|
|
41
|
+
2. The specific task (e.g., writing tests, creating animations, reviewing PRs)
|
|
42
|
+
3. Whether this is a common enough task that a skill likely exists
|
|
43
|
+
|
|
44
|
+
### Step 2: Search for Skills
|
|
45
|
+
|
|
46
|
+
Run the find command with a relevant query:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
npx skills find [query]
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
For example:
|
|
53
|
+
|
|
54
|
+
- User asks "how do I make my React app faster?" → `npx skills find react performance`
|
|
55
|
+
- User asks "can you help me with PR reviews?" → `npx skills find pr review`
|
|
56
|
+
- User asks "I need to create a changelog" → `npx skills find changelog`
|
|
57
|
+
|
|
58
|
+
The command will return results like:
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
Install with npx skills add <owner/repo@skill>
|
|
62
|
+
|
|
63
|
+
vercel-labs/agent-skills@vercel-react-best-practices
|
|
64
|
+
└ https://skills.sh/vercel-labs/agent-skills/vercel-react-best-practices
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Step 3: Present Options to the User
|
|
68
|
+
|
|
69
|
+
When you find relevant skills, present them to the user with:
|
|
70
|
+
|
|
71
|
+
1. The skill name and what it does
|
|
72
|
+
2. The install command they can run
|
|
73
|
+
3. A link to learn more at skills.sh
|
|
74
|
+
|
|
75
|
+
Example response:
|
|
76
|
+
|
|
77
|
+
```
|
|
78
|
+
I found a skill that might help! The "vercel-react-best-practices" skill provides
|
|
79
|
+
React and Next.js performance optimization guidelines from Vercel Engineering.
|
|
80
|
+
|
|
81
|
+
To install it:
|
|
82
|
+
npx skills add vercel-labs/agent-skills@vercel-react-best-practices
|
|
83
|
+
|
|
84
|
+
Learn more: https://skills.sh/vercel-labs/agent-skills/vercel-react-best-practices
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Step 4: Offer to Install
|
|
88
|
+
|
|
89
|
+
If the user wants to proceed, you can install the skill for them:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
npx skills add <owner/repo@skill> -g -y
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
The `-g` flag installs globally (user-level) and `-y` skips confirmation prompts.
|
|
96
|
+
|
|
97
|
+
## Common Skill Categories
|
|
98
|
+
|
|
99
|
+
When searching, consider these common categories:
|
|
100
|
+
|
|
101
|
+
| Category | Example Queries |
|
|
102
|
+
| --------------- | ---------------------------------------- |
|
|
103
|
+
| Web Development | react, nextjs, typescript, css, tailwind |
|
|
104
|
+
| Testing | testing, jest, playwright, e2e |
|
|
105
|
+
| DevOps | deploy, docker, kubernetes, ci-cd |
|
|
106
|
+
| Documentation | docs, readme, changelog, api-docs |
|
|
107
|
+
| Code Quality | review, lint, refactor, best-practices |
|
|
108
|
+
| Design | ui, ux, design-system, accessibility |
|
|
109
|
+
| Productivity | workflow, automation, git |
|
|
110
|
+
|
|
111
|
+
## Tips for Effective Searches
|
|
112
|
+
|
|
113
|
+
1. **Use specific keywords**: "react testing" is better than just "testing"
|
|
114
|
+
2. **Try alternative terms**: If "deploy" doesn't work, try "deployment" or "ci-cd"
|
|
115
|
+
3. **Check popular sources**: Many skills come from `vercel-labs/agent-skills` or `ComposioHQ/awesome-claude-skills`
|
|
116
|
+
|
|
117
|
+
## When No Skills Are Found
|
|
118
|
+
|
|
119
|
+
If no relevant skills exist:
|
|
120
|
+
|
|
121
|
+
1. Acknowledge that no existing skill was found
|
|
122
|
+
2. Offer to help with the task directly using your general capabilities
|
|
123
|
+
3. Suggest the user could create their own skill with `npx skills init`
|
|
124
|
+
|
|
125
|
+
Example:
|
|
126
|
+
|
|
127
|
+
```
|
|
128
|
+
I searched for skills related to "xyz" but didn't find any matches.
|
|
129
|
+
I can still help you with this task directly! Would you like me to proceed?
|
|
130
|
+
|
|
131
|
+
If this is something you do often, you could create your own skill:
|
|
132
|
+
npx skills init my-xyz-skill
|
|
133
|
+
```
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: skill-guide
|
|
3
|
+
description: 技能安装与开发指南。当用户询问"如何添加技能"、"自定义技能"、"安装技能"时立即调用。
|
|
4
|
+
allowed-tools: Read, Write, Edit, Glob, Grep, Bash
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# 技能(Skill)安装与开发指南
|
|
8
|
+
|
|
9
|
+
## 概述
|
|
10
|
+
|
|
11
|
+
技能(Skill)是 Agent 的扩展能力模块,存放在 `.agent/skills/` 目录下。
|
|
12
|
+
|
|
13
|
+
## 技能存放位置
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
项目目录/
|
|
17
|
+
└── .agent/
|
|
18
|
+
└── skills/
|
|
19
|
+
└── my-skill/ # 技能文件夹
|
|
20
|
+
├── SKILL.md # 必需,技能定义文件
|
|
21
|
+
└── ... # 其他资源文件(可选)
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## SKILL.md 格式
|
|
25
|
+
|
|
26
|
+
每个技能必须包含 `SKILL.md` 文件,使用 YAML frontmatter 定义元数据:
|
|
27
|
+
|
|
28
|
+
```yaml
|
|
29
|
+
---
|
|
30
|
+
name: my-skill # 技能名称(必需,唯一标识)
|
|
31
|
+
description: 这是一个自定义技能的描述。当用户说"..."时调用此技能。(必需)
|
|
32
|
+
allowed-tools: Read, Write, Edit, Glob, Grep, Bash # 可选,允许使用的工具列表
|
|
33
|
+
license: MIT # 可选,许可证
|
|
34
|
+
compatibility: v1.0.0 # 可选,兼容版本
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
# 技能标题
|
|
38
|
+
|
|
39
|
+
这里是技能的详细说明内容,可以使用 Markdown 格式。
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### frontmatter 字段说明
|
|
43
|
+
|
|
44
|
+
| 字段 | 必需 | 说明 |
|
|
45
|
+
|------|------|------|
|
|
46
|
+
| `name` | 是 | 技能唯一标识,字母、数字、下划线、横杠,1-64字符 |
|
|
47
|
+
| `description` | 是 | 技能描述,当用户意图匹配时会被调用 |
|
|
48
|
+
| `allowed-tools` | 否 | 允许使用的工具列表,逗号分隔 |
|
|
49
|
+
| `license` | 否 | 许可证类型 |
|
|
50
|
+
| `compatibility` | 否 | 兼容的框架版本 |
|
|
51
|
+
|
|
52
|
+
### 正文格式
|
|
53
|
+
|
|
54
|
+
frontmatter 之后是技能的正文内容,支持 Markdown 格式,包含:
|
|
55
|
+
- 详细的功能说明
|
|
56
|
+
- 使用示例
|
|
57
|
+
- 最佳实践
|
|
58
|
+
- 注意事项
|
|
59
|
+
|
|
60
|
+
## 创建自定义技能
|
|
61
|
+
|
|
62
|
+
1. 在 `.agent/skills/` 下创建技能文件夹
|
|
63
|
+
2. 创建 `SKILL.md` 文件,包含完整的 frontmatter
|
|
64
|
+
3. 在正文中详细描述技能的功能和使用方法
|
|
65
|
+
4. 调用 `reloadSkills` 工具重载所有技能
|
|
66
|
+
|
|
67
|
+
## 技能重载
|
|
68
|
+
|
|
69
|
+
创建或修改技能后,需要调用 `reloadSkills` 工具重载:
|
|
70
|
+
|
|
71
|
+
```json
|
|
72
|
+
{
|
|
73
|
+
"tool": "reloadSkills",
|
|
74
|
+
"args": {}
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## 示例:创建天气查询技能
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
.agent/skills/weather/
|
|
82
|
+
└── SKILL.md
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
SKILL.md 内容:
|
|
86
|
+
|
|
87
|
+
```yaml
|
|
88
|
+
---
|
|
89
|
+
name: weather
|
|
90
|
+
description: 查询天气信息。当用户说"天气怎么样"、"今天多少度"时调用。
|
|
91
|
+
allowed-tools: Bash, Read
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
# 天气查询技能
|
|
95
|
+
|
|
96
|
+
## 功能
|
|
97
|
+
|
|
98
|
+
查询指定城市的天气信息。
|
|
99
|
+
|
|
100
|
+
## 使用方式
|
|
101
|
+
|
|
102
|
+
用户发送 "北京天气" 或 "今天上海多少度"
|
|
103
|
+
|
|
104
|
+
## 注意事项
|
|
105
|
+
|
|
106
|
+
- 使用免费的天气 API
|
|
107
|
+
- 响应需要简洁明了
|
|
108
|
+
```
|
|
@@ -133,7 +133,7 @@ class SkillManagerPlugin extends Plugin {
|
|
|
133
133
|
this.priority = 5
|
|
134
134
|
|
|
135
135
|
this._framework = null
|
|
136
|
-
this._skillsDirs = Array.isArray(config.skillsDirs) ? config.skillsDirs : [config.skillsDir || 'skills']
|
|
136
|
+
this._skillsDirs = Array.isArray(config.skillsDirs) ? config.skillsDirs : [config.skillsDir || '.agent/skills', 'skills']
|
|
137
137
|
this._skills = new Map()
|
|
138
138
|
this._loaded = false
|
|
139
139
|
}
|
|
@@ -168,6 +168,21 @@ class SkillManagerPlugin extends Plugin {
|
|
|
168
168
|
}
|
|
169
169
|
})
|
|
170
170
|
|
|
171
|
+
// 注册 reloadSkills 工具
|
|
172
|
+
framework.registerTool({
|
|
173
|
+
name: 'reloadSkills',
|
|
174
|
+
description: '重载所有技能,当用户添加新技能或修改技能后调用此工具',
|
|
175
|
+
inputSchema: z.object({}),
|
|
176
|
+
execute: async () => {
|
|
177
|
+
this.reload(this._framework)
|
|
178
|
+
return {
|
|
179
|
+
success: true,
|
|
180
|
+
message: `Skills reloaded. Total: ${this._skills.size}`,
|
|
181
|
+
skills: Array.from(this._skills.keys())
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
})
|
|
185
|
+
|
|
171
186
|
return this
|
|
172
187
|
}
|
|
173
188
|
|
|
@@ -219,23 +234,55 @@ class SkillManagerPlugin extends Plugin {
|
|
|
219
234
|
this._loaded = true
|
|
220
235
|
}
|
|
221
236
|
|
|
237
|
+
/**
|
|
238
|
+
* 递归查找 SKILL.md 或 AGENTS.md(支持多层嵌套目录)
|
|
239
|
+
* @param {string} dir - 要搜索的目录
|
|
240
|
+
* @returns {string|null} 找到的 markdown 文件路径
|
|
241
|
+
*/
|
|
242
|
+
_findSkillMarkdown(dir) {
|
|
243
|
+
if (!fs.existsSync(dir) || !fs.statSync(dir).isDirectory()) {
|
|
244
|
+
return null
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true })
|
|
248
|
+
|
|
249
|
+
// 第一遍:优先查找 SKILL.MD
|
|
250
|
+
for (const entry of entries) {
|
|
251
|
+
if (entry.isFile() && entry.name.toUpperCase() === 'SKILL.MD') {
|
|
252
|
+
return path.join(dir, entry.name)
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// 第二遍:查找 AGENTS.MD
|
|
257
|
+
for (const entry of entries) {
|
|
258
|
+
if (entry.isFile() && entry.name.toUpperCase() === 'AGENTS.MD') {
|
|
259
|
+
return path.join(dir, entry.name)
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// 如果没找到,递归搜索子目录(排除 node_modules)
|
|
264
|
+
for (const entry of entries) {
|
|
265
|
+
if (entry.isDirectory() && entry.name !== 'node_modules') {
|
|
266
|
+
const subPath = path.join(dir, entry.name)
|
|
267
|
+
const found = this._findSkillMarkdown(subPath)
|
|
268
|
+
if (found) return found
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
return null
|
|
273
|
+
}
|
|
274
|
+
|
|
222
275
|
/**
|
|
223
276
|
* 加载单个 skill
|
|
224
277
|
*/
|
|
225
278
|
_loadSkill(name, skillPath) {
|
|
226
|
-
// 查找 markdown 文件,优先加载 SKILL.md 或 AGENTS.md
|
|
227
|
-
const
|
|
228
|
-
|
|
229
|
-
if (mdFiles.length === 0) {
|
|
279
|
+
// 查找 markdown 文件,优先加载 SKILL.md 或 AGENTS.md(支持多层嵌套)
|
|
280
|
+
const skillMdPath = this._findSkillMarkdown(skillPath)
|
|
281
|
+
if (!skillMdPath) {
|
|
230
282
|
throw new Error('No markdown file found')
|
|
231
283
|
}
|
|
232
284
|
|
|
233
|
-
|
|
234
|
-
let mainFileName = mdFiles.find(f => f.toUpperCase() === 'SKILL.MD') ||
|
|
235
|
-
mdFiles.find(f => f.toUpperCase() === 'AGENTS.MD') ||
|
|
236
|
-
mdFiles[0]
|
|
237
|
-
|
|
238
|
-
const mainFile = path.join(skillPath, mainFileName)
|
|
285
|
+
const mainFile = skillMdPath
|
|
239
286
|
const content = fs.readFileSync(mainFile, 'utf-8')
|
|
240
287
|
const frontmatter = parseFrontmatter(content)
|
|
241
288
|
|