@co-engram/core 0.1.0

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 (531) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +167 -0
  3. package/dist/config/defaults.d.ts +45 -0
  4. package/dist/config/defaults.d.ts.map +1 -0
  5. package/dist/config/defaults.js +70 -0
  6. package/dist/config/defaults.js.map +1 -0
  7. package/dist/config/index.d.ts +84 -0
  8. package/dist/config/index.d.ts.map +1 -0
  9. package/dist/config/index.js +230 -0
  10. package/dist/config/index.js.map +1 -0
  11. package/dist/config/types.d.ts +145 -0
  12. package/dist/config/types.d.ts.map +1 -0
  13. package/dist/config/types.js +14 -0
  14. package/dist/config/types.js.map +1 -0
  15. package/dist/contradiction/arbiter.d.ts +51 -0
  16. package/dist/contradiction/arbiter.d.ts.map +1 -0
  17. package/dist/contradiction/arbiter.js +112 -0
  18. package/dist/contradiction/arbiter.js.map +1 -0
  19. package/dist/contradiction/auto-degrade.d.ts +53 -0
  20. package/dist/contradiction/auto-degrade.d.ts.map +1 -0
  21. package/dist/contradiction/auto-degrade.js +79 -0
  22. package/dist/contradiction/auto-degrade.js.map +1 -0
  23. package/dist/contradiction/detector.d.ts +33 -0
  24. package/dist/contradiction/detector.d.ts.map +1 -0
  25. package/dist/contradiction/detector.js +76 -0
  26. package/dist/contradiction/detector.js.map +1 -0
  27. package/dist/contradiction/index.d.ts +11 -0
  28. package/dist/contradiction/index.d.ts.map +1 -0
  29. package/dist/contradiction/index.js +11 -0
  30. package/dist/contradiction/index.js.map +1 -0
  31. package/dist/contradiction/resolver.d.ts +45 -0
  32. package/dist/contradiction/resolver.d.ts.map +1 -0
  33. package/dist/contradiction/resolver.js +196 -0
  34. package/dist/contradiction/resolver.js.map +1 -0
  35. package/dist/contradiction/types.d.ts +73 -0
  36. package/dist/contradiction/types.d.ts.map +1 -0
  37. package/dist/contradiction/types.js +7 -0
  38. package/dist/contradiction/types.js.map +1 -0
  39. package/dist/dedup/dedupe.d.ts +49 -0
  40. package/dist/dedup/dedupe.d.ts.map +1 -0
  41. package/dist/dedup/dedupe.js +111 -0
  42. package/dist/dedup/dedupe.js.map +1 -0
  43. package/dist/dedup/hash.d.ts +27 -0
  44. package/dist/dedup/hash.d.ts.map +1 -0
  45. package/dist/dedup/hash.js +43 -0
  46. package/dist/dedup/hash.js.map +1 -0
  47. package/dist/dedup/index.d.ts +12 -0
  48. package/dist/dedup/index.d.ts.map +1 -0
  49. package/dist/dedup/index.js +12 -0
  50. package/dist/dedup/index.js.map +1 -0
  51. package/dist/dedup/llm-triage.d.ts +48 -0
  52. package/dist/dedup/llm-triage.d.ts.map +1 -0
  53. package/dist/dedup/llm-triage.js +100 -0
  54. package/dist/dedup/llm-triage.js.map +1 -0
  55. package/dist/dedup/merge.d.ts +41 -0
  56. package/dist/dedup/merge.d.ts.map +1 -0
  57. package/dist/dedup/merge.js +55 -0
  58. package/dist/dedup/merge.js.map +1 -0
  59. package/dist/dedup/similar.d.ts +45 -0
  60. package/dist/dedup/similar.d.ts.map +1 -0
  61. package/dist/dedup/similar.js +103 -0
  62. package/dist/dedup/similar.js.map +1 -0
  63. package/dist/dedup/types.d.ts +72 -0
  64. package/dist/dedup/types.d.ts.map +1 -0
  65. package/dist/dedup/types.js +18 -0
  66. package/dist/dedup/types.js.map +1 -0
  67. package/dist/disclosure/adaptive.d.ts +86 -0
  68. package/dist/disclosure/adaptive.d.ts.map +1 -0
  69. package/dist/disclosure/adaptive.js +196 -0
  70. package/dist/disclosure/adaptive.js.map +1 -0
  71. package/dist/disclosure/budget.d.ts +51 -0
  72. package/dist/disclosure/budget.d.ts.map +1 -0
  73. package/dist/disclosure/budget.js +91 -0
  74. package/dist/disclosure/budget.js.map +1 -0
  75. package/dist/disclosure/index.d.ts +11 -0
  76. package/dist/disclosure/index.d.ts.map +1 -0
  77. package/dist/disclosure/index.js +11 -0
  78. package/dist/disclosure/index.js.map +1 -0
  79. package/dist/disclosure/tier-loader.d.ts +58 -0
  80. package/dist/disclosure/tier-loader.d.ts.map +1 -0
  81. package/dist/disclosure/tier-loader.js +205 -0
  82. package/dist/disclosure/tier-loader.js.map +1 -0
  83. package/dist/dreaming/decay.d.ts +46 -0
  84. package/dist/dreaming/decay.d.ts.map +1 -0
  85. package/dist/dreaming/decay.js +69 -0
  86. package/dist/dreaming/decay.js.map +1 -0
  87. package/dist/dreaming/deep.d.ts +48 -0
  88. package/dist/dreaming/deep.d.ts.map +1 -0
  89. package/dist/dreaming/deep.js +41 -0
  90. package/dist/dreaming/deep.js.map +1 -0
  91. package/dist/dreaming/index.d.ts +12 -0
  92. package/dist/dreaming/index.d.ts.map +1 -0
  93. package/dist/dreaming/index.js +12 -0
  94. package/dist/dreaming/index.js.map +1 -0
  95. package/dist/dreaming/light.d.ts +54 -0
  96. package/dist/dreaming/light.d.ts.map +1 -0
  97. package/dist/dreaming/light.js +114 -0
  98. package/dist/dreaming/light.js.map +1 -0
  99. package/dist/dreaming/rem.d.ts +128 -0
  100. package/dist/dreaming/rem.d.ts.map +1 -0
  101. package/dist/dreaming/rem.js +228 -0
  102. package/dist/dreaming/rem.js.map +1 -0
  103. package/dist/dreaming/scheduler.d.ts +75 -0
  104. package/dist/dreaming/scheduler.d.ts.map +1 -0
  105. package/dist/dreaming/scheduler.js +138 -0
  106. package/dist/dreaming/scheduler.js.map +1 -0
  107. package/dist/dreaming/trash.d.ts +174 -0
  108. package/dist/dreaming/trash.d.ts.map +1 -0
  109. package/dist/dreaming/trash.js +466 -0
  110. package/dist/dreaming/trash.js.map +1 -0
  111. package/dist/evolution/category.d.ts +127 -0
  112. package/dist/evolution/category.d.ts.map +1 -0
  113. package/dist/evolution/category.js +271 -0
  114. package/dist/evolution/category.js.map +1 -0
  115. package/dist/evolution/index.d.ts +8 -0
  116. package/dist/evolution/index.d.ts.map +1 -0
  117. package/dist/evolution/index.js +8 -0
  118. package/dist/evolution/index.js.map +1 -0
  119. package/dist/evolution/triggered.d.ts +107 -0
  120. package/dist/evolution/triggered.d.ts.map +1 -0
  121. package/dist/evolution/triggered.js +278 -0
  122. package/dist/evolution/triggered.js.map +1 -0
  123. package/dist/generative/cross-pollinate.d.ts +144 -0
  124. package/dist/generative/cross-pollinate.d.ts.map +1 -0
  125. package/dist/generative/cross-pollinate.js +390 -0
  126. package/dist/generative/cross-pollinate.js.map +1 -0
  127. package/dist/generative/gap-detector.d.ts +80 -0
  128. package/dist/generative/gap-detector.d.ts.map +1 -0
  129. package/dist/generative/gap-detector.js +250 -0
  130. package/dist/generative/gap-detector.js.map +1 -0
  131. package/dist/generative/hypothesis.d.ts +161 -0
  132. package/dist/generative/hypothesis.d.ts.map +1 -0
  133. package/dist/generative/hypothesis.js +356 -0
  134. package/dist/generative/hypothesis.js.map +1 -0
  135. package/dist/generative/index.d.ts +9 -0
  136. package/dist/generative/index.d.ts.map +1 -0
  137. package/dist/generative/index.js +9 -0
  138. package/dist/generative/index.js.map +1 -0
  139. package/dist/graph/clustering.d.ts +117 -0
  140. package/dist/graph/clustering.d.ts.map +1 -0
  141. package/dist/graph/clustering.js +196 -0
  142. package/dist/graph/clustering.js.map +1 -0
  143. package/dist/graph/index.d.ts +13 -0
  144. package/dist/graph/index.d.ts.map +1 -0
  145. package/dist/graph/index.js +13 -0
  146. package/dist/graph/index.js.map +1 -0
  147. package/dist/graph/layout.d.ts +46 -0
  148. package/dist/graph/layout.d.ts.map +1 -0
  149. package/dist/graph/layout.js +269 -0
  150. package/dist/graph/layout.js.map +1 -0
  151. package/dist/graph/presets.d.ts +134 -0
  152. package/dist/graph/presets.d.ts.map +1 -0
  153. package/dist/graph/presets.js +190 -0
  154. package/dist/graph/presets.js.map +1 -0
  155. package/dist/graph/registry.d.ts +42 -0
  156. package/dist/graph/registry.d.ts.map +1 -0
  157. package/dist/graph/registry.js +158 -0
  158. package/dist/graph/registry.js.map +1 -0
  159. package/dist/graph/snapshot.d.ts +113 -0
  160. package/dist/graph/snapshot.d.ts.map +1 -0
  161. package/dist/graph/snapshot.js +194 -0
  162. package/dist/graph/snapshot.js.map +1 -0
  163. package/dist/graph/traverse.d.ts +84 -0
  164. package/dist/graph/traverse.d.ts.map +1 -0
  165. package/dist/graph/traverse.js +190 -0
  166. package/dist/graph/traverse.js.map +1 -0
  167. package/dist/graph/view-config.d.ts +99 -0
  168. package/dist/graph/view-config.d.ts.map +1 -0
  169. package/dist/graph/view-config.js +208 -0
  170. package/dist/graph/view-config.js.map +1 -0
  171. package/dist/host/detect-git-author.d.ts +26 -0
  172. package/dist/host/detect-git-author.d.ts.map +1 -0
  173. package/dist/host/detect-git-author.js +53 -0
  174. package/dist/host/detect-git-author.js.map +1 -0
  175. package/dist/host/index.d.ts +7 -0
  176. package/dist/host/index.d.ts.map +1 -0
  177. package/dist/host/index.js +7 -0
  178. package/dist/host/index.js.map +1 -0
  179. package/dist/i18n/en.d.ts +8 -0
  180. package/dist/i18n/en.d.ts.map +1 -0
  181. package/dist/i18n/en.js +211 -0
  182. package/dist/i18n/en.js.map +1 -0
  183. package/dist/i18n/field-names.d.ts +95 -0
  184. package/dist/i18n/field-names.d.ts.map +1 -0
  185. package/dist/i18n/field-names.js +329 -0
  186. package/dist/i18n/field-names.js.map +1 -0
  187. package/dist/i18n/index.d.ts +92 -0
  188. package/dist/i18n/index.d.ts.map +1 -0
  189. package/dist/i18n/index.js +135 -0
  190. package/dist/i18n/index.js.map +1 -0
  191. package/dist/i18n/types.d.ts +92 -0
  192. package/dist/i18n/types.d.ts.map +1 -0
  193. package/dist/i18n/types.js +7 -0
  194. package/dist/i18n/types.js.map +1 -0
  195. package/dist/i18n/zh.d.ts +197 -0
  196. package/dist/i18n/zh.d.ts.map +1 -0
  197. package/dist/i18n/zh.js +216 -0
  198. package/dist/i18n/zh.js.map +1 -0
  199. package/dist/importance/index.d.ts +7 -0
  200. package/dist/importance/index.d.ts.map +1 -0
  201. package/dist/importance/index.js +7 -0
  202. package/dist/importance/index.js.map +1 -0
  203. package/dist/importance/vector.d.ts +113 -0
  204. package/dist/importance/vector.d.ts.map +1 -0
  205. package/dist/importance/vector.js +202 -0
  206. package/dist/importance/vector.js.map +1 -0
  207. package/dist/index/digest-builder.d.ts +59 -0
  208. package/dist/index/digest-builder.d.ts.map +1 -0
  209. package/dist/index/digest-builder.js +195 -0
  210. package/dist/index/digest-builder.js.map +1 -0
  211. package/dist/index/graph-builder.d.ts +32 -0
  212. package/dist/index/graph-builder.d.ts.map +1 -0
  213. package/dist/index/graph-builder.js +104 -0
  214. package/dist/index/graph-builder.js.map +1 -0
  215. package/dist/index/incremental.d.ts +31 -0
  216. package/dist/index/incremental.d.ts.map +1 -0
  217. package/dist/index/incremental.js +47 -0
  218. package/dist/index/incremental.js.map +1 -0
  219. package/dist/index/index.d.ts +11 -0
  220. package/dist/index/index.d.ts.map +1 -0
  221. package/dist/index/index.js +11 -0
  222. package/dist/index/index.js.map +1 -0
  223. package/dist/index/orchestrator.d.ts +60 -0
  224. package/dist/index/orchestrator.d.ts.map +1 -0
  225. package/dist/index/orchestrator.js +99 -0
  226. package/dist/index/orchestrator.js.map +1 -0
  227. package/dist/index/types.d.ts +116 -0
  228. package/dist/index/types.d.ts.map +1 -0
  229. package/dist/index/types.js +10 -0
  230. package/dist/index/types.js.map +1 -0
  231. package/dist/index.d.ts +37 -0
  232. package/dist/index.d.ts.map +1 -0
  233. package/dist/index.js +37 -0
  234. package/dist/index.js.map +1 -0
  235. package/dist/learning/index.d.ts +7 -0
  236. package/dist/learning/index.d.ts.map +1 -0
  237. package/dist/learning/index.js +7 -0
  238. package/dist/learning/index.js.map +1 -0
  239. package/dist/learning/loop.d.ts +79 -0
  240. package/dist/learning/loop.d.ts.map +1 -0
  241. package/dist/learning/loop.js +116 -0
  242. package/dist/learning/loop.js.map +1 -0
  243. package/dist/lifecycle/freshness.d.ts +35 -0
  244. package/dist/lifecycle/freshness.d.ts.map +1 -0
  245. package/dist/lifecycle/freshness.js +60 -0
  246. package/dist/lifecycle/freshness.js.map +1 -0
  247. package/dist/lifecycle/index.d.ts +7 -0
  248. package/dist/lifecycle/index.d.ts.map +1 -0
  249. package/dist/lifecycle/index.js +7 -0
  250. package/dist/lifecycle/index.js.map +1 -0
  251. package/dist/lineage/index.d.ts +10 -0
  252. package/dist/lineage/index.d.ts.map +1 -0
  253. package/dist/lineage/index.js +10 -0
  254. package/dist/lineage/index.js.map +1 -0
  255. package/dist/lineage/trace.d.ts +142 -0
  256. package/dist/lineage/trace.d.ts.map +1 -0
  257. package/dist/lineage/trace.js +316 -0
  258. package/dist/lineage/trace.js.map +1 -0
  259. package/dist/maintenance/engine.d.ts +78 -0
  260. package/dist/maintenance/engine.d.ts.map +1 -0
  261. package/dist/maintenance/engine.js +291 -0
  262. package/dist/maintenance/engine.js.map +1 -0
  263. package/dist/maintenance/index.d.ts +8 -0
  264. package/dist/maintenance/index.d.ts.map +1 -0
  265. package/dist/maintenance/index.js +8 -0
  266. package/dist/maintenance/index.js.map +1 -0
  267. package/dist/maintenance/types.d.ts +111 -0
  268. package/dist/maintenance/types.d.ts.map +1 -0
  269. package/dist/maintenance/types.js +24 -0
  270. package/dist/maintenance/types.js.map +1 -0
  271. package/dist/observability/audit-log.d.ts +77 -0
  272. package/dist/observability/audit-log.d.ts.map +1 -0
  273. package/dist/observability/audit-log.js +101 -0
  274. package/dist/observability/audit-log.js.map +1 -0
  275. package/dist/observability/effectiveness-tracker.d.ts +162 -0
  276. package/dist/observability/effectiveness-tracker.d.ts.map +1 -0
  277. package/dist/observability/effectiveness-tracker.js +251 -0
  278. package/dist/observability/effectiveness-tracker.js.map +1 -0
  279. package/dist/observability/index.d.ts +16 -0
  280. package/dist/observability/index.d.ts.map +1 -0
  281. package/dist/observability/index.js +16 -0
  282. package/dist/observability/index.js.map +1 -0
  283. package/dist/observability/necessity-evaluator.d.ts +116 -0
  284. package/dist/observability/necessity-evaluator.d.ts.map +1 -0
  285. package/dist/observability/necessity-evaluator.js +487 -0
  286. package/dist/observability/necessity-evaluator.js.map +1 -0
  287. package/dist/observability/proposal-engine.d.ts +224 -0
  288. package/dist/observability/proposal-engine.d.ts.map +1 -0
  289. package/dist/observability/proposal-engine.js +651 -0
  290. package/dist/observability/proposal-engine.js.map +1 -0
  291. package/dist/perspectives/index.d.ts +7 -0
  292. package/dist/perspectives/index.d.ts.map +1 -0
  293. package/dist/perspectives/index.js +7 -0
  294. package/dist/perspectives/index.js.map +1 -0
  295. package/dist/perspectives/multi-view.d.ts +81 -0
  296. package/dist/perspectives/multi-view.d.ts.map +1 -0
  297. package/dist/perspectives/multi-view.js +221 -0
  298. package/dist/perspectives/multi-view.js.map +1 -0
  299. package/dist/prompt-builder/builder.d.ts +47 -0
  300. package/dist/prompt-builder/builder.d.ts.map +1 -0
  301. package/dist/prompt-builder/builder.js +136 -0
  302. package/dist/prompt-builder/builder.js.map +1 -0
  303. package/dist/prompt-builder/index.d.ts +8 -0
  304. package/dist/prompt-builder/index.d.ts.map +1 -0
  305. package/dist/prompt-builder/index.js +8 -0
  306. package/dist/prompt-builder/index.js.map +1 -0
  307. package/dist/prompt-builder/types.d.ts +42 -0
  308. package/dist/prompt-builder/types.d.ts.map +1 -0
  309. package/dist/prompt-builder/types.js +10 -0
  310. package/dist/prompt-builder/types.js.map +1 -0
  311. package/dist/prompt-signals/cache.d.ts +36 -0
  312. package/dist/prompt-signals/cache.d.ts.map +1 -0
  313. package/dist/prompt-signals/cache.js +70 -0
  314. package/dist/prompt-signals/cache.js.map +1 -0
  315. package/dist/prompt-signals/index.d.ts +12 -0
  316. package/dist/prompt-signals/index.d.ts.map +1 -0
  317. package/dist/prompt-signals/index.js +11 -0
  318. package/dist/prompt-signals/index.js.map +1 -0
  319. package/dist/prompt-signals/stats.d.ts +45 -0
  320. package/dist/prompt-signals/stats.d.ts.map +1 -0
  321. package/dist/prompt-signals/stats.js +119 -0
  322. package/dist/prompt-signals/stats.js.map +1 -0
  323. package/dist/prompt-signals/types.d.ts +53 -0
  324. package/dist/prompt-signals/types.d.ts.map +1 -0
  325. package/dist/prompt-signals/types.js +34 -0
  326. package/dist/prompt-signals/types.js.map +1 -0
  327. package/dist/provenance/index.d.ts +7 -0
  328. package/dist/provenance/index.d.ts.map +1 -0
  329. package/dist/provenance/index.js +7 -0
  330. package/dist/provenance/index.js.map +1 -0
  331. package/dist/provenance/reliability.d.ts +133 -0
  332. package/dist/provenance/reliability.d.ts.map +1 -0
  333. package/dist/provenance/reliability.js +213 -0
  334. package/dist/provenance/reliability.js.map +1 -0
  335. package/dist/reinforcement/config.d.ts +34 -0
  336. package/dist/reinforcement/config.d.ts.map +1 -0
  337. package/dist/reinforcement/config.js +43 -0
  338. package/dist/reinforcement/config.js.map +1 -0
  339. package/dist/reinforcement/index.d.ts +12 -0
  340. package/dist/reinforcement/index.d.ts.map +1 -0
  341. package/dist/reinforcement/index.js +12 -0
  342. package/dist/reinforcement/index.js.map +1 -0
  343. package/dist/reinforcement/ltd.d.ts +59 -0
  344. package/dist/reinforcement/ltd.d.ts.map +1 -0
  345. package/dist/reinforcement/ltd.js +90 -0
  346. package/dist/reinforcement/ltd.js.map +1 -0
  347. package/dist/reinforcement/ltp.d.ts +63 -0
  348. package/dist/reinforcement/ltp.d.ts.map +1 -0
  349. package/dist/reinforcement/ltp.js +99 -0
  350. package/dist/reinforcement/ltp.js.map +1 -0
  351. package/dist/reinforcement/related.d.ts +39 -0
  352. package/dist/reinforcement/related.d.ts.map +1 -0
  353. package/dist/reinforcement/related.js +92 -0
  354. package/dist/reinforcement/related.js.map +1 -0
  355. package/dist/retrieval/filter.d.ts +18 -0
  356. package/dist/retrieval/filter.d.ts.map +1 -0
  357. package/dist/retrieval/filter.js +68 -0
  358. package/dist/retrieval/filter.js.map +1 -0
  359. package/dist/retrieval/fts.d.ts +44 -0
  360. package/dist/retrieval/fts.d.ts.map +1 -0
  361. package/dist/retrieval/fts.js +120 -0
  362. package/dist/retrieval/fts.js.map +1 -0
  363. package/dist/retrieval/index.d.ts +10 -0
  364. package/dist/retrieval/index.d.ts.map +1 -0
  365. package/dist/retrieval/index.js +10 -0
  366. package/dist/retrieval/index.js.map +1 -0
  367. package/dist/retrieval/orchestrator.d.ts +78 -0
  368. package/dist/retrieval/orchestrator.d.ts.map +1 -0
  369. package/dist/retrieval/orchestrator.js +156 -0
  370. package/dist/retrieval/orchestrator.js.map +1 -0
  371. package/dist/retrieval/scoring.d.ts +105 -0
  372. package/dist/retrieval/scoring.d.ts.map +1 -0
  373. package/dist/retrieval/scoring.js +165 -0
  374. package/dist/retrieval/scoring.js.map +1 -0
  375. package/dist/signals/extract.d.ts +98 -0
  376. package/dist/signals/extract.d.ts.map +1 -0
  377. package/dist/signals/extract.js +388 -0
  378. package/dist/signals/extract.js.map +1 -0
  379. package/dist/signals/file-sink.d.ts +81 -0
  380. package/dist/signals/file-sink.d.ts.map +1 -0
  381. package/dist/signals/file-sink.js +227 -0
  382. package/dist/signals/file-sink.js.map +1 -0
  383. package/dist/signals/index.d.ts +12 -0
  384. package/dist/signals/index.d.ts.map +1 -0
  385. package/dist/signals/index.js +12 -0
  386. package/dist/signals/index.js.map +1 -0
  387. package/dist/signals/rpe.d.ts +60 -0
  388. package/dist/signals/rpe.d.ts.map +1 -0
  389. package/dist/signals/rpe.js +68 -0
  390. package/dist/signals/rpe.js.map +1 -0
  391. package/dist/signals/types.d.ts +80 -0
  392. package/dist/signals/types.d.ts.map +1 -0
  393. package/dist/signals/types.js +14 -0
  394. package/dist/signals/types.js.map +1 -0
  395. package/dist/storage/engram-index.d.ts +73 -0
  396. package/dist/storage/engram-index.d.ts.map +1 -0
  397. package/dist/storage/engram-index.js +215 -0
  398. package/dist/storage/engram-index.js.map +1 -0
  399. package/dist/storage/engram-store.d.ts +147 -0
  400. package/dist/storage/engram-store.d.ts.map +1 -0
  401. package/dist/storage/engram-store.js +221 -0
  402. package/dist/storage/engram-store.js.map +1 -0
  403. package/dist/storage/git-stage.d.ts +56 -0
  404. package/dist/storage/git-stage.d.ts.map +1 -0
  405. package/dist/storage/git-stage.js +147 -0
  406. package/dist/storage/git-stage.js.map +1 -0
  407. package/dist/storage/git.d.ts +57 -0
  408. package/dist/storage/git.d.ts.map +1 -0
  409. package/dist/storage/git.js +156 -0
  410. package/dist/storage/git.js.map +1 -0
  411. package/dist/storage/hash.d.ts +23 -0
  412. package/dist/storage/hash.d.ts.map +1 -0
  413. package/dist/storage/hash.js +31 -0
  414. package/dist/storage/hash.js.map +1 -0
  415. package/dist/storage/index.d.ts +14 -0
  416. package/dist/storage/index.d.ts.map +1 -0
  417. package/dist/storage/index.js +14 -0
  418. package/dist/storage/index.js.map +1 -0
  419. package/dist/storage/path.d.ts +51 -0
  420. package/dist/storage/path.d.ts.map +1 -0
  421. package/dist/storage/path.js +72 -0
  422. package/dist/storage/path.js.map +1 -0
  423. package/dist/storage/repository.d.ts +342 -0
  424. package/dist/storage/repository.d.ts.map +1 -0
  425. package/dist/storage/repository.js +1221 -0
  426. package/dist/storage/repository.js.map +1 -0
  427. package/dist/storage/synapse-store.d.ts +113 -0
  428. package/dist/storage/synapse-store.d.ts.map +1 -0
  429. package/dist/storage/synapse-store.js +279 -0
  430. package/dist/storage/synapse-store.js.map +1 -0
  431. package/dist/tools/doctor-tools.d.ts +53 -0
  432. package/dist/tools/doctor-tools.d.ts.map +1 -0
  433. package/dist/tools/doctor-tools.js +97 -0
  434. package/dist/tools/doctor-tools.js.map +1 -0
  435. package/dist/tools/engram-tools.d.ts +166 -0
  436. package/dist/tools/engram-tools.d.ts.map +1 -0
  437. package/dist/tools/engram-tools.js +834 -0
  438. package/dist/tools/engram-tools.js.map +1 -0
  439. package/dist/tools/index.d.ts +16 -0
  440. package/dist/tools/index.d.ts.map +1 -0
  441. package/dist/tools/index.js +16 -0
  442. package/dist/tools/index.js.map +1 -0
  443. package/dist/tools/llm-descriptions.d.ts +61 -0
  444. package/dist/tools/llm-descriptions.d.ts.map +1 -0
  445. package/dist/tools/llm-descriptions.js +556 -0
  446. package/dist/tools/llm-descriptions.js.map +1 -0
  447. package/dist/tools/proposal-tools.d.ts +40 -0
  448. package/dist/tools/proposal-tools.d.ts.map +1 -0
  449. package/dist/tools/proposal-tools.js +99 -0
  450. package/dist/tools/proposal-tools.js.map +1 -0
  451. package/dist/tools/registry.d.ts +30 -0
  452. package/dist/tools/registry.d.ts.map +1 -0
  453. package/dist/tools/registry.js +43 -0
  454. package/dist/tools/registry.js.map +1 -0
  455. package/dist/tools/schemas.d.ts +715 -0
  456. package/dist/tools/schemas.d.ts.map +1 -0
  457. package/dist/tools/schemas.js +383 -0
  458. package/dist/tools/schemas.js.map +1 -0
  459. package/dist/tools/skill-tools.d.ts +26 -0
  460. package/dist/tools/skill-tools.d.ts.map +1 -0
  461. package/dist/tools/skill-tools.js +84 -0
  462. package/dist/tools/skill-tools.js.map +1 -0
  463. package/dist/tools/synapse-tools.d.ts +28 -0
  464. package/dist/tools/synapse-tools.d.ts.map +1 -0
  465. package/dist/tools/synapse-tools.js +177 -0
  466. package/dist/tools/synapse-tools.js.map +1 -0
  467. package/dist/tools/tool.d.ts +84 -0
  468. package/dist/tools/tool.d.ts.map +1 -0
  469. package/dist/tools/tool.js +22 -0
  470. package/dist/tools/tool.js.map +1 -0
  471. package/dist/tools/wrapped.d.ts +28 -0
  472. package/dist/tools/wrapped.d.ts.map +1 -0
  473. package/dist/tools/wrapped.js +172 -0
  474. package/dist/tools/wrapped.js.map +1 -0
  475. package/dist/types/disclosure.d.ts +70 -0
  476. package/dist/types/disclosure.d.ts.map +1 -0
  477. package/dist/types/disclosure.js +9 -0
  478. package/dist/types/disclosure.js.map +1 -0
  479. package/dist/types/engram.d.ts +203 -0
  480. package/dist/types/engram.d.ts.map +1 -0
  481. package/dist/types/engram.js +7 -0
  482. package/dist/types/engram.js.map +1 -0
  483. package/dist/types/index.d.ts +15 -0
  484. package/dist/types/index.d.ts.map +1 -0
  485. package/dist/types/index.js +15 -0
  486. package/dist/types/index.js.map +1 -0
  487. package/dist/types/intention.d.ts +91 -0
  488. package/dist/types/intention.d.ts.map +1 -0
  489. package/dist/types/intention.js +9 -0
  490. package/dist/types/intention.js.map +1 -0
  491. package/dist/types/repository-types.d.ts +113 -0
  492. package/dist/types/repository-types.d.ts.map +1 -0
  493. package/dist/types/repository-types.js +18 -0
  494. package/dist/types/repository-types.js.map +1 -0
  495. package/dist/types/scene.d.ts +52 -0
  496. package/dist/types/scene.d.ts.map +1 -0
  497. package/dist/types/scene.js +12 -0
  498. package/dist/types/scene.js.map +1 -0
  499. package/dist/types/skill.d.ts +107 -0
  500. package/dist/types/skill.d.ts.map +1 -0
  501. package/dist/types/skill.js +10 -0
  502. package/dist/types/skill.js.map +1 -0
  503. package/dist/types/slugify.d.ts +34 -0
  504. package/dist/types/slugify.d.ts.map +1 -0
  505. package/dist/types/slugify.js +55 -0
  506. package/dist/types/slugify.js.map +1 -0
  507. package/dist/types/synapse-id.d.ts +22 -0
  508. package/dist/types/synapse-id.d.ts.map +1 -0
  509. package/dist/types/synapse-id.js +34 -0
  510. package/dist/types/synapse-id.js.map +1 -0
  511. package/dist/types/synapse.d.ts +99 -0
  512. package/dist/types/synapse.d.ts.map +1 -0
  513. package/dist/types/synapse.js +9 -0
  514. package/dist/types/synapse.js.map +1 -0
  515. package/dist/verification/index.d.ts +11 -0
  516. package/dist/verification/index.d.ts.map +1 -0
  517. package/dist/verification/index.js +11 -0
  518. package/dist/verification/index.js.map +1 -0
  519. package/dist/verification/metacognition.d.ts +102 -0
  520. package/dist/verification/metacognition.d.ts.map +1 -0
  521. package/dist/verification/metacognition.js +284 -0
  522. package/dist/verification/metacognition.js.map +1 -0
  523. package/dist/verification/state-machine.d.ts +77 -0
  524. package/dist/verification/state-machine.d.ts.map +1 -0
  525. package/dist/verification/state-machine.js +126 -0
  526. package/dist/verification/state-machine.js.map +1 -0
  527. package/dist/verification/upgrade.d.ts +133 -0
  528. package/dist/verification/upgrade.d.ts.map +1 -0
  529. package/dist/verification/upgrade.js +364 -0
  530. package/dist/verification/upgrade.js.map +1 -0
  531. package/package.json +70 -0
@@ -0,0 +1,834 @@
1
+ /**
2
+ * Engram 工具集
3
+ *
4
+ * 11 个工具(P0 六个 + P1 五个:三信号 + 生命周期):
5
+ * - engram_create / engram_get / engram_update / engram_delete
6
+ * - engram_search / engram_list
7
+ * - engram_reinforce / engram_report_failure(三信号)
8
+ * - engram_archive / engram_restore / engram_forget(生命周期)
9
+ *
10
+ * @module @co-engram/core/tools
11
+ */
12
+ import { validateInput } from "./tool.js";
13
+ import { matchesFilter } from "../retrieval/filter.js";
14
+ import { computeFreshness } from "../lifecycle/freshness.js";
15
+ import { adaptiveDisclosure } from "../disclosure/adaptive.js";
16
+ import { createBudget } from "../disclosure/budget.js";
17
+ import { recordRetrievalSuccess, } from "../reinforcement/ltp.js";
18
+ import { recordRetrievalFailure } from "../reinforcement/ltd.js";
19
+ import { reinforceRelated } from "../reinforcement/related.js";
20
+ import { DEFAULT_CONFIG as DEFAULT_REINFORCEMENT_CONFIG } from "../reinforcement/config.js";
21
+ import { checkDuplicateSync } from "../dedup/dedupe.js";
22
+ import { mergeEngram } from "../dedup/merge.js";
23
+ import { recomputeImportance } from "../importance/vector.js";
24
+ import { manualResolveContradiction } from "../contradiction/index.js";
25
+ import { closeLearningLoop } from "../learning/loop.js";
26
+ import { upgradeVerification } from "../verification/index.js";
27
+ import { getEvolutionLineage } from "../lineage/index.js";
28
+ import { restoreFromTrash } from "../dreaming/trash.js";
29
+ import { collectDigestLines } from "../index/digest-builder.js";
30
+ import { EngramCreateInputSchema, EngramGetInputSchema, EngramUpdateInputSchema, EngramDeleteInputSchema, EngramSearchInputSchema, EngramListInputSchema, EngramReinforceInputSchema, EngramReportFailureInputSchema, EngramArchiveInputSchema, EngramRestoreInputSchema, EngramForgetInputSchema, EngramRecomputeImportanceInputSchema, ContradictionResolveInputSchema, CloseLearningLoopInputSchema, UpgradeVerificationInputSchema, GetEvolutionLineageInputSchema, } from "./schemas.js";
31
+ export const engramCreateTool = {
32
+ name: "engram_create",
33
+ description: '创建一个新的 Engram(记忆单元)。需要 title / content / kind / domainTags;createdBy 可选,缺省时回退到 ToolContext.defaultCreatedBy(MCP: CO_ENGRAM_DEFAULT_CREATED_BY 环境变量;OpenClaw: plugin config.defaultCreatedBy),再缺省回退到 "unknown"。默认开启智能去重(dedupe=true):DUPLICATE 时强化原 engram 不重复创建;UPDATE 时合并;NEW 时正常创建。',
34
+ inputSchema: EngramCreateInputSchema,
35
+ execute(input, ctx) {
36
+ const parsed = validateInput(EngramCreateInputSchema, input);
37
+ const createdBy = parsed.createdBy ?? ctx.defaultCreatedBy ?? "unknown";
38
+ if (parsed.dedupe !== false) {
39
+ const dedupResult = checkDuplicateSync({ repository: ctx.repository }, {
40
+ title: parsed.title,
41
+ content: parsed.content,
42
+ kind: parsed.kind,
43
+ kinds: parsed.kinds,
44
+ summary: parsed.summary,
45
+ domainTags: parsed.domainTags,
46
+ contextTags: parsed.contextTags,
47
+ encodingContext: parsed.encodingContext,
48
+ importance: parsed.importance,
49
+ confidence: parsed.confidence,
50
+ emotionalValence: parsed.emotionalValence,
51
+ sourceType: parsed.sourceType,
52
+ visibility: parsed.visibility,
53
+ decayHalfLifeDays: parsed.decayHalfLifeDays,
54
+ createdBy,
55
+ });
56
+ if (dedupResult.verdict === "DUPLICATE" && dedupResult.targetId) {
57
+ // 强化原 engram:再次见到视为有效检索(effectiveness=1)
58
+ recordRetrievalSuccess(ctx.repository, dedupResult.targetId, 1);
59
+ return {
60
+ id: dedupResult.targetId,
61
+ verdict: "DUPLICATE",
62
+ targetId: dedupResult.targetId,
63
+ reason: dedupResult.reason,
64
+ confidence: dedupResult.confidence,
65
+ candidatesConsidered: dedupResult.candidatesConsidered,
66
+ };
67
+ }
68
+ if (dedupResult.verdict === "UPDATE" && dedupResult.targetId) {
69
+ mergeEngram(ctx.repository, {
70
+ id: dedupResult.targetId,
71
+ newTitle: parsed.title,
72
+ newContent: parsed.content,
73
+ newSummary: parsed.summary,
74
+ newImportance: parsed.importance,
75
+ mergedBy: createdBy,
76
+ reason: dedupResult.reason ?? "dedup auto-merge",
77
+ });
78
+ invalidateSearchIndex(ctx);
79
+ return {
80
+ id: dedupResult.targetId,
81
+ verdict: "UPDATE",
82
+ targetId: dedupResult.targetId,
83
+ reason: dedupResult.reason,
84
+ confidence: dedupResult.confidence,
85
+ candidatesConsidered: dedupResult.candidatesConsidered,
86
+ };
87
+ }
88
+ }
89
+ const engram = ctx.repository.createEngram({
90
+ title: parsed.title,
91
+ content: parsed.content,
92
+ kind: parsed.kind,
93
+ kinds: parsed.kinds,
94
+ summary: parsed.summary,
95
+ domainTags: parsed.domainTags,
96
+ contextTags: parsed.contextTags,
97
+ encodingContext: parsed.encodingContext,
98
+ importance: parsed.importance,
99
+ confidence: parsed.confidence,
100
+ emotionalValence: parsed.emotionalValence,
101
+ sourceType: parsed.sourceType,
102
+ visibility: parsed.visibility,
103
+ decayHalfLifeDays: parsed.decayHalfLifeDays,
104
+ createdBy,
105
+ });
106
+ invalidateSearchIndex(ctx);
107
+ ctx.auditLog?.append({
108
+ actor: "user",
109
+ action: "create",
110
+ engramId: engram.id,
111
+ metadata: {
112
+ title: parsed.title,
113
+ kind: parsed.kind,
114
+ domainTags: parsed.domainTags,
115
+ createdBy,
116
+ },
117
+ });
118
+ return {
119
+ id: engram.id,
120
+ verdict: "NEW",
121
+ candidatesConsidered: 0,
122
+ };
123
+ },
124
+ };
125
+ // ============================================================
126
+ // engram_get
127
+ // ============================================================
128
+ export const engramGetTool = {
129
+ name: "engram_get",
130
+ description: "按披露层级(catalog / digest / content / meta / synapses / auto)读取 Engram。auto 模式按 contextBudget 自动选 tier。",
131
+ inputSchema: EngramGetInputSchema,
132
+ execute(input, ctx) {
133
+ const parsed = validateInput(EngramGetInputSchema, input);
134
+ if (parsed.tier === "auto") {
135
+ return readEngramViewAuto(ctx.repository, parsed.id, {
136
+ contextBudget: parsed.contextBudget,
137
+ score: parsed.score,
138
+ });
139
+ }
140
+ return readEngramView(ctx.repository, parsed.id, parsed.tier);
141
+ },
142
+ };
143
+ /**
144
+ * auto 模式:调用 adaptiveDisclosure 决定 tier
145
+ *
146
+ * 把单条 engram 当作唯一的候选传入。
147
+ */
148
+ function readEngramViewAuto(repo, id, options) {
149
+ const totalTokens = options.contextBudget?.totalTokens ?? 4096;
150
+ const reserved = options.contextBudget?.reserved ?? 0;
151
+ const budget = createBudget(totalTokens, reserved);
152
+ const digest = repo.readDigest(id);
153
+ if (!digest)
154
+ throw new Error(`Engram not found: ${id}`);
155
+ const line = {
156
+ id,
157
+ title: digest.title,
158
+ kind: digest.kind,
159
+ kinds: [digest.kind],
160
+ summary: digest.summary,
161
+ domainTags: digest.domainTags,
162
+ contextTags: [],
163
+ importance: digest.importance,
164
+ emotionalValence: digest.emotionalValence,
165
+ freshness: digest.freshness,
166
+ status: "active",
167
+ sourceType: "firsthand",
168
+ createdBy: "",
169
+ createdAt: digest.updatedAt,
170
+ updatedAt: digest.updatedAt,
171
+ lastRetrievedAt: null,
172
+ lastEffectiveAt: null,
173
+ retrievalCount: 0,
174
+ effectiveRetrievals: 0,
175
+ failedUses: 0,
176
+ reinforcementScore: 0,
177
+ decayHalfLifeDays: 90,
178
+ contentSize: digest.contentSize,
179
+ contentHash: "",
180
+ outgoingSynapseCount: 0,
181
+ incomingSynapseCount: 0,
182
+ activeContradictionCount: 0,
183
+ };
184
+ const result = adaptiveDisclosure({
185
+ repository: repo,
186
+ candidates: [{ id, score: options.score ?? 1 }],
187
+ digestLines: { [id]: line },
188
+ budget,
189
+ });
190
+ const entry = result.loaded[0];
191
+ if (!entry) {
192
+ // 预算极小,连 catalog 都装不下 → 降级为直接读 catalog
193
+ return readEngramView(repo, id, "catalog");
194
+ }
195
+ return entry.view;
196
+ }
197
+ /**
198
+ * 读取 EngramView(被工具 / adapter 共用)
199
+ */
200
+ export function readEngramView(repo, id, tier) {
201
+ switch (tier) {
202
+ case "catalog": {
203
+ const entry = repo.readCatalogEntry(id);
204
+ if (!entry)
205
+ throw new Error(`Engram not found: ${id}`);
206
+ return { tier: "catalog", entry };
207
+ }
208
+ case "digest": {
209
+ const digest = repo.readDigest(id);
210
+ if (!digest)
211
+ throw new Error(`Engram not found: ${id}`);
212
+ return { tier: "digest", digest };
213
+ }
214
+ case "content": {
215
+ const engram = repo.readEngram(id);
216
+ return {
217
+ tier: "content",
218
+ entry: toCatalogEntry(engram),
219
+ content: engram.content,
220
+ };
221
+ }
222
+ case "meta": {
223
+ const engram = repo.readEngram(id);
224
+ return {
225
+ tier: "meta",
226
+ entry: toCatalogEntry(engram),
227
+ meta: stripContentFromMeta(engram),
228
+ };
229
+ }
230
+ case "synapses": {
231
+ const entry = repo.readCatalogEntry(id);
232
+ if (!entry)
233
+ throw new Error(`Engram not found: ${id}`);
234
+ const outgoingFile = repo.readSynapses(id);
235
+ const incoming = collectIncoming(repo, id);
236
+ const neighborDigests = collectNeighborDigests(repo, id, outgoingFile.outgoing, incoming);
237
+ const bundle = {
238
+ engramId: id,
239
+ outgoing: outgoingFile.outgoing,
240
+ incoming,
241
+ neighborDigests,
242
+ };
243
+ return { tier: "synapses", bundle };
244
+ }
245
+ }
246
+ }
247
+ function toCatalogEntry(engram) {
248
+ return {
249
+ id: engram.id,
250
+ title: engram.title,
251
+ kind: engram.kind,
252
+ domainTags: engram.domainTags,
253
+ };
254
+ }
255
+ /** meta tier 不暴露 body(避免双重传输) */
256
+ function stripContentFromMeta(engram) {
257
+ const { content: _content, ...rest } = engram;
258
+ return rest;
259
+ }
260
+ /** 收集指向 id 的 incoming synapses(需要扫所有 engram) */
261
+ function collectIncoming(repo, id) {
262
+ const all = repo.collectAllSynapses();
263
+ return all
264
+ .filter(({ synapse }) => synapse.to === id)
265
+ .map(({ synapse }) => synapse);
266
+ }
267
+ function collectNeighborDigests(repo, _selfId, outgoing, incoming) {
268
+ const neighborIds = new Set();
269
+ for (const s of outgoing)
270
+ neighborIds.add(s.to);
271
+ for (const s of incoming)
272
+ neighborIds.add(s.from);
273
+ const digests = [];
274
+ for (const nid of neighborIds) {
275
+ const d = repo.readDigest(nid);
276
+ if (d)
277
+ digests.push(d);
278
+ }
279
+ return digests;
280
+ }
281
+ // ============================================================
282
+ // engram_update
283
+ // ============================================================
284
+ /**
285
+ * 跟踪 engram_update 的字段对比(用于 audit log)
286
+ *
287
+ * 不在表中的字段(version / updatedAt / retrievalCount 等系统字段)不算"用户修改"。
288
+ */
289
+ const TRACKED_ENGRAM_FIELDS = [
290
+ "title",
291
+ "summary",
292
+ "content",
293
+ "kinds",
294
+ "domainTags",
295
+ "contextTags",
296
+ "encodingContext",
297
+ "importance",
298
+ "confidence",
299
+ "emotionalValence",
300
+ "decayHalfLifeDays",
301
+ "visibility",
302
+ ];
303
+ /** 字段值在 audit 中的最大长度(超出截断,防 audit.jsonl 爆炸) */
304
+ const FIELD_TRUNCATE = {
305
+ title: 80,
306
+ summary: 120,
307
+ content: 240,
308
+ encodingContext: 120,
309
+ };
310
+ function truncateFieldValue(field, value) {
311
+ if (typeof value === "string") {
312
+ const max = FIELD_TRUNCATE[field] ?? 0;
313
+ if (max > 0 && value.length > max) {
314
+ const head = Math.ceil(max * 0.6);
315
+ const tail = Math.floor(max * 0.3);
316
+ const omitted = value.length - head - tail;
317
+ return (value.slice(0, head) +
318
+ `…[${omitted} chars omitted]…` +
319
+ value.slice(-tail));
320
+ }
321
+ }
322
+ return value;
323
+ }
324
+ /**
325
+ * 对比 before / after,返回每个变化字段的 { from, to }
326
+ *
327
+ * 用 JSON.stringify 等价比较覆盖数组 / 对象 / 基本类型,简单稳健。
328
+ */
329
+ function diffEngramFields(before, after) {
330
+ const changes = {};
331
+ for (const f of TRACKED_ENGRAM_FIELDS) {
332
+ const b = before[f];
333
+ const a = after[f];
334
+ if (JSON.stringify(b) === JSON.stringify(a))
335
+ continue;
336
+ changes[f] = {
337
+ from: truncateFieldValue(f, b),
338
+ to: truncateFieldValue(f, a),
339
+ };
340
+ }
341
+ return changes;
342
+ }
343
+ export const engramUpdateTool = {
344
+ name: "engram_update",
345
+ description: "更新 Engram 的字段(content / title / importance / 等)。",
346
+ inputSchema: EngramUpdateInputSchema,
347
+ execute(input, ctx) {
348
+ const parsed = validateInput(EngramUpdateInputSchema, input);
349
+ // 取 before 用于 audit diff;若 engram 不存在 updateEngram 会抛,这里 readEngram 也抛
350
+ const before = ctx.repository.readEngram(parsed.id);
351
+ const engram = ctx.repository.updateEngram(parsed.id, {
352
+ title: parsed.title,
353
+ content: parsed.content,
354
+ summary: parsed.summary,
355
+ kinds: parsed.kinds,
356
+ domainTags: parsed.domainTags,
357
+ contextTags: parsed.contextTags,
358
+ encodingContext: parsed.encodingContext,
359
+ importance: parsed.importance,
360
+ confidence: parsed.confidence,
361
+ emotionalValence: parsed.emotionalValence,
362
+ decayHalfLifeDays: parsed.decayHalfLifeDays,
363
+ visibility: parsed.visibility,
364
+ updatedBy: parsed.updatedBy,
365
+ });
366
+ invalidateSearchIndex(ctx);
367
+ ctx.auditLog?.append({
368
+ actor: "user",
369
+ action: "update",
370
+ engramId: engram.id,
371
+ metadata: {
372
+ updatedBy: parsed.updatedBy,
373
+ changes: diffEngramFields(before, engram),
374
+ },
375
+ });
376
+ return { id: engram.id, version: engram.version };
377
+ },
378
+ };
379
+ // ============================================================
380
+ // engram_delete
381
+ // ============================================================
382
+ export const engramDeleteTool = {
383
+ name: "engram_delete",
384
+ description: "删除 Engram(content + meta + synapses 三文件一起删)。",
385
+ inputSchema: EngramDeleteInputSchema,
386
+ execute(input, ctx) {
387
+ const parsed = validateInput(EngramDeleteInputSchema, input);
388
+ if (!ctx.repository.exists(parsed.id)) {
389
+ throw new Error(`Engram not found: ${parsed.id}`);
390
+ }
391
+ ctx.repository.deleteEngram(parsed.id);
392
+ invalidateSearchIndex(ctx);
393
+ ctx.auditLog?.append({
394
+ actor: "user",
395
+ action: "purge",
396
+ engramId: parsed.id,
397
+ });
398
+ return { id: parsed.id, deleted: true };
399
+ },
400
+ };
401
+ // ============================================================
402
+ // engram_search
403
+ // ============================================================
404
+ export const engramSearchTool = {
405
+ name: "engram_search",
406
+ description: "FTS 全文检索(中文 bigram + 英文 word),可选过滤器。",
407
+ inputSchema: EngramSearchInputSchema,
408
+ execute(input, ctx) {
409
+ const parsed = validateInput(EngramSearchInputSchema, input);
410
+ if (!ctx.searchOrchestrator) {
411
+ throw new Error("SearchOrchestrator not available in ToolContext");
412
+ }
413
+ const results = ctx.searchOrchestrator.search(parsed.query, parsed.filter, parsed.limit);
414
+ // P4 自动维护:命中后立即 bump retrieval stats(不触发 version++)
415
+ // 用于 RPE 公式的 expected 基准
416
+ const timestamp = new Date().toISOString();
417
+ for (const r of results) {
418
+ try {
419
+ ctx.repository.bumpRetrievalStats(r.id, {
420
+ retrievedDelta: 1,
421
+ lastRetrievalScore: r.score,
422
+ lastRetrievedAt: timestamp,
423
+ });
424
+ }
425
+ catch {
426
+ // bump 失败不阻塞 search 结果(可能 engram 已被并发删除)
427
+ }
428
+ // M1: 为每个 hit 开观察窗口(如果配置了 effectivenessTracker)
429
+ const engram = safeReadEngram(ctx, r.id);
430
+ if (engram) {
431
+ ctx.effectivenessTracker?.openWindow({
432
+ engramId: r.id,
433
+ query: parsed.query,
434
+ score: r.score,
435
+ kinds: engram.kinds ?? [engram.kind],
436
+ sessionId: ctx.sessionId,
437
+ });
438
+ }
439
+ }
440
+ return {
441
+ // title/kind/domainTags 让 LLM 不必再 engram_get 才知道每条结果是啥。
442
+ // orchestrator 已经从 DigestLine 带出了 entry 字段,直接展开。
443
+ results: results.map((r) => ({
444
+ id: r.id,
445
+ score: r.score,
446
+ title: r.entry.title,
447
+ kind: r.entry.kind,
448
+ domainTags: r.entry.domainTags,
449
+ })),
450
+ total: results.length,
451
+ };
452
+ },
453
+ };
454
+ // ============================================================
455
+ // engram_list
456
+ // ============================================================
457
+ export const engramListTool = {
458
+ name: "engram_list",
459
+ description: "按过滤器列出 Engram(无查询,按元数据过滤,直接读最新数据)。",
460
+ inputSchema: EngramListInputSchema,
461
+ execute(input, ctx) {
462
+ const parsed = validateInput(EngramListInputSchema, input);
463
+ const entries = ctx.repository.listEngrams();
464
+ const lines = [];
465
+ for (const entry of entries) {
466
+ const engram = ctx.repository.readEngram(entry.id);
467
+ lines.push(engramToDigestLine(engram));
468
+ }
469
+ const filtered = lines.filter((line) => matchesFilter(line, parsed.filter));
470
+ const limited = filtered.slice(0, parsed.limit);
471
+ return {
472
+ results: limited.map((line) => ({
473
+ id: line.id,
474
+ title: line.title,
475
+ kind: line.kind,
476
+ domainTags: line.domainTags,
477
+ })),
478
+ total: filtered.length,
479
+ };
480
+ },
481
+ };
482
+ /** Engram → DigestLine(用于过滤) */
483
+ function engramToDigestLine(engram) {
484
+ return {
485
+ id: engram.id,
486
+ title: engram.title,
487
+ kind: engram.kind,
488
+ kinds: engram.kinds,
489
+ summary: engram.summary,
490
+ domainTags: engram.domainTags,
491
+ contextTags: engram.contextTags,
492
+ importance: engram.importance,
493
+ emotionalValence: engram.emotionalValence,
494
+ freshness: engram.freshness,
495
+ status: engram.status,
496
+ sourceType: engram.sourceType,
497
+ createdBy: engram.createdBy,
498
+ createdAt: engram.createdAt,
499
+ updatedAt: engram.updatedAt,
500
+ lastRetrievedAt: engram.lastRetrievedAt ?? null,
501
+ lastEffectiveAt: engram.lastEffectiveAt ?? null,
502
+ retrievalCount: engram.retrievalCount,
503
+ effectiveRetrievals: engram.effectiveRetrievals,
504
+ failedUses: engram.failedUses,
505
+ reinforcementScore: engram.reinforcementScore,
506
+ decayHalfLifeDays: engram.decayHalfLifeDays,
507
+ contentSize: engram.contentSize,
508
+ contentHash: engram.contentHash,
509
+ outgoingSynapseCount: engram.outgoingSynapseCount,
510
+ incomingSynapseCount: engram.incomingSynapseCount,
511
+ activeContradictionCount: engram.activeContradictionCount,
512
+ };
513
+ }
514
+ /**
515
+ * 写入操作后失效搜索索引,并立即从 repository 重建
516
+ *
517
+ * 之前的实现是 no-op,依赖 host adapter 手动 rebuild,但 host 无从得知何时该 rebuild,
518
+ * 导致用户新建 engram 后立即 engram_search 搜不到(索引是启动时的快照)。
519
+ *
520
+ * 当前实现:用 collectDigestLines(repo) 拉取真实 DigestLine[](含真实 importance /
521
+ * decayHalfLifeDays / retrievalCount / reinforcementScore 等),让三因子打分能正常工作。
522
+ *
523
+ * 代价是每次写入都做一次 O(N) rebuild;N 通常 < 10k,可接受。
524
+ * 后续 P1 改为增量更新(只插入/更新被改动的 engram)。
525
+ */
526
+ function invalidateSearchIndex(ctx) {
527
+ if (!ctx.searchOrchestrator)
528
+ return;
529
+ ctx.searchOrchestrator.build(collectDigestLines(ctx.repository));
530
+ }
531
+ /** 读取 engram,失败时返回 null(不抛) */
532
+ function safeReadEngram(ctx, id) {
533
+ try {
534
+ return ctx.repository.readEngram(id);
535
+ }
536
+ catch {
537
+ return null;
538
+ }
539
+ }
540
+ // ============================================================
541
+ // engram_reinforce(P1:三信号追踪 - 有效检索 LTP)
542
+ // ============================================================
543
+ export const engramReinforceTool = {
544
+ name: "engram_reinforce",
545
+ description: "上报一次有效检索(LTP 强化 + Hebbian 关联强化)。更新 effectiveRetrievals / reinforcementScore / importance(每次 += effectiveness × 0.02,clamp [0,1]);邻居 engram 得到 50% 增益(contradicts 除外)。",
546
+ inputSchema: EngramReinforceInputSchema,
547
+ execute(input, ctx) {
548
+ const parsed = validateInput(EngramReinforceInputSchema, input);
549
+ if (!ctx.repository.exists(parsed.id)) {
550
+ throw new Error(`Engram not found: ${parsed.id}`);
551
+ }
552
+ const nowIso = new Date().toISOString();
553
+ const direct = recordRetrievalSuccess(ctx.repository, parsed.id, parsed.effectiveness, DEFAULT_REINFORCEMENT_CONFIG, nowIso);
554
+ const related = reinforceRelated(ctx.repository, parsed.id, direct.importanceDelta, DEFAULT_REINFORCEMENT_CONFIG, nowIso);
555
+ // M1: 关闭观察窗口并标记为 effective(有效性信号)
556
+ ctx.effectivenessTracker?.closeAsEffective(parsed.id);
557
+ ctx.auditLog?.append({
558
+ actor: "user",
559
+ action: "reinforce",
560
+ engramId: parsed.id,
561
+ metadata: { effectiveness: parsed.effectiveness, note: parsed.note },
562
+ });
563
+ return {
564
+ id: parsed.id,
565
+ retrievalCount: direct.retrievalCount,
566
+ effectiveRetrievals: direct.effectiveRetrievals,
567
+ reinforcementScore: direct.reinforcementScore,
568
+ importance: direct.importance,
569
+ importanceDelta: direct.importanceDelta,
570
+ lastEffectiveAt: direct.lastEffectiveAt,
571
+ reinforcedNeighborIds: related.reinforcedNeighborIds,
572
+ };
573
+ },
574
+ };
575
+ // ============================================================
576
+ // engram_report_failure(P1:三信号追踪 - 失败使用 LTD)
577
+ // ============================================================
578
+ export const engramReportFailureTool = {
579
+ name: "engram_report_failure",
580
+ description: "上报一次失败使用(LTD 削弱)。更新 failedUses / retrievalCount / importance(单次 -0.03,超阈值后 ×1.5 升级)。failedUses≥3 建议 archive,≥5 建议 forget。",
581
+ inputSchema: EngramReportFailureInputSchema,
582
+ execute(input, ctx) {
583
+ const parsed = validateInput(EngramReportFailureInputSchema, input);
584
+ if (!ctx.repository.exists(parsed.id)) {
585
+ throw new Error(`Engram not found: ${parsed.id}`);
586
+ }
587
+ const result = recordRetrievalFailure(ctx.repository, parsed.id, DEFAULT_REINFORCEMENT_CONFIG);
588
+ // M1: 关闭观察窗口(标记为 failure,不再触发 inconclusive)
589
+ ctx.effectivenessTracker?.closeAsFailure(parsed.id);
590
+ ctx.auditLog?.append({
591
+ actor: "user",
592
+ action: "report_failure",
593
+ engramId: parsed.id,
594
+ metadata: { reason: parsed.reason, context: parsed.context },
595
+ });
596
+ return {
597
+ id: parsed.id,
598
+ failedUses: result.failedUses,
599
+ retrievalCount: result.retrievalCount,
600
+ importance: result.importance,
601
+ importanceDelta: result.importanceDelta,
602
+ shouldArchive: result.shouldArchive,
603
+ shouldForget: result.shouldForget,
604
+ };
605
+ },
606
+ };
607
+ // ============================================================
608
+ // engram_archive / restore / forget(P1:生命周期管理)
609
+ // ============================================================
610
+ export const engramArchiveTool = {
611
+ name: "engram_archive",
612
+ description: "归档 engram(移出默认检索,但保留数据可恢复)。检索默认排除 archived,可用 filter 包含。",
613
+ inputSchema: EngramArchiveInputSchema,
614
+ execute(input, ctx) {
615
+ const parsed = validateInput(EngramArchiveInputSchema, input);
616
+ if (!ctx.repository.exists(parsed.id)) {
617
+ throw new Error(`Engram not found: ${parsed.id}`);
618
+ }
619
+ ctx.repository.updateLifecycle(parsed.id, "archived", undefined);
620
+ const updated = ctx.repository.readEngram(parsed.id);
621
+ ctx.auditLog?.append({
622
+ actor: "user",
623
+ action: "update_lifecycle",
624
+ engramId: parsed.id,
625
+ metadata: { to: "archived", reason: parsed.reason },
626
+ });
627
+ return {
628
+ id: parsed.id,
629
+ status: "archived",
630
+ freshness: computeFreshness(updated.lastEffectiveAt, updated.decayHalfLifeDays),
631
+ };
632
+ },
633
+ };
634
+ export const engramRestoreTool = {
635
+ name: "engram_restore",
636
+ description: "从 archived/forgotten 恢复为 active,重新进入默认检索。若 engram 已被 sweep 到 .trash/,会先从回收站移回再恢复。",
637
+ inputSchema: EngramRestoreInputSchema,
638
+ execute(input, ctx) {
639
+ const parsed = validateInput(EngramRestoreInputSchema, input);
640
+ // 双路径查找:先查 active 区,再查 trash
641
+ let restoredFromTrash = false;
642
+ if (!ctx.repository.exists(parsed.id)) {
643
+ const trashResult = restoreFromTrash(ctx.repository, parsed.id, {
644
+ auditLog: ctx.auditLog,
645
+ });
646
+ if (!trashResult.ok) {
647
+ throw new Error(`Engram not found: ${parsed.id} (${trashResult.reason})`);
648
+ }
649
+ restoredFromTrash = true;
650
+ }
651
+ ctx.repository.updateLifecycle(parsed.id, "active", undefined);
652
+ const updated = ctx.repository.readEngram(parsed.id);
653
+ ctx.auditLog?.append({
654
+ actor: "user",
655
+ action: "restore",
656
+ engramId: parsed.id,
657
+ metadata: { reason: parsed.reason },
658
+ });
659
+ return {
660
+ id: parsed.id,
661
+ status: "active",
662
+ freshness: computeFreshness(updated.lastEffectiveAt, updated.decayHalfLifeDays),
663
+ ...(restoredFromTrash ? { restoredFromTrash: true } : {}),
664
+ };
665
+ },
666
+ };
667
+ export const engramForgetTool = {
668
+ name: "engram_forget",
669
+ description: "主动遗忘 engram(RIF 检索诱导遗忘)。文件保留(Git 可追溯)但移出所有默认检索。需要 reason。",
670
+ inputSchema: EngramForgetInputSchema,
671
+ execute(input, ctx) {
672
+ const parsed = validateInput(EngramForgetInputSchema, input);
673
+ if (!ctx.repository.exists(parsed.id)) {
674
+ throw new Error(`Engram not found: ${parsed.id}`);
675
+ }
676
+ ctx.repository.updateLifecycle(parsed.id, "forgotten", "forgotten");
677
+ ctx.auditLog?.append({
678
+ actor: "user",
679
+ action: "forget",
680
+ engramId: parsed.id,
681
+ metadata: { reason: parsed.reason },
682
+ });
683
+ return { id: parsed.id, status: "forgotten", freshness: "forgotten" };
684
+ },
685
+ };
686
+ // ============================================================
687
+ // engram_recompute_importance(P2:多维重要性)
688
+ // ============================================================
689
+ export const engramRecomputeImportanceTool = {
690
+ name: "engram_recompute_importance",
691
+ description: "重新计算 engram 的多维重要性(personal/team/project/network/temporal)。network 和 temporal 由系统派生(incomingSynapseCount + 艾宾浩斯衰退),其余可通过 overrides 手动设置。结果 composite 写回 engram.importance。",
692
+ inputSchema: EngramRecomputeImportanceInputSchema,
693
+ execute(input, ctx) {
694
+ const parsed = validateInput(EngramRecomputeImportanceInputSchema, input);
695
+ const result = recomputeImportance(ctx.repository, parsed.id, {
696
+ overrides: parsed.overrides,
697
+ persist: parsed.persist,
698
+ updatedBy: parsed.updatedBy,
699
+ });
700
+ return {
701
+ id: result.id,
702
+ previous: result.previous,
703
+ next: result.next,
704
+ persisted: result.persisted,
705
+ };
706
+ },
707
+ };
708
+ // ============================================================
709
+ // contradiction_resolve(P2:spec §3.9 人工裁决)
710
+ // ============================================================
711
+ export const contradictionResolveTool = {
712
+ name: "contradiction_resolve",
713
+ description: "人工裁决一个 contradicts synapse(spec §3.9 阶段 2 人工介入)。必须给 verdict + rationale + resolvedBy。系统会自动把 synapse.resolutionState 标记为 resolved 并记录到 evidence 数组。",
714
+ inputSchema: ContradictionResolveInputSchema,
715
+ execute(input, ctx) {
716
+ const parsed = validateInput(ContradictionResolveInputSchema, input);
717
+ const result = manualResolveContradiction(ctx.repository, {
718
+ fromId: parsed.fromId,
719
+ synapseId: parsed.synapseId,
720
+ verdict: parsed.verdict,
721
+ rationale: parsed.rationale,
722
+ resolvedBy: parsed.resolvedBy,
723
+ });
724
+ return {
725
+ fromId: parsed.fromId,
726
+ synapseId: parsed.synapseId,
727
+ status: result.finalStatus,
728
+ resolved: true,
729
+ };
730
+ },
731
+ };
732
+ // ============================================================
733
+ // close_learning_loop(P2:闭合学习回路,spec §5.3.5)
734
+ // ============================================================
735
+ export const closeLearningLoopTool = {
736
+ name: "close_learning_loop",
737
+ description: "闭合学习回路(多巴胺闭环):把使用结果反馈到系统。success/partial → LTP 强化 + Hebbian 邻居强化;failure → LTD 削弱 + 触发降级阈值检查。同步触发 Provenance 奖惩回路(如已配置)。",
738
+ inputSchema: CloseLearningLoopInputSchema,
739
+ execute(input, ctx) {
740
+ const parsed = validateInput(CloseLearningLoopInputSchema, input);
741
+ const result = closeLearningLoop(ctx.repository, {
742
+ engramId: parsed.engramId,
743
+ outcome: parsed.outcome,
744
+ effectiveness: parsed.effectiveness,
745
+ reason: parsed.reason,
746
+ reportedBy: parsed.reportedBy,
747
+ });
748
+ return {
749
+ engramId: result.engramId,
750
+ outcome: result.outcome,
751
+ importance: result.importance,
752
+ importanceDelta: result.importanceDelta,
753
+ hebbianTriggered: result.hebbianReinforcement.triggered,
754
+ provenanceTriggered: result.provenanceUpdate.triggered,
755
+ shouldArchive: result.shouldArchive,
756
+ shouldForget: result.shouldForget,
757
+ };
758
+ },
759
+ };
760
+ // ============================================================
761
+ // upgrade_verification(P3 4.5.3:验证状态升级)
762
+ // ============================================================
763
+ export const upgradeVerificationTool = {
764
+ name: "upgrade_verification",
765
+ description: "升级 engram 的验证状态(unverified → plausible → probable → verified → refuted)。必须给出证据说明 + 验证人。系统会校验状态机(不允许跳级)+ 三维证据条件(evidenceCount + 跨情境 domainTags + 时间稳定天数)。force=true 可跳过条件检查但保留状态机校验(人工裁决场景)。",
766
+ inputSchema: UpgradeVerificationInputSchema,
767
+ execute(input, ctx) {
768
+ const parsed = validateInput(UpgradeVerificationInputSchema, input);
769
+ const result = upgradeVerification(ctx.repository, parsed.engramId, parsed.newStatus, {
770
+ description: parsed.evidenceDescription,
771
+ verifiedBy: parsed.verifiedBy,
772
+ confidence: parsed.confidence,
773
+ domainTags: parsed.evidenceDomainTags,
774
+ }, {
775
+ force: parsed.force,
776
+ });
777
+ return {
778
+ engramId: result.engramId,
779
+ previousStatus: result.previousStatus,
780
+ newStatus: result.newStatus,
781
+ eligible: result.eligible,
782
+ applied: result.applied,
783
+ evidenceAppended: result.evidenceAppended,
784
+ synapseIds: result.synapseIds,
785
+ reason: result.reason,
786
+ checks: result.checks,
787
+ };
788
+ },
789
+ };
790
+ // ============================================================
791
+ // get_evolution_lineage(P3 4.6.3:进化血统追溯)
792
+ // ============================================================
793
+ export const getEvolutionLineageTool = {
794
+ name: "get_evolution_lineage",
795
+ description: "追溯 engram 的进化血统(spec §12.7 场景 6)。沿 derives_from / consolidates / supersedes synapse 双向追溯:ancestors = 来源(observation 等),descendants = 演化结果(pattern/procedure 等)。返回 DAG 节点和边,可用于 Graph View 可视化。spec §4.6 验收:从 Skill 可反向追溯到原 observation 的完整链路。",
796
+ inputSchema: GetEvolutionLineageInputSchema,
797
+ execute(input, ctx) {
798
+ const parsed = validateInput(GetEvolutionLineageInputSchema, input);
799
+ const lineage = getEvolutionLineage(ctx.repository, parsed.engramId, {
800
+ direction: parsed.direction,
801
+ maxDepth: parsed.maxDepth,
802
+ kinds: parsed.kinds,
803
+ });
804
+ return {
805
+ rootId: lineage.rootId,
806
+ nodes: lineage.nodes,
807
+ edges: lineage.edges,
808
+ maxDepth: lineage.maxDepth,
809
+ totalNodes: lineage.totalNodes,
810
+ origins: lineage.origins,
811
+ terminals: lineage.terminals,
812
+ hasCycle: lineage.hasCycle,
813
+ };
814
+ },
815
+ };
816
+ export const ALL_ENGRAM_TOOLS = [
817
+ engramCreateTool,
818
+ engramGetTool,
819
+ engramUpdateTool,
820
+ engramDeleteTool,
821
+ engramSearchTool,
822
+ engramListTool,
823
+ engramReinforceTool,
824
+ engramReportFailureTool,
825
+ engramArchiveTool,
826
+ engramRestoreTool,
827
+ engramForgetTool,
828
+ engramRecomputeImportanceTool,
829
+ contradictionResolveTool,
830
+ closeLearningLoopTool,
831
+ upgradeVerificationTool,
832
+ getEvolutionLineageTool,
833
+ ];
834
+ //# sourceMappingURL=engram-tools.js.map