Plan, apply and roll back changes to a production ontology, with a blast radius report and a proof an auditor can re-check.
Rust ai-nativedescription-logicsformal-verificationinfrastructure-as-codeisabelle-languageknowledge-graphleanlean4mcpmcp-serverontologyowlowl2reasoningrustshaclsparqltheorem-proving
feat(studio): add the DemoSource interface and its replay implementation
FABIOTESScb4a62e951b8
diff --git a/studio/src/lib/__tests__/replay-source.test.ts b/studio/src/lib/__tests__/replay-source.test.tsnew file mode 100644index 00000000..a6645e35--- /dev/null+++ b/studio/src/lib/__tests__/replay-source.test.ts@@ -0,0 +1,49 @@+import { describe, it, expect } from 'vitest'+import { createReplaySource } from '../replay-source'++const fixtures = {+ corpus: [{ id: 'README', title: 'README', text: 'an implementation of the W3C DCAT standard' }],+ graph: { classes: [{ iri: 'ex:Dataset' }], properties: [], edges: [] },+ findings: [+ {+ id: 'f1',+ subject: 'ex:conformance',+ kind: 'provenance-split' as const,+ claims: [+ { document: 'README', predicate: 'claims', object: 'dcat-conformant' },+ { document: 'examples', predicate: 'yields', object: 'zero-dcat-triples' },+ ],+ },+ ],+ chat: { 'what disagrees?': [{ type: 'text' as const, value: 'README and examples disagree.' }] },+}++describe('ReplaySource', () => {+ it('returns the committed findings', async () => {+ const src = createReplaySource(fixtures)+ const found = await src.findings()+ expect(found).toHaveLength(1)+ expect(found[0].claims.map((c) => c.document)).toEqual(['README', 'examples'])+ })++ it('records a resolution in session state without mutating fixtures', async () => {+ const src = createReplaySource(fixtures)+ await src.resolve('f1', { kind: 'accept' })+ expect(await src.findings()).toHaveLength(1)+ expect(fixtures.findings).toHaveLength(1)+ })++ it('streams a scripted answer', async () => {+ const src = createReplaySource(fixtures)+ const out: string[] = []+ for await (const chunk of src.ask('what disagrees?')) out.push(chunk.value)+ expect(out.join('')).toContain('disagree')+ })++ it('answers unknown questions without throwing', async () => {+ const src = createReplaySource(fixtures)+ const out: string[] = []+ for await (const chunk of src.ask('unscripted question')) out.push(chunk.value)+ expect(out.join('')).not.toHaveLength(0)+ })+})diff --git a/studio/src/lib/demo-source.ts b/studio/src/lib/demo-source.tsnew file mode 100644index 00000000..304f441e--- /dev/null+++ b/studio/src/lib/demo-source.ts@@ -0,0 +1,23 @@+export interface Document { id: string; title: string; text: string }+export interface Claim { document: string; predicate: string; object: string }+export interface Contradiction {+ id: string+ subject: string+ kind: 'provenance-split' | 'disjointness' | 'typing'+ claims: Claim[]+}+export interface GraphView {+ classes: { iri: string; label?: string }[]+ properties: { iri: string; label?: string }[]+ edges: { source: string; target: string }[]+}+export type Decision = { kind: 'accept' | 'reject'; note?: string }+export interface Chunk { type: 'text' | 'tool_call'; value: string }++export interface DemoSource {+ corpus(): Promise<Document[]>+ graph(): Promise<GraphView>+ findings(): Promise<Contradiction[]>+ resolve(id: string, decision: Decision): Promise<void>+ ask(question: string): AsyncIterable<Chunk>+}diff --git a/studio/src/lib/replay-source.ts b/studio/src/lib/replay-source.tsnew file mode 100644index 00000000..41886c6d--- /dev/null+++ b/studio/src/lib/replay-source.ts@@ -0,0 +1,40 @@+import type { Chunk, Contradiction, Decision, DemoSource, Document, GraphView } from './demo-source'++export interface ReplayFixtures {+ corpus: Document[]+ graph: GraphView+ findings: Contradiction[]+ chat: Record<string, Chunk[]>+}++const UNSCRIPTED: Chunk[] = [+ {+ type: 'text',+ value:+ 'This is the offline replay of the demonstration. Only the scripted questions are answered here. Run the desktop application against the engine for a live session.',+ },+]++export function createReplaySource(fixtures: ReplayFixtures): DemoSource {+ const findings = fixtures.findings.map((f) => ({ ...f, claims: [...f.claims] }))+ const ledger: { id: string; decision: Decision }[] = []++ return {+ async corpus() {+ return fixtures.corpus+ },+ async graph() {+ return fixtures.graph+ },+ async findings() {+ return findings+ },+ async resolve(id, decision) {+ ledger.push({ id, decision })+ },+ async *ask(question) {+ const scripted = fixtures.chat[question.trim().toLowerCase()] ?? fixtures.chat[question]+ for (const chunk of scripted ?? UNSCRIPTED) yield chunk+ },+ }+}