@gulibs/safe-coder 0.0.26 → 0.0.27

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.
Files changed (192) hide show
  1. package/README.md +678 -994
  2. package/dist/cache/cache-manager.d.ts +71 -0
  3. package/dist/cache/cache-manager.d.ts.map +1 -0
  4. package/dist/cache/cache-manager.js +244 -0
  5. package/dist/cache/cache-manager.js.map +1 -0
  6. package/dist/executor/cli-executor.d.ts +106 -0
  7. package/dist/executor/cli-executor.d.ts.map +1 -0
  8. package/dist/executor/cli-executor.js +133 -0
  9. package/dist/executor/cli-executor.js.map +1 -0
  10. package/dist/executor/dependency-checker.d.ts +23 -0
  11. package/dist/executor/dependency-checker.d.ts.map +1 -0
  12. package/dist/executor/dependency-checker.js +62 -0
  13. package/dist/executor/dependency-checker.js.map +1 -0
  14. package/dist/index.js +3 -4
  15. package/dist/index.js.map +1 -1
  16. package/dist/processor/content-processor.d.ts +76 -0
  17. package/dist/processor/content-processor.d.ts.map +1 -0
  18. package/dist/processor/content-processor.js +182 -0
  19. package/dist/processor/content-processor.js.map +1 -0
  20. package/dist/processor/guide-generator.d.ts +68 -0
  21. package/dist/processor/guide-generator.d.ts.map +1 -0
  22. package/dist/processor/guide-generator.js +189 -0
  23. package/dist/processor/guide-generator.js.map +1 -0
  24. package/dist/server/safe-coder-mcp.d.ts +18 -0
  25. package/dist/server/safe-coder-mcp.d.ts.map +1 -0
  26. package/dist/server/safe-coder-mcp.js +164 -0
  27. package/dist/server/safe-coder-mcp.js.map +1 -0
  28. package/dist/tools/cache-tools.d.ts +42 -0
  29. package/dist/tools/cache-tools.d.ts.map +1 -0
  30. package/dist/tools/cache-tools.js +70 -0
  31. package/dist/tools/cache-tools.js.map +1 -0
  32. package/dist/tools/crawl-documentation.d.ts +57 -0
  33. package/dist/tools/crawl-documentation.d.ts.map +1 -0
  34. package/dist/tools/crawl-documentation.js +96 -0
  35. package/dist/tools/crawl-documentation.js.map +1 -0
  36. package/dist/tools/index.d.ts +4 -0
  37. package/dist/tools/index.d.ts.map +1 -0
  38. package/dist/tools/index.js +4 -0
  39. package/dist/tools/index.js.map +1 -0
  40. package/dist/tools/save-skill.d.ts +49 -0
  41. package/dist/tools/save-skill.d.ts.map +1 -0
  42. package/dist/tools/save-skill.js +207 -0
  43. package/dist/tools/save-skill.js.map +1 -0
  44. package/package.json +18 -28
  45. package/dist/documentation/browser-doc-browser.d.ts +0 -41
  46. package/dist/documentation/browser-doc-browser.d.ts.map +0 -1
  47. package/dist/documentation/browser-doc-browser.js +0 -357
  48. package/dist/documentation/browser-doc-browser.js.map +0 -1
  49. package/dist/documentation/browser-manager.d.ts +0 -51
  50. package/dist/documentation/browser-manager.d.ts.map +0 -1
  51. package/dist/documentation/browser-manager.js +0 -260
  52. package/dist/documentation/browser-manager.js.map +0 -1
  53. package/dist/documentation/cache.d.ts +0 -13
  54. package/dist/documentation/cache.d.ts.map +0 -1
  55. package/dist/documentation/cache.js +0 -48
  56. package/dist/documentation/cache.js.map +0 -1
  57. package/dist/documentation/checkpoint-manager.d.ts +0 -38
  58. package/dist/documentation/checkpoint-manager.d.ts.map +0 -1
  59. package/dist/documentation/checkpoint-manager.js +0 -101
  60. package/dist/documentation/checkpoint-manager.js.map +0 -1
  61. package/dist/documentation/doc-crawler.d.ts +0 -221
  62. package/dist/documentation/doc-crawler.d.ts.map +0 -1
  63. package/dist/documentation/doc-crawler.js +0 -1415
  64. package/dist/documentation/doc-crawler.js.map +0 -1
  65. package/dist/documentation/github-client.d.ts +0 -13
  66. package/dist/documentation/github-client.d.ts.map +0 -1
  67. package/dist/documentation/github-client.js +0 -90
  68. package/dist/documentation/github-client.js.map +0 -1
  69. package/dist/documentation/http-fetcher.d.ts +0 -8
  70. package/dist/documentation/http-fetcher.d.ts.map +0 -1
  71. package/dist/documentation/http-fetcher.js +0 -31
  72. package/dist/documentation/http-fetcher.js.map +0 -1
  73. package/dist/documentation/index.d.ts +0 -16
  74. package/dist/documentation/index.d.ts.map +0 -1
  75. package/dist/documentation/index.js +0 -159
  76. package/dist/documentation/index.js.map +0 -1
  77. package/dist/documentation/llms-txt/detector.d.ts +0 -31
  78. package/dist/documentation/llms-txt/detector.d.ts.map +0 -1
  79. package/dist/documentation/llms-txt/detector.js +0 -77
  80. package/dist/documentation/llms-txt/detector.js.map +0 -1
  81. package/dist/documentation/llms-txt/downloader.d.ts +0 -30
  82. package/dist/documentation/llms-txt/downloader.d.ts.map +0 -1
  83. package/dist/documentation/llms-txt/downloader.js +0 -84
  84. package/dist/documentation/llms-txt/downloader.js.map +0 -1
  85. package/dist/documentation/llms-txt/index.d.ts +0 -4
  86. package/dist/documentation/llms-txt/index.d.ts.map +0 -1
  87. package/dist/documentation/llms-txt/index.js +0 -4
  88. package/dist/documentation/llms-txt/index.js.map +0 -1
  89. package/dist/documentation/llms-txt/parser.d.ts +0 -43
  90. package/dist/documentation/llms-txt/parser.d.ts.map +0 -1
  91. package/dist/documentation/llms-txt/parser.js +0 -177
  92. package/dist/documentation/llms-txt/parser.js.map +0 -1
  93. package/dist/documentation/normalizer.d.ts +0 -6
  94. package/dist/documentation/normalizer.d.ts.map +0 -1
  95. package/dist/documentation/normalizer.js +0 -38
  96. package/dist/documentation/normalizer.js.map +0 -1
  97. package/dist/documentation/npm-client.d.ts +0 -19
  98. package/dist/documentation/npm-client.d.ts.map +0 -1
  99. package/dist/documentation/npm-client.js +0 -182
  100. package/dist/documentation/npm-client.js.map +0 -1
  101. package/dist/documentation/skill-generator.d.ts +0 -108
  102. package/dist/documentation/skill-generator.d.ts.map +0 -1
  103. package/dist/documentation/skill-generator.js +0 -642
  104. package/dist/documentation/skill-generator.js.map +0 -1
  105. package/dist/documentation/web-doc-browser.d.ts +0 -67
  106. package/dist/documentation/web-doc-browser.d.ts.map +0 -1
  107. package/dist/documentation/web-doc-browser.js +0 -555
  108. package/dist/documentation/web-doc-browser.js.map +0 -1
  109. package/dist/errors/api-validator.d.ts +0 -9
  110. package/dist/errors/api-validator.d.ts.map +0 -1
  111. package/dist/errors/api-validator.js +0 -57
  112. package/dist/errors/api-validator.js.map +0 -1
  113. package/dist/errors/contextual-analysis.d.ts +0 -14
  114. package/dist/errors/contextual-analysis.d.ts.map +0 -1
  115. package/dist/errors/contextual-analysis.js +0 -173
  116. package/dist/errors/contextual-analysis.js.map +0 -1
  117. package/dist/errors/cross-file-analyzer.d.ts +0 -16
  118. package/dist/errors/cross-file-analyzer.d.ts.map +0 -1
  119. package/dist/errors/cross-file-analyzer.js +0 -172
  120. package/dist/errors/cross-file-analyzer.js.map +0 -1
  121. package/dist/errors/eslint-integration.d.ts +0 -9
  122. package/dist/errors/eslint-integration.d.ts.map +0 -1
  123. package/dist/errors/eslint-integration.js +0 -131
  124. package/dist/errors/eslint-integration.js.map +0 -1
  125. package/dist/errors/framework-detector.d.ts +0 -10
  126. package/dist/errors/framework-detector.d.ts.map +0 -1
  127. package/dist/errors/framework-detector.js +0 -126
  128. package/dist/errors/framework-detector.js.map +0 -1
  129. package/dist/errors/index.d.ts +0 -18
  130. package/dist/errors/index.d.ts.map +0 -1
  131. package/dist/errors/index.js +0 -134
  132. package/dist/errors/index.js.map +0 -1
  133. package/dist/errors/pattern-matcher.d.ts +0 -25
  134. package/dist/errors/pattern-matcher.d.ts.map +0 -1
  135. package/dist/errors/pattern-matcher.js +0 -44
  136. package/dist/errors/pattern-matcher.js.map +0 -1
  137. package/dist/errors/patterns.d.ts +0 -11
  138. package/dist/errors/patterns.d.ts.map +0 -1
  139. package/dist/errors/patterns.js +0 -351
  140. package/dist/errors/patterns.js.map +0 -1
  141. package/dist/errors/performance-detector.d.ts +0 -11
  142. package/dist/errors/performance-detector.d.ts.map +0 -1
  143. package/dist/errors/performance-detector.js +0 -119
  144. package/dist/errors/performance-detector.js.map +0 -1
  145. package/dist/errors/runtime-detector.d.ts +0 -7
  146. package/dist/errors/runtime-detector.d.ts.map +0 -1
  147. package/dist/errors/runtime-detector.js +0 -86
  148. package/dist/errors/runtime-detector.js.map +0 -1
  149. package/dist/errors/security-detector.d.ts +0 -6
  150. package/dist/errors/security-detector.d.ts.map +0 -1
  151. package/dist/errors/security-detector.js +0 -75
  152. package/dist/errors/security-detector.js.map +0 -1
  153. package/dist/errors/typescript-integration.d.ts +0 -6
  154. package/dist/errors/typescript-integration.d.ts.map +0 -1
  155. package/dist/errors/typescript-integration.js +0 -46
  156. package/dist/errors/typescript-integration.js.map +0 -1
  157. package/dist/server/mcp-server.d.ts +0 -14
  158. package/dist/server/mcp-server.d.ts.map +0 -1
  159. package/dist/server/mcp-server.js +0 -793
  160. package/dist/server/mcp-server.js.map +0 -1
  161. package/dist/types/documentation.d.ts +0 -26
  162. package/dist/types/documentation.d.ts.map +0 -1
  163. package/dist/types/documentation.js +0 -2
  164. package/dist/types/documentation.js.map +0 -1
  165. package/dist/utils/config.d.ts +0 -21
  166. package/dist/utils/config.d.ts.map +0 -1
  167. package/dist/utils/config.js +0 -34
  168. package/dist/utils/config.js.map +0 -1
  169. package/dist/utils/http-client.d.ts +0 -17
  170. package/dist/utils/http-client.d.ts.map +0 -1
  171. package/dist/utils/http-client.js +0 -62
  172. package/dist/utils/http-client.js.map +0 -1
  173. package/dist/utils/logger.d.ts +0 -36
  174. package/dist/utils/logger.d.ts.map +0 -1
  175. package/dist/utils/logger.js +0 -128
  176. package/dist/utils/logger.js.map +0 -1
  177. package/dist/utils/rate-limiter.d.ts +0 -9
  178. package/dist/utils/rate-limiter.d.ts.map +0 -1
  179. package/dist/utils/rate-limiter.js +0 -26
  180. package/dist/utils/rate-limiter.js.map +0 -1
  181. package/dist/validation/auto-fix.d.ts +0 -15
  182. package/dist/validation/auto-fix.d.ts.map +0 -1
  183. package/dist/validation/auto-fix.js +0 -49
  184. package/dist/validation/auto-fix.js.map +0 -1
  185. package/dist/validation/index.d.ts +0 -21
  186. package/dist/validation/index.d.ts.map +0 -1
  187. package/dist/validation/index.js +0 -45
  188. package/dist/validation/index.js.map +0 -1
  189. package/dist/validation/resolution-db.d.ts +0 -15
  190. package/dist/validation/resolution-db.d.ts.map +0 -1
  191. package/dist/validation/resolution-db.js +0 -62
  192. package/dist/validation/resolution-db.js.map +0 -1
package/README.md CHANGED
@@ -1,1237 +1,921 @@
1
- # Safe Coder MCP 服务
2
-
3
- 一个基于 Model Context Protocol (MCP) 的服务器,提供以下功能:
4
- - **最新库文档** - 从 npm、GitHub 和 HTTP 源获取文档
5
- - **文档爬取和技能生成** - 递归爬取文档网站并生成 Agent Skill
6
- - **网页文档浏览** - 浏览和搜索网页文档内容
7
- - **全面错误检测** - 使用 ESLint、TypeScript、模式匹配和上下文分析
8
- - **代码验证** - 带自动修复功能
9
- - **错误解决方案建议** - 针对常见编码问题
10
-
11
- ## 功能特性
12
-
13
- ### 文档获取
14
-
15
- - npm 注册表获取
16
- - 从 GitHub 仓库获取
17
- - 从直接 HTTP 文档站点获取
18
- - 智能缓存,基于版本键和 TTL
19
- - 热门包的背景刷新
20
-
21
- ### 文档爬取和技能生成 🚀
22
-
23
- #### 核心功能
24
- - 递归爬取文档网站,自动跟踪文档链接
25
- - 智能边界检测,只在文档路径内爬取
26
- - 生成结构化的 Agent Skill 输出(Markdown 格式)
27
- - 支持深度限制、页面限制和速率控制
28
- - 自动组织内容,生成目录和章节
29
-
30
- #### 基础特性
31
- - **SPA 检测**:自动检测单页应用并提供建议
32
- - **智能重试**:对临时错误自动重试,提高成功率
33
- - **错误分类**:详细的错误类型统计和分析
34
- - **进度监控**:实时显示爬取进度和性能指标
35
-
36
- #### 🌟 增强特性(新增)
37
- - **双重爬取策略**:支持 BFS(广度优先)和 DFS(深度优先)两种策略
38
- - **并行爬取**:1-10个worker并发,速度提升 **4-6倍**
39
- - **断点续传**:中断后可恢复,支持大规模文档爬取
40
- - **llms.txt支持**:自动检测和使用llms.txt文件,效率提升 **2-3倍**
41
- - **Markdown支持**:完整支持.md文件爬取和结构化提取
42
- - **智能质量检测**:6项指标多维度评估内容质量
43
-
44
- ### 网页文档浏览
45
-
46
- - 浏览和搜索网页文档内容
47
- - 自动检测文档页面(节省 token)
48
- - 支持查询过滤和导航链接提取
49
- - 智能内容提取和组织
50
-
51
- ### 错误检测
52
-
53
- - 多层检测:
54
- 1. ESLint - 代码质量检查
55
- 2. TypeScript 编译器 - 类型检查
56
- 3. 模式匹配 - 常见错误模式
57
- 4. 上下文分析 - 未定义变量和 API 使用错误
58
- - 优先级错误报告(语法 类型 → 运行时 → 逻辑 → 警告)
59
-
60
- ### 代码验证
61
-
62
- - 完整的验证管道
63
- - 自动修复常见错误(语法、缺失导入)
64
- - 错误解决方案数据库
65
- - 在代码展示前进行验证
66
-
67
- ## 安装方式
68
-
69
- ### 方式一:通过 npm 安装(推荐)
70
-
71
- 如果已发布到 npm:
72
-
1
+ # Safe Coder MCP Server
2
+
3
+ > **Version:** 0.0.27
4
+ > **Status:** Development Preview
5
+ > **Architecture:** MCP Server (orchestration layer)
6
+
7
+ MCP Server for documentation crawling orchestration. Coordinates with `@gulibs/safe-coder-cli` to crawl documentation websites, process content, and provide structured guidance for creating Cursor AI SKILL files.
8
+
9
+ ## ⚠️ Current Version Status
10
+
11
+ **Version 0.0.27 - Development Preview:**
12
+ - ✅ Architecture refactored: Clean separation between MCP Server and CLI
13
+ - ✅ Core functionality: Crawling orchestration, content processing, SKILL guidance
14
+ - ✅ **NEW: `save_skill` tool** - Automatic SKILL file creation with complete directory structure
15
+ - ⚠️ **Not published to npm** - requires manual installation from source
16
+
17
+ ## What This Package Does
18
+
19
+ **Safe Coder MCP Server is an orchestration layer** that:
20
+
21
+ 1. **Checks dependencies** - Verifies `safe-coder-cli` is installed
22
+ 2. ✅ **Spawns CLI process** - Executes crawling via child process
23
+ 3. ✅ **Parses CLI output** - Reads JSON from stdout, progress from stderr
24
+ 4. ✅ **Processes content** - Extracts key points, code patterns, topics
25
+ 5. ✅ **Generates guidance** - Creates structured SKILL generation recommendations
26
+ 6. ✅ **Manages cache** - Stores results for 7 days in `~/.safe-coder/cache/`
27
+ 7. ✅ **Saves SKILL files** - Creates complete directory structure (SKILL.md + references/)
28
+ 8. ✅ **Exposes MCP tools** - Provides 4 tools to Cursor AI
29
+
30
+ **This package does NOT:**
31
+ - Perform web crawling (delegated to CLI)
32
+ - ❌ Run browser automation (CLI responsibility)
33
+
34
+ ## Architecture
35
+
36
+ ```
37
+ ┌─────────────────────────────────────────────────────────────┐
38
+ │ Cursor / Claude Desktop (MCP Client) │
39
+ │ • Calls MCP tools │
40
+ │ • Receives data + guidance │
41
+ │ • Creates SKILL.md based on guidance │
42
+ └────────────────┬────────────────────────────────────────────┘
43
+ │ MCP Protocol (JSON-RPC over stdio)
44
+ ┌────────────────▼────────────────────────────────────────────┐
45
+ │ @gulibs/safe-coder (MCP Server) - THIS PACKAGE │
46
+ │ ┌──────────────────────────────────────────────────────┐ │
47
+ │ │ 1. Dependency Check (which safe-coder-cli) │ │
48
+ │ │ 2. CLI Executor (spawn child process) │ │
49
+ │ │ 3. Parse JSON Output (stdout → data) │ │
50
+ │ │ 4. Content Processor (extract key info) │ │
51
+ │ │ 5. Guide Generator (create SKILL guidance) │ │
52
+ │ │ 6. Cache Manager (store/retrieve results) │ │
53
+ │ └──────────────────────────────────────────────────────┘ │
54
+ │ │
55
+ Tools: crawl_documentation, save_skill, │
56
+ │ list_cached_documentation, clear_cache │
57
+ └────────────────┬────────────────────────────────────────────┘
58
+ │ spawn('safe-coder-cli', ['crawl', url, ...])
59
+ │ stdin: commands, stdout: JSON, stderr: progress
60
+ ┌────────────────▼────────────────────────────────────────────┐
61
+ │ @gulibs/safe-coder-cli (Standalone CLI Tool) │
62
+ │ • HTTP + Browser-based web crawling │
63
+ │ • Content extraction and markup conversion │
64
+ │ • JSON output to stdout (results) │
65
+ │ • JSON output to stderr (progress messages) │
66
+ └────────────────┬────────────────────────────────────────────┘
67
+ HTTP requests / Puppeteer / Playwright
68
+ ┌────────────────▼────────────────────────────────────────────┐
69
+ │ Documentation Website (e.g., react.dev, vuejs.org) │
70
+ └─────────────────────────────────────────────────────────────┘
71
+ ```
72
+
73
+ ## Installation
74
+
75
+ ### Step 1: Prerequisites
76
+
77
+ **Node.js 18+**
73
78
  ```bash
74
- # 全局安装
75
- npm install -g @gulibs/safe-coder
76
-
77
- # 或者本地安装到项目
78
- npm install @gulibs/safe-coder
79
+ node --version # Must be v18.0.0 or higher
79
80
  ```
80
81
 
81
- ### 方式二:从源码安装
82
+ ### Step 2: Install CLI Tool (Required)
82
83
 
83
- ```bash
84
- # 克隆或下载项目
85
- git clone <repository-url>
86
- cd safe-coder
87
-
88
- # 安装依赖
89
- npm install
90
-
91
- # 构建项目
92
- npm run build
93
- ```
94
-
95
- ## 配置
96
-
97
- 设置环境变量(可选):
98
-
99
- - `CACHE_TTL_MINUTES` - 文档缓存 TTL(分钟),默认:60
100
- - `GITHUB_TOKEN` - GitHub API token(用于访问私有仓库,可选)
101
- - `ENABLE_AUTO_FIX` - 启用自动修复,默认:true
102
- - `RATE_LIMIT_REQUESTS` - 每个窗口的最大请求数,默认:100
103
- - `RATE_LIMIT_WINDOW_MS` - 速率限制窗口(毫秒),默认:60000
104
- - `LOG_LEVEL` - 日志级别:`DEBUG`、`INFO`、`WARN`、`ERROR`,默认:`INFO`
105
- - `LOG_COLORS` - 启用彩色日志输出,默认:`true`(设置为 `false` 禁用)
106
-
107
- ### 代理配置(适用于国内网络环境)
108
-
109
- 如果无法直接访问 npm registry 或 GitHub API,可以配置代理:
110
-
111
- - `HTTP_PROXY` 或 `http_proxy` - HTTP 代理地址,例如:`http://127.0.0.1:7890`
112
- - `HTTPS_PROXY` 或 `https_proxy` - HTTPS 代理地址,例如:`http://127.0.0.1:7890`
113
- - `NO_PROXY` 或 `no_proxy` - 不使用代理的地址列表(逗号分隔),例如:`localhost,127.0.0.1`
114
-
115
- **示例配置:**
84
+ ⚠️ **The MCP server requires `@gulibs/safe-coder-cli` to be globally installed.**
116
85
 
86
+ **Option A: From npm (after publication)**
117
87
  ```bash
118
- # 使用 HTTP/HTTPS 代理
119
- export HTTP_PROXY=http://127.0.0.1:7890
120
- export HTTPS_PROXY=http://127.0.0.1:7890
121
-
122
- # 或者使用 SOCKS5 代理(如果代理支持)
123
- export HTTP_PROXY=socks5://127.0.0.1:1080
124
- export HTTPS_PROXY=socks5://127.0.0.1:1080
125
-
126
- # 排除本地地址
127
- export NO_PROXY=localhost,127.0.0.1,*.local
128
- ```
129
-
130
- **在 Cursor 配置文件中设置:**
131
-
132
- ```json
133
- {
134
- "mcpServers": {
135
- "safe-coder": {
136
- "command": "npx",
137
- "args": ["-y", "@gulibs/safe-coder"],
138
- "env": {
139
- "HTTP_PROXY": "http://127.0.0.1:7890",
140
- "HTTPS_PROXY": "http://127.0.0.1:7890",
141
- "NO_PROXY": "localhost,127.0.0.1"
142
- }
143
- }
144
- }
145
- }
88
+ npm install -g @gulibs/safe-coder-cli
146
89
  ```
147
90
 
148
- ## 使用方法
149
-
150
- ### 1. 运行服务器
151
-
91
+ **Option B: From source (current development setup)**
152
92
  ```bash
153
- # 开发模式(使用 tsx)
154
- npm run dev
155
-
156
- # 生产模式(需要先构建)
93
+ # Clone and build CLI
94
+ cd /path/to/safe-coder-cli
95
+ npm install
157
96
  npm run build
158
- npm start
159
- ```
160
-
161
- 服务器通过 stdio 运行,使用 MCP 协议进行通信。
162
-
163
- ### 2. 监控服务状态
164
-
165
- #### 查看日志
97
+ npm link # Makes 'safe-coder-cli' available globally
166
98
 
167
- 所有日志输出到 `stderr`(标准错误输出),包括:
168
- - 服务器启动信息
169
- - 工具调用记录(请求 ID、参数、执行时间)
170
- - 错误和警告信息
171
-
172
- **日志格式示例:**
173
-
174
- ```
175
- [2024-01-01T12:00:00.000Z] [INFO] Safe Coder MCP server started {"version":"1.0.0","pid":12345}
176
- [2024-01-01T12:00:00.100Z] [INFO] MCP server connected to transport
177
- [2024-01-01T12:00:00.200Z] [INFO] Tool invoked: get_documentation {"requestId":"req-1234567890-1","tool":"get_documentation","params":{"packageName":"react"}}
178
- [2024-01-01T12:00:00.500Z] [INFO] Tool completed: get_documentation {"requestId":"req-1234567890-1","tool":"get_documentation","duration":"500ms","success":true}
179
- ```
180
-
181
- **日志级别(通过 `LOG_LEVEL` 环境变量设置):**
182
- - `DEBUG` - 详细调试信息
183
- - `INFO` - 一般信息(工具调用、完成)默认
184
- - `WARN` - 警告信息
185
- - `ERROR` - 错误信息
186
-
187
- #### 使用 get_status 工具
188
-
189
- 在 Cursor 中,你可以调用 `get_status` 工具来查看服务器状态:
190
-
191
- ```json
192
- {
193
- "status": "running",
194
- "uptime": 3600,
195
- "version": "1.0.0",
196
- "tools": ["get_documentation", "detect_errors", "validate_code", "resolve_error", "get_status"],
197
- "cacheSize": 10,
198
- "pid": 12345
199
- }
99
+ # Verify
100
+ safe-coder-cli --version
101
+ # Output: 0.0.1
200
102
  ```
201
103
 
202
- #### Cursor 中查看日志
203
-
204
- 1. **打开 Cursor 的开发者工具**:
205
- - macOS: `Cmd + Shift + P` → "Developer: Toggle Developer Tools"
206
- - Windows/Linux: `Ctrl + Shift + P` → "Developer: Toggle Developer Tools"
207
-
208
- 2. **查看控制台**:
209
- - 在开发者工具中切换到 "Console" 标签
210
- - MCP 服务器的日志会显示在这里
211
-
212
- 3. **启用调试模式**:
213
-
214
- 在 Cursor 配置中添加:
215
-
216
- ```json
217
- {
218
- "mcpServers": {
219
- "safe-coder": {
220
- "command": "npx",
221
- "args": ["-y", "@gulibs/safe-coder"],
222
- "env": {
223
- "LOG_LEVEL": "DEBUG",
224
- "LOG_COLORS": "true"
225
- }
226
- }
227
- }
228
- }
229
- ```
230
-
231
- ### 3. 在 Cursor 中配置
232
-
233
- > **⚠️ 重要提示**:如果包还没有发布到 npm,请使用"本地开发配置"方式。
234
-
235
- #### 步骤 1:找到 Cursor 配置文件
236
-
237
- Cursor 的 MCP 配置文件位置:
238
- - **macOS**: `~/Library/Application Support/Cursor/User/globalStorage/mcp.json`
239
- - **Windows**: `%APPDATA%\Cursor\User\globalStorage\mcp.json`
240
- - **Linux**: `~/.config/Cursor/User/globalStorage/mcp.json`
241
-
242
- 或者通过 Cursor 设置界面:
243
- 1. 打开 Cursor 设置(`Cmd/Ctrl + ,`)
244
- 2. 搜索 "MCP" 或 "Model Context Protocol"
245
- 3. 找到 MCP 服务器配置
246
-
247
- #### 步骤 2:添加配置
104
+ ### Step 3: Install MCP Server
248
105
 
249
- 根据你的安装方式选择对应的配置:
250
-
251
- ##### 方式 A:本地开发配置(推荐,如果包未发布)
252
-
253
- 使用项目的绝对路径:
254
-
255
- ```json
256
- {
257
- "mcpServers": {
258
- "safe-coder": {
259
- "command": "node",
260
- "args": ["/Users/wormhole/Documents/Developments/Our/mcp/safe-coder/dist/index.js"],
261
- "env": {
262
- "CACHE_TTL_MINUTES": "60",
263
- "GITHUB_TOKEN": "your_token_here"
264
- }
265
- }
266
- }
267
- }
268
- ```
269
-
270
- **获取你的项目路径:**
106
+ ⚠️ **Not yet published to npm - use local installation:**
271
107
 
108
+ **Development Installation:**
272
109
  ```bash
273
- # 在项目目录下运行
274
- pwd
275
- ```
276
-
277
- ##### 方式 B:通过 npm 安装(需要先发布到 npm)
278
-
279
- 如果包已发布到 npm,可以使用 npx:
110
+ cd /path/to/safe-coder
111
+ npm install
112
+ npm run build
280
113
 
281
- ```json
282
- {
283
- "mcpServers": {
284
- "safe-coder": {
285
- "command": "npx",
286
- "args": ["-y", "@gulibs/safe-coder"],
287
- "env": {
288
- "CACHE_TTL_MINUTES": "60",
289
- "GITHUB_TOKEN": "your_token_here"
290
- }
291
- }
292
- }
293
- }
114
+ # Optional: Link for global access
115
+ npm link
294
116
  ```
295
117
 
296
- 或者全局安装后使用:
118
+ ### Step 4: Configure Cursor
297
119
 
298
- ```bash
299
- # 全局安装
300
- npm install -g @gulibs/safe-coder
301
-
302
- # 查看全局安装路径
303
- npm root -g
304
- ```
120
+ **Edit Cursor MCP configuration:**
305
121
 
306
- 然后配置(替换 `<global-node-modules-path>` 为实际路径):
122
+ File location: `~/Library/Application Support/Cursor/User/globalStorage/mcp.json`
307
123
 
308
124
  ```json
309
125
  {
310
126
  "mcpServers": {
311
127
  "safe-coder": {
312
128
  "command": "node",
313
- "args": ["<global-node-modules-path>/@gulibs/safe-coder/dist/index.js"],
314
- "env": {
315
- "CACHE_TTL_MINUTES": "60",
316
- "GITHUB_TOKEN": "your_token_here"
317
- }
129
+ "args": ["/absolute/path/to/safe-coder/dist/index.js"]
318
130
  }
319
131
  }
320
132
  }
321
133
  ```
322
134
 
323
- ##### 如果从源码安装:
324
-
325
- 找到你安装的路径,然后配置:
326
-
135
+ **Replace `/absolute/path/to/safe-coder`** with actual path, e.g.:
327
136
  ```json
328
137
  {
329
138
  "mcpServers": {
330
139
  "safe-coder": {
331
140
  "command": "node",
332
- "args": ["/绝对路径/to/safe-coder/dist/index.js"],
333
- "env": {
334
- "CACHE_TTL_MINUTES": "60",
335
- "GITHUB_TOKEN": "your_token_here"
336
- }
141
+ "args": ["/Users/yourname/projects/mcp/safe-coder/dist/index.js"]
337
142
  }
338
143
  }
339
144
  }
340
145
  ```
341
146
 
342
- **获取绝对路径的方法:**
343
-
344
- 在项目目录下运行:
345
-
346
- ```bash
347
- # macOS/Linux
348
- pwd
349
-
350
- # Windows PowerShell
351
- (Get-Location).Path
352
- ```
353
-
354
- ##### 如果使用本地项目安装(node_modules):
355
-
147
+ **Future (after npm publication):**
356
148
  ```json
357
149
  {
358
150
  "mcpServers": {
359
151
  "safe-coder": {
360
- "command": "node",
361
- "args": ["./node_modules/@gulibs/safe-coder/dist/index.js"],
362
- "env": {
363
- "CACHE_TTL_MINUTES": "60",
364
- "GITHUB_TOKEN": "your_token_here"
365
- }
152
+ "command": "npx",
153
+ "args": ["-y", "@gulibs/safe-coder@latest"]
366
154
  }
367
155
  }
368
156
  }
369
157
  ```
370
158
 
371
- #### 步骤 3:验证配置
372
-
373
- 1. **检查配置文件格式**:确保 JSON 格式正确,可以使用在线 JSON 验证器
374
- 2. **重启 Cursor**:保存配置后,完全重启 Cursor
375
- 3. **检查连接状态**:
376
- - 在 Cursor 设置中查看 MCP 服务器列表
377
- - 应该能看到 "safe-coder" 服务器
378
- - 状态应该显示为已连接(绿色)
159
+ ### Step 5: Restart Cursor
379
160
 
380
- #### 步骤 4:测试工具
161
+ Restart Cursor to load the MCP server.
381
162
 
382
- Cursor AI 对话中测试:
383
-
384
- ```
385
- 请使用 get_documentation 工具获取 axios 库的文档
386
- ```
163
+ ## Usage: SKILL File Generation Workflow
387
164
 
388
- 如果工具正常工作,说明配置成功!
165
+ ### ⚠️ Important: How SKILL Files Are Created
389
166
 
390
- ### 3. 使用 MCP 工具
167
+ **The MCP server does NOT create `SKILL.md` files directly.** Here's the actual workflow:
391
168
 
392
- 配置完成后,你可以在 Cursor AI 对话中使用以下工具:
169
+ #### What the MCP Server Returns
393
170
 
394
- **可用工具列表:**
395
- 1. `get_documentation` - 获取文档
396
- 2. `browse_documentation` - 浏览网页文档
397
- 3. `crawl_documentation` - 爬取文档并生成技能
398
- 4. `detect_spa` - 检测单页应用
399
- 5. `detect_errors` - 检测代码错误
400
- 6. `validate_code` - 验证代码
401
- 7. `resolve_error` - 解决错误
402
- 8. `get_status` - 获取服务器状态
403
- 9. `get_version` - 获取版本号
171
+ 1. **Crawled content** - Full text from all pages
172
+ 2. **Processed data** - Key points, code patterns, categories, topics
173
+ 3. **SKILL generation guide** - Structured recommendations for SKILL.md
174
+ 4. **Quality assessment** - Scores for content quality, completeness
404
175
 
405
- #### `get_documentation` - 获取文档
176
+ #### Where SKILL Files Are Saved
406
177
 
407
- 获取库或包的文档。
178
+ **You must explicitly tell Cursor AI where to save the file:**
408
179
 
409
- **参数:**
410
- - `packageName`(必需):包名(npm)、仓库(owner/repo)或 URL
411
- - `version`(可选):版本或分支 / 标签
412
- - `source`(可选):源类型('npm'、'github'、'http')- 如果不指定会自动检测
413
-
414
- **使用示例:**
415
-
416
- ```
417
- 请帮我获取 axios 库的文档
418
180
  ```
419
-
420
- 或者直接调用:
421
-
422
- ```json
423
- {
424
- "packageName": "axios",
425
- "version": "latest",
426
- "source": "npm"
427
- }
181
+ User: "Crawl React docs and create a SKILL file"
182
+
183
+ Cursor AI: [Calls crawl_documentation, receives data + guidance]
184
+
185
+ User: "Save it to ~/.claude/skills/react-docs/SKILL.md"
186
+
187
+ Cursor AI: [Creates file at specified location]
428
188
  ```
429
189
 
430
- #### `browse_documentation` - 浏览网页文档
431
-
432
- 浏览和搜索网页文档页面。
433
-
434
- **参数:**
435
- - `url`(必需):文档 URL
436
- - `query`(可选):搜索查询词,用于过滤内容
437
- - `navigateTo`(可选):导航到文档内的其他页面
438
-
439
- **使用示例:**
440
-
190
+ **Recommended location pattern:**
441
191
  ```
442
- 浏览 https://react.dev/docs/getting-started 的文档
192
+ ~/.claude/skills/
193
+ ├── react-docs/SKILL.md # React documentation
194
+ ├── vue-guide/SKILL.md # Vue.js guide
195
+ ├── typescript-handbook/SKILL.md # TypeScript handbook
196
+ └── [tech-name]/SKILL.md # Generic pattern
443
197
  ```
444
198
 
445
- ```
446
- https://expressjs.com/en/guide 中查找关于路由的内容
447
- ```
199
+ **Naming conventions:**
200
+ - Directory: `[technology-name]` (lowercase, hyphens)
201
+ - File: Always `SKILL.md` (Cursor convention)
202
+ - Examples: `react-docs`, `vue-guide`, `next-js-docs`
448
203
 
449
- #### `crawl_documentation` - 爬取文档并生成Agent Skill 🚀
450
-
451
- 递归爬取文档网站,提取内容并生成结构化的 Agent Skill。
452
-
453
- **基础参数:**
454
- - `url`(必需):文档根 URL
455
- - `maxDepth`(可选):最大爬取深度(默认:3)
456
- - `maxPages`(可选):最大页面数(默认:50)
457
- - `includePaths`(可选):额外包含的路径模式
458
- - `excludePaths`(可选):排除的路径模式
459
- - `rateLimit`(可选):请求间隔(毫秒,默认:500)
460
- - `maxRetries`(可选):失败请求的最大重试次数(默认:2)
461
- - `retryDelay`(可选):重试前的延迟(毫秒,默认:1000)
462
- - `outputDir`(可选):保存技能文件的目录(如果不提供,只返回内容)
463
- - `filename`(可选):自定义文件名(不含扩展名)
464
-
465
- **🌟 增强参数(新增):**
466
- - `crawlStrategy`(可选):爬取策略 `'bfs'` | `'dfs'`(默认:bfs)
467
- - **BFS**(广度优先):逐层爬取,适合全面覆盖
468
- - **DFS**(深度优先):深入一条路径,适合深度理解
469
- - `workers`(可选):并发worker数量 1-10(默认:1)
470
- - 建议:小型站点2-3个,大型站点5-8个
471
- - 性能提升:3 workers ≈ 3倍,5 workers ≈ 4-5倍
472
- - `skipLlmsTxt`(可选):是否跳过llms.txt检测(默认:false)
473
- - 启用时自动检测和使用llms.txt,效率提升2-3倍
474
- - `checkpoint`(可选):断点续传配置
475
- - `enabled`:是否启用断点功能
476
- - `interval`:每N页保存一次(默认:10)
477
- - `file`:checkpoint文件路径(可选)
478
- - `resume`(可选):是否从上次断点恢复(默认:false)
479
-
480
- **基础功能:**
481
- - ✅ **SPA 检测**:自动检测单页应用(SPA)并提供建议
482
- - ✅ **智能重试**:对临时错误(超时、网络错误等)自动重试
483
- - ✅ **错误分类**:详细的错误类型分类和统计
484
- - ✅ **进度日志**:实时显示爬取进度和统计信息
485
-
486
- **🎯 使用示例:**
487
-
488
- ##### 1. 快速基础爬取
489
- ```
490
- 爬取 https://react.dev/docs 的文档并生成技能
491
- ```
204
+ ### Complete Example Workflow
492
205
 
493
- ##### 2. 并行加速爬取(推荐)
206
+ **1. Request crawl:**
494
207
  ```
495
- https://react.dev 生成 agent skill,使用 5 个并发worker,最多爬取 200 页
208
+ User: "Crawl the React documentation at https://react.dev and create a SKILL file"
496
209
  ```
497
210
 
498
- 对应参数:
499
- ```json
500
- {
501
- "url": "https://react.dev",
502
- "workers": 5,
503
- "maxPages": 200,
504
- "rateLimit": 200
505
- }
506
- ```
507
-
508
- ##### 3. 深度优先策略
509
- ```
510
- 使用 DFS 策略爬取 https://docs.example.com,深度限制为 6
511
- ```
512
-
513
- 对应参数:
514
- ```json
515
- {
516
- "url": "https://docs.example.com",
517
- "crawlStrategy": "dfs",
518
- "maxDepth": 6,
519
- "workers": 3
520
- }
211
+ **2. Cursor AI calls MCP tool:**
212
+ ```typescript
213
+ crawl_documentation({
214
+ url: "https://react.dev",
215
+ maxPages: 200, // Default
216
+ depth: 3 // Default
217
+ })
521
218
  ```
522
219
 
523
- ##### 4. 大规模爬取(带断点)
220
+ **3. MCP Server process:**
524
221
  ```
525
- 爬取 https://large-docs.com,最多 1000 页,启用断点每 50 页保存一次
222
+ [Dependency Check] ✓ safe-coder-cli found at /usr/local/bin/safe-coder-cli
223
+ [Spawning CLI] safe-coder-cli crawl https://react.dev --output-format json ...
224
+ [Progress] Crawling... 10/50 pages
225
+ [Progress] Crawling... 25/50 pages
226
+ [Progress] Crawling... 50/50 pages complete
227
+ [Processing] Analyzing content...
228
+ [Processing] Generating SKILL guidance...
229
+ [Cache] Saving to ~/.safe-coder/cache/aHR0cHM6Ly9yZWFjdC5kZXY=.json
230
+ [Complete] Ready to return
526
231
  ```
527
232
 
528
- 对应参数:
233
+ **4. MCP returns to Cursor:**
529
234
  ```json
530
235
  {
531
- "url": "https://large-docs.com",
532
- "maxPages": 1000,
533
- "workers": 8,
534
- "checkpoint": {
535
- "enabled": true,
536
- "interval": 50
537
- }
236
+ "success": true,
237
+ "data": {
238
+ "source": {
239
+ "url": "https://react.dev",
240
+ "crawledAt": "2026-01-15T14:30:00Z",
241
+ "pageCount": 50,
242
+ "depth": 3
243
+ },
244
+ "pages": [
245
+ {
246
+ "url": "https://react.dev/learn",
247
+ "title": "Quick Start",
248
+ "content": "Welcome to React...",
249
+ "keyPoints": [
250
+ "React is a JavaScript library",
251
+ "Components are building blocks",
252
+ "...more..."
253
+ ],
254
+ "codePatterns": [
255
+ {
256
+ "language": "jsx",
257
+ "pattern": "function Component() { return <div>...</div> }",
258
+ "description": "Functional component syntax"
259
+ }
260
+ ],
261
+ "wordCount": 1500,
262
+ "codeBlocks": 12
263
+ }
264
+ // ... 49 more pages
265
+ ],
266
+ "analysis": {
267
+ "mainTopics": ["Components", "Hooks", "State", "Props", "Effects"],
268
+ "difficulty": "intermediate",
269
+ "technicalDensity": 0.65
270
+ }
271
+ },
272
+ "skillGenerationGuide": {
273
+ "suggestedStructure": [
274
+ "Overview",
275
+ "Quick Start",
276
+ "Core Concepts",
277
+ "Hooks Reference",
278
+ "Best Practices",
279
+ "Common Patterns",
280
+ "Troubleshooting"
281
+ ],
282
+ "keyTopics": [
283
+ "JSX Syntax",
284
+ "Components (Functional & Class)",
285
+ "Props and State",
286
+ "Hooks (useState, useEffect, useContext, etc.)",
287
+ "Event Handling",
288
+ "Conditional Rendering",
289
+ "Lists and Keys"
290
+ ],
291
+ "recommendedSections": {
292
+ "overview": "React is a JavaScript library for building user interfaces...",
293
+ "quickStart": [
294
+ "Install: npx create-react-app my-app",
295
+ "Create first component",
296
+ "Understand JSX"
297
+ ],
298
+ "coreFeatures": [
299
+ "Component-based architecture",
300
+ "Virtual DOM",
301
+ "One-way data flow",
302
+ "Declarative UI"
303
+ ],
304
+ "bestPractices": [
305
+ "Use functional components with Hooks",
306
+ "Keep components small and focused",
307
+ "Lift state up when needed"
308
+ ]
309
+ },
310
+ "tips": [
311
+ "Focus on the Hooks API (modern approach)",
312
+ "Include examples for common Hooks",
313
+ "Explain component lifecycle clearly",
314
+ "Cover both client and server rendering"
315
+ ],
316
+ "quality": {
317
+ "contentQuality": 90,
318
+ "codeExamples": 85,
319
+ "completeness": 88,
320
+ "overall": 87
321
+ }
322
+ },
323
+ "fromCache": false,
324
+ "message": "Successfully crawled 50 pages. Quality score: 87/100"
538
325
  }
539
326
  ```
540
327
 
541
- ##### 5. 恢复中断的爬取
328
+ **5. Tell Cursor where to save:**
542
329
  ```
543
- 从断点恢复 https://large-docs.com 的爬取
330
+ User: "Save this as a SKILL file at ~/.claude/skills/react-docs/SKILL.md"
544
331
  ```
545
332
 
546
- 对应参数:
547
- ```json
548
- {
549
- "url": "https://large-docs.com",
550
- "resume": true,
551
- "checkpoint": { "enabled": true }
552
- }
553
- ```
333
+ **6. Cursor AI generates and saves:**
334
+ - Uses `data.pages` for content
335
+ - Uses `skillGenerationGuide` for structure
336
+ - Creates formatted `SKILL.md`
337
+ - Saves to specified location
554
338
 
555
- **📊 性能对比:**
339
+ ## MCP Tools Reference
556
340
 
557
- | 爬取规模 | 串行模式 | 并行模式(workers=5) | 提升 |
558
- |---------|---------|-------------------|------|
559
- | 50页 | ~90秒 | ~22秒 | **4倍** ⚡ |
560
- | 100页 | ~180秒 | ~45秒 | **4倍** ⚡ |
561
- | 200页 | ~360秒 | ~80秒 | **4.5倍** ⚡ |
341
+ ### Tool 1: `crawl_documentation`
562
342
 
563
- **输出内容:**
564
- - `skillContent`: Markdown 格式的技能内容
565
- - `metadata`: 技能元数据(标题、描述、源 URL 等)
566
- - `crawlStats`: 爬取统计(总页数、最大深度、错误列表、质量指标)
567
- - `files`(可选):保存的文件路径
568
- - `skillFile`: SKILL.md 文件路径
569
- - `manifestFile`: metadata.json 文件路径
343
+ (**Recommended Workflow**: Use with `save_skill` for complete automation)
570
344
 
571
- **💡 最佳实践:**
572
- 1. **先小规模测试**:maxPages设为10-20验证效果
573
- 2. **逐步增加并发**:从workers=2开始,观察效果
574
- 3. **大规模使用断点**:超过200页建议启用checkpoint
575
- 4. **关注质量指标**:diversity和coverage应 > 0.5
345
+ Crawl documentation website and return processed data with SKILL generation guidance.
576
346
 
577
- **🌐 SPA网站支持(新增):**
347
+ **Parameters:**
578
348
 
579
- 系统智能检测并处理单页应用(React、Vue、Angular等),自动切换HTTP和浏览器渲染模式。
349
+ | Parameter | Type | Required | Default | Description |
350
+ |-----------|------|----------|---------|-------------|
351
+ | `url` | `string` | ✅ Yes | - | Documentation URL to crawl |
352
+ | `maxPages` | `number` | No | `200` | Maximum pages to crawl |
353
+ | `depth` | `number` | No | `3` | Maximum crawl depth |
354
+ | `workers` | `number` | No | `1` | Number of parallel workers |
355
+ | `useBrowser` | `boolean` | No | `false` | Force browser automation |
356
+ | `browser` | `'puppeteer'` \| `'playwright'` | No | `'puppeteer'` | Browser type |
357
+ | `spaStrategy` | `'smart'` \| `'auto'` \| `'manual'` | No | `'smart'` | SPA detection |
358
+ | `useCache` | `boolean` | No | `true` | Use cached results |
359
+ | `forceRefresh` | `boolean` | No | `false` | Bypass cache |
580
360
 
581
- ##### 自动处理SPA(推荐)
582
- ```
583
- 爬取 https://react.dev 的文档 # 自动检测并处理SPA
584
- ```
361
+ **⚠️ Parameters NOT Currently Exposed (CLI supports, MCP doesn't):**
362
+ - `strategy` (bfs/dfs) - Crawl strategy
363
+ - `checkpoint`, `resume` - Checkpoint/resume functionality
364
+ - `rateLimit`, `maxRetries`, `retryDelay` - Rate limiting and retry control
365
+ - `includePaths`, `excludePaths` - URL path filtering
366
+ - `skipLlmsTxt` - llms.txt detection control
585
367
 
586
- ##### SPA策略配置
368
+ **Returns:**
587
369
  ```typescript
588
370
  {
589
- "spaStrategy": "smart", // smart(智能)| auto(自动)| manual(手动)
590
- "spaFallback": "warn", // warn(警告)| skip(跳过)| error(错误)
591
- "browserPath": "/path/to/chrome", // 可选:自定义浏览器路径
592
- "waitForTimeout": 3000, // 可选:等待内容加载时间
593
- "networkIdleTimeout": 500 // 可选:网络空闲等待时间
371
+ success: boolean;
372
+ data: {
373
+ source: { url, crawledAt, pageCount, depth };
374
+ pages: Array<{
375
+ url, title, content, keyPoints, codePatterns,
376
+ category, wordCount, codeBlocks, headings
377
+ }>;
378
+ metadata: { technology, version, documentType, categories };
379
+ statistics: { totalPages, maxDepthReached, errors, linkDiscovery };
380
+ analysis: {
381
+ totalWords, totalCodeBlocks, categories,
382
+ mainTopics, technicalDensity, difficulty
383
+ };
384
+ };
385
+ skillGenerationGuide: {
386
+ suggestedStructure: string[];
387
+ keyTopics: string[];
388
+ recommendedSections: {
389
+ overview, quickStart, coreFeatures, bestPractices, troubleshooting
390
+ };
391
+ tips: string[];
392
+ quality: { contentQuality, codeExamples, completeness, overall };
393
+ };
394
+ fromCache: boolean;
395
+ cacheAge?: string; // If from cache
396
+ message: string;
594
397
  }
595
398
  ```
596
399
 
597
- **三种SPA策略**:
598
- - **smart(默认)**: HTTP优先,内容不足时自动切换浏览器(推荐)
599
- - **auto**: 检测到SPA立即使用浏览器
600
- - **manual**: 仅在useBrowserAutomation=true时使用浏览器
400
+ **Example Cursor prompts:**
601
401
 
602
- **浏览器要求**:
603
- - 系统已安装Chrome/Chromium/Edge(推荐,自动检测)
604
- - 或安装完整版puppeteer(自动下载Chromium)
605
- - ✅ 或设置CHROME_PATH环境变量
606
- - 📖 详见:[SPA浏览器设置指南](docs/SPA_BROWSER_SETUP.md)
402
+ ```bash
403
+ # Basic usage
404
+ "Crawl https://react.dev and create a SKILL"
607
405
 
608
- **性能对比**:
609
- - HTTP模式:0.5-1秒/页
610
- - 浏览器模式:2-3秒/页
611
- - smart策略:平均<1.5秒/页(自动优化)
406
+ # Limit pages
407
+ "Crawl Vue.js docs but only 50 pages"
612
408
 
613
- **使用示例**:
409
+ # Force refresh
410
+ "Re-crawl React docs, ignore cache"
614
411
 
615
- 快速SPA爬取:
616
- ```
617
- 爬取 https://vuejs.org,自动处理SPA,最多100页
412
+ # Use browser for SPA
413
+ "Crawl https://app.example.com with Playwright"
618
414
  ```
619
415
 
620
- 已知SPA站点:
621
- ```
622
- 从 https://angular.io 生成技能,使用浏览器渲染,5个并发worker
623
- ```
416
+ ### Tool 2: `list_cached_documentation`
624
417
 
625
- 对应参数:
626
- ```json
418
+ List all cached documentation crawl results with metadata.
419
+
420
+ **Parameters:** None
421
+
422
+ **Returns:**
423
+ ```typescript
627
424
  {
628
- "url": "https://angular.io",
629
- "spaStrategy": "auto",
630
- "workers": 5,
631
- "maxPages": 200
425
+ success: boolean;
426
+ entries: Array<{
427
+ url: string;
428
+ technology?: string;
429
+ pageCount: number;
430
+ cachedAt: string; // ISO timestamp
431
+ age: string; // Human-readable, e.g., "2 hours ago"
432
+ size: string; // Human-readable, e.g., "2.5 MB"
433
+ }>;
434
+ statistics: {
435
+ totalEntries: number;
436
+ totalSize: number; // Bytes
437
+ oldestEntry?: Date;
438
+ newestEntry?: Date;
439
+ };
440
+ message: string;
632
441
  }
633
442
  ```
634
443
 
635
- **📚 详细文档:**
636
- - SPA浏览器设置:`docs/SPA_BROWSER_SETUP.md`
637
- - 完整使用指南:`docs/ENHANCED_CRAWLING.md`
638
- - 快速上手:查看项目中的 `QUICKSTART_*.md` 文档
639
- - 实施细节:`IMPLEMENTATION_SUMMARY.md`
640
-
641
- #### `detect_errors` - 检测错误
642
-
643
- 检测代码中的错误和警告。
644
-
645
- **参数:**
646
- - `code`(必需):要分析的代码
647
- - `filename`(可选):用于上下文的文件名(默认:'code.ts')
648
-
649
- **使用示例:**
650
-
651
- ```
652
- 请检测这段代码的错误:
653
- const x = y;
654
- console.log(z);
444
+ **Example Cursor prompts:**
445
+ ```bash
446
+ "Show me all cached documentation"
447
+ "List cached docs"
448
+ "What's in the cache?"
655
449
  ```
656
450
 
657
- #### `validate_code` - 验证代码
451
+ ### Tool 3: `save_skill` NEW
658
452
 
659
- 验证代码并可选择自动修复常见错误。
453
+ **Save complete SKILL directory structure to filesystem.**
660
454
 
661
- **参数:**
662
- - `code`(必需):要验证的代码
663
- - `filename`(可选):用于上下文的文件名
664
- - `autoFix`(可选):启用自动修复(默认:true)
455
+ Creates a properly formatted Cursor Agent Skill with:
456
+ - `SKILL.md` - Main skill file with metadata
457
+ - `references/` - Reference documentation organized by category
458
+ - Standard directory structure compatible with Cursor
665
459
 
666
- **使用示例:**
460
+ **Parameters:**
667
461
 
668
- ```
669
- 请验证并修复这段代码:
670
- function test() {
671
- return x
462
+ | Parameter | Type | Required | Default | Description |
463
+ |-----------|------|----------|---------|-------------|
464
+ | `skillName` | `string` | ✅ Yes | - | Name for skill directory (e.g., "react-docs") |
465
+ | `skillContent` | `string` | ✅ Yes | - | Content for SKILL.md file |
466
+ | `referenceFiles` | `Record<string, string>` | No | `{}` | Map of category → markdown content |
467
+ | `baseDirectory` | `string` | No | `~/.claude/skills` | Base directory for skills |
468
+ | `overwrite` | `boolean` | No | `false` | Overwrite existing skill |
469
+
470
+ **Returns:**
471
+ ```typescript
472
+ {
473
+ success: boolean;
474
+ skillDirectory: string; // Absolute path to skill directory
475
+ filesCreated: {
476
+ skillMd: string; // Path to SKILL.md
477
+ references: string[]; // Paths to reference files
478
+ };
479
+ message: string;
672
480
  }
673
481
  ```
674
482
 
675
- #### `resolve_error` - 解决错误
676
-
677
- 获取特定错误的解决方案建议。
678
-
679
- **参数:**
680
- - `errorType`(必需):错误类型
681
- - `message`(必需):错误消息
682
- - `line`(可选):错误发生的行号
683
-
684
- **使用示例:**
685
-
483
+ **Directory Structure Created:**
686
484
  ```
687
- 我遇到了一个 undefined-variable 错误,消息是 "Variable 'x' is used but not defined",在第 5 行
485
+ ~/.claude/skills/
486
+ └── [skillName]/
487
+ ├── SKILL.md # Main skill file
488
+ └── references/ # Reference documentation
489
+ ├── api.md # API category
490
+ ├── guides.md # Guides category
491
+ ├── getting_started.md # Getting started
492
+ └── ... # Other categories
688
493
  ```
689
494
 
690
- #### `detect_spa` - 检测单页应用
691
-
692
- 检测网站是否为需要 JavaScript 渲染的单页应用(SPA)。
495
+ **Example Cursor Prompts:**
693
496
 
694
- **参数:**
695
- - `url`(必需):要检测的 URL
497
+ ```bash
498
+ # After crawling, extract and save skill data
499
+ "Use the crawled React data to create a complete SKILL:
500
+ - skillName: 'react-docs'
501
+ - skillContent: [generated from guidance]
502
+ - referenceFiles: [organized by category]"
696
503
 
697
- **使用示例:**
504
+ # Save with custom location
505
+ "Save the Vue skill to ~/my-skills/"
698
506
 
699
- ```
700
- 检测 https://react-dnd.github.io/react-dnd/docs 是否是 SPA
507
+ # Overwrite existing
508
+ "Update the react-docs skill with new content"
701
509
  ```
702
510
 
703
- **返回:**
704
- - `isSPA`:是否为 SPA
705
- - `confidence`:检测置信度(high/medium/low)
706
- - `indicators`:检测到的 SPA 指标
707
- - `suggestion`:建议(如果检测到 SPA)
511
+ **Automated Workflow Example:**
708
512
 
709
- ### 4. 使用 MCP 资源
513
+ ```
514
+ User: "Crawl React docs and save as a complete SKILL"
710
515
 
711
- #### `safe-coder://documentation` - 缓存的文档
516
+ Step 1: Cursor calls crawl_documentation
517
+ Step 2: Receives data with pages organized by category
518
+ Step 3: Cursor calls save_skill with:
519
+ {
520
+ skillName: "react-docs",
521
+ skillContent: "[Generated SKILL.md from guidance]",
522
+ referenceFiles: {
523
+ "api": "[API pages content]",
524
+ "guides": "[Guide pages content]",
525
+ "getting_started": "[Getting started content]"
526
+ }
527
+ }
528
+ Step 4: Tool creates complete directory structure
529
+ Step 5: Returns paths to all created files
530
+ ```
712
531
 
713
- 访问缓存的文档条目,查看缓存状态。
532
+ ### Tool 4: `clear_cache`
714
533
 
715
- #### `safe-coder://error-patterns` - 错误模式数据库
534
+ Clear cached documentation results by pattern, all entries, or expired only.
716
535
 
717
- 访问错误模式数据库,查看已知的错误模式和解决方案。
536
+ **Parameters:**
718
537
 
719
- ## 开发
538
+ | Parameter | Type | Required | Default | Description |
539
+ |-----------|------|----------|---------|-------------|
540
+ | `urlPattern` | `string` | No | - | URL pattern to match (substring) |
541
+ | `clearAll` | `boolean` | No | `false` | Clear all cached entries |
720
542
 
721
- ### 项目结构
543
+ **Behavior:**
544
+ - If `clearAll: true` → Delete all cached entries
545
+ - If `urlPattern` provided → Delete entries matching pattern
546
+ - If neither → Delete only expired entries (>7 days old)
722
547
 
548
+ **Returns:**
549
+ ```typescript
550
+ {
551
+ success: boolean;
552
+ deletedCount: number;
553
+ message: string;
554
+ }
723
555
  ```
724
- safe-coder/
725
- ├── src/
726
- │ ├── documentation/ # 文档获取、缓存、爬取和技能生成
727
- │ │ ├── index.ts # 文档服务
728
- │ │ ├── web-doc-browser.ts # 网页文档浏览
729
- │ │ ├── doc-crawler.ts # 文档爬取
730
- │ │ └── skill-generator.ts # 技能生成
731
- │ ├── errors/ # 错误检测(ESLint、TypeScript、模式、上下文)
732
- │ ├── validation/ # 代码验证和自动修复
733
- │ ├── server/ # MCP 服务器实现
734
- │ ├── types/ # TypeScript 类型定义
735
- │ ├── utils/ # 配置和工具函数
736
- │ └── index.ts # 入口文件
737
- ├── tests/ # 测试文件
738
- ├── dist/ # 编译输出
739
- └── package.json
740
- ```
741
-
742
- ### 开发命令
743
556
 
557
+ **Example Cursor prompts:**
744
558
  ```bash
745
- # 安装依赖
746
- npm install
747
-
748
- # 构建项目
749
- npm run build
750
-
751
- # 开发模式运行(自动重新编译)
752
- npm run dev
753
-
754
- # 运行测试
755
- npm test
756
-
757
- # 监听模式运行测试
758
- npm run test:watch
559
+ # Clear all
560
+ "Clear all cached documentation"
759
561
 
760
- # 类型检查
761
- npm run type-check
562
+ # Clear by pattern
563
+ "Clear cache for react.dev"
564
+ "Delete cached Vue docs"
762
565
 
763
- # 代码检查
764
- npm run lint
566
+ # Clear expired only
567
+ "Clear old cached docs"
765
568
  ```
766
569
 
767
- ### 调试
768
-
769
- 如果遇到问题,可以:
770
-
771
- 1. **检查服务器是否正常运行**:
772
-
773
- ```bash
774
- npm run dev
775
- ```
776
-
777
- 应该看到:`Safe Coder MCP server running on stdio`
778
-
779
- 2. **查看 Cursor 的 MCP 日志**:
780
- - 在 Cursor 中打开开发者工具
781
- - 查看控制台中的 MCP 相关错误
782
-
783
- 3. **测试工具调用**:
784
- 可以在 Cursor 的 AI 对话中直接请求使用工具,例如:
785
-
786
- ```
787
- 请使用 get_documentation 工具获取 react 的文档
788
- ```
789
-
790
- ## 常见问题
570
+ ## Internal Workflow
791
571
 
792
- ### Q: 服务器无法启动?
572
+ ### 1. Dependency Check
793
573
 
794
- **A:** 检查以下几点:
795
- - 确保已运行 `npm install` 和 `npm run build`
796
- - 检查 Node.js 版本(建议 18+)
797
- - 查看错误日志
798
-
799
- ### Q: 无法获取 GitHub 文档?
800
-
801
- **A:**
802
- - 如果访问私有仓库,需要设置 `GITHUB_TOKEN` 环境变量
803
- - 公开仓库通常不需要 token,但设置 token 可以提高速率限制
574
+ ```typescript
575
+ const checker = new DependencyChecker();
576
+ const check = await checker.checkCLIInstalled();
804
577
 
805
- ### Q: 错误检测不准确?
578
+ if (!check.installed) {
579
+ throw new Error(`
580
+ ⚠️ safe-coder-cli is not installed.
806
581
 
807
- **A:**
808
- - 确保代码文件扩展名正确(`.ts` 用于 TypeScript,`.js` 用于 JavaScript)
809
- - 某些复杂的错误可能需要更多上下文
810
- - 可以尝试使用 `validate_code` 工具获得更全面的分析
582
+ Please install globally:
583
+ npm install -g @gulibs/safe-coder-cli
811
584
 
812
- ### Q: 如何更新错误模式数据库?
585
+ Or from source:
586
+ cd /path/to/safe-coder-cli
587
+ npm install && npm run build && npm link
813
588
 
814
- **A:**
815
- - 编辑 `src/errors/patterns.json` 文件
816
- - 添加新的错误模式
817
- - 重新构建项目
589
+ Then verify:
590
+ safe-coder-cli --version
591
+ `);
592
+ }
593
+ ```
818
594
 
819
- ### Q: 文档爬取工具如何使用?
595
+ ### 2. CLI Execution
820
596
 
821
- **A:**
822
- - 使用 `crawl_documentation` 工具,提供文档根 URL
823
- - 工具会自动检测文档页面,跟踪链接,生成技能
824
- - 支持配置深度和页面限制
825
- - 详见 `DOC_CRAWLER_USAGE.md`
597
+ ```typescript
598
+ const executor = new CLIExecutor(checker);
599
+ const result = await executor.executeCrawl({
600
+ url: 'https://react.dev',
601
+ maxPages: 200,
602
+ maxDepth: 3,
603
+ // ... other params
604
+ }, (progress) => {
605
+ console.error(`[Progress] ${progress.message}`);
606
+ });
607
+ ```
608
+
609
+ **Under the hood:**
610
+ ```bash
611
+ spawn('safe-coder-cli', [
612
+ 'crawl',
613
+ 'https://react.dev',
614
+ '--output-format', 'json',
615
+ '--max-pages', '200',
616
+ '--depth', '3'
617
+ ])
826
618
 
827
- **示例:**
828
- ```
829
- 爬取 https://react.dev/docs 的文档并生成技能
619
+ # stdout → JSON result
620
+ # stderr → Progress messages
830
621
  ```
831
622
 
832
- ### Q: 爬取大型文档站点时需要注意什么?
623
+ ### 3. Content Processing
833
624
 
834
- **A:**
835
- - 使用 `maxPages` 参数限制页面数量(默认 50)
836
- - 使用 `maxDepth` 参数限制爬取深度(默认 3)
837
- - 调整 `rateLimit` 避免对服务器造成压力(默认 500ms)
838
- - 使用 `workers` 参数启用并行爬取(推荐5-8个)
839
- - 启用 `checkpoint` 断点续传(超过200页建议启用)
840
- - 大型站点建议分多次爬取不同部分
841
-
842
- ### Q: 如何爬取SPA网站(React、Vue等)?
843
-
844
- **A:**
845
- - 系统自动检测SPA并智能切换到浏览器渲染
846
- - 确保系统已安装Chrome/Chromium/Edge浏览器
847
- - 使用 `spaStrategy: "smart"` 获得最佳性能(默认)
848
- - 或使用 `spaStrategy: "auto"` 强制使用浏览器
849
- - 详见:`docs/SPA_BROWSER_SETUP.md`
625
+ ```typescript
626
+ const processor = new ContentProcessor();
627
+ const processed = await processor.process(rawResult);
850
628
 
851
- **示例**:
629
+ // Extracts:
630
+ // - Key points from each page
631
+ // - Code patterns and examples
632
+ // - Content categories
633
+ // - Technical density
634
+ // - Difficulty level
852
635
  ```
853
- 爬取 https://react.dev,自动处理SPA
854
- ```
855
-
856
- ### Q: 系统没有Chrome怎么办?
857
636
 
858
- **A:**
859
- 有三种解决方案:
860
- 1. **安装Chrome**(推荐):
861
- - macOS: `brew install --cask google-chrome`
862
- - Windows: `winget install Google.Chrome`
863
- - Linux: `sudo apt install google-chrome-stable`
637
+ ### 4. SKILL Guidance Generation
864
638
 
865
- 2. **安装完整版puppeteer**(自动下载Chromium):
866
- ```bash
867
- npm install puppeteer
868
- ```
869
-
870
- 3. **设置浏览器路径**:
871
- ```bash
872
- export CHROME_PATH=/path/to/chrome
873
- ```
639
+ ```typescript
640
+ const guideGenerator = new GuideGenerator();
641
+ const guide = guideGenerator.generate(processed);
874
642
 
875
- 详细指南:`docs/SPA_BROWSER_SETUP.md`
643
+ // Creates:
644
+ // - Suggested SKILL structure
645
+ // - Key topics to cover
646
+ // - Recommended sections
647
+ // - Writing tips
648
+ // - Quality assessment
649
+ ```
876
650
 
877
- ### Q: 网页文档浏览和文档爬取有什么区别?
651
+ ### 5. Caching
878
652
 
879
- **A:**
880
- - **`browse_documentation`**: 浏览单个文档页面,支持查询和导航
881
- - **`crawl_documentation`**: 递归爬取多个页面,生成完整的技能文件
882
- - 浏览适合查看特定内容,爬取适合生成完整文档技能
653
+ ```typescript
654
+ const cache = new CacheManager();
883
655
 
884
- ## 发布到 npm(开发者)
656
+ // Save (7-day TTL)
657
+ await cache.set(url, processed, guide);
885
658
 
886
- 如果你想将这个包发布到 npm:
659
+ // Retrieve
660
+ const cached = await cache.get(url);
661
+ if (cached && !forceRefresh) {
662
+ return cached;
663
+ }
664
+ ```
887
665
 
888
- ### 1. 准备发布
666
+ **Cache location:** `~/.safe-coder/cache/`
667
+ **Cache format:** JSON files with base64-encoded URL as filename
668
+ **TTL:** 7 days (default)
889
669
 
890
- ```bash
891
- # 确保已登录 npm
892
- npm login
670
+ ## Error Handling
893
671
 
894
- # 检查包名是否可用(如果已发布,需要更新版本号)
895
- npm view @gulibs/safe-coder
672
+ ### CLI Not Installed
896
673
 
897
- # 更新版本号
898
- npm version patch # 或 minor, major
899
674
  ```
675
+ Error: safe-coder-cli is not installed
900
676
 
901
- ### 2. 发布
677
+ Please install:
678
+ npm install -g @gulibs/safe-coder-cli
902
679
 
903
- ```bash
904
- # 发布到 npm
905
- npm publish
906
-
907
- # 如果使用作用域包且是首次发布,需要添加访问权限
908
- npm publish --access public
680
+ Current PATH checked:
681
+ /usr/local/bin
682
+ /usr/bin
683
+ /bin
684
+ ...
909
685
  ```
910
686
 
911
- ### 3. 验证发布
687
+ ### CLI Execution Failed
912
688
 
913
- ```bash
914
- # 检查包是否已发布
915
- npm view @gulibs/safe-coder
916
-
917
- # 测试安装
918
- npm install -g @gulibs/safe-coder
919
689
  ```
690
+ Error: CLI process exited with code 1
920
691
 
921
- ## 本地开发配置示例
922
-
923
- 如果你在本地开发,可以创建一个测试配置:
692
+ stderr output:
693
+ [Error] Failed to crawl: Network timeout
694
+ [Error] URL: https://example.com
924
695
 
925
- ### 创建测试配置文件
696
+ Possible solutions:
697
+ - Check network connectivity
698
+ - Try with --use-browser flag
699
+ - Increase timeout with --rate-limit
700
+ ```
926
701
 
927
- 在项目根目录创建 `cursor-mcp-config.json`:
702
+ ### Cache Errors
928
703
 
929
- ```json
930
- {
931
- "mcpServers": {
932
- "safe-coder": {
933
- "command": "node",
934
- "args": ["./dist/index.js"],
935
- "env": {
936
- "CACHE_TTL_MINUTES": "60",
937
- "GITHUB_TOKEN": ""
938
- }
939
- }
940
- }
941
- }
942
704
  ```
705
+ Warning: Failed to cache results
706
+ Error: EACCES: permission denied, mkdir '~/.safe-coder/cache'
943
707
 
944
- 然后将此配置复制到 Cursor 的配置目录。
708
+ Continuing without cache...
709
+ ```
945
710
 
946
- ### 快速测试脚本
711
+ Cache errors are non-fatal - the operation continues without caching.
947
712
 
948
- 创建 `test-mcp.sh`(macOS/Linux)或 `test-mcp.bat`(Windows):
713
+ ## Configuration
949
714
 
950
- ```bash
951
- #!/bin/bash
952
- # test-mcp.sh
715
+ ### Cache Settings
953
716
 
954
- echo "构建项目..."
955
- npm run build
717
+ Modify cache behavior by editing `src/cache/cache-manager.ts`:
956
718
 
957
- echo "测试 MCP 服务器..."
958
- node dist/index.js
719
+ ```typescript
720
+ const cache = new CacheManager(
721
+ '/custom/cache/path', // Default: ~/.safe-coder/cache
722
+ 14 // TTL in days (default: 7)
723
+ );
959
724
  ```
960
725
 
961
- ## 故障排除
726
+ ### CLI Arguments Mapping
962
727
 
963
- ### 问题:Cursor 无法找到服务器
728
+ | MCP Parameter | CLI Argument |
729
+ |---------------|--------------|
730
+ | `url` | `<url>` (positional) |
731
+ | `maxPages` | `--max-pages <number>` |
732
+ | `depth` | `--max-depth <number>` |
733
+ | `workers` | `--workers <number>` |
734
+ | `useBrowser` | (implicitly sets `--spa-strategy auto`) |
735
+ | `browser` | `--browser <type>` |
736
+ | `spaStrategy` | `--spa-strategy <type>` |
737
+ | - | `--output-format json` (forced) |
964
738
 
965
- **解决方案:**
966
- 1. 检查路径是否正确(使用绝对路径)
967
- 2. 确保 `dist/index.js` 文件存在
968
- 3. 检查 Node.js 是否在 PATH 中:`which node` 或 `where node`
739
+ ## Troubleshooting
969
740
 
970
- ### 问题:服务器启动失败
741
+ ### MCP Server Not Appearing in Cursor
971
742
 
972
- **解决方案:**
973
- 1. 检查依赖是否安装:`npm install`
974
- 2. 检查构建是否成功:`npm run build`
975
- 3. 查看错误日志
743
+ 1. **Check configuration file exists:**
744
+ ```bash
745
+ cat ~/Library/Application\ Support/Cursor/User/globalStorage/mcp.json
746
+ ```
976
747
 
977
- ### 问题:工具无法使用
748
+ 2. **Verify JSON syntax is valid**
978
749
 
979
- **解决方案:**
980
- 1. 确认服务器在 Cursor 中显示为已连接
981
- 2. 检查 Cursor 版本是否支持 MCP
982
- 3. 查看 Cursor 开发者工具中的错误信息
750
+ 3. **Check absolute path is correct:**
751
+ ```bash
752
+ node /absolute/path/to/safe-coder/dist/index.js
753
+ # Should not error
754
+ ```
983
755
 
984
- ### 问题:权限错误
756
+ 4. **Restart Cursor completely**
985
757
 
986
- **解决方案:**
758
+ ### "CLI Not Found" Error
987
759
 
988
760
  ```bash
989
- # 确保 dist/index.js 有执行权限
990
- chmod +x dist/index.js
991
- ```
761
+ # Check if CLI is in PATH
762
+ which safe-coder-cli
992
763
 
993
- ## 许可证
994
-
995
- MIT
764
+ # If not found, reinstall
765
+ cd /path/to/safe-coder-cli
766
+ npm link
996
767
 
997
- ## 🎓 在大模型中使用MCP Server生成Agent Skill
998
-
999
- ### 快速上手
1000
-
1001
- #### 步骤1:在Claude/Cursor中触发爬取
1002
-
1003
- **中文触发词:**
1004
- ```
1005
- 帮我爬取 https://react.dev 的文档并生成Agent Skill
768
+ # Verify
769
+ safe-coder-cli --version
1006
770
  ```
1007
771
 
1008
- ```
1009
- 使用并行爬取从 https://docs.example.com 生成技能,要快一点
1010
- ```
772
+ ### Slow Crawling
1011
773
 
1012
- ```
1013
- 递归抓取 https://nextjs.org/docs 的文档,深度优先策略
1014
- ```
774
+ - Reduce `maxPages` (e.g., 50 instead of 200)
775
+ - Decrease `depth` (e.g., 2 instead of 3)
776
+ - Increase `workers` (e.g., 3 for parallel crawling) - *requires CLI support*
1015
777
 
1016
- **英文触发词:**
1017
- ```
1018
- Crawl https://react.dev and generate an agent skill
1019
- ```
778
+ ### Cache Not Working
1020
779
 
1021
- ```
1022
- Use parallel crawling to create a skill from https://docs.example.com
1023
- ```
1024
-
1025
- ```
1026
- Recursive crawl https://nextjs.org/docs with DFS strategy
1027
- ```
1028
-
1029
- #### 步骤2:配置爬取参数
1030
-
1031
- Claude/Cursor会自动调用`crawl_documentation`工具,你可以在对话中指定参数:
1032
-
1033
- **基础爬取:**
1034
- ```
1035
- 爬取 https://react.dev/docs,最多50页
1036
- ```
780
+ ```bash
781
+ # Check cache directory
782
+ ls -la ~/.safe-coder/cache/
1037
783
 
1038
- **快速爬取(推荐):**
1039
- ```
1040
- 爬取 https://react.dev,使用5个并发worker,最多200页
1041
- ```
784
+ # Permissions issue?
785
+ chmod 755 ~/.safe-coder/cache/
1042
786
 
1043
- **深度研究:**
1044
- ```
1045
- 使用DFS策略深入爬取 https://docs.example.com,深度限制为6层
787
+ # Clear and rebuild
788
+ rm -rf ~/.safe-coder/cache/
789
+ # Cache will recreate on next crawl
1046
790
  ```
1047
791
 
1048
- **大规模爬取:**
1049
- ```
1050
- 爬取 https://large-docs.com,最多1000页,启用断点续传每50页保存
1051
- ```
792
+ ## Development
1052
793
 
1053
- ### 使用场景
794
+ ### Project Structure
1054
795
 
1055
- #### 场景1:快速探索新技术栈
1056
- ```
1057
- 帮我爬取 Svelte 的官方文档,快速生成一个技能
1058
796
  ```
797
+ safe-coder/
798
+ ├── src/
799
+ │ ├── index.ts # Entry point
800
+ │ ├── server/
801
+ │ │ └── safe-coder-mcp.ts # MCP server class
802
+ │ ├── executor/
803
+ │ │ ├── dependency-checker.ts # Check CLI installation
804
+ │ │ └── cli-executor.ts # Spawn CLI process
805
+ │ ├── processor/
806
+ │ │ ├── content-processor.ts # Analyze content
807
+ │ │ └── guide-generator.ts # Generate SKILL guidance
808
+ │ ├── cache/
809
+ │ │ └── cache-manager.ts # Cache management
810
+ │ └── tools/
811
+ │ ├── crawl-documentation.ts # Main MCP tool
812
+ │ ├── cache-tools.ts # Cache MCP tools
813
+ │ └── index.ts # Tool exports
814
+ ├── dist/ # Compiled output
815
+ ├── tsconfig.json
816
+ ├── package.json
817
+ └── README.md
818
+ ```
819
+
820
+ ### Build and Test
1059
821
 
1060
- **自动参数:**
1061
- - workers: 3(快速)
1062
- - maxPages: 50(快速探索)
1063
- - crawlStrategy: bfs(全面覆盖)
1064
-
1065
- #### 场景2:深入学习框架
1066
- ```
1067
- 深入爬取 Vue 3 的文档,我要完整理解它的 API
1068
- ```
822
+ ```bash
823
+ # Install dependencies
824
+ npm install
1069
825
 
1070
- **自动参数:**
1071
- - crawlStrategy: dfs(深入学习)
1072
- - maxDepth: 5(深入层级)
1073
- - workers: 5(加速)
1074
- - maxPages: 200(完整覆盖)
826
+ # Build
827
+ npm run build
1075
828
 
1076
- #### 场景3:大型文档站点
1077
- ```
1078
- 爬取 MDN Web Docs 的 JavaScript 部分,分多次进行,支持断点恢复
1079
- ```
829
+ # Watch mode
830
+ npm run build -- --watch
1080
831
 
1081
- **自动参数:**
1082
- - workers: 8(大规模)
1083
- - maxPages: 1000
1084
- - checkpoint: { enabled: true, interval: 50 }
832
+ # Test locally
833
+ node dist/index.js
1085
834
 
1086
- #### 场景4:恢复中断的爬取
835
+ # Test with MCP Inspector (if available)
836
+ npx @modelcontextprotocol/inspector node dist/index.js
1087
837
  ```
1088
- 上次爬取中断了,从断点继续爬取 https://large-docs.com
1089
- ```
1090
-
1091
- **自动参数:**
1092
- - resume: true
1093
- - checkpoint: { enabled: true }
1094
-
1095
- ### 生成的Agent Skill格式
1096
838
 
1097
- 爬取完成后,会生成标准的Claude Agent Skill格式:
839
+ ### Running with Debug Output
1098
840
 
1099
- ```
1100
- SKILL.md # 主技能文件
1101
- ├── 技能元数据(YAML frontmatter)
1102
- ├── When to Use This Skill # 使用场景
1103
- ├── Core Concepts # 核心概念
1104
- ├── API Reference # API参考
1105
- ├── Examples # 示例代码
1106
- └── Reference Files # 引用文件列表
1107
-
1108
- references/ # 引用文件目录
1109
- ├── page-1.md
1110
- ├── page-2.md
1111
- └── ...
841
+ ```typescript
842
+ // In src/index.ts
843
+ console.error('[Debug] MCP Server starting...');
844
+ console.error('[Debug] Available tools:', server.listTools());
1112
845
  ```
1113
846
 
1114
- ### 技能质量指标
847
+ MCP uses stdio, so:
848
+ - `stdout` → MCP protocol messages (JSON-RPC)
849
+ - `stderr` → Debug/log output (visible in Cursor logs)
1115
850
 
1116
- 系统会自动评估生成的Skill质量:
851
+ ## Roadmap / Future Enhancements
1117
852
 
1118
- | 指标 | 说明 | 优秀标准 |
1119
- |-----|-----|---------|
1120
- | **内容充足性** | 每页内容长度 | > 100字符/页 |
1121
- | **结构完整性** | 标题、章节组织 | 至少1个标题/页 |
1122
- | **内容多样性** | URL路径和主题分布 | diversity > 0.7 |
1123
- | **API覆盖度** | 代码示例比例 | coverage > 0.5 |
853
+ ### Planned Features
1124
854
 
1125
- ### 使用生成的Skill
855
+ 1. **Expose More CLI Parameters**
856
+ - [ ] `strategy` (bfs/dfs)
857
+ - [ ] `checkpoint`, `resume`
858
+ - [ ] `rateLimit`, `maxRetries`
859
+ - [ ] `includePaths`, `excludePaths`
1126
860
 
1127
- #### 方法1:直接在对话中使用
861
+ 2. **Direct File Creation Tool**
862
+ - [ ] `save_skill` tool to create SKILL.md directly
863
+ - [ ] Automatic filename generation
864
+ - [ ] Default location management
1128
865
 
1129
- 生成的Skill会自动出现在Claude的技能列表中,你可以直接引用:
866
+ 3. **Enhanced Processing**
867
+ - [ ] Semantic analysis of content
868
+ - [ ] Automatic category detection
869
+ - [ ] Code example quality scoring
870
+ - [ ] Cross-reference detection
1130
871
 
1131
- ```
1132
- 根据我刚生成的React技能,帮我写一个自定义Hook
1133
- ```
1134
-
1135
- #### 方法2:保存为文件
872
+ 4. **Better Caching**
873
+ - [ ] Configurable TTL per URL
874
+ - [ ] Cache compression
875
+ - [ ] Partial cache updates
876
+ - [ ] Cache analytics
1136
877
 
1137
- 如果指定了`outputDir`,Skill会保存为文件:
878
+ ## Contributing
1138
879
 
1139
- ```
1140
- 爬取并保存到 ./skills 目录,文件名为 react-docs
1141
- ```
880
+ This package is part of the Safe Coder project. Contributions welcome!
1142
881
 
1143
- 生成文件:
1144
- - `./skills/react-docs.md` - Skill内容
1145
- - `./skills/react-docs.metadata.json` - 元数据
882
+ ### Development Workflow
1146
883
 
1147
- #### 方法3:分享给团队
884
+ 1. Fork and clone both `safe-coder` and `safe-coder-cli`
885
+ 2. Make changes
886
+ 3. Build and test locally
887
+ 4. Submit pull request
1148
888
 
1149
- 将生成的SKILL.md文件放入项目的`.claude/skills/`目录,团队成员都可使用:
889
+ ### Testing
1150
890
 
1151
891
  ```bash
1152
- # 复制到项目技能目录
1153
- cp output/react-docs.md .claude/skills/
892
+ # Unit tests (when implemented)
893
+ npm test
1154
894
 
1155
- # 提交到版本控制
1156
- git add .claude/skills/react-docs.md
1157
- git commit -m "Add React documentation skill"
1158
- ```
895
+ # Integration test
896
+ # 1. Build both packages
897
+ cd safe-coder-cli && npm run build && npm link
898
+ cd ../safe-coder && npm run build && npm link
1159
899
 
1160
- ### 常见问题
1161
-
1162
- #### Q: 如何选择爬取策略?
1163
- **A:**
1164
- - **BFS(广度优先)**:适合扁平结构、需要全面覆盖的文档
1165
- - **DFS(深度优先)**:适合层级结构、需要深入理解的文档
1166
-
1167
- #### Q: workers设置多少合适?
1168
- **A:**
1169
- - 小型站点(<50页):workers: 2-3
1170
- - 中型站点(50-200页):workers: 3-5
1171
- - 大型站点(>200页):workers: 5-8
1172
-
1173
- #### Q: 什么时候需要启用断点?
1174
- **A:**
1175
- - 爬取页面超过200页
1176
- - 网络不稳定
1177
- - 需要分批次爬取
1178
-
1179
- #### Q: 如何提高爬取速度?
1180
- **A:**
1181
- 1. 增加workers数量(推荐5-8个)
1182
- 2. 降低rateLimit(200-300ms)
1183
- 3. 确保站点有llms.txt(自动检测)
1184
-
1185
- #### Q: 生成的Skill质量不够怎么办?
1186
- **A:**
1187
- 1. 增加maxPages(建议200+)
1188
- 2. 调整maxDepth(建议3-5)
1189
- 3. 使用includePaths精确指定路径
1190
- 4. 查看日志中的质量指标建议
1191
-
1192
- ### 性能提示
1193
-
1194
- **🚀 极速模式(适合快速探索):**
1195
- ```json
1196
- {
1197
- "workers": 5,
1198
- "maxPages": 50,
1199
- "rateLimit": 200,
1200
- "crawlStrategy": "bfs"
1201
- }
900
+ # 2. Configure in Cursor
901
+ # 3. Test end-to-end
1202
902
  ```
1203
903
 
1204
- **🎯 深度模式(适合完整学习):**
1205
- ```json
1206
- {
1207
- "workers": 5,
1208
- "maxPages": 300,
1209
- "maxDepth": 5,
1210
- "crawlStrategy": "dfs",
1211
- "checkpoint": { "enabled": true }
1212
- }
1213
- ```
904
+ ## License
1214
905
 
1215
- **⚡ 超快模式(适合有llms.txt的站点):**
1216
- ```json
1217
- {
1218
- "workers": 8,
1219
- "skipLlmsTxt": false,
1220
- "rateLimit": 200
1221
- }
1222
- ```
906
+ MIT
1223
907
 
1224
- ### 完整文档
908
+ ## Related Projects
1225
909
 
1226
- - **快速上手指南**:项目中的快速开始文档
1227
- - **详细使用说明**:`docs/ENHANCED_CRAWLING.md`
1228
- - **实施技术细节**:`IMPLEMENTATION_SUMMARY.md`
1229
- - **原始文档爬取指南**:`docs/DOC_CRAWLER_USAGE.md`
910
+ - **@gulibs/safe-coder-cli** - Standalone documentation crawler
911
+ - **Cursor** - AI-powered code editor
912
+ - **Model Context Protocol (MCP)** - Protocol for AI tool integration
1230
913
 
1231
- ---
914
+ ## Support
1232
915
 
1233
- ## 贡献
916
+ Issues: https://github.com/gulibs/safe-coder/issues
917
+ Discord: [Link TBD]
1234
918
 
1235
- 欢迎提交 Issue 和 Pull Request!
919
+ ---
1236
920
 
1237
- 基于 [Skill_Seekers](examples/Skill_Seekers/) 项目的优秀实践,我们实现了完整对标并超越的TypeScript版本。
921
+ **Safe Coder** - Bringing documentation intelligence to your AI coding assistant.