Repository navigation
feat(cli): coworkers set up their own cloud environment from the CLI #7913
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7c7f1c1
feat(db): environment names are labels, not unique keys
saddlepaddle 72b1bff
feat(api): promote replaces an environment in place, copies variables…
saddlepaddle 6d7717d
feat(cli): set up a cloud environment end to end from the CLI
saddlepaddle 3500c1a
chore(sandbox): release rebuilds the internal environment by id
saddlepaddle 4d88d7e
fix(setup): a cloud workspace installs dependencies on first boot
saddlepaddle 5fe07cc
fix(api,cli): no orphaned goldens or half-made environments
saddlepaddle 13331ee
Merge remote-tracking branch 'origin/main' into saddlepaddle/cli-self…
saddlepaddle 7aa930d
fix(cli,api): a gateway timeout during save is waited out; archive an…
saddlepaddle c72fdd7
fix(api): replace applies only to the environment it loaded
saddlepaddle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
packages/cli/src/commands/connections/agents/list/command.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { command } from "../../../../lib/command"; | ||
|
|
||
| export default command({ | ||
| sandbox: false, | ||
| description: "List the agents signed in for your cloud workspaces", | ||
| run: async ({ ctx }) => { | ||
| const rows = await ctx.api.agentCredential.list.query(); | ||
| return { | ||
| data: rows, | ||
| message: | ||
| rows | ||
| .map((row) => | ||
| [ | ||
| row.agent, | ||
| row.provider === "gateway" ? "gateway key" : row.kind, | ||
| row.accountLabel, | ||
| ] | ||
| .filter(Boolean) | ||
| .join(" "), | ||
| ) | ||
| .join("\n") || | ||
| "No agents signed in. Run: superset connections agents set claude --kind subscription", | ||
| }; | ||
| }, | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| export default { | ||
| description: "Sign agents in for the cloud workspaces you start", | ||
| }; |
17 changes: 17 additions & 0 deletions
17
packages/cli/src/commands/connections/agents/remove/command.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import { positional } from "@superset/cli-framework"; | ||
| import { command } from "../../../../lib/command"; | ||
|
|
||
| export default command({ | ||
| sandbox: false, | ||
| description: "Sign an agent out of your cloud workspaces", | ||
| args: [positional("agent").required().desc("Agent: claude or codex")], | ||
| run: async ({ ctx, args }) => { | ||
| const removed = await ctx.api.agentCredential.remove.mutate({ | ||
| agent: args.agent as string, | ||
| }); | ||
| return { | ||
| data: removed, | ||
| message: `Signed ${removed.agent} out of your cloud workspaces`, | ||
| }; | ||
| }, | ||
| }); |
60 changes: 60 additions & 0 deletions
60
packages/cli/src/commands/connections/agents/set/command.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import * as p from "@clack/prompts"; | ||
| import { boolean, CLIError, positional, string } from "@superset/cli-framework"; | ||
| import { command } from "../../../../lib/command"; | ||
|
|
||
| async function readStdin(): Promise<string> { | ||
| const chunks: Buffer[] = []; | ||
| for await (const chunk of process.stdin) { | ||
| chunks.push(typeof chunk === "string" ? Buffer.from(chunk) : chunk); | ||
| } | ||
| return Buffer.concat(chunks).toString("utf-8"); | ||
| } | ||
|
|
||
| export default command({ | ||
| sandbox: false, | ||
| description: | ||
| "Store an agent's subscription token or API key for your cloud workspaces; read from stdin or a prompt", | ||
| args: [positional("agent").required().desc("Agent: claude or codex")], | ||
| options: { | ||
| kind: string() | ||
| .enum("subscription", "api_key") | ||
| .required() | ||
| .desc( | ||
| "subscription: the token from `claude setup-token`; api_key: a provider or gateway key", | ||
| ), | ||
| gateway: boolean().desc("The key is a Vercel AI Gateway key"), | ||
| baseUrl: string().desc("A compatible endpoint the key is for"), | ||
| }, | ||
| run: async ({ ctx, args, options }) => { | ||
| const agent = args.agent as string; | ||
| const hint = | ||
| options.kind === "subscription" && agent === "claude" | ||
| ? "Run `claude setup-token` and paste the token it prints" | ||
| : `Paste the ${agent} ${options.kind === "subscription" ? "token" : "API key"}`; | ||
| let value: string | undefined; | ||
| if (!process.stdin.isTTY) { | ||
| value = await readStdin(); | ||
| } else { | ||
| const entered = await p.password({ message: hint }); | ||
| if (p.isCancel(entered)) throw new CLIError("Cancelled"); | ||
| value = entered; | ||
| } | ||
| if (!value?.trim()) { | ||
| throw new CLIError( | ||
| "No value given", | ||
| `${hint}, or pipe it: printf '%s' "$TOKEN" | superset connections agents set ${agent} --kind ${options.kind}`, | ||
| ); | ||
| } | ||
| const saved = await ctx.api.agentCredential.set.mutate({ | ||
| agent, | ||
| kind: options.kind, | ||
| value, | ||
| baseUrl: options.baseUrl, | ||
| provider: options.gateway ? "gateway" : undefined, | ||
| }); | ||
| return { | ||
| data: saved, | ||
| message: `Signed ${saved.agent} in for your cloud workspaces (${saved.kind})`, | ||
| }; | ||
| }, | ||
| }); |
55 changes: 55 additions & 0 deletions
55
packages/cli/src/commands/connections/github/connect/command.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import { boolean, CLIError } from "@superset/cli-framework"; | ||
| import { command } from "../../../../lib/command"; | ||
| import { canReachDesktop, openUrl } from "../../../../lib/open-url"; | ||
|
|
||
| const POLL_INTERVAL_MS = 2_000; | ||
| const POLL_TIMEOUT_MS = 5 * 60_000; | ||
|
|
||
| export default command({ | ||
| sandbox: false, | ||
| description: | ||
| "Connect your GitHub account in the browser so your cloud workspaces push and open pull requests as you", | ||
| options: { | ||
| noWait: boolean().desc("Print the authorize URL and exit without waiting"), | ||
| }, | ||
| run: async ({ ctx, options }) => { | ||
| const { connection: existing } = await ctx.api.githubUser.get.query(); | ||
| if (existing) { | ||
| return { | ||
| data: { connection: existing }, | ||
| message: `Already connected as ${existing.login}. To switch accounts, run: superset connections github disconnect`, | ||
| }; | ||
| } | ||
| const { url } = await ctx.api.githubUser.connect.mutate(); | ||
| const opened = | ||
| canReachDesktop() && | ||
| (await openUrl(url).then( | ||
| () => true, | ||
| () => false, | ||
| )); | ||
| if (options.noWait) { | ||
| return { | ||
| data: { url }, | ||
| message: `Open this URL to connect GitHub:\n ${url}`, | ||
| }; | ||
| } | ||
| process.stderr.write( | ||
| `${opened ? "Opened" : "Open"} this URL to connect GitHub:\n ${url}\nWaiting for you to authorize…\n`, | ||
| ); | ||
| const deadline = Date.now() + POLL_TIMEOUT_MS; | ||
| while (Date.now() < deadline) { | ||
| await new Promise((r) => setTimeout(r, POLL_INTERVAL_MS)); | ||
| const { connection } = await ctx.api.githubUser.get.query(); | ||
| if (connection) { | ||
| return { | ||
| data: { connection }, | ||
| message: `Connected as ${connection.login}`, | ||
| }; | ||
| } | ||
| } | ||
| throw new CLIError( | ||
| "GitHub was not connected in 5 minutes", | ||
| "Run: superset connections github connect", | ||
| ); | ||
| }, | ||
| }); | ||
11 changes: 11 additions & 0 deletions
11
packages/cli/src/commands/connections/github/disconnect/command.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { command } from "../../../../lib/command"; | ||
|
|
||
| export default command({ | ||
| sandbox: false, | ||
| description: | ||
| "Disconnect your GitHub account; cloud workspaces push as the Superset GitHub App again", | ||
| run: async ({ ctx }) => { | ||
| const result = await ctx.api.githubUser.disconnect.mutate(); | ||
| return { data: result, message: "Disconnected GitHub" }; | ||
| }, | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| export default { | ||
| description: | ||
| "Connect your GitHub account so your cloud workspaces push and open pull requests as you", | ||
| }; |
17 changes: 17 additions & 0 deletions
17
packages/cli/src/commands/connections/github/status/command.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import { command } from "../../../../lib/command"; | ||
|
|
||
| export default command({ | ||
| sandbox: false, | ||
| description: "Show which GitHub account your cloud workspaces act as", | ||
| run: async ({ ctx }) => { | ||
| const { available, connection } = await ctx.api.githubUser.get.query(); | ||
| return { | ||
| data: { available, connection }, | ||
| message: connection | ||
| ? `Connected as ${connection.login}` | ||
| : available | ||
| ? "Not connected; cloud workspaces push as the Superset GitHub App. Run: superset connections github connect" | ||
| : "GitHub account connections are not set up on this server", | ||
| }; | ||
| }, | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| export default { | ||
| audience: "internal", | ||
| description: | ||
| "Your own accounts that the cloud workspaces you start sign in with", | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { boolean, CLIError, positional } from "@superset/cli-framework"; | ||
| import { command } from "../../../lib/command"; | ||
| import { confirmByName, resolveEnvironment } from "../../../lib/environments"; | ||
|
|
||
| export default command({ | ||
| sandbox: false, | ||
| description: | ||
| "Archive an environment; its snapshot is deleted and no new workspace can start from it", | ||
| args: [positional("environment").required().desc("Environment ID")], | ||
| options: { | ||
| yes: boolean().desc("Archive without asking; required without a terminal"), | ||
| }, | ||
| run: async ({ ctx, args, options }) => { | ||
| const organizationId = ctx.config.organizationId; | ||
| if (!organizationId) { | ||
| throw new CLIError("No active organization", "Run: superset auth login"); | ||
| } | ||
| const environment = await resolveEnvironment( | ||
| ctx.api, | ||
| organizationId, | ||
| args.environment as string, | ||
| ); | ||
| await confirmByName({ | ||
| name: environment.name, | ||
| consequence: `Archiving ${environment.name} deletes its snapshot and cannot be undone`, | ||
| yes: options.yes, | ||
| rerun: `superset environments archive ${environment.id}`, | ||
| }); | ||
| await ctx.api.environment.archive.mutate({ id: environment.id }); | ||
| return { | ||
| data: { id: environment.id, name: environment.name, archived: true }, | ||
| message: `Archived ${environment.name}`, | ||
| }; | ||
| }, | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| import { CLIError, string } from "@superset/cli-framework"; | ||
| import { | ||
| SANDBOX_REGION_IDS, | ||
| type SandboxRegionId, | ||
| } from "@superset/shared/sandbox-regions"; | ||
| import { command } from "../../../lib/command"; | ||
|
|
||
| export default command({ | ||
| sandbox: false, | ||
| description: "Create an environment for cloud workspaces to start from", | ||
| options: { | ||
| name: string().required().desc("Environment name"), | ||
| repo: string() | ||
| .variadic() | ||
| .required() | ||
| .desc( | ||
| "Repository as owner/name. Repeatable; the first is the one a workspace opens on", | ||
| ), | ||
| hooksRepo: string().desc( | ||
| "Repository whose .superset/config.json runs setup (default: the first --repo)", | ||
| ), | ||
| scope: string() | ||
| .enum("organization", "personal") | ||
| .desc("Who can use it (default: organization)"), | ||
| region: string().desc( | ||
| "Where its workspaces run, e.g. iad1 or fra1 (default: the region nearest you)", | ||
| ), | ||
| }, | ||
| run: async ({ ctx, options }) => { | ||
| const organizationId = ctx.config.organizationId; | ||
| if (!organizationId) { | ||
| throw new CLIError("No active organization", "Run: superset auth login"); | ||
| } | ||
| const region = options.region as SandboxRegionId | undefined; | ||
| if (region && !SANDBOX_REGION_IDS.includes(region)) { | ||
| throw new CLIError( | ||
| `Unknown region ${region}`, | ||
| `Regions: ${SANDBOX_REGION_IDS.join(", ")}`, | ||
| ); | ||
| } | ||
| const connected = await ctx.api.integration.github.listRepositories.query({ | ||
| organizationId, | ||
| }); | ||
| const repositoryId = (fullName: string) => { | ||
| const match = connected.find( | ||
| (repo) => repo.fullName.toLowerCase() === fullName.toLowerCase(), | ||
| ); | ||
| if (!match) { | ||
| throw new CLIError( | ||
| `${fullName} is not connected to this organization`, | ||
| "See what is connected with: superset environments repos", | ||
| ); | ||
| } | ||
| return match.id; | ||
| }; | ||
| const repositoryIds = (options.repo as string[]).map(repositoryId); | ||
| const created = await ctx.api.environment.create.mutate({ | ||
| organizationId, | ||
| name: options.name, | ||
| repositoryIds, | ||
| hooksRepositoryId: options.hooksRepo | ||
| ? repositoryId(options.hooksRepo) | ||
| : repositoryIds[0], | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| scope: options.scope, | ||
| region, | ||
| }); | ||
| const environment = await ctx.api.environment.get.query({ | ||
| id: created.id, | ||
| }); | ||
| return { | ||
| data: environment, | ||
| message: `Created ${environment.name} (${environment.id}) in ${environment.region}`, | ||
| }; | ||
| }, | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| export default { | ||
| audience: "internal", | ||
| description: "Inspect the environments cloud workspaces start from", | ||
| description: "Manage the environments cloud workspaces start from", | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: superset-sh/superset
Length of output: 10358
🏁 Script executed:
Repository: superset-sh/superset
Length of output: 24961
Wait for the new GitHub authorization, not any connection.
githubUserAuthorizeUrlonly creates the authorization URL and does not clear the current connection. The polling loop exits whengithubUser.getreturns any connection, so an existing connection can report success before the new authorization completes. Tie polling to this authorization attempt instead of checking only whether a connection exists.🤖 Prompt for AI Agents