chivgent 1.1.4 → 1.1.5

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 (105) hide show
  1. package/README.md +4 -4
  2. package/README.zh-CN.md +4 -4
  3. package/dist/cli-options.d.ts +2 -0
  4. package/dist/cli-options.d.ts.map +1 -1
  5. package/dist/cli-options.js +4 -0
  6. package/dist/cli-options.js.map +1 -1
  7. package/dist/cli-runtime.d.ts.map +1 -1
  8. package/dist/cli-runtime.js +16 -2
  9. package/dist/cli-runtime.js.map +1 -1
  10. package/dist/cli.d.ts.map +1 -1
  11. package/dist/cli.js +33 -12
  12. package/dist/cli.js.map +1 -1
  13. package/dist/prompts.d.ts +1 -1
  14. package/dist/prompts.d.ts.map +1 -1
  15. package/dist/prompts.js +4 -1
  16. package/dist/prompts.js.map +1 -1
  17. package/dist/providers/deepseek.d.ts +1 -0
  18. package/dist/providers/deepseek.d.ts.map +1 -1
  19. package/dist/providers/deepseek.js +2 -2
  20. package/dist/providers/deepseek.js.map +1 -1
  21. package/dist/providers/interactive.d.ts +9 -3
  22. package/dist/providers/interactive.d.ts.map +1 -1
  23. package/dist/providers/interactive.js +116 -19
  24. package/dist/providers/interactive.js.map +1 -1
  25. package/dist/repl.d.ts +8 -7
  26. package/dist/repl.d.ts.map +1 -1
  27. package/dist/repl.js +142 -308
  28. package/dist/repl.js.map +1 -1
  29. package/dist/runtime/desktop-runtime.d.ts +12 -0
  30. package/dist/runtime/desktop-runtime.d.ts.map +1 -1
  31. package/dist/runtime/desktop-runtime.js +11 -4
  32. package/dist/runtime/desktop-runtime.js.map +1 -1
  33. package/dist/tools/list-files.d.ts.map +1 -1
  34. package/dist/tools/list-files.js +3 -0
  35. package/dist/tools/list-files.js.map +1 -1
  36. package/dist/tools/search-text.d.ts +6 -2
  37. package/dist/tools/search-text.d.ts.map +1 -1
  38. package/dist/tools/search-text.js +24 -8
  39. package/dist/tools/search-text.js.map +1 -1
  40. package/dist/tui/animation.d.ts +21 -0
  41. package/dist/tui/animation.d.ts.map +1 -0
  42. package/dist/tui/animation.js +97 -0
  43. package/dist/tui/animation.js.map +1 -0
  44. package/dist/tui/editor-input.d.ts +20 -38
  45. package/dist/tui/editor-input.d.ts.map +1 -1
  46. package/dist/tui/editor-input.js +136 -347
  47. package/dist/tui/editor-input.js.map +1 -1
  48. package/dist/tui/editor.d.ts +11 -24
  49. package/dist/tui/editor.d.ts.map +1 -1
  50. package/dist/tui/editor.js +79 -147
  51. package/dist/tui/editor.js.map +1 -1
  52. package/dist/tui/input.d.ts +12 -16
  53. package/dist/tui/input.d.ts.map +1 -1
  54. package/dist/tui/input.js +89 -127
  55. package/dist/tui/input.js.map +1 -1
  56. package/dist/tui/live.d.ts +4 -0
  57. package/dist/tui/live.d.ts.map +1 -1
  58. package/dist/tui/live.js +18 -8
  59. package/dist/tui/live.js.map +1 -1
  60. package/dist/tui/paint.d.ts +3 -0
  61. package/dist/tui/paint.d.ts.map +1 -1
  62. package/dist/tui/paint.js +9 -2
  63. package/dist/tui/paint.js.map +1 -1
  64. package/dist/tui/provider-picker.d.ts +9 -6
  65. package/dist/tui/provider-picker.d.ts.map +1 -1
  66. package/dist/tui/provider-picker.js +11 -9
  67. package/dist/tui/provider-picker.js.map +1 -1
  68. package/dist/tui/state.d.ts +1 -1
  69. package/dist/tui/state.d.ts.map +1 -1
  70. package/dist/tui/state.js +9 -1
  71. package/dist/tui/state.js.map +1 -1
  72. package/dist/tui/view.d.ts +34 -0
  73. package/dist/tui/view.d.ts.map +1 -1
  74. package/dist/tui/view.js +142 -57
  75. package/dist/tui/view.js.map +1 -1
  76. package/dist/tui/welcome.d.ts +4 -4
  77. package/dist/tui/welcome.d.ts.map +1 -1
  78. package/dist/tui/welcome.js +58 -25
  79. package/dist/tui/welcome.js.map +1 -1
  80. package/dist/websearch/backend.d.ts.map +1 -1
  81. package/dist/websearch/backend.js +10 -6
  82. package/dist/websearch/backend.js.map +1 -1
  83. package/dist/workspace/fs.d.ts +4 -0
  84. package/dist/workspace/fs.d.ts.map +1 -0
  85. package/dist/workspace/fs.js +6 -0
  86. package/dist/workspace/fs.js.map +1 -0
  87. package/dist/workspace/list.d.ts.map +1 -1
  88. package/dist/workspace/list.js +9 -5
  89. package/dist/workspace/list.js.map +1 -1
  90. package/dist/workspace/search.d.ts +1 -0
  91. package/dist/workspace/search.d.ts.map +1 -1
  92. package/dist/workspace/search.js +38 -6
  93. package/dist/workspace/search.js.map +1 -1
  94. package/dist/workspace/text.d.ts +1 -1
  95. package/dist/workspace/text.d.ts.map +1 -1
  96. package/dist/workspace/text.js +2 -3
  97. package/dist/workspace/text.js.map +1 -1
  98. package/dist/workspace/types.d.ts +7 -1
  99. package/dist/workspace/types.d.ts.map +1 -1
  100. package/dist/workspace/types.js.map +1 -1
  101. package/package.json +1 -1
  102. package/dist/tui/menu.d.ts +0 -26
  103. package/dist/tui/menu.d.ts.map +0 -1
  104. package/dist/tui/menu.js +0 -75
  105. package/dist/tui/menu.js.map +0 -1
package/dist/repl.js CHANGED
@@ -4,9 +4,8 @@ import { readLiveGitDiff } from "./tui/git-diff.js";
4
4
  import { displayWidth, terminalText } from "./tui/text.js";
5
5
  import { terminalColorEnabled } from "./tui/selection.js";
6
6
  import { PatchReviewController } from "./tui/review.js";
7
- import { ProviderPickerController } from "./tui/provider-picker.js";
8
- import { InputMenu } from "./tui/menu.js";
9
- import { createInterface, emitKeypressEvents } from "node:readline";
7
+ import { ProviderPickerController, providerPickerLabel } from "./tui/provider-picker.js";
8
+ import { createInterface } from "node:readline";
10
9
  import { formatTokens } from "./providers/usage.js";
11
10
  import { approvalPreview, commandReviewable } from "./tui/activity.js";
12
11
  import { fitLine } from "./tui/text.js";
@@ -94,10 +93,6 @@ export const LEGACY_COMMAND_ALIASES = [
94
93
  "session",
95
94
  "plan",
96
95
  "tools",
97
- "compose",
98
- "editor",
99
- "review",
100
- "gitdiff",
101
96
  "quit",
102
97
  "logout",
103
98
  ];
@@ -121,7 +116,6 @@ const HELP = `Commands:
121
116
  /help Show this help
122
117
  /status Show live session, model, permissions, plan state, and usage (alias: /session)
123
118
  /compact Summarise older history for the model; keeps the full transcript
124
- /plan [on|off] Toggle restricted read-only Plan Mode
125
119
  /permissions [ask-first|workspace|unrestricted|plan] Inspect or change this process's policy
126
120
  /new [title] Save this session and start a fresh session
127
121
  /resume [id] Switch to a saved session in this workspace
@@ -137,10 +131,10 @@ const HELP = `Commands:
137
131
  Anything else is sent to the model. Ctrl+C stops a running answer.
138
132
  `;
139
133
  function helpText(context) {
140
- const controls = context.inlineComposer
141
- ? `Rich TUI input: Enter sends; Ctrl+O inserts a newline; Ctrl+R searches prompt history; arrows move the cursor. Ctrl+C clears the current draft; Ctrl+D exits when it is empty.${context.permissionPolicy === undefined ? "" : " Shift+Tab cycles Plan → Auto mode → Ask for me at the idle prompt."}\n\n`
134
+ const controls = context.tui
135
+ ? `Rich TUI input: Enter sends; Ctrl+O inserts a newline; ↑/↓ cycles prompt history; arrows move the cursor. Ctrl+C clears the current draft; Ctrl+D exits when it is empty.${context.permissionPolicy === undefined ? "" : " Shift+Tab cycles Plan → Auto mode → Ask for me at the idle prompt."}\n\n`
142
136
  : "";
143
- const exit = context.inlineComposer ? "" : "At the simple prompt Ctrl+C or Ctrl+D exits.\n";
137
+ const exit = context.tui ? "" : "At the simple prompt Ctrl+C or Ctrl+D exits.\n";
144
138
  const extras = context.extensionCommands ?? [];
145
139
  if (extras.length === 0) {
146
140
  return `${controls}${HELP}${exit}`;
@@ -265,22 +259,6 @@ export function handleSlashCommand(line, context) {
265
259
  context.write(formatDiffPage(patch, page, context.width ?? 80, context.color === true).text);
266
260
  return "handled";
267
261
  }
268
- case "/compose":
269
- context.write(context.inlineComposer
270
- ? "The multiline editor is already active in this prompt. Enter sends; Ctrl+O inserts a newline.\n"
271
- : "Use /compose at the interactive prompt to enter multi-line mode.\n");
272
- return "handled";
273
- case "/editor":
274
- context.write(context.inlineComposer
275
- ? "The cursor-addressable multiline editor is already active in this prompt. Enter sends; Ctrl+O inserts a newline.\n"
276
- : "Use /editor in the rich interactive TUI to open the multiline editor.\n");
277
- return "handled";
278
- case "/review":
279
- context.write("Use /review in an interactive TUI to browse the most recent successful patch.\n");
280
- return "handled";
281
- case "/gitdiff":
282
- context.write("Use /gitdiff [--staged] in an interactive TUI to approve read-only Git diff.\n");
283
- return "handled";
284
262
  case "/clear":
285
263
  context.session.clear();
286
264
  context.write("Transcript cleared.\n");
@@ -425,13 +403,12 @@ async function withoutEcho(readline, read, echoWhile = () => false) {
425
403
  internals._writeToOutput = original;
426
404
  }
427
405
  }
428
- /** Plain-REPL Provider chooser; only the API key itself is hidden. */
429
- async function readProviderChoice(readNextLine, write, providerIds, active) {
430
- write("Select a Provider for /login:\n");
431
- providerIds.forEach((id, index) => {
432
- write(` ${index + 1}. ${id}${id === active ? " (current)" : ""}\n`);
406
+ async function readSetupChoice(readNextLine, write, ids, active, title, label) {
407
+ write(`${title}\n`);
408
+ ids.forEach((id, index) => {
409
+ write(` ${index + 1}. ${label(id)}${id === active ? " (current)" : ""}\n`);
433
410
  });
434
- write("Provider (number or name, Enter cancels): ");
411
+ write("Choice (number or name, Enter cancels): ");
435
412
  const answer = await readNextLine();
436
413
  if (answer === undefined)
437
414
  return undefined;
@@ -439,17 +416,28 @@ async function readProviderChoice(readNextLine, write, providerIds, active) {
439
416
  if (choice.length === 0)
440
417
  return undefined;
441
418
  const number = Number(choice);
442
- if (Number.isInteger(number) && number >= 1 && number <= providerIds.length) {
443
- return providerIds[number - 1];
419
+ if (Number.isInteger(number) && number >= 1 && number <= ids.length) {
420
+ return ids[number - 1];
444
421
  }
445
- return providerIds.find((id) => id.toLowerCase() === choice.toLowerCase());
422
+ return ids.find((id) => id.toLowerCase() === choice.toLowerCase());
446
423
  }
447
424
  async function runSignIn(readline, readNextLine, write, signIn) {
448
- write(`API key for ${signIn.provider} (hidden, saved locally; Enter skips): `);
449
425
  // The key is read from the same line source the loop uses. readline's
450
426
  // question() competes with the loop's own iterator for input, so the answer
451
427
  // would be swallowed or never arrive.
452
- const answer = await withoutEcho(readline, readNextLine);
428
+ // The hidden readline answer must also be unavailable through the Up key.
429
+ const discardKey = (history) => { history.shift(); };
430
+ readline.once("history", discardKey);
431
+ let answer;
432
+ try {
433
+ answer = await withoutEcho(readline, () => {
434
+ write(`API key for ${signIn.provider} (hidden, saved locally; Enter skips): `);
435
+ return readNextLine();
436
+ });
437
+ }
438
+ finally {
439
+ readline.off("history", discardKey);
440
+ }
453
441
  write("\n");
454
442
  if (answer === undefined) {
455
443
  return;
@@ -478,20 +466,12 @@ export async function runRepl(options) {
478
466
  options.stderr.write(text);
479
467
  };
480
468
  const tuiInput = options.tui ? new TuiInput(options.input) : undefined;
481
- // Decode independently so readline uses normal editing for every key. Its
482
- // chunked-paste fast path can lose wrapped cursor rows or overwrite text
483
- // when inserting a paste in the middle of an existing draft.
484
- if (tuiInput !== undefined)
485
- emitKeypressEvents(tuiInput);
486
469
  const readline = createInterface({
487
470
  input: tuiInput ?? options.input,
488
471
  output: options.output,
489
472
  terminal: true,
490
473
  prompt: REPL_PROMPT,
491
474
  });
492
- const menu = tuiInput === undefined ? undefined : new InputMenu(readline, options.output);
493
- let dismissedLine;
494
- let refreshQueued = false;
495
475
  const menuPriority = ["status", "diff", "provider", "model", "new", "resume", "help"];
496
476
  const commands = [...BUILT_IN_COMMANDS, ...(options.extensionCommands ?? []).map((command) => command.name)]
497
477
  .filter((name, index, all) => all.indexOf(name) === index)
@@ -508,113 +488,20 @@ export async function runRepl(options) {
508
488
  const suffix = description === undefined ? "" : ` · ${description}`;
509
489
  return { value: name, label: `/${name}${suffix}` };
510
490
  });
511
- const menuItems = (line) => {
512
- if (line === "/provider" || line.startsWith("/provider ")) {
513
- const query = line.slice("/provider".length).trim().toLowerCase();
514
- return (options.providers?.providerIds() ?? []).filter((id) => id.includes(query))
515
- .map((id) => ({ value: `provider ${id}`, label: `${id === options.providers?.provider ? "●" : "○"} ${id}` }));
516
- }
517
- if (line.startsWith("/") && !/\s/.test(line)) {
518
- return commands.filter((item) => item.label.startsWith(line));
519
- }
520
- return [];
521
- };
522
- const refreshMenu = () => {
523
- if (menu === undefined || inputClosed || signingIn || controller !== undefined)
524
- return;
525
- const line = readline.line;
526
- menu.show(line === dismissedLine ? [] : menuItems(line), true);
527
- };
528
- const queueRefresh = () => {
529
- if (refreshQueued)
530
- return;
531
- refreshQueued = true;
532
- setImmediate(() => { refreshQueued = false; refreshMenu(); });
533
- };
534
- const replaceDraft = (value) => {
535
- menu?.reset();
536
- readline.write(null, { ctrl: true, name: "a" });
537
- readline.write(null, { ctrl: true, name: "k" });
538
- readline.write(value);
539
- };
540
491
  let controller;
541
492
  let questionMode = false;
542
- let questionCancel;
543
493
  let promptVisible = false;
544
494
  let inputClosed = false;
545
495
  let signingIn = false;
546
- let composing = false;
547
- let composeCancelled = false;
548
496
  let interrupted = false;
549
- if (tuiInput !== undefined) {
550
- tuiInput.setMenuControls(() => {
551
- menu?.clear();
552
- dismissedLine = undefined;
553
- }, (key) => {
554
- if (questionCancel !== undefined && key === "escape") {
555
- questionCancel();
556
- return true;
557
- }
558
- if (signingIn || controller !== undefined)
559
- return false;
560
- if (key === "enter" && !menu?.active && readline.line === "/provider" && options.providers !== undefined) {
561
- menu?.show(menuItems(readline.line));
562
- return true;
563
- }
564
- if (key === "tab" && !menu?.active) {
565
- const first = menuItems(readline.line)[0]?.value;
566
- if (first !== undefined) {
567
- replaceDraft(`/${first}${first === "model" || first === "endpoint" ? " " : ""}`);
568
- queueRefresh();
569
- return true;
570
- }
571
- }
572
- if (!menu?.active)
573
- return false;
574
- if (key === "up" || key === "down") {
575
- menu.move(key === "up" ? -1 : 1);
576
- return true;
577
- }
578
- if (key === "escape") {
579
- dismissedLine = readline.line;
580
- menu.clear();
581
- return true;
582
- }
583
- const chosen = menu.selection;
584
- if (chosen === undefined)
585
- return false;
586
- const replacement = `/${chosen}`;
587
- if (key === "tab") {
588
- replaceDraft(replacement + (chosen === "model" || chosen === "endpoint" ? " " : ""));
589
- queueRefresh();
590
- return true;
591
- }
592
- if (key === "enter") {
593
- replaceDraft(replacement);
594
- if (chosen === "provider" || chosen === "model" || chosen === "endpoint") {
595
- if (chosen !== "provider")
596
- readline.write(" ");
597
- queueRefresh();
598
- }
599
- else {
600
- tuiInput.markSubmitted();
601
- readline.write("\r");
602
- }
603
- return true;
604
- }
605
- return false;
606
- });
607
- tuiInput.on("keypress", queueRefresh);
608
- }
609
497
  const showPrompt = () => {
610
- if (inputClosed || options.inlineComposer)
498
+ if (inputClosed || tuiInput !== undefined)
611
499
  return;
612
500
  promptVisible = true;
613
501
  readline.prompt();
614
502
  };
615
- readline.on("line", () => { menu?.reset(); promptVisible = false; });
503
+ readline.on("line", () => { promptVisible = false; });
616
504
  readline.on("close", () => {
617
- menu?.reset();
618
505
  inputClosed = true;
619
506
  controller?.abort();
620
507
  if (options.tui && promptVisible) {
@@ -624,20 +511,9 @@ export async function runRepl(options) {
624
511
  }
625
512
  });
626
513
  readline.on("SIGINT", () => {
627
- if (composing) {
628
- composeCancelled = true;
629
- readline.write("\r");
630
- return;
631
- }
632
514
  if (controller === undefined) {
633
- if (options.tui) {
634
- // Erase wrapped drafts before removing the prompt on close.
635
- readline.write(null, { ctrl: true, name: "e" });
636
- readline.write(null, { ctrl: true, name: "u" });
637
- }
638
- else {
515
+ if (!options.tui)
639
516
  options.output.write("\n");
640
- }
641
517
  interrupted = true;
642
518
  readline.close();
643
519
  return;
@@ -647,7 +523,6 @@ export async function runRepl(options) {
647
523
  if (options.banner !== undefined) {
648
524
  write(options.banner);
649
525
  }
650
- showPrompt();
651
526
  const lines = readline[Symbol.asyncIterator]();
652
527
  const readNextLine = async () => {
653
528
  tuiInput?.acceptLine();
@@ -657,8 +532,6 @@ export async function runRepl(options) {
657
532
  const questionPresenter = async (request, signal) => {
658
533
  if (inputClosed || controller?.signal.aborted === true)
659
534
  return { status: "unavailable", reason: "the local input channel is closed" };
660
- menu?.clear();
661
- dismissedLine = undefined;
662
535
  options.liveRegion?.pause();
663
536
  tuiInput?.setBusy(false);
664
537
  questionMode = true;
@@ -694,7 +567,7 @@ export async function runRepl(options) {
694
567
  let escaped = false;
695
568
  const cancelOnEscape = () => { escaped = true; if (!inputClosed)
696
569
  readline.write("\n"); };
697
- questionCancel = cancelOnEscape;
570
+ tuiInput?.setEscapeHandler(cancelOnEscape);
698
571
  const unblockOnAbort = () => { if (!inputClosed)
699
572
  readline.write("\n"); };
700
573
  signal?.addEventListener("abort", unblockOnAbort, { once: true });
@@ -714,7 +587,7 @@ export async function runRepl(options) {
714
587
  line("That answer does not match this question. Choose a listed number or enter a non-empty answer.");
715
588
  }
716
589
  finally {
717
- questionCancel = undefined;
590
+ tuiInput?.setEscapeHandler(undefined);
718
591
  signal?.removeEventListener("abort", unblockOnAbort);
719
592
  }
720
593
  }
@@ -725,7 +598,6 @@ export async function runRepl(options) {
725
598
  return { ...request, answers };
726
599
  }
727
600
  finally {
728
- questionCancel = undefined;
729
601
  questionMode = false;
730
602
  readline.setPrompt(REPL_PROMPT);
731
603
  tuiInput?.setBusy(true);
@@ -738,7 +610,6 @@ export async function runRepl(options) {
738
610
  if (signal?.aborted)
739
611
  return { approved: false, reason: "cancelled" };
740
612
  let resizeListener;
741
- menu?.clear();
742
613
  options.liveRegion?.pause();
743
614
  tuiInput?.setApprovalMode(true);
744
615
  tuiInput?.setBusy(false);
@@ -800,63 +671,10 @@ export async function runRepl(options) {
800
671
  }
801
672
  });
802
673
  }
803
- /** Modal composer retains readline editing, Unicode and native history. */
804
- const collectMultiline = async () => {
805
- const parts = [];
806
- let bytes = 0;
807
- composing = true;
808
- composeCancelled = false;
809
- tuiInput?.setComposeMode(true);
810
- menu?.clear();
811
- dismissedLine = undefined;
812
- readline.setPrompt(" │ ");
813
- write("\nCompose prompt · Enter adds a line · /send submits · /cancel discards\n");
814
- try {
815
- for (;;) {
816
- readline.prompt();
817
- const part = await readNextLine();
818
- if (tuiInput?.composeLimitExceeded) {
819
- write("Draft too large (64 KiB paste buffer). Nothing was sent.\n");
820
- return undefined;
821
- }
822
- if (composeCancelled || part === undefined || part.trim() === "/cancel") {
823
- write("Draft discarded.\n");
824
- return undefined;
825
- }
826
- if (part.trim() === "/send") {
827
- const message = parts.join("\n");
828
- if (message.trim().length === 0) {
829
- write("Empty draft discarded.\n");
830
- return undefined;
831
- }
832
- write(`Submitted ${parts.length} lines.\n`);
833
- return message;
834
- }
835
- bytes += Buffer.byteLength(part, "utf8") + 1;
836
- if (parts.length >= 200 || bytes > 64 * 1024) {
837
- write("Draft too large (200 lines / 64 KiB). Nothing was sent.\n");
838
- return undefined;
839
- }
840
- // //send and //cancel are literal lines instead of commands.
841
- parts.push(part.startsWith("//send") || part.startsWith("//cancel") ? part.slice(1) : part);
842
- }
843
- }
844
- finally {
845
- composing = false;
846
- composeCancelled = false;
847
- tuiInput?.setComposeMode(false);
848
- readline.setPrompt(REPL_PROMPT);
849
- }
850
- };
851
- /** Cursor-editable modal, with exclusive keyboard and paint ownership. */
852
- const collectEditor = async (isDefault = false) => {
853
- if (tuiInput === undefined) {
854
- write("The cursor editor requires the rich TUI in an interactive terminal. Use /compose here instead.\n");
674
+ /** Rounded inline composer with exclusive keyboard and paint ownership. */
675
+ const collectEditor = async () => {
676
+ if (tuiInput === undefined)
855
677
  return undefined;
856
- }
857
- menu?.clear();
858
- dismissedLine = undefined;
859
- composing = true;
860
678
  let resolveDraft;
861
679
  const pending = new Promise(resolve => { resolveDraft = resolve; });
862
680
  const output = options.output;
@@ -875,13 +693,11 @@ export async function runRepl(options) {
875
693
  return `${provider} · ${model}`;
876
694
  };
877
695
  const editor = new EditorController(output, resolveDraft, {
878
- submitOnEnter: isDefault,
879
696
  history: recent,
880
- slashCommands: commands.map(item => ({ value: item.value, label: item.label })),
881
- mouse: isDefault && options.tui === true && output.isTTY === true,
882
- color: isDefault && terminalColorEnabled(output.isTTY === true, process.env),
883
- ...(isDefault && options.tui ? { footerIdentity } : {}),
884
- ...(isDefault && options.tui && options.permissionPolicy !== undefined ? {
697
+ slashCommands: commands,
698
+ color: terminalColorEnabled(output.isTTY === true, process.env),
699
+ footerIdentity,
700
+ ...(options.permissionPolicy !== undefined ? {
885
701
  footerStatus: () => {
886
702
  if (activeSession.planMode)
887
703
  return "Plan · Shift+Tab Auto mode · /help";
@@ -919,8 +735,6 @@ export async function runRepl(options) {
919
735
  const result = await pending;
920
736
  if (editor.exitRequested.value)
921
737
  readline.close();
922
- if (!isDefault)
923
- write(result === undefined ? "Draft discarded.\n" : "Draft submitted.\n");
924
738
  return result;
925
739
  }
926
740
  finally {
@@ -928,7 +742,6 @@ export async function runRepl(options) {
928
742
  output.off("resize", resized);
929
743
  readline.off("close", closed);
930
744
  options.input.off("end", closed);
931
- composing = false;
932
745
  }
933
746
  };
934
747
  /** Read-only patch viewer, safe and separate from the model's tool calls. */
@@ -942,7 +755,6 @@ export async function runRepl(options) {
942
755
  write("Interactive patch review requires the rich TUI in an interactive terminal; use /diff instead.\n");
943
756
  return;
944
757
  }
945
- menu?.clear();
946
758
  let resolveReview;
947
759
  const pending = new Promise(resolve => { resolveReview = resolve; });
948
760
  const output = options.output;
@@ -962,16 +774,11 @@ export async function runRepl(options) {
962
774
  readline.off("close", closed);
963
775
  }
964
776
  };
965
- const inspectLiveGitDiff = async (line) => {
777
+ const inspectLiveGitDiff = async (mode) => {
966
778
  if (tuiInput === undefined) {
967
779
  write("Live Git review requires the rich TUI in an interactive terminal.\n");
968
780
  return;
969
781
  }
970
- if (line !== "/gitdiff" && line !== "/gitdiff --staged") {
971
- write("Usage: /gitdiff [--staged]\n");
972
- return;
973
- }
974
- const mode = line.endsWith("--staged") ? "staged" : "working";
975
782
  // Explicit user confirmation before starting any local Git process.
976
783
  const root = terminalText(activeSession.cwd);
977
784
  write(`\nRead-only local Git diff (${mode}) in:\n${root}\nNo network, hooks, external diff or file writes. Approve once? [y/N]\n`);
@@ -1004,23 +811,16 @@ export async function runRepl(options) {
1004
811
  write(`${error instanceof Error ? error.message : "Git diff unavailable"}\n`);
1005
812
  }
1006
813
  };
1007
- /** `/login` must name its target before any hidden key prompt. */
1008
- const chooseLoginProvider = async () => {
1009
- const providers = options.providers;
1010
- if (providers === undefined)
1011
- return undefined;
1012
- const ids = [...providers.providerIds()];
814
+ const chooseSetupOption = async (ids, active, title, label) => {
1013
815
  if (ids.length === 0)
1014
816
  return undefined;
1015
817
  if (tuiInput === undefined) {
1016
- return readProviderChoice(readNextLine, write, ids, providers.provider);
818
+ return readSetupChoice(readNextLine, write, ids, active, title, label);
1017
819
  }
1018
- menu?.clear();
1019
- dismissedLine = undefined;
1020
820
  let resolveChoice;
1021
821
  const pending = new Promise(resolve => { resolveChoice = resolve; });
1022
822
  const output = options.output;
1023
- const picker = new ProviderPickerController(output, ids, providers.provider, resolveChoice);
823
+ const picker = new ProviderPickerController(output, ids, active, resolveChoice, { title, item: label });
1024
824
  const resized = () => { picker.resized(); };
1025
825
  const closed = () => { picker.cancel(); };
1026
826
  tuiInput.setRawHandler(chunk => { picker.receive(chunk); });
@@ -1038,6 +838,81 @@ export async function runRepl(options) {
1038
838
  options.input.off("end", closed);
1039
839
  }
1040
840
  };
841
+ const chooseLoginProvider = (title = "Select a Provider for /login") => {
842
+ const providers = options.providers;
843
+ if (providers === undefined)
844
+ return Promise.resolve(undefined);
845
+ return chooseSetupOption(providers.providerIds(), providers.provider, title, providerPickerLabel);
846
+ };
847
+ const signInWithSubscription = async (target) => {
848
+ const signIn = options.signIn;
849
+ if (signIn?.oauth === undefined) {
850
+ write("OAuth sign-in is unavailable in this session.\n");
851
+ return;
852
+ }
853
+ controller = new AbortController();
854
+ tuiInput?.setBusy(true);
855
+ try {
856
+ write("Waiting for subscription sign-in. Ctrl+C cancels.\n");
857
+ const failure = await signIn.oauth(target, controller.signal);
858
+ write(failure ?? `Signed in to ${target} subscription for this session. Ready for your next prompt.\n`);
859
+ }
860
+ finally {
861
+ tuiInput?.setBusy(false);
862
+ controller = undefined;
863
+ }
864
+ };
865
+ const connectProvider = async (startup) => {
866
+ const { providers, signIn } = options;
867
+ if (providers === undefined || signIn === undefined)
868
+ return;
869
+ const wasReady = signIn.ready();
870
+ signingIn = true;
871
+ try {
872
+ const chosen = await chooseLoginProvider(startup ? "Connect a model · Select a Provider" : undefined);
873
+ if (chosen === undefined) {
874
+ write("No Provider selected; no key was stored.\n");
875
+ return;
876
+ }
877
+ const selected = await providers.select(chosen, "setup");
878
+ write(selected.message);
879
+ if (!selected.ok || (startup && signIn.ready()))
880
+ return;
881
+ for (const field of providers.missingSetup ?? []) {
882
+ write(field === "model" ? "Model ID (Enter cancels): " : "API endpoint URL (Enter cancels): ");
883
+ const value = (await readNextLine())?.trim();
884
+ if (!value)
885
+ return;
886
+ const configured = field === "model" ? await providers.changeModel(value, "setup") : await providers.changeEndpoint(value, "setup");
887
+ write(configured.message);
888
+ if (!configured.ok)
889
+ return;
890
+ }
891
+ if (startup && signIn.ready())
892
+ return;
893
+ if (signIn.oauth !== undefined && (chosen === "openai" || chosen === "xai")) {
894
+ const method = await chooseSetupOption(["key", "oauth"], "", `Connect ${chosen} · Choose a sign-in method`, (id) => id === "key" ? "Enter an API key" : chosen === "openai" ? "Sign in with ChatGPT" : "Sign in with xAI");
895
+ if (method === undefined)
896
+ return;
897
+ if (method === "oauth") {
898
+ await signInWithSubscription(chosen);
899
+ return;
900
+ }
901
+ }
902
+ await runSignIn(readline, readNextLine, write, signIn);
903
+ }
904
+ finally {
905
+ signingIn = false;
906
+ if (!wasReady && signIn.ready()) {
907
+ try {
908
+ await options.rememberProviderSetup?.();
909
+ }
910
+ catch (error) {
911
+ write(`Could not save model setup: ${error instanceof Error ? error.message : String(error)}\n`);
912
+ }
913
+ }
914
+ }
915
+ };
1041
916
  const signInAfterProviderSelection = async () => {
1042
917
  if (!options.tui || options.signIn === undefined)
1043
918
  return;
@@ -1062,9 +937,15 @@ export async function runRepl(options) {
1062
937
  }
1063
938
  };
1064
939
  try {
940
+ if (options.offerProviderSetup && options.signIn?.ready() === false) {
941
+ await connectProvider(true);
942
+ if (!inputClosed && !options.signIn.ready())
943
+ write("Run /login to connect a model before sending a prompt.\n");
944
+ }
945
+ showPrompt();
1065
946
  for (;;) {
1066
- let line = options.inlineComposer && tuiInput !== undefined
1067
- ? await collectEditor(true)
947
+ const line = tuiInput !== undefined
948
+ ? await collectEditor()
1068
949
  : await readNextLine();
1069
950
  if (line === undefined) {
1070
951
  if (inputClosed)
@@ -1075,51 +956,29 @@ export async function runRepl(options) {
1075
956
  showPrompt();
1076
957
  continue;
1077
958
  }
1078
- const fromComposer = line.trim() === "/compose";
1079
- const fromEditor = line.trim() === "/editor";
1080
- if (line.trim() === "/review" || line.trim() === "/diff patch") {
959
+ const trimmed = line.trim();
960
+ if (tuiInput !== undefined && trimmed === "/diff patch") {
1081
961
  await inspectPatch();
1082
962
  if (inputClosed)
1083
963
  break;
1084
964
  showPrompt();
1085
965
  continue;
1086
966
  }
1087
- if (line.trim() === "/diff" || line.trim() === "/diff --staged" || line.trim().startsWith("/gitdiff")) {
1088
- const gitDiffLine = line.trim().startsWith("/gitdiff")
1089
- ? line.trim()
1090
- : `/gitdiff${line.trim().slice("/diff".length)}`;
1091
- await inspectLiveGitDiff(gitDiffLine);
967
+ if (tuiInput !== undefined && (trimmed === "/diff" || trimmed === "/diff --staged")) {
968
+ await inspectLiveGitDiff(trimmed.endsWith("--staged") ? "staged" : "working");
1092
969
  if (inputClosed)
1093
970
  break;
1094
971
  showPrompt();
1095
972
  continue;
1096
973
  }
1097
- if (fromComposer || fromEditor) {
1098
- if (options.inlineComposer && tuiInput !== undefined) {
1099
- write("The cursor-addressable multiline editor is already active in this prompt. Enter sends; Ctrl+O inserts a newline.\n");
1100
- if (inputClosed)
1101
- break;
1102
- showPrompt();
1103
- continue;
1104
- }
1105
- const draft = fromEditor ? await collectEditor() : await collectMultiline();
1106
- if (draft === undefined) {
1107
- if (inputClosed)
1108
- break;
1109
- showPrompt();
1110
- continue;
1111
- }
1112
- line = draft;
1113
- }
1114
- if (options.inlineComposer && tuiInput !== undefined) {
974
+ if (tuiInput !== undefined) {
1115
975
  const isOutputTTY = typeof options.output === "object" && options.output !== null && "isTTY" in options.output && options.output.isTTY === true;
1116
- const useColor = options.tui === true && terminalColorEnabled(isOutputTTY, process.env);
976
+ const useColor = terminalColorEnabled(isOutputTTY, process.env);
1117
977
  const prefix = useColor ? "\u001b[1m\u001b[2m›\u001b[0m " : "› ";
1118
- const lines = line.split("\n");
1119
- const formattedPrompt = lines.map((l, i) => `${i === 0 ? prefix : " "}${terminalText(l)}`).join("\n");
978
+ const formattedPrompt = line.split("\n").map((l, i) => `${i === 0 ? prefix : " "}${terminalText(l)}`).join("\n");
1120
979
  write(`\n${formattedPrompt}\n\n`);
1121
980
  }
1122
- const outcome = fromComposer || fromEditor ? "not-a-command" : handleSlashCommand(line, {
981
+ const outcome = handleSlashCommand(line, {
1123
982
  session: activeSession,
1124
983
  write,
1125
984
  width: terminalWidth({ columns: options.output.columns }),
@@ -1139,7 +998,7 @@ export async function runRepl(options) {
1139
998
  ...(options.webSearch === undefined ? {} : { webSearch: options.webSearch }),
1140
999
  ...(options.permissions === undefined ? {} : { permissions: options.permissions }),
1141
1000
  ...(options.permissionPolicy === undefined ? {} : { permissionPolicy: options.permissionPolicy }),
1142
- ...(options.inlineComposer === true ? { inlineComposer: true } : {}),
1001
+ ...(options.tui === true ? { tui: true } : {}),
1143
1002
  ...(tuiInput !== undefined ? { interactivePicker: true } : {}),
1144
1003
  ...(options.sessionOptions === undefined ? {} : { sessionOptions: options.sessionOptions }),
1145
1004
  });
@@ -1174,14 +1033,7 @@ export async function runRepl(options) {
1174
1033
  continue;
1175
1034
  }
1176
1035
  }
1177
- controller = new AbortController();
1178
- try {
1179
- const failure = await options.signIn.oauth(target, controller.signal);
1180
- write(failure ?? `Signed in to ${target} subscription for this session. API keys remain preferred on the next launch.\n`);
1181
- }
1182
- finally {
1183
- controller = undefined;
1184
- }
1036
+ await signInWithSubscription(target);
1185
1037
  showPrompt();
1186
1038
  continue;
1187
1039
  }
@@ -1198,30 +1050,12 @@ export async function runRepl(options) {
1198
1050
  continue;
1199
1051
  }
1200
1052
  }
1201
- else if (options.providers !== undefined) {
1202
- signingIn = true;
1203
- let chosen;
1204
- try {
1205
- chosen = await chooseLoginProvider();
1206
- }
1207
- finally {
1208
- signingIn = false;
1209
- }
1210
- if (chosen === undefined) {
1211
- write("No Provider selected; no key was stored.\n");
1212
- if (inputClosed)
1213
- break;
1214
- showPrompt();
1215
- continue;
1216
- }
1217
- const selected = await options.providers.select(chosen);
1218
- write(selected.message);
1219
- if (!selected.ok) {
1220
- if (inputClosed)
1221
- break;
1222
- showPrompt();
1223
- continue;
1224
- }
1053
+ else if (options.providers !== undefined && options.signIn !== undefined) {
1054
+ await connectProvider(false);
1055
+ if (inputClosed)
1056
+ break;
1057
+ showPrompt();
1058
+ continue;
1225
1059
  }
1226
1060
  if (options.signIn !== undefined) {
1227
1061
  signingIn = true;
@@ -1311,7 +1145,7 @@ export async function runRepl(options) {
1311
1145
  if (typeof outcome === "object" && outcome.kind === "plan") {
1312
1146
  try {
1313
1147
  await activeSession.setPlanMode(outcome.enabled);
1314
- write(`Plan Mode ${activeSession.planMode ? "on" : "off"}. ${activeSession.planMode ? "Only built-in read tools and update_plan may execute." : "Session capabilities restored."}\n`);
1148
+ write(`Plan Mode ${activeSession.planMode ? "on" : "off"}. ${activeSession.planMode ? "Built-in read tools, configured web_search, update_plan, and question may execute." : "Session capabilities restored."}\n`);
1315
1149
  }
1316
1150
  catch (error) {
1317
1151
  write(`Could not change Plan Mode: ${error instanceof Error ? error.message : String(error)}\n`);