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,387 @@
|
|
|
1
|
+
import { NodeHttpClient, NodeHttpServer } from '@effect/platform-node';
|
|
2
|
+
// Boundary: NodeHttpServer serves a Node `http.Server`, made here (see `holdingServer`).
|
|
3
|
+
import { createServer } from 'node:http';
|
|
4
|
+
import { Config, Context, Duration, Effect, Exit, FileSystem, Layer, Option, Path, Schema, Scope, Semaphore, } from 'effect';
|
|
5
|
+
import { HttpClient, HttpIncomingMessage, HttpClientResponse, HttpServerRequest, HttpServerRespondable, HttpServerResponse, HttpStaticServer, } from 'effect/http';
|
|
6
|
+
import { SecureRandom } from 'effect/crypto';
|
|
7
|
+
import { hex, hmacSha256, sha256 } from '../report/index.js';
|
|
8
|
+
import { runsDir } from '../store-local/index.js';
|
|
9
|
+
import { ExitCode } from './exit-codes.js';
|
|
10
|
+
import { Failure } from './failure.js';
|
|
11
|
+
/**
|
|
12
|
+
* A local HTTP server for reports, for browsers that cannot open `file://` (the ones built into
|
|
13
|
+
* coding tools). It binds 127.0.0.1 only and serves the runs folder read-only: only files with
|
|
14
|
+
* the extensions a report uses, never a directory listing, a dotfile, or anything outside the
|
|
15
|
+
* folder (also through symlinks). Range requests (206, 416) come from `HttpStaticServer`, so
|
|
16
|
+
* videos seek and play.
|
|
17
|
+
*/
|
|
18
|
+
export const REPORT_HOST = '127.0.0.1';
|
|
19
|
+
/**
|
|
20
|
+
* Without `--port`, a project's report server takes a port from this range, the same one every
|
|
21
|
+
* time: a hash of the runs folder's real path picks it, so report links keep working across
|
|
22
|
+
* processes and sessions.
|
|
23
|
+
*/
|
|
24
|
+
export const STABLE_PORTS = { first: 41000, count: 1000 };
|
|
25
|
+
/**
|
|
26
|
+
* Proves that a report server serves a given runs folder, so another process for the same folder
|
|
27
|
+
* can use it instead of starting its own. A challenge: the caller sends a fresh random `nonce`
|
|
28
|
+
* (64 hex digits), and the server answers with an HMAC of it, the folder's hash and the port it
|
|
29
|
+
* listens on, under the folder's secret (see `SECRET_FILE`). Only a process that can read the
|
|
30
|
+
* secret (the same user) can answer, and an answer relayed from that user's server on another port
|
|
31
|
+
* does not fit. Answered after the same Host and method checks as files; 404 without a secret.
|
|
32
|
+
*/
|
|
33
|
+
export const IDENTITY_PATH = '/.screw-bugs/identity';
|
|
34
|
+
/** What `IDENTITY_PATH` answers: a fixed marker, the folder's hash (never its path) and the proof. */
|
|
35
|
+
export const Identity = Schema.Struct({
|
|
36
|
+
app: Schema.Literal('screw-bugs-report-server'),
|
|
37
|
+
root: Schema.String,
|
|
38
|
+
proof: Schema.String,
|
|
39
|
+
});
|
|
40
|
+
/**
|
|
41
|
+
* The secret behind identity proofs, beside the runs folder (in `.screw-bugs/`): 32 random bytes
|
|
42
|
+
* as hex, made once per folder, readable by its owner only (mode 0600). On Windows, where modes do
|
|
43
|
+
* not apply, it gets whatever access `FileSystem` gives new files there.
|
|
44
|
+
*/
|
|
45
|
+
export const SECRET_FILE = 'report-server.secret';
|
|
46
|
+
const SecretText = Schema.String.check(Schema.makeFilter((text) => /^[0-9a-f]{64}\n?$/.test(text) ? undefined : 'Must be 64 hex digits'));
|
|
47
|
+
const randomHex = (size) => SecureRandom.SecureRandom.use((random) => random.randomBytes(size)).pipe(Effect.map(hex), Effect.provide(SecureRandom.layerWebCrypto));
|
|
48
|
+
const fromHex = (text) => Uint8Array.from(text.match(/[0-9a-f]{2}/g) ?? [], (pair) => Number.parseInt(pair, 16));
|
|
49
|
+
/**
|
|
50
|
+
* Whether proofs are off on this platform: on Windows, where mode 0600 does not make a file
|
|
51
|
+
* private (a folder's inherited ACL may let other users read it), so a secret there could be read
|
|
52
|
+
* and proofs forged. There, no secret is made, no server is reused, and a taken stable port means
|
|
53
|
+
* a free port of our own. Read from the path separator; tests give it instead.
|
|
54
|
+
*/
|
|
55
|
+
export const noProofs = (options = {}) => options.windows === undefined
|
|
56
|
+
? Path.Path.useSync((path) => path.sep === '\\')
|
|
57
|
+
: Effect.succeed(options.windows);
|
|
58
|
+
/**
|
|
59
|
+
* The secret for the runs folder at `realRoot`, made on first use: written to a temporary file
|
|
60
|
+
* with mode 0600, then linked into place, which fails if another process got there first (its
|
|
61
|
+
* secret is then the one used). None when it cannot be made or read, or when others could read it,
|
|
62
|
+
* and always on Windows (see `noProofs`), where it is not made at all.
|
|
63
|
+
*/
|
|
64
|
+
export const loadSecret = (realRoot, options = {}) => Effect.gen(function* () {
|
|
65
|
+
if (yield* noProofs(options))
|
|
66
|
+
return Option.none();
|
|
67
|
+
const fs = yield* FileSystem.FileSystem;
|
|
68
|
+
const path = yield* Path.Path;
|
|
69
|
+
const dir = path.dirname(realRoot);
|
|
70
|
+
const file = path.join(dir, SECRET_FILE);
|
|
71
|
+
const read = Effect.gen(function* () {
|
|
72
|
+
const info = yield* fs.stat(file);
|
|
73
|
+
// A secret others can read proves nothing.
|
|
74
|
+
if ((info.mode & 0o077) !== 0)
|
|
75
|
+
return Option.none();
|
|
76
|
+
const text = yield* fs.readFileString(file);
|
|
77
|
+
const secret = yield* Schema.decodeUnknownEffect(SecretText)(text);
|
|
78
|
+
return Option.some(fromHex(secret.trim()));
|
|
79
|
+
});
|
|
80
|
+
const create = Effect.gen(function* () {
|
|
81
|
+
const temporary = path.join(dir, `${SECRET_FILE}.${yield* randomHex(8)}.tmp`);
|
|
82
|
+
yield* fs.writeFileString(temporary, `${yield* randomHex(32)}\n`, {
|
|
83
|
+
flag: 'wx',
|
|
84
|
+
mode: 0o600,
|
|
85
|
+
});
|
|
86
|
+
yield* fs.link(temporary, file).pipe(Effect.catchIf((error) => error.reason._tag === 'AlreadyExists', () => Effect.void), Effect.ensuring(fs.remove(temporary).pipe(Effect.ignore)));
|
|
87
|
+
});
|
|
88
|
+
if (!(yield* fs.exists(file)))
|
|
89
|
+
yield* create;
|
|
90
|
+
return yield* read;
|
|
91
|
+
}).pipe(Effect.catch(() => Effect.succeed(Option.none())));
|
|
92
|
+
/** The proof a server for `rootId` on `port` gives for `nonce`. */
|
|
93
|
+
export const proofOf = (secret, nonce, rootId, port) => hex(hmacSha256(secret, new TextEncoder().encode(`${nonce}\n${rootId}\n${port}`)));
|
|
94
|
+
/** The hash that identifies a served folder (its real absolute path), as hex. */
|
|
95
|
+
export const rootIdOf = (realRoot) => hex(sha256(new TextEncoder().encode(`screw-bugs report root\0${realRoot}`)));
|
|
96
|
+
/** The stable port for a served folder, from its `rootIdOf` hash. */
|
|
97
|
+
export const stablePortOf = (rootId) => STABLE_PORTS.first + (Number.parseInt(rootId.slice(0, 8), 16) % STABLE_PORTS.count);
|
|
98
|
+
/** What a report links to; anything else is a 404. */
|
|
99
|
+
export const SERVED_TYPES = {
|
|
100
|
+
html: 'text/html; charset=utf-8',
|
|
101
|
+
png: 'image/png',
|
|
102
|
+
jpg: 'image/jpeg',
|
|
103
|
+
jpeg: 'image/jpeg',
|
|
104
|
+
webm: 'video/webm',
|
|
105
|
+
json: 'application/json; charset=utf-8',
|
|
106
|
+
};
|
|
107
|
+
const notFound = HttpServerResponse.text('Not found', { status: 404 });
|
|
108
|
+
/** The extension of a file name we may serve (an own key of `SERVED_TYPES`), or undefined. */
|
|
109
|
+
const servedExtension = (name) => {
|
|
110
|
+
const dot = name.lastIndexOf('.');
|
|
111
|
+
const extension = dot > 0 ? name.slice(dot + 1).toLowerCase() : '';
|
|
112
|
+
return Object.hasOwn(SERVED_TYPES, extension) ? extension : undefined;
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Whether these path segments name a file we may serve: no empty segment, `..`, dotfile or dot
|
|
116
|
+
* folder, and an allowed extension.
|
|
117
|
+
*/
|
|
118
|
+
const servable = (segments) => segments.length > 0 &&
|
|
119
|
+
segments.every((s) => s !== '' && !s.startsWith('.')) &&
|
|
120
|
+
servedExtension(segments.at(-1)) !== undefined;
|
|
121
|
+
/** Whether `text` has a control character (C0 or DEL) or a backslash. */
|
|
122
|
+
const hasControlOrBackslash = (text) => [...text].some((c) => c === '\\' || c.charCodeAt(0) < 0x20 || c.charCodeAt(0) === 0x7f);
|
|
123
|
+
/**
|
|
124
|
+
* The path a request target names under the root, as decoded segments; undefined for anything
|
|
125
|
+
* odd. A target is an absolute path, maybe with a query (dropped); no raw fragment (`#` is never
|
|
126
|
+
* sent by a browser), whitespace, control characters or backslashes, and none of the last two
|
|
127
|
+
* once decoded.
|
|
128
|
+
*/
|
|
129
|
+
const requestSegments = (url) => {
|
|
130
|
+
if (!url.startsWith('/') || /[#\s]/.test(url) || hasControlOrBackslash(url))
|
|
131
|
+
return undefined;
|
|
132
|
+
const query = url.indexOf('?');
|
|
133
|
+
const pathname = query === -1 ? url : url.slice(0, query);
|
|
134
|
+
let decoded;
|
|
135
|
+
try {
|
|
136
|
+
decoded = decodeURIComponent(pathname);
|
|
137
|
+
}
|
|
138
|
+
catch {
|
|
139
|
+
return undefined;
|
|
140
|
+
}
|
|
141
|
+
// Decoded, only what no file name here has; `#`, `?` and spaces are re-encoded when served.
|
|
142
|
+
if (hasControlOrBackslash(decoded))
|
|
143
|
+
return undefined;
|
|
144
|
+
const segments = decoded.slice(1).split('/');
|
|
145
|
+
return servable(segments) ? segments : undefined;
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* The request handler for `root`, answering only requests addressed to `port` on this machine by
|
|
149
|
+
* name (a Host check, so a web page cannot reach it through DNS rebinding). `port` may be a
|
|
150
|
+
* function, read per request, so the handler can be made before the server knows its port.
|
|
151
|
+
*/
|
|
152
|
+
export const makeReportApp = Effect.fnUntraced(function* (root, port, secret) {
|
|
153
|
+
const portNow = typeof port === 'number' ? () => port : port;
|
|
154
|
+
const fs = yield* FileSystem.FileSystem;
|
|
155
|
+
const path = yield* Path.Path;
|
|
156
|
+
const realRoot = yield* fs.realPath(root);
|
|
157
|
+
const rootId = rootIdOf(realRoot);
|
|
158
|
+
/** The answer to an identity challenge, or undefined for any other request. */
|
|
159
|
+
const identity = (url) => {
|
|
160
|
+
const nonce = /^\/\.screw-bugs\/identity\?nonce=([0-9a-f]{64})$/.exec(url)?.[1];
|
|
161
|
+
if (nonce === undefined || secret === undefined)
|
|
162
|
+
return undefined;
|
|
163
|
+
return HttpServerResponse.jsonUnsafe({
|
|
164
|
+
app: 'screw-bugs-report-server',
|
|
165
|
+
root: rootId,
|
|
166
|
+
proof: proofOf(secret, nonce, rootId, portNow()),
|
|
167
|
+
});
|
|
168
|
+
};
|
|
169
|
+
const serveStatic = yield* HttpStaticServer.make({
|
|
170
|
+
root: realRoot,
|
|
171
|
+
index: undefined,
|
|
172
|
+
cacheControl: 'no-store',
|
|
173
|
+
mimeTypes: SERVED_TYPES,
|
|
174
|
+
});
|
|
175
|
+
/**
|
|
176
|
+
* The file a request names, resolved once to its real path and checked there, as segments
|
|
177
|
+
* under the real root; undefined unless it is a file we may serve. Only this canonical path is
|
|
178
|
+
* served, so what is checked is what is sent.
|
|
179
|
+
*/
|
|
180
|
+
const canonical = (url) => Effect.gen(function* () {
|
|
181
|
+
const segments = requestSegments(url);
|
|
182
|
+
if (!segments)
|
|
183
|
+
return undefined;
|
|
184
|
+
const resolved = path.resolveWithin(realRoot, segments.join('/'));
|
|
185
|
+
if (Option.isNone(resolved))
|
|
186
|
+
return undefined;
|
|
187
|
+
const real = yield* fs.realPath(resolved.value).pipe(Effect.option);
|
|
188
|
+
if (Option.isNone(real) || !real.value.startsWith(realRoot + path.sep))
|
|
189
|
+
return undefined;
|
|
190
|
+
const relative = path.relative(realRoot, real.value).split(path.sep);
|
|
191
|
+
return servable(relative) ? relative : undefined;
|
|
192
|
+
});
|
|
193
|
+
return Effect.gen(function* () {
|
|
194
|
+
const request = yield* HttpServerRequest.HttpServerRequest;
|
|
195
|
+
const host = request.headers['host'];
|
|
196
|
+
if (host !== `${REPORT_HOST}:${portNow()}` && host !== `localhost:${portNow()}`) {
|
|
197
|
+
return HttpServerResponse.text('Forbidden', { status: 403 });
|
|
198
|
+
}
|
|
199
|
+
if (request.method !== 'GET' && request.method !== 'HEAD') {
|
|
200
|
+
return HttpServerResponse.text('Method not allowed', {
|
|
201
|
+
status: 405,
|
|
202
|
+
headers: { allow: 'GET, HEAD' },
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
const proof = identity(request.url);
|
|
206
|
+
if (proof)
|
|
207
|
+
return proof;
|
|
208
|
+
const file = yield* canonical(request.url);
|
|
209
|
+
if (!file)
|
|
210
|
+
return notFound;
|
|
211
|
+
// The static server gets the canonical path alone, encoded so it decodes back to exactly it.
|
|
212
|
+
const exact = request.modify({ url: `/${file.map(encodeURIComponent).join('/')}` });
|
|
213
|
+
return yield* serveStatic.pipe(Effect.provideService(HttpServerRequest.HttpServerRequest, exact), Effect.catch(HttpServerRespondable.toResponse));
|
|
214
|
+
}).pipe(Effect.map(HttpServerResponse.setHeader('x-content-type-options', 'nosniff')), Effect.catchCause(() => Effect.succeed(HttpServerResponse.text('Error', { status: 500 }))));
|
|
215
|
+
});
|
|
216
|
+
/** The URL of `file` (an absolute path inside `root`) on a server at `base`, or undefined. */
|
|
217
|
+
export const fileUrl = (path, base, root, file) => {
|
|
218
|
+
const relative = path.relative(root, file);
|
|
219
|
+
if (relative === '' || relative.startsWith('..') || path.isAbsolute(relative))
|
|
220
|
+
return undefined;
|
|
221
|
+
return `${base}/${relative.split(path.sep).map(encodeURIComponent).join('/')}`;
|
|
222
|
+
};
|
|
223
|
+
/**
|
|
224
|
+
* Boundary: a Node `http.Server` that holds the requests it gets until `release`. `NodeHttpServer`
|
|
225
|
+
* starts listening before its handler is attached, and Node drops nothing but answers nothing to a
|
|
226
|
+
* request with no listener, so one that arrives in between (such as another process's identity
|
|
227
|
+
* check) would wait for good. This listener is there from the start; `release` takes it away once
|
|
228
|
+
* the handler is attached, and hands that handler what it held.
|
|
229
|
+
*/
|
|
230
|
+
const holdingServer = () => {
|
|
231
|
+
const server = createServer();
|
|
232
|
+
const held = [];
|
|
233
|
+
const hold = (request, response) => {
|
|
234
|
+
held.push([request, response]);
|
|
235
|
+
};
|
|
236
|
+
server.on('request', hold);
|
|
237
|
+
return {
|
|
238
|
+
server,
|
|
239
|
+
held: () => held.length,
|
|
240
|
+
release: () => {
|
|
241
|
+
server.off('request', hold);
|
|
242
|
+
for (const [request, response] of held.splice(0))
|
|
243
|
+
server.emit('request', request, response);
|
|
244
|
+
},
|
|
245
|
+
};
|
|
246
|
+
};
|
|
247
|
+
/**
|
|
248
|
+
* Listens for `root` on `port` (0 picks a free one) while the scope is open; the base URL.
|
|
249
|
+
* `beforeServe` runs between listening and attaching the handler, for tests of that moment.
|
|
250
|
+
*/
|
|
251
|
+
export const listen = (root, port, secret, options = {}) => Effect.gen(function* () {
|
|
252
|
+
let bound = port;
|
|
253
|
+
const app = yield* makeReportApp(root, () => bound, secret);
|
|
254
|
+
const holding = holdingServer();
|
|
255
|
+
const server = yield* NodeHttpServer.make(() => holding.server, { port, host: REPORT_HOST });
|
|
256
|
+
if ('port' in server.address)
|
|
257
|
+
bound = server.address.port;
|
|
258
|
+
if (options.beforeServe)
|
|
259
|
+
yield* options.beforeServe({ port: bound, held: holding.held });
|
|
260
|
+
yield* server.serve(app);
|
|
261
|
+
yield* Effect.sync(holding.release);
|
|
262
|
+
return `http://${REPORT_HOST}:${bound}`;
|
|
263
|
+
}).pipe(Effect.provide(NodeHttpServer.layerHttpServices));
|
|
264
|
+
/** How long to wait for whatever holds a port to answer the identity challenge. */
|
|
265
|
+
export const IDENTITY_TIMEOUT = Duration.seconds(2);
|
|
266
|
+
/**
|
|
267
|
+
* Whether the report server of this folder (the one that can read `secret`) answers on `port`.
|
|
268
|
+
* Anything else there (another program, a server for another folder or user, a wrong or late
|
|
269
|
+
* answer) is false. Nothing stops a process from taking the port after this check; links would
|
|
270
|
+
* then reach it until this process takes the port back (see `ReportServer`).
|
|
271
|
+
*/
|
|
272
|
+
export const servesSameRoot = (port, rootId, secret) => Effect.gen(function* () {
|
|
273
|
+
const nonce = yield* randomHex(32);
|
|
274
|
+
const answer = yield* HttpClient.get(`http://${REPORT_HOST}:${port}${IDENTITY_PATH}?nonce=${nonce}`).pipe(Effect.flatMap(HttpClientResponse.filterStatusOk), Effect.flatMap(HttpIncomingMessage.schemaBodyJson(Identity)), Effect.scoped);
|
|
275
|
+
return answer.root === rootId && answer.proof === proofOf(secret, nonce, rootId, port);
|
|
276
|
+
}).pipe(Effect.timeout(IDENTITY_TIMEOUT), Effect.provide(NodeHttpClient.layerNodeHttp), Effect.catch(() => Effect.succeed(false)));
|
|
277
|
+
/** How often to try the preferred port again after its holder failed the challenge. */
|
|
278
|
+
export const BIND_RETRIES = 2;
|
|
279
|
+
/** The hash and secret of the runs folder at `root` (no secret on Windows, see `noProofs`). */
|
|
280
|
+
export const folderOf = (root, options = {}) => Effect.gen(function* () {
|
|
281
|
+
const realRoot = yield* FileSystem.FileSystem.use((fs) => fs.realPath(root));
|
|
282
|
+
const secret = yield* loadSecret(realRoot, options);
|
|
283
|
+
return { rootId: rootIdOf(realRoot), secret };
|
|
284
|
+
});
|
|
285
|
+
/**
|
|
286
|
+
* Serves `root` on `preferred` if it is free; else uses this folder's server already there, if it
|
|
287
|
+
* proves it is one; else tries the port again (`BIND_RETRIES`; its holder may have been shutting
|
|
288
|
+
* down); else serves with `fallback` (by default on a free port). `probe` is for tests.
|
|
289
|
+
*/
|
|
290
|
+
export const serveOnPreferredPort = (root, preferred, folder, options = {}) => Effect.gen(function* () {
|
|
291
|
+
const secret = Option.getOrUndefined(folder.secret);
|
|
292
|
+
const bind = listen(root, preferred, secret).pipe(Effect.map(Option.some), Effect.catchTag('ServeError', () => Effect.succeed(Option.none())));
|
|
293
|
+
const first = yield* bind;
|
|
294
|
+
if (Option.isSome(first))
|
|
295
|
+
return { base: first.value, on: 'preferred' };
|
|
296
|
+
const probe = options.probe ??
|
|
297
|
+
(secret === undefined
|
|
298
|
+
? Effect.succeed(false)
|
|
299
|
+
: servesSameRoot(preferred, folder.rootId, secret));
|
|
300
|
+
if (yield* probe) {
|
|
301
|
+
return { base: `http://${REPORT_HOST}:${preferred}`, on: 'reused' };
|
|
302
|
+
}
|
|
303
|
+
for (let retry = 0; retry < BIND_RETRIES; retry++) {
|
|
304
|
+
const again = yield* bind;
|
|
305
|
+
if (Option.isSome(again))
|
|
306
|
+
return { base: again.value, on: 'preferred' };
|
|
307
|
+
}
|
|
308
|
+
const base = yield* options.fallback ?? listen(root, 0, secret);
|
|
309
|
+
return { base, on: 'fallback' };
|
|
310
|
+
});
|
|
311
|
+
/**
|
|
312
|
+
* Serves `root` while the scope is open. With `port`, exactly there (0 picks a free one), failing
|
|
313
|
+
* if it is taken. Without, on `preferred` (by default the folder's stable port, see
|
|
314
|
+
* `STABLE_PORTS`) as `serveOnPreferredPort` does.
|
|
315
|
+
*/
|
|
316
|
+
export const startReportServer = (root, options = {}) => Effect.gen(function* () {
|
|
317
|
+
const folder = yield* folderOf(root, options);
|
|
318
|
+
if (options.port !== undefined) {
|
|
319
|
+
const secret = Option.getOrUndefined(folder.secret);
|
|
320
|
+
return { base: yield* listen(root, options.port, secret), on: 'preferred' };
|
|
321
|
+
}
|
|
322
|
+
return yield* serveOnPreferredPort(root, options.preferred ?? stablePortOf(folder.rootId), folder);
|
|
323
|
+
}).pipe(Effect.catchTag('ServeError', (error) => Effect.fail(new Failure({
|
|
324
|
+
code: ExitCode.Usage,
|
|
325
|
+
reason: 'serve_failed',
|
|
326
|
+
message: `Could not serve reports on ${REPORT_HOST}:${options.port ?? 0}` +
|
|
327
|
+
(options.port ? ' (is the port in use? Try another --port, or leave it out)' : '') +
|
|
328
|
+
`: ${String(error.cause)}`,
|
|
329
|
+
}))), Effect.catchTag('PlatformError', (error) => Effect.fail(new Failure({
|
|
330
|
+
code: ExitCode.Usage,
|
|
331
|
+
reason: 'serve_failed',
|
|
332
|
+
message: `Could not serve reports from ${root}: ${error.message}`,
|
|
333
|
+
}))));
|
|
334
|
+
/** `SCREW_BUGS_SERVE=0` (or false, no, off) turns the MCP server's report URLs off. */
|
|
335
|
+
export const serveEnabled = Config.String('SCREW_BUGS_SERVE').pipe(Config.map((value) => !['0', 'false', 'no', 'off'].includes(value.trim().toLowerCase())), Config.withDefault(true), Effect.orDie);
|
|
336
|
+
/**
|
|
337
|
+
* Report URLs for a long-lived process (the MCP server). The server starts on first need, on the
|
|
338
|
+
* project's stable port, and lives as long as the process. While this folder's server in another
|
|
339
|
+
* process holds that port, its URL is given instead; while anything else holds it, this process
|
|
340
|
+
* serves on a free port. Either way each later call tries the stable port again, and once it is
|
|
341
|
+
* free this process serves there too and gives that URL from then on; a fallback server stays up,
|
|
342
|
+
* so links already given keep working. Without a server, or when none can start, there is no URL
|
|
343
|
+
* and callers give the file path alone. On Windows it never uses another process's server (see
|
|
344
|
+
* `noProofs`). `preferredPort` and `windows` are for tests.
|
|
345
|
+
*/
|
|
346
|
+
export class ReportServer extends Context.Service()('screw-bugs/ReportServer') {
|
|
347
|
+
static layer = (projectRoot, options = {}) => Layer.effect(ReportServer, Effect.gen(function* () {
|
|
348
|
+
const path = yield* Path.Path;
|
|
349
|
+
const root = yield* runsDir(projectRoot);
|
|
350
|
+
if (!(yield* serveEnabled))
|
|
351
|
+
return { urlOf: () => Effect.succeed(undefined) };
|
|
352
|
+
const scope = yield* Scope.Scope;
|
|
353
|
+
const fs = yield* FileSystem.FileSystem;
|
|
354
|
+
const services = yield* Effect.context();
|
|
355
|
+
const lock = yield* Semaphore.make(1);
|
|
356
|
+
/** This process's server on the preferred port, once it has one. */
|
|
357
|
+
let preferred;
|
|
358
|
+
/** This process's server on a free port, once it needed one; kept for links given. */
|
|
359
|
+
let fallback;
|
|
360
|
+
const fallbackServer = Effect.suspend(() => fallback !== undefined
|
|
361
|
+
? Effect.succeed(fallback)
|
|
362
|
+
: folderOf(root, options).pipe(Effect.flatMap((folder) => listen(root, 0, Option.getOrUndefined(folder.secret))), Effect.catchTag('PlatformError', (error) => Effect.die(error)), Scope.provide(scope), Effect.tap((base) => Effect.sync(() => {
|
|
363
|
+
fallback = base;
|
|
364
|
+
}))));
|
|
365
|
+
/** Starts or finds a server; one attempt at a time, so calls at once start one. */
|
|
366
|
+
const base = Effect.gen(function* () {
|
|
367
|
+
if (preferred !== undefined)
|
|
368
|
+
return Option.some(preferred);
|
|
369
|
+
// A scope per attempt, kept only when this process ends up serving on the preferred port.
|
|
370
|
+
const attempt = yield* Scope.fork(scope);
|
|
371
|
+
const served = yield* Effect.gen(function* () {
|
|
372
|
+
yield* fs.makeDirectory(root, { recursive: true });
|
|
373
|
+
const folder = yield* folderOf(root, options);
|
|
374
|
+
return yield* serveOnPreferredPort(root, options.preferredPort ?? stablePortOf(folder.rootId), folder, { fallback: fallbackServer });
|
|
375
|
+
}).pipe(Scope.provide(attempt), Effect.option);
|
|
376
|
+
if (Option.isSome(served) && served.value.on === 'preferred') {
|
|
377
|
+
preferred = served.value.base;
|
|
378
|
+
}
|
|
379
|
+
else
|
|
380
|
+
yield* Scope.close(attempt, Exit.void);
|
|
381
|
+
return Option.map(served, (s) => s.base);
|
|
382
|
+
}).pipe(Semaphore.withPermit(lock), Effect.provide(services));
|
|
383
|
+
return {
|
|
384
|
+
urlOf: (file) => base.pipe(Effect.map(Option.flatMap((url) => Option.fromUndefinedOr(fileUrl(path, url, root, file)))), Effect.map(Option.getOrUndefined)),
|
|
385
|
+
};
|
|
386
|
+
}));
|
|
387
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { NodeRuntime } from '@effect/platform-node';
|
|
2
|
+
import { Effect } from 'effect';
|
|
3
|
+
import { ExitCode } from './exit-codes.js';
|
|
4
|
+
declare const SIGNALS: readonly ['SIGINT', 'SIGTERM'];
|
|
5
|
+
type Signal = (typeof SIGNALS)[number];
|
|
6
|
+
/**
|
|
7
|
+
* The process, as far as `runMain` below uses it beyond `NodeRuntime.runMain`: `process` in
|
|
8
|
+
* production, fakes in tests.
|
|
9
|
+
*/
|
|
10
|
+
export interface ProcessHost {
|
|
11
|
+
readonly on: (signal: Signal, listener: () => void) => unknown;
|
|
12
|
+
readonly off: (signal: Signal, listener: () => void) => unknown;
|
|
13
|
+
/** Quits at once, without waiting for cleanup. */
|
|
14
|
+
readonly forceExit: (code: ExitCode) => void;
|
|
15
|
+
/** The code the process ends with when it ends on its own, once its output is written. */
|
|
16
|
+
readonly setExitCode: (code: ExitCode) => void;
|
|
17
|
+
/** Says what is happening, on stderr. */
|
|
18
|
+
readonly tell: (message: string) => void;
|
|
19
|
+
}
|
|
20
|
+
/** Boundary: the real process, for the two things `NodeRuntime.runMain` does not do (below). */
|
|
21
|
+
export declare const processHost: ProcessHost;
|
|
22
|
+
/**
|
|
23
|
+
* Runs the CLI as the process's main program, with `NodeRuntime.runMain`. The first SIGINT or
|
|
24
|
+
* SIGTERM interrupts the program (that is `runMain`'s own handling) instead of killing the
|
|
25
|
+
* process, so running jobs are marked errored, the browser closes and the final ledger is
|
|
26
|
+
* written; the code is then `ExitCode.Interrupted`.
|
|
27
|
+
*
|
|
28
|
+
* Two things `runMain` does not do are added here. Its signal listener only interrupts again on a
|
|
29
|
+
* second signal, so quitting at once needs a listener of our own, which also says what is going
|
|
30
|
+
* on. And it exits with `process.exit` as soon as the program ends with a non-zero code, which can
|
|
31
|
+
* cut off output still on its way to a pipe; a program that ended on its own instead sets the
|
|
32
|
+
* code and lets Node exit when its output is written, as before.
|
|
33
|
+
*
|
|
34
|
+
* `run` is `NodeRuntime.runMain` except in tests.
|
|
35
|
+
*/
|
|
36
|
+
export declare const runMain: (program: Effect.Effect<ExitCode, unknown>, host?: ProcessHost, run?: typeof NodeRuntime.runMain) => void;
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { NodeRuntime } from '@effect/platform-node';
|
|
2
|
+
import { Cause, Effect, Exit } from 'effect';
|
|
3
|
+
import { ExitCode } from './exit-codes.js';
|
|
4
|
+
const SIGNALS = ['SIGINT', 'SIGTERM'];
|
|
5
|
+
/** Boundary: the real process, for the two things `NodeRuntime.runMain` does not do (below). */
|
|
6
|
+
export const processHost = {
|
|
7
|
+
on: (signal, listener) => process.on(signal, listener),
|
|
8
|
+
off: (signal, listener) => process.off(signal, listener),
|
|
9
|
+
forceExit: (code) => process.exit(code),
|
|
10
|
+
setExitCode: (code) => {
|
|
11
|
+
process.exitCode = code;
|
|
12
|
+
},
|
|
13
|
+
tell: (message) => console.error(message),
|
|
14
|
+
};
|
|
15
|
+
/** Anything but an interrupt is a bug: report it and exit with `ExitCode.Internal`. */
|
|
16
|
+
const reportInternalErrors = (program, host) => program.pipe(Effect.catchCause((cause) => Cause.hasInterrupts(cause)
|
|
17
|
+
? Effect.failCause(cause)
|
|
18
|
+
: Effect.sync(() => {
|
|
19
|
+
host.tell(`screw-bugs hit an internal error. Please report it.\n${Cause.pretty(cause)}`);
|
|
20
|
+
return ExitCode.Internal;
|
|
21
|
+
})));
|
|
22
|
+
/**
|
|
23
|
+
* Runs the CLI as the process's main program, with `NodeRuntime.runMain`. The first SIGINT or
|
|
24
|
+
* SIGTERM interrupts the program (that is `runMain`'s own handling) instead of killing the
|
|
25
|
+
* process, so running jobs are marked errored, the browser closes and the final ledger is
|
|
26
|
+
* written; the code is then `ExitCode.Interrupted`.
|
|
27
|
+
*
|
|
28
|
+
* Two things `runMain` does not do are added here. Its signal listener only interrupts again on a
|
|
29
|
+
* second signal, so quitting at once needs a listener of our own, which also says what is going
|
|
30
|
+
* on. And it exits with `process.exit` as soon as the program ends with a non-zero code, which can
|
|
31
|
+
* cut off output still on its way to a pipe; a program that ended on its own instead sets the
|
|
32
|
+
* code and lets Node exit when its output is written, as before.
|
|
33
|
+
*
|
|
34
|
+
* `run` is `NodeRuntime.runMain` except in tests.
|
|
35
|
+
*/
|
|
36
|
+
export const runMain = (program, host = processHost, run = NodeRuntime.runMain) => {
|
|
37
|
+
// Plain state shared by a signal listener and the teardown, both called by Node, not Effect.
|
|
38
|
+
let signals = 0;
|
|
39
|
+
const onSignal = () => {
|
|
40
|
+
signals += 1;
|
|
41
|
+
if (signals === 1)
|
|
42
|
+
host.tell('screw-bugs: Stopping. Press Ctrl+C again to quit at once.');
|
|
43
|
+
else
|
|
44
|
+
host.forceExit(ExitCode.Interrupted);
|
|
45
|
+
};
|
|
46
|
+
// Listening before `runMain` does puts our listener first, so "Stopping" is said before the
|
|
47
|
+
// interrupted program says anything. It stays until the program's cleanup is done, so a second
|
|
48
|
+
// signal can cut that short.
|
|
49
|
+
SIGNALS.forEach((signal) => host.on(signal, onSignal));
|
|
50
|
+
run(reportInternalErrors(program, host), {
|
|
51
|
+
// Internal errors are reported above, in our own words.
|
|
52
|
+
disableErrorReporting: true,
|
|
53
|
+
teardown: (exit, onExit) => {
|
|
54
|
+
SIGNALS.forEach((signal) => host.off(signal, onSignal));
|
|
55
|
+
// A signal decides the code, however the program ended while it was being stopped.
|
|
56
|
+
if (signals > 0 || Exit.isFailure(exit))
|
|
57
|
+
return onExit(ExitCode.Interrupted);
|
|
58
|
+
host.setExitCode(exit.value);
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { NodeRuntime, NodeServices } from '@effect/platform-node';
|
|
2
|
+
import { Console, Effect, Layer } from 'effect';
|
|
3
|
+
import { stampBuild } from './build-info.js';
|
|
4
|
+
import { PackageInfo } from './package-info.js';
|
|
5
|
+
/**
|
|
6
|
+
* Run by `pnpm build` after the compiler (`node dist/cli/stamp-build.js`): writes
|
|
7
|
+
* `dist/build-info.json`, which lets doctor tell a stale `dist/` or a server running old code.
|
|
8
|
+
*/
|
|
9
|
+
NodeRuntime.runMain(PackageInfo.use(({ root }) => stampBuild(root)).pipe(Effect.flatMap((file) => Console.log(`Stamped ${file}`)), Effect.provide(PackageInfo.layer.pipe(Layer.provideMerge(NodeServices.layer)))));
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { Context, Duration, Effect, FileSystem, Layer, Option, Path, Schema, Stdio } from 'effect';
|
|
2
|
+
import { HttpClient } from 'effect/http';
|
|
3
|
+
import type { ChildProcessSpawner } from 'effect/process';
|
|
4
|
+
import type { DoctorCheck } from '../schema/index.js';
|
|
5
|
+
import { type BuildProblem, RunningBuild } from './build-info.js';
|
|
6
|
+
import { type InstallMethod, type UpdateCommand } from './install-method.js';
|
|
7
|
+
import { PackageInfo } from './package-info.js';
|
|
8
|
+
/** A check is due when the last one that got an answer is this old. */
|
|
9
|
+
export declare const CHECK_EVERY: Duration.Duration;
|
|
10
|
+
/** A running MCP server tries again this long after a check that got no answer. */
|
|
11
|
+
export declare const RETRY_AFTER: Duration.Duration;
|
|
12
|
+
/** How long a check waits for the registry. */
|
|
13
|
+
export declare const CHECK_TIMEOUT: Duration.Duration;
|
|
14
|
+
/**
|
|
15
|
+
* How long a CLI command waits, after its output, for a check it started because one was due,
|
|
16
|
+
* counted from when the check started.
|
|
17
|
+
*/
|
|
18
|
+
export declare const CLI_WAIT: Duration.Duration;
|
|
19
|
+
/** A running MCP server never waits less than this between checks, whatever the cache says. */
|
|
20
|
+
export declare const MIN_WAIT: Duration.Duration;
|
|
21
|
+
/** The CLI's line about a newer version is printed at most this often. */
|
|
22
|
+
export declare const NOTICE_EVERY: Duration.Duration;
|
|
23
|
+
/**
|
|
24
|
+
* What the last checks found, shared by every screw-bugs process of the user (times in ms since
|
|
25
|
+
* the epoch). A check that got no answer only moves `lastAttemptMs`.
|
|
26
|
+
*/
|
|
27
|
+
export declare const UpdateCache: Schema.Struct<{
|
|
28
|
+
readonly lastAttemptMs: Schema.optionalKey<Schema.Number>;
|
|
29
|
+
readonly lastSuccessMs: Schema.optionalKey<Schema.Number>;
|
|
30
|
+
/** The registry's latest version at the last success; missing when it knows none (404). */
|
|
31
|
+
readonly latest: Schema.optionalKey<Schema.String>;
|
|
32
|
+
/** When the CLI last printed its line about a newer version. */
|
|
33
|
+
readonly notifiedMs: Schema.optionalKey<Schema.Number>;
|
|
34
|
+
}>;
|
|
35
|
+
export type UpdateCache = typeof UpdateCache.Type;
|
|
36
|
+
export declare const CACHE_FILE = "update-check.json";
|
|
37
|
+
/** Due when no check has got an answer in the last 24 hours: what a process checks on start. */
|
|
38
|
+
export declare const isDue: (cache: UpdateCache, now: number) => boolean;
|
|
39
|
+
/** In a running server, a failed check is also not tried again for an hour. */
|
|
40
|
+
export declare const isDueInServer: (cache: UpdateCache, now: number) => boolean;
|
|
41
|
+
/**
|
|
42
|
+
* How long a running server waits before it checks again: at least `MIN_WAIT`, so that no cache
|
|
43
|
+
* (one that was never written, or holds odd times) can make the server check in a busy loop.
|
|
44
|
+
*/
|
|
45
|
+
export declare const nextCheckIn: (cache: UpdateCache, now: number) => Duration.Duration;
|
|
46
|
+
/**
|
|
47
|
+
* The user's cache folder, as each system has it: `$XDG_CACHE_HOME` or `~/.cache` on Linux and
|
|
48
|
+
* the like, `~/Library/Caches` on macOS, `%LOCALAPPDATA%` on Windows. None when there is no home.
|
|
49
|
+
*/
|
|
50
|
+
export declare const cacheDirFor: (platform: string) => Effect.Effect<string | undefined, never, Path.Path>;
|
|
51
|
+
/** The cache file, `<cache folder>/screw-bugs/update-check.json`. */
|
|
52
|
+
export declare const cacheFileFor: (platform: string) => Effect.Effect<string | undefined, never, Path.Path>;
|
|
53
|
+
/** The cache as saved; a missing or broken file is an empty cache. */
|
|
54
|
+
export declare const readCache: (file: string) => Effect.Effect<{
|
|
55
|
+
readonly lastAttemptMs?: number;
|
|
56
|
+
readonly lastSuccessMs?: number;
|
|
57
|
+
readonly latest?: string;
|
|
58
|
+
readonly notifiedMs?: number;
|
|
59
|
+
}, never, FileSystem.FileSystem>;
|
|
60
|
+
/** A temporary file of the cache this old is left from a write that was cut short: removed. */
|
|
61
|
+
export declare const STALE_TEMPORARY: Duration.Duration;
|
|
62
|
+
/**
|
|
63
|
+
* Saves the cache through a temporary file and a rename, so a process reading it never sees half
|
|
64
|
+
* a file. Several processes may write at once (each with its own temporary file); the last one
|
|
65
|
+
* wins. Never fails: a cache that cannot be written only means the next start checks again.
|
|
66
|
+
*
|
|
67
|
+
* Interruptible throughout, so a filesystem that stalls (a network home that went away) never
|
|
68
|
+
* holds up the CLI's capped wait, the MCP server's shutdown or the process's exit. A write cut
|
|
69
|
+
* short may leave its temporary file; nothing reads those, and the next write removes any older
|
|
70
|
+
* than `STALE_TEMPORARY`.
|
|
71
|
+
*/
|
|
72
|
+
export declare const writeCache: (file: string, cache: UpdateCache) => Effect.Effect<void, never, FileSystem.FileSystem | Path.Path>;
|
|
73
|
+
/** The npm registry's URL for the latest version of `name` (a scoped name keeps its `@`). */
|
|
74
|
+
export declare const registryUrl: (name: string) => string;
|
|
75
|
+
/**
|
|
76
|
+
* The latest version on npm: `Some(version)`, or `None` when the registry does not know the
|
|
77
|
+
* package (404: not published yet). Fails when there is no answer (offline, timeout, another
|
|
78
|
+
* status, a body that is not a version).
|
|
79
|
+
*/
|
|
80
|
+
export declare const fetchLatest: (name: string) => Effect.Effect<Option.Option<string>, import("effect/http/HttpClientError").HttpClientError | Schema.SchemaError | import("effect/Cause").TimeoutError, HttpClient.HttpClient>;
|
|
81
|
+
/** `latest` when it is a newer version than `current`. */
|
|
82
|
+
export declare const newerThan: (latest: string | undefined, current: string) => string | undefined;
|
|
83
|
+
/** The sentence telling the agent a newer version exists and exactly how to get it. */
|
|
84
|
+
export declare const updateSentence: (latest: string, current: string, update: UpdateCommand, options?: {
|
|
85
|
+
readonly name?: string;
|
|
86
|
+
readonly restart?: string;
|
|
87
|
+
}) => string;
|
|
88
|
+
/** The doctor check for a build problem (see `buildProblem`). */
|
|
89
|
+
export declare const checkBuild: (problem: BuildProblem, name?: string) => DoctorCheck;
|
|
90
|
+
/** The doctor check for a newer version, from what the cache knows. */
|
|
91
|
+
export declare const checkVersion: (current: string, cache: UpdateCache, install: InstallMethod, options: {
|
|
92
|
+
readonly enabled: boolean;
|
|
93
|
+
readonly name?: string;
|
|
94
|
+
}) => DoctorCheck;
|
|
95
|
+
type Needs = HttpClient.HttpClient | FileSystem.FileSystem | Path.Path | PackageInfo | RunningBuild | ChildProcessSpawner.ChildProcessSpawner | Stdio.Stdio;
|
|
96
|
+
declare const UpdateCheck_base: Context.ServiceClass<UpdateCheck, "screw-bugs/UpdateCheck", {
|
|
97
|
+
/** Off in CI and with `SCREW_BUGS_UPDATE_CHECK=0`: nothing is fetched, read or said. */
|
|
98
|
+
readonly enabled: boolean;
|
|
99
|
+
/** On and with a cache folder to keep its results in: only then does anything check. */
|
|
100
|
+
readonly active: boolean;
|
|
101
|
+
readonly install: InstallMethod;
|
|
102
|
+
/** The cache as saved (empty when off or unreadable). */
|
|
103
|
+
readonly read: Effect.Effect<UpdateCache>;
|
|
104
|
+
/**
|
|
105
|
+
* Asks the registry when a check is due (`start`: `isDue`; `server`: `isDueInServer`) and
|
|
106
|
+
* saves what it found. Returns the cache as it now stands. Never fails.
|
|
107
|
+
*/
|
|
108
|
+
readonly checkIfDue: (rule: 'start' | 'server') => Effect.Effect<UpdateCache>;
|
|
109
|
+
/**
|
|
110
|
+
* A start check, then one whenever the next is due, for as long as the server runs. Ends at
|
|
111
|
+
* once when not `active`.
|
|
112
|
+
*/
|
|
113
|
+
readonly serverLoop: Effect.Effect<void>;
|
|
114
|
+
/**
|
|
115
|
+
* For a CLI command, before it runs: starts, in the background, a check if one is due
|
|
116
|
+
* (`isDue`), and returns the wait for it, which ends when the check does (at once when none is
|
|
117
|
+
* due) or `CLI_WAIT` after it started, whichever is first, whatever the filesystem does. When
|
|
118
|
+
* not `active`, the wait is nothing.
|
|
119
|
+
*/
|
|
120
|
+
readonly startCliCheck: Effect.Effect<Effect.Effect<void>>;
|
|
121
|
+
/** The sentence about a newer version known from the cache, if there is one. */
|
|
122
|
+
readonly notice: Effect.Effect<string | undefined>;
|
|
123
|
+
/** Doctor's `update` check: a build to restart or rebuild, else a newer version. */
|
|
124
|
+
readonly doctorCheck: Effect.Effect<DoctorCheck>;
|
|
125
|
+
/**
|
|
126
|
+
* The CLI's line about a newer version, on stderr: at most once a day, only to a terminal,
|
|
127
|
+
* never with `--json` (or for `mcp`, whose stderr is the client's log). Gives up after
|
|
128
|
+
* `CLI_WAIT` when the filesystem stalls.
|
|
129
|
+
*/
|
|
130
|
+
readonly cliNotice: (args: ReadonlyArray<string>) => Effect.Effect<void>;
|
|
131
|
+
}>;
|
|
132
|
+
/**
|
|
133
|
+
* The check for a newer screw-bugs on npm, once a day, in the background. screw-bugs only says
|
|
134
|
+
* so (doctor, the MCP server's instructions, one CLI line a day); it never installs anything.
|
|
135
|
+
*/
|
|
136
|
+
export declare class UpdateCheck extends UpdateCheck_base {
|
|
137
|
+
/** `platform` is the operating system's name (`process.platform`), for the cache folder. */
|
|
138
|
+
static readonly layer: (platform: string) => Layer.Layer<UpdateCheck, never, Needs>;
|
|
139
|
+
}
|
|
140
|
+
export {};
|