diff --git a/app/config.example.yml b/app/config.example.yml index c3217e3..04a87e3 100644 --- a/app/config.example.yml +++ b/app/config.example.yml @@ -7,7 +7,7 @@ platforms: [] # 模型 profile:prompt + tools 白名单组合,模型用 profile: <名> 引用(不配 = 全量)。 model_profiles: mini: # 小模型:只留核心工具,省上下文 - tools_allow: [read_file, write_file, edit_file, list_directory, terminal, fetch, web_search, get_skill_info, run_skill] + tools_allow: [read_file, write_file, edit_file, terminal, fetch, web_search, get_skill_info, run_skill] system_prompt_file: mini-system.txt # 相对 server/templates/(也接受绝对路径) zero: # 纯文本对话:一个工具都不发 tools_allow: [] diff --git a/app/package-lock.json b/app/package-lock.json index 9bd0f7b..69a4186 100644 --- a/app/package-lock.json +++ b/app/package-lock.json @@ -11,7 +11,6 @@ "better-sqlite3": "11.3.0", "cron-parser": "5.10.1", "express": "4.21.2", - "minimatch": "9.0.5", "multer": "1.4.5-lts.1", "sharp": "0.35.4", "yaml": "2.6.1" @@ -552,12 +551,6 @@ "integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==", "license": "MIT" }, - "node_modules/balanced-match": { - "version": "1.0.2", - "resolved": "http://mirrors.tencentyun.com/npm/balanced-match/-/balanced-match-1.0.2.tgz", - "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", - "license": "MIT" - }, "node_modules/base64-js": { "version": "1.5.1", "resolved": "http://mirrors.tencentyun.com/npm/base64-js/-/base64-js-1.5.1.tgz", @@ -646,15 +639,6 @@ "npm": "1.2.8000 || >= 1.4.16" } }, - "node_modules/brace-expansion": { - "version": "2.1.4", - "resolved": "http://mirrors.tencentyun.com/npm/brace-expansion/-/brace-expansion-2.1.4.tgz", - "integrity": "sha512-hGfVzPxthbf3+2yjg/RBs60cB0FhqBS/zvdV/4wn4/BmN0bNMMHPc4V/BbFieqf1TKAGGAHnY4eSjajCl0f2Xg==", - "license": "MIT", - "dependencies": { - "balanced-match": "^1.0.0" - } - }, "node_modules/buffer": { "version": "5.7.1", "resolved": "http://mirrors.tencentyun.com/npm/buffer/-/buffer-5.7.1.tgz", @@ -1306,21 +1290,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/minimatch": { - "version": "9.0.5", - "resolved": "http://mirrors.tencentyun.com/npm/minimatch/-/minimatch-9.0.5.tgz", - "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", - "license": "ISC", - "dependencies": { - "brace-expansion": "^2.0.1" - }, - "engines": { - "node": ">=16 || 14 >=14.17" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, "node_modules/minimist": { "version": "1.2.8", "resolved": "http://mirrors.tencentyun.com/npm/minimist/-/minimist-1.2.8.tgz", diff --git a/app/package.json b/app/package.json index a166aac..5761a34 100644 --- a/app/package.json +++ b/app/package.json @@ -1,6 +1,6 @@ { "name": "agent-app", - "version": "2.1.0", + "version": "2.2.0", "description": "自用通用 Agent 系统:多模型调度 + 任务目录 + 工具调用 + H5 Web UI", "main": "server/server.js", "scripts": { @@ -11,7 +11,6 @@ "better-sqlite3": "11.3.0", "cron-parser": "5.10.1", "express": "4.21.2", - "minimatch": "9.0.5", "multer": "1.4.5-lts.1", "sharp": "0.35.4", "yaml": "2.6.1" diff --git a/app/server/config.js b/app/server/config.js index 1b6c021..1a362ba 100644 --- a/app/server/config.js +++ b/app/server/config.js @@ -86,7 +86,7 @@ const DEFAULTS = { model_profiles: { // 小模型:只留文件/终端/网页等核心工具,省上下文。 mini: { - tools_allow: ['read_file', 'write_file', 'edit_file', 'list_directory', 'terminal', 'fetch', 'web_search', 'get_skill_info', 'run_skill'], + tools_allow: ['read_file', 'write_file', 'edit_file', 'terminal', 'fetch', 'web_search', 'get_skill_info', 'run_skill'], system_prompt_file: 'mini-system.txt', }, // 纯文本对话:一个工具都不发。 diff --git a/app/server/routes/system.js b/app/server/routes/system.js index 96dcebf..2362850 100644 --- a/app/server/routes/system.js +++ b/app/server/routes/system.js @@ -15,7 +15,7 @@ const router = express.Router(); const STARTED_AT = Date.now(); // 版本以本文件字面量为准:容器部署只挂载 app/server,镜像里的 package.json 可能是旧的, // 读它会一直显示发版时的版本号(之前 2.1.0 改完仍显 2.0.0 即此因)。发版时记得同步这里。 -const VERSION = '2.1.0'; +const VERSION = '2.2.0'; // git 提交号单独返回(提交时 post-commit 钩子自动生成),前端只显示简洁版本号 const VERSION_COMMIT = versionInfo.commit || ''; diff --git a/app/server/templates/mini-system.txt b/app/server/templates/mini-system.txt index e3fc43d..e0b6602 100644 --- a/app/server/templates/mini-system.txt +++ b/app/server/templates/mini-system.txt @@ -47,7 +47,7 @@ For out-of-scope requests: state the limit in one or two sentences, don't over-a ## Files - Work inside the working directory. Use clear file names. -- Uploaded files are in the working directory; check with `list_directory`. +- Uploaded files are in the working directory; check with `terminal` (e.g. `ls`). ## Completion diff --git a/app/server/templates/system-prompt.txt b/app/server/templates/system-prompt.txt index 0930334..d63a9dc 100644 --- a/app/server/templates/system-prompt.txt +++ b/app/server/templates/system-prompt.txt @@ -61,7 +61,7 @@ You are a file / data / information processing assistant. The environment expose ## File Management - Work inside the working directory. Use clear file names. -- Uploaded files appear in the working directory; check with `list_directory` if needed. +- Uploaded files appear in the working directory; check with `terminal` (e.g. `ls`) if needed. ## External Services diff --git a/app/server/tools/definitions.json b/app/server/tools/definitions.json index 5cf4fc4..5da5108 100644 --- a/app/server/tools/definitions.json +++ b/app/server/tools/definitions.json @@ -1,59 +1,4 @@ [ - { - "type": "function", - "function": { - "name": "copy_path", - "description": "Copies a file or directory to a new location, preserving the original. Directories are copied recursively.\n\nUse this tool when you need to duplicate a file or directory without modifying the original. It is more efficient than reading and writing contents manually. Returns confirmation on success.", - "parameters": { - "type": "object", - "required": ["source_path", "destination_path"], - "properties": { - "source_path": { - "type": "string", - "description": "Path of the file or directory to copy, relative to the session working directory. Absolute paths are also accepted." - }, - "destination_path": { - "type": "string", - "description": "Destination path where the copy should be placed, relative to the session working directory. Absolute paths are also accepted." - } - } - } - } - }, - { - "type": "function", - "function": { - "name": "create_directory", - "description": "Creates a new directory (and any missing parent directories) at the specified path. Returns confirmation on success.", - "parameters": { - "type": "object", - "required": ["path"], - "properties": { - "path": { - "type": "string", - "description": "Path of the directory to create, relative to the session working directory. Absolute paths are also accepted." - } - } - } - } - }, - { - "type": "function", - "function": { - "name": "delete_path", - "description": "Deletes a file or directory (recursively) at the specified path. Returns confirmation on success.", - "parameters": { - "type": "object", - "required": ["path"], - "properties": { - "path": { - "type": "string", - "description": "Path of the file or directory to delete, relative to the session working directory. Absolute paths are also accepted." - } - } - } - } - }, { "type": "function", "function": { @@ -106,78 +51,6 @@ } } }, - { - "type": "function", - "function": { - "name": "find_path", - "description": "Finds file paths matching a glob pattern.\n\n- Supports patterns like \"**/*.js\" or \"src/**/*.ts\".\n- Returns matching paths sorted alphabetically.\n- Use `grep` instead when searching for file contents.\n- Results are paginated (50 per page); use `offset` to get more.", - "parameters": { - "type": "object", - "required": ["glob"], - "properties": { - "glob": { - "type": "string", - "description": "Glob pattern to match against file paths, relative to the session working directory." - }, - "offset": { - "type": "integer", - "description": "Optional starting position for paginated results (0-based). Defaults to 0.", - "default": 0, - "minimum": 0 - } - } - } - } - }, - { - "type": "function", - "function": { - "name": "grep", - "description": "Searches file contents using a regular expression.\n\n- Prefer this tool when looking for symbols or text inside files, rather than guessing paths.\n- Supports full regex syntax.\n- Use `include_pattern` to limit which files are searched.\n- Results are paginated (20 per page); use `offset` for more.\n- Do not use HTML entities to escape characters.", - "parameters": { - "type": "object", - "required": ["regex"], - "properties": { - "regex": { - "type": "string", - "description": "Regular expression pattern to search for. Matches against file contents only." - }, - "include_pattern": { - "type": "string", - "nullable": true, - "description": "Optional glob pattern to filter which files are searched (e.g., \"**/*.py\"). If omitted, all files are searched." - }, - "offset": { - "type": "integer", - "description": "Optional starting position for paginated results (0-based). Defaults to 0.", - "default": 0, - "minimum": 0 - }, - "case_sensitive": { - "type": "boolean", - "description": "Whether the search is case-sensitive. Defaults to false (case-insensitive).", - "default": false - } - } - } - } - }, - { - "type": "function", - "function": { - "name": "list_directory", - "description": "Lists files and directories in a given path.\n\nUse this to see the contents of a directory. For searching by name or content, prefer `find_path` or `grep`.", - "parameters": { - "type": "object", - "properties": { - "path": { - "type": "string", - "description": "Path of the directory to list, relative to the session working directory. Absolute paths are also accepted. If empty or omitted, lists the current working directory (like `ls` with no argument)." - } - } - } - } - }, { "type": "function", "function": { @@ -195,27 +68,6 @@ } } }, - { - "type": "function", - "function": { - "name": "move_path", - "description": "Moves or renames a file or directory, and returns confirmation that the move succeeded. If source and destination are in the same directory but with different names, this acts as a rename.", - "parameters": { - "type": "object", - "required": ["source_path", "destination_path"], - "properties": { - "source_path": { - "type": "string", - "description": "Path of the file or directory to move or rename, relative to the session working directory. Absolute paths are also accepted." - }, - "destination_path": { - "type": "string", - "description": "Destination path after the move/rename, relative to the session working directory. Absolute paths are also accepted." - } - } - } - } - }, { "type": "function", "function": { @@ -314,7 +166,7 @@ "type": "function", "function": { "name": "write_file", - "description": "Creates a new file or overwrites an existing file with the given content.\n\nUse `edit_file` for targeted changes to existing files. Before creating a new file, verify the parent directory exists with `list_directory`.", + "description": "Creates a new file or overwrites an existing file with the given content.\n\nUse `edit_file` for targeted changes to existing files. Parent directories are created automatically as needed.", "parameters": { "type": "object", "required": ["path", "content"], diff --git a/app/server/tools/executor.js b/app/server/tools/executor.js index 3c6d043..f996e87 100644 --- a/app/server/tools/executor.js +++ b/app/server/tools/executor.js @@ -4,20 +4,12 @@ const fs = require('fs'); const path = require('path'); const fsp = require('fs').promises; const { spawn } = require('child_process'); -const { Minimatch } = require('minimatch'); const mcp = require('../mcp'); const skills = require('./skills'); const rexec = require('../remote-exec'); const publicFiles = require('../public-files'); const scheduler = require('../scheduler'); // 只依赖 log/cron-parser,不成环(engine→executor→scheduler 单向) -function makeMatcher(pattern, opts) { - const mm = new Minimatch(pattern, opts || {}); - return function (p) { return mm.match(p); }; -} - -const IGNORED_DIRS = new Set(['.git', 'node_modules', '__pycache__', '.venv', 'venv', 'dist', 'build', '.next', '.cache']); - // ---------- 路径沙箱 ---------- function resolveInTask(taskDir, p) { if (typeof p !== 'string' || !p.trim()) throw new Error('路径不能为空'); @@ -38,29 +30,6 @@ function relOf(taskDir, abs) { return path.relative(path.resolve(taskDir), abs) || '.'; } -// ---------- 文件系统遍历 ---------- -function walk(taskDir, opts) { - const out = []; - const maxFiles = (opts && opts.maxFiles) || 20000; - function rec(dir) { - let entries; - try { entries = fs.readdirSync(dir, { withFileTypes: true }); } catch (_) { return; } - for (const ent of entries) { - if (out.length >= maxFiles) return; - if (ent.name.startsWith('.') && IGNORED_DIRS.has(ent.name)) continue; - if (IGNORED_DIRS.has(ent.name)) continue; - const abs = path.join(dir, ent.name); - if (ent.isDirectory()) { - rec(abs); - } else if (ent.isFile()) { - out.push(abs); - } - } - } - rec(taskDir); - return out; -} - function isProbablyBinary(abs) { let fd; try { @@ -185,7 +154,7 @@ async function toolReadFile(ctx, args) { let st; try { st = await fsp.stat(abs); } catch (_) { throw new Error('文件不存在:' + args.path); } - if (st.isDirectory()) throw new Error(args.path + ' 是目录不是文件,请用 list_directory 工具查看目录内容。'); + if (st.isDirectory()) throw new Error(args.path + ' 是目录不是文件,请用 terminal 执行 ls 查看目录内容。'); if (IMAGE_EXTS.has(path.extname(abs).toLowerCase())) { const rel = relOf(ctx.taskDir, abs); if (!ctx.vision) { @@ -439,131 +408,6 @@ async function toolEditFile(ctx, args) { return '已成功应用 ' + applied + ' 处编辑到 ' + relOf(ctx.taskDir, abs); } -// 对齐 Zed list_directory 的输出格式: -// # Folders: -// / -// -// # Files: -// / -// 条目为相对任务目录的完整路径(不带尾部斜杠),目录/文件分节、各自排序,空节省略。 -async function toolListDirectory(ctx, args) { - // 对齐 ls 语义:path 缺省或为空字符串时等同于当前目录(任务目录)。 - const p = typeof args.path === 'string' && args.path.trim() ? args.path : '.'; - const abs = resolveInTask(ctx.taskDir, p); - const entries = await fsp.readdir(abs, { withFileTypes: true }); - const rel = relOf(ctx.taskDir, abs); - const dirs = []; const files = []; - for (const e of entries) { - const full = rel === '.' ? e.name : rel + '/' + e.name; - if (e.isDirectory()) dirs.push(full); - else files.push(full); - } - dirs.sort(); files.sort(); - const total = dirs.length + files.length; - if (total === 0) return 'Directory is empty'; - const shownDirs = dirs.slice(0, 500); - const shownFiles = files.slice(0, 500 - shownDirs.length); - const sections = []; - if (shownDirs.length) sections.push('# Folders:\n' + shownDirs.join('\n')); - if (shownFiles.length) sections.push('# Files:\n' + shownFiles.join('\n')); - let out = sections.join('\n\n'); - if (shownDirs.length + shownFiles.length < total) out += '\n\n...(' + total + ' entries total, truncated)'; - return out; -} - -async function toolCreateDirectory(ctx, args) { - const abs = resolveInTask(ctx.taskDir, args.path); - await fsp.mkdir(abs, { recursive: true }); - return '已创建目录 ' + relOf(ctx.taskDir, abs); -} - -async function toolDeletePath(ctx, args) { - const abs = resolveInTask(ctx.taskDir, args.path); - if (path.resolve(abs) === path.resolve(ctx.taskDir)) throw new Error('禁止删除任务目录本身'); - await fsp.rm(abs, { recursive: true, force: true }); - return '已删除 ' + relOf(ctx.taskDir, abs); -} - -async function toolMovePath(ctx, args) { - const src = resolveInTask(ctx.taskDir, args.source_path); - const dst = resolveInTask(ctx.taskDir, args.destination_path); - await fsp.mkdir(path.dirname(dst), { recursive: true }); - await fsp.rename(src, dst); - recordFile(ctx, dst); - return '已移动/重命名 ' + relOf(ctx.taskDir, src) + ' → ' + relOf(ctx.taskDir, dst); -} - -async function toolCopyPath(ctx, args) { - const src = resolveInTask(ctx.taskDir, args.source_path); - const dst = resolveInTask(ctx.taskDir, args.destination_path); - await fsp.mkdir(path.dirname(dst), { recursive: true }); - await fsp.cp(src, dst, { recursive: true }); - recordFile(ctx, dst); - return '已复制 ' + relOf(ctx.taskDir, src) + ' → ' + relOf(ctx.taskDir, dst); -} - -async function toolFindPath(ctx, args) { - const files = walk(ctx.taskDir).map(f => relOf(ctx.taskDir, f)).sort(); - // 对齐 Zed:空 glob 视为 *;不含 / 的裸模式按文件名匹配, - // 否则 schema 里 "*thing*.txt 匹配 directory1/a/something.txt" 的例子永远命不中。 - const glob = (args.glob || '').trim() || '*'; - const bare = !glob.includes('/'); - const matcher = makeMatcher(glob, { dot: true }); - const matched = files.filter(bare ? f => matcher(path.basename(f)) : matcher); - const offset = args.offset || 0; - const page = matched.slice(offset, offset + 50); - if (page.length === 0) return '没有匹配 ' + args.glob + ' 的路径'; - return page.join('\n') + '\n(共 ' + matched.length + ' 个匹配' + (offset + 50 < matched.length ? ',用 offset=' + (offset + 50) + ' 看下一页' : '') + ')'; -} - -async function toolGrep(ctx, args) { - let re; - try { re = new RegExp(args.regex, args.case_sensitive ? '' : 'i'); } catch (e) { - return '正则解析失败:' + e.message; - } - const pattern = args.include_pattern ? makeMatcher(args.include_pattern, { dot: false }) : null; - const files = walk(ctx.taskDir); - // 对齐 Zed:分页单位是“片段”(匹配行 ±2 行上下文,相邻匹配合并),而非单行。 - const SNIPPET_CAP = 200; // 防止病态全仓匹配撞大内存 - const snippets = []; - let capped = false; - outer: - for (const abs of files) { - const rel = relOf(ctx.taskDir, abs); - if (pattern && !pattern(rel)) continue; - if (isProbablyBinary(abs)) continue; - let text; - try { text = await fsp.readFile(abs, 'utf8'); } catch (_) { continue; } - if (text.length > 2 * 1024 * 1024) continue; - const lines = text.split('\n'); - let cur = null; - for (let i = 0; i < lines.length; i++) { - re.lastIndex = 0; - if (!re.test(lines[i])) continue; - if (cur && i <= cur.end) { if (i + 2 > cur.end) cur.end = Math.min(lines.length - 1, i + 2); continue; } - if (cur) snippets.push(cur); - if (snippets.length >= SNIPPET_CAP) { capped = true; cur = null; break outer; } - cur = { file: rel, lines, start: Math.max(0, i - 2), end: Math.min(lines.length - 1, i + 2) }; - } - if (cur) snippets.push(cur); - } - const offset = args.offset || 0; - const page = snippets.slice(offset, offset + 20); - if (page.length === 0) return '没有匹配'; - let outText = ''; - let lastFile = null; - for (const s of page) { - if (s.file !== lastFile) { outText += '\n## ' + s.file + ' 中的匹配\n'; lastFile = s.file; } - const label = s.start === s.end ? 'L' + (s.start + 1) : 'L' + (s.start + 1) + '-' + (s.end + 1); - outText += '\n### ' + label + '\n```\n' + s.lines.slice(s.start, s.end + 1).join('\n') + '\n```\n'; - } - const more = capped || offset + 20 < snippets.length; - const header = more - ? '显示匹配 ' + (offset + 1) + '-' + (offset + page.length) + '(还有更多,用 offset=' + (offset + 20) + ' 看下一页):\n' - : '共找到 ' + snippets.length + ' 处匹配:\n'; - return header + outText; -} - // 对齐 Zed select_terminal_output_lines:head/tail 各自取行;同时给时中间空一行;不去重叠;0 合法。 function selectOutput(text, head, tail) { const hasH = typeof head === 'number' && isFinite(head); @@ -755,14 +599,7 @@ const HANDLERS = { read_file: toolReadFile, write_file: toolWriteFile, edit_file: toolEditFile, - list_directory: toolListDirectory, mint_public_link: toolMintPublicLink, - create_directory: toolCreateDirectory, - delete_path: toolDeletePath, - move_path: toolMovePath, - copy_path: toolCopyPath, - find_path: toolFindPath, - grep: toolGrep, terminal: toolTerminal, fetch: toolFetch, schedule_task: toolScheduleTask, diff --git a/app/test/smoke.js b/app/test/smoke.js index 92acf20..f6194ea 100644 --- a/app/test/smoke.js +++ b/app/test/smoke.js @@ -205,7 +205,7 @@ async function main() { const pool = await api('GET', '/api/models'); ok(pool.length === 2, '模型池数量', JSON.stringify(pool)); - // ---- 8. 工具单元:terminal 超时 + grep ---- + // ---- 8. 工具单元:terminal 超时 ---- console.log('\n[7] terminal 超时'); const eng = require(path.join(ROOT, 'server/engine.js')); // engine 未在本进程初始化(服务在子进程),此处直接单测 executor @@ -223,10 +223,7 @@ async function main() { const toc = await executeTool(ctx, 'terminal', { command: 'echo hello-unit && pwd' }); ok(toc.includes('hello-unit') && toc.includes('exit code: '), 'terminal 正常执行', toc.slice(0, 120)); await executeTool(ctx, 'write_file', { path: 'g.txt', content: 'alpha\nbeta\n' }); - const gres = await executeTool(ctx, 'grep', { regex: 'et' }); - ok(gres.includes('beta'), 'grep 命中', gres); - const fpath = await executeTool(ctx, 'find_path', { glob: '*.txt' }); - ok(fpath.includes('g.txt'), 'find_path 命中', fpath); + const esc = await executeTool(ctx, 'read_file', { path: '../outside.txt' }).catch(e => 'ERR:' + e.message); ok(String(esc).includes('越界'), 'read_file 拒绝越界', String(esc)); // read_file 读图:非 vision → 文本提示;vision → {text, image_rel}(依赖 sharp;小图压缩无收益时 image_rel 直指原文件,不落 .imgcache) diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index f623ea8..55c4971 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -41,7 +41,7 @@ agent/ │ │ ├── balance.js 余额查询适配器(按 platform.type 分发) │ │ ├── version.js 版本信息(package.json + git 短提交号) │ │ ├── tools/ -│ │ │ ├── definitions.json 内置 17 个工具的 OpenAI function 格式定义 +│ │ │ ├── definitions.json 内置 10 个工具的 OpenAI function 格式定义 │ │ │ ├── executor.js 工具执行器(文件类 + terminal + skill 委托) │ │ │ └── skills.js Skill Manager(list/info/run + 路径预处理) │ │ ├── download-token.js 下载链接签名(浏览器原生下载用;密钥进程内随机) @@ -279,7 +279,7 @@ stateDiagram-v2 - session 补偿:MCP 规范的 `Mcp-Session-Id` 缓存在 `server.sessionId`;过期(400 + 含 "session" 字样)自动重 initialize 后重试一次。 - 某些老服务无 `initialize` → catch `Method not found` 不阻断。 -### 5.4 `tools/executor.js` —— 内置 17 工具的派发器 +### 5.4 `tools/executor.js` —— 内置 10 工具的派发器 `HANDLERS` 是 `name → async(ctx, args) → result` 的表;`executeTool(ctx, name, args)` 按 `name` 派发;**未知名直接转发给 MCP**(若 `mcp.hasTool(name)`,调 `mcp.callTool`)。 @@ -287,7 +287,7 @@ stateDiagram-v2 |---|---| | `read_file` | 走 `resolveInTask` 防路径穿越;图像(PNG/JPEG/WebP/GIF/BMP/TIFF)按 vision 能力走 `sharp` 压缩后落盘 `.imgcache/` 并回传 `image_rel`(长边 ≤ 2000px,JPEG q=80;文件名带源文件 mtime+size 指纹,重读复用不增殖;重编码无收益时不落盘、直指原文件),发送前由 `llm.buildMessages` 现签成公网外链(engine 侧 mint 前 realpath 复核);大文本/二进制给 outline;行号前缀格式 "`<6位右对齐行号>\\t<原文>`"(`edit_file` 用) | | `write_file` / `edit_file` | `edit_file` 用模糊定位(Zed 风格):先精确匹配,失败后用 Levenshtein DP 找最相似行;`old_text`/`new_text` 协议见 `definitions.json` | -| `list_directory` / `create_directory` / `delete_path` / `move_path` / `copy_path` / `find_path` / `grep` | 标准文件操作,全部 `resolveInTask` 约束;`grep` 走 `ripgrep`(`rg`)优先 | +| 已移除的工具 | `list_directory` / `create_directory` / `delete_path` / `move_path` / `copy_path` / `find_path` / `grep`:环境固定,文件操作与检索统一走 `terminal`(ls / mkdir / rm / mv / cp / find / rg),内置工具 17 → 10 | | `terminal` | **唯一一个走 executor 的内置工具**(当 `rexec.isRemote(cfg)`);本地分支用 `spawn` + `detached` + 进程组 kill;远端分支 `rexec.run` SSE 收流,结果套上超时/截断/取消注解后 `truncate(text, cfg.terminal.max_output_chars)` 返回 | | `fetch` | `AbortController` + UA + redirect + content-type 简单判断;HTML 用 `htmlToMarkdown` 转 | | `mint_public_link` | **唯一的 mint 入口**:与 core 同进程,直接 `publicFiles.mint()`,不绕任何 HTTP;`ctx.taskDir` 就是会话目录,`relOf` 的结果正是取用侧要的 `rel`。校验:`public_link.base_url` 已配 + `resolveInTask` 沙箱 + 确认是文件 + `realpath` 未沿符号链接跳出任务目录;返回单行 URL |