@cleocode/core 2026.4.31 → 2026.4.36

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 (1024) hide show
  1. package/dist/adapters/adapter-registry.js +64 -0
  2. package/dist/adapters/adapter-registry.js.map +1 -0
  3. package/dist/adapters/discovery.js +83 -0
  4. package/dist/adapters/discovery.js.map +1 -0
  5. package/dist/adapters/index.js +9 -0
  6. package/dist/adapters/index.js.map +1 -0
  7. package/dist/adapters/manager.js +260 -0
  8. package/dist/adapters/manager.js.map +1 -0
  9. package/dist/admin/export-tasks.js +171 -0
  10. package/dist/admin/export-tasks.js.map +1 -0
  11. package/dist/admin/export.js +103 -0
  12. package/dist/admin/export.js.map +1 -0
  13. package/dist/admin/help.js +106 -0
  14. package/dist/admin/help.js.map +1 -0
  15. package/dist/admin/import-tasks.js +182 -0
  16. package/dist/admin/import-tasks.js.map +1 -0
  17. package/dist/admin/import.js +129 -0
  18. package/dist/admin/import.js.map +1 -0
  19. package/dist/admin/index.js +13 -0
  20. package/dist/admin/index.js.map +1 -0
  21. package/dist/adrs/find.js +134 -0
  22. package/dist/adrs/find.js.map +1 -0
  23. package/dist/adrs/index.js +15 -0
  24. package/dist/adrs/index.js.map +1 -0
  25. package/dist/adrs/link-pipeline.js +160 -0
  26. package/dist/adrs/link-pipeline.js.map +1 -0
  27. package/dist/adrs/list.js +43 -0
  28. package/dist/adrs/list.js.map +1 -0
  29. package/dist/adrs/parse.js +51 -0
  30. package/dist/adrs/parse.js.map +1 -0
  31. package/dist/adrs/show.js +22 -0
  32. package/dist/adrs/show.js.map +1 -0
  33. package/dist/adrs/sync.js +232 -0
  34. package/dist/adrs/sync.js.map +1 -0
  35. package/dist/adrs/types.js +9 -0
  36. package/dist/adrs/types.js.map +1 -0
  37. package/dist/adrs/validate.js +57 -0
  38. package/dist/adrs/validate.js.map +1 -0
  39. package/dist/agents/agent-registry.js +288 -0
  40. package/dist/agents/agent-registry.js.map +1 -0
  41. package/dist/agents/agent-schema.js +82 -0
  42. package/dist/agents/agent-schema.js.map +1 -0
  43. package/dist/agents/capacity.js +116 -0
  44. package/dist/agents/capacity.js.map +1 -0
  45. package/dist/agents/execution-learning.js +474 -0
  46. package/dist/agents/execution-learning.js.map +1 -0
  47. package/dist/agents/health-monitor.js +217 -0
  48. package/dist/agents/health-monitor.js.map +1 -0
  49. package/dist/agents/index.js +29 -0
  50. package/dist/agents/index.js.map +1 -0
  51. package/dist/agents/registry.js +314 -0
  52. package/dist/agents/registry.js.map +1 -0
  53. package/dist/agents/retry.js +215 -0
  54. package/dist/agents/retry.js.map +1 -0
  55. package/dist/audit-prune.js +94 -0
  56. package/dist/audit-prune.js.map +1 -0
  57. package/dist/audit.js +68 -0
  58. package/dist/audit.js.map +1 -0
  59. package/dist/backfill/index.js +229 -0
  60. package/dist/backfill/index.js.map +1 -0
  61. package/dist/bootstrap.js +435 -0
  62. package/dist/bootstrap.js.map +1 -0
  63. package/dist/caamp/adapter.js +259 -0
  64. package/dist/caamp/adapter.js.map +1 -0
  65. package/dist/caamp/capability-check.js +38 -0
  66. package/dist/caamp/capability-check.js.map +1 -0
  67. package/dist/caamp/index.js +21 -0
  68. package/dist/caamp/index.js.map +1 -0
  69. package/dist/caamp-init.js +16 -0
  70. package/dist/caamp-init.js.map +1 -0
  71. package/dist/cleo.js +322 -0
  72. package/dist/cleo.js.map +1 -0
  73. package/dist/code/index.js +14 -0
  74. package/dist/code/index.js.map +1 -0
  75. package/dist/code/outline.js +165 -0
  76. package/dist/code/outline.js.map +1 -0
  77. package/dist/code/parser.js +420 -0
  78. package/dist/code/parser.js.map +1 -0
  79. package/dist/code/search.js +135 -0
  80. package/dist/code/search.js.map +1 -0
  81. package/dist/code/unfold.js +155 -0
  82. package/dist/code/unfold.js.map +1 -0
  83. package/dist/codebase-map/analyzers/architecture.js +129 -0
  84. package/dist/codebase-map/analyzers/architecture.js.map +1 -0
  85. package/dist/codebase-map/analyzers/concerns.js +122 -0
  86. package/dist/codebase-map/analyzers/concerns.js.map +1 -0
  87. package/dist/codebase-map/analyzers/conventions.js +149 -0
  88. package/dist/codebase-map/analyzers/conventions.js.map +1 -0
  89. package/dist/codebase-map/analyzers/integrations.js +108 -0
  90. package/dist/codebase-map/analyzers/integrations.js.map +1 -0
  91. package/dist/codebase-map/analyzers/stack.js +117 -0
  92. package/dist/codebase-map/analyzers/stack.js.map +1 -0
  93. package/dist/codebase-map/analyzers/structure.js +137 -0
  94. package/dist/codebase-map/analyzers/structure.js.map +1 -0
  95. package/dist/codebase-map/analyzers/testing.js +118 -0
  96. package/dist/codebase-map/analyzers/testing.js.map +1 -0
  97. package/dist/codebase-map/index.js +57 -0
  98. package/dist/codebase-map/index.js.map +1 -0
  99. package/dist/codebase-map/store.js +122 -0
  100. package/dist/codebase-map/store.js.map +1 -0
  101. package/dist/codebase-map/summary.js +152 -0
  102. package/dist/codebase-map/summary.js.map +1 -0
  103. package/dist/compliance/index.js +288 -0
  104. package/dist/compliance/index.js.map +1 -0
  105. package/dist/compliance/protocol-enforcement.js +332 -0
  106. package/dist/compliance/protocol-enforcement.js.map +1 -0
  107. package/dist/compliance/protocol-rules.js +786 -0
  108. package/dist/compliance/protocol-rules.js.map +1 -0
  109. package/dist/compliance/protocol-types.js +79 -0
  110. package/dist/compliance/protocol-types.js.map +1 -0
  111. package/dist/compliance/store.js +53 -0
  112. package/dist/compliance/store.js.map +1 -0
  113. package/dist/conduit/conduit-client.js +107 -0
  114. package/dist/conduit/conduit-client.js.map +1 -0
  115. package/dist/conduit/factory.js +52 -0
  116. package/dist/conduit/factory.js.map +1 -0
  117. package/dist/conduit/http-transport.js +155 -0
  118. package/dist/conduit/http-transport.js.map +1 -0
  119. package/dist/conduit/index.js +15 -0
  120. package/dist/conduit/index.js.map +1 -0
  121. package/dist/conduit/local-transport.js +255 -0
  122. package/dist/conduit/local-transport.js.map +1 -0
  123. package/dist/conduit/sse-transport.js +299 -0
  124. package/dist/conduit/sse-transport.js.map +1 -0
  125. package/dist/config/build-config.js +29 -0
  126. package/dist/config/build-config.js.map +1 -0
  127. package/dist/config.d.ts.map +1 -1
  128. package/dist/config.js +407 -0
  129. package/dist/config.js.map +1 -0
  130. package/dist/constants.js +18 -0
  131. package/dist/constants.js.map +1 -0
  132. package/dist/context/index.js +137 -0
  133. package/dist/context/index.js.map +1 -0
  134. package/dist/crypto/credentials.js +219 -0
  135. package/dist/crypto/credentials.js.map +1 -0
  136. package/dist/discovery.js +182 -0
  137. package/dist/discovery.js.map +1 -0
  138. package/dist/engine-result.js +12 -0
  139. package/dist/engine-result.js.map +1 -0
  140. package/dist/error-catalog.js +404 -0
  141. package/dist/error-catalog.js.map +1 -0
  142. package/dist/error-registry.js +393 -0
  143. package/dist/error-registry.js.map +1 -0
  144. package/dist/errors.js +173 -0
  145. package/dist/errors.js.map +1 -0
  146. package/dist/hooks/handlers/agent-hooks.js +106 -0
  147. package/dist/hooks/handlers/agent-hooks.js.map +1 -0
  148. package/dist/hooks/handlers/conduit-hooks.d.ts +72 -0
  149. package/dist/hooks/handlers/conduit-hooks.d.ts.map +1 -0
  150. package/dist/hooks/handlers/conduit-hooks.js +229 -0
  151. package/dist/hooks/handlers/conduit-hooks.js.map +1 -0
  152. package/dist/hooks/handlers/context-hooks.js +111 -0
  153. package/dist/hooks/handlers/context-hooks.js.map +1 -0
  154. package/dist/hooks/handlers/error-hooks.js +52 -0
  155. package/dist/hooks/handlers/error-hooks.js.map +1 -0
  156. package/dist/hooks/handlers/file-hooks.js +104 -0
  157. package/dist/hooks/handlers/file-hooks.js.map +1 -0
  158. package/dist/hooks/handlers/handler-helpers.js +61 -0
  159. package/dist/hooks/handlers/handler-helpers.js.map +1 -0
  160. package/dist/hooks/handlers/index.d.ts +6 -0
  161. package/dist/hooks/handlers/index.d.ts.map +1 -1
  162. package/dist/hooks/handlers/index.js +37 -0
  163. package/dist/hooks/handlers/index.js.map +1 -0
  164. package/dist/hooks/handlers/intelligence-hooks.d.ts +26 -0
  165. package/dist/hooks/handlers/intelligence-hooks.d.ts.map +1 -0
  166. package/dist/hooks/handlers/intelligence-hooks.js +69 -0
  167. package/dist/hooks/handlers/intelligence-hooks.js.map +1 -0
  168. package/dist/hooks/handlers/memory-bridge-refresh.js +42 -0
  169. package/dist/hooks/handlers/memory-bridge-refresh.js.map +1 -0
  170. package/dist/hooks/handlers/notification-hooks.js +62 -0
  171. package/dist/hooks/handlers/notification-hooks.js.map +1 -0
  172. package/dist/hooks/handlers/session-hooks.d.ts +30 -0
  173. package/dist/hooks/handlers/session-hooks.d.ts.map +1 -1
  174. package/dist/hooks/handlers/session-hooks.js +190 -0
  175. package/dist/hooks/handlers/session-hooks.js.map +1 -0
  176. package/dist/hooks/handlers/task-hooks.d.ts +2 -0
  177. package/dist/hooks/handlers/task-hooks.d.ts.map +1 -1
  178. package/dist/hooks/handlers/task-hooks.js +79 -0
  179. package/dist/hooks/handlers/task-hooks.js.map +1 -0
  180. package/dist/hooks/handlers/watchdog-hooks.d.ts +49 -0
  181. package/dist/hooks/handlers/watchdog-hooks.d.ts.map +1 -0
  182. package/dist/hooks/handlers/watchdog-hooks.js +162 -0
  183. package/dist/hooks/handlers/watchdog-hooks.js.map +1 -0
  184. package/dist/hooks/handlers/work-capture-hooks.js +165 -0
  185. package/dist/hooks/handlers/work-capture-hooks.js.map +1 -0
  186. package/dist/hooks/index.js +13 -0
  187. package/dist/hooks/index.js.map +1 -0
  188. package/dist/hooks/payload-schemas.js +220 -0
  189. package/dist/hooks/payload-schemas.js.map +1 -0
  190. package/dist/hooks/provider-hooks.js +66 -0
  191. package/dist/hooks/provider-hooks.js.map +1 -0
  192. package/dist/hooks/registry.js +229 -0
  193. package/dist/hooks/registry.js.map +1 -0
  194. package/dist/hooks/types.js +66 -0
  195. package/dist/hooks/types.js.map +1 -0
  196. package/dist/hooks.js +136 -0
  197. package/dist/hooks.js.map +1 -0
  198. package/dist/index.js +56736 -47002
  199. package/dist/index.js.map +4 -4
  200. package/dist/init.js +920 -0
  201. package/dist/init.js.map +1 -0
  202. package/dist/inject/index.js +82 -0
  203. package/dist/inject/index.js.map +1 -0
  204. package/dist/injection.d.ts +13 -1
  205. package/dist/injection.d.ts.map +1 -1
  206. package/dist/injection.js +377 -0
  207. package/dist/injection.js.map +1 -0
  208. package/dist/intelligence/adaptive-validation.js +497 -0
  209. package/dist/intelligence/adaptive-validation.js.map +1 -0
  210. package/dist/intelligence/impact.js +675 -0
  211. package/dist/intelligence/impact.js.map +1 -0
  212. package/dist/intelligence/index.js +22 -0
  213. package/dist/intelligence/index.js.map +1 -0
  214. package/dist/intelligence/patterns.js +492 -0
  215. package/dist/intelligence/patterns.js.map +1 -0
  216. package/dist/intelligence/prediction.js +499 -0
  217. package/dist/intelligence/prediction.js.map +1 -0
  218. package/dist/intelligence/types.js +13 -0
  219. package/dist/intelligence/types.js.map +1 -0
  220. package/dist/internal.d.ts +10 -3
  221. package/dist/internal.d.ts.map +1 -1
  222. package/dist/internal.js +321 -0
  223. package/dist/internal.js.map +1 -0
  224. package/dist/issue/create.js +121 -0
  225. package/dist/issue/create.js.map +1 -0
  226. package/dist/issue/diagnostics.js +59 -0
  227. package/dist/issue/diagnostics.js.map +1 -0
  228. package/dist/issue/index.js +10 -0
  229. package/dist/issue/index.js.map +1 -0
  230. package/dist/issue/template-parser.js +267 -0
  231. package/dist/issue/template-parser.js.map +1 -0
  232. package/dist/json-schema-validator.js +76 -0
  233. package/dist/json-schema-validator.js.map +1 -0
  234. package/dist/lib/index.js +11 -0
  235. package/dist/lib/index.js.map +1 -0
  236. package/dist/lib/retry.js +152 -0
  237. package/dist/lib/retry.js.map +1 -0
  238. package/dist/lib/tree-sitter-languages.js +75 -0
  239. package/dist/lib/tree-sitter-languages.js.map +1 -0
  240. package/dist/lifecycle/chain-composition.js +152 -0
  241. package/dist/lifecycle/chain-composition.js.map +1 -0
  242. package/dist/lifecycle/chain-store.js +246 -0
  243. package/dist/lifecycle/chain-store.js.map +1 -0
  244. package/dist/lifecycle/consolidate-rcasd.js +352 -0
  245. package/dist/lifecycle/consolidate-rcasd.js.map +1 -0
  246. package/dist/lifecycle/default-chain.js +176 -0
  247. package/dist/lifecycle/default-chain.js.map +1 -0
  248. package/dist/lifecycle/evidence.js +180 -0
  249. package/dist/lifecycle/evidence.js.map +1 -0
  250. package/dist/lifecycle/frontmatter.js +363 -0
  251. package/dist/lifecycle/frontmatter.js.map +1 -0
  252. package/dist/lifecycle/index.js +756 -0
  253. package/dist/lifecycle/index.js.map +1 -0
  254. package/dist/lifecycle/pipeline.js +656 -0
  255. package/dist/lifecycle/pipeline.js.map +1 -0
  256. package/dist/lifecycle/rcasd-index.js +326 -0
  257. package/dist/lifecycle/rcasd-index.js.map +1 -0
  258. package/dist/lifecycle/rcasd-paths.js +220 -0
  259. package/dist/lifecycle/rcasd-paths.js.map +1 -0
  260. package/dist/lifecycle/resume.js +864 -0
  261. package/dist/lifecycle/resume.js.map +1 -0
  262. package/dist/lifecycle/stage-artifacts.js +94 -0
  263. package/dist/lifecycle/stage-artifacts.js.map +1 -0
  264. package/dist/lifecycle/stage-guidance.js +234 -0
  265. package/dist/lifecycle/stage-guidance.js.map +1 -0
  266. package/dist/lifecycle/stages.js +534 -0
  267. package/dist/lifecycle/stages.js.map +1 -0
  268. package/dist/lifecycle/state-machine.js +516 -0
  269. package/dist/lifecycle/state-machine.js.map +1 -0
  270. package/dist/lifecycle/tessera-engine.js +249 -0
  271. package/dist/lifecycle/tessera-engine.js.map +1 -0
  272. package/dist/logger.js +140 -0
  273. package/dist/logger.js.map +1 -0
  274. package/dist/memory/anthropic-key-resolver.d.ts +35 -0
  275. package/dist/memory/anthropic-key-resolver.d.ts.map +1 -0
  276. package/dist/memory/anthropic-key-resolver.js +105 -0
  277. package/dist/memory/anthropic-key-resolver.js.map +1 -0
  278. package/dist/memory/auto-extract.d.ts +38 -42
  279. package/dist/memory/auto-extract.d.ts.map +1 -1
  280. package/dist/memory/auto-extract.js +77 -0
  281. package/dist/memory/auto-extract.js.map +1 -0
  282. package/dist/memory/brain-backfill.js +389 -0
  283. package/dist/memory/brain-backfill.js.map +1 -0
  284. package/dist/memory/brain-consolidator.d.ts +48 -0
  285. package/dist/memory/brain-consolidator.d.ts.map +1 -0
  286. package/dist/memory/brain-consolidator.js +294 -0
  287. package/dist/memory/brain-consolidator.js.map +1 -0
  288. package/dist/memory/brain-embedding.js +66 -0
  289. package/dist/memory/brain-embedding.js.map +1 -0
  290. package/dist/memory/brain-lifecycle.d.ts +83 -2
  291. package/dist/memory/brain-lifecycle.d.ts.map +1 -1
  292. package/dist/memory/brain-lifecycle.js +807 -0
  293. package/dist/memory/brain-lifecycle.js.map +1 -0
  294. package/dist/memory/brain-links.js +161 -0
  295. package/dist/memory/brain-links.js.map +1 -0
  296. package/dist/memory/brain-maintenance.js +114 -0
  297. package/dist/memory/brain-maintenance.js.map +1 -0
  298. package/dist/memory/brain-migration.js +149 -0
  299. package/dist/memory/brain-migration.js.map +1 -0
  300. package/dist/memory/brain-purge.js +243 -0
  301. package/dist/memory/brain-purge.js.map +1 -0
  302. package/dist/memory/brain-reasoning.js +215 -0
  303. package/dist/memory/brain-reasoning.js.map +1 -0
  304. package/dist/memory/brain-retrieval.d.ts +75 -1
  305. package/dist/memory/brain-retrieval.d.ts.map +1 -1
  306. package/dist/memory/brain-retrieval.js +1044 -0
  307. package/dist/memory/brain-retrieval.js.map +1 -0
  308. package/dist/memory/brain-row-types.js +10 -0
  309. package/dist/memory/brain-row-types.js.map +1 -0
  310. package/dist/memory/brain-search.d.ts +82 -15
  311. package/dist/memory/brain-search.d.ts.map +1 -1
  312. package/dist/memory/brain-search.js +613 -0
  313. package/dist/memory/brain-search.js.map +1 -0
  314. package/dist/memory/brain-similarity.js +145 -0
  315. package/dist/memory/brain-similarity.js.map +1 -0
  316. package/dist/memory/claude-mem-migration.js +277 -0
  317. package/dist/memory/claude-mem-migration.js.map +1 -0
  318. package/dist/memory/decisions.d.ts.map +1 -1
  319. package/dist/memory/decisions.js +218 -0
  320. package/dist/memory/decisions.js.map +1 -0
  321. package/dist/memory/embedding-local.js +102 -0
  322. package/dist/memory/embedding-local.js.map +1 -0
  323. package/dist/memory/embedding-queue.js +271 -0
  324. package/dist/memory/embedding-queue.js.map +1 -0
  325. package/dist/memory/embedding-worker.js +58 -0
  326. package/dist/memory/embedding-worker.js.map +1 -0
  327. package/dist/memory/engine-compat.d.ts +16 -1
  328. package/dist/memory/engine-compat.d.ts.map +1 -1
  329. package/dist/memory/engine-compat.js +1561 -0
  330. package/dist/memory/engine-compat.js.map +1 -0
  331. package/dist/memory/extraction-gate.d.ts +139 -0
  332. package/dist/memory/extraction-gate.d.ts.map +1 -0
  333. package/dist/memory/extraction-gate.js +459 -0
  334. package/dist/memory/extraction-gate.js.map +1 -0
  335. package/dist/memory/graph-auto-populate.js +148 -0
  336. package/dist/memory/graph-auto-populate.js.map +1 -0
  337. package/dist/memory/graph-queries.js +290 -0
  338. package/dist/memory/graph-queries.js.map +1 -0
  339. package/dist/memory/index.d.ts +2 -0
  340. package/dist/memory/index.d.ts.map +1 -1
  341. package/dist/memory/index.js +1144 -0
  342. package/dist/memory/index.js.map +1 -0
  343. package/dist/memory/learnings.d.ts +14 -0
  344. package/dist/memory/learnings.d.ts.map +1 -1
  345. package/dist/memory/learnings.js +179 -0
  346. package/dist/memory/learnings.js.map +1 -0
  347. package/dist/memory/llm-extraction.d.ts +107 -0
  348. package/dist/memory/llm-extraction.d.ts.map +1 -0
  349. package/dist/memory/llm-extraction.js +425 -0
  350. package/dist/memory/llm-extraction.js.map +1 -0
  351. package/dist/memory/memory-bridge.js +382 -0
  352. package/dist/memory/memory-bridge.js.map +1 -0
  353. package/dist/memory/mental-model-injection.js +61 -0
  354. package/dist/memory/mental-model-injection.js.map +1 -0
  355. package/dist/memory/mental-model-queue.js +211 -0
  356. package/dist/memory/mental-model-queue.js.map +1 -0
  357. package/dist/memory/observer-reflector.d.ts +157 -0
  358. package/dist/memory/observer-reflector.d.ts.map +1 -0
  359. package/dist/memory/observer-reflector.js +626 -0
  360. package/dist/memory/observer-reflector.js.map +1 -0
  361. package/dist/memory/patterns.d.ts +24 -4
  362. package/dist/memory/patterns.d.ts.map +1 -1
  363. package/dist/memory/patterns.js +174 -0
  364. package/dist/memory/patterns.js.map +1 -0
  365. package/dist/memory/pipeline-manifest-sqlite.js +975 -0
  366. package/dist/memory/pipeline-manifest-sqlite.js.map +1 -0
  367. package/dist/memory/quality-scoring.d.ts +42 -5
  368. package/dist/memory/quality-scoring.d.ts.map +1 -1
  369. package/dist/memory/quality-scoring.js +182 -0
  370. package/dist/memory/quality-scoring.js.map +1 -0
  371. package/dist/memory/session-memory.js +331 -0
  372. package/dist/memory/session-memory.js.map +1 -0
  373. package/dist/metrics/ab-test.js +260 -0
  374. package/dist/metrics/ab-test.js.map +1 -0
  375. package/dist/metrics/aggregation.js +363 -0
  376. package/dist/metrics/aggregation.js.map +1 -0
  377. package/dist/metrics/common.js +64 -0
  378. package/dist/metrics/common.js.map +1 -0
  379. package/dist/metrics/enums.js +78 -0
  380. package/dist/metrics/enums.js.map +1 -0
  381. package/dist/metrics/index.js +19 -0
  382. package/dist/metrics/index.js.map +1 -0
  383. package/dist/metrics/model-provider-registry.js +88 -0
  384. package/dist/metrics/model-provider-registry.js.map +1 -0
  385. package/dist/metrics/otel-integration.js +263 -0
  386. package/dist/metrics/otel-integration.js.map +1 -0
  387. package/dist/metrics/provider-detection.js +103 -0
  388. package/dist/metrics/provider-detection.js.map +1 -0
  389. package/dist/metrics/token-estimation.js +253 -0
  390. package/dist/metrics/token-estimation.js.map +1 -0
  391. package/dist/metrics/token-service.js +450 -0
  392. package/dist/metrics/token-service.js.map +1 -0
  393. package/dist/migration/agent-outputs.js +316 -0
  394. package/dist/migration/agent-outputs.js.map +1 -0
  395. package/dist/migration/checksum.js +92 -0
  396. package/dist/migration/checksum.js.map +1 -0
  397. package/dist/migration/index.js +282 -0
  398. package/dist/migration/index.js.map +1 -0
  399. package/dist/migration/logger.js +360 -0
  400. package/dist/migration/logger.js.map +1 -0
  401. package/dist/migration/preflight.js +9 -0
  402. package/dist/migration/preflight.js.map +1 -0
  403. package/dist/migration/state.js +421 -0
  404. package/dist/migration/state.js.map +1 -0
  405. package/dist/migration/validate.js +241 -0
  406. package/dist/migration/validate.js.map +1 -0
  407. package/dist/mvi-helpers.js +73 -0
  408. package/dist/mvi-helpers.js.map +1 -0
  409. package/dist/nexus/deps.js +375 -0
  410. package/dist/nexus/deps.js.map +1 -0
  411. package/dist/nexus/discover.js +288 -0
  412. package/dist/nexus/discover.js.map +1 -0
  413. package/dist/nexus/hash.js +10 -0
  414. package/dist/nexus/hash.js.map +1 -0
  415. package/dist/nexus/index.js +40 -0
  416. package/dist/nexus/index.js.map +1 -0
  417. package/dist/nexus/migrate-json-to-sqlite.js +115 -0
  418. package/dist/nexus/migrate-json-to-sqlite.js.map +1 -0
  419. package/dist/nexus/nexus-bridge.d.ts +51 -0
  420. package/dist/nexus/nexus-bridge.d.ts.map +1 -0
  421. package/dist/nexus/nexus-bridge.js +321 -0
  422. package/dist/nexus/nexus-bridge.js.map +1 -0
  423. package/dist/nexus/permissions.js +105 -0
  424. package/dist/nexus/permissions.js.map +1 -0
  425. package/dist/nexus/query.js +175 -0
  426. package/dist/nexus/query.js.map +1 -0
  427. package/dist/nexus/registry.js +584 -0
  428. package/dist/nexus/registry.js.map +1 -0
  429. package/dist/nexus/sharing/index.js +288 -0
  430. package/dist/nexus/sharing/index.js.map +1 -0
  431. package/dist/nexus/transfer-types.js +8 -0
  432. package/dist/nexus/transfer-types.js.map +1 -0
  433. package/dist/nexus/transfer.js +271 -0
  434. package/dist/nexus/transfer.js.map +1 -0
  435. package/dist/nexus/workspace.js +355 -0
  436. package/dist/nexus/workspace.js.map +1 -0
  437. package/dist/observability/index.js +103 -0
  438. package/dist/observability/index.js.map +1 -0
  439. package/dist/observability/log-filter.js +63 -0
  440. package/dist/observability/log-filter.js.map +1 -0
  441. package/dist/observability/log-parser.js +99 -0
  442. package/dist/observability/log-parser.js.map +1 -0
  443. package/dist/observability/log-reader.js +139 -0
  444. package/dist/observability/log-reader.js.map +1 -0
  445. package/dist/observability/types.js +19 -0
  446. package/dist/observability/types.js.map +1 -0
  447. package/dist/orchestration/analyze.js +107 -0
  448. package/dist/orchestration/analyze.js.map +1 -0
  449. package/dist/orchestration/bootstrap.js +132 -0
  450. package/dist/orchestration/bootstrap.js.map +1 -0
  451. package/dist/orchestration/context.js +56 -0
  452. package/dist/orchestration/context.js.map +1 -0
  453. package/dist/orchestration/critical-path.js +100 -0
  454. package/dist/orchestration/critical-path.js.map +1 -0
  455. package/dist/orchestration/hierarchy.js +183 -0
  456. package/dist/orchestration/hierarchy.js.map +1 -0
  457. package/dist/orchestration/index.js +287 -0
  458. package/dist/orchestration/index.js.map +1 -0
  459. package/dist/orchestration/parallel.js +89 -0
  460. package/dist/orchestration/parallel.js.map +1 -0
  461. package/dist/orchestration/protocol-validators.js +815 -0
  462. package/dist/orchestration/protocol-validators.js.map +1 -0
  463. package/dist/orchestration/skill-ops.js +98 -0
  464. package/dist/orchestration/skill-ops.js.map +1 -0
  465. package/dist/orchestration/status.js +107 -0
  466. package/dist/orchestration/status.js.map +1 -0
  467. package/dist/orchestration/unblock.js +103 -0
  468. package/dist/orchestration/unblock.js.map +1 -0
  469. package/dist/orchestration/validate-spawn.js +67 -0
  470. package/dist/orchestration/validate-spawn.js.map +1 -0
  471. package/dist/orchestration/waves.js +86 -0
  472. package/dist/orchestration/waves.js.map +1 -0
  473. package/dist/otel/index.js +163 -0
  474. package/dist/otel/index.js.map +1 -0
  475. package/dist/output.js +164 -0
  476. package/dist/output.js.map +1 -0
  477. package/dist/pagination.js +64 -0
  478. package/dist/pagination.js.map +1 -0
  479. package/dist/paths.js +882 -0
  480. package/dist/paths.js.map +1 -0
  481. package/dist/phases/deps.js +372 -0
  482. package/dist/phases/deps.js.map +1 -0
  483. package/dist/phases/index.js +349 -0
  484. package/dist/phases/index.js.map +1 -0
  485. package/dist/pipeline/index.js +10 -0
  486. package/dist/pipeline/index.js.map +1 -0
  487. package/dist/pipeline/phase.js +45 -0
  488. package/dist/pipeline/phase.js.map +1 -0
  489. package/dist/platform.js +211 -0
  490. package/dist/platform.js.map +1 -0
  491. package/dist/project-info.js +84 -0
  492. package/dist/project-info.js.map +1 -0
  493. package/dist/reconciliation/index.js +10 -0
  494. package/dist/reconciliation/index.js.map +1 -0
  495. package/dist/reconciliation/link-store.js +175 -0
  496. package/dist/reconciliation/link-store.js.map +1 -0
  497. package/dist/reconciliation/reconciliation-engine.js +298 -0
  498. package/dist/reconciliation/reconciliation-engine.js.map +1 -0
  499. package/dist/release/artifacts.js +427 -0
  500. package/dist/release/artifacts.js.map +1 -0
  501. package/dist/release/changelog-writer.js +151 -0
  502. package/dist/release/changelog-writer.js.map +1 -0
  503. package/dist/release/channel.js +144 -0
  504. package/dist/release/channel.js.map +1 -0
  505. package/dist/release/ci.js +166 -0
  506. package/dist/release/ci.js.map +1 -0
  507. package/dist/release/github-pr.js +225 -0
  508. package/dist/release/github-pr.js.map +1 -0
  509. package/dist/release/guards.js +116 -0
  510. package/dist/release/guards.js.map +1 -0
  511. package/dist/release/index.js +22 -0
  512. package/dist/release/index.js.map +1 -0
  513. package/dist/release/release-config.js +158 -0
  514. package/dist/release/release-config.js.map +1 -0
  515. package/dist/release/release-manifest.js +1019 -0
  516. package/dist/release/release-manifest.js.map +1 -0
  517. package/dist/release/version-bump.js +255 -0
  518. package/dist/release/version-bump.js.map +1 -0
  519. package/dist/remote/index.js +257 -0
  520. package/dist/remote/index.js.map +1 -0
  521. package/dist/repair.js +130 -0
  522. package/dist/repair.js.map +1 -0
  523. package/dist/research/index.js +2 -0
  524. package/dist/research/index.js.map +1 -0
  525. package/dist/roadmap/index.js +59 -0
  526. package/dist/roadmap/index.js.map +1 -0
  527. package/dist/routing/capability-matrix.js +1556 -0
  528. package/dist/routing/capability-matrix.js.map +1 -0
  529. package/dist/routing/index.js +9 -0
  530. package/dist/routing/index.js.map +1 -0
  531. package/dist/scaffold.d.ts +18 -0
  532. package/dist/scaffold.d.ts.map +1 -1
  533. package/dist/scaffold.js +1798 -0
  534. package/dist/scaffold.js.map +1 -0
  535. package/dist/schema-management.js +295 -0
  536. package/dist/schema-management.js.map +1 -0
  537. package/dist/security/index.js +9 -0
  538. package/dist/security/index.js.map +1 -0
  539. package/dist/security/input-sanitization.js +326 -0
  540. package/dist/security/input-sanitization.js.map +1 -0
  541. package/dist/sequence/index.js +295 -0
  542. package/dist/sequence/index.js.map +1 -0
  543. package/dist/sessions/assumptions.js +54 -0
  544. package/dist/sessions/assumptions.js.map +1 -0
  545. package/dist/sessions/briefing.js +377 -0
  546. package/dist/sessions/briefing.js.map +1 -0
  547. package/dist/sessions/context-alert.js +222 -0
  548. package/dist/sessions/context-alert.js.map +1 -0
  549. package/dist/sessions/context-inject.js +61 -0
  550. package/dist/sessions/context-inject.js.map +1 -0
  551. package/dist/sessions/context-monitor.js +98 -0
  552. package/dist/sessions/context-monitor.js.map +1 -0
  553. package/dist/sessions/decisions.js +65 -0
  554. package/dist/sessions/decisions.js.map +1 -0
  555. package/dist/sessions/find.js +65 -0
  556. package/dist/sessions/find.js.map +1 -0
  557. package/dist/sessions/handoff.js +328 -0
  558. package/dist/sessions/handoff.js.map +1 -0
  559. package/dist/sessions/hitl-warnings.js +254 -0
  560. package/dist/sessions/hitl-warnings.js.map +1 -0
  561. package/dist/sessions/index.js +327 -0
  562. package/dist/sessions/index.js.map +1 -0
  563. package/dist/sessions/session-archive.js +40 -0
  564. package/dist/sessions/session-archive.js.map +1 -0
  565. package/dist/sessions/session-cleanup.js +59 -0
  566. package/dist/sessions/session-cleanup.js.map +1 -0
  567. package/dist/sessions/session-drift.js +134 -0
  568. package/dist/sessions/session-drift.js.map +1 -0
  569. package/dist/sessions/session-enforcement.js +144 -0
  570. package/dist/sessions/session-enforcement.js.map +1 -0
  571. package/dist/sessions/session-grade.js +253 -0
  572. package/dist/sessions/session-grade.js.map +1 -0
  573. package/dist/sessions/session-history.js +42 -0
  574. package/dist/sessions/session-history.js.map +1 -0
  575. package/dist/sessions/session-id.js +81 -0
  576. package/dist/sessions/session-id.js.map +1 -0
  577. package/dist/sessions/session-memory-bridge.js +30 -0
  578. package/dist/sessions/session-memory-bridge.js.map +1 -0
  579. package/dist/sessions/session-show.js +24 -0
  580. package/dist/sessions/session-show.js.map +1 -0
  581. package/dist/sessions/session-stats.js +69 -0
  582. package/dist/sessions/session-stats.js.map +1 -0
  583. package/dist/sessions/session-suspend.js +39 -0
  584. package/dist/sessions/session-suspend.js.map +1 -0
  585. package/dist/sessions/session-switch.js +51 -0
  586. package/dist/sessions/session-switch.js.map +1 -0
  587. package/dist/sessions/session-view.js +76 -0
  588. package/dist/sessions/session-view.js.map +1 -0
  589. package/dist/sessions/snapshot.js +213 -0
  590. package/dist/sessions/snapshot.js.map +1 -0
  591. package/dist/sessions/statusline-setup.js +85 -0
  592. package/dist/sessions/statusline-setup.js.map +1 -0
  593. package/dist/sessions/types.js +8 -0
  594. package/dist/sessions/types.js.map +1 -0
  595. package/dist/skills/agents/config.js +94 -0
  596. package/dist/skills/agents/config.js.map +1 -0
  597. package/dist/skills/agents/install.js +116 -0
  598. package/dist/skills/agents/install.js.map +1 -0
  599. package/dist/skills/agents/registry.js +161 -0
  600. package/dist/skills/agents/registry.js.map +1 -0
  601. package/dist/skills/discovery.js +333 -0
  602. package/dist/skills/discovery.js.map +1 -0
  603. package/dist/skills/dispatch.js +347 -0
  604. package/dist/skills/dispatch.js.map +1 -0
  605. package/dist/skills/dynamic-skill-generator.js +87 -0
  606. package/dist/skills/dynamic-skill-generator.js.map +1 -0
  607. package/dist/skills/index.js +44 -0
  608. package/dist/skills/index.js.map +1 -0
  609. package/dist/skills/injection/subagent.js +195 -0
  610. package/dist/skills/injection/subagent.js.map +1 -0
  611. package/dist/skills/injection/token.js +260 -0
  612. package/dist/skills/injection/token.js.map +1 -0
  613. package/dist/skills/install.js +40 -0
  614. package/dist/skills/install.js.map +1 -0
  615. package/dist/skills/manifests/contribution.js +175 -0
  616. package/dist/skills/manifests/contribution.js.map +1 -0
  617. package/dist/skills/manifests/research.js +281 -0
  618. package/dist/skills/manifests/research.js.map +1 -0
  619. package/dist/skills/manifests/resolver.js +146 -0
  620. package/dist/skills/manifests/resolver.js.map +1 -0
  621. package/dist/skills/marketplace.js +90 -0
  622. package/dist/skills/marketplace.js.map +1 -0
  623. package/dist/skills/orchestrator/spawn.js +178 -0
  624. package/dist/skills/orchestrator/spawn.js.map +1 -0
  625. package/dist/skills/orchestrator/startup.js +451 -0
  626. package/dist/skills/orchestrator/startup.js.map +1 -0
  627. package/dist/skills/orchestrator/validator.js +301 -0
  628. package/dist/skills/orchestrator/validator.js.map +1 -0
  629. package/dist/skills/precedence-integration.js +73 -0
  630. package/dist/skills/precedence-integration.js.map +1 -0
  631. package/dist/skills/precedence-types.js +16 -0
  632. package/dist/skills/precedence-types.js.map +1 -0
  633. package/dist/skills/routing-table.js +63 -0
  634. package/dist/skills/routing-table.js.map +1 -0
  635. package/dist/skills/skill-paths.js +217 -0
  636. package/dist/skills/skill-paths.js.map +1 -0
  637. package/dist/skills/test-utility.js +55 -0
  638. package/dist/skills/test-utility.js.map +1 -0
  639. package/dist/skills/types.js +118 -0
  640. package/dist/skills/types.js.map +1 -0
  641. package/dist/skills/validation.js +183 -0
  642. package/dist/skills/validation.js.map +1 -0
  643. package/dist/skills/version.js +57 -0
  644. package/dist/skills/version.js.map +1 -0
  645. package/dist/snapshot/index.js +188 -0
  646. package/dist/snapshot/index.js.map +1 -0
  647. package/dist/spawn/adapter-registry.js +246 -0
  648. package/dist/spawn/adapter-registry.js.map +1 -0
  649. package/dist/spawn/index.js +10 -0
  650. package/dist/spawn/index.js.map +1 -0
  651. package/dist/stats/index.d.ts.map +1 -1
  652. package/dist/stats/index.js +350 -0
  653. package/dist/stats/index.js.map +1 -0
  654. package/dist/stats/workflow-telemetry.js +400 -0
  655. package/dist/stats/workflow-telemetry.js.map +1 -0
  656. package/dist/sticky/archive.js +47 -0
  657. package/dist/sticky/archive.js.map +1 -0
  658. package/dist/sticky/convert.js +235 -0
  659. package/dist/sticky/convert.js.map +1 -0
  660. package/dist/sticky/create.js +48 -0
  661. package/dist/sticky/create.js.map +1 -0
  662. package/dist/sticky/id.js +35 -0
  663. package/dist/sticky/id.js.map +1 -0
  664. package/dist/sticky/index.js +16 -0
  665. package/dist/sticky/index.js.map +1 -0
  666. package/dist/sticky/list.js +57 -0
  667. package/dist/sticky/list.js.map +1 -0
  668. package/dist/sticky/purge.js +45 -0
  669. package/dist/sticky/purge.js.map +1 -0
  670. package/dist/sticky/show.js +42 -0
  671. package/dist/sticky/show.js.map +1 -0
  672. package/dist/sticky/types.js +10 -0
  673. package/dist/sticky/types.js.map +1 -0
  674. package/dist/store/agent-registry-accessor.js +886 -0
  675. package/dist/store/agent-registry-accessor.js.map +1 -0
  676. package/dist/store/api-key-kdf.js +84 -0
  677. package/dist/store/api-key-kdf.js.map +1 -0
  678. package/dist/store/atomic.js +167 -0
  679. package/dist/store/atomic.js.map +1 -0
  680. package/dist/store/backup-crypto.js +184 -0
  681. package/dist/store/backup-crypto.js.map +1 -0
  682. package/dist/store/backup-pack.js +581 -0
  683. package/dist/store/backup-pack.js.map +1 -0
  684. package/dist/store/backup-unpack.js +449 -0
  685. package/dist/store/backup-unpack.js.map +1 -0
  686. package/dist/store/backup.js +94 -0
  687. package/dist/store/backup.js.map +1 -0
  688. package/dist/store/brain-accessor.js +429 -0
  689. package/dist/store/brain-accessor.js.map +1 -0
  690. package/dist/store/brain-schema.d.ts +663 -39
  691. package/dist/store/brain-schema.d.ts.map +1 -1
  692. package/dist/store/brain-schema.js +579 -0
  693. package/dist/store/brain-schema.js.map +1 -0
  694. package/dist/store/brain-sqlite.d.ts.map +1 -1
  695. package/dist/store/brain-sqlite.js +297 -0
  696. package/dist/store/brain-sqlite.js.map +1 -0
  697. package/dist/store/cache.js +168 -0
  698. package/dist/store/cache.js.map +1 -0
  699. package/dist/store/chain-schema.js +51 -0
  700. package/dist/store/chain-schema.js.map +1 -0
  701. package/dist/store/cleanup-legacy.js +171 -0
  702. package/dist/store/cleanup-legacy.js.map +1 -0
  703. package/dist/store/conduit-sqlite.js +570 -0
  704. package/dist/store/conduit-sqlite.js.map +1 -0
  705. package/dist/store/converters.js +124 -0
  706. package/dist/store/converters.js.map +1 -0
  707. package/dist/store/cross-db-cleanup.js +319 -0
  708. package/dist/store/cross-db-cleanup.js.map +1 -0
  709. package/dist/store/data-accessor.js +26 -0
  710. package/dist/store/data-accessor.js.map +1 -0
  711. package/dist/store/data-safety-central.js +269 -0
  712. package/dist/store/data-safety-central.js.map +1 -0
  713. package/dist/store/data-safety.js +274 -0
  714. package/dist/store/data-safety.js.map +1 -0
  715. package/dist/store/db-helpers.js +224 -0
  716. package/dist/store/db-helpers.js.map +1 -0
  717. package/dist/store/export.js +155 -0
  718. package/dist/store/export.js.map +1 -0
  719. package/dist/store/file-utils.js +270 -0
  720. package/dist/store/file-utils.js.map +1 -0
  721. package/dist/store/git-checkpoint.js +365 -0
  722. package/dist/store/git-checkpoint.js.map +1 -0
  723. package/dist/store/global-salt.js +147 -0
  724. package/dist/store/global-salt.js.map +1 -0
  725. package/dist/store/import-logging.js +139 -0
  726. package/dist/store/import-logging.js.map +1 -0
  727. package/dist/store/import-remap.js +145 -0
  728. package/dist/store/import-remap.js.map +1 -0
  729. package/dist/store/import-sort.js +121 -0
  730. package/dist/store/import-sort.js.map +1 -0
  731. package/dist/store/index.js +29 -0
  732. package/dist/store/index.js.map +1 -0
  733. package/dist/store/json.js +208 -0
  734. package/dist/store/json.js.map +1 -0
  735. package/dist/store/lifecycle-store.js +249 -0
  736. package/dist/store/lifecycle-store.js.map +1 -0
  737. package/dist/store/lock.js +70 -0
  738. package/dist/store/lock.js.map +1 -0
  739. package/dist/store/migrate-signaldock-to-conduit.js +562 -0
  740. package/dist/store/migrate-signaldock-to-conduit.js.map +1 -0
  741. package/dist/store/migration-manager.d.ts +5 -1
  742. package/dist/store/migration-manager.d.ts.map +1 -1
  743. package/dist/store/migration-manager.js +288 -0
  744. package/dist/store/migration-manager.js.map +1 -0
  745. package/dist/store/migration-sqlite.js +676 -0
  746. package/dist/store/migration-sqlite.js.map +1 -0
  747. package/dist/store/nexus-schema.js +268 -0
  748. package/dist/store/nexus-schema.js.map +1 -0
  749. package/dist/store/nexus-sqlite.js +242 -0
  750. package/dist/store/nexus-sqlite.js.map +1 -0
  751. package/dist/store/nexus-validation-schemas.js +40 -0
  752. package/dist/store/nexus-validation-schemas.js.map +1 -0
  753. package/dist/store/parsers.js +37 -0
  754. package/dist/store/parsers.js.map +1 -0
  755. package/dist/store/project-detect.js +457 -0
  756. package/dist/store/project-detect.js.map +1 -0
  757. package/dist/store/provider.js +101 -0
  758. package/dist/store/provider.js.map +1 -0
  759. package/dist/store/regenerators.js +207 -0
  760. package/dist/store/regenerators.js.map +1 -0
  761. package/dist/store/restore-conflict-report.js +206 -0
  762. package/dist/store/restore-conflict-report.js.map +1 -0
  763. package/dist/store/restore-json-merge.js +454 -0
  764. package/dist/store/restore-json-merge.js.map +1 -0
  765. package/dist/store/safety-data-accessor.js +257 -0
  766. package/dist/store/safety-data-accessor.js.map +1 -0
  767. package/dist/store/schema.js +7 -0
  768. package/dist/store/schema.js.map +1 -0
  769. package/dist/store/session-store.js +219 -0
  770. package/dist/store/session-store.js.map +1 -0
  771. package/dist/store/signaldock-sqlite.js +550 -0
  772. package/dist/store/signaldock-sqlite.js.map +1 -0
  773. package/dist/store/sqlite-backup.js +498 -0
  774. package/dist/store/sqlite-backup.js.map +1 -0
  775. package/dist/store/sqlite-data-accessor.js +787 -0
  776. package/dist/store/sqlite-data-accessor.js.map +1 -0
  777. package/dist/store/sqlite.js +483 -0
  778. package/dist/store/sqlite.js.map +1 -0
  779. package/dist/store/status-registry.js +8 -0
  780. package/dist/store/status-registry.js.map +1 -0
  781. package/dist/store/t310-readiness.js +115 -0
  782. package/dist/store/t310-readiness.js.map +1 -0
  783. package/dist/store/task-store.js +358 -0
  784. package/dist/store/task-store.js.map +1 -0
  785. package/dist/store/tasks-schema.d.ts +1 -1
  786. package/dist/store/tasks-schema.js +610 -0
  787. package/dist/store/tasks-schema.js.map +1 -0
  788. package/dist/store/typed-query.js +15 -0
  789. package/dist/store/typed-query.js.map +1 -0
  790. package/dist/store/validation-schemas.d.ts +6 -6
  791. package/dist/store/validation-schemas.js +278 -0
  792. package/dist/store/validation-schemas.js.map +1 -0
  793. package/dist/system/archive-analytics.js +277 -0
  794. package/dist/system/archive-analytics.js.map +1 -0
  795. package/dist/system/archive-stats.js +64 -0
  796. package/dist/system/archive-stats.js.map +1 -0
  797. package/dist/system/audit.js +145 -0
  798. package/dist/system/audit.js.map +1 -0
  799. package/dist/system/backup.js +280 -0
  800. package/dist/system/backup.js.map +1 -0
  801. package/dist/system/cleanup.js +134 -0
  802. package/dist/system/cleanup.js.map +1 -0
  803. package/dist/system/dependencies.js +466 -0
  804. package/dist/system/dependencies.js.map +1 -0
  805. package/dist/system/health.d.ts.map +1 -1
  806. package/dist/system/health.js +1206 -0
  807. package/dist/system/health.js.map +1 -0
  808. package/dist/system/index.js +18 -0
  809. package/dist/system/index.js.map +1 -0
  810. package/dist/system/inject-generate.js +122 -0
  811. package/dist/system/inject-generate.js.map +1 -0
  812. package/dist/system/labels.js +38 -0
  813. package/dist/system/labels.js.map +1 -0
  814. package/dist/system/metrics.js +61 -0
  815. package/dist/system/metrics.js.map +1 -0
  816. package/dist/system/migrate.js +43 -0
  817. package/dist/system/migrate.js.map +1 -0
  818. package/dist/system/platform-paths.js +80 -0
  819. package/dist/system/platform-paths.js.map +1 -0
  820. package/dist/system/runtime.js +161 -0
  821. package/dist/system/runtime.js.map +1 -0
  822. package/dist/system/safestop.js +89 -0
  823. package/dist/system/safestop.js.map +1 -0
  824. package/dist/system/storage-preflight.js +123 -0
  825. package/dist/system/storage-preflight.js.map +1 -0
  826. package/dist/task-work/index.js +159 -0
  827. package/dist/task-work/index.js.map +1 -0
  828. package/dist/tasks/add.js +837 -0
  829. package/dist/tasks/add.js.map +1 -0
  830. package/dist/tasks/analyze.js +85 -0
  831. package/dist/tasks/analyze.js.map +1 -0
  832. package/dist/tasks/archive.js +90 -0
  833. package/dist/tasks/archive.js.map +1 -0
  834. package/dist/tasks/atomicity.js +83 -0
  835. package/dist/tasks/atomicity.js.map +1 -0
  836. package/dist/tasks/cancel-ops.js +83 -0
  837. package/dist/tasks/cancel-ops.js.map +1 -0
  838. package/dist/tasks/complete.d.ts.map +1 -1
  839. package/dist/tasks/complete.js +228 -0
  840. package/dist/tasks/complete.js.map +1 -0
  841. package/dist/tasks/crossref-extract.js +73 -0
  842. package/dist/tasks/crossref-extract.js.map +1 -0
  843. package/dist/tasks/delete-preview.js +192 -0
  844. package/dist/tasks/delete-preview.js.map +1 -0
  845. package/dist/tasks/delete.js +120 -0
  846. package/dist/tasks/delete.js.map +1 -0
  847. package/dist/tasks/deletion-strategy.js +200 -0
  848. package/dist/tasks/deletion-strategy.js.map +1 -0
  849. package/dist/tasks/dependency-check.js +278 -0
  850. package/dist/tasks/dependency-check.js.map +1 -0
  851. package/dist/tasks/deps-ready.js +32 -0
  852. package/dist/tasks/deps-ready.js.map +1 -0
  853. package/dist/tasks/enforcement.js +86 -0
  854. package/dist/tasks/enforcement.js.map +1 -0
  855. package/dist/tasks/epic-enforcement.js +294 -0
  856. package/dist/tasks/epic-enforcement.js.map +1 -0
  857. package/dist/tasks/find.js +163 -0
  858. package/dist/tasks/find.js.map +1 -0
  859. package/dist/tasks/graph-cache.js +127 -0
  860. package/dist/tasks/graph-cache.js.map +1 -0
  861. package/dist/tasks/graph-ops.d.ts.map +1 -1
  862. package/dist/tasks/graph-ops.js +173 -0
  863. package/dist/tasks/graph-ops.js.map +1 -0
  864. package/dist/tasks/graph-rag.js +328 -0
  865. package/dist/tasks/graph-rag.js.map +1 -0
  866. package/dist/tasks/hierarchy-policy.js +149 -0
  867. package/dist/tasks/hierarchy-policy.js.map +1 -0
  868. package/dist/tasks/hierarchy.js +185 -0
  869. package/dist/tasks/hierarchy.js.map +1 -0
  870. package/dist/tasks/id-generator.js +65 -0
  871. package/dist/tasks/id-generator.js.map +1 -0
  872. package/dist/tasks/index.js +14 -0
  873. package/dist/tasks/index.js.map +1 -0
  874. package/dist/tasks/labels.js +55 -0
  875. package/dist/tasks/labels.js.map +1 -0
  876. package/dist/tasks/list.js +75 -0
  877. package/dist/tasks/list.js.map +1 -0
  878. package/dist/tasks/phase-tracking.js +133 -0
  879. package/dist/tasks/phase-tracking.js.map +1 -0
  880. package/dist/tasks/pipeline-stage.js +248 -0
  881. package/dist/tasks/pipeline-stage.js.map +1 -0
  882. package/dist/tasks/plan.js +268 -0
  883. package/dist/tasks/plan.js.map +1 -0
  884. package/dist/tasks/relates.js +101 -0
  885. package/dist/tasks/relates.js.map +1 -0
  886. package/dist/tasks/show.js +83 -0
  887. package/dist/tasks/show.js.map +1 -0
  888. package/dist/tasks/size-weighting.js +86 -0
  889. package/dist/tasks/size-weighting.js.map +1 -0
  890. package/dist/tasks/staleness.js +86 -0
  891. package/dist/tasks/staleness.js.map +1 -0
  892. package/dist/tasks/task-ops.js +1741 -0
  893. package/dist/tasks/task-ops.js.map +1 -0
  894. package/dist/tasks/update.js +303 -0
  895. package/dist/tasks/update.js.map +1 -0
  896. package/dist/templates/index.js +10 -0
  897. package/dist/templates/index.js.map +1 -0
  898. package/dist/templates/parser.js +254 -0
  899. package/dist/templates/parser.js.map +1 -0
  900. package/dist/ui/aliases.js +153 -0
  901. package/dist/ui/aliases.js.map +1 -0
  902. package/dist/ui/changelog.js +184 -0
  903. package/dist/ui/changelog.js.map +1 -0
  904. package/dist/ui/command-registry.js +168 -0
  905. package/dist/ui/command-registry.js.map +1 -0
  906. package/dist/ui/flags.js +94 -0
  907. package/dist/ui/flags.js.map +1 -0
  908. package/dist/ui/index.js +24 -0
  909. package/dist/ui/index.js.map +1 -0
  910. package/dist/upgrade.js +1148 -0
  911. package/dist/upgrade.js.map +1 -0
  912. package/dist/validation/chain-validation.js +146 -0
  913. package/dist/validation/chain-validation.js.map +1 -0
  914. package/dist/validation/compliance.js +155 -0
  915. package/dist/validation/compliance.js.map +1 -0
  916. package/dist/validation/docs-sync.js +212 -0
  917. package/dist/validation/docs-sync.js.map +1 -0
  918. package/dist/validation/doctor/checks.js +1069 -0
  919. package/dist/validation/doctor/checks.js.map +1 -0
  920. package/dist/validation/doctor/index.js +9 -0
  921. package/dist/validation/doctor/index.js.map +1 -0
  922. package/dist/validation/doctor/project-cache.js +160 -0
  923. package/dist/validation/doctor/project-cache.js.map +1 -0
  924. package/dist/validation/doctor/utils.js +155 -0
  925. package/dist/validation/doctor/utils.js.map +1 -0
  926. package/dist/validation/engine.js +914 -0
  927. package/dist/validation/engine.js.map +1 -0
  928. package/dist/validation/gap-check.js +175 -0
  929. package/dist/validation/gap-check.js.map +1 -0
  930. package/dist/validation/index.js +40 -0
  931. package/dist/validation/index.js.map +1 -0
  932. package/dist/validation/manifest.js +237 -0
  933. package/dist/validation/manifest.js.map +1 -0
  934. package/dist/validation/operation-gate-validators.js +724 -0
  935. package/dist/validation/operation-gate-validators.js.map +1 -0
  936. package/dist/validation/operation-verification-gates.js +532 -0
  937. package/dist/validation/operation-verification-gates.js.map +1 -0
  938. package/dist/validation/param-utils.js +141 -0
  939. package/dist/validation/param-utils.js.map +1 -0
  940. package/dist/validation/protocol-common.js +300 -0
  941. package/dist/validation/protocol-common.js.map +1 -0
  942. package/dist/validation/protocols/_shared.js +82 -0
  943. package/dist/validation/protocols/_shared.js.map +1 -0
  944. package/dist/validation/protocols/architecture-decision.js +31 -0
  945. package/dist/validation/protocols/architecture-decision.js.map +1 -0
  946. package/dist/validation/protocols/artifact-publish.js +28 -0
  947. package/dist/validation/protocols/artifact-publish.js.map +1 -0
  948. package/dist/validation/protocols/consensus.js +41 -0
  949. package/dist/validation/protocols/consensus.js.map +1 -0
  950. package/dist/validation/protocols/contribution.js +27 -0
  951. package/dist/validation/protocols/contribution.js.map +1 -0
  952. package/dist/validation/protocols/decomposition.js +28 -0
  953. package/dist/validation/protocols/decomposition.js.map +1 -0
  954. package/dist/validation/protocols/implementation.js +24 -0
  955. package/dist/validation/protocols/implementation.js.map +1 -0
  956. package/dist/validation/protocols/provenance.js +29 -0
  957. package/dist/validation/protocols/provenance.js.map +1 -0
  958. package/dist/validation/protocols/release.js +29 -0
  959. package/dist/validation/protocols/release.js.map +1 -0
  960. package/dist/validation/protocols/research.js +24 -0
  961. package/dist/validation/protocols/research.js.map +1 -0
  962. package/dist/validation/protocols/specification.js +27 -0
  963. package/dist/validation/protocols/specification.js.map +1 -0
  964. package/dist/validation/protocols/testing.js +30 -0
  965. package/dist/validation/protocols/testing.js.map +1 -0
  966. package/dist/validation/protocols/validation.js +30 -0
  967. package/dist/validation/protocols/validation.js.map +1 -0
  968. package/dist/validation/schema-integrity.js +170 -0
  969. package/dist/validation/schema-integrity.js.map +1 -0
  970. package/dist/validation/schema-validator.js +176 -0
  971. package/dist/validation/schema-validator.js.map +1 -0
  972. package/dist/validation/validate-ops.js +937 -0
  973. package/dist/validation/validate-ops.js.map +1 -0
  974. package/dist/validation/validation-rules.js +226 -0
  975. package/dist/validation/validation-rules.js.map +1 -0
  976. package/dist/validation/verification.js +321 -0
  977. package/dist/validation/verification.js.map +1 -0
  978. package/migrations/drizzle-brain/20260411000001_t528-graph-schema-expansion/migration.sql +47 -0
  979. package/migrations/drizzle-brain/20260412000001_t531-quality-score-typed-tables/migration.sql +23 -0
  980. package/migrations/drizzle-brain/20260413000001_t549-tiered-typed-memory/migration.sql +195 -0
  981. package/migrations/drizzle-nexus/20260412000001_t529-nexus-graph-tables/migration.sql +49 -0
  982. package/package.json +13 -12
  983. package/src/config.ts +7 -0
  984. package/src/hooks/handlers/__tests__/conduit-hooks.test.ts +356 -0
  985. package/src/hooks/handlers/conduit-hooks.ts +258 -0
  986. package/src/hooks/handlers/index.ts +13 -0
  987. package/src/hooks/handlers/intelligence-hooks.ts +80 -0
  988. package/src/hooks/handlers/session-hooks.ts +78 -0
  989. package/src/hooks/handlers/task-hooks.ts +14 -0
  990. package/src/hooks/handlers/watchdog-hooks.ts +187 -0
  991. package/src/injection.ts +41 -2
  992. package/src/internal.ts +39 -2
  993. package/src/memory/__tests__/auto-extract.test.ts +43 -114
  994. package/src/memory/__tests__/brain-automation.test.ts +16 -39
  995. package/src/memory/__tests__/brain-rrf.test.ts +431 -0
  996. package/src/memory/__tests__/llm-extraction.test.ts +342 -0
  997. package/src/memory/__tests__/observer-reflector.test.ts +475 -0
  998. package/src/memory/anthropic-key-resolver.ts +113 -0
  999. package/src/memory/auto-extract.ts +40 -72
  1000. package/src/memory/brain-consolidator.ts +344 -0
  1001. package/src/memory/brain-lifecycle.ts +636 -2
  1002. package/src/memory/brain-retrieval.ts +630 -18
  1003. package/src/memory/brain-search.ts +234 -132
  1004. package/src/memory/decisions.ts +21 -1
  1005. package/src/memory/engine-compat.ts +25 -15
  1006. package/src/memory/extraction-gate.ts +574 -0
  1007. package/src/memory/index.ts +6 -2
  1008. package/src/memory/learnings.ts +34 -1
  1009. package/src/memory/llm-extraction.ts +524 -0
  1010. package/src/memory/memory-bridge.ts +29 -12
  1011. package/src/memory/observer-reflector.ts +829 -0
  1012. package/src/memory/patterns.ts +30 -1
  1013. package/src/memory/quality-scoring.ts +93 -9
  1014. package/src/nexus/nexus-bridge.ts +444 -0
  1015. package/src/scaffold.ts +42 -0
  1016. package/src/stats/index.ts +11 -3
  1017. package/src/store/brain-schema.ts +282 -0
  1018. package/src/store/brain-sqlite.ts +55 -0
  1019. package/src/store/migration-manager.ts +83 -12
  1020. package/src/system/health.ts +17 -0
  1021. package/src/tasks/complete.ts +7 -10
  1022. package/src/tasks/graph-ops.ts +1 -0
  1023. package/src/tasks/task-ops.ts +1 -1
  1024. package/templates/CLEO-INJECTION.md +15 -0
@@ -0,0 +1,829 @@
1
+ /**
2
+ * Observer/Reflector — LLM-driven session compression for CLEO BRAIN.
3
+ *
4
+ * Implements the Mastra-style two-agent compression pattern that achieves
5
+ * 3-6x context compression on text and 5-40x on tool-call-heavy workloads.
6
+ *
7
+ * ## Architecture
8
+ *
9
+ * **Observer** (runs after each task or when observation count ≥ threshold):
10
+ * - Takes raw brain observations from the current session
11
+ * - Produces 3-5 dense, dated, prioritized observation notes (≤ 300 chars each)
12
+ * - Compresses verbose tool outputs into 1-line summaries
13
+ * - Stored as brain_observations with source='observer-compressed'
14
+ * - Linked to original observation IDs via brain_memory_links table
15
+ *
16
+ * **Reflector** (runs at session end when observation count ≥ threshold):
17
+ * - Takes accumulated observation notes from the current session
18
+ * - Restructures: combines related items, identifies cross-cutting patterns,
19
+ * drops superseded observations
20
+ * - Outputs stored as brain_patterns and brain_learnings via existing store fns
21
+ * - Source tagged as 'reflector-synthesized'
22
+ *
23
+ * ## LLM Backend
24
+ *
25
+ * Calls the Anthropic Messages API directly via native fetch (no SDK dep).
26
+ * Uses the cheapest available model (`claude-haiku-4-5` or env override).
27
+ * When `ANTHROPIC_API_KEY` is not set, both functions silently no-op — the
28
+ * rest of the memory pipeline still runs normally.
29
+ *
30
+ * ## Configuration
31
+ *
32
+ * Add to `config.json` under `brain.observer`:
33
+ * ```json
34
+ * {
35
+ * "brain": {
36
+ * "observer": {
37
+ * "enabled": true,
38
+ * "threshold": 10
39
+ * },
40
+ * "reflector": {
41
+ * "enabled": true
42
+ * }
43
+ * }
44
+ * }
45
+ * ```
46
+ *
47
+ * @task T554
48
+ * @epic T549
49
+ * @see .cleo/agent-outputs/R-llm-memory-systems-research.md §7 (Observer/Reflector Pattern)
50
+ */
51
+
52
+ import { randomBytes } from 'node:crypto';
53
+ import { getBrainNativeDb } from '../store/brain-sqlite.js';
54
+ import { addGraphEdge } from './graph-auto-populate.js';
55
+ import { storeLearning } from './learnings.js';
56
+ import { storePattern } from './patterns.js';
57
+
58
+ // ============================================================================
59
+ // Internal row type (raw SQLite snake_case columns, not Drizzle camelCase)
60
+ // ============================================================================
61
+
62
+ /** Minimal raw-query row from brain_observations. */
63
+ interface RawObservationRow {
64
+ id: string;
65
+ type: string;
66
+ title: string | null;
67
+ narrative: string | null;
68
+ created_at: string | null;
69
+ source_type: string | null;
70
+ source_session_id: string | null;
71
+ }
72
+
73
+ // ============================================================================
74
+ // Constants
75
+ // ============================================================================
76
+
77
+ /** Default model used for observer/reflector LLM calls. */
78
+ const DEFAULT_MODEL = 'claude-haiku-4-5';
79
+
80
+ /** Maximum tokens for LLM response. Enough for 5 structured observations. */
81
+ const MAX_RESPONSE_TOKENS = 1024;
82
+
83
+ /** Default threshold: trigger observer after this many session observations. */
84
+ const DEFAULT_OBSERVER_THRESHOLD = 10;
85
+
86
+ /** Maximum observations passed to observer in a single batch. */
87
+ const OBSERVER_BATCH_LIMIT = 30;
88
+
89
+ /** Source tag written to brain_observations for observer-compressed entries. */
90
+ const OBSERVER_SOURCE = 'observer-compressed';
91
+
92
+ /** Source tag written to brain_patterns / brain_learnings for reflector outputs. */
93
+ const REFLECTOR_SOURCE = 'reflector-synthesized';
94
+
95
+ // ============================================================================
96
+ // Types
97
+ // ============================================================================
98
+
99
+ /** A single compressed observation produced by the Observer. */
100
+ export interface ObserverNote {
101
+ /** ISO date string when the original events occurred. */
102
+ date: string;
103
+ /**
104
+ * Priority 1 (highest, architectural) through 5 (lowest, routine).
105
+ * Maps to the research's RED/YELLOW/GREEN scale.
106
+ */
107
+ priority: 1 | 2 | 3 | 4 | 5;
108
+ /** Dense observation text, ≤ 300 characters. */
109
+ observation: string;
110
+ /** IDs of the original observations this note compresses. */
111
+ source_ids: string[];
112
+ }
113
+
114
+ /** Output of `runObserver`. */
115
+ export interface ObserverResult {
116
+ /** Whether the LLM was invoked (false when no API key or disabled). */
117
+ ran: boolean;
118
+ /** Number of new compressed observation entries stored. */
119
+ stored: number;
120
+ /** IDs of original observations that were compressed. */
121
+ compressedIds: string[];
122
+ /** The raw notes produced by the LLM (for testing/debugging). */
123
+ notes: ObserverNote[];
124
+ }
125
+
126
+ /** A single pattern extracted by the Reflector. */
127
+ export interface ReflectorPattern {
128
+ pattern: string;
129
+ context: string;
130
+ }
131
+
132
+ /** A single learning extracted by the Reflector. */
133
+ export interface ReflectorLearning {
134
+ insight: string;
135
+ confidence: number;
136
+ }
137
+
138
+ /** Structured output from the Reflector LLM call. */
139
+ interface ReflectorOutput {
140
+ patterns: ReflectorPattern[];
141
+ learnings: ReflectorLearning[];
142
+ /** IDs of observation notes the reflector considers superseded. */
143
+ superseded: string[];
144
+ }
145
+
146
+ /** Output of `runReflector`. */
147
+ export interface ReflectorResult {
148
+ /** Whether the LLM was invoked (false when no API key or disabled). */
149
+ ran: boolean;
150
+ /** Number of new patterns stored. */
151
+ patternsStored: number;
152
+ /** Number of new learnings stored. */
153
+ learningsStored: number;
154
+ /** IDs of observations marked as superseded. */
155
+ supersededIds: string[];
156
+ }
157
+
158
+ // ============================================================================
159
+ // Configuration helpers
160
+ // ============================================================================
161
+
162
+ /**
163
+ * Observer configuration resolved from `brain.observer` in config.json,
164
+ * with safe defaults.
165
+ */
166
+ export interface ObserverConfig {
167
+ enabled: boolean;
168
+ threshold: number;
169
+ }
170
+
171
+ /**
172
+ * Reflector configuration resolved from `brain.reflector` in config.json,
173
+ * with safe defaults.
174
+ */
175
+ export interface ReflectorConfig {
176
+ enabled: boolean;
177
+ }
178
+
179
+ /**
180
+ * Load observer configuration for the project.
181
+ * Falls back to defaults on any error (enabled=true, threshold=10).
182
+ */
183
+ async function loadObserverConfig(projectRoot: string): Promise<ObserverConfig> {
184
+ try {
185
+ const { loadConfig } = await import('../config.js');
186
+ const config = await loadConfig(projectRoot);
187
+ // Config type does not yet include observer/reflector — use dynamic cast
188
+ const brain = config.brain as Record<string, unknown> | undefined;
189
+ const observer = brain?.['observer'] as Record<string, unknown> | undefined;
190
+ return {
191
+ enabled: observer?.['enabled'] !== false,
192
+ threshold:
193
+ typeof observer?.['threshold'] === 'number'
194
+ ? observer['threshold']
195
+ : DEFAULT_OBSERVER_THRESHOLD,
196
+ };
197
+ } catch {
198
+ return { enabled: true, threshold: DEFAULT_OBSERVER_THRESHOLD };
199
+ }
200
+ }
201
+
202
+ /**
203
+ * Load reflector configuration for the project.
204
+ * Falls back to defaults on any error (enabled=true).
205
+ */
206
+ async function loadReflectorConfig(projectRoot: string): Promise<ReflectorConfig> {
207
+ try {
208
+ const { loadConfig } = await import('../config.js');
209
+ const config = await loadConfig(projectRoot);
210
+ const brain = config.brain as Record<string, unknown> | undefined;
211
+ const reflector = brain?.['reflector'] as Record<string, unknown> | undefined;
212
+ return {
213
+ enabled: reflector?.['enabled'] !== false,
214
+ };
215
+ } catch {
216
+ return { enabled: true };
217
+ }
218
+ }
219
+
220
+ // ============================================================================
221
+ // LLM client
222
+ // ============================================================================
223
+
224
+ /** Response envelope from the Anthropic Messages API. */
225
+ interface AnthropicResponse {
226
+ content: Array<{ type: string; text: string }>;
227
+ stop_reason: string;
228
+ }
229
+
230
+ /**
231
+ * Call the Anthropic Messages API via native fetch.
232
+ *
233
+ * Uses `ANTHROPIC_API_KEY` from the environment. Returns null when the key is
234
+ * not set or when the API call fails (caller handles graceful degradation).
235
+ *
236
+ * @param systemPrompt - System instruction for the LLM.
237
+ * @param userContent - User message content.
238
+ * @returns The assistant response text, or null on failure.
239
+ */
240
+ async function callAnthropicLlm(systemPrompt: string, userContent: string): Promise<string | null> {
241
+ const { resolveAnthropicApiKey } = await import('./anthropic-key-resolver.js');
242
+ const apiKey = resolveAnthropicApiKey();
243
+ if (!apiKey) {
244
+ return null;
245
+ }
246
+
247
+ const model = process.env['CLEO_OBSERVER_MODEL'] ?? DEFAULT_MODEL;
248
+
249
+ try {
250
+ const response = await fetch('https://api.anthropic.com/v1/messages', {
251
+ method: 'POST',
252
+ headers: {
253
+ 'Content-Type': 'application/json',
254
+ 'x-api-key': apiKey,
255
+ 'anthropic-version': '2023-06-01',
256
+ },
257
+ body: JSON.stringify({
258
+ model,
259
+ max_tokens: MAX_RESPONSE_TOKENS,
260
+ system: systemPrompt,
261
+ messages: [{ role: 'user', content: userContent }],
262
+ }),
263
+ });
264
+
265
+ if (!response.ok) {
266
+ const body = await response.text().catch(() => '');
267
+ console.warn(
268
+ `[observer-reflector] Anthropic API error ${response.status}: ${body.slice(0, 200)}`,
269
+ );
270
+ return null;
271
+ }
272
+
273
+ const data = (await response.json()) as AnthropicResponse;
274
+ const textBlock = data.content.find((b) => b.type === 'text');
275
+ return textBlock?.text ?? null;
276
+ } catch (err) {
277
+ const msg = err instanceof Error ? err.message : String(err);
278
+ console.warn(`[observer-reflector] LLM call failed: ${msg}`);
279
+ return null;
280
+ }
281
+ }
282
+
283
+ // ============================================================================
284
+ // JSON parse helper
285
+ // ============================================================================
286
+
287
+ /**
288
+ * Attempt to parse the LLM response as JSON. Strips markdown code fences
289
+ * (```json ... ```) before parsing. Returns null on parse failure.
290
+ */
291
+ function parseJsonResponse<T>(text: string): T | null {
292
+ try {
293
+ // Strip markdown code fences if present
294
+ const cleaned = text
295
+ .replace(/^```(?:json)?\s*/m, '')
296
+ .replace(/\s*```\s*$/m, '')
297
+ .trim();
298
+ return JSON.parse(cleaned) as T;
299
+ } catch {
300
+ return null;
301
+ }
302
+ }
303
+
304
+ // ============================================================================
305
+ // Database helpers
306
+ // ============================================================================
307
+
308
+ /**
309
+ * Query recent brain_observations for a session.
310
+ *
311
+ * Returns up to `limit` observations (most recent first) that:
312
+ * - Were created within the current session (`source_session_id = sessionId`)
313
+ * - Are not already observer-compressed (`source_type != 'observer-compressed'`)
314
+ * - Have not been soft-evicted (`invalid_at IS NULL`)
315
+ *
316
+ * Falls back to all uncompressed observations from the last 24 hours when
317
+ * sessionId is not provided or yields fewer than 2 results.
318
+ */
319
+ function fetchSessionObservations(
320
+ sessionId: string | undefined,
321
+ limit: number,
322
+ ): RawObservationRow[] {
323
+ const nativeDb = getBrainNativeDb();
324
+ if (!nativeDb) return [];
325
+
326
+ try {
327
+ if (sessionId) {
328
+ const rows = nativeDb
329
+ .prepare(
330
+ `
331
+ SELECT id, type, title, narrative, created_at, source_session_id
332
+ FROM brain_observations
333
+ WHERE source_session_id = ?
334
+ AND (source_type IS NULL OR source_type != ?)
335
+ AND invalid_at IS NULL
336
+ ORDER BY created_at DESC
337
+ LIMIT ?
338
+ `,
339
+ )
340
+ .all(sessionId, OBSERVER_SOURCE, limit) as unknown as RawObservationRow[];
341
+
342
+ if (rows.length >= 2) return rows;
343
+ }
344
+
345
+ // Fallback: recent uncompressed observations from the last 24 hours
346
+ const cutoff = new Date(Date.now() - 24 * 60 * 60 * 1000)
347
+ .toISOString()
348
+ .replace('T', ' ')
349
+ .slice(0, 19);
350
+
351
+ return nativeDb
352
+ .prepare(
353
+ `
354
+ SELECT id, type, title, narrative, created_at, source_session_id
355
+ FROM brain_observations
356
+ WHERE created_at >= ?
357
+ AND (source_type IS NULL OR source_type != ?)
358
+ AND invalid_at IS NULL
359
+ ORDER BY created_at DESC
360
+ LIMIT ?
361
+ `,
362
+ )
363
+ .all(cutoff, OBSERVER_SOURCE, limit) as unknown as RawObservationRow[];
364
+ } catch {
365
+ return [];
366
+ }
367
+ }
368
+
369
+ /**
370
+ * Count uncompressed observations for a session.
371
+ * Used to check the trigger threshold before running the observer.
372
+ */
373
+ function countSessionObservations(sessionId: string | undefined): number {
374
+ const nativeDb = getBrainNativeDb();
375
+ if (!nativeDb) return 0;
376
+
377
+ try {
378
+ if (sessionId) {
379
+ const row = nativeDb
380
+ .prepare(
381
+ `
382
+ SELECT COUNT(*) as cnt
383
+ FROM brain_observations
384
+ WHERE source_session_id = ?
385
+ AND (source_type IS NULL OR source_type != ?)
386
+ AND invalid_at IS NULL
387
+ `,
388
+ )
389
+ .get(sessionId, OBSERVER_SOURCE) as { cnt: number } | undefined;
390
+ if (row && row.cnt > 0) return row.cnt;
391
+ }
392
+
393
+ const cutoff = new Date(Date.now() - 24 * 60 * 60 * 1000)
394
+ .toISOString()
395
+ .replace('T', ' ')
396
+ .slice(0, 19);
397
+
398
+ const row = nativeDb
399
+ .prepare(
400
+ `
401
+ SELECT COUNT(*) as cnt
402
+ FROM brain_observations
403
+ WHERE created_at >= ?
404
+ AND (source_type IS NULL OR source_type != ?)
405
+ AND invalid_at IS NULL
406
+ `,
407
+ )
408
+ .get(cutoff, OBSERVER_SOURCE) as { cnt: number } | undefined;
409
+
410
+ return row?.cnt ?? 0;
411
+ } catch {
412
+ return 0;
413
+ }
414
+ }
415
+
416
+ /**
417
+ * Store a compressed observer note as a brain_observation entry.
418
+ *
419
+ * Uses source_type = 'observer-compressed' so it is excluded from
420
+ * future observer input batches (no infinite compression loops).
421
+ *
422
+ * @returns ID of the stored entry, or null on failure.
423
+ */
424
+ function storeObserverNote(
425
+ projectRoot: string,
426
+ note: ObserverNote,
427
+ sessionId: string | undefined,
428
+ ): string | null {
429
+ const nativeDb = getBrainNativeDb();
430
+ if (!nativeDb) return null;
431
+
432
+ try {
433
+ const id = `O-${randomBytes(4).toString('hex')}`;
434
+ const now = new Date().toISOString().replace('T', ' ').slice(0, 19);
435
+ const title = `[Observer p${note.priority}] ${note.observation.slice(0, 80)}`;
436
+ const narrative = `${note.observation} (compressed from: ${note.source_ids.join(', ')})`;
437
+
438
+ nativeDb
439
+ .prepare(
440
+ `
441
+ INSERT INTO brain_observations
442
+ (id, type, title, narrative, source_type, source_session_id, quality_score,
443
+ memory_tier, created_at)
444
+ VALUES (?, 'change', ?, ?, ?, ?, ?, 'short', ?)
445
+ `,
446
+ )
447
+ .run(
448
+ id,
449
+ title,
450
+ narrative,
451
+ OBSERVER_SOURCE,
452
+ sessionId ?? null,
453
+ // Quality: priority 1 = highest quality (1.0), priority 5 = lowest (0.6)
454
+ Math.max(0.6, 1.0 - (note.priority - 1) * 0.1),
455
+ now,
456
+ );
457
+
458
+ // Link compressed note to its source observation IDs via graph edges
459
+ // (best-effort, non-blocking)
460
+ for (const sourceId of note.source_ids) {
461
+ addGraphEdge(
462
+ projectRoot,
463
+ `observation:${id}`,
464
+ `observation:${sourceId}`,
465
+ 'supersedes',
466
+ 0.9,
467
+ 'observer-reflector',
468
+ ).catch(() => undefined);
469
+ }
470
+
471
+ return id;
472
+ } catch (err) {
473
+ const msg = err instanceof Error ? err.message : String(err);
474
+ console.warn(`[observer-reflector] Failed to store observer note: ${msg}`);
475
+ return null;
476
+ }
477
+ }
478
+
479
+ /**
480
+ * Mark observations as superseded by the reflector.
481
+ * Sets invalid_at so they are excluded from future queries.
482
+ */
483
+ function markSuperseded(ids: string[]): void {
484
+ if (ids.length === 0) return;
485
+ const nativeDb = getBrainNativeDb();
486
+ if (!nativeDb) return;
487
+
488
+ const now = new Date().toISOString().replace('T', ' ').slice(0, 19);
489
+ try {
490
+ // SQLite placeholder limit is 999; process in safe batches
491
+ const BATCH = 100;
492
+ for (let i = 0; i < ids.length; i += BATCH) {
493
+ const batch = ids.slice(i, i + BATCH);
494
+ const placeholders = batch.map(() => '?').join(',');
495
+ nativeDb
496
+ .prepare(
497
+ `UPDATE brain_observations
498
+ SET invalid_at = ?, updated_at = ?
499
+ WHERE id IN (${placeholders}) AND invalid_at IS NULL`,
500
+ )
501
+ .run(now, now, ...batch);
502
+ }
503
+ } catch {
504
+ /* best-effort */
505
+ }
506
+ }
507
+
508
+ // ============================================================================
509
+ // Observer
510
+ // ============================================================================
511
+
512
+ /** System prompt for the Observer LLM call. */
513
+ const OBSERVER_SYSTEM_PROMPT = `You are compressing AI coding session activity into dense observation notes.
514
+ Input: recent observations and tool outputs from a CLEO agent coding session.
515
+ Output: 3-5 dated, prioritized observation notes (each ≤300 chars).
516
+ Focus on: state changes, decisions, errors, completed work.
517
+ Drop: verbose tool output, repetition, transient state.
518
+ Format: JSON array of objects with keys:
519
+ - date: ISO date string (YYYY-MM-DD)
520
+ - priority: integer 1-5 (1=architectural decision, 2=implementation choice, 3=constraint/bug, 4=routine action, 5=noise)
521
+ - observation: string ≤300 chars — capture DECISION+RATIONALE not the discussion
522
+ - source_ids: array of original observation IDs that this note compresses
523
+
524
+ Rules:
525
+ - For tool calls: capture the outcome, not the invocation
526
+ - For file reads: capture what was LEARNED, not what was read
527
+ - For errors: capture the ROOT CAUSE, not the stack trace
528
+ - Prefer priority 1-2 items; include priority 4-5 only if significant count
529
+ - ONLY return valid JSON array, no markdown fences or extra text`;
530
+
531
+ /**
532
+ * Run the Observer on current session observations.
533
+ *
534
+ * Triggered when:
535
+ * 1. `brain.observer.enabled` is true (default)
536
+ * 2. Uncompressed observation count ≥ `brain.observer.threshold` (default: 10)
537
+ * 3. `ANTHROPIC_API_KEY` is set in the environment
538
+ *
539
+ * Steps:
540
+ * 1. Fetch up to OBSERVER_BATCH_LIMIT recent uncompressed observations
541
+ * 2. Call Anthropic LLM with Observer prompt
542
+ * 3. Parse response as ObserverNote[]
543
+ * 4. Store each note as brain_observation with source='observer-compressed'
544
+ * 5. Add graph edges linking compressed notes → source observation IDs
545
+ *
546
+ * Always best-effort — errors are caught and logged, never thrown.
547
+ *
548
+ * @param projectRoot - Absolute path to project root.
549
+ * @param sessionId - Current CLEO session ID (used to scope observation query).
550
+ * @returns ObserverResult with counts and note details.
551
+ */
552
+ export async function runObserver(
553
+ projectRoot: string,
554
+ sessionId?: string,
555
+ ): Promise<ObserverResult> {
556
+ const empty: ObserverResult = { ran: false, stored: 0, compressedIds: [], notes: [] };
557
+
558
+ // Gate 1: API key must be present
559
+ const { resolveAnthropicApiKey: resolveKey } = await import('./anthropic-key-resolver.js');
560
+ if (!resolveKey()) return empty;
561
+
562
+ // Gate 2: Configuration must allow observer
563
+ const cfg = await loadObserverConfig(projectRoot);
564
+ if (!cfg.enabled) return empty;
565
+
566
+ // Gate 3: Ensure brain.db is initialized
567
+ try {
568
+ const { getBrainDb } = await import('../store/brain-sqlite.js');
569
+ await getBrainDb(projectRoot);
570
+ } catch {
571
+ return empty;
572
+ }
573
+
574
+ // Gate 4: Threshold check
575
+ const count = countSessionObservations(sessionId);
576
+ if (count < cfg.threshold) return empty;
577
+
578
+ // Fetch input observations
579
+ const observations = fetchSessionObservations(sessionId, OBSERVER_BATCH_LIMIT);
580
+ if (observations.length < 2) return empty;
581
+
582
+ // Build the user message: list of observation records
583
+ const observationList = observations
584
+ .map(
585
+ (obs) =>
586
+ `[${obs.id}] ${obs.created_at ?? 'unknown'}: ${obs.title ?? ''} — ${(obs.narrative ?? '').slice(0, 200)}`,
587
+ )
588
+ .join('\n');
589
+
590
+ const userContent = `Recent observations to compress (${observations.length} entries):\n\n${observationList}`;
591
+
592
+ // Call LLM
593
+ const rawResponse = await callAnthropicLlm(OBSERVER_SYSTEM_PROMPT, userContent);
594
+ if (!rawResponse) return empty;
595
+
596
+ // Parse response
597
+ const notes = parseJsonResponse<ObserverNote[]>(rawResponse);
598
+ if (!notes || !Array.isArray(notes) || notes.length === 0) {
599
+ console.warn('[observer-reflector] Observer: failed to parse LLM response as ObserverNote[]');
600
+ return empty;
601
+ }
602
+
603
+ // Validate and store notes
604
+ let stored = 0;
605
+ const compressedIds: string[] = [];
606
+
607
+ for (const note of notes) {
608
+ // Basic structural validation
609
+ if (
610
+ typeof note.observation !== 'string' ||
611
+ !note.observation ||
612
+ !Array.isArray(note.source_ids)
613
+ ) {
614
+ continue;
615
+ }
616
+
617
+ const id = storeObserverNote(projectRoot, note, sessionId);
618
+ if (id !== null) {
619
+ stored++;
620
+ compressedIds.push(...note.source_ids);
621
+ }
622
+ }
623
+
624
+ return {
625
+ ran: true,
626
+ stored,
627
+ compressedIds: [...new Set(compressedIds)],
628
+ notes,
629
+ };
630
+ }
631
+
632
+ // ============================================================================
633
+ // Reflector
634
+ // ============================================================================
635
+
636
+ /** System prompt for the Reflector LLM call. */
637
+ const REFLECTOR_SYSTEM_PROMPT = `You are restructuring accumulated observations from a coding agent session into durable knowledge.
638
+ Input: observation notes from the session (both raw and observer-compressed).
639
+ Output: extracted patterns + learnings.
640
+
641
+ Rules:
642
+ - Combine related observations into single insights
643
+ - Identify cross-cutting patterns (3+ similar events)
644
+ - Drop observations superseded by later ones (list their IDs in "superseded")
645
+ - Preserve ALL architectural decisions and their rationale
646
+ - Preserve ALL discovered constraints and bugs with root causes
647
+ - Add cross-cutting insights that emerge from the full picture
648
+
649
+ Format: JSON object with keys:
650
+ - patterns: array of { pattern: string (≤300 chars), context: string (≤150 chars) }
651
+ - learnings: array of { insight: string (≤300 chars), confidence: number 0.0-1.0 }
652
+ - superseded: array of observation IDs (strings) that are now redundant
653
+
654
+ ONLY return valid JSON, no markdown fences or extra text.
655
+ Maximum 5 patterns, 5 learnings. Quality over quantity.`;
656
+
657
+ /**
658
+ * Run the Reflector on accumulated session observation notes.
659
+ *
660
+ * Triggered at session end when:
661
+ * 1. `brain.reflector.enabled` is true (default)
662
+ * 2. Sufficient observations exist to reflect on (≥ 3)
663
+ * 3. `ANTHROPIC_API_KEY` is set in the environment
664
+ *
665
+ * Steps:
666
+ * 1. Fetch recent observations (raw + observer-compressed) for the session
667
+ * 2. Call Anthropic LLM with Reflector prompt
668
+ * 3. Parse response as { patterns, learnings, superseded }
669
+ * 4. Store patterns via storePattern()
670
+ * 5. Store learnings via storeLearning()
671
+ * 6. Mark superseded observations as invalid (soft-evict)
672
+ *
673
+ * Always best-effort — errors are caught and logged, never thrown.
674
+ *
675
+ * @param projectRoot - Absolute path to project root.
676
+ * @param sessionId - Current CLEO session ID.
677
+ * @returns ReflectorResult with counts.
678
+ */
679
+ export async function runReflector(
680
+ projectRoot: string,
681
+ sessionId?: string,
682
+ ): Promise<ReflectorResult> {
683
+ const empty: ReflectorResult = {
684
+ ran: false,
685
+ patternsStored: 0,
686
+ learningsStored: 0,
687
+ supersededIds: [],
688
+ };
689
+
690
+ // Gate 1: API key must be present
691
+ const { resolveAnthropicApiKey: resolveKey } = await import('./anthropic-key-resolver.js');
692
+ if (!resolveKey()) return empty;
693
+
694
+ // Gate 2: Configuration must allow reflector
695
+ const cfg = await loadReflectorConfig(projectRoot);
696
+ if (!cfg.enabled) return empty;
697
+
698
+ // Gate 3: Ensure brain.db is initialized
699
+ try {
700
+ const { getBrainDb } = await import('../store/brain-sqlite.js');
701
+ await getBrainDb(projectRoot);
702
+ } catch {
703
+ return empty;
704
+ }
705
+
706
+ // Fetch ALL recent session observations (both raw and compressed)
707
+ // for reflector to synthesize across
708
+ const nativeDb = getBrainNativeDb();
709
+ if (!nativeDb) return empty;
710
+
711
+ let observations: RawObservationRow[] = [];
712
+ try {
713
+ const cutoff = new Date(Date.now() - 48 * 60 * 60 * 1000)
714
+ .toISOString()
715
+ .replace('T', ' ')
716
+ .slice(0, 19);
717
+
718
+ if (sessionId) {
719
+ observations = nativeDb
720
+ .prepare(
721
+ `
722
+ SELECT id, type, title, narrative, created_at, source_type
723
+ FROM brain_observations
724
+ WHERE source_session_id = ?
725
+ AND invalid_at IS NULL
726
+ ORDER BY created_at DESC
727
+ LIMIT 50
728
+ `,
729
+ )
730
+ .all(sessionId) as unknown as RawObservationRow[];
731
+ }
732
+
733
+ if (observations.length < 3) {
734
+ // Fallback: last 48 hours
735
+ observations = nativeDb
736
+ .prepare(
737
+ `
738
+ SELECT id, type, title, narrative, created_at, source_type
739
+ FROM brain_observations
740
+ WHERE created_at >= ?
741
+ AND invalid_at IS NULL
742
+ ORDER BY created_at DESC
743
+ LIMIT 50
744
+ `,
745
+ )
746
+ .all(cutoff) as unknown as RawObservationRow[];
747
+ }
748
+ } catch {
749
+ return empty;
750
+ }
751
+
752
+ if (observations.length < 3) return empty;
753
+
754
+ // Build user message
755
+ const obsList = observations
756
+ .map(
757
+ (obs) =>
758
+ `[${obs.id}] (${obs.source_type ?? 'raw'}): ${obs.title ?? ''} — ${(obs.narrative ?? '').slice(0, 200)}`,
759
+ )
760
+ .join('\n');
761
+
762
+ const userContent = `Session observations to synthesize (${observations.length} entries):\n\n${obsList}`;
763
+
764
+ // Call LLM
765
+ const rawResponse = await callAnthropicLlm(REFLECTOR_SYSTEM_PROMPT, userContent);
766
+ if (!rawResponse) return empty;
767
+
768
+ // Parse response
769
+ const output = parseJsonResponse<ReflectorOutput>(rawResponse);
770
+ if (!output || typeof output !== 'object') {
771
+ console.warn('[observer-reflector] Reflector: failed to parse LLM response');
772
+ return empty;
773
+ }
774
+
775
+ let patternsStored = 0;
776
+ let learningsStored = 0;
777
+
778
+ // Store patterns
779
+ if (Array.isArray(output.patterns)) {
780
+ for (const p of output.patterns) {
781
+ if (typeof p.pattern !== 'string' || !p.pattern) continue;
782
+ try {
783
+ await storePattern(projectRoot, {
784
+ type: 'workflow',
785
+ pattern: p.pattern.slice(0, 500),
786
+ context: (p.context ?? '').slice(0, 200),
787
+ source: REFLECTOR_SOURCE,
788
+ });
789
+ patternsStored++;
790
+ } catch {
791
+ /* best-effort */
792
+ }
793
+ }
794
+ }
795
+
796
+ // Store learnings
797
+ if (Array.isArray(output.learnings)) {
798
+ for (const l of output.learnings) {
799
+ if (typeof l.insight !== 'string' || !l.insight) continue;
800
+ const confidence =
801
+ typeof l.confidence === 'number' ? Math.max(0.1, Math.min(1.0, l.confidence)) : 0.7;
802
+ try {
803
+ await storeLearning(projectRoot, {
804
+ insight: l.insight.slice(0, 500),
805
+ source: REFLECTOR_SOURCE,
806
+ confidence,
807
+ actionable: confidence >= 0.7,
808
+ });
809
+ learningsStored++;
810
+ } catch {
811
+ /* best-effort */
812
+ }
813
+ }
814
+ }
815
+
816
+ // Mark superseded observations
817
+ const supersededIds = Array.isArray(output.superseded)
818
+ ? output.superseded.filter((id): id is string => typeof id === 'string')
819
+ : [];
820
+
821
+ markSuperseded(supersededIds);
822
+
823
+ return {
824
+ ran: true,
825
+ patternsStored,
826
+ learningsStored,
827
+ supersededIds,
828
+ };
829
+ }