"""System Prompter - Builds system prompts with optional file context""" MAX_FILE_CHARS = 4000 # Limit file context to avoid token overflow class SystemPrompter: @staticmethod def generate_prompt(file_context: dict | None = None) -> str: """Build a system prompt, optionally embedding a file's content. Args: file_context: dict with keys 'name' and 'content', or None. Returns: A system prompt string. """ base = ( "You are an expert code assistant integrated into a lightweight code editor. " "Help the user with code suggestions, debugging, explanations, and improvements. " "Be concise and precise. Use markdown and fenced code blocks where appropriate." ) if file_context: name = file_context.get("name", "unknown") content = file_context.get("content", "") # Truncate large files to avoid exceeding token limits if len(content) > MAX_FILE_CHARS: content = content[:MAX_FILE_CHARS] + "\n... [truncated]" file_section = ( f"\n\nThe user currently has the following file open in the editor:\n" f"\n" f"\n{content}\n\n" f"\n" f"Refer to this file when answering questions about the code." ) return base + file_section return base