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,49 @@
1
+ /** How many bytes from the start of a file `contentMatches` looks at (text files are checked in it). */
2
+ export declare const UPLOAD_HEAD_BYTES: number;
3
+ /** How many bytes from the end: enough for a ZIP's end record with the longest comment. */
4
+ export declare const UPLOAD_TAIL_BYTES: number;
5
+ /** The start, the end and the size of a file, as `contentMatches` judges it. */
6
+ export interface FileSample {
7
+ readonly head: Uint8Array;
8
+ readonly tail: Uint8Array;
9
+ readonly size: number;
10
+ }
11
+ /** What a file should be, from its extension, such as `PDF`; `.xyz file` or `file` otherwise. */
12
+ export declare const uploadTypeOf: (path: string) => string;
13
+ /**
14
+ * Whether the content of a file fits its extension. Files of a type not checked (unknown or no
15
+ * extension) always do.
16
+ */
17
+ export declare const contentMatches: (path: string, sample: FileSample) => boolean;
18
+ /** Why a file given for an upload cannot be used. */
19
+ export type FileProblem = 'missing' | 'not_a_file' | 'empty' | 'too_big' | 'wrong_type' | 'outside_project' | 'unreadable';
20
+ /** A file a job needs before it can run, and why the one on disk (if any) does not do. */
21
+ export interface FileNeeded {
22
+ /** As the job gives it, relative to the project. */
23
+ readonly path: string;
24
+ /** What it should be, from its extension (`uploadTypeOf`). */
25
+ readonly type: string;
26
+ readonly about?: string;
27
+ /** The job skips its content check on purpose (see `UploadFile`). */
28
+ readonly allowMismatch?: boolean;
29
+ readonly problem: FileProblem;
30
+ /** `problem` in words, such as `not really a PDF`. */
31
+ readonly reason: string;
32
+ }
33
+ /** `problem` in a few plain words, for a file of type `type`. */
34
+ export declare const fileProblemText: (problem: FileProblem, details: {
35
+ readonly type: string;
36
+ readonly size?: number;
37
+ readonly error?: string;
38
+ }) => string;
39
+ /** A files-needed reply lists at most this many files. */
40
+ export declare const FILES_LISTED = 10;
41
+ /** What the files-needed reply and the report say of a file whose content check is skipped. */
42
+ export declare const MISMATCH_ALLOWED = "type check skipped on purpose";
43
+ /**
44
+ * The reply when upload files are missing or unusable, so nothing started: a sentence with the
45
+ * count, one line per file (path, type, why, and what it should hold, whole: `about` is at most
46
+ * `ABOUT_MAX` characters already), then one sentence telling the caller to create them with
47
+ * synthetic content and start again.
48
+ */
49
+ export declare const formatFilesNeeded: (files: ReadonlyArray<FileNeeded>) => string;
@@ -0,0 +1,133 @@
1
+ import { UPLOAD_MAX_BYTES } from '../schema/index.js';
2
+ /*
3
+ * Upload files are made by the caller, never by screw-bugs. Before a run starts, every file its
4
+ * upload steps give is checked against the disk; what is wrong with one is listed as a file
5
+ * needed (`FileNeeded`), so the caller's agent can create it and start the run again. The content
6
+ * check is by magic bytes, so a text file renamed to `.pdf` is caught, unless the job skips it on
7
+ * purpose for that file (`allowMismatch`), to test how a site handles an invalid file.
8
+ */
9
+ /** How many bytes from the start of a file `contentMatches` looks at (text files are checked in it). */
10
+ export const UPLOAD_HEAD_BYTES = 1024 * 1024;
11
+ /** How many bytes from the end: enough for a ZIP's end record with the longest comment. */
12
+ export const UPLOAD_TAIL_BYTES = 65_535 + 22;
13
+ const ascii = (text) => Array.from(text, (c) => c.charCodeAt(0));
14
+ const startsWith = (bytes, prefix, at = 0) => bytes.length >= at + prefix.length && prefix.every((b, i) => bytes[at + i] === b);
15
+ const includes = (bytes, needle) => {
16
+ for (let i = 0; i + needle.length <= bytes.length; i++)
17
+ if (startsWith(bytes, needle, i))
18
+ return true;
19
+ return false;
20
+ };
21
+ /**
22
+ * Valid UTF-8 without NUL bytes, as far as the head goes; a character cut at the end of the head
23
+ * is fine.
24
+ */
25
+ const isText = ({ head }) => {
26
+ if (head.includes(0))
27
+ return false;
28
+ try {
29
+ new TextDecoder('utf-8', { fatal: true }).decode(head, { stream: true });
30
+ return true;
31
+ }
32
+ catch {
33
+ return false;
34
+ }
35
+ };
36
+ const PDF_START = ascii('%PDF-');
37
+ const PDF_END = ascii('%%EOF');
38
+ const PNG_START = [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a];
39
+ const PNG_END = ascii('IEND');
40
+ const ZIP_START = [0x50, 0x4b, 0x03, 0x04];
41
+ const ZIP_END = [0x50, 0x4b, 0x05, 0x06];
42
+ /** A ZIP archive (as Office files are): a local file header first, an end record last. */
43
+ const isZip = ({ head, tail }) => startsWith(head, ZIP_START) && includes(tail, ZIP_END);
44
+ const kinds = {
45
+ pdf: {
46
+ name: 'PDF',
47
+ // Readers accept a PDF whose end marker is within its last kilobyte.
48
+ matches: ({ head, tail }) => startsWith(head, PDF_START) && includes(tail.slice(-1024), PDF_END),
49
+ },
50
+ png: {
51
+ name: 'PNG image',
52
+ matches: ({ head, tail }) => startsWith(head, PNG_START) && includes(tail.slice(-12), PNG_END),
53
+ },
54
+ jpg: { name: 'JPEG image', matches: ({ head }) => startsWith(head, [0xff, 0xd8, 0xff]) },
55
+ jpeg: { name: 'JPEG image', matches: ({ head }) => startsWith(head, [0xff, 0xd8, 0xff]) },
56
+ gif: {
57
+ name: 'GIF image',
58
+ matches: ({ head }) => startsWith(head, ascii('GIF87a')) || startsWith(head, ascii('GIF89a')),
59
+ },
60
+ webp: {
61
+ name: 'WebP image',
62
+ matches: ({ head }) => startsWith(head, ascii('RIFF')) && startsWith(head, ascii('WEBP'), 8),
63
+ },
64
+ docx: { name: 'Word document', matches: isZip },
65
+ pptx: { name: 'PowerPoint presentation', matches: isZip },
66
+ xlsx: { name: 'Excel workbook', matches: isZip },
67
+ txt: { name: 'text file', matches: isText },
68
+ csv: { name: 'CSV file', matches: isText },
69
+ json: { name: 'JSON file', matches: isText },
70
+ md: { name: 'Markdown file', matches: isText },
71
+ };
72
+ const extensionOf = (path) => {
73
+ const name = path.split(/[\\/]/).at(-1) ?? path;
74
+ const dot = name.lastIndexOf('.');
75
+ return dot <= 0 ? '' : name.slice(dot + 1).toLowerCase();
76
+ };
77
+ /** What a file should be, from its extension, such as `PDF`; `.xyz file` or `file` otherwise. */
78
+ export const uploadTypeOf = (path) => {
79
+ const extension = extensionOf(path);
80
+ return kinds[extension]?.name ?? (extension ? `.${extension} file` : 'file');
81
+ };
82
+ /**
83
+ * Whether the content of a file fits its extension. Files of a type not checked (unknown or no
84
+ * extension) always do.
85
+ */
86
+ export const contentMatches = (path, sample) => kinds[extensionOf(path)]?.matches(sample) ?? true;
87
+ const MB = 1024 * 1024;
88
+ /** Rounded up, so a file just over the limit never reads as exactly the limit. */
89
+ const megabytes = (bytes) => `${(Math.ceil((bytes / MB) * 10) / 10).toFixed(1)} MB`;
90
+ /** `problem` in a few plain words, for a file of type `type`. */
91
+ export const fileProblemText = (problem, details) => {
92
+ switch (problem) {
93
+ case 'missing':
94
+ return 'missing';
95
+ case 'not_a_file':
96
+ return 'a folder, not a file';
97
+ case 'empty':
98
+ return 'empty';
99
+ case 'too_big':
100
+ return `too big (${megabytes(details.size ?? 0)}; at most ${UPLOAD_MAX_BYTES / MB} MB)`;
101
+ case 'wrong_type':
102
+ return `not really a ${details.type}; its content does not match its extension`;
103
+ case 'outside_project':
104
+ return 'outside the project (it links to a file elsewhere)';
105
+ case 'unreadable':
106
+ return `could not be read${details.error ? ` (${details.error})` : ''}`;
107
+ }
108
+ };
109
+ /** A files-needed reply lists at most this many files. */
110
+ export const FILES_LISTED = 10;
111
+ /** What the files-needed reply and the report say of a file whose content check is skipped. */
112
+ export const MISMATCH_ALLOWED = 'type check skipped on purpose';
113
+ const oneLine = (text) => text.replace(/\s+/g, ' ').trim();
114
+ /**
115
+ * The reply when upload files are missing or unusable, so nothing started: a sentence with the
116
+ * count, one line per file (path, type, why, and what it should hold, whole: `about` is at most
117
+ * `ABOUT_MAX` characters already), then one sentence telling the caller to create them with
118
+ * synthetic content and start again.
119
+ */
120
+ export const formatFilesNeeded = (files) => {
121
+ const lines = files
122
+ .slice(0, FILES_LISTED)
123
+ .map((file) => `- ${file.path} (${file.type}${file.allowMismatch === true ? `, ${MISMATCH_ALLOWED}` : ''}): ${file.reason}` +
124
+ (file.about?.trim() ? `. About: ${oneLine(file.about)}` : ''));
125
+ const more = files.length - FILES_LISTED;
126
+ const one = files.length === 1;
127
+ return [
128
+ `Nothing was started: ${files.length} upload ${one ? 'file is' : 'files are'} missing or unusable.`,
129
+ ...lines,
130
+ ...(more > 0 ? [`- and ${more} more.`] : []),
131
+ `Create ${one ? 'it' : 'them'} at ${one ? 'that path' : 'those paths'} in the project with synthetic test content (no real personal data), then start the run again.`,
132
+ ].join('\n');
133
+ };
@@ -0,0 +1,16 @@
1
+ /** How many bytes from the start of a video file `webmDurationMs` needs. */
2
+ export declare const VIDEO_HEAD_BYTES: number;
3
+ /**
4
+ * How long a WebM video is, in ms, from the start of its file; undefined when the header does not
5
+ * say (a file cut short before its header was finished, or not WebM at all).
6
+ */
7
+ export declare const webmDurationMs: (bytes: Uint8Array) => number | undefined;
8
+ /**
9
+ * Why a session's video is missing or incomplete, or undefined when it looks whole: it exists,
10
+ * is not empty, and is at least about as long as the session ran (it may be a little longer:
11
+ * the recorder keeps the last frame until the browser closes).
12
+ */
13
+ export declare const videoProblemOf: (file: {
14
+ readonly size: number;
15
+ readonly durationMs: number | undefined;
16
+ } | undefined, sessionMs: number) => string | undefined;
@@ -0,0 +1,101 @@
1
+ /*
2
+ * Checking a session's video without a video library: the WebM file says how long it is in its
3
+ * header (Segment > Info > Duration), which is read here in pure code and compared with how long
4
+ * the session ran. Video problems are reported in words; they never change a status.
5
+ */
6
+ /** How many bytes from the start of a video file `webmDurationMs` needs. */
7
+ export const VIDEO_HEAD_BYTES = 64 * 1024;
8
+ const EBML = 0x1a45dfa3;
9
+ const SEGMENT = 0x18538067;
10
+ const INFO = 0x1549a966;
11
+ const TIMECODE_SCALE = 0x2ad7b1;
12
+ const DURATION = 0x4489;
13
+ const CLUSTER = 0x1f43b675;
14
+ /** An EBML variable-length integer at `at`: its value (with or without the length marker). */
15
+ const vint = (bytes, at, keepMarker) => {
16
+ const first = bytes[at];
17
+ if (first === undefined || first === 0)
18
+ return undefined;
19
+ const length = Math.clz32(first) - 23;
20
+ if (at + length > bytes.length)
21
+ return undefined;
22
+ let value = keepMarker ? first : first & (0xff >> length);
23
+ let allOnes = value === 0xff >> length;
24
+ for (let i = 1; i < length; i++) {
25
+ const byte = bytes[at + i];
26
+ value = value * 256 + byte;
27
+ allOnes &&= byte === 0xff;
28
+ }
29
+ return { value, length, unknown: !keepMarker && allOnes };
30
+ };
31
+ const readUint = (bytes, at, size) => {
32
+ let value = 0;
33
+ for (let i = 0; i < size; i++)
34
+ value = value * 256 + bytes[at + i];
35
+ return value;
36
+ };
37
+ const readFloat = (bytes, at, size) => {
38
+ const view = new DataView(bytes.buffer, bytes.byteOffset + at, size);
39
+ return size === 4 ? view.getFloat32(0) : size === 8 ? view.getFloat64(0) : undefined;
40
+ };
41
+ /**
42
+ * How long a WebM video is, in ms, from the start of its file; undefined when the header does not
43
+ * say (a file cut short before its header was finished, or not WebM at all).
44
+ */
45
+ export const webmDurationMs = (bytes) => {
46
+ let at = 0;
47
+ let end = bytes.length;
48
+ let scale = 1_000_000;
49
+ let duration;
50
+ let sawHeader = false;
51
+ while (at < end) {
52
+ const id = vint(bytes, at, true);
53
+ if (id === undefined)
54
+ return undefined;
55
+ const size = vint(bytes, at + id.length, false);
56
+ if (size === undefined)
57
+ return undefined;
58
+ const body = at + id.length + size.length;
59
+ if (id.value === EBML)
60
+ sawHeader = true;
61
+ if (!sawHeader)
62
+ return undefined;
63
+ if (id.value === SEGMENT || id.value === INFO) {
64
+ // Containers: read on inside them.
65
+ if (!size.unknown)
66
+ end = Math.min(bytes.length, body + size.value);
67
+ at = body;
68
+ continue;
69
+ }
70
+ if (size.unknown || id.value === CLUSTER)
71
+ break;
72
+ if (body + size.value > bytes.length)
73
+ break;
74
+ if (id.value === TIMECODE_SCALE)
75
+ scale = readUint(bytes, body, size.value);
76
+ if (id.value === DURATION)
77
+ duration = readFloat(bytes, body, size.value);
78
+ at = body + size.value;
79
+ }
80
+ return duration === undefined || !Number.isFinite(duration) || duration < 0
81
+ ? undefined
82
+ : Math.round((duration * scale) / 1_000_000);
83
+ };
84
+ const seconds = (ms) => `${(ms / 1000).toFixed(1)} s`;
85
+ /**
86
+ * Why a session's video is missing or incomplete, or undefined when it looks whole: it exists,
87
+ * is not empty, and is at least about as long as the session ran (it may be a little longer:
88
+ * the recorder keeps the last frame until the browser closes).
89
+ */
90
+ export const videoProblemOf = (file, sessionMs) => {
91
+ if (file === undefined)
92
+ return 'The video file was not saved.';
93
+ if (file.size === 0)
94
+ return 'The video file is empty.';
95
+ if (file.durationMs === undefined)
96
+ return 'The video file does not say how long it is, so it may have been cut short.';
97
+ const slack = Math.max(2_000, sessionMs * 0.1);
98
+ return file.durationMs < sessionMs - slack
99
+ ? `The video is ${seconds(file.durationMs)} long, but the session ran for ${seconds(sessionMs)}.`
100
+ : undefined;
101
+ };
@@ -0,0 +1,28 @@
1
+ import type { Box, Device, Shot, ShotPage, StepAction, VisualViewport } from '../schema/index.js';
2
+ /**
3
+ * Where a box measured in the page's layout viewport (CSS pixels) shows in the viewport Playwright
4
+ * set (its CSS pixels, which is what a viewport screenshot and the video show): moved by where the
5
+ * visual viewport is in the layout, and scaled by its scale.
6
+ */
7
+ export declare const layoutToScreen: (box: Box, visual: VisualViewport) => Box;
8
+ /**
9
+ * Whether boxes measured on a run on `device` can be drawn where they show: always when what they
10
+ * were measured in is known (`measuredIn`: a `VisualViewport` or its scale), else only on a
11
+ * desktop, whose visual viewport is its layout viewport. Older runs on a phone recorded boxes in
12
+ * the page's layout, which the phone may have shown scaled or moved: they are not drawn at all.
13
+ */
14
+ export declare const boxesDrawable: (device: Device, measuredIn: unknown) => boolean;
15
+ /** Why the box of a step's element measured in the page's layout on a phone is not drawn. */
16
+ export declare const TARGET_UNPLACED = "the element was measured in the layout of the page, which the phone may have shown scaled or moved";
17
+ /**
18
+ * A screenshot's record as it may be drawn on a run on `device`: without `target` and
19
+ * `targetContent` when they cannot be placed where they show (see `boxesDrawable`), saying why.
20
+ */
21
+ export declare const drawableShot: (shot: Shot, device: Device) => Shot;
22
+ /**
23
+ * Why the boxes of a screenshot's saved page state cannot be drawn on a run on `device`, when they
24
+ * cannot (see `boxesDrawable`).
25
+ */
26
+ export declare const pageUnplaced: (page: ShotPage, device: Device) => string | undefined;
27
+ /** An action as it may be drawn on a run on `device`: without a `target` it cannot place. */
28
+ export declare const drawableAction: (action: StepAction, device: Device) => StepAction;
@@ -0,0 +1,50 @@
1
+ /*
2
+ * Where the page's layout shows on the screen. Element boxes are measured in the page's layout
3
+ * viewport (`getBoundingClientRect`), but a screenshot of the viewport, and the video, show the
4
+ * visual viewport: on a phone a page without a viewport meta tag is laid out 980 wide and shown at
5
+ * 0.41, and a page zoomed in shows part of its layout bigger. On a desktop the two are the same.
6
+ */
7
+ /**
8
+ * Where a box measured in the page's layout viewport (CSS pixels) shows in the viewport Playwright
9
+ * set (its CSS pixels, which is what a viewport screenshot and the video show): moved by where the
10
+ * visual viewport is in the layout, and scaled by its scale.
11
+ */
12
+ export const layoutToScreen = (box, visual) => ({
13
+ x: (box.x - visual.x) * visual.scale,
14
+ y: (box.y - visual.y) * visual.scale,
15
+ width: box.width * visual.scale,
16
+ height: box.height * visual.scale,
17
+ });
18
+ /**
19
+ * Whether boxes measured on a run on `device` can be drawn where they show: always when what they
20
+ * were measured in is known (`measuredIn`: a `VisualViewport` or its scale), else only on a
21
+ * desktop, whose visual viewport is its layout viewport. Older runs on a phone recorded boxes in
22
+ * the page's layout, which the phone may have shown scaled or moved: they are not drawn at all.
23
+ */
24
+ export const boxesDrawable = (device, measuredIn) => measuredIn !== undefined || device === 'desktop';
25
+ /** Why the box of a step's element measured in the page's layout on a phone is not drawn. */
26
+ export const TARGET_UNPLACED = 'the element was measured in the layout of the page, which the phone may have shown scaled or moved';
27
+ /**
28
+ * A screenshot's record as it may be drawn on a run on `device`: without `target` and
29
+ * `targetContent` when they cannot be placed where they show (see `boxesDrawable`), saying why.
30
+ */
31
+ export const drawableShot = (shot, device) => {
32
+ if (shot.target === undefined || boxesDrawable(device, shot.visual))
33
+ return shot;
34
+ const { target: _target, targetContent: _content, ...rest } = shot;
35
+ return { ...rest, targetProblem: TARGET_UNPLACED };
36
+ };
37
+ /**
38
+ * Why the boxes of a screenshot's saved page state cannot be drawn on a run on `device`, when they
39
+ * cannot (see `boxesDrawable`).
40
+ */
41
+ export const pageUnplaced = (page, device) => boxesDrawable(device, page.visual)
42
+ ? undefined
43
+ : 'the elements of this screenshot were measured in the layout of the page, which the phone may have shown scaled or moved';
44
+ /** An action as it may be drawn on a run on `device`: without a `target` it cannot place. */
45
+ export const drawableAction = (action, device) => {
46
+ if (action.target === undefined || boxesDrawable(device, action.scale))
47
+ return action;
48
+ const { target: _target, ...rest } = action;
49
+ return rest;
50
+ };
@@ -0,0 +1,37 @@
1
+ import { Layer } from 'effect';
2
+ import { ReportRenderer } from '../core/index.js';
3
+ import { type ReportBundle } from '../schema/index.js';
4
+ /**
5
+ * The page's one script, allowed by its hash in the Content Security Policy. It sets the theme
6
+ * (light, dark, or the system's) before anything is painted and keeps the choice where the browser
7
+ * allows (a page opened from disk may not); it shows the theme switch, which is hidden without
8
+ * script; it makes timecode links (and each player's "Play from" button) seek the case's video in
9
+ * place instead of opening the file; and when a screenshot or video cannot load (the page opened
10
+ * where its run folder is not, as in a viewer that shows only the HTML), it says so in its figure
11
+ * and hides the boxes drawn over it. Errors can come before it runs, so it also looks for media
12
+ * that already failed (a video has no source yet while it starts loading, so only one that has
13
+ * picked its file and has none counts). Players load nothing until played (`preload="none"`), so a
14
+ * video that was never played is never called broken, and it plays one video at a time: when one
15
+ * starts, every other that loaded anything lets go of its file. On a server without HTTP range
16
+ * requests, a video that has started holds a connection for as long as it is loaded, and a few of
17
+ * those would keep the screenshots from ever loading. Without script, the theme follows the
18
+ * system, timecodes and "Play from" still open the video at their time, and a screenshot that
19
+ * cannot load shows the same words, which lie under the image.
20
+ */
21
+ export declare const REPORT_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)))};const bad=e=>{const f=e.closest('figure');if(!f||f.classList.contains('broken'))return;f.classList.add('broken');f.querySelectorAll('.unloaded').forEach(u=>{u.hidden=false;u.removeAttribute('aria-hidden')})};const off=o=>{if(o.readyState===0&&o.networkState!==2)return;const s=o.getAttribute('src');o.pause();o.removeAttribute('src');o.load();if(s!==null)o.setAttribute('src',s);const f=o.closest('figure');if(f)f.classList.remove('started')};let m='system';try{m=localStorage.getItem(k)||m}catch(e){}r.dataset.theme=m;d.addEventListener('error',e=>{const t=e.target;if(t instanceof Element&&t.matches('figure img,figure video,figure source'))bad(t)},true);d.addEventListener('play',e=>{const v=e.target;if(!(v instanceof HTMLVideoElement))return;const f=v.closest('figure');if(f)f.classList.add('started');d.querySelectorAll('video').forEach(o=>{if(o!==v)off(o)})},true);const scan=()=>{d.querySelectorAll('figure img').forEach(i=>{if(i.complete&&i.naturalWidth===0)bad(i)});d.querySelectorAll('figure video').forEach(v=>{if(v.error||(v.networkState===3&&v.currentSrc))bad(v)})};d.addEventListener('DOMContentLoaded',()=>{set(r.dataset.theme);const t=d.getElementById('theme');if(t)t.hidden=false;scan()});addEventListener('load',scan);d.addEventListener('click',e=>{const b=e.target.closest('[data-theme-set]');if(b){set(b.dataset.themeSet);try{localStorage.setItem(k,b.dataset.themeSet)}catch(e){}return}const a=e.target.closest('a[data-v]');if(!a)return;const v=d.getElementById(a.dataset.v);if(!v||v.closest('.broken'))return;e.preventDefault();if(a.closest('figure')!==v.closest('figure'))v.scrollIntoView({block:'center',behavior:matchMedia('(prefers-reduced-motion: reduce)').matches?'auto':'smooth'});const go=()=>{v.currentTime=Number(a.dataset.t);v.play().catch(()=>{})};if(v.readyState>0)go();else{v.addEventListener('loadedmetadata',go,{once:true});v.play().catch(()=>{})}})})();";
22
+ /**
23
+ * Nothing loads from the network. Images and video load from the run folder by relative path
24
+ * (`'self'`, and `file:` for a report opened from disk); styles are inline; the only script is
25
+ * {@link REPORT_SCRIPT}, by its hash.
26
+ */
27
+ export declare const REPORT_CSP: string;
28
+ /**
29
+ * A self-contained HTML report: inline CSS, one tiny inline script, no fonts or network.
30
+ * Screenshots and the video are linked by paths relative to the run folder, so the page works from
31
+ * disk and after the folder is zipped or moved. Code lays out every part and decides every status;
32
+ * the agent's write-up, when it submitted one, fills fixed slots and is labelled as its own.
33
+ * Every piece of text from the job, the page or the agent is escaped.
34
+ */
35
+ export declare const renderHtmlReport: (bundle: ReportBundle) => string;
36
+ /** The report module's renderer, for the engine to write a run's report. */
37
+ export declare const ReportRendererHtml: Layer.Layer<ReportRenderer, never, never>;