Files

91 lines
2.7 KiB
Python

"""Prompt templates for command generation."""
from typing import Optional
class PromptTemplates:
"""Manages prompt templates for different shells and scenarios."""
BASE_PROMPT = """You are a shell command expert. Convert the following natural language description into a {shell} command.
Return ONLY the command in a code block, followed by a brief explanation.
Description: {description}
{directory}
{shell} command:"""
BASH_SPECIFIC = """Generate a bash command. You can use:
- Bash-specific syntax like [[ ]], parameter expansion ${{...}}
- Process substitution <(), >()
- Arrays and associative arrays
- Extended globbing patterns
- Here-strings <<<"""
ZSH_SPECIFIC = """Generate a zsh command. You can use:
- Zsh-specific features like glob qualifiers
- Extended globbing (**,omg, etc.)
- Zsh arithmetic $((...))
- Named directories and magic assignments
- Zsh-specific builtins"""
GIT_CONTEXT = """Context: Git repository detected. Use git commands when appropriate."""
DOCKER_CONTEXT = """Context: Docker environment detected. Use docker/docker-compose when appropriate."""
def generate_prompt(
self,
description: str,
shell: str,
context: Optional[str] = None,
) -> str:
"""Generate a complete prompt for command generation.
Args:
description: Natural language description of the task.
shell: Target shell (bash or zsh).
context: Optional context information.
Returns:
Complete prompt string.
"""
shell_specific = self.ZSH_SPECIFIC if shell == "zsh" else self.BASH_SPECIFIC
directory_info = ""
if context:
directory_info = f"Current directory context: {context}"
prompt = self.BASE_PROMPT.format(
shell=shell.upper(),
description=description,
directory=directory_info,
)
prompt += "\n\n" + shell_specific
return prompt
def generate_feedback_prompt(
self,
original_description: str,
generated_command: str,
user_correction: str,
) -> str:
"""Generate a prompt to learn from user feedback.
Args:
original_description: The original natural language description.
generated_command: The command that was originally generated.
user_correction: The user's corrected command.
Returns:
Prompt for learning from feedback.
"""
return f"""The user wanted to: {original_description}
I generated: {generated_command}
The user corrected it to: {user_correction}
What was wrong with my original command, and what should I learn for similar requests?"""