autosnippet 3.2.21 → 3.3.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/dashboard/dist/assets/icons-BJ2mUBi8.js +1 -0
- package/dashboard/dist/assets/index-B659K9t5.js +128 -0
- package/dashboard/dist/assets/index-NCm40PMD.css +1 -0
- package/dashboard/dist/index.html +3 -3
- package/dist/bin/cli.d.ts +1 -1
- package/dist/bin/cli.js +244 -261
- package/dist/lib/agent/context/ExplorationTracker.d.ts +2 -0
- package/dist/lib/agent/context/ExplorationTracker.js +21 -3
- package/dist/lib/agent/core/ToolExecutionPipeline.d.ts +3 -1
- package/dist/lib/agent/core/ToolExecutionPipeline.js +8 -1
- package/dist/lib/agent/forge/DynamicComposer.d.ts +58 -0
- package/dist/lib/agent/forge/DynamicComposer.js +99 -0
- package/dist/lib/agent/forge/SandboxRunner.d.ts +60 -0
- package/dist/lib/agent/forge/SandboxRunner.js +251 -0
- package/dist/lib/agent/forge/TemporaryToolRegistry.d.ts +76 -0
- package/dist/lib/agent/forge/TemporaryToolRegistry.js +154 -0
- package/dist/lib/agent/forge/ToolForge.d.ts +92 -0
- package/dist/lib/agent/forge/ToolForge.js +239 -0
- package/dist/lib/agent/forge/ToolRequirementAnalyzer.d.ts +44 -0
- package/dist/lib/agent/forge/ToolRequirementAnalyzer.js +119 -0
- package/dist/lib/agent/tools/ToolRegistry.d.ts +2 -0
- package/dist/lib/agent/tools/ToolRegistry.js +4 -0
- package/dist/lib/agent/tools/composite.js +0 -1
- package/dist/lib/agent/tools/index.d.ts +2 -50
- package/dist/lib/agent/tools/index.js +2 -3
- package/dist/lib/agent/tools/lifecycle.d.ts +1 -58
- package/dist/lib/agent/tools/lifecycle.js +2 -75
- package/dist/lib/cli/SetupService.d.ts +46 -2
- package/dist/lib/cli/SetupService.js +2 -27
- package/dist/lib/cli/deploy/FileManifest.d.ts +0 -21
- package/dist/lib/cli/deploy/FileManifest.js +0 -11
- package/dist/lib/{platform/ios/spm → core/discovery}/SpmDiscoverer.d.ts +2 -5
- package/dist/lib/{platform/ios/spm → core/discovery}/SpmDiscoverer.js +159 -44
- package/dist/lib/core/discovery/index.d.ts +1 -1
- package/dist/lib/core/discovery/index.js +2 -2
- package/dist/lib/domain/knowledge/KnowledgeEntry.d.ts +10 -0
- package/dist/lib/domain/knowledge/KnowledgeEntry.js +2 -0
- package/dist/lib/domain/knowledge/Lifecycle.d.ts +19 -2
- package/dist/lib/domain/knowledge/Lifecycle.js +32 -6
- package/dist/lib/domain/knowledge/UnifiedValidator.d.ts +1 -5
- package/dist/lib/domain/knowledge/UnifiedValidator.js +7 -44
- package/dist/lib/domain/knowledge/values/Stats.d.ts +29 -0
- package/dist/lib/domain/knowledge/values/Stats.js +41 -0
- package/dist/lib/external/mcp/McpServer.d.ts +19 -38
- package/dist/lib/external/mcp/McpServer.js +145 -117
- package/dist/lib/external/mcp/autoApproveInjector.js +0 -2
- package/dist/lib/external/mcp/handlers/bootstrap/MissionBriefingBuilder.d.ts +26 -1
- package/dist/lib/external/mcp/handlers/bootstrap/MissionBriefingBuilder.js +41 -0
- package/dist/lib/external/mcp/handlers/bootstrap/pipeline/orchestrator.js +49 -0
- package/dist/lib/external/mcp/handlers/bootstrap/shared/bootstrap-phases.d.ts +3 -0
- package/dist/lib/external/mcp/handlers/bootstrap/shared/bootstrap-phases.js +27 -0
- package/dist/lib/external/mcp/handlers/bootstrap/skills.js +1 -1
- package/dist/lib/external/mcp/handlers/bootstrap-external.js +1 -0
- package/dist/lib/external/mcp/handlers/bootstrap-internal.js +2 -0
- package/dist/lib/external/mcp/handlers/consolidated.d.ts +116 -6
- package/dist/lib/external/mcp/handlers/consolidated.js +251 -71
- package/dist/lib/external/mcp/handlers/guard.d.ts +150 -0
- package/dist/lib/external/mcp/handlers/guard.js +245 -8
- package/dist/lib/external/mcp/handlers/knowledge.d.ts +0 -29
- package/dist/lib/external/mcp/handlers/knowledge.js +1 -76
- package/dist/lib/external/mcp/handlers/panorama.d.ts +36 -0
- package/dist/lib/external/mcp/handlers/panorama.js +156 -0
- package/dist/lib/external/mcp/handlers/system.d.ts +2 -54
- package/dist/lib/external/mcp/handlers/system.js +3 -113
- package/dist/lib/external/mcp/handlers/task.d.ts +13 -24
- package/dist/lib/external/mcp/handlers/task.js +217 -557
- package/dist/lib/external/mcp/handlers/types.d.ts +91 -8
- package/dist/lib/external/mcp/handlers/types.js +18 -1
- package/dist/lib/external/mcp/handlers/wiki-external.d.ts +18 -1
- package/dist/lib/external/mcp/handlers/wiki-external.js +16 -1
- package/dist/lib/external/mcp/tools.d.ts +14 -20
- package/dist/lib/external/mcp/tools.js +62 -91
- package/dist/lib/http/HttpServer.js +52 -6
- package/dist/lib/http/routes/{snippets.d.ts → audit.d.ts} +4 -2
- package/dist/lib/http/routes/audit.js +51 -0
- package/dist/lib/http/routes/commands.d.ts +1 -1
- package/dist/lib/http/routes/commands.js +1 -66
- package/dist/lib/http/routes/guardReport.d.ts +10 -0
- package/dist/lib/http/routes/guardReport.js +143 -0
- package/dist/lib/http/routes/knowledge.js +32 -1
- package/dist/lib/http/routes/panorama.d.ts +11 -0
- package/dist/lib/http/routes/panorama.js +322 -0
- package/dist/lib/http/routes/remote.js +0 -5
- package/dist/lib/http/routes/signals.d.ts +10 -0
- package/dist/lib/http/routes/signals.js +104 -0
- package/dist/lib/http/routes/task.d.ts +2 -3
- package/dist/lib/http/routes/task.js +17 -347
- package/dist/lib/http/routes/violations.js +1 -1
- package/dist/lib/infrastructure/audit/AuditLogger.d.ts +6 -1
- package/dist/lib/infrastructure/audit/AuditLogger.js +14 -1
- package/dist/lib/infrastructure/database/drizzle/schema.d.ts +181 -583
- package/dist/lib/infrastructure/database/drizzle/schema.js +28 -69
- package/dist/lib/infrastructure/database/migrations/004_evolution_proposals.d.ts +8 -0
- package/dist/lib/infrastructure/database/migrations/004_evolution_proposals.js +43 -0
- package/dist/lib/infrastructure/logging/Logger.d.ts +2 -0
- package/dist/lib/infrastructure/logging/Logger.js +34 -7
- package/dist/lib/infrastructure/monitoring/ErrorTracker.js +3 -1
- package/dist/lib/infrastructure/monitoring/PerformanceMonitor.d.ts +2 -2
- package/dist/lib/infrastructure/monitoring/PerformanceMonitor.js +12 -10
- package/dist/lib/infrastructure/notification/LarkNotifier.d.ts +24 -0
- package/dist/lib/infrastructure/notification/LarkNotifier.js +97 -0
- package/dist/lib/infrastructure/report/ReportStore.d.ts +45 -0
- package/dist/lib/infrastructure/report/ReportStore.js +133 -0
- package/dist/lib/infrastructure/signal/SignalAggregator.d.ts +18 -0
- package/dist/lib/infrastructure/signal/SignalAggregator.js +84 -0
- package/dist/lib/infrastructure/signal/SignalBridge.d.ts +13 -0
- package/dist/lib/infrastructure/signal/SignalBridge.js +20 -0
- package/dist/lib/infrastructure/signal/SignalBus.d.ts +63 -0
- package/dist/lib/infrastructure/signal/SignalBus.js +106 -0
- package/dist/lib/infrastructure/signal/SignalTraceWriter.d.ts +36 -0
- package/dist/lib/infrastructure/signal/SignalTraceWriter.js +130 -0
- package/dist/lib/injection/ServiceContainer.js +6 -0
- package/dist/lib/injection/ServiceMap.d.ts +16 -19
- package/dist/lib/injection/modules/AgentModule.d.ts +1 -1
- package/dist/lib/injection/modules/AgentModule.js +7 -1
- package/dist/lib/injection/modules/AppModule.d.ts +3 -4
- package/dist/lib/injection/modules/AppModule.js +7 -43
- package/dist/lib/injection/modules/GuardModule.js +59 -2
- package/dist/lib/injection/modules/InfraModule.d.ts +0 -1
- package/dist/lib/injection/modules/InfraModule.js +9 -7
- package/dist/lib/injection/modules/KnowledgeModule.js +51 -0
- package/dist/lib/injection/modules/PanoramaModule.d.ts +18 -0
- package/dist/lib/injection/modules/PanoramaModule.js +76 -0
- package/dist/lib/injection/modules/SignalModule.d.ts +10 -0
- package/dist/lib/injection/modules/SignalModule.js +84 -0
- package/dist/lib/repository/knowledge/KnowledgeRepository.impl.d.ts +1 -0
- package/dist/lib/repository/knowledge/KnowledgeRepository.impl.js +6 -0
- package/dist/lib/service/bootstrap/BootstrapTaskManager.d.ts +3 -1
- package/dist/lib/service/bootstrap/BootstrapTaskManager.js +20 -1
- package/dist/lib/service/delivery/AgentInstructionsGenerator.js +4 -5
- package/dist/lib/service/delivery/CursorDeliveryPipeline.d.ts +3 -1
- package/dist/lib/service/delivery/CursorDeliveryPipeline.js +13 -10
- package/dist/lib/service/delivery/RulesGenerator.js +3 -2
- package/dist/lib/service/evolution/ConsolidationAdvisor.d.ts +114 -0
- package/dist/lib/service/evolution/ConsolidationAdvisor.js +542 -0
- package/dist/lib/service/evolution/ContradictionDetector.d.ts +54 -0
- package/dist/lib/service/evolution/ContradictionDetector.js +253 -0
- package/dist/lib/service/evolution/DecayDetector.d.ts +71 -0
- package/dist/lib/service/evolution/DecayDetector.js +244 -0
- package/dist/lib/service/evolution/EnhancementSuggester.d.ts +38 -0
- package/dist/lib/service/evolution/EnhancementSuggester.js +220 -0
- package/dist/lib/service/evolution/KnowledgeMetabolism.d.ts +82 -0
- package/dist/lib/service/evolution/KnowledgeMetabolism.js +167 -0
- package/dist/lib/service/evolution/RedundancyAnalyzer.d.ts +53 -0
- package/dist/lib/service/evolution/RedundancyAnalyzer.js +210 -0
- package/dist/lib/service/evolution/StagingManager.d.ts +57 -0
- package/dist/lib/service/evolution/StagingManager.js +201 -0
- package/dist/lib/service/guard/ComplianceReporter.d.ts +42 -2
- package/dist/lib/service/guard/ComplianceReporter.js +43 -5
- package/dist/lib/service/guard/CoverageAnalyzer.d.ts +54 -0
- package/dist/lib/service/guard/CoverageAnalyzer.js +149 -0
- package/dist/lib/service/guard/GuardCheckEngine.d.ts +55 -1
- package/dist/lib/service/guard/GuardCheckEngine.js +508 -15
- package/dist/lib/service/guard/GuardFeedbackLoop.d.ts +3 -0
- package/dist/lib/service/guard/GuardFeedbackLoop.js +9 -0
- package/dist/lib/service/guard/ReverseGuard.d.ts +73 -0
- package/dist/lib/service/guard/ReverseGuard.js +256 -0
- package/dist/lib/service/guard/RuleLearner.d.ts +12 -0
- package/dist/lib/service/guard/RuleLearner.js +38 -0
- package/dist/lib/service/guard/UncertaintyCollector.d.ts +83 -0
- package/dist/lib/service/guard/UncertaintyCollector.js +149 -0
- package/dist/lib/service/guard/ViolationsStore.d.ts +1 -0
- package/dist/lib/service/guard/ViolationsStore.js +33 -3
- package/dist/lib/service/knowledge/ConfidenceRouter.d.ts +13 -0
- package/dist/lib/service/knowledge/ConfidenceRouter.js +14 -0
- package/dist/lib/service/knowledge/KnowledgeService.js +22 -4
- package/dist/lib/service/module/ModuleService.js +3 -13
- package/dist/lib/service/panorama/CouplingAnalyzer.d.ts +27 -0
- package/dist/lib/service/panorama/CouplingAnalyzer.js +192 -0
- package/dist/lib/service/panorama/DimensionAnalyzer.d.ts +28 -0
- package/dist/lib/service/panorama/DimensionAnalyzer.js +320 -0
- package/dist/lib/service/panorama/LayerInferrer.d.ts +19 -0
- package/dist/lib/service/panorama/LayerInferrer.js +182 -0
- package/dist/lib/service/panorama/ModuleDiscoverer.d.ts +24 -0
- package/dist/lib/service/panorama/ModuleDiscoverer.js +185 -0
- package/dist/lib/service/panorama/PanoramaAggregator.d.ts +29 -0
- package/dist/lib/service/panorama/PanoramaAggregator.js +228 -0
- package/dist/lib/service/panorama/PanoramaScanner.d.ts +52 -0
- package/dist/lib/service/panorama/PanoramaScanner.js +188 -0
- package/dist/lib/service/panorama/PanoramaService.d.ts +108 -0
- package/dist/lib/service/panorama/PanoramaService.js +220 -0
- package/dist/lib/service/panorama/PanoramaTypes.d.ts +134 -0
- package/dist/lib/service/panorama/PanoramaTypes.js +6 -0
- package/dist/lib/service/panorama/RoleRefiner.d.ts +48 -0
- package/dist/lib/service/panorama/RoleRefiner.js +535 -0
- package/dist/lib/service/search/MultiSignalRanker.d.ts +1 -0
- package/dist/lib/service/search/MultiSignalRanker.js +16 -0
- package/dist/lib/service/search/SearchEngine.d.ts +1 -0
- package/dist/lib/service/search/SearchEngine.js +9 -1
- package/dist/lib/service/search/SearchTypes.d.ts +2 -0
- package/dist/lib/service/signal/HitRecorder.d.ts +68 -0
- package/dist/lib/service/signal/HitRecorder.js +173 -0
- package/dist/lib/service/skills/SignalCollector.d.ts +3 -1
- package/dist/lib/service/skills/SignalCollector.js +31 -1
- package/dist/lib/service/task/IntentExtractor.d.ts +58 -0
- package/dist/lib/service/task/IntentExtractor.js +142 -0
- package/dist/lib/service/task/PrimeSearchPipeline.d.ts +54 -0
- package/dist/lib/service/task/PrimeSearchPipeline.js +98 -0
- package/dist/lib/shared/constants.d.ts +0 -15
- package/dist/lib/shared/constants.js +0 -10
- package/dist/lib/shared/schemas/config.d.ts +4 -1
- package/dist/lib/shared/schemas/config.js +8 -1
- package/dist/lib/shared/schemas/mcp-tools.d.ts +41 -96
- package/dist/lib/shared/schemas/mcp-tools.js +59 -119
- package/dist/scripts/analyze-signals.d.ts +20 -0
- package/dist/scripts/analyze-signals.js +155 -0
- package/dist/scripts/diagnose-mcp.js +1 -1
- package/dist/scripts/release.js +2 -10
- package/package.json +4 -19
- package/skills/autosnippet-devdocs/SKILL.md +11 -8
- package/templates/claude-code/hooks/autosnippet-session.sh +10 -15
- package/templates/cursor-hooks/hooks/session-start.sh +1 -1
- package/templates/instructions/agent-static.md +2 -1
- package/templates/instructions/conventions.md +5 -6
- package/templates/recipes-setup/README.md +1 -2
- package/dashboard/dist/assets/icons-C1dUryS-.js +0 -1
- package/dashboard/dist/assets/index-D0whuycy.css +0 -1
- package/dashboard/dist/assets/index-DdvZE4Yd.js +0 -128
- package/dist/lib/domain/task/Task.d.ts +0 -140
- package/dist/lib/domain/task/Task.js +0 -254
- package/dist/lib/domain/task/TaskDependency.d.ts +0 -23
- package/dist/lib/domain/task/TaskDependency.js +0 -34
- package/dist/lib/domain/task/TaskIdGenerator.d.ts +0 -40
- package/dist/lib/domain/task/TaskIdGenerator.js +0 -75
- package/dist/lib/domain/task/index.d.ts +0 -4
- package/dist/lib/domain/task/index.js +0 -4
- package/dist/lib/http/routes/snippets.js +0 -49
- package/dist/lib/infrastructure/database/migrations/002_add_tasks.d.ts +0 -11
- package/dist/lib/infrastructure/database/migrations/002_add_tasks.js +0 -86
- package/dist/lib/platform/ClipboardManager.d.ts +0 -24
- package/dist/lib/platform/ClipboardManager.js +0 -142
- package/dist/lib/platform/NativeUi.d.ts +0 -53
- package/dist/lib/platform/NativeUi.js +0 -284
- package/dist/lib/platform/ios/index.d.ts +0 -38
- package/dist/lib/platform/ios/index.js +0 -42
- package/dist/lib/platform/ios/routes/spm.d.ts +0 -9
- package/dist/lib/platform/ios/routes/spm.js +0 -371
- package/dist/lib/platform/ios/snippet/PlaceholderConverter.d.ts +0 -21
- package/dist/lib/platform/ios/snippet/PlaceholderConverter.js +0 -48
- package/dist/lib/platform/ios/snippet/XcodeCodec.d.ts +0 -23
- package/dist/lib/platform/ios/snippet/XcodeCodec.js +0 -96
- package/dist/lib/platform/ios/spm/DependencyGraph.d.ts +0 -56
- package/dist/lib/platform/ios/spm/DependencyGraph.js +0 -195
- package/dist/lib/platform/ios/spm/PackageSwiftParser.d.ts +0 -69
- package/dist/lib/platform/ios/spm/PackageSwiftParser.js +0 -231
- package/dist/lib/platform/ios/spm/PathFinder.d.ts +0 -28
- package/dist/lib/platform/ios/spm/PathFinder.js +0 -117
- package/dist/lib/platform/ios/spm/PolicyEngine.d.ts +0 -44
- package/dist/lib/platform/ios/spm/PolicyEngine.js +0 -79
- package/dist/lib/platform/ios/spm/SpmHelper.d.ts +0 -102
- package/dist/lib/platform/ios/spm/SpmHelper.js +0 -464
- package/dist/lib/platform/ios/xcode/HeaderResolver.d.ts +0 -33
- package/dist/lib/platform/ios/xcode/HeaderResolver.js +0 -90
- package/dist/lib/platform/ios/xcode/SaveEventFilter.d.ts +0 -66
- package/dist/lib/platform/ios/xcode/SaveEventFilter.js +0 -142
- package/dist/lib/platform/ios/xcode/XcodeAutomation.d.ts +0 -71
- package/dist/lib/platform/ios/xcode/XcodeAutomation.js +0 -327
- package/dist/lib/platform/ios/xcode/XcodeImportResolver.d.ts +0 -130
- package/dist/lib/platform/ios/xcode/XcodeImportResolver.js +0 -404
- package/dist/lib/platform/ios/xcode/XcodeIntegration.d.ts +0 -89
- package/dist/lib/platform/ios/xcode/XcodeIntegration.js +0 -588
- package/dist/lib/platform/ios/xcode/XcodeWriteUtils.d.ts +0 -99
- package/dist/lib/platform/ios/xcode/XcodeWriteUtils.js +0 -190
- package/dist/lib/repository/task/TaskRepository.impl.d.ts +0 -171
- package/dist/lib/repository/task/TaskRepository.impl.js +0 -347
- package/dist/lib/service/automation/ActionPipeline.d.ts +0 -34
- package/dist/lib/service/automation/ActionPipeline.js +0 -53
- package/dist/lib/service/automation/AutomationOrchestrator.d.ts +0 -86
- package/dist/lib/service/automation/AutomationOrchestrator.js +0 -57
- package/dist/lib/service/automation/ContextCollector.d.ts +0 -24
- package/dist/lib/service/automation/ContextCollector.js +0 -35
- package/dist/lib/service/automation/DirectiveDetector.d.ts +0 -51
- package/dist/lib/service/automation/DirectiveDetector.js +0 -112
- package/dist/lib/service/automation/FileWatcher.d.ts +0 -51
- package/dist/lib/service/automation/FileWatcher.js +0 -366
- package/dist/lib/service/automation/TriggerResolver.d.ts +0 -36
- package/dist/lib/service/automation/TriggerResolver.js +0 -62
- package/dist/lib/service/automation/handlers/AlinkHandler.d.ts +0 -7
- package/dist/lib/service/automation/handlers/AlinkHandler.js +0 -80
- package/dist/lib/service/automation/handlers/CreateHandler.d.ts +0 -11
- package/dist/lib/service/automation/handlers/CreateHandler.js +0 -170
- package/dist/lib/service/automation/handlers/GuardHandler.d.ts +0 -17
- package/dist/lib/service/automation/handlers/GuardHandler.js +0 -218
- package/dist/lib/service/automation/handlers/HeaderHandler.d.ts +0 -2
- package/dist/lib/service/automation/handlers/HeaderHandler.js +0 -32
- package/dist/lib/service/automation/handlers/SearchHandler.d.ts +0 -11
- package/dist/lib/service/automation/handlers/SearchHandler.js +0 -278
- package/dist/lib/service/snippet/SnippetFactory.d.ts +0 -101
- package/dist/lib/service/snippet/SnippetFactory.js +0 -145
- package/dist/lib/service/snippet/SnippetInstaller.d.ts +0 -91
- package/dist/lib/service/snippet/SnippetInstaller.js +0 -276
- package/dist/lib/service/snippet/codecs/SnippetCodec.d.ts +0 -44
- package/dist/lib/service/snippet/codecs/SnippetCodec.js +0 -35
- package/dist/lib/service/snippet/codecs/VSCodeCodec.d.ts +0 -27
- package/dist/lib/service/snippet/codecs/VSCodeCodec.js +0 -82
- package/dist/lib/service/task/TaskGraphService.d.ts +0 -222
- package/dist/lib/service/task/TaskGraphService.js +0 -597
- package/dist/lib/service/task/TaskKnowledgeBridge.d.ts +0 -95
- package/dist/lib/service/task/TaskKnowledgeBridge.js +0 -298
- package/dist/lib/service/task/TaskReadyEngine.d.ts +0 -84
- package/dist/lib/service/task/TaskReadyEngine.js +0 -115
- package/dist/scripts/build-native-ui.d.ts +0 -3
- package/dist/scripts/build-native-ui.js +0 -62
- package/dist/scripts/init-snippets.d.ts +0 -30
- package/dist/scripts/init-snippets.js +0 -298
- package/dist/scripts/install-full.d.ts +0 -7
- package/dist/scripts/install-full.js +0 -38
- package/resources/native-ui/README.md +0 -29
- package/resources/native-ui/combined-window.swift +0 -494
- package/resources/native-ui/main.swift +0 -598
- package/scripts/postinstall-safe.mjs +0 -89
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DependencyGraph — SPM 依赖图构建与分析
|
|
3
|
-
* 合并 V1 DepGraphService + DepGraphAnalyzer
|
|
4
|
-
* 构建 target 级依赖 DAG,支持层级计算、拓扑排序、可达性检查
|
|
5
|
-
*/
|
|
6
|
-
import Logger from '#infra/logging/Logger.js';
|
|
7
|
-
export class DependencyGraph {
|
|
8
|
-
#adjacency; // Map<string, Set<string>>
|
|
9
|
-
#reverseAdj; // Map<string, Set<string>>
|
|
10
|
-
#nodes; // Set<string>
|
|
11
|
-
#logger;
|
|
12
|
-
constructor() {
|
|
13
|
-
this.#adjacency = new Map();
|
|
14
|
-
this.#reverseAdj = new Map();
|
|
15
|
-
this.#nodes = new Set();
|
|
16
|
-
this.#logger = Logger.getInstance();
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* 从 PackageSwiftParser 的解析结果构建图
|
|
20
|
-
* @param parsed
|
|
21
|
-
*/
|
|
22
|
-
buildFromParsed(parsed) {
|
|
23
|
-
this.clear();
|
|
24
|
-
for (const target of parsed.targets || []) {
|
|
25
|
-
this.addNode(target.name);
|
|
26
|
-
for (const dep of target.dependencies || []) {
|
|
27
|
-
this.addEdge(target.name, dep);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
this.#logger.debug(`[DependencyGraph] built: ${this.#nodes.size} nodes, ${this.edgeCount()} edges`);
|
|
31
|
-
}
|
|
32
|
-
/** 添加节点 */
|
|
33
|
-
addNode(name) {
|
|
34
|
-
this.#nodes.add(name);
|
|
35
|
-
if (!this.#adjacency.has(name)) {
|
|
36
|
-
this.#adjacency.set(name, new Set());
|
|
37
|
-
}
|
|
38
|
-
if (!this.#reverseAdj.has(name)) {
|
|
39
|
-
this.#reverseAdj.set(name, new Set());
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
/** 添加边: from 依赖 to */
|
|
43
|
-
addEdge(from, to) {
|
|
44
|
-
this.addNode(from);
|
|
45
|
-
this.addNode(to);
|
|
46
|
-
this.#adjacency.get(from).add(to);
|
|
47
|
-
this.#reverseAdj.get(to).add(from);
|
|
48
|
-
}
|
|
49
|
-
/** BFS 可达性检查 */
|
|
50
|
-
isReachable(from, to) {
|
|
51
|
-
if (from === to) {
|
|
52
|
-
return true;
|
|
53
|
-
}
|
|
54
|
-
const visited = new Set();
|
|
55
|
-
const queue = [from];
|
|
56
|
-
while (queue.length > 0) {
|
|
57
|
-
const node = queue.shift();
|
|
58
|
-
if (node === to) {
|
|
59
|
-
return true;
|
|
60
|
-
}
|
|
61
|
-
if (visited.has(node)) {
|
|
62
|
-
continue;
|
|
63
|
-
}
|
|
64
|
-
visited.add(node);
|
|
65
|
-
for (const neighbor of this.#adjacency.get(node) || []) {
|
|
66
|
-
queue.push(neighbor);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* 检测循环依赖
|
|
73
|
-
* @returns 循环路径列表
|
|
74
|
-
*/
|
|
75
|
-
detectCycles() {
|
|
76
|
-
const cycles = [];
|
|
77
|
-
const white = new Set(this.#nodes);
|
|
78
|
-
const gray = new Set();
|
|
79
|
-
const black = new Set();
|
|
80
|
-
const path = [];
|
|
81
|
-
const dfs = (node) => {
|
|
82
|
-
white.delete(node);
|
|
83
|
-
gray.add(node);
|
|
84
|
-
path.push(node);
|
|
85
|
-
for (const neighbor of this.#adjacency.get(node) || []) {
|
|
86
|
-
if (gray.has(neighbor)) {
|
|
87
|
-
const cycleStart = path.indexOf(neighbor);
|
|
88
|
-
cycles.push(path.slice(cycleStart).concat(neighbor));
|
|
89
|
-
}
|
|
90
|
-
else if (white.has(neighbor)) {
|
|
91
|
-
dfs(neighbor);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
path.pop();
|
|
95
|
-
gray.delete(node);
|
|
96
|
-
black.add(node);
|
|
97
|
-
};
|
|
98
|
-
for (const node of this.#nodes) {
|
|
99
|
-
if (white.has(node)) {
|
|
100
|
-
dfs(node);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
return cycles;
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* 拓扑排序 (Kahn's algorithm)
|
|
107
|
-
* @returns 若有环则返回部分结果
|
|
108
|
-
*/
|
|
109
|
-
topologicalSort() {
|
|
110
|
-
const inDegree = new Map();
|
|
111
|
-
for (const node of this.#nodes) {
|
|
112
|
-
inDegree.set(node, 0);
|
|
113
|
-
}
|
|
114
|
-
for (const [, deps] of this.#adjacency) {
|
|
115
|
-
for (const dep of deps) {
|
|
116
|
-
inDegree.set(dep, (inDegree.get(dep) || 0) + 1);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
const queue = [];
|
|
120
|
-
for (const [node, degree] of inDegree) {
|
|
121
|
-
if (degree === 0) {
|
|
122
|
-
queue.push(node);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
const result = [];
|
|
126
|
-
while (queue.length > 0) {
|
|
127
|
-
const node = queue.shift();
|
|
128
|
-
result.push(node);
|
|
129
|
-
for (const dep of this.#adjacency.get(node) || []) {
|
|
130
|
-
inDegree.set(dep, (inDegree.get(dep) ?? 0) - 1);
|
|
131
|
-
if (inDegree.get(dep) === 0) {
|
|
132
|
-
queue.push(dep);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
return result;
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* 层级计算: L0 = 无依赖的节点, L1 = 只依赖 L0, etc.
|
|
140
|
-
* @returns node → level
|
|
141
|
-
*/
|
|
142
|
-
computeLevels() {
|
|
143
|
-
const levels = new Map();
|
|
144
|
-
const topo = this.topologicalSort();
|
|
145
|
-
// 反向处理: 叶子节点是 L0
|
|
146
|
-
for (const node of topo.reverse()) {
|
|
147
|
-
const deps = this.#adjacency.get(node) || new Set();
|
|
148
|
-
if (deps.size === 0) {
|
|
149
|
-
levels.set(node, 0);
|
|
150
|
-
}
|
|
151
|
-
else {
|
|
152
|
-
let maxDepLevel = 0;
|
|
153
|
-
for (const dep of deps) {
|
|
154
|
-
maxDepLevel = Math.max(maxDepLevel, levels.get(dep) || 0);
|
|
155
|
-
}
|
|
156
|
-
levels.set(node, maxDepLevel + 1);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
return levels;
|
|
160
|
-
}
|
|
161
|
-
/** 获取节点的直接依赖 */
|
|
162
|
-
getDependencies(node) {
|
|
163
|
-
return [...(this.#adjacency.get(node) || [])];
|
|
164
|
-
}
|
|
165
|
-
/** 获取节点的直接依赖者 (谁依赖了这个节点) */
|
|
166
|
-
getDependents(node) {
|
|
167
|
-
return [...(this.#reverseAdj.get(node) || [])];
|
|
168
|
-
}
|
|
169
|
-
/** 获取所有节点 */
|
|
170
|
-
getNodes() {
|
|
171
|
-
return [...this.#nodes];
|
|
172
|
-
}
|
|
173
|
-
edgeCount() {
|
|
174
|
-
let count = 0;
|
|
175
|
-
for (const deps of this.#adjacency.values()) {
|
|
176
|
-
count += deps.size;
|
|
177
|
-
}
|
|
178
|
-
return count;
|
|
179
|
-
}
|
|
180
|
-
clear() {
|
|
181
|
-
this.#adjacency.clear();
|
|
182
|
-
this.#reverseAdj.clear();
|
|
183
|
-
this.#nodes.clear();
|
|
184
|
-
}
|
|
185
|
-
/** 导出为 JSON (可视化用) */
|
|
186
|
-
toJSON() {
|
|
187
|
-
const edges = [];
|
|
188
|
-
for (const [from, deps] of this.#adjacency) {
|
|
189
|
-
for (const to of deps) {
|
|
190
|
-
edges.push({ from, to });
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
return { nodes: [...this.#nodes], edges };
|
|
194
|
-
}
|
|
195
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* PackageSwiftParser — Package.swift 解析器
|
|
3
|
-
* 从 V1 PackageParserV2 迁移,提取包名/版本/targets/dependencies/products/platforms
|
|
4
|
-
*/
|
|
5
|
-
export declare class PackageSwiftParser {
|
|
6
|
-
#private;
|
|
7
|
-
constructor(projectRoot: string);
|
|
8
|
-
/**
|
|
9
|
-
* 向上递归查找 Package.swift
|
|
10
|
-
* @returns 路径
|
|
11
|
-
*/
|
|
12
|
-
findPackageSwift(startPath?: string): any;
|
|
13
|
-
/**
|
|
14
|
-
* 向下递归扫描所有 Package.swift(支持多 Package 项目)
|
|
15
|
-
* @param rootDir 扫描起点(默认 projectRoot)
|
|
16
|
-
* @returns Package.swift 路径数组
|
|
17
|
-
*/
|
|
18
|
-
findAllPackageSwifts(rootDir?: string): any;
|
|
19
|
-
/**
|
|
20
|
-
* 解析 Package.swift
|
|
21
|
-
* @returns }
|
|
22
|
-
*/
|
|
23
|
-
parse(packagePath: string): {
|
|
24
|
-
path: string;
|
|
25
|
-
name: string;
|
|
26
|
-
version: string;
|
|
27
|
-
targets: {
|
|
28
|
-
name: string;
|
|
29
|
-
type: string;
|
|
30
|
-
path: string | null;
|
|
31
|
-
dependencies: string[];
|
|
32
|
-
}[];
|
|
33
|
-
dependencies: ({
|
|
34
|
-
url: string;
|
|
35
|
-
version: string | null;
|
|
36
|
-
type: string;
|
|
37
|
-
} | {
|
|
38
|
-
path: string;
|
|
39
|
-
type: string;
|
|
40
|
-
})[];
|
|
41
|
-
products: {
|
|
42
|
-
name: string;
|
|
43
|
-
type: string;
|
|
44
|
-
}[];
|
|
45
|
-
platforms: {
|
|
46
|
-
name: string;
|
|
47
|
-
version: string;
|
|
48
|
-
}[];
|
|
49
|
-
};
|
|
50
|
-
/** 获取包摘要 */
|
|
51
|
-
getSummary(packagePath: string): {
|
|
52
|
-
name: string;
|
|
53
|
-
version: string;
|
|
54
|
-
targetCount: number;
|
|
55
|
-
dependencyCount: number;
|
|
56
|
-
platforms: {
|
|
57
|
-
name: string;
|
|
58
|
-
version: string;
|
|
59
|
-
}[];
|
|
60
|
-
} | null;
|
|
61
|
-
/** 提取 target blocks(公开方法,供外部使用) */
|
|
62
|
-
extractTargets(content: string): {
|
|
63
|
-
name: string;
|
|
64
|
-
type: string;
|
|
65
|
-
path: string | null;
|
|
66
|
-
dependencies: string[];
|
|
67
|
-
}[];
|
|
68
|
-
clearCache(): void;
|
|
69
|
-
}
|
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* PackageSwiftParser — Package.swift 解析器
|
|
3
|
-
* 从 V1 PackageParserV2 迁移,提取包名/版本/targets/dependencies/products/platforms
|
|
4
|
-
*/
|
|
5
|
-
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
6
|
-
import { dirname, join } from 'node:path';
|
|
7
|
-
import Logger from '#infra/logging/Logger.js';
|
|
8
|
-
export class PackageSwiftParser {
|
|
9
|
-
#projectRoot;
|
|
10
|
-
#cache;
|
|
11
|
-
#logger;
|
|
12
|
-
constructor(projectRoot) {
|
|
13
|
-
this.#projectRoot = projectRoot;
|
|
14
|
-
this.#cache = new Map();
|
|
15
|
-
this.#logger = Logger.getInstance();
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* 向上递归查找 Package.swift
|
|
19
|
-
* @returns 路径
|
|
20
|
-
*/
|
|
21
|
-
findPackageSwift(startPath = this.#projectRoot) {
|
|
22
|
-
const cacheKey = `find:${startPath}`;
|
|
23
|
-
if (this.#cache.has(cacheKey)) {
|
|
24
|
-
return this.#cache.get(cacheKey);
|
|
25
|
-
}
|
|
26
|
-
let dir = startPath;
|
|
27
|
-
for (let i = 0; i < 10; i++) {
|
|
28
|
-
const candidate = join(dir, 'Package.swift');
|
|
29
|
-
if (existsSync(candidate)) {
|
|
30
|
-
this.#cache.set(cacheKey, candidate);
|
|
31
|
-
return candidate;
|
|
32
|
-
}
|
|
33
|
-
const parent = dirname(dir);
|
|
34
|
-
if (parent === dir) {
|
|
35
|
-
break;
|
|
36
|
-
}
|
|
37
|
-
dir = parent;
|
|
38
|
-
}
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* 向下递归扫描所有 Package.swift(支持多 Package 项目)
|
|
43
|
-
* @param rootDir 扫描起点(默认 projectRoot)
|
|
44
|
-
* @returns Package.swift 路径数组
|
|
45
|
-
*/
|
|
46
|
-
findAllPackageSwifts(rootDir = this.#projectRoot) {
|
|
47
|
-
const cacheKey = `findAll:${rootDir}`;
|
|
48
|
-
if (this.#cache.has(cacheKey)) {
|
|
49
|
-
return this.#cache.get(cacheKey);
|
|
50
|
-
}
|
|
51
|
-
const results = [];
|
|
52
|
-
const skipDirs = new Set([
|
|
53
|
-
'node_modules',
|
|
54
|
-
'.git',
|
|
55
|
-
'Build',
|
|
56
|
-
'.build',
|
|
57
|
-
'.swiftpm',
|
|
58
|
-
'Pods',
|
|
59
|
-
'DerivedData',
|
|
60
|
-
]);
|
|
61
|
-
const scan = (dir, depth = 0) => {
|
|
62
|
-
if (depth > 5) {
|
|
63
|
-
return; // 限制深度
|
|
64
|
-
}
|
|
65
|
-
try {
|
|
66
|
-
const entries = readdirSync(dir, { withFileTypes: true });
|
|
67
|
-
for (const entry of entries) {
|
|
68
|
-
if (entry.isDirectory()) {
|
|
69
|
-
if (skipDirs.has(entry.name)) {
|
|
70
|
-
continue;
|
|
71
|
-
}
|
|
72
|
-
scan(join(dir, entry.name), depth + 1);
|
|
73
|
-
}
|
|
74
|
-
else if (entry.name === 'Package.swift') {
|
|
75
|
-
results.push(join(dir, entry.name));
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
catch {
|
|
80
|
-
// 权限错误等,跳过
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
scan(rootDir);
|
|
84
|
-
this.#cache.set(cacheKey, results);
|
|
85
|
-
return results;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* 解析 Package.swift
|
|
89
|
-
* @returns }
|
|
90
|
-
*/
|
|
91
|
-
parse(packagePath) {
|
|
92
|
-
if (!packagePath || !existsSync(packagePath)) {
|
|
93
|
-
throw new Error(`Package.swift not found: ${packagePath}`);
|
|
94
|
-
}
|
|
95
|
-
const content = readFileSync(packagePath, 'utf-8');
|
|
96
|
-
const result = {
|
|
97
|
-
path: packagePath,
|
|
98
|
-
name: this.#extractName(content),
|
|
99
|
-
version: this.#extractVersion(content),
|
|
100
|
-
targets: this.#extractTargets(content),
|
|
101
|
-
dependencies: this.#extractDependencies(content),
|
|
102
|
-
products: this.#extractProducts(content),
|
|
103
|
-
platforms: this.#extractPlatforms(content),
|
|
104
|
-
};
|
|
105
|
-
this.#logger.debug(`[PackageSwiftParser] 解析完成: ${result.name} (${result.targets.length} targets)`);
|
|
106
|
-
return result;
|
|
107
|
-
}
|
|
108
|
-
/** 获取包摘要 */
|
|
109
|
-
getSummary(packagePath) {
|
|
110
|
-
try {
|
|
111
|
-
const parsed = this.parse(packagePath);
|
|
112
|
-
return {
|
|
113
|
-
name: parsed.name,
|
|
114
|
-
version: parsed.version,
|
|
115
|
-
targetCount: parsed.targets.length,
|
|
116
|
-
dependencyCount: parsed.dependencies.length,
|
|
117
|
-
platforms: parsed.platforms,
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
catch {
|
|
121
|
-
return null;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
/** 提取 target blocks(公开方法,供外部使用) */
|
|
125
|
-
extractTargets(content) {
|
|
126
|
-
return this.#extractTargets(content);
|
|
127
|
-
}
|
|
128
|
-
clearCache() {
|
|
129
|
-
this.#cache.clear();
|
|
130
|
-
}
|
|
131
|
-
// ─── 私有提取方法 ──────────────────────────────────────
|
|
132
|
-
#extractName(content) {
|
|
133
|
-
const m = content.match(/name\s*:\s*"([^"]+)"/);
|
|
134
|
-
return m ? m[1] : 'unknown';
|
|
135
|
-
}
|
|
136
|
-
#extractVersion(content) {
|
|
137
|
-
const m = content.match(/version\s*:\s*"([^"]+)"/);
|
|
138
|
-
return m ? m[1] : '0.0.0';
|
|
139
|
-
}
|
|
140
|
-
#extractTargets(content) {
|
|
141
|
-
const targets = [];
|
|
142
|
-
const re = /\.(?:target|testTarget|executableTarget)\s*\(/g;
|
|
143
|
-
let match;
|
|
144
|
-
while ((match = re.exec(content)) !== null) {
|
|
145
|
-
const type = match[0].includes('testTarget')
|
|
146
|
-
? 'testTarget'
|
|
147
|
-
: match[0].includes('executableTarget')
|
|
148
|
-
? 'executableTarget'
|
|
149
|
-
: 'target';
|
|
150
|
-
const startPos = match.index + match[0].length;
|
|
151
|
-
let depth = 1;
|
|
152
|
-
let endPos = startPos;
|
|
153
|
-
while (depth > 0 && endPos < content.length) {
|
|
154
|
-
if (content[endPos] === '(') {
|
|
155
|
-
depth++;
|
|
156
|
-
}
|
|
157
|
-
else if (content[endPos] === ')') {
|
|
158
|
-
depth--;
|
|
159
|
-
}
|
|
160
|
-
endPos++;
|
|
161
|
-
}
|
|
162
|
-
if (depth === 0) {
|
|
163
|
-
const block = content.substring(startPos, endPos - 1);
|
|
164
|
-
const nameMatch = block.match(/name\s*:\s*"([^"]+)"/);
|
|
165
|
-
if (!nameMatch) {
|
|
166
|
-
continue;
|
|
167
|
-
}
|
|
168
|
-
const pathMatch = block.match(/path\s*:\s*"([^"]+)"/);
|
|
169
|
-
const depsMatch = block.match(/dependencies\s*:\s*\[([^\]]*)\]/s);
|
|
170
|
-
const deps = [];
|
|
171
|
-
if (depsMatch) {
|
|
172
|
-
const depRe = /\.(?:product|target)\s*\(\s*name\s*:\s*"([^"]+)"/g;
|
|
173
|
-
let dm;
|
|
174
|
-
while ((dm = depRe.exec(depsMatch[1])) !== null) {
|
|
175
|
-
deps.push(dm[1]);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
targets.push({
|
|
179
|
-
name: nameMatch[1],
|
|
180
|
-
type,
|
|
181
|
-
path: pathMatch ? pathMatch[1] : null,
|
|
182
|
-
dependencies: deps,
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
return targets;
|
|
187
|
-
}
|
|
188
|
-
#extractDependencies(content) {
|
|
189
|
-
const deps = [];
|
|
190
|
-
// 1. URL 依赖: .package(url: "...", ...)
|
|
191
|
-
const urlRe = /\.package\s*\(\s*url\s*:\s*"([^"]+)"[^)]*\)/g;
|
|
192
|
-
let m;
|
|
193
|
-
while ((m = urlRe.exec(content)) !== null) {
|
|
194
|
-
const block = m[0];
|
|
195
|
-
const fromMatch = block.match(/from\s*:\s*"([^"]+)"/);
|
|
196
|
-
const exactMatch = block.match(/exact\s*:\s*"([^"]+)"/);
|
|
197
|
-
deps.push({
|
|
198
|
-
url: m[1],
|
|
199
|
-
version: fromMatch ? fromMatch[1] : exactMatch ? exactMatch[1] : null,
|
|
200
|
-
type: 'package',
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
// 2. Local path 依赖: .package(path: "...")
|
|
204
|
-
const pathRe = /\.package\s*\(\s*path\s*:\s*"([^"]+)"\s*\)/g;
|
|
205
|
-
while ((m = pathRe.exec(content)) !== null) {
|
|
206
|
-
deps.push({
|
|
207
|
-
path: m[1],
|
|
208
|
-
type: 'local',
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
return deps;
|
|
212
|
-
}
|
|
213
|
-
#extractProducts(content) {
|
|
214
|
-
const products = [];
|
|
215
|
-
const re = /\.(library|executable)\s*\(\s*name\s*:\s*"([^"]+)"/g;
|
|
216
|
-
let m;
|
|
217
|
-
while ((m = re.exec(content)) !== null) {
|
|
218
|
-
products.push({ name: m[2], type: m[1] });
|
|
219
|
-
}
|
|
220
|
-
return products;
|
|
221
|
-
}
|
|
222
|
-
#extractPlatforms(content) {
|
|
223
|
-
const platforms = [];
|
|
224
|
-
const re = /\.(iOS|macOS|tvOS|watchOS|visionOS)\s*\(\s*\.v(\d+(?:_\d+)?)\s*\)/g;
|
|
225
|
-
let m;
|
|
226
|
-
while ((m = re.exec(content)) !== null) {
|
|
227
|
-
platforms.push({ name: m[1], version: m[2].replace(/_/g, '.') });
|
|
228
|
-
}
|
|
229
|
-
return platforms;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* PathFinder — 轻量级路径发现工具(V2 ESM)
|
|
3
|
-
* 从文件路径向上查找 SPM 项目结构:Package.swift、Target 根目录、头文件路径
|
|
4
|
-
*/
|
|
5
|
-
/** 向上遍历目录,查找含 Code/ 或 Sources/ 子目录的 target 根目录 */
|
|
6
|
-
export declare function findTargetRootDir(filePath: string): Promise<string | null>;
|
|
7
|
-
/** 向上查找 Package.swift */
|
|
8
|
-
export declare function findPackageSwiftPath(filePath: string): Promise<string | null>;
|
|
9
|
-
/** 简易解析 Package.swift,提取 targets 数组和包名 */
|
|
10
|
-
export declare function parsePackageSwift(packagePath: string): Promise<{
|
|
11
|
-
name: string;
|
|
12
|
-
path: string;
|
|
13
|
-
targets: string[];
|
|
14
|
-
} | null>;
|
|
15
|
-
/**
|
|
16
|
-
* 在 targetRootDir 下递归查找指定头文件
|
|
17
|
-
* @param rootDir target 根目录
|
|
18
|
-
* @param headerName 不含扩展名的头文件名
|
|
19
|
-
* @param moduleName 模块名(可选,用于优先匹配模块子目录)
|
|
20
|
-
*/
|
|
21
|
-
export declare function findSubHeaderPath(rootDir: string, headerName: string, moduleName: string | null): Promise<string | null>;
|
|
22
|
-
declare const _default: {
|
|
23
|
-
findTargetRootDir: typeof findTargetRootDir;
|
|
24
|
-
findPackageSwiftPath: typeof findPackageSwiftPath;
|
|
25
|
-
parsePackageSwift: typeof parsePackageSwift;
|
|
26
|
-
findSubHeaderPath: typeof findSubHeaderPath;
|
|
27
|
-
};
|
|
28
|
-
export default _default;
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
/**
|
|
4
|
-
* PathFinder — 轻量级路径发现工具(V2 ESM)
|
|
5
|
-
* 从文件路径向上查找 SPM 项目结构:Package.swift、Target 根目录、头文件路径
|
|
6
|
-
*/
|
|
7
|
-
/** 向上遍历目录,查找含 Code/ 或 Sources/ 子目录的 target 根目录 */
|
|
8
|
-
export async function findTargetRootDir(filePath) {
|
|
9
|
-
let current = path.dirname(path.resolve(filePath));
|
|
10
|
-
for (let i = 0; i < 10; i++) {
|
|
11
|
-
try {
|
|
12
|
-
const entries = fs.readdirSync(current, { withFileTypes: true });
|
|
13
|
-
for (const e of entries) {
|
|
14
|
-
if (e.isDirectory() && (e.name === 'Code' || e.name === 'Sources')) {
|
|
15
|
-
return current;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
catch {
|
|
20
|
-
break;
|
|
21
|
-
}
|
|
22
|
-
const parent = path.dirname(current);
|
|
23
|
-
if (parent === current) {
|
|
24
|
-
break;
|
|
25
|
-
}
|
|
26
|
-
current = parent;
|
|
27
|
-
}
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
/** 向上查找 Package.swift */
|
|
31
|
-
export async function findPackageSwiftPath(filePath) {
|
|
32
|
-
let current = path.dirname(path.resolve(filePath));
|
|
33
|
-
for (let i = 0; i < 15; i++) {
|
|
34
|
-
const candidate = path.join(current, 'Package.swift');
|
|
35
|
-
if (fs.existsSync(candidate)) {
|
|
36
|
-
return candidate;
|
|
37
|
-
}
|
|
38
|
-
const parent = path.dirname(current);
|
|
39
|
-
if (parent === current) {
|
|
40
|
-
break;
|
|
41
|
-
}
|
|
42
|
-
current = parent;
|
|
43
|
-
}
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
/** 简易解析 Package.swift,提取 targets 数组和包名 */
|
|
47
|
-
export async function parsePackageSwift(packagePath) {
|
|
48
|
-
try {
|
|
49
|
-
const content = fs.readFileSync(packagePath, 'utf8');
|
|
50
|
-
const nameMatch = content.match(/name:\s*"([^"]+)"/);
|
|
51
|
-
const name = nameMatch?.[1] || path.basename(path.dirname(packagePath));
|
|
52
|
-
const targets = [];
|
|
53
|
-
const targetRe = /\.(?:target|testTarget|executableTarget)\s*\(\s*name:\s*"([^"]+)"/g;
|
|
54
|
-
let m;
|
|
55
|
-
while ((m = targetRe.exec(content)) !== null) {
|
|
56
|
-
targets.push(m[1]);
|
|
57
|
-
}
|
|
58
|
-
return { name, path: path.dirname(packagePath), targets };
|
|
59
|
-
}
|
|
60
|
-
catch {
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* 在 targetRootDir 下递归查找指定头文件
|
|
66
|
-
* @param rootDir target 根目录
|
|
67
|
-
* @param headerName 不含扩展名的头文件名
|
|
68
|
-
* @param moduleName 模块名(可选,用于优先匹配模块子目录)
|
|
69
|
-
*/
|
|
70
|
-
export async function findSubHeaderPath(rootDir, headerName, moduleName) {
|
|
71
|
-
if (!rootDir || !headerName) {
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
74
|
-
const target = `${headerName}.h`;
|
|
75
|
-
// 优先在模块名子目录下找
|
|
76
|
-
if (moduleName) {
|
|
77
|
-
const modDir = path.join(rootDir, 'Sources', moduleName);
|
|
78
|
-
const found = _findFile(modDir, target);
|
|
79
|
-
if (found) {
|
|
80
|
-
return found;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
// 全局搜索
|
|
84
|
-
return _findFile(rootDir, target);
|
|
85
|
-
}
|
|
86
|
-
function _findFile(dir, filename, maxDepth = 8, depth = 0) {
|
|
87
|
-
if (depth > maxDepth || !fs.existsSync(dir)) {
|
|
88
|
-
return null;
|
|
89
|
-
}
|
|
90
|
-
try {
|
|
91
|
-
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
92
|
-
if (entry.name.startsWith('.')) {
|
|
93
|
-
continue;
|
|
94
|
-
}
|
|
95
|
-
const full = path.join(dir, entry.name);
|
|
96
|
-
if (entry.isFile() && entry.name === filename) {
|
|
97
|
-
return full;
|
|
98
|
-
}
|
|
99
|
-
if (entry.isDirectory()) {
|
|
100
|
-
const found = _findFile(full, filename, maxDepth, depth + 1);
|
|
101
|
-
if (found) {
|
|
102
|
-
return found;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
catch {
|
|
108
|
-
/* ignore */
|
|
109
|
-
}
|
|
110
|
-
return null;
|
|
111
|
-
}
|
|
112
|
-
export default {
|
|
113
|
-
findTargetRootDir,
|
|
114
|
-
findPackageSwiftPath,
|
|
115
|
-
parsePackageSwift,
|
|
116
|
-
findSubHeaderPath,
|
|
117
|
-
};
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* PolicyEngine — SPM 依赖策略引擎
|
|
3
|
-
* 检查循环依赖、反向依赖 (违反分层架构原则)、方针约束
|
|
4
|
-
*/
|
|
5
|
-
import type { DependencyGraph } from './DependencyGraph.js';
|
|
6
|
-
/** 策略检查配置 */
|
|
7
|
-
interface PolicyConfig {
|
|
8
|
-
layerOrder?: string[];
|
|
9
|
-
}
|
|
10
|
-
/** 策略违规记录 */
|
|
11
|
-
interface PolicyViolation {
|
|
12
|
-
type: string;
|
|
13
|
-
severity: string;
|
|
14
|
-
message: string;
|
|
15
|
-
nodes?: string[];
|
|
16
|
-
from?: string;
|
|
17
|
-
to?: string;
|
|
18
|
-
fromLayer?: number;
|
|
19
|
-
toLayer?: number;
|
|
20
|
-
}
|
|
21
|
-
export declare class PolicyEngine {
|
|
22
|
-
#private;
|
|
23
|
-
/**
|
|
24
|
-
* 全面策略检查
|
|
25
|
-
* @param config - layerOrder 定义分层顺序,低层不应依赖高层
|
|
26
|
-
* @returns }
|
|
27
|
-
*/
|
|
28
|
-
check(graph: DependencyGraph, config?: PolicyConfig): {
|
|
29
|
-
passed: boolean;
|
|
30
|
-
violations: PolicyViolation[];
|
|
31
|
-
};
|
|
32
|
-
/**
|
|
33
|
-
* 单独检查能否添加新依赖
|
|
34
|
-
* @returns }
|
|
35
|
-
*/
|
|
36
|
-
canAddDependency(graph: DependencyGraph, from: string, to: string): {
|
|
37
|
-
allowed: boolean;
|
|
38
|
-
reason: string;
|
|
39
|
-
} | {
|
|
40
|
-
allowed: boolean;
|
|
41
|
-
reason?: undefined;
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
export {};
|