# SpacePress — Full Documentation Corpus
Index: https://spacepress.dev/llms.txt
---
# Build a SpacePress app
You are helping someone build a TypeScript application that compiles directly into native PHP, SQL migrations, and WordPress plugins — headful WordPress by default, zero Node.js in production. Finish with a working local WordPress site they can open and inspect.
## 1. Inspect the current directory
Look at what is already in the workspace before scaffolding or asking questions. If the goal is still unclear, ask **one** concise question: *What are you building, and what should editors manage in WordPress?* Do not re-ask anything the user already told you.
Choose the matching path:
- **Already a SpacePress project (`typedpress.config.ts` exists):** Read `AGENTS.md` and use the `typedpress` MCP server (`schema`, `check`, `docs_search`, `docs_read`). Do not scaffold over it.
- **Migrating an existing schema (EmDash, Payload, Sanity, or Zero):** Run `npx typedpress migrate config --from emdash|payload|sanity|zero --out typedpress.config.ts` to convert statically without executing source code.
- **Brand new project:** Scaffold with `npm create typedpress@0.3.0
` (uses the pre-release identifier `typedpress` for CLI, config file, and imports; requires Node.js 22+, no Docker or Rust toolchain). It writes `AGENTS.md`, `.mcp.json`, and 12 skills into `.agents/skills/` and `.claude/skills/`.
- **Different existing app:** Ask before replacing its framework or files.
## 2. Read the compiler rules first
Read [https://spacepress.dev/rules.md](https://spacepress.dev/rules.md) before writing TypeScript so you follow the exact TS-to-PHP subset, import boundaries, access rules, and safe migration conventions on the first try.
## 3. Build one complete vertical slice
1. **Model the data:** Use `collection()` (or `wp.posts.extend()`) for editorial content backed by WordPress posts (Gutenberg, drafts, revisions, `sync: "content/**/*.md"`), and `table()` for relational SQL data with explicit `access` rules.
2. **Add server logic & pages:** Export `action()` RPC endpoints or `job()` queues from `tp/`, and build at least one headful server-rendered TSX page in `tp/app/` (plus a `"use client"` island if interactivity is needed). Only generate/wire an external frontend (`tp/_generated/client/` or `@typedpress/astro`) if the user explicitly wants headless.
3. **Compile and check:** Run `npx typedpress check` after every edit (`npx typedpress check --fix` fixes lint warnings like `capital_P_dangit`), and `npx typedpress init` after changing `typedpress.config.ts` so `AGENTS.md` stays in sync.
4. **Boot local WordPress and verify:** Run `npm run dev` (or `npx typedpress dev --detach`). Confirm the local site and `/wp-admin/new/` respond cleanly.
5. **Hand back:** Share the local site URL, `/wp-admin/new/` admin URL, what is editable, and any remaining caveats. Do not create production credentials or push to a live site without explicit user approval.
## 4. Reference & discovery
- Compiler rules: https://spacepress.dev/rules.md
- Full documentation index: https://spacepress.dev/llms.txt
- Full documentation corpus: https://spacepress.dev/llms-full.txt
- Agent skills catalog: https://spacepress.dev/.well-known/agent-skills/index.json
- Local dev MCP server: `npx --no-install typedpress mcp` (read-only docs, live schema, check, and local queries; separate from a running site's authenticated runtime MCP at `/wp-json/mcp/typedpress-`).
---
# SpacePress Coding Agent Rules
Targets SpacePress v0 ("Istanbul") / `typedpress` CLI `0.3.0` (WordPress 7.1+, PHP 8.2+).
## Core compilation model
- **Server TypeScript compiles to native PHP — not Node.js.** Never import Node built-ins (`fs`, `path`, `crypto`, `process`, `buffer`, `child_process`) or arbitrary npm packages inside `typedpress.config.ts`, `tp/app/`, actions, hooks, jobs, or routes.
- **Headful WordPress is the default.** Files under `tp/app/**/page.tsx` and `layout.tsx` compile directly into server-rendered PHP inside WordPress. Interactive widgets belong in `"use client"` components compiled to the WordPress Interactivity API. Only wire `tp/_generated/client/` or `@typedpress/astro` when the user explicitly wants a separate headless frontend.
- **Never edit `tp/_generated/` or `tp/dist/`.** `typedpress build` regenerates them. Commit `tp/_generated/` (migrations, snapshots, types, plugin lockfile); git-ignore `tp/dist/` and `.tp/`.
- **Pre-release identifier:** The framework brand is SpacePress (`spacepress.dev`), while the npm package, CLI binary, config file (`typedpress.config.ts`), `tp/` directory, and imports (`"typedpress"`, `"typedpress:db"`, `"typedpress/app"`, `"typedpress/client"`) use `typedpress` during v0.
## Exact import boundaries
- `"typedpress"`: schema & server builders (`collection`, `table`, `global`, `wp`, `taxonomy`, `store`, `product`, `productCategory`, `productTag`, `order`, `action`, `job`, `jobs`, `db`, `mail`, `HttpError`, `defineConfig`, and field builders `text`, `integer`, `boolean`, `richText`, `slug`, `select`, `timestamp`, `ref`, `email`).
- `"typedpress:db"`: visitor-scoped kind queries (e.g. `import { posts, tasks } from "typedpress:db"`). **Always prefer `"typedpress:db"` in `tp/app/` pages** because it enforces `.access()` rules automatically. Reserve trusted `db` from `"typedpress"` for `action()`/`job()` handlers after verifying authorization.
- `"typedpress/app"`: server page/layout helpers (`Link`, `Content`, `useFormState`, `type PageProps`, `type LayoutProps`).
- `"typedpress/client"`: client-only hooks (`useState`, `useLive`) — valid **only** inside files starting with `"use client";`.
- `"php/wordpress"`: typed bridges to WordPress core functions and `abilities.call(...)`.
## Data modeling & migrations
- Use `collection()` (or `wp.posts.extend()`) for editorial content that needs Gutenberg, drafts, revisions, comments, URL routing, or `sync: "content/**/*.md"`.
- Use `table()` for relational application rows (tasks, votes, orders, subscriptions) stored in dedicated SQL tables with `.index([...])` and incremental migrations.
- Export kinds, actions, and jobs from `typedpress.config.ts` or any file under `tp/` — they register automatically by export name; `defineConfig()` does not list them.
- **Timestamp values:** Pass ISO-8601 strings (`new Date().toISOString()`) when writing `timestamp()` fields — not raw `Date` objects.
- **Safe renames:** When renaming a field or column, chain `.was("oldName")` so `typedpress build` emits a `RENAME` migration instead of dropping data.
- **WooCommerce checkout:** Whenever a project exports `store()` alongside `tp/app/`, include a public `tp/app/checkout/page.md` containing WooCommerce's native Checkout Block (``).
- **Markdown sync:** Avoid raw HTML comments (``) in synced `.md` files and never reuse a deleted document's `uid` for a new file.
## Security & authorization
- Declare explicit `access` rules on every `collection()`, `table()`, `global()`, and `action()`, and export `guard` on every custom `route.ts`.
- For user-owned rows, return a row filter (`({ user }) => (user ? { ownerId: user.id } : false)`) rather than only checking truthiness; never trust a client-supplied `userId` in an action.
- Attach field-level `.access({ read: "admin" })` to sensitive columns so REST, pages, and generated clients strip them automatically.
- Annotate `action()` declarations with `readonly: true` or `destructive: true` to guide WordPress Abilities safety checks (`agents: false` opts internal actions out).
## Verification workflow
- Run `npx typedpress check` after every edit to `typedpress.config.ts` or `tp/` (`npx typedpress check --fix` applies auto-fixes such as `capital_P_dangit` for proper `WordPress` spelling).
- Run `npx typedpress init` after config changes (`npx typedpress init --check` in CI).
- Before deploying to production, always run `npx typedpress push --dry-run`, obtain explicit user approval, and verify afterward with `npx typedpress doctor --site --links`.
- On WP Cloud (Pressable / WordPress.com), avoid `/files/*` for custom public downloads and copy top-level `public/*.{js,wasm,txt}` files into `/srv/htdocs/` before purging edge cache.
---
# SpacePress Quick Start
> Go from zero to a running SpacePress application on local WordPress in 3 minutes — no Docker or Rust toolchain required.
Source: https://spacepress.dev/quick-start/
## 1. Scaffold a new project
```sh
npm create typedpress@0.3.0 my-app
cd my-app
```
## 2. Start local WordPress
```sh
npm run dev
```
## 3. Check & auto-fix
```sh
npx typedpress check
npx typedpress check --fix
```
## 4. Sync Markdown content
```sh
npx typedpress sync
```
## 5. Build & deploy
Deploy to Spacefast, Pressable, WordPress.com, or any self-hosted WordPress site:
```sh
npx typedpress build
npx typedpress login https://example.com && npx typedpress push
```
---
# The SpacePress Handbook
> End-to-end engineering handbook covering every layer of SpacePress — Rust/OXC compiler, schemas, SQL migrations, access control, actions, jobs, TSX pages, WooCommerce, React Email, Markdown sync, MCP, and deployment.
Source: https://spacepress.dev/handbook/
## Chapters
- **01. [Project Layout & Mental Model](https://spacepress.dev/handbook/#mental-model)** — typedpress.config.ts, tp/ modules, and how the compiler emits native WordPress artifacts.
- **02. [Rust & OXC Compiler](https://spacepress.dev/handbook/#compiler)** — TypeScript/TSX parsing in Rust, emitted PHP/SQL/OpenAPI/types, and capital_P_dangit lint.
- **03. [Data Modeling & Migrations](https://spacepress.dev/handbook/#data-modeling)** — collection(), table(), global(), wp.posts.extend(), snapshot.json, and .was() safe renames.
- **04. [Queries, Validation & Access](https://spacepress.dev/handbook/#queries-access)** — Typed db queries, row-level filters, field-level .access(), and .validate().
- **05. [Hooks & Lifecycle Events](https://spacepress.dev/handbook/#hooks)** — Transactional collection hooks (.on) and typed WordPress core hooks in tp/wp-hooks/.
- **06. [Actions, Jobs, Routes & Files](https://spacepress.dev/handbook/#actions-jobs-routes)** — Typed RPC action(), Action Scheduler job(), custom HTTP route.ts, and file buckets.
- **07. [Pages, Layouts & Islands](https://spacepress.dev/handbook/#pages-islands)** — File-based TSX pages in tp/app/ compiled to PHP and "use client" Interactivity API islands.
- **08. [Typed Client, React & Astro](https://spacepress.dev/handbook/#clients-astro)** — Generated fetch client, React hooks, and @typedpress/astro external frontend integration.
- **09. [WooCommerce Storefront](https://spacepress.dev/handbook/#woocommerce)** — store(), product(), shipping zones, orders, and optimistic cart hooks on native WooCommerce.
- **10. [React Email Templates](https://spacepress.dev/handbook/#react-email)** — Transactional email templates in emails/*.tsx rendered via mail.render() and mail.send().
- **11. [Admin, Gutenberg & Plugins](https://spacepress.dev/handbook/#admin-plugins)** — typedpress-admin at /wp-admin/new/, adminScreen(), @typedpress/blocks, and plugins.
- **12. [Two-Way Markdown Git Sync](https://spacepress.dev/handbook/#markdown-sync)** — Three-way merges between content/**/*.md and WordPress Admin with stable UIDs.
- **13. [MCP, Abilities & AI Agents](https://spacepress.dev/handbook/#mcp-agents)** — WordPress Abilities API annotations and typedpress mcp server for coding agents.
- **14. [Hosting, Deploy & CLI](https://spacepress.dev/handbook/#deploy-cli)** — Deploy to Spacefast, Pressable, WordPress.com, or self-hosted WordPress with typedpress push.
For complete topic-by-topic technical specs, fetch `/llms.txt` or `/llms-full.txt`.
---
# Schema & Storage
> Collections, SQL tables, globals, WordPress built-in kinds, field builders, and migrations.
Source: https://spacepress.dev/docs/core/schema-and-storage
## Choosing a storage kind
| Builder | Storage | When to use |
|---------------------|-----------------------------|----------------------------------------------------------------------------------------------------------------|
| `collection()` | WordPress custom post type | Editorial items needing Gutenberg, drafts, revisions, staged versions, comments, URL routing, or Markdown sync |
| `table()` | Dedicated SQL table | Relational app records, high-volume data, compound indexes (`.index()`), strict SQL migrations |
| `global()` | WordPress options singleton | Site-wide settings, navigation links, feature flags |
| `wp.posts.extend()` | Built-in WordPress `post` | Native blog posts extended with typed meta fields and URL pattern |
| `userProjection()` | `wp_users` + `wp_usermeta` | Typed user profiles without duplicating WordPress accounts |
| `taxonomy()` | WordPress term tables | Flat or hierarchical vocabularies attached via `on: [...]` or `terms()` |
## Field builders
All columns are `NOT NULL` by default unless `.optional()` is chained.
- **Scalars:** `text({ multiline? })`, `integer()`, `number()`, `boolean()`, `date()`, `timestamp()`, `json()`
- **Semantic:** `email()`, `url()`, `slug({ source })`, `richText()`, `select([...])` (`.many()` for multi-select)
- **Relations & Media:** `ref(kind)` (`.many()`, `.onDelete("cascade" | "restrict" | "setNull")`, `.reverse("name")`), `terms(taxonomy)`, `media({ accept })`, `file(bucket)`
- **Structured:** `group(fields)`, `repeater(fields)`, `blocks(layouts)`
## Modifiers & safe renames
Chain `.min(n)`, `.max(n)`, `.pattern(/.../)`, `.unique()`, `.default(v)`, `.defaultNow()`, `.$default(fn)`, `.$onUpdate(fn)`, `.validate((v, ctx) => ...)`, `.ui({ label, help, placeholder, width })`, and `.showIf({ ... })`.
To rename a column or SQL table without losing production data, declare `.was("oldName")` on the column or `was: "old_table"` on `table()`. SpacePress emits a safe rename migration against `tp/_generated/migrations/snapshot.json`.
---
# Queries & Access Control
> Visitor-scoped typedpress:db queries, trusted db queries, filtering operators, and declarative access rules.
Source: https://spacepress.dev/docs/core/queries-and-access
## Visitor-scoped vs trusted database APIs
Import named kinds from `"typedpress:db"` for visitor-scoped operations that automatically enforce access rules, draft visibility, and field masks:
```ts
import { posts } from "typedpress:db";
const published = await posts.list({
where: { tags: { has: "release" } },
orderBy: { publishedAt: "desc" },
with: { cover: true },
limit: 20,
});
// Explicit system escalation when needed:
const all = await posts.system.list({ limit: 100 });
```
Inside hooks, jobs, and trusted server actions, you can also use the Drizzle-inspired `db` API from `"typedpress"`:
```ts
import { db } from "typedpress";
const row = await db.query.posts.findFirst({ where: { slug: "hello" } });
const [created] = await db.insert(tasks).values({ title: "Ship v1" }).returning();
```
## Declarative access rules
The role ladder is ordered: `guest < subscriber < author < editor < admin`. Naming a role admits that role and every higher role.
- Shorthands: `"anyone"`, `"authenticated"`, `"self"`, role name, or boolean.
- Functions: `(ctx) => boolean | AccessFilter` — returning a filter restricts `read`, `update`, and `delete` queries to matching rows (non-matching rows return `404`).
- Field masks: `.access({ read, create, update })` on any column strips or refuses unauthorized fields across REST, pages, and client queries.
---
# Actions, Jobs, Hooks & HTTP Routes
> Server RPC actions, Action Scheduler background jobs, transactional hooks, custom routes, and file buckets.
Source: https://spacepress.dev/docs/core/actions-jobs-routes
## Server actions
Export an `action()` to mount a validated endpoint at `POST /__tp/api/v1/actions/` (and expose it to `"use client"` components and the typed client):
```ts
import { action, integer, HttpError, db } from "typedpress";
export const archiveTask = action({
input: { id: integer() },
access: "editor",
idempotent: true,
async handler({ id }) {
const [row] = await db.update(tasks).set({ done: true }).where({ id }).returning();
if (!row) throw new HttpError(404, "not_found", "Task not found");
return row;
},
});
```
Set `readonly: true` or `destructive: true` to annotate the generated WordPress Ability for AI agents, or `signature` to verify incoming HMAC webhooks.
## Background jobs
Export a `job()` and enqueue it with `jobs..enqueue(input, { delay?, key? })`. Jobs run asynchronously on WordPress Action Scheduler, commit atomically with the enclosing database transaction, support automatic `retries`, and can guard non-idempotent side effects with `once(key, fn)`.
## Transactional hooks & WordPress hooks
- Chain `.on({ beforeCreate, afterCreate, beforeUpdate, afterUpdate, beforeDelete, afterDelete, afterPublish })` onto any collection or table. Throwing aborts the request and rolls back the transaction.
- Place typed WordPress core filters/actions in `tp/wp-hooks/.ts` using `Handler<"...">` from `"php/wordpress"`.
## Custom HTTP routes & private files
- Create `tp/app//route.ts` exporting `GET`, `POST`, `PUT`, `PATCH`, or `DELETE` plus `export const guard`.
- Define private upload buckets with `files({ accept, maxBytes, access })` backed by local disk or S3-compatible storage (`uploads: { backend: "s3", ... }`). Loading a `file(bucket)` column via `with` yields a 5-minute signed URL.
---
# Pages, Layouts & Interactive Islands
> File-based TSX routing compiled to PHP, progressive forms, "use client" Interactivity API islands, and static export.
Source: https://spacepress.dev/docs/core/pages-and-islands
## File-based routing in `tp/app/`
SpacePress compiles TSX pages and layouts in `tp/app/` directly into server-rendered PHP:
- `tp/app/layout.tsx` — shared shell, `export const template = "theme" | "blank" | ""`, `metadata`, and CSS imports.
- `tp/app/page.tsx`, `[slug]/page.tsx`, `[...path]/page.tsx`, `(group)/` — static, dynamic, catch-all, and grouped routes.
- `tp/app/not-found.tsx` and `tp/app/login.tsx` — custom 404 and custom WordPress sign-in screens.
- `export const search = { page: integer().default(1) }` — typed query string parsing.
- `export const guard = "authenticated"` — route-level authorization.
## Built-in server components (`typedpress/app`)
Use `` (Interactivity Router navigation), `` (block content via `the_content`), `` (sanitized HTML), ``, ``, ``, ``, ``, ``, ``, and `useFormState(action)` for progressive zero-JS `