@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,828 @@
1
+ import { buildComplianceModel, } from "./compliance.js";
2
+ import { COMPLIANCE_CSS } from "./compliance-styles.js";
3
+ import { datedText, datingStatement, notesGap, pinAbsence, span, transcriptRows, verificationRows, wordingRow, } from "./outcome-report-view.js";
4
+ import { NOT_STATED } from "@action-state-group/agent-action-capsule";
5
+ import { DEFAULT_WORDS } from "./contract-report-wording.js";
6
+ import { caseParts, judgedOf, judgeNote, lazyBody, levelToggle, proofList, conversationFold, ruleWord, wordPill, assuranceRow, reportSummary, } from "./report-levels.js";
7
+ import { provenanceLines, renderProvenance, tallyJudges, } from "./report-provenance.js";
8
+ import { renderAggregate, renderCheckYourself, expandableRow, leadWithProvenance, placeMockMark, renderMockJudgeLine, } from "./report-front.js";
9
+ import { buildVerificationPageModel } from "@action-state-group/agent-action-capsule";
10
+ /**
11
+ * The contract-report module's `groups` grouping (contract-report.ts): a
12
+ * report read as requirement groups and the tests under each. The EU AI Act
13
+ * Results are this grouping with the EU AI Act wording pack; every word on
14
+ * it is the pack's (`w`). Drawn by the module in place of `renderResultPage`
15
+ * when the bundle's `eu-ai-act-compliance/v1` extension opts in, after the same verify-first
16
+ * gate every other root family goes through -- nothing here ever runs on a
17
+ * bundle that did not verify. See compliance.ts for where every value on the
18
+ * page comes from: counts, verdicts, test wording, tiers and the pack from
19
+ * the sealed records (or "not stated"); the regulatory mapping from the
20
+ * producer's extension, labelled as such.
21
+ *
22
+ * Two levels and no more (report-levels.ts): the summary states what was
23
+ * checked and the result per obligation and test; toggle 1 on a test opens
24
+ * the sessions behind its exceptions, listed in place and each readable as
25
+ * it stands (every test's result by name, the conversation and its tool
26
+ * calls); toggle 2 in a session opens its proofs. The methodology, mapping and bundle checks sit
27
+ * in one proofs toggle at the foot of the page.
28
+ *
29
+ * The whole card renders inside one `.cc`-classed wrapper with its own
30
+ * `<style>` (`COMPLIANCE_CSS`) as its first child.
31
+ */
32
+ function element(tag, text) {
33
+ const value = document.createElement(tag);
34
+ if (text !== undefined)
35
+ value.textContent = text;
36
+ return value;
37
+ }
38
+ function el(tag, className, text) {
39
+ const value = element(tag, text);
40
+ value.className = className;
41
+ return value;
42
+ }
43
+ /**
44
+ * Producer text: the eu-ai-act-compliance/v1 mapping, carried beside the
45
+ * signed records and signed by no one. Set in italics (`<i>`, the browser's
46
+ * own style) and tagged `data-source="producer"`, so it never reads as a
47
+ * sealed finding; the summary's basis line says what the italics mean.
48
+ */
49
+ function producerText(w, ...content) {
50
+ const value = element("i");
51
+ value.append(...content);
52
+ value.dataset.source = "producer";
53
+ // The tooltip comes from the card's own pack, per render.
54
+ value.title = w.t("groups.producer.title");
55
+ return value;
56
+ }
57
+ /** `text` in an element of its own, as producer text when `producer` is true. */
58
+ function maybeProducer(w, tag, className, text, producer) {
59
+ if (!producer)
60
+ return el(tag, className, text);
61
+ const value = el(tag, className);
62
+ value.append(producerText(w, text));
63
+ return value;
64
+ }
65
+ const fmt = (n) => n.toLocaleString();
66
+ /** `{n} <noun>` from the pack's `groups.count.<noun>.one|other`. */
67
+ const count = (w, noun, n) => w.p(`groups.count.${noun}`, n, { n: fmt(n) });
68
+ const SEVERITY_CLASS = {
69
+ High: "high",
70
+ Medium: "medium",
71
+ Low: "low",
72
+ };
73
+ /** The producer's severity, as the producer's: an unknown value gets no colour of its own, never "medium". */
74
+ function severityPill(severity, w) {
75
+ const cls = Object.hasOwn(SEVERITY_CLASS, severity)
76
+ ? SEVERITY_CLASS[severity]
77
+ : undefined;
78
+ const pill = el("span", cls === undefined ? "sev" : `sev ${cls}`);
79
+ pill.append(producerText(w, severity));
80
+ return pill;
81
+ }
82
+ function tierBadge(tier, w) {
83
+ const key = tier === "judged" || tier === "recomputed" || tier === "mixed"
84
+ ? tier
85
+ : "unstated";
86
+ const badge = el("span", `kind ${tier === "judged" || tier === "recomputed" ? tier : "unstated"}`, w.t(`groups.tier.${key}`));
87
+ badge.dataset.tier = tier;
88
+ badge.title =
89
+ tier === "judged" || tier === "recomputed"
90
+ ? w.t(`groups.tier.${tier}.title`)
91
+ : "";
92
+ return badge;
93
+ }
94
+ function statusPill(statusClass, text) {
95
+ return el("span", `st ${statusClass}`, text);
96
+ }
97
+ /**
98
+ * A word a host pack sets for this contract (contract-report/v1 section 3:
99
+ * `group.<segment>.title`, `row.<requirement_ref>.label` and the rest),
100
+ * drawn in the page's own voice and tagged `data-wording="pack"`: never
101
+ * producer text, never a sealed record.
102
+ */
103
+ function packWord(tag, className, text) {
104
+ const value = el(tag, className, text);
105
+ value.dataset.wording = "pack";
106
+ return value;
107
+ }
108
+ /** A test's name: the pack's `row.<ref>.label` when it sets one, else the producer's label or the test id made readable. */
109
+ function rowName(w, tag, className, row) {
110
+ const label = w.row(row.criterionId, "label");
111
+ return label !== undefined
112
+ ? packWord(tag, className, label)
113
+ : maybeProducer(w, tag, className, row.name, row.producerName);
114
+ }
115
+ /** An obligation's heading after its article: the pack's `group.<segment>.title` when it sets one, else the producer's title. */
116
+ function obligationName(w, obligation, article) {
117
+ const title = w.group(obligation.key);
118
+ if (title !== undefined)
119
+ return [article, packWord("span", "", ` · ${title}`)];
120
+ return obligation.mapped
121
+ ? [producerText(w, article, ` · ${obligation.title}`)]
122
+ : [article, element("span", ` · ${obligation.title}`)];
123
+ }
124
+ /** Each test's short name, by its criterion id, as producer text when it is the producer's label. */
125
+ function testNames(model, w) {
126
+ const rows = new Map(model.obligations.flatMap((o) => o.rows.map((r) => [r.criterionId, r])));
127
+ return (criterionId, tag, className) => {
128
+ const row = rows.get(criterionId);
129
+ return rowName(w, tag, className, {
130
+ criterionId,
131
+ name: row?.name ?? criterionId,
132
+ producerName: row?.producerName === true,
133
+ });
134
+ };
135
+ }
136
+ function sessionSpan(model, w) {
137
+ const days = model.sessions
138
+ .map((s) => s.day)
139
+ .filter((d) => d !== NOT_STATED)
140
+ .sort();
141
+ const first = days[0];
142
+ const last = days[days.length - 1];
143
+ if (first === undefined || last === undefined)
144
+ return undefined;
145
+ return first === last ? first : w.t("card.span", { from: first, to: last });
146
+ }
147
+ // ---------------------------------------------------------------------------
148
+ // Header
149
+ // ---------------------------------------------------------------------------
150
+ function renderHeader(host, model, w) {
151
+ const hd = el("div", "hd");
152
+ hd.dataset.section = "header";
153
+ // The report's name is the pack's (`groups.kicker`). The regulation is
154
+ // the producer's mapping, so it opens L1 (renderSummary), never L0
155
+ // (presentation contract section 6).
156
+ hd.append(el("h1", "", w.t("groups.kicker")));
157
+ const summary = reportSummary(w);
158
+ if (summary !== undefined)
159
+ hd.append(summary);
160
+ const pack = model.pack.id === NOT_STATED
161
+ ? w.t("groups.pack.not-stated")
162
+ : w.t("groups.pack", { id: model.pack.id, version: model.pack.version });
163
+ const period = sessionSpan(model, w);
164
+ const vars = {
165
+ pack,
166
+ obligations: count(w, "obligation", model.obligations.length),
167
+ sessions: count(w, "session", model.totalSessions),
168
+ };
169
+ hd.append(el("div", "sub", period === undefined
170
+ ? w.t("groups.sub", vars)
171
+ : w.t(model.dating.basis === "judged"
172
+ ? "groups.sub.judged"
173
+ : "groups.sub.dated", { ...vars, period })));
174
+ host.append(hd);
175
+ }
176
+ // ---------------------------------------------------------------------------
177
+ // Summary: what was checked and what we found
178
+ // ---------------------------------------------------------------------------
179
+ /** A test no session has a met, not-met, undecided or unverified result for: nothing was checked. */
180
+ function nothingChecked(row) {
181
+ return (row.metCount +
182
+ row.notMetCount +
183
+ row.notEvaluableCount +
184
+ row.outOfScopeCount +
185
+ row.unverifiedCount ===
186
+ 0);
187
+ }
188
+ /** No session with a result for this test met it, did not, or was judged out of scope: every one was undecided or could not be verified. */
189
+ function noneDecided(row) {
190
+ return (row.metCount === 0 && row.notMetCount === 0 && row.outOfScopeCount === 0);
191
+ }
192
+ /** The sessions a test's population counts: not the ones it did not apply to, and not the ones whose claim is not yet in force (Result v0 section 4.3). */
193
+ function population(row, totalSessions) {
194
+ return totalSessions - row.notApplicableCount - row.notYetInForceCount;
195
+ }
196
+ /** Every claim for this test is not yet in force: readiness only, nothing in force to count (Result v0 section 4.3). */
197
+ function allLater(row) {
198
+ return nothingChecked(row) && row.notYetInForceCount > 0;
199
+ }
200
+ /**
201
+ * An obligation's status, from the sealed counts alone. Its applicability
202
+ * (in force, or from a later date) is the producer's mapping: it is never
203
+ * drawn in this pill, which speaks only for the records, and is shown
204
+ * instead in the producer's own italic line beside the title.
205
+ *
206
+ * "No exceptions", in the ok tone, only when every one of its tests was met
207
+ * by at least one session and no session's result for it was not met: an
208
+ * obligation one of whose tests no session met (every result undecided,
209
+ * unverified or absent) does not read clean. When none of its tests could
210
+ * be checked it reads "Could not be checked"; when some could not, the pill
211
+ * is neutral and says how many.
212
+ */
213
+ export function obligationStatus(obligation, w = DEFAULT_WORDS.groups) {
214
+ const exceptions = obligation.rows.reduce((sum, r) => sum + r.notMetCount, 0);
215
+ // Result v0 section 4.3: only when every test is wholly later is there no
216
+ // population to have no exceptions in. A test in force whose claims all
217
+ // failed verification is still in force: its failure is never hidden
218
+ // behind "Not yet in force".
219
+ if (obligation.rows.length > 0 && obligation.rows.every(allLater))
220
+ return { cls: "na", text: w.t("groups.ob.later") };
221
+ // A wholly later test was not "could not be checked": it is not in force
222
+ // yet, so it is left out of both counts.
223
+ const inForce = obligation.rows.filter((r) => !allLater(r));
224
+ const unchecked = inForce.filter((r) => noneDecided(r)).length;
225
+ const unverified = obligation.rows.reduce((sum, r) => sum + r.unverifiedCount, 0);
226
+ const total = inForce.length;
227
+ const uncheckedText = unchecked > 0
228
+ ? w.t("groups.ob.unchecked-of", {
229
+ unchecked: fmt(unchecked),
230
+ total: count(w, "test", total),
231
+ })
232
+ : "";
233
+ if (exceptions > 0)
234
+ return {
235
+ cls: "exc",
236
+ text: `${count(w, "exception", exceptions)}${unchecked > 0 && unchecked < total ? uncheckedText : ""}`,
237
+ };
238
+ if (unchecked === total)
239
+ return { cls: "ne", text: w.t("groups.ob.unchecked") };
240
+ if (unchecked > 0)
241
+ return { cls: "ne", text: `${w.t("groups.ob.ok.found")}${uncheckedText}` };
242
+ if (unverified > 0)
243
+ return {
244
+ cls: "ne",
245
+ text: w.t("groups.ob.ok.unverified", {
246
+ unverified: count(w, "result", unverified),
247
+ }),
248
+ };
249
+ return { cls: "ok", text: w.t("groups.ob.ok") };
250
+ }
251
+ /** A test's result in the summary: a status, and an optional note under it. */
252
+ export function rowStatus(row, w = DEFAULT_WORDS.groups) {
253
+ if (allLater(row))
254
+ return {
255
+ cls: "na",
256
+ text: w.t("groups.row.later"),
257
+ note: w.t("groups.row.later-note", { n: fmt(row.notYetInForceCount) }),
258
+ };
259
+ if (nothingChecked(row))
260
+ return { cls: "ne", text: w.t("groups.row.nothing") };
261
+ if (noneDecided(row)) {
262
+ const packNotEvaluable = row.notEvaluableCount > 0
263
+ ? w.row(row.criterionId, "not_evaluable")
264
+ : undefined;
265
+ // Module-only notes a producer or pack word never speaks for: unverified
266
+ // and not-yet-in-force claims can coexist with an undecided row, and
267
+ // both must still be said, whichever of the two branches below applies.
268
+ const moduleNotes = [
269
+ ...(row.unverifiedCount > 0
270
+ ? [w.t("groups.row.unverified-note", { n: fmt(row.unverifiedCount) })]
271
+ : []),
272
+ ...(row.notYetInForceCount > 0
273
+ ? [w.t("groups.row.later-note", { n: fmt(row.notYetInForceCount) })]
274
+ : []),
275
+ ];
276
+ if (packNotEvaluable !== undefined)
277
+ return {
278
+ cls: "ne",
279
+ text: w.t("groups.row.none-decided"),
280
+ note: [packNotEvaluable, ...moduleNotes].join("; "),
281
+ };
282
+ if (row.notEvaluableNote !== undefined && row.notEvaluableCount > 0)
283
+ return {
284
+ cls: "ne",
285
+ text: w.t("groups.row.none-decided"),
286
+ note: row.notEvaluableNote,
287
+ producerNote: true,
288
+ };
289
+ return {
290
+ cls: "ne",
291
+ text: w.t("groups.row.none-decided"),
292
+ ...(moduleNotes.length > 0 ? { note: moduleNotes.join("; ") } : {}),
293
+ };
294
+ }
295
+ const notes = [
296
+ ...(row.notEvaluableCount > 0
297
+ ? [w.t("groups.row.undecided-note", { n: fmt(row.notEvaluableCount) })]
298
+ : []),
299
+ ...(row.unverifiedCount > 0
300
+ ? [w.t("groups.row.unverified-note", { n: fmt(row.unverifiedCount) })]
301
+ : []),
302
+ ...(row.outOfScopeCount > 0
303
+ ? [w.t("groups.row.out-of-scope-note", { n: fmt(row.outOfScopeCount) })]
304
+ : []),
305
+ ...(row.notYetInForceCount > 0
306
+ ? [w.t("groups.row.later-note", { n: fmt(row.notYetInForceCount) })]
307
+ : []),
308
+ ];
309
+ const undecided = notes.length > 0 ? { note: notes.join("; ") } : {};
310
+ if (row.notMetCount > 0)
311
+ return {
312
+ cls: "exc",
313
+ text: w.p("groups.row.exceptions", row.notMetCount, {
314
+ n: fmt(row.notMetCount),
315
+ }),
316
+ ...undecided,
317
+ };
318
+ // Every decided result was judged out of scope: it did not arise, which
319
+ // is never met (Result v0 section 4.2), so never "no exceptions" either.
320
+ if (row.metCount === 0)
321
+ return { cls: "na", text: w.t("groups.row.out-of-scope"), ...undecided };
322
+ // Neither word set says more than "no exceptions": a session's result
323
+ // that was met is all the records show, never "established in every
324
+ // session".
325
+ return {
326
+ cls: row.unverifiedCount > 0 ? "ne" : "ok",
327
+ text: w.t(row.notEvaluableCount === 0
328
+ ? "groups.row.ok.all-decided"
329
+ : "groups.row.ok"),
330
+ ...undecided,
331
+ };
332
+ }
333
+ function rowResult(row, w) {
334
+ const cell = document.createElement("td");
335
+ const status = rowStatus(row, w);
336
+ cell.append(statusPill(status.cls, status.text));
337
+ if (status.note !== undefined)
338
+ cell.append(maybeProducer(w, "div", "applic", status.note, status.producerNote === true));
339
+ return cell;
340
+ }
341
+ function renderSummary(host, model, presentation, w) {
342
+ const section = el("section", "");
343
+ section.dataset.section = "summary";
344
+ const regulation = maybeProducer(w, "p", "kicker", model.regulation, true);
345
+ regulation.dataset.regulation = "";
346
+ section.append(regulation, el("h2", "", w.t("groups.summary.h")));
347
+ const tests = model.obligations.reduce((n, o) => n + o.rows.length, 0);
348
+ section.append(el("p", "lede", w.t("groups.summary.lede", {
349
+ tests: count(w, "test", tests),
350
+ obligations: count(w, "obligation", model.obligations.length),
351
+ })));
352
+ const table = document.createElement("table");
353
+ table.className = "grid sum";
354
+ table.dataset.rows = "summary";
355
+ const thead = document.createElement("thead");
356
+ const headRow = document.createElement("tr");
357
+ headRow.append(element("th", w.t("groups.summary.col.test")), el("th", "n", w.t("groups.summary.col.checked-in")), element("th", w.t("groups.summary.col.result")));
358
+ thead.append(headRow);
359
+ table.append(thead);
360
+ for (const obligation of model.obligations) {
361
+ const tbody = document.createElement("tbody");
362
+ tbody.dataset.obligationGroup = obligation.key;
363
+ const row = el("tr", "ob");
364
+ row.dataset.obligation = obligation.key;
365
+ // A group heading (contract-report/v1 section 2): its tests are the
366
+ // rows. No tally sums the tests' sessions here. The heading opens to
367
+ // the obligation's plain-language text and when it applies, kept
368
+ // together (decision D3).
369
+ const title = el("td", "");
370
+ title.setAttribute("colspan", "3");
371
+ const name = el("b", "obn");
372
+ name.append(...obligationName(w, obligation, el("span", "art", obligation.article)));
373
+ title.append(name);
374
+ row.append(title);
375
+ tbody.append(row);
376
+ const about = el("tr", "drill-row ob-about");
377
+ about.dataset.aboutFor = obligation.key;
378
+ const aboutCell = el("td", "");
379
+ aboutCell.setAttribute("colspan", "3");
380
+ about.append(aboutCell);
381
+ expandableRow(row, name, about, () => {
382
+ const body = el("div", "ob-x");
383
+ if (obligation.plain !== NOT_STATED)
384
+ body.append(maybeProducer(w, "div", "plain", obligation.plain, true));
385
+ body.append(maybeProducer(w, "div", "applic", obligation.applicability.note, obligation.mapped));
386
+ return body;
387
+ }, `ob-${obligation.key}`, true);
388
+ tbody.append(about);
389
+ for (const test of obligation.rows) {
390
+ const tr = el("tr", "test");
391
+ tr.dataset.criterion = test.criterionId;
392
+ const counted = population(test, model.totalSessions);
393
+ tr.dataset.population = String(counted);
394
+ tr.dataset.outOfScope = String(test.outOfScopeCount);
395
+ tr.dataset.notYetInForce = String(test.notYetInForceCount);
396
+ tr.dataset.exceptions = String(test.notMetCount);
397
+ tr.dataset.notEvaluable = String(test.notEvaluableCount);
398
+ const nameCell = el("td", "tn");
399
+ const head = el("div", "tnh");
400
+ const testName = rowName(w, "b", "", test);
401
+ head.append(testName, tierBadge(test.tier, w));
402
+ nameCell.append(head);
403
+ const detail = w.row(test.criterionId, "detail");
404
+ if (detail !== undefined)
405
+ nameCell.append(packWord("div", "plain", detail));
406
+ const sessionIds = [
407
+ ...(test.sessionsByVerdict.get("not_met") ?? []),
408
+ ...(test.sessionsByVerdict.get("unverified") ?? []),
409
+ ...(test.sessionsByVerdict.get("not_evaluable") ?? []),
410
+ ];
411
+ tr.append(nameCell, el("td", "n", count(w, "session", counted)), rowResult(test, w));
412
+ tbody.append(tr);
413
+ // The row itself opens the sessions behind it, in a full-width row
414
+ // below it, so each one reads at the table's width.
415
+ if (sessionIds.length > 0) {
416
+ const drillRow = el("tr", "drill-row");
417
+ drillRow.dataset.drillFor = test.criterionId;
418
+ const cell = document.createElement("td");
419
+ cell.setAttribute("colspan", "3");
420
+ drillRow.append(cell);
421
+ const toggle = expandableRow(tr, testName, drillRow, () => renderSessionList(sessionIds, model, presentation, w), `test-${obligation.key}-${test.criterionId}`);
422
+ toggle.dataset.records = "sessions";
423
+ toggle.dataset.drill = test.criterionId;
424
+ tbody.append(drillRow);
425
+ }
426
+ }
427
+ table.append(tbody);
428
+ }
429
+ section.append(table);
430
+ const notes = el("aside", "footnotes");
431
+ notes.dataset.section = "footnotes";
432
+ const basis = el("p", "", w.t("groups.summary.basis"));
433
+ basis.dataset.basis = "terms";
434
+ notes.append(basis);
435
+ section.append(notes);
436
+ host.append(section);
437
+ }
438
+ /**
439
+ * The producer's findings (severity, recommendation), in one block under a
440
+ * fixed label: presentation text, not evidence (presentation contract
441
+ * section 6). Each finding's session count is the claims'; nothing here
442
+ * tallies the findings themselves.
443
+ */
444
+ function renderFindings(host, model, w) {
445
+ if (model.findings.length === 0)
446
+ return;
447
+ const section = el("section", "findings");
448
+ section.dataset.section = "findings";
449
+ section.dataset.producer = "";
450
+ section.append(el("div", "plabel", w.t("front.findings.label")), el("h2", "", w.t("front.findings.h")));
451
+ for (const finding of model.findings)
452
+ section.append(renderFinding(finding, w));
453
+ host.append(section);
454
+ }
455
+ function renderFinding(finding, w) {
456
+ const box = el("div", "fnd");
457
+ box.dataset.finding = finding.id;
458
+ const fh = el("div", "fh");
459
+ fh.append(maybeProducer(w, "b", "", w.t("groups.finding", { id: finding.id }), true), severityPill(finding.severity, w), element("span", count(w, "session", finding.sessionIds.length)));
460
+ box.append(fh);
461
+ box.append(maybeProducer(w, "div", "rec", finding.recommendation, true));
462
+ const own = el("div", "own", w.t("groups.finding.owner"));
463
+ own.append(producerText(w, finding.ownerDue));
464
+ box.append(own);
465
+ return box;
466
+ }
467
+ // ---------------------------------------------------------------------------
468
+ // Level 1: sessions, listed in place, each readable as it stands
469
+ // ---------------------------------------------------------------------------
470
+ function renderSessionList(conversationIds, model, presentation, w) {
471
+ const byId = new Map(model.sessions.map((s) => [s.conversationId, s]));
472
+ const list = el("div", "convs");
473
+ list.dataset.sessionCount = String(conversationIds.length);
474
+ for (const id of conversationIds) {
475
+ const session = byId.get(id);
476
+ if (session !== undefined)
477
+ list.append(renderSession(session, model, presentation, w));
478
+ }
479
+ return list;
480
+ }
481
+ /**
482
+ * A claim not yet in force, in words: its date as the producer copied it
483
+ * from the contract, never checked here, and never counted; beside it, the
484
+ * conditions that narrow when or to whom the obligation binds, in the
485
+ * pack's words (`row.<ref>.detail`), never the presentation block's (a
486
+ * hint with dates of its own). The date is never drawn alone (decision
487
+ * D3): with no such words, the line says the conditions are not stated.
488
+ */
489
+ function laterNote(test, w, tag) {
490
+ // A claim is later only when it carries applies_from (Result v0 4.3).
491
+ const note = el(tag, "applic", w.t("groups.later.note", { date: test.claim?.appliesFrom ?? "" }));
492
+ const conditions = w.row(test.criterionId, "detail");
493
+ note.append(" ", conditions === undefined
494
+ ? w.t("groups.later.conditions-not-stated")
495
+ : packWord("span", "", conditions));
496
+ return note;
497
+ }
498
+ function isException(test) {
499
+ return test.verdict === "not_met";
500
+ }
501
+ function isUnverified(test) {
502
+ return test.verdict === "failed" || test.verdict === "unsupported";
503
+ }
504
+ /** One session, in place inside a level-1 toggle: a header line and its body right below it, never a toggle of its own; the body is built when it scrolls near the view. */
505
+ function renderSession(session, model, presentation, w) {
506
+ const names = testNames(model, w);
507
+ const exceptions = session.tests.filter(isException);
508
+ const unverified = session.tests.filter(isUnverified);
509
+ const undecided = session.tests.filter((t) => t.verdict === "not_evaluable");
510
+ const parts = caseParts(session.conversationId, w);
511
+ const item = el("article", "conv session");
512
+ item.dataset.session = session.conversationId;
513
+ const head = el("div", "conv-h");
514
+ head.append(el("span", "cid", parts.label));
515
+ head.append(exceptions.length > 0
516
+ ? wordPill({ word: count(w, "exception", exceptions.length), tone: "bad" }, "exceptions")
517
+ : unverified.length > 0
518
+ ? wordPill({ word: w.t("groups.session.unverified"), tone: "ne" }, "unverified")
519
+ : undecided.length > 0
520
+ ? wordPill({ word: w.t("groups.session.undecided"), tone: "ne" }, "undecided")
521
+ : session.tests.some((t) => t.verdict === "met")
522
+ ? wordPill({ word: w.t("groups.session.ok"), tone: "ok" }, "ok")
523
+ : wordPill({ word: w.t("groups.session.none"), tone: "na" }, "none"));
524
+ const why = el("span", "cwhy");
525
+ (exceptions.length > 0
526
+ ? exceptions
527
+ : unverified.length > 0
528
+ ? unverified
529
+ : undecided).forEach((t, i) => {
530
+ if (i > 0)
531
+ why.append(", ");
532
+ why.append(names(t.criterionId, "span", ""));
533
+ });
534
+ head.append(why);
535
+ head.append(el("span", "cmodel", parts.model ?? session.day));
536
+ item.append(head);
537
+ const body = el("div", "conv-slot");
538
+ item.append(body);
539
+ lazyBody(body, () => sessionBody(session, model, presentation, w));
540
+ return item;
541
+ }
542
+ function sessionBody(session, model, presentation, w) {
543
+ const names = testNames(model, w);
544
+ const body = el("div", "conv-b");
545
+ body.append(el("h4", "", w.t("groups.h.test-by-test")));
546
+ for (const test of session.tests) {
547
+ const box = el("div", "ck");
548
+ box.dataset.crit = test.criterionId;
549
+ box.dataset.critVerdict = test.verdict;
550
+ const h = el("div", "h");
551
+ h.append(wordPill(ruleWord(test.verdict, judgedOf(test.reportState, test.judgePinDigest), w), test.verdict));
552
+ h.append(names(test.criterionId, "span", "tname"));
553
+ if (test.verdict !== "not_applicable" &&
554
+ test.verdict !== "not_yet_in_force")
555
+ h.append(tierBadge(test.tier, w));
556
+ if (test.verdict === "failed" || test.verdict === "unsupported")
557
+ h.append(el("span", "applic", w.t("groups.unverified-note")));
558
+ if (test.verdict === "not_yet_in_force")
559
+ h.append(laterNote(test, w, "span"));
560
+ box.append(h);
561
+ if (test.rationale !== undefined)
562
+ box.append(el("div", "why", judgeNote(test.rationale, test.claim?.verdict ?? test.verdict, w)));
563
+ body.append(box);
564
+ }
565
+ if (session.tests.every((t) => t.rationale === undefined)) {
566
+ const gap = el("p", "small", notesGap(session.tests.flatMap((t) => t.claim === undefined ? [] : [t.reportState]), w));
567
+ gap.dataset.gaps = "true";
568
+ body.append(gap);
569
+ }
570
+ body.append(conversationFold(session.transcript, session.sourceCapsuleId, w));
571
+ body.append(levelToggle(2, w.t("card.proofs.toggle"), () => sessionProofs(session, model, w), { className: "proofs" }));
572
+ return body;
573
+ }
574
+ function sessionProofs(session, model, w) {
575
+ const names = testNames(model, w);
576
+ const box = el("div", "pf-b");
577
+ box.dataset.proofsFor = session.conversationId;
578
+ // Which date the session is counted under, verbatim, beside the sealed day:
579
+ // the outcome card's rule, so a backfilled session never reads as if it
580
+ // happened on the day it was sealed.
581
+ const dated = session.dated;
582
+ const dating = dated.basis === "judged"
583
+ ? []
584
+ : [
585
+ [w.t("groups.pf.dated"), datedText(dated, w), { dated: dated.basis }],
586
+ ...(dated.importedAt === undefined
587
+ ? []
588
+ : [
589
+ [
590
+ w.t("card.pf.imported"),
591
+ dated.importedAt,
592
+ { imported: "" },
593
+ ],
594
+ ]),
595
+ ];
596
+ const rows = [
597
+ [w.t("groups.pf.session"), session.conversationId],
598
+ ...dating,
599
+ [w.t("card.pf.judged-sealed"), session.judgedDay, { sealed: "" }],
600
+ [
601
+ w.t("card.pf.case-record"),
602
+ session.sourceCapsuleId === undefined
603
+ ? w.t("card.pf.case-record.not-stated")
604
+ : session.caseFrom === "claims"
605
+ ? w.t("groups.pf.case-record.from-claims", {
606
+ record: session.sourceCapsuleId,
607
+ })
608
+ : session.sourceCapsuleId,
609
+ ],
610
+ ];
611
+ rows.push(...transcriptRows(session.transcript, w));
612
+ rows.push([w.t("card.pf.result-capsule"), model.capsuleId]);
613
+ const dl = proofList(rows);
614
+ dl.dataset.checkIt = session.conversationId;
615
+ box.append(dl);
616
+ box.append(el("h5", "", w.t("groups.pf.h.each-report")));
617
+ for (const test of session.tests) {
618
+ const ev = el("div", "ev");
619
+ ev.dataset.proofCrit = test.criterionId;
620
+ const label = names(test.criterionId, "b", "");
621
+ label.append(": ");
622
+ ev.append(label);
623
+ if (test.verdict === "not_applicable") {
624
+ ev.append(element("span", w.t("groups.pf.no-claim")));
625
+ }
626
+ else if (test.verdict === "not_yet_in_force") {
627
+ ev.append(laterNote(test, w, "span"));
628
+ }
629
+ else {
630
+ if (test.reportDigest !== undefined)
631
+ ev.append(element("code", test.reportDigest));
632
+ if (test.contract !== undefined)
633
+ ev.append(element("code", test.contract));
634
+ if (test.judgePinDigest !== undefined)
635
+ ev.append(element("code", w.t("groups.pf.judge-pin", { digest: test.judgePinDigest })));
636
+ if (test.rationale !== undefined) {
637
+ const sealed = el("div", "sealed", w.t("groups.pf.rationale", { rationale: test.rationale }));
638
+ sealed.dataset.rationale = "sealed";
639
+ ev.append(sealed);
640
+ }
641
+ if (test.reportDigest === undefined)
642
+ ev.append(element("span", w.t("groups.pf.absent")));
643
+ }
644
+ // contract-report/v1 section 2: assurance stays on the claim.
645
+ if (test.claim !== undefined)
646
+ ev.append(proofList([assuranceRow(test.claim, w)]));
647
+ box.append(ev);
648
+ }
649
+ return box;
650
+ }
651
+ // ---------------------------------------------------------------------------
652
+ // Proofs for the whole report
653
+ // ---------------------------------------------------------------------------
654
+ function pinText(model, w) {
655
+ if (model.runInfo.judgePinDigest !== undefined)
656
+ return model.runInfo.judgePinDigest;
657
+ if (!model.runInfo.pinned)
658
+ return w.t("groups.pin.differs");
659
+ return pinAbsence(model.runInfo, w) ?? w.t("groups.pin.none");
660
+ }
661
+ function renderReportProofs(host, model, bundle, verified, w) {
662
+ const section = el("section", "rp");
663
+ section.dataset.section = "report-proofs";
664
+ section.append(levelToggle(2, w.t("groups.rp.toggle"), () => {
665
+ const box = el("div", "pf-b");
666
+ renderObligationDetails(box, model, w);
667
+ renderQuality(box, model, w);
668
+ renderWhatRan(box, model, w);
669
+ renderVerificationDetails(box, bundle, verified, w);
670
+ return box;
671
+ }, { className: "proofs" }));
672
+ host.append(section);
673
+ }
674
+ function renderObligationDetails(host, model, w) {
675
+ const part = el("div", "rp-s");
676
+ part.dataset.section = "obligation-detail";
677
+ part.append(el("h3", "", w.t("groups.od.h")));
678
+ for (const obligation of model.obligations) {
679
+ const box = el("div", "obd");
680
+ box.dataset.obligationDetail = obligation.key;
681
+ box.dataset.mapped = String(obligation.mapped);
682
+ const heading = element("h5");
683
+ heading.append(...obligationName(w, obligation, element("span", obligation.article)));
684
+ box.append(heading);
685
+ box.append(el("p", "na", w.t(obligation.mapped ? "groups.od.mapped" : "groups.od.unmapped")));
686
+ if (obligation.judgedTerms.length > 0) {
687
+ const terms = el("p", "applic", w.t("groups.od.judged-terms"));
688
+ terms.append(producerText(w, obligation.judgedTerms.join(", ")));
689
+ box.append(terms);
690
+ }
691
+ box.append(maybeProducer(w, "p", "", obligation.method, obligation.mapped));
692
+ for (const row of obligation.rows) {
693
+ const rowBox = el("div", "ck");
694
+ rowBox.dataset.wording = row.wording.source;
695
+ const h = el("div", "h");
696
+ h.append(rowName(w, "span", "", row), tierBadge(row.tier, w));
697
+ rowBox.append(h);
698
+ rowBox.append(el("div", "why", row.wording.source === "sealed"
699
+ ? w.t("groups.od.wording.sealed", { text: row.wording.text })
700
+ : w.t(row.wording.source === "mixed"
701
+ ? "groups.od.wording.mixed"
702
+ : "groups.od.wording.unstated")));
703
+ const packNote = w.row(row.criterionId, "not_evaluable");
704
+ if (packNote !== undefined)
705
+ rowBox.append(packWord("div", "ev", packNote));
706
+ else if (row.notEvaluableNote !== undefined)
707
+ rowBox.append(maybeProducer(w, "div", "ev", row.notEvaluableNote, true));
708
+ box.append(rowBox);
709
+ }
710
+ part.append(box);
711
+ }
712
+ host.append(part);
713
+ }
714
+ function renderQuality(host, model, w) {
715
+ const part = el("div", "rp-s");
716
+ part.dataset.section = "quality";
717
+ part.append(el("h3", "", w.t("groups.q.h")));
718
+ const protocol = model.qualityProtocol;
719
+ if (protocol === undefined) {
720
+ part.append(el("p", "", w.t("groups.q.none")));
721
+ host.append(part);
722
+ return;
723
+ }
724
+ const line = el("p", "", w.t("groups.q.protocol"));
725
+ line.append(protocol.protocol === undefined
726
+ ? w.t("groups.q.unspecified")
727
+ : producerText(w, protocol.protocol));
728
+ if (protocol.cadence !== undefined)
729
+ line.append(", ", producerText(w, protocol.cadence));
730
+ line.append(w.t("groups.q.tail"));
731
+ part.append(line);
732
+ if (protocol.note !== undefined)
733
+ part.append(maybeProducer(w, "p", "na", protocol.note, true));
734
+ host.append(part);
735
+ }
736
+ function renderWhatRan(host, model, w) {
737
+ const part = el("div", "rp-s");
738
+ part.dataset.section = "methodology";
739
+ part.append(el("h3", "", w.t("groups.ran.h")));
740
+ const dl = proofList([
741
+ [
742
+ w.t("groups.ran.contract"),
743
+ model.runInfo.contract ??
744
+ w.t(model.runInfo.pinned
745
+ ? "groups.ran.contract.none"
746
+ : "groups.ran.contract.differs"),
747
+ ],
748
+ [w.t("groups.ran.judge-pin"), pinText(model, w)],
749
+ [w.t("groups.ran.sessions"), fmt(model.totalSessions)],
750
+ ...(model.dating.from === undefined || model.dating.to === undefined
751
+ ? []
752
+ : [
753
+ [
754
+ w.t("groups.ran.period"),
755
+ span([model.dating.from, model.dating.to], w),
756
+ { period: "" },
757
+ ],
758
+ ]),
759
+ ...(model.dating.basis === "judged"
760
+ ? []
761
+ : [
762
+ [
763
+ w.t("groups.ran.sealed"),
764
+ span(model.dating.judgedDays, w),
765
+ { sealed: "" },
766
+ ],
767
+ ]),
768
+ [w.t("card.pf.result-capsule"), model.capsuleId],
769
+ wordingRow(w),
770
+ ]);
771
+ dl.dataset.ran = "true";
772
+ part.append(dl);
773
+ const note = datingStatement(model.dating, model.totalSessions, w);
774
+ if (note !== undefined) {
775
+ const p = el("p", "na", note);
776
+ p.dataset.dateNote = model.dating.basis;
777
+ part.append(p);
778
+ }
779
+ host.append(part);
780
+ }
781
+ function renderVerificationDetails(host, bundle, verified, w) {
782
+ const part = el("div", "rp-s");
783
+ part.dataset.section = "verification-details";
784
+ part.append(el("h3", "", w.t("card.vd.h")));
785
+ const model = buildVerificationPageModel(bundle, verified);
786
+ part.append(proofList(verificationRows(model, w)));
787
+ part.append(el("p", "", w.t("groups.vd.note")));
788
+ host.append(part);
789
+ }
790
+ // ---------------------------------------------------------------------------
791
+ // Assembly
792
+ // ---------------------------------------------------------------------------
793
+ /** The `groups` grouping's page wrapper: its element, class, page name and stylesheet. */
794
+ export const GROUPS_FRAME = {
795
+ tag: "div",
796
+ className: "cc",
797
+ page: "compliance",
798
+ css: COMPLIANCE_CSS,
799
+ };
800
+ /**
801
+ * Draw the `groups` grouping into `wrapper` (contract-report.ts made it and
802
+ * put its stylesheet in it). Every word is `w`'s.
803
+ */
804
+ export async function drawGroups(levels, result, presentation, bundle, verified, w) {
805
+ const model = buildComplianceModel(result, presentation);
806
+ const claims = model.sessions.flatMap((s) => s.tests.flatMap((t) => (t.claim === undefined ? [] : [t.claim])));
807
+ // L0, what matters: the header with the mock-judge mark (D5 b), the
808
+ // sealed aggregate.
809
+ const mock = renderMockJudgeLine(await tallyJudges(result.records, claims), w);
810
+ // One L0 card: the header (with the mark) and the aggregate.
811
+ const sheet = el("div", "l0-card");
812
+ renderHeader(sheet, model, w);
813
+ const header = sheet.querySelector(".hd");
814
+ if (header !== null)
815
+ placeMockMark(header, mock);
816
+ else if (mock !== undefined)
817
+ sheet.prepend(mock);
818
+ sheet.append(renderAggregate(result, w));
819
+ levels.L0.append(sheet);
820
+ // L1, why: the tests, led by who judged, who witnessed, what verified.
821
+ renderSummary(levels.L1, model, presentation, w);
822
+ leadWithProvenance(levels.L1, levels.L1.querySelector('[data-section="summary"]'), renderProvenance(await provenanceLines(result.records, claims, bundle, verified, w)));
823
+ renderFindings(levels.L1, model, w);
824
+ // L2, module detail after the core's verification section.
825
+ levels.L2.append(renderCheckYourself(bundle, w));
826
+ renderReportProofs(levels.L2, model, bundle, verified, w);
827
+ }
828
+ //# sourceMappingURL=compliance-view.js.map