AI-native design editor. Open-source Figma alternative.
fix(mcp): repair published exports and Windows roots
Danila Poyarkova5c6a1e3ab77
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 508b47616..45f173508 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -71,6 +71,8 @@### Fixed+- Make published package export conditions resolve to files included in npm tarballs.+- Use the user's home directory as the default MCP file root on Windows, avoiding the caller's unreliable working directory.- Open legacy raw `.fig` files that store the Kiwi document and thumbnail without a ZIP wrapper. (#582)- Preserve a frame's auto-layout HUG sizing mode when converting it into a component with `create_component`, so later padding changes still resize the component as expected.- Run `openpencil import` on Node so the npm-installed CLI no longer fails with `Bun is not defined`. (#575)diff --git a/packages/cli/package.json b/packages/cli/package.jsonindex 09790b481..e8321c1dd 100644--- a/packages/cli/package.json+++ b/packages/cli/package.json@@ -12,7 +12,6 @@"exports": {"./library": {"types": "./dist/library/index.d.mts",- "bun": "./src/library/index.ts","import": "./dist/library/index.mjs","default": "./dist/library/index.mjs"}diff --git a/packages/core/package.json b/packages/core/package.jsonindex affda0e42..fd049f2c2 100644--- a/packages/core/package.json+++ b/packages/core/package.json@@ -86,7 +86,6 @@"default": "./dist/rpc/index.js"},"./library": {- "bun": "./src/library/index.ts","types": "./dist/library/index.d.ts","import": "./dist/library/index.js","default": "./dist/library/index.js"@@ -132,7 +131,6 @@"default": "./dist/clipboard.js"},"./bytes": {- "bun": "./src/bytes/index.ts","types": "./dist/bytes/index.d.ts","import": "./dist/bytes/index.js","default": "./dist/bytes/index.js"diff --git a/packages/dom-css/package.json b/packages/dom-css/package.jsonindex 026b4ec49..a541ada3b 100644--- a/packages/dom-css/package.json+++ b/packages/dom-css/package.json@@ -6,32 +6,27 @@"imports": {"#dom-css/*": {"types": "./src/*",- "bun": "./src/*","default": "./dist/*"}},"exports": {".": {"types": "./dist/index.d.ts",- "bun": "./src/index.ts","import": "./dist/index.js","default": "./dist/index.js"},"./browser": {"types": "./dist/browser.d.ts",- "bun": "./src/browser.ts","import": "./dist/browser.js","default": "./dist/browser.js"},"./jsx-runtime": {"types": "./dist/jsx-runtime.d.ts",- "bun": "./src/jsx/runtime.ts","import": "./dist/jsx-runtime.js","default": "./dist/jsx-runtime.js"},"./jsx-dev-runtime": {"types": "./dist/jsx-dev-runtime.d.ts",- "bun": "./src/jsx/dev-runtime.ts","import": "./dist/jsx-dev-runtime.js","default": "./dist/jsx-dev-runtime.js"}diff --git a/packages/fig/package.json b/packages/fig/package.jsonindex 34250728f..bf54dd7ea 100644--- a/packages/fig/package.json+++ b/packages/fig/package.json@@ -6,19 +6,16 @@"exports": {".": {"types": "./dist/index.d.ts",- "bun": "./src/index.ts","import": "./dist/index.js","default": "./dist/index.js"},"./node-change": {"types": "./dist/node-change.d.ts",- "bun": "./src/node-change/index.ts","import": "./dist/node-change.js","default": "./dist/node-change.js"},"./instance-overrides": {"types": "./dist/instance-overrides.d.ts",- "bun": "./src/instance-overrides/index.ts","import": "./dist/instance-overrides.js","default": "./dist/instance-overrides.js"}diff --git a/packages/harness/package.json b/packages/harness/package.jsonindex a457de024..5806f4db7 100644--- a/packages/harness/package.json+++ b/packages/harness/package.json@@ -8,7 +8,6 @@"exports": {".": {"types": "./dist/index.d.mts",- "bun": "./src/index.ts","import": "./dist/index.mjs","default": "./dist/index.mjs"}diff --git a/packages/kiwi/package.json b/packages/kiwi/package.jsonindex 9222e6b37..0a5a0db21 100644--- a/packages/kiwi/package.json+++ b/packages/kiwi/package.json@@ -19,43 +19,36 @@"exports": {".": {"types": "./dist/index.d.ts",- "bun": "./src/index.ts","import": "./dist/index.js","default": "./dist/index.js"},"./schema-runtime": {"types": "./dist/schema-runtime.d.ts",- "bun": "./src/schema-runtime/index.ts","import": "./dist/schema-runtime.js","default": "./dist/schema-runtime.js"},"./fig": {"types": "./dist/fig.d.ts",- "bun": "./src/fig/index.ts","import": "./dist/fig.js","default": "./dist/fig.js"},"./fig/codec": {"types": "./dist/fig/codec.d.ts",- "bun": "./src/fig/codec.ts","import": "./dist/fig/codec.js","default": "./dist/fig/codec.js"},"./fig/container": {"types": "./dist/fig/container.d.ts",- "bun": "./src/fig/container.ts","import": "./dist/fig/container.js","default": "./dist/fig/container.js"},"./fig/guid": {"types": "./dist/fig/guid.d.ts",- "bun": "./src/fig/guid.ts","import": "./dist/fig/guid.js","default": "./dist/fig/guid.js"},"./fig/parse": {"types": "./dist/fig/parse.d.ts",- "bun": "./src/fig/parse.ts","import": "./dist/fig/parse.js","default": "./dist/fig/parse.js"}diff --git a/packages/mcp/package.json b/packages/mcp/package.jsonindex 055545b7c..4e3136578 100644--- a/packages/mcp/package.json+++ b/packages/mcp/package.json@@ -6,7 +6,6 @@"imports": {"#mcp/*": {"types": "./src/*.ts",- "bun": "./src/*.ts","default": "./dist/*.mjs"}},@@ -24,19 +23,16 @@},"./transport": {"types": "./dist/transport.d.mts",- "bun": "./src/transport/paths.ts","import": "./dist/transport.mjs","default": "./dist/transport.mjs"},"./discovery": {"types": "./dist/discovery.d.mts",- "bun": "./src/transport/discovery.ts","import": "./dist/discovery.mjs","default": "./dist/discovery.mjs"},"./tools": {"types": "./dist/tools.d.mts",- "bun": "./src/tool/index.ts","import": "./dist/tools.mjs","default": "./dist/tools.mjs"}diff --git a/packages/mcp/src/index.ts b/packages/mcp/src/index.tsindex 972bc4b1d..9f7f53444 100644--- a/packages/mcp/src/index.ts+++ b/packages/mcp/src/index.ts@@ -1,4 +1,5 @@#!/usr/bin/env node+import { resolveMCPRoot } from '#mcp/root'import { startServer } from '#mcp/server'import { readToolPolicyFromEnv } from '#mcp/tool/policy'@@ -17,8 +18,8 @@ if (process.argv.includes('--help') || process.argv.includes('-h')) {` platform path. Parent dir created 0o700. Mainly for test isolation.\n` +` OPENPENCIL_MCP_TCP Deprecated — TCP is controlled by PORT (>0 = on, 0 = off)\n` +` OPENPENCIL_MCP_AUTH_TOKEN Bearer token for MCP and RPC auth\n` +- ` OPENPENCIL_MCP_ROOT Allowed directory for file-scoped tools (default: current working directory)\n` +- ` OPENPENCIL_MCP_EVAL Set to 1 to enable the eval tool\n` ++ ` OPENPENCIL_MCP_ROOT Allowed directory for file-scoped tools (default: home directory on Windows, current working directory elsewhere)\n` ++ ` OPENPENCIL_MCP_EVAL Set to 1 to enable the eval tool\n` +` OPENPENCIL_MCP_DISABLED_TOOLS Comma-separated tool names to omit\n` +` OPENPENCIL_MCP_CORS_ORIGIN Allowed CORS origin\n` +` OPENPENCIL_MCP_APP_TIMEOUT_MS If set, close the server and remove its discovery\n` +@@ -75,7 +76,7 @@ const handle = await startServer({socketPath: process.env.OPENPENCIL_MCP_SOCKET?.trim() || null,enableEval: toolPolicy.allowEval,disabledTools: toolPolicy.disabledTools,- mcpRoot: process.env.OPENPENCIL_MCP_ROOT?.trim() || process.cwd(),+ mcpRoot: resolveMCPRoot(process.env.OPENPENCIL_MCP_ROOT),// Auth token: undefined → auto-generate, empty string → disable auth,// non-empty → use trimmed value. Whitespace-only is rejected to prevent a// silent fallback to an auto-generated token when the operator intended todiff --git a/packages/mcp/src/root.ts b/packages/mcp/src/root.tsnew file mode 100644index 000000000..1b6b7b1b2--- /dev/null+++ b/packages/mcp/src/root.ts@@ -0,0 +1,5 @@+import { homedir, platform } from 'node:os'++export function resolveMCPRoot(value: string | undefined, runtimePlatform = platform()): string {+ return value?.trim() || (runtimePlatform === 'win32' ? homedir() : process.cwd())+}diff --git a/packages/mcp/src/stdio.ts b/packages/mcp/src/stdio.tsindex ba711d268..46ee3831b 100644--- a/packages/mcp/src/stdio.ts+++ b/packages/mcp/src/stdio.ts@@ -2,6 +2,7 @@import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'+import { resolveMCPRoot } from '#mcp/root'import { MCP_VERSION, registerTools } from '#mcp/server'import { createStdioRPCBridge } from '#mcp/stdio/bridge'import type { ToolPolicy } from '#mcp/tool/metadata'@@ -22,7 +23,7 @@ if (process.argv.includes('--help') || process.argv.includes('-h')) {` OPENPENCIL_MCP_SOCKET Override socket path (auto-discovered from discovery file when unset)\n` +` OPENPENCIL_MCP_AUTH_TOKEN Bearer token for RPC auth\n` +` OPENPENCIL_MCP_ROOT Allowed directory for file-scoped tools\n` +- ` (default: cwd when run standalone, home directory when app-spawned)\n` ++ ` (default: home directory on Windows, cwd elsewhere)\n` +` OPENPENCIL_MCP_EVAL Set to 1 to enable the eval tool\n` +` OPENPENCIL_MCP_DISABLED_TOOLS Comma-separated tool names to omit; defaults to the app setting\n`)@@ -36,7 +37,7 @@ const toolPolicy: ToolPolicy = {? ((await readDiscoveryFile())?.disabledTools ?? []): parseDisabledTools(process.env.OPENPENCIL_MCP_DISABLED_TOOLS)}-const mcpRoot = process.env.OPENPENCIL_MCP_ROOT?.trim() || process.cwd()+const mcpRoot = resolveMCPRoot(process.env.OPENPENCIL_MCP_ROOT)// Auth token: undefined → auto-discover from discovery file, empty string →// disable auth, whitespace-only → reject (same fail-fast as index.ts to catch// misconfiguration), otherwise → use the trimmed value.diff --git a/packages/mcp/tests/root.test.ts b/packages/mcp/tests/root.test.tsnew file mode 100644index 000000000..4c1e3aef5--- /dev/null+++ b/packages/mcp/tests/root.test.ts@@ -0,0 +1,14 @@+import { describe, expect, test } from 'bun:test'+import { homedir } from 'node:os'++import { resolveMCPRoot } from '../src/root'++describe('resolveMCPRoot', () => {+ test('honors an explicit root', () => {+ expect(resolveMCPRoot(' /designs ')).toBe('/designs')+ })++ test('uses the home directory on Windows', () => {+ expect(resolveMCPRoot(undefined, 'win32')).toBe(homedir())+ })+})diff --git a/packages/pen/package.json b/packages/pen/package.jsonindex 4081d8f88..10aa5f3bd 100644--- a/packages/pen/package.json+++ b/packages/pen/package.json@@ -6,7 +6,6 @@"exports": {".": {"types": "./dist/index.d.ts",- "bun": "./src/index.ts","import": "./dist/index.js","default": "./dist/index.js"}diff --git a/packages/scene-graph/package.json b/packages/scene-graph/package.jsonindex df0ff7416..9ee5d254b 100644--- a/packages/scene-graph/package.json+++ b/packages/scene-graph/package.json@@ -18,151 +18,126 @@"exports": {".": {"types": "./dist/index.d.ts",- "bun": "./src/index.ts","import": "./dist/index.js","default": "./dist/index.js"},"./copy": {"types": "./dist/copy.d.ts",- "bun": "./src/copy.ts","import": "./dist/copy.js","default": "./dist/copy.js"},"./node-defaults": {"types": "./dist/node-defaults.d.ts",- "bun": "./src/node-defaults.ts","import": "./dist/node-defaults.js","default": "./dist/node-defaults.js"},"./instances": {"types": "./dist/instances.d.ts",- "bun": "./src/instances.ts","import": "./dist/instances.js","default": "./dist/instances.js"},"./snap": {"types": "./dist/snap.d.ts",- "bun": "./src/snap.ts","import": "./dist/snap.js","default": "./dist/snap.js"},"./source-metadata": {"types": "./dist/source-metadata.d.ts",- "bun": "./src/source-metadata.ts","import": "./dist/source-metadata.js","default": "./dist/source-metadata.js"},"./undo": {"types": "./dist/undo.d.ts",- "bun": "./src/undo.ts","import": "./dist/undo.js","default": "./dist/undo.js"},"./variant-name": {"types": "./dist/variant-name.d.ts",- "bun": "./src/variant-name.ts","import": "./dist/variant-name.js","default": "./dist/variant-name.js"},"./variant-properties": {"types": "./dist/variant-properties.d.ts",- "bun": "./src/variant-properties.ts","import": "./dist/variant-properties.js","default": "./dist/variant-properties.js"},"./vector-network": {"types": "./dist/vector-network.d.ts",- "bun": "./src/vector-network.ts","import": "./dist/vector-network.js","default": "./dist/vector-network.js"},"./guides": {"types": "./dist/guides.d.ts",- "bun": "./src/guides.ts","import": "./dist/guides.js","default": "./dist/guides.js"},"./layout-guides": {"types": "./dist/layout-guides.d.ts",- "bun": "./src/layout-guides.ts","import": "./dist/layout-guides.js","default": "./dist/layout-guides.js"},"./types": {"types": "./dist/types.d.ts",- "bun": "./src/types.ts","import": "./dist/types.js","default": "./dist/types.js"},"./primitives": {"types": "./dist/primitives.d.ts",- "bun": "./src/primitives.ts","import": "./dist/primitives.js","default": "./dist/primitives.js"},"./constants": {"types": "./dist/constants.d.ts",- "bun": "./src/constants.ts","import": "./dist/constants.js","default": "./dist/constants.js"},"./hit-test": {"types": "./dist/hit-test.d.ts",- "bun": "./src/hit-test.ts","import": "./dist/hit-test.js","default": "./dist/hit-test.js"},"./preview": {"types": "./dist/preview.d.ts",- "bun": "./src/preview.ts","import": "./dist/preview.js","default": "./dist/preview.js"},"./text-picture": {"types": "./dist/text-picture.d.ts",- "bun": "./src/text-picture.ts","import": "./dist/text-picture.js","default": "./dist/text-picture.js"},"./variables": {"types": "./dist/variables.d.ts",- "bun": "./src/variables.ts","import": "./dist/variables.js","default": "./dist/variables.js"},"./images": {"types": "./dist/images.d.ts",- "bun": "./src/images.ts","import": "./dist/images.js","default": "./dist/images.js"},"./coordinate": {"types": "./dist/coordinate.d.ts",- "bun": "./src/coordinate.ts","import": "./dist/coordinate.js","default": "./dist/coordinate.js"},"./matrix": {"types": "./dist/matrix.d.ts",- "bun": "./src/matrix.ts","import": "./dist/matrix.js","default": "./dist/matrix.js"},"./geometry": {"types": "./dist/geometry.d.ts",- "bun": "./src/geometry.ts","import": "./dist/geometry.js","default": "./dist/geometry.js"},"./resize": {"types": "./dist/resize.d.ts",- "bun": "./src/resize.ts","import": "./dist/resize.js","default": "./dist/resize.js"},"./parse-path": {"types": "./dist/parse-path.d.ts",- "bun": "./src/parse-path.ts","import": "./dist/parse-path.js","default": "./dist/parse-path.js"}diff --git a/tools/release-packages/src/tarballs.ts b/tools/release-packages/src/tarballs.tsindex e97670693..cfcca7ab1 100644--- a/tools/release-packages/src/tarballs.ts+++ b/tools/release-packages/src/tarballs.ts@@ -15,6 +15,17 @@ export function packageBinTargets(packageJSON: PackageJSON): Record<string, strireturn packageJSON.bin ?? {}}+function packageExportTargets(value: unknown): string[] {+ if (typeof value === 'string') return [value]+ if (Array.isArray(value)) return value.flatMap(packageExportTargets)+ if (!value || typeof value !== 'object') return []+ return Object.values(value).flatMap(packageExportTargets)+}++export function packageExportTargetPaths(packageJSON: { exports?: unknown }): string[] {+ return packageExportTargets(packageJSON.exports)+}+export async function tarballEntries(tarballPath: string): Promise<Set<string>> {const { stdout } = await execFileAsync('tar', ['-tf', tarballPath], { encoding: 'utf8' })return new Set(stdout.trim().split('\n').filter(Boolean))@@ -39,9 +50,24 @@ export async function validateTarballBinTargets(tarballPath: string): Promise<vo}}+export async function validateTarballExportTargets(tarballPath: string): Promise<void> {+ const entries = await tarballEntries(tarballPath)+ const packageJSON = (await tarballPackageJSON(tarballPath)) as PackageJSON & { exports?: unknown }++ for (const target of packageExportTargetPaths(packageJSON)) {+ if (!target.startsWith('./')) continue+ const entry = `package/${target.slice(2)}`+ if (!entries.has(entry)) {+ throw new Error(`${tarballPath}: export target missing from tarball: ${entry}`)+ }+ }+}+export async function validatePackedTarballs(directory: string): Promise<void> {const tarballs = (await readdir(directory)).filter((name) => name.endsWith('.tgz'))for (const tarball of tarballs) {- await validateTarballBinTargets(join(directory, tarball))+ const path = join(directory, tarball)+ await validateTarballBinTargets(path)+ await validateTarballExportTargets(path)}}diff --git a/tools/release-packages/tests/tarballs.test.ts b/tools/release-packages/tests/tarballs.test.tsindex e0b1bb246..547f1504c 100644--- a/tools/release-packages/tests/tarballs.test.ts+++ b/tools/release-packages/tests/tarballs.test.ts@@ -1,6 +1,6 @@import { describe, expect, test } from 'bun:test'-import { packageBinTargets } from '../src/tarballs'+import { packageBinTargets, packageExportTargetPaths } from '../src/tarballs'describe('packageBinTargets', () => {test('normalizes string bin fields', () => {@@ -17,3 +17,16 @@ describe('packageBinTargets', () => {})})})++describe('package export targets', () => {+ test('collects targets from conditional exports', () => {+ expect(+ packageExportTargetPaths({+ exports: {+ '.': { types: './dist/index.d.ts', import: './dist/index.js' },+ './feature': { import: './dist/feature.js' }+ }+ })+ ).toEqual(['./dist/index.d.ts', './dist/index.js', './dist/feature.js'])+ })+})