@aotter/mantle 0.0.11-alpha.73 → 0.1.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,14 +3,7 @@
3
3
  > If you're an AI working in a project that consumes `@aotter/mantle-*`,
4
4
  > read this first. It explains the entire surface area in one page.
5
5
  >
6
- > **Status**: v0.1 grammar lock. Atoms are shipped; rich sub-spec
7
- > grammar (policies, recursive views, temporal predicates, quotas,
8
- > projection triggers, cron/queue sources, and extended lifecycle hooks) is
9
- > reserved as **DRAFT** — see "Future grammar" appendix. Editorial
10
- > lifecycle is the one shipped grammar key whose runtime is **deferred
11
- > to v0.1.x**: parser and boot accept the shape, while
12
- > `request_publish` rejects it with `LIFECYCLE_NOT_IN_V010` until the approval
13
- > queue lands. Do not use editorial for a v0.1 publishing workflow.
6
+ > **Status**: v0.1 shipped grammar. Unknown keys and enum values are rejected.
14
7
  >
15
8
  > **This is the reference manual** — what the system is. For *why* it
16
9
  > ended up this shape (alternatives considered, trade-offs accepted),
@@ -33,7 +26,7 @@ primitives Postgres has shipped for 30 years.
33
26
  | **`Schema`** | `CREATE TABLE` | no (manipulated via View / Procedure) | no |
34
27
  | **`View`** | `CREATE VIEW` | **yes** (auto-mounted on its declared public/staff REST and MCP surface; see ADR-0012) | no |
35
28
  | **`Procedure`** | `CREATE FUNCTION ... LANGUAGE plpgsql` | **no** (transport-agnostic; needs a `Trigger` to bind it) | **yes — handler ref to consumer's TS file** |
36
- | **`Trigger`** | `CREATE TRIGGER` + `pg_cron` + PostgREST route + `LISTEN/NOTIFY` | yes (the binding atom — turns Procedures into HTTP endpoints, cron jobs, MCP tools, lifecycle hooks) | no |
29
+ | **`Trigger`** | `CREATE TRIGGER` + route/tool binding | yes (the binding atom — turns Procedures into HTTP endpoints, MCP tools, and lifecycle hooks) | no |
37
30
 
38
31
  The **read/write asymmetry is by design** and matches HTTP safe-vs-unsafe
39
32
  semantics. Reads (`View`) are idempotent and cacheable; the SDK
@@ -53,7 +46,6 @@ apiVersion: cms.mantle.aotter.net/v1
53
46
  kind: Schema | View | Procedure | Trigger
54
47
  metadata:
55
48
  name: posts # required, kebab-case, unique within deployment
56
- labels: { ... } # optional, free-form
57
49
  spec:
58
50
  ... # kind-specific
59
51
  ```
@@ -73,7 +65,7 @@ A logical feature commonly bundles a Procedure + a Trigger (and often a
73
65
  Schema and a View). Put related atoms in one file separated by `---`:
74
66
 
75
67
  ```yaml
76
- # manifests/contact.yaml
68
+ # manifests/site.yaml
77
69
  apiVersion: cms.mantle.aotter.net/v1
78
70
  kind: Procedure
79
71
  metadata: { name: send-contact-message }
@@ -93,8 +85,8 @@ spec:
93
85
  target: { procedure: send-contact-message }
94
86
  ```
95
87
 
96
- One file, two atoms. File count stays low; conceptual atom separation
97
- stays honest.
88
+ One fixed file, two documents. Add every atom to `manifests/site.yaml` with
89
+ `---`; the loader rejects other manifest filenames.
98
90
 
99
91
  ## What each atom is for (v0.1 minimum essential grammar)
100
92
 
@@ -112,7 +104,7 @@ metadata: { name: posts }
112
104
  spec:
113
105
  title: Posts # required: human-readable label for the admin UI
114
106
  localized: true # opt-in: row carries data.locale (ADR-0010)
115
- lifecycle: simple # default; 'none' is operational, 'editorial' is reserved
107
+ lifecycle: publishing # default; use 'operational' for live records
116
108
  schema:
117
109
  $schema: https://json-schema.org/draft/2020-12/schema
118
110
  type: object
@@ -126,7 +118,8 @@ spec:
126
118
  # against localized Schemas.
127
119
  content: { type: string }
128
120
  authorId: { type: string, format: uuid, x-mantle-bind: ctx.user }
129
- createdAt: { type: string, format: date-time, x-mantle-bind: now }
121
+ createdAt: { type: integer, x-mcp-hint: timestamp-ms, x-mantle-bind: now }
122
+ searchableFields: [title, slug] # id is always searched
130
123
  uniqueIndexes: [[slug, locale]]
131
124
  indexes: [[locale, title]] # ordered, non-unique hot path
132
125
  ```
@@ -135,6 +128,17 @@ spec:
135
128
  in the user's primary language (the install-time chosen locale); the
136
129
  SPA shows this everywhere instead of `metadata.name`.
137
130
 
131
+ **`spec.searchableFields`** — optional allowlist of top-level string
132
+ properties used by Admin and Staff MCP substring search. Entry id is always
133
+ searchable. This is separate from `indexes`; ordinary B-tree indexes do not
134
+ accelerate leading-wildcard substring search.
135
+
136
+ **`spec.uiSchema.list.filterField`** — optional Admin-only primary filter for
137
+ an operational collection. The field must declare a non-empty string `enum`
138
+ and be the first field of an `indexes` or `uniqueIndexes` tuple. Admin reuses
139
+ the enum for sidebar links and list tabs; Staff MCP uses declared Views for
140
+ richer query capabilities instead of reading UI configuration.
141
+
138
142
  **`spec.localized: bool`** (default `false`, ADR-0010) — opt-in per
139
143
  Schema. Localized Schemas store locale in `data.locale`; non-localized
140
144
  Schemas reject `data.locale` writes. Site config must declare the set
@@ -144,25 +148,22 @@ validates manifest shape.
144
148
 
145
149
  **`spec.translates: { parent, on }`** (ADR-0010) — declares this
146
150
  Schema as the translation companion to a non-localized parent, joined
147
- on the named field (typically `slug`). Implies `localized: true`. The
151
+ on the named field (typically `slug`). Requires an explicit
152
+ `localized: true`. The
148
153
  admin UI surfaces the child only as locale tabs in the parent's editor.
149
154
 
155
+ Use a standalone localized Schema only when each locale row is an
156
+ independent record. When several locale rows are versions of one entity,
157
+ declare a non-localized parent plus a localized `translates` child; that
158
+ relationship is what powers translation grouping and completeness in Admin.
159
+
150
160
  #### Lifecycle
151
161
 
152
- **`spec.lifecycle: 'simple' | 'editorial' | 'none'`** — controls the
162
+ **`spec.lifecycle: 'publishing' | 'operational'`** — controls the
153
163
  entry's state machine.
154
164
 
155
- - `simple` (default) — `draft → published → archived`. No approval
156
- queue. **This is the only content-workflow mode whose runtime ships
157
- in v0.1.0.**
158
- - `editorial` — the six-state machine with an approval queue
159
- (`draft → review → approved → scheduled → published → archived`,
160
- with `published` returnable to `draft` for republish). The grammar and
161
- state-machine vocabulary are reserved for forward compatibility, but the
162
- approval/request-publish runtime is on the v0.1.x roadmap. In v0.1,
163
- `request_publish` rejects with `LIFECYCLE_NOT_IN_V010`; do not declare
164
- editorial for a current publishing workflow.
165
- - `none` — **operational records**, not authored content: orders,
165
+ - `publishing` (default) — `draft → published → archived`. No approval queue.
166
+ - `operational` — records that are not authored content: orders,
166
167
  inventory snapshots, grant/audit rows — anything written by
167
168
  Procedures as a side effect rather than drafted by a person. No
168
169
  content workflow applies: entries are live (`published`) the moment
@@ -175,8 +176,8 @@ entry's state machine.
175
176
  `update_record_<schema>` for these Schemas instead of draft tools.
176
177
 
177
178
  The modes are **per-Schema and mix freely** within a site. There is no
178
- site-wide lifecycle setting; one Schema can be `simple` while another
179
- is `editorial` and a third is `none`.
179
+ site-wide lifecycle setting; one Schema can be `publishing` while another
180
+ is `operational`.
180
181
 
181
182
  **Property-level extensions** (JSON Schema vendor keywords, all optional):
182
183
 
@@ -204,17 +205,11 @@ wire.
204
205
  | `now` | Server timestamp at write (ISO-8601 string with timezone) | `createdAt`, `submittedAt`, `grantedAt` |
205
206
 
206
207
  **v0.1 stamping behavior**:
207
- - Stamped on `INSERT` only. Update-stamping (e.g. `updatedAt: now` that
208
- re-stamps on every UPDATE) is DRAFT — it lands when first use case
209
- surfaces.
208
+ - Stamped on `INSERT` only.
210
209
  - Caller-supplied value: rejected at input validation. The Procedure's
211
210
  effective input schema strips bound fields before checking caller
212
211
  input, so callers can't accidentally send them.
213
212
  - Visible in View output: yes, as ordinary columns. No special masking.
214
- - Used by `requires.auth.owns:` predicate (DRAFT): the predicate
215
- compares a row's `x-mantle-bind: ctx.user` field to the current
216
- `:ctx.user` to verify ownership without configuring per-Schema
217
- owner-column names.
218
213
 
219
214
  **Why a closed enum** (highest-leverage discipline in the spec): bind
220
215
  values are server-controlled identity + time facts. If we accepted
@@ -237,7 +232,11 @@ properties:
237
232
  Informational FK marker on a string-typed field that holds an ID
238
233
  referencing rows in another Schema. Not enforced in v0.1 (the SDK
239
234
  passes it through; no foreign-key constraint, no cascade, no orphan
240
- detection). Future grammar may upgrade it to enforced.
235
+ detection). The admin uses declared refs to show related rows and to nest
236
+ required child collections; it does not infer relationships from field names.
237
+ Declare a single-field `indexes` entry for the ref field (for example,
238
+ `indexes: [[authorId]]`) when reverse lookups must stay bounded. Mantle adds
239
+ the native entry-order columns to that access path.
241
240
 
242
241
  **Example**:
243
242
  ```yaml
@@ -281,12 +280,6 @@ MCP tool schemas preserve the hint for agents. Admin surfaces expose
281
280
  media-shaped fields but first-party upload hosting is optional and not
282
281
  part of first-run provisioning.
283
282
 
284
- ---
285
-
286
- Anything beyond these three (policies, computed columns, RBAC grants,
287
- owner declarations, `x-mantle-bind` enum extension) is **DRAFT** — see
288
- appendix.
289
-
290
283
  **Postgres analogue**: `CREATE TABLE posts (id UUID PRIMARY KEY, ...,
291
284
  UNIQUE (slug, locale));`
292
285
 
@@ -358,11 +351,8 @@ query, no `LIMIT n+1` probe.
358
351
 
359
352
  **v0.1 filter AST**: comparison operators (`eq`, `gt`, `gte`, `lt`,
360
353
  `lte`) plus `and` / `or`. Comparison `value` may be a literal or a
361
- `{ $param: <name> }` sentinel. v0.1.0 enforces required-only param refs;
362
- optional-with-skip semantics are reserved for v0.1.x. Field-to-field
363
- comparisons are not supported yet; compare a field to a literal or
364
- param. Anything else (`contains`, `recursive`, `gatedBy`,
365
- `join.aggregate`, `policies.skip`) is DRAFT.
354
+ `{ $param: <name> }` sentinel. Param refs must be required. Field-to-field
355
+ comparisons are not supported; compare a field to a literal or param.
366
356
 
367
357
  **Postgres analogue**: `CREATE VIEW recent_published AS SELECT ...
368
358
  FROM posts WHERE status = 'published' ORDER BY updated_at DESC LIMIT
@@ -378,8 +368,8 @@ provides the handler function with auto-generated TS types.
378
368
  `Procedure` is **transport-agnostic and not directly exposed**. It does
379
369
  not contain HTTP paths, methods, or MCP tool names. To call a Procedure
380
370
  from outside the SDK runtime, declare a `Trigger` whose `target` points
381
- at it. The same Procedure can be bound by multiple Triggers (HTTP +
382
- cron + MCP + lifecycle, all sharing one handler).
371
+ at it. The same Procedure can be bound by multiple Triggers (HTTP + MCP +
372
+ lifecycle, all sharing one handler).
383
373
 
384
374
  ```yaml
385
375
  apiVersion: cms.mantle.aotter.net/v1
@@ -421,9 +411,6 @@ export const handlers = {
421
411
  - `ctx.auth.scope: <scope>` — verified credential carries the exact opaque,
422
412
  consumer-owned scope; repeat to require multiple scopes
423
413
 
424
- Anything beyond this (`any:`, `owns:`, `withinMinutes:`, `contains:`,
425
- `requires.window`, `requires.quota`, `errors`, `retry`) is DRAFT.
426
-
427
414
  Both Procedures and Views may add one dynamic guard beside `auth`:
428
415
 
429
416
  ```yaml
@@ -480,7 +467,7 @@ spec:
480
467
  ```
481
468
 
482
469
  The same Procedure can have multiple Triggers — that's how it becomes
483
- "an HTTP endpoint AND a cron job AND an MCP tool" without duplicating
470
+ an HTTP endpoint and an MCP tool without duplicating
484
471
  handler logic. Each transport is one Trigger; the Procedure body is
485
472
  shared.
486
473
 
@@ -491,17 +478,14 @@ tool on `surface: public | staff`), or `lifecycle` (entry-writer hook). For `lif
491
478
  Lifecycle hooks are wired through `LifecycleHookingEntryRepository`, so
492
479
  MCP, admin, and builtin write paths share the same hook behavior.
493
480
 
494
- - `cron` / `queue` are **DRAFT (v0.2+)** — speculative, gated by
495
- concrete consumer demand. Same appendix § "DRAFT (v0.2+)."
496
-
497
481
  The state-machine "lifecycle" from the Schema atom
498
- (`Schema.spec.lifecycle: simple | editorial`) is a separate domain
482
+ (`Schema.spec.lifecycle: publishing | operational`) is a separate domain
499
483
  that shares the word. The Schema setting governs which states an
500
484
  entry can be in; shipped lifecycle Triggers govern what fires around
501
485
  mutations.
502
486
 
503
487
  **Postgres analogue**: `CREATE TRIGGER ... AFTER INSERT ON posts
504
- EXECUTE FUNCTION ...` (lifecycle); `pg_cron` extension (cron); plus
488
+ EXECUTE FUNCTION ...` (lifecycle), plus
505
489
  `CREATE FUNCTION` exposed via PostgREST routes (http) — Postgres has
506
490
  had all of these via extensions for years, just split across multiple
507
491
  mechanisms. We unify them under one atom.
@@ -579,7 +563,7 @@ different constraints.
579
563
  | `UNAUTHENTICATED` | `401` | no active session (admin API: missing/expired session cookie) |
580
564
  | `AUTH_DENIED` | `403` | `requires.auth` predicate evaluated false (or admin: caller lacks required staff role) |
581
565
  | `ENTITLEMENT_REQUIRED` | `402` | consumer guard denies current payment/membership/transaction entitlement |
582
- | `NOT_FOUND` | `404` | resource not found — admin: approval id; runtime: View name at `/api/views/<name>` |
566
+ | `NOT_FOUND` | `404` | resource not found — entry id or View name at `/api/views/<name>` |
583
567
  | `HANDLER_NOT_REGISTERED` | `500` | `handler.ref` key not registered at boot |
584
568
  | `DISPATCHER_NOT_BUILT` | `501` | runtime feature not implemented in this SDK build |
585
569
  | `INTERNAL_ERROR` | `500` | uncaught handler exception |
@@ -590,10 +574,7 @@ may also fire in earlier loops (e.g. `HANDLER_NOT_REGISTERED`
590
574
  fires at boot — `phase: "boot"` — and that's where it should be
591
575
  caught; the runtime occurrence is defense-in-depth).
592
576
 
593
- Additional runtime codes activate as future grammar surfaces (e.g.
594
- `QUOTA_EXCEEDED → 429` arrives with `requires.quota`).
595
-
596
- ## RBAC — what v0.1 ships, what's DRAFT
577
+ ## RBAC
597
578
 
598
579
  v0.1 auth gates use `requires.auth.all` with `ctx.user`,
599
580
  `ctx.staff: [<roles>]`, `ctx.auth`, and `ctx.auth.scope` predicates on
@@ -601,16 +582,6 @@ Procedures and Views. This covers staff-only, logged-in-only,
601
582
  credential-protected, and delegated-scope targets. One Procedure-backed guard
602
583
  handles mutable consumer business state without widening the static grammar.
603
584
 
604
- **Not yet shipped** (DRAFT):
605
- - Row-level read visibility (private posts, friend-only audiences)
606
- - Field-level write policies (this user can update body but not
607
- parent_id)
608
- - Cross-Schema policy inheritance (gatedBy)
609
- - Quotas, edit-windows, rate limits
610
-
611
- These all live as `Schema.spec.policies.*` and `Procedure.spec.requires.*`
612
- sub-specs in the DRAFT spec. See "Future grammar" appendix.
613
-
614
585
  ## How to think when extending this CMS
615
586
 
616
587
  1. **What entities does the feature need?** → `Schema` for each.
@@ -619,13 +590,11 @@ sub-specs in the DRAFT spec. See "Future grammar" appendix.
619
590
  external read endpoints).
620
591
  3. **What operations?** → `Procedure` for each. One Procedure = one
621
592
  typed function call. Compose in handler code, not in YAML.
622
- 4. **What invokes them?** → `Trigger` per source. Multiple Triggers
623
- can target the same Procedure (HTTP + MCP + cron, all on one
624
- handler).
593
+ 4. **What invokes them?** → `Trigger` per declared HTTP, MCP, or lifecycle
594
+ source. Site-owned events can call the same Procedure binding directly.
625
595
  5. **Who's allowed?** → `Procedure/View.spec.requires.auth` for static
626
596
  identity/scope; optional `requires.guard.procedure` for one live,
627
- consumer-owned business check. Row-level and field-level rules remain
628
- future grammar.
597
+ consumer-owned business check.
629
598
 
630
599
  If you find yourself wanting a 5th kind, **stop**. Sketch the same
631
600
  thing as a composition of the four; almost always it works.
@@ -714,16 +683,15 @@ grammar, leftmost-prefix rules, SQL helper, and query-plan examples.
714
683
  ### Practical scale envelope on D1
715
684
 
716
685
  - **Blog-scale (< 10k entries / collection)**: today's design is
717
- comfortable. Public render hits KV cache, not D1.
686
+ comfortable. Anonymous public responses can hit version-local Workers
687
+ Cache before the Worker; origin misses use indexed D1 reads.
718
688
  - **Mid-scale (10k – 100k entries)**: declare measured list/filter
719
- access paths with ordered `indexes`. Cross-collection JSON-path joins
720
- may eventually gain `x-mantle-ref` auto-lift; that remains DRAFT.
689
+ access paths with ordered `indexes`.
721
690
  - **Hard D1 limits**: 1 MB max row size; 5,000 rows per query result;
722
691
  single-writer per database (concurrent writes serialize).
723
- - **Cross-region read**: D1 is region-pinned; first hit from a
724
- far region is ~100–200 ms cold replica. Public reads should hit
725
- the SDK's KV render cache, not D1, so this rarely matters at the
726
- CMS layer.
692
+ - **Cross-region read**: D1 is region-pinned; first origin hit from a
693
+ far region may pay replica latency. Eligible anonymous responses are
694
+ then served by version-local Workers Cache.
727
695
 
728
696
  ### Scale-up path: D1 → Postgres via Cloudflare Hyperdrive
729
697
 
@@ -748,7 +716,6 @@ When this path is taken (post-v0.1; not implemented yet), the
748
716
  | `json_each` → array operators (`@>`, `&&`) | none — predicates stay declarative |
749
717
  | SDK-stamped `now` → `DEFAULT now()` (optional) | none |
750
718
  | SDK-side policy rewriting → native RLS (optional) | none |
751
- | `Trigger.target.project` single-writer DO → real same-transaction trigger | atomicity guarantee strengthens; YAML grammar unchanged (the `atomicity:` declaration just stops needing the eventual-consistency caveat) |
752
719
 
753
720
  Migration shape: `entries` table dumped from D1, restored to PG. Stay
754
721
  single-table-with-discriminator (drop-in) or split into
@@ -756,68 +723,12 @@ table-per-collection (more PG-idiomatic, longer migration). Both shapes
756
723
  remain valid `cms.mantle.aotter.net/v1` deployments.
757
724
 
758
725
  **v0.1 commitment**: D1 only via the Cloudflare adapter. Hyperdrive +
759
- PG path is documented as the upgrade route but not implemented. SDKs
760
- and starters target D1 exclusively. The Netlify adapter package
761
- (`@aotter/mantle-netlify`) is a README stub for v0.2; its
762
- existence is an engineering forcing function ensuring the runtime
763
- package stays portable across adapters.
764
-
765
- ## Roadmap — what's not in v0.1.0
766
-
767
- > See [ADR-0001 §"Future grammar discipline"](adr/0001-four-atom-manifest-model.md#future-grammar-discipline-was-poc-adr-0005)
768
- > for the v0.1 minimum-vs-roadmap discipline, the promotion process,
769
- > and the YAGNI argument that gates speculative shipping.
726
+ PG is an upgrade route, not an implemented adapter. SDKs and starters target
727
+ D1 exclusively.
770
728
 
771
- The atoms are locked at 4. Their **inner grammar** is intentionally
772
- narrow at v0.1.0 and grows in two tiers:
729
+ ## Detailed shipped grammar
773
730
 
774
- 1. **v0.1.0 shipped** — grammar parses and runtime behavior is wired
775
- in the current rebuild.
776
- 2. **v0.1.x committed** — on the patch-release roadmap. Spec is
777
- documented; implementation lands within the v0.1 series. The unsupported
778
- runtime path fails closed with a code naming the feature.
779
- 3. **DRAFT (v0.2+)** — speculative, gated by concrete consumer
780
- demand. Parser/static validation rejects with `DRAFT_KEY_USED`. May or may
781
- not ship — depends on whether real use cases apply pressure.
782
-
783
- ### v0.1.0 shipped
784
-
785
- #### `Trigger.source.kind: lifecycle` — bind a Procedure to a Schema event
786
-
787
- Grammar lives in v0.1.0. Runtime is the
788
- `LifecycleHookingEntryRepository` decorator wrapping the entry-writer
789
- chokepoint so MCP / admin / builtin paths all fire the same hooks.
790
- Full shape lives further down.
791
-
792
- #### `Procedure.handler.kind: builtin` — SDK-supplied CRUD Procedure
793
-
794
- Grammar lives in v0.1.0. Runtime is the
795
- `InvokeBuiltinUseCase` that dispatches `op: create | update | upsert
796
- | delete | archive` against the entry-writer chokepoint with `x-mantle-bind`
797
- stamping and `input ∩ Schema.properties` projection. Full shape lives
798
- further down.
799
-
800
- #### `Trigger.source.kind: mcp` and shared authorization
801
-
802
- An MCP Trigger binds a declared Procedure to either the public or staff MCP
803
- surface. Procedures/Views share `ctx.auth`/scope predicates and optional guard
804
- orchestration across REST and MCP. Staff role is loaded live for each protected
805
- call; staff Views remain absent and un-callable on public MCP.
806
-
807
- ### Detailed shipped grammar and v0.1.x reservation
808
-
809
- > The `handler.kind: builtin` and `Trigger.source.kind: lifecycle`
810
- > sections below describe shipped v0.1.0 behavior. Only the
811
- > `Schema.spec.lifecycle: editorial` subsection remains v0.1.x-committed.
812
-
813
- #### `Schema.spec.lifecycle: editorial` runtime
814
-
815
- Grammar and boot already accept the key, but `request_publish` emits
816
- `LIFECYCLE_NOT_IN_V010` because the approval-queue runtime ships in v0.1.x.
817
- When that runtime lands, the same manifest can use the publish workflow without
818
- a grammar change.
819
-
820
- #### `handler.kind: builtin` — thin shortcut over the storage adapter for trivial CRUD-shaped Procedures
731
+ ### `handler.kind: builtin` — thin shortcut over the storage adapter for trivial CRUD-shaped Procedures
821
732
 
822
733
  Use when the body is "insert a row" / "update a row" / "delete a
823
734
  row"; reach for `ref` when there is real business logic. Shape:
@@ -834,11 +745,11 @@ spec:
834
745
 
835
746
  | op | Behavior |
836
747
  |---|---|
837
- | `create` | INSERT a new row. Project `input ∩ Schema.spec.schema.properties`; stamp `x-mantle-bind` fields; generated id; status is `draft`, or immediately `published` for `lifecycle: none`. |
748
+ | `create` | INSERT a new row. Project `input ∩ Schema.spec.schema.properties`; stamp `x-mantle-bind` fields; generated id; status is `draft`, or immediately `published` for `lifecycle: operational`. |
838
749
  | `update` | UPDATE in place. `input.id` + `input.expectedVersion` (OCC) required. Bumps version. |
839
750
  | `upsert` | If `input.id` resolves, behaves as `update`; else as `create`. |
840
751
  | `delete` | Hard DELETE by id. |
841
- | `archive` | Soft-archive (status='archived'). The manifest validator permits this builtin only for `editorial` Schemas; the archive transition itself is runtime-wired, while editorial approval/request-publish remains deferred. |
752
+ | `archive` | Soft-archive a publishing entry (`status='archived'`). |
842
753
 
843
754
  The Procedure's `input` is the contract with the *caller*. It MAY
844
755
  declare fields the Schema does not (e.g. a Turnstile token). The
@@ -848,11 +759,10 @@ the side-channel fields pass validation. To act on those fields
848
759
  (read the token, call the vendor), declare a `before_create`
849
760
  lifecycle Trigger — see below.
850
761
 
851
- `request_publish` and `publish` are intentionally not in the
852
- builtin vocabulary. They are editorial-workflow operations, not CRUD
853
- primitives.
762
+ `request_publish` and `publish` are intentionally not in the builtin
763
+ vocabulary. They are lifecycle operations, not CRUD primitives.
854
764
 
855
- #### `Trigger.source.kind: lifecycle` — bind a Procedure to a Schema event
765
+ ### `Trigger.source.kind: lifecycle` — bind a Procedure to a Schema event
856
766
 
857
767
  Shape:
858
768
 
@@ -874,12 +784,15 @@ spec:
874
784
  |---|---|
875
785
  | `before_create` | Before INSERT. Throw cancels. |
876
786
  | `after_create` | After INSERT. Default best-effort. |
877
- | `before_update` | Before UPDATE. Throw cancels. |
878
- | `after_update` | After UPDATE. Default best-effort. |
787
+ | `before_update` | Before UPDATE or a status transition whose target is not `published` (including unpublish and archive). Throw cancels. |
788
+ | `after_update` | After UPDATE or a status transition whose target is not `published` (including unpublish and archive). Default best-effort. |
879
789
  | `before_delete` | Before DELETE. Throw cancels. |
880
790
  | `after_delete` | After DELETE. Default best-effort. |
881
- | `before_publish` | Before any supported status transition to `published` (the shipped workflow is `simple`). |
882
- | `after_publish` | After any supported status transition to `published` (the shipped workflow is `simple`). |
791
+ | `before_publish` | Before any supported status transition to `published` (the shipped workflow is `publishing`). |
792
+ | `after_publish` | After any supported status transition to `published` (the shipped workflow is `publishing`). |
793
+
794
+ v0.1 has no separate unpublish or archive hooks. Do not treat
795
+ `before_update` / `after_update` as edit-only hooks.
883
796
 
884
797
  **Atomicity defaults by phase**:
885
798
  - `before_*`: `errorPolicy: abort`. Handler throw cancels the
@@ -910,9 +823,8 @@ post-mutation row for every `after_*`.
910
823
 
911
824
  **Hook ordering**: when multiple lifecycle Triggers bind the same
912
825
  `(schema, hook)`, the runtime fires them **alphabetically by
913
- `Trigger.metadata.name`**. A `priority: number` key is reserved for
914
- v0.2; today, choose names that sort correctly (`010-bot-check`,
915
- `020-rate-limit`).
826
+ `Trigger.metadata.name`**. Choose names that sort correctly
827
+ (`010-bot-check`, `020-rate-limit`).
916
828
 
917
829
  For deferred delivery, that ordered Trigger-name list is captured in
918
830
  one strict versioned event. Every captured Trigger runs before a
@@ -923,103 +835,7 @@ Cloudflare wiring, the 128 KB platform limit, retry/DLQ configuration,
923
835
  idempotency, and legacy-envelope draining are specified in
924
836
  [Deferred lifecycle hooks on Cloudflare Queues](deferred-lifecycle-queues.md).
925
837
 
926
- `before_publish` and `after_publish` already wrap the shipped simple publish
927
- transition. When editorial approval lands, the same hooks wrap its final
928
- transition to `published`; no second hook grammar is planned.
929
-
930
- ### DRAFT (v0.2+, speculative)
931
-
932
- Each item below lands when the first concrete real-world use case
933
- forces it, not on speculation. Today, do not implement; parser/static
934
- validation rejects it with `DRAFT_KEY_USED`.
935
-
936
- #### Schema future
937
- - **`x-mantle-ref` auto-lift to virtual column** — when a property
938
- carrying `x-mantle-ref: <other-schema>` is referenced in any registered
939
- View's `filter:` or future `join:`, the SDK auto-creates the virtual
940
- column + non-unique index without requiring an explicit `indexes`
941
- declaration. Solves cross-collection JSON-path join
942
- performance without making authors think about it. Pure SDK
943
- behavior; no new YAML grammar.
944
- - **`spec.policies.visible`** — row-level read predicate auto-AND'd
945
- into Views from this Schema. Lands with first private/audience
946
- feature.
947
- - **`spec.policies.readable.fields`** — field-level wire-mask. Lands
948
- when staff-only fields surface (e.g. `threadLength` visible to
949
- editors only).
950
- - **`spec.policies.writable.{fields, create}`** — field-level write
951
- gate auto-applied to all writers.
952
- - **`spec.policies.owner`** — names the ownership column for `owns:`
953
- predicate. Currently implicit (`authorId`).
954
- - **Computed columns via projection Trigger** — see `Trigger.target`.
955
-
956
- #### View future
957
- - **`recursive: { parent, rootWhen, pathBy, depthAs?, pathAs?, maxDepth }`**
958
- — declarative recursive CTE. Lands with first threaded-reads feature
959
- (comments, taxonomies).
960
- - **`params: { <name>: <jsonschema> }`** — caller-bound view parameters.
961
- - **`gatedBy: [{ schema, policy, on }]`** — cross-Schema visibility
962
- inheritance.
963
- - **`join: [{ as, from, on, project?, aggregate?: count|exists, bind? }]`**
964
- — joined relations with optional reducer (per-row count or boolean).
965
- - **`policies: { skip: [<policy-name> | field, ...] }`** — explicit
966
- bypass for admin/audit Views.
967
- - Filter AST extension: `contains` (array containment), `not`, `in`, `like`.
968
-
969
- #### Procedure future
970
- - **`requires.auth.any`** with disjunction; the shipped `all` predicate
971
- vocabulary extends to `owns: { schema, idFrom }`, `contains: {
972
- schema, idFrom, field, valueFrom }`.
973
- - **`requires.window.{withinMinutes, column?}`** — temporal
974
- precondition, sibling-modifier of `owns:`. DRY rule: window MUST
975
- sit beside exactly one `(schema, id)`-binding predicate in the same
976
- any/all group.
977
- - **`requires.quota.{key, limit, per, overrideFrom?}`** — declarative
978
- rate cap. Override Schema lookup keyed by `ctx.user`. Counter
979
- substrate: Durable Object.
980
- - **`errors.{onHandlerThrow, onRecursionDepth, maxDepth}`** + **`retry.{
981
- limit, backoff, retryOn, idempotencyKey?}`** — failure-policy
982
- declared. Retry + `op: create` requires `idempotencyKey:` (parse
983
- error otherwise).
984
-
985
- #### Trigger future
986
- - **`source.kind: cron`** with `expr:` — scheduled invocation.
987
- - **`source.kind: queue`** — async fan-out / message-driven invocation.
988
- - **`source.kind: lifecycle.foo`** — DRAFT extensions to the shipped
989
- lifecycle hooks (e.g. `before_archive`, `after_request_publish`).
990
- The 8 hooks listed in the detailed shipped section are the floor,
991
- not the ceiling.
992
-
993
- (Full lifecycle Trigger spec for the 8 shipped hooks lives
994
- in the detailed section above. The remaining DRAFT items
995
- below are the speculative v0.2+ shapes that haven't yet been promoted
996
- to a committed roadmap.)
997
-
998
- - **`target.project: { schema, where, set: { <col>: { aggregate, from,
999
- where } } }`** — declarative aggregate-projection across Schemas.
1000
- Replaces hand-written counter handlers. Same-transaction on PG;
1001
- bounded-eventual on D1 via single-writer DO.
1002
- - **`atomicity: same-transaction | best-effort`** — explicit guarantee
1003
- declaration when projection Triggers ship.
1004
-
1005
- #### Cross-cutting future
1006
- - **Closed `ctx.*` predicate identity**: v0.1 `{ user, staff, auth,
1007
- auth.scope }`
1008
- extends to `{ ..., system }` when SDK-internal Trigger executor
1009
- paths land. Multi-tenant deployments would add `{ tenant }` via
1010
- grammar-revise round if/when that product shape is pursued. New
1011
- entries require explicit grammar-revise (closed enum is
1012
- load-bearing infrastructure).
1013
- - **Placeholder namespace `$.*`**: `$.input.<f>`, `$.row.<f>`, `$.op`,
1014
- `$.params.<f>`, `$.source` — write-time data-flow bindings inside
1015
- policy ASTs and handler signatures. Distinct from `:ctx.*` identity
1016
- bindings; one-site evaluation rule.
1017
- - **`Schema.spec.staffBypass: [<role>]`** — DRY shortcut once
1018
- `ctx.staff: [editor, owner]` repetition crosses 4+ schemas.
1019
-
1020
- Each extension goes through a 3-agent review (yml-editor proposes /
1021
- code-impler tests buildability / fresh-dev verifies clarity) before
1022
- locking. v0.1 is the floor, not the ceiling.
838
+ `before_publish` and `after_publish` wrap the shipped publishing transition.
1023
839
 
1024
840
  ## Lineage — the academic foundations
1025
841
 
@@ -1032,6 +848,6 @@ locking. v0.1 is the floor, not the ceiling.
1032
848
 
1033
849
  The composite design — declarative resources + ECA-fired procedures +
1034
850
  policy-gated execution — is sometimes labeled **Active Database +
1035
- Policy-Based Management**. Postgres + PostgREST + pg_cron is the
851
+ Policy-Based Management**. Postgres + PostgREST is the
1036
852
  canonical full-stack reference; we abstract that pattern up to the
1037
853
  application layer with K8s-style YAML manifests.
package/docs/labels.md CHANGED
@@ -33,7 +33,7 @@ For package README or package-local docs changes, prefer the package area label
33
33
  | `area:skills` | `skills/*` agent briefs and install/extend/provision workflows. |
34
34
  | `area:admin-ui` | `packages/mantle-admin-ui` React admin SPA. |
35
35
  | `area:docs` | Repo-wide human docs, governance docs, ADR text, release docs, root README content, and cross-cutting documentation work. |
36
- | `area:adapter` | Adapter boundary work spanning Cloudflare, Netlify stub, or future adapters. |
36
+ | `area:adapter` | Adapter boundary work spanning Cloudflare or future adapters. |
37
37
 
38
38
  ## Release and review gates
39
39
 
@@ -41,7 +41,8 @@ For package README or package-local docs changes, prefer the package area label
41
41
  |---|---|---|---|
42
42
  | `release-gate` | Blocks a public release or release-quality claim. | Must be resolved or explicitly deferred before release. | The gate is closed or deferred by maintainer decision. |
43
43
  | `v0.1.0` | Required for the v0.1.0 release gate. | Track in the v0.1.0 release pass. | The item lands or is moved out of v0.1.0. |
44
- | `breaking-change` | Semver-relevant breaking change. | Changelog and release notes must call it out. | The change is redesigned to be non-breaking. |
44
+ | `breaking-change` | Semver-relevant breaking change. | Generated release notes must call it out. | The change is redesigned to be non-breaking. |
45
+ | `skip-release-notes` | Release bookkeeping with no user-facing change. | Excluded from generated GitHub Release notes. | The PR contains a user-facing change. |
45
46
  | `needs-adr` | Architecture, trust boundary, package boundary, or long-lived decision needs an ADR or ADR-lite proposal. | Do not merge implementation until the decision is captured. | ADR/proposal lands or maintainer confirms an existing ADR covers it. |
46
47
  | `needs-grammar-revise` | Manifest grammar or closed-enum change. | Requires grammar-revise round before code/types/starters change. | Grammar decision lands or the change no longer affects grammar. |
47
48
  | `needs-discussion` | Not converged enough for implementation. | Do not start coding from this issue. | Closing criteria are met and scope is concrete. |
@@ -60,6 +61,7 @@ gh label create "area:admin-ui" --description "React admin UI" --color "1d76db"
60
61
  gh label create "area:docs" --description "Documentation and governance" --color "1d76db"
61
62
  gh label create "area:adapter" --description "Adapter boundary and future adapter work" --color "1d76db"
62
63
  gh label create "breaking-change" --description "Semver-relevant breaking change" --color "b60205"
64
+ gh label create "skip-release-notes" --description "Release bookkeeping only; omit from generated GitHub notes" --color "ededed"
63
65
  gh label create "needs-adr" --description "Requires an ADR or ADR-lite decision before merge" --color "d93f0b"
64
66
  gh label create "needs-grammar-revise" --description "Requires manifest grammar review before implementation" --color "d93f0b"
65
67
  gh label create "needs-discussion" --description "Not converged enough for implementation" --color "fbca04"