import json, copy

path = "/home/min/hermes_workspace/demo_review/ai_harness_gateway.excalidraw"
scene = json.load(open(path))
els = scene["elements"]

OFFSET_Y = 750  # English section below the Japanese one

translations = {
    "AIハーネス：エージェントを「入り口」で一元制御": "AI Harness: unify agent control at the entry point",
    "社内のAIエージェント": "Internal AI Agents",
    "・クロードコード / Cursor\n・自作エージェント（GCP / AWS）\n・社員のチャット利用\n・約20〜30個・今後増加":
        "• Claude Code / Cursor\n• Custom agents (GCP / AWS)\n• Employee chat usage\n• ~20-30 agents, growing",
    "AIハーネス（ゲートウェイ）": "AI Harness (Gateway)",
    "・認証・権限制御（誰が）\n・ポリシーチェック（何を）\n・MCP許可リスト\n・全ログ記録（何をしたか）":
        "• Auth & permission control (who)\n• Policy checks (what)\n• MCP allowlist\n• Full audit log (what was done)",
    "全通信がここを経由": "All traffic goes through here",
    "全エージェント通信": "all agent traffic",
    "ローカルLLM（GLM 等）": "Local LLM (GLM etc.)",
    "・トークン課金ゼロ": "• No token costs",
    "クラウドLLM（許可制）": "Cloud LLMs (allowlisted)",
    "・許可されたモデルのみ": "• Approved models only",
    "社内データ": "Internal data",
    "・権限ベースでアクセス": "• Permission-based access",
    "権限ベース": "permission-based",
    "許可時のみ": "only when approved",
    "キーメッセージ": "Key message",
    "出口を塞ぐのではなく\n入り口で束ねる": "Don't block the exits —\nfunnel the entry point",
    "× 直接接続は禁止（必ずハーネス経由）": "× Direct connections blocked (always via the harness)",
}

# x nudges for English string lengths (left edges)
x_nudge = {
    "t_title": 360,
    "t_harness_tag": 630,
    "t_note2": 150,
}

clones = []
for e in els:
    c = copy.deepcopy(e)
    c["id"] = e["id"] + "_en"
    c["y"] = e["y"] + OFFSET_Y
    if "points" in c:
        c["points"] = [[dx, dy + OFFSET_Y] for dx, dy in c["points"]]
    if c["type"] == "text":
        src = e.get("originalText", e.get("text", ""))
        if src in translations:
            en = translations[src]
            c["text"] = en
            c["originalText"] = en
        if e["id"] in x_nudge:
            c["x"] = x_nudge[e["id"]]
        # re-point container bindings to the cloned container ids
        if c.get("containerId"):
            c["containerId"] = c["containerId"] + "_en"
    if c.get("boundElements"):
        c["boundElements"] = [{**b, "id": b["id"] + "_en"} for b in c["boundElements"]]
    for bk in ("startBinding", "endBinding"):
        if c.get(bk) and c[bk].get("elementId"):
            c[bk] = {**c[bk], "elementId": c[bk]["elementId"] + "_en"}
    clones.append(c)

scene["elements"] = els + clones
json.dump(scene, open(path, "w"), ensure_ascii=False, indent=2)
print(f"total elements now: {len(scene['elements'])} (was {len(els)})")