qat

Developing: qatjs init, qatjs dev, env, plugins

Three commands, no config file: qatjs dev while you work, qatjs compress to ship (compress.md), qatjs check for diagnostics. The file structure and package.json are the configuration.

A new app

shell1 line
npm create qatjs my-app

npm create qatjs (or pnpm create qatjs, yarn create qatjs) needs no global install. npm fetches create-qatjs, which runs qatjs init from its own @qatjs/toolchain and prints the next steps: cd my-app, npm install, npm run dev. With npm, flags go after --: npm create qatjs my-shell -- --shell, npm create qatjs payments -- --remote payments.

Inside a project that already has @qatjs/toolchain, qatjs init does the same:

shell3 lines
qatjs init my-app
cd my-app
qatjs dev

qatjs init writes package.json, index.html, src/main.js, src/routes.js, two pages and a stylesheet — no config file — and AGENTS.md (with a CLAUDE.md that includes it). That file gives coding agents the React → Qat dictionary, the reserved names, the rules (one way per concept, the closure rule, the two surfaces) and qatjs check --json. qatjs init --agents writes both again in an existing project. (npm install first if you are outside this repository's pnpm workspace: only packages/*, examples/* and benchmarks/* resolve the workspace's packages without it.) Its package.json lists what the language compiles to: @qatjs/core, @qatjs/router, and @qatjs/load and @qatjs/form, which a load(…) and a form(…) import. qatjs dev says at start which dependencies are not installed, and qatjs check reports QX-DEP-MISSING for a package a module under src/ imports, as it compiles, that package.json does not list: qatjs compress would find it in node_modules, but dev's import map is made from package.json. qatjs init my-shell --shell and qatjs init payments --remote payments add qat.federate.js for federation.

Upgrading: qatjs upgrade

shell2 lines
qatjs upgrade --dry
qatjs upgrade

qatjs upgrade moves the project from its version to the toolchain's. It reads the project's version from package.json (the oldest of its qat packages' ranges), then runs, in order, each codemod the upgrade ledger (@qatjs/toolchain/upgrade-ledger.json) has between the two versions. Then it moves the ranges; npm install follows. A codemod edits only what it can prove:

  • qat/ui copies (src/ui/, from qatjs add): a file byte for byte one qat/ui shipped is replaced by the current one, and a file it now imports is added. A copy you changed is left as it is, for review (qatjs add <name> --update shows the difference). A copy that nothing in src/ or index.html imports is named, never deleted.
  • a name that moved (Calendar out of date, Combobox out of select): your import is pointed at the one copy that exports it now, copied in if you had none.
  • a renamed flag (qatjs check --json=0): rewritten in package.json scripts and .github/workflows, and left for review, since whatever reads the output must change too.

The report says what changed, what needs review and why, what was unchanged, and what the new version adds (nothing to adapt for those). --dry writes nothing; --json prints the report as upgrade v1 (@qatjs/schemas); --from <version> gives the version when package.json cannot.

No breaking change ships without its ledger entry and its codemod. CI holds the public surface: every name each published entry point and each qat/ui file exports (packages/toolchain/surface.json), and each name's type (surface-types.json, written by TypeScript's checker). A pull request that removes a name, or changes its signature, fails unless a ledger entry lists it. The check prints a signature change as a .d.ts diff of its entry point:

4 lines
--- @qatjs/router.d.ts
+++ @qatjs/router.d.ts
- export navigate: { (to: string) => Promise<void> }
+ export navigate: { (to: string, options?: { replace?: boolean | undefined; } | undefined) => Promise<void> }

The ledger entry's kind is addition when old code still compiles, breaking (with its codemod) when it does not.

qatjs dev

shell2 lines
qatjs dev --port 5180 --proxy /api=http://localhost:3000
qatjs dev --https
  • No bundle. Each file is transformed when the browser asks for it: .qx, .tsx and .jsx through the compiler, routes.js through the route compiler (it also writes routes.d.ts), .ts with its types stripped, CSS and assets imported from JS as small modules.
  • node_modules through an import map in index.html: ESM packages are served as they are; CommonJS ones are converted once (esbuild) and cached in node_modules/.qat/deps until the lockfile changes.
  • The first page asks for everything at once. The page gets a <link rel="modulepreload"> for each module of its route — the entry, the route table, the matched layouts and page, and what they import — so the browser does not discover the graph one level at a time; the server starts compiling all of them when the page is requested. Still no bundle: every module is its own request.
  • Compiled components are kept in node_modules/.qat/transform, so a restart of qatjs dev compiles only what changed (qatjs dev --force starts over). A large project compiles in worker threads.
  • --https serves HTTP/2 over TLS (with a certificate in node_modules/.qat/dev-cert, made with openssl on first use — or put mkcert's there): hundreds of module requests share one connection instead of six.
  • --proxy /api=http://localhost:3000 forwards a path prefix (repeatable).
  • Aliases are package.json#imports ("#src/*": "./src/*"), the one place for them: the import map carries them, Rolldown and TypeScript read them as they are.
  • import.meta.glob and workers (new Worker(new URL('./w.ts', import.meta.url), { type: 'module' })) work as in the build: see compress.md.
  • Errors show in an overlay with the .qx location; the page keeps running the last good version, and the fix applies without a reload.
  • Cold start on examples/shop: 20 ms on a laptop, the median of five new qatjs dev processes (the ms it prints when ready); the CI runners' medians are 46–61 ms on Linux and 59–116 ms on Windows (ci.budgets.json, gates.dev.cold-start.shop-ms). The target is under 100 ms; the slowest Windows median is over it.

HMR

Edits apply in place, in a few milliseconds. The server's part of a component update on examples/shop is 1.4–2.6 ms (CI medians, gates.dev.hmr-component.server-ms); no committed script measures the whole way from the file write to the DOM. What happens depends on what changed:

You changed What happens State
only the <style> of a .qx its stylesheet is replaced; nothing re-renders all kept
a component's JSX or setup each live instance is re-created in place under the same owner; its old effects, watches, loads and listeners are disposed first; mount runs again kept by name (below)
a component's props, emits or expose, or a component added or removed the nearest parent instance re-renders; a route page (no parent instance) re-renders in place at the outlet the parent's kept, the child's reset
a .js/.ts module it re-executes up the import graph to the first module that can take it (a component module, a store module, routes.js) module signals and stores kept; a store's actions and derived values are swapped; persist is not re-read
routes.js the table is swapped and the URL matched again; levels whose definition is unchanged keep their instance (keep pages too) kept where matched
a stylesheet replaced all kept
index.html, .env*, package.json, qat.federate.js a full reload; the overlay then says why reset
a syntax error the overlay; the previous version keeps running kept
an error while swapping the overlay, then a full reload when you close it reset

A keep page that is hidden when its component changes shows the new version when it is shown again, with its state.

State is kept by name and initializer kind: let n = state(0) survives an edit while it is still called n and still starts from a number. A renamed or retyped variable starts over, and a toast names it. This is best effort — never rely on it in tests.

Known limits: in federation, the shell's dev import map cannot remap a remote's newer qat minor (versions are still checked); the override token is a switch, not a secret (set it in staging builds only).

shell1 line
qatjs dev --no-hmr

reloads the page on every change instead (for debugging HMR itself). Federation remotes in dev hot-swap inside the shell too: Developing a remote.

Devtools

shell1 line
qatjs dev --devtools

opens the devtools in a drawer at the bottom of every page (Alt+Shift+D toggles it). A bug from the element to a test, with screenshots, is walked through in debug.md. The same panel is a Chrome extension (packages/devtools-panel, built to dist/extension/, loaded unpacked; it works on any qatjs dev page on localhost). It reads the program graph — loaded when the panel opens, never before — and the page's dev hooks:

Tab What it shows
Signals every named signal (component state, store fields, form fields, load entries), its value, its subscribers and what kind each is (a DOM binding, an effect, a derived value); cold (nothing reads it) and large ones marked; a live graph
Explain pick an element: the effect that wrote each of its bindings, the signals it reads, the derived chain, the last writer from the action log, the source span. A disabled button bound to a form ends at the failing field: its constraint and validationMessage
Resources per component instance, the listeners, timers, observers and sockets created in mount or an effect that are still open
Stores each store's state; the action log; time travel over it; edit a value (a snapshot patch); load a snapshot
Loads the load cache by key: age, pending, stale, subscribers
Federation the remotes, the versions they share, the import map's scopes, which shell routes import each remote (graph edges)
Routes each route's chunks and sizes (the production view in dev, graph.json and report.json after a build) and the budget table: qatjs budget's, after a qatjs compress, with the field p75s from package.json#qat.vitals (vitals.md)

When a component's unmounts leave more resources open each time — three times in a row — the console says so:

1 line
QX-RESOURCE-GROWTH /src/pages/leak.qx:3 Leak leaves 6 resources open after its last 3 unmounts (interval 1000 ms, window resize): return a cleanup from mount/effect that removes, clears, disconnects or closes each one

The fix is the cleanup mount returns:

.qx8 lines, 1 reactive nameOpen in the playground
export default function Clock() {
  let now = state(Date.now())
  mount(() => {
    const id = setInterval(() => (now = Date.now()), 1000)
    return () => clearInterval(id)
  })
  return <p>{now}</p>
}
now state

Nothing of the devtools is in a build: qatjs compress writes none of it unless --devtools is passed (then the drawer, with the build's graph and report; the app's own chunks are unchanged).

Snapshot, replay, repro

With @qatjs/devtools among the app's dependencies (a devDependency is enough for qatjs dev), the page's whole reactive state is one JSON object, every signal named by its program graph id:

JavaScript9 lines
import { lastWriter, patch, report, restore, snapshot } from '@qatjs/devtools'

const s = snapshot() // stores (global and scoped), component state, form values, loads, the router, <Head>
s.signals['src/stores/cart.js#cart.items'] // [{ id: '1', qty: 2, … }]
s.routeLoads // [{ id: 'src/routes.js#/products/:id', params: { id: '1' }, query: '', data: { product, category }, time }, …]
await restore(s) // the same state back (instances created later get theirs as they are created; loads answered from it)
await restore(patch('src/stores/cart.js#cart.coupon', 'SAVE10')) // an edit: a patch, through restore
lastWriter('src/stores/cart.js#cart.items') // { signal, handler: 'src/pages/products/detail.qx#Detail.on:click<button>', from: 'click', target: 'button.add', value, … }
const bug = report() // the snapshot + the last 50 errors + the user agent + the action log (a sequence)
  • The action log keeps the last 200 user-originated signal writes (at most 64 kB): which signal, which handler (graph id), the event and a selector of its target, the new value summarized. A write after an await in a handler (in .qx and .tsx), and what a load's response writes when an event started the load, are logged under that event (async: true): each await carries its own event, so two overlapping clicks keep theirs, for 30 s after the event (configure({ async: ms })). Writes a timer or an unrelated response makes are not the user's and are not logged.
  • Loads in the snapshot: the load cache by key (loads), each instance's keyless loads by graph id (instances[].loads), and the route loads by route id, params and query (routeLoads, the newest 20; a layout's is <routes file>#layout:<prefix>). While a restore is in progress, a load whose value the snapshot holds is answered from it, without a request: a replayed page renders as it was, with no network call. After it, loads request as usual.
  • Redaction: store({ …, redact: ['token'] }) and report({ redact: [ids] | (id) => boolean }) keep values out of the snapshot, the log and the report; their ids are listed in redacted. What is typed into a password field is never kept.
  • In production: qatjs compress --report is a recording build (the compiler names state and handlers by graph id through @qatjs/devtools/hot), so report() is the bug-report path there. Without the flag a build has nothing of it.
  • Formats: snapshot v1 and sequence v1 in @qatjs/schemas.

(These need a recorded file; packages/toolchain/test/devtools-*.test.ts run them on the shop.)

4 lines
qatjs replay snapshot.json          # qatjs dev, every page starting in that state
qatjs replay bug.json               # … and the recorded steps replayed with their timing, paused on the first onError
qatjs replay bug.json --to-test     # tests/replay/bug.spec.ts: a Playwright test of the same steps (marked for review)
qatjs repro bug.json                # tests/repro/<n>.test.ts: the replay in happy-dom (Vitest), asserting the final values

--to-test asserts the nodes the handlers' write sets reach in the program graph (the cart link after an "Add to cart"), not the whole page; run it against qatjs dev. qatjs repro needs no browser.

Env

Variables come from, highest first:

1 line
.env.<mode>.local > .env.<mode> > .env.local > .env > the process environment (QAT_PUBLIC_X)

The mode is development in qatjs dev and production in qatjs compress, or --mode:

shell2 lines
qatjs dev --mode staging
qatjs compress --mode staging
.env4 lines
# .env
PUBLIC_TITLE=Shop
PUBLIC_API_URL=runtime   # supplied at deploy time (below)
DATABASE_URL=postgres://… # not public: never reaches the browser
JavaScript1 line
const res = await fetch(`${import.meta.env.PUBLIC_API_URL}/users`)
  • The dev server never serves a dot file (.env, .git), and answers across origins only to this machine's own pages (localhost, any port: a federation remote and its shell), so no other site open in your browser reads the project through it.
  • Only PUBLIC_ variables reach the browser, as import.meta.env.NAME. Reading another one in client code is a compile error (QX-ENV-PRIVATE), and so is a name that no .env file defines (QX-ENV-UNKNOWN). env.d.ts is written from the files (by qatjs dev and qatjs check), so import.meta.env is typed.
  • Mode flags: MODE is the mode's name; DEV and PROD follow the command, not the name — qatjs compress --mode staging is MODE === 'staging', PROD === true. qatjs compress inlines build-time values and drops dead branches (if (import.meta.env.DEV)). BASE_URL is the path the app is served from: /, or qatjs compress --base (compress).
  • CI: a process variable QAT_PUBLIC_X gives PUBLIC_X when no file does (the prefix keeps the machine's own environment out of the browser). env.d.ts is written from the files alone, so it is the same on every machine: declare a name that only the process gives in .env with no value (PUBLIC_X=) — it is then typed, and the process's value is its value. .env.local and .env.*.local are for one machine; qatjs init puts them in .gitignore.

Runtime variables: one build for every deployment

PUBLIC_X=runtime marks X as supplied at deploy time. qatjs compress does not inline it: the page reads it, before any module runs, from one element of dist/index.html:

HTML1 line
<script type="application/json" id="qat-env">{}</script>

Fill it where you deploy, and the same dist/ — the one you tested and audited, with identical file hashes and SRI integrity values — is promoted from staging to production unchanged. Only index.html differs, and only inside that element (it is JSON, not script, so a CSP with script hashes is unaffected). A runtime variable that is missing or empty at boot stops the app before it starts: a QatEnvError naming it, in the console and at the top of the page. dist/env.json lists every variable the build uses — build-time ones with their value and source file, runtime ones as runtime — to check a deployment against. In qatjs dev, the element is filled from the process environment (QAT_PUBLIC_API_URL=http://localhost:3000 qatjs dev).

nginx, with sub_filter:

nginx6 lines
location = /index.html {
  sub_filter '<script type="application/json" id="qat-env">{}</script>'
             '<script type="application/json" id="qat-env">{"PUBLIC_API_URL":"https://api.example"}</script>';
  sub_filter_once on;
  gzip_static off; # sub_filter needs the uncompressed file
}

Docker, with an envsubst entrypoint (nginx:alpine has envsubst):

shell8 lines
#!/bin/sh
# docker-entrypoint.sh: fill #qat-env from the container's environment, then serve
set -eu
: "${PUBLIC_API_URL:?PUBLIC_API_URL must be set}"
html=/usr/share/nginx/html/index.html
[ -f "$html.in" ] || sed 's#id="qat-env">{}<#id="qat-env">{"PUBLIC_API_URL":"${PUBLIC_API_URL}"}<#' "$html" > "$html.in"
envsubst '$PUBLIC_API_URL' < "$html.in" > "$html"
exec nginx -g 'daemon off;'

(Values go into JSON as they are: one with ", \ or < needs escaping, which the edge worker below does for you.)

An edge worker (Cloudflare Workers, HTMLRewriter):

JavaScript8 lines
export default {
  async fetch(request, env) {
    const res = await env.ASSETS.fetch(request)
    if (!res.headers.get('content-type')?.startsWith('text/html')) return res
    const values = JSON.stringify({ PUBLIC_API_URL: env.PUBLIC_API_URL }).replace(/</g, '\\u003c')
    return new HTMLRewriter().on('script#qat-env', { element: (el) => el.setInnerContent(values) }).transform(res)
  },
}

The reader is the toolchain's inline bootstrap in index.html (a few hundred bytes, only in apps that have a runtime variable); nothing of it is in the runtime packages. A federation remote cannot have runtime variables — its shell passes values to it (federation).

qatjs env

shell2 lines
qatjs env
qatjs env --mode production --build

prints every variable of a mode, its value and where it came from; non-public values are masked unless --show, and --json prints the rows as data:

8 lines
qatjs env — mode production (qatjs compress); precedence: .env.production.local > .env.production > .env.local > .env > process env (QAT_PUBLIC_*)
MODE            production            qatjs compress --mode production
DEV             false                 qatjs compress --mode production
PROD            true                  qatjs compress --mode production
BASE_URL        /                     qatjs compress --mode production
PUBLIC_TITLE    Production title      .env.production
PUBLIC_API_URL  runtime               .env  (supplied at deploy time (#qat-env))
DATABASE_URL    ••••••                .env  (not public: never reaches the browser)

qatjs check and the editor

shell2 lines
qatjs check
qatjs check --json

qatjs check reports the compiler's diagnostics (syntax, macros, lints, styles) and TypeScript's, at .qx locations; --json prints { $schema, version, diagnostics: [{ file, line, col, code, severity, message, fix? }] } for tools and agents (every JSON file and output Qat writes carries $schema and version: see compress.md). Until 0.10.0, --json=0 still prints the bare diagnostics array of 0.9.0-rc.1 and before, with a deprecation notice on stderr; readManifest(json, 'check') from @qatjs/schemas reads either. TypeScript is whichever the project installs:

Project's TypeScript qatjs check, qatjs dts .qx in the editor .ts/.tsx importing .qx
5.x – 6.x its compiler API, in worker threads qatjs lsp @qatjs/typescript-plugin in the editor's TypeScript
7.x (native) the native compiler (its API server; tsc for declarations): about twice as fast on the scale app qatjs lsp (with the TypeScript 6 it brings for language features) qatjs dts declarations (x.qx.d.ts): TypeScript 7 has no plugin API

The diagnostics find the same problems at the same places under both (the type-check corpus reports identically under 6 and 7), but a few of TypeScript's own codes differ between the two compilers: a route link missing a param is TS2345 from TypeScript 6 and TS2741 from 7, both saying the property is missing. A tool that reads --json should match on what an error says, not on one compiler's code.

@qatjs/typescript-plugin does nothing under TypeScript 7. It is a tsserver plugin, and TypeScript 7's native server loads no plugins. With TypeScript 7, .qx support in the editor is the Qat language server (qatjs lsp, which the VS Code extension runs); .ts files importing .qx get their types from qatjs dts. qatjs check says so when a TypeScript 7 project still configures the plugin, with QX-TS7-NO-PLUGIN — an info, not a warning: nothing in the code is wrong.

shell1 line
qatjs check --unused

lists dead code across the app, and deletes nothing:

  • components no entry, route or expose reaches, or that nothing imports
  • module stores and signals nothing imports or reads
  • declared events no parent listens to
  • a remote's exposes no shell in the workspace imports
  • rules in global stylesheets no markup matches

Each entry is grouped by package and is certain (static reachability says so) or likely (a component only passed on as a value, as to <Dynamic>; class names built at runtime; no shell in the workspace). --json gives the same as data.

qatjs check also reads import.meta.env against the .env files, as qatjs dev and qatjs compress do: an unknown name is QX-ENV-UNKNOWN, and a variable without the PUBLIC_ prefix is QX-ENV-PRIVATE in every route mode, because every module a route reaches is part of the browser bundle.

Render modes: the server/client boundary

There is no "use client". A route's mode (page('./pages/home.qx', { mode: 'server' }); the default is 'client') decides, and qatjs check reports the boundary as errors. The mode is the one qatjs compress builds: the literal mode, else QAT_MODE, else 'client'. So QAT_MODE=server qatjs check checks every route without a mode as a server route. The files a route renders are the page, its layouts and catch: pages, the route table and everything they import (the reachability of --unused).

On a server, static or island route, this code runs on the server: module top-level code, component setup, the markup's expressions (text, attributes, block heads, bind: reads), load functions and keys, static(…), the route's own load and guard, and the callbacks those call on the spot (derived, untrack, batch, array callbacks, render functions). A cache: 'user' load on a static route runs in the browser. mount, unmount, idle, effect, watch callbacks, on: handlers and functions that are only defined run in the browser, and so does code under typeof window !== 'undefined'.

Code On What
QX-SERVER-DOM server, static, island window, document, localStorage, … in code that runs on the server; fix-it: move a setup statement into mount
QX-SERVER-INTERACTIVE (warning) server, static the route resumes pure components (no state, handlers, effects, loads, context or children) that 'island' would not run in the browser; names them, at the route's mode, fix-it 'island' (from QAT_MODE: at the page() call, no fix-it)
QX-SERVER-GLOBAL server, static, island a module-scope store(), signal() or state() that code the route runs on the server reads; use store.scoped(…) with provide/inject
QX-SYNC-STATIC static code the route reaches imports @qatjs/core/sync: a static page is built once, a shared document changes after it; render it 'server' (seeded from the relay) or 'client'
QX-SCENARIO-STATIC static code the route reaches imports @qatjs/core/scenario: a static page is built once, and a scenario is one person's branch of the page
QX-CACHE-LEAK server, static, island a cache: 'user' load whose data reaches a load cached for everyone ('static', '5m'), through derived values, keys and props; fix-it 'user'
QX-ROUTE-MODE — a mode that is not client, server, static or island
2 lines
src/pages/home.qx:4:3 error QX-SERVER-DOM `document` is a browser API, and the setup of <Home> runs on the server on the server route `/`: move it into mount(), effect() or an event handler
  fix: run it after mount, in the browser

Each one is suppressed like a lint: // qat-ignore QX-SERVER-DOM on the line or the line above, or "server-dom": "off" in package.json#qat.lint.

In the editor, each state, derived and load shows what updates with it, as an inlay hint (1 derived · 3 nodes · 2 components, or "nothing updates with it"). Hovering its name lists each reader and its line. The hints come from the compiler's reactive graph, as in qatjs explain. They are on in .qx; turn them on for .tsx with the setting qat.inlayHints.tsx.

In a .qx file the editor completes what is Qat's own, where it stands: the event after on: (the gestures among them), a modifier after |, a bind: target, a transition:, a block after { — a snippet that closes itself — with {else}, {case}, {catch} inside the block they belong to, the open block's closing tag after {/, and the app's routes in href="…". Everywhere else the completions are TypeScript's. A block left open is reported once, by the compiler: TypeScript's errors over the same file are held back until it closes.

compile(source, { ir: true }) (from @qatjs/compiler) also returns meta.ir: each template of the file as data — its HTML, and its operations in the order they run, each with its kind (attr, prop, event, bind, insert, spread, …), the node it works on as a path of child indexes, its name, whether it runs again (dynamic), and its line. An insert says what stands there, and under it (content): an expression (read again, or inserted once), a component — its name, each prop and how it is given (value, getter, event, bind, ref, spread), its children and slots — a block with its branches' content, an element by its template's index. It is what the compiler itself holds between reading the markup and writing code; a tool that wants to know what a template does reads it instead of the output's text:

JavaScript3 lines, 1 reactive name
import { compile } from '@qatjs/compiler'
const { meta } = compile('export default function A() { let n = state(0); return <button on:click={() => n++}>{n}</button> }', { filename: 'a.qx', ir: true })
// meta.ir[0] → { html: '<button></button>', svg: false, ops: [{ kind: 'event', name: 'click', path: [], dynamic: false, … }, { kind: 'insert', name: '', path: [], dynamic: true, … }] }
n state

QAT_OXC_RAW=0 in the environment makes the compiler read the parser's result as JSON instead of from its memory (oxc's raw transfer, which reserves a large buffer per process): the same result, about 15 % slower to parse — for a machine where that buffer is refused or slow to get.

With ir, meta.macros is each macro's site as data, in the same spirit: what was declared and the form it took (a state: signal, deep, or constant when nobody writes it; a derived: computed, inline where its one reader stands, incremental; a load: load or live), what was called (effect, watch, mount, emit, …), and each read and write of a reactive name (set, update, deep), with its line and column.

A file's diagnostics come in the order of the source — the scanner's and the parser's first (an unclosed block before what follows from it), then every other, by its place.

For agents: qatjs mcp, qatjs explain

shell1 line
qatjs explain src/pages/home.qx

qatjs explain <file> [component] prints a component's reactive graph. For each state, derived, load and prop it lists what reads it: DOM positions, other derived values, effects, and child components' props. Handlers are listed apart: they read a value when they run and do not re-run when it changes. --json gives the same data. The compiler computes it statically; nothing runs.

In the page, under qatjs dev, __qat.explain(element) answers the same question for what is on screen. It returns the component that rendered the element, its file and line, its state with the last five updates of each value, its props, and the components around it. __qat.explain() gives the route and its params, the module stores and signals, and the load cache. It is meant for agents that drive a browser (Claude in Chrome and the like) and for you at the console. Nothing of it is in a build. Each component and signal also has its id in the program graph that qatjs dev keeps in .qat/graph.json (graph.md): qatjs graph --component Cart shows the same component's readers and writers across the app.

qatjs mcp is a Model Context Protocol server on stdio, so an agent can run Qat's own commands: check (diagnostics with fix-its), compile (one file → output and source map), explain, migrate_audit and docs_search. To connect it:

  • Claude Code: claude mcp add qatjs -- npx qatjs mcp
  • Cursor: in .cursor/mcp.json, { "mcpServers": { "qat": { "command": "npx", "args": ["qatjs", "mcp"] } } }

It keeps no state, reads the files as they are, and sends nothing anywhere. A tool reads the project it was started in: a path that leaves it is refused, one that is not there is said. qatjs migrate --ai uses it to put each remaining TODO to the connected agent (migrate.md).

Plugins

Vite and Rollup plugins run unmodified in qatjs dev and in qatjs compress, listed in package.json (a convention, not a config file):

JSON5 lines
{
  "qat": {
    "plugins": ["@tailwindcss/vite", ["unplugin-icons/vite", { "compiler": "raw" }]]
  }
}

Each entry is a package (or ./path) whose default export is a plugin factory, with its options. Supported: apply, enforce, config, configResolved, configureServer, resolveId, load, transform (with hook filters), transformIndexHtml, and this.addWatchFile — a stylesheet a plugin builds from your sources (Tailwind) is rebuilt when they change. examples/plugins runs Tailwind CSS v4 and unplugin-icons.

Stylesheets

  • <style lang="scss"> (or sass) needs the optional sass-embedded; without it the error says so. <style lang="postcss"> runs the project's postcss.config.js.
  • @apply inside <style> works when Tailwind v4 is installed — no @reference needed.
  • Preprocessing runs before scoping, so nesting and mixins are scoped like plain CSS.
  • qatjs compress finishes every stylesheet with Lightning CSS: minified, prefixed for the project's browserslist.

Formatting: Prettier

@qatjs/prettier-plugin formats .qx files: the code and JSX through Prettier's own TypeScript printer (a .qx file looks like a .tsx file formatted with the same options), blocks indented like elements, on:click|prevent, bind:, class:, style:, transition: and ref kept as written, the text of a <pre> and of a <textarea> kept character for character (elsewhere a run of spaces is one, as HTML shows it), and the top-level <style> through Prettier's CSS printer (lang="scss" and lang="less" with theirs). Install it next to prettier and list it in your Prettier config (your tool's config, not Qat's):

JSON1 line
{ "plugins": ["@qatjs/prettier-plugin"] }
.qx26 lines, 1 reactive nameOpen in the playground
export default function Reviews({ reviews, onPost }) {
  let text = state("");
  const post = () => onPost(text);
  return (
    <section>
      {if (reviews.loading)}
        <p>Loading reviews…</p>
      {else}
        <ul class="reviews">
          {for (const r of reviews.data ?? [])}
            <li>{r.text}</li>
          {/for}
        </ul>
      {/if}
      <form on:submit|prevent={post}>
        <input bind:value={text} />
      </form>
    </section>
  );
}

<style>
.reviews {
  padding: 0;
}
</style>
text state

Block heads are formatted on one line; a short block around text stays inline (item{if (n !== 1)}s{/if}). Details: packages/prettier-plugin/README.md.

This repository's own components — the examples, qat/ui, the templates — are written by it: pnpm format (pnpm format:check says which are not), no semicolons, single quotes, 120 columns.

Linting: ESLint

@qatjs/eslint-plugin reports qatjs check's compiler diagnostics in ESLint: one rule, qat/check, for .qx files and for .tsx/.jsx files that import @qatjs/core. Each message has the Qat code (QX-REACT-ATTR: …) and the diagnostic's position and severity. eslint --fix applies the compiler's fix-its, and package.json#qat.lint applies as in qatjs check.

JavaScript4 lines
// eslint.config.js
import qat from '@qatjs/eslint-plugin'

export default [...qat.configs.recommended]

TypeScript errors and the project stylesheet checks (QX-CLASS-UNKNOWN, QX-TOKEN-UNKNOWN) stay in qatjs check and in the editor. The plugin's README explains why.