diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.json index b7ede95..4a81869 100644 --- a/.claude-plugin/marketplace.json +++ b/.claude-plugin/marketplace.json @@ -12,7 +12,7 @@ { "name": "shapeitup", "description": "CAD scripting toolkit: create/modify .shape.ts files, validate geometry, check collisions, export STEP/STL/3MF via Replicad + OpenCascade. Runs headless; live 3D preview available if the ShapeItUp VS Code extension is installed.", - "version": "1.30.0", + "version": "1.30.1", "author": { "name": "Asbjorn Rorvik", "email": "rorvik.asbjorn@gmail.com" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6f0b157..b38baf6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,6 +32,9 @@ jobs: - name: Test @shapeitup/core run: pnpm --filter @shapeitup/core exec vitest run + - name: Test @shapeitup/shared + run: pnpm --filter @shapeitup/shared exec vitest run + - name: Test shapeitup-vscode (extension) run: pnpm --filter shapeitup-vscode exec vitest run diff --git a/CHANGELOG.md b/CHANGELOG.md index d74743c..7c001c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,39 @@ Releases 1.17.0–1.24.0 are described only in their Format based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/); the project follows semantic versioning at the extension level. +## [1.30.1] - 2026-10-12 + +Extension `1.30.1` / mcp-server `1.30.1` — Codex setup docs and three fixes. + +### Added +- **Codex setup in the docs** (`README.md`, `packages/mcp-server/README.md`, + `INSTALL.md`, shapeitup.dev). `codex mcp add`, then `startup_timeout_sec = 60` + and `tool_timeout_sec = 180` in `~/.codex/config.toml`. Codex's defaults are + 10 s to start and 60 s per tool; a first `npx` run from an empty cache took + 34 s, so a fresh install timed out before it answered. The skill goes in + `~/.agents/skills/shapeitup/`, where Codex looks for skills. + +### Fixed +- **On macOS the MCP server and the VS Code extension never found each + other.** The server hardcoded `~/.config/Code/...` on every non-Windows OS, + but VS Code on macOS keeps globalStorage under + `~/Library/Application Support/Code/...`. The extension never saw the + server's heartbeat, so live viewer sync, `set_render_mode`, + `toggle_dimensions` and workspace-root detection silently did nothing there. + The server now follows VS Code's own rules (`APPDATA` on Windows, + `XDG_CONFIG_HOME` on Linux) and, when the extension runs in Cursor, + VS Code Insiders, VSCodium or Windsurf, uses that editor's directory. +- **Every render warned `Import "sim" will always be undefined`** unless the + file exported `sim`. The filter for the wrapper's optional exports predated + `sim`. Both bundlers now use one list in `@shapeitup/shared`, and a test + fails if the wrapper gains a name the filter doesn't cover. +- **Published builds signed every tool result `[shapeitup mcp vdev …]`.** The + version lookup used `__dirname`, which doesn't exist in the ESM bundle. It + now uses the version esbuild bakes in, as `serverInfo` already did. + +### Changed +- CI now runs the `@shapeitup/shared` tests. + ## [1.30.0] - 2026-09-30 Extension `1.30.0` / mcp-server `1.30.0` — Mistral Vibe support diff --git a/INSTALL.md b/INSTALL.md index 45fb504..e94382b 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -37,6 +37,8 @@ Check for each of these (absence of one is fine — just skip that client): - **Claude Code CLI**: `which claude` succeeds, OR `~/.claude.json` exists, OR `~/.claude/` exists. +- **Codex** (CLI, IDE extension or ChatGPT desktop app — they share one + config): `which codex` succeeds, OR `~/.codex/` exists. - **Cursor**: `~/.cursor/mcp.json` exists, OR the Cursor app is installed (`/Applications/Cursor.app` on macOS, `%LOCALAPPDATA%\Programs\cursor` on Windows). @@ -81,6 +83,35 @@ Fallback if `claude mcp add` isn't available: merge this into `~/.claude.json`: `mcpServers.shapeitup` entry, write back. If the file is malformed, stop and tell the user. +#### Codex + +Preferred: use the CLI. + +```bash +codex mcp add shapeitup -- npx -y @shapeitup/mcp-server +``` + +Then open `~/.codex/config.toml` and make sure the `[mcp_servers.shapeitup]` +table carries both timeouts. Add the two keys if they are missing; leave +everything else in the file alone: + +```toml +[mcp_servers.shapeitup] +command = "npx" +args = ["-y", "@shapeitup/mcp-server"] +startup_timeout_sec = 60 +tool_timeout_sec = 180 +``` + +Fallback if `codex` isn't on the PATH (the desktop app alone doesn't add it): +append that table to `~/.codex/config.toml`, creating the file if missing. If +the file already has a `[mcp_servers.shapeitup]` table, edit it instead — +TOML rejects a table defined twice. + +Keep both timeouts. Codex gives a server 10 s to start by default, which is +shorter than the first `npx` download, and a tool 60 s, which a cold render of +complex geometry can exceed. Tell the user to restart Codex. + #### Cursor Merge into `~/.cursor/mcp.json` (create if missing): @@ -154,12 +185,16 @@ curl -fsSL https://raw.githubusercontent.com/asbis/ShapeItUp/master/skills/shape If Mistral Vibe is present, the same file works there unchanged: write it to `~/.vibe/skills/shapeitup/SKILL.md` (ask first). Vibe picks it up on `/reload`. +If Codex is present, write the same file to `~/.agents/skills/shapeitup/SKILL.md` +(ask first). That is Codex's user-level skills directory; it picks up new +skills without a restart. + ### Step 4 — Verify After registration: 1. For CLI clients, ask the user to restart their agent session (or run - `claude mcp list` to confirm `shapeitup` is listed). + `claude mcp list` / `codex mcp list` to confirm `shapeitup` is listed). 2. Tell the user to try a prompt like: *"Use the ShapeItUp MCP to create a simple 20mm cube and render it."* If the agent reports that the `shapeitup` tools are available, installation succeeded. @@ -175,7 +210,9 @@ so the user can troubleshoot. ## Uninstall To remove ShapeItUp from an MCP client, delete the `shapeitup` entry from the -relevant config file, or run `claude mcp remove shapeitup` for Claude Code and -`vibe mcp remove shapeitup` for Mistral Vibe. No global state is left behind -beyond those config entries and the optional skill files at -`~/.claude/skills/shapeitup/` and `~/.vibe/skills/shapeitup/`. +relevant config file (for Codex, the `[mcp_servers.shapeitup]` table in +`~/.codex/config.toml`), or run `claude mcp remove shapeitup` for Claude Code +and `vibe mcp remove shapeitup` for Mistral Vibe. No global state is left +behind beyond those config entries and the optional skill files at +`~/.claude/skills/shapeitup/`, `~/.vibe/skills/shapeitup/` and +`~/.agents/skills/shapeitup/`. diff --git a/README.md b/README.md index 0112928..ae158a2 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ --- -ShapeItUp is an MCP server that turns [Replicad](https://replicad.xyz) / OpenCascade into AI-agent-grade CAD tooling. It writes, renders, verifies, and exports parametric 3D models from TypeScript `.shape.ts` files, headlessly — from the terminal, from Claude Code / Cursor / Claude Desktop / Mistral Vibe, or from CI. A [VSCode extension](#vscode-extension-optional) is available as an optional interactive viewer for humans who want to watch the renders happen live. +ShapeItUp is an MCP server that turns [Replicad](https://replicad.xyz) / OpenCascade into AI-agent-grade CAD tooling. It writes, renders, verifies, and exports parametric 3D models from TypeScript `.shape.ts` files, headlessly — from the terminal, from Claude Code / Codex / Cursor / Claude Desktop / Mistral Vibe, or from CI. A [VSCode extension](#vscode-extension-optional) is available as an optional interactive viewer for humans who want to watch the renders happen live. ## Install for Claude Code @@ -23,6 +23,30 @@ claude mcp add shapeitup -- npx -y @shapeitup/mcp-server That's it. `claude mcp add` registers the server in your Claude Code config so agent sessions pick it up automatically. See the [Claude Code MCP docs](https://docs.claude.com/en/docs/claude-code/mcp) for scoping options (`-s user` for all projects, `-s project` for just this repo). +## Install for Codex + +```bash +codex mcp add shapeitup -- npx -y @shapeitup/mcp-server +``` + +Then raise the timeouts in `~/.codex/config.toml`, under the entry that command wrote: + +```toml +[mcp_servers.shapeitup] +command = "npx" +args = ["-y", "@shapeitup/mcp-server"] +startup_timeout_sec = 60 +tool_timeout_sec = 180 +``` + +Keep both. Codex gives a server 10 s to start, and the first `npx` run downloads the package, which can take half a minute. It gives a tool 60 s, and a cold render of complex geometry can need more. The Codex CLI, the IDE extension and the ChatGPT desktop app share this file. Check with `codex mcp list`, or `/mcp` inside Codex. + +For the Replicad API reference, save [`SKILL.md`](skills/shapeitup/SKILL.md) where Codex looks for skills: + +```bash +mkdir -p ~/.agents/skills/shapeitup && curl -fsSL https://raw.githubusercontent.com/asbis/ShapeItUp/master/skills/shapeitup/SKILL.md -o ~/.agents/skills/shapeitup/SKILL.md +``` + ## Install for Cursor / Claude Desktop / other MCP clients The generic MCP-config snippet: diff --git a/packages/extension/package.json b/packages/extension/package.json index e461817..120dc23 100644 --- a/packages/extension/package.json +++ b/packages/extension/package.json @@ -2,7 +2,7 @@ "name": "shapeitup-vscode", "displayName": "ShapeItUp", "description": "Scripted CAD for VS Code — write TypeScript, see 3D, export STEP/STL/3MF (Bambu Studio & OrcaSlicer ready). AI-powered with Claude Code MCP integration.", - "version": "1.30.0", + "version": "1.30.1", "publisher": "shapeitup", "license": "MIT", "icon": "icon.png", diff --git a/packages/extension/src/viewer-provider.ts b/packages/extension/src/viewer-provider.ts index b10afbe..1443515 100644 --- a/packages/extension/src/viewer-provider.ts +++ b/packages/extension/src/viewer-provider.ts @@ -14,6 +14,7 @@ import { describeTransformFailure, renderViewerHtml, computeParamEdit, + isOptionalReexportWarning, type ExportFormat, type ParamCommitResult, type FaceOpResultMessage, @@ -1287,13 +1288,12 @@ export class ViewerProvider implements vscode.WebviewViewProvider { throw new Error(`Unresolved imports:\n${msg}`); } // Filter out "Import 'X' will always be undefined" warnings for the - // optional names the synthetic wrapper re-exports (`config`, `material`, - // `params`). These fire on every file that doesn't declare one of them - // — which is most — and the re-export pattern is deliberate. - const OPTIONAL_REEXPORT_NAMES = /Import "(config|material|params)" will always be undefined/; + // optional names the synthetic wrapper re-exports. These fire on every + // file that doesn't declare one of them — which is most — and the + // re-export pattern is deliberate. // Surface other (non-fatal) warnings in the output channel. for (const w of result.warnings) { - if (OPTIONAL_REEXPORT_NAMES.test(w.text)) continue; + if (isOptionalReexportWarning(w.text)) continue; this.output.appendLine(`[warn] ${w.text}`); } diff --git a/packages/mcp-server/README.md b/packages/mcp-server/README.md index d2f4655..dc4d70d 100644 --- a/packages/mcp-server/README.md +++ b/packages/mcp-server/README.md @@ -1,6 +1,6 @@ # @shapeitup/mcp-server -MCP server for [ShapeItUp](https://github.com/asbis/ShapeItUp) — scripted CAD tools (Replicad / OpenCascade WASM) for Claude Code, Cursor, Claude Desktop, Gemini CLI, Mistral Vibe, and any stdio MCP client. Fully headless, no VSCode required. +MCP server for [ShapeItUp](https://github.com/asbis/ShapeItUp) — scripted CAD tools (Replicad / OpenCascade WASM) for Claude Code, Codex, Cursor, Claude Desktop, Gemini CLI, Mistral Vibe, and any stdio MCP client. Fully headless, no VSCode required. ## Install @@ -16,6 +16,26 @@ npx -y @shapeitup/mcp-server claude mcp add shapeitup -- npx -y @shapeitup/mcp-server ``` +### Codex + +```bash +codex mcp add shapeitup -- npx -y @shapeitup/mcp-server +``` + +Then raise the timeouts in `~/.codex/config.toml`, under the entry that command wrote: + +```toml +[mcp_servers.shapeitup] +command = "npx" +args = ["-y", "@shapeitup/mcp-server"] +startup_timeout_sec = 60 +tool_timeout_sec = 180 +``` + +Keep both. Codex gives a server 10 s to start, and the first `npx` run downloads the package, which can take half a minute. It gives a tool 60 s, and a cold render of complex geometry can need more. The CLI, the IDE extension and the ChatGPT desktop app share this file. + +For the Replicad API reference, save [`SKILL.md`](https://github.com/asbis/ShapeItUp/blob/master/skills/shapeitup/SKILL.md) as `~/.agents/skills/shapeitup/SKILL.md`, where Codex looks for skills. + ### Cursor / Claude Desktop / generic MCP client ```json diff --git a/packages/mcp-server/package.json b/packages/mcp-server/package.json index 99caf9f..c3c56c9 100644 --- a/packages/mcp-server/package.json +++ b/packages/mcp-server/package.json @@ -1,7 +1,7 @@ { "name": "@shapeitup/mcp-server", - "version": "1.30.0", - "description": "ShapeItUp MCP server — scripted CAD tools (Replicad/OpenCascade) for Claude Code, Cursor, Claude Desktop, and other MCP clients.", + "version": "1.30.1", + "description": "ShapeItUp MCP server — scripted CAD tools (Replicad/OpenCascade) for Claude Code, Codex, Cursor, Claude Desktop, and other MCP clients.", "type": "module", "bin": { "shapeitup-mcp": "./dist/index.js" diff --git a/packages/mcp-server/src/engine.ts b/packages/mcp-server/src/engine.ts index bc4c315..16f2c0b 100644 --- a/packages/mcp-server/src/engine.ts +++ b/packages/mcp-server/src/engine.ts @@ -28,7 +28,7 @@ import { type Core, type ExecutedPart, } from "@shapeitup/core"; -import type { ParamValue } from "@shapeitup/shared"; +import { isOptionalReexportWarning, type ParamValue } from "@shapeitup/shared"; import * as esbuild from "esbuild-wasm"; // esbuild-wasm requires a one-shot initialize() before the first build(). @@ -1209,13 +1209,12 @@ export async function executeShapeFile( // `params` from a sibling .shape.ts — supported but fragile). // // Filter out "Import 'X' will always be undefined" warnings for the - // optional names the synthetic wrapper re-exports (`config`, `material`, - // `params`). These fire on every file that doesn't declare one of them — - // which is most of them — and the re-export pattern is deliberate (back- - // compat with the executor's ambient `typeof foo !== "undefined"` lookup). - const OPTIONAL_REEXPORT_NAMES = /Import "(config|material|params)" will always be undefined/; + // optional names the synthetic wrapper re-exports. These fire on every + // file that doesn't declare one of them — which is most of them — and the + // re-export pattern is deliberate (back-compat with the executor's + // ambient `typeof foo !== "undefined"` lookup). const filteredEsbuildWarnings = result.warnings.filter( - (w) => !OPTIONAL_REEXPORT_NAMES.test(w.text), + (w) => !isOptionalReexportWarning(w.text), ); const combinedWarnings = [ ...preflightResult.warnings, diff --git a/packages/mcp-server/src/subscriber-bus.test.ts b/packages/mcp-server/src/subscriber-bus.test.ts index 3bf0372..f2f0810 100644 --- a/packages/mcp-server/src/subscriber-bus.test.ts +++ b/packages/mcp-server/src/subscriber-bus.test.ts @@ -8,11 +8,11 @@ * - with zero subscribers, publishEvent returns delivered=0 without hanging */ import { describe, it, expect, beforeEach, afterEach } from "vitest"; -import { mkdtempSync, rmSync, existsSync, readdirSync } from "fs"; +import { mkdtempSync, rmSync, existsSync, readdirSync, mkdirSync, writeFileSync, utimesSync } from "fs"; import { tmpdir } from "os"; import { join } from "path"; import { WebSocket } from "ws"; -import { SubscriberBus, readMcpServerHeartbeat } from "./subscriber-bus.js"; +import { SubscriberBus, readMcpServerHeartbeat, resolveGlobalStorageDir } from "./subscriber-bus.js"; // Tiny helper so each test's subscriber can block until it sees a message. function awaitMessage(ws: WebSocket, timeoutMs = 2000): Promise { @@ -170,3 +170,62 @@ describe("SubscriberBus", () => { expect(existsSync(storageDir)).toBe(true); // the dir itself stays }); }); + +describe("resolveGlobalStorageDir", () => { + const ID = "shapeitup.shapeitup-vscode"; + let home: string; + + beforeEach(() => { + home = mkdtempSync(join(tmpdir(), "global-storage-")); + }); + + afterEach(() => { + try { rmSync(home, { recursive: true, force: true }); } catch {} + }); + + // What the extension leaves behind: a heartbeat in its own globalStorage. + function extensionHeartbeat(dir: string, ageSeconds: number, name = "shapeitup-heartbeat.json") { + mkdirSync(dir, { recursive: true }); + const file = join(dir, name); + writeFileSync(file, "{}"); + const t = Date.now() / 1000 - ageSeconds; + utimesSync(file, t, t); + } + + it("uses VS Code's macOS location, not ~/.config", () => { + expect(resolveGlobalStorageDir({ home, platform: "darwin", env: {} })).toBe( + join(home, "Library", "Application Support", "Code", "User", "globalStorage", ID), + ); + }); + + it("follows APPDATA on Windows and XDG_CONFIG_HOME on Linux", () => { + expect(resolveGlobalStorageDir({ home, platform: "win32", env: { APPDATA: join(home, "Roaming") } })).toBe( + join(home, "Roaming", "Code", "User", "globalStorage", ID), + ); + expect(resolveGlobalStorageDir({ home, platform: "linux", env: {} })).toBe( + join(home, ".config", "Code", "User", "globalStorage", ID), + ); + expect(resolveGlobalStorageDir({ home, platform: "linux", env: { XDG_CONFIG_HOME: join(home, "xdg") } })).toBe( + join(home, "xdg", "Code", "User", "globalStorage", ID), + ); + }); + + it("picks the editor the extension ran in, even when VS Code's dir exists", () => { + const root = join(home, "Library", "Application Support"); + // This server creates VS Code's dir on its own, so its existence proves nothing. + mkdirSync(join(root, "Code", "User", "globalStorage", ID), { recursive: true }); + extensionHeartbeat(join(root, "Cursor", "User", "globalStorage", ID), 60, "shapeitup-heartbeat-123.json"); + expect(resolveGlobalStorageDir({ home, platform: "darwin", env: {} })).toBe( + join(root, "Cursor", "User", "globalStorage", ID), + ); + }); + + it("prefers the editor with the most recent heartbeat", () => { + const root = join(home, ".config"); + extensionHeartbeat(join(root, "Cursor", "User", "globalStorage", ID), 3600); + extensionHeartbeat(join(root, "Code", "User", "globalStorage", ID), 5); + expect(resolveGlobalStorageDir({ home, platform: "linux", env: {} })).toBe( + join(root, "Code", "User", "globalStorage", ID), + ); + }); +}); diff --git a/packages/mcp-server/src/subscriber-bus.ts b/packages/mcp-server/src/subscriber-bus.ts index a5ae057..35c7122 100644 --- a/packages/mcp-server/src/subscriber-bus.ts +++ b/packages/mcp-server/src/subscriber-bus.ts @@ -417,19 +417,90 @@ export function getSubscriberBus(globalStorageDir: string, serverVersion: string return busSingleton; } +const EXTENSION_ID = "shapeitup.shapeitup-vscode"; + +/** + * VS Code-family editors the extension can run in, by the name of their + * user-data directory. Each keeps its own globalStorage, so an extension in + * Cursor never looks in VS Code's. Order breaks ties: VS Code first. + */ +const EDITOR_DATA_DIRS = ["Code", "Cursor", "Code - Insiders", "VSCodium", "Windsurf"]; + +export interface GlobalStorageLookup { + home?: string; + platform?: NodeJS.Platform; + env?: NodeJS.ProcessEnv; +} + +/** + * The extension's globalStorage dir in every VS Code-family editor, in + * `EDITOR_DATA_DIRS` order. Mirrors where VS Code puts user data, which is + * what `context.globalStorageUri` resolves under on the extension side. + */ +export function editorGlobalStorageDirs(opts: GlobalStorageLookup = {}): string[] { + const home = opts.home ?? os.homedir(); + const platform = opts.platform ?? process.platform; + const env = opts.env ?? process.env; + const root = + platform === "darwin" + ? path.join(home, "Library", "Application Support") + : platform === "win32" + ? env.APPDATA || path.join(home, "AppData", "Roaming") + : env.XDG_CONFIG_HOME || path.join(home, ".config"); + return EDITOR_DATA_DIRS.map((app) => path.join(root, app, "User", "globalStorage", EXTENSION_ID)); +} + +/** Newest mtime of an extension-written heartbeat in `dir`, or -Infinity. */ +function newestExtensionHeartbeat(dir: string): number { + let newest = -Infinity; + try { + for (const name of fs.readdirSync(dir)) { + if (!name.startsWith("shapeitup-heartbeat") || !name.endsWith(".json")) continue; + try { + newest = Math.max(newest, fs.statSync(path.join(dir, name)).mtimeMs); + } catch {} + } + } catch {} + return newest; +} + +/** + * Pick the globalStorage dir this server shares with the extension: the + * editor the extension ran in most recently, else VS Code's. + * + * Only the extension writes `shapeitup-heartbeat*.json`; this server creates + * the directory itself, so a directory existing proves nothing. Before this, + * the path was hardcoded to `~/.config/Code/...` on every non-Windows OS. On + * macOS VS Code uses `~/Library/Application Support/Code/...`, so the two + * sides never found each other there. + * + * With the extension in two editors at once, only the more recent one sees + * this server. + */ +export function resolveGlobalStorageDir(opts: GlobalStorageLookup = {}): string { + const dirs = editorGlobalStorageDirs(opts); + let best = dirs[0]; + let bestMtime = -Infinity; + for (const dir of dirs) { + const mtime = newestExtensionHeartbeat(dir); + if (mtime > bestMtime) { + best = dir; + bestMtime = mtime; + } + } + return best; +} + +let cachedGlobalStorageDir: string | null = null; + /** - * Locate the standard globalStorage dir used by both the extension and the - * MCP server. This mirrors the path embedded in tools.ts — kept in sync so a - * new process doesn't drift from the existing heartbeat discovery path. + * `resolveGlobalStorageDir()` for this process, resolved once. tools.ts reads + * it at import and the bus at startup; resolving twice could split them across + * two editors if a heartbeat landed in between. */ export function defaultGlobalStorageDir(): string { - const home = os.homedir(); - return path.join( - home, - process.platform === "win32" - ? "AppData/Roaming/Code/User/globalStorage/shapeitup.shapeitup-vscode" - : ".config/Code/User/globalStorage/shapeitup.shapeitup-vscode", - ); + cachedGlobalStorageDir ??= resolveGlobalStorageDir(); + return cachedGlobalStorageDir; } /** diff --git a/packages/mcp-server/src/tools.ts b/packages/mcp-server/src/tools.ts index fc4873a..06e8a11 100644 --- a/packages/mcp-server/src/tools.ts +++ b/packages/mcp-server/src/tools.ts @@ -18,7 +18,6 @@ import { } from "@shapeitup/sim"; import { runDynamics, type MeshData } from "@shapeitup/sim-dynamics"; import { runMujoco } from "@shapeitup/sim-mujoco"; -import { homedir } from "os"; import { appendScreenshotMetadata, bundleDepsAreStale, @@ -67,14 +66,10 @@ import { sanitizeToolListResponse } from "./schema-sanitizer.js"; * Shared globalStorage dir with the VSCode extension. Both processes write and * read `shapeitup-status.json` here, so MCP-driven renders and extension-driven * renders stay interchangeable. This is the only place we "touch" VSCode: it's - * a file location, not a runtime dependency. + * a file location, not a runtime dependency. Resolved in subscriber-bus.ts so + * the bus's heartbeat and these files always land in the same directory. */ -const GLOBAL_STORAGE = join( - homedir(), - process.platform === "win32" - ? "AppData/Roaming/Code/User/globalStorage/shapeitup.shapeitup-vscode" - : ".config/Code/User/globalStorage/shapeitup.shapeitup-vscode" -); +const GLOBAL_STORAGE = defaultGlobalStorageDir(); // --- Subscriber bus (WebSocket) ------------------------------------------- // The MCP server advertises a WebSocket port via its own heartbeat file. @@ -110,18 +105,22 @@ const _emittedWorkspaceRoots = new Set(); * so the combined footer reflects both sides of the stack honestly. */ const MCP_SERVER_VERSION: string = (() => { - // Candidates in order of likelihood for each install shape: - // 1. Bundled dist (packages/mcp-server/dist/mcp-server.mjs → ../package.json) - // 2. Dev / tsc (packages/mcp-server/src/tools.ts → ../package.json) - // 3. Defensive fallback against process.cwd() + // Bundled builds (the npm dist, the extension's mcp-server.mjs) get the + // version baked in by esbuild's `define` — see esbuild.config.mjs. They are + // ESM, where `__dirname` doesn't exist, so the package.json probe below + // could never run there and every published build reported `vdev`. + const baked = process.env.SHAPEITUP_MCP_VERSION; + if (baked) return baked; + + // Unbundled (vitest / tsc): find the package.json next to the source. + // 1. packages/mcp-server/src/tools.ts → ../package.json + // 2. Defensive fallback against process.cwd() const candidates: string[] = []; - try { + if (typeof __dirname !== "undefined") { candidates.push(join(__dirname, "..", "package.json")); candidates.push(join(__dirname, "..", "..", "package.json")); - candidates.push(resolve(process.cwd(), "packages", "mcp-server", "package.json")); - } catch { - // __dirname shouldn't throw but be defensive. } + candidates.push(resolve(process.cwd(), "packages", "mcp-server", "package.json")); for (const p of candidates) { try { if (existsSync(p)) { diff --git a/packages/shared/src/bundle-spec.test.ts b/packages/shared/src/bundle-spec.test.ts new file mode 100644 index 0000000..7a4b4ec --- /dev/null +++ b/packages/shared/src/bundle-spec.test.ts @@ -0,0 +1,23 @@ +import { describe, expect, it } from "vitest"; +import { buildSyntheticShapeEntry, isOptionalReexportWarning } from "./bundle-spec.js"; + +// esbuild's text for an import the wrapper makes that the user's file doesn't +// satisfy, e.g. `export const sim = __shapeitup_entry__.sim;`. +const warning = (name: string) => + `Import "${name}" will always be undefined because there is no matching export in "bracket.shape.ts"`; + +describe("isOptionalReexportWarning", () => { + it("covers every optional name the synthetic wrapper re-exports", () => { + const wrapper = buildSyntheticShapeEntry("/tmp/bracket.shape.ts"); + const names = [...wrapper.matchAll(/^export const (\w+) =/gm)].map((m) => m[1]); + expect(names).toContain("sim"); + for (const name of names) { + expect(isOptionalReexportWarning(warning(name)), name).toBe(true); + } + }); + + it("keeps the same warning for a user's own missing import", () => { + expect(isOptionalReexportWarning(warning("bracketWidth"))).toBe(false); + expect(isOptionalReexportWarning(warning("simulate"))).toBe(false); + }); +}); diff --git a/packages/shared/src/bundle-spec.ts b/packages/shared/src/bundle-spec.ts index 410a876..5b13d76 100644 --- a/packages/shared/src/bundle-spec.ts +++ b/packages/shared/src/bundle-spec.ts @@ -32,6 +32,28 @@ export function buildSyntheticShapeEntry(absPath: string): string { ); } +/** + * The names `buildSyntheticShapeEntry` re-exports whether or not the user's + * file declares them. + */ +const OPTIONAL_ENTRY_EXPORTS = ["params", "material", "config", "sim"]; + +const OPTIONAL_REEXPORT_WARNING = new RegExp( + `^Import "(${OPTIONAL_ENTRY_EXPORTS.join("|")})" will always be undefined`, +); + +/** + * True for the esbuild warning the synthetic wrapper causes on every file that + * doesn't declare one of its optional exports — which is most files. The MCP + * engine and the extension both filter with this, so the list lives in one + * place; each used to carry its own regex, and both missed `sim`. The engine + * and the extension still inline copies of the wrapper itself — a name added + * there must be added here too (bundle-spec.test.ts checks this file's copy). + */ +export function isOptionalReexportWarning(text: string): boolean { + return OPTIONAL_REEXPORT_WARNING.test(text); +} + /** * esbuild options every `.shape.ts` bundler must agree on, whatever esbuild * flavour it runs (native in `@shapeitup/serve`, `esbuild-wasm` in the MCP diff --git a/website/public/index.html b/website/public/index.html index 70187a2..c5e5c4c 100644 --- a/website/public/index.html +++ b/website/public/index.html @@ -148,7 +148,9 @@

Describe the part. Your agent builds it.

# ~/.codex/config.toml
 [mcp_servers.shapeitup]
 command = "npx"
-args = ["-y", "@shapeitup/mcp-server"]
+args = ["-y", "@shapeitup/mcp-server"] +startup_timeout_sec = 60 # first npx download is slow +tool_timeout_sec = 180 # cold renders can exceed 60 s