@yokla/report 0.4.3 → 0.6.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.
package/src/html.ts CHANGED
@@ -8,8 +8,21 @@
8
8
  // - The same results give the same bytes: no render time, no locale formatting.
9
9
  // - A model call's prompt is shown by role and size only (ADR-0015).
10
10
 
11
- import { CASE_STATUSES, type Results } from '@yokla/core';
12
- import { counted, observedTotals, round, withOrigin } from './format.ts';
11
+ import { CASE_STATUSES, failingCategories, type Results } from '@yokla/core';
12
+ import {
13
+ byWeight,
14
+ categoryCode,
15
+ counted,
16
+ MAPPING_NOTE,
17
+ scoreText,
18
+ observedTotals,
19
+ passRateText,
20
+ rate,
21
+ round,
22
+ tagsByFailures,
23
+ hasWeights,
24
+ withOrigin,
25
+ } from './format.ts';
13
26
  import { xmlText } from './junit.ts';
14
27
  import { caseProblems, caseReason, dimensionSummary, type CaseResult } from './problems.ts';
15
28
 
@@ -18,7 +31,7 @@ type CheckResult = TurnResult['checks'][number];
18
31
  type ModelCall = NonNullable<TurnResult['proxy']>['calls'][number];
19
32
 
20
33
  /** Markup that is safe as it is. */
21
- interface Html {
34
+ export interface Html {
22
35
  readonly markup: string;
23
36
  }
24
37
  type Part = string | number | Html | readonly Html[] | undefined;
@@ -38,7 +51,7 @@ function markupOf(part: Part): string {
38
51
  }
39
52
 
40
53
  /** A template whose strings are markup and whose values are escaped text. */
41
- function h(strings: TemplateStringsArray, ...parts: readonly Part[]): Html {
54
+ export function h(strings: TemplateStringsArray, ...parts: readonly Part[]): Html {
42
55
  let markup = strings[0] ?? '';
43
56
  for (const [index, part] of parts.entries()) {
44
57
  markup += markupOf(part) + (strings[index + 1] ?? '');
@@ -46,7 +59,8 @@ function h(strings: TemplateStringsArray, ...parts: readonly Part[]): Html {
46
59
  return { markup };
47
60
  }
48
61
 
49
- const STYLE = `
62
+ // The helpers below are shared with the comparison page (ADR-0095).
63
+ export const STYLE = `
50
64
  :root { color-scheme: light dark; --bg: #ffffff; --fg: #1d2025; --muted: #5d6570;
51
65
  --line: #d8dce2; --panel: #f6f7f9; --code: #eef0f3;
52
66
  --good: #1a7f37; --bad: #c42b2b; --warn: #8f6200; }
@@ -94,7 +108,7 @@ a { color: inherit; }
94
108
  @media print { details.case { break-inside: avoid-page; } }
95
109
  `;
96
110
 
97
- const STATUS_TONE: Readonly<Record<CaseResult['status'], string>> = {
111
+ export const STATUS_TONE: Readonly<Record<CaseResult['status'], string>> = {
98
112
  pass: 'good',
99
113
  fail: 'bad',
100
114
  error: 'bad',
@@ -111,7 +125,7 @@ const VERDICT_TONE: Readonly<Record<string, string>> = {
111
125
  unmeasured: 'warn',
112
126
  };
113
127
 
114
- function badge(text: string, tone: string): Html {
128
+ export function badge(text: string, tone: string): Html {
115
129
  return h`<span class="status ${tone}">${text}</span>`;
116
130
  }
117
131
 
@@ -119,11 +133,11 @@ function seconds(durationMs: number): string {
119
133
  return `${(durationMs / 1000).toFixed(3)} s`;
120
134
  }
121
135
 
122
- function ms(value: number): string {
136
+ export function ms(value: number): string {
123
137
  return `${String(Math.round(value))} ms`;
124
138
  }
125
139
 
126
- function usd(value: number | null): string {
140
+ export function usd(value: number | null): string {
127
141
  return value === null ? 'no cost' : `$${round(value)}`;
128
142
  }
129
143
 
@@ -135,11 +149,15 @@ function item(term: string, value: Part): Html {
135
149
  return h`<dt>${term}</dt><dd>${value}</dd>`;
136
150
  }
137
151
 
138
- function list(lines: readonly string[], tone: string): Html {
152
+ export function list(lines: readonly string[], tone: string): Html {
139
153
  return h`<ul class="${tone}">${lines.map((line) => h`<li>${line}</li>`)}</ul>`;
140
154
  }
141
155
 
142
- function table(head: readonly string[], rows: readonly Html[], numeric: readonly number[] = []) {
156
+ export function table(
157
+ head: readonly string[],
158
+ rows: readonly Html[],
159
+ numeric: readonly number[] = [],
160
+ ): Html {
143
161
  const cells = head.map((name, index) =>
144
162
  numeric.includes(index) ? h`<th class="num">${name}</th>` : h`<th>${name}</th>`,
145
163
  );
@@ -177,6 +195,11 @@ function runSection(results: Results): Html {
177
195
  ),
178
196
  );
179
197
  }
198
+ // The strategy the run sent its redteam cases with (ADR-0084).
199
+ const { strategy } = run;
200
+ if (strategy !== undefined) {
201
+ items.push(item('Strategy', `${strategy.name}: ${counted(strategy.messages, 'message')}`));
202
+ }
180
203
  const { proxy, observation } = run;
181
204
  if (proxy !== undefined) {
182
205
  const { calls: _calls, ...sums } = proxy.totals;
@@ -225,8 +248,10 @@ function runSection(results: Results): Html {
225
248
  }</section>`;
226
249
  }
227
250
 
228
- function marks(c: CaseResult): Html[] {
251
+ function marks(c: CaseResult, weights = false): Html[] {
229
252
  return [
253
+ // Its weight, when the run's cases carry weights (ADR-0076).
254
+ ...(weights ? [h`<span class="mark">[weight ${String(c.weight ?? 1)}]</span>`] : []),
230
255
  ...(c.review === 'proposed' ? [h`<span class="mark">[proposed]</span>`] : []),
231
256
  ...(c.unstable ? [h`<span class="mark">[unstable]</span>`] : []),
232
257
  // A case that stopped once its failure was settled (ADR-0038).
@@ -254,15 +279,106 @@ function casesSection(results: Results, ordered: readonly CaseResult[]): Html {
254
279
  return count === undefined ? [] : [h`<li>${badge(status, STATUS_TONE[status])} ${count}</li>`];
255
280
  });
256
281
  const proposed = results.cases.filter((c) => c.review === 'proposed').length;
282
+ const weights = hasWeights(results);
283
+ // A Tags column once a case has tags, so each failing case shows its own (ADR-0077).
284
+ const tagged = results.cases.some((c) => c.tags !== undefined);
257
285
  const rows = ordered.map(
258
286
  (c) =>
259
- h`<tr><td>${badge(c.status, STATUS_TONE[c.status])}</td><td><a href="#case-${c.id}"><code>${c.id}</code></a>${marks(c)}</td><td>${c.suite}</td><td>${c.language}</td><td>${reasonOf(c)}</td></tr>`,
287
+ h`<tr><td>${badge(c.status, STATUS_TONE[c.status])}</td><td><a href="#case-${c.id}"><code>${c.id}</code></a>${marks(c, weights)}</td><td>${c.suite}</td><td>${c.language}</td>${
288
+ tagged ? h`<td>${(c.tags ?? []).join(', ')}</td>` : undefined
289
+ }<td>${reasonOf(c)}</td></tr>`,
260
290
  );
261
- return h`<section id="cases"><h2>Cases</h2><p>${counted(results.summary.cases, 'case')}</p><ul class="counts">${counts}</ul>${
291
+ const passRate = results.summary.passRate;
292
+ return h`<section id="cases"><h2>Cases</h2><p>${counted(results.summary.cases, 'case')}${
293
+ passRate === undefined ? undefined : `; ${passRateText(passRate)}`
294
+ }</p><ul class="counts">${counts}</ul>${
295
+ weights
296
+ ? h`<p class="muted">The weighted pass rate counts each case by its weight; failing cases are listed heaviest first.</p>`
297
+ : undefined
298
+ }${
262
299
  proposed === 0
263
300
  ? undefined
264
301
  : h`<p class="muted">${counted(proposed, 'proposed case')}: they ran, and gate once a person sets their status to approved.</p>`
265
- }${table(['Status', 'Case', 'Suite', 'Language', 'Reason'], rows)}</section>`;
302
+ }${table(
303
+ ['Status', 'Case', 'Suite', 'Language', ...(tagged ? ['Tags'] : []), 'Reason'],
304
+ rows,
305
+ )}</section>`;
306
+ }
307
+
308
+ /** Per tag: the cases, their statuses and pass rate, the most failing first (ADR-0077). */
309
+ function tagsSection(results: Results): Html | undefined {
310
+ const tags = tagsByFailures(results);
311
+ if (tags.length === 0) return undefined;
312
+ const weights = hasWeights(results);
313
+ const rows = tags.map((group) => {
314
+ const statuses = CASE_STATUSES.flatMap((status) => {
315
+ const count = group.statuses[status];
316
+ return count === undefined ? [] : [`${status} ${String(count)}`];
317
+ }).join(', ');
318
+ const own = group.passRate;
319
+ return h`<tr><td><code>${group.tag}</code></td><td class="num">${group.cases}</td><td>${statuses}</td><td class="num">${
320
+ own === undefined
321
+ ? '–'
322
+ : `${rate(own.rate)} (${String(own.passed)} of ${String(own.measured)})`
323
+ }</td><td class="num">${
324
+ own === undefined ? '–' : `${rate(own.interval.lower)} to ${rate(own.interval.upper)}`
325
+ }</td>${
326
+ weights
327
+ ? h`<td class="num">${own?.weighted === undefined ? '–' : rate(own.weighted.rate)}</td>`
328
+ : undefined
329
+ }</tr>`;
330
+ });
331
+ return h`<section id="tags"><h2>By tag</h2><p class="muted">A case with several tags counts in each.</p>${table(
332
+ [
333
+ 'Tag',
334
+ 'Cases',
335
+ 'Statuses',
336
+ 'Pass rate',
337
+ 'Pass rate, 95 %',
338
+ ...(weights ? ['Weighted pass rate'] : []),
339
+ ],
340
+ rows,
341
+ weights ? [1, 3, 4, 5] : [1, 3, 4],
342
+ )}</section>`;
343
+ }
344
+
345
+ /**
346
+ * What the run's attack kinds and checks map to (ADR-0089): per framework,
347
+ * each category with the cases a failing finding names it in, and every
348
+ * attack kind's risk.
349
+ */
350
+ function frameworksSection(results: Results): Html | undefined {
351
+ const { taxonomy } = results;
352
+ if (taxonomy === undefined) return undefined;
353
+ const failing = new Map(failingCategories(results).map((row) => [row.category, row.cases]));
354
+ const frameworks = taxonomy.frameworks.map((framework) => {
355
+ const rows = framework.categories.map((category) => {
356
+ const cases = failing.get(category.id) ?? [];
357
+ return h`<tr><td><code>${categoryCode(framework.id, category.id)}</code></td><td>${category.name}</td><td class="num">${cases.length}</td><td>${cases.join(', ')}</td></tr>`;
358
+ });
359
+ return h`<h3>${framework.name} ${framework.version}</h3>${table(
360
+ ['Category', 'Name', 'Failing cases', 'Cases'],
361
+ rows,
362
+ [2],
363
+ )}`;
364
+ });
365
+ const risks = (results.summary.risk ?? []).map(
366
+ (risk) =>
367
+ h`<tr><td><code>${risk.kind}</code></td><td>${risk.severity}</td><td class="num">${risk.succeeded} of ${risk.trials}</td><td class="num">${
368
+ risk.rate === undefined || risk.interval === undefined
369
+ ? 'unmeasured'
370
+ : `${rate(risk.rate)} (95 % ${rate(risk.interval.lower)} to ${rate(risk.interval.upper)})`
371
+ }</td><td class="num">${scoreText(risk) ?? 'unmeasured'}</td></tr>`,
372
+ );
373
+ return h`<section id="frameworks"><h2>Frameworks</h2><p class="muted">The categories are ${MAPPING_NOTE}.</p>${frameworks}${
374
+ risks.length === 0
375
+ ? undefined
376
+ : h`<h3>Risk by attack kind</h3><p class="muted">10 × the severity's weight (critical 1, high 0.75, medium 0.5, low 0.25) × the attack success rate.</p>${table(
377
+ ['Kind', 'Severity', 'Succeeded', 'Success rate', 'Score'],
378
+ risks,
379
+ [2, 3, 4],
380
+ )}`
381
+ }</section>`;
266
382
  }
267
383
 
268
384
  function checksSection(results: Results): Html | undefined {
@@ -395,7 +511,7 @@ function spansBlock(spans: NonNullable<TurnResult['spans']>): Html {
395
511
  )}</details>`;
396
512
  }
397
513
 
398
- function answerBlock(turn: TurnResult): Html {
514
+ export function answerBlock(turn: TurnResult): Html {
399
515
  const { response } = turn;
400
516
  if (response === undefined) return h`<p class="bad">No answer.</p>`;
401
517
  const facts = [
@@ -493,9 +609,13 @@ function caseBlock(c: CaseResult): Html {
493
609
 
494
610
  /** The report as one HTML document. */
495
611
  export function htmlReport(results: Results): string {
496
- // Cases that didn't pass come first, in the order the results list them.
612
+ // Cases that didn't pass come first, in the order the results list them; the
613
+ // heaviest first when the cases carry weights (ADR-0076).
497
614
  const ordered = [
498
- ...results.cases.filter((c) => c.status !== 'pass'),
615
+ ...byWeight(
616
+ results,
617
+ results.cases.filter((c) => c.status !== 'pass'),
618
+ ),
499
619
  ...results.cases.filter((c) => c.status === 'pass'),
500
620
  ];
501
621
  const page = h`<!doctype html>
@@ -513,7 +633,8 @@ export function htmlReport(results: Results): string {
513
633
  <p class="muted">This report holds the target's answers and evidence. Keep it as private as the results file.</p>
514
634
  ${runSection(results)}
515
635
  ${casesSection(results, ordered)}
516
- ${checksSection(results)}
636
+ ${tagsSection(results)}
637
+ ${frameworksSection(results)}${checksSection(results)}
517
638
  <section id="details"><h2>Case details</h2>
518
639
  ${ordered.map((c) => h`${caseBlock(c)}\n`)}</section>
519
640
  </body>
package/src/index.ts CHANGED
@@ -3,6 +3,8 @@
3
3
  export { CONTENT_SECURITY_POLICY, htmlReport } from './html.ts';
4
4
  export { junitXml, xmlAttribute, xmlText } from './junit.ts';
5
5
  export { comparisonText } from './compare.ts';
6
+ export { comparisonHtml } from './compare-html.ts';
6
7
  export { caseProblems, caseReason, type CaseProblems, type Problem } from './problems.ts';
8
+ export { markdownReport, MARKDOWN_ROWS } from './markdown.ts';
7
9
  export { terminalSummary, type TerminalSummary } from './terminal.ts';
8
10
  export { originText, withOrigin } from './format.ts';
@@ -0,0 +1,80 @@
1
+ // The Markdown summary of a run (ADR-0094), for a CI's job summary: what the
2
+ // terminal summary says, as Markdown, and, with the gate's outcome, the
3
+ // verdict first. It holds no answers, as the terminal summary holds none; the
4
+ // results file and the HTML report keep them. Its table shows the first
5
+ // MARKDOWN_ROWS cases, so it stays well under a CI's limit for a summary.
6
+
7
+ import type { GateOutcome, Results } from '@yokla/core';
8
+ import { caseRows, countLines, errorLines, noteLines } from './terminal.ts';
9
+
10
+ /** The most cases the table shows. */
11
+ export const MARKDOWN_ROWS = 100;
12
+
13
+ const HEADINGS: Readonly<Record<GateOutcome['verdict'], string>> = {
14
+ pass: 'the gate passed',
15
+ broken: 'the gate is broken',
16
+ unjudgeable: "the gate can't judge the run",
17
+ };
18
+
19
+ /** Text for a table cell: one line, with its pipes escaped. */
20
+ function cell(text: string): string {
21
+ return text
22
+ .replaceAll('\\', '\\\\')
23
+ .replaceAll('|', '\\|')
24
+ .replaceAll(/\s*\n\s*/gu, ' ');
25
+ }
26
+
27
+ /** Text for a list item: one line. */
28
+ function item(text: string): string {
29
+ return `- ${text.replaceAll(/\s*\n\s*/gu, ' ')}`;
30
+ }
31
+
32
+ /** A run's summary as Markdown; with the gate's outcome, its verdict first. */
33
+ export function markdownReport(results: Results, outcome?: GateOutcome): string {
34
+ const out: string[] = [
35
+ outcome === undefined ? '### yokla' : `### yokla: ${HEADINGS[outcome.verdict]}`,
36
+ '',
37
+ `Run \`${results.run.id}\` against \`${results.run.profile.target}\`.`,
38
+ '',
39
+ ...countLines(results).map(item),
40
+ ];
41
+
42
+ if (outcome !== undefined) {
43
+ const lines = [
44
+ ...outcome.breaches.map((breach) => breach.message),
45
+ ...outcome.problems.map((problem) => `can't judge: ${problem}`),
46
+ ...outcome.notices.map((notice) => `notice: ${notice}`),
47
+ ];
48
+ if (lines.length > 0) out.push('', '**The gate**', '', ...lines.map(item));
49
+ }
50
+
51
+ const rows = caseRows(results);
52
+ if (rows.length > 0) {
53
+ out.push('', '| Status | Case | Why |', '| --- | --- | --- |');
54
+ for (const [status, id, reason] of rows.slice(0, MARKDOWN_ROWS)) {
55
+ out.push(`| ${cell(status)} | \`${cell(id)}\` | ${cell(reason)} |`);
56
+ }
57
+ const more = rows.length - MARKDOWN_ROWS;
58
+ if (more > 0) {
59
+ out.push('', `And ${String(more)} more, which the HTML report lists.`);
60
+ }
61
+ }
62
+
63
+ const errors = errorLines(results);
64
+ if (errors.length > 0) out.push('', '**Errors**', '', ...errors.map(item));
65
+
66
+ const notes = noteLines(results);
67
+ if (notes.length > 0) {
68
+ out.push(
69
+ '',
70
+ '<details><summary>More about the run</summary>',
71
+ '',
72
+ '```text',
73
+ ...notes,
74
+ '```',
75
+ '',
76
+ '</details>',
77
+ );
78
+ }
79
+ return `${out.join('\n')}\n`;
80
+ }
package/src/terminal.ts CHANGED
@@ -2,8 +2,18 @@
2
2
  // case that did not plainly pass, advisory findings, and what the target's
3
3
  // logs observed. Errors and run issues go to stderr.
4
4
 
5
- import { CASE_STATUSES, type Results } from '@yokla/core';
6
- import { counted, observedTotals } from './format.ts';
5
+ import { CASE_STATUSES, failingCategories, type Results } from '@yokla/core';
6
+ import {
7
+ byWeight,
8
+ categoryCode,
9
+ counted,
10
+ MAPPING_NOTE,
11
+ scoreText,
12
+ observedTotals,
13
+ passRateText,
14
+ tagsByFailures,
15
+ hasWeights,
16
+ } from './format.ts';
7
17
  import { caseProblems, caseReason, dimensionSummary } from './problems.ts';
8
18
 
9
19
  export interface TerminalSummary {
@@ -11,30 +21,99 @@ export interface TerminalSummary {
11
21
  readonly err: readonly string[];
12
22
  }
13
23
 
14
- export function terminalSummary(results: Results): TerminalSummary {
15
- const out: string[] = [];
16
- const err: string[] = [];
24
+ /** The attacker's bounds, as the summary words them (ADR-0087, ADR-0088). */
25
+ function attackerBound(attacker: NonNullable<Results['run']['attacker']>): string {
26
+ switch (attacker.strategy) {
27
+ case 'escalation': {
28
+ return `at most ${counted(attacker.limit, 'turn')}`;
29
+ }
30
+ case 'tree': {
31
+ const { branches, depth } = attacker;
32
+ const shape =
33
+ branches === undefined || depth === undefined
34
+ ? ''
35
+ : `${String(branches)} ${branches === 1 ? 'branch' : 'branches'} to depth ${String(depth)}, `;
36
+ return `${shape}at most ${counted(attacker.limit, 'attempt')}`;
37
+ }
38
+ case 'translate': {
39
+ return `into ${counted(attacker.limit, 'other language')}`;
40
+ }
41
+ case 'best-of-n':
42
+ case 'iterative': {
43
+ return counted(attacker.limit, 'attempt');
44
+ }
45
+ }
46
+ }
47
+
48
+ /**
49
+ * What the failing findings map to, per framework, and each attack kind
50
+ * that scored above 0 (ADR-0089); nothing when no finding failed.
51
+ */
52
+ function frameworkLines(results: Results): string[] {
53
+ const failing = new Map(failingCategories(results).map((row) => [row.category, row.cases]));
54
+ if (failing.size === 0) return [];
55
+ const lines = [`frameworks, ${MAPPING_NOTE}:`];
56
+ for (const framework of results.taxonomy?.frameworks ?? []) {
57
+ const named = framework.categories.flatMap((category) => {
58
+ const cases = failing.get(category.id);
59
+ return cases === undefined
60
+ ? []
61
+ : [
62
+ `${categoryCode(framework.id, category.id)} ${category.name} (${counted(cases.length, 'case')})`,
63
+ ];
64
+ });
65
+ if (named.length > 0) {
66
+ lines.push(` ${framework.name} ${framework.version}: ${named.join(', ')}`);
67
+ }
68
+ }
69
+ const scored = (results.summary.risk ?? []).filter((risk) => (risk.score ?? 0) > 0);
70
+ if (scored.length > 0) lines.push('risk by attack kind, from 0 to 10:');
71
+ for (const risk of scored) {
72
+ lines.push(
73
+ ` ${risk.kind} (${risk.severity}): ${scoreText(risk) ?? ''}; ${String(risk.succeeded)} of ${counted(risk.trials, 'trial')} succeeded`,
74
+ );
75
+ }
76
+ return lines;
77
+ }
17
78
 
79
+ /**
80
+ * The lines that open a run's summary: the status counts and pass rate, then
81
+ * what --stop-early saved and how many cases are proposed.
82
+ */
83
+ export function countLines(results: Results): string[] {
84
+ const lines: string[] = [];
18
85
  const counts = CASE_STATUSES.flatMap((status) => {
19
86
  const count = results.summary.statuses[status];
20
87
  return count === undefined ? [] : [`${status} ${String(count)}`];
21
88
  });
22
- out.push(`${String(results.summary.cases)} cases: ${counts.join(', ')}`);
89
+ const passRate = results.summary.passRate;
90
+ lines.push(
91
+ `${String(results.summary.cases)} cases: ${counts.join(', ')}` +
92
+ (passRate === undefined ? '' : `; ${passRateText(passRate)}`),
93
+ );
23
94
  if (results.run.sampling?.stopEarly === true) {
24
95
  // How many samples --stop-early saved (ADR-0038).
25
96
  const ran = results.cases.reduce((n, c) => n + c.samples.length, 0);
26
97
  const planned = results.cases.reduce((n, c) => n + (c.samplesPlanned ?? c.samples.length), 0);
27
- out.push(` --stop-early: ${counted(ran, 'sample')} ran of ${String(planned)} planned`);
98
+ lines.push(`--stop-early: ${counted(ran, 'sample')} ran of ${String(planned)} planned`);
28
99
  }
29
100
  const proposed = results.cases.filter((c) => c.review === 'proposed').length;
30
101
  if (proposed > 0) {
31
- out.push(
32
- ` ${String(proposed)} proposed: they ran, and gate once a person sets their status to approved`,
102
+ lines.push(
103
+ `${String(proposed)} proposed: they ran, and gate once a person sets their status to approved`,
33
104
  );
34
105
  }
106
+ return lines;
107
+ }
108
+
109
+ /** A case that didn't plainly pass, or its advisory findings: its status, its id, and why. */
110
+ export type CaseRow = readonly [status: string, id: string, reason: string];
35
111
 
36
- const rows: [string, string, string][] = [];
37
- for (const c of results.cases) {
112
+ /** The cases that didn't plainly pass, and advisory findings, heaviest first with weights (ADR-0076). */
113
+ export function caseRows(results: Results): CaseRow[] {
114
+ const rows: CaseRow[] = [];
115
+ const weights = hasWeights(results);
116
+ for (const c of byWeight(results, results.cases)) {
38
117
  const problems = caseProblems(c);
39
118
  const reason = caseReason(c, problems);
40
119
  if (reason !== undefined) {
@@ -42,22 +121,57 @@ export function terminalSummary(results: Results): TerminalSummary {
42
121
  c.samplesPlanned === undefined
43
122
  ? ''
44
123
  : ` [stopped after ${String(c.samples.length)} of ${String(c.samplesPlanned)} samples]`;
45
- const marks = `${c.unstable ? ' [unstable]' : ''}${stopped}${c.review === 'proposed' ? ' [proposed]' : ''}`;
124
+ const marks =
125
+ `${c.unstable ? ' [unstable]' : ''}${stopped}${c.review === 'proposed' ? ' [proposed]' : ''}` +
126
+ (weights ? ` [weight ${String(c.weight ?? 1)}]` : '') +
127
+ (c.tags === undefined ? '' : ` [tags: ${c.tags.join(', ')}]`);
46
128
  rows.push([c.status, c.id, `${reason}${marks}`]);
47
129
  }
48
130
  const advisory = dimensionSummary(c, problems.advisory, true);
49
131
  if (advisory !== '') rows.push(['advisory', c.id, advisory]);
132
+ }
133
+ return rows;
134
+ }
135
+
136
+ /** Each turn that ended in an error, and each problem of the run itself. */
137
+ export function errorLines(results: Results): string[] {
138
+ const lines: string[] = [];
139
+ for (const c of byWeight(results, results.cases)) {
50
140
  for (const sample of c.samples) {
51
141
  for (const turn of sample.turns) {
52
- if (turn.error !== undefined)
53
- err.push(` ${c.id} [sample ${String(sample.index)}]: ${turn.error}`);
142
+ if (turn.error !== undefined) {
143
+ lines.push(`${c.id} [sample ${String(sample.index)}]: ${turn.error}`);
144
+ }
54
145
  }
55
146
  }
56
147
  }
57
- const statusWidth = Math.max(0, ...rows.map(([status]) => status.length));
58
- const idWidth = Math.max(0, ...rows.map(([, id]) => id.length));
59
- for (const [status, id, reason] of rows) {
60
- out.push(` ${status.padEnd(statusWidth)} ${id.padEnd(idWidth)} ${reason}`);
148
+ for (const issue of results.run.issues ?? []) lines.push(`run: ${issue}`);
149
+ return lines;
150
+ }
151
+
152
+ /**
153
+ * The rest of a run's summary: the cases by tag, what the target's logs, the
154
+ * model proxy and the spans observed, yokla's own models, the run's
155
+ * transforms, strategy, attacker and judge, and the frameworks.
156
+ */
157
+ export function noteLines(results: Results): string[] {
158
+ const out: string[] = [];
159
+
160
+ // Per tag, the most failing first (ADR-0077).
161
+ const tags = tagsByFailures(results);
162
+ if (tags.length > 0) {
163
+ out.push('by tag:');
164
+ const tagWidth = Math.max(...tags.map((group) => group.tag.length));
165
+ for (const group of tags) {
166
+ const statuses = CASE_STATUSES.flatMap((status) => {
167
+ const count = group.statuses[status];
168
+ return count === undefined ? [] : [`${status} ${String(count)}`];
169
+ });
170
+ out.push(
171
+ ` ${group.tag.padEnd(tagWidth)} ${counted(group.cases, 'case')}: ${statuses.join(', ')}` +
172
+ (group.passRate === undefined ? '' : `; ${passRateText(group.passRate)}`),
173
+ );
174
+ }
61
175
  }
62
176
 
63
177
  const observation = results.run.observation;
@@ -101,6 +215,49 @@ export function terminalSummary(results: Results): TerminalSummary {
101
215
  .join(', ')}`,
102
216
  );
103
217
  }
104
- for (const issue of results.run.issues ?? []) err.push(` run: ${issue}`);
105
- return { out, err };
218
+ const { strategy } = results.run;
219
+ if (strategy !== undefined) {
220
+ out.push(`strategy: ${strategy.name} (${counted(strategy.messages, 'message')})`);
221
+ }
222
+ // The attacker's strategy, its bounds, and the cases it adapted (ADR-0087, ADR-0088).
223
+ const { attacker } = results.run;
224
+ if (attacker !== undefined) {
225
+ out.push(
226
+ `attacker: ${attacker.strategy}, ${attackerBound(attacker)}, ${counted(attacker.cases, 'case')}`,
227
+ );
228
+ }
229
+ // The judge: its model, its dimensions, and its calibration (ADR-0090).
230
+ const { judge } = results.run;
231
+ if (judge !== undefined) {
232
+ const dimensions = judge.dimensions
233
+ .map(
234
+ (dimension) => `${dimension} (${judge.gated.includes(dimension) ? 'gating' : 'advisory'})`,
235
+ )
236
+ .join(', ');
237
+ const calibrated = `${String(judge.calibration.items - judge.calibration.misjudged.length)} of ${counted(judge.calibration.items, 'calibration item')} judged right`;
238
+ out.push(
239
+ `judge: ${judge.model ?? 'none'}, ${dimensions}; ${judge.unmeasured === undefined ? calibrated : `unmeasured: ${judge.unmeasured}`}`,
240
+ );
241
+ }
242
+ out.push(...frameworkLines(results));
243
+ return out;
244
+ }
245
+
246
+ export function terminalSummary(results: Results): TerminalSummary {
247
+ const [first = '', ...more] = countLines(results);
248
+ const rows = caseRows(results);
249
+ const statusWidth = Math.max(0, ...rows.map(([status]) => status.length));
250
+ const idWidth = Math.max(0, ...rows.map(([, id]) => id.length));
251
+ return {
252
+ out: [
253
+ first,
254
+ ...more.map((line) => ` ${line}`),
255
+ ...rows.map(
256
+ ([status, id, reason]) =>
257
+ ` ${status.padEnd(statusWidth)} ${id.padEnd(idWidth)} ${reason}`,
258
+ ),
259
+ ...noteLines(results),
260
+ ],
261
+ err: errorLines(results).map((line) => ` ${line}`),
262
+ };
106
263
  }