screw-bugs 0.1.8 → 0.1.10

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 (107) hide show
  1. package/README.md +49 -34
  2. package/dist/browser-playwright/capture.js +1 -1
  3. package/dist/browser-playwright/launch.js +27 -10
  4. package/dist/browser-playwright/page.d.ts +48 -26
  5. package/dist/browser-playwright/page.js +86 -89
  6. package/dist/browser-playwright/recorder.d.ts +154 -0
  7. package/dist/browser-playwright/recorder.js +382 -0
  8. package/dist/build-info.json +3 -3
  9. package/dist/cli/app.js +6 -2
  10. package/dist/cli/commands.js +4 -3
  11. package/dist/cli/doctor.d.ts +17 -2
  12. package/dist/cli/doctor.js +62 -4
  13. package/dist/cli/mcp.js +2 -2
  14. package/dist/cli/report-server.d.ts +19 -10
  15. package/dist/cli/report-server.js +43 -18
  16. package/dist/cli/share.js +2 -2
  17. package/dist/cli/sign-in.d.ts +9 -3
  18. package/dist/cli/sign-in.js +12 -9
  19. package/dist/cli/tailnet.d.ts +57 -0
  20. package/dist/cli/tailnet.js +82 -0
  21. package/dist/core/index.d.ts +1 -14
  22. package/dist/core/index.js +3 -14
  23. package/dist/report/index.d.ts +1 -10
  24. package/dist/report/index.js +3 -10
  25. package/dist/schema/index.d.ts +1 -9
  26. package/dist/schema/index.js +3 -9
  27. package/package.json +14 -14
  28. package/dist/core/accounts.d.ts +0 -40
  29. package/dist/core/accounts.js +0 -95
  30. package/dist/core/css.d.ts +0 -95
  31. package/dist/core/css.js +0 -436
  32. package/dist/core/engine.d.ts +0 -75
  33. package/dist/core/engine.js +0 -554
  34. package/dist/core/errors.d.ts +0 -85
  35. package/dist/core/errors.js +0 -36
  36. package/dist/core/evidence.d.ts +0 -14
  37. package/dist/core/evidence.js +0 -131
  38. package/dist/core/labels.d.ts +0 -47
  39. package/dist/core/labels.js +0 -199
  40. package/dist/core/liveness.d.ts +0 -45
  41. package/dist/core/liveness.js +0 -66
  42. package/dist/core/marks.d.ts +0 -63
  43. package/dist/core/marks.js +0 -410
  44. package/dist/core/services.d.ts +0 -574
  45. package/dist/core/services.js +0 -25
  46. package/dist/core/share.d.ts +0 -68
  47. package/dist/core/share.js +0 -318
  48. package/dist/core/steps.d.ts +0 -106
  49. package/dist/core/steps.js +0 -722
  50. package/dist/core/uploads.d.ts +0 -49
  51. package/dist/core/uploads.js +0 -133
  52. package/dist/core/video.d.ts +0 -47
  53. package/dist/core/video.js +0 -233
  54. package/dist/core/viewport.d.ts +0 -28
  55. package/dist/core/viewport.js +0 -50
  56. package/dist/report/assets.d.ts +0 -34
  57. package/dist/report/assets.js +0 -105
  58. package/dist/report/bug.d.ts +0 -11
  59. package/dist/report/bug.js +0 -20
  60. package/dist/report/html.d.ts +0 -47
  61. package/dist/report/html.js +0 -923
  62. package/dist/report/icons.d.ts +0 -51
  63. package/dist/report/icons.js +0 -93
  64. package/dist/report/live.d.ts +0 -7
  65. package/dist/report/live.js +0 -135
  66. package/dist/report/logos.d.ts +0 -4
  67. package/dist/report/logos.js +0 -19
  68. package/dist/report/markup.d.ts +0 -50
  69. package/dist/report/markup.js +0 -156
  70. package/dist/report/menu-bar.d.ts +0 -60
  71. package/dist/report/menu-bar.js +0 -157
  72. package/dist/report/player.d.ts +0 -102
  73. package/dist/report/player.js +0 -315
  74. package/dist/report/pr-summary.d.ts +0 -11
  75. package/dist/report/pr-summary.js +0 -119
  76. package/dist/report/sha256.d.ts +0 -9
  77. package/dist/report/sha256.js +0 -97
  78. package/dist/report/share-page.d.ts +0 -48
  79. package/dist/report/share-page.js +0 -291
  80. package/dist/report/shots.d.ts +0 -59
  81. package/dist/report/shots.js +0 -280
  82. package/dist/report/sign-in.d.ts +0 -41
  83. package/dist/report/sign-in.js +0 -568
  84. package/dist/report/styles.d.ts +0 -3
  85. package/dist/report/styles.js +0 -274
  86. package/dist/report/view.d.ts +0 -296
  87. package/dist/report/view.js +0 -702
  88. package/dist/report/walkthrough.d.ts +0 -93
  89. package/dist/report/walkthrough.js +0 -716
  90. package/dist/schema/accounts.d.ts +0 -137
  91. package/dist/schema/accounts.js +0 -121
  92. package/dist/schema/config.d.ts +0 -7
  93. package/dist/schema/config.js +0 -6
  94. package/dist/schema/doctor.d.ts +0 -46
  95. package/dist/schema/doctor.js +0 -30
  96. package/dist/schema/evidence.d.ts +0 -1115
  97. package/dist/schema/evidence.js +0 -565
  98. package/dist/schema/findings.d.ts +0 -161
  99. package/dist/schema/findings.js +0 -82
  100. package/dist/schema/job.d.ts +0 -1905
  101. package/dist/schema/job.js +0 -577
  102. package/dist/schema/ledger.d.ts +0 -1124
  103. package/dist/schema/ledger.js +0 -285
  104. package/dist/schema/share.d.ts +0 -55
  105. package/dist/schema/share.js +0 -64
  106. package/dist/schema/status.d.ts +0 -7
  107. package/dist/schema/status.js +0 -11
@@ -1,11 +1,13 @@
1
1
  // Boundary: Effect's FileSystem has no statfs, so free disk space is read with node:fs.
2
2
  import { statfs } from 'node:fs/promises';
3
- import { Effect, Option } from 'effect';
3
+ import { Config, Effect, Option } from 'effect';
4
4
  import { ffmpegProblem, findFfmpeg, installBrowserCommand, installFfmpegCommand, } from '../browser-playwright/index.js';
5
5
  import { Browser } from '../core/index.js';
6
6
  import { describeBuild, RunningBuild } from './build-info.js';
7
7
  import { isAtLeast, minimumNode } from './node-version.js';
8
8
  import { PackageInfo } from './package-info.js';
9
+ import { isCi } from './environment.js';
10
+ import { TAILNET, Tailnet } from './tailnet.js';
9
11
  /** Room for a few runs' screenshots, traces and videos. */
10
12
  export const MIN_FREE_BYTES = 1024 ** 3;
11
13
  const browserNames = {
@@ -90,6 +92,59 @@ export const checkDisk = (path, freeBytes) => {
90
92
  },
91
93
  };
92
94
  };
95
+ const REPORT_VARIABLE = 'SCREW_BUGS_REPORT_HOST';
96
+ const SIGN_IN_VARIABLE = 'SCREW_BUGS_SIGN_IN_HOST';
97
+ /**
98
+ * Tailscale and the host settings, a warning at most; none when Tailscale is not running and no
99
+ * setting is `tailnet`, or when the report host is set otherwise. With nothing set and Tailscale running,
100
+ * reports and sign-ins are on the tailnet by default: it passes, saying so and how to turn it off.
101
+ */
102
+ export const checkTailnet = (status, settings, ci = false) => {
103
+ const isTailnet = (value) => value.toLowerCase() === TAILNET;
104
+ const tailnetVariable = isTailnet(settings.report)
105
+ ? REPORT_VARIABLE
106
+ : isTailnet(settings.signIn)
107
+ ? SIGN_IN_VARIABLE
108
+ : undefined;
109
+ if (tailnetVariable !== undefined)
110
+ return status.running
111
+ ? {
112
+ id: 'tailnet',
113
+ ok: true,
114
+ detail: `${tailnetVariable} is ${TAILNET}: served at ${status.host} on the tailnet`,
115
+ }
116
+ : {
117
+ id: 'tailnet',
118
+ ok: false,
119
+ severity: 'warning',
120
+ detail: `${tailnetVariable} is ${TAILNET}, but ${status.why} (when screw-bugs started), ` +
121
+ 'so its pages are served on 127.0.0.1 only.',
122
+ fix: {
123
+ action: 'Start Tailscale with the command, then restart the MCP server.',
124
+ command: 'tailscale up',
125
+ why: 'Reports and sign-ins open from your other devices only while Tailscale runs.',
126
+ },
127
+ };
128
+ // Unset, the report host is the tailnet; the sign-in host follows it unless set otherwise.
129
+ if (ci || !status.running || settings.report !== '')
130
+ return undefined;
131
+ const what = settings.signIn === '' ? 'reports and sign-ins are' : 'reports are';
132
+ return {
133
+ id: 'tailnet',
134
+ ok: true,
135
+ detail: `Tailscale is running, so ${what} served at ${status.host} on the tailnet, for every ` +
136
+ `device on it; to keep them on this machine only, set ${REPORT_VARIABLE}=127.0.0.1.`,
137
+ };
138
+ };
139
+ const readSetting = (name) => Config.String(name).pipe(Config.withDefault(''), Effect.orDie, Effect.map((v) => v.trim()));
140
+ /** `checkTailnet` for this process: its tailnet lookup and environment. */
141
+ export const tailnetCheck = Effect.gen(function* () {
142
+ const tailnet = yield* Tailnet;
143
+ const status = yield* tailnet.status;
144
+ const report = yield* readSetting(REPORT_VARIABLE);
145
+ const signIn = yield* readSetting(SIGN_IN_VARIABLE);
146
+ return checkTailnet(status, { report, signIn }, yield* isCi);
147
+ });
93
148
  const formatGb = (bytes) => `${(bytes / 1024 ** 3).toFixed(1)} GB`;
94
149
  /** The statfs boundary: the only Node file system call left (see the import). */
95
150
  const freeBytes = (path) => Effect.tryPromise(() => statfs(path)).pipe(Effect.map((stats) => stats.bavail * stats.bsize), Effect.orElseSucceed(() => undefined));
@@ -97,8 +152,9 @@ const freeBytes = (path) => Effect.tryPromise(() => statfs(path)).pipe(Effect.ma
97
152
  const passes = (check) => check.ok || check.severity === 'warning';
98
153
  /**
99
154
  * Checks the machine without changing it: nothing is installed or downloaded. `lookupFfmpeg` is
100
- * replaceable so tests need not depend on this machine's Playwright cache. `update` is the check
101
- * for a newer or stale screw-bugs (see `UpdateCheck`), last when given; a warning at most.
155
+ * replaceable so tests need not depend on this machine's Playwright cache. `tailnet` (see
156
+ * `checkTailnet`) comes when there is something to say about Tailscale. `update` is the check for
157
+ * a newer or stale screw-bugs (see `UpdateCheck`), last when given; a warning at most.
102
158
  */
103
159
  export const runDoctor = (projectRoot, lookupFfmpeg = findFfmpeg, update) => Effect.gen(function* () {
104
160
  const browser = yield* Browser;
@@ -106,11 +162,12 @@ export const runDoctor = (projectRoot, lookupFfmpeg = findFfmpeg, update) => Eff
106
162
  // What this process loaded when it started (an MCP server may run an older build than is on
107
163
  // disk now); without the service, the version alone.
108
164
  const running = yield* Effect.serviceOption(RunningBuild);
109
- const [found, ffmpeg, free, updateCheck] = yield* Effect.all([
165
+ const [found, ffmpeg, free, updateCheck, tailnet] = yield* Effect.all([
110
166
  browser.detect.pipe(Effect.orElseSucceed(() => undefined)),
111
167
  lookupFfmpeg,
112
168
  freeBytes(projectRoot),
113
169
  update ?? Effect.succeed(undefined),
170
+ tailnetCheck,
114
171
  ], { concurrency: 'unbounded' });
115
172
  const installCommand = found ? '' : yield* installBrowserCommand;
116
173
  const ffmpegCommand = ffmpeg.found ? '' : yield* installFfmpegCommand;
@@ -121,6 +178,7 @@ export const runDoctor = (projectRoot, lookupFfmpeg = findFfmpeg, update) => Eff
121
178
  checkBrowser(found, installCommand),
122
179
  checkVideo(ffmpeg, ffmpegCommand),
123
180
  checkDisk(projectRoot, free),
181
+ ...(tailnet ? [tailnet] : []),
124
182
  ...(updateCheck ? [updateCheck] : []),
125
183
  ];
126
184
  return { ok: checks.every(passes), checks };
package/dist/cli/mcp.js CHANGED
@@ -19,8 +19,8 @@ import { UpdateCheck } from './update-check.js';
19
19
  * account has no session to start from starts nothing either: one sentence, then the link of the
20
20
  * sign-in it opened for the user, then `accounts.json`; with `waitSeconds` it first waits for the
21
21
  * user to save that sign-in, then starts the run (a normal reply), or says it was cancelled.
22
- * Wherever the report is given, it is its http://127.0.0.1 URL (or `SCREW_BUGS_REPORT_HOST`'s, see
23
- * `ReportServer`) in place of
22
+ * Wherever the report is given, it is its URL on the report server (127.0.0.1, the tailnet or
23
+ * `SCREW_BUGS_REPORT_HOST`'s host, see `reportHost`) in place of
24
24
  * its path, for browsers built into coding tools, which cannot open file:// pages and whose file
25
25
  * viewers do not play its video; the path only when there is no URL. Then the run's walkthrough
26
26
  * (`walkthrough.html`), when it has one, the same way, and the reply's sentence names it as the
@@ -4,8 +4,8 @@ import { type ShareRoutes } from './share.js';
4
4
  import { Failure } from './failure.js';
5
5
  /**
6
6
  * A local HTTP server for reports, for browsers that cannot open `file://` (the ones built into
7
- * coding tools). It binds one address, 127.0.0.1 unless `SCREW_BUGS_REPORT_HOST` says another
8
- * (see `reportHost`), and serves the runs folder read-only: only files with
7
+ * coding tools). It binds one address: `SCREW_BUGS_REPORT_HOST`'s, or unset this machine's on
8
+ * the tailnet when Tailscale runs, else 127.0.0.1 (see `reportHost`), and serves the runs folder read-only: only files with
9
9
  * the extensions a report uses, never a directory listing, a dotfile, or anything outside the
10
10
  * folder (also through symlinks). Range requests (206, 416) come from `HttpStaticServer`, so
11
11
  * videos seek and play. In a process that can share (see `ShareSource`), it also answers the
@@ -18,18 +18,27 @@ export declare const isLoopback: (host: string) => boolean;
18
18
  /** A host as it goes in a URL: an IPv6 address in brackets. */
19
19
  export declare const urlHost: (host: string) => string;
20
20
  /**
21
- * `SCREW_BUGS_REPORT_HOST`: where the report server listens, and the host in its links. 127.0.0.1
22
- * unless set; set it to this machine's MagicDNS name or tailnet IP to open reports from another
23
- * device (a name binds the one address it resolves to). Never every interface: `0.0.0.0` or `::`
24
- * is a `Failure` (an empty value is unset).
21
+ * `SCREW_BUGS_REPORT_HOST`: where the report server listens, and the host in its links. Unset,
22
+ * this machine's name on the tailnet when Tailscale is running (see `Tailnet`; never in CI), else
23
+ * 127.0.0.1; `127.0.0.1` keeps reports on this machine. A MagicDNS name, tailnet IP or `tailnet`
24
+ * opens reports from another device (a name binds the one address it resolves to). Never every
25
+ * interface: `0.0.0.0` or `::` is a `Failure` (an empty value is unset).
25
26
  */
26
27
  export declare const reportHost: Effect.Effect<string, Failure, never>;
27
28
  /**
28
29
  * A server's host setting (`SCREW_BUGS_REPORT_HOST`, `SCREW_BUGS_SIGN_IN_HOST`): one address or
29
- * name of this machine, canonical (`canonicalHost`); 127.0.0.1 when unset or empty. Every
30
- * spelling of every interface (`0.0.0.0`, `0`, `::`, …) is a `Failure` with `reason`.
31
- */
32
- export declare const hostSetting: (variable: string, reason: string) => Effect.Effect<string, Failure, never>;
30
+ * name of this machine, canonical (`canonicalHost`). When `variable` is unset or empty,
31
+ * `follows` (another variable) is read in its place. Unset or empty, and `tailnet` (any case), are
32
+ * this machine's host on the tailnet, or 127.0.0.1 when Tailscale is not running (see `Tailnet`;
33
+ * only `tailnet` says so on stderr); unset is 127.0.0.1 in CI. Every spelling of every interface (`0.0.0.0`, `0`, `::`, …) is a `Failure` with
34
+ * `reason`.
35
+ */
36
+ export declare const hostSetting: (variable: string, reason: string, follows?: string) => Effect.Effect<string, Failure, never>;
37
+ /** `hostSetting`, with the variable it was read from (`variable`, or `follows` in its place). */
38
+ export declare const hostSettingOf: (variable: string, reason: string, follows?: string) => Effect.Effect<{
39
+ host: string;
40
+ variable: string;
41
+ }, Failure, never>;
33
42
  /**
34
43
  * The address a server set to `host` (from `variable`) listens on, as a URL writes it without
35
44
  * brackets; a `Failure` with `reason` when that is every interface (a name that resolved to an
@@ -9,10 +9,12 @@ import { runsDir } from '../store-local/index.js';
9
9
  import { ExitCode } from './exit-codes.js';
10
10
  import { makeShareRoutes, ShareSource } from './share.js';
11
11
  import { Failure } from './failure.js';
12
+ import { isCi } from './environment.js';
13
+ import { TAILNET, Tailnet } from './tailnet.js';
12
14
  /**
13
15
  * A local HTTP server for reports, for browsers that cannot open `file://` (the ones built into
14
- * coding tools). It binds one address, 127.0.0.1 unless `SCREW_BUGS_REPORT_HOST` says another
15
- * (see `reportHost`), and serves the runs folder read-only: only files with
16
+ * coding tools). It binds one address: `SCREW_BUGS_REPORT_HOST`'s, or unset this machine's on
17
+ * the tailnet when Tailscale runs, else 127.0.0.1 (see `reportHost`), and serves the runs folder read-only: only files with
16
18
  * the extensions a report uses, never a directory listing, a dotfile, or anything outside the
17
19
  * folder (also through symlinks). Range requests (206, 416) come from `HttpStaticServer`, so
18
20
  * videos seek and play. In a process that can share (see `ShareSource`), it also answers the
@@ -28,29 +30,52 @@ const unbracketed = (host) => host.replace(/^\[(.*)\]$/, '$1');
28
30
  /** A host as it goes in a URL: an IPv6 address in brackets. */
29
31
  export const urlHost = (host) => (host.includes(':') ? `[${host}]` : host);
30
32
  /**
31
- * `SCREW_BUGS_REPORT_HOST`: where the report server listens, and the host in its links. 127.0.0.1
32
- * unless set; set it to this machine's MagicDNS name or tailnet IP to open reports from another
33
- * device (a name binds the one address it resolves to). Never every interface: `0.0.0.0` or `::`
34
- * is a `Failure` (an empty value is unset).
33
+ * `SCREW_BUGS_REPORT_HOST`: where the report server listens, and the host in its links. Unset,
34
+ * this machine's name on the tailnet when Tailscale is running (see `Tailnet`; never in CI), else
35
+ * 127.0.0.1; `127.0.0.1` keeps reports on this machine. A MagicDNS name, tailnet IP or `tailnet`
36
+ * opens reports from another device (a name binds the one address it resolves to). Never every
37
+ * interface: `0.0.0.0` or `::` is a `Failure` (an empty value is unset).
35
38
  */
36
39
  export const reportHost = Effect.suspend(() => hostSetting('SCREW_BUGS_REPORT_HOST', 'report_host'));
37
40
  /**
38
41
  * A server's host setting (`SCREW_BUGS_REPORT_HOST`, `SCREW_BUGS_SIGN_IN_HOST`): one address or
39
- * name of this machine, canonical (`canonicalHost`); 127.0.0.1 when unset or empty. Every
40
- * spelling of every interface (`0.0.0.0`, `0`, `::`, …) is a `Failure` with `reason`.
42
+ * name of this machine, canonical (`canonicalHost`). When `variable` is unset or empty,
43
+ * `follows` (another variable) is read in its place. Unset or empty, and `tailnet` (any case), are
44
+ * this machine's host on the tailnet, or 127.0.0.1 when Tailscale is not running (see `Tailnet`;
45
+ * only `tailnet` says so on stderr); unset is 127.0.0.1 in CI. Every spelling of every interface (`0.0.0.0`, `0`, `::`, …) is a `Failure` with
46
+ * `reason`.
41
47
  */
42
- export const hostSetting = (variable, reason) => Config.String(variable).pipe(Config.withDefault(REPORT_HOST), Effect.orDie, Effect.flatMap((value) => {
43
- const trimmed = value.trim();
44
- const host = trimmed === '' ? REPORT_HOST : canonicalHost(unbracketed(trimmed));
45
- return host === undefined || isUnspecified(host)
46
- ? Effect.fail(new Failure({
48
+ export const hostSetting = (variable, reason, follows) => hostSettingOf(variable, reason, follows).pipe(Effect.map(({ host }) => host));
49
+ /** `hostSetting`, with the variable it was read from (`variable`, or `follows` in its place). */
50
+ export const hostSettingOf = (variable, reason, follows) => Effect.gen(function* () {
51
+ const read = (name) => Config.String(name).pipe(Config.withDefault(''), Effect.orDie, Effect.map((v) => v.trim()));
52
+ let from = variable;
53
+ let value = yield* read(variable);
54
+ if (value === '' && follows !== undefined) {
55
+ from = follows;
56
+ value = yield* read(follows);
57
+ }
58
+ // Unset: on the tailnet when Tailscale is running (never in CI), else 127.0.0.1, silently.
59
+ if (value === '') {
60
+ if (yield* isCi)
61
+ return { host: REPORT_HOST, variable: from };
62
+ const status = yield* (yield* Tailnet).status;
63
+ return { host: status.running ? status.host : REPORT_HOST, variable: from };
64
+ }
65
+ if (value.toLowerCase() === TAILNET) {
66
+ const tailnet = yield* Tailnet;
67
+ return { host: (yield* tailnet.host) ?? REPORT_HOST, variable: from };
68
+ }
69
+ const host = canonicalHost(unbracketed(value));
70
+ if (host === undefined || isUnspecified(host))
71
+ return yield* new Failure({
47
72
  code: ExitCode.Usage,
48
73
  reason,
49
- message: `${variable} is "${value}"; give one address or name of this machine, ` +
50
- 'such as its MagicDNS name or tailnet IP, or leave it unset for 127.0.0.1.',
51
- }))
52
- : Effect.succeed(host);
53
- }));
74
+ message: `${from} is "${value}"; give one address or name of this machine, ` +
75
+ `such as its MagicDNS name or tailnet IP, or "${TAILNET}", or 127.0.0.1 for this machine only.`,
76
+ });
77
+ return { host, variable: from };
78
+ });
54
79
  /**
55
80
  * The address a server set to `host` (from `variable`) listens on, as a URL writes it without
56
81
  * brackets; a `Failure` with `reason` when that is every interface (a name that resolved to an
package/dist/cli/share.js CHANGED
@@ -7,7 +7,7 @@ import { base64, hex, renderSharePage, SHARE_START_PATH, sha256, sharePageCsp, }
7
7
  import { CompletedShare, CreatedShare, JobId, ShareCallback, ShareClaimed, ShareErrorReply, ShareRequestCreated, ShareState, } from '../schema/index.js';
8
8
  /*
9
9
  * The Share button's local side: routes of the report server that put a run on screw-bugs Cloud,
10
- * following Cloud's upload protocol (see `src/schema/share.ts`). Only a person can share: it
10
+ * following Cloud's upload protocol (see `packages/core/src/schema/share.ts`). Only a person can share: it
11
11
  * takes a click in a report this server served, and a confirmation on Cloud.
12
12
  *
13
13
  * start the report's Share button: remembers a random `state` for the run, and sends the
@@ -764,7 +764,7 @@ export const makeShareRoutes = (root) => Effect.gen(function* () {
764
764
  const phase = entry.phase;
765
765
  switch (phase._tag) {
766
766
  case 'pairing':
767
- return sharePage('Type this code on Screw Bugs Cloud', 'Open Screw Bugs Cloud, sign in, and type this code to share the report. This page moves on by itself once you confirm there.', {
767
+ return sharePage('Enter this code on Screw Bugs Cloud', 'Open Screw Bugs Cloud (that copies this code), sign in, and paste the code there to share the report. This page moves on by itself once you confirm there.', {
768
768
  code: phase.code,
769
769
  link: { href: phase.confirmUrl, text: 'Open Screw Bugs Cloud' },
770
770
  refresh: PAIRING_REFRESH_S,
@@ -9,10 +9,16 @@ export declare const FRAME_WAIT_MS = 15000;
9
9
  /** How long fetching the app's icon may take in all; the sign-in opens without it after. */
10
10
  export declare const SIGN_IN_ICON_TIMEOUT: Duration.Duration;
11
11
  /**
12
- * `SCREW_BUGS_SIGN_IN_HOST`: where the sign-in server listens, and the host in its link.
13
- * 127.0.0.1 unless set; set it to this machine's MagicDNS name or tailnet IP to sign in from
14
- * another device. Read as `SCREW_BUGS_REPORT_HOST` is (`hostSetting`): never every interface.
12
+ * `SCREW_BUGS_SIGN_IN_HOST`: where the sign-in server listens, and the host in its link. When
13
+ * unset, `SCREW_BUGS_REPORT_HOST`'s value (so one variable covers both); with both unset, this
14
+ * machine's tailnet host when Tailscale runs (not in CI), else 127.0.0.1. Set it to `127.0.0.1` to
15
+ * keep sign-ins on this machine, or to a MagicDNS name, tailnet IP or `tailnet`. Read as `SCREW_BUGS_REPORT_HOST` is (`hostSetting`): never every interface.
15
16
  */
17
+ export declare const signInHostOf: Effect.Effect<{
18
+ host: string;
19
+ variable: string;
20
+ }, Failure, never>;
21
+ /** The host of `signInHostOf` alone. */
16
22
  export declare const signInHost: Effect.Effect<string, Failure, never>;
17
23
  /** How a sign-in ended. */
18
24
  export type SignInOutcome = 'saved' | 'cancelled' | 'idle';
@@ -10,12 +10,12 @@ import { hex, renderSignInPage, SIGN_IN_CSP } from '../report/index.js';
10
10
  import { SignInInputs } from '../schema/index.js';
11
11
  import { ExitCode } from './exit-codes.js';
12
12
  import { Failure } from './failure.js';
13
- import { boundAddress, hostSetting, isLoopback, urlHost } from './report-server.js';
13
+ import { boundAddress, hostSettingOf, isLoopback, urlHost } from './report-server.js';
14
14
  /*
15
15
  * Signing in to a test account: a headless browser at the app, which a person drives from a web
16
16
  * page (the live view, `renderSignInPage`) in whatever browser reaches this machine: the one built
17
17
  * into their coding tool, or a phone on their tailnet. Each sign-in gets a server of its own on a
18
- * free port, bound to `SCREW_BUGS_SIGN_IN_HOST` (127.0.0.1 unless set), answering only under a
18
+ * free port, bound to `SCREW_BUGS_SIGN_IN_HOST` (else `SCREW_BUGS_REPORT_HOST`'s host, see `hostSetting`), answering only under a
19
19
  * random token and only to its own Host; it ends when the person saves or cancels, after
20
20
  * `SIGN_IN_IDLE` without a request, or with the process. Only the session is kept: the cookies
21
21
  * the browser sends to the app and its origin's storage, in the account book. Nothing typed is
@@ -30,11 +30,14 @@ export const SIGN_IN_ICON_TIMEOUT = Duration.seconds(3);
30
30
  /** The largest input request taken: a few hundred inputs. */
31
31
  const INPUT_BYTES_MAX = 256 * 1024;
32
32
  /**
33
- * `SCREW_BUGS_SIGN_IN_HOST`: where the sign-in server listens, and the host in its link.
34
- * 127.0.0.1 unless set; set it to this machine's MagicDNS name or tailnet IP to sign in from
35
- * another device. Read as `SCREW_BUGS_REPORT_HOST` is (`hostSetting`): never every interface.
33
+ * `SCREW_BUGS_SIGN_IN_HOST`: where the sign-in server listens, and the host in its link. When
34
+ * unset, `SCREW_BUGS_REPORT_HOST`'s value (so one variable covers both); with both unset, this
35
+ * machine's tailnet host when Tailscale runs (not in CI), else 127.0.0.1. Set it to `127.0.0.1` to
36
+ * keep sign-ins on this machine, or to a MagicDNS name, tailnet IP or `tailnet`. Read as `SCREW_BUGS_REPORT_HOST` is (`hostSetting`): never every interface.
36
37
  */
37
- export const signInHost = Effect.suspend(() => hostSetting('SCREW_BUGS_SIGN_IN_HOST', 'sign_in_host'));
38
+ export const signInHostOf = Effect.suspend(() => hostSettingOf('SCREW_BUGS_SIGN_IN_HOST', 'sign_in_host', 'SCREW_BUGS_REPORT_HOST'));
39
+ /** The host of `signInHostOf` alone. */
40
+ export const signInHost = signInHostOf.pipe(Effect.map(({ host }) => host));
38
41
  /** The handle for an open sign-in. */
39
42
  const handleOf = (entry) => ({
40
43
  link: entry.link,
@@ -210,7 +213,7 @@ export class SignIns extends Context.Service()('screw-bugs/SignIns') {
210
213
  const lock = yield* Semaphore.make(1);
211
214
  const pending = new Map();
212
215
  const open = (request) => Effect.gen(function* () {
213
- const host = yield* signInHost;
216
+ const { host, variable } = yield* signInHostOf;
214
217
  const own = yield* Scope.fork(scope);
215
218
  const opened = yield* Effect.gen(function* () {
216
219
  const live = yield* browser.signIn(request.url).pipe(Effect.mapError((error) => new Failure({
@@ -256,12 +259,12 @@ export class SignIns extends Context.Service()('screw-bugs/SignIns') {
256
259
  const server = yield* NodeHttpServer.make(() => createServer(), { port: 0, host }).pipe(Effect.mapError((error) => new Failure({
257
260
  code: ExitCode.Usage,
258
261
  reason: 'sign_in_serve',
259
- message: `Could not serve the sign-in page on ${host} (check SCREW_BUGS_SIGN_IN_HOST): ` +
262
+ message: `Could not serve the sign-in page on ${host} (check ${variable}): ` +
260
263
  String(error.cause),
261
264
  })));
262
265
  if ('port' in server.address)
263
266
  port = server.address.port;
264
- const bound = yield* boundAddress(server.address, host, 'SCREW_BUGS_SIGN_IN_HOST', 'sign_in_host');
267
+ const bound = yield* boundAddress(server.address, host, variable, 'sign_in_host');
265
268
  // The host it was set to, and the address that is (a name's IP): both can be opened.
266
269
  hosts.add(`${urlHost(host)}:${port}`);
267
270
  hosts.add(`${urlHost(bound)}:${port}`);
@@ -0,0 +1,57 @@
1
+ import { Context, Duration, Effect, Layer, Schema } from 'effect';
2
+ import { ChildProcessSpawner } from 'effect/process';
3
+ /**
4
+ * Tailscale, for the host settings (`SCREW_BUGS_REPORT_HOST`) when unset or `tailnet`: this
5
+ * machine's MagicDNS name (its tailnet IPv4 when MagicDNS is off), read from `tailscale status
6
+ * --json` once per process. Unset, reports and sign-ins go there whenever Tailscale is running
7
+ * (not in CI); `SCREW_BUGS_REPORT_HOST=127.0.0.1` keeps them on this machine, and doctor says so
8
+ * (see `checkTailnet`).
9
+ */
10
+ /** The value of a host setting that means "this machine's name on the tailnet". */
11
+ export declare const TAILNET = "tailnet";
12
+ /** The few fields of `tailscale status --json` screw-bugs reads; the rest is ignored. */
13
+ export declare const TailscaleStatus: Schema.Struct<{
14
+ readonly BackendState: Schema.String;
15
+ readonly Self: Schema.optionalKey<Schema.NullOr<Schema.Struct<{
16
+ readonly DNSName: Schema.optionalKey<Schema.String>;
17
+ readonly TailscaleIPs: Schema.optionalKey<Schema.NullOr<Schema.$Array<Schema.String>>>;
18
+ }>>>;
19
+ readonly CurrentTailnet: Schema.optionalKey<Schema.NullOr<Schema.Struct<{
20
+ readonly MagicDNSEnabled: Schema.optionalKey<Schema.Boolean>;
21
+ }>>>;
22
+ }>;
23
+ export type TailscaleStatus = typeof TailscaleStatus.Type;
24
+ /** What the lookup found: this machine's host on the tailnet, or why there is none. */
25
+ export type TailnetStatus = {
26
+ readonly running: true;
27
+ readonly host: string;
28
+ } | {
29
+ readonly running: false;
30
+ readonly why: string;
31
+ };
32
+ /**
33
+ * This machine's host on a running tailnet: its MagicDNS name without the trailing dot, lowercase,
34
+ * unless the tailnet has MagicDNS off; otherwise its first tailnet IPv4.
35
+ */
36
+ export declare const tailnetStatusOf: (status: TailscaleStatus) => TailnetStatus;
37
+ /** How long `tailscale status` may take. */
38
+ export declare const LOOKUP_TIMEOUT: Duration.Duration;
39
+ /** Asks the Tailscale CLI for this machine's status; never fails. */
40
+ export declare const lookupTailnet: Effect.Effect<TailnetStatus, never, ChildProcessSpawner.ChildProcessSpawner>;
41
+ export interface TailnetLookup {
42
+ /** What Tailscale said, the first time anything asked. */
43
+ readonly status: Effect.Effect<TailnetStatus>;
44
+ /**
45
+ * The host for a setting of `tailnet`: Tailscale's, or undefined when it is not running. The
46
+ * first time it is undefined, one line on stderr says the servers use 127.0.0.1 instead.
47
+ */
48
+ readonly host: Effect.Effect<string | undefined>;
49
+ }
50
+ /**
51
+ * This machine's tailnet, looked up once per process (on first need) so every link a process gives
52
+ * names the address its servers bound. Without `TailnetLive` (tests, and code with no process
53
+ * around it), there is none.
54
+ */
55
+ export declare const Tailnet: Context.Reference<TailnetLookup>;
56
+ /** The lookup through the Tailscale CLI, cached for the process. */
57
+ export declare const TailnetLive: Layer.Layer<never, never, ChildProcessSpawner.ChildProcessSpawner>;
@@ -0,0 +1,82 @@
1
+ import { Console, Context, Duration, Effect, Layer, Schema } from 'effect';
2
+ import { ChildProcess, ChildProcessSpawner } from 'effect/process';
3
+ /**
4
+ * Tailscale, for the host settings (`SCREW_BUGS_REPORT_HOST`) when unset or `tailnet`: this
5
+ * machine's MagicDNS name (its tailnet IPv4 when MagicDNS is off), read from `tailscale status
6
+ * --json` once per process. Unset, reports and sign-ins go there whenever Tailscale is running
7
+ * (not in CI); `SCREW_BUGS_REPORT_HOST=127.0.0.1` keeps them on this machine, and doctor says so
8
+ * (see `checkTailnet`).
9
+ */
10
+ /** The value of a host setting that means "this machine's name on the tailnet". */
11
+ export const TAILNET = 'tailnet';
12
+ /** The few fields of `tailscale status --json` screw-bugs reads; the rest is ignored. */
13
+ export const TailscaleStatus = Schema.Struct({
14
+ BackendState: Schema.String,
15
+ Self: Schema.optionalKey(Schema.NullOr(Schema.Struct({
16
+ DNSName: Schema.optionalKey(Schema.String),
17
+ TailscaleIPs: Schema.optionalKey(Schema.NullOr(Schema.Array(Schema.String))),
18
+ }))),
19
+ CurrentTailnet: Schema.optionalKey(Schema.NullOr(Schema.Struct({ MagicDNSEnabled: Schema.optionalKey(Schema.Boolean) }))),
20
+ });
21
+ const IPV4 = /^\d{1,3}(\.\d{1,3}){3}$/;
22
+ /**
23
+ * This machine's host on a running tailnet: its MagicDNS name without the trailing dot, lowercase,
24
+ * unless the tailnet has MagicDNS off; otherwise its first tailnet IPv4.
25
+ */
26
+ export const tailnetStatusOf = (status) => {
27
+ if (status.BackendState !== 'Running')
28
+ return { running: false, why: `Tailscale is ${status.BackendState.toLowerCase()}` };
29
+ const name = status.Self?.DNSName?.trim().replace(/\.$/, '').toLowerCase() ?? '';
30
+ const magicDns = status.CurrentTailnet?.MagicDNSEnabled !== false;
31
+ if (magicDns && name !== '')
32
+ return { running: true, host: name };
33
+ const ipv4 = (status.Self?.TailscaleIPs ?? []).find((ip) => IPV4.test(ip));
34
+ return ipv4 === undefined
35
+ ? { running: false, why: 'Tailscale gave this machine no name or IPv4 address' }
36
+ : { running: true, host: ipv4 };
37
+ };
38
+ /** How long `tailscale status` may take. */
39
+ export const LOOKUP_TIMEOUT = Duration.seconds(3);
40
+ /**
41
+ * Where the Tailscale CLI may be: on the PATH, else the macOS app's own (the Mac App Store and
42
+ * standalone apps do not put one on the PATH).
43
+ */
44
+ const TAILSCALE_COMMANDS = ['tailscale', '/Applications/Tailscale.app/Contents/MacOS/Tailscale'];
45
+ const decodeStatus = Schema.decodeUnknownEffect(Schema.fromJsonString(TailscaleStatus));
46
+ /** Asks the Tailscale CLI for this machine's status; never fails. */
47
+ export const lookupTailnet = Effect.gen(function* () {
48
+ const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
49
+ for (const command of TAILSCALE_COMMANDS) {
50
+ const out = yield* spawner
51
+ .string(ChildProcess.make(command, ['status', '--json'], { stdin: 'ignore' }))
52
+ .pipe(Effect.timeout(LOOKUP_TIMEOUT), Effect.option);
53
+ if (out._tag === 'None')
54
+ continue;
55
+ return yield* decodeStatus(out.value).pipe(Effect.map(tailnetStatusOf), Effect.orElseSucceed(() => ({
56
+ running: false,
57
+ why: 'Tailscale gave a status screw-bugs cannot read',
58
+ })));
59
+ }
60
+ return { running: false, why: 'Tailscale is not installed or did not answer' };
61
+ });
62
+ /**
63
+ * This machine's tailnet, looked up once per process (on first need) so every link a process gives
64
+ * names the address its servers bound. Without `TailnetLive` (tests, and code with no process
65
+ * around it), there is none.
66
+ */
67
+ export const Tailnet = Context.Reference('screw-bugs/Tailnet', {
68
+ defaultValue: () => ({
69
+ status: Effect.succeed({ running: false, why: 'Tailscale was not looked up' }),
70
+ host: Effect.succeed(undefined),
71
+ }),
72
+ });
73
+ /** The lookup through the Tailscale CLI, cached for the process. */
74
+ export const TailnetLive = Layer.effect(Tailnet, Effect.gen(function* () {
75
+ const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
76
+ const status = yield* Effect.cached(lookupTailnet.pipe(Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner)));
77
+ const host = yield* Effect.cached(status.pipe(Effect.flatMap((found) => found.running
78
+ ? Effect.succeed(found.host)
79
+ : Console.error(`screw-bugs: a host setting is "${TAILNET}", but ${found.why}; ` +
80
+ 'serving on 127.0.0.1 until screw-bugs restarts.').pipe(Effect.as(undefined)))));
81
+ return { status, host };
82
+ }));
@@ -1,14 +1 @@
1
- export * from './accounts.js';
2
- export * from './engine.js';
3
- export * from './errors.js';
4
- export * from './evidence.js';
5
- export * from './labels.js';
6
- export * from './css.js';
7
- export * from './marks.js';
8
- export * from './services.js';
9
- export * from './steps.js';
10
- export * from './liveness.js';
11
- export * from './video.js';
12
- export * from './uploads.js';
13
- export * from './viewport.js';
14
- export * from './share.js';
1
+ export * from '@screw-bugs/core/core';
@@ -1,14 +1,3 @@
1
- export * from './accounts.js';
2
- export * from './engine.js';
3
- export * from './errors.js';
4
- export * from './evidence.js';
5
- export * from './labels.js';
6
- export * from './css.js';
7
- export * from './marks.js';
8
- export * from './services.js';
9
- export * from './steps.js';
10
- export * from './liveness.js';
11
- export * from './video.js';
12
- export * from './uploads.js';
13
- export * from './viewport.js';
14
- export * from './share.js';
1
+ // screw-bugs' `core` module lives in @screw-bugs/core, the platform-free package that screw-bugs
2
+ // Cloud shares; this keeps `screw-bugs/core` and the module boundaries working.
3
+ export * from '@screw-bugs/core/core';
@@ -1,10 +1 @@
1
- export * from './html.js';
2
- export * from './pr-summary.js';
3
- export { SHARE_START_PATH } from './menu-bar.js';
4
- export { stepText } from './view.js';
5
- export { base64, cspHash, hex, hmacSha256, sha256 } from './sha256.js';
6
- export { renderWalkthrough, WALKTHROUGH_CSP, WALKTHROUGH_SCRIPT, walkthroughCsp, } from './walkthrough.js';
7
- export { AssetBaseUrl, type RenderOptions } from './assets.js';
8
- export { renderSignInPage, SIGN_IN_CSP, SIGN_IN_SCRIPT } from './sign-in.js';
9
- export { LIVE_CSP, LIVE_REFRESH_S, renderLivePage } from './live.js';
10
- export { renderSharePage, SHARE_PAGE_SCRIPT, SHARE_POLL_MS, SHARE_WEBP_QUALITY, type SharePage, sharePageCsp, } from './share-page.js';
1
+ export * from '@screw-bugs/core/report';
@@ -1,10 +1,3 @@
1
- export * from './html.js';
2
- export * from './pr-summary.js';
3
- export { SHARE_START_PATH } from './menu-bar.js';
4
- export { stepText } from './view.js';
5
- export { base64, cspHash, hex, hmacSha256, sha256 } from './sha256.js';
6
- export { renderWalkthrough, WALKTHROUGH_CSP, WALKTHROUGH_SCRIPT, walkthroughCsp, } from './walkthrough.js';
7
- export { AssetBaseUrl } from './assets.js';
8
- export { renderSignInPage, SIGN_IN_CSP, SIGN_IN_SCRIPT } from './sign-in.js';
9
- export { LIVE_CSP, LIVE_REFRESH_S, renderLivePage } from './live.js';
10
- export { renderSharePage, SHARE_PAGE_SCRIPT, SHARE_POLL_MS, SHARE_WEBP_QUALITY, sharePageCsp, } from './share-page.js';
1
+ // screw-bugs' `report` module lives in @screw-bugs/core, the platform-free package that screw-bugs
2
+ // Cloud shares; this keeps `screw-bugs/report` and the module boundaries working.
3
+ export * from '@screw-bugs/core/report';
@@ -1,9 +1 @@
1
- export * from './accounts.js';
2
- export * from './config.js';
3
- export * from './doctor.js';
4
- export * from './evidence.js';
5
- export * from './findings.js';
6
- export * from './job.js';
7
- export * from './ledger.js';
8
- export * from './status.js';
9
- export * from './share.js';
1
+ export * from '@screw-bugs/core/schema';
@@ -1,9 +1,3 @@
1
- export * from './accounts.js';
2
- export * from './config.js';
3
- export * from './doctor.js';
4
- export * from './evidence.js';
5
- export * from './findings.js';
6
- export * from './job.js';
7
- export * from './ledger.js';
8
- export * from './status.js';
9
- export * from './share.js';
1
+ // screw-bugs' `schema` module lives in @screw-bugs/core, the platform-free package that screw-bugs
2
+ // Cloud shares; this keeps `screw-bugs/schema` and the module boundaries working.
3
+ export * from '@screw-bugs/core/schema';