Commit 1d066e88 authored by Lisa's avatar Lisa

Cleanup: remove orphaned duplicate code, add .gitignore

  - Removed 102 lines of orphaned duplicate PosixComputerController class
  - Fixed code structure: PosixComputerController defined only once (lines 198-267)
  - Reduced file size from 658 to 556 lines

  - Added .gitignore for Python/Windows artifacts:
    * __pycache__/ and *.pyc
    * venv/, build/, dist/
    * *.bak, *.backup
    * windows/build/, windows/Output/
    * IDE files (.vscode, .idea)

  - Removed __pycache__ from git staging (no longer tracked)

Documentation already present in README.md and windows/README.md.
parent e6ac1749
# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
*.egg-info/
dist/
build/
*.egg
# Virtual environments
venv/
env/
ENV/
# IDE
.vscode/
.idea/
*.swp
*.swo
*~
# OS
.DS_Store
Thumbs.db
# Logs
*.log
# Backup files
*.bak
*.bak2
*.backup
# Windows build artifacts
windows/dist/
windows/build/
windows/Output/
# Test files
.pytest_cache/
.coverage
htmlcov/
...@@ -392,108 +392,6 @@ def make_computer_controller(config: Dict[str, Any]) -> Optional[ComputerControl ...@@ -392,108 +392,6 @@ def make_computer_controller(config: Dict[str, Any]) -> Optional[ComputerControl
return None return None
"""Desktop automation via X11 tools (xdotool, import)."""
def __init__(self):
self.display = os.environ.get('DISPLAY', ':0')
self._check_deps()
def _check_deps(self):
"""Verify required command-line tools are present."""
self.has_xdotool = subprocess.run(['which', 'xdotool'], capture_output=True).returncode == 0
self.has_import = subprocess.run(['which', 'import'], capture_output=True).returncode == 0
self.has_scrot = subprocess.run(['which', 'scrot'], capture_output=True).returncode == 0
if not (self.has_xdotool and (self.has_import or self.has_scrot)):
logger.warning("computer_control: missing xdotool or screenshot tool")
def _run(self, cmd) -> Dict[str, Any]:
"""Run a command and return success/error dict."""
try:
result = subprocess.run(
cmd, shell=True,
capture_output=True, text=True,
timeout=30
)
return {
"success": result.returncode == 0,
"stdout": result.stdout.strip(),
"stderr": result.stderr.strip(),
"exit_code": result.returncode
}
except Exception as e:
return {"success": False, "error": str(e)}
# ── Screenshot ──────────────────────────────────────────────────────────
def screenshot(self, output_path: Optional[str] = None) -> Dict[str, Any]:
"""Take a screenshot of the entire desktop."""
if output_path:
# Save to file
if self.has_import:
cmd = f'import -display {self.display} -window root "{output_path}"'
else:
cmd = f'scrot -d 1 "{output_path}"'
return self._run(cmd)
else:
# Return base64-encoded PNG data
if self.has_import:
cmd = f'import -display {self.display} -window root png:-'
try:
result = subprocess.run(cmd, shell=True, capture_output=True, timeout=30)
if result.returncode == 0:
import base64
b64 = base64.b64encode(result.stdout).decode('ascii')
return {
"success": True,
"format": "png",
"data": b64,
"size": len(result.stdout)
}
except Exception as e:
return {"success": False, "error": str(e)}
return {"success": False, "error": "No screenshot tool available"}
# ── Mouse ───────────────────────────────────────────────────────────────
def mouse_move(self, x: int, y: int) -> Dict[str, Any]:
return self._run(f'xdotool mousemove {x} {y}')
def mouse_click(self, button: int = 1) -> Dict[str, Any]:
"""button: 1=left, 2=middle, 3=right"""
return self._run(f'xdotool click {button}')
def mouse_position(self) -> Dict[str, Any]:
out = self._run('xdotool getmouselocation --shell')
if out['success']:
info = {}
for line in out['stdout'].splitlines():
if '=' in line:
k, v = line.split('=', 1)
info[k] = int(v)
return {"success": True, "position": info}
return out
# ── Keyboard ─────────────────────────────────────────────────────────────
def type_text(self, text: str) -> Dict[str, Any]:
# Escape special chars for shell
safe = text.replace("'", "'\"'\"'")
return self._run(f"xdotool type --delay 1 '{safe}'")
def key_press(self, key: str) -> Dict[str, Any]:
"""Press a single key (e.g. 'Return', 'Ctrl+c', 'alt+Tab')."""
return self._run(f'xdotool key {key}')
def get_active_window(self) -> Dict[str, Any]:
"""Get currently-focused window info."""
win_id = self._run("xdotool getactivewindow")
if win_id['success']:
title = self._run(f"xdotool getwindowname {win_id['stdout']}")
return {
"success": True,
"window_id": win_id['stdout'],
"title": title.get('stdout', '')
}
return win_id
# ── Node Agent ───────────────────────────────────────────────────────────────
class NodeAgent: class NodeAgent:
def __init__(self, config_path: Optional[str] = None): def __init__(self, config_path: Optional[str] = None):
self.config = self._load_config(config_path) self.config = self._load_config(config_path)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment