@o-a/cms-agent 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -35,27 +35,18 @@ Granite CMS is the combination neither of those is:
35
35
 
36
36
  - **Developers** build the theme: Liquid layouts, sections, and blocks,
37
37
  each with an embedded JSON Schema for its settings. Start with
38
- [`docs/theme-authoring-guide.md`](docs/theme-authoring-guide.md).
38
+ [`docs/guide-theme-authoring.md`](docs/guide-theme-authoring.md).
39
39
  - **Content editors / marketing managers** never touch this repository at
40
40
  all - they work entirely through a separate admin application (see
41
41
  [Companion projects](#companion-projects) below), browsing pages,
42
42
  editing sections, and publishing through the API this package exposes.
43
43
  The content model itself is documented in
44
- [`docs/content-authoring-guide.md`](docs/content-authoring-guide.md).
44
+ [`docs/guide-content-authoring.md`](docs/guide-content-authoring.md).
45
45
 
46
46
  ## Quick start
47
47
 
48
- > **Not yet published to npm.** Until it is, install from a local build -
49
- > see [`docs/hosting.md`](docs/hosting.md#installing-o-acms-agent-today) for
50
- > the exact steps. Once published, this becomes:
51
- >
52
- > ```
53
- > npx -p @o-a/cms-agent create-site my-site
54
- > ```
55
-
56
- Either way, the result is the same:
57
-
58
48
  ```
49
+ npx -p @o-a/cms-agent create-site my-site
59
50
  cd my-site/vhost
60
51
  npm install
61
52
  npm start
@@ -76,7 +67,7 @@ and the site's own serving configuration lives under `vhost/`:
76
67
 
77
68
  ```
78
69
  my-site/
79
- content/ pages, posts, menus, redirects, drafts
70
+ content/ pages, menus, redirects, drafts
80
71
  theme/ layouts, sections, blocks, snippets, assets, root, templates
81
72
  media/ uploaded files - gitignored, backed up separately
82
73
  vhost/ site.config.json, package.json, server.js
@@ -97,9 +88,9 @@ install.
97
88
 
98
89
  ## Documentation
99
90
 
100
- - [`docs/theme-authoring-guide.md`](docs/theme-authoring-guide.md) - building a theme
101
- - [`docs/content-authoring-guide.md`](docs/content-authoring-guide.md) - the content model
102
- - [`docs/hosting.md`](docs/hosting.md) - running a site somewhere real
91
+ - [`docs/guide-theme-authoring.md`](docs/guide-theme-authoring.md) - building a theme
92
+ - [`docs/guide-content-authoring.md`](docs/guide-content-authoring.md) - the content model
93
+ - [`docs/guide-hosting.md`](docs/guide-hosting.md) - running a site somewhere real
103
94
  - [`docs/cms-build-plan.md`](docs/cms-build-plan.md) - full architecture and design rationale
104
95
 
105
96
  A friendlier, browsable documentation site (covering both this engine and
@@ -114,6 +114,6 @@ export function scaffoldSite(targetDir) {
114
114
  // runStartupChecks hard-fails not-a-git-repo otherwise - a scaffold
115
115
  // without a real git repo cannot boot at all.
116
116
  execFileSync('git', ['init', '--quiet'], { cwd: targetDir });
117
- commitPaths(targetDir, ['theme', 'content', 'vhost', '.gitignore', '.dockerignore'], 'chore: initial scaffold', CHECKPOINT_AUTHOR);
117
+ commitPaths(targetDir, ['theme', 'content', 'vhost', 'AGENTS.md', '.gitignore', '.dockerignore'], 'chore: initial scaffold', CHECKPOINT_AUTHOR);
118
118
  return { raw: token.raw };
119
119
  }
@@ -0,0 +1,191 @@
1
+ # AGENTS.md
2
+
3
+ This file orients an AI coding agent working in this repository. It is written for the task of turning a visual design (a screenshot, a Figma export, a written brief) into working site code - not for general software engineering advice.
4
+
5
+ This repo is a single site built on Granite CMS: a self-hosted, git-backed CMS. There is no framework source code here to read - the CMS itself is an installed dependency (`vhost/node_modules/@o-a/cms-agent`). Everything that makes this site what it is lives in two folders:
6
+
7
+ ```
8
+ theme/ Liquid templates - the design/markup layer
9
+ content/ JSON files - the actual page content, git-tracked, the source of truth
10
+ media/ uploaded images - not git-tracked, see "Images" below
11
+ vhost/ deploy config (package.json, server.js, site.config.json) - rarely needs editing
12
+ ```
13
+
14
+ Every rule below is exact, not a rough guide - the CMS validates content against real JSON Schemas and will reject anything that deviates. Where this file gives a worked example, prefer copying its shape over improvising a new one.
15
+
16
+ ## Folder structure inside `theme/`
17
+
18
+ ```
19
+ theme/
20
+ layouts/ *.liquid, flat, no schema - page wrappers (<html>, <head>, nav, footer)
21
+ sections/ *.liquid, flat, one per section type - markup + embedded settings schema
22
+ blocks/ *.liquid, flat, one per block type - markup + embedded settings schema
23
+ snippets/ *.liquid, flat, no schema - small reusable partials, invoked with {% render %}
24
+ assets/ static files (CSS, JS, images) - served as-is at /assets/<path>
25
+ root/ static files served at the bare site root (robots.txt, favicon.ico, etc.)
26
+ templates/ *.json, flat, optional - prebuilt starting pages an editor can pick from
27
+ ```
28
+
29
+ No subfolders inside `layouts/`, `sections/`, `blocks/`, or `snippets/` - one file, one component, named directly. The filename (without `.liquid`) is that component's type identifier and must match `^[a-z0-9][a-z0-9-]*$` (lowercase, digits, hyphens only). This exact string is what page content JSON uses in its own `"type"` field - they must match exactly.
30
+
31
+ This scaffold already ships real, working examples worth reading before writing anything new: `theme/sections/hero.liquid`, `theme/blocks/button.liquid`, and `theme/layouts/theme.liquid`. Match their conventions rather than inventing a different style.
32
+
33
+ ## Turning a design into code - the actual workflow
34
+
35
+ 1. Break the design into distinct repeating/reusable visual components. Each one becomes a `theme/sections/<name>.liquid` (a self-contained region of a page) or `theme/blocks/<name>.liquid` (a smaller item nested inside a section, e.g. one card in a grid, one FAQ row).
36
+ 2. Each file has two parts: ordinary Liquid/HTML markup, and a `{% schema %} ... {% endschema %}` block containing a single JSON object - a plain [JSON Schema draft-07](https://json-schema.org/draft-07) description of that component's `settings`. The schema block is stripped out before rendering, so a real Liquid tag never sees it - place it anywhere in the file (convention: at the end).
37
+ 3. Once the theme components exist, compose an actual page by writing a file under `content/pages/` whose `sections` array references those types by filename, with a `settings` object matching each one's schema (see "Content JSON model" below).
38
+ 4. Preview the result before considering the task done - see "Previewing your work".
39
+
40
+ ### Worked example - a section
41
+
42
+ ```liquid
43
+ <section class="hero" data-section-id="{{ section.id }}">
44
+ <h1>{{ section.settings.heading }}</h1>
45
+ {% if section.settings.subheading %}<p>{{ section.settings.subheading }}</p>{% endif %}
46
+ <div class="hero__blocks">{% for html in blocksHtml %}{{ html | raw }}{% endfor %}</div>
47
+ </section>
48
+ {% schema %}
49
+ {
50
+ "type": "object",
51
+ "additionalProperties": false,
52
+ "required": ["heading"],
53
+ "properties": {
54
+ "heading": { "type": "string", "minLength": 1, "default": "New section" },
55
+ "subheading": { "type": "string" }
56
+ }
57
+ }
58
+ {% endschema %}
59
+ ```
60
+
61
+ Available variables in a section: `section.id`, `section.settings.<key>`, and `blocksHtml` (an array of already-rendered child block HTML strings - a section never sees raw block data, only finished HTML, output with `{{ html | raw }}`). A block template gets the same shape: `block.id`, `block.settings.<key>`, and (rarely) its own `blocksHtml` if it nests further blocks.
62
+
63
+ **Every property listed in a schema's `"required"` array must also declare a `"default"`** that itself satisfies the property's own constraints (e.g. not `"default": ""` against `"minLength": 1`). A schema that violates this is silently excluded from the theme entirely - it simply won't be selectable, with no error printed anywhere obvious. If a new section/block isn't showing up, check this first.
64
+
65
+ To restrict which block types are allowed under a given section/block, add `"allowedBlocks": ["button", "logo-mark"]` alongside `"properties"` in its schema - omit it entirely for no restriction (the default).
66
+
67
+ ### Layouts
68
+
69
+ `theme/layouts/theme.liquid` is required - every theme must define a layout named exactly `theme` as the default (a page can opt into a different one via its own `"layout"` field). A layout only ever sees:
70
+
71
+ ```liquid
72
+ {{ content_for_layout | raw }} the page's fully-rendered sections, concatenated
73
+ {{ page.title }} the page's title (the ONLY page field exposed to layouts)
74
+ {{ menus.<name>.items }} every menu in content/menus/, keyed by filename
75
+ ```
76
+
77
+ ### Snippets
78
+
79
+ Flat `.liquid` files in `snippets/`, invoked with `{% render 'name', param1: value %}` - never `{% include %}`. A snippet only sees parameters explicitly passed to it; the calling scope never leaks in.
80
+
81
+ ## Field format hints
82
+
83
+ Every setting is plain JSON Schema (`string`, `integer`, `number`, `boolean`, `array`, with `minLength`/`minimum`/`enum`/etc. for real validation). One extra keyword, `"format"`, is a UI hint only (never validated server-side) that the admin reads to choose a richer input widget:
84
+
85
+ | `format` | On type | Effect |
86
+ |---|---|---|
87
+ | `richtext` | `string` | Rich-text editor; render with `{{ ... | raw }}`, not plain `{{ }}` |
88
+ | `image` | `object` | Image picker with focal point; object shape is exactly `{ "url": "...", "focalX": 0.5, "focalY": 0.5 }` - render `{{ section.settings.<field>.url }}` |
89
+ | `textarea` | `string` | Multi-line `<textarea>` |
90
+ | `uri` | `string` | `<input type="url">` |
91
+ | `date` | `string` | `<input type="date">`, value as `YYYY-MM-DD` |
92
+ | `color` | `string` | Hex value (e.g. `"#ff6600"`); optional sibling `"swatches": ["#c2410c", ...]` for a preset palette (not an `enum` - a custom colour is still always allowed) |
93
+ | `range` | `integer`/`number` | Slider + number box; requires `minimum`/`maximum`; optional `"step"` (default `1`) and `"unit"` (e.g. `"px"`) |
94
+ | `toggle` | `boolean` | Switch instead of a checkbox (same underlying data) |
95
+ | (none) | `boolean` | Plain checkbox |
96
+ | (none) | `string` + `"enum"` | Segmented tabs (few short options) or a `<select>` (more/longer) - decided automatically, not choosable |
97
+
98
+ A `format` on the wrong `type` (e.g. `image` on a `string`) is a mistake, not something the admin guesses around - it silently falls back to a plain widget for that type.
99
+
100
+ A separate keyword, `"api": true`, can be added to any scalar property to expose its value through `GET /search.json` for structured filtering, independent of full-text search - see that section below.
101
+
102
+ ## Content JSON model
103
+
104
+ `content/pages/*.json` - nested folders allowed via a **sibling** pattern: a page with children is a `.json` file sitting beside a same-named folder (`about.json` next to `about/team.json`, never `about/about.json`). A URL maps directly to this path; `/` maps to `index.json`.
105
+
106
+ Required fields, `additionalProperties: false`:
107
+
108
+ | Field | Type | Notes |
109
+ |---|---|---|
110
+ | `schemaVersion` | integer | Always `6` for new content |
111
+ | `name` | string | Internal label (shown in the admin's page tree) |
112
+ | `title` | string | Rendered as `{{ page.title }}` |
113
+ | `type` | string | Free-form (e.g. `"page"`, `"blog-article"`) - use `pageType` filtering below to distinguish kinds |
114
+ | `layout` | string | A filename in `theme/layouts/` (no extension) - `"theme"` unless a different layout exists |
115
+ | `published` | boolean | `false` behaves as if the page doesn't exist on the live site at all |
116
+ | `sections` | array | Section instances - see below |
117
+
118
+ Optional fields, any page may carry them: `author` (string), `publishDate` (string, `YYYY-MM-DD` recommended - it's indexed numerically for sorting/range filters), `tags` (array of non-empty strings). There is no separate "post" content type - a blog article is just a page, conventionally nested under a `content/pages/blog/` folder.
119
+
120
+ Each entry in `sections` requires `id` (any non-empty string, unique within the page), `type` (must exactly match a filename in `theme/sections/`), and `settings` (matching that type's schema). Optional `blocks` array, same shape, referencing `theme/blocks/`.
121
+
122
+ ```json
123
+ {
124
+ "schemaVersion": 6,
125
+ "name": "Home",
126
+ "title": "Welcome",
127
+ "type": "page",
128
+ "layout": "theme",
129
+ "published": true,
130
+ "sections": [
131
+ {
132
+ "id": "sec-hero",
133
+ "type": "hero",
134
+ "settings": { "heading": "Welcome" },
135
+ "blocks": [
136
+ { "id": "blk-cta", "type": "button", "settings": { "label": "Get started", "url": "/" } }
137
+ ]
138
+ }
139
+ ]
140
+ }
141
+ ```
142
+
143
+ `content/menus/<name>.json` - referenced in layouts as `{{ menus.<name>.items }}`:
144
+
145
+ ```json
146
+ { "schemaVersion": 6, "items": [{ "label": "Home", "url": "/" }, { "label": "About", "url": "/about" }] }
147
+ ```
148
+
149
+ `content/redirects.json` - a single file, not a folder:
150
+
151
+ ```json
152
+ { "schemaVersion": 1, "entries": [{ "from": "/old-path", "to": "/new-path" }] }
153
+ ```
154
+
155
+ `to` must be a bare internal path (no `https://`, no leading `//`). A redirect never overrides a real page at the same URL.
156
+
157
+ `content/pages/404.json`, if present and `published`, renders through the normal page pipeline with the HTTP status forced to 404 - the standard way to give a broken URL a real branded page instead of a bare JSON error.
158
+
159
+ ## Images
160
+
161
+ Uploads go through `POST /v1/media` (multipart, requires a token with `media` scope) or the admin's own media library UI - never write directly into `media/` from an agent, since the CMS names files by content hash. A successful upload returns `{ "url": "/media/<name>" }`. In theme content, an image is just a plain string setting holding that URL:
162
+
163
+ ```json
164
+ { "type": "string", "default": "" }
165
+ ```
166
+
167
+ unless the design needs a focal point for a cropped image, in which case use `"format": "image"` (see the table above) instead of a plain string.
168
+
169
+ ## `GET /search.json`
170
+
171
+ A public, unauthenticated, read-only endpoint - safe to call directly from a section's own client-side JavaScript with a plain `fetch()`, no token needed. Only ever returns already-published content. Query params: `q` (full-text), `filter=field:op:value` (repeatable, ANDed; `op` is `eq`/`gt`/`gte`/`lt`/`lte`), `pageType`, `sort` (`-publishDate` for newest-first), `limit`, `offset`. Useful for a blog listing, a filterable directory, or a live search box.
172
+
173
+ ## Hard constraints - do not deviate from these
174
+
175
+ - **No dynamically registered Liquid tags or filters, ever.** Only standard LiquidJS built-ins (`if`, `for`, `assign`, `render`, filters like `upcase`, `times`) plus the CMS-provided context objects described above. Never invent a custom tag.
176
+ - **`{{ }}` auto-escapes HTML by default.** Only use `| raw` for values the CMS itself already produced as safe HTML (`blocksHtml` entries, `content_for_layout`, a `format: "richtext"` field). Never apply `| raw` to an ordinary setting value.
177
+ - **Every template render is bounded to roughly 50ms.** Keep Liquid logic simple - loops and conditionals, no heavy computation.
178
+ - **One file, one type, no subfolders** inside `layouts/`, `sections/`, `blocks/`, `snippets/` - and the filename must match `^[a-z0-9][a-z0-9-]*$` exactly.
179
+ - **The `{% schema %}` block must be valid, parseable JSON.** A malformed or missing schema fails the whole component, not just the settings half.
180
+ - **`additionalProperties: false` applies everywhere in content JSON** - don't add a field "just in case"; anything not in the tables above fails validation.
181
+
182
+ ## Previewing your work
183
+
184
+ From `vhost/`:
185
+
186
+ ```
187
+ npm start # boots the site on the port set in vhost/site.config.json
188
+ npm run tunnel # same, plus a public tunnel URL for sharing a preview
189
+ ```
190
+
191
+ Then request the page you changed (`curl http://localhost:<port>/<path>`, or open it in a browser) and confirm it actually renders as expected before considering a change finished - a page that fails schema validation or references a non-existent section type won't crash the server, but the specific page/component involved will misbehave silently.
@@ -1,7 +1,7 @@
1
1
  # Generic and site-content-agnostic - this file never needs to change
2
2
  # per site. Runs identically via plain `docker build`/`docker run` on a
3
3
  # bare VPS, Fly, ECS, or any PaaS - nothing platform-specific is baked
4
- # in here (see docs/hosting.md for platform-specific deploy config,
4
+ # in here (see docs/guide-hosting.md for platform-specific deploy config,
5
5
  # which always layers on top of this, never inside it).
6
6
  #
7
7
  # Lives in vhost/, not the site root, alongside the rest of the site's
@@ -29,7 +29,7 @@ function buildSitemapUrls(config) {
29
29
  for (const relativePath of listFilesRecursively(config.pagesRoot, config.pagesRoot, '.json')) {
30
30
  // The 404 page must never be listed as a real crawlable URL,
31
31
  // regardless of its own published flag - it's a fallback
32
- // convention (docs/content-authoring-guide.md), not real content.
32
+ // convention (docs/guide-content-authoring.md), not real content.
33
33
  if (relativePath === '404.json') {
34
34
  continue;
35
35
  }
@@ -106,7 +106,7 @@ function pushFieldValue(blockType, instanceId, fieldKey, value, isDateField, out
106
106
  // Reads schema.properties for the given instance's own type, keeping
107
107
  // only properties explicitly flagged "api": true (an unvalidated,
108
108
  // theme-authored JSON Schema keyword - same status as "format"/
109
- // "allowedBlocks", see docs/theme-authoring-guide.md and
109
+ // "allowedBlocks", see docs/guide-theme-authoring.md and
110
110
  // services/validation.ts's own allowedBlockTypesOf) - and pairs each
111
111
  // with its actual value out of instance.settings via pushFieldValue.
112
112
  function extractInstanceApiFields(instance, schemaMap, out) {
@@ -40,14 +40,14 @@ function loadTypeSchemas(typesDir) {
40
40
  // A type whose required settings fields lack usable defaults is
41
41
  // skipped the same way a malformed schema block already is -
42
42
  // never a boot failure, just excluded from what gets registered
43
- // (theme-authoring-guide.md, Group L).
43
+ // (guide-theme-authoring.md, Group L).
44
44
  if (!requiredFieldsHaveValidDefaults(parsed.schema)) {
45
45
  continue;
46
46
  }
47
47
  schemas[type] = parsed.schema;
48
48
  // The only place "does this type support nested blocks" is ever
49
49
  // expressed - a markup convention (does the template loop
50
- // blocksHtml), not a schema field (theme-authoring-guide.md).
50
+ // blocksHtml), not a schema field (guide-theme-authoring.md).
51
51
  acceptsBlocks[type] = parsed.markup.includes('blocksHtml');
52
52
  }
53
53
  return { schemas, acceptsBlocks };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@o-a/cms-agent",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"