Contracts
A contract is a versioned data file that independently written plugins share; its provider implements it and its consumers rely on it.
A contract is the interface independently written plugins share. It is a data file, contracts/<namespace>/<Name>/v<major>.toml, independent of any plugin. Its provider implements it, its consumers rely on it, and either side can be swapped without the other noticing.
The smallest contract
[contract]
name = "c:test/Tick"
version = "1.0.0"
[[events]]
name = "Tick"Tables
Every table except [contract] is optional. A key or table not listed is refused, as is a missing required key, a value of the wrong type or a value outside a closed set.
| Table | What it declares |
|---|---|
[contract] | name, version, description, and the residence reasons the provider may send. Required. |
[[events]] | Events only the active provider emits, with their payload fields. |
[[requests]] | Requests other plugins send to the provider, the phase that handles them and the refusal reasons. |
[[views]] | Values the provider exposes for others to read. |
[[link_types]] | Links between two people, with their roles and attributes. |
[on_death], [on_exit] | The views and link types the provider clears when a person dies or emigrates. |
[entry] | The state an entrant carries, with a default for each field. |
[[points]] | Modulation points, where policies attach: a hazard per year or a row of transition probabilities. |
[[competing_risks]] | Sets of at least two events resolved together, jointly or in phase order. |
[[decisions]] | Decision types, the keys of the provider's random draws, shared by every variant. |
[[indicators]] | Indicators, each a declarative query over the journal with its unit. |
[[tables]] | Table roles the provider reads from the data manifest, with the normalized schema and versions accepted. |
[capabilities] | What every provider's manifest must declare: events it listens to, requests it accepts, points it exposes. |
[[invariants]] | Named conformance tests of the contract suite. |
[absent] | The defaults the kernel serves when an optional requirement has no active provider. |
Fields
Payloads, views, link attributes and entry fields are lists of fields:
| Key | Required | Value |
|---|---|---|
name | yes | snake_case, unique in its list |
type | yes | agent, date, bool, int64, float64, category (a closed set) or text |
values | for category | the allowed values |
unit | for int64, float64 and date | a unit of schemas/units.toml |
optional | no, default false | whether the field may be missing |
Versions
A contract version is MAJOR.MINOR.PATCH and the file is named by its major. An item may be marked deprecated = { since = "<version>", replacement = "<item>" }: a plugin that uses it gets warning W2007 and the run starts.
At start-up the kernel checks every plugin manifest against the loaded contracts: unknown items (E3004), items declared differently (E3005), missing capabilities (E3006) and ranges that span different majors (E3008).
Contracts in 0.1
official/Corev1, the kernel's own contract, embedded in the engine.test/Tickv1, the contract of the test plugin.
The full contract-file reference, with a complete commented example, is in the README of cohortix-contracts.