screw-bugs 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +906 -2
  3. package/bin/screw-bugs.js +29 -0
  4. package/dist/browser-playwright/annotate.d.ts +9 -0
  5. package/dist/browser-playwright/annotate.js +86 -0
  6. package/dist/browser-playwright/capture.d.ts +232 -0
  7. package/dist/browser-playwright/capture.js +1049 -0
  8. package/dist/browser-playwright/frames.d.ts +77 -0
  9. package/dist/browser-playwright/frames.js +191 -0
  10. package/dist/browser-playwright/index.d.ts +2 -0
  11. package/dist/browser-playwright/index.js +2 -0
  12. package/dist/browser-playwright/input.d.ts +44 -0
  13. package/dist/browser-playwright/input.js +116 -0
  14. package/dist/browser-playwright/launch.d.ts +21 -0
  15. package/dist/browser-playwright/launch.js +86 -0
  16. package/dist/browser-playwright/page.d.ts +387 -0
  17. package/dist/browser-playwright/page.js +1930 -0
  18. package/dist/build-info.json +5 -0
  19. package/dist/cli/app.d.ts +19 -0
  20. package/dist/cli/app.js +70 -0
  21. package/dist/cli/build-info.d.ts +52 -0
  22. package/dist/cli/build-info.js +82 -0
  23. package/dist/cli/commands.d.ts +14 -0
  24. package/dist/cli/commands.js +308 -0
  25. package/dist/cli/config.d.ts +16 -0
  26. package/dist/cli/config.js +71 -0
  27. package/dist/cli/doctor.d.ts +19 -0
  28. package/dist/cli/doctor.js +113 -0
  29. package/dist/cli/environment.d.ts +20 -0
  30. package/dist/cli/environment.js +34 -0
  31. package/dist/cli/exit-codes.d.ts +29 -0
  32. package/dist/cli/exit-codes.js +28 -0
  33. package/dist/cli/failure.d.ts +20 -0
  34. package/dist/cli/failure.js +15 -0
  35. package/dist/cli/index.d.ts +6 -0
  36. package/dist/cli/index.js +6 -0
  37. package/dist/cli/install-method.d.ts +96 -0
  38. package/dist/cli/install-method.js +148 -0
  39. package/dist/cli/main.d.ts +1 -0
  40. package/dist/cli/main.js +10 -0
  41. package/dist/cli/mcp.d.ts +30 -0
  42. package/dist/cli/mcp.js +309 -0
  43. package/dist/cli/node-version.d.ts +3 -0
  44. package/dist/cli/node-version.js +22 -0
  45. package/dist/cli/operations.d.ts +127 -0
  46. package/dist/cli/operations.js +337 -0
  47. package/dist/cli/package-info.d.ts +22 -0
  48. package/dist/cli/package-info.js +25 -0
  49. package/dist/cli/report-server.d.ts +170 -0
  50. package/dist/cli/report-server.js +387 -0
  51. package/dist/cli/signals.d.ts +37 -0
  52. package/dist/cli/signals.js +61 -0
  53. package/dist/cli/stamp-build.d.ts +1 -0
  54. package/dist/cli/stamp-build.js +9 -0
  55. package/dist/cli/update-check.d.ts +140 -0
  56. package/dist/cli/update-check.js +316 -0
  57. package/dist/cli/uploads.d.ts +16 -0
  58. package/dist/cli/uploads.js +80 -0
  59. package/dist/core/css.d.ts +95 -0
  60. package/dist/core/css.js +436 -0
  61. package/dist/core/engine.d.ts +65 -0
  62. package/dist/core/engine.js +436 -0
  63. package/dist/core/errors.d.ts +66 -0
  64. package/dist/core/errors.js +30 -0
  65. package/dist/core/evidence.d.ts +14 -0
  66. package/dist/core/evidence.js +127 -0
  67. package/dist/core/index.d.ts +12 -0
  68. package/dist/core/index.js +12 -0
  69. package/dist/core/labels.d.ts +47 -0
  70. package/dist/core/labels.js +199 -0
  71. package/dist/core/liveness.d.ts +45 -0
  72. package/dist/core/liveness.js +64 -0
  73. package/dist/core/marks.d.ts +63 -0
  74. package/dist/core/marks.js +410 -0
  75. package/dist/core/services.d.ts +444 -0
  76. package/dist/core/services.js +22 -0
  77. package/dist/core/steps.d.ts +96 -0
  78. package/dist/core/steps.js +656 -0
  79. package/dist/core/uploads.d.ts +49 -0
  80. package/dist/core/uploads.js +133 -0
  81. package/dist/core/video.d.ts +16 -0
  82. package/dist/core/video.js +101 -0
  83. package/dist/core/viewport.d.ts +28 -0
  84. package/dist/core/viewport.js +50 -0
  85. package/dist/report/html.d.ts +37 -0
  86. package/dist/report/html.js +762 -0
  87. package/dist/report/index.d.ts +5 -0
  88. package/dist/report/index.js +5 -0
  89. package/dist/report/markup.d.ts +27 -0
  90. package/dist/report/markup.js +75 -0
  91. package/dist/report/pr-summary.d.ts +11 -0
  92. package/dist/report/pr-summary.js +110 -0
  93. package/dist/report/sha256.d.ts +9 -0
  94. package/dist/report/sha256.js +97 -0
  95. package/dist/report/styles.d.ts +1 -0
  96. package/dist/report/styles.js +328 -0
  97. package/dist/report/view.d.ts +141 -0
  98. package/dist/report/view.js +368 -0
  99. package/dist/report/walkthrough.d.ts +75 -0
  100. package/dist/report/walkthrough.js +458 -0
  101. package/dist/schema/config.d.ts +7 -0
  102. package/dist/schema/config.js +6 -0
  103. package/dist/schema/doctor.d.ts +46 -0
  104. package/dist/schema/doctor.js +23 -0
  105. package/dist/schema/evidence.d.ts +994 -0
  106. package/dist/schema/evidence.js +521 -0
  107. package/dist/schema/findings.d.ts +159 -0
  108. package/dist/schema/findings.js +80 -0
  109. package/dist/schema/index.d.ts +7 -0
  110. package/dist/schema/index.js +7 -0
  111. package/dist/schema/job.d.ts +1724 -0
  112. package/dist/schema/job.js +505 -0
  113. package/dist/schema/ledger.d.ts +951 -0
  114. package/dist/schema/ledger.js +193 -0
  115. package/dist/schema/status.d.ts +7 -0
  116. package/dist/schema/status.js +11 -0
  117. package/dist/store-local/accounts.d.ts +7 -0
  118. package/dist/store-local/accounts.js +9 -0
  119. package/dist/store-local/index.d.ts +3 -0
  120. package/dist/store-local/index.js +3 -0
  121. package/dist/store-local/paths.d.ts +10 -0
  122. package/dist/store-local/paths.js +17 -0
  123. package/dist/store-local/storage.d.ts +20 -0
  124. package/dist/store-local/storage.js +170 -0
  125. package/package.json +73 -4
@@ -0,0 +1,444 @@
1
+ import { Context, type Effect, type Scope } from 'effect';
2
+ import type { Box, Candidate, CaseLedger, Device, ElementTarget, JobId, JobRecord, JobSpec, JobState, PageFacts, PageNode, Point, ReportBundle, ShotFrame, Target, Truncated, VisualViewport, WaitState } from '../schema/index.js';
3
+ import type { BrowserNotFound, NotImplemented, PageActionFailed, RunNotFound, StorageFailed } from './errors.js';
4
+ export type BrowserKind = 'chrome' | 'msedge' | 'playwright-chromium';
5
+ export interface BrowserInfo {
6
+ readonly kind: BrowserKind;
7
+ readonly version: string;
8
+ }
9
+ /**
10
+ * A main-frame document load, in the case's page or in a tab or window the case opened, that did
11
+ * not work out. `step` is the index (as given to `BrowserPage.settle`) of the step during which it
12
+ * started.
13
+ */
14
+ export type LoadProblem = {
15
+ readonly step: number;
16
+ readonly inNewTab: boolean;
17
+ } & ({
18
+ readonly _tag: 'HttpError';
19
+ readonly status: number;
20
+ } | {
21
+ readonly _tag: 'LoadFailed';
22
+ readonly error: string;
23
+ } | {
24
+ readonly _tag: 'Unfinished';
25
+ readonly timeoutMs: number;
26
+ });
27
+ /** Where a case's browser went that screw-bugs must not capture, such as a `data:` frame. */
28
+ export interface Refusal {
29
+ /** Such as `data:`. */
30
+ readonly scheme: string;
31
+ /** The case's page, a frame inside a page, or a page the case opened in a new tab or window. */
32
+ readonly where: 'page' | 'frame' | 'window';
33
+ }
34
+ /** What a screenshot captured besides the image: its size and the page state for highlights. */
35
+ export interface ShotCapture {
36
+ /** Image size in pixels, and image pixels per CSS pixel. */
37
+ readonly width: number;
38
+ readonly height: number;
39
+ readonly scale: number;
40
+ readonly url: string;
41
+ /**
42
+ * The box of the `target` asked for, when it could be measured and at least part of it is on the
43
+ * image; never a guess.
44
+ */
45
+ readonly target: Box | undefined;
46
+ /** Where the text and images of `target` are inside it (see `Candidate.content`), when measured. */
47
+ readonly targetContent?: Box | undefined;
48
+ /**
49
+ * How long after the screenshot was asked for `target` was measured, in ms, when it has a box:
50
+ * the moment the box is true of, which can be seconds before the image is taken.
51
+ */
52
+ readonly targetAfterMs?: number | undefined;
53
+ /** Why `target` has no box although it was measured, such as it being off the image. */
54
+ readonly targetProblem?: string | undefined;
55
+ /**
56
+ * The visual viewport `target` and the boxes below were measured in, which they account for (see
57
+ * `Shot.visual`); undefined when that could not be told for sure, with boxes as older runs had.
58
+ */
59
+ readonly visual?: VisualViewport | undefined;
60
+ /** Elements on the page a highlight may name (see `ShotPage`), at most `CANDIDATES_MAX`. */
61
+ readonly candidates: ReadonlyArray<Candidate>;
62
+ /** Set when the page held more elements than `candidates` (see `Truncated`). */
63
+ readonly truncated?: Truncated | undefined;
64
+ /** Frames visible on the image (see `ShotPage.frames`); their elements are in `candidates`. */
65
+ readonly frames?: ReadonlyArray<ShotFrame> | undefined;
66
+ /** How many frames were visible, when more than `frames` holds. */
67
+ readonly framesFound?: number | undefined;
68
+ /** How many frames in the page itself could not be described (see `ShotPage.framesUnread`). */
69
+ readonly framesUnread?: number | undefined;
70
+ /** The elements that hold candidates (see `ShotPage.nodes`). */
71
+ readonly nodes?: ReadonlyArray<PageNode> | undefined;
72
+ }
73
+ /** The frames something is in, outermost first (see `framesOf`); empty for the page itself. */
74
+ export type Frames = ReadonlyArray<ElementTarget>;
75
+ /** What a scroll step scrolls: an element into view, or the page or a frame to an end or by pixels. */
76
+ export type ScrollTo = {
77
+ readonly _tag: 'target';
78
+ readonly target: Target;
79
+ } | {
80
+ readonly _tag: 'end';
81
+ readonly to: 'top' | 'bottom';
82
+ readonly frames: Frames;
83
+ } | {
84
+ readonly _tag: 'by';
85
+ readonly by: number;
86
+ readonly frames: Frames;
87
+ };
88
+ /** What a step looked for and did not find: a text, or an element. */
89
+ export type Sought = {
90
+ readonly _tag: 'text';
91
+ readonly text: string;
92
+ } | {
93
+ readonly _tag: 'element';
94
+ readonly target: ElementTarget;
95
+ };
96
+ /**
97
+ * Where something a step did not find is after all, outside where the step looked
98
+ * (see `BrowserPage.findElsewhere`).
99
+ */
100
+ export interface Elsewhere {
101
+ /** In the page itself, outside every frame. Only looked for when the step named a frame. */
102
+ readonly inPage: boolean;
103
+ /**
104
+ * Up to 2 of the visible frames it is in, each as the frames that lead to it, outermost first,
105
+ * found the way a person would name them (see `frameSelector`).
106
+ */
107
+ readonly frames: ReadonlyArray<Frames>;
108
+ /** How many of the visible frames looked in hold it. */
109
+ readonly count: number;
110
+ }
111
+ /** Where text that should not show did (see `BrowserPage.watchText`). */
112
+ export interface TextSeen {
113
+ /** How it showed: as visible text, as the alt text of an image, or as an ARIA label. */
114
+ readonly as: 'text' | 'alt' | 'label';
115
+ /** The text, alt text or label that holds it, around it and cut short. */
116
+ readonly value: string;
117
+ /** Where in its document, as a short selector such as `.clients`; undefined when nothing says. */
118
+ readonly near?: string | undefined;
119
+ /**
120
+ * The frames it is in, outermost first, found the way a person would name them (see
121
+ * `frameSelector`); empty for where the step looked itself.
122
+ */
123
+ readonly frames: Frames;
124
+ }
125
+ /** What `BrowserPage.watchText` saw. */
126
+ export type TextWatch = {
127
+ readonly _tag: 'absent';
128
+ } | {
129
+ readonly _tag: 'shown';
130
+ readonly seen: TextSeen;
131
+ }
132
+ /** Nothing showed where it looked within the wait, so its absence would prove nothing. */
133
+ | {
134
+ readonly _tag: 'empty';
135
+ }
136
+ /** Not all of where it had to look could be read, such as a frame that did not answer. */
137
+ | {
138
+ readonly _tag: 'incomplete';
139
+ readonly reason: string;
140
+ };
141
+ /**
142
+ * Where `BrowserPage.watchText` looks: in `target`, or else the document `frames` lead to (the
143
+ * page itself when empty); the frames visible inside it too.
144
+ */
145
+ export interface TextScope {
146
+ readonly frames: Frames;
147
+ readonly target?: Target | undefined;
148
+ }
149
+ /**
150
+ * When and where an action of `BrowserPage` happened, for drawing it over the video
151
+ * (`StepAction`). Times are relative, so the caller puts them on the video's clock.
152
+ */
153
+ export interface ActionTrace {
154
+ /**
155
+ * How long after the operation was called it acted, in ms: when the browser dispatched the
156
+ * click or the key to the page, or the load started. Missing when that was not seen, and for a
157
+ * fill or files set on a file input directly (a page can make their edits itself).
158
+ */
159
+ readonly afterMs?: number | undefined;
160
+ /**
161
+ * Where the mouse pressed, in the viewport in CSS pixels, as the video shows it (not in the
162
+ * page's layout, which a phone may show scaled or zoomed), when it did and that is certain.
163
+ */
164
+ readonly point?: Point | undefined;
165
+ /**
166
+ * The element acted on, in the viewport in CSS pixels, where it showed (not in the page's layout,
167
+ * which a phone may show scaled or zoomed), when it could be measured and that is certain.
168
+ */
169
+ readonly target?: Box | undefined;
170
+ /** The visual viewport's scale `target` was measured at, which it accounts for. */
171
+ readonly scale?: number | undefined;
172
+ /** The viewport's size in CSS pixels, which `point` and `target` are measured against. */
173
+ readonly viewport?: {
174
+ readonly width: number;
175
+ readonly height: number;
176
+ } | undefined;
177
+ }
178
+ /** How long an operation may wait; without one, the adapter's default for it. */
179
+ export interface Wait {
180
+ readonly timeoutMs?: number | undefined;
181
+ }
182
+ /**
183
+ * A file an upload step sends, as checked before the run started: `path` as the job gives it,
184
+ * `absolute` where it really is (links resolved), and its size in bytes.
185
+ */
186
+ export interface UploadSource {
187
+ readonly path: string;
188
+ readonly absolute: string;
189
+ readonly size: number;
190
+ }
191
+ /**
192
+ * The tab a session's cases run in, one after another. The adapter owns the default timeouts
193
+ * (`DEFAULT_WAIT_MS`, `DEFAULT_LOAD_MS`); a step's `timeoutMs` replaces them. Every operation gives
194
+ * up rather than hanging.
195
+ */
196
+ export interface BrowserPage {
197
+ /**
198
+ * goto, reload, click, fill, upload and press fail only when the action itself could not be
199
+ * performed. What the documents they load come to is judged by `settle`. Each says when it
200
+ * acted and, for an element, where (see `ActionTrace`).
201
+ */
202
+ readonly goto: (url: string, wait?: Wait) => Effect.Effect<ActionTrace, PageActionFailed>;
203
+ readonly reload: (wait?: Wait) => Effect.Effect<ActionTrace, PageActionFailed>;
204
+ readonly click: (target: Target, wait?: Wait) => Effect.Effect<ActionTrace, PageActionFailed>;
205
+ readonly fill: (target: Target, value: string, wait?: Wait) => Effect.Effect<ActionTrace, PageActionFailed>;
206
+ /**
207
+ * Sets `files` (absolute paths) on the file input `target` matches, hidden or not, or else
208
+ * clicks `target` and sets them on the file chooser that opens. Fails when there is neither,
209
+ * or when a single-file input or chooser is given more than one file.
210
+ */
211
+ readonly upload: (target: Target, files: ReadonlyArray<string>, wait?: Wait) => Effect.Effect<ActionTrace, PageActionFailed>;
212
+ readonly press: (key: string) => Effect.Effect<ActionTrace, PageActionFailed>;
213
+ /**
214
+ * The absolute URL the element links to, when it is (or is inside) a link with an `href`, so
215
+ * a click can be refused before it goes anywhere. Waits for the element like `click` does.
216
+ */
217
+ readonly linkUrl: (target: Target, wait?: Wait) => Effect.Effect<string | undefined, PageActionFailed>;
218
+ /** Waits for the text to be visible, in the page or in `frames`. False means it never was. */
219
+ readonly hasText: (text: string, wait?: Wait, frames?: Frames) => Effect.Effect<boolean, PageActionFailed>;
220
+ /**
221
+ * Waits until where `scope` says shows anything at all (any visible text or image, waiting for
222
+ * `target` or the frame like `click` does), and every frame inside it does too, then watches it
223
+ * for `watchMs` for `text`, as visible text, image alt text or an ARIA label. `absent` only
224
+ * when every look in that time read all of it; `incomplete` when, by the end of the wait, not
225
+ * all of it could be read; `empty` when nothing showed within the wait.
226
+ */
227
+ readonly watchText: (text: string, scope: TextScope, watchMs: number, wait?: Wait) => Effect.Effect<TextWatch, PageActionFailed>;
228
+ /**
229
+ * Waits until `target` reaches `state` (see `WaitState`). False means it did not in time; a
230
+ * failure means it could not be looked for.
231
+ */
232
+ readonly waitFor: (target: Target, state: WaitState, wait?: Wait) => Effect.Effect<boolean, PageActionFailed>;
233
+ /**
234
+ * Scrolls an element into view (waiting for it like `click`), or the page or a frame (waiting
235
+ * for the frame) to its top or bottom or by some pixels down.
236
+ */
237
+ readonly scroll: (to: ScrollTo, wait?: Wait) => Effect.Effect<ActionTrace, PageActionFailed>;
238
+ /** Waits for the URL to contain `includes`. */
239
+ readonly urlIncludes: (includes: string, wait?: Wait) => Effect.Effect<boolean, PageActionFailed>;
240
+ readonly url: Effect.Effect<string>;
241
+ /**
242
+ * Called before step `next` runs, and before the case is judged. Waits until no main-frame
243
+ * document of any of the case's pages is loading (each for the time it was given from when it
244
+ * started), then judges every one that started since the last call, and from now on counts
245
+ * new ones as step `next`'s, giving each `loadTimeoutMs` (see `loadTimeoutOf`). Resolves with
246
+ * the problem of the earliest step, if any.
247
+ */
248
+ readonly settle: (next: number, loadTimeoutMs: number) => Effect.Effect<LoadProblem | undefined>;
249
+ /**
250
+ * The first navigation of the case to a URL that is not http or https, in any frame of any of
251
+ * its pages (popups included); undefined while there was none. From then on nothing of the
252
+ * case's pages may be captured.
253
+ */
254
+ readonly refused: Effect.Effect<Refusal | undefined>;
255
+ /**
256
+ * Looks for `sought`, which a step did not find in `frames` (the page itself when empty), in the
257
+ * page itself and in the visible frames, as they are now, without waiting. Bounded in time and in
258
+ * how many frames it reads; undefined when it is nowhere else, or when that could not be told.
259
+ * Never fails.
260
+ */
261
+ readonly findElsewhere: (sought: Sought, frames: Frames) => Effect.Effect<Elsewhere | undefined>;
262
+ /**
263
+ * Saves a PNG at `path`, an absolute file path: the whole page, or what is in the viewport. With
264
+ * `target`, that element is scrolled into view first when it can be, and its box is measured,
265
+ * without waiting for it.
266
+ */
267
+ readonly screenshot: (path: string, options: {
268
+ readonly fullPage: boolean;
269
+ readonly target?: Target | undefined;
270
+ }) => Effect.Effect<ShotCapture, PageActionFailed>;
271
+ /**
272
+ * Short facts about the page now (see `PageFacts`); with `text`, the visible text near
273
+ * `target`, or the start of the page's when there is none or it is not found. Never fails.
274
+ */
275
+ readonly facts: (options: {
276
+ readonly target: Target | undefined;
277
+ readonly text: boolean;
278
+ }) => Effect.Effect<PageFacts>;
279
+ }
280
+ /**
281
+ * One test user in one browser, start to end: one context and one tab, recorded as one
282
+ * continuous video. Cases share its cookies and storage. Closed when its scope closes.
283
+ */
284
+ export interface BrowserSessionPage {
285
+ readonly page: BrowserPage;
286
+ /**
287
+ * Called before each case: closes tabs and windows the last case opened and starts watching
288
+ * page loads afresh, so nothing of the last case is judged against this one. With `continues`,
289
+ * the case goes on from the page the last case left (`CaseSpec.continue`): a way off the web
290
+ * that case took is not forgotten, since its page may still show it.
291
+ */
292
+ readonly beginCase: (options?: {
293
+ readonly continues?: boolean;
294
+ }) => Effect.Effect<void>;
295
+ /** Why the browser stopped working (it crashed or closed), once it has. */
296
+ readonly crashed: Effect.Effect<string | undefined>;
297
+ /** When the video started, in epoch ms from `Clock`. */
298
+ readonly videoStartedAt: number;
299
+ /**
300
+ * Closes the session and saves its video at the path it was opened with. Resolves with why
301
+ * there is no video, when recording was not possible. Safe to call more than once.
302
+ */
303
+ readonly close: Effect.Effect<{
304
+ readonly videoProblem: string | undefined;
305
+ }>;
306
+ }
307
+ /** An open browser. Closed when its scope closes. */
308
+ export interface BrowserSession {
309
+ readonly info: BrowserInfo;
310
+ /**
311
+ * A session in a fresh context. With `video`, it is recorded: the recorder works in `dir` (an
312
+ * absolute folder path), and the video is saved at `path` (an absolute file path inside it).
313
+ */
314
+ readonly newSession: (options: {
315
+ readonly device: Device;
316
+ readonly video: {
317
+ readonly dir: string;
318
+ readonly path: string;
319
+ } | undefined;
320
+ }) => Effect.Effect<BrowserSessionPage, PageActionFailed, Scope.Scope>;
321
+ }
322
+ /** A screenshot to draw boxes on, for copies people can paste where no overlay is possible. */
323
+ export interface AnnotateJob {
324
+ /** Absolute paths of the screenshot and the copy to write. */
325
+ readonly image: string;
326
+ readonly out: string;
327
+ /** Image size in pixels. */
328
+ readonly width: number;
329
+ readonly height: number;
330
+ readonly marks: ReadonlyArray<{
331
+ readonly box: Box;
332
+ readonly color: 'red' | 'green';
333
+ /** Short text drawn by the box, such as its number. */
334
+ readonly label: string;
335
+ }>;
336
+ /** Boxes of the page's other elements, which labels keep off where they can. */
337
+ readonly obstacles?: ReadonlyArray<Box>;
338
+ }
339
+ declare const Browser_base: Context.ServiceClass<Browser, "screw-bugs/Browser", {
340
+ readonly detect: Effect.Effect<BrowserInfo, BrowserNotFound>;
341
+ readonly open: (options: {
342
+ readonly headed: boolean;
343
+ }) => Effect.Effect<BrowserSession, BrowserNotFound, Scope.Scope>;
344
+ /** What `device` emulates, for people reading a run: "Desktop", "iPhone 17 (Chromium)". */
345
+ readonly deviceLabel: (device: Device) => string;
346
+ /**
347
+ * Draws the boxes onto copies of screenshots, in a browser of its own that opens nothing but
348
+ * them. Resolves with the copies it wrote; one that fails is left out.
349
+ */
350
+ readonly annotate: (jobs: ReadonlyArray<AnnotateJob>) => Effect.Effect<ReadonlyArray<string>, BrowserNotFound>;
351
+ }>;
352
+ /** Finds and launches a browser. Headless unless `headed` is set (used for logins). */
353
+ export declare class Browser extends Browser_base {
354
+ }
355
+ /** A run as listed by `screw-bugs runs`. */
356
+ export interface RunSummary {
357
+ readonly job: JobRecord;
358
+ /** Undefined when the ledger is missing or unreadable. */
359
+ readonly ledger: CaseLedger | undefined;
360
+ }
361
+ declare const Storage_base: Context.ServiceClass<Storage, "screw-bugs/Storage", {
362
+ readonly createRun: (spec: JobSpec) => Effect.Effect<JobId, StorageFailed>;
363
+ readonly readJob: (jobId: JobId) => Effect.Effect<JobRecord, RunNotFound | StorageFailed>;
364
+ readonly readLedger: (jobId: JobId) => Effect.Effect<CaseLedger, RunNotFound | StorageFailed>;
365
+ readonly writeLedger: (ledger: CaseLedger) => Effect.Effect<void, StorageFailed>;
366
+ /** Most recent first. */
367
+ readonly listRuns: (limit: number) => Effect.Effect<ReadonlyArray<RunSummary>, StorageFailed>;
368
+ /**
369
+ * Writes the run's own `report.html` and returns its path, then deletes a leftover
370
+ * `report-interrupted.html`. Only the run itself, or `screw-bugs report` once the run has
371
+ * ended, writes it.
372
+ */
373
+ readonly writeReport: (jobId: JobId, html: string) => Effect.Effect<string, StorageFailed>;
374
+ /**
375
+ * Writes `report-interrupted.html`, the report of a run whose process is gone, and returns
376
+ * its path. It never touches `report.html`.
377
+ */
378
+ readonly writeInterruptedReport: (jobId: JobId, html: string) => Effect.Effect<string, StorageFailed>;
379
+ /**
380
+ * The run's report to show: `report.html` when it exists, otherwise
381
+ * `report-interrupted.html` when that does, otherwise undefined.
382
+ */
383
+ readonly findReport: (jobId: JobId) => Effect.Effect<string | undefined>;
384
+ readonly runDir: (jobId: JobId) => string;
385
+ /**
386
+ * Absolute path of an evidence file, such as `01/02-after-login.png`; the ledger records it as
387
+ * `evidence/<fileName>`. Missing folders on the way are created by whoever writes the file.
388
+ */
389
+ readonly evidencePath: (jobId: JobId, fileName: string) => string;
390
+ /** Absolute path of a file in the run folder, such as `video/session-1.webm`. */
391
+ readonly filePath: (jobId: JobId, relative: string) => string;
392
+ /**
393
+ * Writes a text file in the run folder (`evidence.json`, `findings.json`, a screenshot's page
394
+ * state), creating folders on the way; atomically, like the ledger.
395
+ */
396
+ readonly writeFile: (jobId: JobId, relative: string, text: string) => Effect.Effect<void, StorageFailed>;
397
+ /** A text file in the run folder; undefined when it does not exist. */
398
+ readonly readFile: (jobId: JobId, relative: string) => Effect.Effect<string | undefined, StorageFailed>;
399
+ /** The size and first `headBytes` bytes of a file in the run folder, if it exists. */
400
+ readonly probe: (jobId: JobId, relative: string, headBytes: number) => Effect.Effect<{
401
+ readonly size: number;
402
+ readonly head: Uint8Array;
403
+ } | undefined>;
404
+ }>;
405
+ /**
406
+ * Runs, ledgers and evidence. Paths it returns are absolute. Everything is read back from
407
+ * storage, so a run started by one process can be checked from another.
408
+ */
409
+ export declare class Storage extends Storage_base {
410
+ }
411
+ declare const ReportRenderer_base: Context.ServiceClass<ReportRenderer, "screw-bugs/ReportRenderer", {
412
+ readonly html: (bundle: ReportBundle) => string;
413
+ /** The run's walkthrough (`runFiles.walkthrough`): its video and every step as a script. */
414
+ readonly walkthrough: (bundle: ReportBundle) => string;
415
+ }>;
416
+ /**
417
+ * Turns a run into its HTML report. Pure: the `report` module provides it, and the engine writes
418
+ * what it returns through `Storage`.
419
+ */
420
+ export declare class ReportRenderer extends ReportRenderer_base {
421
+ }
422
+ /** A saved login. Listings never include secrets. */
423
+ export interface AccountSummary {
424
+ readonly label: string;
425
+ readonly origin: string;
426
+ }
427
+ declare const AccountBook_base: Context.ServiceClass<AccountBook, "screw-bugs/AccountBook", {
428
+ readonly list: Effect.Effect<ReadonlyArray<AccountSummary>, NotImplemented>;
429
+ }>;
430
+ /** Test accounts the engine can log in with. */
431
+ export declare class AccountBook extends AccountBook_base {
432
+ }
433
+ export interface JobEvent {
434
+ readonly jobId: JobId;
435
+ readonly state: JobState;
436
+ readonly message: string;
437
+ }
438
+ declare const Notifier_base: Context.ServiceClass<Notifier, "screw-bugs/Notifier", {
439
+ readonly notify: (event: JobEvent) => Effect.Effect<void>;
440
+ }>;
441
+ /** Tells the outside world about job progress (terminal, MCP client, later screw-bugs Cloud). */
442
+ export declare class Notifier extends Notifier_base {
443
+ }
444
+ export {};
@@ -0,0 +1,22 @@
1
+ import { Context } from 'effect';
2
+ /** Finds and launches a browser. Headless unless `headed` is set (used for logins). */
3
+ export class Browser extends Context.Service()('screw-bugs/Browser') {
4
+ }
5
+ /**
6
+ * Runs, ledgers and evidence. Paths it returns are absolute. Everything is read back from
7
+ * storage, so a run started by one process can be checked from another.
8
+ */
9
+ export class Storage extends Context.Service()('screw-bugs/Storage') {
10
+ }
11
+ /**
12
+ * Turns a run into its HTML report. Pure: the `report` module provides it, and the engine writes
13
+ * what it returns through `Storage`.
14
+ */
15
+ export class ReportRenderer extends Context.Service()('screw-bugs/ReportRenderer') {
16
+ }
17
+ /** Test accounts the engine can log in with. */
18
+ export class AccountBook extends Context.Service()('screw-bugs/AccountBook') {
19
+ }
20
+ /** Tells the outside world about job progress (terminal, MCP client, later screw-bugs Cloud). */
21
+ export class Notifier extends Context.Service()('screw-bugs/Notifier') {
22
+ }
@@ -0,0 +1,96 @@
1
+ import { Effect } from 'effect';
2
+ import { type CaseEntry, type CaseSpec, type LinkMatch, type ShotPage, type Step, type Target } from '../schema/index.js';
3
+ import type { BrowserPage, Elsewhere, Frames, TextSeen, UploadSource } from './services.js';
4
+ /** Where a screenshot goes: `path` is absolute, `relative` is what the ledger records. */
5
+ export interface EvidenceFile {
6
+ readonly path: string;
7
+ readonly relative: string;
8
+ }
9
+ /**
10
+ * A screenshot name as a decorative part of a file name: lowercase letters, digits and dashes,
11
+ * at most `SLUG_MAX` characters. It never makes a file name unique on its own; see
12
+ * {@link evidenceFileName}.
13
+ */
14
+ export declare const fileSlug: (name: string) => string;
15
+ /**
16
+ * Where the `shot`th screenshot of the `caseNumber`th case is stored, relative to the evidence
17
+ * folder, such as `01/03-after-login.png`. Both numbers are 1-based. The numbers alone make a name
18
+ * unique, so it does not depend on how a file system compares names: `A` and `a`, or `shot` and
19
+ * `SHOT`, never land on the same file on Windows or macOS. The name starts with digits and holds
20
+ * only lowercase letters, digits and dashes, so it is never a reserved Windows name (`CON`,
21
+ * `LPT1`) and never ends in a dot or space.
22
+ */
23
+ export declare const evidenceFileName: (caseNumber: number, shot: number, name: string) => string;
24
+ /** Where something is, innermost frame first, such as ` in iframe css "iframe.preview"`. */
25
+ export declare const describeFrames: (frames: Frames) => string;
26
+ /** Such as `text "Save" in iframe css "iframe.preview"`. */
27
+ export declare const describeTarget: (target: Target) => string;
28
+ export declare const describeStep: (step: Step) => string;
29
+ /** Relative URLs (`/login`) are resolved against the job URL. */
30
+ export declare const resolveUrl: (url: string, base: string) => string;
31
+ /**
32
+ * The scheme of a URL screw-bugs must not open or capture, such as `file:`; undefined for http
33
+ * and https (see `WEB_SCHEMES`). `about:blank` holds nothing, so it passes too: it is where a
34
+ * page starts, and where it stays when a load fails.
35
+ */
36
+ export declare const refusedScheme: (url: string) => string | undefined;
37
+ /**
38
+ * The first step of every case is a navigation, so each case starts from a known page: a case
39
+ * that does not begin with goto starts at the job URL. A case that continues (`CaseSpec.continue`)
40
+ * starts where the case before it ended instead, with its own steps only.
41
+ */
42
+ export declare const withStartPage: (spec: Pick<CaseSpec, 'steps' | 'continue'>, jobUrl: string) => ReadonlyArray<Step>;
43
+ /**
44
+ * What to change when a step did not find its text or element where it looked (`given`, the
45
+ * page itself when empty) but it is somewhere else (`found`): the `frame` to add, to use instead,
46
+ * or to remove. Up to `named` frames are named, and how many hold it. `inTarget` says that `frame`
47
+ * goes on the step's target. Undefined when there is nothing to say.
48
+ */
49
+ export declare const frameHint: (found: Elsewhere, given: Frames, inTarget: boolean, named?: number) => string | undefined;
50
+ /**
51
+ * A reason with a hint after it (see `frameHint`), kept within `REASON_MAX` so the hint shows
52
+ * whole where reasons are cut. `hints` says the same in fewer words each, most first; the first
53
+ * that fits is used, with the step's own message, else with `short`. When none fits, the
54
+ * shortest is used, with `label` cut at a word (or only its step number).
55
+ */
56
+ export declare const withHint: (label: string, message: string, short: string, hints: ReadonlyArray<string>) => string;
57
+ /**
58
+ * Whether a link's address `href` (absolute) is what an `expectLink` step expects: contains its
59
+ * `href`, or with `exact` is it, resolved against the page's URL `pageUrl` when it is a path.
60
+ */
61
+ export declare const linkMatches: (href: string, expected: string, match: LinkMatch, pageUrl: string) => boolean;
62
+ /** How text that should not show did, such as `image alt "Acme logo" in .clients`. */
63
+ export declare const seenText: (seen: TextSeen) => string;
64
+ /** `01-03`: the ID of the 3rd screenshot of the 1st case, as agents name screenshots. */
65
+ export declare const shotId: (caseNumber: number, shot: number) => string;
66
+ /**
67
+ * Runs one case's steps in order and maps the outcome to a status: `passed` when every step ran
68
+ * and every expectation held, `failed` at the first expectation that did not hold, `blocked`
69
+ * at the first step that could not run. A case that does not pass also gets a screenshot of
70
+ * the page as it was. Records when it and each step ran (`now`), every screenshot with the page
71
+ * state saved next to it, and a few facts about the page at the end.
72
+ */
73
+ export declare const runCase: (page: BrowserPage, spec: CaseSpec, options: {
74
+ readonly jobUrl: string;
75
+ /** 1-based position of the case in its job; it names the case's evidence folder. */
76
+ readonly caseNumber: number;
77
+ /**
78
+ * Maps a screenshot's file name in the evidence folder (see {@link evidenceFileName}) to where
79
+ * it is stored.
80
+ */
81
+ readonly evidenceFile: (fileName: string) => EvidenceFile;
82
+ /** Milliseconds since the session's video started. */
83
+ readonly now: Effect.Effect<number>;
84
+ /** Saves the page state of a screenshot (`ShotPage`) as JSON at an evidence file name. */
85
+ readonly savePage: (fileName: string, page: ShotPage) => Effect.Effect<void, unknown>;
86
+ /**
87
+ * The checked file behind an upload path as the job gives it; undefined for one that was not
88
+ * checked, which is never sent.
89
+ */
90
+ readonly uploads?: ((path: string) => UploadSource | undefined) | undefined;
91
+ /**
92
+ * For a case that continues: the ID of the case before it, whose page it starts on. The
93
+ * ledger records it.
94
+ */
95
+ readonly continuedFrom?: string | undefined;
96
+ }) => Effect.Effect<CaseEntry>;