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,372 @@
1
+ /**
2
+ * Plan/Act agent modes with per-mode model config — ported from cline
3
+ * (snapshot: research/source_snapshots/cline-cline @ 8eb5f3d).
4
+ * Citations are snapshot-relative path:line.
5
+ *
6
+ * Ported behavior:
7
+ * - Two modes, "plan" | "act", default "act"
8
+ * (apps/vscode/src/shared/storage/state-keys.ts:281 mode: { default: "act" }).
9
+ * - Plan mode is the read-only exploration mode: editor/patch tools are
10
+ * disabled (sdk/packages/core/src/extensions/tools/presets.ts:45-57), and
11
+ * the model cannot switch modes itself — the user flips the toggle
12
+ * (apps/vscode/src/sdk/sdk-session-config-builder.ts:12-18,
13
+ * sdk/packages/shared/src/prompt/cline.ts:52-59).
14
+ * - Per-mode provider+model slots (state-keys.ts:150,196,245-252
15
+ * planModeApiModelId / actModeApiModelId / planModeApiProvider /
16
+ * actModeApiProvider): each mode reads ITS OWN slot at run-build time
17
+ * (apps/vscode/src/sdk/cline-session-factory.ts:552-558 resolveModelId;
18
+ * :799-800 provider per mode), while `planActSeparateModels` (default
19
+ * false — state-keys.ts:272) gates WRITE-time sync only: with the flag
20
+ * off, setting a model in one mode mirrors it to the other
21
+ * (apps/vscode/src/core/controller/models/updateApiConfiguration.ts:104-131).
22
+ * - Toggling to the mode you are already in is a no-op
23
+ * (apps/vscode/src/sdk/sdk-mode-coordinator.ts:131-135).
24
+ * - A user-initiated switch stamps a <mode_notice> onto the next outbound
25
+ * message, and a round trip (plan→act→plan before sending) cancels out
26
+ * (sdk/packages/shared/src/prompt/format.ts:41-80, tracker semantics
27
+ * :61-80; per-session scoping of pending notices:
28
+ * apps/vscode/src/sdk/sdk-mode-coordinator.ts:79-81,101-112).
29
+ * - Plan-mode behavioral contract for the system prompt adapted from
30
+ * sdk/packages/shared/src/prompt/cline.ts:34-45 (base) + :52-59 (the
31
+ * no-self-switch tail used by hosts without a switch_to_act_mode tool).
32
+ *
33
+ * Deliberate deviations (rovecode-specific, per ADR-005 deny-default policy):
34
+ * - Enforcement rides the EXISTING permission pipeline: plan mode is a rule
35
+ * set appended to RunConfig.permissionRules and evaluated by the one
36
+ * evaluatePermissions ladder (src/core/tools.ts:17-27, last match wins).
37
+ * No second enforcement path.
38
+ * - Upstream plan mode keeps shell access with a file-editing command
39
+ * blacklist (presets.ts:48, sdk/packages/core/src/extensions/tools/
40
+ * command-guard.ts:1-74, runtime-builder.ts:477-489). rovecode plan mode
41
+ * denies shell.exec outright — the task bar mandates a read/grep-class
42
+ * toolset, and a blacklist is a weaker guarantee than a deny rule.
43
+ * - Upstream plan mode allows spawning sub-agents (presets.ts:55); rovecode
44
+ * denies spawn in plan mode because children could write.
45
+ * - memory.write is denied in plan mode EXCEPT `todo_write` (port #32): the
46
+ * todo list is the plan's own artifact (agent-private session metadata,
47
+ * never workspace state), so planning may record it; memory_edit stays denied.
48
+ * - The mode switch is preserved durably as a session entry (a system-role
49
+ * Message carrying the upstream notice text) instead of a prefix on the
50
+ * next user message — rovecode sessions are an append-only tree, so the entry
51
+ * lands exactly where the switch happened. Round-trip cancellation is
52
+ * kept: a cancelled switch never becomes an entry.
53
+ *
54
+ * Scope: modes are a TUI feature — only src/tui consumes this module;
55
+ * `rovecode run`/acp/serve ignore .rovecode/modes.json (incl. defaultMode) and own
56
+ * their RunConfig outright (R2 #20 LOW-4 decision: documented, not wired).
57
+ */
58
+
59
+ import { randomUUID } from "node:crypto";
60
+ import { readFileSync } from "node:fs";
61
+ import { join } from "node:path";
62
+ import type { Message, PermissionRule } from "./types.ts";
63
+
64
+ // ---------- Mode ----------
65
+
66
+ export type AgentMode = "plan" | "act";
67
+
68
+ /** Upstream default mode (state-keys.ts:281). */
69
+ export const DEFAULT_MODE: AgentMode = "act";
70
+
71
+ function isMode(v: unknown): v is AgentMode {
72
+ return v === "plan" || v === "act";
73
+ }
74
+
75
+ // ---------- Per-mode model config (.rovecode/modes.json) ----------
76
+
77
+ /** One mode's provider/model selection (upstream planMode… / actMode… fields). */
78
+ export interface ModeModelSelection {
79
+ provider?: string;
80
+ model?: string;
81
+ }
82
+
83
+ export interface ModesConfig {
84
+ /** Starting mode; default "act" (state-keys.ts:281). Read by the TUI only —
85
+ * headless entrypoints (run/acp/serve) never load modes.json (LOW-4). */
86
+ defaultMode?: AgentMode;
87
+ /** Write-time sync gate; default false (planActSeparateModelsSetting,
88
+ * state-keys.ts:272): false = setting a model in one mode mirrors it to
89
+ * the other (updateApiConfiguration.ts:119-131). */
90
+ planActSeparateModels?: boolean;
91
+ plan?: ModeModelSelection;
92
+ act?: ModeModelSelection;
93
+ }
94
+
95
+ function asSelection(v: unknown): ModeModelSelection | undefined {
96
+ if (!v || typeof v !== "object" || Array.isArray(v)) return undefined;
97
+ const o = v as Record<string, unknown>;
98
+ const provider = typeof o.provider === "string" && o.provider.trim() !== "" ? o.provider.trim() : undefined;
99
+ const model = typeof o.model === "string" && o.model.trim() !== "" ? o.model.trim() : undefined;
100
+ if (provider === undefined && model === undefined) return undefined;
101
+ return { provider, model };
102
+ }
103
+
104
+ /** Load `<cwd>/.rovecode/modes.json`. Missing, unreadable, or malformed files and
105
+ * junk fields all degrade to defaults — config can never crash startup
106
+ * (house pattern: src/core/config.ts tryReadFile / src/mcp config). */
107
+ export function loadModesConfig(cwd: string): ModesConfig {
108
+ let raw: unknown;
109
+ try {
110
+ raw = JSON.parse(readFileSync(join(cwd, ".rovecode", "modes.json"), "utf8"));
111
+ } catch {
112
+ return {};
113
+ }
114
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return {};
115
+ const o = raw as Record<string, unknown>;
116
+ const out: ModesConfig = {};
117
+ if (isMode(o.defaultMode)) out.defaultMode = o.defaultMode;
118
+ if (typeof o.planActSeparateModels === "boolean") out.planActSeparateModels = o.planActSeparateModels;
119
+ const plan = asSelection(o.plan);
120
+ const act = asSelection(o.act);
121
+ if (plan) out.plan = plan;
122
+ if (act) out.act = act;
123
+ return out;
124
+ }
125
+
126
+ // ---------- Plan-mode policy rule set (rides the existing pipeline) ----------
127
+
128
+ /**
129
+ * Deny rules appended AFTER the base rules; evaluatePermissions is
130
+ * last-match-wins (src/core/tools.ts:17-27), so these override any earlier
131
+ * allow/prompt — including yolo's `* * allow`. Action names are the ones
132
+ * actionFor() emits (src/core/tools.ts:145-154).
133
+ *
134
+ * Upstream basis: ToolPresets.plan disables editing (presets.ts:50-51); the
135
+ * shell/spawn/memory denies are the rovecode deviations documented above.
136
+ */
137
+ export function planModeRules(allowTools: readonly string[] = []): PermissionRule[] {
138
+ const rules: PermissionRule[] = [
139
+ // plan is the exploration mode: reads are guaranteed, whatever the base
140
+ // rules said (ToolPresets.plan enableReadFiles/enableSearch, presets.ts:46-47)
141
+ { action: "file.read", resource: "*", effect: "allow" },
142
+ { action: "file.write", resource: "*", effect: "deny" },
143
+ { action: "shell.exec", resource: "*", effect: "deny" },
144
+ { action: "spawn", resource: "*", effect: "deny" },
145
+ { action: "memory.write", resource: "*", effect: "deny" },
146
+ // port #32: the session todo list IS the plan — todo_write (kind memory; its policy resource
147
+ // is the tool name, tools/todo.ts) is re-allowed right after the memory deny, so plan mode can
148
+ // record its plan while memory_edit and every other memory.write stay denied (one ladder)
149
+ { action: "memory.write", resource: "todo_write", effect: "allow" },
150
+ // blanket deny for custom tools (e.g. mcp_call) — MCP calls can mutate
151
+ { action: "tool.*", resource: "*", effect: "deny" },
152
+ ];
153
+ // read-only custom tools a caller vouches for, re-allowed after the blanket
154
+ // deny (last match wins)
155
+ for (const name of allowTools) {
156
+ rules.push({ action: `tool.${name}`, resource: "*", effect: "allow" });
157
+ }
158
+ return rules;
159
+ }
160
+
161
+ /** Mode-aware rule transform: act passes the base rules through untouched;
162
+ * plan appends the read-only rule set. Pure — never mutates `base`. */
163
+ export function applyModeRules(
164
+ mode: AgentMode,
165
+ base: readonly PermissionRule[],
166
+ allowTools: readonly string[] = [],
167
+ ): PermissionRule[] {
168
+ if (mode !== "plan") return [...base];
169
+ return [...base, ...planModeRules(allowTools)];
170
+ }
171
+
172
+ // ---------- Plan-mode system prompt section ----------
173
+
174
+ /**
175
+ * Behavioral contract appended to the system prompt in plan mode. Adapted
176
+ * from PLAN_MODE_INSTRUCTIONS_BASE (sdk/packages/shared/src/prompt/
177
+ * cline.ts:34-45) with the no-self-switch tail (:52-59). The upstream
178
+ * run_commands paragraph is replaced: rovecode plan mode has no shell at all.
179
+ */
180
+ export function planModePromptSection(): string {
181
+ return `# Plan Mode
182
+
183
+ You are in Plan mode. Your role is to explore, analyze, and plan -- not to execute.
184
+ - Read files and search the codebase to understand the task
185
+ - Present your plan as a structured outline with clear steps
186
+ - Editing tools, shell commands, and sub-agents are unavailable in plan mode: attempts are denied by policy. If the task requires a mutation, put it in the plan; it happens only after the user switches to act mode.
187
+
188
+ Once you have presented your plan, end your turn and wait for the user's response. You do NOT have the ability to switch to act mode yourself -- the user must do it manually with the Plan/Act toggle once they are satisfied with the plan. If the task requires tools that are only available in act mode, ask the user to "toggle to Act mode" (use those words).`;
189
+ }
190
+
191
+ // ---------- Mode-switch notice (format.ts:41-80, ported) ----------
192
+
193
+ export interface ModeSwitch {
194
+ from: AgentMode;
195
+ to: AgentMode;
196
+ }
197
+
198
+ /** Ports formatModeSwitchNotice (format.ts:41-46) verbatim. */
199
+ export function formatModeSwitchNotice(from: AgentMode, to: AgentMode): string {
200
+ return `<mode_notice>The user switched from ${from} mode to ${to} mode before sending this message.</mode_notice>`;
201
+ }
202
+
203
+ /**
204
+ * Ports createModeSwitchNoticeTracker (format.ts:61-80): tracks a
205
+ * user-initiated switch so the next outbound turn can carry a notice. A
206
+ * round trip (plan→act→plan before sending anything) cancels out, since the
207
+ * mode the model last saw never effectively changed (:64-73).
208
+ */
209
+ export function createModeSwitchNoticeTracker(): {
210
+ record(from: AgentMode, to: AgentMode): void;
211
+ consume(): ModeSwitch | null;
212
+ } {
213
+ let pending: ModeSwitch | null = null;
214
+ return {
215
+ record(from: AgentMode, to: AgentMode): void {
216
+ if (from === to) return;
217
+ if (pending) {
218
+ pending = pending.from === to ? null : { from: pending.from, to };
219
+ return;
220
+ }
221
+ pending = { from, to };
222
+ },
223
+ consume(): ModeSwitch | null {
224
+ const notice = pending;
225
+ pending = null;
226
+ return notice;
227
+ },
228
+ };
229
+ }
230
+
231
+ // ---------- Session entry (durable mode-switch record) ----------
232
+
233
+ /**
234
+ * Mode switches persist as system-role Messages so the existing SessionStore
235
+ * Entry union (src/core/session.ts:10) accepts them unchanged: `modeSwitch`
236
+ * is an extra field that rides the JSONL round trip; replay renders the
237
+ * notice text as a system note; the provider seam sees a system message
238
+ * placed exactly where the switch happened.
239
+ */
240
+ export interface ModeChangeEntry extends Message {
241
+ role: "system";
242
+ modeSwitch: ModeSwitch;
243
+ }
244
+
245
+ export function buildModeChangeEntry(sw: ModeSwitch, parentId: string | null): ModeChangeEntry {
246
+ return {
247
+ id: randomUUID(),
248
+ role: "system",
249
+ parts: [{ kind: "text", text: formatModeSwitchNotice(sw.from, sw.to) }],
250
+ parentId,
251
+ createdAt: Date.now(),
252
+ modeSwitch: { from: sw.from, to: sw.to },
253
+ };
254
+ }
255
+
256
+ /** The ModeSwitch a session entry carries, or null for anything else (plain
257
+ * system notes, junk fields). Lets replay render a switch as a human line
258
+ * ("mode → plan") instead of the raw <mode_notice> XML (R2 #20 LOW-3). */
259
+ export function modeSwitchOf(entry: unknown): ModeSwitch | null {
260
+ if (!entry || typeof entry !== "object") return null;
261
+ const e = entry as { role?: unknown; modeSwitch?: unknown };
262
+ if (e.role !== "system") return null;
263
+ const sw = e.modeSwitch as { from?: unknown; to?: unknown } | undefined;
264
+ if (!sw || typeof sw !== "object") return null;
265
+ return isMode(sw.from) && isMode(sw.to) ? { from: sw.from, to: sw.to } : null;
266
+ }
267
+
268
+ /** Mode a resumed session should restore to: the LAST mode-change entry on
269
+ * the active path wins; null when the session never switched. */
270
+ export function modeFromEntries(entries: readonly unknown[]): AgentMode | null {
271
+ for (let i = entries.length - 1; i >= 0; i--) {
272
+ const sw = modeSwitchOf(entries[i]);
273
+ if (sw) return sw.to;
274
+ }
275
+ return null;
276
+ }
277
+
278
+ // ---------- ModeManager (session-scoped mode + per-mode model slots) ----------
279
+
280
+ interface Slots {
281
+ plan: ModeModelSelection;
282
+ act: ModeModelSelection;
283
+ }
284
+
285
+ /**
286
+ * Holds the current mode plus one provider/model slot per mode.
287
+ *
288
+ * Model resolution precedence per field (highest wins), tested:
289
+ * 1. runtime writes via setModel() to that mode's slot (latest wins —
290
+ * upstream: the settings UI writes the current mode's field,
291
+ * updateApiConfiguration.ts:108-117)
292
+ * 2. `.rovecode/modes.json` per-mode entry (seeds the slot — upstream reads
293
+ * planMode… / actMode… fields per mode, cline-session-factory.ts:552-558)
294
+ * 3. constructor fallback (session default provider/model)
295
+ *
296
+ * With planActSeparateModels=false (the default, state-keys.ts:272),
297
+ * setModel() mirrors the write into BOTH slots (updateApiConfiguration.ts:
298
+ * 119-131); config seeds still resolve per mode, matching upstream's
299
+ * read-side behavior which never consults the flag.
300
+ */
301
+ export class ModeManager {
302
+ private currentMode: AgentMode;
303
+ private readonly slots: Slots;
304
+ private readonly fallback: ModeModelSelection;
305
+ private readonly separateModels: boolean;
306
+ private readonly tracker = createModeSwitchNoticeTracker();
307
+
308
+ constructor(cfg: ModesConfig = {}, fallback: ModeModelSelection = {}) {
309
+ this.currentMode = cfg.defaultMode ?? DEFAULT_MODE;
310
+ this.separateModels = cfg.planActSeparateModels ?? false;
311
+ this.fallback = { provider: fallback.provider, model: fallback.model };
312
+ this.slots = {
313
+ plan: { provider: cfg.plan?.provider, model: cfg.plan?.model },
314
+ act: { provider: cfg.act?.provider, model: cfg.act?.model },
315
+ };
316
+ }
317
+
318
+ get mode(): AgentMode {
319
+ return this.currentMode;
320
+ }
321
+
322
+ get separate(): boolean {
323
+ return this.separateModels;
324
+ }
325
+
326
+ /** Switch modes. Already in `to` → null, nothing recorded
327
+ * (sdk-mode-coordinator.ts:131-135). Otherwise records the pending notice
328
+ * (round trips cancel, format.ts:64-73) and returns the switch. */
329
+ toggle(to: AgentMode): ModeSwitch | null {
330
+ if (to === this.currentMode) return null;
331
+ const sw: ModeSwitch = { from: this.currentMode, to };
332
+ this.currentMode = to;
333
+ this.tracker.record(sw.from, sw.to);
334
+ return sw;
335
+ }
336
+
337
+ /** Restore a mode on session resume WITHOUT recording a notice: a pending
338
+ * notice must not leak across sessions (sdk-mode-coordinator.ts:79-81,
339
+ * 101-112 scope notices to the session they were recorded for). */
340
+ restore(mode: AgentMode): void {
341
+ this.currentMode = mode;
342
+ this.tracker.consume();
343
+ }
344
+
345
+ /** Pending user-initiated switch for the NEXT outbound turn, cleared on
346
+ * read (format.ts:74-78). Null after a cancelled round trip. */
347
+ consumeSwitchNotice(): ModeSwitch | null {
348
+ return this.tracker.consume();
349
+ }
350
+
351
+ /** Provider+model the given (default: current) mode runs with. */
352
+ modelFor(mode: AgentMode = this.currentMode): { provider: string; model: string } {
353
+ const slot = this.slots[mode];
354
+ return {
355
+ provider: slot.provider ?? this.fallback.provider ?? "",
356
+ model: slot.model ?? this.fallback.model ?? "",
357
+ };
358
+ }
359
+
360
+ /** Write the current mode's slot; with separate models OFF the write is
361
+ * mirrored into the other mode's slot (updateApiConfiguration.ts:119-131).
362
+ * Only fields present in `sel` are written. */
363
+ setModel(sel: ModeModelSelection): void {
364
+ const targets: AgentMode[] = this.separateModels
365
+ ? [this.currentMode]
366
+ : ["plan", "act"];
367
+ for (const m of targets) {
368
+ if (sel.provider !== undefined) this.slots[m].provider = sel.provider;
369
+ if (sel.model !== undefined) this.slots[m].model = sel.model;
370
+ }
371
+ }
372
+ }
@@ -0,0 +1,207 @@
1
+ /** Subagent orchestration (ADR-009): child sessions, depth caps, spawn policy,
2
+ * git-worktree isolation with delta patch merge-back (omp structured-subagent + worktree pattern). */
3
+
4
+ import { randomUUID } from "node:crypto";
5
+ import { cpSync, mkdirSync, mkdtempSync, rmSync } from "node:fs";
6
+ import { tmpdir } from "node:os";
7
+ import { join } from "node:path";
8
+ import type { AgentDefinition, AgentVars, SpawnRequest, SpawnResult, RunConfig, StreamFn, PermissionRule } from "../core/types.ts";
9
+ import { ToolRegistry, type ExtensionHooks } from "../core/tools.ts";
10
+ import { ToolGuard } from "../core/guardrails.ts";
11
+ import { SessionStore } from "../core/session.ts";
12
+ import { agentLoop, SteeringQueue } from "../core/loop.ts";
13
+
14
+ export const DEFAULT_MAX_DEPTH = 3;
15
+
16
+ export interface SpawnContext {
17
+ depth: number; // 0 = root
18
+ maxDepth: number;
19
+ parentSessionId: string;
20
+ }
21
+
22
+ /** Preflight (omp structured-subagent.ts:220-237): depth, spawn policy, recursion block. */
23
+ export function preflightSpawn(def: AgentDefinition, ctx: SpawnContext): { ok: boolean; reason?: string } {
24
+ const policy = def.spawns ?? "subtasks";
25
+ if (policy === "none") return { ok: false, reason: `agent '${def.name}' spawn policy is 'none'` };
26
+ if (ctx.depth >= ctx.maxDepth) return { ok: false, reason: `depth cap ${ctx.maxDepth} reached (current ${ctx.depth})` };
27
+ return { ok: true };
28
+ }
29
+
30
+ export interface IsolationWorkspace {
31
+ dir: string;
32
+ kind: "worktree" | "copy" | "none";
33
+ /** produce a git-compatible patch of changes vs baseline */
34
+ diff(): Promise<string>;
35
+ cleanup(): Promise<void>;
36
+ }
37
+
38
+ function git(args: string[], cwd: string, stdin?: string): { code: number; out: string } {
39
+ const p = Bun.spawnSync(["git", ...args], { cwd, stdin: stdin === undefined ? "ignore" : new Blob([stdin]), stdout: "pipe", stderr: "pipe" });
40
+ return { code: p.exitCode ?? -1, out: p.stdout.toString() };
41
+ }
42
+
43
+ /** COW-ish isolation: prefer `git worktree`, fall back to plain copy (omp pi-iso ladder).
44
+ * Windows-safe: git for worktree/diff, node fs.cpSync/rmSync for copy/cleanup (no POSIX cp/rm/diff). */
45
+ export async function createIsolation(rootDir: string, opts: { prefer: "worktree" | "copy" | "none" }): Promise<IsolationWorkspace> {
46
+ if (opts.prefer === "none") {
47
+ return { dir: rootDir, kind: "none", diff: async () => "", cleanup: async () => {} };
48
+ }
49
+ const id = randomUUID().slice(0, 8);
50
+ if (opts.prefer === "worktree") {
51
+ const dir = join(rootDir, ".rovecode", "worktrees", id);
52
+ // --detach (fix-wave L3): `-b rovecode/task/<id>` left one branch per isolated task behind in
53
+ // the root repo after `worktree remove`; a detached checkout at HEAD leaves only the
54
+ // worktree, which cleanup removes
55
+ if (git(["worktree", "add", "--detach", dir], rootDir).code === 0) {
56
+ return {
57
+ dir, kind: "worktree",
58
+ // intent-to-add first: `git diff HEAD` never shows UNTRACKED files, so a child's
59
+ // new files would silently miss the merge-back (port #26 isolation fix)
60
+ diff: async () => { git(["add", "-A", "-N"], dir); return git(["diff", "HEAD"], dir).out; },
61
+ cleanup: async () => { git(["worktree", "remove", "--force", dir], rootDir); },
62
+ };
63
+ }
64
+ }
65
+ // copy fallback: work/ is the live copy the child mutates; baseline/ is the pristine snapshot
66
+ // (node fs.cpSync/fs.rmSync — POSIX `cp -r`/`rm -rf` don't exist on Windows)
67
+ const dir = mkdtempSync(join(tmpdir(), "rovecode-iso-"));
68
+ try {
69
+ mkdirSync(join(dir, "baseline"));
70
+ cpSync(rootDir, join(dir, "baseline"), { recursive: true });
71
+ cpSync(rootDir, join(dir, "work"), { recursive: true });
72
+ } catch {
73
+ rmSync(dir, { recursive: true, force: true });
74
+ return { dir: rootDir, kind: "none", diff: async () => "", cleanup: async () => {} };
75
+ }
76
+ return {
77
+ dir: join(dir, "work"), kind: "copy",
78
+ // git diff --no-index (POSIX `diff -ru` doesn't exist on Windows and isn't a git patch);
79
+ // strip the baseline//work/ path roots so the patch applies at repo-relative paths.
80
+ // The header names EITHER root on either side (modify: a/baseline b/work; create:
81
+ // a/work b/work; delete: a/baseline b/baseline) — strip both, or `git apply` rejects
82
+ // creations with "inconsistent new filename" (port #26 isolation fix).
83
+ diff: async () => {
84
+ const d = git(["diff", "--no-index", "baseline", "work"], dir);
85
+ return d.code <= 1 ? d.out.replace(/^([-+]{3} [ab]\/)(baseline|work)\//gm, "$1").replace(/^(diff --git a\/)(?:baseline|work)\/(\S+ b\/)(?:baseline|work)\/(\S+)/gm, "$1$2$3") : "";
86
+ },
87
+ cleanup: async () => { rmSync(dir, { recursive: true, force: true }); },
88
+ };
89
+ }
90
+
91
+ /** Per-child context handed to registryFactory (port #26): a child's registry can
92
+ * bind nested tools (the `task` tool) to THIS child's depth, its own steering
93
+ * queue (nested completion notes land in the child's next turn, not the root's)
94
+ * and its run signal. `taskId` is set by TaskManager when the child IS a
95
+ * background task (enables slot lending); plain runChild callers leave it unset. */
96
+ export interface ChildContext {
97
+ depth: number;
98
+ steering: SteeringQueue;
99
+ signal?: AbortSignal;
100
+ taskId?: string;
101
+ }
102
+
103
+ export interface ChildRunnerDeps {
104
+ defs: Map<string, AgentDefinition>;
105
+ stream: StreamFn;
106
+ registryFactory: (def: AgentDefinition, cwd: string, child?: ChildContext) => ToolRegistry;
107
+ rootDir: string;
108
+ sessionsDir: string;
109
+ baseConfig: RunConfig;
110
+ /** port #29: the parent runtime's hook set — a child runs under the same hooks (pre_tool vetoes,
111
+ * post_tool, pre_run/post_run/on_event via the observer), so delegation cannot dodge a hook */
112
+ hooks?: ExtensionHooks;
113
+ }
114
+
115
+ /** Runs a child agent in its own session (+ optional isolation), returns summary + patch.
116
+ * `depth` = this child's depth (root spawn = 0); grandchildren receive depth + 1 via agentLoop.
117
+ * `signal` (port #26): aborting it cancels the child's run — agentLoop's own controller
118
+ * follows deps.signal (port #21), so the in-flight fetch and tool subprocesses die.
119
+ * ok = the child's run ended "done"; error/budget/stopped runs return ok:false with
120
+ * the run_end summary (a background job needs a truthful failed status). An isolated
121
+ * child's patch is merged back ONLY when ok — a cancelled or errored child's
122
+ * half-done edits never land in the parent tree (the patch is still returned). */
123
+ export async function runChild(deps: ChildRunnerDeps, req: SpawnRequest, depth = 0, signal?: AbortSignal): Promise<SpawnResult> {
124
+ const fail = (summary: string): SpawnResult => ({ agent: req.agent, ok: false, summary, usage: { input: 0, output: 0 } });
125
+ const def = deps.defs.get(req.agent);
126
+ if (!def) return fail(`unknown agent '${req.agent}'`);
127
+ const gate = preflightSpawn(def, { depth, maxDepth: DEFAULT_MAX_DEPTH, parentSessionId: "" });
128
+ if (!gate.ok) return fail(gate.reason ?? "spawn refused");
129
+
130
+ const iso = req.isolated ? await createIsolation(deps.rootDir, { prefer: "worktree" }) : await createIsolation(deps.rootDir, { prefer: "none" });
131
+ try {
132
+ const store = new SessionStore(deps.sessionsDir, randomUUID());
133
+ const steering = new SteeringQueue();
134
+ const registry = deps.registryFactory(def, iso.dir, { depth, steering, signal });
135
+ const cfg: RunConfig = {
136
+ ...deps.baseConfig,
137
+ // children get their own permission set derived from parent policy (opencode task.ts:160)
138
+ permissionRules: deriveChildRules(deps.baseConfig.permissionRules, iso.dir, iso.kind !== "none"),
139
+ };
140
+ let end: { status: string; summary: string } | undefined;
141
+ for await (const ev of agentLoop(def, req.goal, req.vars ?? {}, cfg, {
142
+ // port #4: children get their own loop guard — subagents loop too
143
+ stream: deps.stream, registry, store, guard: new ToolGuard(),
144
+ // tools resolve relative paths / run shells in the ISOLATION dir, not the process cwd
145
+ cwd: iso.dir,
146
+ signal,
147
+ hooks: deps.hooks, // port #29: the parent's hooks govern the child too
148
+ }, steering, depth + 1)) {
149
+ if (ev.type === "run_end") end = { status: ev.status, summary: ev.summary };
150
+ }
151
+ let input = 0, output = 0;
152
+ for (const m of store.messages()) {
153
+ if (m.usage) { input += m.usage.input; output += m.usage.output; }
154
+ }
155
+ const patch = iso.kind === "none" ? undefined : await iso.diff();
156
+ const ok = end?.status === "done";
157
+ const text = lastText(store);
158
+ let summary = ok
159
+ ? (text || "(no output)")
160
+ : `${end?.summary ?? "child run ended without run_end"}${text ? `\nlast output: ${text}` : ""}`;
161
+ if (ok && patch && !applyPatch(patch, deps.rootDir)) summary += `\npatch-apply-failed`;
162
+ return { agent: req.agent, ok, summary: summary.slice(0, 4_000), usage: { input, output }, patch };
163
+ } finally {
164
+ await iso.cleanup();
165
+ }
166
+ }
167
+
168
+ function lastText(store: SessionStore): string {
169
+ const last = [...store.messages()].reverse().find((m) => m.role === "assistant");
170
+ return last ? last.parts.filter((p) => p.kind === "text").map((p) => (p as { text: string }).text).join("") : "";
171
+ }
172
+
173
+ /** Best-effort merge-back into the parent tree (omp worktree → git apply). */
174
+ function applyPatch(patch: string, parentDir: string): boolean {
175
+ if (!patch.trim()) return true; // nothing changed
176
+ // -c core.autocrlf=false: apply the patch byte-exact — Git for Windows' system-level autocrlf=true
177
+ // would rewrite every patched file to CRLF, even in a non-repo parent dir (measured on the copy rung)
178
+ return git(["-c", "core.autocrlf=false", "apply", "--whitespace=nowarn", "-"], parentDir, patch).code === 0;
179
+ }
180
+
181
+ /** Children never exceed parent grants:
182
+ * - "prompt" rules become "deny": children are non-interactive, nobody can answer a prompt
183
+ * - isolated children: path-glob allow resources are re-rooted under the isolation dir
184
+ * - non-isolated children keep allow breadth unchanged (resources are action-shaped globs like
185
+ * "src/**" or "rm *"; prefixing them with an absolute path would break shell-command matching)
186
+ * - deny-rest DEFAULT, placed FIRST: evaluatePermissions is LAST-match-wins
187
+ * (tools.ts), so the catch-all must sit at the lowest priority for the
188
+ * parent-derived rules after it to override — an unlisted action falls
189
+ * through to it and is denied. Appending it LAST was bug FW2-P: the
190
+ * catch-all matched everything as the final word and overrode every
191
+ * parent allow, denying ALL child tool calls even under an allow-all parent.
192
+ */
193
+ export function deriveChildRules(rules: PermissionRule[], isoDir?: string, isolated = false): PermissionRule[] {
194
+ const out: PermissionRule[] = [{ action: "*", resource: "*", effect: "deny" }];
195
+ for (const r of rules) {
196
+ if (r.effect === "prompt") out.push({ ...r, effect: "deny" });
197
+ else if (isolated && isoDir && r.effect === "allow" && isPathResource(r)) out.push({ ...r, resource: join(isoDir, r.resource) });
198
+ else out.push({ ...r });
199
+ }
200
+ return out;
201
+ }
202
+
203
+ /** Path-shaped resources ("src/**", "**\/*.ts"); "rm *" (space-separated) is a command resource. */
204
+ function isPathResource(r: PermissionRule): boolean {
205
+ if (r.resource === "*" || r.resource.includes(" ")) return false;
206
+ return r.action.startsWith("file.") || r.resource.includes("/");
207
+ }