import re
from pathlib import Path

REPLACE_IN_FILE_REGEX = re.compile(
    r"<replace_in_file>\s+<path>(.*?)<\/path>\s+<diff>(.*)<\/diff>\s+<\/replace_in_file>", re.DOTALL
)
REPLACE_IN_FILE_TAGS_REGEX = re.compile(r"<replace_in_file>(.*)<\/replace_in_file>", re.DOTALL | re.MULTILINE)
MULTI_REPLACE_IN_FILE_TAGS_REGEX = re.compile(
    r"<replace_in_file>\s*<path>(.*?)<\/path>\s*<diff>([\s\S]*?)<\/diff>\s*<\/replace_in_file>", re.MULTILINE
)

parent_dir = Path(__file__).parent.parent
EXPLANATION_THEN_CODE = "Begin your response with a short explanation of the changes (without any title or heading like 'Explanation' or 'Changes'), then output the code."

MARKDOWN_CONTEXT_PROMPT = (
    (parent_dir / "multi-file-code-format.md").read_text().format(EXPLANATION_THEN_CODE=EXPLANATION_THEN_CODE)
)
DEPS_CONTEXT_PROMPT = (parent_dir / "dependency_context_prompt.md").read_text()
INIT_OPTIMIZATION_PROMPT = (parent_dir / "init_optimization_prompt.md").read_text()
LINE_PROF_CONTEXT_PROMPT = (parent_dir / "lineprof_context_prompt.md").read_text()

FULL_CODE_PROMPT_INSTRUCTIONS = """- Always provide the FULL, updated content of the artifact. This means:
    - Include ALL updated code, even if some parts are unchanged
    - NEVER use placeholders like "// rest of the code remains the same..." or "<- leave original code here ->"
"""
