#!/usr/bin/env python3 """Patch iishko gates for minara-pool models (line-based, no escape games).""" import json, py_compile, shutil, time MODELS = json.load(open("/root/minara_models.json", encoding="utf-8")) ts = time.strftime("%Y%m%d-%H%M%S") TAG = " # [MINARA 1106]" line_sso = "MODELS += [m for m in " + repr(MODELS) + " if m not in MODELS]" + TAG line_rank = " models += [m for m in " + repr(MODELS) + " if m not in models]" + TAG line_tool = "ALLOW += [m for m in " + repr(MODELS) + " if m not in ALLOW]" + TAG def insert_after(path, anchor, newline): lines = open(path, encoding="utf-8").read().split("\n") if any("MINARA 1106" in l for l in lines): return "already" idx = [i for i, l in enumerate(lines) if anchor in l] if not idx: return "anchor-missing" shutil.copy2(path, path + ".bak-minara-" + ts) out = lines[:idx[0] + 1] + [newline] + lines[idx[0] + 1:] open(path, "w", encoding="utf-8").write("\n".join(out)) py_compile.compile(path, doraise=True) return "patched" def insert_before(path, anchor, newline): lines = open(path, encoding="utf-8").read().split("\n") if any("MINARA 1106" in l for l in lines): return "already" idx = [i for i, l in enumerate(lines) if anchor in l] if not idx: return "anchor-missing" shutil.copy2(path, path + ".bak-minara-" + ts) out = lines[:idx[0]] + [newline] + lines[idx[0]:] open(path, "w", encoding="utf-8").write("\n".join(out)) py_compile.compile(path, doraise=True) return "patched" def append_line(path, newline): lines = open(path, encoding="utf-8").read().split("\n") if any("MINARA 1106" in l for l in lines): return "already" shutil.copy2(path, path + ".bak-minara-" + ts) out = lines + [newline, ""] open(path, "w", encoding="utf-8").write("\n".join(out)) py_compile.compile(path, doraise=True) return "patched" print("sso_limits:", insert_before("/root/sso_limits.py", "parts = [x.strip()", line_sso)) print("legacy:", insert_after("/opt/grok-bot/iishko/legacy.py", "models += IMG_MODELS + IMG_ALWAYS + DISC_MODELS + WUS_MODELS", line_rank)) print("toolgate:", append_line("/root/toolgate.py", line_tool)) for p in ("/root/sso_limits.py", "/opt/grok-bot/iishko/legacy.py", "/root/toolgate.py"): n = sum(1 for l in open(p, encoding="utf-8") if "MINARA 1106" in l) print(p, "markers:", n)