| 69 | |
| 70 | |
| 71 | def cache_log_tail(name: str, limit: int = 16384) -> str: |
| 72 | cache_dir = os.environ.get("CBM_CACHE_DIR") |
| 73 | if not cache_dir: |
| 74 | return "" |
| 75 | path = os.path.join(cache_dir, "logs", name) |
| 76 | try: |
| 77 | with open(path, "rb") as stream: |
| 78 | stream.seek(0, os.SEEK_END) |
| 79 | size = stream.tell() |
| 80 | stream.seek(max(0, size - limit), os.SEEK_SET) |
| 81 | return stream.read(limit).decode("utf-8", errors="replace") |
| 82 | except OSError: |
| 83 | return "" |
| 84 | |
| 85 | |
| 86 | def send(process: subprocess.Popen[bytes], message: dict[str, Any]) -> None: |