Skip to content

Commit 782db11

Browse files
authored
Enables cg as a global command (#1229)
1 parent 771ab52 commit 782db11

File tree

4 files changed

+34
-15
lines changed

4 files changed

+34
-15
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ keywords = [
7070
]
7171
[project.scripts]
7272
codegen = "codegen.cli.cli:main"
73+
cg = "codegen.cli.cli:main"
7374

7475
[project.optional-dependencies]
7576
types = []

src/codegen/cli/auth/login.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ def login_routine(token: str | None = None) -> str:
2323
typer.Exit: If login fails
2424
2525
"""
26+
# Display header like in the main TUI
27+
print("\033[38;2;82;19;217m" + "/" * 20 + " Codegen\033[0m")
28+
print()
29+
2630
# Try environment variable first
2731
token = token or global_env.CODEGEN_USER_ACCESS_TOKEN
2832

@@ -39,7 +43,7 @@ def login_routine(token: str | None = None) -> str:
3943
try:
4044
token_manager = TokenManager()
4145
token_manager.authenticate_token(token)
42-
rich.print(f"[green]✓ Stored token and profile to:[/green] {token_manager.token_file}")
46+
rich.print(f"[dim]✓ Stored token and profile to:[/dim] [#ffca85]{token_manager.token_file}[/#ffca85]")
4347

4448
# Show organization selector if multiple organizations available
4549
organizations = get_cached_organizations()
@@ -69,6 +73,12 @@ def login_routine(token: str | None = None) -> str:
6973
except Exception as e:
7074
rich.print(f"[yellow]Warning: Could not set default organization: {e}[/yellow]")
7175

76+
# After successful login, launch the TUI
77+
print() # Add some space
78+
from codegen.cli.tui.app import run_tui
79+
80+
run_tui()
81+
7282
return token
7383
except AuthError as e:
7484
rich.print(f"[red]Error:[/red] {e!s}")

src/codegen/cli/tui/app.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ def _create_background_agent(self, prompt: str):
402402
input("Press Enter to continue...")
403403
return
404404

405-
print(f"\n🔄 Creating agent run with prompt: '{prompt[:50]}{'...' if len(prompt) > 50 else ''}'")
405+
print(f"\n\033[90mCreating agent run with prompt: '{prompt[:50]}{'...' if len(prompt) > 50 else ''}'\033[0m")
406406

407407
try:
408408
payload = {"prompt": prompt.strip()}
@@ -420,10 +420,10 @@ def _create_background_agent(self, prompt: str):
420420
status = agent_run_data.get("status", "Unknown")
421421
web_url = self._generate_agent_url(run_id)
422422

423-
print("\n✅ Agent run created successfully!")
424-
print(f" Run ID: {run_id}")
425-
print(f" Status: {status}")
426-
print(f" Web URL: {web_url}")
423+
print("\n\033[90mAgent run created successfully!\033[0m")
424+
print(f"\033[90m Run ID: {run_id}\033[0m")
425+
print(f"\033[90m Status: {status}\033[0m")
426+
print(f"\033[90m Web URL: \033[38;2;255;202;133m{web_url}\033[0m")
427427

428428
# Clear the input
429429
self.prompt_input = ""
@@ -441,8 +441,8 @@ def _show_post_creation_menu(self, web_url: str):
441441
"""Show menu after successful agent creation."""
442442
from codegen.cli.utils.inplace_print import inplace_print
443443

444-
print("\nWhat would you like to do next?")
445-
options = ["open in web preview", "go to recent"]
444+
print("\n\033[90mWhat would you like to do next?\033[0m")
445+
options = ["Open Trace ↗", "Go to Recent"]
446446
selected = 0
447447
prev_lines = 0
448448

@@ -470,15 +470,15 @@ def build_lines():
470470
selected = (selected + 1) % len(options)
471471
prev_lines = inplace_print(build_lines(), prev_lines)
472472
elif key == "\r" or key == "\n": # Enter - select option
473-
if selected == 0: # open in web preview
473+
if selected == 0: # Open Trace
474474
try:
475475
import webbrowser
476476

477477
webbrowser.open(web_url)
478478
except Exception as e:
479479
print(f"\n❌ Failed to open browser: {e}")
480480
input("Press Enter to continue...")
481-
elif selected == 1: # go to recent
481+
elif selected == 1: # Go to Recent
482482
self.current_tab = 0 # Switch to recent tab
483483
self.input_mode = False
484484
self._load_agent_runs() # Refresh the data
@@ -884,8 +884,16 @@ def _clear_and_redraw(self):
884884
def run(self):
885885
"""Run the minimal TUI."""
886886
if not self.is_authenticated:
887-
print("⚠️ Not authenticated. Please run 'codegen login' first.")
888-
return
887+
# Automatically start login flow for first-time users
888+
from codegen.cli.auth.login import login_routine
889+
890+
try:
891+
login_routine()
892+
# login_routine will launch TUI after successful authentication
893+
return
894+
except Exception:
895+
# If login fails, just exit gracefully
896+
return
889897

890898
# Show UI immediately
891899
self._clear_and_redraw()

src/codegen/cli/utils/simple_selector.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def signal_handler(signum, frame):
7777
for i, option in enumerate(options):
7878
display_text = str(option.get(display_key, f"Option {i + 1}"))
7979
if i == selected:
80-
print(f" \033[34m{display_text}\033[0m")
80+
print(f" \033[37m{display_text}\033[0m") # White for selected
8181
else:
8282
print(f" \033[90m {display_text}\033[0m")
8383

@@ -100,7 +100,7 @@ def signal_handler(signum, frame):
100100
for i, option in enumerate(options):
101101
display_text = str(option.get(display_key, f"Option {i + 1}"))
102102
if i == selected:
103-
print(f" \033[34m{display_text}\033[0m\033[K") # Clear to end of line
103+
print(f" \033[37m{display_text}\033[0m\033[K") # White for selected, clear to end of line
104104
else:
105105
print(f" \033[90m {display_text}\033[0m\033[K") # Clear to end of line
106106
if show_help:
@@ -115,7 +115,7 @@ def signal_handler(signum, frame):
115115
for i, option in enumerate(options):
116116
display_text = str(option.get(display_key, f"Option {i + 1}"))
117117
if i == selected:
118-
print(f" \033[34m{display_text}\033[0m\033[K") # Clear to end of line
118+
print(f" \033[37m{display_text}\033[0m\033[K") # White for selected, clear to end of line
119119
else:
120120
print(f" \033[90m {display_text}\033[0m\033[K") # Clear to end of line
121121
if show_help:

0 commit comments

Comments
 (0)