Contents

Open App Definition (OAD) 0.2: Core Specification#

Status: working draft.

The key words MUST, MUST NOT, SHOULD, SHOULD NOT and MAY are to be read as in RFC 2119.

1. What OAD is#

An app definition is a single JSON document that describes what an app does: the values it holds, the things it can do, when it does them, what it needs from the outside world, what it is permitted to touch, and how people and agents use it. A host loads a definition, binds real capabilities, enforces grants and serves surfaces. An AI writes and edits definitions; people and agents use the resulting apps.

Four principles are fixed:

  1. Intent over implementation. A definition says what the app does, never how a platform draws or runs it.
  2. Explicit, enforceable permissions. Nothing has an effect outside the app unless a grant covers it.
  3. Everything is versioned. The spec, catalogs, contracts and definitions all carry versions.
  4. Inspectable by any user. A person or agent can always see what an app does, what it touches and why.

2. The model in one page#

OAD is built around a kernel and projections of it.

The kernel is the app itself, with no user interface in it:

  • State: named, typed values. Stored, derived from other values, or sourced from a capability.
  • Actions: named, typed operations. Every outside effect, and every change to state that others share, is an action or runs inside one. The handlers and bindings of a visual surface write view state and the person's own state directly, and start everything else by running an action (section 12.2).
  • Rules: "when X, do Y". A trigger plus steps.
  • Flows: explicit state machines for multi-step processes.
  • Code: sandboxed pure functions for logic nothing else can express.

Around the kernel:

  • Capabilities: typed access to the outside world (data, devices, services), referenced by contract and bound by the host.
  • Grants: the permissions the app asks for. Every capability operation and every code module is gated by one.
  • Surfaces: projections of the kernel for a kind of user. A visual surface projects state into controls and events into actions. An agent surface projects actions into callable tools and state into readable resources. A voice surface projects actions into intents. Every surface is optional, and none of them holds logic.
  • Parts: other definitions included in this one.

A host runs a definition as an instance: one installation with its own state, issued grants and audit log, owned by one person or organization and used by its members (section 6.4).

Two consequences follow, and both are deliberate:

  • An app with no surfaces is still a complete app. A headless agent app and a visual app share one model.
  • Any action a person can trigger from a screen, an agent can call as a tool, subject to the same grants and the same guards. There is no second, weaker path for agents.

3. Document format#

  • A definition is a JSON document (RFC 8259), UTF-8, conventionally named *.oad.json.
  • JSON is the only canonical form. Tools MAY offer other authoring views, but interchange is JSON.
  • Named things live in objects keyed by name, not arrays, wherever order carries no meaning. This gives every element a stable JSON Pointer (/rules/warnOverBudget), which is what makes small, reviewable AI edits (RFC 6902 patches) reliable.
  • Names MUST match ^[a-z][a-zA-Z0-9]*$ and MUST NOT be one of the reserved words true, false, null and in. This applies to every key that names something: entries of state, actions, rules, flows, code, capabilities, grants, parts, roles and assets, views and their state entries, flow states, events, intents, field-map keys, local names bound by as, let and indexAs, and catalog or definition aliases. Type names in types MUST match ^[A-Z][a-zA-Z0-9]*$.
  • Capability aliases and part names share one namespace and MUST be distinct, because both appear before a dot in references such as bank.listTransactions and budget.logDeposit.
  • Unknown keys are an error at every level of the document. The one extension point is the top-level extensions object, keyed by a reverse-DNS namespace ("com.vendor.feature": {...}) whose values are objects. Hosts MUST ignore extension namespaces they do not understand. A top-level $schema key holding a schema URI or relative reference is permitted so editors can validate files.
  • description fields are part of the contract with users. They are the source of the plain-language explanation of the app (section 15). They are REQUIRED on actions, rules, flows, code modules and capabilities, and reason is REQUIRED on grants.

3.1 Top-level shape#

{
  "oad": "0.2",
  "id": "com.example.trip-savings",
  "version": "1.0.0",
  "meta": { "name": "Trip Savings", "description": "Tracks progress toward a savings goal." },
  "uses": { "catalogs": {}, "definitions": {}, "design": null },
  "types": {},
  "roles": {},
  "capabilities": {},
  "grants": {},
  "state": {},
  "actions": {},
  "rules": {},
  "flows": {},
  "code": {},
  "parts": {},
  "exports": {},
  "surfaces": {},
  "assets": {},
  "localization": { "default": "en" },
  "extensions": {},
  "included": []
}

Only oad, id, version and meta are required. Every other key defaults to empty, except localization: a definition without it declares no language (section 12.6). included holds the carried copies of what the definition refers to (section 4); it is not part of the app's own content and never part of its digest (section 16).

Key Meaning
oad Spec version the document targets, MAJOR.MINOR. 0.2 for this specification (section 16).
id Globally unique identifier in reverse-DNS form, lowercase, segments of [a-z0-9-], at least two segments. An id that begins with org.openappdefinition. names a document of the format itself (section 4).
version Semantic version (semver 2.0.0) of this definition.
meta name (required), description (required), and optional authors (array of strings), license (SPDX expression), tags (array of strings), icon (a name of the core catalog's icon vocabulary, its type IconName, as an icon control's name takes; contracts.md section 1), homepage (absolute URI), derivedFrom ({ "id", "version", "digest" } with digest optional, set when a definition is forked or remixed).
included Carried copies: whole definitions and design systems the file brings along so that it opens alone (section 4).

3.2 Values and expressions#

Many fields accept a dynamic value: a JSON value that may contain expressions.

  • A string that starts with = is an expression. "=state.goal - state.saved" evaluates to a number.
  • A string that starts with == is a literal string starting with a single = (the first = is removed).
  • Any other JSON value is a literal. Objects and arrays are walked recursively, so { "amount": "=input.amount", "note": "Deposit" } is a dynamic value.

Some fields are always expressions and are written without the leading =: derive, when, if, allow, where, becomes, each.in and the other fields this document marks as expression.

Some fields are paths: a reference to a writable location, such as state.form.amount. Paths are written without = and are marked path. A path names fields with dots. Where this document allows it, a path MAY also select one element of a list with a selector, [field=expression]: state.answers[id=item.id].note is the note of the first element of state.answers whose id equals the value of item.id, compared as == compares. The expression in a selector sees the roots of the position the path is in. Selectors are allowed in the targets of set, append, remove and patch (section 8.1) and in bind (section 12.2); a path with a selector anywhere else is an error (expression.syntax). The grammar of paths is in expressions.md, section "Paths". Fields of values an app writes through paths are named as identifiers; data from outside with other key shapes is read with index syntax (row["posted-at"]) and reshaped by an expression before it is stored.

The expression language is defined in expressions.md. In short: it uses a subset of the syntax of the Common Expression Language (CEL) plus template strings (`Saved ${state.saved}`), is side-effect free, has no loops or recursion beyond bounded macros over finite lists, and always terminates. expressions.md also gives every function a signature and says how types flow through expressions, and validation uses this to report operations and values that cannot be right wherever the types involved are known (validation.md).

3.3 Types#

A type reference is either a string shorthand or a JSON Schema object.

  • Shorthand primitives: string, number, integer, boolean, date (ISO 8601 calendar date), datetime (ISO 8601 timestamp with Z or a numeric offset; hosts produce UTC with Z), duration (ISO 8601 duration), any. Values of date, datetime and duration are strings in those forms (expressions.md, section "Date, datetime and duration formats"), so they conform wherever string is expected.
  • A name defined in this document's types: Transaction.
  • A type defined by a catalog, written alias:TypeName with an alias from uses.catalogs: finance:Transaction.
  • Suffix [] for a list and ? for nullable, list first: Transaction[], string?, finance:Transaction[]?. At most one of each is allowed; deeper nesting needs a named type.
  • A JSON Schema object (2020-12) restricted to: type (a JSON type name, or an array of them such as ["string", "null"]), properties, required, additionalProperties, items, minItems, maxItems, uniqueItems, enum, const, oneOf, format (date, date-time, duration or uri), minimum, maximum, minLength, maxLength, pattern, default, description, title and $ref. A $ref is #/types/Name for a type in the same document or, in a definition or in a catalog that declares uses.catalogs, alias:TypeName for a catalog type, and MAY appear wherever a schema object may, including inside items and properties. Members of oneOf SHOULD be objects told apart by a const property, so hosts and people can name the variants. The one other accepted pattern is a nullable reference: a $ref beside { "type": "null" }. Any other JSON Schema keyword is an error. A string type in a catalog's types MAY also carry known (contracts.md section 1).
  • A pattern is written in the restricted pattern dialect of expressions.md, section "Patterns", which can be matched in time linear in the input. A pattern outside the dialect is an error (type.invalid).

types is an object of type name to JSON Schema object.

A field map describes named inputs. It is used for action input, capability operation input, code module input, view input, control props and capability config:

{
  "amount": { "type": "number", "description": "Amount saved" },
  "memo":   { "type": "string", "description": "Optional note", "required": false },
  "kind":   { "type": "string", "description": "Deposit or withdrawal", "default": "deposit" }
}

type is required. required defaults to true. A field with a default is optional and MUST NOT also set required: true. The default is a literal JSON value, used when the field is absent. An optional field with no default that the caller leaves out is absent from the value: has(input.memo) is false and reading input.memo fails with missing, so such a field is read with has(input.memo) or default(input.memo, '').

3.4 Expression scope#

Expressions read from a fixed set of root names. Which roots are present depends on where the expression sits.

Root Holds Present
env The environment (section 3.5). Everywhere.
state Every state entry, by name. Everywhere except state initial, capability config and a grant's where.
sources For each sourced entry: { "status", "error", "updatedAt", "partial" } (section 7.1). Wherever state is, except a view state initial.
capabilities For each alias: { "available": boolean }. As sources.
grants For each grant request: { "held": boolean, "declined": boolean } (section 6). As sources.
flows For each singleton flow: { "state": name }. As sources.
parts For each part: { "state": { exported entries } }. As sources.
user The acting principal (sections 6.1 and 6.4.4). In derive, the principal the value is read for (section 7). Wherever state is.
input The action's input, or the operation input in a grant's where. Action allow, require, confirm, done and steps; grant where; voice reply.
output The output of the action an intent ran, or of the action whose done message it is. Voice reply; action done.
event The payload of the trigger or control event. In a flow, the with of the send that caused the transition, or null for an after transition. Rule if and do; flow transitions (if, allow, do) and enter and exit steps; visual handlers; voice announce.
view The current view's input values and view state, by name (view.requestId). Visual surface.
item, index The current element and its position. where of remove and patch, and with of a patch that has where (section 8.1); the transitions and enter and exit steps of a collection flow; each of a step, a node or a navigation section (item only when as is not given, index only when indexAs is not given).
error { "code", "message" } of the failed step. onError steps and orElse.

The base roots are env, state, sources, capabilities, flows, parts, grants and user.

A grant's where is the exception to the table: it sees only input and env, so a permission never depends on app state the app itself can change. validation.md, section "Expression scope", gives the roots at every position in a definition.

Local names bound by as (on call, run, code and each steps, on a node's each and on a navigation section's each), by a let step, and by indexAs (on an each step, a node's each and a navigation section's each) join the scope: for a step, the steps after it in the same list, including steps nested in them (for each, the steps of its body); for a node's each, the node, the nodes inside it and their event handlers; for a navigation section's each, the section's label, when, with, count and each.key. A local name MUST NOT be any root name in this table. Variables bound by list macros inside an expression are separate and MAY reuse any name (see expressions.md).

3.5 Environment#

env is read-only and supplied by the host.

Field Meaning
env.now Current UTC datetime. Fixed for the duration of an action. For derived values and view bindings the host refreshes it at least once a minute in each active session (section 6.4), and while an agent is connected. A refresh while no session is active tests no trigger and causes no source read (section 6.4.4).
env.today Current calendar date in env.timezone.
env.timezone IANA time zone name.
env.locale BCP 47 language tag of the locale that formats numbers, dates, relative times and plural categories. For a definition with localization, the formatting locale of env.language for the person (section 12.7), so that formats agree with the words beside them. For a definition without it, the locale the host gives for the person.
env.language The shown language (section 12.7): one of the app's own language tags. null when the definition has no localization.
env.direction 'ltr' or 'rtl': the direction of env.language (section 12.7); 'ltr' when that is null.
env.currency ISO 4217 code of the user's default currency, or null.
env.online Whether the host currently has network connectivity.
env.surface The surface the current invocation came from, or that is evaluating the expression for display (a view title, a prop, a node's when): visual, voice or agent. null for rules, timers and derived values.
env.invocation The id of the audit record (section 15) of the outermost invocation: the action invoked from a surface, the visual handler, the rule firing or the timer. It lets app records point at the audit log. null in derived values and wherever no invocation is running.
env.host { "name", "version" } of the host.

When an env field changes (online, today, or now when the host refreshes it), the host re-evaluates the derived values, bindings, becomes triggers and source with values that read it, as it does when state changes. A source whose with reads env.now is therefore read again each time now is refreshed, when its refresh.on includes change.

A definition without localization behaves as if these languages did not exist: env.language is null, env.direction is 'ltr', and env.locale is the person's locale as the host gives it. When the person's languages or the kept choice of language (section 12.7) change while the app runs, env.language, env.direction and env.locale change like any other env field. The host then treats env.language and env.locale as changed even where a value stays the same, because a text taken from another table of the text chain follows the person's languages directly.

4. Uses: catalogs, definitions, design#

"uses": {
  "catalogs": {
    "core": { "id": "org.openappdefinition.core", "version": "^0.2.0" }
  },
  "definitions": {
    "budgetApp": { "id": "com.example.budget", "version": "^1.2.0", "digest": "sha256-RBNvo1WzZ4oRRq0W9-hknpT7T8If536DEMBg9hyq_4o" }
  },
  "design": { "id": "com.example.brand", "version": "^2.0.0" }
}
  • catalogs maps a local alias to a catalog id and a semver range. Controls and capability contracts are referenced as alias:contractName (core:list). The core catalog's controls, with their props, events and slots, and its capabilities, with their operations, are described in catalogs/core/README.md.
  • definitions maps a local alias to another definition, by id and semver range. digest is optional and pins exact content (section 16). source is an optional URI hint for where to fetch it.
  • design optionally references a design system (section 12.4).
  • Version ranges use a subset of node-semver syntax: exact versions, comparators and space-separated comparator sets (>=1.2.0 <2.0.0), caret and tilde ranges, x and * wildcards, hyphen ranges, and || alternatives.

Hosts resolve these references. A reference of definitions or design is looked up first among the carried copies (below). Otherwise, how a host locates a catalog or definition by id (registry, local folder, bundle) is outside this document. A catalog the host cannot find does not by itself fail the load (section 14).

Carried copies. A definition MAY have a top-level member included: an array of whole documents, each a definition or a design system, called its carried copies. They let one file hold what it refers to, so that it opens alone wherever it is handed. A catalog is never a carried copy: a catalog names what a host itself provides, and no file can bring that along.

  • included changes where a reference of uses.definitions and uses.design is looked up, and nothing else. A reference written in a document is looked up first among the carried copies of the file the document came in, then where the host looks otherwise.
  • The file a document came in is: for the definition a host or tool was given, that document; for a carried copy, the document that carries it; for a definition the host found elsewhere (a registry, a folder, another draft), that definition itself, with its own included if it has one. The copies a file carries therefore serve that file and the copies in it, and no other document: a definition found elsewhere does not see the carried copies of the app that includes it.
  • Among the carried copies of the right kind with the referenced id, the one with the highest version that satisfies the range is chosen. When one is chosen, no other place is consulted for that reference, even when another place holds a higher version that fits, so the same file opens as the same app everywhere. When none fits, the lookup goes on as it would without included.
  • A pinned digest is checked against the chosen copy exactly as against a definition found elsewhere. A mismatch is an error (uses.digestMismatch in validation.md); the lookup does not go on to another place.
  • included is flat: a carried definition MUST NOT have an included of its own, and a document of one kind, id and version is in the list at most once. A tool that writes the carried form puts the copies of copies in the one list.
  • A carried copy serves only the document that carries it. A host or tool MUST NOT put a carried copy into any store from which the references of other apps are resolved, and MUST NOT take it for the definition of an instance because its id matches (section 13).
  • A carried design system MAY name a catalog of custom controls as any design system may; the host resolves that catalog as always.
  • An id that begins with org.openappdefinition. belongs to the format: it names a document of the format itself, such as the core catalog org.openappdefinition.core and the default design system org.openappdefinition.design.default, which every host provides. Such a document is never carried. A carried copy MUST NOT have such an id (included.reserved in validation.md), a reference to such an id is never looked up among the carried copies but where the host looks otherwise, and a tool that writes the carried form leaves such a document out. A file therefore cannot bring a default design system of its own, and a written file does not hold the look to the default design system of the day it was written.

A tool that writes the carried form of a definition sets included to exactly what the definition's references reach: every definition a part of the app, or a part of a part, resolves to, once each, and every design system the app or one of those definitions names that resolves, the format's own documents left out. A copy nothing reaches is dropped. Two different documents that claim one kind, id and version (their digests differ) cannot both be carried: the tool writes nothing and names both, with the references through which each was reached. It writes the definitions first and then the design systems, each ordered by id and then by version in ascending order of precedence, so that the same app is written as the same bytes, and it changes no other member of the document, so the digest stays the same (section 16).

5. Capabilities#

A capability is typed access to something outside the app. A definition never names a provider or protocol. It names a contract from a catalog, and the host binds any provider that implements that contract. This is what lets a definition move between hosts.

"capabilities": {
  "bank": {
    "contract": "finance:accounts",
    "description": "Your bank accounts, used to read deposits into savings.",
    "config": { "accountKind": "savings" },
    "required": true,
    "prefer": ["com.examplebank.connector"]
  }
}
Field Meaning
contract alias:name of a capability contract. Required.
description Why the app uses it, in plain language. Required.
config Dynamic value matching the contract's config field map, with only env in scope. Evaluated once, when the capability is bound for the instance, with the owner's env, and kept until an update. A required field MAY be left out for the host to supply (below).
required Default true. When false, the app loads without it and capabilities.<name>.available is false in expressions.
prefer Optional ordered list of provider ids. A preference, never a requirement: the host and user have the final say over which equivalent provider is bound.

Capabilities have operations (called by steps), and MAY have events (which trigger rules). Both are declared by the contract (see contracts.md).

Configuration left to the host. A definition MAY leave out a required config field, such as the collection an organization keeps its tickets in, so that the definition can be shared without it. The host supplies the value when it binds the capability, from the owner or from host policy; for a personal capability, each person supplies it when they answer its requests, or host policy does. Leaving one out is not a validation error. The resolution report shows the value supplied, and it is part of what the approver answered (section 6, rule 5). A host that has no value reports the capability as missing (section 14).

Personal capabilities. A capability whose contract has the personal trait (contracts.md section 4) acts for one person: their device, their accounts, their files. Grants on it are answered by each person for themselves (section 6.4.2).

File references. A file reference (the core catalog's FileRef) is a handle the host issued; it identifies a file without containing it. Its id MUST be unguessable: at least 128 random bits.

  • A file reference in an operation input, at any depth of the input type, that the contract types as the core catalog's FileRef is resolved by the host, so the provider receives a file it can read. A contract in another catalog names that type through its catalog's uses (contracts.md section 1).
  • A file reference in an agent's tool input MUST be one the host issued to that agent for this instance: one the agent received from this instance (in a tool's output or a resource), or one the host gave it for a file the agent handed over. The check applies to every field typed as a file reference, at any depth of the input type, and a host SHOULD apply it to any value that carries the host's own reference form, whatever its declared type. Anything else is refused as invalid input (action.invalidInput).
  • A file reference stays readable for as long as the instance's stored state holds it, across restarts. A host that cannot keep the file MUST NOT leave the reference in state looking valid: reading it fails, and controls that show it show their fallback.
  • A file reference kept in shared state shares that file with every member whose grant covers reading it.
  • A host SHOULD give agents a way to hand a file to the host and get a reference back. How is up to the adapter.

6. Grants#

The grants section lists what the app asks for. It never contains issued permissions: those are created by the host when a person approves, and they live with the host, not in the file. Who answers a request, and whom the issued grant covers, is set out in section 6.4.2.

"grants": {
  "readSavings": {
    "capability": "bank",
    "scopes": ["transactions.read"],
    "reason": "Read deposits into your savings account to track progress.",
    "rate": { "count": 24, "per": "P1D" },
    "duration": "P90D",
    "required": true
  },
  "readTickets": {
    "capability": "helpdesk",
    "scopes": ["http.read"],
    "reason": "Fetch open support tickets.",
    "where": "input.path.startsWith('/v1/tickets')"
  },
  "lookUpManagers": {
    "capability": "people",
    "scopes": ["directory.read"],
    "operations": ["manager"],
    "reason": "Find the manager who approves each request."
  },
  "scoring": {
    "code": "scoreWord",
    "reason": "Runs a small scoring function for the game."
  }
}
Field Meaning
capability or code Exactly one. The capability alias or code module name the request covers.
scopes For capabilities: scope names defined by the contract. Required and non-empty.
operations For capabilities: a non-empty list of names of operations and events of the capability. Optional. The issued grant then covers only those operations and events, within its scopes, and the list is shown to the approver. Each name MUST be an operation or event of the capability whose scope is one of scopes (grant.operationUnknown).
reason Plain-language justification shown to the approver. Required.
where Expression over input (the operation input) and env. A call is permitted only if it evaluates to true. input is the operation input after the contract's defaults are applied, so a field the call left out reads as its default. Optional. This is also how a permission is narrowed by an input value, for example input.precision == 'approximate'.
rate { "count", "per" } with an ISO 8601 duration. Optional. Counted per issued grant: per instance for an instance grant, per person for a personal grant (section 6.4.2). Every request has its own rate, a part's included (section 13).
duration Longest lifetime requested for the issued grant. Optional; hosts MAY shorten it.
required Default true. When false, the app loads if the request is declined, and operations it would have covered fail with grant.denied.

A request that names code MAY set only reason, rate, duration and required.

Knowing what was granted. grants.<name>.held is true while an issued grant for request <name> is in force for the principal acting: the instance's grant for an instance request, or the grant of the acting principal's person for a personal request (section 6.4.2). grants.<name>.declined is true while a decline of the request stands for that same instance or person: someone entitled to answer said no, or a grant for it was revoked (rule 4), and nobody entitled has allowed it since; or the including definition declined a part's request (section 13). A request that has not been answered yet, or that is asked again because it changed, is neither held nor declined, and so is one that went unanswered only because nobody entitled was present (rule 6). An app offers what an optional request would allow while the request is not declined, so that a person's use of it can bring the question ("When a request is asked", below), stops offering it once they have said no, and shows what depends on the grant only while it is held. The grants root is present wherever state is, and never in a grant's where. A part sees its own requests, under their own names.

Enforcement rules:

  1. A host MUST refuse a capability operation unless an issued, unexpired, unrevoked grant covers it: the grant was issued for a request of the definition whose steps made the call (section 13), it is held for the principal acting (section 6.4.2), it includes the operation's scope and, when its request lists operations, names the operation, it satisfies where, and the call is within rate. Likewise a host MUST NOT deliver a capability event to the app unless such a grant covers the event's scope and, when its request lists operations, names the event. A grant's where narrows events as it narrows operations: it is evaluated with input set to the event payload, and an event for which it is not true, or cannot be evaluated because the payload lacks a field it reads, is not delivered. Delivery does not count against rate.
  2. A host MUST refuse to run a code module without an issued grant naming it. When it runs a module, it MUST refuse to run it unless the module's text is the text the grant was issued for.
  3. The definition's requests are an upper bound. A host MUST NOT issue the app more than it requested.
  4. Issued grants are scoped, time-limited and revocable. An instance grant is revoked by the owner; a personal grant by its person or by the owner. Revocation takes effect before the next operation, and leaves the request declined: it is not asked again, and nothing is issued for it, until a person entitled to answer allows it.
  5. A grant answers one request as it was put to the approver. A host that keeps grants between runs MUST treat a kept grant as covering a request only while what the approver would be asked now is what they were asked then: the request itself, the capability it names (its contract, its config, including values the host supplied when binding it, the origin it reaches, and whether its provider keeps the request inside the app) and, for a code request, the module's text. When any of these has changed the host MUST withdraw the kept grant and ask again, and SHOULD tell the approver that the request replaces one they answered before. For a request that needs no answer ("When a request is asked", below), the host withdraws the kept grant and issues a new one without asking. A kept grant for a request the definition no longer makes MUST be withdrawn. Narrowing chosen by the approver is not a change: a grant issued narrower than its request stays in force while the request is unchanged. A reason written as a reference to a text (section 12.6) counts as the text the approver was shown: the host keeps, with a kept grant, the language whose text it showed, and the grant holds while the reason's text in that language is unchanged. Adding a language, or editing another language's text, does not ask again; editing the text the approver read does. A reason written as plain text is compared as it is. Section 6.4.1 applies this rule to updates.
  6. A request that needs an answer ("When a request is asked", below) is answered by a person entitled to answer it (section 6.4.2) who can see it. A host MAY hold the review until such a person is present. When nobody entitled is present to answer (an agent served on its own, a run without a screen), a request that was not answered earlier is declined; a host MUST NOT approve it on that person's behalf. A request declined because nobody entitled was present is declined for that use only, and is asked again when such a person is present.

When a request is asked. Every question costs a person attention, and a person asked too often stops reading. A host asks where an answer protects something, once, and in plain words.

  • Given by use. A contract MAY mark a scope as given by use (contracts.md section 4): nothing happens under it unless a person does it themselves at that moment in the host's own interface, such as choosing a file or taking a photo, or has already handed the app the thing acted on. A request whose scopes are all given by use needs no answer. The mark is a catalog's promise, so it counts only from a catalog the host trusts to make it: the core catalog, and any other that the host's operator or the person has chosen to trust. A scope marked by any other catalog is asked like any other scope.
  • Contained. A request is contained when everything done under it stays inside the app, so that an answer would protect nothing. A request that names code is contained: its module is a pure function run in the host's sandbox, with no network, storage, clock or host object (section 11). A capability request is contained when the provider the host binds for it promises, for every scope the request names, that everything done under that scope stays inside the app: the provider gives the app nothing that belongs to a person or to anyone else outside the app (data made for a demonstration belongs to nobody), changes nothing outside the instance's own state and what the host shows for this app, reaches no network, no other program and no other person, cannot cost anyone money, and does nothing once the host no longer runs the app. A provider that reaches the web, a real account, a real device sensor, another person or the device's own notifications does not keep that promise. What a person turns on themselves in the host's own interface, such as having the app's notices also shown by their device, is that person's choice made with the host, and not something the provider reaches. Only the host makes the promise, through the provider it binds, about what that provider really does; nothing a definition or a catalog says makes a request contained, and neither a scope's sensitivity nor a contract's traits change whether it is. A contained request needs no answer.
  • Without an answer. Wherever this document says a request is asked, the host instead issues the grant for a request given by use or contained without asking, and records that nobody was asked: when the instance is installed for an instance request, when work on a person's behalf first needs it for a personal request (whether that person or an agent of theirs started the work), and again when the request has changed (rule 5) or its grant has expired. It does so also when nobody entitled to answer is present, since there is nothing to answer (rule 6). The grant is otherwise a grant like any other: issued for the module's text for a code request (rule 2), limited by the request's operations, where, rate and duration, shown with the app's other grants, and revocable. Once it is declined or revoked, nothing is issued for the request until a person entitled to answer allows it in the host's own interface. A host MAY ask for a request given by use or contained all the same.
  • Required requests. Any other request with required: true is asked before the load completes for the person who answers it.
  • Optional requests. Any other request with required: false MAY be left unanswered when the app loads. The host then asks it later, at a moment of its choosing, while a person entitled to answer is present. When work makes a call that an unanswered request would cover, the host MAY hold the call and ask, and it MUST do so when a person entitled to answer started that work from a surface of theirs that is still active. Holding the call does not hold the instance (section 8.2, "Waiting on a person"). The call continues if a grant is issued that covers it. Otherwise, and whenever the host does not ask, the call fails with grant.denied. A host that shares an instance among several people SHOULD put its optional instance requests to the owner at install, since no member can answer them.
  • Once. An answer stands until the request changes (rule 5), its grant expires, or the person who gave it changes it. A host MUST NOT ask again for a request whose decline stands; the person changes their answer in the host's own interface. When a person opens an app that cannot load because a required request of theirs stands declined, the host says which request that is and lets them change the answer there.
  • Plainly. A host MAY put all the requests it asks at one moment to the approver together and take one act as the answer to all of them. What the approver sees names each request in the words of its scopes, keeps its reason and limits within reach, and sets apart the requests that deserve a closer look: a scope of high sensitivity, a provider that may charge, a capability with the background or egress trait, a code module where the host asks for one, and a request that replaces one the approver answered before.

6.1 Principals and delegation#

A principal is a person, an agent or an app. Expressions see the acting principal as user: { "id", "kind": "person" | "agent" | "app", "name", "roles": [...], "onBehalfOf": principal or null, "person": { "id", "name" } or null }. A principal's person is the principal itself when it is a person, and otherwise the person at the end of its onBehalfOf chain, or none when the chain reaches no person; user.person gives it. A definition that records who owns something, or compares a stored person id with the caller, uses user.person.id, so that work an agent does for a person belongs to that person and an agent acting for the person passes the comparison. It compares with user.id only where the person themselves must act. A principal holds full access when its access says every action, as the owner's does, as a member's does unless host policy narrowed it, and as a delegation of all of such an access does. An access that lists actions is never full access, even when the list names every action the definition has today. Which principal acts at each point is set out in section 6.4.4.

Delegation is attenuation only. A principal MAY delegate a grant it holds to another principal, and the derived grant MUST have: scopes that are a subset of the parent's, an expiry no later than the parent's, and constraints (where, rate) no looser than the parent's. Revoking a grant revokes everything derived from it. A host MUST record the delegation chain and MUST be able to show it.

To use an app, a principal needs access to its actions. The owner of an instance holds access to all of them; a member holds the access the host's policy gives them (section 6.4). Access names what can be invoked from outside a definition: its actions that are not internal, and an action that one of its parts exports, as part.action. An action that cannot be named this way, an internal action or an action of a part that the part does not export, is reached only through the steps and visual handlers of the definition that holds it and needs no access of its own: a person who uses a view runs what its handlers run, subject to each action's allow, require and confirm. A person MAY delegate access they hold to an agent for a subset of actions and of the resources an agent may read (section 12.1), optionally time-limited. Limits on resources bind agents: a person who holds access to an instance sees what its surfaces show them. When an agent builds an app for another agent, the grants the new app requests MUST be approved by a principal that itself holds them and is allowed to delegate them, so approval always traces back to a person or organization policy.

Approval. Who answers a grant request is set out in section 6.4.2. A person entitled to answer MAY delegate the answer to an agent for that contract; an agent never approves a request to run code. A request put to an approver that receives no decision is declined for that use only, as one that could be put to nobody is (section 6, rule 6). onBehalfOf records for whom a principal acts and lends it nothing: an agent has exactly the access, and the roles, delegated to it (section 6.4.3). A capability or code grant belongs to the instance, or the person within it, it was issued to (section 6.4.2), and cannot be delegated to another holder.

Agents and surfaces. An agent uses an app only through its agent surface (section 12.1). A host MUST NOT let an agent run a visual handler or write a binding, whatever access the agent holds.

6.2 Roles#

"roles": {
  "finance": { "description": "Gives final approval and releases payment." },
  "director": { "description": "Decides requests that waited too long for a manager." }
}

roles declares the role names the app's guards refer to, each with a required description. A definition never says who holds a role: the host assigns roles (section 6.4.3) and exposes them as user.roles. A definition SHOULD declare every role its guards test.

A role says what a principal may do anywhere in the app. A relationship between a principal and one record, such as "this request's manager", is not a role: store it on the record and compare it with user.person.id (section 6.1), or with user.id where the person themselves must act, as the manager's approval in section 10 does with managerId.

6.3 Egress#

A network request made in order to present or run the app is an outside effect even when no step asked for it: loading an image, map tiles, a font or media named by a control prop, or prefetching a link. Such a request could carry app state to a third party inside its address.

  • A host MUST NOT make such a request unless the app holds a grant, on a capability whose contract declares the egress trait, whose configured origin matches the request. In the core catalog that capability is http, with scope http.read.
  • The grant's where and rate apply to such a request as they would to a read operation, with input being { "path", "query" } of the requested address.
  • A grant request that carries operations (section 6) permits egress only if its list names an operation whose effect is read. Without operations, the rule above applies unchanged.
  • Control contracts mark props that can cause requests with remote: true (see contracts.md). Hosts and validators use the mark to find every place egress can occur.
  • A value in such a prop is a remote address when it is an absolute http or https URL. Loading it is egress, under the rules above.
  • A value is an asset reference when it is the string asset: followed by an asset name, such as asset:logo. It refers to the asset of that name in the definition the control belongs to: for a view of a part, the part's own definition (section 12.5). Loading an asset is not egress and needs no grant. An asset reference that names no entry of that definition's assets MUST NOT be loaded.
  • Every other value MUST be a reference the host itself issued, such as the uri of a file reference returned by a capability or the name of a resource bundled with the host. Loading content the host already holds is not egress and needs no grant. A reference is good only for the app instance the host issued it to.
  • A value of none of these three kinds MUST NOT be loaded.
  • The rule is enforced when content is loaded, whatever a validator reported, so an app that holds no egress grant can never cause a request. An app that shows only its own assets and content the host holds requests no egress grant.
  • Following a link is a user action, not egress, provided a person activates it and the host shows the destination before leaving the app.
  • Fetching a resource the definition or a catalog pins by digest, such as a control's implementation module or a code module's module.uri, is the host's own act when it installs the app, checked against the digest (section 16). It is not egress and needs no grant.
  • A refused request fails with egress.denied, and the control shows its fallback or its accessible label.

6.4 Instances#

An app instance is one installation of a definition on a host: its state, its issued grants and its audit log. A definition can have many instances, on one host or several, and they share nothing.

An instance has one owner: the person who installed it, or the person or organization the host's policy names. Where this document says the owner answers or acts, an organization does so through a person or a policy acting for it. Other people who use the instance are its members. How people come to use an instance, such as by invitation or through a directory group, is host policy. The owner holds access to every action (section 6.1). Unless host policy says otherwise, a member holds access to every action that is not internal, the actions its parts export included. A person who holds no access to an instance cannot load it: the load fails with instance.forbidden, and nothing of the instance's state or audit log is shown. Access that is taken away or runs out ends at once: the host ends the sessions of a principal that no longer holds access, shows it nothing further, asks it nothing, and runs nothing on its behalf.

A session is one principal's use of an instance through a surface on one device, from when it opens the app until it closes the app or the host ends the session. Locking the device or moving the app to the background does not end a session. A person using an instance on two devices has two sessions. The session's person is the person of its principal (section 6.1).

A surface is active while a person has it open. A session is active while its surface is, and the app is active while any session is. An agent's connection alone does not make the app active: every rules, flow after timers and timed source refreshes need a person's active session (section 6.4.4 says whose) or a background grant (section 9). An agent's own calls run whenever it makes them.

6.4.1 Updates#

The host records the version and digest of the definition an instance runs, including the versions and digests of the parts it resolved. Running the instance with a definition of the same id and a different digest is an update, and so is a change in any part the instance resolves.

  • Only the owner may update an instance. Anyone else who presents a different definition for it is refused with instance.forbidden, and the instance keeps the definition it runs.
  • The host MUST record an update in the audit log: who updated, the previous and new version and digest, and for each part whose definition changed, its path and its previous and new id, version and digest (only the side that exists for a part that is new or gone). It SHOULD show the owner what changed before applying it. An update that adds no request and changes nothing an approver answered (section 6, rule 5) asks nothing.
  • Kept grants follow section 6, rule 5: a grant stays in force only while its request is unchanged. A changed request is asked again as a new request would be (section 6, "When a request is asked"): an instance request of the owner, a personal request of each person.
  • A stored entry the new definition adds gets its initial, evaluated at the update (section 7). A stored value that no longer conforms to its entry's type under the new definition is replaced by the entry's initial, evaluated at the update. Flow state is treated the same way: a collection element whose flow field names a state the new definition no longer declares, or a singleton flow in such a state, is put in the flow's initial state without running enter steps. The resolution report says which entries were replaced and which flow instances were reset. The host SHOULD keep the replaced values, and the values of entries the new definition no longer declares, where the person they belong to can retrieve them: shared values for the owner and a user value for its person. device and session values are not kept. A member SHOULD be told, at their next use, that the definition changed, also when only a part changed.
  • A host MAY refuse an update that does not descend from the running definition, judged by its history (section 16) or its signer (contracts.md section 7).

6.4.2 Personal and instance grants#

Every grant request is either personal or for the instance.

  • A request on a capability whose contract has the personal trait is a personal request. Each person answers it for themselves: the first time they use the instance when it is required, and otherwise when section 6 says it is asked. The grant issued covers only operations done on that person's behalf: by the person, by an agent acting for them, or by the app acting on their behalf (section 6.4.4). Its rate is counted per person.
  • Every other request, including every code request, is an instance request. The owner answers it once, when it needs an answer. The grant issued covers the instance, whoever is using it, and its rate is counted per instance. Members are not asked; a member can see the instance grants at their first use and whenever they look.
  • A request given by use or contained is answered by nobody (section 6): its grant is issued for the instance, or for each person, without a question.
  • A request that needs an answer when nobody entitled to answer it is present is declined for that use only (section 6, rule 6). A request that is waiting to be asked is neither held nor declined.
  • A member for whom a required personal request is declined cannot load the app; others are unaffected. A required instance request the owner declined fails the load for everyone.
  • A principal that acts for no person holds no personal grant. An instance with a required personal request does not load for it, and a call it makes on a personal capability fails with grant.denied.
  • With one person, nothing changes: the owner is that person and answers everything.

An operation is done on a person's behalf when the person of the principal acting (section 6.1) is that person. A capability event on a personal capability is delivered under the grant of the person it concerns, and the rules it fires act on that person's behalf. contracts.md section 9 lists which core capabilities are personal.

6.4.3 Roles in an instance#

The owner assigns roles. The owner holds every declared role unless host policy assigns otherwise. A member holds the roles the host assigns, whether they come from the owner, from organization policy or from a capability with the multiUser trait (such as a directory), and none by default. A host that takes roles from a capability decides how the capability's roles map onto the app's; a definition cannot assume that a directory role is the app role of the same name. When a person delegates access to an agent (section 6.1), the delegation MAY include roles the person holds; the agent then holds exactly those, and none by default. A delegation can never carry a role its giver does not hold. The app principal holds no roles.

6.4.4 Who acts#

Every expression that reads user, and every grant check, uses the principal acting at that point:

Work Acting principal
An action invoked from a surface (a voice intent, an agent's tool call, a run in a visual handler), and a visual handler's own steps. The invoking principal.
A flow transition taken because of a send, with its exit, do and enter steps. The principal whose steps sent the event. user in the transition's allow is that principal.
A rule fired by a write made by work that has an acting principal (an action invoked from a surface, a rule's steps, a transition's steps), or by an app event such work raised. The app principal, on behalf of that principal's person. The trigger is tested, and the rule fires, once, with the values of that person and of the work's session when it has one.
A rule fired by the result of a source read. The app principal, on behalf of the person the value belongs to. The trigger is tested, and the rule fires, once, with that person's values and those of the session that occasioned the read when there is one.
A rule fired by a change of the environment of an active session (env.online, env.today, env.now when the host refreshes it, or another env field). The app principal, on behalf of the session's person, in that session, with its values. Each session has its own environment, so the same rule can fire in several sessions. With no active session and a background grant held, the environment is the host's own and the rule fires once for the instance, on behalf of the owner.
An every rule. The app principal. It fires once per interval in each active session, on behalf of that session's person; with no active session and a background grant held, once per interval for the instance, on behalf of the owner, unless the rule says "foreground": true (section 9), in which case it does not fire.
A lifecycle rule. The app principal, on behalf of the session's person.
A source read. The app principal, on behalf of the person whose value it reads; section 7.1 says whose values each occasion reads.
A flow after transition, with its steps. The app principal. It is taken once per flow instance; its event is null, and its flow:<name> payload has "event": null. A singleton flow, or a flow over a shared collection, acts on behalf of the owner, and its timers run while the app is active or a background grant is held. A flow over a collection that is not shared acts on behalf of the person whose collection holds the element, and its timers run while that person has an active session or a background grant is held.
A rule fired by an event of a personal capability. The app principal, once, on behalf of the person under whose grant the event was delivered.
A rule fired by a capability event that its contract says belongs to a person. The app principal, once, on behalf of that person. In the core catalog a scheduler wake belongs to the person on whose behalf it was scheduled (contracts.md section 9).
A rule fired by any other capability event. The app principal, once in each active session, on behalf of that session's person; with no active session and a background grant held, once for the instance, on behalf of the owner.
becomes, source.with, source.when and a part's with. The app principal, on behalf of the person of the place where it is evaluated: the work that made the change, the person whose value is read, or the session whose environment changed.
A derived value, a view title, prop or binding, a navigation section's label, when, with or count, a navigation group's heading or when. The principal for whom the value is read (section 7).

Actions that a run step runs, and transitions that a send step causes, act as the principal of the steps that ran or sent them.

Where triggers are tested. A becomes or changes trigger is tested where a change happens, by comparing its value before and after that change, with the values of that place. There are exactly three kinds of change: a write made by work that has an acting principal, the result of a source read, and a change of the environment of a session (the rows above). A scheduler wake or a capability event changes state only through a rule's steps or a source read, and so through one of these.

  • A change made in one place fires no rule in another. When one person's write makes a trigger true for another person as well, no rule fires on the other person's behalf: nobody's action makes the app act under another person's grants.
  • With no session, session and device entries hold their initial values and env is the host's own.
  • An event for a person who has no active session is delivered only when a background grant is held.
  • An effect that must happen once for a person, or once for the instance, carries once (section 8.3).

A principal with no person. Where this section speaks of a principal's person and the principal has none (section 6.1), the principal itself stands in that place: user, device and session values and sourced values are kept for that principal, and the app principal acting for its work has user.onBehalfOf set to that principal and user.person null. A principal with no person holds no personal grant, so a call on a personal capability fails with grant.denied.

For the app principal, user.kind is app, user.id is the id of the definition whose rule or flow is running (a part's own id inside a part), user.name is that definition's meta.name, user.roles is empty, and user.onBehalfOf and user.person are the person it acts for. Since a rule never acts as a person, anything that identifies the person who acted, such as who filed a record, is captured in the action they invoked or read from user.person.

7. State#

"state": {
  "goal":      { "type": "number", "initial": 5000, "description": "Savings target" },
  "startDate": { "type": "date", "initial": "=env.today", "description": "Day saving started" },
  "deposits":  { "type": "finance:Transaction[]", "sensitive": true, "source": { "call": "bank.listTransactions", "with": { "since": "=state.startDate" }, "refresh": { "every": "PT1H" } } },
  "saved":     { "type": "number", "sensitive": false, "derive": "sum(default(state.deposits, []).map(d, d.amount))", "description": "Total saved, which may be shown without the transactions behind it" },
  "remaining": { "type": "number", "derive": "state.goal - state.saved" }
}

Each entry is exactly one of three kinds:

  • Stored: has initial or no kind key at all (starts as null). initial is a dynamic value with env in scope. It is evaluated once, when the instance is created, and the result is stored: every later load, and every value of the entry that starts later (a new person's user value, a new session's session value), starts from that same result, so a start date stays the day the app was installed. An entry that an update adds is evaluated at that update (section 6.4.1). Written by steps and by bindings; a shared entry only by actions (section 8.1). A write whose value does not conform to the entry's type fails with state.invalidValue.
  • Derived: has derive (expression). Recomputed when any value it reads changes. Read-only. Derived values MUST NOT form a cycle; this is a load-time error. A derived entry read during an action reflects that action's pending writes. Inside derive, user is the principal for whom the value is read: during an action, a rule, a flow transition or a can or canSend evaluation, the acting principal (section 6.4.4); on a visual or voice surface, the person using it; for an agent reading a resource, the agent. A derived entry that reads user therefore has one value per principal. To follow the person an agent or the app acts for, read user.person. env.surface and env.invocation are null in derive. A derive that fails, or whose value does not conform to type, yields null and a diagnostic (section 17).
  • Sourced: has source. The value is the output of a capability operation (section 7.1). Read-only.

Common fields:

Field Meaning
type Type reference. Required.
description Recommended.
scope Stored entries only. Where the value lives: session (one value per session, gone when the session ends, section 6.4), device (one value per person on each device; another person using the same device does not see it), user (default; one value per person, following them across devices), shared (one value for the whole instance).
sensitive Whether the host keeps the value out of view (section 7.3). Default false, except for a derived entry that reads a sensitive entry.
internal Default false. When true, the entry is never an agent resource and never an export. Naming it in resources.include or exports.state is an error (state.internal).
conflict Stored entries with user or shared scope only. How concurrent or offline writes resolve: lastWrite (default), merge or reject (section 7.2).
key Stored entries with conflict: "merge" only. The field that identifies elements when a list value is merged.

Ownership. State belongs to the instance and the people who use it, never to the definition's author: a user value to its person, a shared value to the instance and so to its owner. The host stores it. A definition file carries no user data; initial is seed data and SHOULD be small.

Texts keep their language. A text in the app's languages (section 12.6) that is written into state, sent, as in a notification, or recorded in the audit log is a plain string in the language of the moment it was made, and stays in that language when the shown language changes later.

7.1 Sources#

"openTickets": {
  "type": "core:RecordPage",
  "source": {
    "call": "tickets.list",
    "with": { "filter": [ { "field": "team", "op": "eq", "value": "=state.teamId" } ], "limit": 500 },
    "when": "state.teamId != null",
    "pages": 10,
    "refresh": { "every": "PT1H", "on": ["open", "change", "tickets.changed"] }
  }
}
Field Meaning
call alias.operation of an operation whose effect is read and that is not interactive. Required.
with Dynamic value: the operation input.
when Expression. Optional. The entry is read only while it is true; otherwise its status is idle and its value is kept. A when that becomes true causes a read.
pages Integer from 1 to 50, default 1. How many pages to read and join (below). A value above 1 needs an operation that declares paging (contracts.md section 4); otherwise it is an error (state.sourceNotPaged).
refresh { "every", "on" }. Optional. every is an ISO 8601 duration. on lists occasions: open, change (when the value of with or when changes) and capability events written alias.event. on defaults to ["open", "change"] whenever it is absent, also when every is given.
  • A sourced entry has one value per person, read on that person's behalf (section 6.4.4). Each occasion reads these persons' values:
    • open: the value of the person whose session opens.
    • change: with and when are evaluated for each person, and a change for a person reads that person's value.
    • refresh.every: the value of each person who has an active session, once per interval for each; with no active session and a background grant held, the owner's value.
    • A capability event named in on: the values of the persons the event reaches (section 6.4.4).
    • A refresh step: the value of the acting principal's person.
  • The value is null until the first successful read, whatever type says. After that it is the output of the latest successful read. While loading, or after a failed read, the previous value is kept.
  • type MAY be narrower than the operation's output. An output that does not conform to type is a failed read with state.invalidValue.
  • At most one read per entry and person is in flight. A trigger that arrives during a read causes exactly one more read after it.
  • A read caused by what another read returned, because a with or when reads a sourced entry directly or through derived values or the writes of rules, is a level of a cascade as a rule is (section 9). A read that would be made more than 16 levels below the work that started the cascade is not made, and rule.cascade is recorded in the audit log against that work. So a sourced entry whose with reads its own value settles and does not read without end.
  • A read that would exceed the grant's rate is put off until the rate allows; it does not fail.
  • refresh.every runs while no surface is active only when the app holds a grant on a capability with the background trait, as an every rule does (section 9).
  • The host keeps the last value read, for the person it was read for, so after a restart the entry holds that value while it loads. A becomes trigger sees no edge for values restored at load (section 9).
  • With pages above 1, the host calls the operation, then, while the output's next field is present and not null and fewer than pages calls were made, calls it again with the same input and the cursor input set to that next value (the fields named by the operation's paging). The value is the output of the last call with its items field replaced by the items of every call, in order. Every call counts against rate.
  • sources.<name> exposes, for every sourced entry, { "status", "error", "updatedAt", "partial" }. status is idle, loading, ready or error. error is { "code", "message" } of the latest read when it failed, and null otherwise. updatedAt is the datetime of the latest successful read, or null. partial is true when the latest read stopped with pages remaining.
  • A refresh step asks for a read at once (section 8.1).

7.2 Scopes, offline and conflicts#

  • session and device values are always available, with or without a network. A device value belongs to one person on one device.
  • For user and shared values, a host that synchronizes them between devices or people keeps a local copy: reads see the last known value, and writes made offline are applied on reconnection under the entry's conflict policy.
  • lastWrite: the later write wins. device entries always resolve this way.
  • merge applies to the top level of the value. For a list with key, elements are matched by that field: an element added on either side is kept, one removed on either side is removed, and an element changed on both sides is taken whole from the later write. For an object, each top-level field is taken from the side that changed it, and a field changed on both sides from the later write. A list without key, and any other value, resolve as lastWrite.
  • reject: a write based on a value that has since changed fails with state.conflict. A write whose base still equals what storage holds is not a conflict. A write made offline that conflicts when it is applied is discarded, and the host records that in the audit log.

7.3 Sensitivity#

A value that is sensitive is kept out of view:

  • The host MUST redact it in audit records, together with any recorded input, output or error message computed from it (section 15). Redaction follows the value: a recorded value that was not computed from a sensitive value is recorded in full, even when the same invocation also read sensitive values.
  • The host MUST NOT expose it on an agent surface unless resources.include names the entry (section 12.1).
  • An explanation MUST NOT print a value written in the definition for the entry (section 15).

What is sensitive. A stored or sourced entry is sensitive when it sets sensitive: true. A derived entry that reads a sensitive entry, directly, through other derived entries or through a part's exported state, is itself sensitive unless it sets sensitive: false, which is the author's statement that the computed value may be shown. A derived entry MAY also set sensitive: true on its own account.

A value is computed from a sensitive value when the expression that produced it has among its references (expressions.md, section "Static analysis") a sensitive entry, a part's exported state that is sensitive in the part, or a local name, input field or event field whose value was itself so computed. The output of a call or code step is so computed when its input was. A derived entry with sensitive: false, and a stored entry without sensitive: true, are not sensitive values, whatever was written to them. A condition does not make a value sensitive: the result of state.secret > 100 ? 'a' : 'b' is not computed from state.secret.

Messages and outputs. A message returned to an agent (a require message, a done message, a fail message, an error's message) that was computed from a sensitive value the agent cannot read as a resource is replaced by the host's own words. A tool's output is returned as computed: an action that returns a sensitive value makes it readable by every principal that may call the action.

A sourced entry whose operation's scope has sensitivity high SHOULD state sensitive either way; validation warns when it does not (state.sensitivityUnstated).

8. Actions#

An action is a named, typed, described operation. Actions are the only entry points into the app's behavior: surfaces invoke them, rules and flows run them, parent definitions call them.

"actions": {
  "setGoal": {
    "description": "Change the savings target.",
    "input": { "amount": { "type": "number", "description": "New target amount" } },
    "require": [ { "that": "input.amount > 0", "message": "The goal must be more than zero." } ],
    "steps": [ { "set": "state.goal", "to": "=input.amount" } ]
  },
  "startOver": {
    "description": "Start saving again from today.",
    "confirm": { "message": "=`This sets aside the ${state.saved} saved so far.`" },
    "steps": [ { "set": "state.startDate", "to": "=env.today" } ]
  }
}
Field Meaning
description Required. Written for both people and agents.
input Field map. Default empty.
output Type reference of the value produced by return. Optional. An action that ends without return produces null, and a value is checked against output only when a return ran.
allow Expression guard: who may run the action. It sees input, state, user and the other base roots. If present and not true, the invocation fails with action.forbidden.
require Array of { "that": expression, "message": dynamic value }: what must hold for the action to be done now. Optional. Each that and message sees what allow sees. The first entry whose that is not true fails the invocation with action.refused and that entry's message.
confirm true, false (the default) or { "message": dynamic value }. Whether a person must confirm before the action runs (below).
done { "message": dynamic value }: what to say when the action has been done, to whoever invoked it from outside (below). Optional.
internal Default false. When true, the action is callable only from steps inside this definition, including the steps of its own visual handlers. It is never a tool, an intent or an export.
steps Array of steps. Required.

Invoking an action. An invocation passes these checks in order, and stops at the first that fails:

  1. The action exists, is not internal (unless it is run from this definition's own steps), is exposed by the surface the call came through, and the caller holds access to it where access names it (section 6.1). Otherwise the invocation fails with action.forbidden, with the same message whatever the reason, so that a refusal does not tell whether the name exists.
  2. The input is validated against input and defaults are applied. Missing required fields, unknown fields and values that do not conform fail with action.invalidInput.
  3. allow is evaluated. If it is not true, the invocation fails with action.forbidden. The refusal MUST NOT carry the guard's text.
  4. The require entries are evaluated in order. The first whose that is not true fails the invocation with action.refused, carrying that entry's message. A message that cannot be evaluated is replaced by the host's own words. allow answers who may act; require answers whether it can be done now, and its message is written to be shown to whoever asked.
  5. When confirm is set, confirmation is obtained. A declined or unanswered confirmation fails the invocation with action.declined.
  6. The steps run (section 8.2).

A failing allow or that expression counts as not true (section 17).

Confirmation. When confirm is true or an object, the host MUST obtain confirmation from a person before running the action when the caller is an agent, and SHOULD when the caller is a person. Confirmation is asked of the person of the calling principal (section 6.1); when it has none, the invocation fails with action.declined. The host shows the person the action, its input and who is asking. With { "message" } it also shows the message, evaluated before asking with the roots allow sees, beside them and marked as the app's own words; a message that cannot be evaluated is replaced by the host's own words. An agent never confirms for itself, and a request that receives no answer is declined. For a person's own act the confirmation need not interrupt: asking at the control they activated is enough, provided they see the action and the message there and can open its input, where it has any, from the same place. The person chose the act, so the host need not repeat its values to them unasked; for work an agent does, the input is always shown with the question. When the answer arrives, checks 1 to 4 are evaluated again, so a confirmed invocation still fails if, meanwhile, its caller lost access or a require stopped holding. A pending answer never holds up other work on the app (section 8.2): the host asks before the work starts, or while the work is suspended.

Confirmation cannot be bypassed. A run step that targets an action with confirm is an error (action.confirmBypassed) when it is in a rule's steps, in a flow's steps (a transition's do, a state's enter or exit), or in an action that does not itself have confirm. A run in a visual handler, and a voice intent's action, are the person's own invocation and are allowed. When a confirmed action runs another action with confirm, the person is not asked twice.

Saying it was done. done.message is what the app says when the action has been done, so that whoever asked knows, also when the result is not where they look: a form that closed, a view that went back, a record sent elsewhere. Whoever invoked the action from outside hears it, and nobody else: a person through a visual handler's run (section 12.2) or a voice intent (section 12.3), and an agent through the agent surface (section 12.1). An action that another action's run step runs, or that a rule or a flow runs, says nothing, and its message is not evaluated; the steps of a parent definition, its visual handlers included, that run an action of a part get its output only (section 13).

  • The message is evaluated once, when the steps have ended without failure, and is said only once the work the invocation belongs to has completed and its writes are kept (section 8.2). It is never evaluated for an invocation that failed, was refused or was declined.
  • It sees what allow sees, with state as the steps left it, and output, the value the action produced (null when no return ran). Its evaluation changes nothing and calls nothing.
  • A message that cannot be evaluated, that is not text, or that is empty once cleaned is no message: the action has still succeeded, and the failure is reported as a failing expression is elsewhere (section 17).
  • The host cleans the message as it cleans a notification's title, to plain text on one line that is never markup or a link, and cuts it at 200 characters with an ellipsis. Validation warns about a literal message that is longer (action.doneTooLong).

As with a require message, the message is the app's words for whoever asked: its author writes it for that reader, and puts nothing in it that the reader may not see. It is for a result that is not in front of the person already; a change the person sees where they look needs no message.

8.1 Steps#

A step is an object with exactly one kind key from the table below, plus that kind's other fields. By convention the kind key is written first. Steps run in order.

Step Shape Effect
set { "set": path, "to": value } Write a stored or view state value, or a field inside one.
append { "append": path, "value": value } Add an element to the end of a list.
remove { "remove": path, "where": expression } Remove the list elements for which where is true.
patch { "patch": path, "where": expression, "with": value } Shallow-merge with into each list element for which where is true. Without where, path is an object and with is merged into it.
let { "let": name, "to": value } Bind a local name to a value for the steps that follow.
call { "call": "alias.operation", "with": value, "as": name, "once": value, "orElse": value } Invoke a capability operation. The output is bound to name for later steps. once makes the effect happen at most once (section 8.3).
run { "run": "actionName", "with": value, "as": name, "orElse": value } Run another action in this definition, or partName.actionName for an exported action of a part. Its output is bound to name.
code { "code": "moduleName", "with": value, "as": name, "orElse": value } Run a sandboxed code module. Its output is bound to name.
refresh { "refresh": "state.<name>" } Ask for a sourced entry to be read again (section 7.1), without waiting for the result. Naming an entry that is not sourced is an error (state.notSourced).
send { "send": "eventName", "to": "flowName", "key": value, "with": value } Send an event to a flow instance. key is required for collection flows.
emit { "emit": "eventName", "with": value } Raise an app event that rules can trigger on and parent definitions and agents can observe.
if { "if": expression, "then": [steps], "else": [steps] } Branch. else is optional. A failing condition counts as false.
each { "each": expression, "as": name, "indexAs": name, "do": [steps] } Run steps once per element of a finite list. Without as the element is item, which hides any outer item for the body. The position is bound to indexAs when given, and otherwise to index, which hides any outer index. A value that is not a list fails the step with expression.error.
return { "return": value } End the action with an output.
fail { "fail": "code", "message": value } End the action with an error. code has the form area.problem; an app MAY use its own codes as well as those of section 17.

return and fail end the action whose steps contain them from any depth of if, each and onError. An action that a run step ran ends on its own return or fail; a fail there fails the run step.

Write targets. The path of set, append, remove and patch MUST start with state. followed by the name of a stored entry. In a view's handlers it MAY instead start with view. followed by the name of one of that view's state entries (section 12.2). In the steps of a collection flow (a transition's do and a state's enter and exit) it MAY be item, which writes through to the element (section 10). Any other target is an error (write.invalidTarget). A binding, and a step written directly in a visual handler, MUST NOT target a shared stored entry (write.sharedDirect): shared state changes only through actions, run from the handler with run, so every change passes an allow and an agent can make it on the same terms. Entries of other scopes may be written directly, as the person using the surface. Which other steps a visual handler may hold is set out in section 12.2 (view.handlerStep). Writing to a derived or sourced entry is a load-time error (state.readonly). A part's step that writes an input its parent drives fails with state.readonly (section 13), and a step that writes the state field of a collection flow fails with flow.fieldWrite (section 10). A path MAY select list elements with selectors (section 3.2); a write through a selector that matches no element fails with state.noElement. set on a nested path creates missing intermediate objects, and fails with state.invalidValue if an intermediate value exists and is not an object.

Elements in remove and patch. In where, item and index are the element under test. In the with of a patch that has where, they are the element being patched, so { "patch": "state.players", "where": "item.id == input.id", "with": { "score": "=item.score + 1" } } adds one to a score. Both hide any outer item and index; name an outer element with as and its position with indexAs to keep them visible. A where that fails counts as false.

Failures. call, run and code steps MAY carry onError, an array of steps that runs when the step fails, with error ({ "code", "message" }) in scope, and orElse, a dynamic value for the step's as name when it fails. A step with either handles its own failure: the onError steps run first, and when they finish normally the failure counts as handled; the as name is then bound to orElse, evaluated after the onError steps with error in scope, or to null without it; and the action continues with the next step. An empty onError handles a failure and does nothing else. A failure inside the onError steps fails the action. Without onError or orElse, a failed step fails the action. When a run step fails, the writes made by the action it ran are discarded; writes made before it by the calling steps are kept, and the calling action continues if the failure is handled.

8.2 Execution semantics#

  • Scope. Expressions in an action's steps see state, sources, input, env, user, flows, parts, capabilities, grants and local names (section 3.4). The steps of a rule, a flow or a visual handler see event in place of input. An action run from such steps receives only what the run step's with passes.
  • Principal. The principal an action, rule or transition acts as is set out in section 6.4.4.
  • Order. Work on an instance is serial: an invocation, a visual handler, a binding's write, a timer firing or a capability event, with the rules it triggers, runs to its end before the next piece of work starts, in the order they arrived. The one exception is a wait on a person (next item).
  • Waiting on a person. Work MUST NOT hold the instance while it waits on a person. A wait on a person is a call of an interactive operation (contracts.md section 4), a confirmation (section 8), or a request asked at the moment of a call (section 6, "When a request is asked"). Work waits on a person only while it has changed nothing: it has written no state, sent no flow event, raised no app event and called no operation whose effect is not read; validation places the steps that wait by their nature accordingly (action.waitsOnPerson). At such a wait the work is suspended: its turn ends with nothing to commit, and other work on the instance goes on. When the person has answered, the work continues where it stopped, in a turn of its own; it is not run again. On continuing, the allow and require of every action the work is inside are evaluated again against the state as it is then, and a failure ends the work as that check does at the start: nothing is written and the person's answer is dropped. Names bound before the wait keep their values, env.now is the time of continuing, and state read from then on is the state then. The rules the continued work triggers run as for any work. If the instance stops, or the person's session ends, while the work is suspended, the work ends and nothing is written. Work that reaches a wait on a person after it changed something, and the steps of a rule or a flow, which have nobody to ask, do not wait: a call of an interactive operation fails with capability.unavailable, and a confirmation with action.declined. A request asked at a call made after the work changed something MAY hold the instance, but no longer than the host's limit for a call that waits on no person; unanswered by then, the call fails with grant.denied, the question stays open, and its answer serves the next try.
  • Transaction. State writes made by an action are applied atomically when the outermost action completes. Steps see their own pending writes, and a derived entry read during the action reflects them; a send to a collection flow finds an element appended earlier in the same action. If the action fails, its writes are discarded. Outside effects (capability calls) that already happened are not undone; they are recorded in the audit log, and once (section 8.3) keeps a retry from repeating them.
  • Only the definition runs. A host MUST execute only steps, bindings and expressions that are part of the loaded definition. A surface names a handler or a binding by its location in the definition and supplies data for its scope; it never supplies steps.
  • Events. An app event raised by emit, an action:<name> event and a flow:<name> event are delivered only if the transaction that raised them commits. An event is observed where it is raised: by rules at that place (section 6.4.4), and by the surfaces of the person on whose behalf the work ran, that person's agents included. Work that ran on behalf of no person is observed by the surfaces of the principal that did it. Other people learn what changed through the state they can read. action:<name> is raised each time the action succeeds, including when another action ran it, with payload { "input", "output" }.
  • Termination. There are no unbounded loops. each iterates a finite list. run MUST NOT recurse: the static call graph of actions MUST be acyclic, which is a load-time check.
  • Effectful functions. random() and uuid() are available only in step expressions, never in derive, guards or view bindings. Time comes from env.now, which is fixed for the duration of an action, and of each turn of work that continued after a wait on a person.

8.3 Effects that happen once#

A call step MAY carry once: a dynamic value giving a string of 1 to 200 code points that names the effect, such as "=`report:${item.id}`". Within an instance, a call takes effect at most once per effect record. A record is identified by the definition whose steps made the call (the root definition or a part instance), the capability alias, the operation, the once key and, for a personal capability, the person on whose behalf the call is made. The record also holds a digest of the operation input after defaults.

  • When a call succeeded under the same identity with an equal input, the host does not call the provider again, and the step produces the recorded output. The repeated call still needs a grant that covers it, does not count against rate, and is recorded in the audit log as repeated.
  • When a call succeeded under the same identity with a different input, the step fails with capability.onceMismatch, and the provider is not called.
  • A call made while another with the same identity is in progress waits for that call's outcome, and then follows these rules.
  • A call that failed is not recorded and may be tried again.
  • The host keeps the record outside the action's transaction, as it keeps the audit log, so a call that succeeded stays recorded when the action that made it fails. It keeps each record for at least 30 days.
  • The host also passes the key to the provider, so the provider can refuse a duplicate the host could not know about (contracts.md section 4).
  • once is allowed only on operations whose effect is write or external (call.onceEffect). A once value that is not a string of 1 to 200 code points fails the step with capability.failed, and the operation is not called.

once is what makes a failed action safe to run again: an action that files a report and then fails on a later step can be retried, and the report is filed once. The key names the thing the effect is about; a key made with uuid() differs on every attempt and protects nothing. A key names the effect for the whole instance, so an effect that should happen once for each person includes user.person.id in its key.

8.4 Asking in advance#

Two functions let a view or a rule ask whether something would be allowed, so that guards are not repeated:

  • can(actionName, input?) is true when input (default {}) is valid input for the action, its allow holds and every require entry holds, for the principal acting where the expression is evaluated.
  • canSend(flowName, event, key?) is true when the flow instance exists (for a collection flow, the element with that key), its current state has a transition for event that would be taken, and that transition's allow holds. While the transitions' if and allow are evaluated for this purpose, the root event is null.

Both are usable wherever user is in scope, except in derive and in the guards they evaluate: an action's allow and a require entry's that, and a flow transition's if and allow, where they would recurse. actionName names an action as a run step does (action.unknown); flowName names a declared flow (flow.unknown) and event an event it handles (flow.unknownEvent); all three MUST be string literals. key is given exactly when the flow is a collection flow (flow.keyMismatch). Neither function runs steps, asks for confirmation or is recorded in the audit log, and can does not consider grants or the caller's access to the action. expressions.md, section "Questions about the app", defines them exactly.

9. Rules#

"rules": {
  "celebrateGoal": {
    "description": "When savings reach the goal, send a congratulation.",
    "when": { "becomes": "state.goal > 0 && state.saved >= state.goal" },
    "do": [ { "call": "notify.send", "once": "=`goal:${user.person.id}:${state.goal}`", "with": { "title": "Goal reached", "body": "=`You saved ${formatNumber(state.saved, { style: 'currency' })}`" } } ]
  }
}

when holds exactly one trigger:

Trigger Fires
{ "becomes": expression } When the expression changes from not-true to true (edge-triggered). It does not fire when a session opens while the expression is already true, unless "initial": true is set beside it: it then fires when a session opens while the expression is true, in that session. Values restored at load make no edge (section 7.1). Where the trigger is tested is set out in section 6.4.4.
{ "changes": path } When the value at a state path changes. event is { "previous", "current" }.
{ "event": name } On an app event raised by emit, a capability event alias.event, an action completion action:name, a flow transition flow:name, or a part's exported event part.name. event is the payload.
{ "every": duration, "foreground": boolean } Repeatedly at an ISO 8601 interval while the app is active, first one interval after the trigger starts running. foreground is optional (below).
{ "lifecycle": "install" \| "open" \| "close" } install at the first load of an instance; open when a session's first surface opens; close when its last surface closes.

if is an optional expression guard. A failing if counts as false. do is an array of steps, run as an anonymous internal action with the same semantics as section 8.2.

A condition that must hold for an edge to mean anything belongs inside becomes, because if is tested only when the edge happens. If a goal starts at 0, state.saved >= state.goal is true from the start, and raising the goal to an amount below what is saved never makes it become true, so a rule with that trigger and "if": "state.goal > 0" never fires. With state.goal > 0 && state.saved >= state.goal in becomes, as in the example, the edge happens when the goal is set. An app that waits for a condition of the environment, such as env.online, and may already find it true when a session opens, sets "initial": true.

Rules always act as the app principal, on behalf of a person, or of the principal that caused the work when it has no person (section 6.4.4): inside a rule user.kind is app, user.roles is empty, and user.onBehalfOf is that person or principal. A rule runs after the transaction that triggered it commits, in its own transaction. Where a trigger is tested, and so where and how often a rule fires, is set out in section 6.4.4: a change made in one place fires no rule in another, and other sessions receive the resulting state.

  • A rule with an every trigger runs only while a surface is active (a person has it open, section 6.4), unless the app holds a grant on a capability whose contract declares the background trait. Unattended execution is an outside effect and is permissioned like one. Validation warns about an every trigger with no such grant request (trigger.noBackground) unless it says "foreground": true, the author's statement that it is meant to run only while a surface is active. The statement binds: a rule that says so runs only while a surface is active, whatever grant the app holds, so an app that holds a background grant for one purpose does not run its other rules unattended.
  • A schedule (every, refresh.every) that fell due more than once while the app was not running, across a jump of the clock, or while other work on the instance ran (section 8.2), fires once when it can, not once per missed interval. The audit record of that firing says how many times it fell due.
  • Hosts MUST bound rule cascades (a rule's writes triggering further rules). The limit is 16 levels, counting only rules whose if held: a rule that would run more than 16 levels below the work that started the cascade does not run, and rule.cascade is recorded in the audit log against that work.
  • A capability event that follows from a call made in a cascade, as a store's event that a record changed follows the write that changed it, is a level of that cascade as a rule is: the rules it fires and the reads it causes count from the level of the call, also in another instance that receives the event. So a rule that writes to a capability whose events fire it settles and does not run without end. A scheduler wake whose time lay after the call that scheduled it starts new work, because time caused it; a wake that was already due when it was scheduled is a level of the cascade that scheduled it.
  • Hosts MAY enforce a minimum interval for every, and MAY hold a flow's after (section 10) to the same minimum: a transition whose duration is shorter is taken when the minimum has passed. A host that renders a visual surface SHOULD support intervals down to 16 ms.

10. Flows#

A flow is a finite state machine. Use one when a process has named stages and only certain moves between them are legal.

"flows": {
  "approval": {
    "description": "Purchase requests move from draft through manager and finance review.",
    "over": { "collection": "state.requests", "key": "id", "field": "status" },
    "initial": "draft",
    "states": {
      "draft": {
        "on": { "submit": [ { "to": "managerReview", "if": "item.amount > 500", "allow": "user.person.id == item.requesterId" }, { "to": "approved", "allow": "user.person.id == item.requesterId" } ] }
      },
      "managerReview": {
        "description": "Waiting for the requester's manager.",
        "on": {
          "approve": { "to": "financeReview", "allow": "user.id == item.managerId" },
          "reject":  { "to": "rejected", "allow": "user.id == item.managerId", "do": [ { "patch": "item", "with": { "rejectedBy": "=user.id" } } ] }
        },
        "after": { "P3D": { "to": "escalated" } }
      },
      "financeReview": { "on": { "approve": { "to": "approved", "allow": "'finance' in user.roles" }, "reject": { "to": "rejected", "allow": "'finance' in user.roles" } } },
      "escalated": { "on": { "approve": { "to": "financeReview", "allow": "'director' in user.roles" } } },
      "approved": { "final": true },
      "rejected": { "final": true }
    }
  }
}

state.requests is a shared list, so the whole team works on the same requests. Each request stores requesterId and managerId when it is filed. Only the requester, or an agent acting for them, may submit it. The filing action reads managerId from the directory (directory.manager), never from its own input, so a requester cannot name themselves; only that manager can approve the request at the first stage, and an agent acting for the manager is not the manager. No action changes amount, managerId or requesterId after filing, since the guards rely on them. finance and director are roles (section 6.2).

  • Without over, the flow is a singleton: one instance per app instance, current state readable as flows.<name>.state. Its bookkeeping (the current state and when the instance entered it) lives with the app instance.
  • With over, there is one instance per element of a stored list. collection is a path to that list, key names the element's identity field and field names the element field that holds the current flow state; all three are required. The flow's bookkeeping lives with the collection, in that entry's scope. In transitions and in enter and exit steps, item is the element and index its position, and steps may write to it ({ "patch": "item", "with": {...} }).
  • The state field belongs to the flow. Only the flow writes field. Any step that writes it, through the collection's path or through item, fails with flow.fieldWrite: a load-time error where validation can see it, and otherwise a failure of the step at run time. At run time, when a step or binding writes the collection or any path inside it, the host compares each element, by key, before and after the write. The write fails with flow.fieldWrite if an existing element's field changed, if an added element's field is neither absent nor initial, or if an existing element's key changed. An element added again after it was removed starts at initial. An appended element MAY omit the field or give the flow's initial. The host writes initial into an element appended without it, as it is appended, so reads always see a state. No enter steps run for the initial state of a new element.
  • states.<s>.on.<event> is a transition or an ordered array of transitions; the first whose if is true (or absent) is taken. A transition has to (required), if (expression), allow (expression guard) and do (steps). A false or failing if moves on to the next candidate. When the transition taken has an allow that is not true, the event fails with flow.forbidden, nothing moves, and the refusal MUST NOT carry the guard's text.
  • A transition taken because of a send acts as the principal whose steps sent the event, and user in its allow is that principal (section 6.4.4). event is the with of the send.
  • enter and exit are optional step arrays on a state. Order on a transition: source exit, transition do, state change, target enter. All run in one transaction. to MAY name the state the transition leaves; that state's exit and enter steps then run, and its after timers start again.
  • after maps an ISO 8601 duration to a transition taken if the instance stays in the state that long. The transition is taken once per flow instance, however many sessions have the app open; its event is null. On whose behalf it acts, and when its timers run, depends on whether the collection is shared (section 6.4.4); a timer that must fire while no surface is active needs a background grant.
  • An event sent to an element that does not exist, or to an instance whose current state has no transition for it (or none whose if holds), fails with flow.noTransition.
  • final: true marks a state with no outgoing transitions.
  • Every transition raises the app event flow:<name> with { "from", "to", "event", "key" }: event is the event's name, or null for an after transition, and key is the element's key, or null for a singleton flow.
  • canSend (section 8.4) tells a view whether an event would be accepted.

11. Code#

Code is the last resort, for logic that expressions, steps, rules and flows cannot express.

"code": {
  "scoreWord": {
    "description": "Scores a word by letter rarity and length.",
    "runtime": "js",
    "input": { "word": { "type": "string" } },
    "output": "integer",
    "source": "export default function ({ word }) { return word.length * 2; }",
    "limits": { "timeMs": 50, "memoryMb": 16 }
  }
}
  • A module is a pure function from input to output. It has no ambient authority: no network, storage, clock, randomness, timers or host objects. Anything it needs is passed in input. It cannot call capabilities.
  • runtime is js (an ECMAScript module whose default export is the function) or wasm (reserved in 0.2).
  • source holds the module text inline. module MAY be used instead: { "uri", "digest" }, where digest is the digest of the module's bytes (section 16).
  • Hosts MUST run code in an isolated sandbox, MUST enforce limits (defaults: 100 ms, 32 MB), and MUST require a grant naming the module and issued for its text (section 6, rule 2). Since the module can reach nothing, its request is contained: the host issues that grant without asking anyone, unless it chooses to ask (section 6, "When a request is asked"). Hosts MAY decline to support code at all; a definition that uses code on such a host fails resolution for the steps that need it (section 14).
  • Input and output are validated against their declared types and copied by value across the sandbox boundary as plain JSON data. A result that holds anything else (a function, undefined, a class instance, a non-finite number, a cycle) fails with code.failed.
  • limits cover everything the module does: evaluating it, the call, any promise it returns and copying the result. A returned promise is awaited; one that cannot settle fails with code.failed. A host MAY cap the limits a module asks for.
  • A module has no time zone: dates behave as UTC.

12. Surfaces#

A surface is a projection of the kernel. Surfaces hold no logic of their own: event handlers on a visual node hold only the steps section 12.2 allows, which run as in an action body, and SHOULD be a single run step in anything but trivial cases.

A surface exists only if its key is present. "agent": {} is a complete agent surface.

12.1 Agent surface#

"surfaces": {
  "agent": {
    "instructions": "Use setGoal before logging deposits. Amounts are in the user's currency.",
    "tools": { "include": ["setGoal", "logDeposit"], "describe": { "setGoal": "Set the savings target in whole currency units." } },
    "resources": { "include": ["goal", "saved", "remaining"] },
    "events": { "include": ["goalReached"] }
  }
}
  • Tools. Every non-internal action is a tool: its name, description, input and output are the tool's schema. tools.include or tools.exclude narrows the set; a surface gives one or the other, not both. include MAY name a part's exported action as part.action. describe overrides a description for agent readers.
  • Resources. Every state entry that is neither sensitive (section 7.3) nor internal is a readable resource with its type and description. resources.include or resources.exclude narrows the set in the same way. include is the only way to expose a sensitive entry, MAY name a part's exported state entry as part.name, and MUST NOT name an internal entry. View state is never a resource. A derived entry that reads user is read for the agent (section 7).
  • Events. An app event that is listed is observable by an agent (as a notification or a subscription, depending on the adapter) when it was raised by work that ran on behalf of the agent's person, the agent's own work included (section 8.2), while the agent holds access to the app. events.include MAY name a part's exported event as part.name. An agent learns an event's name and time. Access grants in 0.2 do not name events, so a host SHOULD withhold event payloads from agents; an agent reads what changed through the resources it has access to.
  • Files. A file reference in a tool's input follows section 5: it MUST be one the host issued to that agent for this instance.
  • Discovery. A host MUST be able to produce, for any loaded app, a machine-readable manifest: the app's id, version, meta, instructions, tools with input and output schemas, resources with types, events, and the grants the app holds. This is how agents discover what an app can do. Adapters map the manifest onto concrete protocols (for example MCP tools and resources). An app that declares no agent surface exposes no tools, resources or events to agents; its manifest still carries its identity, meta and grants.
  • An agent invoking a tool is subject to the action's allow, require and confirm, and to the agent's own access to that action (section 6.1). A refusal for require carries the entry's message, which is how an agent learns why it cannot act.
  • Results. A tool call that succeeds returns the action's output and, when the action has a done message (section 8), the message beside the output, where the agent reads it. An adapter carries the message without changing the output, so an output that conforms to the tool's output schema still does.
  • Least privilege. A host SHOULD show an agent only the tools and resources its access covers. A refusal MUST NOT tell an agent whether a name exists: an unknown name, an internal action, a name the surface does not expose and a name the agent's access does not cover are refused alike, with action.forbidden (section 8). Change notices reach an agent only for resources it may read.

12.2 Visual surface#

"surfaces": {
  "visual": {
    "start": "home",
    "views": {
      "home": {
        "title": "Trip Savings",
        "state": { "draftGoal": { "type": "number?", "initial": "=state.goal", "description": "The goal being typed" } },
        "body": {
          "control": "core:stack",
          "children": [
            { "control": "core:progress", "props": { "value": "=state.saved", "max": "=state.goal", "label": "Saved so far" } },
            { "control": "core:numberInput", "props": { "label": "New goal" }, "bind": { "value": "view.draftGoal" } },
            { "control": "core:button", "props": { "label": "Update goal", "disabled": "=!can('setGoal', { amount: default(view.draftGoal, 0) })" },
              "on": { "press": { "run": "setGoal", "with": { "amount": "=view.draftGoal" } } } },
            { "control": "core:list", "props": { "items": "=default(state.deposits, [])", "itemKey": "id" },
              "slots": { "item": { "control": "core:text", "props": { "value": "=default(item.memo, '')" } } } },
            { "control": "core:badge", "each": { "in": "state.milestones", "as": "m", "key": "m.id" }, "props": { "label": "=m.name" } }
          ]
        }
      }
    }
  }
}

A view has these fields. start names the first view; when the app lists main sections (below), start is normally the first of them.

Field Meaning
title Dynamic value. Optional.
input Field map of values passed on navigation, read as view.<name>. Optional.
state View state: entries of { "type", "initial", "description" } (below). Optional.
body The node drawn. Required.

Main navigation. navigation, beside start and views, lists the app's main sections in order, so that a host can draw them as the app's own navigation and does not have to guess which views are sections. Sections can come from the app's data, as the channels of a chat app, the folders of a mail app or the projects of a planner do:

"navigation": [
  { "view": "activity", "label": "Activity", "icon": "notification" },
  { "group": "Channels", "sections": [
    { "each": { "in": "state.channels", "as": "c", "key": "c.id" }, "view": "channel", "with": { "id": "=c.id" }, "label": "=c.name", "count": "=state.messages.count(m, m.channelId == c.id && !m.read)" },
    { "view": "newChannel", "label": "New channel", "icon": "add" }
  ] }
]

The list holds 1 to 12 entries. Each entry is a section, a repeated section (a section with each) or a group. A section has these fields:

Field Meaning
view A declared view. Required.
label Dynamic value giving the section's name. Required.
icon A name of the core catalog's icon vocabulary, as meta.icon takes. A host that does not know the name shows no symbol. Optional.
when Expression. The section is offered only while it is true. Optional.
with Dynamic value: the input the section opens its view with, as the with of a navigate step. It MUST give every required input of the view and MUST fit the view's input as a navigate step's with does. Without it the view is opened with no input, so its view MUST then take no required input. Optional.
count Dynamic value giving a whole number not below zero, or null: how many things wait in the section, such as unread messages or open tasks. Optional.
each { "in": expression, "as": name, "indexAs": name, "key": expression }, with the shape and meaning of a node's each: the section is offered once for each element of the list, in order, with its other fields evaluated with the element in scope. as defaults to item; the position is index, or the name given by indexAs; key gives elements a stable identity. Optional.

A group is { "group": value, "when": expression, "sections": [...] }: group is a dynamic value giving the heading drawn above the group's sections; when, optional, offers the group only while it is true; sections holds 1 to 12 sections or repeated sections. A group holds no group.

A section's label, when, count and with are evaluated with the base roots and, in a repeated section, the names its each binds, for the principal the views are read for, and follow state as a view's title does; a group's group and when see the base roots only. None of them reads view. A label that cannot be evaluated is replaced by the view's name; a when that cannot be evaluated counts as not true; a count that cannot be evaluated, or is not a whole number not below zero, counts as null; a section whose with cannot be evaluated, or does not fit the view's input, is not offered, since it could not be opened; and an each whose list cannot be evaluated, or is not a list, offers nothing. A group's heading that cannot be evaluated is replaced by no text. Two sections that have neither each nor with MUST NOT name the same view; otherwise a view MAY be named by several sections, such as one for each channel.

A host shows the sections that are offered as the app's navigation, in the app's design and in whatever form suits the window (a sidebar, a bar, a menu), with a group's heading above the group's sections and a count above zero beside its section's label, as part of the section's accessible name. A group whose when holds is offered with its heading even when none of its sections is offered, as an empty "Channels" group is while the app has no channel; a host MAY leave out the heading of a group that offers no section. The host marks the offered section whose view is at the bottom of the navigation stack with an input equal to the section's with, inputs compared as a navigate step compares them and a section without with standing for an input of nothing; when several are equal, the first is marked. Choosing a section replaces the navigation stack with its view, opened with its with; when that view with that input is already at the bottom of the stack, choosing it returns to it and closes the views above, as a navigate to an open view does. A host tells the sections it offers apart by keys of its own, and a section's key stays the same while its element keeps its each key, so that a list that changes while the person chooses never opens another section than the one they meant: choosing a section that is no longer offered changes nothing. A navigate step or a link to the view of an offered section, with the input that section opens with, chooses that section, as the paragraph on the navigate step below describes. when decides what is offered, never what is allowed: a section that is not offered can still be opened by a navigate step, which then shows it on top of the current view, and what a person may do is decided by each action's allow.

The navigation offers at most 200 sections, counted in order; what a repeated section would offer beyond that is left out, and the host knows how many elements each repeated section left out, so that it can say that there are more. A host resolves the whole navigation within one bounded cost, as it resolves views; once that cost is spent, the sections already resolved are offered and the elements not yet looked at are left out and counted as such. Without navigation the app has no main navigation and a host shows none.

An app of one view. An app whose visual surface declares exactly one view and no navigation is one tool for one purpose, such as a whiteboard, a small dashboard or a calculator. The definition alone decides this form, so every host draws the same apps this way: a host that draws views as pages SHOULD draw such an app as one card and nothing above it, headed by the view's title, or by meta.name when the view has none, as the page's only heading. When the view's body is one control that draws a box with a head of its own (a canvas, chart, table, list or diagram with a label, or a group with a title), that box is the card, its head shows the title, and the control's own label or title stays its accessible name. What the host shows of its own, such as the app's name and a way to its information about the app, it places outside the card. Every other app is drawn as pages in the host's frame. A view the app opens on top of its one view still has its way back.

View state. A view's state entries hold values that belong to one visit of the view, such as a form being filled in. type is required; initial is a dynamic value evaluated when the view opens, with view inputs, state, user and env in scope, and without it the entry starts as null. Entries are read as view.<name> beside the view's inputs, whose names they MUST NOT share (name.collision). They are written by bind and by set, append, remove and patch steps in that view's handlers (path view.<name>); a write that does not conform to type fails with state.invalidValue. A view pushed on the navigation stack opens with fresh view state; returning to a view still on the stack finds its view state as it was left; view state is gone when its view leaves the stack. Actions never see view: a handler passes what an action needs in with. View state is never a resource.

A node is one of:

  • A control node: { "control": "alias:name", ... }.
  • A part node: { "part": "partName", "view": "viewName" }, which embeds an exported view of a part. It MAY also carry id and when, and nothing else. In the resolved view, the node that stands for the embedded view carries the part node's id when it has one, so edits and tests can address it, and the ids of the nodes inside the embedded view are qualified by the part's name and a dot (savings.total, and outer.inner.total for a part within a part), so they never clash with the ids of the including view. A navigate step in an embedded part view's handlers does nothing, and the host reports it as a diagnostic.

Control node fields:

Field Meaning
control alias:name of a control contract. Required.
id Optional name, unique within the view. Gives the node a stable address for edits and tests.
props Object of prop name to dynamic value, matching the contract's props.
bind Object of bindable prop name or output name to a path into a stored state entry that is not shared (section 8.1), or into a view state entry. The path MAY select a list element (section 3.2), which is how a row of a repeated list binds to its own element. For a bindable prop the binding is two-way: the control shows the value and writes user input back. For an output the control only writes. A bound prop counts as supplied when the contract marks it required. A binding whose selector matches no element shows an empty, disabled control.
on Object of event name to a step or an array of steps. event holds the control event's payload.
children Array of nodes, for controls whose contract accepts children.
slots Object of slot name to a node, for controls with named template regions. The variables a slot's template can read are declared by the contract, not by the node.
when Expression. The node exists only while it is true.
each { "in": expression, "as": name, "indexAs": name, "key": expression }. Repeats the node itself once per element. as defaults to item; the position is index, or the name given by indexAs. The names are visible to the node, the nodes inside it and their handlers. key is optional and gives elements a stable identity across updates. To feed a list-like control, pass the list as a prop instead.
fallback A node used instead if the host cannot provide the control (section 14). A fallback is a complete node of its own: it takes nothing from the node it replaces except its place, so it carries its own props, bind and on. The outer node's when and each apply to whichever is drawn.

Handlers. A visual event handler holds only steps that stay with the person and the view: set, append, remove and patch (never on shared state, section 8.1), let, if, each, navigate, refresh and run. A call, code, send, emit or return step in a handler, at any depth (also inside its if, each and onError steps), is an error (view.handlerStep). Every outside effect, flow event and app event therefore starts in an action, passes an allow, and can be done by an agent on the same terms. Within that limit a handler's steps run like an action's body (section 8.2), as the person using the surface. When a step fails and the failure is not handled, the handler ends: later steps, including a navigate, do not run, and its writes are discarded. When a handler fails and has no onError for the failure, the host SHOULD show the error's message to the person at the control that raised the event; for a form's submit, in the form.

Saying what was done. A run step of a visual handler is the person's own invocation. When the handler has ended without failure, the host SHOULD show the person the done message (section 8) of an action such a step ran, for a moment, in its own interface outside the view, so that the message is still seen when the handler went on to navigate. It is set as the app's words and never as the host's. When several actions a handler ran have a message, the last one is shown. The message is announced to assistive technology without taking the focus, and the person can dismiss it.

Navigation is a built-in step available only in visual handlers, including steps nested inside them: { "navigate": "viewName", "with": value } and { "navigate": "back" }. with supplies the view's input. Inputs are compared after the view's input is checked and its defaults are filled in, and a section without with stands for an input of nothing. A navigate to a view that the main navigation offers as a section at that moment, with an input equal to the one that section opens with, chooses that section: the navigation stack is replaced with that view, and when that view with that input is already at the bottom of the stack, navigation returns to it and closes the views above, keeping its view state, exactly as when the person chooses the section. Any other navigate to a named view pushes it on the navigation stack, except that when the stack already holds that view with equal input, navigation returns to it and closes the views above it. The same holds for a link that opens a view and for a host that opens a view for the person, as for a notification they opened; an app without navigation has no sections, so its views are always pushed or returned to. navigate: "back" closes the current view; followed by a named navigate in the same handler, it replaces the current view, or chooses the section when the named view and its input are one. No view may be named back. A host MAY show more than one view of the stack at a time, such as a list with the record opened from it beside it. A navigate step, back included, of a handler that runs in a view below the top first closes the views above that view, so that opening another record from the list replaces the one that was open. A handler that does not navigate closes nothing, whichever view it runs in.

Props that a contract marks remote are subject to the egress rule in section 6.3. Behaviour that controls share, such as how when, hidden and disabled differ, is in contracts.md section 8; the core controls and their props are described in catalogs/core/README.md.

The definition never specifies pixels, coordinates, fonts or colors. Layout intent is expressed through layout controls (stack, grid, group) and their props (direction, gap as a named size, emphasis), which the host and design system realize.

12.3 Voice surface#

The voice surface is less proven than the agent and visual surfaces, and its shape may change in a later version.

"voice": {
  "greeting": "=`You have saved ${state.saved} of ${state.goal}.`",
  "intents": {
    "logDeposit": {
      "action": "logDeposit",
      "examples": ["I saved {amount} dollars", "add {amount} to savings"],
      "reply": "=`Added ${input.amount}. ${state.remaining} to go.`"
    },
    "howFar": { "examples": ["how much is left", "how am I doing"], "reply": "=`${state.remaining} to go.`" }
  },
  "announce": { "goalReached": "Goal reached. Well done." }
}
Field Meaning
greeting Dynamic value spoken when a voice session starts. Optional.
intents Object of intent name to intent (below).
announce Object from an app event name (an emit name or flow:<name>) to a dynamic value spoken when that event is raised while a voice session is active, with event (the payload) in scope. Nothing is spoken when no voice session is active. Optional.

Intent fields:

Field Meaning
examples Required, at least one. Phrases a person might say, with {slot} placeholders that each name an input field of the action (voice.unknownSlot). An intent without action has no slots.
action Optional. The action the intent invokes. Without it the intent only replies.
reply Dynamic value spoken after the action succeeds, with state as it is after the action, input, output, env and user in scope. Without action, input is {} and output is null. Without reply, the host speaks the action's done message (section 8), when it has one. Optional.
  • Recognizing speech, and matching it to intents, is the host's job. Examples are guidance, not patterns. As a minimum a host MUST recognize each example as written with its slots filled, MUST convert slot values to the field's type and ask again when it cannot, MUST NOT run an action whose required input it could not fill, and MUST say so when nothing fits.
  • The person speaking is the invoking principal, and env.surface is voice. An intent's action is the person's own invocation (section 8).
  • When the action fails, the host speaks the error's message and not the reply. A refusal for require speaks the entry's message.
  • For an action with confirm, the host asks aloud and proceeds only on a clear yes.
  • A control's surfaces.voice support level (contracts.md section 2) describes how a voice host that presents views reads a view out. It is independent of intents.

12.4 Design systems#

A design system is a separately versioned document referenced from uses.design. It supplies tokens (named colors, type styles, spacing, motion), variants (named prop presets for controls), and MAY reference a catalog of custom controls. For agent surfaces it MAY supply naming and error-message conventions. Definitions refer to tokens and variants by name only ("variant": "primary", "gap": "medium"), so swapping the design system restyles every app that references it. A design system MAY restyle any control but MUST NOT change a control's contract (props, events, accessibility role). The design system document format is specified in contracts.md.

12.5 Assets#

A definition MAY carry the pictures it shows, such as a header photo, a logo or the sprites of a game, in its top-level assets member: an object from asset name to entry. An asset name is a name (section 3) of at most 64 characters. A prop that a contract marks remote refers to an asset as asset: followed by its name (section 6.3).

"assets": {
  "logo": {
    "type": "image/png",
    "digest": "sha256-rtVn_O8tnRRoQYWK0VMl6WNaojSAA9tc5TN8320NCy8",
    "data": "iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAIAAAAlC+aJAAAw…",
    "width": 64,
    "height": 64,
    "credit": "Logo by Ada Example, CC BY 4.0."
  }
},
"surfaces": {
  "visual": {
    "start": "home",
    "views": {
      "home": { "title": "Home", "body": { "control": "core:image", "props": { "source": "asset:logo", "alt": "The Trip Savings logo" } } }
    }
  }
}

The data above is shortened with an ellipsis to fit the page: a real entry carries the whole base64 text of the picture, here 16,560 characters.

Member Meaning
type Required. The picture's media type: image/png, image/jpeg, image/webp or image/gif. No other type is an asset in 0.2; in particular an SVG drawing is not.
digest Required. The digest of the picture's bytes (section 16). It says which picture the asset is.
data Optional. The picture's bytes as base64 (RFC 4648, section 4): the standard alphabet, with padding, with no line break and no other character, and with zero in the bits that padding leaves unused, so that the same bytes always give the same text.
width, height Optional. The size in pixels the picture shows at, each from 1 to 4096. When given, they MUST be that size: the size its header gives, with the two swapped when its orientation turns it a quarter (see "Orientation" below).
source Optional. The absolute http or https address the bytes came from, for people. A host MUST NOT load it.
credit Optional. One line of at most 300 characters that credits the author and the license. A host SHOULD show it where it tells about the app, as its explanation does (section 15).

An entry has no other member.

What an asset is. An asset is the picture whose bytes have its digest. data is one way those bytes travel with the definition, and an entry without data is valid. A host that holds bytes with that digest, from the entry's data or from anywhere else, shows the asset. A host that holds none has no asset to show, and the control shows what it shows for a picture that cannot be loaded. A host or a tool MAY therefore keep the bytes apart from the document it works on and put them back as data when it hands the definition on: the digest of a definition leaves data out (section 16), so the definition stays the same.

Showing an asset. An asset reference (section 6.3) is the whole string asset: and a name, either the value of a remote prop or a string inside it, such as the source of an image shape on a canvas. A host shows the asset of that name in the definition the control belongs to, which for a view of a part is the part's own definition, never its parent's. Loading an asset is not egress and needs no grant. A host MUST NOT show bytes whose digest is not the entry's digest.

Bytes that are carried. Where data is present, all of these hold, and a definition that breaks any of them is not valid (validation.md, section 9.1):

  • data is base64 in the one form the table above gives;
  • the digest of its bytes is digest;
  • its bytes are a picture of the type type says, recognized from the bytes as the table below sets out;
  • the picture is at most 4096 pixels wide and at most 4096 pixels high, as its header gives them;
  • width and height, where given, are the size the picture shows at.

A picture is recognized from its header alone, read without decoding the picture. Offsets count from the first byte, at 0. A header that gives a width or a height of 0 is not a picture.

Type The bytes are Width and height
image/png the eight bytes 89 50 4E 47 0D 0A 1A 0A, then a chunk whose 32-bit big-endian length is 13 and whose type is IHDR, complete with its CRC (33 bytes in all). The 32-bit big-endian integers at offsets 16 and 20.
image/jpeg FF D8, then segments. A segment starts with FF, after any number of further FF bytes, and a marker byte. Markers 01 and D0 to D7 stand alone; every other marker is followed by a 16-bit big-endian length, at least 2, that counts itself, and its segment lies within the bytes. A start-of-frame segment (markers C0 to CF except C4, C8 and CC), of length at least 8, comes before any marker 00, D8, D9 or DA. In the first start-of-frame segment, after its length and one byte of sample precision: the 16-bit big-endian height, then the width.
image/webp RIFF, four bytes, WEBP, then a first chunk whose 32-bit little-endian size (offset 16) is at least 10 for VP8 and VP8X and at least 5 for VP8L, and whose header lies within the bytes: for VP8, a key frame (bit 0 of the byte at offset 20 is 0) with the start code 9D 01 2A at offset 23; for VP8L, the byte 2F at offset 20 and 0 in the top three bits of the 32-bit little-endian integer at offset 21; for VP8X, 30 bytes in all. VP8: the low 14 bits of the 16-bit little-endian integers at offsets 26 and 28. VP8L: bits 0 to 13 and bits 14 to 27 of the integer at offset 21, each plus one. VP8X: the 24-bit little-endian integers at offsets 24 and 27, each plus one.
image/gif GIF87a or GIF89a, at least 13 bytes. The 16-bit little-endian integers at offsets 6 and 8.

Orientation. A photo taken with the camera held upright is often stored on its side, with an EXIF orientation that says how to turn it. A JPEG or a PNG has an orientation when it carries EXIF data (in a JPEG, an APP1 segment that starts with Exif and two zero bytes; in a PNG, an eXIf chunk) whose first directory has the tag 0112 as one SHORT from 1 to 8; the first such data gives it. A host MUST show a JPEG or a PNG turned and mirrored as its orientation says, as browsers do. The orientations 5 to 8 turn the picture a quarter, so it shows with its width and height swapped: a photo stored 2048 by 1536 pixels with orientation 6 shows 1536 by 2048, and that is its width and height. A WebP and a GIF show as they are stored, whatever EXIF data they carry. The limit of 4096 pixels a side holds either way.

Where a picture was taken. A photo's metadata often says where it was taken, as coordinates or as a place named in words. Its location is: the GPS directory of its EXIF data; in its XMP data, every property whose local name starts with GPS (other than GPSVersionID), and the properties that name a place, photoshop:City, photoshop:State, photoshop:Country, Iptc4xmpCore:Location, Iptc4xmpCore:CountryCode, and the structures Iptc4xmpExt:LocationCreated and Iptc4xmpExt:LocationShown whole; and in its IPTC data (IPTC-NAA, as a JPEG carries it in the Photoshop resources of an APP13 segment), the datasets 2:26 (content location code), 2:27 (content location name), 2:90 (city), 2:92 (sublocation), 2:95 (province or state), 2:100 (country code) and 2:101 (country name). Nothing else is part of it: a title, a caption, keywords, a credit, an author or a copyright notice stays, even where its words name a place. Carried in an asset, that location travels to everyone who receives the definition, though nothing shows it. A tool that adds a picture to a definition for its author SHOULD remove that location from the picture first, and leave the rest of the picture as it is, so that the digest is of the bytes without it. A validator SHOULD warn about a carried picture that holds a location, naming the asset; a definition that has one is still valid. A host shows a picture as it is: it MUST NOT change the bytes of an asset, since they must keep their digest.

The sizes of a definition and of its assets that every host accepts are given in section 18.1.

12.6 Localization#

A definition MAY carry its own texts in several languages, in its top-level localization member: the language its plain texts are written in, and for each language a table from key to text. A host shows the app in one of these languages, chosen for the person (section 12.7).

"localization": {
  "default": "en",
  "strings": {
    "en": {
      "appName": "Trip planner",
      "welcome": "Welcome back, {name}",
      "nights": { "by": "count", "forms": { "one": "{count} night", "other": "{count} nights" } }
    },
    "ar": { "appName": "مخطط الرحلات", "welcome": "مرحبًا بعودتك يا {name}" }
  },
  "notes": { "welcome": "Top of the home page. {name} is the traveler's first name." }
}
Member Meaning
default Required. A language tag: the language of every plain text of the document, and the last table a text is looked for in. "localization": { "default": "ar" } alone is valid: it declares the language of an app that carries no table.
strings Optional. An object from language tag to that language's table, an object from key to entry. When present it MUST have a member for default. The default language is complete: every key the definition uses is in its table. The other languages MAY be partial.
notes Optional. An object from key to a note of 1 to 300 characters for whoever translates the app later: what the text is for, what each blank holds. A host never shows a note to a person using the app.

localization has no other member. The app's own tags are the keys of strings, or default alone when there is no strings.

Language tags. default and every key of strings is a language tag written language[-Script][-REGION] exactly, in ASCII. It matches

^[a-z]{2,3}(-[A-Z][a-z]{3})?(-([A-Z]{2}|[0-9]{3}))?$

that is: 2 or 3 lower-case letters; then optionally a hyphen and 4 letters, the first upper-case and the other three lower-case (the script, an ISO 15924 code); then optionally a hyphen and 2 upper-case letters or 3 digits (the region, an ISO 3166 code or a UN M49 area). Nothing else: no variant, no extension, no private use. The language MUST NOT be und, and MUST NOT be one of the old codes of table aliases (Appendix A): an app writes he, never iw. A tag has this one spelling, so en-us, en_US and EN are not tags (validation.md reports them with their valid spelling). A bare zh or sr is read by its region (section 12.7); an app SHOULD write the script of these two (zh-Hans, zh-Hant, sr-Cyrl, sr-Latn).

Keys. A key matches ^[A-Za-z][A-Za-z0-9_.]{0,79}$: an ASCII letter, then ASCII letters, digits, _ or ., at most 80 characters in all. Case matters. Dots only group names for a reader: a table is flat, and home.title is one key.

Entries. An entry is a text or forms.

  • A text holds blanks, written {name}, where the name is an ASCII letter or _ followed by ASCII letters, digits or _. {{ writes one { and }} writes one }; any other brace makes the text malformed. The empty text is a text.
  • Forms are { "by": "<blank name>", "forms": { "<form key>": "<text>" } }, with no other member: the text used is chosen by the value given for the blank by. The form other is required; the other form keys are the plural category names zero, one, two, few and many, = followed by a number (=0, =12), and any other text that does not begin with =, matched exactly.
  • Each language writes its own entry: a text in one language MAY be forms in another, and the reverse.

expressions.md section 8.7, "Texts of the app", gives the syntax of a text exactly, how a form is chosen, how blanks are filled, and the function t that shows an entry from an expression: t('welcome', { name: user.name }).

Fixed-text references. Some places of a definition hold text that is never an expression: a leading = is a character there. In these places one value is read differently. A value that is exactly =t('key') (the characters =t(', a key, then '), with single quotes, no space and no second argument) is a reference to that key, and the place shows the key's text. Any other value is the literal text, as it is elsewhere.

  • The entry of a referenced key MUST be, in every language that has it, a text without blanks that is not empty.
  • The text shown is the entry with {{ read as { and }} read as }, the same text t('key') gives. Every check on the place, such as its length, being one line, or holding no Markdown, reads that text.
  • The places are: meta.name and meta.description; a grant request's reason; the description of a capability, a role, a state entry (a view's own state entries too), an action, an input field, a type, a rule, a flow, a flow state and a code module; a type's title; an asset's credit; and the agent surface's instructions and the descriptions of its tools.
  • The reference does not apply to meta.tags, meta.authors, meta.license, icon names, the source of code, or voice examples (phrases a person says, which stay as written).
  • Which language. Where a person in a session reads the text, as in a list of apps, the title of a page, the heading of an app of one view, a permission sheet or a confirmation, the text is read in that person's shown language, along its text chain (section 12.7). Where no person in a session reads it, as in an agent's manifest and tool schemas, the explanation of section 15 and everything else that must be the same on every machine, and the user.name of the app's own principal, it is read in the default language.

Sizes. Section 18.1 gives the number of languages, keys, characters and forms every host accepts.

12.7 Language, formats and direction#

A host shows a definition that has localization in one of the app's own languages, the shown language, chosen from the languages the person reads. From the shown language it derives the app's direction, left-to-right or right-to-left, and the locale that formats numbers and dates beside its words. A definition without localization has no shown language: it is shown left-to-right, and its env.locale is the locale the host gives for the person (section 3.5). This version says nothing of the words of the host itself, such as its hints, sheets and messages.

The rules of this section use the five tables of Appendix A and nothing else: aliases (old codes), sameLanguage (languages compared as one), scripts (the script of a language), parents (regional parents) and rtlScripts (scripts written right to left). A host MUST apply them as written and MUST NOT consult other locale data, such as the likely subtags of Unicode CLDR, to choose the shown language or to work out its direction, its text chain or its formatting locale, so that every host gives the same answers for the same person. How a locale then writes a number or a date is not part of these rules. The rows of conformance/0.2/languages/ hold a host to these rules.

What a host is given#

  • The person's languages, in order of preference: a list of BCP 47 tags as the platform gives them, such as a browser's navigator.languages, the locale a chat gives a frame and then the page's languages, or a command's flag and else the locale of the process. The list may be empty.
  • A kept choice for this app and this person, or none: one of the app's own tags, which the person chose through the host's language switch and the host remembers.

Reading a person's tag#

A tag from the person's list is read as follows. A tag that cannot be read so is skipped.

  1. It is at most 64 characters, and splitting it at each hyphen gives subtags of 1 to 8 ASCII letters or digits. Case is ignored.
  2. The first subtag is the language: 2 or 3 letters, read in lower case, not und.
  3. A subtag of 4 letters right after the language is the script, read with its first letter in upper case and the others in lower case.
  4. A subtag of 2 letters or 3 digits right after the language, or right after the script when there is one, is the region, read in upper case.
  5. A language that table aliases lists is replaced by the tag the table gives: its language becomes the language, and its script, when it has one, becomes the script when the person's tag wrote none. iw-IL is read as he-IL and sh as sr-Latn.
  6. The Unicode keywords are the first subtag u after the language, script and region, with the subtags that follow it up to the next subtag of one character or the end, joined with hyphens in lower case. There are none when there is no such u, or when the subtag after it is missing or has one character. They are kept for the formatting locale.
  7. Every other subtag is not used.

An app's own tags are read by their one spelling (section 12.6), without these allowances.

Comparing tags#

  • The language as compared. Table sameLanguage gives, for a language it lists, the language it is compared as: no is compared as nb. Every other language is compared as itself.
  • The row of a language in table scripts is the row of the language as compared, or, when that has none, the row of the language itself. A language with a row is a language the table lists.
  • The script of a tag, for a language the table lists, is the script the tag writes; else, when the tag has a region that the row names for another script, that script; else the row's usual script. A tag of a language the table does not list has no script for comparing.
  • The same language and script. Two tags have the same language and script when their languages are compared as the same language and, in addition: when the table lists the language of either, the scripts of the two tags are equal; when it lists neither, they do not both write a script that differs. So zh-TW and zh-Hant have the same language and script, zh and zh-TW do not, and for a language the table lacks, xyz-Latn and xyz-Arab differ while xyz goes with either.
  • The regions of a tag, in order: its own region; then the parent of that region; then the parent of that one; and so on, at most 8 regions in all; then, last, no region. A tag without a region has only that last step. The parent is looked up in table parents under language-Script-REGION, with the tag's language as written and its script for comparing, for a language the table of scripts lists, and under language-REGION for any other language, whatever script the tag writes. The region of the parent is its last subtag. es-MX has the regions MX, 419, then none; en-AT has AT, 150, 001, then none; zh-MO and zh-Hant-MO have MO, HK, then none.
  • Shortest first. Of several tags, the one with fewer characters comes first, and of tags of equal length the one that comes first in ascending order of code points.

Table scripts lists the languages written in more than one script and the languages whose usual script runs right to left. Two of its rows differ from the likely subtags of Unicode CLDR on purpose, so that the table stays small and stable: a bare zh is Traditional only in TW, HK and MO, and a bare sr is Latin only in ME. In every other region the two keep their usual scripts, Simplified and Cyrillic.

Choosing the shown language#

  1. A kept choice that is one of the app's tags is the shown language. A kept choice that is not one of them is ignored.
  2. Otherwise the person's tags are taken in order. For each tag that can be read, the candidates are the app's tags that have the same language and script as it. A tag with no candidate passes to the next.
  3. With candidates, the regions of the person's tag are walked in order. At each step the candidates whose region is exactly that region are hits, and at the last step the candidates without a region. Of several hits, the shortest first. The first hit is the shown language.
  4. When no step has a hit, the shortest candidate is the shown language.
  5. When no tag of the person has a candidate, default is the shown language.

A script is never crossed: a reader of Traditional Chinese is not given zh, and a reader of Latin Serbian is not given sr. The first of the person's tags that has a candidate decides, even when a later tag would match more closely: for ["de-AT", "fr"] an app with de and fr shows de.

Direction#

The direction of an app's tag is right-to-left when its script is in table rtlScripts and left-to-right otherwise. Its script is the one the tag writes, else its script for comparing. A tag of a language the table of scripts does not list, with no script written, is left-to-right. An app in such a language that is written right to left states its direction by writing the script in its tag: xyz-Arab.

env.direction is the direction of the shown language. Direction comes from the shown language only: never from the person's region, and never from a setting. A definition cannot set its direction apart from its language.

The text chain#

A text of a key is looked for in these tables, in order:

  1. the table of the shown language;
  2. the tables of the app's other tags that have the same language and script as the shown language, met along the regions of the shown language: at each step, the tags whose region is exactly that region, and at the last step those without a region; several tags at one step in the order shortest first. For es-MX these are es-419, then es; for nb-NO among en, no, nb and nb-NO they are nb, then no;
  3. the table of default.

A tag is in the chain once, where it is first met. The first table that has the key gives its entry, whole: the forms of one table are never mixed with those of another. The language of that table is the language of the text.

The formatting locale#

Numbers, dates, relative times and plural categories follow the words they stand beside, written for the person's region. The formatting locale of an app's tag T for the person is made as follows.

  • P is the first of the person's tags that can be read and has the same language and script as T; else the first of the person's tags that can be read; else there is none.
  • The region is P's region; else T's region; else there is none.
  • The script is the script T writes. When T writes none and there is a region, it is T's script for comparing when the table lists T's language and the script for comparing of a tag of T's language with that region and no script is another; otherwise there is none.
  • The locale is T's language, then the script, then the region, joined with hyphens, leaving out what there is none of, then, when P has Unicode keywords, a hyphen and those keywords.
Shown language The person's languages Formatting locale
en ja-JP en-JP
ar ar-EG-u-nu-latn ar-EG-u-nu-latn
ar en-US ar-US
zh zh-Hans-HK zh-Hans-HK
pa ur-PK pa-Guru-PK
no en-GB, nb-NO no-NO
xyz-Arab en-US, xyz-Latn-MA xyz-Arab-US

env.locale is the formatting locale of the shown language. A text taken from another table of the chain is formatted with the formatting locale of that table's tag. formatNumber, formatDate, relativeTime and plural read env.locale, and so agree with the words of the app.

13. Parts: building apps from apps#

"uses": { "definitions": { "budgetApp": { "id": "com.example.budget", "version": "^1.2.0" } } },
"parts": {
  "budget": {
    "definition": "budgetApp",
    "with": { "goal": "=state.tripCost" },
    "capabilities": { "bank": "bank" },
    "grants": { "readSavings": { "rate": { "count": 4, "per": "P1D" } } }
  }
}

The included definition declares what it offers in its own exports:

"exports": {
  "inputs":  { "goal": "state.goal" },
  "state":   ["saved", "remaining"],
  "actions": ["logDeposit"],
  "events":  ["goalReached"],
  "views":   ["summary"]
}
  • Encapsulation. A parent sees only what a part exports: parts.budget.state.remaining in expressions, { "run": "budget.logDeposit" } in steps, { "event": "budget.goalReached" } in rule triggers, { "part": "budget", "view": "summary" } in views, and budget.logDeposit, budget.remaining and budget.goalReached in an agent surface's include lists (section 12.1). Everything else is private. A run of a part's action from the parent's steps gives the parent its output, never its done message (section 8).
  • Inputs. exports.inputs maps an input name to a stored state path in the part. The parent's with drives it reactively: the part's value follows the parent's expression. A driven input is read-only inside the part: a part step that writes it fails with state.readonly. Its type must accept every value the parent can drive. Validation reports a known type that cannot be accepted, but not null. At run time a driven value that does not conform is not written: the input keeps its previous value, and the host reports state.invalidValue. A driven value changes like any write, so the part's becomes triggers over it follow section 9: one that is already true when the parent first drives the input does not fire.
  • State. Each part instance has its own isolated state. Nothing is shared implicitly. A definition MAY be included more than once under different part names. A host MAY let a person start a part from the state of an instance of that definition the person owns. Only shared entries and the person's own user entries are copied; other people's values, device and session values, flow bookkeeping, grants, once records and the audit log are not. The copy is recorded in the source instance's audit log, and the two instances are independent afterwards. For a part whose definition is a carried copy (section 4), a host offers this only when the copy's digest is the digest the source instance runs: a carried copy is not the definition of an instance because its id matches.
  • Capabilities. parts.<name>.capabilities maps each of the part's capability aliases to one of the parent's. Contracts MUST be compatible: the same catalog id and contract name, at the same major version. Unmapped part capabilities are bound by the host as if the part were standalone.
  • Grants. A part's grant requests become part of the parent's and are shown to the approver as such, attributed to the part. parts.<name>.grants MAY attenuate a request (an additional where, which is combined with the part's own by logical and, a lower rate, a shorter duration, fewer scopes, a shorter operations list) or decline it with false. A parent can never widen what a part requested, and a part can never exercise more than the parent holds. A call made by a part's steps is covered only by that part's requests, as the parent attenuated them; a call made by the parent's steps is covered only by the parent's requests. Each request has its own rate, also when the part's capability is mapped to the parent's. A part's request that the parent declines with false is not put to the approver.
  • Language. A part is its own definition with its own localization. The host applies the same person's languages, and the kept choice of the app that includes the part, to the part's own tags by the rules of section 12.7, so a part can show another language than its parent. A part's env.language, env.direction and env.locale are its own.
  • Versions. A part is resolved by its semver range, and by digest when given, first among the carried copies of the file (section 4). Two parts MAY resolve to different versions of the same definition; instances are independent.
  • Carried copies. A part whose definition is a carried copy is a part like any other: encapsulation, a part's requests shown as the parent's, attenuation, the part's own language, the limits below, and that a change in any part an instance resolves is an update of the instance (section 6.4.1) all hold unchanged.
  • Limits. The include graph MUST be acyclic and MUST NOT be more than 8 levels deep, a depth every host supports.

14. Resolution and graceful degradation#

Before running a definition, a host resolves it and produces a resolution report: for every catalog, control, capability, part, surface, grant and code module, one of satisfied, degraded (with a note on what differs) or missing. For a part whose definition is a carried copy, and for a design system that is one, the report says it is carried in the file (section 4).

  • A missing required capability, a declined required grant, or an unresolvable part fails the load. A declined required personal request fails it only for that person (section 6.4.2).
  • A request for a capability that is unavailable, or for code the host cannot run, is not asked and does not fail the load. The steps that need it fail when they run (capability.unavailable, code.unsupported).
  • A request with no grant in force is missing, and the report says which it is: declined, or not asked yet (section 6). An optional request left to be asked later does not fail the load. A request given by use or contained is satisfied unless it was declined, and the report says that nobody was asked and why.
  • A catalog the host cannot find does not fail the load by itself. Its controls are missing and resolve to their fallbacks, and its capabilities are missing, which fails the load only if one of them is required. Validation tools still need the catalog to check a definition (uses.catalogNotFound).
  • A capability whose required config the host cannot supply is missing (section 5).
  • A missing optional capability leaves capabilities.<alias>.available as false. Calls to it fail with capability.unavailable.
  • A missing control is replaced by the node's fallback if present, otherwise by the control contract's declared degradation (degradeTo, which MAY name a contract in a catalog the control's catalog uses), otherwise by a host placeholder that shows the node's accessible label. The app still loads.
  • A host that lacks a whole surface simply does not serve it. The kernel is unaffected. A declared surface is satisfied only when the host serves it, and missing otherwise.
  • A type from a catalog the host cannot find is treated as any at run time, and the report marks it degraded.
  • A part's request that the parent declined with false is listed as declined by the including definition, not as missing. A request the parent attenuated, and that the approver granted as shown, is satisfied; degraded is for a grant narrower than what the approver was shown.
  • When meta.derivedFrom carries a digest and the host holds the definition it names, the host MUST verify the digest and fail the load on a mismatch. When the host does not hold that definition, the report says the origin is unverified.
  • The report shows configuration values the host supplied (section 5) and, after an update, which stored values were replaced and which flow instances were reset (section 6.4.1).
  • The report MUST be available to the owner, to members and to agents that hold access to the app. For an agent that does not hold full access, a host MAY reduce it to the name and status of each item.

15. Inspection, explanation and audit#

  • Explain. A host MUST be able to render any definition as plain language without running it: what the app holds, its main sections where it lists them, each action with who may run it, what it requires, whether it asks for confirmation and what it says once done, each rule as "When ..., then ...", each flow's stages and moves, each capability and each grant request with its reason and limits, who answers it, and whether it is asked, given by use, or given without asking (section 6), and the credit of each picture it carries that has one, with its source where given (section 12.5). Where it says what the app is made of, it says of a part whose definition is a carried copy that it is carried in the file (section 4). The rendering is derived from structure plus description, reason, and require and done message text. It is deterministic, so two people looking at the same definition see the same explanation. An explanation is meant to be shown and passed on, so it MUST NOT print a value written in the definition for an entry that is sensitive (section 7.3). It describes the whole definition, so a host SHOULD give it only to principals that hold full access to the app or hold the definition itself.
  • Audit. A host MUST record, per app instance: every action invocation (principal, surface, input, outcome), every capability operation (grant used, outcome; a call repeated under once is marked as repeated), every capability event delivered, every code run, every rule firing, timer and flow transition (with a reference to the record that caused it), every update of the instance (section 6.4.1), every grant issue, delegation, denial and revocation, and every load that failed because a required request was declined. A denial is either a declined request (which request, who declined, when) or a refused operation. Each record has a kind: action, operation, event (a capability event delivered), egress, code, rule, flow, handler (a visual handler's invocation), timer (an every trigger, a flow after timer or a timed source refresh firing), state (a write from a binding), lifecycle, update, access (access given to a principal), grant.issue, grant.delegate, grant.deny or grant.revoke. A record's id is what env.invocation gives (section 3.5). Routine refreshes of the environment, such as the minute tick of env.now, are not recorded. every firings at intervals under one minute are recorded as one timer record per minute, with a count. Writes to view state are not recorded, and successive writes from one binding while the person types form one record.
  • Redaction. A recorded input, output or error message is redacted when it was computed from a sensitive value (section 7.3). A value that was not is recorded in full, even when the same invocation also read sensitive values, so the log can still show, for example, the fixed text of a notification.
  • Causes. The record of a state change names as its cause the record of the action whose step made the write, also when that action was run by another action or belongs to a part. The record of a flow after transition names as its cause the record of the transition that put the flow instance in that state. A timed source read names its timer.
  • Keeping records. A host MAY bound the size of the log, but MUST keep the records of grants (issue, delegation, denial, revocation) and of updates for the life of the instance, and SHOULD keep at least 90 days of the rest.
  • Who reads the audit log. The owner can read every record of the instance. A member can read in full the records of their own invocations and of what those caused on their own behalf, and the other records in outline; what an invocation of theirs caused for another person, such as a value read for that person or a rule run in that person's session, is among the other records. An agent reads in full only the records of its own invocations, whose input it supplied and whose output it received. The other records it may see, which are those its invocations caused and, for an agent with full access, every record of the instance, are given in outline. A record in outline says what happened, when, and to which action, rule, flow or operation, without inputs, outputs or messages.
  • Why. From any audit record, a user MUST be able to walk the cause chain back to the principal action or trigger that started it.

16. Versioning, identity and history#

  • Spec version. oad is MAJOR.MINOR; this document defines 0.2. Before 1.0 every minor version is its own format: a host or tool declares the versions it reads and refuses a document of any other version, saying which versions it reads (document.version, validation.md). changes.md lists what changed from 0.1. From 1.0 on, minor versions only add; a 1.2 host runs any 1.x document, ignoring nothing silently: unknown constructs are reported as degraded or missing in the resolution report.
  • Definition version. Semver. Removing or renaming an export, action, action input field or agent-exposed state entry is a breaking change and requires a major bump.
  • Instance identity. An instance runs one definition at a time, identified by id; running it with another digest is an update (section 6.4.1).
  • Digest. The digest of a JSON document (a definition, catalog, design system or history) is sha256- followed by the base64url (no padding) SHA-256 of its canonical JSON form (RFC 8785, JCS). The digest of any other resource, such as a code module or a control implementation module, is sha256- followed by the base64url (no padding) SHA-256 of its bytes. Digests pin exact content in uses.definitions, meta.derivedFrom, code module, catalog implementations and history.
  • The digest of a definition never covers data. The digest of a definition is taken of the definition without the data member of each entry of its assets (section 12.5): those members, and nothing else, are left out before the canonical form is made. A definition that carries its pictures and the same definition without them are one definition with one digest, so everything that rests on the digest, such as a pin in uses.definitions or meta.derivedFrom, a signature, a grant issued for a definition, the definition an instance runs (section 6.4.1) and the digests of a history, holds whichever of the two a host or tool has. Each picture is still covered, through the digest member of its entry.
  • The digest of a definition never covers included. The member included (section 4) is left out before the canonical form is made, exactly as the data of each asset is. A definition with its carried copies and the same definition without them are one definition with one digest, and everything that rests on the digest holds for both. A carried copy is covered only where a reference pins its digest; each carried copy has its own digest, taken as for any definition or design system. A signature, a grant or an approval that rests on the digest of an app therefore says nothing about its carried copies unless the app's reference pins their digest, and a reference of uses.design pins none. What stands for the same app as before is the app's digest together with the digests of the parts it resolved, which is what an instance records (section 6.4.1).
  • History. A definition does not carry its own change log. History is a sidecar document (*.oad.history.json) of the form { "oadHistory": "0.2", "id", "base", "entries" }, where id is the definition's id and entries is an ordered list of { "version", "at", "by": { "kind": "person" | "agent", "id" }, "approvedBy", "intent", "patch", "digest" }. at is a UTC datetime written with Z, patch is an RFC 6902 JSON Patch from the previous entry's document, intent is the request that led to the change, in the requester's words, and digest is the digest of the document after the patch. approvedBy is optional: { "kind": "person", "id" }, the person who agreed to the change. A tool that applies a change which widens what the app may do (a new or broader grant request, a new capability, code module or network origin) SHOULD record who agreed. base is optional: { "version", "digest" } of the document the first patch applies to. Without base, the first patch applies to the empty object, so the history rebuilds the definition from nothing. A history with a base can be replayed only by someone who also holds that base document, which the sidecar does not carry; a tool that starts a history for an existing definition SHOULD therefore omit base and record the whole definition as the first entry. Edits are undone one at a time by replaying the history up to the entry before; a JSON Patch alone does not carry the values it removed. Keeping it beside the file keeps the definition small and lets a definition be shared without its past.
  • Signatures. Detached signatures over the digest are carried in a sidecar and are specified in contracts.md together with catalog signing.

17. Errors#

Failures carry a stable code and a human-readable message. Codes defined here:

Code Raised when
action.invalidInput An action's input, or a file reference in an agent's tool input, is not valid (sections 5 and 8).
action.forbidden An action's allow is not true, or the caller has no access to the action (sections 6.1 and 8).
action.refused A require entry is not true; carries the entry's message (section 8).
action.declined A confirmation was declined or not answered (section 8).
action.failed An action failed for a reason no other code names.
instance.forbidden A person who holds no access to an instance tried to load it, or someone other than the owner presented a different definition for it (sections 6.4 and 6.4.1).
grant.denied No issued grant covers an operation (section 6).
grant.expired The grant that would cover an operation has expired.
grant.rateLimited An operation would exceed its grant's rate.
capability.unavailable A call names a capability the host could not bind (section 14).
capability.failed A provider failed, or an operation's input or once key is not valid.
capability.onceMismatch A call repeated a once key under the same identity with a different input (section 8.3).
code.unsupported The host cannot run the module's runtime.
code.limit A module exceeded its limits.
code.failed A module failed or returned something that is not plain data (section 11).
flow.forbidden The transition taken has an allow that is not true (section 10).
flow.noTransition A flow event has no element, or no transition to take (section 10).
flow.fieldWrite A step wrote the state field of a collection flow (section 10).
rule.cascade A rule would have run, or a sourced entry would have been read, more than 16 levels below the work that started the cascade, counting the capability events that follow from the cascade's own calls; recorded in the audit log (sections 7.1 and 9).
state.conflict A write under conflict: "reject" was based on a stale value (section 7.2).
state.readonly A write targets a derived or sourced entry, or a part's driven input (sections 8.1 and 13).
state.invalidValue A value does not conform to its entry's type, or a source's output does not (sections 7 and 7.1).
state.noElement A write through a selector matched no element (section 8.1).
egress.denied A remote fetch is not covered by a grant (section 6.3).
expression.syntax An expression or path does not parse.
expression.error An expression failed when evaluated (expressions.md).
resolution.failed The definition could not be resolved for loading (section 14).

An app MAY use its own codes in a fail step (section 8.1). The diagnostics a validator reports, such as action.confirmBypassed or call.onceEffect, are listed in validation.md.

Expression errors are contained where they occur: a failing derive yields null and a diagnostic; a failing guard or condition (allow, a require entry's that, if, the when of a node, where, becomes) counts as not-true and produces a diagnostic; a failing expression in a step fails the step.

Elsewhere a failing expression has these effects:

  • A failing prop or view title is absent, so its default applies; a failing required prop gives the node's placeholder (section 14). A canvas that has already drawn keeps its last picture in the placeholder's place for a short time (contracts.md section 8.3).
  • A failing each.in repeats nothing.
  • A failing binding or selector shows an empty, disabled control and writes nothing.
  • A failing source.with or source.when is a failed read with expression.error.
  • A failing config member is left unsupplied (section 5).
  • A failing done message, or one that is not text, gives no message, and the action has still succeeded (section 8).
  • A failing stored initial or view state initial gives null.

18. Conformance#

A conforming definition validates against the 0.2 JSON Schema and passes the semantic checks of validation.md (references resolve, names are unique and well-formed, expressions parse and agree with the types that can be known, derived state and the action call graph are acyclic, every capability operation used has a scope covered by some grant request, every code module has a grant request).

A conforming host loads conforming definitions, produces resolution reports, enforces grants as in section 6, implements execution semantics as in sections 7 to 11, and provides explanation and audit as in section 15. A host declares which surfaces and code runtimes it supports. Conformance fixtures live in conformance/0.2/.

18.1 Sizes#

A host MUST accept a definition that is within all of these sizes:

  • the definition, as JSON without insignificant white space and without the data of its assets, is at most 2,621,440 bytes in UTF-8;
  • it has at most 64 assets;
  • the data of each asset is at most 1,048,576 characters, and the data of all its assets together at most 2,621,440 characters;
  • its localization (section 12.6) has at most 64 languages, at most 2,000 keys in one language, at most 2,000 code points in one text (each form of an entry counts alone), and at most 24 forms in one entry. All of it counts toward the size of the definition like any other member;
  • the size of the definition does not count included (section 4), which has sizes of its own: it holds at most 16 definitions and at most 17 design systems, and the carried copies together are within the sizes of one definition: each as JSON without insignificant white space and without the data of its assets, at most 2,621,440 bytes in UTF-8 in all; at most 64 assets among them; the data of each of those assets at most 1,048,576 characters, and of all of them together at most 2,621,440 characters.

A host MAY accept more, and MAY let the person who runs it set how many definitions one app may include in all, counting the parts of its parts once each. A host that refuses a document for its size SHOULD say which of these sizes the document passed and by how much. A definition beyond these sizes is still valid; a validator warns that not every host accepts it (validation.md, section 9.1). Section 13 gives the deepest include graph every host supports.

Appendix A. Language tables#

The five tables that section 12.7 uses, in full. Script codes are those of ISO 15924; region codes are those of ISO 3166 and the areas of UN M49. Table scripts follows the likely subtags of Unicode CLDR, with the two differences that section 12.7 names.

A.1 Old codes (aliases)#

The old language codes a person's device may still send, and the tag each is read as (section 12.7, "Reading a person's tag"). They apply to a person's tags only: an app's own tag never uses one.

Old code Read as
iw he
in id
ji yi
jw jv
mo ro
tl fil
sh sr-Latn
cmn zh

A.2 One language (sameLanguage)#

Languages that are one language when tags are compared. Both are valid tags of an app.

Language Compared as
no nb

A.3 Scripts (scripts)#

For each language listed, its usual script and the regions where another script is usual. Listed are the languages written in more than one script and the languages whose usual script runs right to left; for any other language, script is not compared.

Language Usual script Another script, and the regions where it is usual
acm Arab
aeb Arab
afb Arab
apc Arab
ar Arab
arq Arab
ars Arab
ary Arab
arz Arab
az Latn Arab: IQ, IR; Cyrl: RU
azb Arab
bal Arab
bgn Arab
bm Latn
bqi Arab
brh Arab
bs Latn
ckb Arab
dv Thaa
fa Arab
ff Latn
glk Arab
ha Latn Arab: CM, SD
hak Hans Hant: TW
haz Arab
he Hebr
hi Deva
iu Cans
khw Arab
kk Cyrl Arab: AF, CN, IR, MN
kok Deva
ks Arab
ku Latn Arab: IQ, IR, LB; Cyrl: AM, AZ, GE, TM
ky Cyrl Arab: CN; Latn: TR
lah Arab
lrc Arab
mn Cyrl Mong: CN
mni Beng
ms Latn
mzn Arab
nan Hans Hant: MO, TW
nqo Nkoo
pa Guru Arab: PK
pnb Arab
ps Arab
rhg Rohg
sat Olck
sd Arab Deva: IN
sdh Arab
shi Tfng
skr Arab
sr Cyrl Latn: ME
syr Syrc
tg Cyrl Arab: PK
ug Arab Cyrl: KZ, MN
ur Arab
uz Latn Arab: AF; Cyrl: CN
vai Vaii
yi Hebr
yue Hant Hans: CN
zh Hans Hant: HK, MO, TW

A.4 Regional parents (parents)#

For en, es, pt and zh-Hant, the regions whose texts fall back to a wider regional form before the plain language, taken from Unicode CLDR 49. Every tag is written language-Script-REGION for a language that table scripts lists and language-REGION for any other, and a parent has the language and the script of the tags whose parent it is.

Parent The tags whose parent it is
en-001 en-150, en-AG, en-AI, en-AU, en-BB, en-BM, en-BS, en-BW, en-BZ, en-CC, en-CK, en-CM, en-CX, en-CY, en-DG, en-DM, en-ER, en-FJ, en-FK, en-FM, en-GB, en-GD, en-GG, en-GH, en-GI, en-GM, en-GS, en-GY, en-HK, en-ID, en-IE, en-IL, en-IM, en-IN, en-IO, en-JE, en-JM, en-KE, en-KI, en-KN, en-KY, en-LC, en-LR, en-LS, en-MG, en-MO, en-MS, en-MT, en-MU, en-MV, en-MW, en-MY, en-NA, en-NF, en-NG, en-NR, en-NU, en-NZ, en-PG, en-PK, en-PN, en-PW, en-RW, en-SB, en-SC, en-SD, en-SG, en-SH, en-SL, en-SS, en-SX, en-SZ, en-TC, en-TK, en-TO, en-TT, en-TV, en-TZ, en-UG, en-VC, en-VG, en-VU, en-WS, en-ZA, en-ZM, en-ZW
en-150 en-AT, en-BE, en-CH, en-CZ, en-DE, en-DK, en-EE, en-ES, en-FI, en-FR, en-GE, en-HU, en-IT, en-LT, en-LV, en-NL, en-NO, en-PL, en-PT, en-RO, en-SE, en-SI, en-SK, en-UA
es-419 es-AR, es-BO, es-BR, es-BZ, es-CL, es-CO, es-CR, es-CU, es-DO, es-EC, es-GT, es-HN, es-JP, es-MX, es-NI, es-PA, es-PE, es-PR, es-PY, es-SV, es-US, es-UY, es-VE
pt-PT pt-AO, pt-CH, pt-CV, pt-FR, pt-GQ, pt-GW, pt-LU, pt-MO, pt-MZ, pt-ST, pt-TL
zh-Hant-HK zh-Hant-MO

A.5 Right-to-left scripts (rtlScripts)#

The scripts written right to left, those in use and the historic ones.

Kind Scripts
In use Adlm, Arab, Aran, Hebr, Mand, Nkoo, Rohg, Syrc, Syre, Syrj, Syrn, Thaa
Historic Armi, Avst, Chrs, Cprt, Elym, Gara, Hatr, Hung, Khar, Lydi, Mani, Mend, Merc, Mero, Narb, Nbat, Orkh, Ougr, Palm, Phli, Phlp, Phnx, Prti, Samr, Sarb, Sidt, Sogd, Sogo, Yezi