screw-bugs 0.1.0 → 0.1.1-next.1.g2238271

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 (53) hide show
  1. package/README.md +79 -44
  2. package/dist/browser-playwright/launch.d.ts +7 -2
  3. package/dist/browser-playwright/launch.js +31 -8
  4. package/dist/browser-playwright/page.d.ts +12 -5
  5. package/dist/browser-playwright/page.js +52 -14
  6. package/dist/build-info.json +3 -3
  7. package/dist/cli/app.js +31 -3
  8. package/dist/cli/build-info.d.ts +7 -0
  9. package/dist/cli/build-info.js +17 -1
  10. package/dist/cli/commands.js +6 -2
  11. package/dist/cli/doctor.d.ts +7 -1
  12. package/dist/cli/doctor.js +23 -9
  13. package/dist/cli/exit-codes.d.ts +4 -1
  14. package/dist/cli/exit-codes.js +4 -1
  15. package/dist/cli/install-method.d.ts +12 -2
  16. package/dist/cli/install-method.js +12 -4
  17. package/dist/cli/mcp.js +4 -0
  18. package/dist/cli/operations.d.ts +6 -3
  19. package/dist/cli/operations.js +36 -14
  20. package/dist/cli/report-server.d.ts +15 -6
  21. package/dist/cli/report-server.js +73 -8
  22. package/dist/cli/update-check.d.ts +27 -11
  23. package/dist/cli/update-check.js +45 -24
  24. package/dist/core/engine.d.ts +6 -0
  25. package/dist/core/engine.js +41 -3
  26. package/dist/core/services.d.ts +17 -0
  27. package/dist/report/bug.d.ts +11 -0
  28. package/dist/report/bug.js +19 -0
  29. package/dist/report/html.d.ts +26 -24
  30. package/dist/report/html.js +704 -618
  31. package/dist/report/icons.d.ts +40 -0
  32. package/dist/report/icons.js +81 -0
  33. package/dist/report/logos.d.ts +4 -0
  34. package/dist/report/logos.js +19 -0
  35. package/dist/report/markup.d.ts +25 -6
  36. package/dist/report/markup.js +110 -22
  37. package/dist/report/player.d.ts +76 -0
  38. package/dist/report/player.js +249 -0
  39. package/dist/report/shots.d.ts +56 -0
  40. package/dist/report/shots.js +276 -0
  41. package/dist/report/styles.js +220 -265
  42. package/dist/report/view.d.ts +135 -0
  43. package/dist/report/view.js +288 -0
  44. package/dist/report/walkthrough.d.ts +26 -22
  45. package/dist/report/walkthrough.js +309 -163
  46. package/dist/schema/doctor.d.ts +3 -3
  47. package/dist/schema/doctor.js +8 -1
  48. package/dist/schema/findings.js +1 -5
  49. package/dist/schema/job.d.ts +20 -0
  50. package/dist/schema/job.js +10 -0
  51. package/dist/schema/ledger.d.ts +37 -1
  52. package/dist/schema/ledger.js +21 -0
  53. package/package.json +1 -1
package/README.md CHANGED
@@ -19,9 +19,10 @@ npx screw-bugs@latest doctor
19
19
 
20
20
  `doctor` installs nothing. It tells you what is missing, the command that fixes it and why.
21
21
 
22
- Session videos need Playwright's ffmpeg. If `doctor` cannot find it, it warns (exit code stays 0)
23
- and prints the command that downloads it, `npx -y playwright-core@<version> install ffmpeg`, pinned
24
- to the Playwright that screw-bugs uses. Runs still work without it; they just have no video.
22
+ Every run is recorded as video, which needs Playwright's ffmpeg. If `doctor` cannot find it, it
23
+ fails (exit code 4) and prints the command that downloads it,
24
+ `npx -y playwright-core@<version> install ffmpeg`, pinned to the Playwright that screw-bugs uses.
25
+ Without it no run starts: `start_run` and `screw-bugs run` reply with the same command (exit code 4).
25
26
 
26
27
  ## Use from a coding agent (MCP)
27
28
 
@@ -29,6 +30,11 @@ to the Playwright that screw-bugs uses. Runs still work without it; they just ha
29
30
  claude mcp add screw-bugs -- npx -y screw-bugs@latest mcp
30
31
  ```
31
32
 
33
+ To try the newest build of `main` instead, use the `next` channel: every merge to `main` is
34
+ published as a prerelease under the npm tag `next` (for example `0.1.1-next.57.gfa82ee8`, which
35
+ names its commit), with `npx -y screw-bugs@next mcp`. `doctor` shows the version and commit that is
36
+ running. A `next` build checks for, and suggests, newer `next` builds only.
37
+
32
38
  Tools: `doctor`, `start_run` (returns a job ID right away; the run continues inside the MCP
33
39
  server), `run_status`, `submit_findings`, `answer_question`. `start_run` takes the same job as a
34
40
  `--spec` file, without `version`, and there `summary` is required. Upload paths are relative to the
@@ -177,6 +183,7 @@ Limits (each text is one line, not blank; findings past them are rejected with w
177
183
  {
178
184
  "version": 1,
179
185
  "url": "http://localhost:3000",
186
+ "title": "Sign-in after the refactor",
180
187
  "instructions": "check that login still works after my refactor",
181
188
  "summary": "Signing in with a test account still reaches the dashboard and greets the user.",
182
189
  "cases": [
@@ -196,16 +203,20 @@ Limits (each text is one line, not blank; findings past them are rejected with w
196
203
  }
197
204
  ```
198
205
 
199
- Two optional free-text fields describe a job. screw-bugs saves both in `job.json` and shows them in
200
- `status` and the report, but never reads or interprets them: only `cases` decide what runs.
206
+ Three optional free-text fields describe a job. screw-bugs saves them in `job.json` and shows them
207
+ in `status` and the report, but never reads or interprets them: only `cases` decide what runs.
201
208
 
209
+ - `title`: a short name for the run, one line of at most 80 characters, such as
210
+ `Notes app walkthrough` or `Checkout on mobile`. It is the report's heading. Without one, the
211
+ heading is the app's own page title as the run recorded it (from the first case that recorded
212
+ one), else the target's host.
202
213
  - `instructions`: what the user asked for, in their own words (verbatim when possible). Provenance.
203
214
  - `summary`: what these cases test and why, written by whoever wrote the cases, for a reader who
204
215
  never sees the steps. Not a list of steps. Without one, screw-bugs derives a summary from the case
205
216
  titles, such as `Checks: page loads; signup with a valid email`.
206
217
 
207
- With `run`, `--instructions <text>` and `--summary <text>` override the same fields in a `--spec`
208
- file.
218
+ With `run`, `--title <text>`, `--instructions <text>` and `--summary <text>` override the same
219
+ fields in a `--spec` file.
209
220
 
210
221
  `device` is optional: `desktop` (the default, a 1280×800 window) or `mobile`, which emulates an
211
222
  iPhone 17 (Playwright's profile: viewport, user agent, pixel ratio and touch). screw-bugs only
@@ -233,7 +244,8 @@ Every step that waits (all but `screenshot`) takes an optional `timeoutMs`, from
233
244
  (three minutes): how long to wait for its element, text, URL, state or frame (default 5000), or
234
245
  for the page it loads (`goto`, `reload`, `press`; default 15000). A page that a `click`, `fill`, `upload` or an
235
246
  expectation starts loading gets at least the default 15 seconds, or the step's `timeoutMs` when
236
- that is longer. Use it for slow work, such as generation that takes a minute:
247
+ that is longer. A page load that has not finished by then blocks the case and is stopped, so the
248
+ case's screenshot and page facts show the page as it was before that load. Use it for slow work, such as generation that takes a minute:
237
249
  `{ "action": "expectText", "text": "Your portfolio is ready", "timeoutMs": 120000 }`. A failed
238
250
  expectation says how long it waited (`did not appear within 5 s`), and the report shows a timeout
239
251
  that is not the default next to its step (`waited up to 120 s`).
@@ -501,7 +513,8 @@ That way each check of what a case made is a case of its own, and one failure hi
501
513
 
502
514
  A continuing case runs whatever the case before it came to, failed or blocked; only a browser that
503
515
  crashed stops the run, as always. Tabs and windows the case before it opened are closed, and its
504
- page loads are not judged again, but a way off the web it took (such as a `data:` frame) still
516
+ page loads are not judged again (one that did not finish was stopped, so the continuing case
517
+ starts on the page as it was before that load), but a way off the web it took (such as a `data:` frame) still
505
518
  blocks the continuing case. The first case of a job cannot continue: that job is rejected
506
519
  (`The first case, "generate", cannot continue: there is no case before it to continue from. …`).
507
520
  The ledger and the evidence pack record `continuedFrom` (the ID of the case before it), and the
@@ -527,8 +540,8 @@ A `target` is exactly one of `{ "role": "button", "name": "Save" }` (`name` opti
527
540
  [Frames](#frames)). When several elements match, the first visible one is used.
528
541
 
529
542
  Cases run one after another, in job order, in one browser session (one test user in one browser),
530
- recorded as one continuous video (`video/session-1.webm`, at most 1280×720). Cookies and storage
531
- carry over from one case to the next, so a case can rely on what an earlier one did (signing in)
543
+ recorded as one continuous video (`video/session-1.webm`, at the viewport's own size: 1280×800 on a
544
+ desktop, 402×680 on a phone). Cookies and storage carry over from one case to the next, so a case can rely on what an earlier one did (signing in)
532
545
  and can be affected by it. A failed or blocked case does not stop the session; only a browser that
533
546
  crashes does, and the cases after it are then `not_verified`. A case whose first step is not `goto`
534
547
  starts at the job URL, unless it continues (see below). A job without cases gets one "page loads" case: it opens the URL, passes when there is no HTTP
@@ -637,23 +650,33 @@ deletes the interrupted report once it has written its own.
637
650
 
638
651
  ### Report
639
652
 
640
- Every run that ends, finished or errored, writes `report.html` into its folder. It reads like a QA
641
- write-up: the headline verdict and the counts, with what was not tested and why; what to fix,
642
- most severe first; run details (target, device, times, video, version); then each case with its
643
- status, the session video starting at the case with timecodes to jump to, what was done and what
644
- worked and what didn't, its screenshots with the highlights drawn over them (a checkbox hides
645
- them), and its steps with their timecodes; then what to test next. Code lays out the page and
646
- decides every status; the agent's write-up fills fixed slots and is labelled as its own. Without a
647
- write-up the report shows the run alone.
648
-
649
- It is one self-contained file: inline styles, one small inline script allowed by its hash in the
650
- Content Security Policy, no fonts or network requests. Screenshots and the video load by relative
651
- paths, so it opens from disk and still works when the run folder is zipped or moved. It has a light
652
- and a dark theme: it follows the system, and a switch picks one (kept in the browser where it
653
- allows). Without script it follows the system, and timecodes are plain links that open the video
654
- at that time. Each case has its own player, which loads nothing until played (its "Play from"
655
- button shows where the case starts), and only one video plays at a time; so the screenshots load
656
- from any static server, also one without HTTP range requests such as `python3 -m http.server`.
653
+ Every run that ends, finished or errored, writes `report.html` into its folder. One page, one
654
+ player: at the top the target, the number of cases, how long the run took and the device, what was
655
+ asked (two lines, with the rest a click away) and a filter per status. Below, the run's video in a
656
+ browser window (a phone, for a run on a phone) with the page's address at each moment, as the run
657
+ recorded it, and beside it the evaluation and one card per case. The evaluation is the agent's
658
+ headline with the counts under it, one line per fix (most severe first), the agent's first fix as
659
+ "Fix first", and what was not tested and why; without a write-up, the counts alone. Each card has
660
+ the case's status (an icon and its word), its time on the video, why it did not pass, and its
661
+ screenshots: for a case that did not pass, the page when it stopped as "Actual" (beside one the
662
+ agent marked only in green as "Expected"), else small thumbnails. A screenshot opens in a viewer
663
+ with the highlights drawn over it (a checkbox hides them) and the element the step acted on; the
664
+ arrow keys step through the case's screenshots. "Steps and details" opens the case's steps with
665
+ their timecodes and the agent's write-up of it. Then what to test next, and the run's details
666
+ (what it checks, target, times, video, version, raw files). Scrolling the cases drives the player:
667
+ the case at the reading line plays, in a loop unless "Loop case" is off, when the cases follow the
668
+ video instead. Code lays out the page and decides every status; the agent's write-up fills fixed
669
+ slots and is labelled as its own.
670
+
671
+ It is one self-contained file: inline styles and one inline script allowed by its hash in the
672
+ Content Security Policy. The only thing it loads from the network is Geist and Geist Mono from
673
+ Google Fonts, when online; offline it falls back to the system's fonts. Screenshots and the video
674
+ load by relative paths, so it opens from disk and still works when the run folder is zipped or
675
+ moved. It has a light and a dark theme: it follows the
676
+ system, and a switch picks one (kept in the browser where it allows). Without script it follows the
677
+ system, the video has the browser's own controls, timecodes are plain links that open the video at
678
+ that time and screenshots open the image. One video loads at a time, so the screenshots load from
679
+ any static server, also one without HTTP range requests such as `python3 -m http.server`.
657
680
  `run`, `status` and the MCP tool `run_status` give its path once the run has ended.
658
681
 
659
682
  Only the run writes its `report.html`, plus `report` and `findings` under the rules below. For a
@@ -681,15 +704,18 @@ drawn in, and the report's path. It embeds no images, so it can be pasted into a
681
704
 
682
705
  ### Walkthrough
683
706
 
684
- With `report.html`, the run writes `walkthrough.html`: a page to click through what the run did. A
685
- video player on top, and below it the script: every step of every case in run order, grouped by
686
- case (its title and status), each with its timecode and the step in words (`0:01.5 Fill the field
687
- labelled "Note" with "this is a new line"`). As the video plays, the step playing now is shown in
688
- full contrast and the others are dimmed; the script scrolls to keep it in view (without motion
689
- when the system asks for less). Every timecode is a link: it seeks the video there and plays, and
690
- switches to the right session's video when it is in another one; when one session's video ends,
691
- the next one plays. Cases that did not pass are listed at the top, each with a link to where it
692
- was decided, and the step that decided one says its status and reason, in the report's words.
707
+ With `report.html`, the run writes `walkthrough.html`: a page to click through what the run did. The
708
+ video in a browser window (a phone, for a run on a phone, with the script beside it on a wide
709
+ screen) with the page's address at each moment, controls under it (speed, "Skip inactive" to jump
710
+ over stretches where no step ran, the cursor overlay, fullscreen), and below it the script: every
711
+ step of every case in run order, grouped by case (its title and status), each with its timecode
712
+ and the step in words (`0:01.5 Fill the field labelled "Note" with "this is a new line"`). As the
713
+ video plays, the step playing now is the script's top row, highlighted (without motion when the
714
+ system asks for less); "Expand" shows the whole script. Every timecode and row seeks the video
715
+ there (playing on if it was playing, staying paused if not), and switches to the right session's video when it is in another one; when one
716
+ session's video ends, the next one plays. The step that decided a case that did not pass says its
717
+ status and reason, in the report's words, and those cases are listed under the script, each with a
718
+ link to where it was decided.
693
719
  While a step that acted on an element is playing, a box over the video shows that element: taken
694
720
  from the step's screenshot of the viewport, measured as the step ran, and drawn only around the
695
721
  moment it was measured. Steps with no such measurement get no box. Boxes on the video, on the
@@ -725,18 +751,19 @@ motion the cursor jumps instead of gliding and there is no ripple. **Show cursor
725
751
  turns it off; the choice is remembered like the theme. Runs from before actions were recorded have
726
752
  none of it.
727
753
 
728
- Like the report it is self-contained, loads nothing from the network, links the video by relative
729
- path, follows the light and dark theme, and works from disk and over the report server. A run with
754
+ Like the report it is self-contained, loads only Geist and Geist Mono from Google Fonts when
755
+ online (falling back to the system's fonts offline), links the video by relative path, follows the
756
+ light and dark theme, and works from disk and over the report server. A run with
730
757
  no video, or an older run with no step times, still lists every step and error, and says why the
731
758
  times cannot be played.
732
759
 
733
- It is written under the same rules as `report.html`: by the run when it ends, and again by
734
- `report`, `findings`/`submit_findings` and `walkthrough`; never by status reads, and never for an
735
- interrupted run (`report-interrupted.html` has no walkthrough). The report links it near the top
736
- when it exists.
760
+ It is written with `report.html`: by the run when it ends, and again by `report` and
761
+ `findings`/`submit_findings`; never by status reads, and never for an interrupted run
762
+ (`report-interrupted.html` has no walkthrough). `walkthrough` rewrites only the walkthrough and
763
+ leaves the report as it is. The report links it near the top when it exists.
737
764
 
738
765
  ```sh
739
- screw-bugs walkthrough <job-id> # (re)write it with the report and print its path
766
+ screw-bugs walkthrough <job-id> # (re)write it (not the report) and print its path
740
767
  screw-bugs walkthrough <job-id> --serve # serve it at a http://127.0.0.1 URL, as report --serve
741
768
  ```
742
769
 
@@ -773,6 +800,10 @@ processes, sessions and `report --serve`, as long as one of them serves the proj
773
800
  - An MCP server that is not on the project's port tries it again each time it gives a URL. Once it
774
801
  is free, it serves there too and gives that URL from then on; a free-port server it started
775
802
  keeps running, so links it gave before still work.
803
+ - An MCP server that gave out another MCP server's URL also tries the port every 2 seconds in the
804
+ background, and serves there as soon as that one ends. So the project's report server lives as
805
+ long as any of its MCP servers that gave links to it, even when the one that started it (say, a
806
+ subagent's) is gone.
776
807
  - `report --serve --port <n>` uses exactly that port, and fails if it is taken (`--port 0` picks a
777
808
  free one).
778
809
 
@@ -848,6 +879,10 @@ checkout's (`pnpm build` stamps `dist/build-info.json`), it suggests `pnpm build
848
879
  MCP server loaded an older build or version than is installed now, it says to restart the server
849
880
  (in Claude Code: `/mcp`, pick screw-bugs, Reconnect).
850
881
 
882
+ A `next` build (see [Use from a coding agent](#use-from-a-coding-agent-mcp)) asks for the newest
883
+ `next` build instead of `latest`, keeps its own cache file (`update-check-next.json`), and its
884
+ commands use `@next` (`npx -y screw-bugs@next mcp`, `npm i -g screw-bugs@next`, …).
885
+
851
886
  Turn the check off with `SCREW_BUGS_UPDATE_CHECK=0`. It is always off with `CI=true`.
852
887
 
853
888
  ### Analytics
@@ -1,7 +1,10 @@
1
1
  import { Effect, FileSystem, Layer, Path } from 'effect';
2
2
  import { Browser } from '../core/index.js';
3
- /** Launches the installed Chrome, else Edge, else Playwright's downloaded Chromium. */
4
- export declare const BrowserPlaywright: Layer.Layer<Browser, never, never>;
3
+ /**
4
+ * Launches the installed Chrome, else Edge, else Playwright's downloaded Chromium. Needs the
5
+ * platform (`FileSystem`, `Path`) to find Playwright's ffmpeg.
6
+ */
7
+ export declare const BrowserPlaywright: Layer.Layer<Browser, never, FileSystem.FileSystem | Path.Path>;
5
8
  /**
6
9
  * Downloads the Chromium build that matches the bundled Playwright. Pinned to our version so the
7
10
  * browser revision is the one we look for.
@@ -14,6 +17,8 @@ export interface FfmpegLookup {
14
17
  readonly found: boolean;
15
18
  readonly path: string | undefined;
16
19
  }
20
+ /** What is wrong when Playwright's ffmpeg is not found, as a clause: no full stop. */
21
+ export declare const ffmpegProblem: (lookup: FfmpegLookup) => string;
17
22
  /**
18
23
  * Finds the ffmpeg Playwright records videos with, where Playwright itself looks (its registry
19
24
  * follows PLAYWRIGHT_BROWSERS_PATH and the platform's cache folder). Never downloads anything.
@@ -39,16 +39,35 @@ const launchAny = (headed) => Effect.gen(function* () {
39
39
  });
40
40
  });
41
41
  const open = (options) => launchAny(options.headed).pipe(Effect.map(({ candidate, browser }) => ({
42
- info: { kind: candidate.kind, version: browser.version() },
42
+ info: {
43
+ kind: candidate.kind,
44
+ type: browser.browserType().name(),
45
+ channel: candidate.channel,
46
+ version: browser.version(),
47
+ },
43
48
  newSession: (session) => newSession(browser, session.device, session.video),
44
49
  })));
45
- /** Launches the installed Chrome, else Edge, else Playwright's downloaded Chromium. */
46
- export const BrowserPlaywright = Layer.succeed(Browser, {
47
- detect: Effect.scoped(open({ headed: false })).pipe(Effect.map((session) => session.info)),
48
- open,
49
- deviceLabel,
50
- annotate: (jobs) => Effect.scoped(launchAny(false).pipe(Effect.flatMap(({ browser }) => annotateAll(browser, jobs)))),
51
- });
50
+ /**
51
+ * Launches the installed Chrome, else Edge, else Playwright's downloaded Chromium. Needs the
52
+ * platform (`FileSystem`, `Path`) to find Playwright's ffmpeg.
53
+ */
54
+ export const BrowserPlaywright = Layer.effect(Browser, Effect.gen(function* () {
55
+ const fs = yield* FileSystem.FileSystem;
56
+ const path = yield* Path.Path;
57
+ const videoSupport = Effect.gen(function* () {
58
+ const lookup = yield* findFfmpeg;
59
+ if (lookup.found)
60
+ return { ok: true };
61
+ return { ok: false, problem: ffmpegProblem(lookup), command: yield* installFfmpegCommand };
62
+ }).pipe(Effect.provideService(FileSystem.FileSystem, fs), Effect.provideService(Path.Path, path));
63
+ return {
64
+ detect: Effect.scoped(open({ headed: false })).pipe(Effect.map((session) => session.info)),
65
+ videoSupport,
66
+ open,
67
+ deviceLabel,
68
+ annotate: (jobs) => Effect.scoped(launchAny(false).pipe(Effect.flatMap(({ browser }) => annotateAll(browser, jobs)))),
69
+ };
70
+ }));
52
71
  const PlaywrightPackage = Schema.Struct({ version: Schema.String });
53
72
  /** The bundled Playwright's version, for install commands pinned to it. */
54
73
  const playwrightVersion = Effect.gen(function* () {
@@ -67,6 +86,10 @@ const playwrightVersion = Effect.gen(function* () {
67
86
  export const installBrowserCommand = playwrightVersion.pipe(Effect.map((version) => `npx -y playwright-core@${version} install chromium`));
68
87
  /** Downloads the ffmpeg build that the bundled Playwright records videos with. */
69
88
  export const installFfmpegCommand = playwrightVersion.pipe(Effect.map((version) => `npx -y playwright-core@${version} install ffmpeg`));
89
+ /** What is wrong when Playwright's ffmpeg is not found, as a clause: no full stop. */
90
+ export const ffmpegProblem = (lookup) => lookup.path === undefined
91
+ ? "Playwright's ffmpeg could not be looked up"
92
+ : `Playwright's ffmpeg is missing (looked for ${lookup.path})`;
70
93
  /**
71
94
  * Finds the ffmpeg Playwright records videos with, where Playwright itself looks (its registry
72
95
  * follows PLAYWRIGHT_BROWSERS_PATH and the platform's cache folder). Never downloads anything.
@@ -25,10 +25,15 @@ export declare const NAVIGATION_START_MS = 250;
25
25
  export declare const MOBILE_DEVICE = "iPhone 17";
26
26
  /** The device as reports show it; the engine is named because mobile is not real Safari. */
27
27
  export declare const deviceLabel: (device: Device) => string;
28
- /** Session videos fit in this box, keeping the viewport's shape, so files stay small. */
28
+ /**
29
+ * Session videos fit in this box, keeping the viewport's shape. It is larger than every viewport
30
+ * we set (desktop 1280x800), so videos are recorded 1:1: scaling frames down (as a 1280x720 box
31
+ * once did, to 1152x720) resamples every glyph and blurs text. Chromium's screencast sends frames
32
+ * in CSS pixels, so a box larger than the viewport would only pad the frame, not sharpen it.
33
+ */
29
34
  export declare const VIDEO_MAX: {
30
- readonly width: 1280;
31
- readonly height: 720;
35
+ readonly width: 1920;
36
+ readonly height: 1080;
32
37
  };
33
38
  /** The size of a session's video for a viewport: the viewport, scaled down into `VIDEO_MAX`. */
34
39
  export declare const videoSize: (viewport: {
@@ -44,6 +49,8 @@ export declare const CLOSE_TIMEOUT_MS = 30000;
44
49
  export declare const MEASURE_TIMEOUT_MS = 1000;
45
50
  /** How long setting up the input observer (`watchInput`) or taking it down may take. */
46
51
  export declare const INPUT_SETUP_TIMEOUT_MS = 2000;
52
+ /** How long stopping a load judged unfinished may take (see `watchContext`'s `settle`). */
53
+ export declare const STOP_LOADING_TIMEOUT_MS = 2000;
47
54
  /** How long saving what a screenshot needs besides the image may take. */
48
55
  export declare const CAPTURE_TIMEOUT_MS = 3000;
49
56
  /**
@@ -365,8 +372,8 @@ export declare const ELSEWHERE_TIMEOUT_MS = 1000;
365
372
  * is saved then too, so a run that is stopped keeps it.
366
373
  *
367
374
  * Playwright records each tab's video separately, so only the session's own tab is kept: the
368
- * videos of tabs the cases opened are deleted. Recording needs Playwright's ffmpeg; without it,
369
- * the session runs without a video and says why.
375
+ * videos of tabs the cases opened are deleted. Recording needs Playwright's ffmpeg: a session
376
+ * with `video` that cannot be recorded fails rather than run without one.
370
377
  */
371
378
  export declare const newSession: (browser: PlaywrightBrowser, device: Device, video: {
372
379
  readonly dir: string;
@@ -30,8 +30,13 @@ export const MOBILE_DEVICE = 'iPhone 17';
30
30
  /** The device as reports show it; the engine is named because mobile is not real Safari. */
31
31
  export const deviceLabel = (device) => device === 'mobile' ? `${MOBILE_DEVICE} (Chromium)` : 'Desktop';
32
32
  const contextOptions = (device) => device === 'mobile' ? devices[MOBILE_DEVICE] : { viewport: { width: 1280, height: 800 } };
33
- /** Session videos fit in this box, keeping the viewport's shape, so files stay small. */
34
- export const VIDEO_MAX = { width: 1280, height: 720 };
33
+ /**
34
+ * Session videos fit in this box, keeping the viewport's shape. It is larger than every viewport
35
+ * we set (desktop 1280x800), so videos are recorded 1:1: scaling frames down (as a 1280x720 box
36
+ * once did, to 1152x720) resamples every glyph and blurs text. Chromium's screencast sends frames
37
+ * in CSS pixels, so a box larger than the viewport would only pad the frame, not sharpen it.
38
+ */
39
+ export const VIDEO_MAX = { width: 1920, height: 1080 };
35
40
  /** The size of a session's video for a viewport: the viewport, scaled down into `VIDEO_MAX`. */
36
41
  export const videoSize = (viewport) => {
37
42
  const scale = Math.min(1, VIDEO_MAX.width / viewport.width, VIDEO_MAX.height / viewport.height);
@@ -44,6 +49,8 @@ export const CLOSE_TIMEOUT_MS = 30_000;
44
49
  export const MEASURE_TIMEOUT_MS = 1_000;
45
50
  /** How long setting up the input observer (`watchInput`) or taking it down may take. */
46
51
  export const INPUT_SETUP_TIMEOUT_MS = 2_000;
52
+ /** How long stopping a load judged unfinished may take (see `watchContext`'s `settle`). */
53
+ export const STOP_LOADING_TIMEOUT_MS = 2_000;
47
54
  /** How long saving what a screenshot needs besides the image may take. */
48
55
  export const CAPTURE_TIMEOUT_MS = 3_000;
49
56
  /**
@@ -131,7 +138,10 @@ const refusedIn = (url, child) => url === '' || url === LOAD_ERROR_URL || (child
131
138
  * a load. `settle` waits for loads and judges them:
132
139
  * - A load is in flight from its request until its final response or its failure. It is waited
133
140
  * for up to its step's load timeout from its start (`NAVIGATION_TIMEOUT_MS` unless the step gives
134
- * `timeoutMs`); one still in flight then did not finish.
141
+ * `timeoutMs`); one still in flight then did not finish. Once judged, it is stopped (CDP
142
+ * `Page.stopLoading` in its page, best effort): while a navigation hangs, every read of the
143
+ * page (scripts, screenshots) waits on it too, so the case's evidence would time out one read
144
+ * after another. Stopped, the page shows the document it had before.
135
145
  * - A final response of 400 or above is an HTTP error; any other response is fine. A failure
136
146
  * reported after the response is ignored: the response already decided. That is how Chromium
137
147
  * ends a download (a response with `content-disposition: attachment`, then `ERR_ABORTED`), so a
@@ -167,6 +177,15 @@ const watchContext = (context, page, clock) => {
167
177
  first = from;
168
178
  return first;
169
179
  };
180
+ /** The page a document request loads in, if its frame is known yet. */
181
+ const pageOf = (request) => {
182
+ try {
183
+ return request.frame().page();
184
+ }
185
+ catch {
186
+ return undefined;
187
+ }
188
+ };
170
189
  /** Whether a request loads a document of the case's page, of another page, or neither. */
171
190
  const kindOf = (request) => {
172
191
  if (!request.isNavigationRequest())
@@ -201,6 +220,7 @@ const watchContext = (context, page, clock) => {
201
220
  loads.set(first, {
202
221
  step,
203
222
  inNewTab: kind === 'popup',
223
+ page: kind === 'page' ? page : pageOf(first),
204
224
  startedAt: clock.currentTimeMillisUnsafe(),
205
225
  timeoutMs: stepTimeoutMs,
206
226
  outcome: undefined,
@@ -272,6 +292,20 @@ const watchContext = (context, page, clock) => {
272
292
  ? { ...base, _tag: 'HttpError', status: outcome.status }
273
293
  : undefined;
274
294
  };
295
+ /**
296
+ * Stops the loads still in flight whose page is known, in that page. Best effort, each bounded:
297
+ * without CDP (not Chromium), or when it fails, the load goes on as before. (A new tab stuck on
298
+ * its first document has no page yet, and no read of the case waits on it.) Boundary: CDP
299
+ * sessions are Playwright promises.
300
+ */
301
+ const stopLoading = (unfinished) => Effect.forEach(new Set(unfinished.flatMap((load) => (load.page?.isClosed() === false ? [load.page] : []))), (target) => within(STOP_LOADING_TIMEOUT_MS,
302
+ // All of it interruptible, so the bound holds; a session cut short goes with the
303
+ // context.
304
+ Effect.gen(function* () {
305
+ const session = yield* attempt(() => context.newCDPSession(target), firstLine);
306
+ yield* attempt(() => session.send('Page.stopLoading'), firstLine).pipe(Effect.ignore);
307
+ yield* attempt(() => session.detach(), firstLine);
308
+ })), { concurrency: 'unbounded', discard: true });
275
309
  return {
276
310
  settle: (next, loadTimeoutMs) => Effect.gen(function* () {
277
311
  for (let wait = nextDeadline(); wait !== undefined; wait = nextDeadline())
@@ -287,6 +321,9 @@ const watchContext = (context, page, clock) => {
287
321
  if (problem !== undefined && (first === undefined || problem.step < first.step))
288
322
  first = problem;
289
323
  }
324
+ // Only after the verdict, so it changes nothing judged. A stopped load ends as aborted,
325
+ // and it is no longer among the loads watched.
326
+ yield* stopLoading(judged.filter((load) => load.outcome === undefined));
290
327
  return first;
291
328
  }),
292
329
  refused: Effect.sync(() => refused),
@@ -1836,8 +1873,8 @@ drawn) => {
1836
1873
  * is saved then too, so a run that is stopped keeps it.
1837
1874
  *
1838
1875
  * Playwright records each tab's video separately, so only the session's own tab is kept: the
1839
- * videos of tabs the cases opened are deleted. Recording needs Playwright's ffmpeg; without it,
1840
- * the session runs without a video and says why.
1876
+ * videos of tabs the cases opened are deleted. Recording needs Playwright's ffmpeg: a session
1877
+ * with `video` that cannot be recorded fails rather than run without one.
1841
1878
  */
1842
1879
  export const newSession = (browser, device, video,
1843
1880
  /** Whether to watch the input the page gets, for recording actions; for tests to compare. */
@@ -1855,13 +1892,12 @@ observed = true) => Effect.gen(function* () {
1855
1892
  // Only reached when opening it went wrong, or once the session closed it already
1856
1893
  // (`closeAll`): a failure to close it again cannot change what the session found.
1857
1894
  (context) => attempt(() => context.close(), firstLine).pipe(Effect.ignore)).pipe(Effect.flatMap((context) => attempt(() => context.newPage(), failed).pipe(Effect.map((page) => ({ context, page })))));
1858
- let videoProblem;
1895
+ // Video is not optional: a session that cannot be recorded does not run.
1859
1896
  const { context, page } = yield* video === undefined
1860
1897
  ? open(false)
1861
- : open(true).pipe(Effect.catchTag('PageActionFailed', (error) => {
1862
- videoProblem = `Video could not be recorded: ${error.message}`;
1863
- return open(false);
1864
- }));
1898
+ : open(true).pipe(Effect.mapError((error) => new PageActionFailed({
1899
+ message: `The session could not be recorded as video (run \`npx screw-bugs doctor\` to see what is missing): ${error.message}`,
1900
+ })));
1865
1901
  const videoStartedAt = clock.currentTimeMillisUnsafe();
1866
1902
  // Boundary: Playwright reports crashes and closes through event callbacks.
1867
1903
  let closing = false;
@@ -1885,8 +1921,10 @@ observed = true) => Effect.gen(function* () {
1885
1921
  closing = true;
1886
1922
  await context.close().catch(() => undefined);
1887
1923
  const recorded = page.video();
1888
- if (video === undefined || recorded === null)
1889
- return videoProblem;
1924
+ if (video === undefined)
1925
+ return undefined;
1926
+ if (recorded === null)
1927
+ return 'The session was not recorded.';
1890
1928
  try {
1891
1929
  await recorded.saveAs(video.path);
1892
1930
  await recorded.delete();
@@ -1900,10 +1938,10 @@ observed = true) => Effect.gen(function* () {
1900
1938
  .video()
1901
1939
  ?.delete()
1902
1940
  .catch(() => undefined);
1903
- return videoProblem;
1941
+ return undefined;
1904
1942
  })());
1905
1943
  // Closing never fails the session: what went wrong is said about the video, which it is for.
1906
- const close = attempt(closeAll, (error) => `The video could not be saved: ${firstLine(error)}`).pipe(Effect.catchTag('PageActionFailed', (error) => Effect.succeed(video === undefined ? videoProblem : error.message)), Effect.timeoutOption(CLOSE_TIMEOUT_MS), Effect.map((problem) => ({
1944
+ const close = attempt(closeAll, (error) => `The video could not be saved: ${firstLine(error)}`).pipe(Effect.catchTag('PageActionFailed', (error) => Effect.succeed(video === undefined ? undefined : error.message)), Effect.timeoutOption(CLOSE_TIMEOUT_MS), Effect.map((problem) => ({
1907
1945
  videoProblem: problem._tag === 'Some'
1908
1946
  ? problem.value
1909
1947
  : `The video was not saved within ${seconds(CLOSE_TIMEOUT_MS)}.`,
@@ -1,5 +1,5 @@
1
1
  {
2
- "id": "2026-11-04T22:43:25.274Z-3f71a942",
3
- "builtAt": "2026-11-04T22:43:25.274Z",
4
- "commit": "3723289d34ae685c4dff51eb580fa9e5b5453383"
2
+ "id": "2026-11-10T09:49:11.224Z-5187d416",
3
+ "builtAt": "2026-11-10T09:49:11.224Z",
4
+ "commit": "223827146c3480da0d237064f321a0d35f4be1ea"
5
5
  }
package/dist/cli/app.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { NodeHttpClient } from '@effect/platform-node';
2
- import { Duration, Effect, Layer, Option } from 'effect';
2
+ import { Console, Duration, Effect, Layer, Option } from 'effect';
3
3
  import { CliError, Command } from 'effect/cli';
4
4
  import { BrowserPlaywright } from '../browser-playwright/index.js';
5
5
  import { AppVersion, Engine, Notifier, ProcessId } from '../core/index.js';
@@ -9,7 +9,7 @@ import { root } from './commands.js';
9
9
  import { ExitCode } from './exit-codes.js';
10
10
  import { Operations } from './operations.js';
11
11
  import { PackageInfo } from './package-info.js';
12
- import { RunningBuild } from './build-info.js';
12
+ import { RunningBuild, short } from './build-info.js';
13
13
  import { ReportServer } from './report-server.js';
14
14
  import { CLI_WAIT, UpdateCheck } from './update-check.js';
15
15
  /** Progress goes nowhere yet; the terminal and MCP notifiers come with real runs. */
@@ -56,13 +56,41 @@ const startUpdateCheck = (args) => Effect.serviceOption(UpdateCheck).pipe(Effect
56
56
  });
57
57
  }),
58
58
  })));
59
+ const VERSION_FLAGS = new Set(['--version', '-v']);
60
+ /**
61
+ * What `--version` shows after the name: the version, then the commit of the build when it is
62
+ * known (`0.1.1-next.57.gfa82ee8 (commit fa82ee8)`), so the first word after the name stays the
63
+ * plain version. With `--json` (and nothing else), the same as one JSON object instead.
64
+ */
65
+ const versionOutput = Effect.gen(function* () {
66
+ const { name, version } = yield* PackageInfo;
67
+ const running = yield* Effect.serviceOption(RunningBuild);
68
+ const build = Option.getOrUndefined(running)?.build;
69
+ const loaded = Option.match(running, { onNone: () => version, onSome: (r) => r.version });
70
+ return {
71
+ label: build?.commit ? `${loaded} (commit ${short(build.commit)})` : loaded,
72
+ json: {
73
+ name,
74
+ version: loaded,
75
+ ...(build?.commit ? { commit: build.commit } : {}),
76
+ ...(build ? { builtAt: build.builtAt } : {}),
77
+ },
78
+ };
79
+ });
59
80
  /**
60
81
  * Runs the CLI and resolves to the process exit code. A due update check started with it gets
61
82
  * the rest of its time after the command has written everything; it never changes the code.
62
83
  */
63
84
  export const runCli = (args) => Effect.gen(function* () {
64
85
  const waitForCheck = yield* startUpdateCheck(args);
65
- const code = yield* PackageInfo.use(({ version }) => Command.runWith(root, { version })(args)).pipe(Effect.as(ExitCode.Ok), Effect.catchTag('ExitWith', (exit) => Effect.succeed(exit.code)),
86
+ const version = yield* versionOutput;
87
+ // Effect CLI's own `--version` prints text only; `--version --json` gets the JSON here.
88
+ const versionJson = args.includes('--json') &&
89
+ args.some((arg) => VERSION_FLAGS.has(arg)) &&
90
+ args.every((arg) => arg === '--json' || VERSION_FLAGS.has(arg));
91
+ const code = yield* (versionJson
92
+ ? Console.log(JSON.stringify(version.json, null, 2))
93
+ : Command.runWith(root, { version: version.label })(args)).pipe(Effect.as(ExitCode.Ok), Effect.catchTag('ExitWith', (exit) => Effect.succeed(exit.code)),
66
94
  // Effect CLI has already printed the problem and the relevant help.
67
95
  Effect.catchIf(CliError.isCliError, () => Effect.succeed(ExitCode.Usage)));
68
96
  yield* waitForCheck;
@@ -42,6 +42,13 @@ export type BuildProblem =
42
42
  readonly built: string;
43
43
  readonly head: string;
44
44
  };
45
+ /** A commit's short form, as git shows it. */
46
+ export declare const short: (commit: string) => string;
47
+ /**
48
+ * What a build was made from, for people: `commit fa82ee8, built 2026-11-08T14:02Z` (no commit
49
+ * when it was not built in a git checkout). None without a stamp.
50
+ */
51
+ export declare const describeBuild: (build: BuildInfo | undefined) => string | undefined;
45
52
  /**
46
53
  * Whether the code running differs from what is installed (any install: a rebuilt `dist/` or a
47
54
  * new version in package.json), and, for a git checkout, whether `dist/` is behind it. Works
@@ -47,7 +47,23 @@ const installedNow = (root) => Effect.gen(function* () {
47
47
  const version = yield* fs.readFileString(path.join(root, 'package.json')).pipe(Effect.flatMap(Schema.decodeUnknownEffect(Schema.fromJsonString(PackageVersion))), Effect.map((json) => json.version), Effect.orElseSucceed(() => undefined));
48
48
  return { version, build: yield* readBuildInfo(root) };
49
49
  });
50
- const short = (commit) => commit.slice(0, 7);
50
+ /** A commit's short form, as git shows it. */
51
+ export const short = (commit) => commit.slice(0, 7);
52
+ /** `2026-11-08T14:02:33.123Z` as `2026-11-08T14:02Z`; anything else as it is. */
53
+ const toTheMinute = (iso) => {
54
+ const found = /^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2})(?::[\d.]+)?Z$/.exec(iso);
55
+ return found ? `${found[1]}Z` : iso;
56
+ };
57
+ /**
58
+ * What a build was made from, for people: `commit fa82ee8, built 2026-11-08T14:02Z` (no commit
59
+ * when it was not built in a git checkout). None without a stamp.
60
+ */
61
+ export const describeBuild = (build) => build === undefined
62
+ ? undefined
63
+ : [
64
+ ...(build.commit ? [`commit ${short(build.commit)}`] : []),
65
+ `built ${toTheMinute(build.builtAt)}`,
66
+ ].join(', ');
51
67
  /**
52
68
  * Whether the code running differs from what is installed (any install: a rebuilt `dist/` or a
53
69
  * new version in package.json), and, for a git checkout, whether `dist/` is behind it. Works