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
|
@@ -2,20 +2,21 @@
|
|
|
2
2
|
* @Author: Roman 306863030@qq.com
|
|
3
3
|
* @Date: 2026-03-17 11:59:19
|
|
4
4
|
* @LastEditors: Roman 306863030@qq.com
|
|
5
|
-
* @LastEditTime: 2026-03-
|
|
5
|
+
* @LastEditTime: 2026-03-25 19:28:32
|
|
6
6
|
* @FilePath: \deepfish\src\core\extension\ExtensionManager.js
|
|
7
7
|
* @Description: 扩展函数管理
|
|
8
8
|
* @
|
|
9
9
|
*/
|
|
10
|
-
const
|
|
10
|
+
const BaseExtension = require('./BaseExtension')
|
|
11
|
+
const SystemExtension = require('./SystemExtension')
|
|
12
|
+
const FileExtension = require('./FileExtension')
|
|
13
|
+
const InquirerExtension = require('./InquirerExtension')
|
|
14
|
+
const TestExtension = require('./TestExtension')
|
|
11
15
|
const path = require('path')
|
|
12
16
|
const fs = require('fs-extra')
|
|
13
17
|
const axios = require('axios')
|
|
14
18
|
const dayjs = require('dayjs')
|
|
15
19
|
const lodash = require('lodash')
|
|
16
|
-
const shelljs = require('shelljs')
|
|
17
|
-
const iconv = require('iconv-lite') // 用于编码转换
|
|
18
|
-
const os = require('os') // 用于判断系统类型
|
|
19
20
|
const { logError } = require('../utils/log')
|
|
20
21
|
const { getGlobalNodeModulesPath } = require('../utils/node-root')
|
|
21
22
|
|
|
@@ -23,12 +24,31 @@ class ExtensionManager {
|
|
|
23
24
|
constructor(aiCli) {
|
|
24
25
|
this.aiCli = aiCli
|
|
25
26
|
this.extensions = {
|
|
26
|
-
descriptions,
|
|
27
|
-
functions,
|
|
27
|
+
descriptions: [],
|
|
28
|
+
functions: {},
|
|
28
29
|
}
|
|
30
|
+
this.loadDefaultExtensions()
|
|
29
31
|
this.parseExtends(this.aiCli.config.extensions || [])
|
|
30
32
|
}
|
|
31
33
|
|
|
34
|
+
loadDefaultExtensions() {
|
|
35
|
+
this.extensions.descriptions = this.extensions.descriptions.concat(
|
|
36
|
+
SystemExtension.descriptions,
|
|
37
|
+
FileExtension.descriptions,
|
|
38
|
+
InquirerExtension.descriptions,
|
|
39
|
+
TestExtension.descriptions,
|
|
40
|
+
BaseExtension.descriptions
|
|
41
|
+
)
|
|
42
|
+
this.extensions.functions = Object.assign(
|
|
43
|
+
this.extensions.functions,
|
|
44
|
+
SystemExtension.functions,
|
|
45
|
+
FileExtension.functions,
|
|
46
|
+
InquirerExtension.functions,
|
|
47
|
+
TestExtension.functions,
|
|
48
|
+
BaseExtension.functions
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
|
|
32
52
|
parseExtends(configExtends) {
|
|
33
53
|
// 自动扫描扩展模块
|
|
34
54
|
const autoScannedExtends = this.autoScanExtensions()
|
|
@@ -47,6 +67,9 @@ class ExtensionManager {
|
|
|
47
67
|
|
|
48
68
|
// 动态加载扩展模块
|
|
49
69
|
let { descriptions, functions } = require(resolvedPath)
|
|
70
|
+
if (!descriptions || !functions) {
|
|
71
|
+
continue
|
|
72
|
+
}
|
|
50
73
|
descriptions = descriptions.map((item) => {
|
|
51
74
|
if (!item.type) {
|
|
52
75
|
return {
|
|
@@ -78,6 +101,11 @@ class ExtensionManager {
|
|
|
78
101
|
functions['axios'] = axios
|
|
79
102
|
functions['dayjs'] = dayjs
|
|
80
103
|
functions['lodash'] = lodash
|
|
104
|
+
// 根据名称去重
|
|
105
|
+
this.extensions.descriptions = lodash.uniqBy(
|
|
106
|
+
this.extensions.descriptions,
|
|
107
|
+
'function.name',
|
|
108
|
+
)
|
|
81
109
|
}
|
|
82
110
|
|
|
83
111
|
// 自动扫描node_modules和命令执行目录下的扩展模块
|
|
@@ -171,49 +199,6 @@ class ExtensionManager {
|
|
|
171
199
|
}
|
|
172
200
|
return null
|
|
173
201
|
}
|
|
174
|
-
|
|
175
|
-
_executeCommand(command) {
|
|
176
|
-
return new Promise((resolve, reject) => {
|
|
177
|
-
const platform = os.platform()
|
|
178
|
-
const targetEncoding = platform === 'win32' ? 'gbk' : 'utf-8' // Windows(含PowerShell)用gbk,Linux/macOS用utf-8
|
|
179
|
-
shelljs.exec(
|
|
180
|
-
command,
|
|
181
|
-
{
|
|
182
|
-
async: true,
|
|
183
|
-
cwd: process.cwd(),
|
|
184
|
-
encoding: 'binary',
|
|
185
|
-
silent: true,
|
|
186
|
-
},
|
|
187
|
-
(code, stdout, stderr) => {
|
|
188
|
-
try {
|
|
189
|
-
const stdoutUtf8 = iconv.decode(
|
|
190
|
-
Buffer.from(stdout, 'binary'),
|
|
191
|
-
targetEncoding,
|
|
192
|
-
)
|
|
193
|
-
const stderrUtf8 = iconv.decode(
|
|
194
|
-
Buffer.from(stderr, 'binary'),
|
|
195
|
-
targetEncoding,
|
|
196
|
-
)
|
|
197
|
-
if (stderrUtf8 && !stderrUtf8.trim().startsWith('WARNING')) {
|
|
198
|
-
// 过滤无关警告
|
|
199
|
-
const error = new Error(
|
|
200
|
-
`Command failed (code ${code}): ${stderrUtf8}`,
|
|
201
|
-
)
|
|
202
|
-
reject(error)
|
|
203
|
-
return
|
|
204
|
-
}
|
|
205
|
-
resolve(stdoutUtf8)
|
|
206
|
-
} catch (decodeError) {
|
|
207
|
-
reject(
|
|
208
|
-
new Error(
|
|
209
|
-
`Failed to parse command output: ${decodeError.message}`,
|
|
210
|
-
),
|
|
211
|
-
)
|
|
212
|
-
}
|
|
213
|
-
},
|
|
214
|
-
)
|
|
215
|
-
})
|
|
216
|
-
}
|
|
217
202
|
}
|
|
218
203
|
|
|
219
204
|
module.exports = ExtensionManager
|
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @Author: Roman 306863030@qq.com
|
|
3
|
+
* @Date: 2026-03-17 11:59:19
|
|
4
|
+
* @LastEditors: Roman 306863030@qq.com
|
|
5
|
+
* @LastEditTime: 2026-03-20 16:52:45
|
|
6
|
+
* @FilePath: \deepfish\src\core\extension\FileExtension.js
|
|
7
|
+
* @Description: 文件处理扩展函数
|
|
8
|
+
* @
|
|
9
|
+
*/
|
|
10
|
+
const path = require("path");
|
|
11
|
+
const fs = require("fs-extra");
|
|
12
|
+
|
|
13
|
+
async function createFile(filePath, content) {
|
|
14
|
+
try {
|
|
15
|
+
const fullPath = path.resolve(process.cwd(), filePath);
|
|
16
|
+
const dirPath = path.dirname(fullPath);
|
|
17
|
+
|
|
18
|
+
if (!fs.existsSync(dirPath)) {
|
|
19
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
20
|
+
}
|
|
21
|
+
fs.writeFileSync(fullPath, content);
|
|
22
|
+
return true;
|
|
23
|
+
} catch (error) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async function modifyFile(filePath, content) {
|
|
29
|
+
try {
|
|
30
|
+
const fullPath = path.resolve(process.cwd(), filePath);
|
|
31
|
+
|
|
32
|
+
if (!fs.existsSync(fullPath)) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
fs.writeFileSync(fullPath, content);
|
|
37
|
+
return true;
|
|
38
|
+
} catch (error) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async function readFile(filePath) {
|
|
44
|
+
try {
|
|
45
|
+
const fullPath = path.resolve(process.cwd(), filePath);
|
|
46
|
+
|
|
47
|
+
if (!fs.existsSync(fullPath)) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const content = fs.readFileSync(fullPath, "utf8");
|
|
52
|
+
return content;
|
|
53
|
+
} catch (error) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async function appendToFile(filePath, content) {
|
|
59
|
+
try {
|
|
60
|
+
const fullPath = path.resolve(process.cwd(), filePath);
|
|
61
|
+
|
|
62
|
+
if (!fs.existsSync(fullPath)) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
fs.appendFileSync(fullPath, content);
|
|
67
|
+
return true;
|
|
68
|
+
} catch (error) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function fileExists(filePath) {
|
|
74
|
+
const fullPath = path.resolve(process.cwd(), filePath);
|
|
75
|
+
return fs.existsSync(fullPath);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async function createDirectory(dirPath) {
|
|
79
|
+
try {
|
|
80
|
+
const fullPath = path.resolve(process.cwd(), dirPath);
|
|
81
|
+
if (!fs.existsSync(fullPath)) {
|
|
82
|
+
fs.mkdirSync(fullPath, { recursive: true });
|
|
83
|
+
}
|
|
84
|
+
return true;
|
|
85
|
+
} catch (error) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async function deleteFile(filePath) {
|
|
91
|
+
try {
|
|
92
|
+
const fullPath = path.resolve(process.cwd(), filePath);
|
|
93
|
+
|
|
94
|
+
if (fs.existsSync(fullPath)) {
|
|
95
|
+
fs.unlinkSync(fullPath);
|
|
96
|
+
}
|
|
97
|
+
return true;
|
|
98
|
+
} catch (error) {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async function deleteDirectory(dirPath) {
|
|
104
|
+
try {
|
|
105
|
+
const fullPath = path.resolve(process.cwd(), dirPath);
|
|
106
|
+
|
|
107
|
+
if (fs.existsSync(fullPath)) {
|
|
108
|
+
fs.rmSync(fullPath, { recursive: true, force: true });
|
|
109
|
+
}
|
|
110
|
+
return true;
|
|
111
|
+
} catch (error) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async function rename(oldPath, newPath) {
|
|
117
|
+
try {
|
|
118
|
+
const fullOldPath = path.resolve(process.cwd(), oldPath);
|
|
119
|
+
const fullNewPath = path.resolve(process.cwd(), newPath);
|
|
120
|
+
|
|
121
|
+
if (fs.existsSync(fullOldPath)) {
|
|
122
|
+
fs.renameSync(fullOldPath, fullNewPath);
|
|
123
|
+
}
|
|
124
|
+
return true;
|
|
125
|
+
} catch (error) {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async function moveFile(sourcePath, destinationPath) {
|
|
131
|
+
try {
|
|
132
|
+
const fullSourcePath = path.resolve(process.cwd(), sourcePath);
|
|
133
|
+
const fullDestPath = path.resolve(process.cwd(), destinationPath);
|
|
134
|
+
const destDirPath = path.dirname(fullDestPath);
|
|
135
|
+
|
|
136
|
+
if (!fs.existsSync(destDirPath)) {
|
|
137
|
+
fs.mkdirSync(destDirPath, { recursive: true });
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (fs.existsSync(fullSourcePath)) {
|
|
141
|
+
fs.renameSync(fullSourcePath, fullDestPath);
|
|
142
|
+
}
|
|
143
|
+
return true;
|
|
144
|
+
} catch (error) {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
async function getFileInfo(filePath) {
|
|
150
|
+
try {
|
|
151
|
+
const fullPath = path.resolve(process.cwd(), filePath);
|
|
152
|
+
|
|
153
|
+
if (!fs.existsSync(fullPath)) {
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const stats = fs.statSync(fullPath);
|
|
158
|
+
return {
|
|
159
|
+
path: fullPath,
|
|
160
|
+
size: stats.size,
|
|
161
|
+
birthtime: stats.birthtime,
|
|
162
|
+
mtime: stats.mtime,
|
|
163
|
+
ctime: stats.ctime,
|
|
164
|
+
isFile: stats.isFile(),
|
|
165
|
+
isDirectory: stats.isDirectory(),
|
|
166
|
+
};
|
|
167
|
+
} catch (error) {
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
async function getFileNameList(dirPath) {
|
|
173
|
+
try {
|
|
174
|
+
const fullPath = path.resolve(process.cwd(), dirPath);
|
|
175
|
+
if (!fs.existsSync(fullPath) || !fs.statSync(fullPath).isDirectory()) {
|
|
176
|
+
return [];
|
|
177
|
+
}
|
|
178
|
+
const files = fs
|
|
179
|
+
.readdirSync(fullPath)
|
|
180
|
+
.filter((file) => file !== "ai-history" && file !== "ai-log");
|
|
181
|
+
return files;
|
|
182
|
+
} catch (error) {
|
|
183
|
+
return [];
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
async function clearDirectory(dirPath) {
|
|
188
|
+
try {
|
|
189
|
+
const fullPath = path.resolve(process.cwd(), dirPath);
|
|
190
|
+
|
|
191
|
+
if (!fs.existsSync(fullPath)) {
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (!fs.statSync(fullPath).isDirectory()) {
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const files = fs.readdirSync(fullPath);
|
|
200
|
+
|
|
201
|
+
for (const file of files) {
|
|
202
|
+
const filePath = path.join(fullPath, file);
|
|
203
|
+
if (fs.statSync(filePath).isDirectory()) {
|
|
204
|
+
fs.rmSync(filePath, { recursive: true, force: true });
|
|
205
|
+
} else {
|
|
206
|
+
fs.unlinkSync(filePath);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return true;
|
|
211
|
+
} catch (error) {
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const descriptions = [
|
|
217
|
+
{
|
|
218
|
+
type: "function",
|
|
219
|
+
function: {
|
|
220
|
+
name: "createFile",
|
|
221
|
+
description:
|
|
222
|
+
"创建一个包含指定内容的新文件,返回布尔值表示操作是否成功。如果目录不存在会自动创建目录结构。",
|
|
223
|
+
parameters: {
|
|
224
|
+
type: "object",
|
|
225
|
+
properties: {
|
|
226
|
+
filePath: { type: "string" },
|
|
227
|
+
content: { type: "string" },
|
|
228
|
+
},
|
|
229
|
+
required: ["filePath", "content"],
|
|
230
|
+
},
|
|
231
|
+
},
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
type: "function",
|
|
235
|
+
function: {
|
|
236
|
+
name: "modifyFile",
|
|
237
|
+
description:
|
|
238
|
+
"修改指定文件的内容,返回布尔值表示操作是否成功。如果文件不存在则返回false。",
|
|
239
|
+
parameters: {
|
|
240
|
+
type: "object",
|
|
241
|
+
properties: {
|
|
242
|
+
filePath: { type: "string" },
|
|
243
|
+
content: { type: "string" },
|
|
244
|
+
},
|
|
245
|
+
required: ["filePath", "content"],
|
|
246
|
+
},
|
|
247
|
+
},
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
type: "function",
|
|
251
|
+
function: {
|
|
252
|
+
name: "readFile",
|
|
253
|
+
description:
|
|
254
|
+
"读取指定文件的内容,返回文件内容字符串。如果文件不存在或读取失败则返回null。",
|
|
255
|
+
parameters: {
|
|
256
|
+
type: "object",
|
|
257
|
+
properties: {
|
|
258
|
+
filePath: { type: "string" },
|
|
259
|
+
},
|
|
260
|
+
required: ["filePath"],
|
|
261
|
+
},
|
|
262
|
+
},
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
type: "function",
|
|
266
|
+
function: {
|
|
267
|
+
name: "appendToFile",
|
|
268
|
+
description:
|
|
269
|
+
"向指定文件追加内容,返回布尔值表示操作是否成功。如果文件不存在则返回false。",
|
|
270
|
+
parameters: {
|
|
271
|
+
type: "object",
|
|
272
|
+
properties: {
|
|
273
|
+
filePath: { type: "string" },
|
|
274
|
+
content: { type: "string" },
|
|
275
|
+
},
|
|
276
|
+
required: ["filePath", "content"],
|
|
277
|
+
},
|
|
278
|
+
},
|
|
279
|
+
},
|
|
280
|
+
{
|
|
281
|
+
type: "function",
|
|
282
|
+
function: {
|
|
283
|
+
name: "fileExists",
|
|
284
|
+
description: "检查指定文件是否存在,返回布尔值。",
|
|
285
|
+
parameters: {
|
|
286
|
+
type: "object",
|
|
287
|
+
properties: {
|
|
288
|
+
filePath: { type: "string" },
|
|
289
|
+
},
|
|
290
|
+
required: ["filePath"],
|
|
291
|
+
},
|
|
292
|
+
},
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
type: "function",
|
|
296
|
+
function: {
|
|
297
|
+
name: "createDirectory",
|
|
298
|
+
description:
|
|
299
|
+
"创建一个新目录,返回布尔值表示操作是否成功。支持递归创建目录结构。",
|
|
300
|
+
parameters: {
|
|
301
|
+
type: "object",
|
|
302
|
+
properties: {
|
|
303
|
+
dirPath: { type: "string" },
|
|
304
|
+
},
|
|
305
|
+
required: ["dirPath"],
|
|
306
|
+
},
|
|
307
|
+
},
|
|
308
|
+
},
|
|
309
|
+
{
|
|
310
|
+
type: "function",
|
|
311
|
+
function: {
|
|
312
|
+
name: "deleteFile",
|
|
313
|
+
description:
|
|
314
|
+
"删除指定文件,返回布尔值表示操作是否成功。如果文件不存在也会返回true。",
|
|
315
|
+
parameters: {
|
|
316
|
+
type: "object",
|
|
317
|
+
properties: {
|
|
318
|
+
filePath: { type: "string" },
|
|
319
|
+
},
|
|
320
|
+
required: ["filePath"],
|
|
321
|
+
},
|
|
322
|
+
},
|
|
323
|
+
},
|
|
324
|
+
{
|
|
325
|
+
type: "function",
|
|
326
|
+
function: {
|
|
327
|
+
name: "deleteDirectory",
|
|
328
|
+
description:
|
|
329
|
+
"删除指定目录,返回布尔值表示操作是否成功。支持递归删除目录及其内容。如果目录不存在也会返回true。",
|
|
330
|
+
parameters: {
|
|
331
|
+
type: "object",
|
|
332
|
+
properties: {
|
|
333
|
+
dirPath: { type: "string" },
|
|
334
|
+
},
|
|
335
|
+
required: ["dirPath"],
|
|
336
|
+
},
|
|
337
|
+
},
|
|
338
|
+
},
|
|
339
|
+
{
|
|
340
|
+
type: "function",
|
|
341
|
+
function: {
|
|
342
|
+
name: "rename",
|
|
343
|
+
description:
|
|
344
|
+
"重命名文件或目录,返回布尔值表示操作是否成功。如果原文件不存在也会返回true。",
|
|
345
|
+
parameters: {
|
|
346
|
+
type: "object",
|
|
347
|
+
properties: {
|
|
348
|
+
oldPath: { type: "string" },
|
|
349
|
+
newPath: { type: "string" },
|
|
350
|
+
},
|
|
351
|
+
required: ["oldPath", "newPath"],
|
|
352
|
+
},
|
|
353
|
+
},
|
|
354
|
+
},
|
|
355
|
+
{
|
|
356
|
+
type: "function",
|
|
357
|
+
function: {
|
|
358
|
+
name: "moveFile",
|
|
359
|
+
description:
|
|
360
|
+
"移动文件,返回布尔值表示操作是否成功。如果目标目录不存在会自动创建。如果源文件不存在也会返回true。",
|
|
361
|
+
parameters: {
|
|
362
|
+
type: "object",
|
|
363
|
+
properties: {
|
|
364
|
+
sourcePath: { type: "string" },
|
|
365
|
+
destinationPath: { type: "string" },
|
|
366
|
+
},
|
|
367
|
+
required: ["sourcePath", "destinationPath"],
|
|
368
|
+
},
|
|
369
|
+
},
|
|
370
|
+
},
|
|
371
|
+
{
|
|
372
|
+
type: "function",
|
|
373
|
+
function: {
|
|
374
|
+
name: "getFileInfo",
|
|
375
|
+
description:
|
|
376
|
+
"获取指定文件的信息,返回文件信息对象。如果文件不存在或获取失败则返回null。返回对象包含path、size、birthtime、mtime、ctime、isFile、isDirectory等属性。",
|
|
377
|
+
parameters: {
|
|
378
|
+
type: "object",
|
|
379
|
+
properties: {
|
|
380
|
+
filePath: { type: "string" },
|
|
381
|
+
},
|
|
382
|
+
required: ["filePath"],
|
|
383
|
+
},
|
|
384
|
+
},
|
|
385
|
+
},
|
|
386
|
+
{
|
|
387
|
+
type: "function",
|
|
388
|
+
function: {
|
|
389
|
+
name: "getFileNameList",
|
|
390
|
+
description:
|
|
391
|
+
"获取指定目录下的所有文件名,返回文件名数组。如果目录不存在或不是目录则返回空数组。",
|
|
392
|
+
parameters: {
|
|
393
|
+
type: "object",
|
|
394
|
+
properties: {
|
|
395
|
+
dirPath: { type: "string" },
|
|
396
|
+
},
|
|
397
|
+
required: ["dirPath"],
|
|
398
|
+
},
|
|
399
|
+
},
|
|
400
|
+
},
|
|
401
|
+
{
|
|
402
|
+
type: "function",
|
|
403
|
+
function: {
|
|
404
|
+
name: "clearDirectory",
|
|
405
|
+
description:
|
|
406
|
+
"清空指定目录的内容,返回布尔值表示操作是否成功。如果目录不存在或不是目录则返回false。",
|
|
407
|
+
parameters: {
|
|
408
|
+
type: "object",
|
|
409
|
+
properties: {
|
|
410
|
+
dirPath: { type: "string" },
|
|
411
|
+
},
|
|
412
|
+
required: ["dirPath"],
|
|
413
|
+
},
|
|
414
|
+
},
|
|
415
|
+
},
|
|
416
|
+
];
|
|
417
|
+
|
|
418
|
+
const functions = {
|
|
419
|
+
createFile,
|
|
420
|
+
modifyFile,
|
|
421
|
+
readFile,
|
|
422
|
+
appendToFile,
|
|
423
|
+
fileExists,
|
|
424
|
+
createDirectory,
|
|
425
|
+
deleteFile,
|
|
426
|
+
deleteDirectory,
|
|
427
|
+
rename,
|
|
428
|
+
moveFile,
|
|
429
|
+
getFileInfo,
|
|
430
|
+
getFileNameList,
|
|
431
|
+
clearDirectory,
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
module.exports = {
|
|
435
|
+
name: 'FileExtension',
|
|
436
|
+
extensionDescription: "提供文件和目录的创建、读取、修改、删除、移动、重命名、信息获取等文件系统操作功能",
|
|
437
|
+
descriptions,
|
|
438
|
+
functions,
|
|
439
|
+
};
|