@mavonengine/cli 0.0.8 → 0.0.10

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 CHANGED
@@ -380,7 +380,7 @@ Client tools, for the game tabs open while Vite serves the client in dev:
380
380
  | `network_timeline` | The server's records for one tab and the tab's own, merged by time |
381
381
  | `client_logs` | Console output, uncaught errors and unhandled rejections, filtered by level and text |
382
382
  | `client_screenshot` | What the tab renders, as an image (the WebGL canvas, without HTML UI) |
383
- | `client_trace` | Records a few seconds of the tab and analyses it: frame times, render CPU vs GPU, composer passes, ticks, WebGL work per frame, the bottleneck, and the worst hitches with their causes. Saves a flame chart trace file |
383
+ | `client_trace` | Records a few seconds of the tab and analyses it: frame times, render CPU vs GPU, the render pipeline and its effects, ticks, WebGL work per frame, the bottleneck, and the worst hitches with their causes. Saves a flame chart trace file |
384
384
  | `compare_entity` | One entity on the server next to a tab's copy: position / rotation / scale deltas and differing fields |
385
385
 
386
386
  Plugin tools:
@@ -427,7 +427,7 @@ The server scene and entity tools read `GET /api/game/dev/*` on the game server.
427
427
 
428
428
  The client tools go through the dev bridge of the Vite plugin in `@mavonengine/core/vite.config` (Vite 8). In dev it adds a small module to the page that answers over Vite's hot-reload WebSocket, and serves `GET /__mavonengine/clients` to localhost, or with `MAVONENGINE_METRICS_TOKEN` as bearer token when that is set for the dev server. Builds never include it. Turn it off with `mavonEnginePlugins({ devBridge: false })`.
429
429
 
430
- `client_trace` patches the tab only while it records and puts everything back afterwards. It times every frame and composer pass, counts the WebGL calls on the context, keeps slow single calls (shader compiles, texture uploads, `readPixels` / `getError` stalls), long animation frames with the scripts that ran, and your own `performance.measure()` spans. GPU time per frame needs `EXT_disjoint_timer_query_webgl2` (Chrome and Edge on most GPUs; the three-perf panel pauses while tracing since it uses the same queries). JS call stacks come from the [JS Self-Profiling API](https://wicg.github.io/js-self-profiling/) in Chromium browsers: the Vite plugin serves dev pages with `Document-Policy: js-profiling` for it, so reload tabs opened before you updated. The trace file is [Chrome Trace Event](https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU) JSON with tracks for frames, passes, GPU time, ticks, JS samples and slow WebGL calls: open it in [Perfetto](https://ui.perfetto.dev), `chrome://tracing` or [speedscope](https://www.speedscope.app). Keep the tab in the foreground while it records, browsers throttle hidden tabs.
430
+ `client_trace` patches the tab only while it records and puts everything back afterwards. It times every frame and the render pipeline, counts the WebGL calls on the context (so it needs the WebGL 2 backend, the default), keeps slow single calls (shader compiles, texture uploads, `readPixels` / `getError` stalls), long animation frames with the scripts that ran, and your own `performance.measure()` spans. GPU time per frame needs `EXT_disjoint_timer_query_webgl2` (Chrome and Edge on most GPUs; the inspector's GPU timing pauses while tracing since it uses the same queries). JS call stacks come from the [JS Self-Profiling API](https://wicg.github.io/js-self-profiling/) in Chromium browsers: the Vite plugin serves dev pages with `Document-Policy: js-profiling` for it, so reload tabs opened before you updated. The trace file is [Chrome Trace Event](https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU) JSON with tracks for frames, passes, GPU time, ticks, JS samples and slow WebGL calls: open it in [Perfetto](https://ui.perfetto.dev), `chrome://tracing` or [speedscope](https://www.speedscope.app). Keep the tab in the foreground while it records, browsers throttle hidden tabs.
431
431
 
432
432
  The network tools read what both sides record while developing: every message through the game socket, the engine's and your own, with its size, and events such as `connect`, `disconnect`, `dropped` (the transport dropped a message), `sync_enter` / `sync_leave` (entities coming into or leaving a player's sync distance) and, on a client, `state_gap` (state updates that never arrived) and `state_out_of_order`. Each side keeps its last 2000 records, and 8 MB of their payloads. The server records when `NODE_ENV` is not `production` and serves them on `GET /api/game/dev/net/packets`, `/packets/:id` and `/sync`; a tab records while the dev bridge or the editor runs. Nothing is recorded, and the socket is left untouched, in a production build. `network_timeline` orders the two sides by their own clocks, which line up on one machine.
433
433
 
@@ -512,6 +512,172 @@ export default defineServerPlugin({
512
512
 
513
513
  A hook that throws is logged and turned off for that plugin, and the game keeps running.
514
514
 
515
+ ### Graphs and nodes
516
+
517
+ A plugin can ship material and logic graphs: put `<name>.graph.json` files (made in the editor's Graphs view, then copied over) in a `graphs/` directory in the package. They go by `<package>:<name>`, e.g. `my-custom-plugin:ocean`, wherever a graph is picked: a primitive's material graph, a Logic Graph object's graph. They are served at `/graphs/<package>/<name>.graph.json`, shipped in every release, and the server reads them from the package. The editor lists them under the project's graphs, read-only: *Copy to project* makes an editable copy.
518
+
519
+ It can also add node types, from `setup`. Their key in graph files is `<package>:<type>`, which `registerNode` returns. Material nodes take their TSL implementation as a second argument; logic nodes need registering in the server entry too, for graphs that run there:
520
+
521
+ ```ts
522
+ // client.ts
523
+ import { defineClientPlugin } from '@mavonengine/core/Plugins/types'
524
+ import { sin, time } from 'three/tsl'
525
+
526
+ export default defineClientPlugin({
527
+ setup(ctx) {
528
+ ctx.registerNode({
529
+ type: 'wobble',
530
+ label: 'Wobble',
531
+ category: 'Math',
532
+ kinds: ['material', 'logic'],
533
+ inputs: {
534
+ speed: { type: 'float', default: 1 }
535
+ },
536
+ outputs: {
537
+ value: { type: 'float' }
538
+ },
539
+ // In logic graphs
540
+ eval: ({ speed }, { time }) => ({
541
+ value: Math.sin(time * Number(speed))
542
+ }),
543
+ }, ({ speed }) => ({
544
+ value: sin(time.mul(speed))
545
+ }))
546
+ },
547
+ })
548
+ ```
549
+
550
+ ### Particle effects
551
+
552
+ A plugin can add particle effects from `setup` with `ctx.registerParticle`. They show in the editor's Particles tab with the plugin's name, can be placed in scenes (a `ParticleEffect` object) and are played by logic graphs (Spawn Effect, Play / Stop / Burst Effect). Their name in scene files and graphs is `<package>:<name>`, which `registerParticle` returns. Build them from the engine's emitters: `PooledEmitter` simulates particles with gravity, drag, wind, bouncing and settling, and only needs to know where each one starts. Load textures from the plugin's assets with `ctx.assetUrl()`. Particle effects only exist on the client:
553
+
554
+ ```ts
555
+ // client.ts
556
+ import type { PooledParticle } from '@mavonengine/core/Particles/System/PooledEmitter'
557
+ import type { Vector3 } from 'three'
558
+ import ParticleEffect from '@mavonengine/core/Particles/System/ParticleEffect'
559
+ import PooledEmitter from '@mavonengine/core/Particles/System/PooledEmitter'
560
+ import { defineClientPlugin } from '@mavonengine/core/Plugins/types'
561
+
562
+ class HailEmitter extends PooledEmitter {
563
+ constructor(position: Vector3) {
564
+ super(position, {
565
+ maxParticles: 400,
566
+ rate: 120,
567
+ lifetime: [4, 4],
568
+ size: [0.05, 0.05],
569
+ color: [0xE8F0FF, 0xE8F0FF],
570
+ gravity: 9.8,
571
+ bounce: 0.3,
572
+ restFor: [1, 2],
573
+ })
574
+ }
575
+
576
+ protected spawn(particle: PooledParticle) {
577
+ particle.position.set((Math.random() - 0.5) * 20, 12, (Math.random() - 0.5) * 20)
578
+ }
579
+ }
580
+
581
+ class Hail extends ParticleEffect {
582
+ constructor(position: Vector3) {
583
+ super()
584
+ this.emitters.push(new HailEmitter(position))
585
+ }
586
+ }
587
+
588
+ export default defineClientPlugin({
589
+ setup(ctx) {
590
+ // 'my-custom-plugin:Hail'
591
+ ctx.registerParticle('Hail', {
592
+ preview: {
593
+ cameraPosition: [0, 4, 12],
594
+ cameraTarget: [0, 2, 0]
595
+ },
596
+ spawn: position => new Hail(position),
597
+ icon: ctx.assetUrl('icons/hail.svg'),
598
+ })
599
+ },
600
+ })
601
+ ```
602
+
603
+ ### Brushes
604
+
605
+ The editor's Brushes panel comes with sculpt brushes (raise, lower, smooth, flatten, noise) for a `Terrain`, paint brushes for its material layers, and scatter brushes that paint models onto anything. A plugin can add to both kinds.
606
+
607
+ **Scatter brushes** are files: put `<name>.brush.json` files (made in the Brushes panel, which saves them to the project's `brushes/`) in a `brushes/` directory in the package. They go by `<package>:<name>` and are listed read-only next to the project's; *Copy* makes an editable copy.
608
+
609
+ **Brush tools** are code: register them from `setup` with `ctx.registerBrush`. A brush gets one stroke at a time (the editor spaces the stamps along the drag) and returns how to undo it. Its key is `<package>:<name>`. Its `options` show in the panel and reach the stroke as `context.options`:
610
+
611
+ ```ts
612
+ // client.ts
613
+ import { defineClientPlugin } from '@mavonengine/core/Plugins/types'
614
+ import { restoreHeights, sculpt, snapshotHeights } from '@mavonengine/core/Terrain/sculpt'
615
+
616
+ export default defineClientPlugin({
617
+ setup(ctx) {
618
+ ctx.registerBrush({
619
+ name: 'crater',
620
+ label: 'Crater',
621
+ group: 'Sculpt',
622
+ target: 'terrain',
623
+ options: [
624
+ {
625
+ type: 'slider',
626
+ key: 'depth',
627
+ label: 'depth',
628
+ min: 0.1,
629
+ max: 5,
630
+ step: 0.1,
631
+ default: 1
632
+ }
633
+ ],
634
+ begin(hit, context) {
635
+ const terrain = hit.terrain
636
+ if (!terrain)
637
+ return undefined
638
+ const region = {
639
+ col0: 0,
640
+ row0: 0,
641
+ col1: terrain.heightmap.resolution - 1,
642
+ row1: terrain.heightmap.resolution - 1
643
+ }
644
+ const before = snapshotHeights(terrain.heightmap, region)
645
+ return {
646
+ stamp(at, context) {
647
+ const local = terrain.toLocal(at.point)
648
+ const changed = sculpt(terrain.heightmap, {
649
+ mode: 'lower',
650
+ x: local.x,
651
+ z: local.z,
652
+ radius: context.settings.radius,
653
+ falloff: 1,
654
+ strength: Number(context.options.depth) / 5
655
+ })
656
+ if (changed)
657
+ terrain.heightsChanged(changed)
658
+ },
659
+ end() {
660
+ const after = snapshotHeights(terrain.heightmap, region)
661
+ terrain.commit()
662
+ const put = (heights: Float32Array) => {
663
+ restoreHeights(terrain.heightmap, region, heights)
664
+ terrain.heightsChanged()
665
+ terrain.commit()
666
+ }
667
+ return {
668
+ undo: () => put(before),
669
+ redo: () => put(after)
670
+ }
671
+ },
672
+ }
673
+ },
674
+ })
675
+ },
676
+ })
677
+ ```
678
+
679
+ A brush with `target: 'surface'` hits any mesh, not just terrains; `context.surfaceBelow(point)`, `context.scatterLayer(true)` and `context.scatterBrush` give what the built-in scatter brushes use.
680
+
515
681
  ### Dev entries
516
682
 
517
683
  A plugin's `dev` entry runs in the client's Vite dev server, only in dev: tooling for the editor that has to work with the project's files, like downloading something and writing it into `client/public/`. It is never part of a build, and the game server never loads it.
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  DEFAULT_DOCS_URL,
4
4
  version
5
- } from "./chunk-33OMMYNV.js";
5
+ } from "./chunk-W23KLMK7.js";
6
6
  import {
7
7
  READ_ONLY
8
8
  } from "./chunk-WMXVMJDM.js";
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // package.json
4
- var version = "0.0.8";
4
+ var version = "0.0.10";
5
5
 
6
6
  // src/mcp/config.ts
7
7
  import { existsSync, readFileSync, writeFileSync } from "fs";
@@ -2,10 +2,10 @@
2
2
  import {
3
3
  DocsClient,
4
4
  registerDocsTools
5
- } from "./chunk-HRMANFDB.js";
5
+ } from "./chunk-BACG3UTT.js";
6
6
  import {
7
7
  DEFAULT_DOCS_URL
8
- } from "./chunk-33OMMYNV.js";
8
+ } from "./chunk-W23KLMK7.js";
9
9
  import "./chunk-WMXVMJDM.js";
10
10
  import "./chunk-K3NQKI34.js";
11
11
  export {
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  MCP_CONFIG_FILE,
12
12
  version,
13
13
  writeMcpConfig
14
- } from "./chunk-33OMMYNV.js";
14
+ } from "./chunk-W23KLMK7.js";
15
15
  import {
16
16
  __export
17
17
  } from "./chunk-K3NQKI34.js";
@@ -4172,7 +4172,7 @@ import process4 from "process";
4172
4172
  import { Readable, Transform } from "stream";
4173
4173
  import { pipeline } from "stream/promises";
4174
4174
  import AdmZip from "adm-zip";
4175
- var TEMPLATE_URL = "https://github.com/MavonEngine/Core/archive/refs/tags/0.0.22-alpha.zip";
4175
+ var TEMPLATE_URL = "https://github.com/MavonEngine/Core/archive/refs/tags/0.0.24-alpha.zip";
4176
4176
  var TEMPLATE_SUBPATH = "packages/multiplayer-template";
4177
4177
  var PROJECT_NAME_RE = /^[\w@./-][\w@./\- ]*$/;
4178
4178
  var NAME_SEPARATORS_RE = /[-_\s]+/;
@@ -5344,7 +5344,32 @@ var appNameTitle = {
5344
5344
  }
5345
5345
  }
5346
5346
  };
5347
- var MIGRATIONS = [devScript, appNameTitle];
5347
+ var PACKAGE_JSONS = ["client/package.json", "package.json"];
5348
+ var THREE_PERF = "three-perf";
5349
+ var dropThreePerf = {
5350
+ id: "0.0.28-drop-three-perf",
5351
+ since: "0.0.28",
5352
+ description: "Remove three-perf, which core no longer uses: frame stats come from three's inspector",
5353
+ applies({ files }) {
5354
+ return PACKAGE_JSONS.some((path) => {
5355
+ const pkg = files.readJson(path);
5356
+ return !!(pkg?.dependencies?.[THREE_PERF] || pkg?.devDependencies?.[THREE_PERF]);
5357
+ });
5358
+ },
5359
+ run({ files }) {
5360
+ for (const path of PACKAGE_JSONS) {
5361
+ const pkg = files.readJson(path);
5362
+ if (!pkg?.dependencies?.[THREE_PERF] && !pkg?.devDependencies?.[THREE_PERF])
5363
+ continue;
5364
+ for (const field of ["dependencies", "devDependencies"]) {
5365
+ if (pkg[field]?.[THREE_PERF])
5366
+ delete pkg[field][THREE_PERF];
5367
+ }
5368
+ files.writeJson(path, pkg);
5369
+ }
5370
+ }
5371
+ };
5372
+ var MIGRATIONS = [devScript, appNameTitle, dropThreePerf];
5348
5373
 
5349
5374
  // ../core/dist/Migrations/ProjectFiles.js
5350
5375
  import { existsSync as existsSync7, mkdirSync as mkdirSync2, readFileSync as readFileSync6, writeFileSync as writeFileSync3 } from "fs";
@@ -6450,7 +6475,7 @@ var GameServerClient = class {
6450
6475
  }
6451
6476
  /** The game tabs open in a browser, through the dev bridge */
6452
6477
  clients() {
6453
- return this.bridge("__mavonengine/clients", {});
6478
+ return this.bridge("__mavonengine/clients", {}, 1e4);
6454
6479
  }
6455
6480
  /**
6456
6481
  * Ask one tab. `clientId` defaults to the only open tab (or the only one not running the editor)
@@ -6612,8 +6637,8 @@ function parseMcpArgs(args, env = process11.env) {
6612
6637
  async function runMcpCommand({ client, docsUrl, pluginsUrl, readOnly }) {
6613
6638
  const [{ StdioServerTransport }, { createMcpServer }, { DocsClient }, { ProjectPluginTools }] = await Promise.all([
6614
6639
  import("@modelcontextprotocol/sdk/server/stdio.js"),
6615
- import("./server-KTKAYX65.js"),
6616
- import("./docs-5J3ZQJSF.js"),
6640
+ import("./server-P5G2CHRT.js"),
6641
+ import("./docs-SSXJZII4.js"),
6617
6642
  import("./projectPluginTools-QWULLUMD.js")
6618
6643
  ]);
6619
6644
  const docs = docsUrl ? new DocsClient(docsUrl) : void 0;
@@ -5,10 +5,10 @@ import {
5
5
  } from "./chunk-GOPDTCJD.js";
6
6
  import {
7
7
  registerDocsTools
8
- } from "./chunk-HRMANFDB.js";
8
+ } from "./chunk-BACG3UTT.js";
9
9
  import {
10
10
  version
11
- } from "./chunk-33OMMYNV.js";
11
+ } from "./chunk-W23KLMK7.js";
12
12
  import {
13
13
  LOG_LEVELS,
14
14
  READ_ONLY,
@@ -330,9 +330,9 @@ function analyzeTrace(capture, { maxHitches = 10 } = {}) {
330
330
  findings.push(`${totals.syncCalls} GPU sync calls (${totals.syncMs}ms): readPixels / getError stall the pipeline. renderer.debug.checkShaderErrors = true calls getError after compiles, and picking with readPixels each frame stalls too`);
331
331
  if (bottleneck.verdict === "gpu-bound") {
332
332
  findings.push(`GPU-bound at ${capture.canvas.width}x${capture.canvas.height} (pixel ratio ${capture.canvas.pixelRatio}): lower the pixel ratio (cap it at 1.5\u20132), shadow map size or shadow-casting lights, and look at the most expensive passes`);
333
- const heavyPasses = passes.filter((p) => p.name !== "RenderPass" && p.name !== "OutputPass");
334
- if (heavyPasses.length)
335
- findings.push(`Post-processing passes cost GPU fill rate on every pixel: ${heavyPasses.map((p) => p.name).join(", ")}`);
333
+ const effects = capture.effects ?? passes.map((p) => p.name).filter((name) => name !== "RenderPass" && name !== "OutputPass");
334
+ if (effects.length)
335
+ findings.push(`Post-processing effects cost GPU fill rate on every pixel: ${effects.join(", ")}`);
336
336
  }
337
337
  if (tickStats && budgetMs && tickStats.p95 > budgetMs / 2) {
338
338
  findings.push(`Game ticks are slow (p95 ${tickStats.p95}ms${tickStats.physics ? `, physics p95 ${tickStats.physics.p95}ms` : ""}${tickStats.world ? `, world.update p95 ${tickStats.world.p95}ms` : ""}) and block rendering when they run`);
@@ -390,7 +390,7 @@ var TRACKS = {
390
390
  };
391
391
  var TRACK_NAMES = {
392
392
  [TRACKS.frames]: "Frames (render CPU)",
393
- [TRACKS.passes]: "Composer passes",
393
+ [TRACKS.passes]: "Render passes",
394
394
  [TRACKS.gpu]: "GPU time per frame (duration, not GPU clock)",
395
395
  [TRACKS.ticks]: "Game ticks",
396
396
  [TRACKS.js]: "JS samples",
@@ -751,7 +751,7 @@ function registerClientTools(server, client) {
751
751
  });
752
752
  server.registerTool("client_trace", {
753
753
  title: "Trace client rendering",
754
- description: "Record a tab for a few seconds and analyse its performance: frame time distribution, render CPU vs GPU time per frame, time per composer pass, game tick time (physics, world.update), WebGL work per frame (draw calls, program / texture / framebuffer switches, uniform calls, uploads), the bottleneck, and the worst hitches with their likely causes (shader compiles, texture uploads, GPU syncs, GC, slow ticks, long scripts, hot JS functions). JS sampling uses the browser's JS Self-Profiling API (Chromium) and GPU time EXT_disjoint_timer_query_webgl2. Also saves a Chrome Trace Event file to open as a flame chart in https://ui.perfetto.dev or chrome://tracing. Keep the tab in the foreground while it records.",
754
+ description: "Record a tab for a few seconds and analyse its performance: frame time distribution, render CPU vs GPU time per frame, time in the render pipeline, game tick time (physics, world.update), WebGL work per frame (draw calls, program / texture / framebuffer switches, uniform calls, uploads), the bottleneck, and the worst hitches with their likely causes (shader compiles, texture uploads, GPU syncs, GC, slow ticks, long scripts, hot JS functions). JS sampling uses the browser's JS Self-Profiling API (Chromium) and GPU time EXT_disjoint_timer_query_webgl2. Also saves a Chrome Trace Event file to open as a flame chart in https://ui.perfetto.dev or chrome://tracing. Keep the tab in the foreground while it records.",
755
755
  inputSchema: {
756
756
  clientId,
757
757
  durationMs: z.number().int().min(500).max(15e3).default(3e3).describe("How long to record"),
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mavonengine/cli",
3
3
  "type": "module",
4
- "version": "0.0.8",
4
+ "version": "0.0.10",
5
5
  "description": "MavonEngine command line tools",
6
6
  "license": "MIT",
7
7
  "keywords": [
@@ -33,17 +33,17 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@modelcontextprotocol/sdk": "^1.32.2",
36
- "@profullstack/hqtui": "0.11.1",
37
- "adm-zip": "^0.5.16",
36
+ "@profullstack/hqtui": "0.12.0",
37
+ "adm-zip": "^0.6.1",
38
38
  "zod": "^4.6.7"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@mavonengine/core": "*",
42
- "@types/adm-zip": "^0.5.7",
43
- "@types/node": "^24.0.0",
42
+ "@types/adm-zip": "^0.6.0",
43
+ "@types/node": "^22.20.7",
44
44
  "@vitest/coverage-v8": "^5.1.0",
45
45
  "tsup": "^9.0.0",
46
46
  "typescript": "7.0.2",
47
- "vitest": "^5.1.1"
47
+ "vitest": "^5.1.2"
48
48
  }
49
49
  }