S252 Handoff

Documentation for Sessions

S252 Handoff — Vitto Studio & Platform Generation

What S252 Accomplished

S252 took vitto-studio from "everything empty" to "live preview renders real generated platforms with CRUD data." The session fixed 3 major infrastructure layers:

1. SSE Event Pipeline (was: 3/15 events forwarded → now: all)

File: libs/libs-ai/vitto-chat/src/lib/services/vitto-chat-engine.service.ts:555-565

VittoChatEngineService now forwards ALL module-gen.*, pipeline.*, generation.*, phase.* SSE events to the studio via moduleGenEvents$. Previously only started/completed/failed were forwarded — the studio was blind to file writes, pipeline progress, manifest creation, etc.

2. Git Provider Unification (was: GitLab-hardcoded → now: provider-agnostic)

Files:

3. Live Preview in Blob URL (was: black screen → now: renders Angular app)

Files:

4. Other Fixes


What Still Needs Work (User's 6 Requirements)

Requirement 1: "Everything renders"

Current state: 4 of 5 modules render correctly. Club-dashboard has Module not found errors for ../../services/club-dashboard-api.service — deeply nested relative imports that fail intermittently in rspack's memfs.

Root causes to investigate:

Generation quality improvements needed:

Requirement 2: "Everything works, including custom CRUD"

Current state: List views work (real data from MongoDB via UniverseDataService stub). Form views render but save may not work — the useCrudForm.onSubmit() calls apiService.create() which calls UniverseDataService.create() which does fetch(POST /api/spaces/{spaceId}/universes/{universeId}/data/{collection}/insert).

Issues:

Requirement 3: "Renders quickly"

Current state: Preview shows "Ready when you are" → then compiles (~400ms) → renders. On page reload, there's a flash sequence: empty state → base template → generated platform (because VFS loads from develop first, then tryLatestGenerationBranch switches to feature branch).

Fixes needed:

Requirement 4: "Platform is performant"

Current state: The generated platform runs in a blob URL iframe with CDN externals (Angular, RxJS, zone.js from esm.sh). First load is slow because the browser fetches ~10 CDN modules. Subsequent navigations within the preview are instant.

Fixes needed:

Requirement 5: "Changes persist"

Current state: Changes made in the preview (CRUD data) persist in MongoDB via the real backend API. But code changes (editing components, styles) do NOT persist — the VFS is in-memory and the preview compiles from VFS.

What needs to work:

Requirement 6: "Can make changes via Vitto and via editing tool"

Current state:

What needs to be built:


Architecture Reference

Preview Compilation Chain

VfsSyncService (loads files from Hetzner git)
  → PreviewService.compileRspack()
    → detectModulesInVfs() (regex scan for modules/{slug}/src/*.routes.ts)
    → BundlerFilesystemService.enrichForWorker()
      → synthesizeAppShell() (main.ts, app.config.ts, app.routes.ts, app.component.ts, index.html)
      → stripAuthGuards()
      → compileScssFiles()
      → inlineAngularComponentResources()
      → synthesizeSdkStubs() (replaces @libs-* imports with stub implementations)
    → BundlerService.compile() → Worker postMessage
      → rspack-compiler.worker.js → rspack WASM → assets (main.js + main.css)
    → PreviewServerService.updateAssets()
      → prerequisite script (zone.js + compiler CDN, history API patch)
      → resolve bare specifiers (CDN_ONLY_MAP)
      → inline CSS
      → strip import map
      → blob URL → iframe

Git Provider Chain

Frontend (StudioApiService / GitStateService)
  → backend-ai-api StudioRepoController (relay)
    → backend-api GitProviderController
      → GIT_PROVIDER_SERVICE (injection token)
        → RemoteGitProviderService (Hetzner)  [if PLATFORM_GIT_SERVER_URL set]
        → LocalGitProviderService (filesystem) [if LOCAL_REPOS_ROOT set]
        → GitLabProviderService (GitLab API)   [fallback]

Key Files

File Purpose
libs/libs-ai/vitto-chat/src/lib/services/vitto-chat-engine.service.ts SSE event forwarding to studio
libs/libs-structural/vitto-studio/src/lib/services/preview.service.ts Preview compilation orchestrator
libs/libs-structural/vitto-studio/src/lib/services/vfs-sync.service.ts VFS hydration from git
libs/libs-structural/vitto-studio/src/lib/services/studio-generation-listener.service.ts SSE event handler, VFS writer
libs/libs-structural/platform-preview/src/lib/services/bundler-filesystem.service.ts File enrichment, app shell synthesis, SDK stubs injection
libs/libs-structural/platform-preview/src/lib/services/preview-server.service.ts Blob URL assembly, CDN specifier resolution
libs/libs-structural/platform-preview/src/lib/services/bundler.service.ts rspack worker orchestration
libs/libs-structural/platform-preview/src/lib/config/sdk-preview-stubs.ts SDK library stub implementations (~2000 lines)
libs/libs-structural/platform-preview/src/lib/config/esm-cdn-map.ts CDN URL map for Angular/RxJS/third-party
apps/gograb-space/src/rspack-compiler.worker.js rspack WASM compilation worker
APIs/backend-api/src/app/git-provider/git-provider.controller.ts Provider-agnostic git REST API
APIs/backend-api/src/app/studio/universe-git.service.ts Provider-agnostic universe git operations
APIs/backend-api/src/app/data/data.controller.ts Universe data CRUD (MongoDB)

Critical Constraints (Blob URL Preview)

  1. No import maps — blob: URLs don't support import maps. rspack embeds full CDN URLs via module ${url} externals.
  2. No history API — history.pushState/replaceState throws SecurityError. Monkey-patched in prerequisite script.
  3. No external CSS — <link rel="stylesheet"> can't resolve relative URLs. CSS inlined as <style>.
  4. No code splitting — blob: URLs can't load chunk files. dynamicImportMode: 'eager' bundles everything into main.js.
  5. @angular/compiler must load BEFORE main.js parse — static class initializers run at parse time. Handled by separate prerequisite <script> tag.
  6. SDK stubs live inside template literal strings — NOT as top-level imports. Top-level imports would crash the main app (FormBuilder outside DI context).

Env Vars (Git Provider Selection)

PLATFORM_GIT_SERVER_URL=https://sandbox.gograb.space  → RemoteGitProviderService
PLATFORM_GIT_API_KEY=...                               → X-API-Key header
LOCAL_REPOS_ROOT=/tmp/test-platforms                    → LocalGitProviderService
# Neither set → GitLabProviderService (fallback)

Recommended Session Plan

Session A: Generation Quality & DEPLOY Phase

  1. Fix DEPLOY phase to auto-merge feature branch → develop
  2. Improve generation prompts: barrel exports, flat imports, no deep ../../ paths
  3. Ensure generated modules match SDK stub API surface (all methods exist)
  4. Add generation validation: after committing files, verify they compile in rspack

Session B: Code Editing & Persistence

  1. Wire Code tab save (Monaco Ctrl+S → VFS update → git commit → preview recompile)
  2. Add Vitto edit_file tool for AI-driven code changes
  3. Implement draft branch system for unsaved edits
  4. Add file diff viewer before committing

Session C: Preview Performance & Polish

  1. CDN module preloading (<link rel="modulepreload">)
  2. Preview cache in sessionStorage/IndexedDB
  3. Batch file fetching (single API call for all module files)
  4. Remove consumed .html/.scss files from enriched map after inlining
  5. Add file fetch retry (1x) with logging of failed files

Session D: Visual Editor

  1. Property panel binding for selected components
  2. Inline style editing
  3. Template drag-drop editing
  4. Visual changes → VFS update → git commit → preview recompile