#!/usr/bin/env python3 import sqlite3 import json import os import subprocess import time DB_PATH = '/root/.hermes/kanban/boards/research-hub/kanban.db' PROJECT_BASE = '/opt/ai-os/products/ceo/content/research/tourism_benchmarking/' def check_and_orchestrate(): conn = sqlite3.connect(DB_PATH) c = conn.cursor() # 1. Lấy toàn bộ task không bị archived rows = c.execute("SELECT id, title, assignee, status, body FROM tasks WHERE status != 'archived'").fetchall() vn_tasks = [r for r in rows if '[VN.' in r[1]] tl_tasks = [r for r in rows if '[TL.' in r[1]] messages = [] # --- ORCHESTRATE VIETNAM --- if not vn_tasks or all(t[3] == 'done' for t in vn_tasks): # Không có task hoặc tất cả đã done -> Khởi tạo Loop mới subprocess.run(['python3', './init_pipeline.py', 'VN']) messages.append("🔄 **Khởi động Vòng Nghiên cứu Mới - Việt Nam (VN) [KẾ THỪA]**") else: # Báo cáo các task đang chạy running_vn = [t for t in vn_tasks if t[3] == 'running'] if running_vn: for t in running_vn: messages.append(f"🔄 **VN Pipeline:** `{t[1]}` đang thực thi...") # --- ORCHESTRATE THAILAND --- if not tl_tasks or all(t[3] == 'done' for t in tl_tasks): # Không có task hoặc tất cả đã done -> Khởi tạo Loop mới subprocess.run(['python3', './init_pipeline.py', 'TL']) messages.append("🔄 **Khởi động Vòng Nghiên cứu Mới - Thái Lan (TL) [KẾ THỪA]**") else: # Báo cáo các task đang chạy running_tl = [t for t in tl_tasks if t[3] == 'running'] if running_tl: for t in running_tl: messages.append(f"🔄 **TL Pipeline:** `{t[1]}` đang thực thi...") # --- BÁO CÁO FILES ĐÃ XUẤT --- report_dir = os.path.join(PROJECT_BASE, 'master_reports') if os.path.exists(report_dir): files = os.listdir(report_dir) if files: messages.append("\n📁 **Master Reports hiện tại:**") for f in sorted(files): messages.append(f"- [{f}](https://vmi3427693.tail8c1aaf.ts.net/files/opt/ai-os/products/ceo/content/research/tourism_benchmarking/master_reports/{f})") conn.close() if messages: print("\n".join(messages)) else: print("[SILENT]") if __name__ == "__main__": check_and_orchestrate()