This commit is contained in:
2026-03-06 23:07:08 -05:00
parent cb57cc4a02
commit 4921a6715c
7 changed files with 51 additions and 44 deletions

View File

@@ -1,4 +1,4 @@
# mcp_client.py
# mcp_client.py
"""
Note(Gemini):
MCP-style file context tools for manual_slop.
@@ -322,7 +322,7 @@ def set_file_slice(path: str, start_line: int, end_line: int, new_content: str)
new_content += "\n"
new_lines = new_content.splitlines(keepends=True) if new_content else []
lines[start_idx:end_idx] = new_lines
p.write_text("".join(lines), encoding="utf-8", newline="")
p.write_text("".join(lines), encoding="utf-8")
return f"Successfully updated lines {start_line}-{end_line} in {path}"
except Exception as e:
return f"ERROR updating slice in '{path}': {e}"
@@ -341,7 +341,7 @@ def edit_file(path: str, old_string: str, new_string: str, replace_all: bool = F
if not old_string:
return "ERROR: old_string cannot be empty"
try:
content = p.read_text(encoding="utf-8", newline="")
content = p.read_text(encoding="utf-8")
if old_string not in content:
return f"ERROR: old_string not found in '{path}'"
count = content.count(old_string)
@@ -349,11 +349,11 @@ def edit_file(path: str, old_string: str, new_string: str, replace_all: bool = F
return f"ERROR: Found {count} matches for old_string in '{path}'. Use replace_all=true or provide more context to make it unique."
if replace_all:
new_content = content.replace(old_string, new_string)
p.write_text(new_content, encoding="utf-8", newline="")
p.write_text(new_content, encoding="utf-8")
return f"Successfully replaced {count} occurrences in '{path}'"
else:
new_content = content.replace(old_string, new_string, 1)
p.write_text(new_content, encoding="utf-8", newline="")
p.write_text(new_content, encoding="utf-8")
return f"Successfully replaced 1 occurrence in '{path}'"
except Exception as e:
return f"ERROR editing '{path}': {e}"
@@ -734,10 +734,10 @@ def get_tree(path: str, max_depth: int = 2) -> str:
entries = [e for e in entries if not e.name.startswith('.') and e.name not in ('__pycache__', 'venv', 'env') and e.name != "history.toml" and not e.name.endswith("_history.toml")]
for i, entry in enumerate(entries):
is_last = (i == len(entries) - 1)
connector = "└── " if is_last else "├── "
connector = "└── " if is_last else "├── "
lines.append(f"{prefix}{connector}{entry.name}")
if entry.is_dir():
extension = " " if is_last else " "
extension = " " if is_last else "│ "
lines.extend(_build_tree(entry, current_depth + 1, prefix + extension))
return lines
tree_lines = [f"{p.name}/"] + _build_tree(p, 1)
@@ -1416,3 +1416,5 @@ MCP_TOOL_SPECS: list[dict[str, Any]] = [
}
]