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.
- package/LICENSE +21 -0
- package/README.md +906 -2
- package/bin/screw-bugs.js +29 -0
- package/dist/browser-playwright/annotate.d.ts +9 -0
- package/dist/browser-playwright/annotate.js +86 -0
- package/dist/browser-playwright/capture.d.ts +232 -0
- package/dist/browser-playwright/capture.js +1049 -0
- package/dist/browser-playwright/frames.d.ts +77 -0
- package/dist/browser-playwright/frames.js +191 -0
- package/dist/browser-playwright/index.d.ts +2 -0
- package/dist/browser-playwright/index.js +2 -0
- package/dist/browser-playwright/input.d.ts +44 -0
- package/dist/browser-playwright/input.js +116 -0
- package/dist/browser-playwright/launch.d.ts +21 -0
- package/dist/browser-playwright/launch.js +86 -0
- package/dist/browser-playwright/page.d.ts +387 -0
- package/dist/browser-playwright/page.js +1930 -0
- package/dist/build-info.json +5 -0
- package/dist/cli/app.d.ts +19 -0
- package/dist/cli/app.js +70 -0
- package/dist/cli/build-info.d.ts +52 -0
- package/dist/cli/build-info.js +82 -0
- package/dist/cli/commands.d.ts +14 -0
- package/dist/cli/commands.js +308 -0
- package/dist/cli/config.d.ts +16 -0
- package/dist/cli/config.js +71 -0
- package/dist/cli/doctor.d.ts +19 -0
- package/dist/cli/doctor.js +113 -0
- package/dist/cli/environment.d.ts +20 -0
- package/dist/cli/environment.js +34 -0
- package/dist/cli/exit-codes.d.ts +29 -0
- package/dist/cli/exit-codes.js +28 -0
- package/dist/cli/failure.d.ts +20 -0
- package/dist/cli/failure.js +15 -0
- package/dist/cli/index.d.ts +6 -0
- package/dist/cli/index.js +6 -0
- package/dist/cli/install-method.d.ts +96 -0
- package/dist/cli/install-method.js +148 -0
- package/dist/cli/main.d.ts +1 -0
- package/dist/cli/main.js +10 -0
- package/dist/cli/mcp.d.ts +30 -0
- package/dist/cli/mcp.js +309 -0
- package/dist/cli/node-version.d.ts +3 -0
- package/dist/cli/node-version.js +22 -0
- package/dist/cli/operations.d.ts +127 -0
- package/dist/cli/operations.js +337 -0
- package/dist/cli/package-info.d.ts +22 -0
- package/dist/cli/package-info.js +25 -0
- package/dist/cli/report-server.d.ts +170 -0
- package/dist/cli/report-server.js +387 -0
- package/dist/cli/signals.d.ts +37 -0
- package/dist/cli/signals.js +61 -0
- package/dist/cli/stamp-build.d.ts +1 -0
- package/dist/cli/stamp-build.js +9 -0
- package/dist/cli/update-check.d.ts +140 -0
- package/dist/cli/update-check.js +316 -0
- package/dist/cli/uploads.d.ts +16 -0
- package/dist/cli/uploads.js +80 -0
- package/dist/core/css.d.ts +95 -0
- package/dist/core/css.js +436 -0
- package/dist/core/engine.d.ts +65 -0
- package/dist/core/engine.js +436 -0
- package/dist/core/errors.d.ts +66 -0
- package/dist/core/errors.js +30 -0
- package/dist/core/evidence.d.ts +14 -0
- package/dist/core/evidence.js +127 -0
- package/dist/core/index.d.ts +12 -0
- package/dist/core/index.js +12 -0
- package/dist/core/labels.d.ts +47 -0
- package/dist/core/labels.js +199 -0
- package/dist/core/liveness.d.ts +45 -0
- package/dist/core/liveness.js +64 -0
- package/dist/core/marks.d.ts +63 -0
- package/dist/core/marks.js +410 -0
- package/dist/core/services.d.ts +444 -0
- package/dist/core/services.js +22 -0
- package/dist/core/steps.d.ts +96 -0
- package/dist/core/steps.js +656 -0
- package/dist/core/uploads.d.ts +49 -0
- package/dist/core/uploads.js +133 -0
- package/dist/core/video.d.ts +16 -0
- package/dist/core/video.js +101 -0
- package/dist/core/viewport.d.ts +28 -0
- package/dist/core/viewport.js +50 -0
- package/dist/report/html.d.ts +37 -0
- package/dist/report/html.js +762 -0
- package/dist/report/index.d.ts +5 -0
- package/dist/report/index.js +5 -0
- package/dist/report/markup.d.ts +27 -0
- package/dist/report/markup.js +75 -0
- package/dist/report/pr-summary.d.ts +11 -0
- package/dist/report/pr-summary.js +110 -0
- package/dist/report/sha256.d.ts +9 -0
- package/dist/report/sha256.js +97 -0
- package/dist/report/styles.d.ts +1 -0
- package/dist/report/styles.js +328 -0
- package/dist/report/view.d.ts +141 -0
- package/dist/report/view.js +368 -0
- package/dist/report/walkthrough.d.ts +75 -0
- package/dist/report/walkthrough.js +458 -0
- package/dist/schema/config.d.ts +7 -0
- package/dist/schema/config.js +6 -0
- package/dist/schema/doctor.d.ts +46 -0
- package/dist/schema/doctor.js +23 -0
- package/dist/schema/evidence.d.ts +994 -0
- package/dist/schema/evidence.js +521 -0
- package/dist/schema/findings.d.ts +159 -0
- package/dist/schema/findings.js +80 -0
- package/dist/schema/index.d.ts +7 -0
- package/dist/schema/index.js +7 -0
- package/dist/schema/job.d.ts +1724 -0
- package/dist/schema/job.js +505 -0
- package/dist/schema/ledger.d.ts +951 -0
- package/dist/schema/ledger.js +193 -0
- package/dist/schema/status.d.ts +7 -0
- package/dist/schema/status.js +11 -0
- package/dist/store-local/accounts.d.ts +7 -0
- package/dist/store-local/accounts.js +9 -0
- package/dist/store-local/index.d.ts +3 -0
- package/dist/store-local/index.js +3 -0
- package/dist/store-local/paths.d.ts +10 -0
- package/dist/store-local/paths.js +17 -0
- package/dist/store-local/storage.d.ts +20 -0
- package/dist/store-local/storage.js +170 -0
- package/package.json +73 -4
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Effect, type FileSystem, type Path } from 'effect';
|
|
2
|
+
import { type FfmpegLookup } from '../browser-playwright/index.js';
|
|
3
|
+
import { Browser, type BrowserInfo } from '../core/index.js';
|
|
4
|
+
import type { DoctorCheck, DoctorReport } from '../schema/index.js';
|
|
5
|
+
import { PackageInfo } from './package-info.js';
|
|
6
|
+
/** Room for a few runs' screenshots, traces and videos. */
|
|
7
|
+
export declare const MIN_FREE_BYTES: number;
|
|
8
|
+
export declare const checkNode: (current: string, range: string) => DoctorCheck;
|
|
9
|
+
/** `installCommand` is what downloads a browser when none is found. */
|
|
10
|
+
export declare const checkBrowser: (found: BrowserInfo | undefined, installCommand: string) => DoctorCheck;
|
|
11
|
+
/** A warning, not a failure: without ffmpeg runs still work, only without a video. */
|
|
12
|
+
export declare const checkVideo: (lookup: FfmpegLookup, installCommand: string) => DoctorCheck;
|
|
13
|
+
export declare const checkDisk: (path: string, freeBytes: number | undefined) => DoctorCheck;
|
|
14
|
+
/**
|
|
15
|
+
* Checks the machine without changing it: nothing is installed or downloaded. `lookupFfmpeg` is
|
|
16
|
+
* replaceable so tests need not depend on this machine's Playwright cache. `update` is the check
|
|
17
|
+
* for a newer or stale screw-bugs (see `UpdateCheck`), last when given; a warning at most.
|
|
18
|
+
*/
|
|
19
|
+
export declare const runDoctor: (projectRoot: string, lookupFfmpeg?: Effect.Effect<FfmpegLookup, never, FileSystem.FileSystem>, update?: Effect.Effect<DoctorCheck>) => Effect.Effect<DoctorReport, never, Browser | PackageInfo | FileSystem.FileSystem | Path.Path>;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// Boundary: Effect's FileSystem has no statfs, so free disk space is read with node:fs.
|
|
2
|
+
import { statfs } from 'node:fs/promises';
|
|
3
|
+
import { Effect } from 'effect';
|
|
4
|
+
import { findFfmpeg, installBrowserCommand, installFfmpegCommand, } from '../browser-playwright/index.js';
|
|
5
|
+
import { Browser } from '../core/index.js';
|
|
6
|
+
import { isAtLeast, minimumNode } from './node-version.js';
|
|
7
|
+
import { PackageInfo } from './package-info.js';
|
|
8
|
+
/** Room for a few runs' screenshots, traces and videos. */
|
|
9
|
+
export const MIN_FREE_BYTES = 1024 ** 3;
|
|
10
|
+
const browserNames = {
|
|
11
|
+
chrome: 'Google Chrome',
|
|
12
|
+
msedge: 'Microsoft Edge',
|
|
13
|
+
'playwright-chromium': "Playwright's Chromium",
|
|
14
|
+
};
|
|
15
|
+
export const checkNode = (current, range) => {
|
|
16
|
+
const minimum = minimumNode(range);
|
|
17
|
+
return isAtLeast(current, minimum)
|
|
18
|
+
? { id: 'node', ok: true, detail: `Node ${current}` }
|
|
19
|
+
: {
|
|
20
|
+
id: 'node',
|
|
21
|
+
ok: false,
|
|
22
|
+
detail: `Node ${current} is too old; screw-bugs needs ${minimum} or newer.`,
|
|
23
|
+
fix: {
|
|
24
|
+
action: `Install Node ${minimum} or newer (the LTS release is fine) from https://nodejs.org.`,
|
|
25
|
+
command: 'nvm install --lts',
|
|
26
|
+
why: 'screw-bugs uses features of recent Node, such as the built-in SQLite module.',
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
/** `installCommand` is what downloads a browser when none is found. */
|
|
31
|
+
export const checkBrowser = (found, installCommand) => found
|
|
32
|
+
? { id: 'browser', ok: true, detail: `${browserNames[found.kind]} ${found.version}` }
|
|
33
|
+
: {
|
|
34
|
+
id: 'browser',
|
|
35
|
+
ok: false,
|
|
36
|
+
detail: "No browser found: tried Google Chrome, Microsoft Edge and Playwright's Chromium.",
|
|
37
|
+
fix: {
|
|
38
|
+
action: "Install Google Chrome, or download Playwright's Chromium with the command.",
|
|
39
|
+
command: installCommand,
|
|
40
|
+
why: 'screw-bugs tests your app in a real browser.',
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
/** A warning, not a failure: without ffmpeg runs still work, only without a video. */
|
|
44
|
+
export const checkVideo = (lookup, installCommand) => lookup.found
|
|
45
|
+
? { id: 'video', ok: true, detail: 'Video recording available' }
|
|
46
|
+
: {
|
|
47
|
+
id: 'video',
|
|
48
|
+
ok: false,
|
|
49
|
+
severity: 'warning',
|
|
50
|
+
detail: lookup.path === undefined
|
|
51
|
+
? "Playwright's ffmpeg could not be looked up, so runs may have no video."
|
|
52
|
+
: `Playwright's ffmpeg is missing (looked for ${lookup.path}), so runs will have no video.`,
|
|
53
|
+
fix: {
|
|
54
|
+
action: "Download Playwright's ffmpeg with the command.",
|
|
55
|
+
command: installCommand,
|
|
56
|
+
why: 'screw-bugs records each browser session as a video with it; runs still work without one.',
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
export const checkDisk = (path, freeBytes) => {
|
|
60
|
+
if (freeBytes === undefined) {
|
|
61
|
+
return {
|
|
62
|
+
id: 'disk',
|
|
63
|
+
ok: false,
|
|
64
|
+
detail: `Could not read free disk space for ${path}.`,
|
|
65
|
+
fix: {
|
|
66
|
+
action: `Check that ${path} exists and is readable.`,
|
|
67
|
+
why: 'Runs save screenshots and recordings in the project folder.',
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
return freeBytes >= MIN_FREE_BYTES
|
|
72
|
+
? { id: 'disk', ok: true, detail: `${formatGb(freeBytes)} free` }
|
|
73
|
+
: {
|
|
74
|
+
id: 'disk',
|
|
75
|
+
ok: false,
|
|
76
|
+
detail: `Only ${formatGb(freeBytes)} free where ${path} is stored.`,
|
|
77
|
+
fix: {
|
|
78
|
+
action: `Free at least ${formatGb(MIN_FREE_BYTES)} on that disk.`,
|
|
79
|
+
why: 'Runs save screenshots and recordings in the project folder.',
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
const formatGb = (bytes) => `${(bytes / 1024 ** 3).toFixed(1)} GB`;
|
|
84
|
+
/** The statfs boundary: the only Node file system call left (see the import). */
|
|
85
|
+
const freeBytes = (path) => Effect.tryPromise(() => statfs(path)).pipe(Effect.map((stats) => stats.bavail * stats.bsize), Effect.orElseSucceed(() => undefined));
|
|
86
|
+
/** A check passes when it is ok; a warning never makes the report fail. */
|
|
87
|
+
const passes = (check) => check.ok || check.severity === 'warning';
|
|
88
|
+
/**
|
|
89
|
+
* Checks the machine without changing it: nothing is installed or downloaded. `lookupFfmpeg` is
|
|
90
|
+
* replaceable so tests need not depend on this machine's Playwright cache. `update` is the check
|
|
91
|
+
* for a newer or stale screw-bugs (see `UpdateCheck`), last when given; a warning at most.
|
|
92
|
+
*/
|
|
93
|
+
export const runDoctor = (projectRoot, lookupFfmpeg = findFfmpeg, update) => Effect.gen(function* () {
|
|
94
|
+
const browser = yield* Browser;
|
|
95
|
+
const { engines } = yield* PackageInfo;
|
|
96
|
+
const [found, ffmpeg, free, updateCheck] = yield* Effect.all([
|
|
97
|
+
browser.detect.pipe(Effect.orElseSucceed(() => undefined)),
|
|
98
|
+
lookupFfmpeg,
|
|
99
|
+
freeBytes(projectRoot),
|
|
100
|
+
update ?? Effect.succeed(undefined),
|
|
101
|
+
], { concurrency: 'unbounded' });
|
|
102
|
+
const installCommand = found ? '' : yield* installBrowserCommand;
|
|
103
|
+
const ffmpegCommand = ffmpeg.found ? '' : yield* installFfmpegCommand;
|
|
104
|
+
const checks = [
|
|
105
|
+
// Boundary: the version of the Node running us; there is no Effect service for it.
|
|
106
|
+
checkNode(process.versions.node, engines.node),
|
|
107
|
+
checkBrowser(found, installCommand),
|
|
108
|
+
checkVideo(ffmpeg, ffmpegCommand),
|
|
109
|
+
checkDisk(projectRoot, free),
|
|
110
|
+
...(updateCheck ? [updateCheck] : []),
|
|
111
|
+
];
|
|
112
|
+
return { ok: checks.every(passes), checks };
|
|
113
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Effect, Stdio } from 'effect';
|
|
2
|
+
/** How an on/off environment variable reads as on: `1`, `true`, `yes` or `on`, in any case. */
|
|
3
|
+
export declare const isTruthy: (value: string | undefined) => boolean;
|
|
4
|
+
/** How an on/off environment variable reads as off: `0`, `false`, `no` or `off`, in any case. */
|
|
5
|
+
export declare const isFalsy: (value: string | undefined) => boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Non-interactive when running in CI or when there is no terminal to ask in. In that mode
|
|
8
|
+
* screw-bugs never waits for input: anything it would ask for becomes a clear error.
|
|
9
|
+
*/
|
|
10
|
+
export declare const isNonInteractive: Effect.Effect<boolean, never, Stdio.Stdio>;
|
|
11
|
+
/**
|
|
12
|
+
* Anonymous usage analytics are off unless `SCREW_BUGS_ANALYTICS=1`. `DO_NOT_TRACK=1` always
|
|
13
|
+
* wins. Nothing is collected yet; this is the switch future collection must respect.
|
|
14
|
+
*/
|
|
15
|
+
export declare const analyticsEnabled: Effect.Effect<boolean, never, never>;
|
|
16
|
+
/**
|
|
17
|
+
* The daily check for a newer screw-bugs is on unless `SCREW_BUGS_UPDATE_CHECK=0` (or `false`,
|
|
18
|
+
* `no`, `off`), and always off in CI.
|
|
19
|
+
*/
|
|
20
|
+
export declare const updateCheckEnabled: Effect.Effect<boolean, never, never>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Config, Effect, Stdio } from 'effect';
|
|
2
|
+
/** How an on/off environment variable reads as on: `1`, `true`, `yes` or `on`, in any case. */
|
|
3
|
+
export const isTruthy = (value) => value !== undefined && ['1', 'true', 'yes', 'on'].includes(value.trim().toLowerCase());
|
|
4
|
+
/** How an on/off environment variable reads as off: `0`, `false`, `no` or `off`, in any case. */
|
|
5
|
+
export const isFalsy = (value) => value !== undefined && ['0', 'false', 'no', 'off'].includes(value.trim().toLowerCase());
|
|
6
|
+
/** An on/off environment variable, read through `Config`; unset is `unset` (off by default). */
|
|
7
|
+
const flag = (name, unset = false) => Config.String(name).pipe(Config.map((value) => (unset ? !isFalsy(value) : isTruthy(value))), Config.withDefault(unset),
|
|
8
|
+
// A plain string with a default cannot fail to read.
|
|
9
|
+
Effect.orDie);
|
|
10
|
+
/**
|
|
11
|
+
* Non-interactive when running in CI or when there is no terminal to ask in. In that mode
|
|
12
|
+
* screw-bugs never waits for input: anything it would ask for becomes a clear error.
|
|
13
|
+
*/
|
|
14
|
+
export const isNonInteractive = Effect.gen(function* () {
|
|
15
|
+
const ci = yield* flag('CI');
|
|
16
|
+
const stdinIsTerminal = yield* Stdio.Stdio.use((stdio) => stdio.stdinIsTerminal);
|
|
17
|
+
return ci || !stdinIsTerminal;
|
|
18
|
+
});
|
|
19
|
+
/**
|
|
20
|
+
* Anonymous usage analytics are off unless `SCREW_BUGS_ANALYTICS=1`. `DO_NOT_TRACK=1` always
|
|
21
|
+
* wins. Nothing is collected yet; this is the switch future collection must respect.
|
|
22
|
+
*/
|
|
23
|
+
export const analyticsEnabled = Effect.all([
|
|
24
|
+
flag('SCREW_BUGS_ANALYTICS'),
|
|
25
|
+
flag('DO_NOT_TRACK'),
|
|
26
|
+
]).pipe(Effect.map(([optedIn, doNotTrack]) => optedIn && !doNotTrack));
|
|
27
|
+
/**
|
|
28
|
+
* The daily check for a newer screw-bugs is on unless `SCREW_BUGS_UPDATE_CHECK=0` (or `false`,
|
|
29
|
+
* `no`, `off`), and always off in CI.
|
|
30
|
+
*/
|
|
31
|
+
export const updateCheckEnabled = Effect.all([
|
|
32
|
+
flag('CI'),
|
|
33
|
+
flag('SCREW_BUGS_UPDATE_CHECK', true),
|
|
34
|
+
]).pipe(Effect.map(([ci, enabled]) => enabled && !ci));
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** Process exit codes. Stable: CI scripts may branch on them. */
|
|
2
|
+
export declare const ExitCode: {
|
|
3
|
+
readonly Ok: 0;
|
|
4
|
+
/** A run ended with at least one case that did not pass. */
|
|
5
|
+
readonly TestsFailed: 1;
|
|
6
|
+
/** Bad arguments or flags. */
|
|
7
|
+
readonly Usage: 2;
|
|
8
|
+
/** `screw-bugs.json` is missing or invalid. */
|
|
9
|
+
readonly Config: 3;
|
|
10
|
+
/** `doctor` found something missing (Node, browser, disk). */
|
|
11
|
+
readonly NotReady: 4;
|
|
12
|
+
/** The command exists but is not built yet. */
|
|
13
|
+
readonly NotImplemented: 5;
|
|
14
|
+
/** Findings were not valid for the run; nothing was saved. The message says what to fix. */
|
|
15
|
+
readonly InvalidFindings: 6;
|
|
16
|
+
/**
|
|
17
|
+
* Files the job's upload steps give are missing or unusable, so nothing was started. The
|
|
18
|
+
* message (and `--json`) lists each with why; create them and start the run again.
|
|
19
|
+
*/
|
|
20
|
+
readonly FilesNeeded: 7;
|
|
21
|
+
/** A bug in screw-bugs. */
|
|
22
|
+
readonly Internal: 70;
|
|
23
|
+
/**
|
|
24
|
+
* Stopped by Ctrl+C or SIGTERM (128 + SIGINT, as shells report it). Runs in progress were
|
|
25
|
+
* marked errored, with unfinished cases not verified.
|
|
26
|
+
*/
|
|
27
|
+
readonly Interrupted: 130;
|
|
28
|
+
};
|
|
29
|
+
export type ExitCode = (typeof ExitCode)[keyof typeof ExitCode];
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** Process exit codes. Stable: CI scripts may branch on them. */
|
|
2
|
+
export const ExitCode = {
|
|
3
|
+
Ok: 0,
|
|
4
|
+
/** A run ended with at least one case that did not pass. */
|
|
5
|
+
TestsFailed: 1,
|
|
6
|
+
/** Bad arguments or flags. */
|
|
7
|
+
Usage: 2,
|
|
8
|
+
/** `screw-bugs.json` is missing or invalid. */
|
|
9
|
+
Config: 3,
|
|
10
|
+
/** `doctor` found something missing (Node, browser, disk). */
|
|
11
|
+
NotReady: 4,
|
|
12
|
+
/** The command exists but is not built yet. */
|
|
13
|
+
NotImplemented: 5,
|
|
14
|
+
/** Findings were not valid for the run; nothing was saved. The message says what to fix. */
|
|
15
|
+
InvalidFindings: 6,
|
|
16
|
+
/**
|
|
17
|
+
* Files the job's upload steps give are missing or unusable, so nothing was started. The
|
|
18
|
+
* message (and `--json`) lists each with why; create them and start the run again.
|
|
19
|
+
*/
|
|
20
|
+
FilesNeeded: 7,
|
|
21
|
+
/** A bug in screw-bugs. */
|
|
22
|
+
Internal: 70,
|
|
23
|
+
/**
|
|
24
|
+
* Stopped by Ctrl+C or SIGTERM (128 + SIGINT, as shells report it). Runs in progress were
|
|
25
|
+
* marked errored, with unfinished cases not verified.
|
|
26
|
+
*/
|
|
27
|
+
Interrupted: 130,
|
|
28
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { NotImplemented } from '../core/index.js';
|
|
2
|
+
import { ExitCode } from './exit-codes.js';
|
|
3
|
+
declare const Failure_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
4
|
+
readonly _tag: "Failure";
|
|
5
|
+
} & Readonly<A>;
|
|
6
|
+
/** An expected failure with a plain-language message, shared by the CLI and the MCP server. */
|
|
7
|
+
export declare class Failure extends Failure_base<{
|
|
8
|
+
readonly code: ExitCode;
|
|
9
|
+
/** Machine-readable reason for `--json` output. */
|
|
10
|
+
readonly reason: string;
|
|
11
|
+
readonly message: string;
|
|
12
|
+
/** Absolute paths to give after the message, one per line. */
|
|
13
|
+
readonly paths?: ReadonlyArray<string> | undefined;
|
|
14
|
+
/** More machine-readable fields for the `--json` error, such as the files a job needs. */
|
|
15
|
+
readonly details?: Readonly<Record<string, unknown>> | undefined;
|
|
16
|
+
}> {
|
|
17
|
+
}
|
|
18
|
+
export declare const notImplemented: (command: string) => Failure;
|
|
19
|
+
export declare const fromNotImplemented: (error: NotImplemented) => Failure;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Data } from 'effect';
|
|
2
|
+
import { ExitCode } from './exit-codes.js';
|
|
3
|
+
/** An expected failure with a plain-language message, shared by the CLI and the MCP server. */
|
|
4
|
+
export class Failure extends Data.TaggedError('Failure') {
|
|
5
|
+
}
|
|
6
|
+
export const notImplemented = (command) => new Failure({
|
|
7
|
+
code: ExitCode.NotImplemented,
|
|
8
|
+
reason: 'not_implemented',
|
|
9
|
+
message: `\`screw-bugs ${command}\` is not implemented yet. This release is an early scaffold.`,
|
|
10
|
+
});
|
|
11
|
+
export const fromNotImplemented = (error) => new Failure({
|
|
12
|
+
code: ExitCode.NotImplemented,
|
|
13
|
+
reason: 'not_implemented',
|
|
14
|
+
message: `${error.message} This release is an early scaffold.`,
|
|
15
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { appLayer, runCli } from './app.js';
|
|
2
|
+
export * from './environment.js';
|
|
3
|
+
export { ExitCode } from './exit-codes.js';
|
|
4
|
+
export { Failure } from './failure.js';
|
|
5
|
+
export { formatDoctor, makeMcpServer } from './mcp.js';
|
|
6
|
+
export { Operations } from './operations.js';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { appLayer, runCli } from './app.js';
|
|
2
|
+
export * from './environment.js';
|
|
3
|
+
export { ExitCode } from './exit-codes.js';
|
|
4
|
+
export { Failure } from './failure.js';
|
|
5
|
+
export { formatDoctor, makeMcpServer } from './mcp.js';
|
|
6
|
+
export { Operations } from './operations.js';
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { Effect, FileSystem, Path } from 'effect';
|
|
2
|
+
export type PackageManager = 'npm' | 'pnpm' | 'yarn' | 'bun';
|
|
3
|
+
/** How the running copy of screw-bugs was installed, worked out from where it lives. */
|
|
4
|
+
export type InstallMethod =
|
|
5
|
+
/** A clone of the repository, run from its `dist/`. */
|
|
6
|
+
{
|
|
7
|
+
readonly kind: 'git';
|
|
8
|
+
readonly root: string;
|
|
9
|
+
}
|
|
10
|
+
/** npx's cache (`~/.npm/_npx/…`): the MCP config runs `npx screw-bugs …`. */
|
|
11
|
+
| {
|
|
12
|
+
readonly kind: 'npx';
|
|
13
|
+
} | {
|
|
14
|
+
readonly kind: 'global';
|
|
15
|
+
readonly manager: 'npm' | 'pnpm';
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A dependency of the project in `project`, installed with `manager`, listed in the project's
|
|
19
|
+
* package.json under `section` (missing when it is not listed there).
|
|
20
|
+
*/
|
|
21
|
+
| {
|
|
22
|
+
readonly kind: 'project';
|
|
23
|
+
readonly manager: PackageManager;
|
|
24
|
+
readonly project: string;
|
|
25
|
+
readonly section?: DependencySection;
|
|
26
|
+
}
|
|
27
|
+
/** Somewhere else: the npm command is the best guess. */
|
|
28
|
+
| {
|
|
29
|
+
readonly kind: 'unknown';
|
|
30
|
+
};
|
|
31
|
+
/** Where a project's package.json lists a dependency. */
|
|
32
|
+
export type DependencySection = 'dependencies' | 'devDependencies' | 'optionalDependencies';
|
|
33
|
+
/** Where the project's package.json lists `name`; none when it does not, or cannot be read. */
|
|
34
|
+
export declare const dependencySection: (project: string, name: string) => Effect.Effect<DependencySection | undefined, never, FileSystem.FileSystem | Path.Path>;
|
|
35
|
+
/**
|
|
36
|
+
* Where a package folder sits, from its path alone (`/` or `\` separated). `git` is decided before
|
|
37
|
+
* this, by a `.git` in the folder; the project's package manager after it, by its lock file.
|
|
38
|
+
*/
|
|
39
|
+
export declare const classifyInstallPath: (packageRoot: string) => {
|
|
40
|
+
readonly kind: 'npx';
|
|
41
|
+
} | {
|
|
42
|
+
readonly kind: 'global';
|
|
43
|
+
readonly manager: 'npm' | 'pnpm';
|
|
44
|
+
} | {
|
|
45
|
+
readonly kind: 'project';
|
|
46
|
+
readonly project: string;
|
|
47
|
+
} | {
|
|
48
|
+
readonly kind: 'unknown';
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* How the copy of `name` in `packageRoot` (the folder of its package.json) was installed.
|
|
52
|
+
*/
|
|
53
|
+
export declare const detectInstall: (packageRoot: string, name: string) => Effect.Effect<{
|
|
54
|
+
readonly kind: 'npx';
|
|
55
|
+
} | {
|
|
56
|
+
readonly kind: 'global';
|
|
57
|
+
readonly manager: 'npm' | 'pnpm';
|
|
58
|
+
} | {
|
|
59
|
+
readonly kind: 'unknown';
|
|
60
|
+
} | {
|
|
61
|
+
kind: "git";
|
|
62
|
+
root: string;
|
|
63
|
+
} | {
|
|
64
|
+
root?: never;
|
|
65
|
+
kind: "project";
|
|
66
|
+
manager: PackageManager;
|
|
67
|
+
project: string;
|
|
68
|
+
section?: DependencySection;
|
|
69
|
+
}, never, FileSystem.FileSystem | Path.Path>;
|
|
70
|
+
/**
|
|
71
|
+
* A POSIX path as one shell word, quoted only when it needs to be: single quotes (`'` as `'\''`),
|
|
72
|
+
* inside which a POSIX shell expands nothing, so `$()`, backticks and `$VAR` stay text.
|
|
73
|
+
*/
|
|
74
|
+
export declare const shellWord: (word: string) => string;
|
|
75
|
+
/**
|
|
76
|
+
* `command` to run in `folder`: `cd <folder> && command` for a POSIX path; for a Windows path, the
|
|
77
|
+
* command alone with the folder to run it in.
|
|
78
|
+
*
|
|
79
|
+
* A Windows path never gets a `cd`: in cmd, `cd "D:\app"` from a prompt on C: only changes D:'s
|
|
80
|
+
* folder and stays on C:, so the command would run in the wrong project; `cd /d` is not understood
|
|
81
|
+
* by PowerShell or Git Bash; and no quoting of a path is literal in all three.
|
|
82
|
+
*/
|
|
83
|
+
export declare const inFolder: (folder: string, command: string) => {
|
|
84
|
+
readonly command: string;
|
|
85
|
+
readonly cwd?: string;
|
|
86
|
+
};
|
|
87
|
+
/** The command that brings this copy up to date, and where it goes. */
|
|
88
|
+
export interface UpdateCommand {
|
|
89
|
+
readonly command: string;
|
|
90
|
+
/** `config`: the command goes in the MCP config instead of being run. */
|
|
91
|
+
readonly runs: 'shell' | 'config';
|
|
92
|
+
/** The folder to run it in, when it is not in the command (see `inFolder`). */
|
|
93
|
+
readonly cwd?: string;
|
|
94
|
+
}
|
|
95
|
+
/** The exact command that updates `name` installed this way. screw-bugs never runs it. */
|
|
96
|
+
export declare const updateCommandFor: (method: InstallMethod, name: string) => UpdateCommand;
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { Effect, FileSystem, Option, Path, Schema } from 'effect';
|
|
2
|
+
/** The sections in the order they decide: npm lets `optionalDependencies` win over `dependencies`. */
|
|
3
|
+
const SECTIONS = [
|
|
4
|
+
'optionalDependencies',
|
|
5
|
+
'dependencies',
|
|
6
|
+
'devDependencies',
|
|
7
|
+
];
|
|
8
|
+
const Dependencies = Schema.optionalKey(Schema.Record(Schema.String, Schema.Unknown));
|
|
9
|
+
/** The parts of a project's package.json that say where a dependency is listed. */
|
|
10
|
+
const ProjectManifest = Schema.Struct({
|
|
11
|
+
dependencies: Dependencies,
|
|
12
|
+
devDependencies: Dependencies,
|
|
13
|
+
optionalDependencies: Dependencies,
|
|
14
|
+
});
|
|
15
|
+
/** Where the project's package.json lists `name`; none when it does not, or cannot be read. */
|
|
16
|
+
export const dependencySection = (project, name) => Effect.gen(function* () {
|
|
17
|
+
const fs = yield* FileSystem.FileSystem;
|
|
18
|
+
const path = yield* Path.Path;
|
|
19
|
+
const manifest = yield* fs
|
|
20
|
+
.readFileString(path.join(project, 'package.json'))
|
|
21
|
+
.pipe(Effect.flatMap(Schema.decodeUnknownEffect(Schema.fromJsonString(ProjectManifest))), Effect.option);
|
|
22
|
+
return Option.match(manifest, {
|
|
23
|
+
onNone: () => undefined,
|
|
24
|
+
onSome: (found) => SECTIONS.find((section) => Object.hasOwn(found[section] ?? {}, name)),
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
/** Lock files, in the order they decide a project's package manager. */
|
|
28
|
+
const LOCK_FILES = [
|
|
29
|
+
['pnpm-lock.yaml', 'pnpm'],
|
|
30
|
+
['yarn.lock', 'yarn'],
|
|
31
|
+
['bun.lock', 'bun'],
|
|
32
|
+
['bun.lockb', 'bun'],
|
|
33
|
+
['package-lock.json', 'npm'],
|
|
34
|
+
];
|
|
35
|
+
/**
|
|
36
|
+
* Where a package folder sits, from its path alone (`/` or `\` separated). `git` is decided before
|
|
37
|
+
* this, by a `.git` in the folder; the project's package manager after it, by its lock file.
|
|
38
|
+
*/
|
|
39
|
+
export const classifyInstallPath = (packageRoot) => {
|
|
40
|
+
const parts = packageRoot.split(/[\\/]+/);
|
|
41
|
+
const lower = parts.map((part) => part.toLowerCase());
|
|
42
|
+
if (lower.includes('_npx'))
|
|
43
|
+
return { kind: 'npx' };
|
|
44
|
+
const pnpmAt = lower.findIndex((part, i) => part === 'pnpm' && lower[i + 1] === 'global');
|
|
45
|
+
if (pnpmAt >= 0)
|
|
46
|
+
return { kind: 'global', manager: 'pnpm' };
|
|
47
|
+
const modulesAt = lower.indexOf('node_modules');
|
|
48
|
+
if (modulesAt < 0)
|
|
49
|
+
return { kind: 'unknown' };
|
|
50
|
+
// npm's global folder: `<prefix>/lib/node_modules` (macOS, Linux, nvm) or `…\npm\node_modules`
|
|
51
|
+
// (Windows), with the package right in it.
|
|
52
|
+
const before = lower[modulesAt - 1];
|
|
53
|
+
if ((before === 'lib' || before === 'npm') && modulesAt === lower.length - 2) {
|
|
54
|
+
return { kind: 'global', manager: 'npm' };
|
|
55
|
+
}
|
|
56
|
+
if (modulesAt === 0)
|
|
57
|
+
return { kind: 'unknown' };
|
|
58
|
+
// The project is the folder that holds the outermost node_modules.
|
|
59
|
+
const separator = packageRoot.includes('/') ? '/' : '\\';
|
|
60
|
+
return {
|
|
61
|
+
kind: 'project',
|
|
62
|
+
project: parts.slice(0, modulesAt).join(separator),
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* How the copy of `name` in `packageRoot` (the folder of its package.json) was installed.
|
|
67
|
+
*/
|
|
68
|
+
export const detectInstall = (packageRoot, name) => Effect.gen(function* () {
|
|
69
|
+
const fs = yield* FileSystem.FileSystem;
|
|
70
|
+
const path = yield* Path.Path;
|
|
71
|
+
const exists = (file) => fs.exists(file).pipe(Effect.orElseSucceed(() => false));
|
|
72
|
+
// A `.git` folder (or, in a worktree, a file) next to package.json: a checkout.
|
|
73
|
+
if (yield* exists(path.join(packageRoot, '.git'))) {
|
|
74
|
+
return { kind: 'git', root: packageRoot };
|
|
75
|
+
}
|
|
76
|
+
// Node loads modules from their real paths, so a pnpm dependency is seen in the project's
|
|
77
|
+
// `node_modules/.pnpm/…`: its outermost node_modules is still the project's.
|
|
78
|
+
const where = classifyInstallPath(packageRoot);
|
|
79
|
+
if (where.kind !== 'project')
|
|
80
|
+
return where;
|
|
81
|
+
let manager = 'npm';
|
|
82
|
+
for (const [file, locked] of LOCK_FILES) {
|
|
83
|
+
if (yield* exists(path.join(where.project, file))) {
|
|
84
|
+
manager = locked;
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const section = yield* dependencySection(where.project, name);
|
|
89
|
+
return {
|
|
90
|
+
kind: 'project',
|
|
91
|
+
manager,
|
|
92
|
+
project: where.project,
|
|
93
|
+
...(section ? { section } : {}),
|
|
94
|
+
};
|
|
95
|
+
});
|
|
96
|
+
/** What every shell takes literally without quotes. No `~` (a home folder at the start), no `\`. */
|
|
97
|
+
const PLAIN_WORD = /^[A-Za-z0-9_./:@+,=-]+$/;
|
|
98
|
+
/** A path with a drive letter (`C:\…`, `C:/…`) or a UNC path (`\\server\…`). */
|
|
99
|
+
const WINDOWS_PATH = /^(?:[A-Za-z]:[\\/]|\\\\)/;
|
|
100
|
+
/**
|
|
101
|
+
* A POSIX path as one shell word, quoted only when it needs to be: single quotes (`'` as `'\''`),
|
|
102
|
+
* inside which a POSIX shell expands nothing, so `$()`, backticks and `$VAR` stay text.
|
|
103
|
+
*/
|
|
104
|
+
export const shellWord = (word) => PLAIN_WORD.test(word) ? word : `'${word.replaceAll("'", "'\\''")}'`;
|
|
105
|
+
/**
|
|
106
|
+
* `command` to run in `folder`: `cd <folder> && command` for a POSIX path; for a Windows path, the
|
|
107
|
+
* command alone with the folder to run it in.
|
|
108
|
+
*
|
|
109
|
+
* A Windows path never gets a `cd`: in cmd, `cd "D:\app"` from a prompt on C: only changes D:'s
|
|
110
|
+
* folder and stays on C:, so the command would run in the wrong project; `cd /d` is not understood
|
|
111
|
+
* by PowerShell or Git Bash; and no quoting of a path is literal in all three.
|
|
112
|
+
*/
|
|
113
|
+
export const inFolder = (folder, command) => WINDOWS_PATH.test(folder)
|
|
114
|
+
? { command, cwd: folder }
|
|
115
|
+
: { command: `cd ${shellWord(folder)} && ${command}` };
|
|
116
|
+
/** The flag that adds a dependency to `section` again (`-D` when it is not listed). */
|
|
117
|
+
const addFlag = (manager, section) => {
|
|
118
|
+
if (section === 'dependencies')
|
|
119
|
+
return '';
|
|
120
|
+
if (section === 'optionalDependencies')
|
|
121
|
+
return manager === 'bun' ? ' --optional' : ' -O';
|
|
122
|
+
return ' -D';
|
|
123
|
+
};
|
|
124
|
+
/** The exact command that updates `name` installed this way. screw-bugs never runs it. */
|
|
125
|
+
export const updateCommandFor = (method, name) => {
|
|
126
|
+
const latest = `${name}@latest`;
|
|
127
|
+
switch (method.kind) {
|
|
128
|
+
case 'git':
|
|
129
|
+
return {
|
|
130
|
+
...inFolder(method.root, 'git pull && pnpm build'),
|
|
131
|
+
runs: 'shell',
|
|
132
|
+
};
|
|
133
|
+
case 'npx':
|
|
134
|
+
return { command: `npx -y ${latest} mcp`, runs: 'config' };
|
|
135
|
+
case 'global':
|
|
136
|
+
return {
|
|
137
|
+
command: method.manager === 'pnpm' ? `pnpm add -g ${latest}` : `npm i -g ${latest}`,
|
|
138
|
+
runs: 'shell',
|
|
139
|
+
};
|
|
140
|
+
case 'project':
|
|
141
|
+
return {
|
|
142
|
+
...inFolder(method.project, `${method.manager} add${addFlag(method.manager, method.section)} ${latest}`),
|
|
143
|
+
runs: 'shell',
|
|
144
|
+
};
|
|
145
|
+
case 'unknown':
|
|
146
|
+
return { command: `npm i -g ${latest}`, runs: 'shell' };
|
|
147
|
+
}
|
|
148
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/cli/main.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { NodeServices } from '@effect/platform-node';
|
|
2
|
+
import { Effect, Path, Stdio } from 'effect';
|
|
3
|
+
import { appLayer, runCli } from './app.js';
|
|
4
|
+
import { runMain } from './signals.js';
|
|
5
|
+
runMain(Effect.gen(function* () {
|
|
6
|
+
const args = yield* Stdio.Stdio.use((stdio) => stdio.args);
|
|
7
|
+
// With no arguments, `resolve` is the working directory: the project screw-bugs runs in.
|
|
8
|
+
const projectRoot = yield* Path.Path.useSync((path) => path.resolve());
|
|
9
|
+
return yield* runCli(args).pipe(Effect.provide(appLayer(projectRoot)));
|
|
10
|
+
}).pipe(Effect.provide(NodeServices.layer)));
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/server';
|
|
2
|
+
import { Effect, Path } from 'effect';
|
|
3
|
+
import { type CaseLedger, type DoctorReport, type EvidencePack } from '../schema/index.js';
|
|
4
|
+
import { type FindingsResult, Operations } from './operations.js';
|
|
5
|
+
import { PackageInfo } from './package-info.js';
|
|
6
|
+
export declare const formatDoctor: (report: DoctorReport) => string;
|
|
7
|
+
export declare const formatLedger: (ledger: CaseLedger) => string;
|
|
8
|
+
/** A run counts as passed only when it finished and every case passed. */
|
|
9
|
+
export declare const allPassed: (ledger: CaseLedger) => boolean;
|
|
10
|
+
/** A status reply lists at most this many cases, those that did not pass first; the rest are counted. */
|
|
11
|
+
export declare const LISTED_CASES = 10;
|
|
12
|
+
/** Screenshot IDs and timecodes listed per case; evidence.json has them all. */
|
|
13
|
+
export declare const SHOTS_LISTED = 8;
|
|
14
|
+
export declare const TIMECODES_LISTED = 12;
|
|
15
|
+
/**
|
|
16
|
+
* After the counts of an ended run, the compact evidence pack: two lines per case (cases that did
|
|
17
|
+
* not pass first), at most `LISTED_CASES`, then how many more there are, and a line for a video
|
|
18
|
+
* that is missing or incomplete.
|
|
19
|
+
*/
|
|
20
|
+
export declare const formatEvidence: (ledger: CaseLedger, pack: EvidencePack) => ReadonlyArray<string>;
|
|
21
|
+
/** One line per case that did not pass, for a run without an evidence pack. */
|
|
22
|
+
export declare const formatNotPassing: (ledger: CaseLedger) => ReadonlyArray<string>;
|
|
23
|
+
/** A status reply: the counts, then the evidence pack (see `formatEvidence`). */
|
|
24
|
+
export declare const formatStatus: (ledger: CaseLedger, pack?: EvidencePack) => string;
|
|
25
|
+
/** The reply to saved findings: one sentence, maybe one about highlights, then the paths. */
|
|
26
|
+
export declare const formatFindings: (result: FindingsResult) => string;
|
|
27
|
+
/** The MCP server: exactly five tools, each a thin call into `Operations`. */
|
|
28
|
+
export declare const makeMcpServer: Effect.Effect<McpServer, never, Operations | PackageInfo | Path.Path>;
|
|
29
|
+
/** Serves MCP over stdio until the client disconnects. Nothing else may write to stdout. */
|
|
30
|
+
export declare const serveMcp: Effect.Effect<void, never, Operations | PackageInfo | Path.Path>;
|