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.
- package/README.md +49 -34
- package/dist/browser-playwright/capture.js +1 -1
- package/dist/build-info.json +3 -3
- package/dist/cli/app.js +6 -2
- package/dist/cli/commands.js +4 -3
- package/dist/cli/doctor.d.ts +17 -2
- package/dist/cli/doctor.js +62 -4
- package/dist/cli/mcp.js +2 -2
- package/dist/cli/report-server.d.ts +19 -10
- package/dist/cli/report-server.js +43 -18
- package/dist/cli/share.js +2 -2
- package/dist/cli/sign-in.d.ts +9 -3
- package/dist/cli/sign-in.js +12 -9
- package/dist/cli/tailnet.d.ts +57 -0
- package/dist/cli/tailnet.js +82 -0
- package/dist/core/index.d.ts +1 -14
- package/dist/core/index.js +3 -14
- package/dist/report/index.d.ts +1 -10
- package/dist/report/index.js +3 -10
- package/dist/schema/index.d.ts +1 -9
- package/dist/schema/index.js +3 -9
- package/package.json +14 -14
- package/dist/core/accounts.d.ts +0 -40
- package/dist/core/accounts.js +0 -95
- package/dist/core/css.d.ts +0 -95
- package/dist/core/css.js +0 -436
- package/dist/core/engine.d.ts +0 -75
- package/dist/core/engine.js +0 -560
- package/dist/core/errors.d.ts +0 -85
- package/dist/core/errors.js +0 -36
- package/dist/core/evidence.d.ts +0 -14
- package/dist/core/evidence.js +0 -131
- package/dist/core/labels.d.ts +0 -47
- package/dist/core/labels.js +0 -199
- package/dist/core/liveness.d.ts +0 -45
- package/dist/core/liveness.js +0 -66
- package/dist/core/marks.d.ts +0 -63
- package/dist/core/marks.js +0 -410
- package/dist/core/services.d.ts +0 -579
- package/dist/core/services.js +0 -25
- package/dist/core/share.d.ts +0 -68
- package/dist/core/share.js +0 -318
- package/dist/core/steps.d.ts +0 -106
- package/dist/core/steps.js +0 -722
- package/dist/core/uploads.d.ts +0 -49
- package/dist/core/uploads.js +0 -133
- package/dist/core/video.d.ts +0 -53
- package/dist/core/video.js +0 -241
- package/dist/core/viewport.d.ts +0 -28
- package/dist/core/viewport.js +0 -50
- package/dist/report/assets.d.ts +0 -34
- package/dist/report/assets.js +0 -105
- package/dist/report/bug.d.ts +0 -11
- package/dist/report/bug.js +0 -20
- package/dist/report/html.d.ts +0 -47
- package/dist/report/html.js +0 -923
- package/dist/report/icons.d.ts +0 -51
- package/dist/report/icons.js +0 -93
- package/dist/report/live.d.ts +0 -7
- package/dist/report/live.js +0 -135
- package/dist/report/logos.d.ts +0 -4
- package/dist/report/logos.js +0 -19
- package/dist/report/markup.d.ts +0 -50
- package/dist/report/markup.js +0 -156
- package/dist/report/menu-bar.d.ts +0 -60
- package/dist/report/menu-bar.js +0 -157
- package/dist/report/player.d.ts +0 -102
- package/dist/report/player.js +0 -315
- package/dist/report/pr-summary.d.ts +0 -11
- package/dist/report/pr-summary.js +0 -119
- package/dist/report/sha256.d.ts +0 -9
- package/dist/report/sha256.js +0 -97
- package/dist/report/share-page.d.ts +0 -48
- package/dist/report/share-page.js +0 -291
- package/dist/report/shots.d.ts +0 -59
- package/dist/report/shots.js +0 -280
- package/dist/report/sign-in.d.ts +0 -41
- package/dist/report/sign-in.js +0 -568
- package/dist/report/styles.d.ts +0 -3
- package/dist/report/styles.js +0 -274
- package/dist/report/view.d.ts +0 -296
- package/dist/report/view.js +0 -702
- package/dist/report/walkthrough.d.ts +0 -93
- package/dist/report/walkthrough.js +0 -716
- package/dist/schema/accounts.d.ts +0 -137
- package/dist/schema/accounts.js +0 -121
- package/dist/schema/config.d.ts +0 -7
- package/dist/schema/config.js +0 -6
- package/dist/schema/doctor.d.ts +0 -46
- package/dist/schema/doctor.js +0 -30
- package/dist/schema/evidence.d.ts +0 -1115
- package/dist/schema/evidence.js +0 -565
- package/dist/schema/findings.d.ts +0 -161
- package/dist/schema/findings.js +0 -82
- package/dist/schema/job.d.ts +0 -1905
- package/dist/schema/job.js +0 -577
- package/dist/schema/ledger.d.ts +0 -1124
- package/dist/schema/ledger.js +0 -285
- package/dist/schema/share.d.ts +0 -55
- package/dist/schema/share.js +0 -64
- package/dist/schema/status.d.ts +0 -7
- package/dist/schema/status.js +0 -11
package/dist/report/shots.js
DELETED
|
@@ -1,280 +0,0 @@
|
|
|
1
|
-
import { clampBox, clipBox, contentWithin, outsetBox, placeLabels } from '../core/index.js';
|
|
2
|
-
import { html, icon, Markup, safeRelative } from './markup.js';
|
|
3
|
-
import { CROP_NARROW as NARROW, CROP_WIDE as WIDE, cropAround, } from './view.js';
|
|
4
|
-
/*
|
|
5
|
-
* Screenshots as the report shows them: each image untouched, with what code knows about it drawn
|
|
6
|
-
* over it: the agent's highlights (numbered, red or green) where code placed them, and (dashed) the
|
|
7
|
-
* element the step acted on, measured as it ran. Nothing is drawn where it was not placed or
|
|
8
|
-
* measured; the legend says why instead.
|
|
9
|
-
*/
|
|
10
|
-
const pct = (n, of) => `${Math.round((n / of) * 1e6) / 1e4}%`;
|
|
11
|
-
/** A box over the part of an image a frame shows, as CSS percentages of that part. */
|
|
12
|
-
const boxStyle = (box, frame) => `left:${pct(box.x - frame.x, frame.width)};top:${pct(box.y - frame.y, frame.height)};` +
|
|
13
|
-
`width:${pct(box.width, frame.width)};height:${pct(box.height, frame.height)}`;
|
|
14
|
-
/*
|
|
15
|
-
* Sizes of what is drawn over a frame, in CSS pixels, for a frame `f` CSS pixels wide: the same
|
|
16
|
-
* as the styles work out with container units (`.mk`, `.mk-n`), so labels are placed where they
|
|
17
|
-
* will be. Lines and labels get thinner and smaller on narrow frames, down to a readable least.
|
|
18
|
-
*/
|
|
19
|
-
const clamp = (least, value, most) => Math.min(most, Math.max(least, value));
|
|
20
|
-
/** How far a box's line and its rings reach outside the element: gap, line, outer rings. */
|
|
21
|
-
const reach = (f) => clamp(1, 0.0025 * f, 2) + clamp(1.5, 0.004 * f, 3) + 2;
|
|
22
|
-
/** A label: bold text with its padding and ring. */
|
|
23
|
-
const labelSize = (text, f) => {
|
|
24
|
-
const font = clamp(10, 0.02 * f, 12);
|
|
25
|
-
return { width: text.length * 0.62 * font + font + 3, height: font * 1.4 + 5 };
|
|
26
|
-
};
|
|
27
|
-
/** How far a label sits from the outer ring of its box. */
|
|
28
|
-
const LABEL_GAP = 4;
|
|
29
|
-
/**
|
|
30
|
-
* The sides of `box` that are cut by the frame (`cut-*`: the element goes on past it, so its line
|
|
31
|
-
* there is not shown) or, where the frame shows it whole, on the edge of the image (`fl-*`: no
|
|
32
|
-
* room outside, so its line there is drawn inside). A side the frame cuts is never drawn, even
|
|
33
|
-
* when the element reaches the image's edge further on: a line there would cover what is marked
|
|
34
|
-
* and say the element ends where it does not. Labels line up with the frame's edge on either.
|
|
35
|
-
*/
|
|
36
|
-
const edgeSides = (box, frame, width, height) => {
|
|
37
|
-
const side = (name, pastFrame, atImage) => pastFrame ? ` cut-${name}` : atImage ? ` fl-${name}` : '';
|
|
38
|
-
const [right, bottom] = [box.x + box.width, box.y + box.height];
|
|
39
|
-
return [
|
|
40
|
-
side('l', box.x < frame.x - 0.5, box.x <= 0.5),
|
|
41
|
-
side('t', box.y < frame.y - 0.5, box.y <= 0.5),
|
|
42
|
-
side('r', right > frame.x + frame.width + 0.5, right >= width - 0.5),
|
|
43
|
-
side('b', bottom > frame.y + frame.height + 0.5, bottom >= height - 0.5),
|
|
44
|
-
].join('');
|
|
45
|
-
};
|
|
46
|
-
/**
|
|
47
|
-
* The boxes over the part of an image a frame shows (`frame`, in image pixels): each over its
|
|
48
|
-
* element, with its line drawn outside it, and its label outside that, clear of the other boxes
|
|
49
|
-
* and off the page's other `elements` where it can be. Labels are placed for the narrowest the
|
|
50
|
-
* frame is shown (`minWidth` CSS pixels), where they take most of the image.
|
|
51
|
-
*/
|
|
52
|
-
const overlays = (items, frame, size, minWidth, elements) => {
|
|
53
|
-
const scale = frame.width / minWidth;
|
|
54
|
-
const inFrame = (box) => {
|
|
55
|
-
const part = clipBox(box, frame);
|
|
56
|
-
return { ...part, x: part.x - frame.x, y: part.y - frame.y };
|
|
57
|
-
};
|
|
58
|
-
const boxes = items.map((item) => clipBox(item.box, frame));
|
|
59
|
-
const places = placeLabels(frame, items.map((item) => {
|
|
60
|
-
const label = labelSize(item.label, minWidth);
|
|
61
|
-
return {
|
|
62
|
-
box: inFrame(outsetBox(item.box, reach(minWidth) * scale)),
|
|
63
|
-
label: { width: label.width * scale, height: label.height * scale },
|
|
64
|
-
// The step's label goes below its element when it can: a step acts mostly on fields and
|
|
65
|
-
// buttons, with their own labels above; and it keeps clear of the agent's numbers above.
|
|
66
|
-
prefer: item.kind === 'step' ? 'below' : 'above',
|
|
67
|
-
};
|
|
68
|
-
}), LABEL_GAP * scale, elements.map(inFrame).filter((box) => box.width > 0 && box.height > 0));
|
|
69
|
-
return items.map((item, i) => {
|
|
70
|
-
const { spot, shift } = places[i];
|
|
71
|
-
// A shift is in image pixels; labels have a CSS size, so it goes back to CSS pixels.
|
|
72
|
-
return html `<span
|
|
73
|
-
class="${`mk mk-${item.kind}${edgeSides(item.box, frame, size.width, size.height)}`}"
|
|
74
|
-
style="${boxStyle(boxes[i], frame)}"
|
|
75
|
-
><span
|
|
76
|
-
class="mk-n at-${spot}"
|
|
77
|
-
${shift > 0 ? html ` style="${`margin-left:${Math.round(shift / scale)}px`}"` : ''}
|
|
78
|
-
>${item.label}</span
|
|
79
|
-
></span
|
|
80
|
-
>`;
|
|
81
|
-
});
|
|
82
|
-
};
|
|
83
|
-
/** The image in a frame that shows only `frame`'s part of it, scaled up to fill the frame. */
|
|
84
|
-
const zoomedStyle = (frame, imageWidth) => `width:${pct(imageWidth, frame.width)};left:${pct(-frame.x, frame.width)};top:${pct(-frame.y, frame.height)}`;
|
|
85
|
-
export const markWord = { red: 'Problem', green: 'As expected' };
|
|
86
|
-
/** Where to open a report whose screenshots or video cannot load. */
|
|
87
|
-
export const OPEN_FROM_RUN_FOLDER = 'Open this report from its run folder in a browser';
|
|
88
|
-
/**
|
|
89
|
-
* What a screenshot's frame says when its image cannot load. It lies under the image, so without
|
|
90
|
-
* script it shows only then; the page's script also hides the boxes drawn over the frame.
|
|
91
|
-
*/
|
|
92
|
-
const unloadedShot = (href) => html `<span class="unloaded" aria-hidden="true"
|
|
93
|
-
><strong>Screenshot didn't load:</strong> <code>${href}</code>. ${OPEN_FROM_RUN_FOLDER}.</span
|
|
94
|
-
>`;
|
|
95
|
-
const sameCrop = (a, b) => a === b ||
|
|
96
|
-
(a !== undefined &&
|
|
97
|
-
b !== undefined &&
|
|
98
|
-
a.x === b.x &&
|
|
99
|
-
a.y === b.y &&
|
|
100
|
-
a.width === b.width &&
|
|
101
|
-
a.height === b.height);
|
|
102
|
-
/**
|
|
103
|
-
* The frames a screenshot is shown in: zoomed in on its boxes (whole when it has none, they take
|
|
104
|
-
* most of it, or `whole` is asked for), with the boxes drawn over the untouched image, linking to
|
|
105
|
-
* `link`. One frame, or one for wide and one for narrow figures when their crops differ.
|
|
106
|
-
*/
|
|
107
|
-
export const framesOf = (options) => {
|
|
108
|
-
const { src, link, external, size, items, elements, alt } = options;
|
|
109
|
-
const boxes = items.map((item) => ({ ...item.box, content: item.content }));
|
|
110
|
-
const [wide, narrow] = size && options.whole !== true
|
|
111
|
-
? [WIDE, NARROW].map((crop) => cropAround(size.width, size.height, boxes, crop))
|
|
112
|
-
: [undefined, undefined];
|
|
113
|
-
const variants = sameCrop(wide, narrow)
|
|
114
|
-
? [{ crop: wide, variant: '', min: options.whole ? WIDE.frame : NARROW.frame }]
|
|
115
|
-
: [
|
|
116
|
-
{ crop: wide, variant: ' v-wide', min: WIDE.frame },
|
|
117
|
-
{ crop: narrow, variant: ' v-narrow', min: NARROW.frame },
|
|
118
|
-
];
|
|
119
|
-
const frames = variants.map(({ crop, variant, min }) => {
|
|
120
|
-
const frame = crop ?? (size ? { x: 0, y: 0, width: size.width, height: size.height } : undefined);
|
|
121
|
-
return html `<a
|
|
122
|
-
class="${`frame${crop ? ' zoom' : ''}${variant}`}"
|
|
123
|
-
href="${link}"
|
|
124
|
-
${external ? html ` target="_blank" rel="noopener"` : ''}
|
|
125
|
-
${frame ? html ` style="${`aspect-ratio:${frame.width} / ${frame.height}`}"` : ''}
|
|
126
|
-
${options.attrs ?? ''}
|
|
127
|
-
>${unloadedShot(options.file)}<img
|
|
128
|
-
src="${src}"
|
|
129
|
-
alt="${alt(crop !== undefined)}"
|
|
130
|
-
loading="lazy"
|
|
131
|
-
${crop && size ? html ` style="${zoomedStyle(crop, size.width)}"` : ''}
|
|
132
|
-
/>${size && frame ? overlays(items, frame, size, min, elements) : ''}</a
|
|
133
|
-
>`;
|
|
134
|
-
});
|
|
135
|
-
/** The note that a frame is zoomed in, for each frame that is. */
|
|
136
|
-
const zoomed = variants
|
|
137
|
-
.filter(({ crop }) => crop !== undefined)
|
|
138
|
-
.map(({ variant }) => html ` <span class="${`zoomed${variant}`}">(zoomed in; opens whole)</span>`);
|
|
139
|
-
return { frames, zoomed };
|
|
140
|
-
};
|
|
141
|
-
/** What is drawn over a screenshot, and what is said instead where nothing could be drawn. */
|
|
142
|
-
const shotMarks = (shot) => {
|
|
143
|
-
const record = shot.shot;
|
|
144
|
-
const size = record && record.width > 0 && record.height > 0 ? record : undefined;
|
|
145
|
-
const measured = size && record?.target;
|
|
146
|
-
// Older runs could record a box off the image; it is said in words instead of drawn.
|
|
147
|
-
const targetBox = measured && clampBox(measured, size.width, size.height) !== undefined ? measured : undefined;
|
|
148
|
-
const targetProblem = targetBox === undefined
|
|
149
|
-
? (record?.targetProblem ??
|
|
150
|
-
(measured ? 'the element was outside this screenshot' : undefined))
|
|
151
|
-
: undefined;
|
|
152
|
-
const placed = shot.marks.map((mark, i) => ({ mark, n: i + 1 }));
|
|
153
|
-
const drawn = size ? placed.filter(({ mark }) => mark.box !== undefined) : [];
|
|
154
|
-
const items = [
|
|
155
|
-
...drawn.map(({ mark, n }) => ({
|
|
156
|
-
kind: mark.mark,
|
|
157
|
-
box: mark.box,
|
|
158
|
-
content: mark.content,
|
|
159
|
-
label: String(n),
|
|
160
|
-
})),
|
|
161
|
-
...(targetBox
|
|
162
|
-
? [
|
|
163
|
-
{
|
|
164
|
-
kind: 'step',
|
|
165
|
-
box: targetBox,
|
|
166
|
-
content: contentWithin(record?.targetContent, targetBox),
|
|
167
|
-
label: `Step ${record?.step}`,
|
|
168
|
-
},
|
|
169
|
-
]
|
|
170
|
-
: []),
|
|
171
|
-
];
|
|
172
|
-
return { record, size, targetBox, targetProblem, placed, drawn, items };
|
|
173
|
-
};
|
|
174
|
-
const markLegend = (mark, n) => html `<li class="lg-${mark.mark}${mark.box ? '' : ' unplaced'}" value="${n}">
|
|
175
|
-
<span class="key">${n}</span>
|
|
176
|
-
<span
|
|
177
|
-
><strong>${markWord[mark.mark]}</strong>${mark.note ? html `: ${mark.note}` : ''}
|
|
178
|
-
<span class="note"
|
|
179
|
-
>(${mark.target}${mark.box
|
|
180
|
-
? mark.ignored
|
|
181
|
-
? `; ${mark.ignored}`
|
|
182
|
-
: ''
|
|
183
|
-
: html `; not drawn: ${mark.problem ?? 'not found'}`})</span
|
|
184
|
-
></span
|
|
185
|
-
>
|
|
186
|
-
</li>`;
|
|
187
|
-
/** The legend of a screenshot's marks, including the ones that could not be drawn. */
|
|
188
|
-
const legendOf = (marks) => {
|
|
189
|
-
const { record, targetBox, targetProblem, placed } = marks;
|
|
190
|
-
return placed.length > 0 || targetBox || targetProblem
|
|
191
|
-
? html `<ol class="mk-legend">
|
|
192
|
-
${targetBox ? html `<li class="lg-step" value="0"><span class="key"></span>Step ${record?.step} acted on this element <span class="note">(code)</span></li>` : ''}
|
|
193
|
-
${targetProblem ? html `<li class="lg-step unplaced" value="0"><span class="key"></span>Step ${record?.step} acted on an element not drawn here <span class="note">(code; not drawn: ${targetProblem})</span></li>` : ''}
|
|
194
|
-
${placed.map(({ mark, n }) => markLegend(mark, n))}
|
|
195
|
-
</ol>`
|
|
196
|
-
: '';
|
|
197
|
-
};
|
|
198
|
-
/** What a shot is called in the viewer: `Actual`, `Expected`, or the step it was taken at. */
|
|
199
|
-
export const shotCaption = (shot) => shot.role === 'actual'
|
|
200
|
-
? 'Actual'
|
|
201
|
-
: shot.role === 'expected'
|
|
202
|
-
? 'Expected'
|
|
203
|
-
: (shot.step ?? shot.name);
|
|
204
|
-
/**
|
|
205
|
-
* A screenshot in a case card: a frame zoomed in on its marks (whole when it has none) that opens
|
|
206
|
-
* the screenshot viewer at it (`n`, its place in the case), or the image itself without script.
|
|
207
|
-
* `large` ones (Actual, Expected) carry their label under them.
|
|
208
|
-
*/
|
|
209
|
-
export const cardShot = (view, shot, n, large, assets) => {
|
|
210
|
-
const file = safeRelative(shot.shot.path);
|
|
211
|
-
const label = shotCaption(shot);
|
|
212
|
-
if (file === undefined)
|
|
213
|
-
return html `<span class="thumb missing">${label}: ${shot.shot.path} (not shown)</span>`;
|
|
214
|
-
const href = assets.url(file);
|
|
215
|
-
const marks = shotMarks(shot.shot);
|
|
216
|
-
const { frames } = framesOf({
|
|
217
|
-
src: href,
|
|
218
|
-
file,
|
|
219
|
-
link: href,
|
|
220
|
-
external: true,
|
|
221
|
-
size: marks.size,
|
|
222
|
-
items: large ? marks.items : [],
|
|
223
|
-
elements: shot.shot.elements,
|
|
224
|
-
alt: (zoom) => `Screenshot of case ${view.entry.title}: ${label}${shot.role === 'shot' ? '' : ` (${shot.step ?? shot.name})`}${zoom ? ', zoomed in on its marks' : ''}`,
|
|
225
|
-
attrs: html ` data-shot="${String(n)}"`,
|
|
226
|
-
});
|
|
227
|
-
return html `<figure class="${`shot thumb${large ? ' large' : ''} role-${shot.role}`}">
|
|
228
|
-
${frames} ${large ? html `<figcaption>${label}</figcaption>` : ''}
|
|
229
|
-
</figure>`;
|
|
230
|
-
};
|
|
231
|
-
/**
|
|
232
|
-
* A screenshot as the viewer shows it: the whole image with its marks (a checkbox shows and hides
|
|
233
|
-
* them, with no script), its name, ID and when it was taken (`time`, a link that plays the video
|
|
234
|
-
* from there), the file, and the legend of its marks.
|
|
235
|
-
*/
|
|
236
|
-
export const viewerShot = (shot, time, assets) => {
|
|
237
|
-
const file = safeRelative(shot.shot.path);
|
|
238
|
-
const caption = shotCaption(shot);
|
|
239
|
-
if (file === undefined)
|
|
240
|
-
return html `<figure class="vshot missing" data-cap="${caption}">
|
|
241
|
-
<figcaption>${shot.shot.path} (not shown)</figcaption>
|
|
242
|
-
</figure>`;
|
|
243
|
-
const marks = shotMarks(shot.shot);
|
|
244
|
-
const { record } = marks;
|
|
245
|
-
const href = assets.url(file);
|
|
246
|
-
const toggleId = `marks-${record?.id ?? file.replace(/[^A-Za-z0-9]/g, '-')}`;
|
|
247
|
-
const hasMarks = marks.drawn.length > 0 || marks.targetBox !== undefined;
|
|
248
|
-
const { frames } = framesOf({
|
|
249
|
-
src: href,
|
|
250
|
-
file,
|
|
251
|
-
link: href,
|
|
252
|
-
external: true,
|
|
253
|
-
size: marks.size,
|
|
254
|
-
items: marks.items,
|
|
255
|
-
elements: shot.shot.elements,
|
|
256
|
-
whole: true,
|
|
257
|
-
alt: () => `Screenshot: ${shot.name}${marks.drawn.length > 0 ? `, with ${marks.drawn.length} marked ${marks.drawn.length === 1 ? 'element' : 'elements'}` : ''}`,
|
|
258
|
-
});
|
|
259
|
-
return html `<figure class="shot vshot" data-cap="${caption}">
|
|
260
|
-
${hasMarks ? html `<input type="checkbox" class="mk-toggle" id="${toggleId}" checked />` : ''}
|
|
261
|
-
${frames}
|
|
262
|
-
<figcaption>
|
|
263
|
-
<span class="cap">
|
|
264
|
-
<span>${shot.name}</span>
|
|
265
|
-
${record ? html `<span class="shot-id">${record.id}</span>` : ''} ${time}
|
|
266
|
-
${hasMarks
|
|
267
|
-
? html `<label class="mk-switch" for="${toggleId}"
|
|
268
|
-
>${icon('check', { size: 12, strokeWidth: 2.5, className: 'i-on' })}${icon('x', {
|
|
269
|
-
size: 12,
|
|
270
|
-
strokeWidth: 2.5,
|
|
271
|
-
className: 'i-off',
|
|
272
|
-
})}Marks</label
|
|
273
|
-
>`
|
|
274
|
-
: ''}
|
|
275
|
-
<a class="file" href="${href}" target="_blank" rel="noopener">${file}</a>
|
|
276
|
-
</span>
|
|
277
|
-
${legendOf(marks)}
|
|
278
|
-
</figcaption>
|
|
279
|
-
</figure>`;
|
|
280
|
-
};
|
package/dist/report/sign-in.d.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Rive's web runtime (its canvas renderer without text and audio, which the animation does not
|
|
3
|
-
* use), on jsDelivr at an exact version: the script, taken only with `RIVE_JS_SRI`, and its
|
|
4
|
-
* WebAssembly, which the script fetches.
|
|
5
|
-
*/
|
|
6
|
-
export declare const RIVE_RUNTIME = "https://cdn.jsdelivr.net/npm/@rive-app/canvas-lite@2.48.0/";
|
|
7
|
-
/** The runtime script's Subresource Integrity hash: any other script at that URL is refused. */
|
|
8
|
-
export declare const RIVE_JS_SRI = "sha384-KKLeoe6TCJ0x8AYfmSeeOfpT6u1rpxnG6clu8dKuLNqMImJV40kWrCVhTU7lmcNg";
|
|
9
|
-
/**
|
|
10
|
-
* The animation the page plays (the bug kicks a lock open when the person starts), on screw-bugs'
|
|
11
|
-
* CDN, which allows any page to fetch it. The page is the same without it when it cannot load.
|
|
12
|
-
*/
|
|
13
|
-
export declare const SIGN_IN_ANIMATION = "https://static.screwbugs.dev/animations/auth-required.riv";
|
|
14
|
-
/**
|
|
15
|
-
* The script of the live view, with no values of its own (they are data attributes), so its
|
|
16
|
-
* hash is fixed. Frames come by long polling `frame?after=<seq>`; inputs go out in order, one
|
|
17
|
-
* request at a time, mouse moves merged. `410` from any route means the sign-in ended.
|
|
18
|
-
*/
|
|
19
|
-
export declare const SIGN_IN_SCRIPT = "(() => {\n 'use strict';\n const RIVE = 'https://cdn.jsdelivr.net/npm/@rive-app/canvas-lite@2.48.0/', RIVE_JS_SRI = 'sha384-KKLeoe6TCJ0x8AYfmSeeOfpT6u1rpxnG6clu8dKuLNqMImJV40kWrCVhTU7lmcNg', ANIMATION = 'https://static.screwbugs.dev/animations/auth-required.riv';\n // The animation's state while the bug waits by the lock (its `kick` trigger works only then),\n // and how long after the kick the bug has run off, when the browser shows (at most\n // `KICK_WAIT_MAX` after the person started, however long the bug took to reach the lock).\n const WAITING = 'Wait (idle)', KICK_MS = 2300, KICK_WAIT_MAX = 6000;\n const base = location.pathname.replace(/\\/+$/, '');\n const $ = (id) => document.getElementById(id);\n const img = $('screen'), stage = $('stage'), kb = $('keys'), addr = $('addr'), note = $('note');\n let seq = 0, fw = 1280, fh = 800, over = false, saving = false;\n const sleep = (ms) => new Promise((r) => setTimeout(r, ms));\n\n const end = (text) => {\n over = true;\n document.body.classList.add('over');\n note.textContent = text;\n $('ended').textContent = text;\n };\n const GONE = 'This sign-in has ended (it closes after 15 minutes without use), so nothing was saved. Ask your coding agent to start its job again for a new link.';\n\n const queue = [];\n // Inputs per request: under the server's limit (100, and 256 KB with text of up to 2000).\n const BATCH = 50;\n let sending = false;\n // Whether an input may not have reached the browser: Save then asks to check the page first.\n let lost = false;\n const flush = async () => {\n if (sending || over || queue.length === 0) return;\n sending = true;\n const batch = queue.splice(0, BATCH);\n try {\n const r = await fetch(base + '/input', {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify(batch),\n });\n if (r.status === 410) end('This sign-in has ended. You can close this tab.');\n else if (!r.ok) lost = true;\n } catch {\n // It may or may not have been played; sending it again could type twice.\n lost = true;\n await sleep(500);\n }\n if (lost && !over) note.textContent = 'Some input may not have reached the browser; check the page shows what you expect.';\n sending = false;\n flush();\n };\n const send = (input) => {\n // Nothing more goes in once Save was pressed: the session is what the inputs before it made.\n if (saving || over) return;\n const last = queue[queue.length - 1];\n if (input.type === 'mouse' && input.kind === 'move' && last && last.type === 'mouse' && last.kind === 'move') queue[queue.length - 1] = input;\n else queue.push(input);\n flush();\n };\n\n const frames = async () => {\n let failures = 0;\n while (!over) {\n try {\n const r = await fetch(base + '/frame?after=' + seq, { cache: 'no-store' });\n failures = 0;\n if (r.status === 410) return end('This sign-in has ended. You can close this tab.');\n if (r.status === 200) {\n const f = await r.json();\n seq = f.seq; fw = f.width; fh = f.height;\n img.src = 'data:image/jpeg;base64,' + f.jpeg;\n addr.textContent = f.url;\n } else if (r.status !== 204) await sleep(1000);\n } catch {\n // Its server is gone (it ended, or the agent's process stopped): say so rather than wait.\n if (++failures >= 3) return end(GONE);\n await sleep(1000);\n }\n }\n };\n\n let sized;\n const resize = () => {\n clearTimeout(sized);\n sized = setTimeout(() => send({ type: 'viewport', width: Math.round(stage.clientWidth), height: Math.round(stage.clientHeight) }), 250);\n };\n addEventListener('resize', resize);\n\n const at = (e) => {\n const r = img.getBoundingClientRect();\n return {\n x: Math.round(((e.clientX - r.left) * fw) / Math.max(1, r.width)),\n y: Math.round(((e.clientY - r.top) * fh) / Math.max(1, r.height)),\n };\n };\n const button = (b) => (b === 1 ? 'middle' : b === 2 ? 'right' : 'left');\n let touch;\n img.addEventListener('contextmenu', (e) => e.preventDefault());\n img.addEventListener('pointerdown', (e) => {\n e.preventDefault();\n kb.focus({ preventScroll: true });\n img.setPointerCapture(e.pointerId);\n const p = at(e);\n if (e.pointerType === 'mouse') send({ type: 'mouse', kind: 'down', ...p, button: button(e.button), clickCount: Math.min(3, Math.max(1, e.detail || 1)) });\n else touch = { x: e.clientX, y: e.clientY, moved: false };\n });\n img.addEventListener('pointermove', (e) => {\n const p = at(e);\n if (e.pointerType === 'mouse') return send({ type: 'mouse', kind: 'move', ...p });\n if (!touch) return;\n const dx = e.clientX - touch.x, dy = e.clientY - touch.y;\n if (!touch.moved && Math.hypot(dx, dy) < 8) return;\n touch.moved = true;\n const scale = fw / Math.max(1, img.getBoundingClientRect().width);\n send({ type: 'wheel', ...p, dx: Math.round(-dx * scale), dy: Math.round(-dy * scale) });\n touch.x = e.clientX; touch.y = e.clientY;\n });\n img.addEventListener('pointerup', (e) => {\n const p = at(e);\n if (e.pointerType === 'mouse') return send({ type: 'mouse', kind: 'up', ...p, button: button(e.button), clickCount: Math.min(3, Math.max(1, e.detail || 1)) });\n if (touch && !touch.moved) {\n send({ type: 'mouse', kind: 'move', ...p });\n send({ type: 'mouse', kind: 'down', ...p, button: 'left', clickCount: 1 });\n send({ type: 'mouse', kind: 'up', ...p, button: 'left', clickCount: 1 });\n }\n touch = undefined;\n });\n img.addEventListener('pointercancel', () => { touch = undefined; });\n img.addEventListener('wheel', (e) => {\n e.preventDefault();\n const unit = e.deltaMode === 1 ? 16 : e.deltaMode === 2 ? fh : 1;\n send({ type: 'wheel', ...at(e), dx: Math.round(e.deltaX * unit), dy: Math.round(e.deltaY * unit) });\n }, { passive: false });\n\n const ignored = new Set(['Shift', 'Control', 'Alt', 'Meta', 'CapsLock', 'Unidentified', 'Dead', 'Process', 'Compose']);\n let composing = false;\n kb.addEventListener('compositionstart', () => { composing = true; });\n kb.addEventListener('compositionend', () => { composing = false; typed(); });\n kb.addEventListener('keydown', (e) => {\n if (e.isComposing || e.keyCode === 229 || ignored.has(e.key)) return;\n // A character typed with AltGr (an @ on many European keyboards, where it also reports Ctrl\n // and Alt) or with Option on a Mac is text, not a shortcut: the box gets it as input.\n const altGraph = e.getModifierState && e.getModifierState('AltGraph');\n if (e.key.length === 1 && (altGraph || (e.altKey && !e.ctrlKey && !e.metaKey))) return;\n const command = e.ctrlKey || e.metaKey || e.altKey;\n // Pasting goes in as text, from the paste itself.\n if (command && e.key.toLowerCase() === 'v') return;\n if (e.key.length === 1 && !command) return;\n e.preventDefault();\n const modifiers = [e.altKey && 'Alt', e.ctrlKey && 'Control', e.metaKey && 'Meta', e.shiftKey && 'Shift'].filter(Boolean);\n send({ type: 'key', key: e.key, modifiers });\n });\n // The box always holds one invisible character, so a phone keyboard's Backspace (often only\n // keyCode 229 or 'Unidentified' on keydown) has something to delete, which shows below.\n const MARK = '\u200B';\n const reset = () => {\n kb.value = MARK;\n kb.setSelectionRange(1, 1);\n };\n const typed = () => {\n if (composing) return;\n const value = kb.value;\n const text = value.split(MARK).join('');\n if (!value.includes(MARK) && !text) send({ type: 'key', key: 'Backspace', modifiers: [] });\n if (text) send({ type: 'text', text: text.slice(0, 2000) });\n reset();\n };\n kb.addEventListener('beforeinput', (e) => {\n // Deleting, as keyboards that send no key for it say it: played as the key itself.\n const key = e.inputType === 'deleteContentBackward' ? 'Backspace' : e.inputType === 'deleteContentForward' ? 'Delete' : undefined;\n if (key === undefined || !e.cancelable) return;\n e.preventDefault();\n send({ type: 'key', key, modifiers: [] });\n });\n kb.addEventListener('input', typed);\n kb.addEventListener('focus', reset);\n reset();\n\n $('back').addEventListener('click', () => send({ type: 'nav', kind: 'back' }));\n $('reload').addEventListener('click', () => send({ type: 'nav', kind: 'reload' }));\n const post = async (route) => {\n const r = await fetch(base + '/' + route, { method: 'POST', headers: { 'content-type': 'application/json' }, body: '{}' });\n return r;\n };\n /** Until every input already given has been played (or the sign-in ended). */\n const drained = async () => {\n while (!over && (sending || queue.length > 0)) await sleep(50);\n };\n $('save').addEventListener('click', async () => {\n if (saving || over) return;\n saving = true;\n document.body.classList.add('saving');\n note.textContent = 'Saving\u2026';\n try {\n await drained();\n if (over) return;\n if (lost) {\n lost = false;\n saving = false;\n document.body.classList.remove('saving');\n note.textContent = 'Some input did not reach the browser, so nothing was saved yet. Check the page shows you signed in, then press Save sign-in again.';\n return;\n }\n const r = await post('save');\n if (r.ok) return end('Saved. You can close this tab; your coding agent can start the run again.');\n if (r.status === 410) return end('This sign-in has ended. You can close this tab.');\n note.textContent = 'Could not save: ' + (await r.text());\n } catch {\n note.textContent = 'Could not reach screw-bugs to save. Try again.';\n }\n saving = false;\n document.body.classList.remove('saving');\n });\n $('cancel').addEventListener('click', async () => {\n try { await post('cancel'); } catch {}\n end('Cancelled. Nothing was saved. You can close this tab.');\n });\n\n // The theme: light, dark or the system's, in turn, as on screw-bugs Cloud's menu bar (the\n // reports' tokens follow `data-theme`). Not kept: each sign-in is a new origin.\n const themeCycle=(b,key)=>{\n const r=document.documentElement,T=['light','dark','system'],N={light:'Light theme',dark:'Dark theme',system:'Theme from system'};\n const at=()=>{const i=T.indexOf(r.dataset.theme);return i<0?2:i};\n const show=()=>{const i=at(),f=document.getElementById('favicon'),h=f&&f.dataset[T[i]];if(h)f.href=h;b.setAttribute('aria-label',N[T[i]]+'. Switch to '+N[T[(i+1)%3]].toLowerCase());b.title=N[T[i]]};\n show();\n b.addEventListener('click',()=>{const m=T[(at()+1)%3];r.dataset.theme=m;if(key)try{localStorage.setItem(key,m)}catch(e){}show()});\n};\n themeCycle(document.querySelector('.menubar .theme'));\n\n // The animation: the bug waits by a lock, and kicks it open when the person starts. It plays\n // with Rive's runtime from its CDN (taken only with the hash it was published with) and the file\n // from screw-bugs' CDN. Without either, or where the person prefers less motion, the page is the\n // same without it.\n const art = $('art');\n // `instance` from when it is made, `rive` once its file loaded; `stopped` once the art is gone\n // for good (it failed, or the person started), so nothing that loads later plays.\n let instance, rive, observer, stopped = false, waiting = false, onWaiting;\n const noArt = () => {\n stopped = true;\n if (art) art.hidden = true;\n if (observer) observer.disconnect();\n try {\n if (instance) instance.cleanup();\n } catch {}\n instance = rive = observer = undefined;\n };\n if (art && !matchMedia('(prefers-reduced-motion: reduce)').matches) {\n const runtime = document.createElement('script');\n runtime.src = RIVE + 'rive.js';\n runtime.integrity = RIVE_JS_SRI;\n runtime.crossOrigin = 'anonymous';\n runtime.onerror = noArt;\n runtime.onload = () => {\n if (stopped) return;\n try {\n const R = window.rive;\n // The runtime is pinned, so the state changes it still gives are what this relies on.\n R.Rive.suppressDeprecationWarnings = ['state-change-events'];\n R.RuntimeLoader.setWasmUrl(RIVE + 'rive.wasm');\n R.RuntimeLoader.setWasmFallbackUrl(RIVE + 'rive_fallback.wasm');\n const canvas = art.querySelector('canvas');\n const r = new R.Rive({\n src: ANIMATION,\n canvas,\n autoplay: true,\n stateMachine: 'Main',\n // Binds the file's view model, whose `kick` trigger starts the kick.\n autoBind: true,\n layout: new R.Layout({ fit: R.Fit.Contain, alignment: R.Alignment.Center }),\n onLoad: () => {\n if (stopped) return;\n r.resizeDrawingSurfaceToCanvas();\n rive = r;\n },\n onLoadError: noArt,\n onStateChange: (e) => {\n for (const name of [].concat(e.data || [])) {\n if (name === WAITING) waiting = true;\n else if (name === 'Arrive' || name === 'Kick') waiting = false;\n }\n if (waiting && onWaiting) onWaiting();\n },\n });\n instance = r;\n observer = new ResizeObserver(() => rive && rive.resizeDrawingSurfaceToCanvas());\n observer.observe(canvas);\n } catch {\n noArt();\n }\n };\n document.head.appendChild(runtime);\n } else noArt();\n /** Plays the kick (once the bug waits by the lock), resolving when the bug has run off. */\n const kick = () =>\n new Promise((done) => {\n if (!rive) return done();\n const cap = setTimeout(done, KICK_WAIT_MAX);\n onWaiting = () => {\n onWaiting = undefined;\n try {\n rive.viewModelInstance.trigger('kick').trigger();\n } catch {\n clearTimeout(cap);\n return done();\n }\n setTimeout(() => {\n clearTimeout(cap);\n done();\n }, KICK_MS);\n };\n if (waiting) onWaiting();\n });\n\n // The explainer comes first; the browser shows (and its frames start) once the person starts.\n // Start shows a spinner and takes no more clicks from the click until the browser shows; a\n // failed check gives it back.\n const start = $('start'), startError = $('start-error');\n let starting = false;\n const busy = (on) => {\n starting = on;\n start.disabled = on;\n start.classList.toggle('loading', on);\n if (on) start.setAttribute('aria-busy', 'true');\n else start.removeAttribute('aria-busy');\n };\n start.addEventListener('click', async () => {\n if (starting || over) return;\n busy(true);\n startError.textContent = '';\n // Reading this takes no requests, so the sign-in may have ended meanwhile.\n try {\n const r = await fetch(base + '/status', { cache: 'no-store' });\n if (!r.ok) {\n busy(false);\n return end(GONE);\n }\n } catch {\n // Not reached at all: screw-bugs may have stopped, or the network dropped for a moment.\n busy(false);\n startError.textContent = 'Could not reach screw-bugs. Check that your coding agent is still running, then try again.';\n return;\n }\n await kick();\n noArt();\n if (over) return;\n document.body.classList.remove('intro');\n resize();\n frames();\n });\n})();";
|
|
20
|
-
/**
|
|
21
|
-
* The live view's Content-Security-Policy: its own script, frames and icons as data URLs, its own
|
|
22
|
-
* routes, Google Fonts as the reports load them (`webFonts`), Rive's runtime from its exact folder
|
|
23
|
-
* on jsDelivr (its script and WebAssembly, which needs `wasm-unsafe-eval` to run) and the
|
|
24
|
-
* animation it plays (`SIGN_IN_ANIMATION`).
|
|
25
|
-
*/
|
|
26
|
-
export declare const SIGN_IN_CSP: string;
|
|
27
|
-
/**
|
|
28
|
-
* The live view for signing in to the account `label`, which `about` describes, at the app that
|
|
29
|
-
* `site` names (its title and icon as the sign-in browser read them; its host alone without).
|
|
30
|
-
* First a card that says what happens, beside the animation (`SIGN_IN_ANIMATION`), then the
|
|
31
|
-
* browser.
|
|
32
|
-
*/
|
|
33
|
-
export declare const renderSignInPage: (account: {
|
|
34
|
-
readonly label: string;
|
|
35
|
-
readonly about: string | undefined;
|
|
36
|
-
readonly origin: string;
|
|
37
|
-
readonly site?: {
|
|
38
|
-
readonly title: string | undefined;
|
|
39
|
-
readonly icon: string | undefined;
|
|
40
|
-
};
|
|
41
|
-
}) => string;
|