diff --git a/tools/gh-monitor/poll.py b/tools/gh-monitor/poll.py index 9edb715..aad9fe1 100644 --- a/tools/gh-monitor/poll.py +++ b/tools/gh-monitor/poll.py @@ -153,10 +153,10 @@ def format_notification(repo_slug: str, pr: dict, event: dict) -> str: return f'[gh-monitor] PR #{number} "{title}" — {actor} {action}:\n"{body_preview}"\n{url}' -def dispatch_agent(repo_slug: str, pr: dict, event: dict) -> None: +def dispatch_to_main(repo_slug: str, pr: dict, event: dict) -> None: """ - Fire a one-shot isolated agentTurn via `openclaw cron add` to handle the event. - The agent reads the PR, replies to the comment, and pushes fixes if needed. + Send a system event to the main session with full context so Hans handles + the PR comment directly — no isolated agent needed. """ number = pr["number"] title = pr["title"] @@ -165,50 +165,17 @@ def dispatch_agent(repo_slug: str, pr: dict, event: dict) -> None: body = (event["body"] or "")[:500] url = event["url"] - message = ( - f"gh-monitor detected new PR activity — act on it now.\n\n" - f"Repo: {repo_slug}\n" - f"PR #{number}: {title}\n" - f"Event: {actor} {action}\n" - f"Comment: {body}\n" - f"URL: {url}\n\n" - f"Instructions:\n" - f"1. Read the full PR and the comment at the URL above.\n" - f"2. IMMEDIATELY post a reply to the comment on GitHub acknowledging you have " - f"read it — even if you haven't done the work yet. Something like " - f"'Got it, looking into this now.' This must happen first, before any code changes.\n" - f"3. If the comment requests a code change, implement it on the PR branch, " - f"commit, and push.\n" - f"4. Post a follow-up GitHub reply with what you did (or why no change was needed).\n" - f"5. Run this exact command when done to notify Andrew on Signal:\n" - f" openclaw system event --text \"[gh-monitor] PR #{number}: \" --mode now\n" - f"6. Keep replies concise and technical." + text = ( + f"[gh-monitor] New PR activity on {repo_slug}#{number} \"{title}\":\n" + f"{actor} {action}:\n" + f'"{body}"\n' + f"{url}\n\n" + f"Read the full comment, address it if needed (code change + GitHub reply), " + f"and notify Andrew on Signal when done." ) - job_name = f"gh-monitor-pr{number}-{event.get('id', 'evt')}" - - try: - result = subprocess.run( - [ - "openclaw", "cron", "add", - "--name", job_name, - "--at", "1m", - "--session", "isolated", - "--message", message, - "--delete-after-run", - "--no-deliver", - "--timeout-seconds", "300", - ], - capture_output=True, - text=True, - timeout=15, - ) - if result.returncode == 0: - log.info("Dispatched agent for PR #%d %s", number, action) - else: - log.warning("Failed to dispatch agent for PR #%d: %s", number, result.stderr.strip()) - except Exception as exc: - log.warning("Failed to dispatch agent for PR #%d: %s", number, exc) + notify(text) + log.info("Notified main session for PR #%d %s by %s", number, action, actor) # --------------------------------------------------------------------------- @@ -325,7 +292,7 @@ def poll_repo(repo_cfg: dict, state: dict) -> dict: for pr, event in all_new_events: log.info("[%s] New event: PR #%d %s by %s", repo_slug, pr["number"], event["action"], event["actor"]) - dispatch_agent(repo_slug, pr, event) + dispatch_to_main(repo_slug, pr, event) if event.get("id"): seen_ids.add(event["id"])