liter-llm-cli 2.7.4__py3-none-win_amd64.whl

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.
@@ -0,0 +1,3 @@
1
+ """CLI proxy package."""
2
+
3
+ __version__ = "2.7.4"
@@ -0,0 +1,4 @@
1
+ [diffend] Oversized file quarantined before diffing.
2
+ name: liter_llm_cli/bin/x86_64-pc-windows-msvc/liter-llm.exe
3
+ size: 34142720 bytes
4
+ sha256: d913ce895aa82a6e07bc4825fb5ee7eae9fd32b6c039daadbced9d9ac90b1510
liter_llm_cli/cli.py ADDED
@@ -0,0 +1,16 @@
1
+ """CLI entry point for the liter-llm proxy."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import sys
6
+
7
+ from .downloader import run
8
+
9
+
10
+ def main() -> None:
11
+ """Resolve the native binary and exec it with forwarded argv."""
12
+ sys.exit(run(sys.argv[1:]))
13
+
14
+
15
+ if __name__ == "__main__":
16
+ main()
@@ -0,0 +1,239 @@
1
+ """Resolve, download, verify, and run the native liter-llm binary.
2
+
3
+ The package is published in lockstep with the product, so its own version names
4
+ the one release it may install: a binary bundled in the wheel is used first,
5
+ otherwise exactly ``liter-llm-<version>-<triple>`` is downloaded from the
6
+ ``v<version>`` release and verified against ``SHA256SUMS-<version>.txt``. It
7
+ never resolves "latest". All diagnostics go to stderr.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import hashlib
13
+ import os
14
+ import platform
15
+ import shutil
16
+ import subprocess
17
+ import sys
18
+ import tarfile
19
+ import tempfile
20
+ import zipfile
21
+ from pathlib import Path, PurePosixPath
22
+ from urllib.error import URLError
23
+ from urllib.parse import quote, urlsplit
24
+ from urllib.request import HTTPRedirectHandler, Request, build_opener
25
+
26
+ from . import __version__
27
+
28
+ REPO = "xberg-io/liter-llm"
29
+ BIN_NAME = "liter-llm"
30
+ PKG_NAME = "liter-llm-cli"
31
+ _USER_AGENT = "liter-llm-cli-python-proxy"
32
+
33
+
34
+ def _target_triple() -> str:
35
+ system = platform.system().lower()
36
+ machine = platform.machine().lower()
37
+
38
+ if system == "windows":
39
+ if machine in {"amd64", "x86_64"}:
40
+ return "x86_64-pc-windows-msvc"
41
+ raise RuntimeError(f"unsupported Windows arch: {machine}")
42
+ if system == "linux":
43
+ if machine in {"amd64", "x86_64"}:
44
+ return "x86_64-unknown-linux-gnu"
45
+ if machine in {"aarch64", "arm64"}:
46
+ return "aarch64-unknown-linux-gnu"
47
+ raise RuntimeError(f"unsupported Linux arch: {machine}")
48
+ if system == "darwin":
49
+ if machine in {"aarch64", "arm64"}:
50
+ return "aarch64-apple-darwin"
51
+ if machine in {"amd64", "x86_64"}:
52
+ return "x86_64-apple-darwin"
53
+ raise RuntimeError(f"unsupported macOS arch: {machine}")
54
+ raise RuntimeError(f"unsupported platform: {system} {machine}")
55
+
56
+
57
+ def _binary_name() -> str:
58
+ return f"{BIN_NAME}.exe" if platform.system().lower() == "windows" else BIN_NAME
59
+
60
+
61
+ class _HttpsOnlyRedirectHandler(HTTPRedirectHandler):
62
+ """Reject any redirect whose target is not https (downgrade/SSRF guard)."""
63
+
64
+ def redirect_request(self, req, fp, code, msg, headers, newurl): # type: ignore[no-untyped-def] # noqa: PLR0917 — overrides fixed HTTPRedirectHandler signature
65
+ if urlsplit(newurl).scheme.lower() != "https":
66
+ raise URLError(f"refusing non-https redirect to: {newurl}")
67
+ return super().redirect_request(req, fp, code, msg, headers, newurl)
68
+
69
+
70
+ _opener = build_opener(_HttpsOnlyRedirectHandler())
71
+
72
+
73
+ def _http_get(url: str) -> bytes:
74
+ if urlsplit(url).scheme.lower() != "https":
75
+ raise RuntimeError(f"refusing non-https URL: {url}")
76
+ request = Request(url, headers={"User-Agent": _USER_AGENT})
77
+ try:
78
+ with _opener.open(request, timeout=60) as response:
79
+ if response.status != 200:
80
+ raise RuntimeError(f"HTTP {response.status} for {url}")
81
+ return response.read() # type: ignore[no-any-return]
82
+ except URLError as exc:
83
+ raise RuntimeError(f"failed to fetch {url}: {exc}") from exc
84
+
85
+
86
+ def archive_name(version: str, triple: str) -> str:
87
+ """Return the release archive name for ``version`` and ``triple``."""
88
+ extension = "zip" if triple.endswith("-windows-msvc") else "tar.gz"
89
+ return f"{BIN_NAME}-{version}-{triple}.{extension}"
90
+
91
+
92
+ def release_urls(version: str, triple: str) -> tuple[str, str, str]:
93
+ """Return (archive name, archive URL, checksums URL) pinned to ``v<version>``."""
94
+ base = f"https://github.com/{REPO}/releases/download/v{quote(version, safe='')}"
95
+ archive = archive_name(version, triple)
96
+ return archive, f"{base}/{archive}", f"{base}/SHA256SUMS-{version}.txt"
97
+
98
+
99
+ def _expected_digest(text: str, asset_name: str) -> str | None:
100
+ for line in text.splitlines():
101
+ stripped = line.strip()
102
+ if not stripped:
103
+ continue
104
+ parts = stripped.split()
105
+ if len(parts) < 2:
106
+ continue
107
+ name = parts[-1].lstrip("*")
108
+ if name == asset_name:
109
+ return parts[0].lower()
110
+ return None
111
+
112
+
113
+ def verify_checksum(data: bytes, asset_name: str, sums_text: str) -> None:
114
+ """Raise unless ``data`` matches the digest listed for ``asset_name``."""
115
+ expected = _expected_digest(sums_text, asset_name)
116
+ if not expected:
117
+ raise RuntimeError(f"no checksum entry for {asset_name} in SHA256SUMS — refusing to install unverified binary")
118
+ digest = hashlib.sha256(data).hexdigest().lower()
119
+ if digest != expected:
120
+ raise RuntimeError(f"checksum mismatch for {asset_name} (expected {expected}, got {digest})")
121
+
122
+
123
+ def _is_within(base: Path, target: Path) -> bool:
124
+ """True if `target`'s resolved path stays inside `base`."""
125
+ base_resolved = base.resolve()
126
+ try:
127
+ target.resolve().relative_to(base_resolved)
128
+ except ValueError:
129
+ return False
130
+ return True
131
+
132
+
133
+ def _reject_unsafe_member(name: str) -> None:
134
+ """Reject absolute paths and any `..` component (zip-slip / tar-slip)."""
135
+ normalized = name.replace("\\", "/")
136
+ pure = PurePosixPath(normalized)
137
+ if pure.is_absolute() or normalized.startswith("/"):
138
+ raise RuntimeError(f"refusing absolute path in archive: {name}")
139
+ if len(normalized) >= 2 and normalized[1] == ":":
140
+ raise RuntimeError(f"refusing absolute path in archive: {name}")
141
+ if any(part == ".." for part in pure.parts):
142
+ raise RuntimeError(f"refusing parent-directory escape in archive: {name}")
143
+
144
+
145
+ def _safe_extract(archive_path: Path, asset_name: str, dest: Path) -> None:
146
+ """Extract a tar/zip, validating every member stays within `dest`.
147
+
148
+ Does not rely on extractall() defaults or the 3.12-only ``filter='data'``:
149
+ each member name is rejected up front if it is absolute or contains ``..``,
150
+ and the resolved destination path is re-checked against ``dest``.
151
+ """
152
+ dest = dest.resolve()
153
+ dest.mkdir(parents=True, exist_ok=True)
154
+
155
+ if asset_name.lower().endswith(".zip"):
156
+ with zipfile.ZipFile(archive_path) as zf:
157
+ for member in zf.namelist():
158
+ _reject_unsafe_member(member)
159
+ if not _is_within(dest, dest / member):
160
+ raise RuntimeError(f"refusing archive entry escaping dest: {member}")
161
+ for member in zf.namelist():
162
+ zf.extract(member, dest)
163
+ else:
164
+ with tarfile.open(archive_path, "r:gz") as tf:
165
+ for tar_member in tf.getmembers():
166
+ _reject_unsafe_member(tar_member.name)
167
+ if not _is_within(dest, dest / tar_member.name):
168
+ raise RuntimeError(f"refusing archive entry escaping dest: {tar_member.name}")
169
+ if tar_member.islnk() or tar_member.issym():
170
+ link_target = dest / tar_member.name
171
+ if not _is_within(dest, link_target.parent / tar_member.linkname):
172
+ raise RuntimeError(f"refusing link escaping dest: {tar_member.name}")
173
+ tf.extractall(dest)
174
+
175
+
176
+ def _find_binary(root: Path, name: str) -> Path | None:
177
+ for candidate in root.rglob(name):
178
+ if candidate.is_file():
179
+ return candidate
180
+ return None
181
+
182
+
183
+ def _cache_dir(version: str) -> Path:
184
+ cache = Path.home() / ".cache" / PKG_NAME / version
185
+ cache.mkdir(parents=True, exist_ok=True, mode=0o700)
186
+ return cache
187
+
188
+
189
+ def bundled_binary() -> Path | None:
190
+ """Return the binary shipped inside a platform wheel, if there is one."""
191
+ candidate = Path(__file__).resolve().parent / "bin" / _target_triple() / _binary_name()
192
+ return candidate if candidate.is_file() else None
193
+
194
+
195
+ def ensure_binary() -> str:
196
+ """Ensure the native binary for this package's version exists, downloading if necessary."""
197
+ override = os.getenv("LITER_LLM_BINARY")
198
+ if override:
199
+ return override
200
+
201
+ bundled = bundled_binary()
202
+ if bundled is not None:
203
+ return str(bundled)
204
+
205
+ version = __version__
206
+ triple = _target_triple()
207
+ cache = _cache_dir(version)
208
+ binary_path = cache / _binary_name()
209
+ if binary_path.exists() and os.access(binary_path, os.X_OK):
210
+ return str(binary_path)
211
+
212
+ archive, archive_url, checksums_url = release_urls(version, triple)
213
+ print(f"Downloading {BIN_NAME} {version} asset {archive}...", file=sys.stderr)
214
+ data = _http_get(archive_url)
215
+ verify_checksum(data, archive, _http_get(checksums_url).decode("utf-8"))
216
+ print(f"Checksum verified for {archive}.", file=sys.stderr)
217
+ with tempfile.TemporaryDirectory() as tmpdir:
218
+ tmp = Path(tmpdir)
219
+ archive_path = tmp / archive
220
+ archive_path.write_bytes(data)
221
+ extract_dir = tmp / "extract"
222
+ extract_dir.mkdir()
223
+ _safe_extract(archive_path, archive, extract_dir)
224
+ found = _find_binary(extract_dir, _binary_name())
225
+ if not found:
226
+ raise RuntimeError(f"binary {_binary_name()} not found after extracting {archive}")
227
+ shutil.move(str(found), str(binary_path))
228
+
229
+ if platform.system().lower() != "windows":
230
+ binary_path.chmod(0o755)
231
+ print(f"{BIN_NAME} installed.", file=sys.stderr)
232
+ return str(binary_path)
233
+
234
+
235
+ def run(args: list[str]) -> int:
236
+ """Run the native binary with the given args, returning its exit code."""
237
+ binary_path = ensure_binary()
238
+ completed = subprocess.run([binary_path, *args], check=False)
239
+ return completed.returncode
@@ -0,0 +1,32 @@
1
+ Metadata-Version: 2.5
2
+ Name: liter-llm-cli
3
+ Version: 2.7.4
4
+ Summary: CLI proxy for liter-llm — downloads and runs the native liter-llm binary from GitHub releases.
5
+ Project-URL: Homepage, https://github.com/xberg-io/liter-llm
6
+ Project-URL: Issues, https://github.com/xberg-io/liter-llm/issues
7
+ Project-URL: Repository, https://github.com/xberg-io/liter-llm.git
8
+ Author-email: Na'aman Hirschfeld <naaman@xberg.io>, Tobias Perlstein <tobias@xberg.io>
9
+ Maintainer-email: Na'aman Hirschfeld <naaman@xberg.io>, Tobias Perlstein <tobias@xberg.io>
10
+ License: MIT
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Requires-Python: >=3.11
21
+ Description-Content-Type: text/markdown
22
+
23
+ # liter-llm-cli
24
+
25
+ CLI proxy for [`liter-llm`](https://github.com/xberg-io/liter-llm). Installing
26
+ this package provides a `liter-llm` command.
27
+
28
+ The package version always equals the `liter-llm` release it carries. Platform
29
+ wheels bundle the native binary; the source distribution instead downloads
30
+ exactly `liter-llm-<version>-<target>` from the matching `v<version>` GitHub
31
+ release and verifies it against `SHA256SUMS-<version>.txt` before running it.
32
+ Set `LITER_LLM_BINARY` to run a binary you already have.
@@ -0,0 +1,8 @@
1
+ liter_llm_cli/__init__.py,sha256=nKzQumAkzYYJj5bS4fB6zIFtDmqASZOOdwIO46P2l0s,51
2
+ liter_llm_cli/cli.py,sha256=ugJesYE0-97wl9_jj1oCNnYs7Hx_yEeTO0i05dpV24U,303
3
+ liter_llm_cli/downloader.py,sha256=kyuzGa_FFXbuS33dJNcjo0nOfuWRminBfgR6npkVXJ8,9602
4
+ liter_llm_cli/bin/x86_64-pc-windows-msvc/liter-llm.exe,sha256=2RPOiVqoKm4HvEgl-17n6un9MrbAOdqtvO2dmskLFRA,34142720
5
+ liter_llm_cli-2.7.4.dist-info/METADATA,sha256=qO4NNFSDHSHgyFSQS0fH3TVlOBIApNJojsz63er5SO0,1554
6
+ liter_llm_cli-2.7.4.dist-info/WHEEL,sha256=lpoBGaIUIidvvdZ4qRAP61bBKYJdt4FI3WXFL50Gzyo,94
7
+ liter_llm_cli-2.7.4.dist-info/entry_points.txt,sha256=X736sjXX_-9KxPEto8T6ZaMzv3Lqp2QkFu7qo9-a9zw,53
8
+ liter_llm_cli-2.7.4.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: false
4
+ Tag: py3-none-win_amd64
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ liter-llm = liter_llm_cli.cli:main