deepfish-ai 1.0.29 → 2.0.3
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 +195 -344
- package/dist/generate-skill.md +104 -0
- package/dist/generate-tool.md +88 -0
- package/dist/index.js +26831 -0
- package/dist/serve/client/assets/index-DUHYC91l.js +1 -0
- package/dist/serve/client/assets/index-zcrdNLZs.css +1 -0
- package/dist/serve/client/index.html +14 -0
- package/dist/serve/pm2-server.js +24405 -0
- package/dist/serve/server/entry-server.mjs +224 -0
- package/dist/view-learn-cache.md +65 -0
- package/package.json +77 -83
- package/LICENSE +0 -21
- package/README_CN.md +0 -460
- package/src/AgentRobot/AgentRobotFactory/MainAgentRobot.js +0 -88
- package/src/AgentRobot/AgentRobotFactory/SubAgentRobot.js +0 -45
- package/src/AgentRobot/AgentRobotFactory/SubSkillAgentRobot.js +0 -45
- package/src/AgentRobot/AgentRobotFactory/index.js +0 -48
- package/src/AgentRobot/BaseAgentRobot/Brain.js +0 -210
- package/src/AgentRobot/BaseAgentRobot/BrainEvent.js +0 -17
- package/src/AgentRobot/BaseAgentRobot/Hand.js +0 -119
- package/src/AgentRobot/BaseAgentRobot/Heart.js +0 -0
- package/src/AgentRobot/BaseAgentRobot/Logger.js +0 -114
- package/src/AgentRobot/BaseAgentRobot/ScreenPrinter.js +0 -49
- package/src/AgentRobot/BaseAgentRobot/index.js +0 -266
- package/src/AgentRobot/BaseAgentRobot/lazy-tools/AliBailian.js +0 -997
- package/src/AgentRobot/BaseAgentRobot/lazy-tools/doc-transform.js +0 -204
- package/src/AgentRobot/BaseAgentRobot/lazy-tools/docx.js +0 -1286
- package/src/AgentRobot/BaseAgentRobot/lazy-tools/img.js +0 -765
- package/src/AgentRobot/BaseAgentRobot/lazy-tools/pdf.js +0 -736
- package/src/AgentRobot/BaseAgentRobot/lazy-tools/pptx.js +0 -567
- package/src/AgentRobot/BaseAgentRobot/lazy-tools/video.js +0 -36
- package/src/AgentRobot/BaseAgentRobot/lazy-tools/xlsx.js +0 -611
- package/src/AgentRobot/BaseAgentRobot/tools/BaseTools.js +0 -13
- package/src/AgentRobot/BaseAgentRobot/tools/CreateAgentTools.js +0 -158
- package/src/AgentRobot/BaseAgentRobot/tools/FileTools.js +0 -768
- package/src/AgentRobot/BaseAgentRobot/tools/GenerateTools.js +0 -441
- package/src/AgentRobot/BaseAgentRobot/tools/InquirerTools.js +0 -244
- package/src/AgentRobot/BaseAgentRobot/tools/SystemTools.js +0 -424
- package/src/AgentRobot/BaseAgentRobot/tools/TaskTools.js +0 -211
- package/src/AgentRobot/BaseAgentRobot/tools/TestTools.js +0 -100
- package/src/AgentRobot/BaseAgentRobot/tools/UserTool.js +0 -87
- package/src/AgentRobot/BaseAgentRobot/tools/WebTools.js +0 -257
- package/src/AgentRobot/BaseAgentRobot/utils/AIRequest.js +0 -297
- package/src/AgentRobot/BaseAgentRobot/utils/AIToolManager.js +0 -131
- package/src/AgentRobot/BaseAgentRobot/utils/AgentTree.js +0 -66
- package/src/AgentRobot/BaseAgentRobot/utils/AttachmentToolScanner.js +0 -235
- package/src/AgentRobot/BaseAgentRobot/utils/MessageCompresser.js +0 -236
- package/src/AgentRobot/BaseAgentRobot/utils/aiConsole.js +0 -74
- package/src/AgentRobot/BaseAgentRobot/utils/aiInquirer.js +0 -78
- package/src/AgentRobot/BaseAgentRobot/utils/analyzeReturn.test.js +0 -104
- package/src/AgentRobot/BaseAgentRobot/utils/copilot.js +0 -117
- package/src/AgentRobot/BaseAgentRobot/utils/node-root.js +0 -138
- package/src/AgentRobot/BaseAgentRobot/utils/normal.js +0 -399
- package/src/cli/ConfigManager.js +0 -283
- package/src/cli/DefaultConfig.js +0 -98
- package/src/cli/GlobalVariable.js +0 -8
- package/src/cli/MemoryManager.js +0 -53
- package/src/cli/SkillConfigManager.js +0 -354
- package/src/cli/SkillParser.js +0 -58
- package/src/cli/ai-auth.js +0 -231
- package/src/cli/ai-config.js +0 -225
- package/src/cli/ai-memory.js +0 -22
- package/src/cli/ai-skill.js +0 -65
- package/src/cli/index.js +0 -77
- package/src/index.js +0 -54
|
@@ -1,424 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @Author: Roman 306863030@qq.com
|
|
3
|
-
* @Date: 2026-03-17 11:59:19
|
|
4
|
-
* @LastEditors: Roman 306863030@qq.com
|
|
5
|
-
* @LastEditTime: 2026-05-12 18:49:29
|
|
6
|
-
* @FilePath: \deepfish\src\AgentRobot\BaseAgentRobot\tools\SystemTools.js
|
|
7
|
-
* @Description: 默认扩展函数(含AST-grep/ripgrep/comby代码搜索替换工具)
|
|
8
|
-
* @
|
|
9
|
-
*/
|
|
10
|
-
const path = require('path')
|
|
11
|
-
const fs = require('fs-extra')
|
|
12
|
-
const dayjs = require('dayjs')
|
|
13
|
-
const iconv = require('iconv-lite')
|
|
14
|
-
const { spawnSync } = require('child_process')
|
|
15
|
-
const { detectEncoding, analyzeReturn } = require('../utils/normal.js')
|
|
16
|
-
const aiConsole = require('../utils/aiConsole.js')
|
|
17
|
-
|
|
18
|
-
// 执行系统命令
|
|
19
|
-
// 执行系统命令(全平台兼容:Windows/PowerShell/CentOS)
|
|
20
|
-
function executeCommand(command, timeout = -1) {
|
|
21
|
-
aiConsole.logSuccess(
|
|
22
|
-
`Executing system command: ${command}; ${timeout > 0 ? `Timeout: ${timeout}ms` : 'No timeout limit'}`,
|
|
23
|
-
)
|
|
24
|
-
try {
|
|
25
|
-
const result = spawnSync(command, {
|
|
26
|
-
cwd: process.cwd(),
|
|
27
|
-
stdio: 'pipe',
|
|
28
|
-
shell: true,
|
|
29
|
-
encoding: 'buffer',
|
|
30
|
-
windowsHide: true,
|
|
31
|
-
argv0: 'deepfish-shell',
|
|
32
|
-
timeout: timeout > 0 ? timeout : undefined,
|
|
33
|
-
})
|
|
34
|
-
let targetEncoding = this.agentRobot.config?.encoding
|
|
35
|
-
if (!targetEncoding || targetEncoding === 'auto') {
|
|
36
|
-
targetEncoding = detectEncoding(result.stdout || result.stderr)
|
|
37
|
-
}
|
|
38
|
-
const stdout = iconv.decode(result.stdout, targetEncoding)
|
|
39
|
-
const stderr = iconv.decode(result.stderr, targetEncoding)
|
|
40
|
-
const code = result.status
|
|
41
|
-
if (stderr && !stderr.trim().startsWith('WARNING')) {
|
|
42
|
-
const error = new Error(`Command failed (code ${code}): ${stderr.trim()}`)
|
|
43
|
-
aiConsole.logError(`Execute error: ${error.message}`)
|
|
44
|
-
return `Execute error: ${error.message}`
|
|
45
|
-
}
|
|
46
|
-
aiConsole.logSuccess(`${stdout}\nCommand executed successfully`)
|
|
47
|
-
return stdout || 'Command executed successfully'
|
|
48
|
-
} catch (decodeError) {
|
|
49
|
-
aiConsole.logError(`Encoding convert error: ${decodeError.message}`)
|
|
50
|
-
return `Failed to parse command output: ${decodeError.message}`
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// 请求ai服务
|
|
55
|
-
async function requestAI(
|
|
56
|
-
systemDescription,
|
|
57
|
-
prompt,
|
|
58
|
-
temperature = this.agentRobot.opt.aiConfig.temperature,
|
|
59
|
-
) {
|
|
60
|
-
aiConsole.logSuccess(`Requesting AI`)
|
|
61
|
-
if (
|
|
62
|
-
typeof systemDescription === 'object' &&
|
|
63
|
-
systemDescription.systemDescription
|
|
64
|
-
) {
|
|
65
|
-
prompt = systemDescription.prompt || prompt || ''
|
|
66
|
-
systemDescription = systemDescription.systemDescription || ''
|
|
67
|
-
}
|
|
68
|
-
try {
|
|
69
|
-
const response = await this.agentRobot.brain.think(
|
|
70
|
-
systemDescription,
|
|
71
|
-
prompt,
|
|
72
|
-
temperature,
|
|
73
|
-
)
|
|
74
|
-
return response
|
|
75
|
-
} catch (error) {
|
|
76
|
-
aiConsole.logError(`Error executing AI function: ${error.message}`)
|
|
77
|
-
throw error
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// 执行js代码
|
|
82
|
-
async function executeJSCode(code) {
|
|
83
|
-
aiConsole.logSuccess('Executing JavaScript code: ')
|
|
84
|
-
aiConsole.logSuccess(code)
|
|
85
|
-
// 校验代码片段中是否存在顶层 return,避免仅按最后一行判断导致误判。
|
|
86
|
-
const { hasReturnValue } = analyzeReturn(code)
|
|
87
|
-
if (!hasReturnValue) {
|
|
88
|
-
const error = new Error('The code must contain a return value.')
|
|
89
|
-
throw error
|
|
90
|
-
}
|
|
91
|
-
try {
|
|
92
|
-
const functions = this.agentRobot.toolManager.functions
|
|
93
|
-
const Func = new Function(
|
|
94
|
-
'Tools',
|
|
95
|
-
'require',
|
|
96
|
-
`return (async () => {
|
|
97
|
-
this.logMessages = []
|
|
98
|
-
this.Tools = Tools
|
|
99
|
-
const originalLog = console.log
|
|
100
|
-
const newLog = function () {
|
|
101
|
-
originalLog.apply(console, arguments)
|
|
102
|
-
this.logMessages.push(Array.from(arguments).join(' '))
|
|
103
|
-
}
|
|
104
|
-
console.log = newLog.bind(this)
|
|
105
|
-
async function __main() {
|
|
106
|
-
${code}
|
|
107
|
-
}
|
|
108
|
-
const result = await __main()
|
|
109
|
-
console.log = originalLog
|
|
110
|
-
return result || this.logMessages.join('\\n')
|
|
111
|
-
})()`,
|
|
112
|
-
)
|
|
113
|
-
const originalRequire = require
|
|
114
|
-
const newRequire = (modulePath) => {
|
|
115
|
-
if (modulePath.startsWith('./')) {
|
|
116
|
-
const resolvedPath = path.resolve(process.cwd(), modulePath)
|
|
117
|
-
return originalRequire(resolvedPath)
|
|
118
|
-
}
|
|
119
|
-
return originalRequire(modulePath)
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const result = await Func(functions, newRequire)
|
|
123
|
-
return result || ''
|
|
124
|
-
} catch (error) {
|
|
125
|
-
aiConsole.logError(`Error executing code: ${error.stack}`)
|
|
126
|
-
throw error
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// 获取当前系统时间
|
|
131
|
-
function getCurrentTime() {
|
|
132
|
-
const now = dayjs()
|
|
133
|
-
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone || 'unknown'
|
|
134
|
-
return `Current system time: ${now.format('YYYY-MM-DD HH:mm:ss')} | ISO: ${now.toISOString()} | Timezone: ${timezone}`
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// 了解自己
|
|
138
|
-
function getSelfInfo() {
|
|
139
|
-
// 返回自己的代码路径、package.json路径、readme路径等基本信息,供AI有选择的了解自己,回答用户的问题
|
|
140
|
-
const homeDir = path.resolve(__dirname, '../../../../')
|
|
141
|
-
const packageJson = fs.readJSONSync(path.resolve(homeDir, 'package.json'))
|
|
142
|
-
return {
|
|
143
|
-
config: {
|
|
144
|
-
description: 'DeepFish AI程序代码配置项',
|
|
145
|
-
value: this.agentRobot.config,
|
|
146
|
-
},
|
|
147
|
-
codePath: {
|
|
148
|
-
description: 'DeepFish AI程序代码路径',
|
|
149
|
-
value: homeDir,
|
|
150
|
-
},
|
|
151
|
-
configPath: {
|
|
152
|
-
description: 'DeepFish AI程序配置文件路径',
|
|
153
|
-
value: path.resolve(this.agentRobot.basespace, 'config.js'),
|
|
154
|
-
},
|
|
155
|
-
selfCmd: {
|
|
156
|
-
description: 'DeepFish AI程序系统命令说明',
|
|
157
|
-
value: ```bash
|
|
158
|
-
# Configuration commands
|
|
159
|
-
ai config add # Add a new AI configuration
|
|
160
|
-
ai config ls # List all AI configurations
|
|
161
|
-
ai config use <name> # Set the specified AI configuration as the current one
|
|
162
|
-
ai config del <name> # Delete the specified AI configuration
|
|
163
|
-
ai config view [name] # View details of the specified AI configuration
|
|
164
|
-
ai config edit # Edit the configuration file manually
|
|
165
|
-
ai config dir # Open the configuration file directory
|
|
166
|
-
ai config reset # Reset configuration
|
|
167
|
-
|
|
168
|
-
# Skill commands
|
|
169
|
-
ai skill ls # List all registered skills
|
|
170
|
-
ai skill add <name> # Add a local skill directory or zip file from the current directory
|
|
171
|
-
ai skill del <name|index> # Remove a skill by name or index, exp: ai skill del 1
|
|
172
|
-
ai skill install <url> # Install a skill from ClawHub,exp: ai skill install https://clawhub.ai/TheSethRose/agent-browser
|
|
173
|
-
ai skill enable <name|index> # Enable a skill by name or index, exp: ai skill enable 1
|
|
174
|
-
ai skill disable <name|index> # Disable a skill by name or index, exp: ai skill disable 1
|
|
175
|
-
ai skill dir # Open the skill directory
|
|
176
|
-
|
|
177
|
-
# Memory commands
|
|
178
|
-
ai memory clear # Clear the history messages for the current directory
|
|
179
|
-
ai memory dir # Open the memory directory
|
|
180
|
-
```
|
|
181
|
-
},
|
|
182
|
-
packageJsonPath: {
|
|
183
|
-
description: 'DeepFish AI程序package.json文件路径',
|
|
184
|
-
value: path.resolve(homeDir, 'package.json'),
|
|
185
|
-
},
|
|
186
|
-
readmeCNPath: {
|
|
187
|
-
description: 'DeepFish AI程序中文文档路径',
|
|
188
|
-
value: path.resolve(homeDir, 'README_CN.md'),
|
|
189
|
-
},
|
|
190
|
-
readmeENPath: {
|
|
191
|
-
description: 'DeepFish AI程序英文文档路径',
|
|
192
|
-
value: path.resolve(homeDir, 'README.md'),
|
|
193
|
-
},
|
|
194
|
-
version: {
|
|
195
|
-
description: 'DeepFish AI程序版本',
|
|
196
|
-
value: 'v' + packageJson.version,
|
|
197
|
-
},
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
// ========== 代码搜索与结构替换工具 ==========
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* 查找 CLI 工具是否可用,返回可用的命令路径或 null
|
|
205
|
-
* @param {string[]} candidateCmds 候选命令列表
|
|
206
|
-
* @returns {string|null} 找到的第一个可用命令
|
|
207
|
-
*/
|
|
208
|
-
function findAvailableCommand(candidateCmds) {
|
|
209
|
-
for (const cmd of candidateCmds) {
|
|
210
|
-
try {
|
|
211
|
-
const check = spawnSync(cmd, ['--version'], {
|
|
212
|
-
shell: true,
|
|
213
|
-
windowsHide: true,
|
|
214
|
-
timeout: 8000,
|
|
215
|
-
encoding: 'buffer',
|
|
216
|
-
})
|
|
217
|
-
if (check.status === 0) return cmd
|
|
218
|
-
} catch (_) {
|
|
219
|
-
// 继续尝试下一个
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
return null
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* AST结构化代码搜索与替换(基于ast-grep)
|
|
227
|
-
* 通过AST模式精准匹配代码结构,避免正则误匹配。
|
|
228
|
-
* 支持 JavaScript/TypeScript/Python/Java/Go/Rust 等30+语言。
|
|
229
|
-
*
|
|
230
|
-
* @param {string} pattern - AST模式,如 'class $NAME { $$ }'、'function $FUNC($$$ARGS) { $$ }'
|
|
231
|
-
* @param {string} filePath - 目标文件或目录路径(相对于工作目录)
|
|
232
|
-
* @param {string} [language] - 语言选择器,如 'javascript'、'typescript'、'python'
|
|
233
|
-
* @param {string} [rewrite] - 替换模板,如 'class $NAME extends Base { $$ }'
|
|
234
|
-
* @param {boolean} [update=false] - 是否直接修改源文件(默认false,仅预览)
|
|
235
|
-
* @returns {string} 搜索匹配结果或替换统计信息
|
|
236
|
-
*/
|
|
237
|
-
function astGrepSearch(pattern, filePath, language, rewrite, update) {
|
|
238
|
-
aiConsole.logSuccess(
|
|
239
|
-
`AST-grep: pattern="${pattern}", path="${filePath}", lang=${language || 'auto'}, rewrite=${!!rewrite}, update=${!!update}`,
|
|
240
|
-
)
|
|
241
|
-
try {
|
|
242
|
-
const resolvedPath = path.resolve(process.cwd(), filePath)
|
|
243
|
-
|
|
244
|
-
// 候选命令:npx 调用 / 本地 node_modules / 全局安装
|
|
245
|
-
const nodeBin = path.resolve(__dirname, '../../../../node_modules/.bin')
|
|
246
|
-
const candidateCmds = [
|
|
247
|
-
`npx ast-grep`,
|
|
248
|
-
`"${path.join(nodeBin, 'ast-grep')}"`,
|
|
249
|
-
`"${path.join(nodeBin, 'ast-grep.cmd')}"`,
|
|
250
|
-
'ast-grep',
|
|
251
|
-
'sg',
|
|
252
|
-
]
|
|
253
|
-
|
|
254
|
-
const astGrepCmd = findAvailableCommand(candidateCmds)
|
|
255
|
-
if (!astGrepCmd) {
|
|
256
|
-
return `[AST-grep] 工具未安装。安装方法:npm install @ast-grep/cli(项目级)或 npm install -g @ast-grep/cli(全局)`
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
const args = ['--pattern', pattern]
|
|
260
|
-
if (language) args.push('--selector', language)
|
|
261
|
-
if (rewrite) args.push('--rewrite', rewrite)
|
|
262
|
-
if (update) args.push('--update')
|
|
263
|
-
args.push(resolvedPath)
|
|
264
|
-
|
|
265
|
-
const result = spawnSync(astGrepCmd, args, {
|
|
266
|
-
cwd: process.cwd(),
|
|
267
|
-
stdio: 'pipe',
|
|
268
|
-
shell: true,
|
|
269
|
-
encoding: 'buffer',
|
|
270
|
-
windowsHide: true,
|
|
271
|
-
timeout: 60000,
|
|
272
|
-
})
|
|
273
|
-
|
|
274
|
-
const stdout = iconv.decode(result.stdout, 'utf8')
|
|
275
|
-
const stderr = iconv.decode(result.stderr, 'utf8')
|
|
276
|
-
|
|
277
|
-
if (result.status !== 0 && stderr && !stderr.includes('no matches')) {
|
|
278
|
-
return `[AST-grep] 错误: ${stderr.trim()}`
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
const output = stdout.trim()
|
|
282
|
-
if (!output) {
|
|
283
|
-
return '[AST-grep] 搜索完成,未找到匹配项。'
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
const lines = output.split('\n').length
|
|
287
|
-
const actionLabel = rewrite ? (update ? '已替换' : '可替换(预览模式,未修改文件)') : '匹配'
|
|
288
|
-
return `[AST-grep] ${actionLabel} ${lines} 处:\n${output}`
|
|
289
|
-
} catch (error) {
|
|
290
|
-
return `[AST-grep] 执行失败: ${error.message}`
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
const descriptions = [
|
|
297
|
-
{
|
|
298
|
-
type: 'function',
|
|
299
|
-
function: {
|
|
300
|
-
name: 'executeCommand',
|
|
301
|
-
description:
|
|
302
|
-
'执行系统命令,返回执行结果。适用于运行shell命令、系统工具等。command为需要执行的系统命令字符串,如"ls -l"; timeout为命令执行的超时时间,单位为毫秒,-1表示不限制超时时间, 默认值为-1。注意:如果执行多条命令,且需要保持会话,使用命令链的方式执行。命令执行失败时会抛出错误,成功时返回命令执行结果字符串或"System command executed successfully"。',
|
|
303
|
-
parameters: {
|
|
304
|
-
type: 'object',
|
|
305
|
-
properties: {
|
|
306
|
-
command: { type: 'string' },
|
|
307
|
-
timeout: { type: 'number' },
|
|
308
|
-
},
|
|
309
|
-
required: ['command'],
|
|
310
|
-
},
|
|
311
|
-
},
|
|
312
|
-
},
|
|
313
|
-
{
|
|
314
|
-
type: 'function',
|
|
315
|
-
function: {
|
|
316
|
-
name: 'requestAI',
|
|
317
|
-
description:
|
|
318
|
-
'请求AI服务处理简单任务,如随机生成一段话、翻译文本、数学计算、代码分析、知识检索等。通过systemDescription参数指定AI的行为和限制,prompt参数输入任务描述, temperature参数指定AI的温度(0-2之间的浮点数,默认为用户配置)。返回AI处理后的结果字符串,执行失败时会抛出错误。',
|
|
319
|
-
parameters: {
|
|
320
|
-
type: 'object',
|
|
321
|
-
properties: {
|
|
322
|
-
systemDescription: { type: 'string' },
|
|
323
|
-
prompt: { type: 'string' },
|
|
324
|
-
temperature: { type: 'number' },
|
|
325
|
-
},
|
|
326
|
-
required: ['systemDescription', 'prompt'],
|
|
327
|
-
},
|
|
328
|
-
},
|
|
329
|
-
},
|
|
330
|
-
{
|
|
331
|
-
type: 'function',
|
|
332
|
-
function: {
|
|
333
|
-
name: 'executeJSCode',
|
|
334
|
-
description:
|
|
335
|
-
'执行JavaScript代码,返回代码执行结果。代码中可通过Tools命名空间直接调用其他工具函数(如await Tools.createFile(),注意:不需要使用require引入),Tools中引入了一些常用库可直接调用(Tools.fs="fs-extra", Tools.dayjs="dayjs", Tools.axios="axios", Tools.lodash="lodash", Tools.echarts="echarts", Tools.canvas="canvas" Tools.cheerio="cheerio" Tools.puppeteer="puppeteer"),支持引入自定义模块(需使用绝对路径)。注意:1.代码中不要使用__dirname获取当前目录,请使用path.resolve(".")来获取当前目录。2.执行失败时会抛出错误,成功时返回代码执行结果或空字符串。3.使用require(module_path)函数引入自定义模块,module_path为模块路径字符串,支持相对路径(如"./myModule.js")和绝对路径,返回引入的模块内容。4.执行主函数必须使用return返回,如return main()',
|
|
336
|
-
parameters: {
|
|
337
|
-
type: 'object',
|
|
338
|
-
properties: {
|
|
339
|
-
code: { type: 'string' },
|
|
340
|
-
},
|
|
341
|
-
required: ['code'],
|
|
342
|
-
},
|
|
343
|
-
},
|
|
344
|
-
},
|
|
345
|
-
{
|
|
346
|
-
type: 'function',
|
|
347
|
-
function: {
|
|
348
|
-
name: 'getCurrentTime',
|
|
349
|
-
description:
|
|
350
|
-
'获取当前系统时间,返回本地时间、ISO时间和时区信息。适用于需要在任务中使用当前时间戳或进行时间记录的场景。',
|
|
351
|
-
parameters: {
|
|
352
|
-
type: 'object',
|
|
353
|
-
properties: {},
|
|
354
|
-
required: [],
|
|
355
|
-
},
|
|
356
|
-
},
|
|
357
|
-
},
|
|
358
|
-
{
|
|
359
|
-
type: 'function',
|
|
360
|
-
function: {
|
|
361
|
-
name: 'getSelfInfo',
|
|
362
|
-
description:
|
|
363
|
-
'获取DeepFish AI程序的基本信息、命令行等,供AI有选择的了解自己,回答用户的问题。',
|
|
364
|
-
parameters: {
|
|
365
|
-
type: 'object',
|
|
366
|
-
properties: {},
|
|
367
|
-
required: [],
|
|
368
|
-
},
|
|
369
|
-
},
|
|
370
|
-
},
|
|
371
|
-
{
|
|
372
|
-
type: 'function',
|
|
373
|
-
function: {
|
|
374
|
-
name: 'astGrepSearch',
|
|
375
|
-
description:
|
|
376
|
-
'【推荐】使用AST-grep进行结构化代码搜索与精准替换。通过AST语法树模式匹配代码结构(而非正则文本),避免误匹配注释/字符串。支持JavaScript/TypeScript/Python/Java/Go/Rust等30+语言。适用于:重命名函数、修改API调用、重构类继承、批量清理TODO等场景。参数:pattern-AST模式(如"class $NAME { $$ }"匹配类定义);filePath-目标文件或目录路径;language-可选,语言选择器(如javascript/typescript/python,不指定则自动检测);rewrite-可选,替换模板(如"class $NAME extends Base { $$ }");update-可选,是否直接修改源文件(默认false仅预览)。比replaceFileText更精准,比手动逐个修改高效。',
|
|
377
|
-
parameters: {
|
|
378
|
-
type: 'object',
|
|
379
|
-
properties: {
|
|
380
|
-
pattern: {
|
|
381
|
-
type: 'string',
|
|
382
|
-
description: 'AST匹配模式,如 "function $FUNC($$$ARGS) { $$ }"',
|
|
383
|
-
},
|
|
384
|
-
filePath: {
|
|
385
|
-
type: 'string',
|
|
386
|
-
description: '目标文件或目录路径',
|
|
387
|
-
},
|
|
388
|
-
language: {
|
|
389
|
-
type: 'string',
|
|
390
|
-
description: '语言选择器,如 javascript/typescript/python/java/go/rust,默认自动检测',
|
|
391
|
-
},
|
|
392
|
-
rewrite: {
|
|
393
|
-
type: 'string',
|
|
394
|
-
description: '替换模板,如 "function $FUNC($$$ARGS) { log(); $$ }"',
|
|
395
|
-
},
|
|
396
|
-
update: {
|
|
397
|
-
type: 'boolean',
|
|
398
|
-
description: '是否直接修改源文件,默认false(仅预览)',
|
|
399
|
-
},
|
|
400
|
-
},
|
|
401
|
-
required: ['pattern', 'filePath'],
|
|
402
|
-
},
|
|
403
|
-
},
|
|
404
|
-
}
|
|
405
|
-
]
|
|
406
|
-
const functions = {
|
|
407
|
-
executeCommand,
|
|
408
|
-
requestAI,
|
|
409
|
-
executeJSCode,
|
|
410
|
-
getCurrentTime,
|
|
411
|
-
getSelfInfo,
|
|
412
|
-
astGrepSearch,
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
const SystemTool = {
|
|
416
|
-
name: 'SystemTool',
|
|
417
|
-
description:
|
|
418
|
-
'提供系统命令执行、AI请求、JS代码执行、AST-grep结构化搜索替换、ripgrep超快文本搜索、comby结构化代码替换、扩展文件生成规则、AI配置管理、Tool加载执行等核心系统功能',
|
|
419
|
-
descriptions,
|
|
420
|
-
functions,
|
|
421
|
-
isSystem: true
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
module.exports = SystemTool
|
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
const fs = require('fs-extra')
|
|
2
|
-
const path = require('path')
|
|
3
|
-
|
|
4
|
-
// 生成/创建任务列表
|
|
5
|
-
function createTaskList(userPrompt = '') {
|
|
6
|
-
const prompt = `在当前目录创建一个任务列表文件 tmp_tasklist_${this.agentRobot.id}.json;创建一个记录用户任务目标的文件,tmp_task_goal_${this.agentRobot.id}.md。
|
|
7
|
-
tmp_tasklist_${this.agentRobot.id}.json文件创建规则:
|
|
8
|
-
1. 文件内容必须是 JSON 数组;
|
|
9
|
-
2. 每个数组元素是一个任务对象,字段至少包含:
|
|
10
|
-
- id: 任务唯一标识(字符串或数字)
|
|
11
|
-
- name: 任务名称
|
|
12
|
-
- description: 任务的详细说明
|
|
13
|
-
- status: 任务状态("todo" | "doing" | "done")
|
|
14
|
-
- createdAt: 创建时间(ISO 字符串)
|
|
15
|
-
- finishedAt: 完成时间(未完成可为 null)
|
|
16
|
-
- note: 备注(可为空字符串)
|
|
17
|
-
3. 任务需尽量原子化、可执行。
|
|
18
|
-
|
|
19
|
-
输出要求:
|
|
20
|
-
- 仅输出可写入的合法 JSON 内容,不要输出解释文字。
|
|
21
|
-
|
|
22
|
-
tmp_task_goal_${this.agentRobot.id}.md文件为以下内容:
|
|
23
|
-
${userPrompt}
|
|
24
|
-
`
|
|
25
|
-
return this.Tools.createSubAgent(prompt)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// 执行任务列表
|
|
29
|
-
function executeTaskList(userPrompt = '') {
|
|
30
|
-
const prompt = `你需要执行当前目录下的 tmp_tasklist_${this.agentRobot.id}.json。
|
|
31
|
-
|
|
32
|
-
执行规则:
|
|
33
|
-
1. 读取任务列表,仅处理 status 为 "todo" 或 "doing" 的任务;
|
|
34
|
-
2. 每次只执行一个子任务,按列表顺序执行;
|
|
35
|
-
3. 执行前将当前任务状态更新为 "doing" 并保存;
|
|
36
|
-
4. 执行前需要阅读 tmp_task_goal_${this.agentRobot.id}.md 文件,了解用户的整体需求;
|
|
37
|
-
5. 子任务执行成功后更新为 "done",并写入 finishedAt(ISO 时间);
|
|
38
|
-
6. 子任务失败时保留为 "doing" 或回退为 "todo",并在 note 记录失败原因摘要;
|
|
39
|
-
7. 每完成一个子任务都必须立刻写回 tmp_tasklist_${this.agentRobot.id}.json;
|
|
40
|
-
8. 当全部任务为 "done" 时,明确输出“任务列表执行完成”。
|
|
41
|
-
9. 尽量交给子任务完成,主任务流不要参与过多思考和执行细节。
|
|
42
|
-
10. 告诉子任务任务列表的文件名称 tmp_tasklist_${this.agentRobot.id}.json。
|
|
43
|
-
11. 任务全部执行完成后,删除 tmp_tasklist_${this.agentRobot.id}.json 文件和 tmp_task_goal_${this.agentRobot.id}.md 文件。
|
|
44
|
-
|
|
45
|
-
输出要求:
|
|
46
|
-
- 输出当前执行的任务 id/name、结果状态、下一步计划;
|
|
47
|
-
- 不要跳过状态更新与落盘步骤。
|
|
48
|
-
|
|
49
|
-
工具函数:
|
|
50
|
-
- readTaskList: 读取任务列表文件
|
|
51
|
-
- updateTaskList: 更新任务列表文件
|
|
52
|
-
- executeSubTaskFromTaskList: 执行单个子任务目标
|
|
53
|
-
|
|
54
|
-
以下是用户的原始需求:
|
|
55
|
-
${userPrompt}
|
|
56
|
-
`
|
|
57
|
-
return this.Tools.createSubAgent(prompt)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// 读取任务列表
|
|
61
|
-
function readTaskList(taskListPath) {
|
|
62
|
-
return (
|
|
63
|
-
fs.readFileSync(
|
|
64
|
-
taskListPath ||
|
|
65
|
-
path.join(process.cwd(), `tmp_tasklist_${this.agentRobot.id}.json`),
|
|
66
|
-
{ encoding: 'utf-8' },
|
|
67
|
-
) || '[]'
|
|
68
|
-
)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// 更新任务列表
|
|
72
|
-
function updateTaskList(taskListPath, list) {
|
|
73
|
-
try {
|
|
74
|
-
fs.writeFileSync(
|
|
75
|
-
taskListPath ||
|
|
76
|
-
path.join(process.cwd(), `tmp_tasklist_${this.agentRobot.id}.json`),
|
|
77
|
-
JSON.stringify(list, null, 2),
|
|
78
|
-
{ encoding: 'utf-8' },
|
|
79
|
-
)
|
|
80
|
-
return true
|
|
81
|
-
} catch (error) {
|
|
82
|
-
return { error: error.message }
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// 从任务列表执行子任务
|
|
87
|
-
function executeSubTaskFromTaskList(subTaskGoalPrompt = '') {
|
|
88
|
-
return this.Tools.createSubAgent(subTaskGoalPrompt)
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const descriptions = [
|
|
92
|
-
{
|
|
93
|
-
type: 'function',
|
|
94
|
-
function: {
|
|
95
|
-
name: 'createTaskList',
|
|
96
|
-
description:
|
|
97
|
-
'创建一个任务列表文件,根据用户的原始任务目标生成一个合法的任务列表。返回创建结果与状态信息。',
|
|
98
|
-
parameters: {
|
|
99
|
-
type: 'object',
|
|
100
|
-
properties: {
|
|
101
|
-
userPrompt: {
|
|
102
|
-
type: 'string',
|
|
103
|
-
description: '用户的原始任务目标,用于生成任务列表',
|
|
104
|
-
},
|
|
105
|
-
},
|
|
106
|
-
required: ['userPrompt'],
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
type: 'function',
|
|
112
|
-
function: {
|
|
113
|
-
name: 'executeTaskList',
|
|
114
|
-
description:
|
|
115
|
-
'根据任务列表文件执行任务,按照预定义的执行规则处理每个任务的状态更新与结果记录。返回执行结果与状态信息。',
|
|
116
|
-
parameters: {
|
|
117
|
-
type: 'object',
|
|
118
|
-
properties: {
|
|
119
|
-
userPrompt: {
|
|
120
|
-
type: 'string',
|
|
121
|
-
description: '用户的原始需求,用于约束和校验任务执行方向',
|
|
122
|
-
},
|
|
123
|
-
},
|
|
124
|
-
required: ['userPrompt'],
|
|
125
|
-
},
|
|
126
|
-
},
|
|
127
|
-
},
|
|
128
|
-
{
|
|
129
|
-
type: 'function',
|
|
130
|
-
function: {
|
|
131
|
-
name: 'readTaskList',
|
|
132
|
-
description:
|
|
133
|
-
'读取任务列表并返回任务数组。读取以tmp_tasklist_开头的json文件,文件不存在或读取失败时返回空数组。',
|
|
134
|
-
parameters: {
|
|
135
|
-
type: 'object',
|
|
136
|
-
properties: {
|
|
137
|
-
taskListPath: {
|
|
138
|
-
type: 'string',
|
|
139
|
-
description:
|
|
140
|
-
'任务列表文件路径,以tmp_tasklist_开头的json文件',
|
|
141
|
-
},
|
|
142
|
-
},
|
|
143
|
-
required: ['taskListPath'],
|
|
144
|
-
},
|
|
145
|
-
},
|
|
146
|
-
},
|
|
147
|
-
{
|
|
148
|
-
type: 'function',
|
|
149
|
-
function: {
|
|
150
|
-
name: 'updateTaskList',
|
|
151
|
-
description:
|
|
152
|
-
'将完整任务数组写入任务列表文件。用于任务状态、备注、时间字段的持久化更新。返回true表示写入成功,写入失败会抛出错误。',
|
|
153
|
-
parameters: {
|
|
154
|
-
type: 'object',
|
|
155
|
-
properties: {
|
|
156
|
-
taskListPath: {
|
|
157
|
-
type: 'string',
|
|
158
|
-
description:
|
|
159
|
-
'任务列表文件路径,以tmp_tasklist_开头的json文件',
|
|
160
|
-
},
|
|
161
|
-
list: {
|
|
162
|
-
type: 'array',
|
|
163
|
-
description: '任务对象数组',
|
|
164
|
-
items: {
|
|
165
|
-
type: 'object',
|
|
166
|
-
},
|
|
167
|
-
},
|
|
168
|
-
},
|
|
169
|
-
required: ['taskListPath', 'list'],
|
|
170
|
-
},
|
|
171
|
-
},
|
|
172
|
-
},
|
|
173
|
-
{
|
|
174
|
-
type: 'function',
|
|
175
|
-
function: {
|
|
176
|
-
name: 'executeSubTaskFromTaskList',
|
|
177
|
-
description:
|
|
178
|
-
'启动子任务工作流执行单个子任务目标。subTaskGoalPrompt为子任务目标的提示词,传入“任务列表文件名称+当前进度+当前任务目标详细说明”。',
|
|
179
|
-
parameters: {
|
|
180
|
-
type: 'object',
|
|
181
|
-
properties: {
|
|
182
|
-
subTaskGoalPrompt: {
|
|
183
|
-
type: 'string',
|
|
184
|
-
description:
|
|
185
|
-
'子任务目标的详细描述,传入“任务列表文件名称+当前进度+当前任务目标详细说明”',
|
|
186
|
-
},
|
|
187
|
-
},
|
|
188
|
-
required: ['subTaskGoalPrompt'],
|
|
189
|
-
},
|
|
190
|
-
},
|
|
191
|
-
},
|
|
192
|
-
]
|
|
193
|
-
|
|
194
|
-
const functions = {
|
|
195
|
-
createTaskList,
|
|
196
|
-
executeTaskList,
|
|
197
|
-
readTaskList,
|
|
198
|
-
updateTaskList,
|
|
199
|
-
executeSubTaskFromTaskList,
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
const TaskTools = {
|
|
203
|
-
name: 'TaskTools',
|
|
204
|
-
extensionDescription:
|
|
205
|
-
'提供任务列表创建规则、执行规则、任务读写与子任务执行能力,支持基于tasklist的可追踪拆分执行流程',
|
|
206
|
-
descriptions,
|
|
207
|
-
functions,
|
|
208
|
-
isSystem: true
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
module.exports = TaskTools
|