@fnndsc/calypso 0.29.15 → 0.30.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/dist/calypso.js +19 -8
- package/dist/calypso.js.map +1 -1
- package/dist/daemon/attachFile.d.ts +26 -19
- package/dist/daemon/attachFile.js +42 -51
- package/dist/daemon/attachFile.js.map +1 -1
- package/dist/daemon/attachOrigin.d.ts +69 -0
- package/dist/daemon/attachOrigin.js +125 -0
- package/dist/daemon/attachOrigin.js.map +1 -0
- package/dist/daemon/berth.d.ts +265 -26
- package/dist/daemon/berth.js +521 -158
- package/dist/daemon/berth.js.map +1 -1
- package/dist/daemon/claims.js +19 -9
- package/dist/daemon/claims.js.map +1 -1
- package/dist/daemon/commandLane.d.ts +317 -0
- package/dist/daemon/commandLane.js +409 -0
- package/dist/daemon/commandLane.js.map +1 -0
- package/dist/daemon/console.d.ts +0 -2
- package/dist/daemon/console.js +7 -10
- package/dist/daemon/console.js.map +1 -1
- package/dist/daemon/consoleSession.js +4 -1
- package/dist/daemon/consoleSession.js.map +1 -1
- package/dist/daemon/elevation.d.ts +0 -3
- package/dist/daemon/elevation.js +1 -3
- package/dist/daemon/elevation.js.map +1 -1
- package/dist/daemon/face.d.ts +18 -4
- package/dist/daemon/face.js +77 -32
- package/dist/daemon/face.js.map +1 -1
- package/dist/daemon/hostControl.d.ts +114 -1
- package/dist/daemon/hostControl.js +104 -4
- package/dist/daemon/hostControl.js.map +1 -1
- package/dist/daemon/hostPtyRelay.d.ts +118 -0
- package/dist/daemon/hostPtyRelay.js +186 -0
- package/dist/daemon/hostPtyRelay.js.map +1 -0
- package/dist/daemon/httpRoutes.d.ts +257 -0
- package/dist/daemon/httpRoutes.js +537 -0
- package/dist/daemon/httpRoutes.js.map +1 -0
- package/dist/daemon/instance.d.ts +37 -0
- package/dist/daemon/instance.js +59 -0
- package/dist/daemon/instance.js.map +1 -0
- package/dist/daemon/launch.d.ts +17 -0
- package/dist/daemon/launch.js +198 -194
- package/dist/daemon/launch.js.map +1 -1
- package/dist/daemon/launchBanner.d.ts +76 -0
- package/dist/daemon/launchBanner.js +80 -0
- package/dist/daemon/launchBanner.js.map +1 -0
- package/dist/daemon/rival.d.ts +65 -0
- package/dist/daemon/rival.js +67 -0
- package/dist/daemon/rival.js.map +1 -0
- package/dist/daemon/server.d.ts +104 -190
- package/dist/daemon/server.js +358 -866
- package/dist/daemon/server.js.map +1 -1
- package/dist/daemon/settings.d.ts +42 -0
- package/dist/daemon/settings.js +43 -0
- package/dist/daemon/settings.js.map +1 -0
- package/dist/daemon/surface.d.ts +103 -0
- package/dist/daemon/surface.js +71 -0
- package/dist/daemon/surface.js.map +1 -0
- package/dist/daemon/surfaceReplies.d.ts +109 -0
- package/dist/daemon/surfaceReplies.js +108 -0
- package/dist/daemon/surfaceReplies.js.map +1 -0
- package/dist/daemon/terminals.js +5 -2
- package/dist/daemon/terminals.js.map +1 -1
- package/dist/daemon/token.d.ts +41 -5
- package/dist/daemon/token.js +43 -12
- package/dist/daemon/token.js.map +1 -1
- package/dist/daemon/uploadHold.d.ts +85 -0
- package/dist/daemon/uploadHold.js +205 -0
- package/dist/daemon/uploadHold.js.map +1 -0
- package/dist/daemon/vfsHeaders.d.ts +11 -0
- package/dist/daemon/vfsHeaders.js +60 -0
- package/dist/daemon/vfsHeaders.js.map +1 -0
- package/dist/index.d.ts +5 -5
- package/dist/index.js +3 -4
- package/dist/index.js.map +1 -1
- package/dist/notes.json +1 -1
- package/package.json +9 -4
- package/dist/daemon/discovery.d.ts +0 -23
- package/dist/daemon/discovery.js +0 -57
- package/dist/daemon/discovery.js.map +0 -1
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The lines a launched daemon prints: its stack, where it listens, and how to attach.
|
|
3
|
+
*
|
|
4
|
+
* The launcher prints them once, line by line, after the daemon listens and its berth is written. They are built
|
|
5
|
+
* here from facts the launcher already holds, with no read of the host and no write, so the same facts give the
|
|
6
|
+
* same lines.
|
|
7
|
+
*
|
|
8
|
+
* Key components:
|
|
9
|
+
* - LaunchBanner: the facts the lines are made from.
|
|
10
|
+
* - launchBanner_lines: the lines.
|
|
11
|
+
*
|
|
12
|
+
* Typical usage:
|
|
13
|
+
* ```ts
|
|
14
|
+
* for (const line of launchBanner_lines(banner)) console.log(line);
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* Dependencies: chalk (at the level the launcher set); brasa's banner rows and their painter; hostControl.ts for
|
|
18
|
+
* the declared tiers; token.ts for how a token is worded.
|
|
19
|
+
*
|
|
20
|
+
* @module
|
|
21
|
+
*/
|
|
22
|
+
import { type StackBannerRow } from '@fnndsc/brasa/core';
|
|
23
|
+
import { type HostControlPolicy } from './hostControl.js';
|
|
24
|
+
import type { TokenWords } from './token.js';
|
|
25
|
+
/**
|
|
26
|
+
* What a launched daemon's banner says.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* const banner: LaunchBanner = { stackRows, url: 'ws://127.0.0.1:4100', build: 'abc1234', hostControl: HOST_CONTROL_OFF, bindHost: '127.0.0.1', resumed: 0, identity: 'chris@cube', words, berthPath, attachHint: ' chris@cube', displayHost: '127.0.0.1', port: 4100, webRoot: null, notePath: null };
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export interface LaunchBanner {
|
|
34
|
+
/** The stack, one row per package. */
|
|
35
|
+
stackRows: StackBannerRow[];
|
|
36
|
+
/** The wire's address. */
|
|
37
|
+
url: string;
|
|
38
|
+
/** The build hash. */
|
|
39
|
+
build: string;
|
|
40
|
+
/** The declared host-control policy. */
|
|
41
|
+
hostControl: HostControlPolicy;
|
|
42
|
+
/** The address bound. */
|
|
43
|
+
bindHost: string;
|
|
44
|
+
/** How many tasks were picked up again after a restart. */
|
|
45
|
+
resumed: number;
|
|
46
|
+
/** The identity hosted. */
|
|
47
|
+
identity: string;
|
|
48
|
+
/** How the token is worded where it is printed. */
|
|
49
|
+
words: TokenWords;
|
|
50
|
+
/** The berth record's path. */
|
|
51
|
+
berthPath: string;
|
|
52
|
+
/** What follows `chell --remote` to attach: the identity, or nothing. */
|
|
53
|
+
attachHint: string;
|
|
54
|
+
/** The host named in printed addresses. */
|
|
55
|
+
displayHost: string;
|
|
56
|
+
/** The port bound. */
|
|
57
|
+
port: number;
|
|
58
|
+
/** The web surface served, or null. */
|
|
59
|
+
webRoot: string | null;
|
|
60
|
+
/** The file these lines are also written to, or null. */
|
|
61
|
+
notePath: string | null;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The lines a launched daemon prints, in order. The stack, every package written out once, versions in a clean
|
|
65
|
+
* column: the build hash rides the listening line rather than one row's version, which pushed that row past the
|
|
66
|
+
* column the rest share. The token is printed where somebody reads it off a terminal, and nowhere else (`words`).
|
|
67
|
+
*
|
|
68
|
+
* @param banner - What the banner says.
|
|
69
|
+
* @returns The lines, coloured at chalk's level.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* for (const line of launchBanner_lines(banner)) console.log(line);
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export declare function launchBanner_lines(banner: LaunchBanner): string[];
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The lines a launched daemon prints: its stack, where it listens, and how to attach.
|
|
3
|
+
*
|
|
4
|
+
* The launcher prints them once, line by line, after the daemon listens and its berth is written. They are built
|
|
5
|
+
* here from facts the launcher already holds, with no read of the host and no write, so the same facts give the
|
|
6
|
+
* same lines.
|
|
7
|
+
*
|
|
8
|
+
* Key components:
|
|
9
|
+
* - LaunchBanner: the facts the lines are made from.
|
|
10
|
+
* - launchBanner_lines: the lines.
|
|
11
|
+
*
|
|
12
|
+
* Typical usage:
|
|
13
|
+
* ```ts
|
|
14
|
+
* for (const line of launchBanner_lines(banner)) console.log(line);
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* Dependencies: chalk (at the level the launcher set); brasa's banner rows and their painter; hostControl.ts for
|
|
18
|
+
* the declared tiers; token.ts for how a token is worded.
|
|
19
|
+
*
|
|
20
|
+
* @module
|
|
21
|
+
*/
|
|
22
|
+
import { stackBannerRow_paint } from '@fnndsc/brasa/core';
|
|
23
|
+
import chalk from 'chalk';
|
|
24
|
+
import { hostControl_describe } from './hostControl.js';
|
|
25
|
+
/**
|
|
26
|
+
* The host-control lines: annunciated every launch, since this daemon acts on its own host.
|
|
27
|
+
*
|
|
28
|
+
* @param hostControl - The declared policy.
|
|
29
|
+
* @param bindHost - The address bound.
|
|
30
|
+
* @returns The lines; none when host control is off.
|
|
31
|
+
*/
|
|
32
|
+
function hostControlBanner_lines(hostControl, bindHost) {
|
|
33
|
+
if (hostControl.tiers.size === 0)
|
|
34
|
+
return [];
|
|
35
|
+
const lines = [chalk.yellow(`[!] HOST CONTROL: ${hostControl_describe(hostControl)} — ${hostControl.tiers.has('tasks') && hostControl.tiers.size === 1 ? 'this session may start jobs that change the cloud and bill' : `\`!\`, pipes, and the disk are this host's${hostControl.tiers.has('tasks') ? '; jobs may change the cloud and bill' : ''}`}`)];
|
|
36
|
+
if (hostControl.exposed && bindHost !== '127.0.0.1') {
|
|
37
|
+
lines.push(chalk.red(`[!] HOST CONTROL EXPOSED ON ${bindHost}: the attach URL is a shell on this host`));
|
|
38
|
+
}
|
|
39
|
+
return lines;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The lines a launched daemon prints, in order. The stack, every package written out once, versions in a clean
|
|
43
|
+
* column: the build hash rides the listening line rather than one row's version, which pushed that row past the
|
|
44
|
+
* column the rest share. The token is printed where somebody reads it off a terminal, and nowhere else (`words`).
|
|
45
|
+
*
|
|
46
|
+
* @param banner - What the banner says.
|
|
47
|
+
* @returns The lines, coloured at chalk's level.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* for (const line of launchBanner_lines(banner)) console.log(line);
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export function launchBanner_lines(banner) {
|
|
55
|
+
const lines = banner.stackRows.map((row) => ` ${stackBannerRow_paint(row, { name: chalk.bold.cyan, phrase: chalk.white, version: chalk.gray })}`);
|
|
56
|
+
lines.push(chalk.green(`[+] CALYPSO listening on ${banner.url} ${chalk.gray(`(build ${banner.build})`)}`));
|
|
57
|
+
lines.push(...hostControlBanner_lines(banner.hostControl, banner.bindHost));
|
|
58
|
+
if (banner.resumed > 0)
|
|
59
|
+
lines.push(chalk.yellow(`[!] ${String(banner.resumed)} task${banner.resumed === 1 ? '' : 's'} picked up again after the restart (ls /proc)`));
|
|
60
|
+
lines.push(chalk.gray(` identity: ${banner.identity}`));
|
|
61
|
+
lines.push(chalk.gray(` token: ${banner.words.token}`));
|
|
62
|
+
lines.push(chalk.gray(` berth: ${banner.berthPath}`));
|
|
63
|
+
lines.push(chalk.gray(` attach a surface with: chell --remote${banner.attachHint}`));
|
|
64
|
+
if (banner.bindHost !== '127.0.0.1') {
|
|
65
|
+
// Berth discovery is a file in this host's runtime directory, so it cannot
|
|
66
|
+
// reach another machine. An explicit address is how a surface elsewhere
|
|
67
|
+
// attaches, and it is worth printing ready to paste.
|
|
68
|
+
lines.push(chalk.gray(` from another machine: chell --remote --attach ${banner.url} ${banner.words.flag}`));
|
|
69
|
+
}
|
|
70
|
+
if (banner.webRoot !== null) {
|
|
71
|
+
lines.push(chalk.green(`[+] ARGUS web surface at http://${banner.displayHost}:${String(banner.port)}/${banner.words.query}${banner.words.aside}`));
|
|
72
|
+
lines.push(chalk.gray(` serving: ${banner.webRoot}`));
|
|
73
|
+
}
|
|
74
|
+
if (banner.notePath !== null) {
|
|
75
|
+
lines.push(chalk.gray(` these lines also in: ${banner.notePath}`));
|
|
76
|
+
lines.push(chalk.gray(' or run: calypso --berths'));
|
|
77
|
+
}
|
|
78
|
+
return lines;
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=launchBanner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,KAAK,CAAC,IAAI,CAAC,uDAAuD,MAAM,CAAC,GAAG,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IACnH,CAAC;IACD,IAAI,MAAM,CAAC,OAAO,KAAK,IAAI,EAAE,CAAC;QAC5B,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,mCAAmC,MAAM,CAAC,WAAW,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QACnJ,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,kBAAkB,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;IAC7D,CAAC;IACD,IAAI,MAAM,CAAC,QAAQ,KAAK,IAAI,EAAE,CAAC;QAC7B,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,6BAA6B,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;QACvE,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,4CAA4C,CAAC,CAAC,CAAC;IACvE,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Whether a daemon may start for an identity: what this runtime's record of it says, probed.
|
|
3
|
+
*
|
|
4
|
+
* A daemon refuses to host a rival for an identity one of its own already serves. A record proves its daemon is
|
|
5
|
+
* running only by answering a probe (`berthInstance_probe`); an earlier release's record cannot, and whether it
|
|
6
|
+
* still runs is unknown unless its address refuses a connection. Neither a live record nor an unverified one is
|
|
7
|
+
* grounds to start beside it.
|
|
8
|
+
*
|
|
9
|
+
* Key components:
|
|
10
|
+
* - RivalStanding: a record in the way of a start, and what its probe said.
|
|
11
|
+
* - rival_read: this runtime's record for an identity, probed.
|
|
12
|
+
* - rivalRefusal_lines: what a refused start says.
|
|
13
|
+
*
|
|
14
|
+
* Typical usage:
|
|
15
|
+
* ```ts
|
|
16
|
+
* const rival: RivalStanding | null = await rival_read(identity);
|
|
17
|
+
* if (rival !== null) rivalRefusal_lines(rival, '').forEach((line: string): void => { console.error(line); });
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* Dependencies: ./berth.js (berthOwn_read, berthInstance_probe).
|
|
21
|
+
*
|
|
22
|
+
* @module
|
|
23
|
+
*/
|
|
24
|
+
import { type Berth, type BerthLiveness } from './berth.js';
|
|
25
|
+
/**
|
|
26
|
+
* A record that stands in the way of a start, and what its probe said.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* const rival: RivalStanding = { berth, liveness: 'unverified' };
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export interface RivalStanding {
|
|
34
|
+
/** The record. */
|
|
35
|
+
berth: Berth;
|
|
36
|
+
/** Live, or unverified (an earlier release's). */
|
|
37
|
+
liveness: Exclude<BerthLiveness, 'dead'>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Reads this runtime's own record for an identity and probes it.
|
|
41
|
+
*
|
|
42
|
+
* @param identity - The normalised identity.
|
|
43
|
+
* @param probe - The probe (a test's seam).
|
|
44
|
+
* @returns The record standing in the way, or null when a daemon may start.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* const rival: RivalStanding | null = await rival_read(identity);
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare function rival_read(identity: string, probe?: (berth: Berth) => Promise<BerthLiveness>): Promise<RivalStanding | null>;
|
|
52
|
+
/**
|
|
53
|
+
* What is said when a start is refused: a live daemon is pointed at; an unverified one is named with how to stop
|
|
54
|
+
* it. Its pid is not offered to kill: an unverified record's pid may since be another program's.
|
|
55
|
+
*
|
|
56
|
+
* @param rival - The record in the way.
|
|
57
|
+
* @param attachHint - The identity to attach by, with a leading space, or empty.
|
|
58
|
+
* @returns The lines, the first the refusal.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* rivalRefusal_lines(rival, ` ${identity}`).forEach((line: string): void => console.error(line));
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export declare function rivalRefusal_lines(rival: RivalStanding, attachHint: string): [string, string];
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Whether a daemon may start for an identity: what this runtime's record of it says, probed.
|
|
3
|
+
*
|
|
4
|
+
* A daemon refuses to host a rival for an identity one of its own already serves. A record proves its daemon is
|
|
5
|
+
* running only by answering a probe (`berthInstance_probe`); an earlier release's record cannot, and whether it
|
|
6
|
+
* still runs is unknown unless its address refuses a connection. Neither a live record nor an unverified one is
|
|
7
|
+
* grounds to start beside it.
|
|
8
|
+
*
|
|
9
|
+
* Key components:
|
|
10
|
+
* - RivalStanding: a record in the way of a start, and what its probe said.
|
|
11
|
+
* - rival_read: this runtime's record for an identity, probed.
|
|
12
|
+
* - rivalRefusal_lines: what a refused start says.
|
|
13
|
+
*
|
|
14
|
+
* Typical usage:
|
|
15
|
+
* ```ts
|
|
16
|
+
* const rival: RivalStanding | null = await rival_read(identity);
|
|
17
|
+
* if (rival !== null) rivalRefusal_lines(rival, '').forEach((line: string): void => { console.error(line); });
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* Dependencies: ./berth.js (berthOwn_read, berthInstance_probe).
|
|
21
|
+
*
|
|
22
|
+
* @module
|
|
23
|
+
*/
|
|
24
|
+
import { berthInstance_probe, berthOwn_read } from './berth.js';
|
|
25
|
+
/**
|
|
26
|
+
* Reads this runtime's own record for an identity and probes it.
|
|
27
|
+
*
|
|
28
|
+
* @param identity - The normalised identity.
|
|
29
|
+
* @param probe - The probe (a test's seam).
|
|
30
|
+
* @returns The record standing in the way, or null when a daemon may start.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* const rival: RivalStanding | null = await rival_read(identity);
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export async function rival_read(identity, probe = berthInstance_probe) {
|
|
38
|
+
const berth = berthOwn_read(identity);
|
|
39
|
+
if (berth === null)
|
|
40
|
+
return null;
|
|
41
|
+
const liveness = await probe(berth);
|
|
42
|
+
return liveness === 'dead' ? null : { berth, liveness };
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* What is said when a start is refused: a live daemon is pointed at; an unverified one is named with how to stop
|
|
46
|
+
* it. Its pid is not offered to kill: an unverified record's pid may since be another program's.
|
|
47
|
+
*
|
|
48
|
+
* @param rival - The record in the way.
|
|
49
|
+
* @param attachHint - The identity to attach by, with a leading space, or empty.
|
|
50
|
+
* @returns The lines, the first the refusal.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* rivalRefusal_lines(rival, ` ${identity}`).forEach((line: string): void => console.error(line));
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export function rivalRefusal_lines(rival, attachHint) {
|
|
58
|
+
const { berth } = rival;
|
|
59
|
+
if (rival.liveness === 'live')
|
|
60
|
+
return [`[!] Calypso is already running for ${berth.identity} at ${berth.url}`, ` attach with: chell --remote${attachHint}`];
|
|
61
|
+
const pid = berth.pid !== undefined ? ` (pid ${String(berth.pid)} when it was written)` : '';
|
|
62
|
+
return [
|
|
63
|
+
`[!] A daemon of an earlier release may still be running for ${berth.identity} at ${berth.url}${pid}.`,
|
|
64
|
+
' Stop the old daemon from its original terminal (Ctrl-C at the idle daemon prompt) or through its service manager, then retry.',
|
|
65
|
+
];
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=rival.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rival.js","sourceRoot":"","sources":["../../src/daemon/rival.ts"],"names":[],"mappings":"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