45 lines
2.0 KiB
Python
45 lines
2.0 KiB
Python
import os as _os, sys as _sys
|
|
_w = _os.path.dirname(_os.path.abspath(__file__))
|
|
while _w != "/" and not _os.path.isdir(_os.path.join(_w, "hand")):
|
|
_w = _os.path.dirname(_w)
|
|
WURZEL = _w
|
|
for _u in ("lesen", "entscheiden", "hand", "lobby", "korpus", "betrieb", "mock"):
|
|
_q = _os.path.join(_w, _u)
|
|
if _os.path.isdir(_q) and _q not in _sys.path:
|
|
_sys.path.insert(0, _q)
|
|
import json, os, select, subprocess, sys, time
|
|
S = os.path.expanduser("~/Projects/pokerfreak-shell")
|
|
p = subprocess.Popen(["bash", os.path.join(S, "run.sh")], stdin=subprocess.PIPE,
|
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, bufsize=1, cwd=S)
|
|
def send(o):
|
|
p.stdin.write(json.dumps(o) + "\n"); p.stdin.flush()
|
|
def read(sek=12):
|
|
ende = time.time() + sek
|
|
while time.time() < ende:
|
|
if select.select([p.stdout], [], [], 0.3)[0]:
|
|
zeile = p.stdout.readline()
|
|
if zeile.strip():
|
|
try: return json.loads(zeile)
|
|
except Exception: return {"raw": zeile[:300]}
|
|
return None
|
|
send({"jsonrpc":"2.0","id":1,"method":"initialize","params":{
|
|
"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"probe","version":"1"}}})
|
|
init = read(15) or {}
|
|
print("initialize:", json.dumps(init.get("result", init), ensure_ascii=False)[:260])
|
|
send({"jsonrpc":"2.0","method":"notifications/initialized","params":{}})
|
|
send({"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}})
|
|
r = read() or {}
|
|
tools = (r.get("result") or {}).get("tools", [])
|
|
print(f"\nWerkzeuge: {len(tools)}")
|
|
for t in tools:
|
|
print(" -", t["name"], "|", (t.get("description") or "").split("\n")[0][:66])
|
|
send({"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"status","arguments":{}}})
|
|
a = read(25) or {}
|
|
erg = (a.get("result") or {})
|
|
inhalt = erg.get("content") or []
|
|
print("\nstatus ->", json.dumps(inhalt, ensure_ascii=False)[:800] if inhalt else json.dumps(a, ensure_ascii=False)[:500])
|
|
p.terminate()
|
|
time.sleep(0.4)
|
|
fehler = (p.stderr.read() or "")[:400]
|
|
if fehler.strip(): print("\nstderr:", fehler)
|