@craft_eco/craft-mcp 0.1.34-beta.2 → 0.1.34-beta.3
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 +4 -17
- package/bin/craft-mcp.mjs +28 -2
- package/dist-server/game-workflow/art-previews.mjs +71 -71
- package/dist-server/game-workflow/local-context.mjs +64 -64
- package/dist-server/game-workflow/project-art-previews.mjs +63 -63
- package/dist-server/game-workflow/project-context.mjs +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/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 +99 -33
- 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 +42 -24
- package/dist-server/launcher.mjs +18 -2
- package/dist-server/mcp/server.mjs +13 -5
- package/dist-server/mcp/update-session.mjs +9 -6
- package/package.json +4 -2
- package/resources/context-filter-report.json +1 -1
- package/resources/craft-create/SKILL.md +25 -23
- package/resources/craft-update/SKILL.md +27 -25
- package/resources/targets/claude/js/context-filter-report.json +1 -1
- package/resources/targets/claude/js3d/context-filter-report.json +1 -1
- package/resources/targets/codebuddy/js/context-filter-report.json +1 -1
- package/resources/targets/codebuddy/js3d/context-filter-report.json +1 -1
- package/resources/targets/codex/js/context-filter-report.json +1 -1
- package/resources/targets/codex/js3d/context-filter-report.json +1 -1
- package/resources/targets/comate/js/context-filter-report.json +1 -1
- package/resources/targets/comate/js3d/context-filter-report.json +1 -1
- package/resources/targets/cursor/js/context-filter-report.json +1 -1
- package/resources/targets/cursor/js3d/context-filter-report.json +1 -1
- package/resources/targets/dsh/js/context-filter-report.json +1 -1
- package/resources/targets/dsh/js3d/context-filter-report.json +1 -1
- package/resources/targets/kimi/js/context-filter-report.json +1 -1
- package/resources/targets/kimi/js3d/context-filter-report.json +1 -1
- package/resources/targets/opencode/js/context-filter-report.json +1 -1
- package/resources/targets/opencode/js3d/context-filter-report.json +1 -1
- package/resources/targets/qoder/js/context-filter-report.json +1 -1
- package/resources/targets/qoder/js3d/context-filter-report.json +1 -1
- package/resources/targets/qoder-cn/js/context-filter-report.json +1 -1
- package/resources/targets/qoder-cn/js3d/context-filter-report.json +1 -1
- package/resources/targets/qwen/js/context-filter-report.json +1 -1
- package/resources/targets/qwen/js3d/context-filter-report.json +1 -1
- package/resources/targets/trae/js/context-filter-report.json +1 -1
- package/resources/targets/trae/js3d/context-filter-report.json +1 -1
- package/resources/targets/workbuddy/js/context-filter-report.json +1 -1
- package/resources/targets/workbuddy/js3d/context-filter-report.json +1 -1
- package/resources/targets/zcode/js/context-filter-report.json +1 -1
- package/resources/targets/zcode/js3d/context-filter-report.json +1 -1
- package/vendor/craft-runtime/SOURCE.json +1 -1
|
@@ -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
|
}
|
|
@@ -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') } : {}) };
|