From bdd7d1f57ce748c00929394c207c3d2dc9f12bda Mon Sep 17 00:00:00 2001 From: david Date: Tue, 8 Sep 2026 01:59:38 -0300 Subject: no one reads this --- colab_setup.py | 46 +++++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 25 deletions(-) (limited to 'colab_setup.py') diff --git a/colab_setup.py b/colab_setup.py index 33cc26e..42d57d9 100644 --- a/colab_setup.py +++ b/colab_setup.py @@ -1,11 +1,9 @@ #!/usr/bin/env python3 -#all of this is vibecoded but i read it and it's okay """ run this in a colab cell to stand up main.py + a public wss:// tunnel to it. session is ephemeral — restart the notebook, get a new url, re-paste it into your bot.py-side config/connection.txt. """ - import os import re import secrets @@ -56,16 +54,13 @@ def ensure_auth_token() -> str: return token -def ensure_params_and_prompt(): - # main.py needs both of these to exist — if this is a fresh colab instance - # and you haven't uploaded them yet, stop here and add them first. +def ensure_params(): + # main.py is stateless — system_prompt comes over the wire in every payload from bot.py. + # params.json is the one thing it actually reads off its own disk (ollama.chat options + # aren't sent in the payload), so that's the only file that has to exist here. params_file = CONFIG_DIR / "params.json" - prompt_file = CONFIG_DIR / "system_prompt.txt" - missing = [f.name for f in (params_file, prompt_file) if not f.exists()] - if missing: - raise SystemExit( - f"missing {', '.join(missing)} in {CONFIG_DIR} — upload them before running this" - ) + if not params_file.exists(): + raise SystemExit(f"missing params.json in {CONFIG_DIR} — upload it before running this") def start_main(): @@ -82,44 +77,45 @@ def start_tunnel() -> str: run("dpkg -i cloudflared.deb") print("\n-- opening tunnel to localhost:8765 --") - proc = subprocess.Popen( + # logging to a real file instead of a PIPE — a pipe's read end lives in this python + # process, so once this script exits the pipe's reader disappears and cloudflared + # gets SIGPIPE on its next log write and dies. a file has no reader to lose. + log_path = SCRIPT_DIR / "cloudflared.log" + log_file = open(log_path, "w") + subprocess.Popen( "cloudflared tunnel --url http://localhost:8765", shell=True, - stdout=subprocess.PIPE, + stdout=log_file, stderr=subprocess.STDOUT, - text=True, - bufsize=1, ) url = None deadline = time.time() + 30 - for line in proc.stdout: - print(line, end="") - match = re.search(r"https://[a-zA-Z0-9\-]+\.trycloudflare\.com", line) + while time.time() < deadline: + text = log_path.read_text(encoding="utf-8", errors="ignore") + match = re.search(r"https://[a-zA-Z0-9\-]+\.trycloudflare\.com", text) if match: url = match.group(0) break - if time.time() > deadline: - break + time.sleep(1) if not url: - raise SystemExit("couldn't find the tunnel url in cloudflared's output, check the log above") + raise SystemExit(f"couldn't find the tunnel url, check {log_path}") - wss_url = url.replace("https://", "wss://") - return wss_url + return url.replace("https://", "wss://") def main(): install_ollama() pull_models() install_python_deps() - ensure_params_and_prompt() + ensure_params() token = ensure_auth_token() start_main() time.sleep(3) # let main.py bind its port before the tunnel tries to reach it wss_url = start_tunnel() - print("\n" + "=" * 60) #wtf is this shit claude + print("\n" + "=" * 60) print("paste these into setup_wizard.py on the bot.py side:") print(f" address: {wss_url}") print(f" token: {token}") -- cgit v1.3-2-g0d8e