autosnippet 2.8.0 → 2.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  **Project Knowledge Engine for iOS / Swift Teams**
6
6
 
7
7
  将团队的代码模式、最佳实践沉淀为 AI 可检索的知识库,<br>
8
- 让 Cursor、Copilot 和 Xcode 都按你的项目规范生成代码。
8
+ 让 Cursor、Trae、Copilot 和 Xcode 都按你的项目规范生成代码。
9
9
 
10
10
  [![npm version](https://img.shields.io/npm/v/autosnippet.svg?style=flat-square)](https://www.npmjs.com/package/autosnippet)
11
11
  [![License](https://img.shields.io/npm/l/autosnippet.svg?style=flat-square)](https://github.com/GxFn/AutoSnippet/blob/main/LICENSE)
@@ -24,7 +24,7 @@ AI 编码助手生成的代码往往脱离项目上下文——不知道团队
24
24
 
25
25
  ┌───────────────────────────────────────┘
26
26
 
27
- Cursor / Copilot / Xcode ──→ 按规范生成代码
27
+ Cursor / Trae / Copilot / Xcode ──→ 按规范生成代码
28
28
  ```
29
29
 
30
30
  ## 核心概念
@@ -131,6 +131,10 @@ AutoSnippet 为 Cursor 提供完整的 MCP + Skills 集成:
131
131
  asd install:cursor-skill --mcp # 安装 Skills + MCP 配置
132
132
  ```
133
133
 
134
+ ### Trae
135
+
136
+ Trae 支持 MCP 协议,MCP 配置格式与 Cursor 兼容——安装 Cursor 集成后即可在 Trae 中使用相同的 MCP 工具与 Skills。
137
+
134
138
  ### VSCode Copilot
135
139
 
136
140
  ```bash
package/bin/api-server.js CHANGED
@@ -24,6 +24,12 @@ async function main() {
24
24
 
25
25
  // 配置路径安全守卫 — 阻止写操作逃逸到项目外
26
26
  const projectRoot = process.env.ASD_PROJECT_DIR || process.cwd();
27
+
28
+ // 切换工作目录到项目根 — 确保 DB 等相对路径正确解析
29
+ if (projectRoot !== process.cwd()) {
30
+ process.chdir(projectRoot);
31
+ }
32
+
27
33
  Bootstrap.configurePathGuard(projectRoot);
28
34
 
29
35
  // 初始化应用程序引导
package/bin/cli.js CHANGED
@@ -605,6 +605,11 @@ async function initBootstrap() {
605
605
  async function initContainer(opts = {}) {
606
606
  const projectRoot = opts.projectRoot || process.cwd();
607
607
 
608
+ // 切换工作目录到项目根 — 确保 DB 等相对路径正确解析
609
+ if (resolve(projectRoot) !== resolve(process.cwd())) {
610
+ process.chdir(projectRoot);
611
+ }
612
+
608
613
  // 配置路径安全守卫 — 阻止写操作逃逸到项目外
609
614
  const { default: Bootstrap } = await import('../lib/bootstrap.js');
610
615
  Bootstrap.configurePathGuard(projectRoot);
@@ -54,6 +54,12 @@ export class McpServer {
54
54
 
55
55
  // 路径安全守卫 — 在任何写操作前配置
56
56
  const projectRoot = process.env.ASD_PROJECT_DIR || process.cwd();
57
+
58
+ // 切换工作目录到项目根 — 确保 DB 等相对路径正确解析
59
+ if (projectRoot !== process.cwd()) {
60
+ process.chdir(projectRoot);
61
+ }
62
+
57
63
  Bootstrap.configurePathGuard(projectRoot);
58
64
 
59
65
  this.bootstrap = new Bootstrap();
@@ -22,7 +22,7 @@ const MAX_BATCH_SIZE = 100;
22
22
  router.get('/', asyncHandler(async (req, res) => {
23
23
  const { status, language, category, keyword } = req.query;
24
24
  const page = safeInt(req.query.page, 1);
25
- const pageSize = safeInt(req.query.limit, 20, 1, 100);
25
+ const pageSize = safeInt(req.query.limit, 20, 1, 1000);
26
26
 
27
27
  const container = getServiceContainer();
28
28
  const candidateService = container.get('candidateService');
@@ -9,6 +9,9 @@ const __dirname = path.dirname(__filename);
9
9
 
10
10
  /**
11
11
  * DatabaseConnection - 数据库连接管理器
12
+ *
13
+ * 重要:相对 DB 路径通过 projectRoot 解析,而非 process.cwd()。
14
+ * 这样即使 MCP 服务器的 cwd 不是项目目录,DB 也不会创建到项目外。
12
15
  */
13
16
  export class DatabaseConnection {
14
17
  constructor(config) {
@@ -22,8 +25,14 @@ export class DatabaseConnection {
22
25
  async connect() {
23
26
  const dbPath = this.config.path;
24
27
 
28
+ // 使用 projectRoot(PathGuard 已配置)优先解析相对路径,
29
+ // 而非 path.resolve()(依赖 cwd,MCP 场景下 cwd 可能是用户主目录)
30
+ const projectRoot = pathGuard.projectRoot;
31
+ const resolvedDbPath = (projectRoot && !path.isAbsolute(dbPath))
32
+ ? path.resolve(projectRoot, dbPath)
33
+ : path.resolve(dbPath);
34
+
25
35
  // 路径安全检查 — 防止 DB 文件创建到项目允许范围外
26
- const resolvedDbPath = path.resolve(dbPath);
27
36
  pathGuard.assertProjectWriteSafe(resolvedDbPath);
28
37
 
29
38
  // 确保数据目录存在
@@ -32,7 +41,7 @@ export class DatabaseConnection {
32
41
  fs.mkdirSync(dbDir, { recursive: true });
33
42
  }
34
43
 
35
- this.db = new Database(dbPath, {
44
+ this.db = new Database(resolvedDbPath, {
36
45
  verbose: this.config.verbose ? (msg) => process.stderr.write(`[SQL] ${msg}\n`) : null,
37
46
  });
38
47
 
@@ -104,11 +104,11 @@ class PathGuard {
104
104
  this.#packageRoot = packageRoot ? path.resolve(packageRoot) : null;
105
105
  this.#knowledgeBaseDir = knowledgeBaseDir || null; // 延迟解析
106
106
 
107
- // 默认白名单:Xcode snippets 目录、全局缓存
107
+ // 默认白名单:Xcode snippets 目录、全局缓存(cache 子目录,不含整个 ~/.autosnippet)
108
108
  const HOME = process.env.HOME || process.env.USERPROFILE || '';
109
109
  if (HOME) {
110
110
  this.#allowList.add(path.join(HOME, 'Library/Developer/Xcode/UserData/CodeSnippets'));
111
- this.#allowList.add(path.join(HOME, '.autosnippet'));
111
+ this.#allowList.add(path.join(HOME, '.autosnippet', 'cache'));
112
112
  }
113
113
 
114
114
  // 用户自定义白名单
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autosnippet",
3
- "version": "2.8.0",
3
+ "version": "2.8.2",
4
4
  "description": "AutoSnippet - 连接开发者、AI 与项目知识库的工具",
5
5
  "type": "module",
6
6
  "main": "lib/bootstrap.js",
@@ -1,4 +1,3 @@
1
- ```skill
2
1
  ---
3
2
  name: autosnippet-coldstart
4
3
  description: Cold-start knowledge base initialization. Full 9-dimension analysis workflow — works with both external Agent and internal AI. Call bootstrap_knowledge, then systematically analyze code and submit candidates.
@@ -465,4 +464,3 @@ description: Cold-start knowledge base initialization. Full 9-dimension analysis
465
464
  - **autosnippet-reference-swift**: Swift 业界最佳实践参考(命名/并发/错误处理/内存/设计模式)
466
465
  - **autosnippet-reference-objc**: Objective-C 业界最佳实践参考(ARC/Block/Delegate/Prefix/GCD)
467
466
  - **autosnippet-reference-jsts**: JavaScript/TypeScript 业界最佳实践参考(async/React/Node/ESM/类型系统)
468
- ```
@@ -1,4 +1,3 @@
1
- ```skill
2
1
  ---
3
2
  name: autosnippet-reference-jsts
4
3
  description: JavaScript/TypeScript 业界最佳实践参考。涵盖类型系统、模块化、错误处理、async/await、命名、ESLint 规则,为冷启动分析提供高质量参考标准。
@@ -437,4 +436,3 @@ const url = baseUrl + '/api/v' + version + '/users/' + userId;
437
436
  - **autosnippet-coldstart**: 完整冷启动流程(本 Skill 的主 Skill)
438
437
  - **autosnippet-reference-swift**: Swift 业界最佳实践参考
439
438
  - **autosnippet-reference-objc**: Objective-C 业界最佳实践参考
440
- ```
@@ -1,4 +1,3 @@
1
- ```skill
2
1
  ---
3
2
  name: autosnippet-reference-objc
4
3
  description: Objective-C 业界最佳实践参考。涵盖命名前缀、属性声明、Delegate 模式、内存管理、nullability、错误处理,为冷启动分析提供高质量参考标准。
@@ -424,4 +423,3 @@ if ([NSThread isMainThread]) {
424
423
  - **autosnippet-coldstart**: 完整冷启动流程(本 Skill 的主 Skill)
425
424
  - **autosnippet-reference-swift**: Swift 业界最佳实践参考
426
425
  - **autosnippet-reference-jsts**: JavaScript/TypeScript 业界最佳实践参考
427
- ```
@@ -1,4 +1,3 @@
1
- ```skill
2
1
  ---
3
2
  name: autosnippet-reference-swift
4
3
  description: Swift 业界最佳实践参考。涵盖命名规范、Swift Concurrency、SwiftUI 模式、错误处理、内存管理、设计模式,为冷启动分析提供高质量参考标准。
@@ -458,4 +457,3 @@ UIView.animate(
458
457
  - **autosnippet-coldstart**: 完整冷启动流程(本 Skill 的主 Skill)
459
458
  - **autosnippet-reference-objc**: Objective-C 业界最佳实践参考
460
459
  - **autosnippet-reference-jsts**: JavaScript/TypeScript 业界最佳实践参考
461
- ```