Skip to content

Commit fa8fc39

Browse files
vicsanity623pyob-bot
authored andcommitted
🪄 PyOB: Automated Lint & Format Fixes
1 parent e15fe1f commit fa8fc39

2 files changed

Lines changed: 40 additions & 11 deletions

File tree

src/pyob/entrance_mixins.py

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import difflib
2-
import json
32
import logging
43
import os
54
import shutil
@@ -9,11 +8,13 @@
98

109
logger = logging.getLogger(__name__)
1110

11+
1212
class EntranceMixin:
1313
"""
1414
Mixin providing core iteration logic.
1515
Attributes are declared here to satisfy strict Mypy checks.
1616
"""
17+
1718
target_dir: str
1819
pyob_dir: str
1920
ENGINE_FILES: list[str]
@@ -32,28 +33,42 @@ class EntranceMixin:
3233

3334
def pick_target_file(self) -> str:
3435
return ""
36+
3537
def _read_file(self, path: str) -> str:
3638
return ""
39+
3740
def _extract_path_from_llm_response(self, text: str) -> str:
3841
return ""
39-
def get_valid_llm_response(self, p: str, v: Callable[[str], bool], context: str) -> str:
42+
43+
def get_valid_llm_response(
44+
self, p: str, v: Callable[[str], bool], context: str
45+
) -> str:
4046
return ""
47+
4148
def update_analysis_for_single_file(self, abs_p: str, rel_p: str):
4249
pass
50+
4351
def update_ledger_for_file(self, rel_p: str, code: str):
4452
pass
53+
4554
def detect_symbolic_ripples(self, o: str, n: str, p: str) -> list[str]:
4655
return []
56+
4757
def _run_final_verification_and_heal(self, b: dict) -> bool:
4858
return False
59+
4960
def handle_git_librarian(self, p: str, i: int):
5061
pass
62+
5163
def append_to_history(self, p: str, o: str, n: str):
5264
pass
65+
5366
def wrap_up_evolution_session(self):
5467
pass
68+
5569
def generate_pr_summary(self, rel_path: str, diff_text: str) -> dict:
5670
return {}
71+
5772
def execute_targeted_iteration(self, iteration: int):
5873
"""Orchestrates a single targeted evolution step."""
5974
backup_state = self.llm_engine.backup_workspace()
@@ -62,7 +77,9 @@ def execute_targeted_iteration(self, iteration: int):
6277
if self.cascade_queue:
6378
target_rel_path = self.cascade_queue.pop(0)
6479
target_diff = self.cascade_diffs.get(target_rel_path, "")
65-
logger.warning(f"SYMBOLIC CASCADE: Targeting impacted file: {target_rel_path}")
80+
logger.warning(
81+
f"SYMBOLIC CASCADE: Targeting impacted file: {target_rel_path}"
82+
)
6683
is_cascade = True
6784
else:
6885
target_rel_path = self.pick_target_file()
@@ -99,17 +116,18 @@ def execute_targeted_iteration(self, iteration: int):
99116
old_content = f.read()
100117

101118
from pyob.targeted_reviewer import TargetedReviewer
119+
102120
reviewer = TargetedReviewer(self.target_dir, target_abs_path)
103121
reviewer.session_context = self.llm_engine.session_context[:]
104-
if hasattr(self, 'key_cooldowns'):
122+
if hasattr(self, "key_cooldowns"):
105123
reviewer.key_cooldowns = self.key_cooldowns
106-
if hasattr(self, 'session_pr_count'):
124+
if hasattr(self, "session_pr_count"):
107125
reviewer.session_pr_count = self.session_pr_count
108126

109127
reviewer.run_pipeline(iteration)
110128

111129
self.llm_engine.session_context = reviewer.session_context[:]
112-
if hasattr(reviewer, 'session_pr_count'):
130+
if hasattr(reviewer, "session_pr_count"):
113131
self.session_pr_count = reviewer.session_pr_count
114132

115133
new_content = ""
@@ -124,8 +142,15 @@ def execute_targeted_iteration(self, iteration: int):
124142
if old_content != new_content:
125143
logger.info(f"Edit successful. Verifying {target_rel_path}...")
126144
self.append_to_history(target_rel_path, old_content, new_content)
127-
current_diff = "".join(difflib.unified_diff(old_content.splitlines(keepends=True), new_content.splitlines(keepends=True)))
128-
ripples = self.detect_symbolic_ripples(old_content, new_content, target_rel_path)
145+
current_diff = "".join(
146+
difflib.unified_diff(
147+
old_content.splitlines(keepends=True),
148+
new_content.splitlines(keepends=True),
149+
)
150+
)
151+
ripples = self.detect_symbolic_ripples(
152+
old_content, new_content, target_rel_path
153+
)
129154
if ripples:
130155
for r in ripples:
131156
if r not in self.cascade_queue:
@@ -140,6 +165,10 @@ def execute_targeted_iteration(self, iteration: int):
140165
self.self_evolved_flag = True
141166

142167
# --- THE FINAL WRAP-UP GATE ---
143-
if getattr(self, "session_pr_count", 0) >= 8 and not getattr(self, "cascade_queue", []):
144-
logger.info(f"🏆 MISSION ACCOMPLISHED: {self.session_pr_count} PRs achieved.")
168+
if getattr(self, "session_pr_count", 0) >= 8 and not getattr(
169+
self, "cascade_queue", []
170+
):
171+
logger.info(
172+
f"🏆 MISSION ACCOMPLISHED: {self.session_pr_count} PRs achieved."
173+
)
145174
self.wrap_up_evolution_session()

src/pyob/prompts_and_memory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def _ensure_prompt_files(self) -> None:
3131
templates = {
3232
"UM.md": "You are the PyOB Memory Manager. Your job is to update MEMORY.md.\n\n### Current Memory:\n{current_memory}\n\n### Recent Actions:\n{session_summary}\n\n### INSTRUCTIONS:\n1. Update the memory with the Recent Actions.\n2. TRANSACTIONAL RECORDING: Only record changes as 'Implemented' if the actions specifically state 'SUCCESSFUL CHANGE'. If you see 'CRITICAL: FAILED' or 'ROLLED BACK', record this as a 'Failed Attempt' with the reason, so the engine knows to try a different approach next time.\n3. BREVITY: Keep the ENTIRE document under 200 words. Be ruthless. Delete old, irrelevant details.\n4. FORMAT: Keep lists strictly to bullet points. No long paragraphs.\n5. **HUMAN DIRECTIVES**: If the current memory contains a section titled HUMAN DIRECTIVES, you are strictly FORBIDDEN from deleting or altering it. Prepend all new session summaries BELOW that section.\n6. Respond EXCLUSIVELY with the raw markdown for MEMORY.md. Do not use ```markdown fences or <THOUGHT> blocks.\n FINAL WARNING: Only output XML and code. If you add conversational text outside of <THOUGHT> or <EDIT>, the system will ROLLBACK.",
3333
"RM.md": "You are the PYOB Memory Manager. The current MEMORY.md is too bloated and is breaking the AI context window.\n\n### Bloated Memory:\n{current_memory}\n\n### INSTRUCTIONS:\n1. AGGRESSIVELY COMPRESS this memory. \n2. Delete duplicate information, repetitive logs, and obvious statements.\n3. Keep ONLY the core architectural rules and crucial file dependencies.\n4. The final output MUST BE UNDER 150 WORDS.\n5. Respond EXCLUSIVELY with the raw markdown. No fences, no thoughts.\n FINAL WARNING: Only output XML and code. If you add conversational text outside of <THOUGHT> or <EDIT>, the system will ROLLBACK.",
34-
"PP.md": "You are an elite PYOB Software Engineer. Analyze the code for bugs or architectural gaps.\n\n{memory_section}{ruff_section}{mypy_section}{custom_issues_section}### Source Code:\n```{lang_tag}\n{content}\n```\n\n### CRITICAL RULES:\n1. **ITERATION BUDGET**: \n - IF iteration < 5: Focus ONLY on bug fixes, linting, and minor performance tweaks. Do NOT create new files, move classes, or extract logic. \n - IF iteration >= 5: You may propose architectural refactors, file extractions, and logic movement.\n2. **SURGICAL FIXES**: Every <SEARCH> block must be exactly 2-5 lines. Only provide ONE <EDIT> block per response.\n3. **NO HALLUCINATIONS**: Do not invent bugs. If the code is functional, state 'The code looks good.'\n4. **ARCHITECTURAL BLOAT**: Only flag bloat for future planning until iteration 5.\n5. **MISSING IMPORTS**: If you use a new module/type, you MUST add an <EDIT> block to import it at the top.\n6. **INDENTATION IS SYNTAX**: Your <REPLACE> blocks must have perfect, absolute indentation.\n7. **DEFEATING MYPY**: If fixing a `[union-attr]` error, use `assert variable is not None` or `# type: ignore`.\n8. **IMPORT PATHS (MANDATORY)**: Never use the prefix `src.` in any import statement. The root of the package is `pyob`. (Example: Use `from pyob.core_utils import ...`, NOT `from src.pyob.core_utils import ...`).\n9. **TYPE HINTS (CRITICAL)**: Never use the `|` operator with quoted class names (Forward References). Use `Any` for objects that create circular dependencies.\n10. **ATOMIC REFACTORING**: If you are beyond iteration 5 and need to move logic, use a 3-step process: A) Add new file/imports. B) Update call sites. C) Remove old code in a subsequent turn.\n11. **NO SCAFFOLDING (CRITICAL)**: Never include bot-specific text, logs, or status tags (like \"APPROVED\" or \"LIBRARIAN\") inside the code blocks. Your output must be 100% valid code for the target language.\n\n### HOW TO RESPOND (CHOOSE ONE):\n\n**SCENARIO A: Code has bugs/bloat and needs edits:**\n<THOUGHT>\nSummary: ...\nEvaluation: [Address bloat here if flagged]\nImports Required: ...\nAction: I will fix X by doing Y.\n</THOUGHT>\n<EDIT>\n<SEARCH>\nExact lines to replace (2-5 lines max)\n</SEARCH>\n<REPLACE>\nNew lines\n</REPLACE>\n</EDIT>\n\n**SCENARIO B: Code is perfect. NO EDITS NEEDED:**\n<THOUGHT>\nSummary: ...\nEvaluation: ...\nAction: The code looks good. No fixes needed.\n</THOUGHT>\n FINAL WARNING: Only output XML and code. If you add conversational text outside of <THOUGHT> or <EDIT>, the system will ROLLBACK.",
34+
"PP.md": 'You are an elite PYOB Software Engineer. Analyze the code for bugs or architectural gaps.\n\n{memory_section}{ruff_section}{mypy_section}{custom_issues_section}### Source Code:\n```{lang_tag}\n{content}\n```\n\n### CRITICAL RULES:\n1. **ITERATION BUDGET**: \n - IF iteration < 5: Focus ONLY on bug fixes, linting, and minor performance tweaks. Do NOT create new files, move classes, or extract logic. \n - IF iteration >= 5: You may propose architectural refactors, file extractions, and logic movement.\n2. **SURGICAL FIXES**: Every <SEARCH> block must be exactly 2-5 lines. Only provide ONE <EDIT> block per response.\n3. **NO HALLUCINATIONS**: Do not invent bugs. If the code is functional, state \'The code looks good.\'\n4. **ARCHITECTURAL BLOAT**: Only flag bloat for future planning until iteration 5.\n5. **MISSING IMPORTS**: If you use a new module/type, you MUST add an <EDIT> block to import it at the top.\n6. **INDENTATION IS SYNTAX**: Your <REPLACE> blocks must have perfect, absolute indentation.\n7. **DEFEATING MYPY**: If fixing a `[union-attr]` error, use `assert variable is not None` or `# type: ignore`.\n8. **IMPORT PATHS (MANDATORY)**: Never use the prefix `src.` in any import statement. The root of the package is `pyob`. (Example: Use `from pyob.core_utils import ...`, NOT `from src.pyob.core_utils import ...`).\n9. **TYPE HINTS (CRITICAL)**: Never use the `|` operator with quoted class names (Forward References). Use `Any` for objects that create circular dependencies.\n10. **ATOMIC REFACTORING**: If you are beyond iteration 5 and need to move logic, use a 3-step process: A) Add new file/imports. B) Update call sites. C) Remove old code in a subsequent turn.\n11. **NO SCAFFOLDING (CRITICAL)**: Never include bot-specific text, logs, or status tags (like "APPROVED" or "LIBRARIAN") inside the code blocks. Your output must be 100% valid code for the target language.\n\n### HOW TO RESPOND (CHOOSE ONE):\n\n**SCENARIO A: Code has bugs/bloat and needs edits:**\n<THOUGHT>\nSummary: ...\nEvaluation: [Address bloat here if flagged]\nImports Required: ...\nAction: I will fix X by doing Y.\n</THOUGHT>\n<EDIT>\n<SEARCH>\nExact lines to replace (2-5 lines max)\n</SEARCH>\n<REPLACE>\nNew lines\n</REPLACE>\n</EDIT>\n\n**SCENARIO B: Code is perfect. NO EDITS NEEDED:**\n<THOUGHT>\nSummary: ...\nEvaluation: ...\nAction: The code looks good. No fixes needed.\n</THOUGHT>\n FINAL WARNING: Only output XML and code. If you add conversational text outside of <THOUGHT> or <EDIT>, the system will ROLLBACK.',
3535
"ALF.md": "You are an elite developer fixing syntax errors.\nThe file `{rel_path}` failed validation with these exact errors:\n{err_text}\n\n### Current Code:\n```\n{code}\n```\n\n### Instructions:\n1. Fix the syntax errors (like stray brackets, unexpected tokens, or indentation) using surgical XML edits.\n2. Respond EXCLUSIVELY with a <THOUGHT> block followed by ONE OR MORE <EDIT> blocks.\n3. Ensure your edits perfectly align with the surrounding brackets.\n FINAL WARNING: Only output XML and code. If you add conversational text outside of <THOUGHT> or <EDIT>, the system will ROLLBACK.",
3636
"FRE.md": "You are an elite PYOB developer fixing runtime crashes.\n{memory_section}The application crashed during a test run.\n\n### Crash Logs & Traceback:\n{logs}\n\nThe traceback indicates the error occurred in `{rel_path}`.\n\n### Current Code of `{rel_path}`:\n```python\n{code}\n```\n\n### Instructions:\n1. Identify the EXACT root cause of the crash.\n2. Fix the error using surgical XML edits.\n3. Respond EXCLUSIVELY with a <THOUGHT> block followed by ONE OR MORE <EDIT> blocks.\n\n### REQUIRED XML FORMAT:\n<THOUGHT>\nExplanation of root cause...\nImports Needed: [List new imports required or 'None']\n</THOUGHT>\n<EDIT>\n<SEARCH>\nExact lines to replace\n</SEARCH>\n<REPLACE>\nNew replacement lines\n</REPLACE>\n</EDIT>",
3737
"PF.md": "You are the PYOB Product Architect. Review the source code and suggest ONE highly useful, INTERACTIVE feature.\n\n{memory_section}### Source Code:\n```{lang_tag}\n{content}\n```\n\n### CRITICAL RULES:\n1. Suggest an INTERACTIVE feature (UI elements, buttons, menus).\n2. **ARCHITECTURAL SPLIT (MANDATORY)**: If the source code is over 800 lines, you ARE NOT ALLOWED to propose a new feature. You MUST propose an 'Architectural Split'. Identify a logical module (like a Mixin) to move to a NEW file.\n3. **SINGLE FILE LIMIT**: If you are proposing an Architectural Split, you are ONLY allowed to create ONE new file per iteration. Do not attempt to split multiple modules at once. Focus on the largest logical block first.\n4. **NEW FILE FORMAT**: If proposing a split, your <SNIPPET> block MUST use this format: <CREATE_FILE path=\"new_filename.py\">[Full Code for New File]</CREATE_FILE>. Your <THOUGHT> must then explain how to update the original file to import this new module.\n5. MULTI-FILE ORCHESTRATION: Explicitly list filenames of other files that will need updates in your <THOUGHT>.\n6. The <SNIPPET> block MUST contain ONLY the new logic or the <CREATE_FILE> block.\n\n### REQUIRED XML FORMAT:\n<THOUGHT>\n...\n</THOUGHT>\n<SNIPPET>\n# New logic OR <CREATE_FILE> tag here\n</SNIPPET>\n FINAL WARNING: Only output XML and code. If you add conversational text outside of <THOUGHT> or <EDIT>, the system will ROLLBACK.",

0 commit comments

Comments
 (0)