#!/usr/bin/env python3 """Issue #1 audit probe: speak ACP to hermes exactly like Museion's ACPEngineClient. initialize (slim, pass flavor) -> session/new -> prompt(pass stub). Prints the sessionId + stopReason; the messages land in the profile's state.db where the layout audit reads them back. """ import json, subprocess, sys, threading, queue, time PROFILE = sys.argv[1] if len(sys.argv) > 1 else "museion-pass1" STUB = open(sys.argv[2]).read() if len(sys.argv) > 2 else "hello" CWD = "/Users/alex/.hermes/cache/scratch/museion-issue1" p = subprocess.Popen( ["hermes", "acp", "-p", PROFILE], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, bufsize=1, ) inq = queue.Queue() def reader(): for line in p.stdout: inq.put(line.strip()) threading.Thread(target=reader, daemon=True).start() stderr_lines = [] threading.Thread(target=lambda: [stderr_lines.append(l) for l in p.stderr], daemon=True).start() _next_id = [0] def request(method, params, timeout=600): _next_id[0] += 1 rid = _next_id[0] msg = {"jsonrpc": "2.0", "id": rid, "method": method, "params": params} p.stdin.write(json.dumps(msg) + "\n"); p.stdin.flush() deadline = time.time() + timeout while time.time() < deadline: try: line = inq.get(timeout=1) except queue.Empty: continue try: d = json.loads(line) except json.JSONDecodeError: print("UNPARSED:", line[:200]); continue if d.get("id") == rid: if "error" in d: raise RuntimeError(f"{method}: {d['error']}") return d.get("result") # notifications — log tool traffic compactly for the live view if method_ := d.get("method"): up = (d.get("params") or {}).get("update") or {} kind = up.get("sessionUpdate") if kind == "tool_call": print(f" [tool_call] {up.get('toolCall',{}).get('title','')[:80]}") elif kind == "agent_message_chunk": pass raise TimeoutError(method) r = request("initialize", { "protocolVersion": 1, "clientCapabilities": {}, "clientInfo": {"name": "Museion", "title": "Museion", "version": "0.1"}, }) print("agentInfo:", json.dumps(r.get("agentInfo"))) r = request("session/new", {"cwd": CWD, "mcpServers": []}) sid = r["sessionId"] print("sessionId:", sid) r = request("session/prompt", { "sessionId": sid, "prompt": [{"type": "text", "text": STUB}], }) print("stopReason:", r.get("stopReason")) print("lastChunk:", json.dumps(r.get("lastChunk"))[:200]) p.stdin.close(); p.terminate() sys.exit(0)