@chances-ai/engine 24.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (389) hide show
  1. package/dist/agents/discover.d.ts +30 -0
  2. package/dist/agents/discover.d.ts.map +1 -0
  3. package/dist/agents/discover.js +183 -0
  4. package/dist/agents/discover.js.map +1 -0
  5. package/dist/agents/index.d.ts +20 -0
  6. package/dist/agents/index.d.ts.map +1 -0
  7. package/dist/agents/index.js +52 -0
  8. package/dist/agents/index.js.map +1 -0
  9. package/dist/agents/parse.d.ts +61 -0
  10. package/dist/agents/parse.d.ts.map +1 -0
  11. package/dist/agents/parse.js +527 -0
  12. package/dist/agents/parse.js.map +1 -0
  13. package/dist/agents/types.d.ts +52 -0
  14. package/dist/agents/types.d.ts.map +1 -0
  15. package/dist/agents/types.js +8 -0
  16. package/dist/agents/types.js.map +1 -0
  17. package/dist/ai/adapters/ai-sdk-stream.d.ts +19 -0
  18. package/dist/ai/adapters/ai-sdk-stream.d.ts.map +1 -0
  19. package/dist/ai/adapters/ai-sdk-stream.js +125 -0
  20. package/dist/ai/adapters/ai-sdk-stream.js.map +1 -0
  21. package/dist/ai/adapters/ai-sdk.d.ts +56 -0
  22. package/dist/ai/adapters/ai-sdk.d.ts.map +1 -0
  23. package/dist/ai/adapters/ai-sdk.js +112 -0
  24. package/dist/ai/adapters/ai-sdk.js.map +1 -0
  25. package/dist/ai/adapters/mock.d.ts +13 -0
  26. package/dist/ai/adapters/mock.d.ts.map +1 -0
  27. package/dist/ai/adapters/mock.js +54 -0
  28. package/dist/ai/adapters/mock.js.map +1 -0
  29. package/dist/ai/adapters/openai-compatible.d.ts +23 -0
  30. package/dist/ai/adapters/openai-compatible.d.ts.map +1 -0
  31. package/dist/ai/adapters/openai-compatible.js +45 -0
  32. package/dist/ai/adapters/openai-compatible.js.map +1 -0
  33. package/dist/ai/cost.d.ts +3 -0
  34. package/dist/ai/cost.d.ts.map +1 -0
  35. package/dist/ai/cost.js +5 -0
  36. package/dist/ai/cost.js.map +1 -0
  37. package/dist/ai/index.d.ts +12 -0
  38. package/dist/ai/index.d.ts.map +1 -0
  39. package/dist/ai/index.js +11 -0
  40. package/dist/ai/index.js.map +1 -0
  41. package/dist/ai/known-models.d.ts +20 -0
  42. package/dist/ai/known-models.d.ts.map +1 -0
  43. package/dist/ai/known-models.js +129 -0
  44. package/dist/ai/known-models.js.map +1 -0
  45. package/dist/ai/registry.d.ts +12 -0
  46. package/dist/ai/registry.d.ts.map +1 -0
  47. package/dist/ai/registry.js +24 -0
  48. package/dist/ai/registry.js.map +1 -0
  49. package/dist/ai/retry.d.ts +11 -0
  50. package/dist/ai/retry.d.ts.map +1 -0
  51. package/dist/ai/retry.js +14 -0
  52. package/dist/ai/retry.js.map +1 -0
  53. package/dist/ai/router.d.ts +25 -0
  54. package/dist/ai/router.d.ts.map +1 -0
  55. package/dist/ai/router.js +36 -0
  56. package/dist/ai/router.js.map +1 -0
  57. package/dist/ai/setup.d.ts +23 -0
  58. package/dist/ai/setup.d.ts.map +1 -0
  59. package/dist/ai/setup.js +47 -0
  60. package/dist/ai/setup.js.map +1 -0
  61. package/dist/ai/summarizer.d.ts +24 -0
  62. package/dist/ai/summarizer.d.ts.map +1 -0
  63. package/dist/ai/summarizer.js +56 -0
  64. package/dist/ai/summarizer.js.map +1 -0
  65. package/dist/ai/types.d.ts +83 -0
  66. package/dist/ai/types.d.ts.map +1 -0
  67. package/dist/ai/types.js +2 -0
  68. package/dist/ai/types.js.map +1 -0
  69. package/dist/core/compaction/circuit-breaker.d.ts +32 -0
  70. package/dist/core/compaction/circuit-breaker.d.ts.map +1 -0
  71. package/dist/core/compaction/circuit-breaker.js +42 -0
  72. package/dist/core/compaction/circuit-breaker.js.map +1 -0
  73. package/dist/core/compaction/compactor.d.ts +75 -0
  74. package/dist/core/compaction/compactor.d.ts.map +1 -0
  75. package/dist/core/compaction/compactor.js +261 -0
  76. package/dist/core/compaction/compactor.js.map +1 -0
  77. package/dist/core/compaction/estimate.d.ts +39 -0
  78. package/dist/core/compaction/estimate.d.ts.map +1 -0
  79. package/dist/core/compaction/estimate.js +74 -0
  80. package/dist/core/compaction/estimate.js.map +1 -0
  81. package/dist/core/compaction/index.d.ts +5 -0
  82. package/dist/core/compaction/index.d.ts.map +1 -0
  83. package/dist/core/compaction/index.js +5 -0
  84. package/dist/core/compaction/index.js.map +1 -0
  85. package/dist/core/compaction/prune.d.ts +43 -0
  86. package/dist/core/compaction/prune.d.ts.map +1 -0
  87. package/dist/core/compaction/prune.js +51 -0
  88. package/dist/core/compaction/prune.js.map +1 -0
  89. package/dist/core/engine.d.ts +268 -0
  90. package/dist/core/engine.d.ts.map +1 -0
  91. package/dist/core/engine.js +767 -0
  92. package/dist/core/engine.js.map +1 -0
  93. package/dist/core/index.d.ts +6 -0
  94. package/dist/core/index.d.ts.map +1 -0
  95. package/dist/core/index.js +6 -0
  96. package/dist/core/index.js.map +1 -0
  97. package/dist/core/task-tool.d.ts +175 -0
  98. package/dist/core/task-tool.d.ts.map +1 -0
  99. package/dist/core/task-tool.js +901 -0
  100. package/dist/core/task-tool.js.map +1 -0
  101. package/dist/core/workspace-query.d.ts +83 -0
  102. package/dist/core/workspace-query.d.ts.map +1 -0
  103. package/dist/core/workspace-query.js +217 -0
  104. package/dist/core/workspace-query.js.map +1 -0
  105. package/dist/core/worktree/active-marker.d.ts +31 -0
  106. package/dist/core/worktree/active-marker.d.ts.map +1 -0
  107. package/dist/core/worktree/active-marker.js +109 -0
  108. package/dist/core/worktree/active-marker.js.map +1 -0
  109. package/dist/core/worktree/create.d.ts +40 -0
  110. package/dist/core/worktree/create.d.ts.map +1 -0
  111. package/dist/core/worktree/create.js +121 -0
  112. package/dist/core/worktree/create.js.map +1 -0
  113. package/dist/core/worktree/errors.d.ts +7 -0
  114. package/dist/core/worktree/errors.d.ts.map +1 -0
  115. package/dist/core/worktree/errors.js +11 -0
  116. package/dist/core/worktree/errors.js.map +1 -0
  117. package/dist/core/worktree/gc.d.ts +39 -0
  118. package/dist/core/worktree/gc.d.ts.map +1 -0
  119. package/dist/core/worktree/gc.js +146 -0
  120. package/dist/core/worktree/gc.js.map +1 -0
  121. package/dist/core/worktree/git.d.ts +53 -0
  122. package/dist/core/worktree/git.d.ts.map +1 -0
  123. package/dist/core/worktree/git.js +166 -0
  124. package/dist/core/worktree/git.js.map +1 -0
  125. package/dist/core/worktree/index.d.ts +8 -0
  126. package/dist/core/worktree/index.d.ts.map +1 -0
  127. package/dist/core/worktree/index.js +8 -0
  128. package/dist/core/worktree/index.js.map +1 -0
  129. package/dist/core/worktree/paths.d.ts +26 -0
  130. package/dist/core/worktree/paths.d.ts.map +1 -0
  131. package/dist/core/worktree/paths.js +57 -0
  132. package/dist/core/worktree/paths.js.map +1 -0
  133. package/dist/core/worktree/slug.d.ts +6 -0
  134. package/dist/core/worktree/slug.d.ts.map +1 -0
  135. package/dist/core/worktree/slug.js +21 -0
  136. package/dist/core/worktree/slug.js.map +1 -0
  137. package/dist/local-vault/file-store.d.ts +64 -0
  138. package/dist/local-vault/file-store.d.ts.map +1 -0
  139. package/dist/local-vault/file-store.js +225 -0
  140. package/dist/local-vault/file-store.js.map +1 -0
  141. package/dist/local-vault/index.d.ts +57 -0
  142. package/dist/local-vault/index.d.ts.map +1 -0
  143. package/dist/local-vault/index.js +68 -0
  144. package/dist/local-vault/index.js.map +1 -0
  145. package/dist/local-vault/keychain.d.ts +58 -0
  146. package/dist/local-vault/keychain.d.ts.map +1 -0
  147. package/dist/local-vault/keychain.js +200 -0
  148. package/dist/local-vault/keychain.js.map +1 -0
  149. package/dist/local-vault/mutex.d.ts +20 -0
  150. package/dist/local-vault/mutex.d.ts.map +1 -0
  151. package/dist/local-vault/mutex.js +44 -0
  152. package/dist/local-vault/mutex.js.map +1 -0
  153. package/dist/local-vault/passphrase.d.ts +30 -0
  154. package/dist/local-vault/passphrase.d.ts.map +1 -0
  155. package/dist/local-vault/passphrase.js +72 -0
  156. package/dist/local-vault/passphrase.js.map +1 -0
  157. package/dist/lsp/config.d.ts +34 -0
  158. package/dist/lsp/config.d.ts.map +1 -0
  159. package/dist/lsp/config.js +68 -0
  160. package/dist/lsp/config.js.map +1 -0
  161. package/dist/lsp/detect.d.ts +7 -0
  162. package/dist/lsp/detect.d.ts.map +1 -0
  163. package/dist/lsp/detect.js +78 -0
  164. package/dist/lsp/detect.js.map +1 -0
  165. package/dist/lsp/errors.d.ts +11 -0
  166. package/dist/lsp/errors.d.ts.map +1 -0
  167. package/dist/lsp/errors.js +11 -0
  168. package/dist/lsp/errors.js.map +1 -0
  169. package/dist/lsp/formatters.d.ts +147 -0
  170. package/dist/lsp/formatters.d.ts.map +1 -0
  171. package/dist/lsp/formatters.js +259 -0
  172. package/dist/lsp/formatters.js.map +1 -0
  173. package/dist/lsp/index.d.ts +31 -0
  174. package/dist/lsp/index.d.ts.map +1 -0
  175. package/dist/lsp/index.js +31 -0
  176. package/dist/lsp/index.js.map +1 -0
  177. package/dist/lsp/instance.d.ts +72 -0
  178. package/dist/lsp/instance.d.ts.map +1 -0
  179. package/dist/lsp/instance.js +489 -0
  180. package/dist/lsp/instance.js.map +1 -0
  181. package/dist/lsp/lazy-load.d.ts +27 -0
  182. package/dist/lsp/lazy-load.d.ts.map +1 -0
  183. package/dist/lsp/lazy-load.js +57 -0
  184. package/dist/lsp/lazy-load.js.map +1 -0
  185. package/dist/lsp/manager.d.ts +59 -0
  186. package/dist/lsp/manager.d.ts.map +1 -0
  187. package/dist/lsp/manager.js +242 -0
  188. package/dist/lsp/manager.js.map +1 -0
  189. package/dist/lsp/ops.d.ts +13 -0
  190. package/dist/lsp/ops.d.ts.map +1 -0
  191. package/dist/lsp/ops.js +225 -0
  192. package/dist/lsp/ops.js.map +1 -0
  193. package/dist/lsp/rpc.d.ts +47 -0
  194. package/dist/lsp/rpc.d.ts.map +1 -0
  195. package/dist/lsp/rpc.js +134 -0
  196. package/dist/lsp/rpc.js.map +1 -0
  197. package/dist/lsp/safe-uri.d.ts +18 -0
  198. package/dist/lsp/safe-uri.d.ts.map +1 -0
  199. package/dist/lsp/safe-uri.js +96 -0
  200. package/dist/lsp/safe-uri.js.map +1 -0
  201. package/dist/lsp/types.d.ts +70 -0
  202. package/dist/lsp/types.d.ts.map +1 -0
  203. package/dist/lsp/types.js +16 -0
  204. package/dist/lsp/types.js.map +1 -0
  205. package/dist/mcp/bridge.d.ts +57 -0
  206. package/dist/mcp/bridge.d.ts.map +1 -0
  207. package/dist/mcp/bridge.js +98 -0
  208. package/dist/mcp/bridge.js.map +1 -0
  209. package/dist/mcp/category.d.ts +22 -0
  210. package/dist/mcp/category.d.ts.map +1 -0
  211. package/dist/mcp/category.js +11 -0
  212. package/dist/mcp/category.js.map +1 -0
  213. package/dist/mcp/client.d.ts +228 -0
  214. package/dist/mcp/client.d.ts.map +1 -0
  215. package/dist/mcp/client.js +352 -0
  216. package/dist/mcp/client.js.map +1 -0
  217. package/dist/mcp/content.d.ts +86 -0
  218. package/dist/mcp/content.d.ts.map +1 -0
  219. package/dist/mcp/content.js +147 -0
  220. package/dist/mcp/content.js.map +1 -0
  221. package/dist/mcp/env.d.ts +19 -0
  222. package/dist/mcp/env.d.ts.map +1 -0
  223. package/dist/mcp/env.js +50 -0
  224. package/dist/mcp/env.js.map +1 -0
  225. package/dist/mcp/host.d.ts +199 -0
  226. package/dist/mcp/host.d.ts.map +1 -0
  227. package/dist/mcp/host.js +530 -0
  228. package/dist/mcp/host.js.map +1 -0
  229. package/dist/mcp/index.d.ts +18 -0
  230. package/dist/mcp/index.d.ts.map +1 -0
  231. package/dist/mcp/index.js +17 -0
  232. package/dist/mcp/index.js.map +1 -0
  233. package/dist/mcp/load-mcp-host.d.ts +32 -0
  234. package/dist/mcp/load-mcp-host.d.ts.map +1 -0
  235. package/dist/mcp/load-mcp-host.js +49 -0
  236. package/dist/mcp/load-mcp-host.js.map +1 -0
  237. package/dist/mcp/oauth/callback-server.d.ts +73 -0
  238. package/dist/mcp/oauth/callback-server.d.ts.map +1 -0
  239. package/dist/mcp/oauth/callback-server.js +280 -0
  240. package/dist/mcp/oauth/callback-server.js.map +1 -0
  241. package/dist/mcp/oauth/config-hash.d.ts +24 -0
  242. package/dist/mcp/oauth/config-hash.d.ts.map +1 -0
  243. package/dist/mcp/oauth/config-hash.js +55 -0
  244. package/dist/mcp/oauth/config-hash.js.map +1 -0
  245. package/dist/mcp/oauth/error-normalize.d.ts +39 -0
  246. package/dist/mcp/oauth/error-normalize.d.ts.map +1 -0
  247. package/dist/mcp/oauth/error-normalize.js +91 -0
  248. package/dist/mcp/oauth/error-normalize.js.map +1 -0
  249. package/dist/mcp/oauth/provider.d.ts +190 -0
  250. package/dist/mcp/oauth/provider.d.ts.map +1 -0
  251. package/dist/mcp/oauth/provider.js +305 -0
  252. package/dist/mcp/oauth/provider.js.map +1 -0
  253. package/dist/mcp/oauth/refresh-coalescer.d.ts +46 -0
  254. package/dist/mcp/oauth/refresh-coalescer.d.ts.map +1 -0
  255. package/dist/mcp/oauth/refresh-coalescer.js +77 -0
  256. package/dist/mcp/oauth/refresh-coalescer.js.map +1 -0
  257. package/dist/mcp/oauth/sdk-shapes.d.ts +77 -0
  258. package/dist/mcp/oauth/sdk-shapes.d.ts.map +1 -0
  259. package/dist/mcp/oauth/sdk-shapes.js +21 -0
  260. package/dist/mcp/oauth/sdk-shapes.js.map +1 -0
  261. package/dist/mcp/parse.d.ts +28 -0
  262. package/dist/mcp/parse.d.ts.map +1 -0
  263. package/dist/mcp/parse.js +209 -0
  264. package/dist/mcp/parse.js.map +1 -0
  265. package/dist/mcp/prompts.d.ts +31 -0
  266. package/dist/mcp/prompts.d.ts.map +1 -0
  267. package/dist/mcp/prompts.js +71 -0
  268. package/dist/mcp/prompts.js.map +1 -0
  269. package/dist/mcp/redact.d.ts +62 -0
  270. package/dist/mcp/redact.d.ts.map +1 -0
  271. package/dist/mcp/redact.js +87 -0
  272. package/dist/mcp/redact.js.map +1 -0
  273. package/dist/mcp/resources.d.ts +70 -0
  274. package/dist/mcp/resources.d.ts.map +1 -0
  275. package/dist/mcp/resources.js +170 -0
  276. package/dist/mcp/resources.js.map +1 -0
  277. package/dist/mcp/types.d.ts +123 -0
  278. package/dist/mcp/types.d.ts.map +1 -0
  279. package/dist/mcp/types.js +2 -0
  280. package/dist/mcp/types.js.map +1 -0
  281. package/dist/memory/frontmatter.d.ts +18 -0
  282. package/dist/memory/frontmatter.d.ts.map +1 -0
  283. package/dist/memory/frontmatter.js +81 -0
  284. package/dist/memory/frontmatter.js.map +1 -0
  285. package/dist/memory/index.d.ts +5 -0
  286. package/dist/memory/index.d.ts.map +1 -0
  287. package/dist/memory/index.js +5 -0
  288. package/dist/memory/index.js.map +1 -0
  289. package/dist/memory/store.d.ts +44 -0
  290. package/dist/memory/store.d.ts.map +1 -0
  291. package/dist/memory/store.js +237 -0
  292. package/dist/memory/store.js.map +1 -0
  293. package/dist/memory/tools.d.ts +11 -0
  294. package/dist/memory/tools.d.ts.map +1 -0
  295. package/dist/memory/tools.js +159 -0
  296. package/dist/memory/tools.js.map +1 -0
  297. package/dist/memory/types.d.ts +32 -0
  298. package/dist/memory/types.d.ts.map +1 -0
  299. package/dist/memory/types.js +20 -0
  300. package/dist/memory/types.js.map +1 -0
  301. package/dist/plugin-api/index.d.ts +167 -0
  302. package/dist/plugin-api/index.d.ts.map +1 -0
  303. package/dist/plugin-api/index.js +151 -0
  304. package/dist/plugin-api/index.js.map +1 -0
  305. package/dist/plugin-logger/index.d.ts +21 -0
  306. package/dist/plugin-logger/index.d.ts.map +1 -0
  307. package/dist/plugin-logger/index.js +59 -0
  308. package/dist/plugin-logger/index.js.map +1 -0
  309. package/dist/session/index.d.ts +125 -0
  310. package/dist/session/index.d.ts.map +1 -0
  311. package/dist/session/index.js +202 -0
  312. package/dist/session/index.js.map +1 -0
  313. package/dist/tools/approval.d.ts +33 -0
  314. package/dist/tools/approval.d.ts.map +1 -0
  315. package/dist/tools/approval.js +53 -0
  316. package/dist/tools/approval.js.map +1 -0
  317. package/dist/tools/builtins/_shared.d.ts +94 -0
  318. package/dist/tools/builtins/_shared.d.ts.map +1 -0
  319. package/dist/tools/builtins/_shared.js +246 -0
  320. package/dist/tools/builtins/_shared.js.map +1 -0
  321. package/dist/tools/builtins/ask-user-question.d.ts +27 -0
  322. package/dist/tools/builtins/ask-user-question.d.ts.map +1 -0
  323. package/dist/tools/builtins/ask-user-question.js +191 -0
  324. package/dist/tools/builtins/ask-user-question.js.map +1 -0
  325. package/dist/tools/builtins/bash.d.ts +3 -0
  326. package/dist/tools/builtins/bash.d.ts.map +1 -0
  327. package/dist/tools/builtins/bash.js +158 -0
  328. package/dist/tools/builtins/bash.js.map +1 -0
  329. package/dist/tools/builtins/diff.d.ts +3 -0
  330. package/dist/tools/builtins/diff.d.ts.map +1 -0
  331. package/dist/tools/builtins/diff.js +83 -0
  332. package/dist/tools/builtins/diff.js.map +1 -0
  333. package/dist/tools/builtins/edit.d.ts +3 -0
  334. package/dist/tools/builtins/edit.d.ts.map +1 -0
  335. package/dist/tools/builtins/edit.js +40 -0
  336. package/dist/tools/builtins/edit.js.map +1 -0
  337. package/dist/tools/builtins/glob.d.ts +3 -0
  338. package/dist/tools/builtins/glob.d.ts.map +1 -0
  339. package/dist/tools/builtins/glob.js +37 -0
  340. package/dist/tools/builtins/glob.js.map +1 -0
  341. package/dist/tools/builtins/grep.d.ts +3 -0
  342. package/dist/tools/builtins/grep.d.ts.map +1 -0
  343. package/dist/tools/builtins/grep.js +81 -0
  344. package/dist/tools/builtins/grep.js.map +1 -0
  345. package/dist/tools/builtins/lsp.d.ts +3 -0
  346. package/dist/tools/builtins/lsp.d.ts.map +1 -0
  347. package/dist/tools/builtins/lsp.js +102 -0
  348. package/dist/tools/builtins/lsp.js.map +1 -0
  349. package/dist/tools/builtins/pty.d.ts +64 -0
  350. package/dist/tools/builtins/pty.d.ts.map +1 -0
  351. package/dist/tools/builtins/pty.js +536 -0
  352. package/dist/tools/builtins/pty.js.map +1 -0
  353. package/dist/tools/builtins/read.d.ts +3 -0
  354. package/dist/tools/builtins/read.d.ts.map +1 -0
  355. package/dist/tools/builtins/read.js +18 -0
  356. package/dist/tools/builtins/read.js.map +1 -0
  357. package/dist/tools/builtins/web-fetch.d.ts +4 -0
  358. package/dist/tools/builtins/web-fetch.d.ts.map +1 -0
  359. package/dist/tools/builtins/web-fetch.js +353 -0
  360. package/dist/tools/builtins/web-fetch.js.map +1 -0
  361. package/dist/tools/builtins/write.d.ts +3 -0
  362. package/dist/tools/builtins/write.d.ts.map +1 -0
  363. package/dist/tools/builtins/write.js +48 -0
  364. package/dist/tools/builtins/write.js.map +1 -0
  365. package/dist/tools/builtins.d.ts +9 -0
  366. package/dist/tools/builtins.d.ts.map +1 -0
  367. package/dist/tools/builtins.js +29 -0
  368. package/dist/tools/builtins.js.map +1 -0
  369. package/dist/tools/diff.d.ts +18 -0
  370. package/dist/tools/diff.d.ts.map +1 -0
  371. package/dist/tools/diff.js +57 -0
  372. package/dist/tools/diff.js.map +1 -0
  373. package/dist/tools/index.d.ts +10 -0
  374. package/dist/tools/index.d.ts.map +1 -0
  375. package/dist/tools/index.js +9 -0
  376. package/dist/tools/index.js.map +1 -0
  377. package/dist/tools/permission.d.ts +120 -0
  378. package/dist/tools/permission.d.ts.map +1 -0
  379. package/dist/tools/permission.js +208 -0
  380. package/dist/tools/permission.js.map +1 -0
  381. package/dist/tools/registry.d.ts +12 -0
  382. package/dist/tools/registry.d.ts.map +1 -0
  383. package/dist/tools/registry.js +19 -0
  384. package/dist/tools/registry.js.map +1 -0
  385. package/dist/tools/types.d.ts +244 -0
  386. package/dist/tools/types.d.ts.map +1 -0
  387. package/dist/tools/types.js +15 -0
  388. package/dist/tools/types.js.map +1 -0
  389. package/package.json +109 -0
@@ -0,0 +1,268 @@
1
+ import { type ApprovalMode, type AsyncTaskRegistry, type CancellationToken, type EventBus, type TaskNotification, ModelSelection } from "@chances-ai/runtime";
2
+ import { type ModelRouter, type RetryConfig } from "../ai/index.js";
3
+ import type { SessionManager } from "../session/index.js";
4
+ import type { MemoryStore } from "../memory/index.js";
5
+ import type { PermissionGate, ToolRegistry } from "../tools/index.js";
6
+ import type { PluginHost } from "../plugin-api/index.js";
7
+ export interface AgentEngineOptions {
8
+ bus: EventBus;
9
+ router: ModelRouter;
10
+ tools: ToolRegistry;
11
+ gate: PermissionGate;
12
+ session: SessionManager;
13
+ workspaceRoot: string;
14
+ memory?: MemoryStore;
15
+ plugins?: PluginHost;
16
+ /**
17
+ * (5.3) Session approval-mode getter. Read at the start of every turn (for
18
+ * the plan-mode system reminder) and per tool call (for the `blockByMode`
19
+ * pre-check). When omitted the engine behaves as `default` mode. The same
20
+ * getter is passed to the `PermissionGate`; child engines (`createTaskTool`)
21
+ * receive it too so a subagent in plan mode is told to stay read-only rather
22
+ * than discovering it via repeated denials (codex Round-1 SHOULD-FIX #2).
23
+ */
24
+ getApprovalMode?: () => ApprovalMode;
25
+ /**
26
+ * Mutable model-preference holder. The engine reads it at the start of every
27
+ * turn, so `/model` switches land on the next request without an engine
28
+ * rebuild. When omitted, the engine seeds one from the deprecated scalar
29
+ * fields below for backwards compatibility with v2.x callers.
30
+ */
31
+ selection?: ModelSelection;
32
+ /** @deprecated since v3.0 — pass `selection` instead. Still honored when
33
+ * `selection` is absent so existing tests / external callers don't break. */
34
+ preferredModel?: string;
35
+ /** @deprecated since v3.0 — pass `selection` instead. */
36
+ preferredProvider?: string;
37
+ /**
38
+ * Safety valve against runaway tool loops. Matches claude-code's `maxTurns`
39
+ * (`src/QueryEngine.ts:154`) and pi's `MAX_TURNS` test convention. When the
40
+ * loop exhausts this budget without the model returning a final answer, the
41
+ * engine throws `AppError(Provider, "Reached maximum number of turns (N)")`
42
+ * — claude-code's terminal-error pattern. Defaults to 12 when omitted; the
43
+ * CLI threads `ChancesConfig.agent.maxTurns` in here.
44
+ */
45
+ maxTurns?: number;
46
+ /**
47
+ * @deprecated Renamed to `maxTurns` in 3.0.1 for parity with claude-code /
48
+ * pi. The old name still works for one minor cycle so any out-of-tree
49
+ * caller doesn't break silently; removal target is 4.x. New callers should
50
+ * use `maxTurns`. When both are set, `maxTurns` wins.
51
+ */
52
+ maxIterations?: number;
53
+ /** Override default per-attempt backoff for provider stream retries. */
54
+ retry?: RetryConfig;
55
+ /**
56
+ * When true, the engine does NOT emit `error` events on the shared bus for
57
+ * its own terminal failures (provider exhaustion, max-turns). It still
58
+ * throws `AppError` so the caller can surface the failure on its own
59
+ * channel. Set this for child engines (e.g. the `task` subagent tool) that
60
+ * share a bus with a parent loop — without it the parent's `lastError`
61
+ * listener (see `apps/cli/src/commands/prompt.ts:26`) would record the
62
+ * child's failure as the *parent's* exit code, even when the parent's
63
+ * overall turn succeeded.
64
+ *
65
+ * Telemetry / TUI still see the child's per-call `usage`, `tool:call`, and
66
+ * `tool:result` frames — only the terminal `error` event is suppressed.
67
+ * The `tool:result` for the parent's `task` call carries the failure text
68
+ * (e.g. "Subagent failed: PROVIDER: ..."), which is the contextual story
69
+ * users actually need.
70
+ */
71
+ suppressTerminalErrors?: boolean;
72
+ /**
73
+ * Replaces the hardcoded base system prompt with caller-supplied text.
74
+ * Memory context (`MemoryStore.asSystemContext()`) is still appended after
75
+ * it. Set by the subagent `task` tool when spawning a catalog persona —
76
+ * the agent's body becomes the child's prompt INSTEAD of the generic
77
+ * "You are chances..." base, so a read-only `explore` agent doesn't carry
78
+ * the parent's "you may modify the workspace" framing into its turn.
79
+ * (3.3 design doc: codex Round-1 #3.) Undefined → engine keeps the v3.0
80
+ * baseline.
81
+ */
82
+ systemBaseOverride?: string;
83
+ /**
84
+ * (3.4) Identity tag for events this engine emits. Child engines (the
85
+ * `task` subagent tool) set this so subscribers can demultiplex
86
+ * parent vs. child output on a shared bus. Parent engines leave undefined.
87
+ * Tagged event variants: `assistant:delta`, `assistant:message`,
88
+ * `tool:call`, `tool:permission`, `tool:result`, `usage`. Lifecycle
89
+ * events (`turn:start`, `turn:end`, `error`) are not tagged — child
90
+ * engines suppress those via `suppressLifecycleEvents`.
91
+ *
92
+ * `agentId` is optional (3.6 codex Round-1 MUST-FIX #3): sync subagents
93
+ * have no registry-issued id (they complete before the parent's
94
+ * `tool:call`/`tool:result` boundary closes — the parent already
95
+ * labels them at that level). Background subagents always set it.
96
+ */
97
+ agentContext?: {
98
+ agentId?: string;
99
+ agentName: string;
100
+ };
101
+ /**
102
+ * (3.4 — codex Round-1 MUST-FIX #2) When true, the engine does NOT emit
103
+ * `turn:start` / `turn:end` / `error` events on the shared bus. Set for
104
+ * child engines because the TUI flips its `busy` flag on every `turn:*`
105
+ * event (`packages/tui/src/view-model.ts:74-101`) — a child's turn
106
+ * lifecycle would otherwise end the parent's busy state and confuse the
107
+ * NDJSON / `-p` mode renderers that assume one bus = one conversation.
108
+ *
109
+ * `error` is suppressed too because the existing `suppressTerminalErrors`
110
+ * only gated the engine's *terminal* error emits (provider exhaustion,
111
+ * max-turns) — but with `agentContext` plumbing children can also emit
112
+ * mid-turn errors, and those should stay off the shared bus.
113
+ */
114
+ suppressLifecycleEvents?: boolean;
115
+ /**
116
+ * (3.4) Optional registry of background subagent tasks. When provided:
117
+ * - At the top of every `runTurn`, the engine drains queued
118
+ * completion notifications and prepends an XML block to the turn's
119
+ * user-role message so the model sees them on the next request.
120
+ * - The `task` tool is expected to wire the launch path through the
121
+ * same registry (handled in `createTaskTool`, not here).
122
+ * When undefined: drain is a no-op (same as 3.3). The `task` tool's
123
+ * schema omits `run_in_background`. Used to scope the feature to
124
+ * interactive `chat` mode — `-p` one-shot mode passes undefined so
125
+ * backgrounds never accidentally orphan into a process exit.
126
+ */
127
+ backgroundTasks?: AsyncTaskRegistry;
128
+ /**
129
+ * (3.5) Auto-compaction orchestrator. When provided:
130
+ * - After every appendTurn + before turn:end, the engine asks
131
+ * `compactor.shouldCompact(...)` with the last provider
132
+ * request's `inputTokens`, and `await`s
133
+ * `compactor.compact("threshold", token.signal)` when true.
134
+ * - On Anthropic overflow errors (`"prompt is too long"` /
135
+ * `"request_too_large"` / `"maximum.*context.*length"`),
136
+ * the engine triggers `compactor.compact("overflow", ...)`
137
+ * once per turn and retries the failed stream.
138
+ * - Engine emits `usage:turn` carrying `lastRequestInputTokens`
139
+ * BEFORE the compaction await; `turn:end` fires AFTER (codex
140
+ * Round-1 MUST-FIX #4 — TUI / slash should not see "turn
141
+ * over" while session is still mutating).
142
+ * When undefined (subagent engines, `-p` one-shot mode), the
143
+ * engine still emits `usage:turn` but never compacts.
144
+ */
145
+ compactor?: import("./compaction/index.js").Compactor;
146
+ /**
147
+ * (4.1) Active worktree path for an isolated subagent. When set:
148
+ * - `ToolContext.workspaceRoot` and `ToolContext.cwd` BOTH flip to
149
+ * `worktreeCwd` for the duration of `runTurn`. `safePath`
150
+ * therefore resolves against the worktree tree, not the parent's.
151
+ * - The engine wraps `runTurn` body in `runWithCwd(worktreeCwd,
152
+ * …)` so descendant tool calls inherit the override transparently
153
+ * via AsyncLocalStorage (same pattern claude-code uses in
154
+ * `src/utils/cwd.ts`).
155
+ * - At every `runTurn` top, `refreshActiveMarker(worktreeCwd)`
156
+ * fires so cross-process GC can tell this worktree has a live
157
+ * owner.
158
+ * - The system prompt gains a paragraph informing the model that
159
+ * uncommitted parent changes are invisible here and the parent
160
+ * will see the final diff after the task completes.
161
+ * Set by `task-tool.ts` when `isolation: 'worktree'` is resolved for
162
+ * the spawning agent. Undefined → no isolation (the 3.x default).
163
+ */
164
+ worktreeCwd?: string;
165
+ /**
166
+ * (4.2) Optional LSP host wired in at boot. Threaded through to
167
+ * `ToolContext.lsp` so the `lsp` built-in can reach it without a
168
+ * module-global. Undefined → tool returns `ok:false` "LSP not
169
+ * available". codex Round-1 MUST-FIX #1 — keeps the wrapper free
170
+ * of CLI-boot-state imports.
171
+ */
172
+ lsp?: import("../tools/index.js").ToolLspHost;
173
+ /**
174
+ * (5.4) Optional MCP resource-mention resolver. When set, `runTurn`
175
+ * expands `@<server>:<uri>` mentions in DIRECTLY-TYPED user input into a
176
+ * synthetic resource message before the turn. Injected by boot (closed over
177
+ * the `McpHost`); typed structurally so `@chances-ai/core` stays decoupled
178
+ * from `@chances-ai/mcp` (no boundary edge). NOT applied to submitted/prompt
179
+ * text — see `runTurn`'s `expandMentions` (codex 5.4 R1 M3).
180
+ */
181
+ resolveMcpMentions?: (prompt: string, signal: AbortSignal) => Promise<ResolvedMention[]>;
182
+ }
183
+ /**
184
+ * (5.4) Structural shape of a resolved `@<server>:<uri>` mention — mirrors
185
+ * `@chances-ai/mcp#McpResolvedResource` without importing it (boundary).
186
+ */
187
+ export interface ResolvedMention {
188
+ ref: string;
189
+ server: string;
190
+ uri: string;
191
+ /** Rendered resource content (present on success). */
192
+ text?: string;
193
+ /** Why it couldn't be read (mutually exclusive with `text`). */
194
+ note?: string;
195
+ }
196
+ /** Engine default when no caller-supplied or config-supplied value applies. */
197
+ export declare const DEFAULT_MAX_TURNS = 12;
198
+ /** Default base prompt the engine uses when no `systemBaseOverride` is set.
199
+ * Exported so tests can assert "is this the default or an agent override?" and
200
+ * so the doc + plugin authors can read the exact text. */
201
+ export declare const DEFAULT_BASE_PROMPT: string;
202
+ export interface AgentResult {
203
+ text: string;
204
+ inputTokens: number;
205
+ outputTokens: number;
206
+ costUsd: number;
207
+ }
208
+ /**
209
+ * Mediator over ai/session/tools/memory. Depends only on interfaces (ports), so
210
+ * any ProviderAdapter or Tool plugs in unchanged. Communicates outward purely by
211
+ * emitting events on the bus — it never imports the TUI.
212
+ */
213
+ export declare class AgentEngine {
214
+ private readonly opts;
215
+ private readonly selection;
216
+ constructor(opts: AgentEngineOptions);
217
+ /**
218
+ * Exposes the mutable selection so callers — typically slash commands like
219
+ * `/model` — can update it between turns. Returning the live instance (not a
220
+ * copy) is intentional: writes must propagate back.
221
+ */
222
+ getSelection(): ModelSelection;
223
+ /** Bus-emit wrapper. Three responsibilities (3.4):
224
+ * 1. Suppress lifecycle frames (`turn:*`, `error`) when the engine is a
225
+ * child (`suppressLifecycleEvents=true`). Codex Round-1 MUST-FIX #2.
226
+ * 2. Stamp `agentId/agentName` on tagged event variants when an
227
+ * `agentContext` was supplied. Skipped silently when undefined.
228
+ * 3. Forward to `bus.emit` otherwise — fully transparent for parent engines.
229
+ */
230
+ private emit;
231
+ runTurn(prompt: string, token: CancellationToken, opts?: {
232
+ expandMentions?: boolean;
233
+ }): Promise<AgentResult>;
234
+ private runTurnImpl;
235
+ private runTool;
236
+ private composeSystem;
237
+ }
238
+ /** (5.3) Inserted into the system prompt while the session approval mode is
239
+ * `plan`. Tells the model it is read-only and should produce a plan instead of
240
+ * editing — the same posture claude-code's plan mode enforces. */
241
+ export declare const PLAN_MODE_NOTICE: string;
242
+ /** (4.1) Inserted at the END of the child engine's system prompt when
243
+ * `worktreeCwd` is set. Tells the model two load-bearing facts: the
244
+ * worktree starts from HEAD (parent's uncommitted state is invisible),
245
+ * and writes are sandboxed (parent sees them as a diff after the task
246
+ * completes, not live). Round-1 SHOULD-FIX #2 wording. */
247
+ export declare const ISOLATED_WORKTREE_NOTICE: string;
248
+ /** Renders one `<task-notification>` XML block, fully entity-escaped so
249
+ * `result`/`summary` text containing `<`, `>`, `&`, `"`, `'` can't break
250
+ * the surrounding tag structure or impersonate a different role.
251
+ *
252
+ * This is the format the model receives at the top of its next turn
253
+ * after a background subagent completes. The shape matches the one we
254
+ * (chances-cli's own host) observe receiving from background research
255
+ * subagents — claude-code's `<task_notification>` convention, with our
256
+ * hyphen-separated tag style.
257
+ */
258
+ export declare function renderTaskNotificationXml(n: TaskNotification): string;
259
+ /**
260
+ * (5.4) Build the synthetic resource message for `@<server>:<uri>` mentions.
261
+ * EVERY inserted field — server, uri, body, note — is XML-escaped (codex R1 M5:
262
+ * a malicious resource could otherwise close the tag and inject instructions),
263
+ * exactly like `renderTaskNotificationXml`. The resolver already stripped
264
+ * controls + redacted the body. Returns "" when nothing resolved (the caller
265
+ * skips the message entirely).
266
+ */
267
+ export declare function renderMcpResourcesXml(resolved: ResolvedMention[]): string;
268
+ //# sourceMappingURL=engine.d.ts.map
@@ -0,0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