The editor now runs Socrates' three Phase-0-validated detection prompts against the live model, persists the findings, and surfaces them in a new FindingsPanel beside the IssuesPanel. Click any finding to focus its linked element across rail + diagram. Re-detect after model edits to refresh against the new state. apps/web/lib/llm/prompts/socrates - detect-assumptions.md / detect-risks.md / detect-inconsistencies.md promoted verbatim from phase-0 (Phase 0 corpus validated them 10/10). apps/web/lib/llm/detect.ts - Three sequential detection passes (parallel was OOM-prone on 4B local models — Phase 0 lesson). Each pass uses the Phase 0 JSON schema with jsonObjectMode fallback + chatJSON repair-retry. Fail-soft per pass: one busted pass returns [] rather than blowing up the whole detect. - post-validate strips hallucinated element refs (drops findings whose refs ALL fail to resolve; keeps findings with zero refs since some inconsistencies are genuinely about absences). apps/web/prisma/schema.prisma - Finding table: kind / text / linkedElementIds (JSON) / confidence / severity / validationCode / status / modelVersion / provider / model. - ResearchFinding table reserved for the Tavily integration that comes next — schema in place so we don't have to migrate again. apps/web/lib/db/repo.ts - listOpenFindings(projectId), replaceFindings(...) — replaceFindings wipes prior open findings in a transaction and writes the new set so re-detect doesn't accumulate stale findings. apps/web/app/api/projects/[projectId]/findings/route.ts - GET returns persisted open findings. - POST runs detect, persists, returns findings + meta (provider, model, durationMs, strippedRefs, droppedFindings). apps/web/components/editor/FindingsPanel.tsx - New panel, anchored bottom-right just left of IssuesPanel. Shows count summary (asm / risk / inc), detect / re-detect button, list grouped by kind (inconsistencies first, then risks, then assumptions), per-finding glyph + tag + severity + confidence + linked refs. - Click a finding row → focus its first linked element via the same setFocusBlockId path the rail and IssuesPanel already use. - "stale" indicator when the model version has advanced past the one the findings were detected against. EditorShell wires version + projectId through to FindingsPanel. Smoke-tested end-to-end: 12 findings returned (5 asm / 4 risk / 3 inc), 0 hallucinated refs stripped, ~37s on local gemma-4-e4b. Sample assumption "students are willing to engage with an AI tutor that is programmed to refuse providing complete solutions" — specific to Aristotle's refusal_policy, not a generic startup truism. Deferred to follow-ups: inline rail/diagram badges from findings, auto-detect-on-save, Tavily research, experiment modal.
173 lines
5.7 KiB
TypeScript
173 lines
5.7 KiB
TypeScript
// The dual-canvas workspace shell.
|
|
// M5: state lives in ModelStoreProvider; both canvases consume the canonical
|
|
// SysMLModel and emit ModelOps back through useApply().
|
|
|
|
"use client";
|
|
|
|
import { useMemo, useState, Suspense } from "react";
|
|
import { useSearchParams } from "next/navigation";
|
|
import { TopBar } from "./TopBar";
|
|
import { LeftRail } from "./LeftRail";
|
|
import { CanvasHeader } from "./CanvasHeader";
|
|
import { StatusBar } from "./StatusBar";
|
|
import { IssuesPanel } from "./IssuesPanel";
|
|
import { FindingsPanel } from "./FindingsPanel";
|
|
import { TextCanvas } from "../text-canvas/TextCanvas";
|
|
import { DiagramCanvas, type DiagramVariant } from "../diagram-canvas/DiagramCanvas";
|
|
import { SocratesDock, type Density, type SocratesPresence } from "../socrates/SocratesDock";
|
|
import type { MarkupStyle } from "../text-canvas/Chip";
|
|
import type { FixtureData } from "../../lib/fixtures/aristotle";
|
|
import { fromFixture } from "../../lib/sysml/fromFixture";
|
|
import { applyBreaks, BREAKS, type BreakName } from "../../lib/sysml/breaks";
|
|
import { ModelStoreProvider, useModelStore } from "../../lib/sync/ModelStore";
|
|
|
|
interface EditorShellProps {
|
|
data: FixtureData;
|
|
/** Server-loaded initial model + version (M5.9). When omitted, falls back to
|
|
* deriving from `data` (legacy fixture path; useful for tests). */
|
|
initialModel?: import("../../lib/sysml/model").SysMLModel;
|
|
initialVersion?: number;
|
|
/** When set, apply() POSTs to /api/projects/[projectId]/apply. */
|
|
projectId?: string;
|
|
density?: Density;
|
|
markupStyle?: MarkupStyle;
|
|
diagramStyle?: DiagramVariant;
|
|
presence?: SocratesPresence;
|
|
}
|
|
|
|
export function EditorShell(props: EditorShellProps) {
|
|
return (
|
|
<Suspense fallback={null}>
|
|
<EditorShellInner {...props} />
|
|
</Suspense>
|
|
);
|
|
}
|
|
|
|
function EditorShellInner({
|
|
data,
|
|
initialModel,
|
|
initialVersion,
|
|
projectId,
|
|
density = "comfortable",
|
|
markupStyle = "color",
|
|
diagramStyle = "softened",
|
|
presence = "default",
|
|
}: EditorShellProps) {
|
|
const searchParams = useSearchParams();
|
|
|
|
const breaks = useMemo<BreakName[]>(() => {
|
|
const raw = searchParams?.get("break") ?? "";
|
|
if (!raw) return [];
|
|
return raw.split(",").map(s => s.trim()).filter((s): s is BreakName => s in BREAKS);
|
|
}, [searchParams]);
|
|
|
|
// Prefer server-loaded model; fall back to fixture derivation for legacy
|
|
// callers without DB persistence wiring.
|
|
const startingModel = useMemo(() => {
|
|
const base = initialModel ?? fromFixture(data);
|
|
return breaks.length > 0 ? applyBreaks(base, breaks) : base;
|
|
}, [initialModel, data, breaks]);
|
|
|
|
return (
|
|
<ModelStoreProvider
|
|
initialModel={startingModel}
|
|
initialVersion={initialVersion ?? 1}
|
|
projectId={projectId}
|
|
>
|
|
<ShellBody
|
|
data={data}
|
|
projectId={projectId}
|
|
density={density}
|
|
markupStyle={markupStyle}
|
|
diagramStyle={diagramStyle}
|
|
presence={presence}
|
|
breaks={breaks}
|
|
/>
|
|
</ModelStoreProvider>
|
|
);
|
|
}
|
|
|
|
interface ShellBodyProps {
|
|
data: FixtureData;
|
|
projectId?: string;
|
|
density: Density;
|
|
markupStyle: MarkupStyle;
|
|
diagramStyle: DiagramVariant;
|
|
presence: SocratesPresence;
|
|
breaks: BreakName[];
|
|
}
|
|
|
|
function ShellBody({ data, projectId, density, markupStyle, diagramStyle, presence, breaks }: ShellBodyProps) {
|
|
const [focusBlockId, setFocusBlockId] = useState<string | null>(null);
|
|
const { model, version, issues, issuesByElement } = useModelStore();
|
|
|
|
const stats = `SysML · ${model.blocks.length} blocks · ${model.associations.length} associations · ${model.constraints.length} constraints`;
|
|
const subtitle = breaks.length > 0 ? `${stats} · breaks active: ${breaks.join(", ")}` : stats;
|
|
|
|
return (
|
|
<div className={`shell shell-density-${density} shell-presence-${presence}`}>
|
|
<TopBar data={data} />
|
|
|
|
<div className="shell-body">
|
|
<SocratesDock projectId={projectId ?? "aristotle"} presence={presence} density={density} />
|
|
<LeftRail
|
|
data={data}
|
|
focusBlockId={focusBlockId}
|
|
setFocusBlockId={setFocusBlockId}
|
|
issuesByElement={issuesByElement}
|
|
/>
|
|
|
|
<main className="canvases">
|
|
<section className="canvas canvas-text">
|
|
<CanvasHeader title="Narrative" subtitle="Markup-augmented prose · synced to model" />
|
|
<div className="canvas-scroll">
|
|
<TextCanvas
|
|
data={data}
|
|
density={density}
|
|
markupStyle={markupStyle}
|
|
focusBlockId={focusBlockId}
|
|
setFocusBlockId={setFocusBlockId}
|
|
/>
|
|
</div>
|
|
</section>
|
|
|
|
<div className="canvas-divider" />
|
|
|
|
<section className="canvas canvas-diagram">
|
|
<CanvasHeader
|
|
title="Model"
|
|
subtitle={subtitle}
|
|
right={
|
|
<div className="canvas-actions">
|
|
<span className="canvas-mode-pill">Fit</span>
|
|
<span className="canvas-mode-pill canvas-mode-active">100%</span>
|
|
<span className="canvas-mode-pill">Layout</span>
|
|
</div>
|
|
}
|
|
/>
|
|
<div className="canvas-scroll canvas-scroll-diagram">
|
|
<DiagramCanvas
|
|
data={data}
|
|
density={density}
|
|
variant={diagramStyle}
|
|
focusBlockId={focusBlockId}
|
|
onSelect={setFocusBlockId}
|
|
issuesByElement={issuesByElement}
|
|
/>
|
|
</div>
|
|
</section>
|
|
</main>
|
|
</div>
|
|
|
|
<StatusBar data={data} />
|
|
|
|
<IssuesPanel issues={issues} onSelectAnchor={id => setFocusBlockId(id)} />
|
|
<FindingsPanel
|
|
projectId={projectId ?? "aristotle"}
|
|
modelVersion={version}
|
|
onSelectAnchor={id => setFocusBlockId(id)}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|