-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatch_iterm_return.py
More file actions
48 lines (40 loc) · 1.78 KB
/
Copy pathpatch_iterm_return.py
File metadata and controls
48 lines (40 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import sys, re
with open('run_rotator_monolith.py', 'r') as f:
code = f.read()
old_auth = re.search(r'def start_opencode_auth\(\):.*?return url, proc', code, re.DOTALL).group(0)
new_auth = """def start_opencode_auth():
print("[CLI] Starte 'opencode auth login' im nativen Terminal...")
import subprocess, time, os, re
subprocess.run(["rm", "-f", "/tmp/opencode_auth_m30.log"])
script = r'''
tell application "iTerm"
activate
set newWindow to (create window with default profile)
tell current session of newWindow
write text "env BROWSER=echo opencode auth logout --provider openai"
delay 2
write text "pids=\\$(lsof -ti tcp:1455 2>/dev/null); if [ -n \\"\\$pids\\" ]; then kill -9 \\$pids; fi"
delay 1
write text "rm -f /tmp/opencode_auth_m30.log"
delay 1
write text "env BROWSER=echo opencode auth login --provider openai --method 'ChatGPT Pro/Plus (browser)' | tee /tmp/opencode_auth_m30.log"
end tell
end tell
'''
subprocess.run(["osascript", "-e", script])
url = None
for _ in range(60):
time.sleep(0.5)
if os.path.exists("/tmp/opencode_auth_m30.log"):
try:
content = open("/tmp/opencode_auth_m30.log", "r").read()
m = re.search(r"(https://auth\\.openai\\.com/oauth/authorize[^\\s\\x1b]+)", content)
if m: url = m.group(1); break
except: pass
if not url: raise RuntimeError("URL aus Terminal Log nicht gefunden!")
print(f" URL generiert: {url[:60]}...")
return url, None"""
code = code.replace(old_auth, new_auth)
with open('run_rotator_monolith.py', 'w') as f:
f.write(code)
print("iTerm2 Terminal Patch wiederhergestellt!")