autosnippet 3.3.6 → 3.3.8

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.
Files changed (275) hide show
  1. package/README.md +1 -0
  2. package/dashboard/dist/assets/icons-BMNb0V6L.js +1 -0
  3. package/dashboard/dist/assets/index-DHJ1Dj7u.css +1 -0
  4. package/dashboard/dist/assets/index-DV8biUkH.js +112 -0
  5. package/dashboard/dist/index.html +3 -3
  6. package/dist/bin/cli.js +8 -4
  7. package/dist/lib/agent/AgentRuntime.d.ts +2 -2
  8. package/dist/lib/agent/AgentRuntime.js +26 -18
  9. package/dist/lib/agent/core/ChatAgentPrompts.js +57 -21
  10. package/dist/lib/agent/core/LoopContext.d.ts +1 -0
  11. package/dist/lib/agent/core/ToolExecutionPipeline.js +13 -0
  12. package/dist/lib/agent/domain/ChatAgentTasks.js +4 -0
  13. package/dist/lib/agent/forced-summary.js +7 -2
  14. package/dist/lib/agent/memory/ActiveContext.d.ts +0 -2
  15. package/dist/lib/agent/memory/ActiveContext.js +0 -2
  16. package/dist/lib/agent/memory/MemoryEmbeddingStore.d.ts +49 -0
  17. package/dist/lib/agent/memory/MemoryEmbeddingStore.js +159 -0
  18. package/dist/lib/agent/memory/MemoryRetriever.d.ts +2 -0
  19. package/dist/lib/agent/memory/MemoryRetriever.js +25 -11
  20. package/dist/lib/agent/memory/MemoryStore.d.ts +8 -41
  21. package/dist/lib/agent/memory/MemoryStore.js +196 -261
  22. package/dist/lib/agent/memory/PersistentMemory.d.ts +2 -0
  23. package/dist/lib/agent/memory/PersistentMemory.js +4 -5
  24. package/dist/lib/agent/memory/SessionStore.d.ts +0 -2
  25. package/dist/lib/agent/memory/SessionStore.js +0 -2
  26. package/dist/lib/agent/tools/ast-graph.js +21 -19
  27. package/dist/lib/agent/tools/infrastructure.js +3 -2
  28. package/dist/lib/agent/tools/project-access.d.ts +2 -2
  29. package/dist/lib/agent/tools/project-access.js +5 -4
  30. package/dist/lib/bootstrap.js +2 -1
  31. package/dist/lib/cli/AiScanService.js +8 -21
  32. package/dist/lib/cli/KnowledgeSyncService.d.ts +7 -37
  33. package/dist/lib/cli/KnowledgeSyncService.js +23 -51
  34. package/dist/lib/core/ast/ProjectGraph.js +5 -27
  35. package/dist/lib/core/discovery/ConfigWatcher.d.ts +64 -0
  36. package/dist/lib/core/discovery/ConfigWatcher.js +336 -0
  37. package/dist/lib/core/discovery/CustomConfigDiscoverer.d.ts +28 -0
  38. package/dist/lib/core/discovery/CustomConfigDiscoverer.js +1303 -0
  39. package/dist/lib/core/discovery/DiscovererPreference.d.ts +44 -0
  40. package/dist/lib/core/discovery/DiscovererPreference.js +141 -0
  41. package/dist/lib/core/discovery/DiscovererRegistry.d.ts +10 -1
  42. package/dist/lib/core/discovery/DiscovererRegistry.js +42 -2
  43. package/dist/lib/core/discovery/ProjectDiscoverer.d.ts +19 -0
  44. package/dist/lib/core/discovery/index.d.ts +2 -0
  45. package/dist/lib/core/discovery/index.js +4 -0
  46. package/dist/lib/core/discovery/parsers/CMakeParser.d.ts +32 -0
  47. package/dist/lib/core/discovery/parsers/CMakeParser.js +148 -0
  48. package/dist/lib/core/discovery/parsers/GradleDslParser.d.ts +43 -0
  49. package/dist/lib/core/discovery/parsers/GradleDslParser.js +171 -0
  50. package/dist/lib/core/discovery/parsers/JsonConfigParser.d.ts +45 -0
  51. package/dist/lib/core/discovery/parsers/JsonConfigParser.js +122 -0
  52. package/dist/lib/core/discovery/parsers/RubyDslParser.d.ts +49 -0
  53. package/dist/lib/core/discovery/parsers/RubyDslParser.js +282 -0
  54. package/dist/lib/core/discovery/parsers/StarlarkParser.d.ts +33 -0
  55. package/dist/lib/core/discovery/parsers/StarlarkParser.js +229 -0
  56. package/dist/lib/core/discovery/parsers/YamlConfigParser.d.ts +37 -0
  57. package/dist/lib/core/discovery/parsers/YamlConfigParser.js +212 -0
  58. package/dist/lib/domain/dimension/DimensionRegistry.d.ts +0 -2
  59. package/dist/lib/domain/dimension/DimensionRegistry.js +0 -2
  60. package/dist/lib/domain/dimension/DimensionSop.js +44 -33
  61. package/dist/lib/domain/dimension/UnifiedDimension.d.ts +0 -2
  62. package/dist/lib/domain/dimension/UnifiedDimension.js +0 -2
  63. package/dist/lib/domain/knowledge/KnowledgeEntry.d.ts +7 -1
  64. package/dist/lib/domain/knowledge/KnowledgeEntry.js +17 -3
  65. package/dist/lib/domain/knowledge/Lifecycle.d.ts +26 -0
  66. package/dist/lib/domain/knowledge/Lifecycle.js +42 -0
  67. package/dist/lib/domain/knowledge/index.d.ts +2 -1
  68. package/dist/lib/domain/knowledge/index.js +1 -1
  69. package/dist/lib/external/ai/AiProvider.d.ts +12 -0
  70. package/dist/lib/external/ai/AiProvider.js +24 -0
  71. package/dist/lib/external/ai/AiProviderManager.d.ts +101 -0
  72. package/dist/lib/external/ai/AiProviderManager.js +193 -0
  73. package/dist/lib/external/ai/providers/ClaudeProvider.js +11 -0
  74. package/dist/lib/external/ai/providers/GoogleGeminiProvider.js +18 -0
  75. package/dist/lib/external/ai/providers/MockProvider.d.ts +21 -3
  76. package/dist/lib/external/ai/providers/MockProvider.js +290 -14
  77. package/dist/lib/external/ai/providers/OpenAiProvider.js +16 -0
  78. package/dist/lib/external/lark/LarkTransport.d.ts +5 -1
  79. package/dist/lib/external/lark/LarkTransport.js +10 -2
  80. package/dist/lib/external/mcp/handlers/bootstrap/pipeline/BootstrapSnapshot.d.ts +2 -1
  81. package/dist/lib/external/mcp/handlers/bootstrap/pipeline/BootstrapSnapshot.js +102 -153
  82. package/dist/lib/external/mcp/handlers/bootstrap/pipeline/mock-pipeline.d.ts +20 -0
  83. package/dist/lib/external/mcp/handlers/bootstrap/pipeline/mock-pipeline.js +432 -0
  84. package/dist/lib/external/mcp/handlers/bootstrap/pipeline/orchestrator.js +49 -24
  85. package/dist/lib/external/mcp/handlers/bootstrap/refine.js +8 -0
  86. package/dist/lib/external/mcp/handlers/bootstrap/shared/bootstrap-phases.d.ts +1 -1
  87. package/dist/lib/external/mcp/handlers/bootstrap/shared/bootstrap-phases.js +41 -37
  88. package/dist/lib/external/mcp/handlers/bootstrap-external.d.ts +9 -0
  89. package/dist/lib/external/mcp/handlers/bootstrap-external.js +3 -1
  90. package/dist/lib/external/mcp/handlers/bootstrap-internal.js +2 -0
  91. package/dist/lib/external/mcp/handlers/consolidated.js +2 -1
  92. package/dist/lib/external/mcp/handlers/dimension-complete-external.js +9 -4
  93. package/dist/lib/external/mcp/handlers/evolve-external.d.ts +1 -0
  94. package/dist/lib/external/mcp/handlers/evolve-external.js +18 -18
  95. package/dist/lib/external/mcp/handlers/guard.js +15 -24
  96. package/dist/lib/external/mcp/handlers/knowledge.js +5 -4
  97. package/dist/lib/external/mcp/handlers/panorama.js +9 -9
  98. package/dist/lib/external/mcp/handlers/rescan-external.js +7 -6
  99. package/dist/lib/external/mcp/handlers/rescan-internal.js +9 -5
  100. package/dist/lib/external/mcp/handlers/search.js +3 -1
  101. package/dist/lib/external/mcp/handlers/skill.js +4 -4
  102. package/dist/lib/external/mcp/handlers/structure.js +8 -12
  103. package/dist/lib/external/mcp/handlers/system.js +10 -34
  104. package/dist/lib/http/routes/ai.js +109 -30
  105. package/dist/lib/http/routes/candidates.js +11 -4
  106. package/dist/lib/http/routes/commands.js +10 -1
  107. package/dist/lib/http/routes/guardReport.js +3 -5
  108. package/dist/lib/http/routes/health.js +11 -0
  109. package/dist/lib/http/routes/modules.js +27 -0
  110. package/dist/lib/http/routes/panorama.js +12 -12
  111. package/dist/lib/http/routes/recipes.js +66 -8
  112. package/dist/lib/http/routes/remote.js +3 -13
  113. package/dist/lib/http/routes/search.js +11 -8
  114. package/dist/lib/http/utils/routeHelpers.js +2 -1
  115. package/dist/lib/infrastructure/audit/AuditLogger.d.ts +20 -3
  116. package/dist/lib/infrastructure/audit/AuditStore.d.ts +28 -29
  117. package/dist/lib/infrastructure/audit/AuditStore.js +81 -88
  118. package/dist/lib/infrastructure/database/drizzle/schema.d.ts +180 -2
  119. package/dist/lib/infrastructure/database/drizzle/schema.js +23 -3
  120. package/dist/lib/injection/ServiceContainer.d.ts +6 -5
  121. package/dist/lib/injection/ServiceContainer.js +18 -31
  122. package/dist/lib/injection/ServiceMap.d.ts +22 -0
  123. package/dist/lib/injection/modules/AiModule.d.ts +6 -9
  124. package/dist/lib/injection/modules/AiModule.js +82 -39
  125. package/dist/lib/injection/modules/AppModule.js +2 -1
  126. package/dist/lib/injection/modules/GuardModule.js +5 -5
  127. package/dist/lib/injection/modules/InfraModule.js +60 -0
  128. package/dist/lib/injection/modules/KnowledgeModule.js +86 -51
  129. package/dist/lib/injection/modules/PanoramaModule.js +16 -10
  130. package/dist/lib/injection/modules/VectorModule.js +3 -0
  131. package/dist/lib/repository/audit/AuditRepository.d.ts +107 -0
  132. package/dist/lib/repository/audit/AuditRepository.js +272 -0
  133. package/dist/lib/repository/base/RepositoryBase.d.ts +46 -0
  134. package/dist/lib/repository/base/RepositoryBase.js +32 -0
  135. package/dist/lib/repository/bootstrap/BootstrapRepository.d.ts +94 -0
  136. package/dist/lib/repository/bootstrap/BootstrapRepository.js +246 -0
  137. package/dist/lib/repository/code/CodeEntityRepository.d.ts +91 -0
  138. package/dist/lib/repository/code/CodeEntityRepository.js +361 -0
  139. package/dist/lib/repository/delivery/DeliveryRepoAdapter.d.ts +39 -0
  140. package/dist/lib/repository/delivery/DeliveryRepoAdapter.js +23 -0
  141. package/dist/lib/repository/evolution/LifecycleEventRepository.d.ts +51 -0
  142. package/dist/lib/repository/evolution/LifecycleEventRepository.js +119 -0
  143. package/dist/lib/repository/evolution/ProposalRepository.d.ts +9 -12
  144. package/dist/lib/repository/evolution/ProposalRepository.js +114 -57
  145. package/dist/lib/repository/guard/GuardViolationRepository.d.ts +104 -0
  146. package/dist/lib/repository/guard/GuardViolationRepository.js +217 -0
  147. package/dist/lib/repository/knowledge/KnowledgeEdgeRepository.d.ts +129 -0
  148. package/dist/lib/repository/knowledge/KnowledgeEdgeRepository.js +475 -0
  149. package/dist/lib/repository/knowledge/KnowledgeFileStore.d.ts +39 -0
  150. package/dist/lib/repository/knowledge/KnowledgeFileStore.js +12 -0
  151. package/dist/lib/repository/knowledge/KnowledgeRepository.impl.d.ts +295 -11
  152. package/dist/lib/repository/knowledge/KnowledgeRepository.impl.js +608 -13
  153. package/dist/lib/repository/knowledge/KnowledgeUnitOfWork.d.ts +61 -0
  154. package/dist/lib/repository/knowledge/KnowledgeUnitOfWork.js +156 -0
  155. package/dist/lib/repository/memory/MemoryRepository.d.ts +90 -0
  156. package/dist/lib/repository/memory/MemoryRepository.js +260 -0
  157. package/dist/lib/repository/search/SearchRepoAdapter.d.ts +92 -0
  158. package/dist/lib/repository/search/SearchRepoAdapter.js +124 -0
  159. package/dist/lib/repository/session/SessionRepository.d.ts +46 -0
  160. package/dist/lib/repository/session/SessionRepository.js +110 -0
  161. package/dist/lib/repository/sourceref/RecipeSourceRefRepository.d.ts +66 -0
  162. package/dist/lib/repository/sourceref/RecipeSourceRefRepository.js +182 -0
  163. package/dist/lib/repository/sync/SyncRepoAdapter.d.ts +58 -0
  164. package/dist/lib/repository/sync/SyncRepoAdapter.js +58 -0
  165. package/dist/lib/service/bootstrap/UiStartupTasks.js +5 -6
  166. package/dist/lib/service/bootstrap/bootstrap-event-types.d.ts +0 -1
  167. package/dist/lib/service/bootstrap/bootstrap-event-types.js +0 -1
  168. package/dist/lib/service/cleanup/CleanupService.d.ts +54 -7
  169. package/dist/lib/service/cleanup/CleanupService.js +291 -40
  170. package/dist/lib/service/delivery/CursorDeliveryPipeline.js +6 -8
  171. package/dist/lib/service/evolution/ConsolidationAdvisor.d.ts +4 -9
  172. package/dist/lib/service/evolution/ConsolidationAdvisor.js +34 -70
  173. package/dist/lib/service/evolution/ContentPatcher.d.ts +4 -12
  174. package/dist/lib/service/evolution/ContentPatcher.js +48 -19
  175. package/dist/lib/service/evolution/ContradictionDetector.d.ts +3 -7
  176. package/dist/lib/service/evolution/ContradictionDetector.js +17 -24
  177. package/dist/lib/service/evolution/DecayDetector.d.ts +10 -9
  178. package/dist/lib/service/evolution/DecayDetector.js +63 -57
  179. package/dist/lib/service/evolution/EnhancementSuggester.d.ts +3 -9
  180. package/dist/lib/service/evolution/EnhancementSuggester.js +42 -86
  181. package/dist/lib/service/evolution/KnowledgeMetabolism.d.ts +4 -4
  182. package/dist/lib/service/evolution/KnowledgeMetabolism.js +102 -71
  183. package/dist/lib/service/evolution/ProposalExecutor.d.ts +5 -12
  184. package/dist/lib/service/evolution/ProposalExecutor.js +64 -69
  185. package/dist/lib/service/evolution/RecipeLifecycleSupervisor.d.ts +9 -14
  186. package/dist/lib/service/evolution/RecipeLifecycleSupervisor.js +94 -155
  187. package/dist/lib/service/evolution/RecipeRelevanceAuditor.d.ts +4 -1
  188. package/dist/lib/service/evolution/RecipeRelevanceAuditor.js +50 -49
  189. package/dist/lib/service/evolution/RedundancyAnalyzer.d.ts +3 -7
  190. package/dist/lib/service/evolution/RedundancyAnalyzer.js +15 -22
  191. package/dist/lib/service/evolution/StagingManager.d.ts +6 -15
  192. package/dist/lib/service/evolution/StagingManager.js +37 -95
  193. package/dist/lib/service/evolution/createSupersedeProposal.d.ts +1 -1
  194. package/dist/lib/service/evolution/createSupersedeProposal.js +7 -8
  195. package/dist/lib/service/guard/CoverageAnalyzer.d.ts +3 -7
  196. package/dist/lib/service/guard/CoverageAnalyzer.js +9 -11
  197. package/dist/lib/service/guard/GuardCheckEngine.d.ts +3 -0
  198. package/dist/lib/service/guard/GuardCheckEngine.js +14 -22
  199. package/dist/lib/service/guard/ReverseGuard.d.ts +4 -7
  200. package/dist/lib/service/guard/ReverseGuard.js +21 -31
  201. package/dist/lib/service/guard/ViolationsStore.d.ts +15 -21
  202. package/dist/lib/service/guard/ViolationsStore.js +75 -69
  203. package/dist/lib/service/knowledge/CodeEntityGraph.d.ts +45 -63
  204. package/dist/lib/service/knowledge/CodeEntityGraph.js +418 -496
  205. package/dist/lib/service/knowledge/ConfidenceRouter.js +18 -9
  206. package/dist/lib/service/knowledge/KnowledgeFileWriter.d.ts +2 -1
  207. package/dist/lib/service/knowledge/KnowledgeGraphService.d.ts +18 -60
  208. package/dist/lib/service/knowledge/KnowledgeGraphService.js +58 -109
  209. package/dist/lib/service/knowledge/KnowledgeService.d.ts +15 -1
  210. package/dist/lib/service/knowledge/KnowledgeService.js +97 -46
  211. package/dist/lib/service/knowledge/RecipeProductionGateway.d.ts +0 -2
  212. package/dist/lib/service/knowledge/RecipeProductionGateway.js +0 -2
  213. package/dist/lib/service/knowledge/SourceRefReconciler.d.ts +5 -13
  214. package/dist/lib/service/knowledge/SourceRefReconciler.js +58 -78
  215. package/dist/lib/service/module/ModuleService.js +10 -19
  216. package/dist/lib/service/panorama/CouplingAnalyzer.d.ts +14 -3
  217. package/dist/lib/service/panorama/CouplingAnalyzer.js +137 -32
  218. package/dist/lib/service/panorama/DimensionAnalyzer.d.ts +7 -4
  219. package/dist/lib/service/panorama/DimensionAnalyzer.js +94 -33
  220. package/dist/lib/service/panorama/LayerInferrer.d.ts +16 -1
  221. package/dist/lib/service/panorama/LayerInferrer.js +118 -1
  222. package/dist/lib/service/panorama/ModuleDiscoverer.d.ts +14 -4
  223. package/dist/lib/service/panorama/ModuleDiscoverer.js +209 -61
  224. package/dist/lib/service/panorama/PanoramaAggregator.d.ts +15 -4
  225. package/dist/lib/service/panorama/PanoramaAggregator.js +128 -62
  226. package/dist/lib/service/panorama/PanoramaScanner.d.ts +5 -1
  227. package/dist/lib/service/panorama/PanoramaScanner.js +60 -31
  228. package/dist/lib/service/panorama/PanoramaService.d.ts +11 -8
  229. package/dist/lib/service/panorama/PanoramaService.js +49 -69
  230. package/dist/lib/service/panorama/PanoramaTypes.d.ts +41 -0
  231. package/dist/lib/service/panorama/RoleRefiner.d.ts +10 -5
  232. package/dist/lib/service/panorama/RoleRefiner.js +92 -282
  233. package/dist/lib/service/panorama/TechStackProfiler.d.ts +13 -0
  234. package/dist/lib/service/panorama/TechStackProfiler.js +79 -0
  235. package/dist/lib/service/quality/QualityScorer.d.ts +45 -26
  236. package/dist/lib/service/quality/QualityScorer.js +157 -83
  237. package/dist/lib/service/search/SearchEngine.d.ts +1 -0
  238. package/dist/lib/service/search/SearchEngine.js +32 -37
  239. package/dist/lib/service/signal/HitRecorder.js +5 -5
  240. package/dist/lib/service/skills/RuleRecallStrategy.js +7 -3
  241. package/dist/lib/service/skills/SignalCollector.d.ts +6 -8
  242. package/dist/lib/service/skills/SignalCollector.js +34 -60
  243. package/dist/lib/service/skills/SkillAdvisor.d.ts +7 -13
  244. package/dist/lib/service/skills/SkillAdvisor.js +30 -79
  245. package/dist/lib/service/vector/ContextualEnricher.d.ts +1 -0
  246. package/dist/lib/service/vector/ContextualEnricher.js +4 -0
  247. package/dist/lib/service/vector/SyncCoordinator.d.ts +3 -1
  248. package/dist/lib/service/vector/SyncCoordinator.js +25 -3
  249. package/dist/lib/service/vector/VectorService.d.ts +2 -0
  250. package/dist/lib/service/vector/VectorService.js +3 -0
  251. package/dist/lib/service/wiki/WikiGenerator.js +1 -1
  252. package/dist/lib/shared/LanguageProfiles.d.ts +109 -0
  253. package/dist/lib/shared/LanguageProfiles.js +939 -0
  254. package/dist/lib/shared/LanguageService.d.ts +6 -0
  255. package/dist/lib/shared/LanguageService.js +19 -0
  256. package/dist/lib/shared/constants.d.ts +19 -19
  257. package/dist/lib/shared/constants.js +10 -10
  258. package/dist/lib/shared/developer-identity.d.ts +18 -0
  259. package/dist/lib/shared/developer-identity.js +62 -0
  260. package/dist/lib/shared/schemas/http-requests.d.ts +8 -17
  261. package/dist/lib/shared/schemas/http-requests.js +9 -6
  262. package/dist/lib/shared/schemas/mcp-tools.d.ts +1 -1
  263. package/dist/lib/types/knowledge-wire.d.ts +1 -0
  264. package/dist/lib/types/project-snapshot-builder.d.ts +0 -1
  265. package/dist/lib/types/project-snapshot-builder.js +0 -1
  266. package/dist/lib/types/project-snapshot.d.ts +0 -1
  267. package/dist/lib/types/project-snapshot.js +0 -1
  268. package/dist/lib/types/snapshot-views.d.ts +0 -2
  269. package/dist/lib/types/snapshot-views.js +0 -1
  270. package/package.json +2 -1
  271. package/dashboard/dist/assets/icons-D1aVZYFW.js +0 -1
  272. package/dashboard/dist/assets/index-CxHOu8Hd.css +0 -1
  273. package/dashboard/dist/assets/index-DDdAOpYT.js +0 -128
  274. package/dist/lib/repository/base/BaseRepository.d.ts +0 -53
  275. package/dist/lib/repository/base/BaseRepository.js +0 -226
@@ -9,12 +9,7 @@
9
9
  */
10
10
  import type { ReportStore } from '../../infrastructure/report/ReportStore.js';
11
11
  import type { SignalBus } from '../../infrastructure/signal/SignalBus.js';
12
- interface DatabaseLike {
13
- prepare(sql: string): {
14
- all(...params: unknown[]): Record<string, unknown>[];
15
- get(...params: unknown[]): Record<string, unknown> | undefined;
16
- };
17
- }
12
+ import type KnowledgeRepositoryImpl from '../../repository/knowledge/KnowledgeRepository.impl.js';
18
13
  export type EnhancementType = 'missing_code_example' | 'low_adoption' | 'low_authority' | 'deprecated_reference';
19
14
  export interface EnhancementSuggestion {
20
15
  recipeId: string;
@@ -26,13 +21,12 @@ export interface EnhancementSuggestion {
26
21
  }
27
22
  export declare class EnhancementSuggester {
28
23
  #private;
29
- constructor(db: DatabaseLike, options?: {
24
+ constructor(knowledgeRepo: KnowledgeRepositoryImpl, options?: {
30
25
  signalBus?: SignalBus;
31
26
  reportStore?: ReportStore;
32
27
  });
33
28
  /**
34
29
  * 运行全部 4 种增强策略
35
30
  */
36
- analyzeAll(): EnhancementSuggestion[];
31
+ analyzeAll(): Promise<EnhancementSuggestion[]>;
37
32
  }
38
- export {};
@@ -7,6 +7,7 @@
7
7
  * ③ 同类知识中 authority 偏低 → 建议补充 whenClause
8
8
  * ④ 关联 Recipe 已 deprecated → 建议检查引用是否过时
9
9
  */
10
+ import { Lifecycle, PUBLISHED_LIFECYCLES } from '../../domain/knowledge/Lifecycle.js';
10
11
  import Logger from '../../infrastructure/logging/Logger.js';
11
12
  /* ────────────────────── Constants ────────────────────── */
12
13
  const GUARD_HIT_THRESHOLD = 5;
@@ -14,24 +15,25 @@ const SEARCH_HIT_THRESHOLD = 10;
14
15
  const LOW_AUTHORITY_PERCENTILE = 0.25;
15
16
  /* ────────────────────── Class ────────────────────── */
16
17
  export class EnhancementSuggester {
17
- #db;
18
+ #knowledgeRepo;
18
19
  #signalBus;
19
20
  #reportStore;
20
21
  #logger = Logger.getInstance();
21
- constructor(db, options = {}) {
22
- this.#db = db;
22
+ constructor(knowledgeRepo, options = {}) {
23
+ this.#knowledgeRepo = knowledgeRepo;
23
24
  this.#signalBus = options.signalBus ?? null;
24
25
  this.#reportStore = options.reportStore ?? null;
25
26
  }
26
27
  /**
27
28
  * 运行全部 4 种增强策略
28
29
  */
29
- analyzeAll() {
30
+ async analyzeAll() {
31
+ const entries = await this.#knowledgeRepo.findAllByLifecycles(PUBLISHED_LIFECYCLES);
30
32
  const suggestions = [
31
- ...this.#checkMissingCodeExamples(),
32
- ...this.#checkLowAdoption(),
33
- ...this.#checkLowAuthority(),
34
- ...this.#checkDeprecatedReferences(),
33
+ ...this.#checkMissingCodeExamples(entries),
34
+ ...this.#checkLowAdoption(entries),
35
+ ...this.#checkLowAuthority(entries),
36
+ ...(await this.#checkDeprecatedReferences(entries)),
35
37
  ];
36
38
  if (this.#reportStore && suggestions.length > 0) {
37
39
  void this.#reportStore.write({
@@ -49,30 +51,20 @@ export class EnhancementSuggester {
49
51
  return suggestions;
50
52
  }
51
53
  /* ── Strategy ①: Guard 频繁命中但无 coreCode ── */
52
- #checkMissingCodeExamples() {
53
- const rows = this.#db
54
- .prepare(`SELECT id, title, coreCode, stats
55
- FROM knowledge_entries
56
- WHERE lifecycle IN ('active', 'staging') AND kind = 'rule'`)
57
- .all();
54
+ #checkMissingCodeExamples(entries) {
55
+ const rules = entries.filter((e) => e.kind === 'rule');
58
56
  const suggestions = [];
59
- for (const row of rows) {
60
- const hasCode = row.coreCode && row.coreCode.trim().length > 10;
57
+ for (const entry of rules) {
58
+ const hasCode = entry.coreCode && entry.coreCode.trim().length > 10;
61
59
  if (hasCode) {
62
60
  continue;
63
61
  }
64
- let stats = {};
65
- try {
66
- stats = JSON.parse(row.stats || '{}');
67
- }
68
- catch {
69
- continue;
70
- }
62
+ const stats = (entry.stats ?? {});
71
63
  const guardHits = stats.guardHits || 0;
72
64
  if (guardHits >= GUARD_HIT_THRESHOLD) {
73
65
  suggestions.push({
74
- recipeId: row.id,
75
- title: row.title,
66
+ recipeId: entry.id,
67
+ title: entry.title,
76
68
  type: 'missing_code_example',
77
69
  description: `Guard 已命中 ${guardHits} 次但无代码示例,建议补充 coreCode 帮助开发者理解正确用法`,
78
70
  priority: guardHits >= GUARD_HIT_THRESHOLD * 3 ? 'high' : 'medium',
@@ -83,27 +75,16 @@ export class EnhancementSuggester {
83
75
  return suggestions;
84
76
  }
85
77
  /* ── Strategy ②: Search 高频命中但 adoptions=0 ── */
86
- #checkLowAdoption() {
87
- const rows = this.#db
88
- .prepare(`SELECT id, title, stats
89
- FROM knowledge_entries
90
- WHERE lifecycle IN ('active', 'staging')`)
91
- .all();
78
+ #checkLowAdoption(entries) {
92
79
  const suggestions = [];
93
- for (const row of rows) {
94
- let stats = {};
95
- try {
96
- stats = JSON.parse(row.stats || '{}');
97
- }
98
- catch {
99
- continue;
100
- }
80
+ for (const entry of entries) {
81
+ const stats = (entry.stats ?? {});
101
82
  const searchHits = stats.searchHits || 0;
102
83
  const adoptions = stats.adoptions || 0;
103
84
  if (searchHits >= SEARCH_HIT_THRESHOLD && adoptions === 0) {
104
85
  suggestions.push({
105
- recipeId: row.id,
106
- title: row.title,
86
+ recipeId: entry.id,
87
+ title: entry.title,
107
88
  type: 'low_adoption',
108
89
  description: `搜索命中 ${searchHits} 次但采纳为 0,建议改善 usageGuide 或 whenClause 使知识更具可操作性`,
109
90
  priority: searchHits >= SEARCH_HIT_THRESHOLD * 3 ? 'high' : 'medium',
@@ -114,28 +95,16 @@ export class EnhancementSuggester {
114
95
  return suggestions;
115
96
  }
116
97
  /* ── Strategy ③: 同类知识中 authority 偏低 ── */
117
- #checkLowAuthority() {
118
- const rows = this.#db
119
- .prepare(`SELECT id, title, category, stats
120
- FROM knowledge_entries
121
- WHERE lifecycle IN ('active', 'staging')`)
122
- .all();
123
- // 按 category 分组计算 authority 分位
98
+ #checkLowAuthority(entries) {
124
99
  const byCategory = new Map();
125
- for (const row of rows) {
126
- let stats = {};
127
- try {
128
- stats = JSON.parse(row.stats || '{}');
129
- }
130
- catch {
131
- continue;
132
- }
100
+ for (const entry of entries) {
101
+ const stats = (entry.stats ?? {});
133
102
  const authority = stats.authority || 0;
134
- const cat = row.category || 'general';
103
+ const cat = entry.category || 'general';
135
104
  if (!byCategory.has(cat)) {
136
105
  byCategory.set(cat, []);
137
106
  }
138
- byCategory.get(cat).push({ id: row.id, title: row.title, authority });
107
+ byCategory.get(cat)?.push({ id: entry.id, title: entry.title, authority });
139
108
  }
140
109
  const suggestions = [];
141
110
  for (const [category, entries] of byCategory) {
@@ -163,22 +132,10 @@ export class EnhancementSuggester {
163
132
  return suggestions;
164
133
  }
165
134
  /* ── Strategy ④: 关联 Recipe 已 deprecated ── */
166
- #checkDeprecatedReferences() {
167
- const rows = this.#db
168
- .prepare(`SELECT id, title, relations
169
- FROM knowledge_entries
170
- WHERE lifecycle IN ('active', 'staging')`)
171
- .all();
135
+ async #checkDeprecatedReferences(entries) {
172
136
  const suggestions = [];
173
- for (const row of rows) {
174
- let relations = {};
175
- try {
176
- relations = JSON.parse(row.relations || '{}');
177
- }
178
- catch {
179
- continue;
180
- }
181
- // 检查 related, depends_on 等关系桶中的 ID
137
+ for (const entry of entries) {
138
+ const relations = (entry.relations ?? {});
182
139
  const relatedIds = [];
183
140
  for (const [bucket, ids] of Object.entries(relations)) {
184
141
  if (bucket === 'deprecated_by') {
@@ -192,19 +149,18 @@ export class EnhancementSuggester {
192
149
  continue;
193
150
  }
194
151
  // 批量检查关联条目的 lifecycle
195
- const placeholders = relatedIds.map(() => '?').join(',');
196
- const deprecated = this.#db
197
- .prepare(`SELECT id, title FROM knowledge_entries WHERE id IN (${placeholders}) AND lifecycle = 'deprecated'`)
198
- .all(...relatedIds);
199
- for (const dep of deprecated) {
200
- suggestions.push({
201
- recipeId: row.id,
202
- title: row.title,
203
- type: 'deprecated_reference',
204
- description: `引用了已废弃的 Recipe "${dep.title}" (${dep.id}),建议检查引用是否过时`,
205
- priority: 'high',
206
- evidence: [`referenced: ${dep.id}`, `referenced_title: ${dep.title}`],
207
- });
152
+ for (const relId of relatedIds) {
153
+ const relEntry = await this.#knowledgeRepo.findById(relId);
154
+ if (relEntry && relEntry.lifecycle === Lifecycle.DEPRECATED) {
155
+ suggestions.push({
156
+ recipeId: entry.id,
157
+ title: entry.title,
158
+ type: 'deprecated_reference',
159
+ description: `引用了已废弃的 Recipe "${relEntry.title}" (${relEntry.id}),建议检查引用是否过时`,
160
+ priority: 'high',
161
+ evidence: [`referenced: ${relEntry.id}`, `referenced_title: ${relEntry.title}`],
162
+ });
163
+ }
208
164
  }
209
165
  }
210
166
  return suggestions;
@@ -68,17 +68,17 @@ export declare class KnowledgeMetabolism {
68
68
  /**
69
69
  * 执行完整治理周期
70
70
  */
71
- runFullCycle(): MetabolismReport;
71
+ runFullCycle(): Promise<MetabolismReport>;
72
72
  /**
73
73
  * 只执行衰退扫描
74
74
  */
75
- checkDecay(): DecayScoreResult[];
75
+ checkDecay(): Promise<DecayScoreResult[]>;
76
76
  /**
77
77
  * 只执行矛盾检测
78
78
  */
79
- checkContradictions(): ContradictionResult[];
79
+ checkContradictions(): Promise<ContradictionResult[]>;
80
80
  /**
81
81
  * 只执行冗余分析
82
82
  */
83
- checkRedundancy(): RedundancyResult[];
83
+ checkRedundancy(): Promise<RedundancyResult[]>;
84
84
  }
@@ -24,6 +24,7 @@ export class KnowledgeMetabolism {
24
24
  #logger = Logger.getInstance();
25
25
  #pendingTriggers = [];
26
26
  #debounceTimer = null;
27
+ #running = false;
27
28
  constructor(options) {
28
29
  this.#contradictionDetector = options.contradictionDetector;
29
30
  this.#redundancyAnalyzer = options.redundancyAnalyzer;
@@ -40,13 +41,17 @@ export class KnowledgeMetabolism {
40
41
  }
41
42
  }
42
43
  #scheduleMetabolism() {
44
+ // 当前正在执行周期时,忽略信号(防止自身产出的信号导致无限循环)
45
+ if (this.#running) {
46
+ return;
47
+ }
43
48
  if (this.#debounceTimer) {
44
49
  return;
45
50
  }
46
51
  this.#debounceTimer = setTimeout(() => {
47
52
  this.#debounceTimer = null;
48
- if (this.#pendingTriggers.length > 0) {
49
- this.runFullCycle();
53
+ if (this.#pendingTriggers.length > 0 && !this.#running) {
54
+ void this.runFullCycle();
50
55
  this.#pendingTriggers = [];
51
56
  }
52
57
  }, 30_000);
@@ -54,95 +59,121 @@ export class KnowledgeMetabolism {
54
59
  /**
55
60
  * 执行完整治理周期
56
61
  */
57
- runFullCycle() {
58
- this.#logger.info('KnowledgeMetabolism: starting full governance cycle');
59
- // 1. 衰退检测
60
- const decayResults = this.#decayDetector.scanAll();
61
- // 2. 矛盾检测
62
- const contradictions = this.#contradictionDetector.detectAll();
63
- // 3. 冗余分析
64
- const redundancies = this.#redundancyAnalyzer.analyzeAll();
65
- // 4. 生成进化提案
66
- const proposals = [
67
- ...this.#proposalsFromContradictions(contradictions),
68
- ...this.#proposalsFromRedundancies(redundancies),
69
- ...this.#proposalsFromDecay(decayResults),
70
- ];
71
- // 5. 持久化提案到 evolution_proposals 表
72
- let persistedCount = 0;
73
- if (this.#proposalRepo && proposals.length > 0) {
74
- for (const p of proposals) {
75
- const sourceMap = {
76
- contradiction: 'metabolism',
77
- redundancy: 'metabolism',
78
- decay: 'decay-scan',
79
- enhancement: 'metabolism',
80
- };
81
- const record = this.#proposalRepo.create({
82
- type: p.type,
83
- targetRecipeId: p.targetRecipeId,
84
- relatedRecipeIds: p.relatedRecipeIds,
85
- confidence: p.confidence,
86
- source: sourceMap[p.source] ?? 'metabolism',
87
- description: p.description,
88
- evidence: p.evidence.map((e) => ({ detail: e })),
89
- });
90
- if (record) {
91
- persistedCount++;
62
+ async runFullCycle() {
63
+ if (this.#running) {
64
+ this.#logger.warn('KnowledgeMetabolism: cycle already in progress, skipping');
65
+ return {
66
+ contradictions: [],
67
+ redundancies: [],
68
+ decayResults: [],
69
+ proposals: [],
70
+ summary: {
71
+ totalScanned: 0,
72
+ contradictionCount: 0,
73
+ redundancyCount: 0,
74
+ decayingCount: 0,
75
+ proposalCount: 0,
76
+ },
77
+ };
78
+ }
79
+ this.#running = true;
80
+ // 清除执行期间积累的信号,避免周期结束后立刻再次触发
81
+ this.#pendingTriggers = [];
82
+ try {
83
+ this.#logger.info('KnowledgeMetabolism: starting full governance cycle');
84
+ // 1. 衰退检测
85
+ const decayResults = await this.#decayDetector.scanAll();
86
+ // 2. 矛盾检测
87
+ const contradictions = await this.#contradictionDetector.detectAll();
88
+ // 3. 冗余分析
89
+ const redundancies = await this.#redundancyAnalyzer.analyzeAll();
90
+ // 4. 生成进化提案
91
+ const proposals = [
92
+ ...this.#proposalsFromContradictions(contradictions),
93
+ ...this.#proposalsFromRedundancies(redundancies),
94
+ ...this.#proposalsFromDecay(decayResults),
95
+ ];
96
+ // 5. 持久化提案到 evolution_proposals 表
97
+ let persistedCount = 0;
98
+ if (this.#proposalRepo && proposals.length > 0) {
99
+ for (const p of proposals) {
100
+ const sourceMap = {
101
+ contradiction: 'metabolism',
102
+ redundancy: 'metabolism',
103
+ decay: 'decay-scan',
104
+ enhancement: 'metabolism',
105
+ };
106
+ const record = this.#proposalRepo.create({
107
+ type: p.type,
108
+ targetRecipeId: p.targetRecipeId,
109
+ relatedRecipeIds: p.relatedRecipeIds,
110
+ confidence: p.confidence,
111
+ source: sourceMap[p.source] ?? 'metabolism',
112
+ description: p.description,
113
+ evidence: p.evidence.map((e) => ({ detail: e })),
114
+ });
115
+ if (record) {
116
+ persistedCount++;
117
+ }
92
118
  }
93
119
  }
94
- }
95
- // 6. 写入治理报告(降级:同时写 ReportStore)
96
- if (this.#reportStore && proposals.length > 0) {
97
- void this.#reportStore.write({
98
- category: 'governance',
99
- type: 'metabolism_cycle',
100
- producer: 'KnowledgeMetabolism',
101
- data: {
102
- proposalCount: proposals.length,
103
- persistedCount,
120
+ // 6. 写入治理报告(降级:同时写 ReportStore)
121
+ if (this.#reportStore && proposals.length > 0) {
122
+ void this.#reportStore.write({
123
+ category: 'governance',
124
+ type: 'metabolism_cycle',
125
+ producer: 'KnowledgeMetabolism',
126
+ data: {
127
+ proposalCount: proposals.length,
128
+ persistedCount,
129
+ contradictionCount: contradictions.length,
130
+ redundancyCount: redundancies.length,
131
+ decayingCount: decayResults.filter((d) => d.level !== 'healthy' && d.level !== 'watch')
132
+ .length,
133
+ },
134
+ timestamp: Date.now(),
135
+ });
136
+ }
137
+ const report = {
138
+ contradictions,
139
+ redundancies,
140
+ decayResults,
141
+ proposals,
142
+ summary: {
143
+ totalScanned: decayResults.length,
104
144
  contradictionCount: contradictions.length,
105
145
  redundancyCount: redundancies.length,
106
146
  decayingCount: decayResults.filter((d) => d.level !== 'healthy' && d.level !== 'watch')
107
147
  .length,
148
+ proposalCount: proposals.length,
108
149
  },
109
- timestamp: Date.now(),
110
- });
150
+ };
151
+ this.#logger.info(`KnowledgeMetabolism: cycle complete — ${report.summary.proposalCount} proposals generated`);
152
+ return report;
153
+ }
154
+ finally {
155
+ this.#running = false;
156
+ // 清除周期期间积累的信号,防止自身产出的信号立即触发下一轮
157
+ this.#pendingTriggers = [];
111
158
  }
112
- const report = {
113
- contradictions,
114
- redundancies,
115
- decayResults,
116
- proposals,
117
- summary: {
118
- totalScanned: decayResults.length,
119
- contradictionCount: contradictions.length,
120
- redundancyCount: redundancies.length,
121
- decayingCount: decayResults.filter((d) => d.level !== 'healthy' && d.level !== 'watch')
122
- .length,
123
- proposalCount: proposals.length,
124
- },
125
- };
126
- this.#logger.info(`KnowledgeMetabolism: cycle complete — ${report.summary.proposalCount} proposals generated`);
127
- return report;
128
159
  }
129
160
  /**
130
161
  * 只执行衰退扫描
131
162
  */
132
- checkDecay() {
133
- return this.#decayDetector.scanAll();
163
+ async checkDecay() {
164
+ return await this.#decayDetector.scanAll();
134
165
  }
135
166
  /**
136
167
  * 只执行矛盾检测
137
168
  */
138
- checkContradictions() {
139
- return this.#contradictionDetector.detectAll();
169
+ async checkContradictions() {
170
+ return await this.#contradictionDetector.detectAll();
140
171
  }
141
172
  /**
142
173
  * 只执行冗余分析
143
174
  */
144
- checkRedundancy() {
145
- return this.#redundancyAnalyzer.analyzeAll();
175
+ async checkRedundancy() {
176
+ return await this.#redundancyAnalyzer.analyzeAll();
146
177
  }
147
178
  /* ── Proposal Generation ── */
148
179
  #proposalsFromContradictions(results) {
@@ -17,17 +17,10 @@
17
17
  */
18
18
  import type { SignalBus } from '../../infrastructure/signal/SignalBus.js';
19
19
  import type { ProposalRepository, ProposalType } from '../../repository/evolution/ProposalRepository.js';
20
+ import type { KnowledgeEdgeRepositoryImpl } from '../../repository/knowledge/KnowledgeEdgeRepository.js';
21
+ import type KnowledgeRepositoryImpl from '../../repository/knowledge/KnowledgeRepository.impl.js';
20
22
  import type { ContentPatcher } from './ContentPatcher.js';
21
23
  import type { RecipeLifecycleSupervisor } from './RecipeLifecycleSupervisor.js';
22
- interface DatabaseLike {
23
- prepare(sql: string): {
24
- all(...params: unknown[]): Record<string, unknown>[];
25
- get(...params: unknown[]): Record<string, unknown> | undefined;
26
- run(...params: unknown[]): {
27
- changes: number;
28
- };
29
- };
30
- }
31
24
  export interface ProposalExecutionResult {
32
25
  executed: {
33
26
  id: string;
@@ -51,16 +44,16 @@ export interface ProposalExecutionResult {
51
44
  }
52
45
  export declare class ProposalExecutor {
53
46
  #private;
54
- constructor(db: DatabaseLike, repo: ProposalRepository, options?: {
47
+ constructor(knowledgeRepo: KnowledgeRepositoryImpl, repo: ProposalRepository, options?: {
55
48
  signalBus?: SignalBus;
56
49
  contentPatcher?: ContentPatcher;
57
50
  supervisor?: RecipeLifecycleSupervisor;
51
+ knowledgeEdgeRepo?: KnowledgeEdgeRepositoryImpl;
58
52
  });
59
53
  /**
60
54
  * 定期调用(UiStartupTasks Stage 5)
61
55
  *
62
56
  * 扫描所有到期 Proposal → 评估 → 执行/拒绝/过期
63
57
  */
64
- checkAndExecute(): ProposalExecutionResult;
58
+ checkAndExecute(): Promise<ProposalExecutionResult>;
65
59
  }
66
- export {};