virtualmatter 0.6.8 → 0.8.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 +38 -7
- package/dist/agentfiles.js +1 -1
- package/dist/agents-md.generated.js +1 -1
- package/dist/asset-commands.js +154 -0
- package/dist/assets.js +395 -0
- package/dist/client.js +97 -14
- package/dist/depth.js +119 -0
- package/dist/files.js +151 -44
- package/dist/index.js +195 -12
- package/dist/mcp.js +154 -9
- package/dist/sync.js +83 -6
- package/dist/world-status.js +81 -0
- package/package.json +1 -1
package/dist/mcp.js
CHANGED
|
@@ -11,19 +11,24 @@ import { eventSchema } from "./log-events.js";
|
|
|
11
11
|
* and `select_project` work in that state, and every world-bound tool says
|
|
12
12
|
* how to pick one.
|
|
13
13
|
*/
|
|
14
|
+
import fs from "node:fs";
|
|
15
|
+
import os from "node:os";
|
|
16
|
+
import path from "node:path";
|
|
14
17
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
15
18
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
16
19
|
import { z } from "zod";
|
|
17
20
|
import { createProject, createWebsiteBuild, getWebsiteBuild, getEmbed, defaultRegion, editUrl, listProjects, playUrl, resolveEditSession, resolveSession, sessionBaseUrl, } from "./api.js";
|
|
21
|
+
import { attachAsset, findAsset, getJob, assetForJob, listAssets, listProjectAssets, placeInWorld, voxelizeSource, } from "./assets.js";
|
|
18
22
|
import { ensureClientInstalled, launchClient, seedNativeAuth } from "./client.js";
|
|
19
23
|
import { packageVersion } from "./config.js";
|
|
24
|
+
import { depthToNpy, depthToPreviewPng, describeDepth } from "./depth.js";
|
|
20
25
|
import { ConflictError, editSessionClient } from "./files.js";
|
|
21
26
|
import { acquireFolderLock } from "./lock.js";
|
|
22
27
|
import { pullCommand } from "./pull.js";
|
|
23
28
|
import { makeFramingOf, resolveTarget } from "./resolve.js";
|
|
24
29
|
import { loadState } from "./state.js";
|
|
25
30
|
import { SyncEngine } from "./sync.js";
|
|
26
|
-
import { bootSceneNotes, getDrift, getEngineLog, getEngineRestarts, getPublishRun, projectForEditor, startPublish, } from "./world-status.js";
|
|
31
|
+
import { bootSceneNotes, getDrift, getEngineIterations, getEngineLog, getEngineRestarts, getPublishRun, projectForEditor, publishMovesPlays, startPublish, } from "./world-status.js";
|
|
27
32
|
export function resolveFramingId(dir, framingFlag) {
|
|
28
33
|
if (framingFlag)
|
|
29
34
|
return framingFlag;
|
|
@@ -56,6 +61,12 @@ export const MCP_INSTRUCTIONS = [
|
|
|
56
61
|
"publish. The maker watches your changes land live at the watch_url that select_project",
|
|
57
62
|
"and world_info return (the editor with ?chat=closed), in any browser with no install.",
|
|
58
63
|
"open_native_client is optional, for more memory and frame rate, never required.",
|
|
64
|
+
"",
|
|
65
|
+
"3D models (GLB, OBJ, FBX, STL, point clouds, city tiles) go in through voxelize_model:",
|
|
66
|
+
"it uploads the file from disk, voxelizes it on Virtual Matter's voxelizer into the",
|
|
67
|
+
"maker's asset library, and can attach and place it in one call. Never paste mesh,",
|
|
68
|
+
"footprint or height-grid text into Lua or rebuild a model out of Lua primitives:",
|
|
69
|
+
"that burns credits and engine memory for a worse result.",
|
|
59
70
|
].join("\n");
|
|
60
71
|
const NO_WORLD = "No world is selected. Call select_project with a Virtual Matter URL or id, create_project to make a new one, or list_projects to see what exists.";
|
|
61
72
|
function makeContext(framingId) {
|
|
@@ -167,6 +178,53 @@ export async function patchRemoteFile(client, filePath, oldText, newText) {
|
|
|
167
178
|
}
|
|
168
179
|
}
|
|
169
180
|
}
|
|
181
|
+
const defaultWorldTargetDeps = {
|
|
182
|
+
resolveEditSession,
|
|
183
|
+
projectForEditor,
|
|
184
|
+
makeClient: (framingId, session) => editSessionClient(framingId, session),
|
|
185
|
+
};
|
|
186
|
+
/**
|
|
187
|
+
* Resolve `framingId` (read from the selection once, by the caller) to its
|
|
188
|
+
* editor, project and an engine client of its own. Nothing here reads the
|
|
189
|
+
* MCP selection again, so a later select_project cannot redirect the work.
|
|
190
|
+
*/
|
|
191
|
+
export async function captureWorldTarget(framingId, deps = defaultWorldTargetDeps) {
|
|
192
|
+
const { session, framingId: editor } = await deps.resolveEditSession(framingId);
|
|
193
|
+
const project = await deps.projectForEditor(editor);
|
|
194
|
+
return { project, framingId: editor, client: deps.makeClient(editor, session) };
|
|
195
|
+
}
|
|
196
|
+
const defaultAssetToolDeps = { voxelizeSource, findAsset, attachAsset, placeInWorld };
|
|
197
|
+
/** voxelize_model: voxelize, then attach to and place in `target` (when given) - never another world. */
|
|
198
|
+
export async function voxelizeModelInto(target, args, deps = defaultAssetToolDeps) {
|
|
199
|
+
const run = await deps.voxelizeSource(args.path, {
|
|
200
|
+
voxelsPerMeter: args.voxels_per_meter,
|
|
201
|
+
scale: args.scale,
|
|
202
|
+
method: args.method,
|
|
203
|
+
rotation: args.rotation_deg,
|
|
204
|
+
assetName: args.name,
|
|
205
|
+
wait: args.wait,
|
|
206
|
+
});
|
|
207
|
+
const out = { upload_id: run.upload.id, job: run.job, asset: run.asset };
|
|
208
|
+
if (target && run.asset) {
|
|
209
|
+
await deps.attachAsset(target.project.id, run.asset.id);
|
|
210
|
+
out.attached_to = target.project.name;
|
|
211
|
+
if (args.place) {
|
|
212
|
+
out.placed = await deps.placeInWorld(target.client, run.asset, { at: args.place });
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return out;
|
|
216
|
+
}
|
|
217
|
+
/** place_asset: attach to and place in `target` only. */
|
|
218
|
+
export async function placeAssetInto(target, args, deps = defaultAssetToolDeps) {
|
|
219
|
+
const asset = await deps.findAsset(args.asset);
|
|
220
|
+
await deps.attachAsset(target.project.id, asset.id);
|
|
221
|
+
return deps.placeInWorld(target.client, asset, {
|
|
222
|
+
at: args.at,
|
|
223
|
+
yawDeg: args.yaw_deg,
|
|
224
|
+
scale: args.scale,
|
|
225
|
+
name: args.name,
|
|
226
|
+
});
|
|
227
|
+
}
|
|
170
228
|
export async function runMcpServer(dir, framingFlag) {
|
|
171
229
|
const ctx = makeContext(resolveFramingId(dir, framingFlag));
|
|
172
230
|
// Instructions land in the host agent's system prompt, which is the only
|
|
@@ -352,14 +410,18 @@ export async function runMcpServer(dir, framingFlag) {
|
|
|
352
410
|
return textResult(JSON.stringify(await getEngineLog(framing, Math.max(1, tail ?? 100)), null, 2));
|
|
353
411
|
});
|
|
354
412
|
server.registerTool("play_server_status", {
|
|
355
|
-
description: "The selected world's play servers (what visitors play): whether each still matches the editor, which scene they load and when the editor last saved it, and how the last update went (per server). Use it before and after publish_play_servers.",
|
|
413
|
+
description: "The selected world's engine iteration (the editor's and each play server's, what each last booted, any mismatch between them, an announced platform move, and a link to what changed in the API) and its play servers (what visitors play): whether each still matches the editor, which scene they load and when the editor last saved it, and how the last update went (per server). Use it before and after publish_play_servers, and when engine behaviour looks different from what you expect.",
|
|
356
414
|
inputSchema: {},
|
|
357
415
|
}, async () => {
|
|
358
416
|
await ctx.getSession();
|
|
359
417
|
const project = await projectForEditor(ctx.requireFraming());
|
|
360
|
-
const [drift, last] = await Promise.all([
|
|
418
|
+
const [drift, last, engine] = await Promise.all([
|
|
419
|
+
getDrift(project.id),
|
|
420
|
+
getPublishRun(project.id),
|
|
421
|
+
getEngineIterations(project.id).catch(() => null),
|
|
422
|
+
]);
|
|
361
423
|
const notes = bootSceneNotes(drift, last?.send_played_scene ?? false);
|
|
362
|
-
return textResult(JSON.stringify({ project: project.name, boot_scene: notes.facts, drift, last_update: last }, null, 2));
|
|
424
|
+
return textResult(JSON.stringify({ project: project.name, engine, boot_scene: notes.facts, drift, last_update: last }, null, 2));
|
|
363
425
|
});
|
|
364
426
|
server.registerTool("publish_play_servers", {
|
|
365
427
|
description: "Publish the editor to the world's play servers (the project page's Update play servers): saves and pushes the editor's changes, copies its voxel data, and restarts each play server on it. Returns at once with the run and any warning about which scene the servers will load; poll play_server_status until last_update.status is done or failed (it can take minutes for a large terrain). Anyone playing briefly reconnects.",
|
|
@@ -379,8 +441,17 @@ export async function runMcpServer(dir, framingFlag) {
|
|
|
379
441
|
catch {
|
|
380
442
|
notes = null;
|
|
381
443
|
}
|
|
444
|
+
const warnings = [...(notes?.warnings ?? [])];
|
|
445
|
+
try {
|
|
446
|
+
const moving = publishMovesPlays(await getEngineIterations(project.id));
|
|
447
|
+
if (moving)
|
|
448
|
+
warnings.push(moving);
|
|
449
|
+
}
|
|
450
|
+
catch {
|
|
451
|
+
/* advice, not a gate */
|
|
452
|
+
}
|
|
382
453
|
const run = await startPublish(project.id, send_played_scene === true);
|
|
383
|
-
return textResult(JSON.stringify({ started: run, boot_scene: notes?.facts ?? null, warnings
|
|
454
|
+
return textResult(JSON.stringify({ started: run, boot_scene: notes?.facts ?? null, warnings }, null, 2));
|
|
384
455
|
});
|
|
385
456
|
server.registerTool("run_lua", {
|
|
386
457
|
description: "Execute a Lua snippet in the running Virtual Matter engine and return its result. target \"server\" (default) runs in the server-side Lua state where game logic lives; \"client\" runs in a connected client (someone must have the world open) - that is where UI, input and the camera live. With several clients connected, pass client_id; list them with target server and code 'return Server:GetClients()'. Use this to inspect live state, call engine APIs, or nudge the scene without editing files. If it fails with \"run-lua timed out\", the engine may still be running the snippet: check its effect before sending code that changes the world again.",
|
|
@@ -432,18 +503,36 @@ export async function runMcpServer(dir, framingFlag) {
|
|
|
432
503
|
.positive()
|
|
433
504
|
.optional()
|
|
434
505
|
.describe("Capture through this connected client, UI (HUD, menus) included - a server capture never shows UI. With no target/at/rot it is exactly what that client sees."),
|
|
506
|
+
depth: z
|
|
507
|
+
.boolean()
|
|
508
|
+
.optional()
|
|
509
|
+
.describe("Also read the frame's depth buffer (server view only, not with client_id). Returns a depth preview image (near is white, sky black) and its range, and saves the metres as a float32 .npy (height x width, distance along the view axis, 0 = sky) whose path is in the answer. One capture, no raycasts."),
|
|
435
510
|
},
|
|
436
|
-
}, async ({ target, at, rot, client_id }) => {
|
|
511
|
+
}, async ({ target, at, rot, client_id, depth }) => {
|
|
437
512
|
const client = await ctx.getClient();
|
|
438
|
-
const
|
|
513
|
+
const aim = {
|
|
439
514
|
target,
|
|
440
515
|
at: at,
|
|
441
516
|
rot: rot,
|
|
442
517
|
clientId: client_id,
|
|
443
|
-
}
|
|
518
|
+
};
|
|
519
|
+
if (!depth) {
|
|
520
|
+
const png = await client.screenshot(aim);
|
|
521
|
+
return {
|
|
522
|
+
content: [{ type: "image", data: png.toString("base64"), mimeType: "image/png" }],
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
const shot = await client.screenshotDepth(aim);
|
|
526
|
+
const npy = path.join(os.tmpdir(), `virtualmatter-depth-${Date.now()}.npy`);
|
|
527
|
+
fs.writeFileSync(npy, depthToNpy(shot.depth));
|
|
444
528
|
return {
|
|
445
529
|
content: [
|
|
446
|
-
{ type: "image", data:
|
|
530
|
+
{ type: "image", data: shot.image.toString("base64"), mimeType: shot.mediaType },
|
|
531
|
+
{ type: "image", data: depthToPreviewPng(shot.depth).toString("base64"), mimeType: "image/png" },
|
|
532
|
+
{
|
|
533
|
+
type: "text",
|
|
534
|
+
text: JSON.stringify({ summary: describeDepth(shot.depth.info), npy, ...shot.depth.info }),
|
|
535
|
+
},
|
|
447
536
|
],
|
|
448
537
|
};
|
|
449
538
|
});
|
|
@@ -458,6 +547,62 @@ export async function runMcpServer(dir, framingFlag) {
|
|
|
458
547
|
launchClient(installed, url);
|
|
459
548
|
return textResult(JSON.stringify({ launched: true, url, client_dir: installed.dir, signed_in_via_cli: signedIn.length > 0 }, null, 2));
|
|
460
549
|
});
|
|
550
|
+
/**
|
|
551
|
+
* The world an asset operation acts on, captured once when the operation
|
|
552
|
+
* starts. A select_project that lands while it runs must not split it:
|
|
553
|
+
* attach and place both go to this world, through a client of its own.
|
|
554
|
+
*/
|
|
555
|
+
const captureWorld = () => captureWorldTarget(ctx.requireFraming());
|
|
556
|
+
server.registerTool("voxelize_model", {
|
|
557
|
+
description: "Turn a 3D file on this machine (glb gltf fbx obj stl; ply pts xyz e57 las laz point clouds; vox; zip) into a voxel asset in the maker's library, on Virtual Matter's voxelizer: uploads it (resumable, up to 10 GiB), voxelizes it, and waits. With attach=true it also goes into the selected world's Assets/ folder, and with place it is put in the scene. The asset keeps the source's own coordinates in metres: place moves the source's 0,0,0, so map tiles placed with the same offset line up. Voxelizing takes seconds for a small model and can take an hour for a huge one; with wait=false it returns the job at once (poll get_voxelize_job). If placement fails the result says placed:false with the reason.",
|
|
558
|
+
inputSchema: {
|
|
559
|
+
path: z.string().describe("Local file path, or an upload id to voxelize again"),
|
|
560
|
+
voxels_per_meter: z.number().positive().optional().describe("Rounded to a power of two. Default 4 (25 cm voxels); city blocks 2-4, props 32-128"),
|
|
561
|
+
scale: z.union([z.number().positive(), z.literal("AUTO")]).optional().describe("Multiply the source's size; AUTO fits it to a default size. Default 1 (real-world metres)"),
|
|
562
|
+
method: z.enum(["FloodFill", "ShellOnly", "RayCast", "Projections", "Polymender"]).optional().describe("FloodFill (default) fills closed meshes solid; RayCast suits open meshes and terrain"),
|
|
563
|
+
rotation_deg: z.array(z.number()).length(3).optional().describe("Rotate the source first, [x, y, z] degrees; [-90, 0, 0] turns a Z-up model Y-up"),
|
|
564
|
+
name: z.string().min(1).max(100).optional().describe("Asset name (default: the file name)"),
|
|
565
|
+
attach: z.boolean().optional().describe("Attach the result to the selected world"),
|
|
566
|
+
place: z.array(z.number()).length(3).optional().describe("Also place it in the selected world: where the source's 0,0,0 goes"),
|
|
567
|
+
wait: z.boolean().optional().describe("Wait for the voxelizer (default true)"),
|
|
568
|
+
},
|
|
569
|
+
}, async (args) => {
|
|
570
|
+
const wantWorld = args.attach || args.place !== undefined;
|
|
571
|
+
if (wantWorld && args.wait === false)
|
|
572
|
+
throw new Error("attach and place need the finished asset; leave wait on.");
|
|
573
|
+
const target = wantWorld ? await captureWorld() : null;
|
|
574
|
+
return textResult(JSON.stringify(await voxelizeModelInto(target, args), null, 2));
|
|
575
|
+
});
|
|
576
|
+
server.registerTool("get_voxelize_job", {
|
|
577
|
+
description: "A voxelize job's status (queued, running, succeeded, failed, cancelled) and, once it succeeded, the library asset it made.",
|
|
578
|
+
inputSchema: { job_id: z.string() },
|
|
579
|
+
}, async ({ job_id }) => {
|
|
580
|
+
const job = await getJob(job_id);
|
|
581
|
+
const asset = job.status === "succeeded" ? await assetForJob(job.id) : null;
|
|
582
|
+
return textResult(JSON.stringify({ job, asset }, null, 2));
|
|
583
|
+
});
|
|
584
|
+
server.registerTool("list_assets", {
|
|
585
|
+
description: "The maker's asset library (voxelized models: id, name, voxel size, file size), or with project=true only the assets attached to the selected world.",
|
|
586
|
+
inputSchema: { project: z.boolean().optional().describe("Only the selected world's attached assets") },
|
|
587
|
+
}, async ({ project }) => {
|
|
588
|
+
const assets = project
|
|
589
|
+
? await listProjectAssets((await captureWorld()).project.id)
|
|
590
|
+
: (await listAssets()).filter((a) => a.status !== "deleted");
|
|
591
|
+
return textResult(JSON.stringify(assets, null, 2));
|
|
592
|
+
});
|
|
593
|
+
server.registerTool("place_asset", {
|
|
594
|
+
description: "Put a library asset (id or exact name) into the selected world's scene as a saved object at real-world size, attaching it to the world first if needed. at is where the source model's 0,0,0 goes, in metres (default [0, 0, 0]); yaw_deg turns it about the vertical axis; scale multiplies its real size. Returns the scene object's name, or placed:false with the reason.",
|
|
595
|
+
inputSchema: {
|
|
596
|
+
asset: z.string().describe("Asset id or exact name from list_assets"),
|
|
597
|
+
at: z.array(z.number()).length(3).optional(),
|
|
598
|
+
yaw_deg: z.number().optional(),
|
|
599
|
+
scale: z.number().positive().optional(),
|
|
600
|
+
name: z.string().optional().describe("Scene object name (default: the asset's name)"),
|
|
601
|
+
},
|
|
602
|
+
}, async (args) => {
|
|
603
|
+
const target = await captureWorld();
|
|
604
|
+
return textResult(JSON.stringify(await placeAssetInto(target, args), null, 2));
|
|
605
|
+
});
|
|
461
606
|
server.registerTool("world_info", {
|
|
462
607
|
description: "Return the selected world's framing id plus its URLs: the editor and play links a human can open, and the session API base this server talks to.",
|
|
463
608
|
inputSchema: {},
|
package/dist/sync.js
CHANGED
|
@@ -20,7 +20,7 @@ import { startLogSync } from "./agent-logs.js";
|
|
|
20
20
|
*/
|
|
21
21
|
import fs from "node:fs";
|
|
22
22
|
import path from "node:path";
|
|
23
|
-
import { ConflictError, MAX_WRITE_BYTES, SessionLostError, removeStaleDownloadTemps, } from "./files.js";
|
|
23
|
+
import { ConflictError, MAX_WRITE_BYTES, SessionLostError, WorldStoppedError, removeStaleDownloadTemps, } from "./files.js";
|
|
24
24
|
import { isIgnoredPath } from "./ignore.js";
|
|
25
25
|
import { supervisingPids, watchSupervisors } from "./lock.js";
|
|
26
26
|
import { loadState, adoptLocal, localHash, recordLocal, saveState, sha256Hex, syncedHash, } from "./state.js";
|
|
@@ -390,6 +390,14 @@ export class SyncEngine {
|
|
|
390
390
|
}
|
|
391
391
|
catch (err) {
|
|
392
392
|
if (err instanceof ConflictError) {
|
|
393
|
+
// The world's copy may still be exactly the file this edit started
|
|
394
|
+
// from: the engine rewrites some files at boot (aligned shader copies,
|
|
395
|
+
// 2026-10-21) without changing a byte, and the etag we held can be
|
|
396
|
+
// stale for other reasons. Then nothing was edited on the world's
|
|
397
|
+
// side and the push is a fast-forward, not a conflict.
|
|
398
|
+
const forwarded = await this.fastForward(relPath, body);
|
|
399
|
+
if (forwarded)
|
|
400
|
+
return forwarded;
|
|
393
401
|
// false: the world already holds exactly this file (an earlier push
|
|
394
402
|
// that landed, or another process) - recorded as in sync, not sent
|
|
395
403
|
return (await this.writeConflict(relPath)) ? "conflict" : "unchanged";
|
|
@@ -397,6 +405,49 @@ export class SyncEngine {
|
|
|
397
405
|
throw err;
|
|
398
406
|
}
|
|
399
407
|
}
|
|
408
|
+
/**
|
|
409
|
+
* After a 412: when the world's copy is byte-identical to this file's last
|
|
410
|
+
* synced content (etags are content hashes, so the listing says so without
|
|
411
|
+
* a download), overwrite it with `body` under the world's current etag.
|
|
412
|
+
* Returns null when the world really changed, so the caller reports the
|
|
413
|
+
* conflict; a second 412 (the world moved again meanwhile) is a conflict too.
|
|
414
|
+
*/
|
|
415
|
+
async fastForward(relPath, body) {
|
|
416
|
+
const base = syncedHash(this.state, relPath);
|
|
417
|
+
if (base === undefined)
|
|
418
|
+
return null;
|
|
419
|
+
let current;
|
|
420
|
+
try {
|
|
421
|
+
current = (await this.client.list()).find((f) => f.path === relPath)?.etag;
|
|
422
|
+
}
|
|
423
|
+
catch (err) {
|
|
424
|
+
rethrowFatal(err);
|
|
425
|
+
return null;
|
|
426
|
+
}
|
|
427
|
+
if (current === undefined)
|
|
428
|
+
return null;
|
|
429
|
+
if (current === sha256Hex(body)) {
|
|
430
|
+
this.state.etags[relPath] = current;
|
|
431
|
+
recordLocal(this.state, this.dir, relPath, body);
|
|
432
|
+
this.persist();
|
|
433
|
+
return "unchanged";
|
|
434
|
+
}
|
|
435
|
+
if (current !== base)
|
|
436
|
+
return null;
|
|
437
|
+
try {
|
|
438
|
+
const etag = await this.client.put(relPath, body, { etag: current });
|
|
439
|
+
this.state.etags[relPath] = etag;
|
|
440
|
+
recordLocal(this.state, this.dir, relPath, body);
|
|
441
|
+
this.persist();
|
|
442
|
+
this.log.info(`pushed ${relPath} (the world's copy was unchanged since the last sync)`);
|
|
443
|
+
return "pushed";
|
|
444
|
+
}
|
|
445
|
+
catch (err) {
|
|
446
|
+
if (err instanceof ConflictError)
|
|
447
|
+
return null;
|
|
448
|
+
throw err;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
400
451
|
/**
|
|
401
452
|
* Over the session API's write cap: the server would answer 413, so do not
|
|
402
453
|
* read the file at all (a multi-GB read would also exhaust memory). Warned
|
|
@@ -572,10 +623,11 @@ export class SyncEngine {
|
|
|
572
623
|
* One remote poll tick: pull files whose remote etag differs from our
|
|
573
624
|
* bookkeeping. Files we just pushed match by etag, so they are skipped
|
|
574
625
|
* naturally. A file with local changes that have not gone out yet is a
|
|
575
|
-
* conflict, never a pull. Returns the pulled paths.
|
|
626
|
+
* conflict, never a pull. Returns the pulled paths. Passive: a world whose
|
|
627
|
+
* engine was stopped throws WorldStoppedError rather than being started.
|
|
576
628
|
*/
|
|
577
629
|
async pollOnce() {
|
|
578
|
-
const remote = await this.client.list();
|
|
630
|
+
const remote = await this.client.list({ passive: true });
|
|
579
631
|
const pulled = [];
|
|
580
632
|
for (const file of remote) {
|
|
581
633
|
if (isIgnoredPath(file.path))
|
|
@@ -704,9 +756,19 @@ export async function runSyncLoop(engine, dir, opts = {}) {
|
|
|
704
756
|
console.warn(String(err));
|
|
705
757
|
});
|
|
706
758
|
};
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
759
|
+
// While the world's engine is stopped (the platform stops it when nobody is
|
|
760
|
+
// in it), the remote poll must not start it again: that is what kept a
|
|
761
|
+
// running sync's world from ever staying stopped. The poll then only looks
|
|
762
|
+
// about once a minute whether it is back; a local save pushes, which wakes
|
|
763
|
+
// it, and polling resumes on the next tick.
|
|
764
|
+
let worldStopped = false;
|
|
765
|
+
let nextStoppedLook = 0;
|
|
766
|
+
const lookNow = () => {
|
|
767
|
+
nextStoppedLook = 0;
|
|
768
|
+
};
|
|
769
|
+
watcher.on("add", (p) => enqueue(() => engine.handleLocalChange(path.relative(dir, p)).then(lookNow)));
|
|
770
|
+
watcher.on("change", (p) => enqueue(() => engine.handleLocalChange(path.relative(dir, p)).then(lookNow)));
|
|
771
|
+
watcher.on("unlink", (p) => enqueue(() => engine.handleLocalDelete(path.relative(dir, p)).then(lookNow)));
|
|
710
772
|
const interval = setInterval(() => {
|
|
711
773
|
enqueue(async () => {
|
|
712
774
|
try {
|
|
@@ -716,11 +778,26 @@ export async function runSyncLoop(engine, dir, opts = {}) {
|
|
|
716
778
|
rethrowFatal(err);
|
|
717
779
|
console.warn(`local scan failed: ${String(err)}`);
|
|
718
780
|
}
|
|
781
|
+
if (worldStopped && Date.now() < nextStoppedLook)
|
|
782
|
+
return;
|
|
719
783
|
try {
|
|
720
784
|
if (touchesSkills(await engine.pollOnce()))
|
|
721
785
|
await refreshSkills();
|
|
786
|
+
if (worldStopped) {
|
|
787
|
+
worldStopped = false;
|
|
788
|
+
console.log("The world is running again; sync is pulling its changes again.");
|
|
789
|
+
}
|
|
722
790
|
}
|
|
723
791
|
catch (err) {
|
|
792
|
+
if (err instanceof WorldStoppedError) {
|
|
793
|
+
if (!worldStopped) {
|
|
794
|
+
worldStopped = true;
|
|
795
|
+
console.log("The world's engine isn't running (stopped because nobody was in it, or still starting), " +
|
|
796
|
+
"so sync won't start it just to poll. Saving a file wakes it; until then sync looks once a minute whether it is back.");
|
|
797
|
+
}
|
|
798
|
+
nextStoppedLook = Date.now() + 60_000;
|
|
799
|
+
return;
|
|
800
|
+
}
|
|
724
801
|
rethrowFatal(err);
|
|
725
802
|
console.warn(`remote poll failed: ${String(err)}`);
|
|
726
803
|
}
|
package/dist/world-status.js
CHANGED
|
@@ -43,6 +43,9 @@ export async function projectForEditor(framingId, fetchFn = fetch) {
|
|
|
43
43
|
export function getDrift(montageId, fetchFn = fetch) {
|
|
44
44
|
return getJson(`/api/v1/montages/${encodeURIComponent(montageId)}/play-server-drift`, "Checking the play servers", fetchFn);
|
|
45
45
|
}
|
|
46
|
+
export function getEngineIterations(montageId, fetchFn = fetch) {
|
|
47
|
+
return getJson(`/api/v1/montages/${encodeURIComponent(montageId)}/engine-iterations`, "Reading the engine iterations", fetchFn);
|
|
48
|
+
}
|
|
46
49
|
export function getPublishRun(montageId, fetchFn = fetch) {
|
|
47
50
|
return getJson(`/api/v1/montages/${encodeURIComponent(montageId)}/play-server-sync`, "Reading the last update", fetchFn);
|
|
48
51
|
}
|
|
@@ -82,6 +85,63 @@ export async function waitForPublish(montageId, onChange, opts = {}) {
|
|
|
82
85
|
await sleep(opts.intervalMs ?? 3000);
|
|
83
86
|
}
|
|
84
87
|
}
|
|
88
|
+
/** "release/iteration076:24d309b487" -> "iteration076 @ 24d309b"; a bare branch as is. */
|
|
89
|
+
function prettySpec(spec) {
|
|
90
|
+
const [branch, commit] = spec.split(":");
|
|
91
|
+
const label = branch.startsWith("release/") ? branch.slice("release/".length) : branch;
|
|
92
|
+
return commit ? `${label} @ ${commit.slice(0, 7)}` : label;
|
|
93
|
+
}
|
|
94
|
+
function surfaceLine(s, now) {
|
|
95
|
+
const who = s.kind === "make" ? "editor " : `play ${(s.region ?? "").padEnd(6)}`;
|
|
96
|
+
const set = `${prettySpec(s.pinned)}${s.follows_default ? " (platform default)" : ""}`;
|
|
97
|
+
let ran = "never started";
|
|
98
|
+
if (s.running_branch) {
|
|
99
|
+
const build = prettySpec(s.running_commit ? `${s.running_branch}:${s.running_commit}` : s.running_branch);
|
|
100
|
+
const since = s.running_since ? ` ${s.live ? "since" : "last booted"} ${ago(s.running_since, now)}` : "";
|
|
101
|
+
ran = `${s.live ? "running" : "stopped,"} ${build}${since}`;
|
|
102
|
+
}
|
|
103
|
+
const flag = s.restart_pending ? " <- switches on its next restart" : "";
|
|
104
|
+
return ` ${who} ${set.padEnd(32)} ${ran}${flag}`;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* The world's engine iteration per surface, for `status`. A maker could not see
|
|
108
|
+
* this before 0.6.9: SCAR moved 073 -> 076 on 2026-10-20 and its agents found out
|
|
109
|
+
* from in-game breakage, and Ashlight's pin read 076 for hours while it ran 073.
|
|
110
|
+
*/
|
|
111
|
+
export function formatIterations(it, now = Date.now()) {
|
|
112
|
+
const out = ["Engine:"];
|
|
113
|
+
if (it.editor)
|
|
114
|
+
out.push(surfaceLine(it.editor, now));
|
|
115
|
+
for (const p of it.plays)
|
|
116
|
+
out.push(surfaceLine(p, now));
|
|
117
|
+
if (it.mismatch)
|
|
118
|
+
out.push(` Warning: ${it.detail}`);
|
|
119
|
+
for (const m of it.upcoming) {
|
|
120
|
+
const when = m.scheduled_for ? ` on ${m.scheduled_for.slice(0, 16).replace("T", " ")} UTC` : "";
|
|
121
|
+
out.push(` Announced: the platform will move this world to ${prettySpec(m.to_iteration)}${when}.${m.message ? ` ${m.message}` : ""}`);
|
|
122
|
+
if (m.changelog_url)
|
|
123
|
+
out.push(` What changes: ${m.changelog_url}`);
|
|
124
|
+
}
|
|
125
|
+
const last = it.history.find((m) => m.status === "done" && m.framing_id === it.editor?.framing_id);
|
|
126
|
+
if (last) {
|
|
127
|
+
const by = last.initiated_by === "maker" ? "by this account (Update on the project page)" : "by the platform";
|
|
128
|
+
const at = last.applied_at ?? last.created_at;
|
|
129
|
+
out.push(` Last move: ${last.from_iteration ? prettySpec(last.from_iteration) : "?"} -> ${prettySpec(last.to_iteration)} ${by}${at ? `, ${ago(at, now)}` : ""}.`);
|
|
130
|
+
}
|
|
131
|
+
if (it.changelog_url)
|
|
132
|
+
out.push(` What changed in this iteration: ${it.changelog_url}`);
|
|
133
|
+
return out;
|
|
134
|
+
}
|
|
135
|
+
/** A publish moves every play server to the editor's iteration; say so before it does. */
|
|
136
|
+
export function publishMovesPlays(it) {
|
|
137
|
+
if (!it.editor)
|
|
138
|
+
return null;
|
|
139
|
+
const moving = it.plays.filter((p) => p.pinned_iteration !== it.editor.pinned_iteration);
|
|
140
|
+
if (moving.length === 0)
|
|
141
|
+
return null;
|
|
142
|
+
const from = [...new Set(moving.map((p) => p.pinned_iteration))].join(", ");
|
|
143
|
+
return `This publish also moves ${moving.length === 1 ? "the play server" : `${moving.length} play servers`} from ${from} to the editor's ${it.editor.pinned_iteration}. A ${from} desktop app can't join them afterwards.`;
|
|
144
|
+
}
|
|
85
145
|
export function playLine(p) {
|
|
86
146
|
const what = p.detail ?? p.step;
|
|
87
147
|
return `${p.region.padEnd(3)} ${p.status.padEnd(8)} ${what} (${p.framing_id})`;
|
|
@@ -96,6 +156,23 @@ function ago(iso, now) {
|
|
|
96
156
|
return `${Math.round(s / 3600)} h ago`;
|
|
97
157
|
return `${Math.round(s / 86400)} days ago`;
|
|
98
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* How far the played scene's last save is ahead of InitScene's, or null when
|
|
161
|
+
* either is unknown. SCAR (2026-10-20): InitScene was 12 days older than the
|
|
162
|
+
* played scene the world really lived in, and a plain publish sent 147 of its
|
|
163
|
+
* 296 objects.
|
|
164
|
+
*/
|
|
165
|
+
export function playedSceneLead(drift) {
|
|
166
|
+
if (!drift.init_scene_saved_at || !drift.played_scene_saved_at)
|
|
167
|
+
return null;
|
|
168
|
+
return Date.parse(drift.played_scene_saved_at) - Date.parse(drift.init_scene_saved_at);
|
|
169
|
+
}
|
|
170
|
+
/** "Much newer": a day. Within one sitting the two scenes are routinely minutes apart. */
|
|
171
|
+
export const PLAYED_SCENE_NEWER_MS = 24 * 3600 * 1000;
|
|
172
|
+
function span(ms) {
|
|
173
|
+
const h = ms / 3600000;
|
|
174
|
+
return h < 48 ? `${Math.round(h)} hours` : `${Math.round(h / 24)} days`;
|
|
175
|
+
}
|
|
99
176
|
/**
|
|
100
177
|
* Which scene the play servers will boot, and the warnings worth a stop
|
|
101
178
|
* before publishing. Ashlight (2026-10-07): InitScene was the day-1 starter
|
|
@@ -113,6 +190,10 @@ export function bootSceneNotes(drift, sendPlayedScene, now = Date.now()) {
|
|
|
113
190
|
if (drift.played_terrain_left_out) {
|
|
114
191
|
warnings.push("InitScene doesn't use the terrain the editor plays on, so play servers will load InitScene's own terrain. Pass --played-scene, or save the world as InitScene in the editor first.");
|
|
115
192
|
}
|
|
193
|
+
const newer = playedSceneLead(drift);
|
|
194
|
+
if (newer !== null && newer >= PLAYED_SCENE_NEWER_MS) {
|
|
195
|
+
warnings.push(`The played scene was saved ${span(newer)} after InitScene, so InitScene may be missing what was built since. Pass --played-scene to publish the played scene, or --init-scene to publish InitScene anyway.`);
|
|
196
|
+
}
|
|
116
197
|
const init = drift.init_scene_volumes;
|
|
117
198
|
const played = drift.played_scene_volumes;
|
|
118
199
|
if (init != null && played != null && played - init >= 5 && played >= init * 1.5) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "virtualmatter",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "CLI + MCP server for building with Virtual Matter - list and create worlds, sync their files, run Lua, capture screenshots, open the native client, and wire coding agents into a live session.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|