Add STS2MCP HTTP client and state capture tool

sts2.py: thin client for the mod's localhost HTTP API, maps
state_type -> legal actions (the action space), strict
observe -> act once -> observe-again loop.
capture.py: manual state snapshot tool for building facts.py.
This commit is contained in:
0xrsydn 2026-09-21 17:09:43 +07:00
commit 5b57fc7af3
2 changed files with 254 additions and 0 deletions

27
capture.py Normal file
View file

@ -0,0 +1,27 @@
#!/usr/bin/env python3
"""Save game state snapshots to ./capture/<label>.json while building facts.py.
usage: python3 capture.py <label> [--wait SECONDS]
"""
import json, sys, time, pathlib
sys.path.insert(0, str(pathlib.Path(__file__).parent))
import sts2
def snap(label, wait=1.0):
if wait: time.sleep(wait)
obs = sts2.state()
out = pathlib.Path(__file__).parent / "capture"
out.mkdir(exist_ok=True)
path = out / f"{label}.json"
path.write_text(json.dumps(obs, indent=2))
print(f"[{label}] state_type={obs.get('state_type')!r} "
f"msg={str(obs.get('message'))[:60]!r} -> {path.name} ({path.stat().st_size}B)")
return obs
if __name__ == "__main__":
args = [a for a in sys.argv[1:] if not a.startswith("--")]
wait = 1.0
if "--wait" in sys.argv:
wait = float(sys.argv[sys.argv.index("--wait") + 1])
for lbl in args:
snap(lbl, wait)