@craft_eco/craft-mcp 0.1.34 → 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/README.md +2 -2
- package/bin/craft-mcp.mjs +11 -2
- package/dist-server/core/http-utils.mjs +11 -0
- package/dist-server/game-workflow/asset-formats.mjs +1 -1
- package/dist-server/game-workflow/bundle-files.mjs +19 -0
- package/dist-server/game-workflow/bundle-template.mjs +5 -0
- package/dist-server/game-workflow/context-state.mjs +1 -1
- package/dist-server/game-workflow/draft-archive.mjs +61 -0
- package/dist-server/game-workflow/draft-binding-migration.mjs +73 -0
- package/dist-server/game-workflow/draft-uploads.mjs +258 -75
- package/dist-server/game-workflow/native-context.mjs +4 -1
- package/dist-server/game-workflow/project-bundles.mjs +17 -6
- package/dist-server/game-workflow/projects.mjs +4 -0
- package/dist-server/game-workflow/template-refresh.mjs +430 -0
- package/dist-server/integrations/distribution-targets.mjs +2 -0
- package/dist-server/integrations/files.mjs +30 -2
- package/dist-server/integrations/fixed-launcher.mjs +4 -4
- package/dist-server/integrations/install.mjs +5 -5
- package/dist-server/integrations/installation-state.mjs +6 -7
- package/dist-server/integrations/launcher-start.mjs +12 -8
- package/dist-server/integrations/opencode-config.mjs +1 -1
- package/dist-server/integrations/project-setup.mjs +0 -1
- package/dist-server/integrations/runtime-candidate.mjs +8 -12
- package/dist-server/integrations/runtime-gc.mjs +20 -21
- package/dist-server/integrations/runtime.mjs +7 -3
- package/dist-server/integrations/updates.mjs +64 -27
- package/dist-server/launcher.mjs +39 -14
- package/dist-server/mcp/login-page.mjs +2 -2
- package/dist-server/mcp/server.mjs +10 -12
- package/dist-server/mcp/update-session.mjs +3 -3
- package/dist-server/upstream/{craft-aigc.mjs → craft-platform.mjs} +40 -115
- package/dist-server/upstream/draft-audit.mjs +51 -0
- package/dist-server/upstream/draft-transport.mjs +184 -0
- package/package.json +3 -3
- package/resources/craft-update/SKILL.md +2 -0
- package/resources/targets/claude/js/js/bundle.json +15 -9
- package/resources/targets/claude/js/target.json +8 -6
- package/resources/targets/claude/js3d/js3d/bundle.json +21 -10
- package/resources/targets/claude/js3d/target.json +14 -7
- package/resources/targets/codebuddy/js/js/bundle.json +15 -9
- package/resources/targets/codebuddy/js/target.json +8 -6
- package/resources/targets/codebuddy/js3d/js3d/bundle.json +21 -10
- package/resources/targets/codebuddy/js3d/target.json +14 -7
- package/resources/targets/codex/js/js/bundle.json +15 -9
- package/resources/targets/codex/js/target.json +8 -6
- package/resources/targets/codex/js3d/js3d/bundle.json +21 -10
- package/resources/targets/codex/js3d/target.json +14 -7
- package/resources/targets/comate/js/js/bundle.json +15 -9
- package/resources/targets/comate/js/target.json +8 -6
- package/resources/targets/comate/js3d/js3d/bundle.json +21 -10
- package/resources/targets/comate/js3d/target.json +14 -7
- package/resources/targets/cursor/js/js/bundle.json +15 -9
- package/resources/targets/cursor/js/target.json +8 -6
- package/resources/targets/cursor/js3d/js3d/bundle.json +21 -10
- package/resources/targets/cursor/js3d/target.json +14 -7
- package/resources/targets/dsh/js/js/bundle.json +15 -9
- package/resources/targets/dsh/js/target.json +8 -6
- package/resources/targets/dsh/js3d/js3d/bundle.json +21 -10
- package/resources/targets/dsh/js3d/target.json +14 -7
- package/resources/targets/index.json +56 -56
- package/resources/targets/kimi/js/js/bundle.json +15 -9
- package/resources/targets/kimi/js/target.json +8 -6
- package/resources/targets/kimi/js3d/js3d/bundle.json +21 -10
- package/resources/targets/kimi/js3d/target.json +14 -7
- package/resources/targets/opencode/js/js/bundle.json +15 -9
- package/resources/targets/opencode/js/target.json +8 -6
- package/resources/targets/opencode/js3d/js3d/bundle.json +21 -10
- package/resources/targets/opencode/js3d/target.json +14 -7
- package/resources/targets/qoder/js/js/bundle.json +15 -9
- package/resources/targets/qoder/js/target.json +8 -6
- package/resources/targets/qoder/js3d/js3d/bundle.json +21 -10
- package/resources/targets/qoder/js3d/target.json +14 -7
- package/resources/targets/qoder-cn/js/js/bundle.json +15 -9
- package/resources/targets/qoder-cn/js/target.json +8 -6
- package/resources/targets/qoder-cn/js3d/js3d/bundle.json +21 -10
- package/resources/targets/qoder-cn/js3d/target.json +14 -7
- package/resources/targets/qwen/js/js/bundle.json +15 -9
- package/resources/targets/qwen/js/target.json +8 -6
- package/resources/targets/qwen/js3d/js3d/bundle.json +21 -10
- package/resources/targets/qwen/js3d/target.json +14 -7
- package/resources/targets/trae/js/js/bundle.json +15 -9
- package/resources/targets/trae/js/target.json +8 -6
- package/resources/targets/trae/js3d/js3d/bundle.json +21 -10
- package/resources/targets/trae/js3d/target.json +14 -7
- package/resources/targets/workbuddy/js/js/bundle.json +15 -9
- package/resources/targets/workbuddy/js/target.json +8 -6
- package/resources/targets/workbuddy/js3d/js3d/bundle.json +21 -10
- package/resources/targets/workbuddy/js3d/target.json +14 -7
- package/resources/targets/zcode/js/js/bundle.json +15 -9
- package/resources/targets/zcode/js/target.json +8 -6
- package/resources/targets/zcode/js3d/js3d/bundle.json +21 -10
- package/resources/targets/zcode/js3d/target.json +14 -7
- package/resources/templates/js/materialize_paths.json +9 -0
- package/resources/templates/js/project/package.json +1 -0
- package/resources/templates/js/project/runtime/lightgame/1.1.0/platform/platform-capture-dom.mjs +176 -0
- package/resources/templates/js/project/runtime/lightgame/1.1.0/platform/platform.d.mts +5 -1
- package/resources/templates/js/project/runtime/lightgame/1.1.0/platform/platform.mjs +87 -3
- package/resources/templates/js/project/runtime/lightgame/1.1.0/release.json +3 -2
- package/resources/templates/js/project/scripts/refresh-runtime.mjs +50 -0
- package/resources/templates/js3d/materialize_paths.json +9 -0
- package/resources/templates/js3d/project/package.json +4 -2
- package/resources/templates/js3d/project/runtime/lightgame/1.1.0/platform/platform-capture-dom.mjs +176 -0
- package/resources/templates/js3d/project/runtime/lightgame/1.1.0/platform/platform.d.mts +5 -1
- package/resources/templates/js3d/project/runtime/lightgame/1.1.0/platform/platform.mjs +87 -3
- package/resources/templates/js3d/project/runtime/lightgame/1.1.0/release.json +3 -2
- package/resources/templates/js3d/project/scripts/refresh-runtime.mjs +50 -0
- package/resources/templates/js3d/project/scripts/skill-modules/gameplay-check/check.mjs +331 -0
- package/resources/templates/js3d/project/src/game/capability/core.ts +3 -0
- package/resources/templates/js3d/project/src/main.ts +23 -6
- package/resources/templates/js3d/project/src/skill-modules/gameplay/core/index.d.mts +92 -0
- package/resources/templates/js3d/project/src/skill-modules/gameplay/core/index.mjs +375 -0
- package/resources/templates/js3d/project/src/skill-modules/gameplay/installed.json +6 -0
- package/dist-server/game-workflow/local-context.mjs +0 -64
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ Craft MCP 是面向支持本地 stdio MCP 的 AI IDE 的游戏制作服务,例
|
|
|
10
10
|
|
|
11
11
|
选择当前宿主;只有同时接入时才用逗号列出多个宿主。安装完整 MCP 程序包、固定启动入口及全局 craft-create、craft-update Skill,保留已有平台和工作区。
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
使用下面的正式渠道命令,把 --ide 后的宿主名替换为当前宿主。用户明确指定版本号时,安装命令沿用该版本号。
|
|
14
14
|
|
|
15
15
|
已安装的实例启动失败时,保留原包和源,先执行 doctor --ide <当前宿主> --instance <原服务名>。确认运行目录损坏后,执行 install --repair --ide <当前宿主> --instance <原服务名> 恢复原构建,重连后用 craft_game_info 核对。
|
|
16
16
|
|
|
@@ -21,7 +21,7 @@ npx --yes --registry=https://registry.npmjs.org/ @craft_eco/craft-mcp@stable ins
|
|
|
21
21
|
|
|
22
22
|
其他宿主将 --ide 改为 cursor、codebuddy、claude、dsh、zcode、kimi、trae、qoder-cn、qoder、comate、opencode 或 qwen。TRAE 与国际版 Qoder IDE 还须 --host-config <宿主设置中打开的 MCP 配置绝对路径>;TRAE CN 加 --trae-region cn,国际版默认 global。这两个选项也适用于 doctor/check/update/connect/project-setup,可由 CRAFT_HOST_CONFIG、CRAFT_TRAE_REGION 环境变量提供。kimi 指当前 Kimi Code CLI,不写旧 Python Kimi CLI 的 ~/.kimi。可用 --workspace <绝对游戏父目录> 和 --platform <HTTPS origin> 指定目录与平台;未提供时保留现有配置,新安装默认 ~/CraftGames 和本包平台。安装不创建游戏、不修改信任权限。
|
|
23
23
|
|
|
24
|
-
Codex 配置 ~/.codex/config.toml(设置 CODEX_HOME 时使用其 config.toml),全局 Skill 在 ~/.agents/skills;WorkBuddy 配置 ~/.workbuddy/mcp.json,全局 Skill 在 ~/.workbuddy/skills。CodeBuddy 使用 ~/.codebuddy/.mcp.json 与 ~/.codebuddy/skills,已有旧 MCP
|
|
24
|
+
Codex 配置 ~/.codex/config.toml(设置 CODEX_HOME 时使用其 config.toml),全局 Skill 在 ~/.agents/skills;WorkBuddy 配置 ~/.workbuddy/mcp.json,全局 Skill 在 ~/.workbuddy/skills。CodeBuddy 使用 ~/.codebuddy/.mcp.json 与 ~/.codebuddy/skills,已有旧 MCP 配置按官方优先级沿用。安装或更新后,在下次启动或重连时调用当前聊天的 craft_game_info,核对 update.source.channel、运行版本、build_id 和 active_verified。doctor --ide <当前宿主> 仅验证独立探测和文件,不证明当前聊天已切版或发现 Skill。
|
|
25
25
|
|
|
26
26
|
Claude Code 使用 ~/.claude.json 与 ~/.claude/skills;DSH 使用 ~/.dsh/cordis.patch.yml 与 ~/.dsh/skills;ZCode 使用 ~/.zcode/cli/config.json 的 mcp.servers 和 ~/.zcode/skills;Kimi Code CLI 使用 ~/.kimi-code/mcp.json 与 ~/.kimi-code/skills。DSH 配置是 YAML 插件 patch,ZCode 不是 mcpServers。对应目录覆盖通过 CLAUDE_CONFIG_DIR、DSH_HOME、KIMI_CODE_HOME 指定。不要把不同宿主的配置格式互换。
|
|
27
27
|
|
package/bin/craft-mcp.mjs
CHANGED
|
@@ -18,9 +18,17 @@ if (args.length === 0 || (args.length === 2 && args[0] === '--workspace' && path
|
|
|
18
18
|
if (process.env.npm_command === 'exec' && process.env.npm_lifecycle_event === 'npx') {
|
|
19
19
|
const { npmInstallSelector } = await import('../dist-server/integrations/install-source.mjs');
|
|
20
20
|
const { serverIdForChannel } = await import('../dist-server/integrations/instance.mjs');
|
|
21
|
+
const { distributionTargets, publicReleaseTags } = await import('../dist-server/integrations/distribution-targets.mjs');
|
|
21
22
|
const pkg = JSON.parse(await readFile(new URL('../package.json', import.meta.url), 'utf8'));
|
|
22
23
|
const selector = await npmInstallSelector(fileURLToPath(new URL('..', import.meta.url)), pkg.name);
|
|
23
|
-
|
|
24
|
+
const publicPackage = pkg.name === distributionTargets.public.package;
|
|
25
|
+
if (publicPackage && selector?.tag === 'latest') {
|
|
26
|
+
guide = '此安装请求使用正式版的历史别名。请按下文的 @stable 命令安装正式版。\n\n' + guide;
|
|
27
|
+
} else if (publicPackage && selector?.kind === 'tag' && !publicReleaseTags.includes(selector.tag)) {
|
|
28
|
+
process.stderr.write('Craft guide: @' + selector.tag + ' 不能作为新的公开安装入口。请向维护者确认该渠道的安装来源。\n');
|
|
29
|
+
process.exitCode = 1;
|
|
30
|
+
guide = '';
|
|
31
|
+
} else if (selector?.kind === 'tag' && !['stable', 'latest'].includes(selector.tag)) {
|
|
24
32
|
const tag = selector.tag;
|
|
25
33
|
const server = serverIdForChannel(tag);
|
|
26
34
|
guide = [
|
|
@@ -35,7 +43,8 @@ if (args.length === 0 || (args.length === 2 && args[0] === '--workspace' && path
|
|
|
35
43
|
'启动失败时先运行 doctor。确认运行文件损坏后,用 install --repair --ide <当前宿主> --instance ' + server + ' 恢复该实例记录的构建。', '',
|
|
36
44
|
].join('\n');
|
|
37
45
|
} else if (selector?.kind === 'package') {
|
|
38
|
-
|
|
46
|
+
const readmeTag = publicPackage ? 'stable' : (pkg.publishConfig?.tag ?? 'stable');
|
|
47
|
+
guide = guide.replaceAll(pkg.name + '@' + readmeTag + ' ', pkg.name + '@' + pkg.version + ' ');
|
|
39
48
|
}
|
|
40
49
|
}
|
|
41
50
|
process.stdout.write(guide);
|
|
@@ -12,3 +12,14 @@ export async function parseJsonBody(req, maxBytes) {
|
|
|
12
12
|
}
|
|
13
13
|
return JSON.parse(body || '{}');
|
|
14
14
|
}
|
|
15
|
+
export async function boundedBody(response, limit) {
|
|
16
|
+
const tooLarge = () => Object.assign(new Error('Response exceeds size limit'),{ code:'CRAFT_RESPONSE_TOO_LARGE' });
|
|
17
|
+
if (Number(response.headers.get('content-length')) > limit) { await response.body?.cancel(); throw tooLarge(); }
|
|
18
|
+
const parts = []; let size = 0;
|
|
19
|
+
for await (const part of response.body ?? []) {
|
|
20
|
+
size += part.length;
|
|
21
|
+
if (size > limit) throw tooLarge();
|
|
22
|
+
parts.push(Buffer.from(part));
|
|
23
|
+
}
|
|
24
|
+
return Buffer.concat(parts);
|
|
25
|
+
}
|
|
@@ -4,6 +4,7 @@ import { createHash } from 'node:crypto';
|
|
|
4
4
|
import { hosts } from '../integrations/hosts.mjs';
|
|
5
5
|
import { resolveBundleTemplate } from './bundle-template.mjs';
|
|
6
6
|
import { bundleArtPreviewDirectory, collectArtPreviews, readArtPreview } from './art-previews.mjs';
|
|
7
|
+
import { isProjectRefreshPath, normalizeProjectRefreshPaths, readTemplateRefreshPaths } from './template-refresh.mjs';
|
|
7
8
|
|
|
8
9
|
export const bundleContracts = Object.freeze({ export:1, skills:1, mcp:1, sdk_lifecycle:1 });
|
|
9
10
|
export const digest = value => createHash('sha256').update(value).digest('hex');
|
|
@@ -51,6 +52,12 @@ export async function readBundleManifest(root, engine, expectedId) {
|
|
|
51
52
|
if (manifest.schema === 2) {
|
|
52
53
|
const target = JSON.parse(await readFile(path.join(root,'target.json'),'utf8'));
|
|
53
54
|
if (!Object.hasOwn(hosts,manifest.host) || target.host !== manifest.host || target.engine !== engine || target.version !== manifest.version) throw new Error('Context target identity mismatch');
|
|
55
|
+
if (manifest.template_refresh_paths !== undefined) {
|
|
56
|
+
const normalized = normalizeProjectRefreshPaths(manifest.template_refresh_paths);
|
|
57
|
+
if (!normalized.length || JSON.stringify(normalized) !== JSON.stringify(manifest.template_refresh_paths)) {
|
|
58
|
+
throw new Error('Invalid template refresh paths in bundle manifest');
|
|
59
|
+
}
|
|
60
|
+
}
|
|
54
61
|
}
|
|
55
62
|
return manifest;
|
|
56
63
|
}
|
|
@@ -63,6 +70,18 @@ export async function verifyBundle(root, engine, expectedId, {contextOnly = fals
|
|
|
63
70
|
const ordered = [...previews].sort();
|
|
64
71
|
if (JSON.stringify(manifest.art_previews ?? []) !== JSON.stringify(ordered)) throw new Error('Context bundle art preview bindings differ: '+engine);
|
|
65
72
|
for (const name of ordered) await readArtPreview(bundleArtPreviewDirectory(root,engine,manifest.host,template),name);
|
|
73
|
+
if (!contextOnly && manifest.schema === 2) {
|
|
74
|
+
const expectedRefresh = await readTemplateRefreshPaths(template,engine);
|
|
75
|
+
if (JSON.stringify(manifest.template_refresh_paths ?? []) !== JSON.stringify(expectedRefresh)) {
|
|
76
|
+
throw new Error('Context bundle template refresh paths differ: '+engine);
|
|
77
|
+
}
|
|
78
|
+
const projectPrefix = engine+'/project/';
|
|
79
|
+
for (const entry of expectedRefresh) {
|
|
80
|
+
if (!Object.keys(actual).some(name => name.startsWith(projectPrefix) && isProjectRefreshPath(name.slice(projectPrefix.length),[entry]))) {
|
|
81
|
+
throw new Error('Context bundle template refresh path missing from template: '+entry);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
66
85
|
const expected = contextOnly ? Object.fromEntries(Object.entries(manifest.files).filter(([name])=>!name.startsWith(engine+'/project/'))) : manifest.files;
|
|
67
86
|
if (JSON.stringify(actual) !== JSON.stringify(expected)) throw new Error('Context bundle integrity check failed: ' + engine);
|
|
68
87
|
return manifest;
|
|
@@ -8,6 +8,11 @@ export function sharedTemplatePath(engine) {
|
|
|
8
8
|
return `templates/${engine}/project`;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
export function sharedTemplateMaterializePath(engine) {
|
|
12
|
+
if (!['js', 'js3d'].includes(engine)) throw new Error('Unsupported bundle engine');
|
|
13
|
+
return `templates/${engine}/materialize_paths.json`;
|
|
14
|
+
}
|
|
15
|
+
|
|
11
16
|
export function assertSharedTemplateIndex(index) {
|
|
12
17
|
if (index?.schema !== 1) throw new Error('Invalid shared template layout index');
|
|
13
18
|
}
|
|
@@ -7,7 +7,7 @@ import { entryPolicyVersion, projectEntryPolicy, validateProjectRecoveryEntries
|
|
|
7
7
|
import { projectInstallFile, readProjectInstall } from './project-install.mjs';
|
|
8
8
|
|
|
9
9
|
const readyFile='.craft/context-ready.json';
|
|
10
|
-
|
|
10
|
+
const preparingFile='.craft/context-preparing.json';
|
|
11
11
|
const hash=value=>createHash('sha256').update(value).digest('hex');
|
|
12
12
|
async function optional(project,file) {
|
|
13
13
|
try {return JSON.parse(await readFile(await safeProjectFile(project,file),'utf8'));}
|
|
@@ -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
|
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export async function listLegacyUploadHistory(store, scope) {
|
|
2
|
+
const history = (await store.list()).filter(record =>
|
|
3
|
+
Object.entries(scope).every(([key, value]) => record[key] === value) && !['expired', 'superseded'].includes(record.state));
|
|
4
|
+
if (history.some(record => !Number.isFinite(Date.parse(record.created_at)))) {
|
|
5
|
+
throw new Error('Invalid draft upload history timestamp');
|
|
6
|
+
}
|
|
7
|
+
history.sort((a, b) => Date.parse(b.created_at) - Date.parse(a.created_at));
|
|
8
|
+
if (history.some((record, index) => index && Date.parse(record.created_at) === Date.parse(history[index - 1].created_at))) {
|
|
9
|
+
throw new Error('Ambiguous draft upload history; cannot choose the original project');
|
|
10
|
+
}
|
|
11
|
+
return history;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export async function loadOrMigrateBinding(bindings, store, scope) {
|
|
15
|
+
const binding = await bindings.read(scope);
|
|
16
|
+
if (binding) return binding;
|
|
17
|
+
// Persist the migration queue as well: a crash or profile switch must not lose older receipts.
|
|
18
|
+
return bindings.save(scope, { schema: 1, ...scope, migration: await listLegacyUploadHistory(store, scope) });
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export async function resolveDraftTarget({ binding, store, scope, platform, owner, signal, terminal, mergeReceipt }) {
|
|
22
|
+
const history = binding ? binding.migration ?? [] : await listLegacyUploadHistory(store, scope);
|
|
23
|
+
let head = binding;
|
|
24
|
+
for (let record of binding?.pending ? [binding.pending, ...history] : history) {
|
|
25
|
+
if (Object.entries(scope).some(([key, value]) => record[key] !== value)) {
|
|
26
|
+
throw new Error('Invalid draft binding history scope');
|
|
27
|
+
}
|
|
28
|
+
// Refresh build-only and text-review receipts to resolve the target without submitting the upload.
|
|
29
|
+
if (!terminal(record) && record.upload_id && (!record.prepare_input?.source || record.text_audit_protocol || record.content_audit)) {
|
|
30
|
+
signal?.throwIfAborted();
|
|
31
|
+
record = mergeReceipt(record, await platform.draftSession(owner)('status', { id: record.upload_id }, signal));
|
|
32
|
+
}
|
|
33
|
+
if (record.state === 'draft_ready') { head = record; break; }
|
|
34
|
+
if (!terminal(record)) {
|
|
35
|
+
return {
|
|
36
|
+
state: 'recovery_required',
|
|
37
|
+
appid: binding?.conversation_id,
|
|
38
|
+
check_task_id: record.check_task_id ?? record.request_id,
|
|
39
|
+
upload_mode: record.upload_mode ?? 'current_project',
|
|
40
|
+
request_key: record.request_key,
|
|
41
|
+
...(record.content_audit && {content_audit:record.content_audit}),
|
|
42
|
+
next: 'Check the existing upload receipt and recover it before starting another upload.',
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return head?.conversation_id
|
|
47
|
+
? { state: 'bound', appid: head.conversation_id, conversation_id: head.conversation_id, version_id: head.version_id }
|
|
48
|
+
: { state: 'unbound', next: 'An initial upload can create a cloud project. To update an existing appid, locate its bound local project first.' };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export async function advanceLegacyMigration(bindings, store, scope, binding, prepareInput) {
|
|
52
|
+
if (!binding.pending && binding.migration?.length) {
|
|
53
|
+
const record = binding.migration.shift();
|
|
54
|
+
record.prepare_input = prepareInput(record);
|
|
55
|
+
await store.save(record);
|
|
56
|
+
binding.pending = record;
|
|
57
|
+
await bindings.save(scope, binding);
|
|
58
|
+
}
|
|
59
|
+
if (!binding.pending && binding.migration) {
|
|
60
|
+
delete binding.migration;
|
|
61
|
+
await bindings.save(scope, binding);
|
|
62
|
+
}
|
|
63
|
+
return binding;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export async function retireUnreviewedLegacyRecord(store, record, { statusOnly, terminal, hasCurrentSecurityReview }) {
|
|
67
|
+
if (!statusOnly && !terminal(record) && !hasCurrentSecurityReview(record)) {
|
|
68
|
+
const superseded = { ...record, state: 'superseded' };
|
|
69
|
+
await store.save(superseded);
|
|
70
|
+
return superseded;
|
|
71
|
+
}
|
|
72
|
+
return record;
|
|
73
|
+
}
|