@openplanr/protocol 0.6.1 → 0.6.2

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 (55) hide show
  1. package/lib/dashboard/closed-json-contract.mjs +99 -109
  2. package/lib/dashboard/operate-experience-audit-display-contract.d.mts +128 -153
  3. package/lib/dashboard/operate-experience-audit-display-contract.mjs +530 -585
  4. package/lib/dashboard/operate-experience-display-contract.d.mts +415 -437
  5. package/lib/dashboard/operate-experience-display-contract.mjs +768 -831
  6. package/lib/dashboard/operate-experience-surface-contract.d.mts +143 -148
  7. package/lib/dashboard/operate-experience-surface-contract.mjs +72 -73
  8. package/lib/dashboard/operate-review-contract.d.mts +7 -14
  9. package/lib/dashboard/operate-review-contract.mjs +46 -42
  10. package/lib/dashboard/operate-review-display-workspace-contract.d.mts +2 -5
  11. package/lib/dashboard/operate-review-display-workspace-contract.mjs +158 -104
  12. package/lib/dashboard/operate-review-payload-safety.mjs +4 -2
  13. package/lib/dashboard/operate-review-workspace-projection-v2.d.mts +47 -33
  14. package/lib/protocol/index.d.ts +2647 -543
  15. package/package.json +1 -1
  16. package/registries/commands.json +3 -3
  17. package/registries/skills.json +5 -5
  18. package/src/browser-contracts.d.mts +4 -1
  19. package/src/browser-contracts.mjs +16 -5
  20. package/src/canonical-json.d.mts +3 -1
  21. package/src/canonical-json.mjs +57 -20
  22. package/src/compat/live-evidence-v2.mjs +1604 -485
  23. package/src/compat/operate-experience-live-patch.mjs +67 -15
  24. package/src/compat/operating-planning-contracts.mjs +183 -51
  25. package/src/contracts.d.mts +54 -13
  26. package/src/contracts.mjs +625 -335
  27. package/src/design-contracts.mjs +58 -21
  28. package/src/design-handoff-contracts.d.mts +67 -11
  29. package/src/design-handoff-contracts.mjs +243 -98
  30. package/src/design-publication-contracts.mjs +98 -33
  31. package/src/diagram-authoring-contracts.d.mts +422 -78
  32. package/src/diagram-authoring-contracts.mjs +1697 -326
  33. package/src/diagram-contracts.d.mts +4 -1
  34. package/src/diagram-contracts.mjs +16 -4
  35. package/src/enterprise-contracts.d.mts +211 -46
  36. package/src/enterprise-contracts.mjs +727 -175
  37. package/src/errors.mjs +4 -0
  38. package/src/generated/canonical-registries.mjs +8 -8
  39. package/src/index.d.mts +8 -8
  40. package/src/index.mjs +36 -20
  41. package/src/json-schema.d.mts +21 -6
  42. package/src/json-schema.mjs +66 -18
  43. package/src/planning-contracts.d.mts +8 -2
  44. package/src/planning-contracts.mjs +33 -7
  45. package/src/registries.d.mts +11 -3
  46. package/src/registries.mjs +369 -87
  47. package/src/review-experience-contracts.d.mts +7 -2
  48. package/src/review-experience-contracts.mjs +198 -49
  49. package/src/semver.mjs +5 -1
  50. package/src/skill-source-contracts.d.mts +36 -16
  51. package/src/skill-source-contracts.mjs +25 -6
  52. package/src/task-contracts.d.mts +13 -3
  53. package/src/task-contracts.mjs +181 -40
  54. package/src/workspace-contracts.d.mts +38 -10
  55. package/src/workspace-contracts.mjs +147 -33
@@ -1,1007 +1,944 @@
1
1
  import { validateJson } from '../../src/json-schema.mjs';
2
2
  import {
3
- contentHash,
4
- deepFreeze,
5
- exactEventHead,
6
- exactJson,
7
- jcsHash,
8
- safeDataClone,
9
- withoutContentHash,
10
- } from "./closed-json-contract.mjs";
3
+ contentHash,
4
+ deepFreeze,
5
+ exactEventHead,
6
+ exactJson,
7
+ jcsHash,
8
+ safeDataClone,
9
+ withoutContentHash,
10
+ } from './closed-json-contract.mjs';
11
11
  import {
12
- OPERATE_ACTION_DISPLAY_WORKSPACE_SCHEMA as actionDisplayWorkspaceSchema,
13
- OPERATE_ALLOWED_ACTION_SCHEMA as allowedActionSchema,
14
- OPERATE_API_ENVELOPE_SCHEMA as apiEnvelopeSchema,
15
- OPERATE_CYCLE_DISPLAY_WORKSPACE_SCHEMA as cycleDisplayWorkspaceSchema,
16
- OPERATE_EXECUTIVE_BOARD_DISPLAY_SURFACE_SCHEMA as executiveBoardDisplaySurfaceSchema,
17
- OPERATE_RECOVERY_DISPLAY_SURFACE_SCHEMA as recoveryDisplaySurfaceSchema,
18
- OPERATE_EXPERIENCE_DISPLAY_SURFACE_SCHEMA as displaySurfaceSchema,
19
- OPERATE_EXPERIENCE_PREVIEW_SCHEMA as experiencePreviewSchema,
20
- OPERATE_EXPERIENCE_SURFACE_SCHEMA as surfaceSchema,
21
- OPERATE_EXPERIENCE_VIEW_SCHEMA as experienceViewSchema,
22
- OPERATE_REVIEW_DISPLAY_WORKSPACE_SCHEMA as reviewWorkspaceSchema,
23
- OPERATING_FINDING_SCHEMA as findingSchema,
24
- OPERATING_DELIVERY_ROUTE_SCHEMA as deliveryRouteSchema,
25
- OPERATING_EVIDENCE_RESOLUTION_SCHEMA as evidenceResolutionSchema,
26
- OPERATING_EXECUTION_RESULT_SCHEMA as executionResultSchema,
27
- OPERATING_GOVERNED_OPERATION_SCHEMA as governedOperationSchema,
28
- OPERATING_REVIEW_SCHEMA as reviewSchema,
29
- OPERATING_TRACE_MATRIX_SCHEMA as traceMatrixSchema,
30
- OPERATING_WORK_LEDGER_SCHEMA as workLedgerSchema,
31
- } from "./generated/operate-experience-surface-schema-data.mjs";
32
- import { assertOperateExperienceSurfaceV1 } from "./operate-experience-surface-contract.mjs";
33
-
34
- const DISPLAY_SURFACE_DOMAIN =
35
- "openplanr:operate-experience-display-surface:1.0.0";
36
- const CYCLE_WORKSPACE_DOMAIN =
37
- "openplanr:operate-cycle-display-workspace:1.0.0";
38
- const EXECUTIVE_BOARD_DISPLAY_DOMAIN =
39
- "openplanr:operate-executive-board-display-surface:1.0.0";
40
- export const ACTION_WORKSPACE_DOMAIN =
41
- "openplanr:operate-action-display-workspace:1.0.0";
42
- export const RECOVERY_DISPLAY_DOMAIN =
43
- "openplanr:operate-recovery-display-surface:1.0.0";
12
+ OPERATE_ACTION_DISPLAY_WORKSPACE_SCHEMA as actionDisplayWorkspaceSchema,
13
+ OPERATE_ALLOWED_ACTION_SCHEMA as allowedActionSchema,
14
+ OPERATE_API_ENVELOPE_SCHEMA as apiEnvelopeSchema,
15
+ OPERATE_CYCLE_DISPLAY_WORKSPACE_SCHEMA as cycleDisplayWorkspaceSchema,
16
+ OPERATING_DELIVERY_ROUTE_SCHEMA as deliveryRouteSchema,
17
+ OPERATE_EXPERIENCE_DISPLAY_SURFACE_SCHEMA as displaySurfaceSchema,
18
+ OPERATING_EVIDENCE_RESOLUTION_SCHEMA as evidenceResolutionSchema,
19
+ OPERATING_EXECUTION_RESULT_SCHEMA as executionResultSchema,
20
+ OPERATE_EXECUTIVE_BOARD_DISPLAY_SURFACE_SCHEMA as executiveBoardDisplaySurfaceSchema,
21
+ OPERATE_EXPERIENCE_PREVIEW_SCHEMA as experiencePreviewSchema,
22
+ OPERATE_EXPERIENCE_VIEW_SCHEMA as experienceViewSchema,
23
+ OPERATING_FINDING_SCHEMA as findingSchema,
24
+ OPERATING_GOVERNED_OPERATION_SCHEMA as governedOperationSchema,
25
+ OPERATE_RECOVERY_DISPLAY_SURFACE_SCHEMA as recoveryDisplaySurfaceSchema,
26
+ OPERATING_REVIEW_SCHEMA as reviewSchema,
27
+ OPERATE_REVIEW_DISPLAY_WORKSPACE_SCHEMA as reviewWorkspaceSchema,
28
+ OPERATE_EXPERIENCE_SURFACE_SCHEMA as surfaceSchema,
29
+ OPERATING_TRACE_MATRIX_SCHEMA as traceMatrixSchema,
30
+ OPERATING_WORK_LEDGER_SCHEMA as workLedgerSchema,
31
+ } from './generated/operate-experience-surface-schema-data.mjs';
32
+ import { assertOperateExperienceSurfaceV1 } from './operate-experience-surface-contract.mjs';
33
+
34
+ const DISPLAY_SURFACE_DOMAIN = 'openplanr:operate-experience-display-surface:1.0.0';
35
+ const CYCLE_WORKSPACE_DOMAIN = 'openplanr:operate-cycle-display-workspace:1.0.0';
36
+ const EXECUTIVE_BOARD_DISPLAY_DOMAIN = 'openplanr:operate-executive-board-display-surface:1.0.0';
37
+ export const ACTION_WORKSPACE_DOMAIN = 'openplanr:operate-action-display-workspace:1.0.0';
38
+ export const RECOVERY_DISPLAY_DOMAIN = 'openplanr:operate-recovery-display-surface:1.0.0';
44
39
  const ACTION_WORKSPACE_BOUNDARIES = Object.freeze({
45
- approvalExecution:
46
- "Named approval satisfies only its exact version-bound requirement. Execution receives a fresh authority check.",
47
- verification:
48
- "Outcome verification remains separate. No success claim appears before accepted evidence.",
49
- retry:
50
- "An effect may have occurred. Only Inspect, Reconcile, custody restoration, or an explicit runtime recovery route is legal.",
40
+ approvalExecution:
41
+ 'Named approval satisfies only its exact version-bound requirement. Execution receives a fresh authority check.',
42
+ verification:
43
+ 'Outcome verification remains separate. No success claim appears before accepted evidence.',
44
+ retry:
45
+ 'An effect may have occurred. Only Inspect, Reconcile, custody restoration, or an explicit runtime recovery route is legal.',
51
46
  });
52
- const DISPLAY_SURFACES = new Set(["today", "inbox", "cycles", "cycle", "actions"]);
47
+ const DISPLAY_SURFACES = new Set(['today', 'inbox', 'cycles', 'cycle', 'actions']);
53
48
  const STAGE_ORDER = Object.freeze([
54
- "observe",
55
- "understand",
56
- "decide",
57
- "govern",
58
- "act",
59
- "verify",
60
- "learn",
49
+ 'observe',
50
+ 'understand',
51
+ 'decide',
52
+ 'govern',
53
+ 'act',
54
+ 'verify',
55
+ 'learn',
61
56
  ]);
62
57
  const ACTIVE_CYCLE_STAGE = Object.freeze({
63
- created: 0,
64
- observing: 0,
65
- advising: 1,
66
- challenging: 1,
67
- synthesizing: 1,
68
- awaiting_review: 2,
69
- approved: 3,
70
- executing: 4,
71
- verifying: 5,
72
- closed: 6,
73
- blocked: 0,
74
- failed: 0,
75
- cancelled: 0,
58
+ created: 0,
59
+ observing: 0,
60
+ advising: 1,
61
+ challenging: 1,
62
+ synthesizing: 1,
63
+ awaiting_review: 2,
64
+ approved: 3,
65
+ executing: 4,
66
+ verifying: 5,
67
+ closed: 6,
68
+ blocked: 0,
69
+ failed: 0,
70
+ cancelled: 0,
76
71
  });
77
72
  const CYCLE_STATES = new Set([
78
- ...Object.keys(ACTIVE_CYCLE_STAGE),
79
- "closed",
80
- "blocked",
81
- "failed",
82
- "cancelled",
83
- ]);
84
- const CYCLE_HEALTH = new Set(["normal", "quiet", "partial", "blocked"]);
85
- const PERSISTENT_RELATIONS = Object.freeze([
86
- "source",
87
- "touched",
88
- "carried-forward",
73
+ ...Object.keys(ACTIVE_CYCLE_STAGE),
74
+ 'closed',
75
+ 'blocked',
76
+ 'failed',
77
+ 'cancelled',
89
78
  ]);
79
+ const CYCLE_HEALTH = new Set(['normal', 'quiet', 'partial', 'blocked']);
80
+ const PERSISTENT_RELATIONS = Object.freeze(['source', 'touched', 'carried-forward']);
90
81
  const PERSISTENT_ID = Object.freeze({
91
- finding: /^fnd_[A-Za-z0-9][A-Za-z0-9._-]{7,127}$/u,
92
- decision: /^dec_[A-Za-z0-9][A-Za-z0-9._-]{7,127}$/u,
93
- action: /^act_[A-Za-z0-9][A-Za-z0-9._-]{7,127}$/u,
82
+ finding: /^fnd_[A-Za-z0-9][A-Za-z0-9._-]{7,127}$/u,
83
+ decision: /^dec_[A-Za-z0-9][A-Za-z0-9._-]{7,127}$/u,
84
+ action: /^act_[A-Za-z0-9][A-Za-z0-9._-]{7,127}$/u,
94
85
  });
95
86
  const PERSISTENT_STATE = Object.freeze({
96
- finding: new Set([
97
- "open",
98
- "accepted",
99
- "resolved",
100
- "rejected",
101
- "deferred",
102
- "superseded",
103
- ]),
104
- decision: new Set([
105
- "proposed",
106
- "approved",
107
- "rejected",
108
- "deferred",
109
- "superseded",
110
- ]),
111
- action: new Set([
112
- "proposed",
113
- "approved",
114
- "queued",
115
- "in_progress",
116
- "completed",
117
- "blocked",
118
- "rejected",
119
- "deferred",
120
- "cancelled",
121
- ]),
87
+ finding: new Set(['open', 'accepted', 'resolved', 'rejected', 'deferred', 'superseded']),
88
+ decision: new Set(['proposed', 'approved', 'rejected', 'deferred', 'superseded']),
89
+ action: new Set([
90
+ 'proposed',
91
+ 'approved',
92
+ 'queued',
93
+ 'in_progress',
94
+ 'completed',
95
+ 'blocked',
96
+ 'rejected',
97
+ 'deferred',
98
+ 'cancelled',
99
+ ]),
122
100
  });
123
101
 
124
102
  const schemas = new Map([
125
- ["operate-experience-display-surface.schema.json", displaySurfaceSchema],
126
- ["operate-action-display-workspace.schema.json", actionDisplayWorkspaceSchema],
127
- ["operate-cycle-display-workspace.schema.json", cycleDisplayWorkspaceSchema],
128
- ["operate-executive-board-display-surface.schema.json", executiveBoardDisplaySurfaceSchema],
129
- ["operate-recovery-display-surface.schema.json", recoveryDisplaySurfaceSchema],
130
- ["operate-experience-surface.schema.json", surfaceSchema],
131
- ["operate-experience-view.schema.json", experienceViewSchema],
132
- ["operate-review-display-workspace.schema.json", reviewWorkspaceSchema],
133
- ["operating-finding.schema.json", findingSchema],
134
- ["operate-experience-preview.schema.json", experiencePreviewSchema],
135
- ["operate-api-envelope.schema.json", apiEnvelopeSchema],
136
- ["operate-allowed-action.schema.json", allowedActionSchema],
137
- ["operating-work-ledger.schema.json", workLedgerSchema],
138
- ["operating-delivery-route.schema.json", deliveryRouteSchema],
139
- ["operating-evidence-resolution.schema.json", evidenceResolutionSchema],
140
- ["operating-execution-result.schema.json", executionResultSchema],
141
- ["operating-governed-operation.schema.json", governedOperationSchema],
142
- ["operating-review.schema.json", reviewSchema],
143
- ["operating-trace-matrix.schema.json", traceMatrixSchema],
103
+ ['operate-experience-display-surface.schema.json', displaySurfaceSchema],
104
+ ['operate-action-display-workspace.schema.json', actionDisplayWorkspaceSchema],
105
+ ['operate-cycle-display-workspace.schema.json', cycleDisplayWorkspaceSchema],
106
+ ['operate-executive-board-display-surface.schema.json', executiveBoardDisplaySurfaceSchema],
107
+ ['operate-recovery-display-surface.schema.json', recoveryDisplaySurfaceSchema],
108
+ ['operate-experience-surface.schema.json', surfaceSchema],
109
+ ['operate-experience-view.schema.json', experienceViewSchema],
110
+ ['operate-review-display-workspace.schema.json', reviewWorkspaceSchema],
111
+ ['operating-finding.schema.json', findingSchema],
112
+ ['operate-experience-preview.schema.json', experiencePreviewSchema],
113
+ ['operate-api-envelope.schema.json', apiEnvelopeSchema],
114
+ ['operate-allowed-action.schema.json', allowedActionSchema],
115
+ ['operating-work-ledger.schema.json', workLedgerSchema],
116
+ ['operating-delivery-route.schema.json', deliveryRouteSchema],
117
+ ['operating-evidence-resolution.schema.json', evidenceResolutionSchema],
118
+ ['operating-execution-result.schema.json', executionResultSchema],
119
+ ['operating-governed-operation.schema.json', governedOperationSchema],
120
+ ['operating-review.schema.json', reviewSchema],
121
+ ['operating-trace-matrix.schema.json', traceMatrixSchema],
144
122
  ]);
145
123
 
146
124
  function jsonPointer(root, fragment) {
147
- if (!fragment || fragment === "#") return root;
148
- if (!fragment.startsWith("#/")) return null;
149
- return fragment
150
- .slice(2)
151
- .split("/")
152
- .map((part) => part.replaceAll("~1", "/").replaceAll("~0", "~"))
153
- .reduce((value, part) => value?.[part], root);
125
+ if (!fragment || fragment === '#') return root;
126
+ if (!fragment.startsWith('#/')) return null;
127
+ return fragment
128
+ .slice(2)
129
+ .split('/')
130
+ .map((part) => part.replaceAll('~1', '/').replaceAll('~0', '~'))
131
+ .reduce((value, part) => value?.[part], root);
154
132
  }
155
133
 
156
134
  function resolveSchemaRef(reference) {
157
- const [path, pointer = ""] = reference.split("#");
158
- const filename = path.split("/").at(-1);
159
- const rootSchema = schemas.get(filename);
160
- if (!rootSchema) return null;
161
- return {
162
- schema: jsonPointer(rootSchema, pointer ? `#${pointer}` : "#"),
163
- rootSchema,
164
- base: filename,
165
- };
135
+ const [path, pointer = ''] = reference.split('#');
136
+ const filename = path.split('/').at(-1);
137
+ const rootSchema = schemas.get(filename);
138
+ if (!rootSchema) return null;
139
+ return {
140
+ schema: jsonPointer(rootSchema, pointer ? `#${pointer}` : '#'),
141
+ rootSchema,
142
+ base: filename,
143
+ };
166
144
  }
167
145
 
168
146
  function validationFailure() {
169
- return [
170
- {
171
- path: "$",
172
- rule: "closedContract",
173
- detail: "does not satisfy the closed display contract",
174
- },
175
- ];
147
+ return [
148
+ {
149
+ path: '$',
150
+ rule: 'closedContract',
151
+ detail: 'does not satisfy the closed display contract',
152
+ },
153
+ ];
176
154
  }
177
155
 
178
156
  function exactKeys(value, keys) {
179
- if (value === null || typeof value !== "object" || Array.isArray(value))
180
- return false;
181
- const actual = Object.keys(value);
182
- return actual.length === keys.length && keys.every((key) => actual.includes(key));
157
+ if (value === null || typeof value !== 'object' || Array.isArray(value)) return false;
158
+ const actual = Object.keys(value);
159
+ return actual.length === keys.length && keys.every((key) => actual.includes(key));
183
160
  }
184
161
 
185
162
  function exactExpectedBinding(
186
- payload,
187
- expected,
188
- { workspace = false, executiveBoard = false, action = false, recovery = false } = {},
163
+ payload,
164
+ expected,
165
+ { workspace = false, executiveBoard = false, action = false, recovery = false } = {},
189
166
  ) {
190
- if (!expected) return true;
191
- if (
192
- payload.actorId !== expected.actorId ||
193
- payload.scopeId !== expected.scopeId ||
194
- payload.domainId !== expected.domainId ||
195
- payload.domainVersion !== expected.domainVersion ||
196
- payload.generatedAt !== expected.generatedAt ||
197
- payload.viewHash !== expected.viewHash ||
198
- !exactEventHead(payload.eventHead, expected.eventHead)
199
- )
200
- return false;
201
- if (!workspace) {
202
- if (expected.surface !== undefined && payload.surface !== expected.surface)
203
- return false;
204
- if (payload.surface === "inbox" || payload.surface === "actions") {
205
- return (
206
- expected.surface === payload.surface &&
207
- typeof expected.projectId === "string" &&
208
- Number.isSafeInteger(expected.generation) &&
209
- payload.data.requestBinding.projectId === expected.projectId &&
210
- payload.data.requestBinding.generation === expected.generation &&
211
- (payload.surface !== "inbox" ||
212
- payload.data.requestBinding.subjectId === expected.subjectId) &&
213
- (payload.surface !== "actions" ||
214
- (expected.subjectId === null &&
215
- typeof expected.cycleId === "string" &&
216
- expected.cycleId.length > 0))
217
- );
218
- }
219
- if (payload.surface === "cycle") {
220
- const committedCycleId = payload.data.cycle.cycleId;
221
- if (
222
- typeof expected.subjectId !== "string" ||
223
- typeof expected.cycleId !== "string" ||
224
- expected.subjectId !== committedCycleId ||
225
- expected.cycleId !== committedCycleId
226
- )
227
- return false;
228
- }
229
- return true;
230
- }
231
- if (executiveBoard) {
232
- return (
233
- expected.cycleId === payload.data.cycleId &&
234
- expected.subjectId === payload.data.cycleId
235
- );
236
- }
237
- if (action) {
238
- return (
239
- expected.subjectId === payload.data.action.actionId &&
240
- expected.actionId === payload.data.action.actionId
241
- );
242
- }
243
- if (recovery) return true;
244
- return (
245
- expected.cycleId === payload.data.cycle.cycleId &&
246
- expected.subjectId === payload.data.cycle.cycleId
247
- );
167
+ if (!expected) return true;
168
+ if (
169
+ payload.actorId !== expected.actorId ||
170
+ payload.scopeId !== expected.scopeId ||
171
+ payload.domainId !== expected.domainId ||
172
+ payload.domainVersion !== expected.domainVersion ||
173
+ payload.generatedAt !== expected.generatedAt ||
174
+ payload.viewHash !== expected.viewHash ||
175
+ !exactEventHead(payload.eventHead, expected.eventHead)
176
+ )
177
+ return false;
178
+ if (!workspace) {
179
+ if (expected.surface !== undefined && payload.surface !== expected.surface) return false;
180
+ if (payload.surface === 'inbox' || payload.surface === 'actions') {
181
+ return (
182
+ expected.surface === payload.surface &&
183
+ typeof expected.projectId === 'string' &&
184
+ Number.isSafeInteger(expected.generation) &&
185
+ payload.data.requestBinding.projectId === expected.projectId &&
186
+ payload.data.requestBinding.generation === expected.generation &&
187
+ (payload.surface !== 'inbox' ||
188
+ payload.data.requestBinding.subjectId === expected.subjectId) &&
189
+ (payload.surface !== 'actions' ||
190
+ (expected.subjectId === null &&
191
+ typeof expected.cycleId === 'string' &&
192
+ expected.cycleId.length > 0))
193
+ );
194
+ }
195
+ if (payload.surface === 'cycle') {
196
+ const committedCycleId = payload.data.cycle.cycleId;
197
+ if (
198
+ typeof expected.subjectId !== 'string' ||
199
+ typeof expected.cycleId !== 'string' ||
200
+ expected.subjectId !== committedCycleId ||
201
+ expected.cycleId !== committedCycleId
202
+ )
203
+ return false;
204
+ }
205
+ return true;
206
+ }
207
+ if (executiveBoard) {
208
+ return expected.cycleId === payload.data.cycleId && expected.subjectId === payload.data.cycleId;
209
+ }
210
+ if (action) {
211
+ return (
212
+ expected.subjectId === payload.data.action.actionId &&
213
+ expected.actionId === payload.data.action.actionId
214
+ );
215
+ }
216
+ if (recovery) return true;
217
+ return (
218
+ expected.cycleId === payload.data.cycle.cycleId &&
219
+ expected.subjectId === payload.data.cycle.cycleId
220
+ );
248
221
  }
249
222
 
250
223
  function validCycleLifecycle(cycle) {
251
- if (
252
- !cycle ||
253
- typeof cycle !== "object" ||
254
- !CYCLE_STATES.has(cycle.state) ||
255
- !CYCLE_HEALTH.has(cycle.health) ||
256
- !Array.isArray(cycle.stages) ||
257
- cycle.stages.length !== STAGE_ORDER.length ||
258
- !cycle.stages.every((stage, index) => stage.id === STAGE_ORDER[index])
259
- )
260
- return false;
261
- const current = ACTIVE_CYCLE_STAGE[cycle.state];
262
- return cycle.stages.every((stage, index) => {
263
- let expected = index < current ? "complete" : index === current ? "current" : "waiting";
264
- if (cycle.state === "closed") expected = "complete";
265
- if (index === current && ["blocked", "failed"].includes(cycle.state)) {
266
- expected = cycle.state;
267
- }
268
- if (index === current && cycle.state === "cancelled") expected = "skipped";
269
- const reason = ["blocked", "failed", "skipped"].includes(expected)
270
- ? `Cycle is ${cycle.state}.`
271
- : null;
272
- return stage.state === expected && stage.reason === reason;
273
- });
224
+ if (
225
+ !cycle ||
226
+ typeof cycle !== 'object' ||
227
+ !CYCLE_STATES.has(cycle.state) ||
228
+ !CYCLE_HEALTH.has(cycle.health) ||
229
+ !Array.isArray(cycle.stages) ||
230
+ cycle.stages.length !== STAGE_ORDER.length ||
231
+ !cycle.stages.every((stage, index) => stage.id === STAGE_ORDER[index])
232
+ )
233
+ return false;
234
+ const current = ACTIVE_CYCLE_STAGE[cycle.state];
235
+ return cycle.stages.every((stage, index) => {
236
+ let expected = index < current ? 'complete' : index === current ? 'current' : 'waiting';
237
+ if (cycle.state === 'closed') expected = 'complete';
238
+ if (index === current && ['blocked', 'failed'].includes(cycle.state)) {
239
+ expected = cycle.state;
240
+ }
241
+ if (index === current && cycle.state === 'cancelled') expected = 'skipped';
242
+ const reason = ['blocked', 'failed', 'skipped'].includes(expected)
243
+ ? `Cycle is ${cycle.state}.`
244
+ : null;
245
+ return stage.state === expected && stage.reason === reason;
246
+ });
274
247
  }
275
248
 
276
249
  function validDisplaySurfaceSemantics(value, expected) {
277
- const payload = value.payload;
278
- if (
279
- !DISPLAY_SURFACES.has(payload.surface) ||
280
- value.integrity.sourceViewHash !== payload.viewHash ||
281
- payload.truthSummary.sourceViewHash !== payload.viewHash ||
282
- !exactEventHead(payload.truthSummary.sourceEventHead, payload.eventHead) ||
283
- !exactExpectedBinding(payload, expected)
284
- )
285
- return false;
286
- if (payload.surface === "inbox") {
287
- const items = payload.data.inbox;
288
- const subjectId = payload.data.requestBinding.subjectId;
289
- return (
290
- Array.isArray(items) &&
291
- new Set(items.map((item) => item.itemId)).size === items.length &&
292
- (subjectId === null ||
293
- (items.length === 1 && items[0].itemId === subjectId)) &&
294
- items.every((item, index) =>
295
- index === 0 ||
296
- Number(items[index - 1].blocking) > Number(item.blocking) ||
297
- (Number(items[index - 1].blocking) === Number(item.blocking) &&
298
- items[index - 1].itemId.localeCompare(item.itemId) < 0),
299
- )
300
- );
301
- }
302
- if (payload.surface === "actions") {
303
- const items = payload.data.actions;
304
- return (
305
- Array.isArray(items) &&
306
- new Set(items.map((item) => item.actionId)).size === items.length
307
- );
308
- }
309
- const cycles =
310
- payload.surface === "today"
311
- ? payload.data.activeCycle === null
312
- ? []
313
- : [payload.data.activeCycle]
314
- : payload.surface === "cycles"
315
- ? payload.data.cycles
316
- : [payload.data.cycle];
317
- return (
318
- new Set(cycles.map((cycle) => cycle.cycleId)).size === cycles.length &&
319
- cycles.every(validCycleLifecycle)
320
- );
250
+ const payload = value.payload;
251
+ if (
252
+ !DISPLAY_SURFACES.has(payload.surface) ||
253
+ value.integrity.sourceViewHash !== payload.viewHash ||
254
+ payload.truthSummary.sourceViewHash !== payload.viewHash ||
255
+ !exactEventHead(payload.truthSummary.sourceEventHead, payload.eventHead) ||
256
+ !exactExpectedBinding(payload, expected)
257
+ )
258
+ return false;
259
+ if (payload.surface === 'inbox') {
260
+ const items = payload.data.inbox;
261
+ const subjectId = payload.data.requestBinding.subjectId;
262
+ return (
263
+ Array.isArray(items) &&
264
+ new Set(items.map((item) => item.itemId)).size === items.length &&
265
+ (subjectId === null || (items.length === 1 && items[0].itemId === subjectId)) &&
266
+ items.every(
267
+ (item, index) =>
268
+ index === 0 ||
269
+ Number(items[index - 1].blocking) > Number(item.blocking) ||
270
+ (Number(items[index - 1].blocking) === Number(item.blocking) &&
271
+ items[index - 1].itemId.localeCompare(item.itemId) < 0),
272
+ )
273
+ );
274
+ }
275
+ if (payload.surface === 'actions') {
276
+ const items = payload.data.actions;
277
+ return (
278
+ Array.isArray(items) && new Set(items.map((item) => item.actionId)).size === items.length
279
+ );
280
+ }
281
+ const cycles =
282
+ payload.surface === 'today'
283
+ ? payload.data.activeCycle === null
284
+ ? []
285
+ : [payload.data.activeCycle]
286
+ : payload.surface === 'cycles'
287
+ ? payload.data.cycles
288
+ : [payload.data.cycle];
289
+ return (
290
+ new Set(cycles.map((cycle) => cycle.cycleId)).size === cycles.length &&
291
+ cycles.every(validCycleLifecycle)
292
+ );
321
293
  }
322
294
 
323
295
  function validPersistentItem(value, kind) {
324
- return (
325
- exactKeys(value, ["kind", "subjectId", "state", "relations"]) &&
326
- value.kind === kind &&
327
- typeof value.subjectId === "string" &&
328
- PERSISTENT_ID[kind].test(value.subjectId) &&
329
- typeof value.state === "string" &&
330
- PERSISTENT_STATE[kind].has(value.state) &&
331
- Array.isArray(value.relations) &&
332
- value.relations.length >= 1 &&
333
- value.relations.length <= PERSISTENT_RELATIONS.length &&
334
- value.relations.every((relation) => PERSISTENT_RELATIONS.includes(relation)) &&
335
- new Set(value.relations).size === value.relations.length
336
- );
296
+ return (
297
+ exactKeys(value, ['kind', 'subjectId', 'state', 'relations']) &&
298
+ value.kind === kind &&
299
+ typeof value.subjectId === 'string' &&
300
+ PERSISTENT_ID[kind].test(value.subjectId) &&
301
+ typeof value.state === 'string' &&
302
+ PERSISTENT_STATE[kind].has(value.state) &&
303
+ Array.isArray(value.relations) &&
304
+ value.relations.length >= 1 &&
305
+ value.relations.length <= PERSISTENT_RELATIONS.length &&
306
+ value.relations.every((relation) => PERSISTENT_RELATIONS.includes(relation)) &&
307
+ new Set(value.relations).size === value.relations.length
308
+ );
337
309
  }
338
310
 
339
311
  function validCycleLink(value) {
340
- return (
341
- exactKeys(value, ["entityKind", "entityId", "cycleId", "relation"]) &&
342
- PERSISTENT_ID[value.entityKind]?.test(value.entityId) === true &&
343
- typeof value.cycleId === "string" &&
344
- PERSISTENT_RELATIONS.includes(value.relation)
345
- );
312
+ return (
313
+ exactKeys(value, ['entityKind', 'entityId', 'cycleId', 'relation']) &&
314
+ PERSISTENT_ID[value.entityKind]?.test(value.entityId) === true &&
315
+ typeof value.cycleId === 'string' &&
316
+ PERSISTENT_RELATIONS.includes(value.relation)
317
+ );
346
318
  }
347
319
 
348
320
  function validPersistentGraph(persistent, cycleId) {
349
- const items = [
350
- ...persistent.findings,
351
- ...persistent.decisions,
352
- ...persistent.actions,
353
- ];
354
- const itemKeys = items.map((item) => `${item.kind}:${item.subjectId}`);
355
- const linkKeys = persistent.cycleLinks.map(
356
- (link) => `${link.entityKind}:${link.entityId}:${link.cycleId}:${link.relation}`,
357
- );
358
- if (
359
- new Set(itemKeys).size !== itemKeys.length ||
360
- new Set(linkKeys).size !== linkKeys.length ||
361
- persistent.cycleLinks.some(
362
- (link) =>
363
- link.cycleId !== cycleId ||
364
- !items.some(
365
- (item) =>
366
- item.kind === link.entityKind && item.subjectId === link.entityId,
367
- ),
368
- )
369
- )
370
- return false;
371
- return items.every((item) =>
372
- exactJson(
373
- item.relations,
374
- persistent.cycleLinks
375
- .filter(
376
- (link) =>
377
- link.entityKind === item.kind && link.entityId === item.subjectId,
378
- )
379
- .map((link) => link.relation),
380
- ),
381
- );
321
+ const items = [...persistent.findings, ...persistent.decisions, ...persistent.actions];
322
+ const itemKeys = items.map((item) => `${item.kind}:${item.subjectId}`);
323
+ const linkKeys = persistent.cycleLinks.map(
324
+ (link) => `${link.entityKind}:${link.entityId}:${link.cycleId}:${link.relation}`,
325
+ );
326
+ if (
327
+ new Set(itemKeys).size !== itemKeys.length ||
328
+ new Set(linkKeys).size !== linkKeys.length ||
329
+ persistent.cycleLinks.some(
330
+ (link) =>
331
+ link.cycleId !== cycleId ||
332
+ !items.some((item) => item.kind === link.entityKind && item.subjectId === link.entityId),
333
+ )
334
+ )
335
+ return false;
336
+ return items.every((item) =>
337
+ exactJson(
338
+ item.relations,
339
+ persistent.cycleLinks
340
+ .filter((link) => link.entityKind === item.kind && link.entityId === item.subjectId)
341
+ .map((link) => link.relation),
342
+ ),
343
+ );
382
344
  }
383
345
 
384
346
  function validAllowedAction(value, cycleId) {
385
- return (
386
- exactKeys(value, ["tool", "arguments", "label", "effect"]) &&
387
- value.tool === "operate.cycle.get" &&
388
- exactKeys(value.arguments, ["cycleId"]) &&
389
- value.arguments.cycleId === cycleId &&
390
- typeof value.label === "string" &&
391
- value.label.length > 0 &&
392
- value.label.length <= 256 &&
393
- !/(?:<[^>]+>|\{\{[^}]+\}\})/u.test(value.label) &&
394
- value.effect === "read-only"
395
- );
347
+ return (
348
+ exactKeys(value, ['tool', 'arguments', 'label', 'effect']) &&
349
+ value.tool === 'operate.cycle.get' &&
350
+ exactKeys(value.arguments, ['cycleId']) &&
351
+ value.arguments.cycleId === cycleId &&
352
+ typeof value.label === 'string' &&
353
+ value.label.length > 0 &&
354
+ value.label.length <= 256 &&
355
+ !/(?:<[^>]+>|\{\{[^}]+\}\})/u.test(value.label) &&
356
+ value.effect === 'read-only'
357
+ );
396
358
  }
397
359
 
398
360
  function outcomeCarriesAffirmativeProof(outcome) {
399
- const verification = outcome.verification;
400
- const metric = outcome.metric;
401
- return (
402
- ["succeeded", "failed"].includes(outcome.status) &&
403
- outcome.accessReason === null &&
404
- outcome.observationIds.length > 0 &&
405
- outcome.evidenceRefIds.length > 0 &&
406
- metric !== null &&
407
- metric.observed !== null &&
408
- metric.freshness === "current" &&
409
- verification !== null &&
410
- verification.accessReason === null &&
411
- outcome.verificationPlanId === verification.verificationPlanId &&
412
- metric.metricId === verification.metricId &&
413
- metric.metricHash === verification.metricHash
414
- );
361
+ const verification = outcome.verification;
362
+ const metric = outcome.metric;
363
+ return (
364
+ ['succeeded', 'failed'].includes(outcome.status) &&
365
+ outcome.accessReason === null &&
366
+ outcome.observationIds.length > 0 &&
367
+ outcome.evidenceRefIds.length > 0 &&
368
+ metric !== null &&
369
+ metric.observed !== null &&
370
+ metric.freshness === 'current' &&
371
+ verification !== null &&
372
+ verification.accessReason === null &&
373
+ outcome.verificationPlanId === verification.verificationPlanId &&
374
+ metric.metricId === verification.metricId &&
375
+ metric.metricHash === verification.metricHash
376
+ );
415
377
  }
416
378
 
417
379
  function validOutcomeLearningGraph(persistent, cycle, verification, truthSummary) {
418
- const actionIds = persistent.actions.map((action) => action.subjectId);
419
- const outcomeIds = persistent.outcomes.map((outcome) => outcome.outcomeId);
420
- const learningIds = persistent.learnings.map((learning) => learning.learningId);
421
- if (
422
- new Set(outcomeIds).size !== outcomeIds.length ||
423
- new Set(learningIds).size !== learningIds.length ||
424
- persistent.outcomes.some((outcome) => !actionIds.includes(outcome.actionId)) ||
425
- persistent.learnings.some(
426
- (learning) => !outcomeIds.includes(learning.outcomeId),
427
- )
428
- )
429
- return false;
430
- const expected = truthSummary.proof.status === "verified"
431
- ? "verified"
432
- : truthSummary.proof.status === "not-required"
433
- ? "not-required"
434
- : "unverified";
435
- const reasonCodes = expected === "unverified"
436
- ? truthSummary.proof.reasonCodes.length > 0
437
- ? truthSummary.proof.reasonCodes
438
- : ["OPERATE_VERIFICATION_EVIDENCE_MISSING"]
439
- : [];
440
- return (
441
- verification.status === expected &&
442
- exactJson(verification.reasonCodes, reasonCodes)
443
- );
380
+ const actionIds = persistent.actions.map((action) => action.subjectId);
381
+ const outcomeIds = persistent.outcomes.map((outcome) => outcome.outcomeId);
382
+ const learningIds = persistent.learnings.map((learning) => learning.learningId);
383
+ if (
384
+ new Set(outcomeIds).size !== outcomeIds.length ||
385
+ new Set(learningIds).size !== learningIds.length ||
386
+ persistent.outcomes.some((outcome) => !actionIds.includes(outcome.actionId)) ||
387
+ persistent.learnings.some((learning) => !outcomeIds.includes(learning.outcomeId))
388
+ )
389
+ return false;
390
+ const expected =
391
+ truthSummary.proof.status === 'verified'
392
+ ? 'verified'
393
+ : truthSummary.proof.status === 'not-required'
394
+ ? 'not-required'
395
+ : 'unverified';
396
+ const reasonCodes =
397
+ expected === 'unverified'
398
+ ? truthSummary.proof.reasonCodes.length > 0
399
+ ? truthSummary.proof.reasonCodes
400
+ : ['OPERATE_VERIFICATION_EVIDENCE_MISSING']
401
+ : [];
402
+ return verification.status === expected && exactJson(verification.reasonCodes, reasonCodes);
444
403
  }
445
404
 
446
405
  function workspaceSurface(payload, surface, data) {
447
- return {
448
- ok: true,
449
- kind: "operate-experience-surface",
450
- schemaVersion: "1.0.0",
451
- protocolVersion: payload.protocolVersion,
452
- surface,
453
- readOnly: true,
454
- mutationEnabled: payload.status === "ready",
455
- scopeId: payload.scopeId,
456
- domainId: payload.domainId,
457
- domainVersion: payload.domainVersion,
458
- actorId: payload.actorId,
459
- accessLevel: payload.accessLevel,
460
- generatedAt: payload.generatedAt,
461
- eventHead: payload.eventHead,
462
- viewHash: payload.viewHash,
463
- truthSummary: payload.truthSummary,
464
- status: payload.status,
465
- reasonCodes: payload.reasonCodes,
466
- data,
467
- };
406
+ return {
407
+ ok: true,
408
+ kind: 'operate-experience-surface',
409
+ schemaVersion: '1.0.0',
410
+ protocolVersion: payload.protocolVersion,
411
+ surface,
412
+ readOnly: true,
413
+ mutationEnabled: payload.status === 'ready',
414
+ scopeId: payload.scopeId,
415
+ domainId: payload.domainId,
416
+ domainVersion: payload.domainVersion,
417
+ actorId: payload.actorId,
418
+ accessLevel: payload.accessLevel,
419
+ generatedAt: payload.generatedAt,
420
+ eventHead: payload.eventHead,
421
+ viewHash: payload.viewHash,
422
+ truthSummary: payload.truthSummary,
423
+ status: payload.status,
424
+ reasonCodes: payload.reasonCodes,
425
+ data,
426
+ };
468
427
  }
469
428
 
470
429
  function validWorkspacePayload(payload) {
471
- const data = payload.data;
472
- if (
473
- !exactKeys(data.ownerCycle, [
474
- "cycleId",
475
- "scopeId",
476
- "domainId",
477
- "domainVersion",
478
- "state",
479
- "health",
480
- "focus",
481
- "createdAt",
482
- "updatedAt",
483
- ]) ||
484
- !Array.isArray(data.persistentWork.findings) ||
485
- !data.persistentWork.findings.every((item) =>
486
- validPersistentItem(item, "finding"),
487
- ) ||
488
- !Array.isArray(data.persistentWork.decisions) ||
489
- !data.persistentWork.decisions.every((item) =>
490
- validPersistentItem(item, "decision"),
491
- ) ||
492
- !Array.isArray(data.persistentWork.actions) ||
493
- !data.persistentWork.actions.every((item) =>
494
- validPersistentItem(item, "action"),
495
- ) ||
496
- !Array.isArray(data.persistentWork.cycleLinks) ||
497
- !data.persistentWork.cycleLinks.every(validCycleLink) ||
498
- !Array.isArray(data.persistentWork.outcomes) ||
499
- !Array.isArray(data.persistentWork.learnings) ||
500
- data.allowedActions.length !== 1
501
- )
502
- return false;
503
- try {
504
- const cycle = data.cycle;
505
- const schemaCycle = {
506
- ...cycle,
507
- assignments: cycle.assignments.map((assignment) =>
508
- assignment.deepLink === null
509
- ? { ...assignment, deepLink: cycle.deepLink }
510
- : assignment,
511
- ),
512
- };
513
- const schemaOutcomes = data.persistentWork.outcomes.map((outcome) =>
514
- outcome.deepLink === null
515
- ? {
516
- ...outcome,
517
- deepLink: `#/operate/outcomes/${encodeURIComponent(outcome.outcomeId)}`,
518
- }
519
- : outcome,
520
- );
521
- assertOperateExperienceSurfaceV1(
522
- workspaceSurface(payload, "cycle", { cycle: schemaCycle }),
523
- );
524
- assertOperateExperienceSurfaceV1(
525
- workspaceSurface(payload, "outcomes", {
526
- domainMetrics: [],
527
- outcomes: schemaOutcomes,
528
- learnings: data.persistentWork.learnings,
529
- }),
530
- );
531
- assertOperateExperienceSurfaceV1(
532
- workspaceSurface(payload, "history", {
533
- history: [],
534
- replay: data.replay,
535
- }),
536
- );
537
- const sourceActionIds = data.persistentWork.actions
538
- .filter((action) => action.relations.includes("source"))
539
- .map((action) => action.subjectId);
540
- return (
541
- validCycleLifecycle(cycle) &&
542
- data.ownerCycle.cycleId === cycle.cycleId &&
543
- data.ownerCycle.scopeId === payload.scopeId &&
544
- data.ownerCycle.domainId === payload.domainId &&
545
- data.ownerCycle.domainVersion === payload.domainVersion &&
546
- data.ownerCycle.state === cycle.state &&
547
- data.ownerCycle.health === cycle.health &&
548
- exactJson(data.ownerCycle.focus, cycle.focus) &&
549
- data.ownerCycle.createdAt === cycle.createdAt &&
550
- data.ownerCycle.updatedAt === cycle.updatedAt &&
551
- cycle.deepLink ===
552
- `#/operate/cycles/${encodeURIComponent(cycle.cycleId)}` &&
553
- exactEventHead(data.replay.finalHead, payload.eventHead) &&
554
- exactJson(cycle.replayCheckpoint, data.replay.checkpoint) &&
555
- exactJson(cycle.persistentActionIds, sourceActionIds) &&
556
- validPersistentGraph(data.persistentWork, cycle.cycleId) &&
557
- validOutcomeLearningGraph(
558
- data.persistentWork,
559
- cycle,
560
- data.verification,
561
- payload.truthSummary,
562
- ) &&
563
- validAllowedAction(data.allowedActions[0], cycle.cycleId)
564
- );
565
- } catch {
566
- return false;
567
- }
430
+ const data = payload.data;
431
+ if (
432
+ !exactKeys(data.ownerCycle, [
433
+ 'cycleId',
434
+ 'scopeId',
435
+ 'domainId',
436
+ 'domainVersion',
437
+ 'state',
438
+ 'health',
439
+ 'focus',
440
+ 'createdAt',
441
+ 'updatedAt',
442
+ ]) ||
443
+ !Array.isArray(data.persistentWork.findings) ||
444
+ !data.persistentWork.findings.every((item) => validPersistentItem(item, 'finding')) ||
445
+ !Array.isArray(data.persistentWork.decisions) ||
446
+ !data.persistentWork.decisions.every((item) => validPersistentItem(item, 'decision')) ||
447
+ !Array.isArray(data.persistentWork.actions) ||
448
+ !data.persistentWork.actions.every((item) => validPersistentItem(item, 'action')) ||
449
+ !Array.isArray(data.persistentWork.cycleLinks) ||
450
+ !data.persistentWork.cycleLinks.every(validCycleLink) ||
451
+ !Array.isArray(data.persistentWork.outcomes) ||
452
+ !Array.isArray(data.persistentWork.learnings) ||
453
+ data.allowedActions.length !== 1
454
+ )
455
+ return false;
456
+ try {
457
+ const cycle = data.cycle;
458
+ const schemaCycle = {
459
+ ...cycle,
460
+ assignments: cycle.assignments.map((assignment) =>
461
+ assignment.deepLink === null ? { ...assignment, deepLink: cycle.deepLink } : assignment,
462
+ ),
463
+ };
464
+ const schemaOutcomes = data.persistentWork.outcomes.map((outcome) =>
465
+ outcome.deepLink === null
466
+ ? {
467
+ ...outcome,
468
+ deepLink: `#/operate/outcomes/${encodeURIComponent(outcome.outcomeId)}`,
469
+ }
470
+ : outcome,
471
+ );
472
+ assertOperateExperienceSurfaceV1(workspaceSurface(payload, 'cycle', { cycle: schemaCycle }));
473
+ assertOperateExperienceSurfaceV1(
474
+ workspaceSurface(payload, 'outcomes', {
475
+ domainMetrics: [],
476
+ outcomes: schemaOutcomes,
477
+ learnings: data.persistentWork.learnings,
478
+ }),
479
+ );
480
+ assertOperateExperienceSurfaceV1(
481
+ workspaceSurface(payload, 'history', {
482
+ history: [],
483
+ replay: data.replay,
484
+ }),
485
+ );
486
+ const sourceActionIds = data.persistentWork.actions
487
+ .filter((action) => action.relations.includes('source'))
488
+ .map((action) => action.subjectId);
489
+ return (
490
+ validCycleLifecycle(cycle) &&
491
+ data.ownerCycle.cycleId === cycle.cycleId &&
492
+ data.ownerCycle.scopeId === payload.scopeId &&
493
+ data.ownerCycle.domainId === payload.domainId &&
494
+ data.ownerCycle.domainVersion === payload.domainVersion &&
495
+ data.ownerCycle.state === cycle.state &&
496
+ data.ownerCycle.health === cycle.health &&
497
+ exactJson(data.ownerCycle.focus, cycle.focus) &&
498
+ data.ownerCycle.createdAt === cycle.createdAt &&
499
+ data.ownerCycle.updatedAt === cycle.updatedAt &&
500
+ cycle.deepLink === `#/operate/cycles/${encodeURIComponent(cycle.cycleId)}` &&
501
+ exactEventHead(data.replay.finalHead, payload.eventHead) &&
502
+ exactJson(cycle.replayCheckpoint, data.replay.checkpoint) &&
503
+ exactJson(cycle.persistentActionIds, sourceActionIds) &&
504
+ validPersistentGraph(data.persistentWork, cycle.cycleId) &&
505
+ validOutcomeLearningGraph(
506
+ data.persistentWork,
507
+ cycle,
508
+ data.verification,
509
+ payload.truthSummary,
510
+ ) &&
511
+ validAllowedAction(data.allowedActions[0], cycle.cycleId)
512
+ );
513
+ } catch {
514
+ return false;
515
+ }
568
516
  }
569
517
 
570
518
  function validWorkspaceSemantics(value, expected) {
571
- return (
572
- value.integrity.sourceViewHash === value.payload.viewHash &&
573
- value.payload.truthSummary.sourceViewHash === value.payload.viewHash &&
574
- exactEventHead(value.payload.truthSummary.sourceEventHead, value.payload.eventHead) &&
575
- exactExpectedBinding(value.payload, expected, { workspace: true }) &&
576
- validWorkspacePayload(value.payload)
577
- );
519
+ return (
520
+ value.integrity.sourceViewHash === value.payload.viewHash &&
521
+ value.payload.truthSummary.sourceViewHash === value.payload.viewHash &&
522
+ exactEventHead(value.payload.truthSummary.sourceEventHead, value.payload.eventHead) &&
523
+ exactExpectedBinding(value.payload, expected, { workspace: true }) &&
524
+ validWorkspacePayload(value.payload)
525
+ );
578
526
  }
579
527
 
580
528
  function validateDisplay(value, schema, base, semantics, expected) {
581
- try {
582
- const clone = safeDataClone(value);
583
- const errors = validateJson(clone, schema, {
584
- base,
585
- resolveRef: resolveSchemaRef,
586
- });
587
- if (errors.length > 0 || !semantics(clone, expected))
588
- return validationFailure();
589
- const expectedHash = contentHash(
590
- withoutContentHash(clone),
591
- clone.integrity.domain,
592
- );
593
- return clone.integrity.contentHash === expectedHash
594
- ? []
595
- : validationFailure();
596
- } catch {
597
- return validationFailure();
598
- }
529
+ try {
530
+ const clone = safeDataClone(value);
531
+ const errors = validateJson(clone, schema, {
532
+ base,
533
+ resolveRef: resolveSchemaRef,
534
+ });
535
+ if (errors.length > 0 || !semantics(clone, expected)) return validationFailure();
536
+ const expectedHash = contentHash(withoutContentHash(clone), clone.integrity.domain);
537
+ return clone.integrity.contentHash === expectedHash ? [] : validationFailure();
538
+ } catch {
539
+ return validationFailure();
540
+ }
599
541
  }
600
542
 
601
543
  export function validateOperateExperienceDisplaySurfaceV1(value, expected) {
602
- return validateDisplay(
603
- value,
604
- displaySurfaceSchema,
605
- "schemas/v1.2.0/operate-experience-display-surface.schema.json",
606
- validDisplaySurfaceSemantics,
607
- expected,
608
- );
544
+ return validateDisplay(
545
+ value,
546
+ displaySurfaceSchema,
547
+ 'schemas/v1.2.0/operate-experience-display-surface.schema.json',
548
+ validDisplaySurfaceSemantics,
549
+ expected,
550
+ );
609
551
  }
610
552
 
611
553
  export function assertOperateExperienceDisplaySurfaceV1(value, expected) {
612
- if (validateOperateExperienceDisplaySurfaceV1(value, expected).length > 0) {
613
- const error = new TypeError(
614
- "The Operate display surface does not satisfy its closed integrity contract.",
615
- );
616
- error.code = "E_OPERATE_EXPERIENCE_DISPLAY_INVALID";
617
- throw error;
618
- }
619
- return value;
554
+ if (validateOperateExperienceDisplaySurfaceV1(value, expected).length > 0) {
555
+ const error = new TypeError(
556
+ 'The Operate display surface does not satisfy its closed integrity contract.',
557
+ );
558
+ error.code = 'E_OPERATE_EXPERIENCE_DISPLAY_INVALID';
559
+ throw error;
560
+ }
561
+ return value;
620
562
  }
621
563
 
622
564
  function exactExpectedPreview(value, expected) {
623
- if (!expected) return true;
624
- return (
625
- value.actorId === expected.actorId &&
626
- value.scopeId === expected.scopeId &&
627
- value.domainId === expected.domainId &&
628
- value.domainVersion === expected.domainVersion &&
629
- exactEventHead(value.eventHead, expected.eventHead) &&
630
- value.sourceViewHash === expected.sourceViewHash &&
631
- value.subject.id === expected.subjectId &&
632
- value.actionDigest === expected.actionDigest
633
- );
565
+ if (!expected) return true;
566
+ return (
567
+ value.actorId === expected.actorId &&
568
+ value.scopeId === expected.scopeId &&
569
+ value.domainId === expected.domainId &&
570
+ value.domainVersion === expected.domainVersion &&
571
+ exactEventHead(value.eventHead, expected.eventHead) &&
572
+ value.sourceViewHash === expected.sourceViewHash &&
573
+ value.subject.id === expected.subjectId &&
574
+ value.actionDigest === expected.actionDigest
575
+ );
634
576
  }
635
577
 
636
578
  function validPreviewTransition(transition) {
637
- if (
638
- new Set(transition.targets.map((target) => `${target.kind}:${target.id}`)).size !==
639
- transition.targets.length
640
- ) return false;
641
- if (transition.kind !== "approval") return transition.threshold === null;
642
- const threshold = transition.threshold;
643
- if (
644
- threshold === null ||
645
- threshold.recorded > threshold.required ||
646
- threshold.remaining !== threshold.required - threshold.recorded
647
- ) return false;
648
- return threshold.remaining === 0
649
- ? transition.nextState === "threshold-satisfied"
650
- : transition.nextState === "recorded-parties-remain";
579
+ if (
580
+ new Set(transition.targets.map((target) => `${target.kind}:${target.id}`)).size !==
581
+ transition.targets.length
582
+ )
583
+ return false;
584
+ if (transition.kind !== 'approval') return transition.threshold === null;
585
+ const threshold = transition.threshold;
586
+ if (
587
+ threshold === null ||
588
+ threshold.recorded > threshold.required ||
589
+ threshold.remaining !== threshold.required - threshold.recorded
590
+ )
591
+ return false;
592
+ return threshold.remaining === 0
593
+ ? transition.nextState === 'threshold-satisfied'
594
+ : transition.nextState === 'recorded-parties-remain';
651
595
  }
652
596
 
653
597
  export function validateOperateExperiencePreviewV1(value, expected) {
654
- try {
655
- const clone = safeDataClone(value);
656
- const errors = validateJson(clone, experiencePreviewSchema, {
657
- base: "schemas/v2.0.0/operate-experience-preview.schema.json",
658
- resolveRef: resolveSchemaRef,
659
- });
660
- if (
661
- errors.length > 0 ||
662
- !exactExpectedPreview(clone, expected) ||
663
- !validPreviewTransition(clone.transition)
664
- ) return errors.length > 0 ? errors : validationFailure();
665
- const base = safeDataClone(clone);
666
- delete base.previewHash;
667
- if (
668
- clone.actionDigest !== jcsHash(clone.allowedAction) ||
669
- clone.previewHash !== jcsHash(base)
670
- ) return validationFailure();
671
- return [];
672
- } catch {
673
- return validationFailure();
674
- }
598
+ try {
599
+ const clone = safeDataClone(value);
600
+ const errors = validateJson(clone, experiencePreviewSchema, {
601
+ base: 'schemas/v2.0.0/operate-experience-preview.schema.json',
602
+ resolveRef: resolveSchemaRef,
603
+ });
604
+ if (
605
+ errors.length > 0 ||
606
+ !exactExpectedPreview(clone, expected) ||
607
+ !validPreviewTransition(clone.transition)
608
+ )
609
+ return errors.length > 0 ? errors : validationFailure();
610
+ const base = safeDataClone(clone);
611
+ delete base.previewHash;
612
+ if (clone.actionDigest !== jcsHash(clone.allowedAction) || clone.previewHash !== jcsHash(base))
613
+ return validationFailure();
614
+ return [];
615
+ } catch {
616
+ return validationFailure();
617
+ }
675
618
  }
676
619
 
677
620
  export function assertOperateExperiencePreviewV1(value, expected) {
678
- if (validateOperateExperiencePreviewV1(value, expected).length > 0) {
679
- const error = new TypeError(
680
- "The Operate preview does not satisfy its closed integrity contract.",
681
- );
682
- error.code = "E_OPERATE_EXPERIENCE_PREVIEW_INVALID";
683
- throw error;
684
- }
685
- return deepFreeze(safeDataClone(value));
621
+ if (validateOperateExperiencePreviewV1(value, expected).length > 0) {
622
+ const error = new TypeError(
623
+ 'The Operate preview does not satisfy its closed integrity contract.',
624
+ );
625
+ error.code = 'E_OPERATE_EXPERIENCE_PREVIEW_INVALID';
626
+ throw error;
627
+ }
628
+ return deepFreeze(safeDataClone(value));
686
629
  }
687
630
 
688
631
  export function validateOperateCycleDisplayWorkspaceV1(value, expected) {
689
- return validateDisplay(
690
- value,
691
- cycleDisplayWorkspaceSchema,
692
- "schemas/v1.2.0/operate-cycle-display-workspace.schema.json",
693
- validWorkspaceSemantics,
694
- expected,
695
- );
632
+ return validateDisplay(
633
+ value,
634
+ cycleDisplayWorkspaceSchema,
635
+ 'schemas/v1.2.0/operate-cycle-display-workspace.schema.json',
636
+ validWorkspaceSemantics,
637
+ expected,
638
+ );
696
639
  }
697
640
 
698
641
  export function assertOperateCycleDisplayWorkspaceV1(value, expected) {
699
- if (validateOperateCycleDisplayWorkspaceV1(value, expected).length > 0) {
700
- const error = new TypeError(
701
- "The Cycle display workspace does not satisfy its closed integrity contract.",
702
- );
703
- error.code = "E_OPERATE_CYCLE_DISPLAY_INVALID";
704
- throw error;
705
- }
706
- return value;
642
+ if (validateOperateCycleDisplayWorkspaceV1(value, expected).length > 0) {
643
+ const error = new TypeError(
644
+ 'The Cycle display workspace does not satisfy its closed integrity contract.',
645
+ );
646
+ error.code = 'E_OPERATE_CYCLE_DISPLAY_INVALID';
647
+ throw error;
648
+ }
649
+ return value;
707
650
  }
708
651
 
709
652
  function issueDisplay(kind, domain, payload, assertIssued) {
710
- const base = {
711
- kind,
712
- schemaVersion: "1.0.0",
713
- protocolVersion: "2.0.0",
714
- payload: safeDataClone(payload),
715
- integrity: {
716
- algorithm: "sha-256-jcs",
717
- domain,
718
- sourceViewHash: payload.viewHash,
719
- },
720
- };
721
- const issued = {
722
- ...base,
723
- integrity: {
724
- ...base.integrity,
725
- contentHash: contentHash(base, domain),
726
- },
727
- };
728
- assertIssued(issued);
729
- return deepFreeze(issued);
653
+ const base = {
654
+ kind,
655
+ schemaVersion: '1.0.0',
656
+ protocolVersion: '2.0.0',
657
+ payload: safeDataClone(payload),
658
+ integrity: {
659
+ algorithm: 'sha-256-jcs',
660
+ domain,
661
+ sourceViewHash: payload.viewHash,
662
+ },
663
+ };
664
+ const issued = {
665
+ ...base,
666
+ integrity: {
667
+ ...base.integrity,
668
+ contentHash: contentHash(base, domain),
669
+ },
670
+ };
671
+ assertIssued(issued);
672
+ return deepFreeze(issued);
730
673
  }
731
674
 
732
675
  export function issueOperateExperienceDisplaySurfaceV1(payload) {
733
- return issueDisplay(
734
- "operate-experience-display-surface",
735
- DISPLAY_SURFACE_DOMAIN,
736
- payload,
737
- assertOperateExperienceDisplaySurfaceV1,
738
- );
676
+ return issueDisplay(
677
+ 'operate-experience-display-surface',
678
+ DISPLAY_SURFACE_DOMAIN,
679
+ payload,
680
+ assertOperateExperienceDisplaySurfaceV1,
681
+ );
739
682
  }
740
683
 
741
684
  export function issueOperateCycleDisplayWorkspaceV1(payload) {
742
- return issueDisplay(
743
- "operate-cycle-display-workspace",
744
- CYCLE_WORKSPACE_DOMAIN,
745
- payload,
746
- assertOperateCycleDisplayWorkspaceV1,
747
- );
685
+ return issueDisplay(
686
+ 'operate-cycle-display-workspace',
687
+ CYCLE_WORKSPACE_DOMAIN,
688
+ payload,
689
+ assertOperateCycleDisplayWorkspaceV1,
690
+ );
748
691
  }
749
692
 
750
693
  function validExecutiveBoardSeatAbsence(absence) {
751
- if (absence === null) return true;
752
- if (typeof absence !== "object" || Array.isArray(absence)) return false;
753
- if (absence.kind === "omitted") {
754
- return typeof absence.reason === "string" && absence.reason.length > 0;
755
- }
756
- if (absence.kind === "lens") {
757
- return (
758
- typeof absence.roleId === "string" &&
759
- typeof absence.roleKind === "string" &&
760
- typeof absence.absenceCode === "string" &&
761
- typeof absence.reason === "string"
762
- );
763
- }
764
- if (absence.kind === "terminal") {
765
- return (
766
- (absence.outcome === "abandoned" || absence.outcome === "failed") &&
767
- typeof absence.code === "string" &&
768
- typeof absence.reason === "string" &&
769
- typeof absence.recoveryDisposition === "string"
770
- );
771
- }
772
- return false;
694
+ if (absence === null) return true;
695
+ if (typeof absence !== 'object' || Array.isArray(absence)) return false;
696
+ if (absence.kind === 'omitted') {
697
+ return typeof absence.reason === 'string' && absence.reason.length > 0;
698
+ }
699
+ if (absence.kind === 'lens') {
700
+ return (
701
+ typeof absence.roleId === 'string' &&
702
+ typeof absence.roleKind === 'string' &&
703
+ typeof absence.absenceCode === 'string' &&
704
+ typeof absence.reason === 'string'
705
+ );
706
+ }
707
+ if (absence.kind === 'terminal') {
708
+ return (
709
+ (absence.outcome === 'abandoned' || absence.outcome === 'failed') &&
710
+ typeof absence.code === 'string' &&
711
+ typeof absence.reason === 'string' &&
712
+ typeof absence.recoveryDisposition === 'string'
713
+ );
714
+ }
715
+ return false;
773
716
  }
774
717
 
775
718
  function validExecutiveBoardSeat(seat) {
776
- return (
777
- typeof seat?.roleId === "string" &&
778
- typeof seat?.label === "string" &&
779
- seat.roleId !== seat.label &&
780
- typeof seat?.roleKind === "string" &&
781
- typeof seat?.roleVersion === "string" &&
782
- validExecutiveBoardSeatAbsence(seat?.absence ?? null)
783
- );
719
+ return (
720
+ typeof seat?.roleId === 'string' &&
721
+ typeof seat?.label === 'string' &&
722
+ seat.roleId !== seat.label &&
723
+ typeof seat?.roleKind === 'string' &&
724
+ typeof seat?.roleVersion === 'string' &&
725
+ validExecutiveBoardSeatAbsence(seat?.absence ?? null)
726
+ );
784
727
  }
785
728
 
786
729
  function validExecutiveBoardPayload(payload) {
787
- const board = payload?.data?.executiveBoard;
788
- if (!board || !Array.isArray(board.seats)) return false;
789
- return board.seats.every(validExecutiveBoardSeat);
730
+ const board = payload?.data?.executiveBoard;
731
+ if (!board || !Array.isArray(board.seats)) return false;
732
+ return board.seats.every(validExecutiveBoardSeat);
790
733
  }
791
734
 
792
735
  function validExecutiveBoardSemantics(value, expected) {
793
- return (
794
- value.integrity.sourceViewHash === value.payload.viewHash &&
795
- exactExpectedBinding(value.payload, expected, { executiveBoard: true }) &&
796
- validExecutiveBoardPayload(value.payload)
797
- );
736
+ return (
737
+ value.integrity.sourceViewHash === value.payload.viewHash &&
738
+ exactExpectedBinding(value.payload, expected, { executiveBoard: true }) &&
739
+ validExecutiveBoardPayload(value.payload)
740
+ );
798
741
  }
799
742
 
800
743
  export function validateOperateExecutiveBoardDisplaySurfaceV1(value, expected) {
801
- return validateDisplay(
802
- value,
803
- executiveBoardDisplaySurfaceSchema,
804
- "schemas/v1.2.0/operate-executive-board-display-surface.schema.json",
805
- validExecutiveBoardSemantics,
806
- expected,
807
- );
744
+ return validateDisplay(
745
+ value,
746
+ executiveBoardDisplaySurfaceSchema,
747
+ 'schemas/v1.2.0/operate-executive-board-display-surface.schema.json',
748
+ validExecutiveBoardSemantics,
749
+ expected,
750
+ );
808
751
  }
809
752
 
810
753
  export function assertOperateExecutiveBoardDisplaySurfaceV1(value, expected) {
811
- if (validateOperateExecutiveBoardDisplaySurfaceV1(value, expected).length > 0) {
812
- const error = new TypeError(
813
- "The executive board display surface does not satisfy its closed integrity contract.",
814
- );
815
- error.code = "E_OPERATE_EXECUTIVE_BOARD_DISPLAY_INVALID";
816
- throw error;
817
- }
818
- return value;
754
+ if (validateOperateExecutiveBoardDisplaySurfaceV1(value, expected).length > 0) {
755
+ const error = new TypeError(
756
+ 'The executive board display surface does not satisfy its closed integrity contract.',
757
+ );
758
+ error.code = 'E_OPERATE_EXECUTIVE_BOARD_DISPLAY_INVALID';
759
+ throw error;
760
+ }
761
+ return value;
819
762
  }
820
763
 
821
764
  export function issueOperateExecutiveBoardDisplaySurfaceV1(payload) {
822
- return issueDisplay(
823
- "operate-executive-board-display-surface",
824
- EXECUTIVE_BOARD_DISPLAY_DOMAIN,
825
- payload,
826
- assertOperateExecutiveBoardDisplaySurfaceV1,
827
- );
765
+ return issueDisplay(
766
+ 'operate-executive-board-display-surface',
767
+ EXECUTIVE_BOARD_DISPLAY_DOMAIN,
768
+ payload,
769
+ assertOperateExecutiveBoardDisplaySurfaceV1,
770
+ );
828
771
  }
829
772
 
830
773
  function actionDeepLink(actionId) {
831
- return `#/operate/actions/${encodeURIComponent(actionId)}`;
774
+ return `#/operate/actions/${encodeURIComponent(actionId)}`;
832
775
  }
833
776
 
834
777
  function verificationFromOutcome(outcome) {
835
- if (outcome === null) {
836
- return Object.freeze({
837
- status: "not-required",
838
- reasonCodes: Object.freeze([]),
839
- });
840
- }
841
- if (outcome.status === "insufficient-evidence") {
842
- return Object.freeze({
843
- status: "unverified",
844
- reasonCodes: Object.freeze(["OPERATE_VERIFICATION_EVIDENCE_MISSING"]),
845
- });
846
- }
847
- if (
848
- ["succeeded", "failed"].includes(outcome.status) &&
849
- outcomeCarriesAffirmativeProof(outcome)
850
- ) {
851
- return Object.freeze({
852
- status: "verified",
853
- reasonCodes: Object.freeze([]),
854
- });
855
- }
856
- return Object.freeze({
857
- status: "unverified",
858
- reasonCodes: Object.freeze(["OPERATE_VERIFICATION_EVIDENCE_MISSING"]),
859
- });
778
+ if (outcome === null) {
779
+ return Object.freeze({
780
+ status: 'not-required',
781
+ reasonCodes: Object.freeze([]),
782
+ });
783
+ }
784
+ if (outcome.status === 'insufficient-evidence') {
785
+ return Object.freeze({
786
+ status: 'unverified',
787
+ reasonCodes: Object.freeze(['OPERATE_VERIFICATION_EVIDENCE_MISSING']),
788
+ });
789
+ }
790
+ if (['succeeded', 'failed'].includes(outcome.status) && outcomeCarriesAffirmativeProof(outcome)) {
791
+ return Object.freeze({
792
+ status: 'verified',
793
+ reasonCodes: Object.freeze([]),
794
+ });
795
+ }
796
+ return Object.freeze({
797
+ status: 'unverified',
798
+ reasonCodes: Object.freeze(['OPERATE_VERIFICATION_EVIDENCE_MISSING']),
799
+ });
860
800
  }
861
801
 
862
802
  function recoveryStateFromInspection(inspection) {
863
- const status = inspection?.status;
864
- if (status === "healthy" || status === "empty") return "restored";
865
- if (status === "corrupt") return "corrupt";
866
- if (status === "incompatible") return "incompatible";
867
- if (status === "locked") return "blocked";
868
- if (status === "repairable") {
869
- if (inspection.allowedRecovery === "clear-stale-lock") return "blocked";
870
- if (inspection.allowedRecovery === "restore-generation") return "uncertain";
871
- return "uncertain";
872
- }
873
- return "blocked";
803
+ const status = inspection?.status;
804
+ if (status === 'healthy' || status === 'empty') return 'restored';
805
+ if (status === 'corrupt') return 'corrupt';
806
+ if (status === 'incompatible') return 'incompatible';
807
+ if (status === 'locked') return 'blocked';
808
+ if (status === 'repairable') {
809
+ if (inspection.allowedRecovery === 'clear-stale-lock') return 'blocked';
810
+ if (inspection.allowedRecovery === 'restore-generation') return 'uncertain';
811
+ return 'uncertain';
812
+ }
813
+ return 'blocked';
874
814
  }
875
815
 
876
816
  function validActionWorkspacePayload(payload) {
877
- const data = payload.data;
878
- const action = data.action;
879
- const expectedDeepLink = actionDeepLink(action.actionId);
880
- const allowedActions = data.allowedActions;
881
- const outcome = data.outcome;
882
- const verification = verificationFromOutcome(outcome);
883
- const commandable = allowedActions.some(
884
- (entry) => entry.action.effect !== "read-only",
885
- );
886
- if (
887
- payload.readOnly === payload.mutationEnabled ||
888
- (payload.mutationEnabled && (payload.status !== "ready" || !commandable)) ||
889
- action.deepLink !== expectedDeepLink ||
890
- !exactJson(data.boundaries, ACTION_WORKSPACE_BOUNDARIES) ||
891
- !exactJson(data.verification, verification) ||
892
- !exactJson(data.replay.finalHead, payload.eventHead) ||
893
- allowedActions.some((entry) => entry.subjectId !== action.actionId) ||
894
- data.inbox.some((item) => item.subjectId !== action.actionId) ||
895
- data.learnings.some(
896
- (learning) =>
897
- outcome === null || learning.outcomeId !== outcome.outcomeId,
898
- ) ||
899
- (outcome !== null && outcome.actionId !== action.actionId)
900
- )
901
- return false;
902
- return true;
817
+ const data = payload.data;
818
+ const action = data.action;
819
+ const expectedDeepLink = actionDeepLink(action.actionId);
820
+ const allowedActions = data.allowedActions;
821
+ const outcome = data.outcome;
822
+ const verification = verificationFromOutcome(outcome);
823
+ const commandable = allowedActions.some((entry) => entry.action.effect !== 'read-only');
824
+ if (
825
+ payload.readOnly === payload.mutationEnabled ||
826
+ (payload.mutationEnabled && (payload.status !== 'ready' || !commandable)) ||
827
+ action.deepLink !== expectedDeepLink ||
828
+ !exactJson(data.boundaries, ACTION_WORKSPACE_BOUNDARIES) ||
829
+ !exactJson(data.verification, verification) ||
830
+ !exactJson(data.replay.finalHead, payload.eventHead) ||
831
+ allowedActions.some((entry) => entry.subjectId !== action.actionId) ||
832
+ data.inbox.some((item) => item.subjectId !== action.actionId) ||
833
+ data.learnings.some(
834
+ (learning) => outcome === null || learning.outcomeId !== outcome.outcomeId,
835
+ ) ||
836
+ (outcome !== null && outcome.actionId !== action.actionId)
837
+ )
838
+ return false;
839
+ return true;
903
840
  }
904
841
 
905
842
  function validActionWorkspaceSemantics(value, expected) {
906
- return (
907
- value.integrity.sourceViewHash === value.payload.viewHash &&
908
- exactExpectedBinding(value.payload, expected, { workspace: true, action: true }) &&
909
- validActionWorkspacePayload(value.payload)
910
- );
843
+ return (
844
+ value.integrity.sourceViewHash === value.payload.viewHash &&
845
+ exactExpectedBinding(value.payload, expected, { workspace: true, action: true }) &&
846
+ validActionWorkspacePayload(value.payload)
847
+ );
911
848
  }
912
849
 
913
850
  export function validateOperateActionDisplayWorkspaceV1(value, expected) {
914
- return validateDisplay(
915
- value,
916
- actionDisplayWorkspaceSchema,
917
- "schemas/v1.2.0/operate-action-display-workspace.schema.json",
918
- validActionWorkspaceSemantics,
919
- expected,
920
- );
851
+ return validateDisplay(
852
+ value,
853
+ actionDisplayWorkspaceSchema,
854
+ 'schemas/v1.2.0/operate-action-display-workspace.schema.json',
855
+ validActionWorkspaceSemantics,
856
+ expected,
857
+ );
921
858
  }
922
859
 
923
860
  export function assertOperateActionDisplayWorkspaceV1(value, expected) {
924
- if (validateOperateActionDisplayWorkspaceV1(value, expected).length > 0) {
925
- const error = new TypeError(
926
- "The Action display workspace does not satisfy its closed integrity contract.",
927
- );
928
- error.code = "E_OPERATE_ACTION_DISPLAY_INVALID";
929
- throw error;
930
- }
931
- return value;
861
+ if (validateOperateActionDisplayWorkspaceV1(value, expected).length > 0) {
862
+ const error = new TypeError(
863
+ 'The Action display workspace does not satisfy its closed integrity contract.',
864
+ );
865
+ error.code = 'E_OPERATE_ACTION_DISPLAY_INVALID';
866
+ throw error;
867
+ }
868
+ return value;
932
869
  }
933
870
 
934
871
  export function issueOperateActionDisplayWorkspaceV1(payload) {
935
- return issueDisplay(
936
- "operate-action-display-workspace",
937
- ACTION_WORKSPACE_DOMAIN,
938
- payload,
939
- assertOperateActionDisplayWorkspaceV1,
940
- );
872
+ return issueDisplay(
873
+ 'operate-action-display-workspace',
874
+ ACTION_WORKSPACE_DOMAIN,
875
+ payload,
876
+ assertOperateActionDisplayWorkspaceV1,
877
+ );
941
878
  }
942
879
 
943
880
  function validRecoveryDisplayPayload(payload) {
944
- const data = payload.data;
945
- if (
946
- "integrityBoundary" in data.inspection ||
947
- data.recoveryState !== recoveryStateFromInspection(data.inspection)
948
- )
949
- return false;
950
- return true;
881
+ const data = payload.data;
882
+ if (
883
+ 'integrityBoundary' in data.inspection ||
884
+ data.recoveryState !== recoveryStateFromInspection(data.inspection)
885
+ )
886
+ return false;
887
+ return true;
951
888
  }
952
889
 
953
890
  function validRecoveryDisplaySemantics(value, expected) {
954
- return (
955
- value.integrity.sourceViewHash === value.payload.viewHash &&
956
- exactExpectedBinding(value.payload, expected, { workspace: true, recovery: true }) &&
957
- validRecoveryDisplayPayload(value.payload)
958
- );
891
+ return (
892
+ value.integrity.sourceViewHash === value.payload.viewHash &&
893
+ exactExpectedBinding(value.payload, expected, { workspace: true, recovery: true }) &&
894
+ validRecoveryDisplayPayload(value.payload)
895
+ );
959
896
  }
960
897
 
961
898
  export function validateOperateRecoveryDisplaySurfaceV1(value, expected) {
962
- return validateDisplay(
963
- value,
964
- recoveryDisplaySurfaceSchema,
965
- "schemas/v1.2.0/operate-recovery-display-surface.schema.json",
966
- validRecoveryDisplaySemantics,
967
- expected,
968
- );
899
+ return validateDisplay(
900
+ value,
901
+ recoveryDisplaySurfaceSchema,
902
+ 'schemas/v1.2.0/operate-recovery-display-surface.schema.json',
903
+ validRecoveryDisplaySemantics,
904
+ expected,
905
+ );
969
906
  }
970
907
 
971
908
  export function assertOperateRecoveryDisplaySurfaceV1(value, expected) {
972
- if (validateOperateRecoveryDisplaySurfaceV1(value, expected).length > 0) {
973
- const error = new TypeError(
974
- "The recovery display surface does not satisfy its closed integrity contract.",
975
- );
976
- error.code = "E_OPERATE_RECOVERY_DISPLAY_INVALID";
977
- throw error;
978
- }
979
- return value;
909
+ if (validateOperateRecoveryDisplaySurfaceV1(value, expected).length > 0) {
910
+ const error = new TypeError(
911
+ 'The recovery display surface does not satisfy its closed integrity contract.',
912
+ );
913
+ error.code = 'E_OPERATE_RECOVERY_DISPLAY_INVALID';
914
+ throw error;
915
+ }
916
+ return value;
980
917
  }
981
918
 
982
919
  export function issueOperateRecoveryDisplaySurfaceV1(payload) {
983
- return issueDisplay(
984
- "operate-recovery-display-surface",
985
- RECOVERY_DISPLAY_DOMAIN,
986
- payload,
987
- assertOperateRecoveryDisplaySurfaceV1,
988
- );
920
+ return issueDisplay(
921
+ 'operate-recovery-display-surface',
922
+ RECOVERY_DISPLAY_DOMAIN,
923
+ payload,
924
+ assertOperateRecoveryDisplaySurfaceV1,
925
+ );
989
926
  }
990
927
 
991
928
  export const OPERATE_ACTION_DISPLAY_WORKSPACE_SCHEMA_V1 = Object.freeze(
992
- structuredClone(actionDisplayWorkspaceSchema),
929
+ structuredClone(actionDisplayWorkspaceSchema),
993
930
  );
994
931
  export const OPERATE_RECOVERY_DISPLAY_SURFACE_SCHEMA_V1 = Object.freeze(
995
- structuredClone(recoveryDisplaySurfaceSchema),
932
+ structuredClone(recoveryDisplaySurfaceSchema),
996
933
  );
997
934
 
998
935
  export const OPERATE_EXECUTIVE_BOARD_DISPLAY_SURFACE_SCHEMA_V1 = Object.freeze(
999
- structuredClone(executiveBoardDisplaySurfaceSchema),
936
+ structuredClone(executiveBoardDisplaySurfaceSchema),
1000
937
  );
1001
938
 
1002
939
  export const OPERATE_EXPERIENCE_DISPLAY_SURFACE_SCHEMA_V1 = Object.freeze(
1003
- structuredClone(displaySurfaceSchema),
940
+ structuredClone(displaySurfaceSchema),
1004
941
  );
1005
942
  export const OPERATE_CYCLE_DISPLAY_WORKSPACE_SCHEMA_V1 = Object.freeze(
1006
- structuredClone(cycleDisplayWorkspaceSchema),
943
+ structuredClone(cycleDisplayWorkspaceSchema),
1007
944
  );