Add AI scene bridge (V1): MCP -> /api/scene -> editor

Additive fork feature letting an MCP server (driven by Claude) push parametric
WorkplaneShape[] scenes into the running SketchForge editor. The Node side never
writes browser storage; it stages a command file that an in-page poller applies
through the editor's existing updateProjectShapes() save path.

- Phase 1: apps/web/src/app/api/scene/route.ts — stages/serves commands behind the
  existing same-origin guard, with its own monotonic stagingRevision (separate from
  the app's project revision).
- Phase 2: apps/web/src/lib/sceneBridge.ts (SceneTransport seam + polling transport)
  and a useSceneBridge poller hook in page.tsx (gated on ?bridge=1), which creates
  unknown projects and hydrates via updateProjectShapes; defers while dragging.
- Phase 3: apps/mcp/ MCP server — set_scene/get_scene/add_shapes/list_kinds. zod
  validates the ShapeKind union enum + base numerics, then reuses the app's own
  sceneShape/canonicalizeShape for defaults/canonicalisation (no hand-authored ranges).
- Phase 4: docs/scene-bridge/README.md plus vitest cases for the route handler and
  the schema validator.

Staged scenes live under .codex/pending-scenes/ (gitignored). MCP registered via
.mcp.json. npm run test: 29 passing.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
BloodSteyn
2026-06-26 13:34:44 +02:00
co-authored by Claude Opus 4.8
parent d99fc1e650
commit dee2765538
19 changed files with 2917 additions and 10 deletions
+30
View File
@@ -0,0 +1,30 @@
import type { ShapeInput } from "./shapes";
// In-context reference scenes the model can copy from. Plain WorkplaneShape inputs:
// dimensions in millimetres, x/z on the workplane, elevation = height above it, a cutter
// is any shape with hole: true. These are intentionally simple and valid.
export const PHONE_STAND_EXAMPLE: { name: string; shapes: ShapeInput[] } = {
name: "Phone stand",
shapes: [
{ name: "Base", kind: "box", color: "#0098c7", x: 0, z: 0, elevation: 0, width: 80, depth: 70, height: 8 },
// Backrest tilted back ~20° so a phone leans against it.
{ name: "Backrest", kind: "box", color: "#0098c7", x: 0, z: -22, elevation: 4, width: 80, depth: 8, height: 70, rotationX: 20 },
// Lip at the front to stop the phone sliding off.
{ name: "Lip", kind: "box", color: "#0098c7", x: 0, z: 28, elevation: 8, width: 80, depth: 8, height: 14 },
// Cable slot cut through the base.
{ name: "Cable slot", kind: "cylinder", color: "#d41721", hole: true, x: 0, z: 6, elevation: 0, width: 16, depth: 16, height: 24, radius: 8, sides: 64 },
],
};
export const BRACKET_EXAMPLE: { name: string; shapes: ShapeInput[] } = {
name: "L-bracket with bolt holes",
shapes: [
{ name: "Base flange", kind: "box", color: "#33983d", x: 0, z: 0, elevation: 0, width: 60, depth: 40, height: 6 },
{ name: "Upright flange", kind: "box", color: "#33983d", x: 0, z: -17, elevation: 6, width: 60, depth: 6, height: 40 },
{ name: "Bolt hole L", kind: "cylinder", color: "#d41721", hole: true, x: -18, z: 8, elevation: 0, width: 8, depth: 8, height: 12, radius: 4, sides: 48 },
{ name: "Bolt hole R", kind: "cylinder", color: "#d41721", hole: true, x: 18, z: 8, elevation: 0, width: 8, depth: 8, height: 12, radius: 4, sides: 48 },
],
};
export const EXAMPLE_SCENES = [PHONE_STAND_EXAMPLE, BRACKET_EXAMPLE];