rovecode 0.3.3 → 0.4.0-beta.3

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 (495) hide show
  1. package/CHANGELOG.md +527 -0
  2. package/README.md +46 -48
  3. package/bin/rovecode.js +24 -0
  4. package/dist/cli/app-j6gn14w3.js +2 -0
  5. package/dist/cli/ask-user-cwstt8fz.js +2 -0
  6. package/dist/cli/auth-login-9bbp9915.js +2 -0
  7. package/dist/cli/auth-m8p9grty.js +2 -0
  8. package/dist/cli/bench-16zqdms5.js +9 -0
  9. package/dist/cli/catalog-1xchffa4.js +2 -0
  10. package/dist/cli/cli-1n1zb64f.js +2 -0
  11. package/dist/cli/client-2t9gjkck.js +2 -0
  12. package/dist/cli/commands-exafvm2b.js +2 -0
  13. package/dist/cli/connect-6zde0kn3.js +2 -0
  14. package/dist/cli/context-cmd-5t43wgqt.js +2 -0
  15. package/dist/cli/context-report-kt01pw8y.js +2 -0
  16. package/dist/cli/count-remote-ap7x3vh6.js +2 -0
  17. package/dist/cli/design-ne5zszyh.js +2 -0
  18. package/dist/cli/dispatch-2r5myxye.js +2 -0
  19. package/dist/cli/doctor-ws4fh4tn.js +3 -0
  20. package/dist/cli/executor-bdrjn634.js +2 -0
  21. package/dist/cli/export-1mxb9g5p.js +2 -0
  22. package/dist/cli/files-g104xghh.js +2 -0
  23. package/dist/cli/gauntlet-07xrjpj7.js +2 -0
  24. package/dist/cli/gauntlet-runner-xvy64436.js +10 -0
  25. package/dist/cli/gauntlet-wave3-jm91yt5w.js +5 -0
  26. package/dist/cli/gauntlet-wave4-r13py7p1.js +14 -0
  27. package/dist/cli/hashline-znvrat11.js +2 -0
  28. package/dist/cli/http-xafw6fsh.js +143 -0
  29. package/dist/cli/index-1sgjm25y.js +2 -0
  30. package/dist/cli/init-g2m0tn4m.js +51 -0
  31. package/dist/cli/install-avaqjjqq.js +2 -0
  32. package/dist/cli/loop-mmpfft01.js +2 -0
  33. package/dist/cli/main-0904f6ps.js +5 -0
  34. package/dist/cli/main-0ab9fc26.js +9 -0
  35. package/dist/cli/main-0jys2ccn.js +3 -0
  36. package/dist/cli/main-0mtcdbs7.js +3 -0
  37. package/dist/cli/main-0z1w2zsg.js +3 -0
  38. package/dist/cli/main-1dchs7xv.js +18 -0
  39. package/dist/cli/main-1ereejm1.js +3 -0
  40. package/dist/cli/main-1k1kw6b5.js +3 -0
  41. package/dist/cli/main-27y4sm2k.js +38 -0
  42. package/dist/cli/main-2wwjex5j.js +58 -0
  43. package/dist/cli/main-2yeveeve.js +6 -0
  44. package/dist/cli/main-2yfck9b5.js +3 -0
  45. package/dist/cli/main-2zmzgkwh.js +3 -0
  46. package/dist/cli/main-351pz3z7.js +7 -0
  47. package/dist/cli/main-3gjqfh7a.js +6 -0
  48. package/dist/cli/main-3nf3kgve.js +3 -0
  49. package/dist/cli/main-3pjrb2hd.js +3 -0
  50. package/dist/cli/main-3rxcvgna.js +19 -0
  51. package/dist/cli/main-4b3jgy66.js +19 -0
  52. package/dist/cli/main-4wndhjdc.js +7 -0
  53. package/dist/cli/main-4xcmvxnk.js +3 -0
  54. package/dist/cli/main-5tbz0wbz.js +4 -0
  55. package/dist/cli/main-5ywnwthm.js +3 -0
  56. package/dist/cli/main-6b62vkz0.js +14 -0
  57. package/dist/cli/main-6dnk69vp.js +3 -0
  58. package/dist/cli/main-6genrmhs.js +136 -0
  59. package/dist/cli/main-73g7eff4.js +15 -0
  60. package/dist/cli/main-7c5thhjd.js +5 -0
  61. package/dist/cli/main-7rn6bqje.js +3 -0
  62. package/dist/cli/main-80haw7qk.js +4 -0
  63. package/dist/cli/main-875s60s2.js +4 -0
  64. package/dist/cli/main-8kjxbpw4.js +8 -0
  65. package/dist/cli/main-90ds1z4e.js +10 -0
  66. package/dist/cli/main-9etavkew.js +3 -0
  67. package/dist/cli/main-a9njrkk1.js +3 -0
  68. package/dist/cli/main-aecrjq2d.js +12 -0
  69. package/dist/cli/main-ck9asesq.js +9 -0
  70. package/dist/cli/main-cta9racd.js +4 -0
  71. package/dist/cli/main-ddv7j2ag.js +3 -0
  72. package/dist/cli/main-dfreez27.js +10 -0
  73. package/dist/cli/main-f7rw7des.js +3 -0
  74. package/dist/cli/main-ggcn7rd7.js +5 -0
  75. package/dist/cli/main-gzkmycnv.js +3 -0
  76. package/dist/cli/main-hq51jg8v.js +18 -0
  77. package/dist/cli/main-jft389w9.js +8 -0
  78. package/dist/cli/main-k1eqkg83.js +3 -0
  79. package/dist/cli/main-k2y8a2aw.js +9 -0
  80. package/dist/cli/main-kcpbykxz.js +4 -0
  81. package/dist/cli/main-kd488vje.js +22 -0
  82. package/dist/cli/main-kh32yvgk.js +5 -0
  83. package/dist/cli/main-kqxnqjnv.js +25 -0
  84. package/dist/cli/main-kyn0xnsg.js +3 -0
  85. package/dist/cli/main-m1kk6fp5.js +21 -0
  86. package/dist/cli/main-mv40pcr2.js +4 -0
  87. package/dist/cli/main-n0t3973w.js +3 -0
  88. package/dist/cli/main-nqveez48.js +4 -0
  89. package/dist/cli/main-pknhvrmj.js +3 -0
  90. package/dist/cli/main-pn1w7a7j.js +3 -0
  91. package/dist/cli/main-prxxs70n.js +4 -0
  92. package/dist/cli/main-q3vsesf9.js +3 -0
  93. package/dist/cli/main-qsevpgsv.js +3 -0
  94. package/dist/cli/main-rdgdw24b.js +25 -0
  95. package/dist/cli/main-rfth4tbm.js +16 -0
  96. package/dist/cli/main-rg0wn0xf.js +5 -0
  97. package/dist/cli/main-sdmxhtv8.js +4 -0
  98. package/dist/cli/main-skbp13js.js +18 -0
  99. package/dist/cli/main-t4xnd213.js +7 -0
  100. package/dist/cli/main-vqak588n.js +4 -0
  101. package/dist/cli/main-w2n1303f.js +9 -0
  102. package/dist/cli/main-wbrdspr2.js +5 -0
  103. package/dist/cli/main-wsrg79c1.js +7 -0
  104. package/dist/cli/main-x4r0fne4.js +5 -0
  105. package/dist/cli/main-xea2f3tn.js +6 -0
  106. package/dist/cli/main-xg704a3c.js +3 -0
  107. package/dist/cli/main-xvnrabfp.js +16 -0
  108. package/dist/cli/main-xy53xf0r.js +4 -0
  109. package/dist/cli/main-y1fqy60y.js +3 -0
  110. package/dist/cli/main-yn8cd281.js +34 -0
  111. package/dist/cli/main-yr0ksc0h.js +4 -0
  112. package/dist/cli/main-z2ex2vyf.js +4 -0
  113. package/dist/cli/main-z3aayzvq.js +3 -0
  114. package/dist/cli/main-zaqh35jg.js +3 -0
  115. package/dist/cli/main-zc2e8e46.js +4 -0
  116. package/dist/cli/main-zzrfw6cf.js +13 -0
  117. package/dist/cli/main.js +280 -0
  118. package/dist/cli/market-cmd-e14kmx9n.js +5 -0
  119. package/dist/cli/mcp-login-wq7ktdek.js +2 -0
  120. package/dist/cli/mcp-market-cmd-9mg3jecy.js +2 -0
  121. package/dist/cli/notify-b7qc0cjb.js +2 -0
  122. package/dist/cli/oauth-z8whcgfx.js +2 -0
  123. package/dist/cli/output-b3ewj3ps.js +16 -0
  124. package/dist/cli/profiles-6mr5he5e.js +2 -0
  125. package/dist/cli/provider-config-g7j42q8x.js +2 -0
  126. package/dist/cli/provider-jr1y8vvm.js +2 -0
  127. package/dist/cli/registry-s8yk86g0.js +2 -0
  128. package/dist/cli/registry-t6p8d4mn.js +2 -0
  129. package/dist/cli/repl-bajwe1mh.js +11 -0
  130. package/dist/cli/resume-rwn9nz7y.js +2 -0
  131. package/dist/cli/run-flags-nah7ndpt.js +2 -0
  132. package/dist/cli/runtime-n7gafzhb.js +2 -0
  133. package/dist/cli/sandbox-config-emdy18x4.js +2 -0
  134. package/dist/cli/server-b0nvs2bn.js +5 -0
  135. package/dist/cli/session-arg-y75wd4kj.js +2 -0
  136. package/dist/cli/session-j62evmjq.js +2 -0
  137. package/dist/cli/sessions-cmd-tsnwz0ns.js +7 -0
  138. package/dist/cli/settings-df10wfez.js +2 -0
  139. package/dist/cli/setup-jzvv72fg.js +2 -0
  140. package/dist/cli/sextant-smoke-37m81ke6.js +5 -0
  141. package/dist/cli/skills-cmd-gjxnxnhx.js +2 -0
  142. package/dist/cli/smoke-p7748apt.js +8 -0
  143. package/dist/cli/start-chat-s4st3mm0.js +12 -0
  144. package/dist/cli/stream-gmeyewds.js +2 -0
  145. package/dist/cli/task-gh0kkp3n.js +2 -0
  146. package/dist/cli/tasks-z1kfpe8e.js +2 -0
  147. package/dist/cli/thinking-0eqkrz6t.js +2 -0
  148. package/dist/cli/todo-5brcrt9m.js +2 -0
  149. package/dist/cli/tools-7pzm0vj9.js +2 -0
  150. package/dist/cli/tools-s635p6s8.js +2 -0
  151. package/dist/cli/trust-cmd-cjav8zgm.js +2 -0
  152. package/dist/cli/update-check-pt31bm2f.js +2 -0
  153. package/dist/cli/update-cmd-tk131s9t.js +2 -0
  154. package/dist/cli/voice-56nabd8d.js +2 -0
  155. package/dist/cli/webfetch-xd8q596m.js +2 -0
  156. package/dist/cli/websearch-5hkf98k1.js +2 -0
  157. package/dist/cli/workflow-cmd-cy3cvzjp.js +4 -0
  158. package/dist/cli/workspace-q10g5z3e.js +2 -0
  159. package/dist/lib/index.js +62 -0
  160. package/dist/lib/models-index.json +1 -0
  161. package/dist/lib/plugins.js +55 -0
  162. package/dist/lib/providers.js +17 -0
  163. package/dist/lib/public-api.js +20 -0
  164. package/dist/lib/sdk.js +360 -0
  165. package/package.json +84 -72
  166. package/bin/rovecode.ts +0 -21
  167. package/src/acp/server.ts +0 -374
  168. package/src/cli/auth-login.ts +0 -122
  169. package/src/cli/connect.ts +0 -244
  170. package/src/cli/context-cmd.ts +0 -199
  171. package/src/cli/dispatch.ts +0 -82
  172. package/src/cli/doctor.ts +0 -362
  173. package/src/cli/export.ts +0 -276
  174. package/src/cli/help.ts +0 -293
  175. package/src/cli/is-tui-invocation.ts +0 -8
  176. package/src/cli/main.ts +0 -583
  177. package/src/cli/market-cmd.ts +0 -658
  178. package/src/cli/mcp-login.ts +0 -141
  179. package/src/cli/mcp-market-cmd.ts +0 -302
  180. package/src/cli/output.ts +0 -382
  181. package/src/cli/repl.ts +0 -250
  182. package/src/cli/repomap-root.ts +0 -14
  183. package/src/cli/resume.ts +0 -57
  184. package/src/cli/run-flags.ts +0 -43
  185. package/src/cli/run-limits.ts +0 -78
  186. package/src/cli/runtime.ts +0 -931
  187. package/src/cli/session-arg.ts +0 -30
  188. package/src/cli/sessions-cmd.ts +0 -145
  189. package/src/cli/setup.ts +0 -153
  190. package/src/cli/skills-cmd.ts +0 -194
  191. package/src/cli/start-chat.ts +0 -65
  192. package/src/cli/trust-cmd.ts +0 -52
  193. package/src/coding/bash.ts +0 -148
  194. package/src/coding/checkpoints.ts +0 -327
  195. package/src/coding/diff.ts +0 -138
  196. package/src/coding/files.ts +0 -341
  197. package/src/coding/hashline.ts +0 -274
  198. package/src/coding/lsp-gate.ts +0 -254
  199. package/src/coding/lsp-servers.ts +0 -147
  200. package/src/coding/lsp.ts +0 -283
  201. package/src/coding/repomap-cache.ts +0 -99
  202. package/src/coding/repomap-files.ts +0 -192
  203. package/src/coding/repomap.ts +0 -481
  204. package/src/core/agents.ts +0 -255
  205. package/src/core/compaction.ts +0 -259
  206. package/src/core/config.ts +0 -289
  207. package/src/core/context-report.ts +0 -228
  208. package/src/core/context.ts +0 -60
  209. package/src/core/count-remote.ts +0 -107
  210. package/src/core/execpolicy-rules.ts +0 -196
  211. package/src/core/execpolicy.ts +0 -385
  212. package/src/core/executor.ts +0 -454
  213. package/src/core/guardrails.ts +0 -400
  214. package/src/core/hooks.ts +0 -411
  215. package/src/core/images.ts +0 -230
  216. package/src/core/intro.ts +0 -266
  217. package/src/core/loop.ts +0 -567
  218. package/src/core/modes.ts +0 -372
  219. package/src/core/orchestrator.ts +0 -245
  220. package/src/core/proc-group.ts +0 -48
  221. package/src/core/project-trust.ts +0 -98
  222. package/src/core/reflection.ts +0 -165
  223. package/src/core/sandbox-config.ts +0 -186
  224. package/src/core/session-id.ts +0 -24
  225. package/src/core/session-images.ts +0 -73
  226. package/src/core/session-ops.ts +0 -183
  227. package/src/core/session-text.ts +0 -29
  228. package/src/core/session.ts +0 -469
  229. package/src/core/settings.ts +0 -170
  230. package/src/core/tasks.ts +0 -646
  231. package/src/core/token-scale.ts +0 -108
  232. package/src/core/tools.ts +0 -309
  233. package/src/core/trust.ts +0 -104
  234. package/src/core/types.ts +0 -330
  235. package/src/core/update-check.ts +0 -171
  236. package/src/core/usage.ts +0 -204
  237. package/src/core/validate.ts +0 -121
  238. package/src/core/verify-gate.ts +0 -159
  239. package/src/core/verify.ts +0 -236
  240. package/src/core/voice.ts +0 -158
  241. package/src/core/win-job.ts +0 -183
  242. package/src/core/workspace.ts +0 -184
  243. package/src/design/audit.ts +0 -797
  244. package/src/design/direction.ts +0 -190
  245. package/src/design/rules.ts +0 -157
  246. package/src/eval/bench.ts +0 -150
  247. package/src/eval/gauntlet-runner.ts +0 -215
  248. package/src/eval/gauntlet-support.ts +0 -84
  249. package/src/eval/gauntlet-wave3.ts +0 -269
  250. package/src/eval/gauntlet-wave4.ts +0 -217
  251. package/src/eval/gauntlet.ts +0 -253
  252. package/src/index.ts +0 -17
  253. package/src/lanes/agy.ts +0 -95
  254. package/src/lanes/approval.ts +0 -24
  255. package/src/lanes/claude.ts +0 -129
  256. package/src/lanes/codex.ts +0 -127
  257. package/src/lanes/events.ts +0 -130
  258. package/src/lanes/job.ts +0 -142
  259. package/src/lanes/opencode.ts +0 -122
  260. package/src/lanes/process.ts +0 -184
  261. package/src/lanes/progress.ts +0 -183
  262. package/src/lanes/registry.ts +0 -178
  263. package/src/lanes/runner.ts +0 -124
  264. package/src/lanes/types.ts +0 -112
  265. package/src/market/catalogs/mcp-docs.json +0 -111
  266. package/src/market/catalogs/plugins.json +0 -111
  267. package/src/market/catalogs/skills.json +0 -478
  268. package/src/market/clone.ts +0 -72
  269. package/src/market/context-cost.ts +0 -121
  270. package/src/market/digest.ts +0 -106
  271. package/src/market/index.ts +0 -22
  272. package/src/market/install.ts +0 -578
  273. package/src/market/manifest.ts +0 -187
  274. package/src/market/prereq.ts +0 -145
  275. package/src/market/registry.ts +0 -363
  276. package/src/market/resolve.ts +0 -111
  277. package/src/market/types.ts +0 -236
  278. package/src/market/validate.ts +0 -227
  279. package/src/mcp/client.ts +0 -449
  280. package/src/mcp/config.ts +0 -252
  281. package/src/mcp/local-package.ts +0 -211
  282. package/src/mcp/market-catalog.ts +0 -84
  283. package/src/mcp/market-install.ts +0 -289
  284. package/src/mcp/market.ts +0 -362
  285. package/src/mcp/oauth.ts +0 -251
  286. package/src/mcp/prompts-resources.ts +0 -249
  287. package/src/mcp/shared.ts +0 -149
  288. package/src/mcp/status.ts +0 -67
  289. package/src/mcp/tools.ts +0 -275
  290. package/src/mcp/transport.ts +0 -122
  291. package/src/mcp/trust.ts +0 -25
  292. package/src/memory/blocks.ts +0 -278
  293. package/src/memory/recall.ts +0 -355
  294. package/src/memory/scope.ts +0 -182
  295. package/src/memory/store.ts +0 -105
  296. package/src/memory/tools.ts +0 -99
  297. package/src/plugins/cli.ts +0 -119
  298. package/src/plugins/discover.ts +0 -108
  299. package/src/plugins/index.ts +0 -50
  300. package/src/plugins/install.ts +0 -184
  301. package/src/plugins/load.ts +0 -124
  302. package/src/plugins/manifest.ts +0 -92
  303. package/src/plugins/state.ts +0 -83
  304. package/src/providers/auth.ts +0 -408
  305. package/src/providers/cache.ts +0 -223
  306. package/src/providers/catalog-local.ts +0 -160
  307. package/src/providers/catalog.ts +0 -421
  308. package/src/providers/middleware-context.ts +0 -86
  309. package/src/providers/middleware.ts +0 -373
  310. package/src/providers/model-list.ts +0 -23
  311. package/src/providers/oauth/common.ts +0 -105
  312. package/src/providers/oauth/device-code.ts +0 -107
  313. package/src/providers/oauth/github-copilot.ts +0 -146
  314. package/src/providers/oauth/loopback.ts +0 -158
  315. package/src/providers/oauth/openai.ts +0 -163
  316. package/src/providers/oauth/openrouter.ts +0 -89
  317. package/src/providers/oauth/pkce.ts +0 -45
  318. package/src/providers/oauth/registry.ts +0 -39
  319. package/src/providers/oauth/seam.ts +0 -89
  320. package/src/providers/profile-glm53.ts +0 -111
  321. package/src/providers/profile-sonnet5-persona.ts +0 -65
  322. package/src/providers/profile-sonnet5-voice.ts +0 -23
  323. package/src/providers/profiles.ts +0 -156
  324. package/src/providers/provider-config.ts +0 -311
  325. package/src/providers/registry.ts +0 -333
  326. package/src/providers/responses.ts +0 -209
  327. package/src/providers/retry.ts +0 -234
  328. package/src/providers/router.ts +0 -294
  329. package/src/providers/sse.ts +0 -26
  330. package/src/providers/stream-errors.ts +0 -117
  331. package/src/providers/stream.ts +0 -566
  332. package/src/providers/thinking.ts +0 -189
  333. package/src/providers/wire-messages.ts +0 -129
  334. package/src/providers/wire-responses.ts +0 -79
  335. package/src/providers/wire-select.ts +0 -53
  336. package/src/server/http.ts +0 -291
  337. package/src/server/openapi.ts +0 -246
  338. package/src/sextant/card-hits.ts +0 -102
  339. package/src/sextant/card-keys.ts +0 -55
  340. package/src/sextant/context-source.ts +0 -157
  341. package/src/sextant/crew-cards.ts +0 -350
  342. package/src/sextant/draw-agents.ts +0 -273
  343. package/src/sextant/draw-code.ts +0 -388
  344. package/src/sextant/draw-context.ts +0 -222
  345. package/src/sextant/draw-frame.ts +0 -164
  346. package/src/sextant/draw-market.ts +0 -573
  347. package/src/sextant/draw-messages.ts +0 -386
  348. package/src/sextant/draw-pet.ts +0 -230
  349. package/src/sextant/draw-plan.ts +0 -187
  350. package/src/sextant/draw-tabs.ts +0 -85
  351. package/src/sextant/draw-util.ts +0 -65
  352. package/src/sextant/draw-wizard.ts +0 -378
  353. package/src/sextant/engine.ts +0 -230
  354. package/src/sextant/frame-hits.ts +0 -25
  355. package/src/sextant/frame.ts +0 -101
  356. package/src/sextant/git-status.ts +0 -197
  357. package/src/sextant/grid.ts +0 -59
  358. package/src/sextant/input.ts +0 -119
  359. package/src/sextant/keys.ts +0 -521
  360. package/src/sextant/layout.ts +0 -86
  361. package/src/sextant/local-commands.ts +0 -169
  362. package/src/sextant/market-source.ts +0 -287
  363. package/src/sextant/mentions.ts +0 -200
  364. package/src/sextant/message-hits.ts +0 -26
  365. package/src/sextant/model.ts +0 -387
  366. package/src/sextant/overlays.ts +0 -456
  367. package/src/sextant/panel-hits.ts +0 -38
  368. package/src/sextant/pet.ts +0 -399
  369. package/src/sextant/screen.ts +0 -324
  370. package/src/sextant/scroll-hits.ts +0 -66
  371. package/src/sextant/scrollbar.ts +0 -82
  372. package/src/sextant/sextant-bridge.ts +0 -174
  373. package/src/sextant/sextant-cards.ts +0 -142
  374. package/src/sextant/sextant-diff-base.ts +0 -63
  375. package/src/sextant/sextant-files.ts +0 -154
  376. package/src/sextant/sextant-frame-loop.ts +0 -335
  377. package/src/sextant/sextant-renderer.ts +0 -574
  378. package/src/sextant/sextant-repo.ts +0 -140
  379. package/src/sextant/theme.ts +0 -66
  380. package/src/sextant/tool-rows.ts +0 -189
  381. package/src/sextant/types.ts +0 -493
  382. package/src/skills/index.ts +0 -387
  383. package/src/skills/pack.ts +0 -220
  384. package/src/skills/spec.ts +0 -162
  385. package/src/skills/tools.ts +0 -69
  386. package/src/skills/versioned.ts +0 -227
  387. package/src/telemetry/otel-export.ts +0 -122
  388. package/src/telemetry/otel-lanes.ts +0 -89
  389. package/src/telemetry/otel-logs.ts +0 -131
  390. package/src/telemetry/otel-metrics.ts +0 -136
  391. package/src/telemetry/otel.ts +0 -397
  392. package/src/telemetry/otlp.ts +0 -76
  393. package/src/tools/ask-user.ts +0 -156
  394. package/src/tools/bash-bg.ts +0 -94
  395. package/src/tools/bash-jobs.ts +0 -237
  396. package/src/tools/design.ts +0 -151
  397. package/src/tools/evalcell.ts +0 -338
  398. package/src/tools/html-text.ts +0 -139
  399. package/src/tools/provider.ts +0 -149
  400. package/src/tools/task.ts +0 -250
  401. package/src/tools/todo.ts +0 -320
  402. package/src/tools/webfetch.ts +0 -332
  403. package/src/tools/websearch.ts +0 -359
  404. package/src/tui/agents-cmd.ts +0 -41
  405. package/src/tui/app.ts +0 -749
  406. package/src/tui/attach.ts +0 -127
  407. package/src/tui/boot-notes.ts +0 -41
  408. package/src/tui/builtin-prompts.ts +0 -59
  409. package/src/tui/checkpoints-cmd.ts +0 -70
  410. package/src/tui/clipboard-image.ts +0 -81
  411. package/src/tui/clipboard.ts +0 -78
  412. package/src/tui/commands.ts +0 -283
  413. package/src/tui/config-view.ts +0 -53
  414. package/src/tui/context-cmds.ts +0 -282
  415. package/src/tui/cost.ts +0 -108
  416. package/src/tui/crash-guard.ts +0 -173
  417. package/src/tui/focus-terminal.ts +0 -34
  418. package/src/tui/git-cmds.ts +0 -273
  419. package/src/tui/git-plain.ts +0 -58
  420. package/src/tui/info-cmd.ts +0 -150
  421. package/src/tui/input-plain.ts +0 -76
  422. package/src/tui/mcp-cmd.ts +0 -128
  423. package/src/tui/memory-note.ts +0 -77
  424. package/src/tui/modes-cmd.ts +0 -45
  425. package/src/tui/notify-seq.ts +0 -100
  426. package/src/tui/notify.ts +0 -318
  427. package/src/tui/overlays.ts +0 -97
  428. package/src/tui/pi-renderer.ts +0 -428
  429. package/src/tui/providers-cmd.ts +0 -377
  430. package/src/tui/reasoning-view.ts +0 -56
  431. package/src/tui/renderer.ts +0 -128
  432. package/src/tui/replay-marker.ts +0 -29
  433. package/src/tui/session-cmd.ts +0 -148
  434. package/src/tui/session-manage.ts +0 -95
  435. package/src/tui/sextant-attach.ts +0 -102
  436. package/src/tui/sextant-io.ts +0 -202
  437. package/src/tui/sextant-smoke.ts +0 -110
  438. package/src/tui/shell-cmd.ts +0 -158
  439. package/src/tui/smoke.ts +0 -72
  440. package/src/tui/staged-terminal.ts +0 -50
  441. package/src/tui/startup.ts +0 -12
  442. package/src/tui/theme.ts +0 -59
  443. package/src/tui/todo-label.ts +0 -7
  444. package/src/tui/trust-card.ts +0 -107
  445. package/src/tui/tui-commands.ts +0 -87
  446. package/tsconfig.json +0 -30
  447. package/vendor/pi-tui/LICENSE +0 -21
  448. package/vendor/pi-tui/PATCHES.md +0 -12
  449. package/vendor/pi-tui/PROVENANCE.md +0 -12
  450. package/vendor/pi-tui/README.upstream.md +0 -854
  451. package/vendor/pi-tui/native/win32/prebuilds/win32-arm64/win32-console-mode.node +0 -0
  452. package/vendor/pi-tui/native/win32/prebuilds/win32-x64/win32-console-mode.node +0 -0
  453. package/vendor/pi-tui/src/alt-screen-search.ts +0 -158
  454. package/vendor/pi-tui/src/autocomplete.ts +0 -827
  455. package/vendor/pi-tui/src/components/alt-screen-flash.ts +0 -52
  456. package/vendor/pi-tui/src/components/box.ts +0 -138
  457. package/vendor/pi-tui/src/components/cancellable-loader.ts +0 -41
  458. package/vendor/pi-tui/src/components/editor.ts +0 -2364
  459. package/vendor/pi-tui/src/components/h-stack.ts +0 -45
  460. package/vendor/pi-tui/src/components/image.ts +0 -128
  461. package/vendor/pi-tui/src/components/input.ts +0 -448
  462. package/vendor/pi-tui/src/components/loader.ts +0 -93
  463. package/vendor/pi-tui/src/components/markdown.ts +0 -1016
  464. package/vendor/pi-tui/src/components/scroll-view.ts +0 -217
  465. package/vendor/pi-tui/src/components/select-list.ts +0 -230
  466. package/vendor/pi-tui/src/components/settings-list.ts +0 -277
  467. package/vendor/pi-tui/src/components/spacer.ts +0 -29
  468. package/vendor/pi-tui/src/components/stack.ts +0 -155
  469. package/vendor/pi-tui/src/components/text.ts +0 -108
  470. package/vendor/pi-tui/src/components/truncated-text.ts +0 -66
  471. package/vendor/pi-tui/src/components/v-stack.ts +0 -34
  472. package/vendor/pi-tui/src/editor-component.ts +0 -75
  473. package/vendor/pi-tui/src/fuzzy.ts +0 -138
  474. package/vendor/pi-tui/src/index.ts +0 -149
  475. package/vendor/pi-tui/src/keybindings.ts +0 -321
  476. package/vendor/pi-tui/src/keys.ts +0 -1402
  477. package/vendor/pi-tui/src/kill-ring.ts +0 -47
  478. package/vendor/pi-tui/src/latex.ts +0 -1381
  479. package/vendor/pi-tui/src/layout-node.ts +0 -52
  480. package/vendor/pi-tui/src/layout.ts +0 -411
  481. package/vendor/pi-tui/src/native-modifiers.ts +0 -60
  482. package/vendor/pi-tui/src/native-module-path.ts +0 -32
  483. package/vendor/pi-tui/src/stdin-buffer.ts +0 -445
  484. package/vendor/pi-tui/src/terminal-colors.ts +0 -74
  485. package/vendor/pi-tui/src/terminal-image.ts +0 -701
  486. package/vendor/pi-tui/src/terminal.ts +0 -554
  487. package/vendor/pi-tui/src/tui-alt-screen.ts +0 -1379
  488. package/vendor/pi-tui/src/tui-main-screen.ts +0 -655
  489. package/vendor/pi-tui/src/tui.ts +0 -1264
  490. package/vendor/pi-tui/src/undo-stack.ts +0 -29
  491. package/vendor/pi-tui/src/utils.ts +0 -1327
  492. package/vendor/pi-tui/src/word-navigation.ts +0 -118
  493. package/vendor/pi-tui/test/test-themes.ts +0 -39
  494. package/vendor/pi-tui/test/virtual-terminal.ts +0 -219
  495. /package/{src/providers → dist/cli}/models-index.json +0 -0
@@ -0,0 +1,6 @@
1
+ // @bun
2
+ import{wn as w}from"./main-qsevpgsv.js";import{dlopen as a,FFIType as J,ptr as U}from"bun:ffi";function zq(){if(N===void 0){if(N=null,process.platform==="win32")try{N=a("kernel32.dll",{CreateJobObjectW:{args:[J.ptr,J.ptr],returns:J.ptr},SetInformationJobObject:{args:[J.ptr,J.i32,J.ptr,J.u32],returns:J.i32},AssignProcessToJobObject:{args:[J.ptr,J.ptr],returns:J.i32},TerminateJobObject:{args:[J.ptr,J.u32],returns:J.i32},OpenProcess:{args:[J.u32,J.i32,J.u32],returns:J.ptr},CloseHandle:{args:[J.ptr],returns:J.i32},CreateToolhelp32Snapshot:{args:[J.u32,J.u32],returns:J.ptr},Process32FirstW:{args:[J.ptr,J.ptr],returns:J.i32},Process32NextW:{args:[J.ptr,J.ptr],returns:J.i32}})}catch{N=null}}return N?N.symbols:null}function I(){if(qq===!1)return null;let q=zq();if(!q)return null;let Q=q.CreateJobObjectW(null,null);if(!M(Q))return null;let z=new Uint8Array(D);if(new DataView(z.buffer).setUint32(t,s,!0),!q.SetInformationJobObject(Q,E,U(z),D))return q.CloseHandle(Q),null;let V=Q,W=()=>{if(V!==null)q.CloseHandle(V),V=null},Y=($)=>{if(V===null)return!1;let H=q.OpenProcess(o,0,$);if(!M(H))return!1;try{return q.AssignProcessToJobObject(V,H)!==0}finally{q.CloseHandle(H)}};return{assign($){if(!Y($))return W(),!1;for(let H of Qq(q,$))Y(H);return!0},terminate(){if(V===null)return;q.TerminateJobObject(V,1),W()},release(){if(V===null)return;q.SetInformationJobObject(V,E,U(new Uint8Array(D)),D),W()}}}function Qq(q,Q){let z=q.CreateToolhelp32Snapshot(n,0);if(!M(z))return[];let V=new Map;try{let H=new Uint8Array(m),Z=new DataView(H.buffer);if(Z.setUint32(0,m,!0),!q.Process32FirstW(z,U(H)))return[];do{let X=Z.getUint32(r,!0),G=Z.getUint32(e,!0),B=V.get(G);if(B)B.push(X);else V.set(G,[X])}while(q.Process32NextW(z,U(H)))}finally{q.CloseHandle(z)}let W=new Set([Q]),Y=[],$=[Q];while($.length>0)for(let H of V.get($.pop())??[])if(!W.has(H))W.add(H),Y.push(H),$.push(H);return Y}var s=8192,E=9,D=144,t=16,o=257,n=2,m=568,r=8,e=32,N,qq=null,M=(q)=>typeof q==="number"&&q>0&&q<=4294967295;var h=()=>{};function T(q){return q==="win32"?{}:{detached:!0}}function R(q,Q,z=Vq){if(!(q>0))return!1;try{return z(-q,Q),!0}catch{return!1}}var Vq=(q,Q)=>{process.kill(q,Q)};var F=()=>{};import{existsSync as Yq}from"fs";function b(q,Q){let z=[],V=q.getReader();return{done:(async()=>{for(let Y=await V.read();!Y.done;Y=await V.read())if(Y.value)z.push(Y.value),Q?.(Y.value)})().catch(()=>{}),text:()=>new TextDecoder().decode(Buffer.concat(z)),cancel:()=>{V.cancel().catch(()=>{})}}}function Jq(q,Q){if(!Q)return{treeKill:!1,grouped:!1};return q==="win32"?{treeKill:!0,grouped:!1}:{treeKill:!1,grouped:!0}}function _(q,Q){return(q+(Q?`
3
+ stderr:
4
+ ${Q}`:"")).slice(0,Xq)}function Zq(){if(K!==null)return K;if(process.platform!=="win32")return K="bash";let q="C:/Program Files/Git/bin/bash.exe";return K=Yq(q)?q:"bash",K}function c(q){return q.replace(/\u0000/g,"").trim().slice(0,200)}async function g(q,Q,z){let V={code:-1,stdout:"",stderr:`probe timed out after ${z}ms`},W,Y=new Promise(($)=>{W=setTimeout(()=>$(V),z)});try{let $=await Promise.race([q(Q,{signal:AbortSignal.timeout(z)}),Y]);return{r:$,timedOut:$===V}}finally{clearTimeout(W)}}async function d(q,Q=C,z=process.platform,V={}){let W=V.timeoutMs??Pq;switch(q){case"direct":return{rung:q,available:!0,detail:"always available \u2014 today's in-process bash (blocklist only, NOT a sandbox)"};case"wsl":{if(z!=="win32")return{rung:q,available:!1,detail:`wsl rung requires Windows wsl.exe (platform is ${z})`};let Y="wsl.exe --exec bash -c true",{r:$,timedOut:H}=await g(Q,["wsl.exe","--exec","bash","-c","true"],W);if(H)return{rung:q,available:!1,detail:`wsl trial (${Y}) timed out after ${W}ms \u2014 wrapper did not answer (a cold WSL utility-VM boot exceeds this cap); warm it with the same command and reconfigure`};return $.code===0?{rung:q,available:!0,detail:`wsl trial (${Y}) ok`}:{rung:q,available:!1,detail:`wsl trial (${Y}) exited ${$.code}: ${c($.stderr||$.stdout)||"no output"}`}}case"docker":{let Y=V.dockerImage??u,$=`docker run --rm ${Y} bash -c true`,{r:H,timedOut:Z}=await g(Q,["docker","run","--rm",Y,"bash","-c","true"],W);if(Z)return{rung:q,available:!1,detail:`docker trial (${$}) timed out after ${W}ms \u2014 daemon wedged or pulling the image; pre-pull it and retry`};return H.code===0?{rung:q,available:!0,detail:`docker trial (${$}) ok`}:{rung:q,available:!1,detail:`docker trial (${$}) exited ${H.code}: ${c(H.stderr||H.stdout)||"no output"}`}}}}function Cq(q=C,Q=process.platform,z={}){return Promise.all($q.map((V)=>d(V,q,Q,z)))}function l(q){return{rung:"direct",async run(Q,z,V,W){let Y=await q([Zq(),"-c",Q],{cwd:z,signal:V,...W?{observe:W}:{}});return{code:Y.code,text:_(Y.stdout,Y.stderr)}}}}function Gq(q){return{rung:"wsl",async run(Q,z,V,W){let Y=await q(["wsl.exe","--cd",z,"--exec","bash","-c",Q],{cwd:z,signal:V,...W?{observe:W}:{}});return{code:Y.code,text:_(Y.stdout,Y.stderr)}}}}function Bq(q,Q){return{rung:"docker",async run(z,V,W,Y){let $=["docker","run","--rm","-v",`${V}:/workspace`,"-w","/workspace",Q,"bash","-c",z],H=await q($,{cwd:V,signal:W,...Y?{observe:Y}:{}});return{code:H.code,text:_(H.stdout,H.stderr)}}}}async function Nq(q,Q={}){let z=Q.runner??C,V=await d(q,z,Q.platform??process.platform,{dockerImage:Q.dockerImage});if(!V.available)throw new A(q,V.detail);switch(q){case"direct":return l(z);case"wsl":return Gq(z);case"docker":return Bq(z,Q.dockerImage??u)}}async function Aq(q,Q){x=q;try{return L=await Nq(q,Q),O=null,L}catch(z){throw O=z instanceof A?z.detail:z instanceof Error?z.message:String(z),z}}function Sq(){if(L?.rung===x)return L;if(x==="direct")return L=l(C);throw new A(x,O??`configureExecutor('${x}') has not succeeded; the seam refuses to substitute another rung`)}function fq(){L=null,x="direct",O=null}var $q,Wq=500,Hq="[output truncated: process tree terminated on abort]",C=async(q,Q)=>{let z=Q.signal,{treeKill:V,grouped:W}=Jq(process.platform,z!==void 0);if((V||W)&&z?.aborted)return{code:143,stdout:"",stderr:"aborted before spawn"};let Y,$=null,H=!1,Z;try{let X=Bun.spawn([...q],{cwd:Q.cwd,signal:V||W?void 0:z,stdout:"pipe",stderr:"pipe",...W?T(process.platform):{}});Q.observe?.onSpawn?.(X.pid);let G=Q.observe,B=b(X.stdout,G?.onChunk?(P)=>G.onChunk("stdout",P):void 0),S=b(X.stderr,G?.onChunk?(P)=>G.onChunk("stderr",P):void 0),k=Promise.all([B.done,S.done,X.exited]).then(()=>"done"),v,p=new Promise((P)=>{v=()=>P("grace")});if(z){if(V){if($=I(),$&&!$.assign(X.pid))$=null}Y=()=>{let P=X.exitCode===null;if(H=V||W,V){if($?.terminate(),P)try{Bun.spawn(["taskkill","/T","/F","/PID",String(X.pid)],{stdout:"ignore",stderr:"ignore"})}catch{}}if(W){if(R(X.pid,"SIGTERM"),P)try{X.kill("SIGTERM")}catch{}}Z=setTimeout(v,Wq)},z.addEventListener("abort",Y,{once:!0}),k.then(()=>{if(Y)z.removeEventListener("abort",Y)},()=>{})}let j=await Promise.race([k,p]);if(j==="grace"&&W)R(X.pid,"SIGKILL");if(j==="grace")B.cancel(),S.cancel();let i=H||j==="grace"?143:await X.exited,f=S.text();if(j==="grace")f+=(f?`
5
+ `:"")+Hq;let y={code:i,stdout:B.text(),stderr:f};if(V)y.treeKill=$?"job":"taskkill-only";return y}catch(X){return{code:-1,stdout:"",stderr:`spawn failed: ${X instanceof Error?X.message:String(X)}`}}finally{if(clearTimeout(Z),H)$?.terminate();else $?.release();if(Y)z?.removeEventListener("abort",Y)}},Xq=1e4,K=null,Pq=500,A,u="debian:stable-slim",L=null,x="direct",O=null;var xq=w(()=>{h();F();$q=["direct","wsl","docker"];A=class A extends Error{rung;detail;constructor(q,Q){super(`executor rung '${q}' is unavailable: ${Q}. `+"Refusing to fall back down the ladder \u2014 pick an available rung explicitly "+`(probeLadder() reports availability) or make '${q}' usable and retry.`);this.name="RungUnavailableError",this.rung=q,this.detail=Q}}});
6
+ export{I as $h,h as ai,T as bi,R as ci,F as di,$q as ei,Wq as fi,Hq as gi,Jq as hi,C as ii,Xq as ji,Pq as ki,d as li,Cq as mi,A as ni,u as oi,Nq as pi,Aq as qi,Sq as ri,fq as si,xq as ti};
@@ -0,0 +1,3 @@
1
+ // @bun
2
+ var N=8,O=80,P=2000,S="ask_user unavailable: no interactive user in this session (headless run/serve/acp) \u2014 proceed with your best judgment or stop",U="ask_user aborted",V="user declined to answer";function L(B){let j=B&&typeof B==="object"?B:{},C=typeof j.question==="string"?j.question.trim():"";if(C==="")return"question must be a non-empty string";if(C.length>2000)return`question too long (${C.length} chars, max 2000)`;let z;if(j.options!==void 0&&j.options!==null){if(!Array.isArray(j.options))return"options must be an array of strings";if(j.options.length>8)return`too many options (${j.options.length}, max 8)`;z=[];for(let G of j.options){if(typeof G!=="string"||G.trim()==="")return"every option must be a non-empty string";let I=G.trim();if(I.length>80)return`option too long (${I.length} chars, max 80): ${I.slice(0,40)}\u2026`;z.push(I)}if(z.length===0)z=void 0}if(j.allowFreeText!==void 0&&typeof j.allowFreeText!=="boolean")return"allowFreeText must be a boolean";let E=j.allowFreeText!==!1;if(!z&&!E)return"nothing to answer with: provide options or allow free text";return{question:C,...z?{options:z}:{},allowFreeText:E}}function M(B,j){let C=typeof B.text==="string"?B.text.trim():"";if(C!=="")return{ok:!0,output:`answer: ${C}`,data:{text:C}};let z=j.options??[];if(typeof B.choice==="number"&&Number.isInteger(B.choice)&&B.choice>=0&&B.choice<z.length){let E=z[B.choice];return{ok:!0,output:`answer: ${E}`,data:{choice:B.choice,label:E}}}return{ok:!1,output:"ask_user failed: the surface returned an unusable answer"}}function W(B){return{schema:{name:"ask_user",description:"Ask the user ONE clarifying question and wait for the answer. Use it when instructions are "+"ambiguous, a decision has real consequences, or you must pick between approaches \u2014 do not guess. "+`Give up to ${"8"} short options (\u2264${"80"} chars each); the user may also type a free-text answer unless allowFreeText is false. If you recommend an option, list it first and append `+'"(recommended)"; never add an "Other" option \u2014 the free-text entry covers it. The result is '+"`answer: <chosen option or typed text>`. A declined or aborted question, or a session with no interactive user (headless run/serve/acp), returns an error: then proceed with your best judgment or stop.",args:{type:"object",properties:{question:{type:"string",description:"the complete question \u2014 clear, specific, one decision"},options:{type:"array",items:{type:"string"},maxItems:8,description:`up to ${"8"} answer choices, \u2264${"80"} chars each (recommended one first)`},allowFreeText:{type:"boolean",description:"also accept a typed free-form answer (default true)"}},required:["question"]}},kind:"read",sequential:!0,async execute(j,C){let z=L(j);if(typeof z==="string")return{ok:!1,output:`ask_user failed: ${z}`};let E=B();if(!E)return{ok:!1,output:"ask_user unavailable: no interactive user in this session (headless run/serve/acp) \u2014 proceed with your best judgment or stop"};if(C.signal.aborted)return{ok:!1,output:"ask_user aborted"};let G,I=new Promise((H)=>{G=()=>H("aborted"),C.signal.addEventListener("abort",G,{once:!0})});try{let H=new Promise((K)=>K(E(z,C.signal))),J=await Promise.race([H.then((K)=>({answer:K})),I]);if(J==="aborted"||C.signal.aborted)return{ok:!1,output:"ask_user aborted"};if(J.answer===null)return{ok:!1,output:"user declined to answer"};return M(J.answer,z)}catch(H){return{ok:!1,output:`ask_user failed: ${H instanceof Error?H.message:String(H)}`}}finally{if(G)C.signal.removeEventListener("abort",G)}}}}
3
+ export{N as tg,O as ug,P as vg,S as wg,U as xg,V as yg,L as zg,W as Ag};
@@ -0,0 +1,3 @@
1
+ // @bun
2
+ import{wn as j}from"./main-qsevpgsv.js";var k,p=(c)=>typeof c==="string"&&k.includes(c),q=()=>({garbage:0,scratch:{}});var m=j(()=>{k=["claude","codex","opencode","agy"]});
3
+ export{k as Ue,p as Ve,q as We,m as Xe};
@@ -0,0 +1,19 @@
1
+ // @bun
2
+ import{Nl as c,Rl as IQ}from"./main-ggcn7rd7.js";import{dm as RJ,fm as EJ,mm as YQ}from"./main-prxxs70n.js";import{wn as f,xn as _Q}from"./main-qsevpgsv.js";function PJ(J,Q){let Z=J.trim(),z=Z.indexOf("/");if(z<=0)return{provider:Q,model:Z};return{provider:Z.slice(0,z),model:Z.slice(z+1)}}function sJ(J,Q){return J.split(",").map((Z)=>Z.trim()).filter(Boolean).map((Z)=>PJ(Z,Q))}function TQ(J,Q=process.env){let Z={};for(let z of t){let X=Q[tJ[z]];if(X&&X.trim().length>0){let G=sJ(X,J.provider);if(G.length>0)Z[z]=G}}return{...Z,default:Z.default??[J]}}function eJ(J){let Q=/^HTTP (\d{3})\b/.exec(J??"");if(Q){let Z=Number(Q[1]);return{status:Z,retryable:Z===429||Z>=500&&Z<600}}if((J??"").startsWith("config: "))return{retryable:!1};return{retryable:!0}}function jJ(J){return e.get(J)}function xQ(J){let Q=new Map;for(let G of t){let W=J.roles[G];if(!W)continue;let B=Array.isArray(W)?W:[W];if(B.length>0)Q.set(G,B)}let Z=Q.get("default");if(!Z)throw Error("router: roles.default must contain at least one ModelRef");let z=(G)=>Q.get(G)??Z,X=(G)=>{let W=null;for(let K of t){let V=Q.get(K);if(!V)continue;let Y=V.findIndex(($)=>JQ($,G));if(Y===0)return{key:K,chain:V,index:0};if(Y>0&&W===null)W={key:K,chain:V,index:Y}}if(W)return W;let B=J.looseFallback===!0?[G,...Z]:[G];return{key:QQ(G),chain:B,index:0}};return{chain:z,resolve(G,W){let K=z(G)[0];if(W!==void 0)return typeof W==="string"?PJ(W,K.provider):W;return K},wrap(G){let W=J.sticky??!0,B=new Map;return async function*(K,V,Y){let{key:$,chain:q,index:j}=X(K),P=W?Math.min(Math.max(j,B.get($)??0),q.length-1):j,N=null;for(let O=P;O<q.length;O++){let R=q[O],w=null,E=!1;try{for await(let S of G(R,V,Y))if(S.type==="turn")w=S.turn;else{if(S.type==="text_delta"||S.type==="reasoning_delta")E=!0;yield S}}catch(S){w=s(S instanceof Error?S.message:String(S))}let b=w??s("stream ended without a terminal turn"),T=Y?.signal?.aborted===!0;if(b.stopReason!=="error"||T||E||!eJ(b.error).retryable||q.length===1){e.set(b,R),yield{type:"turn",turn:b};return}N=b;let h=O+1<q.length?q[O+1]:null;if(W&&h!==null)B.set($,O+1);J.onNote?.({chain:$,from:R,to:h,reason:b.error??"error"})}if(W)B.delete($);let U=q.length-P,M=s(`model chain '${$}' exhausted (${U} candidate${U===1?"":"s"} failed); last: ${N?.error??"unknown error"}`);e.set(M,q[q.length-1]),yield{type:"turn",turn:M}}}}}var t,tJ,e,JQ=(J,Q)=>J.provider===Q.provider&&J.model===Q.model,QQ=(J)=>`${J.provider}/${J.model}`,ZQ=()=>({input:0,output:0}),s=(J)=>({parts:[],stopReason:"error",usage:ZQ(),error:J});var MJ=f(()=>{t=["default","smol","plan","commit","task"];tJ={default:"ROVECODE_MODEL_DEFAULT",smol:"ROVECODE_MODEL_SMOL",plan:"ROVECODE_MODEL_PLAN",commit:"ROVECODE_MODEL_COMMIT",task:"ROVECODE_MODEL_TASK"};e=new WeakMap});function k(J){return Math.ceil(J.length/4)}function DJ(J,Q){let Z=[...J].sort((Y,$)=>$.priority-Y.priority),z=Z.filter((Y)=>Y.name!=="history"),X=[],G=[...z],W=Z.find((Y)=>Y.name==="history"),B=W?.tokens??0;while(G.length>0&&G.reduce((Y,$)=>Y+$.tokens,0)+B>Q){let Y=G.pop();X.push(Y)}let K=G.reduce((Y,$)=>Y+$.tokens,0)+B,V=[...G];if(W)V.push(W);return{chunks:V,dropped:X,totalTokens:K,overBudget:K>Q}}function NJ(J,Q){if(J.reduce((W,B)=>W+B.tokens,0)<=Q*0.8)return{keep:J,summarize:[]};let z=Math.floor(Q/2),X=0,G=J.length;for(let W=J.length-1;W>=0;W--){if(X+=J[W].tokens,X>z){G=W+1;break}G=W}return{keep:J.slice(G),summarize:J.slice(0,G)}}var JJ=()=>{};import{randomUUID as CJ}from"crypto";function mQ(J){let Q=(J??"").trim().toLowerCase();if(Q==="")return;if(LJ.includes(Q))return Q;if(!_J.has(Q))_J.add(Q),console.error(`rovecode: unknown ROVECODE_COMPACTION "${(J??"").trim()}" \u2014 using ${QJ} (known: ${LJ.join(", ")})`);return}function SJ(J,Q,Z){if(Z)return"emergency";return J>Q.contextBudgetTokens*Q.compactionThreshold?"speculative":null}function UJ(J){if(!J||zQ.some((Z)=>Z.test(J)))return!1;let Q=/(?:^|last: )HTTP (\d{3})\b/.exec(J)?.[1];if(Q==="413")return!0;if(Q==="429"||Q?.startsWith("5"))return!1;return XQ.some((Z)=>Z.test(J))}function KQ(J,Q,Z){if(Z==="speculative")return J.contextBudgetTokens;return Math.max(1,Math.floor(Math.min(J.contextBudgetTokens,Q)/2))}function WQ(J,Q){if(J==="keep-window")return"keep-window";if(J==="provider-native"&&Q.native)return"provider-native";if(Q.summarize)return"head-summarize";return Q.trigger==="emergency"?"keep-window":null}function ZJ(J,Q,Z){let z=Q.compactionStrategy??QJ,X=WQ(z,Z);if(!X)return null;let G=($)=>k(Z.tokenText($)),W=J.reduce(($,q)=>$+G(q),0),B=KQ(Q,W,Z.trigger),K={strategy:X,tokensBefore:W,budgetTokens:B,...X!==z?{fallbackFrom:z}:{}};if(X==="provider-native")return{...K,keep:J,drop:[],summaryNeeded:!1};if(X==="keep-window"){let $=Z.trigger==="emergency"?0:Q.compactionKeepTurns??$Q;return{...K,...BQ(J,G,B,$),summaryNeeded:!1}}let V=NJ(J.map(($)=>({id:$.id,tokens:G($),text:Z.tokenText($)})),B),Y=new Set(V.keep.map(($)=>$.id));if(Y.size===0&&J.length>0){let $=J.length-1;while($>0&&J[$].role==="tool")$--;for(let q of J.slice($))Y.add(q.id)}return{...K,keep:J.filter(($)=>Y.has($.id)),drop:J.filter(($)=>!Y.has($.id)),summaryNeeded:!0}}function BQ(J,Q,Z,z){let X=Math.floor(Z/2),G=(Y)=>Y.reduce(($,q)=>$+Q(q),0),W=J.flatMap((Y,$)=>Y.role==="user"?[$]:[]),B=Math.max(0,W.length-1-Math.max(0,z)),K=W.length>0?W[B]:0;while(G(J.slice(K))>X&&B<W.length-1)K=W[++B];let V=W.at(-1);if(V!==void 0&&K===V&&G(J.slice(K))>X){let Y=V+1;while(Y<J.length&&Q(J[V])+G(J.slice(Y))>X){let $=OJ(J,Y+1);if($<=Y||$>=J.length)break;Y=$}return{keep:[J[V],...J.slice(Y)],drop:[...J.slice(0,V),...J.slice(V+1,Y)]}}if(W.length===0)while(G(J.slice(K))>X){let Y=OJ(J,K+1);if(Y<=K||Y>=J.length)break;K=Y}return{keep:J.slice(K),drop:J.slice(0,K)}}function OJ(J,Q){let Z=Q;while(Z<J.length&&J[Z].role==="tool")Z++;return Z}async function $J(J,Q,Z,z){let X=Q.fallbackFrom?{fallbackFrom:Q.fallbackFrom}:{};if(Q.strategy==="provider-native"){let B=null;if(z.native)try{B=await z.native(J,{model:z.model,budgetTokens:Q.budgetTokens,trigger:z.trigger,signal:z.signal})}catch{B=null}if(B)return{history:B,strategy:"provider-native",...X};let K=ZJ(J,{...Z,compactionStrategy:QJ},{...z,native:void 0});if(!K)return null;let V=await $J(J,K,Z,{...z,native:void 0});return V?{...V,fallbackFrom:"provider-native"}:null}if(Q.strategy==="keep-window"){if(Q.drop.length===0)return null;let B=Q.drop.reduce((V,Y)=>V+k(z.tokenText(Y)),0);return{history:[{id:CJ(),role:"system",parts:[{kind:"text",text:`[context compacted (keep-window): ${Q.drop.length} earlier messages, ~${B} tokens, removed from the working context]`}],parentId:Q.keep[0]?.id??null,createdAt:Date.now()},...Q.keep],strategy:"keep-window",...X}}if(!z.summarize)return null;let G=await z.summarize(Q.drop.map((B)=>z.tokenText(B)));return{history:[{id:CJ(),role:"system",parts:[{kind:"text",text:`Summary of earlier conversation:
3
+ ${G}`}],parentId:J[0]?.id??null,createdAt:Date.now()},...Q.keep],strategy:"head-summarize",...X}}var LJ,QJ="head-summarize",$Q=2,_J,XQ,zQ;var IJ=f(()=>{JJ();LJ=["head-summarize","keep-window","provider-native"],_J=new Set;XQ=[/prompt is too long/i,/request_too_large/i,/input is too long for requested model/i,/exceeds the context window/i,/maximum context length/i,/context[_ ]length[_ ]exceeded/i,/input token count.*exceeds the maximum/i,/tokens in request more than max tokens allowed/i,/maximum prompt length is \d+/i,/reduce the length of the messages/i,/request entity too large/i,/model_context_window_exceeded/i,/too many tokens/i,/token limit exceeded/i,/exceeds the available context size/i,/greater than the context length/i],zQ=[/rate limit/i,/too many requests/i,/throttling/i,/service unavailable/i]});import{existsSync as GQ,mkdirSync as HQ,readFileSync as bJ,writeFileSync as qQ}from"fs";import{join as L}from"path";function MQ(J,Q){if(Q(L(J,"bun.lock"))||Q(L(J,"bun.lockb")))return{run:"bun run",from:"bun.lock"};if(Q(L(J,"pnpm-lock.yaml")))return{run:"pnpm run",from:"pnpm-lock.yaml"};if(Q(L(J,"yarn.lock")))return{run:"yarn",from:"yarn.lock"};if(Q(L(J,"package-lock.json")))return{run:"npm run",from:"package-lock.json"};return{run:"npm run",from:"no lockfile (npm assumed)"}}function wJ(J,Q={}){let Z=Q.exists??GQ,z=Q.read??(($)=>bJ($,"utf8")),X=EJ(J),G={...X.user,...X.project};if(G.verify===!1)return{source:"none",commands:[],reason:"settings.json verify: false \u2014 the gate is off by choice, nothing is inferred",refused:[]};if(G.verify!==void 0){let $=Array.isArray(G.verify)?G.verify:[G.verify],q=X.project.verify!==void 0?X.projectPath:RJ("user",J);return{source:"settings",commands:$,reason:`${q} verify`,refused:[]}}let W=[],B=[],K=[],V=L(J,"package.json");if(Z(V)){let $={},q=!0;try{let P=JSON.parse(z(V)).scripts;if(P!==void 0&&(typeof P!=="object"||P===null||Array.isArray(P)))K.push('package.json: "scripts" is not an object \u2014 nothing inferred from it'),q=!1;else if(P){for(let[N,U]of Object.entries(P))if(typeof U==="string")$[N]=U}}catch{K.push("package.json is not valid JSON \u2014 nothing inferred from it"),q=!1,$={}}if(q){let j=MQ(J,Z),P=(M)=>$[M].trim(),N=(M)=>`set \`"verify": "${j.run} ${M}"\` in .rovecode/settings.json`,U=(M,O,R,w)=>{if($[M]===void 0)return;let E=P(M);if(AJ.test(E)){K.push(`package.json script "${M}" runs \`${E}\`: a watch mode never exits, so it cannot gate a run`);return}if(!O.test(E)){K.push(`package.json script "${M}" runs \`${E}\`: not a ${R} this gate knows runs unattended and ends (${w}) \u2014 ${N(M)} to run it anyway`);return}W.push(`${j.run} ${M}`),B.push(`package.json script "${M}" (${j.from})`)};if(U("typecheck",PQ,"type-checker","tsc, vue-tsc, svelte-check"),U("lint",jQ,"linter","eslint, biome check, oxlint"),$.check!==void 0){let M=P("check"),O=FQ.exec(M),R=VQ.exec(M);if(O)K.push(`package.json script "check" runs \`${M}\`: it names \`${O[1]}\`, which a check must not do \u2014 ${N("check")} if that is really what you want the gate to run`);else if(AJ.test(M))K.push(`package.json script "check" runs \`${M}\`: a watch mode never exits, so it cannot gate a run`);else if(R)K.push(`package.json script "check" runs \`${M}\`: it runs the test suite (\`${R[1]}\`), which is minutes here rather than seconds; the thorough gate is configured, never inferred \u2014 ${N("check")} if that cost is right for this project`);else if(W.length>0)K.push(`package.json script "check" runs \`${M}\`: a faster script already covers it (${B.map((w)=>w.split(" (")[0]).join(", ")}) \u2014 ${N("check")} to run it instead`);else W.push(`${j.run} check`),B.push(`package.json script "check" (${j.from})`)}if($.test!==void 0){let M=P("test");K.push(`package.json script "test" runs \`${M}\`: a test suite is never inferred, only configured (the fast gate is a type-check; a suite can take minutes and may need services) \u2014 ${N("test")} if it is quick enough here`)}if(W.length===0&&K.length===0)K.push('package.json has no "typecheck", "lint", "check" or "test" script \u2014 name one, or set verify in .rovecode/settings.json')}}if(Z(L(J,"Cargo.toml")))W.push("cargo check"),B.push("Cargo.toml"),K.push("`cargo test` is not inferred: it runs the crate's tests, which may be slow or need services \u2014 set verify to run it");if(Z(L(J,"go.mod")))W.push("go vet ./..."),B.push("go.mod"),K.push("`go test ./...` is not inferred: it runs the module's tests \u2014 set verify to run it");let Y=L(J,"pyproject.toml");if(Z(Y)||Z(L(J,"ruff.toml"))){let $=Z(L(J,"ruff.toml")),q=$;if(!q&&Z(Y))try{q=/^\[tool\.ruff(\.|\])/m.test(z(Y))}catch{}if(q)W.push("ruff check ."),B.push($?"ruff.toml":"pyproject.toml [tool.ruff]");else K.push("pyproject.toml without a [tool.ruff] section: no linter is configured that this gate knows \u2014 set verify (for example `ruff check .` or `pytest -q`) to run one");K.push("`pytest` is not inferred: it runs the project's tests \u2014 set verify to run it")}if(Z(L(J,"Makefile"))||Z(L(J,"makefile")))K.push("a Makefile is here, but make targets are never inferred (a target can do anything) \u2014 set verify to `make check` or the target you mean");if(W.length>0)return{source:"inferred",commands:W,reason:`inferred from ${B.join(", ")}`,refused:K};if(K.length===0)return{source:"none",commands:[],reason:NQ,refused:[]};return{source:"none",commands:[],reason:DQ,refused:K}}function vJ(J){try{let Q=JSON.parse(bJ(L(J,kJ),"utf8"));if(Q===null||typeof Q!=="object"||Array.isArray(Q))return{};let Z={};for(let[z,X]of Object.entries(Q))if(X&&typeof X==="object"&&typeof X.ms==="number"&&typeof X.at==="string")Z[z]=X;return Z}catch{return{}}}function TJ(J,Q,Z,z=new Date){try{let X=vJ(J);X[Q]={ms:Math.max(0,Math.round(Z)),at:z.toISOString()},HQ(L(J,".rovecode"),{recursive:!0}),qQ(L(J,kJ),JSON.stringify(X,null,2)+`
4
+ `)}catch{}}function CQ(J,Q){return vJ(J)[Q]?.ms}function LQ(J){let Q=Math.round(J/1000);if(Q<1)return"under a second";if(Q<120)return`${Q} s`;let Z=Math.floor(Q/60),z=Q%60;return z===0?`${Z} min`:`${Z} min ${z} s`}function iQ(J,Q){return Q.commands.map((Z)=>{let z=CQ(J,Z);return z===void 0?`${Z} (not run here yet)`:`${Z} (${LQ(z)} last time)`}).join(" && ")}var FQ,AJ,VQ,PQ,jQ,DQ="nothing configured and nothing fast and safe to infer \u2014 set verify in .rovecode/settings.json (a command, or a list) to turn the gate on",NQ="no package.json, Cargo.toml, go.mod or pyproject.toml here, so there is no compiler, linter or test runner to run; for a plain HTML/CSS/JS site that is the normal answer, and the gate stays off",dQ="runs after edits made with `edit` or `write`; a run that changed files only through `bash` is not counted, so it is not verified",kJ;var xJ=f(()=>{YQ();FQ=/\b(deploy|publish|release|push|migrate|drop|rm\s+-rf|docker|kubectl|terraform|curl|wget|ssh|scp|rsync)\b/i,AJ=/(^|\s)(--watch(=\S*)?|-w|--watchAll)(\s|$)|\bnodemon\b|\bvitest\s*$/,VQ=/\b(bun test|vitest|jest|mocha|node --test|playwright test|cypress run|ava|tap|uvu)\b/,PQ=/^(bunx |npx |pnpm exec |yarn )?(tsc|vue-tsc|svelte-check)(\s|$)/,jQ=/^(bunx |npx |pnpm exec |yarn )?(eslint|biome (check|lint)|oxlint)(\s|$)/;kJ=L(".rovecode","verify-timing.json")});function rQ(J,Q){try{if(Q.ran>0)TJ(J,Q.command,Q.ms)}catch{}}function yJ(J,Q=OQ){let Z=J.replace(/\r\n?/g,`
5
+ `).split(`
6
+ `);while(Z.length>0&&Z.at(-1).trim()==="")Z.pop();let z=Math.max(0,Z.length-SQ),X=Z.slice(0,z).filter((K)=>/\b(fail|failed|failing|error|not ok|assert(ion)?|exception|panic)\b|\u2717|\u00D7|\u2718/i.test(K)),G=X.length>XJ?[...X.slice(0,XJ),`\u2026 ${X.length-XJ} more lines naming a failure`]:X,W=[...G];if(G.length>0&&z>0)W.push("\u2026");W.push(...Z.slice(z));let B=W.join(`
7
+ `);if(B.length>Q)B=`[\u2026 ${B.length-Q} chars clipped]
8
+ ${B.slice(B.length-Q)}`;return B}async function sQ(J,Q,Z={}){let z=Z.exec??UQ,X=Z.clock??Date.now,G=Z.timeoutMs??fJ,W=X(),B=0,K=J.commands[0]??"";for(let V of J.commands){K=V;let Y=new AbortController,$=!1,q=()=>Y.abort();if(Z.signal?.aborted)Y.abort();else Z.signal?.addEventListener("abort",q,{once:!0});let j=setTimeout(()=>{$=!0,Y.abort()},G),P;try{P=await z(V,Q,Y.signal)}catch(N){P={code:-1,text:`could not run the check: ${N instanceof Error?N.message:String(N)}`}}finally{clearTimeout(j),Z.signal?.removeEventListener("abort",q)}if(B++,$)return{command:V,ok:!1,code:P.code,timedOut:!0,ms:X()-W,failure:yJ(P.text),ran:B};if(P.code!==0||Z.signal?.aborted)return{command:V,ok:!1,code:P.code,timedOut:!1,ms:X()-W,failure:yJ(P.text),ran:B}}return{command:K,ok:!0,code:0,timedOut:!1,ms:X()-W,failure:"",ran:B}}function hJ(J,Q=fJ){return["<verify-check>","You stopped, but the work does not pass \u2014 this is a check by the harness, not a message from the user.",J.timedOut?`The project's check did not finish within ${Math.round(Q/1000)}s and was stopped: \`${J.command}\``:`The project's check failed (exit ${J.code}) after your changes: \`${J.command}\``,J.failure.trim()===""?"(the check produced no output)":`Failing part of its output:
9
+ `+J.failure,"Fix what your changes broke and run the check yourself, or say plainly why it cannot be made to pass. This check runs once per run; your next reply ends it either way.","</verify-check>"].join(`
10
+ `)}function gJ(J){let Q=J.refused&&J.refused.length>0?` \xB7 ${J.refused.length} check${J.refused.length===1?"":"s"} refused (${J.refused.join("; ")})`:"",Z="command"in J?J.command.length>60?`${J.command.slice(0,59)}\u2026`:J.command:"";switch(J.state){case"unconfigured":return`not verified: ${J.reason??"no check configured"}${Q}`;case"passed":return`check passed (${Z})${Q}`;case"timeout":return`check timed out after ${J.seconds}s (${Z})${Q}`;case"failed":return`check failed (${Z}): ${(J.failure.split(`
11
+ `).filter((z)=>z.trim()!=="").at(-1)??"").slice(0,120)}${Q}`}}function mJ(J){if(J.ok)return`passed in ${(J.ms/1000).toFixed(1)}s`;if(J.timedOut)return`timed out after ${(J.ms/1000).toFixed(0)}s`;let Q=J.failure.split(`
12
+ `).filter((Z)=>Z.trim()!=="").at(-1)??"";return`exit ${J.code}${Q?` \u2014 ${Q.slice(0,120)}`:""}`}var oQ=(J)=>{let Q=wJ(J);return{commands:Q.commands,refused:Q.refused,source:Q.source,reason:Q.reason}},fJ=120000,OQ=3000,SQ=40,XJ=20,UQ=async(J,Q,Z)=>{let{getExecutor:z}=await import("./executor-bdrjn634.js");return z().run(J,Q,Z)};var uJ=f(()=>{xJ()});import{randomUUID as v}from"crypto";class AQ{queue=[];push(J){this.queue.push(J)}drainAll(){let J=this.queue;return this.queue=[],J}drainOne(){return this.queue.shift()}get size(){return this.queue.length}}function RQ(J,Q){return{calls:J.filter((z)=>z.kind==="tool_call"),truncated:Q==="length"}}async function*KZ(J,Q,Z,z,X,G,W=0,B){let K=new AbortController,V=()=>K.abort();if(X.signal?.aborted)K.abort();else X.signal?.addEventListener("abort",V,{once:!0});let Y=X.hooks?.observer?.({cwd:X.cwd??process.cwd(),sessionId:X.store.id});try{for await(let $ of EQ(J,Q,Z,z,X,G,W,B,K)){if(Y)await Y.observe($);yield $}}finally{if(X.signal?.removeEventListener("abort",V),K.abort(),Y)await Y.close()}}async function*EQ(J,Q,Z,z,X,G,W,B,K){let V=v();yield{type:"run_start",runId:V,sessionId:X.store.id,goal:Q};let Y=J.model??{provider:"mock",model:"default"},$=[...X.store.messages()],q=$.length,j={id:v(),role:"user",parts:[{kind:"text",text:Q}],parentId:$.at(-1)?.id??null,createdAt:Date.now()};X.store.append(j),$.push(j);let P=[],N=(I)=>{P.push(I)},U=function*(){yield*P.splice(0,P.length)};X.guard?.onTurn();let M=null,O=0,R=X.clock??Date.now,w=R(),E=0,b=0,T=!1,h=-1,S;for(let I=1;I<=z.maxTurns;I++){if(K.signal.aborted){yield{type:"run_end",status:"stopped",summary:"run aborted"};return}if(z.maxSeconds!==void 0&&(R()-w)/1000>=z.maxSeconds){yield{type:"run_end",status:"budget",summary:`wall clock (${z.maxSeconds}s) reached after ${I-1} turn${I===2?"":"s"}`};return}if(z.maxCostUsd!==void 0&&E>=z.maxCostUsd){let H=b>0?`; ${b} turn${b===1?"":"s"} unpriced`:"";yield{type:"run_end",status:"budget",summary:`cost cap ($${z.maxCostUsd.toFixed(2)}) reached after ${I-1} turn${I===2?"":"s"} \u2014 $${E.toFixed(4)} spent${H}`};return}for(let H of G.drainAll()){let F={id:v(),role:"user",parts:[{kind:"text",text:H}],parentId:$.at(-1)?.id??null,createdAt:Date.now()};X.store.append(F),$.push(F),yield{type:"steer",text:H}}yield{type:"turn_start",turn:I};let KJ=$.reduce((H,F)=>H+k(p(F.parts)),0),d=SJ(KJ,z,M!==null),WJ=M;if(M=null,d){let H={trigger:d,tokenText:(D)=>p(D.parts),summarize:X.summarize,native:X.compactNative,model:Y,signal:K.signal},F=ZJ($,z,H),A=F?await $J($,F,z,H):null;if(A){$.length=0,$.push(...A.history);let D={type:"compaction",strategy:A.strategy,trigger:d,tokensBefore:KJ,tokensAfter:$.reduce((C,_)=>C+k(p(_.parts)),0)};X.store.appendEvent(D),yield D}else if(WJ!==null){yield{type:"run_end",status:"error",summary:WJ};return}}let BJ=typeof J.systemPrompt==="function"?J.systemPrompt(Z):J.systemPrompt,dJ=$.reduce((H,F)=>H+k(p(F.parts)),0),iJ=[{name:"system",text:BJ,priority:100,tokens:k(BJ)},...J.contextChunks??[],{name:"history",text:"",priority:50,tokens:dJ}],g=DJ(iJ,z.contextBudgetTokens);if(g.dropped.length>0){let H=g.dropped.reduce((F,A)=>F+A.tokens,0);yield{type:"compaction",strategy:"context-drop",tokensBefore:g.totalTokens+H,tokensAfter:g.totalTokens}}let YJ=g.chunks.filter((H)=>H.name!=="history"),aJ=YJ.length>0,nJ=YJ.map((H)=>H.text).join(`
13
+
14
+ `),i=v(),m,oJ={id:"sys",role:"system",parts:[{kind:"text",text:nJ}],parentId:null,createdAt:0};try{let H=X.planReminder?.($)??null,F=H===null?$:[...$,{id:`reminder-${I}`,role:"user",parts:[{kind:"text",text:H}],parentId:$.at(-1)?.id??null,createdAt:Date.now()}],A=kQ(X.stream,Y,aJ?[oJ,...F]:F,X.tools,K.signal,z.maxSeconds!==void 0?w+z.maxSeconds*1000:void 0),D="";for(;;){let C=await A.next();if(C.done){m=C.value;break}if(C.value.type==="text_delta")yield{type:"message_update",messageId:i,delta:C.value.text};else D+=C.value.text,yield{type:"reasoning_update",messageId:i,tokens:k(D)}}}catch(H){m={parts:[],stopReason:"error",usage:{input:0,output:0},error:H instanceof Error?H.message:String(H)}}yield*U();let{parts:x,stopReason:u,usage:y}=m,a=K.signal.aborted||u==="aborted",n={id:i,role:"assistant",parts:x,parentId:$.at(-1)?.id??null,createdAt:Date.now(),origin:m.origin??Y,usage:y};if(z.maxCostUsd!==void 0&&(y.input>0||y.output>0||(y.cacheRead??0)>0||(y.cacheWrite??0)>0)){let H=z.priceUsd?.(y,n.origin??Y);if(H===void 0)b++;else E+=H}if(!a||x.length>0)X.store.append(n),$.push(n);if(yield{type:"turn_end",turn:I,stopReason:a?"aborted":u},a){for(let H of x)if(H.kind==="tool_call")zJ(X.store,$,H.id,{ok:!1,output:c});yield{type:"run_end",status:"stopped",summary:"run aborted"};return}if(u==="error"){let H=m.error??"provider stream failed",F=cJ(x),A=F?`${F}
15
+ error: ${H}`:`error: ${H}`;if(UJ(H)&&O===0&&I<z.maxTurns){O++,M=A;continue}yield{type:"run_end",status:"error",summary:A};return}let{calls:l,truncated:rJ}=RQ(x,u);if(rJ){for(let F of l)yield{type:"tool_call_failed",callId:F.id,reason:"truncated",detail:"response hit length limit; tool calls not executed"},zJ(X.store,$,F.id,{ok:!1,output:"response hit length limit; tool calls not executed"});continue}if(l.length===0){let H=B?B.drainAll():[];if(H.length>0){X.guard?.onTurn();for(let D of H){let C={id:v(),role:"user",parts:[{kind:"text",text:D}],parentId:$.at(-1)?.id??null,createdAt:Date.now()};X.store.append(C),$.push(C),yield{type:"steer",text:D}}continue}let F=bQ($.slice(q),z.todoState?.()??null,T);if(z.finishCheck!==!1&&!T&&(F.failed.length>0||F.unansweredAsk)){T=!0;let D=wQ(F),C={id:v(),role:"user",parts:[{kind:"text",text:D}],parentId:$.at(-1)?.id??null,createdAt:Date.now()};X.store.append(C),$.push(C),yield{type:"steer",text:D};continue}if(z.verify!==void 0&&F.writes>0){let D=z.verify,C=D.resolution?.refused&&D.resolution.refused.length>0?{refused:D.resolution.refused}:{};if(D.resolution===null||D.resolution.commands.length===0)F.verify={state:"unconfigured",...D.resolution?.reason?{reason:D.resolution.reason}:{},...C};else if(F.writes===h&&S!==void 0)F.verify=S;else{yield{type:"verify",command:D.resolution.commands.join(" && "),state:"running"};let _=await D.run(K.signal);if(K.signal.aborted){yield{type:"run_end",status:"stopped",summary:"run aborted"};return}h=F.writes;let r=_.ok?{state:"passed",command:_.command,ms:_.ms,...C}:_.timedOut?{state:"timeout",command:_.command,seconds:Math.round(D.timeoutMs/1000),...C}:{state:"failed",command:_.command,code:_.code,failure:_.failure,...C};if(S=r,yield{type:"verify",command:_.command,state:r.state,ms:_.ms,detail:mJ(_)},!_.ok&&!T){T=!0;let FJ=hJ(_,D.timeoutMs),VJ={id:v(),role:"user",parts:[{kind:"text",text:FJ}],parentId:$.at(-1)?.id??null,createdAt:Date.now()};X.store.append(VJ),$.push(VJ),yield{type:"steer",text:FJ};continue}F.verify=r}}let A=F.failed.length>0||F.unansweredAsk||(F.todosOpen??0)>0||F.nudged||F.verify!==void 0;yield{type:"run_end",status:"done",summary:cJ(x),...A?{outstanding:F}:{}};return}let GJ={sessionId:X.store.id,cwd:X.cwd??process.cwd(),signal:K.signal,runId:V,spawn:void 0,permissions:{effect:"allow"}},HJ=X.childRunner;if(HJ)GJ.spawn=async(H)=>{let F=await HJ(H.agent,H.goal,H.vars,W+1);return{agent:H.agent,ok:F.ok,summary:F.summary,usage:F.usage}};let qJ=new Map,o=!1;try{let H=X.registry.dispatchBatch(l,GJ,X.hooks,z.permissionRules,z.approval,N,z.parallelTools,X.guard),F=!1;H.then(()=>{F=!0},()=>{F=!0});while(!F&&!K.signal.aborted)if(await Promise.race([H,lJ(5)]),P.length>0)yield*U();if(!F&&K.signal.aborted)await Promise.race([H,lJ(250)]);if(F)qJ=await H,o=!0;if(P.length>0)yield*U()}finally{if(!o)K.abort();for(let H of l)zJ(X.store,$,H.id,qJ.get(H.id)??{ok:!1,output:o?"missing result":c})}if(K.signal.aborted){yield{type:"run_end",status:"stopped",summary:"run aborted"};return}}yield{type:"run_end",status:"budget",summary:`max turns (${z.maxTurns}) reached`}}function bQ(J,Q,Z){let z=new Map;for(let $ of J)if($.role==="tool"){for(let q of $.parts)if(q.kind==="tool_result")z.set(q.callId,{ok:q.ok,output:q.output})}let X=($,q)=>`${$.tool}: ${(q.split(`
16
+ `)[0]??"").slice(0,160)}`,G=($)=>{let q=$.args,j=q?.path??q?.file_path;return typeof j==="string"?j:null},W=0,B=[],K=new Map;for(let $ of J){if($.role!=="assistant")continue;let q=$.parts.filter((j)=>j.kind==="tool_call");if(q.length===0)continue;B=q;for(let j of q){if(j.tool!=="edit"&&j.tool!=="write")continue;let P=z.get(j.id),N=G(j)??j.id;if(P?.ok===!0)W++,K.delete(N);else if(P&&!pJ(P.output))K.set(N,X(j,P.output))}}let V=[...K.values()],Y=!1;for(let $ of B){let q=z.get($.id);if(q===void 0||q.ok)continue;if($.tool==="ask_user"){Y=!0;continue}if(pJ(q.output))continue;let j=X($,q.output);if(!V.includes(j))V.push(j)}return{failed:V,unansweredAsk:Y,writes:W,...Q&&Q.total>0?{todosOpen:Q.open,todosTotal:Q.total}:{},nudged:Z}}function pJ(J){return J.startsWith("Permission denied")||J.includes("loop guard: blocked")||J.startsWith(c)}function wQ(J){let Q=["<finish-check>","You stopped, but this run is not in a finished state \u2014 this is a check by the harness, not a message from the user."];for(let Z of J.failed)Q.push(`- a tool call failed and nothing after it recovered from that: ${Z}`);if(J.unansweredAsk)Q.push("- your question to the user was not answered (there is no one to answer it in this run); decide with your best judgment instead of waiting");if((J.todosOpen??0)>0)Q.push(`- your own todo list still has ${J.todosOpen} of ${J.todosTotal} items open`);return Q.push("Either continue and finish the work now, or say plainly what is left undone and why it is not needed. This check runs once per run; your next reply ends it either way.","</finish-check>"),Q.join(`
17
+ `)}function WZ(J){let Q=[];if(J.failed.length>0)Q.push(`${J.failed.length} failed tool call${J.failed.length===1?"":"s"} not recovered (${[...new Set(J.failed.map((Z)=>Z.split(":")[0]))].join(", ")})`);if(J.unansweredAsk)Q.push("its question to you went unanswered");if((J.todosOpen??0)>0)Q.push(`${J.todosOpen} of ${J.todosTotal} items still open`);if(J.verify!==void 0)Q.push(gJ(J.verify));return Q.length>0?Q.join(" \xB7 "):null}function BZ(J){return J.failed.length===0&&!J.unansweredAsk&&(J.todosOpen??0)===0&&J.verify?.state==="passed"?"info":"warn"}function zJ(J,Q,Z,z){let X={id:v(),role:"tool",parts:[{kind:"tool_result",callId:Z,ok:z.ok,output:z.output}],parentId:Q.at(-1)?.id??null,createdAt:Date.now()};J.append(X),Q.push(X)}async function*kQ(J,Q,Z,z,X,G){let W={parts:[],stopReason:"end_turn",usage:{input:0,output:0}};for await(let B of J(Q,Z,{tools:z,signal:X,...G!==void 0?{deadlineAt:G}:{}}))if(B.type==="text_delta"||B.type==="reasoning_delta")yield B;else if(B.type==="turn")W={parts:B.turn.parts,stopReason:B.turn.stopReason,usage:B.turn.usage,error:B.turn.error,origin:jJ(B.turn)};return W}function cJ(J){return J.filter((Q)=>Q.kind==="text").map((Q)=>Q.text).join("")}function p(J){return J.map((Q)=>Q.kind==="text"?Q.text:Q.kind==="tool_call"?`${Q.tool} ${JSON.stringify(Q.args)}`:Q.kind==="tool_result"?Q.output:"").join(`
18
+ `)}var lJ=(J)=>new Promise((Q)=>setTimeout(Q,J));var vQ=f(()=>{IQ();MJ();JJ();IJ();uJ()});
19
+ export{PJ as Mk,TQ as Nk,eJ as Ok,xQ as Pk,MJ as Qk,k as Rk,JJ as Sk,QJ as Tk,mQ as Uk,ZJ as Vk,$J as Wk,IJ as Xk,wJ as Yk,dQ as Zk,iQ as _k,xJ as $k,oQ as al,rQ as bl,fJ as cl,sQ as dl,uJ as el,AQ as fl,RQ as gl,KZ as hl,bQ as il,wQ as jl,WZ as kl,BZ as ll,cJ as ml,p as nl,vQ as ol};
@@ -0,0 +1,19 @@
1
+ // @bun
2
+ import{rn as I,tn as y}from"./main-nqveez48.js";var X=3,L="save skipped: memory at capacity or repeatedly failing",H=0;function i(){H=0}function k(){return H}function a(q){return{schema:{name:"memory_edit",description:`Edit long-term memory blocks. Ops: add(text) appends a line; replace(oldText,newText) requires oldText to match exactly once; remove(oldText) same. block: "memory" (session/task facts, cap ${q.cap("memory")} chars) or "user" (stable user preferences, cap ${q.cap("user")} chars). Failures count toward a per-turn budget of ${X}; after that saves are skipped until next turn.`,args:{type:"object",properties:{op:{type:"string",enum:["add","replace","remove"]},block:{type:"string",enum:["memory","user"]},text:{type:"string",description:"text to add (op=add)"},oldText:{type:"string",description:"exact text to replace/remove; must match exactly once"},newText:{type:"string",description:"replacement text (op=replace; empty removes)"}},required:["op","block"]}},kind:"memory",sequential:!0,async execute(Q,J){let Z=Q;if(H>=X)return{ok:!1,output:L};let $=Z.block==="user"?"user":Z.block==="memory"?"memory":void 0;if(!$)return j(`invalid block: ${String(Z.block)}`);let z;switch(Z.op){case"add":if(typeof Z.text!=="string"||Z.text.trim().length===0)return j("op=add requires non-empty text");z=q.add($,Z.text);break;case"replace":if(typeof Z.oldText!=="string"||Z.oldText.length===0)return j("op=replace requires oldText");if(typeof Z.newText!=="string")return j('op=replace requires newText (use "" to delete)');z=q.replace($,Z.oldText,Z.newText);break;case"remove":if(typeof Z.oldText!=="string"||Z.oldText.length===0)return j("op=remove requires oldText");z=q.remove($,Z.oldText);break;default:return j(`invalid op: ${String(Z.op)}`)}if(!z.ok)return j(z.reason??"edit failed",z.current,z.limit);return{ok:!0,output:`${Z.op} ok: ${$} block now ${z.current}/${z.limit} chars`,data:{block:$,chars:z.current,limit:z.limit}}}}}function j(q,Q,J){H++;let Z=Q!==void 0&&J!==void 0?` (current ${Q}/${J} chars)`:"";return{ok:!1,output:`memory_edit failed: ${q}${Z}; failures this turn: ${H}/${X}`}}y();import{closeSync as _,existsSync as E,openSync as f,readSync as m}from"fs";import{join as S}from"path";import{appendFileSync as R,existsSync as D,mkdirSync as U,readFileSync as O,renameSync as C,writeFileSync as w}from"fs";import{dirname as g}from"path";var A=".versions.jsonl",F=20;function P(q,Q){U(g(q),{recursive:!0});let J=`${q}.${process.pid}.tmp`;w(J,Q),C(J,q)}function h(q){let Q;try{Q=JSON.parse(q)}catch{return null}if(typeof Q!=="object"||Q===null||Array.isArray(Q))return null;let J=Q;if(typeof J.version!=="number"||typeof J.baseVersion!=="number"||typeof J.before!=="string"||typeof J.after!=="string"||typeof J.reason!=="string"||typeof J.timestamp!=="number")return null;let Z={version:J.version,baseVersion:J.baseVersion,before:J.before,after:J.after,reason:J.reason,timestamp:J.timestamp};if(typeof J.rollbackTo==="number")Z.rollbackTo=J.rollbackTo;return Z}class W{targetPath;ledgerPath;maxEdits;constructor(q,Q={}){this.targetPath=q;this.ledgerPath=Q.ledgerPath??q+A,this.maxEdits=Math.max(1,Q.maxEdits??F)}history(){if(!D(this.ledgerPath))return[];let q=new Map;for(let Q of O(this.ledgerPath,"utf8").split(`
3
+ `)){let J=Q.trim();if(!J)continue;let Z=h(J);if(Z)q.set(Z.version,Z)}return[...q.values()].sort((Q,J)=>Q.version-J.version)}version(){return this.history().at(-1)?.version??0}read(){return D(this.targetPath)?O(this.targetPath,"utf8"):""}range(){let q=this.history(),Q=q.at(-1);if(!Q)return null;let J=q.length-1;while(J>0&&q[J-1].version===q[J].baseVersion)J--;return{from:q[J].baseVersion,to:Q.version}}contentAt(q){let Q=this.history(),J=Q.find((Z)=>Z.version===q);if(J)return J.after;return Q.find((Z)=>Z.baseVersion===q)?.before}drifted(){let q=this.history().at(-1);return q!==void 0&&this.read()!==q.after}commit(q,Q,J,Z=Date.now()){let $=this.version();if(J!==$)return{ok:!1,code:"version-conflict",baseVersion:J,currentVersion:$,message:`baseVersion ${J} does not match current version ${$}; re-read and retry`};return{ok:!0,edit:this.write(q,Q,$,Z)}}rollback(q,Q,J=Date.now()){let Z=this.contentAt(q);if(Z===void 0){let z=this.range();return{ok:!1,code:"unknown-version",requested:q,available:z,message:z?`version ${q} is not restorable; available: ${z.from}..${z.to}`:`version ${q} is not restorable; no recorded edits`}}return{ok:!0,edit:this.write(Z,Q??`rollback to v${q}`,this.version(),J,q)}}write(q,Q,J,Z,$){let z={version:J+1,baseVersion:J,before:this.read(),after:q,reason:Q,timestamp:Z,...$!==void 0?{rollbackTo:$}:{}};U(g(this.ledgerPath),{recursive:!0});let K=JSON.stringify(z)+`
4
+ `;if(D(this.ledgerPath)){let G=O(this.ledgerPath);if(G.length>0&&G[G.length-1]!==10)K=`
5
+ `+K}R(this.ledgerPath,K,"utf8");let M=this.history();if(M.length>this.maxEdits){let G=M.slice(M.length-this.maxEdits);P(this.ledgerPath,G.map((v)=>JSON.stringify(v)).join(`
6
+ `)+`
7
+ `)}return P(this.targetPath,q),z}}var Y={memory:"MEMORY.md",user:"USER.md"},T={memory:2200,user:1375},N=65536,V="memory changed since it was read \u2014 re-read and retry",u=/(?:ignore previous|disregard above|system prompt)/i;function B(q){return q.split(`
8
+ `).map((Q)=>u.test(Q)?"[BLOCKED]":Q).join(`
9
+ `)}function x(q,Q){if(q.length<=Q)return q;let J=q.lastIndexOf(`
10
+ `,Q);if(J<Q/2)J=Q;return q.slice(0,J)}function p(q,Q){let J=f(q,"r");try{let Z=Buffer.alloc(Q+1),$=0;while($<Z.length){let z=m(J,Z,$,Z.length-$,$);if(z<=0)break;$+=z}return{text:Z.subarray(0,Math.min($,Q)).toString("utf8"),cut:$>Q}}finally{_(J)}}function d(q,Q){if(!Q)return 0;let J=0,Z=0;while((Z=q.indexOf(Q,Z))!==-1)J++,Z+=Q.length;return J}class s{caps;live={memory:"",user:""};frozen;ledgers;baseVersions;dirs;readCut={memory:!1,user:!1};withheld;onCommit;constructor(q,Q=T,J={}){this.caps=Q;this.dirs=typeof q==="string"?{memory:q,user:q}:{memory:q.memory,user:q.user},this.withheld=new Set(J.withhold??[]),this.onCommit=J.onCommit,this.live.memory=this.read("memory"),this.live.user=this.read("user"),this.frozen={memory:B(this.live.memory),user:B(this.live.user)},this.ledgers={memory:new W(this.file("memory")),user:new W(this.file("user"))},this.baseVersions={memory:this.ledgers.memory.version(),user:this.ledgers.user.version()}}read(q){let Q=this.file(q);if(!E(Q))return"";let J=p(Q,N);return this.readCut[q]=J.cut,J.text}file(q){return S(this.dirs[q],Y[q])}path(q){return this.file(q)}add(q,Q){let J=Q.trim();if(!J)return{ok:!1,reason:"empty text"};let Z=this.live[q]?this.live[q]+`
11
+ `+J:J;return this.commit(q,Z)}replace(q,Q,J){let Z=this.locate(q,Q);if(!Z.ok)return Z;let $=J.trim(),z=$?this.live[q].replace(Q,$):this.live[q].replace(Q,"");return this.commit(q,z.trim())}remove(q,Q){let J=this.locate(q,Q);if(!J.ok)return J;let Z=this.live[q].replace(Q,"").replace(/\n{3,}/g,`
12
+
13
+ `).trim();return this.commit(q,Z)}locate(q,Q){if(!Q)return{ok:!1,reason:"oldText required"};let J=d(this.live[q],Q);if(J===0)return{ok:!1,reason:"oldText not found"};if(J>1)return{ok:!1,reason:`oldText matches ${J} times; must match exactly once`};return{ok:!0}}capCheck(q,Q){let J=this.caps[q];if(this.withheld.has(q))return{ok:!1,reason:`${Y[q]} came with this repository and is not approved on this machine \u2014 it is not in the prompt and cannot be written to (${I})`,current:this.live[q].length,limit:J};if(this.readCut[q])return{ok:!1,reason:`${Y[q]} on disk is longer than the ${N}-byte read cap \u2014 trim it by hand before editing`,current:this.live[q].length,limit:J};if(Q.length<=J)return null;return{ok:!1,reason:`block would exceed cap (${Q.length} > ${J} chars)`,current:this.live[q].length,limit:J}}commit(q,Q){let J=this.capCheck(q,Q);if(J)return J;let Z=this.ledgers[q].commit(Q,"memory_edit",this.baseVersions[q]);if(!Z.ok)return this.live[q]=this.ledgers[q].read(),this.baseVersions[q]=Z.currentVersion,{ok:!1,reason:V,conflict:{baseVersion:Z.baseVersion,currentVersion:Z.currentVersion}};return this.baseVersions[q]=Z.edit.version,this.live[q]=Q,this.onCommit?.(q,this.file(q)),{ok:!0,current:Q.length,limit:this.caps[q]}}rollback(q,Q){let J=this.ledgers[q].contentAt(Q),Z=J!==void 0?this.capCheck(q,J):null;if(Z)return Z;let $=this.ledgers[q].rollback(Q,"memory_rollback");if(!$.ok)return{ok:!1,reason:$.message};return this.baseVersions[q]=$.edit.version,this.live[q]=this.ledgers[q].read(),this.onCommit?.(q,this.file(q)),{ok:!0,current:this.live[q].length,limit:this.caps[q]}}ledger(q){return this.ledgers[q]}promptView(q){let Q=this.frozen[q],J=this.caps[q];if(Q.length<=J&&!this.readCut[q])return Q;let Z=this.readCut[q]?`more than ${N} bytes`:`${this.live[q].length} chars`;return`${x(Q,J)}
14
+ [truncated: ${Y[q]} holds ${Z}; the first ${J} chars are shown \u2014 trim the file]`}renderForPrompt(){let q=[];if(this.frozen.memory&&!this.withheld.has("memory"))q.push(`# Memory
15
+ ${this.promptView("memory")}`);if(this.frozen.user&&!this.withheld.has("user"))q.push(`# User
16
+ ${this.promptView("user")}`);return q.join(`
17
+
18
+ `)}liveText(q){return this.live[q]}edited(q){return B(this.live[q])!==this.frozen[q]}cap(q){return this.caps[q]}overCap(q){if(this.live[q].length<=this.caps[q]&&!this.readCut[q])return null;return{chars:this.live[q].length,cap:this.caps[q],readCut:this.readCut[q]}}isWithheld(q){return this.withheld.has(q)}}
19
+ export{A as of,Y as pf,T as qf,x as rf,s as sf,i as tf,k as uf,a as vf};
@@ -0,0 +1,7 @@
1
+ // @bun
2
+ import{wn as B}from"./main-qsevpgsv.js";import{readFileSync as D,statSync as v}from"fs";import{basename as qq,isAbsolute as A}from"path";function f(q=process.env){let Q=q[k]?.trim();if(!Q)return T;let Z=Number(Q);return Number.isInteger(Z)&&Z>0?Z:T}function Zq(q){if(N(q,0,[137,80,78,71,13,10,26,10]))return"image/png";if(N(q,0,[255,216,255]))return"image/jpeg";if(N(q,0,[71,73,70,56]))return"image/gif";if(N(q,0,[82,73,70,70])&&N(q,8,[87,69,66,80]))return"image/webp";return}function $q(q,Q){let Z=($,V)=>$>0&&V>0?{width:$,height:V}:void 0;switch(Q){case"image/png":return q.length>=24&&N(q,12,[73,72,68,82])?Z(x(q,16),x(q,20)):void 0;case"image/gif":return q.length>=10?Z(H(q,6),H(q,8)):void 0;case"image/jpeg":return Jq(q);case"image/webp":return Kq(q)}}function Jq(q){let Q=2;while(Q+3<q.length){if(q[Q]!==255)return;let Z=q[Q+1];if(Z===255){Q+=1;continue}if(Z===216||Z===1||Z>=208&&Z<=215){Q+=2;continue}if(Z===217||Z===218)return;if(Z>=192&&Z<=207&&Z!==196&&Z!==200&&Z!==204)return Q+8<q.length?{height:F(q,Q+5),width:F(q,Q+7)}:void 0;Q+=2+F(q,Q+2)}return}function Kq(q){if(q.length<30)return;let Q=String.fromCharCode(q[12],q[13],q[14],q[15]);if(Q==="VP8 ")return{width:H(q,26)&16383,height:H(q,28)&16383};if(Q==="VP8L"&&q[20]===47)return{width:1+(q[21]|(q[22]&63)<<8),height:1+(q[22]>>6|q[23]<<2|(q[24]&15)<<10)};if(Q==="VP8X")return{width:1+I(q,24),height:1+I(q,27)};return}function S(q,Q={}){let Z=Q.name??"image",$=Zq(q);if(!$){let J=[...q.subarray(0,4)].map((O)=>O.toString(16).padStart(2,"0")).join(" ");return{error:`${Z}: not a png/jpeg/gif/webp image (magic bytes: ${J||"empty file"})`}}let V=Q.maxBytes??f(Q.env);if(q.byteLength>V)return{error:`${Z}: ${C(q.byteLength)} is over the ${C(V)} per-image cap (${k})`};let K={kind:"image",mime:$,bytes:Buffer.from(q).toString("base64")},Y=$q(q,$);if(Y)K.width=Y.width,K.height=Y.height;if(Q.name!==void 0)K.name=Q.name;return K}function Fq(q,Q={}){let Z=Q.name??qq(q),$;try{let K=v(q);if(!K.isFile())return{error:`${Z}: not a file`};$=K.size}catch(K){return{error:`${Z}: cannot read (${K instanceof Error?K.message:String(K)})`}}let V=Q.maxBytes??f(Q.env);if($>V)return{error:`${Z}: ${C($)} is over the ${C(V)} per-image cap (${k})`};try{return S(D(q),{...Q,maxBytes:V,name:Z})}catch(K){return{error:`${Z}: cannot read (${K instanceof Error?K.message:String(K)})`}}}function kq(q,Q,Z={}){let $=Buffer.from(q,"base64"),V=S($,Z);if("error"in V)return V;if(Q!==void 0&&Q!==V.mime)return{error:`${Z.name??"image"}: declared ${Q} but the bytes are ${V.mime}`};return V}function _q(q,Q=Qq){return q>Q?`at most ${Q} images per message (${q} attached)`:void 0}function u(q){if(q.bytes!==void 0)return q.bytes;if(q.path===void 0||!A(q.path))return;try{return D(q.path).toString("base64")}catch{return}}function Vq(q){if(q.bytes!==void 0){let Q=q.bytes.endsWith("==")?2:q.bytes.endsWith("=")?1:0;return Math.floor(q.bytes.length*3/4)-Q}if(q.path===void 0||!A(q.path))return;try{return v(q.path).size}catch{return}}function h(q){return q==="image/png"?"png":q==="image/jpeg"?"jpg":q==="image/gif"?"gif":"webp"}function Oq(q){let Q=[q.name??q.mime];if(q.width!==void 0&&q.height!==void 0)Q.push(`${q.width}x${q.height}`);let Z=Vq(q);if(Z!==void 0)Q.push(C(Z));return Q.join(", ")}function gq(q,Q="model has no vision"){return`[image: ${Oq(q)} \u2014 ${Q}]`}function Mq(q){return`[image: ${q.name??q.mime}]`}function Eq(q){let Q=u(q);return Q===void 0?void 0:{type:"image",source:{type:"base64",media_type:q.mime,data:Q}}}function Tq(q,Q="auto"){let Z=u(q);return Z===void 0?void 0:{type:"image_url",image_url:{url:`data:${q.mime};base64,${Z}`,detail:Q}}}var T=5242880,k="ROVECODE_IMAGE_MAX_BYTES",Qq=8,N=(q,Q,Z)=>q.length>=Q+Z.length&&Z.every(($,V)=>q[Q+V]===$),F=(q,Q)=>q[Q]<<8|q[Q+1],x=(q,Q)=>(q[Q]<<24|q[Q+1]<<16|q[Q+2]<<8|q[Q+3])>>>0,H=(q,Q)=>q[Q]|q[Q+1]<<8,I=(q,Q)=>q[Q]|q[Q+1]<<8|q[Q+2]<<16,C=(q)=>q<1024?`${q} B`:`${Math.ceil(q/1024)} KB`;var l=()=>{};import{createHash as Uq}from"crypto";import{existsSync as Yq,mkdirSync as Gq,writeFileSync as Wq}from"fs";import{isAbsolute as c,join as _}from"path";function w(q){let Q=`${L}/`;if(!q.startsWith(Q))return;let Z=q.slice(Q.length);return Z!==""&&Z!=="."&&Z!==".."&&!/[\\/]/.test(Z)?Z:void 0}function d(q,Q){if(!Q.some((Z)=>Z.kind==="image"&&Z.bytes!==void 0))return;return Q.map((Z)=>{if(Z.kind!=="image"||Z.bytes===void 0)return Z;let $=Buffer.from(Z.bytes,"base64"),V=`${Uq("sha256").update($).digest("hex")}.${h(Z.mime)}`;try{Gq(_(q,L),{recursive:!0});let Y=_(q,L,V);if(!Yq(Y))Wq(Y,$)}catch{return Z}let K={kind:"image",mime:Z.mime,path:`${L}/${V}`};if(Z.width!==void 0)K.width=Z.width;if(Z.height!==void 0)K.height=Z.height;if(Z.name!==void 0)K.name=Z.name;return K})}function m(q,Q){let Z=($)=>$.kind==="image"&&$.path!==void 0&&(c($.path)||w($.path)!==void 0);if(!Q.some(Z))return;return Q.map(($)=>{if($.kind!=="image"||$.path===void 0)return $;if(c($.path)){let K={...$};return delete K.path,K}let V=w($.path);return V===void 0?$:{...$,path:_(q,L,V)}})}var L="attachments";var b=B(()=>{l()});function g(q){let Z=q.parts.filter(($)=>$.kind==="text").map(($)=>$.text).join(" ").replace(/\s+/g," ").trim();return Z.length>80?Z.slice(0,79)+"\u2026":Z}function o(q){let Q=q.replace(/[\s\u0000-\u001f\u007f-\u009f]+/g," ").trim();if(Q==="")return;let Z=Array.from(Q);return Z.length>y?Z.slice(0,y-1).join("")+"\u2026":Q}var y=120;var n=()=>{};import{createHash as Xq,randomUUID as zq}from"crypto";import{mkdirSync as Rq,existsSync as M,readFileSync as j,writeFileSync as p,appendFileSync as i,readdirSync as Nq,renameSync as Cq,statSync as s}from"fs";import{join as G}from"path";function a(q,Q){let Z=JSON.stringify(E(Q));return Xq("sha256").update(q+Z).digest("hex")}function E(q){if(Array.isArray(q))return q.map(E);if(q&&typeof q==="object")return Object.fromEntries(Object.entries(q).sort(([Q],[Z])=>Q.localeCompare(Z)).map(([Q,Z])=>[Q,E(Z)]));return q}function R(q){if(!q||typeof q!=="object")return;if(q.kind==="event")return"event";let Q=q;if(!("role"in Q)||!Array.isArray(Q.parts))return;return Q.parts.every((Z)=>!!Z&&typeof Z==="object"&&typeof Z.kind==="string")?"message":void 0}function r(q){return R(q.entry)==="event"}function e(q,Q={}){let Z=[],$=[],V;try{V=Nq(q)}catch{return{sessions:[],hollow:Z}}for(let J of V){let O=-1,U=0;try{let W=s(G(q,J,"entries.jsonl"));if(W.isFile())O=W.size,U=W.mtimeMs}catch{}if(O>0){$.push({name:J,mtime:U});continue}try{if(s(G(q,J,"meta.json")).isFile())Z.push(J)}catch{}}$.sort((J,O)=>O.mtime-J.mtime);let K=Q.limit!==void 0?$.slice(0,Math.max(0,Q.limit)):$,Y=[];for(let{name:J}of K){let O=t(q,J);if(O)Y.push(O)}if(Q.includeHollow)for(let J of Z){let O=t(q,J);if(O)Y.push(O)}return{sessions:Y.sort((J,O)=>O.updatedAt-J.updatedAt),hollow:Z}}function t(q,Q){try{let Z=JSON.parse(j(G(q,Q,"meta.json"),"utf8"));if(!Z||typeof Z!=="object")return;let $=Z;if(typeof $.id!=="string"||typeof $.createdAt!=="number")return;let V=$.createdAt,K=0,Y="",J=0,O=G(q,Q,"entries.jsonl");if(M(O))for(let W of j(O,"utf8").split(`
3
+ `)){if(!W.trim())continue;let X;try{X=JSON.parse(W)}catch{continue}if(!X||typeof X!=="object")continue;let z=X;if(K++,typeof z.createdAt==="number"&&z.createdAt>V)V=z.createdAt;let P=z.entry;if(R(P)==="message"&&P.role==="user"){if(J++,!Y)Y=g(P)}}let U=typeof $.title==="string"?o($.title):void 0;return{id:Q,createdAt:$.createdAt,updatedAt:V,entryCount:K,preview:Y,turns:J,...U!==void 0?{title:U}:{}}}catch{return}}function Lq(q,Q={}){return e(q,Q).sessions}function dq(q){let Q=e(q,{limit:1}).sessions[0];if(Q!==void 0&&Q.entryCount>0)return Q;return Lq(q).find((Z)=>Z.entryCount>0)}class jq{id;dir;leaf="root";prevHash="";cache=[];meta;leafPersisted=!1;staged=[];constructor(q,Q){this.id=Q;this.dir=G(q,Q),this.meta={id:Q,createdAt:Date.now()},this.reload()}get file(){return G(this.dir,"entries.jsonl")}materialize(){Rq(this.dir,{recursive:!0});let q=G(this.dir,"meta.json");if(!M(q))p(q,JSON.stringify(this.meta,null,2))}reload(){this.cache=[],this.leaf="root",this.prevHash="";let q=new Set,Q=[],Z;this.leafPersisted=!1;try{let J=JSON.parse(j(G(this.dir,"meta.json"),"utf8"));if(J&&typeof J==="object"){let O=J;if(typeof O.id==="string"&&typeof O.createdAt==="number")this.meta=O;if(typeof O.leaf==="string")Z=O.leaf,this.leafPersisted=!0}}catch{}if(!M(this.file))return Q;let $=j(this.file,"utf8").split(`
4
+ `).filter(Boolean),V=new Map,K;$.forEach((J,O)=>{let U;try{U=JSON.parse(J)}catch{Q.push({kind:"malformed-json",line:O,detail:`unparseable line ${O}`});return}if(!U||typeof U!=="object"){Q.push({kind:"unknown-shape",line:O,detail:"line is not an entry object"});return}if(typeof U.id!=="string"){Q.push({kind:"unknown-shape",line:O,detail:"entry line has no string id"});return}if(q.has(U.id))Q.push({kind:"duplicate-id",entryId:U.id,line:O,detail:"duplicate id"});q.add(U.id);let W=U.parentId!==null&&!q.has(U.parentId);if(W)Q.push({kind:"orphan-entry",entryId:U.id,line:O,detail:`parent ${U.parentId} missing`});let X=U.parentId===null?"":V.get(U.parentId)?.hash;if(X!==void 0&&U.prevHash!==X)Q.push({kind:"chain-broken",entryId:U.id,line:O,detail:`prevHash disagrees with parent ${U.parentId??"(root)"}`});if(!V.has(U.id))V.set(U.id,U);let z=R(U.entry);if(z===void 0)Q.push({kind:"unknown-shape",entryId:U.id,line:O,detail:"entry is neither a message nor an event"});if(U.entry=this.hydrateImages(U.entry),this.cache.push(U),!W&&z!==void 0)K=U});let Y=new Map(this.cache.map((J)=>[J.id,J]));for(let J of this.cache){let O=new Set,U=J;while(U&&U.parentId!==null){if(O.has(U.id)){Q.push({kind:"cycle",entryId:J.id,line:-1,detail:"ancestry cycle"});break}O.add(U.id),U=Y.get(U.parentId)}}if(K)this.leaf=K.id,this.prevHash=K.hash;if(Z!==void 0){let J=Y.get(Z);if(J)this.leaf=J.id,this.prevHash=J.hash}return Q}append(q){this.materialize();let Q=q.parentId,Z=Q!==void 0?Q:this.leaf,$=this.prevHash;if(Z!==this.leaf)$=Z===null?"":this.cache.find((Y)=>Y.id===Z)?.hash??this.prevHash;if(this.staged.length>0&&"role"in q&&q.role==="user")q.parts.push(...this.staged),this.staged=[];let V=this.sidecarImages(q),K={id:q.id,parentId:Z,createdAt:q.createdAt??Date.now(),prevHash:$,hash:"",entry:V};if(K.hash=a($,K),i(this.file,JSON.stringify(K)+`
5
+ `),this.cache.push(V===q?K:{...K,entry:this.hydrateImages(V)}),this.leaf=K.id,this.prevHash=K.hash,this.leafPersisted)this.persistLeaf()}stageAttachments(q){this.staged=[...q]}get stagedAttachments(){return this.staged}sidecarImages(q){if(R(q)!=="message"||!("role"in q))return q;let Q=d(this.dir,q.parts);return Q===void 0?q:{...q,parts:Q}}hydrateImages(q){if(R(q)!=="message"||!("role"in q))return q;let Q=m(this.dir,q.parts);return Q===void 0?q:{...q,parts:Q}}appendEvent(q){this.materialize();let Q=this.leaf==="root"?null:this.leaf,Z={id:zq(),kind:"event",parentId:Q,createdAt:Date.now(),event:q},$={id:Z.id,parentId:Q,createdAt:Z.createdAt,prevHash:this.prevHash,hash:"",entry:Z};return $.hash=a(this.prevHash,$),i(this.file,JSON.stringify($)+`
6
+ `),this.cache.push($),Z}path(){return this.wrappedPath().filter((q)=>R(q.entry)!==void 0).map((q)=>q.entry)}wrappedPath(){let q=new Map(this.cache.map((J)=>[J.id,J])),Q=[],Z=q.get(this.leaf),$=new Set;while(Z&&!$.has(Z.id))$.add(Z.id),Q.unshift(Z),Z=Z.parentId?q.get(Z.parentId):void 0;let V=new Set(Q.map((J)=>J.id)),K=new Map;for(let J of this.cache){if(V.has(J.id)||!r(J))continue;if(J.parentId!==null&&!V.has(J.parentId))continue;let O=K.get(J.parentId)??[];O.push(J),K.set(J.parentId,O)}if(K.size===0)return Q;let Y=[...K.get(null)??[]];for(let J of Q)Y.push(J,...K.get(J.id)??[]);return Y}turnPoints(){let q=new Map;for(let Z of this.cache)if(!r(Z))q.set(Z.parentId,(q.get(Z.parentId)??0)+1);let Q=[];for(let Z of this.wrappedPath()){let $=Z.entry;if(R($)!=="message"||!("role"in $)||$.role!=="user")continue;Q.push({entryId:Z.id,index:Q.length+1,text:g($),fullText:$.parts.filter((V)=>V.kind==="text").map((V)=>V.text).join(""),parentId:Z.parentId,branches:(q.get(Z.parentId)??1)-1})}return Q}branch(q){let Q=this.cache.find((Z)=>Z.id===q);if(!Q)return!1;return this.leaf=Q.id,this.prevHash=Q.hash,this.persistLeaf(),!0}persistLeaf(){this.materialize(),this.meta={...this.meta,leaf:this.leaf},this.writeMeta(this.meta),this.leafPersisted=!0}patchMeta(q){this.materialize();let Q={};try{let $=JSON.parse(j(G(this.dir,"meta.json"),"utf8"));if($&&typeof $==="object"&&!Array.isArray($))Q=$}catch{Q={...this.meta}}let Z={...Q,...q,id:this.id};this.writeMeta(Z),this.meta={...this.meta,...q,id:this.id}}writeMeta(q){let Q=G(this.dir,"meta.json"),Z=Q+".tmp";p(Z,JSON.stringify(q,null,2)),Cq(Z,Q)}messages(){return this.path().filter((q)=>("role"in q))}}var Hq=B(()=>{b();n()});
7
+ export{Qq as pl,Zq as ql,S as rl,Fq as sl,kq as tl,_q as ul,u as vl,Oq as wl,gq as xl,Mq as yl,Eq as zl,Tq as Al,l as Bl,L as Cl,b as Dl,o as El,n as Fl,a as Gl,R as Hl,e as Il,Lq as Jl,dq as Kl,jq as Ll,Hq as Ml};
@@ -0,0 +1,3 @@
1
+ // @bun
2
+ import{Xi as T,Yi as y,cj as C}from"./main-sdmxhtv8.js";import{kk as F,lk as O,uk as h}from"./main-8kjxbpw4.js";import{$m as I,Um as D,_m as R}from"./main-2yeveeve.js";I();import{createInterface as _}from"readline";h();var A=[{key:"1",id:"anthropic",label:"anthropic \u2014 Claude models"},{key:"2",id:"openai",label:"openai"},{key:"3",id:"openrouter",label:"openrouter \u2014 many models behind one key"},{key:"4",id:"deepseek",label:"deepseek"},{key:"5",id:"groq",label:"groq"},{key:"6",id:"ollama",label:"ollama \u2014 local, no key needed",local:!0},{key:"7",id:"lmstudio",label:"lmstudio \u2014 local, no key needed",local:!0},{key:"8",label:"another OpenAI-compatible URL (a proxy, vLLM, \u2026)",url:"openai"},{key:"9",label:"another Anthropic-protocol URL",url:"anthropic"}],E='Done. Try: rovecode "explain this repo"';function K(G){return new Promise((q)=>{let J=_({input:process.stdin,output:process.stdout}),Y=!1;J.question(G,(H)=>{if(Y)return;Y=!0,J.close(),q(H.trim())}),J.once("close",()=>{if(!Y)Y=!0,q("")})})}async function v(G){let q=G.out??console.log,J=G.ask??K,Y=G.secret??((j)=>R(j)),H=G.save??D,W=G.registry,f=G.probe??((j,B)=>W.probe(j,B));if(!(G.tty??process.stdin.isTTY===!0))return q(O("cli")),q(" (rovecode setup needs a terminal \u2014 this stdin is a pipe)"),2;q("\u25C6 rovecode setup \u2014 let's connect a model. Two or three questions."),q("");for(let j of A)q(` ${j.key} ${j.label}`);q("");let Q;for(let j=0;j<3&&Q===void 0;j++){let B=(await J("Which one? [1-9, empty = cancel]: ")).trim();if(B.length===0)return q(`cancelled \u2014 nothing changed. ${F("rovecode setup")} whenever you like`),2;if(Q=A.find(($)=>$.key===B||$.id===B),Q===void 0)q(` "${B}" is not on the list \u2014 a number from 1 to 9, please.`)}if(Q===void 0)return 2;let z;if(Q.url!==void 0){if(z=(await J("Short name for it (letters, digits, - _ .): ")).trim().toLowerCase(),!T.test(z))return q(` "${z}" won't work as an id. ${F("rovecode setup, and pick a name like myproxy")}`),2;let j=(await J("Base URL (e.g. https://host/v1): ")).trim();if(!/^https?:\/\//.test(j))return q(` "${j}" is not an http(s) URL. ${F("rovecode setup")}`),2;let B=Q.url==="anthropic"?"anthropic":j.includes("anthropic.com")?y(j):"openai",$=(await J("Does it need an API key? [Y/n]: ")).trim().toLowerCase().startsWith("n"),V=W.add({id:z,baseUrl:j,protocol:B,...$?{noKey:!0}:{}},"user");if("error"in V)return q(` ${V.error}. ${F("rovecode setup")}`),2;q(`\u25C6 ${z} registered (${B} protocol, ${j}).`)}else{z=Q.id;let j=W.get(z);if(j===void 0)return q(` ${z} is missing from the built-in table \u2014 that is a bug. ${F("rovecode provider add "+z+" <baseUrl>")}`),2;if(Q.local===!0&&j.noKey!==!0){let B=W.add({id:z,baseUrl:j.baseUrl,protocol:j.protocol,noKey:!0,...j.defaultModel!==void 0?{defaultModel:j.defaultModel}:{}},"user");if("error"in B)return q(` ${B.error}. ${F("rovecode setup")}`),2;q(`\u25C6 ${z} marked as a local server (${j.baseUrl}, no key).`)}}let X=W.get(z),L=X.defaultModel,N=(await J(L!==void 0?`Model id [${L}]: `:"Model id (empty = choose later with rovecode model list): ")).trim(),Z=N.length>0?N:L,M=C(X);if(!M){let j=await Y(`${X.keyEnv} (hidden): `);if(j.trim().length===0)q(`\u25C6 no key stored \u2014 I can't call ${z} without one.`),q(` ${F(`rovecode auth set ${z}`)} (or set ${X.keyEnv} in your environment)`);else H(z,j.trim(),X.keyEnv),W.refresh(),M=!0,q(`\u25C6 key stored for ${z} (hidden; ~/.rovecode/credentials.json).`)}else q(`\u25C6 ${z} already has a key (${X.keySource==="stored"?"stored":`env ${X.keyEnv}`}).`);if(M&&Z!==void 0){q(`\u25C6 testing ${z}/${Z} \u2026`);let j=await f(z,Z);if(j.ok)q(` ${j.detail}`);else q(` that didn't work: ${j.detail}`),q(` ${F(`check the key and the URL, then rovecode provider test ${z} ${Z}`)}`)}if(Z!==void 0){let j=W.setDefault(`${z}/${Z}`,"user");if("error"in j)return q(` ${j.error}. ${F(`rovecode model use ${z}/<model>`)}`),2;q(`\u25C6 default \u2192 ${j.provider}/${j.model} (~/.rovecode/providers.json; running TUIs switch live).`)}else q(`\u25C6 ${z} is set up but has no model yet.`),q(` ${F(`rovecode model list ${z}, then rovecode model use ${z}/<model>`)}`);return q(""),q(E),q(" or open the cockpit: rovecode"),0}
3
+ export{A as wa,E as xa,K as ya,v as za};
@@ -0,0 +1,4 @@
1
+ // @bun
2
+ import{Zl as N,bm as Q}from"./main-0904f6ps.js";Q();import{resolve as V}from"path";var z="--add-dir",W="usage: rovecode [run] [--add-dir <dir>]\u2026 \u2014 an extra workspace root beside the cwd (repeatable; --add-dir=<dir> too)",X=(q)=>{return process.stderr.write(`error: ${q} \u2014 ${W}
3
+ `),process.exit(2)},Y=(q)=>q.length>1&&q.startsWith("-");function w(q,B=X,O=process.cwd()){let C=q.slice(2),H=[];for(let y=0;y<C.length;y++){let J=C[y],j;if(J===z){if(j=C[y+1],j===void 0||Y(j))return B(`${z} needs a value`);y++}else if(J.startsWith(`${z}=`))j=J.slice(z.length+1);else continue;if(j.trim().length===0)return B(`${z} needs a directory`);let K=V(O,j),M=N(K,j);if(M!==void 0)return B(M);if(!H.includes(K))H.push(K)}return H}
4
+ export{z as vh,W as wh,w as xh};
@@ -0,0 +1,3 @@
1
+ // @bun
2
+ import{hj as X,ij as Y,kj as Z,lj as $}from"./main-pknhvrmj.js";import{$m as b,Nm as J,Tm as Q,Xm as W}from"./main-2yeveeve.js";b();var m=`usage: rovecode auth login <${X.join("|")}>`;function C(j,k=Date.now()){if(j>=Number.MAX_SAFE_INTEGER||j>8640000000000000)return"never expires";if(!(j>=-8640000000000000))return"EXPIRED (invalid expiry)";let q=new Date(j).toISOString();return j<=k?`EXPIRED ${q}`:`expires ${q}`}function G(j=W(),k=Date.now()){return j.map((q)=>{let z=q.kind==="oauth"&&q.expires!==void 0?` ${C(q.expires,k)}`:"";return`${q.provider.padEnd(14)} ${q.kind.padEnd(6)} ${q.keyName.padEnd(24)} ${q.redacted}${z}`})}function f(){let j=G();if(j.length===0){console.log(`no stored credentials (${J()}) \u2014 run: rovecode auth set <provider> | rovecode auth login <provider>`);return}for(let k of j)console.log(k)}function H(j){switch(j.type){case"device_code":return[`open ${j.verificationUri}`,`enter ${j.userCode}`,`waiting for authorization \u2014 polling every ${j.intervalSeconds}s, up to ${Math.max(1,Math.round(j.expiresInSeconds/60))} min (Ctrl-C cancels)`];case"auth_url":return[`open ${j.url}`,`waiting for the browser to return to ${j.callbackUrl} (loopback \u2014 the browser must run on this machine; Ctrl-C cancels)`];case"progress":return[j.message]}}async function L(j,k){let q=k.provider===void 0?Y[j]:void 0;if(q!==void 0)return k.err(`rovecode auth login ${j}: refused \u2014 ${q}`),1;let z=(k.provider??Z)(j);if(!z){if(j.length>0)k.err(`error: no OAuth login for "${j}"`);return k.err(m),1}let K=k.signal??new AbortController().signal,M={...$(),...k.oauth};k.out(`rovecode auth login ${j} \u2014 ${z.label}`);try{let B=await z.login({notify:(F)=>{for(let V of H(F))k.out(` ${V}`)},signal:K},M);return(k.save??Q)(j,B),k.out(`stored OAuth token for ${j} in ${J()} (${C(B.expires,M.now())})`),0}catch(B){if(K.aborted)return k.err("login cancelled"),130;return k.err(`error: ${B instanceof Error?B.message:String(B)}`),1}}async function y(j){let k=new AbortController,q=()=>k.abort();process.once("SIGINT",q);try{return await L(j[0]??"",{out:(z)=>console.log(z),err:(z)=>console.error(z),signal:k.signal})}finally{process.removeListener("SIGINT",q)}}
3
+ export{m as Gc,C as Hc,G as Ic,f as Jc,H as Kc,L as Lc,y as Mc};
@@ -0,0 +1,14 @@
1
+ // @bun
2
+ import{Df as c,Ef as I,Ff as p,Gf as i,Hf as a}from"./main-skbp13js.js";import{Th as s,Uh as d}from"./main-0z1w2zsg.js";s();var w="https://mcp.exa.ai/mcp",U=8,h=20,C=1000,n=500,m=200,r=2000,v=16000,R=1048576,S=5,E=25000,t=`Mozilla/5.0 (compatible; rovecode/${d.version} web_search)`,e="application/json, text/event-stream",zz=new Set([301,302,303,307,308]),Zz=96;function $z($){let z=typeof $==="string"&&$.trim()!==""?Number($):$;return typeof z==="number"&&Number.isFinite(z)&&z>0?Math.min(Math.floor(z),h):U}function k($,z){return $.length<=z?$:$.slice(0,z-1).replace(/[\uD800-\uDBFF]$/,"")+"\u2026"}function T($){let z;try{z=JSON.parse($)}catch{return null}if(!z||typeof z!=="object")return null;let G=z;if(G.error&&typeof G.error==="object"){let J=G.error.message;return{error:typeof J==="string"&&J!==""?J:JSON.stringify(G.error)}}if(!G.result||typeof G.result!=="object")return null;let V=G.result,Z=(Array.isArray(V.content)?V.content:[]).map((J)=>J&&typeof J==="object"?J.text:void 0).find((J)=>typeof J==="string"&&J!=="");if(V.isError===!0)return{error:Z??"backend reported an error without a message"};return Z===void 0?null:{text:Z}}function Gz($){let z=$.trim();if(z.startsWith("{")){let G=T(z);if(G)return G}for(let G of $.split(`
3
+ `)){if(!G.startsWith("data:"))continue;let V=T(G.slice(5).trim());if(V)return V}return null}function u($){let z=[];for(let G of $.split(/\r?\n/)){let V=G.trim();if(V==="")continue;if(V==="..."){if(z.length>0&&z[z.length-1]!=="\u2026")z.push("\u2026");continue}z.push(V)}while(z.length>0&&z[z.length-1]==="\u2026")z.pop();return z.join(" ").replace(/\s+/g," ").trim()}var Jz=/^(Title|URL|Published|Author|Score|ID|Image|Favicon):\s*(.*)$/,Vz=/^(Highlights|Text|Summary):\s*$/;function Wz($){let z=[];for(let G of $.split(/\r?\n\s*---\s*\r?\n/)){let V=G.split(/\r?\n/),K={},Z=0;for(;Z<V.length;Z++){let W=V[Z].trim();if(W===""){if(Object.keys(K).length>0)break;continue}let Q=Jz.exec(W);if(!Q)break;K[Q[1]]=Q[2].trim()}while(Z<V.length&&V[Z].trim()==="")Z++;if(Z<V.length&&Vz.test(V[Z].trim()))Z++;let J=K.URL??"";if(!/^https?:\/\//i.test(J))continue;let Y=K.Published;z.push({title:K.Title||J,url:J,snippet:u(V.slice(Z).join(`
4
+ `)),...Y&&Y.toUpperCase()!=="N/A"?{publishedDate:Y}:{}})}return z}function Kz($){let z;try{z=JSON.parse($)}catch{return null}let G=z&&typeof z==="object"?z.results:void 0;if(!Array.isArray(G))return null;let V=[];for(let K of G){if(!K||typeof K!=="object")continue;let Z=K,J=typeof Z.url==="string"?Z.url:"";if(!/^https?:\/\//i.test(J))continue;let Y=Array.isArray(Z.highlights)?Z.highlights.filter((X)=>typeof X==="string"):[],W=typeof Z.text==="string"?Z.text:Y.length>0?Y.join(`
5
+ ...
6
+ `):typeof Z.summary==="string"?Z.summary:"",Q=typeof Z.publishedDate==="string"&&Z.publishedDate!==""?Z.publishedDate:void 0;V.push({title:typeof Z.title==="string"&&Z.title!==""?Z.title:J,url:J,snippet:u(W),...Q?{publishedDate:Q}:{}})}return V}function Qz($){let z=$.trim();if(z===""||/^No search results found/i.test(z))return[];if(z.startsWith("{"))return Kz(z);let G=Wz(z);return G.length>0?G:null}function Xz($,z,G=v){let V=`${z.length} result${z.length===1?"":"s"} for "${k($,m)}" (Exa web search)`,K=z.map((W,Q)=>{let X=`${Q+1}. ${k(W.title.replace(/\s+/g," ").trim(),m)} \xB7 ${k(W.url,r)}${W.publishedDate?` \xB7 ${W.publishedDate}`:""}`,g=k(W.snippet,n);return g===""?X:`${X}
7
+ ${g}`}),Z=V,J=0;for(let W of K){if(Z.length+2+W.length+Zz>G)break;Z+=`
8
+
9
+ ${W}`,J++}let Y=J<K.length;if(Y)Z+=`
10
+
11
+ (Showing ${J} of ${z.length} results: output capped at ${G} characters.)`;return{output:Z,shown:J,truncated:Y}}function L($){return $.origin+$.pathname}function Bz($={}){let z=$.fetch??((W,Q)=>fetch(W,Q)),G=$.resolve??c,V=typeof $.timeoutMs==="number"&&Number.isFinite($.timeoutMs)&&$.timeoutMs>0?Math.floor($.timeoutMs):E,K=typeof $.apiKey==="string"?$.apiKey.trim():"",Z=K===""?w:`${w}?exaApiKey=${encodeURIComponent(K)}`,J=(W,Q)=>{let X=W.split(Z).join(w).split(Q.href).join(L(Q));if(K!=="")for(let g of new Set([K,encodeURIComponent(K)]))X=X.split(g).join("[key]");return X};async function Y(W,Q){let X=typeof W.query==="string"?W.query.trim():"";if(X==="")return{ok:!1,output:"web_search: query is required"};if(X.length>C)return{ok:!1,output:`web_search: query too long (${X.length} characters; max ${C})`};let g=$z(W.max_results);if(Q.signal.aborted)return{ok:!1,output:"web_search: aborted"};let o=JSON.stringify({jsonrpc:"2.0",id:1,method:"tools/call",params:{name:"web_search_exa",arguments:{query:X,type:"auto",numResults:g,livecrawl:"fallback",contextMaxCharacters:Math.max(1e4,g*1500)}}}),N=new AbortController,x=!1,B=new URL(Z),A=setTimeout(()=>{x=!0,N.abort()},V);A.ref?.();let _=()=>N.abort();Q.signal.addEventListener("abort",_,{once:!0});let P=(q)=>{if(N.signal.aborted)return{ok:!1,output:x?`web_search: timed out after ${V}ms`:"web_search: aborted"};return{ok:!1,output:`web_search: request failed: ${J(q instanceof Error?q.message:String(q),B)}`}};try{let q=I(B.hostname),l=0;for(;;){if(B.protocol!=="http:"&&B.protocol!=="https:")return{ok:!1,output:`web_search: backend redirected to unsupported URL scheme ${B.protocol} (http/https only)`};let b;try{b=await i(p(B.hostname,G),N.signal)}catch(F){return P(F)}if(b!==null)return{ok:!1,output:`web_search: refused ${L(B)}: ${J(b,B)}`};if(I(B.hostname)!==q)return{ok:!1,output:`web_search: backend redirected to ${L(B)} (${I(B.hostname)} is not ${q}); not followed`};let j;try{j=await z(B.href,{method:"POST",redirect:"manual",signal:N.signal,body:o,headers:{"User-Agent":t,Accept:e,"Content-Type":"application/json"}})}catch(F){return P(F)}if(zz.has(j.status)){let F=j.headers.get("location");if(await j.body?.cancel().catch(()=>{}),!F)return{ok:!1,output:`web_search: HTTP ${j.status} redirect from ${L(B)} without a Location header`};if(++l>S)return{ok:!1,output:`web_search: too many redirects (more than ${S}) from ${w}`};try{B=new URL(F,B)}catch{return{ok:!1,output:`web_search: invalid redirect target ${F}`}}continue}let D;try{D=await a(j,j.ok?R:2048)}catch(F){return P(F)}let y=new TextDecoder().decode(D.bytes);if(!j.ok){let F=y.split(/\r?\n/).map((f)=>f.trim()).find((f)=>f!=="")??"";return{ok:!1,output:`web_search: backend HTTP ${j.status}${F===""?"":`: ${k(J(F,B),200)}`}`}}let O=Gz(y);if(O===null)return{ok:!1,output:`web_search: malformed backend response (${D.truncated?`body truncated at ${R} bytes`:`${D.bytes.length} bytes, no JSON-RPC result with text`})`};if("error"in O)return{ok:!1,output:`web_search: backend error: ${k(J(O.error,B).replace(/\s+/g," ").trim(),300)}`};let M=Qz(O.text);if(M===null){let F=O.text.trim(),f=k(F,v);return{ok:!0,output:`web_search "${k(X,m)}": the backend answered in an unrecognized format; shown verbatim${f.length<F.length?` (capped at ${v} characters)`:""}:
12
+
13
+ ${f}`,data:{query:X,count:0,total:0,unstructured:!0,truncated:f.length<F.length}}}if(M.length===0)return{ok:!0,output:`No results for "${k(X,m)}" (Exa web search). Try different or fewer terms.`,data:{query:X,count:0,total:0,results:[],truncated:!1}};let H=Xz(X,M.slice(0,g));return{ok:!0,output:H.output,data:{query:X,count:H.shown,total:M.length,results:M.slice(0,H.shown),truncated:H.shown<M.length}}}}finally{clearTimeout(A),Q.signal.removeEventListener("abort",_)}}return{schema:{name:"web_search",description:`Search the web and return up to max_results ranked results (default ${U}, cap ${h}), each as "N. title \xB7 url \xB7 published date (when known)" followed by a snippet of at most ${n} characters; the whole output is capped at ${v} characters (trailing results dropped, with a marker). Results are search snippets, not pages: call web_fetch on a result's url to read it. Backend: Exa via its hosted MCP endpoint (${w}); no API key is required. Times out after ${E/1000}s; a backend that redirects elsewhere or resolves to a private address is refused. The current year is ${new Date().getFullYear()}: put it in queries about recent events.`,args:{type:"object",properties:{query:{type:"string",description:`search query in plain words (at most ${C} characters)`},max_results:{type:"integer",description:`results to return (default ${U}, cap ${h})`}},required:["query"]}},kind:"network",sequential:!1,execute:(W,Q)=>Y(W??{},Q)}}var jz=Bz();
14
+ export{w as ne,U as oe,h as pe,C as qe,n as re,m as se,r as te,v as ue,R as ve,S as we,E as xe,$z as ye,Gz as ze,Wz as Ae,Qz as Be,Xz as Ce,Bz as De,jz as Ee};
@@ -0,0 +1,3 @@
1
+ // @bun
2
+ import{wn as G}from"./main-qsevpgsv.js";function W(x){let y=x.provider.toLowerCase(),B=x.model.toLowerCase();if(L.has(y))return J;let b=K.find((z)=>z.provider===y&&z.match.test(B));return b?{scale:b.scale,charScale:b.charScale,measured:!0,note:b.note}:H}var H,J,K,L;var Q=G(()=>{H={scale:1,charScale:1,measured:!1,note:"no measurement for this model \u2014 the estimate is used as-is; bun scripts/measure-tokenizer.ts measures it"},J={scale:1,charScale:1,measured:!0,note:"o200k is this vendor's own tokenizer \u2014 the estimate is exact"},K=[{provider:"anthropic",match:/(opus-5|sonnet-5|fable-5|mythos-5)/,scale:1.8,charScale:1.82,note:"measured 2026-09-05 against /v1/messages/count_tokens over 20 samples \u2014 o200k reads up to 1.79\xD7 low on Claude 5"},{provider:"anthropic",match:/(haiku-4-5|opus-4-5|sonnet-4-6)/,scale:1.29,charScale:1.46,note:"measured 2026-09-05 against /v1/messages/count_tokens over 20 samples \u2014 o200k reads up to 1.29\xD7 low on Claude 4.5/4.6"}],L=new Set(["openai"])});
3
+ export{W as Hd,Q as Id};