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