Files
RoboMovel/simulacao/robo-movel-godot/addons/claude_godot/agent/tools/shell_bridge.py
T
mguinhosandClaude Opus 5.5 393019705c Projeto: app demo, servidor/firmware em software/, simulacao Godot, planta do bloco D, chapas MDF da base, renders e slides
- app/: app demo (Kivy/buildozer) da API do robo
- software/: servidor RoboMovel (SLAM, profundidade, navegacao) e firmware da base movel (movido de firmware/)
- simulacao/: projeto Godot do robo e script de lancamento servidor + simulacao
- modelos/: planta do 5o andar do bloco D, cena Blender do corredor e modelo real do robo
- partes/mdf/: chapas identificadas e nesting da base do robo (DXF/SVG/FCStd)
- projeto/render, relatorio/imagens, slides: renders finais e apresentacoes de progresso
- ferramentas/scripts: encaixe de chapas, planta do bloco D e render do corredor no Blender
- .gitignore: ignora backups do Blender/FreeCAD e .godot/

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 23:38:16 -03:00

94 lines
3.0 KiB
Python

#!/usr/bin/env python3
"""Minimal exec bridge for the claude-godot remote tool.
Godot on Android/Quest can't spawn processes (OS.execute is unavailable) and
can't speak SSH (the engine doesn't expose the crypto SSH needs), but it can
open a TCP socket. Run this next to the shell you want commands to run in —
in Termux on the same device, 127.0.0.1 is shared across Android apps, so the
editor reaches it without any network setup.
python shell_bridge.py [--host 127.0.0.1] [--port 8799]
Binds to loopback only by default. It runs whatever it is told to run, with
no authentication, so do not bind it to a routable address on a network you
don't control.
"""
import argparse
import json
import subprocess
from http.server import BaseHTTPRequestHandler, HTTPServer
MAX_OUTPUT = 100_000
class Handler(BaseHTTPRequestHandler):
def do_POST(self):
if self.path != "/exec":
self._reply(404, {"error": "unknown path"})
return
try:
length = int(self.headers.get("Content-Length", 0))
payload = json.loads(self.rfile.read(length) or b"{}")
except (ValueError, json.JSONDecodeError) as exc:
self._reply(400, {"error": f"bad request: {exc}"})
return
command = payload.get("command", "")
if not command:
self._reply(400, {"error": "missing command"})
return
cwd = payload.get("cwd") or None
timeout = min(float(payload.get("timeout", 15)), 60)
print(f"> {command}" + (f" (cwd={cwd})" if cwd else ""), flush=True)
try:
proc = subprocess.run(
command,
shell=True,
cwd=cwd,
capture_output=True,
text=True,
timeout=timeout,
)
self._reply(200, {
"exit_code": proc.returncode,
"stdout": proc.stdout[:MAX_OUTPUT],
"stderr": proc.stderr[:MAX_OUTPUT],
})
except subprocess.TimeoutExpired:
self._reply(200, {
"exit_code": -1,
"stdout": "",
"stderr": f"timed out after {timeout:g}s",
})
except OSError as exc:
self._reply(200, {"exit_code": -1, "stdout": "", "stderr": str(exc)})
def _reply(self, status, body):
encoded = json.dumps(body).encode()
self.send_response(status)
self.send_header("Content-Type", "application/json")
self.send_header("Content-Length", str(len(encoded)))
self.end_headers()
self.wfile.write(encoded)
def log_message(self, *args):
pass
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--host", default="127.0.0.1")
parser.add_argument("--port", type=int, default=8799)
args = parser.parse_args()
print(f"shell bridge on {args.host}:{args.port} — ctrl-c to stop", flush=True)
HTTPServer((args.host, args.port), Handler).serve_forever()
if __name__ == "__main__":
main()