From 3c7e8ee8a01ec94df42b78dc61e52e7fea0b2c2b 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 | 3 ++- docs/spec/data.md | 2 +- docs/spec/entities.md | 24 ++++++++++++++++++++++++ docs/spec/glue.md | 2 ++ 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/docs/reference.md b/docs/reference.md index 48d8eae..dddb34e 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 | @@ -163,5 +164,5 @@ The following are parsed (or reserved) but not yet materialised by a generator; - Reserved `function` values for upcoming presentations (`Board`, `Gantt`, `Timeline`). - **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). -- Event-driven document generation (produce a document on an event), 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 d28763d..f87c2d0 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 de31431..0dc4672 100644 --- a/docs/spec/entities.md +++ b/docs/spec/entities.md @@ -306,6 +306,30 @@ The total is recomputed from the guarded entity's own rows for the incoming reco `immutableWhen` requires a `function: EntityStatus` relation; `immutable: true` needs none and is mutually exclusive with it. System / workflow writes stay possible — corrections to an immutable record are flow-generated reversals, never edits. +## 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 An entity's immutability covers **that entity**. A composition child is a different entity, so a master that locks says nothing about whether its child collections should: diff --git a/docs/spec/glue.md b/docs/spec/glue.md index 0de97c5..bf0a3dc 100644 --- a/docs/spec/glue.md +++ b/docs/spec/glue.md @@ -310,6 +310,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