@craft_eco/craft-mcp 0.1.34-beta.2 → 0.1.34-beta.4
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 +6 -17
- package/bin/craft-mcp.mjs +30 -2
- package/dist-server/core/upload-limits.mjs +11 -0
- package/dist-server/game-workflow/bundle-files.mjs +6 -1
- package/dist-server/game-workflow/engines.mjs +18 -9
- package/dist-server/game-workflow/project-context.mjs +11 -7
- package/dist-server/game-workflow/project-install.mjs +17 -8
- package/dist-server/game-workflow/projects.mjs +13 -3
- package/dist-server/integrations/config.mjs +41 -18
- package/dist-server/integrations/connect.mjs +18 -9
- package/dist-server/integrations/connection-handoff.mjs +9 -8
- package/dist-server/integrations/distribution-targets.mjs +9 -0
- package/dist-server/integrations/dsh-config.mjs +30 -14
- package/dist-server/integrations/fixed-launcher.mjs +1 -0
- package/dist-server/integrations/host-config-scope.mjs +4 -3
- package/dist-server/integrations/hosts.mjs +3 -1
- package/dist-server/integrations/install.mjs +147 -43
- package/dist-server/integrations/installation-state.mjs +2 -1
- package/dist-server/integrations/instance-skill.mjs +26 -0
- package/dist-server/integrations/instance.mjs +29 -0
- package/dist-server/integrations/launcher-start.mjs +6 -6
- package/dist-server/integrations/login-task-command.mjs +3 -3
- package/dist-server/integrations/opencode-config.mjs +13 -6
- package/dist-server/integrations/project-setup.mjs +48 -18
- 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 +7 -3
- package/dist-server/integrations/uninstall.mjs +160 -0
- package/dist-server/integrations/updates.mjs +57 -42
- package/dist-server/launcher.mjs +65 -10
- package/dist-server/mcp/production-events.mjs +52 -29
- package/dist-server/mcp/server.mjs +18 -9
- package/dist-server/mcp/update-session.mjs +9 -6
- package/dist-server/preview/preview-snapshot.mjs +3 -2
- package/package.json +5 -3
- package/resources/craft-create/SKILL.md +2 -0
- package/resources/craft-update/SKILL.md +2 -0
- package/vendor/craft-runtime/NOTICE.md +1 -1
- package/vendor/craft-runtime/SOURCE.json +9 -5
- package/vendor/craft-runtime/index.js +228 -164
- package/vendor/craft-runtime/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,24 +10,13 @@ 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
14
|
|
|
15
|
-
|
|
15
|
+
已安装的实例启动失败时,保留原包和源,先执行 doctor --ide <当前宿主> --instance <原服务名>。确认运行目录损坏后,执行 install --repair --ide <当前宿主> --instance <原服务名> 恢复原构建,重连后用 craft_game_info 核对。
|
|
16
16
|
|
|
17
17
|
```sh
|
|
18
|
-
#
|
|
19
|
-
npx --yes --registry=https://registry.npmjs.org/ @craft_eco/craft-mcp@
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
已有安装切换到用户指定的其他渠道时,目标版本可以低于原渠道版本。同渠道安装和自动更新保留防降级。用户只给了具体版本时保留该版本。用户只写包名且未指定渠道时,install 也只写包名,省略 --channel。已有安装继续跟踪原渠道,首次安装默认跟踪 stable。
|
|
23
|
-
|
|
24
|
-
```sh
|
|
25
|
-
# 用户只写包名,在 WorkBuddy 中安装
|
|
26
|
-
npx --yes --registry=https://registry.npmjs.org/ @craft_eco/craft-mcp install --ide workbuddy
|
|
27
|
-
# 指定当前包版本,在 Codex 中安装
|
|
28
|
-
npx --yes --registry=https://registry.npmjs.org/ @craft_eco/craft-mcp@0.1.34-beta.2 install --ide codex
|
|
29
|
-
# 指定当前包版本,在 WorkBuddy 中安装
|
|
30
|
-
npx --yes --registry=https://registry.npmjs.org/ @craft_eco/craft-mcp@0.1.34-beta.2 install --ide workbuddy
|
|
18
|
+
# 在 Codex 中安装
|
|
19
|
+
npx --yes --registry=https://registry.npmjs.org/ @craft_eco/craft-mcp@beta install --ide codex
|
|
31
20
|
```
|
|
32
21
|
|
|
33
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 和本包平台。安装不创建游戏、不修改信任权限。
|
|
@@ -45,7 +34,7 @@ Claude Code 使用 ~/.claude.json 与 ~/.claude/skills;DSH 使用 ~/.dsh/cordi
|
|
|
45
34
|
执行本包 guide,根据当前宿主调用上面的标准 install。十四种宿主使用同一安装流程,无需选择连接模式。当前进程不会因安装新版而切换版本;固定入口在下次启动时读取已安装目标。
|
|
46
35
|
|
|
47
36
|
```sh
|
|
48
|
-
npx --yes --registry=https://registry.npmjs.org/ @craft_eco/craft-mcp guide
|
|
37
|
+
npx --yes --registry=https://registry.npmjs.org/ @craft_eco/craft-mcp@beta guide
|
|
49
38
|
```
|
|
50
39
|
|
|
51
40
|
专家和连接器只通过 connect --ide workbuddy 解析标准安装并启动同一受管入口,首次使用也须先执行标准 install。connect 不安装程序、不改宿主配置、不创建游戏;安装缺失、禁用或平台/工作区不一致时明确失败。不要用无参数 npx 直接启动业务包来替代标准安装。未适配宿主的原始 stdio 调试不包含自动更新和 Skill 安装。
|
|
@@ -62,6 +51,6 @@ npx --yes --registry=https://registry.npmjs.org/ @craft_eco/craft-mcp guide
|
|
|
62
51
|
|
|
63
52
|
使用 craft_game_upload 上传同次检查冻结的源码与 dist。安全检查失败时告知用户原因并停止上传。安全检查通过后,玩法和画面问题作为报告反馈。draft_ready 后把 project_url 交给用户,在 Craft 网页完成发布。
|
|
64
53
|
|
|
65
|
-
当前业务平台是 https://
|
|
54
|
+
当前业务平台是 https://craft.qq.com。游戏上传和提审需要匹配的 Web 服务与审核配置。
|
|
66
55
|
|
|
67
56
|
发布图片上传后可公开访问,游戏审核通过后可能公开。平台审核覆盖提交的文案与图片,不会扫描或执行整个游戏压缩包。
|
package/bin/craft-mcp.mjs
CHANGED
|
@@ -14,7 +14,34 @@ if (args.length === 0 || (args.length === 2 && args[0] === '--workspace' && path
|
|
|
14
14
|
if (args.length) process.env.CLIENT_WORKSPACE_ROOT = path.resolve(args[1]);
|
|
15
15
|
await import('../dist-server/mcp/start.mjs');
|
|
16
16
|
} else if (args.length === 1 && args[0] === 'guide') {
|
|
17
|
-
|
|
17
|
+
let guide = await readFile(new URL('../README.md', import.meta.url), 'utf8');
|
|
18
|
+
if (process.env.npm_command === 'exec' && process.env.npm_lifecycle_event === 'npx') {
|
|
19
|
+
const { npmInstallSelector } = await import('../dist-server/integrations/install-source.mjs');
|
|
20
|
+
const { serverIdForChannel } = await import('../dist-server/integrations/instance.mjs');
|
|
21
|
+
const pkg = JSON.parse(await readFile(new URL('../package.json', import.meta.url), 'utf8'));
|
|
22
|
+
const selector = await npmInstallSelector(fileURLToPath(new URL('..', import.meta.url)), pkg.name);
|
|
23
|
+
if (selector?.kind === 'tag' && !['stable', 'latest'].includes(selector.tag)) {
|
|
24
|
+
const tag = selector.tag;
|
|
25
|
+
const server = serverIdForChannel(tag);
|
|
26
|
+
guide = [
|
|
27
|
+
'# 安装用户指定的 Craft 实例', '',
|
|
28
|
+
'保留本次 npx 命令的 registry 和包选择器,将 guide 换为下列参数,并将占位符替换为当前宿主。', '',
|
|
29
|
+
' install --ide <当前宿主> --channel ' + tag + ' --instance ' + server, '',
|
|
30
|
+
'该服务拥有独立的工作区和 Skill。同一命令再次安装时更新该实例。安装完成后等待宿主连接 ' + server +
|
|
31
|
+
',在当前聊天用它的 craft_game_info 核对 server_id、channel、version、build_id、workspace 和 active_verified。',
|
|
32
|
+
'TRAE 和国际版 Qoder IDE 需追加 --host-config <从该宿主设置中打开的配置绝对路径>。TRAE 国内版另加 --trae-region cn。',
|
|
33
|
+
'新安装默认游戏目录为 ~/CraftTestGames/' + server + ',平台为 ' + pkg.craft.platform + '。安装器会保留该实例已有的平台和工作区。',
|
|
34
|
+
'在 CLI 中检查、更新、诊断或卸载时传 --ide <当前宿主> --instance ' + server + '。',
|
|
35
|
+
'启动失败时先运行 doctor。确认运行文件损坏后,用 install --repair --ide <当前宿主> --instance ' + server + ' 恢复该实例记录的构建。', '',
|
|
36
|
+
].join('\n');
|
|
37
|
+
} else if (selector?.kind === 'package') {
|
|
38
|
+
guide = guide.replaceAll(pkg.name + '@stable ', pkg.name + '@' + pkg.version + ' ');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
process.stdout.write(guide);
|
|
42
|
+
} else if (args[0] === 'uninstall') {
|
|
43
|
+
try { const { runUninstallCommand } = await import('../dist-server/integrations/uninstall.mjs'); await runUninstallCommand(args); }
|
|
44
|
+
catch (error) { process.stderr.write('Craft uninstall failed: ' + error.message + '\n'); process.exitCode = 1; }
|
|
18
45
|
} else if (args[0] === 'connect') {
|
|
19
46
|
try { const { runConnectCommand } = await import('../dist-server/integrations/connect.mjs'); await runConnectCommand(args); }
|
|
20
47
|
catch (error) { process.stderr.write('Craft connect failed: ' + error.message + '\n'); process.exitCode = 1; }
|
|
@@ -35,9 +62,10 @@ if (args.length === 0 || (args.length === 2 && args[0] === '--workspace' && path
|
|
|
35
62
|
try { const { runUpdateCommand } = await import('../dist-server/integrations/updates.mjs'); await runUpdateCommand(args); }
|
|
36
63
|
catch (error) { process.stderr.write('Craft ' + args[0] + ' failed: ' + error.message + '\n'); process.exitCode = 1; }
|
|
37
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');
|
|
38
66
|
process.stdout.write('Windows local login: craft-mcp login-task --setup|--remove --ide workbuddy [--host-config <absolute MCP config file>]\n');
|
|
39
67
|
process.stdout.write('Windows game preview: craft-mcp preview-task --setup|--remove --ide workbuddy [--host-config <absolute MCP config file>]\n');
|
|
40
|
-
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.\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.
|
|
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');
|
|
41
69
|
} else {
|
|
42
70
|
process.stderr.write('Unknown command or extra arguments. Use craft-mcp --help.\n');
|
|
43
71
|
process.exitCode = 1;
|
|
@@ -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
|
+
});
|
|
@@ -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},
|
|
@@ -4,13 +4,16 @@ 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 -->';
|
|
10
12
|
const end = '<!-- craft-mcp:project:end -->';
|
|
11
13
|
// Independent of engine bundle versions: generated recovery instructions evolve too.
|
|
12
|
-
export const entryPolicyVersion =
|
|
14
|
+
export const entryPolicyVersion = 15;
|
|
13
15
|
const hash = value => createHash('sha256').update(value).digest('hex');
|
|
16
|
+
const instanceGuide = '先读取已有的 `.craft/project-install.json`。若宿主暴露多组 Craft 工具,用各服务的只读 `craft_game_info` 核对工作区是当前项目父目录、平台和渠道符合清单,再按项目名核对绝对路径与引擎。记录唯一匹配的工具命名空间和 server_id;后续制作、上传、检查更新和重连核验沿用该服务。多个服务都匹配时请用户选定,缺少匹配时按项目接入指引处理。';
|
|
14
17
|
const turnUpdateGuide = '进入 Craft 工作流后,每条用户消息使用新的检查 key。同一轮调用支持 `update_request_key` 的业务工具时传这个 key,工具会顺带检查;本轮仅答疑、编辑本地文件或只用轮询等工具时,补一次只读 `craft_update_check`(request_key=本轮 key,已有工程传 name)。制作时,业务回执的 update_notice 或显式检查返回 update_available=true 且 automatic_update_enabled=true,就用同一 key 调用 `craft_update`(mode=auto,已有工程传 name)。纯查看只检查,未发现更新直接继续。同一目标版本待重连时只提示一次。';
|
|
15
18
|
const normalizeLines = value => value.replace(/\r\n/g,'\n');
|
|
16
19
|
const uploadGuide = '上传游戏、更新云端版本或发布时,使用 Craft MCP。纯上传用 `craft_game_check` 的 `purpose="upload"` 构建并冻结源码和 dist,安全检查通过后用 `craft_game_upload` 上传。更新原项目时先用 `craft_game_upload_status({name})` 核对云端绑定,上传传 `expected_appid`。收到 `draft_ready` 后报告版本、appid 和项目链接,由用户进入项目页提审。遇到阻塞时报告工具名和原始错误,改用 Computer Use、GM 或网页编辑器上传须另获用户同意。';
|
|
@@ -24,10 +27,10 @@ export function projectContextPaths(project, ide = 'generic', schema = 5) {
|
|
|
24
27
|
|
|
25
28
|
function recovery(name, engine) {
|
|
26
29
|
return `Craft 工程名:\`${name}\`;引擎:\`${engine}\`。保持已有引擎与用户源码。\n\n`
|
|
27
|
-
+ turnUpdateGuide + '\n\n'
|
|
30
|
+
+ instanceGuide + '\n\n' + turnUpdateGuide + '\n\n'
|
|
28
31
|
+ '先读 `SPEC/PROGRESS.md` 和已有的 SPEC 设计文件,核对已完成玩法、待办及最近验收;缺少记录时检查源码与工具回执,不根据旧聊天猜测。\n\n'
|
|
29
32
|
+ `继续本工程前调用 \`craft_game_info({"name":"${name}"})\`,核对返回的 project 是当前目录、context_binding.status 为 bound。读取返回的 \`context.workflow\`、\`context.engine.entrypoint\` 和 \`context.engine.skills_index\`;按索引 description 选择技能,相对于 context.engine.directory 读取 entrypoint,再按需读取引用。\n\n`
|
|
30
|
-
+ `MCP 的 workspace 是游戏父目录,工程位于 \`workspace/${name}
|
|
33
|
+
+ `MCP 的 workspace 是游戏父目录,工程位于 \`workspace/${name}\`,不自动跟随宿主当前目录。若不匹配,先通过项目接入检查确认正确连接,保留其他工作区及其工程。\n\n`
|
|
31
34
|
+ `迁移目录或首次恢复时若提示尚未 prepare,确认 workspace 后调用 \`craft_game_prepare({"name":"${name}","engine":"${engine}","mode":"resume","request_key":"resume-unique-key"})\` 并轮询任务完成;已有合法工程只会被接管,不重置模板。目录更名后使用当前目录名(须符合工具的英文 name 规则)。\n\n`
|
|
32
35
|
+ '项目以 `.craft/context-lock.json` 绑定引擎上下文版本,随项目保存;实际路径每次通过工具查询。缺少绑定时由 prepare 核验后建立,缺包或不兼容时按诊断恢复匹配版本,不删除锁文件来绕过检查。上下文、模板和技能脚本由 Craft 版本包提供,不复制到游戏中;MCP 未连接时先连接项目使用的 Craft 服务。\n\n'
|
|
33
36
|
+ '验收使用 `craft_game_check` → `craft_game_review` → `craft_game_deliver`;宿主按返回命令启动预览,再核对当前快照已运行。构建成功不代表预览自动开启。\n\n'
|
|
@@ -90,12 +93,13 @@ function mergeRuleMetadata(original,prefix) {
|
|
|
90
93
|
|
|
91
94
|
function projectConnectionGuide(host) {
|
|
92
95
|
const target = host === 'generic' ? '<当前宿主>' : host;
|
|
96
|
+
const npx = ['npx -y --registry "<registry>"', ...internalRegistryArgs(projectPackageName)].join(' ');
|
|
93
97
|
return '首次接手或切换 Agent 时,先通过当前宿主实际提供的工具发现能力查找 Craft 工具;工具可能延迟暴露或带命名空间前缀,不能因裸工具名不存在、resources 为空就判断未安装。项目文件和 Skill 可用也不代表 MCP 已连接。\n\n'
|
|
94
|
-
+ '
|
|
98
|
+
+ instanceGuide + ' 实际程序低于 minimum_mcp_version 时先处理版本要求。\n\n'
|
|
95
99
|
+ '若没有可用的 Craft 连接,读取 `.craft/project-install.json`,确认 package_name、minimum_mcp_version、registry、channel、platform 和 engine。使用当前宿主终端执行下面的项目接入检查,将占位值替换为文件中的值及当前游戏绝对目录,并按终端规则引用参数:\n\n'
|
|
96
|
-
+ '```text\
|
|
100
|
+
+ '```text\n'+npx+' "'+projectPackageName+'@<minimum_mcp_version>" project-setup --project "<当前游戏绝对目录>" --ide '+target+'\n```\n\n'
|
|
97
101
|
+ 'TRAE 和国际版 Qoder IDE 的接入命令需加 `--host-config "<宿主 MCP 设置界面打开的配置文件绝对路径>"`;不要猜测配置路径。TRAE CN 另加 `--trae-region cn`,国际版使用 global。已有安装检查、更新及恢复沿用相同路径和地区。\n\n'
|
|
98
|
-
+ '
|
|
102
|
+
+ '检查命令只读。返回 `instance_required` 或 `multiple_installations` 时请用户选定服务,以 `--instance <服务名>` 重新检查。仅返回 `missing_installation` 且用户正在请求继续制作时,在同一命令末尾加 `--install`;非 stable 渠道新装须由用户明确选择命名实例。所选包必须满足项目最低 MCP 版本;随后按已有更新策略检查渠道。安装包尚未发布或网络/终端权限不可用时报告准确原因;用户提供本地候选包时可用该包的同一 CLI,不降低项目版本。\n\n'
|
|
99
103
|
+ '已有配置被禁用、范围不匹配、旧版或连接失败时按检查结果修复,不当作缺失重复安装,不自行启用用户禁用的服务或覆盖其他工作区/平台。`--workspace` 必须是当前游戏父目录,不跟随默认目录。旧项目缺少安装信息时,先使用已连接且目录/平台明确的 Craft 完成 resume 以补齐;无可靠来源则询问缺失的平台/版本信息,不猜默认环境。\n\n'
|
|
100
104
|
+ '安装回执和 doctor 只证明配置及独立探测。等待宿主实际加载 Craft;需要时提示重连或重启,只有宿主提示信任/登录时由用户处理。连接后必须由当前会话调用 `craft_game_info`,核对实际 version/build_id、host、workspace、platform、project 和原引擎,标准安装确认 active_verified 后再 prepare(resume)。不要使用另一个终端探测代替当前会话验收,不重建已有工程。纯查看不安装或更新,打开文件夹本身不触发安装。\n\n';
|
|
101
105
|
}
|
|
@@ -120,7 +124,7 @@ function recoveryEntries(name, engine, ide = 'generic', isolated = false) {
|
|
|
120
124
|
+ start + '\n# 继续当前 Craft 游戏\n\n'
|
|
121
125
|
+ '首次接手先读根 AGENTS.md 的接入流程,确认当前宿主及项目安装信息;缺失 Craft MCP 时先检查、按需安装并核验当前会话连接,再调用下面的工具。不要因延迟工具尚未发现而误判未安装。\n\n'
|
|
122
126
|
+ (isolated ? '本入口适用于 '+host+',project-setup 使用 `--ide '+host+'`;当前 Agent 不属于该宿主时按根路由读取自身入口。\n\n' : '')
|
|
123
|
-
+ `1. 读取项目根 \`AGENTS.md\`,确认工程 \`${name}\` 和引擎 \`${engine}
|
|
127
|
+
+ `1. 读取项目根 \`AGENTS.md\`,确认工程 \`${name}\` 和引擎 \`${engine}\`。` + instanceGuide + '\n'
|
|
124
128
|
+ turnUpdateGuide + '\n\n'
|
|
125
129
|
+ (isolated ? '2. 当前连接仍持有本工程有效 work 时沿用 work_id/context_revision。新会话先调用只读 `craft_game_info` 核对项目和工作区。核对实际版本后,尚无有效 work 且可继续时调用 `craft_game_prepare`(mode=resume,同一 request_key)。轮询完成并保留 work_id/context_revision,重新读取本 Skill 相邻的 [引擎入口](../../AGENTS.md)、[恢复说明](../../recovery.md)、[工作流](../../workflow.md) 和 [技能索引](../index.json),按任务读取当前宿主 skills/ 下的正文。\n' : '2. 按根 AGENTS.md 查询 `craft_game_info`,读取返回的引擎入口、工作流与技能索引。\n')
|
|
126
130
|
+ (isolated ? ' 新版安装后等待下次 MCP 启动或用户重连。确认实际 version、build_id、active_verified 后,prepare(resume) 按游戏原引擎更新各已绑定宿主有变化的官方 Skill。完成后重新读取本宿主的索引和正文。\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) {
|
|
@@ -44,11 +51,13 @@ export async function readProjectInstall(project, { required = false } = {}) {
|
|
|
44
51
|
return manifest;
|
|
45
52
|
}
|
|
46
53
|
|
|
47
|
-
export function assertProjectInstallConnection(manifest, { engine, version, platform, registry, channel }) {
|
|
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');
|
|
51
59
|
if (registry !== undefined && httpsUrl(registry) !== manifest.registry) throw new Error('Project installation registry differs from the current Craft installation; preserve the project source and reconnect with its registry');
|
|
60
|
+
if (requireKnownChannel && !channel && manifest.channel !== 'stable') throw new Error('This project requires a verified Craft installation for its configured channel: ' + manifest.channel);
|
|
52
61
|
if (channel !== undefined && channel !== manifest.channel) throw new Error('Project installation channel differs from the current Craft installation; preserve the project source and reconnect with its channel');
|
|
53
62
|
}
|
|
54
63
|
|
|
@@ -56,8 +65,8 @@ export function assertProjectInstallConnection(manifest, { engine, version, plat
|
|
|
56
65
|
export async function planProjectInstall(project, options) {
|
|
57
66
|
const before = await snapshot(project), previous = before.manifest;
|
|
58
67
|
if (previous) assertProjectInstallConnection(previous, options);
|
|
59
|
-
const manifest = validateProjectInstall({ schema: 1, package_name:
|
|
60
|
-
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,
|
|
61
70
|
channel: options.channel ?? previous?.channel ?? 'stable', platform: options.platform, engine: options.engine });
|
|
62
71
|
return { manifest, previous, before: before.text, changed: JSON.stringify(manifest) !== JSON.stringify(previous) };
|
|
63
72
|
}
|
|
@@ -6,6 +6,7 @@ import { seedProjectTemplate } from '#craft-sdk';
|
|
|
6
6
|
import { atomicJson } from './request-store.mjs';
|
|
7
7
|
import { assetConfig, safeProjectFile } from './asset-import.mjs';
|
|
8
8
|
import { engineDefinition } from './engines.mjs';
|
|
9
|
+
import { verifyBundle } from './bundle-files.mjs';
|
|
9
10
|
import { prepareProjectContext, projectContextPaths } from './project-context.mjs';
|
|
10
11
|
import { clientIde } from '../integrations/hosts.mjs';
|
|
11
12
|
import { ProjectBundles, readContextLock, contextBinding, checkProjectCompatibility, planContextRelease, assertContextRelease } from './project-bundles.mjs';
|
|
@@ -46,6 +47,13 @@ async function readRecord(file, project) {
|
|
|
46
47
|
return record;
|
|
47
48
|
}
|
|
48
49
|
|
|
50
|
+
async function verifySourceBeforeUse(source) {
|
|
51
|
+
if (source.deferPayload) {
|
|
52
|
+
await verifyBundle(source.resources,source.engine,source.bundle.id);
|
|
53
|
+
source.deferPayload = false;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
49
57
|
export class Projects {
|
|
50
58
|
constructor(root, state, engines, ide = 'generic', installationProvider) {
|
|
51
59
|
this.root = root; this.state = path.join(state,'projects'); this.engines = engines; this.ide = clientIde(ide);
|
|
@@ -135,19 +143,21 @@ export class Projects {
|
|
|
135
143
|
signal?.throwIfAborted();
|
|
136
144
|
if (requestedEngine !== undefined) engineDefinition(requestedEngine);
|
|
137
145
|
const project = this.file(name);
|
|
146
|
+
const recordFile = path.join(this.state,name + '.json');
|
|
147
|
+
const record = await readRecord(recordFile,project);
|
|
148
|
+
if (record?.engine && requestedEngine && requestedEngine !== record.engine) throw new Error('Project engine is fixed to ' + record.engine + '; use a different name for another engine');
|
|
138
149
|
let created = false;
|
|
139
150
|
if(options.mode==='resume') await lstat(project);
|
|
140
151
|
else {
|
|
152
|
+
await verifySourceBeforeUse(this.engines[requestedEngine ?? record?.engine ?? 'js']);
|
|
141
153
|
try { await mkdir(project); created = true; }
|
|
142
154
|
catch (error) { if (error.code !== 'EEXIST') throw error; if(options.mode==='create') throw new Error('Project already exists; use mode=resume to continue it'); }
|
|
143
155
|
}
|
|
144
156
|
if (await realpath(project) !== project || (await lstat(project)).isSymbolicLink()) throw new Error('Project must not be a symbolic link');
|
|
145
|
-
const recordFile = path.join(this.state,name + '.json');
|
|
146
|
-
const record = await readRecord(recordFile,project);
|
|
147
|
-
if (record?.engine && requestedEngine && requestedEngine !== record.engine) throw new Error('Project engine is fixed to ' + record.engine + '; use a different name for another engine');
|
|
148
157
|
if (created) await seedProjectTemplate(this.engines[requestedEngine ?? record?.engine ?? 'js'].template,project,{ signal });
|
|
149
158
|
// Existing Craft games are adopted, never overwritten or silently converted from another engine.
|
|
150
159
|
const engine = await inspectProject(project,record?.engine ?? requestedEngine);
|
|
160
|
+
if (!created) await verifySourceBeforeUse(this.engines[engine]);
|
|
151
161
|
if(this.engines[engine].host) {
|
|
152
162
|
if(options.upgrade_context!==undefined && typeof options.upgrade_context!=='boolean') throw new Error('upgrade_context must be boolean');
|
|
153
163
|
if(options.context_bundle_id!==undefined && options.context_bundle_id!==this.engines[engine].bundle.id) throw new Error('Contexts follow the installed release; select the desired MCP release instead of pinning an older context');
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { parse, stringify } from 'smol-toml';
|
|
2
2
|
import { isDeepStrictEqual } from 'node:util';
|
|
3
|
-
import { readDshConfig, dshRegistrations, mergeDshConfig } from './dsh-config.mjs';
|
|
3
|
+
import { readDshConfig, dshRegistrations, mergeDshConfig, removeDshConfig } from './dsh-config.mjs';
|
|
4
4
|
import { hasCraftConnectionIdentity } from './registration-identity.mjs';
|
|
5
|
-
import { readJsonc, updateJsoncEntry } from './jsonc-config.mjs';
|
|
6
|
-
import { readOpenCodeConfig, openCodeConfig, openCodeRegistrations, mergeOpenCodeConfig } from './opencode-config.mjs';
|
|
5
|
+
import { readJsonc, updateJsonc, updateJsoncEntry } from './jsonc-config.mjs';
|
|
6
|
+
import { readOpenCodeConfig, openCodeConfig, openCodeRegistrations, mergeOpenCodeConfig, removeOpenCodeConfig } from './opencode-config.mjs';
|
|
7
|
+
import { validateServerId } from './instance.mjs';
|
|
7
8
|
|
|
8
9
|
function object(value) { return value !== null && typeof value === 'object' && !Array.isArray(value); }
|
|
9
10
|
function serverTable(config, ide) { return ide === 'zcode' ? config.mcp?.servers : config[ide === 'codex' ? 'mcp_servers' : 'mcpServers']; }
|
|
@@ -112,11 +113,37 @@ function sections(text) {
|
|
|
112
113
|
return found.map((section, i) => ({ ...section, end: found[i + 1]?.start ?? text.length }));
|
|
113
114
|
}
|
|
114
115
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
if (
|
|
116
|
+
function withoutTomlServer(text, before, previousName) {
|
|
117
|
+
const owned = sections(text).filter(({ keys }) => keys[0] === 'mcp_servers' && keys[1] === previousName);
|
|
118
|
+
if (before.mcp_servers?.[previousName] && !owned.length) throw new Error('Inline/dotted Craft TOML entry: move it to [mcp_servers.' + previousName + '] before editing; config was preserved');
|
|
119
|
+
let kept = '', from = 0;
|
|
120
|
+
for (const section of owned) { kept += text.slice(from, section.start); from = section.end; }
|
|
121
|
+
return kept + text.slice(from);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function removeConfig(text, ide, serverId = 'craft') {
|
|
125
|
+
validateServerId(serverId);
|
|
126
|
+
if (ide === 'dsh') return removeDshConfig(text, serverId);
|
|
127
|
+
if (ide === 'opencode') return removeOpenCodeConfig(text, serverId);
|
|
118
128
|
const before = readConfig(text, ide), servers = serverTable(before, ide);
|
|
119
|
-
if (
|
|
129
|
+
if (!servers || !Object.hasOwn(servers, serverId)) return text;
|
|
130
|
+
const remaining = { ...servers };
|
|
131
|
+
delete remaining[serverId];
|
|
132
|
+
const expected = withServerTable(before, ide, remaining);
|
|
133
|
+
if (ide === 'qwen') return updateJsonc(text, [{ path: ['mcpServers', serverId], value: undefined }]);
|
|
134
|
+
if (ide !== 'codex') return JSON.stringify(expected, null, 2) + '\n';
|
|
135
|
+
const output = withoutTomlServer(text, before, serverId);
|
|
136
|
+
if (!Object.keys(remaining).length && !parse(output).mcp_servers) delete expected.mcp_servers;
|
|
137
|
+
if (!isDeepStrictEqual(parse(output), parse(stringify(expected)))) throw new Error('TOML removal changed unrelated settings; config was preserved');
|
|
138
|
+
return output;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export function mergeConfig(text, ide, connection, { serverId = 'craft', previousName = serverId, enable = true } = {}) {
|
|
142
|
+
validateServerId(serverId);
|
|
143
|
+
if (ide === 'dsh') return mergeDshConfig(text, connection, { serverId, previousName, enable });
|
|
144
|
+
if (ide === 'opencode') return mergeOpenCodeConfig(text, connection, { serverId, previousName, enable });
|
|
145
|
+
const before = readConfig(text, ide), servers = serverTable(before, ide);
|
|
146
|
+
if (previousName !== serverId && servers?.[serverId]) throw new Error('Craft installation conflicts with an existing ' + serverId + ' registration');
|
|
120
147
|
const previous = servers?.[previousName] ?? {};
|
|
121
148
|
if (!object(previous)) throw new Error('Invalid craft server entry');
|
|
122
149
|
// Preserve host-specific options and user environment; replace only connection identity.
|
|
@@ -128,7 +155,7 @@ export function mergeConfig(text, ide, connection, { previousName = 'craft', ena
|
|
|
128
155
|
if (ide === 'claude') { delete next.enabled; delete next.timeoutMs; delete next.startupTimeoutMs; }
|
|
129
156
|
else {
|
|
130
157
|
next.enabled = true;
|
|
131
|
-
if (ide === 'zcode') { delete next.startupTimeoutMs; next = validateZcodeServer(next,
|
|
158
|
+
if (ide === 'zcode') { delete next.startupTimeoutMs; next = validateZcodeServer(next, serverId); }
|
|
132
159
|
else { delete next.type; delete next.timeoutMs; delete next.environment_id; next.transport = 'stdio'; next.executor = 'local'; }
|
|
133
160
|
}
|
|
134
161
|
} else if (['qwen', 'qoder', 'qoder-cn', 'comate', 'trae'].includes(ide)) {
|
|
@@ -140,22 +167,18 @@ export function mergeConfig(text, ide, connection, { previousName = 'craft', ena
|
|
|
140
167
|
if (Object.hasOwn(previous, key)) next[key] = previous[key]; else delete next[key];
|
|
141
168
|
}
|
|
142
169
|
const normalizedNext = ide === 'codex' ? parse(stringify({ value: next })).value : next;
|
|
143
|
-
if (previousName ===
|
|
144
|
-
const nextServers = { ...servers,
|
|
145
|
-
if (previousName !==
|
|
170
|
+
if (previousName === serverId && isDeepStrictEqual(previous, normalizedNext)) return text;
|
|
171
|
+
const nextServers = { ...servers, [serverId]: next };
|
|
172
|
+
if (previousName !== serverId) delete nextServers[previousName];
|
|
146
173
|
const expected = withServerTable(before, ide, nextServers);
|
|
147
174
|
if (ide === 'qwen') {
|
|
148
|
-
const output = updateJsoncEntry(text, ['mcpServers'],
|
|
175
|
+
const output = updateJsoncEntry(text, ['mcpServers'], serverId, servers?.[previousName], next, { previousName });
|
|
149
176
|
if (!isDeepStrictEqual(readConfig(output, ide), expected)) throw new Error('Qwen merge changed unrelated settings; config was preserved');
|
|
150
177
|
return output;
|
|
151
178
|
}
|
|
152
179
|
if (ide !== 'codex') return JSON.stringify(expected, null, 2) + '\n';
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
let kept = '', from = 0;
|
|
156
|
-
for (const section of owned) { kept += text.slice(from, section.start); from = section.end; }
|
|
157
|
-
kept += text.slice(from);
|
|
158
|
-
const output = kept + (kept.endsWith('\n') || !kept ? '' : '\n') + '\n' + stringify({ mcp_servers: { craft: next } });
|
|
180
|
+
const kept = withoutTomlServer(text, before, previousName);
|
|
181
|
+
const output = kept + (kept.endsWith('\n') || !kept ? '' : '\n') + '\n' + stringify({ mcp_servers: { [serverId]: next } });
|
|
159
182
|
// This also rejects unsupported inline parent tables without changing the user's file.
|
|
160
183
|
if (!isDeepStrictEqual(parse(output), parse(stringify(expected)))) throw new Error('TOML merge changed unrelated settings; config was preserved');
|
|
161
184
|
return output;
|
|
@@ -7,29 +7,38 @@ import { optionalFile } from './files.mjs';
|
|
|
7
7
|
import { readInstallation } from './installation-state.mjs';
|
|
8
8
|
import { verifyLauncher } from './fixed-launcher.mjs';
|
|
9
9
|
import { assertHostConfigScope } from './host-config-scope.mjs';
|
|
10
|
+
import { registrationsForInstance, validateServerId } from './instance.mjs';
|
|
11
|
+
import { assertDshSharedScope } from './dsh-config.mjs';
|
|
10
12
|
|
|
11
13
|
// Optional expert/connector declarations use this resolver, never a second
|
|
12
14
|
// installer or an unmanaged business runtime. No host settings are written.
|
|
13
|
-
export async function installedConnection(ide, { home = os.homedir(), codexHome = process.env.CODEX_HOME, hostOptions = hostEnvironment(), env = process.env } = {}) {
|
|
15
|
+
export async function installedConnection(ide, { home = os.homedir(), codexHome = process.env.CODEX_HOME, hostOptions = hostEnvironment(), env = process.env, serverId = 'craft' } = {}) {
|
|
16
|
+
validateServerId(serverId);
|
|
14
17
|
const targets = installTargets(ide);
|
|
15
18
|
if (targets.length !== 1) throw new Error('connect requires exactly one host');
|
|
16
|
-
const host = targets[0], paths = hostPaths(home, host, codexHome, hostOptions);
|
|
17
|
-
await assertHostConfigScope(paths.config,host,paths.configPeers);
|
|
19
|
+
const host = targets[0], paths = hostPaths(home, host, codexHome, { ...hostOptions, serverId });
|
|
20
|
+
await assertHostConfigScope(paths.config,host,paths.configPeers,serverId);
|
|
21
|
+
assertDshSharedScope(paths,serverId);
|
|
18
22
|
const registrations = craftRegistrations(await optionalFile(paths.config) ?? '', host);
|
|
19
|
-
|
|
20
|
-
|
|
23
|
+
const selected = registrationsForInstance(registrations, serverId);
|
|
24
|
+
if (selected.length > 1) throw new Error('Multiple Craft registrations match the selected instance: ' + serverId);
|
|
25
|
+
const connection = selected[0]?.connection;
|
|
26
|
+
if (!connection) throw new Error('Run craft-mcp install --ide ' + host + ' first; the selected Craft installation is missing: ' + serverId);
|
|
27
|
+
const file = connection.env?.CRAFT_INSTALLATION_FILE;
|
|
21
28
|
const state = await readInstallation(file);
|
|
22
|
-
if (state.host !== host ||
|
|
29
|
+
if (state.host !== host || state.server_id !== serverId || path.relative(state.config, paths.config) !== '' ||
|
|
30
|
+
(connection.env.CRAFT_SERVER_ID ?? 'craft') !== serverId) throw new Error('Craft installation belongs to another host or server scope');
|
|
23
31
|
if (connection.disabled === true || connection.enabled === false || connection.enable === false) throw new Error('Craft is disabled in the host; enable the existing installation first');
|
|
24
32
|
await verifyLauncher(state, file, connection);
|
|
25
|
-
for (const [key, expected] of Object.entries({ CRAFT_WEB_URL: state.platform, CLIENT_WORKSPACE_ROOT: state.workspace, CRAFT_CLIENT_IDE: host })) {
|
|
33
|
+
for (const [key, expected] of Object.entries({ CRAFT_WEB_URL: state.platform, CLIENT_WORKSPACE_ROOT: state.workspace, CRAFT_CLIENT_IDE: host, CRAFT_SERVER_ID: serverId })) {
|
|
34
|
+
if ((connection.env[key] ?? (key === 'CRAFT_SERVER_ID' ? 'craft' : undefined)) !== expected) throw new Error('Craft registration scope differs from its installation: ' + key);
|
|
26
35
|
if (env[key] && env[key] !== expected) throw new Error('Craft connector scope differs from the standard installation: ' + key);
|
|
27
36
|
}
|
|
28
37
|
return { command: process.execPath, args: [state.launcher.entry, '--workspace', state.workspace], env: { ...env, ...connection.env }, installation: file };
|
|
29
38
|
}
|
|
30
39
|
|
|
31
40
|
export async function connectInstalledHost(ide, options = {}) {
|
|
32
|
-
const connection = await installedConnection(ide, {hostOptions:hostCommandOptions({ide,...options})});
|
|
41
|
+
const connection = await installedConnection(ide, {serverId: options.instance, hostOptions:hostCommandOptions({ide,...options})});
|
|
33
42
|
const child = spawn(connection.command, connection.args, { env: connection.env, stdio: 'inherit', shell: false, windowsHide: true });
|
|
34
43
|
const stop = () => child.kill('SIGTERM');
|
|
35
44
|
process.once('SIGINT', stop); process.once('SIGTERM', stop);
|
|
@@ -41,7 +50,7 @@ export async function runConnectCommand(args) {
|
|
|
41
50
|
const options={};
|
|
42
51
|
for(let i=1;i<args.length;i+=2) {
|
|
43
52
|
const key=args[i]?.replace(/^--/,'');
|
|
44
|
-
if(!['--ide','--host-config','--trae-region'].includes(args[i]) || !args[i+1] || Object.hasOwn(options,key)) throw new Error('Use connect --ide <host> [--host-config ABS] [--trae-region global|cn]');
|
|
53
|
+
if(!['--ide','--instance','--host-config','--trae-region'].includes(args[i]) || !args[i+1] || Object.hasOwn(options,key)) throw new Error('Use connect --ide <host> [--instance <server-id>] [--host-config ABS] [--trae-region global|cn]');
|
|
45
54
|
options[key]=args[i+1];
|
|
46
55
|
}
|
|
47
56
|
await connectInstalledHost(options.ide,options);
|
|
@@ -1,36 +1,37 @@
|
|
|
1
1
|
// The MCP process cannot discover or invoke its parent's control plane. This
|
|
2
2
|
// contract is consumed by the host agent after the update response completes.
|
|
3
3
|
import { hostReloadProfile } from './host-reload.mjs';
|
|
4
|
-
export function connectionHandoff({ host, target, current, workspace, platform, serverId = 'craft', busy, intent = 'inspect', name, requestKey }) {
|
|
4
|
+
export function connectionHandoff({ host, target, current, workspace, platform, serverId = 'craft', channel, busy, intent = 'inspect', name, requestKey }) {
|
|
5
5
|
const readOnly = intent === 'inspect';
|
|
6
6
|
const idle = busy?.can_reconnect;
|
|
7
7
|
const profile = hostReloadProfile(host);
|
|
8
8
|
const state = readOnly ? 'inspect_only' : idle === false ? 'wait_for_idle' : idle === true ? 'ready' : 'check_current_connection';
|
|
9
|
-
const
|
|
9
|
+
const reconnectHint = serverId === 'craft' ? profile.fallback : profile.fallback.replace(/\bCraft\b/g, serverId);
|
|
10
|
+
const fallback = [reconnectHint, '只有页面实际提示未信任或授权时才由用户按提示确认;每次更新不一定需要重新信任。'];
|
|
10
11
|
const next = readOnly
|
|
11
12
|
? '本次仅检查版本,不安装、不重连。已安装新版将在下一次 MCP 启动或用户重连后生效。'
|
|
12
13
|
: idle === false
|
|
13
14
|
? '新版已安装,当前进程继续使用原版本。先完成活动任务、保存进度并 release;不要为更新中断工作。新版将在下次 MCP 启动或用户重连后加载。'
|
|
14
15
|
: '新版已安装,当前进程保持原版本。下一次 MCP 启动或用户重连后,通过当前聊天的 craft_game_info 核对实际 version、build_id、active_verified 与宿主范围;无需新建聊天。确认后 prepare(resume) 更新当前项目的上下文和 Skill,再重新读取入口与技能索引。不要主动重载宿主或把安装探测当作当前连接确认。';
|
|
15
16
|
return {
|
|
16
|
-
schema: 2, executor: 'host_agent', host, host_profile: profile, server_id: serverId, intent, state,
|
|
17
|
+
schema: 2, executor: 'host_agent', host, host_profile: { ...profile, fallback: reconnectHint }, server_id: serverId, channel, intent, state,
|
|
17
18
|
after_response: true,
|
|
18
19
|
automatic_reload: readOnly ? 'disabled_read_only' : 'user_requested_reconnect',
|
|
19
20
|
automatic_reload_attempts: 0,
|
|
20
21
|
strategy: ['wait_for_next_mcp_start_or_user_reconnect', 'verify_current_connection', 'prepare_current_project_context'],
|
|
21
22
|
capability_source: 'actual_host_tools', capability_availability: 'not_observable_from_mcp',
|
|
22
23
|
busy: busy ?? null, busy_scope: 'current_connection',
|
|
23
|
-
preflight: { tool: 'craft_game_info', require_idle: true, honor_host_control_scope: true, require_control_scope_idle: true,
|
|
24
|
+
preflight: { server_id: serverId, tool: 'craft_game_info', require_idle: true, honor_host_control_scope: true, require_control_scope_idle: true,
|
|
24
25
|
unknown_control_scope: 'manual_reconnect', if_already_verified: 'continue_without_reload' },
|
|
25
|
-
expected: { version: target?.version, build_id: target?.build_id, host, workspace, platform },
|
|
26
|
+
expected: { version: target?.version, build_id: target?.build_id, server_id: serverId, channel, host, workspace, platform },
|
|
26
27
|
...(current?.instance_id ? { previous_instance_id: current.instance_id } : {}),
|
|
27
|
-
verify: { tool: 'craft_game_info', arguments: name ? { name } : {}, scope: 'current_chat_connection',
|
|
28
|
-
required: ['version', 'runtime.version', 'runtime.build_id', 'runtime.instance_id', 'runtime.activation.status', 'host', 'workspace', 'platform'],
|
|
28
|
+
verify: { server_id: serverId, tool: 'craft_game_info', arguments: name ? { name } : {}, scope: 'current_chat_connection',
|
|
29
|
+
required: ['version', 'runtime.version', 'runtime.build_id', 'runtime.instance_id', 'runtime.activation.status', 'server_id', 'channel', 'host', 'workspace', 'platform'],
|
|
29
30
|
activation_status: 'active_verified', recheck_busy_before_reload: true,
|
|
30
31
|
after_reload: { max_reads: 10, interval_ms: 500, retry_transient_connection_errors: true, never_repeat_reload: true },
|
|
31
32
|
require_new_instance: Boolean(current?.instance_id && (current.version !== target?.version || current.build_id !== target?.build_id)),
|
|
32
33
|
independent_probe_is_not_confirmation: true },
|
|
33
34
|
retry: { ...(requestKey ? { request_key: requestKey } : {}), only_explicitly_unstarted_prepare: true, never_replay_paid_operations: true },
|
|
34
|
-
fallback, next,
|
|
35
|
+
fallback, next: serverId === 'craft' ? next : '本次操作及核验使用 ' + serverId + ' 的工具。' + next,
|
|
35
36
|
};
|
|
36
37
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export const distributionTargets = Object.freeze({
|
|
2
|
+
public: Object.freeze({ package: '@craft_eco/craft-mcp', registry: 'https://registry.npmjs.org/' }),
|
|
3
|
+
internal: Object.freeze({ package: '@tencent/craft-mcp', registry: 'https://mirrors.tencent.com/npm/' }),
|
|
4
|
+
});
|
|
5
|
+
|
|
6
|
+
// A project's @tencent:registry setting takes precedence over npx --registry.
|
|
7
|
+
export function internalRegistryArgs(packageName) {
|
|
8
|
+
return packageName === distributionTargets.internal.package ? ['--@tencent:registry=' + distributionTargets.internal.registry] : [];
|
|
9
|
+
}
|