From d99fc1e650c6fcf61de524c394803f711cad1c25 Mon Sep 17 00:00:00 2001 From: BloodSteyn Date: Fri, 26 Jun 2026 12:13:36 +0200 Subject: [PATCH] Claude.md added Adding Claude to this project to assist in creating an MCP --- CLAUDE.md | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 CLAUDE.md diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..500884c --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,83 @@ +# SketchForge-3D — AI Scene Bridge (fork) + +## What this fork adds + +Upstream SketchForge is a local-first, browser-based CAD editor. This fork adds an +**AI scene bridge** so an MCP server (driven by Claude) can push parametric 3D scenes +into the running editor. A later V2 flips the MCP into the source of truth over a live +connection (see `docs/scene-bridge/PLAN.md` → V2). + +We are **not** rewriting the editor. All work in this fork is **additive**. + +## The one fact that governs the whole design + +The editor's source of truth is **browser-origin storage**, not the server: + +- **Project shapes → IndexedDB.** DB `sketchForge.projectShapes`, store `projectShapes`, + `keyPath: "id"`, record shape `{ id, revision, shapes: WorkplaneShape[], updatedAt }`. + (See the persistence block in `apps/web/src/app/page.tsx`, ~lines 44–135.) +- **Dashboard / project metadata → localStorage.** See the projects-storage key and the + `readStoredProjects` / merge helpers in `page.tsx`. Confirm the exact key from source — + do not hardcode a guessed string. +- **The editor opens a project via URL:** `/?editor=1&project=`. There is also + a `codexBooleanCase` test param. + +An MCP server is a Node process and **cannot write browser IndexedDB/localStorage +directly** — that storage is sandboxed to the page origin. Therefore the bridge is always: + +``` +MCP (Node) → local HTTP route (Next server) → staged scene file on disk + → client poller inside the page hydrates it into IndexedDB + using the app's EXISTING save path → editor opens it +``` + +Never attempt to have the Node side write the scene store. If a design idea requires that, +it is wrong — re-read this section. + +## Data contract + +`WorkplaneShape` in `apps/web/src/types/sketchforge.ts` is THE contract. Key semantics: + +- A cutter is an ordinary shape with `hole: true`. +- A boolean/combined result carries its parts in `groupedShapes: WorkplaneShape[]`. +- Valid `ShapeKind` values and sane parameter ranges live in + `apps/web/src/lib/shapeCatalog.ts` and `apps/web/src/lib/workplaneShapes.ts`. + Read these before generating any shapes. + +Claude's job is emitting **valid `WorkplaneShape[]` JSON**. Manifold WASM (client-side) +does the actual CSG/meshing. Do **not** do mesh maths on the server. + +## Hard rules + +- **Additive only.** Do not refactor, rename, or reformat existing files. Do not load + `SketchForgeEditor.tsx` (~5,700 lines) whole — grep for the one hook you need. +- **Reuse, don't reimplement.** + - Copy the `isLocalSameOriginRequest` guard from an existing route + (`apps/web/src/app/api/local-download/route.ts`) into the new route. + - Reuse the existing IndexedDB read/write helpers and the localStorage project helpers + in `page.tsx`. A project needs BOTH a localStorage metadata entry AND an IndexedDB + shapes record to open — keep them consistent. +- **Pin upstream.** This is an alpha repo; internal shapes churn. Forked from upstream + commit: ``. Do not chase `main`. +- **Keep transport swappable.** Put the scene-delivery mechanism behind a small + `SceneTransport` interface so V2 can replace the poller with a WebSocket without + touching the route or the MCP tools. + +## Where new things go + +- Bridge route: `apps/web/src/app/api/scene/route.ts` +- Client hydrator/poller: new module under `apps/web/src/components/`, wired into editor mount +- MCP server: `apps/mcp/` (new workspace; imports `WorkplaneShape` from `apps/web/src/types`) +- Staged scenes: `.codex/pending-scenes/.json` (mirror the existing `.codex/` convention) + +## Commands + +- `npm run dev` — app at http://127.0.0.1:3000 +- `npm run typecheck` +- vitest tests live in `tests/` + +## Working agreement + +Read `docs/scene-bridge/PLAN.md` before each phase and do its orientation step. +Work **one phase per session**. Confirm your understanding and the plan before writing code. +End each session with a short handoff note (what changed, what's next, open questions).