cognitive-core 0.0.2 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (857) hide show
  1. package/.claude/settings.json +88 -0
  2. package/.claude/settings.local.json +11 -0
  3. package/.entire/settings.json +4 -0
  4. package/README.md +563 -107
  5. package/SKILL.md +193 -0
  6. package/dist/agents/index.d.ts +3 -0
  7. package/dist/agents/index.d.ts.map +1 -0
  8. package/dist/agents/index.js +5 -0
  9. package/dist/agents/index.js.map +1 -0
  10. package/dist/agents/mock-provider.d.ts +23 -0
  11. package/dist/agents/mock-provider.d.ts.map +1 -0
  12. package/dist/agents/mock-provider.js +71 -0
  13. package/dist/agents/mock-provider.js.map +1 -0
  14. package/dist/agents/types.d.ts +98 -0
  15. package/dist/agents/types.d.ts.map +1 -0
  16. package/dist/agents/types.js +44 -0
  17. package/dist/agents/types.js.map +1 -0
  18. package/dist/atlas.d.ts +334 -0
  19. package/dist/atlas.d.ts.map +1 -0
  20. package/dist/atlas.js +702 -0
  21. package/dist/atlas.js.map +1 -0
  22. package/dist/bin/cognitive-core.d.ts +18 -0
  23. package/dist/bin/cognitive-core.d.ts.map +1 -0
  24. package/dist/bin/cognitive-core.js +419 -0
  25. package/dist/bin/cognitive-core.js.map +1 -0
  26. package/dist/embeddings/bm25.d.ts +104 -0
  27. package/dist/embeddings/bm25.d.ts.map +1 -0
  28. package/dist/embeddings/bm25.js +264 -0
  29. package/dist/embeddings/bm25.js.map +1 -0
  30. package/dist/embeddings/index.d.ts +12 -0
  31. package/dist/embeddings/index.d.ts.map +1 -0
  32. package/dist/embeddings/index.js +16 -0
  33. package/dist/embeddings/index.js.map +1 -0
  34. package/dist/embeddings/manager.d.ts +112 -0
  35. package/dist/embeddings/manager.d.ts.map +1 -0
  36. package/dist/embeddings/manager.js +215 -0
  37. package/dist/embeddings/manager.js.map +1 -0
  38. package/dist/embeddings/provider.d.ts +101 -0
  39. package/dist/embeddings/provider.d.ts.map +1 -0
  40. package/dist/embeddings/provider.js +235 -0
  41. package/dist/embeddings/provider.js.map +1 -0
  42. package/dist/embeddings/vector-store.d.ts +101 -0
  43. package/dist/embeddings/vector-store.d.ts.map +1 -0
  44. package/dist/embeddings/vector-store.js +256 -0
  45. package/dist/embeddings/vector-store.js.map +1 -0
  46. package/dist/factory.d.ts +193 -0
  47. package/dist/factory.d.ts.map +1 -0
  48. package/dist/factory.js +109 -0
  49. package/dist/factory.js.map +1 -0
  50. package/dist/index.d.ts +32 -453
  51. package/dist/index.d.ts.map +1 -0
  52. package/dist/index.js +115 -509
  53. package/dist/index.js.map +1 -0
  54. package/dist/learning/analyzer.d.ts +110 -0
  55. package/dist/learning/analyzer.d.ts.map +1 -0
  56. package/dist/learning/analyzer.js +213 -0
  57. package/dist/learning/analyzer.js.map +1 -0
  58. package/dist/learning/effectiveness.d.ts +158 -0
  59. package/dist/learning/effectiveness.d.ts.map +1 -0
  60. package/dist/learning/effectiveness.js +251 -0
  61. package/dist/learning/effectiveness.js.map +1 -0
  62. package/dist/learning/index.d.ts +12 -0
  63. package/dist/learning/index.d.ts.map +1 -0
  64. package/dist/learning/index.js +17 -0
  65. package/dist/learning/index.js.map +1 -0
  66. package/dist/learning/knowledge-extractor.d.ts +56 -0
  67. package/dist/learning/knowledge-extractor.d.ts.map +1 -0
  68. package/dist/learning/knowledge-extractor.js +336 -0
  69. package/dist/learning/knowledge-extractor.js.map +1 -0
  70. package/dist/learning/llm-extractor.d.ts +88 -0
  71. package/dist/learning/llm-extractor.d.ts.map +1 -0
  72. package/dist/learning/llm-extractor.js +372 -0
  73. package/dist/learning/llm-extractor.js.map +1 -0
  74. package/dist/learning/meta-learner.d.ts +87 -0
  75. package/dist/learning/meta-learner.d.ts.map +1 -0
  76. package/dist/learning/meta-learner.js +398 -0
  77. package/dist/learning/meta-learner.js.map +1 -0
  78. package/dist/learning/pipeline.d.ts +89 -0
  79. package/dist/learning/pipeline.d.ts.map +1 -0
  80. package/dist/learning/pipeline.js +236 -0
  81. package/dist/learning/pipeline.js.map +1 -0
  82. package/dist/learning/playbook-extractor.d.ts +113 -0
  83. package/dist/learning/playbook-extractor.d.ts.map +1 -0
  84. package/dist/learning/playbook-extractor.js +523 -0
  85. package/dist/learning/playbook-extractor.js.map +1 -0
  86. package/dist/learning/team-ingester.d.ts +152 -0
  87. package/dist/learning/team-ingester.d.ts.map +1 -0
  88. package/dist/learning/team-ingester.js +333 -0
  89. package/dist/learning/team-ingester.js.map +1 -0
  90. package/dist/learning/team-meta-learner.d.ts +50 -0
  91. package/dist/learning/team-meta-learner.d.ts.map +1 -0
  92. package/dist/learning/team-meta-learner.js +417 -0
  93. package/dist/learning/team-meta-learner.js.map +1 -0
  94. package/dist/learning/team-pipeline.d.ts +76 -0
  95. package/dist/learning/team-pipeline.d.ts.map +1 -0
  96. package/dist/learning/team-pipeline.js +266 -0
  97. package/dist/learning/team-pipeline.js.map +1 -0
  98. package/dist/learning/trajectory-sources/dataclaw.d.ts +41 -0
  99. package/dist/learning/trajectory-sources/dataclaw.d.ts.map +1 -0
  100. package/dist/learning/trajectory-sources/dataclaw.js +330 -0
  101. package/dist/learning/trajectory-sources/dataclaw.js.map +1 -0
  102. package/dist/learning/trajectory-sources/entire.d.ts +28 -0
  103. package/dist/learning/trajectory-sources/entire.d.ts.map +1 -0
  104. package/dist/learning/trajectory-sources/entire.js +182 -0
  105. package/dist/learning/trajectory-sources/entire.js.map +1 -0
  106. package/dist/learning/trajectory-sources/file.d.ts +23 -0
  107. package/dist/learning/trajectory-sources/file.d.ts.map +1 -0
  108. package/dist/learning/trajectory-sources/file.js +101 -0
  109. package/dist/learning/trajectory-sources/file.js.map +1 -0
  110. package/dist/learning/trajectory-sources/huggingface.d.ts +36 -0
  111. package/dist/learning/trajectory-sources/huggingface.d.ts.map +1 -0
  112. package/dist/learning/trajectory-sources/huggingface.js +157 -0
  113. package/dist/learning/trajectory-sources/huggingface.js.map +1 -0
  114. package/dist/learning/trajectory-sources/in-memory.d.ts +21 -0
  115. package/dist/learning/trajectory-sources/in-memory.d.ts.map +1 -0
  116. package/dist/learning/trajectory-sources/in-memory.js +43 -0
  117. package/dist/learning/trajectory-sources/in-memory.js.map +1 -0
  118. package/dist/learning/trajectory-sources/index.d.ts +7 -0
  119. package/dist/learning/trajectory-sources/index.d.ts.map +1 -0
  120. package/dist/learning/trajectory-sources/index.js +7 -0
  121. package/dist/learning/trajectory-sources/index.js.map +1 -0
  122. package/dist/learning/trajectory-sources/pipeline.d.ts +24 -0
  123. package/dist/learning/trajectory-sources/pipeline.d.ts.map +1 -0
  124. package/dist/learning/trajectory-sources/pipeline.js +47 -0
  125. package/dist/learning/trajectory-sources/pipeline.js.map +1 -0
  126. package/dist/learning/usage-inference.d.ts +82 -0
  127. package/dist/learning/usage-inference.d.ts.map +1 -0
  128. package/dist/learning/usage-inference.js +261 -0
  129. package/dist/learning/usage-inference.js.map +1 -0
  130. package/dist/mcp/index.d.ts +6 -0
  131. package/dist/mcp/index.d.ts.map +1 -0
  132. package/dist/mcp/index.js +6 -0
  133. package/dist/mcp/index.js.map +1 -0
  134. package/dist/mcp/playbook-server.d.ts +120 -0
  135. package/dist/mcp/playbook-server.d.ts.map +1 -0
  136. package/dist/mcp/playbook-server.js +427 -0
  137. package/dist/mcp/playbook-server.js.map +1 -0
  138. package/dist/memory/curated-loader.d.ts +62 -0
  139. package/dist/memory/curated-loader.d.ts.map +1 -0
  140. package/dist/memory/curated-loader.js +106 -0
  141. package/dist/memory/curated-loader.js.map +1 -0
  142. package/dist/memory/experience.d.ts +122 -0
  143. package/dist/memory/experience.d.ts.map +1 -0
  144. package/dist/memory/experience.js +392 -0
  145. package/dist/memory/experience.js.map +1 -0
  146. package/dist/memory/graph-layers/base.d.ts +29 -0
  147. package/dist/memory/graph-layers/base.d.ts.map +1 -0
  148. package/dist/memory/graph-layers/base.js +143 -0
  149. package/dist/memory/graph-layers/base.js.map +1 -0
  150. package/dist/memory/graph-layers/causal.d.ts +14 -0
  151. package/dist/memory/graph-layers/causal.d.ts.map +1 -0
  152. package/dist/memory/graph-layers/causal.js +14 -0
  153. package/dist/memory/graph-layers/causal.js.map +1 -0
  154. package/dist/memory/graph-layers/entity.d.ts +14 -0
  155. package/dist/memory/graph-layers/entity.d.ts.map +1 -0
  156. package/dist/memory/graph-layers/entity.js +14 -0
  157. package/dist/memory/graph-layers/entity.js.map +1 -0
  158. package/dist/memory/graph-layers/index.d.ts +6 -0
  159. package/dist/memory/graph-layers/index.d.ts.map +1 -0
  160. package/dist/memory/graph-layers/index.js +6 -0
  161. package/dist/memory/graph-layers/index.js.map +1 -0
  162. package/dist/memory/graph-layers/semantic.d.ts +14 -0
  163. package/dist/memory/graph-layers/semantic.d.ts.map +1 -0
  164. package/dist/memory/graph-layers/semantic.js +14 -0
  165. package/dist/memory/graph-layers/semantic.js.map +1 -0
  166. package/dist/memory/graph-layers/temporal.d.ts +14 -0
  167. package/dist/memory/graph-layers/temporal.d.ts.map +1 -0
  168. package/dist/memory/graph-layers/temporal.js +14 -0
  169. package/dist/memory/graph-layers/temporal.js.map +1 -0
  170. package/dist/memory/index.d.ts +14 -0
  171. package/dist/memory/index.d.ts.map +1 -0
  172. package/dist/memory/index.js +19 -0
  173. package/dist/memory/index.js.map +1 -0
  174. package/dist/memory/knowledge-bank.d.ts +220 -0
  175. package/dist/memory/knowledge-bank.d.ts.map +1 -0
  176. package/dist/memory/knowledge-bank.js +1003 -0
  177. package/dist/memory/knowledge-bank.js.map +1 -0
  178. package/dist/memory/knowledge-defrag.d.ts +49 -0
  179. package/dist/memory/knowledge-defrag.d.ts.map +1 -0
  180. package/dist/memory/knowledge-defrag.js +257 -0
  181. package/dist/memory/knowledge-defrag.js.map +1 -0
  182. package/dist/memory/knowledge-graph.d.ts +41 -0
  183. package/dist/memory/knowledge-graph.d.ts.map +1 -0
  184. package/dist/memory/knowledge-graph.js +273 -0
  185. package/dist/memory/knowledge-graph.js.map +1 -0
  186. package/dist/memory/meta.d.ts +90 -0
  187. package/dist/memory/meta.d.ts.map +1 -0
  188. package/dist/memory/meta.js +362 -0
  189. package/dist/memory/meta.js.map +1 -0
  190. package/dist/memory/playbook.d.ts +133 -0
  191. package/dist/memory/playbook.d.ts.map +1 -0
  192. package/dist/memory/playbook.js +357 -0
  193. package/dist/memory/playbook.js.map +1 -0
  194. package/dist/memory/search-provider.d.ts +31 -0
  195. package/dist/memory/search-provider.d.ts.map +1 -0
  196. package/dist/memory/search-provider.js +2 -0
  197. package/dist/memory/search-provider.js.map +1 -0
  198. package/dist/memory/search-providers/index.d.ts +3 -0
  199. package/dist/memory/search-providers/index.d.ts.map +1 -0
  200. package/dist/memory/search-providers/index.js +3 -0
  201. package/dist/memory/search-providers/index.js.map +1 -0
  202. package/dist/memory/search-providers/minimem.d.ts +43 -0
  203. package/dist/memory/search-providers/minimem.d.ts.map +1 -0
  204. package/dist/memory/search-providers/minimem.js +56 -0
  205. package/dist/memory/search-providers/minimem.js.map +1 -0
  206. package/dist/memory/search-providers/text-similarity.d.ts +15 -0
  207. package/dist/memory/search-providers/text-similarity.d.ts.map +1 -0
  208. package/dist/memory/search-providers/text-similarity.js +21 -0
  209. package/dist/memory/search-providers/text-similarity.js.map +1 -0
  210. package/dist/memory/skill-exporter.d.ts +75 -0
  211. package/dist/memory/skill-exporter.d.ts.map +1 -0
  212. package/dist/memory/skill-exporter.js +248 -0
  213. package/dist/memory/skill-exporter.js.map +1 -0
  214. package/dist/memory/system.d.ts +179 -0
  215. package/dist/memory/system.d.ts.map +1 -0
  216. package/dist/memory/system.js +421 -0
  217. package/dist/memory/system.js.map +1 -0
  218. package/dist/memory/team-experience.d.ts +298 -0
  219. package/dist/memory/team-experience.d.ts.map +1 -0
  220. package/dist/memory/team-experience.js +355 -0
  221. package/dist/memory/team-experience.js.map +1 -0
  222. package/dist/runtime/backends/acp-protocol.d.ts +49 -0
  223. package/dist/runtime/backends/acp-protocol.d.ts.map +1 -0
  224. package/dist/runtime/backends/acp-protocol.js +166 -0
  225. package/dist/runtime/backends/acp-protocol.js.map +1 -0
  226. package/dist/runtime/backends/acp.d.ts +67 -0
  227. package/dist/runtime/backends/acp.d.ts.map +1 -0
  228. package/dist/runtime/backends/acp.js +166 -0
  229. package/dist/runtime/backends/acp.js.map +1 -0
  230. package/dist/runtime/backends/index.d.ts +7 -0
  231. package/dist/runtime/backends/index.d.ts.map +1 -0
  232. package/dist/runtime/backends/index.js +8 -0
  233. package/dist/runtime/backends/index.js.map +1 -0
  234. package/dist/runtime/backends/macro-agent.d.ts +104 -0
  235. package/dist/runtime/backends/macro-agent.d.ts.map +1 -0
  236. package/dist/runtime/backends/macro-agent.js +107 -0
  237. package/dist/runtime/backends/macro-agent.js.map +1 -0
  238. package/dist/runtime/backends/mock.d.ts +67 -0
  239. package/dist/runtime/backends/mock.d.ts.map +1 -0
  240. package/dist/runtime/backends/mock.js +153 -0
  241. package/dist/runtime/backends/mock.js.map +1 -0
  242. package/dist/runtime/backends/subprocess.d.ts +56 -0
  243. package/dist/runtime/backends/subprocess.d.ts.map +1 -0
  244. package/dist/runtime/backends/subprocess.js +260 -0
  245. package/dist/runtime/backends/subprocess.js.map +1 -0
  246. package/dist/runtime/compute-provider.d.ts +87 -0
  247. package/dist/runtime/compute-provider.d.ts.map +1 -0
  248. package/dist/runtime/compute-provider.js +87 -0
  249. package/dist/runtime/compute-provider.js.map +1 -0
  250. package/dist/runtime/flows/learning.d.ts +73 -0
  251. package/dist/runtime/flows/learning.d.ts.map +1 -0
  252. package/dist/runtime/flows/learning.js +116 -0
  253. package/dist/runtime/flows/learning.js.map +1 -0
  254. package/dist/runtime/flows/validation.d.ts +122 -0
  255. package/dist/runtime/flows/validation.d.ts.map +1 -0
  256. package/dist/runtime/flows/validation.js +223 -0
  257. package/dist/runtime/flows/validation.js.map +1 -0
  258. package/dist/runtime/index.d.ts +7 -0
  259. package/dist/runtime/index.d.ts.map +1 -0
  260. package/dist/runtime/index.js +10 -0
  261. package/dist/runtime/index.js.map +1 -0
  262. package/dist/runtime/manager.d.ts +149 -0
  263. package/dist/runtime/manager.d.ts.map +1 -0
  264. package/dist/runtime/manager.js +535 -0
  265. package/dist/runtime/manager.js.map +1 -0
  266. package/dist/runtime/types.d.ts +176 -0
  267. package/dist/runtime/types.d.ts.map +1 -0
  268. package/dist/runtime/types.js +2 -0
  269. package/dist/runtime/types.js.map +1 -0
  270. package/dist/search/evaluator.d.ts +109 -0
  271. package/dist/search/evaluator.d.ts.map +1 -0
  272. package/dist/search/evaluator.js +372 -0
  273. package/dist/search/evaluator.js.map +1 -0
  274. package/dist/search/index.d.ts +8 -0
  275. package/dist/search/index.d.ts.map +1 -0
  276. package/dist/search/index.js +13 -0
  277. package/dist/search/index.js.map +1 -0
  278. package/dist/search/refinement-loop.d.ts +90 -0
  279. package/dist/search/refinement-loop.d.ts.map +1 -0
  280. package/dist/search/refinement-loop.js +316 -0
  281. package/dist/search/refinement-loop.js.map +1 -0
  282. package/dist/search/refinement-types.d.ts +154 -0
  283. package/dist/search/refinement-types.d.ts.map +1 -0
  284. package/dist/search/refinement-types.js +99 -0
  285. package/dist/search/refinement-types.js.map +1 -0
  286. package/dist/search/router.d.ts +61 -0
  287. package/dist/search/router.d.ts.map +1 -0
  288. package/dist/search/router.js +197 -0
  289. package/dist/search/router.js.map +1 -0
  290. package/dist/search/solver.d.ts +75 -0
  291. package/dist/search/solver.d.ts.map +1 -0
  292. package/dist/search/solver.js +216 -0
  293. package/dist/search/solver.js.map +1 -0
  294. package/dist/search/team-router.d.ts +91 -0
  295. package/dist/search/team-router.d.ts.map +1 -0
  296. package/dist/search/team-router.js +315 -0
  297. package/dist/search/team-router.js.map +1 -0
  298. package/dist/search/verification-runner.d.ts +125 -0
  299. package/dist/search/verification-runner.d.ts.map +1 -0
  300. package/dist/search/verification-runner.js +440 -0
  301. package/dist/search/verification-runner.js.map +1 -0
  302. package/dist/session-bank/git-reader.d.ts +39 -0
  303. package/dist/session-bank/git-reader.d.ts.map +1 -0
  304. package/dist/session-bank/git-reader.js +165 -0
  305. package/dist/session-bank/git-reader.js.map +1 -0
  306. package/dist/session-bank/index.d.ts +5 -0
  307. package/dist/session-bank/index.d.ts.map +1 -0
  308. package/dist/session-bank/index.js +4 -0
  309. package/dist/session-bank/index.js.map +1 -0
  310. package/dist/session-bank/parser.d.ts +39 -0
  311. package/dist/session-bank/parser.d.ts.map +1 -0
  312. package/dist/session-bank/parser.js +231 -0
  313. package/dist/session-bank/parser.js.map +1 -0
  314. package/dist/session-bank/session-bank.d.ts +35 -0
  315. package/dist/session-bank/session-bank.d.ts.map +1 -0
  316. package/dist/session-bank/session-bank.js +326 -0
  317. package/dist/session-bank/session-bank.js.map +1 -0
  318. package/dist/session-bank/types.d.ts +129 -0
  319. package/dist/session-bank/types.d.ts.map +1 -0
  320. package/dist/session-bank/types.js +7 -0
  321. package/dist/session-bank/types.js.map +1 -0
  322. package/dist/surfacing/index.d.ts +6 -0
  323. package/dist/surfacing/index.d.ts.map +1 -0
  324. package/dist/surfacing/index.js +5 -0
  325. package/dist/surfacing/index.js.map +1 -0
  326. package/dist/surfacing/publisher.d.ts +22 -0
  327. package/dist/surfacing/publisher.d.ts.map +1 -0
  328. package/dist/surfacing/publisher.js +9 -0
  329. package/dist/surfacing/publisher.js.map +1 -0
  330. package/dist/surfacing/skill-library.d.ts +170 -0
  331. package/dist/surfacing/skill-library.d.ts.map +1 -0
  332. package/dist/surfacing/skill-library.js +455 -0
  333. package/dist/surfacing/skill-library.js.map +1 -0
  334. package/dist/surfacing/skill-publisher.d.ts +43 -0
  335. package/dist/surfacing/skill-publisher.d.ts.map +1 -0
  336. package/dist/surfacing/skill-publisher.js +197 -0
  337. package/dist/surfacing/skill-publisher.js.map +1 -0
  338. package/dist/surfacing/sqlite-storage-adapter.d.ts +42 -0
  339. package/dist/surfacing/sqlite-storage-adapter.d.ts.map +1 -0
  340. package/dist/surfacing/sqlite-storage-adapter.js +207 -0
  341. package/dist/surfacing/sqlite-storage-adapter.js.map +1 -0
  342. package/dist/surfacing/team-skill-library.d.ts +180 -0
  343. package/dist/surfacing/team-skill-library.d.ts.map +1 -0
  344. package/dist/surfacing/team-skill-library.js +384 -0
  345. package/dist/surfacing/team-skill-library.js.map +1 -0
  346. package/dist/types/config.d.ts +2287 -0
  347. package/dist/types/config.d.ts.map +1 -0
  348. package/dist/types/config.js +490 -0
  349. package/dist/types/config.js.map +1 -0
  350. package/dist/types/dataclaw.d.ts +286 -0
  351. package/dist/types/dataclaw.d.ts.map +1 -0
  352. package/dist/types/dataclaw.js +84 -0
  353. package/dist/types/dataclaw.js.map +1 -0
  354. package/dist/types/index.d.ts +16 -0
  355. package/dist/types/index.d.ts.map +1 -0
  356. package/dist/types/index.js +26 -0
  357. package/dist/types/index.js.map +1 -0
  358. package/dist/types/knowledge-graph.d.ts +148 -0
  359. package/dist/types/knowledge-graph.d.ts.map +1 -0
  360. package/dist/types/knowledge-graph.js +40 -0
  361. package/dist/types/knowledge-graph.js.map +1 -0
  362. package/dist/types/knowledge.d.ts +280 -0
  363. package/dist/types/knowledge.d.ts.map +1 -0
  364. package/dist/types/knowledge.js +191 -0
  365. package/dist/types/knowledge.js.map +1 -0
  366. package/dist/types/memory.d.ts +339 -0
  367. package/dist/types/memory.d.ts.map +1 -0
  368. package/dist/types/memory.js +207 -0
  369. package/dist/types/memory.js.map +1 -0
  370. package/dist/types/meta.d.ts +146 -0
  371. package/dist/types/meta.d.ts.map +1 -0
  372. package/dist/types/meta.js +51 -0
  373. package/dist/types/meta.js.map +1 -0
  374. package/dist/types/outcome.d.ts +42 -0
  375. package/dist/types/outcome.d.ts.map +1 -0
  376. package/dist/types/outcome.js +50 -0
  377. package/dist/types/outcome.js.map +1 -0
  378. package/dist/types/playbook.d.ts +119 -0
  379. package/dist/types/playbook.d.ts.map +1 -0
  380. package/dist/types/playbook.js +71 -0
  381. package/dist/types/playbook.js.map +1 -0
  382. package/dist/types/step.d.ts +44 -0
  383. package/dist/types/step.d.ts.map +1 -0
  384. package/dist/types/step.js +32 -0
  385. package/dist/types/step.js.map +1 -0
  386. package/dist/types/task.d.ts +91 -0
  387. package/dist/types/task.d.ts.map +1 -0
  388. package/dist/types/task.js +39 -0
  389. package/dist/types/task.js.map +1 -0
  390. package/dist/types/team-meta.d.ts +160 -0
  391. package/dist/types/team-meta.d.ts.map +1 -0
  392. package/dist/types/team-meta.js +42 -0
  393. package/dist/types/team-meta.js.map +1 -0
  394. package/dist/types/team-playbook.d.ts +276 -0
  395. package/dist/types/team-playbook.d.ts.map +1 -0
  396. package/dist/types/team-playbook.js +85 -0
  397. package/dist/types/team-playbook.js.map +1 -0
  398. package/dist/types/team-trajectory.d.ts +305 -0
  399. package/dist/types/team-trajectory.d.ts.map +1 -0
  400. package/dist/types/team-trajectory.js +304 -0
  401. package/dist/types/team-trajectory.js.map +1 -0
  402. package/dist/types/trajectory-source.d.ts +39 -0
  403. package/dist/types/trajectory-source.d.ts.map +1 -0
  404. package/dist/types/trajectory-source.js +2 -0
  405. package/dist/types/trajectory-source.js.map +1 -0
  406. package/dist/types/trajectory.d.ts +221 -0
  407. package/dist/types/trajectory.d.ts.map +1 -0
  408. package/dist/types/trajectory.js +60 -0
  409. package/dist/types/trajectory.js.map +1 -0
  410. package/dist/utils/frontmatter.d.ts +34 -0
  411. package/dist/utils/frontmatter.d.ts.map +1 -0
  412. package/dist/utils/frontmatter.js +93 -0
  413. package/dist/utils/frontmatter.js.map +1 -0
  414. package/dist/utils/index.d.ts +5 -0
  415. package/dist/utils/index.d.ts.map +1 -0
  416. package/dist/utils/index.js +5 -0
  417. package/dist/utils/index.js.map +1 -0
  418. package/dist/utils/similarity.d.ts +31 -0
  419. package/dist/utils/similarity.d.ts.map +1 -0
  420. package/dist/utils/similarity.js +107 -0
  421. package/dist/utils/similarity.js.map +1 -0
  422. package/dist/utils/storage.d.ts +106 -0
  423. package/dist/utils/storage.d.ts.map +1 -0
  424. package/dist/utils/storage.js +203 -0
  425. package/dist/utils/storage.js.map +1 -0
  426. package/dist/utils/validation.d.ts +129 -0
  427. package/dist/utils/validation.d.ts.map +1 -0
  428. package/dist/utils/validation.js +171 -0
  429. package/dist/utils/validation.js.map +1 -0
  430. package/dist/workspace/index.d.ts +6 -0
  431. package/dist/workspace/index.d.ts.map +1 -0
  432. package/dist/workspace/index.js +11 -0
  433. package/dist/workspace/index.js.map +1 -0
  434. package/dist/workspace/runner.d.ts +50 -0
  435. package/dist/workspace/runner.d.ts.map +1 -0
  436. package/dist/workspace/runner.js +219 -0
  437. package/dist/workspace/runner.js.map +1 -0
  438. package/dist/workspace/skill-converter.d.ts +18 -0
  439. package/dist/workspace/skill-converter.d.ts.map +1 -0
  440. package/dist/workspace/skill-converter.js +257 -0
  441. package/dist/workspace/skill-converter.js.map +1 -0
  442. package/dist/workspace/templates/index.d.ts +11 -0
  443. package/dist/workspace/templates/index.d.ts.map +1 -0
  444. package/dist/workspace/templates/index.js +21 -0
  445. package/dist/workspace/templates/index.js.map +1 -0
  446. package/dist/workspace/templates/knowledge-defrag.d.ts +25 -0
  447. package/dist/workspace/templates/knowledge-defrag.d.ts.map +1 -0
  448. package/dist/workspace/templates/knowledge-defrag.js +154 -0
  449. package/dist/workspace/templates/knowledge-defrag.js.map +1 -0
  450. package/dist/workspace/templates/knowledge-extraction.d.ts +25 -0
  451. package/dist/workspace/templates/knowledge-extraction.d.ts.map +1 -0
  452. package/dist/workspace/templates/knowledge-extraction.js +246 -0
  453. package/dist/workspace/templates/knowledge-extraction.js.map +1 -0
  454. package/dist/workspace/templates/meta-reflection.d.ts +47 -0
  455. package/dist/workspace/templates/meta-reflection.d.ts.map +1 -0
  456. package/dist/workspace/templates/meta-reflection.js +135 -0
  457. package/dist/workspace/templates/meta-reflection.js.map +1 -0
  458. package/dist/workspace/templates/playbook-extraction.d.ts +20 -0
  459. package/dist/workspace/templates/playbook-extraction.d.ts.map +1 -0
  460. package/dist/workspace/templates/playbook-extraction.js +189 -0
  461. package/dist/workspace/templates/playbook-extraction.js.map +1 -0
  462. package/dist/workspace/templates/refinement-analysis.d.ts +31 -0
  463. package/dist/workspace/templates/refinement-analysis.d.ts.map +1 -0
  464. package/dist/workspace/templates/refinement-analysis.js +107 -0
  465. package/dist/workspace/templates/refinement-analysis.js.map +1 -0
  466. package/dist/workspace/templates/solution-evaluation.d.ts +21 -0
  467. package/dist/workspace/templates/solution-evaluation.d.ts.map +1 -0
  468. package/dist/workspace/templates/solution-evaluation.js +131 -0
  469. package/dist/workspace/templates/solution-evaluation.js.map +1 -0
  470. package/dist/workspace/templates/team-playbook-extraction.d.ts +44 -0
  471. package/dist/workspace/templates/team-playbook-extraction.d.ts.map +1 -0
  472. package/dist/workspace/templates/team-playbook-extraction.js +497 -0
  473. package/dist/workspace/templates/team-playbook-extraction.js.map +1 -0
  474. package/dist/workspace/templates/team-trajectory-analysis.d.ts +19 -0
  475. package/dist/workspace/templates/team-trajectory-analysis.d.ts.map +1 -0
  476. package/dist/workspace/templates/team-trajectory-analysis.js +442 -0
  477. package/dist/workspace/templates/team-trajectory-analysis.js.map +1 -0
  478. package/dist/workspace/templates/trajectory-analysis.d.ts +19 -0
  479. package/dist/workspace/templates/trajectory-analysis.d.ts.map +1 -0
  480. package/dist/workspace/templates/trajectory-analysis.js +170 -0
  481. package/dist/workspace/templates/trajectory-analysis.js.map +1 -0
  482. package/dist/workspace/templates/usage-inference.d.ts +19 -0
  483. package/dist/workspace/templates/usage-inference.d.ts.map +1 -0
  484. package/dist/workspace/templates/usage-inference.js +125 -0
  485. package/dist/workspace/templates/usage-inference.js.map +1 -0
  486. package/dist/workspace/types.d.ts +145 -0
  487. package/dist/workspace/types.d.ts.map +1 -0
  488. package/dist/workspace/types.js +17 -0
  489. package/dist/workspace/types.js.map +1 -0
  490. package/docs/DESIGN-agentic-workspace.md +2057 -0
  491. package/docs/DESIGN-semantic-memory-knowledge-bank.md +1789 -0
  492. package/docs/DESIGN-session-bank.md +1134 -0
  493. package/docs/DESIGN-team-extraction-pipeline.md +1369 -0
  494. package/docs/DESIGN-workspace-migration.md +1079 -0
  495. package/docs/PLAN-agentic-workspace-implementation.md +717 -0
  496. package/docs/PLAN-graph-migration.md +299 -0
  497. package/docs/PLAN-session-bank-implementation.md +474 -0
  498. package/docs/PROPOSAL-team-aware-learning.md +1080 -0
  499. package/docs/RESEARCH-semantic-memory-knowledge-structures.md +517 -0
  500. package/docs/RESEARCH-team-trajectory-learning.md +553 -0
  501. package/gaps.md +204 -0
  502. package/package.json +67 -33
  503. package/references/agent-workspace/CLAUDE.md +74 -0
  504. package/references/agent-workspace/README.md +587 -0
  505. package/references/agent-workspace/media/banner.png +0 -0
  506. package/references/agent-workspace/package-lock.json +2061 -0
  507. package/references/agent-workspace/package.json +54 -0
  508. package/references/agent-workspace/src/handle.ts +122 -0
  509. package/references/agent-workspace/src/index.ts +32 -0
  510. package/references/agent-workspace/src/manager.ts +102 -0
  511. package/references/agent-workspace/src/readers/json.ts +71 -0
  512. package/references/agent-workspace/src/readers/markdown.ts +37 -0
  513. package/references/agent-workspace/src/readers/raw.ts +27 -0
  514. package/references/agent-workspace/src/types.ts +68 -0
  515. package/references/agent-workspace/src/validation.ts +93 -0
  516. package/references/agent-workspace/src/writers/json.ts +17 -0
  517. package/references/agent-workspace/src/writers/markdown.ts +27 -0
  518. package/references/agent-workspace/src/writers/raw.ts +22 -0
  519. package/references/agent-workspace/tests/errors.test.ts +652 -0
  520. package/references/agent-workspace/tests/handle.test.ts +144 -0
  521. package/references/agent-workspace/tests/manager.test.ts +124 -0
  522. package/references/agent-workspace/tests/readers.test.ts +205 -0
  523. package/references/agent-workspace/tests/validation.test.ts +196 -0
  524. package/references/agent-workspace/tests/writers.test.ts +108 -0
  525. package/references/agent-workspace/tsconfig.json +20 -0
  526. package/references/agent-workspace/tsup.config.ts +9 -0
  527. package/references/minimem/.claude/settings.json +7 -0
  528. package/references/minimem/.sudocode/issues.jsonl +18 -0
  529. package/references/minimem/.sudocode/specs.jsonl +1 -0
  530. package/references/minimem/CLAUDE.md +310 -0
  531. package/references/minimem/README.md +556 -0
  532. package/references/minimem/claude-plugin/.claude-plugin/plugin.json +10 -0
  533. package/references/minimem/claude-plugin/.mcp.json +7 -0
  534. package/references/minimem/claude-plugin/README.md +158 -0
  535. package/references/minimem/claude-plugin/commands/recall.md +47 -0
  536. package/references/minimem/claude-plugin/commands/remember.md +41 -0
  537. package/references/minimem/claude-plugin/hooks/__tests__/hooks.test.ts +272 -0
  538. package/references/minimem/claude-plugin/hooks/hooks.json +27 -0
  539. package/references/minimem/claude-plugin/hooks/session-end.sh +86 -0
  540. package/references/minimem/claude-plugin/hooks/session-start.sh +85 -0
  541. package/references/minimem/claude-plugin/skills/memory/SKILL.md +108 -0
  542. package/references/minimem/package-lock.json +5373 -0
  543. package/references/minimem/package.json +60 -0
  544. package/references/minimem/scripts/postbuild.js +35 -0
  545. package/references/minimem/src/__tests__/edge-cases.test.ts +371 -0
  546. package/references/minimem/src/__tests__/errors.test.ts +265 -0
  547. package/references/minimem/src/__tests__/helpers.ts +199 -0
  548. package/references/minimem/src/__tests__/internal.test.ts +407 -0
  549. package/references/minimem/src/__tests__/knowledge.test.ts +287 -0
  550. package/references/minimem/src/__tests__/minimem.integration.test.ts +1127 -0
  551. package/references/minimem/src/__tests__/session.test.ts +190 -0
  552. package/references/minimem/src/cli/__tests__/commands.test.ts +759 -0
  553. package/references/minimem/src/cli/commands/__tests__/conflicts.test.ts +141 -0
  554. package/references/minimem/src/cli/commands/append.ts +76 -0
  555. package/references/minimem/src/cli/commands/config.ts +262 -0
  556. package/references/minimem/src/cli/commands/conflicts.ts +413 -0
  557. package/references/minimem/src/cli/commands/daemon.ts +169 -0
  558. package/references/minimem/src/cli/commands/index.ts +12 -0
  559. package/references/minimem/src/cli/commands/init.ts +88 -0
  560. package/references/minimem/src/cli/commands/mcp.ts +177 -0
  561. package/references/minimem/src/cli/commands/push-pull.ts +213 -0
  562. package/references/minimem/src/cli/commands/search.ts +158 -0
  563. package/references/minimem/src/cli/commands/status.ts +84 -0
  564. package/references/minimem/src/cli/commands/sync-init.ts +290 -0
  565. package/references/minimem/src/cli/commands/sync.ts +70 -0
  566. package/references/minimem/src/cli/commands/upsert.ts +197 -0
  567. package/references/minimem/src/cli/config.ts +584 -0
  568. package/references/minimem/src/cli/index.ts +264 -0
  569. package/references/minimem/src/cli/shared.ts +161 -0
  570. package/references/minimem/src/cli/sync/__tests__/central.test.ts +152 -0
  571. package/references/minimem/src/cli/sync/__tests__/conflicts.test.ts +209 -0
  572. package/references/minimem/src/cli/sync/__tests__/daemon.test.ts +118 -0
  573. package/references/minimem/src/cli/sync/__tests__/detection.test.ts +207 -0
  574. package/references/minimem/src/cli/sync/__tests__/integration.test.ts +476 -0
  575. package/references/minimem/src/cli/sync/__tests__/registry.test.ts +363 -0
  576. package/references/minimem/src/cli/sync/__tests__/state.test.ts +255 -0
  577. package/references/minimem/src/cli/sync/__tests__/validation.test.ts +193 -0
  578. package/references/minimem/src/cli/sync/__tests__/watcher.test.ts +178 -0
  579. package/references/minimem/src/cli/sync/central.ts +292 -0
  580. package/references/minimem/src/cli/sync/conflicts.ts +204 -0
  581. package/references/minimem/src/cli/sync/daemon.ts +407 -0
  582. package/references/minimem/src/cli/sync/detection.ts +138 -0
  583. package/references/minimem/src/cli/sync/index.ts +107 -0
  584. package/references/minimem/src/cli/sync/operations.ts +373 -0
  585. package/references/minimem/src/cli/sync/registry.ts +279 -0
  586. package/references/minimem/src/cli/sync/state.ts +355 -0
  587. package/references/minimem/src/cli/sync/validation.ts +206 -0
  588. package/references/minimem/src/cli/sync/watcher.ts +234 -0
  589. package/references/minimem/src/cli/version.ts +34 -0
  590. package/references/minimem/src/core/index.ts +9 -0
  591. package/references/minimem/src/core/indexer.ts +628 -0
  592. package/references/minimem/src/core/searcher.ts +221 -0
  593. package/references/minimem/src/db/schema.ts +183 -0
  594. package/references/minimem/src/db/sqlite-vec.ts +24 -0
  595. package/references/minimem/src/embeddings/__tests__/embeddings.test.ts +431 -0
  596. package/references/minimem/src/embeddings/batch-gemini.ts +392 -0
  597. package/references/minimem/src/embeddings/batch-openai.ts +409 -0
  598. package/references/minimem/src/embeddings/embeddings.ts +434 -0
  599. package/references/minimem/src/index.ts +109 -0
  600. package/references/minimem/src/internal.ts +299 -0
  601. package/references/minimem/src/minimem.ts +1276 -0
  602. package/references/minimem/src/search/__tests__/hybrid.test.ts +247 -0
  603. package/references/minimem/src/search/graph.ts +234 -0
  604. package/references/minimem/src/search/hybrid.ts +151 -0
  605. package/references/minimem/src/search/search.ts +256 -0
  606. package/references/minimem/src/server/__tests__/mcp.test.ts +341 -0
  607. package/references/minimem/src/server/__tests__/tools.test.ts +364 -0
  608. package/references/minimem/src/server/mcp.ts +326 -0
  609. package/references/minimem/src/server/tools.ts +720 -0
  610. package/references/minimem/src/session.ts +460 -0
  611. package/references/minimem/tsconfig.json +19 -0
  612. package/references/minimem/tsup.config.ts +26 -0
  613. package/references/minimem/vitest.config.ts +24 -0
  614. package/references/skill-tree/.claude/settings.json +6 -0
  615. package/references/skill-tree/.sudocode/issues.jsonl +11 -0
  616. package/references/skill-tree/.sudocode/specs.jsonl +1 -0
  617. package/references/skill-tree/CLAUDE.md +150 -0
  618. package/references/skill-tree/README.md +324 -0
  619. package/references/skill-tree/docs/GAPS_v1.md +221 -0
  620. package/references/skill-tree/docs/INTEGRATION_PLAN.md +467 -0
  621. package/references/skill-tree/docs/TODOS.md +91 -0
  622. package/references/skill-tree/docs/anthropic_skill_guide.md +1364 -0
  623. package/references/skill-tree/docs/design/federated-skill-trees.md +524 -0
  624. package/references/skill-tree/docs/design/multi-agent-sync.md +759 -0
  625. package/references/skill-tree/docs/scraper/BRAINSTORM.md +583 -0
  626. package/references/skill-tree/docs/scraper/POC_PLAN.md +420 -0
  627. package/references/skill-tree/docs/scraper/README.md +170 -0
  628. package/references/skill-tree/examples/basic-usage.ts +190 -0
  629. package/references/skill-tree/package-lock.json +1509 -0
  630. package/references/skill-tree/package.json +66 -0
  631. package/references/skill-tree/scraper/README.md +123 -0
  632. package/references/skill-tree/scraper/docs/DESIGN.md +683 -0
  633. package/references/skill-tree/scraper/docs/PLAN.md +336 -0
  634. package/references/skill-tree/scraper/drizzle.config.ts +10 -0
  635. package/references/skill-tree/scraper/package-lock.json +6329 -0
  636. package/references/skill-tree/scraper/package.json +68 -0
  637. package/references/skill-tree/scraper/test/fixtures/invalid-skill/missing-description.md +7 -0
  638. package/references/skill-tree/scraper/test/fixtures/invalid-skill/missing-name.md +7 -0
  639. package/references/skill-tree/scraper/test/fixtures/minimal-skill/SKILL.md +27 -0
  640. package/references/skill-tree/scraper/test/fixtures/skill-json/SKILL.json +21 -0
  641. package/references/skill-tree/scraper/test/fixtures/skill-with-meta/SKILL.md +54 -0
  642. package/references/skill-tree/scraper/test/fixtures/skill-with-meta/_meta.json +24 -0
  643. package/references/skill-tree/scraper/test/fixtures/valid-skill/SKILL.md +93 -0
  644. package/references/skill-tree/scraper/test/fixtures/valid-skill/_meta.json +22 -0
  645. package/references/skill-tree/scraper/tsup.config.ts +14 -0
  646. package/references/skill-tree/scraper/vitest.config.ts +17 -0
  647. package/references/skill-tree/scripts/convert-to-vitest.ts +166 -0
  648. package/references/skill-tree/skills/skill-writer/SKILL.md +339 -0
  649. package/references/skill-tree/skills/skill-writer/references/examples.md +326 -0
  650. package/references/skill-tree/skills/skill-writer/references/patterns.md +210 -0
  651. package/references/skill-tree/skills/skill-writer/references/quality-checklist.md +123 -0
  652. package/references/skill-tree/test/run-all.ts +106 -0
  653. package/references/skill-tree/test/utils.ts +128 -0
  654. package/references/skill-tree/vitest.config.ts +16 -0
  655. package/scripts/migrate-to-playbooks.ts +307 -0
  656. package/src/agents/index.ts +14 -0
  657. package/src/agents/mock-provider.ts +93 -0
  658. package/src/agents/types.ts +137 -0
  659. package/src/atlas.ts +1072 -0
  660. package/src/bin/cognitive-core.ts +470 -0
  661. package/src/embeddings/bm25.ts +337 -0
  662. package/src/embeddings/index.ts +39 -0
  663. package/src/embeddings/manager.ts +288 -0
  664. package/src/embeddings/provider.ts +318 -0
  665. package/src/embeddings/vector-store.ts +353 -0
  666. package/src/factory.ts +263 -0
  667. package/src/index.ts +368 -0
  668. package/src/learning/analyzer.ts +335 -0
  669. package/src/learning/effectiveness.ts +428 -0
  670. package/src/learning/index.ts +93 -0
  671. package/src/learning/knowledge-extractor.ts +470 -0
  672. package/src/learning/meta-learner.ts +570 -0
  673. package/src/learning/pipeline.ts +323 -0
  674. package/src/learning/playbook-extractor.ts +702 -0
  675. package/src/learning/team-ingester.ts +499 -0
  676. package/src/learning/team-meta-learner.ts +558 -0
  677. package/src/learning/team-pipeline.ts +364 -0
  678. package/src/learning/trajectory-sources/dataclaw.ts +403 -0
  679. package/src/learning/trajectory-sources/entire.ts +240 -0
  680. package/src/learning/trajectory-sources/file.ts +136 -0
  681. package/src/learning/trajectory-sources/huggingface.ts +248 -0
  682. package/src/learning/trajectory-sources/in-memory.ts +61 -0
  683. package/src/learning/trajectory-sources/index.ts +15 -0
  684. package/src/learning/trajectory-sources/pipeline.ts +69 -0
  685. package/src/learning/usage-inference.ts +372 -0
  686. package/src/mcp/index.ts +12 -0
  687. package/src/mcp/playbook-server.ts +565 -0
  688. package/src/memory/curated-loader.ts +160 -0
  689. package/src/memory/experience.ts +515 -0
  690. package/src/memory/graph-layers/base.ts +184 -0
  691. package/src/memory/graph-layers/causal.ts +16 -0
  692. package/src/memory/graph-layers/entity.ts +16 -0
  693. package/src/memory/graph-layers/index.ts +5 -0
  694. package/src/memory/graph-layers/semantic.ts +16 -0
  695. package/src/memory/graph-layers/temporal.ts +16 -0
  696. package/src/memory/index.ts +72 -0
  697. package/src/memory/knowledge-bank.ts +1260 -0
  698. package/src/memory/knowledge-defrag.ts +329 -0
  699. package/src/memory/knowledge-graph.ts +361 -0
  700. package/src/memory/meta.ts +506 -0
  701. package/src/memory/playbook.ts +493 -0
  702. package/src/memory/search-provider.ts +35 -0
  703. package/src/memory/search-providers/index.ts +3 -0
  704. package/src/memory/search-providers/minimem.ts +84 -0
  705. package/src/memory/search-providers/text-similarity.ts +35 -0
  706. package/src/memory/skill-exporter.ts +357 -0
  707. package/src/memory/system.ts +604 -0
  708. package/src/memory/team-experience.ts +604 -0
  709. package/src/runtime/backends/acp-protocol.ts +231 -0
  710. package/src/runtime/backends/acp.ts +239 -0
  711. package/src/runtime/backends/index.ts +38 -0
  712. package/src/runtime/backends/macro-agent.ts +177 -0
  713. package/src/runtime/backends/mock.ts +218 -0
  714. package/src/runtime/backends/subprocess.ts +356 -0
  715. package/src/runtime/compute-provider.ts +206 -0
  716. package/src/runtime/flows/learning.ts +183 -0
  717. package/src/runtime/flows/validation.ts +381 -0
  718. package/src/runtime/index.ts +75 -0
  719. package/src/runtime/manager.ts +685 -0
  720. package/src/runtime/types.ts +198 -0
  721. package/src/search/evaluator.ts +499 -0
  722. package/src/search/index.ts +68 -0
  723. package/src/search/refinement-loop.ts +457 -0
  724. package/src/search/refinement-types.ts +159 -0
  725. package/src/search/router.ts +261 -0
  726. package/src/search/solver.ts +303 -0
  727. package/src/search/team-router.ts +459 -0
  728. package/src/search/verification-runner.ts +570 -0
  729. package/src/session-bank/git-reader.ts +190 -0
  730. package/src/session-bank/index.ts +24 -0
  731. package/src/session-bank/parser.ts +366 -0
  732. package/src/session-bank/session-bank.ts +464 -0
  733. package/src/session-bank/types.ts +173 -0
  734. package/src/surfacing/index.ts +29 -0
  735. package/src/surfacing/publisher.ts +23 -0
  736. package/src/surfacing/skill-library.ts +625 -0
  737. package/src/surfacing/skill-publisher.ts +223 -0
  738. package/src/surfacing/sqlite-storage-adapter.ts +301 -0
  739. package/src/surfacing/team-skill-library.ts +610 -0
  740. package/src/types/config.ts +585 -0
  741. package/src/types/dataclaw.ts +99 -0
  742. package/src/types/huggingface-transformers.d.ts +12 -0
  743. package/src/types/index.ts +286 -0
  744. package/src/types/knowledge-graph.ts +246 -0
  745. package/src/types/knowledge.ts +388 -0
  746. package/src/types/memory.ts +270 -0
  747. package/src/types/meta.ts +218 -0
  748. package/src/types/outcome.ts +66 -0
  749. package/src/types/playbook.ts +196 -0
  750. package/src/types/step.ts +40 -0
  751. package/src/types/task.ts +52 -0
  752. package/src/types/team-meta.ts +212 -0
  753. package/src/types/team-playbook.ts +384 -0
  754. package/src/types/team-trajectory.ts +673 -0
  755. package/src/types/trajectory-source.ts +47 -0
  756. package/src/types/trajectory.ts +80 -0
  757. package/src/utils/frontmatter.ts +118 -0
  758. package/src/utils/index.ts +45 -0
  759. package/src/utils/similarity.ts +139 -0
  760. package/src/utils/storage.ts +249 -0
  761. package/src/utils/validation.ts +286 -0
  762. package/src/workspace/index.ts +48 -0
  763. package/src/workspace/runner.ts +281 -0
  764. package/src/workspace/skill-converter.ts +288 -0
  765. package/src/workspace/templates/index.ts +64 -0
  766. package/src/workspace/templates/knowledge-defrag.ts +223 -0
  767. package/src/workspace/templates/knowledge-extraction.ts +337 -0
  768. package/src/workspace/templates/meta-reflection.ts +208 -0
  769. package/src/workspace/templates/playbook-extraction.ts +240 -0
  770. package/src/workspace/templates/refinement-analysis.ts +162 -0
  771. package/src/workspace/templates/solution-evaluation.ts +199 -0
  772. package/src/workspace/templates/team-playbook-extraction.ts +631 -0
  773. package/src/workspace/templates/team-trajectory-analysis.ts +564 -0
  774. package/src/workspace/templates/trajectory-analysis.ts +234 -0
  775. package/src/workspace/templates/usage-inference.ts +163 -0
  776. package/src/workspace/types.ts +233 -0
  777. package/tests/atlas-knowledge.test.ts +165 -0
  778. package/tests/embeddings/bm25.test.ts +130 -0
  779. package/tests/embeddings/manager.test.ts +205 -0
  780. package/tests/gap-fixes.test.ts +1103 -0
  781. package/tests/integration/atlas.test.ts +266 -0
  782. package/tests/integration/dataclaw-e2e.test.ts +559 -0
  783. package/tests/integration/e2e.test.ts +1336 -0
  784. package/tests/integration/entire-e2e.test.ts +187 -0
  785. package/tests/integration/huggingface-e2e.test.ts +627 -0
  786. package/tests/integration/session-bank.test.ts +225 -0
  787. package/tests/integration/skill-tree-wiring.test.ts +152 -0
  788. package/tests/learning/analyzer.test.ts +426 -0
  789. package/tests/learning/dataclaw-trajectory-source.test.ts +642 -0
  790. package/tests/learning/effectiveness.test.ts +542 -0
  791. package/tests/learning/entire-trajectory-source.test.ts +380 -0
  792. package/tests/learning/huggingface-trajectory-source.test.ts +817 -0
  793. package/tests/learning/knowledge-extractor.test.ts +491 -0
  794. package/tests/learning/pipeline.test.ts +176 -0
  795. package/tests/learning/playbook-extractor-provenance.test.ts +114 -0
  796. package/tests/learning/team-ingester.test.ts +349 -0
  797. package/tests/learning/team-meta-learner.test.ts +618 -0
  798. package/tests/learning/team-pipeline.test.ts +334 -0
  799. package/tests/learning/trajectory-sources.test.ts +312 -0
  800. package/tests/learning/usage-inference.test.ts +254 -0
  801. package/tests/mcp/playbook-server.test.ts +252 -0
  802. package/tests/memory/experience.test.ts +198 -0
  803. package/tests/memory/graph-layers/semantic.test.ts +219 -0
  804. package/tests/memory/knowledge-bank-extraction.test.ts +558 -0
  805. package/tests/memory/knowledge-bank.test.ts +705 -0
  806. package/tests/memory/knowledge-defrag.test.ts +366 -0
  807. package/tests/memory/knowledge-evolution.test.ts +563 -0
  808. package/tests/memory/knowledge-graph.test.ts +492 -0
  809. package/tests/memory/knowledge-inbox.test.ts +258 -0
  810. package/tests/memory/knowledge-minimem.test.ts +251 -0
  811. package/tests/memory/playbook.test.ts +338 -0
  812. package/tests/memory/provenance.test.ts +639 -0
  813. package/tests/memory/skill-exporter.test.ts +470 -0
  814. package/tests/memory/system.test.ts +325 -0
  815. package/tests/memory/team-experience.test.ts +411 -0
  816. package/tests/runtime/agent-manager.test.ts +512 -0
  817. package/tests/runtime/compute-provider.test.ts +288 -0
  818. package/tests/runtime/delegate.test.ts +349 -0
  819. package/tests/runtime/macro-agent-backend.test.ts +266 -0
  820. package/tests/runtime/mock-backend.test.ts +248 -0
  821. package/tests/search/refinement-loop.test.ts +468 -0
  822. package/tests/search/refinement.test.ts +267 -0
  823. package/tests/search/router.test.ts +427 -0
  824. package/tests/search/team-router.test.ts +376 -0
  825. package/tests/session-bank/fixtures/multi-tool-session/full.jsonl +12 -0
  826. package/tests/session-bank/fixtures/multi-tool-session/metadata.json +28 -0
  827. package/tests/session-bank/fixtures/root-metadata.json +18 -0
  828. package/tests/session-bank/fixtures/simple-session/full.jsonl +6 -0
  829. package/tests/session-bank/fixtures/simple-session/metadata.json +38 -0
  830. package/tests/session-bank/git-reader.test.ts +232 -0
  831. package/tests/session-bank/parser.test.ts +321 -0
  832. package/tests/session-bank/session-bank.test.ts +546 -0
  833. package/tests/surfacing/skill-library.test.ts +292 -0
  834. package/tests/surfacing/skill-publisher.test.ts +398 -0
  835. package/tests/surfacing/sqlite-storage-adapter.test.ts +218 -0
  836. package/tests/surfacing/team-skill-library.test.ts +444 -0
  837. package/tests/types/outcome.test.ts +147 -0
  838. package/tests/types/step.test.ts +133 -0
  839. package/tests/types/task.test.ts +158 -0
  840. package/tests/types/team-meta.test.ts +147 -0
  841. package/tests/types/team-playbook.test.ts +246 -0
  842. package/tests/types/team-trajectory.test.ts +557 -0
  843. package/tests/types/trajectory.test.ts +253 -0
  844. package/tests/utils/frontmatter.test.ts +208 -0
  845. package/tests/utils/similarity.test.ts +188 -0
  846. package/tests/utils/validation.test.ts +252 -0
  847. package/tests/workspace/full-flow.test.ts +839 -0
  848. package/tests/workspace/manager.test.ts +215 -0
  849. package/tests/workspace/runner.test.ts +330 -0
  850. package/tests/workspace/skill-converter.test.ts +205 -0
  851. package/tests/workspace/templates/knowledge-extraction.test.ts +235 -0
  852. package/tests/workspace/templates/team-playbook-extraction.test.ts +341 -0
  853. package/tests/workspace/templates/team-trajectory-analysis.test.ts +417 -0
  854. package/tsconfig.json +25 -0
  855. package/vitest.config.ts +22 -0
  856. package/dist/index.d.mts +0 -466
  857. package/dist/index.mjs +0 -478
@@ -0,0 +1,253 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import {
3
+ TrajectorySchema,
4
+ createTrajectory,
5
+ isSuccessful,
6
+ getKeySteps,
7
+ type Trajectory,
8
+ } from '../../src/types/trajectory.js';
9
+ import { createTask } from '../../src/types/task.js';
10
+ import { createStep } from '../../src/types/step.js';
11
+ import { successOutcome, failureOutcome } from '../../src/types/outcome.js';
12
+
13
+ describe('Trajectory', () => {
14
+ const sampleTask = createTask({
15
+ id: 'task-1',
16
+ domain: 'code',
17
+ description: 'Write a hello world function',
18
+ });
19
+
20
+ const sampleSteps = [
21
+ createStep({
22
+ thought: 'I need to create a function',
23
+ action: 'write_code()',
24
+ observation: 'Function written',
25
+ }),
26
+ createStep({
27
+ action: 'run_tests()',
28
+ observation: 'Tests passed',
29
+ }),
30
+ ];
31
+
32
+ it('should validate a complete trajectory', () => {
33
+ const trajectory: Trajectory = {
34
+ id: 'traj-1',
35
+ task: sampleTask,
36
+ steps: sampleSteps,
37
+ outcome: successOutcome('function helloWorld() { return "hello"; }'),
38
+ agentId: 'claude-code',
39
+ timestamp: new Date(),
40
+ llmCalls: 5,
41
+ totalTokens: 1500,
42
+ wallTimeSeconds: 30,
43
+ metadata: { version: '1.0' },
44
+ };
45
+ const result = TrajectorySchema.parse(trajectory);
46
+ expect(result.id).toBe('traj-1');
47
+ expect(result.agentId).toBe('claude-code');
48
+ expect(result.llmCalls).toBe(5);
49
+ expect(result.totalTokens).toBe(1500);
50
+ });
51
+
52
+ it('should apply defaults for optional fields', () => {
53
+ const trajectory = TrajectorySchema.parse({
54
+ id: 'traj-2',
55
+ task: sampleTask,
56
+ steps: [],
57
+ outcome: { success: true },
58
+ agentId: 'test-agent',
59
+ });
60
+ expect(trajectory.llmCalls).toBe(0);
61
+ expect(trajectory.totalTokens).toBe(0);
62
+ expect(trajectory.wallTimeSeconds).toBe(0);
63
+ expect(trajectory.metadata).toEqual({});
64
+ expect(trajectory.timestamp).toBeInstanceOf(Date);
65
+ });
66
+
67
+ it('should allow empty steps array', () => {
68
+ const trajectory = TrajectorySchema.parse({
69
+ id: 'traj-3',
70
+ task: sampleTask,
71
+ steps: [],
72
+ outcome: failureOutcome('No steps taken'),
73
+ agentId: 'agent',
74
+ });
75
+ expect(trajectory.steps).toEqual([]);
76
+ });
77
+ });
78
+
79
+ describe('createTrajectory', () => {
80
+ const task = createTask({
81
+ domain: 'reasoning',
82
+ description: 'Solve a logic puzzle',
83
+ });
84
+
85
+ const steps = [
86
+ createStep({ action: 'analyze', observation: 'Found pattern' }),
87
+ createStep({ action: 'apply', observation: 'Applied rule' }),
88
+ createStep({ action: 'verify', observation: 'Correct' }),
89
+ ];
90
+
91
+ it('should create a trajectory with required fields', () => {
92
+ const trajectory = createTrajectory({
93
+ task,
94
+ steps,
95
+ outcome: successOutcome('solved'),
96
+ agentId: 'reasoning-agent',
97
+ });
98
+ expect(trajectory.id).toBeDefined();
99
+ expect(trajectory.id.length).toBeGreaterThan(0);
100
+ expect(trajectory.task).toEqual(task);
101
+ expect(trajectory.steps).toHaveLength(3);
102
+ expect(trajectory.agentId).toBe('reasoning-agent');
103
+ });
104
+
105
+ it('should create a trajectory with custom id', () => {
106
+ const trajectory = createTrajectory({
107
+ id: 'custom-traj-id',
108
+ task,
109
+ steps: [],
110
+ outcome: failureOutcome('failed'),
111
+ agentId: 'agent',
112
+ });
113
+ expect(trajectory.id).toBe('custom-traj-id');
114
+ });
115
+
116
+ it('should create a trajectory with metrics', () => {
117
+ const trajectory = createTrajectory({
118
+ task,
119
+ steps,
120
+ outcome: successOutcome(42),
121
+ agentId: 'agent',
122
+ llmCalls: 10,
123
+ totalTokens: 5000,
124
+ wallTimeSeconds: 120,
125
+ });
126
+ expect(trajectory.llmCalls).toBe(10);
127
+ expect(trajectory.totalTokens).toBe(5000);
128
+ expect(trajectory.wallTimeSeconds).toBe(120);
129
+ });
130
+
131
+ it('should create a trajectory with metadata', () => {
132
+ const trajectory = createTrajectory({
133
+ task,
134
+ steps,
135
+ outcome: successOutcome('done'),
136
+ agentId: 'agent',
137
+ metadata: { attempt: 2, model: 'gpt-4' },
138
+ });
139
+ expect(trajectory.metadata.attempt).toBe(2);
140
+ expect(trajectory.metadata.model).toBe('gpt-4');
141
+ });
142
+
143
+ it('should set timestamp to current time', () => {
144
+ const before = new Date();
145
+ const trajectory = createTrajectory({
146
+ task,
147
+ steps: [],
148
+ outcome: successOutcome('x'),
149
+ agentId: 'agent',
150
+ });
151
+ const after = new Date();
152
+ expect(trajectory.timestamp.getTime()).toBeGreaterThanOrEqual(before.getTime());
153
+ expect(trajectory.timestamp.getTime()).toBeLessThanOrEqual(after.getTime());
154
+ });
155
+ });
156
+
157
+ describe('isSuccessful', () => {
158
+ const task = createTask({ domain: 'test', description: 'test' });
159
+
160
+ it('should return true for successful trajectory', () => {
161
+ const trajectory = createTrajectory({
162
+ task,
163
+ steps: [],
164
+ outcome: successOutcome('done'),
165
+ agentId: 'agent',
166
+ });
167
+ expect(isSuccessful(trajectory)).toBe(true);
168
+ });
169
+
170
+ it('should return false for failed trajectory', () => {
171
+ const trajectory = createTrajectory({
172
+ task,
173
+ steps: [],
174
+ outcome: failureOutcome('error'),
175
+ agentId: 'agent',
176
+ });
177
+ expect(isSuccessful(trajectory)).toBe(false);
178
+ });
179
+ });
180
+
181
+ describe('getKeySteps', () => {
182
+ const task = createTask({ domain: 'test', description: 'test' });
183
+
184
+ it('should return steps above threshold', () => {
185
+ const steps = [
186
+ { ...createStep({ action: 'a', observation: 'o' }), attributionScore: 0.1 },
187
+ { ...createStep({ action: 'b', observation: 'o' }), attributionScore: 0.3 },
188
+ { ...createStep({ action: 'c', observation: 'o' }), attributionScore: 0.8 },
189
+ { ...createStep({ action: 'd', observation: 'o' }), attributionScore: 0.15 },
190
+ ];
191
+ const trajectory = createTrajectory({
192
+ task,
193
+ steps,
194
+ outcome: successOutcome('x'),
195
+ agentId: 'agent',
196
+ });
197
+
198
+ const keySteps = getKeySteps(trajectory);
199
+ expect(keySteps).toHaveLength(3);
200
+ expect(keySteps[0].action).toBe('b');
201
+ expect(keySteps[1].action).toBe('c');
202
+ expect(keySteps[2].action).toBe('d');
203
+ });
204
+
205
+ it('should use custom threshold', () => {
206
+ const steps = [
207
+ { ...createStep({ action: 'a', observation: 'o' }), attributionScore: 0.4 },
208
+ { ...createStep({ action: 'b', observation: 'o' }), attributionScore: 0.6 },
209
+ ];
210
+ const trajectory = createTrajectory({
211
+ task,
212
+ steps,
213
+ outcome: successOutcome('x'),
214
+ agentId: 'agent',
215
+ });
216
+
217
+ expect(getKeySteps(trajectory, 0.5)).toHaveLength(1);
218
+ expect(getKeySteps(trajectory, 0.3)).toHaveLength(2);
219
+ expect(getKeySteps(trajectory, 0.7)).toHaveLength(0);
220
+ });
221
+
222
+ it('should handle steps without attribution scores', () => {
223
+ const steps = [
224
+ createStep({ action: 'a', observation: 'o' }),
225
+ { ...createStep({ action: 'b', observation: 'o' }), attributionScore: 0.5 },
226
+ ];
227
+ const trajectory = createTrajectory({
228
+ task,
229
+ steps,
230
+ outcome: successOutcome('x'),
231
+ agentId: 'agent',
232
+ });
233
+
234
+ const keySteps = getKeySteps(trajectory);
235
+ expect(keySteps).toHaveLength(1);
236
+ expect(keySteps[0].action).toBe('b');
237
+ });
238
+
239
+ it('should return empty array for trajectory with no key steps', () => {
240
+ const steps = [
241
+ { ...createStep({ action: 'a', observation: 'o' }), attributionScore: 0.05 },
242
+ { ...createStep({ action: 'b', observation: 'o' }), attributionScore: 0.1 },
243
+ ];
244
+ const trajectory = createTrajectory({
245
+ task,
246
+ steps,
247
+ outcome: successOutcome('x'),
248
+ agentId: 'agent',
249
+ });
250
+
251
+ expect(getKeySteps(trajectory)).toHaveLength(0);
252
+ });
253
+ });
@@ -0,0 +1,208 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import {
3
+ parseKnowledgeFrontmatter,
4
+ serializeKnowledgeFrontmatter,
5
+ serializeKnowledgeNote,
6
+ parseKnowledgeNote,
7
+ } from '../../src/utils/frontmatter.js';
8
+ import type { KnowledgeNoteFrontmatter } from '../../src/types/knowledge.js';
9
+
10
+ describe('frontmatter', () => {
11
+ const sampleFrontmatter: KnowledgeNoteFrontmatter = {
12
+ id: 'k-prisma-schema-push',
13
+ type: 'observation',
14
+ domain: ['database', 'orm'],
15
+ entities: ['prisma', 'postgresql'],
16
+ tags: ['migration', 'schema-drift'],
17
+ confidence: 0.85,
18
+ source: {
19
+ origin: 'extracted',
20
+ trajectories: ['t-2025-01-15-abc', 't-2025-01-18-def'],
21
+ playbooks: ['playbook-prisma-setup'],
22
+ },
23
+ links: [
24
+ { target: 'k-prisma-migration-workflow', relation: 'related-to' },
25
+ { target: 'k-ts-enum-export', relation: 'co-occurred', layer: 'temporal' },
26
+ ],
27
+ created: '2025-01-15T10:30:00.000Z',
28
+ updated: '2025-01-18T14:00:00.000Z',
29
+ supersedes: null,
30
+ };
31
+
32
+ const sampleBody = '# Prisma requires schema push\n\nSome content here.';
33
+
34
+ describe('parseKnowledgeFrontmatter', () => {
35
+ it('parses valid frontmatter with all fields', () => {
36
+ const content = `---
37
+ id: k-prisma-schema-push
38
+ type: observation
39
+ domain: [database, orm]
40
+ entities: [prisma, postgresql]
41
+ tags: [migration, schema-drift]
42
+ confidence: 0.85
43
+ source:
44
+ origin: extracted
45
+ trajectories:
46
+ - t-2025-01-15-abc
47
+ - t-2025-01-18-def
48
+ playbooks:
49
+ - playbook-prisma-setup
50
+ links:
51
+ - target: k-prisma-migration-workflow
52
+ relation: related-to
53
+ - target: k-ts-enum-export
54
+ relation: co-occurred
55
+ layer: temporal
56
+ created: "2025-01-15T10:30:00.000Z"
57
+ updated: "2025-01-18T14:00:00.000Z"
58
+ ---
59
+
60
+ # Prisma requires schema push
61
+
62
+ Some content here.`;
63
+
64
+ const { frontmatter, body } = parseKnowledgeFrontmatter(content);
65
+
66
+ expect(frontmatter).not.toBeNull();
67
+ expect(frontmatter!.id).toBe('k-prisma-schema-push');
68
+ expect(frontmatter!.type).toBe('observation');
69
+ expect(frontmatter!.domain).toEqual(['database', 'orm']);
70
+ expect(frontmatter!.entities).toEqual(['prisma', 'postgresql']);
71
+ expect(frontmatter!.confidence).toBe(0.85);
72
+ expect(frontmatter!.source.origin).toBe('extracted');
73
+ expect(frontmatter!.source.trajectories).toHaveLength(2);
74
+ expect(frontmatter!.links).toHaveLength(2);
75
+ expect(frontmatter!.links[1].layer).toBe('temporal');
76
+ expect(body).toContain('# Prisma requires schema push');
77
+ });
78
+
79
+ it('returns null frontmatter for content without frontmatter', () => {
80
+ const { frontmatter, body } = parseKnowledgeFrontmatter(
81
+ '# Just a title\n\nSome content.'
82
+ );
83
+
84
+ expect(frontmatter).toBeNull();
85
+ expect(body).toBe('# Just a title\n\nSome content.');
86
+ });
87
+
88
+ it('returns null frontmatter for invalid YAML', () => {
89
+ const { frontmatter } = parseKnowledgeFrontmatter(
90
+ '---\n[invalid yaml\n---\nBody'
91
+ );
92
+
93
+ expect(frontmatter).toBeNull();
94
+ });
95
+
96
+ it('returns null frontmatter for missing required fields', () => {
97
+ const { frontmatter } = parseKnowledgeFrontmatter(
98
+ '---\ntitle: test\n---\nBody'
99
+ );
100
+
101
+ expect(frontmatter).toBeNull();
102
+ });
103
+
104
+ it('applies defaults for optional fields', () => {
105
+ const content = `---
106
+ id: k-test
107
+ type: observation
108
+ confidence: 0.5
109
+ source:
110
+ origin: agent-authored
111
+ created: "2025-01-15T10:00:00.000Z"
112
+ updated: "2025-01-15T10:00:00.000Z"
113
+ ---
114
+
115
+ Body`;
116
+
117
+ const { frontmatter } = parseKnowledgeFrontmatter(content);
118
+
119
+ expect(frontmatter).not.toBeNull();
120
+ expect(frontmatter!.domain).toEqual([]);
121
+ expect(frontmatter!.entities).toEqual([]);
122
+ expect(frontmatter!.tags).toEqual([]);
123
+ expect(frontmatter!.links).toEqual([]);
124
+ });
125
+ });
126
+
127
+ describe('serializeKnowledgeFrontmatter', () => {
128
+ it('produces valid YAML frontmatter block', () => {
129
+ const output = serializeKnowledgeFrontmatter(sampleFrontmatter);
130
+
131
+ expect(output).toMatch(/^---\n/);
132
+ expect(output).toMatch(/---\n$/);
133
+ expect(output).toContain('id: k-prisma-schema-push');
134
+ expect(output).toContain('type: observation');
135
+ expect(output).toContain('confidence: 0.85');
136
+ });
137
+
138
+ it('omits empty arrays', () => {
139
+ const fm: KnowledgeNoteFrontmatter = {
140
+ ...sampleFrontmatter,
141
+ domain: [],
142
+ entities: [],
143
+ tags: [],
144
+ links: [],
145
+ };
146
+
147
+ const output = serializeKnowledgeFrontmatter(fm);
148
+
149
+ expect(output).not.toContain('domain:');
150
+ expect(output).not.toContain('entities:');
151
+ expect(output).not.toContain('tags:');
152
+ expect(output).not.toContain('links:');
153
+ });
154
+ });
155
+
156
+ describe('round-trip', () => {
157
+ it('serialize then parse produces equivalent frontmatter', () => {
158
+ const serialized = serializeKnowledgeFrontmatter(sampleFrontmatter);
159
+ const fullContent = `${serialized}\n${sampleBody}\n`;
160
+
161
+ const { frontmatter, body } = parseKnowledgeFrontmatter(fullContent);
162
+
163
+ expect(frontmatter).not.toBeNull();
164
+ expect(frontmatter!.id).toBe(sampleFrontmatter.id);
165
+ expect(frontmatter!.type).toBe(sampleFrontmatter.type);
166
+ expect(frontmatter!.domain).toEqual(sampleFrontmatter.domain);
167
+ expect(frontmatter!.entities).toEqual(sampleFrontmatter.entities);
168
+ expect(frontmatter!.confidence).toBe(sampleFrontmatter.confidence);
169
+ expect(frontmatter!.source).toEqual(sampleFrontmatter.source);
170
+ expect(frontmatter!.links).toEqual(sampleFrontmatter.links);
171
+ expect(body).toContain(sampleBody);
172
+ });
173
+ });
174
+
175
+ describe('parseKnowledgeNote', () => {
176
+ it('returns a full KnowledgeNote with filePath', () => {
177
+ const content = `${serializeKnowledgeFrontmatter(sampleFrontmatter)}\n${sampleBody}\n`;
178
+
179
+ const note = parseKnowledgeNote(content, 'knowledge/observations/k-prisma-schema-push.md');
180
+
181
+ expect(note).not.toBeNull();
182
+ expect(note!.frontmatter.id).toBe('k-prisma-schema-push');
183
+ expect(note!.body).toContain(sampleBody);
184
+ expect(note!.filePath).toBe('knowledge/observations/k-prisma-schema-push.md');
185
+ });
186
+
187
+ it('returns null for content without valid frontmatter', () => {
188
+ const note = parseKnowledgeNote('No frontmatter here.', 'test.md');
189
+ expect(note).toBeNull();
190
+ });
191
+ });
192
+
193
+ describe('serializeKnowledgeNote', () => {
194
+ it('produces complete markdown with frontmatter + body', () => {
195
+ const note = {
196
+ frontmatter: sampleFrontmatter,
197
+ body: sampleBody,
198
+ filePath: 'test.md',
199
+ };
200
+
201
+ const output = serializeKnowledgeNote(note);
202
+
203
+ expect(output).toMatch(/^---\n/);
204
+ expect(output).toContain('id: k-prisma-schema-push');
205
+ expect(output).toContain(sampleBody);
206
+ });
207
+ });
208
+ });
@@ -0,0 +1,188 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import {
3
+ cosineSimilarity,
4
+ jaccardSimilarity,
5
+ ngramSimilarity,
6
+ textSimilarity,
7
+ tokenize,
8
+ findTopK,
9
+ } from '../../src/utils/similarity.js';
10
+
11
+ describe('cosineSimilarity', () => {
12
+ it('should return 1 for identical vectors', () => {
13
+ expect(cosineSimilarity([1, 0, 0], [1, 0, 0])).toBeCloseTo(1);
14
+ expect(cosineSimilarity([0.5, 0.5], [0.5, 0.5])).toBeCloseTo(1);
15
+ });
16
+
17
+ it('should return 0 for orthogonal vectors', () => {
18
+ expect(cosineSimilarity([1, 0], [0, 1])).toBeCloseTo(0);
19
+ expect(cosineSimilarity([1, 0, 0], [0, 1, 0])).toBeCloseTo(0);
20
+ });
21
+
22
+ it('should return -1 for opposite vectors', () => {
23
+ expect(cosineSimilarity([1, 0], [-1, 0])).toBeCloseTo(-1);
24
+ });
25
+
26
+ it('should handle arbitrary vectors', () => {
27
+ const a = [1, 2, 3];
28
+ const b = [4, 5, 6];
29
+ // dot = 1*4 + 2*5 + 3*6 = 32
30
+ // normA = sqrt(14), normB = sqrt(77)
31
+ const expected = 32 / (Math.sqrt(14) * Math.sqrt(77));
32
+ expect(cosineSimilarity(a, b)).toBeCloseTo(expected);
33
+ });
34
+
35
+ it('should return 0 for zero vectors', () => {
36
+ expect(cosineSimilarity([0, 0, 0], [1, 2, 3])).toBe(0);
37
+ expect(cosineSimilarity([1, 2, 3], [0, 0, 0])).toBe(0);
38
+ });
39
+
40
+ it('should throw for vectors of different lengths', () => {
41
+ expect(() => cosineSimilarity([1, 2], [1, 2, 3])).toThrow();
42
+ });
43
+ });
44
+
45
+ describe('tokenize', () => {
46
+ it('should split text into lowercase tokens', () => {
47
+ expect(tokenize('Hello World')).toEqual(['hello', 'world']);
48
+ });
49
+
50
+ it('should remove punctuation', () => {
51
+ expect(tokenize('Hello, world!')).toEqual(['hello', 'world']);
52
+ });
53
+
54
+ it('should handle multiple spaces', () => {
55
+ expect(tokenize('a b c')).toEqual(['a', 'b', 'c']);
56
+ });
57
+
58
+ it('should return empty array for empty string', () => {
59
+ expect(tokenize('')).toEqual([]);
60
+ });
61
+
62
+ it('should handle special characters', () => {
63
+ expect(tokenize("it's a test-case")).toEqual(['it', 's', 'a', 'test', 'case']);
64
+ });
65
+ });
66
+
67
+ describe('jaccardSimilarity', () => {
68
+ it('should return 1 for identical strings', () => {
69
+ expect(jaccardSimilarity('hello world', 'hello world')).toBe(1);
70
+ });
71
+
72
+ it('should return 0 for completely different strings', () => {
73
+ expect(jaccardSimilarity('abc', 'xyz')).toBe(0);
74
+ });
75
+
76
+ it('should handle partial overlap', () => {
77
+ // 'hello' appears in both
78
+ const sim = jaccardSimilarity('hello world', 'hello there');
79
+ expect(sim).toBeGreaterThan(0);
80
+ expect(sim).toBeLessThan(1);
81
+ });
82
+
83
+ it('should return 0 for empty strings', () => {
84
+ expect(jaccardSimilarity('', '')).toBe(0);
85
+ expect(jaccardSimilarity('hello', '')).toBe(0);
86
+ });
87
+
88
+ it('should be case insensitive', () => {
89
+ expect(jaccardSimilarity('HELLO', 'hello')).toBe(1);
90
+ });
91
+ });
92
+
93
+ describe('ngramSimilarity', () => {
94
+ it('should return 1 for identical strings', () => {
95
+ expect(ngramSimilarity('hello', 'hello')).toBe(1);
96
+ });
97
+
98
+ it('should return 0 for completely different strings', () => {
99
+ expect(ngramSimilarity('abc', 'xyz')).toBe(0);
100
+ });
101
+
102
+ it('should handle partial overlap', () => {
103
+ const sim = ngramSimilarity('hello', 'hella');
104
+ expect(sim).toBeGreaterThan(0);
105
+ expect(sim).toBeLessThan(1);
106
+ });
107
+
108
+ it('should use custom n-gram size', () => {
109
+ const sim2 = ngramSimilarity('hello', 'help', 2);
110
+ const sim3 = ngramSimilarity('hello', 'help', 3);
111
+ // Different n values give different results
112
+ expect(sim2).not.toBe(sim3);
113
+ });
114
+ });
115
+
116
+ describe('textSimilarity', () => {
117
+ it('should return 1 for identical text', () => {
118
+ expect(textSimilarity('hello world', 'hello world')).toBe(1);
119
+ });
120
+
121
+ it('should return 0 for completely different text', () => {
122
+ expect(textSimilarity('abc', 'xyz')).toBe(0);
123
+ });
124
+
125
+ it('should return intermediate values for partial matches', () => {
126
+ const sim = textSimilarity('fix the bug', 'debug the issue');
127
+ expect(sim).toBeGreaterThan(0);
128
+ expect(sim).toBeLessThan(1);
129
+ });
130
+ });
131
+
132
+ describe('findTopK', () => {
133
+ it('should find top-k items by string similarity', () => {
134
+ const items = [
135
+ { id: 1, text: 'hello world' },
136
+ { id: 2, text: 'hello there' },
137
+ { id: 3, text: 'goodbye world' },
138
+ { id: 4, text: 'completely different' },
139
+ ];
140
+
141
+ const results = findTopK('hello world', items, (item) => item.text, 2);
142
+ expect(results).toHaveLength(2);
143
+ expect(results[0].item.id).toBe(1); // Exact match
144
+ expect(results[0].score).toBe(1);
145
+ });
146
+
147
+ it('should find top-k items by vector similarity', () => {
148
+ const items = [
149
+ { id: 1, vec: [1, 0, 0] },
150
+ { id: 2, vec: [0.9, 0.1, 0] },
151
+ { id: 3, vec: [0, 1, 0] },
152
+ { id: 4, vec: [-1, 0, 0] },
153
+ ];
154
+
155
+ const results = findTopK([1, 0, 0], items, (item) => item.vec, 2);
156
+ expect(results).toHaveLength(2);
157
+ expect(results[0].item.id).toBe(1);
158
+ expect(results[1].item.id).toBe(2);
159
+ });
160
+
161
+ it('should handle items without vectors', () => {
162
+ const items = [
163
+ { id: 1, text: 'hello' },
164
+ { id: 2, text: undefined },
165
+ { id: 3, text: 'world' },
166
+ ];
167
+
168
+ const results = findTopK(
169
+ 'hello',
170
+ items,
171
+ (item) => item.text,
172
+ 3
173
+ );
174
+ expect(results).toHaveLength(3);
175
+ expect(results[2].score).toBe(0); // Item with undefined text
176
+ });
177
+
178
+ it('should return fewer items if k is larger than array', () => {
179
+ const items = [{ id: 1, text: 'hello' }];
180
+ const results = findTopK('hello', items, (item) => item.text, 10);
181
+ expect(results).toHaveLength(1);
182
+ });
183
+
184
+ it('should handle empty items array', () => {
185
+ const results = findTopK('hello', [], (item: { text: string }) => item.text, 5);
186
+ expect(results).toHaveLength(0);
187
+ });
188
+ });