GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - stokaro/unswell-sandbox: Unswell in a browser tab: the real engine compiled to WebAssembly, linting prose on the page. Source of play.unswell.dev.

BranchesTags
Open more actions menu

Latest commit

 

History

43 Commits
43 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
runtime/unswell
runtime/unswell
 
 
scripts
scripts
 
 
test
test
 
 
third_party
third_party
 
 
upstream-patch
upstream-patch
 
 
web
web
 
 
.gitignore
.gitignore
 
 
.go-version
.go-version
 
 
LICENSE
LICENSE
 
 
Makefile
Makefile
 
 
README.md
README.md
 
 

Repository files navigation

unswell-sandbox

The source of play.unswell.dev — the Unswell engine running in a browser tab. Real Unswell, compiled to WebAssembly. No server, no account, nothing installed, and the text never leaves the page.

Paste English prose, a Markdown or MDX document, or a Python file. The engine marks what it found inline and lists each finding as a note in the margin. A Markdown or MDX page of 150 prose words or more also gets its AI-sounding index, with every mark the index counts shown in the text, and one button makes the replacements of unswell fix. Choose MDX for a document with imports, JavaScript expressions or JSX components. The native extractor excludes that syntax and keeps the original prose locations; it does not evaluate the document's JavaScript or components.

Why it is built this way

A linter playground that fakes its output teaches people something false about the linter. So this one does not fake anything:

  • The rules are Unswell's own catalog, from a pinned upstream commit. The extraction, segmentation, rules, scoring, and gate run directly from that source in WebAssembly.
  • The gate decision on screen is the gate decision the CLI would return, and the exit 0 / exit 1 beside it is the status your CI would see.
  • The version in the footer is the version of the WebAssembly that is actually running, read out of the binary's build stamp — never the latest release number stamped on top of an older build.
  • The score beside each paragraph is the engine's index for that paragraph, and the +N pts on a note is that finding's contribution to it after the rule and group caps, not its raw weight.
  • The AI-sounding index, its level and its marks are the engine's, and the words beside them are lines of the CLI's own text report for the same result. The fixed text is what unswell fix writes for the same page.

There is no JavaScript fallback and there will not be one. A second implementation of the rules would drift from the engine, and the whole point of the page is that it is the same code as the CLI. If WebAssembly is unavailable or the module fails to compile, the engine strip says what failed and the page stays readable.

Layout

third_party/unswell.pin  the upstream commit every build is made from
upstream-patch/        empty, and meant to stay that way -- see below
runtime/unswell/       new Go files copied into Unswell's module at build time
scripts/               the wasm build, and the catalog helper it runs
web/                   the playground itself, and its vendored runtime
web/samples/           the three sample documents the toolbar loads
test/                  the runtime driven outside a browser, under node

There is no go.mod here. The build materializes a copy of pinned Unswell and builds inside Unswell's own module, so the browser entry point is an ordinary command in that module and Unswell grows no public API for the sake of a website.

Build

make wasm        # materialize, build unswell.wasm, write the manifest
make build-web   # npm ci and bundle web/src into web/dist
make test        # drive the whole runtime under node, no browser needed
make serve       # serve web/ on http://127.0.0.1:8790/
make ui-probe    # drive the real page in headless Chrome (needs `make serve`)
make check-site  # the gate CI runs before publishing

make wasm needs the Go toolchain the pinned Unswell declares; wasm_exec.js is copied from that same toolchain, because the pair has to match.

make test proves the engine and the contract; it never opens a browser. Its Ptah casebook also replays 21 source-bound originals and nine proposed revisions through both profiles, using the same expectations as the native CLI. The notes display the engine's editing guidance when a finding includes it. make ui-probe is the one that proves the page is wired to them. It loads index.html and drives it through the controls a visitor uses — the toolbar, the samples, the marks, the keyboard — then asserts by reading the DOM. Add SHOTS=.refs to write the 1560px and 390px renders as well.

Measured

From a clean build on darwin/arm64 with go1.27.1, at the pin v0.1.0-alpha.3:

unswell.wasm 47,786,668 bytes raw (45.57 MiB, 47.79 MB)
unswell.wasm, gzip -9 21,793,562 bytes (20.78 MiB, 21.79 MB)
wasm_exec.js 16,992 bytes
rules in the catalog 40
boot to ready(), node ~490 ms
boot to ready(), headless Chrome, localhost ~560 ms
one analysis of the AI-flavored sample 150–190 ms

The current build is v0.1.0-alpha.25 with 62 rules. Its WASM is 59,438,597 bytes raw and 24,221,238 bytes with gzip -9, built with go1.27.3 on darwin/arm64. About 7 MB of the raw size, 1.4 MB compressed, is the CLI's report package, which the page links to print the CLI's own words at each mark of the AI-sounding index. The timing figures above describe the earlier alpha.3 build.

The pin

third_party/unswell.pin is the pin: three lines naming the upstream commit, the version git describe gives it, and its commit date. It is the only place that records which engine the site is built from.

Move it with make pin, which takes the tip of main, or make pin REF=v0.1.0-alpha.4 for a tag or a commit. Then make wasm and commit both the pin and web/vendor/unswell/manifest.json.

There is no submodule. scripts/build-wasm.sh fetches the pinned commit into build/unswell-git, a blobless bare mirror that holds the commit graph and the tags and pulls file contents only when asked. It is under a megabyte until the first build and about 40 MB after it, against 169 MB for a full clone.

The build checks the pin against git rather than trusting it: the commit must exist, git describe must give the recorded version, and the commit date must match. A hand-edited line fails the build instead of mislabeling a binary, and make check-site makes the same comparison against the committed manifest.

The build then assembles a disposable tree from three tracked inputs:

  1. git archive of the pinned commit into build/unswell-src, which gives a tree with no .git and with mtimes taken from the commit;
  2. any patch in upstream-patch/, applied with --directory so a hunk that tried to escape the overlay would land outside it and fail;
  3. runtime/unswell/, copied in at its target paths inside the module.

build/unswell-src is gitignored and rebuilt from scratch on every run, and so is the mirror it is archived from.

upstream-patch/ is empty on purpose. Unswell builds for GOOS=js GOARCH=wasm unmodified — the engine never touches the network, discovers files, reads the environment or exits, so a browser is just another caller. An empty directory there is the goal state, not an oversight.

What is committed and what is not

unswell.wasm is not in git. It is 46 MB, it is a build product, and it is rebuilt in CI. manifest.json and wasm_exec.js are in git, because the page reads its version stamp out of the manifest and because wasm_exec.js has to byte-match the toolchain that linked the binary. So when the pin moves, run make wasm and commit the manifest and the shim the build rewrote. CI fails the deploy if you forget: it compares the manifest's unswellCommit and unswellVersion against third_party/unswell.pin, and compares what it built against what you committed.

web/dist is not in git either. CI bundles it. Locally, make build-web.

The manifest's rule list is walked from the rule registry by scripts/catalog/main.go, which is copied into the materialized tree, run once natively, and removed again. It is not part of what ships. The browser gets the authoritative catalog from Engine.Catalog() at ready(); this copy exists so the page can state what it is about to load before it has loaded it, and so CI can compare a fresh build against the committed manifest. test/contract.mjs asserts the two lists are the same list.

(web/.nojekyll is not needed by the Actions deploy path, which uploads the directory as-is. It is there so that pointing Pages at a branch instead would still publish every file rather than quietly dropping the ones Jekyll ignores.)

The Go/JS boundary

JavaScript installs globalThis.__unswellHost before the Go program starts. Go resolves it once at startup and holds it, so it cannot be installed afterwards and cannot be swapped later.

__unswellHost.ready(info)              once, before any analysis is accepted
__unswellHost.result(runId, json)      one finished answer, as a JSON string
__unswellHost.failed(runId, message)   one analysis that produced no report
__unswellHost.panic(message)           a fault that belongs to no single run

Go installs globalThis.__unswell once it is running:

__unswell.analyze(runId, text, profile, format)
__unswell.fix(runId, text, profile, format, includeLow)
__unswell.cancel(runId)

Both calls answer through result(). The payload's kind says which answer it is: report for an analysis, fix for the text after the replacements of unswell fix. A fix is a run like an analysis: one at a time, refused through failed() while another is in flight, and cancelable.

ready(info) carries the build stamp — version, commit, goVersion — and the rule catalog from Engine.Catalog(), plus the profiles and formats this build offers. The page's footer and engine strip are written from it, so they describe the binary that is running rather than the site that was deployed.

Four properties of the Go half are load-bearing, and each one is asserted in test/contract.mjs:

  • main() parks on select {}. A js/wasm instance whose main returns is torn down, taking the engine with it.
  • Work is dispatched through setTimeout(0) plus a goroutine. A bare goroutine is not enough: Go's js/wasm scheduler runs every runnable goroutine before handing control back to JavaScript, so an analysis started with go run() inside analyze() would finish, and call result(), before analyze() returned to its caller — and the page would paint its "analyzing" state after the answer had already arrived. setTimeout is what actually yields. The goroutine inside it is still required, because the analysis blocks and a js.FuncOf callback that blocks blocks the event loop.
  • Every js.FuncOf callback recovers. A panic on a goroutine nobody is recovering takes the whole WebAssembly instance with it. One case is not hypothetical: syscall/js cannot represent a BigInt, and js.Value.Type() panics outright when handed one.
  • One analysis at a time. A second analyze() while one is in flight is refused through that run's own failed(), so the host learns about it on the channel it is already listening to.

The report crosses as a JSON string, not a js.Value tree: syscall/js builds a JavaScript object one property at a time across the boundary, and a report with a few hundred findings costs far more that way than one Marshal and one JSON.parse.

What is in the payload, and what is derived

runtime/unswell/cmd/unswell-wasm/payload.go projects unswell.Result into what the page renders. Two parts are derived rather than forwarded:

  • Units are the paragraph-scope assessments only. They are the ranges the page segments the document by, the scores it prints in the gutter, and — in a source file, where most of the text is code — the only ranges the engine looked at, so everything between them is dimmed.
  • Context (in Installation, in retry_with_backoff) is the grammar-derived block context. It is not on a Finding, so it is recovered by extracting the same source a second time under the same resolved policy with IncludeStructure, and matching blocks to findings by span rather than by block id: nothing in the API promises that requesting structure leaves block numbering untouched, and byte ranges are what both extractions agree on by construction. A failure there costs context lines and nothing else, so it is swallowed rather than failing an analysis that succeeded.

The AI-sounding index and the fix

Since v0.1.0-alpha.10 the engine gives a Markdown page of 150 prose words or more, and since v0.1.0-alpha.22 an MDX page too, an index from 0 to 100 with the levels low, elevated and high, and each counted mark carries the replacement that removes it. The page shows the index in a card of the rail, draws every located mark in the document in a color of its own, and lists the marks under the findings.

Three parts of this are the CLI's, by construction rather than by copy:

  • The numbers and the marks come from Result.Documents[0].AISounding. Since v0.1.0-alpha.13 the index is the higher of two readings, the marks and the rhythm of the sentences, and the card shows both. The engine lists the marks of a reading only when that reading is above the level low; AISounding.Listed is that rule, and the page draws and lists what it returns.
  • The words come from the CLI's text report. index.go renders the completed result with report.Write and cuts the index block out of it: the counts, one line for each mark (em dash; write a comma), the lines about what a command can replace and what it cannot, the line that says not to add an em dash, and the sentence about what the index is. The report lists 60 marks in one run and says how many it left out; the rail lists the same 60 and repeats that sentence. All located marks, up to the engine's 200 on one page, are still drawn in the document.
  • The replacements are applied by unswell.RemoveAIMarks.

One part is mirrored. The loop around RemoveAIMarks (analyze, replace, analyze again, at most eight passes, and leave a page as it is when its marks are at the level low) lives in the CLI's command package, which is not public API. fix.go follows it step by step, together with the line unswell fix prints for a page.

test/ai-sounding.mjs holds both to the published binary. The files in test/fixtures/cli-v0.1.0-alpha.25 are what that binary printed and wrote for the Markdown sample, and the test requires the same index, the same line at every mark, the same fixed text byte for byte, and the same summary line. A pin that changes any of them fails the build until the fixtures are made again with the new release; the fixture directory says how.

A page whose two readings are low shows its number and no marks, because the CLI lists none there. The fix leaves a page as it is when the marks with a replacement are at the level low, also when the page is high by its rhythm. When such a page has marks with a replacement, the card offers them by the name of the CLI's flag, --include-low.

A run of sentences is one mark over a paragraph or more. It is underlined, as any other stretch is, and it has no replacement: the rail gives the remedy the CLI names, and the card offers no fix for it. MDX and Python have no index: the engine measures it on Markdown pages only, and the card says so.

After a fix the box holds the fixed text and the page analyzes it at once, so the report on screen always describes the text in the box. The rail keeps the line of the fix and an undo for as long as that text stays unchanged.

The page

Vanilla TypeScript bundled by esbuild. No framework, no virtual DOM, two entry points: dist/main.js and dist/worker.js.

The engine runs in a module Worker, because an analysis is a few hundred milliseconds of straight-line Go with no yield in it, and on the main thread that is a few hundred milliseconds in which the page cannot repaint — the sweep animation the visitor is watching would freeze exactly while the work it represents is happening.

Boot order in the Worker is not negotiable:

  1. install globalThis.__unswellHost;
  2. load wasm_exec.js, which installs globalThis.Go;
  3. instantiate unswell.wasm and go.run(), never awaited.

wasm_exec.js is loaded rather than bundled, because it must byte-match the toolchain that linked the binary; the manifest records its hash for exactly that reason. Both vendored files are requested at a URL carrying the first 16 hex of their own sha256. GitHub Pages serves everything with a fixed max-age and cannot be told otherwise, so a plain path would let a browser pair a freshly revalidated manifest with the previous binary still in its cache — the tab would then report one version before boot and another after.

Download progress is real bytes. A counting TransformStream sits between fetch and WebAssembly.compileStreaming, so the module still compiles as it downloads instead of being buffered first, and the denominator comes from the manifest rather than Content-Length: on a gzipped response Content-Length is the encoded length while response.body yields decoded bytes, and dividing one by the other would show 220%.

Three things the renderer has to get right

web/src/render.ts turns one string plus one report into the marked-up document. Each of these is a correctness problem, not a styling one:

  1. The engine speaks in UTF-8 byte offsets; JavaScript strings are UTF-16. An em dash, a curly quote or an accented name shifts every offset after it. The document is converted once into a byte-offset-to-code-unit table, and every slice goes through it. Slicing by raw offset is correct for pure ASCII and silently wrong for exactly the prose this tool is for.
  2. Findings overlap. A long-sentence finding contains a phrase finding, and a paragraph-scope gate finding contains both. The ranges are flattened into non-overlapping slices first, and each slice is wrapped outermost-first so the DOM nests the way the spans nest.
  3. A finding's span is not all source text. A phrase match in Markdown steps over the inline markup between its words, and the engine says so in segments. Segments separated by whitespace alone are merged, so "As an AI language model" is one fill rather than five; segments separated by anything else are left apart, because that gap is markup the rule never saw.

The marks of the AI-sounding index go through the same three steps as the findings. A mark of the index is one more range over the same text, so it is flattened and nested with them. It differs in two ways: it carries no number, and it is also drawn in the text between two paragraphs, because the opening asterisks of a bold label stand before the paragraph the engine reports.

Everything is built with createElement and textContent. No string of HTML is assembled from the visitor's text anywhere.

A finding whose scope is paragraph or document — or whose span is wider than a phrase — is drawn as a dotted underline rather than a fill. Filling a whole sentence would claim the rule objected to every word in it; an underline says "this stretch", which is what the rule said.

What is deliberately not there

  • No dark mode. The mock is one light palette and the page implements that palette. color-scheme: light is declared so form controls match rather than inverting.
  • Source view. The document pane shows the source as typed, with hard line breaks preserved. It is what the engine read.

The origin channel

The page shows an experimental origin estimate beside a paragraph: how much the paragraph resembles a training class of generated documentation. It is not a quality judgment, it names nobody as an author, and it decides no gate. The estimate comes from unswell-origin-lexical-v1, the pack this build embeds.

Model preparation and editorial rules

A probability pack records how its text was prepared. Core prepares each channel with the switches its own pack declares, independently of the editorial rules. The shipped lexical pack can therefore use unstructured features while structural repetition rules remain enabled in the same analysis.

This follows the core fix in stokaro/unswell#335. The playground now reads findings, scores, gate decisions, and origin estimates from one completed result. It no longer disables rules in a second engine or analyzes the page twice. The model's recorded contract is unchanged; compatibility checks still apply.

When it cannot estimate

The pack abstains outside the 25 to 89 word band it was fitted on, which is most paragraphs, so a missing badge is the ordinary case and means nothing. A channel that could not run at all is a different fact, and a blank strip states neither. The payload therefore carries the channel's own state, and the rail says in words when there is nothing to show: the status the engine reported and a sentence explaining it.

test/origin.mjs pins both halves at the host boundary, and it runs in make test, which the deploy workflow runs before publishing. It asserts an estimate where the pack accepts a paragraph, a stated reason everywhere else, and incompatible_model nowhere. The browser probe checks the same thing through the page: badges on the AI-flavored sample, and a stated reason on a document too short to estimate.

The samples

Four files in web/samples/. test/samples.mjs runs the two Markdown files and the Python file through the real engine on every make test, and test/mdx-source.mjs runs the MDX file:

File technical strict
ai-flavored.md 12 findings, max index 56.0, gate fails 23 findings, gate fails
revised.md 0 findings, gate passes 0 findings, gate passes
retry_client.py 8 findings, max index 56.0, gate fails 16 findings, gate fails

ai-flavored.md has an AI-sounding index of 100, high, with 21 listed marks: every kind the first reading counts, each replacement the fix makes for an em dash (a comma, a colon after a short list label, a period between two full clauses), and three runs of sentences. After the fix the index is 69: seven stock words and the runs remain, which only a person can rewrite. revised.md has an index of 23, low, and none of the marks. It was elevated by its rhythm until two of its sentences were joined, which is the remedy the report names.

The two profiles are the CLI's. technical is what unswell check runs with no configuration. strict is builtin:strict-v1, which keeps the six rules that ship off since v0.1.0-alpha.10. A rule that is enabled only by name reports under neither, here as in the CLI.

The phrasings are derived from the executable examples in the rule catalog's own descriptors, so every finding they trigger is a genuine activation of a real rule rather than a guess at what the linter dislikes.

The revision's zero is asserted exactly, not as a floor. The page describes it as clean, and a rule change upstream that turns it dirty has to fail the build rather than make the page a liar. The other two are asserted as floors, because a new rule catching more of a deliberately bad document is not a regression.

Deploy

The site is play.unswell.dev: GitHub Pages, with the source set to GitHub Actions and the domain in web/CNAME. Every push to main runs .github/workflows/deploy.yml; a pull request runs the checks and stops. workflow_dispatch re-runs a deploy by hand.

check — typecheck, the unit suite, bundle, then web/scripts/check-site.mjs: the CNAME says exactly play.unswell.dev; index.html and 404.html exist; every href, src and CSS url() on every page resolves to a real file; the files JavaScript reaches by path (dist/worker.js, the three samples) exist; the OFL texts sit beside the woff2 files; no github.io address appears anywhere; the committed manifest names the commit the pin records. No Go and no 46 MB link, so it fails fast.

deploy — reads the pin, restores or builds the wasm, verifies it against what is committed, runs make test against the linked binary, bundles, stages _site, runs the same site check with nothing exempt — the binary's sha256 and byte count against the manifest this time — asserts the artifact is under the Pages ceiling, and uploads.

The wasm cache is keyed on the pin plus a hash of runtime/, upstream-patch/, the build script and the catalog helper, with no restore-keys: a near miss would hand the deploy a binary built from different sources, which is worse than a slow build. When the key hits, the Go toolchain is not even installed.

smoke — fetches the deployed site: 200 on the root, the site's own 404 page on an unknown address, the bundle and the samples present, application/wasm on the binary, and the sha256 of the bytes the CDN actually returned against the manifest that same origin serves.

The manifest comparison in the deploy job is an identity check (unswellVersion, unswellCommit, unswellCommitDate, goVersion, wasmExec, rules), and the wasm's own sha256 is compared as a warning rather than a gate. A Go js/wasm link is not byte-reproducible: the linker embeds a build id derived from paths and build metadata, so two builds of identical source differ even on the same host.

The open question: compression

A cold visit downloads a 45.6 MiB WebAssembly binary. It compresses to 20.8 MiB, and the loading experience assumes that is what crosses the wire. Whether the CDN in front of GitHub Pages compresses an asset that large has not been measured here, so the smoke test measures it rather than assuming it, sending Accept-Encoding: gzip by hand and reporting the wire bytes.

If it is compressed, the run says so. If it is not, it raises a warning with the measured numbers: 45.6 MiB per cold visit instead of 20.8 MiB, and the 100 GB/month Pages bandwidth allowance covering roughly 2,200 visits instead of 4,900. That would need a real fix — a CDN in front that does compress, or a pre-compressed copy served deliberately — not a smaller loader animation.

To measure it against anything, including make serve:

make smoke BASE=http://127.0.0.1:8790/

Security

The page sets its Content-Security-Policy in a meta tag:

default-src 'self'; script-src 'self' 'wasm-unsafe-eval'; style-src 'self';
img-src 'self' data:; font-src 'self'; connect-src 'self'; worker-src 'self';
object-src 'none'; base-uri 'none'; form-action 'none'

'wasm-unsafe-eval' is what compiling the module needs. A dedicated Worker started from a same-origin script with no CSP headers of its own inherits this policy, which is why the directive has to be on the page rather than on the Worker — and why the Worker is a real file rather than a blob: URL. The page ships no inline script, so script-src carries no hash; npm run build fails if an inline script appears without a matching one.

License

MIT. The vendored web fonts carry their own terms; see web/assets/fonts/LICENSES.md. Unswell itself is a separate repository with its own license.

Construction regressions

make test-frames runs the built WASM through the same host API as the page. It checks three denial/redefinition pairs with all six clause locations, a pinned Ptah page, and technical controls under both profiles. The fixtures record their source revision and distinguish constructed probes from real documentation. These checks measure recognition, not authorship or editorial precision.

The runtime preserves mapped segments for related evidence. The renderer marks all occurrences, including those in later paragraphs, and the rail reports the number of text locations. web/src/related.test.mjs checks this behavior with a small DOM fixture; it does not assert browser layout.

About

Unswell in a browser tab: the real engine compiled to WebAssembly, linting prose on the page. Source of play.unswell.dev.

play.unswell.dev

Topics

ai-stylebrowserbrowser-playgroundclient-sidecode-qualitygolanginteractive-demojavascriptmarkdownmdxoffline-toolprivacyprose-linterpythontechnical-writingtext-analysisunswellwasmwebassemblywriting-linter

Resources

Readme
MIT license
Activity
Custom properties

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.