1616
1717# Team ID validation pattern: CUID (v1)
1818TEAM_ID_PATTERN = re .compile (r"^c[a-z0-9]{24}$" )
19+ PROFILE_OVERRIDE_ENV_VARS = (
20+ "PRIME_API_KEY" ,
21+ "PRIME_TEAM_ID" ,
22+ "PRIME_USER_ID" ,
23+ "PRIME_API_BASE_URL" ,
24+ "PRIME_BASE_URL" ,
25+ "PRIME_FRONTEND_URL" ,
26+ "PRIME_INFERENCE_URL" ,
27+ "PRIME_CONTEXT" ,
28+ )
1929
2030
2131def validate_team_id (team_id : str ) -> bool :
@@ -32,6 +42,34 @@ def validate_team_id(team_id: str) -> bool:
3242 return bool (TEAM_ID_PATTERN .match (team_id ))
3343
3444
45+ def _active_profile_override_env_vars () -> list [str ]:
46+ return [name for name in PROFILE_OVERRIDE_ENV_VARS if (os .getenv (name ) or "" ).strip ()]
47+
48+
49+ def _require_profile_env_unset (command : str ) -> None :
50+ names = _active_profile_override_env_vars ()
51+ if not names :
52+ return
53+ joined = ", " .join (names )
54+ console .print (
55+ f"[red]Error:[/red] { joined } { 'is' if len (names ) == 1 else 'are' } set in your "
56+ f"environment, so [bold]prime config { command } [/bold] cannot make a saved profile "
57+ "active. Unset the environment override and rerun the command."
58+ )
59+ raise typer .Exit (1 )
60+
61+
62+ def _require_no_context_override (command : str ) -> None :
63+ context = Config .context_override ()
64+ if not context :
65+ return
66+ console .print (
67+ f"[red]Error:[/red] [bold]prime config { command } [/bold] cannot update auth while "
68+ f"PRIME_CONTEXT is set to '{ context } '. Run the command without a temporary context."
69+ )
70+ raise typer .Exit (1 )
71+
72+
3573@app .command ()
3674def view () -> None :
3775 """View current configuration"""
@@ -125,7 +163,9 @@ def set_api_key(
125163 default = "" ,
126164 )
127165
166+ _require_no_context_override ("set-api-key" )
128167 config = Config ()
168+ config .use_production_environment ()
129169 config .set_api_key (api_key )
130170
131171 if api_key :
@@ -140,7 +180,6 @@ def set_api_key(
140180 user_id = data .get ("id" )
141181 if user_id :
142182 config .set_user_id (user_id )
143- config .update_current_environment_file ()
144183 except (APIError , Exception ):
145184 pass
146185
@@ -161,6 +200,7 @@ def set_team_id(
161200 ),
162201) -> None :
163202 """Set your team ID."""
203+ _require_no_context_override ("set-team-id" )
164204 config = Config ()
165205
166206 # Validate team ID format
@@ -186,6 +226,7 @@ def set_team_id(
186226 except (APIError , Exception ):
187227 pass
188228
229+ config .use_production_environment ()
189230 config .set_team (team_id , team_name = team_name , team_role = team_role )
190231 if team_id :
191232 if team_name :
@@ -199,7 +240,9 @@ def set_team_id(
199240@app .command ()
200241def remove_team_id () -> None :
201242 """Remove team ID to use personal account"""
243+ _require_no_context_override ("remove-team-id" )
202244 config = Config ()
245+ config .use_production_environment ()
203246 config .set_team (None )
204247 console .print ("[green]Team ID removed. Using personal account.[/green]" )
205248
@@ -278,6 +321,7 @@ def _set_environment(
278321 env : str ,
279322) -> None :
280323 """Set URLs for a specific environment"""
324+ _require_profile_env_unset (f"use { env } " )
281325 config = Config ()
282326
283327 # Try to load the environment (handles both built-in and custom)
@@ -384,7 +428,7 @@ def reset(
384428 config .set_base_url (Config .DEFAULT_BASE_URL )
385429 config .set_frontend_url (Config .DEFAULT_FRONTEND_URL )
386430 config .set_ssh_key_path (Config .DEFAULT_SSH_KEY_PATH )
387- config .set_current_environment ( "production" )
431+ config .use_production_environment ( )
388432 console .print ("[green]Configuration reset to defaults![/green]" )
389433
390434
0 commit comments