@ww_nero/mini-cli 1.0.97 → 1.0.98

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/chat.js +18 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ww_nero/mini-cli",
3
- "version": "1.0.97",
3
+ "version": "1.0.98",
4
4
  "description": "极简的 AI 命令行助手",
5
5
  "bin": {
6
6
  "mini": "bin/mini.js"
package/src/chat.js CHANGED
@@ -188,6 +188,10 @@ const formatToolResultForDisplay = (text, maxLength = 100) => {
188
188
  if (!normalized) {
189
189
  return '';
190
190
  }
191
+ if (normalized.startsWith('[Error]')) {
192
+ const errorMsg = normalized.replace('[Error] ', '');
193
+ return errorMsg.length > maxLength ? errorMsg.slice(0, maxLength) + '...' : errorMsg;
194
+ }
191
195
  return normalized.length > maxLength ? 'Done' : normalized;
192
196
  };
193
197
 
@@ -211,6 +215,15 @@ const indentToolResult = (text = '') => splitDisplayLines(text)
211
215
  .map((line) => ` ${line}`)
212
216
  .join('\n');
213
217
 
218
+ const formatTreeResult = (text = '') => {
219
+ const lines = splitDisplayLines(text);
220
+ if (lines.length === 0) return '';
221
+ return lines.map((line, index) => {
222
+ if (index === 0) return `└─ ${line}`;
223
+ return ` ${line}`;
224
+ }).join('\n');
225
+ };
226
+
214
227
  const supportsCursorControl = () => Boolean(process.stdout && process.stdout.isTTY);
215
228
 
216
229
  let loadingCursorActive = false;
@@ -1032,9 +1045,9 @@ const startChatSession = async ({
1032
1045
  if (functionName === 'write') {
1033
1046
  const writeOutput = formatWriteOutput(toolResult);
1034
1047
  if (writeOutput.isError) {
1035
- console.log(chalk.red(indentToolResult(writeOutput.message)));
1048
+ console.log(chalk.red(formatTreeResult(writeOutput.message)));
1036
1049
  } else {
1037
- console.log(chalk.gray(`已写入,共${writeOutput.lineCount}行`));
1050
+ console.log(chalk.gray(formatTreeResult(`已写入,共${writeOutput.lineCount}行`)));
1038
1051
  }
1039
1052
  } else if (functionName === 'edit') {
1040
1053
  const editOutput = formatEditOutput(toolResult);
@@ -1046,17 +1059,17 @@ const startChatSession = async ({
1046
1059
  } else if (functionName === 'read') {
1047
1060
  const isError = rawToolContent.startsWith('[Error]');
1048
1061
  if (isError) {
1049
- console.log(chalk.red(indentToolResult(rawToolContent.replace('[Error] ', ''))));
1062
+ console.log(chalk.red(formatTreeResult(rawToolContent.replace('[Error] ', ''))));
1050
1063
  } else {
1051
1064
  const normalized = rawToolContent.replace(/\r\n/g, '\n').replace(/\r/g, '\n').trim();
1052
1065
  const lineCount = countLines(normalized);
1053
- console.log(chalk.gray(`已读取,共${lineCount}行`));
1066
+ console.log(chalk.gray(formatTreeResult(`已读取,共${lineCount}行`)));
1054
1067
  }
1055
1068
  } else {
1056
1069
  const isError = rawToolContent.startsWith('[Error]');
1057
1070
  const displayResult = formatToolResultForDisplay(rawToolContent, 100);
1058
1071
  if (displayResult) {
1059
- console.log((isError ? chalk.red : chalk.gray)(indentToolResult(displayResult.replace('[Error] ', ''))));
1072
+ console.log((isError ? chalk.red : chalk.gray)(formatTreeResult(displayResult.replace('[Error] ', ''))));
1060
1073
  }
1061
1074
  }
1062
1075