CLI
Every puzzle command: dev server, builds, previews, type checks, scaffolding, and diagnostics.
Installing @magic-spells/puzzle puts a puzzle binary on your PATH for npm scripts. The CLI is a prebuilt Go binary, so there's no compiler toolchain to install. Its commands are init, dev, build, preview, check, generate, add, doctor, info, and upgrade, and puzzle <command> --help documents each one.
A typical package.json wires the two you use most into scripts:
{
"scripts": {
"dev": "puzzle dev",
"build": "puzzle build"
}
}puzzle dev
Starts the development server: it builds the app in development mode, watches app/, rebuilds on every change, and reloads the browser. Reloads preserve state: the store, each view's local state, the route, and scroll survive an edit. A failed build shows its error in the browser as well as the terminal.
puzzle dev puzzle dev --port 3000 # the default port puzzle dev --strict-port # fail if the port is busy puzzle dev --fixtures # seed and mock data from app/fixtures.js
- SPA and hybrid projects are served with the
index.htmlhistory fallback, so path-mode routes work out of the box. - Static projects (
output: 'static') get the real static pipeline: every rebuild runs the prerender, and pages are served with clean URLs, full page loads, and a real 404. - A busy port isn't fatal. The server scans upward for a free port and says where it moved;
--strict-portfails instead. --fixtureswiresapp/fixtures.jsin, so the app seeds and mocks its own data (see Data & Models).--profile-buildprints per-phase timing tables to stderr.
To reach a local backend from same-origin paths, add a proxy to puzzle.config.js. Matching requests are forwarded with their path unchanged, so the app can use apiURL: '' with no CORS setup:
// puzzle.config.js
export default {
dev: {
proxy: { '/api': 'http://localhost:3091' },
},
};puzzle build
Compiles .pzl files and produces a bundle in dist/, alongside everything copied from app/public/. Three output shapes, depending on your config or flags:
puzzle build # production build (the default) puzzle build --mode development # readable, unminified puzzle build --static # true static pages puzzle build --hybrid # prerendered pages + SPA takeover
- Default (SPA). Emits the
index.htmlshell plusapp.jsandstyles.css. - Static. With
output: 'static'inpuzzle.config.js, or the--staticflag, every static route becomes its own HTML page with a small per-page module and no SPA. - Hybrid. With
output: 'hybrid'or--hybrid, every static route is prerendered and the SPA bundle takes over on load.
See Static Builds for both prerender modes. Every shape runs the declared style pipeline: with styles: { use: ['tailwindcss'] } in the config, the build runs Tailwind and folds its output into dist/styles.css.
Production builds target ES2022, minify, and strip console calls. The size summary lists your largest dependencies and flags any single dependency over 200 KB in production. Four build keys in puzzle.config.js adjust this:
// puzzle.config.js
export default {
build: {
splitting: true, // dynamic import() becomes a lazily fetched chunk
hashNames: false, // keep fixed names (defaults to splitting)
sourceMap: true, // emit linked source maps in production
dropConsole: false, // keep console calls in production
},
};With splitting on, each dynamic import() (including a lazy() route view) becomes its own chunk under dist/chunks/, fetched only when that code runs. --fixtures and --profile-build work as they do for dev; --fixtures can't be combined with a prerendered output.
Both build and dev check that the project has @magic-spells/puzzle installed before bundling. When it doesn't, as in a fresh checkout run with a global CLI, they stop and print the install command for your lockfile.
puzzle preview
Serves an existing dist/ the way a production host will, with no watcher and no reload. The SPA gets the history fallback, hybrid serves each route's prerendered page, and static gets clean URLs and a real 404 from dist/404.html. It's the quickest way to catch a page that works in dev and breaks on the host:
puzzle build && puzzle preview puzzle preview --port 4000 # the default port
puzzle check
Type-checks .pzl files with the TypeScript compiler your app has installed (puzzle never installs one for you). A <script lang="ts"> is checked as written, and every template expression is checked too: a method as the same JavaScript method and a library call against the function's signature (an app function is typed any). A typo like { user.nmae } is caught when the receiver has a declared type; a field returned only by data() is untyped. Method and function arguments are checked when their types are known, as in { price.toFixed('2') }. Diagnostics point to the authored line and column. Plain JavaScript scripts are left alone.
npm install -D typescript puzzle check
puzzle init
Scaffolds a new project. In a terminal it prompts for anything you didn't pass (the app name, the template, and TypeScript); in scripts and CI the app name is required, omitted flags use their defaults, and it never prompts:
puzzle init my-app puzzle init my-app --template default # minimal app puzzle init my-app --template todos # the todos example, Tailwind wired up puzzle init my-app --typescript # TypeScript components, .ts modules, strict config + check script
puzzle generate
Generates a stub for a component, view, layout, or model (alias g). --family scaffolds a component family: a directory with one component per member plus an index.js barrel (index.ts in a TypeScript app). Existing files are never overwritten without --force:
puzzle generate component UserCard --path app/components/ui puzzle generate component Frame --family Wrapper,Content puzzle generate view Profile puzzle generate model post
generate never edits your JavaScript. With a root tsconfig.json, every generated stub is TypeScript. Registering a new model in app/models/index.js (or its TypeScript counterpart) is a line you add yourself.
puzzle add
Wires something into an existing project. It never runs npm and never rewrites your styles.css or an existing config; it prints the install command and the lines to add instead:
puzzle add tailwind puzzle add piece button card puzzle add theme cool puzzle add skills
add tailwinddeclares the Tailwind pipeline inpuzzle.config.jsand adds an entry stylesheet.add piececopies puzzle-pieces components intoapp/components/ui/, with their piece and helper dependencies, and records content hashes inpieces.lock. For the npm packages those pieces wrap, it printsnpm install <name>@<range>with the version range each piece needs. It refuses to overwrite existing files unless you pass--overwrite.add themecopies a pieces palette intoapp/styles/themes/(the default palette is thepieces.cssthatadd piecealready writes). It prints the@importand thedata-schemeswitch to add rather than editing your stylesheet, skips a palette your stylesheet already imports from the package, and refuses a locally modified copy unless you pass--overwrite. With no name, it lists the palettes and which ones the app has.add skillsinstalls the Puzzle agent skill for Claude Code, Codex, and Cursor, into each config directory it detects.puzzle upgrade skillsrefreshes an installed copy.
puzzle doctor
Runs environment and project checks and prints a pass, warning, or fail line for each: Node on your PATH, the entry (app/app.ts, else app/app.js; having both is an error), index.html, the config, Tailwind, and the installed runtime. A missing runtime install, or a Tailwind with no local install (it falls back to npx), is only a warning; any other failed check makes it exit non-zero. It's a good first step when a build or the dev server misbehaves:
puzzle doctor
puzzle info
Prints environment and project information (versions, platform, resolved paths, the styles pipeline), which is useful for bug reports:
puzzle info
puzzle upgrade
Upgrades the CLI you ran, through the package manager that installed it: a project dependency is upgraded in that project, a global install globally. --check only reports the current and latest versions. build and dev also print a one-line notice in an interactive terminal when a newer release is out; the check runs in the background, never delays a command, and is skipped in CI or when PUZZLE_NO_UPDATE_CHECK is set.
puzzle upgrade puzzle upgrade --check
Building the CLI from source
Prebuilt binaries cover macOS (arm64, x64), Linux (x64, arm64), and Windows (x64; Windows on ARM runs it under emulation). On any other platform, install from source with Go:
git clone --branch v0.9.0 --depth 1 https://github.com/magic-spells/puzzle.git cd puzzle/packages/puzzle go install ./compiler/cmd/puzzle
Next
- Static Builds: the
--staticand--hybridbuilds in depth. - Installation: getting the CLI in the first place.