Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ 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. 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

# Fresh tmp dir outside the repo.
TMPDIR="$(mktemp -d)"
echo "Smoke-installing $TGZ_ABS into $TMPDIR"
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,20 @@ 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. 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

TMPDIR="$(mktemp -d)"
echo "Smoke-installing $TGZ_ABS into $TMPDIR"
pushd "$TMPDIR" >/dev/null
Expand Down
18 changes: 17 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
36 changes: 28 additions & 8 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
34 changes: 29 additions & 5 deletions esbuild.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down
11 changes: 9 additions & 2 deletions packages/mcp-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
},
"files": [
"dist",
"!dist/**/*.map",
"README.md",
"LICENSE"
],
Expand Down Expand Up @@ -36,21 +37,27 @@
"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:*",
"@shapeitup/sim": "workspace:*",
"@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"
Expand Down
25 changes: 18 additions & 7 deletions packages/mcp-server/src/manifold-node-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,37 @@
* 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;

export async function loadManifoldNode(wasmDir?: string): Promise<any> {
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");
Expand Down
15 changes: 9 additions & 6 deletions packages/mcp-server/src/viewer-host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,15 @@ async function bundleWithWasm(absPath: string): Promise<string> {
*
* 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.
Expand Down
11 changes: 7 additions & 4 deletions packages/sim-mujoco/src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -44,9 +45,11 @@ export function loadMujocoModule(): Promise<MujocoModule> {
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}`,
);
}
Expand Down
13 changes: 6 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 13 additions & 6 deletions scripts/release-check.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down
Loading