diff --git a/components/scenario-form.jsx b/components/scenario-form.jsx index 416f1f8..78c0034 100644 --- a/components/scenario-form.jsx +++ b/components/scenario-form.jsx @@ -4,9 +4,7 @@ import React, { useEffect } from "react"; import { useState, useRef, useMemo } from "react"; import DiagnosticsView from "@/components/diagnostics-view"; import ReasoningWorkspace, { LoadingOverlay, ContinueLaterBanner } from "@/components/reasoning-workspace"; -import ExperimentalBranchSwitcher, { PulseStyle } from "@/components/experimental/branch-switcher"; import { mockFetch, AVAILABLE_SCENARIOS } from "@/lib/mocks/confidence-engine/mock-client"; -import { useBranchScopedFixture } from "@/lib/fixtures/rto26b-branch-scoped.mjs"; /* Compile-time env resolution — NEXT_PUBLIC_ vars are injected by Next.js at build */ const MOCK_ENABLED = process.env.NEXT_PUBLIC_CONFIDENCE_ENGINE_MOCKS === "true"; @@ -231,19 +229,13 @@ export function hasValidInvestigationContext(result, status, scenario) { * Derives the primary surface that must render for the given state tuple. * Enforces exactly-one-primary-surface invariant: no zero, no two. */ -export function derivePrimarySurface(result, status, showExperimentView, scenario, activeBranchId) { +export function derivePrimarySurface(result, status, _showExperimentView, scenario, activeBranchId) { if (status === "loading") return "LOADING"; if (status === "error") return "ERROR_SURFACE"; const valid = hasValidInvestigationContext(result, status, scenario); - // RTO.28B: show question-selection surface when investigation exists but no question/branch is active - if (showExperimentView && valid && !activeBranchId) return "BRANCH_SELECTION"; - - if (showExperimentView && valid) return "EXPERIMENT_NOTEBOOK"; - if (!showExperimentView && valid) return "NORMAL_WORKSPACE"; - if (!showExperimentView) return "SCENARIO_ENTRY"; - // showExperimentView === true but no valid context → fall back to entry + if (valid) return "NORMAL_WORKSPACE"; return "SCENARIO_ENTRY"; } @@ -261,84 +253,6 @@ export default function ScenarioForm() { const [hideFacilitatorOnLanding, setHideFacilitatorOnLanding] = useState(false); const textareaRef = useRef(null); - /* ── RTO.25A — passive late-result branch switcher (experimental) ── */ - - // RTO.28A: no active branch until the user explicitly chooses one. - const [activeBranchId, setActiveBranchId] = useState(null); - // Pre-seed Competitor development with a late result for RTO.27A testing - const [branchNewResults, setBranchNewResults] = useState({ "branch-a": true }); - - /* ── RTO.27B — provisional done-for-now state (experimental) ── */ - - const [doneForNowBranchIds, setDoneForNowBranchIds] = useState([]); - - /* ── RTO.26B — experimental branch-scoped reasoning fixture ───── */ - - const branchScoped = useBranchScopedFixture(); - // Toggle to control when the experiment view is visible vs production - // Always start false for SSR-safe deterministic first render. - // sessionStorage reads are deferred to useEffect (after mount). - const [showExperimentView, setShowExperimentView] = useState(false); - - // Use fixture branches as the authoritative source when available - const BRANCHES = useMemo(() => branchScoped.getBranches(), [branchScoped]); - - // Track the originating question for provenance - const [originQuestion, setOriginQuestion] = useState(null); - - // Extract inferred questions from the fixture (flat list for post-Analyse surface) - const inferredQuestions = useMemo(() => { - if (!branchScoped || typeof branchScoped.getAllInferredQuestions !== 'function') return []; - return branchScoped.getAllInferredQuestions(); - }, [branchScoped]); - - // Simulate a late semantic result arriving on Branch A ~2s after a graph loads - useEffect(() => { - if (status !== "success" && status !== "error") return; - if (branchNewResults["branch-a"]) return; - - const timer = setTimeout(() => { - setBranchNewResults((prev) => ({ ...prev, "branch-a": true })); - }, 2000); - return () => clearTimeout(timer); - }, [status, branchNewResults]); - - // Compute branch-local data for the active branch (explicit provenance) - const activeBranch = BRANCHES.find(b => b.id === activeBranchId); - const experimentalBranchQuestions = useMemo(() => { - if (!activeBranch) return []; - return branchScoped.getBranchQuestions(activeBranch.id); - }, [activeBranch, branchScoped]); - - const experimentalBranchContributions = useMemo(() => { - if (!activeBranch) return []; - return branchScoped.getBranchContributions(activeBranch.id); - }, [activeBranch, branchScoped]); - - // RTO.27A — late results for active branch - const experimentalBranchLateResults = useMemo(() => { - if (!activeBranch) return []; - return (branchScoped.getBranchLateResults?.(activeBranch.id) || []).map(lr => ({ text: lr.text })); - }, [activeBranch, branchScoped]); - - // Determine which non-active branches have new results for passive indicator - // (RTO.27B: also include done-for-now branches so pause state is visible) - const inactiveBranchNewResults = useMemo(() => { - const result = {}; - BRANCHES.forEach(b => { - if (b.id !== activeBranchId) { - if (b.id in branchNewResults) { - result[b.id] = true; - } - // Show pause indicator on any done-for-now branch - if (doneForNowBranchIds.includes(b.id)) { - result[b.id] = true; - } - } - }); - return result; - }, [activeBranchId, BRANCHES, branchNewResults, doneForNowBranchIds]); - /* ── Valid investigation predicate ─────────────────────── */ // Delegated to the exported utility below. @@ -361,33 +275,9 @@ export default function ScenarioForm() { // investigation data to render. if (hasGraph) { setStatus("success"); - setShowExperimentView(true); } }, []); - /* Restore experiment view preference from storage (after hydration) ─ */ - useEffect(() => { - if (typeof window === "undefined") return; - - // Only promote to experiment mode when there is real investigation - // data to render. The ce-show-experiment flag is a presentation - // preference, not proof that an investigation exists. - if (!validCtx) return; - - const savedExp = sessionStorage?.getItem("ce-show-experiment"); - if (savedExp === "true") { - setShowExperimentView(true); - return; - } - - // Also enable experiment mode if session data provides a graph - // (covers the pre-restoration case where scenario was typed but not yet submitted). - const session = getSession(); - if (session?.situationGraph) { - setShowExperimentView(true); - } - }, [validCtx]); - /* Restore facilitator dismiss preference (Experiment 05) ─── */ useEffect(() => { if (typeof window === "undefined") return; @@ -542,135 +432,8 @@ export default function ScenarioForm() { return (
{currentUnderstanding}
-Click a question to start investigating. A branch will be created for your choice.
- - {inferredQuestions.map((q) => ( - - ))} - - {inferredQuestions.length === 0 && ( -No questions available yet.
- )} -- Production view active. -
- -