autosnippet 3.0.2 → 3.0.3

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
@@ -297,7 +297,8 @@ your-project/
297
297
  │ ├── rules/
298
298
  │ └── skills/
299
299
  └── .vscode/ # VS Code integration
300
- └── settings.json # MCP server config
300
+ ├── mcp.json # MCP server config
301
+ └── extensions.json # Recommended extensions
301
302
  ```
302
303
 
303
304
  ## Security
package/bin/mcp-server.js CHANGED
@@ -4,7 +4,18 @@
4
4
  * AutoSnippet V2 MCP Server 入口
5
5
  * 供 Cursor / VSCode Copilot MCP 配置使用
6
6
  *
7
- * 配置示例 (.cursor/mcp.json):
7
+ * VSCode 配置示例 (.vscode/mcp.json):
8
+ * {
9
+ * "servers": {
10
+ * "autosnippet": {
11
+ * "type": "stdio",
12
+ * "command": "node",
13
+ * "args": ["/path/to/v2/bin/mcp-server.js"]
14
+ * }
15
+ * }
16
+ * }
17
+ *
18
+ * Cursor 配置示例 (.cursor/mcp.json):
8
19
  * {
9
20
  * "mcpServers": {
10
21
  * "autosnippet": {
@@ -617,28 +617,25 @@ export class SetupService {
617
617
  });
618
618
  }
619
619
 
620
- /** @private VSCode settings.json → Copilot MCP */
620
+ /** @private .vscode/mcp.json → VSCode MCP (新标准格式) */
621
621
  _configureVSCodeMCP(mcpServerPath) {
622
622
  const vscodeDir = join(this.projectRoot, '.vscode');
623
- const settingsPath = join(vscodeDir, 'settings.json');
623
+ const mcpConfigPath = join(vscodeDir, 'mcp.json');
624
624
  mkdirSync(vscodeDir, { recursive: true });
625
625
 
626
- let settings = {};
627
- if (existsSync(settingsPath)) {
626
+ let config = {};
627
+ if (existsSync(mcpConfigPath)) {
628
628
  try {
629
- settings = JSON.parse(readFileSync(settingsPath, 'utf8'));
629
+ config = JSON.parse(readFileSync(mcpConfigPath, 'utf8'));
630
630
  } catch {
631
631
  /* ignore */
632
632
  }
633
633
  }
634
634
 
635
- if (!settings['github.copilot.mcp']) {
636
- settings['github.copilot.mcp'] = {};
635
+ if (!config.servers) {
636
+ config.servers = {};
637
637
  }
638
- if (!settings['github.copilot.mcp'].servers) {
639
- settings['github.copilot.mcp'].servers = {};
640
- }
641
- settings['github.copilot.mcp'].servers.autosnippet = {
638
+ config.servers.autosnippet = {
642
639
  type: 'stdio',
643
640
  command: 'node',
644
641
  args: [mcpServerPath],
@@ -648,7 +645,7 @@ export class SetupService {
648
645
  },
649
646
  };
650
647
 
651
- writeFileSync(settingsPath, JSON.stringify(settings, null, 2));
648
+ writeFileSync(mcpConfigPath, JSON.stringify(config, null, 2));
652
649
  }
653
650
 
654
651
  /** @private .cursor/mcp.json */
@@ -2,7 +2,7 @@
2
2
  * UpgradeService — IDE 集成升级服务
3
3
  *
4
4
  * 当 AutoSnippet 发布新版本后,老用户执行 `asd upgrade` 即可更新:
5
- * ① MCP 配置(.cursor/mcp.json + .vscode/settings.json)
5
+ * ① MCP 配置(.cursor/mcp.json + .vscode/mcp.json)
6
6
  * ② Cursor Skills(.cursor/skills/)
7
7
  * ③ Cursor Rules(.cursor/rules/autosnippet-conventions.mdc + autosnippet-skills.mdc)
8
8
  * ④ Copilot Instructions(.github/copilot-instructions.md)
@@ -101,26 +101,23 @@ export class UpgradeService {
101
101
  }
102
102
 
103
103
  _updateVSCodeMCP(mcpServerPath, nodePath) {
104
- const settingsPath = join(this.projectRoot, '.vscode', 'settings.json');
105
- if (!existsSync(settingsPath)) {
106
- return;
107
- }
104
+ const vscodeDir = join(this.projectRoot, '.vscode');
105
+ const mcpConfigPath = join(vscodeDir, 'mcp.json');
108
106
 
109
- let settings = {};
110
- try {
111
- settings = JSON.parse(readFileSync(settingsPath, 'utf8'));
112
- } catch {
113
- /* */
107
+ let config = {};
108
+ if (existsSync(mcpConfigPath)) {
109
+ try {
110
+ config = JSON.parse(readFileSync(mcpConfigPath, 'utf8'));
111
+ } catch {
112
+ /* */
113
+ }
114
114
  }
115
115
 
116
- if (!settings['github.copilot.mcp']) {
117
- settings['github.copilot.mcp'] = {};
118
- }
119
- if (!settings['github.copilot.mcp'].servers) {
120
- settings['github.copilot.mcp'].servers = {};
116
+ if (!config.servers) {
117
+ config.servers = {};
121
118
  }
122
119
 
123
- settings['github.copilot.mcp'].servers.autosnippet = {
120
+ config.servers.autosnippet = {
124
121
  type: 'stdio',
125
122
  command: 'node',
126
123
  args: [mcpServerPath],
@@ -130,7 +127,8 @@ export class UpgradeService {
130
127
  },
131
128
  };
132
129
 
133
- writeFileSync(settingsPath, JSON.stringify(settings, null, 2));
130
+ mkdirSync(vscodeDir, { recursive: true });
131
+ writeFileSync(mcpConfigPath, JSON.stringify(config, null, 2));
134
132
  }
135
133
 
136
134
  /* ═══ Skills ════════════════════════════════════════ */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autosnippet",
3
- "version": "3.0.2",
3
+ "version": "3.0.3",
4
4
  "description": "AutoSnippet - 连接开发者、AI 与项目知识库的工具",
5
5
  "type": "module",
6
6
  "main": "lib/bootstrap.js",
@@ -126,7 +126,7 @@ function getMcpServerPath() {
126
126
  // ============ 配置 VSCode settings.json ============
127
127
 
128
128
  function configureVSCodeSettings() {
129
- log('\n📝 配置 VSCode settings.json...', 'blue');
129
+ log('\n📝 配置 VSCode MCP 设置...', 'blue');
130
130
 
131
131
  if (isAutoSnippetRepo && !args.path) {
132
132
  log('ℹ️ 检测到在 AutoSnippet 仓库内执行,仅配置全局设置', 'yellow');
@@ -134,8 +134,8 @@ function configureVSCodeSettings() {
134
134
  }
135
135
 
136
136
  const mcpServerPath = getMcpServerPath();
137
- const mcpConfig = {
138
- name: 'autosnippet',
137
+ const mcpServerConfig = {
138
+ type: 'stdio',
139
139
  command: 'node',
140
140
  args: [mcpServerPath],
141
141
  env: {
@@ -143,71 +143,32 @@ function configureVSCodeSettings() {
143
143
  },
144
144
  };
145
145
 
146
- let globalConfigured = false;
147
- let workspaceConfigured = false;
146
+ let configured = false;
148
147
 
149
- // 全局配置
150
- if (configGlobal) {
151
- const globalSettingsPath = getVSCodeSettingsPath(true);
152
- const globalSettings = readJsonFile(globalSettingsPath, {});
153
-
154
- if (!globalSettings['github.copilot.mcp']) {
155
- globalSettings['github.copilot.mcp'] = {};
156
- }
157
- if (!globalSettings['github.copilot.mcp'].servers) {
158
- globalSettings['github.copilot.mcp'].servers = [];
159
- }
160
-
161
- const existingIndex = globalSettings['github.copilot.mcp'].servers.findIndex(
162
- (s) => s.name === 'autosnippet'
163
- );
164
-
165
- if (existingIndex >= 0) {
166
- globalSettings['github.copilot.mcp'].servers[existingIndex] = mcpConfig;
167
- } else {
168
- globalSettings['github.copilot.mcp'].servers.push(mcpConfig);
169
- }
170
-
171
- // 添加推荐的全局设置
172
- globalSettings['github.copilot.enable'] = globalSettings['github.copilot.enable'] || {};
173
- globalSettings['github.copilot.enable']['*'] = true;
174
- globalSettings['github.copilot.chat.localeOverride'] = 'zh-CN';
175
-
176
- if (writeJsonFile(globalSettingsPath, globalSettings)) {
177
- log(`✅ 全局配置完成: ${globalSettingsPath}`, 'green');
178
- globalConfigured = true;
179
- }
180
- }
181
-
182
- // 工作区配置
148
+ // 工作区配置 → .vscode/mcp.json(新标准格式)
183
149
  if (configWorkspace) {
184
- const workspaceSettingsPath = getVSCodeSettingsPath(false);
185
- const workspaceSettings = readJsonFile(workspaceSettingsPath, {});
186
-
187
- if (!workspaceSettings['github.copilot.mcp']) {
188
- workspaceSettings['github.copilot.mcp'] = {};
189
- }
190
- if (!workspaceSettings['github.copilot.mcp'].servers) {
191
- workspaceSettings['github.copilot.mcp'].servers = [];
150
+ const vscodeDir = path.join(projectPath, '.vscode');
151
+ const mcpConfigPath = path.join(vscodeDir, 'mcp.json');
152
+
153
+ let config = {};
154
+ if (fs.existsSync(mcpConfigPath)) {
155
+ try {
156
+ config = JSON.parse(fs.readFileSync(mcpConfigPath, 'utf8'));
157
+ } catch { /* ignore */ }
192
158
  }
193
159
 
194
- const existingIndex = workspaceSettings['github.copilot.mcp'].servers.findIndex(
195
- (s) => s.name === 'autosnippet'
196
- );
197
-
198
- if (existingIndex >= 0) {
199
- workspaceSettings['github.copilot.mcp'].servers[existingIndex] = mcpConfig;
200
- } else {
201
- workspaceSettings['github.copilot.mcp'].servers.push(mcpConfig);
160
+ if (!config.servers) {
161
+ config.servers = {};
202
162
  }
163
+ config.servers.autosnippet = mcpServerConfig;
203
164
 
204
- if (writeJsonFile(workspaceSettingsPath, workspaceSettings)) {
205
- log(`✅ 工作区配置完成: ${workspaceSettingsPath}`, 'green');
206
- workspaceConfigured = true;
165
+ if (writeJsonFile(mcpConfigPath, config)) {
166
+ log(`✅ 工作区 MCP 配置完成: ${mcpConfigPath}`, 'green');
167
+ configured = true;
207
168
  }
208
169
  }
209
170
 
210
- return globalConfigured || workspaceConfigured;
171
+ return configured;
211
172
  }
212
173
 
213
174
  // ============ 创建推荐扩展配置 ============
@@ -270,41 +231,18 @@ function verifyConfiguration() {
270
231
 
271
232
  log('\n🔍 验证配置...', 'blue');
272
233
 
273
- // 检查全局设置
274
- if (configGlobal) {
275
- const globalSettingsPath = getVSCodeSettingsPath(true);
276
- if (fs.existsSync(globalSettingsPath)) {
277
- const settings = readJsonFile(globalSettingsPath, {});
278
- if (settings['github.copilot.mcp']?.servers) {
279
- const hasAutosnippet = settings['github.copilot.mcp'].servers.some(
280
- (s) => s.name === 'autosnippet'
281
- );
282
- if (hasAutosnippet) {
283
- log(`✅ VSCode 全局 MCP 配置验证成功`, 'green');
284
- } else {
285
- log(`⚠️ 未在全局设置中找到 autosnippet MCP 服务器`, 'yellow');
286
- }
287
- } else {
288
- log(`⚠️ 全局设置中未找到 MCP 配置`, 'yellow');
289
- }
290
- }
291
- }
292
-
293
- // 检查工作区设置
234
+ // 检查工作区 MCP 配置(.vscode/mcp.json)
294
235
  if (configWorkspace) {
295
- const workspaceSettingsPath = getVSCodeSettingsPath(false);
296
- if (fs.existsSync(workspaceSettingsPath)) {
297
- const settings = readJsonFile(workspaceSettingsPath, {});
298
- if (settings['github.copilot.mcp']?.servers) {
299
- const hasAutosnippet = settings['github.copilot.mcp'].servers.some(
300
- (s) => s.name === 'autosnippet'
301
- );
302
- if (hasAutosnippet) {
303
- log(`✅ VSCode 工作区 MCP 配置验证成功`, 'green');
304
- } else {
305
- log(`⚠️ 未在工作区设置中找到 autosnippet MCP 服务器`, 'yellow');
306
- }
236
+ const mcpConfigPath = path.join(projectPath, '.vscode/mcp.json');
237
+ if (fs.existsSync(mcpConfigPath)) {
238
+ const config = readJsonFile(mcpConfigPath, {});
239
+ if (config.servers?.autosnippet) {
240
+ log(`✅ VSCode 工作区 MCP 配置验证成功 (.vscode/mcp.json)`, 'green');
241
+ } else {
242
+ log(`⚠️ .vscode/mcp.json 中未找到 autosnippet 服务器`, 'yellow');
307
243
  }
244
+ } else {
245
+ log(`⚠️ 未找到 .vscode/mcp.json`, 'yellow');
308
246
  }
309
247
  }
310
248
 
@@ -353,18 +291,15 @@ function printQuickStart() {
353
291
  log(` ${path.join(projectPath, '.github/copilot-instructions.md')}`, 'yellow');
354
292
 
355
293
  log('\n📝 配置位置:');
356
- if (configGlobal) {
357
- log(` 全局: ${getVSCodeSettingsPath(true)}`, 'yellow');
358
- }
359
294
  if (configWorkspace) {
360
- log(` 工作区: ${getVSCodeSettingsPath(false)}`, 'yellow');
295
+ log(` MCP: ${path.join(projectPath, '.vscode/mcp.json')}`, 'yellow');
361
296
  }
362
297
 
363
298
  log('\n💡 提示:');
364
299
  log(' - 首次配置需要重启 VSCode');
365
300
  log(' - MCP 服务器需要 Node.js 18.0+');
366
301
  log(' - Dashboard 运行在 http://localhost:3000');
367
- log(' - 可在 VSCode 设置中搜索 "copilot.mcp" 查看配置\n');
302
+ log(' - MCP 配置位于 .vscode/mcp.json(可加入版本控制共享给团队)\n');
368
303
 
369
304
  log(`${'='.repeat(60)}\n`, 'blue');
370
305
  }
@@ -64,41 +64,28 @@ if (isVSCode) {
64
64
  }
65
65
 
66
66
  function configureVSCode() {
67
- // 找到 settings.json 路径
68
- if (os.platform() === 'darwin') {
69
- settingsPath = path.join(os.homedir(), 'Library/Application Support/Code/User/settings.json');
70
- } else if (os.platform() === 'win32') {
71
- settingsPath = path.join(os.getenv('APPDATA'), 'Code/User/settings.json');
72
- } else {
73
- settingsPath = path.join(os.homedir(), '.config/Code/User/settings.json');
74
- }
67
+ // 使用 .vscode/mcp.json(VSCode 新标准格式)
68
+ const vscodeDir = path.join(projectPath, '.vscode');
69
+ const mcpConfigPath = path.join(vscodeDir, 'mcp.json');
75
70
 
76
- // 读取现有设置
77
- let settings = {};
78
- if (fs.existsSync(settingsPath)) {
71
+ // 读取现有配置
72
+ let config = {};
73
+ if (fs.existsSync(mcpConfigPath)) {
79
74
  try {
80
- const content = fs.readFileSync(settingsPath, 'utf8');
81
- settings = JSON.parse(content);
75
+ const content = fs.readFileSync(mcpConfigPath, 'utf8');
76
+ config = JSON.parse(content);
82
77
  } catch (_e) {
83
78
  // 忽略解析错误
84
79
  }
85
80
  }
86
81
 
87
- // 添加 MCP 配置
88
- if (!settings['github.copilot.mcp']) {
89
- settings['github.copilot.mcp'] = {};
90
- }
91
- if (!settings['github.copilot.mcp'].servers) {
92
- settings['github.copilot.mcp'].servers = [];
82
+ // 添加 MCP 服务器配置
83
+ if (!config.servers) {
84
+ config.servers = {};
93
85
  }
94
86
 
95
- // 检查 autosnippet 是否已存在
96
- const existingIndex = settings['github.copilot.mcp'].servers.findIndex(
97
- (s) => s.name === 'autosnippet'
98
- );
99
-
100
- const mcpConfig = {
101
- name: 'autosnippet',
87
+ config.servers.autosnippet = {
88
+ type: 'stdio',
102
89
  command: 'node',
103
90
  args: [mcpServerPath],
104
91
  env: {
@@ -106,24 +93,19 @@ function configureVSCode() {
106
93
  },
107
94
  };
108
95
 
109
- if (existingIndex >= 0) {
110
- settings['github.copilot.mcp'].servers[existingIndex] = mcpConfig;
111
- } else {
112
- settings['github.copilot.mcp'].servers.push(mcpConfig);
113
- }
114
-
115
- // 写入设置
96
+ // 写入 .vscode/mcp.json
116
97
  try {
117
- fs.mkdirSync(path.dirname(settingsPath), { recursive: true });
118
- fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2), 'utf8');
98
+ fs.mkdirSync(vscodeDir, { recursive: true });
99
+ fs.writeFileSync(mcpConfigPath, JSON.stringify(config, null, 2), 'utf8');
119
100
  if (!isQuiet) {
120
101
  }
121
102
  } catch (e) {
122
103
  if (!isQuiet) {
123
- console.error(`✗ 保存设置失败: ${e.message}`);
104
+ console.error(`✗ 保存配置失败: ${e.message}`);
124
105
  }
125
106
  process.exit(1);
126
107
  }
108
+
127
109
  }
128
110
 
129
111
  function configureCursor() {