@ww_nero/mini-cli 1.0.81 → 1.0.82
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/README.md +40 -40
- package/package.json +38 -38
- package/src/chat.js +1150 -1150
- package/src/config.js +342 -342
- package/src/index.js +39 -39
- package/src/llm.js +147 -147
- package/src/prompt/tool.js +18 -18
- package/src/request.js +338 -328
- package/src/tools/bash.js +144 -144
- package/src/tools/edit.js +137 -137
- package/src/tools/index.js +74 -74
- package/src/tools/mcp.js +503 -503
- package/src/tools/read.js +44 -44
- package/src/tools/skills.js +49 -49
- package/src/tools/todos.js +90 -90
- package/src/tools/write.js +66 -66
- package/src/utils/cliOptions.js +9 -9
- package/src/utils/git.js +89 -89
- package/src/utils/history.js +181 -181
- package/src/utils/model.js +131 -131
- package/src/utils/output.js +75 -75
- package/src/utils/renderer.js +102 -102
- package/src/utils/settings.js +77 -77
- package/src/utils/skills.js +250 -250
- package/src/utils/think.js +214 -214
package/src/index.js
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
const { Command } = require('commander');
|
|
2
|
-
const chalk = require('chalk');
|
|
3
|
-
|
|
4
|
-
const pkg = require('../package.json');
|
|
5
|
-
const { startChatSession } = require('./chat');
|
|
6
|
-
const { getDefaultConfigPath } = require('./config');
|
|
7
|
-
const { CLI_OPTIONS } = require('./utils/cliOptions');
|
|
8
|
-
|
|
9
|
-
const run = async () => {
|
|
10
|
-
const program = new Command();
|
|
11
|
-
|
|
12
|
-
program
|
|
13
|
-
.name('mini')
|
|
14
|
-
.description('Mini CLI · 极简 AI 命令行助手')
|
|
15
|
-
.version(pkg.version, '-v, --version')
|
|
16
|
-
.addHelpText('after', `\n退出方法:输入 /exit 或按 Ctrl+C。\n配置模板会自动生成于 ${getDefaultConfigPath()}。`)
|
|
17
|
-
.showHelpAfterError('(使用 mini --help 查看完整帮助)')
|
|
18
|
-
.action(async (options) => {
|
|
19
|
-
await startChatSession({
|
|
20
|
-
initialQuestion: options.input || '',
|
|
21
|
-
initialModelName: options.model,
|
|
22
|
-
initialResume: Boolean(options.resume),
|
|
23
|
-
cliOptions: CLI_OPTIONS
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
CLI_OPTIONS.forEach((option) => {
|
|
28
|
-
program.option(option.flags, option.description);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
try {
|
|
32
|
-
await program.parseAsync(process.argv);
|
|
33
|
-
} catch (error) {
|
|
34
|
-
console.error(chalk.red(`Mini CLI 运行失败: ${error.message}`));
|
|
35
|
-
process.exitCode = 1;
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
run();
|
|
1
|
+
const { Command } = require('commander');
|
|
2
|
+
const chalk = require('chalk');
|
|
3
|
+
|
|
4
|
+
const pkg = require('../package.json');
|
|
5
|
+
const { startChatSession } = require('./chat');
|
|
6
|
+
const { getDefaultConfigPath } = require('./config');
|
|
7
|
+
const { CLI_OPTIONS } = require('./utils/cliOptions');
|
|
8
|
+
|
|
9
|
+
const run = async () => {
|
|
10
|
+
const program = new Command();
|
|
11
|
+
|
|
12
|
+
program
|
|
13
|
+
.name('mini')
|
|
14
|
+
.description('Mini CLI · 极简 AI 命令行助手')
|
|
15
|
+
.version(pkg.version, '-v, --version')
|
|
16
|
+
.addHelpText('after', `\n退出方法:输入 /exit 或按 Ctrl+C。\n配置模板会自动生成于 ${getDefaultConfigPath()}。`)
|
|
17
|
+
.showHelpAfterError('(使用 mini --help 查看完整帮助)')
|
|
18
|
+
.action(async (options) => {
|
|
19
|
+
await startChatSession({
|
|
20
|
+
initialQuestion: options.input || '',
|
|
21
|
+
initialModelName: options.model,
|
|
22
|
+
initialResume: Boolean(options.resume),
|
|
23
|
+
cliOptions: CLI_OPTIONS
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
CLI_OPTIONS.forEach((option) => {
|
|
28
|
+
program.option(option.flags, option.description);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
await program.parseAsync(process.argv);
|
|
33
|
+
} catch (error) {
|
|
34
|
+
console.error(chalk.red(`Mini CLI 运行失败: ${error.message}`));
|
|
35
|
+
process.exitCode = 1;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
run();
|
package/src/llm.js
CHANGED
|
@@ -1,147 +1,147 @@
|
|
|
1
|
-
const { makeRequestWithRetry, processStreamResponse } = require('./request');
|
|
2
|
-
|
|
3
|
-
const sanitizeMessages = (messages = []) => {
|
|
4
|
-
return messages.map((message = {}) => {
|
|
5
|
-
const role = message.role;
|
|
6
|
-
const sanitized = {
|
|
7
|
-
role,
|
|
8
|
-
content: typeof message.content === 'string' ? message.content : String(message.content || '')
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
if (role === 'tool' && message.tool_call_id) {
|
|
12
|
-
sanitized.tool_call_id = message.tool_call_id;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
if (role === 'assistant' && Array.isArray(message.tool_calls) && message.tool_calls.length > 0) {
|
|
16
|
-
sanitized.tool_calls = message.tool_calls;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (message.reasoning_content) {
|
|
20
|
-
sanitized.reasoning_content = message.reasoning_content;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return sanitized;
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const sanitizeOptions = (options = {}) => {
|
|
28
|
-
if (!options || typeof options !== 'object') {
|
|
29
|
-
return {};
|
|
30
|
-
}
|
|
31
|
-
const invalidKeys = new Set(['messages', 'model', 'stream']);
|
|
32
|
-
return Object.keys(options).reduce((acc, key) => {
|
|
33
|
-
if (!invalidKeys.has(key)) {
|
|
34
|
-
acc[key] = options[key];
|
|
35
|
-
}
|
|
36
|
-
return acc;
|
|
37
|
-
}, {});
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const chatCompletion = async ({ endpoint, messages, abortController, onToken, onReasoningToken, onRetry, onComplete, tools = [] }) => {
|
|
41
|
-
const controller = abortController || new AbortController();
|
|
42
|
-
const includeToolCalls = Array.isArray(tools) && tools.length > 0;
|
|
43
|
-
|
|
44
|
-
const requestBody = {
|
|
45
|
-
stream: true,
|
|
46
|
-
model: endpoint.model,
|
|
47
|
-
messages: sanitizeMessages(messages),
|
|
48
|
-
...sanitizeOptions(endpoint.options)
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
if (!requestBody.stream_options || typeof requestBody.stream_options !== 'object') {
|
|
52
|
-
requestBody.stream_options = { include_usage: true };
|
|
53
|
-
} else {
|
|
54
|
-
requestBody.stream_options = {
|
|
55
|
-
...requestBody.stream_options,
|
|
56
|
-
include_usage: true
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (includeToolCalls) {
|
|
61
|
-
requestBody.tools = tools;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const response = await makeRequestWithRetry(endpoint, requestBody, controller, {
|
|
65
|
-
onRetry
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
let fullContent = '';
|
|
69
|
-
let fullReasoningContent = '';
|
|
70
|
-
|
|
71
|
-
const streamResult = await processStreamResponse(response, {
|
|
72
|
-
onContent: (chunk, aggregate) => {
|
|
73
|
-
fullContent = aggregate;
|
|
74
|
-
if (onToken) {
|
|
75
|
-
onToken(chunk, aggregate);
|
|
76
|
-
}
|
|
77
|
-
},
|
|
78
|
-
onReasoningContent: (chunk, aggregate) => {
|
|
79
|
-
fullReasoningContent = aggregate;
|
|
80
|
-
if (onReasoningToken) {
|
|
81
|
-
onReasoningToken(chunk, aggregate);
|
|
82
|
-
}
|
|
83
|
-
},
|
|
84
|
-
onComplete: () => {
|
|
85
|
-
if (onComplete) {
|
|
86
|
-
onComplete(fullContent);
|
|
87
|
-
}
|
|
88
|
-
},
|
|
89
|
-
abortController: controller,
|
|
90
|
-
includeToolCalls
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
const usage = (streamResult && typeof streamResult === 'object') ? streamResult.usage : null;
|
|
94
|
-
|
|
95
|
-
if (includeToolCalls) {
|
|
96
|
-
const streamContent = (streamResult && typeof streamResult === 'object') ? streamResult.content : '';
|
|
97
|
-
const contentText = (streamContent || fullContent || '').trim();
|
|
98
|
-
const streamReasoning = (streamResult && typeof streamResult === 'object') ? streamResult.reasoningContent : '';
|
|
99
|
-
const reasoningContent = (streamReasoning || fullReasoningContent || '').trim();
|
|
100
|
-
const toolCalls = Array.isArray(streamResult?.toolCalls) ? streamResult.toolCalls : [];
|
|
101
|
-
const streamMessage = streamResult && typeof streamResult === 'object' ? streamResult.message : null;
|
|
102
|
-
|
|
103
|
-
const message = (() => {
|
|
104
|
-
if (streamMessage) {
|
|
105
|
-
const merged = { ...streamMessage };
|
|
106
|
-
if (!merged.reasoning_content && reasoningContent) {
|
|
107
|
-
merged.reasoning_content = reasoningContent;
|
|
108
|
-
}
|
|
109
|
-
return merged;
|
|
110
|
-
}
|
|
111
|
-
return {
|
|
112
|
-
role: 'assistant',
|
|
113
|
-
content: contentText,
|
|
114
|
-
...(reasoningContent ? { reasoning_content: reasoningContent } : {})
|
|
115
|
-
};
|
|
116
|
-
})();
|
|
117
|
-
|
|
118
|
-
return {
|
|
119
|
-
content: contentText,
|
|
120
|
-
reasoningContent,
|
|
121
|
-
toolCalls,
|
|
122
|
-
usage,
|
|
123
|
-
message
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const streamContent = (streamResult && typeof streamResult === 'object') ? streamResult.content : streamResult;
|
|
128
|
-
const contentText = (streamContent || fullContent || '').trim();
|
|
129
|
-
const streamReasoning = (streamResult && typeof streamResult === 'object') ? streamResult.reasoningContent : '';
|
|
130
|
-
const reasoningText = (streamReasoning || fullReasoningContent || '').trim();
|
|
131
|
-
|
|
132
|
-
return {
|
|
133
|
-
content: contentText,
|
|
134
|
-
reasoningContent: reasoningText,
|
|
135
|
-
toolCalls: [],
|
|
136
|
-
usage,
|
|
137
|
-
message: {
|
|
138
|
-
role: 'assistant',
|
|
139
|
-
content: contentText,
|
|
140
|
-
...(reasoningText ? { reasoning_content: reasoningText } : {})
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
module.exports = {
|
|
146
|
-
chatCompletion
|
|
147
|
-
};
|
|
1
|
+
const { makeRequestWithRetry, processStreamResponse } = require('./request');
|
|
2
|
+
|
|
3
|
+
const sanitizeMessages = (messages = []) => {
|
|
4
|
+
return messages.map((message = {}) => {
|
|
5
|
+
const role = message.role;
|
|
6
|
+
const sanitized = {
|
|
7
|
+
role,
|
|
8
|
+
content: typeof message.content === 'string' ? message.content : String(message.content || '')
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
if (role === 'tool' && message.tool_call_id) {
|
|
12
|
+
sanitized.tool_call_id = message.tool_call_id;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (role === 'assistant' && Array.isArray(message.tool_calls) && message.tool_calls.length > 0) {
|
|
16
|
+
sanitized.tool_calls = message.tool_calls;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (message.reasoning_content) {
|
|
20
|
+
sanitized.reasoning_content = message.reasoning_content;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return sanitized;
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const sanitizeOptions = (options = {}) => {
|
|
28
|
+
if (!options || typeof options !== 'object') {
|
|
29
|
+
return {};
|
|
30
|
+
}
|
|
31
|
+
const invalidKeys = new Set(['messages', 'model', 'stream']);
|
|
32
|
+
return Object.keys(options).reduce((acc, key) => {
|
|
33
|
+
if (!invalidKeys.has(key)) {
|
|
34
|
+
acc[key] = options[key];
|
|
35
|
+
}
|
|
36
|
+
return acc;
|
|
37
|
+
}, {});
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const chatCompletion = async ({ endpoint, messages, abortController, onToken, onReasoningToken, onRetry, onComplete, tools = [] }) => {
|
|
41
|
+
const controller = abortController || new AbortController();
|
|
42
|
+
const includeToolCalls = Array.isArray(tools) && tools.length > 0;
|
|
43
|
+
|
|
44
|
+
const requestBody = {
|
|
45
|
+
stream: true,
|
|
46
|
+
model: endpoint.model,
|
|
47
|
+
messages: sanitizeMessages(messages),
|
|
48
|
+
...sanitizeOptions(endpoint.options)
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
if (!requestBody.stream_options || typeof requestBody.stream_options !== 'object') {
|
|
52
|
+
requestBody.stream_options = { include_usage: true };
|
|
53
|
+
} else {
|
|
54
|
+
requestBody.stream_options = {
|
|
55
|
+
...requestBody.stream_options,
|
|
56
|
+
include_usage: true
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (includeToolCalls) {
|
|
61
|
+
requestBody.tools = tools;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const response = await makeRequestWithRetry(endpoint, requestBody, controller, {
|
|
65
|
+
onRetry
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
let fullContent = '';
|
|
69
|
+
let fullReasoningContent = '';
|
|
70
|
+
|
|
71
|
+
const streamResult = await processStreamResponse(response, {
|
|
72
|
+
onContent: (chunk, aggregate) => {
|
|
73
|
+
fullContent = aggregate;
|
|
74
|
+
if (onToken) {
|
|
75
|
+
onToken(chunk, aggregate);
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
onReasoningContent: (chunk, aggregate) => {
|
|
79
|
+
fullReasoningContent = aggregate;
|
|
80
|
+
if (onReasoningToken) {
|
|
81
|
+
onReasoningToken(chunk, aggregate);
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
onComplete: () => {
|
|
85
|
+
if (onComplete) {
|
|
86
|
+
onComplete(fullContent);
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
abortController: controller,
|
|
90
|
+
includeToolCalls
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const usage = (streamResult && typeof streamResult === 'object') ? streamResult.usage : null;
|
|
94
|
+
|
|
95
|
+
if (includeToolCalls) {
|
|
96
|
+
const streamContent = (streamResult && typeof streamResult === 'object') ? streamResult.content : '';
|
|
97
|
+
const contentText = (streamContent || fullContent || '').trim();
|
|
98
|
+
const streamReasoning = (streamResult && typeof streamResult === 'object') ? streamResult.reasoningContent : '';
|
|
99
|
+
const reasoningContent = (streamReasoning || fullReasoningContent || '').trim();
|
|
100
|
+
const toolCalls = Array.isArray(streamResult?.toolCalls) ? streamResult.toolCalls : [];
|
|
101
|
+
const streamMessage = streamResult && typeof streamResult === 'object' ? streamResult.message : null;
|
|
102
|
+
|
|
103
|
+
const message = (() => {
|
|
104
|
+
if (streamMessage) {
|
|
105
|
+
const merged = { ...streamMessage };
|
|
106
|
+
if (!merged.reasoning_content && reasoningContent) {
|
|
107
|
+
merged.reasoning_content = reasoningContent;
|
|
108
|
+
}
|
|
109
|
+
return merged;
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
role: 'assistant',
|
|
113
|
+
content: contentText,
|
|
114
|
+
...(reasoningContent ? { reasoning_content: reasoningContent } : {})
|
|
115
|
+
};
|
|
116
|
+
})();
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
content: contentText,
|
|
120
|
+
reasoningContent,
|
|
121
|
+
toolCalls,
|
|
122
|
+
usage,
|
|
123
|
+
message
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const streamContent = (streamResult && typeof streamResult === 'object') ? streamResult.content : streamResult;
|
|
128
|
+
const contentText = (streamContent || fullContent || '').trim();
|
|
129
|
+
const streamReasoning = (streamResult && typeof streamResult === 'object') ? streamResult.reasoningContent : '';
|
|
130
|
+
const reasoningText = (streamReasoning || fullReasoningContent || '').trim();
|
|
131
|
+
|
|
132
|
+
return {
|
|
133
|
+
content: contentText,
|
|
134
|
+
reasoningContent: reasoningText,
|
|
135
|
+
toolCalls: [],
|
|
136
|
+
usage,
|
|
137
|
+
message: {
|
|
138
|
+
role: 'assistant',
|
|
139
|
+
content: contentText,
|
|
140
|
+
...(reasoningText ? { reasoning_content: reasoningText } : {})
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
module.exports = {
|
|
146
|
+
chatCompletion
|
|
147
|
+
};
|
package/src/prompt/tool.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
const getCurrentDate = () => {
|
|
2
|
-
const now = new Date();
|
|
3
|
-
const year = now.getFullYear();
|
|
4
|
-
const month = String(now.getMonth() + 1).padStart(2, '0');
|
|
5
|
-
const day = String(now.getDate()).padStart(2, '0');
|
|
6
|
-
return `${year}-${month}-${day}`;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
const toolSystemPrompt = `<current_date>${getCurrentDate()}</current_date>
|
|
10
|
-
|
|
11
|
-
<basic_rules>
|
|
12
|
-
* 需要调用\`todos\`工具,来创建和更新待办事项的进度。
|
|
13
|
-
* 除代码内容外,应使用简体中文作为默认语言。
|
|
14
|
-
</basic_rules>`;
|
|
15
|
-
|
|
16
|
-
module.exports = {
|
|
17
|
-
toolSystemPrompt
|
|
18
|
-
};
|
|
1
|
+
const getCurrentDate = () => {
|
|
2
|
+
const now = new Date();
|
|
3
|
+
const year = now.getFullYear();
|
|
4
|
+
const month = String(now.getMonth() + 1).padStart(2, '0');
|
|
5
|
+
const day = String(now.getDate()).padStart(2, '0');
|
|
6
|
+
return `${year}-${month}-${day}`;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const toolSystemPrompt = `<current_date>${getCurrentDate()}</current_date>
|
|
10
|
+
|
|
11
|
+
<basic_rules>
|
|
12
|
+
* 需要调用\`todos\`工具,来创建和更新待办事项的进度。
|
|
13
|
+
* 除代码内容外,应使用简体中文作为默认语言。
|
|
14
|
+
</basic_rules>`;
|
|
15
|
+
|
|
16
|
+
module.exports = {
|
|
17
|
+
toolSystemPrompt
|
|
18
|
+
};
|