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