@craft_eco/craft-mcp 0.1.5 → 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/engines/unreal/artifacts.mjs +7 -3
- package/dist-server/engines/unreal/check.mjs +56 -7
- package/dist-server/engines/unreal/export.mjs +3 -3
- package/dist-server/engines/unreal/external-environment.mjs +7 -1
- package/dist-server/engines/unreal/preview-project.mjs +2 -2
- package/dist-server/engines/unreal/project.mjs +44 -12
- 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 +19 -10
- 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/resources/targets/claude/unreal/target.json +6 -6
- package/resources/targets/claude/unreal/unreal/bundle.json +10 -10
- package/resources/targets/claude/unreal/unreal/context/web/knowledge/WebBuild.md +6 -6
- package/resources/targets/codebuddy/unreal/target.json +6 -6
- package/resources/targets/codebuddy/unreal/unreal/bundle.json +10 -10
- package/resources/targets/codebuddy/unreal/unreal/context/web/knowledge/WebBuild.md +9 -7
- package/resources/targets/codex/unreal/target.json +6 -6
- package/resources/targets/codex/unreal/unreal/bundle.json +10 -10
- package/resources/targets/codex/unreal/unreal/context/web/knowledge/WebBuild.md +9 -7
- package/resources/targets/comate/unreal/target.json +6 -6
- package/resources/targets/comate/unreal/unreal/bundle.json +10 -10
- package/resources/targets/comate/unreal/unreal/context/web/knowledge/WebBuild.md +6 -6
- package/resources/targets/cursor/unreal/target.json +6 -6
- package/resources/targets/cursor/unreal/unreal/bundle.json +10 -10
- package/resources/targets/cursor/unreal/unreal/context/web/knowledge/WebBuild.md +6 -6
- package/resources/targets/dsh/unreal/target.json +6 -6
- package/resources/targets/dsh/unreal/unreal/bundle.json +10 -10
- package/resources/targets/dsh/unreal/unreal/context/web/knowledge/WebBuild.md +6 -6
- package/resources/targets/index.json +28 -28
- package/resources/targets/kimi/unreal/target.json +6 -6
- package/resources/targets/kimi/unreal/unreal/bundle.json +10 -10
- package/resources/targets/kimi/unreal/unreal/context/web/knowledge/WebBuild.md +6 -6
- package/resources/targets/opencode/unreal/target.json +6 -6
- package/resources/targets/opencode/unreal/unreal/bundle.json +10 -10
- package/resources/targets/opencode/unreal/unreal/context/web/knowledge/WebBuild.md +6 -6
- package/resources/targets/qoder/unreal/target.json +6 -6
- package/resources/targets/qoder/unreal/unreal/bundle.json +10 -10
- package/resources/targets/qoder/unreal/unreal/context/web/knowledge/WebBuild.md +6 -6
- package/resources/targets/qoder-cn/unreal/target.json +6 -6
- package/resources/targets/qoder-cn/unreal/unreal/bundle.json +10 -10
- package/resources/targets/qoder-cn/unreal/unreal/context/web/knowledge/WebBuild.md +6 -6
- package/resources/targets/qwen/unreal/target.json +6 -6
- package/resources/targets/qwen/unreal/unreal/bundle.json +10 -10
- package/resources/targets/qwen/unreal/unreal/context/web/knowledge/WebBuild.md +6 -6
- package/resources/targets/trae/unreal/target.json +6 -6
- package/resources/targets/trae/unreal/unreal/bundle.json +10 -10
- package/resources/targets/trae/unreal/unreal/context/web/knowledge/WebBuild.md +6 -6
- package/resources/targets/workbuddy/unreal/target.json +6 -6
- package/resources/targets/workbuddy/unreal/unreal/bundle.json +11 -11
- package/resources/targets/workbuddy/unreal/unreal/context/web/knowledge/WebBuild.md +7 -11
- package/resources/targets/workbuddy/unreal/unreal/context/web/skills/unreal-verify/SKILL.md +1 -1
- package/resources/targets/zcode/unreal/target.json +6 -6
- package/resources/targets/zcode/unreal/unreal/bundle.json +10 -10
- package/resources/targets/zcode/unreal/unreal/context/web/knowledge/WebBuild.md +6 -6
- package/resources/templates/unreal/project/Config/DefaultWebPublisher.ini +27 -21
- package/resources/templates/unreal/project/Config/README.md +10 -1
- package/resources/templates/unreal/project/Plugins/WebPublisher/Source/WebPublisher/Private/WebPublisherModule.cpp +13 -0
- package/resources/templates/unreal/project/template.json +33 -33
- package/resources/unreal-websdk/Setup-WebSDK.ps1 +2 -1
- package/resources/unreal-websdk/WebSDK-Packages.ps1 +143 -33
- package/resources/unreal-websdk/websdk-release.json +1 -5
|
@@ -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') } : {}) };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { optionalFile } from './files.mjs';
|
|
3
|
+
import { registryOrigin, updateSource } from './installation-state.mjs';
|
|
4
|
+
import { compareVersions, requireForwardVersion } from './version-policy.mjs';
|
|
5
|
+
|
|
6
|
+
// npm exec can record the original package spec on its own cache entry. Never
|
|
7
|
+
// infer a channel from a resolved version, a cwd manifest or the npm default tag.
|
|
8
|
+
export async function npmInstallSelector(packageRoot, name, env = process.env) {
|
|
9
|
+
if (env.npm_command !== 'exec' || env.npm_lifecycle_event !== 'npx') return null;
|
|
10
|
+
const cache = path.resolve(packageRoot, ...name.split('/').map(() => '..'), '..');
|
|
11
|
+
if (path.basename(path.dirname(cache)) !== '_npx' ||
|
|
12
|
+
path.relative(cache, packageRoot) !== path.join('node_modules', ...name.split('/'))) return null;
|
|
13
|
+
const metadata = await optionalFile(path.join(cache, 'package.json'));
|
|
14
|
+
let specs;
|
|
15
|
+
try { specs = metadata && JSON.parse(metadata)._npx?.packages; }
|
|
16
|
+
catch (error) { if (error instanceof SyntaxError) return null; throw error; }
|
|
17
|
+
if (!Array.isArray(specs) || specs.length !== 1 || typeof specs[0] !== 'string') return null;
|
|
18
|
+
if (specs[0] === name) return { kind: 'bare' };
|
|
19
|
+
if (!specs[0].startsWith(name + '@')) return { kind: 'package' };
|
|
20
|
+
const tag = specs[0].slice(name.length + 1);
|
|
21
|
+
const isTag = /^[a-zA-Z][a-zA-Z0-9._-]*$/.test(tag) && !/^(?:v\d+(?:\.|$)|x(?:\.|$))/i.test(tag);
|
|
22
|
+
return isTag ? { kind: 'tag', tag } : { kind: 'package' };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function installSource(pkg, { registry, channel, selector }, state, legacy) {
|
|
26
|
+
const previous = state?.source ?? legacy;
|
|
27
|
+
const source = updateSource(pkg, { registry: registry ?? previous?.registry, channel: channel ?? previous?.channel }, state?.source);
|
|
28
|
+
const switching = Boolean(channel && previous?.channel && channel !== previous.channel);
|
|
29
|
+
// A pinned version or local archive remains the payload on a normal install.
|
|
30
|
+
// A bare/management reinstall instead resolves the user's existing channel.
|
|
31
|
+
const followTag = Boolean(channel && previous?.channel) || selector === 'tag' ||
|
|
32
|
+
(['bare', 'management'].includes(selector) && Boolean(channel || previous?.channel));
|
|
33
|
+
return { source, followTag, allowLower: switching && registryOrigin(previous.registry) === source.registry };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function checkInstallVersion(identity, plan, integrity) {
|
|
37
|
+
const previous = plan.previousRuntime;
|
|
38
|
+
if (previous && previous.version === identity.version && previous.origin?.kind === 'npm' &&
|
|
39
|
+
previous.origin.registry === plan.source.registry && integrity && previous.origin.integrity !== integrity) {
|
|
40
|
+
throw new Error('Craft same-version registry integrity changed; installation refused');
|
|
41
|
+
}
|
|
42
|
+
if (plan.allowLower && previous && compareVersions(identity.version, previous.version) < 0) return;
|
|
43
|
+
requireForwardVersion(identity, previous);
|
|
44
|
+
}
|