@gencode/agents 0.0.9 → 0.0.11

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 (451) hide show
  1. package/dist/builtin-provider-C0d7-NZt.js +66 -0
  2. package/dist/config/index.d.ts +2 -9
  3. package/dist/config/index.js +1 -9
  4. package/dist/config-DG3Q1aJ6.js +1 -0
  5. package/dist/{index-JD6Ye-N5.d.ts → index-BdfpRxFA.d.ts} +7 -8
  6. package/dist/index.d.ts +1603 -40
  7. package/dist/index.js +504 -35
  8. package/dist/provider-registry-rVbsCDN2.js +1 -0
  9. package/dist/rolldown-runtime-CNxR59P3.js +1 -0
  10. package/package.json +2 -2
  11. package/dist/bootstrap/bootstrap-layout.d.ts +0 -23
  12. package/dist/bootstrap/bootstrap-layout.d.ts.map +0 -1
  13. package/dist/bootstrap/bootstrap-layout.js +0 -151
  14. package/dist/bootstrap/bootstrap-layout.js.map +0 -1
  15. package/dist/bootstrap/bootstrap.d.ts +0 -36
  16. package/dist/bootstrap/bootstrap.d.ts.map +0 -1
  17. package/dist/bootstrap/bootstrap.js +0 -136
  18. package/dist/bootstrap/bootstrap.js.map +0 -1
  19. package/dist/bootstrap/templates/AGENTS_MD.d.ts +0 -2
  20. package/dist/bootstrap/templates/AGENTS_MD.d.ts.map +0 -1
  21. package/dist/bootstrap/templates/AGENTS_MD.js +0 -223
  22. package/dist/bootstrap/templates/AGENTS_MD.js.map +0 -1
  23. package/dist/bootstrap/templates/BOOTSTRAP_MD.d.ts +0 -2
  24. package/dist/bootstrap/templates/BOOTSTRAP_MD.d.ts.map +0 -1
  25. package/dist/bootstrap/templates/BOOTSTRAP_MD.js +0 -66
  26. package/dist/bootstrap/templates/BOOTSTRAP_MD.js.map +0 -1
  27. package/dist/bootstrap/templates/HEARTBEAT_MD.d.ts +0 -2
  28. package/dist/bootstrap/templates/HEARTBEAT_MD.d.ts.map +0 -1
  29. package/dist/bootstrap/templates/HEARTBEAT_MD.js +0 -16
  30. package/dist/bootstrap/templates/HEARTBEAT_MD.js.map +0 -1
  31. package/dist/bootstrap/templates/IDENTITY_MD.d.ts +0 -2
  32. package/dist/bootstrap/templates/IDENTITY_MD.d.ts.map +0 -1
  33. package/dist/bootstrap/templates/IDENTITY_MD.js +0 -31
  34. package/dist/bootstrap/templates/IDENTITY_MD.js.map +0 -1
  35. package/dist/bootstrap/templates/SOUL_MD.d.ts +0 -2
  36. package/dist/bootstrap/templates/SOUL_MD.d.ts.map +0 -1
  37. package/dist/bootstrap/templates/SOUL_MD.js +0 -47
  38. package/dist/bootstrap/templates/SOUL_MD.js.map +0 -1
  39. package/dist/bootstrap/templates/TOOLS_MD.d.ts +0 -2
  40. package/dist/bootstrap/templates/TOOLS_MD.d.ts.map +0 -1
  41. package/dist/bootstrap/templates/TOOLS_MD.js +0 -51
  42. package/dist/bootstrap/templates/TOOLS_MD.js.map +0 -1
  43. package/dist/bootstrap/templates/USER_MD.d.ts +0 -2
  44. package/dist/bootstrap/templates/USER_MD.d.ts.map +0 -1
  45. package/dist/bootstrap/templates/USER_MD.js +0 -27
  46. package/dist/bootstrap/templates/USER_MD.js.map +0 -1
  47. package/dist/bootstrap/templates/index.d.ts +0 -3
  48. package/dist/bootstrap/templates/index.d.ts.map +0 -1
  49. package/dist/bootstrap/templates/index.js +0 -26
  50. package/dist/bootstrap/templates/index.js.map +0 -1
  51. package/dist/commands/compact.d.ts +0 -28
  52. package/dist/commands/compact.d.ts.map +0 -1
  53. package/dist/commands/compact.js +0 -57
  54. package/dist/commands/compact.js.map +0 -1
  55. package/dist/commands/help.d.ts +0 -3
  56. package/dist/commands/help.d.ts.map +0 -1
  57. package/dist/commands/help.js +0 -50
  58. package/dist/commands/help.js.map +0 -1
  59. package/dist/commands/index.d.ts +0 -6
  60. package/dist/commands/index.d.ts.map +0 -1
  61. package/dist/commands/index.js +0 -32
  62. package/dist/commands/index.js.map +0 -1
  63. package/dist/commands/new.d.ts +0 -3
  64. package/dist/commands/new.d.ts.map +0 -1
  65. package/dist/commands/new.js +0 -15
  66. package/dist/commands/new.js.map +0 -1
  67. package/dist/commands/registry.d.ts +0 -11
  68. package/dist/commands/registry.d.ts.map +0 -1
  69. package/dist/commands/registry.js +0 -122
  70. package/dist/commands/registry.js.map +0 -1
  71. package/dist/commands/reset.d.ts +0 -3
  72. package/dist/commands/reset.d.ts.map +0 -1
  73. package/dist/commands/reset.js +0 -4
  74. package/dist/commands/reset.js.map +0 -1
  75. package/dist/commands/skill.d.ts +0 -7
  76. package/dist/commands/skill.d.ts.map +0 -1
  77. package/dist/commands/skill.js +0 -23
  78. package/dist/commands/skill.js.map +0 -1
  79. package/dist/commands/types.d.ts +0 -57
  80. package/dist/commands/types.d.ts.map +0 -1
  81. package/dist/commands/types.js +0 -2
  82. package/dist/commands/types.js.map +0 -1
  83. package/dist/config/agents-config.d.ts +0 -85
  84. package/dist/config/agents-config.d.ts.map +0 -1
  85. package/dist/config/agents-config.js +0 -257
  86. package/dist/config/agents-config.js.map +0 -1
  87. package/dist/config/index.d.ts.map +0 -1
  88. package/dist/config/index.js.map +0 -1
  89. package/dist/config/types.d.ts +0 -87
  90. package/dist/config/types.d.ts.map +0 -1
  91. package/dist/config/types.js +0 -6
  92. package/dist/config/types.js.map +0 -1
  93. package/dist/config-DJX-VM7S.js +0 -198
  94. package/dist/config-DJX-VM7S.js.map +0 -1
  95. package/dist/history/compaction.d.ts +0 -42
  96. package/dist/history/compaction.d.ts.map +0 -1
  97. package/dist/history/compaction.js +0 -135
  98. package/dist/history/compaction.js.map +0 -1
  99. package/dist/history/index.d.ts +0 -57
  100. package/dist/history/index.d.ts.map +0 -1
  101. package/dist/history/index.js +0 -145
  102. package/dist/history/index.js.map +0 -1
  103. package/dist/history/limit.d.ts +0 -13
  104. package/dist/history/limit.d.ts.map +0 -1
  105. package/dist/history/limit.js +0 -32
  106. package/dist/history/limit.js.map +0 -1
  107. package/dist/history/repair.d.ts +0 -13
  108. package/dist/history/repair.d.ts.map +0 -1
  109. package/dist/history/repair.js +0 -25
  110. package/dist/history/repair.js.map +0 -1
  111. package/dist/history/token-estimate.d.ts +0 -22
  112. package/dist/history/token-estimate.d.ts.map +0 -1
  113. package/dist/history/token-estimate.js +0 -38
  114. package/dist/history/token-estimate.js.map +0 -1
  115. package/dist/index-JD6Ye-N5.d.ts.map +0 -1
  116. package/dist/index.d.ts.map +0 -1
  117. package/dist/index.js.map +0 -1
  118. package/dist/llm/client.d.ts +0 -53
  119. package/dist/llm/client.d.ts.map +0 -1
  120. package/dist/llm/client.js +0 -214
  121. package/dist/llm/client.js.map +0 -1
  122. package/dist/llm/openai-completions-compat.d.ts +0 -23
  123. package/dist/llm/openai-completions-compat.d.ts.map +0 -1
  124. package/dist/llm/openai-completions-compat.js +0 -602
  125. package/dist/llm/openai-completions-compat.js.map +0 -1
  126. package/dist/llm/openai-stream-error.d.ts +0 -11
  127. package/dist/llm/openai-stream-error.d.ts.map +0 -1
  128. package/dist/llm/openai-stream-error.js +0 -77
  129. package/dist/llm/openai-stream-error.js.map +0 -1
  130. package/dist/loop-detection/session-state.d.ts +0 -5
  131. package/dist/loop-detection/session-state.d.ts.map +0 -1
  132. package/dist/loop-detection/session-state.js +0 -16
  133. package/dist/loop-detection/session-state.js.map +0 -1
  134. package/dist/loop-detection/tool-loop-detection.d.ts +0 -122
  135. package/dist/loop-detection/tool-loop-detection.d.ts.map +0 -1
  136. package/dist/loop-detection/tool-loop-detection.js +0 -516
  137. package/dist/loop-detection/tool-loop-detection.js.map +0 -1
  138. package/dist/manager-qXa-NP0p.js +0 -1651
  139. package/dist/manager-qXa-NP0p.js.map +0 -1
  140. package/dist/memory/builtin-provider.d.ts +0 -5
  141. package/dist/memory/builtin-provider.d.ts.map +0 -1
  142. package/dist/memory/builtin-provider.js +0 -42
  143. package/dist/memory/builtin-provider.js.map +0 -1
  144. package/dist/memory/config.d.ts +0 -50
  145. package/dist/memory/config.d.ts.map +0 -1
  146. package/dist/memory/config.js +0 -46
  147. package/dist/memory/config.js.map +0 -1
  148. package/dist/memory/embedding-registry.d.ts +0 -37
  149. package/dist/memory/embedding-registry.d.ts.map +0 -1
  150. package/dist/memory/embedding-registry.js +0 -56
  151. package/dist/memory/embedding-registry.js.map +0 -1
  152. package/dist/memory/embeddings.d.ts +0 -11
  153. package/dist/memory/embeddings.d.ts.map +0 -1
  154. package/dist/memory/embeddings.js +0 -40
  155. package/dist/memory/embeddings.js.map +0 -1
  156. package/dist/memory/fs-utils.d.ts +0 -12
  157. package/dist/memory/fs-utils.d.ts.map +0 -1
  158. package/dist/memory/fs-utils.js +0 -24
  159. package/dist/memory/fs-utils.js.map +0 -1
  160. package/dist/memory/hybrid.d.ts +0 -43
  161. package/dist/memory/hybrid.d.ts.map +0 -1
  162. package/dist/memory/hybrid.js +0 -80
  163. package/dist/memory/hybrid.js.map +0 -1
  164. package/dist/memory/internal.d.ts +0 -28
  165. package/dist/memory/internal.d.ts.map +0 -1
  166. package/dist/memory/internal.js +0 -270
  167. package/dist/memory/internal.js.map +0 -1
  168. package/dist/memory/manager-search.d.ts +0 -61
  169. package/dist/memory/manager-search.d.ts.map +0 -1
  170. package/dist/memory/manager-search.js +0 -106
  171. package/dist/memory/manager-search.js.map +0 -1
  172. package/dist/memory/manager.d.ts +0 -126
  173. package/dist/memory/manager.d.ts.map +0 -1
  174. package/dist/memory/manager.js +0 -1006
  175. package/dist/memory/manager.js.map +0 -1
  176. package/dist/memory/memory-schema.d.ts +0 -11
  177. package/dist/memory/memory-schema.d.ts.map +0 -1
  178. package/dist/memory/memory-schema.js +0 -78
  179. package/dist/memory/memory-schema.js.map +0 -1
  180. package/dist/memory/memory.d.ts +0 -46
  181. package/dist/memory/memory.d.ts.map +0 -1
  182. package/dist/memory/memory.js +0 -127
  183. package/dist/memory/memory.js.map +0 -1
  184. package/dist/memory/mmr.d.ts +0 -22
  185. package/dist/memory/mmr.d.ts.map +0 -1
  186. package/dist/memory/mmr.js +0 -112
  187. package/dist/memory/mmr.js.map +0 -1
  188. package/dist/memory/provider-registry.d.ts +0 -29
  189. package/dist/memory/provider-registry.d.ts.map +0 -1
  190. package/dist/memory/provider-registry.js +0 -58
  191. package/dist/memory/provider-registry.js.map +0 -1
  192. package/dist/memory/provider.d.ts +0 -40
  193. package/dist/memory/provider.d.ts.map +0 -1
  194. package/dist/memory/provider.js +0 -2
  195. package/dist/memory/provider.js.map +0 -1
  196. package/dist/memory/session-files.d.ts +0 -13
  197. package/dist/memory/session-files.d.ts.map +0 -1
  198. package/dist/memory/session-files.js +0 -116
  199. package/dist/memory/session-files.js.map +0 -1
  200. package/dist/memory/sqlite-vec.d.ts +0 -10
  201. package/dist/memory/sqlite-vec.d.ts.map +0 -1
  202. package/dist/memory/sqlite-vec.js +0 -20
  203. package/dist/memory/sqlite-vec.js.map +0 -1
  204. package/dist/memory/sqlite.d.ts +0 -2
  205. package/dist/memory/sqlite.d.ts.map +0 -1
  206. package/dist/memory/sqlite.js +0 -12
  207. package/dist/memory/sqlite.js.map +0 -1
  208. package/dist/memory/temporal-decay.d.ts +0 -26
  209. package/dist/memory/temporal-decay.d.ts.map +0 -1
  210. package/dist/memory/temporal-decay.js +0 -119
  211. package/dist/memory/temporal-decay.js.map +0 -1
  212. package/dist/memory/watch-bridge.d.ts +0 -20
  213. package/dist/memory/watch-bridge.d.ts.map +0 -1
  214. package/dist/memory/watch-bridge.js +0 -128
  215. package/dist/memory/watch-bridge.js.map +0 -1
  216. package/dist/message.d.ts +0 -11
  217. package/dist/message.d.ts.map +0 -1
  218. package/dist/message.js +0 -46
  219. package/dist/message.js.map +0 -1
  220. package/dist/plugins/boundary-file-read.d.ts +0 -13
  221. package/dist/plugins/boundary-file-read.d.ts.map +0 -1
  222. package/dist/plugins/boundary-file-read.js +0 -31
  223. package/dist/plugins/boundary-file-read.js.map +0 -1
  224. package/dist/plugins/config-state.d.ts +0 -35
  225. package/dist/plugins/config-state.d.ts.map +0 -1
  226. package/dist/plugins/config-state.js +0 -97
  227. package/dist/plugins/config-state.js.map +0 -1
  228. package/dist/plugins/discovery.d.ts +0 -21
  229. package/dist/plugins/discovery.d.ts.map +0 -1
  230. package/dist/plugins/discovery.js +0 -425
  231. package/dist/plugins/discovery.js.map +0 -1
  232. package/dist/plugins/hooks.d.ts +0 -133
  233. package/dist/plugins/hooks.d.ts.map +0 -1
  234. package/dist/plugins/hooks.js +0 -19
  235. package/dist/plugins/hooks.js.map +0 -1
  236. package/dist/plugins/index.d.ts +0 -20
  237. package/dist/plugins/index.d.ts.map +0 -1
  238. package/dist/plugins/index.js +0 -11
  239. package/dist/plugins/index.js.map +0 -1
  240. package/dist/plugins/loader.d.ts +0 -60
  241. package/dist/plugins/loader.d.ts.map +0 -1
  242. package/dist/plugins/loader.js +0 -224
  243. package/dist/plugins/loader.js.map +0 -1
  244. package/dist/plugins/manager.d.ts +0 -20
  245. package/dist/plugins/manager.d.ts.map +0 -1
  246. package/dist/plugins/manager.js +0 -33
  247. package/dist/plugins/manager.js.map +0 -1
  248. package/dist/plugins/manifest-registry.d.ts +0 -15
  249. package/dist/plugins/manifest-registry.d.ts.map +0 -1
  250. package/dist/plugins/manifest-registry.js +0 -37
  251. package/dist/plugins/manifest-registry.js.map +0 -1
  252. package/dist/plugins/manifest.d.ts +0 -6
  253. package/dist/plugins/manifest.d.ts.map +0 -1
  254. package/dist/plugins/manifest.js +0 -80
  255. package/dist/plugins/manifest.js.map +0 -1
  256. package/dist/plugins/path-safety.d.ts +0 -6
  257. package/dist/plugins/path-safety.d.ts.map +0 -1
  258. package/dist/plugins/path-safety.js +0 -32
  259. package/dist/plugins/path-safety.js.map +0 -1
  260. package/dist/plugins/runtime-context.d.ts +0 -12
  261. package/dist/plugins/runtime-context.d.ts.map +0 -1
  262. package/dist/plugins/runtime-context.js +0 -2
  263. package/dist/plugins/runtime-context.js.map +0 -1
  264. package/dist/plugins/runtime.d.ts +0 -20
  265. package/dist/plugins/runtime.d.ts.map +0 -1
  266. package/dist/plugins/runtime.js +0 -33
  267. package/dist/plugins/runtime.js.map +0 -1
  268. package/dist/plugins/schema-validator.d.ts +0 -17
  269. package/dist/plugins/schema-validator.d.ts.map +0 -1
  270. package/dist/plugins/schema-validator.js +0 -26
  271. package/dist/plugins/schema-validator.js.map +0 -1
  272. package/dist/plugins/tool-hooks.d.ts +0 -4
  273. package/dist/plugins/tool-hooks.d.ts.map +0 -1
  274. package/dist/plugins/tool-hooks.js +0 -63
  275. package/dist/plugins/tool-hooks.js.map +0 -1
  276. package/dist/plugins/tools.d.ts +0 -20
  277. package/dist/plugins/tools.d.ts.map +0 -1
  278. package/dist/plugins/tools.js +0 -42
  279. package/dist/plugins/tools.js.map +0 -1
  280. package/dist/plugins/types.d.ts +0 -61
  281. package/dist/plugins/types.d.ts.map +0 -1
  282. package/dist/plugins/types.js +0 -2
  283. package/dist/plugins/types.js.map +0 -1
  284. package/dist/plugins/utils.d.ts +0 -4
  285. package/dist/plugins/utils.d.ts.map +0 -1
  286. package/dist/plugins/utils.js +0 -22
  287. package/dist/plugins/utils.js.map +0 -1
  288. package/dist/runner/agent-runtime.d.ts +0 -62
  289. package/dist/runner/agent-runtime.d.ts.map +0 -1
  290. package/dist/runner/agent-runtime.js +0 -186
  291. package/dist/runner/agent-runtime.js.map +0 -1
  292. package/dist/runner/announce-loop.d.ts +0 -41
  293. package/dist/runner/announce-loop.d.ts.map +0 -1
  294. package/dist/runner/announce-loop.js +0 -94
  295. package/dist/runner/announce-loop.js.map +0 -1
  296. package/dist/runner/event-dispatcher.d.ts +0 -12
  297. package/dist/runner/event-dispatcher.d.ts.map +0 -1
  298. package/dist/runner/event-dispatcher.js +0 -18
  299. package/dist/runner/event-dispatcher.js.map +0 -1
  300. package/dist/runner/finalizer.d.ts +0 -30
  301. package/dist/runner/finalizer.d.ts.map +0 -1
  302. package/dist/runner/finalizer.js +0 -75
  303. package/dist/runner/finalizer.js.map +0 -1
  304. package/dist/runner/invocation-resolver.d.ts +0 -67
  305. package/dist/runner/invocation-resolver.d.ts.map +0 -1
  306. package/dist/runner/invocation-resolver.js +0 -224
  307. package/dist/runner/invocation-resolver.js.map +0 -1
  308. package/dist/runner/plugin-context.d.ts +0 -18
  309. package/dist/runner/plugin-context.d.ts.map +0 -1
  310. package/dist/runner/plugin-context.js +0 -26
  311. package/dist/runner/plugin-context.js.map +0 -1
  312. package/dist/runner/run-context.d.ts +0 -38
  313. package/dist/runner/run-context.d.ts.map +0 -1
  314. package/dist/runner/run-context.js +0 -159
  315. package/dist/runner/run-context.js.map +0 -1
  316. package/dist/runner/runner-session.d.ts +0 -34
  317. package/dist/runner/runner-session.d.ts.map +0 -1
  318. package/dist/runner/runner-session.js +0 -61
  319. package/dist/runner/runner-session.js.map +0 -1
  320. package/dist/runner/runner.d.ts +0 -13
  321. package/dist/runner/runner.d.ts.map +0 -1
  322. package/dist/runner/runner.js +0 -234
  323. package/dist/runner/runner.js.map +0 -1
  324. package/dist/runner/runtime.d.ts +0 -7
  325. package/dist/runner/runtime.d.ts.map +0 -1
  326. package/dist/runner/runtime.js +0 -21
  327. package/dist/runner/runtime.js.map +0 -1
  328. package/dist/runner/session-lifecycle.d.ts +0 -31
  329. package/dist/runner/session-lifecycle.d.ts.map +0 -1
  330. package/dist/runner/session-lifecycle.js +0 -38
  331. package/dist/runner/session-lifecycle.js.map +0 -1
  332. package/dist/runner/skill-usage.d.ts +0 -29
  333. package/dist/runner/skill-usage.d.ts.map +0 -1
  334. package/dist/runner/skill-usage.js +0 -65
  335. package/dist/runner/skill-usage.js.map +0 -1
  336. package/dist/runner/title.d.ts +0 -3
  337. package/dist/runner/title.d.ts.map +0 -1
  338. package/dist/runner/title.js +0 -6
  339. package/dist/runner/title.js.map +0 -1
  340. package/dist/runner/turn-executor.d.ts +0 -51
  341. package/dist/runner/turn-executor.d.ts.map +0 -1
  342. package/dist/runner/turn-executor.js +0 -294
  343. package/dist/runner/turn-executor.js.map +0 -1
  344. package/dist/security/command-dangerous-rules.d.ts +0 -4
  345. package/dist/security/command-dangerous-rules.d.ts.map +0 -1
  346. package/dist/security/command-dangerous-rules.js +0 -26
  347. package/dist/security/command-dangerous-rules.js.map +0 -1
  348. package/dist/security/command-parser.d.ts +0 -3
  349. package/dist/security/command-parser.d.ts.map +0 -1
  350. package/dist/security/command-parser.js +0 -191
  351. package/dist/security/command-parser.js.map +0 -1
  352. package/dist/security/command-path-guard.d.ts +0 -10
  353. package/dist/security/command-path-guard.d.ts.map +0 -1
  354. package/dist/security/command-path-guard.js +0 -126
  355. package/dist/security/command-path-guard.js.map +0 -1
  356. package/dist/security/command-policy-config.d.ts +0 -5
  357. package/dist/security/command-policy-config.d.ts.map +0 -1
  358. package/dist/security/command-policy-config.js +0 -212
  359. package/dist/security/command-policy-config.js.map +0 -1
  360. package/dist/security/command-policy-engine.d.ts +0 -8
  361. package/dist/security/command-policy-engine.d.ts.map +0 -1
  362. package/dist/security/command-policy-engine.js +0 -122
  363. package/dist/security/command-policy-engine.js.map +0 -1
  364. package/dist/security/command-policy-types.d.ts +0 -67
  365. package/dist/security/command-policy-types.d.ts.map +0 -1
  366. package/dist/security/command-policy-types.js +0 -2
  367. package/dist/security/command-policy-types.js.map +0 -1
  368. package/dist/security/command-safe-bins.d.ts +0 -4
  369. package/dist/security/command-safe-bins.d.ts.map +0 -1
  370. package/dist/security/command-safe-bins.js +0 -84
  371. package/dist/security/command-safe-bins.js.map +0 -1
  372. package/dist/security/command-trusted-executables.d.ts +0 -6
  373. package/dist/security/command-trusted-executables.d.ts.map +0 -1
  374. package/dist/security/command-trusted-executables.js +0 -57
  375. package/dist/security/command-trusted-executables.js.map +0 -1
  376. package/dist/session/session.d.ts +0 -45
  377. package/dist/session/session.d.ts.map +0 -1
  378. package/dist/session/session.js +0 -167
  379. package/dist/session/session.js.map +0 -1
  380. package/dist/skills/skills.d.ts +0 -23
  381. package/dist/skills/skills.d.ts.map +0 -1
  382. package/dist/skills/skills.js +0 -109
  383. package/dist/skills/skills.js.map +0 -1
  384. package/dist/subagent/registry-persist.d.ts +0 -31
  385. package/dist/subagent/registry-persist.d.ts.map +0 -1
  386. package/dist/subagent/registry-persist.js +0 -115
  387. package/dist/subagent/registry-persist.js.map +0 -1
  388. package/dist/subagent/registry.d.ts +0 -52
  389. package/dist/subagent/registry.d.ts.map +0 -1
  390. package/dist/subagent/registry.js +0 -122
  391. package/dist/subagent/registry.js.map +0 -1
  392. package/dist/subagent/types.d.ts +0 -20
  393. package/dist/subagent/types.d.ts.map +0 -1
  394. package/dist/subagent/types.js +0 -2
  395. package/dist/subagent/types.js.map +0 -1
  396. package/dist/system-prompt/builder.d.ts +0 -50
  397. package/dist/system-prompt/builder.d.ts.map +0 -1
  398. package/dist/system-prompt/builder.js +0 -335
  399. package/dist/system-prompt/builder.js.map +0 -1
  400. package/dist/tools/apply-patch.d.ts +0 -15
  401. package/dist/tools/apply-patch.d.ts.map +0 -1
  402. package/dist/tools/apply-patch.js +0 -425
  403. package/dist/tools/apply-patch.js.map +0 -1
  404. package/dist/tools/bash.d.ts +0 -11
  405. package/dist/tools/bash.d.ts.map +0 -1
  406. package/dist/tools/bash.js +0 -13
  407. package/dist/tools/bash.js.map +0 -1
  408. package/dist/tools/cron.d.ts +0 -30
  409. package/dist/tools/cron.d.ts.map +0 -1
  410. package/dist/tools/cron.js +0 -57
  411. package/dist/tools/cron.js.map +0 -1
  412. package/dist/tools/exec.d.ts +0 -18
  413. package/dist/tools/exec.d.ts.map +0 -1
  414. package/dist/tools/exec.js +0 -144
  415. package/dist/tools/exec.js.map +0 -1
  416. package/dist/tools/files.d.ts +0 -37
  417. package/dist/tools/files.d.ts.map +0 -1
  418. package/dist/tools/files.js +0 -191
  419. package/dist/tools/files.js.map +0 -1
  420. package/dist/tools/image.d.ts +0 -14
  421. package/dist/tools/image.d.ts.map +0 -1
  422. package/dist/tools/image.js +0 -26
  423. package/dist/tools/image.js.map +0 -1
  424. package/dist/tools/index.d.ts +0 -36
  425. package/dist/tools/index.d.ts.map +0 -1
  426. package/dist/tools/index.js +0 -53
  427. package/dist/tools/index.js.map +0 -1
  428. package/dist/tools/memory.d.ts +0 -41
  429. package/dist/tools/memory.d.ts.map +0 -1
  430. package/dist/tools/memory.js +0 -114
  431. package/dist/tools/memory.js.map +0 -1
  432. package/dist/tools/process-registry.d.ts +0 -47
  433. package/dist/tools/process-registry.d.ts.map +0 -1
  434. package/dist/tools/process-registry.js +0 -262
  435. package/dist/tools/process-registry.js.map +0 -1
  436. package/dist/tools/process.d.ts +0 -17
  437. package/dist/tools/process.d.ts.map +0 -1
  438. package/dist/tools/process.js +0 -114
  439. package/dist/tools/process.js.map +0 -1
  440. package/dist/tools/subagent-spawn.d.ts +0 -44
  441. package/dist/tools/subagent-spawn.d.ts.map +0 -1
  442. package/dist/tools/subagent-spawn.js +0 -101
  443. package/dist/tools/subagent-spawn.js.map +0 -1
  444. package/dist/tools/subagents.d.ts +0 -30
  445. package/dist/tools/subagents.d.ts.map +0 -1
  446. package/dist/tools/subagents.js +0 -101
  447. package/dist/tools/subagents.js.map +0 -1
  448. package/dist/types.d.ts +0 -153
  449. package/dist/types.d.ts.map +0 -1
  450. package/dist/types.js +0 -6
  451. package/dist/types.js.map +0 -1
@@ -1,1006 +0,0 @@
1
- import fs from "node:fs/promises";
2
- import fsSync from "node:fs";
3
- import path from "node:path";
4
- import { createMockEmbeddingProvider } from "./embeddings.js";
5
- import { resolveEmbeddingProvider } from "./embedding-registry.js";
6
- import { isFileMissingError, statRegularFile } from "./fs-utils.js";
7
- import { buildFileEntry, chunkMarkdown, ensureDir, hashText, isMemoryPath, listMemoryFiles, parseEmbedding, remapChunkLines, } from "./internal.js";
8
- import { bm25RankToScore, buildFtsQuery, mergeHybridResults } from "./hybrid.js";
9
- import { ensureMemoryIndexSchema } from "./memory-schema.js";
10
- import { searchKeyword, searchVector } from "./manager-search.js";
11
- import { requireNodeSqlite } from "./sqlite.js";
12
- import { DEFAULT_MEMORY_SEARCH_CONFIG } from "./config.js";
13
- import { loadSqliteVecExtension } from "./sqlite-vec.js";
14
- import { buildSessionEntry, listSessionFilesForAgent } from "./session-files.js";
15
- const SNIPPET_MAX_CHARS = 700;
16
- const VECTOR_TABLE = "chunks_vec";
17
- const FTS_TABLE = "chunks_fts";
18
- const EMBEDDING_CACHE_TABLE = "embedding_cache";
19
- const META_KEY = "memory_index_meta_v1";
20
- const VECTOR_LOAD_TIMEOUT_MS = 30_000;
21
- const MANAGER_CACHE = new Map();
22
- function resolveConfig(base, override) {
23
- const config = {
24
- ...base,
25
- ...override,
26
- hybrid: { ...base.hybrid, ...(override?.hybrid ?? {}) },
27
- cache: { ...base.cache, ...(override?.cache ?? {}) },
28
- sync: { ...base.sync, ...(override?.sync ?? {}) },
29
- experimental: { ...base.experimental, ...(override?.experimental ?? {}) },
30
- sources: override?.sources ?? base.sources,
31
- embedding: { ...base.embedding, ...(override?.embedding ?? {}) },
32
- store: {
33
- ...base.store,
34
- ...(override?.store ?? {}),
35
- vector: { ...base.store.vector, ...(override?.store?.vector ?? {}) },
36
- },
37
- };
38
- if (config.experimental.sessionMemory && !config.sources.includes("sessions")) {
39
- config.sources = [...config.sources, "sessions"];
40
- }
41
- return config;
42
- }
43
- export class MemoryIndexManager {
44
- dataDir;
45
- memoryRoot;
46
- storePath;
47
- config;
48
- provider;
49
- providerKey;
50
- embeddingProviderId;
51
- db;
52
- dirty = true;
53
- ftsAvailable = false;
54
- ftsError;
55
- vector = {
56
- enabled: true,
57
- available: null,
58
- extensionPath: undefined,
59
- loadError: undefined,
60
- dims: undefined,
61
- };
62
- vectorReady = null;
63
- watchers = [];
64
- watchTimer = null;
65
- sessionWatchTimer = null;
66
- sessionsDirty = false;
67
- sessionsDirtyFiles = new Set();
68
- sessionPendingFiles = new Set();
69
- sessionDeltas = new Map();
70
- static get(dataDir, config) {
71
- const memoryRoot = path.join(dataDir, ".aimax");
72
- const existing = MANAGER_CACHE.get(memoryRoot);
73
- if (existing) {
74
- if (config) {
75
- existing.applyConfig(config);
76
- }
77
- return existing;
78
- }
79
- const manager = new MemoryIndexManager(dataDir, memoryRoot, config);
80
- MANAGER_CACHE.set(memoryRoot, manager);
81
- return manager;
82
- }
83
- constructor(dataDir, memoryRoot, config) {
84
- this.dataDir = dataDir;
85
- this.memoryRoot = memoryRoot;
86
- this.storePath = path.join(memoryRoot, ".index.sqlite");
87
- this.config = resolveConfig(DEFAULT_MEMORY_SEARCH_CONFIG, config);
88
- this.provider = createMockEmbeddingProvider();
89
- this.providerKey = this.computeProviderKey();
90
- this.applyEmbeddingProvider();
91
- this.vector.enabled = this.config.store.vector.enabled;
92
- this.vector.extensionPath = this.config.store.vector.extensionPath;
93
- this.db = this.openDatabase();
94
- this.ensureSchema();
95
- this.ensureWatcher();
96
- this.ensureSessionListener();
97
- this.dirty = true;
98
- }
99
- applyConfig(config) {
100
- this.config = resolveConfig(this.config, config);
101
- this.applyEmbeddingProvider();
102
- this.vector.enabled = this.config.store.vector.enabled;
103
- this.vector.extensionPath = this.config.store.vector.extensionPath;
104
- this.ensureWatcher();
105
- this.ensureSessionListener();
106
- }
107
- warmSession() {
108
- if (!this.config.sync.onSessionStart) {
109
- return;
110
- }
111
- void this.sync({ reason: "session-start" }).catch(() => { });
112
- }
113
- noteSessionUpdate(sessionFile) {
114
- this.scheduleSessionDirty(sessionFile);
115
- }
116
- status() {
117
- const sourceFilter = this.buildSourceFilter();
118
- const files = this.db
119
- .prepare(`SELECT COUNT(*) as c FROM files WHERE 1=1${sourceFilter.sql}`)
120
- .get(...sourceFilter.params);
121
- const chunks = this.db
122
- .prepare(`SELECT COUNT(*) as c FROM chunks WHERE 1=1${sourceFilter.sql}`)
123
- .get(...sourceFilter.params);
124
- const sourceCounts = (() => {
125
- const sources = Array.from(this.config.sources);
126
- if (sources.length === 0) {
127
- return [];
128
- }
129
- const bySource = new Map();
130
- for (const source of sources) {
131
- bySource.set(source, { files: 0, chunks: 0 });
132
- }
133
- const fileRows = this.db
134
- .prepare(`SELECT source, COUNT(*) as c FROM files WHERE 1=1${sourceFilter.sql} GROUP BY source`)
135
- .all(...sourceFilter.params);
136
- for (const row of fileRows) {
137
- const entry = bySource.get(row.source) ?? { files: 0, chunks: 0 };
138
- entry.files = row.c ?? 0;
139
- bySource.set(row.source, entry);
140
- }
141
- const chunkRows = this.db
142
- .prepare(`SELECT source, COUNT(*) as c FROM chunks WHERE 1=1${sourceFilter.sql} GROUP BY source`)
143
- .all(...sourceFilter.params);
144
- for (const row of chunkRows) {
145
- const entry = bySource.get(row.source) ?? { files: 0, chunks: 0 };
146
- entry.chunks = row.c ?? 0;
147
- bySource.set(row.source, entry);
148
- }
149
- return sources.map((source) => Object.assign({ source }, bySource.get(source)));
150
- })();
151
- const searchMode = this.provider ? "hybrid" : "fts-only";
152
- const cacheEntries = this.config.cache.enabled
153
- ? this.db.prepare(`SELECT COUNT(*) as c FROM ${EMBEDDING_CACHE_TABLE}`).get()?.c ?? 0
154
- : undefined;
155
- return {
156
- backend: "builtin",
157
- files: files?.c ?? 0,
158
- chunks: chunks?.c ?? 0,
159
- dirty: this.dirty || this.sessionsDirty,
160
- workspaceDir: this.memoryRoot,
161
- dbPath: this.storePath,
162
- provider: this.provider.id,
163
- model: this.provider.model,
164
- sources: Array.from(this.config.sources),
165
- sourceCounts,
166
- cache: this.config.cache.enabled
167
- ? { enabled: true, entries: cacheEntries, maxEntries: this.config.cache.maxEntries }
168
- : { enabled: false, maxEntries: this.config.cache.maxEntries },
169
- fts: {
170
- enabled: this.config.hybrid.enabled,
171
- available: this.ftsAvailable,
172
- error: this.ftsError,
173
- },
174
- vector: {
175
- enabled: this.vector.enabled,
176
- available: this.vector.available ?? undefined,
177
- extensionPath: this.vector.extensionPath,
178
- loadError: this.vector.loadError,
179
- dims: this.vector.dims,
180
- },
181
- custom: { searchMode },
182
- };
183
- }
184
- async probeEmbeddingAvailability() {
185
- try {
186
- await this.provider.embedBatch(["ping"]);
187
- return { ok: true };
188
- }
189
- catch (err) {
190
- const message = err instanceof Error ? err.message : String(err);
191
- return { ok: false, error: message };
192
- }
193
- }
194
- async probeVectorAvailability() {
195
- if (!this.vector.enabled) {
196
- return false;
197
- }
198
- return await this.ensureVectorReady();
199
- }
200
- async search(query) {
201
- const cleaned = query.trim();
202
- if (!cleaned) {
203
- return [];
204
- }
205
- const meta = this.readMeta();
206
- if (!meta) {
207
- await this.sync({ reason: "boot" });
208
- }
209
- else if (this.config.sync.onSearch && (this.dirty || this.sessionsDirty)) {
210
- void this.sync({ reason: "search" }).catch(() => { });
211
- }
212
- const hybrid = this.config.hybrid;
213
- const candidates = Math.min(200, Math.max(1, Math.floor(this.config.maxResults * hybrid.candidateMultiplier)));
214
- const keywordResults = hybrid.enabled && this.ftsAvailable
215
- ? await this.searchKeyword(cleaned, candidates).catch(() => [])
216
- : [];
217
- const queryVec = await this.provider.embedQuery(cleaned);
218
- const hasVector = queryVec.some((v) => v !== 0);
219
- const vectorResults = hasVector
220
- ? await this.searchVector(queryVec, candidates).catch(() => [])
221
- : [];
222
- if (!hybrid.enabled || !this.ftsAvailable) {
223
- return vectorResults
224
- .filter((entry) => entry.score >= this.config.minScore)
225
- .slice(0, this.config.maxResults);
226
- }
227
- const merged = await mergeHybridResults({
228
- vector: vectorResults.map((r) => ({
229
- id: `${r.path}:${r.startLine}:${r.endLine}:${r.source}`,
230
- path: r.path,
231
- startLine: r.startLine,
232
- endLine: r.endLine,
233
- source: r.source,
234
- snippet: r.snippet,
235
- vectorScore: r.score,
236
- })),
237
- keyword: keywordResults.map((r) => ({
238
- id: `${r.path}:${r.startLine}:${r.endLine}:${r.source}`,
239
- path: r.path,
240
- startLine: r.startLine,
241
- endLine: r.endLine,
242
- source: r.source,
243
- snippet: r.snippet,
244
- textScore: r.textScore,
245
- })),
246
- vectorWeight: hybrid.vectorWeight,
247
- textWeight: hybrid.textWeight,
248
- mmr: hybrid.mmr,
249
- temporalDecay: hybrid.temporalDecay,
250
- memoryRoot: this.memoryRoot,
251
- });
252
- const strict = merged.filter((entry) => entry.score >= this.config.minScore);
253
- if (strict.length > 0 || keywordResults.length === 0) {
254
- return this.decorateCitations(strict.slice(0, this.config.maxResults));
255
- }
256
- const relaxedMinScore = Math.min(this.config.minScore, hybrid.textWeight);
257
- const relaxedResults = merged
258
- .filter((entry) => entry.score >= relaxedMinScore)
259
- .slice(0, this.config.maxResults);
260
- return this.decorateCitations(relaxedResults);
261
- }
262
- async readFile(params) {
263
- const { absPath, relPath } = this.resolveMemoryFilePath(params.relPath);
264
- const statResult = await statRegularFile(absPath);
265
- if (statResult.missing) {
266
- return { text: "", path: relPath };
267
- }
268
- let content;
269
- try {
270
- content = await fs.readFile(absPath, "utf-8");
271
- }
272
- catch (err) {
273
- if (isFileMissingError(err)) {
274
- return { text: "", path: relPath };
275
- }
276
- throw err;
277
- }
278
- if (!params.from && !params.lines) {
279
- return { text: content, path: relPath };
280
- }
281
- const lines = content.split("\n");
282
- const start = Math.max(1, params.from ?? 1);
283
- const count = Math.max(1, params.lines ?? lines.length);
284
- const slice = lines.slice(start - 1, start - 1 + count);
285
- return { text: slice.join("\n"), path: relPath };
286
- }
287
- async replaceFile(params) {
288
- const { absPath } = this.resolveMemoryFilePath(params.relPath);
289
- await fs.mkdir(path.dirname(absPath), { recursive: true });
290
- await fs.writeFile(absPath, params.content, "utf-8");
291
- this.dirty = true;
292
- }
293
- async deleteFile(relPath) {
294
- const { absPath } = this.resolveMemoryFilePath(relPath);
295
- try {
296
- await fs.unlink(absPath);
297
- }
298
- catch (err) {
299
- if (isFileMissingError(err)) {
300
- return;
301
- }
302
- throw err;
303
- }
304
- this.dirty = true;
305
- }
306
- async appendToMemory(content) {
307
- const dir = this.memoryRoot;
308
- await fs.mkdir(dir, { recursive: true });
309
- const filePath = path.join(dir, "MEMORY.md");
310
- const entry = content.endsWith("\n") ? content : `${content}\n`;
311
- await fs.appendFile(filePath, entry, "utf-8");
312
- this.dirty = true;
313
- }
314
- openDatabase() {
315
- ensureDir(path.dirname(this.storePath));
316
- const { DatabaseSync } = requireNodeSqlite();
317
- return new DatabaseSync(this.storePath, { allowExtension: this.vector.enabled });
318
- }
319
- ensureSchema() {
320
- const result = ensureMemoryIndexSchema({
321
- db: this.db,
322
- embeddingCacheTable: EMBEDDING_CACHE_TABLE,
323
- ftsTable: FTS_TABLE,
324
- ftsEnabled: this.config.hybrid.enabled,
325
- });
326
- this.ftsAvailable = result.ftsAvailable;
327
- if (result.ftsError) {
328
- this.ftsError = result.ftsError;
329
- }
330
- }
331
- async ensureVectorReady(dimensions) {
332
- if (!this.vector.enabled) {
333
- return false;
334
- }
335
- if (!this.vectorReady) {
336
- this.vectorReady = this.withTimeout(this.loadVectorExtension(), VECTOR_LOAD_TIMEOUT_MS, `sqlite-vec load timed out after ${Math.round(VECTOR_LOAD_TIMEOUT_MS / 1000)}s`);
337
- }
338
- let ready = false;
339
- try {
340
- ready = (await this.vectorReady) || false;
341
- }
342
- catch (err) {
343
- const message = err instanceof Error ? err.message : String(err);
344
- this.vector.available = false;
345
- this.vector.loadError = message;
346
- this.vectorReady = null;
347
- return false;
348
- }
349
- if (ready && typeof dimensions === "number" && dimensions > 0) {
350
- this.ensureVectorTable(dimensions);
351
- }
352
- return ready;
353
- }
354
- async loadVectorExtension() {
355
- if (this.vector.available !== null) {
356
- return this.vector.available;
357
- }
358
- if (!this.vector.enabled) {
359
- this.vector.available = false;
360
- return false;
361
- }
362
- try {
363
- const resolvedPath = this.vector.extensionPath?.trim()
364
- ? this.vector.extensionPath.trim()
365
- : undefined;
366
- const loaded = await loadSqliteVecExtension({ db: this.db, extensionPath: resolvedPath });
367
- if (!loaded.ok) {
368
- throw new Error(loaded.error ?? "unknown sqlite-vec load error");
369
- }
370
- this.vector.extensionPath = loaded.extensionPath;
371
- this.vector.available = true;
372
- return true;
373
- }
374
- catch (err) {
375
- const message = err instanceof Error ? err.message : String(err);
376
- this.vector.available = false;
377
- this.vector.loadError = message;
378
- return false;
379
- }
380
- }
381
- ensureVectorTable(dimensions) {
382
- if (this.vector.dims === dimensions) {
383
- return;
384
- }
385
- if (this.vector.dims && this.vector.dims !== dimensions) {
386
- this.dropVectorTable();
387
- }
388
- this.db.exec(`CREATE VIRTUAL TABLE IF NOT EXISTS ${VECTOR_TABLE} USING vec0(\n` +
389
- ` id TEXT PRIMARY KEY,\n` +
390
- ` embedding FLOAT[${dimensions}]\n` +
391
- `)`);
392
- this.vector.dims = dimensions;
393
- }
394
- dropVectorTable() {
395
- try {
396
- this.db.exec(`DROP TABLE IF EXISTS ${VECTOR_TABLE}`);
397
- }
398
- catch { }
399
- }
400
- async withTimeout(promise, timeoutMs, message) {
401
- if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
402
- return await promise;
403
- }
404
- let timer = null;
405
- const timeoutPromise = new Promise((_, reject) => {
406
- timer = setTimeout(() => reject(new Error(message)), timeoutMs);
407
- });
408
- try {
409
- return (await Promise.race([promise, timeoutPromise]));
410
- }
411
- finally {
412
- if (timer) {
413
- clearTimeout(timer);
414
- }
415
- }
416
- }
417
- ensureWatcher() {
418
- if (!this.config.sync.watch || this.watchers.length > 0) {
419
- return;
420
- }
421
- const watchTargets = [
422
- path.join(this.memoryRoot, "MEMORY.md"),
423
- path.join(this.memoryRoot, "memory.md"),
424
- path.join(this.memoryRoot, "memory"),
425
- ];
426
- const onChange = () => {
427
- this.dirty = true;
428
- this.scheduleWatchSync();
429
- };
430
- for (const target of watchTargets) {
431
- try {
432
- const watcher = fsSync.watch(target, { recursive: false }, onChange);
433
- watcher.on("error", () => {
434
- try {
435
- watcher.close();
436
- }
437
- catch { }
438
- });
439
- this.watchers.push(watcher);
440
- }
441
- catch {
442
- // Ignore missing/unwatchable paths.
443
- }
444
- }
445
- }
446
- scheduleWatchSync() {
447
- if (!this.config.sync.watch) {
448
- return;
449
- }
450
- if (this.watchTimer) {
451
- clearTimeout(this.watchTimer);
452
- }
453
- this.watchTimer = setTimeout(() => {
454
- this.watchTimer = null;
455
- void this.sync({ reason: "watch" }).catch(() => { });
456
- }, this.config.sync.watchDebounceMs);
457
- }
458
- ensureSessionListener() {
459
- if (!this.config.experimental.sessionMemory) {
460
- return;
461
- }
462
- const sessionsRoot = path.join(this.dataDir, ".aimax", "sessions");
463
- try {
464
- const watcher = fsSync.watch(sessionsRoot, { recursive: true }, (_event, filename) => {
465
- if (!filename || !filename.endsWith("transcript.jsonl")) {
466
- return;
467
- }
468
- const abs = path.join(sessionsRoot, filename);
469
- this.scheduleSessionDirty(abs);
470
- });
471
- this.watchers.push(watcher);
472
- }
473
- catch {
474
- // Ignore missing/unwatchable sessions dir.
475
- }
476
- }
477
- scheduleSessionDirty(sessionFile) {
478
- if (!this.config.experimental.sessionMemory) {
479
- return;
480
- }
481
- this.sessionPendingFiles.add(sessionFile);
482
- if (this.sessionWatchTimer) {
483
- return;
484
- }
485
- this.sessionWatchTimer = setTimeout(() => {
486
- this.sessionWatchTimer = null;
487
- void this.processSessionDeltaBatch().catch(() => { });
488
- }, 5000);
489
- }
490
- async processSessionDeltaBatch() {
491
- if (this.sessionPendingFiles.size === 0) {
492
- return;
493
- }
494
- const pending = Array.from(this.sessionPendingFiles);
495
- this.sessionPendingFiles.clear();
496
- let shouldSync = false;
497
- for (const sessionFile of pending) {
498
- const delta = await this.updateSessionDelta(sessionFile);
499
- if (!delta) {
500
- continue;
501
- }
502
- const bytesThreshold = delta.deltaBytes;
503
- const messagesThreshold = delta.deltaMessages;
504
- const bytesHit = bytesThreshold <= 0 ? delta.pendingBytes > 0 : delta.pendingBytes >= bytesThreshold;
505
- const messagesHit = messagesThreshold <= 0
506
- ? delta.pendingMessages > 0
507
- : delta.pendingMessages >= messagesThreshold;
508
- if (!bytesHit && !messagesHit) {
509
- continue;
510
- }
511
- this.sessionsDirtyFiles.add(sessionFile);
512
- this.sessionsDirty = true;
513
- delta.pendingBytes =
514
- bytesThreshold > 0 ? Math.max(0, delta.pendingBytes - bytesThreshold) : 0;
515
- delta.pendingMessages =
516
- messagesThreshold > 0 ? Math.max(0, delta.pendingMessages - messagesThreshold) : 0;
517
- shouldSync = true;
518
- }
519
- if (shouldSync) {
520
- void this.sync({ reason: "session-delta" }).catch(() => { });
521
- }
522
- }
523
- async updateSessionDelta(sessionFile) {
524
- const thresholds = this.config.sync.sessions;
525
- if (!thresholds) {
526
- return null;
527
- }
528
- let stat;
529
- try {
530
- stat = await fs.stat(sessionFile);
531
- }
532
- catch {
533
- return null;
534
- }
535
- const size = stat.size;
536
- let state = this.sessionDeltas.get(sessionFile);
537
- if (!state) {
538
- state = { lastSize: 0, pendingBytes: 0, pendingMessages: 0 };
539
- this.sessionDeltas.set(sessionFile, state);
540
- }
541
- const deltaBytes = Math.max(0, size - state.lastSize);
542
- if (deltaBytes === 0 && size === state.lastSize) {
543
- return {
544
- deltaBytes: thresholds.deltaBytes,
545
- deltaMessages: thresholds.deltaMessages,
546
- pendingBytes: state.pendingBytes,
547
- pendingMessages: state.pendingMessages,
548
- };
549
- }
550
- if (size < state.lastSize) {
551
- state.lastSize = size;
552
- state.pendingBytes += size;
553
- const shouldCountMessages = thresholds.deltaMessages > 0 &&
554
- (thresholds.deltaBytes <= 0 || state.pendingBytes < thresholds.deltaBytes);
555
- if (shouldCountMessages) {
556
- state.pendingMessages += await this.countNewlines(sessionFile, 0, size);
557
- }
558
- }
559
- else {
560
- state.pendingBytes += deltaBytes;
561
- const shouldCountMessages = thresholds.deltaMessages > 0 &&
562
- (thresholds.deltaBytes <= 0 || state.pendingBytes < thresholds.deltaBytes);
563
- if (shouldCountMessages) {
564
- state.pendingMessages += await this.countNewlines(sessionFile, state.lastSize, size);
565
- }
566
- state.lastSize = size;
567
- }
568
- this.sessionDeltas.set(sessionFile, state);
569
- return {
570
- deltaBytes: thresholds.deltaBytes,
571
- deltaMessages: thresholds.deltaMessages,
572
- pendingBytes: state.pendingBytes,
573
- pendingMessages: state.pendingMessages,
574
- };
575
- }
576
- async countNewlines(absPath, start, end) {
577
- if (end <= start) {
578
- return 0;
579
- }
580
- let handle;
581
- try {
582
- handle = await fs.open(absPath, "r");
583
- }
584
- catch {
585
- return 0;
586
- }
587
- try {
588
- let offset = start;
589
- let count = 0;
590
- const buffer = Buffer.alloc(64 * 1024);
591
- while (offset < end) {
592
- const toRead = Math.min(buffer.length, end - offset);
593
- const { bytesRead } = await handle.read(buffer, 0, toRead, offset);
594
- if (bytesRead <= 0) {
595
- break;
596
- }
597
- for (let i = 0; i < bytesRead; i += 1) {
598
- if (buffer[i] === 10) {
599
- count += 1;
600
- }
601
- }
602
- offset += bytesRead;
603
- }
604
- return count;
605
- }
606
- finally {
607
- await handle.close();
608
- }
609
- }
610
- computeProviderKey() {
611
- return hashText(JSON.stringify({ provider: this.provider.id, model: this.provider.model }));
612
- }
613
- resolveMemoryFilePath(rawPath) {
614
- const trimmed = rawPath.trim();
615
- if (!trimmed) {
616
- throw new Error("path required");
617
- }
618
- const absPath = path.isAbsolute(trimmed)
619
- ? path.resolve(trimmed)
620
- : path.resolve(this.memoryRoot, trimmed);
621
- const relPath = path.relative(this.memoryRoot, absPath).replace(/\\/g, "/");
622
- const inWorkspace = relPath.length > 0 && !relPath.startsWith("..") && !path.isAbsolute(relPath);
623
- const allowed = inWorkspace && isMemoryPath(relPath);
624
- if (!allowed) {
625
- throw new Error("path required");
626
- }
627
- if (!absPath.endsWith(".md")) {
628
- throw new Error("path required");
629
- }
630
- return { absPath, relPath };
631
- }
632
- applyEmbeddingProvider() {
633
- const providerId = this.config.embedding?.providerId?.trim();
634
- if (providerId) {
635
- const resolved = resolveEmbeddingProvider({
636
- providerId,
637
- dataDir: this.dataDir,
638
- memoryDir: this.memoryRoot,
639
- });
640
- if (!resolved) {
641
- throw new Error(`Embedding provider not found: ${providerId}`);
642
- }
643
- this.provider = resolved.provider;
644
- this.embeddingProviderId = providerId;
645
- this.providerKey = this.computeProviderKey();
646
- this.dirty = true;
647
- return;
648
- }
649
- if (this.embeddingProviderId) {
650
- this.provider = createMockEmbeddingProvider();
651
- this.embeddingProviderId = undefined;
652
- this.providerKey = this.computeProviderKey();
653
- this.dirty = true;
654
- }
655
- }
656
- readMeta() {
657
- const row = this.db.prepare(`SELECT value FROM meta WHERE key = ?`).get(META_KEY);
658
- if (!row?.value) {
659
- return null;
660
- }
661
- try {
662
- return JSON.parse(row.value);
663
- }
664
- catch {
665
- return null;
666
- }
667
- }
668
- writeMeta(meta) {
669
- const value = JSON.stringify(meta);
670
- this.db
671
- .prepare(`INSERT INTO meta (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value=excluded.value`)
672
- .run(META_KEY, value);
673
- }
674
- loadEmbeddingCache(hashes) {
675
- if (!this.config.cache.enabled || hashes.length === 0) {
676
- return new Map();
677
- }
678
- const unique = Array.from(new Set(hashes.filter(Boolean)));
679
- if (unique.length === 0) {
680
- return new Map();
681
- }
682
- const out = new Map();
683
- const baseParams = [this.provider.id, this.provider.model, this.providerKey];
684
- const batchSize = 400;
685
- for (let start = 0; start < unique.length; start += batchSize) {
686
- const batch = unique.slice(start, start + batchSize);
687
- const placeholders = batch.map(() => "?").join(", ");
688
- const rows = this.db
689
- .prepare(`SELECT hash, embedding FROM ${EMBEDDING_CACHE_TABLE}\n` +
690
- ` WHERE provider = ? AND model = ? AND provider_key = ? AND hash IN (${placeholders})`)
691
- .all(...baseParams, ...batch);
692
- for (const row of rows) {
693
- out.set(row.hash, parseEmbedding(row.embedding));
694
- }
695
- }
696
- return out;
697
- }
698
- upsertEmbeddingCache(entries) {
699
- if (!this.config.cache.enabled || entries.length === 0) {
700
- return;
701
- }
702
- const now = Date.now();
703
- const stmt = this.db.prepare(`INSERT INTO ${EMBEDDING_CACHE_TABLE} (provider, model, provider_key, hash, embedding, dims, updated_at)\n` +
704
- ` VALUES (?, ?, ?, ?, ?, ?, ?)\n` +
705
- ` ON CONFLICT(provider, model, provider_key, hash) DO UPDATE SET\n` +
706
- ` embedding=excluded.embedding,\n` +
707
- ` dims=excluded.dims,\n` +
708
- ` updated_at=excluded.updated_at`);
709
- for (const entry of entries) {
710
- const embedding = entry.embedding ?? [];
711
- stmt.run(this.provider.id, this.provider.model, this.providerKey, entry.hash, JSON.stringify(embedding), embedding.length, now);
712
- }
713
- }
714
- async embedChunks(chunks) {
715
- if (chunks.length === 0) {
716
- return [];
717
- }
718
- const cached = this.loadEmbeddingCache(chunks.map((chunk) => chunk.hash));
719
- const embeddings = Array.from({ length: chunks.length }, () => []);
720
- const missing = [];
721
- for (let i = 0; i < chunks.length; i += 1) {
722
- const chunk = chunks[i];
723
- const hit = chunk?.hash ? cached.get(chunk.hash) : undefined;
724
- if (hit && hit.length > 0) {
725
- embeddings[i] = hit;
726
- }
727
- else if (chunk) {
728
- missing.push({ index: i, chunk });
729
- }
730
- }
731
- if (missing.length === 0) {
732
- return embeddings;
733
- }
734
- const batchEmbeddings = await this.provider.embedBatch(missing.map((m) => m.chunk.text));
735
- const toCache = [];
736
- for (let i = 0; i < missing.length; i += 1) {
737
- const item = missing[i];
738
- const embedding = batchEmbeddings[i] ?? [];
739
- embeddings[item.index] = embedding;
740
- toCache.push({ hash: item.chunk.hash, embedding });
741
- }
742
- this.upsertEmbeddingCache(toCache);
743
- return embeddings;
744
- }
745
- async indexFile(entry, options) {
746
- const content = options.content ?? (await fs.readFile(entry.absPath, "utf-8"));
747
- const chunks = chunkMarkdown(content, {
748
- tokens: this.config.chunkTokens,
749
- overlap: this.config.chunkOverlap,
750
- }).filter((chunk) => chunk.text.trim().length > 0);
751
- if (options.source === "sessions") {
752
- remapChunkLines(chunks, options.lineMap);
753
- }
754
- const embeddings = await this.embedChunks(chunks);
755
- const sample = embeddings.find((embedding) => embedding.length > 0);
756
- const vectorReady = sample ? await this.ensureVectorReady(sample.length) : false;
757
- const now = Date.now();
758
- if (vectorReady) {
759
- try {
760
- this.db
761
- .prepare(`DELETE FROM ${VECTOR_TABLE} WHERE id IN (SELECT id FROM chunks WHERE path = ? AND source = ?)`)
762
- .run(entry.path, options.source);
763
- }
764
- catch { }
765
- }
766
- if (this.ftsAvailable) {
767
- try {
768
- this.db
769
- .prepare(`DELETE FROM ${FTS_TABLE} WHERE path = ? AND source = ? AND model = ?`)
770
- .run(entry.path, options.source, this.provider.model);
771
- }
772
- catch { }
773
- }
774
- this.db
775
- .prepare(`DELETE FROM chunks WHERE path = ? AND source = ?`)
776
- .run(entry.path, options.source);
777
- for (let i = 0; i < chunks.length; i += 1) {
778
- const chunk = chunks[i];
779
- const embedding = embeddings[i] ?? [];
780
- const id = hashText(`${options.source}:${entry.path}:${chunk.startLine}:${chunk.endLine}:${chunk.hash}:${this.provider.model}`);
781
- this.db
782
- .prepare(`INSERT INTO chunks (id, path, source, start_line, end_line, hash, model, text, embedding, updated_at)
783
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
784
- ON CONFLICT(id) DO UPDATE SET
785
- hash=excluded.hash,
786
- model=excluded.model,
787
- text=excluded.text,
788
- embedding=excluded.embedding,
789
- updated_at=excluded.updated_at`)
790
- .run(id, entry.path, options.source, chunk.startLine, chunk.endLine, chunk.hash, this.provider.model, chunk.text, JSON.stringify(embedding), now);
791
- if (vectorReady && embedding.length > 0) {
792
- try {
793
- this.db.prepare(`DELETE FROM ${VECTOR_TABLE} WHERE id = ?`).run(id);
794
- }
795
- catch { }
796
- this.db
797
- .prepare(`INSERT INTO ${VECTOR_TABLE} (id, embedding) VALUES (?, ?)`)
798
- .run(id, Buffer.from(new Float32Array(embedding).buffer));
799
- }
800
- if (this.ftsAvailable) {
801
- this.db
802
- .prepare(`INSERT INTO ${FTS_TABLE} (text, id, path, source, model, start_line, end_line)\n` +
803
- ` VALUES (?, ?, ?, ?, ?, ?, ?)`)
804
- .run(chunk.text, id, entry.path, options.source, this.provider.model, chunk.startLine, chunk.endLine);
805
- }
806
- }
807
- this.db
808
- .prepare(`INSERT INTO files (path, source, hash, mtime, size) VALUES (?, ?, ?, ?, ?)
809
- ON CONFLICT(path) DO UPDATE SET
810
- source=excluded.source,
811
- hash=excluded.hash,
812
- mtime=excluded.mtime,
813
- size=excluded.size`)
814
- .run(entry.path, options.source, entry.hash, entry.mtimeMs, entry.size);
815
- }
816
- buildSourceFilter() {
817
- const sources = this.config.sources;
818
- if (!sources.length) {
819
- return { sql: "", params: [] };
820
- }
821
- const placeholders = sources.map(() => "?").join(", ");
822
- return { sql: ` AND source IN (${placeholders})`, params: sources };
823
- }
824
- async searchVector(queryVec, limit) {
825
- return await searchVector({
826
- db: this.db,
827
- vectorTable: VECTOR_TABLE,
828
- providerModel: this.provider.model,
829
- queryVec,
830
- limit,
831
- snippetMaxChars: SNIPPET_MAX_CHARS,
832
- ensureVectorReady: async (dimensions) => await this.ensureVectorReady(dimensions),
833
- sourceFilterVec: this.buildSourceFilter(),
834
- sourceFilterChunks: this.buildSourceFilter(),
835
- });
836
- }
837
- async searchKeyword(query, limit) {
838
- if (!this.ftsAvailable) {
839
- return [];
840
- }
841
- return await searchKeyword({
842
- db: this.db,
843
- ftsTable: FTS_TABLE,
844
- providerModel: this.provider.model,
845
- query,
846
- limit,
847
- snippetMaxChars: SNIPPET_MAX_CHARS,
848
- sourceFilter: this.buildSourceFilter(),
849
- buildFtsQuery: (raw) => buildFtsQuery(raw),
850
- bm25RankToScore,
851
- });
852
- }
853
- resetIndex() {
854
- this.db.exec(`DELETE FROM files`);
855
- this.db.exec(`DELETE FROM chunks`);
856
- if (this.ftsAvailable) {
857
- try {
858
- this.db.exec(`DELETE FROM ${FTS_TABLE}`);
859
- }
860
- catch { }
861
- }
862
- this.dropVectorTable();
863
- this.vector.dims = undefined;
864
- this.sessionsDirtyFiles.clear();
865
- }
866
- async sync(params) {
867
- const meta = this.readMeta();
868
- const needsFullReindex = !meta ||
869
- meta.model !== this.provider.model ||
870
- meta.provider !== this.provider.id ||
871
- meta.providerKey !== this.providerKey ||
872
- meta.chunkTokens !== this.config.chunkTokens ||
873
- meta.chunkOverlap !== this.config.chunkOverlap ||
874
- (this.vector.available && !meta?.vectorDims);
875
- if (needsFullReindex) {
876
- this.resetIndex();
877
- }
878
- const files = await listMemoryFiles(this.memoryRoot);
879
- const fileEntries = (await Promise.all(files.map(async (file) => buildFileEntry(file, this.memoryRoot)))).filter((entry) => entry !== null);
880
- const activePaths = new Set(fileEntries.map((entry) => entry.path));
881
- const tasks = fileEntries.map((entry) => async () => {
882
- const record = this.db
883
- .prepare(`SELECT hash FROM files WHERE path = ? AND source = ?`)
884
- .get(entry.path, "memory");
885
- if (!needsFullReindex && record?.hash === entry.hash) {
886
- return;
887
- }
888
- await this.indexFile(entry, { source: "memory" });
889
- });
890
- for (const task of tasks) {
891
- await task();
892
- }
893
- const staleRows = this.db
894
- .prepare(`SELECT path FROM files WHERE source = ?`)
895
- .all("memory");
896
- for (const stale of staleRows) {
897
- if (activePaths.has(stale.path)) {
898
- continue;
899
- }
900
- this.db.prepare(`DELETE FROM files WHERE path = ? AND source = ?`).run(stale.path, "memory");
901
- try {
902
- this.db
903
- .prepare(`DELETE FROM ${VECTOR_TABLE} WHERE id IN (SELECT id FROM chunks WHERE path = ? AND source = ?)`)
904
- .run(stale.path, "memory");
905
- }
906
- catch { }
907
- this.db.prepare(`DELETE FROM chunks WHERE path = ? AND source = ?`).run(stale.path, "memory");
908
- if (this.ftsAvailable) {
909
- try {
910
- this.db
911
- .prepare(`DELETE FROM ${FTS_TABLE} WHERE path = ? AND source = ? AND model = ?`)
912
- .run(stale.path, "memory", this.provider.model);
913
- }
914
- catch { }
915
- }
916
- }
917
- if (this.config.experimental.sessionMemory && (needsFullReindex || this.sessionsDirty)) {
918
- await this.syncSessionFiles(needsFullReindex);
919
- }
920
- this.writeMeta({
921
- model: this.provider.model,
922
- provider: this.provider.id,
923
- providerKey: this.providerKey,
924
- chunkTokens: this.config.chunkTokens,
925
- chunkOverlap: this.config.chunkOverlap,
926
- ...(this.vector.available && this.vector.dims ? { vectorDims: this.vector.dims } : {}),
927
- });
928
- this.dirty = false;
929
- }
930
- async syncSessionFiles(needsFullReindex) {
931
- const files = await listSessionFilesForAgent(this.dataDir);
932
- const entries = (await Promise.all(files.map(async (absPath) => buildSessionEntry(this.dataDir, absPath)))).filter((entry) => entry !== null);
933
- const activePaths = new Set(entries.map((entry) => entry.path));
934
- const indexAll = needsFullReindex || this.sessionsDirtyFiles.size === 0;
935
- for (const entry of entries) {
936
- if (!indexAll && !this.sessionsDirtyFiles.has(entry.absPath)) {
937
- continue;
938
- }
939
- const record = this.db
940
- .prepare(`SELECT hash FROM files WHERE path = ? AND source = ?`)
941
- .get(entry.path, "sessions");
942
- if (!needsFullReindex && record?.hash === entry.hash) {
943
- this.resetSessionDelta(entry.absPath, entry.size);
944
- continue;
945
- }
946
- await this.indexFile(entry, {
947
- source: "sessions",
948
- content: entry.content,
949
- lineMap: entry.lineMap,
950
- });
951
- this.resetSessionDelta(entry.absPath, entry.size);
952
- }
953
- const staleRows = this.db
954
- .prepare(`SELECT path FROM files WHERE source = ?`)
955
- .all("sessions");
956
- for (const stale of staleRows) {
957
- if (activePaths.has(stale.path)) {
958
- continue;
959
- }
960
- this.db
961
- .prepare(`DELETE FROM files WHERE path = ? AND source = ?`)
962
- .run(stale.path, "sessions");
963
- try {
964
- this.db
965
- .prepare(`DELETE FROM ${VECTOR_TABLE} WHERE id IN (SELECT id FROM chunks WHERE path = ? AND source = ?)`)
966
- .run(stale.path, "sessions");
967
- }
968
- catch { }
969
- this.db
970
- .prepare(`DELETE FROM chunks WHERE path = ? AND source = ?`)
971
- .run(stale.path, "sessions");
972
- if (this.ftsAvailable) {
973
- try {
974
- this.db
975
- .prepare(`DELETE FROM ${FTS_TABLE} WHERE path = ? AND source = ? AND model = ?`)
976
- .run(stale.path, "sessions", this.provider.model);
977
- }
978
- catch { }
979
- }
980
- }
981
- this.sessionsDirty = false;
982
- this.sessionsDirtyFiles.clear();
983
- }
984
- resetSessionDelta(absPath, size) {
985
- const state = this.sessionDeltas.get(absPath);
986
- if (!state) {
987
- return;
988
- }
989
- state.lastSize = size;
990
- state.pendingBytes = 0;
991
- state.pendingMessages = 0;
992
- }
993
- decorateCitations(results) {
994
- if (this.config.citations === "off") {
995
- return results;
996
- }
997
- return results.map((entry) => {
998
- const citation = `Source: ${entry.path}#L${entry.startLine}-L${entry.endLine}`;
999
- if (this.config.citations === "on") {
1000
- return { ...entry, citation, snippet: `${entry.snippet}\n\n${citation}` };
1001
- }
1002
- return { ...entry, citation };
1003
- });
1004
- }
1005
- }
1006
- //# sourceMappingURL=manager.js.map