sarvam-cli-app 1.17.13__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.
sarvam_cli/__init__.py ADDED
@@ -0,0 +1,7 @@
1
+ """Thin pip wrapper for the Sarvam CLI native binary.
2
+
3
+ The real product is the platform-native binary published to GitHub Releases;
4
+ this package downloads it on first run and launches it.
5
+ """
6
+
7
+ __version__ = "1.17.13"
sarvam_cli/__main__.py ADDED
@@ -0,0 +1,4 @@
1
+ from .cli import main
2
+
3
+ if __name__ == "__main__":
4
+ main()
sarvam_cli/cli.py ADDED
@@ -0,0 +1,30 @@
1
+ """Entry point: ensure the native binary is present, then hand over to it."""
2
+
3
+ import os
4
+ import signal
5
+ import subprocess
6
+ import sys
7
+
8
+ from .download import DownloadError, ensure_binary
9
+
10
+
11
+ def main():
12
+ try:
13
+ binary = ensure_binary()
14
+ except DownloadError as err:
15
+ print("sarvam-cli: {}".format(err), file=sys.stderr)
16
+ sys.exit(1)
17
+
18
+ args = [binary] + sys.argv[1:]
19
+ if os.name == "posix":
20
+ # Replace this process so signals, exit codes, and TTY behavior all
21
+ # belong to the native binary.
22
+ os.execv(binary, args)
23
+ # Windows: no execv semantics — relay via subprocess. Ignore Ctrl+C in the
24
+ # parent so the child owns interrupt handling.
25
+ signal.signal(signal.SIGINT, signal.SIG_IGN)
26
+ sys.exit(subprocess.run(args).returncode)
27
+
28
+
29
+ if __name__ == "__main__":
30
+ main()
sarvam_cli/download.py ADDED
@@ -0,0 +1,214 @@
1
+ """Fetch the platform-native Sarvam CLI binary from GitHub Releases.
2
+
3
+ Python port of npm/install.mjs. Asset names and the release layout are fixed
4
+ by .github/workflows/release.yml, so the candidate scheme here must match it:
5
+ opencode-{platform}-{arch}{variant}{libc}{ext}.
6
+
7
+ Unlike the npm wrapper (which writes into the package dir at postinstall),
8
+ the binary is cached in a user-writable directory because site-packages may
9
+ be root-owned.
10
+ """
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 urllib.error
21
+ import urllib.request
22
+ import zipfile
23
+
24
+ from . import __version__
25
+
26
+ REPO = "prashlkam/Sarvam-CLI"
27
+ SUPPORTED = {"linux-x64", "linux-arm64", "darwin-x64", "darwin-arm64", "windows-x64"}
28
+
29
+
30
+ class DownloadError(Exception):
31
+ pass
32
+
33
+
34
+ def _os_name():
35
+ if sys.platform.startswith("linux"):
36
+ return "linux"
37
+ if sys.platform == "darwin":
38
+ return "darwin"
39
+ if sys.platform in ("win32", "cygwin"):
40
+ return "windows"
41
+ return sys.platform
42
+
43
+
44
+ def _arch():
45
+ machine = platform.machine().lower()
46
+ if machine in ("x86_64", "amd64"):
47
+ return "x64"
48
+ if machine in ("aarch64", "arm64"):
49
+ return "arm64"
50
+ return machine
51
+
52
+
53
+ def _is_musl():
54
+ if _os_name() != "linux":
55
+ return False
56
+ if os.path.exists("/etc/alpine-release"):
57
+ return True
58
+ try:
59
+ proc = subprocess.run(
60
+ ["ldd", "--version"],
61
+ stdout=subprocess.PIPE,
62
+ stderr=subprocess.STDOUT,
63
+ text=True,
64
+ )
65
+ return "musl" in proc.stdout.lower()
66
+ except OSError:
67
+ return False
68
+
69
+
70
+ def _binary_name():
71
+ return "sarvam-cli.exe" if _os_name() == "windows" else "sarvam-cli"
72
+
73
+
74
+ def _cache_dir():
75
+ if _os_name() == "windows":
76
+ base = os.environ.get("LOCALAPPDATA") or os.path.expanduser("~\\AppData\\Local")
77
+ else:
78
+ base = os.environ.get("XDG_CACHE_HOME") or os.path.expanduser("~/.cache")
79
+ return os.path.join(base, "sarvam-cli")
80
+
81
+
82
+ def _candidates(os_name, arch):
83
+ ext = ".tar.gz" if os_name == "linux" else ".zip"
84
+ variants = ["", "-baseline"] if arch == "x64" else [""]
85
+ libcs = ["-musl"] if os_name == "linux" and _is_musl() else [""]
86
+ return [
87
+ "opencode-{}-{}{}{}{}".format(os_name, arch, variant, libc, ext)
88
+ for libc in libcs
89
+ for variant in variants
90
+ ]
91
+
92
+
93
+ def _fetch_checksums():
94
+ """Return {asset_name: sha256} from the release's checksums.txt, or {} if unavailable."""
95
+ url = "https://github.com/{}/releases/download/v{}/checksums.txt".format(REPO, __version__)
96
+ try:
97
+ with urllib.request.urlopen(url, timeout=30) as res:
98
+ text = res.read().decode("utf-8", "replace")
99
+ except (urllib.error.URLError, OSError):
100
+ return {}
101
+ sums = {}
102
+ for line in text.splitlines():
103
+ parts = line.split()
104
+ if len(parts) == 2:
105
+ sums[parts[1]] = parts[0]
106
+ return sums
107
+
108
+
109
+ def _extract_binary(archive_path, tmp_dir):
110
+ """Extract the archive into tmp_dir and return the path to the binary, or None."""
111
+ if archive_path.endswith(".tar.gz"):
112
+ with tarfile.open(archive_path, "r:gz") as tf:
113
+ try:
114
+ tf.extractall(tmp_dir, filter="data")
115
+ except TypeError: # Python < 3.12: no filter= kwarg
116
+ tf.extractall(tmp_dir)
117
+ else:
118
+ with zipfile.ZipFile(archive_path) as zf:
119
+ zf.extractall(tmp_dir)
120
+ binary = _binary_name()
121
+ for root, _dirs, files in os.walk(tmp_dir):
122
+ if binary in files:
123
+ return os.path.join(root, binary)
124
+ return None
125
+
126
+
127
+ def _try_download(asset, dest, checksums):
128
+ url = "https://github.com/{}/releases/download/v{}/{}".format(REPO, __version__, asset)
129
+ tmp_dir = tempfile.mkdtemp(prefix="sarvam-cli-")
130
+ try:
131
+ archive_path = os.path.join(tmp_dir, asset)
132
+ try:
133
+ with urllib.request.urlopen(url, timeout=60) as res, open(archive_path, "wb") as out:
134
+ shutil.copyfileobj(res, out)
135
+ except (urllib.error.URLError, OSError):
136
+ return False
137
+
138
+ expected = checksums.get(asset)
139
+ if expected:
140
+ digest = hashlib.sha256()
141
+ with open(archive_path, "rb") as f:
142
+ for chunk in iter(lambda: f.read(1 << 20), b""):
143
+ digest.update(chunk)
144
+ if digest.hexdigest() != expected:
145
+ print("sarvam-cli: checksum mismatch for {}, skipping".format(asset), file=sys.stderr)
146
+ return False
147
+
148
+ found = _extract_binary(archive_path, tmp_dir)
149
+ if not found:
150
+ return False
151
+
152
+ dest_dir = os.path.dirname(dest)
153
+ os.makedirs(dest_dir, exist_ok=True)
154
+ # Stage next to the destination so os.replace() is atomic (same filesystem),
155
+ # which keeps concurrent first-runs from seeing a half-written binary.
156
+ fd, staged = tempfile.mkstemp(prefix=".sarvam-cli-", dir=dest_dir)
157
+ os.close(fd)
158
+ shutil.move(found, staged)
159
+ if _os_name() != "windows":
160
+ os.chmod(staged, 0o755)
161
+ os.replace(staged, dest)
162
+ return True
163
+ finally:
164
+ shutil.rmtree(tmp_dir, ignore_errors=True)
165
+
166
+
167
+ def _cleanup_old_versions(cache_root, current):
168
+ try:
169
+ entries = os.listdir(cache_root)
170
+ except OSError:
171
+ return
172
+ for entry in entries:
173
+ if entry.startswith("v") and entry != current:
174
+ shutil.rmtree(os.path.join(cache_root, entry), ignore_errors=True)
175
+
176
+
177
+ def ensure_binary():
178
+ """Return the path to the native binary, downloading it on first run."""
179
+ override = os.environ.get("SARVAM_CLI_BINARY")
180
+ if override:
181
+ if not os.path.exists(override):
182
+ raise DownloadError("SARVAM_CLI_BINARY points to a missing file: {}".format(override))
183
+ return override
184
+
185
+ cache_root = _cache_dir()
186
+ version_dir = "v{}".format(__version__)
187
+ dest = os.path.join(cache_root, version_dir, _binary_name())
188
+ if os.path.exists(dest):
189
+ return dest
190
+
191
+ os_name, arch = _os_name(), _arch()
192
+ if "{}-{}".format(os_name, arch) not in SUPPORTED:
193
+ raise DownloadError(
194
+ "unsupported platform {}-{}. "
195
+ "See https://github.com/{}/releases".format(os_name, arch, REPO)
196
+ )
197
+
198
+ print(
199
+ "sarvam-cli: downloading native binary v{} (first run only)...".format(__version__),
200
+ file=sys.stderr,
201
+ )
202
+ checksums = _fetch_checksums()
203
+ for asset in _candidates(os_name, arch):
204
+ if _try_download(asset, dest, checksums):
205
+ _cleanup_old_versions(cache_root, version_dir)
206
+ return dest
207
+
208
+ raise DownloadError(
209
+ "could not download a binary for {}-{} (v{}). "
210
+ "Check your network (HTTPS_PROXY is honored), or download manually from "
211
+ "https://github.com/{}/releases and point SARVAM_CLI_BINARY at it.".format(
212
+ os_name, arch, __version__, REPO
213
+ )
214
+ )
@@ -0,0 +1,60 @@
1
+ Metadata-Version: 2.4
2
+ Name: sarvam-cli-app
3
+ Version: 1.17.13
4
+ Summary: Sarvam CLI — an AI coding agent for the terminal, powered by Sarvam AI. A fork of opencode.
5
+ Project-URL: Homepage, https://github.com/prashlkam/Sarvam-CLI
6
+ Project-URL: Repository, https://github.com/prashlkam/Sarvam-CLI
7
+ Project-URL: Issues, https://github.com/prashlkam/Sarvam-CLI/issues
8
+ Author: Prashanth Kamath
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: ai,cli,coding-assistant,opencode,sarvam
12
+ Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Operating System :: MacOS
15
+ Classifier: Operating System :: Microsoft :: Windows
16
+ Classifier: Operating System :: POSIX :: Linux
17
+ Classifier: Programming Language :: Python :: 3
18
+ Requires-Python: >=3.9
19
+ Description-Content-Type: text/markdown
20
+
21
+ # Sarvam CLI (pip wrapper)
22
+
23
+ Sarvam CLI — an AI coding agent for the terminal, powered by Sarvam AI. A fork
24
+ of [opencode](https://github.com/sst/opencode).
25
+
26
+ This package is a thin launcher: the first time you run `sarvam-cli` it
27
+ downloads the platform-native binary (~55 MB) for your OS/architecture from
28
+ the matching [GitHub Release](https://github.com/prashlkam/Sarvam-CLI/releases)
29
+ and caches it under `~/.cache/sarvam-cli` (or `%LOCALAPPDATA%\sarvam-cli` on
30
+ Windows). Subsequent runs start instantly.
31
+
32
+ ## Install
33
+
34
+ ```bash
35
+ # pipx (recommended — this is an application, not a library)
36
+ pipx install sarvam-cli-app
37
+
38
+ # or plain pip
39
+ pip install sarvam-cli-app
40
+ ```
41
+
42
+ Both the `sarvam-cli` and `sarvam` commands are installed.
43
+
44
+ > **Note:** the npm package (`npm install -g sarvam-cli`) is an equivalent
45
+ > wrapper over the same binary — install one or the other, not both.
46
+
47
+ ## Usage
48
+
49
+ ```bash
50
+ sarvam-cli # start the agent in the current directory
51
+ sarvam-cli --version
52
+ ```
53
+
54
+ - Supported platforms: linux-x64, linux-arm64 (glibc and musl), darwin-x64,
55
+ darwin-arm64, windows-x64.
56
+ - Set `SARVAM_CLI_BINARY=/path/to/sarvam-cli` to skip the download and use your
57
+ own binary (air-gapped installs, local builds).
58
+ - Corporate proxy? The standard `HTTPS_PROXY` environment variable is honored.
59
+
60
+ Project home: https://github.com/prashlkam/Sarvam-CLI
@@ -0,0 +1,9 @@
1
+ sarvam_cli/__init__.py,sha256=SRnJOuKTbIeTVQjwCp-wpUo1ShMKzLp0Xuh39n3qSUo,217
2
+ sarvam_cli/__main__.py,sha256=MSmt_5Xg84uHqzTN38JwgseJK8rsJn_11A8WD99VtEo,61
3
+ sarvam_cli/cli.py,sha256=84_TkfPUM0wAy9goLrCRBID3V3yCbwO-LOqSZ2Ti1yM,830
4
+ sarvam_cli/download.py,sha256=gxV0YXSvwB9pel_OEqp5I4rkRtb6TkjXCr_2m_iBFLk,6923
5
+ sarvam_cli_app-1.17.13.dist-info/METADATA,sha256=OuFvNMuCMSuVWCmTG_v5avicKAK_mHs88u1iyErLAd8,2160
6
+ sarvam_cli_app-1.17.13.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
7
+ sarvam_cli_app-1.17.13.dist-info/entry_points.txt,sha256=YjprpZ-AOAHxLn7oUfrNQ8J_FVdTPhuDwLQEfPYvVRc,80
8
+ sarvam_cli_app-1.17.13.dist-info/licenses/LICENSE,sha256=Yl8PYZEz-Ju7sqvjc2lhPfoYheuh5Q0CFw3rYrtCy2s,1065
9
+ sarvam_cli_app-1.17.13.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.30.1
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ sarvam = sarvam_cli.cli:main
3
+ sarvam-cli = sarvam_cli.cli:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 opencode
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.