import { gameGenres, gameStyles, gameSettings } from './game-contract.ts'; const reads = { readOnlyHint: true, openWorldHint: false }; const writes = { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false }; const object = (properties: Record, required: string[]) => ({ type: 'object', properties, required, additionalProperties: false }); const id = { type: 'string', pattern: '^[a-zA-Z0-9][a-zA-Z0-9_-]{0,100}$' }; const brief = object({ prompt: { type:'string',minLength:1,maxLength:20000 }, multiplayer: { type:'boolean' }, genre:{ enum:[...gameGenres,null] }, style:{ enum:[...gameStyles,null] }, setting:{ enum:[...gameSettings,null] }, orientation:{ enum:['landscape','portrait'] }, playableAd:{ type:'boolean', description:'Portrait single-player only: build a playable ad (instant play, hand tutorial, short levels, end card with a call to action).' } },['prompt','multiplayer']); const metadataText = { title: { type:'string', minLength:1, maxLength:200 }, description: { type:'string', minLength:1, maxLength:20000 }, controls: { type:'string', minLength:1, maxLength:4000 }, }; const action = {oneOf:[ object({type:{enum:['key']},key:{type:'string',maxLength:32},event:{enum:['down','up','press']}},['type','key']), object({type:{enum:['mouse']},event:{enum:['move','down','up','click']},x:{type:'number',minimum:0,maximum:1280},y:{type:'number',minimum:0,maximum:720},selector:{type:'string',pattern:'^#[a-zA-Z][a-zA-Z0-9_-]{0,79}$'},button:{enum:['left','middle','right']}},['type','event']), object({type:{enum:['wait']},ms:{type:'integer',minimum:0,maximum:10000}},['type','ms']), ]}; const actions = {type:'array',maxItems:100,items:action}; const room = {type:'string',pattern:'^[a-zA-Z0-9][a-zA-Z0-9_-]{0,100}$'}; const simulationStep=object({fromTick:{type:'integer',minimum:1,maximum:10000},toTick:{type:'integer',minimum:1,maximum:10000},action:{type:'object',additionalProperties:true}},['fromTick','toTick','action']); const simulationRoute={oneOf:[{enum:['idle','reference']},{type:'array',maxItems:1000,items:simulationStep}]}; // Retained for source parity with main. Intentionally not registered in // shared/phase1-tools.ts or shared/mcp-profiles.json in Cloud P1 (22 registered tools); // /motion-api/games* returns 501 FEATURE_DEFERRED_P2 until Cloud Game Studio lands. export const gameTools = [ { name:'openmotion_game_create',title:'OpenMotion · Create Game', description:'Create a draft playable web game in the connected local workspace. Returns GameCreated and a complete Agent brief. Follow openmotion://workflow/game/start; Multiplayer shooter or 3d briefs scaffold the offline 1–4 player co-op kit with animated CC0 characters. This does not run an Agent or publish.', inputSchema:brief,annotations:writes }, { name:'openmotion_game_get',title:'OpenMotion · Get Game',description:'Read a GameCard and its file inventory in this workspace. Templates are read-only; remix through the local market before editing.',inputSchema:object({id},['id']),annotations:reads }, { name:'openmotion_game_read_file',title:'OpenMotion · Read Game File',description:'Read a game-relative UTF-8 source file, at most 8 MiB. Paths cannot traverse or follow symlinks.',inputSchema:object({id,path:{type:'string'}},['id','path']),annotations:reads }, { name:'openmotion_game_write_files',title:'OpenMotion · Write Game Files',description:'Write 1–100 UTF-8 game source files, at most 8 MiB per batch, in a workspace-owned game. Never writes template files or metadata. Editing a ready/published game changes it to building. Source files are directly shared with local play.',inputSchema:object({id,files:{type:'array',minItems:1,maxItems:100,items:object({path:{type:'string'},content:{type:'string'}},['path','content'])}},['id','files']),annotations:writes }, { name:'openmotion_game_update_meta',title:'OpenMotion · Update Game Metadata',description:'Update an owned game title, description, controls, existing project-relative cover image (at least 960x540 and 16:9 ±5%) and per-locale i18n. Locale fields merge with saved translations; omitted fields and lifecycle status are preserved. Set concise metadata, zh-CN translations and a cover from openmotion_game_capture_cover before publication. Never edits template metadata.',inputSchema:object({id,...metadataText,cover:{type:'string',minLength:1,maxLength:240},i18n:{type:'object',additionalProperties:object(metadataText,[])}},['id']),annotations:{...writes,idempotentHint:true} }, { name:'openmotion_game_capture_cover',title:'OpenMotion · Capture Game Cover',description:'Server-owned headless Chrome captures only the owned game canvas or #game root at 1280x720 to assets/cover.png and sets metadata. Never opens or controls the user browser/desktop/profile. Optional room and bounded key/mouse/wait actions; multiplayer clients join the room and conventional #start is clicked automatically. delayMs is 0–10000. Requires local Chrome and loopback permission; no downloads or internet requests.',inputSchema:object({id,room,actions,delayMs:{type:'integer',minimum:0,maximum:10000}},['id']),annotations:writes }, { name:'openmotion_game_playtest',title:'OpenMotion · Playtest Game',description:'Server-owned headless Chrome with SwiftShader runs 1–4 isolated clients in one room, auto-starts conventional #start after join, and applies scripts[i] key/mouse/wait inputs concurrently. Before any clicks or scripts, asserts every multiplayer client auto-joins within 5 seconds via the room socket or __omGame. Returns console errors, failed requests, game-only screenshot paths, RAF fps estimate, roomJoined and playerCount for each client. When window.__omGame is present, reads authoritative snapshots and reports pass/fail assertions for player count, phase, scripted net movement (default >0.5 units) and horizontal overflow at 390x844. Missing hooks fail authoritative assertions; omitted scripts use a short W movement for every client. Persists screenshots under game assets/playtests. No user browser/desktop/profile; no arbitrary JS or internet requests. durationMs is the minimum observation period; bounded script waits can extend it. GPU, audio, touch and human fun acceptance remain separate.',inputSchema:object({id,clients:{type:'integer',minimum:1,maximum:4},scripts:{type:'array',maxItems:4,items:actions},durationMs:{type:'integer',minimum:0,maximum:60000},room,movementThreshold:{type:'number',minimum:0,maximum:100,description:'Minimum net player displacement; 0 skips the movement check for games without a moving player (tap puzzles, pull-the-pin).'},expectedPhase:{type:'string',minLength:1,maxLength:64}},['id','clients','durationMs']),annotations:writes }, { name:'openmotion_game_simulate',title:'OpenMotion · Simulate Game Rules',description:'Run deterministic logic.js in the existing bounded GameRuntime without a browser or file writes. players 1–4; scripts may be idle, game-provided reference, or one route per player (inclusive fromTick/toTick/action entries repeated each tick). Optional exports referenceRoute(playerIndex) and summarize(state) supply routes and compact summaries. Returns final over/winners/tick and at most 100 timeline snapshots. Before publication verify reference wins and idle loses; neither proves rendering or human balance.',inputSchema:object({id,players:{type:'integer',minimum:1,maximum:4},scripts:{oneOf:[{enum:['idle','reference']},{type:'array',minItems:1,maxItems:4,items:simulationRoute}]},maxTicks:{type:'integer',minimum:1,maximum:10000}},['id','players','scripts','maxTicks']),annotations:reads }, { name:'openmotion_game_trailer',title:'OpenMotion · Game Trailer',description:'Start or read a persistent background gameplay-to-trailer job for a ready/published local game, including built-in templates. Records three real 5-second headless gameplay clips, creates a standard editable native Motion project, and renders/verifies a roughly 19-second silent MP4 through the existing export pipeline. Returns GameTrailer with status/progress/clips/projectId/videoUrl or a clear failure; interrupted jobs become failed on restart and existing clips are preserved. Active starts coalesce; starting a terminal job records a fresh run. Does not publish, download dependencies, use the user browser, or modify bundled templates.',inputSchema:object({id,action:{enum:['start','status']}},['id','action']),annotations:writes }, { name:'openmotion_game_validate',title:'OpenMotion · Validate Game',description:'Check index.html and optional client.js for allowed external CDN hosts; block multiplayer room-code inputs and Join room buttons, warn when the client never reads ?room=, and multiplayer logic.js named exports/determinism; dry-run 50 ticks with two players and JSON views. Returns non-blocking warnings for a missing cover or fewer than 20 approximate changed kit logic lines, plus a reminder per missing design/plan.md, design/assets.csv and design/verification.md. Use openmotion_game_playtest for headless multiplayer evidence; this does not prove gameplay quality.',inputSchema:object({id},['id']),annotations:reads }, { name:'openmotion_game_set_status',title:'OpenMotion · Set Game Status',description:'Set a workspace game to building, ready or failed. Ready alone does not establish validation or publication.',inputSchema:object({id,status:{enum:['building','ready','failed']}},['id','status']),annotations:{...writes,idempotentHint:true} }, { name:'openmotion_game_publish',title:'OpenMotion · Publish Game',description:'Revalidate and list a workspace game in the local game market. Requires authorized local publication. Returns three short nextSteps prompts derived from design/plan.md when available, playUrl, non-blocking warnings for a prompt-like title or missing cover and, for multiplayer, roomInviteUrlPattern. No internet hosting; room simulation is ephemeral in one local process and starts after join/start. Joined messages include a session reconnectToken: return it on join within 30 seconds to reclaim a disconnected seat; running rooms accept late joins up to maxPlayers.',inputSchema:object({id},['id']),annotations:{...writes,idempotentHint:true} }, ];