screw-bugs 0.1.7 → 0.1.8
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/README.md +83 -13
- package/dist/browser-playwright/page.d.ts +2 -2
- package/dist/browser-playwright/page.js +15 -2
- package/dist/build-info.json +3 -3
- package/dist/cli/commands.js +56 -11
- package/dist/cli/mcp.d.ts +11 -4
- package/dist/cli/mcp.js +86 -23
- package/dist/cli/operations.d.ts +30 -2
- package/dist/cli/operations.js +126 -20
- package/dist/cli/report-links.js +2 -2
- package/dist/cli/report-server.d.ts +41 -9
- package/dist/cli/report-server.js +139 -23
- package/dist/cli/share.d.ts +71 -4
- package/dist/cli/share.js +540 -109
- package/dist/cli/sign-in.d.ts +22 -10
- package/dist/cli/sign-in.js +23 -23
- package/dist/core/engine.js +45 -10
- package/dist/core/liveness.js +3 -1
- package/dist/core/services.d.ts +24 -4
- package/dist/core/share.d.ts +31 -0
- package/dist/core/share.js +139 -0
- package/dist/core/steps.d.ts +5 -0
- package/dist/core/steps.js +15 -1
- package/dist/report/html.d.ts +4 -2
- package/dist/report/html.js +36 -13
- package/dist/report/icons.d.ts +3 -0
- package/dist/report/icons.js +5 -1
- package/dist/report/index.d.ts +3 -1
- package/dist/report/index.js +3 -1
- package/dist/report/live.d.ts +7 -0
- package/dist/report/live.js +135 -0
- package/dist/report/menu-bar.d.ts +3 -3
- package/dist/report/menu-bar.js +3 -3
- package/dist/report/player.d.ts +3 -3
- package/dist/report/player.js +3 -3
- package/dist/report/share-page.d.ts +48 -0
- package/dist/report/share-page.js +291 -0
- package/dist/report/styles.d.ts +2 -0
- package/dist/report/styles.js +2 -2
- package/dist/report/view.js +2 -0
- package/dist/report/walkthrough.d.ts +5 -2
- package/dist/report/walkthrough.js +17 -5
- package/dist/schema/accounts.js +10 -1
- package/dist/schema/evidence.d.ts +15 -8
- package/dist/schema/evidence.js +9 -4
- package/dist/schema/findings.js +1 -1
- package/dist/schema/job.d.ts +205 -65
- package/dist/schema/job.js +63 -11
- package/dist/schema/ledger.d.ts +80 -16
- package/dist/schema/ledger.js +36 -0
- package/dist/schema/share.d.ts +17 -0
- package/dist/schema/share.js +22 -0
- package/package.json +1 -1
package/dist/cli/operations.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Context, Effect, FileSystem, Layer, Path } from 'effect';
|
|
1
|
+
import { Context, Duration, Effect, FileSystem, Layer, Path } from 'effect';
|
|
2
2
|
import { AccountBook, Browser, Engine, type RunSummary, Storage } from '../core/index.js';
|
|
3
3
|
import { type AccountEntry, type CaseLedger, type Device, type DoctorReport, type EvidencePack, JobId, type JobRecord, type JudgedLedger, type PlacedMark, type ReportBundle } from '../schema/index.js';
|
|
4
4
|
import { Failure } from './failure.js';
|
|
@@ -8,6 +8,24 @@ import { type SignInOutcome } from './sign-in.js';
|
|
|
8
8
|
export declare const STATUS_POLL_MS = 500;
|
|
9
9
|
/** The longest a status call may wait for a run to end. */
|
|
10
10
|
export declare const MAX_WAIT_SECONDS = 60;
|
|
11
|
+
/**
|
|
12
|
+
* The longest `start_run` may wait for a person to sign in to its test account. A person is
|
|
13
|
+
* slower than a run: finding the tab, typing a password, a code from an email or a second factor.
|
|
14
|
+
* Ten minutes covers that, stays under a sign-in's own `SIGN_IN_IDLE` (15 minutes), and bounds how
|
|
15
|
+
* long an agent sits blocked; Claude Code's default MCP tool timeout is far longer.
|
|
16
|
+
*/
|
|
17
|
+
export declare const MAX_SIGN_IN_WAIT_SECONDS = 600;
|
|
18
|
+
/**
|
|
19
|
+
* How long, once a sign-in wait's time is up, a save already in progress may take to finish and
|
|
20
|
+
* count. A save that takes longer (a stalled disk, a browser not answering) is not waited for: the
|
|
21
|
+
* call looks for a session once more and replies with the link.
|
|
22
|
+
*/
|
|
23
|
+
export declare const SAVE_SETTLE: Duration.Duration;
|
|
24
|
+
/** A sign-in `startRun` waits for: the account, and the link the person signs in at. */
|
|
25
|
+
export interface SignInWait {
|
|
26
|
+
readonly label: string;
|
|
27
|
+
readonly link: string;
|
|
28
|
+
}
|
|
11
29
|
export interface StartRunInput {
|
|
12
30
|
/** A JobSpec, or part of one, as parsed JSON (from `--spec` or the MCP tool input). */
|
|
13
31
|
readonly spec?: unknown;
|
|
@@ -65,6 +83,11 @@ export interface RunResult {
|
|
|
65
83
|
* (never for an interrupted run's report).
|
|
66
84
|
*/
|
|
67
85
|
readonly walkthroughPath: string | undefined;
|
|
86
|
+
/**
|
|
87
|
+
* While the run is queued or running: its `live.html`, the page to watch it on, once the run
|
|
88
|
+
* wrote it. Only read: the run writes it.
|
|
89
|
+
*/
|
|
90
|
+
readonly livePath: string | undefined;
|
|
68
91
|
/**
|
|
69
92
|
* The ledger as results show it: each case's status after the agent's saved findings, if any
|
|
70
93
|
* (see `judgedLedger`). `ledger` keeps the code's statuses.
|
|
@@ -80,10 +103,15 @@ declare const Operations_base: Context.ServiceClass<Operations, "screw-bugs/Oper
|
|
|
80
103
|
* Starts a run. A job whose test account needs a person to sign in first starts nothing and
|
|
81
104
|
* fails with `SignInNeeded`: with `signIn: 'serve'` (a process that lives on, the MCP
|
|
82
105
|
* server), a sign-in is opened and its link given; otherwise the command that opens one.
|
|
106
|
+
* With `signIn: 'serve'` and `waitSeconds`, it first waits up to that long for the person to
|
|
107
|
+
* save that sign-in, and then starts the run as if called afresh; `onSignInWait` runs for as
|
|
108
|
+
* long as it waits (the MCP server sends progress with the link).
|
|
83
109
|
*/
|
|
84
110
|
readonly startRun: (input: StartRunInput, options: {
|
|
85
111
|
readonly requireConfig: boolean;
|
|
86
112
|
readonly signIn?: 'serve' | 'command';
|
|
113
|
+
readonly waitSeconds?: number | undefined;
|
|
114
|
+
readonly onSignInWait?: ((wait: SignInWait) => Effect.Effect<void>) | undefined;
|
|
87
115
|
}) => Effect.Effect<{
|
|
88
116
|
readonly jobId: JobId;
|
|
89
117
|
readonly runDir: string;
|
|
@@ -99,7 +127,7 @@ declare const Operations_base: Context.ServiceClass<Operations, "screw-bugs/Oper
|
|
|
99
127
|
*/
|
|
100
128
|
readonly signIn: (input: SignInInput) => Effect.Effect<{
|
|
101
129
|
readonly link: string;
|
|
102
|
-
readonly done: Effect.Effect<SignInOutcome
|
|
130
|
+
readonly done: Effect.Effect<SignInOutcome>;
|
|
103
131
|
}, Failure>;
|
|
104
132
|
/** Removes a saved account and its session; false when there was none. */
|
|
105
133
|
readonly removeAccount: (label: string) => Effect.Effect<boolean, Failure>;
|
package/dist/cli/operations.js
CHANGED
|
@@ -14,6 +14,19 @@ import { SignIns } from './sign-in.js';
|
|
|
14
14
|
export const STATUS_POLL_MS = 500;
|
|
15
15
|
/** The longest a status call may wait for a run to end. */
|
|
16
16
|
export const MAX_WAIT_SECONDS = 60;
|
|
17
|
+
/**
|
|
18
|
+
* The longest `start_run` may wait for a person to sign in to its test account. A person is
|
|
19
|
+
* slower than a run: finding the tab, typing a password, a code from an email or a second factor.
|
|
20
|
+
* Ten minutes covers that, stays under a sign-in's own `SIGN_IN_IDLE` (15 minutes), and bounds how
|
|
21
|
+
* long an agent sits blocked; Claude Code's default MCP tool timeout is far longer.
|
|
22
|
+
*/
|
|
23
|
+
export const MAX_SIGN_IN_WAIT_SECONDS = 600;
|
|
24
|
+
/**
|
|
25
|
+
* How long, once a sign-in wait's time is up, a save already in progress may take to finish and
|
|
26
|
+
* count. A save that takes longer (a stalled disk, a browser not answering) is not waited for: the
|
|
27
|
+
* call looks for a session once more and replies with the link.
|
|
28
|
+
*/
|
|
29
|
+
export const SAVE_SETTLE = Duration.seconds(5);
|
|
17
30
|
/** Whether a run is past queued and running: it ended, or it waits for an answer. */
|
|
18
31
|
const hasEnded = (ledger) => ledger.state !== 'queued' && ledger.state !== 'running';
|
|
19
32
|
const isOver = (ledger) => ledger.state === 'finished' || ledger.state === 'errored';
|
|
@@ -126,11 +139,17 @@ export class Operations extends Context.Service()('screw-bugs/Operations') {
|
|
|
126
139
|
? yield* reportOf(jobId, ledger, writeReport)
|
|
127
140
|
: undefined;
|
|
128
141
|
const walkthroughPath = yield* walkthroughOf(jobId, reportPath);
|
|
142
|
+
const livePath = ledger.state === 'queued' || ledger.state === 'running'
|
|
143
|
+
? yield* storage
|
|
144
|
+
.probe(jobId, runFiles.live, 0)
|
|
145
|
+
.pipe(Effect.map((file) => file === undefined ? undefined : storage.filePath(jobId, runFiles.live)))
|
|
146
|
+
: undefined;
|
|
129
147
|
return {
|
|
130
148
|
ledger,
|
|
131
149
|
runDir: storage.runDir(jobId),
|
|
132
150
|
reportPath,
|
|
133
151
|
walkthroughPath,
|
|
152
|
+
livePath,
|
|
134
153
|
judged: judgedLedger(ledger, findings),
|
|
135
154
|
};
|
|
136
155
|
});
|
|
@@ -199,14 +218,22 @@ export class Operations extends Context.Service()('screw-bugs/Operations') {
|
|
|
199
218
|
shellWord(needed.url),
|
|
200
219
|
...(needed.about !== undefined ? ['--about', shellWord(needed.about)] : []),
|
|
201
220
|
].join(' ');
|
|
221
|
+
/** `test account "trial-user" (On a trial)`. */
|
|
222
|
+
const accountText = (needed) => `test account "${needed.label}"` +
|
|
223
|
+
(needed.about !== undefined ? ` (${needed.about})` : '');
|
|
202
224
|
/**
|
|
203
225
|
* Nothing started: a person has to sign in to the job's account first. A process that
|
|
204
|
-
* stays (`serve`) opens the sign-in now
|
|
226
|
+
* stays (`serve`) opens the sign-in now (or gives the one already open) and its link;
|
|
227
|
+
* otherwise the command. `waited`: the seconds it already waited for a save, in vain;
|
|
228
|
+
* `link`: the link of the sign-in it waited on, still open, given again instead of
|
|
229
|
+
* opening one.
|
|
205
230
|
*/
|
|
206
|
-
const signInNeeded = (needed, mode) => Effect.gen(function* () {
|
|
207
|
-
const account =
|
|
208
|
-
|
|
209
|
-
|
|
231
|
+
const signInNeeded = (needed, mode, waited, link) => Effect.gen(function* () {
|
|
232
|
+
const account = accountText(needed);
|
|
233
|
+
const why = describeSignInWhy(needed.why) +
|
|
234
|
+
(waited !== undefined
|
|
235
|
+
? `, and the user did not save one within ${waited} seconds`
|
|
236
|
+
: '');
|
|
210
237
|
const details = {
|
|
211
238
|
account: needed.label,
|
|
212
239
|
...(needed.about !== undefined ? { about: needed.about } : {}),
|
|
@@ -215,19 +242,27 @@ export class Operations extends Context.Service()('screw-bugs/Operations') {
|
|
|
215
242
|
accountsFile: accountBook.file,
|
|
216
243
|
};
|
|
217
244
|
if (mode === 'serve' && Option.isSome(signIns)) {
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
245
|
+
const signInUrl = link ??
|
|
246
|
+
(yield* signIns.value.begin({
|
|
247
|
+
label: needed.label,
|
|
248
|
+
about: needed.about,
|
|
249
|
+
origin: needed.origin,
|
|
250
|
+
url: needed.url,
|
|
251
|
+
})).link;
|
|
224
252
|
return yield* new Failure({
|
|
225
253
|
code: ExitCode.SignInNeeded,
|
|
226
254
|
reason: 'sign_in_needed',
|
|
227
255
|
message: `Nothing was started: ${account} ${why}. Ask the user to open the link below, ` +
|
|
228
|
-
'sign in there as that user and press Save sign-in, then start the same job
|
|
229
|
-
|
|
230
|
-
|
|
256
|
+
'sign in there as that user and press Save sign-in, then start the same job ' +
|
|
257
|
+
(waited !== undefined
|
|
258
|
+
? 'again, with waitSeconds to wait for the save.'
|
|
259
|
+
: 'again.'),
|
|
260
|
+
paths: [signInUrl, accountBook.file],
|
|
261
|
+
details: {
|
|
262
|
+
...details,
|
|
263
|
+
signInUrl,
|
|
264
|
+
...(waited !== undefined ? { waitedSeconds: waited } : {}),
|
|
265
|
+
},
|
|
231
266
|
});
|
|
232
267
|
}
|
|
233
268
|
const command = signInCommand(needed);
|
|
@@ -240,6 +275,76 @@ export class Operations extends Context.Service()('screw-bugs/Operations') {
|
|
|
240
275
|
details: { ...details, command },
|
|
241
276
|
});
|
|
242
277
|
});
|
|
278
|
+
/**
|
|
279
|
+
* Starts `start` (a run that may need a sign-in). With `serve`, a sign-in service and
|
|
280
|
+
* `waitSeconds`, a run that needs one opens it and waits for the person to save it, then
|
|
281
|
+
* starts as if called afresh; a cancel ends it. `waitSeconds` bounds the whole wait,
|
|
282
|
+
* opening the sign-in included: a call never waits for a save past it. When the time runs
|
|
283
|
+
* out it looks once more (a save may have landed just then), and then fails as
|
|
284
|
+
* `signInNeeded` says, with the link of the sign-in it waited on while that is open.
|
|
285
|
+
*/
|
|
286
|
+
const startSignedIn = (start, options,
|
|
287
|
+
/** When the call began (ms): its checks before this count against the wait too. */
|
|
288
|
+
since) => Effect.gen(function* () {
|
|
289
|
+
const mode = options.signIn ?? 'command';
|
|
290
|
+
const waitSeconds = options.waitSeconds ?? 0;
|
|
291
|
+
const deadline = since + waitSeconds * 1000;
|
|
292
|
+
const left = Clock.currentTimeMillis.pipe(Effect.map((now) => Duration.millis(Math.max(0, deadline - now))));
|
|
293
|
+
/** Started, or the `SignInNeeded` that stopped it. */
|
|
294
|
+
const attempt = start.pipe(Effect.map((started) => ({ started })), Effect.catchTag('SignInNeeded', (needed) => Effect.succeed({ needed })));
|
|
295
|
+
let tried = yield* attempt;
|
|
296
|
+
while (true) {
|
|
297
|
+
if ('started' in tried)
|
|
298
|
+
return tried.started;
|
|
299
|
+
const needed = tried.needed;
|
|
300
|
+
if (mode !== 'serve' || Option.isNone(signIns) || waitSeconds <= 0)
|
|
301
|
+
return yield* signInNeeded(needed, mode);
|
|
302
|
+
if (Duration.isZero(yield* left))
|
|
303
|
+
return yield* signInNeeded(needed, mode, waitSeconds);
|
|
304
|
+
// The opening counts against the deadline; the link is needed for any reply, so it is
|
|
305
|
+
// never cut short, but no save is waited for past the deadline after it.
|
|
306
|
+
const signIn = yield* signIns.value.begin({
|
|
307
|
+
label: needed.label,
|
|
308
|
+
about: needed.about,
|
|
309
|
+
origin: needed.origin,
|
|
310
|
+
url: needed.url,
|
|
311
|
+
});
|
|
312
|
+
const waiting = options.onSignInWait?.({ label: needed.label, link: signIn.link });
|
|
313
|
+
const remaining = yield* left;
|
|
314
|
+
const ended = yield* (Duration.isZero(remaining)
|
|
315
|
+
? Effect.succeedNone
|
|
316
|
+
: signIn.done.pipe(Effect.timeoutOption(remaining))).pipe(
|
|
317
|
+
// Whatever the wait does meanwhile ends with it.
|
|
318
|
+
waiting === undefined
|
|
319
|
+
? (self) => self
|
|
320
|
+
: (self) => Effect.raceFirst(self, waiting.pipe(Effect.andThen(Effect.never))));
|
|
321
|
+
// At the deadline, a save in progress finishes first and counts, if it does so within
|
|
322
|
+
// SAVE_SETTLE; one that stalls is treated as not done (the look below may still
|
|
323
|
+
// find its session).
|
|
324
|
+
const outcome = Option.isSome(ended)
|
|
325
|
+
? ended.value
|
|
326
|
+
: yield* signIn.outcome.pipe(Effect.timeoutOption(SAVE_SETTLE), Effect.map(Option.getOrUndefined));
|
|
327
|
+
if (outcome === 'cancelled')
|
|
328
|
+
return yield* new Failure({
|
|
329
|
+
code: ExitCode.SignInNeeded,
|
|
330
|
+
reason: 'sign_in_cancelled',
|
|
331
|
+
message: `Nothing was started: the sign-in to ${accountText(needed)} was cancelled. ` +
|
|
332
|
+
'Start the same job again only if the user wants to sign in; it gives a new link.',
|
|
333
|
+
paths: [accountBook.file],
|
|
334
|
+
details: { account: needed.label, accountsFile: accountBook.file },
|
|
335
|
+
});
|
|
336
|
+
// Saved: start again, as a call made now would.
|
|
337
|
+
tried = yield* attempt;
|
|
338
|
+
if (outcome === 'saved')
|
|
339
|
+
continue;
|
|
340
|
+
// Not saved in time, or it ended unsaved (left idle). The look just now may still
|
|
341
|
+
// find a session (saved as the time ran out); otherwise the reply gives the link of
|
|
342
|
+
// the sign-in still open, or a new one's.
|
|
343
|
+
if ('started' in tried)
|
|
344
|
+
return tried.started;
|
|
345
|
+
return yield* signInNeeded(tried.needed, mode, waitSeconds, outcome === undefined ? signIn.link : undefined);
|
|
346
|
+
}
|
|
347
|
+
});
|
|
243
348
|
const accountsFailure = (error) => storageFailure(error);
|
|
244
349
|
return Operations.of({
|
|
245
350
|
doctor: runDoctor(projectRoot, undefined, Option.getOrUndefined(Option.map(updateCheck, (check) => check.doctorCheck))).pipe(Effect.provideService(Browser, browser), platform),
|
|
@@ -265,6 +370,8 @@ export class Operations extends Context.Service()('screw-bugs/Operations') {
|
|
|
265
370
|
return { path: file };
|
|
266
371
|
}),
|
|
267
372
|
startRun: (input, options) => Effect.gen(function* () {
|
|
373
|
+
// waitSeconds counts from here: the checks before a sign-in is opened count too.
|
|
374
|
+
const since = yield* Clock.currentTimeMillis;
|
|
268
375
|
const config = yield* platform(loadConfig(projectRoot));
|
|
269
376
|
if (!config && options.requireConfig)
|
|
270
377
|
return yield* missingConfig(projectRoot);
|
|
@@ -299,10 +406,9 @@ export class Operations extends Context.Service()('screw-bugs/Operations') {
|
|
|
299
406
|
const uploads = yield* platform(checkUploads(projectRoot, spec));
|
|
300
407
|
if (uploads.needed.length > 0)
|
|
301
408
|
return yield* filesNeeded(projectRoot, uploads.needed);
|
|
302
|
-
const jobId = yield* engine
|
|
303
|
-
|
|
304
|
-
StorageFailed
|
|
305
|
-
}));
|
|
409
|
+
const jobId = yield* startSignedIn(engine
|
|
410
|
+
.startRun(spec, { uploads: uploads.sources })
|
|
411
|
+
.pipe(Effect.catchTag('StorageFailed', (e) => Effect.fail(storageFailure(e)))), options, since);
|
|
306
412
|
return { jobId, runDir: storage.runDir(jobId) };
|
|
307
413
|
}),
|
|
308
414
|
awaitRun: (jobId) => ledgerOf(jobId, engine.awaitRun),
|
|
@@ -414,13 +520,13 @@ export class Operations extends Context.Service()('screw-bugs/Operations') {
|
|
|
414
520
|
message: 'This process cannot open a sign-in.',
|
|
415
521
|
});
|
|
416
522
|
const saved = (yield* accountBook.list.pipe(Effect.mapError(accountsFailure))).find((a) => a.label === label);
|
|
417
|
-
const { link } = yield* signIns.value.begin({
|
|
523
|
+
const { link, done } = yield* signIns.value.begin({
|
|
418
524
|
label,
|
|
419
525
|
about: about ?? saved?.about,
|
|
420
526
|
origin,
|
|
421
527
|
url: input.url,
|
|
422
528
|
});
|
|
423
|
-
return { link, done
|
|
529
|
+
return { link, done };
|
|
424
530
|
}),
|
|
425
531
|
removeAccount: (raw) => decodeLabel(raw).pipe(Effect.flatMap((label) => accountBook.remove(label).pipe(Effect.mapError(accountsFailure)))),
|
|
426
532
|
listRuns: (limit) => storage.listRuns(limit).pipe(Effect.mapError(storageFailure), Effect.flatMap((runs) => Effect.forEach(runs, (run) => run.ledger === undefined || !isOver(run.ledger)
|
package/dist/cli/report-links.js
CHANGED
|
@@ -2,7 +2,7 @@ import { Clock, Context, Duration, Effect, FileSystem, Layer, Option, Path, Ref
|
|
|
2
2
|
import { ChildProcess, ChildProcessSpawner } from 'effect/process';
|
|
3
3
|
import { runsDir } from '../store-local/index.js';
|
|
4
4
|
import { isCi } from './environment.js';
|
|
5
|
-
import { fileUrl, folderOf, listen,
|
|
5
|
+
import { fileUrl, folderOf, listen, reportHost, serveEnabled, servesSameRoot, stablePortOf, urlHost, } from './report-server.js';
|
|
6
6
|
/**
|
|
7
7
|
* Report URLs for CLI commands (`run`, `status`, `report`, `findings`, `walkthrough`), which end
|
|
8
8
|
* long before anyone opens the page. The project's report server on its stable port (see
|
|
@@ -99,7 +99,7 @@ export class ReportLinks extends Context.Service()('screw-bugs/ReportLinks') {
|
|
|
99
99
|
return undefined;
|
|
100
100
|
const secret = folder.secret.value;
|
|
101
101
|
const port = options.preferredPort ?? stablePortOf(folder.rootId);
|
|
102
|
-
const base = `http://${
|
|
102
|
+
const base = `http://${urlHost(yield* reportHost)}:${port}`;
|
|
103
103
|
const answers = servesSameRoot(port, folder.rootId, secret);
|
|
104
104
|
if (yield* answers)
|
|
105
105
|
return base;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Context, Duration, Effect, FileSystem, Layer, Option, Path, Schema, Scope } from 'effect';
|
|
2
|
-
import { HttpServerRequest, HttpServerResponse, type HttpServerError } from 'effect/http';
|
|
2
|
+
import { HttpServerRequest, HttpServerResponse, HttpServer, type HttpServerError } from 'effect/http';
|
|
3
3
|
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 127.0.0.1
|
|
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
|
|
8
9
|
* the extensions a report uses, never a directory listing, a dotfile, or anything outside the
|
|
9
10
|
* folder (also through symlinks). Range requests (206, 416) come from `HttpStaticServer`, so
|
|
10
11
|
* videos seek and play. In a process that can share (see `ShareSource`), it also answers the
|
|
@@ -12,6 +13,36 @@ import { Failure } from './failure.js';
|
|
|
12
13
|
* confirms it there.
|
|
13
14
|
*/
|
|
14
15
|
export declare const REPORT_HOST = "127.0.0.1";
|
|
16
|
+
/** Whether `host` (as `reportHost` gives it) is this machine's loopback. */
|
|
17
|
+
export declare const isLoopback: (host: string) => boolean;
|
|
18
|
+
/** A host as it goes in a URL: an IPv6 address in brackets. */
|
|
19
|
+
export declare const urlHost: (host: string) => string;
|
|
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).
|
|
25
|
+
*/
|
|
26
|
+
export declare const reportHost: Effect.Effect<string, Failure, never>;
|
|
27
|
+
/**
|
|
28
|
+
* 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>;
|
|
33
|
+
/**
|
|
34
|
+
* The address a server set to `host` (from `variable`) listens on, as a URL writes it without
|
|
35
|
+
* brackets; a `Failure` with `reason` when that is every interface (a name that resolved to an
|
|
36
|
+
* unspecified address), or loopback for a name other than localhost (many Linux systems map the
|
|
37
|
+
* machine's own name to 127.0.1.1): its links would not open on another device.
|
|
38
|
+
*/
|
|
39
|
+
export declare const boundAddress: (address: Parameters<typeof HttpServer.formatAddress>[0], host: string, variable: string, reason: string) => Effect.Effect<string, never, never> | Effect.Effect<never, Failure, never>;
|
|
40
|
+
/**
|
|
41
|
+
* `host` as a browser writes it in a URL (lowercase, IPv4 shorthand such as `0` expanded, IPv6
|
|
42
|
+
* compressed), without IPv6 brackets; undefined for what is not a host. Links, the Host check and
|
|
43
|
+
* the address bound all use this one spelling, so a browser's Host header matches it.
|
|
44
|
+
*/
|
|
45
|
+
export declare const canonicalHost: (host: string) => string | undefined;
|
|
15
46
|
/**
|
|
16
47
|
* Without `--port`, a project's report server takes a port from this range, the same one every
|
|
17
48
|
* time: a hash of the runs folder's real path picks it, so report links keep working across
|
|
@@ -69,11 +100,12 @@ export declare const stablePortOf: (rootId: string) => number;
|
|
|
69
100
|
/** What a report links to; anything else is a 404. */
|
|
70
101
|
export declare const SERVED_TYPES: Readonly<Record<string, string>>;
|
|
71
102
|
/**
|
|
72
|
-
* The request handler for `root`, answering only requests addressed to `port` on
|
|
73
|
-
* name
|
|
74
|
-
* function, read per request, so the handler can be made
|
|
103
|
+
* The request handler for `root`, answering only requests addressed to `port` on `host` (and, for
|
|
104
|
+
* a loopback host, on 127.0.0.1 or localhost) by name: a Host check, so a web page cannot reach it
|
|
105
|
+
* through DNS rebinding. `port` may be a function, read per request, so the handler can be made
|
|
106
|
+
* before the server knows its port.
|
|
75
107
|
*/
|
|
76
|
-
export declare const makeReportApp: (root: string, port: number | (() => number), secret?: Uint8Array<ArrayBufferLike> | undefined, share?: ShareRoutes | undefined) => Effect.Effect<Effect.Effect<HttpServerResponse.HttpServerResponse, never, HttpServerRequest.HttpServerRequest>, import("effect/PlatformError").PlatformError, FileSystem.FileSystem | import("effect/http/HttpPlatform").HttpPlatform | Path.Path>;
|
|
108
|
+
export declare const makeReportApp: (root: string, port: number | (() => number), secret?: Uint8Array<ArrayBufferLike> | undefined, share?: ShareRoutes | undefined, host?: string | undefined, boundAt?: (() => string | undefined) | undefined) => Effect.Effect<Effect.Effect<HttpServerResponse.HttpServerResponse, never, HttpServerRequest.HttpServerRequest>, import("effect/PlatformError").PlatformError, FileSystem.FileSystem | import("effect/http/HttpPlatform").HttpPlatform | Path.Path>;
|
|
77
109
|
/** The URL of `file` (an absolute path inside `root`) on a server at `base`, or undefined. */
|
|
78
110
|
export declare const fileUrl: (path: Path.Path, base: string, root: string, file: string) => string | undefined;
|
|
79
111
|
/**
|
|
@@ -87,7 +119,7 @@ export declare const listen: (root: string, port: number, secret?: Uint8Array, o
|
|
|
87
119
|
readonly port: number;
|
|
88
120
|
readonly held: () => number;
|
|
89
121
|
}) => Effect.Effect<void>;
|
|
90
|
-
}) => Effect.Effect<string, import("effect/PlatformError").PlatformError | HttpServerError.ServeError, Scope.Scope>;
|
|
122
|
+
}) => Effect.Effect<string, Failure | import("effect/PlatformError").PlatformError | HttpServerError.ServeError, Scope.Scope>;
|
|
91
123
|
/** How long to wait for whatever holds a port to answer the identity challenge. */
|
|
92
124
|
export declare const IDENTITY_TIMEOUT: Duration.Duration;
|
|
93
125
|
/**
|
|
@@ -127,7 +159,7 @@ export declare const folderOf: (root: string, options?: {
|
|
|
127
159
|
* down); else serves with `fallback` (by default on a free port). `probe` is for tests.
|
|
128
160
|
*/
|
|
129
161
|
export declare const serveOnPreferredPort: (root: string, preferred: number, folder: Folder, options?: {
|
|
130
|
-
readonly fallback?: Effect.Effect<string, HttpServerError.ServeError, Scope.Scope | FileSystem.FileSystem | Path.Path>;
|
|
162
|
+
readonly fallback?: Effect.Effect<string, HttpServerError.ServeError | Failure, Scope.Scope | FileSystem.FileSystem | Path.Path>;
|
|
131
163
|
readonly probe?: Effect.Effect<boolean>;
|
|
132
164
|
}) => Effect.Effect<{
|
|
133
165
|
base: string;
|
|
@@ -138,7 +170,7 @@ export declare const serveOnPreferredPort: (root: string, preferred: number, fol
|
|
|
138
170
|
} | {
|
|
139
171
|
base: string;
|
|
140
172
|
on: "fallback";
|
|
141
|
-
}, import("effect/PlatformError").PlatformError | HttpServerError.ServeError, FileSystem.FileSystem | Path.Path | Scope.Scope>;
|
|
173
|
+
}, Failure | import("effect/PlatformError").PlatformError | HttpServerError.ServeError, FileSystem.FileSystem | Path.Path | Scope.Scope>;
|
|
142
174
|
/**
|
|
143
175
|
* Serves `root` while the scope is open. With `port`, exactly there (0 picks a free one), failing
|
|
144
176
|
* if it is taken. Without, on `preferred` (by default the folder's stable port, see
|