screw-bugs 0.0.0-stage → 0.1.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 (125) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +906 -2
  3. package/bin/screw-bugs.js +29 -0
  4. package/dist/browser-playwright/annotate.d.ts +9 -0
  5. package/dist/browser-playwright/annotate.js +86 -0
  6. package/dist/browser-playwright/capture.d.ts +232 -0
  7. package/dist/browser-playwright/capture.js +1049 -0
  8. package/dist/browser-playwright/frames.d.ts +77 -0
  9. package/dist/browser-playwright/frames.js +191 -0
  10. package/dist/browser-playwright/index.d.ts +2 -0
  11. package/dist/browser-playwright/index.js +2 -0
  12. package/dist/browser-playwright/input.d.ts +44 -0
  13. package/dist/browser-playwright/input.js +116 -0
  14. package/dist/browser-playwright/launch.d.ts +21 -0
  15. package/dist/browser-playwright/launch.js +86 -0
  16. package/dist/browser-playwright/page.d.ts +387 -0
  17. package/dist/browser-playwright/page.js +1930 -0
  18. package/dist/build-info.json +5 -0
  19. package/dist/cli/app.d.ts +19 -0
  20. package/dist/cli/app.js +70 -0
  21. package/dist/cli/build-info.d.ts +52 -0
  22. package/dist/cli/build-info.js +82 -0
  23. package/dist/cli/commands.d.ts +14 -0
  24. package/dist/cli/commands.js +308 -0
  25. package/dist/cli/config.d.ts +16 -0
  26. package/dist/cli/config.js +71 -0
  27. package/dist/cli/doctor.d.ts +19 -0
  28. package/dist/cli/doctor.js +113 -0
  29. package/dist/cli/environment.d.ts +20 -0
  30. package/dist/cli/environment.js +34 -0
  31. package/dist/cli/exit-codes.d.ts +29 -0
  32. package/dist/cli/exit-codes.js +28 -0
  33. package/dist/cli/failure.d.ts +20 -0
  34. package/dist/cli/failure.js +15 -0
  35. package/dist/cli/index.d.ts +6 -0
  36. package/dist/cli/index.js +6 -0
  37. package/dist/cli/install-method.d.ts +96 -0
  38. package/dist/cli/install-method.js +148 -0
  39. package/dist/cli/main.d.ts +1 -0
  40. package/dist/cli/main.js +10 -0
  41. package/dist/cli/mcp.d.ts +30 -0
  42. package/dist/cli/mcp.js +309 -0
  43. package/dist/cli/node-version.d.ts +3 -0
  44. package/dist/cli/node-version.js +22 -0
  45. package/dist/cli/operations.d.ts +127 -0
  46. package/dist/cli/operations.js +337 -0
  47. package/dist/cli/package-info.d.ts +22 -0
  48. package/dist/cli/package-info.js +25 -0
  49. package/dist/cli/report-server.d.ts +170 -0
  50. package/dist/cli/report-server.js +387 -0
  51. package/dist/cli/signals.d.ts +37 -0
  52. package/dist/cli/signals.js +61 -0
  53. package/dist/cli/stamp-build.d.ts +1 -0
  54. package/dist/cli/stamp-build.js +9 -0
  55. package/dist/cli/update-check.d.ts +140 -0
  56. package/dist/cli/update-check.js +316 -0
  57. package/dist/cli/uploads.d.ts +16 -0
  58. package/dist/cli/uploads.js +80 -0
  59. package/dist/core/css.d.ts +95 -0
  60. package/dist/core/css.js +436 -0
  61. package/dist/core/engine.d.ts +65 -0
  62. package/dist/core/engine.js +436 -0
  63. package/dist/core/errors.d.ts +66 -0
  64. package/dist/core/errors.js +30 -0
  65. package/dist/core/evidence.d.ts +14 -0
  66. package/dist/core/evidence.js +127 -0
  67. package/dist/core/index.d.ts +12 -0
  68. package/dist/core/index.js +12 -0
  69. package/dist/core/labels.d.ts +47 -0
  70. package/dist/core/labels.js +199 -0
  71. package/dist/core/liveness.d.ts +45 -0
  72. package/dist/core/liveness.js +64 -0
  73. package/dist/core/marks.d.ts +63 -0
  74. package/dist/core/marks.js +410 -0
  75. package/dist/core/services.d.ts +444 -0
  76. package/dist/core/services.js +22 -0
  77. package/dist/core/steps.d.ts +96 -0
  78. package/dist/core/steps.js +656 -0
  79. package/dist/core/uploads.d.ts +49 -0
  80. package/dist/core/uploads.js +133 -0
  81. package/dist/core/video.d.ts +16 -0
  82. package/dist/core/video.js +101 -0
  83. package/dist/core/viewport.d.ts +28 -0
  84. package/dist/core/viewport.js +50 -0
  85. package/dist/report/html.d.ts +37 -0
  86. package/dist/report/html.js +762 -0
  87. package/dist/report/index.d.ts +5 -0
  88. package/dist/report/index.js +5 -0
  89. package/dist/report/markup.d.ts +27 -0
  90. package/dist/report/markup.js +75 -0
  91. package/dist/report/pr-summary.d.ts +11 -0
  92. package/dist/report/pr-summary.js +110 -0
  93. package/dist/report/sha256.d.ts +9 -0
  94. package/dist/report/sha256.js +97 -0
  95. package/dist/report/styles.d.ts +1 -0
  96. package/dist/report/styles.js +328 -0
  97. package/dist/report/view.d.ts +141 -0
  98. package/dist/report/view.js +368 -0
  99. package/dist/report/walkthrough.d.ts +75 -0
  100. package/dist/report/walkthrough.js +458 -0
  101. package/dist/schema/config.d.ts +7 -0
  102. package/dist/schema/config.js +6 -0
  103. package/dist/schema/doctor.d.ts +46 -0
  104. package/dist/schema/doctor.js +23 -0
  105. package/dist/schema/evidence.d.ts +994 -0
  106. package/dist/schema/evidence.js +521 -0
  107. package/dist/schema/findings.d.ts +159 -0
  108. package/dist/schema/findings.js +80 -0
  109. package/dist/schema/index.d.ts +7 -0
  110. package/dist/schema/index.js +7 -0
  111. package/dist/schema/job.d.ts +1724 -0
  112. package/dist/schema/job.js +505 -0
  113. package/dist/schema/ledger.d.ts +951 -0
  114. package/dist/schema/ledger.js +193 -0
  115. package/dist/schema/status.d.ts +7 -0
  116. package/dist/schema/status.js +11 -0
  117. package/dist/store-local/accounts.d.ts +7 -0
  118. package/dist/store-local/accounts.js +9 -0
  119. package/dist/store-local/index.d.ts +3 -0
  120. package/dist/store-local/index.js +3 -0
  121. package/dist/store-local/paths.d.ts +10 -0
  122. package/dist/store-local/paths.js +17 -0
  123. package/dist/store-local/storage.d.ts +20 -0
  124. package/dist/store-local/storage.js +170 -0
  125. package/package.json +73 -4
@@ -0,0 +1,368 @@
1
+ import { DateTime, Duration, Option } from 'effect';
2
+ import { clipBox, drawableAction, drawableShot, MISMATCH_ALLOWED, withStartPage, } from '../core/index.js';
3
+ import { casesOf, framesOf, baseName, customTimeoutOf, uploadFileOf, } from '../schema/index.js';
4
+ /* What both reports show, worked out once. Plain data: escaping is each format's job. */
5
+ export const statuses = ['passed', 'failed', 'blocked', 'not_verified'];
6
+ export const statusLabel = {
7
+ passed: 'Passed',
8
+ failed: 'Failed',
9
+ blocked: 'Blocked',
10
+ not_verified: 'Not verified',
11
+ };
12
+ export const countsOf = (cases) => {
13
+ const counts = { passed: 0, failed: 0, blocked: 0, not_verified: 0 };
14
+ for (const c of cases)
15
+ counts[c.status]++;
16
+ return counts;
17
+ };
18
+ const t = (text) => ({ kind: 'text', text });
19
+ const v = (text) => ({ kind: 'value', text });
20
+ const c = (text) => ({ kind: 'code', text });
21
+ const elementParts = (target) => {
22
+ if (target.role !== undefined)
23
+ return target.name === undefined
24
+ ? [t(`the ${target.role}`)]
25
+ : [t(`${target.role} `), v(target.name)];
26
+ if (target.text !== undefined)
27
+ return [t('text '), v(target.text)];
28
+ if (target.label !== undefined)
29
+ return [t('the field labelled '), v(target.label)];
30
+ if (target.alt !== undefined)
31
+ return [t('the image '), v(target.alt)];
32
+ return [t('the element matching '), c(target.css ?? '')];
33
+ };
34
+ /** Where it is, innermost frame first, such as ` in the frame iframe.preview`. */
35
+ const frameParts = (frame) => framesOf(frame)
36
+ .toReversed()
37
+ .flatMap((f) => f.role !== undefined
38
+ ? [t(` in the frame ${f.role}`), ...(f.name !== undefined ? [t(' '), v(f.name)] : [])]
39
+ : f.text !== undefined
40
+ ? [t(' in the frame with text '), v(f.text)]
41
+ : f.label !== undefined
42
+ ? [t(' in the frame labelled '), v(f.label)]
43
+ : f.alt !== undefined
44
+ ? [t(' in the frame with alt text '), v(f.alt)]
45
+ : [t(' in the frame '), c(f.css ?? '')]);
46
+ const targetParts = (target) => [
47
+ ...elementParts(target),
48
+ ...frameParts(target.frame),
49
+ ];
50
+ const waitStateParts = {
51
+ visible: ' to be visible',
52
+ hidden: ' to be hidden',
53
+ attached: ' to be in the page',
54
+ detached: ' to be gone from the page',
55
+ };
56
+ /** A step as a sentence, such as Click button “Sign up”. */
57
+ export const stepParts = (step) => {
58
+ switch (step.action) {
59
+ case 'goto':
60
+ return [t('Go to '), c(step.url)];
61
+ case 'reload':
62
+ return [t('Reload the page')];
63
+ case 'click':
64
+ return [t('Click '), ...targetParts(step.target)];
65
+ case 'fill':
66
+ return step.value === ''
67
+ ? [t('Clear '), ...targetParts(step.target)]
68
+ : [t('Fill '), ...targetParts(step.target), t(' with '), v(step.value)];
69
+ case 'upload':
70
+ return [
71
+ t('Upload '),
72
+ v(step.files.map((file) => baseName(uploadFileOf(file).path)).join(', ')),
73
+ t(' to '),
74
+ ...targetParts(step.target),
75
+ ];
76
+ case 'press':
77
+ return [t('Press '), c(step.key)];
78
+ case 'expectText':
79
+ return [t('Expect the text '), v(step.text), t(' to appear'), ...frameParts(step.frame)];
80
+ case 'expectNoText':
81
+ return [
82
+ t('Expect the text '),
83
+ v(step.text),
84
+ t(' not to show'),
85
+ ...(step.target !== undefined
86
+ ? [t(' in '), ...targetParts(step.target)]
87
+ : frameParts(step.frame)),
88
+ ];
89
+ case 'waitFor':
90
+ return [
91
+ t('Wait for '),
92
+ ...targetParts(step.target),
93
+ t(waitStateParts[step.state ?? 'visible']),
94
+ ];
95
+ case 'scroll':
96
+ if (step.target !== undefined)
97
+ return [t('Scroll to '), ...targetParts(step.target)];
98
+ if (step.to !== undefined)
99
+ return step.frame === undefined
100
+ ? [t(`Scroll to the ${step.to} of the page`)]
101
+ : [t(`Scroll to the ${step.to}`), ...frameParts(step.frame)];
102
+ return [
103
+ t(`Scroll ${(step.by ?? 0) < 0 ? 'up' : 'down'} ${Math.abs(step.by ?? 0)} px`),
104
+ ...frameParts(step.frame),
105
+ ];
106
+ case 'expectUrl':
107
+ return [t('Expect the URL to contain '), c(step.includes)];
108
+ case 'expectLink':
109
+ return [
110
+ t('Expect '),
111
+ ...targetParts(step.target),
112
+ t(step.match === 'exact' ? ' to link to exactly ' : ' to link to an address with '),
113
+ c(step.href),
114
+ ];
115
+ case 'screenshot':
116
+ return [t('Take a screenshot '), v(step.name)];
117
+ }
118
+ };
119
+ export const stepText = (step) => stepParts(step)
120
+ .map((p) => p.text)
121
+ .join('');
122
+ /** A step's own `timeoutMs` in words, when it is not the default, such as `waited up to 120 s`. */
123
+ export const waitNote = (step, ran) => {
124
+ const ms = customTimeoutOf(step);
125
+ return ms === undefined ? undefined : `${ran ? 'waited' : 'waits'} up to ${ms / 1000} s`;
126
+ };
127
+ /**
128
+ * The files an upload step sends, each with its size once it ran and what the job says it is.
129
+ * `sizes` come from the ledger (`StepTiming.files`), by file name.
130
+ */
131
+ export const uploadNotes = (step, sizes = []) => step.action !== 'upload'
132
+ ? []
133
+ : step.files.map((file) => {
134
+ const { path, about, allowMismatch } = uploadFileOf(file);
135
+ const name = baseName(path);
136
+ const size = sizes.find((s) => s.name === name)?.size;
137
+ return {
138
+ name,
139
+ ...(size !== undefined ? { size } : {}),
140
+ ...(about?.trim() ? { about } : {}),
141
+ ...(allowMismatch === true ? { note: MISMATCH_ALLOWED } : {}),
142
+ };
143
+ });
144
+ /** A file size as people read it: `840 B`, `12 KB`, `3.4 MB`. */
145
+ export const formatBytes = (bytes) => bytes < 1024
146
+ ? `${bytes} B`
147
+ : bytes < 1024 * 1024
148
+ ? `${Math.round(bytes / 1024)} KB`
149
+ : `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
150
+ const stateOf = (entry, index) => {
151
+ switch (entry.status) {
152
+ case 'passed':
153
+ return 'done';
154
+ case 'not_verified':
155
+ return 'not-run';
156
+ default:
157
+ if (entry.step === undefined)
158
+ return 'unknown';
159
+ return index < entry.step ? 'done' : index === entry.step ? 'decided' : 'not-run';
160
+ }
161
+ };
162
+ /**
163
+ * `evidence/01/04-step3-failed.png`; in older runs `evidence/<case>/step3-failed.png` or
164
+ * `evidence/<case>-step3-failed.png`. The last such file is the one taken when the case stopped.
165
+ */
166
+ const isFailureShot = (entry, path) => (entry.status === 'failed' || entry.status === 'blocked') &&
167
+ entry.step !== undefined &&
168
+ [`/step${entry.step}-${entry.status}.png`, `-step${entry.step}-${entry.status}.png`].some((ending) => path.endsWith(ending));
169
+ /** The video of `entry`'s session, if the run had sessions. */
170
+ export const videoOf = (bundle, entry) => {
171
+ const session = bundle.ledger.sessions?.find((s) => s.number === (entry.session ?? 1));
172
+ if (session === undefined)
173
+ return undefined;
174
+ return {
175
+ session,
176
+ path: session.video,
177
+ problem: session.videoProblem ??
178
+ (session.video === undefined
179
+ ? session.endedAt === undefined
180
+ ? 'The session did not end, so its video was not checked.'
181
+ : 'The video file was not saved.'
182
+ : undefined),
183
+ };
184
+ };
185
+ /**
186
+ * A case's record with only the boxes that can be drawn where they show on a run on `device`:
187
+ * older runs on a phone measured them in the page's layout (see `boxesDrawable`).
188
+ */
189
+ const drawableEntry = (entry, device) => ({
190
+ ...entry,
191
+ ...(entry.shots !== undefined
192
+ ? { shots: entry.shots.map((shot) => drawableShot(shot, device)) }
193
+ : {}),
194
+ ...(entry.steps !== undefined
195
+ ? {
196
+ steps: entry.steps.map((timing) => timing.action === undefined
197
+ ? timing
198
+ : { ...timing, action: drawableAction(timing.action, device) }),
199
+ }
200
+ : {}),
201
+ });
202
+ export const caseViews = (bundle) => {
203
+ const specs = new Map(casesOf(bundle.spec).map((spec) => [spec.id, spec]));
204
+ const written = new Map((bundle.findings?.cases ?? []).map((c) => [c.id, c]));
205
+ return bundle.ledger.cases.map((recorded) => {
206
+ const entry = drawableEntry(recorded, bundle.device.kind);
207
+ const spec = specs.get(entry.id);
208
+ const steps = spec ? withStartPage(spec, bundle.spec.url) : [];
209
+ const offset = spec ? steps.length - spec.steps.length : 0;
210
+ const records = new Map((entry.shots ?? []).map((shot) => [shot.path, shot]));
211
+ const timings = new Map((entry.steps ?? []).map((timing) => [timing.index, timing]));
212
+ const shots = entry.evidence.map((path) => {
213
+ const shot = records.get(path);
214
+ return {
215
+ path,
216
+ shot,
217
+ marks: (shot && bundle.marks?.[shot.id]) ?? [],
218
+ elements: (shot && bundle.elements?.[shot.id]) ?? [],
219
+ };
220
+ });
221
+ const failurePath = entry.evidence.findLast((path) => records.get(path)?.kind === 'failure' || isFailureShot(entry, path));
222
+ return {
223
+ entry,
224
+ spec,
225
+ steps: steps.map((step, i) => ({
226
+ index: i + 1 - offset,
227
+ step,
228
+ implicit: i < offset,
229
+ state: stateOf(entry, i + 1 - offset),
230
+ timing: timings.get(i + 1 - offset),
231
+ })),
232
+ failureShot: shots.find((s) => s.path === failurePath),
233
+ otherShots: shots.filter((s) => s.path !== failurePath),
234
+ findings: written.get(entry.id),
235
+ video: videoOf(bundle, entry),
236
+ };
237
+ });
238
+ };
239
+ /**
240
+ * `3 areas not tested`, when the agent's write-up names any: next to the counts, so passing cases
241
+ * are not read as everything working.
242
+ */
243
+ export const notTestedCount = (bundle) => {
244
+ const n = bundle.findings?.notTested?.length ?? 0;
245
+ return n === 0 ? undefined : `${n} ${n === 1 ? 'area' : 'areas'} not tested`;
246
+ };
247
+ const severityRank = { high: 0, medium: 1, low: 2 };
248
+ /** The agent's fixes, most severe first; the agent's own order within a severity. */
249
+ export const fixesOf = (bundle) => (bundle.findings?.fixes ?? []).toSorted((a, b) => severityRank[a.severity] - severityRank[b.severity]);
250
+ export const severityLabel = {
251
+ high: 'High',
252
+ medium: 'Medium',
253
+ low: 'Low',
254
+ };
255
+ /**
256
+ * `0:07.3`, `1:05.0`, `1:02:03.4`: a timecode as people read it, from ms, to the nearest tenth of
257
+ * a second (so 59.96 s is `1:00.0`).
258
+ */
259
+ export const formatTimecode = (ms) => {
260
+ const tenths = Math.max(0, Math.round(ms / 100));
261
+ const total = Math.floor(tenths / 10);
262
+ const [h, m, s] = [Math.floor(total / 3600), Math.floor((total % 3600) / 60), total % 60];
263
+ const seconds = `${pad(s)}.${tenths % 10}`;
264
+ return h > 0 ? `${h}:${pad(m)}:${seconds}` : `${m}:${seconds}`;
265
+ };
266
+ /** A time to seek to, for a media fragment (`#t=6.25`) and the page's script: seconds, to the ms. */
267
+ export const fragmentSeconds = (ms) => String(Math.max(0, Math.round(ms)) / 1000);
268
+ /** The room kept around the boxes at `frame`, in CSS pixels: beside them, and above and below
269
+ * them for a label (its height, the gap and the box's line). */
270
+ const ROOM_SIDE = 12;
271
+ const ROOM_LABEL = 34;
272
+ /** How far a crop zooms in on boxes that are readable without more: it keeps their surroundings. */
273
+ const ZOOM = 2.5;
274
+ /**
275
+ * The part of a `width` × `height` screenshot a frame shows, zoomed in on `boxes`: all of them
276
+ * with room around (for their lines and labels), at least a `1 / maxZoom` share of the image's
277
+ * width, in the image's shape but no taller than `minShape` (so a full-page screenshot gives a
278
+ * strip of the page). Undefined when there are no boxes or the part would be most of the image.
279
+ */
280
+ export const cropAround = (width, height, boxes, { frame, maxZoom, readable, minShape } = { frame: 300, maxZoom: 2.5, minShape: 1.6 }) => {
281
+ if (boxes.length === 0 || width <= 0 || height <= 0)
282
+ return undefined;
283
+ const shown = boxes.flatMap((b) => {
284
+ const x = Math.max(0, b.x);
285
+ const y = Math.max(0, b.y);
286
+ const w = Math.min(width, b.x + b.width) - x;
287
+ const h = Math.min(height, b.y + b.height) - y;
288
+ return w > 0 && h > 0 ? [{ box: { x, y, width: w, height: h }, content: b.content }] : [];
289
+ });
290
+ if (shown.length === 0)
291
+ return undefined;
292
+ // Rooms as shares of the crop's width, as they are CSS pixels at `frame`.
293
+ const [side, label] = [ROOM_SIDE / frame, ROOM_LABEL / frame];
294
+ // The widest crop at which the shortest box is still `readable` tall; a box wider than fits in
295
+ // it with its room is cut to that width around the middle of its content, kept inside it.
296
+ const legible = readable === undefined
297
+ ? Infinity
298
+ : (frame * Math.min(...shown.map(({ box }) => box.height))) / readable;
299
+ const cap = legible * (1 - 2 * side);
300
+ const spans = shown.map(({ box, content }) => {
301
+ const end = box.x + box.width;
302
+ const inside = content && clipBox(content, box);
303
+ if (box.width <= cap || inside === undefined || inside.width <= 0)
304
+ return [box.x, end];
305
+ const at = Math.min(Math.max(box.x, inside.x + inside.width / 2 - cap / 2), end - cap);
306
+ return [at, at + cap];
307
+ });
308
+ const left = Math.min(...spans.map(([start]) => start));
309
+ const right = Math.max(...spans.map(([, end]) => end));
310
+ const top = Math.min(...shown.map(({ box }) => box.y));
311
+ const bottom = Math.max(...shown.map(({ box }) => box.y + box.height));
312
+ const shape = Math.max(width / height, minShape);
313
+ const least = Math.max(width / maxZoom, Math.min(legible, width / ZOOM));
314
+ let w = Math.min(width, Math.max(least, (right - left) / (1 - 2 * side)));
315
+ let h = w / shape;
316
+ if (h < bottom - top + 2 * label * w) {
317
+ // Taller boxes: as tall as they need with their rooms, and as wide as that shape gives.
318
+ w = Math.min(width, Math.max(w, (shape * (bottom - top)) / Math.max(0.2, 1 - 2 * label * shape)));
319
+ h = Math.max(w / shape, bottom - top + 2 * label * w);
320
+ }
321
+ [w, h] = [Math.round(w), Math.round(Math.min(height, h))];
322
+ if (w >= width * 0.9 && h >= height * 0.9)
323
+ return undefined;
324
+ const clamp = (at, size, of) => Math.round(Math.min(Math.max(0, at), of - size));
325
+ return {
326
+ x: clamp((left + right) / 2 - w / 2, w, width),
327
+ y: clamp((top + bottom) / 2 - h / 2, h, height),
328
+ width: w,
329
+ height: h,
330
+ };
331
+ };
332
+ /**
333
+ * How far a frame zooms in on its boxes: as wide as the case or wider, and on a narrow screen (or
334
+ * in the grid of thumbnails), where it zooms in more so the marked element stays readable. A
335
+ * figure whose two crops differ has a frame for each, and its width picks one; `CROP_NARROW.frame`
336
+ * is also the narrowest a frame is shown.
337
+ */
338
+ export const CROP_WIDE = { frame: 560, maxZoom: 2.5, readable: 12, minShape: 1.6 };
339
+ export const CROP_NARROW = { frame: 250, maxZoom: 6, readable: 16, minShape: 1.2 };
340
+ const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
341
+ const pad = (n) => String(n).padStart(2, '0');
342
+ /** A timestamp from the ledger, parsed; the clock is never read here. */
343
+ const parse = (iso) => DateTime.make(iso).pipe(Option.map(DateTime.toUtc));
344
+ /** `29 Oct 2026, 10:48:57 UTC`: the same for every reader, wherever the report is opened. */
345
+ export const formatTime = (iso) => Option.match(parse(iso), {
346
+ onNone: () => iso,
347
+ onSome: (time) => {
348
+ const { day, month, year, hour, minute, second } = DateTime.toPartsUtc(time);
349
+ return `${day} ${months[month - 1]} ${year}, ${pad(hour)}:${pad(minute)}:${pad(second)} UTC`;
350
+ },
351
+ });
352
+ /** `850 ms`, `4.2 s`, `3 min 05 s`; undefined while the run has not finished. */
353
+ export const durationOf = (startedAt, finishedAt) => {
354
+ if (finishedAt === undefined)
355
+ return undefined;
356
+ const [start, end] = [parse(startedAt), parse(finishedAt)];
357
+ if (Option.isNone(start) || Option.isNone(end))
358
+ return undefined;
359
+ const ms = Duration.toMillis(DateTime.distance(start.value, end.value));
360
+ if (ms < 0)
361
+ return undefined;
362
+ if (ms < 1000)
363
+ return `${ms} ms`;
364
+ if (ms < 60_000)
365
+ return `${(ms / 1000).toFixed(1)} s`;
366
+ const seconds = Math.round(ms / 1000);
367
+ return `${Math.floor(seconds / 60)} min ${pad(seconds % 60)} s`;
368
+ };
@@ -0,0 +1,75 @@
1
+ import { type CaseEntry, type ReportBundle, type Step, type StepAction } from '../schema/index.js';
2
+ import { type StepView } from './view.js';
3
+ /**
4
+ * How long around the moment a step's element was measured its box is drawn over the video, in
5
+ * ms: a little before (the element was already there while the step waited on it) and after.
6
+ * Outside this the page may have moved on, so no box is drawn.
7
+ */
8
+ export declare const BOX_BEFORE_MS = 700;
9
+ export declare const BOX_AFTER_MS = 1200;
10
+ /** Seconds the cursor takes, at most, to glide to the next point the mouse pressed. */
11
+ export declare const GLIDE_S = 0.6;
12
+ /**
13
+ * The page's one script, allowed by its hash in the Content Security Policy. It sets the theme as
14
+ * the report does. With a player, it marks the step playing now (the last step of the video's
15
+ * session whose time is at or before the player's), keeps it in view in the script (without
16
+ * motion when the reader prefers less), draws the box of the element it acted on over the video
17
+ * while that was measured, makes timecodes seek (and switch session videos) instead of opening
18
+ * the file, and goes on to the next session's video when one ends. A session video that does not
19
+ * load is remembered as broken on its own: the note takes the player's place, naming that file,
20
+ * while timecodes of the other sessions still load and play theirs (and bring the player back);
21
+ * moving on skips broken ones. Without script, timecodes open the video file at their time, and
22
+ * every step reads in full contrast.
23
+ *
24
+ * Over the video it also draws, from each step's recorded action (`stepAction`) and only for the
25
+ * session playing, what the mouse and keyboard did: a cursor that shows from the first point the
26
+ * mouse pressed, glides to each next one (eased, over at most `GLIDE_S` before it) and rests there, a ripple where and when it
27
+ * pressed, a ring in place of the step's box around a field typed into (when that box shows: a
28
+ * fill records no time or element of its own), and a short
29
+ * label of the action (the latest one that happened, else the one the cursor is gliding to; the
30
+ * box's own label gives way to it; one whose time was not recorded is labelled while its step
31
+ * plays, and has no cursor or ripple). All of
32
+ * it follows the player's time, so seeking or pausing shows the state at that moment. With less
33
+ * motion preferred, the cursor jumps instead of gliding and there is no ripple. A "Show cursor"
34
+ * switch turns it off, remembered like the theme. Nothing is added to the page under test or to
35
+ * the video.
36
+ */
37
+ export declare const WALKTHROUGH_SCRIPT = "(()=>{const d=document,r=d.documentElement,k='screw-bugs-theme';const set=m=>{r.dataset.theme=m;d.querySelectorAll('[data-theme-set]').forEach(b=>b.setAttribute('aria-pressed',String(b.dataset.themeSet===m)))};let m='system';try{m=localStorage.getItem(k)||m}catch(e){}r.dataset.theme=m;const still=()=>matchMedia('(prefers-reduced-motion: reduce)').matches;d.addEventListener('DOMContentLoaded',()=>{set(r.dataset.theme);const th=d.getElementById('theme');if(th)th.hidden=false;d.addEventListener('click',e=>{const b=e.target.closest('[data-theme-set]');if(!b)return;set(b.dataset.themeSet);try{localStorage.setItem(k,b.dataset.themeSet)}catch(e){}});const v=d.getElementById('wt-video');if(!v)return;const w=d.querySelector('.wt'),fig=v.closest('.wt-player'),panel=d.getElementById('wt-script'),box=d.getElementById('wt-box'),note=d.getElementById('wt-unloaded');const srcs=new Map([...d.querySelectorAll('[data-session-src]')].map(e=>[e.dataset.session,e.dataset.sessionSrc]));const order=[...srcs.keys()];const steps=[...d.querySelectorAll('.wt-step[data-t]')];const dead=new Set();let cur=v.dataset.session,on=null,down=null,ask=0,auto=false;w.classList.add('live');const hide=()=>{box.hidden=true};const show=s=>{down=s;v.pause();hide();update();w.classList.remove('live');fig.classList.add('broken');if(note){note.hidden=false;const a=note.querySelector('a');if(a){a.href=srcs.get(s);a.textContent=srcs.get(s)}}};const fine=()=>{if(down===null)return;down=null;fig.classList.remove('broken');w.classList.add('live');if(note)note.hidden=true};const next=s=>order.slice(order.indexOf(s)+1).find(n=>!dead.has(n));const geo=()=>{const vw=v.videoWidth,vh=v.videoHeight,cw=v.clientWidth,ch=v.clientHeight;if(!vw||!vh||!cw||!ch)return null;const s=Math.min(cw/vw,ch/vh);return{x:v.offsetLeft+(cw-vw*s)/2,y:v.offsetTop+(ch-vh*s)/2,w:vw*s,h:vh*s}};const put=(e,x,y,w,h)=>{e.style.left=x+'px';e.style.top=y+'px';if(w!==undefined){e.style.width=w+'px';e.style.height=h+'px'}};const draw=(t,g)=>{if(down!==null||!g||!on||!on.dataset.box||t<Number(on.dataset.b0)||t>Number(on.dataset.b1))return hide();const [x,y,bw,bh]=on.dataset.box.split(' ').map(Number);put(box,g.x+x*g.w,g.y+y*g.h,bw*g.w,bh*g.h);box.querySelector('span').textContent=on.dataset.label||'';box.hidden=false};const C=d.getElementById('wt-cursor'),R=d.getElementById('wt-ripple'),G=d.getElementById('wt-ring'),L=d.getElementById('wt-act'),T=d.getElementById('wt-cursor-on'),ck='screw-bugs-cursor';const nums=x=>x?x.split(' ').map(Number):null;const acts=[...d.querySelectorAll('.wt-step[data-act][data-s]')].map(e=>({s:e.dataset.s,at:e.dataset.at?Number(e.dataset.at):NaN,t0:Number(e.dataset.t),t1:Number(e.dataset.a1),b0:Number(e.dataset.b0),b1:Number(e.dataset.b1),k:e.dataset.act,p:nums(e.dataset.pt),b:nums(e.dataset.tb),l:e.dataset.al||''})).sort((a,b)=>(a.at>=0?a.at:a.t0)-(b.at>=0?b.at:b.t0));let fon=true;try{fon=localStorage.getItem(ck)!=='off'}catch(e){}const fx=(t,g)=>{C.hidden=R.hidden=G.hidden=L.hidden=true;box.querySelector('span').hidden=false;if(!fon||down!==null||!g)return;const m=still(),mine=acts.filter(a=>a.s===cur),ptr=mine.filter(a=>a.p),xy=p=>[g.x+p[0]*g.w,g.y+p[1]*g.h];let i=-1;ptr.forEach((a,j)=>{if(a.at<=t)i=j});const a=ptr[i],n=ptr[i+1];let c=a?a.p:null;if(n&&a){const w=Math.min(0.6,a?n.at-a.at:0.6),q=w>0?(t-n.at+w)/w:1;if(q>=0){const e=q<.5?4*q*q*q:1-Math.pow(2-2*q,3)/2;c=!m&&q<1?[a.p[0]+(n.p[0]-a.p[0])*e,a.p[1]+(n.p[1]-a.p[1])*e]:n.p}}if(c){const [x,y]=xy(c);put(C,x-3,y-2);C.hidden=false}if(a&&!m&&t-a.at<.6){const q=(t-a.at)/.6,[x,y]=xy(a.p);put(R,x,y);R.style.transform='translate(-50%,-50%) scale('+(.35+q*1.3)+')';R.style.opacity=String(1-q);R.hidden=false}let f=null,l=null,u=null;for(const a of mine){if(a.k==='fill'&&a.b&&t>=a.b0&&t<=a.b1)f=a;if(a.k==='fill'||!(a.at>=0)?t>=a.t0&&t<=a.t1:t>=a.at&&t<=a.at+1.5)l=a;else if(!u&&a.p&&a.at>t&&a.at-t<=0.6)u=a}l=l||u;if(f){const [x,y]=xy(f.b);put(G,x,y,f.b[2]*g.w,f.b[3]*g.h);G.hidden=false;box.hidden=true}if(l&&l.l){L.textContent=l.l;L.hidden=false;let x=g.x+10,y=g.y+10;if(l.p){[x,y]=xy(l.p);x+=14;y+=20}else if(l.b){[x,y]=xy(l.b);y+=l.b[3]*g.h+10}if(y+L.offsetHeight>g.y+g.h-4)y=l.b?g.y+l.b[1]*g.h-L.offsetHeight-10:g.y+g.h-L.offsetHeight-4;put(L,Math.max(g.x+4,Math.min(x,g.x+g.w-L.offsetWidth-4)),Math.max(g.y+4,y))}box.querySelector('span').hidden=!L.hidden};if(T&&acts.length){T.checked=fon;T.closest('label').hidden=false;T.addEventListener('change',()=>{fon=T.checked;try{localStorage.setItem(ck,fon?'on':'off')}catch(e){}update()})}const update=()=>{const t=v.currentTime;let a=null;for(const s of steps){if(s.dataset.s===cur&&Number(s.dataset.t)<=t+0.02)a=s}if(a!==on){if(on){on.classList.remove('on');on.removeAttribute('aria-current');on.closest('.wt-case').classList.remove('on')}on=a;if(a){a.classList.add('on');a.setAttribute('aria-current','step');a.closest('.wt-case').classList.add('on');const p=panel.getBoundingClientRect(),q=a.getBoundingClientRect();if(q.top<p.top||q.bottom>p.bottom)panel.scrollBy({top:q.top-p.top-p.height/3,behavior:still()?'auto':'smooth'})}}const g=geo();draw(t,g);fx(t,g)};let raf=0;const tick=()=>{update();raf=v.paused?0:requestAnimationFrame(tick)};['timeupdate','seeked','loadedmetadata','pause'].forEach(n=>v.addEventListener(n,update));v.addEventListener('play',()=>{if(!raf)raf=requestAnimationFrame(tick)});addEventListener('resize',update);const load=(s,t,play,a=false)=>{const my=++ask;auto=a;if(dead.has(s))return show(s);if(s!==cur||!v.currentSrc||v.error){cur=s;v.dataset.session=s;v.src=srcs.get(s);v.load()}const go=()=>{if(my!==ask)return;auto=false;fine();v.currentTime=t;update();if(play)v.play().catch(()=>{})};if(v.readyState>0)go();else v.addEventListener('loadedmetadata',go,{once:true})};const bad=()=>{if(!v.error)return;dead.add(cur);const n=auto?next(cur):undefined;if(n!==undefined)return load(n,0,true,true);auto=false;show(cur)};v.addEventListener('error',bad);if(v.error)bad();v.addEventListener('ended',()=>{const n=next(cur);if(n!==undefined)load(n,0,true,true)});d.addEventListener('click',e=>{const a=e.target.closest('a[data-t]');if(!a||!srcs.has(a.dataset.s))return;e.preventDefault();if(fig.getBoundingClientRect().bottom<0)fig.scrollIntoView({block:'start',behavior:still()?'auto':'smooth'});load(a.dataset.s,Number(a.dataset.t),true)})})})();";
38
+ /** As the report's: nothing from the network, the video by relative path, one script by hash. */
39
+ export declare const WALKTHROUGH_CSP: string;
40
+ /**
41
+ * Where the element a step acted on was in the video, as shares of the frame, and when to draw
42
+ * it. Only from the viewport screenshot taken at the step (which is what the video shows), and
43
+ * only when its element was measured on it, and when (`targetAtMs`): the element Playwright
44
+ * acted on, located the same way. Never for a full-page screenshot, which the video does not show.
45
+ */
46
+ export declare const stepBox: (entry: CaseEntry, step: StepView) => {
47
+ readonly box: string;
48
+ readonly from: number;
49
+ readonly to: number;
50
+ } | undefined;
51
+ /** An action's label over the video is cut to this many characters. */
52
+ export declare const ACTION_LABEL_MAX = 48;
53
+ /**
54
+ * What a step did, in a few words for over the video, such as `Click "Save"`, `Type "Ada"` or
55
+ * `Press Enter`: the step's own wording (`stepParts`), with only the element's name or the value.
56
+ */
57
+ export declare const actionLabel: (step: Step) => string;
58
+ /**
59
+ * An action drawn over the video, as data on its step for the page's script: when it happened
60
+ * (`at`), and as shares of the viewport (which is what the video shows) where the mouse pressed
61
+ * (`pt`, `x y`) and the element (`tb`, `x y width height`). An action whose input was not seen
62
+ * has no time, and so no point: its label shows while its step plays. Nothing from older runs,
63
+ * which did not record actions.
64
+ */
65
+ export declare const stepAction: (action: StepAction | undefined) => {
66
+ readonly at?: string;
67
+ readonly pt?: string;
68
+ readonly tb?: string;
69
+ } | undefined;
70
+ /**
71
+ * The run's walkthrough as a self-contained page, written next to its `report.html`: inline CSS,
72
+ * one inline script, no fonts or network. Code decides everything on it; nothing from the agent's
73
+ * write-up is shown. Every piece of text from the job or the page is escaped.
74
+ */
75
+ export declare const renderWalkthrough: (bundle: ReportBundle) => string;