diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 914ad2f4..4fe2aecf 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -71,6 +71,8 @@ jobs:
retention-days: 30
- name: Install browser
run: pnpm exec playwright install --with-deps chromium
+ - name: Audit built public authoring playground
+ run: pnpm audit:playground
- name: Browser tests
run: pnpm test:browser:run
- name: Record verified Chromium browser evidence
@@ -135,6 +137,7 @@ jobs:
pnpm preview:build
pnpm test:run
node scripts/verify-release-evidence.mjs
+ pnpm audit:playground
pnpm test:browser:run
pnpm build
pnpm audit:licenses
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d5ead3ae..59299f0d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,14 @@ All notable changes to Throughline are recorded here. Package versions follow
### Added
+- Replaced the fixed-reference Vite development preview with a public-facing,
+ static schema-2 authoring playground. It now supports editable JSON with
+ syntax highlighting, exact semantic/compiler diagnostics, debounced native
+ Graph/Sequence/State-table and Explain/Inspect preview, safe reference
+ loading, format/copy/export actions, responsive editor/preview tabs,
+ appearance and width controls, and Cloudflare Pages deployment guidance.
+ Prose remains inert until independently reviewed; the playground does not
+ publish the npm package or perform AI materialization.
- TL-U18 establishes an exact-head, machine-readable schema-2 release-quality gate: deterministic small/moderate/near-limit fixture hashes and compile/index/query/projection/geometry timings with runner metadata; a seeded negative-input sweep; 260px keyboard/semantic-accessibility browser regressions; separately attested Chromium/Firefox/WebKit runs; a checked independent packed SSR consumer at 260/320/375 CSS px; and CI artifacts plus a read-only evidence verifier. Results use hard correctness/resource budgets, not invented CPU or learning-outcome claims. Maintainer review caught incomplete merge-result CI, 12 repeatedly sampled attack strings and vacuously passing empty-edge geometry: these are corrected with a full proposed-merge CI replay, 144 unique seeded malformed inputs (12 mandatory classes) and an all-edges-preserved bounded-geometry gate. Real screen-reader acceptance is **still pending TL-U18** and cannot be reclassified as an automatic DOM test or postponed to TL-U19 without an accepted spec amendment; a dated SHA-bound human test template is provided. Native zoom is also a manual release check. The previously stale manual publisher export map now checks the schema-2 Node entry and `thl` binary. No package was published.
- TL-U10 adds a separately packed Node 24+ `thl` CLI with strict
`validate`, `materialize` and `check` commands. Materialization computes
diff --git a/README.md b/README.md
index 461cf4bd..b1e17caf 100644
--- a/README.md
+++ b/README.md
@@ -283,20 +283,29 @@ The Graph and Sequence views only render declared facts.
A sequence request without message events falls back to a state table
instead of inventing messages.
-## Local development preview
+## Interactive authoring playground
-[The Vite playground](playground) uses the current **source** versions
-of the four schema-2 artifacts and the native player. With Node.js 24+
-and the repository's pinned pnpm version:
+[The Throughline Playground](playground) is a public-facing, static authoring
+studio built against the current **schema-2 repository source**, independently
+of the npm registry. Write or paste strict JSON into the editor, get compiler
+diagnostics, and explore the resulting Graph, Sequence, State table and
+Explain/Inspect views. Load and edit four verified reference examples; format
+valid source, copy a `thl` Markdown fence or export a validated JSON artifact.
+Unreviewed prose remains inert and cannot be previewed without its separately
+approved materialization.
+
+With Node.js 24+ and the repository's pinned pnpm version:
~~~sh
pnpm install --frozen-lockfile
+pnpm preview:typecheck
pnpm dev
~~~
-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.
+Visit http://localhost:5173. The playground is a browser-only static site with
+responsive authoring and preview layouts; it is **not** an npm package feature
+or proof of the new npm version's publication. See
+[the playground guide and Cloudflare Pages deployment handoff](playground/README.md).
## Behind the model
diff --git a/package.json b/package.json
index 36f33045..2a44b5c8 100644
--- a/package.json
+++ b/package.json
@@ -42,6 +42,7 @@
"scripts": {
"dev": "vite --config playground/vite.config.ts",
"preview:build": "vite build --config playground/vite.config.ts",
+ "audit:playground": "node scripts/audit-playground.mjs",
"preview:typecheck": "tsc -p tsconfig.preview.json",
"build": "tsdown && node scripts/verify-dist.mjs",
"typecheck": "tsc --noEmit",
diff --git a/playground/README.md b/playground/README.md
new file mode 100644
index 00000000..a87ea5e3
--- /dev/null
+++ b/playground/README.md
@@ -0,0 +1,82 @@
+# 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.
+- On a valid artifact, use Graph, Sequence, State table and Explain/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 dev
+```
+
+Visit http://localhost:5173. Before release, run:
+
+```sh
+pnpm test:run
+pnpm preview:build
+pnpm test:browser:run
+```
+
+The static output lives in **playground/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 preview:build` |
+| Output directory | `playground/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/index.html b/playground/index.html
index 3c1f24fa..4bde325a 100644
--- a/playground/index.html
+++ b/playground/index.html
@@ -3,7 +3,14 @@
- Throughline · Local React player preview
+
+
+
+
+
+
+
+ Throughline Playground — Make state visible
diff --git a/playground/main.tsx b/playground/main.tsx
index efd5fa52..fa3d6fd1 100644
--- a/playground/main.tsx
+++ b/playground/main.tsx
@@ -1,118 +1,466 @@
-import { StrictMode, useState } from "react";
+import { StrictMode, useEffect, useMemo, useRef, useState } from "react";
+import type { ReactNode } from "react";
import { createRoot } from "react-dom/client";
-import { compileArtifact, serializeArtifact } from "../src/index.js";
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 = "desktop" | "tablet" | "mobile";
+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 examples = EXAMPLES.map(example => ({
+const REFERENCES = EXAMPLES.map(example => ({
...example,
- trace: compileArtifact(example.artifact),
- source: "~~~thl\n" + serializeArtifact(example.artifact) + "\n~~~",
+ source: JSON.stringify(example.artifact, null, 2),
}));
+function Icon({ name, size = 18 }: { name: IconName; size?: number }) {
+ return (
+
+ {name === "arrow" && <> >}
+ {name === "book" && <> >}
+ {name === "check" && <> >}
+ {name === "chevron" && <> >}
+ {name === "code" && <> >}
+ {name === "copy" && <> >}
+ {name === "download" && <> >}
+ {name === "error" && <> >}
+ {name === "expand" && <> >}
+ {name === "file" && <> >}
+ {name === "plus" && <> >}
+ {name === "refresh" && <> >}
+ {name === "warning" && <> >}
+
+ );
+}
+
+function BrandMark() {
+ return (
+
+
+
+
+
+
+
+ );
+}
+
+/** The highlight layer is presentation only. The textarea is the accessible editor. */
+function highlightJson(source: string): ReactNode {
+ if (source.length > 120_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 [exampleId, setExampleId] = useState("factorial");
+ 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("desktop");
- const current = examples.find(example => example.id === exampleId);
+ 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(source));
+ 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 (
-
-
-
- Throughline / schema-2 development preview
- Reference evidence and player review
-
- Explore independently checked, authored models. Graphs and sequences
- reveal declared evidence; they do not execute source code or infer
- undocumented events.
-
-
-
-
-
- Reference model
- setExampleId(event.currentTarget.value)}
- >
- {examples.map(example =>
- {example.title} )}
-
-
-
- Theme
- setTheme(event.currentTarget.value as Theme)}>
- System
- Light
- Dark
-
-
-
- Viewport
- setViewport(event.currentTarget.value as Viewport)}>
- Responsive desktop
- 768px tablet
- 375px mobile
-
-
+
+
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 clarity Schema 2 · Runs in your browser
+
-
- {current ? (
-
- ) : null}
-
+
+
+
+
Start from a reference
+
+
+ setReferenceChoice(event.currentTarget.value)}>
+ {REFERENCES.map(item => {item.title} )}
+
+
+
+
{
+ const reference = REFERENCES.find(item => item.id === referenceChoice);
+ if (reference) replaceWith(reference.source, reference.id);
+ }}>Load example
+
replaceWith(STARTER_SOURCE, null)}>
+ New trace
+
+
+
+
+
Appearance
+
+ setTheme(event.currentTarget.value as Theme)}>
+ System
+ Light
+ Dark
+
+
+
+
+
+
+
+ setMobilePanel("editor")}> Editor
+ setMobilePanel("preview")}> Preview
+
+
+
+
+
+
+
Source editor Schema-2 artifact JSON
+
+
artifact.json
+
+
+
JSON / thl
+
+ Format
+ Copy thl
+ Export
+
+
+
+
+ Edit JSON · Ctrl/⌘ + Enter to check
+ {cursor} · {lineCount} lines
+
+
+ {checking ? (
+
Checking changes…
+ ) : result.kind === "ready" ? (
+
+ Artifact valid — semantic validation and compilation passed.
+
+ ) : (
+
+
+
{result.kind === "intent" ? "Review required for prose" : "Unable to compile"}
+ {result.kind === "invalid" && (result.path || result.code) &&
{result.path ?? result.code}}
+
{result.message}
+
+
+ )}
+
+
- {current && (
-
- Static explanation
- {current.explanation}
- Comprehension questions
-
- {current.questions.map(question => (
-
- {question.question}
- {question.expectedAnswer}
- Evidence: {question.evidenceEventIds.join(", ")}
-
- ))}
-
- Evidence limits
-
- {current.caveats.map(text => {text} )}
-
-
- )}
-
-
- View strict schema-2 thl source
- {current?.source ?? ""}
-
-
- Use Player options to inspect source events, histories and compatible views.
- The static explanation and questions are a matched baseline, not a
- claim that improved learning outcomes have been measured.
-
-
-
+
+
+
+
Live preview Explore what your artifact describes
+
+
+
+ {checking ? "Updating" : result.kind === "ready" ? "Ready" : "Needs attention"}
+
+
+
+
+ {ready && result.kind === "ready" ? (
+ <>
+ {result.trace.artifact.entities.length} entities
+ {result.trace.artifact.steps.length} steps
+ {result.trace.artifact.steps.reduce((sum, step) => sum + step.events.length, 0)} events
+ >
+ ) : Schema 2 · Strict validation }
+
+
+ Preview width
+ setViewport(event.currentTarget.value as Viewport)}>
+ Desktop
+ Tablet · 768px
+ Mobile · 375px
+
+
+
+
+
+ {result.kind === "ready" ? (
+
+
+ {checking &&
Validating latest edit…
}
+
+ ) : (
+
+
+
{result.kind === "intent" ? "Prose needs a reviewed artifact" : "Your visualization will appear here"}
+
{result.kind === "intent"
+ ? "Write schema-2 JSON for an instant preview. Prose needs an approved materialization and cannot be generated automatically."
+ : "Update the JSON in the editor to resolve its validation errors. Only compiled facts are displayed."}
+
{ setMobilePanel("editor"); editorRef.current?.focus(); }}>Back to editor
+
+ )}
+
+
+ Only authored events and state are shown. Missing evidence is not inferred.
+
+
+
+ {notice}
+
+
+
+
+
{loadedReference ? "About this reference" : "Authoring essentials"}
+ {loadedReference ? (
+ <>
+
{loadedReference.description}
+
+ Explanation, questions and evidence limits
+
+
{loadedReference.explanation}
+
{loadedReference.questions.map(question => (
+ {question.question}
+ {question.expectedAnswer}
+ Source evidence: {question.evidenceEventIds.join(", ")}
+
+ ))}
+
Evidence limits
+
{loadedReference.caveats.map(item => {item} )}
+
+
+ >
+ ) : (
+ <>
+
Declare entities and initial state, then add steps with explicit writes, messages, topology changes or observations. The compiler checks every transition.
+
Read the schema-2 authoring guide
+ >
+ )}
+
+
+
Understand the model
+
Throughline is evidence-aware, not a code runner. JSON compiles locally; descriptive prose requires separately reviewed materialization. You control what the artifact claims.
+
Explore the schema and semantics
+
+
+
+
+
);
}
const root = document.getElementById("root");
-if (!root) throw new Error("Missing preview mount point.");
+if (!root) throw new Error("Missing playground root.");
createRoot(root).render( );
diff --git a/playground/public/_headers b/playground/public/_headers
new file mode 100644
index 00000000..4a9cdca3
--- /dev/null
+++ b/playground/public/_headers
@@ -0,0 +1,4 @@
+/*
+ X-Content-Type-Options: nosniff
+ Referrer-Policy: strict-origin-when-cross-origin
+ Permissions-Policy: camera=(), microphone=(), geolocation=()
diff --git a/playground/public/favicon.svg b/playground/public/favicon.svg
new file mode 100644
index 00000000..faaeecd2
--- /dev/null
+++ b/playground/public/favicon.svg
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/playground/style.css b/playground/style.css
index 50d65edb..ff75f607 100644
--- a/playground/style.css
+++ b/playground/style.css
@@ -1,146 +1,285 @@
-* {
- box-sizing: border-box;
-}
-
-html {
- min-width: 320px;
-}
+* { box-sizing: border-box; }
+html { min-width: 320px; scroll-behavior: smooth; }
+body { margin: 0; }
+button, select, textarea { font: inherit; }
+button { cursor: pointer; }
+button:disabled { cursor: not-allowed; opacity: .55; }
+a { color: inherit; }
+.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
-body {
- margin: 0;
- font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
-}
-
-.preview-app {
- --preview-bg: #f7f7f7;
- --preview-surface: #fff;
- --preview-text: #1d1d1d;
- --preview-muted: #626262;
- --preview-border: #d8d8d8;
+.studio-app {
+ --page: #f7f8fc;
+ --surface: #fff;
+ --surface-soft: #f9faff;
+ --ink: #182335;
+ --muted: #667286;
+ --muted-strong: #4c5a70;
+ --border: #e1e6ef;
+ --accent: #315ee8;
+ --accent-hover: #234ed4;
+ --accent-ink: #254dce;
+ --accent-wash: #eef3ff;
+ --shadow: 0 8px 30px rgba(24, 44, 87, .035), 0 1px 3px rgba(24, 44, 87, .025);
+ --success: #16825b;
+ --success-wash: #e7f8ef;
+ --warning: #996013;
+ --warning-wash: #fff4e4;
+ --error: #b73d50;
+ --error-wash: #fff1f3;
+ color-scheme: light;
+ font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
+ background: var(--page);
+ color: var(--ink);
min-height: 100vh;
- background: var(--preview-bg);
- color: var(--preview-text);
+ line-height: 1.5;
+ -webkit-font-smoothing: antialiased;
}
-
-.preview-app[data-theme="dark"] {
- --preview-bg: #101010;
- --preview-surface: #1b1b1b;
- --preview-text: #f2f2f2;
- --preview-muted: #b2b2b2;
- --preview-border: #3a3a3a;
+.studio-app[data-theme="dark"] {
+ --page: #0d1421;
+ --surface: #151f30;
+ --surface-soft: #18253a;
+ --ink: #eff4fc;
+ --muted: #a3b0c7;
+ --muted-strong: #c5cfe0;
+ --border: #2b3a50;
+ --accent: #7d9cff;
+ --accent-hover: #99b1ff;
+ --accent-ink: #a7bdff;
+ --accent-wash: #1d3150;
+ --shadow: 0 10px 32px rgba(0, 0, 0, .16);
+ --success: #79dab2;
+ --success-wash: #193c34;
+ --warning: #ecc07a;
+ --warning-wash: #3b2c1b;
+ --error: #ff9ba9;
+ --error-wash: #422834;
+ color-scheme: dark;
}
-
@media (prefers-color-scheme: dark) {
- .preview-app[data-theme="auto"] {
- --preview-bg: #101010;
- --preview-surface: #1b1b1b;
- --preview-text: #f2f2f2;
- --preview-muted: #b2b2b2;
- --preview-border: #3a3a3a;
+ .studio-app[data-theme="auto"] {
+ --page: #0d1421;
+ --surface: #151f30;
+ --surface-soft: #18253a;
+ --ink: #eff4fc;
+ --muted: #a3b0c7;
+ --muted-strong: #c5cfe0;
+ --border: #2b3a50;
+ --accent: #7d9cff;
+ --accent-hover: #99b1ff;
+ --accent-ink: #a7bdff;
+ --accent-wash: #1d3150;
+ --shadow: 0 10px 32px rgba(0, 0, 0, .16);
+ --success: #79dab2;
+ --success-wash: #193c34;
+ --warning: #ecc07a;
+ --warning-wash: #3b2c1b;
+ --error: #ff9ba9;
+ --error-wash: #422834;
+ color-scheme: dark;
}
}
+.studio-app :focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
+.skip-link { position: fixed; z-index: 100; top: -100px; left: 18px; background: var(--surface); border: 1px solid var(--accent); border-radius: 8px; padding: 10px 16px; }
+.skip-link:focus { top: 12px; }
-.preview-shell {
- max-width: 1440px;
- margin: 0 auto;
- padding: clamp(1rem, 3vw, 2.5rem);
-}
+.site-header { background: var(--surface); border-bottom: 1px solid var(--border); }
+.header-inner { max-width: 1664px; margin: auto; min-height: 76px; padding: 0 clamp(18px, 3.2vw, 54px); display: flex; align-items: center; justify-content: space-between; gap: 18px; }
+.brand { display: inline-flex; align-items: center; gap: 12px; text-decoration: none; min-width: 0; }
+.brand-mark { flex: none; width: 36px; height: 36px; }
+.brand-name { color: var(--ink); font-weight: 760; letter-spacing: -.045em; font-size: 20px; }
+.brand-divider { display: inline-block; height: 19px; width: 1px; margin: 0 3px; background: var(--border); }
+.brand-section { color: var(--muted-strong); font-weight: 650; font-size: 14px; }
+.header-nav { display: flex; align-items: center; gap: clamp(12px, 2.5vw, 30px); }
+.header-nav a, .site-footer a { display: inline-flex; align-items: center; gap: 5px; text-decoration: none; color: var(--muted-strong); font-weight: 590; font-size: 13px; white-space: nowrap; }
+.header-nav a:hover, .site-footer a:hover, .support-card a:hover { color: var(--accent-ink); }
-.preview-heading {
- max-width: 54rem;
- margin-bottom: 1.5rem;
-}
+.studio-shell { max-width: 1664px; padding: 0 clamp(18px, 3.2vw, 54px) 60px; margin: auto; }
+.hero { display: flex; align-items: flex-end; justify-content: space-between; gap: 32px; padding: clamp(36px, 4.4vw, 68px) 0 34px; }
+.hero > div:first-child { max-width: 770px; }
+.eyebrow { display: flex; align-items: center; gap: 9px; font-size: 11px; font-weight: 800; line-height: 1.5; letter-spacing: .14em; text-transform: uppercase; color: var(--accent-ink); }
+.eyebrow-dot { height: 7px; width: 7px; border-radius: 99px; background: var(--accent); box-shadow: 0 0 0 4px var(--accent-wash); }
+.hero h1 { margin: 14px 0 10px; letter-spacing: -.055em; line-height: 1.08; font-weight: 780; font-size: clamp(32px, 4.5vw, 54px); }
+.hero p { margin: 0; font-size: clamp(14px, 1.32vw, 17px); line-height: 1.7; max-width: 710px; color: var(--muted-strong); }
+.hero-aside { display: flex; gap: 13px; align-items: center; flex: none; padding-bottom: 6px; }
+.aside-icon { background: var(--accent-wash); color: var(--accent-ink); width: 48px; height: 48px; border-radius: 15px; display: grid; place-items: center; }
+.hero-aside strong, .hero-aside span { display: block; }
+.hero-aside strong { font-size: 13px; font-weight: 750; }
+.hero-aside span { margin-top: 3px; color: var(--muted); font-size: 12px; }
-.preview-eyebrow {
- margin: 0 0 0.4rem;
- font-size: 0.8rem;
- font-weight: 700;
- letter-spacing: 0.075em;
- text-transform: uppercase;
- color: var(--preview-muted);
-}
+.studio-workspace { position: relative; }
+.workspace-toolbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; padding: 18px 20px; background: var(--surface); border: 1px solid var(--border); border-radius: 15px 15px 0 0; }
+.toolbar-reference { min-width: 0; flex: 1; }
+.toolbar-reference > label, .toolbar-settings > label { display: block; color: var(--muted-strong); font-size: 12px; font-weight: 750; margin-bottom: 8px; }
+.reference-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
+.select-wrap { position: relative; display: inline-flex; align-items: center; color: var(--ink); min-width: 0; }
+.select-wrap > svg { position: absolute; right: 12px; pointer-events: none; color: var(--muted); }
+.select-wrap select { appearance: none; -webkit-appearance: none; background: var(--surface); color: var(--ink); border: 1px solid var(--border); border-radius: 9px; padding: 9px 35px 9px 13px; min-height: 39px; width: 100%; font-size: 12px; font-weight: 600; box-shadow: 0 1px 1px rgba(0,0,0,.015); }
+.select-wrap select:hover { border-color: var(--muted); }
+.reference-controls > .select-wrap { width: min(285px, 100%); }
+.toolbar-settings > .select-wrap { width: 132px; }
+.button { min-height: 39px; padding: 9px 14px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; font-size: 12px; font-weight: 720; border-radius: 9px; white-space: nowrap; transition: background .15s, border-color .15s, color .15s; }
+.button-secondary { background: var(--accent); border: 1px solid var(--accent); color: #fff; }
+.button-secondary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
+.studio-app[data-theme="dark"] .button-secondary { color: #10172c; }
+@media (prefers-color-scheme: dark) { .studio-app[data-theme="auto"] .button-secondary { color: #10172c; } }
+.button-quiet { color: var(--muted-strong); background: var(--surface); border: 1px solid var(--border); }
+.button-quiet:hover { background: var(--surface-soft); color: var(--ink); }
-.preview-heading h1 {
- margin: 0 0 0.5rem;
- font-size: clamp(1.5rem, 3.5vw, 2.5rem);
- line-height: 1.2;
-}
+.workspace-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 14px; padding: 14px; background: var(--surface-soft); border: 1px solid var(--border); border-top: 0; border-radius: 0 0 15px 15px; align-items: stretch; }
+.workspace-panel { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); min-width: 0; overflow: hidden; display: flex; flex-direction: column; }
+.panel-header { padding: 18px 20px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--border); min-height: 84px; }
+.panel-heading { display: flex; align-items: center; gap: 12px; min-width: 0; }
+.panel-symbol { width: 37px; height: 37px; flex: none; background: var(--accent-wash); color: var(--accent-ink); border-radius: 10px; display: grid; place-items: center; }
+.preview-symbol { background: #e6f7ef; color: #20885f; }
+.panel-heading h2 { font-size: 14px; font-weight: 760; letter-spacing: -.015em; margin: 0; }
+.panel-heading p { font-size: 12px; margin: 3px 0 0; color: var(--muted); }
+.file-label { font-size: 11px; color: var(--muted-strong); padding: 6px 9px; border: 1px solid var(--border); background: var(--surface-soft); border-radius: 7px; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
+.file-dot { width: 6px; height: 6px; background: var(--accent); border-radius: 2px; }
+.editor-actions, .preview-toolbar { min-height: 54px; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 16px; }
+.editor-actions { background: #182338; color: #bbc9e1; border-bottom: 1px solid #2a3952; }
+.editor-language { text-transform: uppercase; letter-spacing: .09em; font-size: 10px; font-weight: 790; white-space: nowrap; }
+.language-divider { opacity: .5; margin: 0 3px; }
+.editor-action-group { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
+.action-button { display: inline-flex; align-items: center; justify-content: center; gap: 5px; border: 1px solid #394965; border-radius: 7px; color: #e5ebf8; padding: 6px 9px; background: #233149; font-weight: 680; font-size: 11px; min-height: 30px; }
+.action-button:hover { background: #31425f; }
+.action-primary { background: #345fe4; border-color: #345fe4; color: white; }
+.action-primary:hover { background: #4773ed; }
-.preview-heading p:last-child,
-.preview-footnote {
- margin: 0;
- line-height: 1.55;
- color: var(--preview-muted);
+.code-surface { height: clamp(410px, 50vw, 640px); min-height: 410px; position: relative; background: #111b2c; color: #d9e4f5; isolation: isolate; }
+.code-highlight, .code-input {
+ position: absolute; inset: 0; margin: 0; padding: 20px 23px;
+ width: 100%; height: 100%; border: 0; border-radius: 0; overflow: auto;
+ font: 12.5px/1.8 "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
+ letter-spacing: 0; tab-size: 2; white-space: pre; overflow-wrap: normal;
+ text-align: left;
}
+.code-highlight { z-index: 0; pointer-events: none; scrollbar-width: none; user-select: none; }
+.code-highlight::-webkit-scrollbar { display: none; }
+.code-highlight code { white-space: pre; font: inherit; }
+.code-input { z-index: 1; outline: none; resize: none; background: transparent; color: transparent; -webkit-text-fill-color: transparent; caret-color: #fff; }
+.code-input::selection { background: rgba(89, 140, 255, .34); }
+.code-input:focus-visible { outline: 2px solid #6f99ff; outline-offset: -2px; }
+.syntax-key { color: #9cc7ff; }
+.syntax-string { color: #b6e3b2; }
+.syntax-number { color: #ffbe87; }
+.syntax-boolean { color: #e5a6ef; }
+.syntax-punctuation { color: #a5b6d0; }
+.editor-footer { display: flex; justify-content: space-between; gap: 12px; padding: 9px 15px; font: 11px/1.5 "SFMono-Regular", Consolas, monospace; color: #aebbd1; background: #182338; border-top: 1px solid #2d3c53; }
+.footer-divider { margin: 0 3px; color: #788eaf; }
+.diagnostic-section { padding: 14px 15px; border-top: 1px solid var(--border); margin-top: auto; }
+.diagnostic { display: flex; align-items: flex-start; gap: 8px; padding: 10px 12px; border-radius: 9px; font-size: 12px; line-height: 1.55; overflow-wrap: anywhere; }
+.diagnostic strong { font-weight: 750; }
+.diagnostic p { margin: 4px 0 0; }
+.diagnostic svg { flex: none; margin-top: 1px; }
+.diagnostic-success { background: var(--success-wash); color: var(--success); }
+.diagnostic-error { background: var(--error-wash); color: var(--error); }
+.diagnostic-intent { background: var(--warning-wash); color: var(--warning); }
+.diagnostic-checking { background: var(--surface-soft); color: var(--muted-strong); align-items: center; }
+.diagnostic-path { display: inline-block; margin-left: 7px; padding: 1px 5px; border: 1px solid currentColor; border-radius: 4px; font-size: 11px; }
+.status-spinner { width: 13px; height: 13px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: studio-spin .75s linear infinite; }
+@keyframes studio-spin { to { transform: rotate(360deg); } }
-.preview-toolbar {
- display: flex;
- flex-wrap: wrap;
- gap: 0.9rem;
- padding: 1rem;
- margin-bottom: 1.25rem;
- border: 1px solid var(--preview-border);
- border-radius: 0.6rem;
- background: var(--preview-surface);
-}
+.preview-status { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; background: var(--surface-soft); color: var(--muted); border: 1px solid var(--border); border-radius: 99px; padding: 5px 9px; font-size: 11px; font-weight: 650; }
+.preview-status-dot { background: #a3aebd; width: 7px; height: 7px; border-radius: 50%; }
+.preview-status.is-ready { background: var(--success-wash); color: var(--success); border-color: transparent; }
+.preview-status.is-ready .preview-status-dot { background: var(--success); }
+.preview-toolbar { background: var(--surface); border-bottom: 1px solid var(--border); }
+.preview-metrics { display: flex; align-items: center; gap: 15px; flex-wrap: wrap; color: var(--muted); font-size: 11px; }
+.preview-metrics span { white-space: nowrap; }
+.preview-metrics strong { color: var(--ink); font-variant-numeric: tabular-nums; font-weight: 760; }
+.viewport-select { width: 152px; flex: none; }
+.viewport-select select { min-height: 32px; font-size: 11px; padding: 6px 28px 6px 11px; }
+.viewport-select > svg { right: 9px; }
+.preview-stage { flex: 1; display: flex; justify-content: center; align-items: flex-start; min-height: 510px; padding: 22px 18px; overflow: auto; background-color: var(--page); background-image: radial-gradient(var(--border) .65px, transparent .65px); background-size: 18px 18px; }
+.visualization-frame { position: relative; width: 100%; min-width: 0; margin: 0 auto; }
+.preview-stage[data-viewport="tablet"] .visualization-frame { width: min(768px, 100%); }
+.preview-stage[data-viewport="mobile"] .visualization-frame { width: min(375px, 100%); }
+.visualization-frame > *:first-child { width: 100%; min-width: 0; }
+.preview-pending { position: absolute; top: 12px; right: 12px; padding: 7px 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); font-size: 11px; font-weight: 660; color: var(--muted-strong); }
+.preview-empty { width: min(360px, 100%); min-height: 360px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 15px; }
+.empty-icon { width: 64px; height: 64px; display: grid; place-items: center; margin-bottom: 16px; color: var(--accent-ink); background: var(--accent-wash); border: 1px solid var(--border); border-radius: 20px; box-shadow: var(--shadow); }
+.preview-empty h3 { font-size: 17px; line-height: 1.35; letter-spacing: -.025em; margin: 0 0 8px; }
+.preview-empty p { margin: 0 0 22px; color: var(--muted-strong); font-size: 12px; line-height: 1.7; }
+.preview-foot { display: flex; align-items: flex-start; gap: 7px; padding: 12px 16px; border-top: 1px solid var(--border); font-size: 11px; line-height: 1.55; color: var(--muted); }
+.preview-foot svg { flex: none; margin-top: 1px; color: var(--success); }
+.workspace-message { font-size: 12px; color: var(--muted-strong); min-height: 24px; padding: 5px 3px 0; }
-.preview-toolbar label {
- display: grid;
- gap: 0.3rem;
- flex: 1 1 12rem;
- min-width: 0;
- font-size: 0.85rem;
- font-weight: 600;
-}
-
-.preview-toolbar select {
- width: 100%;
- padding: 0.5rem;
- border: 1px solid var(--preview-border);
- border-radius: 0.4rem;
- background: var(--preview-surface);
- color: var(--preview-text);
- font: inherit;
-}
+.mobile-panel-tabs { display: none; }
+.support-grid { margin-top: 22px; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
+.support-card { padding: 22px 24px; background: var(--surface); border: 1px solid var(--border); border-radius: 13px; box-shadow: var(--shadow); min-width: 0; }
+.support-card-soft { background: var(--surface-soft); }
+.support-heading { display: flex; align-items: center; gap: 10px; color: var(--accent-ink); }
+.support-heading h2 { margin: 0; color: var(--ink); font-size: 14px; font-weight: 760; }
+.support-card > p { color: var(--muted-strong); font-size: 12px; line-height: 1.7; margin: 10px 0; }
+.support-card a { display: inline-flex; align-items: center; gap: 5px; margin-top: 6px; color: var(--accent-ink); text-decoration: none; font-size: 12px; font-weight: 720; }
+.support-card details { margin-top: 12px; border-top: 1px solid var(--border); padding-top: 10px; }
+.support-card summary { display: flex; align-items: center; gap: 7px; cursor: pointer; font-size: 12px; font-weight: 690; color: var(--accent-ink); }
+.support-card details[open] summary svg { transform: rotate(180deg); }
+.support-detail { padding-top: 9px; color: var(--muted-strong); font-size: 12px; line-height: 1.6; }
+.support-detail li { margin: 11px 0; }
+.support-detail li p { margin: 2px 0; }
+.support-detail small { color: var(--muted); }
+.support-detail h3 { color: var(--ink); font-size: 13px; }
+.site-footer { max-width: 1664px; margin: 0 auto; padding: 22px clamp(18px, 3.2vw, 54px) 30px; border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
+.site-footer > div { display: flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 760; font-size: 13px; }
+.site-footer .brand-mark { width: 25px; height: 25px; }
+.footer-subtle { margin-left: 8px; font-size: 12px; font-weight: 450; color: var(--muted); }
-.preview-frame {
- width: 100%;
- margin: 0 auto;
+@media (max-width: 1250px) {
+ .hero-aside { display: none; }
+ .preview-metrics { gap: 9px; }
}
-
-.preview-frame[data-width="tablet"] {
- width: min(768px, 100%);
+@media (max-width: 960px) {
+ .hero { padding: 37px 0 26px; }
+ .workspace-grid { grid-template-columns: 1fr; }
+ .mobile-panel-tabs { display: flex; gap: 5px; padding: 10px 12px 0; border-left: 1px solid var(--border); border-right: 1px solid var(--border); background: var(--surface-soft); }
+ .mobile-panel-tabs button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; flex: 1; padding: 11px 14px; border: 1px solid var(--border); border-radius: 9px; color: var(--muted-strong); background: var(--surface); font-weight: 690; font-size: 12px; }
+ .mobile-panel-tabs button.is-active { color: #fff; background: #315ee8; border-color: #315ee8; }
+ .workspace-grid[data-mobile-panel="editor"] .preview-pane,
+ .workspace-grid[data-mobile-panel="preview"] .editor-pane { display: none; }
+ .code-surface { height: 560px; }
+ .preview-stage { min-height: 510px; }
}
-
-.preview-frame[data-width="mobile"] {
- width: min(375px, 100%);
+@media (max-width: 660px) {
+ .header-inner { min-height: 66px; }
+ .brand-mark { width: 32px; height: 32px; }
+ .brand-name { font-size: 18px; }
+ .brand-section { font-size: 12px; }
+ .brand-divider { margin: 0; }
+ .header-nav a:first-child { display: none; }
+ .header-nav a { font-size: 12px; }
+ .hero h1 { font-size: 38px; }
+ .hero p { font-size: 14px; }
+ .workspace-toolbar { flex-wrap: wrap; align-items: flex-start; padding: 14px; gap: 12px; }
+ .toolbar-settings { display: flex; align-items: center; gap: 12px; }
+ .toolbar-settings > label { margin: 0; }
+ .toolbar-settings > .select-wrap { width: 130px; }
+ .reference-controls > .select-wrap { flex: 1 1 100%; }
+ .reference-controls > .button { flex: 1; }
+ .workspace-grid { gap: 0; padding: 10px; }
+ .panel-header { padding: 14px; }
+ .file-label { display: none; }
+ .panel-heading p { font-size: 11px; }
+ .code-surface { height: 56vh; min-height: 360px; }
+ .code-highlight, .code-input { padding: 16px; font-size: 12px; }
+ .editor-actions { flex-wrap: wrap; }
+ .editor-action-group { gap: 4px; }
+ .action-button { padding: 6px 7px; }
+ .preview-toolbar { flex-wrap: wrap; }
+ .preview-stage { padding: 14px 8px; min-height: 450px; }
+ .support-grid { grid-template-columns: 1fr; }
+ .support-card { padding: 18px; }
+ .site-footer { flex-wrap: wrap; }
+ .footer-subtle { display: none; }
}
-
-.preview-source {
- margin-top: 1.4rem;
- border: 1px solid var(--preview-border);
- border-radius: 0.6rem;
- background: var(--preview-surface);
+@media (max-width: 390px) {
+ .brand-divider, .brand-section { display: none; }
+ .editor-language { display: none; }
+ .editor-action-group { width: 100%; justify-content: space-between; }
+ .editor-action-group .action-button { flex: 1; }
+ .preview-metrics { gap: 7px; }
+ .viewport-select { width: 122px; }
}
-
-.preview-source summary {
- cursor: pointer;
- padding: 0.9rem 1rem;
- font-weight: 600;
-}
-
-.preview-source pre {
- overflow: auto;
- max-height: 24rem;
- margin: 0;
- padding: 1rem;
- border-top: 1px solid var(--preview-border);
- color: var(--preview-text);
- font-size: 0.8rem;
- line-height: 1.55;
-}
-
-.preview-footnote {
- margin-top: 1.25rem;
- font-size: 0.87rem;
+@media (prefers-reduced-motion: reduce) {
+ *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
diff --git a/playground/workbench.test.ts b/playground/workbench.test.ts
new file mode 100644
index 00000000..badb3259
--- /dev/null
+++ b/playground/workbench.test.ts
@@ -0,0 +1,63 @@
+import { describe, expect, it } from "vitest";
+import {
+ STARTER_SOURCE,
+ compileWorkbenchSource,
+ formatWorkbenchSource,
+ markdownForSource,
+ unwrapThlFence,
+} from "./workbench.js";
+
+describe("public playground authoring boundary", () => {
+ it("validates and compiles an editable schema-2 artifact", () => {
+ const result = compileWorkbenchSource(STARTER_SOURCE);
+ expect(result.kind).toBe("ready");
+ if (result.kind !== "ready") return;
+ expect(result.trace.artifact.schemaVersion).toBe(2);
+ expect(result.trace.frames).toHaveLength(2);
+ expect(result.trace.artifact.steps[0].events[0].id).toBe("counterWrite");
+ });
+
+ it("rejects schema 1 rather than adapting or inferring it", () => {
+ expect(compileWorkbenchSource('{"version":1,"domain":"flow"}').kind).toBe("invalid");
+ });
+
+ it("does not compile arbitrary prose or start a resolver", () => {
+ const result = compileWorkbenchSource("Explain factorial(4) as a graph.");
+ expect(result.kind).toBe("intent");
+ expect(formatWorkbenchSource(result)).toBeNull();
+ });
+
+ it("rejects invalid JSON, duplicate keys and empty input", () => {
+ expect(compileWorkbenchSource('{"schemaVersion":2,').kind).toBe("invalid");
+ expect(compileWorkbenchSource('{"schemaVersion":2,"schemaVersion":2}').kind).toBe("invalid");
+ expect(compileWorkbenchSource(" ").kind).toBe("invalid");
+ });
+
+ it("runs compiler-level atomic-write checks, not only validation", () => {
+ const artifact = JSON.parse(STARTER_SOURCE) as {
+ steps: Array<{ events: Array<{ id: string; [key: string]: unknown }> }>;
+ };
+ artifact.steps[0].events.push({ ...artifact.steps[0].events[0], id: "conflictingWrite" });
+ const result = compileWorkbenchSource(JSON.stringify(artifact));
+ expect(result.kind).toBe("invalid");
+ if (result.kind === "invalid") expect(result.path).toContain("steps");
+ });
+
+ it("formats only compiled data and exports a single plain thl fence", () => {
+ const valid = compileWorkbenchSource(STARTER_SOURCE);
+ const formatted = formatWorkbenchSource(valid);
+ expect(formatted).not.toBeNull();
+ expect(compileWorkbenchSource(formatted ?? "").kind).toBe("ready");
+ const fence = String.fromCharCode(96).repeat(3);
+ const markdown = markdownForSource(formatted ?? "");
+ expect(markdown.startsWith(fence + "thl\n")).toBe(true);
+ expect(unwrapThlFence(markdown)).toBe(formatted);
+ expect(unwrapThlFence("~~~thl\n" + STARTER_SOURCE + "\n~~~")).toBe(STARTER_SOURCE);
+ });
+
+ it("leaves Markdown with additional content untouched", () => {
+ const fence = String.fromCharCode(96).repeat(3);
+ const multi = "Before\n\n" + fence + "thl\n" + STARTER_SOURCE + "\n" + fence + "\nAfter";
+ expect(unwrapThlFence(multi)).toBe(multi);
+ });
+});
diff --git a/playground/workbench.ts b/playground/workbench.ts
new file mode 100644
index 00000000..2665782d
--- /dev/null
+++ b/playground/workbench.ts
@@ -0,0 +1,83 @@
+import {
+ ArtifactValidationError,
+ ThroughlineAuthoringError,
+ compileArtifact,
+ parseThlBody,
+} from "../src/index.js";
+import type { CompiledTrace } from "../src/v2/model.js";
+
+/**
+ * The public playground deliberately uses the *same* strict read-side
+ * validation and compiler as a production consumer. It never executes source
+ * or converts prose into an invented artifact.
+ */
+export type WorkbenchResult =
+ | Readonly<{ kind: "ready"; trace: CompiledTrace }>
+ | Readonly<{ kind: "intent"; message: string }>
+ | Readonly<{ kind: "invalid"; message: string; path?: string; code?: string }>;
+
+export const STARTER_SOURCE = JSON.stringify({
+ schemaVersion: 2,
+ id: "my_first_trace",
+ origins: [{ id: "author", kind: "authored" }],
+ entities: [{ id: "counter", label: "Counter" }],
+ relations: [],
+ initialState: { counter: { status: "known", value: 0 } },
+ steps: [{
+ id: "increment",
+ label: "Increment counter",
+ events: [{
+ id: "counterWrite",
+ type: "write",
+ originId: "author",
+ entityId: "counter",
+ path: [],
+ value: { status: "known", value: 1 },
+ }],
+ }],
+}, null, 2);
+
+/** Accept a single pasted Markdown fence, without treating arbitrary Markdown as code. */
+export function unwrapThlFence(value: string): string {
+ const trimmed = value.trim();
+ const match = /^(~{3,}|`{3,})thl[ \t]*\r?\n([\s\S]*?)\r?\n\1[ \t]*$/.exec(trimmed);
+ return match ? match[2] : value;
+}
+
+export function compileWorkbenchSource(source: string): WorkbenchResult {
+ try {
+ const parsed = parseThlBody(source);
+ if (parsed.kind === "intent") {
+ return {
+ kind: "intent",
+ message: "This is descriptive intent, not runnable JSON. To visualize prose, materialize a schema-2 artifact with the CLI and approve its sidecar in your content repository.",
+ };
+ }
+ // Always compile, not merely parse. This catches atomic write conflicts,
+ // sent-message presence errors and expanded-work budget violations.
+ return { kind: "ready", trace: compileArtifact(parsed.value) };
+ } catch (error) {
+ if (error instanceof ArtifactValidationError) {
+ return {
+ kind: "invalid",
+ path: error.path,
+ message: error.message.startsWith(error.path + ": ")
+ ? error.message.slice(error.path.length + 2)
+ : error.message,
+ };
+ }
+ if (error instanceof ThroughlineAuthoringError) {
+ return { kind: "invalid", code: error.code, message: error.message };
+ }
+ return { kind: "invalid", message: "Unable to read this artifact. Check the JSON and try again." };
+ }
+}
+
+/** Only successful compiler output can be formatted or exported as an artifact. */
+export function formatWorkbenchSource(result: WorkbenchResult): string | null {
+ return result.kind === "ready" ? JSON.stringify(result.trace.artifact, null, 2) : null;
+}
+
+export function markdownForSource(source: string): string {
+ return "```thl\n" + source.trimEnd() + "\n```\n";
+}
diff --git a/scripts/audit-playground.mjs b/scripts/audit-playground.mjs
new file mode 100644
index 00000000..dab5b3f0
--- /dev/null
+++ b/scripts/audit-playground.mjs
@@ -0,0 +1,81 @@
+import assert from "node:assert/strict";
+import { existsSync } from "node:fs";
+import { dirname, join } from "node:path";
+import { fileURLToPath } from "node:url";
+import { chromium, expect } from "@playwright/test";
+import { preview } from "vite";
+
+const root = dirname(dirname(fileURLToPath(import.meta.url)));
+const built = join(root, "playground", "dist", "index.html");
+assert(existsSync(built), "Build the public site first: pnpm preview:build");
+
+let server;
+let browser;
+let context;
+try {
+ server = await preview({
+ configFile: join(root, "playground", "vite.config.ts"),
+ preview: { host: "127.0.0.1", port: 0, strictPort: false },
+ logLevel: "error",
+ });
+ const port = server.httpServer.address()?.port;
+ assert.equal(typeof port, "number", "Preview server must bind a local port");
+ browser = await chromium.launch();
+ context = await browser.newContext({
+ viewport: { width: 1400, height: 900 },
+ reducedMotion: "reduce",
+ acceptDownloads: true,
+ });
+ const page = await context.newPage();
+ const errors = [];
+ page.on("pageerror", error => errors.push(error.message));
+ page.on("console", message => {
+ if (message.type() === "error") errors.push(message.text());
+ });
+ await page.goto("http://127.0.0.1:" + port, { waitUntil: "networkidle" });
+ await expect(page).toHaveTitle(/Throughline Playground/);
+ await expect(page.getByRole("heading", { name: "Make state visible." })).toBeVisible();
+ const editor = page.getByRole("textbox", { name: "Throughline schema-2 JSON" });
+ await expect(editor).toBeVisible();
+ await expect(page.locator(".diagnostic-success")).toBeVisible();
+ await expect(page.getByRole("group", { name: "Visualization player" })).toBeVisible();
+
+ // Real source changes go through the strict compiler; prose is not executable.
+ await editor.fill("Explain factorial(4) in a graph.");
+ await expect(page.locator(".diagnostic-intent")).toBeVisible();
+ await expect(page.getByRole("group", { name: "Visualization player" })).toHaveCount(0);
+ await editor.fill('{"schemaVersion":2,');
+ await expect(page.locator(".diagnostic-error")).toBeVisible();
+ await expect(page.getByRole("group", { name: "Visualization player" })).toHaveCount(0);
+
+ page.once("dialog", dialog => dialog.accept());
+ await page.getByRole("button", { name: "New trace" }).click();
+ await expect(page.locator(".diagnostic-success")).toBeVisible();
+ await expect(page.getByRole("group", { name: "Visualization player" })).toBeVisible();
+ const downloaded = page.waitForEvent("download");
+ await page.getByRole("button", { name: "Export" }).click();
+ const file = await downloaded;
+ assert.equal(file.suggestedFilename(), "my_first_trace.json");
+
+ // The public site must be usable at phone width without desktop overflow.
+ await page.setViewportSize({ width: 375, height: 820 });
+ await expect(page.getByRole("button", { name: "Preview", exact: true })).toBeVisible();
+ await page.getByRole("button", { name: "Preview", exact: true }).click();
+ await expect(page.getByRole("group", { name: "Visualization player" })).toBeVisible();
+ const dimensions = await page.evaluate(() => ({
+ viewport: innerWidth, documentWidth: document.documentElement.scrollWidth,
+ }));
+ assert(dimensions.documentWidth <= dimensions.viewport + 2,
+ "Public playground overflows at mobile width: " + JSON.stringify(dimensions));
+ await page.getByRole("button", { name: "Editor", exact: true }).click();
+ await expect(editor).toBeVisible();
+ await page.getByRole("combobox", { name: "Appearance" }).selectOption("dark");
+ await expect(page.locator(".studio-app[data-theme='dark']")).toBeVisible();
+ assert.deepEqual(errors, [], "Built public playground emitted browser errors");
+ console.log("Public schema-2 playground passed built-site editor, diagnostics, preview, export, mobile and theme smoke tests.");
+} finally {
+ await context?.close();
+ await browser?.close();
+ if (server) await new Promise((resolve, reject) =>
+ server.httpServer.close(error => error ? reject(error) : resolve()));
+}
diff --git a/tsconfig.preview.json b/tsconfig.preview.json
index c182c8cc..f057a780 100644
--- a/tsconfig.preview.json
+++ b/tsconfig.preview.json
@@ -7,6 +7,8 @@
"include": [
"src",
"playground/main.tsx",
+ "playground/workbench.ts",
+ "playground/workbench.test.ts",
"playground/vite.config.ts"
]
}
diff --git a/vitest.config.ts b/vitest.config.ts
index 92fc76f7..463218cb 100644
--- a/vitest.config.ts
+++ b/vitest.config.ts
@@ -3,7 +3,7 @@ import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
environment: "node",
- include: ["src/**/__tests__/**/*.test.{ts,tsx}"],
+ include: ["src/**/__tests__/**/*.test.{ts,tsx}", "playground/**/*.test.ts"],
exclude: ["**/*.browser.test.tsx"],
},
});