@craft_eco/craft-mcp 0.1.29 → 0.1.30
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 +10 -55
- package/bin/craft-mcp.mjs +4 -1
- package/dist-server/game-workflow/check.mjs +3 -2
- package/dist-server/game-workflow/context-state.mjs +67 -67
- package/dist-server/game-workflow/draft-archive.mjs +147 -2
- package/dist-server/game-workflow/draft-upload-identity.mjs +11 -0
- package/dist-server/game-workflow/draft-uploads.mjs +105 -60
- package/dist-server/game-workflow/local-context.mjs +62 -62
- package/dist-server/game-workflow/native-context.mjs +289 -289
- package/dist-server/game-workflow/project-bundles.mjs +246 -246
- package/dist-server/game-workflow/project-context.mjs +8 -8
- package/dist-server/game-workflow/projects.mjs +6 -4
- package/dist-server/game-workflow/tasks.mjs +1 -1
- package/dist-server/game-workflow/work-scope.mjs +7 -7
- package/dist-server/integrations/config.mjs +145 -145
- package/dist-server/integrations/connect.mjs +36 -0
- package/dist-server/integrations/connection-handoff.mjs +36 -42
- package/dist-server/integrations/dsh-config.mjs +182 -182
- package/dist-server/integrations/files.mjs +54 -54
- package/dist-server/integrations/fixed-launcher.mjs +31 -0
- package/dist-server/integrations/host-reload.mjs +19 -0
- package/dist-server/integrations/hosts.mjs +55 -55
- package/dist-server/integrations/install.mjs +223 -205
- package/dist-server/integrations/installation-state.mjs +84 -84
- package/dist-server/integrations/launcher-start.mjs +52 -0
- package/dist-server/integrations/npm-diagnostics.mjs +32 -0
- package/dist-server/integrations/runtime-gc.mjs +191 -188
- package/dist-server/integrations/runtime-identity.mjs +22 -0
- package/dist-server/integrations/runtime.mjs +111 -126
- package/dist-server/integrations/updates.mjs +258 -225
- package/dist-server/integrations/version-policy.mjs +32 -32
- package/dist-server/launcher.mjs +1845 -0
- package/dist-server/mcp/control-panel.mjs +8 -23
- package/dist-server/mcp/server.mjs +31 -80
- package/dist-server/mcp/update-session.mjs +107 -92
- package/dist-server/upstream/craft-aigc.mjs +43 -16
- package/dist-server/upstream/draft-source.mjs +29 -0
- package/package.json +3 -2
- package/resources/context-filter-report.json +1 -1
- package/resources/craft-create/SKILL.md +19 -19
- package/resources/craft-update/SKILL.md +9 -11
- package/resources/targets/claude/js/bootstrap/SKILL.md +3 -1
- package/resources/targets/claude/js/context-filter-report.json +1 -1
- package/resources/targets/claude/js/craft-game-maker/SKILL.md +11 -15
- package/resources/targets/claude/js/js/bundle.json +7 -7
- package/resources/targets/claude/js/recovery.md +5 -1
- package/resources/targets/claude/js/target.json +1 -1
- package/resources/targets/claude/js3d/bootstrap/SKILL.md +3 -1
- package/resources/targets/claude/js3d/context-filter-report.json +1 -1
- package/resources/targets/claude/js3d/craft-game-maker/SKILL.md +11 -15
- package/resources/targets/claude/js3d/js3d/bundle.json +7 -7
- package/resources/targets/claude/js3d/recovery.md +5 -1
- package/resources/targets/claude/js3d/target.json +1 -1
- package/resources/targets/codebuddy/js/bootstrap/SKILL.md +3 -1
- package/resources/targets/codebuddy/js/context-filter-report.json +1 -1
- package/resources/targets/codebuddy/js/craft-game-maker/SKILL.md +11 -15
- package/resources/targets/codebuddy/js/js/bundle.json +7 -7
- package/resources/targets/codebuddy/js/recovery.md +5 -1
- package/resources/targets/codebuddy/js/target.json +1 -1
- package/resources/targets/codebuddy/js3d/bootstrap/SKILL.md +3 -1
- package/resources/targets/codebuddy/js3d/context-filter-report.json +1 -1
- package/resources/targets/codebuddy/js3d/craft-game-maker/SKILL.md +11 -15
- package/resources/targets/codebuddy/js3d/js3d/bundle.json +7 -7
- package/resources/targets/codebuddy/js3d/recovery.md +5 -1
- package/resources/targets/codebuddy/js3d/target.json +1 -1
- package/resources/targets/codex/js/bootstrap/SKILL.md +2 -4
- package/resources/targets/codex/js/context-filter-report.json +1 -1
- package/resources/targets/codex/js/craft-game-maker/SKILL.md +11 -15
- package/resources/targets/codex/js/js/bundle.json +7 -7
- package/resources/targets/codex/js/recovery.md +3 -3
- package/resources/targets/codex/js/target.json +1 -1
- package/resources/targets/codex/js3d/bootstrap/SKILL.md +2 -4
- package/resources/targets/codex/js3d/context-filter-report.json +1 -1
- package/resources/targets/codex/js3d/craft-game-maker/SKILL.md +11 -15
- package/resources/targets/codex/js3d/js3d/bundle.json +7 -7
- package/resources/targets/codex/js3d/recovery.md +3 -3
- package/resources/targets/codex/js3d/target.json +1 -1
- package/resources/targets/cursor/js/bootstrap/SKILL.md +3 -1
- package/resources/targets/cursor/js/context-filter-report.json +1 -1
- package/resources/targets/cursor/js/craft-game-maker/SKILL.md +11 -15
- package/resources/targets/cursor/js/js/bundle.json +7 -7
- package/resources/targets/cursor/js/recovery.md +5 -1
- package/resources/targets/cursor/js/target.json +1 -1
- package/resources/targets/cursor/js3d/bootstrap/SKILL.md +3 -1
- package/resources/targets/cursor/js3d/context-filter-report.json +1 -1
- package/resources/targets/cursor/js3d/craft-game-maker/SKILL.md +11 -15
- package/resources/targets/cursor/js3d/js3d/bundle.json +7 -7
- package/resources/targets/cursor/js3d/recovery.md +5 -1
- package/resources/targets/cursor/js3d/target.json +1 -1
- package/resources/targets/dsh/js/bootstrap/SKILL.md +3 -1
- package/resources/targets/dsh/js/context-filter-report.json +1 -1
- package/resources/targets/dsh/js/craft-game-maker/SKILL.md +11 -15
- package/resources/targets/dsh/js/js/bundle.json +7 -7
- package/resources/targets/dsh/js/recovery.md +5 -1
- package/resources/targets/dsh/js/target.json +1 -1
- package/resources/targets/dsh/js3d/bootstrap/SKILL.md +3 -1
- package/resources/targets/dsh/js3d/context-filter-report.json +1 -1
- package/resources/targets/dsh/js3d/craft-game-maker/SKILL.md +11 -15
- package/resources/targets/dsh/js3d/js3d/bundle.json +7 -7
- package/resources/targets/dsh/js3d/recovery.md +5 -1
- package/resources/targets/dsh/js3d/target.json +1 -1
- package/resources/targets/index.json +32 -32
- package/resources/targets/kimi/js/bootstrap/SKILL.md +3 -1
- package/resources/targets/kimi/js/context-filter-report.json +1 -1
- package/resources/targets/kimi/js/craft-game-maker/SKILL.md +11 -15
- package/resources/targets/kimi/js/js/bundle.json +7 -7
- package/resources/targets/kimi/js/recovery.md +5 -1
- package/resources/targets/kimi/js/target.json +1 -1
- package/resources/targets/kimi/js3d/bootstrap/SKILL.md +3 -1
- package/resources/targets/kimi/js3d/context-filter-report.json +1 -1
- package/resources/targets/kimi/js3d/craft-game-maker/SKILL.md +11 -15
- package/resources/targets/kimi/js3d/js3d/bundle.json +7 -7
- package/resources/targets/kimi/js3d/recovery.md +5 -1
- package/resources/targets/kimi/js3d/target.json +1 -1
- package/resources/targets/workbuddy/js/bootstrap/SKILL.md +22 -24
- package/resources/targets/workbuddy/js/context-filter-report.json +1 -1
- package/resources/targets/workbuddy/js/craft-game-maker/SKILL.md +11 -15
- package/resources/targets/workbuddy/js/js/bundle.json +8 -8
- package/resources/targets/workbuddy/js/js/context/AGENTS.md +29 -29
- package/resources/targets/workbuddy/js/recovery.md +19 -19
- package/resources/targets/workbuddy/js/target.json +1 -1
- package/resources/targets/workbuddy/js3d/bootstrap/SKILL.md +22 -24
- package/resources/targets/workbuddy/js3d/context-filter-report.json +1 -1
- package/resources/targets/workbuddy/js3d/craft-game-maker/SKILL.md +11 -15
- package/resources/targets/workbuddy/js3d/js3d/bundle.json +8 -8
- package/resources/targets/workbuddy/js3d/js3d/context/AGENTS.md +30 -30
- package/resources/targets/workbuddy/js3d/recovery.md +19 -19
- package/resources/targets/workbuddy/js3d/target.json +1 -1
- package/resources/targets/zcode/js/bootstrap/SKILL.md +3 -1
- package/resources/targets/zcode/js/context-filter-report.json +1 -1
- package/resources/targets/zcode/js/craft-game-maker/SKILL.md +11 -15
- package/resources/targets/zcode/js/js/bundle.json +7 -7
- package/resources/targets/zcode/js/recovery.md +5 -1
- package/resources/targets/zcode/js/target.json +1 -1
- package/resources/targets/zcode/js3d/bootstrap/SKILL.md +3 -1
- package/resources/targets/zcode/js3d/context-filter-report.json +1 -1
- package/resources/targets/zcode/js3d/craft-game-maker/SKILL.md +11 -15
- package/resources/targets/zcode/js3d/js3d/bundle.json +7 -7
- package/resources/targets/zcode/js3d/recovery.md +5 -1
- package/resources/targets/zcode/js3d/target.json +1 -1
- package/vendor/craft-runtime/SOURCE.json +4 -4
- package/vendor/craft-runtime/package.json +1 -1
- package/dist-server/game-workflow/publication-materials.mjs +0 -92
- package/dist-server/game-workflow/publications.mjs +0 -168
- package/dist-server/game-workflow/publish-capture-worker.mjs +0 -57
- package/dist-server/game-workflow/publish-capture.mjs +0 -75
- package/dist-server/mcp/publication-page.html +0 -86
- package/dist-server/mcp/publication-page.mjs +0 -375
- package/dist-server/mcp/publication-preview.mjs +0 -63
- package/dist-server/mcp/publication-tools.mjs +0 -22
- package/dist-server/mcp/publish-panel.mjs +0 -210
- package/dist-server/upstream/publication-transport.mjs +0 -101
|
@@ -1,205 +1,223 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import os from 'node:os';
|
|
3
|
-
import { readFile, mkdir } from 'node:fs/promises';
|
|
4
|
-
import lockfile from 'proper-lockfile';
|
|
5
|
-
import { getAppDataRoot } from '../core/app-paths.mjs';
|
|
6
|
-
import { hostPaths, hostEnvironment, installTargets } from './hosts.mjs';
|
|
7
|
-
import { craftConfig, craftRegistrations, mergeConfig, importZcodeFallback } from './config.mjs';
|
|
8
|
-
import { assertDshSharedScope } from './dsh-config.mjs';
|
|
9
|
-
import { optionalFile, assertPlainPath, commitFiles } from './files.mjs';
|
|
10
|
-
import { stageRuntime, probeRuntime, getRuntimeIdentity } from './runtime.mjs';
|
|
11
|
-
import { installationPath, readInstallation, readInstallationSnapshot, updateSource, installedSkillEntries, skillRuntimeIdentity, sameRuntimeIdentity, activationMode } from './installation-state.mjs';
|
|
12
|
-
import { requireForwardVersion } from './version-policy.mjs';
|
|
13
|
-
import { connectionHandoff } from './connection-handoff.mjs';
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (host === '
|
|
35
|
-
if (host === '
|
|
36
|
-
if (host === '
|
|
37
|
-
if (host === '
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if (
|
|
47
|
-
if (
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
if (
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
if (
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
if (!path.isAbsolute(
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
const
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
const
|
|
113
|
-
const
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
if (
|
|
122
|
-
//
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
}
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import { readFile, mkdir } from 'node:fs/promises';
|
|
4
|
+
import lockfile from 'proper-lockfile';
|
|
5
|
+
import { getAppDataRoot } from '../core/app-paths.mjs';
|
|
6
|
+
import { hostPaths, hostEnvironment, installTargets } from './hosts.mjs';
|
|
7
|
+
import { craftConfig, craftRegistrations, mergeConfig, importZcodeFallback } from './config.mjs';
|
|
8
|
+
import { assertDshSharedScope } from './dsh-config.mjs';
|
|
9
|
+
import { optionalFile, assertPlainPath, commitFiles } from './files.mjs';
|
|
10
|
+
import { stageRuntime, probeRuntime, getRuntimeIdentity } from './runtime.mjs';
|
|
11
|
+
import { installationPath, readInstallation, readInstallationSnapshot, updateSource, installedSkillEntries, skillRuntimeIdentity, sameRuntimeIdentity, activationMode } from './installation-state.mjs';
|
|
12
|
+
import { requireForwardVersion } from './version-policy.mjs';
|
|
13
|
+
import { connectionHandoff } from './connection-handoff.mjs';
|
|
14
|
+
import { planLauncher, verifyLauncher } from './fixed-launcher.mjs';
|
|
15
|
+
|
|
16
|
+
const bootstrapMarker = '<!-- craft-mcp:bootstrap:v1 -->';
|
|
17
|
+
function legacyNpmSource(connection, packageName) {
|
|
18
|
+
const args = connection?.args ?? [];
|
|
19
|
+
const spec = args.find(value => typeof value === 'string' && (value === packageName || value.startsWith(packageName + '@')));
|
|
20
|
+
if (!spec) return null;
|
|
21
|
+
const selector = spec.slice(packageName.length + 1);
|
|
22
|
+
const channel = /^[a-zA-Z][a-zA-Z0-9._-]*$/.test(selector) ? selector : undefined;
|
|
23
|
+
const registryValues = args.flatMap((value, index) => typeof value !== 'string' ? [] : value.startsWith('--registry=') ? [value.slice('--registry='.length)] : value === '--registry' ? [args[index + 1]] : []);
|
|
24
|
+
if (registryValues.some(value => typeof value !== 'string') || new Set(registryValues).size > 1) throw new Error('Legacy Craft npm registry arguments are ambiguous; preserve the configuration and choose a registry explicitly');
|
|
25
|
+
return { package_spec: spec, ...(channel ? { channel } : {}), ...(registryValues.length ? { registry: registryValues[0] } : {}), selector_kind: channel ? 'dist_tag' : selector ? 'pinned_version' : 'unspecified' };
|
|
26
|
+
}
|
|
27
|
+
function platformOrigin(value) {
|
|
28
|
+
const url = new URL(value);
|
|
29
|
+
if (url.protocol !== 'https:' || url.username || url.password || url.pathname !== '/' || url.search || url.hash) throw new Error('--platform must be a credential-free HTTPS origin');
|
|
30
|
+
return url.origin;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function hostConnectionOptions(host) {
|
|
34
|
+
if (host === 'codex') return { startup_timeout_sec: 120 };
|
|
35
|
+
if (host === 'claude') return { type: 'stdio' };
|
|
36
|
+
if (host === 'zcode') return { type: 'stdio', timeoutMs: 120000 };
|
|
37
|
+
if (host === 'kimi') return { enabled: true, startupTimeoutMs: 120000 };
|
|
38
|
+
if (host === 'dsh') return {};
|
|
39
|
+
return { type: 'stdio', timeout: 120000 };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export async function installHosts({ ide, workspace, platform, packageRoot, home = os.homedir(), codexHome, hostOptions = {},
|
|
43
|
+
runtimeRoot = path.join(getAppDataRoot(), 'runtimes'), stateRoot = path.join(path.dirname(runtimeRoot), 'installations'),
|
|
44
|
+
registry, channel, updates, materialize = stageRuntime, probe = probeRuntime }) {
|
|
45
|
+
const targets = installTargets(ide);
|
|
46
|
+
if (workspace !== undefined && !path.isAbsolute(workspace)) throw new Error('--workspace must be absolute');
|
|
47
|
+
if (platform !== undefined) platform = platformOrigin(platform);
|
|
48
|
+
if (updates !== undefined && !['auto', 'off'].includes(updates)) throw new Error('--updates must be auto or off');
|
|
49
|
+
const pkg = JSON.parse(await readFile(path.join(packageRoot, 'package.json'), 'utf8'));
|
|
50
|
+
const desiredSkill = await readFile(path.join(packageRoot, 'resources/craft-create/SKILL.md'), 'utf8');
|
|
51
|
+
const desiredUpdateSkill = await optionalFile(path.join(packageRoot, 'resources/craft-update/SKILL.md'));
|
|
52
|
+
if (!desiredSkill.includes(bootstrapMarker)) throw new Error('Craft bootstrap Skill missing from distribution');
|
|
53
|
+
if (desiredUpdateSkill !== null && !desiredUpdateSkill.includes('<!-- craft-mcp:update:v1 -->')) throw new Error('Craft update Skill has an invalid distribution marker');
|
|
54
|
+
await mkdir(runtimeRoot, { recursive: true });
|
|
55
|
+
const targetPaths = new Map(targets.map(host => [host, hostPaths(home, host, codexHome, hostOptions)]));
|
|
56
|
+
const stateLocks = [], lockPaths = targets.map(host => installationPath(stateRoot, host, targetPaths.get(host).config).file).sort();
|
|
57
|
+
let release;
|
|
58
|
+
try {
|
|
59
|
+
// Same lock order as automatic updates: installation first, runtime root
|
|
60
|
+
// second. Keep info/check receipts from invalidating the install snapshot
|
|
61
|
+
// during materialization and probe, without waiting on a lock in reverse order.
|
|
62
|
+
for (const file of lockPaths) {
|
|
63
|
+
await assertPlainPath(file); await mkdir(path.dirname(file), { recursive: true });
|
|
64
|
+
stateLocks.push(await lockfile.lock(file, { realpath: false, stale: 120000, retries: { retries: 120, minTimeout: 100, maxTimeout: 500 } }));
|
|
65
|
+
}
|
|
66
|
+
release = await lockfile.lock(runtimeRoot, { stale: 120000, retries: 0 });
|
|
67
|
+
const plans = [];
|
|
68
|
+
for (const host of targets) {
|
|
69
|
+
const paths = targetPaths.get(host);
|
|
70
|
+
await assertPlainPath(paths.config); await assertPlainPath(paths.skill); await assertPlainPath(paths.updateSkill);
|
|
71
|
+
assertDshSharedScope(paths);
|
|
72
|
+
const original = await optionalFile(paths.config), existingSkill = await optionalFile(paths.skill);
|
|
73
|
+
let configInput = original ?? '', fallbackSnapshot;
|
|
74
|
+
if (paths.fallbackConfig) {
|
|
75
|
+
await assertPlainPath(paths.fallbackConfig);
|
|
76
|
+
const fallback = await optionalFile(paths.fallbackConfig);
|
|
77
|
+
configInput = importZcodeFallback(configInput, fallback);
|
|
78
|
+
if (configInput !== (original ?? '')) fallbackSnapshot = { file: paths.fallbackConfig, text: fallback };
|
|
79
|
+
}
|
|
80
|
+
const existingUpdateSkill = await optionalFile(paths.updateSkill);
|
|
81
|
+
if (existingSkill && !existingSkill.includes(bootstrapMarker)) throw new Error('User-owned craft-create Skill preserved; rename it before installing: ' + paths.skill);
|
|
82
|
+
if (desiredUpdateSkill && existingUpdateSkill && !existingUpdateSkill.includes('<!-- craft-mcp:update:v1 -->')) throw new Error('User-owned craft-update Skill preserved; rename it before installing: ' + paths.updateSkill);
|
|
83
|
+
const registrations = craftRegistrations(configInput, host);
|
|
84
|
+
if (registrations.length > 1) throw new Error(host + ': Multiple Craft registrations found; preserve separate environments and select one installation before updating');
|
|
85
|
+
const previousName = registrations[0]?.name ?? 'craft', old = registrations[0]?.connection;
|
|
86
|
+
const legacySource = legacyNpmSource(old, pkg.name);
|
|
87
|
+
const statePath = installationPath(stateRoot, host, paths.config);
|
|
88
|
+
const previousSnapshot = old?.env?.CRAFT_INSTALLATION_FILE ? await readInstallationSnapshot(old.env.CRAFT_INSTALLATION_FILE) : null;
|
|
89
|
+
const previousState = previousSnapshot?.state;
|
|
90
|
+
if (previousState && (previousState.host !== host || path.resolve(previousState.config) !== path.resolve(paths.config))) throw new Error('Craft installation state belongs to another host configuration');
|
|
91
|
+
const stateBefore = previousSnapshot && path.resolve(old.env.CRAFT_INSTALLATION_FILE) === path.resolve(statePath.file) ? previousSnapshot.text : await optionalFile(statePath.file);
|
|
92
|
+
let previousRuntime = previousState?.target;
|
|
93
|
+
if (!previousRuntime && old?.args?.[0] && path.isAbsolute(old.args[0])) {
|
|
94
|
+
const oldRoot = path.resolve(path.dirname(old.args[0]), '..');
|
|
95
|
+
try { previousRuntime = await getRuntimeIdentity(oldRoot); }
|
|
96
|
+
catch (error) { if (error.code !== 'ENOENT') throw error; }
|
|
97
|
+
}
|
|
98
|
+
if (!previousRuntime) {
|
|
99
|
+
const pinned = old?.args?.find(value => typeof value === 'string' && /^@craft_eco\/craft-mcp@\d/.test(value));
|
|
100
|
+
if (pinned) previousRuntime = { version: pinned.slice('@craft_eco/craft-mcp@'.length) };
|
|
101
|
+
}
|
|
102
|
+
const workspaceIndex = old?.args?.indexOf('--workspace') ?? -1;
|
|
103
|
+
const games = workspace ?? (workspaceIndex >= 0 ? old.args[workspaceIndex + 1] : old?.env?.CLIENT_WORKSPACE_ROOT) ?? path.join(home, 'CraftGames');
|
|
104
|
+
if (!path.isAbsolute(games)) throw new Error('Configured Craft workspace must be absolute');
|
|
105
|
+
const origin = platformOrigin(platform ?? old?.env?.CRAFT_WEB_URL ?? pkg.craft?.platform);
|
|
106
|
+
plans.push({ host, paths, original, configInput, fallbackSnapshot, existingSkill, existingUpdateSkill, previousName, previousRuntime, previousState, legacySource, statePath, stateBefore, workspace: path.resolve(games), platform: origin });
|
|
107
|
+
}
|
|
108
|
+
const runtime = await materialize(packageRoot, runtimeRoot), changes = [], results = [];
|
|
109
|
+
const identity = { ...await getRuntimeIdentity(runtime.package_root ?? path.resolve(path.dirname(runtime.entry), '..')), entry: runtime.entry };
|
|
110
|
+
for (const plan of plans) {
|
|
111
|
+
requireForwardVersion(identity, plan.previousRuntime);
|
|
112
|
+
const source = updateSource(pkg, { registry: registry ?? (!plan.previousState ? plan.legacySource?.registry : undefined), channel: channel ?? (!plan.previousState ? plan.legacySource?.channel : undefined) }, plan.previousState?.source);
|
|
113
|
+
const migration = plan.previousState?.migration ?? (plan.legacySource ? { from_server: plan.previousName, ...plan.legacySource } : undefined);
|
|
114
|
+
const launcherPlan = await planLauncher(plan.statePath.file, plan.previousState?.launcher, identity.package_root);
|
|
115
|
+
const state = { schema: 2, activation_mode: activationMode, id: plan.statePath.id, host: plan.host, server_id: 'craft', config: plan.paths.config,
|
|
116
|
+
launcher: launcherPlan.launcher,
|
|
117
|
+
workspace: plan.workspace, platform: plan.platform, runtime_root: runtimeRoot, source,
|
|
118
|
+
...(migration ? { migration } : {}),
|
|
119
|
+
skills: { 'craft-create': plan.paths.skill, ...(desiredUpdateSkill ? { 'craft-update': plan.paths.updateSkill } : {}) },
|
|
120
|
+
policy: { mode: updates ?? plan.previousState?.policy.mode ?? 'auto', offline: 'allow-existing' }, anchor: identity, target: identity, skills_runtime: skillRuntimeIdentity(identity) };
|
|
121
|
+
if (plan.previousState?.connection_verification && sameRuntimeIdentity(identity, plan.previousState.target) && plan.workspace === plan.previousState.workspace && plan.platform === plan.previousState.platform) state.connection_verification = plan.previousState.connection_verification;
|
|
122
|
+
// Reinstalling the same build must not reset check receipts or touch files.
|
|
123
|
+
const priorComparable = plan.previousState && { ...plan.previousState };
|
|
124
|
+
if (priorComparable) { delete priorComparable.updated_at; delete priorComparable.last_check; }
|
|
125
|
+
const same = priorComparable && JSON.stringify(priorComparable) === JSON.stringify(state);
|
|
126
|
+
const desiredState = same ? plan.previousState : { ...state, updated_at: new Date().toISOString() };
|
|
127
|
+
const connection = { command: process.execPath, args: [launcherPlan.launcher.entry, '--workspace', plan.workspace],
|
|
128
|
+
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 },
|
|
129
|
+
...hostConnectionOptions(plan.host) };
|
|
130
|
+
const configured = craftConfig(plan.configInput, plan.host, plan.previousName);
|
|
131
|
+
// Some hosts omit an enabled flag when saving their configuration. Do not
|
|
132
|
+
// reinsert defaults into an already enabled registration.
|
|
133
|
+
const alreadyEnabled = configured && configured.disabled !== true && configured.enabled !== false && configured.enable !== false;
|
|
134
|
+
const updated = mergeConfig(plan.configInput, plan.host, connection, { previousName: plan.previousName, enable: !alreadyEnabled });
|
|
135
|
+
const verified = await probe({ ...craftConfig(updated, plan.host), args: [runtime.entry, '--workspace', plan.workspace] }, { version: runtime.version, build_id: identity.build_id, host: plan.host, workspace: plan.workspace, platform: plan.platform });
|
|
136
|
+
if (verified.runtime?.activation_mode !== activationMode) throw new Error('Craft runtime requires a legacy frontend; install a next_mcp_start distribution');
|
|
137
|
+
changes.push({ file: plan.paths.skill, before: plan.existingSkill, after: desiredSkill });
|
|
138
|
+
if (desiredUpdateSkill) changes.push({ file: plan.paths.updateSkill, before: plan.existingUpdateSkill, after: desiredUpdateSkill });
|
|
139
|
+
// A host may react as soon as its config changes. Make the state and
|
|
140
|
+
// managed entrypoints available before exposing the new launch command.
|
|
141
|
+
changes.push(launcherPlan.change, { file: plan.statePath.file, before: plan.stateBefore, after: same ? plan.stateBefore : JSON.stringify(desiredState, null, 2) + '\n' },
|
|
142
|
+
{ file: plan.paths.config, before: plan.original, after: updated });
|
|
143
|
+
results.push({ host: plan.host, ...plan.paths, installation: plan.statePath.file, launcher: state.launcher, source, policy: state.policy, ...(migration ? { migration } : {}), ...(plan.previousName !== 'craft' ? { migrated_from: plan.previousName } : {}), ...(plan.fallbackSnapshot ? { imported_from: plan.fallbackSnapshot.file } : {}), verified,
|
|
144
|
+
activation_mode: activationMode, reconnect_required: true, activation: { status: 'pending_connection_verification', expected: identity },
|
|
145
|
+
connection_handoff: connectionHandoff({host:plan.host,target:identity,workspace:plan.workspace,platform:plan.platform,intent:'install'}) });
|
|
146
|
+
}
|
|
147
|
+
for (const plan of plans) {
|
|
148
|
+
await assertPlainPath(plan.paths.config);
|
|
149
|
+
assertDshSharedScope(plan.paths);
|
|
150
|
+
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');
|
|
151
|
+
}
|
|
152
|
+
const written = await commitFiles(changes);
|
|
153
|
+
return { runtime, hosts: results, ...written,
|
|
154
|
+
next: 'The installed package loads at the next MCP start or user-requested reconnect. Verify the actual runtime version/build_id, then prepare the current project to update its context and Skills. Standalone probes do not confirm host activation.' };
|
|
155
|
+
} finally { try { await release?.(); } finally { for (const unlock of stateLocks.reverse()) await unlock(); } }
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
async function verifyInstalledSkills(installation, paths, connection) {
|
|
159
|
+
const entries = installation?.skills ? installedSkillEntries(installation) : [{ name: 'craft-create', file: paths.skill, marker: bootstrapMarker }];
|
|
160
|
+
const contents = new Map();
|
|
161
|
+
for (const { name, file, marker } of entries) {
|
|
162
|
+
await assertPlainPath(file);
|
|
163
|
+
const content = await optionalFile(file);
|
|
164
|
+
if (!content?.includes(marker)) throw new Error('Craft ' + name + ' Skill missing or not managed by installer: ' + file);
|
|
165
|
+
contents.set(name, content);
|
|
166
|
+
}
|
|
167
|
+
const candidates = installation ? installation.skills_runtime ? [installation.skills_runtime] : [installation.target, installation.anchor] : [await getRuntimeIdentity(path.resolve(path.dirname(connection.args[0]), '..'))];
|
|
168
|
+
for (const candidate of candidates) {
|
|
169
|
+
const actual = await getRuntimeIdentity(candidate.package_root);
|
|
170
|
+
if (actual.package !== candidate.package || actual.version !== candidate.version || actual.build_id !== candidate.build_id) throw new Error('Installed Skill runtime files differ from their recorded identity');
|
|
171
|
+
let matches = true;
|
|
172
|
+
for (const { name, marker } of entries) {
|
|
173
|
+
const expected = await optionalFile(path.join(candidate.package_root, 'resources', name, 'SKILL.md'));
|
|
174
|
+
if (!expected?.includes(marker) || contents.get(name) !== expected) { matches = false; break; }
|
|
175
|
+
}
|
|
176
|
+
if (matches) return { status: 'verified', runtime: skillRuntimeIdentity(candidate), managed: entries.map(entry => entry.name) };
|
|
177
|
+
}
|
|
178
|
+
// Pre-receipt installations can have activated B while anchor A and pending C
|
|
179
|
+
// remain on disk. Never call B corrupt or claim its identity is verified.
|
|
180
|
+
if (installation && !installation.skills_runtime) return { status: 'legacy_unverified', managed: entries.map(entry => entry.name), note: 'Managed Skill markers are present, but their runtime identity was not recorded by this older installation. Complete activation on the actual connection to synchronize and verify them.' };
|
|
181
|
+
throw new Error('Craft managed Skills differ from the recorded installed Skill runtime; run install again');
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export async function doctorHosts({ ide, home = os.homedir(), codexHome, hostOptions = {}, probe = probeRuntime }) {
|
|
185
|
+
const results = [];
|
|
186
|
+
for (const host of installTargets(ide)) {
|
|
187
|
+
const paths = hostPaths(home, host, codexHome, hostOptions);
|
|
188
|
+
await assertPlainPath(paths.config);
|
|
189
|
+
assertDshSharedScope(paths);
|
|
190
|
+
const connection = craftConfig(await optionalFile(paths.config) ?? '', host);
|
|
191
|
+
if (!connection?.command || connection.env?.CRAFT_CLIENT_IDE !== host) throw new Error(host + ': Craft installation missing or host marker incorrect; run install --ide ' + host);
|
|
192
|
+
if (connection.disabled === true || connection.enabled === false || connection.enable === false) throw new Error(host + ': Craft MCP is disabled');
|
|
193
|
+
let installation = null, skillsVerification;
|
|
194
|
+
if (connection.env.CRAFT_INSTALLATION_FILE) {
|
|
195
|
+
const unlock = await lockfile.lock(connection.env.CRAFT_INSTALLATION_FILE, { stale: 120000, retries: { retries: 30, minTimeout: 100, maxTimeout: 500 } });
|
|
196
|
+
try {
|
|
197
|
+
installation = await readInstallation(connection.env.CRAFT_INSTALLATION_FILE);
|
|
198
|
+
await verifyLauncher(installation, connection.env.CRAFT_INSTALLATION_FILE, connection);
|
|
199
|
+
skillsVerification = await verifyInstalledSkills(installation, paths, connection);
|
|
200
|
+
} finally { await unlock(); }
|
|
201
|
+
} else skillsVerification = await verifyInstalledSkills(null, paths, connection);
|
|
202
|
+
const skillsPending = Boolean(installation && skillsVerification.runtime?.build_id !== installation.target.build_id);
|
|
203
|
+
const checkConnection = installation && !installation.launcher ? { ...connection, args: [installation.target.entry, '--workspace', installation.workspace] } : connection;
|
|
204
|
+
const verified = await probe(checkConnection, { host, ...(installation ? { version: installation.target.version, build_id: installation.target.build_id } : {}) });
|
|
205
|
+
results.push({ host, ...paths, entry: connection.args[0], target: installation?.target, skills_pending_activation: skillsPending, skills_verification: skillsVerification, verified });
|
|
206
|
+
}
|
|
207
|
+
return { hosts: results, note: results.some(item => item.skills_verification.status !== 'verified')
|
|
208
|
+
? 'Candidate MCP protocol verified; legacy global Skill identity remains unverified. Complete activation on the actual connection, then run doctor again. Host trust and Skill discovery require host verification.'
|
|
209
|
+
: 'MCP protocol and installed files verified. Host trust, Skill discovery and session recovery require a new session in the host.' };
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export async function runIntegrationCommand(args, packageRoot) {
|
|
213
|
+
const [command, ...rest] = args, options = {};
|
|
214
|
+
for (let i = 0; i < rest.length; i += 2) {
|
|
215
|
+
const name = rest[i].replace(/^--/, '');
|
|
216
|
+
if (!rest[i].startsWith('--') || !['ide', ...(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.');
|
|
217
|
+
options[name] = rest[i + 1];
|
|
218
|
+
}
|
|
219
|
+
options.codexHome = process.env.CODEX_HOME;
|
|
220
|
+
options.hostOptions = hostEnvironment();
|
|
221
|
+
const result = command === 'install' ? await installHosts({ ...options, packageRoot }) : await doctorHosts(options);
|
|
222
|
+
process.stdout.write(JSON.stringify(result, null, 2) + '\n');
|
|
223
|
+
}
|