cogmem 3.6.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.
Files changed (793) hide show
  1. package/BENCHMARKS.md +62 -0
  2. package/CHANGELOG.md +215 -0
  3. package/CONCURRENT_ACCESS.md +27 -0
  4. package/CONTRIBUTING.md +32 -0
  5. package/LICENSE +21 -0
  6. package/MEMORY_ATLAS.md +101 -0
  7. package/MEMORY_MODEL.md +179 -0
  8. package/README.md +751 -0
  9. package/RECALL_EXPLAINABILITY.md +152 -0
  10. package/RELEASE_CHECKLIST.md +92 -0
  11. package/SECURITY.md +21 -0
  12. package/dist/adapters/MarkdownSourceLoader.d.ts +5 -0
  13. package/dist/adapters/MarkdownSourceLoader.js +19 -0
  14. package/dist/adapters/conversation/ConversationMarkdownAdapter.d.ts +9 -0
  15. package/dist/adapters/conversation/ConversationMarkdownAdapter.js +233 -0
  16. package/dist/adapters/hermes/HermesStateDbAdapter.d.ts +10 -0
  17. package/dist/adapters/hermes/HermesStateDbAdapter.js +268 -0
  18. package/dist/adapters/hermes/HermesWorkspaceProfile.d.ts +15 -0
  19. package/dist/adapters/hermes/HermesWorkspaceProfile.js +82 -0
  20. package/dist/adapters/index.d.ts +15 -0
  21. package/dist/adapters/index.js +12 -0
  22. package/dist/adapters/openclaw/OpenClawAdapterSupport.d.ts +14 -0
  23. package/dist/adapters/openclaw/OpenClawAdapterSupport.js +29 -0
  24. package/dist/adapters/openclaw/OpenClawDailyMemoryAdapter.d.ts +8 -0
  25. package/dist/adapters/openclaw/OpenClawDailyMemoryAdapter.js +35 -0
  26. package/dist/adapters/openclaw/OpenClawMemoryIndexAdapter.d.ts +8 -0
  27. package/dist/adapters/openclaw/OpenClawMemoryIndexAdapter.js +23 -0
  28. package/dist/adapters/openclaw/OpenClawPersonaAdapter.d.ts +8 -0
  29. package/dist/adapters/openclaw/OpenClawPersonaAdapter.js +24 -0
  30. package/dist/adapters/openclaw/OpenClawSessionAdapter.d.ts +8 -0
  31. package/dist/adapters/openclaw/OpenClawSessionAdapter.js +15 -0
  32. package/dist/adapters/openclaw/OpenClawUserProfileAdapter.d.ts +8 -0
  33. package/dist/adapters/openclaw/OpenClawUserProfileAdapter.js +24 -0
  34. package/dist/adapters/openclaw/OpenClawWorkspaceProfile.d.ts +38 -0
  35. package/dist/adapters/openclaw/OpenClawWorkspaceProfile.js +199 -0
  36. package/dist/adapters/soul/SoulMarkdownAdapter.d.ts +14 -0
  37. package/dist/adapters/soul/SoulMarkdownAdapter.js +255 -0
  38. package/dist/adapters/types.d.ts +97 -0
  39. package/dist/adapters/types.js +185 -0
  40. package/dist/agent/AgentMemoryBackend.d.ts +291 -0
  41. package/dist/agent/AgentMemoryBackend.js +1272 -0
  42. package/dist/agent/AgentRecallQueryCompiler.d.ts +20 -0
  43. package/dist/agent/AgentRecallQueryCompiler.js +289 -0
  44. package/dist/agent/ContextHygiene.d.ts +9 -0
  45. package/dist/agent/ContextHygiene.js +20 -0
  46. package/dist/agent/MemoryUsageReceipt.d.ts +35 -0
  47. package/dist/agent/MemoryUsageReceipt.js +136 -0
  48. package/dist/agent/SessionWorkingState.d.ts +20 -0
  49. package/dist/agent/SessionWorkingState.js +94 -0
  50. package/dist/agent/index.d.ts +6 -0
  51. package/dist/agent/index.js +5 -0
  52. package/dist/algorithm/AlgorithmReviewBackend.d.ts +84 -0
  53. package/dist/algorithm/AlgorithmReviewBackend.js +261 -0
  54. package/dist/algorithm/AlgorithmReviewMetrics.d.ts +23 -0
  55. package/dist/algorithm/AlgorithmReviewMetrics.js +25 -0
  56. package/dist/algorithm/Phase2ModelAlgorithmReviewBackend.d.ts +38 -0
  57. package/dist/algorithm/Phase2ModelAlgorithmReviewBackend.js +372 -0
  58. package/dist/assets/FileAssetIngestionService.d.ts +32 -0
  59. package/dist/assets/FileAssetIngestionService.js +133 -0
  60. package/dist/assets/FileAssetStore.d.ts +36 -0
  61. package/dist/assets/FileAssetStore.js +152 -0
  62. package/dist/assets/FileBlockStore.d.ts +12 -0
  63. package/dist/assets/FileBlockStore.js +110 -0
  64. package/dist/assets/FileChunkStore.d.ts +23 -0
  65. package/dist/assets/FileChunkStore.js +179 -0
  66. package/dist/assets/FileChunker.d.ts +10 -0
  67. package/dist/assets/FileChunker.js +69 -0
  68. package/dist/assets/FileLoaderRegistry.d.ts +8 -0
  69. package/dist/assets/FileLoaderRegistry.js +21 -0
  70. package/dist/assets/FileLoaders.d.ts +37 -0
  71. package/dist/assets/FileLoaders.js +268 -0
  72. package/dist/assets/index.d.ts +10 -0
  73. package/dist/assets/index.js +7 -0
  74. package/dist/assets/providers/types.d.ts +47 -0
  75. package/dist/assets/providers/types.js +1 -0
  76. package/dist/assets/types.d.ts +159 -0
  77. package/dist/assets/types.js +1 -0
  78. package/dist/atlas/ActionFrameExtractor.d.ts +15 -0
  79. package/dist/atlas/ActionFrameExtractor.js +135 -0
  80. package/dist/atlas/MemoryAtlasIndexer.d.ts +32 -0
  81. package/dist/atlas/MemoryAtlasIndexer.js +74 -0
  82. package/dist/atlas/MemoryAtlasQueryCompiler.d.ts +23 -0
  83. package/dist/atlas/MemoryAtlasQueryCompiler.js +55 -0
  84. package/dist/atlas/MemoryAtlasService.d.ts +25 -0
  85. package/dist/atlas/MemoryAtlasService.js +216 -0
  86. package/dist/atlas/MemoryAtlasTypes.d.ts +107 -0
  87. package/dist/atlas/MemoryAtlasTypes.js +1 -0
  88. package/dist/atlas/index.d.ts +6 -0
  89. package/dist/atlas/index.js +5 -0
  90. package/dist/backend/SemanticBackend.d.ts +40 -0
  91. package/dist/backend/SemanticBackend.js +107 -0
  92. package/dist/batch/IngestionCursorStore.d.ts +52 -0
  93. package/dist/batch/IngestionCursorStore.js +153 -0
  94. package/dist/batch/InstalledBatchProcessor.d.ts +88 -0
  95. package/dist/batch/InstalledBatchProcessor.js +179 -0
  96. package/dist/batch/SourceOnboarding.d.ts +56 -0
  97. package/dist/batch/SourceOnboarding.js +366 -0
  98. package/dist/belief/BeliefGovernanceService.d.ts +59 -0
  99. package/dist/belief/BeliefGovernanceService.js +183 -0
  100. package/dist/belief/BeliefStore.d.ts +78 -0
  101. package/dist/belief/BeliefStore.js +898 -0
  102. package/dist/benchmark/BenchmarkRegistry.d.ts +16 -0
  103. package/dist/benchmark/BenchmarkRegistry.js +97 -0
  104. package/dist/benchmark/BenchmarkReport.d.ts +23 -0
  105. package/dist/benchmark/BenchmarkReport.js +62 -0
  106. package/dist/benchmark/BenchmarkRunner.d.ts +27 -0
  107. package/dist/benchmark/BenchmarkRunner.js +64 -0
  108. package/dist/benchmark/BrainEval.d.ts +134 -0
  109. package/dist/benchmark/BrainEval.js +252 -0
  110. package/dist/benchmark/ExternalBenchmarkRunner.d.ts +8 -0
  111. package/dist/benchmark/ExternalBenchmarkRunner.js +12 -0
  112. package/dist/benchmark/LongMemEvalAdapter.d.ts +46 -0
  113. package/dist/benchmark/LongMemEvalAdapter.js +88 -0
  114. package/dist/benchmark/LongMemEvalCli.d.ts +6 -0
  115. package/dist/benchmark/LongMemEvalCli.js +26 -0
  116. package/dist/bin/CliJson.d.ts +17 -0
  117. package/dist/bin/CliJson.js +20 -0
  118. package/dist/bin/brain-eval.d.ts +3 -0
  119. package/dist/bin/brain-eval.js +46 -0
  120. package/dist/bin/cogmem.d.ts +3 -0
  121. package/dist/bin/cogmem.js +95 -0
  122. package/dist/bin/compact.d.ts +3 -0
  123. package/dist/bin/compact.js +96 -0
  124. package/dist/bin/connect.d.ts +3 -0
  125. package/dist/bin/connect.js +398 -0
  126. package/dist/bin/doctor.d.ts +3 -0
  127. package/dist/bin/doctor.js +171 -0
  128. package/dist/bin/dream.d.ts +3 -0
  129. package/dist/bin/dream.js +65 -0
  130. package/dist/bin/episode.d.ts +3 -0
  131. package/dist/bin/episode.js +268 -0
  132. package/dist/bin/explain-recall.d.ts +3 -0
  133. package/dist/bin/explain-recall.js +139 -0
  134. package/dist/bin/import-hermes.d.ts +3 -0
  135. package/dist/bin/import-hermes.js +6 -0
  136. package/dist/bin/import-openclaw.d.ts +3 -0
  137. package/dist/bin/import-openclaw.js +6 -0
  138. package/dist/bin/import-support.d.ts +43 -0
  139. package/dist/bin/import-support.js +528 -0
  140. package/dist/bin/init.d.ts +30 -0
  141. package/dist/bin/init.js +761 -0
  142. package/dist/bin/mcp.d.ts +3 -0
  143. package/dist/bin/mcp.js +52 -0
  144. package/dist/bin/memory.d.ts +3 -0
  145. package/dist/bin/memory.js +803 -0
  146. package/dist/bin/migrate-vectors.d.ts +3 -0
  147. package/dist/bin/migrate-vectors.js +74 -0
  148. package/dist/bin/migrate.d.ts +3 -0
  149. package/dist/bin/migrate.js +95 -0
  150. package/dist/bin/normalize-transcript.d.ts +16 -0
  151. package/dist/bin/normalize-transcript.js +153 -0
  152. package/dist/bin/openclaw.d.ts +3 -0
  153. package/dist/bin/openclaw.js +78 -0
  154. package/dist/bin/prospective.d.ts +3 -0
  155. package/dist/bin/prospective.js +115 -0
  156. package/dist/bin/re-embed.d.ts +3 -0
  157. package/dist/bin/re-embed.js +46 -0
  158. package/dist/bin/repair.d.ts +3 -0
  159. package/dist/bin/repair.js +118 -0
  160. package/dist/bin/snapshot.d.ts +3 -0
  161. package/dist/bin/snapshot.js +100 -0
  162. package/dist/bin/strategy.d.ts +3 -0
  163. package/dist/bin/strategy.js +66 -0
  164. package/dist/bin/update-release.d.ts +15 -0
  165. package/dist/bin/update-release.js +62 -0
  166. package/dist/bin/update.d.ts +3 -0
  167. package/dist/bin/update.js +215 -0
  168. package/dist/binding/BindingClassifier.d.ts +19 -0
  169. package/dist/binding/BindingClassifier.js +270 -0
  170. package/dist/binding/BindingDecisionEngine.d.ts +11 -0
  171. package/dist/binding/BindingDecisionEngine.js +13 -0
  172. package/dist/binding/ClaimKeyGenerator.d.ts +4 -0
  173. package/dist/binding/ClaimKeyGenerator.js +21 -0
  174. package/dist/binding/MemoryBindingService.d.ts +28 -0
  175. package/dist/binding/MemoryBindingService.js +283 -0
  176. package/dist/binding/MemoryBindingTypes.d.ts +140 -0
  177. package/dist/binding/MemoryBindingTypes.js +1 -0
  178. package/dist/binding/TopicPathRegistry.d.ts +5 -0
  179. package/dist/binding/TopicPathRegistry.js +33 -0
  180. package/dist/binding/index.d.ts +12 -0
  181. package/dist/binding/index.js +6 -0
  182. package/dist/boards/ApprovalBoard.d.ts +14 -0
  183. package/dist/boards/ApprovalBoard.js +32 -0
  184. package/dist/boards/Board.d.ts +23 -0
  185. package/dist/boards/Board.js +1 -0
  186. package/dist/boards/BoardEventBuffer.d.ts +10 -0
  187. package/dist/boards/BoardEventBuffer.js +22 -0
  188. package/dist/boards/BoardEventBus.d.ts +15 -0
  189. package/dist/boards/BoardEventBus.js +38 -0
  190. package/dist/boards/BoardEventFilter.d.ts +5 -0
  191. package/dist/boards/BoardEventFilter.js +1 -0
  192. package/dist/boards/BoardRegistry.d.ts +11 -0
  193. package/dist/boards/BoardRegistry.js +15 -0
  194. package/dist/boards/ContextBoard.d.ts +15 -0
  195. package/dist/boards/ContextBoard.js +33 -0
  196. package/dist/boards/MemoryBoard.d.ts +13 -0
  197. package/dist/boards/MemoryBoard.js +30 -0
  198. package/dist/boards/ProcessBoard.d.ts +16 -0
  199. package/dist/boards/ProcessBoard.js +56 -0
  200. package/dist/boards/ProposalBoard.d.ts +13 -0
  201. package/dist/boards/ProposalBoard.js +37 -0
  202. package/dist/boards/ReasoningTraceBoard.d.ts +11 -0
  203. package/dist/boards/ReasoningTraceBoard.js +34 -0
  204. package/dist/boards/TaskBoard.d.ts +14 -0
  205. package/dist/boards/TaskBoard.js +37 -0
  206. package/dist/boards/index.d.ts +13 -0
  207. package/dist/boards/index.js +12 -0
  208. package/dist/config/CogmemConfig.d.ts +43 -0
  209. package/dist/config/CogmemConfig.js +247 -0
  210. package/dist/config/VectorDimension.d.ts +13 -0
  211. package/dist/config/VectorDimension.js +53 -0
  212. package/dist/context/ContextCortex.d.ts +71 -0
  213. package/dist/context/ContextCortex.js +156 -0
  214. package/dist/context/index.d.ts +2 -0
  215. package/dist/context/index.js +1 -0
  216. package/dist/core/ImportanceLevels.d.ts +4 -0
  217. package/dist/core/ImportanceLevels.js +6 -0
  218. package/dist/core/IntentParser.d.ts +12 -0
  219. package/dist/core/IntentParser.js +211 -0
  220. package/dist/core/MemoryGraph.d.ts +100 -0
  221. package/dist/core/MemoryGraph.js +860 -0
  222. package/dist/core/Metabolism.d.ts +43 -0
  223. package/dist/core/Metabolism.js +196 -0
  224. package/dist/core/Neuron.d.ts +20 -0
  225. package/dist/core/Neuron.js +51 -0
  226. package/dist/core/QueryClassifier.d.ts +36 -0
  227. package/dist/core/QueryClassifier.js +161 -0
  228. package/dist/core/Reflection.d.ts +42 -0
  229. package/dist/core/Reflection.js +183 -0
  230. package/dist/core/ResonanceCore.d.ts +26 -0
  231. package/dist/core/ResonanceCore.js +115 -0
  232. package/dist/core/Synapse.d.ts +10 -0
  233. package/dist/core/Synapse.js +27 -0
  234. package/dist/core/TwoStagePulseRanker.d.ts +16 -0
  235. package/dist/core/TwoStagePulseRanker.js +120 -0
  236. package/dist/dream/DreamScheduler.d.ts +47 -0
  237. package/dist/dream/DreamScheduler.js +156 -0
  238. package/dist/dream/index.d.ts +2 -0
  239. package/dist/dream/index.js +1 -0
  240. package/dist/embedding/EmbeddingProvider.d.ts +16 -0
  241. package/dist/embedding/EmbeddingProvider.js +12 -0
  242. package/dist/embedding/NeuronEmbeddingStore.d.ts +38 -0
  243. package/dist/embedding/NeuronEmbeddingStore.js +193 -0
  244. package/dist/embedding/OllamaEmbeddingProvider.d.ts +21 -0
  245. package/dist/embedding/OllamaEmbeddingProvider.js +65 -0
  246. package/dist/embedding/QwenAPIEmbeddingProvider.d.ts +26 -0
  247. package/dist/embedding/QwenAPIEmbeddingProvider.js +53 -0
  248. package/dist/embedding/ReEmbeddingPipeline.d.ts +30 -0
  249. package/dist/embedding/ReEmbeddingPipeline.js +119 -0
  250. package/dist/embedding/ReEmbeddingStatus.d.ts +10 -0
  251. package/dist/embedding/ReEmbeddingStatus.js +1 -0
  252. package/dist/embedding/index.d.ts +11 -0
  253. package/dist/embedding/index.js +5 -0
  254. package/dist/encryption/AesGcmEncryptionProvider.d.ts +9 -0
  255. package/dist/encryption/AesGcmEncryptionProvider.js +42 -0
  256. package/dist/encryption/EncryptionProvider.d.ts +6 -0
  257. package/dist/encryption/EncryptionProvider.js +3 -0
  258. package/dist/encryption/index.d.ts +4 -0
  259. package/dist/encryption/index.js +2 -0
  260. package/dist/engine/BeliefExtractor.d.ts +48 -0
  261. package/dist/engine/BeliefExtractor.js +1189 -0
  262. package/dist/engine/CognitiveGraphCompiler.d.ts +24 -0
  263. package/dist/engine/CognitiveGraphCompiler.js +243 -0
  264. package/dist/engine/ConsolidationPipeline.d.ts +66 -0
  265. package/dist/engine/ConsolidationPipeline.js +376 -0
  266. package/dist/engine/ConsolidationTrigger.d.ts +18 -0
  267. package/dist/engine/ConsolidationTrigger.js +41 -0
  268. package/dist/engine/CrossTopicSynthesizer.d.ts +28 -0
  269. package/dist/engine/CrossTopicSynthesizer.js +70 -0
  270. package/dist/engine/CrossTopicTrigger.d.ts +17 -0
  271. package/dist/engine/CrossTopicTrigger.js +29 -0
  272. package/dist/engine/DeepWriteConfig.d.ts +14 -0
  273. package/dist/engine/DeepWriteConfig.js +37 -0
  274. package/dist/engine/DeepWriteMemoryCompiler.d.ts +43 -0
  275. package/dist/engine/DeepWriteMemoryCompiler.js +42 -0
  276. package/dist/engine/DeepWriteMemoryOrchestrator.d.ts +60 -0
  277. package/dist/engine/DeepWriteMemoryOrchestrator.js +175 -0
  278. package/dist/engine/DeepWritePromotionPolicy.d.ts +48 -0
  279. package/dist/engine/DeepWritePromotionPolicy.js +514 -0
  280. package/dist/engine/DeepWriteRedactor.d.ts +14 -0
  281. package/dist/engine/DeepWriteRedactor.js +53 -0
  282. package/dist/engine/DreamCuratorSchedule.d.ts +18 -0
  283. package/dist/engine/DreamCuratorSchedule.js +95 -0
  284. package/dist/engine/DreamCuratorWorker.d.ts +67 -0
  285. package/dist/engine/DreamCuratorWorker.js +908 -0
  286. package/dist/engine/EntityResolutionEngine.d.ts +45 -0
  287. package/dist/engine/EntityResolutionEngine.js +105 -0
  288. package/dist/engine/EpisodicSemanticDistiller.d.ts +25 -0
  289. package/dist/engine/EpisodicSemanticDistiller.js +68 -0
  290. package/dist/engine/EvolutionVerifier.d.ts +39 -0
  291. package/dist/engine/EvolutionVerifier.js +104 -0
  292. package/dist/engine/FactCompiler.d.ts +41 -0
  293. package/dist/engine/FactCompiler.js +820 -0
  294. package/dist/engine/GraphCommunityEngine.d.ts +20 -0
  295. package/dist/engine/GraphCommunityEngine.js +91 -0
  296. package/dist/engine/ImportanceSignalDetector.d.ts +11 -0
  297. package/dist/engine/ImportanceSignalDetector.js +51 -0
  298. package/dist/engine/IngestionEngine.d.ts +44 -0
  299. package/dist/engine/IngestionEngine.js +182 -0
  300. package/dist/engine/InteractionBinder.d.ts +16 -0
  301. package/dist/engine/InteractionBinder.js +87 -0
  302. package/dist/engine/LocalSemanticCompiler.d.ts +40 -0
  303. package/dist/engine/LocalSemanticCompiler.js +111 -0
  304. package/dist/engine/MemoryConsolidationEngine.d.ts +11 -0
  305. package/dist/engine/MemoryConsolidationEngine.js +21 -0
  306. package/dist/engine/MemoryGate.d.ts +10 -0
  307. package/dist/engine/MemoryGate.js +34 -0
  308. package/dist/engine/OfflineConsolidationPipeline.d.ts +148 -0
  309. package/dist/engine/OfflineConsolidationPipeline.js +670 -0
  310. package/dist/engine/OrphanCleaner.d.ts +15 -0
  311. package/dist/engine/OrphanCleaner.js +27 -0
  312. package/dist/engine/PipelineMetrics.d.ts +32 -0
  313. package/dist/engine/PipelineMetrics.js +126 -0
  314. package/dist/engine/PrincipleDecayPolicy.d.ts +17 -0
  315. package/dist/engine/PrincipleDecayPolicy.js +64 -0
  316. package/dist/engine/TopologyCompiler.d.ts +25 -0
  317. package/dist/engine/TopologyCompiler.js +276 -0
  318. package/dist/engine/WorkingMemoryDelta.d.ts +23 -0
  319. package/dist/engine/WorkingMemoryDelta.js +63 -0
  320. package/dist/entity/EntityGovernanceService.d.ts +47 -0
  321. package/dist/entity/EntityGovernanceService.js +215 -0
  322. package/dist/entity/index.d.ts +3 -0
  323. package/dist/entity/index.js +1 -0
  324. package/dist/episode/CogmemBlockStripper.d.ts +11 -0
  325. package/dist/episode/CogmemBlockStripper.js +58 -0
  326. package/dist/episode/CorrectionResolver.d.ts +30 -0
  327. package/dist/episode/CorrectionResolver.js +17 -0
  328. package/dist/episode/EpisodeAssembler.d.ts +54 -0
  329. package/dist/episode/EpisodeAssembler.js +203 -0
  330. package/dist/episode/EpisodeImportIdentity.d.ts +7 -0
  331. package/dist/episode/EpisodeImportIdentity.js +17 -0
  332. package/dist/episode/EpisodeSemanticSummarizer.d.ts +4 -0
  333. package/dist/episode/EpisodeSemanticSummarizer.js +31 -0
  334. package/dist/episode/EpisodeStore.d.ts +189 -0
  335. package/dist/episode/EpisodeStore.js +680 -0
  336. package/dist/episode/EpisodeTypes.d.ts +96 -0
  337. package/dist/episode/EpisodeTypes.js +1 -0
  338. package/dist/episode/TurnRelationClassifier.d.ts +40 -0
  339. package/dist/episode/TurnRelationClassifier.js +205 -0
  340. package/dist/episode/index.d.ts +9 -0
  341. package/dist/episode/index.js +8 -0
  342. package/dist/eval/datasets/contradiction_injection.d.ts +3 -0
  343. package/dist/eval/datasets/contradiction_injection.js +56 -0
  344. package/dist/eval/datasets/noisy_tool_output_corpus.d.ts +16 -0
  345. package/dist/eval/datasets/noisy_tool_output_corpus.js +59 -0
  346. package/dist/eval/datasets/synthetic_long_conversation.d.ts +40 -0
  347. package/dist/eval/datasets/synthetic_long_conversation.js +136 -0
  348. package/dist/eval/runners/EvalRunner.d.ts +12 -0
  349. package/dist/eval/runners/EvalRunner.js +66 -0
  350. package/dist/eval/runners/ReportFormatter.d.ts +13 -0
  351. package/dist/eval/runners/ReportFormatter.js +59 -0
  352. package/dist/eval/strategy/ContextOutcomeStore.d.ts +12 -0
  353. package/dist/eval/strategy/ContextOutcomeStore.js +44 -0
  354. package/dist/eval/strategy/ContextPolicyScorer.d.ts +25 -0
  355. package/dist/eval/strategy/ContextPolicyScorer.js +58 -0
  356. package/dist/eval/strategy/MemoryUseJudge.d.ts +49 -0
  357. package/dist/eval/strategy/MemoryUseJudge.js +75 -0
  358. package/dist/eval/strategy/StrategyDiversitySelector.d.ts +8 -0
  359. package/dist/eval/strategy/StrategyDiversitySelector.js +44 -0
  360. package/dist/eval/strategy/StrategyRolloutEvaluator.d.ts +15 -0
  361. package/dist/eval/strategy/StrategyRolloutEvaluator.js +30 -0
  362. package/dist/eval/strategy/index.d.ts +6 -0
  363. package/dist/eval/strategy/index.js +5 -0
  364. package/dist/factory.d.ts +726 -0
  365. package/dist/factory.js +2118 -0
  366. package/dist/governance/CandidateReviewService.d.ts +33 -0
  367. package/dist/governance/CandidateReviewService.js +126 -0
  368. package/dist/governance/ContradictionResolver.d.ts +22 -0
  369. package/dist/governance/ContradictionResolver.js +54 -0
  370. package/dist/governance/CredibilityScorer.d.ts +10 -0
  371. package/dist/governance/CredibilityScorer.js +29 -0
  372. package/dist/governance/DecayPolicy.d.ts +18 -0
  373. package/dist/governance/DecayPolicy.js +28 -0
  374. package/dist/governance/MemoryExplain.d.ts +46 -0
  375. package/dist/governance/MemoryExplain.js +62 -0
  376. package/dist/governance/MemoryGovernanceExecutor.d.ts +18 -0
  377. package/dist/governance/MemoryGovernanceExecutor.js +37 -0
  378. package/dist/governance/MemoryGovernancePlan.d.ts +36 -0
  379. package/dist/governance/MemoryGovernancePlan.js +1 -0
  380. package/dist/governance/MemoryGovernanceValidator.d.ts +13 -0
  381. package/dist/governance/MemoryGovernanceValidator.js +53 -0
  382. package/dist/governance/ObservationHygieneRules.d.ts +17 -0
  383. package/dist/governance/ObservationHygieneRules.js +28 -0
  384. package/dist/governance/PiiRedactor.d.ts +20 -0
  385. package/dist/governance/PiiRedactor.js +37 -0
  386. package/dist/governance/SupersedeChain.d.ts +21 -0
  387. package/dist/governance/SupersedeChain.js +107 -0
  388. package/dist/governance/index.d.ts +14 -0
  389. package/dist/governance/index.js +6 -0
  390. package/dist/graph/BrainGraphView.d.ts +20 -0
  391. package/dist/graph/BrainGraphView.js +45 -0
  392. package/dist/host/openclaw/AutoMemoryPluginInstaller.d.ts +45 -0
  393. package/dist/host/openclaw/AutoMemoryPluginInstaller.js +1904 -0
  394. package/dist/internal.d.ts +148 -0
  395. package/dist/internal.js +144 -0
  396. package/dist/lexicon/coreMemoryLexicon.d.ts +96 -0
  397. package/dist/lexicon/coreMemoryLexicon.js +525 -0
  398. package/dist/lexicon/language-packs/en.d.ts +42 -0
  399. package/dist/lexicon/language-packs/en.js +41 -0
  400. package/dist/lexicon/language-packs/zh.d.ts +42 -0
  401. package/dist/lexicon/language-packs/zh.js +41 -0
  402. package/dist/lexicon/zh/entities.d.ts +2 -0
  403. package/dist/lexicon/zh/entities.js +17 -0
  404. package/dist/lexicon/zh/index.d.ts +5 -0
  405. package/dist/lexicon/zh/index.js +3 -0
  406. package/dist/lexicon/zh/stopwords.d.ts +2 -0
  407. package/dist/lexicon/zh/stopwords.js +22 -0
  408. package/dist/lexicon/zh/topics.d.ts +6 -0
  409. package/dist/lexicon/zh/topics.js +52 -0
  410. package/dist/mcp/CoreMcpTools.d.ts +33 -0
  411. package/dist/mcp/CoreMcpTools.js +832 -0
  412. package/dist/mcp/server.d.ts +5 -0
  413. package/dist/mcp/server.js +29 -0
  414. package/dist/meta/MetaObservationCollector.d.ts +37 -0
  415. package/dist/meta/MetaObservationCollector.js +348 -0
  416. package/dist/meta/PolicyProposalGenerator.d.ts +11 -0
  417. package/dist/meta/PolicyProposalGenerator.js +159 -0
  418. package/dist/meta/ProposalApplier.d.ts +18 -0
  419. package/dist/meta/ProposalApplier.js +91 -0
  420. package/dist/meta/ProposalConfigOverlay.d.ts +13 -0
  421. package/dist/meta/ProposalConfigOverlay.js +27 -0
  422. package/dist/meta/ProposalEvalRunner.d.ts +31 -0
  423. package/dist/meta/ProposalEvalRunner.js +62 -0
  424. package/dist/meta/ProposalLedger.d.ts +34 -0
  425. package/dist/meta/ProposalLedger.js +242 -0
  426. package/dist/meta/types.d.ts +63 -0
  427. package/dist/meta/types.js +1 -0
  428. package/dist/migrations/0001_init.d.ts +4 -0
  429. package/dist/migrations/0001_init.js +67 -0
  430. package/dist/migrations/0002_v06_platform.d.ts +10 -0
  431. package/dist/migrations/0002_v06_platform.js +103 -0
  432. package/dist/migrations/0003_v07_dialogues.d.ts +9 -0
  433. package/dist/migrations/0003_v07_dialogues.js +53 -0
  434. package/dist/migrations/0004_v09_self_improvement.d.ts +9 -0
  435. package/dist/migrations/0004_v09_self_improvement.js +100 -0
  436. package/dist/migrations/0005_dialogue_buffer.d.ts +8 -0
  437. package/dist/migrations/0005_dialogue_buffer.js +44 -0
  438. package/dist/migrations/0006_deep_write_memory.d.ts +3 -0
  439. package/dist/migrations/0006_deep_write_memory.js +54 -0
  440. package/dist/migrations/0007_deep_write_summaries.d.ts +3 -0
  441. package/dist/migrations/0007_deep_write_summaries.js +24 -0
  442. package/dist/migrations/0009_memory_importance.d.ts +3 -0
  443. package/dist/migrations/0009_memory_importance.js +18 -0
  444. package/dist/migrations/0010_skill_neurons.d.ts +3 -0
  445. package/dist/migrations/0010_skill_neurons.js +19 -0
  446. package/dist/migrations/0011_topic_path.d.ts +3 -0
  447. package/dist/migrations/0011_topic_path.js +19 -0
  448. package/dist/migrations/0012_governance_security.d.ts +3 -0
  449. package/dist/migrations/0012_governance_security.js +23 -0
  450. package/dist/migrations/0015_memory_governance.d.ts +3 -0
  451. package/dist/migrations/0015_memory_governance.js +74 -0
  452. package/dist/migrations/0016_entity_governance.d.ts +3 -0
  453. package/dist/migrations/0016_entity_governance.js +40 -0
  454. package/dist/migrations/0017_belief_graph.d.ts +3 -0
  455. package/dist/migrations/0017_belief_graph.js +41 -0
  456. package/dist/migrations/0018_temporal_memory.d.ts +3 -0
  457. package/dist/migrations/0018_temporal_memory.js +25 -0
  458. package/dist/migrations/0019_context_cortex.d.ts +3 -0
  459. package/dist/migrations/0019_context_cortex.js +19 -0
  460. package/dist/migrations/0020_prospective_memory.d.ts +3 -0
  461. package/dist/migrations/0020_prospective_memory.js +42 -0
  462. package/dist/migrations/0021_strategy_cortex.d.ts +3 -0
  463. package/dist/migrations/0021_strategy_cortex.js +23 -0
  464. package/dist/migrations/0022_episode_dream_engine.d.ts +3 -0
  465. package/dist/migrations/0022_episode_dream_engine.js +74 -0
  466. package/dist/migrations/0023_episode_dream_hardening.d.ts +3 -0
  467. package/dist/migrations/0023_episode_dream_hardening.js +65 -0
  468. package/dist/migrations/0024_episode_ontology_reliability.d.ts +3 -0
  469. package/dist/migrations/0024_episode_ontology_reliability.js +70 -0
  470. package/dist/migrations/0025_memory_atlas.d.ts +6 -0
  471. package/dist/migrations/0025_memory_atlas.js +268 -0
  472. package/dist/migrations/0026_runtime_governance_atlas_reliability.d.ts +3 -0
  473. package/dist/migrations/0026_runtime_governance_atlas_reliability.js +72 -0
  474. package/dist/migrations/0027_openclaw_upgrade_hotfix.d.ts +3 -0
  475. package/dist/migrations/0027_openclaw_upgrade_hotfix.js +21 -0
  476. package/dist/migrations/SchemaMigrationRunner.d.ts +21 -0
  477. package/dist/migrations/SchemaMigrationRunner.js +67 -0
  478. package/dist/migrations/index.d.ts +36 -0
  479. package/dist/migrations/index.js +57 -0
  480. package/dist/models/ModelCapabilityRouter.d.ts +17 -0
  481. package/dist/models/ModelCapabilityRouter.js +75 -0
  482. package/dist/models/ModelRegistry.d.ts +15 -0
  483. package/dist/models/ModelRegistry.js +132 -0
  484. package/dist/models/ModelRole.d.ts +19 -0
  485. package/dist/models/ModelRole.js +1 -0
  486. package/dist/models/UserInsight.d.ts +16 -0
  487. package/dist/models/UserInsight.js +9 -0
  488. package/dist/models/UserInsightExtractor.d.ts +19 -0
  489. package/dist/models/UserInsightExtractor.js +99 -0
  490. package/dist/models/UserModelManager.d.ts +21 -0
  491. package/dist/models/UserModelManager.js +41 -0
  492. package/dist/models/UserModelStore.d.ts +20 -0
  493. package/dist/models/UserModelStore.js +136 -0
  494. package/dist/models/WorkingMemoryReporter.d.ts +16 -0
  495. package/dist/models/WorkingMemoryReporter.js +38 -0
  496. package/dist/models/adapters/MemoryReviewAdapter.d.ts +12 -0
  497. package/dist/models/adapters/MemoryReviewAdapter.js +77 -0
  498. package/dist/models/index.d.ts +8 -0
  499. package/dist/models/index.js +5 -0
  500. package/dist/models/providers/AnthropicClient.d.ts +17 -0
  501. package/dist/models/providers/AnthropicClient.js +40 -0
  502. package/dist/models/providers/OpenAICompatibleClient.d.ts +24 -0
  503. package/dist/models/providers/OpenAICompatibleClient.js +76 -0
  504. package/dist/observability/DecisionExplainer.d.ts +5 -0
  505. package/dist/observability/DecisionExplainer.js +62 -0
  506. package/dist/observability/TraceEvent.d.ts +11 -0
  507. package/dist/observability/TraceEvent.js +1 -0
  508. package/dist/observability/TraceQuery.d.ts +15 -0
  509. package/dist/observability/TraceQuery.js +28 -0
  510. package/dist/observability/TraceStore.d.ts +15 -0
  511. package/dist/observability/TraceStore.js +110 -0
  512. package/dist/observability/TraceWriter.d.ts +8 -0
  513. package/dist/observability/TraceWriter.js +14 -0
  514. package/dist/ontology/MemoryOntology.d.ts +4 -0
  515. package/dist/ontology/MemoryOntology.js +7 -0
  516. package/dist/prospective/ProspectiveMemoryService.d.ts +79 -0
  517. package/dist/prospective/ProspectiveMemoryService.js +258 -0
  518. package/dist/prospective/index.d.ts +2 -0
  519. package/dist/prospective/index.js +1 -0
  520. package/dist/public.d.ts +160 -0
  521. package/dist/public.js +115 -0
  522. package/dist/recall/BrainRecall.d.ts +96 -0
  523. package/dist/recall/BrainRecall.js +574 -0
  524. package/dist/recall/HierarchicalRecallRouter.d.ts +24 -0
  525. package/dist/recall/HierarchicalRecallRouter.js +62 -0
  526. package/dist/recall/RecallExplanation.d.ts +59 -0
  527. package/dist/recall/RecallExplanation.js +244 -0
  528. package/dist/recall/RecallGovernance.d.ts +10 -0
  529. package/dist/recall/RecallGovernance.js +83 -0
  530. package/dist/recall/RecallSufficiencyGate.d.ts +40 -0
  531. package/dist/recall/RecallSufficiencyGate.js +208 -0
  532. package/dist/recall/SourceContextMetadata.d.ts +49 -0
  533. package/dist/recall/SourceContextMetadata.js +134 -0
  534. package/dist/recall/TopicClassifier.d.ts +33 -0
  535. package/dist/recall/TopicClassifier.js +138 -0
  536. package/dist/recall/TopicDecayPolicy.d.ts +15 -0
  537. package/dist/recall/TopicDecayPolicy.js +46 -0
  538. package/dist/recall/TopicRegistry.d.ts +12 -0
  539. package/dist/recall/TopicRegistry.js +26 -0
  540. package/dist/recall/TopicSummaryBoard.d.ts +27 -0
  541. package/dist/recall/TopicSummaryBoard.js +139 -0
  542. package/dist/recall/VectorCandidateFilter.d.ts +50 -0
  543. package/dist/recall/VectorCandidateFilter.js +78 -0
  544. package/dist/retrieval/ConditionDslEvaluator.d.ts +33 -0
  545. package/dist/retrieval/ConditionDslEvaluator.js +160 -0
  546. package/dist/retrieval/EntityActivationIndex.d.ts +14 -0
  547. package/dist/retrieval/EntityActivationIndex.js +19 -0
  548. package/dist/retrieval/EvidenceFusionPolicy.d.ts +30 -0
  549. package/dist/retrieval/EvidenceFusionPolicy.js +112 -0
  550. package/dist/retrieval/EvidenceFusionRanker.d.ts +13 -0
  551. package/dist/retrieval/EvidenceFusionRanker.js +17 -0
  552. package/dist/retrieval/NarrativeRecallAssembler.d.ts +32 -0
  553. package/dist/retrieval/NarrativeRecallAssembler.js +27 -0
  554. package/dist/retrieval/NativeQueryParser.d.ts +23 -0
  555. package/dist/retrieval/NativeQueryParser.js +135 -0
  556. package/dist/retrieval/PlanDslExecutor.d.ts +67 -0
  557. package/dist/retrieval/PlanDslExecutor.js +194 -0
  558. package/dist/retrieval/PolicyRuntimeEvaluator.d.ts +48 -0
  559. package/dist/retrieval/PolicyRuntimeEvaluator.js +96 -0
  560. package/dist/retrieval/PolicySideEffectExecutor.d.ts +50 -0
  561. package/dist/retrieval/PolicySideEffectExecutor.js +202 -0
  562. package/dist/retrieval/PulseRetrievalEngine.d.ts +37 -0
  563. package/dist/retrieval/PulseRetrievalEngine.js +51 -0
  564. package/dist/retrieval/QueryCompiler.d.ts +18 -0
  565. package/dist/retrieval/QueryCompiler.js +97 -0
  566. package/dist/retrieval/QueryTimePendingEntityResolver.d.ts +67 -0
  567. package/dist/retrieval/QueryTimePendingEntityResolver.js +260 -0
  568. package/dist/retrieval/RetrievalPlanner.d.ts +42 -0
  569. package/dist/retrieval/RetrievalPlanner.js +209 -0
  570. package/dist/retrieval/TemporalBranchSearch.d.ts +38 -0
  571. package/dist/retrieval/TemporalBranchSearch.js +109 -0
  572. package/dist/retrieval/UniverseNavigator.d.ts +43 -0
  573. package/dist/retrieval/UniverseNavigator.js +75 -0
  574. package/dist/retrieval/UniverseTraversalExecutor.d.ts +21 -0
  575. package/dist/retrieval/UniverseTraversalExecutor.js +77 -0
  576. package/dist/routing/AnswerEvidenceTrace.d.ts +18 -0
  577. package/dist/routing/AnswerEvidenceTrace.js +1 -0
  578. package/dist/routing/BrainToolDispatcher.d.ts +37 -0
  579. package/dist/routing/BrainToolDispatcher.js +163 -0
  580. package/dist/routing/ConfidenceGate.d.ts +26 -0
  581. package/dist/routing/ConfidenceGate.js +40 -0
  582. package/dist/routing/ConfirmationPhraseMatcher.d.ts +9 -0
  583. package/dist/routing/ConfirmationPhraseMatcher.js +43 -0
  584. package/dist/routing/DirectReplyFormatter.d.ts +5 -0
  585. package/dist/routing/DirectReplyFormatter.js +55 -0
  586. package/dist/routing/EvidenceBudgetManager.d.ts +30 -0
  587. package/dist/routing/EvidenceBudgetManager.js +55 -0
  588. package/dist/routing/ExecutionLoop.d.ts +79 -0
  589. package/dist/routing/ExecutionLoop.js +234 -0
  590. package/dist/routing/IntentClassifier.d.ts +15 -0
  591. package/dist/routing/IntentClassifier.js +97 -0
  592. package/dist/routing/IntentPatternMatcher.d.ts +12 -0
  593. package/dist/routing/IntentPatternMatcher.js +206 -0
  594. package/dist/routing/IterativeLLMClarifier.d.ts +80 -0
  595. package/dist/routing/IterativeLLMClarifier.js +408 -0
  596. package/dist/routing/LLMToolSchema.d.ts +60 -0
  597. package/dist/routing/LLMToolSchema.js +143 -0
  598. package/dist/routing/MessageRouter.d.ts +20 -0
  599. package/dist/routing/MessageRouter.js +58 -0
  600. package/dist/routing/SessionContextSelector.d.ts +12 -0
  601. package/dist/routing/SessionContextSelector.js +86 -0
  602. package/dist/routing/SystemIntentClassifier.d.ts +15 -0
  603. package/dist/routing/SystemIntentClassifier.js +50 -0
  604. package/dist/routing/TaskPlan.d.ts +31 -0
  605. package/dist/routing/TaskPlan.js +1 -0
  606. package/dist/routing/TaskRouter.d.ts +13 -0
  607. package/dist/routing/TaskRouter.js +111 -0
  608. package/dist/routing/ToolCallParser.d.ts +16 -0
  609. package/dist/routing/ToolCallParser.js +123 -0
  610. package/dist/routing/ToolEvidenceNormalizer.d.ts +13 -0
  611. package/dist/routing/ToolEvidenceNormalizer.js +96 -0
  612. package/dist/routing/ToolEvidencePack.d.ts +36 -0
  613. package/dist/routing/ToolEvidencePack.js +84 -0
  614. package/dist/routing/ToolResultSanitizer.d.ts +19 -0
  615. package/dist/routing/ToolResultSanitizer.js +58 -0
  616. package/dist/routing/ToolUsePolicy.d.ts +78 -0
  617. package/dist/routing/ToolUsePolicy.js +163 -0
  618. package/dist/routing/index.d.ts +32 -0
  619. package/dist/routing/index.js +19 -0
  620. package/dist/routing/templates/ability_template.d.ts +2 -0
  621. package/dist/routing/templates/ability_template.js +34 -0
  622. package/dist/routing/templates/approvals_template.d.ts +2 -0
  623. package/dist/routing/templates/approvals_template.js +43 -0
  624. package/dist/routing/templates/context_template.d.ts +2 -0
  625. package/dist/routing/templates/context_template.js +25 -0
  626. package/dist/routing/templates/contradictions_template.d.ts +2 -0
  627. package/dist/routing/templates/contradictions_template.js +36 -0
  628. package/dist/routing/templates/importance_template.d.ts +2 -0
  629. package/dist/routing/templates/importance_template.js +23 -0
  630. package/dist/routing/templates/memory_template.d.ts +2 -0
  631. package/dist/routing/templates/memory_template.js +37 -0
  632. package/dist/routing/templates/self_manifest_template.d.ts +5 -0
  633. package/dist/routing/templates/self_manifest_template.js +64 -0
  634. package/dist/routing/templates/tasks_template.d.ts +2 -0
  635. package/dist/routing/templates/tasks_template.js +41 -0
  636. package/dist/routing/templates/trace_template.d.ts +2 -0
  637. package/dist/routing/templates/trace_template.js +37 -0
  638. package/dist/routing/tools/EntityExpandTool.d.ts +25 -0
  639. package/dist/routing/tools/EntityExpandTool.js +59 -0
  640. package/dist/routing/tools/NeuronContextTool.d.ts +32 -0
  641. package/dist/routing/tools/NeuronContextTool.js +66 -0
  642. package/dist/routing/tools/SecondaryRecallTool.d.ts +27 -0
  643. package/dist/routing/tools/SecondaryRecallTool.js +30 -0
  644. package/dist/routing/tools/SkillDiscoveryTool.d.ts +13 -0
  645. package/dist/routing/tools/SkillDiscoveryTool.js +11 -0
  646. package/dist/snapshot/SnapshotExporter.d.ts +13 -0
  647. package/dist/snapshot/SnapshotExporter.js +70 -0
  648. package/dist/snapshot/SnapshotHeader.d.ts +15 -0
  649. package/dist/snapshot/SnapshotHeader.js +1 -0
  650. package/dist/snapshot/SnapshotImporter.d.ts +20 -0
  651. package/dist/snapshot/SnapshotImporter.js +40 -0
  652. package/dist/snapshot/errors.d.ts +18 -0
  653. package/dist/snapshot/errors.js +34 -0
  654. package/dist/snapshot/index.d.ts +5 -0
  655. package/dist/snapshot/index.js +3 -0
  656. package/dist/storage/StorageCompactor.d.ts +30 -0
  657. package/dist/storage/StorageCompactor.js +95 -0
  658. package/dist/store/ActivationStore.d.ts +45 -0
  659. package/dist/store/ActivationStore.js +135 -0
  660. package/dist/store/BackgroundJobStore.d.ts +49 -0
  661. package/dist/store/BackgroundJobStore.js +156 -0
  662. package/dist/store/CandidateReviewStore.d.ts +33 -0
  663. package/dist/store/CandidateReviewStore.js +67 -0
  664. package/dist/store/CognitiveGraphStore.d.ts +42 -0
  665. package/dist/store/CognitiveGraphStore.js +193 -0
  666. package/dist/store/CompilerConfidenceStore.d.ts +20 -0
  667. package/dist/store/CompilerConfidenceStore.js +76 -0
  668. package/dist/store/DeepWriteCandidateStore.d.ts +94 -0
  669. package/dist/store/DeepWriteCandidateStore.js +290 -0
  670. package/dist/store/DeterministicEmbedder.d.ts +10 -0
  671. package/dist/store/DeterministicEmbedder.js +24 -0
  672. package/dist/store/DreamLedgerStore.d.ts +22 -0
  673. package/dist/store/DreamLedgerStore.js +84 -0
  674. package/dist/store/Embedder.d.ts +14 -0
  675. package/dist/store/Embedder.js +52 -0
  676. package/dist/store/EmbedderFactory.d.ts +12 -0
  677. package/dist/store/EmbedderFactory.js +51 -0
  678. package/dist/store/EntityStore.d.ts +195 -0
  679. package/dist/store/EntityStore.js +941 -0
  680. package/dist/store/EventStore.d.ts +118 -0
  681. package/dist/store/EventStore.js +699 -0
  682. package/dist/store/FactStore.d.ts +76 -0
  683. package/dist/store/FactStore.js +356 -0
  684. package/dist/store/HnswlibVectorStore.d.ts +2 -0
  685. package/dist/store/HnswlibVectorStore.js +1 -0
  686. package/dist/store/IVectorStore.d.ts +32 -0
  687. package/dist/store/IVectorStore.js +1 -0
  688. package/dist/store/InteractionUnitStore.d.ts +52 -0
  689. package/dist/store/InteractionUnitStore.js +167 -0
  690. package/dist/store/MemoryAtlasStore.d.ts +60 -0
  691. package/dist/store/MemoryAtlasStore.js +500 -0
  692. package/dist/store/MemoryBindingStore.d.ts +77 -0
  693. package/dist/store/MemoryBindingStore.js +608 -0
  694. package/dist/store/MemoryGovernanceStore.d.ts +23 -0
  695. package/dist/store/MemoryGovernanceStore.js +103 -0
  696. package/dist/store/MemoryInspectionStore.d.ts +61 -0
  697. package/dist/store/MemoryInspectionStore.js +215 -0
  698. package/dist/store/PlanRuntimeStore.d.ts +83 -0
  699. package/dist/store/PlanRuntimeStore.js +257 -0
  700. package/dist/store/PolicyExecutionProjector.d.ts +17 -0
  701. package/dist/store/PolicyExecutionProjector.js +115 -0
  702. package/dist/store/PolicyExecutionStore.d.ts +62 -0
  703. package/dist/store/PolicyExecutionStore.js +290 -0
  704. package/dist/store/PolicyProjectionStore.d.ts +18 -0
  705. package/dist/store/PolicyProjectionStore.js +61 -0
  706. package/dist/store/ProjectionObservabilityStore.d.ts +38 -0
  707. package/dist/store/ProjectionObservabilityStore.js +310 -0
  708. package/dist/store/ReasoningChainStore.d.ts +13 -0
  709. package/dist/store/ReasoningChainStore.js +74 -0
  710. package/dist/store/RuntimeProjectionStore.d.ts +18 -0
  711. package/dist/store/RuntimeProjectionStore.js +61 -0
  712. package/dist/store/RuntimeProjector.d.ts +17 -0
  713. package/dist/store/RuntimeProjector.js +119 -0
  714. package/dist/store/SqliteVecStore.d.ts +25 -0
  715. package/dist/store/SqliteVecStore.js +126 -0
  716. package/dist/store/SummaryStore.d.ts +56 -0
  717. package/dist/store/SummaryStore.js +225 -0
  718. package/dist/store/TemporalAdjacencyStore.d.ts +49 -0
  719. package/dist/store/TemporalAdjacencyStore.js +300 -0
  720. package/dist/store/TopologyStore.d.ts +89 -0
  721. package/dist/store/TopologyStore.js +657 -0
  722. package/dist/store/VectorProjector.d.ts +22 -0
  723. package/dist/store/VectorProjector.js +125 -0
  724. package/dist/store/VectorStore.d.ts +35 -0
  725. package/dist/store/VectorStore.js +201 -0
  726. package/dist/strategy/StrategyCapsule.d.ts +44 -0
  727. package/dist/strategy/StrategyCapsule.js +1 -0
  728. package/dist/strategy/StrategyConditionedCandidateBuilder.d.ts +9 -0
  729. package/dist/strategy/StrategyConditionedCandidateBuilder.js +11 -0
  730. package/dist/strategy/StrategyContextFormatter.d.ts +3 -0
  731. package/dist/strategy/StrategyContextFormatter.js +25 -0
  732. package/dist/strategy/StrategyCortex.d.ts +28 -0
  733. package/dist/strategy/StrategyCortex.js +78 -0
  734. package/dist/strategy/StrategyTemplateRegistry.d.ts +9 -0
  735. package/dist/strategy/StrategyTemplateRegistry.js +78 -0
  736. package/dist/strategy/index.d.ts +6 -0
  737. package/dist/strategy/index.js +5 -0
  738. package/dist/temporal/TemporalMemoryService.d.ts +62 -0
  739. package/dist/temporal/TemporalMemoryService.js +128 -0
  740. package/dist/temporal/index.d.ts +2 -0
  741. package/dist/temporal/index.js +1 -0
  742. package/dist/topic/TopicAliasRegistry.d.ts +21 -0
  743. package/dist/topic/TopicAliasRegistry.js +67 -0
  744. package/dist/topic/TopicGovernance.d.ts +21 -0
  745. package/dist/topic/TopicGovernance.js +173 -0
  746. package/dist/topic/TopicPathRegistry.d.ts +36 -0
  747. package/dist/topic/TopicPathRegistry.js +105 -0
  748. package/dist/topic/TopicRelationGraph.d.ts +23 -0
  749. package/dist/topic/TopicRelationGraph.js +55 -0
  750. package/dist/topic/TopicTypes.d.ts +73 -0
  751. package/dist/topic/TopicTypes.js +1 -0
  752. package/dist/topic/index.d.ts +6 -0
  753. package/dist/topic/index.js +5 -0
  754. package/dist/types/AsyncEnrichment.d.ts +62 -0
  755. package/dist/types/AsyncEnrichment.js +7 -0
  756. package/dist/types/BrainRecallResult.d.ts +66 -0
  757. package/dist/types/BrainRecallResult.js +1 -0
  758. package/dist/types/ExtensionPoints.d.ts +116 -0
  759. package/dist/types/ExtensionPoints.js +1 -0
  760. package/dist/types/Migration.d.ts +22 -0
  761. package/dist/types/Migration.js +1 -0
  762. package/dist/types/QueryTimePendingEntityResolution.d.ts +11 -0
  763. package/dist/types/QueryTimePendingEntityResolution.js +23 -0
  764. package/dist/types/index.d.ts +855 -0
  765. package/dist/types/index.js +24 -0
  766. package/dist/types/query-ir.d.ts +71 -0
  767. package/dist/types/query-ir.js +4 -0
  768. package/dist/types/reasoning.d.ts +16 -0
  769. package/dist/types/reasoning.js +4 -0
  770. package/dist/utils/AAAKGenerator.d.ts +57 -0
  771. package/dist/utils/AAAKGenerator.js +212 -0
  772. package/dist/utils/Config.d.ts +78 -0
  773. package/dist/utils/Config.js +91 -0
  774. package/dist/utils/ConversationMarkdownNormalization.d.ts +88 -0
  775. package/dist/utils/ConversationMarkdownNormalization.js +567 -0
  776. package/dist/utils/Logger.d.ts +22 -0
  777. package/dist/utils/Logger.js +77 -0
  778. package/dist/utils/hash.d.ts +33 -0
  779. package/dist/utils/hash.js +53 -0
  780. package/dist/utils/text.d.ts +2 -0
  781. package/dist/utils/text.js +19 -0
  782. package/dist/utils/vector.d.ts +26 -0
  783. package/dist/utils/vector.js +38 -0
  784. package/examples/hermes-backend/AGENTS.md +218 -0
  785. package/examples/hermes-backend/README.md +153 -0
  786. package/examples/hermes-backend/SKILL.md +365 -0
  787. package/examples/hermes-backend/references/operations.md +202 -0
  788. package/examples/openclaw-backend/AGENTS.md +195 -0
  789. package/examples/openclaw-backend/README.md +228 -0
  790. package/examples/openclaw-backend/SKILL.md +464 -0
  791. package/examples/openclaw-backend/references/operations.md +269 -0
  792. package/install.sh +84 -0
  793. package/package.json +90 -0
@@ -0,0 +1,1189 @@
1
+ const PREFERENCE_AND_DECISION_RULES = [
2
+ {
3
+ name: 'preference_like_cn',
4
+ regex: /(?:我)\s*(?:很)?喜欢\s*([\w\-./]+)/i,
5
+ predicatePrefix: 'preference.entity.',
6
+ value: 'like',
7
+ confidence: 0.92,
8
+ extractionReason: 'preference_signal'
9
+ },
10
+ {
11
+ name: 'preference_like_cn_generic',
12
+ regex: /(?:今天|本周|这个月)?\s*喜欢\s*([\w\-./]+)/i,
13
+ predicatePrefix: 'preference.entity.',
14
+ value: 'like',
15
+ confidence: 0.84,
16
+ extractionReason: 'preference_signal'
17
+ },
18
+ {
19
+ name: 'preference_like_en',
20
+ regex: /(?:I\s+like)\s*([\w\-./]+)/i,
21
+ predicatePrefix: 'preference.entity.',
22
+ value: 'like',
23
+ confidence: 0.9,
24
+ extractionReason: 'preference_signal'
25
+ },
26
+ {
27
+ name: 'preference_dislike_cn',
28
+ regex: /(?:我)\s*(?:很)?讨厌\s*([\w\-./]+)/i,
29
+ predicatePrefix: 'preference.entity.',
30
+ value: 'dislike',
31
+ confidence: 0.94,
32
+ extractionReason: 'preference_signal'
33
+ },
34
+ {
35
+ name: 'preference_dislike_en',
36
+ regex: /(?:I\s+dislike|不喜欢)\s*([\w\-./]+)/i,
37
+ predicatePrefix: 'preference.entity.',
38
+ value: 'dislike',
39
+ confidence: 0.9,
40
+ extractionReason: 'preference_signal'
41
+ },
42
+ {
43
+ name: 'preference_prefer',
44
+ regex: /(?:I\s+prefer|偏好)\s*([\w\-./]+)/i,
45
+ predicatePrefix: 'preference.entity.',
46
+ value: 'prefer',
47
+ confidence: 0.88,
48
+ extractionReason: 'preference_signal'
49
+ },
50
+ {
51
+ name: 'decision_selected',
52
+ regex: /(?:决定|决定使用|decide to use|choose)\s*([\w\-./]+)/i,
53
+ predicatePrefix: 'decision.entity.',
54
+ value: 'selected',
55
+ confidence: 0.82,
56
+ extractionReason: 'decision_statement'
57
+ }
58
+ ];
59
+ const CONSTRAINT_RULES = [
60
+ {
61
+ name: 'constraint_required_cn',
62
+ regex: /(?:必须(?:使用)?|一定要使用)\s*([\w\-./]+)/i,
63
+ predicatePrefix: 'constraint.entity.',
64
+ value: 'required',
65
+ confidence: 0.9,
66
+ extractionReason: 'workflow_rule'
67
+ },
68
+ {
69
+ name: 'constraint_required_en',
70
+ regex: /(?:must use)\s*([\w\-./]+)/i,
71
+ predicatePrefix: 'constraint.entity.',
72
+ value: 'required',
73
+ confidence: 0.9,
74
+ extractionReason: 'workflow_rule'
75
+ },
76
+ {
77
+ name: 'constraint_required_conditional',
78
+ regex: /(?:如果.+?[,,]\s*(?:就|则)\s*(?:使用|use))\s*([\w\-./]+)/i,
79
+ predicatePrefix: 'constraint.entity.',
80
+ value: 'required',
81
+ confidence: 0.88,
82
+ extractionReason: 'workflow_rule'
83
+ },
84
+ {
85
+ name: 'constraint_forbidden_cn',
86
+ regex: /(?:不能(?:使用)?|禁止使用|不要用)\s*([\w\-./]+)/i,
87
+ predicatePrefix: 'constraint.entity.',
88
+ value: 'forbidden',
89
+ confidence: 0.93,
90
+ extractionReason: 'workflow_rule'
91
+ },
92
+ {
93
+ name: 'constraint_forbidden_en',
94
+ regex: /(?:must not use|do not use|don't use)\s*([\w\-./]+)/i,
95
+ predicatePrefix: 'constraint.entity.',
96
+ value: 'forbidden',
97
+ confidence: 0.93,
98
+ extractionReason: 'workflow_rule'
99
+ }
100
+ ];
101
+ const WORKFLOW_RULES = [
102
+ {
103
+ name: 'workflow_cn',
104
+ regex: /(?:流程|工作流)\s*(?:是|为|:)\s*([\w\-./]+)/i,
105
+ predicatePrefix: 'workflow.entity.',
106
+ value: 'default',
107
+ confidence: 0.78,
108
+ extractionReason: 'workflow_rule'
109
+ },
110
+ {
111
+ name: 'workflow_en',
112
+ regex: /(?:workflow)\s*(?:is|:)\s*([\w\-./]+)/i,
113
+ predicatePrefix: 'workflow.entity.',
114
+ value: 'default',
115
+ confidence: 0.78,
116
+ extractionReason: 'workflow_rule'
117
+ }
118
+ ];
119
+ const FACT_RULES = [
120
+ {
121
+ name: 'fact_api_endpoint',
122
+ regex: /(?:api endpoint|endpoint)\s*(?:is|=|是)\s*([^\s,,。]+)/i,
123
+ predicate: 'fact.api_endpoint',
124
+ confidence: 0.88
125
+ },
126
+ {
127
+ name: 'fact_base_url',
128
+ regex: /(?:api base url|base url)\s*(?:is|=|是)\s*([^\s,,。]+)/i,
129
+ predicate: 'fact.api_base_url',
130
+ confidence: 0.9
131
+ },
132
+ {
133
+ name: 'fact_database',
134
+ regex: /(?:数据库|database)\s*(?:is|=|是)\s*([\w\-./]+)/i,
135
+ predicate: 'fact.database',
136
+ confidence: 0.84
137
+ }
138
+ ];
139
+ export class BeliefExtractor {
140
+ extract(context) {
141
+ const { neuron, sourceEventId } = context;
142
+ if (neuron.metadata.type !== 'chat' && neuron.metadata.type !== 'doc')
143
+ return [];
144
+ const content = neuron.content.trim();
145
+ if (!content)
146
+ return [];
147
+ const base = this.getBaseContext(neuron, sourceEventId, content);
148
+ const candidates = [
149
+ ...this.extractSchemaRules(content, base, PREFERENCE_AND_DECISION_RULES),
150
+ ...this.extractSchemaRules(content, base, CONSTRAINT_RULES),
151
+ ...this.extractSchemaRules(content, base, WORKFLOW_RULES),
152
+ ...this.extractFactRules(content, base),
153
+ ...this.extractMultiSlotFacts(content, base),
154
+ ...this.extractExecutablePlanGraphs(content, base),
155
+ ...this.extractProceduralSequences(content, base),
156
+ ...this.extractNestedFactGraphs(content, base)
157
+ ];
158
+ return this.dedupeCandidates(candidates);
159
+ }
160
+ extractSchemaRules(content, base, rules) {
161
+ const matches = [];
162
+ for (const rule of rules) {
163
+ const match = content.match(rule.regex);
164
+ if (!match?.[1])
165
+ continue;
166
+ const entity = this.normalizeEntity(match[1]);
167
+ if (!entity)
168
+ continue;
169
+ const value = typeof rule.value === 'function' ? rule.value(match) : rule.value;
170
+ const temporal = this.extractTemporalWindow(content, base.createdAt);
171
+ const conditional = this.extractCondition(content);
172
+ matches.push({
173
+ projectId: base.projectId,
174
+ scope: base.scope,
175
+ subject: 'user',
176
+ predicate: `${rule.predicatePrefix}${entity}`,
177
+ objectValue: {
178
+ raw: value,
179
+ normalized: value,
180
+ type: rule.valueType || 'enum'
181
+ },
182
+ confidence: rule.confidence,
183
+ sourceNeuronId: base.neuronId,
184
+ sourceEventId: base.sourceEventId,
185
+ sourceType: base.sourceType,
186
+ validityKind: this.resolveValidityKind(temporal.kind, conditional ? 'conditional' : undefined),
187
+ validFrom: temporal.validFrom,
188
+ validTo: temporal.validTo,
189
+ explanation: content,
190
+ metadata: {
191
+ extractorRule: rule.name,
192
+ ...(conditional ? {
193
+ conditionExpr: conditional.raw,
194
+ conditionDsl: conditional.dsl
195
+ } : {}),
196
+ ...(temporal.dsl ? { temporalDsl: temporal.dsl } : {})
197
+ },
198
+ extractionReason: rule.extractionReason
199
+ });
200
+ }
201
+ return matches;
202
+ }
203
+ extractFactRules(content, base) {
204
+ const matches = [];
205
+ for (const rule of FACT_RULES) {
206
+ const match = content.match(rule.regex);
207
+ if (!match?.[1])
208
+ continue;
209
+ const value = this.normalizeFactValue(match[1]);
210
+ if (!value)
211
+ continue;
212
+ const temporal = this.extractTemporalWindow(content, base.createdAt);
213
+ matches.push({
214
+ projectId: base.projectId,
215
+ scope: base.scope,
216
+ subject: 'user',
217
+ predicate: rule.predicate,
218
+ objectValue: {
219
+ raw: value,
220
+ normalized: value,
221
+ type: 'string'
222
+ },
223
+ confidence: rule.confidence,
224
+ sourceNeuronId: base.neuronId,
225
+ sourceEventId: base.sourceEventId,
226
+ sourceType: base.sourceType,
227
+ validityKind: temporal.kind,
228
+ validFrom: temporal.validFrom,
229
+ validTo: temporal.validTo,
230
+ explanation: content,
231
+ metadata: {
232
+ extractorRule: rule.name,
233
+ ...(temporal.dsl ? { temporalDsl: temporal.dsl } : {})
234
+ },
235
+ extractionReason: 'tool_verified_fact'
236
+ });
237
+ }
238
+ return matches;
239
+ }
240
+ extractMultiSlotFacts(content, base) {
241
+ const temporal = this.extractTemporalWindow(content, base.createdAt);
242
+ const matches = [];
243
+ const serviceUses = content.match(/(?:service|服务)\s*([\w\-./]+)\s*(?:uses|使用)\s*([\w\-./]+)/i);
244
+ if (serviceUses?.[1] && serviceUses?.[2]) {
245
+ const subject = this.normalizeEntity(serviceUses[1]);
246
+ const target = this.normalizeEntity(serviceUses[2]);
247
+ if (subject && target) {
248
+ matches.push({
249
+ projectId: base.projectId,
250
+ scope: base.scope,
251
+ subject: 'user',
252
+ predicate: `fact.service.${subject}.backend`,
253
+ objectValue: {
254
+ raw: target,
255
+ normalized: target,
256
+ type: 'string'
257
+ },
258
+ confidence: 0.84,
259
+ sourceNeuronId: base.neuronId,
260
+ sourceEventId: base.sourceEventId,
261
+ sourceType: base.sourceType,
262
+ validityKind: temporal.kind,
263
+ validFrom: temporal.validFrom,
264
+ validTo: temporal.validTo,
265
+ explanation: content,
266
+ metadata: {
267
+ extractorRule: 'fact_service_backend',
268
+ slots: {
269
+ entityType: 'service',
270
+ subject,
271
+ relation: 'backend',
272
+ target
273
+ },
274
+ ...(temporal.dsl ? { temporalDsl: temporal.dsl } : {})
275
+ },
276
+ extractionReason: 'tool_verified_fact'
277
+ });
278
+ }
279
+ }
280
+ const portBinding = content.match(/(?:service|module|服务|模块)\s*([\w\-./]+)\s*(?:runs on port|port|运行在端口)\s*(\d{2,5})/i);
281
+ if (portBinding?.[1] && portBinding?.[2]) {
282
+ const subject = this.normalizeEntity(portBinding[1]);
283
+ const port = portBinding[2];
284
+ if (subject) {
285
+ matches.push({
286
+ projectId: base.projectId,
287
+ scope: base.scope,
288
+ subject: 'user',
289
+ predicate: `fact.entity.${subject}.port`,
290
+ objectValue: {
291
+ raw: port,
292
+ normalized: port,
293
+ type: 'number'
294
+ },
295
+ confidence: 0.86,
296
+ sourceNeuronId: base.neuronId,
297
+ sourceEventId: base.sourceEventId,
298
+ sourceType: base.sourceType,
299
+ validityKind: temporal.kind,
300
+ validFrom: temporal.validFrom,
301
+ validTo: temporal.validTo,
302
+ explanation: content,
303
+ metadata: {
304
+ extractorRule: 'fact_entity_port',
305
+ slots: {
306
+ subject,
307
+ property: 'port',
308
+ value: Number(port)
309
+ },
310
+ ...(temporal.dsl ? { temporalDsl: temporal.dsl } : {})
311
+ },
312
+ extractionReason: 'tool_verified_fact'
313
+ });
314
+ }
315
+ }
316
+ return matches;
317
+ }
318
+ extractProceduralSequences(content, base) {
319
+ const steps = this.parseSequenceSteps(content);
320
+ if (steps.length < 2)
321
+ return [];
322
+ const temporal = this.extractTemporalWindow(content, base.createdAt);
323
+ return [{
324
+ projectId: base.projectId,
325
+ scope: base.scope,
326
+ subject: 'user',
327
+ predicate: 'workflow.sequence.primary',
328
+ objectValue: {
329
+ raw: JSON.stringify(steps),
330
+ normalized: steps.join(' > '),
331
+ json: steps,
332
+ type: 'json'
333
+ },
334
+ confidence: 0.8,
335
+ sourceNeuronId: base.neuronId,
336
+ sourceEventId: base.sourceEventId,
337
+ sourceType: base.sourceType,
338
+ validityKind: temporal.kind,
339
+ validFrom: temporal.validFrom,
340
+ validTo: temporal.validTo,
341
+ explanation: content,
342
+ metadata: {
343
+ extractorRule: 'workflow_sequence',
344
+ sequenceDsl: {
345
+ version: 1,
346
+ type: 'ordered_steps',
347
+ steps
348
+ },
349
+ ...(temporal.dsl ? { temporalDsl: temporal.dsl } : {})
350
+ },
351
+ extractionReason: 'workflow_rule'
352
+ }];
353
+ }
354
+ extractExecutablePlanGraphs(content, base) {
355
+ const plan = this.parseExecutablePlanGraph(content);
356
+ if (!plan)
357
+ return [];
358
+ const temporal = this.extractTemporalWindow(content, base.createdAt);
359
+ return [{
360
+ projectId: base.projectId,
361
+ scope: base.scope,
362
+ subject: 'user',
363
+ predicate: 'workflow.plan.primary',
364
+ objectValue: {
365
+ raw: JSON.stringify(plan),
366
+ normalized: plan.nodes.join(' -> '),
367
+ json: plan,
368
+ type: 'json'
369
+ },
370
+ confidence: 0.84,
371
+ sourceNeuronId: base.neuronId,
372
+ sourceEventId: base.sourceEventId,
373
+ sourceType: base.sourceType,
374
+ validityKind: temporal.kind,
375
+ validFrom: temporal.validFrom,
376
+ validTo: temporal.validTo,
377
+ explanation: content,
378
+ metadata: {
379
+ extractorRule: 'workflow_plan_primary',
380
+ planDsl: {
381
+ version: 1,
382
+ type: 'executable_plan_graph',
383
+ entrySteps: plan.entrySteps,
384
+ nodes: plan.nodes,
385
+ edges: plan.edges,
386
+ handlers: plan.handlers,
387
+ retryPolicies: plan.retryPolicies,
388
+ mergePoints: plan.mergePoints,
389
+ branchPoints: plan.branchPoints,
390
+ stateTransitions: plan.stateTransitions,
391
+ policyExecutors: plan.policyExecutors,
392
+ executionGuards: plan.executionGuards,
393
+ stateMachines: plan.stateMachines,
394
+ policyRuntime: plan.policyRuntime,
395
+ mergeConstraints: plan.mergeConstraints,
396
+ runtimeValidation: plan.runtimeValidation,
397
+ executorBindings: plan.executorBindings,
398
+ mergePropagation: plan.mergePropagation
399
+ },
400
+ ...(temporal.dsl ? { temporalDsl: temporal.dsl } : {})
401
+ },
402
+ extractionReason: 'workflow_rule'
403
+ }];
404
+ }
405
+ extractNestedFactGraphs(content, base) {
406
+ const graph = this.parseNestedFactGraph(content);
407
+ if (!graph)
408
+ return [];
409
+ const temporal = this.extractTemporalWindow(content, base.createdAt);
410
+ return [{
411
+ projectId: base.projectId,
412
+ scope: base.scope,
413
+ subject: 'user',
414
+ predicate: 'fact.graph.primary',
415
+ objectValue: {
416
+ raw: JSON.stringify(graph),
417
+ normalized: graph.path.join(' -> '),
418
+ json: graph,
419
+ type: 'json'
420
+ },
421
+ confidence: 0.82,
422
+ sourceNeuronId: base.neuronId,
423
+ sourceEventId: base.sourceEventId,
424
+ sourceType: base.sourceType,
425
+ validityKind: temporal.kind,
426
+ validFrom: temporal.validFrom,
427
+ validTo: temporal.validTo,
428
+ explanation: content,
429
+ metadata: {
430
+ extractorRule: 'fact_graph_primary',
431
+ graphDsl: {
432
+ version: 1,
433
+ type: 'path_graph',
434
+ nodes: graph.nodes,
435
+ edges: graph.edges
436
+ },
437
+ ...(temporal.dsl ? { temporalDsl: temporal.dsl } : {})
438
+ },
439
+ extractionReason: 'tool_verified_fact'
440
+ }];
441
+ }
442
+ extractTemporalWindow(content, now) {
443
+ const startOfToday = new Date(now);
444
+ startOfToday.setHours(0, 0, 0, 0);
445
+ const dayStart = startOfToday.getTime();
446
+ if (/(今天|today)/i.test(content)) {
447
+ return {
448
+ kind: 'time_range',
449
+ validFrom: dayStart,
450
+ validTo: dayStart + 86400000,
451
+ dsl: {
452
+ version: 1,
453
+ type: 'relative_range',
454
+ unit: 'day',
455
+ relation: 'current'
456
+ }
457
+ };
458
+ }
459
+ if (/(本周|this week)/i.test(content)) {
460
+ const date = new Date(now);
461
+ const day = date.getDay() || 7;
462
+ date.setHours(0, 0, 0, 0);
463
+ date.setDate(date.getDate() - (day - 1));
464
+ const start = date.getTime();
465
+ return {
466
+ kind: 'time_range',
467
+ validFrom: start,
468
+ validTo: start + 7 * 86400000,
469
+ dsl: {
470
+ version: 1,
471
+ type: 'relative_range',
472
+ unit: 'week',
473
+ relation: 'current'
474
+ }
475
+ };
476
+ }
477
+ if (/(这个月|this month)/i.test(content)) {
478
+ const date = new Date(now);
479
+ date.setHours(0, 0, 0, 0);
480
+ date.setDate(1);
481
+ const start = date.getTime();
482
+ const end = new Date(date.getFullYear(), date.getMonth() + 1, 1).getTime();
483
+ return {
484
+ kind: 'time_range',
485
+ validFrom: start,
486
+ validTo: end,
487
+ dsl: {
488
+ version: 1,
489
+ type: 'relative_range',
490
+ unit: 'month',
491
+ relation: 'current'
492
+ }
493
+ };
494
+ }
495
+ return { validFrom: now };
496
+ }
497
+ extractCondition(content) {
498
+ const cnIf = content.match(/如果(.+?)[,,]\s*(?:就|则)/i);
499
+ if (cnIf?.[1]) {
500
+ const raw = cnIf[1].trim();
501
+ return {
502
+ raw,
503
+ dsl: this.buildConditionDsl(raw, 'zh')
504
+ };
505
+ }
506
+ const enIf = content.match(/if\s+(.+?)[,,]\s*(?:then\s+)?/i);
507
+ if (enIf?.[1]) {
508
+ const raw = enIf[1].trim();
509
+ return {
510
+ raw,
511
+ dsl: this.buildConditionDsl(raw, 'en')
512
+ };
513
+ }
514
+ const inProject = content.match(/在\s*([\w\-./]+)\s*项目里/i);
515
+ if (inProject?.[1]) {
516
+ const projectHint = inProject[1].trim().toLowerCase();
517
+ return {
518
+ raw: `在 ${projectHint} 项目里`,
519
+ dsl: {
520
+ version: 1,
521
+ op: 'when',
522
+ combinator: 'all',
523
+ clauses: [{ kind: 'project_hint', operator: 'eq', value: projectHint }]
524
+ }
525
+ };
526
+ }
527
+ return undefined;
528
+ }
529
+ resolveValidityKind(temporalKind, conditionalKind) {
530
+ if (conditionalKind)
531
+ return conditionalKind;
532
+ return temporalKind;
533
+ }
534
+ getBaseContext(neuron, sourceEventId, content) {
535
+ return {
536
+ neuronId: neuron.id,
537
+ projectId: neuron.metadata.projectId,
538
+ scope: neuron.metadata.projectId ? 'project' : 'global',
539
+ sourceType: neuron.metadata.sourceType || 'user_input',
540
+ sourceEventId,
541
+ createdAt: neuron.metadata.createdAt,
542
+ content
543
+ };
544
+ }
545
+ normalizeEntity(raw) {
546
+ const entity = raw.trim().toLowerCase().replace(/^[\s"'`]+|[\s"'`?!.。,!?]+$/g, '');
547
+ return entity.length >= 2 ? entity : null;
548
+ }
549
+ normalizeFactValue(raw) {
550
+ const value = raw.trim().replace(/^[\s"'`]+|[\s"'`。!?,,]+$/g, '');
551
+ return value.length >= 2 ? value : null;
552
+ }
553
+ parseSequenceSteps(content) {
554
+ const cleaned = content.replace(/^(?:plan|计划|workflow|流程)\s*[::]\s*/i, '').trim();
555
+ if (/先|再/.test(cleaned)) {
556
+ const normalized = cleaned.replace(/然后|接着/g, '再');
557
+ const parts = normalized
558
+ .split(/先|再/)
559
+ .map((step) => step.trim())
560
+ .filter((step) => step.length > 0)
561
+ .map((step) => step.split(/[\s,,。]+/)[0].toLowerCase());
562
+ if (parts.length >= 2)
563
+ return parts;
564
+ }
565
+ if (/first|then|->/i.test(cleaned)) {
566
+ const normalized = cleaned
567
+ .replace(/first/gi, '')
568
+ .replace(/then/gi, '->');
569
+ const parts = normalized
570
+ .split(/->/)
571
+ .map((step) => step.trim())
572
+ .filter((step) => step.length > 0)
573
+ .map((step) => step.split(/[\s,,。]+/)[0].toLowerCase());
574
+ if (parts.length >= 2)
575
+ return parts;
576
+ }
577
+ return [];
578
+ }
579
+ buildConditionDsl(raw, lang) {
580
+ const normalized = raw.replace(/\s+/g, ' ').trim();
581
+ const expr = this.parseConditionExpression(normalized, lang);
582
+ const clauses = this.flattenConditionClauses(expr);
583
+ return {
584
+ version: 2,
585
+ op: 'when',
586
+ combinator: expr.kind === 'group' ? expr.combinator : 'single',
587
+ clauses,
588
+ expr
589
+ };
590
+ }
591
+ toConditionClause(part, lang) {
592
+ if (lang === 'zh') {
593
+ const negativeProject = part.match(/不是\s*([\w\u4e00-\u9fa5\-./]+)\s*环境/i);
594
+ if (negativeProject?.[1]) {
595
+ return { kind: 'environment', operator: 'neq', value: negativeProject[1].toLowerCase() };
596
+ }
597
+ const project = part.match(/(?:是)?\s*([\w\u4e00-\u9fa5\-./]+)\s*项目/i);
598
+ if (project?.[1]) {
599
+ return { kind: 'project_hint', operator: 'eq', value: project[1].toLowerCase() };
600
+ }
601
+ const positiveEnv = part.match(/(?:是|在)?\s*([\w\u4e00-\u9fa5\-./]+)\s*环境/i);
602
+ if (positiveEnv?.[1]) {
603
+ return { kind: 'environment', operator: 'eq', value: positiveEnv[1].toLowerCase() };
604
+ }
605
+ const state = part.match(/([\w\u4e00-\u9fa5\-./]+)\s*状态/i);
606
+ if (state?.[1]) {
607
+ return { kind: 'state', operator: 'eq', value: state[1].toLowerCase() };
608
+ }
609
+ if (/已批准|审批通过|approved|approval/i.test(part)) {
610
+ return { kind: 'approval', operator: 'eq', value: 'approved' };
611
+ }
612
+ const policy = part.match(/([\w\u4e00-\u9fa5\-./]+)\s*策略/i);
613
+ if (policy?.[1]) {
614
+ return { kind: 'policy_hint', operator: 'eq', value: policy[1].toLowerCase() };
615
+ }
616
+ }
617
+ else {
618
+ const negativeEnv = part.match(/not\s+([\w\-./]+)\s+env/i);
619
+ if (negativeEnv?.[1]) {
620
+ return { kind: 'environment', operator: 'neq', value: negativeEnv[1].toLowerCase() };
621
+ }
622
+ const project = part.match(/([\w\-./]+)\s+project/i);
623
+ if (project?.[1]) {
624
+ return { kind: 'project_hint', operator: 'eq', value: project[1].toLowerCase() };
625
+ }
626
+ const positiveEnv = part.match(/([\w\-./]+)\s+env/i);
627
+ if (positiveEnv?.[1]) {
628
+ return { kind: 'environment', operator: 'eq', value: positiveEnv[1].toLowerCase() };
629
+ }
630
+ const state = part.match(/([\w\-./]+)\s+state/i);
631
+ if (state?.[1]) {
632
+ return { kind: 'state', operator: 'eq', value: state[1].toLowerCase() };
633
+ }
634
+ if (/approved|approval/i.test(part)) {
635
+ return { kind: 'approval', operator: 'eq', value: 'approved' };
636
+ }
637
+ const policy = part.match(/([\w\-./]+)\s+policy/i);
638
+ if (policy?.[1]) {
639
+ return { kind: 'policy_hint', operator: 'eq', value: policy[1].toLowerCase() };
640
+ }
641
+ }
642
+ return { kind: 'raw_text', operator: 'eq', value: part };
643
+ }
644
+ parseConditionExpression(raw, lang) {
645
+ const normalized = this.stripOuterParentheses(this.normalizeConditionOperators(raw, lang));
646
+ const orParts = this.splitTopLevelByOperators(normalized, lang === 'zh' ? ['或者', '或'] : ['or']);
647
+ if (orParts.length > 1) {
648
+ return {
649
+ kind: 'group',
650
+ combinator: 'any',
651
+ clauses: orParts.map((part) => this.parseConditionExpression(part, lang))
652
+ };
653
+ }
654
+ const andParts = this.splitTopLevelByOperators(normalized, lang === 'zh' ? ['并且', '而且', '且', '和'] : ['and']);
655
+ if (andParts.length > 1) {
656
+ return {
657
+ kind: 'group',
658
+ combinator: 'all',
659
+ clauses: andParts.map((part) => this.parseConditionExpression(part, lang))
660
+ };
661
+ }
662
+ return this.toConditionClause(normalized, lang);
663
+ }
664
+ flattenConditionClauses(expr) {
665
+ const kind = String(expr.kind || '');
666
+ if (kind !== 'group')
667
+ return [expr];
668
+ const clauses = Array.isArray(expr.clauses) ? expr.clauses : [];
669
+ return clauses.flatMap((clause) => this.flattenConditionClauses(clause));
670
+ }
671
+ normalizeConditionOperators(raw, lang) {
672
+ const normalized = raw
673
+ .replace(/[(【]/g, '(')
674
+ .replace(/[)】]/g, ')')
675
+ .replace(/\s+/g, ' ')
676
+ .trim();
677
+ if (lang === 'zh') {
678
+ return normalized
679
+ .replace(/并且|而且|以及/g, '且')
680
+ .replace(/或者/g, '或');
681
+ }
682
+ return normalized
683
+ .replace(/\&\&/g, ' and ')
684
+ .replace(/\|\|/g, ' or ');
685
+ }
686
+ stripOuterParentheses(raw) {
687
+ let text = raw.trim();
688
+ while (text.startsWith('(') && text.endsWith(')') && this.isBalancedParentheses(text.slice(1, -1))) {
689
+ text = text.slice(1, -1).trim();
690
+ }
691
+ return text;
692
+ }
693
+ isBalancedParentheses(raw) {
694
+ let depth = 0;
695
+ for (const ch of raw) {
696
+ if (ch === '(')
697
+ depth += 1;
698
+ if (ch === ')') {
699
+ depth -= 1;
700
+ if (depth < 0)
701
+ return false;
702
+ }
703
+ }
704
+ return depth === 0;
705
+ }
706
+ splitTopLevelByOperators(raw, operators) {
707
+ const parts = [];
708
+ let buffer = '';
709
+ let depth = 0;
710
+ let index = 0;
711
+ while (index < raw.length) {
712
+ const ch = raw[index];
713
+ if (ch === '(') {
714
+ depth += 1;
715
+ buffer += ch;
716
+ index += 1;
717
+ continue;
718
+ }
719
+ if (ch === ')') {
720
+ depth -= 1;
721
+ buffer += ch;
722
+ index += 1;
723
+ continue;
724
+ }
725
+ if (depth === 0) {
726
+ const matched = operators.find((operator) => raw.slice(index, index + operator.length).toLowerCase() === operator.toLowerCase());
727
+ if (matched) {
728
+ if (buffer.trim())
729
+ parts.push(buffer.trim());
730
+ buffer = '';
731
+ index += matched.length;
732
+ continue;
733
+ }
734
+ }
735
+ buffer += ch;
736
+ index += 1;
737
+ }
738
+ if (buffer.trim())
739
+ parts.push(buffer.trim());
740
+ return parts.length > 0 ? parts : [raw];
741
+ }
742
+ parseNestedFactGraph(content) {
743
+ const graphMatch = content.match(/(?:graph|architecture|架构)\s*[::]\s*([^\n]+)/i);
744
+ const candidate = graphMatch?.[1] || (/->/.test(content) ? content : '');
745
+ if (!candidate)
746
+ return null;
747
+ const path = candidate
748
+ .split(/->|→/)
749
+ .map((part) => part.trim().toLowerCase())
750
+ .filter((part) => /^[\w\-./]+$/.test(part));
751
+ if (path.length < 3)
752
+ return null;
753
+ const edges = path.slice(0, -1).map((from, index) => ({
754
+ from,
755
+ to: path[index + 1]
756
+ }));
757
+ return {
758
+ path,
759
+ nodes: Array.from(new Set(path)),
760
+ edges
761
+ };
762
+ }
763
+ parseExecutablePlanGraph(content) {
764
+ if (!/(plan|计划|rollback|recover|recovery|redeploy|retry|失败)/i.test(content))
765
+ return null;
766
+ const baseSegment = content.split(/如果|if\s+/i)[0]?.trim() || content;
767
+ const entrySteps = this.parseSequenceSteps(baseSegment);
768
+ const handlers = this.parsePlanHandlers(content);
769
+ const retryPolicies = this.parseRetryPolicies(content);
770
+ const mergePoints = this.parseMergePoints(content);
771
+ const branchPoints = this.parseBranchPoints(content);
772
+ const stateTransitions = this.parseStateTransitions(content);
773
+ const policyExecutors = this.parsePolicyExecutors(content);
774
+ const executionGuards = this.parseExecutionGuards(content);
775
+ const stateMachines = this.parseStateMachines(content);
776
+ const policyRuntime = this.parsePolicyRuntime(content);
777
+ const mergeConstraints = this.parseMergeConstraints(content);
778
+ const runtimeValidation = this.parseRuntimeValidation(content);
779
+ const executorBindings = this.parseExecutorBindings(content);
780
+ const mergePropagation = this.parseMergePropagation(content);
781
+ if (entrySteps.length < 2 && handlers.length === 0 && retryPolicies.length === 0 && mergePoints.length === 0 && branchPoints.length === 0 && stateTransitions.length === 0 && policyExecutors.length === 0 && executionGuards.length === 0 && stateMachines.length === 0 && policyRuntime.length === 0 && mergeConstraints.length === 0 && runtimeValidation.length === 0 && executorBindings.length === 0 && mergePropagation.length === 0)
782
+ return null;
783
+ const nodes = new Set(entrySteps);
784
+ const edges = [];
785
+ for (let i = 0; i < entrySteps.length - 1; i++) {
786
+ edges.push({ from: entrySteps[i], to: entrySteps[i + 1], kind: 'dependency' });
787
+ }
788
+ for (const handler of handlers) {
789
+ nodes.add(handler.trigger);
790
+ for (const step of handler.steps)
791
+ nodes.add(step);
792
+ if (handler.steps[0]) {
793
+ edges.push({ from: handler.trigger, to: handler.steps[0], kind: 'failure' });
794
+ }
795
+ for (let i = 0; i < handler.steps.length - 1; i++) {
796
+ edges.push({ from: handler.steps[i], to: handler.steps[i + 1], kind: 'recovery' });
797
+ }
798
+ }
799
+ for (const policy of retryPolicies) {
800
+ nodes.add(policy.target);
801
+ edges.push({ from: policy.target, to: policy.target, kind: 'retry' });
802
+ }
803
+ for (const mergePoint of mergePoints) {
804
+ nodes.add(mergePoint.into);
805
+ for (const branch of mergePoint.branches) {
806
+ nodes.add(branch);
807
+ edges.push({ from: branch, to: mergePoint.into, kind: 'merge' });
808
+ }
809
+ }
810
+ for (const branchPoint of branchPoints) {
811
+ nodes.add(branchPoint.from);
812
+ for (const branch of branchPoint.branches) {
813
+ nodes.add(branch);
814
+ edges.push({ from: branchPoint.from, to: branch, kind: 'branch' });
815
+ }
816
+ }
817
+ for (const transition of stateTransitions) {
818
+ nodes.add(transition.entity);
819
+ nodes.add(transition.from);
820
+ nodes.add(transition.to);
821
+ edges.push({ from: transition.from, to: transition.to, kind: 'state_transition' });
822
+ }
823
+ for (const executor of policyExecutors) {
824
+ nodes.add(executor.target);
825
+ }
826
+ for (const guard of executionGuards) {
827
+ nodes.add(guard.target);
828
+ for (const requirement of guard.requires)
829
+ nodes.add(requirement);
830
+ }
831
+ for (const machine of stateMachines) {
832
+ nodes.add(machine.entity);
833
+ for (const state of machine.states)
834
+ nodes.add(state);
835
+ }
836
+ for (const runtime of policyRuntime) {
837
+ nodes.add(runtime.target);
838
+ nodes.add(runtime.policy);
839
+ }
840
+ for (const constraint of mergeConstraints) {
841
+ nodes.add(constraint.into);
842
+ for (const requirement of constraint.requires)
843
+ nodes.add(requirement);
844
+ }
845
+ for (const validation of runtimeValidation) {
846
+ nodes.add(validation.target);
847
+ for (const check of validation.checks)
848
+ nodes.add(check);
849
+ }
850
+ for (const binding of executorBindings) {
851
+ nodes.add(binding.target);
852
+ nodes.add(binding.executor);
853
+ }
854
+ for (const propagation of mergePropagation) {
855
+ nodes.add(propagation.into);
856
+ for (const item of propagation.propagates)
857
+ nodes.add(item);
858
+ }
859
+ if (edges.length === 0)
860
+ return null;
861
+ return {
862
+ entrySteps,
863
+ nodes: Array.from(nodes),
864
+ edges,
865
+ handlers,
866
+ retryPolicies,
867
+ mergePoints,
868
+ branchPoints,
869
+ stateTransitions,
870
+ policyExecutors,
871
+ executionGuards,
872
+ stateMachines,
873
+ policyRuntime,
874
+ mergeConstraints,
875
+ runtimeValidation,
876
+ executorBindings,
877
+ mergePropagation
878
+ };
879
+ }
880
+ parsePlanHandlers(content) {
881
+ const handlers = [];
882
+ const cnPattern = /([\w\-./]+)\s*失败(?:了)?\s*(?:就|则|后)?\s*([^\n,。,;;]+)/gi;
883
+ let match;
884
+ while ((match = cnPattern.exec(content)) !== null) {
885
+ const trigger = this.normalizeEntity(match[1] || '');
886
+ const steps = this.parseHandlerSteps(match[2] || '');
887
+ if (trigger && steps.length > 0)
888
+ handlers.push({ trigger, on: 'failure', steps });
889
+ }
890
+ const enPattern = /if\s+([\w\-./]+)\s+fail(?:s)?\s+(?:then\s+)?([^\n,.;]+)/gi;
891
+ while ((match = enPattern.exec(content)) !== null) {
892
+ const trigger = this.normalizeEntity(match[1] || '');
893
+ const steps = this.parseHandlerSteps(match[2] || '');
894
+ if (trigger && steps.length > 0)
895
+ handlers.push({ trigger, on: 'failure', steps });
896
+ }
897
+ return handlers;
898
+ }
899
+ parseHandlerSteps(raw) {
900
+ const direct = this.parseSequenceSteps(raw);
901
+ if (direct.length >= 1)
902
+ return direct;
903
+ return raw
904
+ .replace(/然后|接着/gi, '->')
905
+ .replace(/\band\b/gi, '->')
906
+ .split(/->|再|,/)
907
+ .map((step) => step.trim().toLowerCase())
908
+ .filter((step) => /^[\w\-./]+$/.test(step));
909
+ }
910
+ parseRetryPolicies(content) {
911
+ const policies = [];
912
+ let match;
913
+ const enPattern = /retry\s+([\w\-./]+)\s+(\d+)\s+times(?:\s+with\s+backoff\s+([\w\-./]+))?/gi;
914
+ while ((match = enPattern.exec(content)) !== null) {
915
+ const target = this.normalizeEntity(match[1] || '');
916
+ const maxAttempts = Number(match[2] || 0);
917
+ const backoff = match[3]?.toLowerCase();
918
+ if (target && maxAttempts > 0)
919
+ policies.push({ target, maxAttempts, backoff });
920
+ }
921
+ const cnPattern = /重试\s*([\w\-./]+)\s*(\d+)\s*次(?:.*?退避\s*([\w\-./]+))?/gi;
922
+ while ((match = cnPattern.exec(content)) !== null) {
923
+ const target = this.normalizeEntity(match[1] || '');
924
+ const maxAttempts = Number(match[2] || 0);
925
+ const backoff = match[3]?.toLowerCase();
926
+ if (target && maxAttempts > 0)
927
+ policies.push({ target, maxAttempts, backoff });
928
+ }
929
+ return policies;
930
+ }
931
+ parseMergePoints(content) {
932
+ const mergePoints = [];
933
+ let match;
934
+ const enPattern = /merge\s+([\w\-./]+)\s+and\s+([\w\-./]+)\s+(?:before|into)\s+([\w\-./]+)/gi;
935
+ while ((match = enPattern.exec(content)) !== null) {
936
+ const left = this.normalizeEntity(match[1] || '');
937
+ const right = this.normalizeEntity(match[2] || '');
938
+ const into = this.normalizeEntity(match[3] || '');
939
+ if (left && right && into)
940
+ mergePoints.push({ into, branches: [left, right] });
941
+ }
942
+ const cnPattern = /合并\s*([\w\-./]+)\s*和\s*([\w\-./]+)\s*(?:后进入|到|再到)\s*([\w\-./]+)/gi;
943
+ while ((match = cnPattern.exec(content)) !== null) {
944
+ const left = this.normalizeEntity(match[1] || '');
945
+ const right = this.normalizeEntity(match[2] || '');
946
+ const into = this.normalizeEntity(match[3] || '');
947
+ if (left && right && into)
948
+ mergePoints.push({ into, branches: [left, right] });
949
+ }
950
+ return mergePoints;
951
+ }
952
+ parseBranchPoints(content) {
953
+ const branchPoints = [];
954
+ let match;
955
+ const enPattern = /after\s+([\w\-./]+)\s+branch\s+to\s+([\w\-./]+)\s+and\s+([\w\-./]+)/gi;
956
+ while ((match = enPattern.exec(content)) !== null) {
957
+ const from = this.normalizeEntity(match[1] || '');
958
+ const left = this.normalizeEntity(match[2] || '');
959
+ const right = this.normalizeEntity(match[3] || '');
960
+ if (from && left && right)
961
+ branchPoints.push({ from, branches: [left, right] });
962
+ }
963
+ const cnPattern = /([\w\-./]+)\s*后分支到\s*([\w\-./]+)\s*和\s*([\w\-./]+)/gi;
964
+ while ((match = cnPattern.exec(content)) !== null) {
965
+ const from = this.normalizeEntity(match[1] || '');
966
+ const left = this.normalizeEntity(match[2] || '');
967
+ const right = this.normalizeEntity(match[3] || '');
968
+ if (from && left && right)
969
+ branchPoints.push({ from, branches: [left, right] });
970
+ }
971
+ return branchPoints;
972
+ }
973
+ parseStateTransitions(content) {
974
+ const transitions = [];
975
+ let match;
976
+ const enPattern = /([\w\-./]+)\s+state\s+([\w\-./]+)\s*->\s*([\w\-./]+)/gi;
977
+ while ((match = enPattern.exec(content)) !== null) {
978
+ const entity = this.normalizeEntity(match[1] || '');
979
+ const from = this.normalizeEntity(match[2] || '');
980
+ const to = this.normalizeEntity(match[3] || '');
981
+ if (entity && from && to)
982
+ transitions.push({ entity, from, to });
983
+ }
984
+ const cnPattern = /([\w\-./]+)\s*状态\s*([\w\-./]+)\s*->\s*([\w\-./]+)/gi;
985
+ while ((match = cnPattern.exec(content)) !== null) {
986
+ const entity = this.normalizeEntity(match[1] || '');
987
+ const from = this.normalizeEntity(match[2] || '');
988
+ const to = this.normalizeEntity(match[3] || '');
989
+ if (entity && from && to)
990
+ transitions.push({ entity, from, to });
991
+ }
992
+ return transitions;
993
+ }
994
+ parsePolicyExecutors(content) {
995
+ const executors = [];
996
+ let match;
997
+ const enPattern = /use\s+([\w\-./]+)\s+policy\s+for\s+([\w\-./]+)(?:\s+with\s+([\w\-./]+))?/gi;
998
+ while ((match = enPattern.exec(content)) !== null) {
999
+ const policy = this.normalizeEntity(match[1] || '');
1000
+ const target = this.normalizeEntity(match[2] || '');
1001
+ const config = match[3]?.toLowerCase();
1002
+ if (policy && target)
1003
+ executors.push({ policy, target, config });
1004
+ }
1005
+ const cnPattern = /对\s*([\w\-./]+)\s*使用\s*([\w\-./]+)\s*策略(?:\s*配置\s*([\w\-./]+))?/gi;
1006
+ while ((match = cnPattern.exec(content)) !== null) {
1007
+ const target = this.normalizeEntity(match[1] || '');
1008
+ const policy = this.normalizeEntity(match[2] || '');
1009
+ const config = match[3]?.toLowerCase();
1010
+ if (policy && target)
1011
+ executors.push({ policy, target, config });
1012
+ }
1013
+ return executors;
1014
+ }
1015
+ parseExecutionGuards(content) {
1016
+ const guards = [];
1017
+ let match;
1018
+ const enPattern = /([\w\-./]+)\s+only if\s+([\w\-./]+)\s+passes/gi;
1019
+ while ((match = enPattern.exec(content)) !== null) {
1020
+ const target = this.normalizeEntity(match[1] || '');
1021
+ const requirement = this.normalizeEntity(match[2] || '');
1022
+ if (target && requirement)
1023
+ guards.push({ target, requires: [requirement] });
1024
+ }
1025
+ const guardPattern = /guard\s+([\w\-./]+)\s+requires\s+([\w\-./]+)/gi;
1026
+ while ((match = guardPattern.exec(content)) !== null) {
1027
+ const target = this.normalizeEntity(match[1] || '');
1028
+ const requirement = this.normalizeEntity(match[2] || '');
1029
+ if (target && requirement)
1030
+ guards.push({ target, requires: [requirement] });
1031
+ }
1032
+ const cnPattern = /([\w\-./]+)\s*只有\s*([\w\-./]+)\s*才能执行/gi;
1033
+ while ((match = cnPattern.exec(content)) !== null) {
1034
+ const target = this.normalizeEntity(match[1] || '');
1035
+ const requirement = this.normalizeEntity(match[2] || '');
1036
+ if (target && requirement)
1037
+ guards.push({ target, requires: [requirement] });
1038
+ }
1039
+ return guards;
1040
+ }
1041
+ parseStateMachines(content) {
1042
+ const machines = [];
1043
+ let match;
1044
+ const enPattern = /([\w\-./]+)\s+state\s+([\w\-./\s>,-]+(?:->\s*[\w\-./]+)+)/gi;
1045
+ while ((match = enPattern.exec(content)) !== null) {
1046
+ const entity = this.normalizeEntity(match[1] || '');
1047
+ const states = (match[2] || '')
1048
+ .split(/->/)
1049
+ .map((item) => this.normalizeEntity(item || ''))
1050
+ .filter((item) => Boolean(item));
1051
+ if (entity && states.length >= 2)
1052
+ machines.push({ entity, states });
1053
+ }
1054
+ const cnPattern = /([\w\-./]+)\s*状态机\s*([\w\-./\s>,-]+(?:->\s*[\w\-./]+)+)/gi;
1055
+ while ((match = cnPattern.exec(content)) !== null) {
1056
+ const entity = this.normalizeEntity(match[1] || '');
1057
+ const states = (match[2] || '')
1058
+ .split(/->/)
1059
+ .map((item) => this.normalizeEntity(item || ''))
1060
+ .filter((item) => Boolean(item));
1061
+ if (entity && states.length >= 2)
1062
+ machines.push({ entity, states });
1063
+ }
1064
+ return machines;
1065
+ }
1066
+ parsePolicyRuntime(content) {
1067
+ const runtimes = [];
1068
+ let match;
1069
+ const enPattern = /policy runtime\s+([\w\-./]+)\s+mode\s+([\w\-./]+)\s+for\s+([\w\-./]+)/gi;
1070
+ while ((match = enPattern.exec(content)) !== null) {
1071
+ const policy = this.normalizeEntity(match[1] || '');
1072
+ const mode = this.normalizeEntity(match[2] || '');
1073
+ const target = this.normalizeEntity(match[3] || '');
1074
+ if (policy && target)
1075
+ runtimes.push({ policy, mode: mode || undefined, target });
1076
+ }
1077
+ const cnPattern = /([\w\-./]+)\s*策略运行时\s*模式\s*([\w\-./]+)\s*作用于\s*([\w\-./]+)/gi;
1078
+ while ((match = cnPattern.exec(content)) !== null) {
1079
+ const policy = this.normalizeEntity(match[1] || '');
1080
+ const mode = this.normalizeEntity(match[2] || '');
1081
+ const target = this.normalizeEntity(match[3] || '');
1082
+ if (policy && target)
1083
+ runtimes.push({ policy, mode: mode || undefined, target });
1084
+ }
1085
+ return runtimes;
1086
+ }
1087
+ parseMergeConstraints(content) {
1088
+ const constraints = [];
1089
+ let match;
1090
+ const enPattern = /merge\s+into\s+([\w\-./]+)\s+requires\s+([\w\-./]+)\s+and\s+([\w\-./]+)/gi;
1091
+ while ((match = enPattern.exec(content)) !== null) {
1092
+ const into = this.normalizeEntity(match[1] || '');
1093
+ const left = this.normalizeEntity(match[2] || '');
1094
+ const right = this.normalizeEntity(match[3] || '');
1095
+ if (into && left && right)
1096
+ constraints.push({ into, requires: [left, right] });
1097
+ }
1098
+ const cnPattern = /合并到\s*([\w\-./]+)\s*需要\s*([\w\-./]+)\s*和\s*([\w\-./]+)/gi;
1099
+ while ((match = cnPattern.exec(content)) !== null) {
1100
+ const into = this.normalizeEntity(match[1] || '');
1101
+ const left = this.normalizeEntity(match[2] || '');
1102
+ const right = this.normalizeEntity(match[3] || '');
1103
+ if (into && left && right)
1104
+ constraints.push({ into, requires: [left, right] });
1105
+ }
1106
+ return constraints;
1107
+ }
1108
+ parseRuntimeValidation(content) {
1109
+ const validations = [];
1110
+ let match;
1111
+ const enPattern = /validate\s+([\w\-./]+)\s+with\s+([\w\-./]+)\s+and\s+([\w\-./]+)/gi;
1112
+ while ((match = enPattern.exec(content)) !== null) {
1113
+ const target = this.normalizeEntity(match[1] || '');
1114
+ const left = this.normalizeEntity(match[2] || '');
1115
+ const right = this.normalizeEntity(match[3] || '');
1116
+ if (target && left && right)
1117
+ validations.push({ target, checks: [left, right] });
1118
+ }
1119
+ const cnPattern = /校验\s*([\w\-./]+)\s*使用\s*([\w\-./]+)\s*和\s*([\w\-./]+)/gi;
1120
+ while ((match = cnPattern.exec(content)) !== null) {
1121
+ const target = this.normalizeEntity(match[1] || '');
1122
+ const left = this.normalizeEntity(match[2] || '');
1123
+ const right = this.normalizeEntity(match[3] || '');
1124
+ if (target && left && right)
1125
+ validations.push({ target, checks: [left, right] });
1126
+ }
1127
+ return validations;
1128
+ }
1129
+ parseExecutorBindings(content) {
1130
+ const bindings = [];
1131
+ let match;
1132
+ const enPattern = /execute\s+([\w\-./]+)\s+with\s+([\w\-./]+)(?:\s+mode\s+([\w\-./]+))?/gi;
1133
+ while ((match = enPattern.exec(content)) !== null) {
1134
+ const target = this.normalizeEntity(match[1] || '');
1135
+ const executor = this.normalizeEntity(match[2] || '');
1136
+ const mode = this.normalizeEntity(match[3] || '') || undefined;
1137
+ if (target && executor)
1138
+ bindings.push({ target, executor, mode });
1139
+ }
1140
+ const cnPattern = /用\s*([\w\-./]+)\s*执行\s*([\w\-./]+)(?:\s*模式\s*([\w\-./]+))?/gi;
1141
+ while ((match = cnPattern.exec(content)) !== null) {
1142
+ const executor = this.normalizeEntity(match[1] || '');
1143
+ const target = this.normalizeEntity(match[2] || '');
1144
+ const mode = this.normalizeEntity(match[3] || '') || undefined;
1145
+ if (target && executor)
1146
+ bindings.push({ target, executor, mode });
1147
+ }
1148
+ return bindings;
1149
+ }
1150
+ parseMergePropagation(content) {
1151
+ const propagations = [];
1152
+ let match;
1153
+ const enPattern = /merge\s+into\s+([\w\-./]+)\s+propagates\s+([\w\-./]+)\s+and\s+([\w\-./]+)/gi;
1154
+ while ((match = enPattern.exec(content)) !== null) {
1155
+ const into = this.normalizeEntity(match[1] || '');
1156
+ const left = this.normalizeEntity(match[2] || '');
1157
+ const right = this.normalizeEntity(match[3] || '');
1158
+ if (into && left && right)
1159
+ propagations.push({ into, propagates: [left, right] });
1160
+ }
1161
+ const cnPattern = /合并到\s*([\w\-./]+)\s*传播\s*([\w\-./]+)\s*和\s*([\w\-./]+)/gi;
1162
+ while ((match = cnPattern.exec(content)) !== null) {
1163
+ const into = this.normalizeEntity(match[1] || '');
1164
+ const left = this.normalizeEntity(match[2] || '');
1165
+ const right = this.normalizeEntity(match[3] || '');
1166
+ if (into && left && right)
1167
+ propagations.push({ into, propagates: [left, right] });
1168
+ }
1169
+ return propagations;
1170
+ }
1171
+ dedupeCandidates(candidates) {
1172
+ const deduped = new Map();
1173
+ for (const candidate of candidates) {
1174
+ const key = [
1175
+ candidate.subject,
1176
+ candidate.predicate,
1177
+ candidate.objectValue.normalized || candidate.objectValue.raw,
1178
+ candidate.scope,
1179
+ candidate.validityKind || 'open',
1180
+ candidate.metadata?.conditionExpr || ''
1181
+ ].join('|');
1182
+ const existing = deduped.get(key);
1183
+ if (!existing || candidate.confidence > existing.confidence) {
1184
+ deduped.set(key, candidate);
1185
+ }
1186
+ }
1187
+ return Array.from(deduped.values());
1188
+ }
1189
+ }