autosnippet 3.3.7 → 3.3.9
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 +1 -0
- package/dashboard/dist/assets/icons-BMNb0V6L.js +1 -0
- package/dashboard/dist/assets/index-DEU4tJtP.js +112 -0
- package/dashboard/dist/assets/index-DHJ1Dj7u.css +1 -0
- package/dashboard/dist/index.html +3 -3
- package/dist/bin/cli.js +7 -4
- package/dist/lib/agent/core/ChatAgentPrompts.js +57 -21
- package/dist/lib/agent/core/LoopContext.d.ts +1 -0
- package/dist/lib/agent/core/ToolExecutionPipeline.js +13 -0
- package/dist/lib/agent/memory/ActiveContext.d.ts +0 -2
- package/dist/lib/agent/memory/ActiveContext.js +0 -2
- package/dist/lib/agent/memory/MemoryEmbeddingStore.d.ts +49 -0
- package/dist/lib/agent/memory/MemoryEmbeddingStore.js +159 -0
- package/dist/lib/agent/memory/MemoryRetriever.d.ts +2 -0
- package/dist/lib/agent/memory/MemoryRetriever.js +25 -11
- package/dist/lib/agent/memory/MemoryStore.d.ts +8 -41
- package/dist/lib/agent/memory/MemoryStore.js +196 -261
- package/dist/lib/agent/memory/PersistentMemory.d.ts +2 -0
- package/dist/lib/agent/memory/PersistentMemory.js +4 -5
- package/dist/lib/agent/memory/SessionStore.d.ts +0 -2
- package/dist/lib/agent/memory/SessionStore.js +0 -2
- package/dist/lib/agent/tools/ast-graph.js +21 -19
- package/dist/lib/agent/tools/infrastructure.js +3 -2
- package/dist/lib/agent/tools/project-access.d.ts +2 -2
- package/dist/lib/agent/tools/project-access.js +5 -4
- package/dist/lib/bootstrap.js +8 -2
- package/dist/lib/cli/AiScanService.js +4 -17
- package/dist/lib/cli/KnowledgeSyncService.d.ts +7 -37
- package/dist/lib/cli/KnowledgeSyncService.js +23 -51
- package/dist/lib/cli/SetupService.js +5 -4
- package/dist/lib/core/ast/ProjectGraph.js +5 -27
- package/dist/lib/core/discovery/CustomConfigDiscoverer.d.ts +0 -2
- package/dist/lib/core/discovery/CustomConfigDiscoverer.js +0 -2
- package/dist/lib/domain/dimension/DimensionRegistry.d.ts +0 -2
- package/dist/lib/domain/dimension/DimensionRegistry.js +0 -2
- package/dist/lib/domain/dimension/DimensionSop.js +44 -33
- package/dist/lib/domain/dimension/UnifiedDimension.d.ts +0 -2
- package/dist/lib/domain/dimension/UnifiedDimension.js +0 -2
- package/dist/lib/domain/knowledge/Lifecycle.d.ts +26 -0
- package/dist/lib/domain/knowledge/Lifecycle.js +42 -0
- package/dist/lib/domain/knowledge/index.d.ts +2 -1
- package/dist/lib/domain/knowledge/index.js +1 -1
- package/dist/lib/external/mcp/McpServer.js +19 -2
- package/dist/lib/external/mcp/handlers/bootstrap/pipeline/BootstrapSnapshot.d.ts +2 -1
- package/dist/lib/external/mcp/handlers/bootstrap/pipeline/BootstrapSnapshot.js +102 -153
- package/dist/lib/external/mcp/handlers/bootstrap/pipeline/mock-pipeline.js +10 -29
- package/dist/lib/external/mcp/handlers/bootstrap/pipeline/orchestrator.js +33 -16
- package/dist/lib/external/mcp/handlers/bootstrap/shared/bootstrap-phases.d.ts +1 -1
- package/dist/lib/external/mcp/handlers/bootstrap/shared/bootstrap-phases.js +41 -37
- package/dist/lib/external/mcp/handlers/bootstrap-external.js +1 -1
- package/dist/lib/external/mcp/handlers/dimension-complete-external.js +7 -3
- package/dist/lib/external/mcp/handlers/evolve-external.d.ts +1 -0
- package/dist/lib/external/mcp/handlers/evolve-external.js +13 -16
- package/dist/lib/external/mcp/handlers/guard.js +15 -24
- package/dist/lib/external/mcp/handlers/panorama.js +9 -9
- package/dist/lib/external/mcp/handlers/rescan-external.js +7 -6
- package/dist/lib/external/mcp/handlers/rescan-internal.js +9 -5
- package/dist/lib/external/mcp/handlers/search.js +3 -1
- package/dist/lib/external/mcp/handlers/skill.js +4 -4
- package/dist/lib/external/mcp/handlers/structure.js +8 -12
- package/dist/lib/external/mcp/handlers/system.js +10 -34
- package/dist/lib/http/routes/ai.js +11 -13
- package/dist/lib/http/routes/guardReport.js +3 -5
- package/dist/lib/http/routes/panorama.js +12 -12
- package/dist/lib/http/routes/recipes.js +59 -8
- package/dist/lib/http/routes/remote.js +3 -13
- package/dist/lib/http/routes/search.js +11 -8
- package/dist/lib/infrastructure/audit/AuditLogger.d.ts +20 -3
- package/dist/lib/infrastructure/audit/AuditStore.d.ts +28 -29
- package/dist/lib/infrastructure/audit/AuditStore.js +81 -88
- package/dist/lib/infrastructure/database/DatabaseConnection.js +7 -6
- package/dist/lib/infrastructure/database/drizzle/schema.d.ts +180 -2
- package/dist/lib/infrastructure/database/drizzle/schema.js +23 -3
- package/dist/lib/injection/ServiceContainer.js +7 -4
- package/dist/lib/injection/ServiceMap.d.ts +20 -0
- package/dist/lib/injection/modules/AppModule.js +2 -1
- package/dist/lib/injection/modules/GuardModule.js +5 -5
- package/dist/lib/injection/modules/InfraModule.js +60 -0
- package/dist/lib/injection/modules/KnowledgeModule.js +86 -51
- package/dist/lib/injection/modules/PanoramaModule.js +16 -10
- package/dist/lib/injection/modules/VectorModule.js +3 -0
- package/dist/lib/repository/audit/AuditRepository.d.ts +107 -0
- package/dist/lib/repository/audit/AuditRepository.js +272 -0
- package/dist/lib/repository/base/RepositoryBase.d.ts +46 -0
- package/dist/lib/repository/base/RepositoryBase.js +32 -0
- package/dist/lib/repository/bootstrap/BootstrapRepository.d.ts +94 -0
- package/dist/lib/repository/bootstrap/BootstrapRepository.js +246 -0
- package/dist/lib/repository/code/CodeEntityRepository.d.ts +91 -0
- package/dist/lib/repository/code/CodeEntityRepository.js +361 -0
- package/dist/lib/repository/delivery/DeliveryRepoAdapter.d.ts +39 -0
- package/dist/lib/repository/delivery/DeliveryRepoAdapter.js +23 -0
- package/dist/lib/repository/evolution/LifecycleEventRepository.d.ts +51 -0
- package/dist/lib/repository/evolution/LifecycleEventRepository.js +119 -0
- package/dist/lib/repository/evolution/ProposalRepository.d.ts +9 -12
- package/dist/lib/repository/evolution/ProposalRepository.js +114 -57
- package/dist/lib/repository/guard/GuardViolationRepository.d.ts +104 -0
- package/dist/lib/repository/guard/GuardViolationRepository.js +217 -0
- package/dist/lib/repository/knowledge/KnowledgeEdgeRepository.d.ts +129 -0
- package/dist/lib/repository/knowledge/KnowledgeEdgeRepository.js +475 -0
- package/dist/lib/repository/knowledge/KnowledgeFileStore.d.ts +39 -0
- package/dist/lib/repository/knowledge/KnowledgeFileStore.js +12 -0
- package/dist/lib/repository/knowledge/KnowledgeRepository.impl.d.ts +295 -11
- package/dist/lib/repository/knowledge/KnowledgeRepository.impl.js +608 -13
- package/dist/lib/repository/knowledge/KnowledgeUnitOfWork.d.ts +61 -0
- package/dist/lib/repository/knowledge/KnowledgeUnitOfWork.js +156 -0
- package/dist/lib/repository/memory/MemoryRepository.d.ts +90 -0
- package/dist/lib/repository/memory/MemoryRepository.js +260 -0
- package/dist/lib/repository/search/SearchRepoAdapter.d.ts +92 -0
- package/dist/lib/repository/search/SearchRepoAdapter.js +124 -0
- package/dist/lib/repository/session/SessionRepository.d.ts +46 -0
- package/dist/lib/repository/session/SessionRepository.js +110 -0
- package/dist/lib/repository/sourceref/RecipeSourceRefRepository.d.ts +66 -0
- package/dist/lib/repository/sourceref/RecipeSourceRefRepository.js +182 -0
- package/dist/lib/repository/sync/SyncRepoAdapter.d.ts +58 -0
- package/dist/lib/repository/sync/SyncRepoAdapter.js +58 -0
- package/dist/lib/service/bootstrap/UiStartupTasks.js +5 -6
- package/dist/lib/service/bootstrap/bootstrap-event-types.d.ts +0 -1
- package/dist/lib/service/bootstrap/bootstrap-event-types.js +0 -1
- package/dist/lib/service/cleanup/CleanupService.js +8 -4
- package/dist/lib/service/delivery/CursorDeliveryPipeline.js +21 -9
- package/dist/lib/service/evolution/ConsolidationAdvisor.d.ts +4 -9
- package/dist/lib/service/evolution/ConsolidationAdvisor.js +34 -70
- package/dist/lib/service/evolution/ContentPatcher.d.ts +4 -12
- package/dist/lib/service/evolution/ContentPatcher.js +48 -19
- package/dist/lib/service/evolution/ContradictionDetector.d.ts +3 -7
- package/dist/lib/service/evolution/ContradictionDetector.js +17 -24
- package/dist/lib/service/evolution/DecayDetector.d.ts +10 -9
- package/dist/lib/service/evolution/DecayDetector.js +63 -57
- package/dist/lib/service/evolution/EnhancementSuggester.d.ts +3 -9
- package/dist/lib/service/evolution/EnhancementSuggester.js +42 -86
- package/dist/lib/service/evolution/KnowledgeMetabolism.d.ts +4 -4
- package/dist/lib/service/evolution/KnowledgeMetabolism.js +102 -71
- package/dist/lib/service/evolution/ProposalExecutor.d.ts +5 -12
- package/dist/lib/service/evolution/ProposalExecutor.js +64 -69
- package/dist/lib/service/evolution/RecipeLifecycleSupervisor.d.ts +9 -14
- package/dist/lib/service/evolution/RecipeLifecycleSupervisor.js +94 -155
- package/dist/lib/service/evolution/RecipeRelevanceAuditor.d.ts +4 -1
- package/dist/lib/service/evolution/RecipeRelevanceAuditor.js +50 -49
- package/dist/lib/service/evolution/RedundancyAnalyzer.d.ts +3 -7
- package/dist/lib/service/evolution/RedundancyAnalyzer.js +15 -22
- package/dist/lib/service/evolution/StagingManager.d.ts +6 -15
- package/dist/lib/service/evolution/StagingManager.js +37 -95
- package/dist/lib/service/evolution/createSupersedeProposal.d.ts +1 -1
- package/dist/lib/service/evolution/createSupersedeProposal.js +7 -8
- package/dist/lib/service/guard/CoverageAnalyzer.d.ts +3 -7
- package/dist/lib/service/guard/CoverageAnalyzer.js +9 -11
- package/dist/lib/service/guard/GuardCheckEngine.d.ts +3 -0
- package/dist/lib/service/guard/GuardCheckEngine.js +14 -22
- package/dist/lib/service/guard/ReverseGuard.d.ts +4 -7
- package/dist/lib/service/guard/ReverseGuard.js +21 -31
- package/dist/lib/service/guard/ViolationsStore.d.ts +15 -21
- package/dist/lib/service/guard/ViolationsStore.js +75 -69
- package/dist/lib/service/knowledge/CodeEntityGraph.d.ts +39 -63
- package/dist/lib/service/knowledge/CodeEntityGraph.js +418 -512
- package/dist/lib/service/knowledge/ConfidenceRouter.js +18 -9
- package/dist/lib/service/knowledge/KnowledgeFileWriter.d.ts +2 -1
- package/dist/lib/service/knowledge/KnowledgeGraphService.d.ts +18 -60
- package/dist/lib/service/knowledge/KnowledgeGraphService.js +58 -109
- package/dist/lib/service/knowledge/KnowledgeService.d.ts +15 -1
- package/dist/lib/service/knowledge/KnowledgeService.js +76 -38
- package/dist/lib/service/knowledge/RecipeProductionGateway.d.ts +0 -2
- package/dist/lib/service/knowledge/RecipeProductionGateway.js +0 -2
- package/dist/lib/service/knowledge/SourceRefReconciler.d.ts +5 -13
- package/dist/lib/service/knowledge/SourceRefReconciler.js +58 -78
- package/dist/lib/service/panorama/CouplingAnalyzer.d.ts +5 -3
- package/dist/lib/service/panorama/CouplingAnalyzer.js +102 -39
- package/dist/lib/service/panorama/DimensionAnalyzer.d.ts +7 -4
- package/dist/lib/service/panorama/DimensionAnalyzer.js +72 -25
- package/dist/lib/service/panorama/LayerInferrer.js +1 -1
- package/dist/lib/service/panorama/ModuleDiscoverer.d.ts +7 -6
- package/dist/lib/service/panorama/ModuleDiscoverer.js +174 -82
- package/dist/lib/service/panorama/PanoramaAggregator.d.ts +10 -3
- package/dist/lib/service/panorama/PanoramaAggregator.js +67 -79
- package/dist/lib/service/panorama/PanoramaScanner.d.ts +5 -1
- package/dist/lib/service/panorama/PanoramaScanner.js +32 -31
- package/dist/lib/service/panorama/PanoramaService.d.ts +11 -8
- package/dist/lib/service/panorama/PanoramaService.js +41 -66
- package/dist/lib/service/panorama/PanoramaTypes.d.ts +3 -0
- package/dist/lib/service/panorama/RoleRefiner.d.ts +8 -5
- package/dist/lib/service/panorama/RoleRefiner.js +52 -283
- package/dist/lib/service/panorama/TechStackProfiler.js +7 -119
- package/dist/lib/service/quality/QualityScorer.d.ts +45 -26
- package/dist/lib/service/quality/QualityScorer.js +157 -83
- package/dist/lib/service/search/SearchEngine.d.ts +1 -0
- package/dist/lib/service/search/SearchEngine.js +32 -37
- package/dist/lib/service/signal/HitRecorder.js +5 -5
- package/dist/lib/service/skills/RuleRecallStrategy.js +7 -3
- package/dist/lib/service/skills/SignalCollector.d.ts +5 -8
- package/dist/lib/service/skills/SignalCollector.js +28 -55
- package/dist/lib/service/skills/SkillAdvisor.d.ts +7 -13
- package/dist/lib/service/skills/SkillAdvisor.js +30 -79
- package/dist/lib/service/vector/SyncCoordinator.d.ts +3 -1
- package/dist/lib/service/vector/SyncCoordinator.js +25 -3
- package/dist/lib/service/vector/VectorService.d.ts +2 -0
- package/dist/lib/service/vector/VectorService.js +3 -0
- package/dist/lib/service/wiki/WikiGenerator.js +1 -1
- package/dist/lib/shared/LanguageProfiles.d.ts +109 -0
- package/dist/lib/shared/LanguageProfiles.js +939 -0
- package/dist/lib/shared/LanguageService.d.ts +6 -0
- package/dist/lib/shared/LanguageService.js +16 -0
- package/dist/lib/shared/PathGuard.js +16 -10
- package/dist/lib/shared/constants.d.ts +19 -19
- package/dist/lib/shared/constants.js +10 -10
- package/dist/lib/shared/isOwnDevRepo.d.ts +29 -4
- package/dist/lib/shared/isOwnDevRepo.js +64 -4
- package/dist/lib/shared/schemas/mcp-tools.d.ts +1 -1
- package/dist/lib/types/project-snapshot-builder.d.ts +0 -1
- package/dist/lib/types/project-snapshot-builder.js +0 -1
- package/dist/lib/types/project-snapshot.d.ts +0 -1
- package/dist/lib/types/project-snapshot.js +0 -1
- package/dist/lib/types/snapshot-views.d.ts +0 -2
- package/dist/lib/types/snapshot-views.js +0 -1
- package/package.json +2 -1
- package/dashboard/dist/assets/icons-FHns2ypa.js +0 -1
- package/dashboard/dist/assets/index-BRJv5Y3r.js +0 -135
- package/dashboard/dist/assets/index-DzoB7kxK.css +0 -1
- package/dist/lib/repository/base/BaseRepository.d.ts +0 -53
- package/dist/lib/repository/base/BaseRepository.js +0 -226
|
@@ -135,33 +135,31 @@ router.post('/config', validate(AiConfigBody), async (req, res) => {
|
|
|
135
135
|
router.post('/mock/cleanup', async (_req, res) => {
|
|
136
136
|
const container = getContainer();
|
|
137
137
|
const knowledgeService = container.get('knowledgeService');
|
|
138
|
-
const
|
|
139
|
-
const rawDb = dbConn.getDb();
|
|
138
|
+
const knowledgeRepo = container.get('knowledgeRepository');
|
|
140
139
|
// 查找所有 mock 来源的候选
|
|
141
140
|
const mockSources = ['mock-bootstrap', 'mock-pipeline'];
|
|
142
141
|
let totalDeleted = 0;
|
|
143
142
|
for (const source of mockSources) {
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
.all(source);
|
|
147
|
-
for (const row of rows) {
|
|
143
|
+
const ids = await knowledgeRepo.findIdsBySource(source);
|
|
144
|
+
for (const id of ids) {
|
|
148
145
|
try {
|
|
149
|
-
await knowledgeService.delete(
|
|
146
|
+
await knowledgeService.delete(id, { userId: 'system:mock-cleanup' });
|
|
150
147
|
totalDeleted++;
|
|
151
148
|
}
|
|
152
149
|
catch {
|
|
153
|
-
logger.debug(`Mock cleanup: failed to delete ${
|
|
150
|
+
logger.debug(`Mock cleanup: failed to delete ${id}`);
|
|
154
151
|
}
|
|
155
152
|
}
|
|
156
153
|
}
|
|
157
|
-
// 清理
|
|
154
|
+
// 清理 bootstrap 来源的 semantic_memories
|
|
158
155
|
try {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
.
|
|
156
|
+
const memoryRepo = container.get('memoryRepository');
|
|
157
|
+
if (memoryRepo) {
|
|
158
|
+
await memoryRepo.clearBootstrapMemories();
|
|
159
|
+
}
|
|
162
160
|
}
|
|
163
161
|
catch {
|
|
164
|
-
//
|
|
162
|
+
// memoryRepository 可能未注册
|
|
165
163
|
}
|
|
166
164
|
logger.info(`Mock cleanup completed: ${totalDeleted} entries deleted`);
|
|
167
165
|
const rt = getRealtimeService();
|
|
@@ -67,8 +67,7 @@ router.get('/reverse', async (req, res) => {
|
|
|
67
67
|
reverseGuard = container.get('reverseGuard');
|
|
68
68
|
}
|
|
69
69
|
catch {
|
|
70
|
-
|
|
71
|
-
reverseGuard = new ReverseGuard(db.getDb());
|
|
70
|
+
reverseGuard = new ReverseGuard(container.get('knowledgeRepository'), container.get('codeEntityRepository'), container.get('recipeSourceRefRepository'));
|
|
72
71
|
}
|
|
73
72
|
const maxFiles = req.query.maxFiles ? Number(req.query.maxFiles) : 200;
|
|
74
73
|
const projectFiles = await collectSourceFilesWithContent(projectRoot, { maxFiles });
|
|
@@ -111,14 +110,13 @@ router.get('/coverage', async (_req, res) => {
|
|
|
111
110
|
analyzer = container.get('coverageAnalyzer');
|
|
112
111
|
}
|
|
113
112
|
catch {
|
|
114
|
-
|
|
115
|
-
analyzer = new CoverageAnalyzer(db.getDb());
|
|
113
|
+
analyzer = new CoverageAnalyzer(container.get('knowledgeRepository'), container.get('guardViolationRepository'));
|
|
116
114
|
}
|
|
117
115
|
// 从 Panorama 或目录结构获取模块文件
|
|
118
116
|
const moduleFiles = new Map();
|
|
119
117
|
try {
|
|
120
118
|
const panorama = container.get('panoramaService');
|
|
121
|
-
const overview = panorama.getOverview();
|
|
119
|
+
const overview = await panorama.getOverview();
|
|
122
120
|
if (overview?.modules) {
|
|
123
121
|
for (const mod of overview.modules) {
|
|
124
122
|
if (mod.files?.length > 0) {
|
|
@@ -31,7 +31,7 @@ router.get('/', async (req, res) => {
|
|
|
31
31
|
if (typeof panoramaService.ensureData === 'function') {
|
|
32
32
|
await panoramaService.ensureData();
|
|
33
33
|
}
|
|
34
|
-
const overview = panoramaService.getOverview();
|
|
34
|
+
const overview = await panoramaService.getOverview();
|
|
35
35
|
res.json({ success: true, data: overview });
|
|
36
36
|
}
|
|
37
37
|
catch (err) {
|
|
@@ -62,7 +62,7 @@ router.get('/health', async (req, res) => {
|
|
|
62
62
|
if (typeof panoramaService.ensureData === 'function') {
|
|
63
63
|
await panoramaService.ensureData();
|
|
64
64
|
}
|
|
65
|
-
const health = panoramaService.getHealth();
|
|
65
|
+
const health = await panoramaService.getHealth();
|
|
66
66
|
res.json({ success: true, data: health });
|
|
67
67
|
}
|
|
68
68
|
catch (err) {
|
|
@@ -93,7 +93,7 @@ router.get('/gaps', async (req, res) => {
|
|
|
93
93
|
if (typeof panoramaService.ensureData === 'function') {
|
|
94
94
|
await panoramaService.ensureData();
|
|
95
95
|
}
|
|
96
|
-
const gaps = panoramaService.getGaps();
|
|
96
|
+
const gaps = await panoramaService.getGaps();
|
|
97
97
|
res.json({ success: true, data: gaps });
|
|
98
98
|
}
|
|
99
99
|
catch (err) {
|
|
@@ -124,8 +124,8 @@ router.get('/coverage', async (req, res) => {
|
|
|
124
124
|
if (typeof panoramaService.ensureData === 'function') {
|
|
125
125
|
await panoramaService.ensureData();
|
|
126
126
|
}
|
|
127
|
-
const overview = panoramaService.getOverview();
|
|
128
|
-
const gaps = panoramaService.getGaps?.() ?? [];
|
|
127
|
+
const overview = await panoramaService.getOverview();
|
|
128
|
+
const gaps = (await panoramaService.getGaps?.()) ?? [];
|
|
129
129
|
// 构建模块级覆盖率数据:从 overview.layers 中提取每个模块的文件数和 recipe 数
|
|
130
130
|
const modules = [];
|
|
131
131
|
for (const layer of overview.layers || []) {
|
|
@@ -187,7 +187,7 @@ router.get('/module/:name', async (req, res) => {
|
|
|
187
187
|
if (typeof panoramaService.ensureData === 'function') {
|
|
188
188
|
await panoramaService.ensureData();
|
|
189
189
|
}
|
|
190
|
-
const detail = panoramaService.getModule(req.params.name);
|
|
190
|
+
const detail = await panoramaService.getModule(req.params.name);
|
|
191
191
|
if (!detail) {
|
|
192
192
|
res.status(404).json({
|
|
193
193
|
success: false,
|
|
@@ -220,7 +220,7 @@ router.post('/governance/cycle', async (_req, res) => {
|
|
|
220
220
|
});
|
|
221
221
|
return;
|
|
222
222
|
}
|
|
223
|
-
const report = metabolism.runFullCycle();
|
|
223
|
+
const report = await metabolism.runFullCycle();
|
|
224
224
|
res.json({ success: true, data: report });
|
|
225
225
|
}
|
|
226
226
|
catch (err) {
|
|
@@ -245,7 +245,7 @@ router.get('/governance/decay', async (_req, res) => {
|
|
|
245
245
|
});
|
|
246
246
|
return;
|
|
247
247
|
}
|
|
248
|
-
const results = decayDetector.scanAll();
|
|
248
|
+
const results = await decayDetector.scanAll();
|
|
249
249
|
res.json({ success: true, data: { results } });
|
|
250
250
|
}
|
|
251
251
|
catch (err) {
|
|
@@ -270,8 +270,8 @@ router.post('/governance/staging-check', async (_req, res) => {
|
|
|
270
270
|
});
|
|
271
271
|
return;
|
|
272
272
|
}
|
|
273
|
-
const checkResult = stagingManager.checkAndPromote();
|
|
274
|
-
const currentStaging = stagingManager.listStaging();
|
|
273
|
+
const checkResult = await stagingManager.checkAndPromote();
|
|
274
|
+
const currentStaging = await stagingManager.listStaging();
|
|
275
275
|
res.json({ success: true, data: { checkResult, currentStaging } });
|
|
276
276
|
}
|
|
277
277
|
catch (err) {
|
|
@@ -296,7 +296,7 @@ router.get('/governance/staging', async (_req, res) => {
|
|
|
296
296
|
});
|
|
297
297
|
return;
|
|
298
298
|
}
|
|
299
|
-
const entries = stagingManager.listStaging();
|
|
299
|
+
const entries = await stagingManager.listStaging();
|
|
300
300
|
res.json({ success: true, data: { entries } });
|
|
301
301
|
}
|
|
302
302
|
catch (err) {
|
|
@@ -321,7 +321,7 @@ router.get('/governance/enhancements', async (_req, res) => {
|
|
|
321
321
|
});
|
|
322
322
|
return;
|
|
323
323
|
}
|
|
324
|
-
const suggestions = suggester.analyzeAll();
|
|
324
|
+
const suggestions = await suggester.analyzeAll();
|
|
325
325
|
res.json({ success: true, data: { suggestions } });
|
|
326
326
|
}
|
|
327
327
|
catch (err) {
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* 此路由仅处理 Recipe 特有的批量 AI 操作。
|
|
7
7
|
*/
|
|
8
8
|
import express from 'express';
|
|
9
|
+
import { COUNTABLE_LIFECYCLES } from '../../domain/knowledge/Lifecycle.js';
|
|
9
10
|
import Logger from '../../infrastructure/logging/Logger.js';
|
|
10
11
|
import { getServiceContainer } from '../../injection/ServiceContainer.js';
|
|
11
12
|
const router = express.Router();
|
|
@@ -77,11 +78,10 @@ router.post('/discover-relations', async (req, res) => {
|
|
|
77
78
|
data: { status: 'error', error: 'AI Provider 未配置,当前为 Mock 模式。请先配置 API Key。' },
|
|
78
79
|
});
|
|
79
80
|
}
|
|
80
|
-
// 快速检查:至少需要 2
|
|
81
|
+
// 快速检查:至少需要 2 条可消费 Recipe(active/staging/pending/evolving)
|
|
81
82
|
try {
|
|
82
|
-
const
|
|
83
|
-
const
|
|
84
|
-
const count = items.length || data.length;
|
|
83
|
+
const knowledgeRepo = container.get('knowledgeRepository');
|
|
84
|
+
const count = await knowledgeRepo.countByLifecycles(COUNTABLE_LIFECYCLES);
|
|
85
85
|
if (count < 2) {
|
|
86
86
|
return void res.json({
|
|
87
87
|
success: true,
|
|
@@ -93,7 +93,7 @@ router.post('/discover-relations', async (req, res) => {
|
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
catch {
|
|
96
|
-
//
|
|
96
|
+
// 如果查询失败,继续尝试(让 runTask 给出具体错误)
|
|
97
97
|
}
|
|
98
98
|
// 重置并启动后台任务
|
|
99
99
|
resetTask();
|
|
@@ -103,11 +103,62 @@ router.post('/discover-relations', async (req, res) => {
|
|
|
103
103
|
(async () => {
|
|
104
104
|
try {
|
|
105
105
|
const result = await agentFactory.discoverRelations();
|
|
106
|
+
const relations = result.relations || [];
|
|
107
|
+
const analyzed = result.analyzed || 0;
|
|
108
|
+
// 将 AI 发现的关系写入知识图谱
|
|
109
|
+
// AI 返回的 from/to 是 Recipe 标题,需要解析为实际 ID
|
|
110
|
+
let written = 0;
|
|
111
|
+
if (relations.length > 0) {
|
|
112
|
+
try {
|
|
113
|
+
const graphService = container.get('knowledgeGraphService');
|
|
114
|
+
const knowledgeRepo = container.get('knowledgeRepository');
|
|
115
|
+
// 缓存标题 → ID 映射,避免重复查询
|
|
116
|
+
const titleToId = new Map();
|
|
117
|
+
const resolveId = async (title) => {
|
|
118
|
+
if (titleToId.has(title)) {
|
|
119
|
+
return titleToId.get(title);
|
|
120
|
+
}
|
|
121
|
+
try {
|
|
122
|
+
const entry = await knowledgeRepo.findByTitle(title);
|
|
123
|
+
const id = entry?.id ?? null;
|
|
124
|
+
titleToId.set(title, id);
|
|
125
|
+
return id;
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
titleToId.set(title, null);
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
for (const rel of relations) {
|
|
133
|
+
if (!rel.from || !rel.to || !rel.type) {
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
const fromId = await resolveId(rel.from);
|
|
137
|
+
const toId = await resolveId(rel.to);
|
|
138
|
+
if (!fromId || !toId) {
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
const res = await graphService.addEdge(fromId, 'recipe', toId, 'recipe', rel.type, {
|
|
142
|
+
weight: 0.7,
|
|
143
|
+
source: 'ai-discovery',
|
|
144
|
+
evidence: rel.evidence || '',
|
|
145
|
+
});
|
|
146
|
+
if (res.success) {
|
|
147
|
+
written++;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
catch (graphErr) {
|
|
152
|
+
logger.warn('Failed to write some discovered edges', {
|
|
153
|
+
error: graphErr.message,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
}
|
|
106
157
|
discoverTask.status = 'done';
|
|
107
158
|
discoverTask.finishedAt = new Date().toISOString();
|
|
108
|
-
discoverTask.discovered =
|
|
109
|
-
discoverTask.totalPairs =
|
|
110
|
-
discoverTask.batchErrors =
|
|
159
|
+
discoverTask.discovered = written;
|
|
160
|
+
discoverTask.totalPairs = analyzed;
|
|
161
|
+
discoverTask.batchErrors = relations.length - written;
|
|
111
162
|
discoverTask.elapsed = Math.round((new Date(discoverTask.finishedAt).getTime() - new Date(discoverTask.startedAt).getTime()) /
|
|
112
163
|
1000);
|
|
113
164
|
logger.info('Discover relations completed', {
|
|
@@ -21,7 +21,6 @@ import express from 'express';
|
|
|
21
21
|
import { LarkTransport } from '../../external/lark/LarkTransport.js';
|
|
22
22
|
import Logger from '../../infrastructure/logging/Logger.js';
|
|
23
23
|
import { getServiceContainer } from '../../injection/ServiceContainer.js';
|
|
24
|
-
import { RemoteCommandRepository, } from '../../repository/remote/RemoteCommandRepository.js';
|
|
25
24
|
import { resolveProjectRoot } from '../../shared/resolveProjectRoot.js';
|
|
26
25
|
import { RemoteHistoryQuery, RemoteNotifyBody, RemoteResultBody, RemoteSendBody, } from '../../shared/schemas/http-requests.js';
|
|
27
26
|
import { validate, validateQuery } from '../middleware/validate.js';
|
|
@@ -32,19 +31,10 @@ const PENDING_TIMEOUT_SEC = 120; // pending 超过 2 分钟 → timeout
|
|
|
32
31
|
const RUNNING_TIMEOUT_SEC = 600; // running 超过 10 分钟 → timeout
|
|
33
32
|
const CLEANUP_INTERVAL_MS = 30_000; // 每 30 秒清理一次
|
|
34
33
|
// ─── 数据库辅助 ─────────────────────────────────────
|
|
35
|
-
|
|
36
|
-
const container = getServiceContainer();
|
|
37
|
-
const database = container.get('database');
|
|
38
|
-
return typeof database?.getDb === 'function' ? database.getDb() : database;
|
|
39
|
-
}
|
|
40
|
-
let _repo = null;
|
|
41
|
-
/** 获取或创建 RemoteCommandRepository 单例 */
|
|
34
|
+
/** 从 DI 容器获取 RemoteCommandRepository */
|
|
42
35
|
function getRepo() {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
_repo = new RemoteCommandRepository(db);
|
|
46
|
-
}
|
|
47
|
-
return _repo;
|
|
36
|
+
const container = getServiceContainer();
|
|
37
|
+
return container.get('remoteCommandRepository');
|
|
48
38
|
}
|
|
49
39
|
function genId() {
|
|
50
40
|
return `rcmd_${Date.now().toString(36)}_${crypto.randomBytes(3).toString('hex')}`;
|
|
@@ -98,8 +98,8 @@ router.get('/graph', validateQuery(GraphQuery), async (req, res) => {
|
|
|
98
98
|
return void res.json({ success: true, data: { outgoing: [], incoming: [] } });
|
|
99
99
|
}
|
|
100
100
|
const edges = relation
|
|
101
|
-
? graphService.getRelated(nodeId, nodeType, relation)
|
|
102
|
-
: graphService.getEdges(nodeId, nodeType, direction);
|
|
101
|
+
? await graphService.getRelated(nodeId, nodeType, relation)
|
|
102
|
+
: await graphService.getEdges(nodeId, nodeType, direction);
|
|
103
103
|
res.json({ success: true, data: edges });
|
|
104
104
|
});
|
|
105
105
|
/**
|
|
@@ -114,7 +114,7 @@ router.get('/graph/impact', validateQuery(GraphImpactQuery), async (req, res) =>
|
|
|
114
114
|
if (!graphService) {
|
|
115
115
|
return void res.json({ success: true, data: [] });
|
|
116
116
|
}
|
|
117
|
-
const impact = graphService.getImpactAnalysis(nodeId, nodeType, maxDepth);
|
|
117
|
+
const impact = await graphService.getImpactAnalysis(nodeId, nodeType, maxDepth);
|
|
118
118
|
res.json({ success: true, data: impact });
|
|
119
119
|
});
|
|
120
120
|
/**
|
|
@@ -129,9 +129,11 @@ router.get('/graph/all', async (req, res) => {
|
|
|
129
129
|
if (!graphService) {
|
|
130
130
|
return void res.json({ success: true, data: { edges: [], nodeLabels: {} } });
|
|
131
131
|
}
|
|
132
|
-
//
|
|
133
|
-
|
|
134
|
-
const
|
|
132
|
+
// 默认不过滤 nodeType,返回所有知识相关边(recipe + knowledge)
|
|
133
|
+
// 仅当显式指定 nodeType 时才过滤(module 类由 /spm/dep-graph 提供)
|
|
134
|
+
const rawNodeType = req.query.nodeType;
|
|
135
|
+
const nodeType = rawNodeType === 'all' ? undefined : rawNodeType || undefined;
|
|
136
|
+
const edges = await graphService.getAllEdges(limit, nodeType);
|
|
135
137
|
// 收集节点 ID + 类型 → 按类型查标签
|
|
136
138
|
const nodeMap = new Map(); // id → Set<type>
|
|
137
139
|
for (const e of edges) {
|
|
@@ -183,8 +185,9 @@ router.get('/graph/stats', async (req, res) => {
|
|
|
183
185
|
data: { totalEdges: 0, byRelation: {}, nodeTypes: [] },
|
|
184
186
|
});
|
|
185
187
|
}
|
|
186
|
-
const
|
|
187
|
-
const
|
|
188
|
+
const rawStatsType = req.query.nodeType;
|
|
189
|
+
const statsNodeType = rawStatsType === 'all' ? undefined : rawStatsType || undefined;
|
|
190
|
+
const stats = await graphService.getStats(statsNodeType);
|
|
188
191
|
res.json({ success: true, data: stats });
|
|
189
192
|
});
|
|
190
193
|
/**
|
|
@@ -41,7 +41,18 @@ export declare class AuditLogger {
|
|
|
41
41
|
startDate?: number;
|
|
42
42
|
endDate?: number;
|
|
43
43
|
limit?: number;
|
|
44
|
-
}): Promise<
|
|
44
|
+
}): Promise<{
|
|
45
|
+
id: string;
|
|
46
|
+
timestamp: number;
|
|
47
|
+
actor: string;
|
|
48
|
+
actorContext: string | null;
|
|
49
|
+
action: string;
|
|
50
|
+
resource: string | null;
|
|
51
|
+
operationData: string | null;
|
|
52
|
+
result: string;
|
|
53
|
+
errorMessage: string | null;
|
|
54
|
+
duration: number | null;
|
|
55
|
+
}[]>;
|
|
45
56
|
/** 获取特定请求的日志 */
|
|
46
57
|
getByRequestId(requestId: string): Promise<{
|
|
47
58
|
id: string;
|
|
@@ -102,8 +113,14 @@ export declare class AuditLogger {
|
|
|
102
113
|
failure: number;
|
|
103
114
|
successRate: string;
|
|
104
115
|
avgDuration: string;
|
|
105
|
-
byActor:
|
|
106
|
-
|
|
116
|
+
byActor: {
|
|
117
|
+
actor: string;
|
|
118
|
+
count: number;
|
|
119
|
+
}[];
|
|
120
|
+
byAction: {
|
|
121
|
+
action: string;
|
|
122
|
+
count: number;
|
|
123
|
+
}[];
|
|
107
124
|
}>;
|
|
108
125
|
}
|
|
109
126
|
export default AuditLogger;
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import type { DrizzleDB } from '../database/drizzle/index.js';
|
|
2
2
|
export declare class AuditStore {
|
|
3
3
|
#private;
|
|
4
|
-
db: import('better-sqlite3').Database;
|
|
5
4
|
constructor(db: {
|
|
6
5
|
getDb: () => import('better-sqlite3').Database;
|
|
7
6
|
}, drizzle?: DrizzleDB);
|
|
8
|
-
/**
|
|
9
|
-
* 保存审计日志
|
|
10
|
-
* ★ Drizzle 类型安全 INSERT
|
|
11
|
-
*/
|
|
7
|
+
/** 保存审计日志 */
|
|
12
8
|
save(entry: {
|
|
13
9
|
id: string;
|
|
14
10
|
timestamp: number;
|
|
@@ -21,7 +17,7 @@ export declare class AuditStore {
|
|
|
21
17
|
error_message: string | null;
|
|
22
18
|
duration: number | null;
|
|
23
19
|
}): Promise<void>;
|
|
24
|
-
/**
|
|
20
|
+
/** 查询审计日志(动态多条件,全 Drizzle) */
|
|
25
21
|
query(filters?: {
|
|
26
22
|
actor?: string;
|
|
27
23
|
action?: string;
|
|
@@ -29,11 +25,19 @@ export declare class AuditStore {
|
|
|
29
25
|
startDate?: number;
|
|
30
26
|
endDate?: number;
|
|
31
27
|
limit?: number;
|
|
32
|
-
}):
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
28
|
+
}): {
|
|
29
|
+
id: string;
|
|
30
|
+
timestamp: number;
|
|
31
|
+
actor: string;
|
|
32
|
+
actorContext: string | null;
|
|
33
|
+
action: string;
|
|
34
|
+
resource: string | null;
|
|
35
|
+
operationData: string | null;
|
|
36
|
+
result: string;
|
|
37
|
+
errorMessage: string | null;
|
|
38
|
+
duration: number | null;
|
|
39
|
+
}[];
|
|
40
|
+
/** 根据请求 ID 查询 */
|
|
37
41
|
findByRequestId(requestId: string): {
|
|
38
42
|
id: string;
|
|
39
43
|
timestamp: number;
|
|
@@ -46,10 +50,7 @@ export declare class AuditStore {
|
|
|
46
50
|
errorMessage: string | null;
|
|
47
51
|
duration: number | null;
|
|
48
52
|
} | undefined;
|
|
49
|
-
/**
|
|
50
|
-
* 根据角色查询
|
|
51
|
-
* ★ Drizzle 类型安全 SELECT
|
|
52
|
-
*/
|
|
53
|
+
/** 根据角色查询 */
|
|
53
54
|
findByActor(actor: string, limit?: number): {
|
|
54
55
|
id: string;
|
|
55
56
|
timestamp: number;
|
|
@@ -62,10 +63,7 @@ export declare class AuditStore {
|
|
|
62
63
|
errorMessage: string | null;
|
|
63
64
|
duration: number | null;
|
|
64
65
|
}[];
|
|
65
|
-
/**
|
|
66
|
-
* 根据操作查询
|
|
67
|
-
* ★ Drizzle 类型安全 SELECT
|
|
68
|
-
*/
|
|
66
|
+
/** 根据操作查询 */
|
|
69
67
|
findByAction(action: string, limit?: number): {
|
|
70
68
|
id: string;
|
|
71
69
|
timestamp: number;
|
|
@@ -78,10 +76,7 @@ export declare class AuditStore {
|
|
|
78
76
|
errorMessage: string | null;
|
|
79
77
|
duration: number | null;
|
|
80
78
|
}[];
|
|
81
|
-
/**
|
|
82
|
-
* 根据结果查询
|
|
83
|
-
* ★ Drizzle 类型安全 SELECT
|
|
84
|
-
*/
|
|
79
|
+
/** 根据结果查询 */
|
|
85
80
|
findByResult(result: string, limit?: number): {
|
|
86
81
|
id: string;
|
|
87
82
|
timestamp: number;
|
|
@@ -94,7 +89,7 @@ export declare class AuditStore {
|
|
|
94
89
|
errorMessage: string | null;
|
|
95
90
|
duration: number | null;
|
|
96
91
|
}[];
|
|
97
|
-
/**
|
|
92
|
+
/** 获取统计数据(全 Drizzle) */
|
|
98
93
|
getStats(timeRange?: string): {
|
|
99
94
|
timeRange: string;
|
|
100
95
|
total: number;
|
|
@@ -102,14 +97,18 @@ export declare class AuditStore {
|
|
|
102
97
|
failure: number;
|
|
103
98
|
successRate: string;
|
|
104
99
|
avgDuration: string;
|
|
105
|
-
byActor:
|
|
106
|
-
|
|
100
|
+
byActor: {
|
|
101
|
+
actor: string;
|
|
102
|
+
count: number;
|
|
103
|
+
}[];
|
|
104
|
+
byAction: {
|
|
105
|
+
action: string;
|
|
106
|
+
count: number;
|
|
107
|
+
}[];
|
|
107
108
|
};
|
|
108
109
|
/**
|
|
109
110
|
* 清理过期审计日志
|
|
110
|
-
*
|
|
111
|
-
* @param [opts.maxAgeDays=90] 保留天数,超过此天数的记录将被删除
|
|
112
|
-
* @returns }
|
|
111
|
+
* @param [opts.maxAgeDays=90] 保留天数
|
|
113
112
|
*/
|
|
114
113
|
cleanup({ maxAgeDays }?: {
|
|
115
114
|
maxAgeDays?: number | undefined;
|