screw-bugs 0.1.9 → 0.1.10

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 (102) hide show
  1. package/README.md +49 -34
  2. package/dist/browser-playwright/capture.js +1 -1
  3. package/dist/build-info.json +3 -3
  4. package/dist/cli/app.js +6 -2
  5. package/dist/cli/commands.js +4 -3
  6. package/dist/cli/doctor.d.ts +17 -2
  7. package/dist/cli/doctor.js +62 -4
  8. package/dist/cli/mcp.js +2 -2
  9. package/dist/cli/report-server.d.ts +19 -10
  10. package/dist/cli/report-server.js +43 -18
  11. package/dist/cli/share.js +2 -2
  12. package/dist/cli/sign-in.d.ts +9 -3
  13. package/dist/cli/sign-in.js +12 -9
  14. package/dist/cli/tailnet.d.ts +57 -0
  15. package/dist/cli/tailnet.js +82 -0
  16. package/dist/core/index.d.ts +1 -14
  17. package/dist/core/index.js +3 -14
  18. package/dist/report/index.d.ts +1 -10
  19. package/dist/report/index.js +3 -10
  20. package/dist/schema/index.d.ts +1 -9
  21. package/dist/schema/index.js +3 -9
  22. package/package.json +14 -14
  23. package/dist/core/accounts.d.ts +0 -40
  24. package/dist/core/accounts.js +0 -95
  25. package/dist/core/css.d.ts +0 -95
  26. package/dist/core/css.js +0 -436
  27. package/dist/core/engine.d.ts +0 -75
  28. package/dist/core/engine.js +0 -560
  29. package/dist/core/errors.d.ts +0 -85
  30. package/dist/core/errors.js +0 -36
  31. package/dist/core/evidence.d.ts +0 -14
  32. package/dist/core/evidence.js +0 -131
  33. package/dist/core/labels.d.ts +0 -47
  34. package/dist/core/labels.js +0 -199
  35. package/dist/core/liveness.d.ts +0 -45
  36. package/dist/core/liveness.js +0 -66
  37. package/dist/core/marks.d.ts +0 -63
  38. package/dist/core/marks.js +0 -410
  39. package/dist/core/services.d.ts +0 -579
  40. package/dist/core/services.js +0 -25
  41. package/dist/core/share.d.ts +0 -68
  42. package/dist/core/share.js +0 -318
  43. package/dist/core/steps.d.ts +0 -106
  44. package/dist/core/steps.js +0 -722
  45. package/dist/core/uploads.d.ts +0 -49
  46. package/dist/core/uploads.js +0 -133
  47. package/dist/core/video.d.ts +0 -53
  48. package/dist/core/video.js +0 -241
  49. package/dist/core/viewport.d.ts +0 -28
  50. package/dist/core/viewport.js +0 -50
  51. package/dist/report/assets.d.ts +0 -34
  52. package/dist/report/assets.js +0 -105
  53. package/dist/report/bug.d.ts +0 -11
  54. package/dist/report/bug.js +0 -20
  55. package/dist/report/html.d.ts +0 -47
  56. package/dist/report/html.js +0 -923
  57. package/dist/report/icons.d.ts +0 -51
  58. package/dist/report/icons.js +0 -93
  59. package/dist/report/live.d.ts +0 -7
  60. package/dist/report/live.js +0 -135
  61. package/dist/report/logos.d.ts +0 -4
  62. package/dist/report/logos.js +0 -19
  63. package/dist/report/markup.d.ts +0 -50
  64. package/dist/report/markup.js +0 -156
  65. package/dist/report/menu-bar.d.ts +0 -60
  66. package/dist/report/menu-bar.js +0 -157
  67. package/dist/report/player.d.ts +0 -102
  68. package/dist/report/player.js +0 -315
  69. package/dist/report/pr-summary.d.ts +0 -11
  70. package/dist/report/pr-summary.js +0 -119
  71. package/dist/report/sha256.d.ts +0 -9
  72. package/dist/report/sha256.js +0 -97
  73. package/dist/report/share-page.d.ts +0 -48
  74. package/dist/report/share-page.js +0 -291
  75. package/dist/report/shots.d.ts +0 -59
  76. package/dist/report/shots.js +0 -280
  77. package/dist/report/sign-in.d.ts +0 -41
  78. package/dist/report/sign-in.js +0 -568
  79. package/dist/report/styles.d.ts +0 -3
  80. package/dist/report/styles.js +0 -274
  81. package/dist/report/view.d.ts +0 -296
  82. package/dist/report/view.js +0 -702
  83. package/dist/report/walkthrough.d.ts +0 -93
  84. package/dist/report/walkthrough.js +0 -716
  85. package/dist/schema/accounts.d.ts +0 -137
  86. package/dist/schema/accounts.js +0 -121
  87. package/dist/schema/config.d.ts +0 -7
  88. package/dist/schema/config.js +0 -6
  89. package/dist/schema/doctor.d.ts +0 -46
  90. package/dist/schema/doctor.js +0 -30
  91. package/dist/schema/evidence.d.ts +0 -1115
  92. package/dist/schema/evidence.js +0 -565
  93. package/dist/schema/findings.d.ts +0 -161
  94. package/dist/schema/findings.js +0 -82
  95. package/dist/schema/job.d.ts +0 -1905
  96. package/dist/schema/job.js +0 -577
  97. package/dist/schema/ledger.d.ts +0 -1124
  98. package/dist/schema/ledger.js +0 -285
  99. package/dist/schema/share.d.ts +0 -55
  100. package/dist/schema/share.js +0 -64
  101. package/dist/schema/status.d.ts +0 -7
  102. package/dist/schema/status.js +0 -11
@@ -1,36 +0,0 @@
1
- import { Data } from 'effect';
2
- /** A planned feature that this version does not have yet. */
3
- export class NotImplemented extends Data.TaggedError('NotImplemented') {
4
- get message() {
5
- return `${this.feature} is not implemented yet.`;
6
- }
7
- }
8
- /** None of the supported browsers could be launched. */
9
- export class BrowserNotFound extends Data.TaggedError('BrowserNotFound') {
10
- }
11
- export class RunNotFound extends Data.TaggedError('RunNotFound') {
12
- }
13
- /** Run files could not be read or written. */
14
- export class StorageFailed extends Data.TaggedError('StorageFailed') {
15
- }
16
- /**
17
- * A page action could not be carried out: no element matched, navigation failed, the page
18
- * crashed. `message` is plain language and short; it never holds DOM or browser logs.
19
- */
20
- export class PageActionFailed extends Data.TaggedError('PageActionFailed') {
21
- }
22
- /** A run that has not ended yet cannot take findings: its evidence is not final. */
23
- export class RunNotEnded extends Data.TaggedError('RunNotEnded') {
24
- }
25
- /** Findings that do not fit the run: one plain line per problem, saying what to change. */
26
- export class FindingsRejected extends Data.TaggedError('FindingsRejected') {
27
- get message() {
28
- return this.problems.join('\n');
29
- }
30
- }
31
- /**
32
- * A job's account has no session a run can start from (see `needsSignIn`): nothing was started,
33
- * and a person has to sign in to it first.
34
- */
35
- export class SignInNeeded extends Data.TaggedError('SignInNeeded') {
36
- }
@@ -1,14 +0,0 @@
1
- import { type CaseLedger, type EvidencePack, type Findings, type JobRecord } from '../schema/index.js';
2
- /** What every report and evidence pack says once about how cases ran. */
3
- export declare const SESSION_NOTE: string;
4
- /**
5
- * The evidence pack of a run: per case what an agent needs to write it up (status, deciding step,
6
- * reason, step timecodes, screenshot IDs, page facts), and the IDs its findings may use. Built
7
- * from the job and ledger alone, so it is the same whoever builds it.
8
- */
9
- export declare const evidencePackOf: (job: JobRecord, ledger: CaseLedger) => EvidencePack;
10
- /**
11
- * Everything in `findings` that does not fit the run, one plain line each, saying what to change:
12
- * case IDs, screenshot IDs and timecodes it does not have. Empty when the findings fit.
13
- */
14
- export declare const checkFindings: (findings: Findings, pack: EvidencePack) => ReadonlyArray<string>;
@@ -1,131 +0,0 @@
1
- import { baseName, casesOf, uploadFileOf, } from '../schema/index.js';
2
- import { describeStep, withStartPage } from './steps.js';
3
- /** What every report and evidence pack says once about how cases ran. */
4
- export const SESSION_NOTE = 'Cases ran one after another, in job order, in one browser session: cookies and storage ' +
5
- 'carried over from one case to the next.';
6
- const stepState = (entry, index, ran) => {
7
- if (entry.status === 'passed')
8
- return 'ran';
9
- if (entry.step !== undefined && (entry.status === 'failed' || entry.status === 'blocked'))
10
- return index < entry.step ? 'ran' : index === entry.step ? 'decided' : 'not-run';
11
- return ran ? 'ran' : 'not-run';
12
- };
13
- /** The timecodes key moments of a case may use: its start, each step's start, and its end. */
14
- const timecodesOf = (entry) => {
15
- const all = [entry.startMs, ...(entry.steps ?? []).map((s) => s.startMs), entry.endMs].flatMap((ms) => (ms === undefined ? [] : [Math.round(ms)]));
16
- return [...new Set(all)].toSorted((a, b) => a - b);
17
- };
18
- /**
19
- * The evidence pack of a run: per case what an agent needs to write it up (status, deciding step,
20
- * reason, step timecodes, screenshot IDs, page facts), and the IDs its findings may use. Built
21
- * from the job and ledger alone, so it is the same whoever builds it.
22
- */
23
- export const evidencePackOf = (job, ledger) => {
24
- const specs = new Map(casesOf(job.spec).map((spec) => [spec.id, spec]));
25
- const cases = ledger.cases.map((entry) => {
26
- const spec = specs.get(entry.id);
27
- const steps = spec ? withStartPage(spec, job.spec.url) : [];
28
- const offset = spec ? steps.length - spec.steps.length : 0;
29
- const timings = new Map((entry.steps ?? []).map((s) => [s.index, s]));
30
- // Each step's own screenshot, taken as it ran (not the one when the case stopped).
31
- const stepShots = new Map((entry.shots ?? []).filter((s) => s.kind === 'step').map((s) => [s.step, s.id]));
32
- return {
33
- id: entry.id,
34
- title: entry.title,
35
- status: entry.status,
36
- ...(entry.step !== undefined ? { step: entry.step } : {}),
37
- ...(entry.reason !== undefined ? { reason: entry.reason } : {}),
38
- ...(spec?.success?.trim() ? { success: spec.success } : {}),
39
- ...(entry.continuedFrom !== undefined ? { continuedFrom: entry.continuedFrom } : {}),
40
- ...(entry.session !== undefined ? { session: entry.session } : {}),
41
- ...(entry.startMs !== undefined ? { startMs: Math.round(entry.startMs) } : {}),
42
- ...(entry.endMs !== undefined ? { endMs: Math.round(entry.endMs) } : {}),
43
- steps: steps.map((step, i) => {
44
- const index = i + 1 - offset;
45
- const timing = timings.get(index);
46
- return {
47
- index,
48
- text: describeStep(step),
49
- state: stepState(entry, index, timing !== undefined),
50
- ...(step.action === 'upload'
51
- ? { files: step.files.map((file) => baseName(uploadFileOf(file).path)) }
52
- : {}),
53
- ...(timing
54
- ? { startMs: Math.round(timing.startMs), endMs: Math.round(timing.endMs) }
55
- : {}),
56
- ...(timing?.onScreen !== undefined ? { onScreen: timing.onScreen } : {}),
57
- ...(stepShots.has(index) ? { shot: stepShots.get(index) } : {}),
58
- };
59
- }),
60
- timecodes: timecodesOf(entry),
61
- shots: (entry.shots ?? []).map((shot) => ({
62
- id: shot.id,
63
- name: shot.name,
64
- kind: shot.kind,
65
- step: shot.step,
66
- path: shot.path,
67
- ...(shot.page !== undefined ? { page: shot.page } : {}),
68
- })),
69
- ...(entry.facts !== undefined ? { facts: entry.facts } : {}),
70
- };
71
- });
72
- return {
73
- version: 1,
74
- jobId: ledger.jobId,
75
- state: ledger.state,
76
- sessionNote: SESSION_NOTE,
77
- videos: (ledger.sessions ?? []).map((session) => ({
78
- session: session.number,
79
- ...(session.video !== undefined ? { path: session.video } : {}),
80
- ...(session.videoDurationMs !== undefined ? { durationMs: session.videoDurationMs } : {}),
81
- ...(session.videoProblem !== undefined ? { problem: session.videoProblem } : {}),
82
- })),
83
- cases,
84
- };
85
- };
86
- const list = (values, max = 12) => {
87
- const shown = values.slice(0, max).join(', ');
88
- return values.length > max ? `${shown}, …` : shown;
89
- };
90
- /**
91
- * Everything in `findings` that does not fit the run, one plain line each, saying what to change:
92
- * case IDs, screenshot IDs and timecodes it does not have. Empty when the findings fit.
93
- */
94
- export const checkFindings = (findings, pack) => {
95
- const problems = [];
96
- const cases = new Map(pack.cases.map((c) => [c.id, c]));
97
- const ids = list(pack.cases.map((c) => c.id));
98
- const unknownCase = (where, id) => problems.push(`${where}: "${id}" is not a case of this run; use one of: ${ids}.`);
99
- findings.fixes.forEach((fix, i) => fix.caseIds.forEach((id, j) => {
100
- if (!cases.has(id))
101
- unknownCase(`fixes[${i}].caseIds[${j}]`, id);
102
- }));
103
- const seen = new Set();
104
- findings.cases.forEach((entry, i) => {
105
- const evidence = cases.get(entry.id);
106
- if (evidence === undefined)
107
- return unknownCase(`cases[${i}].id`, entry.id);
108
- if (seen.has(entry.id))
109
- problems.push(`cases[${i}].id: case "${entry.id}" is written up twice; merge the two.`);
110
- seen.add(entry.id);
111
- const shots = evidence.shots.map((s) => s.id);
112
- (entry.highlights ?? []).forEach((highlight, j) => {
113
- if (shots.includes(highlight.shot))
114
- return;
115
- problems.push(`cases[${i}].highlights[${j}].shot: "${highlight.shot}" is not a screenshot of case ` +
116
- `"${entry.id}"; ` +
117
- (shots.length > 0
118
- ? `use one of: ${list(shots)}.`
119
- : 'it has none, so leave its highlights out.'));
120
- });
121
- (entry.keyMoments ?? []).forEach((moment, j) => {
122
- if (evidence.timecodes.includes(moment.ms))
123
- return;
124
- problems.push(`cases[${i}].keyMoments[${j}].ms: ${moment.ms} is not a timecode of case "${entry.id}"; ` +
125
- (evidence.timecodes.length > 0
126
- ? `use one of: ${list(evidence.timecodes)}.`
127
- : 'it has none, so leave its key moments out.'));
128
- });
129
- });
130
- return problems;
131
- };
@@ -1,47 +0,0 @@
1
- import type { Box, ShotPage } from '../schema/index.js';
2
- /** Above or below the box, lined up with its start or end; beside it; or, with no room at all, in it. */
3
- export type LabelSpot = 'above-start' | 'above-end' | 'below-start' | 'below-end' | 'right' | 'left' | 'inside';
4
- export interface Size {
5
- readonly width: number;
6
- readonly height: number;
7
- }
8
- /** Where a label goes: a spot, moved `shift` image pixels to the right to sit after another label. */
9
- export interface LabelPlace {
10
- readonly spot: LabelSpot;
11
- readonly shift: number;
12
- }
13
- /** The area a label of `size` takes at `place`, `gap` away from the edge of `box`. */
14
- export declare const labelArea: (box: Box, size: Size, { spot, shift }: LabelPlace, gap: number) => Box;
15
- /** The part of `box` inside `frame`: a box drawn past the image's edge would be cut off there. */
16
- export declare const clipBox: (box: Box, frame: Box) => Box;
17
- /**
18
- * `box` grown by `by` on every side: the area a line drawn `by` outside an element takes, so the
19
- * line goes around the element and never over it.
20
- */
21
- export declare const outsetBox: (box: Box, by: number) => Box;
22
- /**
23
- * The boxes of the elements saved with a screenshot that labels should keep off: the innermost
24
- * ones (elements with no saved element inside them), visible and on the image, rounded to whole
25
- * pixels. Outer ones such as a form or the page's main area would leave a label nowhere to go.
26
- */
27
- export declare const elementBoxes: (page: ShotPage) => ReadonlyArray<Box>;
28
- /**
29
- * A place for each box's label, in the boxes' order. Preferred: above the box, then below it (or
30
- * the other way round), lined up with its start, its end, or right after a label already there
31
- * (when two boxes mark one element); then beside it. The first that stays in the image, covers no
32
- * label placed before it and no other box, and has room: not on a side where another box is too
33
- * close for the label to fit between them (it goes to the far side from that box, or beside its
34
- * own box), and not touching another box. When none does, the one that does least harm: leaving
35
- * the image is worst (the label would be cut off), then sitting in its own box, then covering
36
- * another label, then covering other boxes (the less of them the better), then covering other
37
- * elements of the page (`obstacles`, such as a button next to the marked text: the less the
38
- * better), then being squeezed against one. Obstacles that hold the box, or are its own element,
39
- * do not count. Last, lined up with the end of a box much wider than the label, far from its start.
40
- * Sizes and `gap` are in the image's pixels.
41
- */
42
- export declare const placeLabels: (frame: Size, boxes: ReadonlyArray<{
43
- readonly box: Box;
44
- readonly label: Size;
45
- /** Try below the box first, as for a field, whose own label is usually just above it. */
46
- readonly prefer?: 'above' | 'below';
47
- }>, gap: number, obstacles?: ReadonlyArray<Box>) => ReadonlyArray<LabelPlace>;
@@ -1,199 +0,0 @@
1
- /** The area a label of `size` takes at `place`, `gap` away from the edge of `box`. */
2
- export const labelArea = (box, size, { spot, shift }, gap) => {
3
- const start = box.x + shift;
4
- const end = box.x + box.width - size.width;
5
- const above = box.y - gap - size.height;
6
- const below = box.y + box.height + gap;
7
- switch (spot) {
8
- case 'above-start':
9
- return { x: start, y: above, ...size };
10
- case 'above-end':
11
- return { x: end, y: above, ...size };
12
- case 'below-start':
13
- return { x: start, y: below, ...size };
14
- case 'below-end':
15
- return { x: end, y: below, ...size };
16
- case 'right':
17
- return { x: box.x + box.width + gap, y: box.y, ...size };
18
- case 'left':
19
- return { x: box.x - gap - size.width, y: box.y, ...size };
20
- case 'inside':
21
- return { x: box.x, y: box.y, ...size };
22
- }
23
- };
24
- /** The part of `box` inside `frame`: a box drawn past the image's edge would be cut off there. */
25
- export const clipBox = (box, frame) => {
26
- const x = Math.max(box.x, frame.x);
27
- const y = Math.max(box.y, frame.y);
28
- return {
29
- x,
30
- y,
31
- width: Math.max(0, Math.min(box.x + box.width, frame.x + frame.width) - x),
32
- height: Math.max(0, Math.min(box.y + box.height, frame.y + frame.height) - y),
33
- };
34
- };
35
- const overlap = (a, b) => a.x < b.x + b.width && b.x < a.x + a.width && a.y < b.y + b.height && b.y < a.y + a.height;
36
- /** The area two boxes share. */
37
- const common = (a, b) => Math.max(0, Math.min(a.x + a.width, b.x + b.width) - Math.max(a.x, b.x)) *
38
- Math.max(0, Math.min(a.y + a.height, b.y + b.height) - Math.max(a.y, b.y));
39
- const within = (area, frame) => area.x >= 0 &&
40
- area.y >= 0 &&
41
- area.x + area.width <= frame.width &&
42
- area.y + area.height <= frame.height;
43
- /**
44
- * `box` grown by `by` on every side: the area a line drawn `by` outside an element takes, so the
45
- * line goes around the element and never over it.
46
- */
47
- export const outsetBox = (box, by) => ({
48
- x: box.x - by,
49
- y: box.y - by,
50
- width: box.width + 2 * by,
51
- height: box.height + 2 * by,
52
- });
53
- const grow = outsetBox;
54
- const contains = (outer, inner) => outer.x <= inner.x &&
55
- outer.y <= inner.y &&
56
- outer.x + outer.width >= inner.x + inner.width &&
57
- outer.y + outer.height >= inner.y + inner.height;
58
- /**
59
- * The boxes of the elements saved with a screenshot that labels should keep off: the innermost
60
- * ones (elements with no saved element inside them), visible and on the image, rounded to whole
61
- * pixels. Outer ones such as a form or the page's main area would leave a label nowhere to go.
62
- */
63
- export const elementBoxes = (page) => {
64
- const holders = new Set(page.candidates.flatMap((c) => (c.parent === undefined ? [] : [c.parent])));
65
- const seen = new Set();
66
- return page.candidates.flatMap((c, i) => {
67
- if (holders.has(i) || c.visible === false)
68
- return [];
69
- // An element in a frame shows only where its frame does.
70
- const shown = c.frame === undefined ? undefined : page.frames?.[c.frame]?.box;
71
- const box = shown === undefined ? c.box : clipBox(c.box, shown);
72
- const x = Math.max(0, Math.floor(box.x));
73
- const y = Math.max(0, Math.floor(box.y));
74
- const right = Math.min(page.width, Math.ceil(box.x + box.width));
75
- const bottom = Math.min(page.height, Math.ceil(box.y + box.height));
76
- const key = `${x},${y},${right},${bottom}`;
77
- if (right <= x || bottom <= y || seen.has(key))
78
- return [];
79
- seen.add(key);
80
- return [{ x, y, width: right - x, height: bottom - y }];
81
- });
82
- };
83
- /** Whether two boxes mark one element (or nearly): they share at least half of the smaller one. */
84
- const sameElement = (a, b) => common(a, b) >= 0.5 * Math.min(a.width * a.height, b.width * b.height);
85
- const sideOf = (spot) => spot === 'inside'
86
- ? undefined
87
- : spot === 'right' || spot === 'left'
88
- ? spot
89
- : spot.startsWith('above')
90
- ? 'above'
91
- : 'below';
92
- /**
93
- * The sides of `box` with another box too close for a label to fit between them with room: such as
94
- * a field's own label, marked just above the field. A label on that side would sit squeezed in the
95
- * gap, so each box's label goes to its far side from the other.
96
- */
97
- const crowdedSides = (box, others, label, gap) => {
98
- const sides = new Set();
99
- const [top, bottom, left, right] = [box.y, box.y + box.height, box.x, box.x + box.width];
100
- for (const other of others) {
101
- if (sameElement(box, other))
102
- continue;
103
- const [oTop, oBottom, oLeft, oRight] = [
104
- other.y,
105
- other.y + other.height,
106
- other.x,
107
- other.x + other.width,
108
- ];
109
- const [midY, midX] = [(oTop + oBottom) / 2, (oLeft + oRight) / 2];
110
- const across = oLeft < right && left < oRight;
111
- const along = oTop < bottom && top < oBottom;
112
- const tall = label.height + 2 * gap;
113
- const wide = label.width + 2 * gap;
114
- if (across && midY < top && top - oBottom < tall)
115
- sides.add('above');
116
- if (across && midY > bottom && oTop - bottom < tall)
117
- sides.add('below');
118
- if (along && midX < left && left - oRight < wide)
119
- sides.add('left');
120
- if (along && midX > right && oLeft - right < wide)
121
- sides.add('right');
122
- }
123
- return sides;
124
- };
125
- /**
126
- * A place for each box's label, in the boxes' order. Preferred: above the box, then below it (or
127
- * the other way round), lined up with its start, its end, or right after a label already there
128
- * (when two boxes mark one element); then beside it. The first that stays in the image, covers no
129
- * label placed before it and no other box, and has room: not on a side where another box is too
130
- * close for the label to fit between them (it goes to the far side from that box, or beside its
131
- * own box), and not touching another box. When none does, the one that does least harm: leaving
132
- * the image is worst (the label would be cut off), then sitting in its own box, then covering
133
- * another label, then covering other boxes (the less of them the better), then covering other
134
- * elements of the page (`obstacles`, such as a button next to the marked text: the less the
135
- * better), then being squeezed against one. Obstacles that hold the box, or are its own element,
136
- * do not count. Last, lined up with the end of a box much wider than the label, far from its start.
137
- * Sizes and `gap` are in the image's pixels.
138
- */
139
- export const placeLabels = (frame, boxes, gap, obstacles = []) => {
140
- const taken = [];
141
- return boxes.map(({ box, label, prefer }, i) => {
142
- const others = boxes.filter((_, j) => j !== i).map((other) => other.box);
143
- const around = obstacles.filter((o) => !sameElement(box, o) && !contains(o, box));
144
- const crowded = crowdedSides(box, others, label, gap);
145
- // Other boxes a label may not touch: not those of this box's own element.
146
- const apart = others.filter((other) => !sameElement(box, other));
147
- // After a label already placed that starts over this box (the other box on the element).
148
- const after = (spot) => taken
149
- .filter((other) => other.x >= box.x - gap && other.x <= box.x + box.width)
150
- .map((other) => ({ spot, shift: other.x + other.width + gap - box.x }));
151
- const above = [
152
- { spot: 'above-start', shift: 0 },
153
- { spot: 'above-end', shift: 0 },
154
- ...after('above-start'),
155
- ];
156
- const below = [
157
- { spot: 'below-start', shift: 0 },
158
- { spot: 'below-end', shift: 0 },
159
- ...after('below-start'),
160
- ];
161
- const places = [
162
- ...(prefer === 'below' ? [...below, ...above] : [...above, ...below]),
163
- { spot: 'right', shift: 0 },
164
- { spot: 'left', shift: 0 },
165
- { spot: 'inside', shift: 0 },
166
- ];
167
- let best = places.at(-1);
168
- let least = Infinity;
169
- for (const place of places) {
170
- const area = labelArea(box, label, place, gap);
171
- // How much of the label lies over other boxes, as a share of it: less is better.
172
- const covered = Math.min(1, others.reduce((sum, other) => sum + common(area, other), 0) /
173
- Math.max(1, area.width * area.height));
174
- // How much of it lies over the page's other elements: covering one is avoided, not barred.
175
- const hidden = Math.min(1, around.reduce((sum, other) => sum + common(area, other), 0) /
176
- Math.max(1, area.width * area.height));
177
- const side = sideOf(place.spot);
178
- // Within a gap of another box (its edge is less than `gap` away), or on a crowded side.
179
- const squeezed = (side !== undefined && crowded.has(side)) ||
180
- apart.some((other) => overlap(grow(area, gap * 0.9), other));
181
- // Lined up with the end of a box much wider than it, a label is far from where the box's
182
- // content starts (the text of a line across the page): fine, but worse than next to it.
183
- const far = place.spot.endsWith('-end') && box.width > 4 * label.width;
184
- const harm = (within(area, frame) ? 0 : 16) +
185
- (place.spot === 'inside' ? 8 : 0) +
186
- (taken.some((other) => overlap(area, other)) ? 4 : 0) +
187
- (covered > 0 ? 1 + covered / 2 : 0) +
188
- (hidden > 0 ? 0.25 + hidden / 2 : 0) +
189
- (squeezed ? 0.5 : 0) +
190
- (far ? 0.1 : 0);
191
- if (harm < least)
192
- [best, least] = [place, harm];
193
- if (harm === 0)
194
- break;
195
- }
196
- taken.push(labelArea(box, label, best, gap));
197
- return best;
198
- });
199
- };
@@ -1,45 +0,0 @@
1
- import { Context } from 'effect';
2
- import type { CaseLedger } from '../schema/index.js';
3
- /** How often a running job rewrites `heartbeatAt` in its ledger. */
4
- export declare const HEARTBEAT_INTERVAL_MS = 5000;
5
- /**
6
- * A queued or running ledger whose heartbeat is older than this belongs to a process that is gone
7
- * (killed, crashed, or the machine lost power). Several intervals, so a busy process is not
8
- * mistaken for a dead one.
9
- */
10
- export declare const HEARTBEAT_STALE_MS: number;
11
- /**
12
- * How long a run's heartbeat must have been stale before a status read writes its
13
- * `report-interrupted.html`, showing it errored. Far beyond `HEARTBEAT_STALE_MS`: a process that
14
- * is only paused (a laptop asleep) is still alive, and may resume and write its own report.
15
- */
16
- export declare const REPORT_STALE_MS: number;
17
- /** The job error of a run whose process disappeared without finishing it. */
18
- export declare const PROCESS_GONE = "The process running this job stopped unexpectedly.";
19
- /** The job error of a run that was interrupted, such as by Ctrl+C or SIGTERM. */
20
- export declare const RUN_INTERRUPTED = "The run was stopped before it finished.";
21
- /** The reason a case gets when its run ended before reaching it. */
22
- export declare const STOPPED_BEFORE_CASE = "The run stopped before this case.";
23
- /**
24
- * ID of the operating-system process running jobs, recorded in each ledger it writes. Core stays
25
- * platform-free, so the CLI provides it; undefined leaves it out of the ledger.
26
- */
27
- export declare const ProcessId: Context.Reference<number | undefined>;
28
- /**
29
- * The version of screw-bugs running jobs, recorded in each ledger. The CLI provides it from its
30
- * package.json; undefined leaves it out.
31
- */
32
- export declare const AppVersion: Context.Reference<string | undefined>;
33
- /** Marks every case that has no result yet as not verified because the run stopped first. */
34
- export declare const markUnreached: (cases: CaseLedger['cases'], reason?: string) => CaseLedger['cases'];
35
- /**
36
- * The ledger as it should be reported at `nowMs`: a queued or running job whose heartbeat is
37
- * stale (or missing) is reported errored, with its unreached cases not verified. Any other ledger
38
- * is returned unchanged.
39
- */
40
- export declare const withLiveness: (ledger: CaseLedger, nowMs: number) => CaseLedger;
41
- /**
42
- * How long ago the heartbeat of a ledger that `withLiveness` reports errored was written; its
43
- * process may only be paused. Undefined for a ledger that its own process ended (or never ended).
44
- */
45
- export declare const staleFor: (ledger: CaseLedger, nowMs: number) => number | undefined;
@@ -1,66 +0,0 @@
1
- import { Context } from 'effect';
2
- /** How often a running job rewrites `heartbeatAt` in its ledger. */
3
- export const HEARTBEAT_INTERVAL_MS = 5_000;
4
- /**
5
- * A queued or running ledger whose heartbeat is older than this belongs to a process that is gone
6
- * (killed, crashed, or the machine lost power). Several intervals, so a busy process is not
7
- * mistaken for a dead one.
8
- */
9
- export const HEARTBEAT_STALE_MS = 6 * HEARTBEAT_INTERVAL_MS;
10
- /**
11
- * How long a run's heartbeat must have been stale before a status read writes its
12
- * `report-interrupted.html`, showing it errored. Far beyond `HEARTBEAT_STALE_MS`: a process that
13
- * is only paused (a laptop asleep) is still alive, and may resume and write its own report.
14
- */
15
- export const REPORT_STALE_MS = 10 * 60_000;
16
- /** The job error of a run whose process disappeared without finishing it. */
17
- export const PROCESS_GONE = 'The process running this job stopped unexpectedly.';
18
- /** The job error of a run that was interrupted, such as by Ctrl+C or SIGTERM. */
19
- export const RUN_INTERRUPTED = 'The run was stopped before it finished.';
20
- /** The reason a case gets when its run ended before reaching it. */
21
- export const STOPPED_BEFORE_CASE = 'The run stopped before this case.';
22
- /**
23
- * ID of the operating-system process running jobs, recorded in each ledger it writes. Core stays
24
- * platform-free, so the CLI provides it; undefined leaves it out of the ledger.
25
- */
26
- export const ProcessId = Context.Reference('screw-bugs/ProcessId', {
27
- defaultValue: () => undefined,
28
- });
29
- /**
30
- * The version of screw-bugs running jobs, recorded in each ledger. The CLI provides it from its
31
- * package.json; undefined leaves it out.
32
- */
33
- export const AppVersion = Context.Reference('screw-bugs/AppVersion', {
34
- defaultValue: () => undefined,
35
- });
36
- /** Marks every case that has no result yet as not verified because the run stopped first. */
37
- export const markUnreached = (cases, reason = STOPPED_BEFORE_CASE) => cases.map((c) => (c.status === 'not_verified' && c.reason === undefined ? { ...c, reason } : c));
38
- /**
39
- * The ledger as it should be reported at `nowMs`: a queued or running job whose heartbeat is
40
- * stale (or missing) is reported errored, with its unreached cases not verified. Any other ledger
41
- * is returned unchanged.
42
- */
43
- export const withLiveness = (ledger, nowMs) => {
44
- if (ledger.state !== 'queued' && ledger.state !== 'running')
45
- return ledger;
46
- const beat = ledger.heartbeatAt === undefined ? Number.NaN : Date.parse(ledger.heartbeatAt);
47
- if (nowMs - beat <= HEARTBEAT_STALE_MS)
48
- return ledger;
49
- // Where it was is no longer where it is: only a running ledger has a progress.
50
- const { progress: _, ...rest } = ledger;
51
- return { ...rest, state: 'errored', error: PROCESS_GONE, cases: markUnreached(ledger.cases) };
52
- };
53
- /**
54
- * How long ago the heartbeat of a ledger that `withLiveness` reports errored was written; its
55
- * process may only be paused. Undefined for a ledger that its own process ended (or never ended).
56
- */
57
- export const staleFor = (ledger, nowMs) => {
58
- if (ledger.state !== 'errored' ||
59
- ledger.error !== PROCESS_GONE ||
60
- ledger.finishedAt !== undefined)
61
- return undefined;
62
- // A ledger without a heartbeat counts as stale forever, as `withLiveness` treats it.
63
- return ledger.heartbeatAt === undefined
64
- ? Number.POSITIVE_INFINITY
65
- : nowMs - Date.parse(ledger.heartbeatAt);
66
- };
@@ -1,63 +0,0 @@
1
- import { type Box, type ElementTarget, type Findings, type PlacedMark, type Shot, type ShotPage, type Target } from '../schema/index.js';
2
- /** Where a highlight's element is on a screenshot, or why it has no box. */
3
- export type Resolution = {
4
- readonly _tag: 'found';
5
- readonly box: Box;
6
- readonly content?: Box;
7
- /** Other matches left out as not on the screenshot, in words (see `PlacedMark.ignored`). */
8
- readonly ignored?: string;
9
- } | {
10
- readonly _tag: 'missing';
11
- readonly reason: string;
12
- } | {
13
- readonly _tag: 'ambiguous';
14
- readonly reason: string;
15
- };
16
- /** The part of `box` on an image of `width` × `height`, or undefined when none of it is. */
17
- export declare const clampBox: (box: Box, width: number, height: number) => Box | undefined;
18
- /**
19
- * The part of an element's `content` (its text and images) inside its `box`, which is already on
20
- * the image; undefined when it has none there, or none was saved.
21
- */
22
- export declare const contentWithin: (content: Box | undefined, box: Box) => Box | undefined;
23
- /** Why a mark is refused on an element that was in the page but not seen on the screenshot. */
24
- export declare const NOT_VISIBLE = "the element was not visible when the screenshot was taken";
25
- /**
26
- * The part of a screenshot one document shows in: the box on the image where it shows (for a
27
- * frame, the part of it that shows), and how to say "outside" it.
28
- */
29
- export interface ShownPart {
30
- readonly box: Box;
31
- /** Such as `the part of its frame css "iframe.preview" that shows on this screenshot`. */
32
- readonly where: string;
33
- }
34
- /**
35
- * Finds `target` among the elements saved with a screenshot. When several match, an element
36
- * inside another match wins over that one (text is in every ancestor too), then an exact name or
37
- * text over a partial one. Then, when some of those left are on the screenshot (on its image, in
38
- * `part` when given, and visible when it was taken), the others are left out and said so: a copy
39
- * far below a viewport screenshot or below where its frame shows, or one that is transparent, is
40
- * not what the agent saw. More than one left, unless they share one box, is ambiguous; an element
41
- * the page had but did not show gets no mark. The box is cut to `part`.
42
- */
43
- export declare const resolveTarget: (target: ElementTarget, page: ShotPage, part?: ShownPart) => Resolution;
44
- /**
45
- * Finds a highlight's element on a screenshot: in the frames its `frame` names, outermost first,
46
- * then among that document's elements (`resolveTarget`). An element in a frame gets only the part
47
- * of its box where the frame shows, and a match outside that part counts as outside the
48
- * screenshot, as a copy below a viewport screenshot does. The frame's own `truncated` decides
49
- * whether a match is unique there. One without `frame` is looked for in the page itself only,
50
- * as a step would; when it is missing there but in a frame, the reason says so.
51
- */
52
- export declare const resolveHighlight: (target: Target, page: ShotPage) => Resolution;
53
- /**
54
- * Places every highlight of `findings` on its screenshot. `shots` has every screenshot of the run
55
- * by ID, with its saved page state when it has one, and why its boxes cannot be placed on the
56
- * image when they cannot (`unplaced`, see `pageUnplaced`). Highlights on unknown screenshots are
57
- * left out: `checkFindings` rejects them before findings are saved.
58
- */
59
- export declare const placeMarks: (findings: Findings, shots: ReadonlyMap<string, {
60
- readonly shot: Shot;
61
- readonly page: ShotPage | undefined;
62
- readonly unplaced?: string | undefined;
63
- }>) => Record<string, ReadonlyArray<PlacedMark>>;