relayrunner 0.11.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +4 -0
  2. package/dist/cli.js +186 -16
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -55,6 +55,10 @@ server of its own or write files outside the runner. It can't tell a job the
55
55
  gateway routed here from a runner it minted on a GitHub repo of its own, so the
56
56
  terminal shows which repo each job is from.
57
57
 
58
+ Only one `connect` runs on a computer at a time; a second one stops and says
59
+ so. For an app that runs `connect` for you, `--events` writes one JSON event
60
+ per line to stdout and takes `pause` or `resume` on stdin (see `events.ts`).
61
+
58
62
  If another `connect` signs in as this machine while it's online, this one stops
59
63
  and says so. When that happens from a different network, the person who
60
64
  approved the machine also gets an email, since someone else may have its token.
package/dist/cli.js CHANGED
@@ -11,6 +11,7 @@ import { Readable, Transform } from "node:stream";
11
11
  import { pipeline } from "node:stream/promises";
12
12
  import { styleText } from "node:util";
13
13
  import { Scalar, YAMLSeq, isMap, isScalar, isSeq, parseDocument } from "yaml";
14
+ import { createInterface } from "node:readline";
14
15
  const version$1 = z.literal(1);
15
16
  const routeId = z.string().min(1);
16
17
  const DeviceKind = z.enum([
@@ -185,7 +186,7 @@ function parse(version) {
185
186
  ] : null;
186
187
  }
187
188
  // version.ts
188
- const cliVersion = "0.11.0";
189
+ const cliVersion = "0.12.0";
189
190
  // paths.ts
190
191
  function relayrunnerHome() {
191
192
  return resolve(process.env.RELAYRUNNER_HOME || join(homedir(), ".relayrunner"));
@@ -1258,11 +1259,21 @@ function takeLock(lock) {
1258
1259
  return true;
1259
1260
  } catch (error) {
1260
1261
  if (error.code !== "EEXIST") throw error;
1261
- if (isAlive(Number(readlinkSync(lock)))) return false;
1262
+ if (lockHolder(lock)) return false;
1262
1263
  rmSync(lock, { force: true });
1263
1264
  }
1264
1265
  return false;
1265
1266
  }
1267
+ /** The pid of the live process holding a lock taken with takeLock, or null. */
1268
+ function lockHolder(lock) {
1269
+ let pid;
1270
+ try {
1271
+ pid = Number(readlinkSync(lock));
1272
+ } catch {
1273
+ return null;
1274
+ }
1275
+ return isAlive(pid) ? pid : null;
1276
+ }
1266
1277
  function isAlive(pid) {
1267
1278
  if (!Number.isSafeInteger(pid) || pid <= 0) return false;
1268
1279
  try {
@@ -1739,6 +1750,12 @@ const RATES = {
1739
1750
  standard: "vcpu",
1740
1751
  premium: "vcpu"
1741
1752
  },
1753
+ boat: {
1754
+ "boat-small": "runner",
1755
+ boat: "runner",
1756
+ "boat-large": "runner",
1757
+ "boat-xlarge": "runner"
1758
+ },
1742
1759
  github: {
1743
1760
  "linux-1-core": "runner",
1744
1761
  "linux-2-core": "runner",
@@ -1872,6 +1889,30 @@ const BASE_PRICES = [
1872
1889
  usd: vcpu(.002, 2),
1873
1890
  from: "2026-09-01"
1874
1891
  },
1892
+ {
1893
+ provider: "boat",
1894
+ rate: "boat-small",
1895
+ usd: .018 / 60,
1896
+ from: "2026-11-16"
1897
+ },
1898
+ {
1899
+ provider: "boat",
1900
+ rate: "boat",
1901
+ usd: .036 / 60,
1902
+ from: "2026-11-16"
1903
+ },
1904
+ {
1905
+ provider: "boat",
1906
+ rate: "boat-large",
1907
+ usd: .072 / 60,
1908
+ from: "2026-11-16"
1909
+ },
1910
+ {
1911
+ provider: "boat",
1912
+ rate: "boat-xlarge",
1913
+ usd: .2 / 60,
1914
+ from: "2026-11-16"
1915
+ },
1875
1916
  {
1876
1917
  provider: "github",
1877
1918
  rate: "linux-1-core",
@@ -1953,6 +1994,7 @@ const HOSTED_PROVIDER_IDS = [
1953
1994
  "namespace",
1954
1995
  "warpbuild",
1955
1996
  "ubicloud",
1997
+ "boat",
1956
1998
  "runs-on"
1957
1999
  ];
1958
2000
  const LABEL_PREFIXES = {
@@ -1961,6 +2003,7 @@ const LABEL_PREFIXES = {
1961
2003
  namespace: ["namespace-profile-", "nscloud-"],
1962
2004
  warpbuild: ["warp-"],
1963
2005
  ubicloud: ["ubicloud-"],
2006
+ boat: ["boat-", "boat/"],
1964
2007
  "runs-on": ["runs-on=", "runs-on/"]
1965
2008
  };
1966
2009
  /** Whether a lowercase label starts with one of `prefixes`, or is the bare name one ends in `-`. */
@@ -1973,7 +2016,7 @@ function hostedProviderOf(label) {
1973
2016
  }
1974
2017
  // workflows.ts
1975
2018
  /** The relay version `init` writes. Bump it with each relayrunner/actions release. */
1976
- const RELAY_REF = "v1.0.0-beta.5";
2019
+ const RELAY_REF = "v1.0.0-beta.6";
1977
2020
  const RELAY_WORKFLOW = "relayrunner/actions/.github/workflows/relay.yml";
1978
2021
  const DEPLOY_SECRET = /\bsecrets\.(?!GITHUB_TOKEN\b)[A-Za-z_][A-Za-z0-9_]*/;
1979
2022
  const LINUX_PACKAGE_MANAGER = /(^|[\s;&|(])(sudo\s+)?(apt-get|apt|yum|dnf|apk)\s+(install|update|add)\b/m;
@@ -2572,6 +2615,73 @@ function startLive(options) {
2572
2615
  }
2573
2616
  };
2574
2617
  }
2618
+ // events.ts
2619
+ const EVENTS_VERSION = 1;
2620
+ let write = null;
2621
+ /** Sends stdout's writes to stderr from now on, and keeps stdout for emitEvent. */
2622
+ function startEvents() {
2623
+ if (write) return;
2624
+ const { stdout, stderr } = process;
2625
+ const toStdout = stdout.write.bind(stdout);
2626
+ write = (line) => void toStdout(line);
2627
+ stdout.write = stderr.write.bind(stderr);
2628
+ }
2629
+ /** Writes an event to stdout, when `connect` runs with --events. Otherwise does nothing. */
2630
+ function emitEvent(event, now) {
2631
+ if (!write) return;
2632
+ const at = (now ?? /* @__PURE__ */ new Date()).toISOString();
2633
+ write(`${JSON.stringify({
2634
+ v: EVENTS_VERSION,
2635
+ at,
2636
+ ...event
2637
+ })}\n`);
2638
+ }
2639
+ /** The command a line of stdin asks for, or null for anything else. */
2640
+ function parseCommand(line) {
2641
+ const word = line.trim().toLowerCase();
2642
+ return word === "pause" || word === "resume" ? word : null;
2643
+ }
2644
+ /**
2645
+ * Reads commands from stdin until stop() is called. onClose runs when stdin closes first.
2646
+ */
2647
+ function readCommands(options) {
2648
+ const lines = createInterface({
2649
+ input: options.input ?? process.stdin,
2650
+ terminal: false
2651
+ });
2652
+ lines.on("line", (line) => {
2653
+ if (!line.trim()) return;
2654
+ const command = parseCommand(line);
2655
+ if (command) options.onCommand(command);
2656
+ else emitEvent({
2657
+ type: "error",
2658
+ code: "UNKNOWN_COMMAND",
2659
+ message: "Commands are `pause` and `resume`.",
2660
+ command: line.trim()
2661
+ });
2662
+ });
2663
+ lines.once("close", options.onClose);
2664
+ return function stop() {
2665
+ lines.off("close", options.onClose);
2666
+ lines.close();
2667
+ };
2668
+ }
2669
+ // connect-lock.ts
2670
+ /** Takes the lock, or throws ALREADY_CONNECTED. Returns the function that lets it go. */
2671
+ function lockConnect(home = relayrunnerHome()) {
2672
+ mkdirSync(home, {
2673
+ recursive: true,
2674
+ mode: 448
2675
+ });
2676
+ const lock = join(home, "connect.lock");
2677
+ if (!takeLock(lock)) {
2678
+ const pid = lockHolder(lock);
2679
+ throw new RunnerError("ALREADY_CONNECTED", `\`relayrunner connect\` is already running on this computer${pid ? ` (process ${pid})` : ""}. Stop that one first, or use it instead.`);
2680
+ }
2681
+ return () => {
2682
+ if (lockHolder(lock) === process.pid) rmSync(lock, { force: true });
2683
+ };
2684
+ }
2575
2685
  // update-check.ts
2576
2686
  const CHECK_INTERVAL_MS = 864e5;
2577
2687
  const REGISTRY_URL = "https://registry.npmjs.org/relayrunner/latest";
@@ -3391,7 +3501,8 @@ async function whoami(options) {
3391
3501
  const Choice = z.object({
3392
3502
  id: z.string().min(1),
3393
3503
  name: z.string(),
3394
- slug: z.string().nullish()
3504
+ slug: z.string().nullish(),
3505
+ logo: z.string().nullish()
3395
3506
  });
3396
3507
  const MachineWorkspaces = z.object({
3397
3508
  machine: z.object({
@@ -3708,9 +3819,14 @@ const connectCommand = defineCommand({
3708
3819
  "local-network": {
3709
3820
  type: "boolean",
3710
3821
  description: "Let jobs in VMs reach this Mac and your local network. They can't by default."
3822
+ },
3823
+ events: {
3824
+ type: "boolean",
3825
+ description: "For apps that run connect: JSON events on stdout, one per line, and `pause` or `resume` on stdin"
3711
3826
  }
3712
3827
  },
3713
3828
  async run({ args }) {
3829
+ if (args.events) startEvents();
3714
3830
  clack.intro("RelayRunner");
3715
3831
  let concurrency;
3716
3832
  let size;
@@ -3719,11 +3835,12 @@ const connectCommand = defineCommand({
3719
3835
  concurrency = args.concurrency ? parseConcurrency(args.concurrency) : slotsFor(size) ?? parseConcurrency(void 0);
3720
3836
  checkFits(size, concurrency);
3721
3837
  } catch (error) {
3722
- clack.log.error(error.message);
3723
- process.exitCode = 1;
3838
+ fail("USAGE", error.message);
3724
3839
  return;
3725
3840
  }
3841
+ let unlock;
3726
3842
  try {
3843
+ unlock = lockConnect();
3727
3844
  await connectMachine({
3728
3845
  ...args,
3729
3846
  concurrency,
@@ -3731,11 +3848,21 @@ const connectCommand = defineCommand({
3731
3848
  });
3732
3849
  } catch (error) {
3733
3850
  if (!(error instanceof LoginError || error instanceof RunnerError)) throw error;
3734
- clack.log.error(error.message);
3735
- process.exitCode = 1;
3851
+ fail(error.code, error.message);
3852
+ } finally {
3853
+ unlock?.();
3736
3854
  }
3737
3855
  }
3738
3856
  });
3857
+ function fail(code, message) {
3858
+ clack.log.error(message);
3859
+ emitEvent({
3860
+ type: "error",
3861
+ code,
3862
+ message
3863
+ });
3864
+ process.exitCode = 1;
3865
+ }
3739
3866
  async function connectMachine(args) {
3740
3867
  const share = shareArg(args.share);
3741
3868
  const vmFlag = [
@@ -3769,6 +3896,13 @@ async function connectMachine(args) {
3769
3896
  clack.log.info(`Machine ${credentials.machine.name} (${credentials.server})`);
3770
3897
  if (share) await applySharing(credentials, share, null);
3771
3898
  }
3899
+ const { id, name } = credentials.machine;
3900
+ emitEvent({
3901
+ type: "machine",
3902
+ id,
3903
+ name,
3904
+ server: credentials.server
3905
+ });
3772
3906
  if (process.stdin.isTTY && process.stdout.isTTY) await offerSetup();
3773
3907
  let updateTimer;
3774
3908
  if (process.stdout.isTTY && !process.env.CI) {
@@ -3850,15 +3984,25 @@ async function connectMachine(args) {
3850
3984
  const stop = new AbortController();
3851
3985
  const enrolled = credentials;
3852
3986
  let toggling = false;
3987
+ const setPaused = async (paused) => {
3988
+ if (toggling || stop.signal.aborted) return;
3989
+ toggling = true;
3990
+ const result = await pauseMachine(enrolled, paused);
3991
+ toggling = false;
3992
+ if (result.status !== "failed") return;
3993
+ const command = paused ? "pause" : "resume";
3994
+ const message = `Couldn't ${command}: ${result.reason}.`;
3995
+ clack.log.error(message);
3996
+ emitEvent({
3997
+ type: "error",
3998
+ code: "PAUSE_FAILED",
3999
+ message,
4000
+ command
4001
+ });
4002
+ };
3853
4003
  const live = startLive({
3854
4004
  machine: enrolled.machine.name,
3855
- onTogglePause: async ({ paused }) => {
3856
- if (toggling || stop.signal.aborted) return;
3857
- toggling = true;
3858
- const result = await pauseMachine(enrolled, !paused);
3859
- toggling = false;
3860
- if (result.status === "failed") clack.log.error(`Couldn't ${paused ? "resume" : "pause"}: ${result.reason}.`);
3861
- }
4005
+ onTogglePause: ({ paused }) => void setPaused(!paused)
3862
4006
  });
3863
4007
  const onInterrupt = () => {
3864
4008
  if (stop.signal.aborted) {
@@ -3868,6 +4012,10 @@ async function connectMachine(args) {
3868
4012
  stop.abort();
3869
4013
  };
3870
4014
  process.on("SIGINT", onInterrupt);
4015
+ const stopCommands = args.events ? readCommands({
4016
+ onCommand: (command) => void setPaused(command === "pause"),
4017
+ onClose: onInterrupt
4018
+ }) : void 0;
3871
4019
  let online = false;
3872
4020
  let end;
3873
4021
  try {
@@ -3903,7 +4051,13 @@ async function connectMachine(args) {
3903
4051
  report,
3904
4052
  output: prefixed?.output,
3905
4053
  onChecked: (target) => {
3906
- if (target) clack.log.info(`${(/* @__PURE__ */ new Date()).toLocaleTimeString()} Job ${run.routeId}${slots > 1 ? ` (slot ${slot})` : ""} is from ${target}`);
4054
+ if (!target) return;
4055
+ clack.log.info(`${(/* @__PURE__ */ new Date()).toLocaleTimeString()} Job ${run.routeId}${slots > 1 ? ` (slot ${slot})` : ""} is from ${target}`);
4056
+ emitEvent({
4057
+ type: "job-repo",
4058
+ routeId: run.routeId,
4059
+ repo: target
4060
+ });
3907
4061
  }
3908
4062
  });
3909
4063
  } finally {
@@ -3915,7 +4069,13 @@ async function connectMachine(args) {
3915
4069
  onEvent: (event) => {
3916
4070
  if (event.type === "connected") online = true;
3917
4071
  show(event, slots > 1);
4072
+ const before = live.state;
3918
4073
  live.onEvent(event);
4074
+ emitEvent(event);
4075
+ if (live.state !== before) emitEvent({
4076
+ type: "state",
4077
+ ...live.state
4078
+ });
3919
4079
  },
3920
4080
  signal: stop.signal
3921
4081
  });
@@ -3923,8 +4083,13 @@ async function connectMachine(args) {
3923
4083
  clearInterval(updateTimer);
3924
4084
  stopUpdating?.();
3925
4085
  live.end();
4086
+ stopCommands?.();
3926
4087
  process.off("SIGINT", onInterrupt);
3927
4088
  }
4089
+ emitEvent({
4090
+ type: "offline",
4091
+ ...end
4092
+ });
3928
4093
  switch (end.reason) {
3929
4094
  case "stopped":
3930
4095
  clack.outro("Offline.");
@@ -4075,6 +4240,11 @@ async function signIn(server, name, platform) {
4075
4240
  platform,
4076
4241
  onCode: ({ userCode, url }) => {
4077
4242
  clack.note(`${url}\n\nConfirm the code ${userCode} matches the one in your browser.`, "Sign in");
4243
+ emitEvent({
4244
+ type: "sign-in",
4245
+ url,
4246
+ code: userCode
4247
+ });
4078
4248
  openBrowser(url);
4079
4249
  waiting.start("Waiting for approval in the browser");
4080
4250
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "relayrunner",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "Run GitHub Actions jobs on your machine through the RelayRunner gateway.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {