@linxiraos/pi-tui 1.4.6 → 1.4.9

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 (399) hide show
  1. package/CHANGELOG.md +162 -244
  2. package/README.md +41 -35
  3. package/dist/types/app-keybindings.d.ts +20 -0
  4. package/dist/types/apps/session-picker.d.ts +5 -0
  5. package/dist/types/charts/chart-plan.d.ts +9 -7
  6. package/dist/types/charts/table-data.d.ts +4 -2
  7. package/dist/types/chat/assistant-message.d.ts +15 -3
  8. package/dist/types/chat/bash-execution.d.ts +6 -1
  9. package/dist/types/chat/display-preferences.d.ts +2 -0
  10. package/dist/types/chat/eval-execution.d.ts +2 -0
  11. package/dist/types/chat/execution-shared.d.ts +14 -8
  12. package/dist/types/chat/extension-types.d.ts +31 -0
  13. package/dist/types/chat/figure-markdown.d.ts +2 -0
  14. package/dist/types/chat/reply-write.d.ts +48 -0
  15. package/dist/types/chat/svg-figure.d.ts +5 -0
  16. package/dist/types/chat/table-chart.d.ts +6 -3
  17. package/dist/types/chat/tool-execution.d.ts +1 -2
  18. package/dist/types/chat/transcript-outline.d.ts +7 -0
  19. package/dist/types/chat/transcript-render-helpers.d.ts +13 -3
  20. package/dist/types/chrome/dynamic-border.d.ts +6 -0
  21. package/dist/types/chrome/index.d.ts +1 -0
  22. package/dist/types/chrome/transcript-notice.d.ts +35 -0
  23. package/dist/types/chrome/transcript-status.d.ts +21 -9
  24. package/dist/types/components/editor.d.ts +23 -6
  25. package/dist/types/components/image.d.ts +6 -0
  26. package/dist/types/components/loader.d.ts +2 -0
  27. package/dist/types/components/markdown.d.ts +7 -0
  28. package/dist/types/keybinding-matchers.d.ts +7 -0
  29. package/dist/types/native/blobs.d.ts +2 -1
  30. package/dist/types/native/describe.d.ts +4 -2
  31. package/dist/types/native/node.d.ts +2 -3
  32. package/dist/types/native/overlay.d.ts +42 -2
  33. package/dist/types/native/picker.d.ts +4 -4
  34. package/dist/types/native/state.d.ts +4 -0
  35. package/dist/types/overlays/annotation-overlay.d.ts +7 -1
  36. package/dist/types/overlays/annotation-types.d.ts +28 -0
  37. package/dist/types/overlays/btw-history-panel.d.ts +15 -0
  38. package/dist/types/overlays/btw-history.d.ts +24 -0
  39. package/dist/types/overlays/btw-inject.d.ts +22 -0
  40. package/dist/types/overlays/btw-panel.d.ts +7 -0
  41. package/dist/types/overlays/hook-editor.d.ts +2 -0
  42. package/dist/types/overlays/jobs-panel.d.ts +4 -0
  43. package/dist/types/overlays/login-dialog.d.ts +5 -1
  44. package/dist/types/overlays/model-browser.d.ts +11 -2
  45. package/dist/types/overlays/oauth-selector.d.ts +23 -0
  46. package/dist/types/overlays/plan-review-overlay.d.ts +2 -0
  47. package/dist/types/overlays/rewind-selector.d.ts +1 -1
  48. package/dist/types/overlays/session-selector.d.ts +33 -4
  49. package/dist/types/prompt/composer.d.ts +56 -5
  50. package/dist/types/prompt/interactive-context-helpers.d.ts +10 -3
  51. package/dist/types/render/extension-links.d.ts +65 -0
  52. package/dist/types/render/hyperlink.d.ts +25 -7
  53. package/dist/types/render/index.d.ts +1 -0
  54. package/dist/types/render/render-utils.d.ts +23 -1
  55. package/dist/types/setup/scenes/glyph.d.ts +1 -1
  56. package/dist/types/setup/scenes/model.d.ts +1 -1
  57. package/dist/types/setup/scenes/outro.d.ts +5 -4
  58. package/dist/types/setup/scenes/sign-in.d.ts +13 -8
  59. package/dist/types/setup/scenes/types.d.ts +16 -1
  60. package/dist/types/setup/startup-splash.d.ts +1 -1
  61. package/dist/types/setup/wizard-overlay.d.ts +11 -7
  62. package/dist/types/setup/wizard.d.ts +5 -1
  63. package/dist/types/status-line/component.d.ts +1 -1
  64. package/dist/types/status-line/context-usage.d.ts +28 -6
  65. package/dist/types/status-line/host.d.ts +6 -2
  66. package/dist/types/status-line/startup.d.ts +0 -15
  67. package/dist/types/terminal-capabilities.d.ts +1 -1
  68. package/dist/types/theme/symbols.d.ts +3 -1
  69. package/dist/types/theme/theme-class.d.ts +1 -0
  70. package/dist/types/theme/theme.d.ts +1 -24
  71. package/dist/types/theme/tui-adapters.d.ts +2 -0
  72. package/dist/types/thinking.d.ts +8 -6
  73. package/dist/types/tools/ast-grep.d.ts +2 -0
  74. package/dist/types/tools/bash-interactive.d.ts +6 -0
  75. package/dist/types/tools/bash.d.ts +2 -0
  76. package/dist/types/tools/default-renderer.d.ts +6 -4
  77. package/dist/types/tools/eval.d.ts +2 -0
  78. package/dist/types/tools/find.d.ts +1 -1
  79. package/dist/types/tools/grouped-file-output.d.ts +100 -19
  80. package/dist/types/tools/hashline-format.d.ts +5 -0
  81. package/dist/types/tools/irc.d.ts +6 -0
  82. package/dist/types/tools/json-tree.d.ts +23 -4
  83. package/dist/types/tools/lsp.d.ts +2 -0
  84. package/dist/types/tools/mcp.d.ts +6 -5
  85. package/dist/types/tools/native-view.d.ts +3 -1
  86. package/dist/types/tools/output-meta.d.ts +27 -0
  87. package/dist/types/tools/read.d.ts +14 -4
  88. package/dist/types/tools/renderer.d.ts +2 -0
  89. package/dist/types/tools/streaming-output.d.ts +11 -0
  90. package/dist/types/tools/task.d.ts +13 -4
  91. package/dist/types/tools/url-scheme-host.d.ts +17 -0
  92. package/dist/types/tools/wait.d.ts +2 -0
  93. package/dist/types/tools/yield.d.ts +1 -1
  94. package/dist/types/tui.d.ts +19 -2
  95. package/dist/types/utils.d.ts +4 -0
  96. package/package.json +10 -14
  97. package/src/app-keybindings.d.ts +20 -0
  98. package/src/app-keybindings.ts +20 -0
  99. package/src/apps/git/git-tui.ts +10 -17
  100. package/src/apps/git/sidebar.ts +21 -35
  101. package/src/apps/ps-top.ts +4 -12
  102. package/src/apps/session-picker.ts +7 -0
  103. package/src/charts/chart-plan.d.ts +9 -7
  104. package/src/charts/chart-plan.ts +20 -79
  105. package/src/charts/table-data.d.ts +4 -2
  106. package/src/charts/table-data.ts +55 -6
  107. package/src/chat/advisor-message.ts +2 -0
  108. package/src/chat/assistant-message.d.ts +15 -3
  109. package/src/chat/assistant-message.ts +137 -19
  110. package/src/chat/background-tan-message.ts +4 -0
  111. package/src/chat/bash-execution.d.ts +6 -1
  112. package/src/chat/bash-execution.ts +26 -9
  113. package/src/chat/chat-transcript-builder.ts +63 -30
  114. package/src/chat/compaction-summary-message.ts +2 -1
  115. package/src/chat/display-preferences.d.ts +2 -0
  116. package/src/chat/display-preferences.ts +3 -0
  117. package/src/chat/eval-execution.d.ts +2 -0
  118. package/src/chat/eval-execution.ts +14 -7
  119. package/src/chat/execution-shared.d.ts +14 -8
  120. package/src/chat/execution-shared.ts +39 -18
  121. package/src/chat/extension-types.d.ts +31 -0
  122. package/src/chat/extension-types.ts +34 -0
  123. package/src/chat/figure-markdown.d.ts +2 -0
  124. package/src/chat/figure-markdown.ts +6 -4
  125. package/src/chat/read-tool-group.ts +56 -36
  126. package/src/chat/reply-write.d.ts +48 -0
  127. package/src/chat/reply-write.ts +127 -0
  128. package/src/chat/svg-figure.d.ts +5 -0
  129. package/src/chat/svg-figure.ts +55 -16
  130. package/src/chat/table-chart.d.ts +6 -3
  131. package/src/chat/table-chart.ts +29 -6
  132. package/src/chat/tool-execution.d.ts +1 -2
  133. package/src/chat/tool-execution.ts +20 -13
  134. package/src/chat/transcript-outline.d.ts +7 -0
  135. package/src/chat/transcript-outline.ts +27 -0
  136. package/src/chat/transcript-render-helpers.d.ts +13 -3
  137. package/src/chat/transcript-render-helpers.ts +134 -44
  138. package/src/chrome/dynamic-border.d.ts +6 -0
  139. package/src/chrome/dynamic-border.ts +28 -2
  140. package/src/chrome/index.ts +1 -0
  141. package/src/chrome/transcript-notice.d.ts +35 -0
  142. package/src/chrome/transcript-notice.ts +83 -0
  143. package/src/chrome/transcript-status.d.ts +21 -9
  144. package/src/chrome/transcript-status.ts +32 -30
  145. package/src/components/editor.d.ts +23 -6
  146. package/src/components/editor.ts +133 -25
  147. package/src/components/image.d.ts +6 -0
  148. package/src/components/image.ts +13 -0
  149. package/src/components/key-value-list.ts +9 -9
  150. package/src/components/loader.d.ts +2 -0
  151. package/src/components/loader.ts +7 -0
  152. package/src/components/markdown.d.ts +7 -0
  153. package/src/components/markdown.ts +116 -6
  154. package/src/components/section.ts +1 -9
  155. package/src/components/table.ts +1 -9
  156. package/src/hotkeys-markdown.ts +1 -0
  157. package/src/keybinding-matchers.d.ts +7 -0
  158. package/src/keybinding-matchers.ts +13 -0
  159. package/src/native/backend.ts +10 -67
  160. package/src/native/blobs.d.ts +2 -1
  161. package/src/native/blobs.ts +3 -2
  162. package/src/native/describe.d.ts +4 -2
  163. package/src/native/describe.ts +9 -4
  164. package/src/native/node.d.ts +2 -3
  165. package/src/native/node.ts +2 -3
  166. package/src/native/overlay.d.ts +42 -2
  167. package/src/native/overlay.ts +124 -16
  168. package/src/native/picker.d.ts +4 -4
  169. package/src/native/picker.ts +4 -4
  170. package/src/native/state.d.ts +4 -0
  171. package/src/native/state.ts +25 -5
  172. package/src/overlays/advisor-config.ts +1 -10
  173. package/src/overlays/annotation-overlay.ts +125 -37
  174. package/src/overlays/annotation-types.ts +24 -0
  175. package/src/overlays/btw-history-panel.ts +106 -14
  176. package/src/overlays/btw-history.ts +65 -0
  177. package/src/overlays/btw-inject.ts +91 -0
  178. package/src/overlays/btw-panel.ts +53 -12
  179. package/src/overlays/extensions/extension-dashboard.ts +7 -8
  180. package/src/overlays/hook-editor.ts +6 -0
  181. package/src/overlays/hook-selector.ts +2 -2
  182. package/src/overlays/jobs-panel.ts +82 -22
  183. package/src/overlays/login-dialog.ts +39 -31
  184. package/src/overlays/mcp-add-wizard.ts +1 -1
  185. package/src/overlays/model-browser.ts +106 -10
  186. package/src/overlays/model-hub.ts +1 -7
  187. package/src/overlays/model-picker.ts +1 -10
  188. package/src/overlays/oauth-selector.ts +44 -6
  189. package/src/overlays/plan-review-overlay.ts +13 -2
  190. package/src/overlays/rewind-selector.ts +29 -12
  191. package/src/overlays/session-selector.ts +338 -47
  192. package/src/overlays/settings-defs.ts +2 -2
  193. package/src/overlays/tree-selector.ts +83 -27
  194. package/src/overlays/usage-dashboard.ts +9 -18
  195. package/src/prompt/composer.ts +233 -6
  196. package/src/prompt/custom-editor.ts +6 -1
  197. package/src/prompt/emoji-autocomplete.ts +0 -2
  198. package/src/prompt/interactive-context-helpers.ts +29 -4
  199. package/src/render/code-cell.ts +1 -1
  200. package/src/render/extension-links.d.ts +65 -0
  201. package/src/render/extension-links.ts +214 -0
  202. package/src/render/file-list.ts +4 -7
  203. package/src/render/hyperlink.d.ts +25 -7
  204. package/src/render/hyperlink.ts +65 -9
  205. package/src/render/index.d.ts +1 -0
  206. package/src/render/index.ts +1 -0
  207. package/src/render/render-utils.d.ts +23 -1
  208. package/src/render/render-utils.ts +38 -6
  209. package/src/setup/scenes/composer.ts +2 -0
  210. package/src/setup/scenes/glyph.ts +4 -2
  211. package/src/setup/scenes/model.ts +192 -29
  212. package/src/setup/scenes/outro.ts +33 -15
  213. package/src/setup/scenes/sign-in.ts +196 -400
  214. package/src/setup/scenes/theme.ts +2 -0
  215. package/src/setup/scenes/types.ts +18 -1
  216. package/src/setup/startup-splash.ts +8 -7
  217. package/src/setup/wizard-overlay.ts +164 -35
  218. package/src/setup/wizard.ts +11 -2
  219. package/src/status-line/component.ts +4 -10
  220. package/src/status-line/context-usage.ts +72 -21
  221. package/src/status-line/host.ts +6 -2
  222. package/src/status-line/startup.ts +36 -70
  223. package/src/terminal-capabilities.d.ts +1 -1
  224. package/src/terminal-capabilities.ts +5 -0
  225. package/src/terminal.ts +24 -2
  226. package/src/theme/defaults.json +1 -0
  227. package/src/theme/loader.ts +1 -1
  228. package/src/theme/symbols.d.ts +3 -1
  229. package/src/theme/symbols.ts +16 -9
  230. package/src/theme/theme-class.d.ts +1 -0
  231. package/src/theme/theme-class.ts +15 -3
  232. package/src/theme/theme.d.ts +1 -24
  233. package/src/theme/theme.ts +3 -75
  234. package/src/theme/tui-adapters.d.ts +2 -0
  235. package/src/theme/tui-adapters.ts +8 -3
  236. package/src/thinking.d.ts +8 -6
  237. package/src/thinking.ts +17 -11
  238. package/src/tmux.ts +1 -0
  239. package/src/tools/agent-tree.ts +13 -11
  240. package/src/tools/ask.ts +24 -37
  241. package/src/tools/ast-edit.ts +48 -93
  242. package/src/tools/ast-grep.d.ts +2 -0
  243. package/src/tools/ast-grep.ts +31 -67
  244. package/src/tools/bash-interactive.d.ts +49 -0
  245. package/src/tools/bash-interactive.ts +6 -1
  246. package/src/tools/bash.d.ts +2 -0
  247. package/src/tools/bash.ts +9 -0
  248. package/src/tools/default-renderer.d.ts +6 -4
  249. package/src/tools/default-renderer.ts +10 -7
  250. package/src/tools/edit.ts +50 -43
  251. package/src/tools/eval.d.ts +2 -0
  252. package/src/tools/eval.ts +16 -4
  253. package/src/tools/fetch.ts +2 -1
  254. package/src/tools/find.d.ts +1 -1
  255. package/src/tools/find.ts +13 -5
  256. package/src/tools/github.ts +14 -46
  257. package/src/tools/glob.ts +2 -1
  258. package/src/tools/grep.ts +47 -277
  259. package/src/tools/grouped-file-output.d.ts +100 -19
  260. package/src/tools/grouped-file-output.ts +414 -103
  261. package/src/tools/hashline-format.d.ts +5 -0
  262. package/src/tools/hashline-format.ts +5 -0
  263. package/src/tools/irc.d.ts +6 -0
  264. package/src/tools/irc.ts +6 -0
  265. package/src/tools/job-widget.ts +13 -1
  266. package/src/tools/json-tree.d.ts +23 -4
  267. package/src/tools/json-tree.ts +132 -46
  268. package/src/tools/lsp.d.ts +2 -0
  269. package/src/tools/lsp.ts +246 -47
  270. package/src/tools/mcp.d.ts +6 -5
  271. package/src/tools/mcp.ts +20 -12
  272. package/src/tools/native-view.d.ts +3 -1
  273. package/src/tools/native-view.ts +12 -6
  274. package/src/tools/output-meta.d.ts +27 -0
  275. package/src/tools/output-meta.ts +68 -4
  276. package/src/tools/proc-render.ts +3 -3
  277. package/src/tools/read.d.ts +14 -4
  278. package/src/tools/read.ts +20 -5
  279. package/src/tools/renderer.d.ts +2 -0
  280. package/src/tools/renderer.ts +2 -0
  281. package/src/tools/streaming-output.d.ts +11 -0
  282. package/src/tools/streaming-output.ts +41 -0
  283. package/src/tools/task.d.ts +13 -4
  284. package/src/tools/task.ts +100 -97
  285. package/src/tools/url-scheme-host.d.ts +17 -0
  286. package/src/tools/url-scheme-host.ts +21 -0
  287. package/src/tools/vibe.ts +4 -4
  288. package/src/tools/wait.d.ts +2 -0
  289. package/src/tools/wait.ts +8 -5
  290. package/src/tools/write.ts +17 -27
  291. package/src/tools/yield.d.ts +1 -1
  292. package/src/tools/yield.ts +19 -10
  293. package/src/tui.d.ts +19 -2
  294. package/src/tui.ts +134 -24
  295. package/src/utils.d.ts +4 -0
  296. package/src/utils.ts +10 -0
  297. package/dist/types/theme/defaults/index.d.ts +0 -10289
  298. package/src/theme/defaults/alabaster.json +0 -103
  299. package/src/theme/defaults/amethyst.json +0 -106
  300. package/src/theme/defaults/anthracite.json +0 -103
  301. package/src/theme/defaults/basalt.json +0 -101
  302. package/src/theme/defaults/birch.json +0 -105
  303. package/src/theme/defaults/dark-abyss.json +0 -101
  304. package/src/theme/defaults/dark-arctic.json +0 -114
  305. package/src/theme/defaults/dark-aurora.json +0 -105
  306. package/src/theme/defaults/dark-catppuccin.json +0 -117
  307. package/src/theme/defaults/dark-cavern.json +0 -101
  308. package/src/theme/defaults/dark-celestial.json +0 -116
  309. package/src/theme/defaults/dark-copper.json +0 -105
  310. package/src/theme/defaults/dark-cosmos.json +0 -100
  311. package/src/theme/defaults/dark-cyberpunk.json +0 -112
  312. package/src/theme/defaults/dark-dracula.json +0 -108
  313. package/src/theme/defaults/dark-eclipse.json +0 -101
  314. package/src/theme/defaults/dark-ember.json +0 -105
  315. package/src/theme/defaults/dark-equinox.json +0 -100
  316. package/src/theme/defaults/dark-forest.json +0 -106
  317. package/src/theme/defaults/dark-github.json +0 -115
  318. package/src/theme/defaults/dark-gruvbox.json +0 -122
  319. package/src/theme/defaults/dark-lavender.json +0 -105
  320. package/src/theme/defaults/dark-lunar.json +0 -99
  321. package/src/theme/defaults/dark-midnight.json +0 -105
  322. package/src/theme/defaults/dark-monochrome.json +0 -104
  323. package/src/theme/defaults/dark-monokai.json +0 -108
  324. package/src/theme/defaults/dark-nebula.json +0 -100
  325. package/src/theme/defaults/dark-neon-noir.json +0 -110
  326. package/src/theme/defaults/dark-nord.json +0 -108
  327. package/src/theme/defaults/dark-ocean.json +0 -111
  328. package/src/theme/defaults/dark-one.json +0 -110
  329. package/src/theme/defaults/dark-poimandres.json +0 -125
  330. package/src/theme/defaults/dark-rainforest.json +0 -101
  331. package/src/theme/defaults/dark-reef.json +0 -101
  332. package/src/theme/defaults/dark-retro.json +0 -102
  333. package/src/theme/defaults/dark-rose-pine.json +0 -106
  334. package/src/theme/defaults/dark-sakura.json +0 -105
  335. package/src/theme/defaults/dark-slate.json +0 -105
  336. package/src/theme/defaults/dark-solarized.json +0 -107
  337. package/src/theme/defaults/dark-solstice.json +0 -100
  338. package/src/theme/defaults/dark-starfall.json +0 -101
  339. package/src/theme/defaults/dark-sunset.json +0 -109
  340. package/src/theme/defaults/dark-swamp.json +0 -100
  341. package/src/theme/defaults/dark-synthwave.json +0 -113
  342. package/src/theme/defaults/dark-taiga.json +0 -101
  343. package/src/theme/defaults/dark-terminal.json +0 -105
  344. package/src/theme/defaults/dark-tokyo-night.json +0 -111
  345. package/src/theme/defaults/dark-tundra.json +0 -101
  346. package/src/theme/defaults/dark-twilight.json +0 -101
  347. package/src/theme/defaults/dark-volcanic.json +0 -101
  348. package/src/theme/defaults/graphite.json +0 -102
  349. package/src/theme/defaults/index.d.ts +0 -10289
  350. package/src/theme/defaults/index.ts +0 -203
  351. package/src/theme/defaults/light-arctic.json +0 -117
  352. package/src/theme/defaults/light-aurora-day.json +0 -101
  353. package/src/theme/defaults/light-canyon.json +0 -101
  354. package/src/theme/defaults/light-catppuccin.json +0 -116
  355. package/src/theme/defaults/light-cirrus.json +0 -100
  356. package/src/theme/defaults/light-coral.json +0 -105
  357. package/src/theme/defaults/light-cyberpunk.json +0 -106
  358. package/src/theme/defaults/light-dawn.json +0 -100
  359. package/src/theme/defaults/light-dunes.json +0 -101
  360. package/src/theme/defaults/light-eucalyptus.json +0 -105
  361. package/src/theme/defaults/light-forest.json +0 -110
  362. package/src/theme/defaults/light-frost.json +0 -105
  363. package/src/theme/defaults/light-github.json +0 -125
  364. package/src/theme/defaults/light-glacier.json +0 -101
  365. package/src/theme/defaults/light-gruvbox.json +0 -118
  366. package/src/theme/defaults/light-haze.json +0 -100
  367. package/src/theme/defaults/light-honeycomb.json +0 -105
  368. package/src/theme/defaults/light-lagoon.json +0 -101
  369. package/src/theme/defaults/light-lavender.json +0 -105
  370. package/src/theme/defaults/light-meadow.json +0 -101
  371. package/src/theme/defaults/light-mint.json +0 -105
  372. package/src/theme/defaults/light-monochrome.json +0 -111
  373. package/src/theme/defaults/light-ocean.json +0 -109
  374. package/src/theme/defaults/light-one.json +0 -109
  375. package/src/theme/defaults/light-opal.json +0 -101
  376. package/src/theme/defaults/light-orchard.json +0 -101
  377. package/src/theme/defaults/light-paper.json +0 -105
  378. package/src/theme/defaults/light-poimandres.json +0 -125
  379. package/src/theme/defaults/light-prism.json +0 -100
  380. package/src/theme/defaults/light-retro.json +0 -108
  381. package/src/theme/defaults/light-sand.json +0 -105
  382. package/src/theme/defaults/light-savanna.json +0 -101
  383. package/src/theme/defaults/light-solarized.json +0 -112
  384. package/src/theme/defaults/light-soleil.json +0 -100
  385. package/src/theme/defaults/light-sunset.json +0 -109
  386. package/src/theme/defaults/light-synthwave.json +0 -108
  387. package/src/theme/defaults/light-tokyo-night.json +0 -121
  388. package/src/theme/defaults/light-wetland.json +0 -101
  389. package/src/theme/defaults/light-zenith.json +0 -99
  390. package/src/theme/defaults/limestone.json +0 -104
  391. package/src/theme/defaults/mahogany.json +0 -107
  392. package/src/theme/defaults/marble.json +0 -103
  393. package/src/theme/defaults/obsidian.json +0 -101
  394. package/src/theme/defaults/onyx.json +0 -101
  395. package/src/theme/defaults/pearl.json +0 -103
  396. package/src/theme/defaults/porcelain.json +0 -101
  397. package/src/theme/defaults/quartz.json +0 -106
  398. package/src/theme/defaults/sandstone.json +0 -105
  399. package/src/theme/defaults/titanium.json +0 -100
@@ -1,113 +1,67 @@
1
1
  import type { AuthStorage } from "@linxiraos/pi-ai";
2
2
  import { PASTE_CODE_LOGIN_PROVIDERS } from "@linxiraos/pi-ai";
3
- import type { OAuthPrompt, OAuthProvider } from "@linxiraos/pi-ai/oauth/types";
4
- import { type Component, type Focusable, Container } from "../../tui";
3
+ import { getOAuthProviders } from "@linxiraos/pi-ai/oauth";
4
+ import type { OAuthProvider } from "@linxiraos/pi-ai/oauth/types";
5
+ import type { TspText } from "@linxiraos/pi-wire";
6
+ import { getAgentDbPath } from "@linxiraos/pi-utils";
7
+ import { Container } from "../../tui";
5
8
  import { Spacer } from "../../components/spacer";
6
9
  import { Text } from "../../components/text";
7
10
  import { WizardStep } from "../../components/wizard-step";
8
- import { Input } from "../../components/input";
9
- import { formatKeyHint } from "../../app-keybindings";
10
11
  import { editorKey } from "../../chrome/keybinding-hints";
11
- import { matchesKey } from "../../keys";
12
12
  import { type SgrMouseEvent } from "../../mouse";
13
13
  import { wrapTextWithAnsi } from "../../utils";
14
- import { getAgentDbPath } from "@linxiraos/pi-utils";
15
- import { OAuthSelectorComponent } from "../../overlays/oauth-selector";
14
+ import { LoginDialogComponent } from "../../overlays/login-dialog";
15
+ import { type OAuthSelectorSheet, OAuthSelectorComponent } from "../../overlays/oauth-selector";
16
16
  import { theme } from "../../theme/theme";
17
- import { col, node, span, text } from "../../native/describe";
18
- import type { NativeChild, NativeNode } from "../../native/node";
17
+ import { col, node, span } from "../../native/describe";
18
+ import type { DescribeContext, NativeChild, NativeNode } from "../../native/node";
19
19
  import { Memo } from "../../native/memo";
20
- import type { SetupScene, SetupSceneController, SetupSceneHost, StyledLine } from "./types";
21
-
22
- function loginUrlLink(url: string): string {
23
- return `\x1b]8;;${url}\x07Open login URL\x1b]8;;\x07`;
24
- }
25
-
26
- function loginCopyHint(): string {
27
- return theme.fg("dim", `(clipboard copy attempted; ${formatKeyHint("alt+c")} retries)`);
28
- }
29
-
30
- class CopyablePromptInput implements Component, Focusable {
31
- #input: Input;
32
- #onCopy: () => void;
33
- readonly #native: NativeNode;
34
-
35
- constructor(input: Input, onCopy: () => void) {
36
- this.#input = input;
37
- this.#onCopy = onCopy;
38
- this.#native = col([input]);
39
- }
40
-
41
- get focused(): boolean {
42
- return this.#input.focused;
43
- }
44
-
45
- set focused(value: boolean) {
46
- this.#input.focused = value;
47
- }
48
-
49
- setUseTerminalCursor(useTerminalCursor: boolean): void {
50
- this.#input.setUseTerminalCursor(useTerminalCursor);
51
- }
52
-
53
- render(width: number): readonly string[] {
54
- return this.#input.render(width);
55
- }
56
-
57
- /** The wrapped field describes itself (`input`, caret while focused); alt+c stays a key here. */
58
- describe(): NativeNode {
59
- return this.#native;
60
- }
61
-
62
- handleInput(data: string): void {
63
- if (matchesKey(data, "alt+c")) {
64
- this.#onCopy();
65
- return;
66
- }
67
- this.#input.handleInput(data);
68
- }
69
-
70
- /** Enhanced-paste delivery targets the focused component's `pasteText`; without it the
71
- * payload fell back to the detached main editor and never reached this field. */
72
- pasteText(text: string): void {
73
- this.#input.pasteText(text);
74
- }
75
-
76
- invalidate(): void {
77
- this.#input.invalidate();
78
- }
79
- }
80
-
81
- interface PromptState {
82
- message: string;
83
- placeholder?: string;
84
- input: CopyablePromptInput;
85
- }
20
+ import {
21
+ SETUP_SHEET_ROLE,
22
+ type SetupScene,
23
+ type SetupSceneController,
24
+ type SetupSceneHost,
25
+ type StyledLine,
26
+ } from "./types";
27
+
28
+ const SCENE_TITLE = "Sign in to your providers";
29
+ /** Login dialog rows kept above a cut on short screens: top border, spacer, first sign-in link row. */
30
+ const DIALOG_HEAD_ROWS = 3;
31
+ const LIST_LEAD = "Pick a provider to sign in — you can connect more than one.";
32
+ /** The provider sheet's subtitle: its title and rows already say "pick a provider". */
33
+ const SHEET_LEAD = "You can connect more than one.";
34
+
35
+ /** The last finished sign-in (`provider` is the display name): shown on the provider sheet (natively) or under the list (ANSI). */
36
+ type SignInOutcome =
37
+ | { readonly kind: "success"; readonly provider: string }
38
+ | { readonly kind: "error"; readonly provider: string; readonly message: string };
86
39
 
87
40
  /**
88
41
  * "Sign in" scene: lets the user authenticate one or more model providers via
89
42
  * OAuth. It never auto-advances the wizard — the user may sign in to several
90
- * providers and then continue with Esc.
43
+ * providers and then leave the step with Esc.
44
+ *
45
+ * Picking is the provider selector (natively a setup sheet: Skip/Continue on
46
+ * Esc, Sign in on Enter); signing in is the app's {@link LoginDialogComponent},
47
+ * driven like `/login` drives it: natively its own sheet over the setup page,
48
+ * in the cell grid drawn in the wizard body in place of the selector.
91
49
  */
92
50
  export class SignInScene implements SetupSceneController {
93
- readonly title = "Sign in to your providers";
51
+ readonly title = SCENE_TITLE;
94
52
  get subtitle(): string {
95
53
  return `Sign in to one or more providers. Press ${editorKey("tui.select.cancel")} when you're done.`;
96
54
  }
97
55
 
98
56
  #authStorage: AuthStorage;
99
57
  #selector: OAuthSelectorComponent;
100
- /** Status copy under the selector or login flow; replaced (never mutated) on change. */
101
- #statusLines: readonly StyledLine[] = [];
102
- #authUrl: string | undefined;
103
- #authLaunchUrl: string | undefined;
104
- #prompt: PromptState | undefined;
105
- #promptResolve: ((value: string) => void) | undefined;
106
- #promptReject: ((error: Error) => void) | undefined;
107
- #promptAbortCleanup: (() => void) | undefined;
108
- #loginAbort: AbortController | undefined;
109
- #loggingInProvider: string | undefined;
110
- #disposed = false;
58
+ /** The login flow on screen; undefined while picking. */
59
+ #dialog: LoginDialogComponent | undefined;
60
+ #outcome: SignInOutcome | undefined;
61
+ /** A sign-in succeeded in this scene: leaving the step reads "Continue". */
62
+ #signedIn = false;
63
+ /** Aborts a running login when the scene goes away. */
64
+ #lifetime = new AbortController();
111
65
  #step: WizardStep | undefined;
112
66
  #native = new Memo();
113
67
 
@@ -116,380 +70,222 @@ export class SignInScene implements SetupSceneController {
116
70
  constructor(host: SetupSceneHost) {
117
71
  this.#host = host;
118
72
  this.#authStorage = host.ctx.authStorage;
119
- this.#selector = this.#createSelector();
73
+ this.#selector = new OAuthSelectorComponent(
74
+ "login",
75
+ this.#authStorage,
76
+ providerId => {
77
+ void this.#login(providerId);
78
+ },
79
+ () => this.#host.finish(this.#signedIn ? "done" : "skipped"),
80
+ {
81
+ requestRender: () => this.#host.requestRender(),
82
+ disabledProviders: this.#host.ctx.disabledProviders,
83
+ sheet: this.#sheet(),
84
+ },
85
+ );
120
86
  }
121
87
 
122
88
  dispose(): void {
123
- this.#disposed = true;
89
+ this.#lifetime.abort();
124
90
  this.#selector.stopValidation();
125
- this.#loginAbort?.abort();
126
- this.#resolvePrompt("");
91
+ this.#dialog = undefined;
127
92
  }
128
93
 
129
94
  invalidate(): void {
130
95
  this.#native.clear();
131
96
  this.#step?.invalidate();
132
97
  this.#selector.invalidate();
133
- this.#prompt?.input.invalidate();
98
+ this.#dialog?.invalidate();
134
99
  }
135
100
 
136
101
  handleInput(data: string): void {
137
- if (this.#loggingInProvider) {
138
- if (this.#authUrl && (matchesKey(data, "alt+c") || (data === "c" && !this.#prompt))) {
139
- void this.#copyAuthUrl();
140
- return;
141
- }
142
- if (matchesKey(data, "escape") || matchesKey(data, "ctrl+c")) {
143
- this.#loginAbort?.abort();
144
- }
102
+ if (this.#dialog) {
103
+ this.#dialog.handleInput(data);
145
104
  return;
146
105
  }
147
106
  this.#selector.handleInput(data);
148
107
  }
149
108
 
150
- /** Forward mouse to the provider selector; pointer is inert during an active login or code prompt. */
109
+ /** Forward mouse to the provider selector; the login dialog takes keys only. */
151
110
  routeMouse(event: SgrMouseEvent, line: number, col: number): void {
152
- if (this.#loggingInProvider || this.#prompt) return;
111
+ if (this.#dialog) return;
153
112
  this.#step?.routeMouse(event, line, col);
154
113
  }
155
114
 
156
115
  render(width: number, maxLines?: number): readonly string[] {
116
+ const dialog = this.#dialog;
117
+ if (dialog) {
118
+ // Short screens cut the middle: the head keeps the title and the first link row (every
119
+ // wrapped URL row links the full URL), the tail the live step (code field, newest progress).
120
+ const lines = dialog.render(width);
121
+ if (maxLines === undefined || lines.length <= maxLines) return lines;
122
+ const head = maxLines >= DIALOG_HEAD_ROWS * 2 ? DIALOG_HEAD_ROWS : 0;
123
+ return [...lines.slice(0, head), ...lines.slice(lines.length - (maxLines - head))];
124
+ }
157
125
  // Hint + blank cost two rows; the wizard subtitle already explains
158
126
  // this panel, so on short screens the rows go to the provider list
159
127
  // instead (17 = full selector: 4 chrome above, 10 rows, 3 below).
160
128
  let intro: Container | undefined;
161
- if (this.#loggingInProvider === undefined && (maxLines === undefined || maxLines >= 17 + 2)) {
129
+ if (maxLines === undefined || maxLines >= 17 + 2) {
162
130
  intro = new Container();
163
- intro.addChild(
164
- new Text(theme.fg("muted", "Pick a provider to sign in — you can connect more than one."), 0, 0),
165
- );
131
+ intro.addChild(new Text(theme.fg("muted", LIST_LEAD), 0, 0));
166
132
  intro.addChild(new Spacer(1));
167
133
  }
168
- const tail = new Container();
169
- const urlLines = this.#authUrl ? wrapTextWithAnsi(theme.fg("dim", this.#authUrl), width) : [];
170
- if (this.#authUrl) {
171
- tail.addChild(
172
- new Text(theme.fg("accent", `Browser login: ${loginUrlLink(this.#authUrl)} ${loginCopyHint()}`), 0, 0),
173
- );
174
- // Keep one URL row above the prompt; repeat the complete wrapped URL
175
- // below so the input remains visible in the wizard's short viewport.
176
- if (urlLines[0]) tail.addChild(new Text(urlLines[0], 0, 0));
177
- if (this.#authLaunchUrl) {
178
- tail.addChild(
179
- new Text(theme.fg("dim", `Local shortcut (this machine only): ${this.#authLaunchUrl}`), 0, 0),
180
- );
181
- }
182
- }
183
- if (this.#prompt) {
184
- tail.addChild(new Text(theme.fg("warning", this.#prompt.message), 0, 0));
185
- if (this.#prompt.placeholder) {
186
- tail.addChild(new Text(theme.fg("dim", this.#prompt.placeholder), 0, 0));
187
- }
188
- tail.addChild(this.#prompt.input);
189
- }
190
- if (urlLines.length > 1) {
191
- for (const line of urlLines) {
192
- tail.addChild(new Text(line, 0, 0));
193
- }
194
- }
195
- for (const line of this.#statusLines) {
134
+ const status = new Container();
135
+ for (const line of this.#statusLines()) {
196
136
  for (const wrapped of wrapTextWithAnsi(theme.fg(line.color, line.text), width)) {
197
- tail.addChild(new Text(wrapped, 0, 0));
137
+ status.addChild(new Text(wrapped, 0, 0));
198
138
  }
199
139
  }
200
- if (!this.#step) {
201
- this.#step = new WizardStep({
202
- kind: "choice",
203
- content: this.#selector,
204
- gap: 0,
205
- fitContent: budget => {
206
- if (budget !== undefined) this.#selector.setMaxHeight(budget);
207
- },
208
- });
209
- }
210
- if (this.#loggingInProvider) {
211
- this.#step.setKind("async");
212
- this.#step.setHeading(new Text(theme.bold(`Signing in to ${this.#loggingInProvider}`), 0, 0));
213
- this.#step.setIntro(undefined);
214
- this.#step.setContent(tail);
215
- this.#step.setStatus(undefined);
216
- } else {
217
- this.#step.setKind("choice");
218
- this.#step.setHeading(undefined);
219
- this.#step.setIntro(intro);
220
- this.#step.setContent(this.#selector);
221
- this.#step.setStatus(tail);
222
- }
140
+ this.#step ??= new WizardStep({
141
+ kind: "choice",
142
+ content: this.#selector,
143
+ gap: 0,
144
+ fitContent: budget => {
145
+ if (budget !== undefined) this.#selector.setMaxHeight(budget);
146
+ },
147
+ });
148
+ this.#step.setIntro(intro);
149
+ this.#step.setStatus(status);
223
150
  this.#step.setMaxHeight(maxLines);
224
151
  return this.#step.render(width);
225
152
  }
226
153
 
227
154
  /**
228
- * Picking: intro, the provider selector (describes itself) and the last
229
- * outcome. Signing in: a spinner heading, the login link (with the full
230
- * URL once, char-wrapped), any code prompt and the flow's progress lines.
155
+ * Signing in: the login dialog (its own sheet). Picking: the provider
156
+ * selector, which presents the setup sheet where the terminal draws
157
+ * pickers; elsewhere it is an inline card under the lead and the outcome.
231
158
  */
232
- describe(): NativeNode {
233
- const provider = this.#loggingInProvider;
234
- const authUrl = this.#authUrl;
235
- const launchUrl = this.#authLaunchUrl;
236
- const prompt = this.#prompt;
237
- const statusLines = this.#statusLines;
238
- const copyKey = formatKeyHint("alt+c");
239
- return this.#native.get([provider, authUrl, launchUrl, prompt, statusLines, this.#selector, copyKey], () => {
240
- const tail: NativeChild[] = [];
241
- if (authUrl) {
242
- tail.push(
243
- node(
244
- "text",
245
- {
246
- spans: [
247
- span("Browser login: ", "accent"),
248
- span("Open login URL", "accent link", { href: authUrl }),
249
- span(` (clipboard copy attempted; ${copyKey} retries)`, "dim"),
250
- ],
251
- },
252
- undefined,
253
- "login",
254
- ),
255
- node(
256
- "text",
257
- { spans: [span(authUrl, "dim link", { href: authUrl })], wrap: "char", actions: { menu: ["copy"] } },
258
- undefined,
259
- "url",
260
- ),
261
- );
262
- if (launchUrl) {
263
- tail.push(
264
- node(
265
- "text",
266
- {
267
- spans: [
268
- span("Local shortcut (this machine only): ", "dim"),
269
- span(launchUrl, "dim link", { href: launchUrl }),
270
- ],
271
- wrap: "char",
272
- },
273
- undefined,
274
- "launch",
275
- ),
276
- );
277
- }
278
- }
279
- if (prompt) {
280
- const promptChildren: NativeChild[] = [text([span(prompt.message, "warning")])];
281
- if (prompt.placeholder) promptChildren.push(text([span(prompt.placeholder, "dim")]));
282
- promptChildren.push(prompt.input);
283
- tail.push(node("col", {}, promptChildren, "prompt"));
284
- }
285
- statusLines.forEach((line, index) => {
286
- tail.push(node("text", { spans: [span(line.text, line.color)] }, undefined, `status:${index}`));
159
+ describe(cx: DescribeContext): NativeNode {
160
+ const dialog = this.#dialog;
161
+ const sheet = cx.supports("picker");
162
+ const outcome = this.#outcome;
163
+ return this.#native.get([dialog, sheet, outcome, this.#selector], () => {
164
+ if (dialog) return col([dialog]);
165
+ if (sheet) return col([this.#selector]);
166
+ const children: NativeChild[] = [
167
+ node("text", { spans: [span(LIST_LEAD, "muted")] }, undefined, "intro"),
168
+ this.#selector,
169
+ ];
170
+ this.#statusLines().forEach((line, index) => {
171
+ children.push(node("text", { spans: [span(line.text, line.color)] }, undefined, `status:${index}`));
287
172
  });
288
-
289
- if (provider) {
290
- return col(
291
- [
292
- node(
293
- "row",
294
- { gap: "sm", align: "center" },
295
- [node("spinner", {}), text([span(`Signing in to ${provider}`, "strong")])],
296
- "heading",
297
- ),
298
- ...tail,
299
- ],
300
- { gap: "sm", role: "zeta.setup.sign-in", tone: "pending" },
301
- );
302
- }
303
- return col(
304
- [
305
- node(
306
- "text",
307
- { spans: [span("Pick a provider to sign in — you can connect more than one.", "muted")] },
308
- undefined,
309
- "intro",
310
- ),
311
- this.#selector,
312
- ...tail,
313
- ],
314
- { gap: "sm", role: "zeta.setup.sign-in" },
315
- );
173
+ return col(children, { gap: "sm", role: "zeta.setup.sign-in" });
316
174
  });
317
175
  }
318
176
 
319
- #createSelector(): OAuthSelectorComponent {
320
- return new OAuthSelectorComponent(
321
- "login",
322
- this.#authStorage,
323
- providerId => {
324
- void this.#login(providerId);
325
- },
326
- () => this.#host.finish("skipped"),
327
- { requestRender: () => this.#host.requestRender(), disabledProviders: this.#host.ctx.disabledProviders },
328
- );
177
+ /** The provider sheet: the step's copy, the last outcome above the action bar, and Skip until a sign-in succeeded. */
178
+ #sheet(): OAuthSelectorSheet {
179
+ const outcome = this.#outcome;
180
+ let status: TspText | undefined;
181
+ if (outcome?.kind === "success") {
182
+ status = [
183
+ span(`Signed in to ${outcome.provider}.`, "success"),
184
+ span(" Add another provider or continue.", "muted"),
185
+ ];
186
+ } else if (outcome?.kind === "error") {
187
+ status = [span(`Couldn't sign in to ${outcome.provider}: ${outcome.message}`, "error")];
188
+ }
189
+ return {
190
+ title: SCENE_TITLE,
191
+ subtitle: SHEET_LEAD,
192
+ role: SETUP_SHEET_ROLE,
193
+ size: "lg",
194
+ ...(status ? { status } : {}),
195
+ leave: { id: "skip", label: this.#signedIn ? "Continue" : "Skip" },
196
+ };
329
197
  }
330
198
 
331
- async #login(providerId: string): Promise<void> {
332
- if (this.#loggingInProvider || this.#disposed) return;
333
- const useManualInput = PASTE_CODE_LOGIN_PROVIDERS.has(providerId);
334
- this.#selector.stopValidation();
335
- this.#loggingInProvider = providerId;
336
- this.#statusLines = [{ text: "Starting OAuth flow…", color: "dim" }];
337
- this.#authUrl = undefined;
338
- this.#authLaunchUrl = undefined;
339
- this.#loginAbort = new AbortController();
340
- this.#host.restoreFocus();
341
- this.#host.requestRender();
342
- try {
343
- await this.#authStorage.oauth.login(providerId as OAuthProvider, {
344
- signal: this.#loginAbort.signal,
345
- onBrowserSession: (request, signal) => this.#host.ctx.captureBrowserSession(request, signal),
346
- onAuth: info => {
347
- // Store the full authorization URL as the primary copy/display
348
- // target: it works from any machine, including SSH boxes where
349
- // the OMP-hosted `launchUrl` would resolve against the user's
350
- // local browser and fail. The wizard render uses
351
- // `wrapTextWithAnsi`, so long URLs wrap across lines rather
352
- // than getting truncated — the RFC 7636 §4.3 PKCE-downgrade
353
- // bug that motivated `launchUrl` is unreachable through this
354
- // surface. `launchUrl` is still surfaced as an optional local
355
- // shortcut for wide-terminal local users.
356
- this.#authUrl = info.url;
357
- this.#authLaunchUrl = info.launchUrl && info.launchUrl !== info.url ? info.launchUrl : undefined;
358
- const statusLines: StyledLine[] = [];
359
- if (info.instructions) {
360
- statusLines.push({ text: info.instructions, color: "warning" });
361
- }
362
- if (useManualInput) {
363
- statusLines.push({ text: "Paste the returned code or redirect URL when prompted.", color: "dim" });
364
- }
365
- this.#statusLines = statusLines;
366
- void this.#copyAuthUrl();
367
- this.#host.ctx.openInBrowser(info.url);
368
- this.#host.requestRender();
369
- },
370
- onPrompt: prompt => this.#showPrompt(prompt),
371
- onProgress: message => {
372
- this.#statusLines = [...this.#statusLines, { text: message, color: "dim" }];
373
- this.#host.requestRender();
374
- },
375
- onManualCodeInput: signal =>
376
- this.#showPrompt({ message: "Paste the authorization code (or full redirect URL):" }, signal),
377
- });
378
- // Provider-scoped online refresh so the just-persisted credential re-runs
379
- // discovery instead of reusing a fresh authoritative cache row (#5780).
380
- await this.#host.ctx.refreshProvider(providerId);
381
- if (this.#disposed) return;
382
- this.#statusLines = [
383
- { text: `${theme.status.success} Signed in to ${providerId}`, color: "success" },
199
+ /** The last outcome as status copy under the cell-grid list (and the inline native fallback). */
200
+ #statusLines(): readonly StyledLine[] {
201
+ const outcome = this.#outcome;
202
+ if (!outcome) return [];
203
+ if (outcome.kind === "success") {
204
+ return [
205
+ { text: `${theme.status.success} Signed in to ${outcome.provider}`, color: "success" },
384
206
  { text: `Credentials saved to ${getAgentDbPath()}`, color: "dim" },
385
207
  ];
386
- this.#authUrl = undefined;
387
- this.#authLaunchUrl = undefined;
388
- this.#loggingInProvider = undefined;
389
- this.#loginAbort = undefined;
390
- this.#selector.stopValidation();
391
- this.#selector = this.#createSelector();
392
- this.#host.restoreFocus();
393
- this.#host.requestRender();
394
- } catch (error) {
395
- if (this.#disposed) return;
396
- if (this.#loginAbort?.signal.aborted) {
397
- this.#statusLines = [{ text: "Login cancelled.", color: "dim" }];
398
- this.#authUrl = undefined;
399
- this.#authLaunchUrl = undefined;
400
- } else {
401
- const message = error instanceof Error ? error.message : String(error);
402
- this.#statusLines = [
403
- { text: `Login failed: ${message}`, color: "error" },
404
- {
405
- text: `Choose another provider or press ${editorKey("tui.select.cancel")} to continue.`,
406
- color: "dim",
407
- },
408
- ];
409
- this.#authUrl = undefined;
410
- this.#authLaunchUrl = undefined;
411
- }
412
- this.#loggingInProvider = undefined;
413
- this.#loginAbort = undefined;
414
- this.#host.restoreFocus();
415
- this.#host.requestRender();
416
208
  }
209
+ return [
210
+ { text: `Login failed: ${outcome.message}`, color: "error" },
211
+ {
212
+ text: `Choose another provider or press ${editorKey("tui.select.cancel")} to continue.`,
213
+ color: "dim",
214
+ },
215
+ ];
417
216
  }
418
217
 
419
- async #copyAuthUrl(): Promise<void> {
420
- const url = this.#authUrl;
421
- if (!url) return;
422
- try {
423
- await this.#host.ctx.copyToClipboard(url);
424
- } catch {
425
- // Clipboard integration is best-effort; the full URL remains rendered below.
426
- }
427
- this.#host.requestRender();
218
+ #setOutcome(outcome: SignInOutcome | undefined): void {
219
+ this.#outcome = outcome;
220
+ if (outcome?.kind === "success") this.#signedIn = true;
221
+ this.#selector.setSheet(this.#sheet());
428
222
  }
429
223
 
430
- #showPrompt(prompt: OAuthPrompt, signal?: AbortSignal): Promise<string> {
431
- this.#resolvePrompt("");
432
- if (signal?.aborted) {
433
- return Promise.reject(signal.reason instanceof Error ? signal.reason : new Error("Login input cancelled"));
434
- }
435
- const input = new Input();
436
- input.mask = prompt.secret === true;
437
- const focusInput = new CopyablePromptInput(input, () => {
438
- void this.#copyAuthUrl();
439
- });
440
- const pending = Promise.withResolvers<string>();
441
- this.#promptResolve = pending.resolve;
442
- this.#promptReject = pending.reject;
443
- this.#prompt = { message: prompt.message, placeholder: prompt.placeholder, input: focusInput };
444
- if (signal) {
445
- const onAbort = () => {
446
- if (this.#promptReject !== pending.reject) return;
447
- this.#rejectPrompt(signal.reason instanceof Error ? signal.reason : new Error("Login input cancelled"));
448
- };
449
- signal.addEventListener("abort", onAbort, { once: true });
450
- this.#promptAbortCleanup = () => signal.removeEventListener("abort", onAbort);
451
- }
452
- input.onSubmit = value => {
453
- this.#resolvePrompt(value);
454
- };
455
- input.onEscape = () => {
456
- this.#loginAbort?.abort();
457
- this.#resolvePrompt("");
458
- };
459
- this.#host.setFocus(focusInput);
224
+ /** Back to the provider list (Esc in the dialog, or the flow settled). */
225
+ #closeDialog(dialog: LoginDialogComponent): void {
226
+ if (this.#dialog !== dialog) return;
227
+ this.#dialog = undefined;
228
+ this.#host.restoreFocus();
460
229
  this.#host.requestRender();
461
- return pending.promise;
462
- }
463
-
464
- #resolvePrompt(value: string): void {
465
- const resolve = this.#promptResolve;
466
- if (!resolve) return;
467
- this.#clearPrompt();
468
- resolve(value);
469
- }
470
-
471
- #rejectPrompt(error: Error): void {
472
- const reject = this.#promptReject;
473
- if (!reject) return;
474
- this.#clearPrompt();
475
- reject(error);
476
230
  }
477
231
 
478
- #clearPrompt(): void {
479
- this.#promptAbortCleanup?.();
480
- this.#promptAbortCleanup = undefined;
481
- this.#promptResolve = undefined;
482
- this.#promptReject = undefined;
483
- this.#prompt = undefined;
484
- this.#host.restoreFocus();
232
+ /** One provider's login, driven like `/login` drives the dialog; the outcome lands on the provider sheet. */
233
+ async #login(providerId: string): Promise<void> {
234
+ if (this.#dialog || this.#lifetime.signal.aborted) return;
235
+ const ctx = this.#host.ctx;
236
+ const useManualInput = PASTE_CODE_LOGIN_PROVIDERS.has(providerId);
237
+ const name = getOAuthProviders().find(provider => provider.id === providerId)?.name ?? providerId;
238
+ const dialog = new LoginDialogComponent(
239
+ this.#host,
240
+ providerId,
241
+ // Fires on Esc: back to the list now; the aborted flow's rejection settles below.
242
+ () => this.#closeDialog(dialog),
243
+ url => ctx.openInBrowser(url),
244
+ );
245
+ this.#dialog = dialog;
246
+ this.#setOutcome(undefined);
247
+ this.#host.setFocus(dialog);
485
248
  this.#host.requestRender();
249
+ try {
250
+ await this.#authStorage.oauth.login(providerId as OAuthProvider, {
251
+ signal: AbortSignal.any([dialog.signal, this.#lifetime.signal]),
252
+ onBrowserSession: (request, signal) => ctx.captureBrowserSession(request, signal),
253
+ onAuth: info => dialog.showAuth(info.url, info.instructions, info.launchUrl),
254
+ onPrompt: prompt => dialog.showPrompt(prompt),
255
+ onProgress: message => dialog.showProgress(message),
256
+ onManualCodeInput: useManualInput
257
+ ? signal =>
258
+ dialog.showManualInput(
259
+ `Paste the authorization code (or full redirect URL), then press ${editorKey("tui.input.submit")}:`,
260
+ signal,
261
+ )
262
+ : undefined,
263
+ });
264
+ // Provider-scoped online refresh so the just-persisted credential re-runs
265
+ // discovery instead of reusing a fresh authoritative cache row (#5780).
266
+ await ctx.refreshProvider(providerId);
267
+ if (this.#lifetime.signal.aborted) return;
268
+ this.#selector.refreshAuth();
269
+ this.#setOutcome({ kind: "success", provider: name });
270
+ } catch (error) {
271
+ // A cancel (Esc in the dialog) is quiet: the list is already back.
272
+ if (this.#lifetime.signal.aborted || dialog.signal.aborted) return;
273
+ this.#setOutcome({
274
+ kind: "error",
275
+ provider: name,
276
+ message: error instanceof Error ? error.message : String(error),
277
+ });
278
+ } finally {
279
+ if (!this.#lifetime.signal.aborted) this.#closeDialog(dialog);
280
+ }
486
281
  }
487
282
  }
488
283
 
489
284
  /** Onboarding scene for provider sign-in. */
490
285
  export const providersSetupScene: SetupScene = {
491
286
  id: "providers",
492
- title: "Sign in to your providers",
287
+ title: SCENE_TITLE,
288
+ step: "Sign in",
493
289
  minVersion: 1,
494
290
  mount: host => new SignInScene(host),
495
291
  };