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,5 @@
1
+ {
2
+ "id": "2026-11-04T22:43:25.274Z-3f71a942",
3
+ "builtAt": "2026-11-04T22:43:25.274Z",
4
+ "commit": "3723289d34ae685c4dff51eb580fa9e5b5453383"
5
+ }
@@ -0,0 +1,19 @@
1
+ import { Effect, Layer } from 'effect';
2
+ import { Command } from 'effect/cli';
3
+ import { ExitCode } from './exit-codes.js';
4
+ import { Operations } from './operations.js';
5
+ import { PackageInfo } from './package-info.js';
6
+ import { RunningBuild } from './build-info.js';
7
+ import { ReportServer } from './report-server.js';
8
+ import { UpdateCheck } from './update-check.js';
9
+ /**
10
+ * The production wiring: the engine on top of the local adapters, and the report server, for one
11
+ * project folder. It
12
+ * needs the platform (`FileSystem`, `Path`) from outside: `NodeServices` in production and tests.
13
+ */
14
+ export declare const appLayer: (projectRoot: string) => Layer.Layer<Operations | PackageInfo | ReportServer | RunningBuild | UpdateCheck, never, import("effect/process/ChildProcessSpawner").ChildProcessSpawner | import("effect/FileSystem").FileSystem | import("effect/Path").Path | import("effect/Stdio").Stdio>;
15
+ /**
16
+ * Runs the CLI and resolves to the process exit code. A due update check started with it gets
17
+ * the rest of its time after the command has written everything; it never changes the code.
18
+ */
19
+ export declare const runCli: (args: ReadonlyArray<string>) => Effect.Effect<ExitCode, never, Operations | PackageInfo | Command.Environment>;
@@ -0,0 +1,70 @@
1
+ import { NodeHttpClient } from '@effect/platform-node';
2
+ import { Duration, Effect, Layer, Option } from 'effect';
3
+ import { CliError, Command } from 'effect/cli';
4
+ import { BrowserPlaywright } from '../browser-playwright/index.js';
5
+ import { AppVersion, Engine, Notifier, ProcessId } from '../core/index.js';
6
+ import { ReportRendererHtml } from '../report/index.js';
7
+ import { AccountBookLocal, StorageLocal } from '../store-local/index.js';
8
+ import { root } from './commands.js';
9
+ import { ExitCode } from './exit-codes.js';
10
+ import { Operations } from './operations.js';
11
+ import { PackageInfo } from './package-info.js';
12
+ import { RunningBuild } from './build-info.js';
13
+ import { ReportServer } from './report-server.js';
14
+ import { CLI_WAIT, UpdateCheck } from './update-check.js';
15
+ /** Progress goes nowhere yet; the terminal and MCP notifiers come with real runs. */
16
+ const NotifierSilent = Layer.succeed(Notifier, { notify: () => Effect.void });
17
+ /** Boundary: the ID of this operating-system process, read here and nowhere else. */
18
+ const ProcessIdLive = Layer.sync(ProcessId, () => process.pid);
19
+ /** The version recorded in each ledger: ours, from package.json. */
20
+ const AppVersionLive = Layer.effect(AppVersion, PackageInfo.use(({ version }) => Effect.succeed(version)));
21
+ /**
22
+ * The daily check for a newer screw-bugs. Boundary: the operating system's name, which decides
23
+ * where the user's cache folder is; there is no Effect service for it.
24
+ */
25
+ const UpdateCheckLive = UpdateCheck.layer(process.platform).pipe(Layer.provide(NodeHttpClient.layerNodeHttp), Layer.provideMerge(RunningBuild.layer));
26
+ /**
27
+ * The production wiring: the engine on top of the local adapters, and the report server, for one
28
+ * project folder. It
29
+ * needs the platform (`FileSystem`, `Path`) from outside: `NodeServices` in production and tests.
30
+ */
31
+ export const appLayer = (projectRoot) => Operations.layer(projectRoot).pipe(Layer.provide(Engine.layer), Layer.provide(Layer.mergeAll(BrowserPlaywright, StorageLocal(projectRoot), AccountBookLocal(projectRoot), NotifierSilent, ReportRendererHtml, ProcessIdLive, AppVersionLive)),
32
+ // Built first, so `RunningBuild` records the build this process started with.
33
+ Layer.provideMerge(UpdateCheckLive), Layer.provideMerge(PackageInfo.layer),
34
+ // Starts nothing until the MCP server first gives a report URL.
35
+ Layer.merge(ReportServer.layer(projectRoot)));
36
+ /**
37
+ * Before a command: the line about a newer version (when one is known and due), and, when a check
38
+ * is due, a check of the registry in the background. Returns the wait for that check, which the
39
+ * command does after its output (see `UpdateCheck.startCliCheck`). Both together hold the command
40
+ * back at most `CLI_WAIT`. `mcp` runs its own (see `serveMcp`).
41
+ */
42
+ const startUpdateCheck = (args) => Effect.serviceOption(UpdateCheck).pipe(Effect.flatMap(Option.match({
43
+ onNone: () => Effect.succeed(Effect.void),
44
+ onSome: (check) => args[0] === 'mcp'
45
+ ? Effect.succeed(Effect.void)
46
+ : Effect.gen(function* () {
47
+ // One cap for all the check adds to a command, the line before it and the wait
48
+ // after it: `CLI_WAIT` from here, whatever the filesystem or registry does.
49
+ const now = Effect.clockWith((clock) => clock.currentTimeMillis);
50
+ const deadline = (yield* now) + Duration.toMillis(CLI_WAIT);
51
+ yield* check.cliNotice(args);
52
+ const wait = yield* check.startCliCheck;
53
+ return Effect.gen(function* () {
54
+ const left = Duration.millis(Math.max(0, deadline - (yield* now)));
55
+ yield* wait.pipe(Effect.timeoutOption(left));
56
+ });
57
+ }),
58
+ })));
59
+ /**
60
+ * Runs the CLI and resolves to the process exit code. A due update check started with it gets
61
+ * the rest of its time after the command has written everything; it never changes the code.
62
+ */
63
+ export const runCli = (args) => Effect.gen(function* () {
64
+ 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)),
66
+ // Effect CLI has already printed the problem and the relevant help.
67
+ Effect.catchIf(CliError.isCliError, () => Effect.succeed(ExitCode.Usage)));
68
+ yield* waitForCheck;
69
+ return code;
70
+ });
@@ -0,0 +1,52 @@
1
+ import { Context, Effect, FileSystem, Layer, Path, Schema } from 'effect';
2
+ import { ChildProcessSpawner } from 'effect/process';
3
+ import type { InstallMethod } from './install-method.js';
4
+ import { PackageInfo } from './package-info.js';
5
+ /** Written into `dist/` by `pnpm build`, after the compiler. */
6
+ export declare const BUILD_INFO_FILE = "build-info.json";
7
+ /** What a build of `dist/` was made from. */
8
+ export declare const BuildInfo: Schema.Struct<{
9
+ /** Different for every build, so a running process can tell it was rebuilt under it. */
10
+ readonly id: Schema.String;
11
+ readonly builtAt: Schema.String;
12
+ /** The checkout's HEAD when it was built; missing when it was not built in a git checkout. */
13
+ readonly commit: Schema.optionalKey<Schema.String>;
14
+ }>;
15
+ export type BuildInfo = typeof BuildInfo.Type;
16
+ /** The commit a checkout in `root` is at, if it is one and git can tell. */
17
+ export declare const gitHead: (root: string) => Effect.Effect<string | undefined, never, ChildProcessSpawner.ChildProcessSpawner>;
18
+ /** The stamp of the build in `<root>/dist`, if it has a readable one. */
19
+ export declare const readBuildInfo: (root: string) => Effect.Effect<BuildInfo | undefined, never, FileSystem.FileSystem | Path.Path>;
20
+ /** Stamps `<root>/dist` with a new build ID, the time and the checkout's commit. */
21
+ export declare const stampBuild: (root: string) => Effect.Effect<string, import("effect/PlatformError").PlatformError, ChildProcessSpawner.ChildProcessSpawner | FileSystem.FileSystem | Path.Path>;
22
+ declare const RunningBuild_base: Context.ServiceClass<RunningBuild, "screw-bugs/RunningBuild", {
23
+ readonly version: string;
24
+ readonly build: BuildInfo | undefined;
25
+ }>;
26
+ /** What this process loaded when it started: its version and build. */
27
+ export declare class RunningBuild extends RunningBuild_base {
28
+ static readonly layer: Layer.Layer<RunningBuild, never, FileSystem.FileSystem | PackageInfo | Path.Path>;
29
+ }
30
+ /** Something about the build that needs fixing; at most one is reported, the first that applies. */
31
+ export type BuildProblem =
32
+ /** This process runs older code than is now installed: it must be restarted to use it. */
33
+ {
34
+ readonly kind: 'restart';
35
+ readonly loaded: string;
36
+ readonly installed: string;
37
+ }
38
+ /** A checkout's `dist/` was built from another commit than the one checked out. */
39
+ | {
40
+ readonly kind: 'rebuild';
41
+ readonly root: string;
42
+ readonly built: string;
43
+ readonly head: string;
44
+ };
45
+ /**
46
+ * Whether the code running differs from what is installed (any install: a rebuilt `dist/` or a
47
+ * new version in package.json), and, for a git checkout, whether `dist/` is behind it. Works
48
+ * offline. A build without a stamp (from before stamps, or not built with `pnpm build`) skips the
49
+ * checks that need one.
50
+ */
51
+ export declare const buildProblem: (install: InstallMethod) => Effect.Effect<BuildProblem | undefined, never, RunningBuild | PackageInfo | FileSystem.FileSystem | Path.Path | ChildProcessSpawner.ChildProcessSpawner>;
52
+ export {};
@@ -0,0 +1,82 @@
1
+ import { Context, DateTime, Effect, FileSystem, Layer, Path, Random, Schema } from 'effect';
2
+ import { ChildProcess, ChildProcessSpawner } from 'effect/process';
3
+ import { PackageInfo } from './package-info.js';
4
+ /** Written into `dist/` by `pnpm build`, after the compiler. */
5
+ export const BUILD_INFO_FILE = 'build-info.json';
6
+ /** What a build of `dist/` was made from. */
7
+ export const BuildInfo = Schema.Struct({
8
+ /** Different for every build, so a running process can tell it was rebuilt under it. */
9
+ id: Schema.String,
10
+ builtAt: Schema.String,
11
+ /** The checkout's HEAD when it was built; missing when it was not built in a git checkout. */
12
+ commit: Schema.optionalKey(Schema.String),
13
+ });
14
+ const GIT_COMMIT = /^[0-9a-f]{40}$/;
15
+ /** The commit a checkout in `root` is at, if it is one and git can tell. */
16
+ export const gitHead = (root) => ChildProcessSpawner.ChildProcessSpawner.use((spawner) => spawner.string(ChildProcess.make('git', ['rev-parse', 'HEAD'], { cwd: root }))).pipe(Effect.map((out) => (GIT_COMMIT.test(out.trim()) ? out.trim() : undefined)), Effect.orElseSucceed(() => undefined));
17
+ const buildInfoPath = (root) => Path.Path.useSync((path) => path.join(root, 'dist', BUILD_INFO_FILE));
18
+ /** The stamp of the build in `<root>/dist`, if it has a readable one. */
19
+ export const readBuildInfo = (root) => Effect.gen(function* () {
20
+ const fs = yield* FileSystem.FileSystem;
21
+ const text = yield* fs.readFileString(yield* buildInfoPath(root));
22
+ return yield* Schema.decodeUnknownEffect(Schema.fromJsonString(BuildInfo))(text);
23
+ }).pipe(Effect.orElseSucceed(() => undefined));
24
+ /** Stamps `<root>/dist` with a new build ID, the time and the checkout's commit. */
25
+ export const stampBuild = (root) => Effect.gen(function* () {
26
+ const fs = yield* FileSystem.FileSystem;
27
+ const commit = yield* gitHead(root);
28
+ const id = (yield* Random.nextIntBetween(0, 2 ** 32 - 1)).toString(16).padStart(8, '0');
29
+ const builtAt = DateTime.formatIso(yield* DateTime.now);
30
+ const info = { id: `${builtAt}-${id}`, builtAt, ...(commit ? { commit } : {}) };
31
+ const file = yield* buildInfoPath(root);
32
+ yield* fs.writeFileString(file, `${JSON.stringify(info, null, 2)}\n`);
33
+ return file;
34
+ });
35
+ /** What this process loaded when it started: its version and build. */
36
+ export class RunningBuild extends Context.Service()('screw-bugs/RunningBuild') {
37
+ static layer = Layer.effect(RunningBuild, Effect.gen(function* () {
38
+ const { version, root } = yield* PackageInfo;
39
+ return { version, build: yield* readBuildInfo(root) };
40
+ }));
41
+ }
42
+ const PackageVersion = Schema.Struct({ version: Schema.String });
43
+ /** What is on disk now: the version in package.json and the build in `dist/`. */
44
+ const installedNow = (root) => Effect.gen(function* () {
45
+ const fs = yield* FileSystem.FileSystem;
46
+ const path = yield* Path.Path;
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
+ return { version, build: yield* readBuildInfo(root) };
49
+ });
50
+ const short = (commit) => commit.slice(0, 7);
51
+ /**
52
+ * Whether the code running differs from what is installed (any install: a rebuilt `dist/` or a
53
+ * new version in package.json), and, for a git checkout, whether `dist/` is behind it. Works
54
+ * offline. A build without a stamp (from before stamps, or not built with `pnpm build`) skips the
55
+ * checks that need one.
56
+ */
57
+ export const buildProblem = (install) => Effect.gen(function* () {
58
+ const running = yield* RunningBuild;
59
+ const { root } = yield* PackageInfo;
60
+ const now = yield* installedNow(root);
61
+ if (running.build && now.build && running.build.id !== now.build.id) {
62
+ return {
63
+ kind: 'restart',
64
+ loaded: running.build.builtAt,
65
+ installed: now.build.builtAt,
66
+ };
67
+ }
68
+ if (now.version !== undefined && now.version !== running.version) {
69
+ return { kind: 'restart', loaded: running.version, installed: now.version };
70
+ }
71
+ if (install.kind !== 'git' || now.build?.commit === undefined)
72
+ return undefined;
73
+ const head = yield* gitHead(install.root);
74
+ if (head === undefined || head === now.build.commit)
75
+ return undefined;
76
+ return {
77
+ kind: 'rebuild',
78
+ root: install.root,
79
+ built: short(now.build.commit),
80
+ head: short(head),
81
+ };
82
+ });
@@ -0,0 +1,14 @@
1
+ import { Path } from 'effect';
2
+ import { Command } from 'effect/cli';
3
+ import { ExitCode } from './exit-codes.js';
4
+ import { Operations } from './operations.js';
5
+ declare const ExitWith_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 & {
6
+ readonly _tag: "ExitWith";
7
+ } & Readonly<A>;
8
+ /** Ends the command with this exit code; anything worth saying has already been printed. */
9
+ export declare class ExitWith extends ExitWith_base<{
10
+ readonly code: ExitCode;
11
+ }> {
12
+ }
13
+ export declare const root: Command.Command<"screw-bugs", {}, {}, ExitWith, import("effect/FileSystem").FileSystem | Operations | import("./package-info.js").PackageInfo | Path.Path | import("effect/Stdio").Stdio>;
14
+ export {};
@@ -0,0 +1,308 @@
1
+ import { Console, Data, Effect, Option, Path } from 'effect';
2
+ import { Argument, Command, Flag } from 'effect/cli';
3
+ import { summaryOf } from '../schema/index.js';
4
+ import { renderPrSummary } from '../report/index.js';
5
+ import { readFindingsFile, readSpecFile } from './config.js';
6
+ import { analyticsEnabled, isNonInteractive } from './environment.js';
7
+ import { ExitCode } from './exit-codes.js';
8
+ import { Failure, notImplemented } from './failure.js';
9
+ import { allPassed, formatEvidence, formatFindings, formatLedger, serveMcp } from './mcp.js';
10
+ import { Operations } from './operations.js';
11
+ import { fileUrl, startReportServer } from './report-server.js';
12
+ /** Ends the command with this exit code; anything worth saying has already been printed. */
13
+ export class ExitWith extends Data.TaggedError('ExitWith') {
14
+ }
15
+ const json = Flag.Boolean('json').pipe(Flag.withDescription('Print machine-readable JSON to stdout'), Flag.withDefault(false));
16
+ const printJson = (value) => Console.log(JSON.stringify(value, null, 2));
17
+ /** Prints a failure (to stderr, or as JSON on stdout with --json) and exits with its code. */
18
+ const handle = (asJson) => (effect) => effect.pipe(Effect.catchTag('Failure', (failure) => (asJson
19
+ ? printJson({
20
+ ok: false,
21
+ error: {
22
+ reason: failure.reason,
23
+ message: failure.message,
24
+ exitCode: failure.code,
25
+ ...failure.details,
26
+ },
27
+ })
28
+ : Console.error([`screw-bugs: ${failure.message}`, ...(failure.paths ?? [])].join('\n'))).pipe(Effect.andThen(Effect.fail(new ExitWith({ code: failure.code }))))));
29
+ const usage = (message) => Effect.fail(new Failure({ code: ExitCode.Usage, reason: 'usage', message }));
30
+ const stub = (name, description) => Command.make(name, { json }, (flags) => handle(flags.json)(Effect.fail(notImplemented(name)))).pipe(Command.withDescription(description));
31
+ const formatDoctorHuman = (report) => report.checks
32
+ .flatMap((check) => [
33
+ `${check.ok ? '✓' : check.severity === 'warning' ? '!' : '✗'} ${check.id.padEnd(8)} ${check.detail}`,
34
+ ...(check.fix
35
+ ? [
36
+ ` Fix: ${check.fix.action}`,
37
+ ...(check.fix.command ? [` Run: ${check.fix.command}`] : []),
38
+ ` Why: ${check.fix.why}`,
39
+ ]
40
+ : []),
41
+ ])
42
+ .join('\n');
43
+ const doctor = Command.make('doctor', { json }, (flags) => Effect.gen(function* () {
44
+ const report = yield* (yield* Operations).doctor;
45
+ yield* flags.json ? printJson(report) : Console.log(formatDoctorHuman(report));
46
+ if (!report.ok)
47
+ return yield* new ExitWith({ code: ExitCode.NotReady });
48
+ })).pipe(Command.withDescription('Check that this machine can run screw-bugs. Reports what is missing and how to fix it; installs nothing.'));
49
+ const statusMark = {
50
+ passed: '✓',
51
+ failed: '✗',
52
+ blocked: '!',
53
+ not_verified: '-',
54
+ };
55
+ /** The counts line, then one line per case; reasons only for cases that did not pass. */
56
+ const formatLedgerHuman = (ledger) => [
57
+ formatLedger(ledger),
58
+ ...(ledger.error ? [ledger.error] : []),
59
+ ...ledger.cases.map((c) => `${statusMark[c.status]} ${c.id} ${c.status.replace('_', ' ')}` +
60
+ (c.status !== 'passed' && c.reason ? `: ${c.reason}` : '')),
61
+ ].join('\n');
62
+ const run = Command.make('run', {
63
+ json,
64
+ spec: Flag.String('spec').pipe(Flag.withDescription('JSON file with the job: url, plus optional cases and their steps'), Flag.optional),
65
+ url: Flag.String('url').pipe(Flag.withDescription('URL of the app to test (overrides the URL in --spec)'), Flag.optional),
66
+ device: Flag.ChoiceWithValue('device', [
67
+ ['desktop', 'desktop'],
68
+ ['mobile', 'mobile'],
69
+ ]).pipe(Flag.optional),
70
+ instructions: Flag.String('instructions').pipe(Flag.withDescription("The user's original request in their own words; recorded and shown in the report, never interpreted (overrides instructions in --spec)"), Flag.optional),
71
+ summary: Flag.String('summary').pipe(Flag.withDescription('What these cases test and why, for a human reader; shown at the top of the report, never interpreted (overrides summary in --spec; derived from the case titles when absent)'), Flag.optional),
72
+ }, (flags) => handle(flags.json)(Effect.gen(function* () {
73
+ const ops = yield* Operations;
74
+ const spec = Option.isSome(flags.spec) ? yield* readSpecFile(flags.spec.value) : undefined;
75
+ const { jobId, runDir } = yield* ops.startRun({
76
+ spec,
77
+ url: Option.getOrUndefined(flags.url),
78
+ device: Option.getOrUndefined(flags.device),
79
+ instructions: Option.getOrUndefined(flags.instructions),
80
+ summary: Option.getOrUndefined(flags.summary),
81
+ }, { requireConfig: yield* isNonInteractive });
82
+ if (!flags.json)
83
+ yield* Console.log(`Running job ${jobId}...`);
84
+ const { ledger, reportPath, walkthroughPath } = yield* ops.awaitRun(jobId).pipe(
85
+ // Stops the run here rather than when the engine shuts down, so the message can give
86
+ // the report path once the final report is written.
87
+ Effect.onInterrupt(() => Effect.gen(function* () {
88
+ const stopped = yield* ops.stopRun(jobId).pipe(Effect.option);
89
+ const reportPath = Option.getOrUndefined(stopped)?.reportPath;
90
+ const message = `Interrupted. Job ${jobId} is marked errored and cases it did not finish are not ` +
91
+ `verified; see \`screw-bugs status ${jobId}\`.`;
92
+ yield* flags.json
93
+ ? printJson({
94
+ ok: false,
95
+ jobId,
96
+ runDir,
97
+ reportPath,
98
+ error: { reason: 'interrupted', message, exitCode: ExitCode.Interrupted },
99
+ })
100
+ : Console.error([`screw-bugs: ${message}`, ...(reportPath ? [reportPath] : [])].join('\n'));
101
+ })));
102
+ const passed = allPassed(ledger);
103
+ yield* flags.json
104
+ ? printJson({ ok: passed, jobId, runDir, reportPath, walkthroughPath, ledger })
105
+ : Console.log([
106
+ formatLedgerHuman(ledger),
107
+ runDir,
108
+ reportPath ??
109
+ `report.html could not be written; try \`screw-bugs report ${jobId}\`.`,
110
+ ...(walkthroughPath ? [walkthroughPath] : []),
111
+ ].join('\n'));
112
+ if (!passed)
113
+ return yield* new ExitWith({ code: ExitCode.TestsFailed });
114
+ }))).pipe(Command.withDescription('Run QA cases in a headless browser and wait for the result (exit 1 unless every case passed)'));
115
+ /** Free text on one line, cut to a length that fits a terminal row. */
116
+ const oneLine = (text, max = 100) => {
117
+ const flat = text.replace(/\s+/g, ' ').trim();
118
+ return flat.length <= max ? flat : `${flat.slice(0, max - 1).trimEnd()}…`;
119
+ };
120
+ const status = Command.make('status', { json, jobId: Argument.String('job-id') }, (flags) => handle(flags.json)(Effect.gen(function* () {
121
+ const { ledger, job, runDir, reportPath, walkthroughPath, evidence, evidencePath } = yield* (yield* Operations).runStatus(flags.jobId);
122
+ const { instructions } = job.spec;
123
+ const summary = summaryOf(job.spec);
124
+ yield* flags.json
125
+ ? printJson({
126
+ ok: true,
127
+ summary,
128
+ instructions,
129
+ ledger,
130
+ evidence,
131
+ runDir,
132
+ evidencePath,
133
+ reportPath,
134
+ walkthroughPath,
135
+ })
136
+ : Console.log([
137
+ `Summary: ${oneLine(summary.text)}`,
138
+ ...(instructions?.trim() ? [`Asked: ${oneLine(instructions)}`] : []),
139
+ formatLedger(ledger),
140
+ ...(ledger.error ? [ledger.error] : []),
141
+ ...formatEvidence(ledger, evidence),
142
+ runDir,
143
+ ...(evidencePath ? [evidencePath] : []),
144
+ ...(reportPath ? [reportPath] : []),
145
+ ...(walkthroughPath ? [walkthroughPath] : []),
146
+ ].join('\n'));
147
+ }))).pipe(Command.withDescription('Show the state and case results of a run'));
148
+ const portFlag = Flag.Int('port').pipe(Flag.withDescription("Port for --serve, which fails if it is taken (default: the project's port in 41000-41999, else a free one)"), Flag.optional);
149
+ /**
150
+ * Serves the run folders on 127.0.0.1 (the project's port, see `startReportServer`) and prints
151
+ * the URL of `path`, a page in a run folder; runs until Ctrl+C, unless another screw-bugs process
152
+ * already serves them. `report --serve` and `walkthrough --serve` share it.
153
+ */
154
+ const serve = (path, portOption, asJson) => Effect.gen(function* () {
155
+ const port = Option.getOrUndefined(portOption);
156
+ if (port !== undefined && (!Number.isInteger(port) || port < 0 || port > 65535)) {
157
+ return yield* usage(`--port must be 0-65535, not ${port}.`);
158
+ }
159
+ const paths = yield* Path.Path;
160
+ // The run folder's parent: every run of the project is served, so links between them work.
161
+ const root = paths.dirname(paths.dirname(path));
162
+ return yield* Effect.scoped(Effect.gen(function* () {
163
+ const served = yield* startReportServer(root, { port });
164
+ const { base } = served;
165
+ const reused = served.on === 'reused';
166
+ const url = fileUrl(paths, base, root, path) ?? base;
167
+ yield* asJson
168
+ ? printJson({ url, ok: true, path, reused })
169
+ : Console.log(reused
170
+ ? `${url}\nAnother screw-bugs process already serves ${root} on ${base}; ` +
171
+ 'the link works while it runs.'
172
+ : `${url}\nServing ${root} on ${base} until Ctrl+C.`);
173
+ // Nothing to hold when another process serves the folder.
174
+ if (reused)
175
+ return;
176
+ // Interrupted by Ctrl+C or SIGTERM, which closes the server with the scope.
177
+ return yield* Effect.never;
178
+ }));
179
+ });
180
+ const report = Command.make('report', {
181
+ json,
182
+ jobId: Argument.String('job-id'),
183
+ format: Flag.ChoiceWithValue('format', [
184
+ ['html', 'html'],
185
+ ['markdown', 'markdown'],
186
+ ]).pipe(Flag.withDescription('html prints the path of the report; markdown prints a pull request summary'), Flag.withDefault('html')),
187
+ serve: Flag.Boolean('serve').pipe(Flag.withDescription('Serve the run folders on 127.0.0.1 and print the report URL, for browsers that cannot open files (such as those built into coding tools); runs until Ctrl+C'), Flag.withDefault(false)),
188
+ port: portFlag,
189
+ }, (flags) => handle(flags.json)(Effect.gen(function* () {
190
+ const { path, bundle, walkthroughPath } = yield* (yield* Operations).report(flags.jobId);
191
+ if (flags.serve) {
192
+ if (flags.format === 'markdown') {
193
+ return yield* usage('--serve serves the html report; leave out --format markdown.');
194
+ }
195
+ return yield* serve(path, flags.port, flags.json);
196
+ }
197
+ if (flags.format === 'markdown') {
198
+ const markdown = renderPrSummary(bundle);
199
+ return yield* flags.json
200
+ ? printJson({ ok: true, path, markdown })
201
+ : Console.log(markdown.trimEnd());
202
+ }
203
+ yield* flags.json ? printJson({ ok: true, path, walkthroughPath }) : Console.log(path);
204
+ }))).pipe(Command.withDescription("Write a run's report and print its path, print a Markdown summary for a pull request, or serve it over http with --serve"));
205
+ const walkthrough = Command.make('walkthrough', {
206
+ json,
207
+ jobId: Argument.String('job-id'),
208
+ serve: Flag.Boolean('serve').pipe(Flag.withDescription('Serve the run folders on 127.0.0.1 and print the walkthrough URL, as report --serve does; runs until Ctrl+C'), Flag.withDefault(false)),
209
+ port: portFlag,
210
+ }, (flags) => handle(flags.json)(Effect.gen(function* () {
211
+ const { path, reportPath } = yield* (yield* Operations).walkthrough(flags.jobId);
212
+ if (flags.serve)
213
+ return yield* serve(path, flags.port, flags.json);
214
+ yield* flags.json ? printJson({ ok: true, path, reportPath }) : Console.log(path);
215
+ }))).pipe(Command.withDescription("Write an ended run's walkthrough (its video with every step as a clickable script) with its report and print its path, or serve it over http with --serve"));
216
+ const findings = Command.make('findings', { json, jobId: Argument.String('job-id'), file: Argument.String('file') }, (flags) => handle(flags.json)(Effect.gen(function* () {
217
+ const input = yield* readFindingsFile(flags.file);
218
+ const result = yield* (yield* Operations).submitFindings(flags.jobId, input);
219
+ yield* flags.json
220
+ ? printJson({
221
+ ok: true,
222
+ jobId: result.jobId,
223
+ path: result.path,
224
+ reportPath: result.reportPath,
225
+ walkthroughPath: result.walkthroughPath,
226
+ annotated: result.annotated,
227
+ marks: result.marks,
228
+ })
229
+ : Console.log([
230
+ formatFindings(result),
231
+ result.path,
232
+ ...(result.reportPath ? [result.reportPath] : []),
233
+ ...(result.walkthroughPath ? [result.walkthroughPath] : []),
234
+ ...result.annotated,
235
+ ].join('\n'));
236
+ }))).pipe(Command.withDescription("Submit an agent's write-up of an ended run (a JSON file, or - for standard input); it is checked, saved and shown in the report (exit 6 if it does not fit the run)"));
237
+ const init = Command.make('init', {
238
+ json,
239
+ url: Flag.String('url').pipe(Flag.withDescription('Default URL to test (baseUrl), used when run gets no URL'), Flag.optional),
240
+ force: Flag.Boolean('force').pipe(Flag.withDescription('Overwrite an existing screw-bugs.json'), Flag.withDefault(false)),
241
+ }, (flags) => handle(flags.json)(Effect.gen(function* () {
242
+ const { path } = yield* (yield* Operations).init({
243
+ baseUrl: Option.getOrUndefined(flags.url),
244
+ force: flags.force,
245
+ });
246
+ yield* flags.json ? printJson({ ok: true, path }) : Console.log(`Wrote ${path}`);
247
+ }))).pipe(Command.withDescription('Set up screw-bugs in this project (writes screw-bugs.json)'));
248
+ const runs = Command.make('runs', {
249
+ json,
250
+ limit: Flag.Int('limit').pipe(Flag.withDescription('How many runs to show'), Flag.withDefault(10)),
251
+ }, (flags) => handle(flags.json)(Effect.gen(function* () {
252
+ const list = yield* (yield* Operations).listRuns(flags.limit);
253
+ if (flags.json) {
254
+ return yield* printJson({
255
+ ok: true,
256
+ runs: list.map(({ job, ledger }) => ({
257
+ jobId: job.jobId,
258
+ url: job.spec.url,
259
+ createdAt: job.createdAt,
260
+ state: ledger?.state,
261
+ cases: ledger?.cases.map((c) => ({ id: c.id, status: c.status })),
262
+ })),
263
+ });
264
+ }
265
+ if (list.length === 0)
266
+ return yield* Console.log('No runs yet in this project.');
267
+ yield* Console.log(list
268
+ .map(({ job, ledger }) => {
269
+ const passed = ledger?.cases.filter((c) => c.status === 'passed').length ?? 0;
270
+ const total = ledger?.cases.length ?? 0;
271
+ const state = (ledger?.state ?? 'unknown').replaceAll('_', ' ');
272
+ return `${job.jobId} ${state.padEnd(10)} ${passed}/${total} passed ${job.spec.url}`;
273
+ })
274
+ .join('\n'));
275
+ }))).pipe(Command.withDescription('List recent runs in this project'));
276
+ const answer = Command.make('answer', {
277
+ json,
278
+ jobId: Argument.String('job-id'),
279
+ questionId: Argument.String('question-id'),
280
+ text: Argument.String('answer'),
281
+ }, (flags) => handle(flags.json)(Effect.gen(function* () {
282
+ yield* (yield* Operations).answer(flags);
283
+ yield* flags.json ? printJson({ ok: true }) : Console.log('Answer sent.');
284
+ }))).pipe(Command.withDescription('Answer a question a waiting run has asked'));
285
+ const mcp = Command.make('mcp', {}, () => serveMcp).pipe(Command.withDescription('Serve the screw-bugs MCP server over stdio, for coding agents'));
286
+ const analytics = Command.make('analytics', { json, setting: Argument.String('on|off').pipe(Argument.optional) }, (flags) => handle(flags.json)(Effect.gen(function* () {
287
+ if (Option.isSome(flags.setting))
288
+ return yield* notImplemented(`analytics ${flags.setting.value}`);
289
+ const enabled = yield* analyticsEnabled;
290
+ yield* flags.json
291
+ ? printJson({ ok: true, enabled, envVar: 'SCREW_BUGS_ANALYTICS' })
292
+ : Console.log(`Analytics are ${enabled ? 'on' : 'off'}. They are opt-in: set SCREW_BUGS_ANALYTICS=1 to turn them on. DO_NOT_TRACK=1 always turns them off.`);
293
+ }))).pipe(Command.withDescription('Show whether anonymous usage analytics are on (off by default)'));
294
+ export const root = Command.make('screw-bugs').pipe(Command.withDescription('Local browser QA for coding agents, people and CI.'), Command.withSubcommands([
295
+ doctor,
296
+ run,
297
+ status,
298
+ answer,
299
+ mcp,
300
+ init,
301
+ stub('accounts', 'Manage the test accounts runs can log in with'),
302
+ report,
303
+ walkthrough,
304
+ findings,
305
+ stub('share', 'Share a report through screw-bugs Cloud'),
306
+ runs,
307
+ analytics,
308
+ ]));
@@ -0,0 +1,16 @@
1
+ import { Effect, FileSystem, Path, Stdio } from 'effect';
2
+ import { Failure } from './failure.js';
3
+ export declare const CONFIG_FILE = "screw-bugs.json";
4
+ /** The project config, or undefined when the project has none. Invalid config is an error. */
5
+ export declare const loadConfig: (projectRoot: string) => Effect.Effect<{
6
+ readonly version: 1;
7
+ readonly baseUrl?: string;
8
+ } | undefined, Failure, FileSystem.FileSystem | Path.Path>;
9
+ export declare const missingConfig: (projectRoot: string) => Failure;
10
+ /** Reads a `--spec` file as JSON. Its contents are checked when the run starts. */
11
+ export declare const readSpecFile: (file: string) => Effect.Effect<unknown, Failure, FileSystem.FileSystem>;
12
+ /**
13
+ * Reads a findings file as JSON, or standard input when `file` is `-`. Its contents are checked
14
+ * against the run when they are submitted.
15
+ */
16
+ export declare const readFindingsFile: (file: string) => Effect.Effect<unknown, Failure, FileSystem.FileSystem | Stdio.Stdio>;
@@ -0,0 +1,71 @@
1
+ import { Effect, FileSystem, Path, Schema, SchemaGetter, SchemaIssue, Stdio, Stream } from 'effect';
2
+ import { ProjectConfig } from '../schema/index.js';
3
+ import { ExitCode } from './exit-codes.js';
4
+ import { Failure } from './failure.js';
5
+ export const CONFIG_FILE = 'screw-bugs.json';
6
+ /** The project config, or undefined when the project has none. Invalid config is an error. */
7
+ export const loadConfig = (projectRoot) => Effect.gen(function* () {
8
+ const fs = yield* FileSystem.FileSystem;
9
+ const path = yield* Path.Path;
10
+ const file = path.join(projectRoot, CONFIG_FILE);
11
+ const text = yield* fs.readFileString(file).pipe(Effect.orElseSucceed(() => undefined));
12
+ if (text === undefined)
13
+ return undefined;
14
+ return yield* Schema.decodeUnknownEffect(Schema.fromJsonString(ProjectConfig))(text).pipe(Effect.mapError((error) => new Failure({
15
+ code: ExitCode.Config,
16
+ reason: 'invalid_config',
17
+ message: `${file} is not valid: ${error.message}`,
18
+ })));
19
+ });
20
+ export const missingConfig = (projectRoot) => new Failure({
21
+ code: ExitCode.Config,
22
+ reason: 'missing_config',
23
+ message: `No ${CONFIG_FILE} in ${projectRoot}. Without a terminal (as in CI) screw-bugs never asks ` +
24
+ `questions, so it needs this file: run \`npx screw-bugs init\` on your machine and commit it.`,
25
+ });
26
+ /**
27
+ * Any JSON text. Like `Schema.fromJsonString(Schema.Unknown)`, except that a parse error keeps the
28
+ * parser's own message, which tells the user where their file breaks.
29
+ */
30
+ const JsonText = Schema.String.pipe(Schema.decodeTo(Schema.Unknown, {
31
+ decode: SchemaGetter.transformEffect((text) => Effect.try({
32
+ // Boundary: inside a Schema getter, only to keep the parser's message (see above).
33
+ try: () => JSON.parse(text),
34
+ catch: (error) => new SchemaIssue.InvalidValue({ message: error instanceof Error ? error.message : String(error) }, text),
35
+ })),
36
+ encode: SchemaGetter.stringifyJson(),
37
+ }));
38
+ /** Reads a `--spec` file as JSON. Its contents are checked when the run starts. */
39
+ export const readSpecFile = (file) => Effect.gen(function* () {
40
+ const fs = yield* FileSystem.FileSystem;
41
+ const text = yield* fs.readFileString(file).pipe(Effect.mapError(() => new Failure({
42
+ code: ExitCode.Usage,
43
+ reason: 'spec_not_found',
44
+ message: `Could not read the job spec ${file}.`,
45
+ })));
46
+ return yield* Schema.decodeUnknownEffect(JsonText)(text).pipe(Effect.mapError((error) => new Failure({
47
+ code: ExitCode.Usage,
48
+ reason: 'invalid_job',
49
+ message: `${file} is not valid JSON: ${error.message}`,
50
+ })));
51
+ });
52
+ /**
53
+ * Reads a findings file as JSON, or standard input when `file` is `-`. Its contents are checked
54
+ * against the run when they are submitted.
55
+ */
56
+ export const readFindingsFile = (file) => Effect.gen(function* () {
57
+ const source = file === '-' ? 'standard input' : file;
58
+ const unreadable = () => new Failure({
59
+ code: ExitCode.Usage,
60
+ reason: 'findings_not_found',
61
+ message: `Could not read the findings from ${source}.`,
62
+ });
63
+ const text = file === '-'
64
+ ? yield* Stdio.Stdio.use((stdio) => stdio.stdin.pipe(Stream.decodeText(), Stream.mkString)).pipe(Effect.mapError(unreadable))
65
+ : yield* FileSystem.FileSystem.use((fs) => fs.readFileString(file)).pipe(Effect.mapError(unreadable));
66
+ return yield* Schema.decodeUnknownEffect(JsonText)(text).pipe(Effect.mapError((error) => new Failure({
67
+ code: ExitCode.InvalidFindings,
68
+ reason: 'invalid_findings',
69
+ message: `The findings in ${source} are not valid JSON: ${error.message}`,
70
+ })));
71
+ });