From 0d73d9d7859cad5b10d8b1b840a0009756388843 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20R=C3=B8rvik?= <11362831+asbis@users.noreply.github.com> Date: Tue, 13 Oct 2026 01:27:43 +0200 Subject: [PATCH 1/2] Shrink the first npx install from 43 packages to 4 A cold `npx -y @shapeitup/mcp-server` downloaded ~38 MB across 43 tarballs (129 MB on disk). On an ordinary connection that ran past Claude Code's 30 s MCP timeout, so a new user's first session started without ShapeItUp. Side by side from an empty cache: 76-105 s before, 14-20 s after, 52 MB on disk. - Ship manifold.js + manifold.wasm in dist/ instead of depending on manifold-3d. Its peer dependencies, which npm installs automatically, brought a second esbuild-wasm, @gltf-transform/* and the native sharp library: ~17 MB for a half-megabyte wasm. The loader and the viewer's asset resolver already look in dist/ first. - @mujoco/mujoco becomes an optional peer (npm installed the optional dependency for everyone, 5 MB). The error for engine: "mujoco" now gives the npx command that adds it. - Stop publishing source maps (1.3 MB gzipped). - release-check and the CI tarball smoke test check that manifold.wasm ships and no .map does. CLAUDE.md records why the tree must stay small. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yml | 8 +++++ .github/workflows/publish.yml | 8 +++++ CHANGELOG.md | 18 +++++++++- CLAUDE.md | 36 ++++++++++++++----- esbuild.config.mjs | 34 +++++++++++++++--- packages/mcp-server/package.json | 11 ++++-- .../mcp-server/src/manifold-node-loader.ts | 25 +++++++++---- packages/mcp-server/src/viewer-host.ts | 15 ++++---- packages/sim-mujoco/src/loader.ts | 11 +++--- pnpm-lock.yaml | 13 ++++--- scripts/release-check.mjs | 19 ++++++---- 11 files changed, 152 insertions(+), 46 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b38baf6..6b38495 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -57,6 +57,14 @@ jobs: TGZ_ABS="$(pwd)/$TGZ" cd "$GITHUB_WORKSPACE" + # The tarball ships Manifold itself (no manifold-3d dependency) and + # leaves the 6 MB source map out. + tar -tzf "$TGZ_ABS" | grep -qx 'package/dist/manifold.wasm' + if tar -tzf "$TGZ_ABS" | grep -q '\.map$'; then + echo "Tarball contains source maps; package.json \"files\" should exclude them." >&2 + exit 1 + fi + # Fresh tmp dir outside the repo. TMPDIR="$(mktemp -d)" echo "Smoke-installing $TGZ_ABS into $TMPDIR" diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 52481c3..cc08017 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -89,6 +89,14 @@ jobs: TGZ_ABS="$(pwd)/$TGZ" cd "$GITHUB_WORKSPACE" + # The tarball ships Manifold itself (no manifold-3d dependency) and + # leaves the 6 MB source map out. + tar -tzf "$TGZ_ABS" | grep -qx 'package/dist/manifold.wasm' + if tar -tzf "$TGZ_ABS" | grep -q '\.map$'; then + echo "Tarball contains source maps; package.json \"files\" should exclude them." >&2 + exit 1 + fi + TMPDIR="$(mktemp -d)" echo "Smoke-installing $TGZ_ABS into $TMPDIR" pushd "$TMPDIR" >/dev/null diff --git a/CHANGELOG.md b/CHANGELOG.md index e8892ff..668af61 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,7 +56,23 @@ Extension `1.30.1` / mcp-server `1.30.1` — Codex setup docs and three fixes. now uses the version esbuild bakes in, as `serverInfo` already did. ### Changed -- CI now runs the `@shapeitup/shared` tests. +- **The first `npx` start downloads 4 packages instead of 43.** It was ~38 MB + across 43 tarballs and 129 MB on disk, which on an ordinary connection ran + past Claude Code's 30 s MCP timeout, so a new user's first session started + without ShapeItUp. Side by side from an empty cache it went from 76–105 s to + 14–20 s, 52 MB on disk: + - Manifold's runtime (`manifold.js` + `manifold.wasm`, ~570 KB) now ships in + the package instead of the `manifold-3d` dependency, whose automatically + installed peers brought a second esbuild-wasm, `@gltf-transform/*` and the + native `sharp` library. + - `@mujoco/mujoco` is now an optional peer dependency rather than an + optional dependency, which npm installed for everyone. To use + `engine: "mujoco"`, register the server as + `npx -y -p @shapeitup/mcp-server -p @mujoco/mujoco shapeitup-mcp`; the + error message says so. + - Source maps are no longer published (1.3 MB gzipped). +- CI now runs the `@shapeitup/shared` tests, and checks that the npm tarball + carries `manifold.wasm` and no source maps. ## [1.30.0] - 2026-09-30 diff --git a/CLAUDE.md b/CLAUDE.md index e86850a..d39e758 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -144,14 +144,34 @@ distribution channels lay them out differently: |---|---|---| | `viewer.js`, `worker.js` | `extension/dist/` | shipped in `dist/` (~1.3 MB gzipped) | | `replicad_single.*` | `extension/dist/` | `node_modules/replicad-opencascadejs` | -| `manifold.*` | `extension/dist/` | `node_modules/manifold-3d` | -| `mujoco.*` | `extension/dist/` | `node_modules/@mujoco/mujoco` (optional) | - -The npm package deliberately does NOT ship the `.wasm` files: those three -packages are already runtime dependencies, so npm puts the exact same bytes on -disk anyway. Copying them in would add ~7 MB gzipped of duplicates to every -install, including installs that never open a viewer. `SHAPEITUP_VIEWER_DIST` -overrides the search for unusual layouts. +| `manifold.*` | `extension/dist/` | shipped in `dist/` (~570 KB) | +| `mujoco.*` | `extension/dist/` | `node_modules/@mujoco/mujoco`, only if the user installed it | + +The npm package deliberately does NOT ship the OCCT `.wasm`: +`replicad-opencascadejs` is a runtime dependency, so npm puts the exact same +bytes on disk anyway, and copying them in would add ~9 MB gzipped of +duplicates. `SHAPEITUP_VIEWER_DIST` overrides the search for unusual layouts. + +**The first `npx` run is the install, and clients time it.** Claude Code gives +a server 30 s to answer `initialize`, Codex 10 s. Every runtime dependency is +downloaded before that clock can be met, so keep the dependency tree small and +measure a cold start (empty `npm_config_cache`) after changing it: + +- **Manifold is shipped, not depended on.** `manifold-3d` declares + `esbuild-wasm` (a second copy) and `@gltf-transform/*` as peer dependencies; + npm installs those automatically, and they pull in the native `sharp`. That + was ~17 MB of a ~38 MB download for a half-megabyte wasm. It stays a devDependency + so the build can copy the two files (`copyManifoldToMcpDist`). +- **MuJoCo is an optional peer.** npm installs optional *dependencies* by + default (5 MB here) but not optional *peers*. Users who want + `engine: "mujoco"` register the server as + `npx -y -p @shapeitup/mcp-server -p @mujoco/mujoco shapeitup-mcp`; the error + without it says so. +- **No source maps in the tarball** (`"!dist/**/*.map"` in `files`, 1.3 MB gzipped). + +That took a cold start from 42 packages / 129 MB to 4 packages / 52 MB. Rapier +(0.77 MB gzipped, inlined in `index.js` and again in `viewer.js`) stays: it is +the default dynamics engine. MuJoCo is optional throughout — a 404 on `mujoco.wasm` just disables Sim. diff --git a/esbuild.config.mjs b/esbuild.config.mjs index ea8d850..5854bf8 100644 --- a/esbuild.config.mjs +++ b/esbuild.config.mjs @@ -3,6 +3,7 @@ import { cpSync, mkdirSync, existsSync, writeFileSync, rmSync, readFileSync } fr import { resolve, dirname, basename } from "path"; import { fileURLToPath } from "url"; import { execSync } from "child_process"; +import { createRequire } from "module"; const __dirname = dirname(fileURLToPath(import.meta.url)); const watch = process.argv.includes("--watch"); @@ -32,11 +33,11 @@ const extensionConfig = { }; // The npm package (`@shapeitup/mcp-server`) ships the two browser bundles so -// `open_viewer` works from a bare `npx` install. It does NOT ship the .wasm — -// replicad-opencascadejs / manifold-3d / @mujoco/mujoco are already runtime -// dependencies, so npm puts those on disk anyway and viewer-host.ts resolves -// them from node_modules. Copying them here would add ~7 MB gzipped of exact -// duplicates to every install. +// `open_viewer` works from a bare `npx` install. It does NOT ship the OCCT +// .wasm — replicad-opencascadejs is a runtime dependency, so npm puts it on +// disk anyway and viewer-host.ts resolves it from node_modules. Copying it +// here would add ~9 MB gzipped of exact duplicates to every install. +// Manifold is the exception; see copyManifoldToMcpDist(). // // An onEnd plugin rather than a post-build copy so `pnpm dev` keeps the two // dist directories in sync on every rebuild, not just the first. @@ -209,6 +210,28 @@ function copyWasmFiles() { } } +/** + * Ship manifold.js + manifold.wasm (~570 KB) inside the npm package instead of + * depending on manifold-3d. That package declares esbuild-wasm (a second + * copy) and @gltf-transform/* as peer dependencies, which npm installs + * automatically, and those pull in the native sharp library: ~17 MB of a + * ~38 MB first `npx` download, enough to push a cold start past Claude Code's + * 30 s MCP timeout. manifold-node-loader.ts and viewer-host.ts both look in + * the bundle's own dist/ first. + * + * Runs in --mcp-only mode too, so a dev rebuild never leaves dist/ without it. + */ +function copyManifoldToMcpDist() { + const req = createRequire(resolve(__dirname, "packages/mcp-server/package.json")); + const manifoldDir = dirname(req.resolve("manifold-3d/manifold.js")); + const destDir = resolve(__dirname, "packages/mcp-server/dist"); + mkdirSync(destDir, { recursive: true }); + for (const file of ["manifold.js", "manifold.wasm"]) { + cpSync(resolve(manifoldDir, file), resolve(destDir, file)); + } + console.log("Copied manifold.js + manifold.wasm to packages/mcp-server/dist/"); +} + /** * Bundle type definitions used by `.shape.ts` autocomplete into the * extension's dist/typings/. On activation the extension copies these into @@ -349,6 +372,7 @@ async function build() { // In --mcp-only mode we skip the WASM + typings copies (extension-side // assets that don't affect the mcp-server bundle) and only rebuild the two // mcp-server configs. Keeps `pnpm dev:mcp` fast when iterating on the server. + copyManifoldToMcpDist(); if (!mcpOnly) { copyWasmFiles(); copySkillFiles(); diff --git a/packages/mcp-server/package.json b/packages/mcp-server/package.json index 1ab206e..c451b41 100644 --- a/packages/mcp-server/package.json +++ b/packages/mcp-server/package.json @@ -9,6 +9,7 @@ }, "files": [ "dist", + "!dist/**/*.map", "README.md", "LICENSE" ], @@ -36,14 +37,19 @@ "dependencies": { "@resvg/resvg-wasm": "^2.6.2", "esbuild-wasm": "^0.28.0", - "manifold-3d": "^3.4.1", "replicad-opencascadejs": "^0.23.0" }, - "optionalDependencies": { + "peerDependencies": { "@mujoco/mujoco": "^3.10.0" }, + "peerDependenciesMeta": { + "@mujoco/mujoco": { + "optional": true + } + }, "devDependencies": { "@modelcontextprotocol/sdk": "^1.0.0", + "@mujoco/mujoco": "^3.10.0", "@shapeitup/core": "workspace:*", "@shapeitup/serve": "workspace:*", "@shapeitup/shared": "workspace:*", @@ -51,6 +57,7 @@ "@shapeitup/sim-dynamics": "workspace:*", "@shapeitup/sim-mujoco": "workspace:*", "@types/ws": "^8.18.1", + "manifold-3d": "^3.4.1", "replicad": "^0.23.0", "ws": "^8.20.0", "zod": "^4.3.6" diff --git a/packages/mcp-server/src/manifold-node-loader.ts b/packages/mcp-server/src/manifold-node-loader.ts index c14c381..e711ca7 100644 --- a/packages/mcp-server/src/manifold-node-loader.ts +++ b/packages/mcp-server/src/manifold-node-loader.ts @@ -9,14 +9,20 @@ * sidesteps the CJS require path inside manifold.js's Node branch, which * doesn't play nicely with the bundled MCP server. * - * Falls back to node_modules/manifold-3d when no wasmDir is supplied (same - * rule as loadOCCTNode: VSCode-bundled copy uses the co-located dist files, - * standalone npm installs resolve through node_modules). + * Looks next to `wasmDir` (the VSIX), then next to this bundle (the npm + * package ships manifold.js + manifold.wasm in its own dist/), then falls back + * to node_modules/manifold-3d (a dev checkout, running from source). + * + * The npm package doesn't depend on manifold-3d: that package declares + * esbuild-wasm and @gltf-transform/* as peer dependencies, which npm installs + * automatically. Through ndarray-pixels they pull in the native sharp library, + * and together they were ~17 MB of a ~38 MB first `npx` download, for a + * half-megabyte wasm this server is the only user of. */ import { readFileSync, existsSync } from "node:fs"; import { dirname, join } from "node:path"; -import { pathToFileURL } from "node:url"; +import { fileURLToPath, pathToFileURL } from "node:url"; declare const require: NodeJS.Require; @@ -24,11 +30,16 @@ export async function loadManifoldNode(wasmDir?: string): Promise { const { createRequire } = require("module") as typeof import("node:module"); const req = createRequire(import.meta.url); + const bundleDir = dirname(fileURLToPath(import.meta.url)); + const shippedDir = [wasmDir, bundleDir].find( + (dir): dir is string => !!dir && existsSync(join(dir, "manifold.wasm")), + ); + let loaderPath: string; let wasmPath: string; - if (wasmDir && existsSync(join(wasmDir, "manifold.wasm"))) { - loaderPath = join(wasmDir, "manifold.js"); - wasmPath = join(wasmDir, "manifold.wasm"); + if (shippedDir) { + loaderPath = join(shippedDir, "manifold.js"); + wasmPath = join(shippedDir, "manifold.wasm"); } else { loaderPath = req.resolve("manifold-3d/manifold.js"); wasmPath = join(dirname(loaderPath), "manifold.wasm"); diff --git a/packages/mcp-server/src/viewer-host.ts b/packages/mcp-server/src/viewer-host.ts index ab45300..644c505 100644 --- a/packages/mcp-server/src/viewer-host.ts +++ b/packages/mcp-server/src/viewer-host.ts @@ -43,12 +43,15 @@ async function bundleWithWasm(absPath: string): Promise { * * VSIX — everything co-located: `mcp-server.mjs` sits in `extension/dist` * next to viewer.js, worker.js and all the .wasm files. - * npm — `dist/` carries only the two browser bundles we build - * (viewer.js + worker.js, ~1.3 MB gzipped). The WASM comes from - * `replicad-opencascadejs` / `manifold-3d` / `@mujoco/mujoco`, - * which npm has already installed as ordinary dependencies. - * Copying them into the tarball would add ~7 MB gzipped of exact - * duplicates of files that are on disk anyway. + * npm — `dist/` carries the two browser bundles we build (viewer.js + * + worker.js, ~1.3 MB gzipped) and manifold.js/.wasm, which it + * ships instead of depending on manifold-3d (see + * manifold-node-loader.ts). The OCCT WASM comes from + * `replicad-opencascadejs`, a runtime dependency npm has already + * installed; copying it into the tarball would add ~9 MB gzipped + * of exact duplicates. `@mujoco/mujoco` is an optional peer, so + * it is on disk only if the user installed it; without it the + * viewer's Sim is disabled. * * `SHAPEITUP_VIEWER_DIST` overrides everything, for a dev checkout or an * unusual install layout. diff --git a/packages/sim-mujoco/src/loader.ts b/packages/sim-mujoco/src/loader.ts index 15840e4..40e829f 100644 --- a/packages/sim-mujoco/src/loader.ts +++ b/packages/sim-mujoco/src/loader.ts @@ -9,7 +9,8 @@ * * Two environments, one code path: * - **Node/MCP**: dynamically import the npm package `@mujoco/mujoco` (an - * OPTIONAL dependency, so nothing loads until a run actually selects MuJoCo). + * optional PEER of the MCP server, so npm doesn't install it unless the user + * asks, and nothing loads until a run actually selects MuJoCo). * - **Webview/viewer**: the Emscripten glue can't be bundled into the IIFE * viewer (it uses `import.meta`/`require`), so the extension copies `mujoco.js` * + `mujoco.wasm` into `dist` and hands us webview URIs via a global; we import @@ -44,9 +45,11 @@ export function loadMujocoModule(): Promise { factory = mod.default; } catch (err) { throw new Error( - "The MuJoCo engine requires the '@mujoco/mujoco' module. In Node install the optional " + - "package (npm i @mujoco/mujoco); in the viewer ensure mujoco.js/.wasm were copied to dist. " + - "Or omit `engine: \"mujoco\"` to use the default engine. " + + "The MuJoCo engine needs the '@mujoco/mujoco' package, which the MCP server doesn't install by " + + "default (it is a 5 MB download most users never need). Install it next to the server: with npx, " + + "register the server as `npx -y -p @shapeitup/mcp-server -p @mujoco/mujoco shapeitup-mcp`; with an " + + "npm install, run `npm i @mujoco/mujoco` in the same place. In the viewer, ensure mujoco.js/.wasm " + + "were copied to dist. Or omit `engine: \"mujoco\"` to use the default engine. " + `Underlying error: ${(err as Error).message}`, ); } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 321fe65..33d9a95 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -70,9 +70,6 @@ importers: esbuild-wasm: specifier: ^0.28.0 version: 0.28.0 - manifold-3d: - specifier: ^3.4.1 - version: 3.4.1(@gltf-transform/core@4.3.0)(@gltf-transform/extensions@4.3.0)(@gltf-transform/functions@4.3.0)(esbuild-wasm@0.28.0) replicad-opencascadejs: specifier: ^0.23.0 version: 0.23.0 @@ -80,6 +77,9 @@ importers: '@modelcontextprotocol/sdk': specifier: ^1.0.0 version: 1.29.0(zod@4.3.6) + '@mujoco/mujoco': + specifier: ^3.10.0 + version: 3.10.0 '@shapeitup/core': specifier: workspace:* version: link:../core @@ -101,6 +101,9 @@ importers: '@types/ws': specifier: ^8.18.1 version: 8.18.1 + manifold-3d: + specifier: ^3.4.1 + version: 3.4.1(@gltf-transform/core@4.3.0)(@gltf-transform/extensions@4.3.0)(@gltf-transform/functions@4.3.0)(esbuild-wasm@0.28.0) replicad: specifier: ^0.23.0 version: 0.23.0 @@ -110,10 +113,6 @@ importers: zod: specifier: ^4.3.6 version: 4.3.6 - optionalDependencies: - '@mujoco/mujoco': - specifier: ^3.10.0 - version: 3.10.0 packages/serve: dependencies: diff --git a/scripts/release-check.mjs b/scripts/release-check.mjs index 8d774f6..d82282a 100644 --- a/scripts/release-check.mjs +++ b/scripts/release-check.mjs @@ -135,16 +135,23 @@ for (const rel of skillPaths) { } } -// 7. The npm package must carry the browser bundles `open_viewer` serves. -// They're mirrored into packages/mcp-server/dist by an esbuild onEnd plugin — -// if that mirror ever breaks, the package still publishes and `open_viewer` -// fails only at runtime, for npm users only. -for (const asset of ["viewer.js", "worker.js"]) { +// 7. The npm package must carry the browser bundles `open_viewer` serves and +// the Manifold runtime, which it ships instead of depending on manifold-3d. +// The build copies them into packages/mcp-server/dist — if that copy ever +// breaks, the package still publishes and the failure shows up only at +// runtime, for npm users only. +const npmAssets = { + "viewer.js": "open_viewer is broken", + "worker.js": "open_viewer is broken", + "manifold.js": "threads.tapInto and other Manifold helpers fail", + "manifold.wasm": "threads.tapInto and other Manifold helpers fail", +}; +for (const [asset, impact] of Object.entries(npmAssets)) { const p = resolve(root, "packages/mcp-server/dist", asset); if (!existsSync(p)) { fail( `packages/mcp-server/dist/${asset} is missing — run \`pnpm build\`. ` + - `Without it, open_viewer is broken for npx/npm installs.`, + `Without it, ${impact} for npx/npm installs.`, ); } else { pass(`npm package carries ${asset}`); From e302630d57cd735df005c4fccfb3400df9ce8168 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20R=C3=B8rvik?= <11362831+asbis@users.noreply.github.com> Date: Tue, 13 Oct 2026 12:37:55 +0200 Subject: [PATCH 2/2] ci: list the tarball once instead of piping tar into grep -q MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `tar -tzf | grep -qx …` let grep exit on its first match; GNU tar then died writing to the closed pipe ("tar: stdout: write error"), and pipefail failed the step even though the file was there. In the source-map check the same race would have hidden a match inside the `if`. BSD tar on macOS doesn't hit it, which is why it passed locally. publish.yml had the same lines and would have failed the release. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yml | 12 +++++++++--- .github/workflows/publish.yml | 12 +++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6b38495..9f2e262 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -58,9 +58,15 @@ jobs: cd "$GITHUB_WORKSPACE" # The tarball ships Manifold itself (no manifold-3d dependency) and - # leaves the 6 MB source map out. - tar -tzf "$TGZ_ABS" | grep -qx 'package/dist/manifold.wasm' - if tar -tzf "$TGZ_ABS" | grep -q '\.map$'; then + # leaves the 6 MB source map out. List it once into a variable: + # `tar | grep -q` lets grep exit on the first match, tar then dies on + # a closed pipe, and pipefail turns that into a failure. + LISTING="$(tar -tzf "$TGZ_ABS")" + if ! grep -qx 'package/dist/manifold.wasm' <<<"$LISTING"; then + echo "Tarball is missing dist/manifold.wasm; run the full build." >&2 + exit 1 + fi + if grep -q '\.map$' <<<"$LISTING"; then echo "Tarball contains source maps; package.json \"files\" should exclude them." >&2 exit 1 fi diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index cc08017..0bb6555 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -90,9 +90,15 @@ jobs: cd "$GITHUB_WORKSPACE" # The tarball ships Manifold itself (no manifold-3d dependency) and - # leaves the 6 MB source map out. - tar -tzf "$TGZ_ABS" | grep -qx 'package/dist/manifold.wasm' - if tar -tzf "$TGZ_ABS" | grep -q '\.map$'; then + # leaves the 6 MB source map out. List it once into a variable: + # `tar | grep -q` lets grep exit on the first match, tar then dies on + # a closed pipe, and pipefail turns that into a failure. + LISTING="$(tar -tzf "$TGZ_ABS")" + if ! grep -qx 'package/dist/manifold.wasm' <<<"$LISTING"; then + echo "Tarball is missing dist/manifold.wasm; run the full build." >&2 + exit 1 + fi + if grep -q '\.map$' <<<"$LISTING"; then echo "Tarball contains source maps; package.json \"files\" should exclude them." >&2 exit 1 fi