From bfe9ef014d7984ce7f358fae4cb4f814c0d0e01a Mon Sep 17 00:00:00 2001 From: Ed_ Date: Mon, 23 Feb 2026 19:20:29 -0500 Subject: [PATCH] feat(simulation): add ping-pong interaction script --- simulation/ping_pong.py | 57 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 simulation/ping_pong.py diff --git a/simulation/ping_pong.py b/simulation/ping_pong.py new file mode 100644 index 0000000..764f2b3 --- /dev/null +++ b/simulation/ping_pong.py @@ -0,0 +1,57 @@ +import sys +import os +import time + +# Ensure project root is in path +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) + +from api_hook_client import ApiHookClient +from simulation.user_agent import UserSimAgent + +def main(): + client = ApiHookClient() + print("Waiting for hook server...") + if not client.wait_for_server(timeout=5): + print("Hook server not found. Start GUI with --enable-test-hooks") + return + + sim_agent = UserSimAgent(client) + + # 1. Reset session to start clean + print("Resetting session...") + client.click("btn_reset") + time.sleep(2) # Give it time to clear + + # 2. Initial message + initial_msg = "Hello! I want to create a simple python script that prints 'Hello World'. Can you help me?" + print(f" +[USER]: {initial_msg}") + client.set_value("ai_input", initial_msg) + client.click("btn_gen_send") + + # 3. Wait for AI response + print("Waiting for AI response...", end="", flush=True) + last_entry_count = 0 + for _ in range(60): # 60 seconds max + time.sleep(1) + print(".", end="", flush=True) + session = client.get_session() + entries = session.get('session', {}).get('entries', []) + + if len(entries) > last_entry_count: + # Something happened + last_entry = entries[-1] + if last_entry.get('role') == 'AI' and last_entry.get('content'): + print(f" + +[AI]: {last_entry.get('content')[:100]}...") + print(" +Ping-pong successful!") + return + last_entry_count = len(entries) + + print(" +Timeout waiting for AI response") + +if __name__ == "__main__": + main()