relay-codex 0.0.0-stage → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +99 -2
- package/assets/relay.svg +15 -0
- package/bin/relay.cjs +148 -0
- package/docs/commands.md +92 -0
- package/docs/publishing.md +56 -0
- package/docs/troubleshooting.md +37 -0
- package/package.json +47 -4
- package/python/Menu.swift +70 -0
- package/python/broker.py +297 -0
- package/python/commands.py +701 -0
- package/python/compatibility.py +225 -0
- package/python/desktop.py +52 -0
- package/python/launch.py +117 -0
- package/python/metadata.py +82 -0
- package/python/notifications.py +36 -0
- package/python/pool.py +579 -0
- package/python/probe_native.py +91 -0
- package/python/processes.py +12 -0
- package/python/requirements.lock +6 -0
- package/python/requirements.txt +2 -0
- package/python/router.py +2053 -0
- package/python/runtime.py +97 -0
- package/python/service.py +663 -0
- package/python/settings.py +109 -0
- package/tests/fake_native.py +238 -0
- package/tests/test_capacity.py +217 -0
- package/tests/test_controller.py +519 -0
- package/tests/test_pool.py +446 -0
- package/tests/test_relay.py +173 -0
- package/tests/test_router.py +314 -0
- package/tests/test_services.py +473 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"""Versioned native runtime snapshots; never replace the user's Codex installation."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import shutil
|
|
5
|
+
import time
|
|
6
|
+
|
|
7
|
+
import compatibility
|
|
8
|
+
from settings import atomic_json
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def index(state):
|
|
12
|
+
file = state / "runtimes.json"
|
|
13
|
+
return (
|
|
14
|
+
json.loads(file.read_text())
|
|
15
|
+
if file.exists()
|
|
16
|
+
else {"runtimes": [], "selected": None}
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def capture(binary, state):
|
|
21
|
+
verified = compatibility.check(binary, state)
|
|
22
|
+
native = compatibility.executable(binary)
|
|
23
|
+
digest = compatibility.digest(native)
|
|
24
|
+
root = state / "native-runtimes" / digest[:20]
|
|
25
|
+
target = root / "vendor" / "bin" / "codex"
|
|
26
|
+
if not target.exists():
|
|
27
|
+
root.mkdir(parents=True, exist_ok=True, mode=0o700)
|
|
28
|
+
temporary = root / "staging"
|
|
29
|
+
if temporary.exists():
|
|
30
|
+
shutil.rmtree(temporary)
|
|
31
|
+
if native.parent.name == "bin":
|
|
32
|
+
shutil.copytree(native.parent.parent, temporary)
|
|
33
|
+
else:
|
|
34
|
+
(temporary / "bin").mkdir(parents=True)
|
|
35
|
+
shutil.copy2(native, temporary / "bin" / "codex")
|
|
36
|
+
temporary.rename(root / "vendor")
|
|
37
|
+
if compatibility.digest(target) != digest:
|
|
38
|
+
raise ValueError("Cached runtime integrity check failed")
|
|
39
|
+
value = index(state)
|
|
40
|
+
if not any(row["sha256"] == digest for row in value["runtimes"]):
|
|
41
|
+
value["runtimes"].append(
|
|
42
|
+
{
|
|
43
|
+
"version": verified["version"],
|
|
44
|
+
"sha256": digest,
|
|
45
|
+
"binary": str(target),
|
|
46
|
+
"captured": time.time(),
|
|
47
|
+
}
|
|
48
|
+
)
|
|
49
|
+
atomic_json(state / "runtimes.json", value)
|
|
50
|
+
return str(target), verified
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def select(binary, state):
|
|
54
|
+
value = index(state)
|
|
55
|
+
if value.get("selected"):
|
|
56
|
+
choices = [r for r in value["runtimes"] if r["sha256"] == value["selected"]]
|
|
57
|
+
if not choices:
|
|
58
|
+
raise ValueError("Selected runtime snapshot is missing")
|
|
59
|
+
selected = choices[0]
|
|
60
|
+
if compatibility.digest(selected["binary"]) != selected["sha256"]:
|
|
61
|
+
raise ValueError("Selected runtime snapshot was modified")
|
|
62
|
+
return (
|
|
63
|
+
selected["binary"],
|
|
64
|
+
compatibility.check(selected["binary"], state),
|
|
65
|
+
"selected_snapshot",
|
|
66
|
+
)
|
|
67
|
+
try:
|
|
68
|
+
path, verified = capture(binary, state)
|
|
69
|
+
return path, verified, "installed_snapshot"
|
|
70
|
+
except Exception as error:
|
|
71
|
+
for row in reversed(value["runtimes"]):
|
|
72
|
+
try:
|
|
73
|
+
if compatibility.digest(row["binary"]) != row["sha256"]:
|
|
74
|
+
continue
|
|
75
|
+
verified = compatibility.check(row["binary"], state)
|
|
76
|
+
return row["binary"], verified, "compatible_fallback"
|
|
77
|
+
except Exception:
|
|
78
|
+
continue
|
|
79
|
+
raise error
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def choose(state, prefix=None):
|
|
83
|
+
value = index(state)
|
|
84
|
+
if prefix in (None, "latest", "installed"):
|
|
85
|
+
value["selected"] = None
|
|
86
|
+
else:
|
|
87
|
+
matching = [
|
|
88
|
+
row
|
|
89
|
+
for row in value["runtimes"]
|
|
90
|
+
if row["sha256"].startswith(prefix) or row["version"] == prefix
|
|
91
|
+
]
|
|
92
|
+
if len(matching) != 1:
|
|
93
|
+
raise ValueError(
|
|
94
|
+
"Choose a unique runtime hash or version from runtime list"
|
|
95
|
+
)
|
|
96
|
+
value["selected"] = matching[0]["sha256"]
|
|
97
|
+
atomic_json(state / "runtimes.json", value)
|