archctx-contracts 0.12.0 → 0.13.0

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.
@@ -30,6 +30,11 @@
30
30
  "coverage": "complete",
31
31
  "reasonCodes": []
32
32
  },
33
+ {
34
+ "check": "state-machines",
35
+ "coverage": "complete",
36
+ "reasonCodes": []
37
+ },
33
38
  {
34
39
  "check": "practices",
35
40
  "coverage": "complete",
@@ -38,7 +43,7 @@
38
43
  ],
39
44
  "items": [],
40
45
  "actionsRequired": [],
41
- "digest": "sha256:1d40d5a0b5f92e61241f310b1f0c26b342210533455707a93f524d306db88b4e"
46
+ "digest": "sha256:ceaaaf214aff4c0b05abe367cad2b58e52b25d2aeeb4809ebc0e101d34e66d09"
42
47
  },
43
48
  "hookLog": {
44
49
  "schemaVersion": "archcontext.hook-log/v1",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "schemaVersion": "archcontext.capabilities/v1",
3
- "package": { "name": "archctx", "version": "0.12.0" },
3
+ "package": { "name": "archctx", "version": "0.13.0" },
4
4
  "protocols": {
5
5
  "projectionRequest": "archcontext.projection-request/v1",
6
6
  "projectionResult": "archcontext.projection-result/v2",
@@ -0,0 +1,158 @@
1
+ {
2
+ "schemaVersion": "archcontext.state-machine/v1",
3
+ "id": "state-machine.checkout.order",
4
+ "capabilityId": "capability.checkout",
5
+ "name": "Order and payment",
6
+ "regions": [
7
+ {
8
+ "id": "order",
9
+ "label": "Order",
10
+ "initial": "open",
11
+ "states": [
12
+ {
13
+ "id": "open",
14
+ "label": "Open"
15
+ },
16
+ {
17
+ "id": "shipped",
18
+ "label": "Shipped",
19
+ "terminal": true
20
+ },
21
+ {
22
+ "id": "cancelled",
23
+ "label": "Cancelled",
24
+ "terminal": true
25
+ }
26
+ ]
27
+ },
28
+ {
29
+ "id": "payment",
30
+ "label": "Payment",
31
+ "initial": "unpaid",
32
+ "states": [
33
+ {
34
+ "id": "unpaid",
35
+ "label": "Unpaid"
36
+ },
37
+ {
38
+ "id": "captured",
39
+ "label": "Captured"
40
+ },
41
+ {
42
+ "id": "refunded",
43
+ "label": "Refunded"
44
+ }
45
+ ]
46
+ }
47
+ ],
48
+ "events": [
49
+ {
50
+ "id": "capture",
51
+ "label": "Capture the payment",
52
+ "source": {
53
+ "kind": "code",
54
+ "path": "src/payment.ts",
55
+ "symbol": "PaymentService.capture"
56
+ },
57
+ "steps": [
58
+ {
59
+ "when": {
60
+ "order": [
61
+ "open"
62
+ ],
63
+ "payment": [
64
+ "unpaid"
65
+ ]
66
+ },
67
+ "then": {
68
+ "payment": "captured"
69
+ }
70
+ }
71
+ ]
72
+ },
73
+ {
74
+ "id": "ship",
75
+ "label": "Ship the order",
76
+ "source": {
77
+ "kind": "code",
78
+ "path": "src/order.ts",
79
+ "symbol": "shipOrder"
80
+ },
81
+ "steps": [
82
+ {
83
+ "when": {
84
+ "order": [
85
+ "open"
86
+ ]
87
+ },
88
+ "then": {
89
+ "order": "shipped"
90
+ }
91
+ }
92
+ ]
93
+ },
94
+ {
95
+ "id": "cancel",
96
+ "label": "Cancel the order",
97
+ "source": {
98
+ "kind": "code",
99
+ "path": "src/order.ts",
100
+ "symbol": "cancelOrder"
101
+ },
102
+ "steps": [
103
+ {
104
+ "when": {
105
+ "order": [
106
+ "open"
107
+ ],
108
+ "payment": [
109
+ "unpaid"
110
+ ]
111
+ },
112
+ "then": {
113
+ "order": "cancelled"
114
+ }
115
+ },
116
+ {
117
+ "when": {
118
+ "order": [
119
+ "open"
120
+ ],
121
+ "payment": [
122
+ "captured"
123
+ ]
124
+ },
125
+ "then": {
126
+ "order": "cancelled",
127
+ "payment": "refunded"
128
+ }
129
+ }
130
+ ]
131
+ }
132
+ ],
133
+ "rules": [
134
+ {
135
+ "id": "paid-before-shipped",
136
+ "label": "An order never ships without a captured payment",
137
+ "never": {
138
+ "order": [
139
+ "shipped"
140
+ ],
141
+ "payment": [
142
+ "unpaid",
143
+ "refunded"
144
+ ]
145
+ }
146
+ },
147
+ {
148
+ "id": "closed-order-stays-closed",
149
+ "label": "A shipped or cancelled order never changes",
150
+ "final": {
151
+ "order": [
152
+ "shipped",
153
+ "cancelled"
154
+ ]
155
+ }
156
+ }
157
+ ]
158
+ }
@@ -30,6 +30,11 @@
30
30
  "coverage": "complete",
31
31
  "reasonCodes": []
32
32
  },
33
+ {
34
+ "check": "state-machines",
35
+ "coverage": "complete",
36
+ "reasonCodes": []
37
+ },
33
38
  {
34
39
  "check": "practices",
35
40
  "coverage": "complete",
@@ -38,7 +43,7 @@
38
43
  ],
39
44
  "items": [],
40
45
  "actionsRequired": [],
41
- "digest": "sha256:1d40d5a0b5f92e61241f310b1f0c26b342210533455707a93f524d306db88b4e"
46
+ "digest": "sha256:ceaaaf214aff4c0b05abe367cad2b58e52b25d2aeeb4809ebc0e101d34e66d09"
42
47
  },
43
48
  "hookLog": {
44
49
  "schemaVersion": "archcontext.hook-log/v1",
@@ -2,7 +2,7 @@
2
2
  "schemaVersion": "archcontext.product-version-manifest/v1",
3
3
  "product": {
4
4
  "name": "archctx",
5
- "version": "0.12.0",
5
+ "version": "0.13.0",
6
6
  "distribution": "one-package"
7
7
  },
8
8
  "packageManager": "bun@1.4.3",
@@ -12,25 +12,25 @@
12
12
  "surfaces": {
13
13
  "cli": {
14
14
  "packageName": "@archcontext/surfaces",
15
- "version": "0.12.0",
15
+ "version": "0.13.0",
16
16
  "entrypoint": "archctx"
17
17
  },
18
18
  "daemon": {
19
19
  "packageName": "@archcontext/local-runtime",
20
- "version": "0.12.0",
20
+ "version": "0.13.0",
21
21
  "entrypoint": "archctx daemon start",
22
22
  "rpcSchemaVersion": "archcontext.runtime-rpc/v2"
23
23
  },
24
24
  "mcp": {
25
25
  "packageName": "@archcontext/surfaces",
26
- "version": "0.12.0",
26
+ "version": "0.13.0",
27
27
  "entrypoint": "archctx mcp",
28
28
  "transport": "stdio"
29
29
  }
30
30
  },
31
31
  "schemas": {
32
32
  "schemaSetVersion": "2026-06-25.al0-ledger",
33
- "contractsPackageVersion": "0.12.0"
33
+ "contractsPackageVersion": "0.13.0"
34
34
  },
35
35
  "runtime": {
36
36
  "localRpc": {
@@ -0,0 +1,76 @@
1
+ {
2
+ "schemaVersion": "archcontext.state-machine-check/v1",
3
+ "machines": [
4
+ {
5
+ "id": "state-machine.checkout.order",
6
+ "capabilityId": "capability.checkout",
7
+ "reachableStates": 6,
8
+ "transitions": 5,
9
+ "rules": [
10
+ {
11
+ "id": "paid-before-shipped",
12
+ "kind": "never",
13
+ "status": "broken",
14
+ "state": {
15
+ "order": "shipped",
16
+ "payment": "unpaid"
17
+ },
18
+ "path": [
19
+ {
20
+ "event": "ship",
21
+ "step": 1
22
+ }
23
+ ]
24
+ },
25
+ {
26
+ "id": "closed-order-stays-closed",
27
+ "kind": "final",
28
+ "status": "holds",
29
+ "protectedBy": [
30
+ {
31
+ "event": "ship",
32
+ "step": 1,
33
+ "region": "order"
34
+ },
35
+ {
36
+ "event": "cancel",
37
+ "step": 1,
38
+ "region": "order"
39
+ },
40
+ {
41
+ "event": "cancel",
42
+ "step": 2,
43
+ "region": "order"
44
+ }
45
+ ]
46
+ }
47
+ ],
48
+ "breaks": [],
49
+ "anchors": [
50
+ {
51
+ "owner": "event",
52
+ "ownerId": "capture",
53
+ "path": "src/payment.ts",
54
+ "symbol": "PaymentService.capture",
55
+ "status": "anchor-unconfirmed",
56
+ "digest": "sha256:1111111111111111111111111111111111111111111111111111111111111111"
57
+ },
58
+ {
59
+ "owner": "event",
60
+ "ownerId": "ship",
61
+ "path": "src/order.ts",
62
+ "symbol": "shipOrder",
63
+ "status": "anchor-unconfirmed",
64
+ "digest": "sha256:2222222222222222222222222222222222222222222222222222222222222222"
65
+ },
66
+ {
67
+ "owner": "event",
68
+ "ownerId": "cancel",
69
+ "path": "src/order.ts",
70
+ "symbol": "cancelOrder",
71
+ "status": "anchor-missing-symbol"
72
+ }
73
+ ]
74
+ }
75
+ ]
76
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "archctx-contracts",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -0,0 +1,153 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://archctx.repoharness.com/schemas/repo/architecture-state-machine.schema.json",
4
+ "title": "ArchitectureStateMachineV1",
5
+ "description": "One state machine of a capability: parallel regions of states, events whose steps move them, and the rules that no reachable global state may break. Cross-entity rules (unknown regions and states, duplicate ids, the 100000 global state limit) are checked by stateMachineModelIssues.",
6
+ "type": "object",
7
+ "additionalProperties": false,
8
+ "required": ["schemaVersion", "id", "capabilityId", "name", "regions", "events", "rules"],
9
+ "properties": {
10
+ "schemaVersion": { "const": "archcontext.state-machine/v1" },
11
+ "id": { "type": "string", "pattern": "^state-machine\\.[a-z][a-z0-9-]*(\\.[a-z0-9][a-z0-9-]*)*$" },
12
+ "capabilityId": { "type": "string", "pattern": "^capability\\.[a-z][a-z0-9-]*(\\.[a-z0-9][a-z0-9-]*)*$" },
13
+ "name": { "$ref": "#/$defs/label" },
14
+ "regions": {
15
+ "type": "array",
16
+ "minItems": 1,
17
+ "items": {
18
+ "type": "object",
19
+ "additionalProperties": false,
20
+ "required": ["id", "label", "initial", "states"],
21
+ "properties": {
22
+ "id": { "$ref": "#/$defs/localId" },
23
+ "label": { "$ref": "#/$defs/label" },
24
+ "initial": { "$ref": "#/$defs/localId" },
25
+ "states": {
26
+ "type": "array",
27
+ "minItems": 1,
28
+ "items": {
29
+ "type": "object",
30
+ "additionalProperties": false,
31
+ "required": ["id", "label"],
32
+ "properties": {
33
+ "id": { "$ref": "#/$defs/localId" },
34
+ "label": { "$ref": "#/$defs/label" },
35
+ "terminal": { "type": "boolean" }
36
+ }
37
+ }
38
+ },
39
+ "source": { "$ref": "#/$defs/codeSource" }
40
+ }
41
+ }
42
+ },
43
+ "events": {
44
+ "type": "array",
45
+ "minItems": 1,
46
+ "items": {
47
+ "type": "object",
48
+ "additionalProperties": false,
49
+ "required": ["id", "label", "source", "steps"],
50
+ "properties": {
51
+ "id": { "$ref": "#/$defs/localId" },
52
+ "label": { "$ref": "#/$defs/label" },
53
+ "source": {
54
+ "if": { "required": ["kind"], "properties": { "kind": { "const": "code" } } },
55
+ "then": { "$ref": "#/$defs/codeSource" },
56
+ "else": { "$ref": "#/$defs/environmentSource" }
57
+ },
58
+ "steps": {
59
+ "type": "array",
60
+ "minItems": 1,
61
+ "items": {
62
+ "type": "object",
63
+ "additionalProperties": false,
64
+ "required": ["when", "then"],
65
+ "properties": {
66
+ "when": {
67
+ "type": "object",
68
+ "minProperties": 1,
69
+ "propertyNames": { "$ref": "#/$defs/localId" },
70
+ "additionalProperties": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "$ref": "#/$defs/localId" } }
71
+ },
72
+ "then": {
73
+ "type": "object",
74
+ "minProperties": 1,
75
+ "propertyNames": { "$ref": "#/$defs/localId" },
76
+ "additionalProperties": { "$ref": "#/$defs/localId" }
77
+ }
78
+ }
79
+ }
80
+ }
81
+ }
82
+ }
83
+ },
84
+ "rules": {
85
+ "type": "array",
86
+ "items": {
87
+ "type": "object",
88
+ "additionalProperties": false,
89
+ "required": ["id", "label"],
90
+ "oneOf": [{ "required": ["never"] }, { "required": ["final"] }],
91
+ "properties": {
92
+ "id": { "$ref": "#/$defs/localId" },
93
+ "label": { "$ref": "#/$defs/label" },
94
+ "never": {
95
+ "type": "object",
96
+ "minProperties": 2,
97
+ "propertyNames": { "$ref": "#/$defs/localId" },
98
+ "additionalProperties": { "$ref": "#/$defs/stateList" }
99
+ },
100
+ "final": {
101
+ "type": "object",
102
+ "minProperties": 1,
103
+ "maxProperties": 1,
104
+ "propertyNames": { "$ref": "#/$defs/localId" },
105
+ "additionalProperties": { "$ref": "#/$defs/stateList" }
106
+ },
107
+ "finding": {
108
+ "type": "object",
109
+ "additionalProperties": false,
110
+ "required": ["tracking"],
111
+ "properties": {
112
+ "tracking": { "type": "string", "pattern": "^https://[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?(?:\\.[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?)*(?::[0-9]{1,5})?(?:[/?#][^\\s|`]*)?$" }
113
+ }
114
+ }
115
+ }
116
+ }
117
+ }
118
+ },
119
+ "$defs": {
120
+ "localId": { "type": "string", "pattern": "^[a-z][a-z0-9]*(-[a-z0-9]+)*$" },
121
+ "label": {
122
+ "description": "One line of 1 to 80 characters with none of the characters that a statechart label would need to escape.",
123
+ "type": "string",
124
+ "minLength": 1,
125
+ "maxLength": 80,
126
+ "pattern": "^[^\"#;:<>\\\\|\\r\\n]+$"
127
+ },
128
+ "stateList": { "type": "array", "minItems": 1, "items": { "$ref": "#/$defs/localId" } },
129
+ "codeSource": {
130
+ "type": "object",
131
+ "additionalProperties": false,
132
+ "required": ["kind", "path"],
133
+ "properties": {
134
+ "kind": { "const": "code" },
135
+ "path": {
136
+ "description": "A canonical repository-relative POSIX path: no leading slash, backslash, empty, `.` or `..` segment, and no `|`, backtick or line break.",
137
+ "type": "string",
138
+ "pattern": "^(?!(?:.*/)?\\.\\.?(?:/|$))[^/\\\\|`\\r\\n]+(?:/[^/\\\\|`\\r\\n]+)*$"
139
+ },
140
+ "symbol": { "description": "One line with no `|` or backtick.", "type": "string", "pattern": "^[^|`\\r\\n]+$" },
141
+ "confirmedDigest": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" }
142
+ }
143
+ },
144
+ "environmentSource": {
145
+ "type": "object",
146
+ "additionalProperties": false,
147
+ "required": ["kind"],
148
+ "properties": {
149
+ "kind": { "const": "environment" }
150
+ }
151
+ }
152
+ }
153
+ }
@@ -71,8 +71,8 @@
71
71
  },
72
72
  "checks": {
73
73
  "type": "array",
74
- "minItems": 5,
75
- "maxItems": 5,
74
+ "minItems": 6,
75
+ "maxItems": 6,
76
76
  "items": {
77
77
  "type": "object",
78
78
  "additionalProperties": false,
@@ -88,6 +88,7 @@
88
88
  "anchors",
89
89
  "dependencies",
90
90
  "flows",
91
+ "state-machines",
91
92
  "practices"
92
93
  ]
93
94
  },
@@ -137,7 +138,9 @@
137
138
  "undeclared-dependency",
138
139
  "flow-proof-failed",
139
140
  "stale-anchor",
140
- "practice-regression"
141
+ "practice-regression",
142
+ "state-machine-rule",
143
+ "state-machine-stale"
141
144
  ]
142
145
  },
143
146
  "nodeIds": {
@@ -0,0 +1,163 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://archcontext.dev/schemas/runtime/state-machine-check.schema.json",
4
+ "title": "StateMachineCheckV1",
5
+ "description": "The data of `archctx state-machines check`: for every declared state machine, the size of its reachable global state space, the result of each declared rule, the built-in breaks and the status of each code anchor. The same model gives the same bytes.",
6
+ "type": "object",
7
+ "additionalProperties": false,
8
+ "required": ["schemaVersion", "machines"],
9
+ "properties": {
10
+ "schemaVersion": { "const": "archcontext.state-machine-check/v1" },
11
+ "machines": {
12
+ "description": "Sorted by machine id.",
13
+ "type": "array",
14
+ "items": {
15
+ "type": "object",
16
+ "additionalProperties": false,
17
+ "required": ["id", "capabilityId", "reachableStates", "transitions", "rules", "breaks", "anchors"],
18
+ "properties": {
19
+ "id": { "type": "string", "pattern": "^state-machine\\.[a-z][a-z0-9-]*(\\.[a-z0-9][a-z0-9-]*)*$" },
20
+ "capabilityId": { "type": "string", "pattern": "^capability\\.[a-z][a-z0-9-]*(\\.[a-z0-9][a-z0-9-]*)*$" },
21
+ "reachableStates": { "type": "integer", "minimum": 1 },
22
+ "transitions": { "type": "integer", "minimum": 0, "description": "Pairs of a reachable global state and an enabled step that changes it." },
23
+ "rules": {
24
+ "description": "In declaration order.",
25
+ "type": "array",
26
+ "items": {
27
+ "type": "object",
28
+ "additionalProperties": false,
29
+ "required": ["id", "kind", "status"],
30
+ "properties": {
31
+ "id": { "$ref": "#/$defs/localId" },
32
+ "kind": { "enum": ["never", "final"] },
33
+ "status": { "enum": ["holds", "broken", "finding-open", "finding-resolved"] },
34
+ "tracking": { "type": "string", "pattern": "^https://[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?(?:\\.[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?)*(?::[0-9]{1,5})?(?:[/?#][^\\s]*)?$" },
35
+ "state": { "$ref": "#/$defs/globalState" },
36
+ "path": { "$ref": "#/$defs/path" },
37
+ "protectedBy": {
38
+ "description": "The guards whose removal breaks this holding rule, in declaration order of the guards.",
39
+ "type": "array",
40
+ "items": {
41
+ "type": "object",
42
+ "additionalProperties": false,
43
+ "required": ["event", "step", "region"],
44
+ "properties": {
45
+ "event": { "$ref": "#/$defs/localId" },
46
+ "step": { "$ref": "#/$defs/stepIndex" },
47
+ "region": { "$ref": "#/$defs/localId" }
48
+ }
49
+ }
50
+ }
51
+ },
52
+ "allOf": [
53
+ {
54
+ "if": { "properties": { "status": { "enum": ["broken", "finding-open"] } } },
55
+ "then": { "required": ["state", "path"], "not": { "required": ["protectedBy"] } },
56
+ "else": { "not": { "anyOf": [{ "required": ["state"] }, { "required": ["path"] }] } }
57
+ },
58
+ {
59
+ "if": { "properties": { "status": { "enum": ["finding-open", "finding-resolved"] } } },
60
+ "then": { "required": ["tracking"] },
61
+ "else": { "not": { "required": ["tracking"] } }
62
+ }
63
+ ]
64
+ }
65
+ },
66
+ "breaks": {
67
+ "description": "Every unreachable state, then every dead step, each in declaration order, then at most one deadlock.",
68
+ "type": "array",
69
+ "items": {
70
+ "oneOf": [
71
+ {
72
+ "type": "object",
73
+ "additionalProperties": false,
74
+ "required": ["kind", "region", "state"],
75
+ "properties": {
76
+ "kind": { "const": "unreachable-state" },
77
+ "region": { "$ref": "#/$defs/localId" },
78
+ "state": { "$ref": "#/$defs/localId" }
79
+ }
80
+ },
81
+ {
82
+ "type": "object",
83
+ "additionalProperties": false,
84
+ "required": ["kind", "event", "step"],
85
+ "properties": {
86
+ "kind": { "const": "dead-step" },
87
+ "event": { "$ref": "#/$defs/localId" },
88
+ "step": { "$ref": "#/$defs/stepIndex" }
89
+ }
90
+ },
91
+ {
92
+ "type": "object",
93
+ "additionalProperties": false,
94
+ "required": ["kind", "state", "path", "count"],
95
+ "properties": {
96
+ "kind": { "const": "deadlock" },
97
+ "state": { "$ref": "#/$defs/globalState" },
98
+ "path": { "$ref": "#/$defs/path" },
99
+ "count": { "type": "integer", "minimum": 1, "description": "The number of deadlocked reachable global states." }
100
+ }
101
+ }
102
+ ]
103
+ }
104
+ },
105
+ "anchors": {
106
+ "description": "Every code source of a region or an event, regions first, then events, each in declaration order, with its status against the current file.",
107
+ "type": "array",
108
+ "items": {
109
+ "type": "object",
110
+ "additionalProperties": false,
111
+ "required": ["owner", "ownerId", "path", "status"],
112
+ "properties": {
113
+ "owner": { "enum": ["region", "event"] },
114
+ "ownerId": { "$ref": "#/$defs/localId" },
115
+ "path": { "type": "string", "minLength": 1 },
116
+ "symbol": { "type": "string", "minLength": 1 },
117
+ "status": { "enum": ["anchor-missing-path", "anchor-language-unsupported", "anchor-missing-symbol", "anchor-ambiguous-symbol", "unchecked", "anchor-unconfirmed", "anchor-changed", "confirmed"] },
118
+ "digest": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$", "description": "The file content, or the lines of the one matching declaration, with CRLF read as LF." },
119
+ "reason": { "enum": ["index-missing", "index-open-failed"], "description": "Why the symbol reader is unavailable." }
120
+ },
121
+ "allOf": [
122
+ {
123
+ "if": { "properties": { "status": { "enum": ["anchor-unconfirmed", "anchor-changed", "confirmed"] } } },
124
+ "then": { "required": ["digest"] },
125
+ "else": { "not": { "required": ["digest"] } }
126
+ },
127
+ {
128
+ "if": { "properties": { "status": { "const": "unchecked" } } },
129
+ "then": { "required": ["reason", "symbol"] },
130
+ "else": { "not": { "required": ["reason"] } }
131
+ }
132
+ ]
133
+ }
134
+ }
135
+ }
136
+ }
137
+ }
138
+ },
139
+ "$defs": {
140
+ "localId": { "type": "string", "pattern": "^[a-z][a-z0-9]*(-[a-z0-9]+)*$" },
141
+ "stepIndex": { "type": "integer", "minimum": 1, "description": "The 1-based index of the step in its event." },
142
+ "globalState": {
143
+ "description": "One state per region, keyed by region id in declaration order.",
144
+ "type": "object",
145
+ "minProperties": 1,
146
+ "propertyNames": { "$ref": "#/$defs/localId" },
147
+ "additionalProperties": { "$ref": "#/$defs/localId" }
148
+ },
149
+ "path": {
150
+ "description": "The shortest sequence of fired steps from the initial global state.",
151
+ "type": "array",
152
+ "items": {
153
+ "type": "object",
154
+ "additionalProperties": false,
155
+ "required": ["event", "step"],
156
+ "properties": {
157
+ "event": { "$ref": "#/$defs/localId" },
158
+ "step": { "$ref": "#/$defs/stepIndex" }
159
+ }
160
+ }
161
+ }
162
+ }
163
+ }
@@ -2,9 +2,9 @@ import { digestJson, type ArchContextError, type Json } from "./schema";
2
2
 
3
3
  /** Measured architecture work, distinct from generated-file freshness and source byte stamps. */
4
4
  export const ARCHITECTURE_DEBT_SCHEMA_VERSION = "archcontext.architecture-debt/v1" as const;
5
- export const ARCHITECTURE_DEBT_KINDS = ["unowned-path", "ambiguous-owner", "undeclared-dependency", "flow-proof-failed", "stale-anchor", "practice-regression"] as const;
5
+ export const ARCHITECTURE_DEBT_KINDS = ["unowned-path", "ambiguous-owner", "undeclared-dependency", "flow-proof-failed", "stale-anchor", "practice-regression", "state-machine-rule", "state-machine-stale"] as const;
6
6
  export type ArchitectureDebtKind = typeof ARCHITECTURE_DEBT_KINDS[number];
7
- export const ARCHITECTURE_DEBT_CHECKS = ["ownership", "anchors", "dependencies", "flows", "practices"] as const;
7
+ export const ARCHITECTURE_DEBT_CHECKS = ["ownership", "anchors", "dependencies", "flows", "state-machines", "practices"] as const;
8
8
  export type ArchitectureDebtCheck = typeof ARCHITECTURE_DEBT_CHECKS[number];
9
9
 
10
10
  export interface ArchitectureDebtItemV1 {
package/src/failure.ts CHANGED
@@ -8,7 +8,7 @@ import { ERROR_CATALOG, canonicalize, isRepoRelativePosixPath, type ArchContextE
8
8
 
9
9
  /** Only selected entrypoints support transport failures; the legacy AC-only envelope is unchanged. */
10
10
  export type FailureCode = ArchContextErrorCode | "RPC_TIMEOUT" | "RPC_ABORTED";
11
- export const FAILURE_STAGES = Object.freeze(["debt", "complete", "practice-checkpoint", "cli", "mcp", "hook-checkpoint", "failure-metadata", "public-operation", "native-export", "docs-anchors", "flows-check"] as const);
11
+ export const FAILURE_STAGES = Object.freeze(["debt", "complete", "practice-checkpoint", "cli", "mcp", "hook-checkpoint", "failure-metadata", "public-operation", "native-export", "docs-anchors", "flows-check", "state-machines-check"] as const);
12
12
  export type FailureStage = typeof FAILURE_STAGES[number];
13
13
  const ERROR_CLASSES = Object.freeze(["Error", "TypeError", "RangeError", "SyntaxError", "ReferenceError", "URIError", "EvalError", "AggregateError", "NonError"]);
14
14
  export interface StrictFailure<C extends FailureCode = FailureCode> {
@@ -55,6 +55,7 @@ const policies: Record<string, Policy> = {
55
55
  "changed-path-invalid": { code: "AC_SCHEMA_INVALID", message: "Changed paths must be an array of repository-relative POSIX paths.", fields: ["checks"] },
56
56
  "debt-report-invalid": { code: "AC_SCHEMA_INVALID", message: "Architecture debt evidence violates its contract.", fields: ["checks"] },
57
57
  "projection-manifest-upgrade-required": { code: "AC_PRECONDITION_FAILED", message: `The committed projection manifest requires supported re-baselining. First restore the original model if missing; the manifest digest cannot recover it. With the reviewed model available, follow ${ARCHITECTURE_DOCS_PROJECTION_MANIFEST_MIGRATION_GUIDE} before running ${ARCHITECTURE_DOCS_PROJECTION_MANIFEST_UPGRADE_COMMAND}.`, facts: { manifestPath: "optional:projectionManifestPath", foundSchemaVersion: "optional:projectionManifestSchemaVersion", supportedSchemaVersion: "optional:projectionManifestSchemaVersion", upgradeCommand: "optional:projectionManifestUpgradeCommand", migrationGuide: "optional:projectionManifestMigrationGuide" } },
58
+ "projection-writer-base-moved": { code: "AC_PRECONDITION_FAILED", message: "The remote base no longer points at the requested commit.", retryable: true, facts: { expectedBaseSha: "head", actualBaseSha: "head" } },
58
59
  "projection-manifest-invalid": { code: "AC_PRECONDITION_FAILED", message: "The committed projection manifest violates its contract." },
59
60
  "architecture-model-ignored": { code: "AC_PRECONDITION_FAILED", action: "commit-architecture-model", message: "Git ignore rules exclude architecture model paths, so the model cannot be committed and a manifest digest cannot rebuild it. Remove or narrow the rule, commit the model, then retry adoption. The diagnostic command prints each deciding rule.", facts: { pathCount: "uint", paths: "optional:diagnosticPaths", commands: "optional:diagnosticCommands", omittedPathCount: "uint" } },
60
61
  "projection-footprint-uncovered": { code: "AC_PRECONDITION_FAILED", message: "Declared source footprints lack a projection target." },
@@ -63,6 +64,7 @@ const policies: Record<string, Policy> = {
63
64
  "checkpoint-input-invalid": { code: "AC_SCHEMA_INVALID", message: "Checkpoint arguments violate the declared input schema.", fields: ["issueCount"], action: "correct-command-arguments" },
64
65
  "cli-input-invalid": { code: "AC_SCHEMA_INVALID", message: "Command arguments violate the declared input contract.", action: "correct-command-arguments" },
65
66
  "constraint-model-invalid": { code: "AC_SCHEMA_INVALID", message: "Dependency constraint declarations are invalid.", facts: { issueCount: "uint" }, action: "repair-constraint-declarations" },
67
+ "state-machine-model-invalid": { code: "AC_SCHEMA_INVALID", message: "State machine declarations are invalid. Run archctx validate --json for the full list of issues.", facts: { issues: "stateMachineIssues", issueCount: "uint", omittedCount: "uint" }, action: "repair-state-machine-declarations" },
66
68
  "complete-input-invalid": { code: "AC_SCHEMA_INVALID", message: "Completion input violates the caller authority contract.", action: "correct-command-arguments" },
67
69
  "hook-event-invalid": { code: "AC_SCHEMA_INVALID", message: "Hook event violates the declared input contract.", action: "correct-command-arguments" },
68
70
  "egress-policy-denied": { code: "AC_POLICY_VIOLATION", message: "Local policy refused this operation." },
@@ -227,6 +229,7 @@ Object.assign(policies, {
227
229
  "refactor-decision-approval-required": {"code": "AC_USER_CONFIRMATION_REQUIRED","message": "Refactor decision approval required.","facts": {"recommendationId": "id"}},
228
230
  "jobs-input-invalid": {"code": "AC_SCHEMA_INVALID","message": "Jobs input invalid.","facts": {"field":"optional:jobsField"}},
229
231
  "job-running-required": {"code": "AC_PRECONDITION_FAILED","message": "Job running required.","facts": {"jobId": "id"}},
232
+ "job-transition-invalid": {"code": "AC_PRECONDITION_FAILED","message": "Job transition invalid.","facts": {"jobId": "id"}},
230
233
  "job-context-stale": {"code": "AC_CONTEXT_STALE","message": "Job context stale.","facts": {"jobId": "id","expectedHeadSha": "head","actualHeadSha": "head","expectedWorktreeDigest": "sha256","actualWorktreeDigest": "sha256"}},
231
234
  "audit-disabled": {"code": "AC_CAPABILITY_UNSUPPORTED","message": "Audit disabled.","facts": {}},
232
235
  "audit-active": {"code": "AC_PRECONDITION_FAILED","message": "Audit active.","facts": {}},
@@ -458,6 +461,17 @@ function localFactValue(rule: string, value: unknown): Json {
458
461
  return { path, code: code as string };
459
462
  });
460
463
  }
464
+ if (rule === "stateMachineIssues") {
465
+ // `<path>: <field>: <invariant or schema message>`; issueCount and omittedCount count what does not fit.
466
+ if (!Array.isArray(value)) throw new Error("State machine issues must be an own list");
467
+ const length = Object.getOwnPropertyDescriptor(value, "length")?.value;
468
+ if (!Number.isSafeInteger(length) || length > 16 || Reflect.ownKeys(value).length !== length + 1) throw new Error("State machine issues exceed their closed budget");
469
+ return Array.from({ length }, (_, index) => {
470
+ const field = Object.getOwnPropertyDescriptor(value, String(index));
471
+ if (!field || !("value" in field) || typeof field.value !== "string" || bytes(field.value) > 256) throw new Error("Invalid state machine issue");
472
+ return field.value;
473
+ });
474
+ }
461
475
  if (rule === "diagnosticPaths" || rule === "diagnosticCommands") {
462
476
  if (!Array.isArray(value)) throw new Error("Diagnostics must be an own list");
463
477
  const length=Object.getOwnPropertyDescriptor(value,"length")?.value;
@@ -744,7 +758,7 @@ export function knownFailure<C extends FailureCode>(code: C, reasonCode: string,
744
758
  return { code, message: policy.message, severity, retryable, action, reasonCode, details: projectionRecoveryDetailsSnapshot(reasonCode, details) };
745
759
  }
746
760
  const safeDetails = detailsFor(policy, details);
747
- const extendedFacts = Object.values(policy.facts ?? {}).some(rule => rule === "publicConfirmationToken" || rule === "commandSuggestion" || rule === "diagnosticCommands");
761
+ const extendedFacts = Object.values(policy.facts ?? {}).some(rule => ["publicConfirmationToken", "commandSuggestion", "diagnosticCommands"].includes(rule.replace(/^optional:/, "")));
748
762
  if (budgetIssues(safeDetails, 0, extendedFacts ? 1024 : 256).length || bytes(JSON.stringify(safeDetails)) > 8192 || bytes(policy.message) > 1024) throw new Error("Failure metadata exceeds its UTF-8 budget");
749
763
  return { code, message: policy.message, severity, retryable, action, reasonCode, details: safeDetails };
750
764
  }
@@ -845,7 +859,7 @@ export function failureIssues(value: unknown): string[] {
845
859
  if ((prototype !== Object.prototype && prototype !== null) || keys.length !== fields.length || Object.keys(value).length !== fields.length || keys.some(key => typeof key !== "string" || !fields.includes(key))) return ["failure must match its closed registered contract"];
846
860
  const data = Object.fromEntries(fields.map(key => [key, ownData(value, key)]));
847
861
  const policy = typeof data.reasonCode === "string" ? policies[data.reasonCode] : undefined;
848
- const extendedFacts = policy !== undefined && policy.code === data.code && Object.values(policy.facts ?? {}).some(rule => rule === "publicConfirmationToken" || rule === "commandSuggestion" || rule === "diagnosticCommands");
862
+ const extendedFacts = policy !== undefined && policy.code === data.code && Object.values(policy.facts ?? {}).some(rule => ["publicConfirmationToken", "commandSuggestion", "diagnosticCommands"].includes(rule.replace(/^optional:/, "")));
849
863
  data.details = policy?.journalRecovery && policy.code === data.code ? changeSetRecoveryDetailsSnapshot(data.details) : policy?.recovery && policy.code === data.code ? projectionRecoveryDetailsSnapshot(data.reasonCode as string, data.details) : jsonDataSnapshot(data.details, 0, extendedFacts ? 1024 : 256);
850
864
  if (typeof data.message !== "string" || bytes(data.message) > 1024 || bytes(JSON.stringify(data.details)) > (policy?.recovery || policy?.journalRecovery ? PROJECTION_RECOVERY_DETAILS_LIMIT_BYTES : 8192)) return ["failure exceeds byte/shape budget"];
851
865
  const expected = failureFromData(data);
package/src/index.ts CHANGED
@@ -19,6 +19,7 @@ export * from "./product-version";
19
19
  export * from "./refactor";
20
20
  export * from "./runtime-topology";
21
21
  export * from "./schema";
22
+ export * from "./state-machine";
22
23
  export * from "./failure";
23
24
  export * from "./validator";
24
25
 
@@ -1,5 +1,5 @@
1
1
  export const ARCHCONTEXT_PRODUCT_NAME = "archctx";
2
- export const ARCHCONTEXT_PRODUCT_VERSION = "0.12.0";
2
+ export const ARCHCONTEXT_PRODUCT_VERSION = "0.13.0";
3
3
  export const ARCHCONTEXT_PACKAGE_MANAGER = "bun@1.4.3";
4
4
  export const ARCHCONTEXT_NODE_RANGE = ">=22.22 <26";
5
5
  export const LOCAL_RUNTIME_RPC_SCHEMA_VERSION = "archcontext.runtime-rpc/v2";
@@ -0,0 +1,275 @@
1
+ import type { Json } from "./schema";
2
+
3
+ export const STATE_MACHINE_SCHEMA_VERSION = "archcontext.state-machine/v1";
4
+ export const STATE_MACHINE_CHECK_SCHEMA_VERSION = "archcontext.state-machine-check/v1";
5
+ /** The largest product of region sizes that a model may declare; the check enumerates at most this many global states. */
6
+ export const STATE_MACHINE_PRODUCT_LIMIT = 100_000;
7
+
8
+ export interface StateMachineCodeSource {
9
+ kind: "code";
10
+ /** A repository-relative POSIX path. */
11
+ path: string;
12
+ symbol?: string;
13
+ confirmedDigest?: string;
14
+ }
15
+
16
+ export interface StateMachineEnvironmentSource {
17
+ kind: "environment";
18
+ }
19
+
20
+ export interface StateMachineState {
21
+ id: string;
22
+ label: string;
23
+ terminal?: boolean;
24
+ }
25
+
26
+ export interface StateMachineRegion {
27
+ id: string;
28
+ label: string;
29
+ initial: string;
30
+ states: StateMachineState[];
31
+ /** The code that owns the region. A region without one is a history region. */
32
+ source?: StateMachineCodeSource;
33
+ }
34
+
35
+ /** `when` maps a region to the states the step accepts; `then` maps a region to the state the step writes. */
36
+ export interface StateMachineStep {
37
+ when: Record<string, string[]>;
38
+ then: Record<string, string>;
39
+ }
40
+
41
+ export interface StateMachineEvent {
42
+ id: string;
43
+ label: string;
44
+ source: StateMachineCodeSource | StateMachineEnvironmentSource;
45
+ steps: StateMachineStep[];
46
+ }
47
+
48
+ export interface StateMachineFinding {
49
+ /** An https URL of the issue that tracks the known break. */
50
+ tracking: string;
51
+ }
52
+
53
+ interface StateMachineRuleBase {
54
+ id: string;
55
+ label: string;
56
+ finding?: StateMachineFinding;
57
+ }
58
+
59
+ /** No reachable global state has every named region in one of its listed states. */
60
+ export interface StateMachineNeverRule extends StateMachineRuleBase {
61
+ never: Record<string, string[]>;
62
+ final?: never;
63
+ }
64
+
65
+ /** Once its one region is in a listed state, no enabled step moves it to another state. */
66
+ export interface StateMachineFinalRule extends StateMachineRuleBase {
67
+ final: Record<string, string[]>;
68
+ never?: never;
69
+ }
70
+
71
+ export type StateMachineRule = StateMachineNeverRule | StateMachineFinalRule;
72
+
73
+ /** `schemas/repo/architecture-state-machine.schema.json`, one file under `.archcontext/model/state-machines/`. */
74
+ export interface StateMachineV1 {
75
+ schemaVersion: typeof STATE_MACHINE_SCHEMA_VERSION;
76
+ id: string;
77
+ capabilityId: string;
78
+ name: string;
79
+ regions: StateMachineRegion[];
80
+ events: StateMachineEvent[];
81
+ rules: StateMachineRule[];
82
+ }
83
+
84
+ export type StateMachineInvariant =
85
+ | "state-machine-id-duplicate"
86
+ | "state-machine-capability-missing"
87
+ | "state-machine-initial-unknown"
88
+ | "state-machine-region-unknown"
89
+ | "state-machine-state-unknown"
90
+ | "state-machine-step-source-missing"
91
+ | "state-machine-product-too-large";
92
+
93
+ export interface StateMachineIssue {
94
+ /** The machine id. */
95
+ entityId: string;
96
+ /** The path of the value inside the machine, for example `regions[1].initial`. */
97
+ field: string;
98
+ invariant: StateMachineInvariant;
99
+ }
100
+
101
+ /** One state per region, keyed by region id in declaration order. */
102
+ export type StateMachineGlobalState = Record<string, string>;
103
+
104
+ /** `step` is the 1-based index of the step in its event. */
105
+ export interface StateMachinePathStep {
106
+ event: string;
107
+ step: number;
108
+ }
109
+
110
+ export interface StateMachineGuard {
111
+ event: string;
112
+ step: number;
113
+ region: string;
114
+ }
115
+
116
+ export type StateMachineRuleStatus = "holds" | "broken" | "finding-open" | "finding-resolved";
117
+
118
+ export interface StateMachineRuleResult {
119
+ id: string;
120
+ kind: "never" | "final";
121
+ status: StateMachineRuleStatus;
122
+ /** Present when the rule carries a finding. */
123
+ tracking?: string;
124
+ /** Present when the rule is broken. */
125
+ state?: StateMachineGlobalState;
126
+ /** Present when the rule is broken: the shortest path to `state`; for a `final` rule it ends with the step that moves the region. */
127
+ path?: StateMachinePathStep[];
128
+ /** Present when the rule holds and the check ran the protection analysis. */
129
+ protectedBy?: StateMachineGuard[];
130
+ }
131
+
132
+ export type StateMachineBreak =
133
+ | { kind: "unreachable-state"; region: string; state: string }
134
+ | { kind: "dead-step"; event: string; step: number }
135
+ | { kind: "deadlock"; state: StateMachineGlobalState; path: StateMachinePathStep[]; count: number };
136
+
137
+ export interface StateMachineMachineReport {
138
+ id: string;
139
+ capabilityId: string;
140
+ reachableStates: number;
141
+ transitions: number;
142
+ rules: StateMachineRuleResult[];
143
+ breaks: StateMachineBreak[];
144
+ }
145
+
146
+ /** The model-only result of `checkStateMachines`: rules and breaks, no code read. */
147
+ export interface StateMachineRuleCheckV1 {
148
+ schemaVersion: typeof STATE_MACHINE_CHECK_SCHEMA_VERSION;
149
+ /** Sorted by machine id. */
150
+ machines: StateMachineMachineReport[];
151
+ }
152
+
153
+ export type StateMachineAnchorStatus =
154
+ | "anchor-missing-path"
155
+ | "anchor-language-unsupported"
156
+ | "anchor-missing-symbol"
157
+ | "anchor-ambiguous-symbol"
158
+ | "unchecked"
159
+ | "anchor-unconfirmed"
160
+ | "anchor-changed"
161
+ | "confirmed";
162
+
163
+ /** The status of one `code` source of a region or an event, measured against the current file. */
164
+ export interface StateMachineAnchor {
165
+ owner: "region" | "event";
166
+ ownerId: string;
167
+ path: string;
168
+ symbol?: string;
169
+ status: StateMachineAnchorStatus;
170
+ /** Present for `anchor-unconfirmed`, `anchor-changed` and `confirmed`. */
171
+ digest?: string;
172
+ /** Present for `unchecked`: the reason code of the unavailable symbol reader. */
173
+ reason?: "index-missing" | "index-open-failed";
174
+ }
175
+
176
+ export interface StateMachineCheckMachineV1 extends StateMachineMachineReport {
177
+ /** Every code anchor, regions first, then events, each in declaration order. */
178
+ anchors: StateMachineAnchor[];
179
+ }
180
+
181
+ /** `schemas/runtime/state-machine-check.schema.json`, the data of `archctx state-machines check`. */
182
+ export interface StateMachineCheckReportV1 {
183
+ schemaVersion: typeof STATE_MACHINE_CHECK_SCHEMA_VERSION;
184
+ /** Sorted by machine id. */
185
+ machines: StateMachineCheckMachineV1[];
186
+ }
187
+
188
+ type NodeRecord = Readonly<Record<string, Json | undefined>>;
189
+
190
+ /**
191
+ * Cross-entity rules of the state machine model that the per-file schema cannot state. The
192
+ * loader and the YAML model store both call this one function on schema-valid machines, so
193
+ * `archctx validate` and `archctx state-machines check` cannot disagree.
194
+ *
195
+ * The result is aligned with `stateMachines`: entry `i` holds the issues of machine `i`, so a
196
+ * caller can name the file of each issue even when two machines share an id. A repeated machine
197
+ * id is reported on every machine after the first. A lookup that meets a duplicate id inside a
198
+ * machine uses the first declaration. A region that the machine does not declare is reported
199
+ * once; its states are not checked. Each entry is sorted by field, then invariant.
200
+ */
201
+ export function stateMachineModelIssuesByMachine(model: { nodes: readonly NodeRecord[]; stateMachines: readonly StateMachineV1[] }): StateMachineIssue[][] {
202
+ const capabilities = new Set(model.nodes.filter((node) => node.kind === "capability" && typeof node.id === "string").map((node) => node.id as string));
203
+ const machineIds = new Set<string>();
204
+ return model.stateMachines.map((machine) => {
205
+ const issues: StateMachineIssue[] = [];
206
+ const report = (field: string, invariant: StateMachineInvariant) => issues.push({ entityId: machine.id, field, invariant });
207
+ if (machineIds.has(machine.id)) report("id", "state-machine-id-duplicate");
208
+ machineIds.add(machine.id);
209
+ if (!capabilities.has(machine.capabilityId)) report("capabilityId", "state-machine-capability-missing");
210
+ const regions = new Map<string, Set<string>>();
211
+ let product = 1;
212
+ machine.regions.forEach((region, regionIndex) => {
213
+ if (regions.has(region.id)) report(`regions[${regionIndex}].id`, "state-machine-id-duplicate");
214
+ const states = new Set<string>();
215
+ region.states.forEach((state, stateIndex) => {
216
+ if (states.has(state.id)) report(`regions[${regionIndex}].states[${stateIndex}].id`, "state-machine-id-duplicate");
217
+ states.add(state.id);
218
+ });
219
+ if (!states.has(region.initial)) report(`regions[${regionIndex}].initial`, "state-machine-initial-unknown");
220
+ if (!regions.has(region.id)) regions.set(region.id, states);
221
+ product *= region.states.length;
222
+ });
223
+ if (product > STATE_MACHINE_PRODUCT_LIMIT) report("regions", "state-machine-product-too-large");
224
+ const checkStates = (field: string, entries: Record<string, string | string[]>) => {
225
+ for (const [regionId, value] of Object.entries(entries)) {
226
+ const states = regions.get(regionId);
227
+ if (!states) {
228
+ report(`${field}.${regionId}`, "state-machine-region-unknown");
229
+ continue;
230
+ }
231
+ if (typeof value === "string") {
232
+ if (!states.has(value)) report(`${field}.${regionId}`, "state-machine-state-unknown");
233
+ continue;
234
+ }
235
+ value.forEach((state, index) => {
236
+ if (!states.has(state)) report(`${field}.${regionId}[${index}]`, "state-machine-state-unknown");
237
+ });
238
+ }
239
+ };
240
+ const eventIds = new Set<string>();
241
+ machine.events.forEach((event, eventIndex) => {
242
+ if (eventIds.has(event.id)) report(`events[${eventIndex}].id`, "state-machine-id-duplicate");
243
+ eventIds.add(event.id);
244
+ event.steps.forEach((step, stepIndex) => {
245
+ const field = `events[${eventIndex}].steps[${stepIndex}]`;
246
+ checkStates(`${field}.when`, step.when);
247
+ checkStates(`${field}.then`, step.then);
248
+ for (const regionId of Object.keys(step.then)) {
249
+ if (!Object.hasOwn(step.when, regionId)) report(`${field}.then.${regionId}`, "state-machine-step-source-missing");
250
+ }
251
+ });
252
+ });
253
+ const ruleIds = new Set<string>();
254
+ machine.rules.forEach((rule, ruleIndex) => {
255
+ if (ruleIds.has(rule.id)) report(`rules[${ruleIndex}].id`, "state-machine-id-duplicate");
256
+ ruleIds.add(rule.id);
257
+ if (rule.never) checkStates(`rules[${ruleIndex}].never`, rule.never);
258
+ else checkStates(`rules[${ruleIndex}].final`, rule.final);
259
+ });
260
+ return issues.sort(compareIssues);
261
+ });
262
+ }
263
+
264
+ /** Every issue of `stateMachineModelIssuesByMachine` in one list, sorted by entity id, then field and invariant. */
265
+ export function stateMachineModelIssues(model: { nodes: readonly NodeRecord[]; stateMachines: readonly StateMachineV1[] }): StateMachineIssue[] {
266
+ return stateMachineModelIssuesByMachine(model).flat().sort(compareIssues);
267
+ }
268
+
269
+ function compareIssues(left: StateMachineIssue, right: StateMachineIssue): number {
270
+ return compare(left.entityId, right.entityId) || compare(left.field, right.field) || compare(left.invariant, right.invariant);
271
+ }
272
+
273
+ function compare(left: string, right: string): number {
274
+ return left < right ? -1 : left > right ? 1 : 0;
275
+ }
package/src/validator.ts CHANGED
@@ -31,6 +31,9 @@ type JsonSchema = {
31
31
  else?: JsonSchema;
32
32
  not?: JsonSchema;
33
33
  additionalProperties?: boolean | JsonSchema;
34
+ propertyNames?: JsonSchema;
35
+ minProperties?: number;
36
+ maxProperties?: number;
34
37
  minItems?: number;
35
38
  maxItems?: number;
36
39
  uniqueItems?: boolean;
@@ -179,6 +182,10 @@ function visit(
179
182
  if (!Object.hasOwn(schema.properties, key)) issues.push({ path: `${path}.${key}`, message: "additional property denied" });
180
183
  }
181
184
  }
185
+ const keys = Object.keys(objectValue);
186
+ if (schema.minProperties !== undefined && keys.length < schema.minProperties) issues.push({ path, message: `expected at least ${schema.minProperties} properties` });
187
+ if (schema.maxProperties !== undefined && keys.length > schema.maxProperties) issues.push({ path, message: `expected at most ${schema.maxProperties} properties` });
188
+ if (schema.propertyNames) for (const key of keys) visit(schema.propertyNames, key, `${path}.${key}`, issues, root, resolveSchema);
182
189
  if (schema.additionalProperties && typeof schema.additionalProperties === "object") {
183
190
  for (const [key, child] of Object.entries(objectValue)) {
184
191
  if (!Object.hasOwn(schema.properties ?? {}, key)) visit(schema.additionalProperties, child, `${path}.${key}`, issues, root, resolveSchema);