@craft_eco/craft-mcp 0.1.14 → 0.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist-server/game-workflow/draft-archive.mjs +53 -91
- package/dist-server/game-workflow/draft-uploads.mjs +207 -207
- package/dist-server/game-workflow/publications.mjs +4 -2
- package/dist-server/mcp/control-panel.mjs +59 -40
- package/dist-server/mcp/publication-page.html +86 -0
- package/dist-server/mcp/publication-page.mjs +347 -0
- package/dist-server/mcp/publication-preview.mjs +49 -0
- package/dist-server/mcp/publication-tools.mjs +4 -1
- package/dist-server/mcp/publish-panel.mjs +191 -0
- package/dist-server/mcp/server.mjs +312 -297
- package/dist-server/upstream/craft-aigc.mjs +169 -197
- package/dist-server/upstream/publication-transport.mjs +2 -1
- package/package.json +1 -1
- package/resources/craft-game-maker/SKILL.md +69 -67
- package/vendor/agent-cli/dist/src/artifacts/external-game-archive.d.ts +19 -0
- package/vendor/agent-cli/dist/src/artifacts/external-game-archive.d.ts.map +1 -0
- package/vendor/agent-cli/dist/src/artifacts/external-game-archive.js +107 -0
- package/vendor/agent-cli/dist/src/artifacts/external-game-archive.js.map +1 -0
- package/vendor/agent-cli/dist/src/artifacts/external-game-upload.d.ts +44 -0
- package/vendor/agent-cli/dist/src/artifacts/external-game-upload.d.ts.map +1 -0
- package/vendor/agent-cli/dist/src/artifacts/external-game-upload.js +106 -0
- package/vendor/agent-cli/dist/src/artifacts/external-game-upload.js.map +1 -0
- package/vendor/agent-cli/dist/src/index.d.ts +2 -0
- package/vendor/agent-cli/dist/src/index.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/index.js +2 -0
- package/vendor/agent-cli/dist/src/index.js.map +1 -1
|
@@ -1,297 +1,312 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { mkdir, realpath, readFile } from 'node:fs/promises';
|
|
3
|
-
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
4
|
-
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
5
|
-
import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
6
|
-
import { installProjectDependencies } from '#craft-sdk';
|
|
7
|
-
import { getUserDataDir, getWorkspaceRoot, getProjectBindingsDir } from '../core/app-paths.mjs';
|
|
8
|
-
import { CraftAigc } from '../upstream/craft-aigc.mjs';
|
|
9
|
-
import { Projects, fingerprint } from '../game-workflow/projects.mjs';
|
|
10
|
-
import { RequestStore } from '../game-workflow/request-store.mjs';
|
|
11
|
-
import { Tasks } from '../game-workflow/tasks.mjs';
|
|
12
|
-
import { ProjectLeases } from '../game-workflow/project-leases.mjs';
|
|
13
|
-
import { Assets } from '../game-workflow/assets.mjs';
|
|
14
|
-
import { LibraryAssets } from '../game-workflow/library-assets.mjs';
|
|
15
|
-
import { libraryCapabilities } from '../game-workflow/library-catalog.mjs';
|
|
16
|
-
import { checkGame, validateSteps } from '../game-workflow/check.mjs';
|
|
17
|
-
import { DraftUploads } from '../game-workflow/draft-uploads.mjs';
|
|
18
|
-
import { DraftBindings } from '../game-workflow/draft-bindings.mjs';
|
|
19
|
-
import { Publications } from '../game-workflow/publications.mjs';
|
|
20
|
-
import { Previews } from '../preview/local-static-preview.mjs';
|
|
21
|
-
import { openControlPanel } from './control-panel.mjs';
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
const
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
const
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
const
|
|
53
|
-
const
|
|
54
|
-
const
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
tool('
|
|
82
|
-
tool('
|
|
83
|
-
tool('
|
|
84
|
-
tool('
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
tool('
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
tool('
|
|
95
|
-
tool('
|
|
96
|
-
]
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
async
|
|
113
|
-
|
|
114
|
-
if (
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
if (
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
case '
|
|
153
|
-
const project = await projects.
|
|
154
|
-
|
|
155
|
-
const selected = engines[project.engine];
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
const plan=await assets.
|
|
175
|
-
return assets.generate(plan.records,signal);
|
|
176
|
-
},{request_keys:
|
|
177
|
-
}
|
|
178
|
-
case '
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
case '
|
|
196
|
-
const
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
const
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
break;
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
break;
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { mkdir, realpath, readFile } from 'node:fs/promises';
|
|
3
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
4
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
5
|
+
import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
6
|
+
import { installProjectDependencies } from '#craft-sdk';
|
|
7
|
+
import { getUserDataDir, getWorkspaceRoot, getProjectBindingsDir } from '../core/app-paths.mjs';
|
|
8
|
+
import { CraftAigc } from '../upstream/craft-aigc.mjs';
|
|
9
|
+
import { Projects, fingerprint } from '../game-workflow/projects.mjs';
|
|
10
|
+
import { RequestStore } from '../game-workflow/request-store.mjs';
|
|
11
|
+
import { Tasks } from '../game-workflow/tasks.mjs';
|
|
12
|
+
import { ProjectLeases } from '../game-workflow/project-leases.mjs';
|
|
13
|
+
import { Assets } from '../game-workflow/assets.mjs';
|
|
14
|
+
import { LibraryAssets } from '../game-workflow/library-assets.mjs';
|
|
15
|
+
import { libraryCapabilities } from '../game-workflow/library-catalog.mjs';
|
|
16
|
+
import { checkGame, validateSteps } from '../game-workflow/check.mjs';
|
|
17
|
+
import { DraftUploads, draftUploadView } from '../game-workflow/draft-uploads.mjs';
|
|
18
|
+
import { DraftBindings } from '../game-workflow/draft-bindings.mjs';
|
|
19
|
+
import { Publications } from '../game-workflow/publications.mjs';
|
|
20
|
+
import { Previews } from '../preview/local-static-preview.mjs';
|
|
21
|
+
import { openControlPanel } from './control-panel.mjs';
|
|
22
|
+
import { createPublishPanel } from './publish-panel.mjs';
|
|
23
|
+
import { openPublicationPreview } from './publication-preview.mjs';
|
|
24
|
+
import { loadEngineResources } from '../game-workflow/engines.mjs';
|
|
25
|
+
import { assetCapabilities } from '../game-workflow/resource-catalog.mjs';
|
|
26
|
+
import { takeConnectorToken, ConnectorAuthStore, connectorLoginAction } from '../core/connector-auth.mjs';
|
|
27
|
+
import { generationFields, importFields, generationInputs, searchFields, importSource } from './asset-tools.mjs';
|
|
28
|
+
import { publicationTools } from './publication-tools.mjs';
|
|
29
|
+
|
|
30
|
+
// Consume before any project/build subprocess can inherit the credential.
|
|
31
|
+
let connectorToken = takeConnectorToken();
|
|
32
|
+
const connectorAuth = connectorToken !== undefined;
|
|
33
|
+
const { version } = JSON.parse(await readFile(new URL('../../package.json',import.meta.url),'utf8'));
|
|
34
|
+
await mkdir(getWorkspaceRoot(),{ recursive:true });
|
|
35
|
+
const root = await realpath(getWorkspaceRoot()), state = getUserDataDir(), resources = process.env.CRAFT_MCP_RESOURCES_DIR;
|
|
36
|
+
const store = new RequestStore(path.join(state,'requests'),root); await store.init();
|
|
37
|
+
const platform = new CraftAigc(path.join(state,'auth-session.json'),process.env.CRAFT_WEB_URL,
|
|
38
|
+
connectorAuth ? new ConnectorAuthStore() : undefined);
|
|
39
|
+
if (connectorAuth) {
|
|
40
|
+
try { await platform.login(connectorToken); }
|
|
41
|
+
finally { connectorToken = undefined; }
|
|
42
|
+
}
|
|
43
|
+
const { instructions:guide, engines } = await loadEngineResources(resources);
|
|
44
|
+
const projects = new Projects(root,state,engines); await projects.init();
|
|
45
|
+
const tasks = new Tasks(state); await tasks.init();
|
|
46
|
+
const previews = new Previews(state);
|
|
47
|
+
const leases = new ProjectLeases(root,name=>tasks.cancelProject(name)); await leases.init();
|
|
48
|
+
const assets = new Assets(platform,store,projects);
|
|
49
|
+
const searches = new RequestStore(path.join(state,'recalls'),root); await searches.init();
|
|
50
|
+
const library = new LibraryAssets(platform,store,searches,projects);
|
|
51
|
+
const reviewed = new Set();
|
|
52
|
+
const uploadStore = new RequestStore(path.join(state,'uploads'),root); await uploadStore.init();
|
|
53
|
+
const resourcePaths = { capture:path.join(resources,'game_visual_qa.mjs'), evidence:path.join(path.dirname(uploadStore.directory),'checks') };
|
|
54
|
+
const drafts = new DraftUploads(platform,uploadStore,resourcePaths.evidence,new DraftBindings(getProjectBindingsDir(),root));
|
|
55
|
+
const publicationStore = new RequestStore(path.join(state,'publications'),root); await publicationStore.init();
|
|
56
|
+
const publications = new Publications(platform,publicationStore,drafts,resourcePaths.evidence);
|
|
57
|
+
const mutations = new Set();
|
|
58
|
+
let closing = false;
|
|
59
|
+
async function mutateProject(name,operation) {
|
|
60
|
+
projects.file(name);
|
|
61
|
+
if (closing || mutations.has(name) || tasks.busy(name)) throw new Error('Project has a running operation');
|
|
62
|
+
mutations.add(name);
|
|
63
|
+
try { await leases.acquire(name); return await operation(); }
|
|
64
|
+
finally { mutations.delete(name); }
|
|
65
|
+
}
|
|
66
|
+
const publishPanel=createPublishPanel({ platform,projects,tasks,drafts,publications,checkedTask,mutate:mutateProject,viewTask,
|
|
67
|
+
coverDirectory:path.join(state,'publication-covers'),preview:check=>openPublicationPreview(check,resourcePaths.evidence) });
|
|
68
|
+
const panel=await openControlPanel(platform,{ allowLocalAuth:!connectorAuth,publishPanel });
|
|
69
|
+
function loginAction() {
|
|
70
|
+
if (connectorAuth) return connectorLoginAction();
|
|
71
|
+
const url = panel.url;
|
|
72
|
+
return { status:'action_required',reason:'login',human_action_required:true,url,
|
|
73
|
+
user_message:`请点击[连接 Craft 账号](${url}),在本机页面输入 Token 后,回到这里说“继续”。Token 无需发送到聊天中。` };
|
|
74
|
+
}
|
|
75
|
+
const nameField = { name:{ type:'string', pattern:'^[a-z][a-z0-9-]{0,47}$', description:'Stable local project name. Reuse it for follow-up edits.' } };
|
|
76
|
+
const engineField = { engine:{ type:'string',enum:['js','js3d'],description:'Choose js for 2D/Phaser, js3d for 3D/Three.js. New games default to js; existing games keep their saved engine. Never change an existing game engine.' } };
|
|
77
|
+
const taskField = { task_id:{ type:'string' } };
|
|
78
|
+
const draftFields = { ...nameField, check_task_id:{ type:'string', description:'ID of the passing check for this exact draft build. Reuse the same ID to recover an upload.' } };
|
|
79
|
+
const tool = (name,description,properties={},required=[])=>({ name,description,inputSchema:{ type:'object',properties,required,additionalProperties:false } });
|
|
80
|
+
const tools = [
|
|
81
|
+
tool('craft_game_info','Show Craft version, supported engines and game-making instructions. Supply name to read an existing game engine and context, or engine to inspect the matching 2D/3D guide. Asset-source choices follow that engine CLAUDE.md, relevant skills and user requirements.',{...nameField,...engineField}),
|
|
82
|
+
tool('craft_game_prepare','Start here before editing a game. Acquires this project for the current session until Craft disconnects; another session can use a different name. New 2D games: engine=js; new 3D games: engine=js3d; existing games: reuse name and saved engine. Poll craft_task_status to completion, follow result.instructions and read the engine context before coding, generating/importing, checking, reviewing and delivering.',{...nameField,...engineField},['name']),
|
|
83
|
+
tool('craft_assets_generate','Generate and import 1 to 8 assets when selected by the current engine context and user requirements: image/image_edit, static_mesh, skeletal_mesh, music, video, sprite_sheet or animation (video_url + model_resource_id). Use assets[].kind; inspect craft_game_info.aigc for capabilities. Platform charges automatically. Reuse request_key after failures or restart; never repeat an uncertain paid submission with a new key. Poll craft_task_status and wire the returned config_file slots into the game.',{...nameField,...generationFields},['name']),
|
|
84
|
+
tool('craft_assets_search','Search the Craft asset library without generating assets. Read craft_game_info.library for categories matching the saved engine. Submit 1 to 8 slot/category/query entries; inspect candidates, scores, metadata and per-slot errors. Poll craft_task_status, then import chosen source=library with search_id/candidate_id. No arbitrary URLs or external search credentials.',{...nameField,...searchFields},['name','queries']),
|
|
85
|
+
tool('craft_assets_import','Import existing AIGC outputs by resource_id, or selected library candidates with source=library, search_id and candidate_id. One source per batch. Never generates assets. Localizes files/dependencies, enforces 8 MiB per file and updates typed configs. Poll craft_task_status.',{...nameField,...importFields},['name','assets']),
|
|
86
|
+
tool('craft_assets_status','Read durable asset requests and import results for the current account and project.',nameField,['name']),
|
|
87
|
+
tool('craft_game_check','Finalize engine exports, build, exercise the core loop, settlement and restart, and capture real screenshots. Each step must assert real snapshot().game fields. Poll craft_task_status, then craft_game_review.',{
|
|
88
|
+
...nameField, brief:{ type:'string' }, steps:{ type:'array',minItems:3,maxItems:3,items:{ type:'object',properties:{
|
|
89
|
+
phase:{ type:'string',enum:['loop','settlement','restart'] },action:{ type:'string',enum:['click','press','drag','wait'] },
|
|
90
|
+
target:{ type:'string' },key:{ type:'string' },x:{ type:'number' },y:{ type:'number' },to_x:{ type:'number' },to_y:{ type:'number' },ms:{ type:'integer',minimum:1,maximum:30000 },expected:{ type:'string' },
|
|
91
|
+
assertions:{ type:'array',minItems:1,maxItems:8,items:{ type:'object',properties:{ path:{ type:'string' },operator:{ type:'string',enum:['eq','gte'] },value:{ type:['string','number','boolean'] } },required:['path','operator','value'],additionalProperties:false } },
|
|
92
|
+
},required:['phase','action','expected','assertions'],additionalProperties:false } },
|
|
93
|
+
},['name','brief','steps']),
|
|
94
|
+
tool('craft_task_status','Wait up to 15 seconds and read background progress. Continue polling while running; do not end the user task while assets/checks are running.',{ ...taskField,wait_ms:{ type:'integer',minimum:0,maximum:15000 } },['task_id']),
|
|
95
|
+
tool('craft_task_cancel','Stop this local task and wait for cleanup. For generation tasks also attempt remote queued-task cancellation; processing tasks may continue remotely. Import cancellation stops only the local import.',taskField,['task_id']),
|
|
96
|
+
tool('craft_game_review','Return the check screenshots as images for WorkBuddy visual inspection. Inspect actual visuals and referenced resources, composition, clipping, readability and requested transparency.',taskField,['task_id']),
|
|
97
|
+
tool('craft_game_deliver','Prepare a verified preview after a current passing check and visual review. Craft does not launch the process. Run result.start.script with the external host terminal tool in the background, then poll craft_game_info(name).preview until running=true and snapshot matches this delivery. Verify the page before reporting its URL. The host or OS may reclaim it; restart using the returned command.',{
|
|
98
|
+
...taskField,visual_passed:{ type:'boolean' },visual_notes:{ type:'string',minLength:10,maxLength:2000 },
|
|
99
|
+
},['task_id','visual_passed','visual_notes']),
|
|
100
|
+
tool('craft_game_upload','When the user asks to upload, transfer the frozen build from a current passing check to a private Craft draft. The same local project, account and platform automatically reuse the saved app ID and append a version. Poll craft_task_status. Reuse the same check_task_id after interruption. draft_ready means the private upload is complete, not published. Use craft_game_deliver and the IDE terminal for local preview.',draftFields,['name','check_task_id']),
|
|
101
|
+
tool('craft_game_publish_status','Query publication review with publication_id, or private upload status with check_task_id. Supply exactly one ID. Only report public publication after this specific version reaches share_completed and returns its verified public_url.',{
|
|
102
|
+
...draftFields,publication_id:{ type:'string' },
|
|
103
|
+
},['name']),
|
|
104
|
+
...publicationTools(nameField,tool),
|
|
105
|
+
tool('craft_preview_stop','Stop this project host-launched preview and cancel pending starts, including an earlier session preview.',nameField,['name']),
|
|
106
|
+
tool('craft_auth_open','Check login first. Return a login URL only when unauthenticated; an authenticated account continues without a login URL. Image generation uses automatic platform billing. Never read credentials or automate login.'),
|
|
107
|
+
tool('craft_auth_status','Check the Craft account without exposing credentials.'),
|
|
108
|
+
tool('craft_auth_logout','Forget this local profile login; does not cancel platform generation.'),
|
|
109
|
+
];
|
|
110
|
+
// The connection and prepare result use the same maintained workflow; clients may omit initialize instructions from their model context.
|
|
111
|
+
const server = new Server({ name:'craft-local',version },{ capabilities:{ tools:{} },instructions:guide });
|
|
112
|
+
server.setRequestHandler(ListToolsRequestSchema,async()=>({ tools }));
|
|
113
|
+
function viewTask(task) {
|
|
114
|
+
if (['upload','publish_prepare','publish_submit'].includes(task.kind)) {
|
|
115
|
+
if (task.owner !== platform.account().user_id || task.platform !== platform.base) throw new Error('Draft task belongs to a different account or platform');
|
|
116
|
+
const { owner, platform:target, ...view } = task;
|
|
117
|
+
return task.kind === 'upload' && view.result ? { ...view,result:draftUploadView(view.result) } : view;
|
|
118
|
+
}
|
|
119
|
+
if (!task.result?.artifacts) return task;
|
|
120
|
+
const { artifacts,snapshot_id,...result } = task.result;
|
|
121
|
+
return { ...task,result };
|
|
122
|
+
}
|
|
123
|
+
async function checkedTask(id, name, resumeUpload = false) {
|
|
124
|
+
const task = await tasks.get(id);
|
|
125
|
+
if (task.kind !== 'check' || task.status !== 'completed' || !task.result?.gate?.passed) throw new Error('A completed passing game check is required');
|
|
126
|
+
if (name !== undefined && task.name !== name) throw new Error('Game check belongs to a different project');
|
|
127
|
+
const { project,engine } = await projects.describe(task.name);
|
|
128
|
+
await leases.acquire(task.name);
|
|
129
|
+
if (task.result.engine && task.result.engine !== engine) throw new Error('Game engine changed since verification');
|
|
130
|
+
if (tasks.busy(task.name) || (!resumeUpload && task.result.source !== await fingerprint(project))) throw new Error('Game changed since verification; check again');
|
|
131
|
+
return { task, project };
|
|
132
|
+
}
|
|
133
|
+
server.setRequestHandler(CallToolRequestSchema,async request=>{
|
|
134
|
+
let lock;
|
|
135
|
+
try {
|
|
136
|
+
if (closing) throw new Error('Craft is shutting down');
|
|
137
|
+
const definition = tools.find(t=>t.name === request.params.name), args = request.params.arguments ?? {};
|
|
138
|
+
if (!definition) throw new Error('Unknown tool');
|
|
139
|
+
for (const [key,value] of Object.entries(args)) {
|
|
140
|
+
const field = definition.inputSchema.properties[key];
|
|
141
|
+
if (!field || (field.type === 'integer' ? !Number.isSafeInteger(value) : field.type === 'array' ? !Array.isArray(value) : typeof value !== field.type) || (field.enum && !field.enum.includes(value))) throw new Error('Invalid argument: ' + key);
|
|
142
|
+
}
|
|
143
|
+
for (const key of definition.inputSchema.required) if (args[key] === undefined) throw new Error('Missing argument: ' + key);
|
|
144
|
+
if (['craft_game_prepare','craft_assets_generate','craft_assets_import','craft_game_check','craft_game_upload','craft_game_publish_prepare','craft_game_publish_review','craft_game_publish_submit','craft_game_publish_open'].includes(definition.name)) {
|
|
145
|
+
projects.file(args.name);
|
|
146
|
+
if (mutations.has(args.name) || tasks.busy(args.name)) throw new Error('Project has a running operation');
|
|
147
|
+
mutations.add(args.name); lock = args.name;
|
|
148
|
+
await leases.acquire(args.name);
|
|
149
|
+
}
|
|
150
|
+
let result;
|
|
151
|
+
switch (definition.name) {
|
|
152
|
+
case 'craft_game_info': {
|
|
153
|
+
const project = args.name ? await projects.describe(args.name) : undefined;
|
|
154
|
+
if (project && args.engine && args.engine !== project.engine) throw new Error('Project engine is fixed to ' + project.engine);
|
|
155
|
+
const selected = engines[project?.engine ?? args.engine];
|
|
156
|
+
result = { version, workspace:root, platform:platform.base, engine:selected?.engine ?? null, supported_engines:Object.keys(engines),
|
|
157
|
+
project:project?.project, preview:project ? await previews.status(project.project) : undefined,
|
|
158
|
+
llm:'WorkBuddy', images:'Craft platform', aigc:assetCapabilities(),library:libraryCapabilities(selected?.engine),publishing:true,draft_upload:true,
|
|
159
|
+
publication:{ local_page:true,open_tool:'craft_game_publish_open',requires:'Open the independent local page to preview the frozen build and confirm its exact reviewed materials; platform publish_enabled and ACE gates',material_visibility:'public_on_upload' },
|
|
160
|
+
concurrency:{workspace_sessions:'multiple',project_sessions:1,release:'Close the owning Craft connection; abnormal exit expires within 30 seconds'},
|
|
161
|
+
instructions:selected?.instructions ?? guide, context:selected?.context ?? {workflow:path.join(resources,'craft-game-maker','SKILL.md')} }; break;
|
|
162
|
+
}
|
|
163
|
+
case 'craft_game_prepare': result = await tasks.start(args.name,'prepare',async signal=>{
|
|
164
|
+
const project = await projects.prepare(args.name,args.engine,signal);
|
|
165
|
+
await installProjectDependencies(project.project,undefined,signal);
|
|
166
|
+
const selected = engines[project.engine];
|
|
167
|
+
return { ...project, instructions:selected.instructions, context:selected.context, next:'Read the selected engine CLAUDE.md and follow its relevant skills and user requirements for asset-source and presentation decisions. Implement gameplay, use resource tools when required by that plan, check, review and deliver.' };
|
|
168
|
+
}); break;
|
|
169
|
+
case 'craft_assets_generate': {
|
|
170
|
+
const inputs=generationInputs(args);
|
|
171
|
+
await projects.owned(args.name);
|
|
172
|
+
result = await tasks.start(args.name,'assets',async signal=>{
|
|
173
|
+
if (!(await platform.status(signal)).authenticated) return loginAction();
|
|
174
|
+
const plan = await assets.plan(args.name,inputs,signal);
|
|
175
|
+
return assets.generate(plan.records,signal);
|
|
176
|
+
},{ request_keys:inputs.map(input=>input?.request_key) }); break;
|
|
177
|
+
}
|
|
178
|
+
case 'craft_assets_import': {
|
|
179
|
+
await projects.owned(args.name);
|
|
180
|
+
const source=importSource(args.assets);
|
|
181
|
+
result=await tasks.start(args.name,'import',async signal=>{
|
|
182
|
+
if (!(await platform.status(signal)).authenticated) return loginAction();
|
|
183
|
+
if(source==='library')return library.import(args.name,args.assets,signal);
|
|
184
|
+
const inputs=args.assets.map(({source,...input})=>input);
|
|
185
|
+
const plan=await assets.planImport(args.name,inputs,signal);
|
|
186
|
+
return assets.generate(plan.records,signal);
|
|
187
|
+
},{request_keys:args.assets.map(input=>input?.request_key)});break;
|
|
188
|
+
}
|
|
189
|
+
case 'craft_assets_search': {
|
|
190
|
+
result=await tasks.start(args.name,'search',async signal=>{
|
|
191
|
+
if(!(await platform.status(signal)).authenticated)return loginAction();
|
|
192
|
+
return library.search(args.name,args.queries,signal);
|
|
193
|
+
});break;
|
|
194
|
+
}
|
|
195
|
+
case 'craft_assets_status': {
|
|
196
|
+
const requests=await assets.list(args.name);
|
|
197
|
+
result={assets:requests,images:requests.filter(record=>!record.asset_type || record.asset_type==='Texture2D')};break;
|
|
198
|
+
}
|
|
199
|
+
case 'craft_game_check': {
|
|
200
|
+
validateSteps(args.steps);
|
|
201
|
+
const { project,engine } = await projects.describe(args.name);
|
|
202
|
+
const selected = {...resourcePaths,engine,context:engines[engine].context.engine.directory};
|
|
203
|
+
result = await tasks.start(args.name,'check',signal=>checkGame(project,selected,args.brief,args.steps,signal)); break;
|
|
204
|
+
}
|
|
205
|
+
case 'craft_task_status': result = viewTask(await tasks.get(args.task_id,args.wait_ms ?? 15000)); break;
|
|
206
|
+
case 'craft_task_cancel': {
|
|
207
|
+
const current = await tasks.get(args.task_id);
|
|
208
|
+
if (['upload','publish_prepare','publish_submit'].includes(current.kind)) viewTask(current);
|
|
209
|
+
await leases.acquire(current.name);
|
|
210
|
+
const task = await tasks.cancel(args.task_id);
|
|
211
|
+
result = viewTask(task);
|
|
212
|
+
if (['images','assets'].includes(task.kind)) {
|
|
213
|
+
try { result.remote = await assets.cancelRemote(task.name,task.request_keys); }
|
|
214
|
+
catch (error) { result.remote_cancellation_confirmed = false; result.remote_error = error.message; }
|
|
215
|
+
}
|
|
216
|
+
if (task.kind === 'upload') result.next = 'Check craft_game_publish_status before retrying. A remote draft may already exist.';
|
|
217
|
+
if (task.kind === 'publish_submit') result.next = 'Query craft_game_publish_status with the original publication_id. Cancellation does not retract a remote review or public version.';
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
case 'craft_game_review': {
|
|
221
|
+
const { task } = await checkedTask(args.task_id);
|
|
222
|
+
const content = [{ type:'text',text:JSON.stringify({ task_id:args.task_id, review:'Inspect every screenshot. Report visual_passed and concrete findings; a browser pass alone is not visual acceptance.' }) }];
|
|
223
|
+
for (const file of task.result.screenshots) {
|
|
224
|
+
const data = await readFile(file); if (data.length > 4 * 1024 * 1024) throw new Error('Screenshot too large');
|
|
225
|
+
content.push({ type:'image',mimeType:'image/jpeg',data:data.toString('base64') });
|
|
226
|
+
}
|
|
227
|
+
reviewed.add(args.task_id); return { content };
|
|
228
|
+
}
|
|
229
|
+
case 'craft_game_deliver': {
|
|
230
|
+
const { task,project } = await checkedTask(args.task_id);
|
|
231
|
+
if (!reviewed.has(args.task_id) || args.visual_passed !== true || args.visual_notes.trim().length < 10 || args.visual_notes.length > 2000) throw new Error('Read and review the screenshots before delivery');
|
|
232
|
+
result = { ...await previews.prepare(project,task.result.artifacts), project, name:task.name, check_task_id:args.task_id, visual_notes:args.visual_notes }; break;
|
|
233
|
+
}
|
|
234
|
+
case 'craft_game_upload': {
|
|
235
|
+
const status = await platform.status();
|
|
236
|
+
if (!status.authenticated) { result = loginAction(); break; }
|
|
237
|
+
// An already authorized upload resumes its frozen check, even after later source edits.
|
|
238
|
+
const resume = await drafts.hasRequest(args.name,args.check_task_id,status.user_id);
|
|
239
|
+
const { task } = await checkedTask(args.check_task_id,args.name,resume);
|
|
240
|
+
result = viewTask(await tasks.start(args.name,'upload',signal=>drafts.upload(task,status.user_id,signal),
|
|
241
|
+
{ owner:status.user_id, platform:platform.base, check_task_id:args.check_task_id }));
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
case 'craft_game_publish_status': {
|
|
245
|
+
projects.file(args.name);
|
|
246
|
+
if (Boolean(args.check_task_id) === Boolean(args.publication_id)) throw new Error('Supply exactly one of check_task_id or publication_id');
|
|
247
|
+
const status = await platform.status();
|
|
248
|
+
result = status.authenticated ? args.publication_id
|
|
249
|
+
? await publications.status(args.name,args.publication_id,status.user_id)
|
|
250
|
+
: await drafts.status(args.name,args.check_task_id,status.user_id) : loginAction();
|
|
251
|
+
break;
|
|
252
|
+
}
|
|
253
|
+
case 'craft_game_publish_open': {
|
|
254
|
+
const status=await platform.status();
|
|
255
|
+
result=status.authenticated ? await publishPanel.open(args.name,args.check_task_id,args.publication_id) : loginAction(); break;
|
|
256
|
+
}
|
|
257
|
+
case 'craft_game_publish_options': {
|
|
258
|
+
const status = await platform.status();
|
|
259
|
+
result = status.authenticated ? { ...await platform.publicationSession(status.user_id)('options'),
|
|
260
|
+
minimum_playtest_seconds:30,display_screenshots:{ minimum:1,maximum:5 },material_visibility:'public_on_upload' } : loginAction();
|
|
261
|
+
break;
|
|
262
|
+
}
|
|
263
|
+
case 'craft_game_publish_prepare': {
|
|
264
|
+
const status = await platform.status();
|
|
265
|
+
if (!status.authenticated) { result = loginAction(); break; }
|
|
266
|
+
const { task,project } = await checkedTask(args.check_task_id,args.name,await drafts.hasRequest(args.name,args.check_task_id,status.user_id));
|
|
267
|
+
result = viewTask(await tasks.start(args.name,'publish_prepare',signal=>publications.prepare(task,project,args.materials,status.user_id,signal),
|
|
268
|
+
{ owner:status.user_id,platform:platform.base,check_task_id:args.check_task_id }));
|
|
269
|
+
break;
|
|
270
|
+
}
|
|
271
|
+
case 'craft_game_publish_review': {
|
|
272
|
+
const status = await platform.status();
|
|
273
|
+
if (!status.authenticated) { result = loginAction(); break; }
|
|
274
|
+
return await publications.review(args.name,args.publication_id,status.user_id);
|
|
275
|
+
}
|
|
276
|
+
case 'craft_game_publish_submit': {
|
|
277
|
+
const status = await platform.status();
|
|
278
|
+
if (!status.authenticated) { result = loginAction(); break; }
|
|
279
|
+
result = viewTask(await tasks.start(args.name,'publish_submit',signal=>publications.submit(args.name,args.publication_id,args.revision,args.confirmed,status.user_id,signal),
|
|
280
|
+
{ owner:status.user_id,platform:platform.base,publication_id:args.publication_id }));
|
|
281
|
+
break;
|
|
282
|
+
}
|
|
283
|
+
case 'craft_preview_stop': await leases.acquire(args.name); result = await previews.stop(await projects.owned(args.name)); break;
|
|
284
|
+
case 'craft_auth_open': {
|
|
285
|
+
const status = await platform.status();
|
|
286
|
+
result = !status.authenticated ? loginAction() :
|
|
287
|
+
{ ...status,status:'already_authenticated',human_action_required:false,next:'Continue making the game. No login page is needed. Required generation uses automatic platform billing.' };
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
case 'craft_auth_status': {
|
|
291
|
+
result = { ...await platform.status(), auth_mode:connectorAuth ? 'token' : 'local_page' };
|
|
292
|
+
if (connectorAuth && !result.authenticated) Object.assign(result,connectorLoginAction());
|
|
293
|
+
break;
|
|
294
|
+
}
|
|
295
|
+
case 'craft_auth_logout': {
|
|
296
|
+
result = platform.logout();
|
|
297
|
+
if (connectorAuth) result.user_message = '本进程已退出登录。要移除 WorkBuddy 保存的凭证,请在连接器中断开或清除凭证;重新连接会再次注入。';
|
|
298
|
+
break;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
return { content:[{ type:'text',text:JSON.stringify(result) }] };
|
|
302
|
+
} catch (error) { return { isError:true,content:[{ type:'text',text:JSON.stringify({ error:error.message,...error.detail }) }] }; }
|
|
303
|
+
finally { if (lock) mutations.delete(lock); }
|
|
304
|
+
});
|
|
305
|
+
async function shutdown() {
|
|
306
|
+
if (closing) return;
|
|
307
|
+
closing = true;
|
|
308
|
+
await tasks.close(); await leases.close(); await panel.close(); await server.close();
|
|
309
|
+
}
|
|
310
|
+
for (const signal of ['SIGINT','SIGTERM']) process.once(signal,()=>{ void shutdown().then(()=>process.exit(0)); });
|
|
311
|
+
process.stdin.once('end',()=>{ void shutdown(); });
|
|
312
|
+
await server.connect(new StdioServerTransport());
|