@sentropic/track 0.98.5 → 0.98.7-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,127 @@
1
+ {
2
+ "format": "sentropic.registry-package/v1",
3
+ "entries": [
4
+ {
5
+ "format": "sentropic.registry-entry/v1",
6
+ "contractVersion": "1.1.4",
7
+ "kind": "skill",
8
+ "id": "sentropic.focus",
9
+ "name": "focus",
10
+ "description": "Prepare, explain and review a read-only decision-dossier snapshot (DecisionDossierDocument v1): sections, options, outcome, disabled affordances and verbatim comprehension evidence. Snapshot only — no decisions, signatures, amendments or Track writes.",
11
+ "entryVersion": "1.0.0",
12
+ "publisher": {
13
+ "packageName": "@sentropic/focus",
14
+ "packageVersion": "0.5.0"
15
+ },
16
+ "compatibility": {
17
+ "entryContract": "1.1.4",
18
+ "packages": [
19
+ {
20
+ "name": "@sentropic/track",
21
+ "range": "^0.98.6"
22
+ }
23
+ ],
24
+ "schemaProfiles": [
25
+ "sentropic.parameters/2020-12-bounded-v1"
26
+ ],
27
+ "requiredHostFeatures": [],
28
+ "optionalHostFeatures": [
29
+ "terminal",
30
+ "markdown",
31
+ "html-sanitization",
32
+ "mcp-app-ui"
33
+ ]
34
+ },
35
+ "parameters": {
36
+ "schemaVersion": "1.0.0",
37
+ "schema": {
38
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
39
+ "$id": "urn:sentropic:registry:parameters:sentropic.focus:1.0.0",
40
+ "type": "object",
41
+ "additionalProperties": false,
42
+ "required": [
43
+ "mode",
44
+ "preferredPresentation",
45
+ "locale"
46
+ ],
47
+ "properties": {
48
+ "mode": {
49
+ "const": "snapshot"
50
+ },
51
+ "preferredPresentation": {
52
+ "enum": [
53
+ "terminal",
54
+ "markdown",
55
+ "html",
56
+ "mcp-app"
57
+ ]
58
+ },
59
+ "locale": {
60
+ "enum": [
61
+ "en",
62
+ "fr"
63
+ ]
64
+ }
65
+ }
66
+ },
67
+ "defaults": {
68
+ "mode": "snapshot",
69
+ "preferredPresentation": "markdown",
70
+ "locale": "en"
71
+ }
72
+ },
73
+ "bindings": [],
74
+ "assets": [
75
+ {
76
+ "role": "skill-instructions",
77
+ "path": "skills/focus/SKILL.md",
78
+ "mediaType": "text/markdown",
79
+ "sha256": "750e5ef2cf894e5c90227acb15911aab583ce7e3949c1d82a2ea40fabd8c97e5"
80
+ },
81
+ {
82
+ "role": "document-schema",
83
+ "path": "schemas/decision-dossier-document.v1.schema.json",
84
+ "mediaType": "application/schema+json",
85
+ "sha256": "4b56940212f5a10d01572f7fa6404238a683e5fc1ebde75c5492edb3916c9f5d"
86
+ }
87
+ ],
88
+ "skill": {
89
+ "profile": "instructions",
90
+ "metadata": {
91
+ "category": "decision",
92
+ "contextFilters": [
93
+ "decision-dossier"
94
+ ],
95
+ "permissions": [
96
+ "track.dossier.read"
97
+ ],
98
+ "toolNames": []
99
+ },
100
+ "instructionsAsset": "skills/focus/SKILL.md",
101
+ "capabilities": [
102
+ {
103
+ "id": "sentropic.focus.decision-dossier",
104
+ "description": "Prepare, explain and review a read-only decision-dossier snapshot under the host's own permissions; never signs, amends or writes.",
105
+ "effect": "read-only",
106
+ "permissions": [
107
+ "track.dossier.read"
108
+ ],
109
+ "inputSchemaRef": "urn:sentropic:focus:DecisionDossierDocument:1.0.0",
110
+ "outputSchemaRef": "urn:sentropic:focus:DecisionDossierDocument:1.0.0"
111
+ }
112
+ ],
113
+ "tools": [],
114
+ "documentSchemas": [
115
+ {
116
+ "name": "DecisionDossierDocument",
117
+ "schemaId": "urn:sentropic:focus:DecisionDossierDocument:1.0.0",
118
+ "version": "1.0.0",
119
+ "assetPath": "schemas/decision-dossier-document.v1.schema.json",
120
+ "sha256": "4b56940212f5a10d01572f7fa6404238a683e5fc1ebde75c5492edb3916c9f5d"
121
+ }
122
+ ],
123
+ "dependencies": []
124
+ }
125
+ }
126
+ ]
127
+ }
@@ -0,0 +1,107 @@
1
+ /**
2
+ * `@sentropic/focus/validate` — the typed runtime validator for the
3
+ * `DecisionDossierDocument` (contract §4.2, R4).
4
+ *
5
+ * Two layers, matching the published JSON Schema asset
6
+ * (`schemas/decision-dossier-document.v1.schema.json`,
7
+ * `urn:sentropic:focus:DecisionDossierDocument:1.0.0`):
8
+ *
9
+ * 1. structure — closed shape check (unknown fields, wrong types, bad enums,
10
+ * an enabled snapshot interaction all refuse);
11
+ * 2. semantics — unique node IDs, interaction targets resolvable to the
12
+ * dossier ref, a section id/targetRef or a nested option id/targetRef,
13
+ * an opaque provenance source binding (any string, per the published
14
+ * schema), and comprehension evidence whose dossier hash still matches
15
+ * the snapshot hash.
16
+ *
17
+ * Pure and dependency-free: no I/O, no clock, no mutation of the input.
18
+ * Every recorded issue is a refusal — the schema is closed.
19
+ */
20
+ /** Stable schema ID of the published DecisionDossierDocument asset. */
21
+ export const DOSSIER_SCHEMA_ID: "urn:sentropic:focus:DecisionDossierDocument:1.0.0";
22
+ /** Version of the dossier schema, independent of the package version. */
23
+ export const DOSSIER_SCHEMA_VERSION: "1.0.0";
24
+ /** Thrown by {@link assertDecisionDossierDocument} on an invalid dossier. */
25
+ export class DecisionDossierValidationError extends Error {
26
+ constructor(issues: any);
27
+ issues: any;
28
+ }
29
+ export function validateDecisionDossierStructure(value: any): {
30
+ ok: boolean;
31
+ issues: any[];
32
+ value?: never;
33
+ } | {
34
+ ok: boolean;
35
+ value: {
36
+ ref: string;
37
+ subject: string;
38
+ title: string;
39
+ hash: string;
40
+ cursor: string;
41
+ sections: any[];
42
+ interactions: any[];
43
+ provenance: {
44
+ comprehensionEvidence?: {
45
+ signature?: string;
46
+ subject: any;
47
+ dossierHash: any;
48
+ };
49
+ source: any;
50
+ readAt: any;
51
+ };
52
+ amendmentTrace: any[];
53
+ };
54
+ issues?: never;
55
+ };
56
+ export function validateDecisionDossierSemantics(doc: any): {
57
+ path: any;
58
+ code: any;
59
+ message: any;
60
+ }[];
61
+ export function validateDecisionDossierDocument(value: any): {
62
+ ok: boolean;
63
+ issues: any[];
64
+ value?: never;
65
+ } | {
66
+ ok: boolean;
67
+ value: {
68
+ ref: string;
69
+ subject: string;
70
+ title: string;
71
+ hash: string;
72
+ cursor: string;
73
+ sections: any[];
74
+ interactions: any[];
75
+ provenance: {
76
+ comprehensionEvidence?: {
77
+ signature?: string;
78
+ subject: any;
79
+ dossierHash: any;
80
+ };
81
+ source: any;
82
+ readAt: any;
83
+ };
84
+ amendmentTrace: any[];
85
+ };
86
+ issues?: never;
87
+ };
88
+ export function assertDecisionDossierDocument(value: any): {
89
+ ref: string;
90
+ subject: string;
91
+ title: string;
92
+ hash: string;
93
+ cursor: string;
94
+ sections: any[];
95
+ interactions: any[];
96
+ provenance: {
97
+ comprehensionEvidence?: {
98
+ signature?: string;
99
+ subject: any;
100
+ dossierHash: any;
101
+ };
102
+ source: any;
103
+ readAt: any;
104
+ };
105
+ amendmentTrace: any[];
106
+ } | undefined;
107
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/focus-vendor/validation/index.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,uEAAuE;AACvE,gCAAiC,mDAAmD,CAAC;AACrF,yEAAyE;AACzE,qCAAsC,OAAO,CAAC;AAC9C,6EAA6E;AAC7E;IAEI,yBAMC;IAPD,YAAO;CAQV;AA0NM;;;;;;;;;;;;;;;;;;;;;;;;;;EAoFN;AAEM;;;;IAiDN;AAEM;;;;;;;;;;;;;;;;;;;;;;;;;;EAQN;AAEM;;;;;;;;;;;;;;;;;;cAKN"}
@@ -0,0 +1,405 @@
1
+ /**
2
+ * `@sentropic/focus/validate` — the typed runtime validator for the
3
+ * `DecisionDossierDocument` (contract §4.2, R4).
4
+ *
5
+ * Two layers, matching the published JSON Schema asset
6
+ * (`schemas/decision-dossier-document.v1.schema.json`,
7
+ * `urn:sentropic:focus:DecisionDossierDocument:1.0.0`):
8
+ *
9
+ * 1. structure — closed shape check (unknown fields, wrong types, bad enums,
10
+ * an enabled snapshot interaction all refuse);
11
+ * 2. semantics — unique node IDs, interaction targets resolvable to the
12
+ * dossier ref, a section id/targetRef or a nested option id/targetRef,
13
+ * an opaque provenance source binding (any string, per the published
14
+ * schema), and comprehension evidence whose dossier hash still matches
15
+ * the snapshot hash.
16
+ *
17
+ * Pure and dependency-free: no I/O, no clock, no mutation of the input.
18
+ * Every recorded issue is a refusal — the schema is closed.
19
+ */
20
+ /** Stable schema ID of the published DecisionDossierDocument asset. */
21
+ export const DOSSIER_SCHEMA_ID = "urn:sentropic:focus:DecisionDossierDocument:1.0.0";
22
+ /** Version of the dossier schema, independent of the package version. */
23
+ export const DOSSIER_SCHEMA_VERSION = "1.0.0";
24
+ /** Thrown by {@link assertDecisionDossierDocument} on an invalid dossier. */
25
+ export class DecisionDossierValidationError extends Error {
26
+ issues;
27
+ constructor(issues) {
28
+ super(`invalid DecisionDossierDocument: ${issues
29
+ .map((issue) => `${issue.path} ${issue.code}`)
30
+ .join("; ")}`);
31
+ this.name = "DecisionDossierValidationError";
32
+ this.issues = issues;
33
+ }
34
+ }
35
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
36
+ const issue = (path, code, message) => ({
37
+ path,
38
+ code,
39
+ message,
40
+ });
41
+ /**
42
+ * Closed-object check: unknown keys refuse, required keys must be present,
43
+ * and `stringKeys` members must be strings when present (a missing required
44
+ * string key therefore yields exactly one `missing_field`).
45
+ */
46
+ const checkClosedObject = (value, path, allowed, required, stringKeys, issues) => {
47
+ if (!isRecord(value)) {
48
+ issues.push(issue(path, "invalid_type", "expected an object"));
49
+ return undefined;
50
+ }
51
+ const allowedSet = new Set(allowed);
52
+ for (const key of Object.keys(value)) {
53
+ if (!allowedSet.has(key)) {
54
+ issues.push(issue(`${path}.${key}`, "unknown_field", "field not in the closed schema"));
55
+ }
56
+ }
57
+ for (const key of required) {
58
+ if (value[key] === undefined) {
59
+ issues.push(issue(`${path}.${key}`, "missing_field", "required field is missing"));
60
+ }
61
+ }
62
+ for (const key of stringKeys) {
63
+ if (value[key] !== undefined && typeof value[key] !== "string") {
64
+ issues.push(issue(`${path}.${key}`, "invalid_type", "expected a string"));
65
+ }
66
+ }
67
+ return value;
68
+ };
69
+ const checkEnum = (value, path, allowed, issues) => {
70
+ if (typeof value !== "string" || !allowed.includes(value)) {
71
+ issues.push(issue(path, "invalid_enum", `expected one of: ${allowed.join(" | ")}`));
72
+ }
73
+ };
74
+ const TOP_REQUIRED = [
75
+ "ref",
76
+ "subject",
77
+ "title",
78
+ "hash",
79
+ "cursor",
80
+ "sections",
81
+ "interactions",
82
+ "provenance",
83
+ "amendmentTrace",
84
+ ];
85
+ const TOP_STRINGS = ["ref", "subject", "title", "hash", "cursor"];
86
+ const checkOptionNode = (value, path, issues) => {
87
+ const start = issues.length;
88
+ const node = checkClosedObject(value, path, ["kind", "id", "targetRef", "label", "body", "annotation", "annotationComment"], ["kind", "id", "targetRef", "label", "annotation"], ["id", "targetRef", "label", "body", "annotationComment"], issues);
89
+ if (node === undefined)
90
+ return undefined;
91
+ if (node["kind"] !== "option") {
92
+ issues.push(issue(`${path}.kind`, "invalid_discriminator", 'expected "option"'));
93
+ }
94
+ checkEnum(node["annotation"], `${path}.annotation`, ["none", "accept", "reject", "comment"], issues);
95
+ if (issues.length !== start)
96
+ return undefined;
97
+ return {
98
+ kind: "option",
99
+ id: node["id"],
100
+ targetRef: node["targetRef"],
101
+ label: node["label"],
102
+ ...(typeof node["body"] === "string" ? { body: node["body"] } : {}),
103
+ annotation: node["annotation"],
104
+ ...(typeof node["annotationComment"] === "string"
105
+ ? { annotationComment: node["annotationComment"] }
106
+ : {}),
107
+ };
108
+ };
109
+ const checkAmendmentStep = (value, path, issues) => {
110
+ const start = issues.length;
111
+ const step = checkClosedObject(value, path, ["at", "author", "summary"], ["at", "author", "summary"], ["at", "author", "summary"], issues);
112
+ if (step === undefined || issues.length !== start)
113
+ return undefined;
114
+ return { at: step["at"], author: step["author"], summary: step["summary"] };
115
+ };
116
+ const checkSectionNode = (value, path, issues) => {
117
+ if (!isRecord(value)) {
118
+ issues.push(issue(path, "invalid_type", "expected an object"));
119
+ return undefined;
120
+ }
121
+ const kind = value["kind"];
122
+ if (kind !== "prose" && kind !== "question" && kind !== "optionSet" && kind !== "outcome" && kind !== "amendmentTrace" && kind !== "diagram") {
123
+ issues.push(issue(`${path}.kind`, typeof kind === "undefined" ? "missing_field" : "unknown_node_kind", `unknown section kind ${typeof kind === "string" ? `"${kind}"` : " discriminant"}`));
124
+ return undefined;
125
+ }
126
+ const start = issues.length;
127
+ switch (kind) {
128
+ case "prose": {
129
+ const node = checkClosedObject(value, path, ["kind", "id", "targetRef", "markdown"], ["kind", "id", "targetRef", "markdown"], ["id", "targetRef", "markdown"], issues);
130
+ if (node === undefined || issues.length !== start)
131
+ return undefined;
132
+ return { kind: "prose", id: node["id"], targetRef: node["targetRef"], markdown: node["markdown"] };
133
+ }
134
+ case "question": {
135
+ const node = checkClosedObject(value, path, ["kind", "id", "targetRef", "question", "recommendedAnswer", "answer", "state"], ["kind", "id", "targetRef", "question", "state"], ["id", "targetRef", "question", "recommendedAnswer", "answer"], issues);
136
+ if (node === undefined)
137
+ return undefined;
138
+ checkEnum(node["state"], `${path}.state`, ["open", "answered", "validated"], issues);
139
+ if (issues.length !== start)
140
+ return undefined;
141
+ return {
142
+ kind: "question",
143
+ id: node["id"],
144
+ targetRef: node["targetRef"],
145
+ question: node["question"],
146
+ ...(typeof node["recommendedAnswer"] === "string" ? { recommendedAnswer: node["recommendedAnswer"] } : {}),
147
+ ...(typeof node["answer"] === "string" ? { answer: node["answer"] } : {}),
148
+ state: node["state"],
149
+ };
150
+ }
151
+ case "optionSet": {
152
+ const node = checkClosedObject(value, path, ["kind", "id", "targetRef", "title", "options"], ["kind", "id", "targetRef", "options"], ["id", "targetRef", "title"], issues);
153
+ if (node === undefined)
154
+ return undefined;
155
+ const options = [];
156
+ if (!Array.isArray(node["options"])) {
157
+ issues.push(issue(`${path}.options`, "invalid_type", "expected an array"));
158
+ }
159
+ else {
160
+ node["options"].forEach((option, index) => {
161
+ const checked = checkOptionNode(option, `${path}.options[${index}]`, issues);
162
+ if (checked !== undefined)
163
+ options.push(checked);
164
+ });
165
+ }
166
+ if (issues.length !== start)
167
+ return undefined;
168
+ return {
169
+ kind: "optionSet",
170
+ id: node["id"],
171
+ targetRef: node["targetRef"],
172
+ ...(typeof node["title"] === "string" ? { title: node["title"] } : {}),
173
+ options,
174
+ };
175
+ }
176
+ case "outcome": {
177
+ const node = checkClosedObject(value, path, ["kind", "id", "targetRef", "modality", "statement"], ["kind", "id", "targetRef", "modality", "statement"], ["id", "targetRef", "statement"], issues);
178
+ if (node === undefined)
179
+ return undefined;
180
+ checkEnum(node["modality"], `${path}.modality`, ["decision", "orientation", "amendment", "comment"], issues);
181
+ if (issues.length !== start)
182
+ return undefined;
183
+ return {
184
+ kind: "outcome",
185
+ id: node["id"],
186
+ targetRef: node["targetRef"],
187
+ modality: node["modality"],
188
+ statement: node["statement"],
189
+ };
190
+ }
191
+ case "amendmentTrace": {
192
+ const node = checkClosedObject(value, path, ["kind", "id", "targetRef", "steps"], ["kind", "id", "targetRef", "steps"], ["id", "targetRef"], issues);
193
+ if (node === undefined)
194
+ return undefined;
195
+ const steps = [];
196
+ if (!Array.isArray(node["steps"])) {
197
+ issues.push(issue(`${path}.steps`, "invalid_type", "expected an array"));
198
+ }
199
+ else {
200
+ node["steps"].forEach((step, index) => {
201
+ const checked = checkAmendmentStep(step, `${path}.steps[${index}]`, issues);
202
+ if (checked !== undefined)
203
+ steps.push(checked);
204
+ });
205
+ }
206
+ if (issues.length !== start)
207
+ return undefined;
208
+ return {
209
+ kind: "amendmentTrace",
210
+ id: node["id"],
211
+ targetRef: node["targetRef"],
212
+ steps,
213
+ };
214
+ }
215
+ case "diagram": {
216
+ const node = checkClosedObject(value, path, ["kind", "id", "targetRef", "syntax", "source", "alt"], ["kind", "id", "targetRef", "syntax", "source", "alt"], ["id", "targetRef", "source", "alt"], issues);
217
+ if (node === undefined)
218
+ return undefined;
219
+ checkEnum(node["syntax"], `${path}.syntax`, ["mermaid", "plantuml"], issues);
220
+ if (issues.length !== start)
221
+ return undefined;
222
+ return {
223
+ kind: "diagram",
224
+ id: node["id"],
225
+ targetRef: node["targetRef"],
226
+ syntax: node["syntax"],
227
+ source: node["source"],
228
+ alt: node["alt"],
229
+ };
230
+ }
231
+ }
232
+ };
233
+ const checkInteraction = (value, path, issues) => {
234
+ const start = issues.length;
235
+ const affordance = checkClosedObject(value, path, ["name", "targetRef", "label", "enabled"], ["name", "targetRef", "label", "enabled"], ["name", "targetRef", "label"], issues);
236
+ if (affordance === undefined)
237
+ return undefined;
238
+ // The snapshot profile is read-only: an enabled affordance is never valid here.
239
+ if (affordance["enabled"] !== false) {
240
+ issues.push(issue(`${path}.enabled`, "enabled_action", "snapshot interactions must stay disabled (enabled:false)"));
241
+ }
242
+ if (issues.length !== start)
243
+ return undefined;
244
+ return {
245
+ name: affordance["name"],
246
+ targetRef: affordance["targetRef"],
247
+ label: affordance["label"],
248
+ enabled: false,
249
+ };
250
+ };
251
+ /** Structural layer: closed shape check against the published schema. */
252
+ export const validateDecisionDossierStructure = (value) => {
253
+ const issues = [];
254
+ const doc = checkClosedObject(value, "$", [...TOP_REQUIRED], [...TOP_REQUIRED], [...TOP_STRINGS], issues);
255
+ if (doc === undefined)
256
+ return { ok: false, issues };
257
+ const sections = [];
258
+ if (!Array.isArray(doc["sections"])) {
259
+ issues.push(issue("$.sections", "invalid_type", "expected an array"));
260
+ }
261
+ else {
262
+ doc["sections"].forEach((section, index) => {
263
+ const checked = checkSectionNode(section, `$.sections[${index}]`, issues);
264
+ if (checked !== undefined)
265
+ sections.push(checked);
266
+ });
267
+ }
268
+ const interactions = [];
269
+ if (!Array.isArray(doc["interactions"])) {
270
+ issues.push(issue("$.interactions", "invalid_type", "expected an array"));
271
+ }
272
+ else {
273
+ doc["interactions"].forEach((interaction, index) => {
274
+ const checked = checkInteraction(interaction, `$.interactions[${index}]`, issues);
275
+ if (checked !== undefined)
276
+ interactions.push(checked);
277
+ });
278
+ }
279
+ let provenance;
280
+ const rawProvenance = checkClosedObject(doc["provenance"], "$.provenance", ["source", "readAt", "comprehensionEvidence"], ["source", "readAt"], ["source", "readAt"], issues);
281
+ if (rawProvenance !== undefined) {
282
+ let evidence;
283
+ if (rawProvenance["comprehensionEvidence"] !== undefined) {
284
+ const evidenceStart = issues.length;
285
+ const rawEvidence = checkClosedObject(rawProvenance["comprehensionEvidence"], "$.provenance.comprehensionEvidence", ["subject", "dossierHash", "signature"], ["subject", "dossierHash"], ["subject", "dossierHash", "signature"], issues);
286
+ if (rawEvidence !== undefined && issues.length === evidenceStart) {
287
+ evidence = {
288
+ subject: rawEvidence["subject"],
289
+ dossierHash: rawEvidence["dossierHash"],
290
+ ...(typeof rawEvidence["signature"] === "string" ? { signature: rawEvidence["signature"] } : {}),
291
+ };
292
+ }
293
+ }
294
+ provenance = {
295
+ source: rawProvenance["source"],
296
+ readAt: rawProvenance["readAt"],
297
+ ...(evidence !== undefined ? { comprehensionEvidence: evidence } : {}),
298
+ };
299
+ }
300
+ const amendmentTrace = [];
301
+ if (!Array.isArray(doc["amendmentTrace"])) {
302
+ issues.push(issue("$.amendmentTrace", "invalid_type", "expected an array"));
303
+ }
304
+ else {
305
+ doc["amendmentTrace"].forEach((step, index) => {
306
+ const checked = checkAmendmentStep(step, `$.amendmentTrace[${index}]`, issues);
307
+ if (checked !== undefined)
308
+ amendmentTrace.push(checked);
309
+ });
310
+ }
311
+ // Every recorded issue is a refusal: the schema is closed.
312
+ if (issues.length > 0 || provenance === undefined) {
313
+ return { ok: false, issues };
314
+ }
315
+ if (typeof doc["ref"] !== "string" ||
316
+ typeof doc["subject"] !== "string" ||
317
+ typeof doc["title"] !== "string" ||
318
+ typeof doc["hash"] !== "string" ||
319
+ typeof doc["cursor"] !== "string") {
320
+ return { ok: false, issues };
321
+ }
322
+ return {
323
+ ok: true,
324
+ value: {
325
+ ref: doc["ref"],
326
+ subject: doc["subject"],
327
+ title: doc["title"],
328
+ hash: doc["hash"],
329
+ cursor: doc["cursor"],
330
+ sections,
331
+ interactions,
332
+ provenance,
333
+ amendmentTrace,
334
+ },
335
+ };
336
+ };
337
+ /** Semantic layer on a structurally valid dossier. Empty means valid. */
338
+ export const validateDecisionDossierSemantics = (doc) => {
339
+ const issues = [];
340
+ const seen = new Map();
341
+ const registerId = (id, path) => {
342
+ const first = seen.get(id);
343
+ if (first !== undefined) {
344
+ issues.push(issue(path, "duplicate_id", `node id "${id}" already used at ${first}`));
345
+ }
346
+ else {
347
+ seen.set(id, path);
348
+ }
349
+ };
350
+ doc.sections.forEach((section, index) => {
351
+ const path = `$.sections[${index}]`;
352
+ registerId(section.id, `${path}.id`);
353
+ if (section.kind === "optionSet") {
354
+ section.options.forEach((option, optionIndex) => {
355
+ registerId(option.id, `${path}.options[${optionIndex}].id`);
356
+ });
357
+ }
358
+ });
359
+ // Every interaction target must resolve: the dossier ref, a section
360
+ // id/targetRef, or a nested option id/targetRef.
361
+ const resolvable = new Set([doc.ref]);
362
+ for (const section of doc.sections) {
363
+ resolvable.add(section.id);
364
+ resolvable.add(section.targetRef);
365
+ if (section.kind === "optionSet") {
366
+ for (const option of section.options) {
367
+ resolvable.add(option.id);
368
+ resolvable.add(option.targetRef);
369
+ }
370
+ }
371
+ }
372
+ doc.interactions.forEach((interaction, index) => {
373
+ if (!resolvable.has(interaction.targetRef)) {
374
+ issues.push(issue(`$.interactions[${index}].targetRef`, "unresolved_target", `interaction target "${interaction.targetRef}" resolves to no node`));
375
+ }
376
+ });
377
+ // The source binding selects the read backend. It is opaque (e.g. a
378
+ // `track:<events-path>` binding): the published schema accepts any string,
379
+ // so the validator does too — no stricter refusal without a versioned change.
380
+ // Comprehension evidence is carried verbatim: its dossier hash must still be
381
+ // the hash the snapshot was taken over. A mismatch is forged evidence.
382
+ const evidence = doc.provenance.comprehensionEvidence;
383
+ if (evidence !== undefined && evidence.dossierHash !== doc.hash) {
384
+ issues.push(issue("$.provenance.comprehensionEvidence.dossierHash", "evidence_mismatch", "comprehension evidence does not match the snapshot hash"));
385
+ }
386
+ return issues;
387
+ };
388
+ /** Full validation: structure first, then semantics. */
389
+ export const validateDecisionDossierDocument = (value) => {
390
+ const structural = validateDecisionDossierStructure(value);
391
+ if (!structural.ok)
392
+ return structural;
393
+ const semantic = validateDecisionDossierSemantics(structural.value);
394
+ if (semantic.length > 0)
395
+ return { ok: false, issues: semantic };
396
+ return structural;
397
+ };
398
+ /** Parse or throw {@link DecisionDossierValidationError}. */
399
+ export const assertDecisionDossierDocument = (value) => {
400
+ const result = validateDecisionDossierDocument(value);
401
+ if (!result.ok)
402
+ throw new DecisionDossierValidationError(result.issues);
403
+ return result.value;
404
+ };
405
+ //# sourceMappingURL=index.js.map