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: -//