@ww_nero/mini-cli 1.0.85 → 1.0.87
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 +3 -1
- package/src/utils/output.js +60 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ww_nero/mini-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.87",
|
|
4
4
|
"description": "极简的 AI 命令行助手",
|
|
5
5
|
"bin": {
|
|
6
6
|
"mini": "bin/mini.js"
|
|
@@ -32,6 +32,8 @@
|
|
|
32
32
|
"diff": "^5.2.0",
|
|
33
33
|
"eventsource-parser": "^1.1.2",
|
|
34
34
|
"gpt-tokenizer": "^2.9.0",
|
|
35
|
+
"marked": "^15.0.12",
|
|
36
|
+
"marked-terminal": "^7.3.0",
|
|
35
37
|
"node-fetch": "^2.7.0",
|
|
36
38
|
"openai": "^6.9.1"
|
|
37
39
|
}
|
package/src/utils/output.js
CHANGED
|
@@ -1,6 +1,65 @@
|
|
|
1
1
|
const chalk = require('chalk');
|
|
2
|
+
const { Marked } = require('marked');
|
|
3
|
+
const { markedTerminal } = require('marked-terminal');
|
|
2
4
|
const { splitThinkContent, summarizeReasoning } = require('./think');
|
|
3
5
|
|
|
6
|
+
const ANSI_PATTERN = /\u001B\[[0-9;]*m/g;
|
|
7
|
+
|
|
8
|
+
const createUnderlineFormatter = (char) => (text = '') => {
|
|
9
|
+
const plainText = text.replace(ANSI_PATTERN, '').trim();
|
|
10
|
+
if (!plainText) {
|
|
11
|
+
return text;
|
|
12
|
+
}
|
|
13
|
+
return `${text}\n${char.repeat(Math.max(plainText.length, 3))}`;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const prefixLines = (prefix, text = '') => text
|
|
17
|
+
.split('\n')
|
|
18
|
+
.map((line) => (line ? `${prefix}${line}` : line))
|
|
19
|
+
.join('\n');
|
|
20
|
+
|
|
21
|
+
const createMarkdownParser = (options) => {
|
|
22
|
+
const parser = new Marked();
|
|
23
|
+
parser.use(markedTerminal(options));
|
|
24
|
+
return parser;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const coloredMarkdownParser = createMarkdownParser({
|
|
28
|
+
showSectionPrefix: false,
|
|
29
|
+
heading: chalk.cyan.bold,
|
|
30
|
+
firstHeading: chalk.cyan.bold.underline,
|
|
31
|
+
strong: chalk.bold,
|
|
32
|
+
em: chalk.italic,
|
|
33
|
+
blockquote: chalk.gray,
|
|
34
|
+
code: chalk.yellow,
|
|
35
|
+
codespan: chalk.yellow,
|
|
36
|
+
table: chalk.gray,
|
|
37
|
+
link: chalk.blue,
|
|
38
|
+
href: chalk.blue.underline
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const plainMarkdownParser = createMarkdownParser({
|
|
42
|
+
showSectionPrefix: false,
|
|
43
|
+
firstHeading: createUnderlineFormatter('='),
|
|
44
|
+
heading: createUnderlineFormatter('-'),
|
|
45
|
+
blockquote: (text) => prefixLines('> ', text.replace(/^ {4}/gm, '')),
|
|
46
|
+
codespan: (text) => `\`${text}\``,
|
|
47
|
+
link: (text) => text,
|
|
48
|
+
href: (text) => text
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const shouldUseColoredMarkdown = () => Boolean(
|
|
52
|
+
process.stdout &&
|
|
53
|
+
process.stdout.isTTY &&
|
|
54
|
+
chalk.supportsColor &&
|
|
55
|
+
chalk.supportsColor.level > 0
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
const renderMarkdownToTerminal = (text) => {
|
|
59
|
+
const parser = shouldUseColoredMarkdown() ? coloredMarkdownParser : plainMarkdownParser;
|
|
60
|
+
return parser.parse(text);
|
|
61
|
+
};
|
|
62
|
+
|
|
4
63
|
const mergeReasoningContent = (...segments) => {
|
|
5
64
|
const normalized = segments
|
|
6
65
|
.map((segment) => (typeof segment === 'string' ? segment.trim() : ''))
|
|
@@ -22,7 +81,7 @@ const printAssistantContent = (text, ensureNewline) => {
|
|
|
22
81
|
return;
|
|
23
82
|
}
|
|
24
83
|
ensureNewline();
|
|
25
|
-
const output =
|
|
84
|
+
const output = renderMarkdownToTerminal(text);
|
|
26
85
|
process.stdout.write(output);
|
|
27
86
|
if (!text.endsWith('\n')) {
|
|
28
87
|
process.stdout.write('\n');
|