Skip to content

Commit 4f3ef51

Browse files
author
jzhu
committed
feat: Improve prompt ID display and generation
- Generate unique IDs using UUID (8 char suffix) instead of timestamps - Display ID prominently on separate line in 'list' command - Show suggested Import ID in 'show-live' command output - Update all ID generation in manager (import, backup, copilot)
1 parent 7bc90d9 commit 4f3ef51

2 files changed

Lines changed: 28 additions & 12 deletions

File tree

code_assistant_manager/cli/prompts_commands.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import json
44
import logging
5+
import uuid
56
from pathlib import Path
67
from typing import Optional
78

@@ -41,6 +42,12 @@ def _get_prompt_manager() -> PromptManager:
4142
return PromptManager()
4243

4344

45+
def generate_prompt_id(prefix: str = "prompt") -> str:
46+
"""Generate a unique prompt ID with a short UUID suffix."""
47+
short_uuid = uuid.uuid4().hex[:8]
48+
return f"{prefix}-{short_uuid}"
49+
50+
4451
@prompt_app.command("list")
4552
def list_prompts():
4653
"""List all prompts."""
@@ -59,11 +66,12 @@ def list_prompts():
5966
else f"{Colors.RED}{Colors.RESET}"
6067
)
6168
app_info = f" [{prompt.app_type}]" if prompt.app_type else ""
62-
typer.echo(
63-
f"{status} {Colors.BOLD}{prompt.name}{Colors.RESET}{app_info} ({prompt_id})"
64-
)
69+
typer.echo(f"{status} {Colors.BOLD}{prompt.name}{Colors.RESET}{app_info}")
70+
typer.echo(f" {Colors.CYAN}ID:{Colors.RESET} {prompt_id}")
6571
if prompt.description:
66-
typer.echo(f" {Colors.CYAN}{prompt.description}{Colors.RESET}")
72+
typer.echo(
73+
f" {Colors.CYAN}Description:{Colors.RESET} {prompt.description}"
74+
)
6775
typer.echo()
6876

6977

@@ -545,9 +553,11 @@ def show_live_prompt(
545553
)
546554

547555
file_path = get_prompt_file_path(app, lvl, lvl_project_dir)
556+
suggested_id = generate_prompt_id(f"{app}-{lvl}")
548557
typer.echo(f"\n{Colors.BOLD}Live prompt for {app}:{Colors.RESET}")
549558
typer.echo(f"{Colors.CYAN}Level:{Colors.RESET} {lvl}")
550-
typer.echo(f"{Colors.CYAN}File:{Colors.RESET} {file_path}\n")
559+
typer.echo(f"{Colors.CYAN}File:{Colors.RESET} {file_path}")
560+
typer.echo(f"{Colors.CYAN}Import ID:{Colors.RESET} {suggested_id}\n")
551561

552562
if content:
553563
typer.echo(content)
@@ -565,10 +575,12 @@ def _show_copilot(manager: PromptManager, project_dir: Optional[Path]):
565575

566576
base_dir = project_dir or Path.cwd()
567577
file_path = base_dir / ".github" / "copilot-instructions.md"
578+
suggested_id = generate_prompt_id("copilot-repo")
568579

569580
typer.echo(f"\n{Colors.BOLD}Live prompt for copilot:{Colors.RESET}")
570581
typer.echo(f"{Colors.CYAN}Level:{Colors.RESET} project")
571-
typer.echo(f"{Colors.CYAN}File:{Colors.RESET} {file_path}\n")
582+
typer.echo(f"{Colors.CYAN}File:{Colors.RESET} {file_path}")
583+
typer.echo(f"{Colors.CYAN}Import ID:{Colors.RESET} {suggested_id}\n")
572584

573585
if content:
574586
typer.echo(content)

code_assistant_manager/prompts/manager.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import json
44
import logging
5+
import uuid
56
from datetime import datetime
67
from pathlib import Path
78
from typing import Dict, List, Optional, Type
@@ -27,6 +28,12 @@
2728
VALID_APP_TYPES = list(PROMPT_HANDLERS.keys())
2829

2930

31+
def generate_unique_id(prefix: str = "prompt") -> str:
32+
"""Generate a unique ID with a short UUID suffix."""
33+
short_uuid = uuid.uuid4().hex[:8]
34+
return f"{prefix}-{short_uuid}"
35+
36+
3037
def get_handler(app_type: str) -> BasePromptHandler:
3138
"""Get a prompt handler instance for the specified app type."""
3239
handler_class = PROMPT_HANDLERS.get(app_type)
@@ -309,9 +316,8 @@ def _backup_live_prompt(
309316
return prompt.id
310317

311318
# Create a backup prompt
312-
timestamp = int(datetime.now().timestamp())
313319
scope_label = f"{level} " if level != "user" else ""
314-
backup_id = f"backup-{level}-{app_type}-{timestamp}"
320+
backup_id = generate_unique_id(f"backup-{app_type}-{level}")
315321
backup_prompt = Prompt(
316322
id=backup_id,
317323
name=f"Backup from {scope_label}{app_type.capitalize()} ({datetime.now().strftime('%Y-%m-%d %H:%M')})".strip(),
@@ -367,8 +373,7 @@ def import_from_live(
367373
)
368374
return prompt.id
369375

370-
timestamp = int(datetime.now().timestamp())
371-
prompt_id = f"imported-{level}-{app_type}-{timestamp}"
376+
prompt_id = generate_unique_id(f"{app_type}-{level}")
372377

373378
if not name:
374379
level_label = "User" if level == "user" else "Project"
@@ -515,8 +520,7 @@ def import_copilot_instructions(
515520
)
516521
return prompt.id
517522

518-
timestamp = int(datetime.now().timestamp())
519-
prompt_id = f"copilot-{instruction_type}-{timestamp}"
523+
prompt_id = generate_unique_id(f"copilot-{instruction_type}")
520524

521525
if not name:
522526
name = f"Copilot {instruction_type} instructions ({datetime.now().strftime('%Y-%m-%d %H:%M')})"

0 commit comments

Comments
 (0)