Sıfırdan Yeni Bir Depo Başlatın:
Mevcut Bir Git Deposu veya Klasörü Gönderin:
Hataları Geri Alma, İptal & Temizlik:
Son commit'i geri al (yapılan değişiklikleri korur):
git reset --soft HEAD~1
Yapılan yerel değişiklikleri iptal et (çalışma ağacını temizler):
git restore .
Takip edilmeyen gereksiz dosyaları sil:
git clean -fd
Değişiklikleri geçici sakla ve geri getir (stash):
git stash git stash pop
Dal (Branch) ve Sürüm Etiketleri:
Yeni dal aç ve geçiş yap:
git checkout -b yeni-ozellik git push -u origin yeni-ozellik
Sürüm etiketi (tag) oluştur ve gönder:
git tag -a v1.0.0 -m "Sürüm 1.0.0" git push origin --tags
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]>
6.2 KiB
Scene Bridge — Build Plan
Work one phase per session. Each phase is a vertical slice that is independently testable. Do not start a phase until the previous one meets its acceptance criteria.
Phase 0 — Orientation (NO CODE)
Goal: Prove you understand the architecture before touching anything.
Read only these:
CLAUDE.md(root)apps/web/src/types/sketchforge.ts- The persistence block in
apps/web/src/app/page.tsx(IndexedDB + localStorage helpers, ~44–135) apps/web/src/app/api/local-download/route.ts(route + same-origin guard template)apps/web/src/lib/shapeCatalog.tsandapps/web/src/lib/workplaneShapes.ts
Deliverable: a short note (docs/scene-bridge/NOTES.md) stating, in your own words:
the IndexedDB record shape, the exact localStorage key, the existing read/write helper
names you will reuse, the URL the editor opens with, and the data flow diagram from
CLAUDE.md. List anything that contradicts CLAUDE.md — alpha drift is expected.
Acceptance: the note is correct against source. No code written.
Phase 1 — Bridge route (server only)
Goal: A local HTTP endpoint that stages and returns a scene.
- Create
apps/web/src/app/api/scene/route.ts. POSTbody{ projectId: string, shapes: WorkplaneShape[], op?: "upsertScene", name?: string }. Validate with the existing routes' style (size cap,isLocalSameOriginRequest,safeProjectId). Assign a monotonicstagingRevisionand write.codex/pending-scenes/<safeId>.json={ stagingRevision, op, projectId, name, shapes, updatedAt }. ThisstagingRevisionis the bridge's OWN counter — it is NOT the app's project revision (keep them separate).GET ?projectId=&sinceStaging=<n>returns the staged command if its stagingRevision is newer, else 204/empty.- Do not import or validate full geometry here — just the JSON shape.
Acceptance (curl, app running):
curl -X POST .../api/scenewith a 1-box scene → 200, file appears under.codex/pending-scenes/.GETreturns it;GETwithsinceequal to current revision returns empty.- Non-local / wrong-origin request → 403 (verify a plain Node
fetchfrom localhost passes; if it does not, document the exact header the MCP must send).
Phase 2 — Client hydrator (browser side)
Goal: The running app picks up a staged command and shows the scene.
- Add a
SceneTransportinterface (poll()now;subscribe()reserved for V2) and a polling implementation that hitsGET /api/scene?...&sinceStaging=for the target project. - Add the poller as a hook called from
Home(page.tsx) — NOT acomponents/module. On a command whosestagingRevisionexceeds the last one applied:- if
op === "upsertScene"and the project id is unknown, create it via the existing create-project path, then make it the active/open project; - call the existing
updateProjectShapes({ projectId, shapes })— it writes IndexedDB + localStorage + a winning project revision, and the editor's existing rehydration effect (keyed oninitialShapes/projectRevision) re-renders the viewport for free. - record the applied
stagingRevisionto avoid re-applying.
- if
- Gate behind a flag (e.g.
?bridge=1or an env var) so normal use is untouched. - Do NOT write IndexedDB directly and do NOT set a project revision yourself.
Acceptance:
- From the dashboard,
POSTanupsertScenefor a NEW project id (2 shapes, one withhole: true, grouped) → project is created, opened, and the geometry renders, no console errors.POSTagain with a higherstagingRevision→ scene updates. Reload → it persists (it's in IndexedDB). While dragging a shape, an incoming push is deferred, not fought.
Phase 3 — MCP server (apps/mcp/)
Goal: Claude-callable tools that drive the bridge.
- New workspace
apps/mcp/. ImportWorkplaneShape,canonicalizeShape, and the per-kind defaults fromapps/web(shared in the monorepo). - Tools:
get_scene(projectId)→ current staged shapes.set_scene(projectId, shapes, name?)→ validate, thenPOST /api/sceneasupsertScene(unknown ids are fine — the client creates the project in Phase 2).add_shapes(projectId, shapes)→ merge with current, re-POST.list_kinds()→ kinds + required/optional fields + defaults derived from the catalog, so the model self-corrects.
- Validation: zod checks the
ShapeKindunion enum + base required numerics ONLY, then run the importedcanonicalizeShapeto clamp/default. Do NOT hand-author parameter ranges — the app's canonicaliser is the single source of truth. Reject only structurally-broken shapes. - Ship a few example scenes (phone stand, bracket with bolt holes) as in-context references.
Acceptance:
- From Claude Code (or an MCP inspector):
set_scenewith a hand-written 3-shape scene for a fresh project id → project is created and the scene appears. Invalid shape (bad kind / malformed) → rejected by zod with a useful message, nothing staged. A valid-but-extreme shape is clamped bycanonicalizeShape, not rejected.
Phase 4 — End-to-end + polish
Goal: Prompt → scene in the editor.
- Driving Claude through the MCP: "a 40 mm phone stand with a cable slot" → valid
WorkplaneShape[]→ renders. - Add
get_sceneround-trip so the model can read back and iterate ("make the slot 5 mm wider"). - Document the loop in
docs/scene-bridge/README.md. Add 1–2 vitest cases for the schema validator and the route handler.
Acceptance: three different natural-language prompts each produce a sensible, error-free scene; iteration on an existing scene works.
V2 — MCP as source of truth (separate effort)
Only after V1 is solid. The seams are already in place:
- Replace the polling
SceneTransportwith a WebSocket implementation (subscribe()); route stays as a fallback. - MCP holds the canonical scene; pushes diffs; the editor reflects them live and round-trips user edits back over the socket.
- Keep the
WorkplaneShapecontract identical so V1 tools keep working.
Do not build V2 abstractions early. The SceneTransport interface from Phase 2 is the
only forward-compatibility you need now.