Keep designs in your repo

Keep a design as React source in your code project, and sync it with Knighn both ways.

A design can live in your code project as React source, beside the code it designs. The folder knighn/<design>/ holds one .tsx file per component, canvas.tsx (where each screen sits), theme.css and design.json. Review it in pull requests like any other code.

Set up the project

cd my-app
knighn dev

Like npx convex dev, the first run does the setup: it signs you in when the knighn command has no key, writes knighn.json (the folder and the link of each design to Knighn) and the knighn/ folder, and lists your designs to pull. Then it keeps watching (see below). knighn init does only the setup.

Bring a design in

knighn ls                # your designs, newest first
knighn pull "Pricing"    # by name, or by its file id

Send changes to Knighn

knighn push            # every design folder
knighn push pricing    # one design

A push fails when the design changed on Knighn since your last pull, so nobody's work is lost. Pull first, or --force to write over it.

Work on both sides at once

knighn dev

knighn dev watches knighn/. It pushes a design when its files change, pulls a newer version from Knighn every few seconds, and reports a change made on both sides as a conflict. Each line has the time. A save that does not read (or whose theme does not compile) is not sent: the line names the file and line to fix, and the next good save goes. --once syncs each design once and stops; --open opens each design in the Mac app too.

More from the terminal

knighn run "return await GetAppState()" --design Pricing   # an execute snippet, like convex run
knighn search "button" --design Pricing                   # search a design
knighn logs                                              # each new version of your designs, like convex logs
knighn zed Pricing                                       # the design in Zed (see Edit in Zed)

Use the components in your app

knighn/_generated/ and each design's index.ts export its components, so your app can import a screen or a component from the design.

In the Mac app, a project tab's Designs tab lists the design folders of the project, and opening one edits the files on disk.