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