@gulibs/safe-coder 0.0.25 → 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 (188) hide show
  1. package/README.md +682 -902
  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 -22
  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/cache.d.ts +0 -13
  50. package/dist/documentation/cache.d.ts.map +0 -1
  51. package/dist/documentation/cache.js +0 -48
  52. package/dist/documentation/cache.js.map +0 -1
  53. package/dist/documentation/checkpoint-manager.d.ts +0 -38
  54. package/dist/documentation/checkpoint-manager.d.ts.map +0 -1
  55. package/dist/documentation/checkpoint-manager.js +0 -101
  56. package/dist/documentation/checkpoint-manager.js.map +0 -1
  57. package/dist/documentation/doc-crawler.d.ts +0 -185
  58. package/dist/documentation/doc-crawler.d.ts.map +0 -1
  59. package/dist/documentation/doc-crawler.js +0 -1162
  60. package/dist/documentation/doc-crawler.js.map +0 -1
  61. package/dist/documentation/github-client.d.ts +0 -13
  62. package/dist/documentation/github-client.d.ts.map +0 -1
  63. package/dist/documentation/github-client.js +0 -90
  64. package/dist/documentation/github-client.js.map +0 -1
  65. package/dist/documentation/http-fetcher.d.ts +0 -8
  66. package/dist/documentation/http-fetcher.d.ts.map +0 -1
  67. package/dist/documentation/http-fetcher.js +0 -31
  68. package/dist/documentation/http-fetcher.js.map +0 -1
  69. package/dist/documentation/index.d.ts +0 -16
  70. package/dist/documentation/index.d.ts.map +0 -1
  71. package/dist/documentation/index.js +0 -159
  72. package/dist/documentation/index.js.map +0 -1
  73. package/dist/documentation/llms-txt/detector.d.ts +0 -31
  74. package/dist/documentation/llms-txt/detector.d.ts.map +0 -1
  75. package/dist/documentation/llms-txt/detector.js +0 -77
  76. package/dist/documentation/llms-txt/detector.js.map +0 -1
  77. package/dist/documentation/llms-txt/downloader.d.ts +0 -30
  78. package/dist/documentation/llms-txt/downloader.d.ts.map +0 -1
  79. package/dist/documentation/llms-txt/downloader.js +0 -84
  80. package/dist/documentation/llms-txt/downloader.js.map +0 -1
  81. package/dist/documentation/llms-txt/index.d.ts +0 -4
  82. package/dist/documentation/llms-txt/index.d.ts.map +0 -1
  83. package/dist/documentation/llms-txt/index.js +0 -4
  84. package/dist/documentation/llms-txt/index.js.map +0 -1
  85. package/dist/documentation/llms-txt/parser.d.ts +0 -43
  86. package/dist/documentation/llms-txt/parser.d.ts.map +0 -1
  87. package/dist/documentation/llms-txt/parser.js +0 -177
  88. package/dist/documentation/llms-txt/parser.js.map +0 -1
  89. package/dist/documentation/normalizer.d.ts +0 -6
  90. package/dist/documentation/normalizer.d.ts.map +0 -1
  91. package/dist/documentation/normalizer.js +0 -38
  92. package/dist/documentation/normalizer.js.map +0 -1
  93. package/dist/documentation/npm-client.d.ts +0 -19
  94. package/dist/documentation/npm-client.d.ts.map +0 -1
  95. package/dist/documentation/npm-client.js +0 -182
  96. package/dist/documentation/npm-client.js.map +0 -1
  97. package/dist/documentation/skill-generator.d.ts +0 -108
  98. package/dist/documentation/skill-generator.d.ts.map +0 -1
  99. package/dist/documentation/skill-generator.js +0 -642
  100. package/dist/documentation/skill-generator.js.map +0 -1
  101. package/dist/documentation/web-doc-browser.d.ts +0 -67
  102. package/dist/documentation/web-doc-browser.d.ts.map +0 -1
  103. package/dist/documentation/web-doc-browser.js +0 -555
  104. package/dist/documentation/web-doc-browser.js.map +0 -1
  105. package/dist/errors/api-validator.d.ts +0 -9
  106. package/dist/errors/api-validator.d.ts.map +0 -1
  107. package/dist/errors/api-validator.js +0 -57
  108. package/dist/errors/api-validator.js.map +0 -1
  109. package/dist/errors/contextual-analysis.d.ts +0 -14
  110. package/dist/errors/contextual-analysis.d.ts.map +0 -1
  111. package/dist/errors/contextual-analysis.js +0 -173
  112. package/dist/errors/contextual-analysis.js.map +0 -1
  113. package/dist/errors/cross-file-analyzer.d.ts +0 -16
  114. package/dist/errors/cross-file-analyzer.d.ts.map +0 -1
  115. package/dist/errors/cross-file-analyzer.js +0 -172
  116. package/dist/errors/cross-file-analyzer.js.map +0 -1
  117. package/dist/errors/eslint-integration.d.ts +0 -9
  118. package/dist/errors/eslint-integration.d.ts.map +0 -1
  119. package/dist/errors/eslint-integration.js +0 -131
  120. package/dist/errors/eslint-integration.js.map +0 -1
  121. package/dist/errors/framework-detector.d.ts +0 -10
  122. package/dist/errors/framework-detector.d.ts.map +0 -1
  123. package/dist/errors/framework-detector.js +0 -126
  124. package/dist/errors/framework-detector.js.map +0 -1
  125. package/dist/errors/index.d.ts +0 -18
  126. package/dist/errors/index.d.ts.map +0 -1
  127. package/dist/errors/index.js +0 -134
  128. package/dist/errors/index.js.map +0 -1
  129. package/dist/errors/pattern-matcher.d.ts +0 -25
  130. package/dist/errors/pattern-matcher.d.ts.map +0 -1
  131. package/dist/errors/pattern-matcher.js +0 -44
  132. package/dist/errors/pattern-matcher.js.map +0 -1
  133. package/dist/errors/patterns.d.ts +0 -11
  134. package/dist/errors/patterns.d.ts.map +0 -1
  135. package/dist/errors/patterns.js +0 -351
  136. package/dist/errors/patterns.js.map +0 -1
  137. package/dist/errors/performance-detector.d.ts +0 -11
  138. package/dist/errors/performance-detector.d.ts.map +0 -1
  139. package/dist/errors/performance-detector.js +0 -119
  140. package/dist/errors/performance-detector.js.map +0 -1
  141. package/dist/errors/runtime-detector.d.ts +0 -7
  142. package/dist/errors/runtime-detector.d.ts.map +0 -1
  143. package/dist/errors/runtime-detector.js +0 -86
  144. package/dist/errors/runtime-detector.js.map +0 -1
  145. package/dist/errors/security-detector.d.ts +0 -6
  146. package/dist/errors/security-detector.d.ts.map +0 -1
  147. package/dist/errors/security-detector.js +0 -75
  148. package/dist/errors/security-detector.js.map +0 -1
  149. package/dist/errors/typescript-integration.d.ts +0 -6
  150. package/dist/errors/typescript-integration.d.ts.map +0 -1
  151. package/dist/errors/typescript-integration.js +0 -46
  152. package/dist/errors/typescript-integration.js.map +0 -1
  153. package/dist/server/mcp-server.d.ts +0 -14
  154. package/dist/server/mcp-server.d.ts.map +0 -1
  155. package/dist/server/mcp-server.js +0 -776
  156. package/dist/server/mcp-server.js.map +0 -1
  157. package/dist/types/documentation.d.ts +0 -26
  158. package/dist/types/documentation.d.ts.map +0 -1
  159. package/dist/types/documentation.js +0 -2
  160. package/dist/types/documentation.js.map +0 -1
  161. package/dist/utils/config.d.ts +0 -21
  162. package/dist/utils/config.d.ts.map +0 -1
  163. package/dist/utils/config.js +0 -34
  164. package/dist/utils/config.js.map +0 -1
  165. package/dist/utils/http-client.d.ts +0 -17
  166. package/dist/utils/http-client.d.ts.map +0 -1
  167. package/dist/utils/http-client.js +0 -62
  168. package/dist/utils/http-client.js.map +0 -1
  169. package/dist/utils/logger.d.ts +0 -36
  170. package/dist/utils/logger.d.ts.map +0 -1
  171. package/dist/utils/logger.js +0 -128
  172. package/dist/utils/logger.js.map +0 -1
  173. package/dist/utils/rate-limiter.d.ts +0 -9
  174. package/dist/utils/rate-limiter.d.ts.map +0 -1
  175. package/dist/utils/rate-limiter.js +0 -26
  176. package/dist/utils/rate-limiter.js.map +0 -1
  177. package/dist/validation/auto-fix.d.ts +0 -15
  178. package/dist/validation/auto-fix.d.ts.map +0 -1
  179. package/dist/validation/auto-fix.js +0 -49
  180. package/dist/validation/auto-fix.js.map +0 -1
  181. package/dist/validation/index.d.ts +0 -21
  182. package/dist/validation/index.d.ts.map +0 -1
  183. package/dist/validation/index.js +0 -45
  184. package/dist/validation/index.js.map +0 -1
  185. package/dist/validation/resolution-db.d.ts +0 -15
  186. package/dist/validation/resolution-db.d.ts.map +0 -1
  187. package/dist/validation/resolution-db.js +0 -62
  188. package/dist/validation/resolution-db.js.map +0 -1
package/README.md CHANGED
@@ -1,1141 +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
- ## 安装方式
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+**
78
+ ```bash
79
+ node --version # Must be v18.0.0 or higher
80
+ ```
68
81
 
69
- ### 方式一:通过 npm 安装(推荐)
82
+ ### Step 2: Install CLI Tool (Required)
70
83
 
71
- 如果已发布到 npm:
84
+ ⚠️ **The MCP server requires `@gulibs/safe-coder-cli` to be globally installed.**
72
85
 
86
+ **Option A: From npm (after publication)**
73
87
  ```bash
74
- # 全局安装
75
- npm install -g @gulibs/safe-coder
76
-
77
- # 或者本地安装到项目
78
- npm install @gulibs/safe-coder
88
+ npm install -g @gulibs/safe-coder-cli
79
89
  ```
80
90
 
81
- ### 方式二:从源码安装
82
-
91
+ **Option B: From source (current development setup)**
83
92
  ```bash
84
- # 克隆或下载项目
85
- git clone <repository-url>
86
- cd safe-coder
87
-
88
- # 安装依赖
93
+ # Clone and build CLI
94
+ cd /path/to/safe-coder-cli
89
95
  npm install
90
-
91
- # 构建项目
92
96
  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
- **示例配置:**
97
+ npm link # Makes 'safe-coder-cli' available globally
116
98
 
117
- ```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
- }
99
+ # Verify
100
+ safe-coder-cli --version
101
+ # Output: 0.0.1
146
102
  ```
147
103
 
148
- ## 使用方法
104
+ ### Step 3: Install MCP Server
149
105
 
150
- ### 1. 运行服务器
106
+ ⚠️ **Not yet published to npm - use local installation:**
151
107
 
108
+ **Development Installation:**
152
109
  ```bash
153
- # 开发模式(使用 tsx)
154
- npm run dev
155
-
156
- # 生产模式(需要先构建)
110
+ cd /path/to/safe-coder
111
+ npm install
157
112
  npm run build
158
- npm start
159
- ```
160
-
161
- 服务器通过 stdio 运行,使用 MCP 协议进行通信。
162
-
163
- ### 2. 监控服务状态
164
-
165
- #### 查看日志
166
-
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
113
 
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
- }
114
+ # Optional: Link for global access
115
+ npm link
200
116
  ```
201
117
 
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"
118
+ ### Step 4: Configure Cursor
207
119
 
208
- 2. **查看控制台**:
209
- - 在开发者工具中切换到 "Console" 标签
210
- - MCP 服务器的日志会显示在这里
120
+ **Edit Cursor MCP configuration:**
211
121
 
212
- 3. **启用调试模式**:
213
-
214
- 在 Cursor 配置中添加:
122
+ File location: `~/Library/Application Support/Cursor/User/globalStorage/mcp.json`
215
123
 
216
124
  ```json
217
125
  {
218
126
  "mcpServers": {
219
127
  "safe-coder": {
220
- "command": "npx",
221
- "args": ["-y", "@gulibs/safe-coder"],
222
- "env": {
223
- "LOG_LEVEL": "DEBUG",
224
- "LOG_COLORS": "true"
225
- }
128
+ "command": "node",
129
+ "args": ["/absolute/path/to/safe-coder/dist/index.js"]
226
130
  }
227
131
  }
228
132
  }
229
133
  ```
230
134
 
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:添加配置
248
-
249
- 根据你的安装方式选择对应的配置:
250
-
251
- ##### 方式 A:本地开发配置(推荐,如果包未发布)
252
-
253
- 使用项目的绝对路径:
254
-
135
+ **Replace `/absolute/path/to/safe-coder`** with actual path, e.g.:
255
136
  ```json
256
137
  {
257
138
  "mcpServers": {
258
139
  "safe-coder": {
259
140
  "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
- }
141
+ "args": ["/Users/yourname/projects/mcp/safe-coder/dist/index.js"]
265
142
  }
266
143
  }
267
144
  }
268
145
  ```
269
146
 
270
- **获取你的项目路径:**
271
-
272
- ```bash
273
- # 在项目目录下运行
274
- pwd
275
- ```
276
-
277
- ##### 方式 B:通过 npm 安装(需要先发布到 npm)
278
-
279
- 如果包已发布到 npm,可以使用 npx:
280
-
147
+ **Future (after npm publication):**
281
148
  ```json
282
149
  {
283
150
  "mcpServers": {
284
151
  "safe-coder": {
285
152
  "command": "npx",
286
- "args": ["-y", "@gulibs/safe-coder"],
287
- "env": {
288
- "CACHE_TTL_MINUTES": "60",
289
- "GITHUB_TOKEN": "your_token_here"
290
- }
153
+ "args": ["-y", "@gulibs/safe-coder@latest"]
291
154
  }
292
155
  }
293
156
  }
294
157
  ```
295
158
 
296
- 或者全局安装后使用:
159
+ ### Step 5: Restart Cursor
297
160
 
298
- ```bash
299
- # 全局安装
300
- npm install -g @gulibs/safe-coder
161
+ Restart Cursor to load the MCP server.
301
162
 
302
- # 查看全局安装路径
303
- npm root -g
304
- ```
163
+ ## Usage: SKILL File Generation Workflow
305
164
 
306
- 然后配置(替换 `<global-node-modules-path>` 为实际路径):
165
+ ### ⚠️ Important: How SKILL Files Are Created
307
166
 
308
- ```json
309
- {
310
- "mcpServers": {
311
- "safe-coder": {
312
- "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
- }
318
- }
319
- }
320
- }
321
- ```
167
+ **The MCP server does NOT create `SKILL.md` files directly.** Here's the actual workflow:
322
168
 
323
- ##### 如果从源码安装:
169
+ #### What the MCP Server Returns
324
170
 
325
- 找到你安装的路径,然后配置:
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
326
175
 
327
- ```json
328
- {
329
- "mcpServers": {
330
- "safe-coder": {
331
- "command": "node",
332
- "args": ["/绝对路径/to/safe-coder/dist/index.js"],
333
- "env": {
334
- "CACHE_TTL_MINUTES": "60",
335
- "GITHUB_TOKEN": "your_token_here"
336
- }
337
- }
338
- }
339
- }
176
+ #### Where SKILL Files Are Saved
177
+
178
+ **You must explicitly tell Cursor AI where to save the file:**
179
+
180
+ ```
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]
340
188
  ```
341
189
 
342
- **获取绝对路径的方法:**
190
+ **Recommended location pattern:**
191
+ ```
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
197
+ ```
343
198
 
344
- 在项目目录下运行:
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`
345
203
 
346
- ```bash
347
- # macOS/Linux
348
- pwd
204
+ ### Complete Example Workflow
349
205
 
350
- # Windows PowerShell
351
- (Get-Location).Path
206
+ **1. Request crawl:**
207
+ ```
208
+ User: "Crawl the React documentation at https://react.dev and create a SKILL file"
209
+ ```
210
+
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
+ })
352
218
  ```
353
219
 
354
- ##### 如果使用本地项目安装(node_modules):
220
+ **3. MCP Server process:**
221
+ ```
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
231
+ ```
355
232
 
233
+ **4. MCP returns to Cursor:**
356
234
  ```json
357
235
  {
358
- "mcpServers": {
359
- "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"
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
365
263
  }
264
+ // ... 49 more pages
265
+ ],
266
+ "analysis": {
267
+ "mainTopics": ["Components", "Hooks", "State", "Props", "Effects"],
268
+ "difficulty": "intermediate",
269
+ "technicalDensity": 0.65
366
270
  }
367
- }
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"
368
325
  }
369
326
  ```
370
327
 
371
- #### 步骤 3:验证配置
372
-
373
- 1. **检查配置文件格式**:确保 JSON 格式正确,可以使用在线 JSON 验证器
374
- 2. **重启 Cursor**:保存配置后,完全重启 Cursor
375
- 3. **检查连接状态**:
376
- - 在 Cursor 设置中查看 MCP 服务器列表
377
- - 应该能看到 "safe-coder" 服务器
378
- - 状态应该显示为已连接(绿色)
379
-
380
- #### 步骤 4:测试工具
381
-
382
- 在 Cursor 的 AI 对话中测试:
383
-
328
+ **5. Tell Cursor where to save:**
384
329
  ```
385
- 请使用 get_documentation 工具获取 axios 库的文档
330
+ User: "Save this as a SKILL file at ~/.claude/skills/react-docs/SKILL.md"
386
331
  ```
387
332
 
388
- 如果工具正常工作,说明配置成功!
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
389
338
 
390
- ### 3. 使用 MCP 工具
339
+ ## MCP Tools Reference
391
340
 
392
- 配置完成后,你可以在 Cursor AI 对话中使用以下工具:
341
+ ### Tool 1: `crawl_documentation`
393
342
 
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` - 获取版本号
343
+ (**Recommended Workflow**: Use with `save_skill` for complete automation)
404
344
 
405
- #### `get_documentation` - 获取文档
345
+ Crawl documentation website and return processed data with SKILL generation guidance.
406
346
 
407
- 获取库或包的文档。
347
+ **Parameters:**
408
348
 
409
- **参数:**
410
- - `packageName`(必需):包名(npm)、仓库(owner/repo)或 URL
411
- - `version`(可选):版本或分支 / 标签
412
- - `source`(可选):源类型('npm'、'github'、'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 |
413
360
 
414
- **使用示例:**
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
415
367
 
416
- ```
417
- 请帮我获取 axios 库的文档
418
- ```
419
-
420
- 或者直接调用:
421
-
422
- ```json
368
+ **Returns:**
369
+ ```typescript
423
370
  {
424
- "packageName": "axios",
425
- "version": "latest",
426
- "source": "npm"
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;
427
397
  }
428
398
  ```
429
399
 
430
- #### `browse_documentation` - 浏览网页文档
400
+ **Example Cursor prompts:**
431
401
 
432
- 浏览和搜索网页文档页面。
402
+ ```bash
403
+ # Basic usage
404
+ "Crawl https://react.dev and create a SKILL"
433
405
 
434
- **参数:**
435
- - `url`(必需):文档 URL
436
- - `query`(可选):搜索查询词,用于过滤内容
437
- - `navigateTo`(可选):导航到文档内的其他页面
406
+ # Limit pages
407
+ "Crawl Vue.js docs but only 50 pages"
438
408
 
439
- **使用示例:**
409
+ # Force refresh
410
+ "Re-crawl React docs, ignore cache"
440
411
 
441
- ```
442
- 浏览 https://react.dev/docs/getting-started 的文档
412
+ # Use browser for SPA
413
+ "Crawl https://app.example.com with Playwright"
443
414
  ```
444
415
 
445
- ```
446
- 在 https://expressjs.com/en/guide 中查找关于路由的内容
447
- ```
416
+ ### Tool 2: `list_cached_documentation`
448
417
 
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
- ```
418
+ List all cached documentation crawl results with metadata.
492
419
 
493
- ##### 2. 并行加速爬取(推荐)
494
- ```
495
- 从 https://react.dev 生成 agent skill,使用 5 个并发worker,最多爬取 200 页
496
- ```
420
+ **Parameters:** None
497
421
 
498
- 对应参数:
499
- ```json
422
+ **Returns:**
423
+ ```typescript
500
424
  {
501
- "url": "https://react.dev",
502
- "workers": 5,
503
- "maxPages": 200,
504
- "rateLimit": 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;
505
441
  }
506
442
  ```
507
443
 
508
- ##### 3. 深度优先策略
509
- ```
510
- 使用 DFS 策略爬取 https://docs.example.com,深度限制为 6
444
+ **Example Cursor prompts:**
445
+ ```bash
446
+ "Show me all cached documentation"
447
+ "List cached docs"
448
+ "What's in the cache?"
511
449
  ```
512
450
 
513
- 对应参数:
514
- ```json
515
- {
516
- "url": "https://docs.example.com",
517
- "crawlStrategy": "dfs",
518
- "maxDepth": 6,
519
- "workers": 3
520
- }
521
- ```
451
+ ### Tool 3: `save_skill` ⭐ NEW
522
452
 
523
- ##### 4. 大规模爬取(带断点)
524
- ```
525
- 爬取 https://large-docs.com,最多 1000 页,启用断点每 50 页保存一次
526
- ```
453
+ **Save complete SKILL directory structure to filesystem.**
527
454
 
528
- 对应参数:
529
- ```json
530
- {
531
- "url": "https://large-docs.com",
532
- "maxPages": 1000,
533
- "workers": 8,
534
- "checkpoint": {
535
- "enabled": true,
536
- "interval": 50
537
- }
538
- }
539
- ```
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
540
459
 
541
- ##### 5. 恢复中断的爬取
542
- ```
543
- 从断点恢复 https://large-docs.com 的爬取
544
- ```
460
+ **Parameters:**
545
461
 
546
- 对应参数:
547
- ```json
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
548
472
  {
549
- "url": "https://large-docs.com",
550
- "resume": true,
551
- "checkpoint": { "enabled": true }
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;
552
480
  }
553
481
  ```
554
482
 
555
- **📊 性能对比:**
556
-
557
- | 爬取规模 | 串行模式 | 并行模式(workers=5) | 提升 |
558
- |---------|---------|-------------------|------|
559
- | 50页 | ~90秒 | ~22秒 | **4倍** ⚡ |
560
- | 100页 | ~180秒 | ~45秒 | **4倍** ⚡ |
561
- | 200页 | ~360秒 | ~80秒 | **4.5倍** ⚡ |
562
-
563
- **输出内容:**
564
- - `skillContent`: Markdown 格式的技能内容
565
- - `metadata`: 技能元数据(标题、描述、源 URL 等)
566
- - `crawlStats`: 爬取统计(总页数、最大深度、错误列表、质量指标)
567
- - `files`(可选):保存的文件路径
568
- - `skillFile`: SKILL.md 文件路径
569
- - `manifestFile`: metadata.json 文件路径
570
-
571
- **💡 最佳实践:**
572
- 1. **先小规模测试**:maxPages设为10-20验证效果
573
- 2. **逐步增加并发**:从workers=2开始,观察效果
574
- 3. **大规模使用断点**:超过200页建议启用checkpoint
575
- 4. **关注质量指标**:diversity和coverage应 > 0.5
576
-
577
- **📚 详细文档:**
578
- - 完整使用指南:`docs/ENHANCED_CRAWLING.md`
579
- - 快速上手:查看项目中的 `QUICKSTART_*.md` 文档
580
- - 实施细节:`IMPLEMENTATION_SUMMARY.md`
581
-
582
- #### `detect_errors` - 检测错误
583
-
584
- 检测代码中的错误和警告。
585
-
586
- **参数:**
587
- - `code`(必需):要分析的代码
588
- - `filename`(可选):用于上下文的文件名(默认:'code.ts')
589
-
590
- **使用示例:**
591
-
483
+ **Directory Structure Created:**
592
484
  ```
593
- 请检测这段代码的错误:
594
- const x = y;
595
- console.log(z);
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
596
493
  ```
597
494
 
598
- #### `validate_code` - 验证代码
599
-
600
- 验证代码并可选择自动修复常见错误。
495
+ **Example Cursor Prompts:**
601
496
 
602
- **参数:**
603
- - `code`(必需):要验证的代码
604
- - `filename`(可选):用于上下文的文件名
605
- - `autoFix`(可选):启用自动修复(默认:true)
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]"
606
503
 
607
- **使用示例:**
504
+ # Save with custom location
505
+ "Save the Vue skill to ~/my-skills/"
608
506
 
507
+ # Overwrite existing
508
+ "Update the react-docs skill with new content"
609
509
  ```
610
- 请验证并修复这段代码:
611
- function test() {
612
- return x
613
- }
614
- ```
615
-
616
- #### `resolve_error` - 解决错误
617
-
618
- 获取特定错误的解决方案建议。
619
-
620
- **参数:**
621
- - `errorType`(必需):错误类型
622
- - `message`(必需):错误消息
623
- - `line`(可选):错误发生的行号
624
510
 
625
- **使用示例:**
511
+ **Automated Workflow Example:**
626
512
 
627
513
  ```
628
- 我遇到了一个 undefined-variable 错误,消息是 "Variable 'x' is used but not defined",在第 5 行
629
- ```
630
-
631
- #### `detect_spa` - 检测单页应用
632
-
633
- 检测网站是否为需要 JavaScript 渲染的单页应用(SPA)。
634
-
635
- **参数:**
636
- - `url`(必需):要检测的 URL
637
-
638
- **使用示例:**
514
+ User: "Crawl React docs and save as a complete SKILL"
639
515
 
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
640
530
  ```
641
- 检测 https://react-dnd.github.io/react-dnd/docs 是否是 SPA
642
- ```
643
-
644
- **返回:**
645
- - `isSPA`:是否为 SPA
646
- - `confidence`:检测置信度(high/medium/low)
647
- - `indicators`:检测到的 SPA 指标
648
- - `suggestion`:建议(如果检测到 SPA)
649
-
650
- ### 4. 使用 MCP 资源
651
531
 
652
- #### `safe-coder://documentation` - 缓存的文档
532
+ ### Tool 4: `clear_cache`
653
533
 
654
- 访问缓存的文档条目,查看缓存状态。
534
+ Clear cached documentation results by pattern, all entries, or expired only.
655
535
 
656
- #### `safe-coder://error-patterns` - 错误模式数据库
536
+ **Parameters:**
657
537
 
658
- 访问错误模式数据库,查看已知的错误模式和解决方案。
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 |
659
542
 
660
- ## 开发
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)
661
547
 
662
- ### 项目结构
663
-
664
- ```
665
- safe-coder/
666
- ├── src/
667
- │ ├── documentation/ # 文档获取、缓存、爬取和技能生成
668
- │ │ ├── index.ts # 文档服务
669
- │ │ ├── web-doc-browser.ts # 网页文档浏览
670
- │ │ ├── doc-crawler.ts # 文档爬取
671
- │ │ └── skill-generator.ts # 技能生成
672
- │ ├── errors/ # 错误检测(ESLint、TypeScript、模式、上下文)
673
- │ ├── validation/ # 代码验证和自动修复
674
- │ ├── server/ # MCP 服务器实现
675
- │ ├── types/ # TypeScript 类型定义
676
- │ ├── utils/ # 配置和工具函数
677
- │ └── index.ts # 入口文件
678
- ├── tests/ # 测试文件
679
- ├── dist/ # 编译输出
680
- └── package.json
548
+ **Returns:**
549
+ ```typescript
550
+ {
551
+ success: boolean;
552
+ deletedCount: number;
553
+ message: string;
554
+ }
681
555
  ```
682
556
 
683
- ### 开发命令
684
-
557
+ **Example Cursor prompts:**
685
558
  ```bash
686
- # 安装依赖
687
- npm install
688
-
689
- # 构建项目
690
- npm run build
691
-
692
- # 开发模式运行(自动重新编译)
693
- npm run dev
694
-
695
- # 运行测试
696
- npm test
697
-
698
- # 监听模式运行测试
699
- npm run test:watch
559
+ # Clear all
560
+ "Clear all cached documentation"
700
561
 
701
- # 类型检查
702
- npm run type-check
562
+ # Clear by pattern
563
+ "Clear cache for react.dev"
564
+ "Delete cached Vue docs"
703
565
 
704
- # 代码检查
705
- npm run lint
566
+ # Clear expired only
567
+ "Clear old cached docs"
706
568
  ```
707
569
 
708
- ### 调试
570
+ ## Internal Workflow
709
571
 
710
- 如果遇到问题,可以:
572
+ ### 1. Dependency Check
711
573
 
712
- 1. **检查服务器是否正常运行**:
574
+ ```typescript
575
+ const checker = new DependencyChecker();
576
+ const check = await checker.checkCLIInstalled();
713
577
 
714
- ```bash
715
- npm run dev
716
- ```
717
-
718
- 应该看到:`Safe Coder MCP server running on stdio`
578
+ if (!check.installed) {
579
+ throw new Error(`
580
+ ⚠️ safe-coder-cli is not installed.
719
581
 
720
- 2. **查看 Cursor 的 MCP 日志**:
721
- - Cursor 中打开开发者工具
722
- - 查看控制台中的 MCP 相关错误
582
+ Please install globally:
583
+ npm install -g @gulibs/safe-coder-cli
723
584
 
724
- 3. **测试工具调用**:
725
- 可以在 Cursor 的 AI 对话中直接请求使用工具,例如:
585
+ Or from source:
586
+ cd /path/to/safe-coder-cli
587
+ npm install && npm run build && npm link
726
588
 
727
- ```
728
- 请使用 get_documentation 工具获取 react 的文档
729
- ```
730
-
731
- ## 常见问题
732
-
733
- ### Q: 服务器无法启动?
589
+ Then verify:
590
+ safe-coder-cli --version
591
+ `);
592
+ }
593
+ ```
734
594
 
735
- **A:** 检查以下几点:
736
- - 确保已运行 `npm install` 和 `npm run build`
737
- - 检查 Node.js 版本(建议 18+)
738
- - 查看错误日志
595
+ ### 2. CLI Execution
739
596
 
740
- ### Q: 无法获取 GitHub 文档?
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
+ ```
741
608
 
742
- **A:**
743
- - 如果访问私有仓库,需要设置 `GITHUB_TOKEN` 环境变量
744
- - 公开仓库通常不需要 token,但设置 token 可以提高速率限制
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
+ ])
745
618
 
746
- ### Q: 错误检测不准确?
619
+ # stdout → JSON result
620
+ # stderr → Progress messages
621
+ ```
747
622
 
748
- **A:**
749
- - 确保代码文件扩展名正确(`.ts` 用于 TypeScript,`.js` 用于 JavaScript)
750
- - 某些复杂的错误可能需要更多上下文
751
- - 可以尝试使用 `validate_code` 工具获得更全面的分析
623
+ ### 3. Content Processing
752
624
 
753
- ### Q: 如何更新错误模式数据库?
625
+ ```typescript
626
+ const processor = new ContentProcessor();
627
+ const processed = await processor.process(rawResult);
754
628
 
755
- **A:**
756
- - 编辑 `src/errors/patterns.json` 文件
757
- - 添加新的错误模式
758
- - 重新构建项目
629
+ // Extracts:
630
+ // - Key points from each page
631
+ // - Code patterns and examples
632
+ // - Content categories
633
+ // - Technical density
634
+ // - Difficulty level
635
+ ```
759
636
 
760
- ### Q: 文档爬取工具如何使用?
637
+ ### 4. SKILL Guidance Generation
761
638
 
762
- **A:**
763
- - 使用 `crawl_documentation` 工具,提供文档根 URL
764
- - 工具会自动检测文档页面,跟踪链接,生成技能
765
- - 支持配置深度和页面限制
766
- - 详见 `DOC_CRAWLER_USAGE.md`
639
+ ```typescript
640
+ const guideGenerator = new GuideGenerator();
641
+ const guide = guideGenerator.generate(processed);
767
642
 
768
- **示例:**
769
- ```
770
- 爬取 https://react.dev/docs 的文档并生成技能
643
+ // Creates:
644
+ // - Suggested SKILL structure
645
+ // - Key topics to cover
646
+ // - Recommended sections
647
+ // - Writing tips
648
+ // - Quality assessment
771
649
  ```
772
650
 
773
- ### Q: 爬取大型文档站点时需要注意什么?
651
+ ### 5. Caching
774
652
 
775
- **A:**
776
- - 使用 `maxPages` 参数限制页面数量(默认 50)
777
- - 使用 `maxDepth` 参数限制爬取深度(默认 3)
778
- - 调整 `rateLimit` 避免对服务器造成压力(默认 500ms)
779
- - 大型站点建议分多次爬取不同部分
653
+ ```typescript
654
+ const cache = new CacheManager();
780
655
 
781
- ### Q: 网页文档浏览和文档爬取有什么区别?
656
+ // Save (7-day TTL)
657
+ await cache.set(url, processed, guide);
782
658
 
783
- **A:**
784
- - **`browse_documentation`**: 浏览单个文档页面,支持查询和导航
785
- - **`crawl_documentation`**: 递归爬取多个页面,生成完整的技能文件
786
- - 浏览适合查看特定内容,爬取适合生成完整文档技能
787
-
788
- ## 发布到 npm(开发者)
789
-
790
- 如果你想将这个包发布到 npm:
659
+ // Retrieve
660
+ const cached = await cache.get(url);
661
+ if (cached && !forceRefresh) {
662
+ return cached;
663
+ }
664
+ ```
791
665
 
792
- ### 1. 准备发布
666
+ **Cache location:** `~/.safe-coder/cache/`
667
+ **Cache format:** JSON files with base64-encoded URL as filename
668
+ **TTL:** 7 days (default)
793
669
 
794
- ```bash
795
- # 确保已登录 npm
796
- npm login
670
+ ## Error Handling
797
671
 
798
- # 检查包名是否可用(如果已发布,需要更新版本号)
799
- npm view @gulibs/safe-coder
672
+ ### CLI Not Installed
800
673
 
801
- # 更新版本号
802
- npm version patch # 或 minor, major
803
674
  ```
675
+ Error: safe-coder-cli is not installed
804
676
 
805
- ### 2. 发布
677
+ Please install:
678
+ npm install -g @gulibs/safe-coder-cli
806
679
 
807
- ```bash
808
- # 发布到 npm
809
- npm publish
810
-
811
- # 如果使用作用域包且是首次发布,需要添加访问权限
812
- npm publish --access public
680
+ Current PATH checked:
681
+ /usr/local/bin
682
+ /usr/bin
683
+ /bin
684
+ ...
813
685
  ```
814
686
 
815
- ### 3. 验证发布
687
+ ### CLI Execution Failed
816
688
 
817
- ```bash
818
- # 检查包是否已发布
819
- npm view @gulibs/safe-coder
820
-
821
- # 测试安装
822
- npm install -g @gulibs/safe-coder
823
689
  ```
690
+ Error: CLI process exited with code 1
824
691
 
825
- ## 本地开发配置示例
826
-
827
- 如果你在本地开发,可以创建一个测试配置:
692
+ stderr output:
693
+ [Error] Failed to crawl: Network timeout
694
+ [Error] URL: https://example.com
828
695
 
829
- ### 创建测试配置文件
696
+ Possible solutions:
697
+ - Check network connectivity
698
+ - Try with --use-browser flag
699
+ - Increase timeout with --rate-limit
700
+ ```
830
701
 
831
- 在项目根目录创建 `cursor-mcp-config.json`:
702
+ ### Cache Errors
832
703
 
833
- ```json
834
- {
835
- "mcpServers": {
836
- "safe-coder": {
837
- "command": "node",
838
- "args": ["./dist/index.js"],
839
- "env": {
840
- "CACHE_TTL_MINUTES": "60",
841
- "GITHUB_TOKEN": ""
842
- }
843
- }
844
- }
845
- }
846
704
  ```
705
+ Warning: Failed to cache results
706
+ Error: EACCES: permission denied, mkdir '~/.safe-coder/cache'
847
707
 
848
- 然后将此配置复制到 Cursor 的配置目录。
708
+ Continuing without cache...
709
+ ```
849
710
 
850
- ### 快速测试脚本
711
+ Cache errors are non-fatal - the operation continues without caching.
851
712
 
852
- 创建 `test-mcp.sh`(macOS/Linux)或 `test-mcp.bat`(Windows):
713
+ ## Configuration
853
714
 
854
- ```bash
855
- #!/bin/bash
856
- # test-mcp.sh
715
+ ### Cache Settings
857
716
 
858
- echo "构建项目..."
859
- npm run build
717
+ Modify cache behavior by editing `src/cache/cache-manager.ts`:
860
718
 
861
- echo "测试 MCP 服务器..."
862
- 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
+ );
863
724
  ```
864
725
 
865
- ## 故障排除
726
+ ### CLI Arguments Mapping
866
727
 
867
- ### 问题: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) |
868
738
 
869
- **解决方案:**
870
- 1. 检查路径是否正确(使用绝对路径)
871
- 2. 确保 `dist/index.js` 文件存在
872
- 3. 检查 Node.js 是否在 PATH 中:`which node` 或 `where node`
739
+ ## Troubleshooting
873
740
 
874
- ### 问题:服务器启动失败
741
+ ### MCP Server Not Appearing in Cursor
875
742
 
876
- **解决方案:**
877
- 1. 检查依赖是否安装:`npm install`
878
- 2. 检查构建是否成功:`npm run build`
879
- 3. 查看错误日志
743
+ 1. **Check configuration file exists:**
744
+ ```bash
745
+ cat ~/Library/Application\ Support/Cursor/User/globalStorage/mcp.json
746
+ ```
880
747
 
881
- ### 问题:工具无法使用
748
+ 2. **Verify JSON syntax is valid**
882
749
 
883
- **解决方案:**
884
- 1. 确认服务器在 Cursor 中显示为已连接
885
- 2. 检查 Cursor 版本是否支持 MCP
886
- 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
+ ```
887
755
 
888
- ### 问题:权限错误
756
+ 4. **Restart Cursor completely**
889
757
 
890
- **解决方案:**
758
+ ### "CLI Not Found" Error
891
759
 
892
760
  ```bash
893
- # 确保 dist/index.js 有执行权限
894
- chmod +x dist/index.js
895
- ```
896
-
897
- ## 许可证
898
-
899
- MIT
900
-
901
- ## 🎓 在大模型中使用MCP Server生成Agent Skill
902
-
903
- ### 快速上手
904
-
905
- #### 步骤1:在Claude/Cursor中触发爬取
906
-
907
- **中文触发词:**
908
- ```
909
- 帮我爬取 https://react.dev 的文档并生成Agent Skill
910
- ```
761
+ # Check if CLI is in PATH
762
+ which safe-coder-cli
911
763
 
912
- ```
913
- 使用并行爬取从 https://docs.example.com 生成技能,要快一点
914
- ```
915
-
916
- ```
917
- 递归抓取 https://nextjs.org/docs 的文档,深度优先策略
918
- ```
764
+ # If not found, reinstall
765
+ cd /path/to/safe-coder-cli
766
+ npm link
919
767
 
920
- **英文触发词:**
921
- ```
922
- Crawl https://react.dev and generate an agent skill
768
+ # Verify
769
+ safe-coder-cli --version
923
770
  ```
924
771
 
925
- ```
926
- Use parallel crawling to create a skill from https://docs.example.com
927
- ```
772
+ ### Slow Crawling
928
773
 
929
- ```
930
- Recursive crawl https://nextjs.org/docs with DFS strategy
931
- ```
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*
932
777
 
933
- #### 步骤2:配置爬取参数
778
+ ### Cache Not Working
934
779
 
935
- Claude/Cursor会自动调用`crawl_documentation`工具,你可以在对话中指定参数:
780
+ ```bash
781
+ # Check cache directory
782
+ ls -la ~/.safe-coder/cache/
936
783
 
937
- **基础爬取:**
938
- ```
939
- 爬取 https://react.dev/docs,最多50页
940
- ```
784
+ # Permissions issue?
785
+ chmod 755 ~/.safe-coder/cache/
941
786
 
942
- **快速爬取(推荐):**
943
- ```
944
- 爬取 https://react.dev,使用5个并发worker,最多200页
787
+ # Clear and rebuild
788
+ rm -rf ~/.safe-coder/cache/
789
+ # Cache will recreate on next crawl
945
790
  ```
946
791
 
947
- **深度研究:**
948
- ```
949
- 使用DFS策略深入爬取 https://docs.example.com,深度限制为6层
950
- ```
951
-
952
- **大规模爬取:**
953
- ```
954
- 爬取 https://large-docs.com,最多1000页,启用断点续传每50页保存
955
- ```
792
+ ## Development
956
793
 
957
- ### 使用场景
794
+ ### Project Structure
958
795
 
959
- #### 场景1:快速探索新技术栈
960
- ```
961
- 帮我爬取 Svelte 的官方文档,快速生成一个技能
962
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
963
821
 
964
- **自动参数:**
965
- - workers: 3(快速)
966
- - maxPages: 50(快速探索)
967
- - crawlStrategy: bfs(全面覆盖)
822
+ ```bash
823
+ # Install dependencies
824
+ npm install
968
825
 
969
- #### 场景2:深入学习框架
970
- ```
971
- 深入爬取 Vue 3 的文档,我要完整理解它的 API
972
- ```
826
+ # Build
827
+ npm run build
973
828
 
974
- **自动参数:**
975
- - crawlStrategy: dfs(深入学习)
976
- - maxDepth: 5(深入层级)
977
- - workers: 5(加速)
978
- - maxPages: 200(完整覆盖)
829
+ # Watch mode
830
+ npm run build -- --watch
979
831
 
980
- #### 场景3:大型文档站点
981
- ```
982
- 爬取 MDN Web Docs 的 JavaScript 部分,分多次进行,支持断点恢复
983
- ```
984
-
985
- **自动参数:**
986
- - workers: 8(大规模)
987
- - maxPages: 1000
988
- - checkpoint: { enabled: true, interval: 50 }
832
+ # Test locally
833
+ node dist/index.js
989
834
 
990
- #### 场景4:恢复中断的爬取
991
- ```
992
- 上次爬取中断了,从断点继续爬取 https://large-docs.com
835
+ # Test with MCP Inspector (if available)
836
+ npx @modelcontextprotocol/inspector node dist/index.js
993
837
  ```
994
838
 
995
- **自动参数:**
996
- - resume: true
997
- - checkpoint: { enabled: true }
998
-
999
- ### 生成的Agent Skill格式
1000
-
1001
- 爬取完成后,会生成标准的Claude Agent Skill格式:
839
+ ### Running with Debug Output
1002
840
 
1003
- ```
1004
- SKILL.md # 主技能文件
1005
- ├── 技能元数据(YAML frontmatter)
1006
- ├── When to Use This Skill # 使用场景
1007
- ├── Core Concepts # 核心概念
1008
- ├── API Reference # API参考
1009
- ├── Examples # 示例代码
1010
- └── Reference Files # 引用文件列表
1011
-
1012
- references/ # 引用文件目录
1013
- ├── page-1.md
1014
- ├── page-2.md
1015
- └── ...
841
+ ```typescript
842
+ // In src/index.ts
843
+ console.error('[Debug] MCP Server starting...');
844
+ console.error('[Debug] Available tools:', server.listTools());
1016
845
  ```
1017
846
 
1018
- ### 技能质量指标
847
+ MCP uses stdio, so:
848
+ - `stdout` → MCP protocol messages (JSON-RPC)
849
+ - `stderr` → Debug/log output (visible in Cursor logs)
1019
850
 
1020
- 系统会自动评估生成的Skill质量:
851
+ ## Roadmap / Future Enhancements
1021
852
 
1022
- | 指标 | 说明 | 优秀标准 |
1023
- |-----|-----|---------|
1024
- | **内容充足性** | 每页内容长度 | > 100字符/页 |
1025
- | **结构完整性** | 标题、章节组织 | 至少1个标题/页 |
1026
- | **内容多样性** | URL路径和主题分布 | diversity > 0.7 |
1027
- | **API覆盖度** | 代码示例比例 | coverage > 0.5 |
853
+ ### Planned Features
1028
854
 
1029
- ### 使用生成的Skill
855
+ 1. **Expose More CLI Parameters**
856
+ - [ ] `strategy` (bfs/dfs)
857
+ - [ ] `checkpoint`, `resume`
858
+ - [ ] `rateLimit`, `maxRetries`
859
+ - [ ] `includePaths`, `excludePaths`
1030
860
 
1031
- #### 方法1:直接在对话中使用
861
+ 2. **Direct File Creation Tool**
862
+ - [ ] `save_skill` tool to create SKILL.md directly
863
+ - [ ] Automatic filename generation
864
+ - [ ] Default location management
1032
865
 
1033
- 生成的Skill会自动出现在Claude的技能列表中,你可以直接引用:
866
+ 3. **Enhanced Processing**
867
+ - [ ] Semantic analysis of content
868
+ - [ ] Automatic category detection
869
+ - [ ] Code example quality scoring
870
+ - [ ] Cross-reference detection
1034
871
 
1035
- ```
1036
- 根据我刚生成的React技能,帮我写一个自定义Hook
1037
- ```
872
+ 4. **Better Caching**
873
+ - [ ] Configurable TTL per URL
874
+ - [ ] Cache compression
875
+ - [ ] Partial cache updates
876
+ - [ ] Cache analytics
1038
877
 
1039
- #### 方法2:保存为文件
878
+ ## Contributing
1040
879
 
1041
- 如果指定了`outputDir`,Skill会保存为文件:
880
+ This package is part of the Safe Coder project. Contributions welcome!
1042
881
 
1043
- ```
1044
- 爬取并保存到 ./skills 目录,文件名为 react-docs
1045
- ```
1046
-
1047
- 生成文件:
1048
- - `./skills/react-docs.md` - Skill内容
1049
- - `./skills/react-docs.metadata.json` - 元数据
882
+ ### Development Workflow
1050
883
 
1051
- #### 方法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
1052
888
 
1053
- 将生成的SKILL.md文件放入项目的`.claude/skills/`目录,团队成员都可使用:
889
+ ### Testing
1054
890
 
1055
891
  ```bash
1056
- # 复制到项目技能目录
1057
- cp output/react-docs.md .claude/skills/
892
+ # Unit tests (when implemented)
893
+ npm test
1058
894
 
1059
- # 提交到版本控制
1060
- git add .claude/skills/react-docs.md
1061
- git commit -m "Add React documentation skill"
1062
- ```
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
1063
899
 
1064
- ### 常见问题
1065
-
1066
- #### Q: 如何选择爬取策略?
1067
- **A:**
1068
- - **BFS(广度优先)**:适合扁平结构、需要全面覆盖的文档
1069
- - **DFS(深度优先)**:适合层级结构、需要深入理解的文档
1070
-
1071
- #### Q: workers设置多少合适?
1072
- **A:**
1073
- - 小型站点(<50页):workers: 2-3
1074
- - 中型站点(50-200页):workers: 3-5
1075
- - 大型站点(>200页):workers: 5-8
1076
-
1077
- #### Q: 什么时候需要启用断点?
1078
- **A:**
1079
- - 爬取页面超过200页
1080
- - 网络不稳定
1081
- - 需要分批次爬取
1082
-
1083
- #### Q: 如何提高爬取速度?
1084
- **A:**
1085
- 1. 增加workers数量(推荐5-8个)
1086
- 2. 降低rateLimit(200-300ms)
1087
- 3. 确保站点有llms.txt(自动检测)
1088
-
1089
- #### Q: 生成的Skill质量不够怎么办?
1090
- **A:**
1091
- 1. 增加maxPages(建议200+)
1092
- 2. 调整maxDepth(建议3-5)
1093
- 3. 使用includePaths精确指定路径
1094
- 4. 查看日志中的质量指标建议
1095
-
1096
- ### 性能提示
1097
-
1098
- **🚀 极速模式(适合快速探索):**
1099
- ```json
1100
- {
1101
- "workers": 5,
1102
- "maxPages": 50,
1103
- "rateLimit": 200,
1104
- "crawlStrategy": "bfs"
1105
- }
900
+ # 2. Configure in Cursor
901
+ # 3. Test end-to-end
1106
902
  ```
1107
903
 
1108
- **🎯 深度模式(适合完整学习):**
1109
- ```json
1110
- {
1111
- "workers": 5,
1112
- "maxPages": 300,
1113
- "maxDepth": 5,
1114
- "crawlStrategy": "dfs",
1115
- "checkpoint": { "enabled": true }
1116
- }
1117
- ```
904
+ ## License
1118
905
 
1119
- **⚡ 超快模式(适合有llms.txt的站点):**
1120
- ```json
1121
- {
1122
- "workers": 8,
1123
- "skipLlmsTxt": false,
1124
- "rateLimit": 200
1125
- }
1126
- ```
906
+ MIT
1127
907
 
1128
- ### 完整文档
908
+ ## Related Projects
1129
909
 
1130
- - **快速上手指南**:项目中的快速开始文档
1131
- - **详细使用说明**:`docs/ENHANCED_CRAWLING.md`
1132
- - **实施技术细节**:`IMPLEMENTATION_SUMMARY.md`
1133
- - **原始文档爬取指南**:`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
1134
913
 
1135
- ---
914
+ ## Support
1136
915
 
1137
- ## 贡献
916
+ Issues: https://github.com/gulibs/safe-coder/issues
917
+ Discord: [Link TBD]
1138
918
 
1139
- 欢迎提交 Issue 和 Pull Request!
919
+ ---
1140
920
 
1141
- 基于 [Skill_Seekers](examples/Skill_Seekers/) 项目的优秀实践,我们实现了完整对标并超越的TypeScript版本。
921
+ **Safe Coder** - Bringing documentation intelligence to your AI coding assistant.