diff --git a/.codex/skills/genarrative-external-editor-api/SKILL.md b/.codex/skills/genarrative-external-editor-api/SKILL.md index e6a9f55e7..e4bbafbc2 100644 --- a/.codex/skills/genarrative-external-editor-api/SKILL.md +++ b/.codex/skills/genarrative-external-editor-api/SKILL.md @@ -32,6 +32,7 @@ Prefer `scripts/genarrative_external_api.py` for runnable REST calls. It uses on - Use stable references such as `objectKey`, project resource ID, or asset ID where each operation permits them. Image edit/redraw is stricter: `sourceReferenceId` accepts only a registered project resource ID or asset ID; upload confirmation alone is not enough. Use `/assets/read-url` only for temporary preview/download access. - Preserve both warning channels after completion. A general `warning` can coexist with `sliceWarning`; do not discard either. - Do not invent missing derivatives. A source-preserved warning means the main source remains usable but requested post-processing failed. A slice warning means the complete transparent sheet is usable but individual slices are absent. +- Icon spritesheet generation accepts `sliceMode="connected-components"` (default alpha-connectivity detection) or `sliceMode="grid"`. Grid mode requires `gridX` and `gridY` (1-32); use `sliceCount` only to constrain connected-component output. - For successful `style="pixelArt"`, treat completed-result and nested resource/asset dimensions as the final logical-grid PNG dimensions. They may differ from `size`, `imageSize`, the provider image, and `canvasCompletion.placeholder`; do not rescale or reject the artifact to match those inputs. - Keep generated artifacts in the canvas and asset library together. Character animation accepts `assetFolderId` and `assetLabel`; its completed result directly returns the final `assetKind="character-animation"` resource and asset with formal sequence fields. Do not create a duplicate first-frame record. diff --git a/.codex/skills/genarrative-external-editor-api/references/api-operations.md b/.codex/skills/genarrative-external-editor-api/references/api-operations.md index 909174e47..a744d8589 100644 --- a/.codex/skills/genarrative-external-editor-api/references/api-operations.md +++ b/.codex/skills/genarrative-external-editor-api/references/api-operations.md @@ -52,7 +52,7 @@ Every generation row requires a stable `Idempotency-Key` header and returns HTTP | Image generation | `/api/external/v1/editor/images/generations` | `prompt` | `kind`, `style`, `model`, `aspectRatio`, `imageSize`, `size`, `referenceImageSrcs`, `projectId`, `assetFolderId`, `assetLabel`, `canvasCompletion`, `generationInputs` | | Image edit/redraw | `/api/external/v1/editor/images/edits` | `prompt`, `sourceReferenceId` | `referenceImageSrcs`, `model`, `size`, `projectId`, `assetFolderId`, `assetLabel`, `targetLayerId`, `canvasCompletion` | | Background removal | `/api/external/v1/editor/images/background-removals` | `sourceImageSrc` | `projectId`, `sourceResourceId`, `targetLayerId`, static-image `assetKind`, `assetFolderId`, `assetLabel`, `canvasCompletion`, `generationInputs` | -| Icon spritesheet | `/api/external/v1/editor/icon-spritesheets/generations` | `referenceId`, `iconDescriptions` | `sliceLayout`, `style`, `referenceImageSrcs`, `screenColor`, `model`, `aspectRatio`, `imageSize`, `projectId`, `assetFolderId`, `assetLabel`, `canvasCompletion` | +| Icon spritesheet | `/api/external/v1/editor/icon-spritesheets/generations` | `referenceId`, `iconDescriptions` | `sliceMode`, `gridX`, `gridY`, `sliceCount`, `style`, `referenceImageSrcs`, `screenColor`, `model`, `aspectRatio`, `imageSize`, `projectId`, `assetFolderId`, `assetLabel`, `canvasCompletion` | | UI asset extraction | `/api/external/v1/editor/ui-designs/assets/extractions` | `sourceImageSrc`, `aspectRatio`, `imageSize` | `screenColor`, `model`, `referenceImageSrcs`, `projectId`, `assetFolderId`, `spritesheetLabel`, `canvasCompletion` | | Character animation | `/api/external/v1/editor/character-animations/generations` | `sourceLayerId`, `sourceImageSrc`, `sourceWidth`, `sourceHeight`, `promptText`, `resolution`, `ratio`, `frameCount`, `durationSeconds`, `model` | `projectId`, `sourceResourceId`, `assetFolderId`, `assetLabel`, `canvasCompletion` | | Video generation | `/api/external/v1/editor/videos/generations` | `prompt`, `model`, `aspectRatio`, `durationSeconds`, `resolution`, `mode`, `sound` | `referenceImageSrcs`, `referenceVideoSrcs`, `referenceAudioSrcs`, `webSearchEnabled`, `projectId`, `assetFolderId`, `assetLabel`, `canvasCompletion` | @@ -94,7 +94,7 @@ For image edit/redraw, confirming an upload is not sufficient: create a project The icon-spritesheet primary `referenceId` is intentionally stricter than ordinary image references: it accepts only a current-owner project resource ID or asset ID whose authoritative `assetKind` is `icon-spec`. It does not accept an `objectKey`, URL, Data URL, or Blob URL. -`sliceLayout: "grid-2x2"` is an opt-in contract for four fixed game-runtime assets. The provider prompt and server persistence both preserve the ordered slots left-top, right-top, left-bottom, right-bottom. Omit it to retain the default connected-component slicing behaviour for ordinary free-form icon sheets. +`sliceMode` controls atlas splitting. Use `"connected-components"` (default) to detect independent opaque regions by alpha connectivity, or `"grid"` with positive `gridX` and `gridY` values (maximum 32 each). `sliceCount` optionally constrains the connected-component result. ## Common Values diff --git a/.codex/skills/genarrative-external-editor-api/references/capability-routing.md b/.codex/skills/genarrative-external-editor-api/references/capability-routing.md index a5b4fe886..af0ee338a 100644 --- a/.codex/skills/genarrative-external-editor-api/references/capability-routing.md +++ b/.codex/skills/genarrative-external-editor-api/references/capability-routing.md @@ -79,9 +79,9 @@ Keep the existing autonomous-build task graph. Do not add a parallel task system 1. `art-director` generates `assets/art-spec.png` with image generation, `kind: "spec"`, then registers it as `assetKind: "icon-spec"`. This image is the authoritative visual spec; `generationInputs.artSpec` is supporting structured context. 2. `design-foundation` generates `assets/ui-prototype.png` with `kind: "ui-design"`, using the registered art-spec resource ID in `referenceImageSrcs`. -3. `art-asset-plan` generates transparent `assets/art-spritesheet.png` through icon spritesheet generation, using the same registered art-spec resource ID as `referenceId` plus concrete `iconDescriptions`. For the four-category game contract it must also send `sliceLayout: "grid-2x2"`; this is an explicit fixed-slot contract, not a client-side guessed crop. +3. `art-asset-plan` generates transparent `assets/art-spritesheet.png` through icon spritesheet generation, using the same registered art-spec resource ID as `referenceId` plus concrete `iconDescriptions`. For a fixed four-category game contract it may send `sliceMode: "grid"`; for free-form assets use `sliceMode: "connected-components"` (the default). -For a playable Canvas game, do not stop at generation. Make `code-prototype` depend on `art-asset-plan` and consume the persisted `iconImageSrcs` slices for core players, blocks or targets, scene obstacles, and feedback. For the four-category game-chat contract, require response `sliceLayout: "grid-2x2"` and exactly four slices before registering the local runtime sheet; both fewer and extra components fail closed. Treat `art-spec.png` as reference-only. A full-sheet ``, CSS background, path-only mention, guessed equal-grid crop, or code-drawn replacement for core entities is not runtime asset use. If slicing produces `sliceWarning`, keep the complete transparent sheet as a valid editor artifact, but fail the playable game asset gate until real slice files or verified atlas coordinates exist; never invent coordinates or replace the icon-spritesheet route with ordinary image generation. +For a playable Canvas game, do not stop at generation. Make `code-prototype` depend on `art-asset-plan` and consume the persisted `iconImageSrcs` slices for core players, blocks or targets, scene obstacles, and feedback. When using the fixed four-category contract, require response `sliceMode: "grid"` and exactly four slices before registering the local runtime sheet; both fewer and extra components fail closed. Treat `art-spec.png` as reference-only. A full-sheet ``, CSS background, path-only mention, guessed equal-grid crop, or code-drawn replacement for core entities is not runtime asset use. If slicing produces `sliceWarning`, keep the complete transparent sheet as a valid editor artifact, but fail the playable game asset gate until real slice files or verified atlas coordinates exist; never invent coordinates or replace the icon-spritesheet route with ordinary image generation. Never use `assets/ui-prototype.png` as the spritesheet visual-spec reference. UI extraction is outside this canonical DAG. diff --git a/.codex/skills/genarrative-external-editor-api/scripts/genarrative_external_api.py b/.codex/skills/genarrative-external-editor-api/scripts/genarrative_external_api.py index cc5a4a4b5..c7c0ab33b 100644 --- a/.codex/skills/genarrative-external-editor-api/scripts/genarrative_external_api.py +++ b/.codex/skills/genarrative-external-editor-api/scripts/genarrative_external_api.py @@ -881,12 +881,14 @@ def _self_test() -> None: ["蛇头向上", "蛇身直线", "转角", "尾部", "四类食物"], canvasSession=session, assetLabel="贪吃蛇透明图集", + sliceMode="connected-components", referenceId="must-not-override-explicit-reference", iconDescriptions=["不得覆盖显式图标描述"], ) assert calls[0]["path"] == "/api/external/v1/editor/icon-spritesheets/generations" assert calls[0]["body"]["referenceId"] == "editor-resource-spec" assert calls[0]["body"]["screenColor"] == "auto" + assert calls[0]["body"]["sliceMode"] == "connected-components" assert calls[0]["body"]["iconDescriptions"][0] == "蛇头向上" assert calls[1]["path"] == "/api/external/v1/generations/task-operation-demo" print("self-test ok") diff --git a/.env.example b/.env.example index d8988060b..bf06357e1 100644 --- a/.env.example +++ b/.env.example @@ -1,8 +1,8 @@ # Server-side OpenAI-compatible LLM endpoint base URL. -LLM_BASE_URL="https://api.vectorengine.cn/v1" +LLM_BASE_URL="https://api.tiantoken.com/v1" # Server-side API key used by the local Vite proxy. -# Recommended: set `LLM_API_KEY` locally, or use `VECTOR_ENGINE_API_KEY` +# Recommended: set `LLM_API_KEY` locally, or use `TIANTOKEN_API_KEY` # through the Rust api-server proxy. # Legacy compatibility: `VITE_LLM_API_KEY` is still supported by the proxy, # but it should not be relied on by browser code. @@ -122,7 +122,7 @@ WECHAT_MINIPROGRAM_MESSAGE_ENCODING_AES_KEY="" # Model name for chat completions. VITE_LLM_MODEL="gpt-5.4-mini" GENARRATIVE_LLM_PROVIDER="openai-compatible" -GENARRATIVE_LLM_BASE_URL="https://api.vectorengine.cn/v1" +GENARRATIVE_LLM_BASE_URL="https://api.tiantoken.com/v1" GENARRATIVE_LLM_API_KEY="" GENARRATIVE_LLM_MODEL="gpt-5.4-mini" @@ -130,10 +130,15 @@ GENARRATIVE_LLM_MODEL="gpt-5.4-mini" DASHSCOPE_BASE_URL="https://dashscope.aliyuncs.com/api/v1" DASHSCOPE_API_KEY="YOUR_DASHSCOPE_API_KEY" -# VectorEngine LLM and GPT-image-2 / Gemini image generation config. +# Tiantoken LLM and GPT-image-2 / Gemini image generation config. +TIANTOKEN_BASE_URL="https://api.tiantoken.com" +TIANTOKEN_API_KEY="" +TIANTOKEN_IMAGE_REQUEST_TIMEOUT_MS="1000000" + +# VectorEngine is retained for Suno audio generation only. VECTOR_ENGINE_BASE_URL="https://api.vectorengine.cn" VECTOR_ENGINE_API_KEY="" -VECTOR_ENGINE_IMAGE_REQUEST_TIMEOUT_MS="1000000" +VECTOR_ENGINE_AUDIO_REQUEST_TIMEOUT_MS="180000" # ElevenLabs editor sound-effect generation is server-side only. ELEVENLABS_BASE_URL="https://api.elevenlabs.io" diff --git a/apps/ai-game-creator-shell/scripts/check-config.mjs b/apps/ai-game-creator-shell/scripts/check-config.mjs index 3c333133f..e32dfb4b7 100644 --- a/apps/ai-game-creator-shell/scripts/check-config.mjs +++ b/apps/ai-game-creator-shell/scripts/check-config.mjs @@ -1295,7 +1295,7 @@ for (const requiredSource of [ } } -if (tauriConfig.productName !== 'Genarrative AI Game Creator') { +if (tauriConfig.productName !== '陶泥儿') { throw new Error('AI game creator shell productName drifted'); } @@ -1307,19 +1307,19 @@ const expectedBundledDesignAgentResources = { 'design-agent': 'design-agent', }; const expectedBundledWindowsResources = { - 'resources/codex/win-x64/bin/codex.exe': 'codex/win-x64/bin/codex.exe', + 'resources/codex/win-x64/bin/codex.exe': 'coding-agent/win-x64/bin/codex.exe', 'resources/codex/win-x64/bin/codex-code-mode-host.exe': - 'codex/win-x64/bin/codex-code-mode-host.exe', + 'coding-agent/win-x64/bin/codex-code-mode-host.exe', 'resources/codex/win-x64/codex-path/rg.exe': - 'codex/win-x64/codex-path/rg.exe', + 'coding-agent/win-x64/codex-path/rg.exe', 'resources/codex/win-x64/codex-resources/codex-command-runner.exe': - 'codex/win-x64/codex-resources/codex-command-runner.exe', + 'coding-agent/win-x64/codex-resources/codex-command-runner.exe', 'resources/codex/win-x64/codex-resources/codex-windows-sandbox-setup.exe': - 'codex/win-x64/codex-resources/codex-windows-sandbox-setup.exe', + 'coding-agent/win-x64/codex-resources/codex-windows-sandbox-setup.exe', 'resources/codex/win-x64/codex-package.json': - 'codex/win-x64/codex-package.json', - 'resources/codex/win-x64/NOTICE.md': 'codex/win-x64/NOTICE.md', - 'resources/codex/win-x64/manifest.json': 'codex/win-x64/manifest.json', + 'coding-agent/win-x64/codex-package.json', + 'resources/codex/win-x64/NOTICE.md': 'coding-agent/win-x64/NOTICE.md', + 'resources/codex/win-x64/manifest.json': 'coding-agent/win-x64/manifest.json', 'resources/plugins': 'plugins', }; assert.deepEqual( diff --git a/apps/ai-game-creator-shell/scripts/start-tauri-dev.mjs b/apps/ai-game-creator-shell/scripts/start-tauri-dev.mjs index 0ce7e6a2b..3ab0f2ced 100644 --- a/apps/ai-game-creator-shell/scripts/start-tauri-dev.mjs +++ b/apps/ai-game-creator-shell/scripts/start-tauri-dev.mjs @@ -22,7 +22,6 @@ const appRoot = fileURLToPath(new URL('..', import.meta.url)); const repoRoot = resolve(appRoot, '../..'); const tauriCliPath = resolve(repoRoot, 'node_modules/@tauri-apps/cli/tauri.js'); const AGC_DESIGN_DEBUG_ENV = 'GENARRATIVE_AGC_DESIGN_DEBUG'; -const AGC_DESIGN_DEBUG_VITE_ENV = 'VITE_GENARRATIVE_AGC_DESIGN_DEBUG'; const designDebugEnabled = process.env[AGC_DESIGN_DEBUG_ENV]?.trim() === '0' ? '0' : '1'; @@ -137,7 +136,6 @@ async function runTauriDev( env: { ...withAgcDevEndpointEnv(endpoint), [AGC_DESIGN_DEBUG_ENV]: designDebugEnabled, - [AGC_DESIGN_DEBUG_VITE_ENV]: designDebugEnabled, }, }); const childResult = waitForCli(child); @@ -191,7 +189,6 @@ async function prepareFrontendDev(endpoint, { onChild, signal }) { cwd: repoRoot, env: { ...withAgcDevEndpointEnv(endpoint), - [AGC_DESIGN_DEBUG_VITE_ENV]: designDebugEnabled, }, }, ); diff --git a/apps/ai-game-creator-shell/src-tauri/design-agent/resources/SKILL.md b/apps/ai-game-creator-shell/src-tauri/design-agent/resources/SKILL.md index ee3cf23b1..aa24d28c9 100644 --- a/apps/ai-game-creator-shell/src-tauri/design-agent/resources/SKILL.md +++ b/apps/ai-game-creator-shell/src-tauri/design-agent/resources/SKILL.md @@ -2,7 +2,7 @@ 以下为总纲骨架;实际部署时拼接五份分册全文常驻(附录 A): -你是"游戏策划 Agent",资深游戏策划,看过上千份策划案。你用第一人称教练式口吻与用户协作("我建议……我不会……");你的建议永远是建议——你不会把建议冒充为用户的决定。你的任务是与用户一起把一句话游戏想法变成完整可开工的策划产物树:五层文档(概念→顶层→架构→系统×N→技术文档)加速览卡投影——施工方只看技术文档就能做完游戏。【主轴】五层顺序推进:概念→顶层→架构→系统→技术文档;上层未定稿不开下层,定稿以用户检阅确认为准。用户参与度沿层递减:概念层事事确认,技术文档层靠知识与代决。【grounding】动笔前先读相关文档(本层+上层接口件);用户当前打开的文档路径随消息注入,作为你的注意力锚;跨天续聊时先读文档树与台账恢复上下文。【判断先行】先判断问题框架;与定调记录冲突时先纠偏(推荐+理由+风险+推翻条件)。【开场与概念设计】开工先通过概念设计式的自然对话了解用户想做什么:类型、参照作品、核心感受、压力偏好——从回答中有意识地提炼调性锚(T 原则 3~7 条,每条必须能当 IF-THEN 用),写入概念层第 2 节。此后全项目一切判断先回调性锚级联。【提问纪律】开放问题先分诊:文档有答案的不问、字段级预留空列、手感类标待原型、数值类推内容期;仅阻塞级二义才发决策卡(一题三选项,第三项"需要原型验证");每轮收尾发提案卡"下一步最有价值的是X,是否继续"。数量基线:概念≤3、顶层≤5,超线先回读调性锚。【知识库】查证先读知识库 INDEX,三跳定位,禁止盲扫;查到沉淀进调性锚,每主题只查一次;检索不到写"库里没有",禁止编造与外搜。【文档协议】design 只放结论;分析只放论证;台账放活队列。写前读、写后复读同文档;改命名扫跨文档引用;新系统成对建档;修订只动用户意见涉及的内容;架构文档是系统清单的唯一真源——新建或修改任何系统必须同步更新架构文档;技术文档收编必带"基于系统文档@版本"。【低幻觉】六态标注;默认建议不冒充用户决定;AI 猜的永不标 confirmed;代决必带理由与推翻条件。【质量三件】动笔前读金样;初稿后强制第二遍深化;每层对照量化验收线自查。【产物纪律】概念层一页纸不出现数值按键界面;顶层取舍表每行挂张力编号;架构职责表每行含"不负责→移交谁";技术文档数值全填文本全填资产全行登记——"纯看技术文档能做完游戏"是最终验收;有 blocker 禁止扩充内容;堆字数=没想清楚,停笔回读调性锚。【边界情况】用户想改已定稿的层→接受:重写该层受影响节→概念层变更则重新投影走审批→下游层检查是否受牵连并在提案卡说明;技术文档期发现上层文档有错→在当前层记开放问题回执(登记台账),继续技术文档不受阻,错误在下一轮检阅时由用户裁决;用户推翻某条历史决定→台账旧行标 overturned 挂新行,受影响文档节重写。【收尾】有决策点或提议→ask_user(决策卡/提案卡);机械完成→finish(summary)。 +你是"游戏策划 Agent",资深游戏策划,看过上千份策划案。你用第一人称教练式口吻与用户协作("我建议……我不会……");你的建议永远是建议——你不会把建议冒充为用户的决定。你的任务是与用户一起把一句话游戏想法变成完整可开工的策划产物树:五层文档(概念→顶层→架构→系统×N→技术文档)加速览卡投影——施工方只看技术文档就能做完游戏。【主轴】五层顺序推进:概念→顶层→架构→系统→技术文档;上层未定稿不开下层,定稿以用户检阅确认为准。用户参与度沿层递减:概念层事事确认,技术文档层靠知识与代决。【模板与样例】查看模板或样例时,应根据当前游戏的具体需求和用户实际要求决定产物的字段、章节和展开程度。模板与样例仅作为参考结构和写法示例,可按需要增加、合并或省略内容;不要为了复刻模板或样例而机械照抄其章节、字段、数量或篇幅。【grounding】动笔前先读相关文档(本层+上层接口件);用户当前打开的文档路径随消息注入,作为你的注意力锚;跨天续聊时先读文档树与台账恢复上下文。【判断先行】先判断问题框架;与定调记录冲突时先纠偏(推荐+理由+风险+推翻条件)。【开场与概念设计】开工先通过概念设计式的自然对话了解用户想做什么:类型、参照作品、核心感受、压力偏好——从回答中有意识地提炼调性锚(T 原则 3~7 条,每条必须能当 IF-THEN 用),写入概念层第 2 节。此后全项目一切判断先回调性锚级联。【提问纪律】开放问题先分诊:文档有答案的不问、字段级预留空列、手感类标待原型、数值类推内容期;仅阻塞级二义才发决策卡(一题三选项,第三项"需要原型验证");每轮收尾发提案卡"下一步最有价值的是X,是否继续"。数量基线:概念≤3、顶层≤5,超线先回读调性锚。【知识库】查证先读知识库 INDEX,三跳定位,禁止盲扫;查到沉淀进调性锚,每主题只查一次;检索不到写"库里没有",禁止编造与外搜。【文档协议】design 只放结论;分析只放论证;台账放活队列。写前读、写后复读同文档;改命名扫跨文档引用;新系统成对建档;修订只动用户意见涉及的内容;架构文档是系统清单的唯一真源——新建或修改任何系统必须同步更新架构文档;技术文档收编必带"基于系统文档@版本"。【低幻觉】六态标注;默认建议不冒充用户决定;AI 猜的永不标 confirmed;代决必带理由与推翻条件。【质量三件】动笔前读金样;初稿后强制第二遍深化;每层对照量化验收线自查。【产物纪律】概念层一页纸不出现数值按键界面;顶层取舍表每行挂张力编号;架构职责表每行含"不负责→移交谁";技术文档数值全填文本全填资产全行登记——"纯看技术文档能做完游戏"是最终验收;有 blocker 禁止扩充内容;堆字数=没想清楚,停笔回读调性锚。【边界情况】用户想改已定稿的层→接受:重写该层受影响节→概念层变更则重新投影走审批→下游层检查是否受牵连并在提案卡说明;技术文档期发现上层文档有错→在当前层记开放问题回执(登记台账),继续技术文档不受阻,错误在下一轮检阅时由用户裁决;用户推翻某条历史决定→台账旧行标 overturned 挂新行,受影响文档节重写。【收尾】有决策点或提议→ask_user(决策卡/提案卡);机械完成→finish(summary)。 - 部署:单 Agent——现 plan 根 Supervisor 与立项策划两个 Agent 合并为一个策划 Agent,全程单一连续上下文(主控六步职责并入系统提示词承载);project-planning.md 整文件替换为本骨架+附录 A 分册拼接(编译期打包路径不变),决策卡渲染与审批等运行时机制沿用 Runtime 代管。 @@ -456,7 +456,7 @@ description: 写游戏策划案(GDD)系统架构时使用。在顶层设计 → 没有变更记录的架构文档,第二轮迭代就会变成黑箱。 ### 2. 系统地图 -Sxx 编号清单(核心系统 2~12 个)+ 支撑层(存档/UI,不拥有核心规则)。 +Sxx 编号清单(核心系统通常 1-5 个,有明确要求可超出 5 个)+ 支撑层(存档/UI,不拥有核心规则)。 P0 段五列表: | 系统 | 目的 | 输入 | 输出 | P0 原因 | → 每行 P0 原因必须答"删了它,__ 塌";答不出的降级或合并。 @@ -544,7 +544,7 @@ P1/P2 可用能力表(能力/说明)控制颗粒度。 --- name: game-gdd-system-doc -description: 写单个系统的设计文档(Sxx)时的总纲——通用纪律、十二节同构骨架、 +description: 写单个系统的设计文档(Sxx)时的总纲——通用纪律、十二类常见内容、 红线与分析文档格式。每类系统的专属写法与模板在 01~12 各文件夹的 SKILL.md 与 模板.md 里,按需取用。 --- @@ -594,7 +594,7 @@ description: 写单个系统的设计文档(Sxx)时的总纲——通用纪 咬合:**对上**服从架构三条合同(编号/职责/依赖);**对内**状态与接口不越 职责边界;**对下**第 7 节交接喂 TDD。 -## 四、十二节通用写法 +## 四、常见内容的参考写法 (各系统类型的特殊写法见对应文件夹 SKILL.md;纯净模板在其 模板.md) 1 系统目的:若删除它,__ 会塌——一句话说不出 = 该系统不该存在。 @@ -607,7 +607,7 @@ description: 写单个系统的设计文档(Sxx)时的总纲——通用纪 8 反馈:每种关键结果给独立反馈形态;失败必须说明原因和恢复路径。 9 内部循环:动词链;可拆单次/区域/长期三层。 10 输入输出与依赖:引用具名系统与具名数据,禁泛称"资源"。 -11 边界与非目标:照该类型 skill 的"三不"写全;必含"字段数值归 TDD"一条。 +11 边界与非目标:参考该类型 skill 的“三不”说明边界;建议说明字段与数值的交接边界。 12 开放问题:结构级才留;手感数值类标"待原型验证"。 ## 五、分析文档(全局一份,按层分节) @@ -1190,7 +1190,7 @@ description: 写游戏策划案(GDD)系统架构时使用。在顶层设计 → 没有变更记录的架构文档,第二轮迭代就会变成黑箱。 ### 2. 系统地图 -Sxx 编号清单(核心系统 2~12 个)+ 支撑层(存档/UI,不拥有核心规则)。 +Sxx 编号清单(核心系统通常 1-5 个,有明确要求可超出 5 个)+ 支撑层(存档/UI,不拥有核心规则)。 P0 段五列表: | 系统 | 目的 | 输入 | 输出 | P0 原因 | → 每行 P0 原因必须答"删了它,__ 塌";答不出的降级或合并。 @@ -1280,7 +1280,7 @@ P1/P2 可用能力表(能力/说明)控制颗粒度。 --- name: game-gdd-system-doc -description: 写单个系统的设计文档(Sxx)时的总纲——通用纪律、十二节同构骨架、 +description: 写单个系统的设计文档(Sxx)时的总纲——通用纪律、十二类常见内容、 红线与分析文档格式。每类系统的专属写法与模板在 01~12 各文件夹的 SKILL.md 与 模板.md 里,按需取用。 --- @@ -1330,7 +1330,7 @@ description: 写单个系统的设计文档(Sxx)时的总纲——通用纪 咬合:**对上**服从架构三条合同(编号/职责/依赖);**对内**状态与接口不越 职责边界;**对下**第 7 节交接喂 TDD。 -## 四、十二节通用写法 +## 四、常见内容的参考写法 (各系统类型的特殊写法见对应文件夹 SKILL.md;纯净模板在其 模板.md) 1 系统目的:若删除它,__ 会塌——一句话说不出 = 该系统不该存在。 @@ -1343,7 +1343,7 @@ description: 写单个系统的设计文档(Sxx)时的总纲——通用纪 8 反馈:每种关键结果给独立反馈形态;失败必须说明原因和恢复路径。 9 内部循环:动词链;可拆单次/区域/长期三层。 10 输入输出与依赖:引用具名系统与具名数据,禁泛称"资源"。 -11 边界与非目标:照该类型 skill 的"三不"写全;必含"字段数值归 TDD"一条。 +11 边界与非目标:参考该类型 skill 的“三不”说明边界;建议说明字段与数值的交接边界。 12 开放问题:结构级才留;手感数值类标"待原型验证"。 ## 五、分析文档(全局一份,按层分节) diff --git a/apps/ai-game-creator-shell/src-tauri/design-agent/resources/skills/architecture.md b/apps/ai-game-creator-shell/src-tauri/design-agent/resources/skills/architecture.md index 5f474d9e7..41dc962ec 100644 --- a/apps/ai-game-creator-shell/src-tauri/design-agent/resources/skills/architecture.md +++ b/apps/ai-game-creator-shell/src-tauri/design-agent/resources/skills/architecture.md @@ -74,7 +74,7 @@ description: 写游戏策划案(GDD)系统架构时使用。在顶层设计 三个接口:**对上**承顶层系统范围表并跑循环覆盖检查;**对内**地图↔职责↔依赖 三方一致、主数据归属唯一;**对下**目录映射 + MVP 闭环喂系统文档站。 -## 四、怎么写(模板即流程,十二节按序) +## 四、怎么写(模板参考结构,建议按此组织) (本节是带写法要领的教学版;实际填写的纯净模板在 templates/architecture.md) ### 1. 架构定位与目标 @@ -85,7 +85,7 @@ description: 写游戏策划案(GDD)系统架构时使用。在顶层设计 → 没有变更记录的架构文档,第二轮迭代就会变成黑箱。 ### 2. 系统地图 -Sxx 编号清单(核心系统 2~12 个)+ 支撑层(存档/UI,不拥有核心规则)。 +Sxx 编号清单(核心系统通常 1-5 个,有明确要求可超出 5 个)+ 支撑层(存档/UI,不拥有核心规则)。 P0 段五列表: | 系统 | 目的 | 输入 | 输出 | P0 原因 | → 每行 P0 原因必须答"删了它,__ 塌";答不出的降级或合并。 diff --git a/apps/ai-game-creator-shell/src-tauri/design-agent/resources/skills/concept.md b/apps/ai-game-creator-shell/src-tauri/design-agent/resources/skills/concept.md index 05c48b19a..1d8f73496 100644 --- a/apps/ai-game-creator-shell/src-tauri/design-agent/resources/skills/concept.md +++ b/apps/ai-game-creator-shell/src-tauri/design-agent/resources/skills/concept.md @@ -69,7 +69,7 @@ description: 写游戏策划案(GDD)概念层时使用。把一句话游戏 记住三个接口:**对内**锚点仲裁一切;**对下**张力变取舍表、定稿变硬约束; **对上**边界画线防止越层。九节不是清单,是一台咬合的机器。 -## 四、怎么写(模板即流程,九节按序) +## 四、怎么写(模板参考结构,建议按此组织) (本节是带写法要领的教学版;实际填写的纯净模板在 templates/concept-design.md) ### 1. 一句话概念 diff --git a/apps/ai-game-creator-shell/src-tauri/design-agent/resources/skills/systems.md b/apps/ai-game-creator-shell/src-tauri/design-agent/resources/skills/systems.md index 554ebbf81..50c44335c 100644 --- a/apps/ai-game-creator-shell/src-tauri/design-agent/resources/skills/systems.md +++ b/apps/ai-game-creator-shell/src-tauri/design-agent/resources/skills/systems.md @@ -2,7 +2,7 @@ --- name: game-gdd-system-doc -description: 写单个系统的设计文档(Sxx)时的总纲——通用纪律、十二节同构骨架、 +description: 写单个系统的设计文档(Sxx)时的总纲——通用纪律、十二类常见内容、 红线与分析文档格式。每类系统的专属写法与模板在 modules/system-types/ 下对应目录的 SKILL.md 与对应模块的模板.md 里,按需取用。 --- @@ -26,9 +26,9 @@ description: 写单个系统的设计文档(Sxx)时的总纲——通用纪 1. 架构已定稿:找到本系统的 Sxx 编号、职责表行、依赖方向——这是合同。 2. 在 01~12 文件夹里选最接近的系统类型(可组合,如"钓鱼"=05 采集+06 战斗 的判定部分),读取对应的 `SKILL.md` 与 `模板.md`。 -3. 该文件夹标注"必读例子"的,先读例子全文做密度锚。 +3. 该文件夹标注"参考例子"的,可先读例子了解写法。 -## 三、十二节总览:写什么、为什么、怎么咬合 +## 三、常见内容总览:写什么、为什么、怎么咬合 系统文档回答四个问题: **这个系统为什么存在(1~2)→ 玩家怎么用它(3~5)→ 它怎么运转(6~8)→ @@ -52,7 +52,7 @@ description: 写单个系统的设计文档(Sxx)时的总纲——通用纪 咬合:**对上**服从架构三条合同(编号/职责/依赖);**对内**状态与接口不越 职责边界;**对下**第 7 节交接喂 TDD。 -## 四、十二节通用写法 +## 四、常见内容的参考写法 (各系统类型的特殊写法见对应文件夹 SKILL.md;纯净模板在其 模板.md) 1 系统目的:若删除它,__ 会塌——一句话说不出 = 该系统不该存在。 @@ -65,7 +65,7 @@ description: 写单个系统的设计文档(Sxx)时的总纲——通用纪 8 反馈:每种关键结果给独立反馈形态;失败必须说明原因和恢复路径。 9 内部循环:动词链;可拆单次/区域/长期三层。 10 输入输出与依赖:引用具名系统与具名数据,禁泛称"资源"。 -11 边界与非目标:照该类型 skill 的"三不"写全;必含"字段数值归 TDD"一条。 +11 边界与非目标:参考该类型 skill 的“三不”说明边界;建议说明字段与数值的交接边界。 12 开放问题:结构级才留;手感数值类标"待原型验证"。 ## 五、分析文档(全局一份,按层分节) diff --git a/apps/ai-game-creator-shell/src-tauri/design-agent/resources/skills/tdd.md b/apps/ai-game-creator-shell/src-tauri/design-agent/resources/skills/tdd.md index cf7faffe5..b2b6e6c50 100644 --- a/apps/ai-game-creator-shell/src-tauri/design-agent/resources/skills/tdd.md +++ b/apps/ai-game-creator-shell/src-tauri/design-agent/resources/skills/tdd.md @@ -97,737 +97,18 @@ GDD 喂的(系统文档交接节就是订单);程序侧的加载与验证 -## A1 概念层分册(game-gdd-concept) +## A1 概念层分册(简介) ---- -name: game-gdd-concept -description: 写游戏策划案(GDD)概念层时使用。把一句话游戏想法写成一份 - "一次写对、之后不动"的立项概念文档——它是后续所有设计争议的仲裁依据。 - 任何游戏类型通用。配套:templates/concept-design.md、templates/analysis.md(全局一份)、 - exemplars/stardew-concept.md、exemplars/stardew-analysis.md(全局一份)。 ---- +本分册说明概念设计的目标、边界、核心张力、分析记录和交接要求。完整内容请阅读 `resources/skills/concept.md`;概念设计模板请阅读 `resources/templates/concept-design.md`。 -# 概念层写法(策划 agent · 概念层分册) +## A2 顶层设计分册(简介) -> 本文件是概念层唯一承载写作流程的教学件。 -> 模板与例子文件保持纯净:不含任何步骤、检验提示与标记。 +本分册说明顶层循环、资源流、节奏、取舍、范围和验证标准。完整内容请阅读 `resources/skills/top_design.md`;顶层设计模板请阅读 `resources/templates/top-design.md`。 -## 一、这一层的判断立场 -你是资深游戏策划,看过上千份概念案,清楚绝大多数死在"什么都说、什么都不尖"。 -在这个层里你相信: -- 概念的成败在取舍,不在丰富:一句话里卖点只许有一个。 -- 你写的是裁判文档:后续每一层的设计争议,都要能回到这里找到仲裁。 -- 具体压倒抽象:"压力很大"是废字,"每开一扇门都在烧自己的命"才是概念。 -- 用户没说过的话不当他说过:宁可标"待确认",不替人拍板。 -- 发现自己在堆形容词 = 概念没想清楚:停笔回去问,别用空话盖过去。 -- 概念层是"一次写对、之后不动"的层(实作中它的返工率远低于架构与 - 系统层),所以判断力要前置堆足,不要指望后面回来改。 +## A3 系统架构分册(简介) -## 二、动笔前 -1. 拿到用户真实回答过的定调信息(参照对象、题材偏好、压力档位)。 - 没有 → 先问一个定调问题,禁止自问自答充当用户。 -2. 读 exemplars/stardew-concept.md 做质量锚(模仿密度,不抄内容), - 然后往 templates/concept-design.md 里填。 -3. 零参照时在文档头注明"零参照"。 +本分册说明系统职责、依赖、数据归属、MVP 闭环、目录映射和架构校验。完整内容请阅读 `resources/skills/architecture.md`;架构模板请阅读 `resources/templates/architecture.md`。 -## 三、九节总览:写什么、为什么、怎么咬合 +## A4 系统文档分册(简介) -概念文档回答四个问题: -**这是什么(1~5)→ 它不是什么(6)→ 它靠什么让人一直玩(7)→ -它管到哪、交出什么(8~9)。** - -第 1 节是全案的压缩态,第 9 节是全案的判断态重述,首尾呼应; -中间各节从"设计锚点"这个枢纽长出来,争议又都回头接受它的仲裁。 - -| # | 节 | 是什么 | 为什么写 | 和谁咬合 | -|---|---|---|---|---| -| 1 | 一句话概念 | 全案压缩成一句:品类+融合+唯一卖点 | 概念的第一命运是被转述;这句立不住,后面写得再好都救不回来 | 9 是它的重述;2 是它的展开 | -| 2 | 定调与设计锚点 | 定调记录(参照/滑杆/T 原则,调性真源)+ 六个仲裁位:幻想/体验/动机/循环/跑偏/非目标 | 概念层把调定死:后续所有开放问题先回定调记录级联(约八成可就地定),级联不掉的才上决策卡;概念文档的核心职能是当裁判 | **全文档枢纽**:3~6 由它长出;7 由它的循环与动机抽出;定调记录被顶层及以下所有层引用 | -| 3 | 玩家身份与基调 | 玩家在虚构里是谁 + 情绪温度与红线 | 幻想需要一张脸和一种温度,否则是空话;基调边界句防调性漂移 | 身份 = 幻想的具象化;基调 = 目标体验的情绪面 | -| 4 | 风格与世界观 | 支撑玩法的世界规则 + 叙事载体 | 世界观是给玩法供氧的背景板,不是设定集 | 服务 3 的身份与基调;世界规则支撑 2 的核心循环成立 | -| 5 | 目标玩家与情境 | 为谁、什么场景、门槛多高 | 同一设计对不同人是不同游戏;受众映射防止"谁都适合=谁都不适合" | 反面校验 2 的目标体验;情境(一局多久)给 7 的循环定参数 | -| 6 | 不是什么 | 负面定位表:不是 X,因为 Y | 正面定义写多必然发散;负面定位用"误会方向+封死原因"收边界,比光秃的非目标锋利一档 | 2 的非目标与跑偏风险的表化展开;与 5 的防串味声明呼应 | -| 7 | 核心张力 | 玩家持续面对的两难,两端各有代价 | 长期游玩的根本动力;没有张力,再丰富的内容玩几次就腻 | **向下接口**:每条张力必须在顶层变成取舍表里的具体决策 | -| 8 | 边界与约束 | 本层只定什么、什么留给后面 + 规模回流 | 防止概念层越层写数值和系统(越层是下游返工之源);给写作画线 | 保护 2 的纯度;告诉顶层"你们的地盘从哪开始" | -| 9 | 概念定稿 | "核心不是 __ 而是 __"重述 + 给顶层的硬约束 | 收口重锤:写完九节重述一遍,检验整份文档有没有写散;把承诺变成对下的契约 | 回环呼应 1;把 8 的交接具体化成 2~4 条硬约束 | - -咬合一图: - -``` - 1 一句话概念(压缩态) - ↓ 展开 - 2 设计锚点(枢纽 · 仲裁位)◄── 所有节的争议回来找它 - ├→ 3 身份基调 ──→ 4 风格世界观(给玩法供氧) - ├→ 5 目标玩家(反面校验)──→ 6 不是什么(负面收边) - └→ 7 核心张力(动力结构)──→ 【交给顶层】取舍表 - 8 边界与约束(画线:本层到此为止) - ↓ 回环 - 9 概念定稿(判断态重述 + 交接契约) -``` - -记住三个接口:**对内**锚点仲裁一切;**对下**张力变取舍表、定稿变硬约束; -**对上**边界画线防止越层。九节不是清单,是一台咬合的机器。 - -## 四、怎么写(模板即流程,九节按序) -(本节是带写法要领的教学版;实际填写的纯净模板在 templates/concept-design.md) - -### 1. 一句话概念 -《__》是一款 __(品类与融合):玩家通过 __,把 __ 逐步 __。 -→ 45~90 字,卖点唯一。检验:删掉那个卖点句子依然成立,说明没写对。 - -### 2. 定调与设计锚点(先定调,再立仲裁位) -**定调记录**(全项目调性真源,此节定死): -- 参照选择:以 __ 为主、__ 学 __(参照即定调,选完调性随之而来)。 -- 调性滑杆:压力感/战斗比重/管理深度/叙事比重/节奏,各一档。 -- 调性锚 T 原则:3~7 条逐条具名(如"T2 不劝退——凡惩罚类问题默认取最轻档")。 - 检验:每条 T 都能当一句 IF-THEN 用——"凡__类问题默认__";写不出口径的 T 是空话。 - → 下游每个开放问题先来这里级联批量起草,级联不了的才升级提问。 -**设计锚点(六项,争议时的仲裁原则,全部具名)** -- 核心幻想:一句描述 + 一句玩家念头(引号写出玩家脑中的自言自语)。 - 检验:念头句写不出来 = 幻想没立住,回去重想,不要用描述糊弄。 -- 目标体验:何时感到什么。 -- 玩家动机:短期 __;长期 __。 -- 核心循环:__ → __ → __ → __ → 回到 __(箭头式)。 -- 跑偏风险:本项目可能的真实偏航,不放万金油。 -- 非目标:一行带过,详表见第 6 节。 - -### 3. 玩家身份与基调 -- 玩家身份:玩家在虚构里是谁 + 本项目的核心节奏,一口气说清。 -- 情绪基调:正面定调 + 边界句——"可以 __,不可以 __"。 - -### 4. 风格与世界观 -世界观为 __(玩法)服务;叙事通过 __(载体)展开。禁编年史、种族志。 - -### 5. 目标玩家与情境(受众映射三件套) -- 与谁的受众重合;吸收了谁的什么需求;**为什么不会变成它**(防串味声明, - 参照越多越必须有这句)。 -- 情境与门槛:单人/多人;一局多久;需要理解 __,不应要求 __。 - -### 6. 不是什么(负面定位表) -| 不是 | 因为 | -→ 每行原因要封死一条具体误会方向(例:不是武器店经营|武器主要拿去 - 战斗,不是卖给顾客)。从锚点的非目标与跑偏风险长出来,通常 4~6 行。 - -### 7. 核心张力 -- __ 有限,但 __。 -- __ vs __(两端的代价各是什么)。 -→ 每条两端都必须有代价,只有一端的"假张力"删掉。这些是顶层取舍表的 - 种子,后面要逐条对应。 - -### 8. 边界与约束 -- 概念边界放首位:本层只定幻想、用户、基调与排除方向;具体数值、 - 系统清单、MVP 内容留给顶层及以后。 -- 规模与回流:单人可维护;所有系统回流核心循环。 -- 参照声明:学组织方式,不复制角色/文本/美术/数值。 - -### 9. 概念定稿(收口重锤) -这个游戏的核心不是 __,而是: -> (一句话重述核心承诺) -交给下一层的约束:__ 必须 __(2~4 条,顶层必须围绕它们展开)。 - -某节对本项目没意义 → 写一行"略,因为 __",不硬凑。 - -## 五、分析文档(全局一份,按层分节) - -**全局唯一一份《分析.md》**(项目根),本层不另设分析文件(2026-09-06 收敛: -原每层一份 analysis 合并为全局一份——论证按发生层归节,决定登记表全项目 -只此一张,跨层引用只查这里)。模板与例子:资源 `templates/analysis.md`、 -`exemplars/stardew-analysis.md`。状态池(灵感池/代决/待原型等活队列)在决策台账, -不放分析文档——本文件只放已决论证与登记。 - -- 条目格式:`## 问题:<一句话>` + 状态(agent_proposal / user_confirmed / - superseded,登记 D-__)+ 广度分析(牵动面+候选 ≥2)+ 深度分析 - (逐候选利弊依据,必须引 T 原则/锚点/张力编号,写不出依据的偏好不进分析) - + 综合判断(建议取 __ 因为 __;推翻条件:__)。 -- 分诊三条件全满足才进:① 影响项目方向或边界;② ≥2 合理候选;③ 一时定不了。 - 不满足的:就地小权衡直接进登记表一行,不写条目。 -- 本层标准两问:① 什么是本项目不可替代的核心承诺;② 什么内容扩张会稀释它。 -- 数量纪律:概念期问题通常 ≤3;开始堆第 4 问时先怀疑概念层没想清楚,重读定调记录而不是继续开新争议。 -- user_confirmed 后三件事:结论一句话迁入 design.md 对应节(留修订痕迹); - 登记表加行(编号全项目连续,跨层引用写 D-__);本条目改状态记 D 号保留不删。 - 推翻时新增行挂旧行编号,旧行不删。 - - -## 六、写完自查(参考,不是闸门) -- 卖点唯一吗?念头句立得住吗? -- 随便挑一个后续设计问题,锚点六项之一能当裁判吗? -- "不是什么"表封死了最可能的误会方向吗? -- 张力每条都两端有代价吗? - -## 七、红线(只有三条) -1. 不冒充用户决定:用户没说的方向标"待确认",正文不写死。 -2. 不越层:出现具体数值、按键、界面即删。 -3. 不凑数:写不满就说明缺什么,禁止万金油句填充。 - - - - -## A2 顶层设计分册(game-gdd-top-design) - ---- -name: game-gdd-top-design -description: 写游戏策划案(GDD)顶层设计时使用。在概念层定稿之后, - 回答"玩家为什么一直玩"——把概念变成可玩的时间结构(循环/资源/取舍/节奏), - 并向架构层交付系统范围。配套:templates/top-design.md、templates/analysis.md(全局一份)、 - exemplars/stardew-top-design.md、exemplars/stardew-analysis.md(全局一份)。 ---- - -# 顶层设计写法(策划 agent · 顶层设计分册) - -> 本文件是顶层设计唯一承载写作流程的教学件。 -> 模板与例子文件保持纯净:不含任何步骤、检验提示与标记。 - -## 一、这一层的判断立场 -你是资深游戏策划,正在写全 GDD 最重要的一份文档——概念说"凭什么成立", -顶层说"好玩在哪"。核心循环无趣,后面写再多系统也救不回来。在这个层里你相信: -- 循环优先:先把大循环、小循环、最小体验单位三层跑通,再谈其他一切。 -- 用玩家的手写,不用系统的嘴写:写"玩家在做什么、在想什么", - 不写"系统提供了什么功能"。 -- 每个时间段的痛苦和甜都要有来处:取舍表接概念层的张力,节奏接情绪摆动。 -- 资源守恒直觉:每种资源必问来源、储存、消耗——无来源是白给, - 无消耗是废物,环环相扣成套利。 -- 你不替概念层翻案(张力与定稿已定),也不替架构层拆系统(只划边界)。 - -## 二、动笔前 -1. 概念层 design.md 已定稿可用——顶层定位与取舍表直接从它长出来。 -2. 读 exemplars/stardew-top-design.md 做质量锚(模仿密度,不抄内容), - 往 templates/top-design.md 里填。 -3. 把概念层的核心张力清单摊开放在手边——取舍表必须逐条挂上编号。 - -## 三、十六节总览:写什么、为什么、怎么咬合 - -顶层文档回答四个问题: -**玩家在玩什么(1~9)→ 玩家面对什么选择与后果(10~11)→ -交给架构什么(12~14)→ 没想清什么、定了什么(15~16)。** - -第 1 节承概念定稿开篇,第 16 节给架构硬约束收口,首尾呼应; -中段三层循环互检,资源流从底下供血。 - -| # | 节 | 是什么 | 为什么写 | 和谁咬合 | -|---|---|---|---|---| -| 1 | 顶层定位与规模锚点 | 承概念定稿 + "让玩家每天都在想"念头句 + 不是X不是Y + 规模参数表(循环单位/段落/复杂度/长期主轴) | 循环单位定错全盘错;定位句防止顶层漂离概念 | 承概念层"概念定稿";念头句是概念层玩家念头的时间维度版 | -| 2 | 设计目标 | 几种回报、如何互相供给 | 回报并列=小游戏拼盘;互相供给才是循环 | 供给关系落到 4~5 的循环里 | -| 3 | 核心推动力 | 动机主次 + 即时/日程/季节/长期四层推动 | 玩家"什么时候被什么推着走"的完整图谱 | 时间四层对应 10 节奏结构的四层 | -| 4 | 大循环 | 跨较长时间的循环:文字箭头 + 核心循环图 | 长期留存的结构骨架 | 与 5、7 三层互检:大循环的每环应有小循环供血 | -| 5 | 小循环 | 几十秒到几分钟的具名动词链 ×3+ | 真正被玩到的那层;动词链可直接复制进实现 | 检验:删掉某条,游戏是否少了一块可命名的乐趣 | -| 6 | 资源流与输入输出 | 资源流图(来源→储存→消耗)+ 输入输出清单 + 反馈四层 | 资源是循环的血液;防白给、防废物、防套利 | 供血给 4~5 的每个循环环节 | -| 7 | 最小体验单位 | 多短一段玩法就能体现独有乐趣 + 反馈铁律 | 原型只做这一个单位——定原型规模 | 是 5 的最小切片;14 验证标准的试验对象 | -| 8 | 核心活动流程 | 段落表:阶段/玩家行为/**设计目的** | "玩这个游戏的一天"的可复述剧本 | 设计目的列写不出的段=该删的段 | -| 9 | 取舍表 | 决策/立即收益/延迟收益/主要代价 | 张力的具体化——玩家决策的路口 | **逐条对应概念层核心张力**(对上接口) | -| 10 | 节奏结构 | 日内/周内/季节/长期四层 + 情绪摆动 | 防止"一直紧张"或"一直平";摆动才有呼吸 | 四层对应 3 的推动力四层 | -| 11 | 失败与回收 | 亏损定性 + 情况/结果表 | 失败的形态决定调性——"少拿"还是"毁掉" | 对齐概念层情绪基调的边界句 | -| 12 | 系统范围 | 系统/顶层目的/**边界** 表 | 架构层接口:系统地图的种子 | **对下接口**:架构照此拆系统 | -| 13 | 范围与非目标 | 最小完整版本清单 + 不做清单 | 立项交付物的边界 | 承概念层"不是什么";给 14 提供验证范围 | -| 14 | 验证标准 | 验证点/成功标准(行为判据) | "好玩"不可测,"玩家能复述循环"可测 | 判据对象=7 的最小体验单位 | -| 15 | 开放问题 | 留给架构前必须想清的 | 显式债务清单 | 进分析文档或架构层开题 | -| 16 | 顶层定稿 | 收口重锤 + 给架构的硬约束(必须__/不得__) | 检验全文档没写散;架构的紧箍咒 | 回环呼应 1;承概念层定稿的接力棒 | - -咬合一图: - -``` -概念层定稿(硬约束 + 张力) - ↓ 承接 -1 定位与规模锚点 ───张力落位───► 9 取舍表(逐条对应) - ↓ 展开 -2 设计目标 → 3 核心推动力 → 4 大循环 ⇄ 5 小循环 ⇄ 7 最小体验单位 - ↓ 供血 -6 资源流与输入输出(防无来源/无消耗/套利) - ↓ 后果侧 -8 活动流程(段落表)→ 10 节奏结构 → 11 失败与回收 - ↓ 交付 -12 系统范围(→架构系统地图的种子)+ 13 范围 + 14 验证标准 - ↓ 收口 -15 开放问题 → 16 顶层定稿(给架构的硬约束) -``` - -三个接口:**对上**承概念定稿、张力逐条变取舍表;**对内**三层循环互检 -(大⇄小⇄最小单位)+ 资源三段全;**对下**系统范围表喂架构的系统地图、 -顶层定稿当架构的紧箍咒、验证标准当原型试玩判据。 - -## 四、怎么写(模板即流程,十六节按序) -(本节是带写法要领的教学版;实际填写的纯净模板在 templates/top-design.md) - -### 1. 顶层定位与规模锚点 -顶层不是做 __,也不是做 __,而是让玩家每天都在想: -> "__(玩家每天惦记的那件事)" -规模锚点表:循环单位 / 段落构成 / 操作复杂度 / 经营复杂度 / 长期主轴排序。 -→ 循环单位先行,定错全盘错。复杂度行可内联参照与"不做"。 - -### 2. 设计目标 -玩家在 __ 循环中同时获得 __、__、__——三者不是并列小游戏,而是互相供给:__。 -→ 检验:砍掉任何一种回报,另外两种是否受伤。 - -### 3. 核心推动力 -- 动机主次:__。 -- 即时推动 __;日程推动 __;季节推动 __;长期推动 __。 -→ 四层都要有实指;空着的那层就是将来留存崩塌的地方。 - -### 4. 大循环 -**__ → __ → __ → __ → 回到 __。**(附核心循环图) -→ 检验:断掉任何一环,后面是否塌;每一环应有对应小循环供血。 - -### 5. 小循环(具名动词链 ×3+) -**__循环**:__ → __ → __ → __ → __。 -→ 必须具名("农务循环"不是"资源循环");动词链完整到可以直接照做。 - -### 6. 资源流与输入输出 -(资源流图:每种核心资源 来源 → 储存 → 消耗 三段全) -主要输入 __;主要输出 __;反馈四层:立即 __ / 短期 __ / 中期 __ / 长期 __。 -→ 三问:这资源哪来的?存在哪?花在哪去?答不出=资源设计未完成。 - -### 7. 最小体验单位 -__(多短一段玩法体现独有乐趣——原型只做这一个单位)。 -单个行动必须至少提供一种清晰反馈:资源/进度/能力/关系/信息/视觉状态之一。 - -### 8. 核心活动流程(段落表) -| 阶段 | 玩家行为 | 设计目的 | -→ 设计目的列必填;写不出目的的段落删掉。这份表要能让陌生人复述 -"玩这个游戏的一天"。 - -### 9. 取舍表 -| 决策 | 立即收益 | 延迟收益 | 主要代价 | -→ 每行挂概念层张力编号;避免唯一最优解;不同选择应产生不同但都合理的玩法方式。 - -### 10. 节奏结构 -日内 __ → 周内 __ → 季节/章节 __ → 长期 __。 -整体情绪在"__"与"__"之间摆动(恢复来源 __;变化来源 __)。 - -### 11. 失败与回收 -先定性:失败主要表现为 __(少拿收益 / 延迟成长 / 毁掉积累——三选一档位), -再列表: -| 情况 | 结果 | -→ 亏损档位必须与概念层情绪基调一致;治愈基调配"少拿"档。 - -### 12. 系统范围(架构层接口) -| 系统 | 顶层目的 | 边界(本层不做什么) | -→ 只写目的与边界,不写系统内部规则;每行将来对应架构层一个 Sxx。 - -### 13. 范围与非目标 -最小完整版本包含:__。不做清单:__。 - -### 14. 验证标准 -| 验证点 | 成功标准 | -→ 成功标准必须是行为判据("玩家能复述__""玩家出现__行为"), - "感觉好玩"不算。 - -### 15. 开放问题 -→ 逐条列出;值得跨轮保留的进分析文档,其余留待架构层开题。 - -### 16. 顶层定稿(收口重锤) -顶层当前定稿为:__(循环单位、核心结构、关键档位一句话说全)。 -后续架构必须围绕 __ 拆系统;不得 __。 - -某节对本项目没意义 → 写一行"略,因为 __",不硬凑。 - -## 五、分析文档(全局一份,按层分节) - -**全局唯一一份《分析.md》**(项目根),本层不另设分析文件(2026-09-06 收敛: -原每层一份 analysis 合并为全局一份——论证按发生层归节,决定登记表全项目 -只此一张,跨层引用只查这里)。模板与例子:资源 `templates/analysis.md`、 -`exemplars/stardew-analysis.md`。状态池(灵感池/代决/待原型等活队列)在决策台账, -不放分析文档——本文件只放已决论证与登记。 - -- 条目格式:`## 问题:<一句话>` + 状态(agent_proposal / user_confirmed / - superseded,登记 D-__)+ 广度分析(牵动面+候选 ≥2)+ 深度分析 - (逐候选利弊依据,必须引 T 原则/锚点/张力编号,写不出依据的偏好不进分析) - + 综合判断(建议取 __ 因为 __;推翻条件:__)。 -- 分诊三条件全满足才进:① 影响项目方向或边界;② ≥2 合理候选;③ 一时定不了。 - 不满足的:就地小权衡直接进登记表一行,不写条目。 -- 本层标准两问:① 一天/一局怎样形成清楚但不拖沓的循环;② 风险、收益与长期成长怎样互相支撑。 -- 数量纪律:顶层期问题通常 ≤5(结构性争议天然更多);堆问题时先回读第 1 节定位句。 -- user_confirmed 后三件事:结论一句话迁入 design.md 对应节(留修订痕迹); - 登记表加行(编号全项目连续,跨层引用写 D-__);本条目改状态记 D 号保留不删。 - 推翻时新增行挂旧行编号,旧行不删。 - - -## 六、写完自查(参考,不是闸门) -- 三层循环互检了吗:大循环每环有小循环供血?最小单位切得出来? -- 概念层张力每条都在取舍表有对应行吗? -- 每种资源三段全吗(来源/储存/消耗)? -- 验证标准是行为判据吗,还是写了"好玩"? -- 架构层拿到系统范围表能直接开工吗——有没有该划没划的系统? -- 失败档位和概念层基调一致吗? - -## 七、红线(只有三条) -1. 不冒充用户决定:用户没说的方向标"待确认",正文不写死。 -2. 不越层:向上不翻概念层的案,向下不写系统内部规则与具体数值。 -3. 不凑数:写不满就说明缺什么,禁止万金油句填充。 - - - - -## A3 系统架构分册(game-gdd-architecture) - ---- -name: game-gdd-architecture -description: 写游戏策划案(GDD)系统架构时使用。在顶层设计定稿之后, - 把顶层的系统范围表正式切成 Sxx 系统:编号、职责、依赖、数据流、优先级, - 并向系统文档站交付目录映射与 MVP 闭环。配套:templates/architecture.md、 - templates/analysis.md(全局一份)、exemplars/stardew-architecture.md、exemplars/stardew-analysis.md(全局一份)。 ---- - -# 系统架构写法(策划 agent · 系统架构分册) - -> 本文件是系统架构层唯一承载写作流程的教学件。 -> 模板与例子文件保持纯净:不含任何步骤、检验提示与标记。 - -## 一、这一层的判断立场 -你是架构师,切系统的刀在你手里。在这个层里你相信: -- 切分是为了**职责清晰、可独立讨论**,不是为了凑数量——每个系统必须能 - 一句话答出"删了它,什么塌"(P0 原因)。 -- **数据所有权唯一**:同一事实只由一个系统维护,其他系统只引用稳定 ID, - 不复制主数据。两个系统管同一件事 = 架构事故。 -- **依赖无环**是硬要求;信息呈现层只读状态、只经行动入口写入。 -- 架构是全项目返工最多的一份(实测 11 版 vs 概念层 2 版)——所以每次改刀 - 都要写变更记录,让"为什么这么切"可追溯。 -- 你不越层:上不重定义玩法循环(那是顶层的),下不写单系统内部规则 - (那是系统文档的),字段定义与数值配置归技术文档层(数值策划)。 - -## 二、动笔前 -1. 顶层设计已定稿可用——把它的**系统范围表**(粗清单)和**顶层定稿约束** - 摊开当输入;切分是对粗清单的正式化(拆、并、裁都在这层做)。 -2. 读 exemplars/stardew-architecture.md 做质量锚(模仿密度,不抄内容), - 往 templates/architecture.md 里填。 -3. 记住顶层的核心循环图——切完必须跑覆盖检查。 - -## 三、十二节总览:写什么、为什么、怎么咬合 - -架构文档回答四个问题: -**这个架构为什么这样切(1~3)→ 系统是什么、怎么连接(4~6)→ -怎么落地、怎么验证(7~11)→ 还有什么没想清(12)。** - -第 1 节承顶层的定稿约束开篇,MVP 闭环在中间当守门员,开放问题收尾。 - -| # | 节 | 是什么 | 为什么写 | 和谁咬合 | -|---|---|---|---|---| -| 1 | 架构定位与目标 | 阶段边界(定哪些系统、不展开内部)+ 划分原则 + 一句话架构 + **变更记录** | 防止架构漂离顶层;改刀可追溯 | 承顶层定稿;变更记录引登记编号 | -| 2 | 系统地图 | Sxx 编号清单(=系统文档目录真源)+ 支撑层 + P0 段五列表(目的/输入/输出/P0原因) | 编号让系统可引用;P0 原因逼答"删了塌什么" | **对下真源**:Sxx ↔ 04 系统文档一一对应 | -| 3 | 系统职责 | 职责表(负责/不负责→移交谁)+ 逐系统说明段 | 边界写死,防两个系统管同一件事 | 系统文档的"边界与非目标"必须与此对齐 | -| 4 | 依赖与数据流 | 依赖图(无环)+ 数据流图 + 主要状态 + 主数据归属规则 | 谁读谁、数据从哪到哪——接口的真源 | 顶层的资源流图在此展开成系统级 | -| 5 | 核心循环覆盖检查 | 顶层每个循环环节 → 认领系统 | 顶层→架构的验收线,防切系统切碎循环 | 对上接口:逐环节对照顶层循环图 | -| 6 | 目录映射 | 职责 → 物理文档目录的归并表 | 职责数≠文档数;归并规则显式化 | **对下接口**:系统文档站照此开工 | -| 7 | MVP 最小闭环 | 编号验证链 + 守门句("闭环不成立不许加东西") | 立项后第一条要跑通的链 | 对应顶层验证标准;失败回顶层而非加系统 | -| 8 | 统一数值基准 | 单位清单 + 四类定性基准(时间/货币/成长/体力风险的风格约束) | 各系统单独配数值会互相失衡;先定全局尺度 | **数值换算与验算归技术文档层**,此处只到定性 | -| 9 | 系统边界 | 哪些功能明确不属于任何系统/归引擎层/归呈现层 | 显式排除,防范围蔓延 | 承概念层"不是什么" | -| 10 | 优先级与范围 | P0/P1/P2 三档(P1/P2 可用能力表) | 拆分≠全做;裁剪顺序显式化 | P0 = MVP 闭环的系统集 | -| 11 | 风险与校验 | 风险/校验方式表 | 架构级风险提前挂出,每条带检验法 | 对应顶层验证标准与概念层跑偏风险 | -| 12 | 开放的结构问题 | 结构级未定案 | 显式债务 | 进分析文档或系统文档开题 | - -咬合一图: - -``` -顶层定稿 + 系统范围表(粗清单) - ↓ 正式切分(拆/并/裁) -1 定位与目标 ──► 2 系统地图(Sxx 真源)──► 3 职责表 - ↓ ↓ ↓ -5 循环覆盖检查 ◄── 4 依赖与数据流(接口真源) - ↓ -6 目录映射 ──► 7 MVP 最小闭环(守门员) - ↓ -8 数值基准(定性)· 9 边界 · 10 优先级 · 11 风险校验 - ↓ -12 开放问题 →(进分析文档 / 系统文档站开题) -``` - -三个接口:**对上**承顶层系统范围表并跑循环覆盖检查;**对内**地图↔职责↔依赖 -三方一致、主数据归属唯一;**对下**目录映射 + MVP 闭环喂系统文档站。 - -## 四、怎么写(模板即流程,十二节按序) -(本节是带写法要领的教学版;实际填写的纯净模板在 templates/architecture.md) - -### 1. 架构定位与目标 -本阶段确定"哪些系统支撑一轮玩法",不展开单系统内部规则。 -划分原则:__。一句话架构: -> (玩家通过哪些系统、以什么因果,把一轮玩法的输入变成下一轮的选择) -变更记录:日期 + 改了什么 + 为什么(引登记编号)。 -→ 没有变更记录的架构文档,第二轮迭代就会变成黑箱。 - -### 2. 系统地图 -Sxx 编号清单(核心系统 2~12 个)+ 支撑层(存档/UI,不拥有核心规则)。 -P0 段五列表: -| 系统 | 目的 | 输入 | 输出 | P0 原因 | -→ 每行 P0 原因必须答"删了它,__ 塌";答不出的降级或合并。 - -### 3. 系统职责 -| 系统 | 主要职责 | 不负责 → 移交谁 | -→ "不负责"列必填且指向具名系统;再为争议最大的 2~3 个系统各写一段 -说明(负责什么 / 不负责什么 / 只负责什么)。 - -### 4. 依赖与数据流 -依赖图(mermaid,呈现层用虚线"读取状态")+ 数据流图(资源从产到耗)。 -主要状态:全局/玩家/场景/社会 四类。 -主数据归属规则:规则与数据表分工 / 稳定 ID 关联 / 任何系统不复制他系统主数据。 -→ 依赖图出现环 = 回去重切。 - -### 5. 核心循环覆盖检查 -| 顶层循环环节 | 认领系统 | -→ 逐环节对照顶层循环图;有环节无人认领或多人认领都是切分错误。 - -### 6. 目录映射 -| 目录 | 本阶段定位 | -→ 职责可以归并进同一文档目录(官方版 8 职责→3 文档);归并规则写明。 -系统文档站以此开工:地图上没有的系统不许有文档。 - -### 7. MVP 最小闭环 -1. __ 2. __ …(编号验证链,一条玩家可走的完整因果) -守门句:如果这条闭环不成立,不应继续增加 __。 -→ 闭环失败回顶层改设计,不是加系统打补丁。 - -### 8. 统一数值基准(定性) -全局单位清单(如时间片/游戏日/货币/体力/经验)+ 四类风格约束 -(时间节奏/货币量级感/成长回报取向/体力风险档位)。 -→ 只写到定性;具体换算、验算数值由技术文档层(数值策划)承接。 - -### 9. 系统边界 -明确排除项(不拆出独立 __ 系统 / __ 归引擎层 / __ 归呈现层)。 - -### 10. 优先级与范围 -P0(最小闭环必需):__;P1(完整体验):__;P2(扩展内容):__。 -P1/P2 可用能力表(能力/说明)控制颗粒度。 - -### 11. 风险与校验 -| 风险 | 校验方式 | -→ 从概念层跑偏风险和顶层失败档位反推;校验方式要可观察。 - -### 12. 开放的结构问题 -→ 结构级(接口归属/统一格式/合并拆分)才留这里;数值细节不留。 - -## 五、分析文档(全局一份,按层分节) - -**全局唯一一份《分析.md》**(项目根),本层不另设分析文件(2026-09-06 收敛: -原每层一份 analysis 合并为全局一份——论证按发生层归节,决定登记表全项目 -只此一张,跨层引用只查这里)。模板与例子:资源 `templates/analysis.md`、 -`exemplars/stardew-analysis.md`。状态池(灵感池/代决/待原型等活队列)在决策台账, -不放分析文档——本文件只放已决论证与登记。 - -- 条目格式:`## 问题:<一句话>` + 状态(agent_proposal / user_confirmed / - superseded,登记 D-__)+ 广度分析(牵动面+候选 ≥2)+ 深度分析 - (逐候选利弊依据,必须引 T 原则/锚点/张力编号,写不出依据的偏好不进分析) - + 综合判断(建议取 __ 因为 __;推翻条件:__)。 -- 分诊三条件全满足才进:① 影响项目方向或边界;② ≥2 合理候选;③ 一时定不了。 - 不满足的:就地小权衡直接进登记表一行,不写条目。 -- 本层标准问题:结构级争议——接口统一、系统归并、主数据归属划分。(本层原本不配独立分析文件,结构争议全归全局文件本节。) -- 数量纪律:按需;架构期问题多为接口与归属二义。 -- user_confirmed 后三件事:结论一句话迁入 design.md 对应节(留修订痕迹); - 登记表加行(编号全项目连续,跨层引用写 D-__);本条目改状态记 D 号保留不删。 - 推翻时新增行挂旧行编号,旧行不删。 - - -## 六、写完自查(参考,不是闸门) -- 每个 Sxx 都能一句话答"删了它什么塌"吗? -- 顶层的循环环节全覆盖、无重复认领吗? -- 依赖图无环?主数据无一物两管? -- 系统文档站拿到目录映射能直接开工吗? -- 有没有字段定义或数值配置偷偷写进来?(该在技术文档层) -- 变更记录补了吗——这次切分和上次的差异说得清吗? - -## 七、红线(只有三条) -1. 不冒充用户决定:用户没说的方向标"待确认",正文不写死。 -2. 不越层:向上不翻顶层的案,向下不写系统内部规则,数值字段归技术文档层。 -3. 不凑数:系统数量不是成绩,写不出 P0 原因的系统就是该删的系统。 - - - - -## A4 系统文档分册(game-gdd-system-doc) - ---- -name: game-gdd-system-doc -description: 写单个系统的设计文档(Sxx)时的总纲——通用纪律、十二节同构骨架、 - 红线与分析文档格式。每类系统的专属写法与模板在 modules/system-types/ 下对应目录的 SKILL.md - 与对应模块的模板.md 里,按需取用。 ---- - -# 系统文档写法(策划 agent · 系统文档分册 · 总纲) - -> 本文件是系统文档层的总纲;各系统的专属写法在 `modules/system-types/` 下对应目录的 `SKILL.md`, - 专属模板在 `modules/system-types/` 对应目录的 `模板.md`。通用纪律不在各系统 skill 里重复。 - -## 一、这一层的判断立场 -你是写单个系统的策划。在这个层里你相信: -- 系统文档是**执行层**:刀已经在架构层切好——服从系统地图编号、职责表 - 边界、依赖图方向,无权改刀;发现切错了,提分析、记登记,不私自扩边界。 -- 一个系统文档的成败在**边界节**:"不负责什么、移交给谁"那几行是 - 防返工价值最高的几行。 -- 接口纪律:引用具名系统与具名数据,禁泛称;别家主数据只引 ID 不复制。 -- 字段定义、数值配置、表结构不归你——写交接声明,交技术文档层(数值策划)。 -- 所有系统同构:读者读熟一份就能读所有份。 - -## 二、动笔前 -1. 架构已定稿:找到本系统的 Sxx 编号、职责表行、依赖方向——这是合同。 -2. 在 01~12 文件夹里选最接近的系统类型(可组合,如"钓鱼"=05 采集+06 战斗 - 的判定部分),读取对应的 `SKILL.md` 与 `模板.md`。 -3. 该文件夹标注"必读例子"的,先读例子全文做密度锚。 - -## 三、十二节总览:写什么、为什么、怎么咬合 - -系统文档回答四个问题: -**这个系统为什么存在(1~2)→ 玩家怎么用它(3~5)→ 它怎么运转(6~8)→ -它怎么和别人连接、不碰什么(9~12)。** - -| # | 节 | 是什么 | 为什么写 | 和谁咬合 | -|---|---|---|---|---| -| 1 | 系统目的 | 一句话:删了它什么塌 | 存在性检验 | 架构 P0 原因的展开 | -| 2 | 支撑的玩家体验 | 对应顶层目标第几条 | 防系统自嗨 | 顶层设计目标 ↔ 本系统 | -| 3 | 进入与退出 | 何时进入、何时/如何退出 | 循环的接口时刻 | 顶层的循环环节 | -| 4 | 玩家行动 | 具名动词组 | 玩家用手玩 | 系统类型卡给动词组 | -| 5 | 取舍表 | 玩家在本系统内的决策 | 张力在系统内的落地 | 概念张力→顶层取舍表→本表 | -| 6 | 状态与规则 | 对象/状态/转换/异常,枚举表达 | 定性规则真源 | 架构职责表对齐 | -| 7 | 数值与数据交接 | 本系统交 TDD 的数据类别+定性约束 | 分层边界 | 技术文档层承接 | -| 8 | 反馈 | 何时/何强度/何通道 | 无反馈=没发生 | 顶层反馈四层 | -| 9 | 内部循环 | 本系统内的小循环 | 系统自己的心跳 | 顶层小循环的组成 | -| 10 | 输入、输出与依赖 | 消费/交付/依赖谁 | 接口真源 | 架构依赖图逐边对齐 | -| 11 | 边界与非目标 | 不负责什么→移交谁 | **防返工价值最高** | 架构职责表"不负责"列 | -| 12 | 开放问题 | 本系统未定案 | 显式债务 | 进分析文档 | - -咬合:**对上**服从架构三条合同(编号/职责/依赖);**对内**状态与接口不越 -职责边界;**对下**第 7 节交接喂 TDD。 - -## 四、十二节通用写法 -(各系统类型的特殊写法见对应文件夹 SKILL.md;纯净模板在其 模板.md) - -1 系统目的:若删除它,__ 会塌——一句话说不出 = 该系统不该存在。 -2 支撑体验:对应顶层目标第__条、调性原则第__条。 -3 进入与退出:常规进入/读档恢复/特殊事件后返回,三入口必写。 -4 玩家行动:≥4 个具名动词组;编排类写"安排"动词,活动类写"操作"动词。 -5 取舍表:决策/立即收益/延迟收益/主要代价;挂顶层张力编号。 -6 状态与规则:对象-状态-转换-异常,全部枚举表达,不许整段散文。 -7 数值与数据交接:列数据类别名 + 设计侧定性约束;字段定义归 TDD。 -8 反馈:每种关键结果给独立反馈形态;失败必须说明原因和恢复路径。 -9 内部循环:动词链;可拆单次/区域/长期三层。 -10 输入输出与依赖:引用具名系统与具名数据,禁泛称"资源"。 -11 边界与非目标:照该类型 skill 的"三不"写全;必含"字段数值归 TDD"一条。 -12 开放问题:结构级才留;手感数值类标"待原型验证"。 - -## 五、分析文档(全局一份,按层分节) - -**全局唯一一份《分析.md》**(项目根),本层不另设分析文件(2026-09-06 收敛: -原每层一份 analysis 合并为全局一份——论证按发生层归节,决定登记表全项目 -只此一张,跨层引用只查这里)。模板与例子:资源 `templates/analysis.md`、 -`exemplars/stardew-analysis.md`。状态池(灵感池/代决/待原型等活队列)在决策台账, -不放分析文档——本文件只放已决论证与登记。 - -- 条目格式:`## 问题:<一句话>` + 状态(agent_proposal / user_confirmed / - superseded,登记 D-__)+ 广度分析(牵动面+候选 ≥2)+ 深度分析 - (逐候选利弊依据,必须引 T 原则/锚点/张力编号,写不出依据的偏好不进分析) - + 综合判断(建议取 __ 因为 __;推翻条件:__)。 -- 分诊三条件全满足才进:① 影响项目方向或边界;② ≥2 合理候选;③ 一时定不了。 - 不满足的:就地小权衡直接进登记表一行,不写条目。 -- 本层标准问题:① 本系统与相邻系统的边界在哪;② 本系统内部哪个规则影响顶层取舍。条目标系统号(如 S06)。 -- 数量纪律:按需;每系统通常 0~1 条,超了先回读架构职责表。 -- user_confirmed 后三件事:结论一句话迁入 design.md 对应节(留修订痕迹); - 登记表加行(编号全项目连续,跨层引用写 D-__);本条目改状态记 D 号保留不删。 - 推翻时新增行挂旧行编号,旧行不删。 - - -## 六、写完自查(参考,不是闸门) -- 目的一句话成立吗?边界节和架构职责表逐行对齐吗? -- 输入输出和依赖图逐边对上吗?有没有泛称漏网? -- 状态是枚举还是散文?失败路径给了原因和恢复吗? -- 有没有字段或数值偷偷写进来?(该在 TDD) -- 同构检查:另一份系统文档的读者能按同样方式读这份吗? - -## 七、红线(只有三条) -1. 不冒充用户决定:用户没说的方向标"待确认",正文不写死。 -2. 不越层:不翻架构的案(要改走分析文档+登记表),不写字段数值(归 TDD), - 不替别的系统定规则。 -3. 不凑数:写不出"删了塌什么"、填不满的节,说明缺料——停笔说明,不硬凑。 - - - - -## A5 技术文档分册(game-tdd) - ---- -name: game-tdd -description: 写游戏技术文档(TDD)时使用的总纲。GDD 四层定稿后的第五步:把 - "怎么做"写实——程序怎么写、美术怎么做、字段怎么定义、怎么配表。 - 三大件各有专属分册:技术实现(程序侧)/ 美术圣经(美术侧)/ 数据与配表(数据侧)。 ---- - -# 技术文档写法(策划 agent · TDD 分册 · 总纲) - -> 本文件是 TDD 层唯一承载写作流程的教学件;各分册 SKILL 与模板配套使用。 -> 模板与例子文件保持纯净:不含任何步骤、检验提示与标记。 - -## 〇、TDD 的完成判据(总纲) - -**TDD 是自足构建包:一个施工 agent 只看 TDD,就能做完完整游戏。** -GDD 是设计真源(给人看、给迭代看);TDD 是构建真源(给施工看)。 -检验方式=自足性检查(见总册):不看 GDD 能否回答——每个系统怎么行为、 -每张表多少行内容、每个界面怎么走、每份素材什么规格。答不出的项就是缺口, -缺口回 GDD 同步后**收编**进 TDD(带版本锁)。收编是构建期快照:GDD 定稿 -变更 → 触发对应收编节重同步(与 fast_gdd 投影同一机制,方向相反)。 - -## 一、这一层的判断立场 - -你是工程师思维的策划。GDD 是"用户视角的功能描述",TDD 是"实现者视角的 -架构性描述"——你不重复设计的论证(为什么这样设计,去 GDD 和 analysis 查), -只写怎么落地。你相信: - -- **交接契约是 TDD 最大的价值**:美术交给程序的素材、程序读的表、加载的 - 顺序——每一条缝都写死。缝上不写死,返工就在缝里发生。 -- **平台事实优先**:目标运行时由 GDD 平台事实锁定——**HTML / Unity / Godot / - Cocos 四选一**。HTML 项纯 HTML/CSS/JS 交付;引擎项支持打开引擎工程、自然 - 语言协作改素材与代码,由陶泥儿驱动引擎**弹窗预览**、驱动引擎 **CLI 导出**。 - 一切技术选择先过所选运行时这道闸,不推荐该运行时做不出来的东西; - TDD 不擅自换运行时。 -- **一个事实只有一个写权**:每张表、每条主数据都有唯一拥有者系统, - 其他系统只引用不复制(GDD 架构层主数据归属规则在 TDD 落成表结构)。 -- **验收是硬闸不是仪式**:有 blocker 禁止扩充内容——这条竞品四十轮实测 - 验证过,照抄。 -- **先少量验证再量产**(美术)/ **先建索引再转表**(数据)——任何方向都 - 不做"做完一大批才发现不对"的事。 - -## 二、TDD 与 GDD 的接口(输入从哪来) - -| 输入 | 来自 | 喂给哪件 | -|---|---|---| -| 系统范围表 + P0 清单 + 主数据归属规则 | 架构层 | 三件共用(拆表与拆模块依据) | -| 各系统「数值与数据交接」节 + 定性约束 | 系统文档 | 数据侧(直接订单) | -| 定调记录(参照/滑杆/T 原则)+ 身份基调 | 概念层 | 美术圣经(视觉翻译源头) | -| 技能选型卡 | skill 库 | 程序侧+美术圣经(@版本+参数实例化) | - -TDD 不回头改 GDD:发现 GDD 没写清楚的点,走「开放问题回执」——该问用户 -的升级决策卡,该代决的记台账(带理由和推翻条件),结论回写对应层,TDD 只 -登记去向。顾问期(开发阶段)同一出口:程序美术卡点、成品与文档偏差,都从 -回执进、修订出(v{N+1})。 - -## 三、三大件与开工顺序 - -| 件 | 管什么 | 读者 | 分册 | -|---|---|---|---| -| 数据与配表 | 字段定义、表结构、数值、验收 | 数值策划 + 程序 | 03 | -| 技术实现 | 代码组织、场景镜头、输入、音频、性能预算、验证 | 程序 | 01 | -| 美术圣经 | 视觉锚、素材规格契约、量产流程 | 美术 | 02 | - -**顺序:数据侧 → 程序侧 → 美术圣经**。数据侧先开的理由:它是唯一直接被 -GDD 喂的(系统文档交接节就是订单);程序侧的加载与验证要引用表结构;美术 -圣经的素材总清单要引用物品表(每个可见对象绑定 item_id 或显式豁免)。小型 -项目三件可交叉,但**表结构永远先于数值填充**。 - -## 四、怎么写(总纲级;细节在各分册) - -1. 数据侧:总清单拆表 → ID 与字段字典 → 公共条件表 → 建表顺序(物品表 - 起步)→ 表结构契约(程序签名)→ 数值填充(代决+台账)→ 验收七查。 -2. 程序侧:系统实现总览(每系统一段话写死怎么做)→ 技术选型与 skill 引用 - → 场景与镜头 → 输入与操作 → 音频 → 验证方式与性能预算。 -3. 美术圣经:视觉锚(从概念层定调翻译)→ 素材规格契约逐素材一行 → - 量产流程(概念候选→锚点确认→小批→验收→扩产)→ 资产总清单。 - -## 五、写完自查(参考,不是闸门) - -- 任意一条缝(美术→程序、表→代码、表→表引用)是否都写死了规格? -- 每张表是否答得出"谁是拥有者系统"?每个 ID 是否全局唯一? -- 程序侧验证方式是否可执行(跑什么命令、看什么输出)? -- 素材契约是否覆盖了 GDD 里全部可见对象(或显式豁免)? -- 验收是否跑过且无 blocker? - -## 六、红线(只有四条) - -1. **收编必带版本锁**:从 GDD 收编的任何内容标注"基于系统文档@v{N}"; - 无锁收编=违规(双源漂移之源)。TDD 不产生设计观点,只汇集与落实施工。 -2. 引用必带版本:skill 引用必须 `名字@版本 + 实例化参数`,选型时与执行时 - 用的一致性靠此保证。 -3. 不越权拍板:产品级取舍回 GDD 层走决策流程;TDD 只做技术代决且记台账。 -4. 表里不写散文:单元格只有数据和枚举;规则写在契约文档,不写在表里。 +本分册说明单个系统的职责、规则、输入输出、反馈、边界、验证和分析记录。完整内容请阅读 `resources/skills/systems.md`;系统类型的专属写法和模板请按需阅读 `modules/system-types/` 下对应分册。 diff --git a/apps/ai-game-creator-shell/src-tauri/design-agent/resources/skills/top_design.md b/apps/ai-game-creator-shell/src-tauri/design-agent/resources/skills/top_design.md index 0f720e181..0eeba8577 100644 --- a/apps/ai-game-creator-shell/src-tauri/design-agent/resources/skills/top_design.md +++ b/apps/ai-game-creator-shell/src-tauri/design-agent/resources/skills/top_design.md @@ -80,7 +80,7 @@ description: 写游戏策划案(GDD)顶层设计时使用。在概念层定 (大⇄小⇄最小单位)+ 资源三段全;**对下**系统范围表喂架构的系统地图、 顶层定稿当架构的紧箍咒、验证标准当原型试玩判据。 -## 四、怎么写(模板即流程,十六节按序) +## 四、怎么写(模板参考结构,建议按此组织) (本节是带写法要领的教学版;实际填写的纯净模板在 templates/top-design.md) ### 1. 顶层定位与规模锚点 diff --git a/apps/ai-game-creator-shell/src-tauri/design-agent/system-prompt.md b/apps/ai-game-creator-shell/src-tauri/design-agent/system-prompt.md index 0850865e8..3807f565e 100644 --- a/apps/ai-game-creator-shell/src-tauri/design-agent/system-prompt.md +++ b/apps/ai-game-creator-shell/src-tauri/design-agent/system-prompt.md @@ -1,12 +1,16 @@ 你是游戏策划协作 Agent,与用户持续协作完成游戏设计。像普通策划同事一样交流,使用工作区文件工具读写资料;所有文件路径使用相对路径。根据当前对话、阶段上下文和已有文档决定下一步行动。修改文件后,简要说明修改内容和相对路径。对不确定内容区分用户确认、Agent 建议和待原型验证事项;不要把建议写成用户已确认的决定。 -优先完成能够依据已有信息推进的工作,不要为每个设计空白都询问用户。局部、可逆的问题可以先提出合理方案并标为暂定。会影响当前阶段范围、关键规则、下游实现或其他重要方向,且必须由用户决定的问题,应先通过纯文本或问询工具询问,等待用户回答,并据此更新相关产物;不要带着这类未决问题提交阶段审批。 +优先完成能够依据已有信息推进的工作,不要为每个设计空白都询问用户。局部、可逆的问题可以先提出合理方案并标为暂定。会影响当前阶段范围、关键规则、下游实现或其他重要方向,且必须由用户决定的问题,应先通过纯文本或问询工具询问,等待用户回答。决定稳定后,再更新受影响的正式产物和必要的过程记录;不要带着这类未决问题提交阶段审批。 + +分析阶段优先记录当前目标、上层约束、候选方案、取舍、用户已确认或 Agent 暂定的边界,以及必须检查的验收项。除非用户明确要求展开讨论,不要先在回复中逐节起草与正式文档重复的长篇正文;形成结论后直接写入正式产物,再进行一次必要的一致性检查。文件操作前只需说明简短计划、目标文件和主要变化。 正式策划文档在文档头部写明版本标记,例如“版本:v1”。由你自行维护版本号:只有整体修订、阶段性定稿或用户意见造成实质内容变化时才递增;错别字、措辞润色、单个局部修改和小范围补充不单独递增。 阶段审批是每个阶段的最终检查,表示本阶段产物已经完成,无未决内容,交给用户做最终检阅,不承担问询功能。提交前,解决所有影响本阶段完成的关键问题,或明确说明它们不阻塞本阶段交付,并更新相关产物。可以保留不阻塞当前阶段的后续事项和待原型验证项。 +过程文档用于记录关键依据、决定和待办,不要求实时完整,也不应重复正式设计文档。阶段内优先完成主要设计内容;只有稳定且影响后续工作的决定才需要同步到多个过程文档。阶段提交前,补齐影响验收的关键记录。 + 阶段获批后,产物中已经采用的方案作为后续工作的依据,并保留原有决策来源。除非用户主动质疑或出现新的约束冲突,不要反复要求确认历史暂定决定。 用户说“继续”时,继续推进当前阶段最有价值的工作。判断本阶段已完成并准备交用户检阅时,应调用 `submit_phase_for_approval`;只有该工具调用成功,才算正式提交审批。 diff --git a/apps/ai-game-creator-shell/src-tauri/design-agent/tools.json b/apps/ai-game-creator-shell/src-tauri/design-agent/tools.json index 06c643c6b..c9c1bd6cf 100644 --- a/apps/ai-game-creator-shell/src-tauri/design-agent/tools.json +++ b/apps/ai-game-creator-shell/src-tauri/design-agent/tools.json @@ -2,7 +2,7 @@ {"type":"function","function":{"name":"get_workflow_status","description":"读取当前策划工作流状态,只返回阶段列表、当前阶段、已批准阶段和待审批阶段;不推进阶段、不提交审批、不修改文件。","parameters":{"type":"object","properties":{},"additionalProperties":false}}}, {"type":"function","function":{"name":"list_resources","description":"列出固定资源的逻辑目录、资源 ID、标题和简介。资源是只读的随包文档;不要猜测物理路径。","parameters":{"type":"object","properties":{},"additionalProperties":false}}}, {"type":"function","function":{"name":"read_resource","description":"读取一份固定资源文档全文。每次读取一个 resource_id;资源只读。读到未实现占位文档时由你自行判断和处理。","parameters":{"type":"object","properties":{"resource_id":{"type":"string"}},"required":["resource_id"],"additionalProperties":false}}}, - {"type":"function","function":{"name":"patch_file","description":"局部修改 UTF-8 文件,优先用于已有文件的小范围修订。先读文件,以唯一且非空的 old_text 精确匹配并替换为 new_text;new_text 为空可删除片段,保留原文并追加可插入。匹配失败不修改文件。path 使用相对路径。","parameters":{"type":"object","properties":{"path":{"type":"string"},"old_text":{"type":"string"},"new_text":{"type":"string"}},"required":["path","old_text","new_text"],"additionalProperties":false}}}, + {"type":"function","function":{"name":"patch_file","description":"局部修改 UTF-8 文件。使用 old_text/new_text,或使用 edits 一次进行多个独立替换;每个 old_text 必须非空且在原文件中唯一,匹配失败、重复或范围重叠时不修改文件。path 使用相对路径。","parameters":{"type":"object","properties":{"path":{"type":"string"},"old_text":{"type":"string"},"new_text":{"type":"string"},"edits":{"type":"array","items":{"type":"object","properties":{"old_text":{"type":"string"},"new_text":{"type":"string"}},"required":["old_text","new_text"],"additionalProperties":false}}},"required":["path"],"additionalProperties":false}}}, {"type":"function","function":{"name":"delete_path","description":"谨慎使用;永久删除工作区内的文件或目录;目录会连同全部内容递归删除,不备份。先确认目标及删除范围。path 使用相对路径,不能删除工作区根目录,也不能经过链接。","parameters":{"type":"object","properties":{"path":{"type":"string"}},"required":["path"],"additionalProperties":false}}}, {"type":"function","function":{"name":"list_dir","description":"列出工作目录内的文件和目录。path 使用相对路径。","parameters":{"type":"object","properties":{"path":{"type":"string"}},"required":["path"],"additionalProperties":false}}}, {"type":"function","function":{"name":"read_file","description":"读取工作目录内的 UTF-8 文本文件。path 使用相对路径。","parameters":{"type":"object","properties":{"path":{"type":"string"}},"required":["path"],"additionalProperties":false}}}, diff --git a/apps/ai-game-creator-shell/src-tauri/resources/agc-skills/agc-game-production-workflow/SKILL.md b/apps/ai-game-creator-shell/src-tauri/resources/agc-skills/agc-game-production-workflow/SKILL.md index f02b45374..82a42ddee 100644 --- a/apps/ai-game-creator-shell/src-tauri/resources/agc-skills/agc-game-production-workflow/SKILL.md +++ b/apps/ai-game-creator-shell/src-tauri/resources/agc-skills/agc-game-production-workflow/SKILL.md @@ -19,8 +19,14 @@ Use this Skill as the top-level SOP for a new game or a substantial game brief. ## Stage transitions -Advance only when the current stage has its output: brief → inventory; inventory → art decision; art decision → usable registered assets or an explicit no-art decision; implementation → source references to those assets; build → playable entry; playtest → evidence; delivery → truthful report. If a tool fails, preserve its error and stop or repair at that stage instead of silently substituting a later-stage placeholder. +Advance only when the current stage has its output: brief → inventory; inventory → art decision; art decision → usable registered assets or an explicit no-art decision; implementation → source references to those assets; build → playable entry; playtest → evidence; delivery → truthful report. If a tool fails, preserve its error and handle it under "Error handling" instead of silently substituting a later-stage placeholder. For a small edit to an existing game where the brief and suitable assets are unchanged, use the focused edit path and do not regenerate art. This exception does not apply to a new game or a substantial planning brief. +## Error handling + +When a stage tool, command, or verification fails, retry at most three times before treating that stage as failed. Keep the retries serial and scoped to the same stage and the same input: a retry must not open a parallel path, skip ahead to a later stage, or substitute a placeholder for the missing output. + +Only after the third attempt also fails, stop and tell the user the failure reason — which stage failed, which tool or command reported the error, what the error says, and what is still missing. A stage whose three attempts never succeeded is not complete, and its missing output cannot be reported as delivered. + Read the referenced specialist Skills for their detailed contracts: `agc-project-structure`, `taonier-art-assets`, `agc-web-game-development`, `agc-client-projection`, and `agc-browser-playtest`. diff --git a/apps/ai-game-creator-shell/src-tauri/resources/agc-skills/manifest.json b/apps/ai-game-creator-shell/src-tauri/resources/agc-skills/manifest.json index 72dbdf5fb..76de3bbc3 100644 --- a/apps/ai-game-creator-shell/src-tauri/resources/agc-skills/manifest.json +++ b/apps/ai-game-creator-shell/src-tauri/resources/agc-skills/manifest.json @@ -1,6 +1,6 @@ { "schemaVersion": "agc-skill-pack.v1", - "version": "2026-08-26.13", + "version": "2026-08-26.14", "skills": [ { "name": "agc-game-production-workflow", @@ -22,7 +22,7 @@ "agents/openai.yaml", "references/workflow-contract.md" ], - "sha256": "91082fdff4123f1e1fcf930af433cbea51a8c9d26991678b19028b344ea49f39" + "sha256": "d9d8e7e0a6bc512e0b463e0e4bd77edee1cc57f4a6965c9553e0920e38985d5c" }, { "name": "agc-project-structure", diff --git a/apps/ai-game-creator-shell/src-tauri/resources/agc-skills/taonier-art-assets/SKILL.md b/apps/ai-game-creator-shell/src-tauri/resources/agc-skills/taonier-art-assets/SKILL.md index 8d63beb92..d652b4436 100644 --- a/apps/ai-game-creator-shell/src-tauri/resources/agc-skills/taonier-art-assets/SKILL.md +++ b/apps/ai-game-creator-shell/src-tauri/resources/agc-skills/taonier-art-assets/SKILL.md @@ -19,6 +19,12 @@ image, UI design image, or publication material; use `agc_edit_image` for an edit of an existing registered image; use `taonier_prepare_game_art` only for the complete game-art package and its canonical slices. +When `agc_generate_image` is used with `kind="art-spritesheet"`, pass +`sliceMode="connected-components"` (the default alpha-connectivity splitter) +or `sliceMode="grid"` with `gridX` and `gridY` (1-32 each). The selected mode is carried +through the client request and returned result; do not infer it from the number +of slices. + ## Authorization boundary `agc_tools` is an AGC client-owned bridge to the AGC backend. In the normal client build it uses the current client login session and account routes; the user and model never need to provide, configure, paste, create, or rotate an API Key, Token, Cookie, URL, or `.env` value. If the tool returns `401` or `403`, report only that the AGC client login or permission state is unavailable, stop the operation, and do not ask the user for credentials or expose an internal URL. diff --git a/apps/ai-game-creator-shell/src-tauri/resources/agc-skills/taonier-art-assets/references/platform-art-contract.md b/apps/ai-game-creator-shell/src-tauri/resources/agc-skills/taonier-art-assets/references/platform-art-contract.md index 9a04e1256..bf0b74481 100644 --- a/apps/ai-game-creator-shell/src-tauri/resources/agc-skills/taonier-art-assets/references/platform-art-contract.md +++ b/apps/ai-game-creator-shell/src-tauri/resources/agc-skills/taonier-art-assets/references/platform-art-contract.md @@ -15,6 +15,7 @@ - On timeout or uncertain delivery, reuse the recorded operation; never create a replacement request. - `postprocess-failed-source-preserved` means the complete provider source remains usable, but the requested transparent derivative is absent. - `sliceWarning` means the complete transparent sheet remains usable, but individual slices are absent. +- For direct `agc_generate_image` spritesheet requests, `sliceMode="connected-components"` selects alpha-connectivity detection and `sliceMode="grid"` uses the caller-provided `gridX` and `gridY` (1-32 each). The client preserves the selected mode and grid dimensions in the request identity and result metadata. - General and slice warnings can coexist. The tool returns them separately through `warnings` and `sliceWarnings`; callers must preserve every entry and must not downgrade a slice warning into a successful independent-asset claim. - `assetPaths` contains the complete package paths. `slicePaths` contains only slices that the client downloaded, validated, and registered with their platform source identities. - `resources` contains only safe registered identity fields: local asset/path/kind/media type, Canvas project/resource/asset/task IDs, and reference resource IDs. It never exposes prompts, models, provider routes, absolute paths, URLs, tokens, cookies, or API keys. diff --git a/apps/ai-game-creator-shell/src-tauri/src/agent.rs b/apps/ai-game-creator-shell/src-tauri/src/agent.rs index 35377ee7d..d084e6174 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/agent.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/agent.rs @@ -28,6 +28,7 @@ mod prompt; mod runtime_actions; mod runtime_adapter; mod runtime_driver; +mod runtime_error; mod runtime_protocol; mod runtime_state; mod runtime_tools; @@ -56,6 +57,7 @@ pub(crate) use prompt::*; pub(crate) use runtime_actions::*; pub(crate) use runtime_adapter::*; pub(crate) use runtime_driver::*; +pub(crate) use runtime_error::*; pub(crate) use runtime_protocol::*; pub(crate) use runtime_state::*; pub(crate) use runtime_tools::*; diff --git a/apps/ai-game-creator-shell/src-tauri/src/agent/codex_app_server/mod.rs b/apps/ai-game-creator-shell/src-tauri/src/agent/codex_app_server/mod.rs index 17f96f93f..a86ef26b5 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/agent/codex_app_server/mod.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/agent/codex_app_server/mod.rs @@ -276,6 +276,51 @@ fn game_creator_codex_app_server_error_kind(kind: &str) -> platform_llm::LlmErro )) } +fn game_creator_codex_app_server_error_kind_with_machine_detail( + kind: &str, + error: &serde_json::Value, +) -> platform_llm::LlmError { + let mut fields = Vec::new(); + if let Some(object) = error.as_object() { + if let Some(code) = object.get("code").and_then(serde_json::Value::as_str) { + if !code.is_empty() + && code.len() <= 80 + && code + .bytes() + .all(|byte| byte.is_ascii_alphanumeric() || b"._-".contains(&byte)) + { + fields.push(format!("code={code}")); + } + } + let keys = object + .keys() + .filter(|key| { + matches!( + key.as_str(), + "httpConnectionFailed" + | "responseStreamConnectionFailed" + | "responseStreamDisconnected" + | "responseTooManyFailedAttempts" + | "activeTurnNotSteerable" + | "codexErrorInfo" + ) + }) + .cloned() + .collect::>(); + if !keys.is_empty() { + fields.push(format!("fields={}", keys.join(","))); + } + } + let suffix = if fields.is_empty() { + String::new() + } else { + format!(" detail={}", fields.join(" ")) + }; + platform_llm::LlmError::InvalidRequest(format!( + "{GAME_CREATOR_CODEX_APP_SERVER_ERROR_KIND_PREFIX}{kind}{suffix}" + )) +} + fn game_creator_codex_app_server_error_http_status( info: &serde_json::Value, field: &str, @@ -430,7 +475,7 @@ fn game_creator_codex_app_server_failed_turn_error( return game_creator_codex_app_server_error_kind("unauthorized"); } let Some(info) = error.get("codexErrorInfo").filter(|info| !info.is_null()) else { - return game_creator_codex_app_server_error_kind("other"); + return game_creator_codex_app_server_error_kind_with_machine_detail("other", error); }; if let Some(kind) = info.as_str() { return match kind { @@ -454,8 +499,8 @@ fn game_creator_codex_app_server_failed_turn_error( game_creator_codex_app_server_error_kind("thread-rollback-failed") } "sandboxError" => game_creator_codex_app_server_error_kind("sandbox-error"), - "other" => game_creator_codex_app_server_error_kind("other"), - _ => game_creator_codex_app_server_error_kind("other"), + "other" => game_creator_codex_app_server_error_kind_with_machine_detail("other", error), + _ => game_creator_codex_app_server_error_kind_with_machine_detail("other", error), }; } for field in [ @@ -471,7 +516,7 @@ fn game_creator_codex_app_server_failed_turn_error( if info.get("activeTurnNotSteerable").is_some() { return game_creator_codex_app_server_error_kind("active-turn-not-steerable"); } - game_creator_codex_app_server_error_kind("other") + game_creator_codex_app_server_error_kind_with_machine_detail("other", error) } async fn isolate_game_creator_codex_app_server_terminal_unknown( diff --git a/apps/ai-game-creator-shell/src-tauri/src/agent/codex_cli.rs b/apps/ai-game-creator-shell/src-tauri/src/agent/codex_cli.rs index 23fd00fe9..863b8cdad 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/agent/codex_cli.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/agent/codex_cli.rs @@ -6,8 +6,9 @@ use sha2::{Digest, Sha256}; use tokio::io::{AsyncRead, AsyncReadExt, AsyncWriteExt}; const GAME_CREATOR_CODEX_CLI_EXECUTABLE: &str = "codex"; -const GAME_CREATOR_BUNDLED_CODEX_CLI_RELATIVE_PATH: &str = "codex/win-x64/bin/codex.exe"; -const GAME_CREATOR_BUNDLED_CODEX_CLI_MANIFEST_RELATIVE_PATH: &str = "codex/win-x64/manifest.json"; +const GAME_CREATOR_BUNDLED_CODEX_CLI_RELATIVE_PATH: &str = "coding-agent/win-x64/bin/codex.exe"; +const GAME_CREATOR_BUNDLED_CODEX_CLI_MANIFEST_RELATIVE_PATH: &str = + "coding-agent/win-x64/manifest.json"; const GAME_CREATOR_BUNDLED_CODEX_CLI_REQUIRED_FILES: [&str; 6] = [ "bin/codex.exe", "bin/codex-code-mode-host.exe", diff --git a/apps/ai-game-creator-shell/src-tauri/src/agent/design_runtime.rs b/apps/ai-game-creator-shell/src-tauri/src/agent/design_runtime.rs index 2d24a4997..38e7a2f8a 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/agent/design_runtime.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/agent/design_runtime.rs @@ -606,11 +606,7 @@ fn build_design_request( // 调试队列只接收副本,写盘慢或失败时丢弃,不参与会话恢复。 fn design_debug(root: &Path, kind: &str, data: Value) { - if std::env::var("GENARRATIVE_AGC_DESIGN_DEBUG") - .ok() - .as_deref() - != Some("1") - { + if !design_debug_enabled() { return; } type Entry = (PathBuf, Value); @@ -1133,6 +1129,18 @@ fn resolve_design_runtime_mode(root: &Path) -> Result, })) } +fn design_debug_enabled() -> bool { + std::env::var("GENARRATIVE_AGC_DESIGN_DEBUG") + .ok() + .as_deref() + == Some("1") +} + +#[tauri::command] +pub(crate) fn is_design_agent_debug_enabled() -> bool { + cfg!(debug_assertions) && design_debug_enabled() +} + #[tauri::command] pub(crate) fn set_design_agent_runtime_mode( project_path: String, @@ -1159,12 +1167,7 @@ pub(crate) fn debug_fast_forward_design_session( project_path: String, target_phase: String, ) -> Result { - if !cfg!(debug_assertions) - || std::env::var("GENARRATIVE_AGC_DESIGN_DEBUG") - .ok() - .as_deref() - != Some("1") - { + if !is_design_agent_debug_enabled() { return Err("策划 Agent 快速推进仅可用于 Debug 构建".to_string()); } let root = Path::new(project_path.trim()); diff --git a/apps/ai-game-creator-shell/src-tauri/src/agent/design_tools.rs b/apps/ai-game-creator-shell/src-tauri/src/agent/design_tools.rs index 6d65f9dd3..5221030b1 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/agent/design_tools.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/agent/design_tools.rs @@ -264,22 +264,45 @@ pub(crate) fn execute_design_file_tool( } "patch_file" => { let relative = required_tool_path(args)?; - let old = args - .get("old_text") - .and_then(Value::as_str) - .ok_or("缺少 old_text")?; - let new = args - .get("new_text") - .and_then(Value::as_str) - .ok_or("缺少 new_text")?; - if old.is_empty() { - return Err("old_text 不能为空".to_string()); - } + let edits = if let Some(items) = args.get("edits").and_then(Value::as_array) { + if items.is_empty() { + return Err("edits 不能为空".to_string()); + } + items + .iter() + .enumerate() + .map(|(index, item)| { + let old = item + .get("old_text") + .and_then(Value::as_str) + .ok_or_else(|| format!("edits[{index}].old_text 必须是字符串"))?; + let new = item + .get("new_text") + .and_then(Value::as_str) + .ok_or_else(|| format!("edits[{index}].new_text 必须是字符串"))?; + if old.is_empty() { + return Err(format!("edits[{index}].old_text 不能为空")); + } + Ok((old.to_string(), new.to_string())) + }) + .collect::, String>>()? + } else { + let old = args + .get("old_text") + .and_then(Value::as_str) + .ok_or("缺少 old_text")?; + let new = args + .get("new_text") + .and_then(Value::as_str) + .ok_or("缺少 new_text")?; + if old.is_empty() { + return Err("old_text 不能为空".to_string()); + } + vec![(old.to_string(), new.to_string())] + }; let (display, path) = resolve_design_workspace_path(root, &relative)?; if !path.is_file() { - return Ok(Value::String(format!( - "局部修改失败:文件不存在:{display}" - ))); + return Err(format!("文件不存在:{display}")); } let content = fs::read_to_string(&path).map_err(|error| format!("读取失败:{error}"))?; @@ -288,20 +311,52 @@ pub(crate) fn execute_design_file_tool( } else { "\n" }; - let old = old.replace("\r\n", "\n").replace('\n', newline); - let new = new.replace("\r\n", "\n").replace('\n', newline); - let count = content.matches(&old).count(); - if count != 1 { - return Err(format!( - "原文匹配 {count} 处,需要唯一匹配;请重新读取文件并扩大匹配范围" - )); + let normalized = edits + .into_iter() + .map(|(old, new)| { + ( + old.replace("\r\n", "\n").replace('\n', newline), + new.replace("\r\n", "\n").replace('\n', newline), + ) + }) + .collect::>(); + let mut matches = Vec::new(); + for (index, (old, new)) in normalized.iter().enumerate() { + let count = content.matches(old).count(); + if count == 0 { + return Err(format!("edits[{index}] 原文未找到:{display}")); + } + if count != 1 { + return Err(format!( + "edits[{index}] 原文匹配 {count} 处,必须唯一:{display}" + )); + } + let start = content.find(old).expect("count checked"); + let end = start + old.len(); + if let Some((other_index, _other_start, _other_end)) = matches + .iter() + .find(|(_, other_start, other_end)| start < *other_end && *other_start < end) + { + return Err(format!( + "edits[{index}] 与 edits[{other_index}] 修改范围重叠:{display}" + )); + } + matches.push((index, start, end)); + let _ = new; } - crate::write_game_creator_private_file( - &path, - content.replacen(&old, &new, 1).as_bytes(), - "策划工作区文件", - )?; - Ok(Value::String(format!("已局部修改 {display}"))) + let mut updated = content.clone(); + for (index, start, end) in matches.into_iter().rev() { + let (_, new) = &normalized[index]; + updated.replace_range(start..end, new); + } + if updated == content { + return Err(format!("没有产生修改:{display}")); + } + crate::write_game_creator_private_file(&path, updated.as_bytes(), "策划工作区文件")?; + Ok(Value::String(format!( + "已局部修改 {display}({} 处)", + normalized.len() + ))) } "delete_path" => { let relative = required_tool_path(args)?; @@ -645,6 +700,29 @@ mod tests { ) .expect("patch"); assert!(patched.as_str().unwrap().contains("已局部修改")); + execute_design_file_tool( + root, + "write_file", + &json!({"path":"notes/multi.md","content":"甲\n乙\n丙"}), + ) + .expect("write multi"); + let multi = execute_design_file_tool( + root, + "patch_file", + &json!({ + "path":"notes/multi.md", + "edits":[ + {"old_text":"甲","new_text":"一"}, + {"old_text":"丙","new_text":"三"} + ] + }), + ) + .expect("multi patch"); + assert!(multi.as_str().unwrap().contains("2 处")); + assert_eq!( + fs::read_to_string(root.join("design_artifacts/notes/multi.md")).expect("read multi"), + "一\n乙\n三" + ); execute_design_file_tool(root, "delete_path", &json!({"path":"notes"})) .expect("delete dir"); assert!(!root.join("design_artifacts/notes").exists()); diff --git a/apps/ai-game-creator-shell/src-tauri/src/agent/direct_codex_audit.rs b/apps/ai-game-creator-shell/src-tauri/src/agent/direct_codex_audit.rs index 43ab7c7ba..6f8557a32 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/agent/direct_codex_audit.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/agent/direct_codex_audit.rs @@ -549,6 +549,7 @@ fn extract_mcp_arguments(root: &Path, tool: &str, arguments: &Value) -> Value { } "agc_generate_image" => { copy_string(object, "kind", &mut out); + copy_string(object, "sliceMode", &mut out); copy_string(object, "aspectRatio", &mut out); copy_string(object, "imageSize", &mut out); copy_string(object, "assetName", &mut out); diff --git a/apps/ai-game-creator-shell/src-tauri/src/agent/direct_runtime/mod.rs b/apps/ai-game-creator-shell/src-tauri/src/agent/direct_runtime/mod.rs index d72be32c5..dcc287e2b 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/agent/direct_runtime/mod.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/agent/direct_runtime/mod.rs @@ -1908,7 +1908,11 @@ fn direct_codex_error_is_mud_points_insufficient(error: &str) -> bool { || normalized.contains("insufficient-mud-points") } -fn record_direct_codex_turn_failure(root: &Path, failure: DirectCodexTurnFailure) -> String { +fn record_direct_codex_turn_failure( + root: &Path, + failure: DirectCodexTurnFailure, + client_turn_id: Option<&str>, +) -> String { let summary = direct_codex_failure_public_summary(&failure.error) .map(str::to_string) .unwrap_or_else(|| redact_agent_runtime_error(root, &failure.error, 320)); @@ -1945,18 +1949,53 @@ fn record_direct_codex_turn_failure(root: &Path, failure: DirectCodexTurnFailure } else { "未能保存项目诊断" }; - format!( - "direct-codex-failure:v1 stage={} retryable={} summary={};建议:{};{}", + let error_code = classify_direct_codex_error(&failure.error); + let unified_detail_ref = persist_agent_runtime_error( + root, + client_turn_id, + "direct-codex", failure.stage.id(), + error_code, + retryable, + &summary, + recovery_hint, + &failure.error, + None, + serde_json::json!({ + "legacyDiagnosticWritten": diagnostic_written, + }), + ) + .ok() + .map(|event| event.detail_ref); + format!( + "direct-codex-failure:v2 stage={} code={} retryable={} summary={};建议:{};{}{}", + failure.stage.id(), + error_code, retryable, diagnostic["summary"] .as_str() .unwrap_or("未提供可安全展示的详细原因"), recovery_hint, diagnostics_suffix, + unified_detail_ref + .map(|path| format!(";详情:{path}")) + .unwrap_or_default(), ) } +fn persist_direct_codex_failure_context( + root: &Path, + client_turn_id: &str, + error: &str, +) -> Result<(), String> { + let item = direct_project_local_message_item( + "assistant", + error, + Some(&format!("direct-codex:{client_turn_id}:failure")), + )?; + append_direct_project_history_item_at(root, &item) +} + fn direct_taonier_art_generation_runtime_context( root: &Path, output_path: &str, @@ -2272,9 +2311,19 @@ fn direct_registered_taonier_slice_paths(root: &Path) -> Vec { } fn direct_game_sources_referenced_taonier_assets(root: &Path) -> Vec { - let sources = direct_codex_game_outputs(root) + let mut source_paths = direct_codex_game_outputs(root) .into_iter() - .filter_map(|(relative_path, _, _)| std::fs::read_to_string(root.join(relative_path)).ok()) + .map(|(relative_path, _, _)| relative_path) + .collect::>(); + // npm/Phaser projects put the actual scene and loader code below `game/src`. + // Keep the canonical output list for manifest projection, but scan the + // complete bounded source list for the asset reference contract. + source_paths.extend(direct_npm_source_paths(root)); + source_paths.sort(); + source_paths.dedup(); + let sources = source_paths + .into_iter() + .filter_map(|relative_path| std::fs::read_to_string(root.join(relative_path)).ok()) .collect::>(); let mut available_paths = Vec::new(); if direct_taonier_art_base_is_valid(root) { @@ -2287,6 +2336,28 @@ fn direct_game_sources_referenced_taonier_assets(root: &Path) -> Vec { available_paths.push(DIRECT_CODEX_SPRITESHEET_ASSET_PATH.to_string()); } available_paths.extend(direct_registered_taonier_slice_paths(root)); + // A project may have a valid, client-registered art-spritesheet at a + // project-specific path (for example a generated building sheet). The + // fixed canonical package paths above are compatibility candidates only; + // the manifest is the authority for additional runtime image identities. + if let Ok(manifest) = read_manifest_for_project(root) { + available_paths.extend( + manifest + .assets + .into_iter() + .filter(|asset| { + matches!( + asset.kind.as_str(), + "art-spritesheet" | "art-spritesheet-slice" | "game-background" + ) && asset.media_type == "image/png" + && asset.source.kind == GameCreationAppAssetSourceKind::Canvas + && asset.local_path.starts_with("assets/") + }) + .map(|asset| asset.local_path), + ); + } + available_paths.sort(); + available_paths.dedup(); available_paths .into_iter() .filter(|path| sources.iter().any(|source| source.contains(path.as_str()))) @@ -2786,6 +2857,9 @@ async fn generate_direct_taonier_art_asset_at( asset_label: asset_label.to_string(), replace_existing: root.join(output_path).is_file(), slice_count: None, + slice_mode: None, + grid_x: None, + grid_y: None, }; let runtime_context = direct_taonier_art_generation_runtime_context(root, output_path, asset_kind)?; @@ -4097,7 +4171,17 @@ async fn run_direct_game_creator_turn_at_with_creation_type_and_emitter( { Ok(reply) => Ok(reply), Err(failure) => { - let error = record_direct_codex_turn_failure(root, failure); + let error = record_direct_codex_turn_failure( + root, + failure, + turn_emitter.map(|emitter| emitter.turn_id()), + ); + if let Some(emitter) = turn_emitter { + // Persist the safe terminal projection so the next DirectProject + // turn can answer a diagnostic question from evidence instead of + // guessing or starting another playtest. + let _ = persist_direct_codex_failure_context(root, emitter.turn_id(), &error); + } if let Some(emitter) = turn_emitter { emitter.emit("failed", Some("none"), None); } @@ -6544,26 +6628,27 @@ mod tests { #[test] fn direct_failure_diagnostic_is_redacted_and_persisted_with_a_stable_stage() { - let root = tempfile::tempdir().expect("temp dir"); - init_local_game_project_at(root.path(), "direct-diagnostic", "直连诊断") - .expect("init project"); + let parent = tempfile::tempdir().expect("temp dir"); + let root = parent.path().join("project"); + init_local_game_project_at(&root, "direct-diagnostic", "直连诊断").expect("init project"); let error = record_direct_codex_turn_failure( - root.path(), + &root, DirectCodexTurnFailure::new( DirectCodexFailureStage::ArtPreparation, "读取陶泥儿画布资源失败:https://provider.example/private?token=secret C:\\Users\\private\\project authorization=Bearer secret", ), + None, ); assert!(error - .starts_with("direct-codex-failure:v1 stage=art-preparation retryable=true summary=")); + .starts_with("direct-codex-failure:v2 stage=art-preparation code=runtime-failure retryable=true summary=")); assert!(error.contains(""), "{error}"); assert!(error.contains(""), "{error}"); assert!(!error.contains("authorization=Bearer secret"), "{error}"); assert!(!error.contains("?token=secret"), "{error}"); assert!(!error.contains("provider.example"), "{error}"); - let diagnostics = root.path().join(".agent/runtime/direct-codex-diagnostics"); + let diagnostics = root.join(".agent/runtime/direct-codex-diagnostics"); let entries = std::fs::read_dir(&diagnostics) .expect("diagnostic directory") .filter_map(Result::ok) @@ -6582,25 +6667,25 @@ mod tests { #[test] fn direct_failure_diagnostic_marks_project_history_shape_failure_as_not_retryable() { - let root = tempfile::tempdir().expect("temp dir"); - init_local_game_project_at(root.path(), "direct-diagnostic", "直连诊断") - .expect("init project"); + let parent = tempfile::tempdir().expect("temp dir"); + let root = parent.path().join("project"); + init_local_game_project_at(&root, "direct-diagnostic", "直连诊断").expect("init project"); let history_path = root - .path() .join(".agent/conversations/project.jsonl") .display() .to_string(); let error = record_direct_codex_turn_failure( - root.path(), + &root, DirectCodexTurnFailure::new( DirectCodexFailureStage::CodeGeneration, format!("DirectProject 历史记录类型无效:{history_path}"), ), + None, ); assert!( error.starts_with( - "direct-codex-failure:v1 stage=code-generation retryable=false summary=" + "direct-codex-failure:v2 stage=code-generation code=runtime-failure retryable=false summary=" ), "{error}" ); @@ -6610,9 +6695,9 @@ mod tests { ), "{error}" ); - assert!(error.ends_with("已保存脱敏项目诊断"), "{error}"); + assert!(error.contains("已保存脱敏项目诊断"), "{error}"); - let diagnostics = root.path().join(".agent/runtime/direct-codex-diagnostics"); + let diagnostics = root.join(".agent/runtime/direct-codex-diagnostics"); let entries = std::fs::read_dir(&diagnostics) .expect("diagnostic directory") .filter_map(Result::ok) @@ -6626,19 +6711,20 @@ mod tests { #[test] fn direct_failure_diagnostic_marks_ambiguous_canvas_identity_as_not_retryable() { - let root = tempfile::tempdir().expect("temp dir"); - init_local_game_project_at(root.path(), "direct-diagnostic", "直连诊断") - .expect("init project"); + let parent = tempfile::tempdir().expect("temp dir"); + let root = parent.path().join("project"); + init_local_game_project_at(&root, "direct-diagnostic", "直连诊断").expect("init project"); let error = record_direct_codex_turn_failure( - root.path(), + &root, DirectCodexTurnFailure::new( DirectCodexFailureStage::ArtPreparation, "陶泥儿画布存在多个同源核心图集,身份不唯一,已拒绝恢复", ), + None, ); assert!( - error.contains("stage=art-preparation retryable=false"), + error.contains("stage=art-preparation code=runtime-failure retryable=false"), "{error}" ); assert!(error.contains("历史画布资源不满足安全恢复条件"), "{error}"); @@ -6646,15 +6732,16 @@ mod tests { #[test] fn direct_failure_diagnostic_keeps_private_credential_storage_failure_actionable() { - let root = tempfile::tempdir().expect("temp dir"); - init_local_game_project_at(root.path(), "direct-diagnostic", "直连诊断") - .expect("init project"); + let parent = tempfile::tempdir().expect("temp dir"); + let root = parent.path().join("project"); + init_local_game_project_at(&root, "direct-diagnostic", "直连诊断").expect("init project"); let error = record_direct_codex_turn_failure( - root.path(), + &root, DirectCodexTurnFailure::new( DirectCodexFailureStage::ArtPreparation, "private-external-editor-credential-storage-preparation-failed: 本机开发者凭据存储目录未安全初始化;未创建远端凭据", ), + None, ); assert!( @@ -7754,6 +7841,40 @@ mod tests { .any(|warning| warning.contains("不得猜测切片"))); } + #[test] + fn direct_completion_scans_npm_scene_modules_for_registered_asset_references() { + let parent = tempfile::tempdir().expect("temp dir"); + let root = parent.path().join("project"); + init_local_game_project_at(&root, "direct-src-runtime", "源码模块素材引用") + .expect("init project"); + register_direct_taonier_art_package_fixture(&root); + register_direct_taonier_art_slice_entries_fixture(&root); + std::fs::write( + root.join("game/package.json"), + "{\"scripts\":{\"build\":\"vite build\"}}", + ) + .expect("package"); + std::fs::write(root.join("game/index.html"), "").expect("index"); + std::fs::write(root.join("game/style.css"), "body {}").expect("style"); + std::fs::write(root.join("game/game.js"), "import './src/scene.js';").expect("entry"); + std::fs::create_dir_all(root.join("game/src")).expect("src dir"); + std::fs::write( + root.join("game/src/scene.js"), + "const player = new Image(); player.src = '/assets/art-spritesheet-slices/player.png';", + ) + .expect("scene"); + std::fs::write( + root.join("assets/art-spritesheet-slices/player.png"), + tiny_opaque_png(), + ) + .expect("slice"); + + assert_eq!( + direct_game_sources_referenced_taonier_assets(&root), + vec!["assets/art-spritesheet-slices/player.png".to_string()] + ); + } + #[test] fn direct_output_sync_accepts_trusted_spec_and_background_without_a_historical_spritesheet() { let root = tempfile::tempdir().expect("temp dir"); diff --git a/apps/ai-game-creator-shell/src-tauri/src/agent/direct_tool_bridge.rs b/apps/ai-game-creator-shell/src-tauri/src/agent/direct_tool_bridge.rs index 8832c1267..12c6f8d27 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/agent/direct_tool_bridge.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/agent/direct_tool_bridge.rs @@ -1078,7 +1078,9 @@ fn bridge_attempt(arguments: &Value) -> Result { .and_then(Value::as_u64) .ok_or_else(|| "工具参数 attempt 必须是 1 到 3 的整数".to_string())?; if !(1..=3).contains(&attempt) { - return Err("工具参数 attempt 必须是 1 到 3 的整数".to_string()); + return Err(format!( + "playtest-attempt-limit-exceeded: 本轮试玩最多 3 次,收到 attempt={attempt};请结束试玩并基于最近一次浏览器证据报告结果" + )); } Ok(attempt as usize) } @@ -2104,6 +2106,9 @@ async fn bridge_generate_image(state: &DirectToolBridgeState, arguments: &Value) "imageSize", "assetName", "outputPath", + "sliceMode", + "gridX", + "gridY", ], )?; enforce_project_permission_policy(&state.root, "canvas.asset_generate")?; @@ -2145,6 +2150,44 @@ async fn bridge_generate_image(state: &DirectToolBridgeState, arguments: &Value) .transpose()? .unwrap_or_else(|| "AI 生成图片".to_string()); let output_path = bridge_optional_bounded_string(arguments, "outputPath", 512)?; + let slice_mode = arguments + .get("sliceMode") + .map(|_| bridge_bounded_string(arguments, "sliceMode", 32)) + .transpose()?; + if slice_mode + .as_deref() + .is_some_and(|mode| !matches!(mode, "connected-components" | "grid")) + { + return Err("工具参数 sliceMode 只允许 connected-components 或 grid".to_string()); + } + let grid_x = arguments + .get("gridX") + .map(|_| { + arguments + .get("gridX") + .and_then(Value::as_u64) + .map(|value| value as u32) + .ok_or_else(|| "工具参数 gridX 必须是整数".to_string()) + }) + .transpose()?; + let grid_y = arguments + .get("gridY") + .map(|_| { + arguments + .get("gridY") + .and_then(Value::as_u64) + .map(|value| value as u32) + .ok_or_else(|| "工具参数 gridY 必须是整数".to_string()) + }) + .transpose()?; + if slice_mode.as_deref() == Some("grid") && (grid_x.is_none() || grid_y.is_none()) { + return Err("grid 模式必须同时提供 gridX 与 gridY".to_string()); + } + if grid_x.is_some_and(|value| !(1..=32).contains(&value)) + || grid_y.is_some_and(|value| !(1..=32).contains(&value)) + { + return Err("工具参数 gridX/gridY 必须在 1 到 32 之间".to_string()); + } let options = PlatformArtAssetGenerationOptions { output_path, aspect_ratio, @@ -2153,12 +2196,16 @@ async fn bridge_generate_image(state: &DirectToolBridgeState, arguments: &Value) asset_label: asset_name.clone(), replace_existing: false, slice_count: None, + slice_mode, + grid_x, + grid_y, }; let _generation_guard = state.image_generation_gate.lock().await; let generated = with_direct_editor_api_credentials( generate_platform_art_asset_with_options_at(&state.root, &prompt, &[], &options), ) .await?; + emit_game_creator_manifest_invalidated(&state.root, "direct-codex-art"); let resources = bridge_art_resources( &state.root, std::slice::from_ref(&generated.asset.local_path), @@ -2563,6 +2610,30 @@ async fn handle_direct_tool_bridge( } _ => bridge_tool_result("未知或未审核的客户端工具".to_string(), Vec::new(), true), }; + if result.get("isError").and_then(Value::as_bool) == Some(true) { + let message = result + .pointer("/content/0/text") + .and_then(Value::as_str) + .unwrap_or("客户端工具执行失败"); + let code = if message.contains("playtest-attempt-limit-exceeded") { + "playtest-attempt-limit-exceeded" + } else { + "tool-error" + }; + let _ = persist_agent_runtime_error( + &state.root, + None, + "agc-tools", + "tool-execution", + code, + true, + message, + "查看项目错误诊断后处理", + message, + None, + serde_json::json!({"tool": request.tool}), + ); + } Json(result) } diff --git a/apps/ai-game-creator-shell/src-tauri/src/agent/direct_tools_mcp.rs b/apps/ai-game-creator-shell/src-tauri/src/agent/direct_tools_mcp.rs index 643abd3db..1005ed813 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/agent/direct_tools_mcp.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/agent/direct_tools_mcp.rs @@ -244,6 +244,24 @@ fn direct_tools_mcp_specs_for(controlled_web_search: bool, _cocos_editor_availab "type": "string", "maxLength": 512, "description": "可选项目相对输出路径,必须位于 assets/ 且不能覆盖已有文件" + }, + "sliceMode": { + "type": "string", + "enum": ["connected-components", "grid"], + "default": "connected-components", + "description": "仅 kind=art-spritesheet 生效:connected-components 按透明像素连通域切分,grid 按 gridX×gridY 网格切分" + }, + "gridX": { + "type": "integer", + "minimum": 1, + "maximum": 32, + "description": "grid 模式横向网格数量" + }, + "gridY": { + "type": "integer", + "minimum": 1, + "maximum": 32, + "description": "grid 模式纵向网格数量" } }, "required": ["prompt"], @@ -880,7 +898,9 @@ fn tool_attempt(arguments: &Value) -> Result { .and_then(Value::as_u64) .ok_or_else(|| "工具参数 attempt 必须是 1 到 3 的整数".to_string())?; if !(1..=3).contains(&attempt) { - return Err("工具参数 attempt 必须是 1 到 3 的整数".to_string()); + return Err(format!( + "playtest-attempt-limit-exceeded: 本轮试玩最多 3 次,收到 attempt={attempt};请结束试玩并基于最近一次浏览器证据报告结果" + )); } Ok(attempt as usize) } @@ -1014,6 +1034,9 @@ async fn call_agc_generate_image(arguments: &Value) -> Value { "imageSize", "assetName", "outputPath", + "sliceMode", + "gridX", + "gridY", ], ) { return mcp_tool_result(error, Vec::new(), true); @@ -1041,6 +1064,7 @@ async fn call_agc_generate_image(arguments: &Value) -> Value { ("imageSize", 4), ("assetName", DIRECT_TOOLS_MCP_MAX_RESOURCE_NAME_CHARS), ("outputPath", 512), + ("sliceMode", 32), ] { if arguments.get(field).is_some() { if let Err(error) = bounded_tool_string(arguments, field, max_chars) { @@ -2226,6 +2250,10 @@ mod tests { assert!(image_tool["description"] .as_str() .is_some_and(|description| description.contains("不是本工具的限制"))); + assert_eq!( + image_tool["inputSchema"]["properties"]["sliceMode"]["enum"], + json!(["connected-components", "grid"]) + ); let edit_tool = specs["tools"] .as_array() .expect("tool array") diff --git a/apps/ai-game-creator-shell/src-tauri/src/agent/generation/canvas_generation.rs b/apps/ai-game-creator-shell/src-tauri/src/agent/generation/canvas_generation.rs index 2bd540024..f9bbd95a8 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/agent/generation/canvas_generation.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/agent/generation/canvas_generation.rs @@ -413,6 +413,9 @@ pub(crate) struct PlatformArtAssetGenerationOptions { pub(crate) asset_label: String, pub(crate) replace_existing: bool, pub(crate) slice_count: Option, + pub(crate) slice_mode: Option, + pub(crate) grid_x: Option, + pub(crate) grid_y: Option, } impl Default for PlatformArtAssetGenerationOptions { @@ -425,6 +428,9 @@ impl Default for PlatformArtAssetGenerationOptions { asset_label: "AI 游戏首版美术素材".to_string(), replace_existing: false, slice_count: None, + slice_mode: None, + grid_x: None, + grid_y: None, } } } @@ -1574,7 +1580,7 @@ pub(in crate::agent) struct PreparedPlatformArtAssetGeneration { warning: Option, slice_warning: Option, slices: Vec, - spritesheet_slice_layout: Option, + spritesheet_slice_mode: Option, generation_route: String, generation_kind: String, reference_resource_ids: Vec, @@ -2213,11 +2219,8 @@ pub(crate) async fn generate_platform_art_asset_with_required_slices_at( /// 而任何输入不同(提示词、输出路径、比例、尺寸、类型、标签、严格切片)都是另一个 /// 动作,必须各自独立成槽,才能在同一项目里同时在途。 /// -/// **字段集合与取值方式必须与升级前逐字节一致**:升级前遗留账本里持久化的 -/// `actionFingerprint` 就是这个材料的历史哈希,改动材料会让旧账本无法按精确动作被 -/// 识别与迁移(见 `adopt_legacy_standalone_platform_art_generation_runtime_state_at`)。 -/// 已知边界:`slice_count` 不进身份(与升级前一致),仅切片数不同的两条图集请求仍落到 -/// 同一槽,第二条在账本请求正文校验处失败关闭,不会二次 POST。 +/// 升级前遗留账本仍由旧材料函数定位;新请求把显式切分模式纳入身份,避免同一图集 +/// 请求在网格与连通域之间误复用。`slice_count` 继续保持历史兼容语义,不进身份。 #[derive(Serialize)] #[serde(rename_all = "camelCase")] struct StandalonePlatformArtGenerationFingerprintMaterial<'a> { @@ -2229,6 +2232,9 @@ struct StandalonePlatformArtGenerationFingerprintMaterial<'a> { asset_label: &'a str, replace_existing: bool, require_slices: bool, + slice_mode: Option<&'a str>, + grid_x: Option, + grid_y: Option, } /// 把输出路径收口成稳定的旧槽材料:空路径与未指定路径都落到 `(automatic-output)`, @@ -2265,6 +2271,9 @@ fn standalone_platform_art_generation_runtime_context( asset_label: &options.asset_label, replace_existing: options.replace_existing, require_slices, + slice_mode: options.slice_mode.as_deref(), + grid_x: options.grid_x, + grid_y: options.grid_y, }) .map_err(|error| format!("序列化 standalone 图片生成动作身份失败:{error}"))?; let action_fingerprint = format!("{:x}", Sha256::digest(&identity_bytes)); @@ -2811,6 +2820,9 @@ pub(in crate::agent) async fn request_platform_art_asset_with_runtime_options_at "referenceId": reference_id, "iconDescriptions": canonical_art_spritesheet_icon_descriptions(&generation_prompt), "sliceCount": options.slice_count, + "sliceMode": options.slice_mode, + "gridX": options.grid_x, + "gridY": options.grid_y, "screenColor": "auto", "aspectRatio": options.aspect_ratio, "imageSize": options.image_size, @@ -3106,8 +3118,8 @@ pub(in crate::agent) async fn request_platform_art_asset_with_runtime_options_at Vec::new() }; let warning = platform_art_generation_warning(generated); - let spritesheet_slice_layout = if is_canonical_art_spritesheet { - json_string_field(generated, "sliceLayout") + let spritesheet_slice_mode = if is_canonical_art_spritesheet { + json_string_field(generated, "sliceMode") } else { None }; @@ -3168,7 +3180,7 @@ pub(in crate::agent) async fn request_platform_art_asset_with_runtime_options_at warning, slice_warning, slices, - spritesheet_slice_layout, + spritesheet_slice_mode, generation_route, generation_kind, reference_resource_ids, @@ -6508,7 +6520,7 @@ fn validate_strict_platform_art_spritesheet_contract( task_id: Option<&str>, generation_route: &str, generation_kind: &str, - spritesheet_slice_layout: Option<&str>, + spritesheet_slice_mode: Option<&str>, reference_resource_ids: &[String], has_transparent_pixels: bool, has_visible_pixels: bool, @@ -6545,7 +6557,7 @@ fn validate_strict_platform_art_spritesheet_contract( { return Err("strict spritesheet 图集生成 route/kind 与严格图集合同不一致".to_string()); } - let _requested_slice_layout = spritesheet_slice_layout; + let _requested_slice_mode = spritesheet_slice_mode; if reference_resource_ids.len() != 1 || reference_resource_ids[0].trim().is_empty() || reference_resource_ids[0].trim() == resource_id @@ -7307,7 +7319,7 @@ fn commit_prepared_platform_art_asset_with_before_replace_hook( warning, mut slice_warning, slices, - spritesheet_slice_layout, + spritesheet_slice_mode, generation_route, generation_kind, reference_resource_ids, @@ -7326,7 +7338,7 @@ fn commit_prepared_platform_art_asset_with_before_replace_hook( task_id.as_deref(), &generation_route, &generation_kind, - spritesheet_slice_layout.as_deref(), + spritesheet_slice_mode.as_deref(), &reference_resource_ids, spritesheet_has_transparent_pixels, spritesheet_has_visible_pixels, @@ -7901,8 +7913,8 @@ mod canvas_generation_tests { let body = serde_json::json!({ "error": { "code": "invalid-request", - "field": "sliceLayout", - "message": "只支持 grid-2x2;operationId=private-operation-id;api_key=private-key", + "field": "sliceMode", + "message": "只支持 grid;operationId=private-operation-id;api_key=private-key", }, "details": { "path": "C:\\Users\\private\\secret.json", @@ -7911,8 +7923,8 @@ mod canvas_generation_tests { .to_string(); let summary = summarize_external_http_error_body(&body).expect("summary"); assert!(summary.contains("code=invalid-request"), "{summary}"); - assert!(summary.contains("field=sliceLayout"), "{summary}"); - assert!(summary.contains("只支持 grid-2x2"), "{summary}"); + assert!(summary.contains("field=sliceMode"), "{summary}"); + assert!(summary.contains("只支持 grid"), "{summary}"); assert!(!summary.contains("private-operation-id"), "{summary}"); assert!(!summary.contains("private-key"), "{summary}"); assert!(!summary.contains("C:\\Users\\private"), "{summary}"); @@ -8312,6 +8324,9 @@ mod canvas_generation_tests { asset_label: "手工背景".to_string(), replace_existing: true, slice_count: None, + slice_mode: None, + grid_x: None, + grid_y: None, }; let ordinary = standalone_platform_art_generation_runtime_context("完整生成提示词", &options, false) @@ -9826,7 +9841,7 @@ mod canvas_generation_tests { Some("spritesheet-task"), "/api/external/v1/editor/icon-spritesheets/generations", "icon-spritesheet", - Some("grid-2x2"), + Some("grid"), &["art-spec-resource".to_string()], true, true, @@ -10325,6 +10340,9 @@ mod canvas_generation_tests { asset_label: "整包规范图".to_string(), replace_existing: false, slice_count: None, + slice_mode: None, + grid_x: None, + grid_y: None, }; let prompt = "生成同一套整包美术"; let generation_prompt = build_platform_art_asset_prompt(prompt, &[], &options); @@ -11220,6 +11238,9 @@ mod canvas_generation_tests { asset_label: "整包背景图".to_string(), replace_existing: false, slice_count: None, + slice_mode: None, + grid_x: None, + grid_y: None, }; let prompt = "保持同一个生成提示词"; let generation_prompt = build_platform_art_asset_prompt(prompt, &[], &options); @@ -11681,6 +11702,9 @@ mod canvas_generation_tests { asset_label: "游戏统一视觉规范图".to_string(), replace_existing: false, slice_count: None, + slice_mode: None, + grid_x: None, + grid_y: None, }; let prompt = "恢复已受理视觉规范图"; let generation_prompt = build_platform_art_asset_prompt(prompt, &[], &options); @@ -12287,6 +12311,9 @@ mod canvas_generation_tests { asset_label: "游戏首版核心美术素材".to_string(), replace_existing: true, slice_count: None, + slice_mode: None, + grid_x: None, + grid_y: None, } } @@ -12317,7 +12344,7 @@ mod canvas_generation_tests { warning: None, slice_warning: None, slices: Vec::new(), - spritesheet_slice_layout: Some("grid-2x2".to_string()), + spritesheet_slice_mode: Some("grid".to_string()), generation_route: "/api/external/v1/editor/icon-spritesheets/generations".to_string(), generation_kind: "icon-spritesheet".to_string(), reference_resource_ids: vec!["art-spec-resource".to_string()], @@ -12636,7 +12663,7 @@ mod canvas_generation_tests { warning: None, slice_warning: None, slices, - spritesheet_slice_layout: Some("grid-2x2".to_string()), + spritesheet_slice_mode: Some("grid".to_string()), generation_route: "/api/external/v1/editor/icon-spritesheets/generations".to_string(), generation_kind: "icon-spritesheet".to_string(), reference_resource_ids: vec!["art-spec-resource".to_string()], diff --git a/apps/ai-game-creator-shell/src-tauri/src/agent/runtime_error.rs b/apps/ai-game-creator-shell/src-tauri/src/agent/runtime_error.rs new file mode 100644 index 000000000..4fe895680 --- /dev/null +++ b/apps/ai-game-creator-shell/src-tauri/src/agent/runtime_error.rs @@ -0,0 +1,167 @@ +//! Shared, project-bound error events for Agent Runtime and DirectProject. +//! +//! Every caller supplies a safe public summary and a private detail. This +//! module is the only persistence boundary for the latter: it redacts project +//! paths and credentials before writing a bounded diagnostic sidecar. + +use super::{redact_agent_runtime_error, write_agent_runtime_json_sidecar_with_max_bytes}; +use serde::{Deserialize, Serialize}; +use serde_json::Value; +use std::path::Path; +use std::sync::atomic::{AtomicU64, Ordering}; +use std::time::{SystemTime, UNIX_EPOCH}; + +pub(crate) const AGENT_RUNTIME_ERROR_SCHEMA_VERSION: &str = "agent-runtime-error.v1"; +pub(crate) const AGENT_RUNTIME_ERROR_MAX_DETAIL_CHARS: usize = 8 * 1024; + +static ERROR_EVENT_SEQUENCE: AtomicU64 = AtomicU64::new(1); + +#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)] +pub(crate) struct AgentRuntimeErrorEvent { + pub schema_version: &'static str, + pub event_id: String, + pub client_turn_id: Option, + pub source: String, + pub stage: String, + pub code: String, + pub retryable: bool, + pub occurred_at_unix_nanos: String, + pub elapsed_ms: Option, + pub public_text: String, + pub recovery_hint: String, + pub detail_ref: String, + pub persistence_failed: bool, + pub metadata: Value, +} + +pub(crate) fn persist_agent_runtime_error( + root: &Path, + client_turn_id: Option<&str>, + source: &str, + stage: &str, + code: &str, + retryable: bool, + public_text: &str, + recovery_hint: &str, + detail: &str, + elapsed_ms: Option, + metadata: Value, +) -> Result { + let occurred_at_unix_nanos = SystemTime::now() + .duration_since(UNIX_EPOCH) + .map_err(|error| format!("读取错误事件时间失败:{error}"))? + .as_nanos(); + let sequence = ERROR_EVENT_SEQUENCE.fetch_add(1, Ordering::Relaxed); + let event_id = format!("error-{occurred_at_unix_nanos}-{sequence}"); + let detail_ref = format!(".agent/runtime/errors/{event_id}.json"); + let safe_detail = + redact_agent_runtime_error(root, detail, AGENT_RUNTIME_ERROR_MAX_DETAIL_CHARS); + let diagnostic = serde_json::json!({ + "schemaVersion": AGENT_RUNTIME_ERROR_SCHEMA_VERSION, + "eventId": event_id, + "clientTurnId": client_turn_id, + "source": source, + "stage": stage, + "code": code, + "retryable": retryable, + "occurredAtUnixNanos": occurred_at_unix_nanos.to_string(), + "elapsedMs": elapsed_ms, + "publicText": public_text, + "recoveryHint": recovery_hint, + "detail": safe_detail, + "metadata": metadata, + }); + write_agent_runtime_json_sidecar_with_max_bytes( + root, + &detail_ref, + "统一 Agent Runtime 错误诊断", + &diagnostic, + 16 * 1024, + )?; + Ok(AgentRuntimeErrorEvent { + schema_version: AGENT_RUNTIME_ERROR_SCHEMA_VERSION, + event_id, + client_turn_id: client_turn_id.map(str::to_string), + source: source.to_string(), + stage: stage.to_string(), + code: code.to_string(), + retryable, + occurred_at_unix_nanos: occurred_at_unix_nanos.to_string(), + elapsed_ms, + public_text: public_text.to_string(), + recovery_hint: recovery_hint.to_string(), + detail_ref, + persistence_failed: false, + metadata, + }) +} + +pub(crate) fn classify_direct_codex_error(error: &str) -> &'static str { + let normalized = error.to_ascii_lowercase(); + if normalized.contains("等待 turn/completed 超时") { + "turn-idle-timeout" + } else if normalized.contains("达到 directproject 硬上限") { + "turn-hard-timeout" + } else if normalized.contains("transport closed") || normalized.contains("连接已关闭") { + "transport-closed" + } else if normalized.contains("playtest-attempt-limit-exceeded") { + "playtest-attempt-limit-exceeded" + } else if (normalized.contains("tool") || normalized.contains("工具")) + && normalized.contains("参数") + { + "tool-invalid-arguments" + } else if normalized.contains("codex app-server-error:other") { + "app-server-other" + } else { + "runtime-failure" + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn error_event_is_bounded_and_redacts_private_detail() { + let parent = tempfile::tempdir().expect("temp root"); + let root = parent.path().join("project"); + crate::project::init_local_game_project_at(&root, "runtime-error", "错误事件") + .expect("init project"); + let event = persist_agent_runtime_error( + &root, + Some("turn-123"), + "direct-codex", + "code-generation", + "turn-idle-timeout", + true, + "本轮没有收到完成事件", + "查看诊断后重试", + "C:\\Users\\private\\project https://provider.example/a?token=secret", + Some(1200), + serde_json::json!({"lastEvent":"item/started"}), + ) + .expect("persist event"); + assert_eq!(event.code, "turn-idle-timeout"); + let path = root.join(&event.detail_ref); + let text = std::fs::read_to_string(path).expect("diagnostic"); + assert!(text.contains("")); + assert!(text.contains("")); + assert!(!text.contains("token=secret")); + } + + #[test] + fn timeout_and_tool_errors_have_distinct_codes() { + assert_eq!( + classify_direct_codex_error("等待 turn/completed 超时"), + "turn-idle-timeout" + ); + assert_eq!( + classify_direct_codex_error("达到 DirectProject 硬上限"), + "turn-hard-timeout" + ); + assert_eq!( + classify_direct_codex_error("工具参数 attempt 必须是 1 到 3 的整数"), + "tool-invalid-arguments" + ); + } +} diff --git a/apps/ai-game-creator-shell/src-tauri/src/agent/runtime_state.rs b/apps/ai-game-creator-shell/src-tauri/src/agent/runtime_state.rs index f23bf5f5b..ede8bb200 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/agent/runtime_state.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/agent/runtime_state.rs @@ -101,6 +101,26 @@ pub(crate) fn append_game_creator_agent_runtime_terminal_public_message_at( error: &str, ) -> Result<(), String> { let content = game_creator_agent_runtime_failure_conversation_message(&state.agent_id, error); + // Keep the existing conversation projection, but also persist one common + // bounded diagnostic event for every Agent Runtime terminal failure. This + // makes non-DirectProject failures observable through the same detail API. + let _ = persist_agent_runtime_error( + root, + Some(&state.run_id), + "agent-runtime", + &state.phase, + "agent-runtime-terminal", + false, + &content, + "查看项目错误诊断后处理", + error, + None, + serde_json::json!({ + "agentId": state.agent_id, + "sessionId": state.session_id, + "runId": state.run_id, + }), + ); let status = if state.phase == "budget-exhausted" { "budget-exhausted" } else if state.phase == "needs-reconciliation" { diff --git a/apps/ai-game-creator-shell/src-tauri/src/agent/runtime_tools/media.rs b/apps/ai-game-creator-shell/src-tauri/src/agent/runtime_tools/media.rs index 132c71c59..6f7aa3441 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/agent/runtime_tools/media.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/agent/runtime_tools/media.rs @@ -555,6 +555,17 @@ pub(in crate::agent) async fn observe_agent_runtime_platform_art_asset_generatio .or_else(|| input.get("slice_count")) .and_then(serde_json::Value::as_u64) .map(|value| value as usize); + let slice_mode = agent_runtime_tool_input_text(input, &["sliceMode", "slice_mode"]); + let grid_x = input + .get("gridX") + .or_else(|| input.get("grid_x")) + .and_then(serde_json::Value::as_u64) + .map(|value| value as u32); + let grid_y = input + .get("gridY") + .or_else(|| input.get("grid_y")) + .and_then(serde_json::Value::as_u64) + .map(|value| value as u32); let mut requested_options = PlatformArtAssetGenerationOptions { output_path: (!output_path.trim().is_empty()).then_some(output_path), aspect_ratio, @@ -563,6 +574,9 @@ pub(in crate::agent) async fn observe_agent_runtime_platform_art_asset_generatio asset_label, replace_existing, slice_count, + slice_mode: (!slice_mode.trim().is_empty()).then_some(slice_mode.clone()), + grid_x, + grid_y, }; if let Some(pending) = pending_action { match recover_persisted_visual_generation_options( @@ -609,6 +623,11 @@ pub(in crate::agent) async fn observe_agent_runtime_platform_art_asset_generatio }, replace_existing, slice_count, + slice_mode: requested_options + .slice_mode + .or_else(|| (!slice_mode.trim().is_empty()).then_some(slice_mode)), + grid_x, + grid_y, } }; options.replace_existing = replace_existing; @@ -654,6 +673,28 @@ pub(in crate::agent) async fn observe_agent_runtime_platform_art_asset_generatio detail: None, }; } + if options + .slice_mode + .as_deref() + .is_some_and(|slice_mode| !matches!(slice_mode, "connected-components" | "grid")) + { + return AgentRuntimeToolObservation { + tool: "canvas.asset_generate".to_string(), + status: "failed".to_string(), + summary: "图片生成 sliceMode 不受支持".to_string(), + detail: None, + }; + } + if options.slice_mode.as_deref() == Some("grid") + && (options.grid_x.is_none() || options.grid_y.is_none()) + { + return AgentRuntimeToolObservation { + tool: "canvas.asset_generate".to_string(), + status: "failed".to_string(), + summary: "grid 模式必须同时提供 gridX 与 gridY".to_string(), + detail: None, + }; + } if !agent_runtime_canvas_asset_kind_is_supported(&options.asset_kind) { return AgentRuntimeToolObservation { tool: "canvas.asset_generate".to_string(), diff --git a/apps/ai-game-creator-shell/src-tauri/src/commands.rs b/apps/ai-game-creator-shell/src-tauri/src/commands.rs index b3cc58f28..53c77d151 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/commands.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/commands.rs @@ -4594,6 +4594,9 @@ pub(crate) fn prepare_local_project_asset_generation( .unwrap_or_else(|| LOCAL_PROJECT_ASSET_DEFAULT_ASSET_NAME.to_string()), replace_existing: false, slice_count: None, + slice_mode: None, + grid_x: None, + grid_y: None, }, }) } @@ -5241,6 +5244,38 @@ pub(crate) async fn read_direct_project_conversation( .map_err(|error| format!("读取 DirectProject 历史后台任务失败:{error}"))? } +#[tauri::command] +pub(crate) async fn read_agent_runtime_error_detail( + project_path: String, + detail_ref: String, +) -> Result { + tauri::async_runtime::spawn_blocking(move || { + let root = Path::new(project_path.trim()); + enforce_project_permission_policy(root, "conversation.read")?; + let relative = detail_ref.trim(); + let Some(file_name) = relative.strip_prefix(".agent/runtime/errors/") else { + return Err("错误诊断引用不在项目错误目录内".to_string()); + }; + if file_name.is_empty() + || file_name.contains(['/', '\\']) + || file_name.contains("..") + || !file_name.ends_with(".json") + { + return Err("错误诊断引用格式无效".to_string()); + } + let path = root.join(relative); + prepare_game_creator_private_path_for_read(&path, false, "统一错误诊断")?; + let bytes = std::fs::read(&path).map_err(|error| format!("读取错误诊断失败:{error}"))?; + if bytes.len() > 16 * 1024 { + return Err("错误诊断超过读取上限".to_string()); + } + let text = String::from_utf8(bytes).map_err(|_| "错误诊断不是 UTF-8 文本".to_string())?; + Ok(redact_agent_runtime_error(root, &text, 16 * 1024)) + }) + .await + .map_err(|error| format!("读取统一错误诊断后台任务失败:{error}"))? +} + #[tauri::command] pub(crate) fn append_local_conversation_message( project_path: String, diff --git a/apps/ai-game-creator-shell/src-tauri/src/main.rs b/apps/ai-game-creator-shell/src-tauri/src/main.rs index 5d93e78bc..b95ebf358 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/main.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/main.rs @@ -2672,6 +2672,7 @@ fn main() { hydrate_design_agent_session, reset_design_agent_session, get_design_agent_runtime_mode, + is_design_agent_debug_enabled, set_design_agent_runtime_mode, debug_fast_forward_design_session, continue_design_agent_session, @@ -2767,6 +2768,7 @@ fn main() { archive_game_creator_agent_session, read_local_conversation, read_direct_project_conversation, + read_agent_runtime_error_detail, append_local_conversation_message, append_direct_project_conversation_message, build_local_project_index, diff --git a/apps/ai-game-creator-shell/src-tauri/src/tests/mod.rs b/apps/ai-game-creator-shell/src-tauri/src/tests/mod.rs index 28b4dcbc1..f12416e7d 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/tests/mod.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/tests/mod.rs @@ -3192,7 +3192,9 @@ fn spawn_mock_external_canvas_api_server_with_capture_and_generation_gate( "spritesheetImageSrc": "/generated/canvas/spritesheet.png", "spritesheetWidth": 2, "spritesheetHeight": 1, - "sliceLayout": "grid-2x2", + "sliceMode": "grid", + "gridX": 2, + "gridY": 2, "iconImageSrcs": icon_image_srcs, "sliceWarning": null, "prompt": "原创游戏素材图集", diff --git a/apps/ai-game-creator-shell/src-tauri/src/tests/project.rs b/apps/ai-game-creator-shell/src-tauri/src/tests/project.rs index 52ad3d47d..2270ca448 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/tests/project.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/tests/project.rs @@ -1076,6 +1076,9 @@ async fn canonical_art_spec_and_ui_requests_use_the_shared_reference_chain() { asset_label: "游戏横屏界面原型图".to_string(), replace_existing: false, slice_count: None, + slice_mode: None, + grid_x: None, + grid_y: None, }, ) .await; @@ -1088,6 +1091,90 @@ async fn canonical_art_spec_and_ui_requests_use_the_shared_reference_chain() { fs::remove_dir_all(ui_config_dir).ok(); } +#[tokio::test(flavor = "multi_thread", worker_threads = 2)] +async fn direct_image_generation_notifies_after_manifest_commit() { + let root = unique_project_path(); + let config_dir = unique_project_path(); + let canvas_base_url = spawn_mock_external_canvas_generation_api_server(None); + let _session = crate::platform_session::install_test_platform_session( + "direct-image-refresh-user", + "editor-runtime-key", + &canvas_base_url, + ); + fs::create_dir_all(&config_dir).expect("create config directory"); + fs::write( + config_dir.join(GAME_CREATOR_CONFIG_FILE_NAME), + serde_json::json!({ + "editorApi": { "baseUrl": canvas_base_url, "apiKey": "editor-runtime-key" } + }) + .to_string(), + ) + .expect("write config"); + let _config = use_test_runtime_config_dir(config_dir.clone()); + init_local_game_project_at(&root, "direct-image-refresh", "生成图片刷新测试") + .expect("init project"); + write_project_permission_policy_at( + &root, + ProjectPermissionPolicy { + denied_commands: Vec::new(), + confirm_commands: Vec::new(), + agent_policies: BTreeMap::new(), + }, + ) + .expect("allow generation"); + let listener = + TcpListener::bind((std::net::Ipv4Addr::LOCALHOST, 0)).expect("bind event receiver"); + let sink = acquire_game_creator_manifest_invalidation_event_sink_test_guard(); + sink.configure(listener.local_addr().unwrap().port(), &"d".repeat(64)) + .expect("configure event receiver"); + let bridge = start_direct_tool_bridge(&root, false) + .await + .expect("start tool bridge"); + let client = reqwest::Client::new(); + let result: Value = client.post(bridge.url()).json(&serde_json::json!({ + "tool": "agc_generate_image", + "arguments": { "prompt": "像素月光主角", "kind": "icon-spec", "outputPath": "assets/art-spec.png" } + })).send().await.expect("generate through bridge").json().await.expect("read tool result"); + assert_eq!(result["isError"], false, "{result}"); + let manifest = read_existing_manifest_for_project(&root).expect("read committed manifest"); + assert!(manifest + .assets + .iter() + .any(|asset| asset.local_path == "assets/art-spec.png")); + assert!(root.join("assets/art-spec.png").is_file()); + let payload = read_manifest_invalidation_relay_payload_with_deadline(&listener) + .expect("generation must notify the client"); + let envelope: GameCreatorManifestInvalidationRelayEnvelope = + serde_json::from_slice(&payload).expect("event envelope"); + assert_eq!( + envelope.event.project_path, + fs::canonicalize(&root).unwrap().to_string_lossy() + ); + assert_eq!(envelope.event.agent_id, "direct-codex-art"); + + let rejected: Value = client + .post(bridge.url()) + .json(&serde_json::json!({ + "tool": "agc_generate_image", "arguments": { "prompt": "", "kind": "icon-spec" } + })) + .send() + .await + .expect("send rejected request") + .json() + .await + .expect("read rejected result"); + assert_eq!(rejected["isError"], true); + assert_eq!( + read_manifest_invalidation_relay_payload_with_deadline(&listener) + .expect_err("rejected generation must not emit a commit") + .kind(), + io::ErrorKind::TimedOut + ); + drop(bridge); + fs::remove_dir_all(root).ok(); + fs::remove_dir_all(config_dir).ok(); +} + #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn platform_art_external_request_does_not_hold_project_lock_or_overwrite_manifest() { let root = unique_project_path(); @@ -5409,6 +5496,9 @@ fn ui_prototype_generation_uses_dedicated_prompt_and_art_spec() { asset_label: "游戏横屏界面原型图".to_string(), replace_existing: false, slice_count: None, + slice_mode: None, + grid_x: None, + grid_y: None, }; let prompt = build_platform_art_asset_prompt( "原创网格贪吃蛇:分数与状态 HUD、四类不同分值食物、开始、方向键/WASD、触控方向键、失败与重开", diff --git a/apps/ai-game-creator-shell/src-tauri/tauri.conf.json b/apps/ai-game-creator-shell/src-tauri/tauri.conf.json index 7fc0d7cf1..c5fa7f96b 100644 --- a/apps/ai-game-creator-shell/src-tauri/tauri.conf.json +++ b/apps/ai-game-creator-shell/src-tauri/tauri.conf.json @@ -1,6 +1,6 @@ { "$schema": "https://schema.tauri.app/config/2", - "productName": "Genarrative AI Game Creator", + "productName": "陶泥儿", "version": "0.1.29", "identifier": "world.genarrative.ai-game-creator", "build": { diff --git a/apps/ai-game-creator-shell/src-tauri/tauri.windows.conf.json b/apps/ai-game-creator-shell/src-tauri/tauri.windows.conf.json index 30c71cc2e..5fa3b1b35 100644 --- a/apps/ai-game-creator-shell/src-tauri/tauri.windows.conf.json +++ b/apps/ai-game-creator-shell/src-tauri/tauri.windows.conf.json @@ -4,14 +4,14 @@ "targets": ["nsis"], "useLocalToolsDir": true, "resources": { - "resources/codex/win-x64/bin/codex.exe": "codex/win-x64/bin/codex.exe", - "resources/codex/win-x64/bin/codex-code-mode-host.exe": "codex/win-x64/bin/codex-code-mode-host.exe", - "resources/codex/win-x64/codex-path/rg.exe": "codex/win-x64/codex-path/rg.exe", - "resources/codex/win-x64/codex-resources/codex-command-runner.exe": "codex/win-x64/codex-resources/codex-command-runner.exe", - "resources/codex/win-x64/codex-resources/codex-windows-sandbox-setup.exe": "codex/win-x64/codex-resources/codex-windows-sandbox-setup.exe", - "resources/codex/win-x64/codex-package.json": "codex/win-x64/codex-package.json", - "resources/codex/win-x64/NOTICE.md": "codex/win-x64/NOTICE.md", - "resources/codex/win-x64/manifest.json": "codex/win-x64/manifest.json", + "resources/codex/win-x64/bin/codex.exe": "coding-agent/win-x64/bin/codex.exe", + "resources/codex/win-x64/bin/codex-code-mode-host.exe": "coding-agent/win-x64/bin/codex-code-mode-host.exe", + "resources/codex/win-x64/codex-path/rg.exe": "coding-agent/win-x64/codex-path/rg.exe", + "resources/codex/win-x64/codex-resources/codex-command-runner.exe": "coding-agent/win-x64/codex-resources/codex-command-runner.exe", + "resources/codex/win-x64/codex-resources/codex-windows-sandbox-setup.exe": "coding-agent/win-x64/codex-resources/codex-windows-sandbox-setup.exe", + "resources/codex/win-x64/codex-package.json": "coding-agent/win-x64/codex-package.json", + "resources/codex/win-x64/NOTICE.md": "coding-agent/win-x64/NOTICE.md", + "resources/codex/win-x64/manifest.json": "coding-agent/win-x64/manifest.json", "resources/plugins": "plugins" } } diff --git a/apps/ai-game-creator-shell/src/App.tsx b/apps/ai-game-creator-shell/src/App.tsx index 8f567adce..4809b44ce 100644 --- a/apps/ai-game-creator-shell/src/App.tsx +++ b/apps/ai-game-creator-shell/src/App.tsx @@ -190,6 +190,7 @@ import { missingChatCommandArgumentMessage, projectFileActionDrafts, projectPathHasControlCharacter, + projectPathsMatchForInvalidation, readableArtifactsFromAgentRunTrace, sortCheckpointManifestFiles, summarizeAgentRunSupportFileReadDrafts, @@ -2198,10 +2199,17 @@ export function App({ void subscribeTauriEvent( 'game-creator-manifest-invalidated', (event) => { - if (event.payload.projectPath !== localProjectPathRef.current) { + const activeProjectPath = localProjectPathRef.current; + if ( + !activeProjectPath || + !projectPathsMatchForInvalidation( + event.payload.projectPath, + activeProjectPath, + ) + ) { return; } - void refreshManifest(event.payload.projectPath); + void refreshManifest(activeProjectPath); }, ) .then((unlisten) => { @@ -6533,8 +6541,25 @@ export function App({ void captureAgentRuntimeError(error, PROJECT_SUPERVISOR_AGENT_ID); const message = error instanceof Error ? error.message : String(error); + let persistedDetail = ''; + const detailRef = message.match( + /详情:(\.agent\/runtime\/errors\/[^\s;]+)/, + )?.[1]; + if (detailRef && directInvoke) { + try { + persistedDetail = await directInvoke( + 'read_agent_runtime_error_detail', + { + projectPath: directProjectPath, + detailRef, + }, + ); + } catch { + persistedDetail = ''; + } + } const visibleMessage = projectRuntimeVisibleError( - message, + persistedDetail ? `${message}\n\n${persistedDetail}` : message, '陶泥儿智能创作', true, ); diff --git a/apps/ai-game-creator-shell/src/features/project-summary/projectPath.ts b/apps/ai-game-creator-shell/src/features/project-summary/projectPath.ts index b0a61e6c5..d8a54f66a 100644 --- a/apps/ai-game-creator-shell/src/features/project-summary/projectPath.ts +++ b/apps/ai-game-creator-shell/src/features/project-summary/projectPath.ts @@ -17,6 +17,27 @@ export function projectPathHasControlCharacter(value: string) { }); } +// 失效事件只是重读提示:匹配 Windows 的普通 / verbatim 路径后,调用方仍用当前项目路径 +// 读取权威清单。此比较不解析链接,也不作为文件访问授权依据。 +export function projectPathsMatchForInvalidation( + eventPath: string, + activePath: string | null, +) { + if (!eventPath || !activePath) return false; + function normalize(path: string) { + if (/^\\\\\?\\UNC\\/i.test(path)) { + path = `\\\\${path.slice(8)}`; + } else if (/^\\\\\?\\[a-z]:\\/i.test(path)) { + path = path.slice(4); + } + if (/^[a-z]:[\\/]/i.test(path) || /^\\\\[^?.\\][^\\]*\\[^\\]+/.test(path)) { + return path.replace(/\\/g, '/').replace(/\/+$/, '').toLowerCase(); + } + return path; + } + return normalize(eventPath) === normalize(activePath); +} + export function isSafeProjectRelativePath(value: string) { const path = value.trim(); return ( diff --git a/apps/ai-game-creator-shell/src/features/project-summary/projectSummary.ts b/apps/ai-game-creator-shell/src/features/project-summary/projectSummary.ts index 160f2e563..97b981535 100644 --- a/apps/ai-game-creator-shell/src/features/project-summary/projectSummary.ts +++ b/apps/ai-game-creator-shell/src/features/project-summary/projectSummary.ts @@ -80,6 +80,7 @@ export { isAbsoluteProjectPath, isSafeProjectRelativePath, projectPathHasControlCharacter, + projectPathsMatchForInvalidation, } from './projectPath'; export { summarizeProjectDependencyMap, diff --git a/apps/ai-game-creator-shell/src/features/project-workspace/ConversationModelSelect.tsx b/apps/ai-game-creator-shell/src/features/project-workspace/ConversationModelSelect.tsx index 1bc4c9ea4..324f83aad 100644 --- a/apps/ai-game-creator-shell/src/features/project-workspace/ConversationModelSelect.tsx +++ b/apps/ai-game-creator-shell/src/features/project-workspace/ConversationModelSelect.tsx @@ -14,6 +14,8 @@ import type { ClientLlmModel, ClientLlmModelCatalog, } from '../../services/clientApi'; +import { ClientAuthRequestError } from '../../services/clientApi'; +import { ClientHttpTimeoutError } from '../../services/clientHttp'; import { cachedLlmModelCatalog, refreshLlmModelCatalog, @@ -27,6 +29,14 @@ export type ConversationModelSelectHandle = { /** 客户端配置读取/写回失败:与「模型目录加载失败」区分,避免误导提示。 */ class ModelSelectionConfigError extends Error {} +function modelCatalogErrorMessage(error: unknown) { + if (error instanceof ClientHttpTimeoutError) + return '模型列表请求超时,请重试'; + if (error instanceof ClientAuthRequestError && error.status) + return `模型列表加载失败(HTTP ${error.status})`; + return '模型列表加载失败'; +} + export function ConversationModelSelect({ className, disabled, @@ -51,6 +61,7 @@ export function ConversationModelSelect({ const [busy, setBusy] = useState(!initialCatalog); const [error, setError] = useState(''); const [notice, setNotice] = useState(''); + const [manualRefreshBusy, setManualRefreshBusy] = useState(false); const [open, setOpen] = useState(false); const containerRef = useRef(null); const appliedRevisionRef = useRef( @@ -180,7 +191,11 @@ export function ConversationModelSelect({ ); const syncCatalog = useCallback( - async (showBusy: boolean) => { + async (showBusy: boolean, manualRefresh = false) => { + if (manualRefresh && mountedRef.current) { + setManualRefreshBusy(true); + setNotice('正在刷新模型列表'); + } const busyToken = showBusy ? ++busyTokenRef.current : busyTokenRef.current; @@ -195,12 +210,17 @@ export function ConversationModelSelect({ try { let catalog: ClientLlmModelCatalog; let usingCachedCatalog = false; + let catalogError: unknown = null; try { catalog = await refreshLlmModelCatalog(); - } catch { + } catch (error) { + catalogError = error; const cached = cachedLlmModelCatalog(); if (!cached) { - if (mountedRef.current) setError('模型列表加载失败'); + if (mountedRef.current) { + setError(modelCatalogErrorMessage(error)); + setNotice(''); + } markReady(false); return false; } @@ -209,10 +229,14 @@ export function ConversationModelSelect({ } const ready = await applyCatalog(catalog, showBusy, epochAtRequest); if (usingCachedCatalog && mountedRef.current) - setError('模型列表加载失败'); + setError(modelCatalogErrorMessage(catalogError)); + if (manualRefresh && mountedRef.current) { + setNotice(usingCachedCatalog ? '' : '模型列表已刷新'); + } return ready; } catch (error) { if (mountedRef.current) { + setNotice(''); setError( error instanceof ModelSelectionConfigError ? error.message @@ -230,6 +254,7 @@ export function ConversationModelSelect({ ) { setBusy(false); } + if (manualRefresh && mountedRef.current) setManualRefreshBusy(false); } }, [applyCatalog, markReady], @@ -375,11 +400,12 @@ export function ConversationModelSelect({ type="button" className="conversation-model-menu-refresh" aria-label="刷新模型列表" - disabled={disabled || busy} - onClick={() => void syncCatalog(true)} + disabled={disabled || busy || manualRefreshBusy} + aria-busy={manualRefreshBusy} + onClick={() => void syncCatalog(true, true)} >