@craft_eco/craft-mcp 0.1.35-beta.1 → 0.1.35-beta.2
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/dist-server/game-workflow/draft-archive.mjs +61 -0
- package/dist-server/game-workflow/draft-uploads.mjs +108 -39
- package/dist-server/game-workflow/project-bundles.mjs +1 -1
- package/dist-server/integrations/project-setup.mjs +0 -1
- package/dist-server/mcp/server.mjs +3 -3
- package/dist-server/mcp/update-session.mjs +0 -1
- package/dist-server/upstream/draft-audit.mjs +40 -2
- package/dist-server/upstream/draft-transport.mjs +1 -1
- package/package.json +2 -3
|
@@ -202,6 +202,67 @@ export async function checkedDraftArchive(evidence,snapshotId,artifacts,signal)
|
|
|
202
202
|
return encodeCheckedDraftArchive(files,signal);
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
+
export async function applyFilteredTextFiles(project, filteredFiles, signal) {
|
|
206
|
+
signal?.throwIfAborted();
|
|
207
|
+
const root = await realpath(project);
|
|
208
|
+
const targets = [];
|
|
209
|
+
const seen = new Set();
|
|
210
|
+
for (const item of filteredFiles) {
|
|
211
|
+
signal?.throwIfAborted();
|
|
212
|
+
if (!item || typeof item.location !== 'string' || !item.location.startsWith('source/') ||
|
|
213
|
+
typeof item.filtered_text !== 'string' || !item.filtered_text || item.filtered_text.includes('\0')) {
|
|
214
|
+
throw new Error('Invalid filtered text entry');
|
|
215
|
+
}
|
|
216
|
+
const rel = item.location.slice('source/'.length);
|
|
217
|
+
if (!rel || !/\.(?:md|txt)$/i.test(rel) || seen.has(rel)) throw new Error('Invalid filtered text path');
|
|
218
|
+
const parts = rel.split('/');
|
|
219
|
+
let prefix = '';
|
|
220
|
+
for (const part of parts) {
|
|
221
|
+
const current = prefix ? `${prefix}/${part}` : part;
|
|
222
|
+
if (!part || part === '.' || part === '..' || skipSourceEntry(part, current)) {
|
|
223
|
+
throw new Error('Filtered text path is not replaceable');
|
|
224
|
+
}
|
|
225
|
+
checkSourcePath(part, current);
|
|
226
|
+
prefix = current;
|
|
227
|
+
}
|
|
228
|
+
const target = path.join(root, ...parts);
|
|
229
|
+
const relativeToRoot = path.relative(root, target);
|
|
230
|
+
if (!relativeToRoot || path.isAbsolute(relativeToRoot) || relativeToRoot === '..' || relativeToRoot.startsWith('..' + path.sep)) {
|
|
231
|
+
throw new Error('Filtered text path escapes project root');
|
|
232
|
+
}
|
|
233
|
+
const before = await lstat(target, { bigint: true });
|
|
234
|
+
if (!before.isFile() || before.isSymbolicLink() || await realpath(target) !== target) {
|
|
235
|
+
throw new Error('Filtered text target must be a regular local file');
|
|
236
|
+
}
|
|
237
|
+
seen.add(rel);
|
|
238
|
+
targets.push({ rel, target, before, filteredText: item.filtered_text });
|
|
239
|
+
}
|
|
240
|
+
const appliedPaths = [];
|
|
241
|
+
const writeFlags = fsConstants.O_RDWR | (fsConstants.O_NOFOLLOW ?? 0);
|
|
242
|
+
for (const { rel, target, before, filteredText } of targets) {
|
|
243
|
+
signal?.throwIfAborted();
|
|
244
|
+
const handle = await open(target, writeFlags);
|
|
245
|
+
try {
|
|
246
|
+
const opened = await handle.stat({ bigint: true });
|
|
247
|
+
if (!sameSourceFile(before, opened, true) || await realpath(target) !== target) {
|
|
248
|
+
throw new Error('Filtered text target changed during update');
|
|
249
|
+
}
|
|
250
|
+
const nextBytes = Buffer.from(filteredText, 'utf8');
|
|
251
|
+
await handle.truncate(0);
|
|
252
|
+
for (let written = 0; written < nextBytes.length; ) {
|
|
253
|
+
signal?.throwIfAborted();
|
|
254
|
+
const { bytesWritten } = await handle.write(nextBytes, written, nextBytes.length - written, written);
|
|
255
|
+
if (!bytesWritten) throw new Error('Failed to write filtered text file');
|
|
256
|
+
written += bytesWritten;
|
|
257
|
+
}
|
|
258
|
+
} finally {
|
|
259
|
+
await handle.close();
|
|
260
|
+
}
|
|
261
|
+
appliedPaths.push(rel);
|
|
262
|
+
}
|
|
263
|
+
return appliedPaths;
|
|
264
|
+
}
|
|
265
|
+
|
|
205
266
|
export function encodeCheckedDraftArchive(files,signal) {
|
|
206
267
|
return encodeExternalGameArchive(Array.from(files,([url,{ data }])=>[url.slice(1),data]),signal);
|
|
207
268
|
}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
2
|
import { promisify } from 'node:util';
|
|
3
3
|
import { gzip } from 'node:zlib';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
applyFilteredTextFiles,
|
|
6
|
+
checkedDraftFiles,
|
|
7
|
+
checkedDraftSource,
|
|
8
|
+
encodeCheckedDraftArchive,
|
|
9
|
+
} from './draft-archive.mjs';
|
|
5
10
|
import { guardWork } from './work-scope.mjs';
|
|
6
11
|
import path from 'node:path';
|
|
7
12
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
@@ -15,6 +20,7 @@ import {
|
|
|
15
20
|
import { draftUploadIdentity } from './draft-upload-identity.mjs';
|
|
16
21
|
import { digest } from './request-store.mjs';
|
|
17
22
|
import { validMcpProduceLocation } from '../core/production-source.mjs';
|
|
23
|
+
import { modelAuditErrorMessage } from '../upstream/draft-audit.mjs';
|
|
18
24
|
import { assertSourceUploadLimit, validSourceMetadata } from '../upstream/draft-source.mjs';
|
|
19
25
|
import { assertUploadSecurity, uploadSecurityPolicyVersion } from './upload-security.mjs';
|
|
20
26
|
|
|
@@ -59,10 +65,10 @@ function hasCurrentSecurityReview(record) {
|
|
|
59
65
|
|
|
60
66
|
function mergeReceipt(record, result) {
|
|
61
67
|
const prior = record.content_audit, current = result.content_audit;
|
|
62
|
-
if ((record.text_audit_protocol || prior) && !current) throw new Error('Craft
|
|
68
|
+
if ((record.text_audit_protocol || prior) && !current) throw new Error('Craft 未返回约定的内容审核状态');
|
|
63
69
|
if (prior && (current?.revision < prior.revision || (processing(record) && (!current || current.state === 'not_started')) ||
|
|
64
70
|
(current?.revision === prior.revision && current.state !== prior.state) ||
|
|
65
|
-
(terminal(record) && current?.state !== prior.state))) throw new Error('Craft
|
|
71
|
+
(terminal(record) && current?.state !== prior.state))) throw new Error('Craft 返回了过期或矛盾的内容审核状态');
|
|
66
72
|
if (record.audit && !result.audit && result.state !== 'expired') throw new Error('Craft 未返回已有上传检查的状态');
|
|
67
73
|
if (result.state === 'draft_ready' && result.audit && result.audit.state !== 'passed') throw new Error('Craft 未确认上传检查通过');
|
|
68
74
|
if (record.upload_id !== undefined && record.upload_id !== result.upload_id) throw new Error('Craft changed the upload ID for this request');
|
|
@@ -89,27 +95,38 @@ function mergeReceipt(record, result) {
|
|
|
89
95
|
return updated;
|
|
90
96
|
}
|
|
91
97
|
|
|
98
|
+
function publicContentAudit(audit) {
|
|
99
|
+
if (!audit) return undefined;
|
|
100
|
+
return { protocol:audit.protocol, state:audit.state, revision:audit.revision,
|
|
101
|
+
...(audit.location ? { location:audit.location } : {}), ...(modelAuditErrorMessage(audit) && {reason:audit.reason}) };
|
|
102
|
+
}
|
|
103
|
+
|
|
92
104
|
export function draftUploadView(record) {
|
|
93
105
|
const ready = record.state === 'draft_ready';
|
|
94
106
|
const sourceReady = record.source_ready === true;
|
|
95
107
|
const distReady = record.dist_ready === true || ready;
|
|
96
108
|
const projectUrl = ready && sourceReady && record.platform && /^[a-zA-Z0-9_-]{1,128}$/.test(record.conversation_id ?? '')
|
|
97
109
|
? new URL(`/chat/${record.conversation_id}`,record.platform).href : undefined;
|
|
110
|
+
const maskedFiles = Array.isArray(record.masked_files) && record.masked_files.length ? record.masked_files : undefined;
|
|
98
111
|
return { state:record.state, check_task_id:record.check_task_id ?? record.request_id, request_id:record.request_id,
|
|
99
112
|
upload_mode:record.upload_mode ?? record.prepare_input?.upload_mode, request_key:record.request_key,
|
|
100
113
|
version_number:record.version_number,
|
|
101
114
|
upload_id:record.upload_id, conversation_id:record.conversation_id, version_id:record.version_id,
|
|
102
115
|
dist_ready:distReady, source_ready:sourceReady, published:false,
|
|
103
116
|
...(record.audit ? { audit:record.audit } : {}),
|
|
104
|
-
...(record.content_audit ? { content_audit:record.content_audit, processing:processing(record) } : {}),
|
|
117
|
+
...(record.content_audit ? { content_audit:publicContentAudit(record.content_audit), processing:processing(record) } : {}),
|
|
118
|
+
...(maskedFiles ? { masked_files:maskedFiles } : {}),
|
|
105
119
|
...(projectUrl ? { project_url:projectUrl } : {}),
|
|
106
120
|
...(record.external_manifest_sha256 ? { external_manifest_sha256:record.external_manifest_sha256 } : {}),
|
|
107
121
|
next:projectUrl ? `Tell the user: uploaded ${record.version_number ? 'version v' + record.version_number : 'version ' + record.version_id}, project ${record.conversation_id}: ${projectUrl}. This is an upload, not a public release; preview and publish in Craft Web.` : ready
|
|
108
122
|
? 'This previous upload contains the build only. Run a new game check and upload the source and build to open it in Craft Web.'
|
|
109
123
|
: record.state === 'title_rejected' ? '项目标题未通过文本审核,请调整标题后重新检查并上传。'
|
|
110
|
-
: processing(record) ? '
|
|
111
|
-
: record.content_audit?.state === 'rejected'
|
|
112
|
-
|
|
124
|
+
: processing(record) ? '文件已上传,内容审核中。使用原 check_task_id、upload_mode 和 request_key 调用 craft_game_upload_status 查询。'
|
|
125
|
+
: record.content_audit?.state === 'rejected'
|
|
126
|
+
? (maskedFiles
|
|
127
|
+
? `包内文档(${maskedFiles.join('、')})触发内容审核,已自动将违禁词替换为 * 并写回本地文件。请告知用户检查修改结果,确认无误后重新运行 craft_game_check 并手动重新上传。`
|
|
128
|
+
: '包内内容未通过审核。如有 content_audit.location,可据此定位文件。请修改后重新检查并上传。')
|
|
129
|
+
: record.content_audit?.state === 'error' ? (modelAuditErrorMessage(record.content_audit) ?? '平台未能完成内容审核,本次上传已结束。')
|
|
113
130
|
: record.audit?.state === 'rejected' ? '服务端上传检查未通过。根据 audit.findings 修复文件,重新运行 craft_game_check 后上传。当前文件未生成预览。'
|
|
114
131
|
: terminal(record) ? 'Run a new game check and upload that result to start a new draft.'
|
|
115
132
|
: 'Run craft_game_upload with the same check_task_id, upload_mode and request_key to resume this upload.' };
|
|
@@ -118,6 +135,8 @@ export function draftUploadView(record) {
|
|
|
118
135
|
const COMMIT_BUSY_BACKEND_CODE = 10016;
|
|
119
136
|
const DEFAULT_COMMIT_RETRY_DELAYS_MS = [1000, 2000, 4000];
|
|
120
137
|
const DEFAULT_CHUNK_RETRY_DELAYS_MS = [500, 1500];
|
|
138
|
+
const DEFAULT_AUDIT_POLL_INTERVAL_MS = 2000;
|
|
139
|
+
const DEFAULT_AUDIT_POLL_TIMEOUT_MS = 90_000;
|
|
121
140
|
|
|
122
141
|
function* iterateByteChunks(parts, chunkSize) {
|
|
123
142
|
let index = 0;
|
|
@@ -163,6 +182,8 @@ export class DraftUploads {
|
|
|
163
182
|
this.bindings = bindings ?? new DraftBindings(path.join(path.dirname(store.directory),'draft-bindings'),store.workspace);
|
|
164
183
|
this.commitRetryDelays = options.commitRetryDelays ?? DEFAULT_COMMIT_RETRY_DELAYS_MS;
|
|
165
184
|
this.chunkRetryDelays = options.chunkRetryDelays ?? DEFAULT_CHUNK_RETRY_DELAYS_MS;
|
|
185
|
+
this.auditPollIntervalMs = options.auditPollIntervalMs ?? DEFAULT_AUDIT_POLL_INTERVAL_MS;
|
|
186
|
+
this.auditPollTimeoutMs = options.auditPollTimeoutMs ?? DEFAULT_AUDIT_POLL_TIMEOUT_MS;
|
|
166
187
|
this.onBound = options.onBound;
|
|
167
188
|
}
|
|
168
189
|
|
|
@@ -326,13 +347,81 @@ export class DraftUploads {
|
|
|
326
347
|
const record = await this.#pending(scope,binding);
|
|
327
348
|
if (record.request_id === id) return binding;
|
|
328
349
|
let recovered = await this.#recover(record,request,signal,statusOnly);
|
|
329
|
-
if (processing(recovered)) throw new Error(`Previous upload is awaiting
|
|
350
|
+
if (processing(recovered)) throw new Error(`Previous upload is awaiting content review. Query craft_game_upload_status with check_task_id=${record.check_task_id ?? record.request_id}, upload_mode=${record.upload_mode ?? 'current_project'}${record.request_key ? ', request_key=' + record.request_key : ''}.`);
|
|
330
351
|
recovered = await retireUnreviewedLegacyRecord(this.store,recovered,{ statusOnly,terminal,hasCurrentSecurityReview });
|
|
331
352
|
if (!terminal(recovered)) throw new Error(`Previous draft upload is unfinished; resume craft_game_upload with check_task_id=${record.check_task_id ?? record.request_id}, upload_mode=${record.upload_mode ?? 'current_project'}${record.request_key ? ', request_key=' + record.request_key : ''} before starting another upload`);
|
|
332
353
|
binding = await this.#finish(scope,binding,recovered);
|
|
333
354
|
}
|
|
334
355
|
}
|
|
335
356
|
|
|
357
|
+
async #waitForAudit(record, request, signal) {
|
|
358
|
+
if (!processing(record) || !record.upload_id) return record;
|
|
359
|
+
const deadline = Date.now() + this.auditPollTimeoutMs;
|
|
360
|
+
while (processing(record) && Date.now() < deadline) {
|
|
361
|
+
const waitMs = Math.min(this.auditPollIntervalMs, Math.max(0, deadline - Date.now()));
|
|
362
|
+
if (waitMs > 0) await delay(waitMs, undefined, { signal });
|
|
363
|
+
signal?.throwIfAborted();
|
|
364
|
+
await guardWork();
|
|
365
|
+
record = await this.#accept(record, await request('status', { id: record.upload_id }, signal));
|
|
366
|
+
}
|
|
367
|
+
return record;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
async #deliverUpload({ record, scope, binding, request, signal, chunkSize, archive, source, input, waitForAudit }) {
|
|
371
|
+
const run = async (kind, options) => {
|
|
372
|
+
signal.throwIfAborted();
|
|
373
|
+
await guardWork();
|
|
374
|
+
record = await this.#accept(record, await request(kind, options, signal));
|
|
375
|
+
};
|
|
376
|
+
signal?.throwIfAborted();
|
|
377
|
+
await guardWork();
|
|
378
|
+
record = await this.#prepare(record, request, signal);
|
|
379
|
+
if (record.text_audit_protocol && record.upload_id) {
|
|
380
|
+
binding.pending = record;
|
|
381
|
+
await this.bindings.save(scope, binding);
|
|
382
|
+
}
|
|
383
|
+
if (record.state === 'prepared' && !record.dist_ready) {
|
|
384
|
+
if (chunkSize && archive.bytes > chunkSize) {
|
|
385
|
+
record = await this.#uploadChunked(record, request, signal, { chunkKind: 'dist', parts: archive.parts, totalBytes: archive.bytes, chunkSize });
|
|
386
|
+
} else {
|
|
387
|
+
await run('upload', { id: record.upload_id, archive });
|
|
388
|
+
}
|
|
389
|
+
if (!record.dist_ready && !terminal(record)) throw new Error('Craft did not confirm the draft archive upload');
|
|
390
|
+
}
|
|
391
|
+
if (record.state === 'prepared' && !record.source_ready) {
|
|
392
|
+
if (chunkSize && source.length > chunkSize) {
|
|
393
|
+
record = await this.#uploadChunked(record, request, signal, { chunkKind: 'source', parts: [source], totalBytes: source.length, chunkSize });
|
|
394
|
+
} else {
|
|
395
|
+
await run('upload-source', { id: record.upload_id, source, sourceFormat: input.source.format });
|
|
396
|
+
}
|
|
397
|
+
if (!record.source_ready && !terminal(record)) throw new Error('Craft did not confirm the project source upload');
|
|
398
|
+
}
|
|
399
|
+
if (record.state === 'uploaded' && !terminal(record) && !processing(record)) record = await this.#commit(record, request, signal);
|
|
400
|
+
if (waitForAudit && processing(record)) record = await this.#waitForAudit(record, request, signal);
|
|
401
|
+
if (terminal(record) && binding.pending?.request_id === record.request_id) {
|
|
402
|
+
binding = await this.#finish(scope, binding, record);
|
|
403
|
+
}
|
|
404
|
+
return { record, binding };
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
async #applyAutoMask(record, options, signal) {
|
|
408
|
+
if (!options?.project || record?.content_audit?.state !== 'rejected' ||
|
|
409
|
+
!Array.isArray(record.content_audit.filtered_files) || !record.content_audit.filtered_files.length ||
|
|
410
|
+
record.masked_files) {
|
|
411
|
+
return record;
|
|
412
|
+
}
|
|
413
|
+
let appliedPaths;
|
|
414
|
+
try {
|
|
415
|
+
appliedPaths = await applyFilteredTextFiles(options.project, record.content_audit.filtered_files, signal);
|
|
416
|
+
} catch (error) {
|
|
417
|
+
if (error?.name === 'AbortError' || signal?.aborted) throw error;
|
|
418
|
+
return record;
|
|
419
|
+
}
|
|
420
|
+
const updated = { ...record, masked_files: appliedPaths };
|
|
421
|
+
await this.store.save(updated);
|
|
422
|
+
return updated;
|
|
423
|
+
}
|
|
424
|
+
|
|
336
425
|
async upload(check, owner, signal, options) {
|
|
337
426
|
const { name, task_id:checkId, result } = check;
|
|
338
427
|
const { id, upload_mode, request_key } = draftUploadIdentity(checkId,options);
|
|
@@ -357,13 +446,16 @@ export class DraftUploads {
|
|
|
357
446
|
if (record && terminal(record)) {
|
|
358
447
|
const binding = await this.#loadBinding(scope);
|
|
359
448
|
if (binding?.pending?.request_id === id) await this.#finish(scope,binding,record);
|
|
449
|
+
record = await this.#applyAutoMask(record,options,signal);
|
|
360
450
|
return draftUploadView(record);
|
|
361
451
|
}
|
|
362
452
|
if (record?.text_audit_protocol && record.upload_id) {
|
|
363
453
|
record = await this.#accept(record,await request('status',{id:record.upload_id},signal));
|
|
454
|
+
if (options?.project && processing(record)) record = await this.#waitForAudit(record,request,signal);
|
|
364
455
|
if (processing(record) || terminal(record)) {
|
|
365
456
|
const binding = await this.#loadBinding(scope);
|
|
366
457
|
if (binding.pending?.request_id === id && terminal(record)) await this.#finish(scope,binding,record);
|
|
458
|
+
record = await this.#applyAutoMask(record,options,signal);
|
|
367
459
|
return draftUploadView(record);
|
|
368
460
|
}
|
|
369
461
|
}
|
|
@@ -380,6 +472,7 @@ export class DraftUploads {
|
|
|
380
472
|
assertFrozenInputs(record,archive,result.source_snapshot);
|
|
381
473
|
if (record && terminal(record)) {
|
|
382
474
|
await this.#finish(scope,binding,record);
|
|
475
|
+
record = await this.#applyAutoMask(record,options,signal);
|
|
383
476
|
return draftUploadView(record);
|
|
384
477
|
}
|
|
385
478
|
const input = record ? prepareInput(record) : { client_request_id:id, engine:result.engine, title:name.slice(0,40),
|
|
@@ -412,38 +505,14 @@ export class DraftUploads {
|
|
|
412
505
|
await this.store.save(record);
|
|
413
506
|
binding.pending = record;
|
|
414
507
|
await this.bindings.save(scope,binding);
|
|
415
|
-
const run = async (kind, options) => {
|
|
416
|
-
signal.throwIfAborted();
|
|
417
|
-
await guardWork();
|
|
418
|
-
record = await this.#accept(record,await request(kind,options,signal));
|
|
419
|
-
};
|
|
420
508
|
// Reconcile each frozen artifact before sending it again after a lost response.
|
|
421
|
-
const
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
}
|
|
429
|
-
if (record.state === 'prepared' && !record.dist_ready) {
|
|
430
|
-
if (chunkSize && archive.bytes > chunkSize) {
|
|
431
|
-
record = await this.#uploadChunked(record,request,signal,{ chunkKind:'dist',parts:archive.parts,totalBytes:archive.bytes,chunkSize });
|
|
432
|
-
} else {
|
|
433
|
-
await run('upload',{ id:record.upload_id, archive });
|
|
434
|
-
}
|
|
435
|
-
if (!record.dist_ready && !terminal(record)) throw new Error('Craft did not confirm the draft archive upload');
|
|
436
|
-
}
|
|
437
|
-
if (record.state === 'prepared' && !record.source_ready) {
|
|
438
|
-
if (chunkSize && source.length > chunkSize) {
|
|
439
|
-
record = await this.#uploadChunked(record,request,signal,{ chunkKind:'source',parts:[source],totalBytes:source.length,chunkSize });
|
|
440
|
-
} else {
|
|
441
|
-
await run('upload-source',{ id:record.upload_id, source, sourceFormat:input.source.format });
|
|
442
|
-
}
|
|
443
|
-
if (!record.source_ready && !terminal(record)) throw new Error('Craft did not confirm the project source upload');
|
|
444
|
-
}
|
|
445
|
-
if (record.state === 'uploaded' && !terminal(record) && !processing(record)) record = await this.#commit(record,request,signal);
|
|
446
|
-
if (terminal(record)) await this.#finish(scope,binding,record);
|
|
509
|
+
const delivered = await this.#deliverUpload({
|
|
510
|
+
record, scope, binding, request, signal,
|
|
511
|
+
chunkSize: limits.chunk_size_bytes,
|
|
512
|
+
archive, source, input,
|
|
513
|
+
waitForAudit: Boolean(options?.project),
|
|
514
|
+
});
|
|
515
|
+
record = await this.#applyAutoMask(delivered.record,options,signal);
|
|
447
516
|
return draftUploadView(record);
|
|
448
517
|
}
|
|
449
518
|
|
|
@@ -216,7 +216,7 @@ export class ProjectBundles {
|
|
|
216
216
|
if (existing?.schema === 1) {
|
|
217
217
|
const legacy = await verifyBundle(source.legacyResources,engine,existing.bundle_id);
|
|
218
218
|
if (legacy.schema !== 1 || legacy.source_revision !== existing.source_revision) throw new Error('Legacy lock cannot select a host-specific context');
|
|
219
|
-
}
|
|
219
|
+
}
|
|
220
220
|
const plan=await planContextRelease(source.legacyResources,current.bundle,existing,project);
|
|
221
221
|
assertContextRelease(plan);
|
|
222
222
|
await guard();
|
|
@@ -189,7 +189,6 @@ export async function setupProject({ project, ide, packageRoot, install = false,
|
|
|
189
189
|
const bundle = await verifyBundle(path.join(packageRoot, 'resources/targets', ide, manifest.engine), manifest.engine);
|
|
190
190
|
if (bundle.host !== ide) throw new Error('Installer context belongs to another host');
|
|
191
191
|
await checkProjectCompatibility(project, bundle);
|
|
192
|
-
if (lock?.compatibility && !isDeepStrictEqual(lock.compatibility, bundle.compatibility)) throw new Error('Installer engine compatibility differs from the project binding');
|
|
193
192
|
if (lock?.contexts) {
|
|
194
193
|
const plan=await planContextRelease(path.join(packageRoot,'resources'),bundle,lock);
|
|
195
194
|
if (plan.conflicting_hosts.length) return { ...response, status: 'installer_update_required', conflicting_hosts:plan.conflicting_hosts,
|
|
@@ -150,7 +150,7 @@ const tools = [
|
|
|
150
150
|
...taskField,visual_passed:{ type:'boolean' },visual_notes:{ type:'string',minLength:10,maxLength:2000 },
|
|
151
151
|
},['task_id','visual_passed','visual_notes']),
|
|
152
152
|
tool('craft_game_upload','Upload the frozen source and dist as a private Craft version. The upload rechecks both snapshots for security. Report any findings and run a new check after fixing them. Local files become current; unsynced Web changes stay in history. Default: append to the bound project, or create on first upload. To update the original project, read the bound target and pass expected_appid. Only explicit requests select new_project. Poll craft_task_status; reuse the check ID, mode and request key for retries. Report vN, appid and project_url from draft_ready. Public review follows in Craft Web.',{...draftFields,expected_appid:{type:'string',pattern:'^[A-Za-z0-9_-]{1,128}$',description:'Require current_project to be bound to this appid; stop if unbound or different.'}},['name','check_task_id']),
|
|
153
|
-
tool('craft_game_upload_status','If an upload returns processing=true, poll with its original check_task_id, mode and request_key until
|
|
153
|
+
tool('craft_game_upload_status','If an upload returns processing=true, poll with its original check_task_id, mode and request_key until content review finishes. On rejection, report content_audit.location when available. Report the project link at draft_ready. With name only, inspect the upload target for the current account and platform.',draftFields,['name']),
|
|
154
154
|
tool('craft_preview_stop','Stop this project independent preview and cancel pending starts, including an earlier session preview.',nameField,['name']),
|
|
155
155
|
tool('craft_auth_open','Check login first. Return a login URL only when unauthenticated; an authenticated account continues without a login URL. Never read credentials or automate login.'),
|
|
156
156
|
tool('craft_auth_status','Check the Craft account without exposing credentials.'),
|
|
@@ -355,8 +355,8 @@ server.setRequestHandler(CallToolRequestSchema,async request=>{
|
|
|
355
355
|
if (!status.authenticated) { result = await loginAction(); break; }
|
|
356
356
|
// An already authorized upload resumes its frozen check, even after later source edits.
|
|
357
357
|
const resume = await drafts.hasRequest(args.name,args.check_task_id,status.user_id,args);
|
|
358
|
-
const { task } = await completedCheck(args.check_task_id,args.name,resume);
|
|
359
|
-
result = viewTask(await tasks.start(args.name,'upload',signal=>drafts.upload(task,status.user_id,signal,args),
|
|
358
|
+
const { task,project } = await completedCheck(args.check_task_id,args.name,resume);
|
|
359
|
+
result = viewTask(await tasks.start(args.name,'upload',signal=>drafts.upload(task,status.user_id,signal,{ ...args,project }),
|
|
360
360
|
{ owner:status.user_id, platform:platform.base, check_task_id:args.check_task_id,upload_mode:args.upload_mode ?? 'current_project',request_key:args.request_key }));
|
|
361
361
|
break;
|
|
362
362
|
}
|
|
@@ -206,7 +206,6 @@ export class UpdateSession {
|
|
|
206
206
|
const candidate=engines[project.engine];
|
|
207
207
|
await checkProjectCompatibility(project.project,candidate.bundle);
|
|
208
208
|
const lock=await readContextLock(project.project,project.engine);
|
|
209
|
-
if(lock?.schema>=2 && !isDeepStrictEqual(lock.compatibility,candidate.bundle.compatibility)) throw new Error('New Craft context is incompatible with this project; keep its engine and migrate explicitly');
|
|
210
209
|
if(lock?.contexts && candidate.host) assertContextRelease(await planContextRelease(candidate.legacyResources,candidate.bundle,lock));
|
|
211
210
|
} : undefined;
|
|
212
211
|
const result=await this.checkInstallation({installationFile:this.installationFile,current:this.current,connectedSource:this.connectedSource,intent,
|
|
@@ -35,6 +35,21 @@ const scanFailures = Object.freeze({
|
|
|
35
35
|
internal_error:'服务端安全检查发生内部故障,请联系平台维护者',
|
|
36
36
|
});
|
|
37
37
|
|
|
38
|
+
const modelAuditErrors = Object.freeze({
|
|
39
|
+
model_manifest_invalid:'请检查项目根目录 craft-audit-assets.json 的版本、字段和资产路径。',
|
|
40
|
+
model_rig_missing:'动作缺少可用的蒙皮底模。请在 craft-audit-assets.json 中关联对应的 FBX。',
|
|
41
|
+
model_rig_incompatible:'动作与关联底模的骨骼不匹配。请检查动作和蒙皮模型的绑定。',
|
|
42
|
+
model_unrenderable:'无法生成模型六视图。请检查模型格式、可见网格和内嵌贴图。',
|
|
43
|
+
animation_unrenderable:'无法生成该动作片段的有效预览。请检查蒙皮、关键帧和时长。',
|
|
44
|
+
animation_gif_invalid:'动画预览 GIF 无法通过格式检查。请提供可解码的多帧 GIF。',
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
export function modelAuditErrorMessage(audit) {
|
|
48
|
+
if (audit?.state === 'error' && typeof audit.reason === 'string' && Object.hasOwn(modelAuditErrors,audit.reason)) {
|
|
49
|
+
return modelAuditErrors[audit.reason];
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
38
53
|
function validAuditPath(value) {
|
|
39
54
|
return typeof value === 'string' && value.length > 0 && value.length <= 1024 &&
|
|
40
55
|
!/[\u0000-\u001f\u007f]/u.test(value) && !value.startsWith('/') && !/^[a-z]:/i.test(value) &&
|
|
@@ -42,16 +57,39 @@ function validAuditPath(value) {
|
|
|
42
57
|
}
|
|
43
58
|
|
|
44
59
|
export const textAuditProtocol = 'ace-text-v1';
|
|
60
|
+
const maxFilteredFiles = 64;
|
|
61
|
+
const maxFilteredBytes = 1024 * 1024;
|
|
62
|
+
|
|
63
|
+
function parseFilteredFiles(value, token) {
|
|
64
|
+
if (!Array.isArray(value) || value.length === 0 || value.length > maxFilteredFiles) return;
|
|
65
|
+
const out = [], seen = new Set();
|
|
66
|
+
let totalBytes = 0;
|
|
67
|
+
for (const item of value) {
|
|
68
|
+
if (!item || typeof item !== 'object' || Array.isArray(item)) return;
|
|
69
|
+
const { location, filtered_text } = item;
|
|
70
|
+
if (!validAuditPath(location) || !location.startsWith('source/') || /[?#]/.test(location) ||
|
|
71
|
+
!/\.(?:md|txt)$/i.test(location) || (token && location.includes(token)) || seen.has(location)) return;
|
|
72
|
+
if (typeof filtered_text !== 'string' || filtered_text.length === 0 || filtered_text.includes('\0') ||
|
|
73
|
+
(token && filtered_text.includes(token))) return;
|
|
74
|
+
totalBytes += Buffer.byteLength(location) + Buffer.byteLength(filtered_text);
|
|
75
|
+
if (totalBytes > maxFilteredBytes) return;
|
|
76
|
+
seen.add(location);
|
|
77
|
+
out.push({ location, filtered_text });
|
|
78
|
+
}
|
|
79
|
+
return out;
|
|
80
|
+
}
|
|
45
81
|
|
|
46
82
|
export function parseContentAudit(value, uploadState, token) {
|
|
47
83
|
if (value?.protocol !== 1 || !Number.isSafeInteger(value.revision) || value.revision < 0 ||
|
|
48
84
|
!['not_started','queued','auditing','retry_wait','passed','rejected','error'].includes(value.state) ||
|
|
49
85
|
((uploadState === 'draft_ready') !== (value.state === 'passed')) ||
|
|
50
86
|
(value.state !== 'not_started' && !['uploaded','draft_ready'].includes(uploadState))) {
|
|
51
|
-
throw new Error('Craft
|
|
87
|
+
throw new Error('Craft 返回的内容审核回执无效');
|
|
52
88
|
}
|
|
53
89
|
const location = validAuditPath(value.location) && !value.location.includes(token) ? value.location : undefined;
|
|
54
|
-
|
|
90
|
+
const filtered_files = value.state === 'rejected' ? parseFilteredFiles(value.filtered_files, token) : undefined;
|
|
91
|
+
return { protocol:1, state:value.state, revision:value.revision, ...(location && {location}),
|
|
92
|
+
...(modelAuditErrorMessage(value) && {reason:value.reason}), ...(filtered_files && {filtered_files}) };
|
|
55
93
|
}
|
|
56
94
|
|
|
57
95
|
export function parseDraftScanFailure(value) {
|
|
@@ -90,7 +90,7 @@ export async function fetchDraftUploadLimits(platform, owner, signal) {
|
|
|
90
90
|
throw platform.createError('Craft 返回的工程上传上限无效');
|
|
91
91
|
}
|
|
92
92
|
if (limits.text_audit_protocol !== undefined && limits.text_audit_protocol !== textAuditProtocol) {
|
|
93
|
-
throw platform.createError('Craft
|
|
93
|
+
throw platform.createError('Craft 返回了当前客户端无法识别的内容审核协议,请升级 Craft MCP');
|
|
94
94
|
}
|
|
95
95
|
if (limits.chunk_size_bytes !== undefined && (!Number.isSafeInteger(limits.chunk_size_bytes) || limits.chunk_size_bytes < 1)) {
|
|
96
96
|
throw platform.createError('Craft 返回的分片上传大小无效');
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@craft_eco/craft-mcp",
|
|
3
|
-
"version": "0.1.35-beta.
|
|
3
|
+
"version": "0.1.35-beta.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=22.12.0"
|
|
7
7
|
},
|
|
8
8
|
"craft": {
|
|
9
9
|
"platform": "https://craft.qq.com",
|
|
10
|
-
"source_sha256": "
|
|
10
|
+
"source_sha256": "5759f8b39af73b6f8d7edde721d214a74fe1fea66cbd98509115016f05b6e486"
|
|
11
11
|
},
|
|
12
12
|
"scripts": {
|
|
13
13
|
"start": "node bin/craft-mcp.mjs"
|
|
@@ -31,7 +31,6 @@
|
|
|
31
31
|
"type": "git",
|
|
32
32
|
"url": "https://git.woa.com/EcoGame/WXUP/WXUPAgent/CraftCli.git"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "2f603df2a409eb844403fd76ba4de4cc599a6edc",
|
|
35
34
|
"bin": {
|
|
36
35
|
"craft-mcp": "bin/craft-mcp.mjs"
|
|
37
36
|
},
|