deepfish-ai 1.0.13 → 1.0.16
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 +45 -5
- package/README_CN.md +44 -5
- package/package.json +7 -2
- package/src/cli/ConfigManager.js +24 -14
- package/src/cli/DefaultConfig.js +59 -0
- package/src/cli/ExtConfigManager.js +7 -7
- package/src/cli/HistoryManager.js +217 -0
- package/src/cli/SkillConfigManager.js +362 -0
- package/src/cli/SkillParser.js +61 -0
- package/src/cli/ai-config.js +23 -5
- package/src/cli/ai-history.js +34 -0
- package/src/cli/ai-skill.js +65 -0
- package/src/cli/index.js +4 -7
- package/src/core/AICLI.js +4 -6
- package/src/core/{globalVariable.js → GlobalVariable.js} +2 -3
- package/src/core/ai-services/AiWorker/AIMessageManager.js +71 -54
- package/src/core/ai-services/AiWorker/AiAgent.js +6 -9
- package/src/core/ai-services/AiWorker/AiPrompt.js +56 -6
- package/src/core/ai-services/AiWorker/AiTools.js +51 -7
- package/src/core/ai-services/AiWorker/index.js +87 -38
- package/src/core/ai-services/{AIService.js → index.js} +8 -0
- package/src/core/extension/BaseExtension.js +2 -0
- package/src/core/extension/ExtensionManager.js +35 -50
- package/src/core/extension/FileExtension.js +439 -0
- package/src/core/extension/InquirerExtension.js +293 -0
- package/src/core/extension/SystemExtension.js +415 -0
- package/src/core/extension/TestExtension.js +67 -0
- package/src/core/utils/log.js +10 -0
- package/src/core/utils/normal.js +86 -0
- package/src/cli/configTools.js +0 -90
- package/src/core/ai-services/AiWorker/AiRecorder.js +0 -119
- package/src/core/extension/DefaultExtension.js +0 -759
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
const { default: inquirer } = require('inquirer')
|
|
2
|
+
|
|
3
|
+
// 判断问答
|
|
4
|
+
async function askConfirm(name, message, defaultVal = true, opt = {}) {
|
|
5
|
+
const questions = [
|
|
6
|
+
{
|
|
7
|
+
type: 'confirm',
|
|
8
|
+
name,
|
|
9
|
+
message,
|
|
10
|
+
default: defaultVal,
|
|
11
|
+
...opt,
|
|
12
|
+
},
|
|
13
|
+
]
|
|
14
|
+
const answers = await inquirer.prompt(questions)
|
|
15
|
+
return answers[name]
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// 选择问答
|
|
19
|
+
function askList(name, message, choices, defaultVal = 0, opt = {}) {
|
|
20
|
+
const questions = [
|
|
21
|
+
{
|
|
22
|
+
type: 'list',
|
|
23
|
+
name,
|
|
24
|
+
message,
|
|
25
|
+
choices,
|
|
26
|
+
default: defaultVal,
|
|
27
|
+
...opt,
|
|
28
|
+
},
|
|
29
|
+
]
|
|
30
|
+
return inquirer.prompt(questions)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// 输入问答
|
|
34
|
+
async function askInput(name, message, defaultVal = '', opt = {}) {
|
|
35
|
+
const questions = [
|
|
36
|
+
{
|
|
37
|
+
type: 'input',
|
|
38
|
+
name,
|
|
39
|
+
message,
|
|
40
|
+
default: defaultVal,
|
|
41
|
+
...opt,
|
|
42
|
+
},
|
|
43
|
+
]
|
|
44
|
+
const answers = await inquirer.prompt(questions)
|
|
45
|
+
return answers[name]
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// 输入数字
|
|
49
|
+
async function askNumber(name, message, defaultVal = 0, opt = {}) {
|
|
50
|
+
const questions = [
|
|
51
|
+
{
|
|
52
|
+
type: 'number',
|
|
53
|
+
name,
|
|
54
|
+
message,
|
|
55
|
+
default: defaultVal,
|
|
56
|
+
...opt,
|
|
57
|
+
},
|
|
58
|
+
]
|
|
59
|
+
const answers = await inquirer.prompt(questions)
|
|
60
|
+
return answers[name]
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// 输入任何
|
|
64
|
+
function askAny(questions) {
|
|
65
|
+
return inquirer.prompt(questions)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const descriptions = [
|
|
69
|
+
{
|
|
70
|
+
type: 'function',
|
|
71
|
+
function: {
|
|
72
|
+
name: 'askConfirm',
|
|
73
|
+
description:
|
|
74
|
+
'用户交互:基于inquirer的confirm类型封装,提示用户确认问题,用户输入Y/N后返回布尔值(true/false)。参数说明(不是对象参数):name-问题标识名称;message-显示给用户的问题文本;defaultVal-默认布尔值(默认true);opt-inquirer额外配置选项对象。',
|
|
75
|
+
parameters: {
|
|
76
|
+
type: 'object',
|
|
77
|
+
properties: {
|
|
78
|
+
name: {
|
|
79
|
+
type: 'string',
|
|
80
|
+
description:
|
|
81
|
+
"问题的唯一标识名称,用于从返回结果中提取该问题的答案,例如 'confirmDelete'、'agreeLicense'",
|
|
82
|
+
},
|
|
83
|
+
message: {
|
|
84
|
+
type: 'string',
|
|
85
|
+
description:
|
|
86
|
+
"显示给用户的确认问题文本,例如 '是否确认删除?'、'你同意继续吗?'",
|
|
87
|
+
},
|
|
88
|
+
defaultVal: {
|
|
89
|
+
type: 'boolean',
|
|
90
|
+
description:
|
|
91
|
+
'用户直接按回车时的默认值,true表示默认确认,false表示默认拒绝,默认为true',
|
|
92
|
+
},
|
|
93
|
+
opt: {
|
|
94
|
+
type: 'object',
|
|
95
|
+
description:
|
|
96
|
+
'inquirer额外配置选项对象,可选。支持的字段包括:when(条件函数,控制是否显示此问题)、prefix(问题前缀符号)、suffix(问题后缀符号)、transformer(显示值转换函数)等',
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
required: ['name', 'message'],
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
type: 'function',
|
|
105
|
+
function: {
|
|
106
|
+
name: 'askList',
|
|
107
|
+
description:
|
|
108
|
+
'用户交互:基于inquirer的list类型封装,提示用户从列表中选择一项,返回包含用户选择结果的对象({choices => items => name: 选中值})。参数说明(不是对象参数):name-问题标识名称;message-显示给用户的提示文本;choices-选项数组(字符串或{name,value,short}对象);defaultVal-默认选中索引(默认0);opt-inquirer额外配置选项对象。',
|
|
109
|
+
parameters: {
|
|
110
|
+
type: 'object',
|
|
111
|
+
properties: {
|
|
112
|
+
name: {
|
|
113
|
+
type: 'string',
|
|
114
|
+
description:
|
|
115
|
+
"问题的唯一标识名称,用于从返回对象中提取选择结果,例如 'language'、'theme'。返回值格式为 {[name]: 选中项的value}",
|
|
116
|
+
},
|
|
117
|
+
message: {
|
|
118
|
+
type: 'string',
|
|
119
|
+
description:
|
|
120
|
+
"显示给用户的选择提示文本,例如 '请选择编程语言:'、'请选择主题风格:'",
|
|
121
|
+
},
|
|
122
|
+
choices: {
|
|
123
|
+
type: 'array',
|
|
124
|
+
description:
|
|
125
|
+
"选项数组,每项可以是字符串(同时作为显示文本和值),也可以是对象 {name: '显示文本', value: '实际值', short: '选中后的简短显示'}。还支持 new inquirer.Separator() 作为分隔线",
|
|
126
|
+
items: {
|
|
127
|
+
type: 'object',
|
|
128
|
+
properties: {
|
|
129
|
+
name: { type: 'string', description: '选项的显示文本' },
|
|
130
|
+
value: {
|
|
131
|
+
type: 'string',
|
|
132
|
+
description: '选项被选中后的实际返回值',
|
|
133
|
+
},
|
|
134
|
+
short: {
|
|
135
|
+
type: 'string',
|
|
136
|
+
description: '选中后在提示行中显示的简短文本,可选',
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
defaultVal: {
|
|
142
|
+
type: 'number',
|
|
143
|
+
description:
|
|
144
|
+
'默认选中项的索引(从0开始),默认为0即选中第一项。例如传入2表示默认高亮第三个选项',
|
|
145
|
+
},
|
|
146
|
+
opt: {
|
|
147
|
+
type: 'object',
|
|
148
|
+
description:
|
|
149
|
+
'inquirer额外配置选项对象,可选。支持的字段包括:loop(布尔值,是否循环滚动列表,默认true)、pageSize(数字,一次显示的选项数量,超出则滚动)、when(条件函数)、filter(结果过滤函数)等',
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
required: ['name', 'message', 'choices'],
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
type: 'function',
|
|
158
|
+
function: {
|
|
159
|
+
name: 'askInput',
|
|
160
|
+
description:
|
|
161
|
+
'用户交互:基于inquirer的input类型封装,提示用户输入一段文本,返回用户输入的字符串。参数说明(不是对象参数):name-问题标识名称;message-显示给用户的提示文本;defaultVal-默认输入值(默认空字符串);opt-inquirer额外配置选项对象(支持validate、filter等)。',
|
|
162
|
+
parameters: {
|
|
163
|
+
type: 'object',
|
|
164
|
+
properties: {
|
|
165
|
+
name: {
|
|
166
|
+
type: 'string',
|
|
167
|
+
description:
|
|
168
|
+
"问题的唯一标识名称,用于从返回结果中提取输入内容,例如 'username'、'filePath'",
|
|
169
|
+
},
|
|
170
|
+
message: {
|
|
171
|
+
type: 'string',
|
|
172
|
+
description:
|
|
173
|
+
"显示给用户的输入提示文本,例如 '请输入用户名:'、'请输入文件路径:'",
|
|
174
|
+
},
|
|
175
|
+
defaultVal: {
|
|
176
|
+
type: 'string',
|
|
177
|
+
description:
|
|
178
|
+
"用户直接按回车时的默认输入值,默认为空字符串。例如传入 './output' 表示默认路径",
|
|
179
|
+
},
|
|
180
|
+
opt: {
|
|
181
|
+
type: 'object',
|
|
182
|
+
description:
|
|
183
|
+
'inquirer额外配置选项对象,可选。支持的字段包括:validate(校验函数,接收输入值返回true或错误提示字符串)、filter(过滤函数,对用户输入进行转换处理)、transformer(显示转换函数,不影响实际值)、when(条件函数)等',
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
required: ['name', 'message'],
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
type: 'function',
|
|
192
|
+
function: {
|
|
193
|
+
name: 'askNumber',
|
|
194
|
+
description:
|
|
195
|
+
'用户交互:基于inquirer的number类型封装,提示用户输入一个数字,返回Number类型值(非数字输入返回NaN)。参数说明(不是对象参数):name-问题标识名称;message-显示给用户的提示文本;defaultVal-默认数字值(默认0);opt-inquirer额外配置选项对象(支持validate、filter等)。',
|
|
196
|
+
parameters: {
|
|
197
|
+
type: 'object',
|
|
198
|
+
properties: {
|
|
199
|
+
name: {
|
|
200
|
+
type: 'string',
|
|
201
|
+
description:
|
|
202
|
+
"问题的唯一标识名称,用于从返回结果中提取输入的数字,例如 'port'、'retryCount'",
|
|
203
|
+
},
|
|
204
|
+
message: {
|
|
205
|
+
type: 'string',
|
|
206
|
+
description:
|
|
207
|
+
"显示给用户的数字输入提示文本,例如 '请输入端口号:'、'请输入重试次数:'",
|
|
208
|
+
},
|
|
209
|
+
defaultVal: {
|
|
210
|
+
type: 'number',
|
|
211
|
+
description:
|
|
212
|
+
'用户直接按回车时的默认数字值,默认为0。例如传入8080表示默认端口号',
|
|
213
|
+
},
|
|
214
|
+
opt: {
|
|
215
|
+
type: 'object',
|
|
216
|
+
description:
|
|
217
|
+
'inquirer额外配置选项对象,可选。支持的字段包括:validate(校验函数,接收输入值返回true或错误提示字符串,可用于限制数值范围)、filter(过滤函数,对输入数字进行转换)、when(条件函数)等',
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
required: ['name', 'message'],
|
|
221
|
+
},
|
|
222
|
+
},
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
type: 'function',
|
|
226
|
+
function: {
|
|
227
|
+
name: 'askAny',
|
|
228
|
+
description:
|
|
229
|
+
'用户交互:直接调用inquirer.prompt()的通用封装,接受自定义问题对象数组,支持一次提出多个问题进行连续交互,返回包含所有答案的对象({问题name: 对应答案})。参数说明(不是对象参数):questions-inquirer问题对象数组,每个对象包含type(问题类型:input/confirm/list/checkbox/password/editor/rawlist/expand)、name(标识名称)、message(提示文本)及可选的default、choices、validate、filter、when等字段。',
|
|
230
|
+
parameters: {
|
|
231
|
+
type: 'object',
|
|
232
|
+
properties: {
|
|
233
|
+
questions: {
|
|
234
|
+
type: 'array',
|
|
235
|
+
description:
|
|
236
|
+
"inquirer问题对象数组,每个问题对象包含以下字段:type(问题类型,如'input'/'confirm'/'list'/'checkbox'/'password'/'editor'/'rawlist'/'expand')、name(问题标识名称)、message(提示文本)、default(默认值)、choices(选项数组,适用于list/checkbox/rawlist/expand类型)、validate(校验函数)、filter(过滤函数)、when(条件函数,控制是否显示该问题,接收前面的回答作为参数)、transformer(显示转换函数)等。多个问题会按数组顺序依次向用户提问",
|
|
237
|
+
items: {
|
|
238
|
+
type: 'object',
|
|
239
|
+
properties: {
|
|
240
|
+
type: {
|
|
241
|
+
type: 'string',
|
|
242
|
+
description:
|
|
243
|
+
"问题类型:'input'(文本输入)、'confirm'(是否确认)、'list'(单选列表)、'checkbox'(多选列表)、'password'(密码输入,输入内容隐藏)、'editor'(打开编辑器输入大段文本)、'rawlist'(带编号的列表选择)、'expand'(按键选择展开列表)",
|
|
244
|
+
},
|
|
245
|
+
name: {
|
|
246
|
+
type: 'string',
|
|
247
|
+
description:
|
|
248
|
+
'问题的唯一标识名称,用于在返回的答案对象中作为key提取对应答案',
|
|
249
|
+
},
|
|
250
|
+
message: {
|
|
251
|
+
type: 'string',
|
|
252
|
+
description: '显示给用户的问题提示文本',
|
|
253
|
+
},
|
|
254
|
+
default: {
|
|
255
|
+
type: 'string',
|
|
256
|
+
description: '默认值,类型根据问题类型而定',
|
|
257
|
+
},
|
|
258
|
+
choices: {
|
|
259
|
+
type: 'array',
|
|
260
|
+
description:
|
|
261
|
+
'选项数组,适用于list/checkbox/rawlist/expand类型',
|
|
262
|
+
},
|
|
263
|
+
validate: {
|
|
264
|
+
type: 'string',
|
|
265
|
+
description:
|
|
266
|
+
'校验函数,接收用户输入返回true表示通过或返回错误字符串',
|
|
267
|
+
},
|
|
268
|
+
},
|
|
269
|
+
required: ['type', 'name', 'message'],
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
},
|
|
273
|
+
required: ['questions'],
|
|
274
|
+
},
|
|
275
|
+
},
|
|
276
|
+
},
|
|
277
|
+
]
|
|
278
|
+
|
|
279
|
+
const functions = {
|
|
280
|
+
askConfirm,
|
|
281
|
+
askList,
|
|
282
|
+
askInput,
|
|
283
|
+
askNumber,
|
|
284
|
+
askAny,
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
module.exports = {
|
|
288
|
+
name: 'InquirerExtension',
|
|
289
|
+
extensionDescription:
|
|
290
|
+
'提供用户交互功能,支持确认、列表选择、文本输入、数字输入等多种交互方式',
|
|
291
|
+
descriptions,
|
|
292
|
+
functions,
|
|
293
|
+
}
|