rovecode 0.3.3 → 0.4.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (495) hide show
  1. package/CHANGELOG.md +527 -0
  2. package/README.md +46 -48
  3. package/bin/rovecode.js +24 -0
  4. package/dist/cli/app-j6gn14w3.js +2 -0
  5. package/dist/cli/ask-user-cwstt8fz.js +2 -0
  6. package/dist/cli/auth-login-9bbp9915.js +2 -0
  7. package/dist/cli/auth-m8p9grty.js +2 -0
  8. package/dist/cli/bench-16zqdms5.js +9 -0
  9. package/dist/cli/catalog-1xchffa4.js +2 -0
  10. package/dist/cli/cli-1n1zb64f.js +2 -0
  11. package/dist/cli/client-2t9gjkck.js +2 -0
  12. package/dist/cli/commands-exafvm2b.js +2 -0
  13. package/dist/cli/connect-6zde0kn3.js +2 -0
  14. package/dist/cli/context-cmd-5t43wgqt.js +2 -0
  15. package/dist/cli/context-report-kt01pw8y.js +2 -0
  16. package/dist/cli/count-remote-ap7x3vh6.js +2 -0
  17. package/dist/cli/design-ne5zszyh.js +2 -0
  18. package/dist/cli/dispatch-2r5myxye.js +2 -0
  19. package/dist/cli/doctor-ws4fh4tn.js +3 -0
  20. package/dist/cli/executor-bdrjn634.js +2 -0
  21. package/dist/cli/export-1mxb9g5p.js +2 -0
  22. package/dist/cli/files-g104xghh.js +2 -0
  23. package/dist/cli/gauntlet-07xrjpj7.js +2 -0
  24. package/dist/cli/gauntlet-runner-xvy64436.js +10 -0
  25. package/dist/cli/gauntlet-wave3-jm91yt5w.js +5 -0
  26. package/dist/cli/gauntlet-wave4-r13py7p1.js +14 -0
  27. package/dist/cli/hashline-znvrat11.js +2 -0
  28. package/dist/cli/http-xafw6fsh.js +143 -0
  29. package/dist/cli/index-1sgjm25y.js +2 -0
  30. package/dist/cli/init-g2m0tn4m.js +51 -0
  31. package/dist/cli/install-avaqjjqq.js +2 -0
  32. package/dist/cli/loop-mmpfft01.js +2 -0
  33. package/dist/cli/main-0904f6ps.js +5 -0
  34. package/dist/cli/main-0ab9fc26.js +9 -0
  35. package/dist/cli/main-0jys2ccn.js +3 -0
  36. package/dist/cli/main-0mtcdbs7.js +3 -0
  37. package/dist/cli/main-0z1w2zsg.js +3 -0
  38. package/dist/cli/main-1dchs7xv.js +18 -0
  39. package/dist/cli/main-1ereejm1.js +3 -0
  40. package/dist/cli/main-1k1kw6b5.js +3 -0
  41. package/dist/cli/main-27y4sm2k.js +38 -0
  42. package/dist/cli/main-2wwjex5j.js +58 -0
  43. package/dist/cli/main-2yeveeve.js +6 -0
  44. package/dist/cli/main-2yfck9b5.js +3 -0
  45. package/dist/cli/main-2zmzgkwh.js +3 -0
  46. package/dist/cli/main-351pz3z7.js +7 -0
  47. package/dist/cli/main-3gjqfh7a.js +6 -0
  48. package/dist/cli/main-3nf3kgve.js +3 -0
  49. package/dist/cli/main-3pjrb2hd.js +3 -0
  50. package/dist/cli/main-3rxcvgna.js +19 -0
  51. package/dist/cli/main-4b3jgy66.js +19 -0
  52. package/dist/cli/main-4wndhjdc.js +7 -0
  53. package/dist/cli/main-4xcmvxnk.js +3 -0
  54. package/dist/cli/main-5tbz0wbz.js +4 -0
  55. package/dist/cli/main-5ywnwthm.js +3 -0
  56. package/dist/cli/main-6b62vkz0.js +14 -0
  57. package/dist/cli/main-6dnk69vp.js +3 -0
  58. package/dist/cli/main-6genrmhs.js +136 -0
  59. package/dist/cli/main-73g7eff4.js +15 -0
  60. package/dist/cli/main-7c5thhjd.js +5 -0
  61. package/dist/cli/main-7rn6bqje.js +3 -0
  62. package/dist/cli/main-80haw7qk.js +4 -0
  63. package/dist/cli/main-875s60s2.js +4 -0
  64. package/dist/cli/main-8kjxbpw4.js +8 -0
  65. package/dist/cli/main-90ds1z4e.js +10 -0
  66. package/dist/cli/main-9etavkew.js +3 -0
  67. package/dist/cli/main-a9njrkk1.js +3 -0
  68. package/dist/cli/main-aecrjq2d.js +12 -0
  69. package/dist/cli/main-ck9asesq.js +9 -0
  70. package/dist/cli/main-cta9racd.js +4 -0
  71. package/dist/cli/main-ddv7j2ag.js +3 -0
  72. package/dist/cli/main-dfreez27.js +10 -0
  73. package/dist/cli/main-f7rw7des.js +3 -0
  74. package/dist/cli/main-ggcn7rd7.js +5 -0
  75. package/dist/cli/main-gzkmycnv.js +3 -0
  76. package/dist/cli/main-hq51jg8v.js +18 -0
  77. package/dist/cli/main-jft389w9.js +8 -0
  78. package/dist/cli/main-k1eqkg83.js +3 -0
  79. package/dist/cli/main-k2y8a2aw.js +9 -0
  80. package/dist/cli/main-kcpbykxz.js +4 -0
  81. package/dist/cli/main-kd488vje.js +22 -0
  82. package/dist/cli/main-kh32yvgk.js +5 -0
  83. package/dist/cli/main-kqxnqjnv.js +25 -0
  84. package/dist/cli/main-kyn0xnsg.js +3 -0
  85. package/dist/cli/main-m1kk6fp5.js +21 -0
  86. package/dist/cli/main-mv40pcr2.js +4 -0
  87. package/dist/cli/main-n0t3973w.js +3 -0
  88. package/dist/cli/main-nqveez48.js +4 -0
  89. package/dist/cli/main-pknhvrmj.js +3 -0
  90. package/dist/cli/main-pn1w7a7j.js +3 -0
  91. package/dist/cli/main-prxxs70n.js +4 -0
  92. package/dist/cli/main-q3vsesf9.js +3 -0
  93. package/dist/cli/main-qsevpgsv.js +3 -0
  94. package/dist/cli/main-rdgdw24b.js +25 -0
  95. package/dist/cli/main-rfth4tbm.js +16 -0
  96. package/dist/cli/main-rg0wn0xf.js +5 -0
  97. package/dist/cli/main-sdmxhtv8.js +4 -0
  98. package/dist/cli/main-skbp13js.js +18 -0
  99. package/dist/cli/main-t4xnd213.js +7 -0
  100. package/dist/cli/main-vqak588n.js +4 -0
  101. package/dist/cli/main-w2n1303f.js +9 -0
  102. package/dist/cli/main-wbrdspr2.js +5 -0
  103. package/dist/cli/main-wsrg79c1.js +7 -0
  104. package/dist/cli/main-x4r0fne4.js +5 -0
  105. package/dist/cli/main-xea2f3tn.js +6 -0
  106. package/dist/cli/main-xg704a3c.js +3 -0
  107. package/dist/cli/main-xvnrabfp.js +16 -0
  108. package/dist/cli/main-xy53xf0r.js +4 -0
  109. package/dist/cli/main-y1fqy60y.js +3 -0
  110. package/dist/cli/main-yn8cd281.js +34 -0
  111. package/dist/cli/main-yr0ksc0h.js +4 -0
  112. package/dist/cli/main-z2ex2vyf.js +4 -0
  113. package/dist/cli/main-z3aayzvq.js +3 -0
  114. package/dist/cli/main-zaqh35jg.js +3 -0
  115. package/dist/cli/main-zc2e8e46.js +4 -0
  116. package/dist/cli/main-zzrfw6cf.js +13 -0
  117. package/dist/cli/main.js +280 -0
  118. package/dist/cli/market-cmd-e14kmx9n.js +5 -0
  119. package/dist/cli/mcp-login-wq7ktdek.js +2 -0
  120. package/dist/cli/mcp-market-cmd-9mg3jecy.js +2 -0
  121. package/dist/cli/notify-b7qc0cjb.js +2 -0
  122. package/dist/cli/oauth-z8whcgfx.js +2 -0
  123. package/dist/cli/output-b3ewj3ps.js +16 -0
  124. package/dist/cli/profiles-6mr5he5e.js +2 -0
  125. package/dist/cli/provider-config-g7j42q8x.js +2 -0
  126. package/dist/cli/provider-jr1y8vvm.js +2 -0
  127. package/dist/cli/registry-s8yk86g0.js +2 -0
  128. package/dist/cli/registry-t6p8d4mn.js +2 -0
  129. package/dist/cli/repl-bajwe1mh.js +11 -0
  130. package/dist/cli/resume-rwn9nz7y.js +2 -0
  131. package/dist/cli/run-flags-nah7ndpt.js +2 -0
  132. package/dist/cli/runtime-n7gafzhb.js +2 -0
  133. package/dist/cli/sandbox-config-emdy18x4.js +2 -0
  134. package/dist/cli/server-b0nvs2bn.js +5 -0
  135. package/dist/cli/session-arg-y75wd4kj.js +2 -0
  136. package/dist/cli/session-j62evmjq.js +2 -0
  137. package/dist/cli/sessions-cmd-tsnwz0ns.js +7 -0
  138. package/dist/cli/settings-df10wfez.js +2 -0
  139. package/dist/cli/setup-jzvv72fg.js +2 -0
  140. package/dist/cli/sextant-smoke-37m81ke6.js +5 -0
  141. package/dist/cli/skills-cmd-gjxnxnhx.js +2 -0
  142. package/dist/cli/smoke-p7748apt.js +8 -0
  143. package/dist/cli/start-chat-s4st3mm0.js +12 -0
  144. package/dist/cli/stream-gmeyewds.js +2 -0
  145. package/dist/cli/task-gh0kkp3n.js +2 -0
  146. package/dist/cli/tasks-z1kfpe8e.js +2 -0
  147. package/dist/cli/thinking-0eqkrz6t.js +2 -0
  148. package/dist/cli/todo-5brcrt9m.js +2 -0
  149. package/dist/cli/tools-7pzm0vj9.js +2 -0
  150. package/dist/cli/tools-s635p6s8.js +2 -0
  151. package/dist/cli/trust-cmd-cjav8zgm.js +2 -0
  152. package/dist/cli/update-check-pt31bm2f.js +2 -0
  153. package/dist/cli/update-cmd-tk131s9t.js +2 -0
  154. package/dist/cli/voice-56nabd8d.js +2 -0
  155. package/dist/cli/webfetch-xd8q596m.js +2 -0
  156. package/dist/cli/websearch-5hkf98k1.js +2 -0
  157. package/dist/cli/workflow-cmd-cy3cvzjp.js +4 -0
  158. package/dist/cli/workspace-q10g5z3e.js +2 -0
  159. package/dist/lib/index.js +62 -0
  160. package/dist/lib/models-index.json +1 -0
  161. package/dist/lib/plugins.js +55 -0
  162. package/dist/lib/providers.js +17 -0
  163. package/dist/lib/public-api.js +20 -0
  164. package/dist/lib/sdk.js +360 -0
  165. package/package.json +84 -72
  166. package/bin/rovecode.ts +0 -21
  167. package/src/acp/server.ts +0 -374
  168. package/src/cli/auth-login.ts +0 -122
  169. package/src/cli/connect.ts +0 -244
  170. package/src/cli/context-cmd.ts +0 -199
  171. package/src/cli/dispatch.ts +0 -82
  172. package/src/cli/doctor.ts +0 -362
  173. package/src/cli/export.ts +0 -276
  174. package/src/cli/help.ts +0 -293
  175. package/src/cli/is-tui-invocation.ts +0 -8
  176. package/src/cli/main.ts +0 -583
  177. package/src/cli/market-cmd.ts +0 -658
  178. package/src/cli/mcp-login.ts +0 -141
  179. package/src/cli/mcp-market-cmd.ts +0 -302
  180. package/src/cli/output.ts +0 -382
  181. package/src/cli/repl.ts +0 -250
  182. package/src/cli/repomap-root.ts +0 -14
  183. package/src/cli/resume.ts +0 -57
  184. package/src/cli/run-flags.ts +0 -43
  185. package/src/cli/run-limits.ts +0 -78
  186. package/src/cli/runtime.ts +0 -931
  187. package/src/cli/session-arg.ts +0 -30
  188. package/src/cli/sessions-cmd.ts +0 -145
  189. package/src/cli/setup.ts +0 -153
  190. package/src/cli/skills-cmd.ts +0 -194
  191. package/src/cli/start-chat.ts +0 -65
  192. package/src/cli/trust-cmd.ts +0 -52
  193. package/src/coding/bash.ts +0 -148
  194. package/src/coding/checkpoints.ts +0 -327
  195. package/src/coding/diff.ts +0 -138
  196. package/src/coding/files.ts +0 -341
  197. package/src/coding/hashline.ts +0 -274
  198. package/src/coding/lsp-gate.ts +0 -254
  199. package/src/coding/lsp-servers.ts +0 -147
  200. package/src/coding/lsp.ts +0 -283
  201. package/src/coding/repomap-cache.ts +0 -99
  202. package/src/coding/repomap-files.ts +0 -192
  203. package/src/coding/repomap.ts +0 -481
  204. package/src/core/agents.ts +0 -255
  205. package/src/core/compaction.ts +0 -259
  206. package/src/core/config.ts +0 -289
  207. package/src/core/context-report.ts +0 -228
  208. package/src/core/context.ts +0 -60
  209. package/src/core/count-remote.ts +0 -107
  210. package/src/core/execpolicy-rules.ts +0 -196
  211. package/src/core/execpolicy.ts +0 -385
  212. package/src/core/executor.ts +0 -454
  213. package/src/core/guardrails.ts +0 -400
  214. package/src/core/hooks.ts +0 -411
  215. package/src/core/images.ts +0 -230
  216. package/src/core/intro.ts +0 -266
  217. package/src/core/loop.ts +0 -567
  218. package/src/core/modes.ts +0 -372
  219. package/src/core/orchestrator.ts +0 -245
  220. package/src/core/proc-group.ts +0 -48
  221. package/src/core/project-trust.ts +0 -98
  222. package/src/core/reflection.ts +0 -165
  223. package/src/core/sandbox-config.ts +0 -186
  224. package/src/core/session-id.ts +0 -24
  225. package/src/core/session-images.ts +0 -73
  226. package/src/core/session-ops.ts +0 -183
  227. package/src/core/session-text.ts +0 -29
  228. package/src/core/session.ts +0 -469
  229. package/src/core/settings.ts +0 -170
  230. package/src/core/tasks.ts +0 -646
  231. package/src/core/token-scale.ts +0 -108
  232. package/src/core/tools.ts +0 -309
  233. package/src/core/trust.ts +0 -104
  234. package/src/core/types.ts +0 -330
  235. package/src/core/update-check.ts +0 -171
  236. package/src/core/usage.ts +0 -204
  237. package/src/core/validate.ts +0 -121
  238. package/src/core/verify-gate.ts +0 -159
  239. package/src/core/verify.ts +0 -236
  240. package/src/core/voice.ts +0 -158
  241. package/src/core/win-job.ts +0 -183
  242. package/src/core/workspace.ts +0 -184
  243. package/src/design/audit.ts +0 -797
  244. package/src/design/direction.ts +0 -190
  245. package/src/design/rules.ts +0 -157
  246. package/src/eval/bench.ts +0 -150
  247. package/src/eval/gauntlet-runner.ts +0 -215
  248. package/src/eval/gauntlet-support.ts +0 -84
  249. package/src/eval/gauntlet-wave3.ts +0 -269
  250. package/src/eval/gauntlet-wave4.ts +0 -217
  251. package/src/eval/gauntlet.ts +0 -253
  252. package/src/index.ts +0 -17
  253. package/src/lanes/agy.ts +0 -95
  254. package/src/lanes/approval.ts +0 -24
  255. package/src/lanes/claude.ts +0 -129
  256. package/src/lanes/codex.ts +0 -127
  257. package/src/lanes/events.ts +0 -130
  258. package/src/lanes/job.ts +0 -142
  259. package/src/lanes/opencode.ts +0 -122
  260. package/src/lanes/process.ts +0 -184
  261. package/src/lanes/progress.ts +0 -183
  262. package/src/lanes/registry.ts +0 -178
  263. package/src/lanes/runner.ts +0 -124
  264. package/src/lanes/types.ts +0 -112
  265. package/src/market/catalogs/mcp-docs.json +0 -111
  266. package/src/market/catalogs/plugins.json +0 -111
  267. package/src/market/catalogs/skills.json +0 -478
  268. package/src/market/clone.ts +0 -72
  269. package/src/market/context-cost.ts +0 -121
  270. package/src/market/digest.ts +0 -106
  271. package/src/market/index.ts +0 -22
  272. package/src/market/install.ts +0 -578
  273. package/src/market/manifest.ts +0 -187
  274. package/src/market/prereq.ts +0 -145
  275. package/src/market/registry.ts +0 -363
  276. package/src/market/resolve.ts +0 -111
  277. package/src/market/types.ts +0 -236
  278. package/src/market/validate.ts +0 -227
  279. package/src/mcp/client.ts +0 -449
  280. package/src/mcp/config.ts +0 -252
  281. package/src/mcp/local-package.ts +0 -211
  282. package/src/mcp/market-catalog.ts +0 -84
  283. package/src/mcp/market-install.ts +0 -289
  284. package/src/mcp/market.ts +0 -362
  285. package/src/mcp/oauth.ts +0 -251
  286. package/src/mcp/prompts-resources.ts +0 -249
  287. package/src/mcp/shared.ts +0 -149
  288. package/src/mcp/status.ts +0 -67
  289. package/src/mcp/tools.ts +0 -275
  290. package/src/mcp/transport.ts +0 -122
  291. package/src/mcp/trust.ts +0 -25
  292. package/src/memory/blocks.ts +0 -278
  293. package/src/memory/recall.ts +0 -355
  294. package/src/memory/scope.ts +0 -182
  295. package/src/memory/store.ts +0 -105
  296. package/src/memory/tools.ts +0 -99
  297. package/src/plugins/cli.ts +0 -119
  298. package/src/plugins/discover.ts +0 -108
  299. package/src/plugins/index.ts +0 -50
  300. package/src/plugins/install.ts +0 -184
  301. package/src/plugins/load.ts +0 -124
  302. package/src/plugins/manifest.ts +0 -92
  303. package/src/plugins/state.ts +0 -83
  304. package/src/providers/auth.ts +0 -408
  305. package/src/providers/cache.ts +0 -223
  306. package/src/providers/catalog-local.ts +0 -160
  307. package/src/providers/catalog.ts +0 -421
  308. package/src/providers/middleware-context.ts +0 -86
  309. package/src/providers/middleware.ts +0 -373
  310. package/src/providers/model-list.ts +0 -23
  311. package/src/providers/oauth/common.ts +0 -105
  312. package/src/providers/oauth/device-code.ts +0 -107
  313. package/src/providers/oauth/github-copilot.ts +0 -146
  314. package/src/providers/oauth/loopback.ts +0 -158
  315. package/src/providers/oauth/openai.ts +0 -163
  316. package/src/providers/oauth/openrouter.ts +0 -89
  317. package/src/providers/oauth/pkce.ts +0 -45
  318. package/src/providers/oauth/registry.ts +0 -39
  319. package/src/providers/oauth/seam.ts +0 -89
  320. package/src/providers/profile-glm53.ts +0 -111
  321. package/src/providers/profile-sonnet5-persona.ts +0 -65
  322. package/src/providers/profile-sonnet5-voice.ts +0 -23
  323. package/src/providers/profiles.ts +0 -156
  324. package/src/providers/provider-config.ts +0 -311
  325. package/src/providers/registry.ts +0 -333
  326. package/src/providers/responses.ts +0 -209
  327. package/src/providers/retry.ts +0 -234
  328. package/src/providers/router.ts +0 -294
  329. package/src/providers/sse.ts +0 -26
  330. package/src/providers/stream-errors.ts +0 -117
  331. package/src/providers/stream.ts +0 -566
  332. package/src/providers/thinking.ts +0 -189
  333. package/src/providers/wire-messages.ts +0 -129
  334. package/src/providers/wire-responses.ts +0 -79
  335. package/src/providers/wire-select.ts +0 -53
  336. package/src/server/http.ts +0 -291
  337. package/src/server/openapi.ts +0 -246
  338. package/src/sextant/card-hits.ts +0 -102
  339. package/src/sextant/card-keys.ts +0 -55
  340. package/src/sextant/context-source.ts +0 -157
  341. package/src/sextant/crew-cards.ts +0 -350
  342. package/src/sextant/draw-agents.ts +0 -273
  343. package/src/sextant/draw-code.ts +0 -388
  344. package/src/sextant/draw-context.ts +0 -222
  345. package/src/sextant/draw-frame.ts +0 -164
  346. package/src/sextant/draw-market.ts +0 -573
  347. package/src/sextant/draw-messages.ts +0 -386
  348. package/src/sextant/draw-pet.ts +0 -230
  349. package/src/sextant/draw-plan.ts +0 -187
  350. package/src/sextant/draw-tabs.ts +0 -85
  351. package/src/sextant/draw-util.ts +0 -65
  352. package/src/sextant/draw-wizard.ts +0 -378
  353. package/src/sextant/engine.ts +0 -230
  354. package/src/sextant/frame-hits.ts +0 -25
  355. package/src/sextant/frame.ts +0 -101
  356. package/src/sextant/git-status.ts +0 -197
  357. package/src/sextant/grid.ts +0 -59
  358. package/src/sextant/input.ts +0 -119
  359. package/src/sextant/keys.ts +0 -521
  360. package/src/sextant/layout.ts +0 -86
  361. package/src/sextant/local-commands.ts +0 -169
  362. package/src/sextant/market-source.ts +0 -287
  363. package/src/sextant/mentions.ts +0 -200
  364. package/src/sextant/message-hits.ts +0 -26
  365. package/src/sextant/model.ts +0 -387
  366. package/src/sextant/overlays.ts +0 -456
  367. package/src/sextant/panel-hits.ts +0 -38
  368. package/src/sextant/pet.ts +0 -399
  369. package/src/sextant/screen.ts +0 -324
  370. package/src/sextant/scroll-hits.ts +0 -66
  371. package/src/sextant/scrollbar.ts +0 -82
  372. package/src/sextant/sextant-bridge.ts +0 -174
  373. package/src/sextant/sextant-cards.ts +0 -142
  374. package/src/sextant/sextant-diff-base.ts +0 -63
  375. package/src/sextant/sextant-files.ts +0 -154
  376. package/src/sextant/sextant-frame-loop.ts +0 -335
  377. package/src/sextant/sextant-renderer.ts +0 -574
  378. package/src/sextant/sextant-repo.ts +0 -140
  379. package/src/sextant/theme.ts +0 -66
  380. package/src/sextant/tool-rows.ts +0 -189
  381. package/src/sextant/types.ts +0 -493
  382. package/src/skills/index.ts +0 -387
  383. package/src/skills/pack.ts +0 -220
  384. package/src/skills/spec.ts +0 -162
  385. package/src/skills/tools.ts +0 -69
  386. package/src/skills/versioned.ts +0 -227
  387. package/src/telemetry/otel-export.ts +0 -122
  388. package/src/telemetry/otel-lanes.ts +0 -89
  389. package/src/telemetry/otel-logs.ts +0 -131
  390. package/src/telemetry/otel-metrics.ts +0 -136
  391. package/src/telemetry/otel.ts +0 -397
  392. package/src/telemetry/otlp.ts +0 -76
  393. package/src/tools/ask-user.ts +0 -156
  394. package/src/tools/bash-bg.ts +0 -94
  395. package/src/tools/bash-jobs.ts +0 -237
  396. package/src/tools/design.ts +0 -151
  397. package/src/tools/evalcell.ts +0 -338
  398. package/src/tools/html-text.ts +0 -139
  399. package/src/tools/provider.ts +0 -149
  400. package/src/tools/task.ts +0 -250
  401. package/src/tools/todo.ts +0 -320
  402. package/src/tools/webfetch.ts +0 -332
  403. package/src/tools/websearch.ts +0 -359
  404. package/src/tui/agents-cmd.ts +0 -41
  405. package/src/tui/app.ts +0 -749
  406. package/src/tui/attach.ts +0 -127
  407. package/src/tui/boot-notes.ts +0 -41
  408. package/src/tui/builtin-prompts.ts +0 -59
  409. package/src/tui/checkpoints-cmd.ts +0 -70
  410. package/src/tui/clipboard-image.ts +0 -81
  411. package/src/tui/clipboard.ts +0 -78
  412. package/src/tui/commands.ts +0 -283
  413. package/src/tui/config-view.ts +0 -53
  414. package/src/tui/context-cmds.ts +0 -282
  415. package/src/tui/cost.ts +0 -108
  416. package/src/tui/crash-guard.ts +0 -173
  417. package/src/tui/focus-terminal.ts +0 -34
  418. package/src/tui/git-cmds.ts +0 -273
  419. package/src/tui/git-plain.ts +0 -58
  420. package/src/tui/info-cmd.ts +0 -150
  421. package/src/tui/input-plain.ts +0 -76
  422. package/src/tui/mcp-cmd.ts +0 -128
  423. package/src/tui/memory-note.ts +0 -77
  424. package/src/tui/modes-cmd.ts +0 -45
  425. package/src/tui/notify-seq.ts +0 -100
  426. package/src/tui/notify.ts +0 -318
  427. package/src/tui/overlays.ts +0 -97
  428. package/src/tui/pi-renderer.ts +0 -428
  429. package/src/tui/providers-cmd.ts +0 -377
  430. package/src/tui/reasoning-view.ts +0 -56
  431. package/src/tui/renderer.ts +0 -128
  432. package/src/tui/replay-marker.ts +0 -29
  433. package/src/tui/session-cmd.ts +0 -148
  434. package/src/tui/session-manage.ts +0 -95
  435. package/src/tui/sextant-attach.ts +0 -102
  436. package/src/tui/sextant-io.ts +0 -202
  437. package/src/tui/sextant-smoke.ts +0 -110
  438. package/src/tui/shell-cmd.ts +0 -158
  439. package/src/tui/smoke.ts +0 -72
  440. package/src/tui/staged-terminal.ts +0 -50
  441. package/src/tui/startup.ts +0 -12
  442. package/src/tui/theme.ts +0 -59
  443. package/src/tui/todo-label.ts +0 -7
  444. package/src/tui/trust-card.ts +0 -107
  445. package/src/tui/tui-commands.ts +0 -87
  446. package/tsconfig.json +0 -30
  447. package/vendor/pi-tui/LICENSE +0 -21
  448. package/vendor/pi-tui/PATCHES.md +0 -12
  449. package/vendor/pi-tui/PROVENANCE.md +0 -12
  450. package/vendor/pi-tui/README.upstream.md +0 -854
  451. package/vendor/pi-tui/native/win32/prebuilds/win32-arm64/win32-console-mode.node +0 -0
  452. package/vendor/pi-tui/native/win32/prebuilds/win32-x64/win32-console-mode.node +0 -0
  453. package/vendor/pi-tui/src/alt-screen-search.ts +0 -158
  454. package/vendor/pi-tui/src/autocomplete.ts +0 -827
  455. package/vendor/pi-tui/src/components/alt-screen-flash.ts +0 -52
  456. package/vendor/pi-tui/src/components/box.ts +0 -138
  457. package/vendor/pi-tui/src/components/cancellable-loader.ts +0 -41
  458. package/vendor/pi-tui/src/components/editor.ts +0 -2364
  459. package/vendor/pi-tui/src/components/h-stack.ts +0 -45
  460. package/vendor/pi-tui/src/components/image.ts +0 -128
  461. package/vendor/pi-tui/src/components/input.ts +0 -448
  462. package/vendor/pi-tui/src/components/loader.ts +0 -93
  463. package/vendor/pi-tui/src/components/markdown.ts +0 -1016
  464. package/vendor/pi-tui/src/components/scroll-view.ts +0 -217
  465. package/vendor/pi-tui/src/components/select-list.ts +0 -230
  466. package/vendor/pi-tui/src/components/settings-list.ts +0 -277
  467. package/vendor/pi-tui/src/components/spacer.ts +0 -29
  468. package/vendor/pi-tui/src/components/stack.ts +0 -155
  469. package/vendor/pi-tui/src/components/text.ts +0 -108
  470. package/vendor/pi-tui/src/components/truncated-text.ts +0 -66
  471. package/vendor/pi-tui/src/components/v-stack.ts +0 -34
  472. package/vendor/pi-tui/src/editor-component.ts +0 -75
  473. package/vendor/pi-tui/src/fuzzy.ts +0 -138
  474. package/vendor/pi-tui/src/index.ts +0 -149
  475. package/vendor/pi-tui/src/keybindings.ts +0 -321
  476. package/vendor/pi-tui/src/keys.ts +0 -1402
  477. package/vendor/pi-tui/src/kill-ring.ts +0 -47
  478. package/vendor/pi-tui/src/latex.ts +0 -1381
  479. package/vendor/pi-tui/src/layout-node.ts +0 -52
  480. package/vendor/pi-tui/src/layout.ts +0 -411
  481. package/vendor/pi-tui/src/native-modifiers.ts +0 -60
  482. package/vendor/pi-tui/src/native-module-path.ts +0 -32
  483. package/vendor/pi-tui/src/stdin-buffer.ts +0 -445
  484. package/vendor/pi-tui/src/terminal-colors.ts +0 -74
  485. package/vendor/pi-tui/src/terminal-image.ts +0 -701
  486. package/vendor/pi-tui/src/terminal.ts +0 -554
  487. package/vendor/pi-tui/src/tui-alt-screen.ts +0 -1379
  488. package/vendor/pi-tui/src/tui-main-screen.ts +0 -655
  489. package/vendor/pi-tui/src/tui.ts +0 -1264
  490. package/vendor/pi-tui/src/undo-stack.ts +0 -29
  491. package/vendor/pi-tui/src/utils.ts +0 -1327
  492. package/vendor/pi-tui/src/word-navigation.ts +0 -118
  493. package/vendor/pi-tui/test/test-themes.ts +0 -39
  494. package/vendor/pi-tui/test/virtual-terminal.ts +0 -219
  495. /package/{src/providers → dist/cli}/models-index.json +0 -0
@@ -1,1402 +0,0 @@
1
- // @ts-nocheck -- vendored by rovecode: upstream-checked at pinned SHA 853a80d2; see ../PATCHES.md
2
- /**
3
- * Keyboard input handling for terminal applications.
4
- *
5
- * Supports both legacy terminal sequences and Kitty keyboard protocol.
6
- * See: https://sw.kovidgoyal.net/kitty/keyboard-protocol/
7
- * Reference: https://github.com/sst/opentui/blob/7da92b4088aebfe27b9f691c04163a48821e49fd/packages/core/src/lib/parse.keypress.ts
8
- *
9
- * Symbol keys are also supported, however some ctrl+symbol combos
10
- * overlap with ASCII codes, e.g. ctrl+[ = ESC.
11
- * See: https://sw.kovidgoyal.net/kitty/keyboard-protocol/#legacy-ctrl-mapping-of-ascii-keys
12
- * Those can still be * used for ctrl+shift combos
13
- *
14
- * API:
15
- * - matchesKey(data, keyId) - Check if input matches a key identifier
16
- * - parseKey(data) - Parse input and return the key identifier
17
- * - Key - Helper object for creating typed key identifiers
18
- * - setKittyProtocolActive(active) - Set global Kitty protocol state
19
- * - isKittyProtocolActive() - Query global Kitty protocol state
20
- */
21
-
22
- // =============================================================================
23
- // Global Kitty Protocol State
24
- // =============================================================================
25
-
26
- let _kittyProtocolActive = false;
27
-
28
- /**
29
- * Set the global Kitty keyboard protocol state.
30
- * Called by ProcessTerminal after detecting protocol support.
31
- */
32
- export function setKittyProtocolActive(active: boolean): void {
33
- _kittyProtocolActive = active;
34
- }
35
-
36
- /**
37
- * Query whether Kitty keyboard protocol is currently active.
38
- */
39
- export function isKittyProtocolActive(): boolean {
40
- return _kittyProtocolActive;
41
- }
42
-
43
- // =============================================================================
44
- // Type-Safe Key Identifiers
45
- // =============================================================================
46
-
47
- type Letter =
48
- | "a"
49
- | "b"
50
- | "c"
51
- | "d"
52
- | "e"
53
- | "f"
54
- | "g"
55
- | "h"
56
- | "i"
57
- | "j"
58
- | "k"
59
- | "l"
60
- | "m"
61
- | "n"
62
- | "o"
63
- | "p"
64
- | "q"
65
- | "r"
66
- | "s"
67
- | "t"
68
- | "u"
69
- | "v"
70
- | "w"
71
- | "x"
72
- | "y"
73
- | "z";
74
-
75
- type Digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
76
-
77
- type SymbolKey =
78
- | "`"
79
- | "-"
80
- | "="
81
- | "["
82
- | "]"
83
- | "\\"
84
- | ";"
85
- | "'"
86
- | ","
87
- | "."
88
- | "/"
89
- | "!"
90
- | "@"
91
- | "#"
92
- | "$"
93
- | "%"
94
- | "^"
95
- | "&"
96
- | "*"
97
- | "("
98
- | ")"
99
- | "_"
100
- | "+"
101
- | "|"
102
- | "~"
103
- | "{"
104
- | "}"
105
- | ":"
106
- | "<"
107
- | ">"
108
- | "?";
109
-
110
- type SpecialKey =
111
- | "escape"
112
- | "esc"
113
- | "enter"
114
- | "return"
115
- | "tab"
116
- | "space"
117
- | "backspace"
118
- | "delete"
119
- | "insert"
120
- | "clear"
121
- | "home"
122
- | "end"
123
- | "pageUp"
124
- | "pageDown"
125
- | "up"
126
- | "down"
127
- | "left"
128
- | "right"
129
- | "f1"
130
- | "f2"
131
- | "f3"
132
- | "f4"
133
- | "f5"
134
- | "f6"
135
- | "f7"
136
- | "f8"
137
- | "f9"
138
- | "f10"
139
- | "f11"
140
- | "f12";
141
-
142
- type BaseKey = Letter | Digit | SymbolKey | SpecialKey;
143
- type ModifierName = "ctrl" | "shift" | "alt" | "super";
144
-
145
- type ModifiedKeyId<Key extends string, RemainingModifiers extends ModifierName = ModifierName> = {
146
- [M in RemainingModifiers]: `${M}+${Key}` | `${M}+${ModifiedKeyId<Key, Exclude<RemainingModifiers, M>>}`;
147
- }[RemainingModifiers];
148
-
149
- /**
150
- * Union type of all valid key identifiers.
151
- * Provides autocomplete and catches typos at compile time.
152
- */
153
- export type KeyId = BaseKey | ModifiedKeyId<BaseKey>;
154
-
155
- /**
156
- * Helper object for creating typed key identifiers with autocomplete.
157
- *
158
- * Usage:
159
- * - Key.escape, Key.enter, Key.tab, etc. for special keys
160
- * - Key.backtick, Key.comma, Key.period, etc. for symbol keys
161
- * - Key.ctrl("c"), Key.alt("x"), Key.super("k") for single modifiers
162
- * - Key.ctrlShift("p"), Key.ctrlAlt("x"), Key.ctrlSuper("k") for combined modifiers
163
- */
164
- export const Key = {
165
- // Special keys
166
- escape: "escape" as const,
167
- esc: "esc" as const,
168
- enter: "enter" as const,
169
- return: "return" as const,
170
- tab: "tab" as const,
171
- space: "space" as const,
172
- backspace: "backspace" as const,
173
- delete: "delete" as const,
174
- insert: "insert" as const,
175
- clear: "clear" as const,
176
- home: "home" as const,
177
- end: "end" as const,
178
- pageUp: "pageUp" as const,
179
- pageDown: "pageDown" as const,
180
- up: "up" as const,
181
- down: "down" as const,
182
- left: "left" as const,
183
- right: "right" as const,
184
- f1: "f1" as const,
185
- f2: "f2" as const,
186
- f3: "f3" as const,
187
- f4: "f4" as const,
188
- f5: "f5" as const,
189
- f6: "f6" as const,
190
- f7: "f7" as const,
191
- f8: "f8" as const,
192
- f9: "f9" as const,
193
- f10: "f10" as const,
194
- f11: "f11" as const,
195
- f12: "f12" as const,
196
-
197
- // Symbol keys
198
- backtick: "`" as const,
199
- hyphen: "-" as const,
200
- equals: "=" as const,
201
- leftbracket: "[" as const,
202
- rightbracket: "]" as const,
203
- backslash: "\\" as const,
204
- semicolon: ";" as const,
205
- quote: "'" as const,
206
- comma: "," as const,
207
- period: "." as const,
208
- slash: "/" as const,
209
- exclamation: "!" as const,
210
- at: "@" as const,
211
- hash: "#" as const,
212
- dollar: "$" as const,
213
- percent: "%" as const,
214
- caret: "^" as const,
215
- ampersand: "&" as const,
216
- asterisk: "*" as const,
217
- leftparen: "(" as const,
218
- rightparen: ")" as const,
219
- underscore: "_" as const,
220
- plus: "+" as const,
221
- pipe: "|" as const,
222
- tilde: "~" as const,
223
- leftbrace: "{" as const,
224
- rightbrace: "}" as const,
225
- colon: ":" as const,
226
- lessthan: "<" as const,
227
- greaterthan: ">" as const,
228
- question: "?" as const,
229
-
230
- // Single modifiers
231
- ctrl: <K extends BaseKey>(key: K): `ctrl+${K}` => `ctrl+${key}`,
232
- shift: <K extends BaseKey>(key: K): `shift+${K}` => `shift+${key}`,
233
- alt: <K extends BaseKey>(key: K): `alt+${K}` => `alt+${key}`,
234
- super: <K extends BaseKey>(key: K): `super+${K}` => `super+${key}`,
235
-
236
- // Combined modifiers
237
- ctrlShift: <K extends BaseKey>(key: K): `ctrl+shift+${K}` => `ctrl+shift+${key}`,
238
- shiftCtrl: <K extends BaseKey>(key: K): `shift+ctrl+${K}` => `shift+ctrl+${key}`,
239
- ctrlAlt: <K extends BaseKey>(key: K): `ctrl+alt+${K}` => `ctrl+alt+${key}`,
240
- altCtrl: <K extends BaseKey>(key: K): `alt+ctrl+${K}` => `alt+ctrl+${key}`,
241
- shiftAlt: <K extends BaseKey>(key: K): `shift+alt+${K}` => `shift+alt+${key}`,
242
- altShift: <K extends BaseKey>(key: K): `alt+shift+${K}` => `alt+shift+${key}`,
243
- ctrlSuper: <K extends BaseKey>(key: K): `ctrl+super+${K}` => `ctrl+super+${key}`,
244
- superCtrl: <K extends BaseKey>(key: K): `super+ctrl+${K}` => `super+ctrl+${key}`,
245
- shiftSuper: <K extends BaseKey>(key: K): `shift+super+${K}` => `shift+super+${key}`,
246
- superShift: <K extends BaseKey>(key: K): `super+shift+${K}` => `super+shift+${key}`,
247
- altSuper: <K extends BaseKey>(key: K): `alt+super+${K}` => `alt+super+${key}`,
248
- superAlt: <K extends BaseKey>(key: K): `super+alt+${K}` => `super+alt+${key}`,
249
-
250
- // Triple modifiers
251
- ctrlShiftAlt: <K extends BaseKey>(key: K): `ctrl+shift+alt+${K}` => `ctrl+shift+alt+${key}`,
252
- ctrlShiftSuper: <K extends BaseKey>(key: K): `ctrl+shift+super+${K}` => `ctrl+shift+super+${key}`,
253
- } as const;
254
-
255
- // =============================================================================
256
- // Constants
257
- // =============================================================================
258
-
259
- const SYMBOL_KEYS = new Set([
260
- "`",
261
- "-",
262
- "=",
263
- "[",
264
- "]",
265
- "\\",
266
- ";",
267
- "'",
268
- ",",
269
- ".",
270
- "/",
271
- "!",
272
- "@",
273
- "#",
274
- "$",
275
- "%",
276
- "^",
277
- "&",
278
- "*",
279
- "(",
280
- ")",
281
- "_",
282
- "+",
283
- "|",
284
- "~",
285
- "{",
286
- "}",
287
- ":",
288
- "<",
289
- ">",
290
- "?",
291
- ]);
292
-
293
- const MODIFIERS = {
294
- shift: 1,
295
- alt: 2,
296
- ctrl: 4,
297
- super: 8,
298
- } as const;
299
-
300
- const LOCK_MASK = 64 + 128; // Caps Lock + Num Lock
301
-
302
- const CODEPOINTS = {
303
- escape: 27,
304
- tab: 9,
305
- enter: 13,
306
- space: 32,
307
- backspace: 127,
308
- kpEnter: 57414, // Numpad Enter (Kitty protocol)
309
- } as const;
310
-
311
- const ARROW_CODEPOINTS = {
312
- up: -1,
313
- down: -2,
314
- right: -3,
315
- left: -4,
316
- } as const;
317
-
318
- const FUNCTIONAL_CODEPOINTS = {
319
- delete: -10,
320
- insert: -11,
321
- pageUp: -12,
322
- pageDown: -13,
323
- home: -14,
324
- end: -15,
325
- } as const;
326
-
327
- const KITTY_FUNCTIONAL_KEY_EQUIVALENTS = new Map<number, number>([
328
- [57399, 48], // KP_0 -> 0
329
- [57400, 49], // KP_1 -> 1
330
- [57401, 50], // KP_2 -> 2
331
- [57402, 51], // KP_3 -> 3
332
- [57403, 52], // KP_4 -> 4
333
- [57404, 53], // KP_5 -> 5
334
- [57405, 54], // KP_6 -> 6
335
- [57406, 55], // KP_7 -> 7
336
- [57407, 56], // KP_8 -> 8
337
- [57408, 57], // KP_9 -> 9
338
- [57409, 46], // KP_DECIMAL -> .
339
- [57410, 47], // KP_DIVIDE -> /
340
- [57411, 42], // KP_MULTIPLY -> *
341
- [57412, 45], // KP_SUBTRACT -> -
342
- [57413, 43], // KP_ADD -> +
343
- [57415, 61], // KP_EQUAL -> =
344
- [57416, 44], // KP_SEPARATOR -> ,
345
- [57417, ARROW_CODEPOINTS.left],
346
- [57418, ARROW_CODEPOINTS.right],
347
- [57419, ARROW_CODEPOINTS.up],
348
- [57420, ARROW_CODEPOINTS.down],
349
- [57421, FUNCTIONAL_CODEPOINTS.pageUp],
350
- [57422, FUNCTIONAL_CODEPOINTS.pageDown],
351
- [57423, FUNCTIONAL_CODEPOINTS.home],
352
- [57424, FUNCTIONAL_CODEPOINTS.end],
353
- [57425, FUNCTIONAL_CODEPOINTS.insert],
354
- [57426, FUNCTIONAL_CODEPOINTS.delete],
355
- ]);
356
-
357
- function normalizeKittyFunctionalCodepoint(codepoint: number): number {
358
- return KITTY_FUNCTIONAL_KEY_EQUIVALENTS.get(codepoint) ?? codepoint;
359
- }
360
-
361
- function normalizeShiftedLetterIdentityCodepoint(codepoint: number, modifier: number): number {
362
- const effectiveModifier = modifier & ~LOCK_MASK;
363
- if ((effectiveModifier & MODIFIERS.shift) !== 0 && codepoint >= 65 && codepoint <= 90) {
364
- return codepoint + 32;
365
- }
366
- return codepoint;
367
- }
368
-
369
- const LEGACY_KEY_SEQUENCES = {
370
- up: ["\x1b[A", "\x1bOA"],
371
- down: ["\x1b[B", "\x1bOB"],
372
- right: ["\x1b[C", "\x1bOC"],
373
- left: ["\x1b[D", "\x1bOD"],
374
- home: ["\x1b[H", "\x1bOH", "\x1b[1~", "\x1b[7~"],
375
- end: ["\x1b[F", "\x1bOF", "\x1b[4~", "\x1b[8~"],
376
- insert: ["\x1b[2~"],
377
- delete: ["\x1b[3~"],
378
- pageUp: ["\x1b[5~", "\x1b[[5~"],
379
- pageDown: ["\x1b[6~", "\x1b[[6~"],
380
- clear: ["\x1b[E", "\x1bOE"],
381
- f1: ["\x1bOP", "\x1b[11~", "\x1b[[A"],
382
- f2: ["\x1bOQ", "\x1b[12~", "\x1b[[B"],
383
- f3: ["\x1bOR", "\x1b[13~", "\x1b[[C"],
384
- f4: ["\x1bOS", "\x1b[14~", "\x1b[[D"],
385
- f5: ["\x1b[15~", "\x1b[[E"],
386
- f6: ["\x1b[17~"],
387
- f7: ["\x1b[18~"],
388
- f8: ["\x1b[19~"],
389
- f9: ["\x1b[20~"],
390
- f10: ["\x1b[21~"],
391
- f11: ["\x1b[23~"],
392
- f12: ["\x1b[24~"],
393
- } as const;
394
-
395
- const LEGACY_SHIFT_SEQUENCES = {
396
- up: ["\x1b[a"],
397
- down: ["\x1b[b"],
398
- right: ["\x1b[c"],
399
- left: ["\x1b[d"],
400
- clear: ["\x1b[e"],
401
- insert: ["\x1b[2$"],
402
- delete: ["\x1b[3$"],
403
- pageUp: ["\x1b[5$"],
404
- pageDown: ["\x1b[6$"],
405
- home: ["\x1b[7$"],
406
- end: ["\x1b[8$"],
407
- } as const;
408
-
409
- const LEGACY_CTRL_SEQUENCES = {
410
- up: ["\x1bOa"],
411
- down: ["\x1bOb"],
412
- right: ["\x1bOc"],
413
- left: ["\x1bOd"],
414
- clear: ["\x1bOe"],
415
- insert: ["\x1b[2^"],
416
- delete: ["\x1b[3^"],
417
- pageUp: ["\x1b[5^"],
418
- pageDown: ["\x1b[6^"],
419
- home: ["\x1b[7^"],
420
- end: ["\x1b[8^"],
421
- } as const;
422
-
423
- const LEGACY_SEQUENCE_KEY_IDS: Record<string, KeyId> = {
424
- "\x1bOA": "up",
425
- "\x1bOB": "down",
426
- "\x1bOC": "right",
427
- "\x1bOD": "left",
428
- "\x1bOH": "home",
429
- "\x1bOF": "end",
430
- "\x1b[E": "clear",
431
- "\x1bOE": "clear",
432
- "\x1bOe": "ctrl+clear",
433
- "\x1b[e": "shift+clear",
434
- "\x1b[2~": "insert",
435
- "\x1b[2$": "shift+insert",
436
- "\x1b[2^": "ctrl+insert",
437
- "\x1b[3$": "shift+delete",
438
- "\x1b[3^": "ctrl+delete",
439
- "\x1b[[5~": "pageUp",
440
- "\x1b[[6~": "pageDown",
441
- "\x1b[a": "shift+up",
442
- "\x1b[b": "shift+down",
443
- "\x1b[c": "shift+right",
444
- "\x1b[d": "shift+left",
445
- "\x1bOa": "ctrl+up",
446
- "\x1bOb": "ctrl+down",
447
- "\x1bOc": "ctrl+right",
448
- "\x1bOd": "ctrl+left",
449
- "\x1b[5$": "shift+pageUp",
450
- "\x1b[6$": "shift+pageDown",
451
- "\x1b[7$": "shift+home",
452
- "\x1b[8$": "shift+end",
453
- "\x1b[5^": "ctrl+pageUp",
454
- "\x1b[6^": "ctrl+pageDown",
455
- "\x1b[7^": "ctrl+home",
456
- "\x1b[8^": "ctrl+end",
457
- "\x1bOP": "f1",
458
- "\x1bOQ": "f2",
459
- "\x1bOR": "f3",
460
- "\x1bOS": "f4",
461
- "\x1b[11~": "f1",
462
- "\x1b[12~": "f2",
463
- "\x1b[13~": "f3",
464
- "\x1b[14~": "f4",
465
- "\x1b[[A": "f1",
466
- "\x1b[[B": "f2",
467
- "\x1b[[C": "f3",
468
- "\x1b[[D": "f4",
469
- "\x1b[[E": "f5",
470
- "\x1b[15~": "f5",
471
- "\x1b[17~": "f6",
472
- "\x1b[18~": "f7",
473
- "\x1b[19~": "f8",
474
- "\x1b[20~": "f9",
475
- "\x1b[21~": "f10",
476
- "\x1b[23~": "f11",
477
- "\x1b[24~": "f12",
478
- "\x1bb": "alt+left",
479
- "\x1bf": "alt+right",
480
- "\x1bp": "alt+up",
481
- "\x1bn": "alt+down",
482
- } as const;
483
-
484
- type LegacyModifierKey = keyof typeof LEGACY_SHIFT_SEQUENCES;
485
-
486
- const matchesLegacySequence = (data: string, sequences: readonly string[]): boolean => sequences.includes(data);
487
-
488
- const matchesLegacyModifierSequence = (data: string, key: LegacyModifierKey, modifier: number): boolean => {
489
- if (modifier === MODIFIERS.shift) {
490
- return matchesLegacySequence(data, LEGACY_SHIFT_SEQUENCES[key]);
491
- }
492
- if (modifier === MODIFIERS.ctrl) {
493
- return matchesLegacySequence(data, LEGACY_CTRL_SEQUENCES[key]);
494
- }
495
- return false;
496
- };
497
-
498
- // =============================================================================
499
- // Kitty Protocol Parsing
500
- // =============================================================================
501
-
502
- /**
503
- * Event types from Kitty keyboard protocol (flag 2)
504
- * 1 = key press, 2 = key repeat, 3 = key release
505
- */
506
- export type KeyEventType = "press" | "repeat" | "release";
507
-
508
- interface ParsedKittySequence {
509
- codepoint: number;
510
- shiftedKey?: number; // Shifted version of the key (when shift is pressed)
511
- baseLayoutKey?: number; // Key in standard PC-101 layout (for non-Latin layouts)
512
- modifier: number;
513
- eventType: KeyEventType;
514
- }
515
-
516
- interface ParsedModifyOtherKeysSequence {
517
- codepoint: number;
518
- modifier: number;
519
- }
520
-
521
- // Store the last parsed event type for isKeyRelease() to query
522
- let _lastEventType: KeyEventType = "press";
523
-
524
- /**
525
- * Check if the last parsed key event was a key release.
526
- * Only meaningful when Kitty keyboard protocol with flag 2 is active.
527
- */
528
- export function isKeyRelease(data: string): boolean {
529
- // Don't treat bracketed paste content as key release, even if it contains
530
- // patterns like ":3F" (e.g., bluetooth MAC addresses like "90:62:3F:A5").
531
- // Terminal.ts re-wraps paste content with bracketed paste markers before
532
- // passing to TUI, so pasted data will always contain \x1b[200~.
533
- if (data.includes("\x1b[200~")) {
534
- return false;
535
- }
536
-
537
- // Quick check: release events with flag 2 contain ":3"
538
- // Format: \x1b[<codepoint>;<modifier>:3u
539
- if (
540
- data.includes(":3u") ||
541
- data.includes(":3~") ||
542
- data.includes(":3A") ||
543
- data.includes(":3B") ||
544
- data.includes(":3C") ||
545
- data.includes(":3D") ||
546
- data.includes(":3H") ||
547
- data.includes(":3F")
548
- ) {
549
- return true;
550
- }
551
- return false;
552
- }
553
-
554
- /**
555
- * Check if the last parsed key event was a key repeat.
556
- * Only meaningful when Kitty keyboard protocol with flag 2 is active.
557
- */
558
- export function isKeyRepeat(data: string): boolean {
559
- // Don't treat bracketed paste content as key repeat, even if it contains
560
- // patterns like ":2F". See isKeyRelease() for details.
561
- if (data.includes("\x1b[200~")) {
562
- return false;
563
- }
564
-
565
- if (
566
- data.includes(":2u") ||
567
- data.includes(":2~") ||
568
- data.includes(":2A") ||
569
- data.includes(":2B") ||
570
- data.includes(":2C") ||
571
- data.includes(":2D") ||
572
- data.includes(":2H") ||
573
- data.includes(":2F")
574
- ) {
575
- return true;
576
- }
577
- return false;
578
- }
579
-
580
- function parseEventType(eventTypeStr: string | undefined): KeyEventType {
581
- if (!eventTypeStr) return "press";
582
- const eventType = parseInt(eventTypeStr, 10);
583
- if (eventType === 2) return "repeat";
584
- if (eventType === 3) return "release";
585
- return "press";
586
- }
587
-
588
- function parseKittySequence(data: string): ParsedKittySequence | null {
589
- // CSI u format with alternate keys (flag 4):
590
- // \x1b[<codepoint>u
591
- // \x1b[<codepoint>;<mod>u
592
- // \x1b[<codepoint>;<mod>:<event>u
593
- // \x1b[<codepoint>:<shifted>;<mod>u
594
- // \x1b[<codepoint>:<shifted>:<base>;<mod>u
595
- // \x1b[<codepoint>::<base>;<mod>u (no shifted key, only base)
596
- //
597
- // With flag 2, event type is appended after modifier colon: 1=press, 2=repeat, 3=release
598
- // With flag 4, alternate keys are appended after codepoint with colons
599
- const csiUMatch = data.match(/^\x1b\[(\d+)(?::(\d*))?(?::(\d+))?(?:;(\d+))?(?::(\d+))?u$/);
600
- if (csiUMatch) {
601
- const codepoint = parseInt(csiUMatch[1]!, 10);
602
- const shiftedKey = csiUMatch[2] && csiUMatch[2].length > 0 ? parseInt(csiUMatch[2], 10) : undefined;
603
- const baseLayoutKey = csiUMatch[3] ? parseInt(csiUMatch[3], 10) : undefined;
604
- const modValue = csiUMatch[4] ? parseInt(csiUMatch[4], 10) : 1;
605
- const eventType = parseEventType(csiUMatch[5]);
606
- _lastEventType = eventType;
607
- return { codepoint, shiftedKey, baseLayoutKey, modifier: modValue - 1, eventType };
608
- }
609
-
610
- // Arrow keys with modifier: \x1b[1;<mod>A/B/C/D or \x1b[1;<mod>:<event>A/B/C/D
611
- const arrowMatch = data.match(/^\x1b\[1;(\d+)(?::(\d+))?([ABCD])$/);
612
- if (arrowMatch) {
613
- const modValue = parseInt(arrowMatch[1]!, 10);
614
- const eventType = parseEventType(arrowMatch[2]);
615
- const arrowCodes: Record<string, number> = { A: -1, B: -2, C: -3, D: -4 };
616
- _lastEventType = eventType;
617
- return { codepoint: arrowCodes[arrowMatch[3]!]!, modifier: modValue - 1, eventType };
618
- }
619
-
620
- // Functional keys: \x1b[<num>~ or \x1b[<num>;<mod>~ or \x1b[<num>;<mod>:<event>~
621
- const funcMatch = data.match(/^\x1b\[(\d+)(?:;(\d+))?(?::(\d+))?~$/);
622
- if (funcMatch) {
623
- const keyNum = parseInt(funcMatch[1]!, 10);
624
- const modValue = funcMatch[2] ? parseInt(funcMatch[2], 10) : 1;
625
- const eventType = parseEventType(funcMatch[3]);
626
- const funcCodes: Record<number, number> = {
627
- 2: FUNCTIONAL_CODEPOINTS.insert,
628
- 3: FUNCTIONAL_CODEPOINTS.delete,
629
- 5: FUNCTIONAL_CODEPOINTS.pageUp,
630
- 6: FUNCTIONAL_CODEPOINTS.pageDown,
631
- 7: FUNCTIONAL_CODEPOINTS.home,
632
- 8: FUNCTIONAL_CODEPOINTS.end,
633
- };
634
- const codepoint = funcCodes[keyNum];
635
- if (codepoint !== undefined) {
636
- _lastEventType = eventType;
637
- return { codepoint, modifier: modValue - 1, eventType };
638
- }
639
- }
640
-
641
- // Home/End with modifier: \x1b[1;<mod>H/F or \x1b[1;<mod>:<event>H/F
642
- const homeEndMatch = data.match(/^\x1b\[1;(\d+)(?::(\d+))?([HF])$/);
643
- if (homeEndMatch) {
644
- const modValue = parseInt(homeEndMatch[1]!, 10);
645
- const eventType = parseEventType(homeEndMatch[2]);
646
- const codepoint = homeEndMatch[3] === "H" ? FUNCTIONAL_CODEPOINTS.home : FUNCTIONAL_CODEPOINTS.end;
647
- _lastEventType = eventType;
648
- return { codepoint, modifier: modValue - 1, eventType };
649
- }
650
-
651
- return null;
652
- }
653
-
654
- function matchesKittySequence(data: string, expectedCodepoint: number, expectedModifier: number): boolean {
655
- const parsed = parseKittySequence(data);
656
- if (!parsed) return false;
657
- const actualMod = parsed.modifier & ~LOCK_MASK;
658
- const expectedMod = expectedModifier & ~LOCK_MASK;
659
-
660
- // Check if modifiers match
661
- if (actualMod !== expectedMod) return false;
662
-
663
- const normalizedCodepoint = normalizeShiftedLetterIdentityCodepoint(
664
- normalizeKittyFunctionalCodepoint(parsed.codepoint),
665
- parsed.modifier,
666
- );
667
- const normalizedExpectedCodepoint = normalizeShiftedLetterIdentityCodepoint(
668
- normalizeKittyFunctionalCodepoint(expectedCodepoint),
669
- expectedModifier,
670
- );
671
-
672
- // Primary match: codepoint matches directly after normalizing functional keys
673
- if (normalizedCodepoint === normalizedExpectedCodepoint) return true;
674
-
675
- // Alternate match: use base layout key for non-Latin keyboard layouts.
676
- // This allows Ctrl+С (Cyrillic) to match Ctrl+c (Latin) when terminal reports
677
- // the base layout key (the key in standard PC-101 layout).
678
- //
679
- // Only fall back to base layout key when the codepoint is NOT already a
680
- // recognized Latin letter (a-z) or symbol (e.g., /, -, [, ;, etc.).
681
- // When the codepoint is a recognized key, it is authoritative regardless
682
- // of physical key position. This prevents remapped layouts (Dvorak, Colemak,
683
- // xremap, etc.) from causing false matches: both letters and symbols move
684
- // to different physical positions, so Ctrl+K could falsely match Ctrl+V
685
- // (letter remapping) and Ctrl+/ could falsely match Ctrl+[ (symbol remapping)
686
- // if the base layout key were always considered.
687
- if (parsed.baseLayoutKey !== undefined && parsed.baseLayoutKey === expectedCodepoint) {
688
- const cp = normalizedCodepoint;
689
- const isLatinLetter = cp >= 97 && cp <= 122; // a-z
690
- const isKnownSymbol = SYMBOL_KEYS.has(String.fromCharCode(cp));
691
- if (!isLatinLetter && !isKnownSymbol) return true;
692
- }
693
-
694
- return false;
695
- }
696
-
697
- function parseModifyOtherKeysSequence(data: string): ParsedModifyOtherKeysSequence | null {
698
- const match = data.match(/^\x1b\[27;(\d+);(\d+)~$/);
699
- if (!match) return null;
700
- const modValue = parseInt(match[1]!, 10);
701
- const codepoint = parseInt(match[2]!, 10);
702
- return { codepoint, modifier: modValue - 1 };
703
- }
704
-
705
- /**
706
- * Match xterm modifyOtherKeys format: CSI 27 ; modifiers ; keycode ~
707
- * This is used by terminals when Kitty protocol is not enabled.
708
- * Modifier values are 1-indexed: 2=shift, 3=alt, 5=ctrl, etc.
709
- */
710
- function matchesModifyOtherKeys(data: string, expectedKeycode: number, expectedModifier: number): boolean {
711
- const parsed = parseModifyOtherKeysSequence(data);
712
- if (!parsed) return false;
713
- return parsed.codepoint === expectedKeycode && parsed.modifier === expectedModifier;
714
- }
715
-
716
- function isWindowsTerminalSession(): boolean {
717
- return (
718
- Boolean(process.env.WT_SESSION) && !process.env.SSH_CONNECTION && !process.env.SSH_CLIENT && !process.env.SSH_TTY
719
- );
720
- }
721
-
722
- /**
723
- * Raw 0x08 (BS) is ambiguous in legacy terminals.
724
- *
725
- * - Windows Terminal uses it for Ctrl+Backspace.
726
- * - Some legacy terminals and tmux setups send it for plain Backspace.
727
- *
728
- * Prefer explicit Kitty / CSI-u / modifyOtherKeys sequences whenever they are
729
- * available. Fall back to a Windows Terminal heuristic only for raw BS bytes.
730
- */
731
- function matchesRawBackspace(data: string, expectedModifier: number): boolean {
732
- if (data === "\x7f") return expectedModifier === 0;
733
- if (data !== "\x08") return false;
734
- return isWindowsTerminalSession() ? expectedModifier === MODIFIERS.ctrl : expectedModifier === 0;
735
- }
736
-
737
- // =============================================================================
738
- // Generic Key Matching
739
- // =============================================================================
740
-
741
- /**
742
- * Get the control character for a key.
743
- * Uses the universal formula: code & 0x1f (mask to lower 5 bits)
744
- *
745
- * Works for:
746
- * - Letters a-z → 1-26
747
- * - Symbols [\]_ → 27, 28, 29, 31
748
- * - Also maps - to same as _ (same physical key on US keyboards)
749
- */
750
- function rawCtrlChar(key: string): string | null {
751
- const char = key.toLowerCase();
752
- const code = char.charCodeAt(0);
753
- if ((code >= 97 && code <= 122) || char === "[" || char === "\\" || char === "]" || char === "_") {
754
- return String.fromCharCode(code & 0x1f);
755
- }
756
- // Handle - as _ (same physical key on US keyboards)
757
- if (char === "-") {
758
- return String.fromCharCode(31); // Same as Ctrl+_
759
- }
760
- return null;
761
- }
762
-
763
- function isDigitKey(key: string): boolean {
764
- return key >= "0" && key <= "9";
765
- }
766
-
767
- function matchesPrintableModifyOtherKeys(data: string, expectedKeycode: number, expectedModifier: number): boolean {
768
- if (expectedModifier === 0) return false;
769
- const parsed = parseModifyOtherKeysSequence(data);
770
- if (!parsed || parsed.modifier !== expectedModifier) return false;
771
- return (
772
- normalizeShiftedLetterIdentityCodepoint(parsed.codepoint, parsed.modifier) ===
773
- normalizeShiftedLetterIdentityCodepoint(expectedKeycode, expectedModifier)
774
- );
775
- }
776
-
777
- function formatKeyNameWithModifiers(keyName: string, modifier: number): string | undefined {
778
- const mods: string[] = [];
779
- const effectiveMod = modifier & ~LOCK_MASK;
780
- const supportedModifierMask = MODIFIERS.shift | MODIFIERS.ctrl | MODIFIERS.alt | MODIFIERS.super;
781
- if ((effectiveMod & ~supportedModifierMask) !== 0) return undefined;
782
- if (effectiveMod & MODIFIERS.shift) mods.push("shift");
783
- if (effectiveMod & MODIFIERS.ctrl) mods.push("ctrl");
784
- if (effectiveMod & MODIFIERS.alt) mods.push("alt");
785
- if (effectiveMod & MODIFIERS.super) mods.push("super");
786
- return mods.length > 0 ? `${mods.join("+")}+${keyName}` : keyName;
787
- }
788
-
789
- function parseKeyId(
790
- keyId: string,
791
- ): { key: string; ctrl: boolean; shift: boolean; alt: boolean; super: boolean } | null {
792
- const parts = keyId.toLowerCase().split("+");
793
- const key = parts[parts.length - 1];
794
- if (!key) return null;
795
- return {
796
- key,
797
- ctrl: parts.includes("ctrl"),
798
- shift: parts.includes("shift"),
799
- alt: parts.includes("alt"),
800
- super: parts.includes("super"),
801
- };
802
- }
803
-
804
- /**
805
- * Match input data against a key identifier string.
806
- *
807
- * Supported key identifiers:
808
- * - Single keys: "escape", "tab", "enter", "backspace", "delete", "home", "end", "space"
809
- * - Arrow keys: "up", "down", "left", "right"
810
- * - Ctrl combinations: "ctrl+c", "ctrl+z", etc.
811
- * - Shift combinations: "shift+tab", "shift+enter"
812
- * - Alt combinations: "alt+enter", "alt+backspace"
813
- * - Super combinations: "super+k", "super+enter"
814
- * - Combined modifiers: "shift+ctrl+p", "ctrl+alt+x", "ctrl+super+k"
815
- *
816
- * Use the Key helper for autocomplete: Key.ctrl("c"), Key.escape, Key.ctrlShift("p"), Key.super("k")
817
- *
818
- * @param data - Raw input data from terminal
819
- * @param keyId - Key identifier (e.g., "ctrl+c", "escape", Key.ctrl("c"))
820
- */
821
- export function matchesKey(data: string, keyId: KeyId): boolean {
822
- const parsed = parseKeyId(keyId);
823
- if (!parsed) return false;
824
-
825
- const { key, ctrl, shift, alt, super: superModifier } = parsed;
826
- let modifier = 0;
827
- if (shift) modifier |= MODIFIERS.shift;
828
- if (alt) modifier |= MODIFIERS.alt;
829
- if (ctrl) modifier |= MODIFIERS.ctrl;
830
- if (superModifier) modifier |= MODIFIERS.super;
831
-
832
- switch (key) {
833
- case "escape":
834
- case "esc":
835
- if (modifier !== 0) return false;
836
- return (
837
- data === "\x1b" ||
838
- matchesKittySequence(data, CODEPOINTS.escape, 0) ||
839
- matchesModifyOtherKeys(data, CODEPOINTS.escape, 0)
840
- );
841
-
842
- case "space":
843
- if (!_kittyProtocolActive) {
844
- if (modifier === MODIFIERS.ctrl && data === "\x00") {
845
- return true;
846
- }
847
- if (modifier === MODIFIERS.alt && data === "\x1b ") {
848
- return true;
849
- }
850
- }
851
- if (modifier === 0) {
852
- return (
853
- data === " " ||
854
- matchesKittySequence(data, CODEPOINTS.space, 0) ||
855
- matchesModifyOtherKeys(data, CODEPOINTS.space, 0)
856
- );
857
- }
858
- return (
859
- matchesKittySequence(data, CODEPOINTS.space, modifier) ||
860
- matchesModifyOtherKeys(data, CODEPOINTS.space, modifier)
861
- );
862
-
863
- case "tab":
864
- if (modifier === MODIFIERS.shift) {
865
- return (
866
- data === "\x1b[Z" ||
867
- matchesKittySequence(data, CODEPOINTS.tab, MODIFIERS.shift) ||
868
- matchesModifyOtherKeys(data, CODEPOINTS.tab, MODIFIERS.shift)
869
- );
870
- }
871
- if (modifier === 0) {
872
- return data === "\t" || matchesKittySequence(data, CODEPOINTS.tab, 0);
873
- }
874
- return (
875
- matchesKittySequence(data, CODEPOINTS.tab, modifier) ||
876
- matchesModifyOtherKeys(data, CODEPOINTS.tab, modifier)
877
- );
878
-
879
- case "enter":
880
- case "return":
881
- if (modifier === MODIFIERS.shift) {
882
- // CSI u sequences (standard Kitty protocol)
883
- if (
884
- matchesKittySequence(data, CODEPOINTS.enter, MODIFIERS.shift) ||
885
- matchesKittySequence(data, CODEPOINTS.kpEnter, MODIFIERS.shift)
886
- ) {
887
- return true;
888
- }
889
- // xterm modifyOtherKeys format (fallback when Kitty protocol not enabled)
890
- if (matchesModifyOtherKeys(data, CODEPOINTS.enter, MODIFIERS.shift)) {
891
- return true;
892
- }
893
- // When Kitty protocol is active, legacy sequences are custom terminal mappings
894
- // \x1b\r = Kitty's "map shift+enter send_text all \e\r"
895
- // \n = Ghostty's "keybind = shift+enter=text:\n"
896
- if (_kittyProtocolActive) {
897
- return data === "\x1b\r" || data === "\n";
898
- }
899
- return false;
900
- }
901
- if (modifier === MODIFIERS.alt) {
902
- // CSI u sequences (standard Kitty protocol)
903
- if (
904
- matchesKittySequence(data, CODEPOINTS.enter, MODIFIERS.alt) ||
905
- matchesKittySequence(data, CODEPOINTS.kpEnter, MODIFIERS.alt)
906
- ) {
907
- return true;
908
- }
909
- // xterm modifyOtherKeys format (fallback when Kitty protocol not enabled)
910
- if (matchesModifyOtherKeys(data, CODEPOINTS.enter, MODIFIERS.alt)) {
911
- return true;
912
- }
913
- // \x1b\r is alt+enter only in legacy mode (no Kitty protocol)
914
- // When Kitty protocol is active, alt+enter comes as CSI u sequence
915
- if (!_kittyProtocolActive) {
916
- return data === "\x1b\r";
917
- }
918
- return false;
919
- }
920
- if (modifier === 0) {
921
- return (
922
- data === "\r" ||
923
- (!_kittyProtocolActive && data === "\n") ||
924
- data === "\x1bOM" || // SS3 M (numpad enter in some terminals)
925
- matchesKittySequence(data, CODEPOINTS.enter, 0) ||
926
- matchesKittySequence(data, CODEPOINTS.kpEnter, 0)
927
- );
928
- }
929
- return (
930
- matchesKittySequence(data, CODEPOINTS.enter, modifier) ||
931
- matchesKittySequence(data, CODEPOINTS.kpEnter, modifier) ||
932
- matchesModifyOtherKeys(data, CODEPOINTS.enter, modifier)
933
- );
934
-
935
- case "backspace":
936
- if (modifier === MODIFIERS.alt) {
937
- if (data === "\x1b\x7f" || data === "\x1b\b") {
938
- return true;
939
- }
940
- return (
941
- matchesKittySequence(data, CODEPOINTS.backspace, MODIFIERS.alt) ||
942
- matchesModifyOtherKeys(data, CODEPOINTS.backspace, MODIFIERS.alt)
943
- );
944
- }
945
- if (modifier === MODIFIERS.ctrl) {
946
- // Legacy raw 0x08 is ambiguous: it can be Ctrl+Backspace on Windows
947
- // Terminal or plain Backspace on other terminals, while also
948
- // overlapping with Ctrl+H.
949
- if (matchesRawBackspace(data, MODIFIERS.ctrl)) return true;
950
- return (
951
- matchesKittySequence(data, CODEPOINTS.backspace, MODIFIERS.ctrl) ||
952
- matchesModifyOtherKeys(data, CODEPOINTS.backspace, MODIFIERS.ctrl)
953
- );
954
- }
955
- if (modifier === 0) {
956
- return (
957
- matchesRawBackspace(data, 0) ||
958
- matchesKittySequence(data, CODEPOINTS.backspace, 0) ||
959
- matchesModifyOtherKeys(data, CODEPOINTS.backspace, 0)
960
- );
961
- }
962
- return (
963
- matchesKittySequence(data, CODEPOINTS.backspace, modifier) ||
964
- matchesModifyOtherKeys(data, CODEPOINTS.backspace, modifier)
965
- );
966
-
967
- case "insert":
968
- if (modifier === 0) {
969
- return (
970
- matchesLegacySequence(data, LEGACY_KEY_SEQUENCES.insert) ||
971
- matchesKittySequence(data, FUNCTIONAL_CODEPOINTS.insert, 0)
972
- );
973
- }
974
- if (matchesLegacyModifierSequence(data, "insert", modifier)) {
975
- return true;
976
- }
977
- return matchesKittySequence(data, FUNCTIONAL_CODEPOINTS.insert, modifier);
978
-
979
- case "delete":
980
- if (modifier === 0) {
981
- return (
982
- matchesLegacySequence(data, LEGACY_KEY_SEQUENCES.delete) ||
983
- matchesKittySequence(data, FUNCTIONAL_CODEPOINTS.delete, 0)
984
- );
985
- }
986
- if (matchesLegacyModifierSequence(data, "delete", modifier)) {
987
- return true;
988
- }
989
- return matchesKittySequence(data, FUNCTIONAL_CODEPOINTS.delete, modifier);
990
-
991
- case "clear":
992
- if (modifier === 0) {
993
- return matchesLegacySequence(data, LEGACY_KEY_SEQUENCES.clear);
994
- }
995
- return matchesLegacyModifierSequence(data, "clear", modifier);
996
-
997
- case "home":
998
- if (modifier === 0) {
999
- return (
1000
- matchesLegacySequence(data, LEGACY_KEY_SEQUENCES.home) ||
1001
- matchesKittySequence(data, FUNCTIONAL_CODEPOINTS.home, 0)
1002
- );
1003
- }
1004
- if (matchesLegacyModifierSequence(data, "home", modifier)) {
1005
- return true;
1006
- }
1007
- return matchesKittySequence(data, FUNCTIONAL_CODEPOINTS.home, modifier);
1008
-
1009
- case "end":
1010
- if (modifier === 0) {
1011
- return (
1012
- matchesLegacySequence(data, LEGACY_KEY_SEQUENCES.end) ||
1013
- matchesKittySequence(data, FUNCTIONAL_CODEPOINTS.end, 0)
1014
- );
1015
- }
1016
- if (matchesLegacyModifierSequence(data, "end", modifier)) {
1017
- return true;
1018
- }
1019
- return matchesKittySequence(data, FUNCTIONAL_CODEPOINTS.end, modifier);
1020
-
1021
- case "pageup":
1022
- if (modifier === 0) {
1023
- return (
1024
- matchesLegacySequence(data, LEGACY_KEY_SEQUENCES.pageUp) ||
1025
- matchesKittySequence(data, FUNCTIONAL_CODEPOINTS.pageUp, 0)
1026
- );
1027
- }
1028
- if (matchesLegacyModifierSequence(data, "pageUp", modifier)) {
1029
- return true;
1030
- }
1031
- return matchesKittySequence(data, FUNCTIONAL_CODEPOINTS.pageUp, modifier);
1032
-
1033
- case "pagedown":
1034
- if (modifier === 0) {
1035
- return (
1036
- matchesLegacySequence(data, LEGACY_KEY_SEQUENCES.pageDown) ||
1037
- matchesKittySequence(data, FUNCTIONAL_CODEPOINTS.pageDown, 0)
1038
- );
1039
- }
1040
- if (matchesLegacyModifierSequence(data, "pageDown", modifier)) {
1041
- return true;
1042
- }
1043
- return matchesKittySequence(data, FUNCTIONAL_CODEPOINTS.pageDown, modifier);
1044
-
1045
- case "up":
1046
- if (modifier === MODIFIERS.alt) {
1047
- return data === "\x1bp" || matchesKittySequence(data, ARROW_CODEPOINTS.up, MODIFIERS.alt);
1048
- }
1049
- if (modifier === 0) {
1050
- return (
1051
- matchesLegacySequence(data, LEGACY_KEY_SEQUENCES.up) ||
1052
- matchesKittySequence(data, ARROW_CODEPOINTS.up, 0)
1053
- );
1054
- }
1055
- if (matchesLegacyModifierSequence(data, "up", modifier)) {
1056
- return true;
1057
- }
1058
- return matchesKittySequence(data, ARROW_CODEPOINTS.up, modifier);
1059
-
1060
- case "down":
1061
- if (modifier === MODIFIERS.alt) {
1062
- return data === "\x1bn" || matchesKittySequence(data, ARROW_CODEPOINTS.down, MODIFIERS.alt);
1063
- }
1064
- if (modifier === 0) {
1065
- return (
1066
- matchesLegacySequence(data, LEGACY_KEY_SEQUENCES.down) ||
1067
- matchesKittySequence(data, ARROW_CODEPOINTS.down, 0)
1068
- );
1069
- }
1070
- if (matchesLegacyModifierSequence(data, "down", modifier)) {
1071
- return true;
1072
- }
1073
- return matchesKittySequence(data, ARROW_CODEPOINTS.down, modifier);
1074
-
1075
- case "left":
1076
- if (modifier === MODIFIERS.alt) {
1077
- return (
1078
- data === "\x1b[1;3D" ||
1079
- (!_kittyProtocolActive && data === "\x1bB") ||
1080
- data === "\x1bb" ||
1081
- matchesKittySequence(data, ARROW_CODEPOINTS.left, MODIFIERS.alt)
1082
- );
1083
- }
1084
- if (modifier === MODIFIERS.ctrl) {
1085
- return (
1086
- data === "\x1b[1;5D" ||
1087
- matchesLegacyModifierSequence(data, "left", MODIFIERS.ctrl) ||
1088
- matchesKittySequence(data, ARROW_CODEPOINTS.left, MODIFIERS.ctrl)
1089
- );
1090
- }
1091
- if (modifier === 0) {
1092
- return (
1093
- matchesLegacySequence(data, LEGACY_KEY_SEQUENCES.left) ||
1094
- matchesKittySequence(data, ARROW_CODEPOINTS.left, 0)
1095
- );
1096
- }
1097
- if (matchesLegacyModifierSequence(data, "left", modifier)) {
1098
- return true;
1099
- }
1100
- return matchesKittySequence(data, ARROW_CODEPOINTS.left, modifier);
1101
-
1102
- case "right":
1103
- if (modifier === MODIFIERS.alt) {
1104
- return (
1105
- data === "\x1b[1;3C" ||
1106
- (!_kittyProtocolActive && data === "\x1bF") ||
1107
- data === "\x1bf" ||
1108
- matchesKittySequence(data, ARROW_CODEPOINTS.right, MODIFIERS.alt)
1109
- );
1110
- }
1111
- if (modifier === MODIFIERS.ctrl) {
1112
- return (
1113
- data === "\x1b[1;5C" ||
1114
- matchesLegacyModifierSequence(data, "right", MODIFIERS.ctrl) ||
1115
- matchesKittySequence(data, ARROW_CODEPOINTS.right, MODIFIERS.ctrl)
1116
- );
1117
- }
1118
- if (modifier === 0) {
1119
- return (
1120
- matchesLegacySequence(data, LEGACY_KEY_SEQUENCES.right) ||
1121
- matchesKittySequence(data, ARROW_CODEPOINTS.right, 0)
1122
- );
1123
- }
1124
- if (matchesLegacyModifierSequence(data, "right", modifier)) {
1125
- return true;
1126
- }
1127
- return matchesKittySequence(data, ARROW_CODEPOINTS.right, modifier);
1128
-
1129
- case "f1":
1130
- case "f2":
1131
- case "f3":
1132
- case "f4":
1133
- case "f5":
1134
- case "f6":
1135
- case "f7":
1136
- case "f8":
1137
- case "f9":
1138
- case "f10":
1139
- case "f11":
1140
- case "f12": {
1141
- if (modifier !== 0) {
1142
- return false;
1143
- }
1144
- const functionKey = key as keyof typeof LEGACY_KEY_SEQUENCES;
1145
- return matchesLegacySequence(data, LEGACY_KEY_SEQUENCES[functionKey]);
1146
- }
1147
- }
1148
-
1149
- // Handle single letter/digit keys and symbols
1150
- if (key.length === 1 && ((key >= "a" && key <= "z") || isDigitKey(key) || SYMBOL_KEYS.has(key))) {
1151
- const codepoint = key.charCodeAt(0);
1152
- const rawCtrl = rawCtrlChar(key);
1153
- const isLetter = key >= "a" && key <= "z";
1154
- const isDigit = isDigitKey(key);
1155
-
1156
- if (modifier === MODIFIERS.ctrl + MODIFIERS.alt && !_kittyProtocolActive && rawCtrl) {
1157
- // Legacy: ctrl+alt+key is ESC followed by the control character.
1158
- // If that legacy form does not match, continue so CSI-u and
1159
- // modifyOtherKeys sequences from tmux can still be recognized.
1160
- if (data === `\x1b${rawCtrl}`) return true;
1161
- }
1162
-
1163
- if (modifier === MODIFIERS.alt && !_kittyProtocolActive && (isLetter || isDigit || SYMBOL_KEYS.has(key))) {
1164
- // Legacy: alt+printable key is ESC followed by the key
1165
- if (data === `\x1b${key}`) return true;
1166
- }
1167
-
1168
- if (modifier === MODIFIERS.ctrl) {
1169
- // Legacy: ctrl+key sends the control character
1170
- if (rawCtrl && data === rawCtrl) return true;
1171
- return (
1172
- matchesKittySequence(data, codepoint, MODIFIERS.ctrl) ||
1173
- matchesPrintableModifyOtherKeys(data, codepoint, MODIFIERS.ctrl)
1174
- );
1175
- }
1176
-
1177
- if (modifier === MODIFIERS.shift + MODIFIERS.ctrl) {
1178
- return (
1179
- matchesKittySequence(data, codepoint, MODIFIERS.shift + MODIFIERS.ctrl) ||
1180
- matchesPrintableModifyOtherKeys(data, codepoint, MODIFIERS.shift + MODIFIERS.ctrl)
1181
- );
1182
- }
1183
-
1184
- if (modifier === MODIFIERS.shift) {
1185
- // Legacy: shift+letter produces uppercase
1186
- if (isLetter && data === key.toUpperCase()) return true;
1187
- return (
1188
- matchesKittySequence(data, codepoint, MODIFIERS.shift) ||
1189
- matchesPrintableModifyOtherKeys(data, codepoint, MODIFIERS.shift)
1190
- );
1191
- }
1192
-
1193
- if (modifier !== 0) {
1194
- return (
1195
- matchesKittySequence(data, codepoint, modifier) ||
1196
- matchesPrintableModifyOtherKeys(data, codepoint, modifier)
1197
- );
1198
- }
1199
-
1200
- // Check both raw char and Kitty sequence (needed for release events)
1201
- return data === key || matchesKittySequence(data, codepoint, 0);
1202
- }
1203
-
1204
- return false;
1205
- }
1206
-
1207
- /**
1208
- * Parse input data and return the key identifier if recognized.
1209
- *
1210
- * @param data - Raw input data from terminal
1211
- * @returns Key identifier string (e.g., "ctrl+c") or undefined
1212
- */
1213
- function formatParsedKey(codepoint: number, modifier: number, baseLayoutKey?: number): string | undefined {
1214
- const normalizedCodepoint = normalizeKittyFunctionalCodepoint(codepoint);
1215
- const identityCodepoint = normalizeShiftedLetterIdentityCodepoint(normalizedCodepoint, modifier);
1216
-
1217
- // Use base layout key only when codepoint is not a recognized Latin
1218
- // letter (a-z), digit (0-9), or symbol (/, -, [, ;, etc.). For those,
1219
- // the codepoint is authoritative regardless of physical key position.
1220
- // This prevents remapped layouts (Dvorak, Colemak, xremap, etc.) from
1221
- // reporting the wrong key name based on the QWERTY physical position.
1222
- const isLatinLetter = identityCodepoint >= 97 && identityCodepoint <= 122; // a-z
1223
- const isDigit = identityCodepoint >= 48 && identityCodepoint <= 57; // 0-9
1224
- const isKnownSymbol = SYMBOL_KEYS.has(String.fromCharCode(identityCodepoint));
1225
- const effectiveCodepoint =
1226
- isLatinLetter || isDigit || isKnownSymbol ? identityCodepoint : (baseLayoutKey ?? identityCodepoint);
1227
-
1228
- let keyName: string | undefined;
1229
- if (effectiveCodepoint === CODEPOINTS.escape) keyName = "escape";
1230
- else if (effectiveCodepoint === CODEPOINTS.tab) keyName = "tab";
1231
- else if (effectiveCodepoint === CODEPOINTS.enter || effectiveCodepoint === CODEPOINTS.kpEnter) keyName = "enter";
1232
- else if (effectiveCodepoint === CODEPOINTS.space) keyName = "space";
1233
- else if (effectiveCodepoint === CODEPOINTS.backspace) keyName = "backspace";
1234
- else if (effectiveCodepoint === FUNCTIONAL_CODEPOINTS.delete) keyName = "delete";
1235
- else if (effectiveCodepoint === FUNCTIONAL_CODEPOINTS.insert) keyName = "insert";
1236
- else if (effectiveCodepoint === FUNCTIONAL_CODEPOINTS.home) keyName = "home";
1237
- else if (effectiveCodepoint === FUNCTIONAL_CODEPOINTS.end) keyName = "end";
1238
- else if (effectiveCodepoint === FUNCTIONAL_CODEPOINTS.pageUp) keyName = "pageUp";
1239
- else if (effectiveCodepoint === FUNCTIONAL_CODEPOINTS.pageDown) keyName = "pageDown";
1240
- else if (effectiveCodepoint === ARROW_CODEPOINTS.up) keyName = "up";
1241
- else if (effectiveCodepoint === ARROW_CODEPOINTS.down) keyName = "down";
1242
- else if (effectiveCodepoint === ARROW_CODEPOINTS.left) keyName = "left";
1243
- else if (effectiveCodepoint === ARROW_CODEPOINTS.right) keyName = "right";
1244
- else if (effectiveCodepoint >= 48 && effectiveCodepoint <= 57) keyName = String.fromCharCode(effectiveCodepoint);
1245
- else if (effectiveCodepoint >= 97 && effectiveCodepoint <= 122) keyName = String.fromCharCode(effectiveCodepoint);
1246
- else if (SYMBOL_KEYS.has(String.fromCharCode(effectiveCodepoint))) keyName = String.fromCharCode(effectiveCodepoint);
1247
-
1248
- if (!keyName) return undefined;
1249
- return formatKeyNameWithModifiers(keyName, modifier);
1250
- }
1251
-
1252
- export function parseKey(data: string): string | undefined {
1253
- const kitty = parseKittySequence(data);
1254
- if (kitty) {
1255
- return formatParsedKey(kitty.codepoint, kitty.modifier, kitty.baseLayoutKey);
1256
- }
1257
-
1258
- const modifyOtherKeys = parseModifyOtherKeysSequence(data);
1259
- if (modifyOtherKeys) {
1260
- return formatParsedKey(modifyOtherKeys.codepoint, modifyOtherKeys.modifier);
1261
- }
1262
-
1263
- // Mode-aware legacy sequences
1264
- // When Kitty protocol is active, ambiguous sequences are interpreted as custom terminal mappings:
1265
- // - \x1b\r = shift+enter (Kitty mapping), not alt+enter
1266
- // - \n = shift+enter (Ghostty mapping)
1267
- if (_kittyProtocolActive) {
1268
- if (data === "\x1b\r" || data === "\n") return "shift+enter";
1269
- }
1270
-
1271
- const legacySequenceKeyId = LEGACY_SEQUENCE_KEY_IDS[data];
1272
- if (legacySequenceKeyId) return legacySequenceKeyId;
1273
-
1274
- // Legacy sequences (used when Kitty protocol is not active, or for unambiguous sequences)
1275
- if (data === "\x1b") return "escape";
1276
- if (data === "\x1c") return "ctrl+\\";
1277
- if (data === "\x1d") return "ctrl+]";
1278
- if (data === "\x1f") return "ctrl+-";
1279
- if (data === "\x1b\x1b") return "ctrl+alt+[";
1280
- if (data === "\x1b\x1c") return "ctrl+alt+\\";
1281
- if (data === "\x1b\x1d") return "ctrl+alt+]";
1282
- if (data === "\x1b\x1f") return "ctrl+alt+-";
1283
- if (data === "\t") return "tab";
1284
- if (data === "\r" || (!_kittyProtocolActive && data === "\n") || data === "\x1bOM") return "enter";
1285
- if (data === "\x00") return "ctrl+space";
1286
- if (data === " ") return "space";
1287
- if (data === "\x7f") return "backspace";
1288
- if (data === "\x08") return isWindowsTerminalSession() ? "ctrl+backspace" : "backspace";
1289
- if (data === "\x1b[Z") return "shift+tab";
1290
- if (!_kittyProtocolActive && data === "\x1b\r") return "alt+enter";
1291
- if (!_kittyProtocolActive && data === "\x1b ") return "alt+space";
1292
- if (data === "\x1b\x7f" || data === "\x1b\b") return "alt+backspace";
1293
- if (!_kittyProtocolActive && data === "\x1bB") return "alt+left";
1294
- if (!_kittyProtocolActive && data === "\x1bF") return "alt+right";
1295
- if (!_kittyProtocolActive && data.length === 2 && data[0] === "\x1b") {
1296
- const code = data.charCodeAt(1);
1297
- if (code >= 1 && code <= 26) {
1298
- return `ctrl+alt+${String.fromCharCode(code + 96)}`;
1299
- }
1300
- // Legacy alt+letter/digit/symbol (ESC followed by the key)
1301
- const key = String.fromCharCode(code);
1302
- if ((code >= 97 && code <= 122) || (code >= 48 && code <= 57) || SYMBOL_KEYS.has(key)) {
1303
- return `alt+${key}`;
1304
- }
1305
- }
1306
- if (data === "\x1b[A") return "up";
1307
- if (data === "\x1b[B") return "down";
1308
- if (data === "\x1b[C") return "right";
1309
- if (data === "\x1b[D") return "left";
1310
- if (data === "\x1b[H" || data === "\x1bOH") return "home";
1311
- if (data === "\x1b[F" || data === "\x1bOF") return "end";
1312
- if (data === "\x1b[3~") return "delete";
1313
- if (data === "\x1b[5~") return "pageUp";
1314
- if (data === "\x1b[6~") return "pageDown";
1315
-
1316
- // Raw Ctrl+letter
1317
- if (data.length === 1) {
1318
- const code = data.charCodeAt(0);
1319
- if (code >= 1 && code <= 26) {
1320
- return `ctrl+${String.fromCharCode(code + 96)}`;
1321
- }
1322
- if (code >= 32 && code <= 126) {
1323
- return data;
1324
- }
1325
- }
1326
-
1327
- return undefined;
1328
- }
1329
-
1330
- // =============================================================================
1331
- // Kitty CSI-u Printable Decoding
1332
- // =============================================================================
1333
-
1334
- const KITTY_CSI_U_REGEX = /^\x1b\[(\d+)(?::(\d*))?(?::(\d+))?(?:;(\d+))?(?::(\d+))?u$/;
1335
- const KITTY_PRINTABLE_ALLOWED_MODIFIERS = MODIFIERS.shift | LOCK_MASK;
1336
-
1337
- /**
1338
- * Decode a Kitty CSI-u sequence into a printable character, if applicable.
1339
- *
1340
- * When Kitty keyboard protocol flag 1 (disambiguate) is active, terminals send
1341
- * CSI-u sequences for all keys, including plain printable characters. This
1342
- * function extracts the printable character from such sequences.
1343
- *
1344
- * Only accepts plain or Shift-modified keys. Rejects Ctrl, Alt, and unsupported
1345
- * modifier combinations (those are handled by keybinding matching instead).
1346
- * Prefers the shifted keycode when Shift is held and a shifted key is reported.
1347
- *
1348
- * @param data - Raw input data from terminal
1349
- * @returns The printable character, or undefined if not a printable CSI-u sequence
1350
- */
1351
- export function decodeKittyPrintable(data: string): string | undefined {
1352
- const match = data.match(KITTY_CSI_U_REGEX);
1353
- if (!match) return undefined;
1354
-
1355
- // CSI-u groups: <codepoint>[:<shifted>[:<base>]];<mod>[:<event>]u
1356
- const codepoint = Number.parseInt(match[1] ?? "", 10);
1357
- if (!Number.isFinite(codepoint)) return undefined;
1358
-
1359
- const shiftedKey = match[2] && match[2].length > 0 ? Number.parseInt(match[2], 10) : undefined;
1360
- const modValue = match[4] ? Number.parseInt(match[4], 10) : 1;
1361
- // Modifiers are 1-indexed in CSI-u; normalize to our bitmask.
1362
- const modifier = Number.isFinite(modValue) ? modValue - 1 : 0;
1363
-
1364
- // Only accept printable CSI-u input for plain or Shift-modified text keys.
1365
- // Reject unsupported modifier bits (e.g. Super/Meta) to avoid inserting
1366
- // characters from modifier-only terminal events.
1367
- if ((modifier & ~KITTY_PRINTABLE_ALLOWED_MODIFIERS) !== 0) return undefined;
1368
- if (modifier & (MODIFIERS.alt | MODIFIERS.ctrl)) return undefined;
1369
-
1370
- // Prefer the shifted keycode when Shift is held.
1371
- let effectiveCodepoint = codepoint;
1372
- if (modifier & MODIFIERS.shift && typeof shiftedKey === "number") {
1373
- effectiveCodepoint = shiftedKey;
1374
- }
1375
- effectiveCodepoint = normalizeKittyFunctionalCodepoint(effectiveCodepoint);
1376
- // Drop control characters or invalid codepoints.
1377
- if (!Number.isFinite(effectiveCodepoint) || effectiveCodepoint < 32) return undefined;
1378
-
1379
- try {
1380
- return String.fromCodePoint(effectiveCodepoint);
1381
- } catch {
1382
- return undefined;
1383
- }
1384
- }
1385
-
1386
- function decodeModifyOtherKeysPrintable(data: string): string | undefined {
1387
- const parsed = parseModifyOtherKeysSequence(data);
1388
- if (!parsed) return undefined;
1389
- const modifier = parsed.modifier & ~LOCK_MASK;
1390
- if ((modifier & ~MODIFIERS.shift) !== 0) return undefined;
1391
- if (!Number.isFinite(parsed.codepoint) || parsed.codepoint < 32) return undefined;
1392
-
1393
- try {
1394
- return String.fromCodePoint(parsed.codepoint);
1395
- } catch {
1396
- return undefined;
1397
- }
1398
- }
1399
-
1400
- export function decodePrintableKey(data: string): string | undefined {
1401
- return decodeKittyPrintable(data) ?? decodeModifyOtherKeysPrintable(data);
1402
- }