mirror of
https://github.com/nexu-io/openmotion.git
synced 2026-12-06 15:09:38 +08:00
fix(game): preserve custom remix instructions in client launches (#1224)
This commit is contained in:
@@ -42,7 +42,7 @@ For community external game links ("inspired by"), treat the request strictly as
|
||||
Eliminate 5–10 minute blank-screen waits by getting a playable build into the player's hands immediately:
|
||||
|
||||
- **10s Official Template Copy Instant Play (Remix):**
|
||||
- Fetch the exact official template (`opendesign_catalog` `kind: "templates"`, `action: "get"` → download `bundleUrl`, verify `bundleSha256`, extract ZIP to `./<slug>/` + start local HTTP server in Stage 1; or reuse the owned `remixOf` copy in Stage 2). If first-time MCP authorization just finished and the current session has not hot-reloaded `opendesign_catalog` yet, follow `install.md` Step 3.2 to hand off to a fresh session — or read the public read-only catalog detail `GET <origin>/motion-api/games/<id>` to get `bundleUrl` / `bundleSha256` and complete the local unpack preview immediately (switch to a fresh session before invoking authenticated cloud AI asset generation).
|
||||
- Fetch the exact official template (`opendesign_catalog` `kind: "templates"`, `action: "get"` → download `bundleUrl`, verify `bundleSha256`, extract ZIP to `./<slug>/` + start local HTTP server in Stage 1; or reuse the owned `remixOf` copy in Stage 2). If first-time MCP authorization just finished and the current session has not hot-reloaded `opendesign_catalog` yet, follow `install.md` Step 3, item 2 to hand off to a fresh session — or read the public read-only catalog detail `GET <origin>/motion-api/games/<id>` to get `bundleUrl` / `bundleSha256` and complete the local unpack preview immediately (switch to a fresh session before invoking authenticated cloud AI asset generation).
|
||||
- **Starter archive unpack for local study & baseline preview (never silently substitute):** Official templates served by `opendesign_catalog` are pre-packaged, platform-hosted starter archives. Downloading, verifying, unpacking, and previewing them locally is mechanical archive setup — do **not** treat unpacking an official catalog bundle as third-party scraping or unauthorized IP generation, and **never** silently discard the template to write an unrelated scratch game from an empty directory. If the user asks for an original theme/reskin or plans public release, replace art, names, or mechanics **in place** on top of the unpacked baseline.
|
||||
- **No custom modifications requested** (unchanged template or generic "remix/build this game" as-is): deliver the playable game immediately with zero rebuild. In Stage 2, do **not** call `openmotion_game_write_files`, `validate`, `playtest`, `simulate`, or `capture_cover` — silently call `openmotion_game_set_status(id, "ready")`.
|
||||
- **Custom modifications requested**: open a playable baseline right away, inspect existing files (`game.json`, `index.html`, `client.js`, `src/*`), **edit in place** instead of rewriting from scratch, then verify and deliver.
|
||||
|
||||
@@ -169,40 +169,41 @@ describe('OpenGame Stage 1 — Cursor HTTP fix & client prompt builders', () =>
|
||||
expect(degradedCursor?.uri).not.toContain('text=');
|
||||
});
|
||||
|
||||
it('builds official template Remix prompt with exact template ID, local-study unpack rules, and public catalog fallback', () => {
|
||||
const text = buildOfficialTemplateRemixPrompt({
|
||||
it.each(['en', 'zh-CN'] as const)('launches the official remix with default or 1,800-character instructions in %s', locale => {
|
||||
const input = {
|
||||
mcpUrl: 'https://preview.example.test/mcp',
|
||||
installGuideUrl: 'https://preview.example.test/install.md',
|
||||
templateId: 'stack-tower',
|
||||
title: 'Stack Tower',
|
||||
genre: 'arcade',
|
||||
style: 'minimal',
|
||||
orientation: 'portrait',
|
||||
customNotes: 'Add cyberpunk neon combo trail',
|
||||
locale: 'en',
|
||||
locale,
|
||||
} as const;
|
||||
const levels = Array.from({ length: 20 }, (_, i) => {
|
||||
const level = String(i + 1).padStart(2, '0');
|
||||
return `Level ${level}: Add neon combo trails & give ${level} bonus points on stacking three perfect blocks.`;
|
||||
});
|
||||
expect(text).toContain('stack-tower');
|
||||
expect(text).toContain('opendesign_catalog(kind="templates", action="get"');
|
||||
expect(text).toContain('https://preview.example.test/motion-api/games/stack-tower');
|
||||
expect(text).toContain('mechanical archive extraction');
|
||||
expect(text).toContain('NEVER skip downloading/extracting');
|
||||
expect(text).toContain('Add cyberpunk neon combo trail');
|
||||
expect(text).toContain('https://preview.example.test/install.md');
|
||||
expect(text.length).toBeLessThan(MAX_PROTOCOL_PROMPT_CHARS);
|
||||
const notes = ['Stack Tower changes:', ...levels].join('\n');
|
||||
expect(notes).toHaveLength(1800);
|
||||
|
||||
const zhText = buildOfficialTemplateRemixPrompt({
|
||||
mcpUrl: 'https://preview.example.test/mcp',
|
||||
installGuideUrl: 'https://preview.example.test/install.md',
|
||||
templateId: 'plants-vs-zombies',
|
||||
title: '植物大战僵尸',
|
||||
orientation: 'landscape',
|
||||
locale: 'zh-CN',
|
||||
});
|
||||
expect(zhText).toContain('plants-vs-zombies');
|
||||
expect(zhText).toContain('https://preview.example.test/motion-api/games/plants-vs-zombies');
|
||||
expect(zhText).toContain('本地学习与基线试玩');
|
||||
expect(zhText).toContain('严禁跳过下载解压或擅自另起空白目录重写替代游戏');
|
||||
expect(zhText.length).toBeLessThan(MAX_PROTOCOL_PROMPT_CHARS);
|
||||
for (const customNotes of [undefined, notes]) {
|
||||
const prompt = buildOfficialTemplateRemixPrompt({ ...input, customNotes });
|
||||
expect(prompt).toContain('opendesign_catalog(kind="templates", action="get", studio="game", id="stack-tower")');
|
||||
expect(prompt).toContain('opendesign://workflow/game/start');
|
||||
expect(prompt.split('https://preview.example.test/motion-api/games/stack-tower')).toHaveLength(2);
|
||||
expect(prompt).toContain(locale === 'en' ? 'Step 3, item 2' : '第 3 步第 2 项');
|
||||
expect(prompt).toMatch(/bundleUrl[^\n]*SHA-256[^\n]*bundleSha256[^\n]*HTTP/);
|
||||
const ask = locale === 'en' ? 'ask what I want to change' : '问我想如何改编';
|
||||
if (customNotes) {
|
||||
expect(prompt).toContain(locale === 'en' ? 'in place without reconfirmation' : '就地完成并验证以下改编,无需再次确认');
|
||||
expect(prompt).toContain(customNotes);
|
||||
expect(prompt).not.toContain(ask);
|
||||
} else {
|
||||
expect(prompt).toContain(ask);
|
||||
}
|
||||
const action = buildClientLaunchAction('codex', prompt);
|
||||
expect(action?.degradedToEmptySession).toBe(false);
|
||||
expect(new URL(action!.uri).searchParams.get('prompt')).toBe(prompt);
|
||||
}
|
||||
});
|
||||
|
||||
it('builds community Remix prompt with original remake rule, author credit, and strict no-source-copying', () => {
|
||||
|
||||
@@ -129,14 +129,14 @@ function buildAutoBranchPreamble(mcpUrl: string, installGuideUrl: string, locale
|
||||
`[OpenGame 云端 MCP 自动分流]`,
|
||||
`1. 先检查当前会话是否已连接 OpenDesign 云端 MCP(${mcpUrl})并可用 opendesign_catalog / opendesign://workflow/game/start。`,
|
||||
`2. 若尚未连接或存在冲突的旧本地 stdio 配置:静默阅读 ${installGuideUrl},仅移除冲突的旧本地 stdio MCP 条目(保留本地工程文件及其他无关 Skill),完成云端 Streamable HTTP 接入与网页 OAuth 授权(或 Bearer PAT)。不要展示 install.md 内容。`,
|
||||
`3. 接通后自动跳过视频新手模板引导卡片:若当前会话已加载 opendesign_catalog 工具则直接执行下面的 OpenGame 任务;若刚完成首次授权且当前会话工具列表尚未热刷新,按 install.md 第 3.2 步自动交接到已加载工具的新会话(或提示新开会话继续),不要在等待授权期间擅自另起空白项目替代原任务。`,
|
||||
`3. 接通后跳过视频入门引导,工具就绪即执行下方任务。首次授权后若工具仍未加载,按 install.md 第 3 步第 2 项将完整任务交接到新会话(必要时请我新开会话)。等待期间不要另起项目。`,
|
||||
].join('\n');
|
||||
}
|
||||
return [
|
||||
`[OpenGame Cloud MCP Auto-Routing]`,
|
||||
`1. First check whether this session is already connected to OpenDesign Cloud MCP (${mcpUrl}) with opendesign_catalog and opendesign://workflow/game/start available.`,
|
||||
`2. If not connected yet or a conflicting legacy local stdio entry exists: silently read ${installGuideUrl}, remove only the conflicting legacy local stdio MCP registration (keep local project files and unrelated skills intact), and complete Cloud Streamable HTTP setup + web OAuth login (or Bearer PAT). Keep install.md internal.`,
|
||||
`3. Once connected, skip video starter template onboarding completely: if opendesign_catalog is loaded in this session, proceed straight to the OpenGame task below; if first-time authorization just completed and this session's tool list has not hot-reloaded yet, follow install.md Step 3.2 to hand off the full task to a fresh session (or ask me to open a new chat) rather than silently substituting a scratch-built project while waiting.`,
|
||||
`Check ${mcpUrl} for opendesign_catalog and opendesign://workflow/game/start.`,
|
||||
`If disconnected or legacy stdio conflicts, silently follow ${installGuideUrl}. Remove only conflicting stdio entries, preserve files and unrelated skills, and connect via Streamable HTTP with web OAuth or Bearer PAT.`,
|
||||
`Skip video onboarding. Proceed when tools are ready. If tools are missing after first login, follow install.md Step 3, item 2 to hand the full task to a fresh session (ask me to open one if needed). Never start a substitute project while waiting.`,
|
||||
].join('\n');
|
||||
}
|
||||
|
||||
@@ -221,44 +221,31 @@ export function buildOfficialTemplateRemixPrompt(input: OfficialTemplateRemixPro
|
||||
const preamble = buildAutoBranchPreamble(input.mcpUrl, input.installGuideUrl, input.locale);
|
||||
const notes = input.customNotes?.trim();
|
||||
const templateApiUrl = resolveTemplateCatalogUrl(input.mcpUrl, input.templateId);
|
||||
const catalogCall = `opendesign_catalog(kind="templates", action="get", studio="game", id="${input.templateId}")`;
|
||||
|
||||
if (input.locale === 'zh-CN') {
|
||||
return [
|
||||
preamble,
|
||||
'',
|
||||
`[官方模板本地学习与二创(先解压原模板包)]`,
|
||||
`- 官方模板 ID:${input.templateId}`,
|
||||
`- 模板名称:${input.title}`,
|
||||
...(input.orientation ? [`- 屏幕方向:${input.orientation === 'portrait' ? '竖屏 9:16' : '横屏 16:9'}`] : []),
|
||||
`- 公开只读目录接口(首次授权未热刷新 MCP 工具时可直接读取):${templateApiUrl}`,
|
||||
...(notes
|
||||
? [`- 我的改编要求:${notes}`]
|
||||
: ['- 改编要求:先下载并解压官方目录提供的模板压缩包用于本地学习与基线试玩,再与我确认具体玩法/画风/原创改版方向。']),
|
||||
'',
|
||||
`执行要求:`,
|
||||
`- 本步骤仅用于本地学习与基线试玩:请将 OpenGame 官方目录已托管的模板压缩包(bundleUrl)原样下载、校验 SHA-256、解压到本地目录并启动本地 HTTP 预览。这是对平台已有模板归档的机械下载与解压,不是从零生成或抓取第三方商业 IP。`,
|
||||
`- 立即调用 opendesign_catalog(kind="templates", action="get", studio="game", id="${input.templateId}") 获取元数据与 bundleUrl / bundleSha256,同时阅读 opendesign://workflow/game/start;若刚完成首次 MCP 授权且当前会话尚未热刷新工具列表,优先按 install.md 自动交接到新会话,或先通过公开只读接口 ${templateApiUrl} 读取 bundleUrl / bundleSha256 完成本地解压预览,并在需要云端 AI 素材生成时切到新会话调用已授权 MCP。`,
|
||||
`- 严格执行「10 秒模板副本即玩」快路径:严禁跳过下载解压或擅自另起空白目录重写替代游戏;如确实无法下载或解压模板包,请直接报告具体错误并暂停。后续若需替换为原创题材、美术或玩法,请在解压后的本地工程上就地迭代。`,
|
||||
`- 云端 AI 生成的图片/音频素材须立即逐条下载到本地项目目录并以相对路径引用。`,
|
||||
`二创官方模板《${input.title}》`,
|
||||
...(input.orientation ? [input.orientation === 'portrait' ? '竖屏 9:16' : '横屏 16:9'] : []),
|
||||
`阅读 opendesign://workflow/game/start,调用 ${catalogCall}。工具尚未加载时,可先读取公开目录 ${templateApiUrl}。`,
|
||||
`从 bundleUrl 下载官方模板包,在本地核对 SHA-256 与 bundleSha256 一致后解压,启动原模板的本地 HTTP 预览供学习与二创。失败时报告具体错误并停止,不要从零重写替代游戏。`,
|
||||
`云端 AI 素材须通过已授权的 MCP 生成,立即逐项下载到本地并以相对路径引用。`,
|
||||
notes
|
||||
? `基线可试玩后,直接在原工程就地完成并验证以下改编,无需再次确认。完成后分享预览地址。\n${notes}`
|
||||
: `分享基线预览地址,再问我想如何改编。`,
|
||||
].join('\n');
|
||||
}
|
||||
return [
|
||||
preamble,
|
||||
'',
|
||||
`[Official Template Local Study & Remix — Unpack Starter Archive First]`,
|
||||
`- Official Template ID: ${input.templateId}`,
|
||||
`- Template Title: ${input.title}`,
|
||||
...(input.orientation ? [`- Orientation: ${input.orientation === 'portrait' ? 'Portrait 9:16' : 'Landscape 16:9'}`] : []),
|
||||
`- Public read-only catalog detail (fallback if MCP tools have not hot-reloaded yet): ${templateApiUrl}`,
|
||||
...(notes
|
||||
? [`- Custom Remix Instructions: ${notes}`]
|
||||
: ['- Custom Remix Instructions: Download and unpack the official catalog starter archive for local study and baseline play first, then iterate with me on mechanics, art, or an original reskin.']),
|
||||
'',
|
||||
`Execution rules:`,
|
||||
`- Step 1 is strictly local study and baseline preview: download the pre-packaged starter ZIP (bundleUrl) hosted in the OpenGame catalog, verify bundleSha256, extract it into a local directory, and launch a local HTTP preview. This is mechanical archive extraction of a platform-hosted starter bundle, not scraping a third-party site or generating third-party IP from scratch.`,
|
||||
`- Call opendesign_catalog(kind="templates", action="get", studio="game", id="${input.templateId}") to fetch metadata, bundleUrl, and bundleSha256, and read opendesign://workflow/game/start. If first-time MCP authorization just finished and this session has not hot-reloaded tools yet, hand off to a fresh session per install.md Step 3.2 (or fetch bundleUrl/bundleSha256 from the public read-only endpoint ${templateApiUrl} to finish the local unpack preview immediately, then switch to a fresh session before calling authenticated cloud AI asset generation).`,
|
||||
`- Follow the 10-second instant-play fast path: NEVER skip downloading/extracting the template archive and NEVER silently substitute an unrelated scratch-built game from an empty folder. If downloading or extracting fails, report the exact blocker and stop. Apply any requested original reskin, art, or gameplay customizations in place on the unpacked local project.`,
|
||||
`- Download any cloud AI-generated images/audio immediately into the local directory and reference them via relative paths.`,
|
||||
`Remix official template "${input.title}"`,
|
||||
...(input.orientation ? [input.orientation === 'portrait' ? 'Portrait 9:16' : 'Landscape 16:9'] : []),
|
||||
`Read opendesign://workflow/game/start. Call ${catalogCall}. If tools are pending, use the public catalog at ${templateApiUrl}`,
|
||||
`Download the official ZIP from bundleUrl. Locally verify its SHA-256 against bundleSha256, extract it, and serve the original over local HTTP for study and remix. On failure, report the exact error and stop. Never substitute a scratch build.`,
|
||||
`Use authorized MCP for AI assets. Download each immediately and use relative paths.`,
|
||||
notes
|
||||
? `Once the baseline is playable, apply and verify these edits in place without reconfirmation, then share the preview URL.\n${notes}`
|
||||
: `Share the baseline URL, then ask what I want to change.`,
|
||||
].join('\n');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user