@craft_eco/craft-mcp 0.1.34-beta.3 → 0.1.34-beta.4
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 +7 -5
- package/bin/craft-mcp.mjs +3 -1
- package/dist-server/core/upload-limits.mjs +11 -0
- package/dist-server/game-workflow/art-previews.mjs +71 -71
- package/dist-server/game-workflow/bundle-files.mjs +6 -1
- package/dist-server/game-workflow/engines.mjs +18 -9
- 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 +4 -1
- package/dist-server/game-workflow/project-install.mjs +15 -7
- package/dist-server/game-workflow/projects.mjs +13 -3
- package/dist-server/integrations/distribution-targets.mjs +9 -0
- package/dist-server/integrations/install.mjs +49 -11
- package/dist-server/integrations/instance-skill.mjs +26 -26
- package/dist-server/integrations/instance.mjs +29 -29
- package/dist-server/integrations/launcher-start.mjs +5 -5
- package/dist-server/integrations/project-setup.mjs +2 -0
- package/dist-server/integrations/runtime-candidate.mjs +32 -6
- package/dist-server/integrations/runtime-file-diagnostics.mjs +68 -0
- package/dist-server/integrations/runtime-gc.mjs +8 -2
- package/dist-server/integrations/runtime-identity.mjs +56 -8
- package/dist-server/integrations/runtime.mjs +5 -2
- package/dist-server/integrations/uninstall.mjs +160 -160
- package/dist-server/integrations/updates.mjs +17 -20
- package/dist-server/launcher.mjs +47 -8
- package/dist-server/mcp/production-events.mjs +52 -29
- package/dist-server/mcp/server.mjs +5 -4
- package/dist-server/preview/preview-snapshot.mjs +3 -2
- package/package.json +5 -5
- package/resources/context-filter-report.json +1 -1
- package/resources/craft-create/SKILL.md +25 -25
- package/resources/craft-update/SKILL.md +27 -27
- 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/NOTICE.md +1 -1
- package/vendor/craft-runtime/SOURCE.json +10 -6
- package/vendor/craft-runtime/index.js +228 -164
- package/vendor/craft-runtime/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schema": 1,
|
|
3
3
|
"config": "context-filters.json",
|
|
4
|
-
"config_sha256": "
|
|
4
|
+
"config_sha256": "8eeef2b88f93dbf9ce4f1c7229bd01fdd93d76c75dce43f03b2649d418084763",
|
|
5
5
|
"exclude": [
|
|
6
6
|
"contexts/*/js/skills/aigc-generate/**",
|
|
7
7
|
"contexts/*/js/skills/asset-search/**",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schema": 1,
|
|
3
3
|
"config": "context-filters.json",
|
|
4
|
-
"config_sha256": "
|
|
4
|
+
"config_sha256": "8eeef2b88f93dbf9ce4f1c7229bd01fdd93d76c75dce43f03b2649d418084763",
|
|
5
5
|
"exclude": [
|
|
6
6
|
"contexts/*/js/skills/aigc-generate/**",
|
|
7
7
|
"contexts/*/js/skills/asset-search/**",
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
# Craft local runtime
|
|
2
2
|
|
|
3
|
-
Built from the verified @tencent/craft-agentcli public API and Craft-owned local finalization source. Upstream license: MIT. Source identities and retained inputs are recorded in SOURCE.json.
|
|
3
|
+
Built from the verified @tencent/craft-agentcli public API and Craft-owned local finalization and upload source. Upstream license: MIT. Source identities and retained inputs are recorded in SOURCE.json.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schema": 1,
|
|
3
3
|
"kind": "craft-local-runtime",
|
|
4
|
-
"profile_version": "1.2.
|
|
4
|
+
"profile_version": "1.2.1",
|
|
5
5
|
"builder": {
|
|
6
6
|
"name": "esbuild",
|
|
7
7
|
"version": "0.27.7"
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"commit": "48ef7264f54dd2868aca98822493f074ccea6e7b",
|
|
26
26
|
"snapshot_sha256": "e2ab885cc08613dbef8631b7cd1daa0b6ca13ccfb9defb47d0cf60f7ad07e332"
|
|
27
27
|
},
|
|
28
|
-
"profile_sha256": "
|
|
28
|
+
"profile_sha256": "17080ebf7998893debd3691fd2c690b536d4fd3273c9bec4b7faa3e9bec1fe2b",
|
|
29
29
|
"inputs": {
|
|
30
30
|
"vendor/agent-cli/dist/src/protocol/messages/errors.gen.js": "532600441cf85d41f645ff637efce263dca2b1cd91c308d54572f33f4b7883e4",
|
|
31
31
|
"vendor/agent-cli/dist/src/protocol/link/envelope.js": "5bbaeb11b3fa78494f019808d828fb9d547c60d61579daae79f6977bdff50d5e",
|
|
@@ -48,16 +48,20 @@
|
|
|
48
48
|
"vendor/agent-cli/dist/src/context/template-seed.js": "e816945896c5ed3f0ee1ed9b9375e1b94fa13dd1d00d84b70596e02ac93666b9",
|
|
49
49
|
"vendor/agent-cli/dist/src/context/template-refresh.js": "bead4ae074929d100e5653ac131faa23b2fa80526602663567e7e69aa0d760cd",
|
|
50
50
|
"vendor/agent-cli/dist/src/context/template-sync.js": "37f7e6be88234757f73dea7c01ca94c66434207508c38a002dd5165bc5190af0",
|
|
51
|
-
"sdk/finalize-game-context.mjs": "
|
|
51
|
+
"sdk/finalize-game-context.mjs": "743f18b58c35e2995744f8e5fb6adff7402d6a5d290ddd4f5eb250c48af06980",
|
|
52
|
+
"sdk/static-artifacts.mjs": "0f6a0d1b34c095167ab427d56f5243aa6d613abbce5a0bf2208484ae00c2bbce",
|
|
53
|
+
"src/core/upload-limits.mjs": "4d5b473d8f80d7cb0b60ee5886f3674b5dea8c83fe510763beef08ab2b8b6896",
|
|
54
|
+
"sdk/external-game-archive.mjs": "9d0485c4468d51c2279755b19265f3454ea933810e69137aace93fc15ba7ce5c",
|
|
55
|
+
"sdk/external-game-content.mjs": "74023a2bc316f788e7739282a05575a5c8bb9b2374575eaa4bc4e8c46da72e53",
|
|
52
56
|
"vendor/agent-cli/dist/src/component/isolated-launcher.js": "05a5ccf310d5d54560779396020442a7374a6bbec2a1b77231b0ba670c5cee15",
|
|
53
57
|
"vendor/agent-cli/dist/src/component/proxied-fetch.js": "7d2f81d904409e9872bb4786d13d92cc9686dd94b3d81698a93593937689e15b",
|
|
54
58
|
"vendor/agent-cli/dist/src/component/isolated-preload.js": "f508888d0e1c81c371227a3375be6ea658497a3f9ae5038eee48a8e041bdb734"
|
|
55
59
|
},
|
|
56
60
|
"files": {
|
|
57
|
-
"index.js": "
|
|
61
|
+
"index.js": "cdbd5f5f7b9b74bd3d13ef394b331e353782e21ad98aa3e4ebcbf1b29af8571a",
|
|
58
62
|
"isolated-launcher.js": "e29f878445a81ab5b3c2855c4a1741f78992a42bb95b2cddc8a18e5bb9634584",
|
|
59
63
|
"isolated-preload.js": "7fd2caa820191e5c0dc188db71d500e2854650198795fd088e90a2438326d625",
|
|
60
|
-
"NOTICE.md": "
|
|
61
|
-
"package.json": "
|
|
64
|
+
"NOTICE.md": "720b23be4a7fbc6d87899700b68e5219d59eb50a0f285b25d2fc45d4fbb0d3f4",
|
|
65
|
+
"package.json": "0582a79a96a035894e80ab05ba78a0eb863c3e59403080a0d1a1507d2ed64f50"
|
|
62
66
|
}
|
|
63
67
|
}
|
|
@@ -555,7 +555,6 @@ async function replaceFile(source, target) {
|
|
|
555
555
|
}
|
|
556
556
|
|
|
557
557
|
// vendor/agent-cli/dist/src/artifacts/static.js
|
|
558
|
-
import { createHash as createHash2 } from "node:crypto";
|
|
559
558
|
import { constants as constants3 } from "node:fs";
|
|
560
559
|
import { lstat as lstat2, open, readFile as readFile3, readdir as readdir2, realpath as realpath3, stat as stat3, unlink } from "node:fs/promises";
|
|
561
560
|
import path8 from "node:path";
|
|
@@ -1086,66 +1085,8 @@ async function runNpmInstall(cwd, args, env, timeoutMs, signal) {
|
|
|
1086
1085
|
function isRecord(value) {
|
|
1087
1086
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1088
1087
|
}
|
|
1089
|
-
async function prepareStaticArtifacts(distDir) {
|
|
1090
|
-
if (!path8.isAbsolute(distDir))
|
|
1091
|
-
throw new Error("static directory must be absolute", { cause: new DiagnosticCause("static_output_invalid") });
|
|
1092
|
-
try {
|
|
1093
|
-
if ((await lstat2(distDir)).isSymbolicLink())
|
|
1094
|
-
throw new Error("static directory must not be a symlink", { cause: new DiagnosticCause("static_output_invalid") });
|
|
1095
|
-
} catch (error) {
|
|
1096
|
-
if (error.code === "ENOENT")
|
|
1097
|
-
throw new BuildFailureError("JS build produced no dist output", { cause: new DiagnosticCause("static_output_missing") });
|
|
1098
|
-
throw error;
|
|
1099
|
-
}
|
|
1100
|
-
const root = await realpath3(distDir);
|
|
1101
|
-
if (!(await stat3(root)).isDirectory())
|
|
1102
|
-
throw new Error("static output is not a directory", { cause: new DiagnosticCause("static_output_invalid") });
|
|
1103
|
-
const artifacts = [];
|
|
1104
|
-
let totalBytes = 0;
|
|
1105
|
-
async function walk(dir) {
|
|
1106
|
-
const entries = await readdir2(dir, { withFileTypes: true });
|
|
1107
|
-
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
1108
|
-
for (const entry of entries) {
|
|
1109
|
-
if (entry.name.startsWith(".") || /(?:secret|credential|token|private[_-]?key)/i.test(entry.name))
|
|
1110
|
-
continue;
|
|
1111
|
-
const absolute = path8.join(dir, entry.name);
|
|
1112
|
-
if (entry.isDirectory()) {
|
|
1113
|
-
await walk(absolute);
|
|
1114
|
-
continue;
|
|
1115
|
-
}
|
|
1116
|
-
if (!entry.isFile())
|
|
1117
|
-
continue;
|
|
1118
|
-
if (artifacts.length >= 2e3)
|
|
1119
|
-
throw new Error("static file count exceeds limit", { cause: new DiagnosticCause("static_limit_exceeded") });
|
|
1120
|
-
const handle = await open(absolute, constants3.O_RDONLY | (constants3.O_NOFOLLOW ?? 0));
|
|
1121
|
-
try {
|
|
1122
|
-
const info = await handle.stat();
|
|
1123
|
-
if (!info.isFile() || info.size > 8 * 1024 * 1024 || totalBytes + info.size > 64 * 1024 * 1024) {
|
|
1124
|
-
throw new Error("static file exceeds size limit", { cause: new DiagnosticCause("static_limit_exceeded") });
|
|
1125
|
-
}
|
|
1126
|
-
const content = await handle.readFile();
|
|
1127
|
-
if (content.length !== info.size)
|
|
1128
|
-
throw new Error("static file changed during collection", { cause: new DiagnosticCause("artifact_changed") });
|
|
1129
|
-
totalBytes += content.length;
|
|
1130
|
-
artifacts.push({
|
|
1131
|
-
relativePath: path8.relative(root, absolute).split(path8.sep).join("/"),
|
|
1132
|
-
path: absolute,
|
|
1133
|
-
bytes: content.length,
|
|
1134
|
-
sha256: createHash2("sha256").update(content).digest("hex")
|
|
1135
|
-
});
|
|
1136
|
-
} finally {
|
|
1137
|
-
await handle.close();
|
|
1138
|
-
}
|
|
1139
|
-
}
|
|
1140
|
-
}
|
|
1141
|
-
await walk(root);
|
|
1142
|
-
if (!artifacts.some((item) => item.relativePath === "index.html"))
|
|
1143
|
-
throw new BuildFailureError("JS build has no index.html", { cause: new DiagnosticCause("static_output_missing") });
|
|
1144
|
-
return artifacts;
|
|
1145
|
-
}
|
|
1146
1088
|
|
|
1147
1089
|
// vendor/agent-cli/dist/src/artifacts/external-game-archive.js
|
|
1148
|
-
import { createHash as createHash3 } from "node:crypto";
|
|
1149
1090
|
var EXTERNAL_GAME_UPLOAD_LIMITS = Object.freeze({
|
|
1150
1091
|
files: 2e3,
|
|
1151
1092
|
fileBytes: 8 * 1024 * 1024,
|
|
@@ -1161,94 +1102,9 @@ var crcTable = Uint32Array.from({ length: 256 }, (_, value) => {
|
|
|
1161
1102
|
value = value & 1 ? value >>> 1 ^ 3988292384 : value >>> 1;
|
|
1162
1103
|
return value >>> 0;
|
|
1163
1104
|
});
|
|
1164
|
-
function crc32(data) {
|
|
1165
|
-
let value = 4294967295;
|
|
1166
|
-
for (const byte of data)
|
|
1167
|
-
value = crcTable[(value ^ byte) & 255] ^ value >>> 8;
|
|
1168
|
-
return (value ^ 4294967295) >>> 0;
|
|
1169
|
-
}
|
|
1170
|
-
function checkedName(name) {
|
|
1171
|
-
if (typeof name !== "string" || !name || name.normalize("NFC") !== name || /[\p{Cc}\\:%?#<>|"*]/u.test(name) || name.split("/").some((part) => !part || part.startsWith(".") || part.endsWith(".") || part.endsWith(" "))) {
|
|
1172
|
-
throw new Error("Invalid external game archive file path");
|
|
1173
|
-
}
|
|
1174
|
-
const encoded = Buffer.from(name, "utf8");
|
|
1175
|
-
if (encoded.length > EXTERNAL_GAME_UPLOAD_LIMITS.pathBytes || encoded.toString("utf8") !== name) {
|
|
1176
|
-
throw new Error("External game archive file path exceeds the platform limit or contains invalid Unicode");
|
|
1177
|
-
}
|
|
1178
|
-
return encoded;
|
|
1179
|
-
}
|
|
1180
|
-
function collisionKey(name) {
|
|
1181
|
-
return name.toUpperCase().toLowerCase().normalize("NFC");
|
|
1182
|
-
}
|
|
1183
|
-
function encodeExternalGameArchive(files, signal) {
|
|
1184
|
-
signal?.throwIfAborted();
|
|
1185
|
-
const parts = [], central = [], names = /* @__PURE__ */ new Set();
|
|
1186
|
-
let offset = 0, centralBytes = 0, totalBytes = 0;
|
|
1187
|
-
let hasEntryPoint = false;
|
|
1188
|
-
for (const [name, input] of files) {
|
|
1189
|
-
signal?.throwIfAborted();
|
|
1190
|
-
const encoded = checkedName(name), key = collisionKey(name);
|
|
1191
|
-
if (names.size >= EXTERNAL_GAME_UPLOAD_LIMITS.files)
|
|
1192
|
-
throw new Error("External game archive file count exceeds the platform limit");
|
|
1193
|
-
if (names.has(key))
|
|
1194
|
-
throw new Error("External game archive contains duplicate file paths");
|
|
1195
|
-
if (!(input instanceof Uint8Array) || input.byteLength > EXTERNAL_GAME_UPLOAD_LIMITS.fileBytes || totalBytes + input.byteLength > EXTERNAL_GAME_UPLOAD_LIMITS.totalFileBytes) {
|
|
1196
|
-
throw new Error("External game archive file bytes exceed the platform limit");
|
|
1197
|
-
}
|
|
1198
|
-
names.add(key);
|
|
1199
|
-
totalBytes += input.byteLength;
|
|
1200
|
-
hasEntryPoint ||= name === "index.html" && input.byteLength > 0;
|
|
1201
|
-
const data = Buffer.from(input);
|
|
1202
|
-
const checksum = crc32(data);
|
|
1203
|
-
const local = Buffer.alloc(30);
|
|
1204
|
-
local.writeUInt32LE(67324752, 0);
|
|
1205
|
-
local.writeUInt16LE(20, 4);
|
|
1206
|
-
local.writeUInt16LE(2048, 6);
|
|
1207
|
-
local.writeUInt16LE(33, 12);
|
|
1208
|
-
local.writeUInt32LE(checksum, 14);
|
|
1209
|
-
local.writeUInt32LE(data.length, 18);
|
|
1210
|
-
local.writeUInt32LE(data.length, 22);
|
|
1211
|
-
local.writeUInt16LE(encoded.length, 26);
|
|
1212
|
-
const entry = Buffer.alloc(46);
|
|
1213
|
-
entry.writeUInt32LE(33639248, 0);
|
|
1214
|
-
entry.writeUInt16LE(20, 4);
|
|
1215
|
-
local.copy(entry, 6, 4, 30);
|
|
1216
|
-
entry.writeUInt32LE(offset, 42);
|
|
1217
|
-
parts.push(local, encoded, data);
|
|
1218
|
-
central.push(entry, encoded);
|
|
1219
|
-
offset += local.length + encoded.length + data.length;
|
|
1220
|
-
centralBytes += entry.length + encoded.length;
|
|
1221
|
-
if (centralBytes > EXTERNAL_GAME_UPLOAD_LIMITS.centralDirectoryBytes || offset + centralBytes + 22 > EXTERNAL_GAME_UPLOAD_LIMITS.archiveBytes) {
|
|
1222
|
-
throw new Error("External game ZIP exceeds the platform size limit");
|
|
1223
|
-
}
|
|
1224
|
-
}
|
|
1225
|
-
if (!hasEntryPoint)
|
|
1226
|
-
throw new Error("External game archive requires a non-empty root index.html");
|
|
1227
|
-
for (const key of names) {
|
|
1228
|
-
let parent = key;
|
|
1229
|
-
while (parent.includes("/")) {
|
|
1230
|
-
parent = parent.slice(0, parent.lastIndexOf("/"));
|
|
1231
|
-
if (names.has(parent))
|
|
1232
|
-
throw new Error("External game archive has conflicting file and directory paths");
|
|
1233
|
-
}
|
|
1234
|
-
}
|
|
1235
|
-
const end = Buffer.alloc(22);
|
|
1236
|
-
end.writeUInt32LE(101010256, 0);
|
|
1237
|
-
end.writeUInt16LE(names.size, 8);
|
|
1238
|
-
end.writeUInt16LE(names.size, 10);
|
|
1239
|
-
end.writeUInt32LE(centralBytes, 12);
|
|
1240
|
-
end.writeUInt32LE(offset, 16);
|
|
1241
|
-
const bytes = offset + centralBytes + end.length;
|
|
1242
|
-
parts.push(...central, end);
|
|
1243
|
-
const hash = createHash3("sha256");
|
|
1244
|
-
for (const part of parts)
|
|
1245
|
-
hash.update(part);
|
|
1246
|
-
signal?.throwIfAborted();
|
|
1247
|
-
return { parts, bytes, sha256: hash.digest("hex") };
|
|
1248
|
-
}
|
|
1249
1105
|
|
|
1250
1106
|
// vendor/agent-cli/dist/src/artifacts/external-game-upload.js
|
|
1251
|
-
import { createHash as
|
|
1107
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
1252
1108
|
import { promisify } from "node:util";
|
|
1253
1109
|
import { gzip } from "node:zlib";
|
|
1254
1110
|
var compress = promisify(gzip);
|
|
@@ -1272,7 +1128,7 @@ async function encodeExternalGameContent(archive, signal) {
|
|
|
1272
1128
|
if (bytes !== archive.bytes)
|
|
1273
1129
|
throw new Error("External game ZIP length does not match its prepared metadata");
|
|
1274
1130
|
const original = Buffer.concat(archive.parts, bytes);
|
|
1275
|
-
if (
|
|
1131
|
+
if (createHash2("sha256").update(original).digest("hex") !== archive.sha256) {
|
|
1276
1132
|
throw new Error("External game ZIP SHA-256 does not match its prepared metadata");
|
|
1277
1133
|
}
|
|
1278
1134
|
let encoded;
|
|
@@ -1380,8 +1236,8 @@ async function assertTemplateTarget(root, relativePath) {
|
|
|
1380
1236
|
if (segment)
|
|
1381
1237
|
target = path9.join(target, segment);
|
|
1382
1238
|
try {
|
|
1383
|
-
const
|
|
1384
|
-
if (
|
|
1239
|
+
const stat5 = await fs4.lstat(target);
|
|
1240
|
+
if (stat5.isSymbolicLink())
|
|
1385
1241
|
throw new Error(`Template target contains a symbolic link: ${relativePath}`);
|
|
1386
1242
|
} catch (error) {
|
|
1387
1243
|
if (error.code === "ENOENT")
|
|
@@ -1506,27 +1362,27 @@ async function withWritableParents(root, relative, body) {
|
|
|
1506
1362
|
}
|
|
1507
1363
|
async function assertRegularTree(target, signal) {
|
|
1508
1364
|
signal.throwIfAborted();
|
|
1509
|
-
const
|
|
1510
|
-
if (!
|
|
1365
|
+
const stat5 = await statOrMissing(target);
|
|
1366
|
+
if (!stat5)
|
|
1511
1367
|
return;
|
|
1512
|
-
if (
|
|
1368
|
+
if (stat5.isSymbolicLink())
|
|
1513
1369
|
throw new Error("Template target contains a symbolic link");
|
|
1514
|
-
if (
|
|
1370
|
+
if (stat5.isDirectory()) {
|
|
1515
1371
|
for (const name of await fs5.readdir(target))
|
|
1516
1372
|
await assertRegularTree(path10.join(target, name), signal);
|
|
1517
|
-
} else if (!
|
|
1373
|
+
} else if (!stat5.isFile())
|
|
1518
1374
|
throw new Error("Template target is not a regular file");
|
|
1519
1375
|
}
|
|
1520
1376
|
async function removeManagedTree(target, signal) {
|
|
1521
1377
|
signal.throwIfAborted();
|
|
1522
|
-
const
|
|
1523
|
-
if (
|
|
1378
|
+
const stat5 = await fs5.lstat(target);
|
|
1379
|
+
if (stat5.isSymbolicLink())
|
|
1524
1380
|
throw new Error("Template target contains a symbolic link");
|
|
1525
|
-
if (!
|
|
1381
|
+
if (!stat5.isDirectory()) {
|
|
1526
1382
|
await fs5.unlink(target);
|
|
1527
1383
|
return;
|
|
1528
1384
|
}
|
|
1529
|
-
await fs5.chmod(target,
|
|
1385
|
+
await fs5.chmod(target, stat5.mode | 448);
|
|
1530
1386
|
let removed = false;
|
|
1531
1387
|
try {
|
|
1532
1388
|
for (const name of await fs5.readdir(target))
|
|
@@ -1535,7 +1391,7 @@ async function removeManagedTree(target, signal) {
|
|
|
1535
1391
|
removed = true;
|
|
1536
1392
|
} finally {
|
|
1537
1393
|
if (!removed)
|
|
1538
|
-
await fs5.chmod(target,
|
|
1394
|
+
await fs5.chmod(target, stat5.mode);
|
|
1539
1395
|
}
|
|
1540
1396
|
}
|
|
1541
1397
|
async function statOrMissing(file) {
|
|
@@ -1607,16 +1463,16 @@ async function seedProjectTemplate(sourceDir, targetDir, options = {}) {
|
|
|
1607
1463
|
});
|
|
1608
1464
|
}
|
|
1609
1465
|
async function isNewOrEmptyWorkspace(targetDir) {
|
|
1610
|
-
let
|
|
1466
|
+
let stat5;
|
|
1611
1467
|
try {
|
|
1612
|
-
|
|
1468
|
+
stat5 = await fs6.lstat(targetDir);
|
|
1613
1469
|
} catch (err) {
|
|
1614
1470
|
if (err.code === "ENOENT") {
|
|
1615
1471
|
return true;
|
|
1616
1472
|
}
|
|
1617
1473
|
throw err;
|
|
1618
1474
|
}
|
|
1619
|
-
if (!
|
|
1475
|
+
if (!stat5.isDirectory()) {
|
|
1620
1476
|
return false;
|
|
1621
1477
|
}
|
|
1622
1478
|
const entries = await fs6.readdir(targetDir);
|
|
@@ -1701,16 +1557,224 @@ async function finalizeGameContext({ workspaceDir, contextDir, engine, onLog = (
|
|
|
1701
1557
|
onLog("Configuration export completed");
|
|
1702
1558
|
}
|
|
1703
1559
|
}
|
|
1560
|
+
|
|
1561
|
+
// sdk/static-artifacts.mjs
|
|
1562
|
+
import path13 from "node:path";
|
|
1563
|
+
import { constants as constants6 } from "node:fs";
|
|
1564
|
+
import { lstat as lstat4, open as open2, readdir as readdir3, realpath as realpath5, stat as stat4 } from "node:fs/promises";
|
|
1565
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
1566
|
+
|
|
1567
|
+
// src/core/upload-limits.mjs
|
|
1568
|
+
var runtimeUploadLimits = Object.freeze({
|
|
1569
|
+
files: 2e3,
|
|
1570
|
+
fileBytes: 8 * 1024 * 1024,
|
|
1571
|
+
totalFileBytes: 220 * 1024 * 1024,
|
|
1572
|
+
archiveBytes: 222 * 1024 * 1024,
|
|
1573
|
+
gzipBytes: 223 * 1024 * 1024,
|
|
1574
|
+
jsonBytes: 300 * 1024 * 1024,
|
|
1575
|
+
pathBytes: 240,
|
|
1576
|
+
centralDirectoryBytes: 4 * 1024 * 1024
|
|
1577
|
+
});
|
|
1578
|
+
|
|
1579
|
+
// sdk/static-artifacts.mjs
|
|
1580
|
+
async function prepareStaticArtifacts2(distDir) {
|
|
1581
|
+
if (!path13.isAbsolute(distDir)) throw new Error("static directory must be absolute");
|
|
1582
|
+
try {
|
|
1583
|
+
if ((await lstat4(distDir)).isSymbolicLink()) throw new Error("static directory must not be a symlink");
|
|
1584
|
+
} catch (error) {
|
|
1585
|
+
if (error.code === "ENOENT") throw new Error("JS build produced no dist output");
|
|
1586
|
+
throw error;
|
|
1587
|
+
}
|
|
1588
|
+
const root = await realpath5(distDir);
|
|
1589
|
+
if (!(await stat4(root)).isDirectory()) throw new Error("static output is not a directory");
|
|
1590
|
+
const artifacts = [];
|
|
1591
|
+
let totalBytes = 0;
|
|
1592
|
+
async function walk(directory) {
|
|
1593
|
+
const entries = await readdir3(directory, { withFileTypes: true });
|
|
1594
|
+
entries.sort((left, right) => left.name.localeCompare(right.name));
|
|
1595
|
+
for (const entry of entries) {
|
|
1596
|
+
if (entry.name.startsWith(".") || /(?:secret|credential|token|private[_-]?key)/i.test(entry.name)) continue;
|
|
1597
|
+
const absolute = path13.join(directory, entry.name);
|
|
1598
|
+
if (entry.isSymbolicLink() || await realpath5(absolute) !== absolute) throw new Error("static output contains a symbolic link");
|
|
1599
|
+
if (entry.isDirectory()) {
|
|
1600
|
+
await walk(absolute);
|
|
1601
|
+
continue;
|
|
1602
|
+
}
|
|
1603
|
+
if (!entry.isFile()) throw new Error("static output must contain regular files");
|
|
1604
|
+
if (artifacts.length >= runtimeUploadLimits.files) throw new Error("static file count exceeds limit");
|
|
1605
|
+
const handle = await open2(absolute, constants6.O_RDONLY | (constants6.O_NOFOLLOW ?? 0));
|
|
1606
|
+
try {
|
|
1607
|
+
const info = await handle.stat();
|
|
1608
|
+
if (!info.isFile() || info.size > runtimeUploadLimits.fileBytes || totalBytes + info.size > runtimeUploadLimits.totalFileBytes) {
|
|
1609
|
+
throw new Error("static file exceeds size limit");
|
|
1610
|
+
}
|
|
1611
|
+
const content = await handle.readFile();
|
|
1612
|
+
if (content.length !== info.size) throw new Error("static file changed during collection");
|
|
1613
|
+
totalBytes += content.length;
|
|
1614
|
+
artifacts.push({
|
|
1615
|
+
relativePath: path13.relative(root, absolute).split(path13.sep).join("/"),
|
|
1616
|
+
path: absolute,
|
|
1617
|
+
bytes: content.length,
|
|
1618
|
+
sha256: createHash3("sha256").update(content).digest("hex")
|
|
1619
|
+
});
|
|
1620
|
+
} finally {
|
|
1621
|
+
await handle.close();
|
|
1622
|
+
}
|
|
1623
|
+
}
|
|
1624
|
+
}
|
|
1625
|
+
await walk(root);
|
|
1626
|
+
if (!artifacts.some((item) => item.relativePath === "index.html")) throw new Error("JS build has no index.html");
|
|
1627
|
+
return artifacts;
|
|
1628
|
+
}
|
|
1629
|
+
|
|
1630
|
+
// sdk/external-game-archive.mjs
|
|
1631
|
+
import { createHash as createHash4 } from "node:crypto";
|
|
1632
|
+
var crcTable2 = Uint32Array.from({ length: 256 }, (_, value) => {
|
|
1633
|
+
for (let bit = 0; bit < 8; bit++)
|
|
1634
|
+
value = value & 1 ? value >>> 1 ^ 3988292384 : value >>> 1;
|
|
1635
|
+
return value >>> 0;
|
|
1636
|
+
});
|
|
1637
|
+
function crc32(data) {
|
|
1638
|
+
let value = 4294967295;
|
|
1639
|
+
for (const byte of data)
|
|
1640
|
+
value = crcTable2[(value ^ byte) & 255] ^ value >>> 8;
|
|
1641
|
+
return (value ^ 4294967295) >>> 0;
|
|
1642
|
+
}
|
|
1643
|
+
function checkedName(name) {
|
|
1644
|
+
if (typeof name !== "string" || !name || name.normalize("NFC") !== name || /[\p{Cc}\\:%?#<>|"*]/u.test(name) || name.split("/").some((part) => !part || part.startsWith(".") || part.endsWith(".") || part.endsWith(" "))) {
|
|
1645
|
+
throw new Error("Invalid external game archive file path");
|
|
1646
|
+
}
|
|
1647
|
+
const encoded = Buffer.from(name, "utf8");
|
|
1648
|
+
if (encoded.length > runtimeUploadLimits.pathBytes || encoded.toString("utf8") !== name) {
|
|
1649
|
+
throw new Error("External game archive file path exceeds the platform limit or contains invalid Unicode");
|
|
1650
|
+
}
|
|
1651
|
+
return encoded;
|
|
1652
|
+
}
|
|
1653
|
+
function collisionKey(name) {
|
|
1654
|
+
return name.toUpperCase().toLowerCase().normalize("NFC");
|
|
1655
|
+
}
|
|
1656
|
+
function encodeExternalGameArchive(files, signal) {
|
|
1657
|
+
signal?.throwIfAborted();
|
|
1658
|
+
const parts = [], central = [], names = /* @__PURE__ */ new Set();
|
|
1659
|
+
let offset = 0, centralBytes = 0, totalBytes = 0;
|
|
1660
|
+
let hasEntryPoint = false;
|
|
1661
|
+
for (const [name, input] of files) {
|
|
1662
|
+
signal?.throwIfAborted();
|
|
1663
|
+
const encoded = checkedName(name), key = collisionKey(name);
|
|
1664
|
+
if (names.size >= runtimeUploadLimits.files)
|
|
1665
|
+
throw new Error("External game archive file count exceeds the platform limit");
|
|
1666
|
+
if (names.has(key))
|
|
1667
|
+
throw new Error("External game archive contains duplicate file paths");
|
|
1668
|
+
if (!(input instanceof Uint8Array) || input.byteLength > runtimeUploadLimits.fileBytes || totalBytes + input.byteLength > runtimeUploadLimits.totalFileBytes) {
|
|
1669
|
+
throw new Error("External game archive file bytes exceed the platform limit");
|
|
1670
|
+
}
|
|
1671
|
+
names.add(key);
|
|
1672
|
+
totalBytes += input.byteLength;
|
|
1673
|
+
hasEntryPoint ||= name === "index.html" && input.byteLength > 0;
|
|
1674
|
+
const data = Buffer.from(input);
|
|
1675
|
+
const checksum = crc32(data);
|
|
1676
|
+
const local = Buffer.alloc(30);
|
|
1677
|
+
local.writeUInt32LE(67324752, 0);
|
|
1678
|
+
local.writeUInt16LE(20, 4);
|
|
1679
|
+
local.writeUInt16LE(2048, 6);
|
|
1680
|
+
local.writeUInt16LE(33, 12);
|
|
1681
|
+
local.writeUInt32LE(checksum, 14);
|
|
1682
|
+
local.writeUInt32LE(data.length, 18);
|
|
1683
|
+
local.writeUInt32LE(data.length, 22);
|
|
1684
|
+
local.writeUInt16LE(encoded.length, 26);
|
|
1685
|
+
const entry = Buffer.alloc(46);
|
|
1686
|
+
entry.writeUInt32LE(33639248, 0);
|
|
1687
|
+
entry.writeUInt16LE(20, 4);
|
|
1688
|
+
local.copy(entry, 6, 4, 30);
|
|
1689
|
+
entry.writeUInt32LE(offset, 42);
|
|
1690
|
+
parts.push(local, encoded, data);
|
|
1691
|
+
central.push(entry, encoded);
|
|
1692
|
+
offset += local.length + encoded.length + data.length;
|
|
1693
|
+
centralBytes += entry.length + encoded.length;
|
|
1694
|
+
if (centralBytes > runtimeUploadLimits.centralDirectoryBytes || offset + centralBytes + 22 > runtimeUploadLimits.archiveBytes) {
|
|
1695
|
+
throw new Error("External game ZIP exceeds the platform size limit");
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1698
|
+
if (!hasEntryPoint)
|
|
1699
|
+
throw new Error("External game archive requires a non-empty root index.html");
|
|
1700
|
+
for (const key of names) {
|
|
1701
|
+
let parent = key;
|
|
1702
|
+
while (parent.includes("/")) {
|
|
1703
|
+
parent = parent.slice(0, parent.lastIndexOf("/"));
|
|
1704
|
+
if (names.has(parent))
|
|
1705
|
+
throw new Error("External game archive has conflicting file and directory paths");
|
|
1706
|
+
}
|
|
1707
|
+
}
|
|
1708
|
+
const end = Buffer.alloc(22);
|
|
1709
|
+
end.writeUInt32LE(101010256, 0);
|
|
1710
|
+
end.writeUInt16LE(names.size, 8);
|
|
1711
|
+
end.writeUInt16LE(names.size, 10);
|
|
1712
|
+
end.writeUInt32LE(centralBytes, 12);
|
|
1713
|
+
end.writeUInt32LE(offset, 16);
|
|
1714
|
+
const bytes = offset + centralBytes + end.length;
|
|
1715
|
+
parts.push(...central, end);
|
|
1716
|
+
const hash = createHash4("sha256");
|
|
1717
|
+
for (const part of parts)
|
|
1718
|
+
hash.update(part);
|
|
1719
|
+
signal?.throwIfAborted();
|
|
1720
|
+
return { parts, bytes, sha256: hash.digest("hex") };
|
|
1721
|
+
}
|
|
1722
|
+
|
|
1723
|
+
// sdk/external-game-content.mjs
|
|
1724
|
+
import { createHash as createHash5 } from "node:crypto";
|
|
1725
|
+
import { promisify as promisify2 } from "node:util";
|
|
1726
|
+
import { gzip as gzip2 } from "node:zlib";
|
|
1727
|
+
var compress2 = promisify2(gzip2);
|
|
1728
|
+
var digestPattern2 = /^[0-9a-f]{64}$/;
|
|
1729
|
+
async function encodeExternalGameContent2(archive, signal) {
|
|
1730
|
+
signal?.throwIfAborted();
|
|
1731
|
+
if (!Number.isSafeInteger(archive?.bytes) || archive.bytes < 22 || archive.bytes > runtimeUploadLimits.archiveBytes || !Array.isArray(archive.parts) || !digestPattern2.test(archive.sha256 ?? "")) {
|
|
1732
|
+
throw new Error("Invalid external game ZIP metadata or platform size limit");
|
|
1733
|
+
}
|
|
1734
|
+
let bytes = 0;
|
|
1735
|
+
const hash = createHash5("sha256");
|
|
1736
|
+
for (const part of archive.parts) {
|
|
1737
|
+
signal?.throwIfAborted();
|
|
1738
|
+
if (!(part instanceof Uint8Array)) throw new Error("Invalid external game ZIP part");
|
|
1739
|
+
bytes += part.byteLength;
|
|
1740
|
+
if (bytes > archive.bytes) throw new Error("External game ZIP length does not match its prepared metadata");
|
|
1741
|
+
hash.update(part);
|
|
1742
|
+
}
|
|
1743
|
+
if (bytes !== archive.bytes) throw new Error("External game ZIP length does not match its prepared metadata");
|
|
1744
|
+
if (hash.digest("hex") !== archive.sha256) throw new Error("External game ZIP SHA-256 does not match its prepared metadata");
|
|
1745
|
+
let encoded;
|
|
1746
|
+
try {
|
|
1747
|
+
encoded = await compress2(Buffer.concat(archive.parts, bytes), { maxOutputLength: runtimeUploadLimits.gzipBytes });
|
|
1748
|
+
} catch (error) {
|
|
1749
|
+
if (error.code === "ERR_BUFFER_TOO_LARGE") throw new Error("Compressed external game ZIP exceeds the platform size limit");
|
|
1750
|
+
throw error;
|
|
1751
|
+
}
|
|
1752
|
+
signal?.throwIfAborted();
|
|
1753
|
+
if (encoded.length > runtimeUploadLimits.gzipBytes) throw new Error("Compressed external game ZIP exceeds the platform size limit");
|
|
1754
|
+
const body = { archive_encoded: encoded.toString("base64") };
|
|
1755
|
+
if (Buffer.byteLength(JSON.stringify(body)) > runtimeUploadLimits.jsonBytes) throw new Error("External game JSON exceeds the platform size limit");
|
|
1756
|
+
return body;
|
|
1757
|
+
}
|
|
1758
|
+
async function externalGameUploadRequest2(kind, options, signal) {
|
|
1759
|
+
if (kind !== "upload") return externalGameUploadRequest(kind, options, signal);
|
|
1760
|
+
const status = await externalGameUploadRequest("status", options, signal);
|
|
1761
|
+
if (!options.archive) throw new Error("External game ZIP is required");
|
|
1762
|
+
return {
|
|
1763
|
+
endpoint: status.endpoint + "/content",
|
|
1764
|
+
method: "POST",
|
|
1765
|
+
body: await encodeExternalGameContent2(options.archive, signal)
|
|
1766
|
+
};
|
|
1767
|
+
}
|
|
1704
1768
|
export {
|
|
1705
1769
|
buildJsStatic,
|
|
1706
1770
|
encodeExternalGameArchive,
|
|
1707
|
-
encodeExternalGameContent,
|
|
1708
|
-
externalGameUploadRequest,
|
|
1771
|
+
encodeExternalGameContent2 as encodeExternalGameContent,
|
|
1772
|
+
externalGameUploadRequest2 as externalGameUploadRequest,
|
|
1709
1773
|
finalizeGameContext,
|
|
1710
1774
|
installProjectDependencies,
|
|
1711
1775
|
parseExternalGameUploadReceipt,
|
|
1712
1776
|
prepareBrowserEnvironment,
|
|
1713
|
-
prepareStaticArtifacts,
|
|
1777
|
+
prepareStaticArtifacts2 as prepareStaticArtifacts,
|
|
1714
1778
|
runProcess,
|
|
1715
1779
|
seedProjectTemplate
|
|
1716
1780
|
};
|