@openplanr/protocol 0.6.1 → 0.7.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 (58) hide show
  1. package/README.md +10 -0
  2. package/lib/dashboard/closed-json-contract.mjs +99 -109
  3. package/lib/dashboard/operate-experience-audit-display-contract.d.mts +128 -153
  4. package/lib/dashboard/operate-experience-audit-display-contract.mjs +530 -585
  5. package/lib/dashboard/operate-experience-display-contract.d.mts +415 -437
  6. package/lib/dashboard/operate-experience-display-contract.mjs +777 -831
  7. package/lib/dashboard/operate-experience-surface-contract.d.mts +143 -148
  8. package/lib/dashboard/operate-experience-surface-contract.mjs +72 -73
  9. package/lib/dashboard/operate-review-contract.d.mts +7 -14
  10. package/lib/dashboard/operate-review-contract.mjs +46 -42
  11. package/lib/dashboard/operate-review-display-workspace-contract.d.mts +2 -5
  12. package/lib/dashboard/operate-review-display-workspace-contract.mjs +158 -104
  13. package/lib/dashboard/operate-review-payload-safety.mjs +4 -2
  14. package/lib/dashboard/operate-review-workspace-projection-v2.d.mts +47 -33
  15. package/lib/protocol/index.d.ts +2647 -543
  16. package/package.json +1 -1
  17. package/registries/artifact-theme.json +64 -0
  18. package/registries/commands.json +40 -40
  19. package/registries/skills.json +5 -5
  20. package/schemas/v1.14.0/artifact-theme.schema.json +316 -0
  21. package/src/browser-contracts.d.mts +4 -1
  22. package/src/browser-contracts.mjs +16 -5
  23. package/src/canonical-json.d.mts +6 -1
  24. package/src/canonical-json.mjs +100 -22
  25. package/src/compat/live-evidence-v2.mjs +1611 -485
  26. package/src/compat/operate-experience-live-patch.mjs +67 -15
  27. package/src/compat/operating-planning-contracts.mjs +183 -51
  28. package/src/contracts.d.mts +54 -13
  29. package/src/contracts.mjs +635 -343
  30. package/src/design-contracts.mjs +58 -21
  31. package/src/design-handoff-contracts.d.mts +67 -11
  32. package/src/design-handoff-contracts.mjs +236 -119
  33. package/src/design-publication-contracts.mjs +98 -33
  34. package/src/diagram-authoring-contracts.d.mts +422 -78
  35. package/src/diagram-authoring-contracts.mjs +1715 -335
  36. package/src/diagram-contracts.d.mts +4 -1
  37. package/src/diagram-contracts.mjs +16 -4
  38. package/src/enterprise-contracts.d.mts +211 -46
  39. package/src/enterprise-contracts.mjs +738 -184
  40. package/src/errors.mjs +4 -0
  41. package/src/generated/canonical-registries.mjs +45 -45
  42. package/src/index.d.mts +8 -8
  43. package/src/index.mjs +36 -20
  44. package/src/json-schema.d.mts +21 -6
  45. package/src/json-schema.mjs +66 -18
  46. package/src/planning-contracts.d.mts +8 -2
  47. package/src/planning-contracts.mjs +33 -7
  48. package/src/registries.d.mts +11 -3
  49. package/src/registries.mjs +369 -87
  50. package/src/review-experience-contracts.d.mts +7 -2
  51. package/src/review-experience-contracts.mjs +198 -49
  52. package/src/semver.mjs +5 -1
  53. package/src/skill-source-contracts.d.mts +36 -16
  54. package/src/skill-source-contracts.mjs +25 -6
  55. package/src/task-contracts.d.mts +13 -3
  56. package/src/task-contracts.mjs +181 -40
  57. package/src/workspace-contracts.d.mts +38 -10
  58. package/src/workspace-contracts.mjs +147 -33
@@ -1,16 +1,24 @@
1
+ // @ts-check
1
2
  /** Company publication constraints over the existing, compatible review bundle. */
2
- import { assertDesignReviewBundle } from './review-experience-contracts.mjs';
3
+
3
4
  import { canonicalizeJson, sha256Hex } from './canonical-json.mjs';
5
+ import { assertDesignReviewBundle } from './review-experience-contracts.mjs';
4
6
 
7
+ /** @type {typeof import('./design-publication-contracts.d.mts').COMPANY_DESIGN_MAX_BYTES} */
5
8
  export const COMPANY_DESIGN_MAX_BYTES = 1024 * 1024;
9
+ /** @type {typeof import('./design-publication-contracts.d.mts').COMPANY_DESIGN_MAX_ENTRIES} */
6
10
  export const COMPANY_DESIGN_MAX_ENTRIES = 256;
7
- const fail = message => { throw new TypeError(`Invalid company design bundle: ${message}`); };
8
- const isRecord = value => value !== null && typeof value === 'object' && !Array.isArray(value);
11
+ const fail = (message) => {
12
+ throw new TypeError(`Invalid company design bundle: ${message}`);
13
+ };
14
+ const isRecord = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
9
15
  const closed = (value, keys, label) => {
10
- if (!isRecord(value) || Object.keys(value).some(key => !keys.includes(key))) fail(`${label} contains unsupported fields.`);
16
+ if (!isRecord(value) || Object.keys(value).some((key) => !keys.includes(key)))
17
+ fail(`${label} contains unsupported fields.`);
11
18
  };
12
19
  const boundedList = (value, max, label) => {
13
- if (!Array.isArray(value) || !value.length || value.length > max) fail(`${label} must contain 1–${max} items.`);
20
+ if (!Array.isArray(value) || !value.length || value.length > max)
21
+ fail(`${label} must contain 1–${max} items.`);
14
22
  };
15
23
  const identities = (items, label) => {
16
24
  const map = new Map();
@@ -21,20 +29,31 @@ const identities = (items, label) => {
21
29
  return map;
22
30
  };
23
31
 
24
- /** Pure browser/Worker-compatible validation; no artifact or design dependency. */
32
+ /**
33
+ * Pure browser/Worker-compatible validation; no artifact or design dependency.
34
+ * @returns {ReturnType<typeof import('./design-publication-contracts.d.mts').assertCompanyDesignBundle>}
35
+ */
25
36
  export function assertCompanyDesignBundle(value) {
26
37
  // Bound complexity before recursive schema validation/canonical serialization.
38
+ /** @type {Array<[unknown, number]>} */
27
39
  const pending = [[value, 0]];
28
40
  let nodes = 0;
29
- while (pending.length) {
30
- const [item, depth] = pending.pop();
41
+ for (let next = pending.pop(); next; next = pending.pop()) {
42
+ const [item, depth] = next;
31
43
  if (++nodes > 50000 || depth > 40) fail('document complexity exceeds the publication limit.');
32
- if (item && typeof item === 'object') for (const child of Object.values(item)) pending.push([child, depth + 1]);
44
+ if (item && typeof item === 'object')
45
+ for (const child of Object.values(item)) pending.push([child, depth + 1]);
33
46
  }
34
47
  let serialized;
35
- try { serialized = canonicalizeJson(value); } catch { fail('expected bounded JSON data.'); }
36
- if (new TextEncoder().encode(serialized).byteLength > COMPANY_DESIGN_MAX_BYTES) fail('publication exceeds 1 MiB.');
37
- if (value?.schemaVersion !== '1.1.0') fail('company publication requires review bundle version 1.1.0.');
48
+ try {
49
+ serialized = canonicalizeJson(value);
50
+ } catch {
51
+ fail('expected bounded JSON data.');
52
+ }
53
+ if (new TextEncoder().encode(serialized).byteLength > COMPANY_DESIGN_MAX_BYTES)
54
+ fail('publication exceeds 1 MiB.');
55
+ if (value?.schemaVersion !== '1.1.0')
56
+ fail('company publication requires review bundle version 1.1.0.');
38
57
  assertDesignReviewBundle(value);
39
58
  const { design, envelope, entries } = value;
40
59
  boundedList(design.screens, 64, 'screens');
@@ -44,42 +63,88 @@ export function assertCompanyDesignBundle(value) {
44
63
  const screens = identities(design.screens, 'screens');
45
64
  const frames = identities(design.frames, 'frames');
46
65
  const variants = identities(design.variants, 'variants');
47
- if (design.variants.some(variant => variant.status !== 'ready') || !variants.has(design.selectedVariant)) fail('selected and published variants must be ready.');
48
- if (design.screenOrder.length !== screens.size || design.screenOrder.some(id => !screens.has(id))) fail('screen order must identify every published screen.');
66
+ if (
67
+ design.variants.some((variant) => variant.status !== 'ready') ||
68
+ !variants.has(design.selectedVariant)
69
+ )
70
+ fail('selected and published variants must be ready.');
71
+ if (
72
+ design.screenOrder.length !== screens.size ||
73
+ design.screenOrder.some((id) => !screens.has(id))
74
+ )
75
+ fail('screen order must identify every published screen.');
49
76
  identities(design.flows ?? [], 'flows');
50
- for (const flow of design.flows ?? []) if (flow.screens.some(id => !screens.has(id))) fail('flow references an unknown screen.');
51
- if (screens.size * frames.size * variants.size !== entries.length) fail('entries must cover every screen, frame and ready variant.');
77
+ for (const flow of design.flows ?? [])
78
+ if (flow.screens.some((id) => !screens.has(id))) fail('flow references an unknown screen.');
79
+ if (screens.size * frames.size * variants.size !== entries.length)
80
+ fail('entries must cover every screen, frame and ready variant.');
52
81
  closed(envelope, ['schemaVersion', 'artifacts', 'viewer'], 'envelope');
53
82
  if (envelope.schemaVersion !== '1.0.0') fail('unsupported envelope version.');
54
83
  boundedList(envelope.artifacts, COMPANY_DESIGN_MAX_ENTRIES, 'artifacts');
55
84
  const artifacts = identities(envelope.artifacts, 'artifacts');
56
85
  if (artifacts.size !== entries.length) fail('entries and artifacts must correspond exactly.');
57
86
  for (const artifact of artifacts.values()) {
58
- closed(artifact, ['id', 'kind', 'title', 'html', 'sha256', 'viewport', 'colorScheme'], 'artifact');
59
- if (typeof artifact.id !== 'string' || !/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/u.test(artifact.id)) fail('artifact identity is invalid.');
60
- if (artifact.kind !== 'html' || typeof artifact.title !== 'string' || !artifact.title.trim() || artifact.title.length > 512 || typeof artifact.html !== 'string' || !artifact.html.trim()) fail('artifacts must be titled HTML screens.');
87
+ closed(
88
+ artifact,
89
+ ['id', 'kind', 'title', 'html', 'sha256', 'viewport', 'colorScheme'],
90
+ 'artifact',
91
+ );
92
+ if (typeof artifact.id !== 'string' || !/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/u.test(artifact.id))
93
+ fail('artifact identity is invalid.');
94
+ if (
95
+ artifact.kind !== 'html' ||
96
+ typeof artifact.title !== 'string' ||
97
+ !artifact.title.trim() ||
98
+ artifact.title.length > 512 ||
99
+ typeof artifact.html !== 'string' ||
100
+ !artifact.html.trim()
101
+ )
102
+ fail('artifacts must be titled HTML screens.');
61
103
  closed(artifact.viewport, ['width', 'height'], 'viewport');
62
- if (!['light', 'dark'].includes(artifact.colorScheme)) fail('artifact color scheme is invalid.');
63
- if (artifact.sha256 !== sha256Hex(artifact.html.replace(/^\uFEFF/u, '').replace(/\r\n?/gu, '\n'))) fail('artifact digest does not match its HTML.');
104
+ if (!['light', 'dark'].includes(artifact.colorScheme))
105
+ fail('artifact color scheme is invalid.');
106
+ if (
107
+ artifact.sha256 !== sha256Hex(artifact.html.replace(/^\uFEFF/u, '').replace(/\r\n?/gu, '\n'))
108
+ )
109
+ fail('artifact digest does not match its HTML.');
64
110
  }
65
- const usedArtifacts = new Set(), combinations = new Set();
111
+ const usedArtifacts = new Set(),
112
+ combinations = new Set();
66
113
  for (const entry of entries) {
67
- const artifact = artifacts.get(entry.artifactId), frame = frames.get(entry.frameId);
68
- if (!artifact || !frame || !screens.has(entry.screenId) || !variants.has(entry.variantId)) fail('entry references an unknown screen, variant, frame or artifact.');
114
+ const artifact = artifacts.get(entry.artifactId),
115
+ frame = frames.get(entry.frameId);
116
+ if (!artifact || !frame || !screens.has(entry.screenId) || !variants.has(entry.variantId))
117
+ fail('entry references an unknown screen, variant, frame or artifact.');
69
118
  const key = `${entry.screenId}:${entry.variantId}:${entry.frameId}`;
70
- if (usedArtifacts.has(entry.artifactId) || combinations.has(key)) fail('entries must uniquely map artboards to artifacts.');
71
- usedArtifacts.add(entry.artifactId); combinations.add(key);
72
- if (artifact.viewport.width !== frame.width || artifact.viewport.height !== frame.height) fail('artifact viewport must match its declared frame.');
119
+ if (usedArtifacts.has(entry.artifactId) || combinations.has(key))
120
+ fail('entries must uniquely map artboards to artifacts.');
121
+ usedArtifacts.add(entry.artifactId);
122
+ combinations.add(key);
123
+ if (artifact.viewport.width !== frame.width || artifact.viewport.height !== frame.height)
124
+ fail('artifact viewport must match its declared frame.');
73
125
  }
74
126
  closed(envelope.viewer, ['mode', 'activeArtifactId', 'presentation'], 'viewer');
75
- if (!['single', 'variants'].includes(envelope.viewer.mode) || !artifacts.has(envelope.viewer.activeArtifactId) || envelope.viewer.presentation !== 'canvas') fail('viewer must select a published canvas artifact.');
76
- if (value.fingerprints.length !== entries.length) fail('fingerprints must cover every published artboard.');
77
- for (const key of Object.keys(value.state?.positions ?? {})) if (!artifacts.has(key)) fail('layout references an unknown artifact.');
127
+ if (
128
+ !['single', 'variants'].includes(envelope.viewer.mode) ||
129
+ !artifacts.has(envelope.viewer.activeArtifactId) ||
130
+ envelope.viewer.presentation !== 'canvas'
131
+ )
132
+ fail('viewer must select a published canvas artifact.');
133
+ if (value.fingerprints.length !== entries.length)
134
+ fail('fingerprints must cover every published artboard.');
135
+ for (const key of Object.keys(value.state?.positions ?? {}))
136
+ if (!artifacts.has(key)) fail('layout references an unknown artifact.');
78
137
  const components = identities(value.reviewContext.implementation.components, 'review components');
79
138
  for (const component of components.values()) {
80
- if (component.screenIds?.some(id => !screens.has(id))) fail('review guidance references an unknown screen.');
81
- const anchors = new Set((component.screenIds?.length ? component.screenIds : design.screenOrder).flatMap(id => screens.get(id).anchors ?? []));
82
- if (component.anchorIds?.some(id => !anchors.has(id))) fail('review guidance references an undeclared anchor.');
139
+ if (component.screenIds?.some((id) => !screens.has(id)))
140
+ fail('review guidance references an unknown screen.');
141
+ const anchors = new Set(
142
+ (component.screenIds?.length ? component.screenIds : design.screenOrder).flatMap(
143
+ (id) => screens.get(id).anchors ?? [],
144
+ ),
145
+ );
146
+ if (component.anchorIds?.some((id) => !anchors.has(id)))
147
+ fail('review guidance references an undeclared anchor.');
83
148
  }
84
149
  return value;
85
150
  }