Files
museion/docs/research/prompt-order-probe.py
AlexKucera 22bca36857
CI / ci (push) Canceled after 0s
feat(mentor): pin prompt-end constraint ordering (#1)
Both personas gain the verbatim-shared "Draft first, rules last"
section (pass 1.5, session 1.2): the writer's material enters
context before the rule skills, so the deslop constraint tables sit
after the draft, nearest the writing they govern — the PRD's
prompt-end rule. A real ACP audit (the app's exact wire — never
-z: one-shot mode swaps the skills directive and loads nothing)
showed the baseline already read the piece before deslop, but by
model choice; the pin converts observed-once into instructed-
always, and PersonaLoadOrderTests guards presence + verbatim
parity over the bundled payload.

Verified layout, probe traps, and the additive-only propagation
cost are documented in docs/research/prompt-layout-factsheet.md
with the probe script in-repo; real-run verify: piece → persona →
deslop → verdict, 6 fix cards + 2 research candidates landed on
the real rails. Suite 479 + 1 load-flake cleared in isolation.

Closes #1
2026-10-30 11:20:01 +01:00

77 lines
2.6 KiB
Python

#!/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)