update
Browse files287 unmodified lines2882892902912922931279 unmodified lines15731574157515761577157849 unmodified lines1628162916301631163216331634287 unmodified lines9. IMPORTANT: The SEARCH block must *exactly* match the current code, including indentation and whitespace.10. For multi-file projects, specify which file you're modifying by starting with the filename before the search/replace block.Example Modifying Code:```Some explanation...1279 unmodified linesif not changes_text.strip():return original_content# Split the changes text into individual search/replace blocksblocks = []current_block = ""49 unmodified linesif search_text in modified_content:modified_content = modified_content.replace(search_text, replace_text)else:print(f"Warning: Search text not found in content: {search_text[:100]}...")return modified_content287 unmodified lines2882892902912922932942952962971279 unmodified lines157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162549 unmodified lines16751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715287 unmodified lines9. IMPORTANT: The SEARCH block must *exactly* match the current code, including indentation and whitespace.10. For multi-file projects, specify which file you're modifying by starting with the filename before the search/replace block.CSS Changes Guidance:- When changing a CSS property that conflicts with other properties (e.g., replacing a gradient text with a solid color), replace the entire CSS rule for that selector instead of only adding the new property. For example, replace the full `.hero h1 { ... }` block, removing `background-clip` and `color: transparent` when setting `color: #fff`.- Ensure search blocks match the current code exactly (spaces, indentation, and line breaks) so replacements apply correctly.Example Modifying Code:```Some explanation...1279 unmodified linesif not changes_text.strip():return original_content# If the model didn't use the block markers, try a CSS-rule fallback where# provided blocks like `.selector { ... }` replace matching CSS rules.if (SEARCH_START not in changes_text) and (DIVIDER not in changes_text) and (REPLACE_END not in changes_text):try:import re # Local import to avoid global side effectsupdated_content = original_contentreplaced_any_rule = False# Find CSS-like rule blocks in the changes_text# This is a conservative matcher that looks for `selector { ... }`css_blocks = re.findall(r"([^{]+)\{([\s\S]*?)\}", changes_text, flags=re.MULTILINE)for selector_raw, body_raw in css_blocks:selector = selector_raw.strip()body = body_raw.strip()if not selector:continue# Build a regex to find the existing rule for this selector# Capture opening `{` and closing `}` to preserve them; replace inner body.pattern = re.compile(rf"({re.escape(selector)}\s*\{{)([\s\S]*?)(\}})")def _replace_rule(match):nonlocal replaced_any_rulereplaced_any_rule = Trueprefix, existing_body, suffix = match.groups()# Preserve indentation of the existing first body line if presentfirst_line_indent = ""for line in existing_body.splitlines():stripped = line.lstrip(" \t")if stripped:first_line_indent = line[: len(line) - len(stripped)]break# Re-indent provided body with the detected indentif body:new_body_lines = [first_line_indent + line if line.strip() else line for line in body.splitlines()]new_body_text = "\n" + "\n".join(new_body_lines) + "\n"else:new_body_text = existing_body # If empty body provided, keep existingreturn f"{prefix}{new_body_text}{suffix}"updated_content, num_subs = pattern.subn(_replace_rule, updated_content, count=1)if replaced_any_rule:return updated_contentexcept Exception:# Fallback silently to the standard block-based applicationpass# Split the changes text into individual search/replace blocksblocks = []current_block = ""49 unmodified linesif search_text in modified_content:modified_content = modified_content.replace(search_text, replace_text)else:# If exact block match fails, attempt a CSS-rule fallback using the replace_texttry:import reupdated_content = modified_contentreplaced_any_rule = Falsecss_blocks = re.findall(r"([^{]+)\{([\s\S]*?)\}", replace_text, flags=re.MULTILINE)for selector_raw, body_raw in css_blocks:selector = selector_raw.strip()body = body_raw.strip()if not selector:continuepattern = re.compile(rf"({re.escape(selector)}\s*\{{)([\s\S]*?)(\}})")def _replace_rule(match):nonlocal replaced_any_rulereplaced_any_rule = Trueprefix, existing_body, suffix = match.groups()first_line_indent = ""for line in existing_body.splitlines():stripped = line.lstrip(" \t")if stripped:first_line_indent = line[: len(line) - len(stripped)]breakif body:new_body_lines = [first_line_indent + line if line.strip() else line for line in body.splitlines()]new_body_text = "\n" + "\n".join(new_body_lines) + "\n"else:new_body_text = existing_bodyreturn f"{prefix}{new_body_text}{suffix}"updated_content, num_subs = pattern.subn(_replace_rule, updated_content, count=1)if replaced_any_rule:modified_content = updated_contentelse:print(f"Warning: Search text not found in content: {search_text[:100]}...")except Exception:print(f"Warning: Search text not found in content: {search_text[:100]}...")return modified_content
app.py+82-1