CMS Harness
by Michaelzhao9
README.md
<p align="center">
<img src="docs/images/banner.svg" alt="CMS Harness: say what you need, the AI builds it as drafts, you publish." width="100%">
</p>
<h3 align="center">An admin you never have to learn. Say what to do, or what to change.<br>Every change is a draft. Nothing goes live without your yes.</h3>
<p align="center">
Pages, back end, data, accounts, the AI chat and the API in <b>one download of about 13 MB</b> and <b>one SQLite file</b> (or Postgres, if you want it).<br>
No Node, no Redis, no build step.
</p>
<p align="center">
<a href="https://github.com/Michaelzhao9/cms-harness/releases"><img alt="Latest release" src="https://img.shields.io/github/v/release/Michaelzhao9/cms-harness?color=f5b700&labelColor=1d1d1f"></a>
<a href="https://github.com/Michaelzhao9/cms-harness/actions/workflows/ci.yml"><img alt="Tests" src="https://img.shields.io/github/actions/workflow/status/Michaelzhao9/cms-harness/ci.yml?branch=main&label=tests&labelColor=1d1d1f"></a>
<a href="https://github.com/Michaelzhao9/cms-harness/stargazers"><img alt="GitHub stars" src="https://img.shields.io/github/stars/Michaelzhao9/cms-harness?style=flat&color=f5b700&labelColor=1d1d1f"></a>
<a href="LICENSE"><img alt="License: AGPL-3.0" src="https://img.shields.io/badge/license-AGPL--3.0-1d1d1f"></a>
<img alt="Rust 1.98+" src="https://img.shields.io/badge/rust-1.98%2B-1d1d1f">
<img alt="MCP server built in" src="https://img.shields.io/badge/MCP-built%20in-f5b700?labelColor=1d1d1f">
</p>
<p align="center">
<a href="#-quick-start">Quick start</a> ·
<a href="#-what-you-get">Features</a> ·
<a href="#-connect-your-agent">Connect your agent</a> ·
<a href="#-reference">Reference</a> ·
<a href="README.zh-CN.md">中文</a>
</p>
<p align="center">
<img src="docs/images/demo-en.webp" alt="Demo: asking the admin chat for a homework system; the assistant sets up the data, a student surface, a teacher surface and the grading function, all as drafts; both surfaces in the preview; publishing; and the environment page listing three surfaces and the data they share." width="100%"><br>
<sub>One request, from an empty environment to an app with two surfaces. The screen and every step are the real program running; so that it can be recorded again, the model's replies here are played back from a script.</sub>
</p>
A traditional admin panel is a lot of clicking: slow to learn, slow to use, and whatever doesn't suit you stays that way. A system you build for a client is worse: once it's handed over, the client can't change anything, and every small change comes back to the developer. CMS Harness turns both into a sentence. Say what to do and it does it; say what bothers you and it changes it. Every change is a draft until a person has looked it over and said yes.
**Who it's for:** developers and studios who build systems for clients use it to build and hand them over. Schools, small companies and organisations run it on their own server: the data stays with them, protection is built in, and later changes are theirs to ask for.
Deploy this one program and it is the whole environment, and the admin that manages it. Open the admin and say *"turn the home page into a studio page"*, *"add a booking form"* or *"give teachers and students a screen each: students hand in homework, teachers grade it"*. The built-in assistant sets up the data, writes the pages and the server functions, and builds the admin screens to manage them. Everything it does is a **draft**: nothing live moves until a person reviews the changes and presses **Publish** (or approves the assistant's request to publish).
Not happy with a detail? Don't write a prompt for it. **Drag it, resize it or retype it right on the page**, add a page or a navigation link from a two-field form, and take back any single change you made by hand. And your own agent (Claude Code, Codex, any MCP client) can do the same work through the built-in MCP server.
## Why it's different
| 🛡️ Live only with your yes | 📦 Nothing to set up | 🧩 More than a website | 🌐 Pages you own |
| --- | --- | --- | --- |
| Content, pages, server functions, settings and admin screens are all drafts. You see every change, old against new, and uncheck what you don't want. Every release is kept and can be put back. | One executable serves the site, the admin, the chat, member accounts and the API. Data is one SQLite file, or Postgres. Back the whole site up as one zip. | One environment holds many surfaces: a screen for each kind of user, each with its own rule for who may enter, over shared data. The back end is sandboxed functions, and a mini program or an app uses the same API. | HTML, CSS and JavaScript, with templates, JSX and TypeScript, React or Vue from an import map, and no bundler. Or export everything as static files. |
## How it compares
| | Where it runs | What the AI changes | After hand-over, who changes it |
| --- | --- | --- | --- |
| Lovable, Base44 | The vendor's cloud (code can be exported; the editor and AI can't be self-hosted) | The whole app's code | Outside their editor, a developer editing code |
| NocoBase | Your server | Data and data models; screens are assembled in a no-code editor | The owner, in the editor |
| Directus, Strapi, WordPress | Your server | Content and data (AI assistant, MCP) | A developer, for the site and the admin themselves |
| PocketBase | Your server, one file | No AI; you write the front end | A developer |
| **CMS Harness** | **Your server, one file** | **Pages, server functions, data, and the admin screens themselves** | **The owner, by asking; nothing goes live without their yes** |
If all you need is internal forms and approval flows, NocoBase is more mature (plugins, workflows) and worth a look first.
## 🚀 Quick start
```sh
curl -O https://raw.githubusercontent.com/Michaelzhao9/cms-harness/main/docker-compose.yml
docker compose up -d
docker compose exec cms-harness cms-harness admin you@example.com # prints the admin password once; the first admin is the top account
```
Sign in at `http://localhost:4200/admin`. The site is at `http://localhost:4200/`.
Then open **Settings → Chat model**, pick a service, paste a key and press **Detect**. Or pick **ChatGPT** and press **Continue with ChatGPT** to run the chat on your own ChatGPT plan, with no key. That's it: start talking.
<details>
<summary><b>No Docker? Download a binary or build from source</b></summary>
<br>
Download a binary for Linux (x86_64, arm64), macOS (Apple Silicon) or Windows from [Releases](https://github.com/Michaelzhao9/cms-harness/releases), or build it (Rust 1.98 or newer):
```sh
git clone https://github.com/Michaelzhao9/cms-harness.git
cd cms-harness
cargo build --release
./target/release/cms-harness admin you@example.com # creates an admin and prints its password once
./target/release/cms-harness # serves on 127.0.0.1:4200
```
Sign in at `http://127.0.0.1:4200/admin`.
</details>
<details>
<summary><b>Putting it on a real domain</b></summary>
<br>
Set `HC_ORIGIN` to the public address exactly as the browser shows it (`https://example.com`); in `docker-compose.yml` that is the `HC_ORIGIN` line. Then either:
- **HTTPS by the program itself** 🆕: point the domain at the server and start it with `HC_TLS=auto`. It listens on 443 and 80 by itself and gets a certificate from Let's Encrypt the first time each of its names is visited, then renews it on its own. Only the environment's own names get one: the site, `www.` before it, the admin's own address, each surface's subdomain and the languages' domains. Port 80 answers Let's Encrypt and sends everything else to https. Ports below 1024 need the right to bind them (`setcap cap_net_bind_service=+ep` on Linux; Docker allows it).
- **Or a reverse proxy** (Caddy, nginx) in front for HTTPS. The binary on its own then only listens on the local address.
**Each surface on its own subdomain** 🆕: add one DNS record, `*.example.com` pointing at the server, and choose it in **Settings → Surface addresses** (or set `HC_END_SUBDOMAINS=1`). Saving checks the record first. From then on every surface answers at its own name: `teacher.example.com`, and any made later too, with no more setup. Old `/teacher/…` addresses lead there; a page a surface does not have (a link to `/about` in its pages) is the site's; a member who logs in once is logged in on every surface. Behind a reverse proxy, send `*.example.com` to the program as well.
The chat model can come from the environment instead of Settings: `LLM_PROVIDER` (`anthropic` or `openai`), `LLM_API_KEY`, `LLM_MODEL` and `LLM_BASE_URL`. Without a model, the admin and the API still work, but there is no chat.
</details>
## ✨ What you get
> 🆕 marks what is new in 0.4 and 0.5.
### Build with AI, safely
- 🤖 **AI that builds, people who say yes.** 🆕 When the assistant has made its changes it asks to publish: every check of a real publish runs first, then a request card appears in the chat, and it goes live when you say yes. If you said "publish when done" in the conversation, it publishes directly for the rest of that conversation: it quotes your words, and the environment checks you typed them. You can also agree once for all your own conversations (**Settings → Publish directly when the chat is done**). Either way only what the assistant changed in that conversation goes live, each direct publish can be taken back from its card, and once a conversation has read text from outside (a web page, what visitors or members wrote) it goes back to asking you. It treats text in records, pages and uploads as data, never as instructions, and words there that claim to be yours do not count.
- ⏰ **Things done at set times.** 🆕 "Every morning at 8, sum up yesterday's orders as a notice": the assistant does it by itself, then waits for your yes, or publishes on the words you set it with. Each run can be opened on the **Environment** page.
- 📝 **Drafts everywhere.** Content, collections, pages, admin screens and settings are drafts until published. The live site always shows the published version, whoever visits. Compare draft and live side by side.
- 🗂️ **Admin screens that follow the site.** When the site gains a form, members or orders, the assistant builds the screen to manage them in the same turn. The sidebar reads like folders 🆕: each surface is a folder that opens to the content its pages use, with the site's own sections as smaller folders inside it; content two surfaces use shows under both. What no surface uses yet is listed last, under *Not used yet*, with one button that asks the chat to put it on the site.
- 🔍 **It checks its own work.** The assistant renders a draft page with `check_page` and reads what comes back: render errors, dead links, missing files, photos put on the page whole. It tries a function with `run_function`, which writes nothing. On a long job it keeps a task list, and it stops when it finds itself repeating the same step.
- 🧠 **Any model.** Claude, OpenAI, Gemini, DeepSeek, Qwen, Kimi, GLM, Doubao, SiliconFlow, Mistral, xAI, Groq, OpenRouter, a local Ollama or LM Studio, or any OpenAI-compatible API. Paste a key and it lists the models you can use. 🆕 Or no key at all: **sign in with your ChatGPT account** and the chat runs on the usage your ChatGPT plan already includes, through OpenAI's sign-in for open-source apps. On your own computer the sign-in comes back by itself; for a server elsewhere you paste the address the browser stops at. The sign-in is kept in `<HC_DATA>/chatgpt.json`, readable by the server's user only, never in the database or a backup. 🆕 A Claude subscription works too, through **the Claude Code installed on the server**: sign in there once with `claude auth login` (Anthropic's own sign-in; on a server with no browser, `claude setup-token` and `CLAUDE_CODE_OAUTH_TOKEN`), pick **Claude (the Claude Code signed in on this server)**, and the chat runs through that program on your plan's limits, with the environment's own prompt and tools. The environment never signs you in to Claude itself and never sees the token: Anthropic's terms do not allow another app to do that.
- 📎 🆕 **Hand it files.** Pictures, PDFs, Word, Excel, PowerPoint, text files and zips: drag them into the chat, paste them or pick them. A picture shows at once and fills in as it uploads, and each file gets a card. "Build a products table from this price list", "put this picture on the home page": it reads what is inside. A PDF goes to a model that reads PDFs as it is, and otherwise the text is taken out of it, as it is out of Word, Excel and PowerPoint files, text files and zip archives. What cannot be read is said so, to you and to the model.
- 🔌 **Your agent, too.** A built-in MCP server and a REST API with 59 tools and scoped keys (`read`, `write`, `structure`, `publish`).
- 💬 🆕 **Run it from a chat app.** WeChat, Telegram, Feishu, DingTalk, WeCom, Slack, Discord, WhatsApp, LINE and QQ can all be connected. Go to Settings → Chat apps, or just tell the assistant "connect my WeChat": WeChat is a QR code you scan (WeChat's own interface for bots; what gets connected is a separate bot, not your WeChat account); Telegram is the token @BotFather gives you, pasted into a card, then a pairing code to scan; for the others the page lists the steps to take in that platform's console and the values to fill in, and once saved gives you an address (to paste back there) and a pairing code (to send the bot there). From then on a message sent there is the same as one typed into the chat in the back office; publishing still waits for your yes, by a reply or a button. Only the one person who connected is listened to, and nothing said in a group is. WeChat and Telegram also take pictures and files; the others read text only for now. Everything goes through each platform's official interface; all are tested against stand-ins, and **none has yet been connected end to end by a person** (what was checked against the real services: WeChat hands out a QR code, and the others refuse made-up credentials); tell us what you find.
- 🌍 **Web search for the chat (off by default).** `web_search` and `fetch_page` through a self-hosted SearXNG, Brave or Tavily, with any model. Pages come back as material, never instructions, and private or local addresses are refused at every redirect.
- 📚 **Skills.** Install a skill folder (with a `SKILL.md`) from GitHub or a zip. The chat reads it when the task needs it.
### More than a website: one environment, many surfaces <sup>new in 0.3</sup>
- 🧩 **A surface for each kind of user.** The site is the first surface. When students and teachers, or customers and staff, need different screens, the assistant builds a surface for each (`/teacher/`, `/student/`; or, with one switch in **Settings**, each on its own subdomain: `teacher.example.com`) 🆕, with its own pages and its own rule for who may enter, over data the whole environment shares. The rule can be "members", or a condition such as `member.kind == 'teacher'`. The system guards the door, so pages never check for themselves. The admin lists every surface, and **Environment** shows them all with the data they share.
- 📦 **Bring in a project you already have.** 🆕 Already have a website or web app? Upload its zip on the **Environment** page (or have your agent call `wrap_project`). The built output goes into a surface, addresses written from the root move under the surface's own address, calls to its old back end are pointed at the surface's functions, and script written into pages moves into files. What cannot come in (sources, server code, unknown files) is listed instead of refusing the lot; so are scripts, data and notes no page reaches (server.js, package.json, README.md beside the pages), which never reach browsers. Then it checks the fit by itself (`check_end`): which back-end address or form no function answers yet, what comes from another site, which file is missing, each with where it is and how to mend it, and the assistant mends until the check passes. The old server code does not run here: what it did is rebuilt with functions and collections.
- ⚙️ **It writes the back end too.** What page scripts and rules cannot do (taking stock as an order is placed, totals, permissions that need several tables), the assistant writes as a server function: `_fn/order.js` answers at `/_fn/order`. A function runs in a sandbox with no files, no network but the services a builder registered, and caps on time and memory. One run is one transaction: if it fails, nothing it wrote is kept. Functions share code by importing each other's files, check the signature of a call from another service, and can be called by the environment itself on a timer (release unpaid stock, close the month). Like every site file a function is a draft until published, and it can be tried first.
- 👥 **Members, attributes and access rules.** Sign-up and login for visitors, kept apart from admin accounts. A member can carry attributes you define (`kind: teacher`, `class: 3`); the system gives them no meaning. Each collection has a rule for reading, adding, changing and removing: a word (public, members, each member their own, private) or a condition such as `record.owner == member.id or member.kind == 'teacher'`. A read rule also filters the lists and totals each person sees, and the same rule decides who finds a record on its own page, in site search and through a relation. 🆕 A rule can also look past the record in hand: whether a membership exists, a related record's field, today's date. Members upload files of their own, opened only by who may see them.
- 📱 **One back end for mini programs and apps.** The content API reads, submits, changes and removes under the same rules. A client without cookies logs in with a token. Functions under `_fn` are its own endpoints.
- 📡 **Pages that follow the data.** 🆕 A chat, a board, a list several people edit: a page asks what changed since it last looked (`/changes?after=…`) or keeps a stream open, and gets each change once, under the same read rule as its lists. Every record has a version, and a change made on an old one is refused (409) instead of overwriting someone else's.
- 🔔 **Word reaches your group.** 🆕 In **Settings → Notifications**, paste the address of a group robot or a push service: Feishu (Lark), WeCom, DingTalk, Slack, Discord, Telegram, Teams, Google Chat, Bark, ntfy, ServerChan or PushPlus (which one is read from the address), or an address of your own. A message goes out when someone submits something, changes are published or a member signs up, and a function sends its own with `notify("…")`. Only a builder says where messages go: neither the chat nor an API key can add a destination.
- 🔑 **Other services, with their keys held back.** 🆕 In **Settings → Outside services** a builder registers a payment, text-message, map or AI service: its address and its key, and for one that signs (Alipay, WeChat Pay) the private key to sign with and the platform's public key. Functions call it by name with `services.call("sms", "/send", {json})`: the server puts the key on the request itself, sends it only under that address, and takes the key out of whatever comes back. A key is kept encrypted and never shown again, to the builder, the assistant or a script; `services.sign`, `services.verify` and `services.hmac` sign and check with it where it is.
- 🛡️ **Protection built in, nothing to set.** 🆕 Every page and endpoint built in the environment is behind one door: rate limits by address and by network, vulnerability scanners shut out, no pages for AI crawlers and scripting tools (search engines still pass), an in-browser check for clients that read page after page (harder each time for one that keeps going), a cap on how many records the public API hands one client a minute, a hidden link only crawlers follow, and deadlines for slow connections, with no outside service. 🆕 Requests shaped like an attack (injection strings, ways out of the folder) are refused and a client that keeps sending them is shut out, as is one that asks for one missing address after another; when pages are asked for far faster than usual, every visitor who has not passed the in-browser check gets it for a few minutes, so a flood of clients that run no script gets a tiny page instead of the site; an IPv6 visitor is counted as their /64; and the admin's own addresses are counted too (slowed, never shut out). It has no page and no switch in the admin: it is always on, at the level the code sets (`src/shield.rs`), and neither the chat, an API key nor an admin account can change it.
### Edit by hand, right on the page <sup>new in 0.2</sup>
- ✏️ **Click anything in the preview to change it.** A small bar sets size, weight, colours, alignment, corners, shadow and padding. Double-click to retype text.
- 🖱️ **Drag, resize, copy, delete.** Elements snap to the edges and centres of their neighbours. Arrow keys nudge, Cmd/Ctrl+Z undoes.
- 🖊️ **A pen that adds things where you click.** Text, rectangles, circles, lines, buttons and uploaded images.
- 📱 **Per-width edits.** Change something for desktop, tablet or phone only, and reset a width back to what desktop shows.
- ⚠️ **It warns, it doesn't guess.** Hand-edited elements that end up off screen, on top of other content or with text under 12 px are counted in the toolbar, with a jump to each.
- 🤝 **The AI knows what you did.** It sees your hand edits and carries them through its rewrites. A rewrite that would lose one is refused until you agree.
- 🧾 **Every hand edit is listed, and undone on its own.** 🆕 The pencil in the toolbar counts what you changed by hand since the last publish. Open it to read each change in words (which element, old against new), click one to see it on the page, and undo any single one, days later too, not just the last with Cmd/Ctrl+Z. Hand edits are marked on the draft like the assistant's changes.
- 🧭 **Navigation as a list.** 🆕 **Navigation** in the toolbar shows the site's menu as lines of a name and where it goes: rename, point elsewhere, move up or down, remove, add one.
- ➕ **A new page from two fields.** 🆕 A title and an address: the page is made with the home page's layout, and linked in the navigation if you tick the box. Links and buttons can be pointed elsewhere, and elements moved before or after their neighbours.
- 🗂️ **Surfaces and content without the chat.** 🆕 On the **Environment** page, a new surface is a name, an address and who may enter; a new kind of content is a name and its fields, like the columns of a spreadsheet. The names programs need are made for you. Whatever the chat can do through its tools can also be done from a plain form per tool (**Advanced**, for those who know them).
Hand edits are drafts too, like everything else.
### A real website
- 🔗 **A page for every record, automatically.** Write one detail template and every record of a collection gets its own page at a clean address (`/news/drum-contest`; Chinese titles stay Chinese). Change a slug or a category and the old address redirects forever. Links in text point at the record, not the address, so they never break, and a publish that would leave a dead link is stopped.
- 🌏 **Any number of languages.** One record, many languages: text is translated; images, dates and prices are shared. Each language gets its own addresses (`/en/…` or its own domain), fallbacks, hreflang, and localized dates and money. Out-of-date translations are flagged, and the chat can keep every language in sync as drafts.
- ⚡ **Dynamic, at static speed.** Live pages are cached, and a publish recomputes exactly the pages it touched. `cms-harness export` writes the whole site as static files for any CDN. 🆕 Pages and API reads have database connections of their own and do not wait for writes, and publishing 20,000 records takes about half a second on SQLite and five seconds on Postgres.
- 🧩 **Your stack, no build step.** HTML with `{{ }}` templates, plus CSS, JavaScript, JSX and TypeScript transpiled on the fly. React, Vue or Three.js load through an import map. You can also upload a site built with Vite.
- 🖼️ **Photos need no preparing.** An uploaded photo is stored upright, without where and when it was taken, with its long edge at 2560 at most, and compressed (a 7 MB photo is kept at about 0.5 MB). A photo saved as a PNG becomes a JPEG; pictures you can see through and small ones are kept as they are. In a page, `{{ img(item.cover, alt=item.title) }}` writes the whole tag: smaller copies at every width, its size, lazy loading. `{{ item.cover|thumb(640) }}` gives just an address. A picture attached in the chat reaches the model as a small copy and is kept in the media library, so the assistant can put it on a page.
- 🔎 **Full-text search.** `search("query")` in a page, `GET /api/v1/search` and a `search` tool. Chinese works without a dictionary, and visitors only ever find what they may open.
### Manage it and run it
- 👑 🆕 **A top account, and admins with surfaces of their own.** The account that made the environment is the top account; it appoints the other admins and decides who manages the whole environment and who manages only some surfaces. An admin with surfaces of their own has, in the back office, only those surfaces and the content they use, and can change and publish records; the other surfaces and the environment's settings are not shown to them, and they are not told those exist. Their assistant in the chat is held to the same.
- 🗂️ **Manage any data directly.** Every collection's list can be searched (text anywhere in a record, drafts too), exported as CSV, and filled from a CSV whose rows arrive as drafts. Every row is checked before anything comes in: one that does not fit and nothing does. In an export, text a spreadsheet would run as a formula is defused. 🆕 Or just tell the chat: *"mark every order waiting to ship as shipped"*, *"take 10% off every price"*. The assistant picks the records by any field, changes them as one batch of drafts (the same values, or worked out per record by a small script), tells you how many and shows a few before and after, and you approve the batch with one click. A release that went wrong is undone in one step. Publishing never puts a draft over a field the site changed after it (an order a customer cancelled meanwhile): it stops and names the record.
- ⏰ **Scheduled publishing.** Pick a time on the review page. It goes through the same checks and history as a normal publish.
- 💾 **Backup and restore.** The whole site (database and uploads) as one zip, from **Settings → Backup** or `cms-harness backup`. A restore checks the archive and saves the current site first. In the back office, backing up and restoring are the top account's alone 🆕: a backup is the whole environment, every admin's account included.
- 🗄️ **SQLite or Postgres.** 🆕 One file by default. Set `HC_DATABASE_URL` and the whole environment is on Postgres: the first start moves everything across by itself, and `cms-harness convert` brings it back. A backup made on one restores into the other. Connections use TLS as `sslmode` in the address says.
- 🗺️ **SEO basics, done.** `sitemap.xml` and `robots.txt` follow every publish, in every language.
- 🈶 **Chinese and English.** The admin switches in Settings, and the chat replies in the admin's language.
<table>
<tr>
<td width="50%"><img src="docs/images/workbench-en.webp" alt="The admin: the chat on the left has built a homework system and lists every change, the preview on the right shows a home page with two doors, and the Publish button shows 13 pending changes."></td>
<td width="50%"><img src="docs/images/publish-en.webp" alt="Publish review: every pending change, each with its own checkbox."></td>
</tr>
<tr>
<td align="center"><sub>Chat on the left, the draft on the right, changes marked.</sub></td>
<td align="center"><sub>Review before publishing: every change, and you uncheck what you don't want.</sub></td>
</tr>
<tr>
<td width="50%"><img src="docs/images/environment-en.webp" alt="The environment page: the site, the student surface and the teacher surface, who may enter each, and the data they share."></td>
<td width="50%"><img src="docs/images/built-en.webp" alt="The live home page that was built: a door for students and a door for teachers."></td>
</tr>
<tr>
<td align="center"><sub>Every surface in one environment, and the data they share.</sub></td>
<td align="center"><sub>The live home page after one request: a door for each.</sub></td>
</tr>
</table>
## 🔌 Connect your agent
Create a key with `cms-harness key <name> [write] [structure] [publish]`, then add the server to any MCP client that speaks HTTP:
```json
{
"mcpServers": {
"cms-harness": {
"type": "http",
"url": "http://127.0.0.1:4200/mcp",
"headers": { "Authorization": "Bearer hc_..." }
}
}
}
```
Leave `publish` off the key and your agent can build all day while the live site stays exactly as it is.
Or use REST: `GET /api/v1/tools` lists the tools this key can call with their parameters. `POST /api/v1/tools/<name>` calls one.
## 🔧 Under the hood
- About 31,000 lines of Rust: [axum](https://github.com/tokio-rs/axum), SQLite (bundled, with full-text search), [minijinja](https://github.com/mitsuhiko/minijinja) for templates, [oxc](https://oxc.rs) to transpile JSX and TypeScript, and [QuickJS](https://bellard.org/quickjs/) (through [rquickjs](https://github.com/DelSkayn/rquickjs)) to run server functions.
- More than 750 tests, run with clippy on every push to main; the same suite passes on Postgres.
- Answers are gzipped for a client that takes them.
- The admin is server-rendered HTML with plain JavaScript and a strict Content-Security-Policy. There is no front-end build.
- Passwords are hashed with Argon2id. The details are in [SECURITY.md](SECURITY.md).
## 📖 Reference
<details>
<summary><b>Command line</b></summary>
| Command | What it does |
| --- | --- |
| `cms-harness` | start the server |
| `cms-harness admin <email> [builder\|editor]` | create an admin, or reset their password. The first admin an environment gets is its top account |
| `cms-harness key <name> [write] [structure] [publish]` | create an API key (shown once) |
| `cms-harness admin-origin <address\|off>` | give the admin its own address; `off` puts it back with the site |
| `cms-harness backup [file.zip]` | the whole site (database and uploads) as one zip |
| `cms-harness restore <file.zip>` | replace the site with a backup (stop the server first) |
| `cms-harness export <dir>` | write the live site as static files (set `HC_ORIGIN` to where they will be served) |
| `cms-harness convert <source> [--replace]` | copy everything from another database (`postgres://…` or a SQLite file) into the one in use |
Builders manage structure, keys, the model, skills, where notifications go and which outside services functions may call. Editors write and publish content.
🆕 **The top account, and admins with surfaces of their own.** The account that made the environment is the top account: only it adds, resets and removes admins, and only it can give an admin the surfaces they manage. An admin who was given surfaces sees, in the back office, only those surfaces and the content their pages use, and can change and publish records; the other surfaces, the other content and the environment's settings are not shown to them, and they are not told those exist (asked about something outside, the answer is word for word the one for something that is not there). They cannot change pages, structure or code, whatever their role: whoever can write a page template or a server function can read all the data, and the division would mean nothing. Their assistant in the chat is held to the same. An admin who was given no surfaces manages the whole environment, as before.
</details>
<details>
<summary><b>The database: SQLite or Postgres</b></summary>
The database is a choice for the whole environment, made when the server starts. Everything in the environment (every surface, the admin, the API, backups) is on the one that was chosen.
- **SQLite** (the default): nothing to set. The database is one file, `<HC_DATA>/harness.db`. One server uses a data folder: a second one started on it stops and says another is using it. The commands (`backup`, `admin`, `key`, …) work beside a running server.
- **Postgres**: set `HC_DATABASE_URL=postgres://user:password@host:5432/database`. Postgres 14 or newer. The database must exist; the tables are made on the first start.
- **TLS to Postgres**: add `sslmode` to the address, as libpq reads it. `?sslmode=verify-full` encrypts and checks that the server's certificate is signed by someone trusted and carries the host name in the address; `verify-ca` checks the signature but not the name; `require` encrypts without checking; `prefer` encrypts when the server can, else goes on in plain; `disable` is plain. Without `sslmode` the connection is plain, as before: keep the server and Postgres on one machine or one private network then. The certificate is checked against the roots browsers trust (built in), or against your own CA with `&sslrootcert=/path/ca.crt` (then `require` checks the signature too, as libpq does); a certificate that signs itself can be given there as it is. The name must be in the certificate's subjectAltName, as browsers require; a name only in its CN is not read. Every connection (the writer, the readers, conversion, backup) is opened the same way.
**Changing over is the environment's own job.** Start the server with `HC_DATABASE_URL` pointing at an empty Postgres database while the data folder still holds the SQLite file, and it copies everything across before it serves: content, drafts, history, accounts, sessions, settings. It says on stderr what it is doing, how many rows went, and how long it took. The search index is made again, row counts are compared table by table, and it all happens in one transaction: if anything fails, Postgres is left empty, the SQLite file is untouched, and the server stops and says why. Afterwards the SQLite file is kept as `harness.before-postgres-<time>.db`, which nothing opens again. Any command does this, not only the server, so `cms-harness admin` on a new Postgres does not start a second, empty site. Uploads stay where they are, in the data folder. Once it has moved, starting without `HC_DATABASE_URL` does not open an empty site: the server stops and says the environment is on Postgres now.
A Postgres database that already holds something is never filled this way: the server uses it, and says on stderr that the SQLite file beside it is not in use. To put a database's contents somewhere explicitly, in either direction:
```bash
# back to SQLite: unset HC_DATABASE_URL, then
cms-harness convert postgres://user:password@host:5432/database
# or into the database in use, from a SQLite file or another Postgres
cms-harness convert /path/to/harness.db
```
`convert` copies into the database the environment is set to use. That database must be empty; with `--replace` it is saved to `<HC_DATA>/backups/` first and then replaced. The source is neither emptied nor renamed. Stop the server first, and copy the `uploads` folder yourself when the source belongs to another data folder.
**Backups are the same on both.** A backup is always a zip holding a SQLite file and the uploads, so one made on SQLite restores into Postgres and the other way round.
**What a record costs.** A live record is stored as its document and, unless its collection sets `history: false` or `search: false`, also as a version in history and an entry in the full-text index. Small records written one at a time came to about 1.4 KB each on SQLite. Deleting records does not make a SQLite file smaller: SQLite keeps the space for what is written next, and history keeps what was deleted.
**What still differs.** Search finds the same records on both, but ranks them differently (BM25 on SQLite, how often the words appear on Postgres). Postgres cannot store text with a NUL character in it. On Postgres a backup and a restore copy every row instead of copying one file, so they take longer and hold the largest table in memory. Pages and API reads have database connections of their own on both (`HC_READERS`) and do not wait for a write; writes, function runs among them, take turns on one connection. A SQLite file has one writer at a time, and a write waits up to 5 seconds for another process that is writing to it; on Postgres a write waits for the rows another transaction holds, and two servers on one database are not kept from reading a record before each changes it. Function runs on servers sharing one Postgres database take turns, as they do on one server: a run waits for another's to end before its 500 ms start. **Settings → Database** shows which one the environment is on.
</details>
<details>
<summary><b>Website pages</b></summary>
A fresh site has one built-in page: a welcome with the site's name and a link to the admin. Every other page comes from **site files** that the assistant (or your agent) writes:
- HTML with templates: `collection("news", limit=10, sort="-date")`, `count("news", filter={...})` for page numbers (`collection()` returns at most 100 at a time), `record("news", 3)`, `search(request.query.q, limit=20)` (each hit has `_collection` and `_snippet`), `img(item.cover, alt=item.title)` for a whole image tag, the signed-in `member` (with its attributes), `site.name`.
- CSS, JavaScript, and JSX / TypeScript / TSX, which are transpiled when served.
- Libraries from `https://esm.sh` through an import map (`set_site_settings`), so no bundler is needed. A site built elsewhere can be uploaded in one piece (`upload_site_bundle`), or brought into a surface together with the calls to its back end (`wrap_project`, above).
The live site always shows the published version, whatever cookies or headers a visitor sends. Drafts only appear in the admin's preview.
**Record pages.** A collection visitors may read gets a page per record once the site has a detail template: `<collection>/_item.html`, or `_item.html` for every collection. The template reads the record as `item`. Addresses come from the collection's `url` pattern, `/{collection}/{slug}` by default; `{id}`, a field (`{year}`) or a relation's slug (`/products/{category.slug}/{slug}`) work too. Each record gets its slug from its title when it is created and keeps it when the title changes. A new slug is a draft; once live, the old address keeps redirecting. Link to records with `item.url` (or `/_r/<id>`): links pasted into rich text are stored that way automatically and always render at the record's current address.
**Languages.** Set the site's languages in **Settings → Site languages** (or `set_site_settings` with `languages`); the first is the default. Other languages live under `/<code>/` or on their own domain, and may fall back to others. Text and rich text fields are translated (`translate: false` keeps one shared); a collection with `untranslated: "hide"` leaves untranslated records out of other languages. Translations are written with `set_translation` or in the record editor, kept in the record as drafts, and `translation_status` lists what is missing or out of date. Templates get `lang`, `dir`, `languages` (this page in every language, for a switcher) and `suggested_lang`; `{{ "…"|t }}` reads the site's string table; `|date`, `|number` and `|money("EUR")` format per language. A link a template writes as `/about` leads to `/en/about` on an English page. hreflang links and a multilingual sitemap are added for you.
**Images.** An uploaded JPEG, PNG or WebP is worked on before it is stored: turned upright by its EXIF and stored without it (place, time, device), shrunk when its long edge is over 2560, and a JPEG compressed again (when that saves a fifth, or when it has to be re-made anyway). A large PNG with no transparency becomes a JPEG when that is under two fifths of its size. See-through pictures, small PNGs, GIFs and PDFs are kept as they came. `/uploads/<name>?w=640` serves a copy no wider than one of five widths (384, 640, 828, 1200, 1920), made once and kept; PNG stays PNG, JPEG and WebP become JPEG, and nothing is enlarged. In a template, `{{ img(item.cover, alt=item.title, sizes="50vw", class="cover") }}` writes the whole `<img>`: every width below the picture's own in `srcset`, its real size, and `loading="lazy"`; give the first picture a visitor sees `eager=true`. Where only an address is needed, use `|thumb(640)`.
**Cache and export.** Live pages for visitors who are not signed in are cached until something they read is published again (the `x-cms-cache` header says hit or miss). `cms-harness export <dir>` writes every public page, record pages included, plus site files, uploads, `sitemap.xml`, `robots.txt` and `404.html`; set `HC_ORIGIN` to the address the files will be served from. Forms and sign-in still need the server; the command lists the pages that use them.
`/sitemap.xml` lists the published pages (not layouts or fragments that other files extend or include, nor names starting with `_`), each with the date it last went live, and `/robots.txt` points to it. Both follow every publish. A site file with the same name replaces them.
</details>
<details>
<summary><b>Editing by hand</b></summary>
In the draft preview, select an element with a click on something that does nothing, a long press or a right-click. The bar above it sets size, weight, slant, underline, colours, alignment, a style preset, corners, shadow and padding, for all widths or only the current one. It also duplicates, deletes, moves the element a layer up or down, and hides it at this width. A double-click edits text written in the template.
- **Move and resize.** Drag an element to move it and pull its handles to resize it. Both snap to nearby elements; hold Alt to turn snapping off. Arrow keys nudge by 1 px, Shift+arrow by 10 px. Cmd/Ctrl+Z and Shift+Cmd/Ctrl+Z undo and redo. Delete removes the element and Cmd/Ctrl+D duplicates it.
- **The pen** (bottom right of the preview) adds text, a rectangle, a circle, a line, a button or an uploaded image where you next click. A selected image can be replaced.
- **Shared elements.** An element in a template other pages use is marked *Shared · N pages*. Its edits can be limited to the current page.
- **Widths.** Edits are saved for the width being looked at. The desktop preview is never narrower than 1024 px; a narrower pane shows it scaled down.
- **With the AI.** `get_site_file` returns `hand_edits`, and file rewrites carry them along. A rewrite that would lose one is refused unless it passes `replace_hand_edits: true`.
Properties and values come from fixed lists, typed text is escaped so it can never become template code, and only uploaded files go into templates.
</details>
<details>
<summary><b>Server functions</b></summary>
A site file under a `_fn` folder (`.js` or `.ts`) is a server function. Its address is its path without the extension: `_fn/order.js` is `/_fn/order`, `teacher/_fn/grade.js` is `/teacher/_fn/grade`. Inside a surface's folder it belongs to that surface: a members-only surface only lets members call its functions. The source is never sent as a file.
```js
export default function (req) {
// req.method, req.path, req.query, req.body, req.member (null for a visitor),
// req.headers, req.raw, req.ip, req.timer
const mine = db.query("orders", { owner: req.member.id, limit: 100 });
if (mine.total >= 3) return reply(409, { error: "three orders at most" });
const id = db.create("orders", { item: req.body.item });
return { id };
}
```
- Data: `db.query(collection, {filter, sort, limit, offset, search, owner})`, `db.get(collection, id)`, `db.create(collection, data)` (a third argument `{owner: memberId}` makes the records that member's, as if they had added them), `db.update(collection, id, data)` (a fourth argument `{version}`, the `_version` read, makes it fail instead of overwriting a change made since), `db.delete(collection, id)`. Given a list, `db.create` writes many records at once (up to 500, one data call, all of them or none) and answers the list of their ids. The writing still counts against the run's half second, but 500 take only some tens of milliseconds on Postgres and a few on SQLite, so a run fits a few thousand. `db.query` answers `{items, total, more}`; with `total: false` it does not count and answers `{items, more}`, which on a large collection is much faster. They read and write live data. A write is live at once, passes the same field checks as any other, and is recorded in history under `fn:<file>`. A function is not bound by a collection's access rules: it decides who may do what.
- Members: `members.get(id)` answers that member's `id`, `email`, `name` and attributes; `members.set(id, {kind: "teacher"})` sets attributes (a `null` removes one). Who a member is (email, name, password) a function cannot change. Where accounts are handed out and visitors do not sign up (a company's staff screen) there is also `members.create({email, password, name, every other key an attribute})` to make an account (a password of 6 characters or more; sign-up's ten an hour does not apply; nobody is signed in by it), `members.setPassword(id, password)` for someone who forgot theirs (wherever they were signed in ends), and `members.setStatus(id, "disabled" or "active")` to turn an account off and on again (off: they cannot log in and `members.get` does not find them). Who may make a function do this is still the function's to decide.
- Totals: `db.aggregate(collection, {filter, group_by, sum, avg, min, max})`. Grouped, one answer lists 100 groups (`group_limit` up to 1000); `group_total` says how many there are, and `group_offset` asks for the next ones.
- Notifications: `notify("low stock: " + item)` goes to the groups set in **Settings → Notifications**, five a run at most. A run that does not count (it failed, or it was a trial) sends nothing.
- Answer: the return value, as JSON. For another status, `reply(status, body)`.
- Shared code: a file under `_fn` whose name, or a folder above it inside `_fn`, starts with `_` (`_fn/_lib.js`, `shop/_fn/_shared/money.js`) is a module. It has no address; function files import it: `import { yuan } from "./_lib.js"`. Imports are relative, with the extension, and only reach `.js`, `.mjs` and `.ts` files under a `_fn` folder (any surface's). A function brings in at most 30 files and 1 MB. Writing a function whose import is missing is refused, and it cannot be published without what it imports.
- Outside services: `services.call(name, path, {method, query, headers, json | form | body})` sends one request to a service registered in **Settings → Outside services** and answers `{status, ok, headers, text, body}` (`body` is the answer read as JSON). The path goes under the registered address and nowhere else; the key goes on as the service was registered (`Authorization: Bearer`, a header, an address parameter or Basic) and is taken out of the answer; redirects are not followed; 10 seconds and 1 MB at most, 5 calls a run, each in `function_log`. Waiting for the answer is not on the run's half second, and the run waits on a read-only connection, not holding up anyone's writes: so a run calls its services first and writes after, and once it has written it cannot call one. `services.hmac(name, text, {hash, encoding, prefix, suffix, chain})` signs with the service's key (Alibaba Cloud's `key&`, AWS SigV4 and Tencent TC3's derived keys through `prefix` and `chain`), `services.sign(name, text)` makes an RSA signature with its private key (SHA256withRSA, base64; `{padding: "pss"}`), `services.verify(name, text, signature)` checks one made with the platform's public key (a key, or a certificate). A trial run sends nothing and signs nothing for real: `services.call` answers `{status: 0, trial: true}` and `hmac`/`sign` a stand-in, so a draft reaches nothing outside; try the real thing once it is published. At most half the read-only connections wait for services at once; a call beyond that fails at once as busy.
- `crypto`: `crypto.randomUUID()`, `crypto.random(n)` (n random bytes as hex, 1 to 64), `crypto.sha256(text)`, `crypto.hmac(key, text)` (HMAC-SHA256 as hex), `crypto.equal(a, b)` (compares two strings in constant time). Codes and tokens must come from `crypto.random`, not `Math.random`.
- The request as it was sent: `req.headers` (lower-cased names; `cookie`, `authorization` and forwarding headers are left out), `req.raw` (the body as text, exactly as it arrived; `req.body` is the parsed value) and `req.ip`. Enough to verify a webhook: `crypto.equal(req.headers["x-signature"] || "", "sha256=" + crypto.hmac(SECRET, req.raw))`.
- Timers: `set_timer` has the environment call a function by itself, every `every_minutes`, or daily at `at` (`"03:00"`, with `tz_offset_minutes`). The function gets `req.method` `"TIMER"` and `req.timer` `{name, due}`, no member, and is not behind any surface's door; give it a module-style path (`/_fn/_jobs/sweep`) and nothing outside can call it. A long job works in slices: answer `{ again: true }` and it is run again at once, up to 20 times a round. After the server was down a timer that was due runs once. Timers are drafts until published, and the **Environment** page lists them with their last run.
- One run is one transaction: an exception, a cut-off, or an answer of 400 and up, and nothing it wrote is kept.
- Limits: 500 ms (the SQL its data calls run counts; waiting for the writer before the run, or for a service, does not), 32 MB of memory, 200 data calls, a 64 KB request body. No files or processes, no network but `services`, and no `setTimeout`.
- When it fails a visitor sees only that it failed; the reason is in `function_log`.
- `run_function` tries a draft function without writing anything, with `headers` and `raw` when it checks a signature and `timer: true` to call it as a timer would. A page in the admin's preview calling a function (GET) is a trial too.
- A static export does not include functions, and they do not work there.
</details>
<details>
<summary><b>Members and access rules</b></summary>
`set_member_login` turns visitor accounts on. The site then has `/account/signup`, `/account/login` and `/account/logout`, and the `/api/v1/members/*` endpoints. The site's accounts appear as **Members** in the site's Setup folder. Members cannot sign in to the admin. Where every account is handed out, `set_member_signup` closes sign-up by visitors: `/account/signup` and the sign-up call are gone, login stays.
**Each surface has its own accounts.** An account belongs to the surface it was made on, and its name only has to be unique there (the site and a shop may each have an `admin`): it signs in from that surface's pages and is a visitor on any other surface, its pages, functions and content requests alike. Where the very same people use two surfaces (a members' area of the site, students and their parents), `set_end`'s `accounts` lets one take the other's accounts; `signup: true` lets visitors make their own account on a surface. Collections stay shared by every surface, and a rule keeps one to a surface's accounts with `member.end == 'shop'`.
Where the people who use a surface are handed their accounts (a company's staff), give `set_end` the `tags` they can carry (`["sales", "warehouse", "accounts"]`): the admin then has a People page under that surface in the sidebar, after its content (it comes by itself even with no `tags`: whenever the surface keeps a door or its files read who is signed in), where an account is made (an email, or a plain name for someone with no mailbox; a password of 6 characters or more), tags are picked by a click, a password is replaced and an account is turned off. A member's tags are kept in the attribute `tag`, joined by `、`; the surface's functions read `req.member.tag` and decide what each tag may do, and the kernel gives them no meaning. The tools behind it are `create_member`, `set_member_password` and `set_member_tags`.
Under each surface the sidebar keeps a **Setup** folder (配置), after the surface's content and set off by a dashed rule and a gear: what the surface is set up with, as opposed to what it is for. It holds the People page above (named as the surface names it: `people_title`, `tags_title`) and every collection marked `config: true`: one with `single: true` is a sheet of settings (a shop's name, a switch, a threshold) and opens as the form itself; a list (warehouses, categories, delivery areas) is a plain table. Those pages are drawn by the admin from the collection's title and fields, without the tabs, search and CSV of content, a yes/no as a switch and a choice of a few as pills. The assistant is told to decide this itself while it builds: what an owner will want to change later goes into configuration the pages and functions read, not into the files as fixed text. A surface with nothing to set up has no folder.
Each collection sets:
- who can read it (`read`): `public`, `members`, `owner` (each member sees their own), `private` (default: admin and keys only), or a condition such as `record.open == true or record.owner == member.id`. A condition is also the filter of every list: each reader's lists and totals hold only what they may see. Search is not filtered by it: a collection read by a condition is left out of search for every visitor and member (only an API key finds its records), and its records have no pages.
- who can submit to it from the site (`create`): `none` (default), `members`, `public`, or a condition such as `member.kind == 'student' and data.class == member.class`. Submissions go live at once, record who sent them, and show as "N new" in the admin. Forms post to `POST /<collection>/new`; the API takes `POST /api/v1/content/<collection>`.
- a rule may look past the record in hand (in the read, create, update and delete rules and in a surface's door): `exists(memberships, it.member == member.id and it.org == record.org)` is true when a live record of another collection meets the condition, which is how membership is asked; `record.article.dept` follows a single relation field to the record it points at; `now` and `today` are the time and the date (UTC), to compare with a date field; `record.status in ['open', 'pending']`. A rule may look elsewhere at most four times; a page read by the clock is not cached.
- who can change (`update`) and remove (`delete`) a record from the site: `none` (default), `owner` (the member who added it), `members`, or a condition such as `record.owner == member.id and data.status == record.status`. A condition can use `record.<field>`, `record.id`, `record.owner`, `member` (logged in), `member.id`, `member.email`, `member.name`, `data.<field>` (what the record would become), `== != < <= > >=`, `and or not` and brackets. Changes and removals are live at once, and history keeps what the record was. A removal is refused while another live record points at the record or a live page links to it; an edit the admin had waiting for a removed record goes with it. The API takes `PATCH` and `DELETE /api/v1/content/<collection>/<id>`.Every record read carries `_version` (raised by one each time its live copy changes) and `_updated_at` (when it last changed). Send back the `_version` you read with a change (or as `If-Match`), and if someone changed the record meanwhile the answer is 409 instead of overwriting their change; without it, the last write wins as before.
Members can carry attributes (`kind: teacher`, `class: 3`). A builder sets them, in **Members** or with `set_member_data`; a member cannot. The system gives them no meaning: a rule reads `member.kind`, a surface's door can be `member.kind == 'teacher'`, and pages and functions see them too.
Mini programs, phone and desktop apps have no cookies: send `"session": "token"` when logging in or signing up, and the answer carries a token to put in `Authorization: Bearer <token>` from then on. A login answer may also carry `device`: keep it and send it back as `"device"` with the next login, and that login is not held up when many others are guessing at the same email.
`GET /api/v1/members/me` says who is signed in: `{"ok": true, "member": {…}}`. With no cookie or token, or one that has expired or been ended, it still answers 200, with `"member": null`: check `member`, not the status. (While member login is off it answers 404.)
Members look after their own account, from a page's script or an app alike, with their cookie or token: `POST /api/v1/members/logout` ends this session; with `{"everywhere": true}` it ends every one they have (a lost phone, someone else's computer). `POST /api/v1/members/password` with `{"password": the old one, "new_password": …}` changes the password, 10 characters at least; wrong old passwords count with failed logins, and every session but this one ends.
A collection of a great many records nobody goes back to or searches (sensor readings, logs) can set `history: false` (no versions are kept, so none can be restored) and `search: false` (left out of full-text search): each record is then stored once instead of three times (the record, its history, the search index).
A collection can also sit in a `group` (the site's section) with a `position`: the admin nav lists collections in that order, and each group folds.
</details>
<details>
<summary><b>Notifications (webhooks)</b></summary>
In **Settings → Notifications** (builders only), paste a webhook address and tick when to send: someone submitted something, changes were published, a member signed up, `notify()` in a function, a timer failed (said once when it starts failing, not every time it is due). What kind of destination it is, is read from the address:
- Feishu / Lark (`open.feishu.cn`, `open.larksuite.com`): a text message. If the robot has signature checking on, give the secret too.
- WeCom (`qyapi.weixin.qq.com`): a text message.
- DingTalk (`oapi.dingtalk.com`): a text message. If the robot's security setting is "Sign", give the secret too.
- Slack (`hooks.slack.com`), Discord (`discord.com/api/webhooks/…`), Google Chat (`chat.googleapis.com`): a text message.
- Teams: only the address a Workflow gives (`*.api.powerplatform.com`), as a card holding the text. The old Office 365 connector addresses were retired in May 2026.
- Telegram: write the address as `https://api.telegram.org/bot<token>/sendMessage?chat_id=<id>`.
- Bark (`api.day.app/<key>`), ntfy (`ntfy.sh/<topic>`), ServerChan (`sctapi.ftqq.com/<key>.send`), PushPlus (`www.pushplus.plus/send?token=…`): a push to a phone, titled with the site's name.
- None of these has been sent to a real robot yet: the formats follow each service's own documentation.
- Any other address: a `POST` of JSON `{"event", "text", "data", "site", "at"}` with the headers `X-Harness-Event` and `X-Harness-Timestamp`. With a signing secret, `X-Harness-Signature` is `sha256=` followed by the hex of `HMAC-SHA256(secret, "<timestamp>.<body>")`.
A message is first written to the database together with the thing it tells of, then sent in a round every 3 seconds, one message a round for each destination. One that fails is tried again after 1 minute and after 5. Once saved, an address is never shown again, only its host. **Send a test** sends one now and says how it went.
</details>
<details>
<summary><b>Reading content from your own front end</b></summary>
`GET /api/v1/content/<collection>` returns published records and `GET /api/v1/content/<collection>/<id>` returns one, following the collection's `read` rule.
| Parameter | Meaning |
| --- | --- |
| `field=value` | equals |
| `field__ne` `__gt` `__gte` `__lt` `__lte` `__contains` | not equal, greater, at least, less, at most, contains |
| `sort=field`, `sort=-field` | sort, `-` for descending |
| `limit`, `offset` | paging, `limit` from 1 to 100 |
| `total=false` | no count: the answer says only `more` (whether more follow). Much faster on a large collection |
| `expand=field` | replace a relation id with the record |
**Following changes.** A list's answer has a `cursor`. `GET /api/v1/content/<collection>/changes?after=<cursor>` then answers what changed since: `items` are the records that changed, as they are now, each once, in the order of their last change; `removed` the ids of records that went (or no longer match the other parameters, which narrow changes as they narrow a list); `cursor` where to ask from next; `more` whether more wait. `GET /api/v1/content/<collection>/changes/stream` sends the same answers as server-sent events while the connection is open (`new EventSource(…)`): the first at once, then one per change, each with its cursor as the event id, so a browser that reconnects goes on from there; a member who logs out or loses access gets an `error` event and the stream ends. Changes follow the collection's `read` rule as lists do: in an `owner` collection each member sees only their own changes, and in a collection read by a condition `removed` is `null` (saying which records went would say they had been there). Changes are kept for 7 days; a cursor older than that gets 410 and reads the list again. A draft is no change until it is published.
Only fields declared with `index` or `unique` can filter and sort. A collection with many records that is often asked by two or three fields together can declare `indexes` (such as `[["org", "status"], ["org", "due"]]`, at most 5): a list that compares `org` for equality and then filters by `status` or sorts by `due` is read along one, instead of fetching many and sorting them. A field in `indexes` can filter and sort too.
</details>
<details>
<summary><b>Uploads</b></summary>
`POST /api/v1/media` with a multipart field named `file` and a key with `write`, up to 20 MB, or the `upload_media` tool (base64, up to 5 MB). JPEG, PNG, GIF, WebP and PDF are accepted, judged by content rather than extension. Files are stored by content hash at `/uploads/<hash>.<ext>` and cached for a long time; add `?w=640` for a smaller copy of an image. A picture is worked on before it is stored (see Images under Website pages), so the answer carries the stored `width`, `height` and `bytes` beside the `path`. Uploads are public, so do not upload private files.
**Members' files.** A logged-in member uploads with `POST /api/v1/members/upload` (the same multipart field, formats and 20 MB) and gets a path under `/uploads/m/`. That file is theirs: it opens for them, for an admin or a key, and for whoever may read a live record that holds it (a teacher who reads the homework opens its attachment); anyone else is told it is not there, and nothing may cache it. A member can put only their own files into what they submit. Each member keeps 200 MB at most and uploads 100 files a day; a file no live record holds a day after it was uploaded is removed. Backups carry members' files; a static export leaves them out.
</details>
<details>
<summary><b>Tools</b></summary>
| Tool | Permission | What it does |
| --- | --- | --- |
| `list_collections` `get_collection` | read | list collections, read one |
| `create_collection` `update_collection` `delete_collection` | structure | create, change (fields, access, `url` pattern, nav `group` and `position`), delete (records are kept) |
| `get_record` `query_records` `aggregate_records` `search` | read | read records, totals (group, sum, average, min, max), full-text search |
| `create_record` `update_record` `delete_record` | write | write records (and their `slug`) |
| `change_records` | write | change many records at once, chosen by any field: the same values, values a script works out per record, or deletion; one batch of drafts, all or none |
| `list_pending` `list_versions` `list_releases` | read | pending changes, an object's history, the latest releases |
| `publish` | publish | publish |
| `schedule_publish` `cancel_schedule` / `list_schedules` | publish / read | publish at a set time |
| `restore_version` `discard_draft` `undo_release` | write | put a version back as a draft, drop a draft (or a whole batch, `records:<collection>`), undo a whole release |
| `list_views` / `set_view` `delete_view` | read / structure | admin screens |
| `get_site_notes` / `set_site_notes` | read / structure | notes for the assistant |
| `check_page` | read | check a draft page: render errors, dead links, missing files, omissions |
| `run_function` / `function_log` | read | try a draft server function (nothing is written); live runs that failed or logged |
| `list_services` | read | the outside services a builder registered: name, address, how the key goes on, whether it can sign and verify (never a key) |
| `list_timers` / `set_timer` `delete_timer` | read / structure | list timers with their last run; have the environment call a function every so many minutes or daily at a time, stop it |
| `list_routines` / `set_routine` `delete_routine` | read / structure | list routines; have the assistant do something by itself at set times (only an admin sets one, and it runs as them), stop it |
| `list_site_files` `get_site_file` | read | read site files (with their hand edits) |
| `write_site_file` `edit_site_file` `delete_site_file` `upload_site_bundle` | structure | write site files, change one place in a file, upload a built site |
| `wrap_project` / `check_end` | structure / read | bring a project you already have into a surface; check what a surface still lacks to work as it did |
| `get_site_settings` / `set_site_settings` | read / structure | site name, languages, template text, import map, script origins |
| `translation_status` / `set_translation` | read / write | what is missing or out of date; write a translation |
| `set_member_login` | structure | turn member accounts on or off |
| `set_member_signup` | structure | open or close sign-up by visitors (login stays) |
| `create_member` `set_member_password` `set_member_tags` | write | make a member account by hand, replace a password, set a surface's tags |
| `list_ends` / `set_end` `delete_end` | read / structure | list surfaces; create, change (title, who may enter), delete a surface with its files |
| `list_members` / `set_member_status` `set_member_data` | read / write | list members; disable or enable one, set its attributes |
| `upload_media` | write | upload an image or PDF; returns the path and the stored size |
Every key can read. Changing structure, screens, site files and notes needs `structure`.
</details>
<details>
<summary><b>Environment</b></summary>
| Variable | Default | Meaning |
| --- | --- | --- |
| `HC_HOST` | `127.0.0.1` | address to listen on (`0.0.0.0` in the Docker image) |
| `HC_PORT` | `4200` | port |
| `HC_DATA` | `data` | data folder, uploads included (`/data` in the Docker image) |
| `HC_DB` | `<HC_DATA>/harness.db` | database file (SQLite) |
| `HC_DATABASE_URL` | unset | `postgres://user:password@host:port/database` puts the whole environment on Postgres instead of the SQLite file; add `?sslmode=verify-full` (and `&sslrootcert=/path/ca.crt` for your own CA) for TLS |
| `HC_READERS` | one for each core, 8 at most | how many read-only database connections answer pages and API reads, beside the one that writes; `0` for none (everything then shares the one connection) |
| `HC_ORIGIN` | `http://127.0.0.1:<port>` | the public address, exactly as the browser shows it |
| `HC_SITE_NAME` | `CMS Harness` | the name until one is set in Settings |
| `HC_ADMIN_PASSWORD` | random | password for `cms-harness admin` |
| `HC_TRUST_PROXY` | unset | `1` when the reverse proxy runs on another machine |
| `HC_ADMIN_ORIGIN` | unset | a separate admin address (`https://admin.example.com`), or `off` |
| `HC_END_SUBDOMAINS` | unset | `1`: every surface on its own subdomain; `0`: under the site's address; overrides Settings |
| `HC_TLS` | unset | `auto`: HTTPS by the program itself, certificates from Let's Encrypt (`HC_ORIGIN` must be `https://…`) |
| `HC_HTTPS_PORT` `HC_HTTP_PORT` | `443` `80` | the ports `HC_TLS=auto` listens on (on `HC_HOST`, `0.0.0.0` then by default) |
| `HC_ACME_EMAIL` | unset | where Let's Encrypt writes about the certificates |
| `HC_ACME_DIRECTORY` `HC_ACME_ROOT` | Let's Encrypt | `staging`, or another ACME server and a root to trust for it |
| `HC_FETCH_ALLOW_PRIVATE` | unset | `1` lets the chat's page reading, notifications and outside services reach private addresses (for a deployment inside its own network) |
| `HC_SECRET_KEY` | unset | 32 bytes, base64: the key the secrets saved in settings are encrypted with (outside services' keys, the chat model's key, the web search key, notification addresses). Unset, the server makes one in `secret.key` in the data folder. Servers sharing one database need the same one; a new server needs it, or the keys are entered again |
| `LLM_PROVIDER` `LLM_API_KEY` `LLM_MODEL` `LLM_BASE_URL` | unset | the chat model; overrides Settings |
With nginx, add `proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;` and `proxy_set_header Host $host;` so rate limits tell visitors apart. Caddy does this by default. The server compresses what it sends itself: pages, styles, scripts, JSON (the API, functions), XML and SVG over 1 KB go out gzipped to browsers that ask, a cached page from a copy compressed once. Pictures, fonts, uploads, backups and the admin chat's event stream go as they are. A proxy in front has nothing left to compress; nginx and Caddy leave an answer that is already compressed alone.
</details>
## 🔒 Security
Read [SECURITY.md](SECURITY.md) before you run scripts on the site that you did not write. It explains when to give the admin its own address (**Settings → Admin address**). What the protection does and does not do, the sandbox server functions run in, and how notifications, outside services' keys and uploaded pictures are handled are there too.
## 📄 License
[AGPL-3.0](LICENSE). Sites built with CMS Harness, front ends that read its API, and the content in its database are not derivative works. You only need to share your changes if you modify CMS Harness itself and offer it as a service. Contributions need a CLA; see [CONTRIBUTING.md](CONTRIBUTING.md).
---
<p align="center">
If CMS Harness is what you were looking for, a ⭐ helps other people find it.
</p>
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues