@openplanr/protocol 0.6.2 → 0.7.1

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.
@@ -0,0 +1,316 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://openplanr.dev/schemas/v1.14.0/artifact-theme.schema.json",
4
+ "x-openplanr-contract": {
5
+ "id": "artifact-theme",
6
+ "version": "1.14.0"
7
+ },
8
+ "title": "OpenPlanr artifact review theme registry",
9
+ "type": "object",
10
+ "additionalProperties": false,
11
+ "required": [
12
+ "kind",
13
+ "schemaVersion",
14
+ "protocolVersion",
15
+ "name",
16
+ "typography",
17
+ "layout",
18
+ "themes"
19
+ ],
20
+ "properties": {
21
+ "kind": {
22
+ "const": "artifact-theme"
23
+ },
24
+ "schemaVersion": {
25
+ "const": "1.1.0"
26
+ },
27
+ "protocolVersion": {
28
+ "const": "1.14.0"
29
+ },
30
+ "name": {
31
+ "const": "OpenPlanr Artifact Review"
32
+ },
33
+ "typography": {
34
+ "type": "object",
35
+ "additionalProperties": false,
36
+ "required": [
37
+ "display",
38
+ "body",
39
+ "mono"
40
+ ],
41
+ "properties": {
42
+ "display": {
43
+ "const": "Outfit"
44
+ },
45
+ "body": {
46
+ "const": "DM Sans"
47
+ },
48
+ "mono": {
49
+ "const": "Source Code Pro"
50
+ }
51
+ }
52
+ },
53
+ "layout": {
54
+ "type": "object",
55
+ "additionalProperties": false,
56
+ "required": [
57
+ "toolbarHeight",
58
+ "reviewRailWidth",
59
+ "radiusSmall",
60
+ "radiusMedium",
61
+ "radiusLarge",
62
+ "motionFastMs",
63
+ "motionBaseMs"
64
+ ],
65
+ "properties": {
66
+ "toolbarHeight": {
67
+ "const": 48
68
+ },
69
+ "reviewRailWidth": {
70
+ "const": 344
71
+ },
72
+ "radiusSmall": {
73
+ "type": "integer",
74
+ "minimum": 0,
75
+ "maximum": 32
76
+ },
77
+ "radiusMedium": {
78
+ "type": "integer",
79
+ "minimum": 0,
80
+ "maximum": 32
81
+ },
82
+ "radiusLarge": {
83
+ "type": "integer",
84
+ "minimum": 0,
85
+ "maximum": 32
86
+ },
87
+ "motionFastMs": {
88
+ "type": "integer",
89
+ "minimum": 120,
90
+ "maximum": 200
91
+ },
92
+ "motionBaseMs": {
93
+ "type": "integer",
94
+ "minimum": 120,
95
+ "maximum": 200
96
+ }
97
+ }
98
+ },
99
+ "themes": {
100
+ "type": "object",
101
+ "additionalProperties": false,
102
+ "required": [
103
+ "dark",
104
+ "light"
105
+ ],
106
+ "properties": {
107
+ "dark": {
108
+ "type": "object",
109
+ "additionalProperties": false,
110
+ "required": [
111
+ "background",
112
+ "chrome",
113
+ "panel",
114
+ "raised",
115
+ "stage",
116
+ "rule",
117
+ "text",
118
+ "textMuted",
119
+ "primary",
120
+ "primaryStrong",
121
+ "onPrimary",
122
+ "warning",
123
+ "danger",
124
+ "onDanger",
125
+ "question",
126
+ "onQuestion",
127
+ "resolved",
128
+ "onResolved",
129
+ "onImprove"
130
+ ],
131
+ "properties": {
132
+ "background": {
133
+ "type": "string",
134
+ "pattern": "^#[0-9A-Fa-f]{6}$"
135
+ },
136
+ "chrome": {
137
+ "type": "string",
138
+ "pattern": "^#[0-9A-Fa-f]{6}$"
139
+ },
140
+ "panel": {
141
+ "type": "string",
142
+ "pattern": "^#[0-9A-Fa-f]{6}$"
143
+ },
144
+ "raised": {
145
+ "type": "string",
146
+ "pattern": "^#[0-9A-Fa-f]{6}$"
147
+ },
148
+ "stage": {
149
+ "type": "string",
150
+ "pattern": "^#[0-9A-Fa-f]{6}$"
151
+ },
152
+ "rule": {
153
+ "type": "string",
154
+ "pattern": "^#[0-9A-Fa-f]{6}$"
155
+ },
156
+ "text": {
157
+ "type": "string",
158
+ "pattern": "^#[0-9A-Fa-f]{6}$"
159
+ },
160
+ "textMuted": {
161
+ "type": "string",
162
+ "pattern": "^#[0-9A-Fa-f]{6}$"
163
+ },
164
+ "primary": {
165
+ "type": "string",
166
+ "pattern": "^#[0-9A-Fa-f]{6}$"
167
+ },
168
+ "primaryStrong": {
169
+ "type": "string",
170
+ "pattern": "^#[0-9A-Fa-f]{6}$"
171
+ },
172
+ "onPrimary": {
173
+ "type": "string",
174
+ "pattern": "^#[0-9A-Fa-f]{6}$"
175
+ },
176
+ "warning": {
177
+ "type": "string",
178
+ "pattern": "^#[0-9A-Fa-f]{6}$"
179
+ },
180
+ "danger": {
181
+ "type": "string",
182
+ "pattern": "^#[0-9A-Fa-f]{6}$"
183
+ },
184
+ "onDanger": {
185
+ "type": "string",
186
+ "pattern": "^#[0-9A-Fa-f]{6}$"
187
+ },
188
+ "question": {
189
+ "type": "string",
190
+ "pattern": "^#[0-9A-Fa-f]{6}$"
191
+ },
192
+ "onQuestion": {
193
+ "type": "string",
194
+ "pattern": "^#[0-9A-Fa-f]{6}$"
195
+ },
196
+ "resolved": {
197
+ "type": "string",
198
+ "pattern": "^#[0-9A-Fa-f]{6}$"
199
+ },
200
+ "onResolved": {
201
+ "type": "string",
202
+ "pattern": "^#[0-9A-Fa-f]{6}$"
203
+ },
204
+ "onImprove": {
205
+ "type": "string",
206
+ "pattern": "^#[0-9A-Fa-f]{6}$"
207
+ }
208
+ }
209
+ },
210
+ "light": {
211
+ "type": "object",
212
+ "additionalProperties": false,
213
+ "required": [
214
+ "background",
215
+ "chrome",
216
+ "panel",
217
+ "raised",
218
+ "stage",
219
+ "rule",
220
+ "text",
221
+ "textMuted",
222
+ "primary",
223
+ "primaryStrong",
224
+ "onPrimary",
225
+ "warning",
226
+ "danger",
227
+ "onDanger",
228
+ "question",
229
+ "onQuestion",
230
+ "resolved",
231
+ "onResolved",
232
+ "onImprove"
233
+ ],
234
+ "properties": {
235
+ "background": {
236
+ "type": "string",
237
+ "pattern": "^#[0-9A-Fa-f]{6}$"
238
+ },
239
+ "chrome": {
240
+ "type": "string",
241
+ "pattern": "^#[0-9A-Fa-f]{6}$"
242
+ },
243
+ "panel": {
244
+ "type": "string",
245
+ "pattern": "^#[0-9A-Fa-f]{6}$"
246
+ },
247
+ "raised": {
248
+ "type": "string",
249
+ "pattern": "^#[0-9A-Fa-f]{6}$"
250
+ },
251
+ "stage": {
252
+ "type": "string",
253
+ "pattern": "^#[0-9A-Fa-f]{6}$"
254
+ },
255
+ "rule": {
256
+ "type": "string",
257
+ "pattern": "^#[0-9A-Fa-f]{6}$"
258
+ },
259
+ "text": {
260
+ "type": "string",
261
+ "pattern": "^#[0-9A-Fa-f]{6}$"
262
+ },
263
+ "textMuted": {
264
+ "type": "string",
265
+ "pattern": "^#[0-9A-Fa-f]{6}$"
266
+ },
267
+ "primary": {
268
+ "type": "string",
269
+ "pattern": "^#[0-9A-Fa-f]{6}$"
270
+ },
271
+ "primaryStrong": {
272
+ "type": "string",
273
+ "pattern": "^#[0-9A-Fa-f]{6}$"
274
+ },
275
+ "onPrimary": {
276
+ "type": "string",
277
+ "pattern": "^#[0-9A-Fa-f]{6}$"
278
+ },
279
+ "warning": {
280
+ "type": "string",
281
+ "pattern": "^#[0-9A-Fa-f]{6}$"
282
+ },
283
+ "danger": {
284
+ "type": "string",
285
+ "pattern": "^#[0-9A-Fa-f]{6}$"
286
+ },
287
+ "onDanger": {
288
+ "type": "string",
289
+ "pattern": "^#[0-9A-Fa-f]{6}$"
290
+ },
291
+ "question": {
292
+ "type": "string",
293
+ "pattern": "^#[0-9A-Fa-f]{6}$"
294
+ },
295
+ "onQuestion": {
296
+ "type": "string",
297
+ "pattern": "^#[0-9A-Fa-f]{6}$"
298
+ },
299
+ "resolved": {
300
+ "type": "string",
301
+ "pattern": "^#[0-9A-Fa-f]{6}$"
302
+ },
303
+ "onResolved": {
304
+ "type": "string",
305
+ "pattern": "^#[0-9A-Fa-f]{6}$"
306
+ },
307
+ "onImprove": {
308
+ "type": "string",
309
+ "pattern": "^#[0-9A-Fa-f]{6}$"
310
+ }
311
+ }
312
+ }
313
+ }
314
+ }
315
+ }
316
+ }
@@ -5,3 +5,6 @@ export declare function withDocumentDigest<T extends Record<string, unknown>>(
5
5
  value: T,
6
6
  ): T & { documentDigest: `sha256:${string}` };
7
7
  export declare function verifyDocumentDigest(value: unknown): boolean;
8
+ /** Already-frozen objects are not descended into, and a cyclic value overflows the stack. */
9
+ export declare function deepFreeze<T>(value: T): T;
10
+ export declare function assertPlainData(value: unknown, label: string): void;
@@ -1,5 +1,5 @@
1
1
  // @ts-check
2
- const hasOwn = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
2
+ const hasOwn = (value, key) => Object.hasOwn(value, key);
3
3
 
4
4
  function assertUnicodeScalarString(value, path) {
5
5
  for (let index = 0; index < value.length; index += 1) {
@@ -65,7 +65,7 @@ export function canonicalizeJson(value) {
65
65
  return serialize(value, '$', new Set());
66
66
  }
67
67
 
68
- const SHA256_K = new Uint32Array([
68
+ const SHA256_K = /* @__PURE__ */ new Uint32Array([
69
69
  0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
70
70
  0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
71
71
  0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
@@ -177,3 +177,44 @@ export function verifyDocumentDigest(value) {
177
177
  delete copy.documentDigest;
178
178
  return actual === sha256Jcs(copy);
179
179
  }
180
+
181
+ /**
182
+ * Freeze a value and every nested object reached through an unfrozen parent.
183
+ * @type {typeof import('./canonical-json.d.mts').deepFreeze}
184
+ */
185
+ export function deepFreeze(value) {
186
+ if (value && typeof value === 'object' && !Object.isFrozen(value)) {
187
+ for (const nested of Object.values(value)) deepFreeze(nested);
188
+ Object.freeze(value);
189
+ }
190
+ return value;
191
+ }
192
+
193
+ function assertPlainDataAt(value, label, depth, seen) {
194
+ if (depth > 64) throw new TypeError(`${label} exceeds the maximum nesting depth.`);
195
+ if (value === null || ['string', 'boolean'].includes(typeof value)) return;
196
+ if (typeof value === 'number' && Number.isFinite(value)) return;
197
+ if (typeof value !== 'object' || seen.has(value))
198
+ throw new TypeError(`${label} must be finite, acyclic JSON.`);
199
+ if (!Array.isArray(value) && ![Object.prototype, null].includes(Object.getPrototypeOf(value)))
200
+ throw new TypeError(`${label} must contain only plain JSON objects.`);
201
+ seen.add(value);
202
+ for (const [key, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(value))) {
203
+ if (
204
+ ['__proto__', 'prototype', 'constructor'].includes(key) ||
205
+ !Object.hasOwn(descriptor, 'value')
206
+ )
207
+ throw new TypeError(`${label} contains a forbidden property.`);
208
+ assertPlainDataAt(descriptor.value, label, depth + 1, seen);
209
+ }
210
+ seen.delete(value);
211
+ }
212
+
213
+ /**
214
+ * Throw a TypeError whose message starts with `label` unless the value is finite, acyclic,
215
+ * plain JSON data made of data properties and nested at most 64 levels deep.
216
+ * @type {typeof import('./canonical-json.d.mts').assertPlainData}
217
+ */
218
+ export function assertPlainData(value, label) {
219
+ assertPlainDataAt(value, label, 0, new Set());
220
+ }
@@ -1,3 +1,10 @@
1
+ /**
2
+ * Live-evidence contracts: validates provider registrations, consent, ingestion and its accepted
3
+ * Artifact bridge, reduces connector checkpoints and measurement schedules, and evaluates Outcomes.
4
+ * Entry points: `assertOperatingLiveEvidenceIngestionV2`, `assertAcceptedLiveEvidenceBridgeV2`,
5
+ * `reduceOperatingConnectorCheckpointV2`, `reduceOperatingMeasurementScheduleV2`.
6
+ */
7
+
1
8
  import { sha256Jcs } from '../canonical-json.mjs';
2
9
  import { assertProtocolArtifact } from '../contracts.mjs';
3
10
 
package/src/contracts.mjs CHANGED
@@ -1,7 +1,17 @@
1
1
  // @ts-check
2
+ /**
3
+ * Protocol artifact schema registry and validation: resolves each kind and version to its packaged
4
+ * JSON Schema, validates artifacts against it with references confined to `schemas/`, and exports
5
+ * the Operate 2.0 vocabularies compiled from the contract catalog, which it checks on load.
6
+ * Entry points: `validateProtocolArtifact`, `assertProtocolArtifact`, `resolveProtocolSchema`,
7
+ * `listProtocolSchemas`, `PROTOCOL_SCHEMA_REGISTRY`. The schema evaluator is `json-schema.mjs`;
8
+ * 1.13.0 diagram authoring kinds are validated by `diagram-authoring-contracts.mjs`.
9
+ */
10
+
2
11
  import { readFileSync } from 'node:fs';
3
12
  import { dirname, join, relative, resolve, sep } from 'node:path';
4
13
  import { fileURLToPath } from 'node:url';
14
+ import { deepFreeze } from './canonical-json.mjs';
5
15
  import { DESIGN_HANDOFF_CONTRACT_FILES } from './design-handoff-contracts.mjs';
6
16
  import {
7
17
  DIAGRAM_AUTHORING_CONTRACT_FILES,
@@ -932,14 +942,6 @@ export function assertOperateIntelligencePlanContractV2(value) {
932
942
  const schemaCache = new Map();
933
943
  const canonicalSchemaPrefix = 'https://openplanr.dev/';
934
944
 
935
- function deepFreeze(value) {
936
- if (value && typeof value === 'object' && !Object.isFrozen(value)) {
937
- for (const nested of Object.values(value)) deepFreeze(nested);
938
- Object.freeze(value);
939
- }
940
- return value;
941
- }
942
-
943
945
  // Validation reads the cached schema in place, so the cache must be immutable.
944
946
  function loadSchema(path) {
945
947
  if (!schemaCache.has(path)) {
@@ -1,5 +1,5 @@
1
1
  // @ts-check
2
- import { canonicalizeJson, sha256Hex } from './canonical-json.mjs';
2
+ import { assertPlainData, canonicalizeJson, deepFreeze, sha256Hex } from './canonical-json.mjs';
3
3
  import { validateJson } from './json-schema.mjs';
4
4
 
5
5
  /** @type {typeof import('./design-handoff-contracts.d.mts').DESIGN_HANDOFF_PROTOCOL_VERSION} */
@@ -272,34 +272,6 @@ export const DESIGN_HANDOFF_SCHEMAS = deepFreeze({
272
272
  'design-planning-lineage': DESIGN_PLANNING_LINEAGE_SCHEMA,
273
273
  });
274
274
 
275
- function deepFreeze(value) {
276
- if (value && typeof value === 'object' && !Object.isFrozen(value)) {
277
- for (const nested of Object.values(value)) deepFreeze(nested);
278
- Object.freeze(value);
279
- }
280
- return value;
281
- }
282
-
283
- function assertPlainData(value, depth = 0, seen = new Set()) {
284
- if (depth > 64) throw new TypeError('Design handoff data exceeds the maximum nesting depth.');
285
- if (value === null || ['string', 'boolean'].includes(typeof value)) return;
286
- if (typeof value === 'number' && Number.isFinite(value)) return;
287
- if (typeof value !== 'object' || seen.has(value))
288
- throw new TypeError('Design handoff data must be finite, acyclic JSON.');
289
- if (!Array.isArray(value) && ![Object.prototype, null].includes(Object.getPrototypeOf(value)))
290
- throw new TypeError('Design handoff data must contain only plain JSON objects.');
291
- seen.add(value);
292
- for (const [key, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(value))) {
293
- if (
294
- ['__proto__', 'prototype', 'constructor'].includes(key) ||
295
- !Object.hasOwn(descriptor, 'value')
296
- )
297
- throw new TypeError('Design handoff data contains a forbidden property.');
298
- assertPlainData(descriptor.value, depth + 1, seen);
299
- }
300
- seen.delete(value);
301
- }
302
-
303
275
  function distinct(items, select, label) {
304
276
  const values = items.map(select);
305
277
  if (new Set(values).size !== values.length) throw new TypeError(`Duplicate ${label}.`);
@@ -329,7 +301,7 @@ export function assertDesignHandoffContract(value, schemaOrName) {
329
301
  const schema =
330
302
  typeof schemaOrName === 'string' ? DESIGN_HANDOFF_SCHEMAS[schemaOrName] : schemaOrName;
331
303
  if (!schema) throw new TypeError('Unknown design handoff contract.');
332
- assertPlainData(value);
304
+ assertPlainData(value, 'Design handoff data');
333
305
  canonicalizeJson(value);
334
306
  const errors = validateJson(value, schema);
335
307
  if (errors.length)
@@ -1,9 +1,21 @@
1
1
  // @ts-check
2
- import { canonicalizeJson, sha256Hex, sha256Jcs } from './canonical-json.mjs';
2
+ /**
3
+ * Diagram authoring contracts (Protocol 1.13.0): closed schemas for documents, presentations,
4
+ * bundles, edit transactions, source maps, fidelity reports, manifests, proposals and publication
5
+ * state, with accessor-safe inspection, digests, cross-reference checks and the capability catalog.
6
+ * Entry points: `validateDiagramAuthoringArtifact`, `assertDiagramAuthoringArtifact`,
7
+ * `DIAGRAM_AUTHORING_CAPABILITIES`, `inspectLegacyDiagramDocument`. Applying edits and rendering
8
+ * belong to the artifact package's `diagram/authoring` modules.
9
+ */
10
+
11
+ import { canonicalizeJson, deepFreeze, sha256Hex, sha256Jcs } from './canonical-json.mjs';
3
12
  import { DIAGRAM_REGISTRIES } from './generated/diagram-registries.mjs';
4
13
  import { LEGACY_DIAGRAM_DOCUMENT_SCHEMA } from './generated/legacy-diagram-schema.mjs';
5
14
  import { validateJson } from './json-schema.mjs';
6
15
 
16
+ /** @typedef {import('./diagram-authoring-contracts.d.mts').DiagramAuthoringCapability} DiagramAuthoringCapability */
17
+ /** @typedef {import('./diagram-authoring-contracts.d.mts').DiagramAuthoringContractKind} DiagramAuthoringContractKind */
18
+
7
19
  /**
8
20
  * Portable, inert data contracts. Validation confers no authorization or readiness.
9
21
  * @type {typeof import('./diagram-authoring-contracts.d.mts').DIAGRAM_AUTHORING_PROTOCOL_VERSION}
@@ -11,13 +23,6 @@ import { validateJson } from './json-schema.mjs';
11
23
  export const DIAGRAM_AUTHORING_PROTOCOL_VERSION = '1.13.0';
12
24
  /** @type {typeof import('./diagram-authoring-contracts.d.mts').DIAGRAM_AUTHORING_CONTRACT_VERSION} */
13
25
  export const DIAGRAM_AUTHORING_CONTRACT_VERSION = '1.0.0';
14
- const deepFreeze = (value) => {
15
- if (value && typeof value === 'object' && !Object.isFrozen(value)) {
16
- Object.values(value).forEach(deepFreeze);
17
- Object.freeze(value);
18
- }
19
- return value;
20
- };
21
26
  /** @type {typeof import('./diagram-authoring-contracts.d.mts').DIAGRAM_EDIT_OPERATION_CLASSES} */
22
27
  export const DIAGRAM_EDIT_OPERATION_CLASSES = deepFreeze([
23
28
  'insert-elements',
@@ -467,7 +472,9 @@ const schemas = {
467
472
  export const DIAGRAM_AUTHORING_SCHEMAS = deepFreeze(schemas);
468
473
  /** @type {typeof import('./diagram-authoring-contracts.d.mts').DIAGRAM_AUTHORING_CONTRACT_FILES} */
469
474
  export const DIAGRAM_AUTHORING_CONTRACT_FILES = deepFreeze(
470
- Object.fromEntries(Object.keys(schemas).map((name) => [name, `${name}.schema.json`])),
475
+ /** @type {Record<DiagramAuthoringContractKind, string>} */ (
476
+ Object.fromEntries(Object.keys(schemas).map((name) => [name, `${name}.schema.json`]))
477
+ ),
471
478
  );
472
479
  const mermaidConstructs = [
473
480
  [
@@ -597,27 +604,29 @@ export const DIAGRAM_AUTHORING_CAPABILITIES = deepFreeze({
597
604
  protocolVersion: '1.13.0',
598
605
  version: '1.0.0',
599
606
  liveCollaboration: false,
600
- profiles: profileIds.map((grammarId) => ({
601
- grammarId,
602
- authoring: true,
603
- primitives: [
604
- 'node',
605
- 'relation',
606
- 'group',
607
- ...(grammarId === 'process' || grammarId === 'swimlane' ? ['lane'] : []),
608
- 'annotation',
609
- 'emphasis',
610
- ],
611
- nodeKinds: [...semanticKinds],
612
- relationKinds: [...relationKinds],
613
- operations: [...DIAGRAM_EDIT_OPERATION_CLASSES],
614
- mermaid: {
615
- mode: 'copy',
616
- certificationVersion: 'flowchart-copy-v1',
617
- constructs: mermaidConstructs.map((entry) => ({ ...entry })),
618
- linkedSource: false,
619
- },
620
- })),
607
+ profiles: /** @type {DiagramAuthoringCapability[]} */ (
608
+ profileIds.map((grammarId) => ({
609
+ grammarId,
610
+ authoring: true,
611
+ primitives: [
612
+ 'node',
613
+ 'relation',
614
+ 'group',
615
+ ...(grammarId === 'process' || grammarId === 'swimlane' ? ['lane'] : []),
616
+ 'annotation',
617
+ 'emphasis',
618
+ ],
619
+ nodeKinds: [...semanticKinds],
620
+ relationKinds: [...relationKinds],
621
+ operations: [...DIAGRAM_EDIT_OPERATION_CLASSES],
622
+ mermaid: {
623
+ mode: 'copy',
624
+ certificationVersion: 'flowchart-copy-v1',
625
+ constructs: mermaidConstructs.map((entry) => ({ ...entry })),
626
+ linkedSource: false,
627
+ },
628
+ }))
629
+ ),
621
630
  unsupportedGrammars: DIAGRAM_REGISTRIES['diagram-grammars.json'].grammars
622
631
  .map((entry) => entry.grammarId)
623
632
  .filter((value) => !profileIds.includes(value)),
@@ -1,5 +1,14 @@
1
1
  // @ts-check
2
- import { canonicalizeJson, sha256Hex } from './canonical-json.mjs';
2
+ /**
3
+ * Enterprise collaboration contracts (Protocol 1.12.0): closed schemas and validators for access
4
+ * context, revisions, review threads, change proposals, evidence, sync state and agent handoffs,
5
+ * plus a fail-closed access policy, escaped handoff Markdown and semantic document diffs.
6
+ * Entry points: `assertEnterpriseContract`, `authorizeEnterpriseAccess`, `createEnterpriseHandoff`,
7
+ * `diffEnterpriseDocuments`, `applyEnterpriseOperations`. Identity verification, current grants
8
+ * and atomic revision writes belong to the caller's storage adapter.
9
+ */
10
+
11
+ import { canonicalizeJson, deepFreeze, sha256Hex } from './canonical-json.mjs';
3
12
  import { validateJson } from './json-schema.mjs';
4
13
 
5
14
  /** @type {typeof import('./enterprise-contracts.d.mts').ENTERPRISE_CONTRACT_VERSION} */
@@ -372,14 +381,6 @@ export const ENTERPRISE_SCHEMAS = deepFreeze({
372
381
  'enterprise-agent-handoff': ENTERPRISE_AGENT_HANDOFF_SCHEMA,
373
382
  });
374
383
 
375
- function deepFreeze(value) {
376
- if (value && typeof value === 'object' && !Object.isFrozen(value)) {
377
- for (const nested of Object.values(value)) deepFreeze(nested);
378
- Object.freeze(value);
379
- }
380
- return value;
381
- }
382
-
383
384
  const unsafeKeys = new Set(['__proto__', 'prototype', 'constructor']);
384
385
  function assertPlainData(value, depth = 0, seen = new Set()) {
385
386
  if (depth > 64) throw new TypeError('Enterprise data exceeds the maximum nesting depth.');
@@ -624,6 +625,7 @@ const noCapabilities = Object.freeze([]);
624
625
  export function enterpriseProjectCapabilities(role) {
625
626
  return projectCapabilities[role] ?? noCapabilities;
626
627
  }
628
+ /** @type {Readonly<Record<'owner' | 'admin' | 'member', readonly import('./enterprise-contracts.d.mts').EnterpriseAction[]>>} */
627
629
  const organizationCapabilities = deepFreeze({
628
630
  owner: [
629
631
  'organization.manage',