cortex-next is the interactive Next.js client for Cortex. It does not run TRIBE v2 itself. Instead, it loads a reproducible runtime manifest, replays previously captured cortical event streams, renders them on a parcel-aware brain mesh, and presents both the TRIBE-derived summary and a separate emotion-analysis layer.
The current product path is backend-free recorded replay: the frontend reads a storage-hosted runtime manifest and fetches recorded stream files directly in the browser. The companion backend in ../cortex-fastapi is still used for fixture capture, publishing, and optional live/provider work.
The upstream model predicts cortical activity. This frontend is the experimental replay and inspection layer around those predictions:
- raw TRIBE output is a dense numerical time series; the frontend consumes normalized event streams and summary artifacts
- raw TRIBE usage does not define a static library or deployment format; the frontend reads a manifest of fixed, reproducible examples
- raw TRIBE usage does not provide parcel-aware inspection; the frontend adds a 3D cortical viewer, hover labels, split-brain interaction, and region callouts
- raw TRIBE usage does not separate emotional interpretation from cortical evidence; the frontend displays the saved DeepSeek emotion layer alongside the preserved TRIBE summary
At a high level, the frontend:
- lets the user browse and launch the recorded examples from a static manifest
- fetches the selected example's recorded event stream directly from storage
- applies captured cortical activity to the left and right hemisphere meshes
- stores full frame history for post-analysis replay and scrubbing
- renders hover inspection, split-brain viewing, and top-region callouts
- shows the final TRIBE summary, recommendations, and technical evidence once replay completes
- loads and presents a separate emotion-analysis artifact when one is available
- Next.js 16 App Router
- React 19
- TypeScript
- Tailwind CSS 4
- Framer Motion
- Zustand
- Three.js
three-mesh-bvhthree-subdivide
Important frontend entrypoints:
app/page.tsx- mounts the application shell
components/cortex-app.tsx- top-level client orchestrator for phase changes, prompts, loader state, split state, callouts, and panel visibility
components/brain/brain-scene.tsx- native Three.js scene and animation runtime
components/ui/*- prompt, feedback, hover tooltip, split switch, legend, and score panel
lib/api.ts- static manifest loading plus the legacy backend session helpers
lib/analysis-stream.ts- static recorded replay orchestration plus the legacy WebSocket path
lib/store.ts- central Zustand state for phase, latest frame, summary, hover state, and errors
lib/schemas.ts- runtime Zod validation for backend responses and stream events
app/page.tsx renders CortexApp.
CortexApp is the real UI controller. It owns:
- prompt submission
- loader progress and dismissal
- result-panel visibility
- split-brain toggle state
- region-label toggle state
- callout list state
It reads long-lived analysis state from Zustand and keeps transient UI choreography local.
The input UI is components/ui/prompt-composer.tsx.
When the user submits:
- the current stream is disconnected if one exists
- Zustand is reset into a
connectingphase openAnalysisStream(request, handlers)is called
The composer now runs from the recorded example library only.
Recorded entries are loaded from NEXT_PUBLIC_RECORDED_MANIFEST_URL when that env var is set. Each selected example includes an events_url, so the browser can fetch the saved JSONL stream directly without creating a backend session. When present, the same manifest entry also carries an emotion_analysis_url, which is loaded separately so the emotional interpretation remains distinct from the recorded TRIBE summary.
Static replay mode is the default deployment path.
When NEXT_PUBLIC_RECORDED_MANIFEST_URL is configured, the frontend:
- loads the runtime manifest through
fetchFixtures() - submits the selected fixture with
mode="replay"and itsevents_url - fetches that JSONL event stream from storage
- schedules the recorded events locally in the browser
lib/analysis-stream.ts is responsible for:
- open timeout handling
- replay pacing for text, audio, and video
- parsing every incoming event through Zod
- forwarding valid events into the store
- surfacing stream errors cleanly
If no recorded manifest URL is configured, the legacy backend path can still create sessions and open the backend WebSocket.
lib/store.ts is the single source of truth for streamed analysis state.
It tracks:
phasestatusTextprovidersessionIdcurrentPromptlatestFrameframeHistoryselectedFrameIndexreplayMetasummaryerrorMessagehoverInfo
Incoming events update the store by type:
session.acceptedanalysis.preparing_eventsanalysis.startedanalysis.frameanalysis.summaryanalysis.erroranalysis.done
This keeps the UI declarative while avoiding large prop chains.
The center of the frontend is components/brain/brain-scene.tsx.
This file runs an imperative Three.js scene inside React. It does not rely on React Three Fiber. That is intentional: the scene has a lot of frame-by-frame mesh, color, hover, and split-state work, and the project keeps that work close to the renderer.
The scene boot sequence:
- creates a
WebGLRenderer,Scene,PerspectiveCamera, andOrbitControls - loads left and right hemisphere GLB assets
- applies subdivision for the display shell
- builds color buffers and parcel lookup data
- loads hover guide / parcel mapping data from local JSON assets
The backend sends sampled left/right activity arrays, not a full arbitrary mesh payload.
The frontend maps those arrays onto the display shell using:
fsaverage5-aligned lookup data- per-hemisphere sample-to-vertex mappings
- parcel labels and copy from the local hover guide
The brain scene is responsible for:
- closed idle pose
- streamed activation coloring
- split-brain hinge motion
- panel-aware scaling and framing
- hover highlighting
- top-region callout placement
The split-brain effect is not a camera trick. Each hemisphere is moved through its own hinge group so the medial surfaces can be exposed.
Hover interaction is accelerated with three-mesh-bvh, which replaces default face raycasting with BVH-accelerated queries. That keeps parcel hover usable on the dense cortex mesh.
When inspection is enabled, the scene:
- resolves the hovered parcel
- emits hover info to the tooltip
- projects the top regions into screen space
- positions the callout cards on outer rails
The current callout system is layout-aware enough to keep the top cards separated and away from the center brain view better than the earlier fixed-position implementation.
Once the backend emits analysis.summary, CortexApp waits briefly, then reveals the result panel.
components/ui/score-panel.tsx renders:
- the headline
- narrative summary
- a separate emotion estimate panel backed by the saved DeepSeek artifact
- audience-facing insight cards
- recommendations
- a collapsible technical evidence section
- top brain regions behind the response
The panel is intentionally split between:
- a product-facing top section
- a more technical evidence section below
The frontend now ships the parcel metadata needed for hover/callout rendering as local JSON assets.
That payload defines:
- parcel ids
- canonical parcel labels
- display names
- system ids and system labels
- role labels and role descriptions
- left/right vertex-to-parcel assignments
This is what lets the client show parcel-level copy instead of anonymous left/right heat.
Main frontend variable for current recorded-only deployment:
NEXT_PUBLIC_RECORDED_MANIFEST_URL- static runtime manifest URL used to load recorded examples and their event streams
Current Cloudinary deployment value:
NEXT_PUBLIC_RECORDED_MANIFEST_URL=https://res.cloudinary.com/dcelboq45/raw/upload/v1776287421/recorded-runtime/runtime-manifest.jsonLegacy backend variable:
NEXT_PUBLIC_API_BASE_URL- backend base URL used only when running the old backend session/WebSocket path
Do not set NEXT_PUBLIC_API_BASE_URL for frontend-only static replay mode.
Example legacy backend env:
NEXT_PUBLIC_API_BASE_URL=http://127.0.0.1:8000Profile examples also live in:
profiles/local-backend.env.exampleprofiles/remote-do.env.example
cd cortex-next
npm install
npm run devFor recorded replay, set NEXT_PUBLIC_RECORDED_MANIFEST_URL in .env.local first.
From the workspace root:
./start-both.sh local-static-recorded
./start-both.sh local-recorded
./start-both.sh local-tribe-cpu
./start-both.sh local-tribe-mps
./start-both.sh remote-doThe launcher defaults to local-static-recorded, kills stale local listeners by default, and only starts the backend for backend profiles.
npm run devnpm run buildnpm run startnpm run lint
The current product surface is intentionally replay-first.
That means:
- the UI currently submits recorded replay sessions only
- the example browser depends on
NEXT_PUBLIC_RECORDED_MANIFEST_URLin static mode - text examples intentionally do not expose media-style replay controls after completion
- live text/audio/video upload is still a separate future track and is not exposed in this interface
The frontend does not require the backend for the current static replay deployment.
In other words, this app is not a thin TRIBE v2 demo client. It is a replay, visualization, and inspection system built on top of precomputed TRIBE artifacts.
If you run the legacy backend path, the frontend expects:
POST /api/v1/sessionsGET /api/v1/brain/guideWS /api/v1/stream/{session_id}
The backend is responsible for:
- provider selection (
tribeorrecorded) - timed-event preparation
- frame generation
- summary generation
- optional DeepSeek/OpenAI refinement
The frontend is responsible for:
- turning those events into a fluid interactive visualization
- managing the session lifecycle in the browser
- presenting both the audience summary and the technical evidence