@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,1488 @@
1
+ import { buildOutcomeReportModel, NOT_STATED, verifyJudgePin, } from "@action-state-group/agent-action-capsule";
2
+ import { OUTCOME_REPORT_CSS } from "./outcome-report-styles.js";
3
+ import { judgedOf, lazyBody, levelToggle, proofList, conversationFold, ruleWord, wordPill, caseParts, judgeNote, assuranceRow, reportSummary, } from "./report-levels.js";
4
+ import { buildVerificationPageModel } from "@action-state-group/agent-action-capsule";
5
+ import { provenanceLines, renderProvenance, tallyJudges, } from "./report-provenance.js";
6
+ import { expandableRow, leadWithProvenance, placeMockMark, renderAggregate, renderCheckYourself, renderMockJudgeLine, } from "./report-front.js";
7
+ /**
8
+ * The contract-report module's `lines` grouping (contract-report.ts): a
9
+ * report read as result lines, results rule by rule, day by day and human
10
+ * spot checks, rendered from a verified `ResultRoot`. The Outcomes report is
11
+ * this grouping with the Outcomes wording pack. Drawn by the module in place
12
+ * of `renderResultPage` when the bundle's `outcome-report/v1` extension opts
13
+ * in (see `readOutcomeReportPresentation`) -- after the same verify-first
14
+ * gate every other root family goes through: nothing here ever runs on a
15
+ * bundle that did not verify.
16
+ *
17
+ * Every word on it is the wording pack's (`w`); nothing here chooses a word.
18
+ *
19
+ * The card renders into the host's three regions, one `.oi`-classed
20
+ * wrapper in each; the L0 wrapper holds its `<style>` (`OUTCOME_REPORT_CSS`)
21
+ * as its first child. Every selector in that stylesheet is scoped under
22
+ * `.oi`, so it can never affect, or be affected by, the rest of the page
23
+ * (the core's verification section, which opens L2 before the card's own
24
+ * L2 detail, or the generic Result page this bundle opted out of).
25
+ * No external reference of any kind: no `<link>`, no web font, no image.
26
+ */
27
+ function element(tag, text) {
28
+ const value = document.createElement(tag);
29
+ if (text !== undefined)
30
+ value.textContent = text;
31
+ return value;
32
+ }
33
+ function el(tag, className, text) {
34
+ const value = element(tag, text);
35
+ value.className = className;
36
+ return value;
37
+ }
38
+ // ---------------------------------------------------------------------------
39
+ // Icons: inline SVG line drawings, never emoji. An emoji glyph renders as an
40
+ // empty box ("tofu") wherever no colour-emoji font is installed -- headless
41
+ // Chromium on a server, most CI images -- and a report is read exactly there.
42
+ // Built with createElementNS from fixed path data (no markup string, no
43
+ // external reference); stroke follows the surrounding text colour.
44
+ // ---------------------------------------------------------------------------
45
+ // The SVG namespace is a URI that happens to begin with a scheme; it is never
46
+ // fetched. Assembled at run time so the emitted runtime contains no literal
47
+ // "http://" -- capsule-cli's report tests assert an offline report.html has
48
+ // none, as a cheap guard that the page loads nothing from the network.
49
+ const SVG_NS = ["http", "://www.w3.org/2000/svg"].join("");
50
+ const ICON_PATHS = {
51
+ // an open rulebook
52
+ book: [
53
+ "M4 5.5C4 4.7 4.7 4 5.5 4H11v15H5.5C4.7 19 4 18.3 4 17.5Z",
54
+ "M20 5.5C20 4.7 19.3 4 18.5 4H13v15h5.5c.8 0 1.5-.7 1.5-1.5Z",
55
+ "M6.5 8h2.5M6.5 11h2.5M15 8h2.5M15 11h2.5",
56
+ ],
57
+ // a ticked circle
58
+ check: ["M12 3a9 9 0 1 0 0 18a9 9 0 1 0 0-18Z", "M7.5 12.5l3 3l6-6.5"],
59
+ // a receipt with a torn foot
60
+ receipt: [
61
+ "M6 3h12v18l-2-1.5l-2 1.5l-2-1.5l-2 1.5l-2-1.5L6 21Z",
62
+ "M9 8h6M9 11.5h6M9 15h4",
63
+ ],
64
+ // a target
65
+ target: [
66
+ "M12 3a9 9 0 1 0 0 18a9 9 0 1 0 0-18Z",
67
+ "M12 7a5 5 0 1 0 0 10a5 5 0 1 0 0-10Z",
68
+ "M12 11a1 1 0 1 0 0 2a1 1 0 1 0 0-2Z",
69
+ ],
70
+ };
71
+ /** The named icon as an inline SVG, or `undefined` for a name with no drawing (the slot then stays empty, never a raw name or glyph). */
72
+ function icon(name) {
73
+ const paths = ICON_PATHS[name];
74
+ if (paths === undefined)
75
+ return undefined;
76
+ const svg = document.createElementNS(SVG_NS, "svg");
77
+ svg.setAttribute("viewBox", "0 0 24 24");
78
+ svg.setAttribute("width", "20");
79
+ svg.setAttribute("height", "20");
80
+ svg.setAttribute("fill", "none");
81
+ svg.setAttribute("stroke", "currentColor");
82
+ svg.setAttribute("stroke-width", "1.6");
83
+ svg.setAttribute("stroke-linecap", "round");
84
+ svg.setAttribute("stroke-linejoin", "round");
85
+ svg.setAttribute("aria-hidden", "true");
86
+ svg.dataset.icon = name;
87
+ for (const d of paths) {
88
+ const path = document.createElementNS(SVG_NS, "path");
89
+ path.setAttribute("d", d);
90
+ svg.append(path);
91
+ }
92
+ return svg;
93
+ }
94
+ const fmtCount = (n) => n.toLocaleString();
95
+ function fmtShare(count, total, percentages, w) {
96
+ if (percentages)
97
+ return total === 0
98
+ ? "–"
99
+ : w.t("lines.share.percent", {
100
+ p: String(Math.round((count / total) * 100)),
101
+ });
102
+ return w.t("lines.share", { count: fmtCount(count), total: fmtCount(total) });
103
+ }
104
+ const tierLabel = (tier, w) => w.t(`lines.tier.${tier}`);
105
+ /**
106
+ * A rule's name and wording. The name is the pack's `row.<check>.<rule>.label`
107
+ * when it sets one (contract-report/v1 section 3), else the contract's label.
108
+ */
109
+ function criterionLabel(model, checkId, criterionId, w) {
110
+ const check = model.terms.checks.find((c) => c.id === checkId);
111
+ const criterion = check?.criteria.find((c) => c.id === criterionId);
112
+ const wording = model.criterionWording.get(`${checkId}.${criterionId}`);
113
+ return {
114
+ label: w.row(`${checkId}.${criterionId}`, "label") ??
115
+ criterion?.label ??
116
+ `${checkId}.${criterionId}`,
117
+ text: wording?.text ?? criterion?.text ?? "",
118
+ question: check?.question ?? checkId,
119
+ source: wording?.source ?? "unstated",
120
+ };
121
+ }
122
+ /** The label a criterion's wording carries when it is NOT the sealed text. */
123
+ const wordingFallback = (source, w) => w.t(`lines.wording.${source}`);
124
+ /** One sentence on where the criterion wording on this page comes from. */
125
+ function wordingNote(model, w) {
126
+ const sources = new Set([...model.criterionWording.values()].map((c) => c.source));
127
+ if (sources.size === 1 && sources.has("sealed"))
128
+ return w.t("lines.wording-note.sealed");
129
+ if (!sources.has("sealed"))
130
+ return w.t("lines.wording-note.unstated");
131
+ return w.t("lines.wording-note.partly");
132
+ }
133
+ /** The producer's "edited" badge for a criterion, when its presentation
134
+ * extension marks one -- presentation text, titled as such, never evidence. */
135
+ function editedBadge(model, ref, w) {
136
+ const edited = model.options.editedCriteria?.find((e) => e.criterion === ref);
137
+ if (edited === undefined)
138
+ return undefined;
139
+ const badge = el("span", "edited", edited.badge);
140
+ badge.dataset.edited = ref;
141
+ badge.title = w.t("lines.edited.title");
142
+ return badge;
143
+ }
144
+ function renderProducerNote(host, model, w) {
145
+ const note = model.options.producerNote;
146
+ if (note === undefined)
147
+ return;
148
+ const box = el("aside", "pnote");
149
+ box.dataset.producerNote = "true";
150
+ box.append(el("div", "pn-k", w.t("lines.producer-note.kicker")));
151
+ box.append(el("h2", "pn-t", note.title));
152
+ const list = el("ul", "pn-l");
153
+ for (const line of note.lines)
154
+ list.append(element("li", line));
155
+ box.append(list);
156
+ box.append(el("p", "pn-src", w.t("lines.producer-note.source")));
157
+ host.append(box);
158
+ }
159
+ const fmtP = (p) => p.toFixed(2);
160
+ /** The probability the judge gave the verdict it returned, from the sealed rationale text; undefined when the text carries none. */
161
+ function verdictProbability(criterion) {
162
+ const probs = criterion.probabilities;
163
+ if (probs === undefined)
164
+ return undefined;
165
+ const key = criterion.claim?.verdict ?? criterion.verdict;
166
+ return probs[key];
167
+ }
168
+ /** The raw verdict names, kept for the proofs (what the sealed record says). */
169
+ const verdictText = (verdict, w) => w.t(`lines.pf.verdict.${verdict}`);
170
+ /** A rule result the judge returned as not met. A failed or unsupported claim is not one: its verdict was never drawn (see `isUnverified`). */
171
+ function isMiss(verdict) {
172
+ return verdict === "not_met";
173
+ }
174
+ /** A claim that failed verification, or whose cited evidence this bundle does not resolve: the records do not say whether the rule was met or not. */
175
+ function isUnverified(verdict) {
176
+ return verdict === "failed" || verdict === "unsupported";
177
+ }
178
+ /** A rule that did not apply: not applicable, or judged out of scope ("did not arise", Result v0 section 4.2). Never met; out of scope is still counted on its own. */
179
+ function notApplying(verdict) {
180
+ return verdict === "not_applicable" || verdict === "out_of_scope";
181
+ }
182
+ export function conversationStatus(conversation) {
183
+ if (conversation.verdict === "met")
184
+ return "resolved";
185
+ if (conversation.criteria.some((c) => isMiss(c.verdict)))
186
+ return "missed";
187
+ if (conversation.criteria.some((c) => isUnverified(c.verdict)))
188
+ return "unverified";
189
+ if (conversation.verdict === "not_met")
190
+ return "missed";
191
+ return conversation.criteria.length > 0 &&
192
+ conversation.criteria.every((c) => notApplying(c.verdict))
193
+ ? "nothing-applied"
194
+ : "undecided";
195
+ }
196
+ // Result words never come from the bundle (presentation contract section
197
+ // 6): they are the card's wording pack's.
198
+ export function statusWord(status, conversation, w) {
199
+ if (status === "resolved")
200
+ return { word: w.t("lines.status.resolved"), tone: "ok" };
201
+ if (status === "missed")
202
+ return { word: w.t("lines.status.missed"), tone: "bad" };
203
+ if (status === "unverified")
204
+ return { word: w.t("lines.status.unverified"), tone: "ne" };
205
+ if (status === "nothing-applied")
206
+ return { word: w.t("lines.status.nothing-applied"), tone: "na" };
207
+ // Three-valued: a judge ran on an undecided rule, none did, or the
208
+ // withheld reports cannot say which. Since e1a44e0 the default pack gives
209
+ // all of these the same plain word ("could not decide"); only the key
210
+ // tells them apart.
211
+ // A `no_claim` rule is undecided with no judge run on it (no claim, so no
212
+ // report): it counts as unjudged.
213
+ const judged = conversation.criteria
214
+ .filter((c) => c.verdict === "not_evaluable" || c.verdict === "no_claim")
215
+ .map((c) => c.verdict === "no_claim"
216
+ ? "no"
217
+ : judgedOf(c.reportState, c.judgePinDigest));
218
+ if (judged.includes("yes"))
219
+ return { word: w.t("lines.status.undecided.judged"), tone: "ne" };
220
+ if (judged.length > 0 && judged.every((j) => j === "no"))
221
+ return { word: w.t("lines.status.undecided.unjudged"), tone: "ne" };
222
+ // No rule result at all for this conversation (no not_evaluable criterion
223
+ // to point to a report state): the plain word set's own bare "could not
224
+ // decide", never a report-specific claim this conversation's records
225
+ // don't support.
226
+ if (judged.length === 0)
227
+ return { word: w.t("lines.status.undecided.none"), tone: "ne" };
228
+ // "withheld" only when every report that would say is withheld; a report
229
+ // in the bundle that cannot be read as sealed is never called withheld.
230
+ return judged.every((j) => j === "withheld" || j === "no")
231
+ ? { word: w.t("lines.status.undecided.withheld"), tone: "ne" }
232
+ : { word: w.t("lines.status.undecided.unavailable"), tone: "ne" };
233
+ }
234
+ function criterionWord(c, w) {
235
+ // agent-action-capsule 0.8.0's `no_claim` (a missing claim the Result's
236
+ // exclusions do not account for) is a gap that rolls up as not_evaluable,
237
+ // so it takes not_evaluable's words. It carries no claim and so no report:
238
+ // no judge ran on it, which is not_evaluable's unjudged word.
239
+ return c.verdict === "no_claim"
240
+ ? ruleWord("not_evaluable", "no", w)
241
+ : ruleWord(c.verdict, judgedOf(c.reportState, c.judgePinDigest), w);
242
+ }
243
+ /** The plain note for a rule whose report carries no rationale: why there is none. */
244
+ function noNoteText(c, w) {
245
+ switch (c.reportState) {
246
+ case "withheld":
247
+ case "mismatch":
248
+ case "unreadable":
249
+ case "invalid":
250
+ return w.t(`lines.no-note.${c.reportState}`);
251
+ default:
252
+ return w.t("lines.no-note.none");
253
+ }
254
+ }
255
+ function names(model, list, w) {
256
+ return list
257
+ .map((c) => criterionLabel(model, c.checkId, c.criterionId, w).label)
258
+ .join(", ");
259
+ }
260
+ /** A count in words up to twelve, in digits above. */
261
+ function countWord(n, w) {
262
+ return Number.isInteger(n) && n >= 0 && n <= 12
263
+ ? w.t(`lines.count.${n}`)
264
+ : String(n);
265
+ }
266
+ /** The rules whose claim failed verification or whose evidence is missing, as one sentence: their verdict was never drawn. */
267
+ function unverifiedClause(model, list, w, lower = false) {
268
+ const failed = list.filter((c) => c.verdict === "failed");
269
+ const unsupported = list.filter((c) => c.verdict === "unsupported");
270
+ const parts = [];
271
+ if (failed.length > 0)
272
+ parts.push(w.t("lines.sentence.unverified.failed", {
273
+ names: names(model, failed, w),
274
+ }));
275
+ if (unsupported.length > 0)
276
+ parts.push(w.t("lines.sentence.unverified.unsupported", {
277
+ names: names(model, unsupported, w),
278
+ }));
279
+ const text = `${parts.join(", and ")}, so the records do not say whether ${w.p("lines.word.that-rule-was", list.length)} met.`;
280
+ return lower ? text : text.charAt(0).toUpperCase() + text.slice(1);
281
+ }
282
+ /** One plain sentence: the conversation's result and the rules behind it. */
283
+ function resultSentence(conversation, model, w) {
284
+ const all = conversation.criteria;
285
+ const applied = all.filter((c) => !notApplying(c.verdict));
286
+ const outOfScope = all.filter((c) => c.verdict === "out_of_scope").length;
287
+ const na = all.length - applied.length - outOfScope;
288
+ const misses = all.filter((c) => isMiss(c.verdict));
289
+ const unverified = all.filter((c) => isUnverified(c.verdict));
290
+ // Undecided rules a judge could not decide, and gaps (`no_claim`): rules
291
+ // the Result holds no claim for, which no judge ran on.
292
+ const undecided = all.filter((c) => c.verdict === "not_evaluable");
293
+ const gaps = all.filter((c) => c.verdict === "no_claim");
294
+ const gapNote = gaps.length > 0
295
+ ? w.t("lines.sentence.undecided.gap-note", {
296
+ names: names(model, gaps, w),
297
+ })
298
+ : "";
299
+ const naText = `${na > 0 ? ` ${w.t("lines.sentence.na", { n: String(na) })}` : ""}${outOfScope > 0
300
+ ? ` ${w.t("lines.sentence.out-of-scope", { n: String(outOfScope) })}`
301
+ : ""}`;
302
+ const unverifiedText = unverified.length > 0 ? ` ${unverifiedClause(model, unverified, w)}` : "";
303
+ switch (conversationStatus(conversation)) {
304
+ case "resolved":
305
+ return `${w.p("lines.sentence.resolved", applied.length, { n: String(applied.length) })}${naText}`;
306
+ case "missed":
307
+ return `${w.t("lines.sentence.missed", {
308
+ misses: String(misses.length),
309
+ applied: String(applied.length),
310
+ rule: w.p("lines.word.rule", applied.length),
311
+ was: w.p("lines.word.was", misses.length),
312
+ names: names(model, misses, w),
313
+ })}${unverifiedText}${naText}`;
314
+ case "unverified":
315
+ return `${w.t("lines.sentence.unverified", {
316
+ clause: unverifiedClause(model, unverified, w, true),
317
+ undecidedNote: `${undecided.length > 0
318
+ ? w.t("lines.sentence.unverified.undecided-note", {
319
+ names: names(model, undecided, w),
320
+ })
321
+ : ""}${gapNote}`,
322
+ })}${naText}`;
323
+ case "undecided":
324
+ return undecided.length > 0
325
+ ? `${w.t("lines.sentence.undecided", {
326
+ names: names(model, undecided, w),
327
+ thatRuleWas: w.p("lines.word.that-rule-was", undecided.length),
328
+ })}${gapNote}${naText}`
329
+ : gaps.length > 0
330
+ ? `${w.t("lines.sentence.undecided.gaps", {
331
+ names: names(model, gaps, w),
332
+ })}${naText}`
333
+ : w.t("lines.sentence.undecided.none");
334
+ case "nothing-applied":
335
+ return w.t("lines.sentence.nothing-applied");
336
+ }
337
+ }
338
+ /**
339
+ * One conversation, in place inside a level-1 toggle: a header line (case,
340
+ * result, why, model) and its body right below it, never a toggle of its
341
+ * own. The body is built when it scrolls near the view (`lazyBody`).
342
+ */
343
+ function renderConversation(conversation, model, runInfo, w) {
344
+ const status = conversationStatus(conversation);
345
+ const item = el("article", "conv");
346
+ item.dataset.conversation = conversation.conversationId;
347
+ item.dataset.conversationVerdict = conversation.verdict;
348
+ item.dataset.status = status;
349
+ const head = el("div", "conv-h");
350
+ const parts = caseParts(conversation.conversationId, w);
351
+ head.append(el("span", "cid", parts.label));
352
+ head.append(wordPill(statusWord(status, conversation, w), status));
353
+ const misses = conversation.criteria.filter((c) => isMiss(c.verdict));
354
+ const unverified = conversation.criteria.filter((c) => isUnverified(c.verdict));
355
+ const undecided = conversation.criteria.filter((c) => c.verdict === "not_evaluable" || c.verdict === "no_claim");
356
+ const outOfScope = conversation.criteria.filter((c) => c.verdict === "out_of_scope");
357
+ head.append(el("span", "cwhy", status === "missed"
358
+ ? w.t("lines.why.missed", { names: names(model, misses, w) })
359
+ : status === "unverified"
360
+ ? w.t("lines.why.unverified", { names: names(model, unverified, w) })
361
+ : status === "undecided"
362
+ ? undecided.length === 0
363
+ ? w.t("lines.why.undecided.none")
364
+ : w.t("lines.why.undecided", {
365
+ names: names(model, undecided, w),
366
+ })
367
+ : status === "nothing-applied"
368
+ ? w.t("lines.why.nothing-applied")
369
+ : outOfScope.length === 0
370
+ ? w.t("lines.why.resolved")
371
+ : w.p("lines.why.resolved-out-of-scope", conversation.criteria.length - outOfScope.length, {
372
+ n: fmtCount(conversation.criteria.length - outOfScope.length),
373
+ oos: fmtCount(outOfScope.length),
374
+ })));
375
+ head.append(el("span", "cmodel", parts.model ?? ""));
376
+ item.append(head);
377
+ const body = el("div", "conv-slot");
378
+ item.append(body);
379
+ lazyBody(body, () => conversationBody(conversation, model, runInfo, w));
380
+ return item;
381
+ }
382
+ function conversationBody(conversation, model, runInfo, w) {
383
+ const body = el("div", "conv-b");
384
+ const sentence = el("p", "verdict-line", resultSentence(conversation, model, w));
385
+ sentence.dataset.why = conversationStatus(conversation);
386
+ body.append(sentence);
387
+ // Rule by rule, in plain words
388
+ body.append(el("h4", "", w.t("lines.h.rule-by-rule")));
389
+ // The judge's notes and the rule wording are shown per rule only when the
390
+ // bundle carries them; otherwise one line says so, not one per rule.
391
+ const hasNotes = conversation.criteria.some((c) => c.rationale !== undefined);
392
+ const wordings = conversation.criteria.map((c) => criterionLabel(model, c.checkId, c.criterionId, w).source);
393
+ const anyWording = wordings.some((source) => source === "sealed");
394
+ const table = el("table", "crit");
395
+ table.dataset.criteriaTable = conversation.conversationId;
396
+ const head = element("thead");
397
+ const headRow = element("tr");
398
+ headRow.append(element("th", w.t("lines.col.rule")), element("th", w.t("lines.col.result")));
399
+ if (hasNotes)
400
+ headRow.append(element("th", w.t("lines.col.note")));
401
+ head.append(headRow);
402
+ table.append(head);
403
+ const tbody = element("tbody");
404
+ for (const criterion of conversation.criteria) {
405
+ const ref = `${criterion.checkId}.${criterion.criterionId}`;
406
+ const tr = element("tr");
407
+ tr.dataset.crit = ref;
408
+ tr.dataset.critVerdict = criterion.verdict;
409
+ const label = criterionLabel(model, criterion.checkId, criterion.criterionId, w);
410
+ const nameCell = el("td", "cn");
411
+ nameCell.append(el("b", "", label.label));
412
+ const rowBadge = editedBadge(model, ref, w);
413
+ if (rowBadge !== undefined)
414
+ nameCell.append(rowBadge);
415
+ if (label.source === "sealed") {
416
+ const wording = el("small", "", label.text);
417
+ wording.dataset.wording = label.source;
418
+ nameCell.append(wording);
419
+ }
420
+ else if (anyWording) {
421
+ const wording = el("small", "wsrc", wordingFallback(label.source, w));
422
+ wording.dataset.wording = label.source;
423
+ nameCell.append(wording);
424
+ }
425
+ tr.append(nameCell);
426
+ const verdictCell = element("td");
427
+ verdictCell.append(wordPill(criterionWord(criterion, w), criterion.verdict));
428
+ tr.append(verdictCell);
429
+ if (!hasNotes) {
430
+ tbody.append(tr);
431
+ continue;
432
+ }
433
+ const noteCell = el("td", "rat");
434
+ if (criterion.verdict === "not_applicable")
435
+ noteCell.append(el("span", "muted", w.t("lines.note.not-applicable")));
436
+ else if (criterion.rationale !== undefined)
437
+ noteCell.append(el("span", "sealed", judgeNote(criterion.rationale, criterion.claim?.verdict ?? criterion.verdict, w)));
438
+ else
439
+ noteCell.append(el("span", "muted", noNoteText(criterion, w)));
440
+ tr.append(noteCell);
441
+ tbody.append(tr);
442
+ }
443
+ table.append(tbody);
444
+ const scroll = el("div", "tscroll");
445
+ scroll.append(table);
446
+ body.append(scroll);
447
+ const gaps = [];
448
+ if (!anyWording)
449
+ gaps.push(w.t(wordings.includes("mixed")
450
+ ? "lines.gap.wording.mixed"
451
+ : "lines.gap.wording.none"));
452
+ if (!hasNotes)
453
+ gaps.push(notesGap(conversation.criteria.flatMap((c) => c.claim === undefined ? [] : [c.reportState]), w));
454
+ if (gaps.length > 0) {
455
+ const gap = el("p", "small", gaps.join(" "));
456
+ gap.dataset.gaps = "true";
457
+ body.append(gap);
458
+ }
459
+ // The conversation itself
460
+ body.append(conversationFold(conversation.transcript, conversation.sourceCapsuleId, w));
461
+ // Toggle 2: the proofs
462
+ body.append(levelToggle(2, w.t("card.proofs.toggle"), () => conversationProofs(conversation, model, runInfo, w), { className: "proofs" }));
463
+ return body;
464
+ }
465
+ /** Why a conversation or session shows no judge's notes, from its reports' states. */
466
+ export function notesGap(states, w) {
467
+ const set = new Set(states);
468
+ return w.t(set.size === 1 && set.has("withheld")
469
+ ? "card.gap.notes.withheld"
470
+ : set.has("mismatch") || set.has("unreadable") || set.has("invalid")
471
+ ? "card.gap.notes.unread"
472
+ : set.has("withheld")
473
+ ? "card.gap.notes.some-withheld"
474
+ : "card.gap.notes.none");
475
+ }
476
+ /** The proofs rows for a case's transcript, shared by both groupings. */
477
+ export function transcriptRows(t, w) {
478
+ if (t.state === "verified")
479
+ return [
480
+ [w.t("card.pf.transcript-record"), t.transcriptRecordId],
481
+ [
482
+ w.t("card.pf.input-digest"),
483
+ w.t("card.pf.input-digest.verified", { digest: t.inputDigest }),
484
+ ],
485
+ ];
486
+ if (t.state === "cited")
487
+ return [
488
+ [w.t("card.pf.transcript-record"), t.transcriptRecordId],
489
+ [
490
+ w.t("card.pf.input-digest"),
491
+ w.t("card.pf.input-digest.cited", { digest: t.inputDigest }),
492
+ ],
493
+ ];
494
+ return [
495
+ [
496
+ w.t("card.pf.transcript"),
497
+ t.state === "absent"
498
+ ? w.t("card.pf.transcript.absent")
499
+ : w.t("card.pf.transcript.not-shown", {
500
+ reason: t.reason ?? w.t("card.pf.transcript.default-reason"),
501
+ }),
502
+ ],
503
+ ];
504
+ }
505
+ /** How a case is dated, in the proofs: the date as given, its zone, and the basis. */
506
+ export function datedText(dated, w) {
507
+ return w.t(dated.zone === "not-stated" ? "card.pf.dated.no-zone" : "card.pf.dated", { date: dated.stated ?? dated.date, basis: basisText(dated.basis, w) });
508
+ }
509
+ function conversationProofs(conversation, model, runInfo, w) {
510
+ const box = el("div", "pf-b");
511
+ box.dataset.proofsFor = conversation.conversationId;
512
+ const rows = [];
513
+ rows.push([w.t("lines.pf.case"), conversation.conversationId]);
514
+ rows.push([
515
+ w.t("card.pf.case-record"),
516
+ conversation.sourceCapsuleId === undefined
517
+ ? w.t("card.pf.case-record.not-stated")
518
+ : conversation.caseFrom === "claims"
519
+ ? w.t("lines.pf.case-record.from-claims", {
520
+ record: conversation.sourceCapsuleId,
521
+ })
522
+ : conversation.sourceCapsuleId,
523
+ ]);
524
+ const dated = conversation.dated;
525
+ if (dated.basis !== "judged") {
526
+ rows.push([
527
+ w.t("lines.pf.dated-by"),
528
+ datedText(dated, w),
529
+ { dated: dated.basis },
530
+ ]);
531
+ if (dated.importedAt !== undefined)
532
+ rows.push([w.t("card.pf.imported"), dated.importedAt]);
533
+ rows.push([w.t("card.pf.judged-sealed"), conversation.judgedDay]);
534
+ }
535
+ rows.push([w.t("card.pf.result-capsule"), model.capsuleId]);
536
+ rows.push(...transcriptRows(conversation.transcript, w));
537
+ rows.push([
538
+ w.t("lines.pf.judge-pin"),
539
+ runInfo.judgePinDigest === undefined
540
+ ? pinNotShown(runInfo, w)
541
+ : runInfo.judgePinRecomputes === true && runInfo.judgePin !== undefined
542
+ ? w.t("lines.pf.judge-pin.recomputed", {
543
+ digest: runInfo.judgePinDigest,
544
+ model: runInfo.judgePin.modelId,
545
+ prompt: runInfo.judgePin.promptDigest,
546
+ axes: runInfo.judgePin.axesDigest,
547
+ })
548
+ : runInfo.judgePinDigest,
549
+ ]);
550
+ const dl = proofList(rows);
551
+ dl.dataset.checkIt = conversation.conversationId;
552
+ box.append(dl);
553
+ box.append(el("h5", "", w.t("lines.pf.h.each-report")));
554
+ const table = el("table", "crit pft");
555
+ const head = element("thead");
556
+ const headRow = element("tr");
557
+ headRow.append(element("th", w.t("lines.pf.col.rule")), element("th", w.t("lines.pf.col.verdict")), el("th", "n", w.t("lines.pf.col.p")), element("th", w.t("lines.pf.col.report")), element("th", w.t("lines.pf.col.rationale")), element("th", w.t("card.pf.assurance")));
558
+ head.append(headRow);
559
+ table.append(head);
560
+ const tbody = element("tbody");
561
+ for (const criterion of conversation.criteria) {
562
+ const tr = element("tr");
563
+ tr.dataset.proofCrit = `${criterion.checkId}.${criterion.criterionId}`;
564
+ // The sealed verdict as data, whatever the pack's word for it.
565
+ tr.dataset.verdict = criterion.verdict;
566
+ tr.append(element("td", criterionLabel(model, criterion.checkId, criterion.criterionId, w)
567
+ .label), element("td", verdictText(criterion.verdict, w)));
568
+ const p = verdictProbability(criterion);
569
+ const pCell = el("td", "n", p === undefined ? "–" : fmtP(p));
570
+ if (p !== undefined)
571
+ pCell.dataset.p = fmtP(p);
572
+ tr.append(pCell);
573
+ tr.append(el("td", "mono", criterion.claim === undefined
574
+ ? w.t("lines.pf.no-claim")
575
+ : `${criterion.reportCapsuleId ?? w.t("lines.pf.not-cited")}${criterion.reportRecordId === undefined ? "" : ` (${criterion.reportRecordId})`}`));
576
+ const rationale = el("td", "rat");
577
+ if (criterion.rationale !== undefined) {
578
+ const sealed = el("code", "sealed", criterion.rationale);
579
+ sealed.dataset.rationale = "sealed";
580
+ rationale.append(sealed);
581
+ }
582
+ else
583
+ rationale.append(el("span", "muted", "–"));
584
+ tr.append(rationale);
585
+ // contract-report/v1 section 2: assurance stays on the claim.
586
+ if (criterion.claim === undefined)
587
+ tr.append(el("td", "muted", "–"));
588
+ else {
589
+ const [, text, data] = assuranceRow(criterion.claim, w);
590
+ const cell = element("td", text);
591
+ for (const [key, value] of Object.entries(data))
592
+ cell.dataset[key] = value;
593
+ tr.append(cell);
594
+ }
595
+ tbody.append(tr);
596
+ }
597
+ table.append(tbody);
598
+ const scroll = el("div", "tscroll");
599
+ scroll.append(table);
600
+ box.append(scroll);
601
+ // "Derived from its probabilities" holds only when every sealed rationale
602
+ // is the judge backend's own synthesized line; any other rationale is
603
+ // shown as sealed, and `judgeNote` passes it through unchanged.
604
+ const rationales = conversation.criteria
605
+ .map((c) => c.rationale)
606
+ .filter((r) => r !== undefined);
607
+ if (rationales.length > 0 &&
608
+ rationales.every((r) => /^jev choice:/u.test(r))) {
609
+ const derived = el("p", "", w.t("lines.pf.derived"));
610
+ derived.dataset.rationaleLabel = "derived";
611
+ box.append(derived);
612
+ }
613
+ else if (rationales.length > 0) {
614
+ const shown = el("p", "", w.t("lines.pf.sealed-rationale"));
615
+ shown.dataset.rationaleLabel = "sealed";
616
+ box.append(shown);
617
+ }
618
+ box.append(el("p", "", w.t("lines.pf.recompute", {
619
+ verdicts: w.p("lines.pf.verdicts", conversation.criteria.length, {
620
+ n: countWord(conversation.criteria.length, w),
621
+ }),
622
+ })));
623
+ return box;
624
+ }
625
+ /**
626
+ * The reasons a judge pin is not in the bundle, shared by both groupings:
627
+ * withheld reports are not the same as an unstated pin, and a mismatched
628
+ * report is neither. Empty when there is no such reason.
629
+ */
630
+ export function pinAbsence(info, w) {
631
+ const unread = (info.reportsMismatched ?? 0) +
632
+ (info.reportsUnreadable ?? 0) +
633
+ (info.reportsInvalid ?? 0);
634
+ const cited = fmtCount(info.reportsCited ?? 0);
635
+ const parts = [];
636
+ if (info.reportsWithheld !== undefined)
637
+ parts.push(w.t("card.pin.withheld", {
638
+ count: fmtCount(info.reportsWithheld),
639
+ total: cited,
640
+ }));
641
+ if (unread > 0)
642
+ parts.push(w.t("card.pin.unread", { count: fmtCount(unread), total: cited }));
643
+ return parts.length === 0
644
+ ? undefined
645
+ : w.t("card.pin.not-in-bundle", { reasons: parts.join("; ") });
646
+ }
647
+ /** What a page says when no judge pin is drawn. */
648
+ function pinNotShown(runInfo, w) {
649
+ if (!runInfo.pinned)
650
+ return w.t("lines.pin.differs");
651
+ return pinAbsence(runInfo, w) ?? w.t("lines.pin.not-stated");
652
+ }
653
+ function renderConversationList(conversations, model, runInfo, key, w) {
654
+ const list = el("div", "convs");
655
+ list.dataset.conversationsFor = key;
656
+ list.dataset.conversationCount = String(conversations.length);
657
+ if (conversations.length === 0)
658
+ list.append(el("p", "small", w.t("lines.list.empty")));
659
+ for (const conversation of conversations)
660
+ list.append(renderConversation(conversation, model, runInfo, w));
661
+ return list;
662
+ }
663
+ /** Toggle 1 on a summary line: the conversations behind it, listed in place, built on open. */
664
+ function drill(label, build, key) {
665
+ const details = levelToggle(1, label, build, { className: "line" });
666
+ details.dataset.drill = key;
667
+ return details;
668
+ }
669
+ function conversationsDrill(label, conversations, model, runInfo, key, w) {
670
+ return drill(label, () => renderConversationList(conversations, model, runInfo, key, w), key);
671
+ }
672
+ /** A criterion's label for a missed-reason group, from the terms; the id itself when the terms don't name it. */
673
+ function missedReasonLabel(terms, checkId, criterionId, w) {
674
+ const check = terms.checks.find((c) => c.id === checkId);
675
+ const criterion = check?.criteria.find((c) => c.id === criterionId);
676
+ return check === undefined || criterion === undefined
677
+ ? `${checkId}.${criterionId}`
678
+ : `${w?.row(`${checkId}.${criterionId}`, "label") ?? criterion.label} (${w === undefined ? check.question : groupTitle(check, w)})`;
679
+ }
680
+ /** A rule group's heading: the pack's `group.<check>.title` when it sets one (contract-report/v1 section 3), else the contract's question. */
681
+ function groupTitle(check, w) {
682
+ return w.group(check.id) ?? check.question;
683
+ }
684
+ /**
685
+ * Group missed conversations by THIS view's own reason: the first criterion
686
+ * where `isMiss` is true -- never AAC's `missedReasonGroups`, whose notion of
687
+ * "missed" still includes `failed`/`unsupported` (0.5.0's `missedReasonGroups`
688
+ * picks the first not_met/failed/unsupported criterion in criteria order, so
689
+ * a conversation with [c1 failed, c2 not_met] files under c1, though this
690
+ * view counts it missed only for c2's sake -- see `isMiss`, `isUnverified`).
691
+ * A reason is the producer's sealed reason code when the terms give it a
692
+ * label (`terms.reasonCodes`), else the first rule not met; a raw code is
693
+ * never shown.
694
+ */
695
+ export function groupMissedReasons(missed, terms, w) {
696
+ const labelledReasonCode = (code) => code === undefined ? undefined : terms.reasonCodes[code];
697
+ const groups = new Map();
698
+ const structured = new Map();
699
+ const labels = new Map();
700
+ for (const conversation of missed) {
701
+ const first = conversation.criteria.find((c) => isMiss(c.verdict));
702
+ if (first === undefined)
703
+ continue;
704
+ const label = labelledReasonCode(first.reasonCode);
705
+ const key = label !== undefined
706
+ ? first.reasonCode
707
+ : `${first.checkId}.${first.criterionId}`;
708
+ const list = groups.get(key) ?? [];
709
+ list.push(conversation);
710
+ groups.set(key, list);
711
+ structured.set(key, label !== undefined);
712
+ labels.set(key, label ?? missedReasonLabel(terms, first.checkId, first.criterionId, w));
713
+ }
714
+ return [...groups.entries()]
715
+ .map(([key, conversations]) => ({
716
+ key,
717
+ label: labels.get(key),
718
+ structured: structured.get(key),
719
+ conversations,
720
+ }))
721
+ .sort((a, b) => b.conversations.length - a.conversations.length);
722
+ }
723
+ /**
724
+ * The missed line's toggle: why conversations missed, then the missed
725
+ * conversations under each reason, in place. A reason is the producer's
726
+ * sealed reason code when the terms give it a label (`terms.reasonCodes`),
727
+ * else the first rule not met; a raw code is never shown. Content of the
728
+ * one level-1 toggle, never a level of its own.
729
+ */
730
+ function whyMissed(missed, model, runInfo, w) {
731
+ const box = el("div", "why-missed");
732
+ box.dataset.section = "why-missed";
733
+ const groups = groupMissedReasons(missed, model.terms, w);
734
+ box.dataset.reasons = String(groups.length);
735
+ box.append(el("h5", "", w.t("lines.why-missed.h")));
736
+ const table = element("table");
737
+ const tbody = element("tbody");
738
+ for (const group of groups) {
739
+ const tr = element("tr");
740
+ tr.dataset.reasonKey = group.key;
741
+ tr.dataset.reasonStructured = String(group.structured);
742
+ tr.dataset.count = String(group.conversations.length);
743
+ tr.append(element("td", group.label), el("td", "n", fmtCount(group.conversations.length)));
744
+ tbody.append(tr);
745
+ }
746
+ table.append(tbody);
747
+ box.append(table);
748
+ const anyStructured = groups.some((g) => g.structured);
749
+ box.append(el("p", "small", w.t(anyStructured
750
+ ? "lines.why-missed.structured"
751
+ : "lines.why-missed.unstructured")));
752
+ for (const group of groups) {
753
+ const head = el("div", "rsn-h", w.t("lines.why-missed.reason", {
754
+ reason: group.label,
755
+ count: fmtCount(group.conversations.length),
756
+ }));
757
+ head.dataset.reasonFor = group.key;
758
+ box.append(head);
759
+ box.append(renderConversationList(group.conversations, model, runInfo, `reason:${group.key}`, w));
760
+ }
761
+ return box;
762
+ }
763
+ // ---------------------------------------------------------------------------
764
+ // The sheet: header meta, report lines, stamp, tamper note
765
+ // ---------------------------------------------------------------------------
766
+ /** The pack and version as one line: both come from the claims' `contract_ref` (see `readOutcomeReportTerms`), or read "not stated". */
767
+ function packLine(model, w) {
768
+ const { id, version } = model.terms.pack;
769
+ return id === NOT_STATED
770
+ ? w.t("card.not-stated")
771
+ : w.t("lines.pack-line", { id, version });
772
+ }
773
+ // ---------------------------------------------------------------------------
774
+ // Dating: which date the calendar and period count a conversation under, and
775
+ // the plain label that says so (see `ConversationDate`)
776
+ // ---------------------------------------------------------------------------
777
+ export function span(days, w) {
778
+ const first = days[0];
779
+ const last = days[days.length - 1];
780
+ if (first === undefined || last === undefined)
781
+ return w.t("card.span.unknown");
782
+ return first === last ? first : w.t("card.span", { from: first, to: last });
783
+ }
784
+ /** What a case's date is, in words. */
785
+ export const basisText = (basis, w) => w.t(`card.basis.${basis}`);
786
+ /** The page's one plain statement of what its dates are, or undefined when every conversation is dated by the day it was judged (the card's behaviour before record dating). */
787
+ function datingNote(model, w) {
788
+ return datingStatement(model.dating, model.totalCount, w);
789
+ }
790
+ /** `datingNote` over any card's dating (both groupings share it), `total` being the conversations it counts. */
791
+ export function datingStatement(dating, total, w) {
792
+ const { basis, counts, judgedDays, zoneNotStated } = dating;
793
+ if (basis === "judged")
794
+ return undefined;
795
+ const sealed = w.t("card.dating.sealed", { span: span(judgedDays, w) });
796
+ const parts = [];
797
+ if (basis === "source")
798
+ parts.push(w.t("card.dating.source"));
799
+ else if (basis === "record")
800
+ parts.push(w.t("card.dating.record"));
801
+ else {
802
+ parts.push(w.t("card.dating.mixed"));
803
+ if (counts.source > 0)
804
+ parts.push(w.t("card.dating.mixed.source", { n: String(counts.source) }));
805
+ if (counts.record > 0)
806
+ parts.push(w.t("card.dating.mixed.record", { n: String(counts.record) }));
807
+ if (counts.judged > 0)
808
+ parts.push(w.t("card.dating.mixed.judged", { n: String(counts.judged) }));
809
+ }
810
+ parts.push(sealed);
811
+ if (counts.source > 0)
812
+ parts.push(w.t("card.dating.self-attested"));
813
+ if (zoneNotStated > 0)
814
+ parts.push(w.t("card.dating.tz", {
815
+ count: String(zoneNotStated),
816
+ total: String(total),
817
+ }));
818
+ return parts.join(" ");
819
+ }
820
+ function renderMeta(host, model, w, notes) {
821
+ const section = el("section", "");
822
+ section.dataset.section = "meta";
823
+ const row1 = el("div", "ih-row");
824
+ const bill = el("div", "party");
825
+ bill.append(el("div", "k", w.t("lines.meta.pack")));
826
+ bill.append(el("div", "v", packLine(model, w)));
827
+ row1.append(bill);
828
+ const title = el("div", "ih-title");
829
+ title.append(el("h1", "inv-title", w.t("lines.title")));
830
+ const summary = reportSummary(w);
831
+ if (summary !== undefined)
832
+ title.append(summary);
833
+ // No Evidence Contract field states when the terms were locked; the line
834
+ // is drawn only when one does, never as a standing "not stated".
835
+ if (model.terms.pack.locked !== NOT_STATED)
836
+ title.append(el("div", "inv-sub", w.t("lines.meta.locked", { locked: model.terms.pack.locked })));
837
+ row1.append(title);
838
+ section.append(row1);
839
+ const row2 = el("div", "ih-row");
840
+ const details = el("div", "meta");
841
+ const first = model.days[0]?.date;
842
+ const last = model.days[model.days.length - 1]?.date;
843
+ const metaRow = (label, value) => {
844
+ const line = element("div");
845
+ line.append(element("span", label), element("span", value));
846
+ details.append(line);
847
+ };
848
+ metaRow(w.t("lines.meta.period"), first === undefined || last === undefined
849
+ ? w.t("lines.meta.no-conversations")
850
+ : first === last
851
+ ? first
852
+ : w.t("card.span", { from: first, to: last }));
853
+ const note = datingNote(model, w);
854
+ if (note !== undefined) {
855
+ metaRow(w.t("lines.meta.sealed"), span(model.dating.judgedDays, w));
856
+ details.lastElementChild.setAttribute("data-sealed", "");
857
+ }
858
+ metaRow(w.t("lines.meta.conversations"), fmtCount(model.totalCount));
859
+ const checked = el("div", "party");
860
+ const rules = model.terms.checks.reduce((n, c) => n + c.criteria.length, 0);
861
+ checked.append(el("div", "k", w.t("lines.meta.what-checked")));
862
+ const groups = model.terms.checks.length;
863
+ const what = el("div", "d", w.t("lines.meta.what-checked.text", {
864
+ rules: w.p("lines.meta.rules", rules, { n: String(rules) }),
865
+ groups: w.p("lines.meta.groups", groups, { n: String(groups) }),
866
+ questions: model.terms.checks.map((c) => groupTitle(c, w)).join(" · "),
867
+ }));
868
+ what.dataset.whatChecked = String(rules);
869
+ checked.append(what);
870
+ row2.append(checked, details);
871
+ section.append(row2);
872
+ if (note !== undefined) {
873
+ const label = el("p", "date-note", note);
874
+ label.dataset.dateNote = model.dating.basis;
875
+ notes.append(label);
876
+ }
877
+ host.append(section);
878
+ }
879
+ // ---------------------------------------------------------------------------
880
+ // Summary: report lines
881
+ // ---------------------------------------------------------------------------
882
+ function renderLines(host, model, runInfo, w, notes) {
883
+ const section = el("section", "");
884
+ section.dataset.section = "lines";
885
+ const table = document.createElement("table");
886
+ table.className = "lines";
887
+ table.dataset.rows = "report-lines";
888
+ const thead = document.createElement("thead");
889
+ const headRow = document.createElement("tr");
890
+ headRow.append(element("th", w.t("lines.col.result")), el("th", "n", w.t("lines.lines.col.conversations")));
891
+ thead.append(headRow);
892
+ table.append(thead);
893
+ const tbody = document.createElement("tbody");
894
+ const byStatus = (status) => model.conversations.filter((c) => conversationStatus(c) === status);
895
+ const resolved = byStatus("resolved");
896
+ const missed = byStatus("missed");
897
+ const unverified = byStatus("unverified");
898
+ const undecided = [...byStatus("undecided"), ...byStatus("nothing-applied")];
899
+ const share = (n) => fmtShare(n, model.totalCount, model.options.percentages, w);
900
+ const line = (key, count, shown, behind) => ({
901
+ key,
902
+ label: w.t(`lines.line.${key}`),
903
+ help: w.t(`lines.line.${key}.help`),
904
+ count,
905
+ shown,
906
+ ...(behind === undefined ? {} : { behind }),
907
+ });
908
+ const lines = [
909
+ line("resolved", resolved.length, share(resolved.length), resolved),
910
+ line("missed", missed.length, share(missed.length), missed),
911
+ ];
912
+ if (unverified.length > 0)
913
+ lines.push(line("unverified", unverified.length, share(unverified.length), unverified));
914
+ if (undecided.length > 0)
915
+ lines.push(line("undecided", undecided.length, share(undecided.length), undecided));
916
+ // A person's re-grades are lines only when this bundle has one; their
917
+ // absence is said where the re-grade records are (renderHumanChecks).
918
+ if (model.heldCount > 0)
919
+ lines.push(line("held", model.heldCount, fmtCount(model.heldCount)));
920
+ if (model.addedCount > 0)
921
+ lines.push(line("added", model.addedCount, fmtCount(model.addedCount)));
922
+ for (const line of lines) {
923
+ const tr = document.createElement("tr");
924
+ tr.dataset.line = line.key;
925
+ tr.dataset.count = String(line.count);
926
+ const desc = el("td", "desc");
927
+ desc.append(el("b", "", line.label));
928
+ desc.append(el("small", "", line.help));
929
+ if (line.behind !== undefined && line.behind.length > 0) {
930
+ const label = w.p("lines.drill.show", line.behind.length, {
931
+ n: fmtCount(line.behind.length),
932
+ });
933
+ const behind = line.behind;
934
+ desc.append(line.key === "missed"
935
+ ? drill(label, () => whyMissed(behind, model, runInfo, w), line.key)
936
+ : conversationsDrill(label, behind, model, runInfo, line.key, w));
937
+ }
938
+ tr.append(desc, el("td", "n", line.shown));
939
+ tbody.append(tr);
940
+ }
941
+ table.append(tbody);
942
+ section.append(table);
943
+ const na = el("p", "na-note", w.p("lines.na-note", model.notApplicableCount, {
944
+ n: fmtCount(model.notApplicableCount),
945
+ }));
946
+ na.dataset.line = "not-applicable";
947
+ na.dataset.count = String(model.notApplicableCount);
948
+ notes.append(na);
949
+ // Result v0 section 4.2: out of scope is counted on its own, never as not
950
+ // applicable and never as met; said only when a bundle has one.
951
+ if (model.outOfScopeCount > 0) {
952
+ const oos = el("p", "na-note", w.p("lines.oos-note", model.outOfScopeCount, {
953
+ n: fmtCount(model.outOfScopeCount),
954
+ }));
955
+ oos.dataset.line = "out-of-scope";
956
+ oos.dataset.count = String(model.outOfScopeCount);
957
+ notes.append(oos);
958
+ }
959
+ host.append(section);
960
+ }
961
+ // ---------------------------------------------------------------------------
962
+ // Summary: results rule by rule
963
+ // ---------------------------------------------------------------------------
964
+ function renderRules(host, model, runInfo, w) {
965
+ const section = el("section", "sec");
966
+ section.dataset.section = "rules";
967
+ section.append(el("h2", "", w.t("lines.rules.h")));
968
+ section.append(el("p", "lede", w.t("lines.rules.lede")));
969
+ const table = el("table", "rules");
970
+ table.dataset.rows = "rules";
971
+ const thead = element("thead");
972
+ const headRow = element("tr");
973
+ // Not met leads; "did not apply" is in each row's expansion, and "could
974
+ // not decide" stays on the row as its own count (Result v0 section 3).
975
+ headRow.append(element("th", w.t("lines.col.rule")), el("th", "n", ruleWord("not_met", "yes", w).word), el("th", "n", ruleWord("met", "yes", w).word), el("th", "n", w.t("lines.rules.col.undecided")));
976
+ // A claim that failed verification or whose evidence is missing has its
977
+ // own column, never folded into "not met"; drawn only when a bundle has
978
+ // one.
979
+ const anyUnverified = model.conversations.some((c) => c.criteria.some((cr) => isUnverified(cr.verdict)));
980
+ if (anyUnverified)
981
+ headRow.append(el("th", "n", w.t("lines.rules.col.unverified")));
982
+ // Judged out of scope (Result v0 section 4.2) is its own column, never
983
+ // folded into "did not apply" or "met"; drawn only when a bundle has one.
984
+ const anyOutOfScope = model.outOfScopeCount > 0;
985
+ if (anyOutOfScope)
986
+ headRow.append(el("th", "n", ruleWord("out_of_scope", "yes", w).word));
987
+ const columns = String(4 + (anyUnverified ? 1 : 0) + (anyOutOfScope ? 1 : 0));
988
+ thead.append(headRow);
989
+ table.append(thead);
990
+ const tbody = element("tbody");
991
+ for (const check of model.terms.checks) {
992
+ const group = el("tr", "grp");
993
+ group.dataset.checkId = check.id;
994
+ group.dataset.passCount = String(model.checkPassCounts.get(check.id) ?? 0);
995
+ const cell = el("td", "", groupTitle(check, w));
996
+ cell.setAttribute("colspan", columns);
997
+ group.append(cell);
998
+ tbody.append(group);
999
+ for (const criterion of check.criteria) {
1000
+ const ref = `${check.id}.${criterion.id}`;
1001
+ const of = (pick) => model.conversations.filter((c) => c.criteria.some((cr) => cr.checkId === check.id &&
1002
+ cr.criterionId === criterion.id &&
1003
+ pick(cr.verdict)));
1004
+ const met = of((v) => v === "met");
1005
+ const notMet = of(isMiss);
1006
+ const unverifiedHere = of(isUnverified);
1007
+ const na = of((v) => v === "not_applicable");
1008
+ const outOfScopeHere = of((v) => v === "out_of_scope");
1009
+ const undecided = of((v) => v === "not_evaluable" || v === "no_claim");
1010
+ const tr = el("tr", "rule");
1011
+ tr.dataset.rule = ref;
1012
+ tr.dataset.tier = model.criterionTiers.get(ref) ?? "unknown";
1013
+ const label = criterionLabel(model, check.id, criterion.id, w);
1014
+ const nameCell = el("td", "cn");
1015
+ const ruleName = el("b", "", label.label);
1016
+ nameCell.append(ruleName);
1017
+ const badge = editedBadge(model, ref, w);
1018
+ if (badge !== undefined)
1019
+ nameCell.append(badge);
1020
+ if (label.source === "sealed")
1021
+ nameCell.append(el("small", "", label.text));
1022
+ // contract-report/v1 section 3: the pack's explanation of the rule,
1023
+ // and its note for a rule whose claims could not be decided.
1024
+ const detail = w.row(ref, "detail");
1025
+ if (detail !== undefined) {
1026
+ const line = el("small", "rdet", detail);
1027
+ line.dataset.wording = "pack";
1028
+ nameCell.append(line);
1029
+ }
1030
+ const undecidedNote = w.row(ref, "not_evaluable");
1031
+ if (undecidedNote !== undefined && undecided.length > 0) {
1032
+ const line = el("small", "rdet", undecidedNote);
1033
+ line.dataset.wording = "pack";
1034
+ line.dataset.note = "not-evaluable";
1035
+ nameCell.append(line);
1036
+ }
1037
+ const problems = [
1038
+ ...notMet,
1039
+ ...unverifiedHere.filter((c) => !notMet.includes(c)),
1040
+ ...undecided.filter((c) => !notMet.includes(c) && !unverifiedHere.includes(c)),
1041
+ ];
1042
+ tr.append(nameCell, el("td", `n${notMet.length > 0 ? " bad" : ""}`, fmtCount(notMet.length)), el("td", "n ok", fmtCount(met.length)), el("td", "n", fmtCount(undecided.length)));
1043
+ if (anyUnverified)
1044
+ tr.append(el("td", "n", fmtCount(unverifiedHere.length)));
1045
+ if (anyOutOfScope)
1046
+ tr.append(el("td", "n", fmtCount(outOfScopeHere.length)));
1047
+ tbody.append(tr);
1048
+ // The row opens: a full-width row below it holds how many
1049
+ // conversations the rule did not apply to and the conversations
1050
+ // behind its problems, each read at the table's width. A rule with
1051
+ // neither has nothing to open.
1052
+ if (problems.length === 0 && na.length === 0)
1053
+ continue;
1054
+ const drillRow = el("tr", "drill-row");
1055
+ drillRow.dataset.drillFor = ref;
1056
+ const cell = element("td");
1057
+ cell.setAttribute("colspan", columns);
1058
+ drillRow.append(cell);
1059
+ // The not-applicable count is drawn now, so a static page (which runs
1060
+ // no script to build a body) still shows it when the row opens.
1061
+ if (na.length > 0) {
1062
+ const naLine = el("p", "rule-na", w.p("lines.rules.expand.na", na.length, {
1063
+ n: fmtCount(na.length),
1064
+ }));
1065
+ naLine.dataset.count = String(na.length);
1066
+ cell.append(naLine);
1067
+ }
1068
+ const toggle = expandableRow(tr, ruleName, drillRow, () => problems.length > 0
1069
+ ? renderConversationList(problems, model, runInfo, `rule:${ref}`, w)
1070
+ : document.createDocumentFragment(), `rule-${ref}`);
1071
+ toggle.dataset.drill = `rule:${ref}`;
1072
+ tbody.append(drillRow);
1073
+ }
1074
+ }
1075
+ // Requirements of the cited contract the run did not cover (Result v0
1076
+ // section 3, `requirements_covered`): one row each, "not covered", under a group
1077
+ // of their own. They are in no conversation, count or column above: the
1078
+ // run never judged them, so no number on this page speaks for them.
1079
+ if (model.notRun.length > 0) {
1080
+ const group = el("tr", "grp");
1081
+ group.dataset.group = "not-run";
1082
+ const heading = el("td", "", w.t("lines.rules.not-run.h"));
1083
+ heading.setAttribute("colspan", columns);
1084
+ group.append(heading);
1085
+ tbody.append(group);
1086
+ for (const ref of model.notRun) {
1087
+ const [checkId = "", ...rest] = ref.split(".");
1088
+ const label = criterionLabel(model, checkId, rest.join("."), w);
1089
+ const tr = el("tr", "rule not-run");
1090
+ tr.dataset.rule = ref;
1091
+ tr.dataset.notRun = "true";
1092
+ const nameCell = el("td", "cn");
1093
+ nameCell.append(el("b", "", label.label));
1094
+ const status = el("td", "nr", w.t("lines.rules.not-run"));
1095
+ status.setAttribute("colspan", String(Number(columns) - 1));
1096
+ tr.append(nameCell, status);
1097
+ tbody.append(tr);
1098
+ }
1099
+ }
1100
+ table.append(tbody);
1101
+ const scroll = el("div", "tscroll");
1102
+ scroll.append(table);
1103
+ section.append(scroll);
1104
+ host.append(section);
1105
+ }
1106
+ // ---------------------------------------------------------------------------
1107
+ // Day by day
1108
+ // ---------------------------------------------------------------------------
1109
+ function renderCalendar(host, model, w) {
1110
+ const section = el("section", "sec");
1111
+ section.dataset.section = "calendar";
1112
+ section.append(el("h2", "", w.t("lines.cal.h")));
1113
+ const note = datingNote(model, w);
1114
+ section.append(el("p", "lede", w.t(note === undefined ? "lines.cal.lede" : "lines.cal.lede.dated")));
1115
+ // The dating note itself is said once, in the sheet's footnotes.
1116
+ const list = el("div", "cal");
1117
+ list.dataset.days = String(model.days.length);
1118
+ for (const day of model.days) {
1119
+ const item = el("div", "day");
1120
+ item.dataset.day = day.date;
1121
+ item.dataset.resolved = String(day.resolvedCount);
1122
+ item.dataset.total = String(day.conversations.length);
1123
+ item.append(el("div", "dn", day.date));
1124
+ if (note !== undefined) {
1125
+ const bases = new Set(day.conversations.map((c) => c.dated.basis));
1126
+ if (bases.has("source")) {
1127
+ const chip = el("div", "src-says", w.t("lines.cal.source-says"));
1128
+ chip.dataset.sourceSays = String(day.conversations.filter((c) => c.dated.basis === "source").length);
1129
+ item.append(chip);
1130
+ }
1131
+ const notStated = day.conversations.filter((c) => c.dated.zone === "not-stated").length;
1132
+ if (notStated > 0) {
1133
+ const tz = el("div", "tz", w.t("lines.cal.tz"));
1134
+ tz.dataset.tzMarker = "not-stated";
1135
+ item.append(tz);
1136
+ }
1137
+ }
1138
+ item.append(el("div", "v", fmtShare(day.resolvedCount, day.conversations.length, model.options.percentages, w)));
1139
+ const mini = el("div", "mini");
1140
+ const share = day.conversations.length === 0
1141
+ ? 0
1142
+ : day.resolvedCount / day.conversations.length;
1143
+ const fill = element("i");
1144
+ fill.style.width = `${Math.round(share * 100)}%`;
1145
+ mini.append(fill);
1146
+ item.append(mini);
1147
+ if (note !== undefined) {
1148
+ const sealed = el("div", "sealed", w.t("lines.cal.sealed", { span: span(day.judgedDays, w) }));
1149
+ sealed.dataset.sealed = day.judgedDays.join(" ");
1150
+ item.append(sealed);
1151
+ }
1152
+ if (day.policyChanged !== null) {
1153
+ const flag = el("div", "flag", w.t("lines.cal.policy-changed"));
1154
+ flag.dataset.policyChanged = day.policyChanged;
1155
+ item.append(flag);
1156
+ }
1157
+ list.append(item);
1158
+ }
1159
+ section.append(list);
1160
+ host.append(section);
1161
+ }
1162
+ // ---------------------------------------------------------------------------
1163
+ // Human spot checks
1164
+ // ---------------------------------------------------------------------------
1165
+ function renderHumanChecks(host, calibration, w) {
1166
+ const section = el("section", "sec");
1167
+ section.dataset.section = "human-checks";
1168
+ section.append(el("h2", "", w.t("lines.hc.h")));
1169
+ section.append(el("p", "lede", w.t("lines.hc.lede")));
1170
+ if (calibration.length === 0) {
1171
+ section.append(el("p", "", w.t("lines.hc.none")));
1172
+ host.append(section);
1173
+ return;
1174
+ }
1175
+ const table = document.createElement("table");
1176
+ table.className = "hct";
1177
+ table.dataset.weeks = String(calibration.length);
1178
+ const thead = document.createElement("thead");
1179
+ const headRow = document.createElement("tr");
1180
+ headRow.append(element("th", w.t("lines.hc.col.week")), el("th", "n", w.t("lines.hc.col.agreed")), el("th", "n", w.t("lines.hc.col.held")), el("th", "n", w.t("lines.hc.col.added")));
1181
+ thead.append(headRow);
1182
+ table.append(thead);
1183
+ const tbody = document.createElement("tbody");
1184
+ for (const week of calibration) {
1185
+ const tr = document.createElement("tr");
1186
+ tr.dataset.week = week.weekId;
1187
+ tr.dataset.k = String(week.k);
1188
+ tr.dataset.n = String(week.n);
1189
+ tr.append(el("td", "", week.weekId));
1190
+ tr.append(el("td", "n", w.t("lines.hc.agreed", { k: String(week.k), n: String(week.n) })));
1191
+ const held = week.sample.filter((s) => s.aiVerdict === "met" && s.humanVerdict !== "met").length;
1192
+ const added = week.sample.filter((s) => s.aiVerdict !== "met" && s.humanVerdict === "met").length;
1193
+ const heldCell = el("td", "n", String(held));
1194
+ heldCell.dataset.held = String(held);
1195
+ const addedCell = el("td", "n", String(added));
1196
+ addedCell.dataset.added = String(added);
1197
+ tr.append(heldCell, addedCell);
1198
+ tbody.append(tr);
1199
+ }
1200
+ table.append(tbody);
1201
+ section.append(table);
1202
+ host.append(section);
1203
+ }
1204
+ // ---------------------------------------------------------------------------
1205
+ // The terms
1206
+ // ---------------------------------------------------------------------------
1207
+ function renderTerms(host, model, w) {
1208
+ const section = el("div", "rp-s");
1209
+ section.dataset.section = "terms";
1210
+ section.append(el("h3", "", w.t("lines.terms.h")));
1211
+ const lede = el("p", "lede", model.terms.pack.agreement === NOT_STATED
1212
+ ? w.t("lines.terms.lede")
1213
+ : w.t("lines.terms.lede.agreed", {
1214
+ agreement: model.terms.pack.agreement,
1215
+ }));
1216
+ lede.dataset.termsSource = "bundle";
1217
+ section.append(lede);
1218
+ const pack = el("div", "pack");
1219
+ const packField = (label, value) => {
1220
+ const box = el("div", "pk");
1221
+ box.append(el("div", "k", label), el("div", "v", value));
1222
+ pack.append(box);
1223
+ };
1224
+ packField(w.t("lines.meta.pack"), model.terms.pack.id);
1225
+ packField(w.t("lines.terms.version"), model.terms.pack.version === NOT_STATED
1226
+ ? w.t("card.not-stated")
1227
+ : w.t("lines.terms.version.value", {
1228
+ version: model.terms.pack.version,
1229
+ }));
1230
+ if (model.terms.pack.locked !== NOT_STATED)
1231
+ packField(w.t("lines.terms.locked"), model.terms.pack.locked);
1232
+ section.append(pack);
1233
+ const outcome = el("div", "outcome");
1234
+ const outcomeIcon = el("div", "oic");
1235
+ const target = icon("target");
1236
+ if (target !== undefined)
1237
+ outcomeIcon.append(target);
1238
+ outcome.append(outcomeIcon);
1239
+ const outcomeBody = element("div");
1240
+ outcomeBody.append(el("div", "t", w.t("lines.terms.outcome")));
1241
+ outcomeBody.append(el("div", "v", model.terms.pack.outcomeStatement));
1242
+ outcome.append(outcomeBody);
1243
+ section.append(outcome);
1244
+ const checks = el("div", "checks");
1245
+ checks.dataset.checks = String(model.terms.checks.length);
1246
+ for (const check of model.terms.checks) {
1247
+ const card = el("section", "check");
1248
+ card.dataset.checkId = check.id;
1249
+ const checkIcon = el("div", "ic");
1250
+ const drawn = icon(check.icon);
1251
+ if (drawn !== undefined)
1252
+ checkIcon.append(drawn);
1253
+ card.append(checkIcon);
1254
+ card.append(el("div", "q", groupTitle(check, w)));
1255
+ card.append(el("div", "d", check.description));
1256
+ const criteria = el("ul", "subs");
1257
+ for (const criterion of check.criteria) {
1258
+ const ref = `${check.id}.${criterion.id}`;
1259
+ const tier = model.criterionTiers.get(ref) ?? "unknown";
1260
+ const item = element("li");
1261
+ item.dataset.criterionId = criterion.id;
1262
+ item.dataset.tier = tier;
1263
+ const wording = model.criterionWording.get(ref) ?? {
1264
+ text: criterion.text,
1265
+ source: "unstated",
1266
+ };
1267
+ item.dataset.wording = wording.source;
1268
+ const label = el("b", "", w.row(ref, "label") ?? criterion.label);
1269
+ const termsBadge = editedBadge(model, ref, w);
1270
+ if (termsBadge !== undefined)
1271
+ label.append(termsBadge);
1272
+ item.append(label);
1273
+ item.append(element("span", w.t("lines.terms.criterion", {
1274
+ text: wording.text,
1275
+ tier: tierLabel(tier, w),
1276
+ })));
1277
+ if (wording.source !== "sealed")
1278
+ item.append(el("small", "wsrc", wordingFallback(wording.source, w)));
1279
+ criteria.append(item);
1280
+ }
1281
+ card.append(criteria);
1282
+ checks.append(card);
1283
+ }
1284
+ section.append(checks);
1285
+ const note = el("p", "small", wordingNote(model, w));
1286
+ note.dataset.wordingNote = "true";
1287
+ section.append(note);
1288
+ section.append(el("div", "rule", model.terms.pack.resolutionRule));
1289
+ host.append(section);
1290
+ }
1291
+ // ---------------------------------------------------------------------------
1292
+ // What ran
1293
+ // ---------------------------------------------------------------------------
1294
+ function renderWhatRan(host, runInfo, w) {
1295
+ const section = el("div", "rp-s");
1296
+ section.dataset.section = "what-ran";
1297
+ section.append(el("h3", "", w.t("lines.ran.h")));
1298
+ const ran = el("div", "ran");
1299
+ ran.dataset.pinned = String(runInfo.pinned);
1300
+ if (runInfo.judgePinRecomputes !== undefined)
1301
+ ran.dataset.pinRecomputes = String(runInfo.judgePinRecomputes);
1302
+ const box = (label, value, key) => {
1303
+ const item = el("div", "it");
1304
+ item.dataset.ran = key;
1305
+ item.append(el("div", "k", label));
1306
+ item.append(el("div", "v", value));
1307
+ ran.append(item);
1308
+ };
1309
+ // The pin's components are drawn only when they recompute to the sealed
1310
+ // digest (verifyJudgePin); otherwise they are "not stated", never shown
1311
+ // beside a digest they do not produce.
1312
+ const pin = runInfo.judgePinRecomputes === true ? runInfo.judgePin : undefined;
1313
+ const notStated = w.t("card.not-stated");
1314
+ box(w.t("lines.ran.contract"), runInfo.contract ?? notStated, "contract");
1315
+ box(w.t("lines.ran.judge-model"), pin === undefined
1316
+ ? notStated
1317
+ : pin.modelVersion === undefined
1318
+ ? pin.modelId
1319
+ : `${pin.modelId} ${pin.modelVersion}`, "judge-model");
1320
+ box(w.t("lines.ran.judge-pin"), runInfo.judgePinDigest === undefined
1321
+ ? pinNotShown(runInfo, w)
1322
+ : pin === undefined
1323
+ ? runInfo.judgePinDigest
1324
+ : w.t("lines.ran.judge-pin.recomputed", {
1325
+ digest: runInfo.judgePinDigest,
1326
+ }), "judge-pin-digest");
1327
+ box(w.t("lines.ran.judge-prompt"), pin?.promptDigest ?? notStated, "judge-prompt-digest");
1328
+ box(w.t("lines.ran.judge-axes"), pin?.axesDigest ?? notStated, "judge-axes-digest");
1329
+ box(w.t("lines.ran.agent"), w.t("lines.ran.agent.value"), "agent");
1330
+ section.append(ran);
1331
+ if (runInfo.judgePinRecomputes === false) {
1332
+ const warning = el("p", "", w.t("lines.ran.components-mismatch"));
1333
+ warning.dataset.pinComponentsMismatch = "true";
1334
+ section.append(warning);
1335
+ }
1336
+ const lock = el("div", "lock", w.t("lines.ran.lock"));
1337
+ section.append(lock);
1338
+ if (!runInfo.pinned) {
1339
+ const warning = el("p", "", w.t("lines.ran.pin-mismatch"));
1340
+ warning.dataset.pinMismatch = "true";
1341
+ section.append(warning);
1342
+ }
1343
+ host.append(section);
1344
+ }
1345
+ // ---------------------------------------------------------------------------
1346
+ // Verification details
1347
+ // ---------------------------------------------------------------------------
1348
+ function renderVerificationDetails(host, bundle, verified, w) {
1349
+ const section = el("div", "rp-s");
1350
+ section.dataset.section = "verification-details";
1351
+ section.append(el("h3", "", w.t("card.vd.h")));
1352
+ section.append(el("p", "lede", w.t("lines.vd.lede")));
1353
+ const model = buildVerificationPageModel(bundle, verified);
1354
+ const tech = el("div", "tech");
1355
+ const field = (label, value) => {
1356
+ tech.append(el("div", "k", label), el("div", "v", value));
1357
+ };
1358
+ for (const [label, value] of verificationRows(model, w))
1359
+ field(label, value);
1360
+ section.append(tech);
1361
+ const note = el("p", "note", w.t("lines.vd.note"));
1362
+ note.dataset.checkpointKind = "mmr";
1363
+ section.append(note);
1364
+ host.append(section);
1365
+ }
1366
+ // ---------------------------------------------------------------------------
1367
+ // Proofs for the whole report: one toggle at the foot of the page
1368
+ // ---------------------------------------------------------------------------
1369
+ /** The bundle's digest and checkpoint, for the report proofs of either grouping. */
1370
+ export function verificationRows(model, w) {
1371
+ return [
1372
+ [
1373
+ w.t("card.vd.bundle-digest"),
1374
+ model.bundleDigest ?? w.t("card.vd.uncomputable"),
1375
+ ],
1376
+ [
1377
+ w.t("card.vd.checkpoint-root"),
1378
+ model.checkpointRoot ?? w.t("card.vd.absent"),
1379
+ ],
1380
+ [
1381
+ w.t("card.vd.checkpoint-size"),
1382
+ model.checkpointSize === undefined
1383
+ ? w.t("card.vd.absent")
1384
+ : String(model.checkpointSize),
1385
+ ],
1386
+ ];
1387
+ }
1388
+ /**
1389
+ * Which wording pack drew this card, in its report proofs: every layer
1390
+ * applied, by digest, not only the final one -- the base layer's digest is
1391
+ * named even on a default-only page (contract-report/v1 §3 records every
1392
+ * layer applied).
1393
+ */
1394
+ export function wordingRow(w) {
1395
+ const refused = w.source.refused;
1396
+ return [
1397
+ w.t("card.pf.wording"),
1398
+ refused !== undefined
1399
+ ? w.t("card.pf.wording.refused", {
1400
+ sha256: refused.sha256,
1401
+ reason: w.t(`card.wording.refused.${refused.reason}`),
1402
+ baseId: w.source.base?.id ?? w.source.id,
1403
+ baseSha256: w.source.base?.sha256 ?? w.source.sha256 ?? "",
1404
+ })
1405
+ : w.source.base === undefined
1406
+ ? w.t("card.pf.wording.default", {
1407
+ id: w.source.id,
1408
+ sha256: w.source.sha256 ?? "",
1409
+ })
1410
+ : w.t("card.pf.wording.supplied.layered", {
1411
+ id: w.source.id,
1412
+ sha256: w.source.sha256 ?? "",
1413
+ baseId: w.source.base.id,
1414
+ baseSha256: w.source.base.sha256,
1415
+ }),
1416
+ ];
1417
+ }
1418
+ function renderReportProofs(host, model, runInfo, bundle, verified, w) {
1419
+ const section = el("section", "sec rp");
1420
+ section.dataset.section = "report-proofs";
1421
+ // Built on first open, like every other toggle.
1422
+ const toggle = levelToggle(2, w.t("lines.rp.toggle"), () => {
1423
+ const box = el("div", "pf-b");
1424
+ const ids = proofList([
1425
+ [w.t("card.pf.result-capsule"), model.capsuleId],
1426
+ [w.t("lines.meta.pack"), packLine(model, w)],
1427
+ wordingRow(w),
1428
+ ]);
1429
+ ids.dataset.reportIds = "true";
1430
+ box.append(ids);
1431
+ renderTerms(box, model, w);
1432
+ renderWhatRan(box, runInfo, w);
1433
+ renderVerificationDetails(box, bundle, verified, w);
1434
+ const tamper = el("p", "tamper-note", w.t("lines.rp.tamper"));
1435
+ tamper.dataset.tamperNote = "verify-first";
1436
+ box.append(tamper);
1437
+ return box;
1438
+ }, { className: "proofs" });
1439
+ section.append(toggle);
1440
+ host.append(section);
1441
+ }
1442
+ /** The `lines` grouping's page wrapper: its element, class, page name and stylesheet. */
1443
+ export const LINES_FRAME = {
1444
+ tag: "section",
1445
+ className: "oi",
1446
+ page: "outcome-report",
1447
+ css: OUTCOME_REPORT_CSS,
1448
+ };
1449
+ /**
1450
+ * Draw the `lines` grouping into `wrapper` (contract-report.ts made it and
1451
+ * put its stylesheet in it). Every word is `w`'s.
1452
+ */
1453
+ export async function drawLines(levels, result, options, bundle, verified, w) {
1454
+ const model = buildOutcomeReportModel(result, options);
1455
+ const runInfo = await verifyJudgePin(model.runInfo);
1456
+ const claims = model.conversations.flatMap((c) => c.criteria.flatMap((cr) => (cr.claim === undefined ? [] : [cr.claim])));
1457
+ // L0, what matters: the header with the mock-judge mark (D5 b), the
1458
+ // sealed aggregate, then the per-conversation lines, each opening its list.
1459
+ const mock = renderMockJudgeLine(await tallyJudges(result.records, claims), w);
1460
+ const sheet = el("div", "sheet");
1461
+ const pad = el("div", "pad");
1462
+ // Notes that explain a figure sit under the sheet, in small type, never
1463
+ // between the reader and the figures.
1464
+ const notes = el("aside", "footnotes");
1465
+ notes.dataset.section = "footnotes";
1466
+ renderMeta(pad, model, w, notes);
1467
+ const title = pad.querySelector(".ih-title");
1468
+ if (title !== null)
1469
+ placeMockMark(title, mock);
1470
+ else if (mock !== undefined)
1471
+ pad.prepend(mock);
1472
+ pad.append(renderAggregate(result, w));
1473
+ renderLines(pad, model, runInfo, w, notes);
1474
+ if (notes.childElementCount > 0)
1475
+ pad.append(notes);
1476
+ sheet.append(pad);
1477
+ levels.L0.append(sheet);
1478
+ // L1, why: rule by rule, led by who judged, who witnessed, what verified.
1479
+ renderRules(levels.L1, model, runInfo, w);
1480
+ leadWithProvenance(levels.L1, levels.L1.querySelector('[data-section="rules"]'), renderProvenance(await provenanceLines(result.records, claims, bundle, verified, w)));
1481
+ // L2, module detail after the core's verification section.
1482
+ levels.L2.append(renderCheckYourself(bundle, w));
1483
+ renderCalendar(levels.L2, model, w);
1484
+ renderHumanChecks(levels.L2, model.calibration, w);
1485
+ renderProducerNote(levels.L2, model, w);
1486
+ renderReportProofs(levels.L2, model, runInfo, bundle, verified, w);
1487
+ }
1488
+ //# sourceMappingURL=outcome-report-view.js.map