@linxiraos/pi-tui 1.4.6 → 1.4.7

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 (278) hide show
  1. package/CHANGELOG.md +194 -195
  2. package/README.md +34 -34
  3. package/dist/types/app-keybindings.d.ts +15 -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/chat/assistant-message.d.ts +15 -3
  7. package/dist/types/chat/bash-execution.d.ts +2 -0
  8. package/dist/types/chat/display-preferences.d.ts +2 -0
  9. package/dist/types/chat/extension-types.d.ts +31 -0
  10. package/dist/types/chat/reply-write.d.ts +48 -0
  11. package/dist/types/chat/table-chart.d.ts +4 -3
  12. package/dist/types/chat/tool-execution.d.ts +1 -2
  13. package/dist/types/chat/transcript-outline.d.ts +7 -0
  14. package/dist/types/chat/transcript-render-helpers.d.ts +2 -0
  15. package/dist/types/chrome/index.d.ts +1 -0
  16. package/dist/types/chrome/transcript-notice.d.ts +35 -0
  17. package/dist/types/chrome/transcript-status.d.ts +20 -8
  18. package/dist/types/components/editor.d.ts +8 -0
  19. package/dist/types/components/markdown.d.ts +7 -0
  20. package/dist/types/native/blobs.d.ts +2 -1
  21. package/dist/types/native/picker.d.ts +4 -4
  22. package/dist/types/overlays/annotation-overlay.d.ts +7 -1
  23. package/dist/types/overlays/annotation-types.d.ts +28 -0
  24. package/dist/types/overlays/login-dialog.d.ts +5 -1
  25. package/dist/types/overlays/model-browser.d.ts +10 -1
  26. package/dist/types/overlays/oauth-selector.d.ts +23 -0
  27. package/dist/types/overlays/plan-review-overlay.d.ts +2 -0
  28. package/dist/types/overlays/rewind-selector.d.ts +1 -1
  29. package/dist/types/overlays/session-selector.d.ts +22 -2
  30. package/dist/types/prompt/composer.d.ts +43 -0
  31. package/dist/types/prompt/interactive-context-helpers.d.ts +10 -3
  32. package/dist/types/render/extension-links.d.ts +65 -0
  33. package/dist/types/render/hyperlink.d.ts +25 -7
  34. package/dist/types/render/index.d.ts +1 -0
  35. package/dist/types/setup/scenes/glyph.d.ts +1 -1
  36. package/dist/types/setup/scenes/model.d.ts +1 -1
  37. package/dist/types/setup/scenes/outro.d.ts +5 -4
  38. package/dist/types/setup/scenes/sign-in.d.ts +13 -8
  39. package/dist/types/setup/scenes/types.d.ts +16 -1
  40. package/dist/types/setup/startup-splash.d.ts +1 -1
  41. package/dist/types/setup/wizard-overlay.d.ts +11 -7
  42. package/dist/types/setup/wizard.d.ts +5 -1
  43. package/dist/types/status-line/component.d.ts +1 -1
  44. package/dist/types/status-line/context-usage.d.ts +28 -6
  45. package/dist/types/status-line/host.d.ts +6 -2
  46. package/dist/types/theme/theme.d.ts +0 -23
  47. package/dist/types/tools/bash-interactive.d.ts +6 -0
  48. package/dist/types/tools/bash.d.ts +2 -0
  49. package/dist/types/tools/default-renderer.d.ts +6 -4
  50. package/dist/types/tools/irc.d.ts +6 -0
  51. package/dist/types/tools/json-tree.d.ts +23 -4
  52. package/dist/types/tools/lsp.d.ts +2 -0
  53. package/dist/types/tools/mcp.d.ts +6 -5
  54. package/dist/types/tools/native-view.d.ts +1 -1
  55. package/dist/types/tools/renderer.d.ts +2 -0
  56. package/dist/types/tools/streaming-output.d.ts +11 -0
  57. package/dist/types/tools/task.d.ts +9 -1
  58. package/dist/types/tools/url-scheme-host.d.ts +17 -0
  59. package/dist/types/tools/yield.d.ts +1 -1
  60. package/dist/types/tui.d.ts +7 -2
  61. package/package.json +10 -14
  62. package/src/app-keybindings.d.ts +15 -0
  63. package/src/app-keybindings.ts +15 -0
  64. package/src/apps/session-picker.ts +7 -0
  65. package/src/charts/chart-plan.d.ts +9 -7
  66. package/src/charts/chart-plan.ts +20 -50
  67. package/src/chat/advisor-message.ts +2 -0
  68. package/src/chat/assistant-message.d.ts +15 -3
  69. package/src/chat/assistant-message.ts +137 -19
  70. package/src/chat/background-tan-message.ts +4 -0
  71. package/src/chat/bash-execution.d.ts +2 -0
  72. package/src/chat/bash-execution.ts +6 -0
  73. package/src/chat/chat-transcript-builder.ts +58 -28
  74. package/src/chat/compaction-summary-message.ts +2 -1
  75. package/src/chat/display-preferences.d.ts +2 -0
  76. package/src/chat/display-preferences.ts +3 -0
  77. package/src/chat/extension-types.d.ts +31 -0
  78. package/src/chat/extension-types.ts +34 -0
  79. package/src/chat/reply-write.d.ts +48 -0
  80. package/src/chat/reply-write.ts +127 -0
  81. package/src/chat/table-chart.d.ts +4 -3
  82. package/src/chat/table-chart.ts +10 -4
  83. package/src/chat/tool-execution.d.ts +1 -2
  84. package/src/chat/tool-execution.ts +20 -13
  85. package/src/chat/transcript-outline.d.ts +7 -0
  86. package/src/chat/transcript-outline.ts +27 -0
  87. package/src/chat/transcript-render-helpers.d.ts +2 -0
  88. package/src/chat/transcript-render-helpers.ts +66 -24
  89. package/src/chrome/index.ts +1 -0
  90. package/src/chrome/transcript-notice.d.ts +35 -0
  91. package/src/chrome/transcript-notice.ts +83 -0
  92. package/src/chrome/transcript-status.d.ts +20 -8
  93. package/src/chrome/transcript-status.ts +29 -29
  94. package/src/components/editor.d.ts +8 -0
  95. package/src/components/editor.ts +10 -1
  96. package/src/components/markdown.d.ts +7 -0
  97. package/src/components/markdown.ts +116 -6
  98. package/src/hotkeys-markdown.ts +1 -0
  99. package/src/native/backend.ts +5 -66
  100. package/src/native/blobs.d.ts +2 -1
  101. package/src/native/blobs.ts +3 -2
  102. package/src/native/picker.d.ts +4 -4
  103. package/src/native/picker.ts +4 -4
  104. package/src/overlays/advisor-config.ts +1 -10
  105. package/src/overlays/annotation-overlay.ts +125 -37
  106. package/src/overlays/annotation-types.ts +24 -0
  107. package/src/overlays/hook-selector.ts +2 -2
  108. package/src/overlays/login-dialog.ts +31 -5
  109. package/src/overlays/mcp-add-wizard.ts +1 -1
  110. package/src/overlays/model-browser.ts +37 -0
  111. package/src/overlays/model-hub.ts +1 -7
  112. package/src/overlays/model-picker.ts +1 -10
  113. package/src/overlays/oauth-selector.ts +44 -6
  114. package/src/overlays/plan-review-overlay.ts +13 -2
  115. package/src/overlays/rewind-selector.ts +29 -12
  116. package/src/overlays/session-selector.ts +313 -42
  117. package/src/overlays/usage-dashboard.ts +5 -12
  118. package/src/prompt/composer.ts +216 -1
  119. package/src/prompt/custom-editor.ts +6 -1
  120. package/src/prompt/emoji-autocomplete.ts +0 -2
  121. package/src/prompt/interactive-context-helpers.ts +29 -4
  122. package/src/render/extension-links.d.ts +65 -0
  123. package/src/render/extension-links.ts +214 -0
  124. package/src/render/hyperlink.d.ts +25 -7
  125. package/src/render/hyperlink.ts +65 -9
  126. package/src/render/index.d.ts +1 -0
  127. package/src/render/index.ts +1 -0
  128. package/src/setup/scenes/composer.ts +2 -0
  129. package/src/setup/scenes/glyph.ts +3 -1
  130. package/src/setup/scenes/model.ts +192 -29
  131. package/src/setup/scenes/outro.ts +33 -15
  132. package/src/setup/scenes/sign-in.ts +196 -400
  133. package/src/setup/scenes/theme.ts +2 -0
  134. package/src/setup/scenes/types.ts +18 -1
  135. package/src/setup/startup-splash.ts +8 -7
  136. package/src/setup/wizard-overlay.ts +164 -35
  137. package/src/setup/wizard.ts +11 -2
  138. package/src/status-line/component.ts +4 -10
  139. package/src/status-line/context-usage.ts +72 -21
  140. package/src/status-line/host.ts +6 -2
  141. package/src/terminal.ts +24 -2
  142. package/src/theme/defaults.json +1 -0
  143. package/src/theme/loader.ts +1 -1
  144. package/src/theme/theme.d.ts +0 -23
  145. package/src/theme/theme.ts +2 -75
  146. package/src/tools/bash-interactive.d.ts +49 -0
  147. package/src/tools/bash-interactive.ts +6 -1
  148. package/src/tools/bash.d.ts +2 -0
  149. package/src/tools/bash.ts +2 -0
  150. package/src/tools/default-renderer.d.ts +6 -4
  151. package/src/tools/default-renderer.ts +9 -6
  152. package/src/tools/eval.ts +14 -4
  153. package/src/tools/irc.d.ts +6 -0
  154. package/src/tools/irc.ts +6 -0
  155. package/src/tools/job-widget.ts +13 -1
  156. package/src/tools/json-tree.d.ts +23 -4
  157. package/src/tools/json-tree.ts +132 -42
  158. package/src/tools/lsp.d.ts +2 -0
  159. package/src/tools/lsp.ts +36 -15
  160. package/src/tools/mcp.d.ts +6 -5
  161. package/src/tools/mcp.ts +20 -12
  162. package/src/tools/native-view.d.ts +1 -1
  163. package/src/tools/native-view.ts +1 -1
  164. package/src/tools/renderer.d.ts +2 -0
  165. package/src/tools/renderer.ts +2 -0
  166. package/src/tools/streaming-output.d.ts +11 -0
  167. package/src/tools/streaming-output.ts +41 -0
  168. package/src/tools/task.d.ts +9 -1
  169. package/src/tools/task.ts +59 -16
  170. package/src/tools/url-scheme-host.d.ts +17 -0
  171. package/src/tools/url-scheme-host.ts +21 -0
  172. package/src/tools/yield.d.ts +1 -1
  173. package/src/tools/yield.ts +18 -9
  174. package/src/tui.d.ts +7 -2
  175. package/src/tui.ts +43 -15
  176. package/dist/types/theme/defaults/index.d.ts +0 -10289
  177. package/src/theme/defaults/alabaster.json +0 -103
  178. package/src/theme/defaults/amethyst.json +0 -106
  179. package/src/theme/defaults/anthracite.json +0 -103
  180. package/src/theme/defaults/basalt.json +0 -101
  181. package/src/theme/defaults/birch.json +0 -105
  182. package/src/theme/defaults/dark-abyss.json +0 -101
  183. package/src/theme/defaults/dark-arctic.json +0 -114
  184. package/src/theme/defaults/dark-aurora.json +0 -105
  185. package/src/theme/defaults/dark-catppuccin.json +0 -117
  186. package/src/theme/defaults/dark-cavern.json +0 -101
  187. package/src/theme/defaults/dark-celestial.json +0 -116
  188. package/src/theme/defaults/dark-copper.json +0 -105
  189. package/src/theme/defaults/dark-cosmos.json +0 -100
  190. package/src/theme/defaults/dark-cyberpunk.json +0 -112
  191. package/src/theme/defaults/dark-dracula.json +0 -108
  192. package/src/theme/defaults/dark-eclipse.json +0 -101
  193. package/src/theme/defaults/dark-ember.json +0 -105
  194. package/src/theme/defaults/dark-equinox.json +0 -100
  195. package/src/theme/defaults/dark-forest.json +0 -106
  196. package/src/theme/defaults/dark-github.json +0 -115
  197. package/src/theme/defaults/dark-gruvbox.json +0 -122
  198. package/src/theme/defaults/dark-lavender.json +0 -105
  199. package/src/theme/defaults/dark-lunar.json +0 -99
  200. package/src/theme/defaults/dark-midnight.json +0 -105
  201. package/src/theme/defaults/dark-monochrome.json +0 -104
  202. package/src/theme/defaults/dark-monokai.json +0 -108
  203. package/src/theme/defaults/dark-nebula.json +0 -100
  204. package/src/theme/defaults/dark-neon-noir.json +0 -110
  205. package/src/theme/defaults/dark-nord.json +0 -108
  206. package/src/theme/defaults/dark-ocean.json +0 -111
  207. package/src/theme/defaults/dark-one.json +0 -110
  208. package/src/theme/defaults/dark-poimandres.json +0 -125
  209. package/src/theme/defaults/dark-rainforest.json +0 -101
  210. package/src/theme/defaults/dark-reef.json +0 -101
  211. package/src/theme/defaults/dark-retro.json +0 -102
  212. package/src/theme/defaults/dark-rose-pine.json +0 -106
  213. package/src/theme/defaults/dark-sakura.json +0 -105
  214. package/src/theme/defaults/dark-slate.json +0 -105
  215. package/src/theme/defaults/dark-solarized.json +0 -107
  216. package/src/theme/defaults/dark-solstice.json +0 -100
  217. package/src/theme/defaults/dark-starfall.json +0 -101
  218. package/src/theme/defaults/dark-sunset.json +0 -109
  219. package/src/theme/defaults/dark-swamp.json +0 -100
  220. package/src/theme/defaults/dark-synthwave.json +0 -113
  221. package/src/theme/defaults/dark-taiga.json +0 -101
  222. package/src/theme/defaults/dark-terminal.json +0 -105
  223. package/src/theme/defaults/dark-tokyo-night.json +0 -111
  224. package/src/theme/defaults/dark-tundra.json +0 -101
  225. package/src/theme/defaults/dark-twilight.json +0 -101
  226. package/src/theme/defaults/dark-volcanic.json +0 -101
  227. package/src/theme/defaults/graphite.json +0 -102
  228. package/src/theme/defaults/index.d.ts +0 -10289
  229. package/src/theme/defaults/index.ts +0 -203
  230. package/src/theme/defaults/light-arctic.json +0 -117
  231. package/src/theme/defaults/light-aurora-day.json +0 -101
  232. package/src/theme/defaults/light-canyon.json +0 -101
  233. package/src/theme/defaults/light-catppuccin.json +0 -116
  234. package/src/theme/defaults/light-cirrus.json +0 -100
  235. package/src/theme/defaults/light-coral.json +0 -105
  236. package/src/theme/defaults/light-cyberpunk.json +0 -106
  237. package/src/theme/defaults/light-dawn.json +0 -100
  238. package/src/theme/defaults/light-dunes.json +0 -101
  239. package/src/theme/defaults/light-eucalyptus.json +0 -105
  240. package/src/theme/defaults/light-forest.json +0 -110
  241. package/src/theme/defaults/light-frost.json +0 -105
  242. package/src/theme/defaults/light-github.json +0 -125
  243. package/src/theme/defaults/light-glacier.json +0 -101
  244. package/src/theme/defaults/light-gruvbox.json +0 -118
  245. package/src/theme/defaults/light-haze.json +0 -100
  246. package/src/theme/defaults/light-honeycomb.json +0 -105
  247. package/src/theme/defaults/light-lagoon.json +0 -101
  248. package/src/theme/defaults/light-lavender.json +0 -105
  249. package/src/theme/defaults/light-meadow.json +0 -101
  250. package/src/theme/defaults/light-mint.json +0 -105
  251. package/src/theme/defaults/light-monochrome.json +0 -111
  252. package/src/theme/defaults/light-ocean.json +0 -109
  253. package/src/theme/defaults/light-one.json +0 -109
  254. package/src/theme/defaults/light-opal.json +0 -101
  255. package/src/theme/defaults/light-orchard.json +0 -101
  256. package/src/theme/defaults/light-paper.json +0 -105
  257. package/src/theme/defaults/light-poimandres.json +0 -125
  258. package/src/theme/defaults/light-prism.json +0 -100
  259. package/src/theme/defaults/light-retro.json +0 -108
  260. package/src/theme/defaults/light-sand.json +0 -105
  261. package/src/theme/defaults/light-savanna.json +0 -101
  262. package/src/theme/defaults/light-solarized.json +0 -112
  263. package/src/theme/defaults/light-soleil.json +0 -100
  264. package/src/theme/defaults/light-sunset.json +0 -109
  265. package/src/theme/defaults/light-synthwave.json +0 -108
  266. package/src/theme/defaults/light-tokyo-night.json +0 -121
  267. package/src/theme/defaults/light-wetland.json +0 -101
  268. package/src/theme/defaults/light-zenith.json +0 -99
  269. package/src/theme/defaults/limestone.json +0 -104
  270. package/src/theme/defaults/mahogany.json +0 -107
  271. package/src/theme/defaults/marble.json +0 -103
  272. package/src/theme/defaults/obsidian.json +0 -101
  273. package/src/theme/defaults/onyx.json +0 -101
  274. package/src/theme/defaults/pearl.json +0 -103
  275. package/src/theme/defaults/porcelain.json +0 -101
  276. package/src/theme/defaults/quartz.json +0 -106
  277. package/src/theme/defaults/sandstone.json +0 -105
  278. 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
  };