screw-bugs 0.1.7 → 0.1.9
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 +83 -13
- package/dist/browser-playwright/launch.js +27 -10
- package/dist/browser-playwright/page.d.ts +50 -28
- package/dist/browser-playwright/page.js +101 -91
- package/dist/browser-playwright/recorder.d.ts +154 -0
- package/dist/browser-playwright/recorder.js +382 -0
- package/dist/build-info.json +3 -3
- package/dist/cli/commands.js +56 -11
- package/dist/cli/mcp.d.ts +11 -4
- package/dist/cli/mcp.js +86 -23
- package/dist/cli/operations.d.ts +30 -2
- package/dist/cli/operations.js +126 -20
- package/dist/cli/report-links.js +2 -2
- package/dist/cli/report-server.d.ts +41 -9
- package/dist/cli/report-server.js +139 -23
- package/dist/cli/share.d.ts +71 -4
- package/dist/cli/share.js +540 -109
- package/dist/cli/sign-in.d.ts +22 -10
- package/dist/cli/sign-in.js +23 -23
- package/dist/core/engine.js +54 -13
- package/dist/core/liveness.js +3 -1
- package/dist/core/services.d.ts +29 -4
- package/dist/core/share.d.ts +31 -0
- package/dist/core/share.js +139 -0
- package/dist/core/steps.d.ts +5 -0
- package/dist/core/steps.js +15 -1
- package/dist/core/video.d.ts +6 -0
- package/dist/core/video.js +8 -0
- package/dist/report/html.d.ts +4 -2
- package/dist/report/html.js +36 -13
- package/dist/report/icons.d.ts +3 -0
- package/dist/report/icons.js +5 -1
- package/dist/report/index.d.ts +3 -1
- package/dist/report/index.js +3 -1
- package/dist/report/live.d.ts +7 -0
- package/dist/report/live.js +135 -0
- package/dist/report/menu-bar.d.ts +3 -3
- package/dist/report/menu-bar.js +3 -3
- package/dist/report/player.d.ts +3 -3
- package/dist/report/player.js +3 -3
- package/dist/report/share-page.d.ts +48 -0
- package/dist/report/share-page.js +291 -0
- package/dist/report/styles.d.ts +2 -0
- package/dist/report/styles.js +2 -2
- package/dist/report/view.js +2 -0
- package/dist/report/walkthrough.d.ts +5 -2
- package/dist/report/walkthrough.js +17 -5
- package/dist/schema/accounts.js +10 -1
- package/dist/schema/evidence.d.ts +15 -8
- package/dist/schema/evidence.js +9 -4
- package/dist/schema/findings.js +1 -1
- package/dist/schema/job.d.ts +205 -65
- package/dist/schema/job.js +63 -11
- package/dist/schema/ledger.d.ts +80 -16
- package/dist/schema/ledger.js +36 -0
- package/dist/schema/share.d.ts +17 -0
- package/dist/schema/share.js +22 -0
- package/package.json +1 -1
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
import { Clock, Deferred, Effect, Exit, FileSystem, Queue, Stream } from 'effect';
|
|
2
|
+
import { ChildProcess, ChildProcessSpawner } from 'effect/process';
|
|
3
|
+
/**
|
|
4
|
+
* A session's video, recorded by screw-bugs itself rather than by Playwright's `recordVideo`:
|
|
5
|
+
* the tab's screencast frames (JPEG, from `page.screencast`) go to Playwright's ffmpeg as
|
|
6
|
+
* Matroska on its stdin, which writes VP9 WebM at a constant frame rate, as Playwright's own
|
|
7
|
+
* recorder does (same container, encoder settings, frame times and last frame).
|
|
8
|
+
*
|
|
9
|
+
* Two frames are left out, so the video only ever shows the page as it renders on its own:
|
|
10
|
+
*
|
|
11
|
+
* - A frame that does not fit the video's size (`fits`). Chromium sends frames at the browser's
|
|
12
|
+
* own scale whatever size is asked for, except around a device-pixel capture on an emulated
|
|
13
|
+
* phone in a browser at 1x, where one may come at full device size (3x); Playwright's recorder
|
|
14
|
+
* crops it into the video, which shows the page's top left corner magnified for one frame.
|
|
15
|
+
* - A frame painted while a screenshot is taken (`hold`). Every device-pixel capture (the step
|
|
16
|
+
* screenshots) changes how the page renders for a moment: on a phone, text comes out crisper
|
|
17
|
+
* and darker, then pale again, a flicker at every step. Such a frame is painted during the
|
|
18
|
+
* capture and often only arrives after it, so frames are judged by when they were painted.
|
|
19
|
+
*
|
|
20
|
+
* The video then holds the last frame it kept, as for any frame the browser does not send.
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* The most frames a second the video has (Playwright's recorder's rate). Unlike Playwright's, it
|
|
24
|
+
* has only the frames the page changed in (the screencast sends one only then), so a still page
|
|
25
|
+
* costs next to nothing to encode and store (`framePacer`).
|
|
26
|
+
*/
|
|
27
|
+
export const VIDEO_FPS = 25;
|
|
28
|
+
/**
|
|
29
|
+
* How much smaller than the video a frame may be (Chromium rounds the screencast's size). One a
|
|
30
|
+
* pixel larger is the page's odd last row or column, which the video leaves out (`videoSize`).
|
|
31
|
+
*/
|
|
32
|
+
export const FRAME_SLACK = 4;
|
|
33
|
+
/** How long the video shows its last frame at least, after it came (as in Playwright). */
|
|
34
|
+
export const LAST_FRAME_MS = 1_000;
|
|
35
|
+
/** How long ffmpeg gets to end after it was asked to stop, before it is killed. */
|
|
36
|
+
const FFMPEG_KILL_AFTER = '2 seconds';
|
|
37
|
+
/**
|
|
38
|
+
* How many frames may wait for ffmpeg (seconds of video at `VIDEO_FPS`, some MB of JPEG). While
|
|
39
|
+
* it is that far behind, new frames are dropped and the video holds the last one it has.
|
|
40
|
+
*/
|
|
41
|
+
export const BACKLOG_FRAMES = 10 * VIDEO_FPS;
|
|
42
|
+
/** How long ffmpeg may take, after the first frame, to open the video it writes. */
|
|
43
|
+
export const READY_TIMEOUT_MS = 3_000;
|
|
44
|
+
/** How often whether it has is looked at. */
|
|
45
|
+
const READY_POLL = '50 millis';
|
|
46
|
+
/** A JPEG's size, from its first start-of-frame segment; undefined when it has none. */
|
|
47
|
+
export const jpegSize = (bytes) => {
|
|
48
|
+
if (bytes[0] !== 0xff || bytes[1] !== 0xd8)
|
|
49
|
+
return undefined;
|
|
50
|
+
const u16 = (at) => (bytes[at] << 8) | bytes[at + 1];
|
|
51
|
+
let at = 2;
|
|
52
|
+
while (at + 3 < bytes.length) {
|
|
53
|
+
if (bytes[at] !== 0xff)
|
|
54
|
+
return undefined;
|
|
55
|
+
const marker = bytes[at + 1];
|
|
56
|
+
// Fill bytes before a marker.
|
|
57
|
+
if (marker === 0xff) {
|
|
58
|
+
at += 1;
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
// Markers without a length.
|
|
62
|
+
if (marker === 0x01 || (marker >= 0xd0 && marker <= 0xd8)) {
|
|
63
|
+
at += 2;
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
// Start of frame (baseline, progressive and the rest), not DHT, JPG or DAC.
|
|
67
|
+
if (marker >= 0xc0 && marker <= 0xcf && marker !== 0xc4 && marker !== 0xc8 && marker !== 0xcc)
|
|
68
|
+
return at + 8 < bytes.length ? { height: u16(at + 5), width: u16(at + 7) } : undefined;
|
|
69
|
+
// Start of scan or end of image: no frame header came first.
|
|
70
|
+
if (marker === 0xda || marker === 0xd9)
|
|
71
|
+
return undefined;
|
|
72
|
+
at += 2 + u16(at + 2);
|
|
73
|
+
}
|
|
74
|
+
return undefined;
|
|
75
|
+
};
|
|
76
|
+
/** Whether a frame of `frame`'s size shows the page whole in a video of `video`'s. */
|
|
77
|
+
export const fits = (frame, video) => frame.width <= video.width + 1 &&
|
|
78
|
+
frame.height <= video.height + 1 &&
|
|
79
|
+
frame.width >= video.width - FRAME_SLACK &&
|
|
80
|
+
frame.height >= video.height - FRAME_SLACK;
|
|
81
|
+
/**
|
|
82
|
+
* Which frames go on the video, and where: a frame's time on the video is its paint time (epoch
|
|
83
|
+
* ms) after the first kept frame's, so the video starts at its first frame, as Playwright's does.
|
|
84
|
+
*/
|
|
85
|
+
export const frameGate = (video) => {
|
|
86
|
+
/** Screenshots being taken (`end` undefined) or taken, by when, in epoch ms. */
|
|
87
|
+
let holds = [];
|
|
88
|
+
let first;
|
|
89
|
+
let lastMs;
|
|
90
|
+
const held = (timestamp) => holds.some((h) => timestamp >= h.start && (h.end === undefined || timestamp <= h.end));
|
|
91
|
+
return {
|
|
92
|
+
/** A screenshot starts being taken `at`; call the result when it was taken. */
|
|
93
|
+
hold: (at) => {
|
|
94
|
+
const window = { start: at, end: undefined };
|
|
95
|
+
holds.push(window);
|
|
96
|
+
return (end) => {
|
|
97
|
+
window.end = Math.max(end, at);
|
|
98
|
+
};
|
|
99
|
+
},
|
|
100
|
+
/**
|
|
101
|
+
* The frame's time on the video in ms when it is kept, else undefined: when it does not fit
|
|
102
|
+
* (`size` undefined is a frame that could not be read), was painted while a screenshot was
|
|
103
|
+
* taken, or does not come after the last kept frame (the video's frames only go forward).
|
|
104
|
+
*/
|
|
105
|
+
admit: (size, timestamp) => {
|
|
106
|
+
if (size === undefined || !fits(size, video) || held(timestamp))
|
|
107
|
+
return undefined;
|
|
108
|
+
const ms = Math.round(timestamp - (first ?? timestamp));
|
|
109
|
+
if (lastMs !== undefined && ms <= lastMs)
|
|
110
|
+
return undefined;
|
|
111
|
+
first ??= timestamp;
|
|
112
|
+
lastMs = ms;
|
|
113
|
+
// A screenshot taken before this frame was painted cannot hold back any later frame.
|
|
114
|
+
holds = holds.filter((h) => h.end === undefined || h.end >= timestamp);
|
|
115
|
+
return ms;
|
|
116
|
+
},
|
|
117
|
+
/** When the first kept frame was painted, in epoch ms. */
|
|
118
|
+
first: () => first,
|
|
119
|
+
/** The time on the video of a frame painted at `timestamp`. */
|
|
120
|
+
at: (timestamp) => Math.round(timestamp - (first ?? timestamp)),
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* When the video's last frame goes again, to end it: as Playwright does, at least `LAST_FRAME_MS`
|
|
125
|
+
* after it was painted, or as long after as the session went on without a new one.
|
|
126
|
+
*/
|
|
127
|
+
export const lastFrameTime = (paintedAt, sinceItCameMs) => paintedAt + Math.max(sinceItCameMs, LAST_FRAME_MS);
|
|
128
|
+
/**
|
|
129
|
+
* At most one frame for each `1000 / VIDEO_FPS` ms of the video, never losing the page's latest
|
|
130
|
+
* state: the first frame in a slot after the last written one is written at once; a later one in
|
|
131
|
+
* that slot waits, replacing the one waiting, and is written at the start of the next slot when a
|
|
132
|
+
* frame comes after that slot, or at the end (`flush`). `ms` (time on the video) only grows.
|
|
133
|
+
*/
|
|
134
|
+
export const framePacer = () => {
|
|
135
|
+
const slotMs = 1000 / VIDEO_FPS;
|
|
136
|
+
let lastSlot;
|
|
137
|
+
let waiting;
|
|
138
|
+
/** The waiting frame, at the earliest time in the slot after the last written one. */
|
|
139
|
+
const takeWaiting = () => {
|
|
140
|
+
const next = lastSlot + 1;
|
|
141
|
+
const out = { frame: waiting.frame, ms: Math.max(waiting.ms, Math.ceil(next * slotMs)) };
|
|
142
|
+
lastSlot = next;
|
|
143
|
+
waiting = undefined;
|
|
144
|
+
return out;
|
|
145
|
+
};
|
|
146
|
+
return {
|
|
147
|
+
/** What to write now, in order, for a frame at `ms` on the video. */
|
|
148
|
+
add: (frame, ms) => {
|
|
149
|
+
const slot = Math.floor(ms / slotMs);
|
|
150
|
+
const out = waiting !== undefined && slot > lastSlot + 1 ? [takeWaiting()] : [];
|
|
151
|
+
if (waiting === undefined && (lastSlot === undefined || slot > lastSlot)) {
|
|
152
|
+
out.push({ frame, ms });
|
|
153
|
+
lastSlot = slot;
|
|
154
|
+
}
|
|
155
|
+
else
|
|
156
|
+
waiting = { frame, ms };
|
|
157
|
+
return out;
|
|
158
|
+
},
|
|
159
|
+
/** The frame still waiting, if one is, to write before the video ends. */
|
|
160
|
+
flush: () => (waiting === undefined ? [] : [takeWaiting()]),
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
// Matroska (EBML) as Playwright's recorder writes it: one MJPEG track whose frames each come in
|
|
164
|
+
// a cluster of their own with its time in ms.
|
|
165
|
+
const hex = (text) => Uint8Array.from(text.match(/../g), (b) => Number.parseInt(b, 16));
|
|
166
|
+
const concat = (parts) => {
|
|
167
|
+
const out = new Uint8Array(parts.reduce((n, p) => n + p.length, 0));
|
|
168
|
+
let at = 0;
|
|
169
|
+
for (const part of parts) {
|
|
170
|
+
out.set(part, at);
|
|
171
|
+
at += part.length;
|
|
172
|
+
}
|
|
173
|
+
return out;
|
|
174
|
+
};
|
|
175
|
+
/** EBML's variable-length size. */
|
|
176
|
+
export const vint = (value) => {
|
|
177
|
+
let length = 1;
|
|
178
|
+
while (value >= 2 ** (7 * length) - 1)
|
|
179
|
+
length++;
|
|
180
|
+
const out = new Uint8Array(length);
|
|
181
|
+
let v = value;
|
|
182
|
+
for (let i = length - 1; i >= 0; i--) {
|
|
183
|
+
out[i] = v & 0xff;
|
|
184
|
+
v = Math.floor(v / 256);
|
|
185
|
+
}
|
|
186
|
+
out[0] |= 1 << (8 - length);
|
|
187
|
+
return out;
|
|
188
|
+
};
|
|
189
|
+
const uint = (value) => {
|
|
190
|
+
const bytes = [];
|
|
191
|
+
for (let v = value; v > 0; v = Math.floor(v / 256))
|
|
192
|
+
bytes.unshift(v & 0xff);
|
|
193
|
+
return Uint8Array.from(bytes.length === 0 ? [0] : bytes);
|
|
194
|
+
};
|
|
195
|
+
const text = (value) => new TextEncoder().encode(value);
|
|
196
|
+
const element = (id, payload) => concat([hex(id), vint(payload.length), payload]);
|
|
197
|
+
/** The stream's start: its EBML header, a segment of unknown size, its info and its track. */
|
|
198
|
+
export const matroskaHeader = () => concat([
|
|
199
|
+
element('1A45DFA3', concat([
|
|
200
|
+
element('4286', uint(1)),
|
|
201
|
+
element('42F7', uint(1)),
|
|
202
|
+
element('42F2', uint(4)),
|
|
203
|
+
element('42F3', uint(8)),
|
|
204
|
+
element('4282', text('matroska')),
|
|
205
|
+
element('4287', uint(4)),
|
|
206
|
+
element('4285', uint(2)),
|
|
207
|
+
])),
|
|
208
|
+
hex('18538067'),
|
|
209
|
+
Uint8Array.from([1, 255, 255, 255, 255, 255, 255, 255]),
|
|
210
|
+
// Times in ms.
|
|
211
|
+
element('1549A966', concat([
|
|
212
|
+
element('2AD7B1', uint(1_000_000)),
|
|
213
|
+
element('4D80', text('screw-bugs')),
|
|
214
|
+
element('5741', text('screw-bugs')),
|
|
215
|
+
])),
|
|
216
|
+
element('1654AE6B', element('AE', concat([
|
|
217
|
+
element('D7', uint(1)),
|
|
218
|
+
element('73C5', uint(1)),
|
|
219
|
+
element('83', uint(1)),
|
|
220
|
+
element('9C', uint(0)),
|
|
221
|
+
element('86', text('V_MJPEG')),
|
|
222
|
+
// Required, but each JPEG gives its own size; 1x1 as Playwright, which found that a
|
|
223
|
+
// larger one can make ffmpeg read a short progressive JPEG as an interlaced field.
|
|
224
|
+
element('E0', concat([element('B0', uint(1)), element('BA', uint(1))])),
|
|
225
|
+
]))),
|
|
226
|
+
]);
|
|
227
|
+
/** One frame: a cluster at `ms` holding it as a key frame of track 1. */
|
|
228
|
+
export const matroskaFrame = (ms, jpeg) => {
|
|
229
|
+
const block = concat([hex('A3'), vint(4 + jpeg.length), vint(1), Uint8Array.from([0, 0, 0x80])]);
|
|
230
|
+
const timestamp = element('E7', uint(ms));
|
|
231
|
+
return concat([
|
|
232
|
+
hex('1F43B675'),
|
|
233
|
+
vint(timestamp.length + block.length + jpeg.length),
|
|
234
|
+
timestamp,
|
|
235
|
+
block,
|
|
236
|
+
jpeg,
|
|
237
|
+
]);
|
|
238
|
+
};
|
|
239
|
+
/** Playwright's ffmpeg arguments for its recorder, writing WebM to `file`. */
|
|
240
|
+
export const ffmpegArgs = (size, file) => {
|
|
241
|
+
const { width: w, height: h } = size;
|
|
242
|
+
const pixelRateScale = Math.max(1, (w * h * VIDEO_FPS) / (800 * 450 * 25));
|
|
243
|
+
const threads = Math.min(8, Math.ceil(pixelRateScale / 4));
|
|
244
|
+
return [
|
|
245
|
+
'-loglevel error -nostdin',
|
|
246
|
+
'-f matroska -fpsprobesize 0 -probesize 32 -analyzeduration 0 -i pipe:0',
|
|
247
|
+
// Each frame at its own time, none repeated: `framePacer` keeps to `VIDEO_FPS` at most.
|
|
248
|
+
'-y -an -fps_mode passthrough',
|
|
249
|
+
// Playwright's settings but the quality: crf 30, not 8, which is near lossless and twice as
|
|
250
|
+
// big, with text that looks the same.
|
|
251
|
+
'-c:v libvpx-vp9 -qmin 0 -qmax 50 -crf 30 -deadline realtime -cpu-used 8 -lag-in-frames 0',
|
|
252
|
+
`-b:v ${Math.round(pixelRateScale * 1000)}k -threads ${threads}`,
|
|
253
|
+
`-tile-columns ${Math.ceil(Math.log2(threads))} -row-mt 1`,
|
|
254
|
+
// A frame a little smaller than the video (see `FRAME_SLACK`) is padded, as Playwright does;
|
|
255
|
+
// one a pixel larger loses its odd row or column first. Cropped before it is padded: `pad` cuts
|
|
256
|
+
// an odd-height 4:2:0 frame (the JPEG's) to even and pads it back, greying its last row.
|
|
257
|
+
`-vf crop='min(iw,${w})':'min(ih,${h})':0:0,pad=${w}:${h}:0:0:gray`,
|
|
258
|
+
'-f webm',
|
|
259
|
+
]
|
|
260
|
+
.flatMap((options) => options.split(' '))
|
|
261
|
+
.concat(file);
|
|
262
|
+
};
|
|
263
|
+
const ffmpegEnded = (code) => typeof code === 'number' ? `ffmpeg ended with code ${code}` : `ffmpeg failed: ${code}`;
|
|
264
|
+
/**
|
|
265
|
+
* Records `page`'s video into `file` (a `.webm`) with the ffmpeg at `ffmpeg`, at `size` (see
|
|
266
|
+
* `videoSize`). Written to a file beside it first and moved there by `finish`, so a run whose
|
|
267
|
+
* process dies leaves no half-written video where a video is looked for. Fails when ffmpeg or
|
|
268
|
+
* the screencast cannot start; with the scope, ffmpeg and the screencast are stopped.
|
|
269
|
+
*/
|
|
270
|
+
export const startRecorder = (page, options) => Effect.gen(function* () {
|
|
271
|
+
const fs = yield* FileSystem.FileSystem;
|
|
272
|
+
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
|
273
|
+
const clock = yield* Effect.clockWith((clock) => Effect.succeed(clock));
|
|
274
|
+
const partial = `${options.file}.part`;
|
|
275
|
+
const gate = frameGate(options.size);
|
|
276
|
+
// Bounded, so an ffmpeg that stops reading never makes frames pile up in memory.
|
|
277
|
+
const queue = yield* Queue.make({
|
|
278
|
+
capacity: BACKLOG_FRAMES,
|
|
279
|
+
strategy: 'dropping',
|
|
280
|
+
});
|
|
281
|
+
const first = yield* Deferred.make();
|
|
282
|
+
const handle = yield* spawner.spawn(ChildProcess.make(options.ffmpeg, [...ffmpegArgs(options.size, partial)], {
|
|
283
|
+
stdin: Stream.fromQueue(queue),
|
|
284
|
+
stdout: 'ignore',
|
|
285
|
+
stderr: 'ignore',
|
|
286
|
+
forceKillAfter: FFMPEG_KILL_AFTER,
|
|
287
|
+
}));
|
|
288
|
+
// Once ffmpeg has ended, frames are no longer queued for it.
|
|
289
|
+
const exited = yield* Deferred.make();
|
|
290
|
+
let endedWith;
|
|
291
|
+
yield* handle.exitCode.pipe(Effect.map(Number), Effect.catch((error) => Effect.succeed(error.message)), Effect.tap((code) => Effect.andThen(Effect.sync(() => {
|
|
292
|
+
endedWith = code;
|
|
293
|
+
}), Deferred.succeed(exited, code))), Effect.andThen(Queue.shutdown(queue)), Effect.forkScoped);
|
|
294
|
+
Queue.offerUnsafe(queue, matroskaHeader());
|
|
295
|
+
let ended = false;
|
|
296
|
+
const pacer = framePacer();
|
|
297
|
+
/** The latest frame on the video (written, or waiting in `pacer`). */
|
|
298
|
+
let last;
|
|
299
|
+
// Boundary: Playwright hands frames to a callback. It only queues them.
|
|
300
|
+
const onFrame = ({ data, timestamp, }) => {
|
|
301
|
+
if (ended)
|
|
302
|
+
return;
|
|
303
|
+
const ms = gate.admit(jpegSize(data), timestamp);
|
|
304
|
+
if (ms === undefined)
|
|
305
|
+
return;
|
|
306
|
+
const now = pacer.add(data, ms);
|
|
307
|
+
// Not on the video when ffmpeg is gone or too far behind.
|
|
308
|
+
for (const frame of now)
|
|
309
|
+
if (!Queue.offerUnsafe(queue, matroskaFrame(frame.ms, frame.frame)) && frame.frame === data)
|
|
310
|
+
return;
|
|
311
|
+
last = { jpeg: data, paintedAt: timestamp, came: clock.currentTimeMillisUnsafe() };
|
|
312
|
+
if (now.length > 0)
|
|
313
|
+
Deferred.doneUnsafe(first, Exit.succeed(gate.first()));
|
|
314
|
+
};
|
|
315
|
+
yield* Effect.acquireRelease(Effect.tryPromise({
|
|
316
|
+
// Two pixels more than the video, so the page's odd last row or column comes as it is:
|
|
317
|
+
// the screencast shrinks, resampling, a frame not smaller than the size it is asked for
|
|
318
|
+
// (1206x2043 for 1206x2043, as for 1206x2042; not for 1206x2044).
|
|
319
|
+
try: () => page.screencast.start({
|
|
320
|
+
size: { width: options.size.width + 2, height: options.size.height + 2 },
|
|
321
|
+
onFrame,
|
|
322
|
+
}),
|
|
323
|
+
catch: (error) => new Error(`the screencast did not start: ${String(error).split('\n')[0]}`),
|
|
324
|
+
}), (listening) => Effect.tryPromise(() => listening.dispose()).pipe(Effect.timeoutOption('2 seconds'), Effect.ignore));
|
|
325
|
+
const finish = yield* Effect.cached(Effect.gen(function* () {
|
|
326
|
+
ended = true;
|
|
327
|
+
const now = yield* Clock.currentTimeMillis;
|
|
328
|
+
if (last !== undefined) {
|
|
329
|
+
const end = matroskaFrame(gate.at(lastFrameTime(last.paintedAt, now - last.came)), last.jpeg);
|
|
330
|
+
// The page's last state and the frame that gives the video its length wait for room,
|
|
331
|
+
// unlike the others; the session's close bounds how long (`CLOSE_TIMEOUT_MS`).
|
|
332
|
+
for (const frame of [...pacer.flush().map((f) => matroskaFrame(f.ms, f.frame)), end])
|
|
333
|
+
while (endedWith === undefined && !Queue.offerUnsafe(queue, frame))
|
|
334
|
+
yield* Effect.sleep(READY_POLL);
|
|
335
|
+
}
|
|
336
|
+
yield* Queue.end(queue);
|
|
337
|
+
const code = yield* Deferred.await(exited);
|
|
338
|
+
if (last === undefined) {
|
|
339
|
+
yield* fs.remove(partial).pipe(Effect.ignore);
|
|
340
|
+
return 'The tab never showed a frame, so there is no video.';
|
|
341
|
+
}
|
|
342
|
+
if (code !== 0) {
|
|
343
|
+
yield* fs.remove(partial).pipe(Effect.ignore);
|
|
344
|
+
return `The video could not be saved: ${ffmpegEnded(code)}.`;
|
|
345
|
+
}
|
|
346
|
+
return yield* fs.rename(partial, options.file).pipe(Effect.as(undefined), Effect.catch((error) => Effect.succeed(`The video could not be saved: ${error.message}`)));
|
|
347
|
+
}));
|
|
348
|
+
return {
|
|
349
|
+
firstFrame: Deferred.await(first),
|
|
350
|
+
hold: (effect) => Effect.acquireUseRelease(Clock.currentTimeMillis.pipe(Effect.map(gate.hold)), () => effect, (release) => Clock.currentTimeMillis.pipe(Effect.map(release))),
|
|
351
|
+
finish,
|
|
352
|
+
ready: Effect.gen(function* () {
|
|
353
|
+
yield* Effect.raceFirst(Deferred.await(first), Deferred.await(exited)).pipe(Effect.timeoutOption(READY_TIMEOUT_MS));
|
|
354
|
+
const opened = yield* Effect.gen(function* () {
|
|
355
|
+
while (endedWith === undefined && !(yield* fs.exists(partial)))
|
|
356
|
+
yield* Effect.sleep(READY_POLL);
|
|
357
|
+
}).pipe(Effect.ignore, Effect.timeoutOption(READY_TIMEOUT_MS));
|
|
358
|
+
if (endedWith !== undefined)
|
|
359
|
+
return yield* Effect.fail(new Error(`${ffmpegEnded(endedWith)}.`));
|
|
360
|
+
if (opened._tag === 'None')
|
|
361
|
+
return yield* Effect.fail(new Error(`ffmpeg did not start writing the video within ${READY_TIMEOUT_MS / 1000} s.`));
|
|
362
|
+
}),
|
|
363
|
+
stopped: Effect.sync(() => ended || endedWith === undefined
|
|
364
|
+
? undefined
|
|
365
|
+
: `the video stopped being recorded (${ffmpegEnded(endedWith)}).`),
|
|
366
|
+
};
|
|
367
|
+
});
|
|
368
|
+
/**
|
|
369
|
+
* How a session with a video at `path` (in the folder `dir`, made when missing) is recorded with
|
|
370
|
+
* the ffmpeg at `ffmpeg`, on the platform this runs on.
|
|
371
|
+
*/
|
|
372
|
+
export const videoRecording = (video) => Effect.gen(function* () {
|
|
373
|
+
const platform = yield* Effect.context();
|
|
374
|
+
return {
|
|
375
|
+
path: video.path,
|
|
376
|
+
record: (page, size) => Effect.gen(function* () {
|
|
377
|
+
const fs = yield* FileSystem.FileSystem;
|
|
378
|
+
yield* fs.makeDirectory(video.dir, { recursive: true });
|
|
379
|
+
return yield* startRecorder(page, { ffmpeg: video.ffmpeg, file: video.path, size });
|
|
380
|
+
}).pipe(Effect.provideContext(platform)),
|
|
381
|
+
};
|
|
382
|
+
});
|
package/dist/build-info.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"id": "2026-11-
|
|
3
|
-
"builtAt": "2026-11-
|
|
4
|
-
"commit": "
|
|
2
|
+
"id": "2026-11-18T15:59:29.049Z-56409fa9",
|
|
3
|
+
"builtAt": "2026-11-18T15:59:29.049Z",
|
|
4
|
+
"commit": "b14b4e16b08bf564288261d44bbf6d89fbf2d061"
|
|
5
5
|
}
|
package/dist/cli/commands.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Console, Data, Duration, Effect, Option, Path } from 'effect';
|
|
1
|
+
import { Console, Data, Duration, Effect, Option, Path, Schema } from 'effect';
|
|
2
2
|
import { Argument, Command, Flag } from 'effect/cli';
|
|
3
|
-
import { judgedLedger, summaryOf, } from '../schema/index.js';
|
|
3
|
+
import { Findings, JobSpec, judgedLedger, summaryOf, } from '../schema/index.js';
|
|
4
4
|
import { renderPrSummary } from '../report/index.js';
|
|
5
5
|
import { readFindingsFile, readSpecFile } from './config.js';
|
|
6
6
|
import { analyticsEnabled, isCi, isNonInteractive } from './environment.js';
|
|
@@ -96,7 +96,7 @@ const caseResults = (ledger) => ledger.cases.map((c) => ({
|
|
|
96
96
|
}));
|
|
97
97
|
const run = Command.make('run', {
|
|
98
98
|
json,
|
|
99
|
-
spec: Flag.String('spec').pipe(Flag.withDescription('JSON file with the job: url,
|
|
99
|
+
spec: Flag.String('spec').pipe(Flag.withDescription('JSON file with the job: {"version":1,"url":"http://localhost:3000","cases":[{"id":"home-loads","title":"Home page loads","steps":[{"action":"goto","url":"/"},{"action":"expectText","text":"Welcome"}]}]}. `screw-bugs schema job` prints its full JSON Schema: every field and step'), Flag.optional),
|
|
100
100
|
url: Flag.String('url').pipe(Flag.withDescription('URL of the app to test (overrides the URL in --spec)'), Flag.optional),
|
|
101
101
|
device: Flag.ChoiceWithValue('device', [
|
|
102
102
|
['desktop', 'desktop'],
|
|
@@ -165,10 +165,15 @@ const oneLine = (text, max = 100) => {
|
|
|
165
165
|
return flat.length <= max ? flat : `${flat.slice(0, max - 1).trimEnd()}…`;
|
|
166
166
|
};
|
|
167
167
|
const status = Command.make('status', { json, jobId: Argument.String('job-id') }, (flags) => handle(flags.json)(Effect.gen(function* () {
|
|
168
|
-
const { ledger, judged, job, runDir, reportPath, walkthroughPath, evidence, evidencePath } = yield* (yield* Operations).runStatus(flags.jobId);
|
|
168
|
+
const { ledger, judged, job, runDir, reportPath, walkthroughPath, livePath, evidence, evidencePath, } = yield* (yield* Operations).runStatus(flags.jobId);
|
|
169
169
|
const { instructions, title } = job.spec;
|
|
170
170
|
const summary = summaryOf(job.spec);
|
|
171
171
|
const links = yield* pageLinks({ reportPath, walkthroughPath });
|
|
172
|
+
// While the run is going: the page to follow it on.
|
|
173
|
+
const live = yield* pageLink(livePath);
|
|
174
|
+
// A queued or running run gives its ledger.json after its folder, as run_status does.
|
|
175
|
+
const going = ledger.state === 'queued' || ledger.state === 'running';
|
|
176
|
+
const ledgerPath = going ? (yield* Path.Path).join(runDir, 'ledger.json') : undefined;
|
|
172
177
|
yield* flags.json
|
|
173
178
|
? printJson({
|
|
174
179
|
ok: true,
|
|
@@ -183,25 +188,29 @@ const status = Command.make('status', { json, jobId: Argument.String('job-id') }
|
|
|
183
188
|
reportPath,
|
|
184
189
|
walkthroughPath,
|
|
185
190
|
...urlFields(links),
|
|
191
|
+
livePath,
|
|
192
|
+
liveUrl: live?.url,
|
|
186
193
|
})
|
|
187
194
|
: Console.log([
|
|
188
195
|
...(title?.trim() ? [`Title: ${oneLine(title)}`] : []),
|
|
189
196
|
`Summary: ${oneLine(summary.text)}`,
|
|
190
197
|
...(instructions?.trim() ? [`Asked: ${oneLine(instructions)}`] : []),
|
|
191
|
-
countsSentence(judged, links.walkthrough?.kind),
|
|
198
|
+
countsSentence(judged, links.walkthrough?.kind, live?.kind),
|
|
192
199
|
...(ledger.error ? [ledger.error] : []),
|
|
193
200
|
...formatEvidence(judged, evidence),
|
|
194
201
|
runDir,
|
|
202
|
+
...(ledgerPath ? [ledgerPath] : []),
|
|
195
203
|
...(evidencePath ? [evidencePath] : []),
|
|
196
204
|
...(links.report ? [links.report.link] : []),
|
|
197
205
|
...(links.walkthrough ? [links.walkthrough.link] : []),
|
|
206
|
+
...(live ? [live.link] : []),
|
|
198
207
|
].join('\n'));
|
|
199
208
|
}))).pipe(Command.withDescription('Show the state and case results of a run'));
|
|
200
209
|
const portFlag = Flag.Int('port').pipe(Flag.withDescription("Port for --serve, which fails if it is taken (default: the project's port in 41000-41999, else a free one)"), Flag.optional);
|
|
201
210
|
/**
|
|
202
|
-
* Serves the run folders on 127.0.0.1 (the project's port, see
|
|
203
|
-
* the URL of `path`, a page in a run folder; runs until Ctrl+C,
|
|
204
|
-
* already serves them. `report --serve` and `walkthrough --serve` share it.
|
|
211
|
+
* Serves the run folders on 127.0.0.1 or `SCREW_BUGS_REPORT_HOST` (the project's port, see
|
|
212
|
+
* `startReportServer`) and prints the URL of `path`, a page in a run folder; runs until Ctrl+C,
|
|
213
|
+
* unless another screw-bugs process already serves them. `report --serve` and `walkthrough --serve` share it.
|
|
205
214
|
*/
|
|
206
215
|
const serve = (path, portOption, asJson,
|
|
207
216
|
/** More `--json` fields, such as `report`'s `cases`. */
|
|
@@ -238,7 +247,7 @@ const report = Command.make('report', {
|
|
|
238
247
|
['html', 'html'],
|
|
239
248
|
['markdown', 'markdown'],
|
|
240
249
|
]).pipe(Flag.withDescription('html prints the path of the report; markdown prints a pull request summary'), Flag.withDefault('html')),
|
|
241
|
-
serve: Flag.Boolean('serve').pipe(Flag.withDescription('Serve the run folders on 127.0.0.1 and print the report URL, for browsers that cannot open files (such as those built into coding tools); runs until Ctrl+C'), Flag.withDefault(false)),
|
|
250
|
+
serve: Flag.Boolean('serve').pipe(Flag.withDescription('Serve the run folders on 127.0.0.1 (or SCREW_BUGS_REPORT_HOST) and print the report URL, for browsers that cannot open files (such as those built into coding tools); runs until Ctrl+C'), Flag.withDefault(false)),
|
|
242
251
|
port: portFlag,
|
|
243
252
|
}, (flags) => handle(flags.json)(Effect.gen(function* () {
|
|
244
253
|
const { path, bundle, walkthroughPath } = yield* (yield* Operations).report(flags.jobId);
|
|
@@ -269,7 +278,7 @@ const report = Command.make('report', {
|
|
|
269
278
|
const walkthrough = Command.make('walkthrough', {
|
|
270
279
|
json,
|
|
271
280
|
jobId: Argument.String('job-id'),
|
|
272
|
-
serve: Flag.Boolean('serve').pipe(Flag.withDescription('Serve the run folders on 127.0.0.1 and print the walkthrough URL, as report --serve does; runs until Ctrl+C'), Flag.withDefault(false)),
|
|
281
|
+
serve: Flag.Boolean('serve').pipe(Flag.withDescription('Serve the run folders on 127.0.0.1 (or SCREW_BUGS_REPORT_HOST) and print the walkthrough URL, as report --serve does; runs until Ctrl+C'), Flag.withDefault(false)),
|
|
273
282
|
port: portFlag,
|
|
274
283
|
}, (flags) => handle(flags.json)(Effect.gen(function* () {
|
|
275
284
|
const { path, reportPath } = yield* (yield* Operations).walkthrough(flags.jobId);
|
|
@@ -303,7 +312,7 @@ const findings = Command.make('findings', { json, jobId: Argument.String('job-id
|
|
|
303
312
|
...(links.walkthrough ? [links.walkthrough.link] : []),
|
|
304
313
|
...result.annotated,
|
|
305
314
|
].join('\n'));
|
|
306
|
-
}))).pipe(Command.withDescription("Submit an agent's write-up of an ended run (a JSON file, or - for standard input); it is checked, saved and shown in the report (exit 6 if it does not fit the run)"));
|
|
315
|
+
}))).pipe(Command.withDescription("Submit an agent's write-up of an ended run (a JSON file, or - for standard input; `screw-bugs schema findings` prints its JSON Schema); it is checked, saved and shown in the report (exit 6 if it does not fit the run)"));
|
|
307
316
|
const init = Command.make('init', {
|
|
308
317
|
json,
|
|
309
318
|
url: Flag.String('url').pipe(Flag.withDescription('Default URL to test (baseUrl), used when run gets no URL'), Flag.optional),
|
|
@@ -488,6 +497,41 @@ const accountRemove = Command.make('remove', { json, label: Argument.String('lab
|
|
|
488
497
|
: Console.log(`Removed test account ${flags.label} and its session.`);
|
|
489
498
|
}))).pipe(Command.withDescription('Remove a test account and its saved session'));
|
|
490
499
|
const accounts = accountsList.pipe(Command.withDescription('List the test accounts runs can start signed in as; sign in to one, or remove one'), Command.withSubcommands([accountSignIn, accountRemove]));
|
|
500
|
+
/**
|
|
501
|
+
* A `--spec` file as `run` reads it: `run` fills in `version` itself, and the URL may come from
|
|
502
|
+
* `--url` or `baseUrl` in screw-bugs.json instead, so neither is required here.
|
|
503
|
+
*/
|
|
504
|
+
const SpecFile = Schema.Struct({
|
|
505
|
+
...JobSpec.fields,
|
|
506
|
+
version: Schema.optionalKey(JobSpec.fields.version),
|
|
507
|
+
url: Schema.optionalKey(JobSpec.fields.url.annotate({
|
|
508
|
+
description: 'http or https URL of the app to test. Optional here when run gets --url, or screw-bugs.json has baseUrl.',
|
|
509
|
+
})),
|
|
510
|
+
});
|
|
511
|
+
/** The JSON files a caller writes for the CLI, by the name `schema` takes. */
|
|
512
|
+
const FILE_SCHEMAS = {
|
|
513
|
+
job: SpecFile.annotate({
|
|
514
|
+
description: 'A job for `screw-bugs run --spec`. Checked when it runs, beyond this schema: case IDs are ' +
|
|
515
|
+
'unique, also ignoring case; url is http or https; upload paths stay inside the project; ' +
|
|
516
|
+
'lengths count UTF-16 code units, as JavaScript does, so an emoji can count as 2. An error ' +
|
|
517
|
+
'names the field to fix.',
|
|
518
|
+
}),
|
|
519
|
+
findings: Findings.annotate({
|
|
520
|
+
description: 'A write-up for `screw-bugs findings`. Checked against the run when it is submitted, beyond ' +
|
|
521
|
+
'this schema: case IDs, screenshot IDs and timecodes must be ones run_status gave; ' +
|
|
522
|
+
'lengths count UTF-16 code units, as JavaScript does, so an emoji can count as 2. An error ' +
|
|
523
|
+
'lists what to fix.',
|
|
524
|
+
}),
|
|
525
|
+
};
|
|
526
|
+
const schema = Command.make('schema', {
|
|
527
|
+
json,
|
|
528
|
+
file: Argument.Literals('job|findings', ['job', 'findings']),
|
|
529
|
+
},
|
|
530
|
+
// Always JSON, on one line (it is long, and read mostly by agents): --json is accepted like
|
|
531
|
+
// every command's, and changes nothing.
|
|
532
|
+
(flags) => Console.log(JSON.stringify(Schema.toStandardJSONSchemaV1(FILE_SCHEMAS[flags.file])['~standard'].jsonSchema.input({
|
|
533
|
+
target: 'draft-2020-12',
|
|
534
|
+
})))).pipe(Command.withDescription('Print the JSON Schema of a file you write: job (for run --spec) or findings (for findings)'));
|
|
491
535
|
const mcp = Command.make('mcp', {}, () => serveMcp).pipe(Command.withDescription('Serve the screw-bugs MCP server over stdio, for coding agents'));
|
|
492
536
|
const analytics = Command.make('analytics', { json, setting: Argument.String('on|off').pipe(Argument.optional) }, (flags) => handle(flags.json)(Effect.gen(function* () {
|
|
493
537
|
if (Option.isSome(flags.setting))
|
|
@@ -509,6 +553,7 @@ export const root = Command.make('screw-bugs').pipe(Command.withDescription('Loc
|
|
|
509
553
|
report,
|
|
510
554
|
walkthrough,
|
|
511
555
|
findings,
|
|
556
|
+
schema,
|
|
512
557
|
stub('share', 'Share a report through Screw Bugs Cloud'),
|
|
513
558
|
runs,
|
|
514
559
|
analytics,
|
package/dist/cli/mcp.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { McpServer } from '@modelcontextprotocol/server';
|
|
2
|
-
import { Effect, Path } from 'effect';
|
|
2
|
+
import { Duration, Effect, Path } from 'effect';
|
|
3
3
|
import { type CaseLedger, type DoctorReport, type EvidencePack, type JudgedLedger } from '../schema/index.js';
|
|
4
4
|
import { type FindingsResult, Operations } from './operations.js';
|
|
5
5
|
import { PackageInfo } from './package-info.js';
|
|
@@ -9,6 +9,8 @@ export type ShownLedger = CaseLedger | JudgedLedger;
|
|
|
9
9
|
/**
|
|
10
10
|
* `Job … is finished: 3 passed, 2 failed (1 by the agent's review), 0 blocked, 0 not verified.`
|
|
11
11
|
* The counts are the statuses results show: a case the agent's findings mark failed is failed.
|
|
12
|
+
* A running job also says where it is (`progressText`): `Job … is running case 2 of 3
|
|
13
|
+
* (reply-maya), step 4 (click): …`.
|
|
12
14
|
*/
|
|
13
15
|
export declare const formatLedger: (ledger: ShownLedger) => string;
|
|
14
16
|
/** A run counts as passed only when it finished and every case passed. */
|
|
@@ -26,18 +28,23 @@ export declare const formatEvidence: (ledger: ShownLedger, pack: EvidencePack) =
|
|
|
26
28
|
export declare const formatNotPassing: (ledger: ShownLedger) => ReadonlyArray<string>;
|
|
27
29
|
/** How a reply gives the walkthrough: its URL, or its path when there is no URL. */
|
|
28
30
|
export type WalkthroughLink = 'url' | 'path';
|
|
29
|
-
/**
|
|
30
|
-
|
|
31
|
+
/**
|
|
32
|
+
* The counts sentence, saying where to watch the run: in its walkthrough, when it has one, or
|
|
33
|
+
* while it is going, in its `live.html` (`live`).
|
|
34
|
+
*/
|
|
35
|
+
export declare const countsSentence: (ledger: ShownLedger, walkthrough: WalkthroughLink | undefined, live?: WalkthroughLink) => string;
|
|
31
36
|
/**
|
|
32
37
|
* A status reply: the counts (and where to watch the run, when it has a walkthrough), then the
|
|
33
38
|
* evidence pack (see `formatEvidence`).
|
|
34
39
|
*/
|
|
35
|
-
export declare const formatStatus: (ledger: ShownLedger, pack?: EvidencePack, walkthrough?: WalkthroughLink) => string;
|
|
40
|
+
export declare const formatStatus: (ledger: ShownLedger, pack?: EvidencePack, walkthrough?: WalkthroughLink, live?: WalkthroughLink) => string;
|
|
36
41
|
/**
|
|
37
42
|
* The reply to saved findings: one sentence (naming the walkthrough as the place to watch the run,
|
|
38
43
|
* when the reply gives it), maybe one about highlights, then the paths.
|
|
39
44
|
*/
|
|
40
45
|
export declare const formatFindings: (result: FindingsResult, walkthrough?: WalkthroughLink) => string;
|
|
46
|
+
/** How often `start_run` sends progress while it waits for a sign-in. */
|
|
47
|
+
export declare const SIGN_IN_PROGRESS_INTERVAL: Duration.Duration;
|
|
41
48
|
/** The MCP server: exactly five tools, each a thin call into `Operations`. */
|
|
42
49
|
export declare const makeMcpServer: Effect.Effect<McpServer, never, Operations | PackageInfo | Path.Path>;
|
|
43
50
|
/** Serves MCP over stdio until the client disconnects. Nothing else may write to stdout. */
|