@rebasepro/cli 0.28.0 → 0.28.2

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.
@@ -4996,7 +4996,7 @@ function stateColor(state) {
4996
4996
  }
4997
4997
  /** The flags `cron list` parses — the help page lists exactly these. */
4998
4998
  var CRON_LIST_FLAGS = { "--host": String };
4999
- async function listCommand$1(rawArgs) {
4999
+ async function listCommand$2(rawArgs) {
5000
5000
  parseCloudArgs({
5001
5001
  spec: CRON_LIST_FLAGS,
5002
5002
  rawArgs,
@@ -5102,7 +5102,7 @@ async function cronCommand(action, rawArgs) {
5102
5102
  await logsCommand$1(rawArgs);
5103
5103
  return;
5104
5104
  }
5105
- await listCommand$1(rawArgs);
5105
+ await listCommand$2(rawArgs);
5106
5106
  }
5107
5107
  //#endregion
5108
5108
  //#region src/commands/cloud/env.ts
@@ -6416,11 +6416,11 @@ async function uploadBundle(url, token, projectId, tarPath) {
6416
6416
  if (!data.bundleId) throw new Error("Bundle upload endpoint did not return a bundle id.");
6417
6417
  return data.bundleId;
6418
6418
  }
6419
- function isRecord$1(value) {
6419
+ function isRecord$2(value) {
6420
6420
  return typeof value === "object" && value !== null && !Array.isArray(value);
6421
6421
  }
6422
6422
  function recordFrom(value) {
6423
- if (!isRecord$1(value) || typeof value.type !== "string" || typeof value.name !== "string") return null;
6423
+ if (!isRecord$2(value) || typeof value.type !== "string" || typeof value.name !== "string") return null;
6424
6424
  const values = Array.isArray(value.values) ? value.values.filter((v) => typeof v === "string") : [];
6425
6425
  return values.length > 0 ? {
6426
6426
  type: value.type,
@@ -6439,10 +6439,10 @@ function recordFrom(value) {
6439
6439
  * not print as live.
6440
6440
  */
6441
6441
  function deployHostsFrom(response) {
6442
- if (!isRecord$1(response) || !Array.isArray(response.hosts)) return void 0;
6442
+ if (!isRecord$2(response) || !Array.isArray(response.hosts)) return void 0;
6443
6443
  const hosts = [];
6444
6444
  for (const entry of response.hosts) {
6445
- if (!isRecord$1(entry) || typeof entry.host !== "string" || entry.host === "") continue;
6445
+ if (!isRecord$2(entry) || typeof entry.host !== "string" || entry.host === "") continue;
6446
6446
  const records = Array.isArray(entry.records) ? entry.records.map(recordFrom).filter((r) => r !== null) : [];
6447
6447
  hosts.push({
6448
6448
  host: entry.host,
@@ -7372,7 +7372,7 @@ function normalizePreviewName(raw) {
7372
7372
  if (name.includes("--")) usage("`--` is what separates it from the project's name in the address");
7373
7373
  return name;
7374
7374
  }
7375
- function isRecord(value) {
7375
+ function isRecord$1(value) {
7376
7376
  return typeof value === "object" && value !== null && !Array.isArray(value);
7377
7377
  }
7378
7378
  function text(row, ...keys) {
@@ -7388,7 +7388,7 @@ function text(row, ...keys) {
7388
7388
  * address, which is the one field a preview cannot be reported without.
7389
7389
  */
7390
7390
  function previewFrom(value) {
7391
- if (!isRecord(value)) return null;
7391
+ if (!isRecord$1(value)) return null;
7392
7392
  const name = text(value, "name");
7393
7393
  const url = text(value, "url");
7394
7394
  if (!name || !url) return null;
@@ -7429,7 +7429,7 @@ function previewsUnavailable(e) {
7429
7429
  */
7430
7430
  var PREVIEW_STATIC_UNSERVED = "PREVIEW_STATIC_UNSERVED";
7431
7431
  function intakeCodeOf(e) {
7432
- if (!isRecord(e) || !isRecord(e.details)) return void 0;
7432
+ if (!isRecord$1(e) || !isRecord$1(e.details)) return void 0;
7433
7433
  return typeof e.details.intakeCode === "string" ? e.details.intakeCode : void 0;
7434
7434
  }
7435
7435
  /**
@@ -7462,9 +7462,9 @@ async function triggerPreview(client, projectId, body, refusal) {
7462
7462
  refusal(e);
7463
7463
  reportError(e, "Preview deploy failed to start");
7464
7464
  }
7465
- const deployment = isRecord(res) && isRecord(res.deployment) ? res.deployment : void 0;
7465
+ const deployment = isRecord$1(res) && isRecord$1(res.deployment) ? res.deployment : void 0;
7466
7466
  const deploymentId = deployment ? text(deployment, "id") : null;
7467
- const preview = isRecord(res) ? previewFrom(res.preview) : null;
7467
+ const preview = isRecord$1(res) ? previewFrom(res.preview) : null;
7468
7468
  if (!deploymentId || !preview) fail("The control plane started a preview but did not say where it will be served.", "Run `rebase cloud previews` to find it.", "invalid_response");
7469
7469
  return {
7470
7470
  deploymentId,
@@ -7488,7 +7488,7 @@ var PREVIEW_PRICING_DOCS = "https://rebase.pro/docs/deployment/cloud/#preview-a-
7488
7488
  /** The billing rule in words: what is printed when the control plane cannot put a number on it. */
7489
7489
  var PREVIEW_PRICING_RULE = "A backend preview is billed like one app unit at the default size, at your app's rate for its region and capacity, prorated for as long as it exists.";
7490
7490
  function quoteAnswerFrom(value) {
7491
- if (!isRecord(value) || typeof value.totalEur !== "number" || !Number.isFinite(value.totalEur)) return null;
7491
+ if (!isRecord$1(value) || typeof value.totalEur !== "number" || !Number.isFinite(value.totalEur)) return null;
7492
7492
  return {
7493
7493
  totalEur: value.totalEur,
7494
7494
  backendPreviews: typeof value.backendPreviews === "number" ? value.backendPreviews : void 0
@@ -7525,13 +7525,13 @@ async function previewCost(client, url, projectId) {
7525
7525
  } catch {
7526
7526
  return cost;
7527
7527
  }
7528
- if (!isRecord(project)) return cost;
7528
+ if (!isRecord$1(project)) return cost;
7529
7529
  try {
7530
7530
  const res = await client.functions.invoke(PREVIEWS_FUNCTION, void 0, {
7531
7531
  method: "GET",
7532
7532
  path: projectId
7533
7533
  });
7534
- const rows = isRecord(res) && Array.isArray(res.previews) ? res.previews : void 0;
7534
+ const rows = isRecord$1(res) && Array.isArray(res.previews) ? res.previews : void 0;
7535
7535
  if (rows) cost.backendPreviews = Math.max(1, rows.map(previewFrom).filter((p) => p !== null && p.backend !== "production").length);
7536
7536
  } catch {}
7537
7537
  const counts = [0, 1];
@@ -7551,7 +7551,7 @@ async function previewCost(client, url, projectId) {
7551
7551
  });
7552
7552
  if (!res.ok) return cost;
7553
7553
  const body = await res.json();
7554
- quotes = isRecord(body) && Array.isArray(body.quotes) ? body.quotes.map(quoteAnswerFrom) : [];
7554
+ quotes = isRecord$1(body) && Array.isArray(body.quotes) ? body.quotes.map(quoteAnswerFrom) : [];
7555
7555
  } catch {
7556
7556
  return cost;
7557
7557
  }
@@ -7575,7 +7575,7 @@ function previewCostLines(cost, previewName) {
7575
7575
  }
7576
7576
  /** The flags `previews list` parses — the help page lists exactly these. */
7577
7577
  var PREVIEWS_LIST_FLAGS = {};
7578
- async function listCommand(rawArgs) {
7578
+ async function listCommand$1(rawArgs) {
7579
7579
  parseCloudArgs({
7580
7580
  spec: PREVIEWS_LIST_FLAGS,
7581
7581
  rawArgs,
@@ -7595,7 +7595,7 @@ async function listCommand(rawArgs) {
7595
7595
  previewsUnavailable(e);
7596
7596
  reportError(e, "Failed to list previews");
7597
7597
  }
7598
- const previews = (isRecord(res) && Array.isArray(res.previews) ? res.previews : []).map(previewFrom).filter((p) => p !== null);
7598
+ const previews = (isRecord$1(res) && Array.isArray(res.previews) ? res.previews : []).map(previewFrom).filter((p) => p !== null);
7599
7599
  emit(() => {
7600
7600
  console.log("");
7601
7601
  console.log(chalk.bold(` 🔍 Previews — project ${displayProjectRef(rawArgs)}`));
@@ -7665,7 +7665,7 @@ async function previewsCommand(action, rawArgs) {
7665
7665
  await deleteCommand(rawArgs);
7666
7666
  return;
7667
7667
  }
7668
- await listCommand(rawArgs);
7668
+ await listCommand$1(rawArgs);
7669
7669
  }
7670
7670
  //#endregion
7671
7671
  //#region src/commands/cloud/runtime-logs.ts
@@ -11728,6 +11728,389 @@ async function powerCommand(action, rawArgs) {
11728
11728
  }
11729
11729
  }
11730
11730
  //#endregion
11731
+ //#region src/commands/cloud/connect.ts
11732
+ /**
11733
+ * `rebase cloud connect <url>` — add a self-hosted Rebase instance to your
11734
+ * Rebase account, so the Rebase connector in Claude reaches it as it reaches
11735
+ * every Cloud project.
11736
+ *
11737
+ * ## What it does
11738
+ *
11739
+ * 1. Registers the instance's origin with the control plane
11740
+ * (`POST /api/functions/linked-instances`). The control plane answers the
11741
+ * two variables the instance needs to accept the connector's short-lived
11742
+ * tokens: the platform's public key and the audience it signs them for.
11743
+ * Registering is idempotent per organization and origin, so the command
11744
+ * can be rerun any time.
11745
+ * 2. Prints those two lines, and offers to write them into `./.env` when
11746
+ * there is one and somebody is at the terminal to say yes.
11747
+ * 3. Waits for the instance to accept the connector
11748
+ * (`POST …/linked-instances/:id/check`), which happens once it restarts
11749
+ * with the variables set.
11750
+ *
11751
+ * `--list` and `--remove` manage what is registered. Nothing here touches the
11752
+ * instance itself: the control plane only ever calls it, and only with tokens
11753
+ * the instance verifies against the key printed here.
11754
+ */
11755
+ /** The control-plane function that holds linked instances. */
11756
+ var LINKED_INSTANCES_FUNCTION = "linked-instances";
11757
+ /** Where the hosted connector lives, for the line that says what to do next. */
11758
+ var CONNECTOR_URL = "https://app.rebase.pro/mcp";
11759
+ /** The two variables the instance reads to accept the connector's tokens. */
11760
+ var PLATFORM_TOKEN_KEY_ENV = "REBASE_PLATFORM_TOKEN_KEY";
11761
+ var PLATFORM_TOKEN_AUDIENCE_ENV = "REBASE_PLATFORM_TOKEN_AUDIENCE";
11762
+ var CHECK_TIMEOUT_MS = 10 * 6e4;
11763
+ /** The flags `cloud connect` parses — the help page lists exactly these. */
11764
+ var CONNECT_FLAGS = {
11765
+ "--name": String,
11766
+ "--org": String,
11767
+ "--list": Boolean,
11768
+ "--remove": String,
11769
+ "--no-wait": Boolean
11770
+ };
11771
+ function isRecord(value) {
11772
+ return typeof value === "object" && value !== null && !Array.isArray(value);
11773
+ }
11774
+ function isLinkedInstance(value) {
11775
+ return isRecord(value) && typeof value.id === "string" && typeof value.url === "string" && (typeof value.name === "string" || value.name === void 0) && (typeof value.verifiedAt === "string" || value.verifiedAt === null || value.verifiedAt === void 0);
11776
+ }
11777
+ function isLinkResponse(value) {
11778
+ return isRecord(value) && isLinkedInstance(value.instance) && isRecord(value.env) && typeof value.env["REBASE_PLATFORM_TOKEN_KEY"] === "string" && typeof value.env["REBASE_PLATFORM_TOKEN_AUDIENCE"] === "string";
11779
+ }
11780
+ function isCheckResult(value) {
11781
+ if (!isRecord(value) || typeof value.ok !== "boolean") return false;
11782
+ return value.ok ? isLinkedInstance(value.instance) : typeof value.reason === "string";
11783
+ }
11784
+ /** The organizations an `organization_required` refusal lists. */
11785
+ function organizationsIn(details) {
11786
+ if (!isRecord(details) || !Array.isArray(details.organizations)) return [];
11787
+ const found = [];
11788
+ for (const org of details.organizations) {
11789
+ if (!isRecord(org) || typeof org.id !== "string" && typeof org.id !== "number") continue;
11790
+ found.push({
11791
+ id: String(org.id),
11792
+ name: typeof org.name === "string" ? org.name : String(org.id)
11793
+ });
11794
+ }
11795
+ return found;
11796
+ }
11797
+ /** An instance's organization, for a reader: its name when the control plane sent one. */
11798
+ function organizationLabel(organization) {
11799
+ if (typeof organization === "string" || typeof organization === "number") return String(organization);
11800
+ if (isRecord(organization)) {
11801
+ if (typeof organization.name === "string") return organization.name;
11802
+ if (typeof organization.id === "string" || typeof organization.id === "number") return String(organization.id);
11803
+ }
11804
+ return "";
11805
+ }
11806
+ /**
11807
+ * The origin of what the person typed: `your-app.com` → `https://your-app.com`,
11808
+ * `https://your-app.com/admin?x=1` → `https://your-app.com`. Null when it is
11809
+ * not an http(s) address at all.
11810
+ */
11811
+ function normalizeInstanceUrl(input) {
11812
+ const trimmed = input.trim();
11813
+ if (!trimmed) return null;
11814
+ const withScheme = /^[a-z][a-z0-9+.-]*:\/\//i.test(trimmed) ? trimmed : `https://${trimmed}`;
11815
+ let parsed;
11816
+ try {
11817
+ parsed = new URL(withScheme);
11818
+ } catch {
11819
+ return null;
11820
+ }
11821
+ if (parsed.protocol !== "https:" && parsed.protocol !== "http:") return null;
11822
+ if (!parsed.hostname) return null;
11823
+ return parsed.origin;
11824
+ }
11825
+ function requireInstanceUrl(input) {
11826
+ const origin = normalizeInstanceUrl(input);
11827
+ if (!origin) fail(`"${input}" is not an address the connector can reach.`, "Pass the instance's public address, e.g. `rebase cloud connect your-app.com`.", "invalid_url");
11828
+ return origin;
11829
+ }
11830
+ /** Refuse, with what it means here, a call the control plane answered with an error. */
11831
+ function reportLinkError(e, context) {
11832
+ if (e instanceof RebaseApiError) {
11833
+ if (e.status === 404 && isMissingRoute(e.message)) fail("This control plane cannot add self-hosted instances yet.", "Cloud projects already reach the connector; self-hosted ones need a newer control plane.", "linked_instances_unavailable");
11834
+ if (e.code === "invalid_url") fail(e.message || "The control plane refused that address.", "Pass the instance's public https address.", "invalid_url");
11835
+ if (e.status === 403 || e.code === "forbidden") fail(e.message || "Only an owner or admin of the organization can add instances to it.", "Ask an owner or admin of the organization, or pass --org with one you administer.", "forbidden");
11836
+ }
11837
+ reportError(e, context);
11838
+ }
11839
+ async function createLink(client, body) {
11840
+ const res = await client.functions.invoke(LINKED_INSTANCES_FUNCTION, body, { method: "POST" });
11841
+ if (!isLinkResponse(res)) fail("The control plane answered without the instance's variables.", void 0, "bad_response");
11842
+ return res;
11843
+ }
11844
+ /**
11845
+ * Register the instance, picking an organization when the account has several
11846
+ * and none was named — interactively when somebody can answer, otherwise by
11847
+ * listing them and naming `--org`.
11848
+ */
11849
+ async function linkInstance(client, body, commandLine) {
11850
+ try {
11851
+ return await createLink(client, body);
11852
+ } catch (e) {
11853
+ if (!(e instanceof RebaseApiError) || e.code !== "organization_required") reportLinkError(e, "Failed to add the instance");
11854
+ const organizations = organizationsIn(e.details);
11855
+ if (!isJsonMode() && process.stdin.isTTY === true && organizations.length > 0) {
11856
+ const { picked } = await inquirer.prompt([{
11857
+ type: "select",
11858
+ name: "picked",
11859
+ message: "You belong to several organizations. Add the instance to which one?",
11860
+ choices: organizations.map((org) => ({
11861
+ name: `${org.name} ${chalk.gray(org.id)}`,
11862
+ value: org.id
11863
+ }))
11864
+ }]);
11865
+ try {
11866
+ return await createLink(client, {
11867
+ ...body,
11868
+ organizationId: picked
11869
+ });
11870
+ } catch (retry) {
11871
+ reportLinkError(retry, "Failed to add the instance");
11872
+ }
11873
+ }
11874
+ const message = "You belong to several organizations; say which one the instance belongs to.";
11875
+ const hint = `Rerun with --org <id>: ${commandLine} --org ${organizations[0]?.id ?? "<id>"}. \`rebase cloud use <org>\` makes one the default.`;
11876
+ if (isJsonMode()) {
11877
+ printJson({ error: {
11878
+ message,
11879
+ code: "organization_required",
11880
+ hint,
11881
+ organizations
11882
+ } });
11883
+ process.exit(1);
11884
+ }
11885
+ console.error("");
11886
+ console.error(chalk.red(` ✗ ${message}`));
11887
+ console.error("");
11888
+ for (const org of organizations) console.error(` ${chalk.bold(org.id)} ${org.name}`);
11889
+ console.error("");
11890
+ console.error(chalk.gray(` ${hint}`));
11891
+ console.error("");
11892
+ process.exit(1);
11893
+ }
11894
+ }
11895
+ /** Ask the control plane whether the instance accepts the connector now. */
11896
+ async function checkInstance(client, id) {
11897
+ const res = await client.functions.invoke(LINKED_INSTANCES_FUNCTION, void 0, {
11898
+ method: "POST",
11899
+ path: `${encodeURIComponent(id)}/check`
11900
+ });
11901
+ if (!isCheckResult(res)) fail("The control plane answered the check with something this CLI cannot read.", void 0, "bad_response");
11902
+ return res;
11903
+ }
11904
+ /** A check that failed on the way — the control plane briefly down — rather than with an answer. */
11905
+ function isTransient(e) {
11906
+ return e instanceof RebaseApiError && (e.status === 0 || e.status !== void 0 && e.status >= 500);
11907
+ }
11908
+ /** What a failed check means, for the waiting line. */
11909
+ function describeCheckFailure(result) {
11910
+ switch (result.reason) {
11911
+ case "unreachable": return "the control plane cannot reach it yet";
11912
+ case "not_configured": return "it does not have the variables yet";
11913
+ case "rejected": return `it refused the connector's token${result.message ? ` (${result.message})` : ""}`;
11914
+ default: return result.message ?? result.reason;
11915
+ }
11916
+ }
11917
+ /**
11918
+ * Check every `intervalMs` until the instance accepts the connector or
11919
+ * `timeoutMs` passes. `onWaiting` hears each refusal, so the caller can keep
11920
+ * one status line current.
11921
+ */
11922
+ async function waitForInstance(client, id, opts = {}) {
11923
+ const intervalMs = opts.intervalMs ?? 5e3;
11924
+ const timeoutMs = opts.timeoutMs ?? 6e5;
11925
+ const sleep = opts.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
11926
+ const now = opts.now ?? Date.now;
11927
+ const deadline = now() + timeoutMs;
11928
+ let last = {
11929
+ ok: false,
11930
+ reason: "unreachable"
11931
+ };
11932
+ for (;;) {
11933
+ try {
11934
+ last = await checkInstance(client, id);
11935
+ if (last.ok) return last;
11936
+ opts.onWaiting?.(last);
11937
+ } catch (e) {
11938
+ if (!isTransient(e)) reportLinkError(e, "Failed to check the instance");
11939
+ }
11940
+ if (now() + intervalMs > deadline) return last;
11941
+ await sleep(intervalMs);
11942
+ }
11943
+ }
11944
+ function connectedLine(name) {
11945
+ return `Connected. Ask Claude about ${name} through the Rebase connector (${CONNECTOR_URL}).`;
11946
+ }
11947
+ /** Offer to write the two variables into `./.env`, when there is one and somebody to ask. */
11948
+ async function offerDotenv(env, yes) {
11949
+ const file = path.resolve(".env");
11950
+ if (!fs.existsSync(file) || process.stdin.isTTY !== true || isJsonMode()) return null;
11951
+ if (!yes) {
11952
+ const { write } = await inquirer.prompt([{
11953
+ type: "confirm",
11954
+ name: "write",
11955
+ default: true,
11956
+ message: "Add them to ./.env?"
11957
+ }]);
11958
+ if (!write) return null;
11959
+ }
11960
+ upsertDotenv(file, PLATFORM_TOKEN_KEY_ENV, env[PLATFORM_TOKEN_KEY_ENV]);
11961
+ upsertDotenv(file, PLATFORM_TOKEN_AUDIENCE_ENV, env[PLATFORM_TOKEN_AUDIENCE_ENV]);
11962
+ return file;
11963
+ }
11964
+ async function connectInstance(client, controlPlane, input, flags) {
11965
+ const origin = requireInstanceUrl(input);
11966
+ const name = flags.name?.trim() || new URL(origin).hostname;
11967
+ const organizationId = flags.org || getContextOrg(controlPlane);
11968
+ const linked = await linkInstance(client, {
11969
+ url: origin,
11970
+ name,
11971
+ ...organizationId ? { organizationId } : {}
11972
+ }, `rebase cloud connect ${input}`);
11973
+ const instance = linked.instance;
11974
+ const shownName = instance.name || name;
11975
+ let check;
11976
+ try {
11977
+ check = await checkInstance(client, instance.id);
11978
+ } catch (e) {
11979
+ if (!isTransient(e)) reportLinkError(e, "Failed to check the instance");
11980
+ check = null;
11981
+ }
11982
+ if (isJsonMode()) {
11983
+ printJson({
11984
+ ...linked,
11985
+ check
11986
+ });
11987
+ return;
11988
+ }
11989
+ if (check?.ok) {
11990
+ success(instance.verifiedAt ? `${instance.url} is already connected to your Rebase account.` : `${instance.url} is in your Rebase account and accepts the connector.`);
11991
+ console.log(` ${connectedLine(shownName)}`);
11992
+ console.log("");
11993
+ return;
11994
+ }
11995
+ const lines = [PLATFORM_TOKEN_KEY_ENV, PLATFORM_TOKEN_AUDIENCE_ENV].map((key) => dotenvLine(key, linked.env[key]) ?? `${key}=${linked.env[key]}`);
11996
+ console.log("");
11997
+ console.log(chalk.bold.green(linked.created ? ` ✓ Added ${instance.url} to your Rebase account as "${shownName}".` : ` ✓ ${instance.url} is already in your Rebase account as "${shownName}".`));
11998
+ console.log("");
11999
+ console.log(" Set these two variables on that server:");
12000
+ console.log("");
12001
+ for (const line of lines) console.log(line);
12002
+ console.log("");
12003
+ console.log(" Then restart it.");
12004
+ console.log("");
12005
+ const wrote = await offerDotenv(linked.env, flags.yes);
12006
+ if (wrote) success(`Set ${PLATFORM_TOKEN_KEY_ENV} and ${PLATFORM_TOKEN_AUDIENCE_ENV} in ${wrote}. Restart the server to load them.`);
12007
+ if (flags.noWait) {
12008
+ note(`Once it has restarted, ${chalk.bold(`rebase cloud connect ${input}`)} checks the connection.`);
12009
+ noteBlank();
12010
+ return;
12011
+ }
12012
+ const waiting = `Waiting for ${instance.url} to accept the connector — restart it with these variables. Ctrl+C to stop; rerun this command any time.`;
12013
+ const live = process.stderr.isTTY === true;
12014
+ if (live) process.stderr.write(` ${waiting}`);
12015
+ else note(waiting);
12016
+ const result = await waitForInstance(client, instance.id, { onWaiting: (failure) => {
12017
+ if (live) process.stderr.write(`\r\x1b[2K ${waiting} ${chalk.gray(`(${describeCheckFailure(failure)})`)}`);
12018
+ } });
12019
+ if (live) process.stderr.write("\n");
12020
+ if (!result.ok) fail(`${instance.url} did not accept the connector within ${CHECK_TIMEOUT_MS / 6e4} minutes: ${describeCheckFailure(result)}.`, `Set the two variables on that server, restart it, then run \`rebase cloud connect ${input}\` again.`, "not_connected");
12021
+ console.log("");
12022
+ console.log(chalk.bold.green(` ✓ ${connectedLine(shownName)}`));
12023
+ console.log("");
12024
+ }
12025
+ async function listInstances(client) {
12026
+ let res;
12027
+ try {
12028
+ res = await client.functions.invoke(LINKED_INSTANCES_FUNCTION, void 0, { method: "GET" });
12029
+ } catch (e) {
12030
+ reportLinkError(e, "Failed to list linked instances");
12031
+ }
12032
+ if (!isRecord(res) || !Array.isArray(res.instances)) fail("The control plane answered without a list of instances.", void 0, "bad_response");
12033
+ return res.instances.filter(isLinkedInstance);
12034
+ }
12035
+ async function listCommand(client) {
12036
+ const instances = await listInstances(client);
12037
+ emit(() => {
12038
+ console.log("");
12039
+ if (instances.length === 0) {
12040
+ console.log(chalk.gray(" No self-hosted instances in your Rebase account."));
12041
+ console.log(chalk.gray(" Add one with ") + chalk.bold("rebase cloud connect <url>"));
12042
+ console.log("");
12043
+ return;
12044
+ }
12045
+ const nameWidth = Math.max(4, ...instances.map((i) => (i.name ?? "").length));
12046
+ const urlWidth = Math.max(3, ...instances.map((i) => i.url.length));
12047
+ console.log(chalk.gray(` ${"NAME".padEnd(nameWidth)} ${"URL".padEnd(urlWidth)} ${"STATUS".padEnd(9)} ORG`));
12048
+ for (const instance of instances) {
12049
+ const status = instance.verifiedAt ? chalk.green("connected") : chalk.yellow("waiting ");
12050
+ console.log(` ${chalk.bold((instance.name ?? "").padEnd(nameWidth))} ${instance.url.padEnd(urlWidth)} ${status} ` + chalk.gray(organizationLabel(instance.organization)));
12051
+ }
12052
+ console.log("");
12053
+ }, { instances });
12054
+ }
12055
+ async function removeCommand(client, ref, yes) {
12056
+ const instances = await listInstances(client);
12057
+ const origin = normalizeInstanceUrl(ref);
12058
+ const target = instances.find((i) => i.id === ref) ?? (origin ? instances.find((i) => normalizeInstanceUrl(i.url) === origin) : void 0);
12059
+ if (!target) fail(`No linked instance matches "${ref}".`, "`rebase cloud connect --list` names them.", "not_found");
12060
+ await confirmDestructive({
12061
+ yes,
12062
+ prompt: `Remove ${target.name || target.url} (${target.url}) from your Rebase account? The connector stops reaching it.`
12063
+ });
12064
+ try {
12065
+ await client.functions.invoke(LINKED_INSTANCES_FUNCTION, void 0, {
12066
+ method: "DELETE",
12067
+ path: encodeURIComponent(target.id)
12068
+ });
12069
+ } catch (e) {
12070
+ reportLinkError(e, "Failed to remove the instance");
12071
+ }
12072
+ success(`Removed ${target.url} from your Rebase account.`);
12073
+ emit(() => {}, {
12074
+ deleted: true,
12075
+ instance: target
12076
+ });
12077
+ }
12078
+ async function connectCommand(rawArgs) {
12079
+ const { flags, positionals } = parseCloudArgs({
12080
+ spec: CONNECT_FLAGS,
12081
+ rawArgs,
12082
+ commandWords: 2,
12083
+ command: "cloud connect",
12084
+ maxPositionals: 1
12085
+ });
12086
+ const input = positionals[0];
12087
+ const list = flags["--list"] === true;
12088
+ const remove = flags["--remove"];
12089
+ const yes = flags["--yes"] === true;
12090
+ if ([
12091
+ list,
12092
+ remove !== void 0,
12093
+ input !== void 0
12094
+ ].filter(Boolean).length > 1) fail("Pass one of: an address, --list, or --remove <url-or-id>.", "Run `rebase cloud connect --help`.", "usage");
12095
+ if (!list && remove === void 0 && !input) fail("Name the instance to add: `rebase cloud connect <url>`.", "Its public address, e.g. `rebase cloud connect your-app.com`. `--list` shows the ones already added.", "usage");
12096
+ const { client, url: controlPlane } = await requireClient(rawArgs);
12097
+ if (list) {
12098
+ await listCommand(client);
12099
+ return;
12100
+ }
12101
+ if (remove !== void 0) {
12102
+ await removeCommand(client, remove, yes);
12103
+ return;
12104
+ }
12105
+ if (!input) return;
12106
+ await connectInstance(client, controlPlane, input, {
12107
+ name: flags["--name"],
12108
+ org: flags["--org"],
12109
+ noWait: flags["--no-wait"] === true,
12110
+ yes
12111
+ });
12112
+ }
12113
+ //#endregion
11731
12114
  //#region src/commands/cloud/usage.ts
11732
12115
  /**
11733
12116
  * `rebase cloud usage [org] [--month YYYY-MM]`: what a project — or every
@@ -13444,6 +13827,32 @@ var ACTION_HELP = {
13444
13827
  flags: [],
13445
13828
  examples: ["rebase cloud open"]
13446
13829
  },
13830
+ connect: {
13831
+ command: "cloud connect",
13832
+ usage: "cloud connect <url> [--name <name>] [--org <id>] [--no-wait] | --list | --remove <url-or-id>",
13833
+ summary: "Add a self-hosted Rebase instance to your Rebase account, so the Rebase connector in Claude (https://app.rebase.pro/mcp) reaches it as it reaches your Cloud projects. Prints the two variables the instance needs, offers to write them into ./.env, then waits for the instance to accept the connector once you restart it. Run it once per instance; rerunning it is safe and checks the connection.",
13834
+ flags: [
13835
+ ["--name <name>", "What to call the instance. Default: its hostname"],
13836
+ ["--org <id>", "The organization it belongs to. Default: the active one (`rebase cloud use`)"],
13837
+ ["--no-wait", "Print the variables and return, without waiting for the instance to accept the connector"],
13838
+ ["--list", "List the self-hosted instances in your account"],
13839
+ ["--remove <url-or-id>", "Remove one from your account. Confirms first unless --yes"]
13840
+ ],
13841
+ examples: [
13842
+ "rebase cloud connect your-app.com",
13843
+ "rebase cloud connect https://api.example.com --name \"Shop (EU)\" --org 3f2a9c1e",
13844
+ "rebase cloud connect your-app.com --no-wait --json",
13845
+ "rebase cloud connect --list",
13846
+ "rebase cloud connect --remove your-app.com --yes"
13847
+ ],
13848
+ notes: [
13849
+ "An address without a scheme is https; only the origin is kept, so a path or query is dropped.",
13850
+ "The two variables are REBASE_PLATFORM_TOKEN_KEY and REBASE_PLATFORM_TOKEN_AUDIENCE: what the instance needs to accept the connector's short-lived tokens.",
13851
+ "Adding an instance takes an owner or admin of the organization.",
13852
+ "With --json it prints what the control plane answered and one check of the connection, and never prompts or waits.",
13853
+ "Not `rebase cloud link`, which binds a directory to a project."
13854
+ ]
13855
+ },
13447
13856
  rollback: {
13448
13857
  command: "cloud rollback",
13449
13858
  usage: "cloud rollback [<deploymentId>] [--yes]",
@@ -13636,6 +14045,7 @@ var CLOUD_VALUE_FLAGS = {
13636
14045
  "--pull-key-file": String,
13637
14046
  "--push-service-account": String,
13638
14047
  "--region": String,
14048
+ "--remove": String,
13639
14049
  "--replicas": String,
13640
14050
  "--repo": String,
13641
14051
  "--repository": String,
@@ -13784,6 +14194,9 @@ async function cloudCommand(subcommand, rawArgs) {
13784
14194
  case "open":
13785
14195
  openCommand(rawArgs);
13786
14196
  break;
14197
+ case "connect":
14198
+ await connectCommand(rawArgs);
14199
+ break;
13787
14200
  case "init":
13788
14201
  await cloudInitCommand(rawArgs);
13789
14202
  break;
@@ -13989,6 +14402,12 @@ var CLOUD_GROUPS = [
13989
14402
  section: "Project link",
13990
14403
  description: "Open the console in a browser"
13991
14404
  },
14405
+ {
14406
+ action: "connect",
14407
+ section: "Project link",
14408
+ args: "<url>",
14409
+ description: "Add a self-hosted instance to your account, so the Rebase connector in Claude reaches it"
14410
+ },
13992
14411
  {
13993
14412
  action: "init",
13994
14413
  section: "Projects",
@@ -14184,4 +14603,4 @@ function printCloudHelp() {
14184
14603
  //#endregion
14185
14604
  export { CLOUD_GROUP_NAMES, GROUP_ALIASES, cloudCommand };
14186
14605
 
14187
- //# sourceMappingURL=cloud-nwWkzAHu.js.map
14606
+ //# sourceMappingURL=cloud-CXyZobBh.js.map