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,265 @@
1
+ /**
2
+ * guard.js — Guard 安全类工具 (6)
3
+ *
4
+ * 7b. list_guard_rules 列出 Guard 规则
5
+ * 8b. get_recommendations 获取推荐 Recipe
6
+ * 12. ai_translate AI 翻译
7
+ * 13. guard_check_code Guard 检查代码
8
+ * 14. query_violations 查询违规历史
9
+ * 15. generate_guard_rule AI 生成 Guard 规则
10
+ */
11
+
12
+ // ────────────────────────────────────────────────────────────
13
+ // 7b. list_guard_rules
14
+ // ────────────────────────────────────────────────────────────
15
+ export const listGuardRules = {
16
+ name: 'list_guard_rules',
17
+ description: '列出所有 Guard 规则(boundary-constraint 类型的 Recipe)。支持按语言/状态过滤。',
18
+ parameters: {
19
+ type: 'object',
20
+ properties: {
21
+ language: { type: 'string', description: '按语言过滤 (swift/objc 等)' },
22
+ includeBuiltIn: { type: 'boolean', description: '是否包含内置规则,默认 true' },
23
+ limit: { type: 'number', description: '返回数量上限,默认 50' },
24
+ },
25
+ },
26
+ handler: async (params, ctx) => {
27
+ const { language, includeBuiltIn = true, limit = 50 } = params;
28
+ const results = [];
29
+
30
+ // 数据库自定义规则
31
+ try {
32
+ const guardService = ctx.container.get('guardService');
33
+ const dbRules = await guardService.listRules({}, { page: 1, pageSize: limit });
34
+ results.push(...(dbRules.data || dbRules.items || []));
35
+ } catch {
36
+ /* not available */
37
+ }
38
+
39
+ // 内置规则
40
+ if (includeBuiltIn) {
41
+ try {
42
+ const guardCheckEngine = ctx.container.get('guardCheckEngine');
43
+ const builtIn = guardCheckEngine
44
+ .getRules(language || null)
45
+ .filter((r) => r.source === 'built-in');
46
+ results.push(...builtIn);
47
+ } catch {
48
+ /* not available */
49
+ }
50
+ }
51
+
52
+ return { total: results.length, rules: results.slice(0, limit) };
53
+ },
54
+ };
55
+
56
+ // ────────────────────────────────────────────────────────────
57
+ // 8b. get_recommendations
58
+ // ────────────────────────────────────────────────────────────
59
+ export const getRecommendations = {
60
+ name: 'get_recommendations',
61
+ description: '获取推荐的 Recipe 列表(基于使用频率和质量排序)。',
62
+ parameters: {
63
+ type: 'object',
64
+ properties: {
65
+ limit: { type: 'number', description: '返回数量,默认 10' },
66
+ },
67
+ },
68
+ handler: async (params, ctx) => {
69
+ const knowledgeService = ctx.container.get('knowledgeService');
70
+ // V3: 推荐 = 活跃条目按使用量排序
71
+ return knowledgeService.list(
72
+ { lifecycle: 'active' },
73
+ { page: 1, pageSize: params.limit || 10 }
74
+ );
75
+ },
76
+ };
77
+
78
+ // ────────────────────────────────────────────────────────────
79
+ // 12. ai_translate
80
+ // ────────────────────────────────────────────────────────────
81
+ export const aiTranslate = {
82
+ name: 'ai_translate',
83
+ description: 'AI 翻译 — 将中文 summary/usageGuide 翻译为英文。',
84
+ parameters: {
85
+ type: 'object',
86
+ properties: {
87
+ summary: { type: 'string', description: '中文摘要' },
88
+ usageGuide: { type: 'string', description: '中文使用指南' },
89
+ },
90
+ },
91
+ handler: async (params, ctx) => {
92
+ if (!ctx.aiProvider) {
93
+ return { error: 'AI provider not available' };
94
+ }
95
+ const { summary, usageGuide } = params;
96
+ if (!summary && !usageGuide) {
97
+ return { summaryEn: '', usageGuideEn: '' };
98
+ }
99
+
100
+ const systemPrompt =
101
+ 'You are a technical translator. Translate from Chinese to English. Keep technical terms unchanged. Return ONLY valid JSON: { "summaryEn": "...", "usageGuideEn": "..." }.';
102
+ const parts = [];
103
+ if (summary) {
104
+ parts.push(`summary: ${summary}`);
105
+ }
106
+ if (usageGuide) {
107
+ parts.push(`usageGuide: ${usageGuide}`);
108
+ }
109
+
110
+ const parsed = await ctx.aiProvider.chatWithStructuredOutput(parts.join('\n'), {
111
+ systemPrompt,
112
+ temperature: 0.2,
113
+ });
114
+ return parsed || { summaryEn: summary || '', usageGuideEn: usageGuide || '' };
115
+ },
116
+ };
117
+
118
+ // ────────────────────────────────────────────────────────────
119
+ // 13. guard_check_code
120
+ // ────────────────────────────────────────────────────────────
121
+ export const guardCheckCode = {
122
+ name: 'guard_check_code',
123
+ description: '对代码运行 Guard 规则检查,返回违规列表(支持内置规则 + 数据库自定义规则)。',
124
+ parameters: {
125
+ type: 'object',
126
+ properties: {
127
+ code: { type: 'string', description: '待检查的源代码' },
128
+ language: { type: 'string', description: '编程语言 (swift/objc/javascript 等)' },
129
+ scope: { type: 'string', description: '检查范围 (file/target/project),默认 file' },
130
+ },
131
+ required: ['code'],
132
+ },
133
+ handler: async (params, ctx) => {
134
+ const { code, language, scope = 'file' } = params;
135
+
136
+ // 优先用 GuardCheckEngine(内置 + DB 规则)
137
+ try {
138
+ const engine = ctx.container.get('guardCheckEngine');
139
+ const violations = engine.checkCode(code, language || 'unknown', { scope });
140
+ // reasoning 已由 GuardCheckEngine.checkCode() 内置附加
141
+ return { violationCount: violations.length, violations };
142
+ } catch {
143
+ /* not available */
144
+ }
145
+
146
+ // 降级到 GuardService.checkCode(仅 DB 规则)
147
+ try {
148
+ const guardService = ctx.container.get('guardService');
149
+ const matches = await guardService.checkCode(code, { language });
150
+ return { violationCount: matches.length, violations: matches };
151
+ } catch (err) {
152
+ return { error: err.message };
153
+ }
154
+ },
155
+ };
156
+
157
+ // ────────────────────────────────────────────────────────────
158
+ // 14. query_violations
159
+ // ────────────────────────────────────────────────────────────
160
+ export const queryViolations = {
161
+ name: 'query_violations',
162
+ description: '查询 Guard 违规历史记录和统计。',
163
+ parameters: {
164
+ type: 'object',
165
+ properties: {
166
+ file: { type: 'string', description: '按文件路径过滤' },
167
+ limit: { type: 'number', description: '返回数量,默认 20' },
168
+ statsOnly: { type: 'boolean', description: '仅返回统计数据,默认 false' },
169
+ },
170
+ },
171
+ handler: async (params, ctx) => {
172
+ const { file, limit = 20, statsOnly = false } = params;
173
+ const store = ctx.container.get('violationsStore');
174
+
175
+ if (statsOnly) {
176
+ return store.getStats();
177
+ }
178
+
179
+ if (file) {
180
+ return { runs: store.getRunsByFile(file) };
181
+ }
182
+
183
+ return store.list({}, { page: 1, limit });
184
+ },
185
+ };
186
+
187
+ // ────────────────────────────────────────────────────────────
188
+ // 15. generate_guard_rule
189
+ // ────────────────────────────────────────────────────────────
190
+ export const generateGuardRule = {
191
+ name: 'generate_guard_rule',
192
+ description: 'AI 生成 Guard 规则 — 描述你想阻止的代码模式,AI 自动生成正则表达式和规则定义。',
193
+ parameters: {
194
+ type: 'object',
195
+ properties: {
196
+ description: {
197
+ type: 'string',
198
+ description: '规则描述(例如 "禁止在主线程使用同步网络请求")',
199
+ },
200
+ language: { type: 'string', description: '目标语言 (swift/objc 等)' },
201
+ severity: { type: 'string', description: '严重程度 (error/warning/info),默认 warning' },
202
+ autoCreate: { type: 'boolean', description: '是否自动创建到数据库,默认 false' },
203
+ },
204
+ required: ['description'],
205
+ },
206
+ handler: async (params, ctx) => {
207
+ if (!ctx.aiProvider) {
208
+ return { error: 'AI provider not available' };
209
+ }
210
+ const { description, language = 'swift', severity = 'warning', autoCreate = false } = params;
211
+
212
+ const prompt = `Generate a Guard rule for this requirement:
213
+ Description: ${description}
214
+ Language: ${language}
215
+ Severity: ${severity}
216
+
217
+ Return ONLY valid JSON:
218
+ {
219
+ "name": "rule-name-kebab-case",
220
+ "description": "One-line description in English",
221
+ "description_cn": "一行中文描述",
222
+ "pattern": "regex pattern for matching the problematic code",
223
+ "languages": ["${language}"],
224
+ "severity": "${severity}",
225
+ "testCases": {
226
+ "shouldMatch": ["code example that should trigger"],
227
+ "shouldNotMatch": ["code example that should NOT trigger"]
228
+ }
229
+ }`;
230
+
231
+ const rule = await ctx.aiProvider.chatWithStructuredOutput(prompt, { temperature: 0.2 });
232
+ if (!rule) {
233
+ return { error: 'Failed to parse AI response' };
234
+ }
235
+
236
+ // 验证正则表达式
237
+ try {
238
+ new RegExp(rule.pattern);
239
+ } catch (e) {
240
+ return { error: `Invalid regex pattern: ${e.message}`, rule };
241
+ }
242
+
243
+ // 自动创建
244
+ if (autoCreate && rule.name && rule.pattern) {
245
+ try {
246
+ const guardService = ctx.container.get('guardService');
247
+ const created = await guardService.createRule(
248
+ {
249
+ name: rule.name,
250
+ description: rule.description || description,
251
+ pattern: rule.pattern,
252
+ languages: rule.languages || [language],
253
+ severity: rule.severity || severity,
254
+ },
255
+ { userId: 'agent' }
256
+ );
257
+ return { rule, created: true, recipeId: created.id };
258
+ } catch (err) {
259
+ return { rule, created: false, error: err.message };
260
+ }
261
+ }
262
+
263
+ return { rule, created: false };
264
+ },
265
+ };
@@ -0,0 +1,250 @@
1
+ /**
2
+ * tools/index.js — Barrel 导出文件
3
+ *
4
+ * 从各子模块导入所有工具,按原始顺序组装 ALL_TOOLS 数组并导出。
5
+ */
6
+
7
+ // ── 项目数据访问 (5) ──
8
+ import {
9
+ searchProjectCode,
10
+ readProjectFile,
11
+ listProjectStructure,
12
+ getFileSummary,
13
+ semanticSearchCode,
14
+ } from './project-access.js';
15
+
16
+ // ── 查询类 (6) ──
17
+ import {
18
+ searchRecipes,
19
+ searchCandidates,
20
+ getRecipeDetail,
21
+ getProjectStats,
22
+ searchKnowledge,
23
+ getRelatedRecipes,
24
+ } from './query.js';
25
+
26
+ // ── AI 分析类 (4) ──
27
+ import {
28
+ summarizeCode,
29
+ extractRecipes,
30
+ enrichCandidate,
31
+ refineBootstrapCandidates,
32
+ } from './ai-analysis.js';
33
+
34
+ // ── Guard 安全类 (6) ──
35
+ import {
36
+ listGuardRules,
37
+ getRecommendations,
38
+ aiTranslate,
39
+ guardCheckCode,
40
+ queryViolations,
41
+ generateGuardRule,
42
+ } from './guard.js';
43
+
44
+ // ── 知识图谱类 (3) ──
45
+ import {
46
+ checkDuplicate,
47
+ discoverRelations,
48
+ addGraphEdge,
49
+ } from './knowledge-graph.js';
50
+
51
+ // ── 生命周期操作类 (11) ──
52
+ import {
53
+ submitCandidate,
54
+ saveDocument,
55
+ approveCandidate,
56
+ rejectCandidate,
57
+ publishRecipe,
58
+ deprecateRecipe,
59
+ updateRecipe,
60
+ recordUsage,
61
+ qualityScore,
62
+ validateCandidate,
63
+ getFeedbackStats,
64
+ } from './lifecycle.js';
65
+
66
+ // ── 基础设施类 (7) ──
67
+ import {
68
+ graphImpactAnalysis,
69
+ rebuildIndex,
70
+ queryAuditLog,
71
+ loadSkill,
72
+ createSkillTool,
73
+ suggestSkills,
74
+ bootstrapKnowledgeTool,
75
+ } from './infrastructure.js';
76
+
77
+ // ── 组合工具 + 元工具 (6) ──
78
+ import {
79
+ analyzeCode,
80
+ knowledgeOverview,
81
+ submitWithCheck,
82
+ getToolDetails,
83
+ planTask,
84
+ reviewMyOutput,
85
+ } from './composite.js';
86
+
87
+ // ── AST 结构化分析 + Agent Memory (10) ──
88
+ import {
89
+ getProjectOverview,
90
+ getClassHierarchy,
91
+ getClassInfo,
92
+ getProtocolInfo,
93
+ getMethodOverrides,
94
+ getCategoryMap,
95
+ getPreviousAnalysis,
96
+ noteFinding,
97
+ getPreviousEvidence,
98
+ queryCodeGraph,
99
+ } from './ast-graph.js';
100
+
101
+ // ── Re-export 所有工具 ──
102
+ export {
103
+ // 项目数据访问
104
+ searchProjectCode,
105
+ readProjectFile,
106
+ listProjectStructure,
107
+ getFileSummary,
108
+ semanticSearchCode,
109
+ // 查询类
110
+ searchRecipes,
111
+ searchCandidates,
112
+ getRecipeDetail,
113
+ getProjectStats,
114
+ searchKnowledge,
115
+ getRelatedRecipes,
116
+ // AI 分析类
117
+ summarizeCode,
118
+ extractRecipes,
119
+ enrichCandidate,
120
+ refineBootstrapCandidates,
121
+ // Guard 安全类
122
+ listGuardRules,
123
+ getRecommendations,
124
+ aiTranslate,
125
+ guardCheckCode,
126
+ queryViolations,
127
+ generateGuardRule,
128
+ // 知识图谱类
129
+ checkDuplicate,
130
+ discoverRelations,
131
+ addGraphEdge,
132
+ // 生命周期操作类
133
+ submitCandidate,
134
+ saveDocument,
135
+ approveCandidate,
136
+ rejectCandidate,
137
+ publishRecipe,
138
+ deprecateRecipe,
139
+ updateRecipe,
140
+ recordUsage,
141
+ qualityScore,
142
+ validateCandidate,
143
+ getFeedbackStats,
144
+ // 基础设施类
145
+ graphImpactAnalysis,
146
+ rebuildIndex,
147
+ queryAuditLog,
148
+ loadSkill,
149
+ createSkillTool,
150
+ suggestSkills,
151
+ bootstrapKnowledgeTool,
152
+ // 组合工具 + 元工具
153
+ analyzeCode,
154
+ knowledgeOverview,
155
+ submitWithCheck,
156
+ getToolDetails,
157
+ planTask,
158
+ reviewMyOutput,
159
+ // AST 结构化分析
160
+ getProjectOverview,
161
+ getClassHierarchy,
162
+ getClassInfo,
163
+ getProtocolInfo,
164
+ getMethodOverrides,
165
+ getCategoryMap,
166
+ getPreviousAnalysis,
167
+ // Agent Memory
168
+ noteFinding,
169
+ getPreviousEvidence,
170
+ // 代码实体图谱
171
+ queryCodeGraph,
172
+ };
173
+
174
+ // ── ALL_TOOLS 数组(与原始 tools.js 顺序一致)──
175
+ export const ALL_TOOLS = [
176
+ // 项目数据访问 (5) — 含 v10 Agent-Pull 工具
177
+ searchProjectCode,
178
+ readProjectFile,
179
+ listProjectStructure,
180
+ getFileSummary,
181
+ semanticSearchCode,
182
+ // 查询类 (8)
183
+ searchRecipes,
184
+ searchCandidates,
185
+ getRecipeDetail,
186
+ getProjectStats,
187
+ searchKnowledge,
188
+ getRelatedRecipes,
189
+ listGuardRules,
190
+ getRecommendations,
191
+ // AI 分析类 (5)
192
+ summarizeCode,
193
+ extractRecipes,
194
+ enrichCandidate,
195
+ refineBootstrapCandidates,
196
+ aiTranslate,
197
+ // Guard 安全类 (3)
198
+ guardCheckCode,
199
+ queryViolations,
200
+ generateGuardRule,
201
+ // 生命周期操作类 (7)
202
+ submitCandidate,
203
+ saveDocument,
204
+ approveCandidate,
205
+ rejectCandidate,
206
+ publishRecipe,
207
+ deprecateRecipe,
208
+ updateRecipe,
209
+ recordUsage,
210
+ // 质量与反馈类 (3)
211
+ qualityScore,
212
+ validateCandidate,
213
+ getFeedbackStats,
214
+ // 知识图谱类 (3)
215
+ checkDuplicate,
216
+ discoverRelations,
217
+ addGraphEdge,
218
+ // 基础设施类 (3)
219
+ graphImpactAnalysis,
220
+ rebuildIndex,
221
+ queryAuditLog,
222
+ // Skills & Bootstrap (4)
223
+ loadSkill,
224
+ createSkillTool,
225
+ suggestSkills,
226
+ bootstrapKnowledgeTool,
227
+ // 组合工具 (3) — 减少 ReAct 轮次
228
+ analyzeCode,
229
+ knowledgeOverview,
230
+ submitWithCheck,
231
+ // 元工具 (3) — Agent 自主能力增强
232
+ getToolDetails,
233
+ planTask,
234
+ reviewMyOutput,
235
+ // AST 结构化分析 (7) — v3.0 AI-First Bootstrap
236
+ getProjectOverview,
237
+ getClassHierarchy,
238
+ getClassInfo,
239
+ getProtocolInfo,
240
+ getMethodOverrides,
241
+ getCategoryMap,
242
+ getPreviousAnalysis,
243
+ // Agent Memory 增强 (2) — 工作记忆 + 情景记忆
244
+ noteFinding,
245
+ getPreviousEvidence,
246
+ // 代码实体图谱 (1) — Phase E
247
+ queryCodeGraph,
248
+ ];
249
+
250
+ export default ALL_TOOLS;