autosnippet 3.0.10 → 3.0.13

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 (56) hide show
  1. package/bin/cli.js +64 -1
  2. package/config/default.json +9 -0
  3. package/dashboard/dist/assets/{index-I2ySoCmF.js → index-Bnm26ulL.js} +47 -47
  4. package/dashboard/dist/index.html +1 -1
  5. package/lib/cli/SetupService.js +92 -5
  6. package/lib/cli/UpgradeService.js +14 -5
  7. package/lib/core/discovery/GenericDiscoverer.js +4 -28
  8. package/lib/external/mcp/handlers/bootstrap/base-dimensions.js +246 -0
  9. package/lib/external/mcp/handlers/bootstrap/pipeline/checkpoint.js +80 -0
  10. package/lib/external/mcp/handlers/bootstrap/pipeline/dimension-configs.js +275 -0
  11. package/lib/external/mcp/handlers/bootstrap/pipeline/noAiFallback.js +600 -0
  12. package/lib/external/mcp/handlers/bootstrap/pipeline/orchestrator.js +125 -342
  13. package/lib/external/mcp/handlers/bootstrap/refine.js +362 -0
  14. package/lib/external/mcp/handlers/bootstrap.js +6 -590
  15. package/lib/external/mcp/handlers/browse.js +119 -9
  16. package/lib/external/mcp/handlers/guard.js +25 -6
  17. package/lib/external/mcp/handlers/search.js +56 -24
  18. package/lib/http/routes/guardRules.js +9 -17
  19. package/lib/injection/ServiceContainer.js +12 -3
  20. package/lib/platform/ios/xcode/XcodeImportResolver.js +434 -0
  21. package/lib/platform/ios/xcode/XcodeIntegration.js +40 -659
  22. package/lib/platform/ios/xcode/XcodeWriteUtils.js +220 -0
  23. package/lib/service/chat/ChatAgent.js +39 -418
  24. package/lib/service/chat/ChatAgentPrompts.js +149 -0
  25. package/lib/service/chat/ChatAgentTasks.js +297 -0
  26. package/lib/service/chat/tools/_shared.js +61 -0
  27. package/lib/service/chat/tools/ai-analysis.js +284 -0
  28. package/lib/service/chat/tools/ast-graph.js +681 -0
  29. package/lib/service/chat/tools/composite.js +496 -0
  30. package/lib/service/chat/tools/guard.js +265 -0
  31. package/lib/service/chat/tools/index.js +250 -0
  32. package/lib/service/chat/tools/infrastructure.js +222 -0
  33. package/lib/service/chat/tools/knowledge-graph.js +234 -0
  34. package/lib/service/chat/tools/lifecycle.js +469 -0
  35. package/lib/service/chat/tools/project-access.js +923 -0
  36. package/lib/service/chat/tools/query.js +264 -0
  37. package/lib/service/chat/tools.js +14 -3994
  38. package/lib/service/cursor/AgentInstructionsGenerator.js +395 -0
  39. package/lib/service/cursor/CursorDeliveryPipeline.js +70 -11
  40. package/lib/service/cursor/FileProtection.js +116 -0
  41. package/lib/service/cursor/KnowledgeCompressor.js +61 -11
  42. package/lib/service/cursor/SkillsSyncer.js +5 -3
  43. package/lib/service/cursor/TopicClassifier.js +19 -3
  44. package/lib/service/guard/ExclusionManager.js +26 -2
  45. package/lib/service/guard/GuardCheckEngine.js +38 -370
  46. package/lib/service/guard/GuardCodeChecks.js +362 -0
  47. package/lib/service/guard/GuardCrossFileChecks.js +307 -0
  48. package/lib/service/guard/GuardPatternUtils.js +180 -0
  49. package/lib/service/guard/GuardService.js +80 -38
  50. package/lib/service/module/ModuleService.js +1 -0
  51. package/lib/service/search/SearchEngine.js +10 -2
  52. package/lib/service/wiki/WikiGenerator.js +226 -1532
  53. package/lib/service/wiki/WikiRenderers.js +1878 -0
  54. package/lib/service/wiki/WikiUtils.js +907 -0
  55. package/lib/shared/LanguageService.js +299 -0
  56. package/package.json +1 -1
@@ -0,0 +1,264 @@
1
+ /**
2
+ * query.js — 查询类工具 (6)
3
+ *
4
+ * 3. search_recipes 搜索知识库 Recipe
5
+ * 2. search_candidates 搜索候选项
6
+ * 3. get_recipe_detail 获取 Recipe 详情
7
+ * 4. get_project_stats 获取项目统计
8
+ * 5. search_knowledge RAG 语义搜索
9
+ * 6. get_related_recipes 知识图谱关联查询
10
+ */
11
+
12
+ // ────────────────────────────────────────────────────────────
13
+ // 3. search_recipes
14
+ // ────────────────────────────────────────────────────────────
15
+ export const searchRecipes = {
16
+ name: 'search_recipes',
17
+ description:
18
+ '搜索知识库中的 Recipe(代码片段/最佳实践/架构模式)。支持关键词搜索和按分类/语言/类型筛选。',
19
+ parameters: {
20
+ type: 'object',
21
+ properties: {
22
+ keyword: { type: 'string', description: '搜索关键词' },
23
+ category: {
24
+ type: 'string',
25
+ description: '分类过滤 (View/Service/Tool/Model/Network/Storage/UI/Utility)',
26
+ },
27
+ language: { type: 'string', description: '编程语言过滤 (swift/objectivec/typescript 等)' },
28
+ knowledgeType: {
29
+ type: 'string',
30
+ description: '知识类型过滤 (code-standard/code-pattern/architecture/best-practice 等)',
31
+ },
32
+ limit: { type: 'number', description: '返回数量上限,默认 10' },
33
+ },
34
+ },
35
+ handler: async (params, ctx) => {
36
+ const knowledgeService = ctx.container.get('knowledgeService');
37
+ const { keyword, category, language, knowledgeType, limit = 10 } = params;
38
+
39
+ if (keyword) {
40
+ return knowledgeService.search(keyword, { page: 1, pageSize: limit });
41
+ }
42
+
43
+ const filters = { lifecycle: 'active' };
44
+ if (category) {
45
+ filters.category = category;
46
+ }
47
+ if (language) {
48
+ filters.language = language;
49
+ }
50
+ if (knowledgeType) {
51
+ filters.knowledgeType = knowledgeType;
52
+ }
53
+
54
+ return knowledgeService.list(filters, { page: 1, pageSize: limit });
55
+ },
56
+ };
57
+
58
+ // ────────────────────────────────────────────────────────────
59
+ // 2. search_candidates
60
+ // ────────────────────────────────────────────────────────────
61
+ export const searchCandidates = {
62
+ name: 'search_candidates',
63
+ description: '搜索或列出候选项(待审核的代码片段)。支持关键词搜索和按状态/语言/分类筛选。',
64
+ parameters: {
65
+ type: 'object',
66
+ properties: {
67
+ keyword: { type: 'string', description: '搜索关键词' },
68
+ status: { type: 'string', description: '状态过滤 (pending/approved/rejected/applied)' },
69
+ language: { type: 'string', description: '编程语言过滤' },
70
+ category: { type: 'string', description: '分类过滤' },
71
+ limit: { type: 'number', description: '返回数量上限,默认 10' },
72
+ },
73
+ },
74
+ handler: async (params, ctx) => {
75
+ const knowledgeService = ctx.container.get('knowledgeService');
76
+ const { keyword, status, language, category, limit = 10 } = params;
77
+
78
+ if (keyword) {
79
+ return knowledgeService.search(keyword, { page: 1, pageSize: limit });
80
+ }
81
+
82
+ // V3: status 映射为 lifecycle
83
+ const filters = {};
84
+ if (status) {
85
+ filters.lifecycle = status;
86
+ }
87
+ if (language) {
88
+ filters.language = language;
89
+ }
90
+ if (category) {
91
+ filters.category = category;
92
+ }
93
+
94
+ return knowledgeService.list(filters, { page: 1, pageSize: limit });
95
+ },
96
+ };
97
+
98
+ // ────────────────────────────────────────────────────────────
99
+ // 3. get_recipe_detail
100
+ // ────────────────────────────────────────────────────────────
101
+ export const getRecipeDetail = {
102
+ name: 'get_recipe_detail',
103
+ description: '获取单个 Recipe 的完整详情(代码、摘要、使用指南、关系等)。',
104
+ parameters: {
105
+ type: 'object',
106
+ properties: {
107
+ recipeId: { type: 'string', description: 'Recipe ID' },
108
+ },
109
+ required: ['recipeId'],
110
+ },
111
+ handler: async (params, ctx) => {
112
+ const knowledgeService = ctx.container.get('knowledgeService');
113
+ try {
114
+ const entry = await knowledgeService.get(params.recipeId);
115
+ return typeof entry.toJSON === 'function' ? entry.toJSON() : entry;
116
+ } catch {
117
+ return { error: `Knowledge entry '${params.recipeId}' not found` };
118
+ }
119
+ },
120
+ };
121
+
122
+ // ────────────────────────────────────────────────────────────
123
+ // 4. get_project_stats
124
+ // ────────────────────────────────────────────────────────────
125
+ export const getProjectStats = {
126
+ name: 'get_project_stats',
127
+ description:
128
+ '获取项目知识库的整体统计:Recipe 数量/分类分布、候选项数量/状态分布、知识图谱节点/边数。',
129
+ parameters: { type: 'object', properties: {} },
130
+ handler: async (_params, ctx) => {
131
+ const knowledgeService = ctx.container.get('knowledgeService');
132
+ const stats = await knowledgeService.getStats();
133
+
134
+ // 尝试获取知识图谱统计
135
+ let graphStats = null;
136
+ try {
137
+ const kgService = ctx.container.get('knowledgeGraphService');
138
+ graphStats = kgService.getStats();
139
+ } catch {
140
+ /* KG not available */
141
+ }
142
+
143
+ return {
144
+ knowledge: stats,
145
+ knowledgeGraph: graphStats,
146
+ };
147
+ },
148
+ };
149
+
150
+ // ────────────────────────────────────────────────────────────
151
+ // 5. search_knowledge
152
+ // ────────────────────────────────────────────────────────────
153
+ export const searchKnowledge = {
154
+ name: 'search_knowledge',
155
+ description: 'RAG 知识库语义搜索 — 结合向量检索和关键词检索,返回与查询最相关的知识片段。',
156
+ parameters: {
157
+ type: 'object',
158
+ properties: {
159
+ query: { type: 'string', description: '搜索查询' },
160
+ topK: { type: 'number', description: '返回结果数,默认 5' },
161
+ },
162
+ required: ['query'],
163
+ },
164
+ handler: async (params, ctx) => {
165
+ const { query, topK = 5 } = params;
166
+
167
+ // 优先使用 SearchEngine(有 BM25 + 向量搜索)
168
+ try {
169
+ const searchEngine = ctx.container.get('searchEngine');
170
+ const results = await searchEngine.search(query, { limit: topK });
171
+ if (results && results.length > 0) {
172
+ const enriched = results.slice(0, topK).map((r, i) => ({
173
+ ...r,
174
+ reasoning: {
175
+ whyRelevant:
176
+ r.score != null
177
+ ? `匹配分 ${(r.score * 100).toFixed(0)}%${r.matchType ? ` (${r.matchType})` : ''}`
178
+ : '语义相关',
179
+ rank: i + 1,
180
+ },
181
+ }));
182
+ const topScore = enriched[0]?.score ?? 0;
183
+ return {
184
+ source: 'searchEngine',
185
+ results: enriched,
186
+ _meta: {
187
+ confidence: topScore > 0.7 ? 'high' : topScore > 0.3 ? 'medium' : 'low',
188
+ hint: topScore < 0.3 ? '匹配度较低,结果可能不够相关。建议尝试更具体的查询词。' : null,
189
+ },
190
+ };
191
+ }
192
+ } catch {
193
+ /* SearchEngine not available */
194
+ }
195
+
196
+ // 降级: RetrievalFunnel + 全量候选
197
+ try {
198
+ const funnel = ctx.container.get('retrievalFunnel');
199
+ const knowledgeRepo = ctx.container.get('knowledgeRepository');
200
+ const allResult = await knowledgeRepo.findWithPagination({}, { page: 1, pageSize: 500 });
201
+ const allRecipes = allResult?.items || [];
202
+
203
+ // 规范化为 funnel 输入格式
204
+ const candidates = allRecipes.map((r) => ({
205
+ id: r.id,
206
+ title: r.title,
207
+ content: r.content || r.code || '',
208
+ description: r.description || '',
209
+ language: r.language,
210
+ category: r.category,
211
+ trigger: r.trigger || '',
212
+ }));
213
+
214
+ if (candidates.length > 0) {
215
+ const results = await funnel.execute(query, candidates, {});
216
+ return { source: 'retrievalFunnel', results: results.slice(0, topK) };
217
+ }
218
+ } catch {
219
+ /* RetrievalFunnel not available */
220
+ }
221
+
222
+ return {
223
+ source: 'none',
224
+ results: [],
225
+ message: 'No search engine available',
226
+ _meta: {
227
+ confidence: 'none',
228
+ hint: '搜索引擎不可用。请确认向量索引已构建(rebuild_index)。',
229
+ },
230
+ };
231
+ },
232
+ };
233
+
234
+ // ────────────────────────────────────────────────────────────
235
+ // 6. get_related_recipes
236
+ // ────────────────────────────────────────────────────────────
237
+ export const getRelatedRecipes = {
238
+ name: 'get_related_recipes',
239
+ description: '通过知识图谱查询某个 Recipe 的关联 Recipe(requires/extends/enforces 等关系)。',
240
+ parameters: {
241
+ type: 'object',
242
+ properties: {
243
+ recipeId: { type: 'string', description: 'Recipe ID' },
244
+ relation: {
245
+ type: 'string',
246
+ description:
247
+ '关系类型过滤 (requires/extends/enforces/depends_on/inherits/implements/calls/prerequisite),不传则返回全部关系',
248
+ },
249
+ },
250
+ required: ['recipeId'],
251
+ },
252
+ handler: async (params, ctx) => {
253
+ const kgService = ctx.container.get('knowledgeGraphService');
254
+ const { recipeId, relation } = params;
255
+
256
+ if (relation) {
257
+ const edges = kgService.getRelated(recipeId, 'recipe', relation);
258
+ return { recipeId, relation, edges };
259
+ }
260
+
261
+ const edges = kgService.getEdges(recipeId, 'recipe', 'both');
262
+ return { recipeId, ...edges };
263
+ },
264
+ };