diff --git a/packages/core/src/__tests__/agent-system-prompt.test.ts b/packages/core/src/__tests__/agent-system-prompt.test.ts index 98b59a9..b9920f8 100644 --- a/packages/core/src/__tests__/agent-system-prompt.test.ts +++ b/packages/core/src/__tests__/agent-system-prompt.test.ts @@ -56,6 +56,7 @@ describe("buildAgentSystemPrompt", () => { expect(prompt).toContain("write_truth_file"); expect(prompt).toContain("rename_entity"); expect(prompt).toContain("patch_chapter_text"); + expect(prompt).toContain("edit"); expect(prompt).toContain("grep"); expect(prompt).toContain("ls"); }); @@ -66,7 +67,7 @@ describe("buildAgentSystemPrompt", () => { expect(prompt).toContain("write_truth_file"); expect(prompt).toContain("用户要求重写/精修已有章节"); expect(prompt).toContain("revise_chapter"); - expect(prompt).not.toContain("用户想做小修改(改名字、调设定)→ 用 edit 直接修改"); + expect(prompt).toContain("只有当上述专用工具都不适合"); }); it("Chinese prompt warns NOT to call architect", () => { diff --git a/packages/core/src/agent/agent-session.ts b/packages/core/src/agent/agent-session.ts index ebf2a83..bfec49f 100644 --- a/packages/core/src/agent/agent-session.ts +++ b/packages/core/src/agent/agent-session.ts @@ -240,6 +240,7 @@ export async function runAgentSession( createWriteTruthFileTool(pipeline, projectRoot, bookId), createRenameEntityTool(pipeline, projectRoot, bookId), createPatchChapterTextTool(pipeline, projectRoot, bookId), + createEditTool(projectRoot), createGrepTool(projectRoot), createLsTool(projectRoot), ], diff --git a/packages/core/src/agent/agent-system-prompt.ts b/packages/core/src/agent/agent-system-prompt.ts index f7e91aa..08e40e3 100644 --- a/packages/core/src/agent/agent-system-prompt.ts +++ b/packages/core/src/agent/agent-system-prompt.ts @@ -81,6 +81,7 @@ export function buildAgentSystemPrompt(bookId: string | null, language: string): - **write_truth_file** — 整文件覆盖真相文件(story_bible、volume_outline、book_rules、current_focus 等) - **rename_entity** — 统一改角色/实体名 - **patch_chapter_text** — 对已有章节做局部定点修补 +- **edit** — 通用精确字符串替换编辑(仅在专用 deterministic 工具都不适合时使用) - **grep** — 搜索内容(如"哪一章提到了某个角色") - **ls** — 列出文件或章节 @@ -92,6 +93,7 @@ export function buildAgentSystemPrompt(bookId: string | null, language: string): - 用户要求重写/精修已有章节 → 用 revise_chapter - 用户要求角色或实体改名 → 用 rename_entity - 用户要求对某一章做局部小修 → 用 patch_chapter_text +- 只有当上述专用工具都不适合,而且你已精确读取并定位文本时,才使用 edit - 其他情况 → 直接对话回答 - **注意:不要调用 architect,当前已有书籍,不需要建书** - **不要在回复中添加表情符号** @@ -128,6 +130,7 @@ export function buildAgentSystemPrompt(bookId: string | null, language: string): - **write_truth_file** — Replace a canonical truth file in story/ - **rename_entity** — Rename a character or entity across the book - **patch_chapter_text** — Apply a local deterministic patch to a chapter +- **edit** — Generic exact string replacement editor (use only when the dedicated deterministic tools do not fit) - **grep** — Search content across chapters - **ls** — List files or chapters @@ -139,6 +142,7 @@ export function buildAgentSystemPrompt(bookId: string | null, language: string): - Use revise_chapter for rewrite/polish/rework of existing chapters - Use rename_entity for character/entity renames - Use patch_chapter_text for local chapter fixes +- Use edit only as a last-resort generic editor after you have read the exact file content - Chat directly for other questions - **Do NOT call architect — a book already exists** - **Do NOT use emoji in your responses**