kosa8-cli 0.22.1__py3-none-any.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.
kosa8_cli/__init__.py ADDED
@@ -0,0 +1,128 @@
1
+ # Copyright (c) 2026 kosa8. All rights reserved. Proprietary; see LICENSE.
2
+ """``uvx kosa8-cli …``: the kosa8 CLI without installing it.
3
+
4
+ Runs the kosa8 release this package version names, downloaded once from
5
+ https://github.com/AzmxAI/kosa8-releases, checked against that release's
6
+ checksums.txt (a mismatch, or an asset missing from it, runs nothing), and
7
+ cached under ~/.cache/kosa8/pypi/<version> (%LOCALAPPDATA%\\kosa8\\pypi on
8
+ Windows). Only the standard library; no binary in the wheel.
9
+
10
+ KOSA8_VERSION runs another release; KOSA8_PYPI_CACHE moves the cache.
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ import hashlib
16
+ import os
17
+ import platform
18
+ import shutil
19
+ import subprocess
20
+ import sys
21
+ import tarfile
22
+ import tempfile
23
+ import urllib.request
24
+ import zipfile
25
+ from typing import Dict, Optional
26
+
27
+ __version__ = "0.22.1"
28
+
29
+ RELEASES = os.environ.get("KOSA8_RELEASES_URL", "https://github.com/AzmxAI/kosa8-releases/releases/download")
30
+
31
+
32
+ def target(system: Optional[str] = None, machine: Optional[str] = None) -> Dict[str, str]:
33
+ """The release's os, arch, archive kind and executable name for a platform."""
34
+ system = (system or platform.system()).lower()
35
+ machine = (machine or platform.machine()).lower()
36
+ o = {"darwin": "darwin", "linux": "linux", "windows": "windows"}.get(system)
37
+ a = {"x86_64": "amd64", "amd64": "amd64", "arm64": "arm64", "aarch64": "arm64"}.get(machine)
38
+ if not o or not a:
39
+ raise RuntimeError(f"kosa8 has no build for {system}/{machine}; see https://kosa8.com/install")
40
+ return {"os": o, "arch": a, "ext": "tar.gz" if o == "linux" else "zip", "exe": "kosa8.exe" if o == "windows" else "kosa8"}
41
+
42
+
43
+ def asset_name(version: str, t: Dict[str, str]) -> str:
44
+ return f"kosa8_{version}_{t['os']}_{t['arch']}.{t['ext']}"
45
+
46
+
47
+ def expected_sum(checksums: str, asset: str) -> str:
48
+ """The asset's SHA-256 from checksums.txt, by exact name ("" if absent)."""
49
+ for line in checksums.splitlines():
50
+ parts = line.split()
51
+ if len(parts) >= 2 and parts[1] in (asset, "*" + asset):
52
+ return parts[0].lower()
53
+ return ""
54
+
55
+
56
+ def cache_dir(version: str) -> str:
57
+ base = os.environ.get("KOSA8_PYPI_CACHE")
58
+ if not base:
59
+ if os.name == "nt":
60
+ base = os.path.join(os.environ.get("LOCALAPPDATA") or os.path.expanduser("~\\AppData\\Local"), "kosa8", "pypi")
61
+ else:
62
+ base = os.path.join(os.environ.get("XDG_CACHE_HOME") or os.path.expanduser("~/.cache"), "kosa8", "pypi")
63
+ return os.path.join(base, version)
64
+
65
+
66
+ def _get(url: str) -> bytes:
67
+ req = urllib.request.Request(url, headers={"User-Agent": "kosa8-pypi"})
68
+ with urllib.request.urlopen(req, timeout=120) as r: # noqa: S310 (https, fixed host)
69
+ return r.read()
70
+
71
+
72
+ def ensure_binary(version: str) -> str:
73
+ """The checked kosa8 binary for version, downloaded once."""
74
+ t = target()
75
+ d = cache_dir(version)
76
+ exe = os.path.join(d, t["exe"])
77
+ if os.path.exists(exe):
78
+ return exe
79
+ asset = asset_name(version, t)
80
+ base = f"{RELEASES}/v{version}"
81
+ print(f"kosa8: downloading {asset} (once; cached in {d})", file=sys.stderr)
82
+ sums = _get(f"{base}/checksums.txt").decode("utf-8", "replace")
83
+ want = expected_sum(sums, asset)
84
+ if not want:
85
+ raise RuntimeError(f"checksums.txt has no entry for {asset}; refusing to run an unverified binary")
86
+ data = _get(f"{base}/{asset}")
87
+ got = hashlib.sha256(data).hexdigest()
88
+ if got != want:
89
+ raise RuntimeError(f"checksum mismatch for {asset} (want {want}, got {got}); refusing to run it")
90
+ os.makedirs(d, exist_ok=True)
91
+ tmp = tempfile.mkdtemp(prefix=".x-", dir=d)
92
+ try:
93
+ path = os.path.join(tmp, asset)
94
+ with open(path, "wb") as f:
95
+ f.write(data)
96
+ member = t["exe"]
97
+ if t["ext"] == "zip":
98
+ with zipfile.ZipFile(path) as z:
99
+ z.extract(member, tmp)
100
+ else:
101
+ with tarfile.open(path, "r:gz") as tf:
102
+ m = tf.getmember(member)
103
+ if not m.isfile():
104
+ raise RuntimeError(f"{asset} has no {member}")
105
+ with tf.extractfile(m) as src, open(os.path.join(tmp, member), "wb") as dst: # type: ignore[union-attr]
106
+ shutil.copyfileobj(src, dst)
107
+ out = os.path.join(tmp, member)
108
+ os.chmod(out, 0o755)
109
+ os.replace(out, exe)
110
+ finally:
111
+ shutil.rmtree(tmp, ignore_errors=True)
112
+ return exe
113
+
114
+
115
+ def main() -> None:
116
+ try:
117
+ exe = ensure_binary(os.environ.get("KOSA8_VERSION") or __version__)
118
+ except Exception as e: # noqa: BLE001 (any failure ends here, said once)
119
+ print(f"kosa8: {e}\n Install it another way: https://kosa8.com/install", file=sys.stderr)
120
+ sys.exit(1)
121
+ args = [exe, *sys.argv[1:]]
122
+ if os.name == "nt":
123
+ sys.exit(subprocess.call(args))
124
+ os.execv(exe, args)
125
+
126
+
127
+ if __name__ == "__main__":
128
+ main()
kosa8_cli/__main__.py ADDED
@@ -0,0 +1,3 @@
1
+ from . import main
2
+
3
+ main()
@@ -0,0 +1,43 @@
1
+ Metadata-Version: 2.5
2
+ Name: kosa8-cli
3
+ Version: 0.22.1
4
+ Summary: The kosa8 CLI in one command: uvx kosa8-cli init. Downloads the kosa8 release binary for this platform, checks it against the release's checksums.txt, and runs it.
5
+ Project-URL: Homepage, https://kosa8.com
6
+ Project-URL: Source, https://github.com/AzmxAI/kosa8/tree/main/packaging/pypi
7
+ License: Proprietary
8
+ Keywords: ai-agents,cli,kosa8,microvm,sandbox,serverless
9
+ Classifier: Environment :: Console
10
+ Classifier: Operating System :: MacOS
11
+ Classifier: Operating System :: Microsoft :: Windows
12
+ Classifier: Operating System :: POSIX :: Linux
13
+ Requires-Python: >=3.8
14
+ Description-Content-Type: text/markdown
15
+
16
+ # kosa8-cli (PyPI)
17
+
18
+ The kosa8 CLI as a one-shot command, for people and agents without it installed:
19
+
20
+ ```sh
21
+ uvx kosa8-cli init # sign in (free Starter, no card) and run a first command on kosa8 Cloud
22
+ uvx kosa8-cli run "echo hi" # one serverless run in a fresh microVM
23
+ uvx kosa8-cli migrate scan # what changes to move E2B, Daytona or Modal code to kosa8
24
+ uvx --from kosa8-cli kosa8 … # the same, under the command's own name
25
+ ```
26
+
27
+ (`kosa8` on PyPI is the Python SDK; this package is only the CLI.)
28
+
29
+ The wheel holds no binary. On first run it downloads the kosa8 release this package version names
30
+ (`kosa8_<version>_<os>_<arch>` from https://github.com/AzmxAI/kosa8-releases), checks its SHA-256
31
+ against that release's `checksums.txt`, refuses to run on a mismatch, and caches it
32
+ (`~/.cache/kosa8/pypi/<version>`, `%LOCALAPPDATA%\kosa8\pypi` on Windows). Standard library only.
33
+
34
+ - `KOSA8_VERSION=0.22.0 uvx kosa8-cli …` runs another release.
35
+ - `KOSA8_PYPI_CACHE` moves the cache.
36
+
37
+ For a lasting install (with the local engine and `kosa8 self-update`): https://kosa8.com/install
38
+
39
+ ## Releasing (owner only; nothing here publishes by itself)
40
+
41
+ 1. Set `version` in `pyproject.toml` and `__version__` in `kosa8_cli/__init__.py` to the CLI release, after that release is published.
42
+ 2. `python3 -m unittest discover -s tests` here.
43
+ 3. `uv build && uv publish` (or `python -m build && twine upload dist/*`) — only when the owner says "publish".
@@ -0,0 +1,6 @@
1
+ kosa8_cli/__init__.py,sha256=W7UH5qXRuvyq7A5hyWhgV-ioXNavyyNXtozDgFA9Zw8,4892
2
+ kosa8_cli/__main__.py,sha256=ubt6XyZvcHwdjCQ90B_U4MeP-3YJduz5GWUC9yOgkrg,27
3
+ kosa8_cli-0.22.1.dist-info/METADATA,sha256=YEyd5aIC2O23HdbjGPsONJ4Xy4n9K3kswqjmhNSBqD8,2125
4
+ kosa8_cli-0.22.1.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
5
+ kosa8_cli-0.22.1.dist-info/entry_points.txt,sha256=vUUd6C4-rGfv6aA3FvEomX658XipAGpLUjCEDPXRXCQ,68
6
+ kosa8_cli-0.22.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ kosa8 = kosa8_cli:main
3
+ kosa8-cli = kosa8_cli:main