From 103725e652149cff8ce7073db7ce004f06a43782 Mon Sep 17 00:00:00 2001 From: hc Date: Fri, 10 Apr 2026 21:07:56 +0800 Subject: [PATCH] =?UTF-8?q?feat(PHASE-06):=20=E6=9C=80=E5=B0=8F=20Edit=20?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=20+=20=E5=B7=A5=E5=85=B7=E4=BC=98=E5=85=88?= =?UTF-8?q?=E7=BA=A7=E4=BC=98=E5=8C=96=EF=BC=88=E4=BF=AE=E6=94=B9=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=9C=BA=E6=99=AF=E5=A4=A7=E5=B9=85=E6=8F=90=E5=8D=87?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AGENTS.md | 5 +++-- SKILLS/cli-core.md | 1 + src/cc_slim/tools.py | 27 +++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index a360984..aab152d 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -38,9 +38,10 @@ - `Read`:用于读取文件内容。 - `Glob`:用于按模式查找文件。 -- 创建或覆盖文件时,优先使用 `Write` 工具。 +- 修改已有文件内容时,优先使用 `Edit` 工具。 +- 创建新文件时,优先使用 `Write` 工具。 - `Bash`:用于执行必须通过 shell 完成的最小命令。 -- 只有在 Bash 确实必要时才使用 Bash。 +- 只有在确实需要 shell 特性时才使用 Bash。 - 不要用 Bash 拼接文件内容。 - Windows 环境下优先使用兼容写法,不默认使用 `cat < list[Tool]: }, execute=lambda data: glob_tool(workspace, data), ), + Tool( + name="Edit", + description="覆盖已有文本文件的完整内容。", + input_schema={ + "type": "object", + "properties": { + "path": {"type": "string", "description": "相对工作区的文件路径"}, + "content": {"type": "string", "description": "替换后的完整文件内容"}, + "encoding": {"type": "string", "description": "文件编码,默认 utf-8"}, + }, + "required": ["path", "content"], + "additionalProperties": False, + }, + execute=lambda data: edit_tool(workspace, data), + ), Tool( name="Write", description="创建或覆盖工作区内的文本文件。", @@ -97,6 +112,18 @@ def glob_tool(workspace: Path, data: dict[str, Any]) -> str: return "\n".join(matches[:200]) +def edit_tool(workspace: Path, data: dict[str, Any]) -> str: + path = _safe_path(workspace, str(data["path"])) + if not path.exists(): + return f"文件不存在: {path.relative_to(workspace)}" + if path.is_dir(): + return f"目标是目录,不能编辑文件: {path.relative_to(workspace)}" + + encoding = str(data.get("encoding") or "utf-8") + path.write_text(str(data["content"]), encoding=encoding) + return f"已修改文件: {path.relative_to(workspace)}" + + def write_tool(workspace: Path, data: dict[str, Any]) -> str: path = _safe_path(workspace, str(data["path"])) if path.exists() and path.is_dir():