@ww_nero/mini-cli 1.0.63 → 1.0.68

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ww_nero/mini-cli",
3
- "version": "1.0.63",
3
+ "version": "1.0.68",
4
4
  "description": "极简的 AI 命令行助手",
5
5
  "bin": {
6
6
  "mini": "bin/mini.js"
package/src/chat.js CHANGED
@@ -37,6 +37,7 @@ const {
37
37
  formatPreviewText,
38
38
  refreshHistoryFilePath
39
39
  } = require('./utils/history');
40
+ const { selectFromList } = require('./utils/menu');
40
41
 
41
42
  const CURSOR_STYLE_CODES = {
42
43
  default: '\u001B[0 q',
@@ -456,35 +457,47 @@ const startChatSession = async ({
456
457
  return true;
457
458
  };
458
459
 
459
- const handleResumeCommand = (rawArgs = '') => {
460
+ const handleResumeCommand = async (rawArgs = '') => {
460
461
  const entries = listHistoryFiles(workspaceRoot);
461
462
  if (entries.length === 0) {
462
463
  console.log(chalk.yellow('暂无历史记录。'));
463
464
  return;
464
465
  }
465
466
 
467
+ let targetIndex = -1;
468
+
466
469
  if (!rawArgs) {
467
- entries.forEach((entry, index) => {
470
+ const items = entries.map((entry, index) => {
468
471
  const historyMessages = readHistoryMessages(entry.filePath);
469
472
  if (!historyMessages) {
470
- console.log(`${index + 1}. ${chalk.red('(记录损坏)')}`);
471
- return;
473
+ return `${index + 1}. ${chalk.red('(记录损坏)')}`;
472
474
  }
473
475
  const previewSource = extractFirstUserQuestion(historyMessages);
474
- const preview = formatPreviewText(previewSource);
475
- console.log(`${index + 1}. ${preview}`);
476
+ const preview = formatPreviewText(previewSource, 50);
477
+ return `${index + 1}. ${preview}`;
476
478
  });
477
- console.log(chalk.gray('使用 /resume <序号> 恢复指定对话。'));
478
- return;
479
- }
480
479
 
481
- const numeric = Number.parseInt(rawArgs, 10);
482
- if (Number.isNaN(numeric)) {
483
- console.log(chalk.yellow('请输入合法的序号,例如 /resume 2。'));
484
- return;
480
+ if (rl) rl.pause();
481
+ const selectedIndex = await selectFromList(items, {
482
+ title: chalk.gray('请选择要恢复的历史记录:'),
483
+ pageSize: 15
484
+ });
485
+ if (rl) rl.resume();
486
+
487
+ if (selectedIndex === null) {
488
+ return;
489
+ }
490
+ targetIndex = selectedIndex;
491
+ } else {
492
+ const numeric = Number.parseInt(rawArgs, 10);
493
+ if (Number.isNaN(numeric)) {
494
+ console.log(chalk.yellow('请输入合法的序号,例如 /resume 2。'));
495
+ return;
496
+ }
497
+ targetIndex = numeric - 1;
485
498
  }
486
499
 
487
- resumeHistoryByIndex(numeric - 1);
500
+ resumeHistoryByIndex(targetIndex);
488
501
  };
489
502
 
490
503
  console.log(chalk.blueBright('Mini CLI 已启动,随时输入问题开始提问。'));
@@ -656,7 +669,9 @@ const startChatSession = async ({
656
669
  modelManager,
657
670
  resetMessages,
658
671
  closeSession,
659
- handleResume: handleResumeCommand
672
+ handleResume: handleResumeCommand,
673
+ pauseSession: () => rl.pause(),
674
+ resumeSession: () => rl.resume()
660
675
  });
661
676
 
662
677
  const resizeHandler = () => {
@@ -715,12 +730,31 @@ const startChatSession = async ({
715
730
  });
716
731
 
717
732
  const sendQuestion = async (rawInput) => {
718
- const text = (rawInput || '').trim();
733
+ let text = (rawInput || '').trim();
719
734
  if (!text) {
720
735
  return true;
721
736
  }
722
737
 
723
- const slashCommandResult = commandHandler.handleSlashCommand(text);
738
+ if (text === '/') {
739
+ rl.pause();
740
+ const menuItems = SLASH_COMMANDS.map((cmd) => `${cmd.value} - ${cmd.description}`);
741
+ const selectedIndex = await selectFromList(menuItems, {
742
+ title: chalk.gray('请选择命令:'),
743
+ pageSize: 10
744
+ });
745
+ rl.resume();
746
+
747
+ if (selectedIndex === null) {
748
+ return true;
749
+ }
750
+
751
+ const selected = SLASH_COMMANDS[selectedIndex];
752
+ if (selected) {
753
+ text = selected.value;
754
+ }
755
+ }
756
+
757
+ const slashCommandResult = await commandHandler.handleSlashCommand(text);
724
758
  if (slashCommandResult.handled) {
725
759
  return !slashCommandResult.shouldExit;
726
760
  }
@@ -885,7 +919,7 @@ const startChatSession = async ({
885
919
  const toolContent = resultInfo.content;
886
920
 
887
921
  // Display tool output
888
- if (functionName === 'write_todos') {
922
+ if (functionName === 'todos') {
889
923
  // For todos, display full formatted output without truncation
890
924
  if (toolContent) {
891
925
  console.log(chalk.gray(` ${toolContent}`));