rovecode 0.3.3 → 0.4.0-beta.2

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 (491) hide show
  1. package/CHANGELOG.md +512 -0
  2. package/README.md +33 -48
  3. package/bin/rovecode.js +24 -0
  4. package/dist/cli/app-dybnr56b.js +2 -0
  5. package/dist/cli/ask-user-p8hq4xgj.js +2 -0
  6. package/dist/cli/auth-login-ewpgw5sm.js +2 -0
  7. package/dist/cli/auth-m8p9grty.js +2 -0
  8. package/dist/cli/bench-xv3ypwev.js +9 -0
  9. package/dist/cli/catalog-737wb2s0.js +2 -0
  10. package/dist/cli/cli-arhg40m0.js +2 -0
  11. package/dist/cli/client-cf2pxx8q.js +2 -0
  12. package/dist/cli/commands-3p7e4xxs.js +2 -0
  13. package/dist/cli/connect-3q93d7cb.js +2 -0
  14. package/dist/cli/context-cmd-eqxmxhzq.js +2 -0
  15. package/dist/cli/context-report-hbw9zfes.js +2 -0
  16. package/dist/cli/count-remote-mby98cd0.js +2 -0
  17. package/dist/cli/design-122y0axd.js +2 -0
  18. package/dist/cli/dispatch-b4egzvvh.js +2 -0
  19. package/dist/cli/doctor-x4jkv72e.js +3 -0
  20. package/dist/cli/executor-ftvg6tsy.js +2 -0
  21. package/dist/cli/export-pdgdhkch.js +2 -0
  22. package/dist/cli/files-cez9a96p.js +2 -0
  23. package/dist/cli/gauntlet-r3xxaszc.js +2 -0
  24. package/dist/cli/gauntlet-runner-r515m7kk.js +10 -0
  25. package/dist/cli/gauntlet-wave3-bnkjk2v2.js +5 -0
  26. package/dist/cli/gauntlet-wave4-acs9s60q.js +14 -0
  27. package/dist/cli/hashline-ewg5hbe3.js +2 -0
  28. package/dist/cli/http-n0kehsk8.js +5 -0
  29. package/dist/cli/index-z5qt1s76.js +2 -0
  30. package/dist/cli/install-80mp63kx.js +2 -0
  31. package/dist/cli/loop-12twjcat.js +2 -0
  32. package/dist/cli/main-01pv9206.js +4 -0
  33. package/dist/cli/main-0jys2ccn.js +3 -0
  34. package/dist/cli/main-1ztz6fkj.js +10 -0
  35. package/dist/cli/main-23q7cmww.js +9 -0
  36. package/dist/cli/main-2rzbexn2.js +3 -0
  37. package/dist/cli/main-2wyax8k9.js +9 -0
  38. package/dist/cli/main-2yeveeve.js +6 -0
  39. package/dist/cli/main-2z3dek0b.js +3 -0
  40. package/dist/cli/main-2zgsknth.js +3 -0
  41. package/dist/cli/main-45ejth3a.js +4 -0
  42. package/dist/cli/main-45rn3trk.js +22 -0
  43. package/dist/cli/main-4p4e2w7x.js +4 -0
  44. package/dist/cli/main-4y0tnfpa.js +16 -0
  45. package/dist/cli/main-5py0rkmc.js +4 -0
  46. package/dist/cli/main-6dtqmbt6.js +7 -0
  47. package/dist/cli/main-6h9x282m.js +4 -0
  48. package/dist/cli/main-6vjeds42.js +3 -0
  49. package/dist/cli/main-78gq4bt9.js +6 -0
  50. package/dist/cli/main-7jd5vh3x.js +4 -0
  51. package/dist/cli/main-7kt6r53y.js +4 -0
  52. package/dist/cli/main-8c1tbazx.js +58 -0
  53. package/dist/cli/main-9a9rnh47.js +19 -0
  54. package/dist/cli/main-9ht36z12.js +3 -0
  55. package/dist/cli/main-a2yfvcy9.js +7 -0
  56. package/dist/cli/main-a3f51n0x.js +5 -0
  57. package/dist/cli/main-b8zq261k.js +3 -0
  58. package/dist/cli/main-bxtvnf6d.js +13 -0
  59. package/dist/cli/main-edxc3yzt.js +4 -0
  60. package/dist/cli/main-evgz4mp5.js +21 -0
  61. package/dist/cli/main-f33fc5je.js +9 -0
  62. package/dist/cli/main-fvnpq46y.js +12 -0
  63. package/dist/cli/main-gbbty4d4.js +3 -0
  64. package/dist/cli/main-gth53dnt.js +25 -0
  65. package/dist/cli/main-hqbz10aw.js +9 -0
  66. package/dist/cli/main-hrrvcfan.js +38 -0
  67. package/dist/cli/main-hzwtsb2m.js +5 -0
  68. package/dist/cli/main-j7ttv0sd.js +34 -0
  69. package/dist/cli/main-jak598k9.js +5 -0
  70. package/dist/cli/main-kba6zeyd.js +6 -0
  71. package/dist/cli/main-kwwsz6rq.js +3 -0
  72. package/dist/cli/main-m8vm17zq.js +3 -0
  73. package/dist/cli/main-mg4f96e1.js +3 -0
  74. package/dist/cli/main-mg9b20ac.js +18 -0
  75. package/dist/cli/main-mgb9ccnx.js +3 -0
  76. package/dist/cli/main-mjt2p7aj.js +3 -0
  77. package/dist/cli/main-n6qrdbmy.js +3 -0
  78. package/dist/cli/main-na7wse0x.js +5 -0
  79. package/dist/cli/main-nqveez48.js +4 -0
  80. package/dist/cli/main-ntqef02r.js +10 -0
  81. package/dist/cli/main-nvc3yjay.js +136 -0
  82. package/dist/cli/main-p0cfn6nr.js +16 -0
  83. package/dist/cli/main-qj2djy17.js +19 -0
  84. package/dist/cli/main-qsevpgsv.js +3 -0
  85. package/dist/cli/main-qvarybsp.js +3 -0
  86. package/dist/cli/main-rebtt91r.js +5 -0
  87. package/dist/cli/main-rpg7h8mb.js +3 -0
  88. package/dist/cli/main-rsy72qmw.js +15 -0
  89. package/dist/cli/main-rvetps99.js +18 -0
  90. package/dist/cli/main-s4bb0jav.js +3 -0
  91. package/dist/cli/main-s9v8k74e.js +3 -0
  92. package/dist/cli/main-tjvwmscs.js +3 -0
  93. package/dist/cli/main-tkgarpjj.js +4 -0
  94. package/dist/cli/main-v8y60bb2.js +3 -0
  95. package/dist/cli/main-vhrrq337.js +3 -0
  96. package/dist/cli/main-vp2dfb7s.js +4 -0
  97. package/dist/cli/main-vqbr22sz.js +8 -0
  98. package/dist/cli/main-vxnwe5xx.js +18 -0
  99. package/dist/cli/main-wgph00xf.js +5 -0
  100. package/dist/cli/main-wk2csfnj.js +5 -0
  101. package/dist/cli/main-wm997zjx.js +3 -0
  102. package/dist/cli/main-wpkyraxh.js +3 -0
  103. package/dist/cli/main-wqt32p5x.js +4 -0
  104. package/dist/cli/main-x9ct6y1a.js +3 -0
  105. package/dist/cli/main-xfekqh9m.js +7 -0
  106. package/dist/cli/main-xt9zc3n6.js +7 -0
  107. package/dist/cli/main-xx2z3zh5.js +4 -0
  108. package/dist/cli/main-y5c82rxr.js +3 -0
  109. package/dist/cli/main-yrjt2sqt.js +14 -0
  110. package/dist/cli/main-ys6zj3yr.js +3 -0
  111. package/dist/cli/main-ywbxshqc.js +8 -0
  112. package/dist/cli/main-z13755t8.js +25 -0
  113. package/dist/cli/main-zc7pyrbj.js +4 -0
  114. package/dist/cli/main.js +279 -0
  115. package/dist/cli/market-cmd-bm5xvn9f.js +5 -0
  116. package/dist/cli/mcp-login-bthtfpt7.js +2 -0
  117. package/dist/cli/mcp-market-cmd-mbeshfyd.js +2 -0
  118. package/dist/cli/notify-54v5z9dz.js +2 -0
  119. package/dist/cli/oauth-g5gme95c.js +2 -0
  120. package/dist/cli/output-satndjap.js +16 -0
  121. package/dist/cli/profiles-sfhpbq3m.js +2 -0
  122. package/dist/cli/provider-config-hv3xtdt4.js +2 -0
  123. package/dist/cli/provider-kwzq6g84.js +2 -0
  124. package/dist/cli/registry-fh0hdnyn.js +2 -0
  125. package/dist/cli/registry-y1y8e94r.js +2 -0
  126. package/dist/cli/repl-t4z03mqq.js +11 -0
  127. package/dist/cli/resume-fqt4chg8.js +2 -0
  128. package/dist/cli/run-flags-rysbag9t.js +2 -0
  129. package/dist/cli/runtime-j19fjbsa.js +2 -0
  130. package/dist/cli/sandbox-config-g4qxd7y5.js +2 -0
  131. package/dist/cli/server-r0b6bksk.js +5 -0
  132. package/dist/cli/session-arg-txmn5g4x.js +2 -0
  133. package/dist/cli/session-ed250d9j.js +2 -0
  134. package/dist/cli/sessions-cmd-adw7svfn.js +7 -0
  135. package/dist/cli/settings-y9rzcqx8.js +2 -0
  136. package/dist/cli/setup-jmbr11j0.js +2 -0
  137. package/dist/cli/sextant-smoke-tcth0vea.js +5 -0
  138. package/dist/cli/skills-cmd-zbdy99v6.js +2 -0
  139. package/dist/cli/smoke-1bg937kx.js +8 -0
  140. package/dist/cli/start-chat-p01cdks3.js +12 -0
  141. package/dist/cli/stream-4wmyaypz.js +2 -0
  142. package/dist/cli/task-eg4s093s.js +2 -0
  143. package/dist/cli/tasks-12v9rr9k.js +2 -0
  144. package/dist/cli/thinking-a5ngvqyh.js +2 -0
  145. package/dist/cli/todo-1wxpcecx.js +2 -0
  146. package/dist/cli/tools-2ftsya7w.js +2 -0
  147. package/dist/cli/tools-x1tj4fxm.js +2 -0
  148. package/dist/cli/trust-cmd-hccxehzb.js +2 -0
  149. package/dist/cli/update-check-ygt3vd7m.js +2 -0
  150. package/dist/cli/update-cmd-v23qhr8c.js +2 -0
  151. package/dist/cli/voice-g1gtck92.js +2 -0
  152. package/dist/cli/webfetch-0nnrjgb5.js +2 -0
  153. package/dist/cli/websearch-f0vr2p7d.js +2 -0
  154. package/dist/cli/workspace-9rq1w4ta.js +2 -0
  155. package/dist/lib/index.js +62 -0
  156. package/dist/lib/models-index.json +1 -0
  157. package/dist/lib/plugins.js +6 -0
  158. package/dist/lib/providers.js +17 -0
  159. package/dist/lib/public-api.js +20 -0
  160. package/dist/rovecode.exe +4 -0
  161. package/package.json +83 -72
  162. package/bin/rovecode.ts +0 -21
  163. package/src/acp/server.ts +0 -374
  164. package/src/cli/auth-login.ts +0 -122
  165. package/src/cli/connect.ts +0 -244
  166. package/src/cli/context-cmd.ts +0 -199
  167. package/src/cli/dispatch.ts +0 -82
  168. package/src/cli/doctor.ts +0 -362
  169. package/src/cli/export.ts +0 -276
  170. package/src/cli/help.ts +0 -293
  171. package/src/cli/is-tui-invocation.ts +0 -8
  172. package/src/cli/main.ts +0 -583
  173. package/src/cli/market-cmd.ts +0 -658
  174. package/src/cli/mcp-login.ts +0 -141
  175. package/src/cli/mcp-market-cmd.ts +0 -302
  176. package/src/cli/output.ts +0 -382
  177. package/src/cli/repl.ts +0 -250
  178. package/src/cli/repomap-root.ts +0 -14
  179. package/src/cli/resume.ts +0 -57
  180. package/src/cli/run-flags.ts +0 -43
  181. package/src/cli/run-limits.ts +0 -78
  182. package/src/cli/runtime.ts +0 -931
  183. package/src/cli/session-arg.ts +0 -30
  184. package/src/cli/sessions-cmd.ts +0 -145
  185. package/src/cli/setup.ts +0 -153
  186. package/src/cli/skills-cmd.ts +0 -194
  187. package/src/cli/start-chat.ts +0 -65
  188. package/src/cli/trust-cmd.ts +0 -52
  189. package/src/coding/bash.ts +0 -148
  190. package/src/coding/checkpoints.ts +0 -327
  191. package/src/coding/diff.ts +0 -138
  192. package/src/coding/files.ts +0 -341
  193. package/src/coding/hashline.ts +0 -274
  194. package/src/coding/lsp-gate.ts +0 -254
  195. package/src/coding/lsp-servers.ts +0 -147
  196. package/src/coding/lsp.ts +0 -283
  197. package/src/coding/repomap-cache.ts +0 -99
  198. package/src/coding/repomap-files.ts +0 -192
  199. package/src/coding/repomap.ts +0 -481
  200. package/src/core/agents.ts +0 -255
  201. package/src/core/compaction.ts +0 -259
  202. package/src/core/config.ts +0 -289
  203. package/src/core/context-report.ts +0 -228
  204. package/src/core/context.ts +0 -60
  205. package/src/core/count-remote.ts +0 -107
  206. package/src/core/execpolicy-rules.ts +0 -196
  207. package/src/core/execpolicy.ts +0 -385
  208. package/src/core/executor.ts +0 -454
  209. package/src/core/guardrails.ts +0 -400
  210. package/src/core/hooks.ts +0 -411
  211. package/src/core/images.ts +0 -230
  212. package/src/core/intro.ts +0 -266
  213. package/src/core/loop.ts +0 -567
  214. package/src/core/modes.ts +0 -372
  215. package/src/core/orchestrator.ts +0 -245
  216. package/src/core/proc-group.ts +0 -48
  217. package/src/core/project-trust.ts +0 -98
  218. package/src/core/reflection.ts +0 -165
  219. package/src/core/sandbox-config.ts +0 -186
  220. package/src/core/session-id.ts +0 -24
  221. package/src/core/session-images.ts +0 -73
  222. package/src/core/session-ops.ts +0 -183
  223. package/src/core/session-text.ts +0 -29
  224. package/src/core/session.ts +0 -469
  225. package/src/core/settings.ts +0 -170
  226. package/src/core/tasks.ts +0 -646
  227. package/src/core/token-scale.ts +0 -108
  228. package/src/core/tools.ts +0 -309
  229. package/src/core/trust.ts +0 -104
  230. package/src/core/types.ts +0 -330
  231. package/src/core/update-check.ts +0 -171
  232. package/src/core/usage.ts +0 -204
  233. package/src/core/validate.ts +0 -121
  234. package/src/core/verify-gate.ts +0 -159
  235. package/src/core/verify.ts +0 -236
  236. package/src/core/voice.ts +0 -158
  237. package/src/core/win-job.ts +0 -183
  238. package/src/core/workspace.ts +0 -184
  239. package/src/design/audit.ts +0 -797
  240. package/src/design/direction.ts +0 -190
  241. package/src/design/rules.ts +0 -157
  242. package/src/eval/bench.ts +0 -150
  243. package/src/eval/gauntlet-runner.ts +0 -215
  244. package/src/eval/gauntlet-support.ts +0 -84
  245. package/src/eval/gauntlet-wave3.ts +0 -269
  246. package/src/eval/gauntlet-wave4.ts +0 -217
  247. package/src/eval/gauntlet.ts +0 -253
  248. package/src/index.ts +0 -17
  249. package/src/lanes/agy.ts +0 -95
  250. package/src/lanes/approval.ts +0 -24
  251. package/src/lanes/claude.ts +0 -129
  252. package/src/lanes/codex.ts +0 -127
  253. package/src/lanes/events.ts +0 -130
  254. package/src/lanes/job.ts +0 -142
  255. package/src/lanes/opencode.ts +0 -122
  256. package/src/lanes/process.ts +0 -184
  257. package/src/lanes/progress.ts +0 -183
  258. package/src/lanes/registry.ts +0 -178
  259. package/src/lanes/runner.ts +0 -124
  260. package/src/lanes/types.ts +0 -112
  261. package/src/market/catalogs/mcp-docs.json +0 -111
  262. package/src/market/catalogs/plugins.json +0 -111
  263. package/src/market/catalogs/skills.json +0 -478
  264. package/src/market/clone.ts +0 -72
  265. package/src/market/context-cost.ts +0 -121
  266. package/src/market/digest.ts +0 -106
  267. package/src/market/index.ts +0 -22
  268. package/src/market/install.ts +0 -578
  269. package/src/market/manifest.ts +0 -187
  270. package/src/market/prereq.ts +0 -145
  271. package/src/market/registry.ts +0 -363
  272. package/src/market/resolve.ts +0 -111
  273. package/src/market/types.ts +0 -236
  274. package/src/market/validate.ts +0 -227
  275. package/src/mcp/client.ts +0 -449
  276. package/src/mcp/config.ts +0 -252
  277. package/src/mcp/local-package.ts +0 -211
  278. package/src/mcp/market-catalog.ts +0 -84
  279. package/src/mcp/market-install.ts +0 -289
  280. package/src/mcp/market.ts +0 -362
  281. package/src/mcp/oauth.ts +0 -251
  282. package/src/mcp/prompts-resources.ts +0 -249
  283. package/src/mcp/shared.ts +0 -149
  284. package/src/mcp/status.ts +0 -67
  285. package/src/mcp/tools.ts +0 -275
  286. package/src/mcp/transport.ts +0 -122
  287. package/src/mcp/trust.ts +0 -25
  288. package/src/memory/blocks.ts +0 -278
  289. package/src/memory/recall.ts +0 -355
  290. package/src/memory/scope.ts +0 -182
  291. package/src/memory/store.ts +0 -105
  292. package/src/memory/tools.ts +0 -99
  293. package/src/plugins/cli.ts +0 -119
  294. package/src/plugins/discover.ts +0 -108
  295. package/src/plugins/index.ts +0 -50
  296. package/src/plugins/install.ts +0 -184
  297. package/src/plugins/load.ts +0 -124
  298. package/src/plugins/manifest.ts +0 -92
  299. package/src/plugins/state.ts +0 -83
  300. package/src/providers/auth.ts +0 -408
  301. package/src/providers/cache.ts +0 -223
  302. package/src/providers/catalog-local.ts +0 -160
  303. package/src/providers/catalog.ts +0 -421
  304. package/src/providers/middleware-context.ts +0 -86
  305. package/src/providers/middleware.ts +0 -373
  306. package/src/providers/model-list.ts +0 -23
  307. package/src/providers/oauth/common.ts +0 -105
  308. package/src/providers/oauth/device-code.ts +0 -107
  309. package/src/providers/oauth/github-copilot.ts +0 -146
  310. package/src/providers/oauth/loopback.ts +0 -158
  311. package/src/providers/oauth/openai.ts +0 -163
  312. package/src/providers/oauth/openrouter.ts +0 -89
  313. package/src/providers/oauth/pkce.ts +0 -45
  314. package/src/providers/oauth/registry.ts +0 -39
  315. package/src/providers/oauth/seam.ts +0 -89
  316. package/src/providers/profile-glm53.ts +0 -111
  317. package/src/providers/profile-sonnet5-persona.ts +0 -65
  318. package/src/providers/profile-sonnet5-voice.ts +0 -23
  319. package/src/providers/profiles.ts +0 -156
  320. package/src/providers/provider-config.ts +0 -311
  321. package/src/providers/registry.ts +0 -333
  322. package/src/providers/responses.ts +0 -209
  323. package/src/providers/retry.ts +0 -234
  324. package/src/providers/router.ts +0 -294
  325. package/src/providers/sse.ts +0 -26
  326. package/src/providers/stream-errors.ts +0 -117
  327. package/src/providers/stream.ts +0 -566
  328. package/src/providers/thinking.ts +0 -189
  329. package/src/providers/wire-messages.ts +0 -129
  330. package/src/providers/wire-responses.ts +0 -79
  331. package/src/providers/wire-select.ts +0 -53
  332. package/src/server/http.ts +0 -291
  333. package/src/server/openapi.ts +0 -246
  334. package/src/sextant/card-hits.ts +0 -102
  335. package/src/sextant/card-keys.ts +0 -55
  336. package/src/sextant/context-source.ts +0 -157
  337. package/src/sextant/crew-cards.ts +0 -350
  338. package/src/sextant/draw-agents.ts +0 -273
  339. package/src/sextant/draw-code.ts +0 -388
  340. package/src/sextant/draw-context.ts +0 -222
  341. package/src/sextant/draw-frame.ts +0 -164
  342. package/src/sextant/draw-market.ts +0 -573
  343. package/src/sextant/draw-messages.ts +0 -386
  344. package/src/sextant/draw-pet.ts +0 -230
  345. package/src/sextant/draw-plan.ts +0 -187
  346. package/src/sextant/draw-tabs.ts +0 -85
  347. package/src/sextant/draw-util.ts +0 -65
  348. package/src/sextant/draw-wizard.ts +0 -378
  349. package/src/sextant/engine.ts +0 -230
  350. package/src/sextant/frame-hits.ts +0 -25
  351. package/src/sextant/frame.ts +0 -101
  352. package/src/sextant/git-status.ts +0 -197
  353. package/src/sextant/grid.ts +0 -59
  354. package/src/sextant/input.ts +0 -119
  355. package/src/sextant/keys.ts +0 -521
  356. package/src/sextant/layout.ts +0 -86
  357. package/src/sextant/local-commands.ts +0 -169
  358. package/src/sextant/market-source.ts +0 -287
  359. package/src/sextant/mentions.ts +0 -200
  360. package/src/sextant/message-hits.ts +0 -26
  361. package/src/sextant/model.ts +0 -387
  362. package/src/sextant/overlays.ts +0 -456
  363. package/src/sextant/panel-hits.ts +0 -38
  364. package/src/sextant/pet.ts +0 -399
  365. package/src/sextant/screen.ts +0 -324
  366. package/src/sextant/scroll-hits.ts +0 -66
  367. package/src/sextant/scrollbar.ts +0 -82
  368. package/src/sextant/sextant-bridge.ts +0 -174
  369. package/src/sextant/sextant-cards.ts +0 -142
  370. package/src/sextant/sextant-diff-base.ts +0 -63
  371. package/src/sextant/sextant-files.ts +0 -154
  372. package/src/sextant/sextant-frame-loop.ts +0 -335
  373. package/src/sextant/sextant-renderer.ts +0 -574
  374. package/src/sextant/sextant-repo.ts +0 -140
  375. package/src/sextant/theme.ts +0 -66
  376. package/src/sextant/tool-rows.ts +0 -189
  377. package/src/sextant/types.ts +0 -493
  378. package/src/skills/index.ts +0 -387
  379. package/src/skills/pack.ts +0 -220
  380. package/src/skills/spec.ts +0 -162
  381. package/src/skills/tools.ts +0 -69
  382. package/src/skills/versioned.ts +0 -227
  383. package/src/telemetry/otel-export.ts +0 -122
  384. package/src/telemetry/otel-lanes.ts +0 -89
  385. package/src/telemetry/otel-logs.ts +0 -131
  386. package/src/telemetry/otel-metrics.ts +0 -136
  387. package/src/telemetry/otel.ts +0 -397
  388. package/src/telemetry/otlp.ts +0 -76
  389. package/src/tools/ask-user.ts +0 -156
  390. package/src/tools/bash-bg.ts +0 -94
  391. package/src/tools/bash-jobs.ts +0 -237
  392. package/src/tools/design.ts +0 -151
  393. package/src/tools/evalcell.ts +0 -338
  394. package/src/tools/html-text.ts +0 -139
  395. package/src/tools/provider.ts +0 -149
  396. package/src/tools/task.ts +0 -250
  397. package/src/tools/todo.ts +0 -320
  398. package/src/tools/webfetch.ts +0 -332
  399. package/src/tools/websearch.ts +0 -359
  400. package/src/tui/agents-cmd.ts +0 -41
  401. package/src/tui/app.ts +0 -749
  402. package/src/tui/attach.ts +0 -127
  403. package/src/tui/boot-notes.ts +0 -41
  404. package/src/tui/builtin-prompts.ts +0 -59
  405. package/src/tui/checkpoints-cmd.ts +0 -70
  406. package/src/tui/clipboard-image.ts +0 -81
  407. package/src/tui/clipboard.ts +0 -78
  408. package/src/tui/commands.ts +0 -283
  409. package/src/tui/config-view.ts +0 -53
  410. package/src/tui/context-cmds.ts +0 -282
  411. package/src/tui/cost.ts +0 -108
  412. package/src/tui/crash-guard.ts +0 -173
  413. package/src/tui/focus-terminal.ts +0 -34
  414. package/src/tui/git-cmds.ts +0 -273
  415. package/src/tui/git-plain.ts +0 -58
  416. package/src/tui/info-cmd.ts +0 -150
  417. package/src/tui/input-plain.ts +0 -76
  418. package/src/tui/mcp-cmd.ts +0 -128
  419. package/src/tui/memory-note.ts +0 -77
  420. package/src/tui/modes-cmd.ts +0 -45
  421. package/src/tui/notify-seq.ts +0 -100
  422. package/src/tui/notify.ts +0 -318
  423. package/src/tui/overlays.ts +0 -97
  424. package/src/tui/pi-renderer.ts +0 -428
  425. package/src/tui/providers-cmd.ts +0 -377
  426. package/src/tui/reasoning-view.ts +0 -56
  427. package/src/tui/renderer.ts +0 -128
  428. package/src/tui/replay-marker.ts +0 -29
  429. package/src/tui/session-cmd.ts +0 -148
  430. package/src/tui/session-manage.ts +0 -95
  431. package/src/tui/sextant-attach.ts +0 -102
  432. package/src/tui/sextant-io.ts +0 -202
  433. package/src/tui/sextant-smoke.ts +0 -110
  434. package/src/tui/shell-cmd.ts +0 -158
  435. package/src/tui/smoke.ts +0 -72
  436. package/src/tui/staged-terminal.ts +0 -50
  437. package/src/tui/startup.ts +0 -12
  438. package/src/tui/theme.ts +0 -59
  439. package/src/tui/todo-label.ts +0 -7
  440. package/src/tui/trust-card.ts +0 -107
  441. package/src/tui/tui-commands.ts +0 -87
  442. package/tsconfig.json +0 -30
  443. package/vendor/pi-tui/LICENSE +0 -21
  444. package/vendor/pi-tui/PATCHES.md +0 -12
  445. package/vendor/pi-tui/PROVENANCE.md +0 -12
  446. package/vendor/pi-tui/README.upstream.md +0 -854
  447. package/vendor/pi-tui/native/win32/prebuilds/win32-arm64/win32-console-mode.node +0 -0
  448. package/vendor/pi-tui/native/win32/prebuilds/win32-x64/win32-console-mode.node +0 -0
  449. package/vendor/pi-tui/src/alt-screen-search.ts +0 -158
  450. package/vendor/pi-tui/src/autocomplete.ts +0 -827
  451. package/vendor/pi-tui/src/components/alt-screen-flash.ts +0 -52
  452. package/vendor/pi-tui/src/components/box.ts +0 -138
  453. package/vendor/pi-tui/src/components/cancellable-loader.ts +0 -41
  454. package/vendor/pi-tui/src/components/editor.ts +0 -2364
  455. package/vendor/pi-tui/src/components/h-stack.ts +0 -45
  456. package/vendor/pi-tui/src/components/image.ts +0 -128
  457. package/vendor/pi-tui/src/components/input.ts +0 -448
  458. package/vendor/pi-tui/src/components/loader.ts +0 -93
  459. package/vendor/pi-tui/src/components/markdown.ts +0 -1016
  460. package/vendor/pi-tui/src/components/scroll-view.ts +0 -217
  461. package/vendor/pi-tui/src/components/select-list.ts +0 -230
  462. package/vendor/pi-tui/src/components/settings-list.ts +0 -277
  463. package/vendor/pi-tui/src/components/spacer.ts +0 -29
  464. package/vendor/pi-tui/src/components/stack.ts +0 -155
  465. package/vendor/pi-tui/src/components/text.ts +0 -108
  466. package/vendor/pi-tui/src/components/truncated-text.ts +0 -66
  467. package/vendor/pi-tui/src/components/v-stack.ts +0 -34
  468. package/vendor/pi-tui/src/editor-component.ts +0 -75
  469. package/vendor/pi-tui/src/fuzzy.ts +0 -138
  470. package/vendor/pi-tui/src/index.ts +0 -149
  471. package/vendor/pi-tui/src/keybindings.ts +0 -321
  472. package/vendor/pi-tui/src/keys.ts +0 -1402
  473. package/vendor/pi-tui/src/kill-ring.ts +0 -47
  474. package/vendor/pi-tui/src/latex.ts +0 -1381
  475. package/vendor/pi-tui/src/layout-node.ts +0 -52
  476. package/vendor/pi-tui/src/layout.ts +0 -411
  477. package/vendor/pi-tui/src/native-modifiers.ts +0 -60
  478. package/vendor/pi-tui/src/native-module-path.ts +0 -32
  479. package/vendor/pi-tui/src/stdin-buffer.ts +0 -445
  480. package/vendor/pi-tui/src/terminal-colors.ts +0 -74
  481. package/vendor/pi-tui/src/terminal-image.ts +0 -701
  482. package/vendor/pi-tui/src/terminal.ts +0 -554
  483. package/vendor/pi-tui/src/tui-alt-screen.ts +0 -1379
  484. package/vendor/pi-tui/src/tui-main-screen.ts +0 -655
  485. package/vendor/pi-tui/src/tui.ts +0 -1264
  486. package/vendor/pi-tui/src/undo-stack.ts +0 -29
  487. package/vendor/pi-tui/src/utils.ts +0 -1327
  488. package/vendor/pi-tui/src/word-navigation.ts +0 -118
  489. package/vendor/pi-tui/test/test-themes.ts +0 -39
  490. package/vendor/pi-tui/test/virtual-terminal.ts +0 -219
  491. /package/{src/providers → dist/cli}/models-index.json +0 -0
@@ -1,1264 +0,0 @@
1
- // @ts-nocheck -- vendored by rovecode: upstream-checked at pinned SHA 853a80d2; see ../PATCHES.md
2
- /**
3
- * Minimal TUI implementation with differential rendering
4
- */
5
-
6
- import * as os from "node:os";
7
- import * as path from "node:path";
8
- import { performance } from "node:perf_hooks";
9
- import { isKeyRelease, matchesKey } from "./keys.ts";
10
- import type { Terminal } from "./terminal.ts";
11
- import {
12
- isOsc11BackgroundColorResponse,
13
- parseOsc11BackgroundColor,
14
- parseTerminalColorSchemeReport,
15
- type RgbColor,
16
- type TerminalColorScheme,
17
- } from "./terminal-colors.ts";
18
- import { getCapabilities, isImageLine, setCellDimensions } from "./terminal-image.ts";
19
- import { extractSegments, normalizeTerminalOutput, sliceByColumn, sliceWithWidth, visibleWidth } from "./utils.ts";
20
-
21
- /**
22
- * Component interface - all components must implement this
23
- */
24
- export interface Component {
25
- /**
26
- * Render the component to lines for the given viewport width
27
- * @param width - Current viewport width
28
- * @returns Array of strings, each representing a line
29
- */
30
- render(width: number): string[];
31
-
32
- /**
33
- * Optional handler for keyboard input when component has focus
34
- */
35
- handleInput?(data: string): void;
36
-
37
- /**
38
- * If true, component receives key release events (Kitty protocol).
39
- * Default is false - release events are filtered out.
40
- */
41
- wantsKeyRelease?: boolean;
42
-
43
- /**
44
- * Invalidate any cached rendering state.
45
- * Called when theme changes or when component needs to re-render from scratch.
46
- */
47
- invalidate(): void;
48
- }
49
-
50
- export type TuiInputListenerResult = { consume?: boolean; data?: string } | undefined;
51
- export type TuiInputListener = (data: string) => TuiInputListenerResult;
52
- type PendingOsc11BackgroundQuery = {
53
- settled: boolean;
54
- resolve: ((rgb: RgbColor | undefined) => void) | undefined;
55
- timer: NodeJS.Timeout | undefined;
56
- };
57
-
58
- /**
59
- * Interface for components that can receive focus and display a hardware cursor.
60
- * When focused, the component should emit CURSOR_MARKER at the cursor position
61
- * in its render output. TUI will find this marker and position the hardware
62
- * cursor there for proper IME candidate window positioning.
63
- */
64
- export interface Focusable {
65
- /** Set by TUI when focus changes. Component should emit CURSOR_MARKER when true. */
66
- focused: boolean;
67
- }
68
-
69
- /** Type guard to check if a component implements Focusable */
70
- export function isFocusable(component: Component | null): component is Component & Focusable {
71
- return component !== null && "focused" in component;
72
- }
73
-
74
- /**
75
- * Cursor position marker - APC (Application Program Command) sequence.
76
- * This is a zero-width escape sequence that terminals ignore.
77
- * Components emit this at the cursor position when focused.
78
- * TUI finds and strips this marker, then positions the hardware cursor there.
79
- */
80
- export const CURSOR_MARKER = "\x1b_pi:c\x07";
81
-
82
- export { visibleWidth };
83
-
84
- /**
85
- * Anchor position for overlays
86
- */
87
- export type OverlayAnchor =
88
- | "center"
89
- | "top-left"
90
- | "top-right"
91
- | "bottom-left"
92
- | "bottom-right"
93
- | "top-center"
94
- | "bottom-center"
95
- | "left-center"
96
- | "right-center";
97
-
98
- /**
99
- * Margin configuration for overlays
100
- */
101
- export interface OverlayMargin {
102
- top?: number;
103
- right?: number;
104
- bottom?: number;
105
- left?: number;
106
- }
107
-
108
- /** Value that can be absolute (number) or percentage (string like "50%") */
109
- export type SizeValue = number | `${number}%`;
110
-
111
- /** Parse a SizeValue into absolute value given a reference size */
112
- function parseSizeValue(value: SizeValue | undefined, referenceSize: number): number | undefined {
113
- if (value === undefined) return undefined;
114
- if (typeof value === "number") return value;
115
- // Parse percentage string like "50%"
116
- const match = value.match(/^(\d+(?:\.\d+)?)%$/);
117
- if (match) {
118
- return Math.floor((referenceSize * parseFloat(match[1])) / 100);
119
- }
120
- return undefined;
121
- }
122
-
123
- /**
124
- * Options for overlay positioning and sizing.
125
- * Values can be absolute numbers or percentage strings (e.g., "50%").
126
- */
127
- export interface OverlayOptions {
128
- // === Sizing ===
129
- /** Width in columns, or percentage of terminal width (e.g., "50%") */
130
- width?: SizeValue;
131
- /** Minimum width in columns */
132
- minWidth?: number;
133
- /** Maximum height in rows, or percentage of terminal height (e.g., "50%") */
134
- maxHeight?: SizeValue;
135
-
136
- // === Positioning - anchor-based ===
137
- /** Anchor point for positioning (default: 'center') */
138
- anchor?: OverlayAnchor;
139
- /** Horizontal offset from anchor position (positive = right) */
140
- offsetX?: number;
141
- /** Vertical offset from anchor position (positive = down) */
142
- offsetY?: number;
143
-
144
- // === Positioning - percentage or absolute ===
145
- /** Row position: absolute number, or percentage (e.g., "25%" = 25% from top) */
146
- row?: SizeValue;
147
- /** Column position: absolute number, or percentage (e.g., "50%" = centered horizontally) */
148
- col?: SizeValue;
149
-
150
- // === Margin from terminal edges ===
151
- /** Margin from terminal edges. Number applies to all sides. */
152
- margin?: OverlayMargin | number;
153
-
154
- // === Visibility ===
155
- /**
156
- * Control overlay visibility based on terminal dimensions.
157
- * If provided, overlay is only rendered when this returns true.
158
- * Called each render cycle with current terminal dimensions.
159
- */
160
- visible?: (termWidth: number, termHeight: number) => boolean;
161
- /** If true, don't capture keyboard focus when shown */
162
- nonCapturing?: boolean;
163
- }
164
-
165
- /** Options for {@link OverlayHandle.unfocus}. */
166
- export interface OverlayUnfocusOptions {
167
- /** Explicit target to focus after releasing this overlay. */
168
- target: Component | null;
169
- }
170
-
171
- /**
172
- * Handle returned by showOverlay for controlling the overlay
173
- */
174
- export interface OverlayHandle {
175
- /** Permanently remove the overlay (cannot be shown again) */
176
- hide(): void;
177
- /** Temporarily hide or show the overlay */
178
- setHidden(hidden: boolean): void;
179
- /** Check if overlay is temporarily hidden */
180
- isHidden(): boolean;
181
- /** Focus this overlay and bring it to the visual front */
182
- focus(): void;
183
- /** Release focus to the next visible capturing overlay or previous target, or to an explicit target when provided */
184
- unfocus(options?: OverlayUnfocusOptions): void;
185
- /** Check if this overlay currently has focus */
186
- isFocused(): boolean;
187
- }
188
-
189
- type OverlayStackEntry = {
190
- component: Component;
191
- options?: OverlayOptions;
192
- preFocus: Component | null;
193
- hidden: boolean;
194
- focusOrder: number;
195
- };
196
-
197
- type OverlayBlockedFocusResume = { status: "restore-overlay" } | { status: "focus-target"; target: Component | null };
198
- type EligibleOverlayFocusRestoreState = { status: "eligible"; overlay: OverlayStackEntry };
199
- type BlockedOverlayFocusRestoreState = {
200
- status: "blocked";
201
- overlay: OverlayStackEntry;
202
- blockedBy: Component;
203
- resume: OverlayBlockedFocusResume;
204
- };
205
- type ActiveOverlayFocusRestoreState = EligibleOverlayFocusRestoreState | BlockedOverlayFocusRestoreState;
206
- type OverlayFocusRestoreState = { status: "inactive" } | ActiveOverlayFocusRestoreState;
207
- type OverlayFocusRestorePolicy = "clear" | "preserve";
208
-
209
- /**
210
- * Container - a component that contains other components
211
- */
212
- export class Container implements Component {
213
- children: Component[] = [];
214
-
215
- addChild(component: Component): void {
216
- this.children.push(component);
217
- }
218
-
219
- removeChild(component: Component): void {
220
- const index = this.children.indexOf(component);
221
- if (index !== -1) {
222
- this.children.splice(index, 1);
223
- }
224
- }
225
-
226
- clear(): void {
227
- this.children = [];
228
- }
229
-
230
- invalidate(): void {
231
- for (const child of this.children) {
232
- child.invalidate?.();
233
- }
234
- }
235
-
236
- render(width: number): string[] {
237
- const lines: string[] = [];
238
- for (const child of this.children) {
239
- const childLines = child.render(width);
240
- for (const line of childLines) {
241
- lines.push(line);
242
- }
243
- }
244
- return lines;
245
- }
246
- }
247
-
248
- /**
249
- * TUI - Main class for managing terminal UI with differential rendering
250
- */
251
- const SEGMENT_RESET = "\x1b[0m\x1b]8;;\x07";
252
-
253
- /** Composite overlay content into a terminal line at a fixed column. */
254
- export function compositeTuiLine(
255
- baseLine: string,
256
- overlayLine: string,
257
- startCol: number,
258
- overlayWidth: number,
259
- totalWidth: number,
260
- ): string {
261
- if (isImageLine(baseLine)) return baseLine;
262
-
263
- const afterStart = startCol + overlayWidth;
264
- const base = extractSegments(baseLine, startCol, afterStart, totalWidth - afterStart, true);
265
- const overlay = sliceWithWidth(overlayLine, 0, overlayWidth, true);
266
- const beforePad = Math.max(0, startCol - base.beforeWidth);
267
- const overlayPad = Math.max(0, overlayWidth - overlay.width);
268
- const actualBeforeWidth = Math.max(startCol, base.beforeWidth);
269
- const actualOverlayWidth = Math.max(overlayWidth, overlay.width);
270
- const afterTarget = Math.max(0, totalWidth - actualBeforeWidth - actualOverlayWidth);
271
- const afterPad = Math.max(0, afterTarget - base.afterWidth);
272
- const result =
273
- base.before +
274
- " ".repeat(beforePad) +
275
- SEGMENT_RESET +
276
- overlay.text +
277
- " ".repeat(overlayPad) +
278
- SEGMENT_RESET +
279
- base.after +
280
- " ".repeat(afterPad);
281
-
282
- return visibleWidth(result) <= totalWidth ? result : sliceByColumn(result, 0, totalWidth, true);
283
- }
284
-
285
- export type TuiMode = "regular" | "fullscreen";
286
-
287
- export interface TuiStopOptions {
288
- /** Leave renderer output in place for another TUI taking over the same terminal. */
289
- preserveScreen?: boolean;
290
- }
291
-
292
- export interface TUI extends Component {
293
- readonly mode: TuiMode;
294
- children: Component[];
295
- terminal: Terminal;
296
- onDebug?: () => void;
297
- readonly fullRedraws: number;
298
- addChild(component: Component): void;
299
- removeChild(component: Component): void;
300
- clear(): void;
301
- getShowHardwareCursor(): boolean;
302
- setShowHardwareCursor(enabled: boolean): void;
303
- getClearOnShrink(): boolean;
304
- setClearOnShrink(enabled: boolean): void;
305
- setFocus(component: Component | null): void;
306
- showOverlay(component: Component, options?: OverlayOptions): OverlayHandle;
307
- hideOverlay(): void;
308
- hasOverlay(): boolean;
309
- start(): void;
310
- stop(options?: TuiStopOptions): void;
311
- renderNow(force?: boolean): void;
312
- requestRender(force?: boolean): void;
313
- addInputListener(listener: TuiInputListener): () => void;
314
- removeInputListener(listener: TuiInputListener): void;
315
- onTerminalColorSchemeChange(listener: (scheme: TerminalColorScheme) => void): () => void;
316
- setTerminalColorSchemeNotifications(enabled: boolean): void;
317
- queryTerminalBackgroundColor(options: { timeoutMs: number }): Promise<RgbColor | undefined>;
318
- queryTerminalColorScheme(options: { timeoutMs: number }): Promise<TerminalColorScheme | undefined>;
319
- }
320
-
321
- export const VIEWPORT_TUI = Symbol.for("@earendil-works/pi-tui/viewport");
322
-
323
- export interface ViewportTUI extends TUI {
324
- readonly [VIEWPORT_TUI]: true;
325
- setLayoutRoot(component: Component | undefined): void;
326
- }
327
-
328
- export function isViewportTUI(tui: TUI): tui is ViewportTUI {
329
- return (tui as Partial<ViewportTUI>)[VIEWPORT_TUI] === true;
330
- }
331
-
332
- export abstract class TuiBase extends Container implements TUI {
333
- abstract readonly mode: TuiMode;
334
- public terminal: Terminal;
335
- private focusedComponent: Component | null = null;
336
- private inputListeners = new Set<TuiInputListener>();
337
-
338
- /** Global callback for debug key (Shift+Ctrl+D). Called before input is forwarded to focused component. */
339
- public onDebug?: () => void;
340
- private renderRequested = false;
341
- private immediateRenderScheduled = false;
342
- private renderTimer: NodeJS.Timeout | undefined;
343
- private lastRenderAt = 0;
344
- private static readonly MIN_RENDER_INTERVAL_MS = 16;
345
- private showHardwareCursor = process.env.PI_HARDWARE_CURSOR === "1";
346
- private clearOnShrink = process.env.PI_CLEAR_ON_SHRINK === "1";
347
- protected fullRedrawCount = 0;
348
- protected stopped = false;
349
- private pendingOsc11BackgroundReplies = 0;
350
- private pendingOsc11BackgroundQueries: PendingOsc11BackgroundQuery[] = [];
351
- private terminalColorSchemeListeners = new Set<(scheme: TerminalColorScheme) => void>();
352
- private terminalColorSchemeNotificationsEnabled = false;
353
- protected readonly logDirectory: string;
354
-
355
- // Overlay stack for modal components rendered on top of base content
356
- private focusOrderCounter = 0;
357
- private overlayStack: OverlayStackEntry[] = [];
358
-
359
- get hasOverlayEntries(): boolean {
360
- return this.overlayStack.length > 0;
361
- }
362
- private overlayFocusRestore: OverlayFocusRestoreState = { status: "inactive" };
363
-
364
- constructor(terminal: Terminal, showHardwareCursor?: boolean, logDirectory?: string) {
365
- super();
366
- this.terminal = terminal;
367
- this.logDirectory = logDirectory ?? process.env.PI_CODING_AGENT_DIR ?? path.join(os.homedir(), ".pi", "agent");
368
- if (showHardwareCursor !== undefined) {
369
- this.showHardwareCursor = showHardwareCursor;
370
- }
371
- }
372
-
373
- protected abstract doRender(): void;
374
-
375
- protected resetRenderState(): void {}
376
-
377
- protected beforeTerminalStart(): void {}
378
-
379
- protected afterTerminalStart(): void {}
380
-
381
- protected beforeTerminalStop(_options: TuiStopOptions): void {}
382
-
383
- protected afterTerminalStop(_options: TuiStopOptions): void {}
384
-
385
- get fullRedraws(): number {
386
- return this.fullRedrawCount;
387
- }
388
-
389
- getShowHardwareCursor(): boolean {
390
- return this.showHardwareCursor;
391
- }
392
-
393
- setShowHardwareCursor(enabled: boolean): void {
394
- if (this.showHardwareCursor === enabled) return;
395
- this.showHardwareCursor = enabled;
396
- if (!enabled) {
397
- this.terminal.hideCursor();
398
- }
399
- this.requestRender();
400
- }
401
-
402
- getClearOnShrink(): boolean {
403
- return this.clearOnShrink;
404
- }
405
-
406
- /**
407
- * Set whether to trigger full re-render when content shrinks.
408
- * When true (default), empty rows are cleared when content shrinks.
409
- * When false, empty rows remain (reduces redraws on slower terminals).
410
- */
411
- setClearOnShrink(enabled: boolean): void {
412
- this.clearOnShrink = enabled;
413
- }
414
-
415
- getFocusedComponent(): Component | null {
416
- return this.focusedComponent;
417
- }
418
-
419
- setFocus(component: Component | null): void {
420
- this.setFocusInternal({ component, overlayFocusRestore: "clear" });
421
- }
422
-
423
- private setFocusInternal({
424
- component,
425
- overlayFocusRestore,
426
- }: {
427
- component: Component | null;
428
- overlayFocusRestore: OverlayFocusRestorePolicy;
429
- }): void {
430
- const previousFocus = this.focusedComponent;
431
- let nextFocus = component;
432
- const previousFocusedOverlay = previousFocus
433
- ? this.overlayStack.find((entry) => entry.component === previousFocus && this.isOverlayVisible(entry))
434
- : undefined;
435
- const nextFocusIsOverlay = nextFocus ? this.overlayStack.some((entry) => entry.component === nextFocus) : false;
436
- const restoreState = this.getVisibleOverlayFocusRestore();
437
- if (nextFocus && !nextFocusIsOverlay) {
438
- if (restoreState.status === "blocked" && restoreState.blockedBy === previousFocus) {
439
- if (restoreState.resume.status === "focus-target" || !this.isComponentMounted(restoreState.blockedBy)) {
440
- nextFocus = this.resolveBlockedOverlayFocusResume(restoreState);
441
- } else {
442
- this.overlayFocusRestore = {
443
- status: "blocked",
444
- overlay: restoreState.overlay,
445
- blockedBy: nextFocus,
446
- resume: restoreState.resume,
447
- };
448
- }
449
- } else if (
450
- previousFocusedOverlay &&
451
- restoreState.status !== "inactive" &&
452
- restoreState.overlay === previousFocusedOverlay &&
453
- !this.isOverlayFocusAncestor(previousFocusedOverlay, nextFocus)
454
- ) {
455
- this.overlayFocusRestore = {
456
- status: "blocked",
457
- overlay: previousFocusedOverlay,
458
- blockedBy: nextFocus,
459
- resume: { status: "restore-overlay" },
460
- };
461
- }
462
- } else if (nextFocus === null) {
463
- if (restoreState.status === "blocked" && restoreState.blockedBy === previousFocus) {
464
- nextFocus = this.resolveBlockedOverlayFocusResume(restoreState);
465
- } else if (overlayFocusRestore === "clear") {
466
- this.clearOverlayFocusRestore();
467
- }
468
- }
469
-
470
- if (isFocusable(this.focusedComponent)) {
471
- this.focusedComponent.focused = false;
472
- }
473
-
474
- this.focusedComponent = nextFocus;
475
-
476
- if (isFocusable(nextFocus)) {
477
- nextFocus.focused = true;
478
- }
479
-
480
- const focusedOverlay = nextFocus
481
- ? this.overlayStack.find((entry) => entry.component === nextFocus && this.isOverlayVisible(entry))
482
- : undefined;
483
- if (focusedOverlay) {
484
- this.overlayFocusRestore = { status: "eligible", overlay: focusedOverlay };
485
- }
486
- }
487
-
488
- private clearOverlayFocusRestore(): void {
489
- this.overlayFocusRestore = { status: "inactive" };
490
- }
491
-
492
- private clearOverlayFocusRestoreFor(overlay: OverlayStackEntry): void {
493
- if (this.overlayFocusRestore.status !== "inactive" && this.overlayFocusRestore.overlay === overlay) {
494
- this.clearOverlayFocusRestore();
495
- }
496
- }
497
-
498
- private resolveBlockedOverlayFocusResume(restoreState: BlockedOverlayFocusRestoreState): Component | null {
499
- if (restoreState.resume.status === "restore-overlay") return restoreState.overlay.component;
500
- this.clearOverlayFocusRestore();
501
- return restoreState.resume.target;
502
- }
503
-
504
- private getVisibleOverlayFocusRestore(): OverlayFocusRestoreState {
505
- const restoreState = this.overlayFocusRestore;
506
- if (restoreState.status === "inactive") return restoreState;
507
- if (!this.overlayStack.includes(restoreState.overlay) || !this.isOverlayVisible(restoreState.overlay)) {
508
- return { status: "inactive" };
509
- }
510
- return restoreState;
511
- }
512
-
513
- private isOverlayFocusAncestor(entry: OverlayStackEntry, component: Component): boolean {
514
- const visited = new Set<Component>();
515
- let current = entry.preFocus;
516
- while (current && !visited.has(current)) {
517
- visited.add(current);
518
- if (current === component) return true;
519
- current = this.overlayStack.find((overlay) => overlay.component === current)?.preFocus ?? null;
520
- }
521
- return false;
522
- }
523
-
524
- private retargetOverlayPreFocus(removed: OverlayStackEntry): void {
525
- for (const overlay of this.overlayStack) {
526
- if (overlay !== removed && overlay.preFocus === removed.component) {
527
- overlay.preFocus = removed.preFocus;
528
- }
529
- }
530
- }
531
-
532
- protected getMountedRoots(): readonly Component[] {
533
- return this.children;
534
- }
535
-
536
- private isComponentMounted(component: Component): boolean {
537
- return this.getMountedRoots().some((child) => this.containsComponent(child, component));
538
- }
539
-
540
- private containsComponent(root: Component, target: Component): boolean {
541
- if (root === target) return true;
542
- if (!(root instanceof Container)) return false;
543
- return root.children.some((child) => this.containsComponent(child, target));
544
- }
545
-
546
- /**
547
- * Show an overlay component with configurable positioning and sizing.
548
- * Returns a handle to control the overlay's visibility.
549
- */
550
- showOverlay(component: Component, options?: OverlayOptions): OverlayHandle {
551
- const entry: OverlayStackEntry = {
552
- component,
553
- ...(options === undefined ? {} : { options }),
554
- preFocus: this.focusedComponent,
555
- hidden: false,
556
- focusOrder: ++this.focusOrderCounter,
557
- };
558
- this.overlayStack.push(entry);
559
- // Only focus if overlay is actually visible
560
- if (!options?.nonCapturing && this.isOverlayVisible(entry)) {
561
- this.setFocus(component);
562
- }
563
- this.terminal.hideCursor();
564
- this.requestRender();
565
-
566
- // Return handle for controlling this overlay
567
- return {
568
- hide: () => {
569
- const index = this.overlayStack.indexOf(entry);
570
- if (index !== -1) {
571
- this.clearOverlayFocusRestoreFor(entry);
572
- this.retargetOverlayPreFocus(entry);
573
- this.overlayStack.splice(index, 1);
574
- // Restore focus if this overlay had focus
575
- if (this.focusedComponent === component) {
576
- const topVisible = this.getTopmostVisibleOverlay();
577
- this.setFocus(topVisible?.component ?? entry.preFocus);
578
- }
579
- if (this.overlayStack.length === 0) this.terminal.hideCursor();
580
- this.requestRender();
581
- }
582
- },
583
- setHidden: (hidden: boolean) => {
584
- if (entry.hidden === hidden) return;
585
- entry.hidden = hidden;
586
- // Update focus when hiding/showing
587
- if (hidden) {
588
- this.clearOverlayFocusRestoreFor(entry);
589
- // If this overlay had focus, move focus to next visible or preFocus
590
- if (this.focusedComponent === component) {
591
- const topVisible = this.getTopmostVisibleOverlay();
592
- this.setFocus(topVisible?.component ?? entry.preFocus);
593
- }
594
- } else {
595
- // Restore focus to this overlay when showing (if it's actually visible)
596
- if (!options?.nonCapturing && this.isOverlayVisible(entry)) {
597
- entry.focusOrder = ++this.focusOrderCounter;
598
- this.setFocus(component);
599
- }
600
- }
601
- this.requestRender();
602
- },
603
- isHidden: () => entry.hidden,
604
- focus: () => {
605
- if (!this.overlayStack.includes(entry) || !this.isOverlayVisible(entry)) return;
606
- entry.focusOrder = ++this.focusOrderCounter;
607
- this.setFocus(component);
608
- this.requestRender();
609
- },
610
- unfocus: (unfocusOptions) => {
611
- const isFocused = this.focusedComponent === component;
612
- const restoreState = this.overlayFocusRestore;
613
- const hasPendingRestore = restoreState.status !== "inactive" && restoreState.overlay === entry;
614
- if (!isFocused && !hasPendingRestore) return;
615
- if (
616
- restoreState.status === "blocked" &&
617
- restoreState.overlay === entry &&
618
- this.focusedComponent === restoreState.blockedBy
619
- ) {
620
- if (unfocusOptions) {
621
- this.overlayFocusRestore = {
622
- status: "blocked",
623
- overlay: entry,
624
- blockedBy: restoreState.blockedBy,
625
- resume: { status: "focus-target", target: unfocusOptions.target },
626
- };
627
- } else {
628
- this.clearOverlayFocusRestore();
629
- }
630
- this.requestRender();
631
- return;
632
- }
633
- this.clearOverlayFocusRestoreFor(entry);
634
- if (isFocused || unfocusOptions) {
635
- const topVisible = this.getTopmostVisibleOverlay();
636
- const fallbackTarget = topVisible && topVisible !== entry ? topVisible.component : entry.preFocus;
637
- this.setFocus(unfocusOptions ? unfocusOptions.target : fallbackTarget);
638
- }
639
- this.requestRender();
640
- },
641
- isFocused: () => this.focusedComponent === component,
642
- };
643
- }
644
-
645
- /** Hide the topmost overlay and restore previous focus. */
646
- hideOverlay(): void {
647
- const overlay = this.overlayStack[this.overlayStack.length - 1];
648
- if (!overlay) return;
649
- this.clearOverlayFocusRestoreFor(overlay);
650
- this.retargetOverlayPreFocus(overlay);
651
- this.overlayStack.pop();
652
- if (this.focusedComponent === overlay.component) {
653
- // Find topmost visible overlay, or fall back to preFocus
654
- const topVisible = this.getTopmostVisibleOverlay();
655
- this.setFocus(topVisible?.component ?? overlay.preFocus);
656
- }
657
- if (this.overlayStack.length === 0) this.terminal.hideCursor();
658
- this.requestRender();
659
- }
660
-
661
- /** Check if there are any visible overlays */
662
- hasOverlay(): boolean {
663
- return this.overlayStack.some((o) => this.isOverlayVisible(o));
664
- }
665
-
666
- /** Check if the focused component is a visible overlay */
667
- protected isOverlayFocused(): boolean {
668
- return this.overlayStack.some(
669
- (entry) => entry.component === this.focusedComponent && this.isOverlayVisible(entry),
670
- );
671
- }
672
-
673
- /** Check if an overlay entry is currently visible */
674
- private isOverlayVisible(entry: OverlayStackEntry): boolean {
675
- if (entry.hidden) return false;
676
- if (entry.options?.visible) {
677
- return entry.options.visible(this.terminal.columns, this.terminal.rows);
678
- }
679
- return true;
680
- }
681
-
682
- /** Find the visual-frontmost visible capturing overlay, if any */
683
- private getTopmostVisibleOverlay(): OverlayStackEntry | undefined {
684
- let topmost: OverlayStackEntry | undefined;
685
- for (const overlay of this.overlayStack) {
686
- if (overlay.options?.nonCapturing || !this.isOverlayVisible(overlay)) continue;
687
- if (!topmost || overlay.focusOrder > topmost.focusOrder) {
688
- topmost = overlay;
689
- }
690
- }
691
- return topmost;
692
- }
693
-
694
- override invalidate(): void {
695
- for (const root of this.getMountedRoots()) root.invalidate();
696
- for (const overlay of this.overlayStack) overlay.component.invalidate();
697
- }
698
-
699
- start(): void {
700
- this.stopped = false;
701
- this.beforeTerminalStart();
702
- this.terminal.start(
703
- (data) => this.handleTerminalInput(data),
704
- () => this.requestRender(),
705
- );
706
- this.afterTerminalStart();
707
- this.terminal.hideCursor();
708
- if (this.terminalColorSchemeNotificationsEnabled) {
709
- this.terminal.write("\x1b[?2031h");
710
- }
711
- this.queryCellSize();
712
- this.requestRender();
713
- }
714
-
715
- addInputListener(listener: TuiInputListener): () => void {
716
- this.inputListeners.add(listener);
717
- return () => {
718
- this.inputListeners.delete(listener);
719
- };
720
- }
721
-
722
- removeInputListener(listener: TuiInputListener): void {
723
- this.inputListeners.delete(listener);
724
- }
725
-
726
- onTerminalColorSchemeChange(listener: (scheme: TerminalColorScheme) => void): () => void {
727
- this.terminalColorSchemeListeners.add(listener);
728
- return () => {
729
- this.terminalColorSchemeListeners.delete(listener);
730
- };
731
- }
732
-
733
- setTerminalColorSchemeNotifications(enabled: boolean): void {
734
- if (this.terminalColorSchemeNotificationsEnabled === enabled) {
735
- return;
736
- }
737
- this.terminalColorSchemeNotificationsEnabled = enabled;
738
- if (!this.stopped) {
739
- this.terminal.write(enabled ? "\x1b[?2031h" : "\x1b[?2031l");
740
- }
741
- }
742
-
743
- private queryCellSize(): void {
744
- // Only query if terminal supports images (cell size is only used for image rendering)
745
- if (!getCapabilities().images) {
746
- return;
747
- }
748
- // Query terminal for cell size in pixels: CSI 16 t
749
- // Response format: CSI 6 ; height ; width t
750
- this.terminal.write("\x1b[16t");
751
- }
752
-
753
- stop(options: TuiStopOptions = {}): void {
754
- this.stopped = true;
755
- this.cancelRenderTimer();
756
- if (this.terminalColorSchemeNotificationsEnabled) {
757
- this.terminal.write("\x1b[?2031l");
758
- }
759
- this.beforeTerminalStop(options);
760
- this.terminal.showCursor();
761
- this.terminal.stop();
762
- this.afterTerminalStop(options);
763
- }
764
-
765
- renderNow(force = false): void {
766
- if (force) this.resetRenderState();
767
- this.renderRequested = false;
768
- this.cancelRenderTimer();
769
- this.lastRenderAt = performance.now();
770
- this.doRender();
771
- }
772
-
773
- requestRender(force = false): void {
774
- if (force) {
775
- this.resetRenderState();
776
- this.requestImmediateRender();
777
- return;
778
- }
779
- if (this.renderRequested) return;
780
- this.renderRequested = true;
781
- process.nextTick(() => this.scheduleRender());
782
- }
783
-
784
- private requestImmediateRender(): void {
785
- this.cancelRenderTimer();
786
- this.renderRequested = true;
787
- if (this.immediateRenderScheduled) return;
788
- this.immediateRenderScheduled = true;
789
- process.nextTick(() => {
790
- this.immediateRenderScheduled = false;
791
- if (this.stopped || !this.renderRequested) return;
792
- // A previously queued scheduleRender() can create a timer before this
793
- // callback runs. User input must preempt that throttled frame.
794
- this.cancelRenderTimer();
795
- this.renderRequested = false;
796
- this.lastRenderAt = performance.now();
797
- this.doRender();
798
- });
799
- }
800
-
801
- private cancelRenderTimer(): void {
802
- if (!this.renderTimer) return;
803
- clearTimeout(this.renderTimer);
804
- this.renderTimer = undefined;
805
- }
806
-
807
- private scheduleRender(): void {
808
- if (this.stopped || this.renderTimer || !this.renderRequested) {
809
- return;
810
- }
811
- const elapsed = performance.now() - this.lastRenderAt;
812
- const delay = Math.max(0, TuiBase.MIN_RENDER_INTERVAL_MS - elapsed);
813
- this.renderTimer = setTimeout(() => {
814
- this.renderTimer = undefined;
815
- if (this.stopped || !this.renderRequested) {
816
- return;
817
- }
818
- this.renderRequested = false;
819
- this.lastRenderAt = performance.now();
820
- this.doRender();
821
- if (this.renderRequested) {
822
- this.scheduleRender();
823
- }
824
- }, delay);
825
- }
826
-
827
- private handleTerminalInput(data: string): void {
828
- if (this.consumeOsc11BackgroundResponse(data)) {
829
- return;
830
- }
831
- if (this.consumeTerminalColorSchemeReport(data)) {
832
- return;
833
- }
834
-
835
- if (this.inputListeners.size > 0) {
836
- let current = data;
837
- for (const listener of this.inputListeners) {
838
- const result = listener(current);
839
- if (result?.consume) {
840
- return;
841
- }
842
- if (result?.data !== undefined) {
843
- current = result.data;
844
- }
845
- }
846
- if (current.length === 0) {
847
- return;
848
- }
849
- data = current;
850
- }
851
-
852
- // Consume terminal cell size responses without blocking unrelated input.
853
- if (this.consumeCellSizeResponse(data)) {
854
- return;
855
- }
856
-
857
- // Global debug key handler (Shift+Ctrl+D)
858
- if (matchesKey(data, "shift+ctrl+d") && this.onDebug) {
859
- this.onDebug();
860
- return;
861
- }
862
-
863
- // If focused component is an overlay, verify it's still visible
864
- // (visibility can change due to terminal resize or visible() callback)
865
- const focusedOverlay = this.overlayStack.find((o) => o.component === this.focusedComponent);
866
- if (focusedOverlay && !this.isOverlayVisible(focusedOverlay)) {
867
- // Focused overlay is no longer visible, redirect to topmost visible overlay
868
- const topVisible = this.getTopmostVisibleOverlay();
869
- if (topVisible) {
870
- this.setFocus(topVisible.component);
871
- } else {
872
- this.setFocusInternal({ component: focusedOverlay.preFocus, overlayFocusRestore: "preserve" });
873
- }
874
- }
875
-
876
- const focusIsOverlay = this.overlayStack.some((o) => o.component === this.focusedComponent);
877
- if (!focusIsOverlay) {
878
- const restoreState = this.getVisibleOverlayFocusRestore();
879
- if (restoreState.status === "eligible") {
880
- this.setFocus(restoreState.overlay.component);
881
- } else if (restoreState.status === "blocked" && restoreState.blockedBy !== this.focusedComponent) {
882
- if (restoreState.resume.status === "restore-overlay") {
883
- this.setFocus(restoreState.overlay.component);
884
- } else {
885
- this.clearOverlayFocusRestore();
886
- this.setFocus(restoreState.resume.target);
887
- }
888
- }
889
- }
890
-
891
- // Pass input to focused component (including Ctrl+C)
892
- // The focused component can decide how to handle Ctrl+C
893
- if (this.focusedComponent?.handleInput) {
894
- // Filter out key release events unless component opts in
895
- if (isKeyRelease(data) && !this.focusedComponent.wantsKeyRelease) {
896
- return;
897
- }
898
- this.focusedComponent.handleInput(data);
899
- // Keyboard input is latency-sensitive. Avoid the throttled timer path,
900
- // where even setTimeout(0) can take a full 16 ms tick on Windows.
901
- this.requestImmediateRender();
902
- }
903
- }
904
-
905
- private consumeOsc11BackgroundResponse(data: string): boolean {
906
- if (this.pendingOsc11BackgroundReplies <= 0) {
907
- return false;
908
- }
909
-
910
- if (!isOsc11BackgroundColorResponse(data)) {
911
- return false;
912
- }
913
-
914
- const rgb = parseOsc11BackgroundColor(data);
915
- this.pendingOsc11BackgroundReplies -= 1;
916
- const query = this.pendingOsc11BackgroundQueries.shift();
917
- if (query && !query.settled) {
918
- query.settled = true;
919
- if (query.timer) {
920
- clearTimeout(query.timer);
921
- query.timer = undefined;
922
- }
923
- query.resolve?.(rgb);
924
- query.resolve = undefined;
925
- }
926
- return true;
927
- }
928
-
929
- private consumeTerminalColorSchemeReport(data: string): boolean {
930
- const scheme = parseTerminalColorSchemeReport(data);
931
- if (!scheme) {
932
- return false;
933
- }
934
-
935
- for (const listener of this.terminalColorSchemeListeners) {
936
- listener(scheme);
937
- }
938
- return true;
939
- }
940
-
941
- private consumeCellSizeResponse(data: string): boolean {
942
- // Response format: ESC [ 6 ; height ; width t
943
- const match = data.match(/^\x1b\[6;(\d+);(\d+)t$/);
944
- if (!match) {
945
- return false;
946
- }
947
-
948
- const heightPx = parseInt(match[1], 10);
949
- const widthPx = parseInt(match[2], 10);
950
- if (heightPx <= 0 || widthPx <= 0) {
951
- return true;
952
- }
953
-
954
- setCellDimensions({ widthPx, heightPx });
955
- // Invalidate all components so images re-render with correct dimensions.
956
- this.invalidate();
957
- this.requestRender();
958
- return true;
959
- }
960
-
961
- /**
962
- * Resolve overlay layout from options.
963
- * Returns { width, row, col, maxHeight } for rendering.
964
- */
965
- private resolveOverlayLayout(
966
- options: OverlayOptions | undefined,
967
- overlayHeight: number,
968
- termWidth: number,
969
- termHeight: number,
970
- ): { width: number; row: number; col: number; maxHeight: number | undefined } {
971
- const opt = options ?? {};
972
-
973
- // Parse margin (clamp to non-negative)
974
- const margin =
975
- typeof opt.margin === "number"
976
- ? { top: opt.margin, right: opt.margin, bottom: opt.margin, left: opt.margin }
977
- : (opt.margin ?? {});
978
- const marginTop = Math.max(0, margin.top ?? 0);
979
- const marginRight = Math.max(0, margin.right ?? 0);
980
- const marginBottom = Math.max(0, margin.bottom ?? 0);
981
- const marginLeft = Math.max(0, margin.left ?? 0);
982
-
983
- // Available space after margins
984
- const availWidth = Math.max(1, termWidth - marginLeft - marginRight);
985
- const availHeight = Math.max(1, termHeight - marginTop - marginBottom);
986
-
987
- // === Resolve width ===
988
- let width = parseSizeValue(opt.width, termWidth) ?? Math.min(80, availWidth);
989
- // Apply minWidth
990
- if (opt.minWidth !== undefined) {
991
- width = Math.max(width, opt.minWidth);
992
- }
993
- // Clamp to available space
994
- width = Math.max(1, Math.min(width, availWidth));
995
-
996
- // === Resolve maxHeight ===
997
- let maxHeight = parseSizeValue(opt.maxHeight, termHeight);
998
- // Clamp to available space
999
- if (maxHeight !== undefined) {
1000
- maxHeight = Math.max(1, Math.min(maxHeight, availHeight));
1001
- }
1002
-
1003
- // Effective overlay height (may be clamped by maxHeight)
1004
- const effectiveHeight = maxHeight !== undefined ? Math.min(overlayHeight, maxHeight) : overlayHeight;
1005
-
1006
- // === Resolve position ===
1007
- let row: number;
1008
- let col: number;
1009
-
1010
- if (opt.row !== undefined) {
1011
- if (typeof opt.row === "string") {
1012
- // Percentage: 0% = top, 100% = bottom (overlay stays within bounds)
1013
- const match = opt.row.match(/^(\d+(?:\.\d+)?)%$/);
1014
- if (match) {
1015
- const maxRow = Math.max(0, availHeight - effectiveHeight);
1016
- const percent = parseFloat(match[1]) / 100;
1017
- row = marginTop + Math.floor(maxRow * percent);
1018
- } else {
1019
- // Invalid format, fall back to center
1020
- row = this.resolveAnchorRow("center", effectiveHeight, availHeight, marginTop);
1021
- }
1022
- } else {
1023
- // Absolute row position
1024
- row = opt.row;
1025
- }
1026
- } else {
1027
- // Anchor-based (default: center)
1028
- const anchor = opt.anchor ?? "center";
1029
- row = this.resolveAnchorRow(anchor, effectiveHeight, availHeight, marginTop);
1030
- }
1031
-
1032
- if (opt.col !== undefined) {
1033
- if (typeof opt.col === "string") {
1034
- // Percentage: 0% = left, 100% = right (overlay stays within bounds)
1035
- const match = opt.col.match(/^(\d+(?:\.\d+)?)%$/);
1036
- if (match) {
1037
- const maxCol = Math.max(0, availWidth - width);
1038
- const percent = parseFloat(match[1]) / 100;
1039
- col = marginLeft + Math.floor(maxCol * percent);
1040
- } else {
1041
- // Invalid format, fall back to center
1042
- col = this.resolveAnchorCol("center", width, availWidth, marginLeft);
1043
- }
1044
- } else {
1045
- // Absolute column position
1046
- col = opt.col;
1047
- }
1048
- } else {
1049
- // Anchor-based (default: center)
1050
- const anchor = opt.anchor ?? "center";
1051
- col = this.resolveAnchorCol(anchor, width, availWidth, marginLeft);
1052
- }
1053
-
1054
- // Apply offsets
1055
- if (opt.offsetY !== undefined) row += opt.offsetY;
1056
- if (opt.offsetX !== undefined) col += opt.offsetX;
1057
-
1058
- // Clamp to terminal bounds (respecting margins)
1059
- row = Math.max(marginTop, Math.min(row, termHeight - marginBottom - effectiveHeight));
1060
- col = Math.max(marginLeft, Math.min(col, termWidth - marginRight - width));
1061
-
1062
- return { width, row, col, maxHeight };
1063
- }
1064
-
1065
- private resolveAnchorRow(anchor: OverlayAnchor, height: number, availHeight: number, marginTop: number): number {
1066
- switch (anchor) {
1067
- case "top-left":
1068
- case "top-center":
1069
- case "top-right":
1070
- return marginTop;
1071
- case "bottom-left":
1072
- case "bottom-center":
1073
- case "bottom-right":
1074
- return marginTop + availHeight - height;
1075
- case "left-center":
1076
- case "center":
1077
- case "right-center":
1078
- return marginTop + Math.floor((availHeight - height) / 2);
1079
- }
1080
- }
1081
-
1082
- private resolveAnchorCol(anchor: OverlayAnchor, width: number, availWidth: number, marginLeft: number): number {
1083
- switch (anchor) {
1084
- case "top-left":
1085
- case "left-center":
1086
- case "bottom-left":
1087
- return marginLeft;
1088
- case "top-right":
1089
- case "right-center":
1090
- case "bottom-right":
1091
- return marginLeft + availWidth - width;
1092
- case "top-center":
1093
- case "center":
1094
- case "bottom-center":
1095
- return marginLeft + Math.floor((availWidth - width) / 2);
1096
- }
1097
- }
1098
-
1099
- /** Composite all overlays into content lines (sorted by focusOrder, higher = on top). */
1100
- protected compositeOverlays(lines: string[], termWidth: number, termHeight: number): string[] {
1101
- if (this.overlayStack.length === 0) return lines;
1102
- const result = [...lines];
1103
-
1104
- // Pre-render all visible overlays and calculate positions
1105
- const rendered: { overlayLines: string[]; row: number; col: number; w: number }[] = [];
1106
- let minLinesNeeded = result.length;
1107
-
1108
- const visibleEntries = this.overlayStack.filter((e) => this.isOverlayVisible(e));
1109
- visibleEntries.sort((a, b) => a.focusOrder - b.focusOrder);
1110
- for (const entry of visibleEntries) {
1111
- const { component, options } = entry;
1112
-
1113
- // Get layout with height=0 first to determine width and maxHeight
1114
- // (width and maxHeight don't depend on overlay height)
1115
- const { width, maxHeight } = this.resolveOverlayLayout(options, 0, termWidth, termHeight);
1116
-
1117
- // Render component at calculated width
1118
- let overlayLines = component.render(width);
1119
-
1120
- // Apply maxHeight if specified
1121
- if (maxHeight !== undefined && overlayLines.length > maxHeight) {
1122
- overlayLines = overlayLines.slice(0, maxHeight);
1123
- }
1124
-
1125
- // Get final row/col with actual overlay height
1126
- const { row, col } = this.resolveOverlayLayout(options, overlayLines.length, termWidth, termHeight);
1127
-
1128
- rendered.push({ overlayLines, row, col, w: width });
1129
- minLinesNeeded = Math.max(minLinesNeeded, row + overlayLines.length);
1130
- }
1131
-
1132
- // Pad to at least terminal height so overlays have screen-relative positions.
1133
- // Excludes maxLinesRendered: the historical high-water mark caused self-reinforcing
1134
- // inflation that pushed content into scrollback on terminal widen.
1135
- const workingHeight = Math.max(result.length, termHeight, minLinesNeeded);
1136
-
1137
- // Extend result with empty lines if content is too short for overlay placement or working area
1138
- while (result.length < workingHeight) {
1139
- result.push("");
1140
- }
1141
-
1142
- const viewportStart = Math.max(0, workingHeight - termHeight);
1143
-
1144
- // Composite each overlay
1145
- for (const { overlayLines, row, col, w } of rendered) {
1146
- for (let i = 0; i < overlayLines.length; i++) {
1147
- const idx = viewportStart + row + i;
1148
- if (idx >= 0 && idx < result.length) {
1149
- // Defensive: truncate overlay line to declared width before compositing
1150
- // (components should already respect width, but this ensures it)
1151
- const truncatedOverlayLine =
1152
- visibleWidth(overlayLines[i]) > w ? sliceByColumn(overlayLines[i], 0, w, true) : overlayLines[i];
1153
- result[idx] = this.compositeLineAt(result[idx], truncatedOverlayLine, col, w, termWidth);
1154
- }
1155
- }
1156
- }
1157
-
1158
- return result;
1159
- }
1160
-
1161
- protected applyLineResets(lines: string[]): string[] {
1162
- const reset = SEGMENT_RESET;
1163
- for (let i = 0; i < lines.length; i++) {
1164
- const line = lines[i];
1165
- if (!isImageLine(line)) {
1166
- lines[i] = normalizeTerminalOutput(line) + reset;
1167
- }
1168
- }
1169
- return lines;
1170
- }
1171
-
1172
- private compositeLineAt(
1173
- baseLine: string,
1174
- overlayLine: string,
1175
- startCol: number,
1176
- overlayWidth: number,
1177
- totalWidth: number,
1178
- ): string {
1179
- return compositeTuiLine(baseLine, overlayLine, startCol, overlayWidth, totalWidth);
1180
- }
1181
-
1182
- /**
1183
- * Find and extract cursor position from rendered lines.
1184
- * Searches for CURSOR_MARKER, calculates its position, and strips it from the output.
1185
- * Only scans the bottom terminal height lines (visible viewport).
1186
- * @param lines - Rendered lines to search
1187
- * @param height - Terminal height (visible viewport size)
1188
- * @returns Cursor position { row, col } or null if no marker found
1189
- */
1190
- protected extractCursorPosition(lines: string[], height: number): { row: number; col: number } | null {
1191
- // Only scan the bottom `height` lines (visible viewport)
1192
- const viewportTop = Math.max(0, lines.length - height);
1193
- for (let row = lines.length - 1; row >= viewportTop; row--) {
1194
- const line = lines[row];
1195
- const markerIndex = line.indexOf(CURSOR_MARKER);
1196
- if (markerIndex !== -1) {
1197
- // Calculate visual column (width of text before marker)
1198
- const beforeMarker = line.slice(0, markerIndex);
1199
- const col = visibleWidth(beforeMarker);
1200
-
1201
- // Strip marker from the line
1202
- lines[row] = line.slice(0, markerIndex) + line.slice(markerIndex + CURSOR_MARKER.length);
1203
-
1204
- return { row, col };
1205
- }
1206
- }
1207
- return null;
1208
- }
1209
-
1210
- /**
1211
- * Query the terminal's default background color with OSC 11 (`ESC ] 11 ; ? BEL`).
1212
- * @param timeoutMs Query timeout in milliseconds.
1213
- * @returns Promise containing the parsed RGB color, or undefined if it times out or fails to parse.
1214
- */
1215
- queryTerminalBackgroundColor({ timeoutMs }: { timeoutMs: number }): Promise<RgbColor | undefined> {
1216
- return new Promise((resolve) => {
1217
- const query: PendingOsc11BackgroundQuery = {
1218
- settled: false,
1219
- resolve,
1220
- timer: undefined,
1221
- };
1222
-
1223
- query.timer = setTimeout(() => {
1224
- if (query.settled) {
1225
- return;
1226
- }
1227
- query.settled = true;
1228
- query.timer = undefined;
1229
- query.resolve?.(undefined);
1230
- query.resolve = undefined;
1231
- }, timeoutMs);
1232
- this.pendingOsc11BackgroundQueries.push(query);
1233
- this.pendingOsc11BackgroundReplies += 1;
1234
- this.terminal.write("\x1b]11;?\x07");
1235
- });
1236
- }
1237
-
1238
- /**
1239
- * Query the terminal's color-scheme preference with DSR (`CSI ? 996 n`).
1240
- * Terminals that support the color palette notification protocol reply with
1241
- * `CSI ? 997 ; 1 n` for dark or `CSI ? 997 ; 2 n` for light.
1242
- */
1243
- queryTerminalColorScheme({ timeoutMs }: { timeoutMs: number }): Promise<TerminalColorScheme | undefined> {
1244
- return new Promise((resolve) => {
1245
- let settled = false;
1246
- let timer: NodeJS.Timeout | undefined;
1247
- let unsubscribe: () => void = () => {};
1248
- const settle = (scheme: TerminalColorScheme | undefined) => {
1249
- if (settled) return;
1250
- settled = true;
1251
- if (timer) {
1252
- clearTimeout(timer);
1253
- timer = undefined;
1254
- }
1255
- unsubscribe();
1256
- resolve(scheme);
1257
- };
1258
-
1259
- unsubscribe = this.onTerminalColorSchemeChange(settle);
1260
- timer = setTimeout(() => settle(undefined), timeoutMs);
1261
- this.terminal.write("\x1b[?996n");
1262
- });
1263
- }
1264
- }