foliko 1.0.36 → 1.0.38

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.
@@ -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
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
  /**
3
3
  * Foliko CLI 入口
4
4
  * Usage: foliko <command> [options]
@@ -100,9 +100,13 @@ async function chatCommand(args) {
100
100
  // 创建 Agent
101
101
  const agent = framework.createAgent({
102
102
  name: 'FolikoAgent',
103
- systemPrompt: '你是一个有帮助的助手,擅长回答问题和执行任务。',
104
- sharedPrompt: '工作目录: {{WORK_DIR}}',
105
- sharedPrompt: '工作目录: {{WORK_DIR}}',
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
  }
@@ -146,7 +146,7 @@ class ChatUI {
146
146
  let lineBuffer = ''
147
147
  const renderState = { inThink: false, inCodeBlock: false }
148
148
 
149
- console.log(colored('Agent:', GREEN))
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foliko",
3
- "version": "1.0.36",
3
+ "version": "1.0.38",
4
4
  "description": "简约的插件化 Agent 框架",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -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')
@@ -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
- const content = message.content ? JSON.parse(message.content) : {}
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
 
@@ -20,7 +20,7 @@ module.exports = function(Plugin) {
20
20
  this.priority = 80
21
21
  // 默认不启用,需要在 plugins.json 中设置 enabled: true
22
22
  this.enabled = false
23
- this.path=`./agent/data`
23
+ this.path=`.agent/data`
24
24
  this.systemPrompt='你是一个微信助手。回复内容不要使用markdown格式文本'
25
25
 
26
26
  this.config = {
@@ -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
+ ```
@@ -219,23 +219,55 @@ class SkillManagerPlugin extends Plugin {
219
219
  this._loaded = true
220
220
  }
221
221
 
222
+ /**
223
+ * 递归查找 SKILL.md 或 AGENTS.md(支持多层嵌套目录)
224
+ * @param {string} dir - 要搜索的目录
225
+ * @returns {string|null} 找到的 markdown 文件路径
226
+ */
227
+ _findSkillMarkdown(dir) {
228
+ if (!fs.existsSync(dir) || !fs.statSync(dir).isDirectory()) {
229
+ return null
230
+ }
231
+
232
+ const entries = fs.readdirSync(dir, { withFileTypes: true })
233
+
234
+ // 第一遍:优先查找 SKILL.MD
235
+ for (const entry of entries) {
236
+ if (entry.isFile() && entry.name.toUpperCase() === 'SKILL.MD') {
237
+ return path.join(dir, entry.name)
238
+ }
239
+ }
240
+
241
+ // 第二遍:查找 AGENTS.MD
242
+ for (const entry of entries) {
243
+ if (entry.isFile() && entry.name.toUpperCase() === 'AGENTS.MD') {
244
+ return path.join(dir, entry.name)
245
+ }
246
+ }
247
+
248
+ // 如果没找到,递归搜索子目录(排除 node_modules)
249
+ for (const entry of entries) {
250
+ if (entry.isDirectory() && entry.name !== 'node_modules') {
251
+ const subPath = path.join(dir, entry.name)
252
+ const found = this._findSkillMarkdown(subPath)
253
+ if (found) return found
254
+ }
255
+ }
256
+
257
+ return null
258
+ }
259
+
222
260
  /**
223
261
  * 加载单个 skill
224
262
  */
225
263
  _loadSkill(name, skillPath) {
226
- // 查找 markdown 文件,优先加载 SKILL.md 或 AGENTS.md
227
- const mdFiles = fs.readdirSync(skillPath).filter(f => f.endsWith('.md'))
228
-
229
- if (mdFiles.length === 0) {
264
+ // 查找 markdown 文件,优先加载 SKILL.md 或 AGENTS.md(支持多层嵌套)
265
+ const skillMdPath = this._findSkillMarkdown(skillPath)
266
+ if (!skillMdPath) {
230
267
  throw new Error('No markdown file found')
231
268
  }
232
269
 
233
- // 优先选择 SKILL.md 或 AGENTS.md
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)
270
+ const mainFile = skillMdPath
239
271
  const content = fs.readFileSync(mainFile, 'utf-8')
240
272
  const frontmatter = parseFrontmatter(content)
241
273