playcanvas-agent-bridge-cli 0.6.1 → 0.7.0
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 +148 -31
- package/README.zh-CN.md +137 -33
- package/dist/cli.js +514 -95
- package/dist/config.js +23 -1
- package/dist/daemon/server.js +336 -28
- package/dist/daemon/target-registry.js +3 -0
- package/dist/plugins/host.js +260 -0
- package/dist/plugins/store.js +567 -0
- package/dist/processing/manager.js +265 -0
- package/dist/processing/tools.js +97 -0
- package/dist/snippets.js +27 -0
- package/dist/updates.js +475 -0
- package/dist/workspace/json-sync.js +821 -0
- package/dist/workspace/manager.js +1973 -326
- package/extension/icons/icon-128.png +0 -0
- package/extension/icons/icon-16.png +0 -0
- package/extension/icons/icon-256.png +0 -0
- package/extension/icons/icon-32.png +0 -0
- package/extension/icons/icon-48.png +0 -0
- package/extension/isolated.js +59 -2
- package/extension/main.js +770 -275
- package/extension/manifest.json +60 -10
- package/extension/popup.html +115 -3
- package/extension/popup.js +398 -14
- package/extension/service-worker.js +221 -4
- package/package.json +18 -18
- package/plugins/index.json +14 -0
- package/plugins/tinyapp-builder/node/builder.js +589 -0
- package/plugins/tinyapp-builder/node/index.js +30 -0
- package/plugins/tinyapp-builder/package.json +13 -0
- package/plugins/tinyapp-builder/page/editor.js +249 -0
- package/plugins/tinyapp-builder/pcbridge-plugin.json +28 -0
- package/skills/claude/pcbridge-plugin-authoring/SKILL.md +220 -0
- package/skills/claude/playcanvas-agent-bridge-cli/SKILL.md +99 -43
- package/skills/codex/pcbridge-plugin-authoring/SKILL.md +220 -0
- package/skills/codex/pcbridge-plugin-authoring/agents/openai.yaml +4 -0
- package/skills/codex/playcanvas-agent-bridge-cli/SKILL.md +89 -62
- package/skills/cursor/pcbridge-plugin-authoring.mdc +221 -0
- package/skills/cursor/playcanvas-agent-bridge-cli.mdc +69 -33
- package/skills/windsurf/pcbridge-plugin-authoring.md +215 -0
- package/skills/windsurf/playcanvas-agent-bridge-cli.md +68 -33
- package/dist/builder/manager.js +0 -564
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
+
import { mkdir, mkdtemp, open, readFile, readdir, realpath, rm, stat, writeFile } from "node:fs/promises";
|
|
3
|
+
import { createReadStream } from "node:fs";
|
|
4
|
+
import { spawn } from "node:child_process";
|
|
5
|
+
import { dirname, join, relative, sep } from "node:path";
|
|
6
|
+
import { createRequire } from "node:module";
|
|
7
|
+
import { activeTools, MEMORY_BYTES, RECIPE, TOOLS_ROOT } from "./tools.js";
|
|
8
|
+
export const CHUNK_BYTES = 256 * 1024;
|
|
9
|
+
async function digest(path) {
|
|
10
|
+
const h = createHash("md5");
|
|
11
|
+
for await (const chunk of createReadStream(path))
|
|
12
|
+
h.update(chunk);
|
|
13
|
+
return h.digest("hex");
|
|
14
|
+
}
|
|
15
|
+
export class ProcessingManager {
|
|
16
|
+
projectDirectory;
|
|
17
|
+
tasks = new Map();
|
|
18
|
+
timer;
|
|
19
|
+
constructor(projectDirectory) {
|
|
20
|
+
this.projectDirectory = projectDirectory;
|
|
21
|
+
this.timer = setInterval(() => {
|
|
22
|
+
for (const task of this.tasks.values())
|
|
23
|
+
if (Date.now() - task.touched > 90000)
|
|
24
|
+
void this.remove(task);
|
|
25
|
+
if (this.tasks.size)
|
|
26
|
+
void readFile(join(TOOLS_ROOT, "settings.json"), "utf8").then(text => {
|
|
27
|
+
if (JSON.parse(text).enabled !== true)
|
|
28
|
+
for (const task of this.tasks.values())
|
|
29
|
+
void this.remove(task);
|
|
30
|
+
}).catch(() => { for (const task of this.tasks.values())
|
|
31
|
+
void this.remove(task); });
|
|
32
|
+
}, 10000);
|
|
33
|
+
this.timer.unref();
|
|
34
|
+
}
|
|
35
|
+
async capabilities() {
|
|
36
|
+
const config = JSON.parse(await readFile(join(TOOLS_ROOT, "settings.json"), "utf8").catch(() => '{}'));
|
|
37
|
+
const memoryBytes = Number(config.memoryBytes || MEMORY_BYTES);
|
|
38
|
+
const timeoutMs = Number(config.timeoutMs || 600000);
|
|
39
|
+
if (!Number.isSafeInteger(memoryBytes) || memoryBytes < 64 * 1024 * 1024 || memoryBytes > MEMORY_BYTES ||
|
|
40
|
+
!Number.isSafeInteger(timeoutMs) || timeoutMs < 1000 || timeoutMs > 600000)
|
|
41
|
+
throw new Error("INVALID_PROCESSING_LIMITS");
|
|
42
|
+
const base = { bridgeProtocolVersion: 1, processingProtocolVersion: 1, recipeVersion: RECIPE,
|
|
43
|
+
targetEngine: "1.77.0", memoryBudgetBytes: memoryBytes, timeoutMs, enabled: config.enabled === true,
|
|
44
|
+
toolRelease: null, toolFingerprints: [], busy: this.tasks.size > 0, available: false, formats: { texture: [], model: [] } };
|
|
45
|
+
if (!base.enabled)
|
|
46
|
+
return { ...base, reason: "LOCAL_DISABLED" };
|
|
47
|
+
try {
|
|
48
|
+
const { manifest } = await activeTools();
|
|
49
|
+
return { ...base, available: !base.busy, formats: manifest.formats, toolRelease: manifest.release,
|
|
50
|
+
toolFingerprints: Object.values(manifest.binaries).map(spec => spec.sha256), reason: base.busy ? "LOCAL_BUSY" : null };
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return { ...base, reason: "TOOLS_UNAVAILABLE" };
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
requireTask(target, id) {
|
|
57
|
+
const task = typeof id === "string" ? this.tasks.get(id) : null;
|
|
58
|
+
if (!task || task.targetId !== target.id || task.clientId !== target.clientId || task.branchId !== target.branchId)
|
|
59
|
+
throw new Error("PROCESSING_TARGET_MISMATCH");
|
|
60
|
+
task.touched = Date.now();
|
|
61
|
+
return task;
|
|
62
|
+
}
|
|
63
|
+
async request(target, action, body) {
|
|
64
|
+
if (target.kind !== "editor" || target.platform !== "selfhost")
|
|
65
|
+
throw new Error("SELFHOST_EDITOR_REQUIRED");
|
|
66
|
+
if (target.processingProtocolVersion !== 1)
|
|
67
|
+
throw new Error("PROCESSING_EDITOR_UNSUPPORTED");
|
|
68
|
+
if (action === "capabilities")
|
|
69
|
+
return this.capabilities();
|
|
70
|
+
if (action === "begin") {
|
|
71
|
+
const caps = await this.capabilities();
|
|
72
|
+
if (!caps.available || this.tasks.size)
|
|
73
|
+
throw new Error("LOCAL_UNAVAILABLE");
|
|
74
|
+
const source = body.source;
|
|
75
|
+
if (!source || !/^[^/\\\x00-\x1f]{1,200}$/.test(source.filename) || source.filename === "." || source.filename === ".." ||
|
|
76
|
+
!Number.isSafeInteger(source.size) || source.size < 1 || source.size > caps.memoryBudgetBytes / 2 ||
|
|
77
|
+
!/^[a-f0-9]{32}$/.test(source.hash) || !["model", "texture"].includes(body.kind) ||
|
|
78
|
+
typeof body.jobId !== "string" || body.jobId.length > 100)
|
|
79
|
+
throw new Error("INVALID_PROCESSING_TASK");
|
|
80
|
+
// Only copy the allowlisted fields; server leases and signed URLs never enter a task.
|
|
81
|
+
const project = this.projectDirectory(target);
|
|
82
|
+
if (!project)
|
|
83
|
+
throw new Error("WORKSPACE_NOT_READY");
|
|
84
|
+
const root = join(project, "tmp", "processing");
|
|
85
|
+
await mkdir(root, { recursive: true });
|
|
86
|
+
if (!(await realpath(root)).startsWith((await realpath(project)) + sep))
|
|
87
|
+
throw new Error("PROCESSING_PATH_ESCAPE");
|
|
88
|
+
for (const name of await readdir(root)) {
|
|
89
|
+
if (!name.startsWith("job-"))
|
|
90
|
+
continue;
|
|
91
|
+
const stale = join(root, name);
|
|
92
|
+
if (Date.now() - (await stat(stale)).mtimeMs > 7 * 86400000)
|
|
93
|
+
await rm(stale, { recursive: true, force: true });
|
|
94
|
+
}
|
|
95
|
+
const directory = await mkdtemp(join(root, "job-"));
|
|
96
|
+
if (this.tasks.size) {
|
|
97
|
+
await rm(directory, { recursive: true });
|
|
98
|
+
throw new Error("LOCAL_BUSY");
|
|
99
|
+
}
|
|
100
|
+
const task = { id: randomUUID(), targetId: target.id, clientId: target.clientId, branchId: target.branchId, jobId: body.jobId,
|
|
101
|
+
directory, source: { filename: source.filename, size: source.size, hash: source.hash }, offset: 0,
|
|
102
|
+
state: "receiving", phase: "download", progress: 0, touched: Date.now(), files: {}, busy: false, memoryBytes: caps.memoryBudgetBytes, timeoutMs: caps.timeoutMs,
|
|
103
|
+
job: { filename: source.filename, kind: body.kind, options: body.options || {} } };
|
|
104
|
+
this.tasks.set(task.id, task);
|
|
105
|
+
await writeFile(join(directory, "source"), Buffer.alloc(0));
|
|
106
|
+
return { transferId: task.id, chunkBytes: CHUNK_BYTES };
|
|
107
|
+
}
|
|
108
|
+
const task = this.requireTask(target, body.transferId);
|
|
109
|
+
if (action === "cancel" || action === "finish") {
|
|
110
|
+
await this.remove(task);
|
|
111
|
+
return { removed: true };
|
|
112
|
+
}
|
|
113
|
+
if (action === "status")
|
|
114
|
+
return { state: task.state, phase: task.phase, progress: task.progress, error: task.error,
|
|
115
|
+
manifest: task.manifest, files: Object.fromEntries(Object.entries(task.files).map(([id, { path, ...file }]) => [id, file])) };
|
|
116
|
+
if (task.busy)
|
|
117
|
+
throw new Error("PROCESSING_TRANSFER_BUSY");
|
|
118
|
+
task.busy = true;
|
|
119
|
+
try {
|
|
120
|
+
if (action === "chunk") {
|
|
121
|
+
if (task.state !== "receiving" || !Number.isSafeInteger(body.offset) || body.offset < 0 ||
|
|
122
|
+
typeof body.data !== "string" || body.data.length > Math.ceil(CHUNK_BYTES / 3) * 4 || !/^[A-Za-z0-9+/]*={0,2}$/.test(body.data))
|
|
123
|
+
throw new Error("INVALID_PROCESSING_CHUNK");
|
|
124
|
+
const bytes = Buffer.from(body.data, "base64");
|
|
125
|
+
if (!bytes.length || bytes.length > CHUNK_BYTES || bytes.toString("base64") !== body.data || body.offset + bytes.length > task.source.size)
|
|
126
|
+
throw new Error("INVALID_PROCESSING_CHUNK");
|
|
127
|
+
const file = await open(join(task.directory, "source"), "r+");
|
|
128
|
+
try {
|
|
129
|
+
if (body.offset < task.offset) {
|
|
130
|
+
const old = Buffer.alloc(bytes.length);
|
|
131
|
+
await file.read(old, 0, old.length, body.offset);
|
|
132
|
+
if (body.offset + bytes.length > task.offset || !old.equals(bytes))
|
|
133
|
+
throw new Error("PROCESSING_CHUNK_CONFLICT");
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
if (body.offset !== task.offset)
|
|
137
|
+
throw new Error("PROCESSING_CHUNK_ORDER");
|
|
138
|
+
await file.write(bytes, 0, bytes.length, task.offset);
|
|
139
|
+
task.offset += bytes.length;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
finally {
|
|
143
|
+
await file.close();
|
|
144
|
+
}
|
|
145
|
+
return { offset: task.offset };
|
|
146
|
+
}
|
|
147
|
+
if (action === "run") {
|
|
148
|
+
if (task.state !== "receiving" || task.offset !== task.source.size || await digest(join(task.directory, "source")) !== task.source.hash)
|
|
149
|
+
throw new Error("PROCESSING_SOURCE_INTEGRITY");
|
|
150
|
+
task.state = "running";
|
|
151
|
+
void this.convert(task).catch(error => { task.state = "failed"; task.error = String(error).slice(0, 2000); });
|
|
152
|
+
return { state: task.state };
|
|
153
|
+
}
|
|
154
|
+
if (action === "read") {
|
|
155
|
+
const file = task.files[body.fileId];
|
|
156
|
+
if (task.state !== "computed" || !file || !Number.isSafeInteger(body.offset) || body.offset < 0 || body.offset >= file.size)
|
|
157
|
+
throw new Error("INVALID_PROCESSING_READ");
|
|
158
|
+
const bytes = Buffer.alloc(Math.min(CHUNK_BYTES, file.size - body.offset));
|
|
159
|
+
const handle = await open(file.path, "r");
|
|
160
|
+
try {
|
|
161
|
+
await handle.read(bytes, 0, bytes.length, body.offset);
|
|
162
|
+
}
|
|
163
|
+
finally {
|
|
164
|
+
await handle.close();
|
|
165
|
+
}
|
|
166
|
+
return { offset: body.offset, data: bytes.toString("base64") };
|
|
167
|
+
}
|
|
168
|
+
throw new Error("UNKNOWN_PROCESSING_ACTION");
|
|
169
|
+
}
|
|
170
|
+
finally {
|
|
171
|
+
task.busy = false;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
async convert(task) {
|
|
175
|
+
const { directory, manifest } = await activeTools();
|
|
176
|
+
const config = { job: task.job, input: join(task.directory, "source"), directory: task.directory,
|
|
177
|
+
memoryBytes: task.memoryBytes, executable: join(directory, manifest.binaries.modelConverter.path),
|
|
178
|
+
textureExecutable: join(directory, manifest.binaries.textureConverter.path),
|
|
179
|
+
catalogPath: join(directory, manifest.catalog.path), includeThumbnails: true };
|
|
180
|
+
const configPath = join(task.directory, "input.json");
|
|
181
|
+
await writeFile(configPath, JSON.stringify(config));
|
|
182
|
+
const require = createRequire(import.meta.url);
|
|
183
|
+
const sharpModules = dirname(dirname(dirname(require.resolve("sharp"))));
|
|
184
|
+
if (!this.tasks.has(task.id))
|
|
185
|
+
return;
|
|
186
|
+
const proc = spawn(process.execPath, [join(directory, manifest.runner.path), configPath], {
|
|
187
|
+
cwd: task.directory, detached: process.platform !== "win32",
|
|
188
|
+
env: { PATH: process.env.PATH || "/usr/bin:/bin", NODE_PATH: sharpModules,
|
|
189
|
+
IMPORT_WORKER_MEMORY_BYTES: String(task.memoryBytes) }, stdio: ["ignore", "pipe", "pipe"]
|
|
190
|
+
});
|
|
191
|
+
task.process = proc;
|
|
192
|
+
let errorOutput = "", pending = "";
|
|
193
|
+
proc.stderr?.on("data", chunk => { errorOutput = (errorOutput + chunk).slice(-2000); });
|
|
194
|
+
proc.stdout?.on("data", chunk => {
|
|
195
|
+
pending = (pending + chunk).slice(-8000);
|
|
196
|
+
const lines = pending.split("\n");
|
|
197
|
+
pending = lines.pop() || "";
|
|
198
|
+
for (const line of lines)
|
|
199
|
+
try {
|
|
200
|
+
const progress = JSON.parse(line);
|
|
201
|
+
if (Number.isFinite(progress.progress))
|
|
202
|
+
task.progress = Math.min(.9, Math.max(0, progress.progress));
|
|
203
|
+
if (typeof progress.phase === "string")
|
|
204
|
+
task.phase = progress.phase.slice(0, 80);
|
|
205
|
+
}
|
|
206
|
+
catch { /* native diagnostics are not protocol messages */ }
|
|
207
|
+
});
|
|
208
|
+
const timeout = setTimeout(() => this.kill(task), task.timeoutMs);
|
|
209
|
+
try {
|
|
210
|
+
const code = await new Promise((resolveExit, reject) => { proc.once("error", reject); proc.once("exit", resolveExit); });
|
|
211
|
+
if (code !== 0)
|
|
212
|
+
throw new Error(`CONVERTER_FAILED: ${errorOutput}`);
|
|
213
|
+
}
|
|
214
|
+
finally {
|
|
215
|
+
clearTimeout(timeout);
|
|
216
|
+
task.process = undefined;
|
|
217
|
+
}
|
|
218
|
+
if (!this.tasks.has(task.id))
|
|
219
|
+
return;
|
|
220
|
+
const resultPath = join(task.directory, "result.json");
|
|
221
|
+
if ((await stat(resultPath)).size > 32 * 1024 * 1024)
|
|
222
|
+
throw new Error("PROCESSING_MANIFEST_TOO_LARGE");
|
|
223
|
+
const result = JSON.parse(await readFile(resultPath, "utf8"));
|
|
224
|
+
if (!Array.isArray(result.artifacts) || result.artifacts.length > 10000)
|
|
225
|
+
throw new Error("PROCESSING_ARTIFACT_LIMIT");
|
|
226
|
+
let total = 0;
|
|
227
|
+
const addFile = async (artifact, artifactId, role, variant) => {
|
|
228
|
+
const path = await realpath(artifact.localFile);
|
|
229
|
+
if (relative(task.directory, path).startsWith("..") || !path.startsWith(task.directory + sep))
|
|
230
|
+
throw new Error("PROCESSING_OUTPUT_ESCAPE");
|
|
231
|
+
const size = (await stat(path)).size;
|
|
232
|
+
total += size;
|
|
233
|
+
if (size > 256 * 1024 * 1024 || total > MEMORY_BYTES * 2)
|
|
234
|
+
throw new Error("PROCESSING_OUTPUT_BUDGET");
|
|
235
|
+
const id = randomUUID();
|
|
236
|
+
task.files[id] = { path, size, hash: await digest(path), filename: artifact.filename, mime: artifact.mime || "application/octet-stream", role, artifactId, artifactType: artifact.type, variant };
|
|
237
|
+
delete artifact.localFile;
|
|
238
|
+
artifact.fileId = id;
|
|
239
|
+
};
|
|
240
|
+
for (const [i, artifact] of result.artifacts.entries()) {
|
|
241
|
+
if (artifact.localFile)
|
|
242
|
+
await addFile(artifact, String(i), "derived");
|
|
243
|
+
for (const [variant, thumb] of Object.entries(artifact.thumbnails || {}))
|
|
244
|
+
await addFile(thumb, String(i), "thumbnail", variant);
|
|
245
|
+
}
|
|
246
|
+
task.manifest = result;
|
|
247
|
+
task.state = "computed";
|
|
248
|
+
task.phase = "upload";
|
|
249
|
+
task.progress = .9;
|
|
250
|
+
}
|
|
251
|
+
kill(task) {
|
|
252
|
+
if (!task.process?.pid)
|
|
253
|
+
return;
|
|
254
|
+
try {
|
|
255
|
+
process.kill(process.platform === "win32" ? task.process.pid : -task.process.pid, "SIGKILL");
|
|
256
|
+
}
|
|
257
|
+
catch { /* already exited */ }
|
|
258
|
+
}
|
|
259
|
+
async remove(task) {
|
|
260
|
+
this.tasks.delete(task.id);
|
|
261
|
+
this.kill(task);
|
|
262
|
+
await rm(task.directory, { recursive: true, force: true });
|
|
263
|
+
}
|
|
264
|
+
async close() { clearInterval(this.timer); await Promise.all([...this.tasks.values()].map(task => this.remove(task))); }
|
|
265
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { mkdir, readFile, writeFile, mkdtemp, rm, rename, lstat, chmod } from "node:fs/promises";
|
|
3
|
+
import { join, resolve, dirname } from "node:path";
|
|
4
|
+
import { x } from "tar";
|
|
5
|
+
import { CONFIG_DIR } from "../config.js";
|
|
6
|
+
export const TOOLS_ROOT = join(CONFIG_DIR, "asset-tools");
|
|
7
|
+
export const RECIPE = "asset-tools-v7";
|
|
8
|
+
export const MEMORY_BYTES = 1024 * 1024 * 1024;
|
|
9
|
+
export const hash = (data, algorithm = "sha256") => createHash(algorithm).update(data).digest("hex");
|
|
10
|
+
export async function verifyTools(directory) {
|
|
11
|
+
const manifest = JSON.parse(await readFile(join(directory, "release.json"), "utf8"));
|
|
12
|
+
if (manifest.schemaVersion !== 1 || manifest.platform !== process.platform || manifest.arch !== process.arch ||
|
|
13
|
+
manifest.recipeVersion !== RECIPE || manifest.targetEngine !== "1.77.0")
|
|
14
|
+
throw new Error("TOOLS_PLATFORM_OR_RECIPE_MISMATCH");
|
|
15
|
+
for (const spec of [manifest.runner, manifest.catalog, ...Object.values(manifest.binaries)]) {
|
|
16
|
+
if (!/^(bin|runner|schema)\/[a-zA-Z0-9._-]+$/.test(spec.path))
|
|
17
|
+
throw new Error("TOOLS_INVALID_PATH");
|
|
18
|
+
const path = join(directory, spec.path);
|
|
19
|
+
const info = await lstat(path);
|
|
20
|
+
if (!info.isFile() || info.isSymbolicLink() || info.size !== spec.size || spec.size > 256 * 1024 * 1024 ||
|
|
21
|
+
hash(await readFile(path)) !== spec.sha256)
|
|
22
|
+
throw new Error("TOOLS_INTEGRITY_MISMATCH");
|
|
23
|
+
}
|
|
24
|
+
return manifest;
|
|
25
|
+
}
|
|
26
|
+
async function readInput(source, maxBytes) {
|
|
27
|
+
if (!/^https:\/\//.test(source)) {
|
|
28
|
+
const info = await lstat(source);
|
|
29
|
+
if (!info.isFile() || info.size > maxBytes)
|
|
30
|
+
throw new Error("TOOLS_DOWNLOAD_TOO_LARGE");
|
|
31
|
+
return readFile(source);
|
|
32
|
+
}
|
|
33
|
+
const response = await fetch(source, { signal: AbortSignal.timeout(120000), redirect: "follow" });
|
|
34
|
+
if (!response.url.startsWith("https://") || !response.ok || !response.body)
|
|
35
|
+
throw new Error(`TOOLS_DOWNLOAD_HTTP_${response.status}`);
|
|
36
|
+
const chunks = [];
|
|
37
|
+
let size = 0;
|
|
38
|
+
for await (const chunk of response.body) {
|
|
39
|
+
size += chunk.length;
|
|
40
|
+
if (size > maxBytes)
|
|
41
|
+
throw new Error("TOOLS_DOWNLOAD_TOO_LARGE");
|
|
42
|
+
chunks.push(chunk);
|
|
43
|
+
}
|
|
44
|
+
return Buffer.concat(chunks);
|
|
45
|
+
}
|
|
46
|
+
// Installation is an explicit local CLI action. Browser requests cannot install executable code.
|
|
47
|
+
export async function installTools(source) {
|
|
48
|
+
const manifestBytes = await readInput(source, 1024 * 1024);
|
|
49
|
+
const manifest = JSON.parse(manifestBytes.toString());
|
|
50
|
+
if (!/^[a-zA-Z0-9._-]{1,160}$/.test(manifest.release) || !/^[a-zA-Z0-9._-]+\.tar\.gz$/.test(manifest.archive.name))
|
|
51
|
+
throw new Error("TOOLS_INVALID_MANIFEST");
|
|
52
|
+
const archiveSource = /^https:\/\//.test(source) ? manifest.archive.url : resolve(dirname(source), manifest.archive.name);
|
|
53
|
+
const archive = await readInput(archiveSource, 256 * 1024 * 1024);
|
|
54
|
+
if (archive.length !== manifest.archive.size || hash(archive) !== manifest.archive.sha256)
|
|
55
|
+
throw new Error("TOOLS_ARCHIVE_INTEGRITY_MISMATCH");
|
|
56
|
+
await mkdir(TOOLS_ROOT, { recursive: true });
|
|
57
|
+
const staging = await mkdtemp(join(TOOLS_ROOT, ".install-"));
|
|
58
|
+
try {
|
|
59
|
+
const archivePath = join(staging, "package.tgz");
|
|
60
|
+
await writeFile(archivePath, archive);
|
|
61
|
+
let expanded = 0;
|
|
62
|
+
await x({ file: archivePath, cwd: staging, strict: true, filter: (path, entry) => {
|
|
63
|
+
if (!/^(?:bin|runner|schema)\/?$|^(?:bin|runner|schema)\/[a-zA-Z0-9._-]+$|^THIRD-PARTY-LICENSES.txt$/.test(path) ||
|
|
64
|
+
!("type" in entry) || !["File", "Directory"].includes(entry.type))
|
|
65
|
+
throw new Error("TOOLS_UNSAFE_ARCHIVE");
|
|
66
|
+
expanded += entry.size;
|
|
67
|
+
if (expanded > 512 * 1024 * 1024)
|
|
68
|
+
throw new Error("TOOLS_ARCHIVE_TOO_LARGE");
|
|
69
|
+
return true;
|
|
70
|
+
} });
|
|
71
|
+
await writeFile(join(staging, "release.json"), manifestBytes);
|
|
72
|
+
await verifyTools(staging);
|
|
73
|
+
for (const spec of Object.values(manifest.binaries))
|
|
74
|
+
await chmod(join(staging, spec.path), 0o755);
|
|
75
|
+
await rm(archivePath);
|
|
76
|
+
const destination = join(TOOLS_ROOT, `${manifest.release}-${manifest.archive.sha256.slice(0, 16)}`);
|
|
77
|
+
try {
|
|
78
|
+
await rename(staging, destination);
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
if (!["EEXIST", "ENOTEMPTY"].includes(error.code || ""))
|
|
82
|
+
throw error;
|
|
83
|
+
await verifyTools(destination);
|
|
84
|
+
}
|
|
85
|
+
await writeFile(join(TOOLS_ROOT, "active.json"), JSON.stringify({ directory: destination }));
|
|
86
|
+
return { release: manifest.release, directory: destination };
|
|
87
|
+
}
|
|
88
|
+
finally {
|
|
89
|
+
await rm(staging, { recursive: true, force: true });
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
export async function activeTools() {
|
|
93
|
+
const active = JSON.parse(await readFile(join(TOOLS_ROOT, "active.json"), "utf8"));
|
|
94
|
+
if (dirname(active.directory) !== TOOLS_ROOT)
|
|
95
|
+
throw new Error("TOOLS_INVALID_ACTIVE_PATH");
|
|
96
|
+
return { directory: active.directory, manifest: await verifyTools(active.directory) };
|
|
97
|
+
}
|
package/dist/snippets.js
CHANGED
|
@@ -1619,6 +1619,33 @@ return {
|
|
|
1619
1619
|
};
|
|
1620
1620
|
`;
|
|
1621
1621
|
}
|
|
1622
|
+
export function sceneManageSnippet() {
|
|
1623
|
+
return `
|
|
1624
|
+
const args = command.args || {};
|
|
1625
|
+
const list = () => new Promise((resolve, reject) => editor.call("scenes:list", resolve, reject));
|
|
1626
|
+
if (args.action === "list") return await list();
|
|
1627
|
+
if (args.action === "create") {
|
|
1628
|
+
if (!editor.call("permissions:write")) throw new Error("Scene creation requires write access.");
|
|
1629
|
+
return await new Promise((resolve, reject) => editor.call("scenes:new", args.name, resolve, reject));
|
|
1630
|
+
}
|
|
1631
|
+
const scenes = await list();
|
|
1632
|
+
const scene = scenes.find(item => String(item.id) === String(args.id) || String(item.uniqueId) === String(args.id));
|
|
1633
|
+
if (!scene) throw new Error("Scene not found in the current project: " + args.id);
|
|
1634
|
+
await new Promise((resolve, reject) => editor.call("scenes:get", String(scene.id), (error, data) => error ? reject(error) : resolve(data)));
|
|
1635
|
+
if (String(editor.api.globals.realtime.scenes.current?.uniqueId) === String(scene.uniqueId)) return scene;
|
|
1636
|
+
await new Promise((resolve, reject) => {
|
|
1637
|
+
const event = editor.on("scene:load", (id, uniqueId) => {
|
|
1638
|
+
if (String(uniqueId) !== String(scene.uniqueId)) return;
|
|
1639
|
+
clearTimeout(timer);
|
|
1640
|
+
event.unbind();
|
|
1641
|
+
resolve();
|
|
1642
|
+
});
|
|
1643
|
+
const timer = setTimeout(() => { event.unbind(); reject(new Error("Scene load timed out.")); }, 50000);
|
|
1644
|
+
editor.call("scene:load", scene.uniqueId);
|
|
1645
|
+
});
|
|
1646
|
+
return scene;
|
|
1647
|
+
`;
|
|
1648
|
+
}
|
|
1622
1649
|
export function sceneSettingsGetSnippet() {
|
|
1623
1650
|
return `
|
|
1624
1651
|
return editor.api.globals.settings.scene.json();
|