@soleri/core 2.1.0 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (377) hide show
  1. package/dist/brain/brain.d.ts +10 -1
  2. package/dist/brain/brain.d.ts.map +1 -1
  3. package/dist/brain/brain.js +116 -13
  4. package/dist/brain/brain.js.map +1 -1
  5. package/dist/brain/intelligence.d.ts +36 -1
  6. package/dist/brain/intelligence.d.ts.map +1 -1
  7. package/dist/brain/intelligence.js +119 -14
  8. package/dist/brain/intelligence.js.map +1 -1
  9. package/dist/brain/types.d.ts +34 -2
  10. package/dist/brain/types.d.ts.map +1 -1
  11. package/dist/cognee/client.d.ts +3 -0
  12. package/dist/cognee/client.d.ts.map +1 -1
  13. package/dist/cognee/client.js +17 -0
  14. package/dist/cognee/client.js.map +1 -1
  15. package/dist/cognee/sync-manager.d.ts +94 -0
  16. package/dist/cognee/sync-manager.d.ts.map +1 -0
  17. package/dist/cognee/sync-manager.js +293 -0
  18. package/dist/cognee/sync-manager.js.map +1 -0
  19. package/dist/control/identity-manager.d.ts +22 -0
  20. package/dist/control/identity-manager.d.ts.map +1 -0
  21. package/dist/control/identity-manager.js +233 -0
  22. package/dist/control/identity-manager.js.map +1 -0
  23. package/dist/control/intent-router.d.ts +32 -0
  24. package/dist/control/intent-router.d.ts.map +1 -0
  25. package/dist/control/intent-router.js +242 -0
  26. package/dist/control/intent-router.js.map +1 -0
  27. package/dist/control/types.d.ts +68 -0
  28. package/dist/control/types.d.ts.map +1 -0
  29. package/dist/control/types.js +9 -0
  30. package/dist/control/types.js.map +1 -0
  31. package/dist/curator/curator.d.ts +37 -1
  32. package/dist/curator/curator.d.ts.map +1 -1
  33. package/dist/curator/curator.js +199 -1
  34. package/dist/curator/curator.js.map +1 -1
  35. package/dist/errors/classify.d.ts +13 -0
  36. package/dist/errors/classify.d.ts.map +1 -0
  37. package/dist/errors/classify.js +97 -0
  38. package/dist/errors/classify.js.map +1 -0
  39. package/dist/errors/index.d.ts +6 -0
  40. package/dist/errors/index.d.ts.map +1 -0
  41. package/dist/errors/index.js +4 -0
  42. package/dist/errors/index.js.map +1 -0
  43. package/dist/errors/retry.d.ts +40 -0
  44. package/dist/errors/retry.d.ts.map +1 -0
  45. package/dist/errors/retry.js +97 -0
  46. package/dist/errors/retry.js.map +1 -0
  47. package/dist/errors/types.d.ts +48 -0
  48. package/dist/errors/types.d.ts.map +1 -0
  49. package/dist/errors/types.js +59 -0
  50. package/dist/errors/types.js.map +1 -0
  51. package/dist/facades/types.d.ts +1 -1
  52. package/dist/governance/governance.d.ts +42 -0
  53. package/dist/governance/governance.d.ts.map +1 -0
  54. package/dist/governance/governance.js +488 -0
  55. package/dist/governance/governance.js.map +1 -0
  56. package/dist/governance/index.d.ts +3 -0
  57. package/dist/governance/index.d.ts.map +1 -0
  58. package/dist/governance/index.js +2 -0
  59. package/dist/governance/index.js.map +1 -0
  60. package/dist/governance/types.d.ts +102 -0
  61. package/dist/governance/types.d.ts.map +1 -0
  62. package/dist/governance/types.js +3 -0
  63. package/dist/governance/types.js.map +1 -0
  64. package/dist/index.d.ts +52 -3
  65. package/dist/index.d.ts.map +1 -1
  66. package/dist/index.js +47 -1
  67. package/dist/index.js.map +1 -1
  68. package/dist/intake/content-classifier.d.ts +14 -0
  69. package/dist/intake/content-classifier.d.ts.map +1 -0
  70. package/dist/intake/content-classifier.js +125 -0
  71. package/dist/intake/content-classifier.js.map +1 -0
  72. package/dist/intake/dedup-gate.d.ts +17 -0
  73. package/dist/intake/dedup-gate.d.ts.map +1 -0
  74. package/dist/intake/dedup-gate.js +66 -0
  75. package/dist/intake/dedup-gate.js.map +1 -0
  76. package/dist/intake/intake-pipeline.d.ts +63 -0
  77. package/dist/intake/intake-pipeline.d.ts.map +1 -0
  78. package/dist/intake/intake-pipeline.js +373 -0
  79. package/dist/intake/intake-pipeline.js.map +1 -0
  80. package/dist/intake/types.d.ts +65 -0
  81. package/dist/intake/types.d.ts.map +1 -0
  82. package/dist/intake/types.js +3 -0
  83. package/dist/intake/types.js.map +1 -0
  84. package/dist/intelligence/loader.js +1 -1
  85. package/dist/intelligence/loader.js.map +1 -1
  86. package/dist/intelligence/types.d.ts +3 -1
  87. package/dist/intelligence/types.d.ts.map +1 -1
  88. package/dist/logging/logger.d.ts +37 -0
  89. package/dist/logging/logger.d.ts.map +1 -0
  90. package/dist/logging/logger.js +145 -0
  91. package/dist/logging/logger.js.map +1 -0
  92. package/dist/logging/types.d.ts +19 -0
  93. package/dist/logging/types.d.ts.map +1 -0
  94. package/dist/logging/types.js +2 -0
  95. package/dist/logging/types.js.map +1 -0
  96. package/dist/loop/loop-manager.d.ts +100 -0
  97. package/dist/loop/loop-manager.d.ts.map +1 -0
  98. package/dist/loop/loop-manager.js +379 -0
  99. package/dist/loop/loop-manager.js.map +1 -0
  100. package/dist/loop/types.d.ts +103 -0
  101. package/dist/loop/types.d.ts.map +1 -0
  102. package/dist/loop/types.js +11 -0
  103. package/dist/loop/types.js.map +1 -0
  104. package/dist/persistence/index.d.ts +3 -0
  105. package/dist/persistence/index.d.ts.map +1 -0
  106. package/dist/persistence/index.js +2 -0
  107. package/dist/persistence/index.js.map +1 -0
  108. package/dist/persistence/sqlite-provider.d.ts +25 -0
  109. package/dist/persistence/sqlite-provider.d.ts.map +1 -0
  110. package/dist/persistence/sqlite-provider.js +59 -0
  111. package/dist/persistence/sqlite-provider.js.map +1 -0
  112. package/dist/persistence/types.d.ts +36 -0
  113. package/dist/persistence/types.d.ts.map +1 -0
  114. package/dist/persistence/types.js +8 -0
  115. package/dist/persistence/types.js.map +1 -0
  116. package/dist/planning/gap-analysis.d.ts +72 -0
  117. package/dist/planning/gap-analysis.d.ts.map +1 -0
  118. package/dist/planning/gap-analysis.js +442 -0
  119. package/dist/planning/gap-analysis.js.map +1 -0
  120. package/dist/planning/gap-types.d.ts +29 -0
  121. package/dist/planning/gap-types.d.ts.map +1 -0
  122. package/dist/planning/gap-types.js +28 -0
  123. package/dist/planning/gap-types.js.map +1 -0
  124. package/dist/planning/planner.d.ts +421 -4
  125. package/dist/planning/planner.d.ts.map +1 -1
  126. package/dist/planning/planner.js +949 -21
  127. package/dist/planning/planner.js.map +1 -1
  128. package/dist/playbooks/generic/brainstorming.d.ts +9 -0
  129. package/dist/playbooks/generic/brainstorming.d.ts.map +1 -0
  130. package/dist/playbooks/generic/brainstorming.js +105 -0
  131. package/dist/playbooks/generic/brainstorming.js.map +1 -0
  132. package/dist/playbooks/generic/code-review.d.ts +11 -0
  133. package/dist/playbooks/generic/code-review.d.ts.map +1 -0
  134. package/dist/playbooks/generic/code-review.js +176 -0
  135. package/dist/playbooks/generic/code-review.js.map +1 -0
  136. package/dist/playbooks/generic/subagent-execution.d.ts +9 -0
  137. package/dist/playbooks/generic/subagent-execution.d.ts.map +1 -0
  138. package/dist/playbooks/generic/subagent-execution.js +68 -0
  139. package/dist/playbooks/generic/subagent-execution.js.map +1 -0
  140. package/dist/playbooks/generic/systematic-debugging.d.ts +9 -0
  141. package/dist/playbooks/generic/systematic-debugging.d.ts.map +1 -0
  142. package/dist/playbooks/generic/systematic-debugging.js +87 -0
  143. package/dist/playbooks/generic/systematic-debugging.js.map +1 -0
  144. package/dist/playbooks/generic/tdd.d.ts +9 -0
  145. package/dist/playbooks/generic/tdd.d.ts.map +1 -0
  146. package/dist/playbooks/generic/tdd.js +70 -0
  147. package/dist/playbooks/generic/tdd.js.map +1 -0
  148. package/dist/playbooks/generic/verification.d.ts +9 -0
  149. package/dist/playbooks/generic/verification.d.ts.map +1 -0
  150. package/dist/playbooks/generic/verification.js +74 -0
  151. package/dist/playbooks/generic/verification.js.map +1 -0
  152. package/dist/playbooks/index.d.ts +4 -0
  153. package/dist/playbooks/index.d.ts.map +1 -0
  154. package/dist/playbooks/index.js +5 -0
  155. package/dist/playbooks/index.js.map +1 -0
  156. package/dist/playbooks/playbook-registry.d.ts +42 -0
  157. package/dist/playbooks/playbook-registry.d.ts.map +1 -0
  158. package/dist/playbooks/playbook-registry.js +227 -0
  159. package/dist/playbooks/playbook-registry.js.map +1 -0
  160. package/dist/playbooks/playbook-seeder.d.ts +47 -0
  161. package/dist/playbooks/playbook-seeder.d.ts.map +1 -0
  162. package/dist/playbooks/playbook-seeder.js +104 -0
  163. package/dist/playbooks/playbook-seeder.js.map +1 -0
  164. package/dist/playbooks/playbook-types.d.ts +132 -0
  165. package/dist/playbooks/playbook-types.d.ts.map +1 -0
  166. package/dist/playbooks/playbook-types.js +12 -0
  167. package/dist/playbooks/playbook-types.js.map +1 -0
  168. package/dist/project/project-registry.d.ts +79 -0
  169. package/dist/project/project-registry.d.ts.map +1 -0
  170. package/dist/project/project-registry.js +274 -0
  171. package/dist/project/project-registry.js.map +1 -0
  172. package/dist/project/types.d.ts +28 -0
  173. package/dist/project/types.d.ts.map +1 -0
  174. package/dist/project/types.js +5 -0
  175. package/dist/project/types.js.map +1 -0
  176. package/dist/prompts/index.d.ts +4 -0
  177. package/dist/prompts/index.d.ts.map +1 -0
  178. package/dist/prompts/index.js +3 -0
  179. package/dist/prompts/index.js.map +1 -0
  180. package/dist/prompts/parser.d.ts +17 -0
  181. package/dist/prompts/parser.d.ts.map +1 -0
  182. package/dist/prompts/parser.js +47 -0
  183. package/dist/prompts/parser.js.map +1 -0
  184. package/dist/prompts/template-manager.d.ts +25 -0
  185. package/dist/prompts/template-manager.d.ts.map +1 -0
  186. package/dist/prompts/template-manager.js +71 -0
  187. package/dist/prompts/template-manager.js.map +1 -0
  188. package/dist/prompts/types.d.ts +26 -0
  189. package/dist/prompts/types.d.ts.map +1 -0
  190. package/dist/prompts/types.js +5 -0
  191. package/dist/prompts/types.js.map +1 -0
  192. package/dist/runtime/admin-extra-ops.d.ts +15 -0
  193. package/dist/runtime/admin-extra-ops.d.ts.map +1 -0
  194. package/dist/runtime/admin-extra-ops.js +595 -0
  195. package/dist/runtime/admin-extra-ops.js.map +1 -0
  196. package/dist/runtime/admin-ops.d.ts +15 -0
  197. package/dist/runtime/admin-ops.d.ts.map +1 -0
  198. package/dist/runtime/admin-ops.js +329 -0
  199. package/dist/runtime/admin-ops.js.map +1 -0
  200. package/dist/runtime/capture-ops.d.ts +15 -0
  201. package/dist/runtime/capture-ops.d.ts.map +1 -0
  202. package/dist/runtime/capture-ops.js +363 -0
  203. package/dist/runtime/capture-ops.js.map +1 -0
  204. package/dist/runtime/cognee-sync-ops.d.ts +12 -0
  205. package/dist/runtime/cognee-sync-ops.d.ts.map +1 -0
  206. package/dist/runtime/cognee-sync-ops.js +55 -0
  207. package/dist/runtime/cognee-sync-ops.js.map +1 -0
  208. package/dist/runtime/core-ops.d.ts +9 -3
  209. package/dist/runtime/core-ops.d.ts.map +1 -1
  210. package/dist/runtime/core-ops.js +693 -10
  211. package/dist/runtime/core-ops.js.map +1 -1
  212. package/dist/runtime/curator-extra-ops.d.ts +9 -0
  213. package/dist/runtime/curator-extra-ops.d.ts.map +1 -0
  214. package/dist/runtime/curator-extra-ops.js +71 -0
  215. package/dist/runtime/curator-extra-ops.js.map +1 -0
  216. package/dist/runtime/domain-ops.d.ts.map +1 -1
  217. package/dist/runtime/domain-ops.js +61 -15
  218. package/dist/runtime/domain-ops.js.map +1 -1
  219. package/dist/runtime/grading-ops.d.ts +14 -0
  220. package/dist/runtime/grading-ops.d.ts.map +1 -0
  221. package/dist/runtime/grading-ops.js +105 -0
  222. package/dist/runtime/grading-ops.js.map +1 -0
  223. package/dist/runtime/intake-ops.d.ts +14 -0
  224. package/dist/runtime/intake-ops.d.ts.map +1 -0
  225. package/dist/runtime/intake-ops.js +110 -0
  226. package/dist/runtime/intake-ops.js.map +1 -0
  227. package/dist/runtime/loop-ops.d.ts +14 -0
  228. package/dist/runtime/loop-ops.d.ts.map +1 -0
  229. package/dist/runtime/loop-ops.js +251 -0
  230. package/dist/runtime/loop-ops.js.map +1 -0
  231. package/dist/runtime/memory-cross-project-ops.d.ts +12 -0
  232. package/dist/runtime/memory-cross-project-ops.d.ts.map +1 -0
  233. package/dist/runtime/memory-cross-project-ops.js +165 -0
  234. package/dist/runtime/memory-cross-project-ops.js.map +1 -0
  235. package/dist/runtime/memory-extra-ops.d.ts +13 -0
  236. package/dist/runtime/memory-extra-ops.d.ts.map +1 -0
  237. package/dist/runtime/memory-extra-ops.js +173 -0
  238. package/dist/runtime/memory-extra-ops.js.map +1 -0
  239. package/dist/runtime/orchestrate-ops.d.ts +17 -0
  240. package/dist/runtime/orchestrate-ops.d.ts.map +1 -0
  241. package/dist/runtime/orchestrate-ops.js +246 -0
  242. package/dist/runtime/orchestrate-ops.js.map +1 -0
  243. package/dist/runtime/planning-extra-ops.d.ts +25 -0
  244. package/dist/runtime/planning-extra-ops.d.ts.map +1 -0
  245. package/dist/runtime/planning-extra-ops.js +663 -0
  246. package/dist/runtime/planning-extra-ops.js.map +1 -0
  247. package/dist/runtime/playbook-ops.d.ts +14 -0
  248. package/dist/runtime/playbook-ops.d.ts.map +1 -0
  249. package/dist/runtime/playbook-ops.js +141 -0
  250. package/dist/runtime/playbook-ops.js.map +1 -0
  251. package/dist/runtime/project-ops.d.ts +15 -0
  252. package/dist/runtime/project-ops.d.ts.map +1 -0
  253. package/dist/runtime/project-ops.js +186 -0
  254. package/dist/runtime/project-ops.js.map +1 -0
  255. package/dist/runtime/runtime.d.ts.map +1 -1
  256. package/dist/runtime/runtime.js +65 -3
  257. package/dist/runtime/runtime.js.map +1 -1
  258. package/dist/runtime/types.d.ts +29 -0
  259. package/dist/runtime/types.d.ts.map +1 -1
  260. package/dist/runtime/vault-extra-ops.d.ts +10 -0
  261. package/dist/runtime/vault-extra-ops.d.ts.map +1 -0
  262. package/dist/runtime/vault-extra-ops.js +536 -0
  263. package/dist/runtime/vault-extra-ops.js.map +1 -0
  264. package/dist/telemetry/telemetry.d.ts +48 -0
  265. package/dist/telemetry/telemetry.d.ts.map +1 -0
  266. package/dist/telemetry/telemetry.js +87 -0
  267. package/dist/telemetry/telemetry.js.map +1 -0
  268. package/dist/vault/playbook.d.ts +34 -0
  269. package/dist/vault/playbook.d.ts.map +1 -0
  270. package/dist/vault/playbook.js +60 -0
  271. package/dist/vault/playbook.js.map +1 -0
  272. package/dist/vault/vault.d.ts +97 -4
  273. package/dist/vault/vault.d.ts.map +1 -1
  274. package/dist/vault/vault.js +424 -65
  275. package/dist/vault/vault.js.map +1 -1
  276. package/package.json +7 -3
  277. package/src/__tests__/admin-extra-ops.test.ts +467 -0
  278. package/src/__tests__/admin-ops.test.ts +271 -0
  279. package/src/__tests__/brain-intelligence.test.ts +205 -0
  280. package/src/__tests__/brain.test.ts +134 -3
  281. package/src/__tests__/capture-ops.test.ts +509 -0
  282. package/src/__tests__/cognee-integration.test.ts +80 -0
  283. package/src/__tests__/cognee-sync-manager.test.ts +103 -0
  284. package/src/__tests__/core-ops.test.ts +292 -2
  285. package/src/__tests__/curator-extra-ops.test.ts +381 -0
  286. package/src/__tests__/domain-ops.test.ts +66 -0
  287. package/src/__tests__/errors.test.ts +388 -0
  288. package/src/__tests__/governance.test.ts +522 -0
  289. package/src/__tests__/grading-ops.test.ts +361 -0
  290. package/src/__tests__/identity-manager.test.ts +243 -0
  291. package/src/__tests__/intake-pipeline.test.ts +162 -0
  292. package/src/__tests__/intent-router.test.ts +222 -0
  293. package/src/__tests__/logger.test.ts +200 -0
  294. package/src/__tests__/loop-ops.test.ts +469 -0
  295. package/src/__tests__/memory-cross-project-ops.test.ts +248 -0
  296. package/src/__tests__/memory-extra-ops.test.ts +352 -0
  297. package/src/__tests__/orchestrate-ops.test.ts +289 -0
  298. package/src/__tests__/persistence.test.ts +225 -0
  299. package/src/__tests__/planner.test.ts +416 -7
  300. package/src/__tests__/planning-extra-ops.test.ts +706 -0
  301. package/src/__tests__/playbook-registry.test.ts +326 -0
  302. package/src/__tests__/playbook-seeder.test.ts +163 -0
  303. package/src/__tests__/playbook.test.ts +389 -0
  304. package/src/__tests__/project-ops.test.ts +381 -0
  305. package/src/__tests__/template-manager.test.ts +222 -0
  306. package/src/__tests__/vault-extra-ops.test.ts +482 -0
  307. package/src/brain/brain.ts +185 -16
  308. package/src/brain/intelligence.ts +179 -10
  309. package/src/brain/types.ts +40 -2
  310. package/src/cognee/client.ts +18 -0
  311. package/src/cognee/sync-manager.ts +389 -0
  312. package/src/control/identity-manager.ts +354 -0
  313. package/src/control/intent-router.ts +326 -0
  314. package/src/control/types.ts +102 -0
  315. package/src/curator/curator.ts +295 -1
  316. package/src/errors/classify.ts +102 -0
  317. package/src/errors/index.ts +5 -0
  318. package/src/errors/retry.ts +132 -0
  319. package/src/errors/types.ts +81 -0
  320. package/src/governance/governance.ts +698 -0
  321. package/src/governance/index.ts +18 -0
  322. package/src/governance/types.ts +111 -0
  323. package/src/index.ts +213 -2
  324. package/src/intake/content-classifier.ts +146 -0
  325. package/src/intake/dedup-gate.ts +92 -0
  326. package/src/intake/intake-pipeline.ts +503 -0
  327. package/src/intake/types.ts +69 -0
  328. package/src/intelligence/loader.ts +1 -1
  329. package/src/intelligence/types.ts +3 -1
  330. package/src/logging/logger.ts +154 -0
  331. package/src/logging/types.ts +21 -0
  332. package/src/loop/loop-manager.ts +448 -0
  333. package/src/loop/types.ts +115 -0
  334. package/src/persistence/index.ts +7 -0
  335. package/src/persistence/sqlite-provider.ts +62 -0
  336. package/src/persistence/types.ts +44 -0
  337. package/src/planning/gap-analysis.ts +775 -0
  338. package/src/planning/gap-types.ts +61 -0
  339. package/src/planning/planner.ts +1273 -24
  340. package/src/playbooks/generic/brainstorming.ts +110 -0
  341. package/src/playbooks/generic/code-review.ts +181 -0
  342. package/src/playbooks/generic/subagent-execution.ts +74 -0
  343. package/src/playbooks/generic/systematic-debugging.ts +92 -0
  344. package/src/playbooks/generic/tdd.ts +75 -0
  345. package/src/playbooks/generic/verification.ts +79 -0
  346. package/src/playbooks/index.ts +27 -0
  347. package/src/playbooks/playbook-registry.ts +284 -0
  348. package/src/playbooks/playbook-seeder.ts +119 -0
  349. package/src/playbooks/playbook-types.ts +162 -0
  350. package/src/project/project-registry.ts +370 -0
  351. package/src/project/types.ts +31 -0
  352. package/src/prompts/index.ts +3 -0
  353. package/src/prompts/parser.ts +59 -0
  354. package/src/prompts/template-manager.ts +77 -0
  355. package/src/prompts/types.ts +28 -0
  356. package/src/runtime/admin-extra-ops.ts +652 -0
  357. package/src/runtime/admin-ops.ts +340 -0
  358. package/src/runtime/capture-ops.ts +404 -0
  359. package/src/runtime/cognee-sync-ops.ts +63 -0
  360. package/src/runtime/core-ops.ts +787 -9
  361. package/src/runtime/curator-extra-ops.ts +85 -0
  362. package/src/runtime/domain-ops.ts +67 -15
  363. package/src/runtime/grading-ops.ts +130 -0
  364. package/src/runtime/intake-ops.ts +126 -0
  365. package/src/runtime/loop-ops.ts +277 -0
  366. package/src/runtime/memory-cross-project-ops.ts +191 -0
  367. package/src/runtime/memory-extra-ops.ts +186 -0
  368. package/src/runtime/orchestrate-ops.ts +278 -0
  369. package/src/runtime/planning-extra-ops.ts +718 -0
  370. package/src/runtime/playbook-ops.ts +169 -0
  371. package/src/runtime/project-ops.ts +202 -0
  372. package/src/runtime/runtime.ts +77 -3
  373. package/src/runtime/types.ts +29 -0
  374. package/src/runtime/vault-extra-ops.ts +606 -0
  375. package/src/telemetry/telemetry.ts +118 -0
  376. package/src/vault/playbook.ts +87 -0
  377. package/src/vault/vault.ts +575 -98
@@ -0,0 +1,277 @@
1
+ /**
2
+ * Loop operations — 9 ops for iterative validation loops.
3
+ *
4
+ * Ops: loop_start, loop_iterate, loop_iterate_gate, loop_status,
5
+ * loop_cancel, loop_history, loop_is_active, loop_complete,
6
+ * loop_anomaly_check.
7
+ */
8
+
9
+ import { z } from 'zod';
10
+ import type { OpDefinition } from '../facades/types.js';
11
+ import type { AgentRuntime } from './types.js';
12
+ import type { LoopMode, LoopKnowledge } from '../loop/types.js';
13
+
14
+ const loopModeSchema = z.enum([
15
+ 'token-migration',
16
+ 'contrast-fix',
17
+ 'component-build',
18
+ 'plan-iteration',
19
+ 'custom',
20
+ ]);
21
+
22
+ /**
23
+ * Default max iterations per mode.
24
+ */
25
+ const DEFAULT_MAX_ITERATIONS: Record<LoopMode, number> = {
26
+ 'token-migration': 20,
27
+ 'contrast-fix': 15,
28
+ 'component-build': 20,
29
+ 'plan-iteration': 10,
30
+ custom: 20,
31
+ };
32
+
33
+ /**
34
+ * Default target scores per mode.
35
+ */
36
+ const DEFAULT_TARGET_SCORES: Partial<Record<LoopMode, number>> = {
37
+ 'token-migration': 95,
38
+ 'component-build': 90,
39
+ 'plan-iteration': 90,
40
+ };
41
+
42
+ /**
43
+ * Create the 9 loop operations for an agent runtime.
44
+ */
45
+ export function createLoopOps(runtime: AgentRuntime): OpDefinition[] {
46
+ const { loop } = runtime;
47
+
48
+ return [
49
+ {
50
+ name: 'loop_start',
51
+ description:
52
+ 'Start an iterative validation loop. Modes: token-migration, contrast-fix, component-build, plan-iteration, custom.',
53
+ auth: 'write',
54
+ schema: z.object({
55
+ mode: loopModeSchema,
56
+ prompt: z.string().describe('Task description for the loop.'),
57
+ maxIterations: z
58
+ .number()
59
+ .optional()
60
+ .describe('Max iterations. Defaults vary by mode (10-20).'),
61
+ targetScore: z
62
+ .number()
63
+ .optional()
64
+ .describe('Target validation score (0-100). Defaults vary by mode.'),
65
+ targetGrade: z
66
+ .string()
67
+ .optional()
68
+ .describe('Target grade for plan-iteration mode (e.g., "A", "A+").'),
69
+ completionPromise: z
70
+ .string()
71
+ .optional()
72
+ .describe('Completion promise text — loop completes when this appears in output.'),
73
+ validationInstructions: z
74
+ .string()
75
+ .optional()
76
+ .describe('Validation instructions appended to the prompt each iteration.'),
77
+ intent: z
78
+ .string()
79
+ .optional()
80
+ .describe('Detected intent for brain session recording (e.g., "BUILD", "FIX").'),
81
+ }),
82
+ handler: async (params) => {
83
+ const mode = params.mode as LoopMode;
84
+ const prompt = params.prompt as string;
85
+ const maxIterations =
86
+ (params.maxIterations as number | undefined) ?? DEFAULT_MAX_ITERATIONS[mode];
87
+ const targetScore =
88
+ (params.targetScore as number | undefined) ?? DEFAULT_TARGET_SCORES[mode];
89
+
90
+ const state = loop.startLoop({
91
+ mode,
92
+ prompt,
93
+ maxIterations,
94
+ targetScore,
95
+ targetGrade: params.targetGrade as string | undefined,
96
+ completionPromise: params.completionPromise as string | undefined,
97
+ validationInstructions: params.validationInstructions as string | undefined,
98
+ intent: params.intent as string | undefined,
99
+ });
100
+
101
+ return {
102
+ started: true,
103
+ loopId: state.id,
104
+ mode,
105
+ maxIterations,
106
+ targetScore: targetScore ?? null,
107
+ };
108
+ },
109
+ },
110
+ {
111
+ name: 'loop_iterate',
112
+ description:
113
+ 'Record a validation iteration result. If max iterations reached on a failing result, the loop auto-closes.',
114
+ auth: 'write',
115
+ schema: z.object({
116
+ passed: z.boolean().describe('Whether this iteration passed validation.'),
117
+ validationScore: z.number().optional().describe('Numeric validation score (0-100).'),
118
+ validationResult: z.string().optional().describe('Free-text validation result summary.'),
119
+ }),
120
+ handler: async (params) => {
121
+ const iteration = loop.iterate({
122
+ passed: params.passed as boolean,
123
+ validationScore: params.validationScore as number | undefined,
124
+ validationResult: params.validationResult as string | undefined,
125
+ });
126
+
127
+ const status = loop.getStatus();
128
+ return {
129
+ iteration: iteration.iteration,
130
+ passed: iteration.passed,
131
+ validationScore: iteration.validationScore ?? null,
132
+ loopActive: loop.isActive(),
133
+ loopStatus: status?.status ?? 'max-iterations',
134
+ };
135
+ },
136
+ },
137
+ {
138
+ name: 'loop_iterate_gate',
139
+ description:
140
+ 'Gate-based loop iteration — accepts LLM output, scans for completion signals ' +
141
+ '(promise tags, heuristic detection), and returns allow/block decision. ' +
142
+ 'Primary method for Stop hook integration.',
143
+ auth: 'write',
144
+ schema: z.object({
145
+ lastOutput: z.string().describe('The LLM response to scan for completion signals.'),
146
+ knowledge: z
147
+ .object({
148
+ items: z.array(z.string()).optional(),
149
+ patternsApplied: z.array(z.string()).optional(),
150
+ antiPatternsAvoided: z.array(z.string()).optional(),
151
+ })
152
+ .optional()
153
+ .describe('Knowledge items discovered during this iteration.'),
154
+ durationMs: z
155
+ .number()
156
+ .optional()
157
+ .describe('Duration of this iteration in milliseconds (for anomaly detection).'),
158
+ }),
159
+ handler: async (params) => {
160
+ const decision = loop.iterateWithGate(
161
+ params.lastOutput as string,
162
+ params.knowledge as LoopKnowledge | undefined,
163
+ params.durationMs as number | undefined,
164
+ );
165
+ return decision;
166
+ },
167
+ },
168
+ {
169
+ name: 'loop_status',
170
+ description: 'Get current loop status, config, and iteration history.',
171
+ auth: 'read',
172
+ handler: async () => {
173
+ const status = loop.getStatus();
174
+ if (!status) {
175
+ return { active: false, loop: null };
176
+ }
177
+ return {
178
+ active: true,
179
+ loop: status,
180
+ };
181
+ },
182
+ },
183
+ {
184
+ name: 'loop_cancel',
185
+ description: 'Cancel the active loop.',
186
+ auth: 'write',
187
+ handler: async () => {
188
+ const cancelled = loop.cancelLoop();
189
+ return {
190
+ cancelled: true,
191
+ loopId: cancelled.id,
192
+ iterations: cancelled.iterations.length,
193
+ status: cancelled.status,
194
+ };
195
+ },
196
+ },
197
+ {
198
+ name: 'loop_history',
199
+ description: 'Get history of all completed, cancelled, and max-iterations loops.',
200
+ auth: 'read',
201
+ handler: async () => {
202
+ const history = loop.getHistory();
203
+ return {
204
+ count: history.length,
205
+ loops: history.map((l) => ({
206
+ id: l.id,
207
+ mode: l.config.mode,
208
+ prompt: l.config.prompt,
209
+ status: l.status,
210
+ iterations: l.iterations.length,
211
+ startedAt: l.startedAt,
212
+ completedAt: l.completedAt,
213
+ })),
214
+ };
215
+ },
216
+ },
217
+ {
218
+ name: 'loop_is_active',
219
+ description: 'Check if a validation loop is currently running.',
220
+ auth: 'read',
221
+ handler: async () => {
222
+ return { active: loop.isActive() };
223
+ },
224
+ },
225
+ {
226
+ name: 'loop_complete',
227
+ description: 'Mark the active loop as completed (validation passed).',
228
+ auth: 'write',
229
+ handler: async () => {
230
+ const completed = loop.completeLoop();
231
+ return {
232
+ completed: true,
233
+ loopId: completed.id,
234
+ iterations: completed.iterations.length,
235
+ status: completed.status,
236
+ };
237
+ },
238
+ },
239
+ {
240
+ name: 'loop_anomaly_check',
241
+ description:
242
+ 'Check active loop iterations for anomalous patterns — fast iterations with low scores, repeated failures, no-progress loops.',
243
+ auth: 'read',
244
+ handler: async () => {
245
+ const status = loop.getStatus();
246
+ if (!status) {
247
+ return { active: false, anomalies: [], summary: 'No active loop' };
248
+ }
249
+
250
+ const { detectAnomaly } = await import('../loop/loop-manager.js');
251
+ const anomalies: string[] = [];
252
+
253
+ for (const iter of status.iterations) {
254
+ const warning = detectAnomaly(iter, status.config.mode);
255
+ if (warning) anomalies.push(warning);
256
+ }
257
+
258
+ // Check for repeated failures (3+ consecutive non-passing iterations)
259
+ const recent = status.iterations.slice(-3);
260
+ if (recent.length >= 3 && recent.every((i) => !i.passed)) {
261
+ anomalies.push(
262
+ `Warning: ${recent.length} consecutive failing iterations — consider cancelling or adjusting approach`,
263
+ );
264
+ }
265
+
266
+ return {
267
+ active: true,
268
+ loopId: status.id,
269
+ mode: status.config.mode,
270
+ totalIterations: status.iterations.length,
271
+ anomalies,
272
+ hasAnomalies: anomalies.length > 0,
273
+ };
274
+ },
275
+ },
276
+ ];
277
+ }
@@ -0,0 +1,191 @@
1
+ /**
2
+ * Cross-project memory operations — 3 ops for sharing knowledge across linked projects.
3
+ *
4
+ * Ops: memory_promote_to_global, memory_configure, memory_cross_project_search.
5
+ */
6
+
7
+ import { z } from 'zod';
8
+ import type { OpDefinition } from '../facades/types.js';
9
+ import type { AgentRuntime } from './types.js';
10
+
11
+ /**
12
+ * Create the 3 cross-project memory operations for an agent runtime.
13
+ */
14
+ export function createMemoryCrossProjectOps(runtime: AgentRuntime): OpDefinition[] {
15
+ const { vault, projectRegistry } = runtime;
16
+
17
+ return [
18
+ {
19
+ name: 'memory_promote_to_global',
20
+ description:
21
+ 'Promote a vault entry to the global pool by adding a _global tag. Promoted entries surface in cross-project searches across all linked projects.',
22
+ auth: 'write',
23
+ schema: z.object({
24
+ entryId: z.string().describe('The vault entry ID to promote.'),
25
+ }),
26
+ handler: async (params) => {
27
+ const entryId = params.entryId as string;
28
+ const entry = vault.get(entryId);
29
+ if (!entry) return { promoted: false, error: `Entry not found: ${entryId}` };
30
+
31
+ const tags = entry.tags ?? [];
32
+ if (tags.includes('_global')) {
33
+ return { promoted: false, entryId, message: 'Entry is already promoted to global.' };
34
+ }
35
+
36
+ vault.update(entryId, { tags: [...tags, '_global'] });
37
+ return { promoted: true, entryId, tags: [...tags, '_global'] };
38
+ },
39
+ },
40
+
41
+ {
42
+ name: 'memory_configure',
43
+ description:
44
+ 'Configure cross-project memory settings for a project. Stores config in the project registry metadata.',
45
+ auth: 'admin',
46
+ schema: z.object({
47
+ projectPath: z.string().describe('Project path to configure.'),
48
+ crossProjectEnabled: z
49
+ .boolean()
50
+ .optional()
51
+ .describe('Enable/disable cross-project memory search.'),
52
+ extraPaths: z
53
+ .array(z.string())
54
+ .optional()
55
+ .describe('Additional project paths to include in cross-project searches.'),
56
+ }),
57
+ handler: async (params) => {
58
+ const projectPath = params.projectPath as string;
59
+ const project = projectRegistry.getByPath(projectPath);
60
+ if (!project) {
61
+ return { configured: false, error: `Project not registered: ${projectPath}` };
62
+ }
63
+
64
+ const currentMeta = project.metadata ?? {};
65
+ const memoryConfig = (currentMeta.memoryConfig as Record<string, unknown>) ?? {};
66
+
67
+ if (params.crossProjectEnabled !== undefined) {
68
+ memoryConfig.crossProjectEnabled = params.crossProjectEnabled;
69
+ }
70
+ if (params.extraPaths !== undefined) {
71
+ memoryConfig.extraPaths = params.extraPaths;
72
+ }
73
+
74
+ projectRegistry.register(projectPath, project.name, {
75
+ ...currentMeta,
76
+ memoryConfig,
77
+ });
78
+
79
+ return { configured: true, projectPath, memoryConfig };
80
+ },
81
+ },
82
+
83
+ {
84
+ name: 'memory_cross_project_search',
85
+ description:
86
+ 'Search memories across the current project and all linked projects. Results weighted: current=1.0, global=0.9, linked=0.8. Requires cross-project search to be enabled.',
87
+ auth: 'read',
88
+ schema: z.object({
89
+ query: z.string().describe('Search query.'),
90
+ projectPath: z.string().describe('Current project path.'),
91
+ type: z
92
+ .enum(['session', 'lesson', 'preference'])
93
+ .optional()
94
+ .describe('Filter by memory type.'),
95
+ limit: z.number().optional().describe('Max results per project (default 10).'),
96
+ }),
97
+ handler: async (params) => {
98
+ const query = params.query as string;
99
+ const projectPath = params.projectPath as string;
100
+ const type = params.type as string | undefined;
101
+ const limit = (params.limit as number) ?? 10;
102
+
103
+ // Search current project (weight 1.0)
104
+ const currentResults = vault.searchMemories(query, { projectPath, type, limit });
105
+ const weightedResults = currentResults.map((m) => ({
106
+ memory: m,
107
+ weight: 1.0,
108
+ source: 'current' as const,
109
+ }));
110
+
111
+ // Search for globally promoted entries (search broadly, then filter for _global tag)
112
+ const allResults = vault.search(query, { limit: limit * 3 });
113
+ const globalEntries = allResults
114
+ .filter((r) => r.entry.tags?.includes('_global'))
115
+ .slice(0, limit)
116
+ .map((r) => ({
117
+ entry: r.entry,
118
+ score: r.score,
119
+ weight: 0.9,
120
+ source: 'global' as const,
121
+ }));
122
+
123
+ // Get linked projects and search their memories
124
+ const project = projectRegistry.getByPath(projectPath);
125
+ const linkedMemories: Array<{
126
+ memory: (typeof currentResults)[0];
127
+ weight: number;
128
+ source: 'linked';
129
+ linkedProject: string;
130
+ }> = [];
131
+
132
+ if (project) {
133
+ const config = (project.metadata?.memoryConfig as Record<string, unknown>) ?? {};
134
+ const enabled = config.crossProjectEnabled !== false; // default enabled
135
+
136
+ if (enabled) {
137
+ const linked = projectRegistry.getLinkedProjects(project.id);
138
+ for (const { project: linkedProj } of linked) {
139
+ const results = vault.searchMemories(query, {
140
+ projectPath: linkedProj.path,
141
+ type,
142
+ limit: Math.ceil(limit / 2), // fewer results from linked projects
143
+ });
144
+ for (const m of results) {
145
+ linkedMemories.push({
146
+ memory: m,
147
+ weight: 0.8,
148
+ source: 'linked',
149
+ linkedProject: linkedProj.path,
150
+ });
151
+ }
152
+ }
153
+
154
+ // Also search extra paths
155
+ const extraPaths = (config.extraPaths as string[]) ?? [];
156
+ for (const extraPath of extraPaths) {
157
+ const results = vault.searchMemories(query, {
158
+ projectPath: extraPath,
159
+ type,
160
+ limit: Math.ceil(limit / 2),
161
+ });
162
+ for (const m of results) {
163
+ linkedMemories.push({
164
+ memory: m,
165
+ weight: 0.7,
166
+ source: 'linked',
167
+ linkedProject: extraPath,
168
+ });
169
+ }
170
+ }
171
+ }
172
+ }
173
+
174
+ // Deduplicate by memory ID
175
+ const seen = new Set(weightedResults.map((r) => r.memory.id));
176
+ const dedupedLinked = linkedMemories.filter((r) => {
177
+ if (seen.has(r.memory.id)) return false;
178
+ seen.add(r.memory.id);
179
+ return true;
180
+ });
181
+
182
+ return {
183
+ memories: weightedResults,
184
+ globalEntries,
185
+ linkedMemories: dedupedLinked,
186
+ totalResults: weightedResults.length + globalEntries.length + dedupedLinked.length,
187
+ };
188
+ },
189
+ },
190
+ ];
191
+ }
@@ -0,0 +1,186 @@
1
+ /**
2
+ * Extended memory operations — 8 ops for advanced memory management.
3
+ *
4
+ * These complement the 4 base memory ops in core-ops.ts:
5
+ * memory_search, memory_capture, memory_list, session_capture
6
+ *
7
+ * New ops: memory_delete, memory_stats, memory_export, memory_import,
8
+ * memory_prune, memory_deduplicate, memory_topics, memory_by_project
9
+ */
10
+
11
+ import { z } from 'zod';
12
+ import type { OpDefinition } from '../facades/types.js';
13
+ import type { AgentRuntime } from './types.js';
14
+
15
+ export function createMemoryExtraOps(runtime: AgentRuntime): OpDefinition[] {
16
+ const { vault } = runtime;
17
+
18
+ return [
19
+ {
20
+ name: 'memory_delete',
21
+ description: 'Delete a memory by ID. Returns whether the deletion was successful.',
22
+ auth: 'write',
23
+ schema: z.object({
24
+ memoryId: z.string().describe('The memory ID to delete'),
25
+ }),
26
+ handler: async (params) => {
27
+ const memoryId = params.memoryId as string;
28
+ const existing = vault.getMemory(memoryId);
29
+ if (!existing) {
30
+ return { deleted: false, error: `Memory "${memoryId}" not found.` };
31
+ }
32
+ const deleted = vault.deleteMemory(memoryId);
33
+ return { deleted, memoryId };
34
+ },
35
+ },
36
+ {
37
+ name: 'memory_stats',
38
+ description:
39
+ 'Detailed memory statistics — counts by type, project, date range, plus oldest/newest timestamps and archived count.',
40
+ auth: 'read',
41
+ schema: z.object({
42
+ projectPath: z.string().optional().describe('Filter stats to a specific project'),
43
+ fromDate: z
44
+ .number()
45
+ .optional()
46
+ .describe('Unix timestamp — only include memories created after this date'),
47
+ toDate: z
48
+ .number()
49
+ .optional()
50
+ .describe('Unix timestamp — only include memories created before this date'),
51
+ }),
52
+ handler: async (params) => {
53
+ return vault.memoryStatsDetailed({
54
+ projectPath: params.projectPath as string | undefined,
55
+ fromDate: params.fromDate as number | undefined,
56
+ toDate: params.toDate as number | undefined,
57
+ });
58
+ },
59
+ },
60
+ {
61
+ name: 'memory_export',
62
+ description:
63
+ 'Export memories as a JSON array. Optionally filter by project or type. Useful for backup and migration.',
64
+ auth: 'read',
65
+ schema: z.object({
66
+ projectPath: z.string().optional().describe('Filter to a specific project'),
67
+ type: z
68
+ .enum(['session', 'lesson', 'preference'])
69
+ .optional()
70
+ .describe('Filter by memory type'),
71
+ includeArchived: z
72
+ .boolean()
73
+ .optional()
74
+ .default(false)
75
+ .describe('Whether to include archived memories'),
76
+ }),
77
+ handler: async (params) => {
78
+ const memories = vault.exportMemories({
79
+ projectPath: params.projectPath as string | undefined,
80
+ type: params.type as string | undefined,
81
+ includeArchived: (params.includeArchived as boolean | undefined) ?? false,
82
+ });
83
+ return { exported: true, count: memories.length, memories };
84
+ },
85
+ },
86
+ {
87
+ name: 'memory_import',
88
+ description:
89
+ 'Import memories from a JSON array. Duplicates (same ID) are skipped. Returns imported and skipped counts.',
90
+ auth: 'write',
91
+ schema: z.object({
92
+ memories: z
93
+ .array(
94
+ z.object({
95
+ id: z.string(),
96
+ projectPath: z.string(),
97
+ type: z.enum(['session', 'lesson', 'preference']),
98
+ context: z.string(),
99
+ summary: z.string(),
100
+ topics: z.array(z.string()).optional().default([]),
101
+ filesModified: z.array(z.string()).optional().default([]),
102
+ toolsUsed: z.array(z.string()).optional().default([]),
103
+ createdAt: z.number(),
104
+ archivedAt: z.number().nullable().optional().default(null),
105
+ }),
106
+ )
107
+ .describe('Array of memory objects to import'),
108
+ }),
109
+ handler: async (params) => {
110
+ const memories = (params.memories as Array<Record<string, unknown>>).map((m) => ({
111
+ id: m.id as string,
112
+ projectPath: m.projectPath as string,
113
+ type: m.type as 'session' | 'lesson' | 'preference',
114
+ context: m.context as string,
115
+ summary: m.summary as string,
116
+ topics: (m.topics as string[]) ?? [],
117
+ filesModified: (m.filesModified as string[]) ?? [],
118
+ toolsUsed: (m.toolsUsed as string[]) ?? [],
119
+ createdAt: m.createdAt as number,
120
+ archivedAt: (m.archivedAt as number | null) ?? null,
121
+ }));
122
+ const result = vault.importMemories(memories);
123
+ return { ...result, total: memories.length };
124
+ },
125
+ },
126
+ {
127
+ name: 'memory_prune',
128
+ description:
129
+ 'Delete non-archived memories older than N days. Destructive — cannot be undone.',
130
+ auth: 'admin',
131
+ schema: z.object({
132
+ olderThanDays: z.number().min(1).describe('Delete memories older than this many days'),
133
+ }),
134
+ handler: async (params) => {
135
+ const days = params.olderThanDays as number;
136
+ const result = vault.pruneMemories(days);
137
+ return { ...result, olderThanDays: days };
138
+ },
139
+ },
140
+ {
141
+ name: 'memory_deduplicate',
142
+ description:
143
+ 'Find and remove duplicate memories (same summary + project + type). Keeps the earliest entry in each duplicate group.',
144
+ auth: 'admin',
145
+ schema: z.object({}),
146
+ handler: async () => {
147
+ return vault.deduplicateMemories();
148
+ },
149
+ },
150
+ {
151
+ name: 'memory_topics',
152
+ description:
153
+ 'List all unique topics across memories, with occurrence counts. Sorted by frequency descending.',
154
+ auth: 'read',
155
+ schema: z.object({}),
156
+ handler: async () => {
157
+ const topics = vault.memoryTopics();
158
+ return { count: topics.length, topics };
159
+ },
160
+ },
161
+ {
162
+ name: 'memory_by_project',
163
+ description:
164
+ 'List memories grouped by project path. Each group includes the project path, count, and the memories themselves.',
165
+ auth: 'read',
166
+ schema: z.object({
167
+ includeMemories: z
168
+ .boolean()
169
+ .optional()
170
+ .default(true)
171
+ .describe('Whether to include full memory objects or just counts'),
172
+ }),
173
+ handler: async (params) => {
174
+ const includeMemories = (params.includeMemories as boolean | undefined) ?? true;
175
+ const groups = vault.memoriesByProject();
176
+ if (!includeMemories) {
177
+ return {
178
+ count: groups.length,
179
+ projects: groups.map((g) => ({ project: g.project, count: g.count })),
180
+ };
181
+ }
182
+ return { count: groups.length, projects: groups };
183
+ },
184
+ },
185
+ ];
186
+ }