acryl 0.1.15 → 0.1.17

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.
package/lib/index.js CHANGED
@@ -6,9 +6,9 @@ import { existsSync, writeFileSync } from "node:fs";
6
6
  import { dirname, join, relative, resolve } from "node:path";
7
7
  import { fileURLToPath } from "node:url";
8
8
  import { DEFAULT_PROFILE_BUNDLES, boot, composeEntries, healProfilesModuleFallback, initProfile, loadProfile, resolveProfileDir } from "@deepseek-ai/dsh-app-boot";
9
+ import { execFile, spawn } from "node:child_process";
9
10
  import { diffLines } from "diff";
10
11
  import { Container, Editor, HStack, Key, KeybindingsManager, ProcessTerminal, ScrollView, TUI_KEYBINDINGS, Text, TuiAltScreen, VStack, matchesKey, setKeybindings, visibleWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
11
- import { spawn } from "node:child_process";
12
12
  import { readdir } from "node:fs/promises";
13
13
  import { ManualCompactionError } from "@deepseek-ai/dsh-compaction";
14
14
  import { GoalError } from "@deepseek-ai/dsh-goal";
@@ -296,22 +296,29 @@ const ACRYL_RUNTIME_ROWS = [{
296
296
  id: "system-prompt",
297
297
  name: "@deepseek-ai/dsh-system-prompt",
298
298
  config: { persona: "You are a coding agent powered by the {{model}} model. Your working directory is {{cwd}}." }
299
- }, { insert: [{
300
- id: "agent-presets",
301
- name: "@deepseek-ai/dsh-agent-presets",
302
- config: {
303
- default: "standard",
304
- roots: existsSync(shippedPresetsDir) ? [{
305
- path: shippedPresetsDir,
306
- trust: "system"
307
- }] : [],
308
- includeShippedRoot: false,
309
- includeUserRoot: true
299
+ }, { insert: [
300
+ {
301
+ id: "agent-presets",
302
+ name: "@deepseek-ai/dsh-agent-presets",
303
+ config: {
304
+ default: "standard",
305
+ roots: existsSync(shippedPresetsDir) ? [{
306
+ path: shippedPresetsDir,
307
+ trust: "system"
308
+ }] : [],
309
+ includeShippedRoot: false,
310
+ includeUserRoot: true
311
+ }
312
+ },
313
+ {
314
+ id: "session-stats",
315
+ name: "@deepseek-ai/dsh-session-stats"
316
+ },
317
+ {
318
+ id: "authorization",
319
+ name: "@deepseek-ai/dsh-authorization"
310
320
  }
311
- }, {
312
- id: "session-stats",
313
- name: "@deepseek-ai/dsh-session-stats"
314
- }] }];
321
+ ] }];
315
322
  /** Boot one normal pinned-Harness ACRYL profile in a single Cordis root. */
316
323
  async function bootAcrylHarnessProfile(options) {
317
324
  if (options.profile.trim() === "") throw new Error("ACRYL Harness profile must not be empty");
@@ -420,7 +427,7 @@ const ESC = "\x1B[";
420
427
  const dim$2 = fg(theme.muted);
421
428
  const cyan$1 = fg(theme.secondary);
422
429
  const primary = fg(theme.primary);
423
- const bold$10 = (s) => `${ESC}1m${s}${ESC}0m`;
430
+ const bold$11 = (s) => `${ESC}1m${s}${ESC}0m`;
424
431
  const italic = (s) => `${ESC}3m${s}${ESC}0m`;
425
432
  const strike = (s) => `${ESC}9m${s}${ESC}0m`;
426
433
  const underline = (s) => `${ESC}4m${s}${ESC}0m`;
@@ -464,7 +471,7 @@ function looksLikeMarkdown(text) {
464
471
  /** Style links, bold, strikethrough, and emphasis in a span already known to contain no inline code. */
465
472
  function applyNonCodeInline(text) {
466
473
  let working = text.replaceAll(LINK_RE_G, (_match, label, url) => hyperlink(url, underline(primary(label))));
467
- working = working.replaceAll(BOLD_RE_G, (_match, a, b) => bold$10(a ?? b ?? ""));
474
+ working = working.replaceAll(BOLD_RE_G, (_match, a, b) => bold$11(a ?? b ?? ""));
468
475
  working = working.replaceAll(STRIKE_RE_G, (_match, t) => strike(t));
469
476
  return working.replaceAll(ITALIC_RE_G, (_match, a, b) => italic(a ?? b ?? ""));
470
477
  }
@@ -530,7 +537,7 @@ function padCell(styled, width, align) {
530
537
  }
531
538
  /** Pad one row of already-styled cells (header or body) to a single column-aligned line. */
532
539
  function formatTableRow(styledCells, widths, aligns, isHeader) {
533
- return widths.map((width, i) => padCell(isHeader ? bold$10(styledCells[i] ?? "") : styledCells[i] ?? "", width, aligns[i] ?? "left")).join(dim$2(" │ "));
540
+ return widths.map((width, i) => padCell(isHeader ? bold$11(styledCells[i] ?? "") : styledCells[i] ?? "", width, aligns[i] ?? "left")).join(dim$2(" │ "));
534
541
  }
535
542
  /** A dim horizontal rule under the header row, with a cross at each column boundary. */
536
543
  function formatTableRule(widths) {
@@ -587,7 +594,7 @@ function renderMarkdown(text) {
587
594
  if (header !== null) {
588
595
  const level = header[1].length;
589
596
  const content = applyInline(header[2]);
590
- out.push(level === 1 ? bold$10(primary(content)) : level === 2 ? bold$10(cyan$1(content)) : bold$10(content));
597
+ out.push(level === 1 ? bold$11(primary(content)) : level === 2 ? bold$11(cyan$1(content)) : bold$11(content));
591
598
  continue;
592
599
  }
593
600
  if (HR_RE.test(line)) {
@@ -1212,6 +1219,31 @@ var TuiStore = class {
1212
1219
  }
1213
1220
  } });
1214
1221
  }
1222
+ /** Open the `/login` sign-in overlay to a fresh, loading flow list. */
1223
+ openLogin() {
1224
+ this.set({ overlay: {
1225
+ kind: "login",
1226
+ login: {
1227
+ flows: void 0,
1228
+ selected: 0,
1229
+ signingIn: void 0,
1230
+ prompt: void 0,
1231
+ busy: true,
1232
+ error: void 0
1233
+ }
1234
+ } });
1235
+ }
1236
+ /** Patch the open `/login` overlay's sub-state; a no-op once it's closed. */
1237
+ updateLogin(patch) {
1238
+ if (this.state.overlay.kind !== "login") return;
1239
+ this.set({ overlay: {
1240
+ kind: "login",
1241
+ login: {
1242
+ ...this.state.overlay.login,
1243
+ ...patch
1244
+ }
1245
+ } });
1246
+ }
1215
1247
  /** Open the `/trajectory` ledger overlay. */
1216
1248
  openTrajectory() {
1217
1249
  this.set({ overlay: { kind: "trajectory" } });
@@ -1763,10 +1795,10 @@ function runSlashCommand(command, actions) {
1763
1795
  }
1764
1796
  //#endregion
1765
1797
  //#region src/tui/piTheme.ts
1766
- const bold$9 = (s) => `\x1b[1m${s}\x1b[0m`;
1798
+ const bold$10 = (s) => `\x1b[1m${s}\x1b[0m`;
1767
1799
  const selectListTheme = {
1768
1800
  selectedPrefix: fg(theme.primary),
1769
- selectedText: (s) => bold$9(fg(theme.primary)(s)),
1801
+ selectedText: (s) => bold$10(fg(theme.primary)(s)),
1770
1802
  description: fg(theme.muted),
1771
1803
  scrollInfo: fg(theme.muted),
1772
1804
  noMatch: fg(theme.muted)
@@ -2091,6 +2123,68 @@ var Spinner = class {
2091
2123
  }
2092
2124
  };
2093
2125
  //#endregion
2126
+ //#region src/tui/clipboard.ts
2127
+ /**
2128
+ * System-clipboard read, used for right-click paste. Node has no built-in
2129
+ * clipboard API, so this shells out to the platform's clipboard tool via
2130
+ * `execFile` (the same `node:child_process` approach used elsewhere for
2131
+ * platform launchers like `open`/`xdg-open`).
2132
+ * @module @tomowang/dsh-tui/tui/clipboard
2133
+ */
2134
+ function clipboardCommands() {
2135
+ switch (process.platform) {
2136
+ case "darwin": return [["pbpaste", []]];
2137
+ case "win32": return [["powershell.exe", [
2138
+ "-NoProfile",
2139
+ "-NonInteractive",
2140
+ "-Command",
2141
+ "Get-Clipboard"
2142
+ ]]];
2143
+ default: return [
2144
+ ["xclip", [
2145
+ "-selection",
2146
+ "clipboard",
2147
+ "-o"
2148
+ ]],
2149
+ ["xsel", ["--clipboard", "--output"]],
2150
+ ["wl-paste", ["--no-newline"]]
2151
+ ];
2152
+ }
2153
+ }
2154
+ /**
2155
+ * Read the system clipboard. Resolves with the clipboard text (possibly empty).
2156
+ * Rejects when no supported clipboard tool is available on this host.
2157
+ *
2158
+ * A single trailing newline is stripped: `pbpaste` prints the clipboard verbatim,
2159
+ * while `xclip`/`xsel`/`Get-Clipboard` append one, so this keeps the result
2160
+ * consistent with a native terminal paste (which inserts exactly what was copied).
2161
+ */
2162
+ function readClipboard() {
2163
+ return new Promise((resolve, reject) => {
2164
+ const commands = clipboardCommands();
2165
+ let index = 0;
2166
+ const attempt = () => {
2167
+ if (index >= commands.length) {
2168
+ reject(/* @__PURE__ */ new Error("no clipboard tool available"));
2169
+ return;
2170
+ }
2171
+ const [command, args] = commands[index];
2172
+ index += 1;
2173
+ execFile(command, args, {
2174
+ encoding: "utf8",
2175
+ maxBuffer: 10 * 1024 * 1024
2176
+ }, (error, stdout) => {
2177
+ if (error) {
2178
+ attempt();
2179
+ return;
2180
+ }
2181
+ resolve(stdout.replace(/\r?\n$/, ""));
2182
+ });
2183
+ };
2184
+ attempt();
2185
+ });
2186
+ }
2187
+ //#endregion
2094
2188
  //#region src/yly/yly-frames.generated.ts
2095
2189
  const YLY_FRAMES = {
2096
2190
  "small": [
@@ -3010,6 +3104,15 @@ var YlyPet = class {
3010
3104
  * delegate keystrokes to a field nested inside a larger custom overlay.
3011
3105
  * @module @tomowang/dsh-tui/tui/miniTextField
3012
3106
  */
3107
+ const BRACKETED_PASTE_START = "\x1B[200~";
3108
+ const BRACKETED_PASTE_END = "\x1B[201~";
3109
+ /** Extract the content of one bracketed-paste sequence, or `undefined` if `data` is not one. */
3110
+ function extractBracketedPaste(data) {
3111
+ if (!data.startsWith(BRACKETED_PASTE_START)) return void 0;
3112
+ const end = data.indexOf(BRACKETED_PASTE_END);
3113
+ if (end === -1) return void 0;
3114
+ return data.slice(6, end);
3115
+ }
3013
3116
  function emptyMiniTextField(value = "") {
3014
3117
  return {
3015
3118
  value,
@@ -3048,6 +3151,15 @@ function miniTextFieldInput(state, data) {
3048
3151
  cursor: state.cursor
3049
3152
  };
3050
3153
  }
3154
+ const paste = extractBracketedPaste(data);
3155
+ if (paste !== void 0) {
3156
+ const text = paste.replace(/[\r\n]+/g, "");
3157
+ if (text.length === 0) return state;
3158
+ return {
3159
+ value: state.value.slice(0, state.cursor) + text + state.value.slice(state.cursor),
3160
+ cursor: state.cursor + text.length
3161
+ };
3162
+ }
3051
3163
  if (data.length > 0 && !data.startsWith("\x1B") && data !== "\r" && data !== "\n" && data !== " ") return {
3052
3164
  value: state.value.slice(0, state.cursor) + data + state.value.slice(state.cursor),
3053
3165
  cursor: state.cursor + data.length
@@ -3061,11 +3173,11 @@ function renderMiniTextField(state, cursorVisible, mask) {
3061
3173
  }
3062
3174
  //#endregion
3063
3175
  //#region src/tui/modelProfile/ModelProfileOverlay.ts
3064
- const bold$8 = (s) => `\x1b[1m${s}\x1b[0m`;
3065
- const secondary$8 = fg(theme.secondary);
3066
- const muted$9 = fg(theme.muted);
3067
- const errorColor$4 = fg(theme.error);
3068
- const invert$4 = (s) => `\x1b[7m${s}\x1b[0m`;
3176
+ const bold$9 = (s) => `\x1b[1m${s}\x1b[0m`;
3177
+ const secondary$9 = fg(theme.secondary);
3178
+ const muted$10 = fg(theme.muted);
3179
+ const errorColor$5 = fg(theme.error);
3180
+ const invert$5 = (s) => `\x1b[7m${s}\x1b[0m`;
3069
3181
  var ModelProfileOverlay = class {
3070
3182
  store;
3071
3183
  actions;
@@ -3142,19 +3254,19 @@ var ModelProfileOverlay = class {
3142
3254
  }
3143
3255
  renderList(mp) {
3144
3256
  const { providers, selected, busy, error } = mp;
3145
- const lines = [bold$8(secondary$8("Model providers"))];
3146
- if (error !== void 0) lines.push(errorColor$4(error));
3147
- if (busy && providers === void 0) lines.push(muted$9("Loading…"));
3257
+ const lines = [bold$9(secondary$9("Model providers"))];
3258
+ if (error !== void 0) lines.push(errorColor$5(error));
3259
+ if (busy && providers === void 0) lines.push(muted$10("Loading…"));
3148
3260
  providers?.forEach((row, index) => {
3149
3261
  const marker = row.configured ? "● " : "○ ";
3150
3262
  const active = row.live ? " (active)" : "";
3151
3263
  const noKey = row.apiKeyConfigured ? "" : " [no api key]";
3152
3264
  const confirm = this.confirmDelete === index ? " — press d again to delete" : "";
3153
3265
  const text = `${index === selected ? "› " : " "}${marker}${row.displayName}${active}${noKey}${confirm}`;
3154
- lines.push(index === selected ? invert$4(text) : text);
3266
+ lines.push(index === selected ? invert$5(text) : text);
3155
3267
  });
3156
- if (providers?.length === 0) lines.push(muted$9("No providers configured yet — press a to add one."));
3157
- lines.push(muted$9("↑↓ select · enter edit · a add · d delete · s set active model · esc close"));
3268
+ if (providers?.length === 0) lines.push(muted$10("No providers configured yet — press a to add one."));
3269
+ lines.push(muted$10("↑↓ select · enter edit · a add · d delete · s set active model · esc close"));
3158
3270
  return lines;
3159
3271
  }
3160
3272
  handleListInput(data, mp) {
@@ -3218,8 +3330,8 @@ var ModelProfileOverlay = class {
3218
3330
  baseURL: "Base URL",
3219
3331
  apiKey: draft.apiKeyConfigured ? "API key (set — leave blank to keep)" : "API key"
3220
3332
  };
3221
- const lines = [bold$8(secondary$8(draft.isNew ? "Add provider" : `Edit ${draft.displayName || draft.route}`))];
3222
- if (mp.error !== void 0) lines.push(errorColor$4(mp.error));
3333
+ const lines = [bold$9(secondary$9(draft.isNew ? "Add provider" : `Edit ${draft.displayName || draft.route}`))];
3334
+ if (mp.error !== void 0) lines.push(errorColor$5(mp.error));
3223
3335
  textFields.forEach((field, index) => {
3224
3336
  const isFocused = this.focused === index;
3225
3337
  const mask = field === "apiKey" ? "*" : void 0;
@@ -3227,10 +3339,10 @@ var ModelProfileOverlay = class {
3227
3339
  lines.push(`${prefix}${renderMiniTextField(fieldState[field], isFocused, mask)}`);
3228
3340
  });
3229
3341
  const modelsText = `${this.focused === modelsRow ? "› " : " "}Models (${this.models.length}) — enter to edit`;
3230
- lines.push(this.focused === modelsRow ? invert$4(modelsText) : modelsText);
3342
+ lines.push(this.focused === modelsRow ? invert$5(modelsText) : modelsText);
3231
3343
  const saveText = `${this.focused === saveRow ? "› " : " "}${mp.busy ? "Saving…" : "Save"}`;
3232
- lines.push(this.focused === saveRow ? invert$4(saveText) : saveText);
3233
- lines.push(muted$9("tab/shift+tab move · enter confirm field / activate row · esc cancel"));
3344
+ lines.push(this.focused === saveRow ? invert$5(saveText) : saveText);
3345
+ lines.push(muted$10("tab/shift+tab move · enter confirm field / activate row · esc cancel"));
3234
3346
  return lines;
3235
3347
  }
3236
3348
  handleFormInput(data, draft) {
@@ -3280,21 +3392,21 @@ var ModelProfileOverlay = class {
3280
3392
  }
3281
3393
  }
3282
3394
  renderModelListEditor(mp) {
3283
- const lines = [bold$8(secondary$8("Models"))];
3395
+ const lines = [bold$9(secondary$9("Models"))];
3284
3396
  this.models.forEach((model, index) => {
3285
3397
  const isSelected = !this.modelInputFocused && index === this.modelSelected;
3286
3398
  const text = `${isSelected ? "› " : " "}${model.id}${model.name === void 0 ? "" : ` — ${model.name}`}`;
3287
- lines.push(isSelected ? invert$4(text) : text);
3399
+ lines.push(isSelected ? invert$5(text) : text);
3288
3400
  });
3289
- if (this.models.length === 0) lines.push(muted$9("No models yet."));
3401
+ if (this.models.length === 0) lines.push(muted$10("No models yet."));
3290
3402
  lines.push(`${this.modelInputFocused ? "› " : " "}Add id: ${renderMiniTextField(this.modelDraftId, this.modelInputFocused)}`);
3291
- if (mp.busy) lines.push(muted$9("Discovering…"));
3292
- if (mp.discovered !== void 0) if (mp.discovered.length === 0) lines.push(muted$9("No models discovered."));
3403
+ if (mp.busy) lines.push(muted$10("Discovering…"));
3404
+ if (mp.discovered !== void 0) if (mp.discovered.length === 0) lines.push(muted$10("No models discovered."));
3293
3405
  else {
3294
- lines.push(muted$9("Discovered — tab to the id field and type one to adopt it:"));
3295
- for (const model of mp.discovered) lines.push(muted$9(` ${model.id}${model.name === void 0 ? "" : ` — ${model.name}`}`));
3406
+ lines.push(muted$10("Discovered — tab to the id field and type one to adopt it:"));
3407
+ for (const model of mp.discovered) lines.push(muted$10(` ${model.id}${model.name === void 0 ? "" : ` — ${model.name}`}`));
3296
3408
  }
3297
- lines.push(muted$9("tab toggle list/input · ↑↓ select · x remove · g discover · esc back"));
3409
+ lines.push(muted$10("tab toggle list/input · ↑↓ select · x remove · g discover · esc back"));
3298
3410
  return lines;
3299
3411
  }
3300
3412
  addModel(id) {
@@ -3355,6 +3467,111 @@ var ModelProfileOverlay = class {
3355
3467
  }
3356
3468
  };
3357
3469
  //#endregion
3470
+ //#region src/tui/login/LoginOverlay.ts
3471
+ const bold$8 = (s) => `\x1b[1m${s}\x1b[0m`;
3472
+ const secondary$8 = fg(theme.secondary);
3473
+ const muted$9 = fg(theme.muted);
3474
+ const errorColor$4 = fg(theme.error);
3475
+ const invert$4 = (s) => `\x1b[7m${s}\x1b[0m`;
3476
+ var LoginOverlay = class {
3477
+ store;
3478
+ actions;
3479
+ promptField = emptyMiniTextField();
3480
+ promptCursor = 0;
3481
+ constructor(store, actions) {
3482
+ this.store = store;
3483
+ this.actions = actions;
3484
+ }
3485
+ invalidate() {}
3486
+ renderList(login) {
3487
+ const lines = [bold$8(secondary$8("Sign in"))];
3488
+ if (login.error !== void 0) lines.push(errorColor$4(login.error));
3489
+ if (login.busy && login.flows === void 0) lines.push(muted$9("Loading…"));
3490
+ login.flows?.forEach((flow, index) => {
3491
+ const marker = flow.inFlight ? "· " : "○ ";
3492
+ const signingIn = login.signingIn === flow.key ? " — signing in…" : "";
3493
+ const text = `${index === login.selected ? "› " : " "}${marker}${flow.label}${signingIn}`;
3494
+ lines.push(index === login.selected ? invert$4(text) : text);
3495
+ });
3496
+ if (login.flows?.length === 0) lines.push(muted$9("No sign-in providers are available in this profile."));
3497
+ lines.push(muted$9("↑↓ select · enter sign in · esc close"));
3498
+ return lines;
3499
+ }
3500
+ renderPrompt(prompt) {
3501
+ const lines = [bold$8(secondary$8("Sign in"))];
3502
+ lines.push(prompt.message);
3503
+ if (prompt.kind === "select") {
3504
+ prompt.options.forEach((option, index) => {
3505
+ const row = `${index === this.promptCursor ? "› " : " "}${option.label}`;
3506
+ lines.push(index === this.promptCursor ? invert$4(row) : row);
3507
+ if (option.description !== void 0) lines.push(muted$9(` ${option.description}`));
3508
+ });
3509
+ lines.push(muted$9("↑↓ choose · enter select · esc cancel"));
3510
+ } else {
3511
+ const mask = prompt.kind === "secret" ? "•" : void 0;
3512
+ const placeholder = prompt.placeholder ?? (prompt.kind === "secret" ? "API key" : "code");
3513
+ const field = this.promptField.value === "" ? `(${placeholder})` : renderMiniTextField(this.promptField, true, mask);
3514
+ lines.push(`> ${field}`);
3515
+ lines.push(muted$9("type + enter submit · esc cancel"));
3516
+ }
3517
+ return lines;
3518
+ }
3519
+ render(_width) {
3520
+ const overlay = this.store.getSnapshot().overlay;
3521
+ if (overlay.kind !== "login") return [];
3522
+ const { prompt } = overlay.login;
3523
+ return prompt === void 0 ? this.renderList(overlay.login) : this.renderPrompt(prompt);
3524
+ }
3525
+ handleInput(data) {
3526
+ const overlay = this.store.getSnapshot().overlay;
3527
+ if (overlay.kind !== "login") return;
3528
+ const { prompt } = overlay.login;
3529
+ if (prompt !== void 0) this.handlePromptInput(data, prompt);
3530
+ else this.handleListInput(data, overlay.login);
3531
+ }
3532
+ handlePromptInput(data, prompt) {
3533
+ if (matchesKey(data, Key.escape)) {
3534
+ this.actions.answerAuthorizationPrompt("");
3535
+ return;
3536
+ }
3537
+ if (prompt.kind === "select") {
3538
+ if (matchesKey(data, Key.up)) {
3539
+ this.promptCursor = Math.max(0, this.promptCursor - 1);
3540
+ return;
3541
+ }
3542
+ if (matchesKey(data, Key.down)) {
3543
+ this.promptCursor = Math.min(prompt.options.length - 1, this.promptCursor + 1);
3544
+ return;
3545
+ }
3546
+ if (matchesKey(data, Key.enter)) this.actions.answerAuthorizationPrompt(prompt.options[this.promptCursor].id);
3547
+ return;
3548
+ }
3549
+ if (matchesKey(data, Key.enter)) {
3550
+ this.actions.answerAuthorizationPrompt(this.promptField.value.trim());
3551
+ return;
3552
+ }
3553
+ const next = miniTextFieldInput(this.promptField, data);
3554
+ if (next !== void 0) this.promptField = next;
3555
+ }
3556
+ handleListInput(data, login) {
3557
+ if (matchesKey(data, Key.escape)) {
3558
+ this.actions.closeLogin();
3559
+ return;
3560
+ }
3561
+ const flows = login.flows;
3562
+ if (flows === void 0 || flows.length === 0) return;
3563
+ if (matchesKey(data, Key.up)) {
3564
+ this.actions.selectLoginFlow(Math.max(0, login.selected - 1));
3565
+ return;
3566
+ }
3567
+ if (matchesKey(data, Key.down)) {
3568
+ this.actions.selectLoginFlow(Math.min(flows.length - 1, login.selected + 1));
3569
+ return;
3570
+ }
3571
+ if (matchesKey(data, Key.enter)) this.actions.beginAuthorization(flows[login.selected].key);
3572
+ }
3573
+ };
3574
+ //#endregion
3358
3575
  //#region src/tui/trajectory/layout.ts
3359
3576
  const LABEL_LIMIT = 100;
3360
3577
  function prettyJson(raw) {
@@ -4594,7 +4811,12 @@ var TuiApp = class {
4594
4811
  this.options = options;
4595
4812
  const { store, actions } = options;
4596
4813
  const terminal = new ProcessTerminal();
4597
- this.tui = new TuiAltScreen(terminal, true, void 0, { mouse: true });
4814
+ this.tui = new TuiAltScreen(terminal, true, void 0, {
4815
+ mouse: true,
4816
+ onRightClickPaste: () => {
4817
+ readClipboard().then((text) => this.tui.getFocusedComponent()?.handleInput?.(`\x1b[200~${text}\x1b[201~`)).catch(() => {});
4818
+ }
4819
+ });
4598
4820
  this.spinner = new Spinner(this.tui);
4599
4821
  this.pet = new YlyPet(this.tui);
4600
4822
  const transcriptScrollView = new ScrollView(this.documentContainer, {
@@ -4782,6 +5004,7 @@ var TuiApp = class {
4782
5004
  switch (overlay.kind) {
4783
5005
  case "none": return;
4784
5006
  case "modelProfile": return new ModelProfileOverlay(store, actions);
5007
+ case "login": return new LoginOverlay(store, actions);
4785
5008
  case "trajectory": return new TrajectoryOverlay(this.tui, store, actions, getTool);
4786
5009
  case "toolCards": return new ToolCardsOverlay(this.tui, store, actions, getTool, getToolCall);
4787
5010
  case "context": return new ContextOverlay(store, actions);
@@ -4970,6 +5193,19 @@ function deriveApiKeyRef(route) {
4970
5193
  const upper = route.toUpperCase().replace(/[^A-Z0-9]+/g, "_");
4971
5194
  return `${/^[A-Z_]/.test(upper) ? upper : `P_${upper}`}_API_KEY`;
4972
5195
  }
5196
+ /** Open a URL in the platform's default browser (fire-and-forget). */
5197
+ function openBrowser(url) {
5198
+ const platform = process.platform;
5199
+ const command = platform === "darwin" ? ["open", [url]] : platform === "win32" ? ["cmd", [
5200
+ "/c",
5201
+ "start",
5202
+ "",
5203
+ url
5204
+ ]] : ["xdg-open", [url]];
5205
+ return new Promise((resolve) => {
5206
+ execFile(command[0], command[1], () => resolve());
5207
+ });
5208
+ }
4973
5209
  /** Nest a provider settings section at its path, e.g. `['providers','deepseek']` -> `{ providers: { deepseek: section } }`. */
4974
5210
  function nestAtPath(path, section) {
4975
5211
  let patch = section;
@@ -5065,6 +5301,30 @@ async function attachSession(host, resumeId) {
5065
5301
  selected: 0
5066
5302
  });
5067
5303
  }
5304
+ async function loadAuthorizationFlows() {
5305
+ const authSvc = host.ctx.get("authorization");
5306
+ if (authSvc === void 0) {
5307
+ store.updateLogin({
5308
+ flows: [],
5309
+ busy: false,
5310
+ error: "Sign-in is not available in this profile."
5311
+ });
5312
+ return;
5313
+ }
5314
+ try {
5315
+ const list = authSvc.list();
5316
+ store.updateLogin({
5317
+ flows: list,
5318
+ busy: false,
5319
+ error: void 0
5320
+ });
5321
+ } catch (error) {
5322
+ store.updateLogin({
5323
+ busy: false,
5324
+ error: error instanceof Error ? error.message : String(error)
5325
+ });
5326
+ }
5327
+ }
5068
5328
  async function loadAgentPresets() {
5069
5329
  const presetsSvc = host.ctx.get("agentPresets");
5070
5330
  if (presetsSvc === void 0) {
@@ -5095,6 +5355,7 @@ async function attachSession(host, resumeId) {
5095
5355
  });
5096
5356
  }
5097
5357
  }
5358
+ let pendingPromptResolve;
5098
5359
  const actions = {
5099
5360
  send(text) {
5100
5361
  store.setNotice(void 0);
@@ -5213,8 +5474,83 @@ async function attachSession(host, resumeId) {
5213
5474
  loadProviders();
5214
5475
  },
5215
5476
  login() {
5216
- store.openModelProfile();
5217
- loadProviders();
5477
+ store.openLogin();
5478
+ loadAuthorizationFlows();
5479
+ },
5480
+ closeLogin() {
5481
+ store.closeOverlay();
5482
+ },
5483
+ selectLoginFlow(index) {
5484
+ store.updateLogin({ selected: index });
5485
+ },
5486
+ beginAuthorization(key) {
5487
+ (async () => {
5488
+ const authSvc = host.ctx.get("authorization");
5489
+ if (authSvc === void 0) {
5490
+ store.setNotice("Sign-in is not available in this profile.");
5491
+ return;
5492
+ }
5493
+ const overlay = store.getSnapshot().overlay;
5494
+ const flow = overlay.kind === "login" ? overlay.login.flows?.find((entry) => entry.key === key) : void 0;
5495
+ if (flow === void 0) return;
5496
+ store.updateLogin({ signingIn: key });
5497
+ const interaction = {
5498
+ notify(notice) {
5499
+ if (notice.url !== void 0) openBrowser(notice.url);
5500
+ const parts = [notice.message];
5501
+ if (notice.url !== void 0) parts.push(notice.url);
5502
+ if (notice.code !== void 0) parts.push(`Code: ${notice.code}`);
5503
+ store.setNotice(parts.join("\n"));
5504
+ },
5505
+ async prompt(prompt) {
5506
+ return await new Promise((resolve, reject) => {
5507
+ if (prompt.signal?.aborted) {
5508
+ reject(/* @__PURE__ */ new Error("authorization prompt withdrawn"));
5509
+ return;
5510
+ }
5511
+ pendingPromptResolve = resolve;
5512
+ const state = prompt.kind === "select" ? {
5513
+ kind: "select",
5514
+ message: prompt.message,
5515
+ options: (prompt.options ?? []).map((option) => ({
5516
+ id: option.id,
5517
+ label: option.label,
5518
+ description: option.description
5519
+ }))
5520
+ } : {
5521
+ kind: prompt.kind,
5522
+ message: prompt.message,
5523
+ placeholder: prompt.placeholder
5524
+ };
5525
+ store.updateLogin({ prompt: state });
5526
+ prompt.signal?.addEventListener("abort", () => {
5527
+ if (pendingPromptResolve === resolve) pendingPromptResolve = void 0;
5528
+ store.updateLogin({ prompt: void 0 });
5529
+ reject(/* @__PURE__ */ new Error("authorization prompt withdrawn"));
5530
+ }, { once: true });
5531
+ });
5532
+ }
5533
+ };
5534
+ try {
5535
+ if ((await authSvc.begin({
5536
+ key,
5537
+ interaction
5538
+ })).status === "authorized") {
5539
+ store.setNotice(`Signed in to ${flow.label}.`);
5540
+ loadAuthorizationFlows();
5541
+ } else store.setNotice("Sign-in cancelled.");
5542
+ } catch (error) {
5543
+ store.setNotice(`Sign-in failed: ${error instanceof Error ? error.message : String(error)}`);
5544
+ } finally {
5545
+ store.updateLogin({ signingIn: void 0 });
5546
+ }
5547
+ })();
5548
+ },
5549
+ answerAuthorizationPrompt(value) {
5550
+ const resolve = pendingPromptResolve;
5551
+ pendingPromptResolve = void 0;
5552
+ store.updateLogin({ prompt: void 0 });
5553
+ if (resolve !== void 0) resolve(value);
5218
5554
  },
5219
5555
  logout() {
5220
5556
  (async () => {