Files
editor/packages/mcp/test-reports/research/PHASE7_PLAN.md
T
Adrian PerezandClaude Opus 4.7 e8d0b13ff5 feat(mcp,editor): Option A+B storage + 10 agent deliverables (Phase 7)
Ships the combined filesystem/Supabase storage adapter + MCP scene
lifecycle tools + Next.js API routes + editor /scene/[id] route, so
an MCP save is directly openable at /scene/<id> without any
injection hack. End-to-end verified: 10/10 e2e steps pass.

Storage (A1/A2/A3):
- SceneStore interface + error classes + slug helpers
- FilesystemSceneStore at $PASCAL_DATA_DIR (defaults XDG/~/.pascal)
  with atomic writes, .index sidecar, optimistic locking
- SupabaseSceneStore with scenes + scene_revisions tables, RLS
  migration SQL, mock-backed unit tests
- createSceneStore(env) auto-selects based on SUPABASE_URL +
  SUPABASE_SERVICE_ROLE_KEY

MCP tools (A4, A8, A9, A10):
- save_scene / load_scene / list_scenes / delete_scene / rename_scene
- list_templates / create_from_template (3 seed templates:
  empty-studio, two-bedroom, garden-house)
- generate_variants (7 mutation kinds, seeded RNG, save=true|false)
- photo_to_scene (vision sampling → scene graph → save)

Editor (A5, A6):
- /api/scenes + /api/scenes/[id] with RFC 7232 If-Match locking
- /scene/[id] and /scenes route pages with save button, SceneLoader
- Removed the window.__pascalScene dev injection hack

Security + UX edges (A7, A8):
- AssetUrl Zod validator: asset:// blob: data:image/ /path https:
  (http://localhost for dev) + PASCAL_ALLOWED_ASSET_ORIGINS env
  allowlist. Hardens scan.url, guide.url, item.asset.src,
  material.texture.url, MaterialMaps.*Map
- Auto-frame camera on empty→non-empty scene transition
  (camera-controls:fit-scene emitter event)

Shared utilities:
- rehydrateSiteChildren() extracted to packages/mcp/src/lib/ and
  used by both create-from-template and generate-variants to work
  around the SiteNode.children-as-objects vs. ids inconsistency
  (CROSS_CUTTING §2)
- Storage + MCP subpath exports added to packages/mcp/package.json
  (CROSS_CUTTING §4)

Tests: 293 pass / 0 fail across 40 files (was 142 pre-Phase-7).
Biome: clean.

Phase-7 e2e script at packages/mcp/test-reports/phase7-e2e.ts:
MCP HTTP + editor Next.js both point at $PASCAL_DATA_DIR =
/tmp/pascal-e2e, save_scene from MCP, GET /api/scenes/<id> from
editor server, /scenes list page renders all saved scenes, scene
page renders SceneLoader, delete_scene works.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-18 19:29:28 +02:00

4.0 KiB

Phase 7 plan — A+B storage + edge cases + ideas

Shared SceneStore contract (every agent reuses this)

// packages/mcp/src/storage/types.ts (Agent 1 owns)

import type { SceneGraph } from '@pascal-app/core/clone-scene-graph'

export type SceneId = string  // slug-safe (a-z0-9-), ≤ 64 chars

export interface SceneMeta {
  id: SceneId
  name: string
  projectId: string | null
  thumbnailUrl: string | null
  version: number            // monotonic, incremented on every save
  createdAt: string          // ISO 8601
  updatedAt: string
  ownerId: string | null
  sizeBytes: number
  nodeCount: number
}

export interface SceneWithGraph extends SceneMeta {
  graph: SceneGraph
}

export interface SceneStore {
  readonly backend: 'filesystem' | 'supabase'
  save(opts: {
    id?: SceneId
    name: string
    projectId?: string | null
    ownerId?: string | null
    graph: SceneGraph
    thumbnailUrl?: string | null
    expectedVersion?: number  // 409 on mismatch
  }): Promise<SceneMeta>
  load(id: SceneId): Promise<SceneWithGraph | null>
  list(opts?: { projectId?: string; ownerId?: string; limit?: number }): Promise<SceneMeta[]>
  delete(id: SceneId, opts?: { expectedVersion?: number }): Promise<boolean>
  rename(id: SceneId, newName: string, opts?: { expectedVersion?: number }): Promise<SceneMeta>
}

export class SceneNotFoundError extends Error { code = 'not_found' as const }
export class SceneVersionConflictError extends Error { code = 'version_conflict' as const }
export class SceneInvalidError extends Error { code = 'invalid' as const }
export class SceneTooLargeError extends Error { code = 'too_large' as const }

export function createSceneStore(env?: NodeJS.ProcessEnv): SceneStore { /* factory */ }

Agent scope map

Agent Scope File ownership
A1 Storage interface + types + factory packages/mcp/src/storage/types.ts, packages/mcp/src/storage/index.ts, packages/mcp/src/storage/store.test.ts
A2 Filesystem impl packages/mcp/src/storage/filesystem-scene-store.ts + tests
A3 Supabase impl + migration SQL packages/mcp/src/storage/supabase-scene-store.ts, packages/mcp/sql/migrations/0001_scenes.sql + tests
A4 MCP scene-lifecycle tools packages/mcp/src/tools/scene-lifecycle/*.ts + index wiring
A5 Next.js API routes apps/editor/app/api/scenes/route.ts, apps/editor/app/api/scenes/[id]/route.ts, apps/editor/lib/scene-store-server.ts
A6 Editor routes + kill dev hook apps/editor/app/scene/[id]/page.tsx, apps/editor/app/scenes/page.tsx, edit apps/editor/app/page.tsx
A7 URL hardening in core schemas packages/core/src/schema/nodes/{scan,guide,item}.ts, packages/core/src/schema/material.ts + migration
A8 Auto-frame camera + scene templates packages/editor/src/hooks/use-auto-frame.ts, packages/mcp/src/templates/*, packages/mcp/src/tools/scene-lifecycle/list-templates.ts
A9 Multi-variant generation packages/mcp/src/tools/variants/* + tests
A10 Photo → scene + example packages/mcp/src/tools/photo-to-scene/* (orchestrator), update README.md, new examples/photo-to-scene.md

Global coordination rules

  • Agent A1 drops first (interface only). A2, A3, A4, A5 read from packages/mcp/src/storage/types.ts; if it doesn't exist when they start, they should inline a copy of the types above and the integrator fixes up the import later.
  • All MCP tools use StreamableHTTPClientTransport-compatible input/output Zod schemas.
  • Every tool uses the shared SceneStore via createSceneStore() — never instantiates concrete stores.
  • Tests are bun:test, colocated.
  • Biome 2-space, single quote, no semicolons, trailing commas all.
  • Do NOT run bun install — already done.
  • Do NOT modify files outside your ownership.

Acceptance

  • bun test --cwd packages/mcp green.
  • bunx biome check packages/mcp apps/editor/app green.
  • bun run --cwd packages/mcp build green.
  • MCP save_scene → list_scenes → editor opens /scene/<id> works without window.__pascalScene.