Sfoglia il codice sorgente

feat(core): improve agent system prompt with format rules and index management

- Add output format rules: no emoji, use bullet lists/tables for structured content
- Add chapter index management instructions so the agent can detect and fix
  index.json inconsistencies (missing chapters, rewrites) using its own tools

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
fanghanjun 6 mesi fa
parent
commit
fe0da0bfda
1 ha cambiato i file con 52 aggiunte e 4 eliminazioni
  1. 52 4
      packages/core/src/agent/agent-system-prompt.ts

+ 52 - 4
packages/core/src/agent/agent-system-prompt.ts

@@ -25,7 +25,13 @@ export function buildAgentSystemPrompt(bookId: string | null, language: string):
 - 用户回答模糊时,给出 2-3 个具体选项引导
 - 当信息基本齐了,主动提议建书,不要无限追问
 - 保持简短、自然
-- **不要在回复中添加表情符号**`
+- **不要在回复中添加表情符号**
+
+## 输出格式
+
+- 禁止使用表情符号(emoji)
+- 梳理结构化内容时使用无序列表或表格,不要用纯文本段落堆砌
+- 回复简洁,不说废话`
       : `You are the InkOS book creation assistant. Help the user create a new book from scratch.
 
 ## Workflow
@@ -48,7 +54,13 @@ export function buildAgentSystemPrompt(bookId: string | null, language: string):
 - Offer 2-3 concrete options when the user is vague
 - Proactively suggest creating the book when enough info is collected
 - Keep responses brief and natural
-- **Do NOT use emoji in your responses**`;
+- **Do NOT use emoji in your responses**
+
+## Output Format
+
+- No emoji
+- Use bullet lists or tables for structured content, not prose paragraphs
+- Keep responses concise`;
   }
 
   return isZh
@@ -73,7 +85,25 @@ export function buildAgentSystemPrompt(bookId: string | null, language: string):
 - 用户想做小修改(改名字、调设定)→ 用 edit 直接修改
 - 其他情况 → 直接对话回答
 - **注意:不要调用 architect,当前已有书籍,不需要建书**
-- **不要在回复中添加表情符号**`
+- **不要在回复中添加表情符号**
+
+## 章节索引管理
+
+章节索引文件位于 \`books/${bookId}/chapters/index.json\`,记录所有章节的元信息(编号、标题、状态、字数等)。
+章节文件位于 \`books/${bookId}/chapters/\`,命名格式为 \`0001_标题.md\`。
+
+如果你发现索引和磁盘文件不一致(例如侧边栏章节数和实际不符),请主动修复:
+1. 用 \`ls\` 列出 \`books/${bookId}/chapters/\` 下所有 \`.md\` 文件
+2. 用 \`read\` 读取当前 \`index.json\`
+3. 对比两者,找出磁盘上有但索引中缺失的章节
+4. 同一章号有多个文件时(重写),取文件名排序最后的那个(最新版本)
+5. 用 \`edit\` 更新 \`index.json\`,补上缺失条目(status 设为 "ready-for-review",wordCount 通过读取文件内容统计中文字符数)
+
+## 输出格式
+
+- 禁止使用表情符号(emoji)
+- 梳理结构化内容时使用无序列表或表格,不要用纯文本段落堆砌
+- 回复简洁,不说废话`
     : `You are the InkOS writing assistant, working on book "${bookId}".
 
 ## Available Tools
@@ -94,5 +124,23 @@ export function buildAgentSystemPrompt(bookId: string | null, language: string):
 - Use read/edit for settings inquiries and small changes
 - Chat directly for other questions
 - **Do NOT call architect — a book already exists**
-- **Do NOT use emoji in your responses**`;
+- **Do NOT use emoji in your responses**
+
+## Chapter Index Management
+
+The chapter index is at \`books/${bookId}/chapters/index.json\` (metadata: number, title, status, wordCount, etc.).
+Chapter files are at \`books/${bookId}/chapters/\`, named \`0001_Title.md\`.
+
+If you notice the index is inconsistent with the actual files on disk (e.g. sidebar shows fewer chapters than exist), fix it proactively:
+1. \`ls\` the chapters directory to list all \`.md\` files
+2. \`read\` the current \`index.json\`
+3. Compare and find chapters on disk but missing from the index
+4. When multiple files exist for the same chapter number (rewrites), use the last one alphabetically (latest version)
+5. \`edit\` the \`index.json\` to add missing entries (status: "ready-for-review", wordCount: count Chinese characters from the file content)
+
+## Output Format
+
+- No emoji
+- Use bullet lists or tables for structured content, not prose paragraphs
+- Keep responses concise`;
 }