virtualmatter 0.6.5 → 0.6.7
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 +37 -6
- package/dist/agent-logs.js +33 -5
- package/dist/agents-md.generated.js +1 -1
- package/dist/files.js +200 -19
- package/dist/ignore.js +12 -0
- package/dist/index.js +222 -22
- package/dist/lock.js +208 -0
- package/dist/log-events.js +2 -2
- package/dist/mcp.js +137 -3
- package/dist/pull.js +2 -2
- package/dist/sync.js +305 -36
- package/dist/world-status.js +161 -0
- package/package.json +1 -1
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The world as the platform sees it, for `logs`, `publish` and `status`:
|
|
3
|
+
* engine restarts and their reasons, the engine log, and publishing the
|
|
4
|
+
* editor to its play servers.
|
|
5
|
+
*
|
|
6
|
+
* Before these existed a coding agent could only publish by driving the
|
|
7
|
+
* website in the maker's signed-in browser, and could not see why the world
|
|
8
|
+
* it was testing kept restarting (Ashlight breakage report, 2026-10-08).
|
|
9
|
+
*/
|
|
10
|
+
import { authorizedFetch, listProjects } from "./api.js";
|
|
11
|
+
import { apiBase } from "./config.js";
|
|
12
|
+
async function getJson(path, what, fetchFn, init = {}) {
|
|
13
|
+
const res = await authorizedFetch(`${apiBase()}${path}`, init, fetchFn);
|
|
14
|
+
if (res.status === 404)
|
|
15
|
+
throw new Error(`${what}: not found, or this account can't edit that world.`);
|
|
16
|
+
if (!res.ok) {
|
|
17
|
+
let detail = "";
|
|
18
|
+
try {
|
|
19
|
+
const body = (await res.json());
|
|
20
|
+
detail = typeof body.detail === "string" ? body.detail : body.detail ? JSON.stringify(body.detail) : "";
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
/* not JSON */
|
|
24
|
+
}
|
|
25
|
+
throw new Error(`${what} failed: HTTP ${res.status}${detail ? ` - ${detail}` : ""}`);
|
|
26
|
+
}
|
|
27
|
+
return (await res.json());
|
|
28
|
+
}
|
|
29
|
+
export function getEngineRestarts(framingId, tail, fetchFn = fetch) {
|
|
30
|
+
return getJson(`/api/v1/framings/${encodeURIComponent(framingId)}/engine-restarts?tail=${tail}`, "Reading the engine's restarts", fetchFn);
|
|
31
|
+
}
|
|
32
|
+
export function getEngineLog(framingId, tail, fetchFn = fetch) {
|
|
33
|
+
return getJson(`/api/v1/framings/${encodeURIComponent(framingId)}/engine-log?tail=${tail}`, "Reading the engine log", fetchFn);
|
|
34
|
+
}
|
|
35
|
+
/** The project whose editor is `framingId`. */
|
|
36
|
+
export async function projectForEditor(framingId, fetchFn = fetch) {
|
|
37
|
+
const project = (await listProjects(fetchFn)).find((p) => p.make_framing_id === framingId);
|
|
38
|
+
if (!project) {
|
|
39
|
+
throw new Error(`Framing ${framingId} isn't the editor of a world this account owns, so it can't be published from here.`);
|
|
40
|
+
}
|
|
41
|
+
return project;
|
|
42
|
+
}
|
|
43
|
+
export function getDrift(montageId, fetchFn = fetch) {
|
|
44
|
+
return getJson(`/api/v1/montages/${encodeURIComponent(montageId)}/play-server-drift`, "Checking the play servers", fetchFn);
|
|
45
|
+
}
|
|
46
|
+
export function getPublishRun(montageId, fetchFn = fetch) {
|
|
47
|
+
return getJson(`/api/v1/montages/${encodeURIComponent(montageId)}/play-server-sync`, "Reading the last update", fetchFn);
|
|
48
|
+
}
|
|
49
|
+
export function startPublish(montageId, sendPlayedScene, fetchFn = fetch) {
|
|
50
|
+
return getJson(`/api/v1/montages/${encodeURIComponent(montageId)}/update-play-servers`, "Updating the play servers", fetchFn, {
|
|
51
|
+
method: "POST",
|
|
52
|
+
headers: { "Content-Type": "application/json" },
|
|
53
|
+
body: JSON.stringify({ send_played_scene: sendPlayedScene }),
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Poll a publish until it finishes, reporting each play's change once.
|
|
58
|
+
* Returns the final run. A run that resumes after a platform deploy keeps
|
|
59
|
+
* its id, so the same run is followed throughout.
|
|
60
|
+
*/
|
|
61
|
+
export async function waitForPublish(montageId, onChange, opts = {}) {
|
|
62
|
+
const sleep = opts.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
63
|
+
const seen = new Map();
|
|
64
|
+
let pushed = false;
|
|
65
|
+
for (;;) {
|
|
66
|
+
const run = await getPublishRun(montageId, opts.fetchFn);
|
|
67
|
+
if (run === null)
|
|
68
|
+
throw new Error("The update disappeared before it finished.");
|
|
69
|
+
if (run.commit_pushed && !pushed) {
|
|
70
|
+
pushed = true;
|
|
71
|
+
onChange("Saved and published your editor's latest changes.");
|
|
72
|
+
}
|
|
73
|
+
for (const p of run.plays) {
|
|
74
|
+
const line = playLine(p);
|
|
75
|
+
if (seen.get(p.framing_id) !== line) {
|
|
76
|
+
seen.set(p.framing_id, line);
|
|
77
|
+
onChange(line);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (run.status !== "running")
|
|
81
|
+
return run;
|
|
82
|
+
await sleep(opts.intervalMs ?? 3000);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
export function playLine(p) {
|
|
86
|
+
const what = p.detail ?? p.step;
|
|
87
|
+
return `${p.region.padEnd(3)} ${p.status.padEnd(8)} ${what} (${p.framing_id})`;
|
|
88
|
+
}
|
|
89
|
+
function ago(iso, now) {
|
|
90
|
+
const s = Math.max(0, Math.round((now - Date.parse(iso)) / 1000));
|
|
91
|
+
if (s < 90)
|
|
92
|
+
return `${s}s ago`;
|
|
93
|
+
if (s < 90 * 60)
|
|
94
|
+
return `${Math.round(s / 60)} min ago`;
|
|
95
|
+
if (s < 36 * 3600)
|
|
96
|
+
return `${Math.round(s / 3600)} h ago`;
|
|
97
|
+
return `${Math.round(s / 86400)} days ago`;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Which scene the play servers will boot, and the warnings worth a stop
|
|
101
|
+
* before publishing. Ashlight (2026-10-07): InitScene was the day-1 starter
|
|
102
|
+
* world while every save went into the played scene, so the first publish
|
|
103
|
+
* showed an empty plane.
|
|
104
|
+
*/
|
|
105
|
+
export function bootSceneNotes(drift, sendPlayedScene, now = Date.now()) {
|
|
106
|
+
const saved = [
|
|
107
|
+
drift.init_scene_saved_at ? `InitScene saved ${ago(drift.init_scene_saved_at, now)}` : null,
|
|
108
|
+
drift.played_scene_saved_at ? `played scene saved ${ago(drift.played_scene_saved_at, now)}` : null,
|
|
109
|
+
].filter(Boolean);
|
|
110
|
+
const facts = `Play servers will load ${sendPlayedScene ? "the editor's played scene" : "InitScene"}${saved.length ? ` (${saved.join("; ")})` : ""}.`;
|
|
111
|
+
const warnings = [];
|
|
112
|
+
if (!sendPlayedScene) {
|
|
113
|
+
if (drift.played_terrain_left_out) {
|
|
114
|
+
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
|
+
}
|
|
116
|
+
const init = drift.init_scene_volumes;
|
|
117
|
+
const played = drift.played_scene_volumes;
|
|
118
|
+
if (init != null && played != null && played - init >= 5 && played >= init * 1.5) {
|
|
119
|
+
warnings.push(`InitScene has ${init} of the played scene's ${played} voxel objects - it may still be the starting template. Pass --played-scene, or save the scene in the editor first.`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return { facts, warnings };
|
|
123
|
+
}
|
|
124
|
+
export function formatRestarts(history, now = Date.now()) {
|
|
125
|
+
if (history.unavailable) {
|
|
126
|
+
const why = {
|
|
127
|
+
nohost: "the world has no server yet",
|
|
128
|
+
unreachable: "its server didn't answer",
|
|
129
|
+
nologs: "the world has no engine logs yet",
|
|
130
|
+
};
|
|
131
|
+
return [`Couldn't read the engine's history: ${why[history.unavailable] ?? history.unavailable}.`];
|
|
132
|
+
}
|
|
133
|
+
const out = [];
|
|
134
|
+
out.push(history.running_since
|
|
135
|
+
? `Engine running since ${history.running_since} (${ago(history.running_since, now)}).`
|
|
136
|
+
: "Engine not running now.");
|
|
137
|
+
if (history.restarts.length === 0) {
|
|
138
|
+
out.push("No restarts in its recent logs.");
|
|
139
|
+
return out;
|
|
140
|
+
}
|
|
141
|
+
for (const r of history.restarts) {
|
|
142
|
+
out.push("");
|
|
143
|
+
const back = r.came_back_at ? `, back ${r.came_back_at}${r.in_place ? " (same server)" : ""}` : "";
|
|
144
|
+
out.push(`${r.went_down_at} ${r.kind.toUpperCase()}${back}`);
|
|
145
|
+
out.push(` ${r.reason}`);
|
|
146
|
+
if (r.last_lines.length > 0) {
|
|
147
|
+
out.push(` last lines before it went down (${r.log_file}):`);
|
|
148
|
+
for (const line of r.last_lines)
|
|
149
|
+
out.push(` ${line}`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return out;
|
|
153
|
+
}
|
|
154
|
+
/** A one-line heads-up for `errors` when the engine went down recently. */
|
|
155
|
+
export function recentRestartNote(history, now = Date.now(), withinMs = 60 * 60 * 1000) {
|
|
156
|
+
const latest = history.restarts[0];
|
|
157
|
+
if (!latest || now - Date.parse(latest.went_down_at) > withinMs)
|
|
158
|
+
return null;
|
|
159
|
+
const what = latest.kind === "crash" ? "crashed" : "was stopped";
|
|
160
|
+
return `Note: the engine ${what} at ${latest.went_down_at} (${ago(latest.went_down_at, now)}): ${latest.reason} Errors from before then are gone. See: npx virtualmatter logs --restarts`;
|
|
161
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "virtualmatter",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.7",
|
|
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",
|