From a9d89922036026866ec5f746bfa8ff6b7dd25ff5 Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Thu, 5 Feb 2026 20:56:05 +0000 Subject: [PATCH] Initial upload: Local LLM Prompt Manager CLI tool --- src/utils/__init__.py | 48 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/utils/__init__.py diff --git a/src/utils/__init__.py b/src/utils/__init__.py new file mode 100644 index 0000000..89d203b --- /dev/null +++ b/src/utils/__init__.py @@ -0,0 +1,48 @@ +"""Utility functions for the prompt manager.""" + +import re +from pathlib import Path +from typing import Any + + +def ensure_directory(path: str) -> Path: + """Create directory if it doesn't exist.""" + path = Path(path) + path.mkdir(parents=True, exist_ok=True) + return path + + +def parse_key_value(key_value: str) -> tuple[str, str]: + """Parse a key=value string into a tuple.""" + if "=" not in key_value: + raise ValueError(f"Invalid key=value format: {key_value}") + key, value = key_value.split("=", 1) + return key.strip(), value.strip() + + +def validate_yaml_structure(data: dict[str, Any], required_fields: list[str]) -> list[str]: + """Validate that required fields are present in YAML data.""" + missing = [] + for field in required_fields: + if field not in data: + missing.append(field) + return missing + + +def sanitize_filename(name: str) -> str: + """Sanitize a string to be used as a filename.""" + name = re.sub(r"[^\w\s-]", "", name) + name = re.sub(r"[\s-]+", "-", name) + return name.strip("-") + + +def format_tags(tags: list[str]) -> str: + """Format tags for display.""" + return ", ".join(tags) if tags else "None" + + +def truncate_text(text: str, max_length: int = 50) -> str: + """Truncate text for display.""" + if len(text) <= max_length: + return text + return text[:max_length - 3] + "..."