@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.
Files changed (152) hide show
  1. package/README.md +10 -55
  2. package/bin/craft-mcp.mjs +4 -1
  3. package/dist-server/game-workflow/check.mjs +3 -2
  4. package/dist-server/game-workflow/context-state.mjs +67 -67
  5. package/dist-server/game-workflow/draft-archive.mjs +147 -2
  6. package/dist-server/game-workflow/draft-upload-identity.mjs +11 -0
  7. package/dist-server/game-workflow/draft-uploads.mjs +105 -60
  8. package/dist-server/game-workflow/local-context.mjs +62 -62
  9. package/dist-server/game-workflow/native-context.mjs +289 -289
  10. package/dist-server/game-workflow/project-bundles.mjs +246 -246
  11. package/dist-server/game-workflow/project-context.mjs +8 -8
  12. package/dist-server/game-workflow/projects.mjs +6 -4
  13. package/dist-server/game-workflow/tasks.mjs +1 -1
  14. package/dist-server/game-workflow/work-scope.mjs +7 -7
  15. package/dist-server/integrations/config.mjs +145 -145
  16. package/dist-server/integrations/connect.mjs +36 -0
  17. package/dist-server/integrations/connection-handoff.mjs +36 -42
  18. package/dist-server/integrations/dsh-config.mjs +182 -182
  19. package/dist-server/integrations/files.mjs +54 -54
  20. package/dist-server/integrations/fixed-launcher.mjs +31 -0
  21. package/dist-server/integrations/host-reload.mjs +19 -0
  22. package/dist-server/integrations/hosts.mjs +55 -55
  23. package/dist-server/integrations/install.mjs +223 -205
  24. package/dist-server/integrations/installation-state.mjs +84 -84
  25. package/dist-server/integrations/launcher-start.mjs +52 -0
  26. package/dist-server/integrations/npm-diagnostics.mjs +32 -0
  27. package/dist-server/integrations/runtime-gc.mjs +191 -188
  28. package/dist-server/integrations/runtime-identity.mjs +22 -0
  29. package/dist-server/integrations/runtime.mjs +111 -126
  30. package/dist-server/integrations/updates.mjs +258 -225
  31. package/dist-server/integrations/version-policy.mjs +32 -32
  32. package/dist-server/launcher.mjs +1845 -0
  33. package/dist-server/mcp/control-panel.mjs +8 -23
  34. package/dist-server/mcp/server.mjs +31 -80
  35. package/dist-server/mcp/update-session.mjs +107 -92
  36. package/dist-server/upstream/craft-aigc.mjs +43 -16
  37. package/dist-server/upstream/draft-source.mjs +29 -0
  38. package/package.json +3 -2
  39. package/resources/context-filter-report.json +1 -1
  40. package/resources/craft-create/SKILL.md +19 -19
  41. package/resources/craft-update/SKILL.md +9 -11
  42. package/resources/targets/claude/js/bootstrap/SKILL.md +3 -1
  43. package/resources/targets/claude/js/context-filter-report.json +1 -1
  44. package/resources/targets/claude/js/craft-game-maker/SKILL.md +11 -15
  45. package/resources/targets/claude/js/js/bundle.json +7 -7
  46. package/resources/targets/claude/js/recovery.md +5 -1
  47. package/resources/targets/claude/js/target.json +1 -1
  48. package/resources/targets/claude/js3d/bootstrap/SKILL.md +3 -1
  49. package/resources/targets/claude/js3d/context-filter-report.json +1 -1
  50. package/resources/targets/claude/js3d/craft-game-maker/SKILL.md +11 -15
  51. package/resources/targets/claude/js3d/js3d/bundle.json +7 -7
  52. package/resources/targets/claude/js3d/recovery.md +5 -1
  53. package/resources/targets/claude/js3d/target.json +1 -1
  54. package/resources/targets/codebuddy/js/bootstrap/SKILL.md +3 -1
  55. package/resources/targets/codebuddy/js/context-filter-report.json +1 -1
  56. package/resources/targets/codebuddy/js/craft-game-maker/SKILL.md +11 -15
  57. package/resources/targets/codebuddy/js/js/bundle.json +7 -7
  58. package/resources/targets/codebuddy/js/recovery.md +5 -1
  59. package/resources/targets/codebuddy/js/target.json +1 -1
  60. package/resources/targets/codebuddy/js3d/bootstrap/SKILL.md +3 -1
  61. package/resources/targets/codebuddy/js3d/context-filter-report.json +1 -1
  62. package/resources/targets/codebuddy/js3d/craft-game-maker/SKILL.md +11 -15
  63. package/resources/targets/codebuddy/js3d/js3d/bundle.json +7 -7
  64. package/resources/targets/codebuddy/js3d/recovery.md +5 -1
  65. package/resources/targets/codebuddy/js3d/target.json +1 -1
  66. package/resources/targets/codex/js/bootstrap/SKILL.md +2 -4
  67. package/resources/targets/codex/js/context-filter-report.json +1 -1
  68. package/resources/targets/codex/js/craft-game-maker/SKILL.md +11 -15
  69. package/resources/targets/codex/js/js/bundle.json +7 -7
  70. package/resources/targets/codex/js/recovery.md +3 -3
  71. package/resources/targets/codex/js/target.json +1 -1
  72. package/resources/targets/codex/js3d/bootstrap/SKILL.md +2 -4
  73. package/resources/targets/codex/js3d/context-filter-report.json +1 -1
  74. package/resources/targets/codex/js3d/craft-game-maker/SKILL.md +11 -15
  75. package/resources/targets/codex/js3d/js3d/bundle.json +7 -7
  76. package/resources/targets/codex/js3d/recovery.md +3 -3
  77. package/resources/targets/codex/js3d/target.json +1 -1
  78. package/resources/targets/cursor/js/bootstrap/SKILL.md +3 -1
  79. package/resources/targets/cursor/js/context-filter-report.json +1 -1
  80. package/resources/targets/cursor/js/craft-game-maker/SKILL.md +11 -15
  81. package/resources/targets/cursor/js/js/bundle.json +7 -7
  82. package/resources/targets/cursor/js/recovery.md +5 -1
  83. package/resources/targets/cursor/js/target.json +1 -1
  84. package/resources/targets/cursor/js3d/bootstrap/SKILL.md +3 -1
  85. package/resources/targets/cursor/js3d/context-filter-report.json +1 -1
  86. package/resources/targets/cursor/js3d/craft-game-maker/SKILL.md +11 -15
  87. package/resources/targets/cursor/js3d/js3d/bundle.json +7 -7
  88. package/resources/targets/cursor/js3d/recovery.md +5 -1
  89. package/resources/targets/cursor/js3d/target.json +1 -1
  90. package/resources/targets/dsh/js/bootstrap/SKILL.md +3 -1
  91. package/resources/targets/dsh/js/context-filter-report.json +1 -1
  92. package/resources/targets/dsh/js/craft-game-maker/SKILL.md +11 -15
  93. package/resources/targets/dsh/js/js/bundle.json +7 -7
  94. package/resources/targets/dsh/js/recovery.md +5 -1
  95. package/resources/targets/dsh/js/target.json +1 -1
  96. package/resources/targets/dsh/js3d/bootstrap/SKILL.md +3 -1
  97. package/resources/targets/dsh/js3d/context-filter-report.json +1 -1
  98. package/resources/targets/dsh/js3d/craft-game-maker/SKILL.md +11 -15
  99. package/resources/targets/dsh/js3d/js3d/bundle.json +7 -7
  100. package/resources/targets/dsh/js3d/recovery.md +5 -1
  101. package/resources/targets/dsh/js3d/target.json +1 -1
  102. package/resources/targets/index.json +32 -32
  103. package/resources/targets/kimi/js/bootstrap/SKILL.md +3 -1
  104. package/resources/targets/kimi/js/context-filter-report.json +1 -1
  105. package/resources/targets/kimi/js/craft-game-maker/SKILL.md +11 -15
  106. package/resources/targets/kimi/js/js/bundle.json +7 -7
  107. package/resources/targets/kimi/js/recovery.md +5 -1
  108. package/resources/targets/kimi/js/target.json +1 -1
  109. package/resources/targets/kimi/js3d/bootstrap/SKILL.md +3 -1
  110. package/resources/targets/kimi/js3d/context-filter-report.json +1 -1
  111. package/resources/targets/kimi/js3d/craft-game-maker/SKILL.md +11 -15
  112. package/resources/targets/kimi/js3d/js3d/bundle.json +7 -7
  113. package/resources/targets/kimi/js3d/recovery.md +5 -1
  114. package/resources/targets/kimi/js3d/target.json +1 -1
  115. package/resources/targets/workbuddy/js/bootstrap/SKILL.md +22 -24
  116. package/resources/targets/workbuddy/js/context-filter-report.json +1 -1
  117. package/resources/targets/workbuddy/js/craft-game-maker/SKILL.md +11 -15
  118. package/resources/targets/workbuddy/js/js/bundle.json +8 -8
  119. package/resources/targets/workbuddy/js/js/context/AGENTS.md +29 -29
  120. package/resources/targets/workbuddy/js/recovery.md +19 -19
  121. package/resources/targets/workbuddy/js/target.json +1 -1
  122. package/resources/targets/workbuddy/js3d/bootstrap/SKILL.md +22 -24
  123. package/resources/targets/workbuddy/js3d/context-filter-report.json +1 -1
  124. package/resources/targets/workbuddy/js3d/craft-game-maker/SKILL.md +11 -15
  125. package/resources/targets/workbuddy/js3d/js3d/bundle.json +8 -8
  126. package/resources/targets/workbuddy/js3d/js3d/context/AGENTS.md +30 -30
  127. package/resources/targets/workbuddy/js3d/recovery.md +19 -19
  128. package/resources/targets/workbuddy/js3d/target.json +1 -1
  129. package/resources/targets/zcode/js/bootstrap/SKILL.md +3 -1
  130. package/resources/targets/zcode/js/context-filter-report.json +1 -1
  131. package/resources/targets/zcode/js/craft-game-maker/SKILL.md +11 -15
  132. package/resources/targets/zcode/js/js/bundle.json +7 -7
  133. package/resources/targets/zcode/js/recovery.md +5 -1
  134. package/resources/targets/zcode/js/target.json +1 -1
  135. package/resources/targets/zcode/js3d/bootstrap/SKILL.md +3 -1
  136. package/resources/targets/zcode/js3d/context-filter-report.json +1 -1
  137. package/resources/targets/zcode/js3d/craft-game-maker/SKILL.md +11 -15
  138. package/resources/targets/zcode/js3d/js3d/bundle.json +7 -7
  139. package/resources/targets/zcode/js3d/recovery.md +5 -1
  140. package/resources/targets/zcode/js3d/target.json +1 -1
  141. package/vendor/craft-runtime/SOURCE.json +4 -4
  142. package/vendor/craft-runtime/package.json +1 -1
  143. package/dist-server/game-workflow/publication-materials.mjs +0 -92
  144. package/dist-server/game-workflow/publications.mjs +0 -168
  145. package/dist-server/game-workflow/publish-capture-worker.mjs +0 -57
  146. package/dist-server/game-workflow/publish-capture.mjs +0 -75
  147. package/dist-server/mcp/publication-page.html +0 -86
  148. package/dist-server/mcp/publication-page.mjs +0 -375
  149. package/dist-server/mcp/publication-preview.mjs +0 -63
  150. package/dist-server/mcp/publication-tools.mjs +0 -22
  151. package/dist-server/mcp/publish-panel.mjs +0 -210
  152. package/dist-server/upstream/publication-transport.mjs +0 -101
@@ -1,84 +1,84 @@
1
- import path from 'node:path';
2
- import { createHash } from 'node:crypto';
3
- import { optionalFile } from './files.mjs';
4
- import { parseVersion, requireForwardVersion } from './version-policy.mjs';
5
- import { hosts } from './hosts.mjs';
6
-
7
- export const defaultRegistry = 'https://registry.npmjs.org/';
8
- export const activationMode = 'next_mcp_start';
9
- export function sameRuntimeIdentity(left, right) {
10
- const samePath = (a, b) => typeof a === 'string' && typeof b === 'string' && (process.platform === 'win32' ? path.resolve(a).toLowerCase() === path.resolve(b).toLowerCase() : path.resolve(a) === path.resolve(b));
11
- return Boolean(left && right && left.package === right.package && left.version === right.version && left.build_id === right.build_id && samePath(left.package_root, right.package_root) && samePath(left.entry, right.entry));
12
- }
13
- export const managedSkillMarkers = Object.freeze({ 'craft-create': '<!-- craft-mcp:bootstrap:v1 -->', 'craft-update': '<!-- craft-mcp:update:v1 -->' });
14
- export function installedSkillEntries(state) {
15
- if (state.skills === undefined) return [];
16
- if (!state.skills || typeof state.skills !== 'object' || Array.isArray(state.skills) || !state.skills['craft-create']) throw new Error('Invalid installed Skill destinations');
17
- 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
- return { name, file, marker: managedSkillMarkers[name] };
20
- });
21
- }
22
- export function skillRuntimeIdentity(identity) {
23
- return Object.fromEntries(['package', 'version', 'build_id', 'package_root', 'entry'].map(key => [key, identity[key]]));
24
- }
25
- export function registryOrigin(value = defaultRegistry) {
26
- const url = new URL(value);
27
- if (url.protocol !== 'https:' || url.username || url.password || url.search || url.hash) throw new Error('Registry must be a credential-free HTTPS URL');
28
- return url.href.replace(/\/?$/, '/');
29
- }
30
-
31
- export function updateSource(pkg, options = {}, previous) {
32
- const name = pkg.name;
33
- if (!/^(@[a-z0-9._-]+\/)?[a-z0-9._-]+$/.test(name ?? '')) throw new Error('Invalid Craft distribution package name');
34
- if (previous?.package && previous.package !== name) throw new Error('Craft package identity differs from the existing installation');
35
- const channel = options.channel ?? previous?.channel ?? 'stable';
36
- if (!/^[a-zA-Z][a-zA-Z0-9._-]*$/.test(channel)) throw new Error('Update channel must be an npm dist-tag');
37
- return { kind: options.kind ?? 'local', package: name, registry: registryOrigin(options.registry ?? previous?.registry ?? pkg.publishConfig?.registry), channel };
38
- }
39
-
40
- export function installationPath(stateRoot, host, config, serverId = 'craft') {
41
- const canonical = path.resolve(config);
42
- const id = createHash('sha256').update(JSON.stringify([host, process.platform === 'win32' ? canonical.toLowerCase() : canonical, serverId])).digest('hex').slice(0, 24);
43
- return { id, file: path.join(stateRoot, id + '.json') };
44
- }
45
-
46
- export function validateIdentity(identity) {
47
- if (!identity || typeof identity !== 'object') throw new Error('Missing Craft runtime identity');
48
- parseVersion(identity.version);
49
- if (!identity.package || !/^[a-f0-9]{64}$/.test(identity.build_id ?? '') || !path.isAbsolute(identity.package_root ?? '') || !path.isAbsolute(identity.entry ?? '')) throw new Error('Invalid Craft runtime identity');
50
- if (path.resolve(identity.entry) !== path.join(path.resolve(identity.package_root), 'bin', 'craft-mcp.mjs')) throw new Error('Craft entry is outside its runtime package');
51
- return identity;
52
- }
53
-
54
- export async function readInstallationSnapshot(file) {
55
- if (!file || !path.isAbsolute(file)) throw new Error('CRAFT_INSTALLATION_FILE must be absolute');
56
- const text = await optionalFile(file);
57
- if (text === null) throw new Error('Craft installation state is missing; run install again');
58
- const state = JSON.parse(text);
59
- if (![1, 2].includes(state.schema) || (state.schema === 2 && state.activation_mode !== activationMode) || !state.id || !Object.hasOwn(hosts, state.host) || !path.isAbsolute(state.config ?? '') || !path.isAbsolute(state.workspace ?? '') || !state.server_id || !['auto', 'off'].includes(state.policy?.mode)) throw new Error('Invalid Craft installation state');
60
- validateIdentity(state.anchor); validateIdentity(state.target);
61
- if (state.source?.package !== state.anchor.package || state.target.package !== state.anchor.package) throw new Error('Craft installation package identity mismatch');
62
- installedSkillEntries(state);
63
- if (state.skills_runtime !== undefined) {
64
- validateIdentity(state.skills_runtime);
65
- if (state.skills_runtime.package !== state.source.package) throw new Error('Installed Skill runtime package identity mismatch');
66
- requireForwardVersion(state.target, state.skills_runtime);
67
- }
68
- if (state.schema === 2 && (!sameRuntimeIdentity(state.anchor, state.target) || !sameRuntimeIdentity(state.skills_runtime, state.target))) throw new Error('Configured runtime and installed Skill identities differ');
69
- if (state.connection_verification !== undefined) {
70
- const receipt = state.connection_verification;
71
- if (!receipt || receipt.version !== state.target.version || receipt.build_id !== state.target.build_id || typeof receipt.instance_id !== 'string' || !receipt.instance_id || !Number.isFinite(Date.parse(receipt.confirmed_at))) throw new Error('Invalid Craft connection verification receipt');
72
- }
73
- registryOrigin(state.source.registry);
74
- if (!/^[a-zA-Z][a-zA-Z0-9._-]*$/.test(state.source.channel ?? '')) throw new Error('Invalid Craft update channel');
75
- return { state, text };
76
- }
77
-
78
- export async function readInstallation(file) { return (await readInstallationSnapshot(file)).state; }
79
-
80
- export function activationStatus(current, target) {
81
- const same = sameRuntimeIdentity(current, target), verified = same && Boolean(current.instance_id);
82
- return { status: verified ? 'active_verified' : same ? 'pending_connection_verification' : 'pending_reconnect', expected: target,
83
- ...(verified ? { instance_id: current.instance_id } : {}) };
84
- }
1
+ import path from 'node:path';
2
+ import { createHash } from 'node:crypto';
3
+ import { optionalFile } from './files.mjs';
4
+ import { parseVersion, requireForwardVersion } from './version-policy.mjs';
5
+ import { hosts } from './hosts.mjs';
6
+
7
+ export const defaultRegistry = 'https://registry.npmjs.org/';
8
+ export const activationMode = 'next_mcp_start';
9
+ export function sameRuntimeIdentity(left, right) {
10
+ const samePath = (a, b) => typeof a === 'string' && typeof b === 'string' && (process.platform === 'win32' ? path.resolve(a).toLowerCase() === path.resolve(b).toLowerCase() : path.resolve(a) === path.resolve(b));
11
+ return Boolean(left && right && left.package === right.package && left.version === right.version && left.build_id === right.build_id && samePath(left.package_root, right.package_root) && samePath(left.entry, right.entry));
12
+ }
13
+ export const managedSkillMarkers = Object.freeze({ 'craft-create': '<!-- craft-mcp:bootstrap:v1 -->', 'craft-update': '<!-- craft-mcp:update:v1 -->' });
14
+ export function installedSkillEntries(state) {
15
+ if (state.skills === undefined) return [];
16
+ if (!state.skills || typeof state.skills !== 'object' || Array.isArray(state.skills) || !state.skills['craft-create']) throw new Error('Invalid installed Skill destinations');
17
+ 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
+ return { name, file, marker: managedSkillMarkers[name] };
20
+ });
21
+ }
22
+ export function skillRuntimeIdentity(identity) {
23
+ return Object.fromEntries(['package', 'version', 'build_id', 'package_root', 'entry'].map(key => [key, identity[key]]));
24
+ }
25
+ export function registryOrigin(value = defaultRegistry) {
26
+ const url = new URL(value);
27
+ if (url.protocol !== 'https:' || url.username || url.password || url.search || url.hash) throw new Error('Registry must be a credential-free HTTPS URL');
28
+ return url.href.replace(/\/?$/, '/');
29
+ }
30
+
31
+ export function updateSource(pkg, options = {}, previous) {
32
+ const name = pkg.name;
33
+ if (!/^(@[a-z0-9._-]+\/)?[a-z0-9._-]+$/.test(name ?? '')) throw new Error('Invalid Craft distribution package name');
34
+ if (previous?.package && previous.package !== name) throw new Error('Craft package identity differs from the existing installation');
35
+ const channel = options.channel ?? previous?.channel ?? 'stable';
36
+ if (!/^[a-zA-Z][a-zA-Z0-9._-]*$/.test(channel)) throw new Error('Update channel must be an npm dist-tag');
37
+ return { kind: options.kind ?? 'local', package: name, registry: registryOrigin(options.registry ?? previous?.registry ?? pkg.publishConfig?.registry), channel };
38
+ }
39
+
40
+ export function installationPath(stateRoot, host, config, serverId = 'craft') {
41
+ const canonical = path.resolve(config);
42
+ const id = createHash('sha256').update(JSON.stringify([host, process.platform === 'win32' ? canonical.toLowerCase() : canonical, serverId])).digest('hex').slice(0, 24);
43
+ return { id, file: path.join(stateRoot, id + '.json') };
44
+ }
45
+
46
+ export function validateIdentity(identity) {
47
+ if (!identity || typeof identity !== 'object') throw new Error('Missing Craft runtime identity');
48
+ parseVersion(identity.version);
49
+ if (!identity.package || !/^[a-f0-9]{64}$/.test(identity.build_id ?? '') || !path.isAbsolute(identity.package_root ?? '') || !path.isAbsolute(identity.entry ?? '')) throw new Error('Invalid Craft runtime identity');
50
+ if (path.resolve(identity.entry) !== path.join(path.resolve(identity.package_root), 'bin', 'craft-mcp.mjs')) throw new Error('Craft entry is outside its runtime package');
51
+ return identity;
52
+ }
53
+
54
+ export async function readInstallationSnapshot(file) {
55
+ if (!file || !path.isAbsolute(file)) throw new Error('CRAFT_INSTALLATION_FILE must be absolute');
56
+ const text = await optionalFile(file);
57
+ if (text === null) throw new Error('Craft installation state is missing; run install again');
58
+ const state = JSON.parse(text);
59
+ if (![1, 2].includes(state.schema) || (state.schema === 2 && state.activation_mode !== activationMode) || !state.id || !Object.hasOwn(hosts, state.host) || !path.isAbsolute(state.config ?? '') || !path.isAbsolute(state.workspace ?? '') || !state.server_id || !['auto', 'off'].includes(state.policy?.mode)) throw new Error('Invalid Craft installation state');
60
+ validateIdentity(state.anchor); validateIdentity(state.target);
61
+ if (state.source?.package !== state.anchor.package || state.target.package !== state.anchor.package) throw new Error('Craft installation package identity mismatch');
62
+ installedSkillEntries(state);
63
+ if (state.skills_runtime !== undefined) {
64
+ validateIdentity(state.skills_runtime);
65
+ if (state.skills_runtime.package !== state.source.package) throw new Error('Installed Skill runtime package identity mismatch');
66
+ requireForwardVersion(state.target, state.skills_runtime);
67
+ }
68
+ if (state.schema === 2 && (!sameRuntimeIdentity(state.anchor, state.target) || !sameRuntimeIdentity(state.skills_runtime, state.target))) throw new Error('Configured runtime and installed Skill identities differ');
69
+ if (state.connection_verification !== undefined) {
70
+ const receipt = state.connection_verification;
71
+ if (!receipt || receipt.version !== state.target.version || receipt.build_id !== state.target.build_id || typeof receipt.instance_id !== 'string' || !receipt.instance_id || !Number.isFinite(Date.parse(receipt.confirmed_at))) throw new Error('Invalid Craft connection verification receipt');
72
+ }
73
+ registryOrigin(state.source.registry);
74
+ if (!/^[a-zA-Z][a-zA-Z0-9._-]*$/.test(state.source.channel ?? '')) throw new Error('Invalid Craft update channel');
75
+ return { state, text };
76
+ }
77
+
78
+ export async function readInstallation(file) { return (await readInstallationSnapshot(file)).state; }
79
+
80
+ export function activationStatus(current, target) {
81
+ const same = sameRuntimeIdentity(current, target), verified = same && Boolean(current.instance_id);
82
+ return { status: verified ? 'active_verified' : same ? 'pending_connection_verification' : 'pending_reconnect', expected: target,
83
+ ...(verified ? { instance_id: current.instance_id } : {}) };
84
+ }
@@ -0,0 +1,52 @@
1
+ // Bundled into a self-contained file. No versioned dependency is loaded before
2
+ // the installation lock is held and the selected package has been verified.
3
+ import path from 'node:path';
4
+ import { pathToFileURL } from 'node:url';
5
+ import { readFile, mkdir, writeFile, unlink } from 'node:fs/promises';
6
+ import { unlinkSync } from 'node:fs';
7
+ import { randomUUID } from 'node:crypto';
8
+ import lockfile from 'proper-lockfile';
9
+ import { readInstallation, sameRuntimeIdentity } from './installation-state.mjs';
10
+ import { getRuntimeIdentity } from './runtime-identity.mjs';
11
+ import { assertPlainPath } from './files.mjs';
12
+ import { verifyLauncher, launcherPath } from './fixed-launcher.mjs';
13
+
14
+ async function start() {
15
+ const entry = path.resolve(process.argv[1]);
16
+ const installationFile = entry.replace(/\.launcher\.mjs$/, '.json');
17
+ if (launcherPath(installationFile) !== entry) throw new Error('Invalid Craft launcher path');
18
+ await assertPlainPath(installationFile);
19
+ const initial = await readInstallation(installationFile);
20
+ await assertPlainPath(path.join(initial.runtime_root, '.path-check'));
21
+ const unlock = await lockfile.lock(initial.runtime_root, { stale: 120000, retries: { retries: 240, minTimeout: 250, maxTimeout: 500 } });
22
+ let identity, state, lease;
23
+ try {
24
+ state = await readInstallation(installationFile);
25
+ if (state.runtime_root !== initial.runtime_root || state.schema !== 2) throw new Error('Craft installation changed or needs migration');
26
+ await verifyLauncher(state, installationFile, { args: [entry] });
27
+ if (process.env.CRAFT_INSTALLATION_FILE && path.resolve(process.env.CRAFT_INSTALLATION_FILE) !== installationFile) throw new Error('Craft launcher installation scope mismatch');
28
+ for (const [key, expected] of Object.entries({ CRAFT_CLIENT_IDE: state.host, CLIENT_WORKSPACE_ROOT: state.workspace, CRAFT_WEB_URL: state.platform })) {
29
+ if (process.env[key] && process.env[key] !== expected) throw new Error('Craft launcher scope mismatch: ' + key);
30
+ process.env[key] = expected;
31
+ }
32
+ const relative = path.relative(path.resolve(state.runtime_root), state.target.package_root);
33
+ if (!relative || relative === '..' || relative.startsWith('..' + path.sep) || path.isAbsolute(relative)) throw new Error('Craft target is outside the managed runtime root');
34
+ await assertPlainPath(state.target.entry);
35
+ identity = await getRuntimeIdentity(state.target.package_root);
36
+ if (!sameRuntimeIdentity(identity, state.target)) throw new Error('Craft target package integrity mismatch');
37
+ const leaseRoot = path.join(state.runtime_root, '.connections');
38
+ await mkdir(leaseRoot, { recursive: true });
39
+ lease = path.join(leaseRoot, 'launcher-' + randomUUID() + '.json');
40
+ await assertPlainPath(lease);
41
+ await writeFile(lease, JSON.stringify({ pid: process.pid, package_root: identity.package_root, version: identity.version, build_id: identity.build_id }), { flag: 'wx', mode: 0o600 });
42
+ // Protect the selected package before releasing the installation/GC lock.
43
+ process.once('exit', () => { try { unlinkSync(lease); } catch {} });
44
+ } finally { await unlock(); }
45
+ if (process.env.CRAFT_STANDALONE_PROBE !== '1') process.env.CRAFT_INSTALLATION_FILE = installationFile;
46
+ process.env.CRAFT_FIXED_LAUNCHER = entry;
47
+ process.argv = [process.execPath, identity.entry, ...process.argv.slice(2)];
48
+ try { await import(pathToFileURL(identity.entry).href); }
49
+ catch (error) { await unlink(lease).catch(() => {}); throw error; }
50
+ }
51
+
52
+ await start().catch(error => { process.stderr.write('Craft launcher failed: ' + error.message + '\n'); process.exitCode = 1; });
@@ -0,0 +1,32 @@
1
+ // npm output can contain registry credentials and user config. Report a bounded
2
+ // error code and our own explanation, never its raw command/stdout/stderr.
3
+ const reasons = Object.freeze({
4
+ E404: 'HTTP 404: the requested package version or archive is unavailable on this registry',
5
+ ETARGET: 'the requested version is not available on this registry',
6
+ E401: 'registry authentication is required',
7
+ E403: 'the registry denied access to this package',
8
+ EINTEGRITY: 'the downloaded archive failed its integrity check',
9
+ EBADENGINE: 'the package requires a different Node.js or npm version',
10
+ ENOTFOUND: 'the registry hostname could not be resolved',
11
+ EAI_AGAIN: 'registry DNS lookup temporarily failed',
12
+ ECONNREFUSED: 'the registry refused the connection',
13
+ ECONNRESET: 'the registry connection was interrupted',
14
+ ETIMEDOUT: 'the npm operation timed out',
15
+ EACCES: 'permission was denied while accessing installation files',
16
+ EPERM: 'the operating system denied an installation file operation',
17
+ ENOSPC: 'there is not enough disk space for installation',
18
+ EROFS: 'the installation filesystem is read-only',
19
+ ENOENT: 'a required executable or installation file is missing',
20
+ CERT_HAS_EXPIRED: 'the registry TLS certificate has expired',
21
+ DEPTH_ZERO_SELF_SIGNED_CERT: 'the registry TLS certificate is not trusted',
22
+ SELF_SIGNED_CERT_IN_CHAIN: 'the registry TLS certificate chain is not trusted',
23
+ UNABLE_TO_VERIFY_LEAF_SIGNATURE: 'the registry TLS certificate could not be verified',
24
+ });
25
+
26
+ export function npmFailure(error) {
27
+ let code;
28
+ try { code=JSON.parse(error.stdout).error?.code; } catch {}
29
+ code=code ?? String(error.stderr??'').match(/^npm (?:ERR!|error) code ([A-Z][A-Z0-9_]*)\r?$/m)?.[1] ?? error.code;
30
+ if(!Object.hasOwn(reasons,code)) code=error.killed?'ETIMEDOUT':'NPM_FAILED';
31
+ return Object.assign(new Error('npm '+code+': '+(reasons[code]??'installation failed; check Node/npm and registry connectivity')), {code:'NPM_FAILED',npm_code:code});
32
+ }