@craft_eco/craft-mcp 0.1.6 → 0.1.7
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 +8 -8
- package/bin/craft-mcp.mjs +28 -2
- package/dist-server/game-workflow/project-context.mjs +7 -6
- package/dist-server/game-workflow/project-install.mjs +2 -1
- 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/dsh-config.mjs +30 -14
- package/dist-server/integrations/files.mjs +3 -1
- 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-source.mjs +44 -0
- package/dist-server/integrations/install.mjs +183 -53
- 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 +1 -1
- 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 +46 -18
- package/dist-server/integrations/runtime.mjs +2 -1
- package/dist-server/integrations/uninstall.mjs +160 -0
- package/dist-server/integrations/updates.mjs +57 -28
- package/dist-server/launcher.mjs +18 -2
- package/dist-server/mcp/server.mjs +16 -8
- package/dist-server/mcp/update-session.mjs +34 -12
- package/dist-server/upstream/craft-aigc.mjs +11 -2
- package/dist-server/upstream/draft-audit.mjs +52 -6
- package/package.json +4 -3
- package/resources/craft-create/SKILL.md +2 -0
- package/resources/craft-update/SKILL.md +2 -0
package/README.md
CHANGED
|
@@ -8,18 +8,18 @@ Craft MCP 是面向支持本地 stdio MCP 的 AI IDE 的游戏制作服务,包
|
|
|
8
8
|
|
|
9
9
|
### 按宿主安装(推荐)
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
选择当前宿主;只有同时接入时才用逗号列出多个宿主。安装完整 MCP 程序包、固定启动入口及全局 craft-create、craft-update Skill,保留已有平台和工作区。
|
|
12
|
+
|
|
13
|
+
使用本次 guide 命令中的包选择器,将 guide 换为 install --ide <当前宿主>。正式安装使用 @stable。只有用户明确给出了其他渠道时,才沿用该标签并传同名 --channel;安装器为它创建独立的命名服务、工作区和 Skill。同一标签再次安装会复用自己的实例。明确指定版本时保留版本号。
|
|
12
14
|
|
|
13
15
|
```sh
|
|
14
|
-
#
|
|
15
|
-
npx --yes --registry=https://registry.npmjs.org/ @craft_eco/craft-mcp@
|
|
16
|
-
# 在 WorkBuddy 中安装
|
|
17
|
-
npx --yes --registry=https://registry.npmjs.org/ @craft_eco/craft-mcp@0.1.6 install --ide workbuddy
|
|
16
|
+
# 正式版,在 Codex 中安装
|
|
17
|
+
npx --yes --registry=https://registry.npmjs.org/ @craft_eco/craft-mcp@stable install --ide codex
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
其他宿主将 --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
|
|
20
|
+
其他宿主将 --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 和本包平台。安装不创建游戏、不修改信任权限。
|
|
21
21
|
|
|
22
|
-
Codex 配置 ~/.codex/config.toml(设置 CODEX_HOME 时使用其 config.toml),全局 Skill 在 ~/.agents/skills;WorkBuddy 配置 ~/.workbuddy/mcp.json,全局 Skill 在 ~/.workbuddy/skills。CodeBuddy 使用 ~/.codebuddy/.mcp.json 与 ~/.codebuddy/skills,已有旧 MCP
|
|
22
|
+
Codex 配置 ~/.codex/config.toml(设置 CODEX_HOME 时使用其 config.toml),全局 Skill 在 ~/.agents/skills;WorkBuddy 配置 ~/.workbuddy/mcp.json,全局 Skill 在 ~/.workbuddy/skills。CodeBuddy 使用 ~/.codebuddy/.mcp.json 与 ~/.codebuddy/skills,已有旧 MCP 配置按官方优先级沿用。安装或切换渠道后,在下次启动或重连时调用当前聊天的 craft_game_info,核对 server_id、update.source.channel、host、supported_engines、运行版本、build_id 和 active_verified。UE 指南中的 environment.status=not_checked 表示尚未请求 Web 诊断。doctor --ide <当前宿主> 仅验证独立探测和文件,不证明当前聊天已切版或发现 Skill。
|
|
23
23
|
|
|
24
24
|
Claude Code 使用 ~/.claude.json 与 ~/.claude/skills;DSH 使用 ~/.dsh/cordis.patch.yml 与 ~/.dsh/skills;ZCode 使用 ~/.zcode/cli/config.json 的 mcp.servers 和 ~/.zcode/skills;Kimi Code CLI 使用 ~/.kimi-code/mcp.json 与 ~/.kimi-code/skills。DSH 配置是 YAML 插件 patch,ZCode 不是 mcpServers。对应目录覆盖通过 CLAUDE_CONFIG_DIR、DSH_HOME、KIMI_CODE_HOME 指定。不要把不同宿主的配置格式互换。
|
|
25
25
|
|
|
@@ -32,7 +32,7 @@ Claude Code 使用 ~/.claude.json 与 ~/.claude/skills;DSH 使用 ~/.dsh/cordi
|
|
|
32
32
|
执行本包 guide,根据当前宿主调用上面的标准 install。十四种宿主使用同一安装流程,无需选择连接模式。当前进程不会因安装新版而切换版本;固定入口在下次启动时读取已安装目标。
|
|
33
33
|
|
|
34
34
|
```sh
|
|
35
|
-
npx --yes --registry=https://registry.npmjs.org/ @craft_eco/craft-mcp@
|
|
35
|
+
npx --yes --registry=https://registry.npmjs.org/ @craft_eco/craft-mcp@stable guide
|
|
36
36
|
```
|
|
37
37
|
|
|
38
38
|
专家和连接器只通过 connect --ide workbuddy 解析标准安装并启动同一受管入口,首次使用也须先执行标准 install。connect 不安装程序、不改宿主配置、不创建游戏;安装缺失、禁用或平台/工作区不一致时明确失败。不要用无参数 npx 直接启动业务包来替代标准安装。未适配宿主的原始 stdio 调试不包含自动更新和 Skill 安装。
|
package/bin/craft-mcp.mjs
CHANGED
|
@@ -14,7 +14,33 @@ 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
|
+
].join('\n');
|
|
36
|
+
} else if (selector?.kind === 'package') {
|
|
37
|
+
guide = guide.replaceAll(pkg.name + '@stable ', pkg.name + '@' + pkg.version + ' ');
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
process.stdout.write(guide);
|
|
41
|
+
} else if (args[0] === 'uninstall') {
|
|
42
|
+
try { const { runUninstallCommand } = await import('../dist-server/integrations/uninstall.mjs'); await runUninstallCommand(args); }
|
|
43
|
+
catch (error) { process.stderr.write('Craft uninstall failed: ' + error.message + '\n'); process.exitCode = 1; }
|
|
18
44
|
} else if (args[0] === 'connect') {
|
|
19
45
|
try { const { runConnectCommand } = await import('../dist-server/integrations/connect.mjs'); await runConnectCommand(args); }
|
|
20
46
|
catch (error) { process.stderr.write('Craft connect failed: ' + error.message + '\n'); process.exitCode = 1; }
|
|
@@ -37,7 +63,7 @@ if (args.length === 0 || (args.length === 2 && args[0] === '--workspace' && path
|
|
|
37
63
|
} else if (args.length === 1 && ['--help', '-h', 'help'].includes(args[0])) {
|
|
38
64
|
process.stdout.write('Windows local login: craft-mcp login-task --setup|--remove --ide workbuddy [--host-config <absolute MCP config file>]\n');
|
|
39
65
|
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
|
|
66
|
+
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
67
|
} else {
|
|
42
68
|
process.stderr.write('Unknown command or extra arguments. Use craft-mcp --help.\n');
|
|
43
69
|
process.exitCode = 1;
|
|
@@ -10,8 +10,9 @@ import { hosts, clientIde, projectSkillPath, hostRecoveryEntry } from '../integr
|
|
|
10
10
|
const start = '<!-- craft-mcp:project:start -->';
|
|
11
11
|
const end = '<!-- craft-mcp:project:end -->';
|
|
12
12
|
// Independent of engine bundle versions: generated recovery instructions evolve too.
|
|
13
|
-
export const entryPolicyVersion =
|
|
13
|
+
export const entryPolicyVersion = 17;
|
|
14
14
|
const hash = value => createHash('sha256').update(value).digest('hex');
|
|
15
|
+
const instanceGuide = '先读取已有的 `.craft/project-install.json`。若宿主暴露多组 Craft 工具,用各服务的只读 `craft_game_info` 核对工作区是当前项目父目录、平台和渠道符合清单,再按项目名核对绝对路径与引擎。记录唯一匹配的工具命名空间和 server_id;后续制作、上传、检查更新和重连核验沿用该服务。多个服务都匹配时请用户选定,缺少匹配时按项目接入指引处理。';
|
|
15
16
|
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)。纯查看只检查,未发现更新直接继续。同一目标版本待重连时只提示一次。';
|
|
16
17
|
const normalizeLines = value => value.replace(/\r\n/g,'\n');
|
|
17
18
|
const jsUploadGuide = '上传游戏、更新云端版本或发布时,使用 Craft MCP。纯上传用 `craft_game_check` 的 `purpose="upload"` 构建并冻结源码和 dist,安全检查通过后用 `craft_game_upload` 上传。更新原项目时先用 `craft_game_upload_status({name})` 核对云端绑定,上传传 `expected_appid`。收到 `draft_ready` 后报告版本、appid 和项目链接,由用户进入项目页提审。遇到阻塞时报告工具名和原始错误,改用 Computer Use、GM 或网页编辑器上传须另获用户同意。';
|
|
@@ -25,10 +26,10 @@ export function projectContextPaths(project, ide = 'generic', schema = 5) {
|
|
|
25
26
|
|
|
26
27
|
function recovery(name, engine) {
|
|
27
28
|
return `Craft 工程名:\`${name}\`;引擎:\`${engine}\`。保持已有引擎与用户源码。\n\n`
|
|
28
|
-
+ turnUpdateGuide + '\n\n'
|
|
29
|
+
+ instanceGuide + '\n\n' + turnUpdateGuide + '\n\n'
|
|
29
30
|
+ '先读 `SPEC/PROGRESS.md` 和已有的 SPEC 设计文件,核对已完成玩法、待办及最近验收;缺少记录时检查源码与工具回执,不根据旧聊天猜测。\n\n'
|
|
30
31
|
+ `继续本工程前调用 \`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`
|
|
31
|
-
+ `MCP 的 workspace 是游戏父目录,工程位于 \`workspace/${name}
|
|
32
|
+
+ `MCP 的 workspace 是游戏父目录,工程位于 \`workspace/${name}\`,不自动跟随宿主当前目录。若不匹配,先通过项目接入检查确认正确连接,保留其他工作区及其工程。\n\n`
|
|
32
33
|
+ `迁移目录或首次恢复时若提示尚未 prepare,确认 workspace 后调用 \`craft_game_prepare({"name":"${name}","engine":"${engine}","mode":"resume","request_key":"resume-unique-key"})\` 并轮询任务完成;已有合法工程只会被接管,不重置模板。目录更名后使用当前目录名(须符合工具的英文 name 规则)。\n\n`
|
|
33
34
|
+ '项目以 `.craft/context-lock.json` 绑定引擎上下文版本,随项目保存;实际路径每次通过工具查询。缺少绑定时由 prepare 核验后建立,缺包或不兼容时按诊断恢复匹配版本,不删除锁文件来绕过检查。上下文、模板和技能脚本由 Craft 版本包提供,不复制到游戏中;MCP 未连接时先连接项目使用的 Craft 服务。\n\n'
|
|
34
35
|
+ '验收使用 `craft_game_check` → `craft_game_review` → `craft_game_deliver`;宿主按返回命令启动预览,再核对当前快照已运行。构建成功不代表预览自动开启。\n\n'
|
|
@@ -92,11 +93,11 @@ function mergeRuleMetadata(original,prefix) {
|
|
|
92
93
|
function projectConnectionGuide(host) {
|
|
93
94
|
const target = host === 'generic' ? '<当前宿主>' : host;
|
|
94
95
|
return '首次接手或切换 Agent 时,先通过当前宿主实际提供的工具发现能力查找 Craft 工具;工具可能延迟暴露或带命名空间前缀,不能因裸工具名不存在、resources 为空就判断未安装。项目文件和 Skill 可用也不代表 MCP 已连接。\n\n'
|
|
95
|
-
+ '
|
|
96
|
+
+ instanceGuide + ' 实际程序低于 minimum_mcp_version 时先处理版本要求。\n\n'
|
|
96
97
|
+ '若没有可用的 Craft 连接,读取 `.craft/project-install.json`,确认 package_name、minimum_mcp_version、registry、channel、platform 和 engine。使用当前宿主终端执行下面的项目接入检查,将占位值替换为文件中的值及当前游戏绝对目录,并按终端规则引用参数:\n\n'
|
|
97
98
|
+ '```text\nnpx -y --registry "<registry>" "@craft_eco/craft-mcp@<minimum_mcp_version>" project-setup --project "<当前游戏绝对目录>" --ide '+target+'\n```\n\n'
|
|
98
99
|
+ 'TRAE 和国际版 Qoder IDE 的接入命令需加 `--host-config "<宿主 MCP 设置界面打开的配置文件绝对路径>"`;不要猜测配置路径。TRAE CN 另加 `--trae-region cn`,国际版使用 global。已有安装检查、更新及恢复沿用相同路径和地区。\n\n'
|
|
99
|
-
+ '
|
|
100
|
+
+ '检查命令只读。返回 `instance_required` 或 `multiple_installations` 时请用户选定服务,以 `--instance <服务名>` 重新检查。仅返回 `missing_installation` 且用户正在请求继续制作时,在同一命令末尾加 `--install`;非 stable 渠道新装须由用户明确选择命名实例。所选包必须满足项目最低 MCP 版本;随后按已有更新策略检查渠道。安装包尚未发布或网络/终端权限不可用时报告准确原因;用户提供本地候选包时可用该包的同一 CLI,不降低项目版本。\n\n'
|
|
100
101
|
+ '已有配置被禁用、范围不匹配、旧版或连接失败时按检查结果修复,不当作缺失重复安装,不自行启用用户禁用的服务或覆盖其他工作区/平台。`--workspace` 必须是当前游戏父目录,不跟随默认目录。旧项目缺少安装信息时,先使用已连接且目录/平台明确的 Craft 完成 resume 以补齐;无可靠来源则询问缺失的平台/版本信息,不猜默认环境。\n\n'
|
|
101
102
|
+ '安装回执和 doctor 只证明配置及独立探测。等待宿主实际加载 Craft;需要时提示重连或重启,只有宿主提示信任/登录时由用户处理。连接后必须由当前会话调用 `craft_game_info`,核对实际 version/build_id、host、workspace、platform、project 和原引擎,标准安装确认 active_verified 后再 prepare(resume)。不要使用另一个终端探测代替当前会话验收,不重建已有工程。纯查看不安装或更新,打开文件夹本身不触发安装。\n\n';
|
|
102
103
|
}
|
|
@@ -125,7 +126,7 @@ function recoveryEntries(name, engine, ide = 'generic', isolated = false) {
|
|
|
125
126
|
+ start + '\n# 继续当前 Craft 游戏\n\n'
|
|
126
127
|
+ '首次接手先读根 AGENTS.md 的接入流程,确认当前宿主及项目安装信息。若当前会话无法使用 Craft MCP,先运行只读 `project-setup` 检查。仅当用户要求继续制作且检查返回 `missing_installation` 时才安装 Craft MCP。核验当前会话的 Craft MCP 连接后,再调用下面的工具。不要因延迟工具尚未发现而误判未安装。\n\n'
|
|
127
128
|
+ (isolated ? '本入口适用于 '+host+',project-setup 使用 `--ide '+host+'`;当前 Agent 不属于该宿主时按根路由读取自身入口。\n\n' : '')
|
|
128
|
-
+ `1. 读取项目根 \`AGENTS.md\`,确认工程 \`${name}\` 和引擎 \`${engine}
|
|
129
|
+
+ `1. 读取项目根 \`AGENTS.md\`,确认工程 \`${name}\` 和引擎 \`${engine}\`。` + instanceGuide + '\n'
|
|
129
130
|
+ turnUpdateGuide + '\n\n'
|
|
130
131
|
+ (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')
|
|
131
132
|
+ (isolated ? ' 新版安装后等待下次 MCP 启动或用户重连。确认实际 version、build_id、active_verified 后,prepare(resume) 按游戏原引擎更新各已绑定宿主有变化的官方 Skill。完成后重新读取本宿主的索引和正文。\n' : '')
|
|
@@ -45,11 +45,12 @@ export async function readProjectInstall(project, { required = false } = {}) {
|
|
|
45
45
|
return manifest;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
export function assertProjectInstallConnection(manifest, { engine, version, platform, registry, channel }) {
|
|
48
|
+
export function assertProjectInstallConnection(manifest, { engine, version, platform, registry, channel, requireKnownChannel = false }) {
|
|
49
49
|
if (manifest.engine !== engine) throw new Error('Project installation engine differs from the existing game; keep its original engine');
|
|
50
50
|
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');
|
|
51
51
|
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');
|
|
52
52
|
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');
|
|
53
|
+
if (requireKnownChannel && !channel && manifest.channel !== 'stable') throw new Error('This project requires a verified Craft installation for its configured channel: ' + manifest.channel);
|
|
53
54
|
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');
|
|
54
55
|
}
|
|
55
56
|
|
|
@@ -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
|
}
|
|
@@ -3,6 +3,7 @@ import { readFileSync, readdirSync, lstatSync, realpathSync } from 'node:fs';
|
|
|
3
3
|
import { isDeepStrictEqual } from 'node:util';
|
|
4
4
|
import { isAlias, isMap, isSeq, parseDocument } from 'yaml';
|
|
5
5
|
import { hasCraftConnectionIdentity } from './registration-identity.mjs';
|
|
6
|
+
import { registrationsForInstance } from './instance.mjs';
|
|
6
7
|
|
|
7
8
|
const pluginName = '@deepseek-ai/dsh-mcp-client';
|
|
8
9
|
const pluginId = 'mcp-craft';
|
|
@@ -37,7 +38,7 @@ function hasDynamicNode(node) {
|
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
function candidates(document) {
|
|
40
|
-
const rows = [], identities = new Set(), allIds = new Map();
|
|
41
|
+
const rows = [], identities = new Set(), allNames = new Map(), allIds = new Map();
|
|
41
42
|
const values = document.toJS();
|
|
42
43
|
for (const [patchIndex, patch] of document.contents.items.entries()) {
|
|
43
44
|
if (!isMap(patch)) throw new Error('DSH patch entries must be YAML mappings');
|
|
@@ -48,6 +49,10 @@ function candidates(document) {
|
|
|
48
49
|
if (!isMap(node)) throw new Error('DSH plugin entries must be YAML mappings');
|
|
49
50
|
const value = insert ? values[patchIndex].insert[entryIndex] : values[patchIndex];
|
|
50
51
|
if (typeof value.id === 'string') allIds.set(value.id, (allIds.get(value.id) ?? 0) + 1);
|
|
52
|
+
if (value.name === pluginName && typeof value.config?.serverName === 'string') {
|
|
53
|
+
const name = value.config.serverName;
|
|
54
|
+
allNames.set(name, (allNames.get(name) ?? 0) + 1);
|
|
55
|
+
}
|
|
51
56
|
if (!isCraft(value)) continue;
|
|
52
57
|
if (!insert || patch.items.some(pair => pair.key?.value !== 'insert')) {
|
|
53
58
|
throw new Error('Ambiguous Craft DSH patch: use one complete insert registration without additional patch operations');
|
|
@@ -61,12 +66,12 @@ function candidates(document) {
|
|
|
61
66
|
if (value.disabled !== undefined && typeof value.disabled !== 'boolean') throw new Error('Craft DSH disabled must be a boolean');
|
|
62
67
|
if (identities.has(value.id)) throw new Error('Duplicate Craft DSH plugin id');
|
|
63
68
|
identities.add(value.id);
|
|
64
|
-
rows.push({ node, value });
|
|
69
|
+
rows.push({ node, value, patchIndex, insert, entryIndex });
|
|
65
70
|
}
|
|
66
71
|
}
|
|
67
|
-
if (rows.length > 1) throw new Error('Multiple Craft DSH registrations found; keep one registration before installing');
|
|
68
72
|
for (const { value } of rows) {
|
|
69
73
|
if (allIds.get(value.id) > 1) throw new Error('Ambiguous or duplicate Craft DSH plugin id');
|
|
74
|
+
if (allNames.get(value.config.serverName) > 1) throw new Error('Duplicate Craft DSH server name: ' + value.config.serverName);
|
|
70
75
|
}
|
|
71
76
|
// A later id-only patch could silently override or disable the inserted server.
|
|
72
77
|
for (const patch of document.contents.items) {
|
|
@@ -87,7 +92,7 @@ export function dshRegistrations(text) {
|
|
|
87
92
|
return candidates(documentFor(text)).map(({ value }) => ({ name: value.config.serverName, connection: connectionFor(value) }));
|
|
88
93
|
}
|
|
89
94
|
|
|
90
|
-
function connectionConfig(connection, previous = {}) {
|
|
95
|
+
function connectionConfig(connection, previous = {}, serverId) {
|
|
91
96
|
if (!isRecord(connection) || typeof connection.command !== 'string' || !connection.command.trim() ||
|
|
92
97
|
!Array.isArray(connection.args) || connection.args.some(arg => typeof arg !== 'string') ||
|
|
93
98
|
(connection.env !== undefined && (!isRecord(connection.env) || Object.values(connection.env).some(value => typeof value !== 'string')))) {
|
|
@@ -96,7 +101,7 @@ function connectionConfig(connection, previous = {}) {
|
|
|
96
101
|
if (previous.env !== undefined && (!isRecord(previous.env) || Object.values(previous.env).some(value => typeof value !== 'string'))) {
|
|
97
102
|
throw new Error('Invalid existing Craft DSH environment');
|
|
98
103
|
}
|
|
99
|
-
const next = { ...previous, ...connection, serverName:
|
|
104
|
+
const next = { ...previous, ...connection, serverName: serverId, transport: 'stdio', env: { ...previous.env, ...connection.env } };
|
|
100
105
|
next.startupTimeoutMs ??= connection.timeout ?? (connection.startup_timeout_sec ? connection.startup_timeout_sec * 1000 : 120000);
|
|
101
106
|
next.toolCallTimeoutMs ??= 3600000;
|
|
102
107
|
next.failOnStartupError ??= true;
|
|
@@ -105,14 +110,15 @@ function connectionConfig(connection, previous = {}) {
|
|
|
105
110
|
}
|
|
106
111
|
|
|
107
112
|
/** Merge a single owned stdio registration while retaining unrelated YAML nodes. */
|
|
108
|
-
export function mergeDshConfig(text, connection, {
|
|
113
|
+
export function mergeDshConfig(text, connection, { serverId = 'craft', previousName = serverId, enable = true } = {}) {
|
|
109
114
|
const document = documentFor(text), found = candidates(document);
|
|
110
115
|
const previous = found.find(row => row.value.config.serverName === previousName);
|
|
111
|
-
|
|
112
|
-
if (
|
|
113
|
-
|
|
116
|
+
const id = 'mcp-' + serverId;
|
|
117
|
+
if (found.some(row => row !== previous && (row.value.id === id || row.value.config.serverName === serverId))) throw new Error('Craft DSH installation conflicts with an existing registration');
|
|
118
|
+
if (!previous && previousName !== serverId) throw new Error('Previous Craft DSH registration was not found');
|
|
119
|
+
const config = connectionConfig(connection, previous?.value.config, serverId);
|
|
114
120
|
if (!previous) {
|
|
115
|
-
document.contents.items.push(document.createNode({ insert: [{ id
|
|
121
|
+
document.contents.items.push(document.createNode({ insert: [{ id, name: pluginName, config }] }));
|
|
116
122
|
} else {
|
|
117
123
|
const next = { ...previous.value, config };
|
|
118
124
|
if (enable && next.disabled === true) next.disabled = false;
|
|
@@ -134,13 +140,22 @@ export function mergeDshConfig(text, connection, { previousName = 'craft', enabl
|
|
|
134
140
|
}
|
|
135
141
|
document.contents.flow = false;
|
|
136
142
|
const output = document.toString({ lineWidth: 0 });
|
|
137
|
-
const written = dshRegistrations(output);
|
|
138
|
-
if (written
|
|
143
|
+
const written = dshRegistrations(output).find(row => row.name === serverId);
|
|
144
|
+
if (!written || !isDeepStrictEqual(written.connection, connectionFor({ config, disabled: !enable && previous?.value.disabled === true }))) {
|
|
139
145
|
throw new Error('Generated Craft DSH configuration failed validation');
|
|
140
146
|
}
|
|
141
147
|
return output;
|
|
142
148
|
}
|
|
143
149
|
|
|
150
|
+
export function removeDshConfig(text, serverId) {
|
|
151
|
+
const document = documentFor(text);
|
|
152
|
+
const row = candidates(document).find(entry => entry.value.config.serverName === serverId);
|
|
153
|
+
if (!row) return text;
|
|
154
|
+
if (row.insert.items.length === 1) document.contents.delete(row.patchIndex);
|
|
155
|
+
else row.insert.delete(row.entryIndex);
|
|
156
|
+
return document.toString({ lineWidth: 0 });
|
|
157
|
+
}
|
|
158
|
+
|
|
144
159
|
/** Read-only profile inventory; callers decide how to handle an existing scope. */
|
|
145
160
|
export function inspectDshProfiles(dshHome) {
|
|
146
161
|
const profiles = path.join(dshHome, 'profiles');
|
|
@@ -175,8 +190,9 @@ export function inspectDshProfiles(dshHome) {
|
|
|
175
190
|
}
|
|
176
191
|
|
|
177
192
|
/** Shared install/doctor/update guard; never move profile-owned registrations. */
|
|
178
|
-
export function assertDshSharedScope(paths) {
|
|
193
|
+
export function assertDshSharedScope(paths, serverId = 'craft') {
|
|
179
194
|
if (!paths.dshHome) return;
|
|
180
|
-
const profiles = inspectDshProfiles(paths.dshHome)
|
|
195
|
+
const profiles = inspectDshProfiles(paths.dshHome).filter(profile =>
|
|
196
|
+
profile.registrations.some(row => row.name === serverId) || registrationsForInstance(profile.registrations, serverId).length);
|
|
181
197
|
if (profiles.length) throw new Error('DSH already has a profile-scoped Craft registration: ' + profiles.map(profile => profile.path).join(', ') + '. Preserve it and resolve that registration before installing or checking the shared DSH_HOME configuration; a duplicate MCP was not created.');
|
|
182
198
|
}
|
|
@@ -40,7 +40,9 @@ export async function commitFiles(changes) {
|
|
|
40
40
|
const backup = change.file + '.craft-backup-' + randomUUID();
|
|
41
41
|
await writeFile(backup, change.before, { flag: 'wx', mode: 0o600 }); backups.push(backup);
|
|
42
42
|
}
|
|
43
|
-
|
|
43
|
+
if (change.after === null) await unlink(change.file);
|
|
44
|
+
else await replace(change.file, change.after);
|
|
45
|
+
committed.push(change);
|
|
44
46
|
}
|
|
45
47
|
} catch (error) {
|
|
46
48
|
for (const change of committed.reverse()) {
|
|
@@ -20,6 +20,7 @@ export async function planLauncher(installationFile, previous, packageRoot) {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export async function verifyLauncher(state, installationFile, connection) {
|
|
23
|
+
if (connection?.env && (connection.env.CRAFT_SERVER_ID ?? 'craft') !== state.server_id) throw new Error('Craft launcher instance differs from its registration');
|
|
23
24
|
if (!state.launcher) return { mode: 'legacy_versioned_entry' };
|
|
24
25
|
const expected = launcherPath(installationFile);
|
|
25
26
|
if (state.launcher.schema !== 1 || state.launcher.entry !== expected || !/^[a-f0-9]{64}$/.test(state.launcher.sha256 ?? '')) throw new Error('Invalid Craft fixed launcher identity');
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import {optionalFile,assertPlainPath} from './files.mjs';
|
|
3
|
-
import {craftRegistrations} from './config.mjs';
|
|
3
|
+
import {craftConfig,craftRegistrations} from './config.mjs';
|
|
4
|
+
import { registrationsForInstance } from './instance.mjs';
|
|
4
5
|
|
|
5
6
|
// OpenCode loads both user JSON and JSONC. Updating one file cannot silently
|
|
6
7
|
// ignore a Craft registration in the other, even if that declaration is disabled.
|
|
7
|
-
export async function assertHostConfigScope(config, host, peers = []) {
|
|
8
|
+
export async function assertHostConfigScope(config, host, peers = [], serverId = 'craft') {
|
|
8
9
|
if(host!=='opencode') return;
|
|
9
10
|
for(const peer of new Set([...peers,...['opencode.json','opencode.jsonc'].map(name=>path.join(path.dirname(config),name))])) {
|
|
10
11
|
if(typeof peer!=='string'||!path.isAbsolute(peer)) throw new Error('Invalid additional host configuration path');
|
|
11
12
|
if(path.resolve(peer)===path.resolve(config)) continue;
|
|
12
13
|
await assertPlainPath(peer);
|
|
13
14
|
const text=await optionalFile(peer);
|
|
14
|
-
if(text!==null && craftRegistrations(text,'opencode').length) throw new Error('OpenCode also loads a Craft registration from '+peer+'; preserve both files and consolidate the intended Craft registration before installing or updating');
|
|
15
|
+
if(text!==null && (craftConfig(text,'opencode',serverId) !== undefined || registrationsForInstance(craftRegistrations(text,'opencode'),serverId).length)) throw new Error('OpenCode also loads a Craft registration from '+peer+'; preserve both files and consolidate the intended Craft registration before installing or updating');
|
|
15
16
|
}
|
|
16
17
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { existsSync } from 'node:fs';
|
|
3
|
+
import { validateServerId } from './instance.mjs';
|
|
3
4
|
|
|
4
5
|
export const hosts = Object.freeze({
|
|
5
6
|
codex: { label: 'Codex', config: '.codex/config.toml', skills: '.agents/skills', projectSkills: '.agents/skills', format: 'toml' },
|
|
@@ -47,6 +48,7 @@ export function hostCommandOptions(options = {}, env = process.env) {
|
|
|
47
48
|
export function hostPaths(home, ide, codexHome, options = {}) {
|
|
48
49
|
const host = hosts[clientIde(ide)];
|
|
49
50
|
if (!host) throw new Error('Select a host before installing');
|
|
51
|
+
const serverId = validateServerId(options.serverId ?? 'craft');
|
|
50
52
|
if (codexHome && !path.isAbsolute(codexHome)) throw new Error('CODEX_HOME must be absolute');
|
|
51
53
|
let override = ide === 'claude' ? options.claudeConfigDir : ide === 'dsh' ? options.dshHome : ide === 'kimi' ? options.kimiCodeHome : ide === 'qwen' ? options.qwenHome : undefined;
|
|
52
54
|
if (ide === 'dsh' && typeof override === 'string') {
|
|
@@ -73,7 +75,7 @@ export function hostPaths(home, ide, codexHome, options = {}) {
|
|
|
73
75
|
? ['.codebuddy/.mcp.json','.codebuddy/mcp.json','.codebuddy.json'].map(file=>path.join(home,file)).find(file=>existsSync(file)) ?? path.join(home,host.config)
|
|
74
76
|
: ide === 'codex' && codexHome ? path.join(codexHome,'config.toml')
|
|
75
77
|
: override ? path.join(override, ({ claude: '.claude.json', dsh: 'cordis.patch.yml', kimi: 'mcp.json', qwen: 'settings.json' })[ide]) : path.join(home,host.config));
|
|
76
|
-
return { config, skill: path.join(skillsRoot, '
|
|
78
|
+
return { config, skill: path.join(skillsRoot, serverId + '-create', 'SKILL.md'), updateSkill: path.join(skillsRoot, serverId + '-update', 'SKILL.md'),
|
|
77
79
|
...(ide==='opencode'?{configPeers:[...new Set([path.join(opencodeRoot,'opencode.json'),path.join(opencodeRoot,'opencode.jsonc'),options.opencodeConfig].filter(file=>file&&path.resolve(file)!==path.resolve(config)))]}:{}),
|
|
78
80
|
...(ide === 'zcode' ? { fallbackConfig: path.join(home, '.agents/mcp.json') } : {}),
|
|
79
81
|
...(ide === 'dsh' ? { dshHome: override || path.join(home, '.dsh') } : {}) };
|