memstead-schema 0.8.0

Schema types for Memstead — entity definitions, vocabulary, and validation rules. Internal library surface consumed by the memstead binaries — pre-1.0, experimental, no API stability promise.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "TypeDefinition",
  "type": "object",
  "properties": {
    "boundaries": {
      "type": "array",
      "default": [],
      "items": {
        "type": "string"
      }
    },
    "constraints": {
      "description": "Declared keep-health constraints (the constraint vocabulary —\nsee [`ConstraintDef`]). Empty default: a schema declaring no\nconstraints behaves byte-identically to before the vocabulary\nexisted.",
      "type": "array",
      "items": {
        "$ref": "#/$defs/ConstraintDef"
      }
    },
    "description": {
      "type": "string"
    },
    "due": {
      "description": "The type's declared due axis (see [`DueAxis`]) — absent for\ntypes without deadline semantics; a schema without any `due:`\ndeclaration behaves byte-identically to before the axis\nexisted.",
      "anyOf": [
        {
          "$ref": "#/$defs/DueAxis"
        },
        {
          "type": "null"
        }
      ]
    },
    "edge_weight_overrides": {
      "type": "object",
      "additionalProperties": {
        "type": "number",
        "format": "float"
      },
      "default": {}
    },
    "exemplar": {
      "description": "One canonical, ENGINE-VALIDATED exemplar entity for this type\n(agent-trust plan 09) — the few-shot material an authoring\nagent actually learns from. Validated against this very type\nthrough the real create path (`dry_run`) at schema\ninstall/seal time: a package whose exemplar does not conform\nrefuses with a typed error naming the type and the defect —\nthere is no warn-and-carry mode, so an exemplar can never\ndrift into teaching the wrong shape. Served at\n`verbosity: full` only (the lite skeleton stays unchanged).\nOptional per type; the built-in reference schemas are complete.",
      "anyOf": [
        {
          "$ref": "#/$defs/Exemplar"
        },
        {
          "type": "null"
        }
      ]
    },
    "health_required_fields": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "hierarchy_relationship": {
      "type": "string"
    },
    "leaf": {
      "description": "Terminal-by-construction marker: entities of this type are\nleaves — they carry no edges BY DESIGN, so health's orphan\naxis exempts their edge-less entities and reports them as a\nseparate leaf population instead (visible, never vanished).\nLeaf means \"no edges required\", not \"edges forbidden\": a\nleaf-typed entity WITH edges stays legal, and every other\nhealth axis, search, and traversal treats leaf entities\nexactly like any other. Declarative per-type flag (the sixth\ndeclarative form the agent-toolbox constraint vocabulary\nanticipated), served at both schema verbosity levels.",
      "type": "boolean"
    },
    "metadata_fields": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/MetadataFieldDef"
      }
    },
    "name": {
      "type": "string"
    },
    "no_self_loop_relationships": {
      "description": "Rel-types on which `memstead_relate` refuses a SELF-LOOP\n(from == to) when this type is the source. That refusal is this\nfield's ONLY effect — it propagates nothing, implies no\nevidence obligation (real impact propagation is the\n`status_propagation` constraint). Renamed from the misleading\n`propagating_relationships` (agent-trust plan 06): the old key\nrefuses at authoring/install load with a typed error naming\nthis one; sealed content (built-ins, installed refs) loads\nwith the old key translated.",
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "required_outgoing": {
      "description": "Outgoing-edge invariants the schema asserts for this type.\nEach entry names a list of relationship names plus a cardinality\nconstraint. The engine evaluates these on every `memstead_create` /\n`memstead_update` (post-application of inline `relations:` / patches)\nand surfaces unsatisfied blocks as a single\n`MISSING_REQUIRED_OUTGOING` warning per entity. Tier-2 (warn,\nnever block). Empty default — types without `required_outgoing`\nkeep current behaviour.",
      "type": "array",
      "items": {
        "$ref": "#/$defs/RequiredOutgoing"
      }
    },
    "sections": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/SectionDef"
      }
    },
    "staleness_threshold_days": {
      "type": "integer",
      "format": "uint32",
      "minimum": 0
    },
    "system_message": {
      "type": [
        "string",
        "null"
      ],
      "default": null
    },
    "text_fields": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "title_weight": {
      "type": "number",
      "format": "float"
    },
    "updatable_fields": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "when_to_use": {
      "type": "string"
    },
    "write_rules": {
      "type": "array",
      "items": {
        "type": "string"
      }
    }
  },
  "additionalProperties": false,
  "required": [
    "name",
    "description",
    "when_to_use",
    "sections",
    "metadata_fields",
    "title_weight",
    "text_fields",
    "hierarchy_relationship",
    "updatable_fields",
    "health_required_fields",
    "staleness_threshold_days",
    "write_rules"
  ],
  "$defs": {
    "ConstraintDef": {
      "description": "One declared keep-health constraint on a type — the constraint\nvocabulary (agent-toolbox plan 07). Declarations travel sealed with\nthe schema package and are rendered on the `memstead_schema`\nresponse at BOTH verbosity levels (a hidden legality condition is a\ndefect class of its own). The `kind` tag is closed: an unknown kind\nfails deserialization, so no declaration can load and be silently\nignored. Forms land vertically — a form is only declarable once the\nengine evaluates it.",
      "oneOf": [
        {
          "description": "Form 1 — conditional requirement: `field` (a metadata field or\nsection key of this type) is required whenever `when_field`\nholds `when_value` (\"`status: checked` requires `checked_by`\").",
          "type": "object",
          "properties": {
            "field": {
              "description": "The field or section that becomes required.",
              "type": "string"
            },
            "kind": {
              "type": "string",
              "const": "requires_when"
            },
            "severity": {
              "$ref": "#/$defs/ConstraintSeverity",
              "default": "warn"
            },
            "when_field": {
              "description": "The metadata field whose value triggers the requirement.",
              "type": "string"
            },
            "when_value": {
              "description": "The triggering value (validated against `when_field`'s\nenum, when it declares one).",
              "type": "string"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "field",
            "when_field",
            "when_value"
          ]
        },
        {
          "description": "Form 2 — uniqueness: the tuple of metadata-field values named\nin `fields` is unique among entities of this type within one\nmem. Entities missing any of the fields carry no tuple and are\nnot compared. Defaults to `block` — the whole point of the\ndeclaration is preventing the duplicate at write time.",
          "type": "object",
          "properties": {
            "fields": {
              "description": "The metadata fields forming the unique tuple (each must be\na declared metadata field of this type).",
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "kind": {
              "type": "string",
              "const": "unique"
            },
            "severity": {
              "$ref": "#/$defs/ConstraintSeverity",
              "default": "block"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "fields"
          ]
        },
        {
          "description": "Form 3 — enum-from-neighbour: the legal values of `field` are\nthe bullet-list entries (`- value` lines) of the `section`\nsection on the entity reached from this one via a `rel_type`\nedge. A set value with no backing entry in any reached\nneighbour's section — including the no-neighbour and\nmissing-section cases, where nothing can back it — is a\nviolation.",
          "type": "object",
          "properties": {
            "field": {
              "description": "The metadata field whose values the neighbour enumerates.",
              "type": "string"
            },
            "kind": {
              "type": "string",
              "const": "enum_from_neighbour"
            },
            "rel_type": {
              "description": "The outgoing rel-type that reaches the enumerating entity.",
              "type": "string"
            },
            "section": {
              "description": "The section key on the reached entity whose bullet entries\nare the legal values.",
              "type": "string"
            },
            "severity": {
              "$ref": "#/$defs/ConstraintSeverity",
              "default": "warn"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "field",
            "rel_type",
            "section"
          ]
        },
        {
          "description": "Form 5 — status propagation: when `field` on an entity of this\ntype holds `value` (the terminal value), every entity reaching\nit — transitively — via `rel_type` edges in `direction` is\ntainted; tainted entities surface as health findings naming\ntheir tainting ancestor. Always warn-tier: the taint arises\nfrom the ancestor's *later* change, so it can never refuse the\ndescendant's historical write (the loader refuses a `block`\ndeclaration on this form rather than accepting a promise the\nengine will not keep).",
          "type": "object",
          "properties": {
            "direction": {
              "description": "Which direction reaches the dependents: `incoming` taints\nthe entities whose `rel_type` edges point at the terminal\nentity (and their dependents, transitively); `outgoing`\nthe entities the terminal entity points at.",
              "$ref": "#/$defs/PropagationDirection"
            },
            "field": {
              "description": "The status metadata field on this (the tainting) type.",
              "type": "string"
            },
            "kind": {
              "type": "string",
              "const": "status_propagation"
            },
            "rel_type": {
              "description": "The rel-type the taint travels along.",
              "type": "string"
            },
            "severity": {
              "$ref": "#/$defs/ConstraintSeverity",
              "default": "warn"
            },
            "value": {
              "description": "The terminal value that starts the taint (validated\nagainst `field`'s enum, when it declares one).",
              "type": "string"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "field",
            "value",
            "rel_type",
            "direction"
          ]
        }
      ]
    },
    "ConstraintSeverity": {
      "description": "Uniform severity for the constraint vocabulary — one model across\nevery constraint form, never five ad-hoc ones. `warn` produces a\nhealth finding only; `block` additionally refuses at write time\n(and still surfaces pre-existing violations in health). Severity\napplies to every write surface uniformly — operator-mode bypasses\nallowlists, never validation.",
      "oneOf": [
        {
          "description": "Health finding only (and, where a write-time warning exists,\nthat warning). The default for every form except uniqueness.",
          "type": "string",
          "const": "warn"
        },
        {
          "description": "Write-time refusal plus health finding for pre-existing\nviolations.",
          "type": "string",
          "const": "block"
        }
      ]
    },
    "DueAxis": {
      "description": "A type's declared **due axis** (first-author-path plan 08): which\nof its fields carry deadline semantics, so the engine's due-brief\n(`memstead due`) can render \"what is due next\" without knowing any\ndomain vocabulary. Validated at schema load: `date_field` must be\na date-typed metadata field of the type, `status_field` an\nenum-typed one, every `open_values` entry a member of that enum,\nand `lead_section` (optional — rendered as \"what must happen\nfirst\") a declared section key. The axis is rendering-only: it\nnever enforces anything (constraints own enforcement) and the\nengine never advances a date (the agent loop is the runtime).",
      "type": "object",
      "properties": {
        "date_field": {
          "description": "Date-typed metadata field holding the deadline.",
          "type": "string"
        },
        "lead_section": {
          "description": "Optional section key whose content renders with each entry as\n\"what must happen first\".",
          "type": [
            "string",
            "null"
          ]
        },
        "open_values": {
          "description": "The `status_field` values under which the entity counts as\nstill open (due-relevant). Every entry must be declared in the\nfield's `enum_values`.",
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "status_field": {
          "description": "Enum-typed metadata field holding the lifecycle status.",
          "type": "string"
        }
      },
      "additionalProperties": false,
      "required": [
        "date_field",
        "status_field",
        "open_values"
      ]
    },
    "Exemplar": {
      "description": "One canonical exemplar entity for a type — a complete entity in the\nmem markdown shape: title, metadata overrides, section bodies, and\nrelationship entries with placeholder targets. Engine-validated at\nschema install/seal through the real create path, so it can never\nteach a shape the validator would refuse.",
      "type": "object",
      "properties": {
        "metadata": {
          "description": "Metadata overrides, keyed by declared field key — validated\nlike a real create's metadata (enums included). Engine-stamped\nfields (`created_date`, …) are omitted; the engine fills them.",
          "type": "object",
          "additionalProperties": {
            "type": "string"
          }
        },
        "relations": {
          "description": "Relationship entries with PLACEHOLDER targets: each `to` is a\nbare slug (no `mem--` prefix — an exemplar lives outside any\nmem); validation checks rel-type legality and shape, never\ntarget existence.",
          "type": "array",
          "items": {
            "$ref": "#/$defs/ExemplarRelation"
          }
        },
        "sections": {
          "description": "Section bodies keyed by section key. Required sections must all\nbe present — the validator enforces it like any create.",
          "type": "object",
          "additionalProperties": {
            "type": "string"
          }
        },
        "title": {
          "description": "The exemplar entity's title (drives the id slug exactly as a\nreal create would).",
          "type": "string"
        }
      },
      "additionalProperties": false,
      "required": [
        "title"
      ]
    },
    "ExemplarRelation": {
      "description": "One relationship entry on an [`Exemplar`].",
      "type": "object",
      "properties": {
        "description": {
          "description": "Optional per-edge description — validated against the\nrel-type's `per_edge_description` posture.",
          "type": [
            "string",
            "null"
          ]
        },
        "to": {
          "description": "Placeholder target: a bare slug, scoped to the exemplar's own\n(virtual) mem at validation time.",
          "type": "string"
        },
        "type": {
          "description": "Relationship type (UPPER_SNAKE_CASE; validated against the\nschema's declared vocabulary).",
          "type": "string"
        }
      },
      "additionalProperties": false,
      "required": [
        "to",
        "type"
      ]
    },
    "FieldType": {
      "type": "string",
      "enum": [
        "string",
        "number",
        "date",
        "boolean"
      ]
    },
    "Filterable": {
      "type": "string",
      "enum": [
        "none",
        "equality",
        "range"
      ]
    },
    "MetadataFieldDef": {
      "description": "A metadata (frontmatter) field.",
      "type": "object",
      "properties": {
        "auto_timestamp": {
          "type": "boolean",
          "default": false
        },
        "default_value": {
          "type": [
            "string",
            "null"
          ],
          "default": null
        },
        "description": {
          "type": "string"
        },
        "enum_values": {
          "type": [
            "array",
            "null"
          ],
          "default": null,
          "items": {
            "type": "string"
          }
        },
        "field_type": {
          "$ref": "#/$defs/FieldType"
        },
        "filterable": {
          "$ref": "#/$defs/Filterable",
          "default": "none"
        },
        "init_timestamp": {
          "type": "boolean",
          "default": false
        },
        "key": {
          "type": "string"
        },
        "required": {
          "description": "Whether an entity must carry this field — **absence means\noptional**, the same rule sections follow. `required: true`\nrefuses a create that leaves the field unset\n(`REQUIRED_FIELD_UNSET`); a required field with a\n`default_value` (or an `init_timestamp`) is auto-filled and\ntherefore never refused — required-with-default means \"always\npresent\", not \"caller must type it\". Replaces the retired\n`optional:` key (opposite polarity): sealed schemas carrying\n`optional` keep loading with inverted-but-equivalent\nsemantics; authoring refuses it naming this key.",
          "type": [
            "boolean",
            "null"
          ]
        },
        "serialization": {
          "$ref": "#/$defs/Serialization",
          "default": "default"
        }
      },
      "additionalProperties": false,
      "required": [
        "key",
        "description",
        "field_type"
      ]
    },
    "PropagationDirection": {
      "description": "Traversal direction for [`ConstraintDef::StatusPropagation`].",
      "type": "string",
      "enum": [
        "incoming",
        "outgoing"
      ]
    },
    "RequiredCardinality": {
      "description": "Required-cardinality variants. `AtLeastOne` is the only variant\nshipped initially; `ExactlyOne` is the obvious next variant but is\nnot yet wired.",
      "type": "string",
      "enum": [
        "at_least_one"
      ]
    },
    "RequiredOutgoing": {
      "description": "One outgoing-edge requirement block on a type definition. Lists one\nor more relationship names and a cardinality constraint they must\njointly satisfy. The schema author groups multiple alternative\nrelationships into a single block when \"any of these\" satisfies the\nrule (e.g. `[CHOSEN, REJECTED]` together with `at_least_one` would\nrequire at least one outgoing edge across both names — but the\nplanning schema lists each as its own block instead, so each block\ngets its own warning entry).",
      "type": "object",
      "properties": {
        "cardinality": {
          "$ref": "#/$defs/RequiredCardinality"
        },
        "relationships": {
          "description": "Edge names the rule applies to. Loader validates each against\nthe schema's declared relationship vocabulary; unknown names\nraise `SchemaLoadError::UndeclaredRelationship`.",
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "severity": {
          "description": "Constraint severity (form 4 of the constraint vocabulary):\n`warn` (the historical default — health finding +\n`MISSING_REQUIRED_OUTGOING` write-time warning) or `block`\n(write-time refusal when a create/update would land, or a\nrelate-remove would leave, the entity below cardinality).",
          "$ref": "#/$defs/ConstraintSeverity",
          "default": "warn"
        }
      },
      "additionalProperties": false,
      "required": [
        "relationships",
        "cardinality"
      ]
    },
    "SectionDef": {
      "description": "A section within an entity (e.g. \"Claim\", \"Evidence\").",
      "type": "object",
      "properties": {
        "catch_all": {
          "type": "boolean",
          "default": false
        },
        "content": {
          "description": "Declared markdown shape (section-format vocabulary, plan 08):\na flat content expression over the mdast block vocabulary —\nsee [`crate::content_expr::ContentExpr`]. Absent = free-form,\nexactly the pre-declaration behavior. Validated and compiled\nat schema load ([`SectionDef::compiled_content`]).",
          "type": [
            "string",
            "null"
          ]
        },
        "description": {
          "type": [
            "string",
            "null"
          ],
          "default": null
        },
        "example": {
          "description": "One conforming snippet, echoed verbatim in every format\nrefusal — for an agent, a conforming example outperforms any\ngrammar string.",
          "type": [
            "string",
            "null"
          ]
        },
        "format_severity": {
          "description": "Severity of format violations (plan 07's uniform model).\nDefault `block`: a shape violation is deterministic and\none-round-trip repairable (the enum-value analogy) — `warn`\nstays available per section.",
          "$ref": "#/$defs/ConstraintSeverity"
        },
        "heading": {
          "type": "string"
        },
        "item_pattern": {
          "description": "Regex applied to the repeating unit of the declared `content`\n(list items with lazy continuation joined; paragraph source\nlines). Implicitly anchored `^…$`; named capture groups name\nthe parts in refusal payloads. Legal only when `content`\ncontains exactly one of `list` / `paragraph`.",
          "type": [
            "string",
            "null"
          ]
        },
        "key": {
          "type": "string"
        },
        "required": {
          "description": "Whether an entity must carry this section — **absence means\noptional**, the same rule metadata fields follow. `required:\ntrue` refuses a create without the section\n(`MISSING_REQUIRED_SECTION`).",
          "type": "boolean",
          "default": false
        },
        "search_weight": {
          "type": "number",
          "format": "float"
        },
        "table": {
          "description": "Table contract — only legal when `content` contains `table`.",
          "anyOf": [
            {
              "$ref": "#/$defs/TableFormat"
            },
            {
              "type": "null"
            }
          ]
        },
        "write_rules": {
          "type": "array",
          "default": [],
          "items": {
            "type": "string"
          }
        }
      },
      "additionalProperties": false,
      "required": [
        "key",
        "heading",
        "search_weight"
      ]
    },
    "Serialization": {
      "type": "string",
      "enum": [
        "default",
        "csv_array",
        "omit_when_falsy"
      ]
    },
    "TableFormat": {
      "description": "The table contract of a format-declared section: `columns` pins\nheader names and order; `column_patterns` maps column name → regex\nper cell (implicitly anchored). Column-count enforcement is ours by\ndecision — GFM silently pads/truncates short or long rows, so a\nrow with the wrong cell count is *our* refusal, not the parser's.",
      "type": "object",
      "properties": {
        "column_patterns": {
          "type": "object",
          "additionalProperties": {
            "type": "string"
          }
        },
        "columns": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "additionalProperties": false,
      "required": [
        "columns"
      ]
    }
  }
}