@action-state-group/capsule-viewer 0.7.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 (53) hide show
  1. package/dist/compliance-styles.js +7 -0
  2. package/dist/compliance-styles.js.map +1 -1
  3. package/dist/compliance-view.d.ts +4 -3
  4. package/dist/compliance-view.js +139 -88
  5. package/dist/compliance-view.js.map +1 -1
  6. package/dist/contract-report-wording.d.ts +2 -1
  7. package/dist/contract-report-wording.js +32 -3
  8. package/dist/contract-report-wording.js.map +1 -1
  9. package/dist/contract-report.d.ts +16 -1
  10. package/dist/contract-report.js +31 -3
  11. package/dist/contract-report.js.map +1 -1
  12. package/dist/core-strip.d.ts +1 -1
  13. package/dist/core-strip.js +7 -4
  14. package/dist/core-strip.js.map +1 -1
  15. package/dist/emitter-shell.html +16 -0
  16. package/dist/evidence-contract.d.ts +61 -0
  17. package/dist/evidence-contract.js +83 -0
  18. package/dist/evidence-contract.js.map +1 -0
  19. package/dist/evidence-graph-view.d.ts +10 -0
  20. package/dist/evidence-graph-view.js +35 -5
  21. package/dist/evidence-graph-view.js.map +1 -1
  22. package/dist/evidence-graph.iife.js +1657 -786
  23. package/dist/index.d.ts +1 -0
  24. package/dist/index.js +1 -0
  25. package/dist/index.js.map +1 -1
  26. package/dist/outcome-report-styles.js +9 -0
  27. package/dist/outcome-report-styles.js.map +1 -1
  28. package/dist/outcome-report-view.d.ts +19 -4
  29. package/dist/outcome-report-view.js +307 -127
  30. package/dist/outcome-report-view.js.map +1 -1
  31. package/dist/presentation-builder.d.ts +14 -0
  32. package/dist/presentation-builder.js +45 -1
  33. package/dist/presentation-builder.js.map +1 -1
  34. package/dist/presentation-fragment.d.ts +3 -0
  35. package/dist/presentation-fragment.js +9 -0
  36. package/dist/presentation-fragment.js.map +1 -1
  37. package/dist/presentation-mount.d.ts +3 -0
  38. package/dist/presentation-mount.js +2 -0
  39. package/dist/presentation-mount.js.map +1 -1
  40. package/dist/report-legend.d.ts +6 -7
  41. package/dist/report-legend.js +16 -9
  42. package/dist/report-legend.js.map +1 -1
  43. package/dist/report-levels.js +2 -1
  44. package/dist/report-levels.js.map +1 -1
  45. package/dist/spot-check.js +10 -5
  46. package/dist/spot-check.js.map +1 -1
  47. package/dist/subject-history.d.ts +77 -0
  48. package/dist/subject-history.js +439 -0
  49. package/dist/subject-history.js.map +1 -0
  50. package/dist/viewer-build.js +1 -1
  51. package/dist/wording/contract-report-eu-ai-act.en.json +16 -1
  52. package/dist/wording/contract-report-outcomes.en.json +61 -2
  53. package/package.json +1 -1
@@ -1,3 +1,4 @@
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";
@@ -6,6 +7,8 @@ import { renderLegend, tagSource } from "./report-legend.js";
6
7
  import { provenanceLines, renderProvenance } from "./report-provenance.js";
7
8
  import { expandableRow, leadWithProvenance, renderCheckYourself, } from "./report-front.js";
8
9
  import { spotCheckToggle } from "./spot-check.js";
10
+ import { readSubjectHistory, renderSubjectHistory, } from "./subject-history.js";
11
+ import { ROW_TIERS } from "./evidence-contract.js";
9
12
  /**
10
13
  * The contract-report module's `lines` grouping (contract-report.ts): a
11
14
  * report read as result lines, results rule by rule, day by day and human
@@ -181,7 +184,55 @@ function isUnverified(verdict) {
181
184
  function notApplying(verdict) {
182
185
  return verdict === "not_applicable" || verdict === "out_of_scope";
183
186
  }
184
- 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";
185
236
  if (conversation.verdict === "met")
186
237
  return "resolved";
187
238
  if (conversation.criteria.some((c) => isMiss(c.verdict)))
@@ -197,7 +248,7 @@ export function conversationStatus(conversation) {
197
248
  }
198
249
  // Result words never come from the bundle (presentation contract section
199
250
  // 6): they are the card's wording pack's.
200
- export function statusWord(status, conversation, w) {
251
+ export function statusWord(status, conversation, w, gating) {
201
252
  if (status === "resolved")
202
253
  return { word: w.t("lines.status.resolved"), tone: "ok" };
203
254
  if (status === "missed")
@@ -212,8 +263,8 @@ export function statusWord(status, conversation, w) {
212
263
  // tells them apart.
213
264
  // A `no_claim` rule is undecided with no judge run on it (no claim, so no
214
265
  // report): it counts as unjudged.
215
- const judged = conversation.criteria
216
- .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")
217
268
  .map((c) => c.verdict === "no_claim"
218
269
  ? "no"
219
270
  : judgedOf(c.reportState, c.judgePinDigest));
@@ -283,7 +334,7 @@ function unverifiedClause(model, list, w, lower = false) {
283
334
  }
284
335
  /** One plain sentence: the conversation's result and the rules behind it. */
285
336
  function resultSentence(conversation, model, w) {
286
- const all = conversation.criteria;
337
+ const all = counted(conversation, model.gating).criteria;
287
338
  const applied = all.filter((c) => !notApplying(c.verdict));
288
339
  const outOfScope = all.filter((c) => c.verdict === "out_of_scope").length;
289
340
  const na = all.length - applied.length - outOfScope;
@@ -302,7 +353,7 @@ function resultSentence(conversation, model, w) {
302
353
  ? ` ${w.t("lines.sentence.out-of-scope", { n: String(outOfScope) })}`
303
354
  : ""}`;
304
355
  const unverifiedText = unverified.length > 0 ? ` ${unverifiedClause(model, unverified, w)}` : "";
305
- switch (conversationStatus(conversation)) {
356
+ switch (conversationStatus(conversation, model.gating)) {
306
357
  case "resolved":
307
358
  return `${w.p("lines.sentence.resolved", applied.length, { n: String(applied.length) })}${naText}`;
308
359
  case "missed":
@@ -343,19 +394,21 @@ function resultSentence(conversation, model, w) {
343
394
  * own. The body is built when it scrolls near the view (`lazyBody`).
344
395
  */
345
396
  function renderConversation(conversation, model, runInfo, w) {
346
- const status = conversationStatus(conversation);
397
+ const status = conversationStatus(conversation, model.gating);
347
398
  const item = el("article", "conv");
348
399
  item.dataset.conversation = conversation.conversationId;
349
- 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;
350
403
  item.dataset.status = status;
351
404
  const head = el("div", "conv-h");
352
405
  const parts = caseParts(conversation.conversationId, w);
353
406
  head.append(el("span", "cid", parts.label));
354
- head.append(wordPill(statusWord(status, conversation, w), status));
355
- const misses = conversation.criteria.filter((c) => isMiss(c.verdict));
356
- const unverified = conversation.criteria.filter((c) => isUnverified(c.verdict));
357
- const undecided = conversation.criteria.filter((c) => c.verdict === "not_evaluable" || c.verdict === "no_claim");
358
- 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");
359
412
  head.append(el("span", "cwhy", status === "missed"
360
413
  ? w.t("lines.why.missed", { names: names(model, misses, w) })
361
414
  : status === "unverified"
@@ -370,8 +423,8 @@ function renderConversation(conversation, model, runInfo, w) {
370
423
  ? w.t("lines.why.nothing-applied")
371
424
  : outOfScope.length === 0
372
425
  ? w.t("lines.why.resolved")
373
- : w.p("lines.why.resolved-out-of-scope", conversation.criteria.length - outOfScope.length, {
374
- 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),
375
428
  oos: fmtCount(outOfScope.length),
376
429
  })));
377
430
  head.append(el("span", "cmodel", parts.model ?? ""));
@@ -384,7 +437,7 @@ function renderConversation(conversation, model, runInfo, w) {
384
437
  function conversationBody(conversation, model, runInfo, w) {
385
438
  const body = el("div", "conv-b");
386
439
  const sentence = el("p", "verdict-line", resultSentence(conversation, model, w));
387
- sentence.dataset.why = conversationStatus(conversation);
440
+ sentence.dataset.why = conversationStatus(conversation, model.gating);
388
441
  body.append(sentence);
389
442
  // Rule by rule, in plain words
390
443
  body.append(el("h4", "", w.t("lines.h.rule-by-rule")));
@@ -414,6 +467,13 @@ function conversationBody(conversation, model, runInfo, w) {
414
467
  const rowBadge = editedBadge(model, ref, w);
415
468
  if (rowBadge !== undefined)
416
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
+ }
417
477
  if (label.source === "sealed") {
418
478
  const wording = tagSource(el("small", "", label.text), "producer");
419
479
  wording.dataset.wording = label.source;
@@ -720,13 +780,13 @@ function groupTitle(check, w) {
720
780
  * label (`terms.reasonCodes`), else the first rule not met; a raw code is
721
781
  * never shown.
722
782
  */
723
- export function groupMissedReasons(missed, terms, w) {
783
+ export function groupMissedReasons(missed, terms, w, gating) {
724
784
  const labelledReasonCode = (code) => code === undefined ? undefined : terms.reasonCodes[code];
725
785
  const groups = new Map();
726
786
  const structured = new Map();
727
787
  const labels = new Map();
728
788
  for (const conversation of missed) {
729
- const first = conversation.criteria.find((c) => isMiss(c.verdict));
789
+ const first = counted(conversation, gating).criteria.find((c) => isMiss(c.verdict));
730
790
  if (first === undefined)
731
791
  continue;
732
792
  const label = labelledReasonCode(first.reasonCode);
@@ -758,7 +818,7 @@ export function groupMissedReasons(missed, terms, w) {
758
818
  function whyMissed(missed, model, runInfo, w) {
759
819
  const box = el("div", "why-missed");
760
820
  box.dataset.section = "why-missed";
761
- const groups = groupMissedReasons(missed, model.terms, w);
821
+ const groups = groupMissedReasons(missed, model.terms, w, model.gating);
762
822
  box.dataset.reasons = String(groups.length);
763
823
  box.append(el("h5", "", w.t("lines.why-missed.h")));
764
824
  const table = element("table");
@@ -922,7 +982,7 @@ function renderLines(host, model, runInfo, w, notes) {
922
982
  thead.append(headRow);
923
983
  table.append(thead);
924
984
  const tbody = document.createElement("tbody");
925
- const byStatus = (status) => model.conversations.filter((c) => conversationStatus(c) === status);
985
+ const byStatus = (status) => model.conversations.filter((c) => conversationStatus(c, model.gating) === status);
926
986
  const resolved = byStatus("resolved");
927
987
  const missed = byStatus("missed");
928
988
  const unverified = byStatus("unverified");
@@ -1019,6 +1079,7 @@ function renderLines(host, model, runInfo, w, notes) {
1019
1079
  // Summary: results rule by rule
1020
1080
  // ---------------------------------------------------------------------------
1021
1081
  function renderRules(host, model, runInfo, result, w) {
1082
+ const tierOf = model.gating?.tierOf;
1022
1083
  const section = el("section", "sec");
1023
1084
  section.dataset.section = "rules";
1024
1085
  section.append(el("h2", "", w.t("lines.rules.h")));
@@ -1052,111 +1113,151 @@ function renderRules(host, model, runInfo, result, w) {
1052
1113
  thead.append(headRow);
1053
1114
  table.append(thead);
1054
1115
  const tbody = element("tbody");
1055
- for (const check of model.terms.checks) {
1056
- const group = el("tr", "grp");
1057
- group.dataset.checkId = check.id;
1058
- group.dataset.passCount = String(model.checkPassCounts.get(check.id) ?? 0);
1059
- const cell = el("td", "", groupTitle(check, w));
1060
- cell.setAttribute("colspan", columns);
1061
- group.append(cell);
1062
- 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)
1063
1130
  for (const criterion of check.criteria) {
1064
1131
  const ref = `${check.id}.${criterion.id}`;
1065
- const of = (pick) => model.conversations.filter((c) => c.criteria.some((cr) => cr.checkId === check.id &&
1066
- cr.criterionId === criterion.id &&
1067
- pick(cr.verdict)));
1068
- // Each count column's verdicts, read once: a cell's number and the
1069
- // claims its Show-evidence action lists come from the same pick.
1070
- const picks = {
1071
- not_met: isMiss,
1072
- met: (v) => v === "met",
1073
- undecided: (v) => v === "not_evaluable" || v === "no_claim",
1074
- unverified: isUnverified,
1075
- out_of_scope: (v) => v === "out_of_scope",
1076
- };
1077
- const met = of(picks.met);
1078
- const notMet = of(picks.not_met);
1079
- const unverifiedHere = of(picks.unverified);
1080
- const na = of((v) => v === "not_applicable");
1081
- const outOfScopeHere = of(picks.out_of_scope);
1082
- const undecided = of(picks.undecided);
1083
- // One count cell: the number, and its Show-evidence action (or the
1084
- // label that stands in for one) over the claims behind it on this rule.
1085
- const countCell = (className, column, counted) => {
1086
- const pick = picks[column];
1087
- const cell = el("td", className);
1088
- cell.dataset.column = column;
1089
- cell.append(el("span", "nv", fmtCount(counted.length)));
1090
- const action = evidenceAction(`rule:${ref}:${column}`, `${label.label} · ${columnWord[column]}: ${fmtCount(counted.length)}`, counted.map((c) => c.criteria.find((cr) => cr.checkId === check.id &&
1091
- cr.criterionId === criterion.id &&
1092
- pick(cr.verdict))?.claim), result, w);
1093
- if (action !== undefined)
1094
- cell.append(action);
1095
- return cell;
1096
- };
1097
- const tr = el("tr", "rule");
1098
- tr.dataset.rule = ref;
1099
- tr.dataset.tier = model.criterionTiers.get(ref) ?? "unknown";
1100
- const label = criterionLabel(model, check.id, criterion.id, w);
1101
- const nameCell = el("td", "cn");
1102
- const ruleName = el("b", "", label.label);
1103
- nameCell.append(ruleName);
1104
- const badge = editedBadge(model, ref, w);
1105
- if (badge !== undefined)
1106
- nameCell.append(badge);
1107
- if (label.source === "sealed")
1108
- nameCell.append(el("small", "", label.text));
1109
- // contract-report/v1 section 3: the pack's explanation of the rule,
1110
- // and its note for a rule whose claims could not be decided.
1111
- const detail = w.row(ref, "detail");
1112
- if (detail !== undefined) {
1113
- const line = el("small", "rdet", detail);
1114
- line.dataset.wording = "pack";
1115
- nameCell.append(line);
1116
- }
1117
- const undecidedNote = w.row(ref, "not_evaluable");
1118
- if (undecidedNote !== undefined && undecided.length > 0) {
1119
- const line = el("small", "rdet", undecidedNote);
1120
- line.dataset.wording = "pack";
1121
- line.dataset.note = "not-evaluable";
1122
- nameCell.append(line);
1123
- }
1124
- const problems = [
1125
- ...notMet,
1126
- ...unverifiedHere.filter((c) => !notMet.includes(c)),
1127
- ...undecided.filter((c) => !notMet.includes(c) && !unverifiedHere.includes(c)),
1128
- ];
1129
- tr.append(nameCell, countCell(`n${notMet.length > 0 ? " bad" : ""}`, "not_met", notMet), countCell("n ok", "met", met), countCell("n", "undecided", undecided));
1130
- if (anyUnverified)
1131
- tr.append(countCell("n", "unverified", unverifiedHere));
1132
- if (anyOutOfScope)
1133
- tr.append(countCell("n", "out_of_scope", outOfScopeHere));
1134
- tbody.append(tr);
1135
- // The row opens: a full-width row below it holds how many
1136
- // conversations the rule did not apply to and the conversations
1137
- // behind its problems, each read at the table's width. A rule with
1138
- // neither has nothing to open.
1139
- 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)
1140
1151
  continue;
1141
- const drillRow = el("tr", "drill-row");
1142
- drillRow.dataset.drillFor = ref;
1143
- 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));
1144
1156
  cell.setAttribute("colspan", columns);
1145
- drillRow.append(cell);
1146
- // The not-applicable count is drawn now, so a static page (which runs
1147
- // no script to build a body) still shows it when the row opens.
1148
- if (na.length > 0) {
1149
- const naLine = el("p", "rule-na", w.p("lines.rules.expand.na", na.length, {
1150
- n: fmtCount(na.length),
1151
- }));
1152
- naLine.dataset.count = String(na.length);
1153
- 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);
1154
1260
  }
1155
- const toggle = expandableRow(tr, ruleName, drillRow, () => problems.length > 0
1156
- ? renderConversationList(problems, model, runInfo, `rule:${ref}`, w)
1157
- : document.createDocumentFragment(), `rule-${ref}`);
1158
- toggle.dataset.drill = `rule:${ref}`;
1159
- tbody.append(drillRow);
1160
1261
  }
1161
1262
  }
1162
1263
  // Requirements of the cited contract the run did not cover (Result v0
@@ -1203,9 +1304,13 @@ function renderCalendar(host, model, w) {
1203
1304
  const list = el("div", "cal");
1204
1305
  list.dataset.days = String(model.days.length);
1205
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;
1206
1311
  const item = el("div", "day");
1207
1312
  item.dataset.day = day.date;
1208
- item.dataset.resolved = String(day.resolvedCount);
1313
+ item.dataset.resolved = String(resolved);
1209
1314
  item.dataset.total = String(day.conversations.length);
1210
1315
  item.append(el("div", "dn", day.date));
1211
1316
  if (note !== undefined) {
@@ -1222,11 +1327,9 @@ function renderCalendar(host, model, w) {
1222
1327
  item.append(tz);
1223
1328
  }
1224
1329
  }
1225
- 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)));
1226
1331
  const mini = el("div", "mini");
1227
- const share = day.conversations.length === 0
1228
- ? 0
1229
- : day.resolvedCount / day.conversations.length;
1332
+ const share = day.conversations.length === 0 ? 0 : resolved / day.conversations.length;
1230
1333
  const fill = element("i");
1231
1334
  fill.style.width = `${Math.round(share * 100)}%`;
1232
1335
  mini.append(fill);
@@ -1526,6 +1629,72 @@ function renderReportProofs(host, model, runInfo, bundle, verified, w) {
1526
1629
  section.append(toggle);
1527
1630
  host.append(section);
1528
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
+ }
1529
1698
  /** The `lines` grouping's page wrapper: its element, class, page name and stylesheet. */
1530
1699
  export const LINES_FRAME = {
1531
1700
  tag: "section",
@@ -1537,8 +1706,11 @@ export const LINES_FRAME = {
1537
1706
  * Draw the `lines` grouping into `wrapper` (contract-report.ts made it and
1538
1707
  * put its stylesheet in it). Every word is `w`'s.
1539
1708
  */
1540
- export async function drawLines(levels, result, options, bundle, verified, w) {
1541
- 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) };
1542
1714
  const runInfo = await verifyJudgePin(model.runInfo);
1543
1715
  const claims = model.conversations.flatMap((c) => c.criteria.flatMap((cr) => (cr.claim === undefined ? [] : [cr.claim])));
1544
1716
  // L0, what matters, after the core's strip (the mock-judge mark and the
@@ -1557,6 +1729,14 @@ export async function drawLines(levels, result, options, bundle, verified, w) {
1557
1729
  pad.append(notes);
1558
1730
  sheet.append(pad);
1559
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
+ }
1560
1740
  // L1, why: rule by rule, led by who judged, who witnessed, what verified.
1561
1741
  renderRules(levels.L1, model, runInfo, result, w);
1562
1742
  leadWithProvenance(levels.L1, levels.L1.querySelector('[data-section="rules"]'), renderProvenance(await provenanceLines(result.records, claims, bundle, verified, w)));