Reading and surfaces
Surfaces
A surface is a one-page Culm document that a product (the program that embeds Culm) draws inside its own web page while that page runs. The product sets a profile (the limits for one surface), changes the surface with checked operations, and gets back a patch (the data that says how the drawn surface changes). The mount, a script in the product's page, applies each patch and reports what the person using the product does.
This page is the behaviour reference. For setup, wiring and the page policy, see the package README. For a model writing operations line by line, and for the MCP Apps view, see generative-ui.md.
Profile and limits
A profile is { kinds, blocks, layout, elements, depth }, and may add pieces (see Package pieces).
Field
Rule
Field
kinds
Rule
A list of kind names. It must list column. A kind inside an allowed block must also be in kinds, or drawing that block is refused with surface.kind
Field
blocks
Rule
A list of block names the surface may hold
Field
layout
Rule
desktop, tablet or phone, drawn 1200, 800 or 390 px wide. Every vw length is rewritten to pixels of that width
Field
elements
Rule
A whole number from 1 to 160
Field
depth
Rule
A whole number from 1 to 8
A profile that breaks the column, layout, elements and depth rules is refused with INVALID_DOCUMENT, path profile. The drawn result is then held to the profile's own numbers: more elements or more depth than the profile allows is RESOURCE_LIMIT_EXCEEDED, path elements or depth, and the batch is not kept.
A batch holds at most 200 operations. data and setData hold at most 1,000,000 characters of JSON. Past either, the call is refused with RESOURCE_LIMIT_EXCEEDED. The measured figures are in limits.md.
Package pieces
A product can let a surface hold pieces (components) from a package it has approved. Culm does not prove the approval: the product approves the package first (approvePackage, or culm add and culm approve), and only passes pieces from packages it trusts.
import { createRegistry } from '@culmjs/core'
import { createSurface } from '@culmjs/surface'
import { loadFolder, openProject } from '@culmjs/tools'
const project = await openProject(dir)
const loaded = await loadFolder(dir, project.registry)
// An approved package puts ALL its pieces in `loaded.doc.components`, used or not, and the site's own pieces too.
// Pass only the ones you offer, picked by their package name.
const card = loaded.doc!.components.find(
c => loaded.map.packageRef(loaded.map.pieceFile(c.id) ?? '') === 'pkg/card',
)!
const made = createSurface({
registry: createRegistry(),
profile: { ...profile, pieces: [card.id] },
look,
id: 's1',
pieces: [card],
})profile.pieces and pieces use the component ids the folder loader derives (for example xmrepjlhpt3di), not pkg/card.
loaded.map.packageRef(loaded.map.pieceFile(id))maps an id to its pkg/card name.
The profile does not list instance in kinds: an instance is allowed when its component is in profile.pieces.
A name in profile.pieces that the product did not supply is refused at createSurface (INVALID_DOCUMENT, path profile.pieces). Two supplied pieces with one id are refused (INVALID_DOCUMENT, path pieces). A document with components is refused (surface.document).
A supplied piece the profile does not name is refused when an instance of it is added (surface.piece).
A piece holding an island is refused (surface.island). A surface runs no island.
The generating agent may place a supplied piece (an instance node) and set its settings and overrides. Those are checked on the unrolled tree, with the same rules as a plain node, so a link file, a layer, a fixed position, an image src or a password field cannot come in through an override. The agent never edits the piece's own tree: an operation aimed at { component: <id> } is refused (surface.piece), and so is an operation on any page but home.
In a stream the outline spelling places a piece as instance.i2 $component=<id>; the $ form sets the node's own field (component=<id> would be a setting, and is refused). The core spelling is { "op": "add", ..., "node": { "id": "i2", "kind": "instance", "component": "<id>" } }. describeSurface does not teach either spelling; tell the model in your own prompt.
The parts of an instance are drawn with ids <instance>.<part> (c1.title), and a press on a part's button reports that id as node.
The pieces are held outside the document: state().document.components is always []. Pass the same pieces again on restore, as you pass rows. Restoring without them is refused with a problem.
A piece may hold a button with an action: a surface allows an action on a node, and a press reaches onAction. culm add cannot take a package piece that has an action today (a site refuses it, surface.action), so a package piece cannot carry one through culm add; a product adds the action itself, or goes without.
Operations
Only these operations pass: add, setProps, setText, setStyle, move, remove, setAction, insertBlock and setBlockSetting. They work on the one page home, whose root is homeroot (surface.page on a created surface). Any other operation is INVALID_OPERATION, and the refusal lists the nine that are allowed.
insertBlock is limited to the profile's blocks; a block the profile does not list is refused with rule surface.block. Untouched sample text in an inserted block is not drawn.
Previous
Next