A category theory notepad. Paste what you have, in any notation, and get checked Lean 4 and drawn diagrams back.
Here the ⟳ in the first diagram was clicked. The theorem that makes the square commute, sign_square, lights up in the Lean buffer, and its statement shows under the diagrams.
catpad keeps four components in sync:
- Notes: a freeform box for pasting expressions in any notation.
- Agent: an LLM agent loop that reads the notes, writes Lean, fixes errors, and draws diagrams.
- Lean: an editable Lean 4 + Mathlib buffer with the language server's hover docs, goal at cursor, and completion. Every edit is checked. Errors show inline, and you can fix them by hand or hand them to the agent. ⌘F (Ctrl+F) searches the buffer, and the handles in the gutter fold a theorem, a def, a diagram, a section or a comment down to its first line.
- Diagrams: TikZ panels generated from a
diagramDSL in the Lean buffer. They redraw whenever Lean finishes, and you can draw in them.
On the diagrams, each part is bound to a Lean term:
- Click an object, an arrow or a ⟳, and its definition lights up in the code.
- Put the cursor on a definition, and everything drawn from it lights up in the diagrams.
- Edit the code, and Lean checks it and TeX draws the diagrams again.
- Math in a comment, written
$inline$or$$display$$, is typeset in place. Put the caret in it to see and edit its source. - Draw in a diagram, and the lines of its
diagramblock are written in the code. See "Drawing".
catpad is a desktop app for macOS (Apple silicon), Linux (x86-64) and Windows (x86-64). On macOS and Linux, one line installs the newest release:
curl -fsSL https://raw.githubusercontent.com/tlehman/catpad/main/scripts/install.sh | shOn Windows, the same in PowerShell:
irm https://raw.githubusercontent.com/tlehman/catpad/main/scripts/install.ps1 | iexOn macOS this puts catpad in Applications and opens it. On Windows it runs the installer, which puts catpad in your Start menu, needs no administrator, and opens it (scripts/install.ps1). On Linux it unpacks the AppImage into ~/.local/share/catpad, so it needs no FUSE, and adds catpad to your applications menu and to ~/.local/bin. The script is scripts/install.sh, short enough to read before you run it. Run it again to reinstall. After that the app updates itself.
The download comes with everything catpad runs on: Lean, Mathlib already compiled, and the tools that draw the diagrams (tectonic, the TeX files it reads, and poppler). The first time catpad starts, it unpacks them into its own folder and shows its progress. That takes a minute or two and about 9 GB of disk. It needs no network, no password and no terminal, and a Lean you already have is neither used nor touched. After that, catpad starts at once. Which versions it comes with, and how they get there, is under "The kit".
On Windows the installer does not carry them yet, so the first start downloads them instead: one archive of about 1 GB.
Each release has:
-
catpad-macos-arm64.dmg: open it and drag catpad to Applications. The app is not signed with an Apple Developer ID yet, so the first time it is blocked: open System Settings → Privacy & Security, and press Open Anyway next to catpad. The one-line installer above does not ask, because the files it downloads are not quarantined. -
catpad-x86_64.AppImage: make it executable (chmod +x catpad-x86_64.AppImage, or Properties in the file manager), then open it. It carries its own Chromium, Lean, Mathlib and diagram tools, so it needs nothing from the distribution but glibc 2.36 or newer (Debian 12, Ubuntu 23.04, Fedora 37 and later) and FUSE 2 (libfuse2, orlibfuse2t64on Ubuntu 24.04). Without FUSE, run it with--appimage-extract-and-run, or use the installer. -
catpad-windows-x64-setup.zip(Windows 10 or 11): unzip it and run the installer inside. The installer is not signed yet, so Windows SmartScreen may say it protected your PC: press More info, then Run anyway. catpad then lives in your Start menu.
Each release also has the full build log for each platform and SHA256SUMS.
./run.sh # http://127.0.0.1:8792/ (PORT changes it)This is the way on an Intel Mac, on an older Linux, and for working on catpad. Run from source, catpad uses the tools on your PATH rather than the kit. It needs:
- bun
- tectonic
- pdftocairo (from poppler)
- elan and lake (Lean 4)
- A Lake project with built Mathlib (see "The Lean project")
- A sandbox for Lean: bubblewrap on Linux,
sandbox-execon macOS (built in) - An agent backend, if you want the agent (see "The agent")
run.sh checks for each tool and prints how to install what is missing.
brew install bun tectonic poppler elan-initThen ./run.sh. The first run sets up Lean and Mathlib.
sudo apt install poppler-utils bubblewrap curl
curl -fsSL https://bun.sh/install | bash
curl https://elan.lean-lang.org/elan-init.sh -sSf | sh
curl --proto '=https' --tlsv1.2 -fsSL https://drop-sh.fullyjustified.net | shThe last line is tectonic's documented installer. It drops a tectonic binary in the current directory, so move it onto your PATH. Your distribution may also package it. Open a new shell afterwards so bun and elan are on your PATH.
nix develop
./run.shflake.nix provides bun, tectonic, poppler-utils and elan, plus bubblewrap on Linux. It supports aarch64-darwin, x86_64-darwin, x86_64-linux and aarch64-linux.
catpad needs two things that are not catpad: Lean with Mathlib, which check the Lean, and TeX with poppler, which draw the diagrams. The app does not ask the machine for either. They come with it as the kit: one archive per platform, built from pinned versions, and carried inside the download.
The pins are two files.
kit.json: Lean (its release archive for each platform, with a SHA-256), Mathlib (a tag, and the commit the tag names), tectonic (pinned the same way as Lean), poppler (its version on conda-forge), and the micromamba that fetches poppler when the kit is builtlean/lake-manifest.json: every Lean package under Mathlib (Batteries, Aesop, Qq and the rest), each at a commit
lean/lean-toolchain and lean/lakefile.toml say the same thing as kit.json, for Lake to read. bun scripts/kit.ts check fails when any of them disagrees, and the release workflow runs it first.
A kit is named by a hash of its pins, so the same pins are the same kit, and changing one makes a new kit.
bun scripts/kit.ts check # the pins agree with each other
bun scripts/kit.ts id # this kit's id
bun scripts/kit.ts build # kits/catpad-kit-<platform>.tar.zst, built and verifiedWhat is in it. About 1 GB to download and 9 GB unpacked:
toolchain/: Lean and Lake as their release ships them, without the C compiler. catpad checks Lean. It builds no programslib/: Mathlib and its packages, compiled. These are most of the 9 GB, and they travel packed byleantar, Lean's own packer for compiled files, which gets them to a quarter of what zstd doesdraw/: tectonic's static binary, and poppler'spdftocairowith exactly the libraries it loadstex/: the TeX files and fonts a diagram can use, so tectonic fetches nothing when it drawskit.json: the manifest, which says what all of the above are
There is no elan in it. elan's job is to choose a Lean and download it, and here both are decided when the kit is built.
How the kit is built. scripts/kit.ts build downloads the Lean release and checks its SHA-256, runs lake exe cache get in a copy of lean/ (Lake clones each package at its locked com
8000
mit, and Mathlib's cache tool fetches them compiled), downloads tectonic and poppler, draws one document that uses every font and arrow a diagram can, and packs the result. Then it verifies what it made: it unpacks the archive the way the app does, compares every compiled file with what went in, and has that copy import Mathlib, prove a few things, compile lean/Prelude.lean and draw a diagram, with nothing of the build machine's on PATH. A kit that cannot do that is never an archive.
How the app gets it. The kit is unpacked once into kit/<id>/ in the data directory, and Lean and the diagram tools run from there. The archive comes from the first of these that has it:
CATPAD_KIT_ARCHIVE, a file you name- the app itself: the macOS disk image's app has it in its resources
kit/<id>.tar.zstin the data directory, where the AppImage puts it before it starts the app- the GitHub release
kit-<id>, downloaded and checked against its SHA-256
The fourth is how an installed catpad moves to a new kit. Updates of the app are small because they do not carry the kit, so an update that changes the pins fetches the new kit once and removes the old one. It is also how Windows gets its first.
To move to a newer Lean and Mathlib, change the versions and checksums in kit.json, the same versions in lean/lean-toolchain and lean/lakefile.toml, and run lake update in lean/ to lock the packages again. bun scripts/kit.ts check says whether the four agree, and bun scripts/kit.ts build whether catpad's prelude still compiles on them. The next release builds the new kit on each platform and ships it.
CATPAD_LEAN_DIR points catpad at a Lake project with Mathlib, to use with the lake on your PATH instead of the kit. Run from source by run.sh, the default is this repo's lean/ directory, which has a lakefile.toml (package catpad, requiring Mathlib v4.35.0), a lean-toolchain for leanprover/lean4:v4.35.0, and the lake-manifest.json that locks the packages. lean/Prelude.lean lives there too. The server compiles it separately, so it is not a Lake target.
On the first run, run.sh sees that $CATPAD_LEAN_DIR/.lake/packages/mathlib is missing and runs lake update there. Mathlib's post-update hook downloads its prebuilt cache. That is several GB, so expect it to take a while. It happens once, and it prints what it is doing.
If you already have a built Mathlib project on the same Lean version, set CATPAD_LEAN_DIR to it and skip the download. In the app, set it in config.env in the data directory.
The agent reads the notes, edits the Lean buffer, reads Lean's errors, and fixes them. The prompt that tells it how to keep the four components in sync and how to use the DSL is agent/prompt.md. Editing that file is the way to change the agent's behaviour.
You pick what runs the agent, and catpad does the wiring. Open AI → Connect Your Agent (the menu bar in the macOS app, the AI menu in the page everywhere else, or "Connect…" above the conversation). catpad looks at the machine first: which of Claude Code and Codex are installed and signed in, and which local model servers answer on their usual ports. Each choice says whether it is ready, and if it is not, the command that makes it so, with a button that copies it.
- Claude Code: Anthropic's agent, run headless with your Claude account. It gets catpad's tools and nothing else: no shell, no file access, none of your own settings, hooks or MCP servers.
- Codex: OpenAI's agent, run headless (
codex exec) with your ChatGPT account or OpenAI key. It reaches catpad's tools through the same MCP endpoint, approved in advance, and runs without your own Codex configuration. Codex always has a shell. catpad runs it read-only in an empty directory, so it can read files and cannot change them. - Local model: any OpenAI-compatible server. catpad finds Ollama (11434), LM Studio (1234), llama.cpp (8080), vLLM (8000) and Jan (1337) by itself, and lists their models. Any other URL works too. The model needs tool calling support.
- Functorial Agent: Functorial's hosted agent, an OpenAI-compatible endpoint (
https://agent.functorial.inc/v1, orCATPAD_FUNCTORIAL_URL) that takes your Functorial API key. Your notes and Lean go to Functorial's servers with each message. - No agent: notes, Lean and diagrams still work, and you write the Lean yourself.
Test asks the choice whether it would work, without connecting it. Connect switches at once, with no restart, and the conversation carries over: the new agent is told it with your next message. The choice is kept in agent.json in the data directory, readable by you alone, with any key you gave. The page is only ever told whether a key is saved.
Without a choice in the dialog, the environment decides. CATPAD_AGENT picks claude, codex, openai, functorial or none. Without it, catpad uses openai if CATPAD_LLM_URL is set, otherwise Claude Code if it is on your PATH, otherwise Codex if that is, otherwise none. CATPAD_AGENT_MODEL picks Claude Code's or Codex's model. CATPAD_LLM_URL, CATPAD_LLM_MODEL and CATPAD_LLM_KEY set up a local server, and CATPAD_FUNCTORIAL_URL and CATPAD_FUNCTORIAL_KEY the Functorial Agent.
Going back in the history gives the agent the context it had then. Claude Code resumes its session at that message. Codex can only resume a thread at its end, so after going back it starts a new thread and is told the conversation up to there, as a local model is.
This is an example. Pick any model that supports tool calling. Once Ollama is running, the dialog finds it, so the variables below are only for setting it up without the dialog.
ollama pull qwen3:14b
export CATPAD_LLM_URL=http://127.0.0.1:11434/v1
export CATPAD_LLM_MODEL=qwen3:14b
export CATPAD_LLM_KEY=ollama # optional, some servers want any non-empty value
./run.shYou can put the three variables in .env instead. See .env.example.
When the agent names a place in the buffer ("line 12", "lines 18-23", "at 12:4"), in its text, in a tool call's summary or in your own message, that place is a link. Point at it and those lines light up in the editor. Click it and the caret goes there and the lines flash. The line numbers are the gutter's, as the agent sees them in read_pad.
The server exposes its tools as an MCP server at http://127.0.0.1:8792/mcp: read_pad, write_lean, edit_lean, goal_at and hover_at. The catpad prompt is sent as the MCP instructions. Some clients, Claude Code among them, cut long instructions short, so for the full prompt point your agent at agent/prompt.md as well. For example:
claude mcp add --transport http catpad http://127.0.0.1:8792/mcpAll optional. .env.example lists them with their defaults, and run.sh loads .env if it exists.
PORT: the port, default 8792CATPAD_LEAN_DIR: a Lake project with Mathlib to use instead of the kit.run.shsets it to./leanCATPAD_DATA: where the projects are kept (see "Projects"), and the kitCATPAD_AUTO_SETUP:1makes catpad set itself up when something is missing: unpack the kit, or runlake updatewhen a Lean project has no Mathlib. The app does this by defaultCATPAD_KIT_ARCHIVE,CATPAD_KIT_DIR,CATPAD_KIT_URL: a kit archive to unpack, an unpacked kit to run on, and where to download the kit from (see "The kit")CATPAD_UPDATE_CHECK:0stops catpad asking GitHub for a newer releaseCATPAD_SANDBOX:0turns the Lean sandbox offCATPAD_AGENT,CATPAD_AGENT_MODEL,CATPAD_LLM_URL,CATPAD_LLM_MODEL,CATPAD_LLM_KEY,CATPAD_FUNCTORIAL_URL,CATPAD_FUNCTORIAL_KEY: the agent, as above. A choice made in Connect Your Agent wins over theseCATPAD_DEBUG:1logs what the language server reportsLEAN_TIMEOUT_MS: how long one Lean check may take, default 60000CATPAD_DRY_RUN:1makesrun.shrun its checks, print what it would start, and exit
Nothing is built or cached in this directory. The compiled prelude and the rendered diagrams go to ~/.cache/catpad, and the projects to the data directory.
You can start from the picture. Draw the shape first, then make the Lean agree with it.
The tools are above the diagrams:
- New diagram: an empty
diagramblock at the end of the buffer. - Object: click an empty place in a diagram.
- Arrow: drag from one object to another. Back onto the same object makes a loop.
- 2-cell: drag from one arrow to another. The two arrows get names if they had none.
- Commutes: click inside a cell to put a ⟳ there.
- Select: click to select, drag an object or a ⟳ to move it. Escape comes back to this tool, and Delete takes out what is selected, with whatever is drawn on it.
What you draw is not bound to anything yet. It appears as a dashed box or a dotted arrow labelled ?, and as a line with no := term in the code. The inspector under the diagrams shows the selected item's fields: its term, name, label, bend, dashes. Fill the term in there, or type it in the code. They are the same text.
Drawing never changes a picture directly. Each stroke is sent to the server as an operation, the server writes it into the buffer as a line of the diagram command, Lean checks the buffer, and the picture comes back the way every picture does. So the buffer stays the one thing that is stored, and a drawing is checked by the same Lean as typing. draw.ts has the operations.
Lean puts every item in one state, and the picture shows it:
| state | meaning | in the picture |
|---|---|---|
ok |
bound to a term that fits where it is drawn | ink |
hole |
drawn, with no term yet | amber, dashed or dotted, ? |
open |
bound, and nothing contradicts it, but one of its ends is a hole | dim amber |
mismatch |
bound to a term that does not fit | red, and the end it does not fit at lights up when you select it |
error |
the term does not elaborate, or it names something missing | red |
A hole is a warning in the buffer, a mismatch or an error is an error. One item failing does not stop the rest of the diagram from being checked and drawn.
A diagram is checked when every item is ok, a sketch when some are holes or open, and in clash when something does not fit. The card's header says which. A sketch is a fine thing to keep around: it is a drawing whose mathematics is not all there yet, and it says so.
When an object is a hole and a bound arrow ends at it, the inspector says what the arrow needs it to be, and one click binds it.
"Ask the agent" on a diagram that is not checked, or on one item in the inspector, hands the drawing over. The request is agent/resolve.md, filled in with the diagram's source, every item's line and state, what the arrows say about the holes, and what you drew since the agent's last turn. It tells the agent that the drawing is the specification: it may add or change the := term of items that do not check and the Lean above the diagram, and it may not move, rename, re-route or delete what you drew. If what you drew cannot be true, it says so and leaves the hole. Edit that file to change the request.
diagram "The sign: n steps scale the bracket by (-1)^n"
obj A at (0, 0) := V × V -- an object: a name, a (row, column), a Lean term
obj C at (1, 0) := ℤ
hom A C swap := det -- an arrow, checked: det must go from V × V to ℤ
comm at (0.5, 0.5) := sign_square n -- a cell: a proof, drawn as ⟳Options go before :=: tex r"\Lambda^2 V" (the label, instead of the pretty-printed term), bend 30, swap (label on the other side), dashed. Inside a section, the terms can use its variables.
The := term is optional on every item. Without it the item is drawn and not bound, which is how a drawing starts:
diagram "A sketch"
obj C at (0, 0) := C
obj D at (0, 1.5) := D
hom F : C D bend 40 := F -- a named arrow
hom G : C D bend -40 swap -- drawn, not bound yet
cell F G := η -- a 2-cell between two named arrowshom A B := f reads a source and target off the type of f (a function, anything with a FunLike instance, a morphism X ⟶ Y, an isomorphism X ≅ Y, a functor C ⥤ D, an equivalence C ≌ D) and compares them with the terms bound to A and B. An arrow that doesn't fit is an error in the code and red in the diagram.
cell F G := η does the same one level up. It reads a source and target off the type of η (a natural transformation or any 2-morphism F ⟶ G, a natural isomorphism F ≅ G, an equation f = g) and compares them with the terms bound to the arrows named F and G.
comm only checks that its term is a proof. It shows the statement. It does not check that the statement is about the arrows around it. A cell between two arrows bound to an equation is checked against both.
lean/Prelude.leandefinesdiagram. It elaborates every term on its own and reports one JSON diagnostic per diagram: for each item its state and the reason for it, its pretty-printed term and type, the source ranges of the item and of its term, and the range of the declaration behind it. The server compiles it once to a module,Diagram.server.tsrunslean --serverand keeps the buffer as one document in it, behind a hidden first lineimport Mathlib import Diagram. On each edit Lean re-elaborates from the change down. The server turns each diagram's JSON into TikZ and runs tectonic and pdftocairo to get an SVG. Item k is drawn in the colour (1, 2, k+3), so the colour of an SVG element says which item it draws. The server replaces it withdata-k="k". Hover, the goal at the cursor and completion (as you type, or Ctrl+Space) are the language server's, passed through.draw.tsis the way back from a picture to the buffer: it carries out a drawing operation on what Lean reported and prints it as lines of the DSL.agent.tsruns the agent loop and the MCP endpoint on top of the same Lean session.history.tskeeps the commits in SQLite, through Bun's built-inbun:sqlite.projects.tskeeps the projects and reads and writes.catpadfiles.paths.tssays where catpad's own files are and where the user's go.update.tsfinds a newer release and installs it, andsrc/main/index.tsis the desktop app.web/is the page: plain JavaScript, no build.web/machine.jsis read by the server too.
Information runs along one line, through the same stations both ways:
notes ─▶ agent ─▶ buffer ─▶ Lean ─▶ spec ─▶ TikZ ─▶ picture left to right
agent ◀─ report ◀─ states ◀─ Lean ◀─ buffer ◀─ op ◀─ picture right to left
Left to right is derivation: each station is computed from the one before it and from nothing else. Righ
8BD0
t to left is editing: a drawing operation is carried out on the spec, printed into the buffer, and from there it runs left to right again. Nothing is changed in the middle of the line. Whoever changes the buffer (you typing, you drawing, the agent, a restore) goes through one function in server.ts, setCode, which is where the pages, the agent's view of the buffer and the history hear of it.
Everything that can be in more than one condition has its states named, with the moves between them, either as a table (machine in web/machine.js) or as one function that derives the state from the facts. web/machine.js starts with the list:
| what | states | where |
|---|---|---|
| an item of a diagram | ok, open, hole, mismatch, error | lean/Prelude.lean |
| a diagram | empty, checked, sketch, clash | diagramState |
| Lean, the process | stopped, starting, ready, failed | server.ts |
| Lean, the document | closed, elaborating, elaborated | server.ts |
| the check of the pad | down, checking, rendering, settled | server.ts, padCheck |
| what the agent knows of the buffer | first, restored, same, typed, drawn | server.ts, agentView |
| a turn of the agent | idle, running, stopping | agent.ts |
| the page and the server | offline, starting, ready | app.js, link |
| the editor and Lean | clean, dirty, checking, stopped | app.js, sync |
| a diagram's picture | fresh, stale, broken | app.js, cardState |
| the drawing tool | move, obj, hom, cell, comm | app.js, tool |
| the pointer on a diagram | idle, armed, moving, linking | app.js, gesture |
Two of these gate drawing. A diagram can be drawn in only when the editor and Lean are clean and its picture is fresh, because a drawing is written into the source ranges Lean reported, and those are ranges of the text it checked. And nobody draws while the agent's turn is running.
- The server listens on 127.0.0.1 only.
- Its WebSocket only accepts its own page.
- The MCP endpoint refuses browser-originated requests.
- Lean is sandboxed on macOS and Linux, because
#evalin the buffer can run IO. Windows has no sandbox for it yet, so there a pad's#evalcan do what you can. The sandbox has no network and cannot write outside its temp directory. On Linux (bubblewrap) it sees only/usr, the toolchain, the Lean project and the prelude. On macOS (sandbox-exec) it cannot read file contents under your home directory apart from those, but file names there and system files such as/etc/hostsstay readable.CATPAD_SANDBOX=0turns it off.
A project is one pad: a name, the notes, the Lean buffer, and the history of how they got there. The project's name is the button next to the version in the header. It opens the list of projects and these:
- New project: an empty pad, opened at once. The project you leave is committed and saved first, so switching loses nothing.
- Open example: a copy of
examples/fib-plucker.catpad, the Fibonacci identity that is a Plücker relation. The first time catpad starts, this is the project it opens. - Import: a
.catpadfile, opened as a new project. - Export: the project as a
.catpadfile, into your downloads. - Name: rename the project.
A .catpad file is JSON, small enough to read:
{ "format": "catpad-project", "version": 1, "name": "…", "notes": "…", "code": "…" }It is the project's content. The history stays behind: it is the project's working memory, and it does not travel.
The server keeps the projects, not the browser. They live in the data directory: ~/Library/Application Support/catpad on macOS, $XDG_DATA_HOME/catpad (usually ~/.local/share/catpad) on Linux, or CATPAD_DATA. Each project is a folder in projects/ with its file, project.catpad, written a moment after every change, and its history, history.db. state.json says which project was open last. A catpad.db from before there were projects becomes a project named catpad, once.
Each project keeps a history in its own SQLite database. It works like git, for one document. A commit is a snapshot of the notes, the Lean buffer, the agent's conversation and the diagrams, taken together, so the four always agree with each other.
- The pad commits itself when the agent finishes a turn, when you draw in a diagram, and when you have typed and then stopped for 20 seconds. Your edits are committed apart from the agent's: once before its turn starts, and once when it ends.
- A stroke in a diagram is a commit of its own, made as soon as Lean and TeX have drawn it, with a message that says what was drawn:
Draw in “The sign”: add arrow A → B. Strokes faster than Lean share a commit. In the tree these commits are dashed circles. - "History" in the header draws the commits as the tree they are: newest at the top, a lane for each branch, a line from every commit to its parent. Write a message and press Commit to make one yourself. If nothing has changed since the last commit, that commit gets your message.
- Click a commit to go there: the notes, the buffer, the conversation and the diagrams all go back at once. Whatever was not committed is committed first, so going back loses nothing.
- Going back and then changing something starts a new branch from there (
branch-2,branch-3, and so on). The branch you left stays. The branches are listed above the tree: click one to go to its tip, and use ✎ to rename the one you are on. - The agent goes back too. Each commit keeps the agent's own state at that moment, and going to a commit gives the agent exactly the context it had then: what was said later is not in it. With Claude Code that is the session, resumed at the commit's last message in a copy of its own (
--resume-session-at,--fork-session). With an OpenAI-compatible server it is the message list. If the state cannot be used (Claude Code deletes old sessions), the agent starts afresh and is given the restored conversation as text.
Parts are stored once, by the hash of their content (history.ts has the schema), so commits that share their notes or a diagram's SVG share the row.
catpad is also an Electrobun app. The app runs the same server run.sh starts and opens a window on it, so it is the same page, with the same projects. src/main/index.ts is the whole of the app's own code. What it adds:
- the login shell's
PATH, which an app started from the Dock or a desktop menu does not get, soclaudeand the other agents are found config.envin the data directory, read the wayrun.shreads.env- a free port, so a checkout running on 8792 is not in the way
- setting itself up on the first start: it unpacks the kit it came with (see "The kit"). Set
CATPAD_LEAN_DIRinconfig.envto use a Lean and Mathlib of your own instead - a file dialog for Import, and Export that shows the file in Finder or the file manager
- a menu bar on macOS: File (New Project ⌘N, Open Example, Import ⌘O, Export ⌘E, Projects ⌘P, History ⌘Y), Edit, AI (Connect Your Agent ⌘K, Formalize, Explore, Draw, Stop, New Conversation), View (Zoom In ⌘=, Zoom Out ⌘−, Actual Size ⌘0, show or hide the notes ⌘B) and Window. Its commands go to the app's own window, which does what its buttons do. In a browser, and in the app on Linux, the page has the same File, AI and View menus in its header
- zoom: the webview's own page zoom, so the text and the diagrams grow together and stay lined up. It is kept across launches
The app brings Lean, Mathlib, tectonic and poppler with it, as the kit, and unpacks them on its first start without asking for anything. "Set up catpad" opens by itself and shows the progress. On Linux it also recommends bubblewrap, Lean's sandbox, which needs your password, so it shows the command; catpad works without it. setup.ts says what is taken from where, and scripts/smoke.sh starts each packaged app on a clean machine before every release and has it check a theorem and draw a diagram. On Linux it does that with the network taken away, so what passes is what the download can do alone.
The icon is a commuting triangle in Functorial's style: a black rounded square and a heavy white mark with Computer Modern arrowheads, the heads taken from Functorial's ⟹. scripts/icon.ts draws it, and writes the macOS icon set, the Linux icon and the favicons.
bun install
bun run app # build and run it from this checkout
bun run build # package it for this machine: the app and its installer in artifacts/Electrobun's toolchain comes through Hutch, which the electrobun package fetches the first time it runs. It builds for the machine it runs on: macOS on a Mac, Linux on Linux, Windows on Windows.
Versions are semver, and the version is the one in package.json. CHANGELOG.md is the build log: every release, the day it was cut, the commit it was cut from, and the commits that went into it.
bun run release patch # 0.1.0 → 0.1.1 (minor, major, or an exact version such as 0.3.0-rc.1)
git push origin main v0.1.1scripts/release.ts checks that the tree is clean and on main, writes the version and the changelog entry, commits, and tags. --dry-run shows the entry and changes nothing. Pushing the tag starts .github/workflows/release.yml, which builds the app on macOS (Apple silicon), Linux (x86-64, on Ubuntu 24.04, with Chromium inside) and Windows (x86-64, with the system's WebView2), builds the kit for each platform or takes the one already published for these pins (scripts/kit.ts), wraps the Linux build and its kit as an AppImage (scripts/appimage.sh), builds the macOS disk image with the kit in the app, starts each packaged app and has it set itself up, check a theorem against Mathlib and draw a diagram (scripts/smoke.sh, scripts/e2e.ts), and only then publishes the release: the DMG, the AppImage, the Windows installer, the update bundles, each platform's full build log and SHA256SUMS. The kit is published beside it, once, as the release kit-<id>. A version with a pre-release suffix is published as a pre-release. Actions → Release → Run workflow builds and checks without publishing.
Without an Apple Developer ID the app is signed ad hoc (scripts/postwrap.ts): macOS opens a downloaded copy only after the user allows it once. With one, the release workflow signs and notarizes it, and a downloaded DMG opens like any other app. It needs these repository secrets (Settings → Secrets and variables → Actions):
MACOS_CERTIFICATE: the Developer ID Application certificate with its key, exported from Keychain Access as a .p12, thenbase64 -i cert.p12MACOS_CERTIFICATE_PASSWORD: the .p12's passwordMACOS_DEVELOPER_ID: the certificate's name,Developer ID Application: Your Name (TEAMID)APPLE_API_KEY_ID,APPLE_API_ISSUER,APPLE_API_KEY: an App Store Connect API key (Users and Access → Integrations), for notarizing; the last is the .p8 file's text
catpad looks for a newer release when it starts and every six hours, and the version in the header checks when you click it. When there is one, an "Update to vX.Y.Z" button appears. Pressing it commits and saves the pad first, and then:
- The app downloads the new bundle from the release, replaces itself, and starts again. The apps look at the newest release's files (
releases/latest/download/), so they never update to a pre-release. - A checkout started by
run.shrunsgit pull --ff-onlyand starts the server again (it exits with 75, andrun.shstarts it). It only does this on a clean main. Otherwise it says why, and you pull yourself.
MIT. See LICENSE.