@openplanr/protocol 0.7.3 → 0.9.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.
Files changed (77) hide show
  1. package/README.md +22 -0
  2. package/package.json +21 -1
  3. package/registries/commands.json +11 -11
  4. package/registries/skills.json +89 -11
  5. package/registry/v1.17.0/commands.json +88 -0
  6. package/schemas/v1.15.0/diagram-review-bundle.schema.json +1280 -0
  7. package/schemas/v1.15.0/diagram-review-feedback.schema.json +157 -0
  8. package/schemas/v1.15.0/diagram-review-workspace.schema.json +108 -0
  9. package/schemas/v1.15.0/diagram-workspace-create.schema.json +170 -0
  10. package/schemas/v1.15.0/diagram-workspace-event.schema.json +97 -0
  11. package/schemas/v1.15.0/diagram-workspace-revision.schema.json +56 -0
  12. package/schemas/v1.16.0/artifact-envelope.schema.json +408 -0
  13. package/schemas/v1.16.0/design-review-bundle.schema.json +590 -0
  14. package/schemas/v1.17.0/artifact-paste-v2.schema.json +52 -0
  15. package/schemas/v1.17.0/artifact-room-append-v3.schema.json +159 -0
  16. package/schemas/v1.17.0/artifact-room-create-v3.schema.json +111 -0
  17. package/schemas/v1.17.0/artifact-room-descriptor-v3.schema.json +92 -0
  18. package/schemas/v1.17.0/artifact-room-event-v3.schema.json +130 -0
  19. package/schemas/v1.17.0/artifact-room-management-v3.schema.json +47 -0
  20. package/schemas/v1.17.0/artifact-room-read-page-v3.schema.json +308 -0
  21. package/schemas/v1.17.0/company-resource-manifest.schema.json +128 -0
  22. package/schemas/v1.17.0/company-resource-upload-prepare.schema.json +164 -0
  23. package/schemas/v1.17.0/company-resource-upload-receipt.schema.json +63 -0
  24. package/schemas/v1.17.0/company-resource-upload-status.schema.json +123 -0
  25. package/schemas/v1.17.0/diagram-authoring-bundle.schema.json +1117 -0
  26. package/schemas/v1.17.0/diagram-edit-transaction.schema.json +3295 -0
  27. package/schemas/v1.17.0/diagram-presentation.schema.json +37 -0
  28. package/schemas/v1.17.0/diagram-review-bundle.schema.json +2439 -0
  29. package/schemas/v1.17.0/encrypted-resource-manifest.schema.json +131 -0
  30. package/schemas/v1.17.0/encrypted-upload-commit.schema.json +38 -0
  31. package/schemas/v1.17.0/encrypted-upload-prepare.schema.json +234 -0
  32. package/schemas/v1.17.0/encrypted-upload-receipt.schema.json +54 -0
  33. package/schemas/v1.17.0/encrypted-upload-status.schema.json +129 -0
  34. package/schemas/v1.17.0/encrypted-workspace-event-v2.schema.json +79 -0
  35. package/schemas/v1.17.0/encrypted-workspace-v2.schema.json +91 -0
  36. package/schemas/v1.17.0/enterprise-agent-handoff.schema.json +985 -0
  37. package/schemas/v1.17.0/enterprise-artifact-revision.schema.json +115 -0
  38. package/schemas/v1.17.0/enterprise-change-proposal.schema.json +379 -0
  39. package/schemas/v1.17.0/enterprise-evidence-reference.schema.json +159 -0
  40. package/schemas/v1.17.0/enterprise-review-thread.schema.json +298 -0
  41. package/schemas/v1.17.0/enterprise-sync-state.schema.json +189 -0
  42. package/schemas/v1.17.0/preview-bridge-message.schema.json +197 -0
  43. package/schemas/v1.17.0/resource-catalog.schema.json +145 -0
  44. package/schemas/v1.17.0/sharing-crypto-aad.schema.json +36 -0
  45. package/schemas/v1.17.0/workspace-management-v2.schema.json +45 -0
  46. package/schemas/v1.17.0/workspace-rotation-v2.schema.json +61 -0
  47. package/src/bounded-json-data.d.mts +2 -0
  48. package/src/bounded-json-data.mjs +56 -0
  49. package/src/browser-contracts.d.mts +23 -1
  50. package/src/browser-contracts.mjs +52 -0
  51. package/src/canonical-json.mjs +17 -16
  52. package/src/contracts.d.mts +1 -0
  53. package/src/contracts.mjs +106 -5
  54. package/src/diagram-authoring-contracts.d.mts +12 -0
  55. package/src/diagram-authoring-contracts.mjs +174 -1
  56. package/src/diagram-review-contracts.d.mts +73 -0
  57. package/src/diagram-review-contracts.mjs +250 -0
  58. package/src/enterprise-contract-validation.d.mts +44 -0
  59. package/src/enterprise-contract-validation.mjs +279 -0
  60. package/src/enterprise-contracts.mjs +25 -231
  61. package/src/enterprise-resource-contracts.d.mts +72 -0
  62. package/src/enterprise-resource-contracts.mjs +202 -0
  63. package/src/generated/artifact-envelope-metadata.mjs +769 -0
  64. package/src/generated/canonical-registries.mjs +100 -22
  65. package/src/index.d.mts +22 -0
  66. package/src/index.mjs +26 -0
  67. package/src/large-object-contracts.d.mts +107 -0
  68. package/src/large-object-contracts.mjs +473 -0
  69. package/src/large-object-limits.d.mts +16 -0
  70. package/src/large-object-limits.mjs +17 -0
  71. package/src/registries.mjs +1 -0
  72. package/src/review-experience-contracts.d.mts +1 -0
  73. package/src/review-experience-contracts.mjs +25 -4
  74. package/src/sharing-security-contracts.d.mts +63 -0
  75. package/src/sharing-security-contracts.mjs +403 -0
  76. package/src/studio-presentation-contracts.d.mts +92 -0
  77. package/src/studio-presentation-contracts.mjs +287 -0
package/src/contracts.mjs CHANGED
@@ -11,9 +11,11 @@
11
11
  import { readFileSync } from 'node:fs';
12
12
  import { dirname, join, relative, resolve, sep } from 'node:path';
13
13
  import { fileURLToPath } from 'node:url';
14
+ import { PROTOCOL_V115_CONTRACTS, validateDiagramReviewArtifact } from './browser-contracts.mjs';
14
15
  import { deepFreeze } from './canonical-json.mjs';
15
16
  import { DESIGN_HANDOFF_CONTRACT_FILES } from './design-handoff-contracts.mjs';
16
17
  import {
18
+ assertDiagramData,
17
19
  DIAGRAM_AUTHORING_CONTRACT_FILES,
18
20
  validateDiagramAuthoringArtifact,
19
21
  } from './diagram-authoring-contracts.mjs';
@@ -21,11 +23,26 @@ import { ENTERPRISE_SCHEMAS } from './enterprise-contracts.mjs';
21
23
  import { PipelineError } from './errors.mjs';
22
24
  import { OPERATE_CONTRACT_CATALOG_V2 } from './generated/contract-catalog-v2.mjs';
23
25
  import { validateJson } from './json-schema.mjs';
26
+ import {
27
+ assertLargeObjectContract,
28
+ assertLargeObjectData,
29
+ LARGE_OBJECT_SCHEMAS,
30
+ } from './large-object-contracts.mjs';
31
+ import {
32
+ assertSharingSecurityContract,
33
+ SHARING_SECURITY_SCHEMAS,
34
+ } from './sharing-security-contracts.mjs';
24
35
  import {
25
36
  PROTOCOL_V16_CONTRACT_FILES,
26
37
  PROTOCOL_V17_CONTRACT_FILES,
27
38
  PROTOCOL_V18_CONTRACT_FILES,
28
39
  } from './skill-source-contracts.mjs';
40
+ import {
41
+ assertDiagramPresentation,
42
+ assertDiagramReviewBundleV11,
43
+ assertVersionedDiagramAuthoringBundle,
44
+ assertVersionedDiagramEditTransaction,
45
+ } from './studio-presentation-contracts.mjs';
29
46
 
30
47
  const packageRoot = join(dirname(fileURLToPath(import.meta.url)), '..');
31
48
 
@@ -36,10 +53,21 @@ const v17Schema = (kind) => `schemas/v1.7.0/${PROTOCOL_V17_CONTRACT_FILES[kind]}
36
53
  const v18Schema = (kind) => `schemas/v1.8.0/${PROTOCOL_V18_CONTRACT_FILES[kind]}`;
37
54
 
38
55
  const foundationPaths = {
56
+ ...Object.fromEntries(
57
+ Object.keys(LARGE_OBJECT_SCHEMAS).map((name) => [
58
+ name,
59
+ { '1.17.0': `schemas/v1.17.0/${name}.schema.json` },
60
+ ]),
61
+ ),
39
62
  ...Object.fromEntries(
40
63
  Object.keys(ENTERPRISE_SCHEMAS).map((name) => [
41
64
  name,
42
- { '1.12.0': `schemas/v1.12.0/${name}.schema.json` },
65
+ {
66
+ ...(Object.hasOwn(LARGE_OBJECT_SCHEMAS, name)
67
+ ? { '1.17.0': `schemas/v1.17.0/${name}.schema.json` }
68
+ : {}),
69
+ '1.12.0': `schemas/v1.12.0/${name}.schema.json`,
70
+ },
43
71
  ]),
44
72
  ),
45
73
  'design-document': { '1.9.0': 'schemas/v1.9.0/design-document.schema.json' },
@@ -50,6 +78,7 @@ const foundationPaths = {
50
78
  'design-review-bundle': {
51
79
  '1.9.0': 'schemas/v1.9.0/design-review-bundle.schema.json',
52
80
  '1.10.0': 'schemas/v1.10.0/design-review-bundle.schema.json',
81
+ '1.16.0': 'schemas/v1.16.0/design-review-bundle.schema.json',
53
82
  },
54
83
  'design-review-context': { '1.10.0': 'schemas/v1.10.0/design-review-context.schema.json' },
55
84
  'design-review-handoff': { '1.10.0': 'schemas/v1.10.0/design-review-handoff.schema.json' },
@@ -110,7 +139,10 @@ const foundationPaths = {
110
139
  '1.3.0': 'schemas/v1.3.0/release-compatibility-claim.schema.json',
111
140
  },
112
141
  'release-ledger-receipt': { '1.3.0': 'schemas/v1.3.0/release-ledger-receipt.schema.json' },
113
- 'artifact-envelope': { '1.1.0': 'schemas/v1.1.0/artifact-envelope.schema.json' },
142
+ 'artifact-envelope': {
143
+ '1.1.0': 'schemas/v1.1.0/artifact-envelope.schema.json',
144
+ '1.16.0': 'schemas/v1.16.0/artifact-envelope.schema.json',
145
+ },
114
146
  'artifact-review': { '1.1.0': 'schemas/v1.1.0/artifact-review.schema.json' },
115
147
  'artifact-paste': { '1.1.0': 'schemas/v1.1.0/artifact-paste.schema.json' },
116
148
  'artifact-room-event': { '1.1.0': 'schemas/v1.1.0/artifact-room-event.schema.json' },
@@ -233,6 +265,10 @@ for (const [kind, filename] of Object.entries(DIAGRAM_AUTHORING_CONTRACT_FILES))
233
265
  foundationPaths[kind] = { ...foundationPaths[kind], '1.13.0': `schemas/v1.13.0/${filename}` };
234
266
  }
235
267
 
268
+ for (const [kind, filename] of Object.entries(PROTOCOL_V115_CONTRACTS)) {
269
+ foundationPaths[kind] = { ...foundationPaths[kind], '1.15.0': `schemas/v1.15.0/${filename}` };
270
+ }
271
+
236
272
  function compiledOperatePaths() {
237
273
  const catalog = OPERATE_CONTRACT_CATALOG_V2;
238
274
  if (
@@ -1193,6 +1229,17 @@ function guidedQuestionnaireCompatibilityErrors(value) {
1193
1229
 
1194
1230
  /** @type {typeof import('./contracts.d.mts').validateProtocolArtifact} */
1195
1231
  export function validateProtocolArtifact(kind, value, { protocolVersion } = {}) {
1232
+ const studioKind = Object.hasOwn(LARGE_OBJECT_SCHEMAS, kind);
1233
+ if (studioKind && protocolVersion === '1.17.0') {
1234
+ return validateStudioArtifact(kind, value, sharedProtocolSchema(kind, protocolVersion));
1235
+ }
1236
+ if (Object.hasOwn(PROTOCOL_V115_CONTRACTS, kind)) {
1237
+ // Review transport envelopes do not carry a Protocol version. Do not read
1238
+ // arbitrary input properties while selecting the dedicated safety preflight.
1239
+ const version = inferredVersion(kind, {}, protocolVersion);
1240
+ sharedProtocolSchema(kind, version);
1241
+ return validateDiagramReviewArtifact(kind, value, { protocolVersion: version });
1242
+ }
1196
1243
  const authoringKind = Object.hasOwn(DIAGRAM_AUTHORING_CONTRACT_FILES, kind);
1197
1244
  let versionInput = value;
1198
1245
  if (authoringKind && (!protocolVersion || protocolVersion === '1.13.0')) {
@@ -1210,16 +1257,70 @@ export function validateProtocolArtifact(kind, value, { protocolVersion } = {})
1210
1257
  if (descriptor && !Object.hasOwn(descriptor, 'value'))
1211
1258
  return validateDiagramAuthoringArtifact(kind, value);
1212
1259
  versionInput = { protocolVersion: descriptor?.value };
1260
+ } else if (studioKind && !protocolVersion) {
1261
+ // New resource envelopes may be hostile objects. Version inference must use
1262
+ // descriptors too; the bounded additive reader owns the safety diagnostic.
1263
+ let descriptor;
1264
+ try {
1265
+ descriptor =
1266
+ value !== null && typeof value === 'object'
1267
+ ? Object.getOwnPropertyDescriptor(value, 'protocolVersion')
1268
+ : undefined;
1269
+ } catch {
1270
+ return invalidStudioData();
1271
+ }
1272
+ if (descriptor && !Object.hasOwn(descriptor, 'value')) return invalidStudioData();
1273
+ versionInput = { protocolVersion: descriptor?.value };
1213
1274
  }
1214
1275
  const version = inferredVersion(kind, versionInput, protocolVersion);
1276
+ if (studioKind && version === '1.17.0') {
1277
+ return validateStudioArtifact(kind, value, sharedProtocolSchema(kind, version));
1278
+ }
1215
1279
  if (version === '1.13.0' && authoringKind) {
1216
1280
  return validateDiagramAuthoringArtifact(kind, value);
1217
1281
  }
1218
- const resolved = sharedProtocolSchema(kind, version);
1282
+ return validateGenericArtifact(kind, value, sharedProtocolSchema(kind, version));
1283
+ }
1284
+ function invalidStudioData() {
1285
+ return [
1286
+ { path: '$', rule: 'studio-protocol-contract', detail: 'Expected bounded inert JSON data.' },
1287
+ ];
1288
+ }
1289
+ function validateStudioArtifact(kind, value, resolved) {
1290
+ try {
1291
+ if (
1292
+ [
1293
+ 'diagram-authoring-bundle',
1294
+ 'diagram-edit-transaction',
1295
+ 'diagram-review-bundle',
1296
+ 'diagram-presentation',
1297
+ ].includes(kind)
1298
+ )
1299
+ assertDiagramData(value);
1300
+ else assertLargeObjectData(value);
1301
+ const errors = validateResolvedArtifact(value, resolved);
1302
+ if (errors.length) return errors;
1303
+ if (Object.hasOwn(SHARING_SECURITY_SCHEMAS, kind)) assertSharingSecurityContract(value, kind);
1304
+ else if (kind === 'diagram-authoring-bundle') assertVersionedDiagramAuthoringBundle(value);
1305
+ else if (kind === 'diagram-edit-transaction') assertVersionedDiagramEditTransaction(value);
1306
+ else if (kind === 'diagram-review-bundle') assertDiagramReviewBundleV11(value);
1307
+ else if (kind === 'diagram-presentation') assertDiagramPresentation(value);
1308
+ else assertLargeObjectContract(value, kind);
1309
+ return [];
1310
+ } catch (error) {
1311
+ return [
1312
+ {
1313
+ path: '$',
1314
+ rule: 'studio-protocol-contract',
1315
+ detail: error instanceof Error ? error.message : 'Invalid Studio contract data.',
1316
+ },
1317
+ ];
1318
+ }
1319
+ }
1320
+ function validateGenericArtifact(kind, value, resolved) {
1219
1321
  const errors = validateResolvedArtifact(value, resolved);
1220
- if (kind === 'guided-questionnaire' && version === '1.2.0') {
1322
+ if (kind === 'guided-questionnaire' && resolved.protocolVersion === '1.2.0')
1221
1323
  errors.push(...guidedQuestionnaireCompatibilityErrors(value));
1222
- }
1223
1324
  return errors;
1224
1325
  }
1225
1326
 
@@ -454,3 +454,15 @@ export declare function summarizeDiagramAuthoringContent(bundle: DiagramAuthorin
454
454
  hasVisibleContent: boolean;
455
455
  };
456
456
  export declare function inspectLegacyDiagramDocument(value: unknown): DiagramLegacyInspection;
457
+
458
+ /** Internal: detached and recursively frozen inert data, without a semantic validity claim. */
459
+ export declare function copyImmutableDiagramData<T>(value: T, previous?: T | null): T;
460
+ /** Inspect inert authoring data with the existing aggregate limits, without copying it. */
461
+ export declare function assertDiagramData<T>(value: T): T;
462
+
463
+ /** Internal: seals an inert draft into an immutable copy without claiming semantic validity. */
464
+ export declare function sealImmutableDiagramData<T>(value: T, previous?: T | null): T;
465
+
466
+ export function immutableDiagramDataUsage(
467
+ value: unknown,
468
+ ): { values: number; text: number; height: number } | null;
@@ -639,6 +639,11 @@ export function getDiagramAuthoringCapability(grammarId) {
639
639
  }
640
640
 
641
641
  const error = (path, rule, detail) => ({ path, rule, detail });
642
+ // Only this module's detached, recursively frozen copies carry inert-data provenance.
643
+ // A caller's Object.freeze() or claimed digest never enters either cache.
644
+ const immutableDataProofs = new WeakMap();
645
+ const immutableDigests = new WeakMap();
646
+ const immutableCanonical = new WeakMap();
642
647
  // Descriptors are inspected before values; neither validation nor hashing invokes accessors.
643
648
  function inspectData(value) {
644
649
  const issues = [];
@@ -673,6 +678,17 @@ function inspectData(value) {
673
678
  issues.push(error(path, 'plain-data', 'Only JSON data is accepted.'));
674
679
  return;
675
680
  }
681
+ const proof = immutableDataProofs.get(current);
682
+ if (
683
+ proof &&
684
+ count + proof.values - 1 <= DIAGRAM_AUTHORING_LIMITS.values &&
685
+ textSize + proof.text <= DIAGRAM_AUTHORING_LIMITS.textCodeUnits &&
686
+ depth + proof.height <= DIAGRAM_AUTHORING_LIMITS.depth
687
+ ) {
688
+ count += proof.values - 1;
689
+ textSize += proof.text;
690
+ return;
691
+ }
676
692
  const proto = Object.getPrototypeOf(current);
677
693
  if (
678
694
  Array.isArray(current)
@@ -734,17 +750,174 @@ function inspectData(value) {
734
750
  }
735
751
  return issues;
736
752
  }
753
+ /**
754
+ * Internal snapshot boundary. The copy is inspected completely before any proof is recorded.
755
+ * @param {unknown} value
756
+ * @param {import('./diagram-authoring-contracts.d.mts').DiagramAuthoringBundle | null} previous
757
+ */
758
+ export function copyImmutableDiagramData(value, previous = null) {
759
+ assertData(value);
760
+ const ancestors = new Set();
761
+ let copiedValues = 0;
762
+ function copyData(current, depth) {
763
+ if (++copiedValues > DIAGRAM_AUTHORING_LIMITS.values || depth > DIAGRAM_AUTHORING_LIMITS.depth)
764
+ throw new TypeError('Copy exceeds portable resource limits.');
765
+ if (!current || typeof current !== 'object') return current;
766
+ if (immutableDataProofs.has(current)) return current;
767
+ if (ancestors.has(current)) throw new TypeError('Cyclic copy is not accepted.');
768
+ ancestors.add(current);
769
+ const result = Array.isArray(current) ? [] : {};
770
+ const descriptors = Object.getOwnPropertyDescriptors(current);
771
+ for (const key of Reflect.ownKeys(descriptors)) {
772
+ const descriptor = descriptors[/** @type {string} */ (key)];
773
+ if (!Object.hasOwn(descriptor, 'value'))
774
+ throw new TypeError('Accessor copy is not accepted.');
775
+ if (Array.isArray(current) && key === 'length') {
776
+ result.length = descriptor.value;
777
+ continue;
778
+ }
779
+ Object.defineProperty(result, key, {
780
+ value: copyData(descriptor.value, depth + 1),
781
+ enumerable: descriptor.enumerable,
782
+ configurable: true,
783
+ writable: true,
784
+ });
785
+ }
786
+ ancestors.delete(current);
787
+ return result;
788
+ }
789
+ let copy = copyData(value, 0);
790
+ assertData(copy);
791
+ if (previous && immutableDataProofs.has(previous)) {
792
+ // Inspected descendants can stay shared; reuse must never mutate an owned frozen root.
793
+ if (immutableDataProofs.has(copy)) copy = Array.isArray(copy) ? [...copy] : { ...copy };
794
+ for (const field of ['document', 'originalSource', 'sourceMap'])
795
+ if (
796
+ copy[field] !== previous[field] &&
797
+ JSON.stringify(copy[field]) === JSON.stringify(previous[field])
798
+ )
799
+ copy[field] = previous[field];
800
+ if (copy.presentation?.elements && previous.presentation?.elements) {
801
+ const placements = new Map(
802
+ previous.presentation.elements.map((item) => [item.elementId, item]),
803
+ );
804
+ copy.presentation = {
805
+ ...copy.presentation,
806
+ elements: copy.presentation.elements.map((item) => {
807
+ const old = placements.get(item.elementId);
808
+ return old && (old === item || JSON.stringify(old) === JSON.stringify(item)) ? old : item;
809
+ }),
810
+ };
811
+ }
812
+ }
813
+ freezeImmutableOwnedData(copy);
814
+ return copy;
815
+ }
816
+ // Call only for values constructed here from inspected copies and immutable descendants.
817
+ function freezeImmutableOwnedData(current) {
818
+ if (!current || typeof current !== 'object')
819
+ return { values: 1, text: typeof current === 'string' ? current.length : 0, height: 0 };
820
+ const retained = immutableDataProofs.get(current);
821
+ if (retained) return retained;
822
+ const proof = { values: 1, text: 0, height: 0 };
823
+ for (const child of Object.values(current)) {
824
+ const part = freezeImmutableOwnedData(child);
825
+ proof.values += part.values;
826
+ proof.text += part.text;
827
+ proof.height = Math.max(proof.height, part.height + 1);
828
+ }
829
+ Object.freeze(current);
830
+ immutableDataProofs.set(current, proof);
831
+ return proof;
832
+ }
833
+ export function immutableDiagramDataUsage(value) {
834
+ const proof = value && typeof value === 'object' ? immutableDataProofs.get(value) : null;
835
+ return proof ? { ...proof } : null;
836
+ }
837
+ function rememberImmutableDigest(value, field, digest) {
838
+ immutableDigests.set(value, new Map([[field, digest]]));
839
+ return value;
840
+ }
841
+ /** Seal an inspected private draft. Every memoized hash was computed from these exact immutable bytes. */
842
+ export function sealImmutableDiagramData(value, previous = null) {
843
+ const draft = copyImmutableDiagramData(value, previous);
844
+ const semanticDigest = diagramDocumentDigest(draft.document);
845
+ const document =
846
+ draft.document.documentDigest === semanticDigest
847
+ ? draft.document
848
+ : rememberImmutableDigest(
849
+ { ...draft.document, documentDigest: semanticDigest },
850
+ 'documentDigest',
851
+ semanticDigest,
852
+ );
853
+ freezeImmutableOwnedData(document);
854
+ const sourceMap = draft.sourceMap ? { ...draft.sourceMap, semanticDigest } : null;
855
+ freezeImmutableOwnedData(sourceMap);
856
+ const presentationDraft = { ...draft.presentation, semanticDigest };
857
+ freezeImmutableOwnedData(presentationDraft);
858
+ const presentationDigest = diagramPresentationDigest(presentationDraft);
859
+ const presentation = rememberImmutableDigest(
860
+ { ...presentationDraft, presentationDigest },
861
+ 'presentationDigest',
862
+ presentationDigest,
863
+ );
864
+ freezeImmutableOwnedData(presentation);
865
+ const bundleDraft = { ...draft, document, presentation, sourceMap };
866
+ freezeImmutableOwnedData(bundleDraft);
867
+ const bundleDigest = diagramAuthoringBundleDigest(bundleDraft);
868
+ const bundle = rememberImmutableDigest(
869
+ { ...bundleDraft, bundleDigest },
870
+ 'bundleDigest',
871
+ bundleDigest,
872
+ );
873
+ freezeImmutableOwnedData(bundle);
874
+ return bundle;
875
+ }
737
876
  function assertData(value) {
738
877
  const issues = inspectData(value);
739
878
  if (issues.length) throw new TypeError(`${issues[0].path}: ${issues[0].rule}`);
740
879
  }
880
+ /** Inspect inert authoring data with the existing aggregate limits, without copying it.
881
+ * @type {typeof import('./diagram-authoring-contracts.d.mts').assertDiagramData}
882
+ */
883
+ export function assertDiagramData(value) {
884
+ assertData(value);
885
+ return value;
886
+ }
887
+ // Called only on private inspected immutable descendants plus the owned digest-exclusion root.
888
+ function canonicalImmutableData(value) {
889
+ if (!value || typeof value !== 'object') return canonicalizeJson(value);
890
+ const known = immutableDataProofs.has(value);
891
+ const cached = known ? immutableCanonical.get(value) : undefined;
892
+ if (cached !== undefined) return cached;
893
+ const text = Array.isArray(value)
894
+ ? '[' + value.map(canonicalImmutableData).join(',') + ']'
895
+ : '{' +
896
+ Object.keys(value)
897
+ .sort()
898
+ .map((key) => canonicalizeJson(key) + ':' + canonicalImmutableData(value[key]))
899
+ .join(',') +
900
+ '}';
901
+ // Bound per-record caching; do not retain another whole document/bundle string for each revision.
902
+ if (known && text.length <= 16384) immutableCanonical.set(value, text);
903
+ return text;
904
+ }
741
905
  function digestExcluding(value, field) {
906
+ const proof = value && typeof value === 'object' && immutableDataProofs.has(value);
907
+ const retained = proof ? immutableDigests.get(value)?.get(field) : undefined;
908
+ if (retained) return retained;
742
909
  assertData(value);
743
910
  if (!value || typeof value !== 'object' || Array.isArray(value))
744
911
  throw new TypeError('Digest input must be an object.');
745
912
  const input = { ...value };
746
913
  delete input[field];
747
- return sha256Jcs(input);
914
+ const digest = proof ? `sha256:${sha256Hex(canonicalImmutableData(input))}` : sha256Jcs(input);
915
+ if (proof) {
916
+ const cache = immutableDigests.get(value) ?? new Map();
917
+ cache.set(field, digest);
918
+ immutableDigests.set(value, cache);
919
+ }
920
+ return digest;
748
921
  }
749
922
  /** @type {typeof import('./diagram-authoring-contracts.d.mts').diagramDocumentDigest} */
750
923
  export const diagramDocumentDigest = (value) => digestExcluding(value, 'documentDigest');
@@ -0,0 +1,73 @@
1
+ import type { DiagramAuthoringBundle } from './diagram-authoring-contracts.mjs';
2
+ export interface DiagramReviewItem {
3
+ id: string;
4
+ label: string;
5
+ kind: string;
6
+ x: number;
7
+ y: number;
8
+ }
9
+ export interface DiagramReviewRelation {
10
+ id: string;
11
+ from: string;
12
+ to: string;
13
+ label: string;
14
+ kind: string;
15
+ }
16
+ export interface DiagramReviewBundle {
17
+ kind: 'openplanr-diagram-review-bundle';
18
+ schemaVersion: '1.0.0';
19
+ diagramId: string;
20
+ title: string;
21
+ source: { kind: 'manifest' | 'authoring'; digest: string };
22
+ rendering: { id: string; version: string; fontFamily: 'Inter' };
23
+ summary?: string;
24
+ grammar?: string;
25
+ colorScheme?: 'light' | 'dark';
26
+ scene: {
27
+ svg: string;
28
+ width: number;
29
+ height: number;
30
+ items: DiagramReviewItem[];
31
+ relations: DiagramReviewRelation[];
32
+ };
33
+ authored?: DiagramAuthoringBundle;
34
+ }
35
+ export interface DiagramReviewTarget {
36
+ elementId?: string;
37
+ x?: number;
38
+ y?: number;
39
+ }
40
+ interface FeedbackBase {
41
+ author: string;
42
+ reviewOf: string;
43
+ createdAt: string;
44
+ commentId: string;
45
+ }
46
+ export type DiagramReviewFeedback = FeedbackBase &
47
+ (
48
+ | { kind: 'comment'; body: string; target: DiagramReviewTarget }
49
+ | { kind: 'reply'; body: string; parentId: string }
50
+ | { kind: 'resolve'; resolved: boolean }
51
+ );
52
+ export declare const DIAGRAM_REVIEW_VERSION: '1.0.0';
53
+ export declare const DIAGRAM_WORKSPACE_VERSION: '1.0.0';
54
+ export declare const DIAGRAM_WORKSPACE_API: '/api/v1/diagram-workspaces';
55
+ export declare const DIAGRAM_WORKSPACE_MAX_BYTES: number;
56
+ export declare const DIAGRAM_WORKSPACE_MAX_EVENT_BYTES: number;
57
+ export declare const DIAGRAM_WORKSPACE_ID_PATTERN: string;
58
+ export declare const DIAGRAM_REVIEW_BUNDLE_SCHEMA: Readonly<Record<string, unknown>>;
59
+ export declare const DIAGRAM_REVIEW_FEEDBACK_SCHEMA: Readonly<Record<string, unknown>>;
60
+ export declare const DIAGRAM_WORKSPACE_SCHEMA: Readonly<Record<string, unknown>>;
61
+ export declare const DIAGRAM_WORKSPACE_CREATE_SCHEMA: Readonly<Record<string, unknown>>;
62
+ export declare const DIAGRAM_WORKSPACE_REVISION_SCHEMA: Readonly<Record<string, unknown>>;
63
+ export declare const DIAGRAM_WORKSPACE_EVENT_SCHEMA: Readonly<Record<string, unknown>>;
64
+ export declare const DIAGRAM_REVIEW_SCHEMAS: Readonly<
65
+ Record<string, Readonly<Record<string, unknown>>>
66
+ >;
67
+ export declare function assertDiagramReviewBundle(value: unknown): DiagramReviewBundle;
68
+ export declare function assertDiagramReviewFeedback(value: unknown): DiagramReviewFeedback;
69
+ export declare function diagramReviewBundleDigest(value: unknown): string;
70
+ export declare function assertDiagramWorkspaceContract<T>(
71
+ value: T,
72
+ schema: string | Readonly<Record<string, unknown>>,
73
+ ): T;