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,193 @@
1
+ import { Schema } from 'effect';
2
+ import { Box, PageFacts, Session, Shot, StepTiming } from './evidence.js';
3
+ import { Findings } from './findings.js';
4
+ import { Device, JobId, JobSpec, summaryOf } from './job.js';
5
+ import { CaseStatus, JobState } from './status.js';
6
+ /**
7
+ * `run_status` cuts each listed reason to this many characters. A reason with a hint about where
8
+ * else its text or element is (see `withHint` in core) is kept within it, so the hint shows.
9
+ */
10
+ export const REASON_MAX = 150;
11
+ /** One row of the case ledger. Evidence entries are paths relative to the run directory. */
12
+ export const CaseEntry = Schema.Struct({
13
+ id: Schema.NonEmptyString,
14
+ title: Schema.NonEmptyString,
15
+ status: CaseStatus,
16
+ /**
17
+ * For a case that continued (`CaseSpec.continue`): the ID of the case before it, on whose page
18
+ * it started rather than at the job URL.
19
+ */
20
+ continuedFrom: Schema.optionalKey(Schema.String),
21
+ /** Why the case did not pass, in plain language. Never DOM or browser logs. */
22
+ reason: Schema.optionalKey(Schema.String),
23
+ /**
24
+ * 1-based index of the step that decided a failed or blocked status; 0 is the opening
25
+ * navigation to the job URL that a case gets when its first step is not goto.
26
+ */
27
+ step: Schema.optionalKey(Schema.Int),
28
+ /**
29
+ * Paths such as `evidence/01/02-after-login.png`: case and screenshot numbers, so they never
30
+ * collide on any file system. Runs from older versions have `evidence/<case>/<name>.png` or
31
+ * `evidence/<case>-<name>.png`.
32
+ */
33
+ evidence: Schema.Array(Schema.String),
34
+ /**
35
+ * The name each evidence path was saved under, as the job gave it (`after-login`), or
36
+ * `step3-failed` for the screenshot taken when the case stopped. Missing in older runs.
37
+ */
38
+ evidenceNames: Schema.optionalKey(Schema.Record(Schema.String, Schema.String)),
39
+ /** The session it ran in (`Session.number`). Missing in older runs, as are the fields below. */
40
+ session: Schema.optionalKey(Schema.Int),
41
+ /** When the case started and ended, in ms from the start of its session's video. */
42
+ startMs: Schema.optionalKey(Schema.Number),
43
+ endMs: Schema.optionalKey(Schema.Number),
44
+ /** When each step that ran started and ended. */
45
+ steps: Schema.optionalKey(Schema.Array(StepTiming)),
46
+ /** Every screenshot of `evidence`, with what it shows. */
47
+ shots: Schema.optionalKey(Schema.Array(Shot)),
48
+ /** Short facts about the page when the case ended. */
49
+ facts: Schema.optionalKey(PageFacts),
50
+ });
51
+ /** The running record of every case in a job; the source of truth for status and reports. */
52
+ export const CaseLedger = Schema.Struct({
53
+ jobId: JobId,
54
+ state: JobState,
55
+ cases: Schema.Array(CaseEntry),
56
+ startedAt: Schema.optionalKey(Schema.String),
57
+ finishedAt: Schema.optionalKey(Schema.String),
58
+ /** Why the job stopped early, when `state` is `errored`. */
59
+ error: Schema.optionalKey(Schema.String),
60
+ /**
61
+ * When the process running the job last rewrote the ledger. Refreshed every few seconds while
62
+ * the job is queued or running; a stale one means that process is gone.
63
+ */
64
+ heartbeatAt: Schema.optionalKey(Schema.String),
65
+ /** ID of the operating-system process running the job, when known. */
66
+ pid: Schema.optionalKey(Schema.Int),
67
+ /** The device the browser emulated, as people read it, such as `iPhone 17 (Chromium)`. */
68
+ deviceLabel: Schema.optionalKey(Schema.String),
69
+ /** The browser sessions of the run, each with its video. Missing in older runs. */
70
+ sessions: Schema.optionalKey(Schema.Array(Session)),
71
+ /** The screw-bugs version that ran the job. */
72
+ version: Schema.optionalKey(Schema.String),
73
+ });
74
+ /**
75
+ * A highlight of the agent's findings as the report draws it: its box on the screenshot, or in
76
+ * words why it has none (the element was not found, or more than one matched). Never a guess.
77
+ */
78
+ export const PlacedMark = Schema.Struct({
79
+ mark: Schema.Literals(['red', 'green']),
80
+ /** The element as the agent named it, such as `button "Sign in"`. */
81
+ target: Schema.String,
82
+ note: Schema.optionalKey(Schema.String),
83
+ box: Schema.optionalKey(Box),
84
+ /** Where the element's text and images are inside `box` (`Candidate.content`), when known. */
85
+ content: Schema.optionalKey(Box),
86
+ problem: Schema.optionalKey(Schema.String),
87
+ /**
88
+ * Other matches that were left out because they were not on the screenshot, in words, such as
89
+ * `1 more match outside this screenshot was ignored`.
90
+ */
91
+ ignored: Schema.optionalKey(Schema.String),
92
+ });
93
+ /**
94
+ * Everything a finished run leaves on disk. `files` paths are relative to the bundle directory,
95
+ * so a bundle can be zipped, moved or uploaded as is.
96
+ */
97
+ export const ReportBundle = Schema.Struct({
98
+ formatVersion: Schema.Literal(1),
99
+ jobId: JobId,
100
+ spec: JobSpec,
101
+ ledger: CaseLedger,
102
+ startedAt: Schema.String,
103
+ finishedAt: Schema.optionalKey(Schema.String),
104
+ /**
105
+ * What the run tests, from `summaryOf(spec)`: the caller's summary, or one derived from the case
106
+ * titles when `derived` is true. The caller's own text, if any, is also in `spec.summary`.
107
+ */
108
+ summary: Schema.Struct({ text: Schema.String, derived: Schema.Boolean }),
109
+ /**
110
+ * The device the run used: `spec.device` (desktop by default) and its label from the ledger,
111
+ * or a generic one for runs recorded before ledgers kept it.
112
+ */
113
+ device: Schema.Struct({ kind: Device, label: Schema.String }),
114
+ files: Schema.Struct({
115
+ ledger: Schema.String,
116
+ html: Schema.optionalKey(Schema.String),
117
+ /** The walkthrough (`runFiles.walkthrough`), when one was written with this report. */
118
+ walkthrough: Schema.optionalKey(Schema.String),
119
+ evidenceDir: Schema.String,
120
+ }),
121
+ /** The agent's write-up, once it submitted one. */
122
+ findings: Schema.optionalKey(Findings),
123
+ /** The agent's highlights, placed on their screenshots by code, by screenshot ID. */
124
+ marks: Schema.optionalKey(Schema.Record(Schema.String, Schema.Array(PlacedMark))),
125
+ /** Copies of screenshots with the highlights drawn in, by screenshot ID; relative paths. */
126
+ annotated: Schema.optionalKey(Schema.Record(Schema.String, Schema.String)),
127
+ /**
128
+ * The boxes of the page's elements on screenshots that get boxes drawn on them, by screenshot
129
+ * ID, from their saved page state: labels keep off them where they can.
130
+ */
131
+ elements: Schema.optionalKey(Schema.Record(Schema.String, Schema.Array(Box))),
132
+ });
133
+ /** Where things are inside a run folder, relative to it. */
134
+ export const runFiles = {
135
+ job: 'job.json',
136
+ ledger: 'ledger.json',
137
+ /** The run's own report; only the run, or `screw-bugs report` once it has ended, writes it. */
138
+ html: 'report.html',
139
+ /** The report of a run whose process is gone, written by whoever reads its status. */
140
+ interruptedHtml: 'report-interrupted.html',
141
+ /**
142
+ * The run's walkthrough: its video with every step as a clickable script. Written with
143
+ * `report.html`, by whoever writes that, never by itself or with `report-interrupted.html`.
144
+ */
145
+ walkthrough: 'walkthrough.html',
146
+ evidenceDir: 'evidence',
147
+ /** The evidence pack of an ended run, written by the run. */
148
+ evidence: 'evidence.json',
149
+ /** The agent's write-up, written by `submit_findings` and `screw-bugs findings`. */
150
+ findings: 'findings.json',
151
+ /** One video per session, `video/session-<n>.webm`. */
152
+ videoDir: 'video',
153
+ /**
154
+ * Screenshots with the agent's highlights drawn in, `annotated/<shot ID>-<revision>.png`, where
155
+ * the revision is that of the `findings.json` they were drawn for. Copies for older findings
156
+ * may be left there; nothing shows them.
157
+ */
158
+ annotatedDir: 'annotated',
159
+ };
160
+ /** Where the video of session `number` goes, relative to the run folder. */
161
+ export const videoFile = (number) => `${runFiles.videoDir}/session-${number}.webm`;
162
+ /**
163
+ * Where the annotated copy of a screenshot goes, relative to the run folder, for the findings of
164
+ * `revision` (see `findingsRevision`).
165
+ */
166
+ export const annotatedFile = (shotId, revision) => `${runFiles.annotatedDir}/${shotId}-${revision}.png`;
167
+ /**
168
+ * A short fingerprint of the text of a `findings.json` (FNV-1a, 64 bits, in hex), so annotated
169
+ * copies drawn for other findings are never taken for this one's. Not a security measure.
170
+ */
171
+ export const findingsRevision = (text) => {
172
+ let hash = 0xcbf29ce484222325n;
173
+ for (const byte of new TextEncoder().encode(text))
174
+ hash = BigInt.asUintN(64, (hash ^ BigInt(byte)) * 0x100000001b3n);
175
+ return hash.toString(16).padStart(16, '0');
176
+ };
177
+ const deviceOf = (spec, ledger) => {
178
+ const kind = spec.device ?? 'desktop';
179
+ return { kind, label: ledger.deviceLabel ?? (kind === 'mobile' ? 'Mobile' : 'Desktop') };
180
+ };
181
+ /** The report bundle of a run, from its job record and (current or final) ledger. */
182
+ export const reportBundleOf = (job, ledger, writeUp = {}) => ({
183
+ ...writeUp,
184
+ formatVersion: 1,
185
+ jobId: job.jobId,
186
+ spec: job.spec,
187
+ ledger,
188
+ startedAt: ledger.startedAt ?? job.createdAt,
189
+ ...(ledger.finishedAt !== undefined ? { finishedAt: ledger.finishedAt } : {}),
190
+ summary: summaryOf(job.spec),
191
+ device: deviceOf(job.spec, ledger),
192
+ files: { ledger: runFiles.ledger, html: runFiles.html, evidenceDir: runFiles.evidenceDir },
193
+ });
@@ -0,0 +1,7 @@
1
+ import { Schema } from 'effect';
2
+ /** Outcome of one test case. `not_verified` means the run ended before the case could be judged. */
3
+ export declare const CaseStatus: Schema.Literals<readonly ["passed", "failed", "blocked", "not_verified"]>;
4
+ export type CaseStatus = typeof CaseStatus.Type;
5
+ /** Lifecycle of a job, as reported by `run_status` and `screw-bugs status`. */
6
+ export declare const JobState: Schema.Literals<readonly ["queued", "running", "waiting_for_answer", "finished", "errored"]>;
7
+ export type JobState = typeof JobState.Type;
@@ -0,0 +1,11 @@
1
+ import { Schema } from 'effect';
2
+ /** Outcome of one test case. `not_verified` means the run ended before the case could be judged. */
3
+ export const CaseStatus = Schema.Literals(['passed', 'failed', 'blocked', 'not_verified']);
4
+ /** Lifecycle of a job, as reported by `run_status` and `screw-bugs status`. */
5
+ export const JobState = Schema.Literals([
6
+ 'queued',
7
+ 'running',
8
+ 'waiting_for_answer',
9
+ 'finished',
10
+ 'errored',
11
+ ]);
@@ -0,0 +1,7 @@
1
+ import { Layer } from 'effect';
2
+ import { AccountBook } from '../core/index.js';
3
+ /**
4
+ * Account book in SQLite at `.screw-bugs/accounts.sqlite`, using the built-in `node:sqlite` so
5
+ * installs need no native build step.
6
+ */
7
+ export declare const AccountBookLocal: (_projectRoot: string) => Layer.Layer<AccountBook, never, never>;
@@ -0,0 +1,9 @@
1
+ import { Effect, Layer } from 'effect';
2
+ import { AccountBook, NotImplemented } from '../core/index.js';
3
+ /**
4
+ * Account book in SQLite at `.screw-bugs/accounts.sqlite`, using the built-in `node:sqlite` so
5
+ * installs need no native build step.
6
+ */
7
+ export const AccountBookLocal = (_projectRoot) => Layer.succeed(AccountBook, {
8
+ list: Effect.fail(new NotImplemented({ feature: 'The account book' })),
9
+ });
@@ -0,0 +1,3 @@
1
+ export * from './accounts.js';
2
+ export * from './paths.js';
3
+ export * from './storage.js';
@@ -0,0 +1,3 @@
1
+ export * from './accounts.js';
2
+ export * from './paths.js';
3
+ export * from './storage.js';
@@ -0,0 +1,10 @@
1
+ import { Effect, FileSystem, Path } from 'effect';
2
+ /**
3
+ * Per-project data lives in `<project>/.screw-bugs/`. The directory ignores itself (a `.gitignore`
4
+ * containing `*`), so runs, evidence and the account book never get committed, with no edits to
5
+ * the project's own `.gitignore`.
6
+ */
7
+ export declare const dataDir: (projectRoot: string) => Effect.Effect<string, never, Path.Path>;
8
+ export declare const runsDir: (projectRoot: string) => Effect.Effect<string, never, Path.Path>;
9
+ export declare const accountBookPath: (projectRoot: string) => Effect.Effect<string, never, Path.Path>;
10
+ export declare const ensureDataDir: (projectRoot: string) => Effect.Effect<string, import("effect/PlatformError").PlatformError, FileSystem.FileSystem | Path.Path>;
@@ -0,0 +1,17 @@
1
+ import { Effect, FileSystem, Path } from 'effect';
2
+ /**
3
+ * Per-project data lives in `<project>/.screw-bugs/`. The directory ignores itself (a `.gitignore`
4
+ * containing `*`), so runs, evidence and the account book never get committed, with no edits to
5
+ * the project's own `.gitignore`.
6
+ */
7
+ export const dataDir = (projectRoot) => Path.Path.useSync((path) => path.join(projectRoot, '.screw-bugs'));
8
+ export const runsDir = (projectRoot) => Path.Path.useSync((path) => path.join(projectRoot, '.screw-bugs', 'runs'));
9
+ export const accountBookPath = (projectRoot) => Path.Path.useSync((path) => path.join(projectRoot, '.screw-bugs', 'accounts.sqlite'));
10
+ export const ensureDataDir = (projectRoot) => Effect.gen(function* () {
11
+ const fs = yield* FileSystem.FileSystem;
12
+ const path = yield* Path.Path;
13
+ const dir = yield* dataDir(projectRoot);
14
+ yield* fs.makeDirectory(dir, { recursive: true });
15
+ yield* fs.writeFileString(path.join(dir, '.gitignore'), '*\n');
16
+ return dir;
17
+ });
@@ -0,0 +1,20 @@
1
+ import { DateTime, Effect, FileSystem, Layer, Path } from 'effect';
2
+ import { Storage } from '../core/index.js';
3
+ import { JobId } from '../schema/index.js';
4
+ export declare const JOB_FILE: "job.json";
5
+ export declare const LEDGER_FILE: "ledger.json";
6
+ export declare const REPORT_FILE: "report.html";
7
+ export declare const INTERRUPTED_REPORT_FILE: "report-interrupted.html";
8
+ export declare const EVIDENCE_DIR: "evidence";
9
+ /**
10
+ * `YYYYMMDD-HHMMSS-xxxxxxxx` in UTC: sorts by creation time as plain text, and is a valid folder
11
+ * name on every OS. The random suffix tells apart jobs created in the same second.
12
+ */
13
+ export declare const formatJobId: (at: DateTime.DateTime, suffix: string) => JobId;
14
+ /** A fresh job ID for the current time. */
15
+ export declare const newJobId: Effect.Effect<string & import("effect/Brand").Brand<"JobId">, never, never>;
16
+ /**
17
+ * Runs and evidence on disk: `.screw-bugs/runs/<jobId>/` holds `job.json`, `ledger.json` and
18
+ * `evidence/<NN>/` with the screenshots of the NNth case.
19
+ */
20
+ export declare const StorageLocal: (projectRoot: string) => Layer.Layer<Storage, never, FileSystem.FileSystem | Path.Path>;
@@ -0,0 +1,170 @@
1
+ import { DateTime, Effect, FileSystem, Layer, Path, PlatformError, Random, Schema } from 'effect';
2
+ import { RunNotFound, Storage, StorageFailed, withLiveness, } from '../core/index.js';
3
+ import { CaseLedger, JobId, JobRecord, runFiles } from '../schema/index.js';
4
+ import { ensureDataDir, runsDir } from './paths.js';
5
+ export const JOB_FILE = runFiles.job;
6
+ export const LEDGER_FILE = runFiles.ledger;
7
+ export const REPORT_FILE = runFiles.html;
8
+ export const INTERRUPTED_REPORT_FILE = runFiles.interruptedHtml;
9
+ export const EVIDENCE_DIR = runFiles.evidenceDir;
10
+ /** `n` random bytes as lowercase hex. */
11
+ const randomHex = (bytes) => Random.nextIntBetween(0, 2 ** (8 * bytes) - 1).pipe(Effect.map((n) => n.toString(16).padStart(2 * bytes, '0')));
12
+ /** Random bytes in a job ID: 8 hex digits, so two jobs in the same second rarely draw the same. */
13
+ const SUFFIX_BYTES = 4;
14
+ /** How many fresh IDs `createRun` tries when the folder of the one it drew already exists. */
15
+ const CREATE_ATTEMPTS = 5;
16
+ /**
17
+ * `YYYYMMDD-HHMMSS-xxxxxxxx` in UTC: sorts by creation time as plain text, and is a valid folder
18
+ * name on every OS. The random suffix tells apart jobs created in the same second.
19
+ */
20
+ export const formatJobId = (at, suffix) => JobId.make(`${DateTime.formatIso(at).slice(0, 19).replaceAll('-', '').replaceAll(':', '').replace('T', '-')}-${suffix}`);
21
+ /** A fresh job ID for the current time. */
22
+ export const newJobId = Effect.all([DateTime.now, randomHex(SUFFIX_BYTES)]).pipe(Effect.map(([now, suffix]) => formatJobId(now, suffix)));
23
+ const isMissing = (error) => error instanceof PlatformError.PlatformError && error.reason._tag === 'NotFound';
24
+ const isTaken = (error) => error instanceof PlatformError.PlatformError && error.reason._tag === 'AlreadyExists';
25
+ /**
26
+ * Runs and evidence on disk: `.screw-bugs/runs/<jobId>/` holds `job.json`, `ledger.json` and
27
+ * `evidence/<NN>/` with the screenshots of the NNth case.
28
+ */
29
+ export const StorageLocal = (projectRoot) => Layer.effect(Storage, Effect.gen(function* () {
30
+ const fs = yield* FileSystem.FileSystem;
31
+ const path = yield* Path.Path;
32
+ const runs = yield* runsDir(projectRoot);
33
+ const runDir = (jobId) => path.join(runs, jobId);
34
+ const ensureData = ensureDataDir(projectRoot).pipe(Effect.provideService(FileSystem.FileSystem, fs), Effect.provideService(Path.Path, path));
35
+ /**
36
+ * A path inside the run folder, for a relative path the engine gave (`evidence/01/02.json`):
37
+ * plain names joined by `/`, never absolute and never `..`.
38
+ */
39
+ const inRun = (jobId, relative) => {
40
+ const parts = relative.split('/');
41
+ if (!parts.every((part) => /^[A-Za-z0-9._-]+$/.test(part) && part !== '..' && part !== '.'))
42
+ throw new Error(`Not a path inside a run folder: ${relative}`);
43
+ return path.join(runDir(jobId), ...parts);
44
+ };
45
+ /** Writes to a temporary file first, so a reader in another process never sees half a file. */
46
+ const writeAtomic = (file, text) => Effect.gen(function* () {
47
+ const temporary = `${file}.${yield* randomHex(4)}.tmp`;
48
+ yield* fs.writeFileString(temporary, text);
49
+ yield* fs.rename(temporary, file);
50
+ }).pipe(Effect.mapError((cause) => new StorageFailed({ message: `Could not write ${file}.`, cause })));
51
+ const writeJson = (file, value) => writeAtomic(file, `${JSON.stringify(value, null, 2)}\n`);
52
+ const readJson = (file, schema) => fs.readFileString(file).pipe(Effect.flatMap((text) => Schema.decodeUnknownEffect(Schema.fromJsonString(schema))(text)), Effect.mapError((cause) => isMissing(cause)
53
+ ? 'missing'
54
+ : new StorageFailed({ message: `${file} is unreadable or not valid.`, cause })));
55
+ /**
56
+ * A ledger as it should be reported now. A job whose process died (killed, crashed) is
57
+ * reported errored once its heartbeat goes stale. The file itself is left alone: reads never
58
+ * write, so a slow but live process (or one woken from sleep) is never overwritten, and its
59
+ * next heartbeat makes it report as running again.
60
+ */
61
+ const readLedgerFile = (file) => Effect.all([readJson(file, CaseLedger), DateTime.now]).pipe(Effect.map(([ledger, now]) => withLiveness(ledger, DateTime.toEpochMillis(now))));
62
+ const orNotFound = (jobId) => (effect) => effect.pipe(Effect.catchIf((error) => error === 'missing', () => Effect.fail(new RunNotFound({ jobId }))));
63
+ return Storage.of({
64
+ createRun: (spec) => Effect.gen(function* () {
65
+ yield* ensureData.pipe(Effect.mapError((cause) => new StorageFailed({ message: `Could not create ${runs}.`, cause })));
66
+ const failed = (dir) => (cause) => new StorageFailed({ message: `Could not create ${dir}.`, cause });
67
+ yield* fs.makeDirectory(runs, { recursive: true }).pipe(Effect.mapError(failed(runs)));
68
+ /**
69
+ * Claims a fresh run folder. Creating it without `recursive` fails when it exists, and
70
+ * the OS does that atomically, so of two jobs that drew the same ID (in this process or
71
+ * another, such as the CLI and the MCP server) only one gets the folder; the other draws
72
+ * again rather than writing over the first one's run.
73
+ */
74
+ const claim = (attempt) => Effect.gen(function* () {
75
+ const now = yield* DateTime.now;
76
+ const jobId = formatJobId(now, yield* randomHex(SUFFIX_BYTES));
77
+ const dir = runDir(jobId);
78
+ return yield* fs.makeDirectory(dir).pipe(Effect.as([now, jobId]), Effect.catch((cause) => isTaken(cause) && attempt < CREATE_ATTEMPTS
79
+ ? claim(attempt + 1)
80
+ : Effect.fail(failed(dir)(cause))));
81
+ });
82
+ const [now, jobId] = yield* claim(1);
83
+ const dir = runDir(jobId);
84
+ yield* fs
85
+ .makeDirectory(path.join(dir, EVIDENCE_DIR))
86
+ .pipe(Effect.mapError(failed(dir)));
87
+ const record = { jobId, spec, createdAt: DateTime.formatIso(now) };
88
+ yield* writeJson(path.join(dir, JOB_FILE), record);
89
+ return jobId;
90
+ }),
91
+ readJob: (jobId) => readJson(path.join(runDir(jobId), JOB_FILE), JobRecord).pipe(orNotFound(jobId)),
92
+ readLedger: (jobId) => readLedgerFile(path.join(runDir(jobId), LEDGER_FILE)).pipe(orNotFound(jobId)),
93
+ writeLedger: (ledger) => writeJson(path.join(runDir(ledger.jobId), LEDGER_FILE), ledger),
94
+ listRuns: (limit) => Effect.gen(function* () {
95
+ const names = yield* fs
96
+ .readDirectory(runs)
97
+ .pipe(Effect.catch((cause) => isMissing(cause)
98
+ ? Effect.succeed([])
99
+ : Effect.fail(new StorageFailed({ message: `Could not list ${runs}.`, cause }))));
100
+ const ids = names
101
+ .filter((name) => Schema.is(JobId)(name))
102
+ .sort()
103
+ .reverse();
104
+ const found = [];
105
+ for (const id of ids) {
106
+ if (found.length >= limit)
107
+ break;
108
+ const dir = path.join(runs, id);
109
+ // A folder that is not a run (or a damaged one) is skipped rather than failing the list.
110
+ const job = yield* readJson(path.join(dir, JOB_FILE), JobRecord).pipe(Effect.orElseSucceed(() => undefined));
111
+ if (!job)
112
+ continue;
113
+ const ledger = yield* readLedgerFile(path.join(dir, LEDGER_FILE)).pipe(Effect.orElseSucceed(() => undefined));
114
+ found.push({ job, ledger });
115
+ }
116
+ return found;
117
+ }),
118
+ writeReport: (jobId, html) => Effect.gen(function* () {
119
+ const file = path.join(runDir(jobId), REPORT_FILE);
120
+ yield* writeAtomic(file, html);
121
+ // The run's own report replaces one written while it looked gone.
122
+ yield* fs
123
+ .remove(path.join(runDir(jobId), INTERRUPTED_REPORT_FILE), { force: true })
124
+ .pipe(Effect.ignore);
125
+ return file;
126
+ }),
127
+ writeInterruptedReport: (jobId, html) => Effect.gen(function* () {
128
+ const file = path.join(runDir(jobId), INTERRUPTED_REPORT_FILE);
129
+ yield* writeAtomic(file, html);
130
+ return file;
131
+ }),
132
+ findReport: (jobId) => Effect.gen(function* () {
133
+ for (const name of [REPORT_FILE, INTERRUPTED_REPORT_FILE]) {
134
+ const file = path.join(runDir(jobId), name);
135
+ if (yield* fs.exists(file).pipe(Effect.orElseSucceed(() => false)))
136
+ return file;
137
+ }
138
+ return undefined;
139
+ }),
140
+ runDir,
141
+ evidencePath: (jobId, fileName) => path.join(runDir(jobId), EVIDENCE_DIR, fileName),
142
+ filePath: inRun,
143
+ writeFile: (jobId, relative, text) => Effect.gen(function* () {
144
+ const file = inRun(jobId, relative);
145
+ yield* fs
146
+ .makeDirectory(path.dirname(file), { recursive: true })
147
+ .pipe(Effect.mapError((cause) => new StorageFailed({ message: `Could not write ${file}.`, cause })));
148
+ yield* writeAtomic(file, text);
149
+ }),
150
+ readFile: (jobId, relative) => Effect.suspend(() => {
151
+ const file = inRun(jobId, relative);
152
+ return fs
153
+ .readFileString(file)
154
+ .pipe(Effect.catch((cause) => isMissing(cause)
155
+ ? Effect.succeed(undefined)
156
+ : Effect.fail(new StorageFailed({ message: `Could not read ${file}.`, cause }))));
157
+ }),
158
+ probe: (jobId, relative, headBytes) => Effect.scoped(Effect.gen(function* () {
159
+ const file = yield* fs.open(inRun(jobId, relative), { flag: 'r' });
160
+ const size = Number((yield* file.stat).size);
161
+ const head = headBytes > 0 && size > 0
162
+ ? yield* file.readAlloc(Math.min(headBytes, size))
163
+ : undefined;
164
+ return {
165
+ size,
166
+ head: head?._tag === 'Some' ? head.value : new Uint8Array(),
167
+ };
168
+ })).pipe(Effect.orElseSucceed(() => undefined)),
169
+ });
170
+ }));
package/package.json CHANGED
@@ -1,6 +1,75 @@
1
1
  {
2
2
  "name": "screw-bugs",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Local browser QA for coding agents (MCP), people and CI.",
5
+ "keywords": [
6
+ "browser",
7
+ "coding-agent",
8
+ "e2e",
9
+ "mcp",
10
+ "playwright",
11
+ "qa",
12
+ "screenshots",
13
+ "testing",
14
+ "video"
15
+ ],
16
+ "homepage": "https://github.com/uxstudioteam/screw-bugs#readme",
17
+ "bugs": {
18
+ "url": "https://github.com/uxstudioteam/screw-bugs/issues"
19
+ },
20
+ "license": "MIT",
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/uxstudioteam/screw-bugs.git"
24
+ },
25
+ "bin": {
26
+ "screw-bugs": "bin/screw-bugs.js"
27
+ },
28
+ "files": [
29
+ "bin",
30
+ "dist"
31
+ ],
32
+ "type": "module",
33
+ "exports": {
34
+ ".": "./dist/core/index.js",
35
+ "./schema": "./dist/schema/index.js",
36
+ "./core": "./dist/core/index.js",
37
+ "./browser-playwright": "./dist/browser-playwright/index.js",
38
+ "./store-local": "./dist/store-local/index.js",
39
+ "./report": "./dist/report/index.js",
40
+ "./cli": "./dist/cli/index.js",
41
+ "./package.json": "./package.json"
42
+ },
43
+ "publishConfig": {
44
+ "access": "public"
45
+ },
46
+ "scripts": {
47
+ "build": "tsc -p tsconfig.build.json && node dist/cli/stamp-build.js",
48
+ "typecheck": "tsc -p tsconfig.json",
49
+ "lint": "oxlint --deny-warnings",
50
+ "format": "oxfmt",
51
+ "format:check": "oxfmt --check",
52
+ "test": "vitest run",
53
+ "check": "pnpm format:check && pnpm lint && pnpm typecheck && pnpm test",
54
+ "e2e": "tsc -p e2e && node e2e/run.ts",
55
+ "prepack": "node -e \"process.getBuiltinModule('fs').rmSync('dist',{recursive:true,force:true})\" && pnpm build"
56
+ },
57
+ "dependencies": {
58
+ "@effect/platform-node": "^4.1.0",
59
+ "@modelcontextprotocol/server": "2.4.0",
60
+ "effect": "^4.1.0",
61
+ "playwright-core": "1.64.1"
62
+ },
63
+ "devDependencies": {
64
+ "@effect/vitest": "4.1.0",
65
+ "@types/node": "22.20.5",
66
+ "oxfmt": "0.75.0",
67
+ "oxlint": "1.90.0",
68
+ "typescript": "7.0.2",
69
+ "vitest": "5.0.5"
70
+ },
71
+ "engines": {
72
+ "node": ">=22.13.0"
73
+ },
74
+ "packageManager": "pnpm@12.9.1"
75
+ }