# Page Files (lexsis_build)

> Create and edit pages as files with lexsis_build or the Lexsis CLI, sending only what changed

Canonical URL: https://0.0.0.0:3005/tools/build

`lexsis_build` treats a page as a tree of files. You read only the files you
need, send only the files you changed, and every save compiles the whole page
once and returns every diagnostic with its file and line. Saves create a new
draft version. `lexsis_build` never publishes; use
[`lexsis_live_ops`](/tools/page-management#publishing-and-deployment-boundaries)
for that.

If your agent can run shell commands with network access, use the
[Lexsis CLI](#lexsis-cli). Otherwise call `lexsis_build` inline.

## Page files

A page uses the `lexsis.page/2` layout:

| Path | Contents |
|---|---|
| `lexsis.json` | Manifest: `"schema": "lexsis.page/2"`, the `sections` order and `head` |
| `sections/<id>.html` | One section: starts with `<!-- section: <id> -->`, then its markup, `<style>` and `<script>` |
| `styles/*.css` | Optional page-level CSS, appended to the page theme CSS. `styles/theme.css` replaces it |

```json
{
  "schema": "lexsis.page/2",
  "sections": ["hero", "benefits", "reviews"],
  "head": { "title": "Summer Collection" }
}
```

Section markup follows the [Page Source Schema](/pages/schema).

## Actions

| Action | Access | Use it to |
|---|---|---|
| `get` | Read | Return the `version`, the `tree` (path to hash) and the contents of the `files` you ask for |
| `diff` | Read | List changed files between two versions, with line diffs |
| `commit` | Draft | Save changed files, or create a new draft |
| `patch` | Draft | Apply small edits as ops, then save like `commit` |
| `push_token` | Draft | Get a 15-minute token for the Lexsis CLI |

## Edit a page

1. `get` with `page_id` and the `files` you need. Keep the returned `version`.
2. `commit` with `base_version` and only the changed files. `null` deletes a file.

```json
{
  "name": "lexsis_build",
  "arguments": {
    "action": "commit",
    "args": {
      "page_id": "page-uuid",
      "base_version": 6,
      "files": {
        "sections/hero.html": "<!-- section: hero -->\n<section class=\"py-16\"><h1>Summer Collection</h1></section>"
      },
      "message": "Tighten hero copy",
      "idempotency_key": "hero-copy-2026-11-09"
    }
  }
}
```

For small edits, `patch` takes `ops` instead of whole files:

| Op | Does |
|---|---|
| `replace_text` | Replace `find` with `replace` in a file (`all` for every match) |
| `upsert_css_rule` / `remove_css_rule` | Add, change or drop a CSS rule by selector |
| `set_attr` | Set or remove (`null`) an attribute on elements matching a simple selector |
| `set_prop` | Set a value in a `.json` file by JSON pointer |
| `set_head` | Set `head[key]` in `lexsis.json`; `null` deletes it |
| `move_section` | Move a section `before`, `after` or to an `index` |
| `remove_section` | Drop a section from the order and delete its file |

Pass `dry_run: true` to compile and get diagnostics without saving.

### Conflicts and retries

- If the page moved past `base_version` but the other changes touch different
  files, the server replays your edit on the current version and returns
  `rebased_from`.
- If the same files changed, it returns `VERSION_CONFLICT` with
  `server_diff` and `your_diff`. Re-read those files and resend.
- `commit` and `patch` accept an `idempotency_key`. A retried edit that is
  already on the page returns a noop instead of a second version.

## Create a page

Call `commit` with no `page_id` and a `create` spec:

```json
{
  "name": "lexsis_build",
  "arguments": {
    "action": "commit",
    "args": {
      "create": {
        "slug": "summer-collection",
        "title": "Summer Collection",
        "theme_id": "theme-uuid",
        "archetype": "landing"
      },
      "files": {
        "lexsis.json": "{\"schema\":\"lexsis.page/2\",\"sections\":[\"hero\"],\"head\":{\"title\":\"Summer Collection\"}}",
        "sections/hero.html": "<!-- section: hero -->\n<section><h1>Summer Collection</h1></section>"
      }
    }
  }
}
```

- `create` also takes `product_binding` and `resource_type` (`product` or
  `collection`).
- `from: { page_id, version? }` seeds the tree from an existing page, so you
  send only new or changed files.
- `shared_sections` links the store header and footer.
- An existing slug returns `PAGE_EXISTS` with that page's `page_id`. Edit it
  instead.

## Edit a cart as files

Pass `cart_profile_id` instead of `page_id` and the same actions work on a
cart profile's presentation layer, laid out as `lexsis.cart/1`:

| Path | Contents |
|---|---|
| `lexsis.json` | `"schema": "lexsis.cart/1"` and `modules`: every module in order, built-ins included, with `type`, `enabled`, optional `visible_when`, and `region` for custom modules |
| `modules/<id>.html` | One custom module: `<!-- section: <id> -->`, markup, `<style>`, `<script>`. Built-in modules have no file |
| `styles/<block>.css` | One file per named CSS block (`commerce_config.custom_css_blocks`) |

```json
{
  "schema": "lexsis.cart/1",
  "modules": [
    { "id": "cart-lines", "type": "cart_lines", "enabled": true },
    { "id": "trust", "type": "custom", "region": "body", "enabled": true },
    { "id": "order-summary", "type": "order_summary", "enabled": true },
    { "id": "checkout", "type": "checkout", "enabled": true },
    { "id": "product-detail", "type": "custom", "region": "sheet", "enabled": true }
  ]
}
```

A `commit` diffs the tree against the draft and saves it as the same
composition and CSS operations `lexsis_drafts` `cart_edit` accepts, in one new
draft version with `base_version` as the guard. Every existing rule still
applies: one section per module, no cart islands inside a module, required
modules stay, module CSS is scoped to the module. Offers, rewards, rules and
the design spec are not files; keep editing them with `cart_edit` and
`cart_promotions_edit`.

Regions are `header`, `body`, `footer`, `above_title`, `floating_above` and
`sheet`. A `sheet` module stays hidden and slides up over the cart when a
control with `data-lx-open-sheet="<id>"` is clicked, when a script dispatches
`lx:cart:open-sheet`, or when a recommendation card in an offer slot with
`presentation.detail_sheet: "<id>"` is tapped. See
[Custom cart modules](/cart/custom-modules).

Differences from pages: no `create` (make the profile with `cart_create`), no
`set_head`, only the current draft version is readable as files, and a stale
`base_version` is always `VERSION_CONFLICT` (re-read and resend).

## Lexsis CLI

`@lexsis/cli` (Node 20 or later) edits the same files on disk.

```bash
npx @lexsis/cli pull <page_id> [dir]
npx @lexsis/cli pull --cart <cart_profile_id> [dir]   # LEXSIS_API_KEY only
npx @lexsis/cli diff [dir]
npx @lexsis/cli push [dir] [-m "message"] [--dry-run]
npx @lexsis/cli new <dir> --slug <slug> --theme <theme_id> [--title t] [--archetype a] [--from page_id] [--shared id,id] [--dry-run]
npx @lexsis/cli --version
```

`push` sends only changed files, compiles once, saves one draft version and
re-pulls. State lives in `<dir>/.lexsis/state.json`.

### Authentication

| Variable | Use |
|---|---|
| `LEXSIS_TOKEN` | Token from `lexsis_build` action `push_token` |
| `LEXSIS_API_KEY` | API key, for CI and scripts |
| `GOLEM_API_URL` | Defaults to `https://api.trylexsis.com` |
| `LEXSIS_WORKSPACE_ID` | Optional workspace |

`push_token` with `page_id` returns a 15-minute token that reads and edits
drafts of that page only. Without `page_id` it returns a 15-minute create-only
token: it can read the store and create one draft (and link shared sections),
nothing else. Use that one with `lexsis new`.

```bash
LEXSIS_TOKEN=<token> npx @lexsis/cli pull <page_id> ./page
# edit ./page/sections/*.html
LEXSIS_TOKEN=<token> npx @lexsis/cli push ./page -m "Tighten hero copy"
```

## Related

- [Page Management](/tools/page-management)
- [Page Source Schema](/pages/schema)
- [Publishing](/pages/publishing)
