From d87ba16cfd796d0fbd8b9e7d6ea613d4c4a38719 Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Thu, 5 Feb 2026 20:56:12 +0000 Subject: [PATCH] Initial upload: Local LLM Prompt Manager CLI tool --- src/commands/tag.py | 70 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 src/commands/tag.py diff --git a/src/commands/tag.py b/src/commands/tag.py new file mode 100644 index 0000000..e674ae4 --- /dev/null +++ b/src/commands/tag.py @@ -0,0 +1,70 @@ +"""Tag management CLI commands.""" + +from typing import Optional + +import click + +from ..storage import PromptStorage + + +@click.group() +def tag_cmd(): + """Manage tags.""" + pass + + +@tag_cmd.command("list") +@click.option("--dir", "prompt_dir", default=None, help="Prompt directory") +def list_tags(prompt_dir: Optional[str]): + """List all tags.""" + from rich.console import Console + from rich.table import Table + + storage = PromptStorage(prompt_dir) + tags = storage.list_tags() + + table = Table(title="Tags") + table.add_column("Tag", style="cyan") + table.add_column("Count", style="magenta") + table.add_column("Prompts", style="green") + + for tag_name in tags: + tag = storage.get_tag(tag_name) + count = len(tag.prompts) if tag else 0 + prompts_str = ", ".join(tag.prompts[:5]) + ("..." if len(tag.prompts) > 5 else "") if tag and tag.prompts else "-" + table.add_row(tag_name, str(count), prompts_str) + + console = Console() + console.print(table) + + +@tag_cmd.command("add") +@click.argument("prompt_name") +@click.argument("tag") +@click.option("--dir", "prompt_dir", default=None, help="Prompt directory") +def add_tag(prompt_name: str, tag: str, prompt_dir: Optional[str]): + """Add a tag to a prompt.""" + storage = PromptStorage(prompt_dir) + + if not storage.prompt_exists(prompt_name): + click.echo(f"Error: Prompt '{prompt_name}' not found", err=True) + return + + storage.add_tag_to_prompt(prompt_name, tag) + click.echo(f"Added tag '{tag}' to prompt '{prompt_name}'") + + +@tag_cmd.command("remove") +@click.argument("prompt_name") +@click.argument("tag") +@click.option("--dir", "prompt_dir", default=None, help="Prompt directory") +def remove_tag(prompt_name: str, tag: str, prompt_dir: Optional[str]): + """Remove a tag from a prompt.""" + storage = PromptStorage(prompt_dir) + + result = storage.remove_tag_from_prompt(prompt_name, tag) + + if result: + click.echo(f"Removed tag '{tag}' from prompt '{prompt_name}'") + else: + click.echo(f"Error: Tag '{tag}' not found on prompt '{prompt_name}'", err=True)