From f02d0cad34bb4d5505f4050ed9686810dded463d Mon Sep 17 00:00:00 2001 From: delchev Date: Fri, 14 Aug 2026 19:45:22 +0300 Subject: [PATCH] docs: lifecycle - the whole legal status graph, enforced on every status write Renders the spec change (IntentFile/intent-specification#16): the new entities-chapter section, the transitions cross-reference, the status-by-name site list, the reference index row, and the Planned list losing "a declarative state machine". --- docs/reference.md | 2 ++ docs/spec/data.md | 2 +- docs/spec/entities.md | 23 +++++++++++++++++++++++ docs/spec/glue.md | 2 ++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/docs/reference.md b/docs/reference.md index b9b9735..ad724d0 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -20,6 +20,7 @@ The quick lookup surface: one line and a minimal snippet per construct. For rule | [`checks`](/spec/entities#checks-declarative-validations) | cross-field / cross-line validations | | [`checks: kind: guard`](/spec/entities#kind-guard-a-precondition-over-an-aggregate) | a precondition over an aggregate: block, mark for a task, or reject | | [`immutableWhen` / `immutable`](/spec/entities#immutablewhen-immutable-user-write-immutability) | reject user writes in a status / append-only | +| [`lifecycle`](/spec/entities#lifecycle-the-legal-status-graph) | the whole legal status graph, enforced on every status write | | [`locksWithMaster`](/spec/entities#lockswithmaster-a-child-collection-that-outlives-its-masters-lock) | a child collection that stays writable while its master is locked | | [`hierarchy` / `leafOnly`](/spec/entities#hierarchy-leafonly-tree-entities) | tree entities, leaf-only references | | [calculated fields](/spec/entities#calculated-fields) | server + UI-evaluated expressions, date helpers, call-outs | @@ -174,4 +175,5 @@ The following are parsed (or reserved) but not yet materialised by a generator; - **Cross-model status names and stage scopes** — a nomenclature owned by another model is seeded there, so its stages and names cannot be resolved from the referencing file; such references are rejected with the numeric-id fallback named. - **`manyToMany`** — parsed but never materialised; the supported shape is the [explicit intermediate entity](/spec/relations#many-to-many). - A declarative state machine, and shadow audit-history entities (audit *columns* via `audit: true` ship today). +- Event-driven document generation (produce a document on an event), and shadow audit-history entities (audit *columns* via `audit: true` ship today). - Arbitrary resolver-path task assignment beyond `assignee: personal`. diff --git a/docs/spec/data.md b/docs/spec/data.md index 0c0a1b6..0d582e6 100644 --- a/docs/spec/data.md +++ b/docs/spec/data.md @@ -60,7 +60,7 @@ The classification exists because a status **id is data, but its meaning is not* ### Status references — name, not number -Everywhere the file names a status — a [transition's](/spec/glue#transitions-guarded-status-flips) `from` and `setStatus`, a relation's `init`, a status-setting step's `value`, [`abortOn`](/spec/processes#aborton-cancel-the-instance-on-a-terminal-status)'s `status`, a [check's](/spec/entities#checks-declarative-validations) `status` / `setStatus`, [`immutableWhen`](/spec/entities#immutablewhen-immutable-user-write-immutability), a [posting's](/spec/glue#postings-source-document-to-ledger) event guard, a [report's](/spec/presentation#reports) `filter` — the seeded **name** may be written instead of the id: +Everywhere the file names a status — a [transition's](/spec/glue#transitions-guarded-status-flips) `from` and `setStatus`, a relation's `init`, a status-setting step's `value`, [`abortOn`](/spec/processes#aborton-cancel-the-instance-on-a-terminal-status)'s `status`, a [check's](/spec/entities#checks-declarative-validations) `status` / `setStatus`, [`immutableWhen`](/spec/entities#immutablewhen-immutable-user-write-immutability), a [`lifecycle`](/spec/entities#lifecycle-the-legal-status-graph) edge, a [posting's](/spec/glue#postings-source-document-to-ledger) event guard, a [report's](/spec/presentation#reports) `filter` — the seeded **name** may be written instead of the id: ```yaml transitions: diff --git a/docs/spec/entities.md b/docs/spec/entities.md index 3873cb8..94d4c0a 100644 --- a/docs/spec/entities.md +++ b/docs/spec/entities.md @@ -311,6 +311,29 @@ The lock also covers the entity's **composition children**. A child declares no ::: info Normative A generator MUST refuse a user create, update or delete of a composition child whose master is currently immutable, unless that child declares `locksWithMaster: false`. The refusal MUST cover every user surface it generates, not only the affordances it renders — permitting the write through a different door undoes the lock as surely as removing it. It MUST NOT extend to system / workflow writes, which are what corrects an immutable record. ::: +## lifecycle — the legal status graph + +Everything else about statuses is stated one edge at a time: `init:` says where a record starts, a [`transitions`](/spec/glue#transitions-guarded-status-flips) button guards the flips a user performs *through that button*, a workflow step sets a status, a [check](#checks-declarative-validations) files a rejected record in another. Nowhere does the file say which moves are legal *at all* — so any writer that is not a transition button (a workflow branch, a glue action, an API call) can move a document from any status to any other, and nothing notices. + +`lifecycle:` states the whole graph, once: + +```yaml +- name: SalesInvoice + lifecycle: + edges: + - { from: DRAFT, to: [ISSUED, CANCELLED] } + - { from: ISSUED, to: [PAID, VOIDED] } +``` + +- One entry per **source** status, listing every status reachable from it. Both sides accept a [seeded status name or its id](/spec/data#status-references-name-not-number). +- The graph is always over the entity's `function: EntityStatus` relation, so it names no column; the nomenclature must be seeded in the same file (a status entity owned by another model is seeded there, and so is its lifecycle). +- A status not listed as any `from` is **terminal**; a status listed nowhere is simply unreachable through this entity. + +> **Normative.** A conforming generator MUST validate every status write against the graph — user, workflow, glue, transition button alike — and reject a move no edge declares, with a message naming both statuses. Enforcement therefore belongs to the layer every writer passes through (the generated persistence layer), never to the transition endpoints alone, which would leave every other writer unguarded. Where the status relation declares `init:`, a record MUST also be *created* in that status: entering the lifecycle anywhere else skips the graph rather than travelling it. + +> **Normative.** With a lifecycle declared, `transitions` become **presentation over its edges**: each `from` status of a transition MUST reach its `setStatus` along a declared edge, and a status written by a workflow step or forced by a check's rejection MUST be one that some edge reaches. A conforming generator reports the disagreement when the file is read, not when the button is pressed — a reject path transiting through an approved status is exactly the mistake the graph exists to catch. + +It composes with the [`stage:` classification](/spec/data#stage-what-a-status-means-to-the-lifecycle): a stage says what a status *means* (draft, live, cancelled, void) and scopes reports by it; the lifecycle says how a record may *move* between statuses. ## locksWithMaster — a child collection that outlives its master's lock diff --git a/docs/spec/glue.md b/docs/spec/glue.md index 434bfef..0b3a78f 100644 --- a/docs/spec/glue.md +++ b/docs/spec/glue.md @@ -415,6 +415,8 @@ transitions: body: "The invoice has been cancelled." ``` +When the entity declares a [`lifecycle`](/spec/entities#lifecycle-the-legal-status-graph), a transition is presentation over its edges: its `from`/`setStatus` pair must be one, and the graph — not the button — is what every other writer is held to as well. + A transition may carry a [notify block](#the-notify-block-and-attach-print) — "on Void, tell the customer" — attempted after the flip has committed, and unable to fail it. ## postings — source document to ledger