rovecode 0.4.0-beta.3 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (432) hide show
  1. package/README.md +57 -72
  2. package/THIRD_PARTY_NOTICES.md +0 -44
  3. package/bin/rovecode.ts +21 -0
  4. package/package.json +16 -38
  5. package/src/account/keys.ts +97 -0
  6. package/src/account/login.ts +158 -0
  7. package/src/account/provision.ts +47 -0
  8. package/src/account/store.ts +63 -0
  9. package/src/acp/server.ts +373 -0
  10. package/src/cli/account-cmd.ts +116 -0
  11. package/src/cli/connect.ts +244 -0
  12. package/src/cli/context-cmd.ts +199 -0
  13. package/src/cli/dispatch.ts +109 -0
  14. package/src/cli/doctor.ts +324 -0
  15. package/src/cli/export.ts +278 -0
  16. package/src/cli/help.ts +240 -0
  17. package/src/cli/is-tui-invocation.ts +8 -0
  18. package/src/cli/main.ts +599 -0
  19. package/src/cli/market-cmd.ts +658 -0
  20. package/src/cli/mcp-market-cmd.ts +299 -0
  21. package/src/cli/output.ts +382 -0
  22. package/src/cli/repl.ts +172 -0
  23. package/src/cli/resume.ts +32 -0
  24. package/src/cli/run-limits.ts +78 -0
  25. package/src/cli/runtime.ts +792 -0
  26. package/src/cli/setup.ts +187 -0
  27. package/src/cli/update-cmd.ts +78 -0
  28. package/src/cli/workflow-cmd.ts +100 -0
  29. package/src/coding/checkpoints.ts +270 -0
  30. package/src/coding/diff.ts +136 -0
  31. package/src/coding/files.ts +339 -0
  32. package/src/coding/hashline.ts +319 -0
  33. package/src/coding/lsp.ts +406 -0
  34. package/src/coding/repomap-cache.ts +99 -0
  35. package/src/coding/repomap-files.ts +110 -0
  36. package/src/coding/repomap.ts +392 -0
  37. package/src/core/compaction.ts +399 -0
  38. package/src/core/config.ts +289 -0
  39. package/src/core/context-report.ts +228 -0
  40. package/src/core/context.ts +60 -0
  41. package/src/core/count-remote.ts +107 -0
  42. package/src/core/execpolicy-rules.ts +196 -0
  43. package/src/core/execpolicy.ts +385 -0
  44. package/src/core/executor.ts +397 -0
  45. package/src/core/guardrails.ts +400 -0
  46. package/src/core/hooks.ts +398 -0
  47. package/src/core/images.ts +230 -0
  48. package/src/core/intro.ts +236 -0
  49. package/src/core/loop.ts +621 -0
  50. package/src/core/modes.ts +372 -0
  51. package/src/core/orchestrator.ts +207 -0
  52. package/src/core/reflection.ts +165 -0
  53. package/src/core/sandbox-config.ts +167 -0
  54. package/src/core/session-images.ts +73 -0
  55. package/src/core/session.ts +398 -0
  56. package/src/core/settings.ts +98 -0
  57. package/src/core/stuck-detector.ts +273 -0
  58. package/src/core/tasks.ts +374 -0
  59. package/src/core/token-scale.ts +108 -0
  60. package/src/core/tool-output-budget.ts +166 -0
  61. package/src/core/tools.ts +288 -0
  62. package/src/core/types.ts +330 -0
  63. package/src/core/update-check.ts +171 -0
  64. package/src/core/update.ts +158 -0
  65. package/src/core/usage.ts +204 -0
  66. package/src/core/validate.ts +121 -0
  67. package/src/core/verify-gate.ts +159 -0
  68. package/src/core/verify.ts +237 -0
  69. package/src/core/voice.ts +158 -0
  70. package/src/core/win-job.ts +183 -0
  71. package/src/design/audit.ts +797 -0
  72. package/src/design/direction.ts +190 -0
  73. package/src/design/rules.ts +157 -0
  74. package/src/eval/bench.ts +150 -0
  75. package/src/eval/gauntlet-runner.ts +218 -0
  76. package/src/eval/gauntlet.ts +226 -0
  77. package/src/eval/grader.ts +186 -0
  78. package/src/eval/record.ts +202 -0
  79. package/src/eval/redact.ts +141 -0
  80. package/src/eval/replay.ts +147 -0
  81. package/src/eval/trajectory.ts +373 -0
  82. package/src/index.ts +17 -0
  83. package/src/market/catalogs/mcp-docs.json +111 -0
  84. package/src/market/catalogs/plugins.json +111 -0
  85. package/src/market/catalogs/skills.json +478 -0
  86. package/src/market/clone.ts +72 -0
  87. package/src/market/context-cost.ts +121 -0
  88. package/src/market/digest.ts +106 -0
  89. package/src/market/index.ts +22 -0
  90. package/src/market/install.ts +578 -0
  91. package/src/market/manifest.ts +187 -0
  92. package/src/market/prereq.ts +145 -0
  93. package/src/market/registry.ts +363 -0
  94. package/src/market/resolve.ts +111 -0
  95. package/src/market/types.ts +236 -0
  96. package/src/market/validate.ts +227 -0
  97. package/src/mcp/client.ts +431 -0
  98. package/src/mcp/config.ts +239 -0
  99. package/src/mcp/local-package.ts +211 -0
  100. package/src/mcp/market-catalog.ts +84 -0
  101. package/src/mcp/market-install.ts +289 -0
  102. package/src/mcp/market.ts +0 -0
  103. package/src/mcp/tools.ts +131 -0
  104. package/src/mcp/trust.ts +49 -0
  105. package/src/memory/blocks.ts +175 -0
  106. package/src/memory/recall.ts +355 -0
  107. package/src/memory/store.ts +105 -0
  108. package/src/memory/tools.ts +99 -0
  109. package/src/plugins/cli.ts +123 -0
  110. package/src/plugins/discover.ts +108 -0
  111. package/src/plugins/index.ts +50 -0
  112. package/src/plugins/init.ts +140 -0
  113. package/src/plugins/install.ts +184 -0
  114. package/src/plugins/load.ts +149 -0
  115. package/src/plugins/manifest.ts +106 -0
  116. package/src/plugins/state.ts +83 -0
  117. package/src/providers/auth.ts +293 -0
  118. package/src/providers/cache.ts +223 -0
  119. package/src/providers/catalog-local.ts +160 -0
  120. package/src/providers/catalog.ts +408 -0
  121. package/src/providers/middleware-context.ts +86 -0
  122. package/src/providers/middleware.ts +373 -0
  123. package/src/providers/profile-glm53.ts +111 -0
  124. package/src/providers/profile-sonnet5-persona.ts +65 -0
  125. package/src/providers/profile-sonnet5-voice.ts +23 -0
  126. package/src/providers/profiles.ts +156 -0
  127. package/src/providers/provider-config.ts +311 -0
  128. package/src/providers/registry.ts +302 -0
  129. package/src/providers/response-validation.ts +80 -0
  130. package/src/providers/retry.ts +234 -0
  131. package/src/providers/router.ts +294 -0
  132. package/src/providers/sse.ts +26 -0
  133. package/src/providers/stream-errors.ts +117 -0
  134. package/src/providers/stream.ts +569 -0
  135. package/src/providers/thinking.ts +189 -0
  136. package/src/providers/wire-messages.ts +129 -0
  137. package/src/sdk/client.ts +225 -0
  138. package/src/sdk/index.ts +3 -0
  139. package/src/server/dashboard.ts +144 -0
  140. package/src/server/http.ts +343 -0
  141. package/src/server/openapi.ts +246 -0
  142. package/src/sextant/card-hits.ts +102 -0
  143. package/src/sextant/card-keys.ts +55 -0
  144. package/src/sextant/context-source.ts +157 -0
  145. package/src/sextant/draw-agents.ts +273 -0
  146. package/src/sextant/draw-code.ts +388 -0
  147. package/src/sextant/draw-context.ts +222 -0
  148. package/src/sextant/draw-frame.ts +164 -0
  149. package/src/sextant/draw-market.ts +573 -0
  150. package/src/sextant/draw-messages.ts +386 -0
  151. package/src/sextant/draw-pet.ts +230 -0
  152. package/src/sextant/draw-plan.ts +159 -0
  153. package/src/sextant/draw-tabs.ts +85 -0
  154. package/src/sextant/draw-util.ts +65 -0
  155. package/src/sextant/engine.ts +230 -0
  156. package/src/sextant/frame-hits.ts +25 -0
  157. package/src/sextant/frame.ts +101 -0
  158. package/src/sextant/git-status.ts +197 -0
  159. package/src/sextant/grid.ts +59 -0
  160. package/src/sextant/input.ts +119 -0
  161. package/src/sextant/keys.ts +488 -0
  162. package/src/sextant/layout.ts +86 -0
  163. package/src/sextant/local-commands.ts +156 -0
  164. package/src/sextant/market-source.ts +287 -0
  165. package/src/sextant/mentions.ts +141 -0
  166. package/src/sextant/message-hits.ts +26 -0
  167. package/src/sextant/model.ts +387 -0
  168. package/src/sextant/overlays.ts +451 -0
  169. package/src/sextant/panel-hits.ts +38 -0
  170. package/src/sextant/pet.ts +399 -0
  171. package/src/sextant/screen.ts +324 -0
  172. package/src/sextant/scroll-hits.ts +66 -0
  173. package/src/sextant/scrollbar.ts +82 -0
  174. package/src/sextant/selection.ts +123 -0
  175. package/src/sextant/sextant-bridge.ts +174 -0
  176. package/src/sextant/sextant-cards.ts +142 -0
  177. package/src/sextant/sextant-diff-base.ts +63 -0
  178. package/src/sextant/sextant-files.ts +154 -0
  179. package/src/sextant/sextant-frame-loop.ts +314 -0
  180. package/src/sextant/sextant-renderer.ts +478 -0
  181. package/src/sextant/sextant-repo.ts +131 -0
  182. package/src/sextant/theme.ts +66 -0
  183. package/src/sextant/tool-rows.ts +189 -0
  184. package/src/sextant/types.ts +473 -0
  185. package/src/skills/index.ts +306 -0
  186. package/src/skills/tools.ts +69 -0
  187. package/src/skills/versioned.ts +227 -0
  188. package/src/telemetry/otel.ts +353 -0
  189. package/src/telemetry/otlp.ts +68 -0
  190. package/src/tools/ask-user.ts +156 -0
  191. package/src/tools/design.ts +151 -0
  192. package/src/tools/evalcell.ts +338 -0
  193. package/src/tools/html-text.ts +139 -0
  194. package/src/tools/provider.ts +149 -0
  195. package/src/tools/task.ts +216 -0
  196. package/src/tools/todo.ts +320 -0
  197. package/src/tools/webfetch.ts +331 -0
  198. package/src/tui/app.ts +608 -0
  199. package/src/tui/attach.ts +127 -0
  200. package/src/tui/checkpoints-cmd.ts +70 -0
  201. package/src/tui/clipboard-image.ts +81 -0
  202. package/src/tui/commands.ts +277 -0
  203. package/src/tui/cost.ts +108 -0
  204. package/src/tui/info-cmd.ts +144 -0
  205. package/src/tui/mcp-cmd.ts +128 -0
  206. package/src/tui/modes-cmd.ts +45 -0
  207. package/src/tui/overlays.ts +97 -0
  208. package/src/tui/pi-renderer.ts +424 -0
  209. package/src/tui/providers-cmd.ts +366 -0
  210. package/src/tui/renderer.ts +101 -0
  211. package/src/tui/replay-marker.ts +29 -0
  212. package/src/tui/session-cmd.ts +146 -0
  213. package/src/tui/sextant-attach.ts +68 -0
  214. package/src/tui/sextant-io.ts +184 -0
  215. package/src/tui/sextant-smoke.ts +110 -0
  216. package/src/tui/smoke.ts +72 -0
  217. package/src/tui/theme.ts +59 -0
  218. package/src/tui/todo-label.ts +7 -0
  219. package/src/workflow/engine.ts +266 -0
  220. package/tsconfig.json +30 -0
  221. package/vendor/pi-tui/LICENSE +21 -0
  222. package/vendor/pi-tui/PATCHES.md +12 -0
  223. package/vendor/pi-tui/PROVENANCE.md +12 -0
  224. package/vendor/pi-tui/README.upstream.md +854 -0
  225. package/vendor/pi-tui/native/win32/prebuilds/win32-arm64/win32-console-mode.node +0 -0
  226. package/vendor/pi-tui/native/win32/prebuilds/win32-x64/win32-console-mode.node +0 -0
  227. package/vendor/pi-tui/src/alt-screen-search.ts +158 -0
  228. package/vendor/pi-tui/src/autocomplete.ts +827 -0
  229. package/vendor/pi-tui/src/components/alt-screen-flash.ts +52 -0
  230. package/vendor/pi-tui/src/components/box.ts +138 -0
  231. package/vendor/pi-tui/src/components/cancellable-loader.ts +41 -0
  232. package/vendor/pi-tui/src/components/editor.ts +2364 -0
  233. package/vendor/pi-tui/src/components/h-stack.ts +45 -0
  234. package/vendor/pi-tui/src/components/image.ts +128 -0
  235. package/vendor/pi-tui/src/components/input.ts +448 -0
  236. package/vendor/pi-tui/src/components/loader.ts +93 -0
  237. package/vendor/pi-tui/src/components/markdown.ts +1016 -0
  238. package/vendor/pi-tui/src/components/scroll-view.ts +217 -0
  239. package/vendor/pi-tui/src/components/select-list.ts +230 -0
  240. package/vendor/pi-tui/src/components/settings-list.ts +277 -0
  241. package/vendor/pi-tui/src/components/spacer.ts +29 -0
  242. package/vendor/pi-tui/src/components/stack.ts +155 -0
  243. package/vendor/pi-tui/src/components/text.ts +108 -0
  244. package/vendor/pi-tui/src/components/truncated-text.ts +66 -0
  245. package/vendor/pi-tui/src/components/v-stack.ts +34 -0
  246. package/vendor/pi-tui/src/editor-component.ts +75 -0
  247. package/vendor/pi-tui/src/fuzzy.ts +138 -0
  248. package/vendor/pi-tui/src/index.ts +149 -0
  249. package/vendor/pi-tui/src/keybindings.ts +321 -0
  250. package/vendor/pi-tui/src/keys.ts +1402 -0
  251. package/vendor/pi-tui/src/kill-ring.ts +47 -0
  252. package/vendor/pi-tui/src/latex.ts +1381 -0
  253. package/vendor/pi-tui/src/layout-node.ts +52 -0
  254. package/vendor/pi-tui/src/layout.ts +411 -0
  255. package/vendor/pi-tui/src/native-modifiers.ts +60 -0
  256. package/vendor/pi-tui/src/native-module-path.ts +32 -0
  257. package/vendor/pi-tui/src/stdin-buffer.ts +445 -0
  258. package/vendor/pi-tui/src/terminal-colors.ts +74 -0
  259. package/vendor/pi-tui/src/terminal-image.ts +701 -0
  260. package/vendor/pi-tui/src/terminal.ts +554 -0
  261. package/vendor/pi-tui/src/tui-alt-screen.ts +1379 -0
  262. package/vendor/pi-tui/src/tui-main-screen.ts +655 -0
  263. package/vendor/pi-tui/src/tui.ts +1264 -0
  264. package/vendor/pi-tui/src/undo-stack.ts +29 -0
  265. package/vendor/pi-tui/src/utils.ts +1327 -0
  266. package/vendor/pi-tui/src/word-navigation.ts +118 -0
  267. package/vendor/pi-tui/test/test-themes.ts +39 -0
  268. package/vendor/pi-tui/test/virtual-terminal.ts +219 -0
  269. package/CHANGELOG.md +0 -527
  270. package/bin/rovecode.js +0 -24
  271. package/dist/cli/app-j6gn14w3.js +0 -2
  272. package/dist/cli/ask-user-cwstt8fz.js +0 -2
  273. package/dist/cli/auth-login-9bbp9915.js +0 -2
  274. package/dist/cli/auth-m8p9grty.js +0 -2
  275. package/dist/cli/bench-16zqdms5.js +0 -9
  276. package/dist/cli/catalog-1xchffa4.js +0 -2
  277. package/dist/cli/cli-1n1zb64f.js +0 -2
  278. package/dist/cli/client-2t9gjkck.js +0 -2
  279. package/dist/cli/commands-exafvm2b.js +0 -2
  280. package/dist/cli/connect-6zde0kn3.js +0 -2
  281. package/dist/cli/context-cmd-5t43wgqt.js +0 -2
  282. package/dist/cli/context-report-kt01pw8y.js +0 -2
  283. package/dist/cli/count-remote-ap7x3vh6.js +0 -2
  284. package/dist/cli/design-ne5zszyh.js +0 -2
  285. package/dist/cli/dispatch-2r5myxye.js +0 -2
  286. package/dist/cli/doctor-ws4fh4tn.js +0 -3
  287. package/dist/cli/executor-bdrjn634.js +0 -2
  288. package/dist/cli/export-1mxb9g5p.js +0 -2
  289. package/dist/cli/files-g104xghh.js +0 -2
  290. package/dist/cli/gauntlet-07xrjpj7.js +0 -2
  291. package/dist/cli/gauntlet-runner-xvy64436.js +0 -10
  292. package/dist/cli/gauntlet-wave3-jm91yt5w.js +0 -5
  293. package/dist/cli/gauntlet-wave4-r13py7p1.js +0 -14
  294. package/dist/cli/hashline-znvrat11.js +0 -2
  295. package/dist/cli/http-xafw6fsh.js +0 -143
  296. package/dist/cli/index-1sgjm25y.js +0 -2
  297. package/dist/cli/init-g2m0tn4m.js +0 -51
  298. package/dist/cli/install-avaqjjqq.js +0 -2
  299. package/dist/cli/loop-mmpfft01.js +0 -2
  300. package/dist/cli/main-0904f6ps.js +0 -5
  301. package/dist/cli/main-0ab9fc26.js +0 -9
  302. package/dist/cli/main-0jys2ccn.js +0 -3
  303. package/dist/cli/main-0mtcdbs7.js +0 -3
  304. package/dist/cli/main-0z1w2zsg.js +0 -3
  305. package/dist/cli/main-1dchs7xv.js +0 -18
  306. package/dist/cli/main-1ereejm1.js +0 -3
  307. package/dist/cli/main-1k1kw6b5.js +0 -3
  308. package/dist/cli/main-27y4sm2k.js +0 -38
  309. package/dist/cli/main-2wwjex5j.js +0 -58
  310. package/dist/cli/main-2yeveeve.js +0 -6
  311. package/dist/cli/main-2yfck9b5.js +0 -3
  312. package/dist/cli/main-2zmzgkwh.js +0 -3
  313. package/dist/cli/main-351pz3z7.js +0 -7
  314. package/dist/cli/main-3gjqfh7a.js +0 -6
  315. package/dist/cli/main-3nf3kgve.js +0 -3
  316. package/dist/cli/main-3pjrb2hd.js +0 -3
  317. package/dist/cli/main-3rxcvgna.js +0 -19
  318. package/dist/cli/main-4b3jgy66.js +0 -19
  319. package/dist/cli/main-4wndhjdc.js +0 -7
  320. package/dist/cli/main-4xcmvxnk.js +0 -3
  321. package/dist/cli/main-5tbz0wbz.js +0 -4
  322. package/dist/cli/main-5ywnwthm.js +0 -3
  323. package/dist/cli/main-6b62vkz0.js +0 -14
  324. package/dist/cli/main-6dnk69vp.js +0 -3
  325. package/dist/cli/main-6genrmhs.js +0 -136
  326. package/dist/cli/main-73g7eff4.js +0 -15
  327. package/dist/cli/main-7c5thhjd.js +0 -5
  328. package/dist/cli/main-7rn6bqje.js +0 -3
  329. package/dist/cli/main-80haw7qk.js +0 -4
  330. package/dist/cli/main-875s60s2.js +0 -4
  331. package/dist/cli/main-8kjxbpw4.js +0 -8
  332. package/dist/cli/main-90ds1z4e.js +0 -10
  333. package/dist/cli/main-9etavkew.js +0 -3
  334. package/dist/cli/main-a9njrkk1.js +0 -3
  335. package/dist/cli/main-aecrjq2d.js +0 -12
  336. package/dist/cli/main-ck9asesq.js +0 -9
  337. package/dist/cli/main-cta9racd.js +0 -4
  338. package/dist/cli/main-ddv7j2ag.js +0 -3
  339. package/dist/cli/main-dfreez27.js +0 -10
  340. package/dist/cli/main-f7rw7des.js +0 -3
  341. package/dist/cli/main-ggcn7rd7.js +0 -5
  342. package/dist/cli/main-gzkmycnv.js +0 -3
  343. package/dist/cli/main-hq51jg8v.js +0 -18
  344. package/dist/cli/main-jft389w9.js +0 -8
  345. package/dist/cli/main-k1eqkg83.js +0 -3
  346. package/dist/cli/main-k2y8a2aw.js +0 -9
  347. package/dist/cli/main-kcpbykxz.js +0 -4
  348. package/dist/cli/main-kd488vje.js +0 -22
  349. package/dist/cli/main-kh32yvgk.js +0 -5
  350. package/dist/cli/main-kqxnqjnv.js +0 -25
  351. package/dist/cli/main-kyn0xnsg.js +0 -3
  352. package/dist/cli/main-m1kk6fp5.js +0 -21
  353. package/dist/cli/main-mv40pcr2.js +0 -4
  354. package/dist/cli/main-n0t3973w.js +0 -3
  355. package/dist/cli/main-nqveez48.js +0 -4
  356. package/dist/cli/main-pknhvrmj.js +0 -3
  357. package/dist/cli/main-pn1w7a7j.js +0 -3
  358. package/dist/cli/main-prxxs70n.js +0 -4
  359. package/dist/cli/main-q3vsesf9.js +0 -3
  360. package/dist/cli/main-qsevpgsv.js +0 -3
  361. package/dist/cli/main-rdgdw24b.js +0 -25
  362. package/dist/cli/main-rfth4tbm.js +0 -16
  363. package/dist/cli/main-rg0wn0xf.js +0 -5
  364. package/dist/cli/main-sdmxhtv8.js +0 -4
  365. package/dist/cli/main-skbp13js.js +0 -18
  366. package/dist/cli/main-t4xnd213.js +0 -7
  367. package/dist/cli/main-vqak588n.js +0 -4
  368. package/dist/cli/main-w2n1303f.js +0 -9
  369. package/dist/cli/main-wbrdspr2.js +0 -5
  370. package/dist/cli/main-wsrg79c1.js +0 -7
  371. package/dist/cli/main-x4r0fne4.js +0 -5
  372. package/dist/cli/main-xea2f3tn.js +0 -6
  373. package/dist/cli/main-xg704a3c.js +0 -3
  374. package/dist/cli/main-xvnrabfp.js +0 -16
  375. package/dist/cli/main-xy53xf0r.js +0 -4
  376. package/dist/cli/main-y1fqy60y.js +0 -3
  377. package/dist/cli/main-yn8cd281.js +0 -34
  378. package/dist/cli/main-yr0ksc0h.js +0 -4
  379. package/dist/cli/main-z2ex2vyf.js +0 -4
  380. package/dist/cli/main-z3aayzvq.js +0 -3
  381. package/dist/cli/main-zaqh35jg.js +0 -3
  382. package/dist/cli/main-zc2e8e46.js +0 -4
  383. package/dist/cli/main-zzrfw6cf.js +0 -13
  384. package/dist/cli/main.js +0 -280
  385. package/dist/cli/market-cmd-e14kmx9n.js +0 -5
  386. package/dist/cli/mcp-login-wq7ktdek.js +0 -2
  387. package/dist/cli/mcp-market-cmd-9mg3jecy.js +0 -2
  388. package/dist/cli/notify-b7qc0cjb.js +0 -2
  389. package/dist/cli/oauth-z8whcgfx.js +0 -2
  390. package/dist/cli/output-b3ewj3ps.js +0 -16
  391. package/dist/cli/profiles-6mr5he5e.js +0 -2
  392. package/dist/cli/provider-config-g7j42q8x.js +0 -2
  393. package/dist/cli/provider-jr1y8vvm.js +0 -2
  394. package/dist/cli/registry-s8yk86g0.js +0 -2
  395. package/dist/cli/registry-t6p8d4mn.js +0 -2
  396. package/dist/cli/repl-bajwe1mh.js +0 -11
  397. package/dist/cli/resume-rwn9nz7y.js +0 -2
  398. package/dist/cli/run-flags-nah7ndpt.js +0 -2
  399. package/dist/cli/runtime-n7gafzhb.js +0 -2
  400. package/dist/cli/sandbox-config-emdy18x4.js +0 -2
  401. package/dist/cli/server-b0nvs2bn.js +0 -5
  402. package/dist/cli/session-arg-y75wd4kj.js +0 -2
  403. package/dist/cli/session-j62evmjq.js +0 -2
  404. package/dist/cli/sessions-cmd-tsnwz0ns.js +0 -7
  405. package/dist/cli/settings-df10wfez.js +0 -2
  406. package/dist/cli/setup-jzvv72fg.js +0 -2
  407. package/dist/cli/sextant-smoke-37m81ke6.js +0 -5
  408. package/dist/cli/skills-cmd-gjxnxnhx.js +0 -2
  409. package/dist/cli/smoke-p7748apt.js +0 -8
  410. package/dist/cli/start-chat-s4st3mm0.js +0 -12
  411. package/dist/cli/stream-gmeyewds.js +0 -2
  412. package/dist/cli/task-gh0kkp3n.js +0 -2
  413. package/dist/cli/tasks-z1kfpe8e.js +0 -2
  414. package/dist/cli/thinking-0eqkrz6t.js +0 -2
  415. package/dist/cli/todo-5brcrt9m.js +0 -2
  416. package/dist/cli/tools-7pzm0vj9.js +0 -2
  417. package/dist/cli/tools-s635p6s8.js +0 -2
  418. package/dist/cli/trust-cmd-cjav8zgm.js +0 -2
  419. package/dist/cli/update-check-pt31bm2f.js +0 -2
  420. package/dist/cli/update-cmd-tk131s9t.js +0 -2
  421. package/dist/cli/voice-56nabd8d.js +0 -2
  422. package/dist/cli/webfetch-xd8q596m.js +0 -2
  423. package/dist/cli/websearch-5hkf98k1.js +0 -2
  424. package/dist/cli/workflow-cmd-cy3cvzjp.js +0 -4
  425. package/dist/cli/workspace-q10g5z3e.js +0 -2
  426. package/dist/lib/index.js +0 -62
  427. package/dist/lib/models-index.json +0 -1
  428. package/dist/lib/plugins.js +0 -55
  429. package/dist/lib/providers.js +0 -17
  430. package/dist/lib/public-api.js +0 -20
  431. package/dist/lib/sdk.js +0 -360
  432. /package/{dist/cli → src/providers}/models-index.json +0 -0
@@ -0,0 +1,330 @@
1
+ /** Rovecode core type contracts. Single source of truth for the runtime. */
2
+
3
+ import type { ContextChunk } from "./context.ts";
4
+ import type { CompactionStrategy, CompactionTrigger, PruneConfig } from "./compaction.ts";
5
+ import type { OutputBudgetOptions } from "./tool-output-budget.ts";
6
+
7
+ // ---------- Messages (harness-level; converted to provider form only at the seam) ----------
8
+
9
+ export type Role = "system" | "user" | "assistant" | "tool";
10
+
11
+ export interface TextPart { kind: "text"; text: string }
12
+ export interface ToolCallPart { kind: "tool_call"; id: string; tool: string; args: unknown }
13
+ export interface ToolResultPart { kind: "tool_result"; callId: string; ok: boolean; output: string }
14
+ /** The four raster types both wire protocols accept (Anthropic image source media_type;
15
+ * OpenAI image_url data URL) — decided by magic bytes, never by file extension (core/images.ts). */
16
+ export type ImageMime = "image/png" | "image/jpeg" | "image/gif" | "image/webp";
17
+ /** port #34: an image attached to a user message. Exactly one carrier is set — `bytes` (base64,
18
+ * the in-memory / transport form: TUI /attach, ACP image blocks) or `path` (the sidecar file the
19
+ * session store wrote under `<session>/attachments/`; session-relative in entries.jsonl,
20
+ * resolved to absolute on load). Adapters read either through core/images.ts imageData(). */
21
+ export interface ImagePart {
22
+ kind: "image";
23
+ mime: ImageMime;
24
+ bytes?: string;
25
+ path?: string;
26
+ width?: number;
27
+ height?: number;
28
+ /** display name (the attached file's basename) — transcript chip + non-vision placeholder */
29
+ name?: string;
30
+ }
31
+ export type MessagePart = TextPart | ToolCallPart | ToolResultPart | ImagePart;
32
+
33
+ export interface Message {
34
+ id: string;
35
+ role: Role;
36
+ parts: MessagePart[];
37
+ parentId: string | null;
38
+ createdAt: number;
39
+ /** provider+model that produced this message, when applicable */
40
+ origin?: { provider: string; model: string };
41
+ usage?: TokenUsage;
42
+ }
43
+
44
+ export interface TokenUsage { input: number; output: number; cacheRead?: number; cacheWrite?: number; costUsd?: number }
45
+
46
+ // ---------- Provider seam (ADR-003: never throws; errors are stopReasons) ----------
47
+
48
+ export type StopReason =
49
+ | "end_turn" | "tool_use" | "length" | "aborted" | "error" | "budget";
50
+
51
+ export interface AssistantTurn {
52
+ parts: MessagePart[];
53
+ stopReason: StopReason;
54
+ usage: TokenUsage;
55
+ error?: string;
56
+ }
57
+
58
+ export interface StreamOptions {
59
+ signal?: AbortSignal;
60
+ /** the run's wall-clock deadline (epoch ms, RunConfig.maxSeconds) — a retry backoff that would end past it
61
+ * is not taken (providers/retry.ts); unset = no clock */
62
+ deadlineAt?: number;
63
+ /** tool schemas advertised to the provider for native function calling */
64
+ tools?: ToolSchema[];
65
+ }
66
+
67
+ export interface StreamFn {
68
+ (model: ModelRef, messages: Message[], options?: StreamOptions): AsyncIterable<StreamEvent>;
69
+ }
70
+
71
+ export type StreamEvent =
72
+ | { type: "text_delta"; text: string }
73
+ /** a slice of the model's reasoning (Anthropic thinking_delta): counted for the live status
74
+ * line, never part of the answer — the terminal turn's parts carry text and tool calls only */
75
+ | { type: "reasoning_delta"; text: string }
76
+ | { type: "tool_call_delta"; id: string; tool: string; argsDelta: string }
77
+ | { type: "turn"; turn: AssistantTurn };
78
+
79
+ /** How hard the model is asked to think before it answers. `off` is the plain request; the three
80
+ * levels map to each protocol's own dial — an Anthropic thinking budget in tokens, an OpenAI
81
+ * `reasoning_effort` string (providers/stream.ts thinkingBudget). A model with no reasoning mode
82
+ * ignores it: the field is sent, the endpoint drops it. */
83
+ /** `auto` = send NO thinking field and let the provider's own default stand — for the Claude 5 family
84
+ * that is adaptive thinking at high effort. It is the runtime default: the old default `off` sent an
85
+ * explicit `thinking: disabled`, which switched OFF the reasoning Opus 5 and Sonnet 5 do on their own
86
+ * and was a large part of "the model is not performing" (Berkay, 2026-09-04). `off` stays as the
87
+ * explicit, deliberate choice. */
88
+ export type ThinkingEffort = "auto" | "off" | "low" | "medium" | "high";
89
+ export const THINKING_EFFORTS: readonly ThinkingEffort[] = ["auto", "off", "low", "medium", "high"];
90
+
91
+ /** a level from a flag/env word; undefined when it names nothing (the caller keeps its default,
92
+ * rather than silently reading a typo as "off") */
93
+ export function parseEffort(v: string | undefined): ThinkingEffort | undefined {
94
+ const w = (v ?? "").trim().toLowerCase();
95
+ return (THINKING_EFFORTS as readonly string[]).includes(w) ? (w as ThinkingEffort) : undefined;
96
+ }
97
+
98
+ export interface ModelRef {
99
+ provider: string;
100
+ model: string;
101
+ maxTokens?: number;
102
+ effort?: ThinkingEffort;
103
+ /** the catalog's word on whether the model has a reasoning mode (models.dev `reasoning`), stamped by
104
+ * cli/runtime.ts buildDef; `false` means no thinking field is ever sent (providers/thinking.ts).
105
+ * Unset = unknown: the dial goes out in the endpoint's dialect and a model that cannot reason ignores it. */
106
+ reasoning?: boolean;
107
+ }
108
+
109
+ // ---------- Tools (ADR-005: validate → revise → policy → approve → sandbox → execute) ----------
110
+
111
+ export interface ToolSchema {
112
+ name: string;
113
+ description: string;
114
+ /** JSON Schema for args */
115
+ args: Record<string, unknown>;
116
+ }
117
+
118
+ export type ToolKind = "read" | "write" | "execute" | "spawn" | "memory" | "network" | "custom";
119
+
120
+ export interface ToolContext {
121
+ sessionId: string;
122
+ cwd: string;
123
+ signal: AbortSignal;
124
+ /** port #29: the run this call belongs to (hook ctx, tracing); unset for bare registry use */
125
+ runId?: string;
126
+ /** emit progress updates surfaced as tool_execution_update events */
127
+ onUpdate?: (note: string) => void;
128
+ /** spawn a child agent (multi-agent path) */
129
+ spawn?: (req: SpawnRequest) => Promise<SpawnResult>;
130
+ permissions: PermissionDecision;
131
+ }
132
+
133
+ export interface Tool {
134
+ schema: ToolSchema;
135
+ kind: ToolKind;
136
+ /** false → run concurrently with siblings in the same batch */
137
+ sequential?: boolean;
138
+ interruptible?: boolean;
139
+ /** Policy resource for a tool whose modes differ in what they are ALLOWED to do, where neither a
140
+ * path, a command nor a URL says which mode this call is. Without it the resource falls back to the
141
+ * tool NAME, so one rule has to cover every mode — which is how a read-only `design_direction
142
+ * {"action":"get"}` came to raise an approval card (2026-09-04): it writes nothing, but it shares a
143
+ * rule with `set`, and a human trained to allow the read hits allow on the write too. Return a short
144
+ * stable word; a rule then targets it (`tool.design_direction get -> allow`). Never derive it from a
145
+ * value the model can vary freely — the point is that a rule can name the mode, not that the model
146
+ * can name its own permissions. */
147
+ resource?(args: unknown): string;
148
+ execute(args: unknown, ctx: ToolContext): Promise<ToolOutput>;
149
+ }
150
+
151
+ export interface ToolOutput { ok: boolean; output: string; data?: unknown }
152
+
153
+ // ---------- Permissions ----------
154
+
155
+ export type PermissionEffect = "allow" | "deny" | "prompt";
156
+
157
+ export interface PermissionRule {
158
+ action: string; // e.g. "file.write", "shell.exec", "spawn", "*"
159
+ resource: string; // glob, e.g. "src/**", "rm *", "*"
160
+ effect: PermissionEffect;
161
+ }
162
+
163
+ export type PermissionDecision =
164
+ | { effect: "allow" }
165
+ | { effect: "deny"; reason: string }
166
+ | { effect: "prompt"; prompt: string };
167
+
168
+ export type ApprovalFn = (req: ApprovalRequest) => Promise<"once" | "always" | "deny">;
169
+
170
+ /** How much the human is asked. `ask` prompts for every write, command and subagent; `accept-edits`
171
+ * stops asking for writes INSIDE the workspace (shell, spawn, network and writes outside it still
172
+ * ask); `auto` never asks. Deny rules, plan mode and the execpolicy forbidden-argv stop hold at
173
+ * every level — this dial only moves the prompt branch. */
174
+ export type PermissionLevel = "ask" | "accept-edits" | "auto";
175
+
176
+ export interface ApprovalRequest {
177
+ tool: string;
178
+ args: unknown;
179
+ revisedArgs: unknown;
180
+ reason: string;
181
+ }
182
+
183
+ // ---------- Events (loop output; also the durability + observability unit) ----------
184
+
185
+ export type RunEvent =
186
+ | { type: "run_start"; runId: string; sessionId: string; goal: string }
187
+ | { type: "turn_start"; turn: number }
188
+ | { type: "message_update"; messageId: string; delta: string }
189
+ /** the provider turn is reasoning: `tokens` = estimated reasoning tokens so far this turn,
190
+ * CUMULATIVE (a dropped event costs nothing). Only the count leaves the loop — the reasoning text
191
+ * is not the answer and neither the transcript nor a client should carry it. */
192
+ | { type: "reasoning_update"; messageId: string; tokens: number }
193
+ | { type: "tool_execution_start"; callId: string; tool: string; args: unknown }
194
+ | { type: "tool_execution_update"; callId: string; note: string }
195
+ | { type: "tool_execution_end"; callId: string; ok: boolean; output: string; durationMs: number }
196
+ | { type: "tool_call_failed"; callId: string; reason: "truncated" | "invalid_args" | "permission_denied" | "not_found"; detail: string }
197
+ /** strategy = the one that RAN (core/compaction.ts seam, or "context-drop" for ADR-007 chunk
198
+ * eviction); trigger (port #25) is set on history compactions only: "speculative" = estimate
199
+ * crossed the threshold, "emergency" = the provider rejected the request as an overflow */
200
+ | { type: "compaction"; strategy: string; trigger?: CompactionTrigger; tokensBefore: number; tokensAfter: number }
201
+ | { type: "turn_end"; turn: number; stopReason: StopReason }
202
+ | { type: "steer"; text: string }
203
+ /** the verify gate is running the project's check / has finished it (core/verify-gate.ts); `detail` is one line */
204
+ | { type: "verify"; command: string; state: "running" | "passed" | "failed" | "timeout"; ms?: number; detail?: string }
205
+ /** `outstanding` (status "done" only): what the run left behind when the model stopped talking — absent
206
+ * when nothing is notable AND at least one file was written, so a clean run's event is exactly what it
207
+ * always was. "done" alone means "the model produced a turn with no tool call"; this field is how a
208
+ * surface tells that from "the work is complete" (core/loop.ts assessOutstanding). */
209
+ | { type: "run_end"; status: "done" | "stopped" | "error" | "budget"; summary: string; outstanding?: RunOutstanding };
210
+
211
+ /** What a run that ended as "done" left behind. Every field is a fact read from the transcript or the
212
+ * session's own todo list — never an interpretation of the model's words. */
213
+ export interface RunOutstanding {
214
+ /** tool calls of the LAST turn that had any, which failed: `write: Write rejected: …` (first line) */
215
+ failed: string[];
216
+ /** that last turn asked the user something and got no answer (headless, declined, or aborted) */
217
+ unansweredAsk: boolean;
218
+ /** successful `edit` + `write` calls over the whole run. `bash` may have changed files too; this counts only the two file tools */
219
+ writes: number;
220
+ /** the model's own todo list, when it kept one: items not completed / all items */
221
+ todosOpen?: number;
222
+ todosTotal?: number;
223
+ /** the finish check (core/loop.ts) asked once for the work to be finished; this run_end is the answer it got */
224
+ nudged: boolean;
225
+ /** the verify gate (core/verify-gate.ts), present when the run wrote files and a gate was wired: did the
226
+ * project's own check pass after the changes, fail (with the failing part), time out, or was there no check to
227
+ * run. Absent when nothing was written — and when files changed only through `bash`, which `writes` cannot see. */
228
+ verify?: VerifyState;
229
+ }
230
+
231
+ /** `refused`: what the resolver (core/verify.ts) saw and deliberately did not run, each with its reason — the
232
+ * argument for trusting the gate. `reason` (unconfigured): why there is nothing to run, in the resolver's words. */
233
+ export type VerifyState =
234
+ | { state: "unconfigured"; reason?: string; refused?: string[] }
235
+ | { state: "passed"; command: string; ms: number; refused?: string[] }
236
+ | { state: "failed"; command: string; code: number; failure: string; refused?: string[] }
237
+ | { state: "timeout"; command: string; seconds: number; refused?: string[] };
238
+
239
+ /** RunConfig.verify — wired by the runtime, consumed by the loop's "done" exit. `resolution` is what
240
+ * core/verify.ts decided (null / no commands = nothing to run → run_end says "not verified"); `run` executes it
241
+ * bounded by `timeoutMs` and the run's abort (core/verify-gate.ts runVerify). */
242
+ export interface VerifyGate {
243
+ resolution: { commands: string[]; refused?: string[]; source?: string; reason?: string } | null;
244
+ timeoutMs: number;
245
+ run: (signal: AbortSignal) => Promise<{ command: string; ok: boolean; code: number; timedOut: boolean; ms: number; failure: string; ran: number }>;
246
+ }
247
+
248
+ // ---------- Agent ----------
249
+
250
+ export interface AgentDefinition {
251
+ name: string;
252
+ systemPrompt: string | ((ctx: AgentVars) => string);
253
+ tools: string[]; // tool names; "*" = all allowed by policy
254
+ model?: ModelRef;
255
+ maxTurns?: number; // finite always (reject swarm's infinity)
256
+ spawns?: "none" | "siblings" | "subtasks";
257
+ memory?: { task?: boolean; episodic?: boolean; semantic?: boolean };
258
+ /** extra non-history ADR-007 chunks (port #8: harvested project config,
259
+ * name "config", priority 70) folded into the system message via
260
+ * assembleContext — droppable under budget pressure, unlike systemPrompt */
261
+ contextChunks?: ContextChunk[];
262
+ }
263
+
264
+ export interface AgentVars { [key: string]: unknown }
265
+
266
+ export interface SpawnRequest {
267
+ agent: string;
268
+ goal: string;
269
+ vars?: AgentVars;
270
+ isolated?: boolean; // COW/git worktree when writing
271
+ background?: boolean;
272
+ }
273
+
274
+ export interface SpawnResult { agent: string; ok: boolean; summary: string; usage: TokenUsage; patch?: string }
275
+
276
+ // ---------- Run configuration ----------
277
+
278
+ export interface RunConfig {
279
+ maxTurns: number;
280
+ /** wall-clock ceiling for one run, in seconds; checked at every turn boundary (core/loop.ts), so a
281
+ * verification spiral of many short turns ends in a clean run_end "budget" with what was done so far.
282
+ * Unset = no clock. `rovecode run` defaults it to 20 minutes; ROVECODE_MAX_SECONDS / --max-seconds set it. */
283
+ maxSeconds?: number;
284
+ /** a spend ceiling for one run, in US dollars, checked at every turn boundary like maxSeconds: the run ends
285
+ * with status "budget" and what was done so far. Only turns `priceUsd` can price count; an unpriced turn
286
+ * (a model the catalog does not know) adds nothing and the summary says how many there were. Unset = no cap.
287
+ * `rovecode run --max-cost D`, ROVECODE_MAX_COST on every surface. */
288
+ maxCostUsd?: number;
289
+ /** what one turn cost, from its usage and the model that SERVED it (router fallback may differ from the one
290
+ * asked for) — undefined when the catalog has no price. The runtime binds this to its catalog; without it
291
+ * maxCostUsd can never trip, which is why buildCfg always sets both together. */
292
+ priceUsd?: (usage: TokenUsage, origin: ModelRef) => number | undefined;
293
+ /** The finish check (core/loop.ts, at the "done" exit): when the model stops talking right after a failed
294
+ * tool call or an unanswered question to the user, ONE continuation turn names what is outstanding and asks
295
+ * it to finish or say what is left. Default on; `false` (ROVECODE_FINISH_CHECK=0) turns it off. The
296
+ * representation on run_end (`outstanding`) is unconditional — turning this off only stops the nudge. */
297
+ finishCheck?: boolean;
298
+ /** the model's own todo list for this session, read at the exit: open / total, or null when it kept none.
299
+ * Represented on run_end; it is NOT a nudge trigger (no session on this machine has ever written one). */
300
+ todoState?: () => { open: number; total: number } | null;
301
+ /** The verify gate (core/verify-gate.ts): after a run that wrote files, run the project's own check before
302
+ * "done"; a failure goes back to the model ONCE (sharing the finish check's one-nudge budget), then run_end
303
+ * says how it ended. Absent = off (ROVECODE_VERIFY=0, plan mode, or a surface that wired none): nothing runs,
304
+ * nothing is added, a run's event is byte-identical to one without the gate. */
305
+ verify?: VerifyGate;
306
+ contextBudgetTokens: number;
307
+ compactionThreshold: number; // fraction of budget triggering compaction
308
+ /** port #25: history compaction strategy (core/compaction.ts; env ROVECODE_COMPACTION); default head-summarize */
309
+ compactionStrategy?: CompactionStrategy;
310
+ /** port #25 keep-window: user turns kept BEFORE the current one (default 2; an emergency keeps 0) */
311
+ compactionKeepTurns?: number;
312
+ /** P0-2: view-only prune of old tool outputs before each provider call (core/compaction.ts
313
+ * pruneToolOutputs). The session record is NEVER rewritten — only the wire view is stubbed;
314
+ * a `compaction` event with strategy "prune" is yielded (not persisted, same precedent as
315
+ * "context-drop"). undefined = DEFAULT_PRUNE_CONFIG; false = off. */
316
+ prune?: PruneConfig | false;
317
+ /** P0-3: unified tool-output ceiling with UTF-8-safe head+tail truncation
318
+ * (core/tool-output-budget.ts), applied by the loop to the persisted/next-request results.
319
+ * undefined = the default ceiling; false = off (tool-side caps still apply). */
320
+ outputBudget?: OutputBudgetOptions | false;
321
+ /** P0-4: compaction thrash guard (core/compaction.ts CompactionPace). A compaction within this
322
+ * many turns of the previous one earns one strike; one that fails to shrink the wire by ≥5%
323
+ * earns another; COOLDOWN_STRIKES (3) stop compacting for the run, and an emergency arriving
324
+ * during cooldown ends the run in error instead of re-driving. 0 = off.
325
+ * Default DEFAULT_RAPID_WINDOW_TURNS (2). */
326
+ compactionRapidTurns?: number;
327
+ parallelTools: boolean;
328
+ permissionRules: PermissionRule[];
329
+ approval?: ApprovalFn;
330
+ }
@@ -0,0 +1,171 @@
1
+ /** Is there a newer rovecode than the one running?
2
+ *
3
+ * The release channel is GitHub Releases on 9Code-Labs/rovecode (Berkay's call, 2026-09-06). That
4
+ * repository is private, so the check needs a token — and the honest consequence is written into the
5
+ * result rather than hidden: with no token the answer is "unknown, and here is why", never "you are up
6
+ * to date". A version check that reports "current" when it could not look is worse than no check, since
7
+ * it is indistinguishable from a real answer.
8
+ *
9
+ * Three rules, because this runs at startup:
10
+ * - **It never blocks.** The caller fires it and paints; the answer arrives or it does not.
11
+ * - **It never throws.** Offline, rate-limited, no token, a repository that has no releases yet — each
12
+ * is a reason string, and the surface can decide whether to say anything.
13
+ * - **It asks rarely.** The answer is cached in ~/.rovecode/update-check.json for six hours, so opening
14
+ * the terminal twenty times in an afternoon is one request. A cache that cannot be read or written is
15
+ * not an error either; it just means asking again. */
16
+
17
+ import { readFileSync, writeFileSync, mkdirSync } from "node:fs";
18
+ import { execFile } from "node:child_process";
19
+ import { join } from "node:path";
20
+ import { rovecodeHome } from "../providers/auth.ts";
21
+
22
+ export interface UpdateStatus {
23
+ /** the version this process is */
24
+ current: string;
25
+ /** the newest release, when one could be read */
26
+ latest?: string;
27
+ /** true only when `latest` is genuinely newer than `current` */
28
+ newer: boolean;
29
+ /** why there is no `latest` — absent when the check succeeded */
30
+ reason?: string;
31
+ /** where the answer came from, so a stale line can be explained */
32
+ from: "network" | "cache";
33
+ /** the release page, for a surface that wants to point at it */
34
+ url?: string;
35
+ }
36
+
37
+ export interface UpdateCheckOptions {
38
+ repo?: string;
39
+ token?: string | undefined;
40
+ fetchFn?: typeof fetch;
41
+ /** overridden in tests; production caches under rovecodeHome() */
42
+ cacheFile?: string;
43
+ ttlMs?: number;
44
+ timeoutMs?: number;
45
+ now?: () => number;
46
+ /** answer from the cache or not at all — never open a socket. `rovecode --version` uses this: a courtesy
47
+ * line must not make a command scripts call wait on a network round-trip (measured 3.2 s on a cold
48
+ * cache before this existed, against 84–103 ms for everything else the command does). */
49
+ cacheOnly?: boolean;
50
+ /** last-resort token source; the default asks the gh CLI. Injected in tests so no process is spawned. */
51
+ ghToken?: () => Promise<string | undefined>;
52
+ }
53
+
54
+ const REPO = "9Code-Labs/rovecode";
55
+ const TTL_MS = 6 * 60 * 60 * 1000;
56
+ // 8s, not the 3s this started with. Nothing waits on this — the card is already painted and the notice
57
+ // arrives when it arrives — so the only thing a short timeout buys is the wrong answer on exactly the run
58
+ // that matters: measured cold on this machine the first api.github.com request took 12.7s and the next
59
+ // 0.36s, which a 3s cap turns into "the check timed out" every single first start of the day.
60
+ const TIMEOUT_MS = 8_000;
61
+
62
+ /** semver-ish compare, tolerant of a leading v and of extra dot-parts; prerelease suffixes lose to the
63
+ * same version without one, which is the conservative direction — it never invents an update. */
64
+ export function isNewer(latest: string, current: string): boolean {
65
+ const parts = (v: string): { nums: number[]; pre: boolean } => {
66
+ const clean = v.trim().replace(/^v/i, "");
67
+ const [core = "", ...rest] = clean.split("-");
68
+ return { nums: core.split(".").map((n) => Number.parseInt(n, 10) || 0), pre: rest.length > 0 };
69
+ };
70
+ const a = parts(latest), b = parts(current);
71
+ const len = Math.max(a.nums.length, b.nums.length);
72
+ for (let i = 0; i < len; i++) {
73
+ const x = a.nums[i] ?? 0, y = b.nums[i] ?? 0;
74
+ if (x !== y) return x > y;
75
+ }
76
+ // same numbers: a prerelease is not newer than the release, and never newer than itself
77
+ return b.pre && !a.pre;
78
+ }
79
+
80
+ function readCache(file: string, ttlMs: number, now: number): UpdateStatus | null {
81
+ try {
82
+ const raw = JSON.parse(readFileSync(file, "utf8")) as { at?: number; status?: UpdateStatus };
83
+ if (typeof raw.at !== "number" || !raw.status) return null;
84
+ if (now - raw.at > ttlMs) return null;
85
+ return { ...raw.status, from: "cache" };
86
+ } catch {
87
+ return null; // unreadable, missing, or written by an older shape — ask again
88
+ }
89
+ }
90
+
91
+ function writeCache(file: string, status: UpdateStatus, now: number): void {
92
+ try {
93
+ mkdirSync(join(file, ".."), { recursive: true });
94
+ writeFileSync(file, JSON.stringify({ at: now, status: { ...status, from: "network" } }));
95
+ } catch {
96
+ /* a read-only home must not turn a successful check into a failure */
97
+ }
98
+ }
99
+
100
+ /** `gh auth token`, or undefined for every way that can fail — no gh, not logged in, slow, noisy. This is
101
+ * a convenience, so it is never allowed to become a reason the terminal waits. */
102
+ function ghAuthToken(): Promise<string | undefined> {
103
+ return new Promise((resolve) => {
104
+ try {
105
+ execFile("gh", ["auth", "token"], { timeout: 1_500, windowsHide: true }, (err, stdout) => {
106
+ const t = typeof stdout === "string" ? stdout.trim() : "";
107
+ resolve(err !== null || t.length === 0 ? undefined : t);
108
+ });
109
+ } catch { resolve(undefined); }
110
+ });
111
+ }
112
+
113
+ export async function checkForUpdate(current: string, opts: UpdateCheckOptions = {}): Promise<UpdateStatus> {
114
+ const now = (opts.now ?? Date.now)();
115
+ const cacheFile = opts.cacheFile ?? join(rovecodeHome(), "update-check.json");
116
+ const ttl = opts.ttlMs ?? TTL_MS;
117
+
118
+ const cached = readCache(cacheFile, ttl, now);
119
+ if (cached) return { ...cached, current, newer: cached.latest !== undefined && isNewer(cached.latest, current) };
120
+
121
+ // GITHUB_TOKEN, then GH_TOKEN, then whatever `gh auth login` already stored — most people who can read
122
+ // a private repository at all have the CLI logged in, and making them export a variable to be told about
123
+ // an update is a step they will not take. The token is used and dropped: it never enters the cache.
124
+ if (opts.cacheOnly === true) {
125
+ return { current, newer: false, from: "cache", reason: "not asked yet — rovecode checks at startup, at most once every six hours" };
126
+ }
127
+ const token = opts.token ?? process.env.GITHUB_TOKEN ?? process.env.GH_TOKEN ?? await (opts.ghToken ?? ghAuthToken)();
128
+ if (!token) {
129
+ // not cached: a token may appear before the next start, and caching "no token" would hide it
130
+ return { current, newer: false, from: "network", reason: "the release repository is private and no GITHUB_TOKEN is set (or `gh auth login`)" };
131
+ }
132
+
133
+ const ac = new AbortController();
134
+ const timer = setTimeout(() => ac.abort(), opts.timeoutMs ?? TIMEOUT_MS);
135
+ try {
136
+ const res = await (opts.fetchFn ?? fetch)(`https://api.github.com/repos/${opts.repo ?? REPO}/releases/latest`, {
137
+ headers: { accept: "application/vnd.github+json", authorization: `Bearer ${token}`, "user-agent": "rovecode" },
138
+ signal: ac.signal,
139
+ });
140
+ if (res.status === 404) {
141
+ const status: UpdateStatus = { current, newer: false, from: "network", reason: "no release published yet" };
142
+ writeCache(cacheFile, status, now); // worth caching: it will stay true until someone publishes
143
+ return status;
144
+ }
145
+ if (!res.ok) return { current, newer: false, from: "network", reason: `GitHub answered ${res.status}` };
146
+ const body = (await res.json().catch(() => null)) as { tag_name?: string; html_url?: string } | null;
147
+ const tag = typeof body?.tag_name === "string" ? body.tag_name : undefined;
148
+ if (!tag) return { current, newer: false, from: "network", reason: "the release carries no tag name" };
149
+ const status: UpdateStatus = {
150
+ current, latest: tag.replace(/^v/i, ""), newer: isNewer(tag, current), from: "network",
151
+ ...(typeof body?.html_url === "string" ? { url: body.html_url } : {}),
152
+ };
153
+ writeCache(cacheFile, status, now);
154
+ return status;
155
+ } catch (e) {
156
+ const msg = e instanceof Error ? e.message : String(e);
157
+ return { current, newer: false, from: "network", reason: ac.signal.aborted ? "the check timed out" : msg };
158
+ } finally {
159
+ clearTimeout(timer);
160
+ }
161
+ }
162
+
163
+ /** The one line a surface shows, or null when there is nothing worth saying. Deliberately silent for
164
+ * "up to date" and for every failure: a startup screen that reports its own plumbing every time trains
165
+ * people to stop reading it. `verbose` is for `rovecode --version`, where asking WAS the point. */
166
+ export function updateLine(s: UpdateStatus, verbose = false): string | null {
167
+ if (s.newer && s.latest !== undefined) return `update available: ${s.current} → ${s.latest}${s.url ? ` · ${s.url}` : ""}`;
168
+ if (!verbose) return null;
169
+ if (s.reason !== undefined) return `update check: ${s.reason}`;
170
+ return `up to date (${s.current})${s.from === "cache" ? " · cached" : ""}`;
171
+ }
@@ -0,0 +1,158 @@
1
+ /** Self-update: how THIS installation gets to the newer release the update-check named.
2
+ *
3
+ * Rovecode ships three ways and each updates differently, so the first job is honest detection
4
+ * (core/update.ts detectInstallMode): an npm install (the published tarball — `npm install -g
5
+ * rovecode@<channel>`), a source checkout (git pull + bun install, and build:cli when a dist was
6
+ * built), or a compiled single binary (no self-swap yet: the release page's artifact is the answer,
7
+ * said plainly rather than attempted and half-done). Detection is path arithmetic, injected and
8
+ * testable; nothing here guesses from the version string alone.
9
+ *
10
+ * The channel follows the running version unless told otherwise: a prerelease (0.4.0-beta.1) stays
11
+ * on `beta`, a release stays on `latest` — an auto-update must never silently move someone between
12
+ * channels.
13
+ *
14
+ * `autoUpdate` (settings.json / ROVECODE_AUTO_UPDATE=1) runs the plan in the BACKGROUND at TUI
15
+ * boot when the cached update-check says a newer version exists. It never blocks the session and
16
+ * never swaps the running process: on Windows a live executable's files are being replaced under
17
+ * it, so the honest promise is "updated — restart to run it", which is what the note says. */
18
+
19
+ import { existsSync } from "node:fs";
20
+ import { join, sep } from "node:path";
21
+
22
+ export type InstallMode = "npm" | "source" | "binary" | "unknown";
23
+ export type UpdateChannel = "beta" | "latest";
24
+
25
+ export interface DetectedInstall {
26
+ mode: InstallMode;
27
+ /** the package root (npm: the rovecode dir under node_modules; source: the repo root) when known */
28
+ root?: string;
29
+ /** npm: the install sits under npm's global prefix (decides -g) */
30
+ npmGlobal?: boolean;
31
+ }
32
+
33
+ /** bun's compiled binaries run their modules from a virtual FS whose path starts with this */
34
+ const BUNFS = "/$bunfs/";
35
+
36
+ /** Where does the running entry live? `entry` is the main module's path (import.meta.path of the
37
+ * CLI entry), `exec` the runtime's own (process.execPath), `npmGlobalPrefix` the answer of
38
+ * `npm prefix -g` when the caller already has it (undefined = decide later, at run time). */
39
+ export function detectInstallMode(paths: { entry: string; exec?: string; npmGlobalPrefix?: string }): DetectedInstall {
40
+ const entry = paths.entry.replace(/\\/g, "/");
41
+ if (entry.includes(BUNFS) || (paths.exec !== undefined && paths.exec.replace(/\\/g, "/").includes(BUNFS))) {
42
+ return { mode: "binary" };
43
+ }
44
+ const nm = entry.lastIndexOf("/node_modules/");
45
+ if (nm >= 0) {
46
+ // the package root is node_modules/<name> (a scoped name adds one segment)
47
+ const after = entry.slice(nm + "/node_modules/".length);
48
+ const segs = after.split("/");
49
+ const pkgSegs = after.startsWith("@") ? segs.slice(0, 2) : segs.slice(0, 1);
50
+ const root = entry.slice(0, nm) + "/node_modules/" + pkgSegs.join("/");
51
+ const prefix = paths.npmGlobalPrefix?.replace(/\\/g, "/").replace(/\/$/, "");
52
+ const npmGlobal = prefix !== undefined
53
+ ? root.toLowerCase().startsWith((prefix + "/node_modules/").toLowerCase())
54
+ : undefined;
55
+ return { mode: "npm", root, ...(npmGlobal !== undefined ? { npmGlobal } : {}) };
56
+ }
57
+ // a source checkout: the entry is src/cli/main.ts (or bin/…) inside a git repo
58
+ for (const cand of sourceRootCandidates(paths.entry)) {
59
+ if (existsSync(join(cand, ".git"))) return { mode: "source", root: cand };
60
+ }
61
+ return { mode: "unknown" };
62
+ }
63
+
64
+ /** walk up from the entry file to the plausible repo roots (bounded: an entry deep in a monorepo) */
65
+ function sourceRootCandidates(entry: string): string[] {
66
+ const out: string[] = [];
67
+ let dir = entry.includes(sep) || entry.includes("/") ? entry.replace(/\\/g, "/").split("/").slice(0, -1).join("/") : ".";
68
+ for (let i = 0; i < 6 && dir.length > 0; i++) {
69
+ out.push(dir.replace(/\//g, sep));
70
+ const up = dir.split("/").slice(0, -1).join("/");
71
+ if (up === dir) break;
72
+ dir = up;
73
+ }
74
+ return out;
75
+ }
76
+
77
+ export interface UpdatePlan {
78
+ mode: InstallMode;
79
+ channel: UpdateChannel;
80
+ /** the commands to run, in order; empty for binary/unknown (manual carries the words) */
81
+ commands: string[][];
82
+ cwd?: string;
83
+ /** what a human does when there is no command to run */
84
+ manual?: string;
85
+ }
86
+
87
+ /** The channel: explicit wins; otherwise a prerelease stays on beta, a release stays on latest. */
88
+ export function channelFor(currentVersion: string, explicit?: UpdateChannel | "auto"): UpdateChannel {
89
+ if (explicit === "beta" || explicit === "latest") return explicit;
90
+ return currentVersion.includes("-") ? "beta" : "latest";
91
+ }
92
+
93
+ export function planUpdate(install: DetectedInstall, opts: { currentVersion: string; channel?: UpdateChannel | "auto"; distBuilt?: boolean }): UpdatePlan {
94
+ const channel = channelFor(opts.currentVersion, opts.channel);
95
+ switch (install.mode) {
96
+ case "npm": {
97
+ const spec = `rovecode@${channel}`;
98
+ // -g when the install is global; a local (project) install updates in its project root.
99
+ // npmGlobal undefined = the caller did not resolve `npm prefix -g` yet: runUpdate decides.
100
+ if (install.npmGlobal === false && install.root) {
101
+ const root = install.root.replace(/\\/g, "/");
102
+ const i = root.lastIndexOf("/node_modules/");
103
+ const project = i > 0 ? root.slice(0, i).replace(/\//g, sep) : undefined;
104
+ return { mode: "npm", channel, commands: [["npm", "install", spec]], ...(project ? { cwd: project } : {}) };
105
+ }
106
+ return { mode: "npm", channel, commands: [["npm", "install", "-g", spec]] };
107
+ }
108
+ case "source": {
109
+ const cmds: string[][] = [["git", "pull", "--ff-only"], ["bun", "install"]];
110
+ if (opts.distBuilt === true) cmds.push(["bun", "run", "build:cli"]);
111
+ return { mode: "source", channel, commands: cmds, ...(install.root ? { cwd: install.root } : {}) };
112
+ }
113
+ case "binary":
114
+ return { mode: "binary", channel, commands: [], manual: "a compiled binary does not replace itself yet — download the new artifact from the releases page (https://github.com/9Code-Labs/rovecode-community/releases) and swap the file" };
115
+ default:
116
+ return { mode: "unknown", channel, commands: [], manual: "cannot tell how this copy was installed — update it the way you installed it (npm: `npm install -g rovecode@" + channel + "`; source: `git pull && bun install`)" };
117
+ }
118
+ }
119
+
120
+ export interface RunUpdateDeps {
121
+ /** run one command, stream-free: returns the exit code and the merged tail of its output */
122
+ spawn(cmd: string[], cwd?: string): Promise<{ code: number; out: string }>;
123
+ /** npm only, and only when the plan did not pre-decide: resolve `npm prefix -g` */
124
+ npmGlobalPrefix?(): Promise<string | undefined>;
125
+ log?(line: string): void;
126
+ }
127
+
128
+ export interface UpdateResult { ok: boolean; detail: string; ran: string[] }
129
+
130
+ /** Run the plan's commands in order; the first failure stops and reports. Never throws. */
131
+ export async function runUpdate(plan: UpdatePlan, install: DetectedInstall, deps: RunUpdateDeps): Promise<UpdateResult> {
132
+ const ran: string[] = [];
133
+ if (plan.commands.length === 0) return { ok: false, detail: plan.manual ?? "nothing to run", ran };
134
+ let commands = plan.commands;
135
+ // an npm plan whose -g question was left open: answer it now, once, from `npm prefix -g`
136
+ if (plan.mode === "npm" && install.npmGlobal === undefined && install.root && deps.npmGlobalPrefix) {
137
+ const prefix = (await deps.npmGlobalPrefix())?.replace(/\\/g, "/").replace(/\/$/, "");
138
+ if (prefix) {
139
+ const global = install.root.replace(/\\/g, "/").toLowerCase().startsWith((prefix + "/node_modules/").toLowerCase());
140
+ const spec = plan.commands[0]![plan.commands[0]!.length - 1]!;
141
+ commands = global ? [["npm", "install", "-g", spec]] : [["npm", "install", spec]];
142
+ }
143
+ }
144
+ for (const cmd of commands) {
145
+ deps.log?.(`$ ${cmd.join(" ")}`);
146
+ let r: { code: number; out: string };
147
+ try { r = await deps.spawn(cmd, plan.cwd); }
148
+ catch (e) { return { ok: false, detail: `${cmd[0]} failed to start: ${e instanceof Error ? e.message : String(e)}`, ran }; }
149
+ ran.push(cmd.join(" "));
150
+ if (r.code !== 0) return { ok: false, detail: `${cmd.join(" ")} exited ${r.code}: ${tail(r.out)}`, ran };
151
+ }
152
+ return { ok: true, detail: "updated — restart rovecode to run the new version", ran };
153
+ }
154
+
155
+ function tail(s: string, max = 400): string {
156
+ const t = s.trim();
157
+ return t.length > max ? "…" + t.slice(-max) : t;
158
+ }