From 4a4f2f37ba75629345ae9f27f316863419db04e4 Mon Sep 17 00:00:00 2001 From: "Christopher S. Aondona" Date: Thu, 26 Nov 2026 20:47:04 +0100 Subject: [PATCH] feat(playground): reconcile public authoring studio with current native player --- .github/workflows/ci.yml | 6 + CHANGELOG.md | 2 + README.md | 9 + package.json | 3 + playground/studio/README.md | 90 ++++++ playground/studio/index.html | 19 ++ playground/studio/main.tsx | 468 +++++++++++++++++++++++++++ playground/studio/public/_headers | 4 + playground/studio/public/favicon.svg | 7 + playground/studio/style.css | 285 ++++++++++++++++ playground/studio/vite.config.ts | 12 + playground/studio/workbench.test.ts | 63 ++++ playground/studio/workbench.ts | 83 +++++ scripts/audit-playground.mjs | 89 +++++ tsconfig.preview.json | 4 +- vitest.config.ts | 2 +- 16 files changed, 1144 insertions(+), 2 deletions(-) create mode 100644 playground/studio/README.md create mode 100644 playground/studio/index.html create mode 100644 playground/studio/main.tsx create mode 100644 playground/studio/public/_headers create mode 100644 playground/studio/public/favicon.svg create mode 100644 playground/studio/style.css create mode 100644 playground/studio/vite.config.ts create mode 100644 playground/studio/workbench.test.ts create mode 100644 playground/studio/workbench.ts create mode 100644 scripts/audit-playground.mjs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 72c2abcb..255a63f1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -52,6 +52,8 @@ jobs: run: pnpm preview:typecheck - name: Bundle local preview run: pnpm preview:build + - name: Bundle public authoring studio + run: pnpm studio:build - name: Compiler, release performance and hostile-input tests env: THL_SOURCE_SHA: ${{ github.event.pull_request.head.sha || github.sha }} @@ -76,6 +78,8 @@ jobs: run: pnpm exec playwright install --with-deps chromium - name: Browser tests run: pnpm test:browser:run + - name: Built public studio smoke test + run: pnpm audit:playground - name: Record verified Chromium browser evidence env: THL_SOURCE_SHA: ${{ github.event.pull_request.head.sha || github.sha }} @@ -136,11 +140,13 @@ jobs: pnpm typecheck pnpm preview:typecheck pnpm preview:build + pnpm studio:build pnpm test:run node scripts/verify-release-evidence.mjs node scripts/test-release-evidence.mjs node --test scripts/release-candidate-gate.test.mjs pnpm test:browser:run + pnpm audit:playground pnpm build pnpm audit:licenses pnpm audit:pack diff --git a/CHANGELOG.md b/CHANGELOG.md index f1a8e5ca..759028a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ All notable changes to Throughline are recorded here. Package versions follow ## [Unreleased] +- Reconcile the public authoring studio with current schema-2 source and the native compact player, keeping the Mermaid feasibility host and its build separate. Add independent studio build and browser smoke coverage; no deployment or npm publication is implied. + - Reconcile compact-player documentation and manual AT instructions with supported view tabs, Inspect toggle, responsive Workflow inspector and source-detail tools; preserve the NOT PERFORMED human acceptance record. - Separate authored mutable shapes from readonly validated/derived public declarations, with source and packed declaration regressions. - Enforce strict release evidence identity and schemas, immutable exact-archive preparation and separately authorized staging. Production audit and final human acceptance remain mandatory and outstanding. diff --git a/README.md b/README.md index b8c19973..559925cb 100644 --- a/README.md +++ b/README.md @@ -295,6 +295,15 @@ Open http://localhost:5173 to inspect states and source events and read the matched explanations/questions at desktop, tablet and mobile widths. The preview is excluded from the published npm package. +## Public authoring studio + +The [Playground authoring studio](playground/studio/README.md) uses the current +native public React player with four reference artifacts, strict JSON editing, +compiler diagnostics and validated JSON/Markdown export. Run `pnpm studio:dev` +and open http://localhost:5174. Build with `pnpm studio:build`; the static site +is separate from the experimental Mermaid host above and from the npm package. +Deployment requires separate maintainer approval. + ## Behind the model 1. **Validate:** strict schema-2 input is detached and checked for diff --git a/package.json b/package.json index 7ba556ce..ea11aa54 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,9 @@ "dev": "vite --config playground/vite.config.ts", "preview:build": "vite build --config playground/vite.config.ts", "preview:typecheck": "tsc -p tsconfig.preview.json", + "studio:dev": "vite --config playground/studio/vite.config.ts", + "studio:build": "vite build --config playground/studio/vite.config.ts", + "audit:playground": "node scripts/audit-playground.mjs", "build": "tsdown && node scripts/verify-dist.mjs", "typecheck": "tsc --noEmit", "test:run": "vitest run", diff --git a/playground/studio/README.md b/playground/studio/README.md new file mode 100644 index 00000000..79b6cac6 --- /dev/null +++ b/playground/studio/README.md @@ -0,0 +1,90 @@ +# Throughline Playground + +A static, browser-only authoring workspace for schema-2 VisualArtifact JSON. This +is the public-facing experience, not a fixed development preview or a separately +published package. It imports the current repository source, so deployment must +be aligned with a reviewed and tested commit. + +## User workflow + +- Load one of four reference artifacts, or select **New trace**. +- Edit strict schema-2 JSON and see semantic compiler diagnostics after a brief + pause. The path in a diagnostic refers to the JSON artifact. While an edit + is being checked, the old visualization is not presented as current evidence. +- On a valid artifact, use Graph, Sequence, State table and Inspect in + the native player; change its width, presentation theme or playback settings. +- **Format** canonicalizes an already valid artifact into indented JSON. +- **Copy thl** copies a fenced Markdown snippet; **Export** downloads a validated + JSON artifact. Invalid or unreviewed prose is not exported as runnable data. +- Pasting a single complete `thl` Markdown fence unwraps it into editable JSON. +- Edits remain in the current browser tab; there is deliberately no account, + save service, telemetry, network-backed compiler or automatic AI generation. + +The editor interprets a body beginning with `{` as strict schema-2 JSON, just +as the source library does. Any other nonempty body is descriptive intent: +it needs independently reviewed materialization and a trusted host's approved +sidecar. The public playground deliberately does not fabricate that step. + +## Local development + +From the repository root, with Node.js >=24 and the pinned pnpm: + +```sh +pnpm install --frozen-lockfile +pnpm preview:typecheck +pnpm studio:dev +``` + +Visit http://localhost:5174. Before release, run: + +```sh +pnpm test:run +pnpm studio:build +pnpm test:browser:run +pnpm audit:playground +``` + +The existing `pnpm dev` and `pnpm preview:build` commands still serve/build +only the separate Checkout Mermaid feasibility host; they are not public studio +builds. The studio uses the native public React entry and does not import the +experimental Mermaid adapter. Change the Pages project build command/output +only with maintainer approval. + +The static output lives in **playground/studio/dist**. No backend routes, API keys or +service bindings are necessary. The package's own `pnpm build` and tarball do +not include the playground. + +## Cloudflare Pages deployment (maintainer setup) + +Suggested hostname: **playground.0xbuff.com**, after the maintainer has +confirmed DNS ownership. This proposal does not create DNS or deploy the app. + +Connect this public repository to a Cloudflare Pages project and configure: + +| Setting | Value | +| --- | --- | +| Source branch | `main` after the PR is reviewed and merged | +| Root directory | Repository root | +| Build command | `corepack enable && pnpm install --frozen-lockfile && pnpm studio:build` | +| Output directory | `playground/studio/dist` | +| Build environment | Node.js 24 (set `NODE_VERSION=24` if needed) | +| Environment variables / secrets | None required by the playground | + +The pinned `packageManager` is `pnpm@11.2.2`. Ensure the Pages build +environment supports Corepack/pnpm for that version. Verify the Pages preview +deployment, keyboard navigation, paste/edit/validation, theme, narrow viewport, +console errors and actual artifact export **before** attaching a public custom +domain. In Cloudflare Pages, use the project's **Custom domains** control to +attach the chosen subdomain and follow the DNS guidance for the zone; confirm +the certificate and HTTPS before announcing the URL. + +The `public/_headers` file is copied into the static build and adds basic +security and privacy headers when served by Cloudflare Pages. Cloudflare +deployment credentials and DNS records must never be committed to this repo. + +## Release boundaries + +The playground follows the checked-out schema-2 **source**, not the currently +published npm release. A successful preview deployment is not evidence of npm +v0.2.0 publication, TL-U18 real screen-reader acceptance or completion of +the planned higher-level ThroughlineDocument/VisualPlan capabilities. diff --git a/playground/studio/index.html b/playground/studio/index.html new file mode 100644 index 00000000..4bde325a --- /dev/null +++ b/playground/studio/index.html @@ -0,0 +1,19 @@ + + + + + + + + + + + + + Throughline Playground — Make state visible + + +
+ + + diff --git a/playground/studio/main.tsx b/playground/studio/main.tsx new file mode 100644 index 00000000..ad2a8ab1 --- /dev/null +++ b/playground/studio/main.tsx @@ -0,0 +1,468 @@ +import { StrictMode, useEffect, useMemo, useRef, useState } from "react"; +import type { ReactNode } from "react"; +import { createRoot } from "react-dom/client"; +import { EXAMPLES } from "../../src/examples.js"; +import { ThroughlineGraphPlayer } from "../../src/react/index.js"; +import { + STARTER_SOURCE, + compileWorkbenchSource, + formatWorkbenchSource, + markdownForSource, + unwrapThlFence, +} from "./workbench.js"; +import "../../src/styles/throughline.css"; +import "./style.css"; + +type Theme = "auto" | "light" | "dark"; +type Viewport = "wide" | "tablet" | "mobile"; +type MobilePanel = "editor" | "preview"; +type IconName = "arrow" | "book" | "check" | "chevron" | "code" | "copy" | + "download" | "error" | "expand" | "file" | "plus" | "refresh" | "warning"; + +const REFERENCES = EXAMPLES.map(example => ({ + ...example, + source: JSON.stringify(example.artifact, null, 2), +})); + +function Icon({ name, size = 18 }: { name: IconName; size?: number }) { + return ( + + ); +} + +function BrandMark() { + return ( + + ); +} + +/** The highlight layer is presentation only. The textarea is the accessible editor. */ +function highlightJson(source: string): ReactNode { + if (source.length > 24_000) return source; + const tokens: ReactNode[] = []; + const pattern = /"(?:\\.|[^"\\])*"(?=\s*:)|"(?:\\.|[^"\\])*"|\b(?:true|false|null)\b|-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?|[{}\[\]:,]/g; + let previous = 0; + let match: RegExpExecArray | null; + let count = 0; + while ((match = pattern.exec(source)) !== null) { + if (match.index > previous) tokens.push(source.slice(previous, match.index)); + const value = match[0]; + let role = "punctuation"; + if (value.startsWith('"')) { + role = /^\s*:/.test(source.slice(pattern.lastIndex, pattern.lastIndex + 64)) ? "key" : "string"; + } else if (/^(true|false|null)$/.test(value)) role = "boolean"; + else if (/^-?\d/.test(value)) role = "number"; + tokens.push({value}); + previous = pattern.lastIndex; + } + if (previous < source.length) tokens.push(source.slice(previous)); + return tokens; +} + +function cursorLabel(value: string, index: number): string { + const before = value.slice(0, index); + const line = before.split("\n").length; + return "Ln " + line + ", Col " + (before.length - before.lastIndexOf("\n")); +} + +function downloadArtifact(id: string, json: string) { + const blob = new Blob([json + "\n"], { type: "application/json;charset=utf-8" }); + const url = URL.createObjectURL(blob); + const link = document.createElement("a"); + link.href = url; + link.download = id + ".json"; + document.body.append(link); + link.click(); + link.remove(); + window.setTimeout(() => URL.revokeObjectURL(url), 0); +} + +function App() { + const [source, setSource] = useState(REFERENCES[0].source); + const [compiledSource, setCompiledSource] = useState(REFERENCES[0].source); + const [referenceChoice, setReferenceChoice] = useState(REFERENCES[0].id); + const [loadedReferenceId, setLoadedReferenceId] = useState(REFERENCES[0].id); + const [loadedSource, setLoadedSource] = useState(REFERENCES[0].source); + const [theme, setTheme] = useState("auto"); + const [viewport, setViewport] = useState("wide"); + const [mobilePanel, setMobilePanel] = useState("editor"); + const [cursor, setCursor] = useState("Ln 1, Col 1"); + const [notice, setNotice] = useState(""); + const highlightRef = useRef(null); + const editorRef = useRef(null); + + // Compile only the settled edit, and never execute or fetch its contents. + useEffect(() => { + const timeout = window.setTimeout(() => setCompiledSource(source), 260); + return () => window.clearTimeout(timeout); + }, [source]); + const result = useMemo(() => compileWorkbenchSource(compiledSource), [compiledSource]); + const syntax = useMemo(() => highlightJson(source), [source]); + const checking = source !== compiledSource; + const ready = !checking && result.kind === "ready"; + const loadedReference = loadedReferenceId && source === loadedSource + ? REFERENCES.find(item => item.id === loadedReferenceId) + : undefined; + const modified = source !== loadedSource; + const lineCount = source.split("\n").length; + + function edit(next: string) { + setSource(next); + setNotice(""); + } + + function replaceWith(next: string, referenceId: string | null) { + if (modified && !window.confirm("Replace your current edits? Unsaved changes will be lost.")) return; + setSource(next); + setCompiledSource(next); + setLoadedSource(next); + setLoadedReferenceId(referenceId); + setNotice(""); + setCursor("Ln 1, Col 1"); + if (editorRef.current) { + editorRef.current.scrollTop = 0; + editorRef.current.scrollLeft = 0; + } + if (highlightRef.current) { + highlightRef.current.scrollTop = 0; + highlightRef.current.scrollLeft = 0; + } + } + + function format() { + const current = compileWorkbenchSource(source); + const formatted = formatWorkbenchSource(current); + if (formatted === null) { + setNotice("Fix validation errors before formatting."); + setCompiledSource(source); + return; + } + edit(formatted); + setCompiledSource(formatted); + setNotice("Formatted schema-2 JSON."); + } + + async function copySnippet() { + const current = compileWorkbenchSource(source); + if (current.kind !== "ready") { + setNotice("Only validated artifacts can be copied as thl snippets."); + setCompiledSource(source); + return; + } + try { + await navigator.clipboard.writeText(markdownForSource(formatWorkbenchSource(current)!)); + setNotice("Validated thl snippet copied."); + } catch { + setNotice("Clipboard access was denied. Select the editor text to copy it manually."); + } + } + + function download() { + const current = compileWorkbenchSource(source); + const json = formatWorkbenchSource(current); + if (!json || current.kind !== "ready") { + setNotice("Fix validation errors before exporting."); + setCompiledSource(source); + return; + } + downloadArtifact(current.trace.artifact.id, json); + setNotice("Validated JSON exported."); + } + + return ( +
+ Skip to editor +
+ +
+ +
+
+
+
Interactive visualization studio
+

Make state visible.

+

Author a trace, validate its semantics, and explore each change as a graph, sequence, or state table. Start with a reference or build your own.

+
+
+
+
Built for claritySchema 2 · Native player · Runs locally
+
+
+ +
+
+
+ +
+
+ + +
+ + +
+
+
+ +
+ + +
+
+
+ +
+ + +
+ +
+
+
+
+

Source editor

Schema-2 artifact JSON

+
+ artifact.json +
+
+ JSON / thl +
+ + + +
+
+
+ +