Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions packages/prime/src/prime_cli/commands/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,68 @@ def pull(
raise typer.Exit(1)


@app.command(no_args_is_help=True)
def fork(
env_id: str = typer.Argument(..., help="Environment ID to fork (owner/name)"),
team: Optional[str] = typer.Option(
None,
"--team",
"-t",
help="Team slug for team ownership of the fork",
),
) -> None:
"""Fork an environment to create your own copy that you can modify and push"""
try:
client = APIClient()

parts = env_id.split("/")
if len(parts) != 2:
console.print("[red]Error: Invalid environment ID format. Expected: owner/name[/red]")
raise typer.Exit(1)

owner, name = parts

console.print(f"Forking {env_id}...")

fork_data: Dict[str, Any] = {}
if team:
fork_data["team_slug"] = team

try:
response = client.post(f"/environments/{env_id}/fork", json=fork_data)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong API endpoint prefix breaks fork command

High Severity

The fork command uses /environments/{env_id}/fork as the API endpoint, but all other environment-related API calls in this file consistently use the /environmentshub/ prefix (e.g., /environmentshub/{env_id}/wheels, /environmentshub/resolve, /environmentshub/{env_id}). This inconsistency likely means the fork command will fail to reach the correct API endpoint.

Fix in Cursor Fix in Web


if "data" in response:
fork_response = response["data"]
else:
fork_response = response

success = fork_response.get("success", False)
message = fork_response.get("message", "")
forked_env_id = fork_response.get("environment_id", "")

if success:
console.print(f"[green]✓ Successfully forked {env_id}[/green]")
console.print(f"[dim]New environment ID: {forked_env_id}[/dim]")
console.print("\n[cyan]Next steps:[/cyan]")
console.print(f" prime env pull {forked_env_id}")
console.print(" # Make your changes")
console.print(" prime env push")
else:
console.print(f"[red]Fork failed: {message}[/red]")
raise typer.Exit(1)

except APIError as e:
console.print(f"[red]Failed to fork environment: {e}[/red]")
raise typer.Exit(1)

except APIError as e:
console.print(f"[red]Error: {e}[/red]")
raise typer.Exit(1)
except Exception as e:
console.print(f"[red]Unexpected error: {e}[/red]")
raise typer.Exit(1)


def validate_env_id(env_id: str) -> Tuple[str, str]:
"""Validate and parse environment ID.

Expand Down