cognitive-core 0.1.0 → 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 (637) 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 +524 -254
  5. package/dist/atlas.d.ts +144 -6
  6. package/dist/atlas.d.ts.map +1 -1
  7. package/dist/atlas.js +339 -10
  8. package/dist/atlas.js.map +1 -1
  9. package/dist/embeddings/provider.d.ts.map +1 -1
  10. package/dist/embeddings/provider.js +6 -3
  11. package/dist/embeddings/provider.js.map +1 -1
  12. package/dist/index.d.ts +8 -6
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +37 -6
  15. package/dist/index.js.map +1 -1
  16. package/dist/learning/index.d.ts +5 -1
  17. package/dist/learning/index.d.ts.map +1 -1
  18. package/dist/learning/index.js +8 -2
  19. package/dist/learning/index.js.map +1 -1
  20. package/dist/learning/knowledge-extractor.d.ts +56 -0
  21. package/dist/learning/knowledge-extractor.d.ts.map +1 -0
  22. package/dist/learning/knowledge-extractor.js +336 -0
  23. package/dist/learning/knowledge-extractor.js.map +1 -0
  24. package/dist/learning/meta-learner.d.ts +7 -0
  25. package/dist/learning/meta-learner.d.ts.map +1 -1
  26. package/dist/learning/meta-learner.js +43 -0
  27. package/dist/learning/meta-learner.js.map +1 -1
  28. package/dist/learning/pipeline.d.ts +24 -0
  29. package/dist/learning/pipeline.d.ts.map +1 -1
  30. package/dist/learning/pipeline.js +70 -4
  31. package/dist/learning/pipeline.js.map +1 -1
  32. package/dist/learning/team-ingester.d.ts +152 -0
  33. package/dist/learning/team-ingester.d.ts.map +1 -0
  34. package/dist/learning/team-ingester.js +333 -0
  35. package/dist/learning/team-ingester.js.map +1 -0
  36. package/dist/learning/team-meta-learner.d.ts +50 -0
  37. package/dist/learning/team-meta-learner.d.ts.map +1 -0
  38. package/dist/learning/team-meta-learner.js +417 -0
  39. package/dist/learning/team-meta-learner.js.map +1 -0
  40. package/dist/learning/team-pipeline.d.ts +76 -0
  41. package/dist/learning/team-pipeline.d.ts.map +1 -0
  42. package/dist/learning/team-pipeline.js +266 -0
  43. package/dist/learning/team-pipeline.js.map +1 -0
  44. package/dist/learning/trajectory-sources/dataclaw.d.ts +41 -0
  45. package/dist/learning/trajectory-sources/dataclaw.d.ts.map +1 -0
  46. package/dist/learning/trajectory-sources/dataclaw.js +330 -0
  47. package/dist/learning/trajectory-sources/dataclaw.js.map +1 -0
  48. package/dist/learning/trajectory-sources/entire.d.ts +28 -0
  49. package/dist/learning/trajectory-sources/entire.d.ts.map +1 -0
  50. package/dist/learning/trajectory-sources/entire.js +182 -0
  51. package/dist/learning/trajectory-sources/entire.js.map +1 -0
  52. package/dist/learning/trajectory-sources/file.d.ts +23 -0
  53. package/dist/learning/trajectory-sources/file.d.ts.map +1 -0
  54. package/dist/learning/trajectory-sources/file.js +101 -0
  55. package/dist/learning/trajectory-sources/file.js.map +1 -0
  56. package/dist/learning/trajectory-sources/huggingface.d.ts +36 -0
  57. package/dist/learning/trajectory-sources/huggingface.d.ts.map +1 -0
  58. package/dist/learning/trajectory-sources/huggingface.js +157 -0
  59. package/dist/learning/trajectory-sources/huggingface.js.map +1 -0
  60. package/dist/learning/trajectory-sources/in-memory.d.ts +21 -0
  61. package/dist/learning/trajectory-sources/in-memory.d.ts.map +1 -0
  62. package/dist/learning/trajectory-sources/in-memory.js +43 -0
  63. package/dist/learning/trajectory-sources/in-memory.js.map +1 -0
  64. package/dist/learning/trajectory-sources/index.d.ts +7 -0
  65. package/dist/learning/trajectory-sources/index.d.ts.map +1 -0
  66. package/dist/learning/trajectory-sources/index.js +7 -0
  67. package/dist/learning/trajectory-sources/index.js.map +1 -0
  68. package/dist/learning/trajectory-sources/pipeline.d.ts +24 -0
  69. package/dist/learning/trajectory-sources/pipeline.d.ts.map +1 -0
  70. package/dist/learning/trajectory-sources/pipeline.js +47 -0
  71. package/dist/learning/trajectory-sources/pipeline.js.map +1 -0
  72. package/dist/memory/graph-layers/base.d.ts +29 -0
  73. package/dist/memory/graph-layers/base.d.ts.map +1 -0
  74. package/dist/memory/graph-layers/base.js +143 -0
  75. package/dist/memory/graph-layers/base.js.map +1 -0
  76. package/dist/memory/graph-layers/causal.d.ts +14 -0
  77. package/dist/memory/graph-layers/causal.d.ts.map +1 -0
  78. package/dist/memory/graph-layers/causal.js +14 -0
  79. package/dist/memory/graph-layers/causal.js.map +1 -0
  80. package/dist/memory/graph-layers/entity.d.ts +14 -0
  81. package/dist/memory/graph-layers/entity.d.ts.map +1 -0
  82. package/dist/memory/graph-layers/entity.js +14 -0
  83. package/dist/memory/graph-layers/entity.js.map +1 -0
  84. package/dist/memory/graph-layers/index.d.ts +6 -0
  85. package/dist/memory/graph-layers/index.d.ts.map +1 -0
  86. package/dist/memory/graph-layers/index.js +6 -0
  87. package/dist/memory/graph-layers/index.js.map +1 -0
  88. package/dist/memory/graph-layers/semantic.d.ts +14 -0
  89. package/dist/memory/graph-layers/semantic.d.ts.map +1 -0
  90. package/dist/memory/graph-layers/semantic.js +14 -0
  91. package/dist/memory/graph-layers/semantic.js.map +1 -0
  92. package/dist/memory/graph-layers/temporal.d.ts +14 -0
  93. package/dist/memory/graph-layers/temporal.d.ts.map +1 -0
  94. package/dist/memory/graph-layers/temporal.js +14 -0
  95. package/dist/memory/graph-layers/temporal.js.map +1 -0
  96. package/dist/memory/index.d.ts +8 -0
  97. package/dist/memory/index.d.ts.map +1 -1
  98. package/dist/memory/index.js +10 -0
  99. package/dist/memory/index.js.map +1 -1
  100. package/dist/memory/knowledge-bank.d.ts +220 -0
  101. package/dist/memory/knowledge-bank.d.ts.map +1 -0
  102. package/dist/memory/knowledge-bank.js +1003 -0
  103. package/dist/memory/knowledge-bank.js.map +1 -0
  104. package/dist/memory/knowledge-defrag.d.ts +49 -0
  105. package/dist/memory/knowledge-defrag.d.ts.map +1 -0
  106. package/dist/memory/knowledge-defrag.js +257 -0
  107. package/dist/memory/knowledge-defrag.js.map +1 -0
  108. package/dist/memory/knowledge-graph.d.ts +41 -0
  109. package/dist/memory/knowledge-graph.d.ts.map +1 -0
  110. package/dist/memory/knowledge-graph.js +273 -0
  111. package/dist/memory/knowledge-graph.js.map +1 -0
  112. package/dist/memory/search-provider.d.ts +31 -0
  113. package/dist/memory/search-provider.d.ts.map +1 -0
  114. package/dist/memory/search-provider.js +2 -0
  115. package/dist/memory/search-provider.js.map +1 -0
  116. package/dist/memory/search-providers/index.d.ts +3 -0
  117. package/dist/memory/search-providers/index.d.ts.map +1 -0
  118. package/dist/memory/search-providers/index.js +3 -0
  119. package/dist/memory/search-providers/index.js.map +1 -0
  120. package/dist/memory/search-providers/minimem.d.ts +43 -0
  121. package/dist/memory/search-providers/minimem.d.ts.map +1 -0
  122. package/dist/memory/search-providers/minimem.js +56 -0
  123. package/dist/memory/search-providers/minimem.js.map +1 -0
  124. package/dist/memory/search-providers/text-similarity.d.ts +15 -0
  125. package/dist/memory/search-providers/text-similarity.d.ts.map +1 -0
  126. package/dist/memory/search-providers/text-similarity.js +21 -0
  127. package/dist/memory/search-providers/text-similarity.js.map +1 -0
  128. package/dist/memory/skill-exporter.d.ts +75 -0
  129. package/dist/memory/skill-exporter.d.ts.map +1 -0
  130. package/dist/memory/skill-exporter.js +248 -0
  131. package/dist/memory/skill-exporter.js.map +1 -0
  132. package/dist/memory/system.d.ts +15 -3
  133. package/dist/memory/system.d.ts.map +1 -1
  134. package/dist/memory/system.js +46 -8
  135. package/dist/memory/system.js.map +1 -1
  136. package/dist/memory/team-experience.d.ts +298 -0
  137. package/dist/memory/team-experience.d.ts.map +1 -0
  138. package/dist/memory/team-experience.js +355 -0
  139. package/dist/memory/team-experience.js.map +1 -0
  140. package/dist/runtime/backends/acp-protocol.d.ts +49 -0
  141. package/dist/runtime/backends/acp-protocol.d.ts.map +1 -0
  142. package/dist/runtime/backends/acp-protocol.js +166 -0
  143. package/dist/runtime/backends/acp-protocol.js.map +1 -0
  144. package/dist/runtime/backends/acp.d.ts +26 -26
  145. package/dist/runtime/backends/acp.d.ts.map +1 -1
  146. package/dist/runtime/backends/acp.js +32 -156
  147. package/dist/runtime/backends/acp.js.map +1 -1
  148. package/dist/runtime/backends/index.d.ts +3 -1
  149. package/dist/runtime/backends/index.d.ts.map +1 -1
  150. package/dist/runtime/backends/index.js +3 -1
  151. package/dist/runtime/backends/index.js.map +1 -1
  152. package/dist/runtime/backends/macro-agent.d.ts +104 -0
  153. package/dist/runtime/backends/macro-agent.d.ts.map +1 -0
  154. package/dist/runtime/backends/macro-agent.js +107 -0
  155. package/dist/runtime/backends/macro-agent.js.map +1 -0
  156. package/dist/runtime/compute-provider.d.ts +87 -0
  157. package/dist/runtime/compute-provider.d.ts.map +1 -0
  158. package/dist/runtime/compute-provider.js +87 -0
  159. package/dist/runtime/compute-provider.js.map +1 -0
  160. package/dist/runtime/index.d.ts +3 -2
  161. package/dist/runtime/index.d.ts.map +1 -1
  162. package/dist/runtime/index.js +3 -1
  163. package/dist/runtime/index.js.map +1 -1
  164. package/dist/runtime/manager.d.ts +37 -4
  165. package/dist/runtime/manager.d.ts.map +1 -1
  166. package/dist/runtime/manager.js +139 -20
  167. package/dist/runtime/manager.js.map +1 -1
  168. package/dist/runtime/types.d.ts +38 -0
  169. package/dist/runtime/types.d.ts.map +1 -1
  170. package/dist/search/evaluator.d.ts +7 -0
  171. package/dist/search/evaluator.d.ts.map +1 -1
  172. package/dist/search/evaluator.js +24 -4
  173. package/dist/search/evaluator.js.map +1 -1
  174. package/dist/search/index.d.ts +1 -0
  175. package/dist/search/index.d.ts.map +1 -1
  176. package/dist/search/index.js +2 -0
  177. package/dist/search/index.js.map +1 -1
  178. package/dist/search/refinement-loop.d.ts +17 -0
  179. package/dist/search/refinement-loop.d.ts.map +1 -1
  180. package/dist/search/refinement-loop.js +77 -6
  181. package/dist/search/refinement-loop.js.map +1 -1
  182. package/dist/search/refinement-types.d.ts +2 -2
  183. package/dist/search/team-router.d.ts +91 -0
  184. package/dist/search/team-router.d.ts.map +1 -0
  185. package/dist/search/team-router.js +315 -0
  186. package/dist/search/team-router.js.map +1 -0
  187. package/dist/session-bank/git-reader.d.ts +39 -0
  188. package/dist/session-bank/git-reader.d.ts.map +1 -0
  189. package/dist/session-bank/git-reader.js +165 -0
  190. package/dist/session-bank/git-reader.js.map +1 -0
  191. package/dist/session-bank/index.d.ts +5 -0
  192. package/dist/session-bank/index.d.ts.map +1 -0
  193. package/dist/session-bank/index.js +4 -0
  194. package/dist/session-bank/index.js.map +1 -0
  195. package/dist/session-bank/parser.d.ts +39 -0
  196. package/dist/session-bank/parser.d.ts.map +1 -0
  197. package/dist/session-bank/parser.js +231 -0
  198. package/dist/session-bank/parser.js.map +1 -0
  199. package/dist/session-bank/session-bank.d.ts +35 -0
  200. package/dist/session-bank/session-bank.d.ts.map +1 -0
  201. package/dist/session-bank/session-bank.js +326 -0
  202. package/dist/session-bank/session-bank.js.map +1 -0
  203. package/dist/session-bank/types.d.ts +129 -0
  204. package/dist/session-bank/types.d.ts.map +1 -0
  205. package/dist/session-bank/types.js +7 -0
  206. package/dist/session-bank/types.js.map +1 -0
  207. package/dist/surfacing/index.d.ts +4 -0
  208. package/dist/surfacing/index.d.ts.map +1 -1
  209. package/dist/surfacing/index.js +3 -0
  210. package/dist/surfacing/index.js.map +1 -1
  211. package/dist/surfacing/publisher.d.ts +22 -0
  212. package/dist/surfacing/publisher.d.ts.map +1 -0
  213. package/dist/surfacing/publisher.js +9 -0
  214. package/dist/surfacing/publisher.js.map +1 -0
  215. package/dist/surfacing/skill-library.d.ts +12 -0
  216. package/dist/surfacing/skill-library.d.ts.map +1 -1
  217. package/dist/surfacing/skill-library.js +26 -0
  218. package/dist/surfacing/skill-library.js.map +1 -1
  219. package/dist/surfacing/skill-publisher.d.ts +43 -0
  220. package/dist/surfacing/skill-publisher.d.ts.map +1 -0
  221. package/dist/surfacing/skill-publisher.js +197 -0
  222. package/dist/surfacing/skill-publisher.js.map +1 -0
  223. package/dist/surfacing/sqlite-storage-adapter.d.ts +42 -0
  224. package/dist/surfacing/sqlite-storage-adapter.d.ts.map +1 -0
  225. package/dist/surfacing/sqlite-storage-adapter.js +207 -0
  226. package/dist/surfacing/sqlite-storage-adapter.js.map +1 -0
  227. package/dist/surfacing/team-skill-library.d.ts +180 -0
  228. package/dist/surfacing/team-skill-library.d.ts.map +1 -0
  229. package/dist/surfacing/team-skill-library.js +384 -0
  230. package/dist/surfacing/team-skill-library.js.map +1 -0
  231. package/dist/types/config.d.ts +1218 -44
  232. package/dist/types/config.d.ts.map +1 -1
  233. package/dist/types/config.js +216 -0
  234. package/dist/types/config.js.map +1 -1
  235. package/dist/types/dataclaw.d.ts +286 -0
  236. package/dist/types/dataclaw.d.ts.map +1 -0
  237. package/dist/types/dataclaw.js +84 -0
  238. package/dist/types/dataclaw.js.map +1 -0
  239. package/dist/types/index.d.ts +8 -1
  240. package/dist/types/index.d.ts.map +1 -1
  241. package/dist/types/index.js +13 -1
  242. package/dist/types/index.js.map +1 -1
  243. package/dist/types/knowledge-graph.d.ts +148 -0
  244. package/dist/types/knowledge-graph.d.ts.map +1 -0
  245. package/dist/types/knowledge-graph.js +40 -0
  246. package/dist/types/knowledge-graph.js.map +1 -0
  247. package/dist/types/knowledge.d.ts +280 -0
  248. package/dist/types/knowledge.d.ts.map +1 -0
  249. package/dist/types/knowledge.js +191 -0
  250. package/dist/types/knowledge.js.map +1 -0
  251. package/dist/types/team-meta.d.ts +160 -0
  252. package/dist/types/team-meta.d.ts.map +1 -0
  253. package/dist/types/team-meta.js +42 -0
  254. package/dist/types/team-meta.js.map +1 -0
  255. package/dist/types/team-playbook.d.ts +276 -0
  256. package/dist/types/team-playbook.d.ts.map +1 -0
  257. package/dist/types/team-playbook.js +85 -0
  258. package/dist/types/team-playbook.js.map +1 -0
  259. package/dist/types/team-trajectory.d.ts +305 -0
  260. package/dist/types/team-trajectory.d.ts.map +1 -0
  261. package/dist/types/team-trajectory.js +304 -0
  262. package/dist/types/team-trajectory.js.map +1 -0
  263. package/dist/types/trajectory-source.d.ts +39 -0
  264. package/dist/types/trajectory-source.d.ts.map +1 -0
  265. package/dist/types/trajectory-source.js +2 -0
  266. package/dist/types/trajectory-source.js.map +1 -0
  267. package/dist/utils/frontmatter.d.ts +34 -0
  268. package/dist/utils/frontmatter.d.ts.map +1 -0
  269. package/dist/utils/frontmatter.js +93 -0
  270. package/dist/utils/frontmatter.js.map +1 -0
  271. package/dist/utils/index.d.ts +1 -0
  272. package/dist/utils/index.d.ts.map +1 -1
  273. package/dist/utils/index.js +1 -0
  274. package/dist/utils/index.js.map +1 -1
  275. package/dist/workspace/index.d.ts +6 -0
  276. package/dist/workspace/index.d.ts.map +1 -0
  277. package/dist/workspace/index.js +11 -0
  278. package/dist/workspace/index.js.map +1 -0
  279. package/dist/workspace/runner.d.ts +50 -0
  280. package/dist/workspace/runner.d.ts.map +1 -0
  281. package/dist/workspace/runner.js +219 -0
  282. package/dist/workspace/runner.js.map +1 -0
  283. package/dist/workspace/skill-converter.d.ts +18 -0
  284. package/dist/workspace/skill-converter.d.ts.map +1 -0
  285. package/dist/workspace/skill-converter.js +257 -0
  286. package/dist/workspace/skill-converter.js.map +1 -0
  287. package/dist/workspace/templates/index.d.ts +11 -0
  288. package/dist/workspace/templates/index.d.ts.map +1 -0
  289. package/dist/workspace/templates/index.js +21 -0
  290. package/dist/workspace/templates/index.js.map +1 -0
  291. package/dist/workspace/templates/knowledge-defrag.d.ts +25 -0
  292. package/dist/workspace/templates/knowledge-defrag.d.ts.map +1 -0
  293. package/dist/workspace/templates/knowledge-defrag.js +154 -0
  294. package/dist/workspace/templates/knowledge-defrag.js.map +1 -0
  295. package/dist/workspace/templates/knowledge-extraction.d.ts +25 -0
  296. package/dist/workspace/templates/knowledge-extraction.d.ts.map +1 -0
  297. package/dist/workspace/templates/knowledge-extraction.js +246 -0
  298. package/dist/workspace/templates/knowledge-extraction.js.map +1 -0
  299. package/dist/workspace/templates/meta-reflection.d.ts +47 -0
  300. package/dist/workspace/templates/meta-reflection.d.ts.map +1 -0
  301. package/dist/workspace/templates/meta-reflection.js +135 -0
  302. package/dist/workspace/templates/meta-reflection.js.map +1 -0
  303. package/dist/workspace/templates/playbook-extraction.d.ts +20 -0
  304. package/dist/workspace/templates/playbook-extraction.d.ts.map +1 -0
  305. package/dist/workspace/templates/playbook-extraction.js +189 -0
  306. package/dist/workspace/templates/playbook-extraction.js.map +1 -0
  307. package/dist/workspace/templates/refinement-analysis.d.ts +31 -0
  308. package/dist/workspace/templates/refinement-analysis.d.ts.map +1 -0
  309. package/dist/workspace/templates/refinement-analysis.js +107 -0
  310. package/dist/workspace/templates/refinement-analysis.js.map +1 -0
  311. package/dist/workspace/templates/solution-evaluation.d.ts +21 -0
  312. package/dist/workspace/templates/solution-evaluation.d.ts.map +1 -0
  313. package/dist/workspace/templates/solution-evaluation.js +131 -0
  314. package/dist/workspace/templates/solution-evaluation.js.map +1 -0
  315. package/dist/workspace/templates/team-playbook-extraction.d.ts +44 -0
  316. package/dist/workspace/templates/team-playbook-extraction.d.ts.map +1 -0
  317. package/dist/workspace/templates/team-playbook-extraction.js +497 -0
  318. package/dist/workspace/templates/team-playbook-extraction.js.map +1 -0
  319. package/dist/workspace/templates/team-trajectory-analysis.d.ts +19 -0
  320. package/dist/workspace/templates/team-trajectory-analysis.d.ts.map +1 -0
  321. package/dist/workspace/templates/team-trajectory-analysis.js +442 -0
  322. package/dist/workspace/templates/team-trajectory-analysis.js.map +1 -0
  323. package/dist/workspace/templates/trajectory-analysis.d.ts +19 -0
  324. package/dist/workspace/templates/trajectory-analysis.d.ts.map +1 -0
  325. package/dist/workspace/templates/trajectory-analysis.js +170 -0
  326. package/dist/workspace/templates/trajectory-analysis.js.map +1 -0
  327. package/dist/workspace/templates/usage-inference.d.ts +19 -0
  328. package/dist/workspace/templates/usage-inference.d.ts.map +1 -0
  329. package/dist/workspace/templates/usage-inference.js +125 -0
  330. package/dist/workspace/templates/usage-inference.js.map +1 -0
  331. package/dist/workspace/types.d.ts +145 -0
  332. package/dist/workspace/types.d.ts.map +1 -0
  333. package/dist/workspace/types.js +17 -0
  334. package/dist/workspace/types.js.map +1 -0
  335. package/docs/DESIGN-agentic-workspace.md +2057 -0
  336. package/docs/DESIGN-semantic-memory-knowledge-bank.md +1789 -0
  337. package/docs/DESIGN-session-bank.md +1134 -0
  338. package/docs/DESIGN-team-extraction-pipeline.md +1369 -0
  339. package/docs/DESIGN-workspace-migration.md +1079 -0
  340. package/docs/PLAN-agentic-workspace-implementation.md +717 -0
  341. package/docs/PLAN-graph-migration.md +299 -0
  342. package/docs/PLAN-session-bank-implementation.md +474 -0
  343. package/docs/PROPOSAL-team-aware-learning.md +1080 -0
  344. package/docs/RESEARCH-semantic-memory-knowledge-structures.md +517 -0
  345. package/docs/RESEARCH-team-trajectory-learning.md +553 -0
  346. package/gaps.md +204 -0
  347. package/package.json +24 -6
  348. package/references/agent-workspace/CLAUDE.md +74 -0
  349. package/references/agent-workspace/README.md +587 -0
  350. package/references/agent-workspace/media/banner.png +0 -0
  351. package/references/agent-workspace/package-lock.json +2061 -0
  352. package/references/agent-workspace/package.json +54 -0
  353. package/references/agent-workspace/src/handle.ts +122 -0
  354. package/references/agent-workspace/src/index.ts +32 -0
  355. package/references/agent-workspace/src/manager.ts +102 -0
  356. package/references/agent-workspace/src/readers/json.ts +71 -0
  357. package/references/agent-workspace/src/readers/markdown.ts +37 -0
  358. package/references/agent-workspace/src/readers/raw.ts +27 -0
  359. package/references/agent-workspace/src/types.ts +68 -0
  360. package/references/agent-workspace/src/validation.ts +93 -0
  361. package/references/agent-workspace/src/writers/json.ts +17 -0
  362. package/references/agent-workspace/src/writers/markdown.ts +27 -0
  363. package/references/agent-workspace/src/writers/raw.ts +22 -0
  364. package/references/agent-workspace/tests/errors.test.ts +652 -0
  365. package/references/agent-workspace/tests/handle.test.ts +144 -0
  366. package/references/agent-workspace/tests/manager.test.ts +124 -0
  367. package/references/agent-workspace/tests/readers.test.ts +205 -0
  368. package/references/agent-workspace/tests/validation.test.ts +196 -0
  369. package/references/agent-workspace/tests/writers.test.ts +108 -0
  370. package/references/agent-workspace/tsconfig.json +20 -0
  371. package/references/agent-workspace/tsup.config.ts +9 -0
  372. package/references/minimem/.claude/settings.json +7 -0
  373. package/references/minimem/.sudocode/issues.jsonl +18 -0
  374. package/references/minimem/.sudocode/specs.jsonl +1 -0
  375. package/references/minimem/CLAUDE.md +310 -0
  376. package/references/minimem/README.md +556 -0
  377. package/references/minimem/claude-plugin/.claude-plugin/plugin.json +10 -0
  378. package/references/minimem/claude-plugin/.mcp.json +7 -0
  379. package/references/minimem/claude-plugin/README.md +158 -0
  380. package/references/minimem/claude-plugin/commands/recall.md +47 -0
  381. package/references/minimem/claude-plugin/commands/remember.md +41 -0
  382. package/references/minimem/claude-plugin/hooks/__tests__/hooks.test.ts +272 -0
  383. package/references/minimem/claude-plugin/hooks/hooks.json +27 -0
  384. package/references/minimem/claude-plugin/hooks/session-end.sh +86 -0
  385. package/references/minimem/claude-plugin/hooks/session-start.sh +85 -0
  386. package/references/minimem/claude-plugin/skills/memory/SKILL.md +108 -0
  387. package/references/minimem/package-lock.json +5373 -0
  388. package/references/minimem/package.json +60 -0
  389. package/references/minimem/scripts/postbuild.js +35 -0
  390. package/references/minimem/src/__tests__/edge-cases.test.ts +371 -0
  391. package/references/minimem/src/__tests__/errors.test.ts +265 -0
  392. package/references/minimem/src/__tests__/helpers.ts +199 -0
  393. package/references/minimem/src/__tests__/internal.test.ts +407 -0
  394. package/references/minimem/src/__tests__/knowledge.test.ts +287 -0
  395. package/references/minimem/src/__tests__/minimem.integration.test.ts +1127 -0
  396. package/references/minimem/src/__tests__/session.test.ts +190 -0
  397. package/references/minimem/src/cli/__tests__/commands.test.ts +759 -0
  398. package/references/minimem/src/cli/commands/__tests__/conflicts.test.ts +141 -0
  399. package/references/minimem/src/cli/commands/append.ts +76 -0
  400. package/references/minimem/src/cli/commands/config.ts +262 -0
  401. package/references/minimem/src/cli/commands/conflicts.ts +413 -0
  402. package/references/minimem/src/cli/commands/daemon.ts +169 -0
  403. package/references/minimem/src/cli/commands/index.ts +12 -0
  404. package/references/minimem/src/cli/commands/init.ts +88 -0
  405. package/references/minimem/src/cli/commands/mcp.ts +177 -0
  406. package/references/minimem/src/cli/commands/push-pull.ts +213 -0
  407. package/references/minimem/src/cli/commands/search.ts +158 -0
  408. package/references/minimem/src/cli/commands/status.ts +84 -0
  409. package/references/minimem/src/cli/commands/sync-init.ts +290 -0
  410. package/references/minimem/src/cli/commands/sync.ts +70 -0
  411. package/references/minimem/src/cli/commands/upsert.ts +197 -0
  412. package/references/minimem/src/cli/config.ts +584 -0
  413. package/references/minimem/src/cli/index.ts +264 -0
  414. package/references/minimem/src/cli/shared.ts +161 -0
  415. package/references/minimem/src/cli/sync/__tests__/central.test.ts +152 -0
  416. package/references/minimem/src/cli/sync/__tests__/conflicts.test.ts +209 -0
  417. package/references/minimem/src/cli/sync/__tests__/daemon.test.ts +118 -0
  418. package/references/minimem/src/cli/sync/__tests__/detection.test.ts +207 -0
  419. package/references/minimem/src/cli/sync/__tests__/integration.test.ts +476 -0
  420. package/references/minimem/src/cli/sync/__tests__/registry.test.ts +363 -0
  421. package/references/minimem/src/cli/sync/__tests__/state.test.ts +255 -0
  422. package/references/minimem/src/cli/sync/__tests__/validation.test.ts +193 -0
  423. package/references/minimem/src/cli/sync/__tests__/watcher.test.ts +178 -0
  424. package/references/minimem/src/cli/sync/central.ts +292 -0
  425. package/references/minimem/src/cli/sync/conflicts.ts +204 -0
  426. package/references/minimem/src/cli/sync/daemon.ts +407 -0
  427. package/references/minimem/src/cli/sync/detection.ts +138 -0
  428. package/references/minimem/src/cli/sync/index.ts +107 -0
  429. package/references/minimem/src/cli/sync/operations.ts +373 -0
  430. package/references/minimem/src/cli/sync/registry.ts +279 -0
  431. package/references/minimem/src/cli/sync/state.ts +355 -0
  432. package/references/minimem/src/cli/sync/validation.ts +206 -0
  433. package/references/minimem/src/cli/sync/watcher.ts +234 -0
  434. package/references/minimem/src/cli/version.ts +34 -0
  435. package/references/minimem/src/core/index.ts +9 -0
  436. package/references/minimem/src/core/indexer.ts +628 -0
  437. package/references/minimem/src/core/searcher.ts +221 -0
  438. package/references/minimem/src/db/schema.ts +183 -0
  439. package/references/minimem/src/db/sqlite-vec.ts +24 -0
  440. package/references/minimem/src/embeddings/__tests__/embeddings.test.ts +431 -0
  441. package/references/minimem/src/embeddings/batch-gemini.ts +392 -0
  442. package/references/minimem/src/embeddings/batch-openai.ts +409 -0
  443. package/references/minimem/src/embeddings/embeddings.ts +434 -0
  444. package/references/minimem/src/index.ts +109 -0
  445. package/references/minimem/src/internal.ts +299 -0
  446. package/references/minimem/src/minimem.ts +1276 -0
  447. package/references/minimem/src/search/__tests__/hybrid.test.ts +247 -0
  448. package/references/minimem/src/search/graph.ts +234 -0
  449. package/references/minimem/src/search/hybrid.ts +151 -0
  450. package/references/minimem/src/search/search.ts +256 -0
  451. package/references/minimem/src/server/__tests__/mcp.test.ts +341 -0
  452. package/references/minimem/src/server/__tests__/tools.test.ts +364 -0
  453. package/references/minimem/src/server/mcp.ts +326 -0
  454. package/references/minimem/src/server/tools.ts +720 -0
  455. package/references/minimem/src/session.ts +460 -0
  456. package/references/minimem/tsconfig.json +19 -0
  457. package/references/minimem/tsup.config.ts +26 -0
  458. package/references/minimem/vitest.config.ts +24 -0
  459. package/references/skill-tree/.claude/settings.json +6 -0
  460. package/references/skill-tree/.sudocode/issues.jsonl +11 -0
  461. package/references/skill-tree/.sudocode/specs.jsonl +1 -0
  462. package/references/skill-tree/CLAUDE.md +150 -0
  463. package/references/skill-tree/README.md +324 -0
  464. package/references/skill-tree/docs/GAPS_v1.md +221 -0
  465. package/references/skill-tree/docs/INTEGRATION_PLAN.md +467 -0
  466. package/references/skill-tree/docs/TODOS.md +91 -0
  467. package/references/skill-tree/docs/anthropic_skill_guide.md +1364 -0
  468. package/references/skill-tree/docs/design/federated-skill-trees.md +524 -0
  469. package/references/skill-tree/docs/design/multi-agent-sync.md +759 -0
  470. package/references/skill-tree/docs/scraper/BRAINSTORM.md +583 -0
  471. package/references/skill-tree/docs/scraper/POC_PLAN.md +420 -0
  472. package/references/skill-tree/docs/scraper/README.md +170 -0
  473. package/references/skill-tree/examples/basic-usage.ts +190 -0
  474. package/references/skill-tree/package-lock.json +1509 -0
  475. package/references/skill-tree/package.json +66 -0
  476. package/references/skill-tree/scraper/README.md +123 -0
  477. package/references/skill-tree/scraper/docs/DESIGN.md +683 -0
  478. package/references/skill-tree/scraper/docs/PLAN.md +336 -0
  479. package/references/skill-tree/scraper/drizzle.config.ts +10 -0
  480. package/references/skill-tree/scraper/package-lock.json +6329 -0
  481. package/references/skill-tree/scraper/package.json +68 -0
  482. package/references/skill-tree/scraper/test/fixtures/invalid-skill/missing-description.md +7 -0
  483. package/references/skill-tree/scraper/test/fixtures/invalid-skill/missing-name.md +7 -0
  484. package/references/skill-tree/scraper/test/fixtures/minimal-skill/SKILL.md +27 -0
  485. package/references/skill-tree/scraper/test/fixtures/skill-json/SKILL.json +21 -0
  486. package/references/skill-tree/scraper/test/fixtures/skill-with-meta/SKILL.md +54 -0
  487. package/references/skill-tree/scraper/test/fixtures/skill-with-meta/_meta.json +24 -0
  488. package/references/skill-tree/scraper/test/fixtures/valid-skill/SKILL.md +93 -0
  489. package/references/skill-tree/scraper/test/fixtures/valid-skill/_meta.json +22 -0
  490. package/references/skill-tree/scraper/tsup.config.ts +14 -0
  491. package/references/skill-tree/scraper/vitest.config.ts +17 -0
  492. package/references/skill-tree/scripts/convert-to-vitest.ts +166 -0
  493. package/references/skill-tree/skills/skill-writer/SKILL.md +339 -0
  494. package/references/skill-tree/skills/skill-writer/references/examples.md +326 -0
  495. package/references/skill-tree/skills/skill-writer/references/patterns.md +210 -0
  496. package/references/skill-tree/skills/skill-writer/references/quality-checklist.md +123 -0
  497. package/references/skill-tree/test/run-all.ts +106 -0
  498. package/references/skill-tree/test/utils.ts +128 -0
  499. package/references/skill-tree/vitest.config.ts +16 -0
  500. package/src/atlas.ts +525 -13
  501. package/src/embeddings/provider.ts +10 -3
  502. package/src/index.ts +127 -5
  503. package/src/learning/index.ts +41 -6
  504. package/src/learning/knowledge-extractor.ts +470 -0
  505. package/src/learning/meta-learner.ts +54 -0
  506. package/src/learning/pipeline.ts +87 -8
  507. package/src/learning/team-ingester.ts +499 -0
  508. package/src/learning/team-meta-learner.ts +558 -0
  509. package/src/learning/team-pipeline.ts +364 -0
  510. package/src/learning/trajectory-sources/dataclaw.ts +403 -0
  511. package/src/learning/trajectory-sources/entire.ts +240 -0
  512. package/src/learning/trajectory-sources/file.ts +136 -0
  513. package/src/learning/trajectory-sources/huggingface.ts +248 -0
  514. package/src/learning/trajectory-sources/in-memory.ts +61 -0
  515. package/src/learning/trajectory-sources/index.ts +15 -0
  516. package/src/learning/trajectory-sources/pipeline.ts +69 -0
  517. package/src/memory/graph-layers/base.ts +184 -0
  518. package/src/memory/graph-layers/causal.ts +16 -0
  519. package/src/memory/graph-layers/entity.ts +16 -0
  520. package/src/memory/graph-layers/index.ts +5 -0
  521. package/src/memory/graph-layers/semantic.ts +16 -0
  522. package/src/memory/graph-layers/temporal.ts +16 -0
  523. package/src/memory/index.ts +45 -0
  524. package/src/memory/knowledge-bank.ts +1260 -0
  525. package/src/memory/knowledge-defrag.ts +329 -0
  526. package/src/memory/knowledge-graph.ts +361 -0
  527. package/src/memory/search-provider.ts +35 -0
  528. package/src/memory/search-providers/index.ts +3 -0
  529. package/src/memory/search-providers/minimem.ts +84 -0
  530. package/src/memory/search-providers/text-similarity.ts +35 -0
  531. package/src/memory/skill-exporter.ts +357 -0
  532. package/src/memory/system.ts +61 -8
  533. package/src/memory/team-experience.ts +604 -0
  534. package/src/runtime/backends/acp-protocol.ts +231 -0
  535. package/src/runtime/backends/acp.ts +57 -196
  536. package/src/runtime/backends/index.ts +14 -0
  537. package/src/runtime/backends/macro-agent.ts +177 -0
  538. package/src/runtime/compute-provider.ts +206 -0
  539. package/src/runtime/index.ts +22 -0
  540. package/src/runtime/manager.ts +167 -23
  541. package/src/runtime/types.ts +41 -0
  542. package/src/search/evaluator.ts +29 -4
  543. package/src/search/index.ts +9 -0
  544. package/src/search/refinement-loop.ts +106 -12
  545. package/src/search/team-router.ts +459 -0
  546. package/src/session-bank/git-reader.ts +190 -0
  547. package/src/session-bank/index.ts +24 -0
  548. package/src/session-bank/parser.ts +366 -0
  549. package/src/session-bank/session-bank.ts +464 -0
  550. package/src/session-bank/types.ts +173 -0
  551. package/src/surfacing/index.ts +23 -0
  552. package/src/surfacing/publisher.ts +23 -0
  553. package/src/surfacing/skill-library.ts +31 -0
  554. package/src/surfacing/skill-publisher.ts +223 -0
  555. package/src/surfacing/sqlite-storage-adapter.ts +301 -0
  556. package/src/surfacing/team-skill-library.ts +610 -0
  557. package/src/types/config.ts +252 -0
  558. package/src/types/dataclaw.ts +99 -0
  559. package/src/types/huggingface-transformers.d.ts +12 -0
  560. package/src/types/index.ts +156 -0
  561. package/src/types/knowledge-graph.ts +246 -0
  562. package/src/types/knowledge.ts +388 -0
  563. package/src/types/team-meta.ts +212 -0
  564. package/src/types/team-playbook.ts +384 -0
  565. package/src/types/team-trajectory.ts +673 -0
  566. package/src/types/trajectory-source.ts +47 -0
  567. package/src/utils/frontmatter.ts +118 -0
  568. package/src/utils/index.ts +7 -0
  569. package/src/workspace/index.ts +48 -0
  570. package/src/workspace/runner.ts +281 -0
  571. package/src/workspace/skill-converter.ts +288 -0
  572. package/src/workspace/templates/index.ts +64 -0
  573. package/src/workspace/templates/knowledge-defrag.ts +223 -0
  574. package/src/workspace/templates/knowledge-extraction.ts +337 -0
  575. package/src/workspace/templates/meta-reflection.ts +208 -0
  576. package/src/workspace/templates/playbook-extraction.ts +240 -0
  577. package/src/workspace/templates/refinement-analysis.ts +162 -0
  578. package/src/workspace/templates/solution-evaluation.ts +199 -0
  579. package/src/workspace/templates/team-playbook-extraction.ts +631 -0
  580. package/src/workspace/templates/team-trajectory-analysis.ts +564 -0
  581. package/src/workspace/templates/trajectory-analysis.ts +234 -0
  582. package/src/workspace/templates/usage-inference.ts +163 -0
  583. package/src/workspace/types.ts +233 -0
  584. package/tests/atlas-knowledge.test.ts +165 -0
  585. package/tests/gap-fixes.test.ts +1103 -0
  586. package/tests/integration/dataclaw-e2e.test.ts +559 -0
  587. package/tests/integration/e2e.test.ts +407 -0
  588. package/tests/integration/entire-e2e.test.ts +187 -0
  589. package/tests/integration/huggingface-e2e.test.ts +627 -0
  590. package/tests/integration/session-bank.test.ts +225 -0
  591. package/tests/integration/skill-tree-wiring.test.ts +152 -0
  592. package/tests/learning/dataclaw-trajectory-source.test.ts +642 -0
  593. package/tests/learning/entire-trajectory-source.test.ts +380 -0
  594. package/tests/learning/huggingface-trajectory-source.test.ts +817 -0
  595. package/tests/learning/knowledge-extractor.test.ts +491 -0
  596. package/tests/learning/team-ingester.test.ts +349 -0
  597. package/tests/learning/team-meta-learner.test.ts +618 -0
  598. package/tests/learning/team-pipeline.test.ts +334 -0
  599. package/tests/learning/trajectory-sources.test.ts +312 -0
  600. package/tests/memory/graph-layers/semantic.test.ts +219 -0
  601. package/tests/memory/knowledge-bank-extraction.test.ts +558 -0
  602. package/tests/memory/knowledge-bank.test.ts +705 -0
  603. package/tests/memory/knowledge-defrag.test.ts +366 -0
  604. package/tests/memory/knowledge-evolution.test.ts +563 -0
  605. package/tests/memory/knowledge-graph.test.ts +492 -0
  606. package/tests/memory/knowledge-inbox.test.ts +258 -0
  607. package/tests/memory/knowledge-minimem.test.ts +251 -0
  608. package/tests/memory/skill-exporter.test.ts +470 -0
  609. package/tests/memory/team-experience.test.ts +411 -0
  610. package/tests/runtime/agent-manager.test.ts +1 -1
  611. package/tests/runtime/compute-provider.test.ts +288 -0
  612. package/tests/runtime/delegate.test.ts +349 -0
  613. package/tests/runtime/macro-agent-backend.test.ts +266 -0
  614. package/tests/search/team-router.test.ts +376 -0
  615. package/tests/session-bank/fixtures/multi-tool-session/full.jsonl +12 -0
  616. package/tests/session-bank/fixtures/multi-tool-session/metadata.json +28 -0
  617. package/tests/session-bank/fixtures/root-metadata.json +18 -0
  618. package/tests/session-bank/fixtures/simple-session/full.jsonl +6 -0
  619. package/tests/session-bank/fixtures/simple-session/metadata.json +38 -0
  620. package/tests/session-bank/git-reader.test.ts +232 -0
  621. package/tests/session-bank/parser.test.ts +321 -0
  622. package/tests/session-bank/session-bank.test.ts +546 -0
  623. package/tests/surfacing/skill-publisher.test.ts +398 -0
  624. package/tests/surfacing/sqlite-storage-adapter.test.ts +218 -0
  625. package/tests/surfacing/team-skill-library.test.ts +444 -0
  626. package/tests/types/team-meta.test.ts +147 -0
  627. package/tests/types/team-playbook.test.ts +246 -0
  628. package/tests/types/team-trajectory.test.ts +557 -0
  629. package/tests/utils/frontmatter.test.ts +208 -0
  630. package/tests/workspace/full-flow.test.ts +839 -0
  631. package/tests/workspace/manager.test.ts +215 -0
  632. package/tests/workspace/runner.test.ts +330 -0
  633. package/tests/workspace/skill-converter.test.ts +205 -0
  634. package/tests/workspace/templates/knowledge-extraction.test.ts +235 -0
  635. package/tests/workspace/templates/team-playbook-extraction.test.ts +341 -0
  636. package/tests/workspace/templates/team-trajectory-analysis.test.ts +417 -0
  637. package/src/learning/llm-extractor.ts +0 -542
@@ -0,0 +1,231 @@
1
+ /**
2
+ * ACP Protocol Handler (Base Class)
3
+ *
4
+ * Extracts the ACP wire protocol handling (processUpdate, runPrompt,
5
+ * session state management) from the monolithic ACPBackend into a
6
+ * reusable base class.
7
+ *
8
+ * Backend implementations (local, remote) extend this and provide
9
+ * their own spawn() / terminate() for their compute environment.
10
+ */
11
+ import type {
12
+ Session,
13
+ ExtendedSessionUpdate,
14
+ } from 'acp-factory';
15
+ import type {
16
+ AgentSpawnConfig,
17
+ AgentSession,
18
+ AgentMessage,
19
+ ToolCall,
20
+ } from '../types.js';
21
+
22
+ // ============================================================
23
+ // Session State Types
24
+ // ============================================================
25
+
26
+ /**
27
+ * Base session state shared by all ACP backends.
28
+ * Subclasses can extend this with backend-specific fields.
29
+ */
30
+ export interface ACPSessionBase {
31
+ atlasSession: AgentSession;
32
+ acpSession: Session;
33
+ }
34
+
35
+ // ============================================================
36
+ // Protocol Handler Base Class
37
+ // ============================================================
38
+
39
+ /**
40
+ * Abstract base class that handles ACP wire protocol concerns:
41
+ * - processUpdate(): Parses ExtendedSessionUpdate into AgentSession messages/tool calls
42
+ * - runPrompt(): Streams updates from an ACP session prompt
43
+ * - Common session accessors (getSession, sendMessage, listSessions)
44
+ *
45
+ * Subclasses provide their own lifecycle management (spawn, terminate).
46
+ */
47
+ export abstract class ACPProtocolHandler<
48
+ TState extends ACPSessionBase = ACPSessionBase,
49
+ > {
50
+ protected sessions: Map<string, TState> = new Map();
51
+
52
+ // ----------------------------------------------------------
53
+ // Protocol: process a single ACP session update
54
+ // ----------------------------------------------------------
55
+
56
+ /**
57
+ * Process a session update from the agent.
58
+ * Uses defensive typing since ACP types can vary.
59
+ */
60
+ protected processUpdate(
61
+ session: AgentSession,
62
+ update: ExtendedSessionUpdate,
63
+ config: AgentSpawnConfig,
64
+ ): void {
65
+ // Cast to any for flexible property access since ACP types are complex unions
66
+ const u = update as Record<string, unknown>;
67
+ const updateType = u.sessionUpdate as string;
68
+
69
+ switch (updateType) {
70
+ case 'agent_message_chunk':
71
+ case 'user_message_chunk':
72
+ case 'agent_thought_chunk': {
73
+ // ContentChunk has a single 'content' field (ContentBlock)
74
+ const content = u.content as Record<string, unknown> | undefined;
75
+ if (content && content.type === 'text' && typeof content.text === 'string') {
76
+ const message: AgentMessage = {
77
+ role: updateType === 'user_message_chunk' ? 'user' : 'assistant',
78
+ content: content.text,
79
+ timestamp: new Date(),
80
+ };
81
+ session.messages.push(message);
82
+ config.onMessage?.(message);
83
+ }
84
+ break;
85
+ }
86
+
87
+ case 'tool_call': {
88
+ // ToolCall has toolCallId, title, rawInput, status, content, etc.
89
+ const toolCallId = (u.toolCallId as string) ?? crypto.randomUUID();
90
+ const title = (u.title as string) ?? 'unknown';
91
+ const rawInput = u.rawInput;
92
+
93
+ const toolCall: ToolCall = {
94
+ id: toolCallId,
95
+ name: title,
96
+ input: rawInput,
97
+ startTime: new Date(),
98
+ };
99
+ session.toolCalls.push(toolCall);
100
+ config.onToolCall?.(toolCall);
101
+ break;
102
+ }
103
+
104
+ case 'tool_call_update': {
105
+ // ToolCallUpdate has toolCallId, status, content, etc.
106
+ const toolCallId = u.toolCallId as string;
107
+ const status = u.status as string | undefined;
108
+ const content = u.content as Array<Record<string, unknown>> | undefined;
109
+
110
+ const existingTc = session.toolCalls.find((t) => t.id === toolCallId);
111
+ if (existingTc) {
112
+ if (status === 'completed' || status === 'failed') {
113
+ existingTc.endTime = new Date();
114
+ }
115
+ if (content && Array.isArray(content)) {
116
+ // Extract text from content blocks
117
+ const outputs: string[] = [];
118
+ for (const block of content) {
119
+ if (block.type === 'text' && typeof block.text === 'string') {
120
+ outputs.push(block.text);
121
+ } else if (block.type === 'diff' && typeof block.diff === 'string') {
122
+ outputs.push(block.diff);
123
+ }
124
+ }
125
+ if (outputs.length > 0) {
126
+ existingTc.output = outputs.join('\n');
127
+ }
128
+ }
129
+ if (status === 'failed') {
130
+ existingTc.error = 'Tool call failed';
131
+ }
132
+ }
133
+ break;
134
+ }
135
+
136
+ case 'permission_request': {
137
+ // In auto-approve mode, this shouldn't happen, but log it
138
+ session.messages.push({
139
+ role: 'system',
140
+ content: `Permission requested: ${JSON.stringify(update)}`,
141
+ timestamp: new Date(),
142
+ });
143
+ break;
144
+ }
145
+
146
+ case 'plan': {
147
+ // Agent shared its plan
148
+ const plan = u.plan;
149
+ session.messages.push({
150
+ role: 'assistant',
151
+ content: `[Plan] ${JSON.stringify(plan)}`,
152
+ timestamp: new Date(),
153
+ });
154
+ break;
155
+ }
156
+
157
+ default:
158
+ // Log other updates for debugging
159
+ session.metadata.lastUpdate = update;
160
+ }
161
+ }
162
+
163
+ // ----------------------------------------------------------
164
+ // Protocol: run a prompt and collect streaming updates
165
+ // ----------------------------------------------------------
166
+
167
+ /**
168
+ * Run a prompt on an ACP session and collect all streaming updates
169
+ * into the Atlas session.
170
+ */
171
+ protected async runPrompt(
172
+ state: TState,
173
+ promptContent: string,
174
+ config: AgentSpawnConfig,
175
+ ): Promise<void> {
176
+ const { atlasSession, acpSession } = state;
177
+
178
+ try {
179
+ // Stream updates from the agent
180
+ for await (const update of acpSession.prompt(promptContent)) {
181
+ this.processUpdate(atlasSession, update, config);
182
+ }
183
+
184
+ // Mark as completed
185
+ atlasSession.state = 'completed';
186
+ atlasSession.endTime = new Date();
187
+ } catch (error) {
188
+ atlasSession.state = 'failed';
189
+ atlasSession.error = error instanceof Error ? error.message : 'Unknown error';
190
+ atlasSession.endTime = new Date();
191
+ console.error(
192
+ `[ACPProtocol] Session ${atlasSession.id} prompt execution failed:`,
193
+ error instanceof Error ? error.message : String(error),
194
+ );
195
+ }
196
+ }
197
+
198
+ // ----------------------------------------------------------
199
+ // Common session accessors
200
+ // ----------------------------------------------------------
201
+
202
+ async getSession(sessionId: string): Promise<AgentSession | undefined> {
203
+ return this.sessions.get(sessionId)?.atlasSession;
204
+ }
205
+
206
+ async sendMessage(sessionId: string, message: string): Promise<void> {
207
+ const state = this.sessions.get(sessionId);
208
+ if (!state) {
209
+ throw new Error('Session not found');
210
+ }
211
+
212
+ // Send additional prompt
213
+ for await (const update of state.acpSession.prompt(message)) {
214
+ this.processUpdate(state.atlasSession, update, {
215
+ agentType: state.atlasSession.agentType,
216
+ task: state.atlasSession.task,
217
+ });
218
+ }
219
+ }
220
+
221
+ async listSessions(): Promise<AgentSession[]> {
222
+ return Array.from(this.sessions.values()).map((s) => s.atlasSession);
223
+ }
224
+
225
+ /**
226
+ * Get a raw ACP session for advanced usage
227
+ */
228
+ getACPSession(sessionId: string): Session | undefined {
229
+ return this.sessions.get(sessionId)?.acpSession;
230
+ }
231
+ }
@@ -1,24 +1,26 @@
1
1
  /**
2
- * ACP Backend using acp-factory
2
+ * Local ACP Backend using acp-factory
3
3
  *
4
- * This backend uses the acp-factory package to spawn and manage ACP-compatible
5
- * agents like Claude Code, providing a clean interface for Atlas integration.
4
+ * Extends ACPProtocolHandler with local process spawning via AgentFactory.
5
+ * The protocol handling (processUpdate, runPrompt, session management) is
6
+ * inherited from the base class so it can be reused by future remote backends.
6
7
  */
7
8
  import {
8
9
  AgentFactory,
9
10
  AgentHandle,
10
- Session,
11
11
  type AgentConfig,
12
12
  type SpawnOptions,
13
- type ExtendedSessionUpdate,
14
13
  } from 'acp-factory';
15
14
  import type {
16
15
  AgentBackend,
17
16
  AgentSpawnConfig,
18
17
  AgentSession,
19
- AgentMessage,
20
- ToolCall,
21
18
  } from '../types.js';
19
+ import { ACPProtocolHandler, type ACPSessionBase } from './acp-protocol.js';
20
+
21
+ // ============================================================
22
+ // Configuration Types
23
+ // ============================================================
22
24
 
23
25
  /**
24
26
  * ACP agent configuration
@@ -28,27 +30,39 @@ export interface ACPAgentConfig extends AgentConfig {
28
30
  displayName?: string;
29
31
  }
30
32
 
33
+ // ============================================================
34
+ // Local Session State
35
+ // ============================================================
36
+
31
37
  /**
32
- * Active ACP session state
38
+ * Session state for locally-spawned ACP agents.
39
+ * Extends the base with an AgentHandle for process lifecycle.
33
40
  */
34
- interface ACPSessionState {
35
- atlasSession: AgentSession;
41
+ interface LocalACPSessionState extends ACPSessionBase {
36
42
  agentHandle: AgentHandle;
37
- acpSession: Session;
38
43
  }
39
44
 
45
+ // ============================================================
46
+ // LocalACPBackend
47
+ // ============================================================
48
+
40
49
  /**
41
- * ACP Backend
42
- * Uses acp-factory to spawn and manage ACP-compatible agents
50
+ * Local ACP Backend
51
+ *
52
+ * Spawns ACP-compatible agents as local processes via AgentFactory.
53
+ * Protocol handling is inherited from ACPProtocolHandler.
43
54
  */
44
- export class ACPBackend implements AgentBackend {
55
+ export class LocalACPBackend
56
+ extends ACPProtocolHandler<LocalACPSessionState>
57
+ implements AgentBackend
58
+ {
45
59
  readonly name = 'acp';
46
60
  readonly supportedTypes: string[];
47
61
 
48
- private sessions: Map<string, ACPSessionState> = new Map();
49
62
  private handles: Map<string, AgentHandle> = new Map();
50
63
 
51
64
  constructor(configs: Record<string, ACPAgentConfig>) {
65
+ super();
52
66
  this.supportedTypes = Object.keys(configs);
53
67
 
54
68
  // Register all agent configs with AgentFactory
@@ -83,7 +97,7 @@ export class ACPBackend implements AgentBackend {
83
97
  };
84
98
 
85
99
  try {
86
- // Spawn the agent
100
+ // Spawn the agent locally via AgentFactory
87
101
  const spawnOptions: SpawnOptions = {
88
102
  permissionMode: 'auto-approve', // Auto-approve for automated learning
89
103
  env: config.env,
@@ -100,7 +114,7 @@ export class ACPBackend implements AgentBackend {
100
114
  const acpSession = await agentHandle.createSession(cwd);
101
115
 
102
116
  // Store session state
103
- const state: ACPSessionState = {
117
+ const state: LocalACPSessionState = {
104
118
  atlasSession,
105
119
  agentHandle,
106
120
  acpSession,
@@ -116,7 +130,7 @@ export class ACPBackend implements AgentBackend {
116
130
  promptContent += `\n\n## Additional Context\n\`\`\`json\n${JSON.stringify(config.task.context, null, 2)}\n\`\`\``;
117
131
  }
118
132
 
119
- // Send prompt and collect updates
133
+ // Send prompt and collect updates (inherited protocol handler)
120
134
  await this.runPrompt(state, promptContent, config);
121
135
 
122
136
  return atlasSession;
@@ -125,169 +139,13 @@ export class ACPBackend implements AgentBackend {
125
139
  atlasSession.error = error instanceof Error ? error.message : 'Unknown error';
126
140
  atlasSession.endTime = new Date();
127
141
  console.error(
128
- `[ACPBackend] Session ${atlasSessionId} spawn failed:`,
129
- error instanceof Error ? error.message : String(error)
142
+ `[LocalACPBackend] Session ${atlasSessionId} spawn failed:`,
143
+ error instanceof Error ? error.message : String(error),
130
144
  );
131
145
  return atlasSession;
132
146
  }
133
147
  }
134
148
 
135
- /**
136
- * Run a prompt and collect all updates
137
- */
138
- private async runPrompt(
139
- state: ACPSessionState,
140
- promptContent: string,
141
- config: AgentSpawnConfig
142
- ): Promise<void> {
143
- const { atlasSession, acpSession } = state;
144
-
145
- try {
146
- // Stream updates from the agent
147
- for await (const update of acpSession.prompt(promptContent)) {
148
- this.processUpdate(atlasSession, update, config);
149
- }
150
-
151
- // Mark as completed
152
- atlasSession.state = 'completed';
153
- atlasSession.endTime = new Date();
154
- } catch (error) {
155
- atlasSession.state = 'failed';
156
- atlasSession.error = error instanceof Error ? error.message : 'Unknown error';
157
- atlasSession.endTime = new Date();
158
- console.error(
159
- `[ACPBackend] Session ${atlasSession.id} prompt execution failed:`,
160
- error instanceof Error ? error.message : String(error)
161
- );
162
- }
163
- }
164
-
165
- /**
166
- * Process a session update from the agent
167
- * Uses defensive typing since ACP types can vary
168
- */
169
- private processUpdate(
170
- session: AgentSession,
171
- update: ExtendedSessionUpdate,
172
- config: AgentSpawnConfig
173
- ): void {
174
- // Cast to any for flexible property access since ACP types are complex unions
175
- const u = update as Record<string, unknown>;
176
- const updateType = u.sessionUpdate as string;
177
-
178
- switch (updateType) {
179
- case 'agent_message_chunk':
180
- case 'user_message_chunk':
181
- case 'agent_thought_chunk': {
182
- // ContentChunk has a single 'content' field (ContentBlock)
183
- const content = u.content as Record<string, unknown> | undefined;
184
- if (content && content.type === 'text' && typeof content.text === 'string') {
185
- const message: AgentMessage = {
186
- role: updateType === 'user_message_chunk' ? 'user' : 'assistant',
187
- content: content.text,
188
- timestamp: new Date(),
189
- };
190
- session.messages.push(message);
191
- config.onMessage?.(message);
192
- }
193
- break;
194
- }
195
-
196
- case 'tool_call': {
197
- // ToolCall has toolCallId, title, rawInput, status, content, etc.
198
- const toolCallId = (u.toolCallId as string) ?? crypto.randomUUID();
199
- const title = (u.title as string) ?? 'unknown';
200
- const rawInput = u.rawInput;
201
-
202
- const toolCall: ToolCall = {
203
- id: toolCallId,
204
- name: title,
205
- input: rawInput,
206
- startTime: new Date(),
207
- };
208
- session.toolCalls.push(toolCall);
209
- config.onToolCall?.(toolCall);
210
- break;
211
- }
212
-
213
- case 'tool_call_update': {
214
- // ToolCallUpdate has toolCallId, status, content, etc.
215
- const toolCallId = u.toolCallId as string;
216
- const status = u.status as string | undefined;
217
- const content = u.content as Array<Record<string, unknown>> | undefined;
218
-
219
- const existingTc = session.toolCalls.find((t) => t.id === toolCallId);
220
- if (existingTc) {
221
- if (status === 'completed' || status === 'failed') {
222
- existingTc.endTime = new Date();
223
- }
224
- if (content && Array.isArray(content)) {
225
- // Extract text from content blocks
226
- const outputs: string[] = [];
227
- for (const block of content) {
228
- if (block.type === 'text' && typeof block.text === 'string') {
229
- outputs.push(block.text);
230
- } else if (block.type === 'diff' && typeof block.diff === 'string') {
231
- outputs.push(block.diff);
232
- }
233
- }
234
- if (outputs.length > 0) {
235
- existingTc.output = outputs.join('\n');
236
- }
237
- }
238
- if (status === 'failed') {
239
- existingTc.error = 'Tool call failed';
240
- }
241
- }
242
- break;
243
- }
244
-
245
- case 'permission_request': {
246
- // In auto-approve mode, this shouldn't happen, but log it
247
- session.messages.push({
248
- role: 'system',
249
- content: `Permission requested: ${JSON.stringify(update)}`,
250
- timestamp: new Date(),
251
- });
252
- break;
253
- }
254
-
255
- case 'plan': {
256
- // Agent shared its plan
257
- const plan = u.plan;
258
- session.messages.push({
259
- role: 'assistant',
260
- content: `[Plan] ${JSON.stringify(plan)}`,
261
- timestamp: new Date(),
262
- });
263
- break;
264
- }
265
-
266
- default:
267
- // Log other updates for debugging
268
- session.metadata.lastUpdate = update;
269
- }
270
- }
271
-
272
- async getSession(sessionId: string): Promise<AgentSession | undefined> {
273
- return this.sessions.get(sessionId)?.atlasSession;
274
- }
275
-
276
- async sendMessage(sessionId: string, message: string): Promise<void> {
277
- const state = this.sessions.get(sessionId);
278
- if (!state) {
279
- throw new Error('Session not found');
280
- }
281
-
282
- // Send additional prompt
283
- for await (const update of state.acpSession.prompt(message)) {
284
- this.processUpdate(state.atlasSession, update, {
285
- agentType: state.atlasSession.agentType,
286
- task: state.atlasSession.task,
287
- });
288
- }
289
- }
290
-
291
149
  async terminate(sessionId: string): Promise<void> {
292
150
  const state = this.sessions.get(sessionId);
293
151
  if (!state) return;
@@ -298,19 +156,19 @@ export class ACPBackend implements AgentBackend {
298
156
  } catch (error) {
299
157
  // Log cancellation errors but don't throw
300
158
  console.error(
301
- `[ACPBackend] Session ${sessionId} cancel error:`,
302
- error instanceof Error ? error.message : String(error)
159
+ `[LocalACPBackend] Session ${sessionId} cancel error:`,
160
+ error instanceof Error ? error.message : String(error),
303
161
  );
304
162
  }
305
163
 
306
164
  try {
307
- // Close the agent handle
165
+ // Close the local agent handle
308
166
  await state.agentHandle.close();
309
167
  } catch (error) {
310
168
  // Log close errors but don't throw
311
169
  console.error(
312
- `[ACPBackend] Session ${sessionId} close error:`,
313
- error instanceof Error ? error.message : String(error)
170
+ `[LocalACPBackend] Session ${sessionId} close error:`,
171
+ error instanceof Error ? error.message : String(error),
314
172
  );
315
173
  }
316
174
 
@@ -322,32 +180,35 @@ export class ACPBackend implements AgentBackend {
322
180
  this.handles.delete(sessionId);
323
181
  }
324
182
 
325
- async listSessions(): Promise<AgentSession[]> {
326
- return Array.from(this.sessions.values()).map((s) => s.atlasSession);
327
- }
328
-
329
183
  /**
330
- * Get a raw ACP session for advanced usage
331
- */
332
- getACPSession(sessionId: string): Session | undefined {
333
- return this.sessions.get(sessionId)?.acpSession;
334
- }
335
-
336
- /**
337
- * Get a raw agent handle for advanced usage
184
+ * Get a raw agent handle for advanced usage (local-specific)
338
185
  */
339
186
  getAgentHandle(sessionId: string): AgentHandle | undefined {
340
187
  return this.sessions.get(sessionId)?.agentHandle;
341
188
  }
342
189
  }
343
190
 
191
+ // ============================================================
192
+ // Backward-compatible alias
193
+ // ============================================================
194
+
195
+ /**
196
+ * @deprecated Use LocalACPBackend directly. ACPBackend is a backward-compatible alias.
197
+ */
198
+ export const ACPBackend = LocalACPBackend;
199
+ export type ACPBackend = LocalACPBackend;
200
+
201
+ // ============================================================
202
+ // Factory helpers
203
+ // ============================================================
204
+
344
205
  /**
345
206
  * Create an ACP backend with agent configurations
346
207
  */
347
208
  export function createACPBackend(
348
- configs: Record<string, ACPAgentConfig>
349
- ): ACPBackend {
350
- return new ACPBackend(configs);
209
+ configs: Record<string, ACPAgentConfig>,
210
+ ): LocalACPBackend {
211
+ return new LocalACPBackend(configs);
351
212
  }
352
213
 
353
214
  /**
@@ -12,6 +12,7 @@ export {
12
12
  } from './mock.js';
13
13
 
14
14
  export {
15
+ LocalACPBackend,
15
16
  ACPBackend,
16
17
  createACPBackend,
17
18
  claudeCodeACPConfig,
@@ -20,5 +21,18 @@ export {
20
21
  type ACPAgentConfig,
21
22
  } from './acp.js';
22
23
 
24
+ export {
25
+ ACPProtocolHandler,
26
+ type ACPSessionBase,
27
+ } from './acp-protocol.js';
28
+
29
+ export {
30
+ MacroAgentBackendAdapter,
31
+ adaptMacroBackend,
32
+ createMacroAgentSource,
33
+ type MacroAgentBackendLike,
34
+ type MacroSessionLike,
35
+ } from './macro-agent.js';
36
+
23
37
  // Re-export useful types from acp-factory
24
38
  export { AgentFactory } from 'acp-factory';