autosnippet 3.0.0 → 3.0.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 +230 -324
- package/bin/api-server.js +1 -1
- package/bin/cli.js +204 -244
- package/bin/mcp-server.js +5 -3
- package/config/knowledge-base.config.js +132 -132
- package/dashboard/dist/assets/{icons-CEfgGaZi.js → icons-Cdq22n2i.js} +95 -100
- package/dashboard/dist/assets/index-ClkyPkDX.js +133 -0
- package/dashboard/dist/assets/index-t4QrJwv1.css +1 -0
- package/dashboard/dist/index.html +3 -3
- package/lib/bootstrap.js +8 -8
- package/lib/cli/AiScanService.js +86 -40
- package/lib/cli/KnowledgeSyncService.js +113 -74
- package/lib/cli/SetupService.js +439 -277
- package/lib/cli/UpgradeService.js +63 -100
- package/lib/core/AstAnalyzer.js +276 -597
- package/lib/core/ast/ProjectGraph.js +101 -40
- package/lib/core/ast/ensure-grammars.js +232 -0
- package/lib/core/ast/index.js +115 -0
- package/lib/core/ast/lang-dart.js +661 -0
- package/lib/core/ast/lang-go.js +530 -0
- package/lib/core/ast/lang-java.js +435 -0
- package/lib/core/ast/lang-javascript.js +272 -0
- package/lib/core/ast/lang-kotlin.js +423 -0
- package/lib/core/ast/lang-objc.js +388 -0
- package/lib/core/ast/lang-python.js +371 -0
- package/lib/core/ast/lang-swift.js +337 -0
- package/lib/core/ast/lang-typescript.js +503 -0
- package/lib/core/capability/CapabilityProbe.js +18 -9
- package/lib/core/constitution/Constitution.js +2 -3
- package/lib/core/constitution/ConstitutionValidator.js +65 -24
- package/lib/core/discovery/DartDiscoverer.js +534 -0
- package/lib/core/discovery/DiscovererRegistry.js +83 -0
- package/lib/core/discovery/GenericDiscoverer.js +225 -0
- package/lib/core/discovery/GoDiscoverer.js +541 -0
- package/lib/core/discovery/JvmDiscoverer.js +506 -0
- package/lib/core/discovery/NodeDiscoverer.js +466 -0
- package/lib/core/discovery/ProjectDiscoverer.js +93 -0
- package/lib/core/discovery/PythonDiscoverer.js +338 -0
- package/lib/core/discovery/SpmDiscoverer.js +5 -0
- package/lib/core/discovery/index.js +53 -0
- package/lib/core/enhancement/EnhancementPack.js +71 -0
- package/lib/core/enhancement/EnhancementRegistry.js +47 -0
- package/lib/core/enhancement/android-enhancement.js +102 -0
- package/lib/core/enhancement/django-enhancement.js +70 -0
- package/lib/core/enhancement/fastapi-enhancement.js +63 -0
- package/lib/core/enhancement/go-grpc-enhancement.js +152 -0
- package/lib/core/enhancement/go-web-enhancement.js +201 -0
- package/lib/core/enhancement/index.js +65 -0
- package/lib/core/enhancement/node-server-enhancement.js +88 -0
- package/lib/core/enhancement/react-enhancement.js +86 -0
- package/lib/core/enhancement/spring-enhancement.js +112 -0
- package/lib/core/enhancement/vue-enhancement.js +96 -0
- package/lib/core/gateway/Gateway.js +8 -9
- package/lib/core/gateway/GatewayActionRegistry.js +1 -1
- package/lib/core/permission/PermissionManager.js +12 -8
- package/lib/domain/index.js +13 -9
- package/lib/domain/knowledge/KnowledgeEntry.js +111 -101
- package/lib/domain/knowledge/KnowledgeRepository.js +0 -1
- package/lib/domain/knowledge/Lifecycle.js +22 -22
- package/lib/domain/knowledge/index.js +9 -12
- package/lib/domain/knowledge/values/Constraints.js +31 -21
- package/lib/domain/knowledge/values/Content.js +21 -13
- package/lib/domain/knowledge/values/Quality.js +31 -18
- package/lib/domain/knowledge/values/Reasoning.js +20 -12
- package/lib/domain/knowledge/values/Relations.js +37 -25
- package/lib/domain/knowledge/values/Stats.js +18 -12
- package/lib/domain/knowledge/values/index.js +4 -3
- package/lib/domain/snippet/Snippet.js +35 -10
- package/lib/external/ai/AiFactory.js +48 -16
- package/lib/external/ai/AiProvider.js +184 -90
- package/lib/external/ai/providers/ClaudeProvider.js +25 -12
- package/lib/external/ai/providers/GoogleGeminiProvider.js +59 -30
- package/lib/external/ai/providers/MockProvider.js +9 -3
- package/lib/external/ai/providers/OpenAiProvider.js +51 -29
- package/lib/external/mcp/McpServer.js +66 -36
- package/lib/external/mcp/errorHandler.js +23 -11
- package/lib/external/mcp/handlers/LanguageExtensions.js +138 -53
- package/lib/external/mcp/handlers/TargetClassifier.js +52 -16
- package/lib/external/mcp/handlers/bootstrap/pipeline/BootstrapSnapshot.js +81 -20
- package/lib/external/mcp/handlers/bootstrap/pipeline/EpisodicMemory.js +71 -42
- package/lib/external/mcp/handlers/bootstrap/pipeline/IncrementalBootstrap.js +9 -17
- package/lib/external/mcp/handlers/bootstrap/pipeline/ToolResultCache.js +14 -9
- package/lib/external/mcp/handlers/bootstrap/pipeline/dimension-context.js +15 -7
- package/lib/external/mcp/handlers/bootstrap/pipeline/orchestrator.js +352 -153
- package/lib/external/mcp/handlers/bootstrap/pipeline/tier-scheduler.js +52 -12
- package/lib/external/mcp/handlers/bootstrap/skills.js +143 -39
- package/lib/external/mcp/handlers/bootstrap.js +691 -168
- package/lib/external/mcp/handlers/browse.js +66 -22
- package/lib/external/mcp/handlers/candidate.js +118 -35
- package/lib/external/mcp/handlers/consolidated.js +49 -17
- package/lib/external/mcp/handlers/guard.js +104 -39
- package/lib/external/mcp/handlers/knowledge.js +60 -36
- package/lib/external/mcp/handlers/search.js +43 -14
- package/lib/external/mcp/handlers/skill.js +120 -45
- package/lib/external/mcp/handlers/structure.js +240 -86
- package/lib/external/mcp/handlers/system.js +42 -12
- package/lib/external/mcp/handlers/wiki.js +58 -33
- package/lib/external/mcp/tools.js +306 -123
- package/lib/http/HttpServer.js +72 -47
- package/lib/http/middleware/RateLimiter.js +5 -3
- package/lib/http/middleware/errorHandler.js +6 -1
- package/lib/http/middleware/requestLogger.js +14 -3
- package/lib/http/middleware/roleResolver.js +30 -23
- package/lib/http/routes/ai.js +387 -265
- package/lib/http/routes/auth.js +81 -61
- package/lib/http/routes/candidates.js +430 -320
- package/lib/http/routes/commands.js +289 -189
- package/lib/http/routes/extract.js +158 -125
- package/lib/http/routes/guardRules.js +309 -217
- package/lib/http/routes/knowledge.js +213 -154
- package/lib/http/routes/modules.js +578 -0
- package/lib/http/routes/monitoring.js +6 -6
- package/lib/http/routes/recipes.js +104 -93
- package/lib/http/routes/search.js +361 -305
- package/lib/http/routes/skills.js +145 -98
- package/lib/http/routes/snippets.js +42 -30
- package/lib/http/routes/spm.js +3 -405
- package/lib/http/routes/violations.js +113 -93
- package/lib/http/routes/wiki.js +211 -170
- package/lib/http/utils/routeHelpers.js +3 -1
- package/lib/http/utils/sse-sessions.js +16 -6
- package/lib/http/utils/sse.js +15 -5
- package/lib/infrastructure/audit/AuditLogger.js +5 -2
- package/lib/infrastructure/audit/AuditStore.js +10 -7
- package/lib/infrastructure/cache/CacheService.js +3 -1
- package/lib/infrastructure/cache/GraphCache.js +8 -4
- package/lib/infrastructure/cache/UnifiedCacheAdapter.js +1 -1
- package/lib/infrastructure/config/ConfigLoader.js +9 -5
- package/lib/infrastructure/config/Defaults.js +30 -10
- package/lib/infrastructure/config/Paths.js +28 -8
- package/lib/infrastructure/config/TriggerSymbol.js +22 -10
- package/lib/infrastructure/database/DatabaseConnection.js +15 -10
- package/lib/infrastructure/database/migrations/001_initial_schema.js +0 -1
- package/lib/infrastructure/external/ClipboardManager.js +6 -2
- package/lib/infrastructure/external/NativeUi.js +50 -43
- package/lib/infrastructure/external/OpenBrowser.js +14 -17
- package/lib/infrastructure/external/XcodeAutomation.js +14 -258
- package/lib/infrastructure/logging/Logger.js +46 -30
- package/lib/infrastructure/monitoring/ErrorTracker.js +7 -5
- package/lib/infrastructure/monitoring/PerformanceMonitor.js +12 -4
- package/lib/infrastructure/paths/HeaderResolver.js +25 -9
- package/lib/infrastructure/paths/PathFinder.js +34 -12
- package/lib/infrastructure/plugin/PluginManager.js +26 -8
- package/lib/infrastructure/realtime/RealtimeService.js +2 -2
- package/lib/infrastructure/vector/Chunker.js +22 -7
- package/lib/infrastructure/vector/IndexingPipeline.js +46 -22
- package/lib/infrastructure/vector/JsonVectorAdapter.js +90 -53
- package/lib/infrastructure/vector/VectorStore.js +28 -10
- package/lib/injection/ServiceContainer.js +247 -93
- package/lib/platform/ios/index.js +63 -0
- package/lib/platform/ios/routes/spm.js +437 -0
- package/lib/platform/ios/snippet/PlaceholderConverter.js +55 -0
- package/lib/platform/ios/snippet/XcodeCodec.js +112 -0
- package/lib/{service → platform/ios}/spm/DependencyGraph.js +41 -17
- package/lib/{service → platform/ios}/spm/PackageSwiftParser.js +41 -14
- package/lib/{service → platform/ios}/spm/PolicyEngine.js +9 -4
- package/lib/platform/ios/spm/SpmDiscoverer.js +122 -0
- package/lib/{service → platform/ios}/spm/SpmService.js +385 -127
- package/lib/{service/automation → platform/ios/xcode}/SaveEventFilter.js +8 -7
- package/lib/platform/ios/xcode/XcodeAutomation.js +350 -0
- package/lib/{service/automation → platform/ios/xcode}/XcodeIntegration.js +325 -145
- package/lib/repository/base/BaseRepository.js +7 -9
- package/lib/repository/knowledge/KnowledgeRepository.impl.js +98 -75
- package/lib/repository/token/TokenUsageStore.js +4 -2
- package/lib/service/automation/ActionPipeline.js +1 -1
- package/lib/service/automation/AutomationOrchestrator.js +8 -4
- package/lib/service/automation/ContextCollector.js +7 -5
- package/lib/service/automation/DirectiveDetector.js +23 -16
- package/lib/service/automation/FileWatcher.js +112 -56
- package/lib/service/automation/TriggerResolver.js +6 -4
- package/lib/service/automation/handlers/AlinkHandler.js +24 -12
- package/lib/service/automation/handlers/CreateHandler.js +19 -20
- package/lib/service/automation/handlers/DraftHandler.js +14 -8
- package/lib/service/automation/handlers/GuardHandler.js +93 -63
- package/lib/service/automation/handlers/HeaderHandler.js +1 -6
- package/lib/service/automation/handlers/SearchHandler.js +155 -88
- package/lib/service/bootstrap/BootstrapTaskManager.js +77 -35
- package/lib/service/candidate/SimilarityService.js +25 -9
- package/lib/service/chat/AnalystAgent.js +50 -24
- package/lib/service/chat/CandidateGuardrail.js +143 -17
- package/lib/service/chat/ChatAgent.js +759 -243
- package/lib/service/chat/ContextWindow.js +116 -71
- package/lib/service/chat/ConversationStore.js +77 -36
- package/lib/service/chat/EpisodicConsolidator.js +47 -23
- package/lib/service/chat/HandoffProtocol.js +98 -22
- package/lib/service/chat/Memory.js +34 -14
- package/lib/service/chat/ProducerAgent.js +40 -20
- package/lib/service/chat/ProjectSemanticMemory.js +109 -78
- package/lib/service/chat/ReasoningLayer.js +148 -70
- package/lib/service/chat/ReasoningTrace.js +44 -32
- package/lib/service/chat/TaskPipeline.js +39 -19
- package/lib/service/chat/ToolRegistry.js +48 -29
- package/lib/service/chat/WorkingMemory.js +44 -18
- package/lib/service/chat/tools.js +1096 -494
- package/lib/service/context/RecipeExtractor.js +132 -51
- package/lib/service/cursor/CursorDeliveryPipeline.js +82 -37
- package/lib/service/cursor/KnowledgeCompressor.js +25 -22
- package/lib/service/cursor/RulesGenerator.js +13 -7
- package/lib/service/cursor/SkillsSyncer.js +77 -27
- package/lib/service/cursor/TokenBudget.js +2 -2
- package/lib/service/cursor/TopicClassifier.js +54 -20
- package/lib/service/guard/ComplianceReporter.js +55 -43
- package/lib/service/guard/ExclusionManager.js +67 -29
- package/lib/service/guard/GuardCheckEngine.js +381 -86
- package/lib/service/guard/GuardFeedbackLoop.js +22 -10
- package/lib/service/guard/GuardService.js +29 -19
- package/lib/service/guard/RuleLearner.js +55 -23
- package/lib/service/guard/SourceFileCollector.js +27 -20
- package/lib/service/guard/ViolationsStore.js +43 -38
- package/lib/service/knowledge/CodeEntityGraph.js +147 -82
- package/lib/service/knowledge/ConfidenceRouter.js +12 -10
- package/lib/service/knowledge/KnowledgeFileWriter.js +147 -56
- package/lib/service/knowledge/KnowledgeGraphService.js +81 -34
- package/lib/service/knowledge/KnowledgeService.js +222 -112
- package/lib/service/module/ModuleService.js +969 -0
- package/lib/service/quality/FeedbackCollector.js +27 -15
- package/lib/service/quality/QualityScorer.js +78 -24
- package/lib/service/recipe/RecipeCandidateValidator.js +110 -44
- package/lib/service/recipe/RecipeParser.js +78 -45
- package/lib/service/search/CoarseRanker.js +43 -28
- package/lib/service/search/CrossEncoderReranker.js +32 -21
- package/lib/service/search/InvertedIndex.js +21 -7
- package/lib/service/search/MultiSignalRanker.js +90 -28
- package/lib/service/search/RetrievalFunnel.js +45 -24
- package/lib/service/search/SearchEngine.js +255 -103
- package/lib/service/skills/EventAggregator.js +32 -15
- package/lib/service/skills/SignalCollector.js +140 -64
- package/lib/service/skills/SkillAdvisor.js +79 -42
- package/lib/service/skills/SkillHooks.js +16 -14
- package/lib/service/snippet/PlaceholderConverter.js +5 -0
- package/lib/service/snippet/SnippetFactory.js +116 -99
- package/lib/service/snippet/SnippetInstaller.js +234 -62
- package/lib/service/snippet/codecs/SnippetCodec.js +67 -0
- package/lib/service/snippet/codecs/VSCodeCodec.js +102 -0
- package/lib/service/snippet/codecs/XcodeCodec.js +5 -0
- package/lib/service/wiki/WikiGenerator.js +637 -263
- package/lib/shared/DimensionCopyRegistry.js +472 -0
- package/lib/shared/LanguageService.js +399 -0
- package/lib/shared/PathGuard.js +45 -28
- package/lib/shared/RecipeReadinessChecker.js +72 -12
- package/lib/shared/constants.js +41 -41
- package/lib/shared/errors/BaseError.js +2 -2
- package/lib/shared/errors/index.js +4 -4
- package/lib/shared/similarity.js +25 -8
- package/lib/shared/token-utils.js +6 -2
- package/lib/shared/utils/common.js +12 -4
- package/package.json +49 -13
- package/scripts/bench-real-projects.mjs +256 -0
- package/scripts/build-native-ui.js +30 -30
- package/scripts/clear-old-vector-index.js +5 -35
- package/scripts/clear-vector-cache.js +7 -37
- package/scripts/collect-test-project-stats.mjs +160 -0
- package/scripts/diagnose-mcp.js +41 -32
- package/scripts/ensure-parse-package.js +6 -9
- package/scripts/generate-recipe-drafts.js +116 -77
- package/scripts/init-db.js +3 -20
- package/scripts/init-snippets.js +305 -0
- package/scripts/init-vector-db.js +173 -170
- package/scripts/install-cursor-skill.js +148 -104
- package/scripts/install-full.js +8 -21
- package/scripts/install-vscode-copilot.js +146 -145
- package/scripts/migrate-md-to-knowledge.mjs +139 -151
- package/scripts/postinstall-safe.js +5 -17
- package/scripts/recipe-audit.js +106 -82
- package/scripts/release.js +283 -323
- package/scripts/setup-mcp-config.js +60 -52
- package/scripts/verify-context-api.js +20 -20
- package/skills/autosnippet-analysis/SKILL.md +10 -6
- package/skills/autosnippet-candidates/SKILL.md +27 -26
- package/skills/autosnippet-coldstart/SKILL.md +555 -38
- package/skills/autosnippet-concepts/SKILL.md +349 -337
- package/skills/autosnippet-create/SKILL.md +5 -5
- package/skills/autosnippet-reference-dart/SKILL.md +543 -0
- package/skills/autosnippet-reference-go/SKILL.md +539 -0
- package/skills/autosnippet-reference-java/SKILL.md +534 -0
- package/skills/autosnippet-reference-jsts/SKILL.md +41 -9
- package/skills/autosnippet-reference-kotlin/SKILL.md +526 -0
- package/skills/autosnippet-reference-objc/SKILL.md +29 -6
- package/skills/autosnippet-reference-python/SKILL.md +800 -0
- package/skills/autosnippet-reference-swift/SKILL.md +70 -14
- package/skills/autosnippet-structure/SKILL.md +4 -4
- package/templates/cursor-rules/autosnippet-conventions.mdc +2 -2
- package/templates/recipes-setup/README.md +2 -2
- package/templates/recipes-setup/_template.md +1 -1
- package/dashboard/dist/assets/index-Bun3ld_J.css +0 -1
- package/dashboard/dist/assets/index-_Sk_Dmg3.js +0 -143
- package/resources/asd-entry/main.swift +0 -159
- package/scripts/build-asd-entry.js +0 -51
- package/scripts/init-xcode-snippets.js +0 -311
- package/template.json +0 -39
|
@@ -3,16 +3,16 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* VSCode/Cursor MCP 配置辅助脚本
|
|
5
5
|
* 帮助用户快速配置 AutoSnippet MCP 集成
|
|
6
|
-
*
|
|
6
|
+
*
|
|
7
7
|
* 使用:
|
|
8
8
|
* node scripts/setup-mcp-config.js [--editor vscode|cursor] [--path /path/to/project]
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
import { execSync } from 'node:child_process';
|
|
12
11
|
import fs from 'node:fs';
|
|
13
|
-
import path from 'node:path';
|
|
14
|
-
import os from 'node:os';
|
|
15
12
|
import { createRequire } from 'node:module';
|
|
13
|
+
import os from 'node:os';
|
|
14
|
+
import path from 'node:path';
|
|
15
|
+
|
|
16
16
|
const require = createRequire(import.meta.url);
|
|
17
17
|
|
|
18
18
|
const args = require('minimist')(process.argv.slice(2));
|
|
@@ -26,15 +26,13 @@ const isCursor = editor === 'cursor';
|
|
|
26
26
|
const isQuiet = process.env.ASD_QUIET === 'true';
|
|
27
27
|
|
|
28
28
|
// 检测是否在 AutoSnippet 仓库内执行
|
|
29
|
-
const isAutoSnippetRepo =
|
|
29
|
+
const isAutoSnippetRepo =
|
|
30
|
+
fs.existsSync(path.join(projectPath, 'bin/mcp-server.js')) &&
|
|
30
31
|
fs.existsSync(path.join(projectPath, 'bin/asd')) &&
|
|
31
32
|
fs.existsSync(path.join(projectPath, 'package.json'));
|
|
32
33
|
|
|
33
34
|
if (isAutoSnippetRepo && !args.path) {
|
|
34
35
|
if (!isQuiet) {
|
|
35
|
-
console.log('⚠️ 检测到在 AutoSnippet 仓库内执行');
|
|
36
|
-
console.log(' AutoSnippet 仓库不应配置 MCP 服务器');
|
|
37
|
-
console.log(' 如需为其他项目配置,请使用: --path /path/to/project');
|
|
38
36
|
}
|
|
39
37
|
process.exit(0);
|
|
40
38
|
}
|
|
@@ -44,7 +42,9 @@ if (isAutoSnippetRepo && !args.path) {
|
|
|
44
42
|
// 检查 MCP Server
|
|
45
43
|
const mcpServerPath = path.join(projectPath, 'bin/mcp-server.js');
|
|
46
44
|
if (!fs.existsSync(mcpServerPath)) {
|
|
47
|
-
if (!isQuiet)
|
|
45
|
+
if (!isQuiet) {
|
|
46
|
+
console.error(`✗ MCP Server 未找到: ${mcpServerPath}`);
|
|
47
|
+
}
|
|
48
48
|
process.exit(1);
|
|
49
49
|
}
|
|
50
50
|
|
|
@@ -57,65 +57,72 @@ if (isVSCode) {
|
|
|
57
57
|
} else if (isCursor) {
|
|
58
58
|
configureCursor();
|
|
59
59
|
} else {
|
|
60
|
-
if (!isQuiet)
|
|
60
|
+
if (!isQuiet) {
|
|
61
|
+
console.error('✗ 未知编辑器,使用 --editor vscode 或 --editor cursor');
|
|
62
|
+
}
|
|
61
63
|
process.exit(1);
|
|
62
64
|
}
|
|
63
65
|
|
|
64
66
|
function configureVSCode() {
|
|
65
67
|
// 找到 settings.json 路径
|
|
66
68
|
if (os.platform() === 'darwin') {
|
|
67
|
-
|
|
69
|
+
settingsPath = path.join(os.homedir(), 'Library/Application Support/Code/User/settings.json');
|
|
68
70
|
} else if (os.platform() === 'win32') {
|
|
69
|
-
|
|
71
|
+
settingsPath = path.join(os.getenv('APPDATA'), 'Code/User/settings.json');
|
|
70
72
|
} else {
|
|
71
|
-
|
|
73
|
+
settingsPath = path.join(os.homedir(), '.config/Code/User/settings.json');
|
|
72
74
|
}
|
|
73
75
|
|
|
74
76
|
// 读取现有设置
|
|
75
77
|
let settings = {};
|
|
76
78
|
if (fs.existsSync(settingsPath)) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
79
|
+
try {
|
|
80
|
+
const content = fs.readFileSync(settingsPath, 'utf8');
|
|
81
|
+
settings = JSON.parse(content);
|
|
82
|
+
} catch (_e) {
|
|
83
|
+
// 忽略解析错误
|
|
84
|
+
}
|
|
83
85
|
}
|
|
84
86
|
|
|
85
87
|
// 添加 MCP 配置
|
|
86
88
|
if (!settings['github.copilot.mcp']) {
|
|
87
|
-
|
|
89
|
+
settings['github.copilot.mcp'] = {};
|
|
88
90
|
}
|
|
89
91
|
if (!settings['github.copilot.mcp'].servers) {
|
|
90
|
-
|
|
92
|
+
settings['github.copilot.mcp'].servers = [];
|
|
91
93
|
}
|
|
92
94
|
|
|
93
95
|
// 检查 autosnippet 是否已存在
|
|
94
|
-
const existingIndex = settings['github.copilot.mcp'].servers.findIndex(
|
|
95
|
-
|
|
96
|
+
const existingIndex = settings['github.copilot.mcp'].servers.findIndex(
|
|
97
|
+
(s) => s.name === 'autosnippet'
|
|
98
|
+
);
|
|
99
|
+
|
|
96
100
|
const mcpConfig = {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
name: 'autosnippet',
|
|
102
|
+
command: 'node',
|
|
103
|
+
args: [mcpServerPath],
|
|
104
|
+
env: {
|
|
105
|
+
ASD_UI_URL: 'http://localhost:3000',
|
|
106
|
+
},
|
|
103
107
|
};
|
|
104
108
|
|
|
105
109
|
if (existingIndex >= 0) {
|
|
106
|
-
|
|
110
|
+
settings['github.copilot.mcp'].servers[existingIndex] = mcpConfig;
|
|
107
111
|
} else {
|
|
108
|
-
|
|
112
|
+
settings['github.copilot.mcp'].servers.push(mcpConfig);
|
|
109
113
|
}
|
|
110
114
|
|
|
111
115
|
// 写入设置
|
|
112
116
|
try {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
117
|
+
fs.mkdirSync(path.dirname(settingsPath), { recursive: true });
|
|
118
|
+
fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2), 'utf8');
|
|
119
|
+
if (!isQuiet) {
|
|
120
|
+
}
|
|
116
121
|
} catch (e) {
|
|
117
|
-
|
|
118
|
-
|
|
122
|
+
if (!isQuiet) {
|
|
123
|
+
console.error(`✗ 保存设置失败: ${e.message}`);
|
|
124
|
+
}
|
|
125
|
+
process.exit(1);
|
|
119
126
|
}
|
|
120
127
|
}
|
|
121
128
|
|
|
@@ -125,25 +132,26 @@ function configureCursor() {
|
|
|
125
132
|
|
|
126
133
|
// 创建配置
|
|
127
134
|
const config = {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
135
|
+
mcpServers: {
|
|
136
|
+
autosnippet: {
|
|
137
|
+
command: 'node',
|
|
138
|
+
args: [path.relative(projectPath, mcpServerPath) || './bin/mcp-server.js'],
|
|
139
|
+
env: {
|
|
140
|
+
ASD_UI_URL: 'http://localhost:3000',
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
},
|
|
139
144
|
};
|
|
140
145
|
|
|
141
146
|
try {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
147
|
+
fs.mkdirSync(cursorConfigDir, { recursive: true });
|
|
148
|
+
fs.writeFileSync(cursorConfigPath, JSON.stringify(config, null, 2), 'utf8');
|
|
149
|
+
if (!isQuiet) {
|
|
150
|
+
}
|
|
145
151
|
} catch (e) {
|
|
146
|
-
|
|
147
|
-
|
|
152
|
+
if (!isQuiet) {
|
|
153
|
+
console.error(`✗ 保存配置失败: ${e.message}`);
|
|
154
|
+
}
|
|
155
|
+
process.exit(1);
|
|
148
156
|
}
|
|
149
157
|
}
|
|
@@ -21,33 +21,33 @@ const opts = {
|
|
|
21
21
|
path: url.pathname,
|
|
22
22
|
method: 'POST',
|
|
23
23
|
headers: {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
24
|
+
'Content-Type': 'application/json',
|
|
25
|
+
'Content-Length': Buffer.byteLength(body),
|
|
26
|
+
},
|
|
27
27
|
};
|
|
28
28
|
|
|
29
29
|
const req = client.request(opts, (res) => {
|
|
30
30
|
let data = '';
|
|
31
|
-
res.on('data', (ch) => {
|
|
31
|
+
res.on('data', (ch) => {
|
|
32
|
+
data += ch;
|
|
33
|
+
});
|
|
32
34
|
res.on('end', () => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
try {
|
|
38
|
-
const json = JSON.parse(data);
|
|
39
|
-
if (!json.items || !Array.isArray(json.items)) {
|
|
40
|
-
console.error('❌ 返回结构异常,缺少 items 数组');
|
|
41
|
-
process.exit(1);
|
|
35
|
+
if (res.statusCode !== 200) {
|
|
36
|
+
console.error(`❌ API 返回 ${res.statusCode}`);
|
|
37
|
+
process.exit(1);
|
|
42
38
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
39
|
+
try {
|
|
40
|
+
const json = JSON.parse(data);
|
|
41
|
+
if (!json.items || !Array.isArray(json.items)) {
|
|
42
|
+
console.error('❌ 返回结构异常,缺少 items 数组');
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
if (json.items.length > 0) {
|
|
46
|
+
}
|
|
47
|
+
} catch (e) {
|
|
48
|
+
console.error('❌ 解析响应失败:', e.message);
|
|
49
|
+
process.exit(1);
|
|
46
50
|
}
|
|
47
|
-
} catch (e) {
|
|
48
|
-
console.error('❌ 解析响应失败:', e.message);
|
|
49
|
-
process.exit(1);
|
|
50
|
-
}
|
|
51
51
|
});
|
|
52
52
|
});
|
|
53
53
|
|
|
@@ -143,17 +143,21 @@ autosnippet_bootstrap(operation=refine, candidateIds: ["id1", "id2", ...])
|
|
|
143
143
|
| 字段 | 重要性 | AI 可填? |
|
|
144
144
|
|------|-------|---------|
|
|
145
145
|
| title | ★★★ 必填 | ✅ |
|
|
146
|
-
|
|
|
146
|
+
| content (markdown+pattern+rationale) | ★★★ 必填 | ✅ |
|
|
147
147
|
| language | ★★★ 必填 | ✅ |
|
|
148
|
-
|
|
|
149
|
-
|
|
|
148
|
+
| kind (rule/pattern/fact) | ★★★ 必填 | ✅ |
|
|
149
|
+
| doClause | ★★★ 必填 | ✅ |
|
|
150
|
+
| category | ★★★ 必填 | ✅ |
|
|
151
|
+
| trigger | ★★★ 必填 | ✅ |
|
|
152
|
+
| description | ★★★ 必填 | ✅ |
|
|
153
|
+
| headers | ★★★ 必填 | ✅ |
|
|
154
|
+
| usageGuide | ★★★ 必填 | ✅ |
|
|
155
|
+
| knowledgeType | ★★★ 必填 | ✅ |
|
|
156
|
+
| reasoning | ★★★ 必填 | Agent 必须自己填 |
|
|
150
157
|
| complexity | ★★☆ 推荐 | ✅ |
|
|
151
158
|
| scope | ★★☆ 推荐 | ✅ |
|
|
152
159
|
| steps | ★★☆ 推荐 | ✅ |
|
|
153
160
|
| constraints.preconditions | ★★☆ 推荐 | ✅ |
|
|
154
|
-
| summary / description | ★★★ 强烈推荐 | ✅ |
|
|
155
|
-
| usageGuide | ★★☆ 推荐 | ⚠️ 需人工审核 |
|
|
156
|
-
| reasoning | ★★★ 必填 | Agent 必须自己填 |
|
|
157
161
|
|
|
158
162
|
---
|
|
159
163
|
|
|
@@ -78,8 +78,16 @@ Every candidate submitted via `submit_candidate` or `submit_candidates` supports
|
|
|
78
78
|
| Field | Type | Example |
|
|
79
79
|
|-------|------|---------|
|
|
80
80
|
| **title** | string | "网络请求统一封装 - APIClient" |
|
|
81
|
-
| **
|
|
81
|
+
| **content** | object | `{ markdown: "≥200字 Markdown 正文", pattern: "核心代码模式", rationale: "设计原理" }` |
|
|
82
82
|
| **language** | string | swift / objc / javascript / python etc. |
|
|
83
|
+
| **kind** | string | `rule` / `pattern` / `fact` |
|
|
84
|
+
| **doClause** | string | 英文祈使句正向指令(≠60 tokens)|
|
|
85
|
+
| **trigger** | string | `@` 开头 kebab-case,如 `@api-client` |
|
|
86
|
+
| **description** | string | 中文摘要 ≤80字 |
|
|
87
|
+
| **category** | string | View / Service / Tool / Model / Network / Storage / UI / Utility |
|
|
88
|
+
| **headers** | string[] | 完整 import 语句数组,无 import 传 `[]` |
|
|
89
|
+
| **usageGuide** | string | Markdown ### 章节格式的使用指南 |
|
|
90
|
+
| **knowledgeType** | string | `code-pattern` / `architecture` / `best-practice` 等 |
|
|
83
91
|
|
|
84
92
|
### Layer 2: Classification (strongly recommended — enables filtering & search)
|
|
85
93
|
|
|
@@ -91,20 +99,9 @@ Every candidate submitted via `submit_candidate` or `submit_candidates` supports
|
|
|
91
99
|
| **scope** | string | `universal` (通用) \| `project-specific` (本项目) \| `target-specific` (特定 Target) |
|
|
92
100
|
| **tags** | string[] | `["networking", "async-await", "error-handling"]` |
|
|
93
101
|
|
|
94
|
-
### Layer 3:
|
|
95
|
-
|
|
96
|
-
| Field | Type | Description |
|
|
97
|
-
|-------|------|-------------|
|
|
98
|
-
| **description** | string | 一句话功能描述 |
|
|
99
|
-
| **summary** | string | 中文详细摘要(等同 summary_cn,Markdown),含功能介绍、设计背景 |
|
|
100
|
-
| **summary_cn** | string | 中文摘要(≤100字)— 与 summary 二选一 |
|
|
101
|
-
| **summary_en** | string | 英文摘要(≤100 words)— **强烈建议**,提升检索与 AI 理解 |
|
|
102
|
-
| **trigger** | string | 触发关键词,**必须** `@` 开头。如 `@api-client` |
|
|
103
|
-
| **usageGuide** | string | 中文使用指南(等同 usageGuide_cn,Markdown),包含 `###` 章节 |
|
|
104
|
-
| **usageGuide_cn** | string | 中文使用指南 — 与 usageGuide 二选一 |
|
|
105
|
-
| **usageGuide_en** | string | 英文使用指南(Markdown ### 章节)— **推荐** |
|
|
102
|
+
### Layer 3: Structured Content (high value — 代码变更与实施步骤)
|
|
106
103
|
|
|
107
|
-
|
|
104
|
+
> **注意**: Layer 1 已包含 V3 全部必填字段(title, content, language, kind, doClause, trigger, description, category, headers, usageGuide, knowledgeType)。本层为可选的高价值补充字段。
|
|
108
105
|
|
|
109
106
|
| Field | Type | Structure |
|
|
110
107
|
|-------|------|-----------|
|
|
@@ -259,7 +256,7 @@ Severity: `error` (must fix) | `warning` (should fix) | `info` (suggestion)
|
|
|
259
256
|
2. **Maximize information density** — Agent's primary value is extracting structured metadata that humans would skip
|
|
260
257
|
3. **Always fill Layer 1-3 + Reasoning + Recipe-Ready Checklist** at minimum; Layer 4-7 for complex patterns
|
|
261
258
|
4. **Reasoning is mandatory** — Every candidate MUST include `reasoning.whyStandard` + `reasoning.sources` + `reasoning.confidence`. No exceptions.
|
|
262
|
-
5. **
|
|
259
|
+
5. **V3 必填字段** — title, content(markdown+pattern+rationale), trigger, kind, doClause, description, language, category, headers, knowledgeType, usageGuide, reasoning
|
|
263
260
|
6. **Check `recipeReadyHints` in submit response** — If not empty, supplement fields and resubmit
|
|
264
261
|
7. **Parallel query existing Recipes** during generation to reduce duplicates and fill `relations`
|
|
265
262
|
6. **Code examples**: use Xcode placeholders (`<#URL#>`, `<#Token#>`), explain in `usageGuide`
|
|
@@ -304,15 +301,15 @@ Recommended sections: When to use / When not to use / Key points / Dependencies
|
|
|
304
301
|
|
|
305
302
|
### 备选:二次补全流程
|
|
306
303
|
|
|
307
|
-
Step 1: 提交基本字段(title,
|
|
304
|
+
Step 1: 提交基本字段(title, content, language)→ 获得 candidate ID(`autosnippet_submit_knowledge` 内置自动校验 + 去重检查)
|
|
308
305
|
Step 2: 根据提交返回的校验结果补全缺失字段
|
|
309
306
|
Step 3: 重新提交完整候选
|
|
310
307
|
|
|
311
308
|
> 注:`autosnippet_enrich_candidates` / `autosnippet_validate_candidate` / `autosnippet_check_duplicate` 已移入 admin 层级。Agent 层级的 `autosnippet_submit_knowledge` 已内置自动校验 + 去重,无需额外调用。
|
|
312
309
|
|
|
313
|
-
|
|
314
|
-
- **语义字段**: rationale, knowledgeType, complexity, scope, steps, constraints
|
|
315
|
-
- **Recipe 必填**: category, trigger,
|
|
310
|
+
需要补全的字段:
|
|
311
|
+
- **语义字段**: content.rationale, knowledgeType, complexity, scope, steps, constraints
|
|
312
|
+
- **Recipe 必填**: kind, doClause, category, trigger, description, headers, usageGuide, reasoning
|
|
316
313
|
|
|
317
314
|
---
|
|
318
315
|
|
|
@@ -324,18 +321,23 @@ Step 3: 重新提交完整候选
|
|
|
324
321
|
"items": [
|
|
325
322
|
{
|
|
326
323
|
"title": "BiliAPI 网络请求封装",
|
|
327
|
-
"
|
|
324
|
+
"content": {
|
|
325
|
+
"markdown": "## BiliAPI 网络请求统一封装\n\n### ✅ 标准用法\n```swift\nclass BiliAPI {\n static func request<T: Decodable>(_ endpoint: Endpoint) async throws -> T {\n let (data, response) = try await URLSession.shared.data(for: endpoint.urlRequest)\n guard let http = response as? HTTPURLResponse, 200..<300 ~= http.statusCode else {\n throw BiliError.invalidResponse\n }\n return try JSONDecoder().decode(T.self, from: data)\n }\n}\n```\n\n### 使用示例\n```swift\nlet user: UserInfo = try await BiliAPI.request(UserInfoEndpoint(uid: uid))\n```\n\n### 要点\n- 所有网络请求统一通过 BiliAPI.request()\n- 支持泛型解码,自动 JSON → Model\n- 统一错误处理和响应验证",
|
|
326
|
+
"pattern": "class BiliAPI {\n static func request<T: Decodable>(_ endpoint: Endpoint) async throws -> T {\n let (data, response) = try await URLSession.shared.data(for: endpoint.urlRequest)\n guard let http = response as? HTTPURLResponse, 200..<300 ~= http.statusCode else {\n throw BiliError.invalidResponse\n }\n return try JSONDecoder().decode(T.self, from: data)\n }\n}",
|
|
327
|
+
"rationale": "统一网络层避免各模块各自实现 URLSession 调用,减少重复代码并统一错误处理策略。"
|
|
328
|
+
},
|
|
329
|
+
"description": "统一的 API 请求封装,支持泛型解码和错误处理",
|
|
330
|
+
"kind": "pattern",
|
|
331
|
+
"doClause": "Use BiliAPI.request() for all network calls with type-safe Decodable responses",
|
|
328
332
|
"language": "swift",
|
|
329
333
|
"category": "Network",
|
|
334
|
+
"trigger": "@bili-api-request",
|
|
335
|
+
"headers": ["import Foundation", "import BiliKit"],
|
|
330
336
|
"knowledgeType": "code-pattern",
|
|
337
|
+
"usageGuide": "### When to use\n- 所有 B 站 API 调用\n- 需要类型安全的响应解码\n\n### Dependencies\n- Foundation\n- BiliKit/Models (Endpoint, BiliError)\n\n### Core steps\n1. 定义 Endpoint\n2. 调用 BiliAPI.request(endpoint)\n3. 处理 Result",
|
|
331
338
|
"complexity": "intermediate",
|
|
332
339
|
"scope": "project-specific",
|
|
333
340
|
"tags": ["networking", "async-await", "generic", "decodable"],
|
|
334
|
-
"description": "统一的 API 请求封装,支持泛型解码和错误处理",
|
|
335
|
-
"summary": "基于 async/await 的网络请求封装层,提供类型安全的 API 调用接口。统一错误处理、响应验证和 JSON 解码。",
|
|
336
|
-
"trigger": "@bili-api-request",
|
|
337
|
-
"usageGuide": "### When to use\n- 所有 B 站 API 调用\n- 需要类型安全的响应解码\n\n### Dependencies\n- Foundation\n- BiliKit/Models (Endpoint, BiliError)\n\n### Core steps\n1. 定义 Endpoint\n2. 调用 BiliAPI.request(endpoint)\n3. 处理 Result",
|
|
338
|
-
"rationale": "统一网络层避免各模块各自实现 URLSession 调用,减少重复代码并统一错误处理策略。",
|
|
339
341
|
"steps": [
|
|
340
342
|
{"title": "定义 Endpoint", "description": "创建符合 Endpoint 协议的请求描述", "code": "struct UserInfoEndpoint: Endpoint { ... }"},
|
|
341
343
|
{"title": "发起请求", "description": "调用统一 API 方法", "code": "let user: UserInfo = try await BiliAPI.request(UserInfoEndpoint(uid: uid))"}
|
|
@@ -343,7 +345,6 @@ Step 3: 重新提交完整候选
|
|
|
343
345
|
"codeChanges": [
|
|
344
346
|
{"file": "Sources/Network/OldAPI.swift", "before": "URLSession.shared.dataTask(with: url) { ... }", "after": "let result: T = try await BiliAPI.request(endpoint)", "explanation": "替换回调式为 async/await"}
|
|
345
347
|
],
|
|
346
|
-
"headers": ["import Foundation", "import BiliKit"],
|
|
347
348
|
"constraints": {
|
|
348
349
|
"preconditions": ["需要有效的网络连接", "Endpoint 必须实现 urlRequest 属性"],
|
|
349
350
|
"sideEffects": ["发起网络请求"],
|