Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(cindy-tools,desktop): 分章投递的子代理复核修复三则 (#918)
张怡c30fcb62101f
diff --git a/apps/desktop/src/main/cindy-brain/__tests__/forge.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/forge.test.tsindex b5afff1242..6602769fcf 100644--- a/apps/desktop/src/main/cindy-brain/__tests__/forge.test.ts+++ b/apps/desktop/src/main/cindy-brain/__tests__/forge.test.ts@@ -362,6 +362,29 @@ describe('scaffoldGhostDir', () => {});describe('FORGE_GUIDE', () => {+ it('分章体量守卫:每个 ## 章节须留在单次工具结果安全体量内(#890 分章投递的不变量)', () => {+ // 手册"随主机版本演进"持续增长;任一章越过单次 MCP 结果上限会静默复现 #890 于该章。+ // 上限取 32KB:当前最大章 ~22KB,余量 ~45%,越线即该拆小节。+ const CHAPTER_BYTE_LIMIT = 32 * 1024;+ const sections = new Map<string, number>();+ let current = '(开场白)';+ let size = 0;+ for (const line of FORGE_GUIDE.split('\n')) {+ if (line.startsWith('## ')) {+ sections.set(current, size);+ current = line;+ size = 0;+ }+ size += Buffer.byteLength(line, 'utf8') + 1;+ }+ sections.set(current, size);+ for (const [header, bytes] of sections) {+ expect(bytes, `${header} 超出分章安全体量,请拆小节`).toBeLessThanOrEqual(+ CHAPTER_BYTE_LIMIT,+ );+ }+ });+it('手册覆盖关键章节(身份卡/工具面/管子/聊天卡片/订阅拦截/网络代发/系统提示/沙箱红线/打包)', () => {for (const marker of ['ghost.json',diff --git a/apps/desktop/src/main/cindy-brain/forge.ts b/apps/desktop/src/main/cindy-brain/forge.tsindex fd89982876..154a39e70d 100644--- a/apps/desktop/src/main/cindy-brain/forge.ts+++ b/apps/desktop/src/main/cindy-brain/forge.ts@@ -710,7 +710,8 @@ export const FORGE_GUIDE = `# 意识(Ghost)编写手册意识是 Cindy 的第三方能力包,文件形态是 \`.cindy\`(zip 包)。装入后可给主机叠加:AI 可调用的工具、常驻界面面板、模型代办能力。本手册教你(agent)替用户-写一个意识。**流程:读完本手册 → 在工作目录写源码文件 → ghost_forge_pack 打包 →+写一个意识。**流程:先取手册目录,按需用 section 读透相关章(动手前至少读完+"沙箱红线"与"打包与测试"两章) → 在工作目录写源码文件 → ghost_forge_pack 打包 →用户在弹窗上确认装入。**从零开始时优先调用 \`ghost_forge_scaffold\` 生成一份不会覆盖现有文件的骨架,再在diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.jsonindex c0e5a3d0de..f594d00792 100644--- a/apps/desktop/src/renderer/i18n/locales/en/common.json+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json@@ -2500,7 +2500,7 @@"addPlugin": "Add plugin","addPluginAria": "Plugin add options","createWithCindy": "Create with Cindy",- "createPrompt": "I want to create a Cindy plugin. First call ghost_forge_guide to read the full specification; do not start implementing yet. Begin by asking questions, focusing on one key decision at a time, and work with me to define the problem, target users, interaction flow, required tools and connections, permission boundaries, and acceptance criteria. After I confirm the design, implement and validate it according to the specification, then call ghost_forge_pack to package and install the plugin.",+ "createPrompt": "I want to create a Cindy plugin. First call ghost_forge_guide to get the handbook's table of contents, then read the relevant chapters via the section parameter (at minimum the sandbox red-lines and packaging chapters) before writing any code; do not start implementing yet. Begin by asking questions, focusing on one key decision at a time, and work with me to define the problem, target users, interaction flow, required tools and connections, permission boundaries, and acceptance criteria. After I confirm the design, implement and validate it according to the specification, then call ghost_forge_pack to package and install the plugin.","installedTitle": "Installed Plugins","installedExpand": "Show {{count}} more installed plugins","installedCollapse": "Hide additional installed plugins",diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.jsonindex 99bf937f93..4c80e7da36 100644--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json@@ -2499,7 +2499,7 @@"addPlugin": "プラグインを追加","addPluginAria": "プラグイン追加オプション","createWithCindy": "Cindy で作成",- "createPrompt": "Cindy プラグインを作成したいです。まず ghost_forge_guide を呼び出して完全な仕様を読み、すぐに実装を始めないでください。質問から始め、毎回一つの重要な判断に集中しながら、解決する課題、対象ユーザー、操作フロー、必要なツールと接続、権限の境界、受け入れ条件を段階的に確認してください。設計を確認した後、仕様に沿って実装と検証を行い、最後に ghost_forge_pack を呼び出してプラグインをパッケージ化し、インストールしてください。",+ "createPrompt": "Cindy プラグインを作成したいです。まず ghost_forge_guide を呼び出してハンドブックの目次を取得し、section パラメータで関連する章(少なくともサンドボックスの禁止事項とパッケージ化の章)を読み込んでから着手してください。すぐに実装を始めないでください。質問から始め、毎回一つの重要な判断に集中しながら、解決する課題、対象ユーザー、操作フロー、必要なツールと接続、権限の境界、受け入れ条件を段階的に確認してください。設計を確認した後、仕様に沿って実装と検証を行い、最後に ghost_forge_pack を呼び出してプラグインをパッケージ化し、インストールしてください。","installedTitle": "インストール済みプラグイン","installedExpand": "インストール済みプラグインをさらに {{count}} 件表示","installedCollapse": "追加のインストール済みプラグインを隠す",diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.jsonindex 95dc64ee37..0098e6aabf 100644--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json@@ -2499,7 +2499,7 @@"addPlugin": "플러그인 추가","addPluginAria": "플러그인 추가 옵션","createWithCindy": "Cindy로 만들기",- "createPrompt": "Cindy 플러그인을 만들고 싶습니다. 먼저 ghost_forge_guide를 호출해 전체 규격을 읽고 바로 구현을 시작하지 마세요. 질문부터 시작해 한 번에 하나의 핵심 결정에 집중하면서 해결할 문제, 대상 사용자, 상호작용 흐름, 필요한 도구와 연결, 권한 경계, 완료 기준을 단계적으로 확인해 주세요. 설계를 확인한 뒤 규격에 따라 구현하고 검증한 다음, 마지막으로 ghost_forge_pack을 호출해 플러그인을 패키징하고 설치해 주세요.",+ "createPrompt": "Cindy 플러그인을 만들고 싶습니다. 먼저 ghost_forge_guide를 호출해 핸드북 목차를 받은 뒤 section 매개변수로 관련 장(최소한 샌드박스 금지선과 패키징 장)을 읽고 나서 작업을 시작하세요. 바로 구현을 시작하지 마세요. 질문부터 시작해 한 번에 하나의 핵심 결정에 집중하면서 해결할 문제, 대상 사용자, 상호작용 흐름, 필요한 도구와 연결, 권한 경계, 완료 기준을 단계적으로 확인해 주세요. 설계를 확인한 뒤 규격에 따라 구현하고 검증한 다음, 마지막으로 ghost_forge_pack을 호출해 플러그인을 패키징하고 설치해 주세요.","installedTitle": "설치된 플러그인","installedExpand": "설치된 플러그인 {{count}}개 더 보기","installedCollapse": "추가 설치 플러그인 숨기기",diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.jsonindex 63179f4d02..7ff2f62064 100644--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json@@ -2499,7 +2499,7 @@"addPlugin": "添加插件","addPluginAria": "插件添加选项","createWithCindy": "使用 Cindy 创建",- "createPrompt": "我要创建一个 Cindy 插件。请先调用 ghost_forge_guide 读取完整规范,不要直接开始实现。先从提问开始,每次聚焦一个关键决策,与我逐步确认插件要解决的问题、目标用户、交互流程、所需工具与连接、权限边界和验收标准。设计确认后,再按规范实现并自检;最后调用 ghost_forge_pack 打包并安装插件。",+ "createPrompt": "我要创建一个 Cindy 插件。请先调用 ghost_forge_guide 获取手册目录,再用 section 参数读透相关章节(动手前至少读完沙箱红线与打包流程两章),不要直接开始实现。先从提问开始,每次聚焦一个关键决策,与我逐步确认插件要解决的问题、目标用户、交互流程、所需工具与连接、权限边界和验收标准。设计确认后,再按规范实现并自检;最后调用 ghost_forge_pack 打包并安装插件。","installedTitle": "已安装的插件","installedExpand": "展开另外 {{count}} 个已安装插件","installedCollapse": "收起其他已安装插件",diff --git a/packages/cindy-tools/src/__tests__/ghostMcp.test.ts b/packages/cindy-tools/src/__tests__/ghostMcp.test.tsindex cd40a6be8f..664adb24ac 100644--- a/packages/cindy-tools/src/__tests__/ghostMcp.test.ts+++ b/packages/cindy-tools/src/__tests__/ghostMcp.test.ts@@ -938,6 +938,19 @@ describe("cindy_ghosts · ghost_forge(锻造)", () => {const sectionedDeps = () =>fakeDeps({ forgeGuide: async () => SECTIONED_GUIDE });+ it("forge_guide 手册以 ## 直接开头(无 H1 开场白)时目录不吞第一章正文", async () => {+ const noPreamble = ["## 1. 起步", "one-body", "## 2. 进阶", "two-body"].join("\n");+ const result = await handleForgeGuide(+ fakeDeps({ forgeGuide: async () => noPreamble }),+ );+ const text = result.content[0].text;+ expect(result.isError).toBeUndefined();+ expect(text).toContain("- 1. 起步");+ expect(text).toContain("- 2. 进阶");+ expect(text).not.toContain("one-body");+ expect(text).not.toContain("two-body");+ });+it("forge_guide 无参返回目录:含开场白与全部章节标题,不含章节正文", async () => {const result = await handleForgeGuide(sectionedDeps());const text = result.content[0].text;diff --git a/packages/cindy-tools/src/ghost/forgeGuideSections.ts b/packages/cindy-tools/src/ghost/forgeGuideSections.tsindex fb3a655eb8..3aa7755a19 100644--- a/packages/cindy-tools/src/ghost/forgeGuideSections.ts+++ b/packages/cindy-tools/src/ghost/forgeGuideSections.ts@@ -45,8 +45,11 @@ function headerTitle(header: string): string {export function buildForgeGuideToc(guide: string): string {const headers = headerLines(guide);if (headers.length === 0) return guide;- const firstHeaderAt = guide.indexOf(`\n${HEADER_PREFIX}`);- const preamble = firstHeaderAt >= 0 ? guide.slice(0, firstHeaderAt).trimEnd() : "";+ // 开场白边界与章节识别走同一通道(逐行 startsWith),避免手册以 ## 开头时+ // indexOf("\n## ") 命中第二章、把第一章整段吞进目录+ const lines = guide.split("\n");+ const firstHeaderLine = lines.findIndex((l) => l.startsWith(HEADER_PREFIX));+ const preamble = lines.slice(0, firstHeaderLine).join("\n").trimEnd();return [...(preamble ? [preamble, ""] : []),"## 目录",