diff --git a/bin/job-dispatch.py b/bin/job-dispatch.py index 83d65be..a8caef9 100755 --- a/bin/job-dispatch.py +++ b/bin/job-dispatch.py @@ -12,6 +12,7 @@ Part of the JOB system (see docs/JOB-SPEC.md). """ import sys +import re import os import json import subprocess @@ -156,21 +157,30 @@ def main(): if sidechat_cfg.get("create", False): # Create sidechat in sender's (opm's) context + # Then send the job DM DIRECTLY to the sidechat, not main. + # This keeps main chat clean; the sidechat IS the job workspace. print(f"Creating sidechat for job {job_id}...", file=sys.stderr) sidechat_url = create_sidechat("opm", dry_run=dry_run) if sidechat_url: - # Render name template for display - name_tmpl = sidechat_cfg.get("name_template", "job-{job_name}-{date}") - sc_name = render_prompt(name_tmpl, variables) - dm_message += f"\n\n[Sidechat created: {sc_name}]\nWork in this side chat. URL: {sidechat_url}" - target = "main" # DM goes to main, directs to sidechat - log_event("job_sidechat_created", { - "job_id": job_id, - "sidechat_url": sidechat_url, - "sidechat_name": sc_name, - }) + # Extract thread ID from URL (https://muse.ai/thread/) + m = re.search(r"/thread/([a-f0-9-]+)", sidechat_url) + if m: + thread_id = m.group(1) + target = thread_id # DM goes directly to sidechat + name_tmpl = sidechat_cfg.get("name_template", "job-{job_name}-{date}") + sc_name = render_prompt(name_tmpl, variables) + log_event("job_sidechat_created", { + "job_id": job_id, + "sidechat_url": sidechat_url, + "sidechat_name": sc_name, + "thread_id": thread_id, + }) + print(f"Sidechat created: {sc_name} ({thread_id})", file=sys.stderr) + else: + print(f"Warning: Could not parse thread ID from {sidechat_url}", file=sys.stderr) + target = "main" else: - print(f"Warning: Failed to create sidechat, proceeding without", file=sys.stderr) + print(f"Warning: Failed to create sidechat, falling back to main", file=sys.stderr) target = "main" else: target = "main"