@craft_eco/craft-mcp 0.1.34-beta.3 → 0.1.34
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 +5 -3
- package/bin/craft-mcp.mjs +3 -1
- package/dist-server/core/upload-limits.mjs +11 -0
- package/dist-server/game-workflow/art-previews.mjs +71 -71
- package/dist-server/game-workflow/bundle-files.mjs +6 -1
- package/dist-server/game-workflow/engines.mjs +18 -9
- package/dist-server/game-workflow/local-context.mjs +64 -64
- package/dist-server/game-workflow/project-art-previews.mjs +63 -63
- package/dist-server/game-workflow/project-context.mjs +4 -1
- package/dist-server/game-workflow/project-install.mjs +15 -7
- package/dist-server/game-workflow/projects.mjs +13 -3
- package/dist-server/integrations/distribution-targets.mjs +9 -0
- package/dist-server/integrations/install.mjs +49 -11
- package/dist-server/integrations/instance-skill.mjs +26 -26
- package/dist-server/integrations/instance.mjs +29 -29
- package/dist-server/integrations/launcher-start.mjs +5 -5
- package/dist-server/integrations/project-setup.mjs +2 -0
- package/dist-server/integrations/runtime-candidate.mjs +32 -6
- package/dist-server/integrations/runtime-file-diagnostics.mjs +68 -0
- package/dist-server/integrations/runtime-gc.mjs +8 -2
- package/dist-server/integrations/runtime-identity.mjs +56 -8
- package/dist-server/integrations/runtime.mjs +5 -2
- package/dist-server/integrations/uninstall.mjs +160 -160
- package/dist-server/integrations/updates.mjs +17 -20
- package/dist-server/launcher.mjs +47 -8
- package/dist-server/mcp/production-events.mjs +52 -29
- package/dist-server/mcp/server.mjs +5 -4
- package/dist-server/preview/preview-snapshot.mjs +3 -2
- package/package.json +5 -5
- package/resources/context-filter-report.json +1 -1
- package/resources/craft-create/SKILL.md +25 -25
- package/resources/craft-update/SKILL.md +27 -27
- package/resources/targets/claude/js/context-filter-report.json +1 -1
- package/resources/targets/claude/js3d/context-filter-report.json +1 -1
- package/resources/targets/codebuddy/js/context-filter-report.json +1 -1
- package/resources/targets/codebuddy/js3d/context-filter-report.json +1 -1
- package/resources/targets/codex/js/context-filter-report.json +1 -1
- package/resources/targets/codex/js3d/context-filter-report.json +1 -1
- package/resources/targets/comate/js/context-filter-report.json +1 -1
- package/resources/targets/comate/js3d/context-filter-report.json +1 -1
- package/resources/targets/cursor/js/context-filter-report.json +1 -1
- package/resources/targets/cursor/js3d/context-filter-report.json +1 -1
- package/resources/targets/dsh/js/context-filter-report.json +1 -1
- package/resources/targets/dsh/js3d/context-filter-report.json +1 -1
- package/resources/targets/kimi/js/context-filter-report.json +1 -1
- package/resources/targets/kimi/js3d/context-filter-report.json +1 -1
- package/resources/targets/opencode/js/context-filter-report.json +1 -1
- package/resources/targets/opencode/js3d/context-filter-report.json +1 -1
- package/resources/targets/qoder/js/context-filter-report.json +1 -1
- package/resources/targets/qoder/js3d/context-filter-report.json +1 -1
- package/resources/targets/qoder-cn/js/context-filter-report.json +1 -1
- package/resources/targets/qoder-cn/js3d/context-filter-report.json +1 -1
- package/resources/targets/qwen/js/context-filter-report.json +1 -1
- package/resources/targets/qwen/js3d/context-filter-report.json +1 -1
- package/resources/targets/trae/js/context-filter-report.json +1 -1
- package/resources/targets/trae/js3d/context-filter-report.json +1 -1
- package/resources/targets/workbuddy/js/context-filter-report.json +1 -1
- package/resources/targets/workbuddy/js3d/context-filter-report.json +1 -1
- package/resources/targets/zcode/js/context-filter-report.json +1 -1
- package/resources/targets/zcode/js3d/context-filter-report.json +1 -1
- package/vendor/craft-runtime/NOTICE.md +1 -1
- package/vendor/craft-runtime/SOURCE.json +10 -6
- package/vendor/craft-runtime/index.js +228 -164
- package/vendor/craft-runtime/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,10 +10,12 @@ Craft MCP 是面向支持本地 stdio MCP 的 AI IDE 的游戏制作服务,例
|
|
|
10
10
|
|
|
11
11
|
选择当前宿主;只有同时接入时才用逗号列出多个宿主。安装完整 MCP 程序包、固定启动入口及全局 craft-create、craft-update Skill,保留已有平台和工作区。
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
保留本次 guide 命令中的源和包选择器,将 guide 换为 install --ide <当前宿主>。用户明确指定测试渠道时传同名 --channel,安装器会为它创建独立的命名服务、工作区和 Skill。同一渠道再次安装会复用自己的实例。明确指定版本时保留版本号。
|
|
14
|
+
|
|
15
|
+
已安装的实例启动失败时,保留原包和源,先执行 doctor --ide <当前宿主> --instance <原服务名>。确认运行目录损坏后,执行 install --repair --ide <当前宿主> --instance <原服务名> 恢复原构建,重连后用 craft_game_info 核对。
|
|
14
16
|
|
|
15
17
|
```sh
|
|
16
|
-
#
|
|
18
|
+
# 在 Codex 中安装
|
|
17
19
|
npx --yes --registry=https://registry.npmjs.org/ @craft_eco/craft-mcp@stable install --ide codex
|
|
18
20
|
```
|
|
19
21
|
|
|
@@ -49,6 +51,6 @@ npx --yes --registry=https://registry.npmjs.org/ @craft_eco/craft-mcp@stable gui
|
|
|
49
51
|
|
|
50
52
|
使用 craft_game_upload 上传同次检查冻结的源码与 dist。安全检查失败时告知用户原因并停止上传。安全检查通过后,玩法和画面问题作为报告反馈。draft_ready 后把 project_url 交给用户,在 Craft 网页完成发布。
|
|
51
53
|
|
|
52
|
-
当前业务平台是 https://
|
|
54
|
+
当前业务平台是 https://craft.qq.com。游戏上传和提审需要匹配的 Web 服务与审核配置。
|
|
53
55
|
|
|
54
56
|
发布图片上传后可公开访问,游戏审核通过后可能公开。平台审核覆盖提交的文案与图片,不会扫描或执行整个游戏压缩包。
|
package/bin/craft-mcp.mjs
CHANGED
|
@@ -31,7 +31,8 @@ if (args.length === 0 || (args.length === 2 && args[0] === '--workspace' && path
|
|
|
31
31
|
',在当前聊天用它的 craft_game_info 核对 server_id、channel、version、build_id、workspace 和 active_verified。',
|
|
32
32
|
'TRAE 和国际版 Qoder IDE 需追加 --host-config <从该宿主设置中打开的配置绝对路径>。TRAE 国内版另加 --trae-region cn。',
|
|
33
33
|
'新安装默认游戏目录为 ~/CraftTestGames/' + server + ',平台为 ' + pkg.craft.platform + '。安装器会保留该实例已有的平台和工作区。',
|
|
34
|
-
'在 CLI 中检查、更新、诊断或卸载时传 --ide <当前宿主> --instance ' + server + '。',
|
|
34
|
+
'在 CLI 中检查、更新、诊断或卸载时传 --ide <当前宿主> --instance ' + server + '。',
|
|
35
|
+
'启动失败时先运行 doctor。确认运行文件损坏后,用 install --repair --ide <当前宿主> --instance ' + server + ' 恢复该实例记录的构建。', '',
|
|
35
36
|
].join('\n');
|
|
36
37
|
} else if (selector?.kind === 'package') {
|
|
37
38
|
guide = guide.replaceAll(pkg.name + '@stable ', pkg.name + '@' + pkg.version + ' ');
|
|
@@ -61,6 +62,7 @@ if (args.length === 0 || (args.length === 2 && args[0] === '--workspace' && path
|
|
|
61
62
|
try { const { runUpdateCommand } = await import('../dist-server/integrations/updates.mjs'); await runUpdateCommand(args); }
|
|
62
63
|
catch (error) { process.stderr.write('Craft ' + args[0] + ' failed: ' + error.message + '\n'); process.exitCode = 1; }
|
|
63
64
|
} else if (args.length === 1 && ['--help', '-h', 'help'].includes(args[0])) {
|
|
65
|
+
process.stdout.write('Repair a managed runtime from its recorded build: craft-mcp install --repair --ide <host> [--instance <server>]\n');
|
|
64
66
|
process.stdout.write('Windows local login: craft-mcp login-task --setup|--remove --ide workbuddy [--host-config <absolute MCP config file>]\n');
|
|
65
67
|
process.stdout.write('Windows game preview: craft-mcp preview-task --setup|--remove --ide workbuddy [--host-config <absolute MCP config file>]\n');
|
|
66
68
|
process.stdout.write('Usage: craft-mcp [--workspace <absolute games directory>|guide|--help]\n craft-mcp install --ide <host[,host]> [--workspace <absolute games directory>] [--platform <HTTPS origin>] [--registry <HTTPS registry>] [--channel <npm tag>] [--updates auto|off]\n craft-mcp project-setup --project <absolute game directory> --ide <host> [--install]\n craft-mcp connect --ide <host>\n craft-mcp doctor --ide <host[,host]>\n craft-mcp check --ide <host[,host]>\n craft-mcp update --ide <host[,host]>\nHosts: codex, workbuddy, codebuddy, cursor, claude, dsh, zcode, kimi, trae, qoder-cn, qoder, comate, opencode, qwen.\nInstance selection: --instance <registered Craft server> for install, doctor, connect, project-setup, check, update or uninstall.\n craft-mcp uninstall --ide <host> [--instance <server>]\nHost options: --host-config <absolute MCP config file> (one host only); --trae-region global|cn. TRAE and Qoder IDE require the path opened by their settings UI. Environment equivalents: CRAFT_HOST_CONFIG, CRAFT_TRAE_REGION.\n\nNo arguments: start the stdio MCP server from this package.\n--workspace: override CLIENT_WORKSPACE_ROOT; games are created under <workspace>/<name>.\nDefault workspace: ~/CraftGames. The host current directory is not used.\nguide: print AI IDE installation instructions and exit.\ninstall: install and verify Craft, merge selected host configurations and install managed Skills. The default server is craft on stable. An explicit test tag selects its separate installation. Use --instance to target a specific managed registration. Reinstalling the same channel and automatic updates retain downgrade protection. Preserve the workspace, platform and update policy; new installations enable automatic updates.\nconnect: start the existing standard installation; never installs or rewrites host settings.\ncheck: inspect the configured npm channel without installing a new runtime.\nupdate: install a verified newer compatible runtime and update the host configuration, including when automatic updates are off. The current process stays on its original package. Load the target at the next MCP start or user-requested reconnect, verify its identity, then prepare the current project to update context and Skills.\nproject-setup: inspect portable project installation requirements and the selected host; --install installs only a missing registration. Verify the current host connection before resuming.\ndoctor: verify configured files and candidate MCP in an isolated process; does not confirm the current host connection.\n');
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Runtime upload budgets match the Web external-game-uploads contract.
|
|
2
|
+
export const runtimeUploadLimits = Object.freeze({
|
|
3
|
+
files: 2_000,
|
|
4
|
+
fileBytes: 8 * 1024 * 1024,
|
|
5
|
+
totalFileBytes: 220 * 1024 * 1024,
|
|
6
|
+
archiveBytes: 222 * 1024 * 1024,
|
|
7
|
+
gzipBytes: 223 * 1024 * 1024,
|
|
8
|
+
jsonBytes: 300 * 1024 * 1024,
|
|
9
|
+
pathBytes: 240,
|
|
10
|
+
centralDirectoryBytes: 4 * 1024 * 1024,
|
|
11
|
+
});
|
|
@@ -1,71 +1,71 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { createHash } from 'node:crypto';
|
|
3
|
-
import { mkdir, readFile, writeFile, lstat } from 'node:fs/promises';
|
|
4
|
-
import { resolveBundleTemplate, sharedTemplatePath } from './bundle-template.mjs';
|
|
5
|
-
|
|
6
|
-
export const archiveArtPreviews = 'shared-art-previews';
|
|
7
|
-
export const projectArtPreviews = '.craft/art-previews';
|
|
8
|
-
|
|
9
|
-
export function previewHash(name) {
|
|
10
|
-
const match = typeof name === 'string' && /^[a-z][a-z0-9-]*-([a-f0-9]{64})\.webp$/.exec(name);
|
|
11
|
-
if (!match) throw new Error('Invalid Craft preview file name: '+name);
|
|
12
|
-
return match[1];
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function checkArtPreview(name, bytes) {
|
|
16
|
-
if (createHash('sha256').update(bytes).digest('hex') !== previewHash(name)) throw new Error('Craft preview checksum mismatch: '+name);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// Skill Markdown carries the final game-relative link verbatim. Only this
|
|
20
|
-
// content-addressed destination can cross the boundary of a native host tree.
|
|
21
|
-
export function artPreviewLink(file, target) {
|
|
22
|
-
if (!target.includes('.craft/art-previews/')) return;
|
|
23
|
-
const parts = file.replaceAll('\\','/').split('/');
|
|
24
|
-
const skills = parts.lastIndexOf('skills'), name = path.posix.basename(target);
|
|
25
|
-
previewHash(name);
|
|
26
|
-
const expected = path.posix.relative(path.posix.dirname(['host',...parts.slice(skills)].join('/')),projectArtPreviews+'/'+name);
|
|
27
|
-
if (skills < 0 || target !== expected) throw new Error('Invalid project-relative Craft preview link: '+target);
|
|
28
|
-
return name;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function collectArtPreviews(file, bytes, names) {
|
|
32
|
-
if (!file.endsWith('.md') || !bytes.includes('.craft/art-previews/')) return;
|
|
33
|
-
for (const [,target] of bytes.toString('utf8').matchAll(/\[[^\]\n]*\]\(([^)\n]+)\)/g)) {
|
|
34
|
-
const name = artPreviewLink(file,target);
|
|
35
|
-
if (name) names.add(name);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function bundleArtPreviewDirectory(root, engine, host, template) {
|
|
40
|
-
const target = path.resolve(root), hostRoot = path.dirname(target), targets = path.dirname(hostRoot);
|
|
41
|
-
const resources = path.dirname(targets);
|
|
42
|
-
// A standalone --out may happen to end in targets/<host>/<engine>. Only a
|
|
43
|
-
// verified shared distribution template opts into the sibling resource pool.
|
|
44
|
-
const shared = template && host && path.basename(target) === engine && path.basename(hostRoot) === host &&
|
|
45
|
-
path.basename(targets) === 'targets' && path.resolve(template) === path.join(resources,sharedTemplatePath(engine));
|
|
46
|
-
return path.join(shared ? resources : root,archiveArtPreviews);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export async function readArtPreview(directory,name) {
|
|
50
|
-
previewHash(name);
|
|
51
|
-
const file=path.join(directory,name);
|
|
52
|
-
if (!(await lstat(directory)).isDirectory() || !(await lstat(file)).isFile()) throw new Error('Craft preview must be a regular file: '+name);
|
|
53
|
-
const bytes = await readFile(file);
|
|
54
|
-
checkArtPreview(name,bytes);
|
|
55
|
-
return bytes;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export async function copyArtPreview(source,destination,name) {
|
|
59
|
-
const bytes = await readArtPreview(source,name);
|
|
60
|
-
await mkdir(destination,{recursive:true});
|
|
61
|
-
try {await writeFile(path.join(destination,name),bytes,{flag:'wx'});}
|
|
62
|
-
catch (error) {if (error.code !== 'EEXIST') throw error; await readArtPreview(destination,name);}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export async function copyBundleArtPreviews(source,destination,bundle) {
|
|
66
|
-
if (!bundle.art_previews?.length) return;
|
|
67
|
-
const template = await resolveBundleTemplate(source,bundle.engine,bundle.host);
|
|
68
|
-
for (const name of bundle.art_previews ?? []) {
|
|
69
|
-
await copyArtPreview(bundleArtPreviewDirectory(source,bundle.engine,bundle.host,template),path.join(destination,archiveArtPreviews),name);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { mkdir, readFile, writeFile, lstat } from 'node:fs/promises';
|
|
4
|
+
import { resolveBundleTemplate, sharedTemplatePath } from './bundle-template.mjs';
|
|
5
|
+
|
|
6
|
+
export const archiveArtPreviews = 'shared-art-previews';
|
|
7
|
+
export const projectArtPreviews = '.craft/art-previews';
|
|
8
|
+
|
|
9
|
+
export function previewHash(name) {
|
|
10
|
+
const match = typeof name === 'string' && /^[a-z][a-z0-9-]*-([a-f0-9]{64})\.webp$/.exec(name);
|
|
11
|
+
if (!match) throw new Error('Invalid Craft preview file name: '+name);
|
|
12
|
+
return match[1];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function checkArtPreview(name, bytes) {
|
|
16
|
+
if (createHash('sha256').update(bytes).digest('hex') !== previewHash(name)) throw new Error('Craft preview checksum mismatch: '+name);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Skill Markdown carries the final game-relative link verbatim. Only this
|
|
20
|
+
// content-addressed destination can cross the boundary of a native host tree.
|
|
21
|
+
export function artPreviewLink(file, target) {
|
|
22
|
+
if (!target.includes('.craft/art-previews/')) return;
|
|
23
|
+
const parts = file.replaceAll('\\','/').split('/');
|
|
24
|
+
const skills = parts.lastIndexOf('skills'), name = path.posix.basename(target);
|
|
25
|
+
previewHash(name);
|
|
26
|
+
const expected = path.posix.relative(path.posix.dirname(['host',...parts.slice(skills)].join('/')),projectArtPreviews+'/'+name);
|
|
27
|
+
if (skills < 0 || target !== expected) throw new Error('Invalid project-relative Craft preview link: '+target);
|
|
28
|
+
return name;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function collectArtPreviews(file, bytes, names) {
|
|
32
|
+
if (!file.endsWith('.md') || !bytes.includes('.craft/art-previews/')) return;
|
|
33
|
+
for (const [,target] of bytes.toString('utf8').matchAll(/\[[^\]\n]*\]\(([^)\n]+)\)/g)) {
|
|
34
|
+
const name = artPreviewLink(file,target);
|
|
35
|
+
if (name) names.add(name);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function bundleArtPreviewDirectory(root, engine, host, template) {
|
|
40
|
+
const target = path.resolve(root), hostRoot = path.dirname(target), targets = path.dirname(hostRoot);
|
|
41
|
+
const resources = path.dirname(targets);
|
|
42
|
+
// A standalone --out may happen to end in targets/<host>/<engine>. Only a
|
|
43
|
+
// verified shared distribution template opts into the sibling resource pool.
|
|
44
|
+
const shared = template && host && path.basename(target) === engine && path.basename(hostRoot) === host &&
|
|
45
|
+
path.basename(targets) === 'targets' && path.resolve(template) === path.join(resources,sharedTemplatePath(engine));
|
|
46
|
+
return path.join(shared ? resources : root,archiveArtPreviews);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export async function readArtPreview(directory,name) {
|
|
50
|
+
previewHash(name);
|
|
51
|
+
const file=path.join(directory,name);
|
|
52
|
+
if (!(await lstat(directory)).isDirectory() || !(await lstat(file)).isFile()) throw new Error('Craft preview must be a regular file: '+name);
|
|
53
|
+
const bytes = await readFile(file);
|
|
54
|
+
checkArtPreview(name,bytes);
|
|
55
|
+
return bytes;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export async function copyArtPreview(source,destination,name) {
|
|
59
|
+
const bytes = await readArtPreview(source,name);
|
|
60
|
+
await mkdir(destination,{recursive:true});
|
|
61
|
+
try {await writeFile(path.join(destination,name),bytes,{flag:'wx'});}
|
|
62
|
+
catch (error) {if (error.code !== 'EEXIST') throw error; await readArtPreview(destination,name);}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export async function copyBundleArtPreviews(source,destination,bundle) {
|
|
66
|
+
if (!bundle.art_previews?.length) return;
|
|
67
|
+
const template = await resolveBundleTemplate(source,bundle.engine,bundle.host);
|
|
68
|
+
for (const name of bundle.art_previews ?? []) {
|
|
69
|
+
await copyArtPreview(bundleArtPreviewDirectory(source,bundle.engine,bundle.host,template),path.join(destination,archiveArtPreviews),name);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -38,7 +38,7 @@ export async function bundleFiles(root, engine, target = false, contextOnly = fa
|
|
|
38
38
|
return files;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
export async function
|
|
41
|
+
export async function readBundleManifest(root, engine, expectedId) {
|
|
42
42
|
const file = path.join(root,engine,'bundle.json');
|
|
43
43
|
if (!(await lstat(file)).isFile() || (await lstat(file)).isSymbolicLink()) throw new Error('Invalid bundle manifest');
|
|
44
44
|
const manifest = JSON.parse(await readFile(file,'utf8'));
|
|
@@ -52,6 +52,11 @@ export async function verifyBundle(root, engine, expectedId, {contextOnly = fals
|
|
|
52
52
|
const target = JSON.parse(await readFile(path.join(root,'target.json'),'utf8'));
|
|
53
53
|
if (!Object.hasOwn(hosts,manifest.host) || target.host !== manifest.host || target.engine !== engine || target.version !== manifest.version) throw new Error('Context target identity mismatch');
|
|
54
54
|
}
|
|
55
|
+
return manifest;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export async function verifyBundle(root, engine, expectedId, {contextOnly = false} = {}) {
|
|
59
|
+
const manifest = await readBundleManifest(root,engine,expectedId);
|
|
55
60
|
const template = contextOnly ? undefined : await resolveBundleTemplate(root,engine,manifest.schema === 2 ? manifest.host : undefined);
|
|
56
61
|
const previews = new Set();
|
|
57
62
|
const actual = await bundleFiles(root,engine,manifest.schema === 2,contextOnly,template,previews);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { readFile } from 'node:fs/promises';
|
|
3
|
-
import { verifyBundle } from './bundle-files.mjs';
|
|
3
|
+
import { digest, readBundleManifest, verifyBundle } from './bundle-files.mjs';
|
|
4
4
|
import { resolveBundleTemplate } from './bundle-template.mjs';
|
|
5
5
|
import { clientIde } from '../integrations/hosts.mjs';
|
|
6
6
|
|
|
@@ -17,29 +17,38 @@ export function engineDefinition(engine) {
|
|
|
17
17
|
return definitions[engine];
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
export async function loadEngineResources(resources, ide = 'generic') {
|
|
20
|
+
export async function loadEngineResources(resources, ide = 'generic', { deferPayload = false } = {}) {
|
|
21
21
|
const host = clientIde(ide);
|
|
22
22
|
const workflow = host === 'generic' ? path.join(resources,'craft-game-maker','SKILL.md') : path.join(resources,'targets',host,'js','bootstrap/SKILL.md');
|
|
23
|
-
const instructions = await readFile(workflow,'utf8');
|
|
24
23
|
const engines = {};
|
|
25
24
|
for (const engine of Object.keys(definitions)) {
|
|
26
25
|
const root = host === 'generic' ? resources : path.join(resources,'targets',host,engine);
|
|
27
|
-
engines[engine] = await loadEngineResource(root,engine,undefined,host === 'generic' ? undefined : host);
|
|
26
|
+
engines[engine] = await loadEngineResource(root,engine,undefined,host === 'generic' ? undefined : host,{deferPayload});
|
|
28
27
|
engines[engine].legacyResources = resources;
|
|
29
28
|
}
|
|
30
|
-
|
|
29
|
+
const instructions = await readFile(workflow);
|
|
30
|
+
const relative = path.relative(engines.js.resources,workflow).split(path.sep).join('/');
|
|
31
|
+
if (deferPayload && digest(instructions) !== engines.js.bundle.files[relative]) throw new Error('Context bundle integrity check failed: '+relative);
|
|
32
|
+
return { instructions:instructions.toString('utf8'), workflow, engines };
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
export async function loadEngineResource(resources, engine, expectedId, expectedHost, options = {}) {
|
|
34
|
-
const definition = engineDefinition(engine), bundle =
|
|
36
|
+
const definition = engineDefinition(engine), bundle = options.deferPayload
|
|
37
|
+
? await readBundleManifest(resources,engine,expectedId)
|
|
38
|
+
: await verifyBundle(resources,engine,expectedId,options);
|
|
35
39
|
if (expectedHost && (bundle.schema !== 2 || bundle.host !== expectedHost)) throw new Error('Context belongs to a different host; expected '+expectedHost);
|
|
36
40
|
const workflow = path.join(resources,'craft-game-maker','SKILL.md');
|
|
37
|
-
const instructions = await readFile(workflow,'utf8');
|
|
38
41
|
const directory = path.join(resources,engine,'context');
|
|
39
42
|
const guide = path.join(resources,'craft-game-maker',engine + '.md');
|
|
43
|
+
const instructions = await Promise.all([workflow,guide].map(async file => {
|
|
44
|
+
const bytes = await readFile(file);
|
|
45
|
+
const relative = path.relative(resources,file).split(path.sep).join('/');
|
|
46
|
+
if (options.deferPayload && digest(bytes) !== bundle.files[relative]) throw new Error('Context bundle integrity check failed: '+relative);
|
|
47
|
+
return bytes.toString('utf8');
|
|
48
|
+
}));
|
|
40
49
|
const template = options.contextOnly ? undefined : await resolveBundleTemplate(resources,engine,bundle.host);
|
|
41
|
-
return { engine, host:bundle.host, label:definition.label, resources, bundle, template,
|
|
42
|
-
instructions:instructions
|
|
50
|
+
return { engine, host:bundle.host, label:definition.label, resources, bundle, template, deferPayload:options.deferPayload,
|
|
51
|
+
instructions:instructions.join('\n\n'),
|
|
43
52
|
context:{ workflow, ...(bundle.schema === 2 ? {recovery:path.join(resources,'recovery.md')} : {}),
|
|
44
53
|
target:{host:bundle.host ?? 'legacy',engine,version:bundle.version ?? null,bundle_id:bundle.id},
|
|
45
54
|
bundle:{id:bundle.id,source_revision:bundle.source_revision,contracts:bundle.contracts,compatibility:bundle.compatibility},
|
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { mkdir, mkdtemp, readFile, readdir, writeFile, lstat, rename, rm } from 'node:fs/promises';
|
|
3
|
-
import { randomUUID } from 'node:crypto';
|
|
4
|
-
import { safeProjectFile } from './asset-import.mjs';
|
|
5
|
-
import { verifyBundle } from './bundle-files.mjs';
|
|
6
|
-
import { loadEngineResource } from './engines.mjs';
|
|
7
|
-
import { copyBundleArtPreviews } from './art-previews.mjs';
|
|
8
|
-
|
|
9
|
-
export const localContextPath = (host,engine,id)=>`.craft/contexts/${host}/${engine}/${id}`;
|
|
10
|
-
|
|
11
|
-
// All parent components are checked using the same project boundary as game files.
|
|
12
|
-
async function directory(project, relative) {
|
|
13
|
-
const marker = await safeProjectFile(project,relative+'/.directory-check',true);
|
|
14
|
-
return path.dirname(marker);
|
|
15
|
-
}
|
|
16
|
-
async function noLinks(root) {
|
|
17
|
-
for (const entry of await readdir(root,{withFileTypes:true})) {
|
|
18
|
-
if (entry.isSymbolicLink() || (!entry.isDirectory() && !entry.isFile())) throw new Error('Project context contains a link or special file');
|
|
19
|
-
if (entry.isDirectory()) await noLinks(path.join(root,entry.name));
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// Immutable version directories keep an in-flight operation on the exact files it selected.
|
|
24
|
-
// Only the sync record switches after the new snapshot is complete and verified.
|
|
25
|
-
export async function materializeContext(project, current, previous) {
|
|
26
|
-
const {host,engine,bundle,resources} = current;
|
|
27
|
-
const relative = localContextPath(host,engine,bundle.id);
|
|
28
|
-
const parent = await directory(project,`.craft/contexts/${host}/${engine}`);
|
|
29
|
-
const target = path.join(parent,bundle.id);
|
|
30
|
-
let present = false, backup;
|
|
31
|
-
try {
|
|
32
|
-
const stat = await lstat(target);
|
|
33
|
-
if (!stat.isDirectory() || stat.isSymbolicLink()) throw new Error('Project context target must be a regular directory');
|
|
34
|
-
await noLinks(target);
|
|
35
|
-
present = true;
|
|
36
|
-
} catch (error) { if (error.code !== 'ENOENT') throw error; }
|
|
37
|
-
if (present) {
|
|
38
|
-
try {
|
|
39
|
-
const selected = await loadEngineResource(target,engine,bundle.id,host,{contextOnly:true});
|
|
40
|
-
return {selected,relative,materialized:false};
|
|
41
|
-
} catch (error) {
|
|
42
|
-
// Do not claim an arbitrary pre-existing directory as an owned context.
|
|
43
|
-
if (previous?.path !== relative) throw new Error('Unmanaged or incomplete project context at '+relative+'; preserve it before retrying', {cause:error});
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
const staging = await mkdtemp(path.join(parent,'.staging-'));
|
|
47
|
-
try {
|
|
48
|
-
const files = [...Object.keys(bundle.files).filter(name=>!name.startsWith(engine+'/project/')),engine+'/bundle.json'];
|
|
49
|
-
for (const name of files) {
|
|
50
|
-
const output = await safeProjectFile(staging,name,true);
|
|
51
|
-
await writeFile(output,await readFile(path.join(resources,name)),{flag:'wx'});
|
|
52
|
-
}
|
|
53
|
-
await copyBundleArtPreviews(resources,staging,bundle);
|
|
54
|
-
await verifyBundle(staging,engine,bundle.id,{contextOnly:true});
|
|
55
|
-
if (present) {
|
|
56
|
-
const backups = await directory(project,`.craft/context-backups/${host}/${engine}`);
|
|
57
|
-
backup = path.join(backups,bundle.id+'-'+randomUUID());
|
|
58
|
-
await rename(target,backup);
|
|
59
|
-
}
|
|
60
|
-
await rename(staging,target);
|
|
61
|
-
const selected = await loadEngineResource(target,engine,bundle.id,host,{contextOnly:true});
|
|
62
|
-
return {selected,relative,materialized:true,...(backup ? {backup} : {})};
|
|
63
|
-
} finally { await rm(staging,{recursive:true,force:true}); }
|
|
64
|
-
}
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { mkdir, mkdtemp, readFile, readdir, writeFile, lstat, rename, rm } from 'node:fs/promises';
|
|
3
|
+
import { randomUUID } from 'node:crypto';
|
|
4
|
+
import { safeProjectFile } from './asset-import.mjs';
|
|
5
|
+
import { verifyBundle } from './bundle-files.mjs';
|
|
6
|
+
import { loadEngineResource } from './engines.mjs';
|
|
7
|
+
import { copyBundleArtPreviews } from './art-previews.mjs';
|
|
8
|
+
|
|
9
|
+
export const localContextPath = (host,engine,id)=>`.craft/contexts/${host}/${engine}/${id}`;
|
|
10
|
+
|
|
11
|
+
// All parent components are checked using the same project boundary as game files.
|
|
12
|
+
async function directory(project, relative) {
|
|
13
|
+
const marker = await safeProjectFile(project,relative+'/.directory-check',true);
|
|
14
|
+
return path.dirname(marker);
|
|
15
|
+
}
|
|
16
|
+
async function noLinks(root) {
|
|
17
|
+
for (const entry of await readdir(root,{withFileTypes:true})) {
|
|
18
|
+
if (entry.isSymbolicLink() || (!entry.isDirectory() && !entry.isFile())) throw new Error('Project context contains a link or special file');
|
|
19
|
+
if (entry.isDirectory()) await noLinks(path.join(root,entry.name));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Immutable version directories keep an in-flight operation on the exact files it selected.
|
|
24
|
+
// Only the sync record switches after the new snapshot is complete and verified.
|
|
25
|
+
export async function materializeContext(project, current, previous) {
|
|
26
|
+
const {host,engine,bundle,resources} = current;
|
|
27
|
+
const relative = localContextPath(host,engine,bundle.id);
|
|
28
|
+
const parent = await directory(project,`.craft/contexts/${host}/${engine}`);
|
|
29
|
+
const target = path.join(parent,bundle.id);
|
|
30
|
+
let present = false, backup;
|
|
31
|
+
try {
|
|
32
|
+
const stat = await lstat(target);
|
|
33
|
+
if (!stat.isDirectory() || stat.isSymbolicLink()) throw new Error('Project context target must be a regular directory');
|
|
34
|
+
await noLinks(target);
|
|
35
|
+
present = true;
|
|
36
|
+
} catch (error) { if (error.code !== 'ENOENT') throw error; }
|
|
37
|
+
if (present) {
|
|
38
|
+
try {
|
|
39
|
+
const selected = await loadEngineResource(target,engine,bundle.id,host,{contextOnly:true});
|
|
40
|
+
return {selected,relative,materialized:false};
|
|
41
|
+
} catch (error) {
|
|
42
|
+
// Do not claim an arbitrary pre-existing directory as an owned context.
|
|
43
|
+
if (previous?.path !== relative) throw new Error('Unmanaged or incomplete project context at '+relative+'; preserve it before retrying', {cause:error});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const staging = await mkdtemp(path.join(parent,'.staging-'));
|
|
47
|
+
try {
|
|
48
|
+
const files = [...Object.keys(bundle.files).filter(name=>!name.startsWith(engine+'/project/')),engine+'/bundle.json'];
|
|
49
|
+
for (const name of files) {
|
|
50
|
+
const output = await safeProjectFile(staging,name,true);
|
|
51
|
+
await writeFile(output,await readFile(path.join(resources,name)),{flag:'wx'});
|
|
52
|
+
}
|
|
53
|
+
await copyBundleArtPreviews(resources,staging,bundle);
|
|
54
|
+
await verifyBundle(staging,engine,bundle.id,{contextOnly:true});
|
|
55
|
+
if (present) {
|
|
56
|
+
const backups = await directory(project,`.craft/context-backups/${host}/${engine}`);
|
|
57
|
+
backup = path.join(backups,bundle.id+'-'+randomUUID());
|
|
58
|
+
await rename(target,backup);
|
|
59
|
+
}
|
|
60
|
+
await rename(staging,target);
|
|
61
|
+
const selected = await loadEngineResource(target,engine,bundle.id,host,{contextOnly:true});
|
|
62
|
+
return {selected,relative,materialized:true,...(backup ? {backup} : {})};
|
|
63
|
+
} finally { await rm(staging,{recursive:true,force:true}); }
|
|
64
|
+
}
|
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
import { readFile, writeFile, rename, rm } from 'node:fs/promises';
|
|
2
|
-
import { randomUUID } from 'node:crypto';
|
|
3
|
-
import { digest } from './bundle-files.mjs';
|
|
4
|
-
import { safeProjectFile } from './asset-import.mjs';
|
|
5
|
-
import { previewHash, projectArtPreviews, bundleArtPreviewDirectory, readArtPreview } from './art-previews.mjs';
|
|
6
|
-
|
|
7
|
-
async function projectPreviewBytes(project,name) {
|
|
8
|
-
previewHash(name);
|
|
9
|
-
try {return await readFile(await safeProjectFile(project,projectArtPreviews+'/'+name));}
|
|
10
|
-
catch (error) {if (error.code !== 'ENOENT') throw error; return null;}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export async function projectArtPreviewsCurrent(project,names,checks=new Map()) {
|
|
14
|
-
for (const name of names ?? []) {
|
|
15
|
-
if (!checks.has(name)) checks.set(name,projectPreviewBytes(project,name).then(bytes=>bytes !== null && digest(bytes) === previewHash(name)));
|
|
16
|
-
if (!await checks.get(name)) return false;
|
|
17
|
-
}
|
|
18
|
-
return true;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// Keep the old lock until retirement finishes. An interrupted migration can
|
|
22
|
-
// retry: an already archived file is absent, and unrelated files are untouched.
|
|
23
|
-
export async function retireArtPreviews(project,previous,current,guard) {
|
|
24
|
-
const active = new Set(current);
|
|
25
|
-
for (const name of previous) {
|
|
26
|
-
if (active.has(name)) continue;
|
|
27
|
-
await guard();
|
|
28
|
-
const bytes = await projectPreviewBytes(project,name);
|
|
29
|
-
if (bytes === null || digest(bytes) !== previewHash(name)) continue;
|
|
30
|
-
const file = await safeProjectFile(project,projectArtPreviews+'/'+name);
|
|
31
|
-
const backup = await safeProjectFile(project,'.craft/context-backups/art-previews/'+randomUUID()+'/'+name,true);
|
|
32
|
-
await rename(file,backup);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export async function prepareArtPreviews(project,current,guard) {
|
|
37
|
-
for (const name of current.bundle.art_previews ?? []) {
|
|
38
|
-
const original = await projectPreviewBytes(project,name);
|
|
39
|
-
if (original !== null && digest(original) === previewHash(name)) continue;
|
|
40
|
-
const bytes = await readArtPreview(bundleArtPreviewDirectory(current.resources,current.engine,current.host,current.template),name);
|
|
41
|
-
await guard();
|
|
42
|
-
// This namespace is reserved for immutable, digest-named reference images.
|
|
43
|
-
// Preserve unexpected local content before repairing its official counterpart.
|
|
44
|
-
const token = randomUUID(), relative = projectArtPreviews+'/'+name;
|
|
45
|
-
if (original !== null) {
|
|
46
|
-
const backup = await safeProjectFile(project,'.craft/context-backups/art-previews/'+token+'/'+name,true);
|
|
47
|
-
await writeFile(backup,original,{flag:'wx'});
|
|
48
|
-
}
|
|
49
|
-
const destination = await safeProjectFile(project,relative,true);
|
|
50
|
-
// Prepare owns the project lock. Reuse its private staging slot on retry
|
|
51
|
-
// so a terminated writer cannot strand a partial image in the asset pool.
|
|
52
|
-
const temporary = await safeProjectFile(project,'.craft/context-staging/art-previews/'+name+'.tmp',true);
|
|
53
|
-
await rm(temporary,{force:true});
|
|
54
|
-
try {
|
|
55
|
-
await writeFile(temporary,bytes,{flag:'wx'});
|
|
56
|
-
await guard();
|
|
57
|
-
const latest = await projectPreviewBytes(project,name);
|
|
58
|
-
if (latest !== null && digest(latest) === previewHash(name)) continue;
|
|
59
|
-
if (latest === null ? original !== null : !original?.equals(latest)) throw new Error('Project art preview changed during restoration: '+name);
|
|
60
|
-
await rename(temporary,destination);
|
|
61
|
-
} finally {await rm(temporary,{force:true});}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
1
|
+
import { readFile, writeFile, rename, rm } from 'node:fs/promises';
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import { digest } from './bundle-files.mjs';
|
|
4
|
+
import { safeProjectFile } from './asset-import.mjs';
|
|
5
|
+
import { previewHash, projectArtPreviews, bundleArtPreviewDirectory, readArtPreview } from './art-previews.mjs';
|
|
6
|
+
|
|
7
|
+
async function projectPreviewBytes(project,name) {
|
|
8
|
+
previewHash(name);
|
|
9
|
+
try {return await readFile(await safeProjectFile(project,projectArtPreviews+'/'+name));}
|
|
10
|
+
catch (error) {if (error.code !== 'ENOENT') throw error; return null;}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export async function projectArtPreviewsCurrent(project,names,checks=new Map()) {
|
|
14
|
+
for (const name of names ?? []) {
|
|
15
|
+
if (!checks.has(name)) checks.set(name,projectPreviewBytes(project,name).then(bytes=>bytes !== null && digest(bytes) === previewHash(name)));
|
|
16
|
+
if (!await checks.get(name)) return false;
|
|
17
|
+
}
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Keep the old lock until retirement finishes. An interrupted migration can
|
|
22
|
+
// retry: an already archived file is absent, and unrelated files are untouched.
|
|
23
|
+
export async function retireArtPreviews(project,previous,current,guard) {
|
|
24
|
+
const active = new Set(current);
|
|
25
|
+
for (const name of previous) {
|
|
26
|
+
if (active.has(name)) continue;
|
|
27
|
+
await guard();
|
|
28
|
+
const bytes = await projectPreviewBytes(project,name);
|
|
29
|
+
if (bytes === null || digest(bytes) !== previewHash(name)) continue;
|
|
30
|
+
const file = await safeProjectFile(project,projectArtPreviews+'/'+name);
|
|
31
|
+
const backup = await safeProjectFile(project,'.craft/context-backups/art-previews/'+randomUUID()+'/'+name,true);
|
|
32
|
+
await rename(file,backup);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export async function prepareArtPreviews(project,current,guard) {
|
|
37
|
+
for (const name of current.bundle.art_previews ?? []) {
|
|
38
|
+
const original = await projectPreviewBytes(project,name);
|
|
39
|
+
if (original !== null && digest(original) === previewHash(name)) continue;
|
|
40
|
+
const bytes = await readArtPreview(bundleArtPreviewDirectory(current.resources,current.engine,current.host,current.template),name);
|
|
41
|
+
await guard();
|
|
42
|
+
// This namespace is reserved for immutable, digest-named reference images.
|
|
43
|
+
// Preserve unexpected local content before repairing its official counterpart.
|
|
44
|
+
const token = randomUUID(), relative = projectArtPreviews+'/'+name;
|
|
45
|
+
if (original !== null) {
|
|
46
|
+
const backup = await safeProjectFile(project,'.craft/context-backups/art-previews/'+token+'/'+name,true);
|
|
47
|
+
await writeFile(backup,original,{flag:'wx'});
|
|
48
|
+
}
|
|
49
|
+
const destination = await safeProjectFile(project,relative,true);
|
|
50
|
+
// Prepare owns the project lock. Reuse its private staging slot on retry
|
|
51
|
+
// so a terminated writer cannot strand a partial image in the asset pool.
|
|
52
|
+
const temporary = await safeProjectFile(project,'.craft/context-staging/art-previews/'+name+'.tmp',true);
|
|
53
|
+
await rm(temporary,{force:true});
|
|
54
|
+
try {
|
|
55
|
+
await writeFile(temporary,bytes,{flag:'wx'});
|
|
56
|
+
await guard();
|
|
57
|
+
const latest = await projectPreviewBytes(project,name);
|
|
58
|
+
if (latest !== null && digest(latest) === previewHash(name)) continue;
|
|
59
|
+
if (latest === null ? original !== null : !original?.equals(latest)) throw new Error('Project art preview changed during restoration: '+name);
|
|
60
|
+
await rename(temporary,destination);
|
|
61
|
+
} finally {await rm(temporary,{force:true});}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -4,6 +4,8 @@ import { createHash, randomUUID } from 'node:crypto';
|
|
|
4
4
|
import { parseDocument, isMap } from 'yaml';
|
|
5
5
|
import { safeProjectFile } from './asset-import.mjs';
|
|
6
6
|
import { nativeContextPath } from './native-context.mjs';
|
|
7
|
+
import { projectPackageName } from './project-install.mjs';
|
|
8
|
+
import { internalRegistryArgs } from '../integrations/distribution-targets.mjs';
|
|
7
9
|
import { hosts, clientIde, projectSkillPath, hostRecoveryEntry } from '../integrations/hosts.mjs';
|
|
8
10
|
|
|
9
11
|
const start = '<!-- craft-mcp:project:start -->';
|
|
@@ -91,10 +93,11 @@ function mergeRuleMetadata(original,prefix) {
|
|
|
91
93
|
|
|
92
94
|
function projectConnectionGuide(host) {
|
|
93
95
|
const target = host === 'generic' ? '<当前宿主>' : host;
|
|
96
|
+
const npx = ['npx -y --registry "<registry>"', ...internalRegistryArgs(projectPackageName)].join(' ');
|
|
94
97
|
return '首次接手或切换 Agent 时,先通过当前宿主实际提供的工具发现能力查找 Craft 工具;工具可能延迟暴露或带命名空间前缀,不能因裸工具名不存在、resources 为空就判断未安装。项目文件和 Skill 可用也不代表 MCP 已连接。\n\n'
|
|
95
98
|
+ instanceGuide + ' 实际程序低于 minimum_mcp_version 时先处理版本要求。\n\n'
|
|
96
99
|
+ '若没有可用的 Craft 连接,读取 `.craft/project-install.json`,确认 package_name、minimum_mcp_version、registry、channel、platform 和 engine。使用当前宿主终端执行下面的项目接入检查,将占位值替换为文件中的值及当前游戏绝对目录,并按终端规则引用参数:\n\n'
|
|
97
|
-
+ '```text\
|
|
100
|
+
+ '```text\n'+npx+' "'+projectPackageName+'@<minimum_mcp_version>" project-setup --project "<当前游戏绝对目录>" --ide '+target+'\n```\n\n'
|
|
98
101
|
+ 'TRAE 和国际版 Qoder IDE 的接入命令需加 `--host-config "<宿主 MCP 设置界面打开的配置文件绝对路径>"`;不要猜测配置路径。TRAE CN 另加 `--trae-region cn`,国际版使用 global。已有安装检查、更新及恢复沿用相同路径和地区。\n\n'
|
|
99
102
|
+ '检查命令只读。返回 `instance_required` 或 `multiple_installations` 时请用户选定服务,以 `--instance <服务名>` 重新检查。仅返回 `missing_installation` 且用户正在请求继续制作时,在同一命令末尾加 `--install`;非 stable 渠道新装须由用户明确选择命名实例。所选包必须满足项目最低 MCP 版本;随后按已有更新策略检查渠道。安装包尚未发布或网络/终端权限不可用时报告准确原因;用户提供本地候选包时可用该包的同一 CLI,不降低项目版本。\n\n'
|
|
100
103
|
+ '已有配置被禁用、范围不匹配、旧版或连接失败时按检查结果修复,不当作缺失重复安装,不自行启用用户禁用的服务或覆盖其他工作区/平台。`--workspace` 必须是当前游戏父目录,不跟随默认目录。旧项目缺少安装信息时,先使用已连接且目录/平台明确的 Craft 完成 resume 以补齐;无可靠来源则询问缺失的平台/版本信息,不猜默认环境。\n\n'
|
|
@@ -2,10 +2,13 @@ import { readFile, open, rename, rm } from 'node:fs/promises';
|
|
|
2
2
|
import { randomUUID } from 'node:crypto';
|
|
3
3
|
import { safeProjectFile } from './asset-import.mjs';
|
|
4
4
|
import { compareVersions, parseVersion } from '../integrations/version-policy.mjs';
|
|
5
|
+
import { distributionTargets } from '../integrations/distribution-targets.mjs';
|
|
6
|
+
import pkg from '../../package.json' with { type: 'json' };
|
|
5
7
|
|
|
6
8
|
export const projectInstallFile = '.craft/project-install.json';
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
+
// Local kits retain the public npm package as their portable recovery entry.
|
|
10
|
+
const distribution = pkg.name === distributionTargets.internal.package ? distributionTargets.internal : distributionTargets.public;
|
|
11
|
+
export const projectPackageName = distribution.package;
|
|
9
12
|
const fields = ['schema', 'package_name', 'minimum_mcp_version', 'registry', 'channel', 'platform', 'engine'];
|
|
10
13
|
|
|
11
14
|
function httpsUrl(value, { origin = false } = {}) {
|
|
@@ -22,13 +25,17 @@ function httpsUrl(value, { origin = false } = {}) {
|
|
|
22
25
|
export function validateProjectInstall(value) {
|
|
23
26
|
if (!value || typeof value !== 'object' || Array.isArray(value) ||
|
|
24
27
|
Object.keys(value).length !== fields.length || Object.keys(value).some(key => !fields.includes(key)) ||
|
|
25
|
-
value.schema !== 1 || value.package_name
|
|
28
|
+
value.schema !== 1 || !Object.values(distributionTargets).some(target => target.package === value.package_name) || !['js', 'js3d'].includes(value.engine)) {
|
|
26
29
|
throw new Error('Invalid Craft project installation contract');
|
|
27
30
|
}
|
|
28
31
|
parseVersion(value.minimum_mcp_version);
|
|
29
32
|
if (typeof value.channel !== 'string' || !/^[a-zA-Z][a-zA-Z0-9._-]*$/.test(value.channel)) throw new Error('Project installation channel must be an npm dist-tag');
|
|
30
|
-
|
|
31
|
-
|
|
33
|
+
const registry = httpsUrl(value.registry);
|
|
34
|
+
if (value.package_name === distributionTargets.internal.package && registry !== distributionTargets.internal.registry) {
|
|
35
|
+
throw new Error('The internal Craft package requires its company npm registry');
|
|
36
|
+
}
|
|
37
|
+
return { schema: 1, package_name: value.package_name, minimum_mcp_version: value.minimum_mcp_version,
|
|
38
|
+
registry, channel: value.channel, platform: httpsUrl(value.platform, { origin: true }), engine: value.engine };
|
|
32
39
|
}
|
|
33
40
|
|
|
34
41
|
async function snapshot(project) {
|
|
@@ -45,6 +52,7 @@ export async function readProjectInstall(project, { required = false } = {}) {
|
|
|
45
52
|
}
|
|
46
53
|
|
|
47
54
|
export function assertProjectInstallConnection(manifest, { engine, version, platform, registry, channel, requireKnownChannel = false }) {
|
|
55
|
+
if (manifest.package_name !== projectPackageName) throw new Error('Project installation package differs from the current Craft runtime');
|
|
48
56
|
if (manifest.engine !== engine) throw new Error('Project installation engine differs from the existing game; keep its original engine');
|
|
49
57
|
if (compareVersions(version, manifest.minimum_mcp_version) < 0) throw new Error('Project requires Craft MCP >= ' + manifest.minimum_mcp_version + '; the current runtime cannot downgrade its installation contract');
|
|
50
58
|
if (httpsUrl(platform, { origin: true }) !== manifest.platform) throw new Error('Project installation platform differs from the current Craft connection; reconnect to the project platform before resuming');
|
|
@@ -57,8 +65,8 @@ export function assertProjectInstallConnection(manifest, { engine, version, plat
|
|
|
57
65
|
export async function planProjectInstall(project, options) {
|
|
58
66
|
const before = await snapshot(project), previous = before.manifest;
|
|
59
67
|
if (previous) assertProjectInstallConnection(previous, options);
|
|
60
|
-
const manifest = validateProjectInstall({ schema: 1, package_name:
|
|
61
|
-
minimum_mcp_version: options.version, registry: options.registry ?? previous?.registry ??
|
|
68
|
+
const manifest = validateProjectInstall({ schema: 1, package_name: projectPackageName,
|
|
69
|
+
minimum_mcp_version: options.version, registry: options.registry ?? previous?.registry ?? distribution.registry,
|
|
62
70
|
channel: options.channel ?? previous?.channel ?? 'stable', platform: options.platform, engine: options.engine });
|
|
63
71
|
return { manifest, previous, before: before.text, changed: JSON.stringify(manifest) !== JSON.stringify(previous) };
|
|
64
72
|
}
|