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 ( + + ); +} + +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. -

-
- -
- - - +
+ 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 · Runs in your browser
+
-
- {current ? ( - - ) : null} -
+
+
+
+ +
+
+ + +
+ + +
+
+
+ +
+ + +
+
+
+ +
+ + +
+ +
+
+
+
+

Source editor

Schema-2 artifact JSON

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