@action-state-group/capsule-viewer 0.6.0 → 0.8.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 (75) hide show
  1. package/dist/chart-spec.d.ts +1 -1
  2. package/dist/chart-spec.js.map +1 -1
  3. package/dist/chart-view.d.ts +1 -1
  4. package/dist/chart-view.js +32 -0
  5. package/dist/chart-view.js.map +1 -1
  6. package/dist/compliance-styles.js +9 -0
  7. package/dist/compliance-styles.js.map +1 -1
  8. package/dist/compliance-view.d.ts +25 -1
  9. package/dist/compliance-view.js +240 -78
  10. package/dist/compliance-view.js.map +1 -1
  11. package/dist/contract-report-wording.d.ts +2 -1
  12. package/dist/contract-report-wording.js +110 -3
  13. package/dist/contract-report-wording.js.map +1 -1
  14. package/dist/contract-report.d.ts +16 -1
  15. package/dist/contract-report.js +31 -3
  16. package/dist/contract-report.js.map +1 -1
  17. package/dist/core-strip.d.ts +5 -2
  18. package/dist/core-strip.js +66 -5
  19. package/dist/core-strip.js.map +1 -1
  20. package/dist/emitter-shell.html +16 -0
  21. package/dist/emitter.js +2 -0
  22. package/dist/emitter.js.map +1 -1
  23. package/dist/evidence-contract.d.ts +61 -0
  24. package/dist/evidence-contract.js +83 -0
  25. package/dist/evidence-contract.js.map +1 -0
  26. package/dist/evidence-graph-view.d.ts +17 -0
  27. package/dist/evidence-graph-view.js +53 -6
  28. package/dist/evidence-graph-view.js.map +1 -1
  29. package/dist/evidence-graph.iife.js +3877 -946
  30. package/dist/index.d.ts +1 -0
  31. package/dist/index.js +1 -0
  32. package/dist/index.js.map +1 -1
  33. package/dist/outcome-report-styles.js +11 -0
  34. package/dist/outcome-report-styles.js.map +1 -1
  35. package/dist/outcome-report-view.d.ts +19 -4
  36. package/dist/outcome-report-view.js +338 -129
  37. package/dist/outcome-report-view.js.map +1 -1
  38. package/dist/presentation-builder.d.ts +14 -0
  39. package/dist/presentation-builder.js +45 -1
  40. package/dist/presentation-builder.js.map +1 -1
  41. package/dist/presentation-fragment.d.ts +3 -0
  42. package/dist/presentation-fragment.js +9 -0
  43. package/dist/presentation-fragment.js.map +1 -1
  44. package/dist/presentation-mount.d.ts +3 -0
  45. package/dist/presentation-mount.js +2 -0
  46. package/dist/presentation-mount.js.map +1 -1
  47. package/dist/record-page.d.ts +69 -0
  48. package/dist/record-page.js +542 -0
  49. package/dist/record-page.js.map +1 -0
  50. package/dist/report-front-styles.js +1 -0
  51. package/dist/report-front-styles.js.map +1 -1
  52. package/dist/report-front.js +5 -3
  53. package/dist/report-front.js.map +1 -1
  54. package/dist/report-legend.d.ts +32 -0
  55. package/dist/report-legend.js +110 -0
  56. package/dist/report-legend.js.map +1 -0
  57. package/dist/report-levels.d.ts +12 -1
  58. package/dist/report-levels.js +86 -14
  59. package/dist/report-levels.js.map +1 -1
  60. package/dist/report-view-render.d.ts +3 -1
  61. package/dist/report-view-render.js +417 -4
  62. package/dist/report-view-render.js.map +1 -1
  63. package/dist/report-view.d.ts +37 -2
  64. package/dist/report-view.js +176 -8
  65. package/dist/report-view.js.map +1 -1
  66. package/dist/spot-check.d.ts +57 -0
  67. package/dist/spot-check.js +123 -0
  68. package/dist/spot-check.js.map +1 -0
  69. package/dist/subject-history.d.ts +77 -0
  70. package/dist/subject-history.js +439 -0
  71. package/dist/subject-history.js.map +1 -0
  72. package/dist/viewer-build.js +1 -1
  73. package/dist/wording/contract-report-eu-ai-act.en.json +216 -6
  74. package/dist/wording/contract-report-outcomes.en.json +250 -6
  75. package/package.json +1 -1
@@ -1,9 +1,14 @@
1
+ import { disclosureOf, verifiedBundleContext, } from "@action-state-group/agent-action-capsule";
1
2
  import { buildOutcomeReportModel, NOT_STATED, verifyJudgePin, } from "@action-state-group/agent-action-capsule";
2
3
  import { OUTCOME_REPORT_CSS } from "./outcome-report-styles.js";
3
4
  import { judgedOf, lazyBody, levelToggle, proofList, conversationFold, evidenceAction, ruleWord, wordPill, caseParts, judgeNote, assuranceRow, reportSummary, } from "./report-levels.js";
4
5
  import { buildVerificationPageModel } from "@action-state-group/agent-action-capsule";
6
+ import { renderLegend, tagSource } from "./report-legend.js";
5
7
  import { provenanceLines, renderProvenance } from "./report-provenance.js";
6
8
  import { expandableRow, leadWithProvenance, renderCheckYourself, } from "./report-front.js";
9
+ import { spotCheckToggle } from "./spot-check.js";
10
+ import { readSubjectHistory, renderSubjectHistory, } from "./subject-history.js";
11
+ import { ROW_TIERS } from "./evidence-contract.js";
7
12
  /**
8
13
  * The contract-report module's `lines` grouping (contract-report.ts): a
9
14
  * report read as result lines, results rule by rule, day by day and human
@@ -149,7 +154,7 @@ function renderProducerNote(host, model, w) {
149
154
  box.dataset.producerNote = "true";
150
155
  box.append(el("div", "pn-k", w.t("lines.producer-note.kicker")));
151
156
  box.append(el("h2", "pn-t", note.title));
152
- const list = el("ul", "pn-l");
157
+ const list = tagSource(el("ul", "pn-l"), "producer");
153
158
  for (const line of note.lines)
154
159
  list.append(element("li", line));
155
160
  box.append(list);
@@ -179,7 +184,55 @@ function isUnverified(verdict) {
179
184
  function notApplying(verdict) {
180
185
  return verdict === "not_applicable" || verdict === "out_of_scope";
181
186
  }
182
- export function conversationStatus(conversation) {
187
+ /** A conversation as the derived lines read it (`Gating`). */
188
+ function counted(conversation, gating) {
189
+ return gating?.counted.get(conversation) ?? conversation;
190
+ }
191
+ /** A row's requirement tier chip (contract-report/v1 section 3, `requirement_tier.*`). */
192
+ function tierChip(tier, w) {
193
+ const chip = el("span", "rtier", w.t(`requirement_tier.${tier}`));
194
+ chip.dataset.requirementTier = tier;
195
+ return chip;
196
+ }
197
+ /** A rule's requirement tier, when the page has a contract. */
198
+ function criterionTier(c, gating) {
199
+ return gating?.tierOf(c.claim?.contractRef, `${c.checkId}.${c.criterionId}`);
200
+ }
201
+ /**
202
+ * The roll-up agent-action-capsule's outcome model applies to a
203
+ * conversation (outcome-report.js `rollUp`), over the rules left in.
204
+ */
205
+ function rollUp(verdicts) {
206
+ if (verdicts.length === 0)
207
+ return "not_evaluable";
208
+ if (verdicts.some((v) => v === "not_met" || isUnverified(v)))
209
+ return "not_met";
210
+ if (verdicts.some((v) => v === "not_evaluable" || v === "no_claim"))
211
+ return "not_evaluable";
212
+ if (!verdicts.some((v) => v === "met"))
213
+ return "not_evaluable";
214
+ return "met";
215
+ }
216
+ export function gating(conversations, tierOf) {
217
+ const map = new Map();
218
+ const out = { tierOf, counted: map };
219
+ for (const conversation of conversations) {
220
+ const kept = conversation.criteria.filter((c) => criterionTier(c, out) !== "informational");
221
+ if (kept.length === conversation.criteria.length)
222
+ continue;
223
+ map.set(conversation, {
224
+ ...conversation,
225
+ criteria: kept,
226
+ verdict: rollUp(kept.map((c) => c.verdict)),
227
+ });
228
+ }
229
+ return out;
230
+ }
231
+ export function conversationStatus(given, gating) {
232
+ const conversation = counted(given, gating);
233
+ // Every rule it has is informational: none of them is in its answer.
234
+ if (conversation !== given && conversation.criteria.length === 0)
235
+ return "nothing-applied";
183
236
  if (conversation.verdict === "met")
184
237
  return "resolved";
185
238
  if (conversation.criteria.some((c) => isMiss(c.verdict)))
@@ -195,7 +248,7 @@ export function conversationStatus(conversation) {
195
248
  }
196
249
  // Result words never come from the bundle (presentation contract section
197
250
  // 6): they are the card's wording pack's.
198
- export function statusWord(status, conversation, w) {
251
+ export function statusWord(status, conversation, w, gating) {
199
252
  if (status === "resolved")
200
253
  return { word: w.t("lines.status.resolved"), tone: "ok" };
201
254
  if (status === "missed")
@@ -210,8 +263,8 @@ export function statusWord(status, conversation, w) {
210
263
  // tells them apart.
211
264
  // A `no_claim` rule is undecided with no judge run on it (no claim, so no
212
265
  // report): it counts as unjudged.
213
- const judged = conversation.criteria
214
- .filter((c) => c.verdict === "not_evaluable" || c.verdict === "no_claim")
266
+ const judged = counted(conversation, gating)
267
+ .criteria.filter((c) => c.verdict === "not_evaluable" || c.verdict === "no_claim")
215
268
  .map((c) => c.verdict === "no_claim"
216
269
  ? "no"
217
270
  : judgedOf(c.reportState, c.judgePinDigest));
@@ -281,7 +334,7 @@ function unverifiedClause(model, list, w, lower = false) {
281
334
  }
282
335
  /** One plain sentence: the conversation's result and the rules behind it. */
283
336
  function resultSentence(conversation, model, w) {
284
- const all = conversation.criteria;
337
+ const all = counted(conversation, model.gating).criteria;
285
338
  const applied = all.filter((c) => !notApplying(c.verdict));
286
339
  const outOfScope = all.filter((c) => c.verdict === "out_of_scope").length;
287
340
  const na = all.length - applied.length - outOfScope;
@@ -300,7 +353,7 @@ function resultSentence(conversation, model, w) {
300
353
  ? ` ${w.t("lines.sentence.out-of-scope", { n: String(outOfScope) })}`
301
354
  : ""}`;
302
355
  const unverifiedText = unverified.length > 0 ? ` ${unverifiedClause(model, unverified, w)}` : "";
303
- switch (conversationStatus(conversation)) {
356
+ switch (conversationStatus(conversation, model.gating)) {
304
357
  case "resolved":
305
358
  return `${w.p("lines.sentence.resolved", applied.length, { n: String(applied.length) })}${naText}`;
306
359
  case "missed":
@@ -341,19 +394,21 @@ function resultSentence(conversation, model, w) {
341
394
  * own. The body is built when it scrolls near the view (`lazyBody`).
342
395
  */
343
396
  function renderConversation(conversation, model, runInfo, w) {
344
- const status = conversationStatus(conversation);
397
+ const status = conversationStatus(conversation, model.gating);
345
398
  const item = el("article", "conv");
346
399
  item.dataset.conversation = conversation.conversationId;
347
- item.dataset.conversationVerdict = conversation.verdict;
400
+ // The header's line is a derived one: it reads the rules in the answer.
401
+ const inAnswer = counted(conversation, model.gating);
402
+ item.dataset.conversationVerdict = inAnswer.verdict;
348
403
  item.dataset.status = status;
349
404
  const head = el("div", "conv-h");
350
405
  const parts = caseParts(conversation.conversationId, w);
351
406
  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");
407
+ head.append(wordPill(statusWord(status, conversation, w, model.gating), status));
408
+ const misses = inAnswer.criteria.filter((c) => isMiss(c.verdict));
409
+ const unverified = inAnswer.criteria.filter((c) => isUnverified(c.verdict));
410
+ const undecided = inAnswer.criteria.filter((c) => c.verdict === "not_evaluable" || c.verdict === "no_claim");
411
+ const outOfScope = inAnswer.criteria.filter((c) => c.verdict === "out_of_scope");
357
412
  head.append(el("span", "cwhy", status === "missed"
358
413
  ? w.t("lines.why.missed", { names: names(model, misses, w) })
359
414
  : status === "unverified"
@@ -368,8 +423,8 @@ function renderConversation(conversation, model, runInfo, w) {
368
423
  ? w.t("lines.why.nothing-applied")
369
424
  : outOfScope.length === 0
370
425
  ? 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),
426
+ : w.p("lines.why.resolved-out-of-scope", inAnswer.criteria.length - outOfScope.length, {
427
+ n: fmtCount(inAnswer.criteria.length - outOfScope.length),
373
428
  oos: fmtCount(outOfScope.length),
374
429
  })));
375
430
  head.append(el("span", "cmodel", parts.model ?? ""));
@@ -382,7 +437,7 @@ function renderConversation(conversation, model, runInfo, w) {
382
437
  function conversationBody(conversation, model, runInfo, w) {
383
438
  const body = el("div", "conv-b");
384
439
  const sentence = el("p", "verdict-line", resultSentence(conversation, model, w));
385
- sentence.dataset.why = conversationStatus(conversation);
440
+ sentence.dataset.why = conversationStatus(conversation, model.gating);
386
441
  body.append(sentence);
387
442
  // Rule by rule, in plain words
388
443
  body.append(el("h4", "", w.t("lines.h.rule-by-rule")));
@@ -412,8 +467,15 @@ function conversationBody(conversation, model, runInfo, w) {
412
467
  const rowBadge = editedBadge(model, ref, w);
413
468
  if (rowBadge !== undefined)
414
469
  nameCell.append(rowBadge);
470
+ // The rule's tier, so a conversation resolved over an informational
471
+ // rule not met says why that rule did not count.
472
+ const tier = criterionTier(criterion, model.gating);
473
+ if (tier !== undefined) {
474
+ tr.dataset.requirementTier = tier;
475
+ nameCell.append(tierChip(tier, w));
476
+ }
415
477
  if (label.source === "sealed") {
416
- const wording = el("small", "", label.text);
478
+ const wording = tagSource(el("small", "", label.text), "producer");
417
479
  wording.dataset.wording = label.source;
418
480
  nameCell.append(wording);
419
481
  }
@@ -456,6 +518,32 @@ function conversationBody(conversation, model, runInfo, w) {
456
518
  gap.dataset.gaps = "true";
457
519
  body.append(gap);
458
520
  }
521
+ // The conversation beside each rule's wording and verdict (spot-check.ts)
522
+ const spot = spotCheckToggle({
523
+ transcript: conversation.transcript,
524
+ caseRecord: conversation.sourceCapsuleId,
525
+ rules: conversation.criteria.flatMap((criterion) => {
526
+ if (criterion.claim === undefined)
527
+ return [];
528
+ const label = criterionLabel(model, criterion.checkId, criterion.criterionId, w);
529
+ return [
530
+ {
531
+ name: label.label,
532
+ ref: `${criterion.checkId}.${criterion.criterionId}`,
533
+ worded: criterionWord(criterion, w),
534
+ verdict: criterion.verdict,
535
+ drawnVerdict: criterion.claim.verdict,
536
+ wording: { text: label.text, source: label.source },
537
+ rationale: criterion.rationale,
538
+ noNote: noNoteText(criterion, w),
539
+ judgePinDigest: criterion.judgePinDigest,
540
+ reportState: criterion.reportState,
541
+ },
542
+ ];
543
+ }),
544
+ }, w);
545
+ if (spot !== undefined)
546
+ body.append(spot);
459
547
  // The conversation itself
460
548
  body.append(conversationFold(conversation.transcript, conversation.sourceCapsuleId, w));
461
549
  // Toggle 2: the proofs
@@ -692,13 +780,13 @@ function groupTitle(check, w) {
692
780
  * label (`terms.reasonCodes`), else the first rule not met; a raw code is
693
781
  * never shown.
694
782
  */
695
- export function groupMissedReasons(missed, terms, w) {
783
+ export function groupMissedReasons(missed, terms, w, gating) {
696
784
  const labelledReasonCode = (code) => code === undefined ? undefined : terms.reasonCodes[code];
697
785
  const groups = new Map();
698
786
  const structured = new Map();
699
787
  const labels = new Map();
700
788
  for (const conversation of missed) {
701
- const first = conversation.criteria.find((c) => isMiss(c.verdict));
789
+ const first = counted(conversation, gating).criteria.find((c) => isMiss(c.verdict));
702
790
  if (first === undefined)
703
791
  continue;
704
792
  const label = labelledReasonCode(first.reasonCode);
@@ -730,7 +818,7 @@ export function groupMissedReasons(missed, terms, w) {
730
818
  function whyMissed(missed, model, runInfo, w) {
731
819
  const box = el("div", "why-missed");
732
820
  box.dataset.section = "why-missed";
733
- const groups = groupMissedReasons(missed, model.terms, w);
821
+ const groups = groupMissedReasons(missed, model.terms, w, model.gating);
734
822
  box.dataset.reasons = String(groups.length);
735
823
  box.append(el("h5", "", w.t("lines.why-missed.h")));
736
824
  const table = element("table");
@@ -894,7 +982,7 @@ function renderLines(host, model, runInfo, w, notes) {
894
982
  thead.append(headRow);
895
983
  table.append(thead);
896
984
  const tbody = document.createElement("tbody");
897
- const byStatus = (status) => model.conversations.filter((c) => conversationStatus(c) === status);
985
+ const byStatus = (status) => model.conversations.filter((c) => conversationStatus(c, model.gating) === status);
898
986
  const resolved = byStatus("resolved");
899
987
  const missed = byStatus("missed");
900
988
  const unverified = byStatus("unverified");
@@ -991,6 +1079,7 @@ function renderLines(host, model, runInfo, w, notes) {
991
1079
  // Summary: results rule by rule
992
1080
  // ---------------------------------------------------------------------------
993
1081
  function renderRules(host, model, runInfo, result, w) {
1082
+ const tierOf = model.gating?.tierOf;
994
1083
  const section = el("section", "sec");
995
1084
  section.dataset.section = "rules";
996
1085
  section.append(el("h2", "", w.t("lines.rules.h")));
@@ -1024,111 +1113,151 @@ function renderRules(host, model, runInfo, result, w) {
1024
1113
  thead.append(headRow);
1025
1114
  table.append(thead);
1026
1115
  const tbody = element("tbody");
1027
- for (const check of model.terms.checks) {
1028
- const group = el("tr", "grp");
1029
- group.dataset.checkId = check.id;
1030
- group.dataset.passCount = String(model.checkPassCounts.get(check.id) ?? 0);
1031
- const cell = el("td", "", groupTitle(check, w));
1032
- cell.setAttribute("colspan", columns);
1033
- group.append(cell);
1034
- tbody.append(group);
1116
+ // With a contract, each rule's requirement tier (contract-report/v1
1117
+ // section 2), read by the contract_ref of the rule's claims: rules are
1118
+ // drawn in tier sections, must-have first, then informational, then
1119
+ // those whose tier is not stated. Without one, one section, as before.
1120
+ const ruleTier = (ref) => {
1121
+ if (tierOf === undefined)
1122
+ return undefined;
1123
+ const claim = model.conversations
1124
+ .flatMap((c) => c.criteria)
1125
+ .find((c) => `${c.checkId}.${c.criterionId}` === ref && c.claim)?.claim;
1126
+ return tierOf(claim?.contractRef, ref);
1127
+ };
1128
+ const tiers = new Map();
1129
+ for (const check of model.terms.checks)
1035
1130
  for (const criterion of check.criteria) {
1036
1131
  const ref = `${check.id}.${criterion.id}`;
1037
- const of = (pick) => model.conversations.filter((c) => c.criteria.some((cr) => cr.checkId === check.id &&
1038
- cr.criterionId === criterion.id &&
1039
- pick(cr.verdict)));
1040
- // Each count column's verdicts, read once: a cell's number and the
1041
- // claims its Show-evidence action lists come from the same pick.
1042
- const picks = {
1043
- not_met: isMiss,
1044
- met: (v) => v === "met",
1045
- undecided: (v) => v === "not_evaluable" || v === "no_claim",
1046
- unverified: isUnverified,
1047
- out_of_scope: (v) => v === "out_of_scope",
1048
- };
1049
- const met = of(picks.met);
1050
- const notMet = of(picks.not_met);
1051
- const unverifiedHere = of(picks.unverified);
1052
- const na = of((v) => v === "not_applicable");
1053
- const outOfScopeHere = of(picks.out_of_scope);
1054
- const undecided = of(picks.undecided);
1055
- // One count cell: the number, and its Show-evidence action (or the
1056
- // label that stands in for one) over the claims behind it on this rule.
1057
- const countCell = (className, column, counted) => {
1058
- const pick = picks[column];
1059
- const cell = el("td", className);
1060
- cell.dataset.column = column;
1061
- cell.append(el("span", "nv", fmtCount(counted.length)));
1062
- const action = evidenceAction(`rule:${ref}:${column}`, `${label.label} · ${columnWord[column]}: ${fmtCount(counted.length)}`, counted.map((c) => c.criteria.find((cr) => cr.checkId === check.id &&
1063
- cr.criterionId === criterion.id &&
1064
- pick(cr.verdict))?.claim), result, w);
1065
- if (action !== undefined)
1066
- cell.append(action);
1067
- return cell;
1068
- };
1069
- const tr = el("tr", "rule");
1070
- tr.dataset.rule = ref;
1071
- tr.dataset.tier = model.criterionTiers.get(ref) ?? "unknown";
1072
- const label = criterionLabel(model, check.id, criterion.id, w);
1073
- const nameCell = el("td", "cn");
1074
- const ruleName = el("b", "", label.label);
1075
- nameCell.append(ruleName);
1076
- const badge = editedBadge(model, ref, w);
1077
- if (badge !== undefined)
1078
- nameCell.append(badge);
1079
- if (label.source === "sealed")
1080
- nameCell.append(el("small", "", label.text));
1081
- // contract-report/v1 section 3: the pack's explanation of the rule,
1082
- // and its note for a rule whose claims could not be decided.
1083
- const detail = w.row(ref, "detail");
1084
- if (detail !== undefined) {
1085
- const line = el("small", "rdet", detail);
1086
- line.dataset.wording = "pack";
1087
- nameCell.append(line);
1088
- }
1089
- const undecidedNote = w.row(ref, "not_evaluable");
1090
- if (undecidedNote !== undefined && undecided.length > 0) {
1091
- const line = el("small", "rdet", undecidedNote);
1092
- line.dataset.wording = "pack";
1093
- line.dataset.note = "not-evaluable";
1094
- nameCell.append(line);
1095
- }
1096
- const problems = [
1097
- ...notMet,
1098
- ...unverifiedHere.filter((c) => !notMet.includes(c)),
1099
- ...undecided.filter((c) => !notMet.includes(c) && !unverifiedHere.includes(c)),
1100
- ];
1101
- tr.append(nameCell, countCell(`n${notMet.length > 0 ? " bad" : ""}`, "not_met", notMet), countCell("n ok", "met", met), countCell("n", "undecided", undecided));
1102
- if (anyUnverified)
1103
- tr.append(countCell("n", "unverified", unverifiedHere));
1104
- if (anyOutOfScope)
1105
- tr.append(countCell("n", "out_of_scope", outOfScopeHere));
1106
- tbody.append(tr);
1107
- // The row opens: a full-width row below it holds how many
1108
- // conversations the rule did not apply to and the conversations
1109
- // behind its problems, each read at the table's width. A rule with
1110
- // neither has nothing to open.
1111
- if (problems.length === 0 && na.length === 0)
1132
+ tiers.set(ref, ruleTier(ref));
1133
+ }
1134
+ const sections = tierOf === undefined
1135
+ ? [undefined]
1136
+ : ROW_TIERS.filter((tier) => [...tiers.values()].includes(tier));
1137
+ for (const tier of sections) {
1138
+ if (tier !== undefined) {
1139
+ const inTier = [...tiers.values()].filter((t) => t === tier).length;
1140
+ const heading = el("tr", "tier");
1141
+ heading.dataset.requirementTier = tier;
1142
+ const cell = el("td", "");
1143
+ cell.setAttribute("colspan", columns);
1144
+ cell.append(el("b", "", w.t(`lines.rtier.${tier}.title`, { n: fmtCount(inTier) })), el("small", "", w.t(`lines.rtier.${tier}.note`)));
1145
+ heading.append(cell);
1146
+ tbody.append(heading);
1147
+ }
1148
+ for (const check of model.terms.checks) {
1149
+ const criteria = check.criteria.filter((criterion) => tiers.get(`${check.id}.${criterion.id}`) === tier);
1150
+ if (criteria.length === 0)
1112
1151
  continue;
1113
- const drillRow = el("tr", "drill-row");
1114
- drillRow.dataset.drillFor = ref;
1115
- const cell = element("td");
1152
+ const group = el("tr", "grp");
1153
+ group.dataset.checkId = check.id;
1154
+ group.dataset.passCount = String(model.checkPassCounts.get(check.id) ?? 0);
1155
+ const cell = el("td", "", groupTitle(check, w));
1116
1156
  cell.setAttribute("colspan", columns);
1117
- drillRow.append(cell);
1118
- // The not-applicable count is drawn now, so a static page (which runs
1119
- // no script to build a body) still shows it when the row opens.
1120
- if (na.length > 0) {
1121
- const naLine = el("p", "rule-na", w.p("lines.rules.expand.na", na.length, {
1122
- n: fmtCount(na.length),
1123
- }));
1124
- naLine.dataset.count = String(na.length);
1125
- cell.append(naLine);
1157
+ group.append(cell);
1158
+ tbody.append(group);
1159
+ for (const criterion of criteria) {
1160
+ const ref = `${check.id}.${criterion.id}`;
1161
+ const of = (pick) => model.conversations.filter((c) => c.criteria.some((cr) => cr.checkId === check.id &&
1162
+ cr.criterionId === criterion.id &&
1163
+ pick(cr.verdict)));
1164
+ // Each count column's verdicts, read once: a cell's number and the
1165
+ // claims its Show-evidence action lists come from the same pick.
1166
+ const picks = {
1167
+ not_met: isMiss,
1168
+ met: (v) => v === "met",
1169
+ undecided: (v) => v === "not_evaluable" || v === "no_claim",
1170
+ unverified: isUnverified,
1171
+ out_of_scope: (v) => v === "out_of_scope",
1172
+ };
1173
+ const met = of(picks.met);
1174
+ const notMet = of(picks.not_met);
1175
+ const unverifiedHere = of(picks.unverified);
1176
+ const na = of((v) => v === "not_applicable");
1177
+ const outOfScopeHere = of(picks.out_of_scope);
1178
+ const undecided = of(picks.undecided);
1179
+ // One count cell: the number, and its Show-evidence action (or the
1180
+ // label that stands in for one) over the claims behind it on this rule.
1181
+ const countCell = (className, column, counted) => {
1182
+ const pick = picks[column];
1183
+ const cell = el("td", className);
1184
+ cell.dataset.column = column;
1185
+ cell.append(el("span", "nv", fmtCount(counted.length)));
1186
+ const action = evidenceAction(`rule:${ref}:${column}`, `${label.label} · ${columnWord[column]}: ${fmtCount(counted.length)}`, counted.map((c) => c.criteria.find((cr) => cr.checkId === check.id &&
1187
+ cr.criterionId === criterion.id &&
1188
+ pick(cr.verdict))?.claim), result, w);
1189
+ if (action !== undefined)
1190
+ cell.append(action);
1191
+ return cell;
1192
+ };
1193
+ const tr = el("tr", "rule");
1194
+ tr.dataset.rule = ref;
1195
+ tr.dataset.tier = model.criterionTiers.get(ref) ?? "unknown";
1196
+ const label = criterionLabel(model, check.id, criterion.id, w);
1197
+ const nameCell = el("td", "cn");
1198
+ const ruleName = el("b", "", label.label);
1199
+ nameCell.append(ruleName);
1200
+ const badge = editedBadge(model, ref, w);
1201
+ if (badge !== undefined)
1202
+ nameCell.append(badge);
1203
+ if (tier !== undefined) {
1204
+ tr.dataset.requirementTier = tier;
1205
+ nameCell.append(tierChip(tier, w));
1206
+ }
1207
+ if (label.source === "sealed")
1208
+ nameCell.append(el("small", "", label.text));
1209
+ // contract-report/v1 section 3: the pack's explanation of the rule,
1210
+ // and its note for a rule whose claims could not be decided.
1211
+ const detail = w.row(ref, "detail");
1212
+ if (detail !== undefined) {
1213
+ const line = el("small", "rdet", detail);
1214
+ line.dataset.wording = "pack";
1215
+ nameCell.append(line);
1216
+ }
1217
+ const undecidedNote = w.row(ref, "not_evaluable");
1218
+ if (undecidedNote !== undefined && undecided.length > 0) {
1219
+ const line = el("small", "rdet", undecidedNote);
1220
+ line.dataset.wording = "pack";
1221
+ line.dataset.note = "not-evaluable";
1222
+ nameCell.append(line);
1223
+ }
1224
+ const problems = [
1225
+ ...notMet,
1226
+ ...unverifiedHere.filter((c) => !notMet.includes(c)),
1227
+ ...undecided.filter((c) => !notMet.includes(c) && !unverifiedHere.includes(c)),
1228
+ ];
1229
+ tr.append(nameCell, countCell(`n${notMet.length > 0 ? " bad" : ""}`, "not_met", notMet), countCell("n ok", "met", met), countCell("n", "undecided", undecided));
1230
+ if (anyUnverified)
1231
+ tr.append(countCell("n", "unverified", unverifiedHere));
1232
+ if (anyOutOfScope)
1233
+ tr.append(countCell("n", "out_of_scope", outOfScopeHere));
1234
+ tbody.append(tr);
1235
+ // The row opens: a full-width row below it holds how many
1236
+ // conversations the rule did not apply to and the conversations
1237
+ // behind its problems, each read at the table's width. A rule with
1238
+ // neither has nothing to open.
1239
+ if (problems.length === 0 && na.length === 0)
1240
+ continue;
1241
+ const drillRow = el("tr", "drill-row");
1242
+ drillRow.dataset.drillFor = ref;
1243
+ const cell = element("td");
1244
+ cell.setAttribute("colspan", columns);
1245
+ drillRow.append(cell);
1246
+ // The not-applicable count is drawn now, so a static page (which runs
1247
+ // no script to build a body) still shows it when the row opens.
1248
+ if (na.length > 0) {
1249
+ const naLine = el("p", "rule-na", w.p("lines.rules.expand.na", na.length, {
1250
+ n: fmtCount(na.length),
1251
+ }));
1252
+ naLine.dataset.count = String(na.length);
1253
+ cell.append(naLine);
1254
+ }
1255
+ const toggle = expandableRow(tr, ruleName, drillRow, () => problems.length > 0
1256
+ ? renderConversationList(problems, model, runInfo, `rule:${ref}`, w)
1257
+ : document.createDocumentFragment(), `rule-${ref}`);
1258
+ toggle.dataset.drill = `rule:${ref}`;
1259
+ tbody.append(drillRow);
1126
1260
  }
1127
- const toggle = expandableRow(tr, ruleName, drillRow, () => problems.length > 0
1128
- ? renderConversationList(problems, model, runInfo, `rule:${ref}`, w)
1129
- : document.createDocumentFragment(), `rule-${ref}`);
1130
- toggle.dataset.drill = `rule:${ref}`;
1131
- tbody.append(drillRow);
1132
1261
  }
1133
1262
  }
1134
1263
  // Requirements of the cited contract the run did not cover (Result v0
@@ -1175,9 +1304,13 @@ function renderCalendar(host, model, w) {
1175
1304
  const list = el("div", "cal");
1176
1305
  list.dataset.days = String(model.days.length);
1177
1306
  for (const day of model.days) {
1307
+ // Resolved as the page's lines count it (`conversationStatus`), which
1308
+ // leaves out informational rules; the model's own count is the same
1309
+ // when a contract marks none.
1310
+ const resolved = day.conversations.filter((c) => conversationStatus(c, model.gating) === "resolved").length;
1178
1311
  const item = el("div", "day");
1179
1312
  item.dataset.day = day.date;
1180
- item.dataset.resolved = String(day.resolvedCount);
1313
+ item.dataset.resolved = String(resolved);
1181
1314
  item.dataset.total = String(day.conversations.length);
1182
1315
  item.append(el("div", "dn", day.date));
1183
1316
  if (note !== undefined) {
@@ -1194,11 +1327,9 @@ function renderCalendar(host, model, w) {
1194
1327
  item.append(tz);
1195
1328
  }
1196
1329
  }
1197
- item.append(el("div", "v", fmtShare(day.resolvedCount, day.conversations.length, model.options.percentages, w)));
1330
+ item.append(el("div", "v", fmtShare(resolved, day.conversations.length, model.options.percentages, w)));
1198
1331
  const mini = el("div", "mini");
1199
- const share = day.conversations.length === 0
1200
- ? 0
1201
- : day.resolvedCount / day.conversations.length;
1332
+ const share = day.conversations.length === 0 ? 0 : resolved / day.conversations.length;
1202
1333
  const fill = element("i");
1203
1334
  fill.style.width = `${Math.round(share * 100)}%`;
1204
1335
  mini.append(fill);
@@ -1498,6 +1629,72 @@ function renderReportProofs(host, model, runInfo, bundle, verified, w) {
1498
1629
  section.append(toggle);
1499
1630
  host.append(section);
1500
1631
  }
1632
+ /**
1633
+ * The Result document the root carries, from the verified disclosures: the
1634
+ * member itself, or a book header's statement. Undefined when it is withheld
1635
+ * or is not an object.
1636
+ */
1637
+ async function resultDocument(result, bundle) {
1638
+ try {
1639
+ const context = await verifiedBundleContext(bundle);
1640
+ const member = disclosureOf(context, result.capsuleId, result.member);
1641
+ if (member.state !== "disclosed")
1642
+ return undefined;
1643
+ const payload = member.payload;
1644
+ return result.form === "book" &&
1645
+ payload !== null &&
1646
+ typeof payload === "object"
1647
+ ? payload.statement
1648
+ : payload;
1649
+ }
1650
+ catch {
1651
+ return undefined;
1652
+ }
1653
+ }
1654
+ /** Each conversation as Same customer in this report draws it (subject-history.ts). */
1655
+ function subjectConversations(model, w) {
1656
+ return model.conversations.map((c) => {
1657
+ const status = conversationStatus(c, model.gating);
1658
+ const outcome = statusWord(status, c, w, model.gating);
1659
+ const time = /T(\d{2}:\d{2})/u.exec(c.dated.stated ?? "")?.[1];
1660
+ const turns = c.transcript.state === "verified" || c.transcript.state === "cited"
1661
+ ? c.transcript.turns
1662
+ : undefined;
1663
+ return {
1664
+ id: c.conversationId,
1665
+ date: c.day,
1666
+ ...(time === undefined ? {} : { time }),
1667
+ status,
1668
+ outcome,
1669
+ terms: c.criteria.map((cr) => ({
1670
+ ref: `${cr.checkId}.${cr.criterionId}`,
1671
+ label: criterionLabel(model, cr.checkId, cr.criterionId, w).label,
1672
+ tone: criterionWord(cr, w).tone,
1673
+ })),
1674
+ open: c.criteria
1675
+ .filter((cr) => cr.verdict !== "met" && cr.verdict !== "not_applicable")
1676
+ .map((cr) => {
1677
+ const label = criterionLabel(model, cr.checkId, cr.criterionId, w);
1678
+ const worded = criterionWord(cr, w);
1679
+ return {
1680
+ label: label.label,
1681
+ wording: label.source === "sealed" ? label.text : "",
1682
+ verdict: worded.word,
1683
+ tone: worded.tone,
1684
+ note: cr.rationale === undefined
1685
+ ? noNoteText(cr, w)
1686
+ : judgeNote(cr.rationale, cr.claim?.verdict ?? cr.verdict, w),
1687
+ };
1688
+ }),
1689
+ ...(turns === undefined
1690
+ ? {}
1691
+ : {
1692
+ turns: turns.length,
1693
+ calls: turns.reduce((n, t) => n + t.toolCalls.length, 0),
1694
+ }),
1695
+ };
1696
+ });
1697
+ }
1501
1698
  /** The `lines` grouping's page wrapper: its element, class, page name and stylesheet. */
1502
1699
  export const LINES_FRAME = {
1503
1700
  tag: "section",
@@ -1509,13 +1706,17 @@ export const LINES_FRAME = {
1509
1706
  * Draw the `lines` grouping into `wrapper` (contract-report.ts made it and
1510
1707
  * put its stylesheet in it). Every word is `w`'s.
1511
1708
  */
1512
- export async function drawLines(levels, result, options, bundle, verified, w) {
1513
- const model = buildOutcomeReportModel(result, options);
1709
+ export async function drawLines(levels, result, options, bundle, verified, w, tierOf) {
1710
+ const built = buildOutcomeReportModel(result, options);
1711
+ const model = tierOf === undefined
1712
+ ? built
1713
+ : { ...built, gating: gating(built.conversations, tierOf) };
1514
1714
  const runInfo = await verifyJudgePin(model.runInfo);
1515
1715
  const claims = model.conversations.flatMap((c) => c.criteria.flatMap((cr) => (cr.claim === undefined ? [] : [cr.claim])));
1516
1716
  // L0, what matters, after the core's strip (the mock-judge mark and the
1517
1717
  // sealed aggregate, core-strip.ts): the header, then the per-conversation
1518
1718
  // lines, each opening its list.
1719
+ levels.L0.append(renderLegend(w));
1519
1720
  const sheet = el("div", "sheet");
1520
1721
  const pad = el("div", "pad");
1521
1722
  // Notes that explain a figure sit under the sheet, in small type, never
@@ -1528,6 +1729,14 @@ export async function drawLines(levels, result, options, bundle, verified, w) {
1528
1729
  pad.append(notes);
1529
1730
  sheet.append(pad);
1530
1731
  levels.L0.append(sheet);
1732
+ // Same customer in this report (Outcomes frame 5), when the Result carries
1733
+ // the producer's slice; every count in it is of this report's conversations.
1734
+ const slice = readSubjectHistory(await resultDocument(result, bundle));
1735
+ if (slice !== undefined) {
1736
+ const subject = renderSubjectHistory(subjectConversations(model, w), slice, model.totalCount, w);
1737
+ if (subject !== undefined)
1738
+ levels.L0.append(subject);
1739
+ }
1531
1740
  // L1, why: rule by rule, led by who judged, who witnessed, what verified.
1532
1741
  renderRules(levels.L1, model, runInfo, result, w);
1533
1742
  leadWithProvenance(levels.L1, levels.L1.querySelector('[data-section="rules"]'), renderProvenance(await provenanceLines(result.records, claims, bundle, verified, w)));