|
5 | 5 | from pathlib import Path |
6 | 6 |
|
7 | 7 | ROOT = Path(__file__).resolve().parents[1] |
8 | | -REPORT = ROOT / "reports" / "cmo-analysis.json" |
| 8 | +ANALYSIS = ROOT / "reports" / "cmo-analysis.json" |
| 9 | +POLICY = ROOT / "config" / "operating_policy.json" |
9 | 10 | OUT = ROOT / "data" / "engagement-queue.json" |
10 | 11 |
|
11 | 12 |
|
12 | | -def main() -> None: |
13 | | - if not REPORT.exists(): |
14 | | - raise SystemExit("Run analyze_x_cmo.py first") |
| 13 | +def load_json(path: Path): |
| 14 | + if not path.exists(): |
| 15 | + raise SystemExit(f"Missing {path}") |
| 16 | + return json.loads(path.read_text()) |
| 17 | + |
| 18 | + |
| 19 | +def split_counts(total: int, core_pct: int): |
| 20 | + core = int(round(total * core_pct / 100.0)) |
| 21 | + discovery = max(0, total - core) |
| 22 | + return core, discovery |
15 | 23 |
|
16 | | - r = json.loads(REPORT.read_text()) |
| 24 | + |
| 25 | +def main() -> None: |
| 26 | + analysis = load_json(ANALYSIS) |
| 27 | + policy = load_json(POLICY) |
17 | 28 |
|
18 | 29 | queue = { |
19 | 30 | "generated_at": datetime.now(timezone.utc).isoformat(), |
20 | | - "mode": "dry-run", |
| 31 | + "mode": "dry-run" if policy.get("automation", {}).get("dry_run_default", True) else "live", |
| 32 | + "policy_ref": str(POLICY), |
21 | 33 | "actions": [], |
22 | 34 | } |
23 | 35 |
|
24 | | - # Very conservative starter policy: propose root posts + selective replies. |
25 | | - for handle, stats in r["accounts"].items(): |
26 | | - # root content recommendation |
| 36 | + targeting = policy.get("targeting", {}) |
| 37 | + core_pct = targeting.get("core_whitelist_pct", 80) |
| 38 | + |
| 39 | + for handle, stats in analysis.get("accounts", {}).items(): |
| 40 | + account_policy = policy.get("account_strategy", {}).get(handle, {}) |
| 41 | + daily_reply_cap = int(account_policy.get("daily_reply_cap", 6)) |
| 42 | + windows = account_policy.get("time_windows_est", []) |
| 43 | + |
| 44 | + # Always include one root post anchor action per run cycle. |
27 | 45 | queue["actions"].append( |
28 | 46 | { |
29 | 47 | "account": handle, |
30 | 48 | "action": "root_post", |
31 | 49 | "priority": "high", |
32 | | - "why": "Keep account voice anchored with original thesis/product narrative.", |
| 50 | + "window_est": windows, |
| 51 | + "why": "Anchor narrative with original voice-aligned post.", |
33 | 52 | "constraints": { |
34 | | - "min_gap_minutes": 180, |
35 | 53 | "must_pass_voice_review": True, |
| 54 | + "must_align_strategy": True, |
| 55 | + "min_gap_minutes": 180, |
36 | 56 | }, |
37 | 57 | } |
38 | 58 | ) |
39 | 59 |
|
40 | | - # reply recommendation from top targets, but cap volume |
41 | | - targets = [u for u, _ in stats.get("top_reply_targets", [])][:5] |
42 | | - for t in targets: |
| 60 | + # Build candidate pools from observed high-frequency targets. |
| 61 | + observed_targets = [u for u, _ in stats.get("top_reply_targets", [])] |
| 62 | + core_count, discovery_count = split_counts(daily_reply_cap, core_pct) |
| 63 | + |
| 64 | + # Core (whitelist-style): historically engaged users. |
| 65 | + for target in observed_targets[:core_count]: |
43 | 66 | queue["actions"].append( |
44 | 67 | { |
45 | 68 | "account": handle, |
46 | 69 | "action": "reply", |
47 | | - "target_user": t, |
| 70 | + "target_user": target, |
| 71 | + "target_pool": "core", |
48 | 72 | "priority": "medium", |
49 | | - "why": "User appears in recent interaction graph.", |
| 73 | + "window_est": windows, |
| 74 | + "why": "Continuation of existing interaction graph.", |
50 | 75 | "constraints": { |
51 | 76 | "max_replies_to_same_user_per_24h": 1, |
52 | | - "min_delay_seconds": random.randint(45, 180), |
53 | 77 | "must_be_contextual": True, |
| 78 | + "must_clear_relevance_score": targeting.get("minimum_relevance_score", 0.7), |
| 79 | + "min_delay_seconds": random.randint( |
| 80 | + policy["risk_controls"].get("random_delay_seconds_min", 45), |
| 81 | + policy["risk_controls"].get("random_delay_seconds_max", 180), |
| 82 | + ), |
| 83 | + }, |
| 84 | + } |
| 85 | + ) |
| 86 | + |
| 87 | + # Discovery budget: placeholders to be filled by candidate-harvest stage. |
| 88 | + for _ in range(discovery_count): |
| 89 | + queue["actions"].append( |
| 90 | + { |
| 91 | + "account": handle, |
| 92 | + "action": "reply", |
| 93 | + "target_user": None, |
| 94 | + "target_pool": "discovery", |
| 95 | + "priority": "low", |
| 96 | + "window_est": windows, |
| 97 | + "why": "Exploration budget for net-new qualified audience.", |
| 98 | + "constraints": { |
| 99 | + "must_be_contextual": True, |
| 100 | + "must_clear_relevance_score": targeting.get("minimum_relevance_score", 0.7), |
| 101 | + "must_not_hit_founder_denylist": handle == "TheCesarCross", |
54 | 102 | }, |
55 | 103 | } |
56 | 104 | ) |
|
0 commit comments