@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,6 +1,6 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import os from 'node:os';
|
|
3
|
-
import { readFile, mkdir } from 'node:fs/promises';
|
|
3
|
+
import { readFile, mkdir, realpath } from 'node:fs/promises';
|
|
4
4
|
import lockfile from 'proper-lockfile';
|
|
5
5
|
import { defaultProfileDataDir, getAppDataRoot } from '../core/app-paths.mjs';
|
|
6
6
|
import { hostPaths, hostCommandOptions, installTargets } from './hosts.mjs';
|
|
@@ -16,8 +16,50 @@ import { planLauncher, verifyLauncher } from './fixed-launcher.mjs';
|
|
|
16
16
|
import { prepareRuntimeCandidate, refreshRuntimeCandidate, publishRuntimeCandidate, disposeRuntimeCandidate } from './runtime-candidate.mjs';
|
|
17
17
|
import { sameInstallation, installationChanged } from './installation-transaction.mjs';
|
|
18
18
|
import { assertHostConfigScope } from './host-config-scope.mjs';
|
|
19
|
+
import { registrationsForInstance, serverIdForChannel, validateServerId } from './instance.mjs';
|
|
20
|
+
import { renderInstanceSkill } from './instance-skill.mjs';
|
|
19
21
|
|
|
20
22
|
const bootstrapMarker = '<!-- craft-mcp:bootstrap:v1 -->';
|
|
23
|
+
|
|
24
|
+
async function canonicalWorkspace(directory) {
|
|
25
|
+
try { return await realpath(directory); }
|
|
26
|
+
catch (error) {
|
|
27
|
+
const parent = path.dirname(directory);
|
|
28
|
+
if (error.code !== 'ENOENT' || parent === directory) throw error;
|
|
29
|
+
return path.join(await canonicalWorkspace(parent), path.basename(directory));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function checkSiblingWorkspaces(registrations, previousName, host, workspace) {
|
|
34
|
+
const siblings = registrations.filter(({ name, connection }) => name !== previousName &&
|
|
35
|
+
connection?.env?.CRAFT_INSTALLATION_FILE && connection.env.CRAFT_CLIENT_IDE === host);
|
|
36
|
+
if (!siblings.length) return;
|
|
37
|
+
const selected = await canonicalWorkspace(workspace);
|
|
38
|
+
for (const { name, connection } of siblings) {
|
|
39
|
+
const args = connection.args ?? [], index = args.indexOf('--workspace');
|
|
40
|
+
const roots = [connection.env.CLIENT_WORKSPACE_ROOT, index >= 0 ? args[index + 1] : undefined];
|
|
41
|
+
for (const root of new Set(roots.filter(value => typeof value === 'string' && path.isAbsolute(value)))) {
|
|
42
|
+
if (path.relative(selected, await canonicalWorkspace(root)) === '') {
|
|
43
|
+
throw new Error('Craft workspace already belongs to another instance in ' + host + ': ' + name + '. Select a separate game directory.');
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function checkInstanceBinding(state, host, paths, serverId, installationFile) {
|
|
50
|
+
if (state.host !== host || path.relative(state.config, paths.config) !== '' || state.server_id !== serverId) {
|
|
51
|
+
throw new Error('Craft installation state belongs to another host configuration or instance');
|
|
52
|
+
}
|
|
53
|
+
const expected = installationPath(path.dirname(installationFile), host, paths.config, serverId);
|
|
54
|
+
if (serverId !== 'craft' && (state.id !== expected.id || path.relative(installationFile, expected.file) !== '')) {
|
|
55
|
+
throw new Error('Craft instance installation path differs from its registration');
|
|
56
|
+
}
|
|
57
|
+
if (serverId !== 'craft' && state.skills && (path.relative(state.skills['craft-create'], paths.skill) !== '' ||
|
|
58
|
+
(state.skills['craft-update'] && path.relative(state.skills['craft-update'], paths.updateSkill) !== ''))) {
|
|
59
|
+
throw new Error('Craft installation Skill paths differ from the selected host configuration');
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
21
63
|
function legacyNpmSource(connection, packageName) {
|
|
22
64
|
const args = connection?.args ?? [];
|
|
23
65
|
const spec = args.find(value => typeof value === 'string' && (value === packageName || value.startsWith(packageName + '@')));
|
|
@@ -57,9 +99,10 @@ function hostRuntimeEnvironment(host, existing = {}) {
|
|
|
57
99
|
|
|
58
100
|
export async function installHosts({ ide, workspace, platform, packageRoot, home = os.homedir(), codexHome, hostOptions = {},
|
|
59
101
|
runtimeRoot = path.join(getAppDataRoot(), 'runtimes'), stateRoot = path.join(path.dirname(runtimeRoot), 'installations'),
|
|
60
|
-
registry, channel, updates, selector = 'package', onlyIfMissing = false, materialize = stageRuntime, probe = probeRuntime,
|
|
102
|
+
registry, channel, updates, serverId, selector = 'package', onlyIfMissing = false, materialize = stageRuntime, probe = probeRuntime,
|
|
61
103
|
lookup = queryRegistry, materializeRegistry = stageRegistryRuntime }) {
|
|
62
104
|
const targets = installTargets(ide);
|
|
105
|
+
const instance = validateServerId(serverId ?? 'craft');
|
|
63
106
|
if (hostOptions.configPath && targets.length !== 1) throw new Error('--host-config requires exactly one --ide');
|
|
64
107
|
if (workspace !== undefined && !path.isAbsolute(workspace)) throw new Error('--workspace must be absolute');
|
|
65
108
|
if (platform !== undefined) platform = platformOrigin(platform);
|
|
@@ -67,14 +110,14 @@ export async function installHosts({ ide, workspace, platform, packageRoot, home
|
|
|
67
110
|
if (updates !== undefined && !['auto', 'off'].includes(updates)) throw new Error('--updates must be auto or off');
|
|
68
111
|
const pkg = JSON.parse(await readFile(path.join(packageRoot, 'package.json'), 'utf8'));
|
|
69
112
|
await mkdir(runtimeRoot, { recursive: true });
|
|
70
|
-
const targetPaths = new Map(targets.map(host => [host, hostPaths(home, host, codexHome, hostOptions)]));
|
|
113
|
+
const targetPaths = new Map(targets.map(host => [host, hostPaths(home, host, codexHome, { ...hostOptions, serverId: instance })]));
|
|
71
114
|
async function readPlans() {
|
|
72
115
|
const plans = [];
|
|
73
116
|
for (const host of targets) {
|
|
74
117
|
const paths = targetPaths.get(host);
|
|
75
118
|
await assertPlainPath(paths.config); await assertPlainPath(paths.skill); await assertPlainPath(paths.updateSkill);
|
|
76
|
-
assertDshSharedScope(paths);
|
|
77
|
-
await assertHostConfigScope(paths.config,host,paths.configPeers);
|
|
119
|
+
assertDshSharedScope(paths, instance);
|
|
120
|
+
await assertHostConfigScope(paths.config,host,paths.configPeers,instance);
|
|
78
121
|
const original = await optionalFile(paths.config), existingSkill = await optionalFile(paths.skill);
|
|
79
122
|
let configInput = original ?? '', fallbackSnapshot;
|
|
80
123
|
if (paths.fallbackConfig) {
|
|
@@ -85,15 +128,24 @@ export async function installHosts({ ide, workspace, platform, packageRoot, home
|
|
|
85
128
|
}
|
|
86
129
|
const existingUpdateSkill = await optionalFile(paths.updateSkill);
|
|
87
130
|
if (existingSkill && !existingSkill.includes(bootstrapMarker)) throw new Error('User-owned craft-create Skill preserved; rename it before installing: ' + paths.skill);
|
|
88
|
-
const
|
|
131
|
+
const hostRegistrations = craftRegistrations(configInput, host);
|
|
132
|
+
const registrations = registrationsForInstance(hostRegistrations, instance);
|
|
133
|
+
if (instance !== 'craft' && craftConfig(configInput, host, instance) !== undefined && !registrations.some(entry => entry.name === instance)) {
|
|
134
|
+
throw new Error('The requested Craft instance name is already used by another registration: ' + instance);
|
|
135
|
+
}
|
|
89
136
|
if (onlyIfMissing && registrations.length) throw new Error(host + ': Craft was configured while project setup was running; preserve the registration and inspect it again');
|
|
90
137
|
if (registrations.length > 1) throw new Error(host + ': Multiple Craft registrations found; preserve separate environments and select one installation before updating');
|
|
91
|
-
const previousName = registrations[0]?.name ??
|
|
138
|
+
const previousName = registrations[0]?.name ?? instance, old = registrations[0]?.connection;
|
|
92
139
|
const legacySource = legacyNpmSource(old, pkg.name);
|
|
93
|
-
const statePath = installationPath(stateRoot, host, paths.config);
|
|
140
|
+
const statePath = installationPath(stateRoot, host, paths.config, instance);
|
|
94
141
|
const previousSnapshot = old?.env?.CRAFT_INSTALLATION_FILE ? await readInstallationSnapshot(old.env.CRAFT_INSTALLATION_FILE) : null;
|
|
95
142
|
const previousState = previousSnapshot?.state;
|
|
96
|
-
if (previousState
|
|
143
|
+
if (previousState) checkInstanceBinding(previousState, host, paths, instance, old.env.CRAFT_INSTALLATION_FILE);
|
|
144
|
+
if (instance !== 'craft' && previousState && path.relative(old.env.CRAFT_INSTALLATION_FILE, statePath.file) !== '') throw new Error('Craft instance installation root differs from its registration');
|
|
145
|
+
const previousChannel = previousState?.source.channel ?? legacySource?.channel;
|
|
146
|
+
if (serverId !== undefined && previousChannel && channel && previousChannel !== channel) {
|
|
147
|
+
throw new Error('Craft instance ' + instance + ' already tracks ' + previousChannel + '; preserve that installation and use a different instance for ' + channel);
|
|
148
|
+
}
|
|
97
149
|
const stateBefore = previousSnapshot && path.resolve(old.env.CRAFT_INSTALLATION_FILE) === path.resolve(statePath.file) ? previousSnapshot.text : await optionalFile(statePath.file);
|
|
98
150
|
let previousRuntime = previousState?.target;
|
|
99
151
|
if (!previousRuntime && old?.args?.[0] && path.isAbsolute(old.args[0])) {
|
|
@@ -106,10 +158,15 @@ export async function installHosts({ ide, workspace, platform, packageRoot, home
|
|
|
106
158
|
if (pinned) previousRuntime = { version: pinned.slice('@craft_eco/craft-mcp@'.length) };
|
|
107
159
|
}
|
|
108
160
|
const workspaceIndex = old?.args?.indexOf('--workspace') ?? -1;
|
|
109
|
-
const
|
|
161
|
+
const defaultGames = instance === 'craft' ? path.join(home, 'CraftGames') : path.join(home, 'CraftTestGames', instance);
|
|
162
|
+
const games = workspace ?? (workspaceIndex >= 0 ? old.args[workspaceIndex + 1] : old?.env?.CLIENT_WORKSPACE_ROOT) ?? defaultGames;
|
|
110
163
|
if (!path.isAbsolute(games)) throw new Error('Configured Craft workspace must be absolute');
|
|
164
|
+
await checkSiblingWorkspaces(hostRegistrations, previousName, host, path.resolve(games));
|
|
111
165
|
const origin = platformOrigin(platform ?? old?.env?.CRAFT_WEB_URL ?? pkg.craft?.platform);
|
|
112
|
-
|
|
166
|
+
// A bare npx bootstrap can come from npm's latest tag. For a new primary
|
|
167
|
+
// installation the product follows stable; a legacy installation keeps its channel.
|
|
168
|
+
const selectedChannel = channel ?? (serverId === 'craft' && selector === 'bare' && !previousChannel ? 'stable' : undefined);
|
|
169
|
+
const selection = installSource(pkg, { registry, channel: selectedChannel, selector }, previousState, legacySource);
|
|
113
170
|
plans.push({ host, paths, original, configInput, fallbackSnapshot, existingSkill, existingUpdateSkill, previousName, previousRuntime, previousState, legacySource, statePath, stateBefore, workspace: path.resolve(games), platform: origin, ...selection });
|
|
114
171
|
}
|
|
115
172
|
if (channel && plans.some(plan => plan.followTag)) {
|
|
@@ -125,8 +182,9 @@ export async function installHosts({ ide, workspace, platform, packageRoot, home
|
|
|
125
182
|
await assertPlainPath(file);
|
|
126
183
|
if (await optionalFile(file) !== expected) throw installationChanged('Craft host files changed while the candidate was prepared');
|
|
127
184
|
}
|
|
128
|
-
assertDshSharedScope(plan.paths);
|
|
129
|
-
await assertHostConfigScope(plan.paths.config,plan.host,plan.paths.configPeers);
|
|
185
|
+
assertDshSharedScope(plan.paths, instance);
|
|
186
|
+
await assertHostConfigScope(plan.paths.config,plan.host,plan.paths.configPeers,instance);
|
|
187
|
+
await checkSiblingWorkspaces(craftRegistrations(plan.configInput, plan.host), plan.previousName, plan.host, plan.workspace);
|
|
130
188
|
if (plan.fallbackSnapshot && await optionalFile(plan.fallbackSnapshot.file) !== plan.fallbackSnapshot.text) throw new Error('ZCode fallback MCP configuration changed during installation; retry without changing the fallback');
|
|
131
189
|
const text = await optionalFile(plan.statePath.file);
|
|
132
190
|
if (text !== plan.stateBefore) {
|
|
@@ -197,9 +255,9 @@ export async function installHosts({ ide, workspace, platform, packageRoot, home
|
|
|
197
255
|
checkInstallVersion(candidate.identity, plan, plan.integrity);
|
|
198
256
|
const old = craftConfig(plan.configInput, plan.host, plan.previousName);
|
|
199
257
|
const connection = { ...old, command: process.execPath, args: [candidate.identity.entry, '--workspace', plan.workspace],
|
|
200
|
-
env: { ...old?.env, ...hostRuntimeEnvironment(plan.host,old?.env), CRAFT_CLIENT_IDE: plan.host, CRAFT_WEB_URL: plan.platform, CLIENT_WORKSPACE_ROOT: plan.workspace,
|
|
258
|
+
env: { ...old?.env, ...hostRuntimeEnvironment(plan.host,old?.env), CRAFT_CLIENT_IDE: plan.host, CRAFT_SERVER_ID: instance, CRAFT_WEB_URL: plan.platform, CLIENT_WORKSPACE_ROOT: plan.workspace,
|
|
201
259
|
CRAFT_INSTALLATION_FILE: plan.statePath.file, CRAFT_RUNTIME_REVISION: candidate.identity.build_id }, ...hostConnectionOptions(plan.host) };
|
|
202
|
-
const expected = { version: candidate.identity.version, build_id: candidate.identity.build_id, host: plan.host, workspace: plan.workspace, platform: plan.platform };
|
|
260
|
+
const expected = { version: candidate.identity.version, build_id: candidate.identity.build_id, host: plan.host, serverId: instance, workspace: plan.workspace, platform: plan.platform };
|
|
203
261
|
const key = JSON.stringify({ connection, expected });
|
|
204
262
|
const verified = verifiedCache.get(key) ?? await probe(connection, expected);
|
|
205
263
|
if (verified.runtime?.activation_mode !== activationMode) throw new Error('Craft runtime requires a legacy frontend; install a next_mcp_start distribution');
|
|
@@ -210,7 +268,7 @@ export async function installHosts({ ide, workspace, platform, packageRoot, home
|
|
|
210
268
|
if (!sameRuntimeIdentity(await getRuntimeIdentity(candidate.identity.package_root), candidate.identity)) throw new Error('Craft candidate changed during verification; installation refused');
|
|
211
269
|
await refreshRuntimeCandidate(candidate);
|
|
212
270
|
}
|
|
213
|
-
const lockPaths = [...new Set(plans.flatMap(plan => [plan.statePath.file, craftConfig(plan.configInput, plan.host, plan.previousName)?.env?.CRAFT_INSTALLATION_FILE].filter(Boolean)).map(file => path.resolve(file)))].sort();
|
|
271
|
+
const lockPaths = [...new Set(plans.flatMap(plan => [plan.paths.config, plan.statePath.file, craftConfig(plan.configInput, plan.host, plan.previousName)?.env?.CRAFT_INSTALLATION_FILE].filter(Boolean)).map(file => path.resolve(file)))].sort();
|
|
214
272
|
for (const file of lockPaths) {
|
|
215
273
|
await assertPlainPath(file); await mkdir(path.dirname(file), { recursive: true });
|
|
216
274
|
stateLocks.push(await lockfile.lock(file, { realpath: false, stale: 120000, retries: 0 }));
|
|
@@ -232,14 +290,15 @@ export async function installHosts({ ide, workspace, platform, packageRoot, home
|
|
|
232
290
|
const origin = plan.integrity ? { kind:'npm', registry:source.registry, integrity:plan.integrity }
|
|
233
291
|
: identity.build_id === plan.previousRuntime?.build_id && plan.previousRuntime.origin?.registry === source.registry ? plan.previousRuntime.origin : undefined;
|
|
234
292
|
const target = origin ? { ...identity, origin } : identity;
|
|
235
|
-
const
|
|
293
|
+
const desiredSkill = renderInstanceSkill(candidate.createSkill, 'craft-create', instance);
|
|
294
|
+
const desiredUpdateSkill = candidate.updateSkill === null ? null : renderInstanceSkill(candidate.updateSkill, 'craft-update', instance);
|
|
236
295
|
const migration = plan.previousState?.migration ?? (plan.legacySource ? { from_server: plan.previousName, ...plan.legacySource } : undefined);
|
|
237
296
|
const launcherPlan = await planLauncher(plan.statePath.file, plan.previousState?.launcher, identity.package_root);
|
|
238
297
|
const loginDir = plan.host === 'workbuddy' && process.platform === 'win32'
|
|
239
298
|
? craftConfig(plan.configInput, plan.host, plan.previousName)?.env?.CLIENT_DATA_DIR || process.env.CLIENT_DATA_DIR || defaultProfileDataDir(plan.workspace, plan.platform)
|
|
240
299
|
: undefined;
|
|
241
300
|
if (loginDir && !path.isAbsolute(loginDir)) throw new Error('WorkBuddy CLIENT_DATA_DIR must be absolute');
|
|
242
|
-
const state = { schema: 2, activation_mode: activationMode, id: plan.statePath.id, host: plan.host, server_id:
|
|
301
|
+
const state = { schema: 2, activation_mode: activationMode, id: plan.statePath.id, host: plan.host, server_id: instance, config: plan.paths.config,
|
|
243
302
|
launcher: launcherPlan.launcher,
|
|
244
303
|
...(loginDir ? {login_data_dir: path.resolve(loginDir)} : {}),
|
|
245
304
|
workspace: plan.workspace, platform: plan.platform, runtime_root: runtimeRoot, source,
|
|
@@ -254,13 +313,13 @@ export async function installHosts({ ide, workspace, platform, packageRoot, home
|
|
|
254
313
|
const same = priorComparable && JSON.stringify(priorComparable) === JSON.stringify(state);
|
|
255
314
|
const desiredState = same ? plan.previousState : { ...state, updated_at: new Date().toISOString() };
|
|
256
315
|
const connection = { command: process.execPath, args: [launcherPlan.launcher.entry, '--workspace', plan.workspace],
|
|
257
|
-
env: { ...hostRuntimeEnvironment(plan.host,craftConfig(plan.configInput,plan.host,plan.previousName)?.env), CRAFT_CLIENT_IDE: plan.host, CRAFT_WEB_URL: plan.platform, CLIENT_WORKSPACE_ROOT: plan.workspace, CRAFT_INSTALLATION_FILE: plan.statePath.file, CRAFT_RUNTIME_REVISION: identity.build_id },
|
|
316
|
+
env: { ...hostRuntimeEnvironment(plan.host,craftConfig(plan.configInput,plan.host,plan.previousName)?.env), CRAFT_CLIENT_IDE: plan.host, CRAFT_SERVER_ID: instance, CRAFT_WEB_URL: plan.platform, CLIENT_WORKSPACE_ROOT: plan.workspace, CRAFT_INSTALLATION_FILE: plan.statePath.file, CRAFT_RUNTIME_REVISION: identity.build_id },
|
|
258
317
|
...hostConnectionOptions(plan.host) };
|
|
259
318
|
const configured = craftConfig(plan.configInput, plan.host, plan.previousName);
|
|
260
319
|
// Some hosts omit an enabled flag when saving their configuration. Do not
|
|
261
320
|
// reinsert defaults into an already enabled registration.
|
|
262
321
|
const alreadyEnabled = configured && configured.disabled !== true && configured.enabled !== false && configured.enable !== false;
|
|
263
|
-
const updated = mergeConfig(plan.configInput, plan.host, connection, { previousName: plan.previousName, enable: !alreadyEnabled });
|
|
322
|
+
const updated = mergeConfig(plan.configInput, plan.host, connection, { serverId: instance, previousName: plan.previousName, enable: !alreadyEnabled });
|
|
264
323
|
const verified = verifiedByHost.get(plan.host);
|
|
265
324
|
changes.push({ file: plan.paths.skill, before: plan.existingSkill, after: desiredSkill });
|
|
266
325
|
if (plan.writeUpdateSkill) changes.push({ file: plan.paths.updateSkill, before: plan.existingUpdateSkill, after: desiredUpdateSkill });
|
|
@@ -268,9 +327,9 @@ export async function installHosts({ ide, workspace, platform, packageRoot, home
|
|
|
268
327
|
// managed entrypoints available before exposing the new launch command.
|
|
269
328
|
changes.push(launcherPlan.change, { file: plan.statePath.file, before: plan.stateBefore, after: same ? plan.stateBefore : JSON.stringify(desiredState, null, 2) + '\n' },
|
|
270
329
|
{ file: plan.paths.config, before: plan.original, after: updated });
|
|
271
|
-
results.push({ host: plan.host, ...plan.paths, installation: plan.statePath.file, launcher: state.launcher, source, policy: state.policy, ...(migration ? { migration } : {}), ...(plan.previousName !==
|
|
330
|
+
results.push({ host: plan.host, server_id: instance, ...plan.paths, installation: plan.statePath.file, launcher: state.launcher, source, policy: state.policy, ...(migration ? { migration } : {}), ...(plan.previousName !== instance ? { migrated_from: plan.previousName } : {}), ...(plan.fallbackSnapshot ? { imported_from: plan.fallbackSnapshot.file } : {}), verified,
|
|
272
331
|
activation_mode: activationMode, reconnect_required: true, activation: { status: 'pending_connection_verification', expected: identity },
|
|
273
|
-
connection_handoff: connectionHandoff({host:plan.host,target:identity,workspace:plan.workspace,platform:plan.platform,intent:'install'}) });
|
|
332
|
+
connection_handoff: connectionHandoff({host:plan.host,serverId:instance,channel:source.channel,target:identity,workspace:plan.workspace,platform:plan.platform,intent:'install'}) });
|
|
274
333
|
}
|
|
275
334
|
const written = await commitFiles(changes);
|
|
276
335
|
return { ...(published.size === 1 ? {runtime:published.values().next().value} : {runtimes:[...published.values()]}), hosts: results, ...written,
|
|
@@ -307,7 +366,7 @@ async function verifyInstalledSkills(installation, paths, connection, snapshot)
|
|
|
307
366
|
let matches = true;
|
|
308
367
|
for (const { name, marker } of entries) {
|
|
309
368
|
const expected = await optionalFile(path.join(candidate.package_root, 'resources', name, 'SKILL.md'));
|
|
310
|
-
if (!expected?.includes(marker) || contents.get(name) !== expected) { matches = false; break; }
|
|
369
|
+
if (!expected?.includes(marker) || contents.get(name) !== renderInstanceSkill(expected, name, installation?.server_id ?? 'craft')) { matches = false; break; }
|
|
311
370
|
}
|
|
312
371
|
if (matches) return { status: 'verified', runtime: skillRuntimeIdentity(candidate), managed: entries.map(entry => entry.name) };
|
|
313
372
|
}
|
|
@@ -317,18 +376,20 @@ async function verifyInstalledSkills(installation, paths, connection, snapshot)
|
|
|
317
376
|
throw new Error('Craft managed Skills differ from the recorded installed Skill runtime; run install again');
|
|
318
377
|
}
|
|
319
378
|
|
|
320
|
-
export async function doctorHosts({ ide, home = os.homedir(), codexHome, hostOptions = {}, probe = probeRuntime }) {
|
|
379
|
+
export async function doctorHosts({ ide, home = os.homedir(), codexHome, hostOptions = {}, serverId = 'craft', probe = probeRuntime }) {
|
|
380
|
+
validateServerId(serverId);
|
|
321
381
|
const results = [];
|
|
322
382
|
for (const host of installTargets(ide)) {
|
|
323
383
|
for (let attempt = 0; attempt < 4; attempt++) {
|
|
324
384
|
try {
|
|
325
|
-
const paths = hostPaths(home, host, codexHome, hostOptions);
|
|
326
|
-
await assertHostConfigScope(paths.config,host,paths.configPeers);
|
|
385
|
+
const paths = hostPaths(home, host, codexHome, { ...hostOptions, serverId });
|
|
386
|
+
await assertHostConfigScope(paths.config,host,paths.configPeers,serverId);
|
|
327
387
|
await assertPlainPath(paths.config);
|
|
328
|
-
assertDshSharedScope(paths);
|
|
388
|
+
assertDshSharedScope(paths,serverId);
|
|
329
389
|
const configText = await optionalFile(paths.config) ?? '';
|
|
330
|
-
const connection = craftConfig(configText, host);
|
|
390
|
+
const connection = craftConfig(configText, host, serverId);
|
|
331
391
|
if (!connection?.command || connection.env?.CRAFT_CLIENT_IDE !== host) throw new Error(host + ': Craft installation missing or host marker incorrect; run install --ide ' + host);
|
|
392
|
+
if ((connection.env.CRAFT_SERVER_ID ?? 'craft') !== serverId) throw new Error('Craft instance marker differs from its registration: ' + serverId);
|
|
332
393
|
if (connection.disabled === true || connection.enabled === false || connection.enable === false) throw new Error(host + ': Craft MCP is disabled');
|
|
333
394
|
let installation = null, skillsVerification, verificationError;
|
|
334
395
|
const file = connection.env.CRAFT_INSTALLATION_FILE, skillSnapshots = new Map();
|
|
@@ -337,6 +398,7 @@ export async function doctorHosts({ ide, home = os.homedir(), codexHome, hostOpt
|
|
|
337
398
|
try {
|
|
338
399
|
if (await optionalFile(paths.config) !== configText) throw installationChanged();
|
|
339
400
|
installation = await readInstallation(file);
|
|
401
|
+
checkInstanceBinding(installation, host, paths, serverId, file);
|
|
340
402
|
const entries = installation.skills ? installedSkillEntries(installation) : [{ file: paths.skill }];
|
|
341
403
|
for (const entry of entries) {
|
|
342
404
|
await assertPlainPath(entry.file);
|
|
@@ -368,13 +430,13 @@ export async function doctorHosts({ ide, home = os.homedir(), codexHome, hostOpt
|
|
|
368
430
|
const skillsPending = Boolean(installation && skillsVerification.runtime?.build_id !== installation.target.build_id);
|
|
369
431
|
const checkConnection = installation && !installation.launcher ? { ...connection, args: [installation.target.entry, '--workspace', installation.workspace] } : connection;
|
|
370
432
|
let verified, probeError;
|
|
371
|
-
try { verified = await probe(checkConnection, { host, ...(installation ? { version: installation.target.version, build_id: installation.target.build_id, workspace: installation.workspace, platform: installation.platform } : {}) }); }
|
|
433
|
+
try { verified = await probe(checkConnection, { host, serverId, ...(installation ? { version: installation.target.version, build_id: installation.target.build_id, workspace: installation.workspace, platform: installation.platform } : {}) }); }
|
|
372
434
|
catch (error) { probeError = error; }
|
|
373
435
|
// The launcher may observe a newer target while a diagnostic probe is
|
|
374
436
|
// starting. Re-read all scope/config fields on the next bounded attempt.
|
|
375
437
|
await stableSnapshot();
|
|
376
438
|
if (probeError) throw probeError;
|
|
377
|
-
results.push({ host, ...paths, entry: connection.args[0], target: installation?.target, skills_pending_activation: skillsPending, skills_verification: skillsVerification, verified });
|
|
439
|
+
results.push({ host, server_id: serverId, ...paths, entry: connection.args[0], target: installation?.target, skills_pending_activation: skillsPending, skills_verification: skillsVerification, verified });
|
|
378
440
|
break;
|
|
379
441
|
} catch (error) {
|
|
380
442
|
if (!['ELOCKED', 'INSTALLATION_CHANGED'].includes(error.code) || attempt === 3) throw error;
|
|
@@ -394,19 +456,20 @@ export async function installWithLoginTask(options) {
|
|
|
394
456
|
if (process.platform === 'win32') {
|
|
395
457
|
const workbuddy = result.hosts.find(host => host.host === 'workbuddy');
|
|
396
458
|
if (workbuddy) {
|
|
459
|
+
const instanceOption = workbuddy.server_id === 'craft' ? '' : ' --instance ' + workbuddy.server_id;
|
|
397
460
|
try {
|
|
398
461
|
const { ensureWorkBuddyLoginTask } = await import('./workbuddy-login-task.mjs');
|
|
399
462
|
workbuddy.login_task = await ensureWorkBuddyLoginTask(workbuddy.installation);
|
|
400
463
|
} catch (error) {
|
|
401
464
|
workbuddy.login_task = {status: 'unavailable', reason: error.message,
|
|
402
|
-
next: 'Windows local-page login requires the on-demand task.
|
|
465
|
+
next: 'Windows local-page login requires the on-demand task. Run login-task --setup --ide workbuddy' + instanceOption + ' after resolving the reported error.'};
|
|
403
466
|
}
|
|
404
467
|
try {
|
|
405
468
|
const { ensureWorkBuddyPreviewTask } = await import('./workbuddy-login-task.mjs');
|
|
406
469
|
workbuddy.preview_task = await ensureWorkBuddyPreviewTask(workbuddy.installation);
|
|
407
470
|
} catch (error) {
|
|
408
471
|
workbuddy.preview_task = {status:'unavailable',reason:error.message,
|
|
409
|
-
next:'Windows WorkBuddy preview requires the on-demand task. Run preview-task --setup --ide workbuddy after resolving the reported error.'};
|
|
472
|
+
next:'Windows WorkBuddy preview requires the on-demand task. Run preview-task --setup --ide workbuddy' + instanceOption + ' after resolving the reported error.'};
|
|
410
473
|
}
|
|
411
474
|
}
|
|
412
475
|
}
|
|
@@ -417,7 +480,7 @@ export async function runIntegrationCommand(args, packageRoot) {
|
|
|
417
480
|
const [command, ...rest] = args, options = {};
|
|
418
481
|
for (let i = 0; i < rest.length; i += 2) {
|
|
419
482
|
const name = rest[i].replace(/^--/, '');
|
|
420
|
-
if (!rest[i].startsWith('--') || !['ide', 'host-config', 'trae-region', ...(command === 'install' ? ['workspace', 'platform', 'registry', 'channel', 'updates'] : [])].includes(name) || !rest[i + 1] || Object.hasOwn(options, name)) throw new Error('Invalid or repeated option. Use craft-mcp --help.');
|
|
483
|
+
if (!rest[i].startsWith('--') || !['ide', 'instance', 'host-config', 'trae-region', ...(command === 'install' ? ['workspace', 'platform', 'registry', 'channel', 'updates'] : [])].includes(name) || !rest[i + 1] || Object.hasOwn(options, name)) throw new Error('Invalid or repeated option. Use craft-mcp --help.');
|
|
421
484
|
options[name] = rest[i + 1];
|
|
422
485
|
}
|
|
423
486
|
options.codexHome = process.env.CODEX_HOME;
|
|
@@ -427,7 +490,10 @@ export async function runIntegrationCommand(args, packageRoot) {
|
|
|
427
490
|
const request = await npmInstallSelector(packageRoot, name);
|
|
428
491
|
options.selector = request?.kind ?? 'management';
|
|
429
492
|
options.channel ??= request?.tag;
|
|
493
|
+
if (options.channel === 'latest') options.channel = 'stable';
|
|
430
494
|
}
|
|
495
|
+
options.serverId = validateServerId(options.instance ?? serverIdForChannel(options.channel));
|
|
496
|
+
if (command === 'install' && options.serverId === 'craft' && options.channel && options.channel !== 'stable') throw new Error('The craft instance tracks stable; select a named test instance for ' + options.channel);
|
|
431
497
|
const result = command === 'install' ? await installWithLoginTask({ ...options, packageRoot }) : await doctorHosts(options);
|
|
432
498
|
process.stdout.write(JSON.stringify(result, null, 2) + '\n');
|
|
433
499
|
}
|
|
@@ -3,6 +3,7 @@ import { createHash } from 'node:crypto';
|
|
|
3
3
|
import { optionalFile } from './files.mjs';
|
|
4
4
|
import { parseVersion, requireForwardVersion } from './version-policy.mjs';
|
|
5
5
|
import { hosts } from './hosts.mjs';
|
|
6
|
+
import { instanceSkillName } from './instance-skill.mjs';
|
|
6
7
|
|
|
7
8
|
export const defaultRegistry = 'https://registry.npmjs.org/';
|
|
8
9
|
export const activationMode = 'next_mcp_start';
|
|
@@ -15,7 +16,7 @@ export function installedSkillEntries(state) {
|
|
|
15
16
|
if (state.skills === undefined) return [];
|
|
16
17
|
if (!state.skills || typeof state.skills !== 'object' || Array.isArray(state.skills) || !state.skills['craft-create']) throw new Error('Invalid installed Skill destinations');
|
|
17
18
|
return Object.entries(state.skills).map(([name, file]) => {
|
|
18
|
-
if (!Object.hasOwn(managedSkillMarkers, name) || typeof file !== 'string' || !path.isAbsolute(file) || path.basename(file) !== 'SKILL.md' || path.basename(path.dirname(file)) !== name) throw new Error('Invalid installed Skill destination');
|
|
19
|
+
if (!Object.hasOwn(managedSkillMarkers, name) || typeof file !== 'string' || !path.isAbsolute(file) || path.basename(file) !== 'SKILL.md' || path.basename(path.dirname(file)) !== instanceSkillName(name, state.server_id)) throw new Error('Invalid installed Skill destination');
|
|
19
20
|
return { name, file, marker: managedSkillMarkers[name] };
|
|
20
21
|
});
|
|
21
22
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { validateServerId } from './instance.mjs';
|
|
2
|
+
|
|
3
|
+
export function instanceSkillName(logicalName, serverId = 'craft') {
|
|
4
|
+
validateServerId(serverId);
|
|
5
|
+
if (!['craft-create', 'craft-update'].includes(logicalName)) throw new Error('Unknown Craft entrypoint Skill');
|
|
6
|
+
return serverId + logicalName.slice('craft'.length);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// Always render from this runtime's original template, including on update and
|
|
10
|
+
// uninstall. Default installations must still match their installed bytes.
|
|
11
|
+
export function renderInstanceSkill(content, logicalName, serverId = 'craft') {
|
|
12
|
+
const name = instanceSkillName(logicalName, serverId);
|
|
13
|
+
if (serverId === 'craft' || content == null) return content;
|
|
14
|
+
const header = /^---\r?\n([\s\S]*?)\r?\n---(?=\r?\n)/.exec(content);
|
|
15
|
+
if (!header || !header[1].split(/\r?\n/).includes('name: ' + logicalName)) {
|
|
16
|
+
throw new Error('Invalid packaged Skill frontmatter for ' + logicalName);
|
|
17
|
+
}
|
|
18
|
+
const action = logicalName === 'craft-create' ? '创建、继续或上传游戏' : '检查和更新安装';
|
|
19
|
+
const description = '仅在用户指定 ' + serverId + ',或当前项目已绑定其渠道和工作区时,使用该实例' + action + '。';
|
|
20
|
+
const frontmatter = header[1].replace(/^name: .*$/m, 'name: ' + name)
|
|
21
|
+
.replace(/^description: .*$/m, 'description: ' + description);
|
|
22
|
+
return '---\n' + frontmatter + '\n---\n\n'
|
|
23
|
+
+ '本入口对应 MCP 服务 `' + serverId + '`。发现该服务的工具,调用其 `craft_game_info` 核对 server_id、渠道和工作区。'
|
|
24
|
+
+ '后续制作、上传、轮询、更新及重连均使用这条连接。\n'
|
|
25
|
+
+ content.slice(header[0].length);
|
|
26
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
|
|
3
|
+
export function validateServerId(id) {
|
|
4
|
+
if (typeof id !== 'string' || id.length > 32 || !/^craft(?:-[a-z0-9]+(?:-[a-z0-9]+)*)?$/.test(id)) {
|
|
5
|
+
throw new Error('Invalid Craft instance name; use craft or craft-<lowercase-identifier> (up to 32 characters)');
|
|
6
|
+
}
|
|
7
|
+
return id;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function serverIdForChannel(channel) {
|
|
11
|
+
if (channel === undefined || channel === 'stable' || channel === 'latest') return 'craft';
|
|
12
|
+
if (typeof channel !== 'string' || !/^[a-zA-Z][a-zA-Z0-9._-]*$/.test(channel)) throw new Error('Update channel must be an npm dist-tag');
|
|
13
|
+
const simple = 'craft-' + channel;
|
|
14
|
+
if (simple.length <= 32 && /^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(channel)) return simple;
|
|
15
|
+
// Host server names (including DSH) have a common limit of 32. Retain
|
|
16
|
+
// distinct case-sensitive tags when the tag cannot be used verbatim.
|
|
17
|
+
const prefix = channel.toLowerCase().replace(/[^a-z0-9]+/g, '-').slice(0, 13).replace(/-$/, '');
|
|
18
|
+
return 'craft-' + prefix + '-' + createHash('sha256').update(channel).digest('hex').slice(0, 12);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// An unmarked renamed Craft registration belongs to the legacy default slot.
|
|
22
|
+
// Managed named instances identify themselves even when several share a host.
|
|
23
|
+
export function registrationsForInstance(registrations, serverId) {
|
|
24
|
+
return registrations.filter(({ name, connection }) => {
|
|
25
|
+
const marker = connection?.env?.CRAFT_SERVER_ID;
|
|
26
|
+
if (marker !== undefined && marker !== name && (marker === serverId || name === serverId)) throw new Error('Craft instance marker differs from its registration: ' + name);
|
|
27
|
+
return marker === undefined ? serverId === 'craft' : marker === serverId;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
@@ -31,7 +31,7 @@ async function start() {
|
|
|
31
31
|
if (state.host === 'workbuddy' && state.login_data_dir && process.env.CRAFT_STANDALONE_PROBE !== '1') {
|
|
32
32
|
process.env.CLIENT_DATA_DIR ||= state.login_data_dir;
|
|
33
33
|
}
|
|
34
|
-
for (const [key, expected] of Object.entries({ CRAFT_CLIENT_IDE: state.host, CLIENT_WORKSPACE_ROOT: state.workspace, CRAFT_WEB_URL: state.platform })) {
|
|
34
|
+
for (const [key, expected] of Object.entries({ CRAFT_CLIENT_IDE: state.host, CRAFT_SERVER_ID: state.server_id, CLIENT_WORKSPACE_ROOT: state.workspace, CRAFT_WEB_URL: state.platform })) {
|
|
35
35
|
if (process.env[key] && process.env[key] !== expected) throw new Error('Craft launcher scope mismatch: ' + key);
|
|
36
36
|
process.env[key] = expected;
|
|
37
37
|
}
|
|
@@ -4,12 +4,12 @@ import { ensureWorkBuddyLoginTask, removeWorkBuddyLoginTask, ensureWorkBuddyPrev
|
|
|
4
4
|
|
|
5
5
|
export async function runLoginTaskCommand([command, action, ...args]) {
|
|
6
6
|
const preview = command === 'preview-task';
|
|
7
|
-
const usage = `Use ${preview ? 'preview' : 'login'}-task --setup|--remove --ide workbuddy [--host-config ABS]`;
|
|
7
|
+
const usage = `Use ${preview ? 'preview' : 'login'}-task --setup|--remove --ide workbuddy [--host-config ABS] [--instance NAME]`;
|
|
8
8
|
const options = {};
|
|
9
9
|
for (let i = 0; i < args.length; i += 2) {
|
|
10
10
|
const key = args[i];
|
|
11
11
|
const value = args[i + 1];
|
|
12
|
-
if (!['--ide', '--host-config'].includes(key) || !value || value.startsWith('--') || Object.hasOwn(options,key.slice(2))) {
|
|
12
|
+
if (!['--ide', '--host-config', '--instance'].includes(key) || !value || value.startsWith('--') || Object.hasOwn(options,key.slice(2))) {
|
|
13
13
|
throw new Error(usage);
|
|
14
14
|
}
|
|
15
15
|
options[key.slice(2)] = value;
|
|
@@ -17,7 +17,7 @@ export async function runLoginTaskCommand([command, action, ...args]) {
|
|
|
17
17
|
if (!['--setup', '--remove'].includes(action) || options.ide !== 'workbuddy') {
|
|
18
18
|
throw new Error(usage);
|
|
19
19
|
}
|
|
20
|
-
const { installation } = await installedConnection('workbuddy', {hostOptions: hostCommandOptions(options), env: {}});
|
|
20
|
+
const { installation } = await installedConnection('workbuddy', {serverId: options.instance, hostOptions: hostCommandOptions(options), env: {}});
|
|
21
21
|
const setup = preview ? ensureWorkBuddyPreviewTask : ensureWorkBuddyLoginTask;
|
|
22
22
|
const remove = preview ? removeWorkBuddyPreviewTask : removeWorkBuddyLoginTask;
|
|
23
23
|
const result = action === '--setup' ? await setup(installation) : await remove(installation);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isDeepStrictEqual } from 'node:util';
|
|
2
2
|
import { hasCraftConnectionIdentity } from './registration-identity.mjs';
|
|
3
|
-
import { readJsonc, updateJsoncEntry } from './jsonc-config.mjs';
|
|
3
|
+
import { readJsonc, updateJsonc, updateJsoncEntry } from './jsonc-config.mjs';
|
|
4
4
|
|
|
5
5
|
const object = value => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
6
6
|
const reserved = new Set(['servers', 'timeout']);
|
|
@@ -55,12 +55,19 @@ export function openCodeConfig(text, name = 'craft') {
|
|
|
55
55
|
return normalizeOpenCodeConnection(found[0]?.raw);
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
export function
|
|
58
|
+
export function removeOpenCodeConfig(text, serverId) {
|
|
59
|
+
openCodeRegistrations(text);
|
|
60
|
+
const matches = entries(readOpenCodeConfig(text)).filter(entry => entry.name === serverId);
|
|
61
|
+
if (matches.length > 1) throw new Error('Ambiguous OpenCode MCP registration: ' + serverId);
|
|
62
|
+
return matches.length ? updateJsonc(text, [{ path: [...matches[0].table, serverId], value: undefined }]) : text;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function mergeOpenCodeConfig(text, connection, { serverId = 'craft', previousName = serverId, enable = true } = {}) {
|
|
59
66
|
const config = readOpenCodeConfig(text);
|
|
60
67
|
openCodeRegistrations(text);
|
|
61
68
|
const all = entries(config), existing = all.filter(entry => entry.name === previousName);
|
|
62
69
|
if (existing.length > 1) throw new Error('Ambiguous OpenCode MCP registration: ' + previousName);
|
|
63
|
-
if (previousName !==
|
|
70
|
+
if (previousName !== serverId && all.some(entry => entry.name === serverId)) throw new Error('Craft installation conflicts with an existing ' + serverId + ' registration');
|
|
64
71
|
const entry = existing[0];
|
|
65
72
|
if (entry && !object(entry.raw)) throw new Error('Invalid craft server entry');
|
|
66
73
|
// Existing V1 files remain V1; native or empty files use V2. Never migrate
|
|
@@ -83,12 +90,12 @@ export function mergeOpenCodeConfig(text, connection, { previousName = 'craft',
|
|
|
83
90
|
if (typeof connection.timeout === 'number') next.timeout = connection.timeout;
|
|
84
91
|
else if (object(connection.timeout) && typeof connection.timeout.startup === 'number') next.timeout = connection.timeout.startup;
|
|
85
92
|
}
|
|
86
|
-
const output = updateJsoncEntry(text, table,
|
|
93
|
+
const output = updateJsoncEntry(text, table, serverId, previous, next, { previousName });
|
|
87
94
|
const after = readOpenCodeConfig(output), expected = structuredClone(config);
|
|
88
95
|
let target = expected;
|
|
89
96
|
for (const key of table) { target[key] ??= {}; target = target[key]; }
|
|
90
|
-
if (previousName !==
|
|
91
|
-
target
|
|
97
|
+
if (previousName !== serverId) delete target[previousName];
|
|
98
|
+
target[serverId] = next;
|
|
92
99
|
if (!isDeepStrictEqual(after, expected)) throw new Error('OpenCode merge changed unrelated settings; config was preserved');
|
|
93
100
|
return output;
|
|
94
101
|
}
|