relayrunner 0.10.0 → 0.10.1

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 +2 -1
  2. package/dist/cli.js +271 -10
  3. package/package.json +2 -1
package/README.md CHANGED
@@ -11,7 +11,8 @@ npm install --global relayrunner # or use npx relayrunner
11
11
 
12
12
  Machines only take jobs from private repositories. To opt jobs in, see the
13
13
  [root README](../../README.md#how-it-works) or
14
- [docs/agent-install.md](../../docs/agent-install.md).
14
+ [docs/agent-install.md](../../docs/agent-install.md). To teach your coding
15
+ agent the CLI, see the [agent skills](../../skills).
15
16
 
16
17
  ## `relayrunner connect`
17
18
 
package/dist/cli.js CHANGED
@@ -184,7 +184,7 @@ function parse(version) {
184
184
  ] : null;
185
185
  }
186
186
  // version.ts
187
- const cliVersion = "0.10.0";
187
+ const cliVersion = "0.10.1";
188
188
  // paths.ts
189
189
  function relayrunnerHome() {
190
190
  return resolve(process.env.RELAYRUNNER_HOME || join(homedir(), ".relayrunner"));
@@ -2604,6 +2604,261 @@ function sharingScope(workspaces) {
2604
2604
  function noWorkspaceYet(machine, server) {
2605
2605
  return [`${machine} isn't in a workspace yet. It takes jobs once RelayRunner is installed on a GitHub account or org you belong to, or once an org owner accepts your install request.`, `Install: ${new URL("/api/github/install", server)}`].join("\n");
2606
2606
  }
2607
+ // ../../packages/errors/src/codes.ts
2608
+ /**
2609
+ * Every error code the API can return. A code never changes once it ships; its message can.
2610
+ * Feature-specific codes read `DOMAIN_FAILURE`, so the code alone names the feature and what
2611
+ * went wrong. Add a code here before returning it: apps/site builds the errors page and the
2612
+ * OpenAPI enum from this list.
2613
+ */
2614
+ const ERRORS = {
2615
+ INVALID_REQUEST: {
2616
+ status: 400,
2617
+ message: "The request isn't valid."
2618
+ },
2619
+ PAYLOAD_TOO_LARGE: {
2620
+ status: 413,
2621
+ message: "The request body is too large."
2622
+ },
2623
+ NOT_FOUND: {
2624
+ status: 404,
2625
+ message: "Not found."
2626
+ },
2627
+ METHOD_NOT_ALLOWED: {
2628
+ status: 405,
2629
+ message: "That method isn't allowed here."
2630
+ },
2631
+ RATE_LIMITED: {
2632
+ status: 429,
2633
+ message: "Too many requests. Try again shortly."
2634
+ },
2635
+ INTERNAL_ERROR: {
2636
+ status: 500,
2637
+ message: "Something went wrong on our side."
2638
+ },
2639
+ UNAUTHENTICATED: {
2640
+ status: 401,
2641
+ message: "Sign in first."
2642
+ },
2643
+ INVALID_TOKEN: {
2644
+ status: 401,
2645
+ message: "The token is invalid, expired or revoked."
2646
+ },
2647
+ FORBIDDEN: {
2648
+ status: 403,
2649
+ message: "You don't have access to that."
2650
+ },
2651
+ AGENT_NOT_ALLOWED: {
2652
+ status: 403,
2653
+ message: "Agent tokens can't call this route."
2654
+ },
2655
+ NOT_A_MEMBER: {
2656
+ status: 403,
2657
+ message: "You aren't a member of that workspace."
2658
+ },
2659
+ LEGAL_TERMS_OUTDATED: {
2660
+ status: 409,
2661
+ message: "The terms changed since you opened this page. Reload it to read the new version."
2662
+ },
2663
+ NO_ACTIVE_WORKSPACE: {
2664
+ status: 409,
2665
+ message: "Pick a workspace first."
2666
+ },
2667
+ WORKSPACE_REQUIRED: {
2668
+ status: 409,
2669
+ message: "This token reads more than one workspace. Name one with the x-relayrunner-workspace header."
2670
+ },
2671
+ CANNOT_DEMOTE_SELF: {
2672
+ status: 400,
2673
+ message: "You can't remove your own operator role."
2674
+ },
2675
+ CANNOT_DELETE_SELF: {
2676
+ status: 400,
2677
+ message: "You can't delete your own account here."
2678
+ },
2679
+ USER_HAS_SHARED_WORKSPACES: {
2680
+ status: 409,
2681
+ message: "The user is in workspaces with other members. Remove them from those first."
2682
+ },
2683
+ MACHINE_NOT_OWNED: {
2684
+ status: 403,
2685
+ message: "Only a machine with an owner can do this."
2686
+ },
2687
+ DEVICE_CODE_INVALID: {
2688
+ status: 400,
2689
+ message: "That code doesn't match a sign-in request. Check it against your terminal."
2690
+ },
2691
+ DEVICE_CODE_EXPIRED: {
2692
+ status: 400,
2693
+ message: "That code has expired. Run `relayrunner connect` again for a new one."
2694
+ },
2695
+ DEVICE_CODE_USED: {
2696
+ status: 409,
2697
+ message: "That code has already been used."
2698
+ },
2699
+ DEVICE_CODE_CLAIMED: {
2700
+ status: 403,
2701
+ message: "Another account already approved or denied this request. Run `relayrunner connect` again for a new code."
2702
+ },
2703
+ WEBSOCKET_REQUIRED: {
2704
+ status: 426,
2705
+ message: "Connect with a WebSocket upgrade."
2706
+ },
2707
+ RUNNER_ORDER_INVALID: {
2708
+ status: 400,
2709
+ message: "The runner order isn't valid."
2710
+ },
2711
+ PROVIDER_UNKNOWN: {
2712
+ status: 400,
2713
+ message: "There's no provider with that id."
2714
+ },
2715
+ PROVIDER_INVALID: {
2716
+ status: 400,
2717
+ message: "Fill in a name, summary and labels, and use https:// links."
2718
+ },
2719
+ PROVIDER_ID_INVALID: {
2720
+ status: 400,
2721
+ message: "Use lowercase letters, numbers and dashes for the id."
2722
+ },
2723
+ PROVIDER_PREFIXES_INVALID: {
2724
+ status: 400,
2725
+ message: "Add at least one label prefix, three or more characters each."
2726
+ },
2727
+ PROVIDER_EXISTS: {
2728
+ status: 409,
2729
+ message: "There's already a provider with that id."
2730
+ },
2731
+ PROVIDER_PREFIX_TAKEN: {
2732
+ status: 409,
2733
+ message: "Another provider, or GitHub's own runners, already use labels like that."
2734
+ },
2735
+ PROVIDER_NOT_CONNECTED: {
2736
+ status: 404,
2737
+ message: "That provider isn't connected."
2738
+ },
2739
+ PROVIDER_TOKEN_REJECTED: {
2740
+ status: 400,
2741
+ message: "The provider didn't accept that token. Check it and its scope."
2742
+ },
2743
+ PROVIDER_UNREACHABLE: {
2744
+ status: 502,
2745
+ message: "The provider's API didn't answer. Try again shortly."
2746
+ },
2747
+ PRICE_INVALID: {
2748
+ status: 400,
2749
+ message: "Check the price and date."
2750
+ },
2751
+ PRICE_EXISTS: {
2752
+ status: 409,
2753
+ message: "That rate already has a price from that day. Remove it first to correct it."
2754
+ },
2755
+ TOKEN_STORAGE_UNAVAILABLE: {
2756
+ status: 503,
2757
+ message: "Saving provider tokens isn't set up on this server yet."
2758
+ },
2759
+ TELEMETRY_ENDPOINT_INVALID: {
2760
+ status: 400,
2761
+ message: "Use an https URL on the internet, like https://api.honeycomb.io."
2762
+ },
2763
+ TELEMETRY_HEADER_MISSING: {
2764
+ status: 400,
2765
+ message: "Enter a value for each header."
2766
+ },
2767
+ TELEMETRY_NOT_CONFIGURED: {
2768
+ status: 404,
2769
+ message: "Telemetry isn't set up for this workspace."
2770
+ },
2771
+ WEBHOOK_SIGNATURE_INVALID: {
2772
+ status: 401,
2773
+ message: "The webhook signature is missing or doesn't match the App's secret."
2774
+ },
2775
+ WEBHOOK_SECRET_NOT_CONFIGURED: {
2776
+ status: 500,
2777
+ message: "The webhook secret for this App isn't set up on this server."
2778
+ },
2779
+ WEBHOOK_ENQUEUE_FAILED: {
2780
+ status: 503,
2781
+ message: "The delivery couldn't be queued. Redeliver it from the App's settings."
2782
+ },
2783
+ GITHUB_UNAVAILABLE: {
2784
+ status: 502,
2785
+ message: "GitHub didn't answer. Try again shortly."
2786
+ },
2787
+ GITHUB_RATE_LIMITED: {
2788
+ status: 503,
2789
+ message: "GitHub's API limit was reached. Try again shortly."
2790
+ },
2791
+ GITHUB_APP_NOT_CONFIGURED: {
2792
+ status: 500,
2793
+ message: "The GitHub App isn't set up."
2794
+ }
2795
+ };
2796
+ function isErrorCode(code) {
2797
+ return typeof code === "string" && Object.hasOwn(ERRORS, code);
2798
+ }
2799
+ // ../../packages/errors/src/app-error.ts
2800
+ /**
2801
+ * A failure with a stable code. Throw it from an API route and the API's error handler answers
2802
+ * with the code's status and an {@link ErrorBody}; clients get one back from {@link parseError}.
2803
+ */
2804
+ var AppError = class extends Error {
2805
+ /** A string rather than ErrorCode: a client can receive codes added after it was built. */
2806
+ code;
2807
+ status;
2808
+ details;
2809
+ retryAfter;
2810
+ constructor(code, options = {}) {
2811
+ super(options.message ?? ERRORS[code].message, { cause: options.cause });
2812
+ this.name = "AppError";
2813
+ this.code = code;
2814
+ this.status = ERRORS[code].status;
2815
+ this.details = options.details;
2816
+ this.retryAfter = options.retryAfter;
2817
+ }
2818
+ toJSON() {
2819
+ return { error: {
2820
+ code: this.code,
2821
+ message: this.message,
2822
+ ...this.details === void 0 ? {} : { details: this.details }
2823
+ } };
2824
+ }
2825
+ };
2826
+ /** Whether a response body is an {@link ErrorBody}. */
2827
+ function isErrorBody(body) {
2828
+ const error = body?.error;
2829
+ return typeof error === "object" && error !== null && typeof error.code === "string" && typeof error.message === "string";
2830
+ }
2831
+ /**
2832
+ * Reads a non-2xx response body as an AppError. Never throws: a body that isn't an
2833
+ * {@link ErrorBody} (a proxy's HTML page, an empty body) keeps the status with a generic message.
2834
+ */
2835
+ function parseError(body, status) {
2836
+ const { code, message, details } = isErrorBody(body) ? body.error : {
2837
+ code: "INTERNAL_ERROR",
2838
+ message: `The request failed with status ${status}.`,
2839
+ details: void 0
2840
+ };
2841
+ const parsed = new AppError(isErrorCode(code) ? code : "INTERNAL_ERROR", {
2842
+ message,
2843
+ details
2844
+ });
2845
+ return Object.assign(parsed, {
2846
+ status,
2847
+ code
2848
+ });
2849
+ }
2850
+ /** An error in one line for an agent or a terminal: "Not found (NOT_FOUND)". */
2851
+ function describeError(error) {
2852
+ return `${error.message.replace(/\.$/, "")} (${error.code})`;
2853
+ }
2854
+ // api-error.ts
2855
+ /**
2856
+ * Why a request to the gateway failed, for "Couldn't …: <reason>.": the API's message and error
2857
+ * code when it sent one (@relayrunner/errors), else the HTTP status.
2858
+ */
2859
+ function failureReason(server, status, body) {
2860
+ return isErrorBody(body) ? describeError(parseError(body, status)) : `${server} answered HTTP ${status}`;
2861
+ }
2607
2862
  // login.ts
2608
2863
  const CLIENT_ID = "relayrunner-cli";
2609
2864
  const DEVICE_GRANT = "urn:ietf:params:oauth:grant-type:device_code";
@@ -2701,7 +2956,10 @@ async function login(options) {
2701
2956
  deviceCode: code.device_code,
2702
2957
  ...options.platform
2703
2958
  }, { authorization: `Bearer ${accessToken}` });
2704
- if (!claimResponse.ok) throw new LoginError("CLAIM_FAILED", `The gateway approved the sign-in but wouldn't enroll this machine (HTTP ${claimResponse.status}).`);
2959
+ if (!claimResponse.ok) {
2960
+ const body = await claimResponse.json().catch(() => null);
2961
+ throw new LoginError("CLAIM_FAILED", `The gateway approved the sign-in but wouldn't enroll this machine: ${failureReason(options.server, claimResponse.status, body)}.`);
2962
+ }
2705
2963
  const claimed = ClaimResponse.parse(await claimResponse.json());
2706
2964
  return {
2707
2965
  credentials: {
@@ -2757,11 +3015,12 @@ async function setPaused(options) {
2757
3015
  };
2758
3016
  }
2759
3017
  if (response.status === 401) return { status: "revoked" };
3018
+ const body = await response.json().catch(() => null);
2760
3019
  if (!response.ok) return {
2761
3020
  status: "failed",
2762
- reason: `${options.server} answered HTTP ${response.status}`
3021
+ reason: failureReason(options.server, response.status, body)
2763
3022
  };
2764
- const parsed = PauseResponse.safeParse(await response.json().catch(() => null));
3023
+ const parsed = PauseResponse.safeParse(body);
2765
3024
  if (!parsed.success) return {
2766
3025
  status: "failed",
2767
3026
  reason: `${options.server} sent an unexpected response`
@@ -2876,11 +3135,12 @@ async function setSharing(options) {
2876
3135
  status: "failed",
2877
3136
  reason: `${options.server} doesn't support sharing yet`
2878
3137
  };
3138
+ const body = await response.json().catch(() => null);
2879
3139
  if (!response.ok) return {
2880
3140
  status: "failed",
2881
- reason: `${options.server} answered HTTP ${response.status}`
3141
+ reason: failureReason(options.server, response.status, body)
2882
3142
  };
2883
- const parsed = SharingResponse.safeParse(await response.json().catch(() => null));
3143
+ const parsed = SharingResponse.safeParse(body);
2884
3144
  if (!parsed.success) return {
2885
3145
  status: "failed",
2886
3146
  reason: `${options.server} sent an unexpected response`
@@ -3046,11 +3306,12 @@ async function whoami(options) {
3046
3306
  };
3047
3307
  }
3048
3308
  if (response.status === 401) return { status: "revoked" };
3309
+ const body = await response.json().catch(() => null);
3049
3310
  if (!response.ok) return {
3050
3311
  status: "unverified",
3051
- reason: `${options.server} answered HTTP ${response.status}`
3312
+ reason: failureReason(options.server, response.status, body)
3052
3313
  };
3053
- const parsed = WhoamiResponse.safeParse(await response.json().catch(() => null));
3314
+ const parsed = WhoamiResponse.safeParse(body);
3054
3315
  if (!parsed.success) return {
3055
3316
  status: "unverified",
3056
3317
  reason: `${options.server} sent an unexpected response`
@@ -3098,7 +3359,7 @@ async function machineWorkspaces(options) {
3098
3359
  }
3099
3360
  if (response.status === 401) return { status: "revoked" };
3100
3361
  const body = await response.json().catch(() => null);
3101
- if (change && response.status === 404 && body?.error === "not_found") return { status: "not_found" };
3362
+ if (change && response.status === 404 && isErrorBody(body) && body.error.code === "NOT_FOUND") return { status: "not_found" };
3102
3363
  if (response.status === 404 || response.status === 405) return {
3103
3364
  status: "failed",
3104
3365
  reason: `${options.server} doesn't support choosing workspaces yet`
@@ -3109,7 +3370,7 @@ async function machineWorkspaces(options) {
3109
3370
  };
3110
3371
  if (!response.ok) return {
3111
3372
  status: "failed",
3112
- reason: `${options.server} answered HTTP ${response.status}`
3373
+ reason: failureReason(options.server, response.status, body)
3113
3374
  };
3114
3375
  const parsed = MachineWorkspaces.safeParse(body);
3115
3376
  if (!parsed.success) return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "relayrunner",
3
- "version": "0.10.0",
3
+ "version": "0.10.1",
4
4
  "description": "Run GitHub Actions jobs on your machine through the RelayRunner gateway.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -25,6 +25,7 @@
25
25
  "zod": "^4.6.7"
26
26
  },
27
27
  "devDependencies": {
28
+ "@relayrunner/errors": "0.0.0",
28
29
  "@relayrunner/machine-protocol": "0.0.0",
29
30
  "@relayrunner/providers": "0.0.0",
30
31
  "@types/ws": "^8.18.2",