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,1327 +0,0 @@
1
- // @ts-nocheck -- vendored by rovecode: upstream-checked at pinned SHA 853a80d2; see ../PATCHES.md
2
- import { eastAsianWidth } from "get-east-asian-width";
3
-
4
- // segmenters (shared instance)
5
- const graphemeSegmenter = new Intl.Segmenter(undefined, { granularity: "grapheme" });
6
- const wordSegmenter = new Intl.Segmenter(undefined, { granularity: "word" });
7
-
8
- /**
9
- * Get the shared grapheme segmenter instance.
10
- */
11
- export function getGraphemeSegmenter(): Intl.Segmenter {
12
- return graphemeSegmenter;
13
- }
14
-
15
- /**
16
- * Get the shared word segmenter instance.
17
- */
18
- export function getWordSegmenter(): Intl.Segmenter {
19
- return wordSegmenter;
20
- }
21
-
22
- /**
23
- * Check if a grapheme cluster (after segmentation) could possibly be an RGI emoji.
24
- * This is a fast heuristic to avoid the expensive rgiEmojiRegex test.
25
- * The tested Unicode blocks are deliberately broad to account for future
26
- * Unicode additions.
27
- */
28
- function couldBeEmoji(segment: string): boolean {
29
- const cp = segment.codePointAt(0)!;
30
- return (
31
- (cp >= 0x1f000 && cp <= 0x1fbff) || // Emoji and Pictograph
32
- (cp >= 0x2300 && cp <= 0x23ff) || // Misc technical
33
- (cp >= 0x2600 && cp <= 0x27bf) || // Misc symbols, dingbats
34
- (cp >= 0x2b50 && cp <= 0x2b55) || // Specific stars/circles
35
- segment.includes("\uFE0F") || // Contains VS16 (emoji presentation selector)
36
- segment.length > 2 // Multi-codepoint sequences (ZWJ, skin tones, etc.)
37
- );
38
- }
39
-
40
- // Regexes for character classification (same as string-width library)
41
- const zeroWidthRegex = /^(?:\p{Default_Ignorable_Code_Point}|\p{Control}|\p{Mark}|\p{Surrogate})+$/v;
42
- const leadingNonPrintingRegex = /^[\p{Default_Ignorable_Code_Point}\p{Control}\p{Format}\p{Mark}\p{Surrogate}]+/v;
43
- const nonPrintingCharRegex = /^(?:\p{Default_Ignorable_Code_Point}|\p{Control}|\p{Format}|\p{Mark}|\p{Surrogate})$/v;
44
- const markCharRegex = /^\p{Mark}$/v;
45
- // Marks that terminals allocate cells for when attached to a base character.
46
- // This includes Unicode spacing marks and non-spacing exceptions in legacy wcwidth tables.
47
- const terminalSpacingMarkRegex =
48
- /^(?:[\p{Spacing_Mark}--[\u1734\u302E\u302F]]|[\u065F\u0F7F\u102B\u102C\u1031\u1033-\u1035\u1038\u103A-\u103E])+$/v;
49
- const rgiEmojiRegex = /^\p{RGI_Emoji}$/v;
50
-
51
- // Cache for non-ASCII strings
52
- const WIDTH_CACHE_SIZE = 512;
53
- const widthCache = new Map<string, number>();
54
-
55
- export const cjkBreakRegex =
56
- /[\p{Script_Extensions=Han}\p{Script_Extensions=Hiragana}\p{Script_Extensions=Katakana}\p{Script_Extensions=Hangul}\p{Script_Extensions=Bopomofo}]/u;
57
-
58
- function isPrintableAscii(str: string): boolean {
59
- for (let i = 0; i < str.length; i++) {
60
- const code = str.charCodeAt(i);
61
- if (code < 0x20 || code > 0x7e) {
62
- return false;
63
- }
64
- }
65
- return true;
66
- }
67
-
68
- function truncateFragmentToWidth(text: string, maxWidth: number): { text: string; width: number } {
69
- if (maxWidth <= 0 || text.length === 0) {
70
- return { text: "", width: 0 };
71
- }
72
-
73
- if (isPrintableAscii(text)) {
74
- const clipped = text.slice(0, maxWidth);
75
- return { text: clipped, width: clipped.length };
76
- }
77
-
78
- const hasAnsi = text.includes("\x1b");
79
- const hasTabs = text.includes("\t");
80
- if (!hasAnsi && !hasTabs) {
81
- let result = "";
82
- let width = 0;
83
- for (const { segment } of graphemeSegmenter.segment(text)) {
84
- const w = graphemeWidth(segment);
85
- if (width + w > maxWidth) {
86
- break;
87
- }
88
- result += segment;
89
- width += w;
90
- }
91
- return { text: result, width };
92
- }
93
-
94
- let result = "";
95
- let width = 0;
96
- let i = 0;
97
- let pendingAnsi = "";
98
-
99
- while (i < text.length) {
100
- const ansi = extractAnsiCode(text, i);
101
- if (ansi) {
102
- pendingAnsi += ansi.code;
103
- i += ansi.length;
104
- continue;
105
- }
106
-
107
- if (text[i] === "\t") {
108
- if (width + 3 > maxWidth) {
109
- break;
110
- }
111
- if (pendingAnsi) {
112
- result += pendingAnsi;
113
- pendingAnsi = "";
114
- }
115
- result += "\t";
116
- width += 3;
117
- i++;
118
- continue;
119
- }
120
-
121
- let end = i;
122
- while (end < text.length && text[end] !== "\t") {
123
- const nextAnsi = extractAnsiCode(text, end);
124
- if (nextAnsi) {
125
- break;
126
- }
127
- end++;
128
- }
129
-
130
- for (const { segment } of graphemeSegmenter.segment(text.slice(i, end))) {
131
- const w = graphemeWidth(segment);
132
- if (width + w > maxWidth) {
133
- return { text: result, width };
134
- }
135
- if (pendingAnsi) {
136
- result += pendingAnsi;
137
- pendingAnsi = "";
138
- }
139
- result += segment;
140
- width += w;
141
- }
142
- i = end;
143
- }
144
-
145
- return { text: result, width };
146
- }
147
-
148
- function finalizeTruncatedResult(
149
- prefix: string,
150
- prefixWidth: number,
151
- ellipsis: string,
152
- ellipsisWidth: number,
153
- maxWidth: number,
154
- pad: boolean,
155
- ): string {
156
- const reset = "\x1b[0m";
157
- const hyperlinkClose = getActiveOsc8Close(prefix);
158
- const visibleWidth = prefixWidth + ellipsisWidth;
159
- let result: string;
160
-
161
- if (ellipsis.length > 0) {
162
- result = `${prefix}${hyperlinkClose}${reset}${ellipsis}${reset}`;
163
- } else {
164
- result = `${prefix}${hyperlinkClose}${reset}`;
165
- }
166
-
167
- return pad ? result + " ".repeat(Math.max(0, maxWidth - visibleWidth)) : result;
168
- }
169
-
170
- /**
171
- * Calculate the terminal width of a single grapheme cluster.
172
- * Based on code from the string-width library, but includes a possible-emoji
173
- * check to avoid running the RGI_Emoji regex unnecessarily.
174
- */
175
- function graphemeWidth(segment: string): number {
176
- if (segment === "\t") {
177
- return 3;
178
- }
179
-
180
- // Some marks occupy cells even without a base character.
181
- if (terminalSpacingMarkRegex.test(segment)) {
182
- return [...segment].length;
183
- }
184
-
185
- // Zero-width clusters
186
- if (zeroWidthRegex.test(segment)) {
187
- return 0;
188
- }
189
-
190
- // Emoji check with pre-filter
191
- if (couldBeEmoji(segment) && rgiEmojiRegex.test(segment)) {
192
- return 2;
193
- }
194
-
195
- // Get base visible codepoint
196
- const base = segment.replace(leadingNonPrintingRegex, "");
197
- const cp = base.codePointAt(0);
198
- if (cp === undefined) {
199
- return 0;
200
- }
201
-
202
- // Regional indicator symbols (U+1F1E6..U+1F1FF) are often rendered as
203
- // full-width emoji in terminals, even when isolated during streaming.
204
- // Keep width conservative (2) to avoid terminal auto-wrap drift artifacts.
205
- if (cp >= 0x1f1e6 && cp <= 0x1f1ff) {
206
- return 2;
207
- }
208
-
209
- let width = eastAsianWidth(cp);
210
-
211
- // Intl.Segmenter can group multiple terminal-spacing code points into one
212
- // grapheme. Count trailing visible code points that terminals may allocate
213
- // cells for: Indic consonants after marks, halfwidth/fullwidth forms, and
214
- // Thai/Lao AM vowels.
215
- let followsMark = false;
216
- const chars = [...base];
217
- for (const char of chars.slice(1)) {
218
- if (terminalSpacingMarkRegex.test(char)) {
219
- width += 1;
220
- followsMark = false;
221
- } else if (markCharRegex.test(char)) {
222
- followsMark = true;
223
- } else if (!nonPrintingCharRegex.test(char)) {
224
- const c = char.codePointAt(0)!;
225
- if (followsMark || (c >= 0xff00 && c <= 0xffef)) {
226
- // halfwidth + fullwidth forms
227
- width += eastAsianWidth(c);
228
- } else if (c === 0x0e33 || c === 0x0eb3) {
229
- width += 1;
230
- }
231
- followsMark = false;
232
- }
233
- }
234
-
235
- return width;
236
- }
237
-
238
- /**
239
- * Calculate the visible width of a string in terminal columns.
240
- */
241
- export function visibleWidth(str: string): number {
242
- if (str.length === 0) {
243
- return 0;
244
- }
245
-
246
- // Fast path: pure ASCII printable
247
- if (isPrintableAscii(str)) {
248
- return str.length;
249
- }
250
-
251
- // Check cache
252
- const cached = widthCache.get(str);
253
- if (cached !== undefined) {
254
- return cached;
255
- }
256
-
257
- // Normalize: tabs to 3 spaces, strip ANSI escape codes
258
- let clean = str;
259
- if (str.includes("\t")) {
260
- clean = clean.replace(/\t/g, " ");
261
- }
262
- if (clean.includes("\x1b")) {
263
- // Strip supported ANSI/OSC/APC escape sequences in one pass.
264
- // This covers CSI styling/cursor codes, OSC hyperlinks and prompt markers,
265
- // and APC sequences like CURSOR_MARKER.
266
- let stripped = "";
267
- let i = 0;
268
- while (i < clean.length) {
269
- const ansi = extractAnsiCode(clean, i);
270
- if (ansi) {
271
- i += ansi.length;
272
- continue;
273
- }
274
- stripped += clean[i];
275
- i++;
276
- }
277
- clean = stripped;
278
- }
279
-
280
- // Calculate width
281
- let width = 0;
282
- for (const { segment } of graphemeSegmenter.segment(clean)) {
283
- width += graphemeWidth(segment);
284
- }
285
-
286
- // Cache result
287
- if (widthCache.size >= WIDTH_CACHE_SIZE) {
288
- const firstKey = widthCache.keys().next().value;
289
- if (firstKey !== undefined) {
290
- widthCache.delete(firstKey);
291
- }
292
- }
293
- widthCache.set(str, width);
294
-
295
- return width;
296
- }
297
-
298
- /** Remove ANSI, OSC, and APC control sequences while preserving visible text. */
299
- export function stripTerminalSequences(str: string): string {
300
- if (!str.includes("\x1b")) return str;
301
- let result = "";
302
- let i = 0;
303
- while (i < str.length) {
304
- const ansi = extractAnsiCode(str, i);
305
- if (ansi) {
306
- i += ansi.length;
307
- continue;
308
- }
309
- result += str[i];
310
- i++;
311
- }
312
- return result;
313
- }
314
-
315
- interface GraphemeCellRange {
316
- start: number;
317
- end: number;
318
- }
319
-
320
- /** Return the terminal-cell range occupied by the grapheme at a visible column. */
321
- export function getGraphemeCellRange(line: string, column: number): GraphemeCellRange | undefined {
322
- let currentCol = 0;
323
- let i = 0;
324
- while (i < line.length) {
325
- const ansi = extractAnsiCode(line, i);
326
- if (ansi) {
327
- i += ansi.length;
328
- continue;
329
- }
330
- let textEnd = i;
331
- while (textEnd < line.length && !extractAnsiCode(line, textEnd)) textEnd++;
332
- for (const { segment } of graphemeSegmenter.segment(line.slice(i, textEnd))) {
333
- const width = graphemeWidth(segment);
334
- if (width > 0 && column >= currentCol && column < currentCol + width) {
335
- return { start: currentCol, end: currentCol + width };
336
- }
337
- currentCol += width;
338
- }
339
- i = textEnd;
340
- }
341
- return undefined;
342
- }
343
-
344
- /** Return the OSC 8 hyperlink covering a visible terminal column. */
345
- export function getOsc8LinkAtColumn(line: string, column: number): string | undefined {
346
- let activeUrl: string | undefined;
347
- let currentCol = 0;
348
- let i = 0;
349
- while (i < line.length) {
350
- const ansi = extractAnsiCode(line, i);
351
- if (ansi) {
352
- const hyperlink = /^\x1b\]8;[^;]*;([^\x07\x1b]*)(?:\x07|\x1b\\)$/.exec(ansi.code);
353
- if (hyperlink) activeUrl = hyperlink[1] || undefined;
354
- i += ansi.length;
355
- continue;
356
- }
357
- let textEnd = i;
358
- while (textEnd < line.length && !extractAnsiCode(line, textEnd)) textEnd++;
359
- for (const { segment } of graphemeSegmenter.segment(line.slice(i, textEnd))) {
360
- const width = segment === "\t" ? 3 : graphemeWidth(segment);
361
- if (column >= currentCol && column < currentCol + width) return activeUrl;
362
- currentCol += width;
363
- }
364
- i = textEnd;
365
- }
366
- return undefined;
367
- }
368
-
369
- /**
370
- * Normalize text for terminal output without changing logical editor content.
371
- * Some terminals render precomposed Thai/Lao AM vowels inconsistently during
372
- * differential repaint. Their compatibility decompositions have the same cell
373
- * width but avoid stale-cell artifacts in terminal renderers. Visible tabs are
374
- * expanded to the fixed width used by layout so terminal tab stops cannot wrap
375
- * a logical line, while tabs inside terminal string sequences stay untouched.
376
- */
377
- const THAI_LAO_AM_REGEX = /[\u0e33\u0eb3]/;
378
- const THAI_LAO_AM_GLOBAL_REGEX = /[\u0e33\u0eb3]/g;
379
-
380
- export function normalizeTerminalOutput(str: string): string {
381
- let normalized = str;
382
- if (THAI_LAO_AM_REGEX.test(normalized)) {
383
- normalized = normalized.replace(THAI_LAO_AM_GLOBAL_REGEX, (char) =>
384
- char === "\u0e33" ? "\u0e4d\u0e32" : "\u0ecd\u0eb2",
385
- );
386
- }
387
- if (!normalized.includes("\t")) return normalized;
388
-
389
- let result = "";
390
- let i = 0;
391
- while (i < normalized.length) {
392
- const ansi = extractAnsiCode(normalized, i);
393
- if (ansi) {
394
- result += ansi.code;
395
- i += ansi.length;
396
- continue;
397
- }
398
- result += normalized[i] === "\t" ? " " : normalized[i];
399
- i++;
400
- }
401
- return result;
402
- }
403
-
404
- /**
405
- * Extract ANSI escape sequences from a string at the given position.
406
- */
407
- export function extractAnsiCode(str: string, pos: number): { code: string; length: number } | null {
408
- if (pos >= str.length || str[pos] !== "\x1b") return null;
409
-
410
- const next = str[pos + 1];
411
-
412
- // CSI sequence: ESC [ ... m/G/K/H/J
413
- if (next === "[") {
414
- let j = pos + 2;
415
- while (j < str.length && !/[mGKHJ]/.test(str[j]!)) j++;
416
- if (j < str.length) return { code: str.substring(pos, j + 1), length: j + 1 - pos };
417
- return null;
418
- }
419
-
420
- // OSC sequence: ESC ] ... BEL or ESC ] ... ST (ESC \)
421
- // Used for hyperlinks (OSC 8), window titles, etc.
422
- if (next === "]") {
423
- let j = pos + 2;
424
- while (j < str.length) {
425
- if (str[j] === "\x07") return { code: str.substring(pos, j + 1), length: j + 1 - pos };
426
- if (str[j] === "\x1b" && str[j + 1] === "\\") return { code: str.substring(pos, j + 2), length: j + 2 - pos };
427
- j++;
428
- }
429
- return null;
430
- }
431
-
432
- // APC sequence: ESC _ ... BEL or ESC _ ... ST (ESC \)
433
- // Used for cursor marker and application-specific commands
434
- if (next === "_") {
435
- let j = pos + 2;
436
- while (j < str.length) {
437
- if (str[j] === "\x07") return { code: str.substring(pos, j + 1), length: j + 1 - pos };
438
- if (str[j] === "\x1b" && str[j + 1] === "\\") return { code: str.substring(pos, j + 2), length: j + 2 - pos };
439
- j++;
440
- }
441
- return null;
442
- }
443
-
444
- return null;
445
- }
446
-
447
- type Osc8Terminator = "\x07" | "\x1b\\";
448
-
449
- interface ActiveHyperlink {
450
- params: string;
451
- url: string;
452
- terminator: Osc8Terminator;
453
- }
454
-
455
- function parseOsc8Hyperlink(ansiCode: string): ActiveHyperlink | null | undefined {
456
- if (!ansiCode.startsWith("\x1b]8;")) {
457
- return undefined;
458
- }
459
-
460
- const terminator: Osc8Terminator = ansiCode.endsWith("\x07") ? "\x07" : "\x1b\\";
461
- const body = ansiCode.slice(4, terminator === "\x07" ? -1 : -2);
462
- const separatorIndex = body.indexOf(";");
463
- if (separatorIndex === -1) {
464
- return undefined;
465
- }
466
-
467
- const params = body.slice(0, separatorIndex);
468
- const url = body.slice(separatorIndex + 1);
469
- if (!url) {
470
- return null;
471
- }
472
- return { params, url, terminator };
473
- }
474
-
475
- function formatOsc8Hyperlink(hyperlink: ActiveHyperlink): string {
476
- return `\x1b]8;${hyperlink.params};${hyperlink.url}${hyperlink.terminator}`;
477
- }
478
-
479
- function formatOsc8Close(terminator: Osc8Terminator): string {
480
- return `\x1b]8;;${terminator}`;
481
- }
482
-
483
- function getActiveOsc8Close(prefix: string): string {
484
- if (!prefix.includes("\x1b]8;")) {
485
- return "";
486
- }
487
-
488
- let activeHyperlink: ActiveHyperlink | null = null;
489
- let i = 0;
490
- while (i < prefix.length) {
491
- const ansi = extractAnsiCode(prefix, i);
492
- if (ansi) {
493
- const hyperlink = parseOsc8Hyperlink(ansi.code);
494
- if (hyperlink !== undefined) {
495
- activeHyperlink = hyperlink;
496
- }
497
- i += ansi.length;
498
- } else {
499
- i++;
500
- }
501
- }
502
- return activeHyperlink ? formatOsc8Close(activeHyperlink.terminator) : "";
503
- }
504
-
505
- /**
506
- * Track active ANSI SGR codes to preserve styling across line breaks.
507
- */
508
- class AnsiCodeTracker {
509
- // Track individual attributes separately so we can reset them specifically
510
- private bold = false;
511
- private dim = false;
512
- private italic = false;
513
- private underline = false;
514
- private blink = false;
515
- private inverse = false;
516
- private hidden = false;
517
- private strikethrough = false;
518
- private fgColor: string | null = null; // Stores the full code like "31" or "38;5;240"
519
- private bgColor: string | null = null; // Stores the full code like "41" or "48;5;240"
520
- private activeHyperlink: ActiveHyperlink | null = null;
521
-
522
- process(ansiCode: string): void {
523
- // OSC 8 hyperlink: \x1b]8;;<url>\x1b\\ (open) or \x1b]8;;\x1b\\ (close).
524
- // Preserve the original terminator because some terminals only make BEL-terminated
525
- // links clickable. OAuth login URLs use BEL, so reopening wrapped lines with ST
526
- // made only the first physical line clickable in those terminals.
527
- const hyperlink = parseOsc8Hyperlink(ansiCode);
528
- if (hyperlink !== undefined) {
529
- this.activeHyperlink = hyperlink;
530
- return;
531
- }
532
-
533
- if (!ansiCode.endsWith("m")) {
534
- return;
535
- }
536
-
537
- // Extract the parameters between \x1b[ and m
538
- const match = ansiCode.match(/\x1b\[([\d;]*)m/);
539
- if (!match) return;
540
-
541
- const params = match[1];
542
- if (params === "" || params === "0") {
543
- // Full reset
544
- this.reset();
545
- return;
546
- }
547
-
548
- // Parse parameters (can be semicolon-separated)
549
- const parts = params.split(";");
550
- let i = 0;
551
- while (i < parts.length) {
552
- const code = Number.parseInt(parts[i], 10);
553
-
554
- // Handle 256-color and RGB codes which consume multiple parameters
555
- if (code === 38 || code === 48) {
556
- // 38;5;N (256 color fg) or 38;2;R;G;B (RGB fg)
557
- // 48;5;N (256 color bg) or 48;2;R;G;B (RGB bg)
558
- if (parts[i + 1] === "5" && parts[i + 2] !== undefined) {
559
- // 256 color: 38;5;N or 48;5;N
560
- const colorCode = `${parts[i]};${parts[i + 1]};${parts[i + 2]}`;
561
- if (code === 38) {
562
- this.fgColor = colorCode;
563
- } else {
564
- this.bgColor = colorCode;
565
- }
566
- i += 3;
567
- continue;
568
- } else if (parts[i + 1] === "2" && parts[i + 4] !== undefined) {
569
- // RGB color: 38;2;R;G;B or 48;2;R;G;B
570
- const colorCode = `${parts[i]};${parts[i + 1]};${parts[i + 2]};${parts[i + 3]};${parts[i + 4]}`;
571
- if (code === 38) {
572
- this.fgColor = colorCode;
573
- } else {
574
- this.bgColor = colorCode;
575
- }
576
- i += 5;
577
- continue;
578
- }
579
- }
580
-
581
- // Standard SGR codes
582
- switch (code) {
583
- case 0:
584
- this.reset();
585
- break;
586
- case 1:
587
- this.bold = true;
588
- break;
589
- case 2:
590
- this.dim = true;
591
- break;
592
- case 3:
593
- this.italic = true;
594
- break;
595
- case 4:
596
- this.underline = true;
597
- break;
598
- case 5:
599
- this.blink = true;
600
- break;
601
- case 7:
602
- this.inverse = true;
603
- break;
604
- case 8:
605
- this.hidden = true;
606
- break;
607
- case 9:
608
- this.strikethrough = true;
609
- break;
610
- case 21:
611
- this.bold = false;
612
- break; // Some terminals
613
- case 22:
614
- this.bold = false;
615
- this.dim = false;
616
- break;
617
- case 23:
618
- this.italic = false;
619
- break;
620
- case 24:
621
- this.underline = false;
622
- break;
623
- case 25:
624
- this.blink = false;
625
- break;
626
- case 27:
627
- this.inverse = false;
628
- break;
629
- case 28:
630
- this.hidden = false;
631
- break;
632
- case 29:
633
- this.strikethrough = false;
634
- break;
635
- case 39:
636
- this.fgColor = null;
637
- break; // Default fg
638
- case 49:
639
- this.bgColor = null;
640
- break; // Default bg
641
- default:
642
- // Standard foreground colors 30-37, 90-97
643
- if ((code >= 30 && code <= 37) || (code >= 90 && code <= 97)) {
644
- this.fgColor = String(code);
645
- }
646
- // Standard background colors 40-47, 100-107
647
- else if ((code >= 40 && code <= 47) || (code >= 100 && code <= 107)) {
648
- this.bgColor = String(code);
649
- }
650
- break;
651
- }
652
- i++;
653
- }
654
- }
655
-
656
- private reset(): void {
657
- this.bold = false;
658
- this.dim = false;
659
- this.italic = false;
660
- this.underline = false;
661
- this.blink = false;
662
- this.inverse = false;
663
- this.hidden = false;
664
- this.strikethrough = false;
665
- this.fgColor = null;
666
- this.bgColor = null;
667
- // SGR reset does not affect OSC 8 hyperlink state
668
- }
669
-
670
- /** Clear all state for reuse. */
671
- clear(): void {
672
- this.reset();
673
- this.activeHyperlink = null;
674
- }
675
-
676
- getActiveCodes(): string {
677
- const codes: string[] = [];
678
- if (this.bold) codes.push("1");
679
- if (this.dim) codes.push("2");
680
- if (this.italic) codes.push("3");
681
- if (this.underline) codes.push("4");
682
- if (this.blink) codes.push("5");
683
- if (this.inverse) codes.push("7");
684
- if (this.hidden) codes.push("8");
685
- if (this.strikethrough) codes.push("9");
686
- if (this.fgColor) codes.push(this.fgColor);
687
- if (this.bgColor) codes.push(this.bgColor);
688
-
689
- let result = codes.length > 0 ? `\x1b[${codes.join(";")}m` : "";
690
- if (this.activeHyperlink) {
691
- result += formatOsc8Hyperlink(this.activeHyperlink);
692
- }
693
- return result;
694
- }
695
-
696
- hasActiveCodes(): boolean {
697
- return (
698
- this.bold ||
699
- this.dim ||
700
- this.italic ||
701
- this.underline ||
702
- this.blink ||
703
- this.inverse ||
704
- this.hidden ||
705
- this.strikethrough ||
706
- this.fgColor !== null ||
707
- this.bgColor !== null ||
708
- this.activeHyperlink !== null
709
- );
710
- }
711
-
712
- /**
713
- * Get reset codes for attributes that need to be turned off at line end.
714
- * Underline must be closed to prevent bleeding into padding.
715
- * Active OSC 8 hyperlinks must be closed and re-opened on the next line.
716
- * Returns empty string if no attributes need closing.
717
- */
718
- getLineEndReset(): string {
719
- let result = "";
720
- if (this.underline) {
721
- result += "\x1b[24m"; // Underline off only
722
- }
723
- if (this.activeHyperlink) {
724
- result += formatOsc8Close(this.activeHyperlink.terminator); // Re-opened at line start via getActiveCodes()
725
- }
726
- return result;
727
- }
728
- }
729
-
730
- function updateTrackerFromText(text: string, tracker: AnsiCodeTracker): void {
731
- let i = 0;
732
- while (i < text.length) {
733
- const ansiResult = extractAnsiCode(text, i);
734
- if (ansiResult) {
735
- tracker.process(ansiResult.code);
736
- i += ansiResult.length;
737
- } else {
738
- i++;
739
- }
740
- }
741
- }
742
-
743
- /**
744
- * Split text into words while keeping ANSI codes attached.
745
- */
746
- function splitIntoTokensWithAnsi(text: string): string[] {
747
- const tokens: string[] = [];
748
- let current = "";
749
- let pendingAnsi = ""; // ANSI codes waiting to be attached to next visible content
750
- let currentKind: "space" | "word" | null = null;
751
- let i = 0;
752
-
753
- const flushCurrent = (): void => {
754
- if (!current) {
755
- return;
756
- }
757
- tokens.push(current);
758
- current = "";
759
- currentKind = null;
760
- };
761
-
762
- while (i < text.length) {
763
- const ansiResult = extractAnsiCode(text, i);
764
- if (ansiResult) {
765
- // Hold ANSI codes separately - they'll be attached to the next visible char
766
- pendingAnsi += ansiResult.code;
767
- i += ansiResult.length;
768
- continue;
769
- }
770
-
771
- let end = i;
772
- while (end < text.length && !extractAnsiCode(text, end)) {
773
- end++;
774
- }
775
-
776
- for (const { segment } of graphemeSegmenter.segment(text.slice(i, end))) {
777
- const segmentIsSpace = segment === " ";
778
- if (!segmentIsSpace && cjkBreakRegex.test(segment)) {
779
- flushCurrent();
780
- const token = pendingAnsi + segment;
781
- pendingAnsi = "";
782
- tokens.push(token);
783
- continue;
784
- }
785
-
786
- const segmentKind = segmentIsSpace ? "space" : "word";
787
- if (current && currentKind !== segmentKind) {
788
- flushCurrent();
789
- }
790
-
791
- // Attach any pending ANSI codes to this visible character
792
- if (pendingAnsi) {
793
- current += pendingAnsi;
794
- pendingAnsi = "";
795
- }
796
-
797
- currentKind = segmentKind;
798
- current += segment;
799
- }
800
-
801
- i = end;
802
- }
803
-
804
- // Handle any remaining pending ANSI codes (attach to last token)
805
- if (pendingAnsi) {
806
- if (current) {
807
- current += pendingAnsi;
808
- } else if (tokens.length > 0) {
809
- tokens[tokens.length - 1] += pendingAnsi;
810
- } else {
811
- current = pendingAnsi;
812
- }
813
- }
814
-
815
- if (current) {
816
- tokens.push(current);
817
- }
818
-
819
- return tokens;
820
- }
821
-
822
- /**
823
- * Wrap text with ANSI codes preserved.
824
- *
825
- * ONLY does word wrapping - NO padding, NO background colors.
826
- * Returns lines where each line is <= width visible chars.
827
- * Active ANSI codes are preserved across line breaks.
828
- *
829
- * @param text - Text to wrap (may contain ANSI codes and newlines)
830
- * @param width - Maximum visible width per line
831
- * @returns Array of wrapped lines (NOT padded to width)
832
- */
833
- export function wrapTextWithAnsi(text: string, width: number): string[] {
834
- if (!text) {
835
- return [""];
836
- }
837
-
838
- // Handle newlines by processing each line separately
839
- // Track ANSI state across lines so styles carry over after literal newlines
840
- const inputLines = text.split(/\r\n|\r|\n/);
841
- const result: string[] = [];
842
- const tracker = new AnsiCodeTracker();
843
-
844
- for (const inputLine of inputLines) {
845
- // Prepend active ANSI codes from previous lines (except for first line)
846
- const prefix = result.length > 0 ? tracker.getActiveCodes() : "";
847
- const wrappedLines = wrapSingleLine(prefix + inputLine, width);
848
- for (const wrappedLine of wrappedLines) {
849
- result.push(wrappedLine);
850
- }
851
- // Update tracker with codes from this line for next iteration
852
- updateTrackerFromText(inputLine, tracker);
853
- }
854
-
855
- return result.length > 0 ? result : [""];
856
- }
857
-
858
- function wrapSingleLine(line: string, width: number): string[] {
859
- if (!line) {
860
- return [""];
861
- }
862
-
863
- const visibleLength = visibleWidth(line);
864
- if (visibleLength <= width) {
865
- return [line];
866
- }
867
-
868
- const wrapped: string[] = [];
869
- const tracker = new AnsiCodeTracker();
870
- const tokens = splitIntoTokensWithAnsi(line);
871
-
872
- let currentLine = "";
873
- let currentVisibleLength = 0;
874
-
875
- for (const token of tokens) {
876
- const tokenVisibleLength = visibleWidth(token);
877
- const isWhitespace = token.trim() === "";
878
-
879
- // Token itself is too long - break it character by character
880
- if (tokenVisibleLength > width && !isWhitespace) {
881
- if (currentLine) {
882
- // Add specific reset for underline only (preserves background)
883
- const lineEndReset = tracker.getLineEndReset();
884
- if (lineEndReset) {
885
- currentLine += lineEndReset;
886
- }
887
- wrapped.push(currentLine);
888
- currentLine = "";
889
- currentVisibleLength = 0;
890
- }
891
-
892
- // Break long token - breakLongWord handles its own resets
893
- const broken = breakLongWord(token, width, tracker);
894
- for (let i = 0; i < broken.length - 1; i++) {
895
- wrapped.push(broken[i]!);
896
- }
897
- currentLine = broken[broken.length - 1];
898
- currentVisibleLength = visibleWidth(currentLine);
899
- continue;
900
- }
901
-
902
- // Check if adding this token would exceed width
903
- const totalNeeded = currentVisibleLength + tokenVisibleLength;
904
-
905
- if (totalNeeded > width && currentVisibleLength > 0) {
906
- // Trim trailing whitespace, then add underline reset (not full reset, to preserve background)
907
- let lineToWrap = currentLine.trimEnd();
908
- const lineEndReset = tracker.getLineEndReset();
909
- if (lineEndReset) {
910
- lineToWrap += lineEndReset;
911
- }
912
- wrapped.push(lineToWrap);
913
- if (isWhitespace) {
914
- // Don't start new line with whitespace
915
- currentLine = tracker.getActiveCodes();
916
- currentVisibleLength = 0;
917
- } else {
918
- currentLine = tracker.getActiveCodes() + token;
919
- currentVisibleLength = tokenVisibleLength;
920
- }
921
- } else {
922
- // Add to current line
923
- currentLine += token;
924
- currentVisibleLength += tokenVisibleLength;
925
- }
926
-
927
- updateTrackerFromText(token, tracker);
928
- }
929
-
930
- if (currentLine) {
931
- // No reset at end of final line - let caller handle it
932
- wrapped.push(currentLine);
933
- }
934
-
935
- // Trailing whitespace can cause lines to exceed the requested width
936
- return wrapped.length > 0 ? wrapped.map((line) => line.trimEnd()) : [""];
937
- }
938
-
939
- export const PUNCTUATION_REGEX = /[(){}[\]<>.,;:'"!?+\-=*/\\|&%^$#@~`]/;
940
-
941
- /**
942
- * Check if a character is whitespace.
943
- */
944
- export function isWhitespaceChar(char: string): boolean {
945
- return /\s/.test(char);
946
- }
947
-
948
- /**
949
- * Check if a character is punctuation.
950
- */
951
- export function isPunctuationChar(char: string): boolean {
952
- return PUNCTUATION_REGEX.test(char);
953
- }
954
-
955
- function breakLongWord(word: string, width: number, tracker: AnsiCodeTracker): string[] {
956
- const lines: string[] = [];
957
- let currentLine = tracker.getActiveCodes();
958
- let currentWidth = 0;
959
-
960
- // First, separate ANSI codes from visible content
961
- // We need to handle ANSI codes specially since they're not graphemes
962
- let i = 0;
963
- const segments: Array<{ type: "ansi" | "grapheme"; value: string }> = [];
964
-
965
- while (i < word.length) {
966
- const ansiResult = extractAnsiCode(word, i);
967
- if (ansiResult) {
968
- segments.push({ type: "ansi", value: ansiResult.code });
969
- i += ansiResult.length;
970
- } else {
971
- // Find the next ANSI code or end of string
972
- let end = i;
973
- while (end < word.length) {
974
- const nextAnsi = extractAnsiCode(word, end);
975
- if (nextAnsi) break;
976
- end++;
977
- }
978
- // Segment this non-ANSI portion into graphemes
979
- const textPortion = word.slice(i, end);
980
- for (const seg of graphemeSegmenter.segment(textPortion)) {
981
- segments.push({ type: "grapheme", value: seg.segment });
982
- }
983
- i = end;
984
- }
985
- }
986
-
987
- // Now process segments
988
- for (const seg of segments) {
989
- if (seg.type === "ansi") {
990
- currentLine += seg.value;
991
- tracker.process(seg.value);
992
- continue;
993
- }
994
-
995
- const grapheme = seg.value;
996
- // Skip empty graphemes to avoid issues with string-width calculation
997
- if (!grapheme) continue;
998
-
999
- const graphemeWidth = visibleWidth(grapheme);
1000
-
1001
- if (currentWidth + graphemeWidth > width) {
1002
- // Add specific reset for underline only (preserves background)
1003
- const lineEndReset = tracker.getLineEndReset();
1004
- if (lineEndReset) {
1005
- currentLine += lineEndReset;
1006
- }
1007
- lines.push(currentLine);
1008
- currentLine = tracker.getActiveCodes();
1009
- currentWidth = 0;
1010
- }
1011
-
1012
- currentLine += grapheme;
1013
- currentWidth += graphemeWidth;
1014
- }
1015
-
1016
- if (currentLine) {
1017
- // No reset at end of final segment - caller handles continuation
1018
- lines.push(currentLine);
1019
- }
1020
-
1021
- return lines.length > 0 ? lines : [""];
1022
- }
1023
-
1024
- /**
1025
- * Apply background color to a line, padding to full width.
1026
- *
1027
- * @param line - Line of text (may contain ANSI codes)
1028
- * @param width - Total width to pad to
1029
- * @param bgFn - Background color function
1030
- * @returns Line with background applied and padded to width
1031
- */
1032
- export function applyBackgroundToLine(line: string, width: number, bgFn: (text: string) => string): string {
1033
- // Calculate padding needed
1034
- const visibleLen = visibleWidth(line);
1035
- const paddingNeeded = Math.max(0, width - visibleLen);
1036
- const padding = " ".repeat(paddingNeeded);
1037
-
1038
- // Apply background to content + padding
1039
- const withPadding = line + padding;
1040
- return bgFn(withPadding);
1041
- }
1042
-
1043
- /**
1044
- * Truncate text to fit within a maximum visible width, adding ellipsis if needed.
1045
- * Optionally pad with spaces to reach exactly maxWidth.
1046
- * Properly handles ANSI escape codes (they don't count toward width).
1047
- *
1048
- * @param text - Text to truncate (may contain ANSI codes)
1049
- * @param maxWidth - Maximum visible width
1050
- * @param ellipsis - Ellipsis string to append when truncating (default: "...")
1051
- * @param pad - If true, pad result with spaces to exactly maxWidth (default: false)
1052
- * @returns Truncated text, optionally padded to exactly maxWidth
1053
- */
1054
- export function truncateToWidth(
1055
- text: string,
1056
- maxWidth: number,
1057
- ellipsis: string = "...",
1058
- pad: boolean = false,
1059
- ): string {
1060
- if (maxWidth <= 0) {
1061
- return "";
1062
- }
1063
-
1064
- if (text.length === 0) {
1065
- return pad ? " ".repeat(maxWidth) : "";
1066
- }
1067
-
1068
- const ellipsisWidth = visibleWidth(ellipsis);
1069
- if (ellipsisWidth >= maxWidth) {
1070
- const textWidth = visibleWidth(text);
1071
- if (textWidth <= maxWidth) {
1072
- return pad ? text + " ".repeat(maxWidth - textWidth) : text;
1073
- }
1074
-
1075
- const clippedEllipsis = truncateFragmentToWidth(ellipsis, maxWidth);
1076
- if (clippedEllipsis.width === 0) {
1077
- return pad ? " ".repeat(maxWidth) : "";
1078
- }
1079
- return finalizeTruncatedResult("", 0, clippedEllipsis.text, clippedEllipsis.width, maxWidth, pad);
1080
- }
1081
-
1082
- if (isPrintableAscii(text)) {
1083
- if (text.length <= maxWidth) {
1084
- return pad ? text + " ".repeat(maxWidth - text.length) : text;
1085
- }
1086
- const targetWidth = maxWidth - ellipsisWidth;
1087
- return finalizeTruncatedResult(text.slice(0, targetWidth), targetWidth, ellipsis, ellipsisWidth, maxWidth, pad);
1088
- }
1089
-
1090
- const targetWidth = maxWidth - ellipsisWidth;
1091
- let result = "";
1092
- let pendingAnsi = "";
1093
- let visibleSoFar = 0;
1094
- let keptWidth = 0;
1095
- let keepContiguousPrefix = true;
1096
- let overflowed = false;
1097
- let exhaustedInput = false;
1098
- const hasAnsi = text.includes("\x1b");
1099
- const hasTabs = text.includes("\t");
1100
-
1101
- if (!hasAnsi && !hasTabs) {
1102
- for (const { segment } of graphemeSegmenter.segment(text)) {
1103
- const width = graphemeWidth(segment);
1104
- if (keepContiguousPrefix && keptWidth + width <= targetWidth) {
1105
- result += segment;
1106
- keptWidth += width;
1107
- } else {
1108
- keepContiguousPrefix = false;
1109
- }
1110
- visibleSoFar += width;
1111
- if (visibleSoFar > maxWidth) {
1112
- overflowed = true;
1113
- break;
1114
- }
1115
- }
1116
- exhaustedInput = !overflowed;
1117
- } else {
1118
- let i = 0;
1119
- while (i < text.length) {
1120
- const ansi = extractAnsiCode(text, i);
1121
- if (ansi) {
1122
- pendingAnsi += ansi.code;
1123
- i += ansi.length;
1124
- continue;
1125
- }
1126
-
1127
- if (text[i] === "\t") {
1128
- if (keepContiguousPrefix && keptWidth + 3 <= targetWidth) {
1129
- if (pendingAnsi) {
1130
- result += pendingAnsi;
1131
- pendingAnsi = "";
1132
- }
1133
- result += "\t";
1134
- keptWidth += 3;
1135
- } else {
1136
- keepContiguousPrefix = false;
1137
- pendingAnsi = "";
1138
- }
1139
- visibleSoFar += 3;
1140
- if (visibleSoFar > maxWidth) {
1141
- overflowed = true;
1142
- break;
1143
- }
1144
- i++;
1145
- continue;
1146
- }
1147
-
1148
- let end = i;
1149
- while (end < text.length && text[end] !== "\t") {
1150
- const nextAnsi = extractAnsiCode(text, end);
1151
- if (nextAnsi) {
1152
- break;
1153
- }
1154
- end++;
1155
- }
1156
-
1157
- for (const { segment } of graphemeSegmenter.segment(text.slice(i, end))) {
1158
- const width = graphemeWidth(segment);
1159
- if (keepContiguousPrefix && keptWidth + width <= targetWidth) {
1160
- if (pendingAnsi) {
1161
- result += pendingAnsi;
1162
- pendingAnsi = "";
1163
- }
1164
- result += segment;
1165
- keptWidth += width;
1166
- } else {
1167
- keepContiguousPrefix = false;
1168
- pendingAnsi = "";
1169
- }
1170
-
1171
- visibleSoFar += width;
1172
- if (visibleSoFar > maxWidth) {
1173
- overflowed = true;
1174
- break;
1175
- }
1176
- }
1177
- if (overflowed) {
1178
- break;
1179
- }
1180
- i = end;
1181
- }
1182
- exhaustedInput = i >= text.length;
1183
- }
1184
-
1185
- if (!overflowed && exhaustedInput) {
1186
- return pad ? text + " ".repeat(Math.max(0, maxWidth - visibleSoFar)) : text;
1187
- }
1188
-
1189
- return finalizeTruncatedResult(result, keptWidth, ellipsis, ellipsisWidth, maxWidth, pad);
1190
- }
1191
-
1192
- /**
1193
- * Extract a range of visible columns from a line. Handles ANSI codes and wide chars.
1194
- * @param strict - If true, exclude wide chars at boundary that would extend past the range
1195
- */
1196
- export function sliceByColumn(line: string, startCol: number, length: number, strict = false): string {
1197
- return sliceWithWidth(line, startCol, length, strict).text;
1198
- }
1199
-
1200
- /** Like sliceByColumn but also returns the actual visible width of the result. */
1201
- export function sliceWithWidth(
1202
- line: string,
1203
- startCol: number,
1204
- length: number,
1205
- strict = false,
1206
- ): { text: string; width: number } {
1207
- if (length <= 0) return { text: "", width: 0 };
1208
- const endCol = startCol + length;
1209
- let result = "",
1210
- resultWidth = 0,
1211
- currentCol = 0,
1212
- i = 0,
1213
- pendingAnsi = "";
1214
-
1215
- while (i < line.length) {
1216
- const ansi = extractAnsiCode(line, i);
1217
- if (ansi) {
1218
- if (currentCol >= startCol && currentCol < endCol) result += ansi.code;
1219
- else if (currentCol < startCol) pendingAnsi += ansi.code;
1220
- i += ansi.length;
1221
- continue;
1222
- }
1223
-
1224
- let textEnd = i;
1225
- while (textEnd < line.length && !extractAnsiCode(line, textEnd)) textEnd++;
1226
-
1227
- for (const { segment } of graphemeSegmenter.segment(line.slice(i, textEnd))) {
1228
- const w = graphemeWidth(segment);
1229
- const inRange = currentCol >= startCol && currentCol < endCol;
1230
- const fits = !strict || currentCol + w <= endCol;
1231
- if (inRange && fits) {
1232
- if (pendingAnsi) {
1233
- result += pendingAnsi;
1234
- pendingAnsi = "";
1235
- }
1236
- result += segment;
1237
- resultWidth += w;
1238
- }
1239
- currentCol += w;
1240
- if (currentCol >= endCol) break;
1241
- }
1242
- i = textEnd;
1243
- if (currentCol >= endCol) break;
1244
- }
1245
- return { text: result, width: resultWidth };
1246
- }
1247
-
1248
- // Pooled tracker instance for extractSegments (avoids allocation per call)
1249
- const pooledStyleTracker = new AnsiCodeTracker();
1250
-
1251
- /**
1252
- * Extract "before" and "after" segments from a line in a single pass.
1253
- * Used for overlay compositing where we need content before and after the overlay region.
1254
- * Preserves styling from before the overlay that should affect content after it.
1255
- */
1256
- export function extractSegments(
1257
- line: string,
1258
- beforeEnd: number,
1259
- afterStart: number,
1260
- afterLen: number,
1261
- strictAfter = false,
1262
- ): { before: string; beforeWidth: number; after: string; afterWidth: number } {
1263
- let before = "",
1264
- beforeWidth = 0,
1265
- after = "",
1266
- afterWidth = 0;
1267
- let currentCol = 0,
1268
- i = 0;
1269
- let pendingAnsiBefore = "";
1270
- let afterStarted = false;
1271
- const afterEnd = afterStart + afterLen;
1272
-
1273
- // Track styling state so "after" inherits styling from before the overlay
1274
- pooledStyleTracker.clear();
1275
-
1276
- while (i < line.length) {
1277
- const ansi = extractAnsiCode(line, i);
1278
- if (ansi) {
1279
- // Track all SGR codes to know styling state at afterStart
1280
- pooledStyleTracker.process(ansi.code);
1281
- // Include ANSI codes in their respective segments
1282
- if (currentCol < beforeEnd) {
1283
- pendingAnsiBefore += ansi.code;
1284
- } else if (currentCol >= afterStart && currentCol < afterEnd && afterStarted) {
1285
- // Only include after we've started "after" (styling already prepended)
1286
- after += ansi.code;
1287
- }
1288
- i += ansi.length;
1289
- continue;
1290
- }
1291
-
1292
- let textEnd = i;
1293
- while (textEnd < line.length && !extractAnsiCode(line, textEnd)) textEnd++;
1294
-
1295
- for (const { segment } of graphemeSegmenter.segment(line.slice(i, textEnd))) {
1296
- const w = graphemeWidth(segment);
1297
-
1298
- if (currentCol < beforeEnd && currentCol + w <= beforeEnd) {
1299
- if (pendingAnsiBefore) {
1300
- before += pendingAnsiBefore;
1301
- pendingAnsiBefore = "";
1302
- }
1303
- before += segment;
1304
- beforeWidth += w;
1305
- } else if (currentCol >= afterStart && currentCol < afterEnd) {
1306
- const fits = !strictAfter || currentCol + w <= afterEnd;
1307
- if (fits) {
1308
- // On first "after" grapheme, prepend inherited styling from before overlay
1309
- if (!afterStarted) {
1310
- after += pooledStyleTracker.getActiveCodes();
1311
- afterStarted = true;
1312
- }
1313
- after += segment;
1314
- afterWidth += w;
1315
- }
1316
- }
1317
-
1318
- currentCol += w;
1319
- // Early exit: done with "before" only, or done with both segments
1320
- if (afterLen <= 0 ? currentCol >= beforeEnd : currentCol >= afterEnd) break;
1321
- }
1322
- i = textEnd;
1323
- if (afterLen <= 0 ? currentCol >= beforeEnd : currentCol >= afterEnd) break;
1324
- }
1325
-
1326
- return { before, beforeWidth, after, afterWidth };
1327
- }