relayrunner 0.6.0 → 0.7.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 +7 -1
  2. package/dist/cli.js +265 -52
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -32,7 +32,7 @@ stops working, so a copy of `machine.json` from a backup or a synced dotfiles
32
32
  folder can't sign in as the machine.
33
33
 
34
34
  While it runs, the machine is online: it keeps a WebSocket open to the gateway,
35
- runs the jobs it's sent (one at a time) and prints what happens, including the
35
+ runs the jobs it's sent and prints what happens, including the
36
36
  repo each job is from. It reconnects on its own if the connection drops. Ctrl-C
37
37
  takes it offline; a job that's running stops with it. Press `p` to pause or
38
38
  resume it without going offline (see `relayrunner pause`). The terminal tab's
@@ -58,6 +58,12 @@ approved the machine also gets an email, since someone else may have its token.
58
58
  one is set, otherwise the Mac's Computer Name from System Settings).
59
59
  - `--share only-me|anyone` sets who can run jobs on this machine without asking.
60
60
  It works on a machine that's already signed in too.
61
+ - `--concurrency <n>` sets how many jobs it runs at once. The default is 2 on a
62
+ computer with 8 or more CPU cores, otherwise 1, and `connect` prints it. Each
63
+ slot runs its jobs in its own copy of the runner,
64
+ `~/.relayrunner/runner/<version>/slot-<n>/`, made when `connect` starts (a
65
+ copy-on-write clone where the disk supports it). With more than one slot,
66
+ each line of a job's output starts with its slot, such as `[slot 2]`.
61
67
  - If the machine is removed in the dashboard, `connect` deletes the saved token.
62
68
  A running `connect` exits and asks you to run it again; a new one signs in
63
69
  straight away.
package/dist/cli.js CHANGED
@@ -2,16 +2,16 @@
2
2
  import * as clack from "@clack/prompts";
3
3
  import { defineCommand, runMain } from "citty";
4
4
  import { z } from "zod";
5
- import { arch, cpus, homedir, hostname, platform, totalmem } from "node:os";
5
+ import { arch, availableParallelism, cpus, homedir, hostname, platform, totalmem } from "node:os";
6
6
  import { basename, dirname, join, resolve } from "node:path";
7
- import { chmodSync, createWriteStream, existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, readlinkSync, renameSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
7
+ import { chmodSync, constants, cpSync, createWriteStream, existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, readlinkSync, renameSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
8
8
  import { execFile, spawn } from "node:child_process";
9
9
  import { createHash } from "node:crypto";
10
10
  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
- const version = z.literal(1);
14
+ const version$1 = z.literal(1);
15
15
  const routeId = z.string().min(1);
16
16
  const DeviceKind = z.enum([
17
17
  "laptop",
@@ -31,7 +31,7 @@ const Device = z.object({
31
31
  osVersion: text.optional()
32
32
  });
33
33
  const HelloMessage = z.object({
34
- v: version,
34
+ v: version$1,
35
35
  type: z.literal("hello"),
36
36
  machineId: z.string().min(1),
37
37
  os: z.enum([
@@ -45,16 +45,19 @@ const HelloMessage = z.object({
45
45
  "arm"
46
46
  ]),
47
47
  runnerVersion: z.string().min(1),
48
+ cliVersion: z.string().trim().min(1).max(40).optional(),
48
49
  device: Device.optional().catch(void 0),
49
- rotatesToken: z.boolean().optional()
50
+ rotatesToken: z.boolean().optional(),
51
+ slots: z.number().int().positive().max(1e3).optional()
50
52
  });
51
53
  const StatusMessage = z.object({
52
- v: version,
54
+ v: version$1,
53
55
  type: z.literal("status"),
54
- state: z.enum(["idle", "busy"])
56
+ state: z.enum(["idle", "busy"]),
57
+ running: z.number().int().nonnegative().max(1e3).optional()
55
58
  });
56
59
  const JobMessage = z.object({
57
- v: version,
60
+ v: version$1,
58
61
  type: z.literal("job"),
59
62
  routeId,
60
63
  state: z.enum([
@@ -65,7 +68,7 @@ const JobMessage = z.object({
65
68
  message: z.string().optional()
66
69
  });
67
70
  const TokenSavedMessage = z.object({
68
- v: version,
71
+ v: version$1,
69
72
  type: z.literal("token_saved")
70
73
  });
71
74
  z.discriminatedUnion("type", [
@@ -75,25 +78,25 @@ z.discriminatedUnion("type", [
75
78
  TokenSavedMessage
76
79
  ]);
77
80
  const RunMessage = z.object({
78
- v: version,
81
+ v: version$1,
79
82
  type: z.literal("run"),
80
83
  routeId,
81
84
  jitConfig: z.string().min(1)
82
85
  });
83
86
  const ErrorMessage = z.object({
84
- v: version,
87
+ v: version$1,
85
88
  type: z.literal("error"),
86
89
  code: z.enum(["version_mismatch", "invalid_message"]),
87
90
  message: z.string()
88
91
  });
89
92
  const PausedMessage = z.object({
90
- v: version,
93
+ v: version$1,
91
94
  type: z.literal("paused"),
92
95
  paused: z.boolean(),
93
96
  by: z.string().nullable()
94
97
  });
95
98
  const TokenMessage = z.object({
96
- v: version,
99
+ v: version$1,
97
100
  type: z.literal("token"),
98
101
  token: z.string().min(1)
99
102
  });
@@ -104,12 +107,12 @@ const GatewayMessage = z.discriminatedUnion("type", [
104
107
  TokenMessage
105
108
  ]);
106
109
  function parseGatewayMessage(frame) {
107
- return parse(GatewayMessage, frame);
110
+ return parse$1(GatewayMessage, frame);
108
111
  }
109
112
  function encodeMessage(message) {
110
113
  return JSON.stringify(message);
111
114
  }
112
- function parse(schema, frame) {
115
+ function parse$1(schema, frame) {
113
116
  let data;
114
117
  try {
115
118
  data = JSON.parse(frame);
@@ -142,6 +145,8 @@ function parse(schema, frame) {
142
145
  function isRunnerForRoute(runnerName, routeId) {
143
146
  return runnerName.endsWith(`-${routeId}`);
144
147
  }
148
+ // version.ts
149
+ const cliVersion = "0.7.0";
145
150
  // paths.ts
146
151
  function relayrunnerHome() {
147
152
  return resolve(process.env.RELAYRUNNER_HOME || join(homedir(), ".relayrunner"));
@@ -149,7 +154,7 @@ function relayrunnerHome() {
149
154
  function runnersDir() {
150
155
  return join(relayrunnerHome(), "runner");
151
156
  }
152
- const userAgent = "relayrunner-cli";
157
+ const userAgent = `relayrunner-cli/${cliVersion}`;
153
158
  const CLOSE_POLICY = 1008;
154
159
  const NodeWebSocket = WebSocket;
155
160
  function connectUrl(server) {
@@ -167,7 +172,8 @@ async function connect(options) {
167
172
  const maxBackoffMs = options.maxBackoffMs ?? 3e4;
168
173
  const emit = options.onEvent ?? (() => {});
169
174
  const signal = options.signal;
170
- let state = "idle";
175
+ const slots = options.slots ?? 1;
176
+ const busy = /* @__PURE__ */ new Set();
171
177
  let socket = null;
172
178
  let token = options.token;
173
179
  const pending = [];
@@ -179,7 +185,8 @@ async function connect(options) {
179
185
  const sendStatus = () => send({
180
186
  v: 1,
181
187
  type: "status",
182
- state
188
+ state: busy.size > 0 ? "busy" : "idle",
189
+ running: busy.size
183
190
  });
184
191
  const saveToken = (next) => {
185
192
  if (!options.saveToken) return;
@@ -199,15 +206,18 @@ async function connect(options) {
199
206
  });
200
207
  };
201
208
  const startJob = (run) => {
202
- if (state === "busy") {
209
+ let slot = 1;
210
+ while (busy.has(slot)) slot++;
211
+ if (slot > slots) {
203
212
  emit({
204
213
  type: "run-refused",
205
- routeId: run.routeId
214
+ routeId: run.routeId,
215
+ running: busy.size
206
216
  });
207
217
  const update = {
208
218
  routeId: run.routeId,
209
219
  state: "failed",
210
- message: "The machine is already running a job."
220
+ message: busy.size === 1 ? "The machine is already running a job." : `The machine is already running ${busy.size} jobs.`
211
221
  };
212
222
  send({
213
223
  v: 1,
@@ -218,14 +228,16 @@ async function connect(options) {
218
228
  }
219
229
  emit({
220
230
  type: "run",
221
- routeId: run.routeId
231
+ routeId: run.routeId,
232
+ slot
222
233
  });
223
- state = "busy";
234
+ busy.add(slot);
224
235
  sendStatus();
225
- options.runJob(run, (update) => {
236
+ options.runJob(run, slot, (update) => {
226
237
  emit({
227
238
  type: "job",
228
- update
239
+ update,
240
+ slot
229
241
  });
230
242
  send({
231
243
  v: 1,
@@ -233,7 +245,7 @@ async function connect(options) {
233
245
  ...update
234
246
  });
235
247
  }).finally(() => {
236
- state = "idle";
248
+ busy.delete(slot);
237
249
  sendStatus();
238
250
  });
239
251
  };
@@ -271,6 +283,7 @@ async function connect(options) {
271
283
  v: 1,
272
284
  type: "hello",
273
285
  ...options.hello,
286
+ slots,
274
287
  rotatesToken
275
288
  }));
276
289
  sendStatus();
@@ -1718,7 +1731,7 @@ const JOB_STATE = [
1718
1731
  ".credentials_rsaparams"
1719
1732
  ];
1720
1733
  async function runJob(run, options) {
1721
- const { runner, report } = options;
1734
+ const { dir, report } = options;
1722
1735
  const output = options.output ?? ((chunk, stream) => (stream === "stdout" ? process.stdout : process.stderr).write(chunk));
1723
1736
  const finish = (update) => {
1724
1737
  report(update);
@@ -1731,16 +1744,16 @@ async function runJob(run, options) {
1731
1744
  message: `Refused the job's runner config: ${checked.reason}.`
1732
1745
  });
1733
1746
  options.onChecked?.(checked.target);
1734
- const lock = join(runner.dir, "job.lock");
1747
+ const lock = join(dir, "job.lock");
1735
1748
  if (!takeLock(lock)) return finish({
1736
1749
  routeId: run.routeId,
1737
1750
  state: "failed",
1738
- message: `Another job is using the runner in ${runner.dir}.`
1751
+ message: `Another job is using the runner in ${dir}.`
1739
1752
  });
1740
1753
  try {
1741
- clean(runner.dir);
1742
- const child = spawn(join(runner.dir, "run.sh"), ["--jitconfig", run.jitConfig], {
1743
- cwd: runner.dir,
1754
+ clean(dir);
1755
+ const child = spawn(join(dir, "run.sh"), ["--jitconfig", run.jitConfig], {
1756
+ cwd: dir,
1744
1757
  env: runnerEnv(),
1745
1758
  stdio: [
1746
1759
  "ignore",
@@ -1780,7 +1793,7 @@ async function runJob(run, options) {
1780
1793
  message: error instanceof Error ? error.message : String(error)
1781
1794
  });
1782
1795
  } finally {
1783
- clean(runner.dir);
1796
+ clean(dir);
1784
1797
  rmSync(lock, { force: true });
1785
1798
  }
1786
1799
  }
@@ -1810,11 +1823,35 @@ function isAlive(pid) {
1810
1823
  return error.code === "EPERM";
1811
1824
  }
1812
1825
  }
1826
+ function prefixLines(prefix, write) {
1827
+ const partial = {
1828
+ stdout: "",
1829
+ stderr: ""
1830
+ };
1831
+ const output = (chunk, stream) => {
1832
+ const text = partial[stream] + chunk.toString();
1833
+ const end = text.lastIndexOf("\n") + 1;
1834
+ partial[stream] = text.slice(end);
1835
+ if (end === 0) return;
1836
+ const lines = text.slice(0, end).replace(/^(?=.)/gm, prefix);
1837
+ write(Buffer.from(lines), stream);
1838
+ };
1839
+ const flush = () => {
1840
+ for (const stream of ["stdout", "stderr"]) {
1841
+ if (partial[stream]) write(Buffer.from(`${prefix}${partial[stream]}\n`), stream);
1842
+ partial[stream] = "";
1843
+ }
1844
+ };
1845
+ return {
1846
+ output,
1847
+ flush
1848
+ };
1849
+ }
1813
1850
  // live.ts
1814
1851
  const INITIAL_STATE = {
1815
1852
  link: "connecting",
1816
1853
  paused: false,
1817
- job: null
1854
+ jobs: []
1818
1855
  };
1819
1856
  /** The state after a connection event. */
1820
1857
  function nextState(state, event) {
@@ -1833,11 +1870,11 @@ function nextState(state, event) {
1833
1870
  };
1834
1871
  case "run": return {
1835
1872
  ...state,
1836
- job: event.routeId
1873
+ jobs: [...state.jobs, event.routeId]
1837
1874
  };
1838
- case "job": return event.update.state === "started" || event.update.routeId !== state.job ? state : {
1875
+ case "job": return event.update.state === "started" || !state.jobs.includes(event.update.routeId) ? state : {
1839
1876
  ...state,
1840
- job: null
1877
+ jobs: state.jobs.filter((id) => id !== event.update.routeId)
1841
1878
  };
1842
1879
  case "paused": return {
1843
1880
  ...state,
@@ -1853,10 +1890,11 @@ function nextState(state, event) {
1853
1890
  function titleFor(state, machine) {
1854
1891
  return `RelayRunner · ${machine} · ${statusText(state)}`;
1855
1892
  }
1856
- function statusText({ link, paused, job }) {
1893
+ function statusText({ link, paused, jobs }) {
1894
+ const running = jobs.length === 1 ? "Running a job" : `Running ${jobs.length} jobs`;
1857
1895
  if (link === "connecting") return "Connecting…";
1858
- if (link === "reconnecting") return job ? "Running a job, reconnecting…" : "Reconnecting…";
1859
- if (job) return paused ? "Running a job, then paused" : "Running a job";
1896
+ if (link === "reconnecting") return jobs.length ? `${running}, reconnecting…` : "Reconnecting…";
1897
+ if (jobs.length) return paused ? `${running}, then paused` : running;
1860
1898
  return paused ? "Paused" : "Waiting for jobs";
1861
1899
  }
1862
1900
  const ESC = "\x1B";
@@ -1922,6 +1960,86 @@ function startLive(options) {
1922
1960
  }
1923
1961
  };
1924
1962
  }
1963
+ // update-check.ts
1964
+ const CHECK_INTERVAL_MS = 864e5;
1965
+ const REGISTRY_URL = "https://registry.npmjs.org/relayrunner/latest";
1966
+ const TIMEOUT_MS = 3e3;
1967
+ const Cache = z.object({
1968
+ checkedAt: z.number(),
1969
+ latest: z.string()
1970
+ });
1971
+ /** The newer version npm has, or null when this CLI is current or the check couldn't tell. */
1972
+ async function checkForUpdate(options = {}) {
1973
+ const now = options.now ?? Date.now();
1974
+ const current = options.current ?? cliVersion;
1975
+ let cache = readCache();
1976
+ if (!cache || now - cache.checkedAt >= 864e5) {
1977
+ const latest = await fetchLatest(options.fetch ?? fetch);
1978
+ if (latest) {
1979
+ cache = {
1980
+ checkedAt: now,
1981
+ latest
1982
+ };
1983
+ writeCache(cache);
1984
+ }
1985
+ }
1986
+ return cache && isNewer(cache.latest, current) ? cache.latest : null;
1987
+ }
1988
+ /** The line to print for a newer version, with the command that updates the way this one runs. */
1989
+ function updateNotice(latest, current = cliVersion, argv1 = process.argv[1] ?? "") {
1990
+ return `relayrunner ${latest} is available (you have ${current}). Update with \`${/[\\/]_npx[\\/]/.test(argv1) ? "npx relayrunner@latest connect" : "npm install --global relayrunner@latest"}\`.`;
1991
+ }
1992
+ function isNewer(candidate, current) {
1993
+ const a = parse(candidate);
1994
+ const b = parse(current);
1995
+ if (!a || !b) return false;
1996
+ for (let i = 0; i < 3; i++) if (a[i] !== b[i]) return a[i] > b[i];
1997
+ return false;
1998
+ }
1999
+ function parse(version) {
2000
+ const match = /^(\d+)\.(\d+)\.(\d+)$/.exec(version.trim());
2001
+ return match ? [
2002
+ Number(match[1]),
2003
+ Number(match[2]),
2004
+ Number(match[3])
2005
+ ] : null;
2006
+ }
2007
+ async function fetchLatest(fetcher) {
2008
+ try {
2009
+ const response = await fetcher(REGISTRY_URL, {
2010
+ headers: {
2011
+ accept: "application/json",
2012
+ "user-agent": userAgent
2013
+ },
2014
+ signal: AbortSignal.timeout(TIMEOUT_MS)
2015
+ });
2016
+ if (!response.ok) {
2017
+ await response.body?.cancel();
2018
+ return null;
2019
+ }
2020
+ const body = z.object({ version: z.string() }).safeParse(await response.json());
2021
+ return body.success ? body.data.version : null;
2022
+ } catch {
2023
+ return null;
2024
+ }
2025
+ }
2026
+ function cachePath() {
2027
+ return join(relayrunnerHome(), "update-check.json");
2028
+ }
2029
+ function readCache() {
2030
+ try {
2031
+ const parsed = Cache.safeParse(JSON.parse(readFileSync(cachePath(), "utf8")));
2032
+ return parsed.success ? parsed.data : null;
2033
+ } catch {
2034
+ return null;
2035
+ }
2036
+ }
2037
+ function writeCache(cache) {
2038
+ try {
2039
+ mkdirSync(relayrunnerHome(), { recursive: true });
2040
+ writeFileSync(cachePath(), `${JSON.stringify(cache)}\n`);
2041
+ } catch {}
2042
+ }
1925
2043
  // workspaces.ts
1926
2044
  const Workspace = z.object({
1927
2045
  id: z.string().min(1),
@@ -2131,6 +2249,62 @@ function pauseMachine(credentials, paused) {
2131
2249
  paused
2132
2250
  }));
2133
2251
  }
2252
+ // slots.ts
2253
+ const MAX_SLOTS = 1e3;
2254
+ function defaultConcurrency(cores = availableParallelism()) {
2255
+ return cores >= 8 ? 2 : 1;
2256
+ }
2257
+ function parseConcurrency(value, cores) {
2258
+ if (value === void 0 || value === "") return defaultConcurrency(cores);
2259
+ const n = Number(value);
2260
+ if (!/^\d+$/.test(value.trim()) || !Number.isSafeInteger(n) || n < 1 || n > 1e3) throw new Error(`--concurrency takes a whole number from 1 to ${MAX_SLOTS}, not "${value}".`);
2261
+ return n;
2262
+ }
2263
+ function slotDir(runner, slot) {
2264
+ return join(runner.dir, `slot-${slot}`);
2265
+ }
2266
+ function ensureSlots(runner, count, log = () => {}) {
2267
+ const dirs = [];
2268
+ const missing = [];
2269
+ for (let slot = 1; slot <= count; slot++) {
2270
+ const dir = slotDir(runner, slot);
2271
+ dirs.push(dir);
2272
+ if (!existsSync(join(dir, "run.sh"))) missing.push(slot);
2273
+ }
2274
+ if (missing.length > 0) log(missing.length === 1 ? `Setting up runner slot ${missing[0]}…` : `Setting up ${missing.length} runner slots…`);
2275
+ for (const slot of missing) copySlot(runner.dir, slotDir(runner, slot));
2276
+ return dirs;
2277
+ }
2278
+ const SKIP = /^(slot-\d+|\.slot-.*|_work|_diag|\.runner|\.credentials.*|job\.lock)$/;
2279
+ function copySlot(source, dir) {
2280
+ rmSync(dir, {
2281
+ recursive: true,
2282
+ force: true
2283
+ });
2284
+ const temp = mkdtempSync(join(source, `.${basename(dir)}-`));
2285
+ try {
2286
+ for (const name of readdirSync(source)) {
2287
+ if (SKIP.test(name)) continue;
2288
+ cpSync(join(source, name), join(temp, name), {
2289
+ recursive: true,
2290
+ mode: constants.COPYFILE_FICLONE,
2291
+ verbatimSymlinks: true,
2292
+ preserveTimestamps: true
2293
+ });
2294
+ }
2295
+ try {
2296
+ renameSync(temp, dir);
2297
+ } catch (error) {
2298
+ const code = error.code;
2299
+ if (code !== "EEXIST" && code !== "ENOTEMPTY") throw error;
2300
+ }
2301
+ } finally {
2302
+ rmSync(temp, {
2303
+ recursive: true,
2304
+ force: true
2305
+ });
2306
+ }
2307
+ }
2134
2308
  // share.ts
2135
2309
  const SHARE_CHOICES = ["only-me", "anyone"];
2136
2310
  const MachineSharing = z.enum(["only_me", "anyone"]);
@@ -2256,12 +2430,27 @@ const connectCommand = defineCommand({
2256
2430
  share: {
2257
2431
  type: "string",
2258
2432
  description: "Who can run jobs on this machine: only-me (jobs you started) or anyone in your workspaces. Skips the question."
2433
+ },
2434
+ concurrency: {
2435
+ type: "string",
2436
+ description: "How many jobs to run at once (default: 2 with 8 or more CPU cores, otherwise 1)"
2259
2437
  }
2260
2438
  },
2261
2439
  async run({ args }) {
2262
2440
  clack.intro("RelayRunner");
2441
+ let concurrency;
2263
2442
  try {
2264
- await connectMachine(args);
2443
+ concurrency = parseConcurrency(args.concurrency);
2444
+ } catch (error) {
2445
+ clack.log.error(error.message);
2446
+ process.exitCode = 1;
2447
+ return;
2448
+ }
2449
+ try {
2450
+ await connectMachine({
2451
+ ...args,
2452
+ concurrency
2453
+ });
2265
2454
  } catch (error) {
2266
2455
  if (!(error instanceof LoginError || error instanceof RunnerError)) throw error;
2267
2456
  clack.log.error(error.message);
@@ -2284,7 +2473,19 @@ async function connectMachine(args) {
2284
2473
  if (share) await applySharing(credentials, share, null);
2285
2474
  }
2286
2475
  if (process.stdin.isTTY && process.stdout.isTTY) await offerSetup();
2476
+ let updateTimer;
2477
+ if (process.stdout.isTTY && !process.env.CI) {
2478
+ const notifyUpdate = () => void checkForUpdate().then((latest) => {
2479
+ if (latest) clack.log.warn(updateNotice(latest));
2480
+ });
2481
+ notifyUpdate();
2482
+ updateTimer = setInterval(notifyUpdate, CHECK_INTERVAL_MS);
2483
+ updateTimer.unref();
2484
+ }
2287
2485
  const runner = await ensureRunner({ log: (line) => clack.log.info(line) });
2486
+ const slots = args.concurrency;
2487
+ const slotDirs = ensureSlots(runner, slots, (line) => clack.log.info(line));
2488
+ clack.log.info(slots === 1 ? "Running 1 job at a time. Change with --concurrency." : `Running up to ${slots} jobs at once. Change with --concurrency.`);
2288
2489
  const device = await detectDevice();
2289
2490
  const stop = new AbortController();
2290
2491
  const enrolled = credentials;
@@ -2317,24 +2518,35 @@ async function connectMachine(args) {
2317
2518
  machineId: credentials.machine.id,
2318
2519
  ...platform,
2319
2520
  runnerVersion: runner.version,
2521
+ cliVersion,
2320
2522
  device
2321
2523
  },
2322
- runJob: (run, report) => runJob(run, {
2323
- runner,
2324
- report,
2325
- onChecked: (target) => {
2326
- if (target) clack.log.info(`${(/* @__PURE__ */ new Date()).toLocaleTimeString()} Job ${run.routeId} is from ${target}`);
2524
+ slots,
2525
+ runJob: async (run, slot, report) => {
2526
+ const prefixed = slots > 1 ? prefixLines(`[slot ${slot}] `, (chunk, stream) => (stream === "stdout" ? process.stdout : process.stderr).write(chunk)) : void 0;
2527
+ try {
2528
+ return await runJob(run, {
2529
+ dir: slotDirs[slot - 1],
2530
+ report,
2531
+ output: prefixed?.output,
2532
+ onChecked: (target) => {
2533
+ if (target) clack.log.info(`${(/* @__PURE__ */ new Date()).toLocaleTimeString()} Job ${run.routeId}${slots > 1 ? ` (slot ${slot})` : ""} is from ${target}`);
2534
+ }
2535
+ });
2536
+ } finally {
2537
+ prefixed?.flush();
2327
2538
  }
2328
- }),
2539
+ },
2329
2540
  saveToken: (token) => saveRotatedToken(credentials, token),
2330
2541
  onEvent: (event) => {
2331
2542
  if (event.type === "connected") online = true;
2332
- show(event);
2543
+ show(event, slots > 1);
2333
2544
  live.onEvent(event);
2334
2545
  },
2335
2546
  signal: stop.signal
2336
2547
  });
2337
2548
  } finally {
2549
+ clearInterval(updateTimer);
2338
2550
  live.end();
2339
2551
  process.off("SIGINT", onInterrupt);
2340
2552
  }
@@ -2499,7 +2711,7 @@ async function signIn(server, name, platform) {
2499
2711
  throw error;
2500
2712
  }
2501
2713
  }
2502
- function show(event) {
2714
+ function show(event, slotted) {
2503
2715
  const at = (/* @__PURE__ */ new Date()).toLocaleTimeString();
2504
2716
  switch (event.type) {
2505
2717
  case "connecting":
@@ -2515,7 +2727,7 @@ function show(event) {
2515
2727
  clack.log.error(`${at} Gateway: ${event.message}`);
2516
2728
  break;
2517
2729
  case "run":
2518
- clack.log.step(`${at} Starting job ${event.routeId}`);
2730
+ clack.log.step(`${at} Starting job ${event.routeId}${slotted ? ` in slot ${event.slot}` : ""}`);
2519
2731
  break;
2520
2732
  case "paused":
2521
2733
  if (event.paused) clack.log.warn(`${at} Paused${event.by ? ` by ${event.by}` : ""}. Staying online, but new jobs skip this machine until it's resumed.${process.stdin.isTTY ? " Press p to resume." : ""}`);
@@ -2525,11 +2737,11 @@ function show(event) {
2525
2737
  clack.log.warn(`${at} Couldn't save the machine's new token (${event.message}). Keeping the old one.`);
2526
2738
  break;
2527
2739
  case "run-refused":
2528
- clack.log.warn(`${at} Turned down job ${event.routeId}: already running one.`);
2740
+ clack.log.warn(`${at} Turned down job ${event.routeId}: already running ${event.running === 1 ? "one" : `${event.running}`}.`);
2529
2741
  break;
2530
2742
  case "job": {
2531
2743
  const { routeId, state, message } = event.update;
2532
- const line = `${at} Job ${routeId} ${state}${message ? `: ${message}` : ""}`;
2744
+ const line = `${at} Job ${routeId}${slotted ? ` (slot ${event.slot})` : ""} ${state}${message ? `: ${message}` : ""}`;
2533
2745
  if (state === "failed") clack.log.error(line);
2534
2746
  else if (state === "finished") clack.log.success(line);
2535
2747
  else clack.log.info(line);
@@ -2718,6 +2930,7 @@ const shareCommand = defineCommand({
2718
2930
  const main = defineCommand({
2719
2931
  meta: {
2720
2932
  name: "relayrunner",
2933
+ version: cliVersion,
2721
2934
  description: "Run GitHub Actions jobs on your machine through the RelayRunner gateway."
2722
2935
  },
2723
2936
  subCommands: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "relayrunner",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Run GitHub Actions jobs on your machine through the RelayRunner gateway.",
5
5
  "repository": {
6
6
  "type": "git",