cognitive-core 0.2.5 → 0.3.1

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 (1279) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +88 -143
  3. package/dist/agents/mock-provider.d.ts.map +1 -1
  4. package/dist/agents/mock-provider.js.map +1 -1
  5. package/dist/agents/types.d.ts.map +1 -1
  6. package/dist/agents/types.js +5 -4
  7. package/dist/agents/types.js.map +1 -1
  8. package/dist/atlas.d.ts +309 -97
  9. package/dist/atlas.d.ts.map +1 -1
  10. package/dist/atlas.js +743 -277
  11. package/dist/atlas.js.map +1 -1
  12. package/dist/bin/cli-utils.d.ts +25 -2
  13. package/dist/bin/cli-utils.d.ts.map +1 -1
  14. package/dist/bin/cli-utils.js +79 -9
  15. package/dist/bin/cli-utils.js.map +1 -1
  16. package/dist/bin/cognitive-core.js +32 -0
  17. package/dist/bin/cognitive-core.js.map +1 -1
  18. package/dist/bin/commands/dream.d.ts +17 -0
  19. package/dist/bin/commands/dream.d.ts.map +1 -0
  20. package/dist/bin/commands/dream.js +168 -0
  21. package/dist/bin/commands/dream.js.map +1 -0
  22. package/dist/bin/commands/eval.d.ts +181 -0
  23. package/dist/bin/commands/eval.d.ts.map +1 -0
  24. package/dist/bin/commands/eval.js +1582 -0
  25. package/dist/bin/commands/eval.js.map +1 -0
  26. package/dist/bin/commands/kb.js +0 -8
  27. package/dist/bin/commands/kb.js.map +1 -1
  28. package/dist/bin/commands/learn.js +12 -4
  29. package/dist/bin/commands/learn.js.map +1 -1
  30. package/dist/bin/commands/legacy.d.ts.map +1 -1
  31. package/dist/bin/commands/legacy.js +1 -1
  32. package/dist/bin/commands/legacy.js.map +1 -1
  33. package/dist/bin/commands/run.d.ts.map +1 -1
  34. package/dist/bin/commands/run.js +10 -9
  35. package/dist/bin/commands/run.js.map +1 -1
  36. package/dist/bin/commands/sessions.d.ts.map +1 -1
  37. package/dist/bin/commands/sessions.js.map +1 -1
  38. package/dist/bin/commands/skills.d.ts.map +1 -1
  39. package/dist/bin/commands/skills.js +283 -1
  40. package/dist/bin/commands/skills.js.map +1 -1
  41. package/dist/embeddings/bm25.d.ts.map +1 -1
  42. package/dist/embeddings/bm25.js +1 -2
  43. package/dist/embeddings/bm25.js.map +1 -1
  44. package/dist/embeddings/index.d.ts +3 -3
  45. package/dist/embeddings/index.d.ts.map +1 -1
  46. package/dist/embeddings/index.js +3 -3
  47. package/dist/embeddings/index.js.map +1 -1
  48. package/dist/embeddings/inverted-index.js +62 -7
  49. package/dist/embeddings/inverted-index.js.map +1 -1
  50. package/dist/embeddings/manager.d.ts.map +1 -1
  51. package/dist/embeddings/manager.js +6 -5
  52. package/dist/embeddings/manager.js.map +1 -1
  53. package/dist/embeddings/provider.d.ts +96 -5
  54. package/dist/embeddings/provider.d.ts.map +1 -1
  55. package/dist/embeddings/provider.js +171 -48
  56. package/dist/embeddings/provider.js.map +1 -1
  57. package/dist/embeddings/vector-store.d.ts.map +1 -1
  58. package/dist/embeddings/vector-store.js +3 -1
  59. package/dist/embeddings/vector-store.js.map +1 -1
  60. package/dist/eval/ablation-validate.d.ts +12 -0
  61. package/dist/eval/ablation-validate.d.ts.map +1 -0
  62. package/dist/eval/ablation-validate.js +78 -0
  63. package/dist/eval/ablation-validate.js.map +1 -0
  64. package/dist/eval/ablation.d.ts +94 -0
  65. package/dist/eval/ablation.d.ts.map +1 -0
  66. package/dist/eval/ablation.js +161 -0
  67. package/dist/eval/ablation.js.map +1 -0
  68. package/dist/eval/ci-smoke.d.ts +11 -0
  69. package/dist/eval/ci-smoke.d.ts.map +1 -0
  70. package/dist/eval/ci-smoke.js +49 -0
  71. package/dist/eval/ci-smoke.js.map +1 -0
  72. package/dist/eval/diagnostics.d.ts +214 -0
  73. package/dist/eval/diagnostics.d.ts.map +1 -0
  74. package/dist/eval/diagnostics.js +107 -0
  75. package/dist/eval/diagnostics.js.map +1 -0
  76. package/dist/eval/index.d.ts +27 -0
  77. package/dist/eval/index.d.ts.map +1 -0
  78. package/dist/eval/index.js +27 -0
  79. package/dist/eval/index.js.map +1 -0
  80. package/dist/eval/live/alfworld.d.ts +248 -0
  81. package/dist/eval/live/alfworld.d.ts.map +1 -0
  82. package/dist/eval/live/alfworld.js +637 -0
  83. package/dist/eval/live/alfworld.js.map +1 -0
  84. package/dist/eval/live/alfworld_h1.d.ts +16 -0
  85. package/dist/eval/live/alfworld_h1.d.ts.map +1 -0
  86. package/dist/eval/live/alfworld_h1.js +75 -0
  87. package/dist/eval/live/alfworld_h1.js.map +1 -0
  88. package/dist/eval/live/alfworld_memory.d.ts +38 -0
  89. package/dist/eval/live/alfworld_memory.d.ts.map +1 -0
  90. package/dist/eval/live/alfworld_memory.js +184 -0
  91. package/dist/eval/live/alfworld_memory.js.map +1 -0
  92. package/dist/eval/live/alfworld_strategy.d.ts +65 -0
  93. package/dist/eval/live/alfworld_strategy.d.ts.map +1 -0
  94. package/dist/eval/live/alfworld_strategy.js +89 -0
  95. package/dist/eval/live/alfworld_strategy.js.map +1 -0
  96. package/dist/eval/live/azure-openai-llm-provider.d.ts +41 -0
  97. package/dist/eval/live/azure-openai-llm-provider.d.ts.map +1 -0
  98. package/dist/eval/live/azure-openai-llm-provider.js +92 -0
  99. package/dist/eval/live/azure-openai-llm-provider.js.map +1 -0
  100. package/dist/eval/live/bridges/skillflow_e2b_bridge.d.ts +3 -0
  101. package/dist/eval/live/bridges/skillflow_e2b_bridge.d.ts.map +1 -0
  102. package/dist/eval/live/bridges/skillflow_e2b_bridge.js +12 -0
  103. package/dist/eval/live/bridges/skillflow_e2b_bridge.js.map +1 -0
  104. package/dist/eval/live/claude-cli-llm-provider.d.ts +53 -0
  105. package/dist/eval/live/claude-cli-llm-provider.d.ts.map +1 -0
  106. package/dist/eval/live/claude-cli-llm-provider.js +71 -0
  107. package/dist/eval/live/claude-cli-llm-provider.js.map +1 -0
  108. package/dist/eval/live/claude-cli.d.ts +96 -0
  109. package/dist/eval/live/claude-cli.d.ts.map +1 -0
  110. package/dist/eval/live/claude-cli.js +314 -0
  111. package/dist/eval/live/claude-cli.js.map +1 -0
  112. package/dist/eval/live/claude-delegate.d.ts +41 -0
  113. package/dist/eval/live/claude-delegate.d.ts.map +1 -0
  114. package/dist/eval/live/claude-delegate.js +59 -0
  115. package/dist/eval/live/claude-delegate.js.map +1 -0
  116. package/dist/eval/live/claude-workspace-backend.d.ts +24 -0
  117. package/dist/eval/live/claude-workspace-backend.d.ts.map +1 -0
  118. package/dist/eval/live/claude-workspace-backend.js +76 -0
  119. package/dist/eval/live/claude-workspace-backend.js.map +1 -0
  120. package/dist/eval/live/clbench.d.ts +64 -0
  121. package/dist/eval/live/clbench.d.ts.map +1 -0
  122. package/dist/eval/live/clbench.js +291 -0
  123. package/dist/eval/live/clbench.js.map +1 -0
  124. package/dist/eval/live/cold-reuse.d.ts +21 -0
  125. package/dist/eval/live/cold-reuse.d.ts.map +1 -0
  126. package/dist/eval/live/cold-reuse.js +102 -0
  127. package/dist/eval/live/cold-reuse.js.map +1 -0
  128. package/dist/eval/live/difficulty-registry.d.ts +68 -0
  129. package/dist/eval/live/difficulty-registry.d.ts.map +1 -0
  130. package/dist/eval/live/difficulty-registry.js +169 -0
  131. package/dist/eval/live/difficulty-registry.js.map +1 -0
  132. package/dist/eval/live/docker.d.ts +52 -0
  133. package/dist/eval/live/docker.d.ts.map +1 -0
  134. package/dist/eval/live/docker.js +164 -0
  135. package/dist/eval/live/docker.js.map +1 -0
  136. package/dist/eval/live/env-bridge.d.ts +68 -0
  137. package/dist/eval/live/env-bridge.d.ts.map +1 -0
  138. package/dist/eval/live/env-bridge.js +188 -0
  139. package/dist/eval/live/env-bridge.js.map +1 -0
  140. package/dist/eval/live/gsm8k.d.ts +44 -0
  141. package/dist/eval/live/gsm8k.d.ts.map +1 -0
  142. package/dist/eval/live/gsm8k.js +142 -0
  143. package/dist/eval/live/gsm8k.js.map +1 -0
  144. package/dist/eval/live/index.d.ts +38 -0
  145. package/dist/eval/live/index.d.ts.map +1 -0
  146. package/dist/eval/live/index.js +38 -0
  147. package/dist/eval/live/index.js.map +1 -0
  148. package/dist/eval/live/lifelongagent.d.ts +64 -0
  149. package/dist/eval/live/lifelongagent.d.ts.map +1 -0
  150. package/dist/eval/live/lifelongagent.js +216 -0
  151. package/dist/eval/live/lifelongagent.js.map +1 -0
  152. package/dist/eval/live/lift-registry.d.ts +128 -0
  153. package/dist/eval/live/lift-registry.d.ts.map +1 -0
  154. package/dist/eval/live/lift-registry.js +147 -0
  155. package/dist/eval/live/lift-registry.js.map +1 -0
  156. package/dist/eval/live/live-benchmark.d.ts +84 -0
  157. package/dist/eval/live/live-benchmark.d.ts.map +1 -0
  158. package/dist/eval/live/live-benchmark.js +2 -0
  159. package/dist/eval/live/live-benchmark.js.map +1 -0
  160. package/dist/eval/live/live-runner.d.ts +609 -0
  161. package/dist/eval/live/live-runner.d.ts.map +1 -0
  162. package/dist/eval/live/live-runner.js +1409 -0
  163. package/dist/eval/live/live-runner.js.map +1 -0
  164. package/dist/eval/live/refine.d.ts +88 -0
  165. package/dist/eval/live/refine.d.ts.map +1 -0
  166. package/dist/eval/live/refine.js +135 -0
  167. package/dist/eval/live/refine.js.map +1 -0
  168. package/dist/eval/live/registry-store.d.ts +109 -0
  169. package/dist/eval/live/registry-store.d.ts.map +1 -0
  170. package/dist/eval/live/registry-store.js +272 -0
  171. package/dist/eval/live/registry-store.js.map +1 -0
  172. package/dist/eval/live/run-checkpoint.d.ts +55 -0
  173. package/dist/eval/live/run-checkpoint.d.ts.map +1 -0
  174. package/dist/eval/live/run-checkpoint.js +86 -0
  175. package/dist/eval/live/run-checkpoint.js.map +1 -0
  176. package/dist/eval/live/run-resume.d.ts +22 -0
  177. package/dist/eval/live/run-resume.d.ts.map +1 -0
  178. package/dist/eval/live/run-resume.js +70 -0
  179. package/dist/eval/live/run-resume.js.map +1 -0
  180. package/dist/eval/live/skill-injector.d.ts +36 -0
  181. package/dist/eval/live/skill-injector.d.ts.map +1 -0
  182. package/dist/eval/live/skill-injector.js +81 -0
  183. package/dist/eval/live/skill-injector.js.map +1 -0
  184. package/dist/eval/live/skillflow-embedded-workbook-bundle.d.ts +3 -0
  185. package/dist/eval/live/skillflow-embedded-workbook-bundle.d.ts.map +1 -0
  186. package/dist/eval/live/skillflow-embedded-workbook-bundle.js +391 -0
  187. package/dist/eval/live/skillflow-embedded-workbook-bundle.js.map +1 -0
  188. package/dist/eval/live/skillflow.d.ts +154 -0
  189. package/dist/eval/live/skillflow.d.ts.map +1 -0
  190. package/dist/eval/live/skillflow.js +612 -0
  191. package/dist/eval/live/skillflow.js.map +1 -0
  192. package/dist/eval/live/skilllearnbench.d.ts +43 -0
  193. package/dist/eval/live/skilllearnbench.d.ts.map +1 -0
  194. package/dist/eval/live/skilllearnbench.js +154 -0
  195. package/dist/eval/live/skilllearnbench.js.map +1 -0
  196. package/dist/eval/live/skillopt_v1.d.ts +96 -0
  197. package/dist/eval/live/skillopt_v1.d.ts.map +1 -0
  198. package/dist/eval/live/skillopt_v1.js +0 -0
  199. package/dist/eval/live/skillopt_v1.js.map +1 -0
  200. package/dist/eval/live/skillopt_v1_causal.d.ts +26 -0
  201. package/dist/eval/live/skillopt_v1_causal.d.ts.map +1 -0
  202. package/dist/eval/live/skillopt_v1_causal.js +106 -0
  203. package/dist/eval/live/skillopt_v1_causal.js.map +1 -0
  204. package/dist/eval/live/skillopt_v1_memory.d.ts +53 -0
  205. package/dist/eval/live/skillopt_v1_memory.d.ts.map +1 -0
  206. package/dist/eval/live/skillopt_v1_memory.js +147 -0
  207. package/dist/eval/live/skillopt_v1_memory.js.map +1 -0
  208. package/dist/eval/live/skillopt_v1_rules.d.ts +39 -0
  209. package/dist/eval/live/skillopt_v1_rules.d.ts.map +1 -0
  210. package/dist/eval/live/skillopt_v1_rules.js +91 -0
  211. package/dist/eval/live/skillopt_v1_rules.js.map +1 -0
  212. package/dist/eval/live/skillsbench.d.ts +138 -0
  213. package/dist/eval/live/skillsbench.d.ts.map +1 -0
  214. package/dist/eval/live/skillsbench.js +626 -0
  215. package/dist/eval/live/skillsbench.js.map +1 -0
  216. package/dist/eval/live/stopping.d.ts +69 -0
  217. package/dist/eval/live/stopping.d.ts.map +1 -0
  218. package/dist/eval/live/stopping.js +213 -0
  219. package/dist/eval/live/stopping.js.map +1 -0
  220. package/dist/eval/live/trace.d.ts +20 -0
  221. package/dist/eval/live/trace.d.ts.map +1 -0
  222. package/dist/eval/live/trace.js +41 -0
  223. package/dist/eval/live/trace.js.map +1 -0
  224. package/dist/eval/mechanism-trace-adapter.d.ts +8 -0
  225. package/dist/eval/mechanism-trace-adapter.d.ts.map +1 -0
  226. package/dist/eval/mechanism-trace-adapter.js +118 -0
  227. package/dist/eval/mechanism-trace-adapter.js.map +1 -0
  228. package/dist/eval/memory-ab.d.ts +61 -0
  229. package/dist/eval/memory-ab.d.ts.map +1 -0
  230. package/dist/eval/memory-ab.js +161 -0
  231. package/dist/eval/memory-ab.js.map +1 -0
  232. package/dist/eval/memory-mock.d.ts +54 -0
  233. package/dist/eval/memory-mock.d.ts.map +1 -0
  234. package/dist/eval/memory-mock.js +129 -0
  235. package/dist/eval/memory-mock.js.map +1 -0
  236. package/dist/eval/memory-qa/index.d.ts +13 -0
  237. package/dist/eval/memory-qa/index.d.ts.map +1 -0
  238. package/dist/eval/memory-qa/index.js +13 -0
  239. package/dist/eval/memory-qa/index.js.map +1 -0
  240. package/dist/eval/memory-qa/iterative.d.ts +80 -0
  241. package/dist/eval/memory-qa/iterative.d.ts.map +1 -0
  242. package/dist/eval/memory-qa/iterative.js +107 -0
  243. package/dist/eval/memory-qa/iterative.js.map +1 -0
  244. package/dist/eval/memory-qa/loaders.d.ts +11 -0
  245. package/dist/eval/memory-qa/loaders.d.ts.map +1 -0
  246. package/dist/eval/memory-qa/loaders.js +21 -0
  247. package/dist/eval/memory-qa/loaders.js.map +1 -0
  248. package/dist/eval/memory-qa/metrics.d.ts +3 -0
  249. package/dist/eval/memory-qa/metrics.d.ts.map +1 -0
  250. package/dist/eval/memory-qa/metrics.js +2 -0
  251. package/dist/eval/memory-qa/metrics.js.map +1 -0
  252. package/dist/eval/memory-qa/qa.d.ts +186 -0
  253. package/dist/eval/memory-qa/qa.d.ts.map +1 -0
  254. package/dist/eval/memory-qa/qa.js +424 -0
  255. package/dist/eval/memory-qa/qa.js.map +1 -0
  256. package/dist/eval/memory-qa/retrieval.d.ts +33 -0
  257. package/dist/eval/memory-qa/retrieval.d.ts.map +1 -0
  258. package/dist/eval/memory-qa/retrieval.js +44 -0
  259. package/dist/eval/memory-qa/retrieval.js.map +1 -0
  260. package/dist/eval/memory-qa/serving.d.ts +60 -0
  261. package/dist/eval/memory-qa/serving.d.ts.map +1 -0
  262. package/dist/eval/memory-qa/serving.js +267 -0
  263. package/dist/eval/memory-qa/serving.js.map +1 -0
  264. package/dist/eval/memory-qa/types.d.ts +2 -0
  265. package/dist/eval/memory-qa/types.d.ts.map +1 -0
  266. package/dist/eval/memory-qa/types.js +2 -0
  267. package/dist/eval/memory-qa/types.js.map +1 -0
  268. package/dist/eval/metrics.d.ts +120 -0
  269. package/dist/eval/metrics.d.ts.map +1 -0
  270. package/dist/eval/metrics.js +361 -0
  271. package/dist/eval/metrics.js.map +1 -0
  272. package/dist/eval/oracle-smoke.d.ts +75 -0
  273. package/dist/eval/oracle-smoke.d.ts.map +1 -0
  274. package/dist/eval/oracle-smoke.js +143 -0
  275. package/dist/eval/oracle-smoke.js.map +1 -0
  276. package/dist/eval/playbook-calibration-report.d.ts +40 -0
  277. package/dist/eval/playbook-calibration-report.d.ts.map +1 -0
  278. package/dist/eval/playbook-calibration-report.js +246 -0
  279. package/dist/eval/playbook-calibration-report.js.map +1 -0
  280. package/dist/eval/playbook-candidate-decisions-report.d.ts +36 -0
  281. package/dist/eval/playbook-candidate-decisions-report.d.ts.map +1 -0
  282. package/dist/eval/playbook-candidate-decisions-report.js +201 -0
  283. package/dist/eval/playbook-candidate-decisions-report.js.map +1 -0
  284. package/dist/eval/playbook-usage-report.d.ts +7 -0
  285. package/dist/eval/playbook-usage-report.d.ts.map +1 -0
  286. package/dist/eval/playbook-usage-report.js +222 -0
  287. package/dist/eval/playbook-usage-report.js.map +1 -0
  288. package/dist/eval/report.d.ts +28 -0
  289. package/dist/eval/report.d.ts.map +1 -0
  290. package/dist/eval/report.js +567 -0
  291. package/dist/eval/report.js.map +1 -0
  292. package/dist/eval/retrieval/corpus.d.ts +41 -0
  293. package/dist/eval/retrieval/corpus.d.ts.map +1 -0
  294. package/dist/eval/retrieval/corpus.js +158 -0
  295. package/dist/eval/retrieval/corpus.js.map +1 -0
  296. package/dist/eval/retrieval/index.d.ts +12 -0
  297. package/dist/eval/retrieval/index.d.ts.map +1 -0
  298. package/dist/eval/retrieval/index.js +14 -0
  299. package/dist/eval/retrieval/index.js.map +1 -0
  300. package/dist/eval/retrieval/knowledge-corpus.d.ts +91 -0
  301. package/dist/eval/retrieval/knowledge-corpus.d.ts.map +1 -0
  302. package/dist/eval/retrieval/knowledge-corpus.js +268 -0
  303. package/dist/eval/retrieval/knowledge-corpus.js.map +1 -0
  304. package/dist/eval/retrieval/knowledge-quality.d.ts +91 -0
  305. package/dist/eval/retrieval/knowledge-quality.d.ts.map +1 -0
  306. package/dist/eval/retrieval/knowledge-quality.js +247 -0
  307. package/dist/eval/retrieval/knowledge-quality.js.map +1 -0
  308. package/dist/eval/retrieval/ladder.d.ts +69 -0
  309. package/dist/eval/retrieval/ladder.d.ts.map +1 -0
  310. package/dist/eval/retrieval/ladder.js +80 -0
  311. package/dist/eval/retrieval/ladder.js.map +1 -0
  312. package/dist/eval/retrieval/quality.d.ts +39 -0
  313. package/dist/eval/retrieval/quality.d.ts.map +1 -0
  314. package/dist/eval/retrieval/quality.js +75 -0
  315. package/dist/eval/retrieval/quality.js.map +1 -0
  316. package/dist/eval/rng.d.ts +25 -0
  317. package/dist/eval/rng.d.ts.map +1 -0
  318. package/dist/eval/rng.js +43 -0
  319. package/dist/eval/rng.js.map +1 -0
  320. package/dist/eval/runner.d.ts +65 -0
  321. package/dist/eval/runner.d.ts.map +1 -0
  322. package/dist/eval/runner.js +216 -0
  323. package/dist/eval/runner.js.map +1 -0
  324. package/dist/eval/skill-bundle.d.ts +18 -0
  325. package/dist/eval/skill-bundle.d.ts.map +1 -0
  326. package/dist/eval/skill-bundle.js +38 -0
  327. package/dist/eval/skill-bundle.js.map +1 -0
  328. package/dist/eval/swarmkit-report.d.ts +21 -0
  329. package/dist/eval/swarmkit-report.d.ts.map +1 -0
  330. package/dist/eval/swarmkit-report.js +93 -0
  331. package/dist/eval/swarmkit-report.js.map +1 -0
  332. package/dist/eval/task-stream.d.ts +22 -0
  333. package/dist/eval/task-stream.d.ts.map +1 -0
  334. package/dist/eval/task-stream.js +99 -0
  335. package/dist/eval/task-stream.js.map +1 -0
  336. package/dist/eval/types.d.ts +173 -0
  337. package/dist/eval/types.d.ts.map +1 -0
  338. package/dist/eval/types.js +11 -0
  339. package/dist/eval/types.js.map +1 -0
  340. package/dist/experimental/causal-store.d.ts +97 -0
  341. package/dist/experimental/causal-store.d.ts.map +1 -0
  342. package/dist/experimental/causal-store.js +213 -0
  343. package/dist/experimental/causal-store.js.map +1 -0
  344. package/dist/experimental/graph-layers/base.d.ts +29 -0
  345. package/dist/experimental/graph-layers/base.d.ts.map +1 -0
  346. package/dist/experimental/graph-layers/base.js +143 -0
  347. package/dist/experimental/graph-layers/base.js.map +1 -0
  348. package/dist/experimental/graph-layers/causal.d.ts +14 -0
  349. package/dist/experimental/graph-layers/causal.d.ts.map +1 -0
  350. package/dist/experimental/graph-layers/causal.js +14 -0
  351. package/dist/experimental/graph-layers/causal.js.map +1 -0
  352. package/dist/experimental/graph-layers/entity.d.ts +14 -0
  353. package/dist/experimental/graph-layers/entity.d.ts.map +1 -0
  354. package/dist/experimental/graph-layers/entity.js +14 -0
  355. package/dist/experimental/graph-layers/entity.js.map +1 -0
  356. package/dist/experimental/graph-layers/index.d.ts +6 -0
  357. package/dist/experimental/graph-layers/index.d.ts.map +1 -0
  358. package/dist/experimental/graph-layers/index.js +6 -0
  359. package/dist/experimental/graph-layers/index.js.map +1 -0
  360. package/dist/experimental/graph-layers/semantic.d.ts +14 -0
  361. package/dist/experimental/graph-layers/semantic.d.ts.map +1 -0
  362. package/dist/experimental/graph-layers/semantic.js +14 -0
  363. package/dist/experimental/graph-layers/semantic.js.map +1 -0
  364. package/dist/experimental/graph-layers/temporal.d.ts +14 -0
  365. package/dist/experimental/graph-layers/temporal.d.ts.map +1 -0
  366. package/dist/experimental/graph-layers/temporal.js +14 -0
  367. package/dist/experimental/graph-layers/temporal.js.map +1 -0
  368. package/dist/experimental/healing-orchestrator.d.ts +182 -0
  369. package/dist/experimental/healing-orchestrator.d.ts.map +1 -0
  370. package/dist/experimental/healing-orchestrator.js +250 -0
  371. package/dist/experimental/healing-orchestrator.js.map +1 -0
  372. package/dist/experimental/knowledge-graph-types.d.ts +148 -0
  373. package/dist/experimental/knowledge-graph-types.d.ts.map +1 -0
  374. package/dist/experimental/knowledge-graph-types.js +40 -0
  375. package/dist/experimental/knowledge-graph-types.js.map +1 -0
  376. package/dist/experimental/knowledge-graph.d.ts +41 -0
  377. package/dist/experimental/knowledge-graph.d.ts.map +1 -0
  378. package/dist/experimental/knowledge-graph.js +270 -0
  379. package/dist/experimental/knowledge-graph.js.map +1 -0
  380. package/dist/experimental/meta-reflection.d.ts +47 -0
  381. package/dist/experimental/meta-reflection.d.ts.map +1 -0
  382. package/dist/experimental/meta-reflection.js +143 -0
  383. package/dist/experimental/meta-reflection.js.map +1 -0
  384. package/dist/experimental/moe-gate.d.ts +134 -0
  385. package/dist/experimental/moe-gate.d.ts.map +1 -0
  386. package/dist/experimental/moe-gate.js +240 -0
  387. package/dist/experimental/moe-gate.js.map +1 -0
  388. package/dist/experimental/reasoning-bank.d.ts +130 -0
  389. package/dist/experimental/reasoning-bank.d.ts.map +1 -0
  390. package/dist/experimental/reasoning-bank.js +427 -0
  391. package/dist/experimental/reasoning-bank.js.map +1 -0
  392. package/dist/experimental/team/team-config.d.ts +127 -0
  393. package/dist/experimental/team/team-config.d.ts.map +1 -0
  394. package/dist/experimental/team/team-config.js +48 -0
  395. package/dist/experimental/team/team-config.js.map +1 -0
  396. package/dist/experimental/team/team-experience.d.ts +300 -0
  397. package/dist/experimental/team/team-experience.d.ts.map +1 -0
  398. package/dist/experimental/team/team-experience.js +355 -0
  399. package/dist/experimental/team/team-experience.js.map +1 -0
  400. package/dist/experimental/team/team-ingester.d.ts +152 -0
  401. package/dist/experimental/team/team-ingester.d.ts.map +1 -0
  402. package/dist/experimental/team/team-ingester.js +330 -0
  403. package/dist/experimental/team/team-ingester.js.map +1 -0
  404. package/dist/experimental/team/team-meta-learner.d.ts +51 -0
  405. package/dist/experimental/team/team-meta-learner.d.ts.map +1 -0
  406. package/dist/experimental/team/team-meta-learner.js +404 -0
  407. package/dist/experimental/team/team-meta-learner.js.map +1 -0
  408. package/dist/experimental/team/team-meta.d.ts +160 -0
  409. package/dist/experimental/team/team-meta.d.ts.map +1 -0
  410. package/dist/experimental/team/team-meta.js +42 -0
  411. package/dist/experimental/team/team-meta.js.map +1 -0
  412. package/dist/experimental/team/team-pipeline.d.ts +77 -0
  413. package/dist/experimental/team/team-pipeline.d.ts.map +1 -0
  414. package/dist/experimental/team/team-pipeline.js +262 -0
  415. package/dist/experimental/team/team-pipeline.js.map +1 -0
  416. package/dist/experimental/team/team-playbook-extraction.d.ts +45 -0
  417. package/dist/experimental/team/team-playbook-extraction.d.ts.map +1 -0
  418. package/dist/experimental/team/team-playbook-extraction.js +526 -0
  419. package/dist/experimental/team/team-playbook-extraction.js.map +1 -0
  420. package/dist/experimental/team/team-playbook.d.ts +276 -0
  421. package/dist/experimental/team/team-playbook.d.ts.map +1 -0
  422. package/dist/experimental/team/team-playbook.js +85 -0
  423. package/dist/experimental/team/team-playbook.js.map +1 -0
  424. package/dist/experimental/team/team-router.d.ts +98 -0
  425. package/dist/experimental/team/team-router.d.ts.map +1 -0
  426. package/dist/experimental/team/team-router.js +312 -0
  427. package/dist/experimental/team/team-router.js.map +1 -0
  428. package/dist/experimental/team/team-skill-library.d.ts +180 -0
  429. package/dist/experimental/team/team-skill-library.d.ts.map +1 -0
  430. package/dist/experimental/team/team-skill-library.js +385 -0
  431. package/dist/experimental/team/team-skill-library.js.map +1 -0
  432. package/dist/experimental/team/team-trajectory-analysis.d.ts +19 -0
  433. package/dist/experimental/team/team-trajectory-analysis.d.ts.map +1 -0
  434. package/dist/experimental/team/team-trajectory-analysis.js +442 -0
  435. package/dist/experimental/team/team-trajectory-analysis.js.map +1 -0
  436. package/dist/experimental/team/team-trajectory.d.ts +305 -0
  437. package/dist/experimental/team/team-trajectory.d.ts.map +1 -0
  438. package/dist/experimental/team/team-trajectory.js +315 -0
  439. package/dist/experimental/team/team-trajectory.js.map +1 -0
  440. package/dist/factory.d.ts +2 -3
  441. package/dist/factory.d.ts.map +1 -1
  442. package/dist/factory.js +12 -11
  443. package/dist/factory.js.map +1 -1
  444. package/dist/index.d.ts +9 -11
  445. package/dist/index.d.ts.map +1 -1
  446. package/dist/index.js +26 -32
  447. package/dist/index.js.map +1 -1
  448. package/dist/learning/analyzer.d.ts +26 -36
  449. package/dist/learning/analyzer.d.ts.map +1 -1
  450. package/dist/learning/analyzer.js +50 -11
  451. package/dist/learning/analyzer.js.map +1 -1
  452. package/dist/learning/compound-bootstrap/external-acquisition.d.ts +63 -0
  453. package/dist/learning/compound-bootstrap/external-acquisition.d.ts.map +1 -0
  454. package/dist/learning/compound-bootstrap/external-acquisition.js +255 -0
  455. package/dist/learning/compound-bootstrap/external-acquisition.js.map +1 -0
  456. package/dist/learning/compound-bootstrap/index.d.ts +3 -0
  457. package/dist/learning/compound-bootstrap/index.d.ts.map +1 -0
  458. package/dist/learning/compound-bootstrap/index.js +3 -0
  459. package/dist/learning/compound-bootstrap/index.js.map +1 -0
  460. package/dist/learning/compound-bootstrap/workspace-analyzer.d.ts +33 -0
  461. package/dist/learning/compound-bootstrap/workspace-analyzer.d.ts.map +1 -0
  462. package/dist/learning/compound-bootstrap/workspace-analyzer.js +379 -0
  463. package/dist/learning/compound-bootstrap/workspace-analyzer.js.map +1 -0
  464. package/dist/learning/consolidation-coordinator.d.ts +49 -0
  465. package/dist/learning/consolidation-coordinator.d.ts.map +1 -0
  466. package/dist/learning/consolidation-coordinator.js +75 -0
  467. package/dist/learning/consolidation-coordinator.js.map +1 -0
  468. package/dist/learning/convention-distiller.d.ts +84 -0
  469. package/dist/learning/convention-distiller.d.ts.map +1 -0
  470. package/dist/learning/convention-distiller.js +268 -0
  471. package/dist/learning/convention-distiller.js.map +1 -0
  472. package/dist/learning/distiller.d.ts +82 -0
  473. package/dist/learning/distiller.d.ts.map +1 -0
  474. package/dist/learning/distiller.js +353 -0
  475. package/dist/learning/distiller.js.map +1 -0
  476. package/dist/learning/effectiveness.d.ts +12 -2
  477. package/dist/learning/effectiveness.d.ts.map +1 -1
  478. package/dist/learning/effectiveness.js +18 -14
  479. package/dist/learning/effectiveness.js.map +1 -1
  480. package/dist/learning/escalation.d.ts +89 -0
  481. package/dist/learning/escalation.d.ts.map +1 -0
  482. package/dist/learning/escalation.js +168 -0
  483. package/dist/learning/escalation.js.map +1 -0
  484. package/dist/learning/external-exposure.d.ts +57 -0
  485. package/dist/learning/external-exposure.d.ts.map +1 -0
  486. package/dist/learning/external-exposure.js +95 -0
  487. package/dist/learning/external-exposure.js.map +1 -0
  488. package/dist/learning/gepa-proposer.d.ts +116 -0
  489. package/dist/learning/gepa-proposer.d.ts.map +1 -0
  490. package/dist/learning/gepa-proposer.js +258 -0
  491. package/dist/learning/gepa-proposer.js.map +1 -0
  492. package/dist/learning/index.d.ts +21 -8
  493. package/dist/learning/index.d.ts.map +1 -1
  494. package/dist/learning/index.js +28 -10
  495. package/dist/learning/index.js.map +1 -1
  496. package/dist/learning/instant-loop.d.ts +46 -16
  497. package/dist/learning/instant-loop.d.ts.map +1 -1
  498. package/dist/learning/instant-loop.js +114 -111
  499. package/dist/learning/instant-loop.js.map +1 -1
  500. package/dist/learning/knowledge-extractor.d.ts.map +1 -1
  501. package/dist/learning/knowledge-extractor.js +1 -2
  502. package/dist/learning/knowledge-extractor.js.map +1 -1
  503. package/dist/learning/llm-extractor.d.ts +88 -0
  504. package/dist/learning/llm-extractor.d.ts.map +1 -0
  505. package/dist/learning/llm-extractor.js +372 -0
  506. package/dist/learning/llm-extractor.js.map +1 -0
  507. package/dist/learning/loop-coordinator.d.ts +61 -0
  508. package/dist/learning/loop-coordinator.d.ts.map +1 -0
  509. package/dist/learning/loop-coordinator.js +96 -0
  510. package/dist/learning/loop-coordinator.js.map +1 -0
  511. package/dist/learning/maintenance-scheduler.d.ts +15 -4
  512. package/dist/learning/maintenance-scheduler.d.ts.map +1 -1
  513. package/dist/learning/maintenance-scheduler.js +19 -16
  514. package/dist/learning/maintenance-scheduler.js.map +1 -1
  515. package/dist/learning/mechanism-trace.d.ts +196 -0
  516. package/dist/learning/mechanism-trace.d.ts.map +1 -0
  517. package/dist/learning/mechanism-trace.js +81 -0
  518. package/dist/learning/mechanism-trace.js.map +1 -0
  519. package/dist/learning/merge-proposer.d.ts +102 -0
  520. package/dist/learning/merge-proposer.d.ts.map +1 -0
  521. package/dist/learning/merge-proposer.js +253 -0
  522. package/dist/learning/merge-proposer.js.map +1 -0
  523. package/dist/learning/meta-learner.d.ts +9 -7
  524. package/dist/learning/meta-learner.d.ts.map +1 -1
  525. package/dist/learning/meta-learner.js +16 -45
  526. package/dist/learning/meta-learner.js.map +1 -1
  527. package/dist/learning/mutation-gate.d.ts +218 -0
  528. package/dist/learning/mutation-gate.d.ts.map +1 -0
  529. package/dist/learning/mutation-gate.js +390 -0
  530. package/dist/learning/mutation-gate.js.map +1 -0
  531. package/dist/learning/oracle-signal.d.ts +67 -0
  532. package/dist/learning/oracle-signal.d.ts.map +1 -0
  533. package/dist/learning/oracle-signal.js +94 -0
  534. package/dist/learning/oracle-signal.js.map +1 -0
  535. package/dist/learning/pipeline.d.ts +116 -0
  536. package/dist/learning/pipeline.d.ts.map +1 -0
  537. package/dist/learning/pipeline.js +288 -0
  538. package/dist/learning/pipeline.js.map +1 -0
  539. package/dist/learning/playbook-extractor.d.ts +8 -0
  540. package/dist/learning/playbook-extractor.d.ts.map +1 -1
  541. package/dist/learning/playbook-extractor.js +119 -34
  542. package/dist/learning/playbook-extractor.js.map +1 -1
  543. package/dist/learning/playbook-optimizer.d.ts +37 -0
  544. package/dist/learning/playbook-optimizer.d.ts.map +1 -0
  545. package/dist/learning/playbook-optimizer.js +125 -0
  546. package/dist/learning/playbook-optimizer.js.map +1 -0
  547. package/dist/learning/reflective-proposer.d.ts +173 -0
  548. package/dist/learning/reflective-proposer.d.ts.map +1 -0
  549. package/dist/learning/reflective-proposer.js +354 -0
  550. package/dist/learning/reflective-proposer.js.map +1 -0
  551. package/dist/learning/reflexion-generator.d.ts.map +1 -1
  552. package/dist/learning/reflexion-generator.js +4 -3
  553. package/dist/learning/reflexion-generator.js.map +1 -1
  554. package/dist/learning/replay-executor.d.ts +64 -0
  555. package/dist/learning/replay-executor.d.ts.map +1 -0
  556. package/dist/learning/replay-executor.js +92 -0
  557. package/dist/learning/replay-executor.js.map +1 -0
  558. package/dist/learning/replay-types.d.ts +150 -0
  559. package/dist/learning/replay-types.d.ts.map +1 -0
  560. package/dist/learning/replay-types.js +207 -0
  561. package/dist/learning/replay-types.js.map +1 -0
  562. package/dist/learning/replay.d.ts +166 -0
  563. package/dist/learning/replay.d.ts.map +1 -0
  564. package/dist/learning/replay.js +228 -0
  565. package/dist/learning/replay.js.map +1 -0
  566. package/dist/learning/seed-report.d.ts +88 -0
  567. package/dist/learning/seed-report.d.ts.map +1 -0
  568. package/dist/learning/seed-report.js +120 -0
  569. package/dist/learning/seed-report.js.map +1 -0
  570. package/dist/learning/trajectory-sources/dataclaw.d.ts.map +1 -1
  571. package/dist/learning/trajectory-sources/dataclaw.js +6 -18
  572. package/dist/learning/trajectory-sources/dataclaw.js.map +1 -1
  573. package/dist/learning/trajectory-sources/entire.d.ts.map +1 -1
  574. package/dist/learning/trajectory-sources/entire.js +30 -9
  575. package/dist/learning/trajectory-sources/entire.js.map +1 -1
  576. package/dist/learning/trajectory-sources/file.d.ts.map +1 -1
  577. package/dist/learning/trajectory-sources/file.js.map +1 -1
  578. package/dist/learning/trajectory-sources/huggingface.d.ts.map +1 -1
  579. package/dist/learning/trajectory-sources/huggingface.js +7 -7
  580. package/dist/learning/trajectory-sources/huggingface.js.map +1 -1
  581. package/dist/learning/trajectory-sources/in-memory.d.ts.map +1 -1
  582. package/dist/learning/trajectory-sources/in-memory.js.map +1 -1
  583. package/dist/learning/trajectory-sources/index.d.ts +3 -4
  584. package/dist/learning/trajectory-sources/index.d.ts.map +1 -1
  585. package/dist/learning/trajectory-sources/index.js +3 -4
  586. package/dist/learning/trajectory-sources/index.js.map +1 -1
  587. package/dist/learning/trajectory-sources/pipeline.d.ts +4 -3
  588. package/dist/learning/trajectory-sources/pipeline.d.ts.map +1 -1
  589. package/dist/learning/trajectory-sources/pipeline.js +4 -3
  590. package/dist/learning/trajectory-sources/pipeline.js.map +1 -1
  591. package/dist/learning/unified-pipeline.d.ts +486 -61
  592. package/dist/learning/unified-pipeline.d.ts.map +1 -1
  593. package/dist/learning/unified-pipeline.js +1501 -232
  594. package/dist/learning/unified-pipeline.js.map +1 -1
  595. package/dist/learning/usage-inference.d.ts.map +1 -1
  596. package/dist/learning/usage-inference.js +4 -9
  597. package/dist/learning/usage-inference.js.map +1 -1
  598. package/dist/learning/workspace-snapshot.d.ts +146 -0
  599. package/dist/learning/workspace-snapshot.d.ts.map +1 -0
  600. package/dist/learning/workspace-snapshot.js +269 -0
  601. package/dist/learning/workspace-snapshot.js.map +1 -0
  602. package/dist/mcp/playbook-server.d.ts +61 -2
  603. package/dist/mcp/playbook-server.d.ts.map +1 -1
  604. package/dist/mcp/playbook-server.js +179 -9
  605. package/dist/mcp/playbook-server.js.map +1 -1
  606. package/dist/memory/coherence.d.ts.map +1 -1
  607. package/dist/memory/coherence.js +5 -7
  608. package/dist/memory/coherence.js.map +1 -1
  609. package/dist/memory/curated-loader.d.ts +24 -0
  610. package/dist/memory/curated-loader.d.ts.map +1 -1
  611. package/dist/memory/curated-loader.js +22 -5
  612. package/dist/memory/curated-loader.js.map +1 -1
  613. package/dist/memory/evolution/llm-evolver.d.ts +36 -0
  614. package/dist/memory/evolution/llm-evolver.d.ts.map +1 -0
  615. package/dist/memory/evolution/llm-evolver.js +106 -0
  616. package/dist/memory/evolution/llm-evolver.js.map +1 -0
  617. package/dist/memory/experience.d.ts +34 -13
  618. package/dist/memory/experience.d.ts.map +1 -1
  619. package/dist/memory/experience.js +59 -48
  620. package/dist/memory/experience.js.map +1 -1
  621. package/dist/memory/extraction/conversation-extractor.d.ts +62 -0
  622. package/dist/memory/extraction/conversation-extractor.d.ts.map +1 -0
  623. package/dist/memory/extraction/conversation-extractor.js +169 -0
  624. package/dist/memory/extraction/conversation-extractor.js.map +1 -0
  625. package/dist/memory/filesystem-cascade.d.ts +116 -0
  626. package/dist/memory/filesystem-cascade.d.ts.map +1 -0
  627. package/dist/memory/filesystem-cascade.js +221 -0
  628. package/dist/memory/filesystem-cascade.js.map +1 -0
  629. package/dist/memory/index.d.ts +14 -10
  630. package/dist/memory/index.d.ts.map +1 -1
  631. package/dist/memory/index.js +15 -12
  632. package/dist/memory/index.js.map +1 -1
  633. package/dist/memory/knowledge-bank.d.ts +145 -29
  634. package/dist/memory/knowledge-bank.d.ts.map +1 -1
  635. package/dist/memory/knowledge-bank.js +511 -200
  636. package/dist/memory/knowledge-bank.js.map +1 -1
  637. package/dist/memory/knowledge-defrag.d.ts +32 -9
  638. package/dist/memory/knowledge-defrag.d.ts.map +1 -1
  639. package/dist/memory/knowledge-defrag.js +57 -49
  640. package/dist/memory/knowledge-defrag.js.map +1 -1
  641. package/dist/memory/meta-playbook-bank.d.ts +24 -0
  642. package/dist/memory/meta-playbook-bank.d.ts.map +1 -0
  643. package/dist/memory/meta-playbook-bank.js +135 -0
  644. package/dist/memory/meta-playbook-bank.js.map +1 -0
  645. package/dist/memory/meta.d.ts.map +1 -1
  646. package/dist/memory/meta.js +33 -14
  647. package/dist/memory/meta.js.map +1 -1
  648. package/dist/memory/playbook-applicability.d.ts +43 -0
  649. package/dist/memory/playbook-applicability.d.ts.map +1 -0
  650. package/dist/memory/playbook-applicability.js +155 -0
  651. package/dist/memory/playbook-applicability.js.map +1 -0
  652. package/dist/memory/playbook-incorporation.d.ts +24 -0
  653. package/dist/memory/playbook-incorporation.d.ts.map +1 -0
  654. package/dist/memory/playbook-incorporation.js +41 -0
  655. package/dist/memory/playbook-incorporation.js.map +1 -0
  656. package/dist/memory/playbook.d.ts +444 -7
  657. package/dist/memory/playbook.d.ts.map +1 -1
  658. package/dist/memory/playbook.js +1231 -50
  659. package/dist/memory/playbook.js.map +1 -1
  660. package/dist/memory/procedural-skill.d.ts +142 -0
  661. package/dist/memory/procedural-skill.d.ts.map +1 -0
  662. package/dist/memory/procedural-skill.js +846 -0
  663. package/dist/memory/procedural-skill.js.map +1 -0
  664. package/dist/memory/search-provider.d.ts +8 -3
  665. package/dist/memory/search-provider.d.ts.map +1 -1
  666. package/dist/memory/search-providers/embedding.d.ts +64 -0
  667. package/dist/memory/search-providers/embedding.d.ts.map +1 -0
  668. package/dist/memory/search-providers/embedding.js +96 -0
  669. package/dist/memory/search-providers/embedding.js.map +1 -0
  670. package/dist/memory/search-providers/hybrid.d.ts +74 -0
  671. package/dist/memory/search-providers/hybrid.d.ts.map +1 -0
  672. package/dist/memory/search-providers/hybrid.js +94 -0
  673. package/dist/memory/search-providers/hybrid.js.map +1 -0
  674. package/dist/memory/search-providers/index.d.ts +3 -0
  675. package/dist/memory/search-providers/index.d.ts.map +1 -1
  676. package/dist/memory/search-providers/index.js +3 -0
  677. package/dist/memory/search-providers/index.js.map +1 -1
  678. package/dist/memory/search-providers/keyword-expanding.d.ts +22 -0
  679. package/dist/memory/search-providers/keyword-expanding.d.ts.map +1 -0
  680. package/dist/memory/search-providers/keyword-expanding.js +35 -0
  681. package/dist/memory/search-providers/keyword-expanding.js.map +1 -0
  682. package/dist/memory/search-providers/minimem.d.ts +16 -4
  683. package/dist/memory/search-providers/minimem.d.ts.map +1 -1
  684. package/dist/memory/search-providers/minimem.js +14 -3
  685. package/dist/memory/search-providers/minimem.js.map +1 -1
  686. package/dist/memory/search-providers/text-similarity.d.ts +2 -4
  687. package/dist/memory/search-providers/text-similarity.d.ts.map +1 -1
  688. package/dist/memory/search-providers/text-similarity.js.map +1 -1
  689. package/dist/memory/seeds/meta-playbook-seeds.d.ts +27 -0
  690. package/dist/memory/seeds/meta-playbook-seeds.d.ts.map +1 -0
  691. package/dist/memory/seeds/meta-playbook-seeds.js +560 -0
  692. package/dist/memory/seeds/meta-playbook-seeds.js.map +1 -0
  693. package/dist/memory/seeds/meta-strategy-seeds.d.ts +23 -0
  694. package/dist/memory/seeds/meta-strategy-seeds.d.ts.map +1 -0
  695. package/dist/memory/seeds/meta-strategy-seeds.js +82 -0
  696. package/dist/memory/seeds/meta-strategy-seeds.js.map +1 -0
  697. package/dist/memory/seeds/seed-loader.d.ts +34 -0
  698. package/dist/memory/seeds/seed-loader.d.ts.map +1 -0
  699. package/dist/memory/seeds/seed-loader.js +60 -0
  700. package/dist/memory/seeds/seed-loader.js.map +1 -0
  701. package/dist/memory/skill-exporter.d.ts.map +1 -1
  702. package/dist/memory/skill-exporter.js +1 -2
  703. package/dist/memory/skill-exporter.js.map +1 -1
  704. package/dist/memory/source-resolver.d.ts.map +1 -1
  705. package/dist/memory/source-resolver.js +7 -8
  706. package/dist/memory/source-resolver.js.map +1 -1
  707. package/dist/memory/system.d.ts +119 -14
  708. package/dist/memory/system.d.ts.map +1 -1
  709. package/dist/memory/system.js +416 -60
  710. package/dist/memory/system.js.map +1 -1
  711. package/dist/memory/temporal-compressor.d.ts +1 -1
  712. package/dist/memory/temporal-compressor.d.ts.map +1 -1
  713. package/dist/memory/temporal-compressor.js +26 -16
  714. package/dist/memory/temporal-compressor.js.map +1 -1
  715. package/dist/persistence/index.d.ts +2 -2
  716. package/dist/persistence/index.d.ts.map +1 -1
  717. package/dist/persistence/index.js +1 -1
  718. package/dist/persistence/index.js.map +1 -1
  719. package/dist/persistence/migrator.d.ts +34 -1
  720. package/dist/persistence/migrator.d.ts.map +1 -1
  721. package/dist/persistence/migrator.js +163 -33
  722. package/dist/persistence/migrator.js.map +1 -1
  723. package/dist/persistence/sqlite-persistence.d.ts +412 -1
  724. package/dist/persistence/sqlite-persistence.d.ts.map +1 -1
  725. package/dist/persistence/sqlite-persistence.js +1038 -47
  726. package/dist/persistence/sqlite-persistence.js.map +1 -1
  727. package/dist/runtime/backends/acp-protocol.d.ts.map +1 -1
  728. package/dist/runtime/backends/acp-protocol.js +2 -1
  729. package/dist/runtime/backends/acp-protocol.js.map +1 -1
  730. package/dist/runtime/backends/acp.d.ts.map +1 -1
  731. package/dist/runtime/backends/acp.js +5 -4
  732. package/dist/runtime/backends/acp.js.map +1 -1
  733. package/dist/runtime/backends/index.d.ts +2 -2
  734. package/dist/runtime/backends/index.d.ts.map +1 -1
  735. package/dist/runtime/backends/index.js +2 -2
  736. package/dist/runtime/backends/index.js.map +1 -1
  737. package/dist/runtime/backends/macro-agent.d.ts +17 -1
  738. package/dist/runtime/backends/macro-agent.d.ts.map +1 -1
  739. package/dist/runtime/backends/macro-agent.js +1 -1
  740. package/dist/runtime/backends/macro-agent.js.map +1 -1
  741. package/dist/runtime/backends/mock.d.ts.map +1 -1
  742. package/dist/runtime/backends/mock.js.map +1 -1
  743. package/dist/runtime/backends/subprocess.d.ts.map +1 -1
  744. package/dist/runtime/backends/subprocess.js +5 -4
  745. package/dist/runtime/backends/subprocess.js.map +1 -1
  746. package/dist/runtime/compute-provider.d.ts +2 -18
  747. package/dist/runtime/compute-provider.d.ts.map +1 -1
  748. package/dist/runtime/compute-provider.js +8 -8
  749. package/dist/runtime/compute-provider.js.map +1 -1
  750. package/dist/runtime/flows/learning.d.ts +2 -1
  751. package/dist/runtime/flows/learning.d.ts.map +1 -1
  752. package/dist/runtime/flows/learning.js +4 -5
  753. package/dist/runtime/flows/learning.js.map +1 -1
  754. package/dist/runtime/flows/validation.d.ts.map +1 -1
  755. package/dist/runtime/flows/validation.js +2 -5
  756. package/dist/runtime/flows/validation.js.map +1 -1
  757. package/dist/runtime/index.d.ts +1 -1
  758. package/dist/runtime/index.d.ts.map +1 -1
  759. package/dist/runtime/index.js.map +1 -1
  760. package/dist/runtime/manager.d.ts +128 -0
  761. package/dist/runtime/manager.d.ts.map +1 -1
  762. package/dist/runtime/manager.js +375 -64
  763. package/dist/runtime/manager.js.map +1 -1
  764. package/dist/runtime/types.d.ts +92 -1
  765. package/dist/runtime/types.d.ts.map +1 -1
  766. package/dist/search/evaluator.d.ts +71 -0
  767. package/dist/search/evaluator.d.ts.map +1 -1
  768. package/dist/search/evaluator.js +40 -5
  769. package/dist/search/evaluator.js.map +1 -1
  770. package/dist/search/index.d.ts +3 -5
  771. package/dist/search/index.d.ts.map +1 -1
  772. package/dist/search/index.js +4 -7
  773. package/dist/search/index.js.map +1 -1
  774. package/dist/search/moe-gate.d.ts +48 -2
  775. package/dist/search/moe-gate.d.ts.map +1 -1
  776. package/dist/search/moe-gate.js +117 -4
  777. package/dist/search/moe-gate.js.map +1 -1
  778. package/dist/search/refinement-loop.d.ts +63 -3
  779. package/dist/search/refinement-loop.d.ts.map +1 -1
  780. package/dist/search/refinement-loop.js +278 -23
  781. package/dist/search/refinement-loop.js.map +1 -1
  782. package/dist/search/refinement-types.d.ts +4 -2
  783. package/dist/search/refinement-types.d.ts.map +1 -1
  784. package/dist/search/refinement-types.js +2 -11
  785. package/dist/search/refinement-types.js.map +1 -1
  786. package/dist/search/router.d.ts +41 -34
  787. package/dist/search/router.d.ts.map +1 -1
  788. package/dist/search/router.js +156 -90
  789. package/dist/search/router.js.map +1 -1
  790. package/dist/search/solver.js +1 -1
  791. package/dist/search/solver.js.map +1 -1
  792. package/dist/search/task-difficulty.d.ts +54 -0
  793. package/dist/search/task-difficulty.d.ts.map +1 -0
  794. package/dist/search/task-difficulty.js +116 -0
  795. package/dist/search/task-difficulty.js.map +1 -0
  796. package/dist/search/tau-bench-verifier.d.ts +74 -0
  797. package/dist/search/tau-bench-verifier.d.ts.map +1 -0
  798. package/dist/search/tau-bench-verifier.js +96 -0
  799. package/dist/search/tau-bench-verifier.js.map +1 -0
  800. package/dist/search/verification-runner.d.ts.map +1 -1
  801. package/dist/search/verification-runner.js +6 -5
  802. package/dist/search/verification-runner.js.map +1 -1
  803. package/dist/session-bank/git-reader.d.ts.map +1 -1
  804. package/dist/session-bank/git-reader.js +5 -19
  805. package/dist/session-bank/git-reader.js.map +1 -1
  806. package/dist/session-bank/parser.d.ts.map +1 -1
  807. package/dist/session-bank/parser.js +26 -0
  808. package/dist/session-bank/parser.js.map +1 -1
  809. package/dist/session-bank/session-bank.d.ts.map +1 -1
  810. package/dist/session-bank/session-bank.js +2 -5
  811. package/dist/session-bank/session-bank.js.map +1 -1
  812. package/dist/session-bank/types.d.ts +24 -0
  813. package/dist/session-bank/types.d.ts.map +1 -1
  814. package/dist/surfacing/index.d.ts +3 -3
  815. package/dist/surfacing/index.d.ts.map +1 -1
  816. package/dist/surfacing/index.js +2 -2
  817. package/dist/surfacing/index.js.map +1 -1
  818. package/dist/surfacing/shared-bank.d.ts +43 -0
  819. package/dist/surfacing/shared-bank.d.ts.map +1 -0
  820. package/dist/surfacing/shared-bank.js +104 -0
  821. package/dist/surfacing/shared-bank.js.map +1 -0
  822. package/dist/surfacing/skill-library.d.ts +98 -2
  823. package/dist/surfacing/skill-library.d.ts.map +1 -1
  824. package/dist/surfacing/skill-library.js +192 -17
  825. package/dist/surfacing/skill-library.js.map +1 -1
  826. package/dist/surfacing/skill-publisher.d.ts +6 -4
  827. package/dist/surfacing/skill-publisher.d.ts.map +1 -1
  828. package/dist/surfacing/skill-publisher.js +32 -30
  829. package/dist/surfacing/skill-publisher.js.map +1 -1
  830. package/dist/surfacing/sqlite-storage-adapter.d.ts.map +1 -1
  831. package/dist/surfacing/sqlite-storage-adapter.js +12 -8
  832. package/dist/surfacing/sqlite-storage-adapter.js.map +1 -1
  833. package/dist/types/analysis.d.ts +43 -0
  834. package/dist/types/analysis.d.ts.map +1 -0
  835. package/dist/types/analysis.js +10 -0
  836. package/dist/types/analysis.js.map +1 -0
  837. package/dist/types/config.d.ts +2178 -425
  838. package/dist/types/config.d.ts.map +1 -1
  839. package/dist/types/config.js +600 -88
  840. package/dist/types/config.js.map +1 -1
  841. package/dist/types/dataclaw.d.ts +3 -3
  842. package/dist/types/index.d.ts +4 -7
  843. package/dist/types/index.d.ts.map +1 -1
  844. package/dist/types/index.js +2 -10
  845. package/dist/types/index.js.map +1 -1
  846. package/dist/types/knowledge-graph.d.ts +1 -1
  847. package/dist/types/knowledge-graph.d.ts.map +1 -1
  848. package/dist/types/knowledge.d.ts +219 -11
  849. package/dist/types/knowledge.d.ts.map +1 -1
  850. package/dist/types/knowledge.js +90 -30
  851. package/dist/types/knowledge.js.map +1 -1
  852. package/dist/types/memory.d.ts +8 -0
  853. package/dist/types/memory.d.ts.map +1 -1
  854. package/dist/types/memory.js +12 -4
  855. package/dist/types/memory.js.map +1 -1
  856. package/dist/types/outcome.d.ts +11 -0
  857. package/dist/types/outcome.d.ts.map +1 -1
  858. package/dist/types/outcome.js +9 -0
  859. package/dist/types/outcome.js.map +1 -1
  860. package/dist/types/playbook.d.ts +63 -0
  861. package/dist/types/playbook.d.ts.map +1 -1
  862. package/dist/types/playbook.js +51 -0
  863. package/dist/types/playbook.js.map +1 -1
  864. package/dist/types/trajectory-source.d.ts +1 -1
  865. package/dist/types/trajectory-source.d.ts.map +1 -1
  866. package/dist/types/trajectory.d.ts +61 -0
  867. package/dist/types/trajectory.d.ts.map +1 -1
  868. package/dist/types/trajectory.js +25 -0
  869. package/dist/types/trajectory.js.map +1 -1
  870. package/dist/utils/clock.d.ts +36 -0
  871. package/dist/utils/clock.d.ts.map +1 -0
  872. package/dist/utils/clock.js +48 -0
  873. package/dist/utils/clock.js.map +1 -0
  874. package/dist/utils/frontmatter.d.ts.map +1 -1
  875. package/dist/utils/frontmatter.js +10 -2
  876. package/dist/utils/frontmatter.js.map +1 -1
  877. package/dist/utils/index.d.ts +4 -1
  878. package/dist/utils/index.d.ts.map +1 -1
  879. package/dist/utils/index.js +4 -1
  880. package/dist/utils/index.js.map +1 -1
  881. package/dist/utils/logger.d.ts +31 -0
  882. package/dist/utils/logger.d.ts.map +1 -0
  883. package/dist/utils/logger.js +50 -0
  884. package/dist/utils/logger.js.map +1 -0
  885. package/dist/utils/objectives.d.ts +45 -0
  886. package/dist/utils/objectives.d.ts.map +1 -0
  887. package/dist/utils/objectives.js +74 -0
  888. package/dist/utils/objectives.js.map +1 -0
  889. package/dist/utils/partitioned-store.d.ts.map +1 -1
  890. package/dist/utils/partitioned-store.js.map +1 -1
  891. package/dist/utils/playbook-hash.d.ts +19 -0
  892. package/dist/utils/playbook-hash.d.ts.map +1 -0
  893. package/dist/utils/playbook-hash.js +51 -0
  894. package/dist/utils/playbook-hash.js.map +1 -0
  895. package/dist/utils/similarity.d.ts.map +1 -1
  896. package/dist/utils/similarity.js.map +1 -1
  897. package/dist/utils/solver-canonicalizer.d.ts +22 -0
  898. package/dist/utils/solver-canonicalizer.d.ts.map +1 -0
  899. package/dist/utils/solver-canonicalizer.js +41 -0
  900. package/dist/utils/solver-canonicalizer.js.map +1 -0
  901. package/dist/utils/storage.d.ts.map +1 -1
  902. package/dist/utils/storage.js +1 -3
  903. package/dist/utils/storage.js.map +1 -1
  904. package/dist/utils/task-signature.d.ts +34 -0
  905. package/dist/utils/task-signature.d.ts.map +1 -0
  906. package/dist/utils/task-signature.js +112 -0
  907. package/dist/utils/task-signature.js.map +1 -0
  908. package/dist/utils/trajectory-helpers.d.ts.map +1 -1
  909. package/dist/utils/trajectory-helpers.js.map +1 -1
  910. package/dist/utils/validation.d.ts.map +1 -1
  911. package/dist/utils/validation.js.map +1 -1
  912. package/dist/workspace/efficacy-toolkit.d.ts.map +1 -1
  913. package/dist/workspace/efficacy-toolkit.js +18 -26
  914. package/dist/workspace/efficacy-toolkit.js.map +1 -1
  915. package/dist/workspace/index.d.ts +4 -3
  916. package/dist/workspace/index.d.ts.map +1 -1
  917. package/dist/workspace/index.js +5 -3
  918. package/dist/workspace/index.js.map +1 -1
  919. package/dist/workspace/runner.d.ts.map +1 -1
  920. package/dist/workspace/runner.js +95 -21
  921. package/dist/workspace/runner.js.map +1 -1
  922. package/dist/workspace/skill-converter.d.ts +66 -1
  923. package/dist/workspace/skill-converter.d.ts.map +1 -1
  924. package/dist/workspace/skill-converter.js +238 -19
  925. package/dist/workspace/skill-converter.js.map +1 -1
  926. package/dist/workspace/skill-import.d.ts +43 -0
  927. package/dist/workspace/skill-import.d.ts.map +1 -0
  928. package/dist/workspace/skill-import.js +40 -0
  929. package/dist/workspace/skill-import.js.map +1 -0
  930. package/dist/workspace/templates/index.d.ts +6 -8
  931. package/dist/workspace/templates/index.d.ts.map +1 -1
  932. package/dist/workspace/templates/index.js +7 -11
  933. package/dist/workspace/templates/index.js.map +1 -1
  934. package/dist/workspace/templates/knowledge-defrag.d.ts.map +1 -1
  935. package/dist/workspace/templates/knowledge-defrag.js +0 -2
  936. package/dist/workspace/templates/knowledge-defrag.js.map +1 -1
  937. package/dist/workspace/templates/knowledge-extraction.d.ts +11 -0
  938. package/dist/workspace/templates/knowledge-extraction.d.ts.map +1 -1
  939. package/dist/workspace/templates/knowledge-extraction.js +11 -6
  940. package/dist/workspace/templates/knowledge-extraction.js.map +1 -1
  941. package/dist/workspace/templates/playbook-conditioning.d.ts +38 -0
  942. package/dist/workspace/templates/playbook-conditioning.d.ts.map +1 -0
  943. package/dist/workspace/templates/playbook-conditioning.js +147 -0
  944. package/dist/workspace/templates/playbook-conditioning.js.map +1 -0
  945. package/dist/workspace/templates/playbook-decay-detection.d.ts.map +1 -1
  946. package/dist/workspace/templates/playbook-decay-detection.js +24 -18
  947. package/dist/workspace/templates/playbook-decay-detection.js.map +1 -1
  948. package/dist/workspace/templates/playbook-efficacy-audit.d.ts.map +1 -1
  949. package/dist/workspace/templates/playbook-efficacy-audit.js +26 -11
  950. package/dist/workspace/templates/playbook-efficacy-audit.js.map +1 -1
  951. package/dist/workspace/templates/playbook-extraction.d.ts.map +1 -1
  952. package/dist/workspace/templates/playbook-extraction.js +75 -15
  953. package/dist/workspace/templates/playbook-extraction.js.map +1 -1
  954. package/dist/workspace/templates/playbook-lifecycle-review.d.ts.map +1 -1
  955. package/dist/workspace/templates/playbook-lifecycle-review.js +12 -8
  956. package/dist/workspace/templates/playbook-lifecycle-review.js.map +1 -1
  957. package/dist/workspace/templates/refinement-analysis.d.ts.map +1 -1
  958. package/dist/workspace/templates/refinement-analysis.js +11 -5
  959. package/dist/workspace/templates/refinement-analysis.js.map +1 -1
  960. package/dist/workspace/templates/skill-enrichment.d.ts.map +1 -1
  961. package/dist/workspace/templates/skill-enrichment.js +7 -11
  962. package/dist/workspace/templates/skill-enrichment.js.map +1 -1
  963. package/dist/workspace/templates/solution-evaluation.d.ts.map +1 -1
  964. package/dist/workspace/templates/solution-evaluation.js +15 -8
  965. package/dist/workspace/templates/solution-evaluation.js.map +1 -1
  966. package/dist/workspace/templates/trajectory-analysis.d.ts.map +1 -1
  967. package/dist/workspace/templates/trajectory-analysis.js +1 -3
  968. package/dist/workspace/templates/trajectory-analysis.js.map +1 -1
  969. package/dist/workspace/templates/usage-inference.d.ts.map +1 -1
  970. package/dist/workspace/templates/usage-inference.js +9 -7
  971. package/dist/workspace/templates/usage-inference.js.map +1 -1
  972. package/dist/workspace/types.d.ts +32 -2
  973. package/dist/workspace/types.d.ts.map +1 -1
  974. package/dist/workspace/types.js +29 -0
  975. package/dist/workspace/types.js.map +1 -1
  976. package/package.json +43 -19
  977. package/playbooks/agent-ops/long-task-checkpointing.json +54 -0
  978. package/playbooks/agent-ops/progressive-context-gathering.json +56 -0
  979. package/playbooks/agent-ops/safe-destructive-operations.json +59 -0
  980. package/playbooks/agent-ops/scope-discipline.json +56 -0
  981. package/playbooks/agent-ops/stall-detection-strategy-switch.json +55 -0
  982. package/playbooks/agent-ops/verification-before-completion.json +54 -0
  983. package/playbooks/alfworld/clean-and-place.json +35 -0
  984. package/playbooks/alfworld/cool-and-place.json +35 -0
  985. package/playbooks/alfworld/examine-in-light.json +32 -0
  986. package/playbooks/alfworld/heat-and-place.json +35 -0
  987. package/playbooks/alfworld/pick-and-place.json +37 -0
  988. package/playbooks/alfworld/pick-two-and-place.json +35 -0
  989. package/.claude/settings.json +0 -197
  990. package/.entire/settings.json +0 -4
  991. package/.sessionlog/settings.json +0 -4
  992. package/CLAUDE.md +0 -233
  993. package/SKILL.md +0 -193
  994. package/docs/DESIGN-agentic-workspace.md +0 -2057
  995. package/docs/DESIGN-semantic-memory-knowledge-bank.md +0 -1789
  996. package/docs/DESIGN-session-bank.md +0 -1134
  997. package/docs/DESIGN-team-extraction-pipeline.md +0 -1369
  998. package/docs/PROPOSAL-team-aware-learning.md +0 -1080
  999. package/docs/RESEARCH-semantic-memory-knowledge-structures.md +0 -517
  1000. package/docs/RESEARCH-team-trajectory-learning.md +0 -553
  1001. package/gaps.md +0 -204
  1002. package/scripts/migrate-to-playbooks.ts +0 -307
  1003. package/src/agents/index.ts +0 -14
  1004. package/src/agents/mock-provider.ts +0 -93
  1005. package/src/agents/types.ts +0 -137
  1006. package/src/atlas.ts +0 -1198
  1007. package/src/bin/cli-utils.ts +0 -220
  1008. package/src/bin/cognitive-core.ts +0 -162
  1009. package/src/bin/commands/kb.ts +0 -266
  1010. package/src/bin/commands/learn.ts +0 -100
  1011. package/src/bin/commands/legacy.ts +0 -182
  1012. package/src/bin/commands/run.ts +0 -113
  1013. package/src/bin/commands/sessions.ts +0 -221
  1014. package/src/bin/commands/skills.ts +0 -146
  1015. package/src/embeddings/bm25.ts +0 -337
  1016. package/src/embeddings/index.ts +0 -42
  1017. package/src/embeddings/inverted-index.ts +0 -134
  1018. package/src/embeddings/manager.ts +0 -293
  1019. package/src/embeddings/provider.ts +0 -318
  1020. package/src/embeddings/vector-store.ts +0 -365
  1021. package/src/factory.ts +0 -280
  1022. package/src/index.ts +0 -495
  1023. package/src/learning/analyzer.ts +0 -319
  1024. package/src/learning/effectiveness.ts +0 -428
  1025. package/src/learning/energy-evaluator.ts +0 -282
  1026. package/src/learning/healing-orchestrator.ts +0 -383
  1027. package/src/learning/index.ts +0 -150
  1028. package/src/learning/instant-loop.ts +0 -357
  1029. package/src/learning/knowledge-extractor.ts +0 -470
  1030. package/src/learning/maintenance-scheduler.ts +0 -271
  1031. package/src/learning/meta-learner.ts +0 -552
  1032. package/src/learning/playbook-extractor.ts +0 -702
  1033. package/src/learning/reflexion-generator.ts +0 -273
  1034. package/src/learning/team-ingester.ts +0 -499
  1035. package/src/learning/team-meta-learner.ts +0 -558
  1036. package/src/learning/team-pipeline.ts +0 -364
  1037. package/src/learning/trajectory-sources/dataclaw.ts +0 -403
  1038. package/src/learning/trajectory-sources/entire.ts +0 -251
  1039. package/src/learning/trajectory-sources/file.ts +0 -136
  1040. package/src/learning/trajectory-sources/huggingface.ts +0 -248
  1041. package/src/learning/trajectory-sources/in-memory.ts +0 -61
  1042. package/src/learning/trajectory-sources/index.ts +0 -15
  1043. package/src/learning/trajectory-sources/pipeline.ts +0 -69
  1044. package/src/learning/unified-pipeline.ts +0 -1191
  1045. package/src/learning/usage-inference.ts +0 -372
  1046. package/src/mcp/index.ts +0 -12
  1047. package/src/mcp/playbook-server.ts +0 -565
  1048. package/src/memory/candidate-retrieval.ts +0 -72
  1049. package/src/memory/causal-store.ts +0 -273
  1050. package/src/memory/coherence.ts +0 -252
  1051. package/src/memory/curated-loader.ts +0 -213
  1052. package/src/memory/experience.ts +0 -682
  1053. package/src/memory/graph-layers/base.ts +0 -184
  1054. package/src/memory/graph-layers/causal.ts +0 -16
  1055. package/src/memory/graph-layers/entity.ts +0 -16
  1056. package/src/memory/graph-layers/index.ts +0 -5
  1057. package/src/memory/graph-layers/semantic.ts +0 -16
  1058. package/src/memory/graph-layers/temporal.ts +0 -16
  1059. package/src/memory/index.ts +0 -131
  1060. package/src/memory/knowledge-bank.ts +0 -1317
  1061. package/src/memory/knowledge-defrag.ts +0 -329
  1062. package/src/memory/knowledge-graph.ts +0 -361
  1063. package/src/memory/meta.ts +0 -488
  1064. package/src/memory/playbook.ts +0 -676
  1065. package/src/memory/reasoning-bank.ts +0 -458
  1066. package/src/memory/reflexion.ts +0 -122
  1067. package/src/memory/search-provider.ts +0 -35
  1068. package/src/memory/search-providers/index.ts +0 -3
  1069. package/src/memory/search-providers/minimem.ts +0 -84
  1070. package/src/memory/search-providers/text-similarity.ts +0 -35
  1071. package/src/memory/skill-exporter.ts +0 -357
  1072. package/src/memory/source-resolver.ts +0 -422
  1073. package/src/memory/system.ts +0 -620
  1074. package/src/memory/team-experience.ts +0 -604
  1075. package/src/memory/temporal-compressor.ts +0 -409
  1076. package/src/persistence/index.ts +0 -37
  1077. package/src/persistence/migrator.ts +0 -298
  1078. package/src/persistence/serializers.ts +0 -79
  1079. package/src/persistence/sqlite-persistence.ts +0 -925
  1080. package/src/runtime/backends/acp-protocol.ts +0 -231
  1081. package/src/runtime/backends/acp.ts +0 -239
  1082. package/src/runtime/backends/index.ts +0 -38
  1083. package/src/runtime/backends/macro-agent.ts +0 -177
  1084. package/src/runtime/backends/mock.ts +0 -218
  1085. package/src/runtime/backends/subprocess.ts +0 -356
  1086. package/src/runtime/compute-provider.ts +0 -206
  1087. package/src/runtime/flows/learning.ts +0 -166
  1088. package/src/runtime/flows/validation.ts +0 -381
  1089. package/src/runtime/index.ts +0 -75
  1090. package/src/runtime/manager.ts +0 -685
  1091. package/src/runtime/types.ts +0 -198
  1092. package/src/search/evaluator.ts +0 -499
  1093. package/src/search/index.ts +0 -78
  1094. package/src/search/moe-gate.ts +0 -304
  1095. package/src/search/refinement-loop.ts +0 -457
  1096. package/src/search/refinement-types.ts +0 -159
  1097. package/src/search/router.ts +0 -368
  1098. package/src/search/solver.ts +0 -303
  1099. package/src/search/team-router.ts +0 -459
  1100. package/src/search/verification-runner.ts +0 -570
  1101. package/src/session-bank/git-reader.ts +0 -200
  1102. package/src/session-bank/index.ts +0 -26
  1103. package/src/session-bank/parser.ts +0 -548
  1104. package/src/session-bank/session-bank.ts +0 -485
  1105. package/src/session-bank/types.ts +0 -176
  1106. package/src/surfacing/index.ts +0 -29
  1107. package/src/surfacing/publisher.ts +0 -23
  1108. package/src/surfacing/skill-library.ts +0 -625
  1109. package/src/surfacing/skill-publisher.ts +0 -258
  1110. package/src/surfacing/sqlite-storage-adapter.ts +0 -287
  1111. package/src/surfacing/team-skill-library.ts +0 -610
  1112. package/src/types/config.ts +0 -661
  1113. package/src/types/dataclaw.ts +0 -99
  1114. package/src/types/huggingface-transformers.d.ts +0 -12
  1115. package/src/types/index.ts +0 -293
  1116. package/src/types/knowledge-graph.ts +0 -246
  1117. package/src/types/knowledge.ts +0 -388
  1118. package/src/types/memory.ts +0 -300
  1119. package/src/types/meta.ts +0 -218
  1120. package/src/types/outcome.ts +0 -66
  1121. package/src/types/playbook.ts +0 -215
  1122. package/src/types/step.ts +0 -40
  1123. package/src/types/task.ts +0 -52
  1124. package/src/types/team-meta.ts +0 -212
  1125. package/src/types/team-playbook.ts +0 -384
  1126. package/src/types/team-trajectory.ts +0 -673
  1127. package/src/types/trajectory-source.ts +0 -47
  1128. package/src/types/trajectory.ts +0 -80
  1129. package/src/utils/error-classifier.ts +0 -113
  1130. package/src/utils/frontmatter.ts +0 -118
  1131. package/src/utils/index.ts +0 -63
  1132. package/src/utils/partitioned-store.ts +0 -299
  1133. package/src/utils/similarity.ts +0 -139
  1134. package/src/utils/storage.ts +0 -249
  1135. package/src/utils/trajectory-helpers.ts +0 -79
  1136. package/src/utils/validation.ts +0 -286
  1137. package/src/workspace/efficacy-toolkit.ts +0 -496
  1138. package/src/workspace/index.ts +0 -77
  1139. package/src/workspace/runner.ts +0 -281
  1140. package/src/workspace/skill-converter.ts +0 -288
  1141. package/src/workspace/templates/index.ts +0 -95
  1142. package/src/workspace/templates/knowledge-defrag.ts +0 -223
  1143. package/src/workspace/templates/knowledge-extraction.ts +0 -337
  1144. package/src/workspace/templates/meta-reflection.ts +0 -208
  1145. package/src/workspace/templates/playbook-decay-detection.ts +0 -272
  1146. package/src/workspace/templates/playbook-efficacy-audit.ts +0 -246
  1147. package/src/workspace/templates/playbook-extraction.ts +0 -240
  1148. package/src/workspace/templates/playbook-lifecycle-review.ts +0 -274
  1149. package/src/workspace/templates/refinement-analysis.ts +0 -162
  1150. package/src/workspace/templates/skill-enrichment.ts +0 -275
  1151. package/src/workspace/templates/solution-evaluation.ts +0 -199
  1152. package/src/workspace/templates/team-playbook-extraction.ts +0 -631
  1153. package/src/workspace/templates/team-trajectory-analysis.ts +0 -564
  1154. package/src/workspace/templates/trajectory-analysis.ts +0 -234
  1155. package/src/workspace/templates/usage-inference.ts +0 -163
  1156. package/src/workspace/types.ts +0 -185
  1157. package/tests/atlas-knowledge.test.ts +0 -165
  1158. package/tests/embeddings/bm25.test.ts +0 -130
  1159. package/tests/embeddings/inverted-index.test.ts +0 -138
  1160. package/tests/embeddings/manager.test.ts +0 -205
  1161. package/tests/feature-toggles.test.ts +0 -275
  1162. package/tests/fixtures/behavioral-trajectories.ts +0 -210
  1163. package/tests/gap-fixes.test.ts +0 -1116
  1164. package/tests/integration/atlas.test.ts +0 -266
  1165. package/tests/integration/cli-e2e.test.ts +0 -621
  1166. package/tests/integration/curated-sources-e2e.test.ts +0 -502
  1167. package/tests/integration/dataclaw-e2e.test.ts +0 -559
  1168. package/tests/integration/e2e.test.ts +0 -1337
  1169. package/tests/integration/entire-e2e.test.ts +0 -376
  1170. package/tests/integration/huggingface-e2e.test.ts +0 -627
  1171. package/tests/integration/persistence-e2e.test.ts +0 -741
  1172. package/tests/integration/phase-e2e.test.ts +0 -1143
  1173. package/tests/integration/pipeline-data-correctness.test.ts +0 -794
  1174. package/tests/integration/ranking-driven-loadout-e2e.test.ts +0 -185
  1175. package/tests/integration/session-bank.test.ts +0 -231
  1176. package/tests/integration/sessionlog-e2e.test.ts +0 -329
  1177. package/tests/integration/skill-publishing-filesystem-e2e.test.ts +0 -216
  1178. package/tests/integration/skill-tree-wiring.test.ts +0 -152
  1179. package/tests/integration/unified-pipeline-e2e.test.ts +0 -634
  1180. package/tests/learning/analyzer.test.ts +0 -426
  1181. package/tests/learning/dataclaw-trajectory-source.test.ts +0 -642
  1182. package/tests/learning/effectiveness.test.ts +0 -542
  1183. package/tests/learning/energy-evaluator.test.ts +0 -180
  1184. package/tests/learning/entire-trajectory-source.test.ts +0 -380
  1185. package/tests/learning/healing-orchestrator.test.ts +0 -269
  1186. package/tests/learning/huggingface-trajectory-source.test.ts +0 -817
  1187. package/tests/learning/instant-loop.test.ts +0 -243
  1188. package/tests/learning/knowledge-extractor.test.ts +0 -491
  1189. package/tests/learning/maintenance-scheduler.test.ts +0 -191
  1190. package/tests/learning/meta-learner.test.ts +0 -418
  1191. package/tests/learning/pipeline-memory-updates.test.ts +0 -721
  1192. package/tests/learning/playbook-extractor-provenance.test.ts +0 -114
  1193. package/tests/learning/reflexion-generator.test.ts +0 -411
  1194. package/tests/learning/team-ingester.test.ts +0 -349
  1195. package/tests/learning/team-meta-learner.test.ts +0 -618
  1196. package/tests/learning/team-pipeline.test.ts +0 -334
  1197. package/tests/learning/trajectory-sources.test.ts +0 -320
  1198. package/tests/learning/unified-pipeline-efficacy.test.ts +0 -232
  1199. package/tests/learning/unified-pipeline.test.ts +0 -322
  1200. package/tests/learning/usage-inference.test.ts +0 -254
  1201. package/tests/mcp/playbook-server.test.ts +0 -257
  1202. package/tests/memory/candidate-retrieval.test.ts +0 -167
  1203. package/tests/memory/causal-store.test.ts +0 -276
  1204. package/tests/memory/coherence.test.ts +0 -232
  1205. package/tests/memory/compound-engineering-seed.test.ts +0 -338
  1206. package/tests/memory/curated-loader-extended.test.ts +0 -225
  1207. package/tests/memory/experience.test.ts +0 -203
  1208. package/tests/memory/graph-layers/semantic.test.ts +0 -219
  1209. package/tests/memory/knowledge-bank-extraction.test.ts +0 -558
  1210. package/tests/memory/knowledge-bank.test.ts +0 -705
  1211. package/tests/memory/knowledge-defrag.test.ts +0 -366
  1212. package/tests/memory/knowledge-evolution.test.ts +0 -563
  1213. package/tests/memory/knowledge-graph.test.ts +0 -492
  1214. package/tests/memory/knowledge-inbox.test.ts +0 -258
  1215. package/tests/memory/knowledge-minimem.test.ts +0 -251
  1216. package/tests/memory/meta.test.ts +0 -399
  1217. package/tests/memory/playbook-quality-validation.test.ts +0 -430
  1218. package/tests/memory/playbook.test.ts +0 -644
  1219. package/tests/memory/provenance.test.ts +0 -648
  1220. package/tests/memory/reasoning-bank.test.ts +0 -239
  1221. package/tests/memory/reflexion.test.ts +0 -166
  1222. package/tests/memory/skill-exporter.test.ts +0 -475
  1223. package/tests/memory/source-resolver.test.ts +0 -700
  1224. package/tests/memory/system.test.ts +0 -330
  1225. package/tests/memory/team-experience.test.ts +0 -411
  1226. package/tests/memory/temporal-compressor.test.ts +0 -318
  1227. package/tests/persistence/migrator.test.ts +0 -1009
  1228. package/tests/persistence/sqlite-persistence.test.ts +0 -635
  1229. package/tests/runtime/agent-manager.test.ts +0 -517
  1230. package/tests/runtime/compute-provider.test.ts +0 -288
  1231. package/tests/runtime/delegate.test.ts +0 -354
  1232. package/tests/runtime/macro-agent-backend.test.ts +0 -266
  1233. package/tests/runtime/mock-backend.test.ts +0 -248
  1234. package/tests/search/evaluator.test.ts +0 -257
  1235. package/tests/search/moe-gate.test.ts +0 -250
  1236. package/tests/search/refinement-loop.test.ts +0 -477
  1237. package/tests/search/refinement.test.ts +0 -267
  1238. package/tests/search/router.test.ts +0 -506
  1239. package/tests/search/team-router.test.ts +0 -376
  1240. package/tests/search/verification-runner.test.ts +0 -357
  1241. package/tests/session-bank/fixtures/multi-tool-session/full.jsonl +0 -12
  1242. package/tests/session-bank/fixtures/multi-tool-session/metadata.json +0 -28
  1243. package/tests/session-bank/fixtures/root-metadata.json +0 -18
  1244. package/tests/session-bank/fixtures/sessionlog-root-metadata.json +0 -16
  1245. package/tests/session-bank/fixtures/sessionlog-session/full.jsonl +0 -6
  1246. package/tests/session-bank/fixtures/sessionlog-session/metadata.json +0 -55
  1247. package/tests/session-bank/fixtures/simple-session/full.jsonl +0 -6
  1248. package/tests/session-bank/fixtures/simple-session/metadata.json +0 -38
  1249. package/tests/session-bank/git-reader.test.ts +0 -232
  1250. package/tests/session-bank/parser.test.ts +0 -453
  1251. package/tests/session-bank/session-bank.test.ts +0 -546
  1252. package/tests/surfacing/skill-library.test.ts +0 -297
  1253. package/tests/surfacing/skill-publisher.test.ts +0 -432
  1254. package/tests/surfacing/sqlite-storage-adapter.test.ts +0 -197
  1255. package/tests/surfacing/team-skill-library.test.ts +0 -444
  1256. package/tests/types/outcome.test.ts +0 -147
  1257. package/tests/types/step.test.ts +0 -133
  1258. package/tests/types/task.test.ts +0 -158
  1259. package/tests/types/team-meta.test.ts +0 -147
  1260. package/tests/types/team-playbook.test.ts +0 -246
  1261. package/tests/types/team-trajectory.test.ts +0 -557
  1262. package/tests/types/trajectory.test.ts +0 -253
  1263. package/tests/utils/error-classifier.test.ts +0 -149
  1264. package/tests/utils/frontmatter.test.ts +0 -208
  1265. package/tests/utils/partitioned-store.test.ts +0 -230
  1266. package/tests/utils/similarity.test.ts +0 -188
  1267. package/tests/utils/trajectory-helpers.test.ts +0 -163
  1268. package/tests/utils/validation.test.ts +0 -252
  1269. package/tests/workspace/efficacy-toolkit.test.ts +0 -404
  1270. package/tests/workspace/full-flow.test.ts +0 -845
  1271. package/tests/workspace/manager.test.ts +0 -215
  1272. package/tests/workspace/runner.test.ts +0 -336
  1273. package/tests/workspace/skill-converter.test.ts +0 -205
  1274. package/tests/workspace/templates/knowledge-extraction.test.ts +0 -235
  1275. package/tests/workspace/templates/playbook-efficacy.test.ts +0 -377
  1276. package/tests/workspace/templates/team-playbook-extraction.test.ts +0 -341
  1277. package/tests/workspace/templates/team-trajectory-analysis.test.ts +0 -417
  1278. package/tsconfig.json +0 -25
  1279. package/vitest.config.ts +0 -22
@@ -1,1317 +0,0 @@
1
- import { readFile, writeFile, readdir, mkdir, unlink, access } from 'node:fs/promises';
2
- import { join, relative } from 'node:path';
3
- import type {
4
- KnowledgeNote,
5
- KnowledgeMatch,
6
- KnowledgeStats,
7
- EntityUpdate,
8
- Contradiction,
9
- ExtractedKnowledge,
10
- InboxResult,
11
- DefragResult,
12
- DecayResult,
13
- GraphLayerName,
14
- PlaybookLink,
15
- } from '../types/knowledge.js';
16
- import { inferLayerFromRelation, createObservation } from '../types/knowledge.js';
17
- import type { Trajectory } from '../types/index.js';
18
- import type { TrajectorySource } from '../types/trajectory-source.js';
19
- import type { KnowledgeBankConfig } from '../types/config.js';
20
- import type { GraphNode } from '../types/knowledge-graph.js';
21
- import type { AgenticTaskRunner } from '../workspace/runner.js';
22
- import type { TrajectoryAnalyzer, AnalysisResult } from '../learning/analyzer.js';
23
- import { KnowledgeGraphManager } from './knowledge-graph.js';
24
- import { CoherenceChecker } from './coherence.js';
25
- import {
26
- parseKnowledgeNote,
27
- serializeKnowledgeNote,
28
- } from '../utils/frontmatter.js';
29
- import type { SearchProvider } from './search-provider.js';
30
- import { TextSimilaritySearchProvider } from './search-providers/text-similarity.js';
31
-
32
- /**
33
- * KnowledgeBank — Semantic memory store for facts, concepts, and relationships.
34
- *
35
- * Uses the filesystem as the universal primary index (minimem-compatible).
36
- * Maintains a multi-layer graph overlay as a derived index for relationship queries.
37
- *
38
- * Directory structure:
39
- * {memoryDir}/
40
- * knowledge/
41
- * observations/ — atomic facts (k-*.md)
42
- * entities/ — living entity docs ({entity}.md)
43
- * domains/ — domain summaries ({domain}.md)
44
- * inbox/ — unorganized agent-authored notes
45
- * .knowledge/ — derived index files (graph, manifest)
46
- */
47
- export class KnowledgeBank {
48
- public readonly graph: KnowledgeGraphManager;
49
-
50
- private memoryDir: string;
51
- private readonly bankConfig: KnowledgeBankConfig;
52
- private initialized = false;
53
- private searchProvider: SearchProvider = new TextSimilaritySearchProvider();
54
- private coherenceChecker: CoherenceChecker = new CoherenceChecker();
55
-
56
- // Directory paths (resolved on init)
57
- private observationsDir = '';
58
- private entitiesDir = '';
59
- private domainsDir = '';
60
- private inboxDir = '';
61
- private indexDir = '';
62
-
63
- constructor(memoryDir: string, config: KnowledgeBankConfig) {
64
- this.memoryDir = memoryDir;
65
- this.bankConfig = config;
66
- this.graph = new KnowledgeGraphManager(this.bankConfig.graph);
67
- }
68
-
69
- // =========================================================================
70
- // Lifecycle
71
- // =========================================================================
72
-
73
- async init(): Promise<void> {
74
- if (this.initialized) return;
75
-
76
- // Resolve directory paths.
77
- // When minimemAware, nest under memory/knowledge/ so paths align with
78
- // minimem's directory layout; otherwise use the original knowledge/ root.
79
- const knowledgeBase = this.bankConfig.minimemAware
80
- ? join(this.memoryDir, 'memory', 'knowledge')
81
- : join(this.memoryDir, 'knowledge');
82
-
83
- this.observationsDir = join(knowledgeBase, 'observations');
84
- this.entitiesDir = join(knowledgeBase, 'entities');
85
- this.domainsDir = join(knowledgeBase, 'domains');
86
- this.inboxDir = join(this.memoryDir, 'inbox');
87
- this.indexDir = join(this.memoryDir, '.knowledge');
88
-
89
- // Create directory structure
90
- await Promise.all([
91
- mkdir(this.observationsDir, { recursive: true }),
92
- mkdir(this.entitiesDir, { recursive: true }),
93
- mkdir(this.domainsDir, { recursive: true }),
94
- mkdir(this.inboxDir, { recursive: true }),
95
- mkdir(this.indexDir, { recursive: true }),
96
- ]);
97
-
98
- // Load graph from disk
99
- await this.graph.loadFromDisk(this.indexDir);
100
-
101
- // Detect minimem and swap search provider if available
102
- if (this.bankConfig.minimemAware) {
103
- await this.detectMinimem();
104
- }
105
-
106
- this.initialized = true;
107
- }
108
-
109
- async close(): Promise<void> {
110
- if (!this.initialized) return;
111
- await this.graph.saveToDisk(this.indexDir);
112
- }
113
-
114
- // =========================================================================
115
- // Write Operations
116
- // =========================================================================
117
-
118
- /**
119
- * Create a new knowledge note and write it to disk.
120
- * Runs coherence checking against existing notes — contradictions are flagged
121
- * via metadata but the note is still stored.
122
- * Updates the graph overlay in memory.
123
- */
124
- async addObservation(note: KnowledgeNote): Promise<string> {
125
- await this.init();
126
-
127
- // Run coherence check against related existing notes (if enabled)
128
- if (this.bankConfig.coherenceChecking !== false) {
129
- try {
130
- const existing = await this.getRelatedNotes(note);
131
- const coherence = await this.coherenceChecker.check(note, existing);
132
-
133
- if (!coherence.isCoherent) {
134
- // Flag contradictions in metadata but still store the note
135
- const meta = (note.frontmatter as Record<string, unknown>);
136
- meta['contradictions'] = coherence.contradictions.map(
137
- (c) => c.existingNoteId
138
- );
139
- meta['coherenceEnergy'] = coherence.globalEnergy;
140
- }
141
- } catch {
142
- // Coherence check is non-critical — don't block insertion
143
- }
144
- }
145
-
146
- await this.writeNote(note);
147
- this.graph.addNode(this.noteToGraphNode(note));
148
- return note.frontmatter.id;
149
- }
150
-
151
- /**
152
- * Get the last coherence result from the most recent addObservation call.
153
- * Useful for downstream consumers to react to contradictions.
154
- */
155
- getCoherenceChecker(): CoherenceChecker {
156
- return this.coherenceChecker;
157
- }
158
-
159
- /**
160
- * Update an existing entity note by appending a section.
161
- */
162
- async updateEntity(entityId: string, update: EntityUpdate): Promise<void> {
163
- await this.init();
164
-
165
- const note = await this.getNote(entityId);
166
- if (!note) {
167
- throw new Error(`Entity note not found: ${entityId}`);
168
- }
169
-
170
- // Append the new section
171
- const separator = '\n\n---\n\n';
172
- const evidence = `*Source: trajectory ${update.trajectoryId}*`;
173
- note.body = `${note.body}${separator}${update.section}\n\n${evidence}`;
174
-
175
- // Update timestamp
176
- note.frontmatter.updated = new Date().toISOString();
177
-
178
- // Add trajectory to sources if not already present
179
- if (!note.frontmatter.source.trajectories) {
180
- note.frontmatter.source.trajectories = [];
181
- }
182
- if (
183
- !note.frontmatter.source.trajectories.includes(update.trajectoryId)
184
- ) {
185
- note.frontmatter.source.trajectories.push(update.trajectoryId);
186
- }
187
-
188
- await this.writeNote(note);
189
-
190
- // Update graph node
191
- this.graph.addNode(this.noteToGraphNode(note));
192
- }
193
-
194
- // =========================================================================
195
- // Read Operations
196
- // =========================================================================
197
-
198
- /**
199
- * Get a note by ID. Scans all directories.
200
- */
201
- async getNote(id: string): Promise<KnowledgeNote | null> {
202
- await this.init();
203
-
204
- // Try each directory
205
- for (const dir of [
206
- this.observationsDir,
207
- this.entitiesDir,
208
- this.domainsDir,
209
- ]) {
210
- const notes = await this.scanDirectory(dir);
211
- const found = notes.find((n) => n.frontmatter.id === id);
212
- if (found) return found;
213
- }
214
-
215
- return null;
216
- }
217
-
218
- /**
219
- * Get an entity note by entity name.
220
- */
221
- async getEntity(entityName: string): Promise<KnowledgeNote | null> {
222
- await this.init();
223
-
224
- const slug = entityName.toLowerCase().replace(/[^a-z0-9]+/g, '-');
225
- const filePath = join(this.entitiesDir, `${slug}.md`);
226
-
227
- try {
228
- const content = await readFile(filePath, 'utf-8');
229
- const relativePath = relative(this.memoryDir, filePath);
230
- return parseKnowledgeNote(content, relativePath);
231
- } catch {
232
- return null;
233
- }
234
- }
235
-
236
- /**
237
- * Get a domain summary by domain name.
238
- */
239
- async getDomainSummary(domain: string): Promise<KnowledgeNote | null> {
240
- await this.init();
241
-
242
- const slug = domain.toLowerCase().replace(/[^a-z0-9]+/g, '-');
243
- const filePath = join(this.domainsDir, `${slug}.md`);
244
-
245
- try {
246
- const content = await readFile(filePath, 'utf-8');
247
- const relativePath = relative(this.memoryDir, filePath);
248
- return parseKnowledgeNote(content, relativePath);
249
- } catch {
250
- return null;
251
- }
252
- }
253
-
254
- /**
255
- * List all known entity names (from entity note filenames).
256
- */
257
- async listEntities(): Promise<string[]> {
258
- await this.init();
259
-
260
- try {
261
- const files = await readdir(this.entitiesDir);
262
- return files
263
- .filter((f) => f.endsWith('.md'))
264
- .map((f) => f.replace('.md', ''));
265
- } catch {
266
- return [];
267
- }
268
- }
269
-
270
- /**
271
- * List all known domain names (from domain summary filenames).
272
- */
273
- async listDomains(): Promise<string[]> {
274
- await this.init();
275
-
276
- try {
277
- const files = await readdir(this.domainsDir);
278
- return files
279
- .filter((f) => f.endsWith('.md'))
280
- .map((f) => f.replace('.md', ''));
281
- } catch {
282
- return [];
283
- }
284
- }
285
-
286
- /**
287
- * Get all notes across all directories.
288
- */
289
- async getAllNotes(): Promise<KnowledgeNote[]> {
290
- await this.init();
291
-
292
- const [observations, entities, domains] = await Promise.all([
293
- this.scanDirectory(this.observationsDir),
294
- this.scanDirectory(this.entitiesDir),
295
- this.scanDirectory(this.domainsDir),
296
- ]);
297
-
298
- return [...observations, ...entities, ...domains];
299
- }
300
-
301
- // =========================================================================
302
- // Graph Delegation
303
- // =========================================================================
304
-
305
- /**
306
- * Get related notes via multi-layer graph traversal.
307
- */
308
- async getRelated(
309
- noteId: string,
310
- options?: {
311
- depth?: number;
312
- layers?: GraphLayerName[];
313
- minWeight?: number;
314
- }
315
- ): Promise<KnowledgeMatch[]> {
316
- await this.init();
317
-
318
- const neighborNodes = this.graph.neighbors(noteId, options);
319
- const matches: KnowledgeMatch[] = [];
320
-
321
- for (const graphNode of neighborNodes) {
322
- const note = await this.getNote(graphNode.id);
323
- if (note) {
324
- matches.push({
325
- note,
326
- score: graphNode.confidence,
327
- matchType: 'graph',
328
- });
329
- }
330
- }
331
-
332
- return matches.sort((a, b) => b.score - a.score);
333
- }
334
-
335
- /**
336
- * Get cross-system links to playbooks.
337
- */
338
- async getPlaybookLinks(noteId: string): Promise<PlaybookLink[]> {
339
- await this.init();
340
-
341
- const edges = this.graph.crossSystemLinks(noteId);
342
- return edges
343
- .filter((e) => e.crossSystem === 'playbook')
344
- .map((e) => ({
345
- noteId: e.from,
346
- playbookId: e.to,
347
- relation: 'supports' as const,
348
- }));
349
- }
350
-
351
- // =========================================================================
352
- // Stats
353
- // =========================================================================
354
-
355
- async getStats(): Promise<KnowledgeStats> {
356
- await this.init();
357
-
358
- const [observations, entities, domains, inbox] = await Promise.all([
359
- this.countFiles(this.observationsDir),
360
- this.countFiles(this.entitiesDir),
361
- this.countFiles(this.domainsDir),
362
- this.countFiles(this.inboxDir),
363
- ]);
364
-
365
- const graphStats = this.graph.getStats();
366
-
367
- // Compute average confidence and domain breakdown
368
- const allNotes = await this.getAllNotes();
369
- let totalConfidence = 0;
370
- let staleCount = 0;
371
- const domainBreakdown: Record<string, number> = {};
372
-
373
- for (const note of allNotes) {
374
- totalConfidence += note.frontmatter.confidence;
375
- if (note.frontmatter.tags.includes('stale')) staleCount++;
376
- for (const domain of note.frontmatter.domain) {
377
- domainBreakdown[domain] = (domainBreakdown[domain] ?? 0) + 1;
378
- }
379
- }
380
-
381
- return {
382
- observationCount: observations,
383
- entityCount: entities,
384
- domainCount: domains,
385
- inboxCount: inbox,
386
- graph: graphStats,
387
- avgConfidence:
388
- allNotes.length > 0 ? totalConfidence / allNotes.length : 0,
389
- staleCount,
390
- domainBreakdown,
391
- };
392
- }
393
-
394
- // =========================================================================
395
- // Search & Retrieval
396
- // =========================================================================
397
-
398
- /**
399
- * Search knowledge notes by text similarity.
400
- * Scores against note ID + body using Jaccard + n-gram similarity.
401
- */
402
- async search(
403
- query: string,
404
- options?: { domains?: string[]; maxResults?: number }
405
- ): Promise<KnowledgeMatch[]> {
406
- await this.init();
407
-
408
- const allNotes = await this.getAllNotes();
409
- const maxResults = options?.maxResults ?? 10;
410
-
411
- // Filter by domains if specified
412
- let candidates = allNotes;
413
- if (options?.domains && options.domains.length > 0) {
414
- candidates = allNotes.filter((note) =>
415
- note.frontmatter.domain.some((d) => options.domains!.includes(d))
416
- );
417
- }
418
-
419
- // Exclude stale notes
420
- candidates = candidates.filter(
421
- (note) => !note.frontmatter.tags.includes('stale')
422
- );
423
-
424
- // Delegate scoring to the search provider
425
- const results = await this.searchProvider.search(query, candidates, { maxResults });
426
-
427
- // Build a lookup for fast note retrieval by ID
428
- const noteById = new Map(candidates.map((n) => [n.frontmatter.id, n]));
429
-
430
- const matches: KnowledgeMatch[] = [];
431
- for (const r of results) {
432
- const note = noteById.get(r.noteId);
433
- if (note) {
434
- matches.push({
435
- note,
436
- score: r.score,
437
- matchType: 'semantic',
438
- });
439
- }
440
- }
441
- return matches;
442
- }
443
-
444
- /**
445
- * Get relevant knowledge for a task using 3-tier retrieval:
446
- * 1. Domain summary match
447
- * 2. Entity name match in task description
448
- * 3. Semantic text similarity search
449
- */
450
- async getRelevantKnowledge(
451
- task: { description: string; domain?: string },
452
- options?: {
453
- maxNotes?: number;
454
- maxTokens?: number;
455
- layers?: GraphLayerName[];
456
- }
457
- ): Promise<KnowledgeMatch[]> {
458
- await this.init();
459
-
460
- const surfacingConfig = this.bankConfig.surfacing;
461
- const maxNotes = options?.maxNotes ?? surfacingConfig.maxNotesPerTask;
462
- const maxTokens = options?.maxTokens ?? surfacingConfig.maxTokensForKnowledge;
463
- const matches: KnowledgeMatch[] = [];
464
- const seenIds = new Set<string>();
465
-
466
- // Tier 1: Domain match
467
- if (surfacingConfig.includeDomainSummaries && task.domain) {
468
- const domainSummary = await this.getDomainSummary(task.domain);
469
- if (domainSummary && !seenIds.has(domainSummary.frontmatter.id)) {
470
- seenIds.add(domainSummary.frontmatter.id);
471
- matches.push({
472
- note: domainSummary,
473
- score: 1.0,
474
- matchType: 'domain',
475
- });
476
- }
477
- }
478
-
479
- // Tier 2: Entity match
480
- if (surfacingConfig.includeEntityNotes) {
481
- const entityNames = await this.listEntities();
482
- const taskLower = task.description.toLowerCase();
483
-
484
- for (const entitySlug of entityNames) {
485
- const entityWords = entitySlug.replace(/-/g, ' ');
486
- if (taskLower.includes(entitySlug) || taskLower.includes(entityWords)) {
487
- if (seenIds.has(entitySlug)) continue;
488
- const entityNote = await this.getEntity(entitySlug);
489
- if (entityNote) {
490
- seenIds.add(entityNote.frontmatter.id);
491
- matches.push({
492
- note: entityNote,
493
- score: 0.9,
494
- matchType: 'entity',
495
- });
496
- }
497
- }
498
- }
499
- }
500
-
501
- // Tier 3: Semantic match
502
- const remainingSlots = maxNotes - matches.length;
503
- if (remainingSlots > 0) {
504
- const searchResults = await this.search(task.description, {
505
- domains: task.domain ? [task.domain] : undefined,
506
- maxResults: remainingSlots + matches.length,
507
- });
508
-
509
- for (const result of searchResults) {
510
- if (seenIds.has(result.note.frontmatter.id)) continue;
511
- seenIds.add(result.note.frontmatter.id);
512
- matches.push(result);
513
- if (matches.length >= maxNotes) break;
514
- }
515
- }
516
-
517
- // Sort: domain > entity > semantic, then by score
518
- matches.sort((a, b) => {
519
- const typeOrder: Record<string, number> = { domain: 0, entity: 1, semantic: 2, graph: 3 };
520
- const typeA = typeOrder[a.matchType ?? 'semantic'];
521
- const typeB = typeOrder[b.matchType ?? 'semantic'];
522
- if (typeA !== typeB) return typeA - typeB;
523
- return b.score - a.score;
524
- });
525
-
526
- // Enforce limits
527
- const limited = matches.slice(0, maxNotes);
528
- return this.enforceTokenBudget(limited, maxTokens);
529
- }
530
-
531
- /**
532
- * Process inbox files: classify, move to correct directory, add to graph.
533
- * Files with valid frontmatter are classified by type field.
534
- * Files without valid frontmatter get heuristic classification as observations.
535
- */
536
- async processInbox(): Promise<InboxResult> {
537
- await this.init();
538
-
539
- let processed = 0;
540
- let failed = 0;
541
- let movedToObservations = 0;
542
- let movedToEntities = 0;
543
- let movedToDomains = 0;
544
-
545
- let files: string[];
546
- try {
547
- files = (await readdir(this.inboxDir)).filter((f) => f.endsWith('.md'));
548
- } catch {
549
- return { processed, failed, movedToObservations, movedToEntities, movedToDomains };
550
- }
551
-
552
- for (const file of files) {
553
- const absPath = join(this.inboxDir, file);
554
- try {
555
- const content = await readFile(absPath, 'utf-8');
556
- const relativePath = `inbox/${file}`;
557
- const parsed = parseKnowledgeNote(content, relativePath);
558
-
559
- let note: KnowledgeNote;
560
- if (parsed && parsed.frontmatter.type) {
561
- // Valid frontmatter — use its type
562
- note = parsed;
563
- } else {
564
- // No valid frontmatter — apply heuristic classification
565
- note = this.processRawInboxFile(content, file);
566
- }
567
-
568
- // Move to correct directory based on type
569
- const result = await this.moveInboxNote(note);
570
- if (result === 'observation') movedToObservations++;
571
- else if (result === 'entity') movedToEntities++;
572
- else if (result === 'domain-summary') movedToDomains++;
573
-
574
- // Add to graph
575
- this.graph.addNode(this.noteToGraphNode(note));
576
-
577
- // Remove from inbox
578
- await unlink(absPath);
579
- processed++;
580
- } catch {
581
- failed++;
582
- }
583
- }
584
-
585
- return { processed, failed, movedToObservations, movedToEntities, movedToDomains };
586
- }
587
-
588
- /**
589
- * Run the full 7-step defragmentation cycle via KnowledgeDefragmenter.
590
- */
591
- async defragment(): Promise<DefragResult> {
592
- await this.init();
593
- const { KnowledgeDefragmenter } = await import('./knowledge-defrag.js');
594
- const defragmenter = new KnowledgeDefragmenter(
595
- this,
596
- this.bankConfig.defrag
597
- );
598
- return defragmenter.defragment();
599
- }
600
-
601
- async applyExtraction(extraction: ExtractedKnowledge): Promise<void> {
602
- await this.init();
603
-
604
- // 1. Add new observations
605
- for (const obs of extraction.observations) {
606
- await this.addObservation(obs);
607
- }
608
-
609
- // 2. Apply entity updates (skip if entity doesn't exist)
610
- for (const update of extraction.entityUpdates) {
611
- try {
612
- await this.updateEntity(update.entityId, update);
613
- } catch {
614
- // Entity doesn't exist yet — skip
615
- }
616
- }
617
-
618
- // 3. Record contradictions
619
- for (const contradiction of extraction.contradictions) {
620
- await this.recordContradiction(contradiction);
621
- }
622
-
623
- // 4. Add graph edges for new links
624
- for (const link of extraction.links) {
625
- const layer = inferLayerFromRelation(link.relation);
626
- const graphLayer = this.graph.getLayer(layer);
627
- if (!graphLayer) continue;
628
-
629
- graphLayer.addEdge({
630
- from: link.from,
631
- to: link.to,
632
- relation: link.relation,
633
- weight: link.weight ?? 0.5,
634
- created: new Date().toISOString(),
635
- });
636
- }
637
-
638
- // 5. Add playbook cross-system links
639
- for (const pbLink of extraction.playbookLinks) {
640
- const semanticLayer = this.graph.getLayer('semantic');
641
- if (!semanticLayer) continue;
642
-
643
- semanticLayer.addEdge({
644
- from: pbLink.noteId,
645
- to: pbLink.playbookId,
646
- relation: pbLink.relation,
647
- weight: 0.5,
648
- created: new Date().toISOString(),
649
- crossSystem: 'playbook',
650
- });
651
- }
652
- }
653
-
654
- /**
655
- * Reinforce a knowledge note with new evidence from a trajectory.
656
- * Uses EMA to increase confidence: newConf = (1 - alpha) * oldConf + alpha * 1.0
657
- */
658
- async reinforce(noteId: string, trajectoryId: string): Promise<void> {
659
- await this.init();
660
-
661
- const note = await this.getNote(noteId);
662
- if (!note) {
663
- throw new Error(`Cannot reinforce: note not found: ${noteId}`);
664
- }
665
-
666
- const alpha = this.bankConfig.confidence.reinforcementAlpha;
667
- note.frontmatter.confidence =
668
- (1 - alpha) * note.frontmatter.confidence + alpha * 1.0;
669
-
670
- // Add trajectory to source (no duplicates)
671
- if (!note.frontmatter.source.trajectories) {
672
- note.frontmatter.source.trajectories = [];
673
- }
674
- if (!note.frontmatter.source.trajectories.includes(trajectoryId)) {
675
- note.frontmatter.source.trajectories.push(trajectoryId);
676
- }
677
-
678
- // Update timestamp
679
- note.frontmatter.updated = new Date().toISOString();
680
-
681
- await this.writeNote(note);
682
- this.graph.addNode(this.noteToGraphNode(note));
683
- }
684
-
685
- async recordContradiction(contradiction: Contradiction): Promise<void> {
686
- await this.init();
687
-
688
- const penalty = this.bankConfig.confidence.contradictionPenalty;
689
-
690
- // Add the new observation if it hasn't been added already
691
- const existingNew = await this.getNote(contradiction.newObservation.frontmatter.id);
692
- if (!existingNew) {
693
- await this.addObservation(contradiction.newObservation);
694
- }
695
-
696
- // Add a 'contradicts' edge in the entity layer
697
- const entityLayer = this.graph.getLayer('entity');
698
- if (entityLayer) {
699
- entityLayer.addEdge({
700
- from: contradiction.newObservation.frontmatter.id,
701
- to: contradiction.existingNoteId,
702
- relation: 'contradicts',
703
- weight: 0.8,
704
- created: new Date().toISOString(),
705
- });
706
- }
707
-
708
- // Load the existing note for confidence updates
709
- const existingNote = await this.getNote(contradiction.existingNoteId);
710
-
711
- if (contradiction.resolution === 'supersede') {
712
- // Old note gets full penalty, new note supersedes
713
- if (existingNote) {
714
- existingNote.frontmatter.confidence = Math.max(
715
- 0,
716
- existingNote.frontmatter.confidence - penalty
717
- );
718
- await this.writeNote(existingNote);
719
- this.graph.addNode(this.noteToGraphNode(existingNote));
720
- }
721
-
722
- contradiction.newObservation.frontmatter.supersedes = contradiction.existingNoteId;
723
- await this.writeNote(contradiction.newObservation);
724
-
725
- // Add temporal 'supersedes' edge
726
- const temporalLayer = this.graph.getLayer('temporal');
727
- if (temporalLayer) {
728
- temporalLayer.addEdge({
729
- from: contradiction.newObservation.frontmatter.id,
730
- to: contradiction.existingNoteId,
731
- relation: 'supersedes',
732
- weight: 1.0,
733
- created: new Date().toISOString(),
734
- });
735
- }
736
- } else if (contradiction.resolution === 'coexist') {
737
- // Both notes get half penalty
738
- const halfPenalty = penalty / 2;
739
-
740
- if (existingNote) {
741
- existingNote.frontmatter.confidence = Math.max(
742
- 0,
743
- existingNote.frontmatter.confidence - halfPenalty
744
- );
745
- await this.writeNote(existingNote);
746
- this.graph.addNode(this.noteToGraphNode(existingNote));
747
- }
748
-
749
- const newNote = await this.getNote(contradiction.newObservation.frontmatter.id);
750
- if (newNote) {
751
- newNote.frontmatter.confidence = Math.max(
752
- 0,
753
- newNote.frontmatter.confidence - halfPenalty
754
- );
755
- await this.writeNote(newNote);
756
- this.graph.addNode(this.noteToGraphNode(newNote));
757
- }
758
- } else if (contradiction.resolution === 'review') {
759
- // No confidence change, tag both for review
760
- if (existingNote) {
761
- if (!existingNote.frontmatter.tags.includes('needs-review')) {
762
- existingNote.frontmatter.tags.push('needs-review');
763
- await this.writeNote(existingNote);
764
- this.graph.addNode(this.noteToGraphNode(existingNote));
765
- }
766
- }
767
-
768
- const newNote = await this.getNote(contradiction.newObservation.frontmatter.id);
769
- if (newNote && !newNote.frontmatter.tags.includes('needs-review')) {
770
- newNote.frontmatter.tags.push('needs-review');
771
- await this.writeNote(newNote);
772
- this.graph.addNode(this.noteToGraphNode(newNote));
773
- }
774
- }
775
- }
776
-
777
- /**
778
- * Apply time-based confidence decay to all knowledge notes.
779
- * Skips domain summaries, notes already tagged stale, and notes within the grace period.
780
- */
781
- async applyDecay(): Promise<DecayResult> {
782
- await this.init();
783
-
784
- const { dailyDecayRate, staleThreshold, decayGracePeriodDays } =
785
- this.bankConfig.confidence;
786
- const now = Date.now();
787
- const msPerDay = 1000 * 60 * 60 * 24;
788
-
789
- let decayed = 0;
790
- let newlyStale = 0;
791
- let alreadyStale = 0;
792
-
793
- // Scan observations and entities (skip domain summaries)
794
- const [observations, entities] = await Promise.all([
795
- this.scanDirectory(this.observationsDir),
796
- this.scanDirectory(this.entitiesDir),
797
- ]);
798
-
799
- for (const note of [...observations, ...entities]) {
800
- // Skip already stale notes
801
- if (note.frontmatter.tags.includes('stale')) {
802
- alreadyStale++;
803
- continue;
804
- }
805
-
806
- // Compute days since last update
807
- const updatedMs = new Date(note.frontmatter.updated).getTime();
808
- const daysSinceUpdated = (now - updatedMs) / msPerDay;
809
-
810
- // Skip notes within grace period
811
- if (daysSinceUpdated <= decayGracePeriodDays) {
812
- continue;
813
- }
814
-
815
- // Apply exponential decay: newConf = oldConf * (1 - rate)^(days - grace)
816
- const decayDays = daysSinceUpdated - decayGracePeriodDays;
817
- const newConfidence =
818
- note.frontmatter.confidence * Math.pow(1 - dailyDecayRate, decayDays);
819
- note.frontmatter.confidence = Math.max(0, newConfidence);
820
-
821
- // Mark as stale if below threshold
822
- if (note.frontmatter.confidence < staleThreshold) {
823
- if (!note.frontmatter.tags.includes('stale')) {
824
- note.frontmatter.tags.push('stale');
825
- newlyStale++;
826
- }
827
- }
828
-
829
- // Write to disk without updating the 'updated' timestamp
830
- await this.writeNote(note);
831
- this.graph.addNode(this.noteToGraphNode(note));
832
- decayed++;
833
- }
834
-
835
- return { decayed, newlyStale, alreadyStale };
836
- }
837
-
838
- // =========================================================================
839
- // Extraction (Phase 2)
840
- // =========================================================================
841
-
842
- /**
843
- * Extract knowledge from a trajectory source.
844
- * Iterates all trajectories, runs extraction (agent or heuristic), and applies results.
845
- */
846
- async extractFrom(
847
- source: TrajectorySource,
848
- options?: {
849
- taskRunner?: AgenticTaskRunner;
850
- analyzer?: TrajectoryAnalyzer;
851
- }
852
- ): Promise<ExtractedKnowledge[]> {
853
- await this.init();
854
-
855
- const items = await source.load();
856
- const results: ExtractedKnowledge[] = [];
857
-
858
- for (const item of items) {
859
- let analysis = item.analysis;
860
- if (!analysis && options?.analyzer) {
861
- analysis = await options.analyzer.analyze(item.trajectory);
862
- }
863
-
864
- const extraction = await this.extractFromTrajectory(
865
- item.trajectory,
866
- analysis,
867
- options?.taskRunner
868
- );
869
- results.push(extraction);
870
- }
871
-
872
- return results;
873
- }
874
-
875
- /**
876
- * Extract knowledge from a single trajectory.
877
- * Uses the workspace template if a taskRunner is provided, otherwise falls back to heuristic.
878
- * Applies the extraction to the knowledge bank.
879
- */
880
- async extractFromTrajectory(
881
- trajectory: Trajectory,
882
- analysis?: AnalysisResult,
883
- taskRunner?: AgenticTaskRunner
884
- ): Promise<ExtractedKnowledge> {
885
- await this.init();
886
-
887
- // Compute analysis if not provided
888
- const { createAnalyzer } = await import('../learning/analyzer.js');
889
- const resolvedAnalysis = analysis ?? await createAnalyzer('simple').analyze(trajectory);
890
-
891
- // Gather context for extraction
892
- const existingEntities = await this.listEntities();
893
- const relatedNotes = await this.getAllNotes();
894
-
895
- // Try workspace-based extraction if taskRunner is available
896
- if (taskRunner) {
897
- try {
898
- const { knowledgeExtractionTemplate } = await import(
899
- '../workspace/templates/knowledge-extraction.js'
900
- );
901
- const result = await taskRunner.run(knowledgeExtractionTemplate, {
902
- trajectory,
903
- analysis: resolvedAnalysis,
904
- existingEntities,
905
- relatedNotes: relatedNotes.slice(0, 20),
906
- });
907
- const extraction = result.output;
908
- await this.applyExtraction(extraction);
909
- return extraction;
910
- } catch (error) {
911
- console.error(
912
- 'Workspace-based knowledge extraction failed, falling back to heuristic:',
913
- error instanceof Error ? error.message : error
914
- );
915
- }
916
- }
917
-
918
- // Heuristic fallback
919
- const { KnowledgeExtractor } = await import(
920
- '../learning/knowledge-extractor.js'
921
- );
922
- const extractor = new KnowledgeExtractor();
923
- const extraction = extractor.extract(trajectory, resolvedAnalysis, {
924
- existingEntities,
925
- });
926
- await this.applyExtraction(extraction);
927
- return extraction;
928
- }
929
-
930
- /**
931
- * Format knowledge notes as a markdown section for agent prompt injection.
932
- * Groups by type: domain summaries → entities → observations.
933
- */
934
- formatKnowledgeForPrompt(
935
- notes: KnowledgeMatch[],
936
- options?: {
937
- maxTokens?: number;
938
- includeEvidence?: boolean;
939
- includeLinks?: boolean;
940
- }
941
- ): string {
942
- if (notes.length === 0) return '';
943
-
944
- const includeEvidence =
945
- options?.includeEvidence ?? this.bankConfig.surfacing.includeEvidence;
946
- const includeLinks =
947
- options?.includeLinks ?? this.bankConfig.surfacing.includeLinks;
948
- const maxTokens =
949
- options?.maxTokens ?? this.bankConfig.surfacing.maxTokensForKnowledge;
950
-
951
- const sections: string[] = [];
952
- sections.push('## Relevant Knowledge\n');
953
-
954
- // Group by type
955
- const domainSummaries = notes.filter(
956
- (m) => m.note.frontmatter.type === 'domain-summary'
957
- );
958
- const entities = notes.filter(
959
- (m) => m.note.frontmatter.type === 'entity'
960
- );
961
- const observations = notes.filter(
962
- (m) => m.note.frontmatter.type === 'observation'
963
- );
964
-
965
- let tokenCount = 0;
966
-
967
- for (const group of [domainSummaries, entities, observations]) {
968
- for (const match of group) {
969
- const noteSection = this.formatSingleNote(
970
- match,
971
- includeEvidence,
972
- includeLinks
973
- );
974
- const sectionTokens = Math.ceil(noteSection.length / 4);
975
-
976
- if (tokenCount + sectionTokens > maxTokens && sections.length > 1) {
977
- break;
978
- }
979
-
980
- sections.push(noteSection);
981
- tokenCount += sectionTokens;
982
- }
983
- }
984
-
985
- return sections.join('\n');
986
- }
987
-
988
- // =========================================================================
989
- // Search Provider
990
- // =========================================================================
991
-
992
- /**
993
- * Get the name of the active search provider.
994
- */
995
- getSearchProviderName(): string {
996
- return this.searchProvider.name;
997
- }
998
-
999
- /**
1000
- * Replace the active search provider (strategy pattern).
1001
- */
1002
- setSearchProvider(provider: SearchProvider): void {
1003
- this.searchProvider = provider;
1004
- }
1005
-
1006
- // =========================================================================
1007
- // Internal Helpers
1008
- // =========================================================================
1009
-
1010
- /**
1011
- * Detect whether minimem is available and set up the MinimemSearchProvider.
1012
- *
1013
- * Detection checks (in order):
1014
- * 1. Look for a `.minimem/` directory under memoryDir
1015
- * 2. Look for a `MEMORY.md` file under memoryDir
1016
- * 3. Create a Minimem instance and wire MinimemSearchProvider
1017
- *
1018
- * Falls back to TextSimilaritySearchProvider on any failure.
1019
- */
1020
- private async detectMinimem(): Promise<void> {
1021
- try {
1022
- // Check for minimem markers
1023
- const minimemDir = join(this.memoryDir, '.minimem');
1024
- const memoryMd = join(this.memoryDir, 'MEMORY.md');
1025
-
1026
- let hasMinimemMarker = false;
1027
- try {
1028
- await access(minimemDir);
1029
- hasMinimemMarker = true;
1030
- } catch {
1031
- try {
1032
- await access(memoryMd);
1033
- hasMinimemMarker = true;
1034
- } catch {
1035
- // No minimem markers found
1036
- }
1037
- }
1038
-
1039
- if (!hasMinimemMarker) return;
1040
-
1041
- // minimem is a direct dependency — use normal dynamic import
1042
- try {
1043
- const { Minimem } = await import('minimem');
1044
- const minimemInstance = await Minimem.create({
1045
- memoryDir: this.memoryDir,
1046
- embedding: { provider: 'auto' },
1047
- });
1048
-
1049
- const { MinimemSearchProvider } = await import(
1050
- './search-providers/minimem.js'
1051
- );
1052
- this.searchProvider = new MinimemSearchProvider(minimemInstance);
1053
- } catch {
1054
- // minimem initialization failed — keep text-similarity fallback
1055
- }
1056
- } catch {
1057
- // Detection failed — keep text-similarity fallback
1058
- }
1059
- }
1060
-
1061
- /**
1062
- * Get the index directory path (for defragmenter).
1063
- */
1064
- getIndexDir(): string {
1065
- return this.indexDir;
1066
- }
1067
-
1068
- /**
1069
- * Check if defragmentation should be triggered.
1070
- */
1071
- async shouldDefragment(): Promise<boolean> {
1072
- await this.init();
1073
- const inboxCount = await this.countFiles(this.inboxDir);
1074
- return inboxCount >= this.bankConfig.defrag.minInboxItems;
1075
- }
1076
-
1077
- /**
1078
- * Resolve a note's file path and write it to disk.
1079
- */
1080
- private async writeNote(note: KnowledgeNote): Promise<void> {
1081
- // Resolve the file path: when minimemAware, remap knowledge/ → memory/knowledge/
1082
- if (
1083
- this.bankConfig.minimemAware &&
1084
- note.filePath.startsWith('knowledge/') &&
1085
- !note.filePath.startsWith('memory/knowledge/')
1086
- ) {
1087
- note.filePath = `memory/${note.filePath}`;
1088
- }
1089
-
1090
- const absPath = join(this.memoryDir, note.filePath);
1091
- const dir = absPath.substring(0, absPath.lastIndexOf('/'));
1092
- await mkdir(dir, { recursive: true });
1093
- const content = serializeKnowledgeNote(note);
1094
- await writeFile(absPath, content, 'utf-8');
1095
- }
1096
-
1097
- /**
1098
- * Scan a directory for .md files and parse them as KnowledgeNotes.
1099
- * Skips files with invalid/missing frontmatter.
1100
- */
1101
- private async scanDirectory(dir: string): Promise<KnowledgeNote[]> {
1102
- const notes: KnowledgeNote[] = [];
1103
-
1104
- try {
1105
- const files = await readdir(dir);
1106
- for (const file of files) {
1107
- if (!file.endsWith('.md')) continue;
1108
-
1109
- try {
1110
- const absPath = join(dir, file);
1111
- const content = await readFile(absPath, 'utf-8');
1112
- const relativePath = relative(this.memoryDir, absPath);
1113
- const note = parseKnowledgeNote(content, relativePath);
1114
- if (note) notes.push(note);
1115
- } catch {
1116
- // Skip files that can't be read
1117
- }
1118
- }
1119
- } catch {
1120
- // Directory doesn't exist yet
1121
- }
1122
-
1123
- return notes;
1124
- }
1125
-
1126
- /**
1127
- * Count .md files in a directory.
1128
- */
1129
- private async countFiles(dir: string): Promise<number> {
1130
- try {
1131
- const files = await readdir(dir);
1132
- return files.filter((f) => f.endsWith('.md')).length;
1133
- } catch {
1134
- return 0;
1135
- }
1136
- }
1137
-
1138
- /**
1139
- * Resolve the relative path for a note based on its type and filename.
1140
- * When minimemAware, paths are nested under memory/knowledge/ instead of knowledge/.
1141
- */
1142
- private resolveNotePath(
1143
- type: 'observation' | 'entity' | 'domain-summary',
1144
- filename: string
1145
- ): string {
1146
- const knowledgePrefix = this.bankConfig.minimemAware
1147
- ? 'memory/knowledge'
1148
- : 'knowledge';
1149
-
1150
- if (type === 'entity') {
1151
- return `${knowledgePrefix}/entities/${filename}`;
1152
- } else if (type === 'domain-summary') {
1153
- return `${knowledgePrefix}/domains/${filename}`;
1154
- }
1155
- return `${knowledgePrefix}/observations/${filename}`;
1156
- }
1157
-
1158
- /**
1159
- * Move an inbox note to the correct directory based on its type.
1160
- * Updates the note's filePath accordingly.
1161
- */
1162
- private async moveInboxNote(
1163
- note: KnowledgeNote
1164
- ): Promise<'observation' | 'entity' | 'domain-summary'> {
1165
- const type = note.frontmatter.type;
1166
- const noteType: 'observation' | 'entity' | 'domain-summary' =
1167
- type === 'entity' ? 'entity' : type === 'domain-summary' ? 'domain-summary' : 'observation';
1168
-
1169
- const filename = `${note.frontmatter.id}.md`;
1170
- note.filePath = this.resolveNotePath(noteType, filename);
1171
- await this.writeNote(note);
1172
-
1173
- return noteType;
1174
- }
1175
-
1176
- /**
1177
- * Create a KnowledgeNote from a raw inbox file with no valid frontmatter.
1178
- * Applies heuristic: observation type, agent-authored origin, agentAuthoredInitial confidence.
1179
- */
1180
- private processRawInboxFile(content: string, filename: string): KnowledgeNote {
1181
- const id = filename.replace('.md', '');
1182
- const title = id.replace(/[-_]/g, ' ');
1183
-
1184
- return createObservation({
1185
- id,
1186
- title,
1187
- body: content,
1188
- domain: [],
1189
- entities: [],
1190
- tags: ['inbox-processed'],
1191
- confidence: this.bankConfig.confidence.agentAuthoredInitial,
1192
- source: { origin: 'agent-authored' as const },
1193
- });
1194
- }
1195
-
1196
- /**
1197
- * Convert a KnowledgeNote to a GraphNode.
1198
- */
1199
- /**
1200
- * Enforce a token budget on a list of matches.
1201
- * Always includes at least one match.
1202
- */
1203
- private enforceTokenBudget(
1204
- matches: KnowledgeMatch[],
1205
- maxTokens: number
1206
- ): KnowledgeMatch[] {
1207
- const result: KnowledgeMatch[] = [];
1208
- let usedTokens = 0;
1209
-
1210
- for (const match of matches) {
1211
- const noteTokens = Math.ceil(match.note.body.length / 4);
1212
- if (usedTokens + noteTokens > maxTokens && result.length > 0) {
1213
- break;
1214
- }
1215
- result.push(match);
1216
- usedTokens += noteTokens;
1217
- }
1218
-
1219
- return result;
1220
- }
1221
-
1222
- /**
1223
- * Format a single knowledge note for prompt injection.
1224
- */
1225
- private formatSingleNote(
1226
- match: KnowledgeMatch,
1227
- includeEvidence: boolean,
1228
- includeLinks: boolean
1229
- ): string {
1230
- const { note } = match;
1231
- const confidencePercent = Math.round(note.frontmatter.confidence * 100);
1232
- const lines: string[] = [];
1233
-
1234
- // Title line with type-appropriate heading
1235
- if (note.frontmatter.type === 'domain-summary') {
1236
- lines.push(
1237
- `### ${note.frontmatter.domain[0] ?? 'General'} Overview (${confidencePercent}% confidence)`
1238
- );
1239
- } else if (note.frontmatter.type === 'entity') {
1240
- const entityName = note.frontmatter.entities[0] ?? note.frontmatter.id;
1241
- lines.push(
1242
- `### About ${entityName} (${confidencePercent}% confidence)`
1243
- );
1244
- } else {
1245
- lines.push(
1246
- `### ${note.frontmatter.id} (${confidencePercent}% confidence)`
1247
- );
1248
- }
1249
-
1250
- // Body content — skip leading markdown heading
1251
- let bodyContent = note.body;
1252
- const firstLine = bodyContent.split('\n')[0];
1253
- if (firstLine.startsWith('#')) {
1254
- bodyContent = bodyContent.slice(firstLine.length).trim();
1255
- }
1256
- if (bodyContent.length > 500) {
1257
- bodyContent = bodyContent.slice(0, 497) + '...';
1258
- }
1259
- lines.push(bodyContent);
1260
-
1261
- // Evidence citations
1262
- if (includeEvidence && note.frontmatter.source.trajectories?.length) {
1263
- const trajectoryIds = note.frontmatter.source.trajectories.slice(0, 3);
1264
- lines.push(`\n*Evidence: ${trajectoryIds.join(', ')}*`);
1265
- }
1266
-
1267
- // Graph links
1268
- if (includeLinks && note.frontmatter.links.length > 0) {
1269
- const linkSummary = note.frontmatter.links
1270
- .slice(0, 3)
1271
- .map((l) => `${l.relation} ${l.target}`)
1272
- .join(', ');
1273
- lines.push(`*Related: ${linkSummary}*`);
1274
- }
1275
-
1276
- lines.push('');
1277
- return lines.join('\n');
1278
- }
1279
-
1280
- /**
1281
- * Get notes related to the given note by entity or domain overlap.
1282
- * Used for coherence checking before insertion.
1283
- */
1284
- private async getRelatedNotes(note: KnowledgeNote): Promise<KnowledgeNote[]> {
1285
- const allNotes = await this.getAllNotes();
1286
-
1287
- const noteEntities = new Set(note.frontmatter.entities);
1288
- const noteDomains = new Set(note.frontmatter.domain);
1289
-
1290
- return allNotes.filter((existing) => {
1291
- if (existing.frontmatter.id === note.frontmatter.id) return false;
1292
-
1293
- const hasEntityOverlap = existing.frontmatter.entities.some((e) =>
1294
- noteEntities.has(e)
1295
- );
1296
- if (hasEntityOverlap) return true;
1297
-
1298
- const hasDomainOverlap = existing.frontmatter.domain.some((d) =>
1299
- noteDomains.has(d)
1300
- );
1301
- return hasDomainOverlap;
1302
- });
1303
- }
1304
-
1305
- private noteToGraphNode(note: KnowledgeNote): GraphNode {
1306
- return {
1307
- id: note.frontmatter.id,
1308
- file: note.filePath,
1309
- type: note.frontmatter.type,
1310
- domains: note.frontmatter.domain,
1311
- entities: note.frontmatter.entities,
1312
- tags: note.frontmatter.tags,
1313
- confidence: note.frontmatter.confidence,
1314
- updated: note.frontmatter.updated,
1315
- };
1316
- }
1317
- }