autosnippet 3.0.1 → 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 +231 -324
- package/bin/api-server.js +1 -1
- package/bin/cli.js +204 -244
- package/bin/mcp-server.js +17 -4
- 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 +441 -282
- package/lib/cli/UpgradeService.js +68 -107
- 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 +655 -260
- 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 +106 -170
- 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 +62 -72
- 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
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* UpgradeService — IDE 集成升级服务
|
|
3
3
|
*
|
|
4
4
|
* 当 AutoSnippet 发布新版本后,老用户执行 `asd upgrade` 即可更新:
|
|
5
|
-
* ① MCP 配置(.cursor/mcp.json + .vscode/
|
|
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)
|
|
@@ -13,15 +13,20 @@
|
|
|
13
13
|
* 不会重建数据库、子仓库或运行时目录。
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
+
import { execSync } from 'node:child_process';
|
|
16
17
|
import {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
copyFileSync,
|
|
19
|
+
existsSync,
|
|
20
|
+
mkdirSync,
|
|
21
|
+
readdirSync,
|
|
22
|
+
readFileSync,
|
|
23
|
+
writeFileSync,
|
|
24
|
+
} from 'node:fs';
|
|
25
|
+
import { dirname, join, resolve } from 'node:path';
|
|
26
|
+
import { fileURLToPath } from 'node:url';
|
|
22
27
|
|
|
23
28
|
const __filename = fileURLToPath(import.meta.url);
|
|
24
|
-
const __dirname
|
|
29
|
+
const __dirname = dirname(__filename);
|
|
25
30
|
|
|
26
31
|
const REPO_ROOT = resolve(__dirname, '..', '..');
|
|
27
32
|
|
|
@@ -52,21 +57,12 @@ export class UpgradeService {
|
|
|
52
57
|
results.push(this._ensureSkillsDir());
|
|
53
58
|
}
|
|
54
59
|
|
|
55
|
-
console.log('');
|
|
56
|
-
console.log('════════════════════════════════════════');
|
|
57
|
-
console.log('✅ 升级完成');
|
|
58
|
-
console.log('════════════════════════════════════════');
|
|
59
|
-
console.log('');
|
|
60
|
-
console.log('📌 请在 Cursor / VSCode / Qoder 中 Reload Window 使更新生效');
|
|
61
|
-
console.log('');
|
|
62
|
-
|
|
63
60
|
return results;
|
|
64
61
|
}
|
|
65
62
|
|
|
66
63
|
/* ═══ MCP 配置 ══════════════════════════════════════ */
|
|
67
64
|
|
|
68
65
|
_upgradeMCP() {
|
|
69
|
-
console.log('[MCP] 更新 IDE MCP 配置...');
|
|
70
66
|
const mcpServerPath = join(REPO_ROOT, 'bin', 'mcp-server.js');
|
|
71
67
|
const nodePath = join(REPO_ROOT, 'node_modules');
|
|
72
68
|
|
|
@@ -79,15 +75,20 @@ export class UpgradeService {
|
|
|
79
75
|
_updateCursorMCP(mcpServerPath, nodePath) {
|
|
80
76
|
const configPath = join(this.projectRoot, '.cursor', 'mcp.json');
|
|
81
77
|
if (!existsSync(configPath)) {
|
|
82
|
-
console.log(' ⚠️ .cursor/mcp.json 不存在,跳过(请先运行 asd setup)');
|
|
83
78
|
return;
|
|
84
79
|
}
|
|
85
80
|
|
|
86
81
|
let config = {};
|
|
87
|
-
try {
|
|
88
|
-
|
|
82
|
+
try {
|
|
83
|
+
config = JSON.parse(readFileSync(configPath, 'utf8'));
|
|
84
|
+
} catch {
|
|
85
|
+
/* */
|
|
86
|
+
}
|
|
87
|
+
if (!config.mcpServers) {
|
|
88
|
+
config.mcpServers = {};
|
|
89
|
+
}
|
|
89
90
|
|
|
90
|
-
config.mcpServers
|
|
91
|
+
config.mcpServers.autosnippet = {
|
|
91
92
|
command: 'node',
|
|
92
93
|
args: [mcpServerPath],
|
|
93
94
|
env: {
|
|
@@ -97,23 +98,26 @@ export class UpgradeService {
|
|
|
97
98
|
};
|
|
98
99
|
|
|
99
100
|
writeFileSync(configPath, JSON.stringify(config, null, 2));
|
|
100
|
-
console.log(' ✅ .cursor/mcp.json');
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
_updateVSCodeMCP(mcpServerPath, nodePath) {
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
console.log(' ℹ️ .vscode/settings.json 不存在,跳过');
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
104
|
+
const vscodeDir = join(this.projectRoot, '.vscode');
|
|
105
|
+
const mcpConfigPath = join(vscodeDir, 'mcp.json');
|
|
109
106
|
|
|
110
|
-
let
|
|
111
|
-
|
|
107
|
+
let config = {};
|
|
108
|
+
if (existsSync(mcpConfigPath)) {
|
|
109
|
+
try {
|
|
110
|
+
config = JSON.parse(readFileSync(mcpConfigPath, 'utf8'));
|
|
111
|
+
} catch {
|
|
112
|
+
/* */
|
|
113
|
+
}
|
|
114
|
+
}
|
|
112
115
|
|
|
113
|
-
if (!
|
|
114
|
-
|
|
116
|
+
if (!config.servers) {
|
|
117
|
+
config.servers = {};
|
|
118
|
+
}
|
|
115
119
|
|
|
116
|
-
|
|
120
|
+
config.servers.autosnippet = {
|
|
117
121
|
type: 'stdio',
|
|
118
122
|
command: 'node',
|
|
119
123
|
args: [mcpServerPath],
|
|
@@ -123,18 +127,15 @@ export class UpgradeService {
|
|
|
123
127
|
},
|
|
124
128
|
};
|
|
125
129
|
|
|
126
|
-
|
|
127
|
-
|
|
130
|
+
mkdirSync(vscodeDir, { recursive: true });
|
|
131
|
+
writeFileSync(mcpConfigPath, JSON.stringify(config, null, 2));
|
|
128
132
|
}
|
|
129
133
|
|
|
130
134
|
/* ═══ Skills ════════════════════════════════════════ */
|
|
131
135
|
|
|
132
136
|
_upgradeSkills() {
|
|
133
|
-
console.log('[Skills] 重新安装 Cursor Skills...');
|
|
134
|
-
|
|
135
137
|
const installScript = join(REPO_ROOT, 'scripts', 'install-cursor-skill.js');
|
|
136
138
|
if (!existsSync(installScript)) {
|
|
137
|
-
console.log(' ⚠️ install-cursor-skill.js 不存在,跳过');
|
|
138
139
|
return;
|
|
139
140
|
}
|
|
140
141
|
|
|
@@ -152,11 +153,8 @@ export class UpgradeService {
|
|
|
152
153
|
/* ═══ Cursor Rules ══════════════════════════════════ */
|
|
153
154
|
|
|
154
155
|
_upgradeCursorRules() {
|
|
155
|
-
console.log('[Rules] 更新 Cursor Rules...');
|
|
156
|
-
|
|
157
156
|
const src = join(REPO_ROOT, 'templates', 'cursor-rules', 'autosnippet-conventions.mdc');
|
|
158
157
|
if (!existsSync(src)) {
|
|
159
|
-
console.log(' ⚠️ 模板不存在,跳过');
|
|
160
158
|
return;
|
|
161
159
|
}
|
|
162
160
|
|
|
@@ -164,7 +162,6 @@ export class UpgradeService {
|
|
|
164
162
|
const dest = join(destDir, 'autosnippet-conventions.mdc');
|
|
165
163
|
mkdirSync(destDir, { recursive: true });
|
|
166
164
|
copyFileSync(src, dest);
|
|
167
|
-
console.log(' ✅ .cursor/rules/autosnippet-conventions.mdc');
|
|
168
165
|
|
|
169
166
|
// 动态生成 4 通道交付物料(如 ServiceContainer 已初始化)
|
|
170
167
|
this._triggerCursorDelivery();
|
|
@@ -180,15 +177,10 @@ export class UpgradeService {
|
|
|
180
177
|
const container = getServiceContainer();
|
|
181
178
|
if (container.services.cursorDeliveryPipeline) {
|
|
182
179
|
const pipeline = container.get('cursorDeliveryPipeline');
|
|
183
|
-
pipeline
|
|
184
|
-
.
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
`${result.channelD?.documentsCount || 0} documents`);
|
|
188
|
-
})
|
|
189
|
-
.catch(err => {
|
|
190
|
-
console.log(` ⚠️ Cursor Delivery 跳过: ${err.message}`);
|
|
191
|
-
});
|
|
180
|
+
pipeline
|
|
181
|
+
.deliver()
|
|
182
|
+
.then((_result) => {})
|
|
183
|
+
.catch((_err) => {});
|
|
192
184
|
}
|
|
193
185
|
})
|
|
194
186
|
.catch(() => {
|
|
@@ -204,13 +196,11 @@ export class UpgradeService {
|
|
|
204
196
|
* @param {string} targetDirName - '.qoder' 或 '.trae'
|
|
205
197
|
*/
|
|
206
198
|
_upgradeMirrorIDE(targetDirName) {
|
|
207
|
-
const
|
|
208
|
-
console.log(`[${label}] 更新 ${label} Rules...`);
|
|
199
|
+
const _label = targetDirName.replace('.', '').charAt(0).toUpperCase() + targetDirName.slice(2);
|
|
209
200
|
|
|
210
201
|
// 镜像 .cursor/rules/ 中的 autosnippet-* 文件
|
|
211
202
|
const cursorRulesDir = join(this.projectRoot, '.cursor', 'rules');
|
|
212
203
|
if (!existsSync(cursorRulesDir)) {
|
|
213
|
-
console.log(' ⚠️ .cursor/rules/ 不存在,跳过');
|
|
214
204
|
return;
|
|
215
205
|
}
|
|
216
206
|
|
|
@@ -218,29 +208,28 @@ export class UpgradeService {
|
|
|
218
208
|
mkdirSync(targetRulesDir, { recursive: true });
|
|
219
209
|
|
|
220
210
|
// 只复制 autosnippet- 前缀的文件,不触碰用户自己创建的规则
|
|
221
|
-
const files = readdirSync(cursorRulesDir).filter(
|
|
222
|
-
(f.endsWith('.mdc') || f.endsWith('.md')) && f.startsWith('autosnippet-')
|
|
211
|
+
const files = readdirSync(cursorRulesDir).filter(
|
|
212
|
+
(f) => (f.endsWith('.mdc') || f.endsWith('.md')) && f.startsWith('autosnippet-')
|
|
223
213
|
);
|
|
224
214
|
for (const file of files) {
|
|
225
215
|
const destName = file.endsWith('.mdc') ? file.replace(/\.mdc$/, '.md') : file;
|
|
226
216
|
copyFileSync(join(cursorRulesDir, file), join(targetRulesDir, destName));
|
|
227
217
|
}
|
|
228
|
-
console.log(` ✅ ${targetDirName}/rules/ (镜像 ${files.length} 个 autosnippet 规则文件)`);
|
|
229
218
|
|
|
230
219
|
// 镜像 .cursor/skills/ 中的 autosnippet-* 技能目录
|
|
231
220
|
const cursorSkillsDir = join(this.projectRoot, '.cursor', 'skills');
|
|
232
221
|
if (existsSync(cursorSkillsDir)) {
|
|
233
222
|
const targetSkillsDir = join(this.projectRoot, targetDirName, 'skills');
|
|
234
223
|
mkdirSync(targetSkillsDir, { recursive: true });
|
|
235
|
-
const skillDirs = readdirSync(cursorSkillsDir, { withFileTypes: true })
|
|
236
|
-
|
|
224
|
+
const skillDirs = readdirSync(cursorSkillsDir, { withFileTypes: true }).filter(
|
|
225
|
+
(d) => d.isDirectory() && d.name.startsWith('autosnippet-')
|
|
226
|
+
);
|
|
237
227
|
for (const dir of skillDirs) {
|
|
238
228
|
this._copyDirRecursiveSkill(
|
|
239
229
|
join(cursorSkillsDir, dir.name),
|
|
240
230
|
join(targetSkillsDir, dir.name)
|
|
241
231
|
);
|
|
242
232
|
}
|
|
243
|
-
console.log(` ✅ ${targetDirName}/skills/ (镜像 ${skillDirs.length} 个 autosnippet 技能)`);
|
|
244
233
|
}
|
|
245
234
|
}
|
|
246
235
|
|
|
@@ -261,11 +250,8 @@ export class UpgradeService {
|
|
|
261
250
|
/* ═══ Copilot Instructions ══════════════════════════ */
|
|
262
251
|
|
|
263
252
|
_upgradeCopilotInstructions() {
|
|
264
|
-
console.log('[Instructions] 更新 Copilot Instructions...');
|
|
265
|
-
|
|
266
253
|
const src = join(REPO_ROOT, 'templates', 'copilot-instructions.md');
|
|
267
254
|
if (!existsSync(src)) {
|
|
268
|
-
console.log(' ⚠️ 模板不存在,跳过');
|
|
269
255
|
return;
|
|
270
256
|
}
|
|
271
257
|
|
|
@@ -273,24 +259,19 @@ export class UpgradeService {
|
|
|
273
259
|
const dest = join(destDir, 'copilot-instructions.md');
|
|
274
260
|
mkdirSync(destDir, { recursive: true });
|
|
275
261
|
copyFileSync(src, dest);
|
|
276
|
-
console.log(' ✅ .github/copilot-instructions.md');
|
|
277
262
|
}
|
|
278
263
|
|
|
279
264
|
/* ═══ Constitution ══════════════════════════════════ */
|
|
280
265
|
|
|
281
266
|
_upgradeConstitution() {
|
|
282
|
-
console.log('[Constitution] 更新权限宪法...');
|
|
283
|
-
|
|
284
267
|
const src = join(REPO_ROOT, 'templates', 'constitution.yaml');
|
|
285
268
|
if (!existsSync(src)) {
|
|
286
|
-
console.log(' ⚠️ 模板不存在,跳过');
|
|
287
269
|
return;
|
|
288
270
|
}
|
|
289
271
|
|
|
290
272
|
// 子仓库路径:AutoSnippet/constitution.yaml
|
|
291
273
|
const dest = join(this.projectRoot, 'AutoSnippet', 'constitution.yaml');
|
|
292
274
|
if (!existsSync(join(this.projectRoot, 'AutoSnippet'))) {
|
|
293
|
-
console.log(' ⚠️ AutoSnippet/ 目录不存在,跳过(请先运行 asd setup)');
|
|
294
275
|
return;
|
|
295
276
|
}
|
|
296
277
|
|
|
@@ -299,32 +280,24 @@ export class UpgradeService {
|
|
|
299
280
|
const oldContent = readFileSync(dest, 'utf8');
|
|
300
281
|
const newContent = readFileSync(src, 'utf8');
|
|
301
282
|
if (oldContent === newContent) {
|
|
302
|
-
console.log(' ℹ️ constitution.yaml 已是最新版本');
|
|
303
283
|
return;
|
|
304
284
|
}
|
|
305
|
-
const backupPath = dest
|
|
285
|
+
const backupPath = `${dest}.bak`;
|
|
306
286
|
copyFileSync(dest, backupPath);
|
|
307
|
-
console.log(` 📦 已备份旧版本 → constitution.yaml.bak`);
|
|
308
287
|
}
|
|
309
288
|
|
|
310
289
|
copyFileSync(src, dest);
|
|
311
|
-
console.log(' ✅ AutoSnippet/constitution.yaml');
|
|
312
290
|
|
|
313
291
|
// 如果子仓库是 git 仓库,提示用户提交
|
|
314
292
|
const gitDir = join(this.projectRoot, 'AutoSnippet', '.git');
|
|
315
293
|
if (existsSync(gitDir)) {
|
|
316
|
-
console.log(' 💡 子仓库已更新,请手动提交并推送:');
|
|
317
|
-
console.log(' cd AutoSnippet && git add constitution.yaml && git commit -m "Upgrade constitution" && git push');
|
|
318
294
|
}
|
|
319
295
|
}
|
|
320
296
|
/* ═══ Skills Template ════════════════════════════════ */
|
|
321
297
|
|
|
322
298
|
_upgradeSkillsTemplate() {
|
|
323
|
-
console.log('[Skills Template] 更新 autosnippet-skills.mdc...');
|
|
324
|
-
|
|
325
299
|
const src = join(REPO_ROOT, 'templates', 'cursor-rules', 'autosnippet-skills.mdc');
|
|
326
300
|
if (!existsSync(src)) {
|
|
327
|
-
console.log(' ⚠️ 模板不存在,跳过');
|
|
328
301
|
return;
|
|
329
302
|
}
|
|
330
303
|
|
|
@@ -332,17 +305,13 @@ export class UpgradeService {
|
|
|
332
305
|
const dest = join(destDir, 'autosnippet-skills.mdc');
|
|
333
306
|
mkdirSync(destDir, { recursive: true });
|
|
334
307
|
copyFileSync(src, dest);
|
|
335
|
-
console.log(' ✅ .cursor/rules/autosnippet-skills.mdc');
|
|
336
308
|
}
|
|
337
309
|
|
|
338
310
|
/* ═══ .gitignore ════════════════════════════════════ */
|
|
339
311
|
|
|
340
312
|
_upgradeGitignore() {
|
|
341
|
-
console.log('[Gitignore] 更新 .gitignore 规则...');
|
|
342
|
-
|
|
343
313
|
const giPath = join(this.projectRoot, '.gitignore');
|
|
344
314
|
if (!existsSync(giPath)) {
|
|
345
|
-
console.log(' ℹ️ .gitignore 不存在,跳过');
|
|
346
315
|
return;
|
|
347
316
|
}
|
|
348
317
|
|
|
@@ -353,28 +322,24 @@ export class UpgradeService {
|
|
|
353
322
|
if (content.includes('.autosnippet/') && !content.includes('.autosnippet/*')) {
|
|
354
323
|
content = content.replace(/^\.autosnippet\/$/m, '.autosnippet/*');
|
|
355
324
|
changed = true;
|
|
356
|
-
console.log(' ✅ .autosnippet/ → .autosnippet/*(升级为精细忽略)');
|
|
357
325
|
}
|
|
358
326
|
|
|
359
327
|
// 确保有 .autosnippet/*
|
|
360
328
|
if (!content.includes('.autosnippet/') && !content.includes('.autosnippet/*')) {
|
|
361
329
|
content += `\n# AutoSnippet 运行时缓存(不入库)\n.autosnippet/*\n`;
|
|
362
330
|
changed = true;
|
|
363
|
-
console.log(' ✅ += .autosnippet/*');
|
|
364
331
|
}
|
|
365
332
|
|
|
366
333
|
// 确保 config.json 跟踪
|
|
367
334
|
if (!content.includes('!.autosnippet/config.json')) {
|
|
368
335
|
content += `!.autosnippet/config.json\n`;
|
|
369
336
|
changed = true;
|
|
370
|
-
console.log(' ✅ += !.autosnippet/config.json');
|
|
371
337
|
}
|
|
372
338
|
|
|
373
339
|
// 清理旧版本的 .autosnippet/skills/ negation(已迁移到 AutoSnippet/skills/)
|
|
374
340
|
if (content.includes('!.autosnippet/skills/')) {
|
|
375
341
|
content = content.replace(/^!?\.autosnippet\/skills\/.*\n?/gm, '');
|
|
376
342
|
changed = true;
|
|
377
|
-
console.log(' ✅ 移除旧版 .autosnippet/skills/ 规则(已迁移到 AutoSnippet/skills/)');
|
|
378
343
|
}
|
|
379
344
|
|
|
380
345
|
// ── v2.8.1: 新增缺失的 gitignore 规则 ──
|
|
@@ -383,68 +348,61 @@ export class UpgradeService {
|
|
|
383
348
|
if (!content.includes('_draft_*.md')) {
|
|
384
349
|
content += `\n# AutoSnippet AI 草稿文件(项目根目录临时文件)\n_draft_*.md\n`;
|
|
385
350
|
changed = true;
|
|
386
|
-
console.log(' ✅ += _draft_*.md');
|
|
387
351
|
}
|
|
388
352
|
|
|
389
353
|
// .DS_Store — macOS 元数据
|
|
390
354
|
if (!content.includes('.DS_Store')) {
|
|
391
355
|
content += `\n# macOS 元数据\n.DS_Store\n`;
|
|
392
356
|
changed = true;
|
|
393
|
-
console.log(' ✅ += .DS_Store');
|
|
394
357
|
}
|
|
395
358
|
|
|
396
359
|
// nohup.out — 后台进程输出
|
|
397
360
|
if (!content.includes('nohup.out')) {
|
|
398
361
|
content += `nohup.out\n`;
|
|
399
362
|
changed = true;
|
|
400
|
-
console.log(' ✅ += nohup.out');
|
|
401
363
|
}
|
|
402
364
|
|
|
403
365
|
// *.sw[a-p] — vim swap 文件
|
|
404
366
|
if (!content.match(/\*\.sw\[a-p\]/)) {
|
|
405
367
|
content += `*.sw[a-p]\n`;
|
|
406
368
|
changed = true;
|
|
407
|
-
console.log(' ✅ += *.sw[a-p]');
|
|
408
369
|
}
|
|
409
370
|
|
|
410
371
|
// .autosnippet-drafts/ — AI 草稿目录
|
|
411
372
|
if (!content.includes('.autosnippet-drafts')) {
|
|
412
373
|
content += `\n# AutoSnippet AI 草稿(临时)\n.autosnippet-drafts/\n`;
|
|
413
374
|
changed = true;
|
|
414
|
-
console.log(' ✅ += .autosnippet-drafts/');
|
|
415
375
|
}
|
|
416
376
|
|
|
417
377
|
// .env — 环境变量
|
|
418
378
|
if (!content.includes('.env') || (!content.match(/^\.env$/m) && !content.match(/^\.env\s/m))) {
|
|
419
379
|
content += `\n# AutoSnippet 环境变量(含 API Key,不入库)\n.env\n`;
|
|
420
380
|
changed = true;
|
|
421
|
-
console.log(' ✅ += .env');
|
|
422
381
|
}
|
|
423
382
|
|
|
424
383
|
// logs/ — 运行日志
|
|
425
384
|
if (!content.match(/^logs\/?$/m)) {
|
|
426
385
|
content += `\n# AutoSnippet 运行日志\nlogs/\n`;
|
|
427
386
|
changed = true;
|
|
428
|
-
console.log(' ✅ += logs/');
|
|
429
387
|
}
|
|
430
388
|
|
|
431
389
|
// 确保 AutoSnippet/ 不被忽略
|
|
432
390
|
const lines = content.split('\n');
|
|
433
|
-
const hasIgnoreAS = lines.some(l => {
|
|
391
|
+
const hasIgnoreAS = lines.some((l) => {
|
|
434
392
|
const t = l.trim();
|
|
435
|
-
return (
|
|
393
|
+
return (
|
|
394
|
+
(t === 'AutoSnippet/' || t === 'AutoSnippet') && !t.startsWith('#') && !t.startsWith('!')
|
|
395
|
+
);
|
|
436
396
|
});
|
|
437
|
-
const hasNegation = lines.some(l => l.trim() === '!AutoSnippet/');
|
|
397
|
+
const hasNegation = lines.some((l) => l.trim() === '!AutoSnippet/');
|
|
438
398
|
if (hasIgnoreAS && !hasNegation) {
|
|
439
399
|
content += `\n# AutoSnippet 知识库必须入库(取消上方忽略)\n!AutoSnippet/\n`;
|
|
440
400
|
changed = true;
|
|
441
|
-
console.log(' ✅ += !AutoSnippet/ (取消忽略)');
|
|
442
401
|
}
|
|
443
402
|
|
|
444
403
|
if (changed) {
|
|
445
404
|
writeFileSync(giPath, content);
|
|
446
405
|
} else {
|
|
447
|
-
console.log(' ℹ️ .gitignore 已是最新版本');
|
|
448
406
|
}
|
|
449
407
|
}
|
|
450
408
|
|
|
@@ -454,10 +412,12 @@ export class UpgradeService {
|
|
|
454
412
|
const oldSkillsDir = join(this.projectRoot, '.autosnippet', 'skills');
|
|
455
413
|
const newSkillsDir = join(this.projectRoot, 'AutoSnippet', 'skills');
|
|
456
414
|
|
|
457
|
-
if (!existsSync(oldSkillsDir))
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
415
|
+
if (!existsSync(oldSkillsDir)) {
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
if (!existsSync(join(this.projectRoot, 'AutoSnippet'))) {
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
461
421
|
|
|
462
422
|
try {
|
|
463
423
|
mkdirSync(newSkillsDir, { recursive: true });
|
|
@@ -465,11 +425,12 @@ export class UpgradeService {
|
|
|
465
425
|
let migrated = 0;
|
|
466
426
|
|
|
467
427
|
for (const entry of entries) {
|
|
468
|
-
if (!entry.isDirectory())
|
|
428
|
+
if (!entry.isDirectory()) {
|
|
429
|
+
continue;
|
|
430
|
+
}
|
|
469
431
|
const src = join(oldSkillsDir, entry.name);
|
|
470
432
|
const dest = join(newSkillsDir, entry.name);
|
|
471
433
|
if (existsSync(dest)) {
|
|
472
|
-
console.log(` ℹ️ ${entry.name} 已存在于新路径,跳过`);
|
|
473
434
|
continue;
|
|
474
435
|
}
|
|
475
436
|
// 复制目录
|
|
@@ -478,10 +439,7 @@ export class UpgradeService {
|
|
|
478
439
|
}
|
|
479
440
|
|
|
480
441
|
if (migrated > 0) {
|
|
481
|
-
console.log(` ✅ 已迁移 ${migrated} 个 Skill 到 AutoSnippet/skills/`);
|
|
482
|
-
console.log(' 💡 确认迁移无误后可删除旧目录: rm -rf .autosnippet/skills/');
|
|
483
442
|
} else {
|
|
484
|
-
console.log(' ℹ️ 无需迁移(所有 Skill 已存在于新路径)');
|
|
485
443
|
}
|
|
486
444
|
} catch (e) {
|
|
487
445
|
console.error(` ❌ 迁移失败: ${e.message}`);
|
|
@@ -492,11 +450,14 @@ export class UpgradeService {
|
|
|
492
450
|
|
|
493
451
|
_ensureSkillsDir() {
|
|
494
452
|
const skillsDir = join(this.projectRoot, 'AutoSnippet', 'skills');
|
|
495
|
-
if (!existsSync(join(this.projectRoot, 'AutoSnippet')))
|
|
496
|
-
|
|
453
|
+
if (!existsSync(join(this.projectRoot, 'AutoSnippet'))) {
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
if (existsSync(skillsDir)) {
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
497
459
|
|
|
498
460
|
mkdirSync(skillsDir, { recursive: true });
|
|
499
|
-
console.log('[Skills] ✅ 创建 AutoSnippet/skills/ 目录');
|
|
500
461
|
}
|
|
501
462
|
}
|
|
502
463
|
|