@action-state-group/capsule-viewer 0.0.0 → 0.3.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 (95) hide show
  1. package/LICENSE +201 -0
  2. package/LICENSE-BSD-3-Clause +28 -0
  3. package/README.md +94 -1
  4. package/dist/alias-interpreters.d.ts +18 -0
  5. package/dist/alias-interpreters.js +50 -0
  6. package/dist/alias-interpreters.js.map +1 -0
  7. package/dist/browser.d.ts +7 -0
  8. package/dist/browser.js +25 -0
  9. package/dist/browser.js.map +1 -0
  10. package/dist/builtin-manifests.d.ts +51 -0
  11. package/dist/builtin-manifests.js +196 -0
  12. package/dist/builtin-manifests.js.map +1 -0
  13. package/dist/compliance-presentation.d.ts +51 -0
  14. package/dist/compliance-presentation.js +140 -0
  15. package/dist/compliance-presentation.js.map +1 -0
  16. package/dist/compliance-styles.d.ts +1 -0
  17. package/dist/compliance-styles.js +104 -0
  18. package/dist/compliance-styles.js.map +1 -0
  19. package/dist/compliance-view.d.ts +46 -0
  20. package/dist/compliance-view.js +828 -0
  21. package/dist/compliance-view.js.map +1 -0
  22. package/dist/compliance.d.ts +121 -0
  23. package/dist/compliance.js +412 -0
  24. package/dist/compliance.js.map +1 -0
  25. package/dist/composed-styles.d.ts +12 -0
  26. package/dist/composed-styles.js +20 -0
  27. package/dist/composed-styles.js.map +1 -0
  28. package/dist/composed-view.d.ts +24 -0
  29. package/dist/composed-view.js +186 -0
  30. package/dist/composed-view.js.map +1 -0
  31. package/dist/contract-report-wording.d.ts +195 -0
  32. package/dist/contract-report-wording.js +1141 -0
  33. package/dist/contract-report-wording.js.map +1 -0
  34. package/dist/contract-report.d.ts +92 -0
  35. package/dist/contract-report.js +63 -0
  36. package/dist/contract-report.js.map +1 -0
  37. package/dist/emitter-shell.html +310 -0
  38. package/dist/emitter.d.ts +105 -0
  39. package/dist/emitter.js +329 -0
  40. package/dist/emitter.js.map +1 -0
  41. package/dist/evidence-graph-view.d.ts +149 -0
  42. package/dist/evidence-graph-view.js +2718 -0
  43. package/dist/evidence-graph-view.js.map +1 -0
  44. package/dist/evidence-graph.iife.js +18159 -0
  45. package/dist/frame-tokens.generated.d.ts +3 -0
  46. package/dist/frame-tokens.generated.js +5 -0
  47. package/dist/frame-tokens.generated.js.map +1 -0
  48. package/dist/index.d.ts +5 -0
  49. package/dist/index.js +12 -0
  50. package/dist/index.js.map +1 -0
  51. package/dist/outcome-report-presentation.d.ts +48 -0
  52. package/dist/outcome-report-presentation.js +90 -0
  53. package/dist/outcome-report-presentation.js.map +1 -0
  54. package/dist/outcome-report-styles.d.ts +1 -0
  55. package/dist/outcome-report-styles.js +228 -0
  56. package/dist/outcome-report-styles.js.map +1 -0
  57. package/dist/outcome-report-view.d.ts +78 -0
  58. package/dist/outcome-report-view.js +1488 -0
  59. package/dist/outcome-report-view.js.map +1 -0
  60. package/dist/presentation-builder.d.ts +296 -0
  61. package/dist/presentation-builder.js +646 -0
  62. package/dist/presentation-builder.js.map +1 -0
  63. package/dist/presentation-fragment.d.ts +129 -0
  64. package/dist/presentation-fragment.js +213 -0
  65. package/dist/presentation-fragment.js.map +1 -0
  66. package/dist/presentation-mount.d.ts +26 -0
  67. package/dist/presentation-mount.js +45 -0
  68. package/dist/presentation-mount.js.map +1 -0
  69. package/dist/presentation-registry.d.ts +277 -0
  70. package/dist/presentation-registry.js +416 -0
  71. package/dist/presentation-registry.js.map +1 -0
  72. package/dist/record-content.d.ts +68 -0
  73. package/dist/record-content.js +153 -0
  74. package/dist/record-content.js.map +1 -0
  75. package/dist/record-dating.d.ts +10 -0
  76. package/dist/record-dating.js +76 -0
  77. package/dist/record-dating.js.map +1 -0
  78. package/dist/report-front-styles.d.ts +9 -0
  79. package/dist/report-front-styles.js +55 -0
  80. package/dist/report-front-styles.js.map +1 -0
  81. package/dist/report-front.d.ts +78 -0
  82. package/dist/report-front.js +274 -0
  83. package/dist/report-front.js.map +1 -0
  84. package/dist/report-levels.d.ts +206 -0
  85. package/dist/report-levels.js +739 -0
  86. package/dist/report-levels.js.map +1 -0
  87. package/dist/report-provenance.d.ts +111 -0
  88. package/dist/report-provenance.js +535 -0
  89. package/dist/report-provenance.js.map +1 -0
  90. package/dist/viewer-build.d.ts +37 -0
  91. package/dist/viewer-build.js +29 -0
  92. package/dist/viewer-build.js.map +1 -0
  93. package/dist/wording/contract-report-eu-ai-act.en.json +295 -0
  94. package/dist/wording/contract-report-outcomes.en.json +394 -0
  95. package/package.json +48 -4
@@ -0,0 +1,1141 @@
1
+ // SPDX-License-Identifier: BSD-3-Clause
2
+ import { EVIDENCE_STATUSES, GRADES, sha256Hex, SUFFICIENCIES, TIERS, } from "@action-state-group/agent-action-capsule";
3
+ import {} from "./presentation-fragment.js";
4
+ import OUTCOMES_PACK from "./wording/contract-report-outcomes.en.json" with { type: "json" };
5
+ import EU_AI_ACT_PACK from "./wording/contract-report-eu-ai-act.en.json" with { type: "json" };
6
+ /**
7
+ * The words of the contract-report module (contract-report.ts), and the
8
+ * wording packs they come from.
9
+ *
10
+ * The module's own words on a contract report -- labels, headings, the
11
+ * plain-language lines, the verdict words -- are each an entry of an
12
+ * `aac.wording-pack/v0` pack (presentation contract section 7.4). Not
13
+ * every word on the page is the pack's: the bundle's own producer-supplied
14
+ * text and two lines agent-action-capsule's outcome model writes are not
15
+ * (report-levels.ts's and compliance-view.ts's own docs say which). The
16
+ * module ships two default packs, beside its code and never in a bundle
17
+ * (section 6: this module's own wording never comes from the bundle):
18
+ *
19
+ * wording/contract-report-outcomes.en.json the Outcomes report
20
+ * wording/contract-report-eu-ai-act.en.json the EU AI Act Results
21
+ *
22
+ * A host may hand a page a pack of its own (`renderEvidenceGraph`'s
23
+ * `wording`, the same pack the presentation builder carries), bound to its
24
+ * bytes by `wording_sha256`. Its entries replace the default pack's entry
25
+ * for the same key; keys this module does not know (a page title, another
26
+ * module's words) are left to their owners.
27
+ *
28
+ * A pack changes words only. It holds strings and nothing else; every count,
29
+ * verdict, digest and record id on the page is computed by the module and
30
+ * put into a pack's sentence through its `{placeholders}`, and a replacement
31
+ * entry must carry exactly the placeholders of the entry it replaces, so a
32
+ * pack can neither drop a count or a denominator nor invent one. The words
33
+ * for two different verdicts must stay different words, so a pack cannot
34
+ * fold one verdict into another. The lines that say what the page checked,
35
+ * what the bundle withholds, and what is the producer's rather than evidence
36
+ * are locked (LOCKED_ENTRIES): a pack cannot reword them. The raw verdict is
37
+ * always on the element as data, whatever the words say.
38
+ *
39
+ * Plurals are two entries, `<key>.one` and `<key>.other`, chosen by count.
40
+ */
41
+ export const WORDING_PACK_VERSION = "aac.wording-pack/v0";
42
+ const WORDING_KEY = /^[a-z0-9][a-z0-9._-]*$/u;
43
+ const LOCALE = /^[A-Za-z]{2,8}(-[A-Za-z0-9]{1,8})*$/u;
44
+ const PLACEHOLDER = /\{([a-zA-Z][a-zA-Z0-9_]*)\}/gu;
45
+ /** Bidi and other invisible format controls: refused outright, never merely stripped for comparison, so the string this module checks is the string the browser renders. */
46
+ const INVISIBLE = /[\p{Cf}\p{Default_Ignorable_Code_Point}]/u;
47
+ /** A pack that is not an `aac.wording-pack/v0` object, or does not fit this module. */
48
+ export class WordingPackError extends Error {
49
+ constructor(message) {
50
+ super(message);
51
+ this.name = "WordingPackError";
52
+ }
53
+ }
54
+ /** Shape-check a parsed pack (contract 7.4): id, locale and non-empty string entries, nothing else. */
55
+ export function readWordingPack(pack) {
56
+ const p = pack;
57
+ const entries = p?.entries;
58
+ if (pack === null ||
59
+ typeof pack !== "object" ||
60
+ Array.isArray(pack) ||
61
+ Object.keys(p).some((k) => !["wording_pack_version", "id", "locale", "entries"].includes(k)) ||
62
+ p.wording_pack_version !== WORDING_PACK_VERSION ||
63
+ typeof p.id !== "string" ||
64
+ INVISIBLE.test(p.id) ||
65
+ typeof p.locale !== "string" ||
66
+ !LOCALE.test(p.locale) ||
67
+ entries === null ||
68
+ typeof entries !== "object" ||
69
+ Array.isArray(entries) ||
70
+ Object.keys(entries).length === 0 ||
71
+ Object.entries(entries).some(([k, v]) => !WORDING_KEY.test(k) || typeof v !== "string" || v === ""))
72
+ throw new WordingPackError(`wording pack is not an ${WORDING_PACK_VERSION} object`);
73
+ return {
74
+ id: p.id,
75
+ locale: p.locale,
76
+ entries: entries,
77
+ };
78
+ }
79
+ /**
80
+ * Check a distributed pack against its digest (the exact bytes, hashed as
81
+ * given) and its shape, and read it.
82
+ */
83
+ export async function checkWordingPackInput(wording) {
84
+ if (!/^[0-9a-f]{64}$/u.test(wording.sha256))
85
+ throw new WordingPackError("wording sha256 is not a lowercase hex SHA-256");
86
+ const digest = await sha256Hex(new TextEncoder().encode(wording.pack));
87
+ if (digest !== wording.sha256)
88
+ throw new WordingPackError("wording pack bytes do not hash to its wording_sha256");
89
+ let parsed;
90
+ try {
91
+ parsed = JSON.parse(wording.pack);
92
+ }
93
+ catch {
94
+ throw new WordingPackError("wording pack is not JSON");
95
+ }
96
+ return readWordingPack(parsed);
97
+ }
98
+ /**
99
+ * Every `{placeholder}` `text` uses, in the order it uses them, repeats and
100
+ * all: a count and a denominator in one entry are two placeholders, not one,
101
+ * and a replacement that reorders or drops a repeat changes what the
102
+ * sentence can say with them.
103
+ */
104
+ export function placeholders(text) {
105
+ return [...text.matchAll(PLACEHOLDER)].map((m) => m[1]);
106
+ }
107
+ /**
108
+ * The text between each pair of consecutive `{placeholder}`s in `text`, in
109
+ * order: one entry fewer than `placeholders(text)`. Used to catch a pack
110
+ * that keeps a sentence's placeholder order but drops the word between two
111
+ * of them, so two counts the sentence computed separately (a count and its
112
+ * denominator) could run together on the page ("2 of 10" read as "210").
113
+ */
114
+ function placeholderGaps(text) {
115
+ const matches = [...text.matchAll(PLACEHOLDER)];
116
+ const gaps = [];
117
+ for (let i = 1; i < matches.length; i++)
118
+ gaps.push(text.slice(matches[i - 1].index + matches[i - 1][0].length, matches[i].index));
119
+ return gaps;
120
+ }
121
+ const HAS_NON_SPACE = /\S/u;
122
+ const HAS_LETTER = /\p{L}/u;
123
+ /**
124
+ * Latin letters (after `asRead` folds case and Cyrillic/Greek look-alikes)
125
+ * that read as a digit between two counts: "{count}O{total}" or
126
+ * "{count}O {total}" reads as one number ("59O 768" as 590 768), and
127
+ * "{count} OOO {total}" as a thousands group (59 000 768), so a gap with
128
+ * only these has no word in it -- unless it is one letter with a space on
129
+ * both sides ("59 o 768" is Welsh for "59 of 768").
130
+ */
131
+ const DIGIT_LIKE = /[oil]/gu;
132
+ // ---------------------------------------------------------------------------
133
+ // contract-report/v1 section 3: the keys the kind defines
134
+ // ---------------------------------------------------------------------------
135
+ /**
136
+ * The enum values contract-report/v1 section 3 gives a word each, lowercased
137
+ * (agent-action-capsule's TIERS, GRADES, SUFFICIENCIES and EVIDENCE_STATUSES).
138
+ * The verdicts are the four Result v0 defines; this module's own extra drawn
139
+ * verdicts (failed, unsupported, not applicable) keep their grouping keys.
140
+ */
141
+ export const SECTION3_ENUMS = Object.freeze({
142
+ verdict: ["met", "not_met", "not_evaluable", "out_of_scope"],
143
+ tier: TIERS.map((v) => v.toLowerCase()),
144
+ grade: GRADES.map((v) => v.toLowerCase()),
145
+ sufficiency: SUFFICIENCIES.map((v) => v.toLowerCase()),
146
+ status: EVIDENCE_STATUSES.map((v) => v.toLowerCase()),
147
+ });
148
+ /**
149
+ * A key whose meaning contract-report/v1 section 3 fixes. The module's own
150
+ * keys never use these prefixes (`report.`, `group.`, `row.`, `verdict.`,
151
+ * `sufficiency.`, `tier.`, `grade.`, `status.`, `applicability.`,
152
+ * `contract_fact.`); its own words sit under `card.`, `lines.`, `groups.`
153
+ * and the shared prefixes (`prov.`, `chat.`, `case.`, `judge.`).
154
+ */
155
+ export const SECTION3_PREFIXES = Object.freeze([
156
+ "report.",
157
+ "group.",
158
+ "row.",
159
+ "verdict.",
160
+ "sufficiency.",
161
+ "tier.",
162
+ "grade.",
163
+ "status.",
164
+ "applicability.",
165
+ "contract_fact.",
166
+ ]);
167
+ /**
168
+ * The section 3 keys that name the same thing a grouping already has a word
169
+ * for, and that grouping's keys for it. A host pack's section 3 entry sets
170
+ * each of them unless the same pack also sets the grouping's own key, which
171
+ * is more specific and wins. The section 3 entry is then checked exactly as
172
+ * that grouping key would be (placeholders, DISTINCT, the clean/not-clean
173
+ * categories, locks): a section 3 word can never say what the grouping's own
174
+ * key could not.
175
+ */
176
+ const SECTION3_ALIASES = Object.freeze({
177
+ lines: {
178
+ "report.title": ["lines.title"],
179
+ // The rule table's pill and the proofs table's cell both name the
180
+ // verdict, so a section 3 word reaches both.
181
+ "verdict.met": ["lines.verdict.met", "lines.pf.verdict.met"],
182
+ "verdict.not_met": ["lines.verdict.not_met", "lines.pf.verdict.not_met"],
183
+ "verdict.not_evaluable": [
184
+ "lines.verdict.not_evaluable.judged",
185
+ "lines.verdict.not_evaluable.unjudged",
186
+ "lines.verdict.not_evaluable.withheld",
187
+ "lines.verdict.not_evaluable.unavailable",
188
+ "lines.pf.verdict.not_evaluable",
189
+ ],
190
+ "verdict.out_of_scope": [
191
+ "lines.verdict.out_of_scope",
192
+ "lines.pf.verdict.out_of_scope",
193
+ ],
194
+ "tier.recomputed": ["lines.tier.recomputed"],
195
+ "tier.judged": ["lines.tier.judged"],
196
+ },
197
+ groups: {
198
+ "report.title": ["groups.kicker"],
199
+ "verdict.met": ["groups.verdict.met"],
200
+ "verdict.not_met": ["groups.verdict.not_met"],
201
+ "verdict.not_evaluable": [
202
+ "groups.verdict.not_evaluable.judged",
203
+ "groups.verdict.not_evaluable.unjudged",
204
+ "groups.verdict.not_evaluable.withheld",
205
+ "groups.verdict.not_evaluable.unavailable",
206
+ ],
207
+ "verdict.out_of_scope": ["groups.verdict.out_of_scope"],
208
+ "tier.recomputed": ["groups.tier.recomputed"],
209
+ "tier.judged": ["groups.tier.judged"],
210
+ },
211
+ });
212
+ /**
213
+ * `pack` with each section 3 alias it carries copied onto the grouping keys
214
+ * it names (SECTION3_ALIASES), where the pack does not set them itself.
215
+ * Every check and every lookup reads this expanded form, so a section 3
216
+ * word and a grouping word are one entry to the rest of this module.
217
+ */
218
+ function expandSection3(pack, grouping) {
219
+ const aliases = SECTION3_ALIASES[grouping];
220
+ const entries = { ...pack.entries };
221
+ for (const [key, targets] of Object.entries(aliases))
222
+ if (Object.hasOwn(pack.entries, key))
223
+ for (const target of targets)
224
+ if (!Object.hasOwn(pack.entries, target))
225
+ entries[target] = pack.entries[key];
226
+ return { ...pack, entries };
227
+ }
228
+ export const DEFAULT_PACKS = Object.freeze({
229
+ lines: readWordingPack(OUTCOMES_PACK),
230
+ groups: readWordingPack(EU_AI_ACT_PACK),
231
+ });
232
+ /**
233
+ * Entries whose words name a verdict. Within each set, no two keys may share
234
+ * a word (except where the set says so), so a pack cannot make two verdicts
235
+ * read alike. The three undecided variants of one verdict may share a word:
236
+ * the default plain set does.
237
+ */
238
+ const DISTINCT = [
239
+ // This module's own rule verdict words (contract-report.ts: the bare
240
+ // `verdict.*` namespace stays contract-report/v1 §3's), one set per
241
+ // grouping -- the Outcomes card's and the EU card's prefixes never
242
+ // compare against each other, each pack names only its own.
243
+ [
244
+ "lines.verdict.met",
245
+ "lines.verdict.not_met",
246
+ "lines.verdict.not_applicable",
247
+ "lines.verdict.failed",
248
+ "lines.verdict.unsupported",
249
+ "lines.verdict.out_of_scope",
250
+ [
251
+ "lines.verdict.not_evaluable.judged",
252
+ "lines.verdict.not_evaluable.unjudged",
253
+ "lines.verdict.not_evaluable.withheld",
254
+ "lines.verdict.not_evaluable.unavailable",
255
+ ],
256
+ ],
257
+ [
258
+ "groups.verdict.met",
259
+ "groups.verdict.not_met",
260
+ "groups.verdict.not_applicable",
261
+ "groups.verdict.failed",
262
+ "groups.verdict.unsupported",
263
+ "groups.verdict.out_of_scope",
264
+ "groups.verdict.not_yet_in_force",
265
+ [
266
+ "groups.verdict.not_evaluable.judged",
267
+ "groups.verdict.not_evaluable.unjudged",
268
+ "groups.verdict.not_evaluable.withheld",
269
+ "groups.verdict.not_evaluable.unavailable",
270
+ ],
271
+ ],
272
+ [
273
+ "lines.status.resolved",
274
+ "lines.status.missed",
275
+ "lines.status.nothing-applied",
276
+ "lines.status.unverified",
277
+ [
278
+ "lines.status.undecided.judged",
279
+ "lines.status.undecided.unjudged",
280
+ "lines.status.undecided.none",
281
+ "lines.status.undecided.withheld",
282
+ "lines.status.undecided.unavailable",
283
+ ],
284
+ ],
285
+ // The sealed verdicts as the Outcomes proofs name them.
286
+ [
287
+ "lines.pf.verdict.met",
288
+ "lines.pf.verdict.not_met",
289
+ "lines.pf.verdict.not_evaluable",
290
+ "lines.pf.verdict.failed",
291
+ "lines.pf.verdict.unsupported",
292
+ "lines.pf.verdict.not_applicable",
293
+ "lines.pf.verdict.out_of_scope",
294
+ "lines.pf.verdict.no_claim",
295
+ ],
296
+ // The assurance tier (judged vs. recomputed) must stay a non-swappable
297
+ // set too: a judgement must never read as a check anyone can repeat.
298
+ [
299
+ "groups.tier.judged",
300
+ "groups.tier.recomputed",
301
+ "groups.tier.mixed",
302
+ "groups.tier.unstated",
303
+ ],
304
+ [
305
+ "lines.tier.judged",
306
+ "lines.tier.recomputed",
307
+ "lines.tier.mixed",
308
+ "lines.tier.unknown",
309
+ ],
310
+ // The Outcomes headline row labels.
311
+ [
312
+ "lines.line.resolved",
313
+ "lines.line.missed",
314
+ "lines.line.undecided",
315
+ "lines.line.unverified",
316
+ "lines.line.held",
317
+ "lines.line.added",
318
+ ],
319
+ // An obligation's summary pill (EU card): "could not be checked" must
320
+ // never read as "no exceptions" or the reverse.
321
+ [
322
+ "groups.ob.unchecked",
323
+ "groups.ob.later",
324
+ ["groups.ob.ok", "groups.ob.ok.found", "groups.ob.ok.unverified"],
325
+ ],
326
+ // A test row's summary pill (EU card).
327
+ [
328
+ "groups.row.nothing",
329
+ "groups.row.none-decided",
330
+ "groups.row.out-of-scope",
331
+ "groups.row.later",
332
+ ["groups.row.ok", "groups.row.ok.all-decided"],
333
+ ],
334
+ // A session's pill inside a test's drill-down (EU card).
335
+ [
336
+ "groups.session.ok",
337
+ "groups.session.undecided",
338
+ "groups.session.unverified",
339
+ "groups.session.none",
340
+ ],
341
+ // A conversation's "why" line (Outcomes card): the same {names} signature
342
+ // on all three, so a pack could otherwise swap a missed conversation's
343
+ // reason for an undecided one's, or the reverse.
344
+ ["lines.why.missed", "lines.why.unverified", "lines.why.undecided"],
345
+ // The rules table's column header for a rule nobody could decide, and for
346
+ // one whose claim could not be verified (Outcomes card).
347
+ ["lines.rules.col.undecided", "lines.rules.col.unverified"],
348
+ // A test row's undecided and unverified counts (EU card).
349
+ ["groups.row.undecided-note", "groups.row.unverified-note"],
350
+ ];
351
+ const GUARDED_CATEGORY = {
352
+ // met/clean: a rule was met, a row resolved, or nothing exceptioned.
353
+ "lines.verdict.met": "clean",
354
+ "groups.verdict.met": "clean",
355
+ "lines.pf.verdict.met": "clean",
356
+ "lines.line.resolved": "clean",
357
+ "lines.status.resolved": "clean",
358
+ "groups.ob.ok": "clean",
359
+ "groups.ob.ok.found": "clean",
360
+ "groups.ob.ok.unverified": "clean",
361
+ "groups.row.ok": "clean",
362
+ "groups.row.ok.all-decided": "clean",
363
+ "groups.session.ok": "clean",
364
+ // not-met/exception: a rule was not met or missed, or a row's or an
365
+ // obligation's red exceptions count.
366
+ "lines.verdict.not_met": "exception",
367
+ "groups.verdict.not_met": "exception",
368
+ "lines.pf.verdict.not_met": "exception",
369
+ "lines.line.missed": "exception",
370
+ "lines.status.missed": "exception",
371
+ "groups.row.exceptions.one": "exception",
372
+ "groups.row.exceptions.other": "exception",
373
+ "groups.count.exception.one": "exception",
374
+ "groups.count.exception.other": "exception",
375
+ // could-not-decide: nobody could decide.
376
+ "lines.line.undecided": "undecided",
377
+ "lines.status.undecided.judged": "undecided",
378
+ "lines.status.undecided.unjudged": "undecided",
379
+ "lines.status.undecided.none": "undecided",
380
+ "lines.status.undecided.withheld": "undecided",
381
+ "lines.status.undecided.unavailable": "undecided",
382
+ "lines.pf.verdict.not_evaluable": "undecided",
383
+ "lines.verdict.not_evaluable.judged": "undecided",
384
+ "lines.verdict.not_evaluable.unjudged": "undecided",
385
+ "lines.verdict.not_evaluable.withheld": "undecided",
386
+ "lines.verdict.not_evaluable.unavailable": "undecided",
387
+ "groups.verdict.not_evaluable.judged": "undecided",
388
+ "groups.verdict.not_evaluable.unjudged": "undecided",
389
+ "groups.verdict.not_evaluable.withheld": "undecided",
390
+ "groups.verdict.not_evaluable.unavailable": "undecided",
391
+ "groups.session.undecided": "undecided",
392
+ "groups.row.undecided-note": "undecided",
393
+ // could-not-verify: a claim is unverified, or its verification failed or
394
+ // is unsupported -- all six failed/unsupported verdict keys included.
395
+ "lines.line.unverified": "unverifiable",
396
+ "lines.status.unverified": "unverifiable",
397
+ "groups.session.unverified": "unverifiable",
398
+ "lines.verdict.failed": "unverifiable",
399
+ "lines.verdict.unsupported": "unverifiable",
400
+ "groups.verdict.failed": "unverifiable",
401
+ "groups.verdict.unsupported": "unverifiable",
402
+ "lines.pf.verdict.failed": "unverifiable",
403
+ "lines.pf.verdict.unsupported": "unverifiable",
404
+ "groups.row.unverified-note": "unverifiable",
405
+ // could-not-check: nothing could be checked at all.
406
+ "groups.ob.unchecked": "unchecked",
407
+ "groups.ob.unchecked-of": "unchecked",
408
+ "groups.row.nothing": "unchecked",
409
+ "groups.row.none-decided": "unchecked",
410
+ // Not covered: the run did not cover the rule (Result v0 section 3).
411
+ "lines.rules.not-run": "unchecked",
412
+ // did-not-apply: no rule or test applied, so nothing was checked; never
413
+ // a met or a missed result.
414
+ "lines.verdict.not_applicable": "not-applicable",
415
+ "groups.verdict.not_applicable": "not-applicable",
416
+ "lines.pf.verdict.not_applicable": "not-applicable",
417
+ "lines.status.nothing-applied": "not-applicable",
418
+ "groups.session.none": "not-applicable",
419
+ // Judged out of scope (Result v0 section 4.2): it did not arise. Its own
420
+ // count, never met, so it reads with did-not-apply, never with clean.
421
+ "lines.verdict.out_of_scope": "not-applicable",
422
+ "groups.verdict.out_of_scope": "not-applicable",
423
+ "lines.pf.verdict.out_of_scope": "not-applicable",
424
+ "groups.row.out-of-scope": "not-applicable",
425
+ // later: a claim not yet in force (Result v0 section 4.3), readiness
426
+ // only; never a result that counts.
427
+ "groups.verdict.not_yet_in_force": "later",
428
+ "groups.ob.later": "later",
429
+ "groups.row.later": "later",
430
+ // held: a person's spot check disagreed with a resolved result, which is
431
+ // held back for a person to decide.
432
+ "lines.line.held": "held",
433
+ // added: a person's spot check graded a missed result as resolved; it must
434
+ // not read as a plain resolved result, which no person overrode.
435
+ "lines.line.added": "added",
436
+ // recomputed tier: a fixed check anyone can repeat from the records.
437
+ "lines.tier.recomputed": "tier.recomputed",
438
+ "groups.tier.recomputed": "tier.recomputed",
439
+ // judged tier: a judgement, which must never read like the recomputed
440
+ // tier above.
441
+ "lines.tier.judged": "tier.judged",
442
+ "groups.tier.judged": "tier.judged",
443
+ };
444
+ /** A human-readable noun phrase for each GuardedCategory, for problem messages. */
445
+ const CATEGORY_LABEL = {
446
+ clean: "a met/clean result",
447
+ exception: "a not-met/exception result",
448
+ undecided: "something nobody could decide",
449
+ unverifiable: "something that could not be verified",
450
+ unchecked: "something that could not be checked at all",
451
+ "not-applicable": "something nothing applied to",
452
+ held: "a result held for a person to decide",
453
+ added: "a result a person's check added",
454
+ later: "a claim not yet in force",
455
+ "tier.recomputed": "the recomputed tier",
456
+ "tier.judged": "the judged tier",
457
+ };
458
+ /**
459
+ * Lines that state what this page checked or did not check, what the bundle
460
+ * does not carry or withholds, and which text is the producer's rather than
461
+ * sealed evidence. A pack may not reword them: they are the page's honesty,
462
+ * not its voice. A pack that carries one of these entries with any text but
463
+ * the default's is refused (a pack that repeats the default, as a copied
464
+ * file does, changes nothing and passes).
465
+ */
466
+ export const LOCKED_ENTRIES = new Set([
467
+ // contract-report/v1 section 3: the assurance words each claim shows (its
468
+ // carrier status, grade and sufficiency). They state what the sealed claim
469
+ // says about its own evidence, so a pack cannot make WITHHELD read as
470
+ // clean or a self-attested grade read as witnessed.
471
+ ...SECTION3_ENUMS.status.map((v) => `status.${v}`),
472
+ ...SECTION3_ENUMS.grade.map((v) => `grade.${v}`),
473
+ ...SECTION3_ENUMS.sufficiency.map((v) => `sufficiency.${v}`),
474
+ // The shared front (report-front.ts): the mock-judge line, what the
475
+ // aggregate's unknown count is, what the page and the bundle carry, and
476
+ // the producer's findings label.
477
+ "front.mock",
478
+ "front.agg.unknown.one",
479
+ "front.agg.unknown.other",
480
+ "front.agg.mismatch",
481
+ "front.agg.as-of",
482
+ "front.agg.copied.both",
483
+ "front.agg.copied.dates",
484
+ "front.agg.copied.switch",
485
+ // The bucket labels name a verdict: a pack cannot make one read as another.
486
+ "front.agg.bucket.met",
487
+ "front.agg.bucket.not_met",
488
+ "front.agg.bucket.not_evaluable",
489
+ "front.agg.bucket.out_of_scope",
490
+ "front.check.s1",
491
+ "front.check.s3.receipt",
492
+ "front.check.s3.none",
493
+ "front.findings.label",
494
+ // The front block (report-provenance.ts): who judged, who witnessed, what verified.
495
+ "prov.judge.none",
496
+ "prov.judge.model.does-not-recompute",
497
+ "prov.judge.model.differs",
498
+ "prov.judge.model.partly-stated",
499
+ "prov.judge.model.not-stated",
500
+ "prov.judge.all-withheld",
501
+ "prov.judge.some-withheld",
502
+ "prov.judge.not-carried",
503
+ "prov.judge.unread",
504
+ "prov.judge.checker-not-stated",
505
+ "prov.judge.recomputed",
506
+ "prov.judge.unnamed",
507
+ "prov.judge.nothing",
508
+ "prov.witness.stated",
509
+ "prov.witness.verified",
510
+ "prov.witness.invalid",
511
+ "prov.witness.failed",
512
+ "prov.witness.invalid.findings",
513
+ "prov.witness.failed-entry",
514
+ "prov.witness.invalid.unreadable.one",
515
+ "prov.witness.invalid.unreadable.other",
516
+ "prov.witness.none",
517
+ "prov.witness.receipt-not-stated",
518
+ "prov.witness.stubs.one",
519
+ "prov.witness.stubs.other",
520
+ "prov.witness.malformed.one",
521
+ "prov.witness.malformed.other",
522
+ "prov.witness.about",
523
+ "prov.witness.about.unchecked",
524
+ "prov.witness.about.unsigned",
525
+ "prov.verifier.ran",
526
+ "prov.verifier.ran.cll",
527
+ "prov.verifier.ran.not-stated",
528
+ "prov.verifier.commit.not-stated",
529
+ "prov.verifier.built",
530
+ "prov.verifier.built.not-stated",
531
+ "prov.verifier.version.not-stated",
532
+ // Both cards: a rule or conversation nobody could decide, by why.
533
+ "lines.status.undecided.unjudged",
534
+ "lines.status.undecided.withheld",
535
+ "lines.status.undecided.unavailable",
536
+ // Both cards: dating, withheld reports, the conversation, the proofs.
537
+ "card.not-stated",
538
+ "card.span.unknown",
539
+ "card.basis.source",
540
+ "card.basis.record",
541
+ "card.basis.judged",
542
+ "card.dating.source",
543
+ "card.dating.record",
544
+ "card.dating.mixed",
545
+ "card.dating.mixed.source",
546
+ "card.dating.mixed.record",
547
+ "card.dating.mixed.judged",
548
+ "card.dating.self-attested",
549
+ "card.dating.tz",
550
+ "card.gap.notes.withheld",
551
+ "card.gap.notes.unread",
552
+ "card.gap.notes.some-withheld",
553
+ "card.gap.notes.none",
554
+ "card.pf.case-record.not-stated",
555
+ "card.pf.dated",
556
+ "card.pf.dated.no-zone",
557
+ "card.pf.input-digest.verified",
558
+ "card.pf.input-digest.cited",
559
+ "card.pf.transcript.absent",
560
+ "card.pf.transcript.not-shown",
561
+ "card.pf.transcript.default-reason",
562
+ "card.pf.wording.default",
563
+ "card.pf.wording.supplied.layered",
564
+ "card.pf.assurance",
565
+ "card.pin.withheld",
566
+ "card.pin.unread",
567
+ "card.pin.not-in-bundle",
568
+ "card.vd.uncomputable",
569
+ "card.vd.absent",
570
+ "chat.absent",
571
+ "chat.record.not-stated",
572
+ "chat.not-shown",
573
+ "chat.not-shown.default-reason",
574
+ "chat.state.cited",
575
+ "chat.state.verified",
576
+ "chat.lede",
577
+ // The Outcomes report.
578
+ "lines.tier.unknown",
579
+ "lines.wording.unstated",
580
+ "lines.wording.mixed",
581
+ "lines.wording-note.sealed",
582
+ "lines.wording-note.unstated",
583
+ "lines.wording-note.partly",
584
+ "lines.edited.title",
585
+ "lines.producer-note.kicker",
586
+ "lines.producer-note.source",
587
+ "lines.no-note.withheld",
588
+ "lines.no-note.mismatch",
589
+ "lines.no-note.unreadable",
590
+ "lines.no-note.invalid",
591
+ "lines.no-note.none",
592
+ "lines.line.unverified.help",
593
+ "lines.sentence.unverified.unsupported",
594
+ "lines.sentence.unverified.failed",
595
+ "lines.sentence.unverified",
596
+ "lines.why.unverified",
597
+ "lines.sentence.undecided",
598
+ "lines.sentence.undecided.gaps",
599
+ "lines.sentence.undecided.gap-note",
600
+ "lines.why.nothing-applied",
601
+ "lines.cal.lede",
602
+ "lines.line.resolved.help",
603
+ "lines.line.missed.help",
604
+ "lines.line.undecided.help",
605
+ "lines.line.held.help",
606
+ "lines.line.added.help",
607
+ "lines.gap.wording.mixed",
608
+ "lines.gap.wording.none",
609
+ "lines.pf.case-record.from-claims",
610
+ "lines.pf.judge-pin.recomputed",
611
+ "lines.pf.col.rationale",
612
+ "lines.pf.no-claim",
613
+ "lines.pf.not-cited",
614
+ "lines.pf.derived",
615
+ "lines.pf.sealed-rationale",
616
+ "lines.pf.recompute",
617
+ "lines.pin.differs",
618
+ "lines.pin.not-stated",
619
+ "lines.why-missed.structured",
620
+ "lines.why-missed.unstructured",
621
+ // The folded provenance line is the only provenance a reader sees
622
+ // without opening it: every entry is the page's own account.
623
+ "prov.brief.judge.stated",
624
+ "prov.brief.judge.mixed",
625
+ "prov.brief.judge.partial",
626
+ "prov.brief.judge.withheld",
627
+ "prov.brief.judge.not-stated",
628
+ "prov.brief.judge.mock",
629
+ "prov.brief.witness.stated",
630
+ "prov.brief.witness.verified",
631
+ "prov.brief.witness.partly-checked",
632
+ "prov.brief.witness.invalid",
633
+ "prov.brief.witness.mixed",
634
+ "prov.brief.witness.not-stated",
635
+ "prov.brief.verifier.stated",
636
+ "prov.brief.verifier.not-stated",
637
+ "lines.hc.none",
638
+ "lines.terms.lede",
639
+ "lines.terms.lede.agreed",
640
+ "lines.terms.version.value",
641
+ "lines.ran.judge-pin.recomputed",
642
+ "lines.ran.agent.value",
643
+ "lines.ran.components-mismatch",
644
+ "lines.ran.lock",
645
+ "lines.ran.pin-mismatch",
646
+ "lines.vd.note",
647
+ "lines.rp.tamper",
648
+ "lines.cal.source-says",
649
+ "lines.cal.tz",
650
+ "lines.cal.lede.dated",
651
+ "lines.cal.sealed",
652
+ "lines.tier.mixed",
653
+ "lines.meta.what-checked.text",
654
+ // The spelled-out numbers up to twelve: a pack must not make "2" read as
655
+ // "one hundred".
656
+ "lines.count.0",
657
+ "lines.count.1",
658
+ "lines.count.2",
659
+ "lines.count.3",
660
+ "lines.count.4",
661
+ "lines.count.5",
662
+ "lines.count.6",
663
+ "lines.count.7",
664
+ "lines.count.8",
665
+ "lines.count.9",
666
+ "lines.count.10",
667
+ "lines.count.11",
668
+ "lines.count.12",
669
+ // Has no placeholder of its own: a pack could otherwise make "1 verdict"
670
+ // read as any count it likes ("one hundred verdicts").
671
+ "lines.pf.verdicts.one",
672
+ "lines.na-note.one",
673
+ "lines.na-note.other",
674
+ "lines.sentence.undecided.none",
675
+ "lines.why.undecided.none",
676
+ "lines.sentence.nothing-applied",
677
+ "lines.note.not-applicable",
678
+ // The EU AI Act Results.
679
+ "groups.producer.title",
680
+ "groups.tier.unstated",
681
+ "groups.tier.judged.title",
682
+ "groups.tier.recomputed.title",
683
+ "groups.tier.mixed",
684
+ "groups.pack.not-stated",
685
+ "groups.row.nothing",
686
+ "groups.row.none-decided",
687
+ "groups.row.ok",
688
+ "groups.row.ok.all-decided",
689
+ "groups.row.unverified-note",
690
+ "groups.unverified-note",
691
+ "groups.ob.unchecked",
692
+ "groups.ob.unchecked-of",
693
+ "groups.ob.ok",
694
+ "groups.ob.ok.found",
695
+ "groups.ob.ok.unverified",
696
+ "groups.summary.basis",
697
+ "groups.summary.lede",
698
+ "groups.pf.case-record.from-claims",
699
+ "groups.pf.no-claim",
700
+ "groups.pf.rationale",
701
+ "groups.pf.absent",
702
+ "groups.pin.none",
703
+ "groups.pin.differs",
704
+ "groups.od.mapped",
705
+ "groups.od.unmapped",
706
+ "groups.od.wording.sealed",
707
+ "groups.od.wording.mixed",
708
+ "groups.od.wording.unstated",
709
+ "groups.q.none",
710
+ "groups.q.unspecified",
711
+ "groups.q.tail",
712
+ "groups.ran.contract.differs",
713
+ "groups.vd.note",
714
+ // Out of scope and not yet in force (Result v0 sections 4.2, 4.3): what
715
+ // they count and what is copied from the contract, not checked here.
716
+ "lines.oos-note.one",
717
+ "lines.oos-note.other",
718
+ "groups.later.note",
719
+ "groups.later.conditions-not-stated",
720
+ "groups.row.later-note",
721
+ // A refused wording layer (contract-report/v1 section 3): the page says
722
+ // so, and which layer drew it.
723
+ "card.wording.refused",
724
+ "card.wording.refused.digest",
725
+ "card.wording.refused.shape",
726
+ "card.wording.refused.fit",
727
+ "card.pf.wording.refused",
728
+ ]);
729
+ /**
730
+ * Cyrillic and Greek letters that are visual homoglyphs of a Latin letter,
731
+ * folded to that Latin letter before any word comparison: a verdict word
732
+ * written wholly in one of these scripts -- never mixing scripts, so
733
+ * `mixesScripts` below would not catch it -- can otherwise read exactly
734
+ * like a different verdict's Latin word (an all-Cyrillic "мет" is "met" to
735
+ * a reader, letter for letter) and pass the DISTINCT and clean/not-clean
736
+ * checks, which only compare the normalized text. Covers the letters
737
+ * actually used in common script-spoofing lists, not a full confusables
738
+ * table (uts39's is thousands of entries across every script, not only
739
+ * these two). Keyed by capital (or caseless) letter only: `asRead`
740
+ * uppercases before it folds, so a word and the same word in another case
741
+ * always fold alike ("ΕΤΣΙ" and "ετσι" are one word to a reader).
742
+ */
743
+ const CONFUSABLES = {
744
+ А: "A",
745
+ В: "B",
746
+ Е: "E",
747
+ З: "Z",
748
+ К: "K",
749
+ М: "M",
750
+ Н: "H",
751
+ О: "O",
752
+ Р: "P",
753
+ С: "C",
754
+ Т: "T",
755
+ У: "Y",
756
+ Х: "X",
757
+ І: "I",
758
+ Ј: "J",
759
+ Ѕ: "S",
760
+ Ԛ: "Q",
761
+ Ԝ: "W",
762
+ Α: "A",
763
+ Β: "B",
764
+ Ε: "E",
765
+ Ζ: "Z",
766
+ Η: "H",
767
+ Ι: "I",
768
+ Κ: "K",
769
+ Μ: "M",
770
+ Ν: "N",
771
+ Ο: "O",
772
+ Ρ: "P",
773
+ Τ: "T",
774
+ Υ: "Y",
775
+ Χ: "X",
776
+ Ϲ: "C",
777
+ Ϳ: "J",
778
+ Һ: "H",
779
+ Ԁ: "D",
780
+ Ӏ: "I",
781
+ ǀ: "l",
782
+ };
783
+ const CONFUSABLE = new RegExp(`[${Object.keys(CONFUSABLES).join("")}]`, "gu");
784
+ /**
785
+ * Lowercase Greek letters that read as a different Latin letter than their
786
+ * capital does (ν is "v" but Ν is "N"), folded before case is touched so
787
+ * the capital's reading never stands in for theirs.
788
+ */
789
+ const LOWER_CONFUSABLES = {
790
+ ν: "v",
791
+ η: "n",
792
+ μ: "u",
793
+ };
794
+ const LOWER_CONFUSABLE = new RegExp(`[${Object.keys(LOWER_CONFUSABLES).join("")}]`, "gu");
795
+ /**
796
+ * `word` with every `{placeholder}` dropped (a count the page fills in is
797
+ * not part of the word itself: "{n} met" reads as "met"), compatibility
798
+ * forms folded, punctuation and symbols turned into a space (so internal
799
+ * punctuation still separates words: "not-met" reads as "not met", never
800
+ * "notmet"), whitespace collapsed -- but case and homoglyphs both left
801
+ * alone, so a genuine Cyrillic or Greek word still reads as the one script
802
+ * it is written in (case does not affect which script a letter belongs to,
803
+ * so leaving it be does not weaken `mixesScripts`). Used only for
804
+ * `mixesScripts` and the "no visible word" check, both case-insensitive by
805
+ * nature: a real word must be judged by the letters it actually has, not by
806
+ * what CONFUSABLES maps some of them to.
807
+ */
808
+ function asReadUnfolded(word) {
809
+ return word
810
+ .replace(PLACEHOLDER, "")
811
+ .normalize("NFKC")
812
+ .replace(/[\p{P}\p{S}]/gu, " ")
813
+ .replace(/\s+/gu, " ")
814
+ .trim();
815
+ }
816
+ /**
817
+ * A word as its homoglyph reading: `asReadUnfolded`, with the lowercase
818
+ * letters that read unlike their capital folded first (LOWER_CONFUSABLES),
819
+ * then lowercased and uppercased (so ß and ẞ both become SS), every
820
+ * Cyrillic or Greek homoglyph folded to the Latin letter it reads as
821
+ * (CONFUSABLES, keyed by capital letter), and case ignored. An
822
+ * all-Cyrillic "мет" reads as "met", as does "ΜΕΤ"; "ν" reads as "v".
823
+ * Because ν and Ν read as different Latin letters, this reading alone can
824
+ * tell "ναι" from "ΝΑΙ": `readings` pairs it with a plain case fold.
825
+ */
826
+ function asRead(word) {
827
+ return asReadUnfolded(word)
828
+ .replace(LOWER_CONFUSABLE, (c) => LOWER_CONFUSABLES[c])
829
+ .toLowerCase()
830
+ .toUpperCase()
831
+ .replace(CONFUSABLE, (c) => CONFUSABLES[c])
832
+ .toLowerCase();
833
+ }
834
+ /**
835
+ * Every way a reader may read `word`, for comparisons (DISTINCT,
836
+ * categoryCollisions): its homoglyph reading (`asRead`) and its case fold in
837
+ * its own script, so "Met", "met " and "(met)." are one word, as are "ναι"
838
+ * and "ΝΑΙ" or "ordnungsgemäß" and "ORDNUNGSGEMÄẞ", and "мет" is "met". Two
839
+ * words read alike when any reading of one is a reading of the other. Never
840
+ * used for `mixesScripts`, which needs the word before any folding.
841
+ */
842
+ function readings(word) {
843
+ const caseFolded = asReadUnfolded(word)
844
+ .toLowerCase()
845
+ .toUpperCase()
846
+ .toLowerCase();
847
+ const read = asRead(word);
848
+ return read === caseFolded ? [read] : [read, caseFolded];
849
+ }
850
+ /** Letters from more than one of Latin, Greek and Cyrillic in `word` as actually written (`asReadUnfolded`, no homoglyph folded): a genuine word in one script never mixes, however many of its letters CONFUSABLES would fold; a spoof mixing a real Latin letter with a lookalike still does. */
851
+ function mixesScripts(word) {
852
+ return ([/\p{Script=Latin}/u, /\p{Script=Greek}/u, /\p{Script=Cyrillic}/u].filter((script) => script.test(word)).length > 1);
853
+ }
854
+ /**
855
+ * Every pair of GUARDED_CATEGORY entries from two DIFFERENT categories that,
856
+ * as read, are the same word (4344180862, 4344180866, 4344180870): a result
857
+ * of one category must never read like a result of another. Compared are
858
+ * both the merged word (`merged`, the pack's entries over the defaults --
859
+ * the same lookup `wordingProblems` checks DISTINCT against) and each
860
+ * entry's own shipped default, in both directions: comparing only the
861
+ * merged words would miss a pack that renames its own clean-side entries
862
+ * away from "resolved" while giving a not-clean entry the word "resolved"
863
+ * -- the clean side no longer reads "resolved" in the merged pack, but the
864
+ * gap it left at the clean side's default word is still open for the other
865
+ * category to walk into. Two entries of the SAME category may share a word
866
+ * (the undecided variants' shared "could not decide" by design): that is
867
+ * not this check's business.
868
+ */
869
+ function categoryCollisions(merged, defaults) {
870
+ const problems = [];
871
+ // Single pass, the same owner-map style the DISTINCT loop above uses: the
872
+ // first key to read a given word claims it, and any later key with a
873
+ // different category reading the same word is refused against that owner.
874
+ const seen = new Map();
875
+ // One problem per pair of keys, however many of their readings collide.
876
+ const reported = new Set();
877
+ const visit = (key, category, source) => {
878
+ if (!Object.hasOwn(source, key))
879
+ return;
880
+ for (const word of readings(source[key])) {
881
+ if (word === "")
882
+ continue;
883
+ const owner = seen.get(word);
884
+ if (owner === undefined)
885
+ seen.set(word, { key, category });
886
+ else if (owner.category !== category &&
887
+ !reported.has(`${owner.key}\n${key}`)) {
888
+ reported.add(`${owner.key}\n${key}`);
889
+ problems.push(`${owner.key} and ${key} read alike (${JSON.stringify(word)}); ${CATEGORY_LABEL[owner.category]} must not read like ${CATEGORY_LABEL[category]}, or the other way round`);
890
+ }
891
+ }
892
+ };
893
+ for (const [key, category] of Object.entries(GUARDED_CATEGORY)) {
894
+ visit(key, category, merged);
895
+ visit(key, category, defaults.entries);
896
+ }
897
+ return problems;
898
+ }
899
+ /**
900
+ * Every problem with `pack` as a replacement for `defaults`: a locked line
901
+ * (LOCKED_ENTRIES) reworded, an entry whose placeholders differ from the
902
+ * entry it replaces, a `layout.grouping` that is
903
+ * not the default's, verdict words two verdicts would share (as read), a
904
+ * verdict worded as another verdict reads by default, a verdict word with
905
+ * nothing visible in it, and an entry of one GUARDED_CATEGORY reading like an
906
+ * entry of a different one (a met result like a missed one, an exceptions
907
+ * count like an undecided note, and so on). Entries the defaults do not have
908
+ * are not this module's and are not checked.
909
+ */
910
+ export function wordingProblems(supplied, defaults) {
911
+ const grouping = defaults.entries["layout.grouping"];
912
+ const pack = grouping === "lines" || grouping === "groups"
913
+ ? expandSection3(supplied, grouping)
914
+ : supplied;
915
+ const problems = [];
916
+ if (grouping === "lines" || grouping === "groups")
917
+ for (const [key, targets] of Object.entries(SECTION3_ALIASES[grouping]))
918
+ if (Object.hasOwn(supplied.entries, key))
919
+ for (const target of targets)
920
+ if (Object.hasOwn(supplied.entries, target) &&
921
+ supplied.entries[target] !== supplied.entries[key])
922
+ problems.push(`${key} and ${target} name the same thing and must say the same; this pack gives them different words`);
923
+ for (const [key, text] of Object.entries(pack.entries)) {
924
+ if (INVISIBLE.test(text))
925
+ problems.push(`${key} carries a bidi or other invisible format character, never only stripped for a check: refused outright`);
926
+ if (!Object.hasOwn(defaults.entries, key))
927
+ continue;
928
+ const base = defaults.entries[key];
929
+ if (LOCKED_ENTRIES.has(key)) {
930
+ if (text !== base)
931
+ problems.push(`${key}: this line states what the page checked and can't be reworded`);
932
+ continue;
933
+ }
934
+ if (key.startsWith("layout.")) {
935
+ if (text !== base)
936
+ problems.push(`${key} is ${JSON.stringify(text)}; this report is laid out as ${JSON.stringify(base)}`);
937
+ continue;
938
+ }
939
+ const want = placeholders(base);
940
+ const got = placeholders(text);
941
+ if (want.join(" ") !== got.join(" "))
942
+ problems.push(`${key} uses {${got.join("} {")}}; it must use exactly {${want.join("} {")}}`);
943
+ else {
944
+ const baseGaps = placeholderGaps(base);
945
+ const gotGaps = placeholderGaps(text);
946
+ for (let i = 0; i < gotGaps.length; i++) {
947
+ const baseGap = baseGaps[i];
948
+ const gotGap = gotGaps[i];
949
+ const runsTogether = HAS_LETTER.test(baseGap)
950
+ ? !HAS_LETTER.test(gotGap) ||
951
+ (!HAS_LETTER.test(asRead(gotGap).replace(DIGIT_LIKE, "")) &&
952
+ !(/^\s[^]*\s$/u.test(gotGap) && [...asRead(gotGap)].length === 1))
953
+ : HAS_NON_SPACE.test(baseGap) && !HAS_NON_SPACE.test(gotGap);
954
+ if (runsTogether)
955
+ problems.push(`${key} runs {${got[i]}} and {${got[i + 1]}} together with no word between them; two counts the page computes separately must not be able to read as one`);
956
+ }
957
+ }
958
+ }
959
+ // Only entries the defaults have: a key this module does not own changes
960
+ // nothing on the page, so it must not take part in any comparison either.
961
+ const merged = { ...defaults.entries };
962
+ for (const [key, text] of Object.entries(pack.entries))
963
+ if (Object.hasOwn(defaults.entries, key))
964
+ merged[key] = text;
965
+ for (const set of DISTINCT) {
966
+ const members = set.map((m) => (typeof m === "string" ? [m] : [...m]));
967
+ // Each verdict's default words, as read: a pack may not give one verdict
968
+ // the word another verdict reads as by default (met and not met swapped).
969
+ const defaultOf = new Map();
970
+ for (const keys of members)
971
+ for (const k of keys)
972
+ if (Object.hasOwn(defaults.entries, k))
973
+ for (const word of readings(defaults.entries[k]))
974
+ defaultOf.set(word, keys.join(" / "));
975
+ const seen = new Map();
976
+ for (const keys of members) {
977
+ const name = keys.join(" / ");
978
+ const words = new Set();
979
+ for (const k of keys) {
980
+ if (!Object.hasOwn(merged, k))
981
+ continue;
982
+ const unfolded = asReadUnfolded(merged[k]);
983
+ if (unfolded === "")
984
+ problems.push(`${k} has no visible word`);
985
+ else if (mixesScripts(unfolded))
986
+ problems.push(`${k} mixes Latin, Greek and Cyrillic letters (${JSON.stringify(unfolded)}); a verdict word is written in one script`);
987
+ else
988
+ for (const word of readings(merged[k]))
989
+ words.add(word);
990
+ }
991
+ // One problem per pair of verdicts, however many readings collide.
992
+ const shared = new Set();
993
+ const taken = new Set();
994
+ for (const word of words) {
995
+ const other = seen.get(word);
996
+ if (other !== undefined) {
997
+ if (!shared.has(other))
998
+ problems.push(`${name} and ${other} read alike (${JSON.stringify(word)}); two verdicts must not share a word`);
999
+ shared.add(other);
1000
+ }
1001
+ else
1002
+ seen.set(word, name);
1003
+ const owner = defaultOf.get(word);
1004
+ if (owner !== undefined && owner !== name && !taken.has(owner)) {
1005
+ problems.push(`${name} reads ${JSON.stringify(word)}, the word for ${owner}; a verdict must not take another verdict's word`);
1006
+ taken.add(owner);
1007
+ }
1008
+ }
1009
+ }
1010
+ }
1011
+ problems.push(...categoryCollisions(merged, defaults));
1012
+ return problems.map((p) => `${pack.id}: ${p}`);
1013
+ }
1014
+ /**
1015
+ * sha256 of each default pack exactly as this package ships it --
1016
+ * `wording/contract-report-outcomes.en.json` and
1017
+ * `wording/contract-report-eu-ai-act.en.json`, the literal file bytes, not
1018
+ * a re-serialized form -- so the proofs line's digest is the one a reader
1019
+ * who downloads this package and hashes the file themselves actually gets,
1020
+ * the same canonical form a supplied pack's `wording_sha256` already uses
1021
+ * (`checkWordingPackInput` hashes the bytes as given, never a re-encoding).
1022
+ * contract-report.test.ts hashes the real files on disk and checks these
1023
+ * still match; regenerate with `sha256sum ts/src/wording/*.en.json` after
1024
+ * editing either file.
1025
+ */
1026
+ export const DEFAULT_PACK_SHA256 = Object.freeze({
1027
+ lines: "7065032ca2818ad967a35eaa1dd8c6da43a84861c3babc6446afd24db488dbc0",
1028
+ groups: "37f9e5df13bfb85f3c44ecd13fe0b19265e661e9e4c4e5f6d471c7f27c9d93c1",
1029
+ });
1030
+ function fill(key, text, vars) {
1031
+ return text.replace(PLACEHOLDER, (whole, name) => {
1032
+ if (!Object.hasOwn(vars, name))
1033
+ throw new WordingPackError(`${key}: no value for {${name}}`);
1034
+ return String(vars[name]);
1035
+ });
1036
+ }
1037
+ /**
1038
+ * The words over `defaults`, with `supplied`'s entries in place of the
1039
+ * defaults' where it has them. `context` defaults closed
1040
+ * (`singleContract: false`): a caller that has not checked
1041
+ * `citesOneContract` itself gets raw identifiers for `row`/`group`, never a
1042
+ * guess that a multi-contract Result is safe to label per-contract.
1043
+ */
1044
+ export function wordsOf(defaults, supplied, context = { singleContract: false }, refused) {
1045
+ const declared = defaults.entries["layout.grouping"];
1046
+ const entries = supplied === undefined
1047
+ ? defaults.entries
1048
+ : {
1049
+ ...defaults.entries,
1050
+ ...(declared === "lines" || declared === "groups"
1051
+ ? expandSection3(supplied.pack, declared)
1052
+ : supplied.pack).entries,
1053
+ };
1054
+ const t = (key, vars = {}) => {
1055
+ const text = Object.hasOwn(entries, key) ? entries[key] : undefined;
1056
+ if (text === undefined)
1057
+ throw new WordingPackError(`${defaults.id}: no entry ${key}`);
1058
+ return fill(key, text, vars);
1059
+ };
1060
+ const section3 = (key) => WORDING_KEY.test(key) && Object.hasOwn(entries, key)
1061
+ ? entries[key]
1062
+ : undefined;
1063
+ const grouping = entries["layout.grouping"];
1064
+ if (grouping !== "lines" && grouping !== "groups")
1065
+ throw new WordingPackError(`${defaults.id}: layout.grouping is ${JSON.stringify(grouping)}`);
1066
+ const base = { id: defaults.id, sha256: DEFAULT_PACK_SHA256[grouping] };
1067
+ return {
1068
+ t,
1069
+ p: (key, count, vars = {}) => t(`${key}.${count === 1 ? "one" : "other"}`, {
1070
+ n: count.toLocaleString(),
1071
+ ...vars,
1072
+ }),
1073
+ section3,
1074
+ // A section 3 word that names what the grouping already has a word
1075
+ // for (SECTION3_ALIASES) is read through the grouping's own key, the
1076
+ // one every check covers, so the two can never disagree on the page.
1077
+ enumWord: (family, value) => {
1078
+ const key = `${family}.${value.toLowerCase()}`;
1079
+ const target = SECTION3_ALIASES[grouping][key]?.[0];
1080
+ return target !== undefined ? t(target) : (section3(key) ?? value);
1081
+ },
1082
+ row: (requirementRef, part) => context.singleContract
1083
+ ? section3(`row.${requirementRef}.${part}`)
1084
+ : undefined,
1085
+ group: (segment) => context.singleContract ? section3(`group.${segment}.title`) : undefined,
1086
+ grouping,
1087
+ source: supplied === undefined
1088
+ ? {
1089
+ id: base.id,
1090
+ sha256: base.sha256,
1091
+ ...(refused === undefined ? {} : { base, refused }),
1092
+ }
1093
+ : {
1094
+ id: supplied.pack.id,
1095
+ ...(supplied.sha256 === undefined
1096
+ ? {}
1097
+ : { sha256: supplied.sha256 }),
1098
+ base,
1099
+ },
1100
+ };
1101
+ }
1102
+ /**
1103
+ * The words for a card laid out as `grouping`: the default pack, with the
1104
+ * host's pack over it entry by entry once it checks against its digest and
1105
+ * fits this module (contract-report/v1 §3 layering). A host layer that does
1106
+ * not check is refused and contributes no words: the card is drawn with the
1107
+ * default layer alone, and `source.refused` says why, so the page says so.
1108
+ * A builder that must refuse to write such a page (§3 allows it) checks the
1109
+ * pack itself first (`presentation-builder.ts` `checkWordingFits`), before
1110
+ * this function ever runs.
1111
+ */
1112
+ export async function contractReportWords(grouping, wording, context = { singleContract: false }) {
1113
+ const defaults = DEFAULT_PACKS[grouping];
1114
+ if (wording === undefined)
1115
+ return wordsOf(defaults, undefined, context);
1116
+ const refuse = (reason) => wordsOf(defaults, undefined, context, {
1117
+ sha256: /^[0-9a-f]{64}$/u.test(wording.sha256)
1118
+ ? wording.sha256
1119
+ : "(not a SHA-256)",
1120
+ reason,
1121
+ });
1122
+ let pack;
1123
+ try {
1124
+ pack = await checkWordingPackInput(wording);
1125
+ }
1126
+ catch (e) {
1127
+ if (!(e instanceof WordingPackError))
1128
+ throw e;
1129
+ return refuse(/hash|sha256/u.test(e.message) ? "digest" : "shape");
1130
+ }
1131
+ const problems = wordingProblems(pack, defaults);
1132
+ if (problems.length > 0)
1133
+ return refuse("fit");
1134
+ return wordsOf(defaults, { pack, sha256: wording.sha256 }, context);
1135
+ }
1136
+ /** The default words of one grouping, for the shared parts' callers that are handed none. */
1137
+ export const DEFAULT_WORDS = Object.freeze({
1138
+ lines: wordsOf(DEFAULT_PACKS.lines),
1139
+ groups: wordsOf(DEFAULT_PACKS.groups),
1140
+ });
1141
+ //# sourceMappingURL=contract-report-wording.js.map