tamcoder 0.1.50__tar.gz → 0.1.90__tar.gz
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.
Potentially problematic release.
This version of tamcoder might be problematic. Click here for more details.
- {tamcoder-0.1.50 → tamcoder-0.1.90}/PKG-INFO +1 -1
- {tamcoder-0.1.50 → tamcoder-0.1.90}/pyproject.toml +3 -6
- tamcoder-0.1.90/src/tamcoder/__init__.py +3 -0
- tamcoder-0.1.90/src/tamcoder/__main__.py +226 -0
- tamcoder-0.1.90/tests/test_shim.py +55 -0
- {tamcoder-0.1.50 → tamcoder-0.1.90}/LICENSE +0 -0
- {tamcoder-0.1.50 → tamcoder-0.1.90}/README.md +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: tamcoder
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.90
|
|
4
4
|
Summary: Tamcoder — TypeScript coding agent runtime (PyPI shim that installs the official Linux x86_64 release)
|
|
5
5
|
Project-URL: Homepage, https://gpt.tamfitronics.com/tamcoder
|
|
6
6
|
Project-URL: Repository, https://gpt.tamfitronics.com/tamcoder
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "tamcoder"
|
|
7
|
-
version = "0.1.
|
|
7
|
+
version = "0.1.90"
|
|
8
8
|
description = "Tamcoder — TypeScript coding agent runtime (PyPI shim that installs the official Linux x86_64 release)"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = {text = "MIT"}
|
|
@@ -48,11 +48,8 @@ dev = [
|
|
|
48
48
|
]
|
|
49
49
|
|
|
50
50
|
[tool.hatch.build.targets.sdist]
|
|
51
|
-
include
|
|
52
|
-
|
|
53
|
-
"/README.md",
|
|
54
|
-
"/LICENSE",
|
|
55
|
-
]
|
|
51
|
+
# Use default selection; Hatch will include the "src/tamcoder" package.
|
|
52
|
+
# Explicit configuration removed to avoid shipping the empty top-level "tamcoder/" dir.
|
|
56
53
|
|
|
57
54
|
[tool.hatch.build.targets.wheel]
|
|
58
55
|
packages = ["src/tamcoder"]
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Tamcoder PyPI shim entry point — downloads and installs the official TypeScript release."""
|
|
3
|
+
|
|
4
|
+
import json
|
|
5
|
+
import os
|
|
6
|
+
import hashlib
|
|
7
|
+
import shutil
|
|
8
|
+
import subprocess
|
|
9
|
+
import sys
|
|
10
|
+
import tempfile
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
from urllib.parse import urljoin
|
|
13
|
+
|
|
14
|
+
try:
|
|
15
|
+
import requests
|
|
16
|
+
from tqdm import tqdm
|
|
17
|
+
except ImportError as e:
|
|
18
|
+
print(f"Missing dependency: {e}", file=sys.stderr)
|
|
19
|
+
print("Run: pip install requests tqdm", file=sys.stderr)
|
|
20
|
+
sys.exit(1)
|
|
21
|
+
|
|
22
|
+
RELEASE_BASE = os.environ.get("TAMCODER_RELEASE_BASE", "https://gpt.tamfitronics.com/tamcoder")
|
|
23
|
+
INSTALL_PREFIX = Path(os.environ.get("TAMCODER_INSTALL_PREFIX", Path.home() / ".local"))
|
|
24
|
+
ARTIFACT_ROOT = Path("/mnt/tamcoder/users")
|
|
25
|
+
ARTIFACT_BASE = ARTIFACT_ROOT.parent
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def fetch_latest() -> dict:
|
|
29
|
+
"""Fetch latest.json from the release server."""
|
|
30
|
+
url = urljoin(RELEASE_BASE.rstrip("/") + "/", "latest.json")
|
|
31
|
+
resp = requests.get(url, headers={"Cache-Control": "no-cache"}, timeout=30)
|
|
32
|
+
resp.raise_for_status()
|
|
33
|
+
return resp.json()
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def download_file(url: str, dest: Path, desc: str = "Downloading") -> None:
|
|
37
|
+
"""Download a file with progress bar."""
|
|
38
|
+
resp = requests.get(url, stream=True, timeout=60)
|
|
39
|
+
resp.raise_for_status()
|
|
40
|
+
total = int(resp.headers.get("content-length", 0))
|
|
41
|
+
with open(dest, "wb") as f, tqdm(
|
|
42
|
+
total=total, unit="B", unit_scale=True, unit_divisor=1024, desc=desc
|
|
43
|
+
) as pbar:
|
|
44
|
+
for chunk in resp.iter_content(chunk_size=8192):
|
|
45
|
+
if chunk:
|
|
46
|
+
f.write(chunk)
|
|
47
|
+
pbar.update(len(chunk))
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def verify_sha256(filepath: Path, expected: str) -> bool:
|
|
51
|
+
"""Verify SHA-256 checksum."""
|
|
52
|
+
sha256 = hashlib.sha256()
|
|
53
|
+
with open(filepath, "rb") as f:
|
|
54
|
+
for chunk in iter(lambda: f.read(8192), b""):
|
|
55
|
+
sha256.update(chunk)
|
|
56
|
+
actual = sha256.hexdigest()
|
|
57
|
+
return actual == expected
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def ensure_artifact_directory(directory: Path, mode: int) -> None:
|
|
61
|
+
"""Create directory with sticky permissions, using sudo if needed."""
|
|
62
|
+
if directory.exists():
|
|
63
|
+
return
|
|
64
|
+
try:
|
|
65
|
+
directory.mkdir(mode=mode, parents=True, exist_ok=True)
|
|
66
|
+
return
|
|
67
|
+
except PermissionError:
|
|
68
|
+
pass
|
|
69
|
+
# Try with sudo
|
|
70
|
+
try:
|
|
71
|
+
subprocess.run(["sudo", "install", "-d", "-m", str(mode), str(directory)], check=True)
|
|
72
|
+
return
|
|
73
|
+
except (subprocess.CalledProcessError, FileNotFoundError):
|
|
74
|
+
pass
|
|
75
|
+
print(f"Cannot create {directory}; need permission to provision {ARTIFACT_BASE} and {ARTIFACT_ROOT}",
|
|
76
|
+
file=sys.stderr)
|
|
77
|
+
sys.exit(1)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def ensure_sticky_mode(path: Path) -> None:
|
|
81
|
+
"""Ensure directory has sticky bit (1777)."""
|
|
82
|
+
try:
|
|
83
|
+
path.chmod(0o1777)
|
|
84
|
+
return
|
|
85
|
+
except PermissionError:
|
|
86
|
+
pass
|
|
87
|
+
try:
|
|
88
|
+
subprocess.run(["sudo", "chmod", "1777", str(path)], check=True)
|
|
89
|
+
return
|
|
90
|
+
except (subprocess.CalledProcessError, FileNotFoundError):
|
|
91
|
+
pass
|
|
92
|
+
print(f"Cannot configure {path} as shared sticky directory; run 'sudo chmod 1777 {path}'",
|
|
93
|
+
file=sys.stderr)
|
|
94
|
+
sys.exit(1)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def check_node() -> None:
|
|
98
|
+
"""Verify Node.js 22+ is available at /usr/bin/node."""
|
|
99
|
+
node_path = Path("/usr/bin/node")
|
|
100
|
+
if not node_path.exists():
|
|
101
|
+
print("Node.js 22 or newer is required at /usr/bin/node", file=sys.stderr)
|
|
102
|
+
sys.exit(1)
|
|
103
|
+
try:
|
|
104
|
+
result = subprocess.run([str(node_path), "--version"], capture_output=True, text=True, check=True)
|
|
105
|
+
version_str = result.stdout.strip().lstrip("v")
|
|
106
|
+
major = int(version_str.split(".")[0])
|
|
107
|
+
if major < 22:
|
|
108
|
+
print(f"Node.js 22 or newer is required (found {major})", file=sys.stderr)
|
|
109
|
+
sys.exit(1)
|
|
110
|
+
except (subprocess.CalledProcessError, ValueError, IndexError):
|
|
111
|
+
print("Could not determine Node.js version", file=sys.stderr)
|
|
112
|
+
sys.exit(1)
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def install_release(version: str, asset_name: str) -> Path:
|
|
116
|
+
"""Download, verify, and install a specific release."""
|
|
117
|
+
asset_url = urljoin(RELEASE_BASE.rstrip("/") + "/", f"releases/{asset_name}")
|
|
118
|
+
sha256_url = urljoin(RELEASE_BASE.rstrip("/") + "/", f"releases/{asset_name}.sha256")
|
|
119
|
+
|
|
120
|
+
with tempfile.TemporaryDirectory() as tmpdir:
|
|
121
|
+
tmp = Path(tmpdir)
|
|
122
|
+
asset_path = tmp / asset_name
|
|
123
|
+
sha256_path = tmp / f"{asset_name}.sha256"
|
|
124
|
+
|
|
125
|
+
print(f"Downloading {asset_name}...")
|
|
126
|
+
download_file(asset_url, asset_path, desc=asset_name)
|
|
127
|
+
download_file(sha256_url, sha256_path, desc="checksum")
|
|
128
|
+
|
|
129
|
+
expected_sha256 = sha256_path.read_text().strip().split()[0]
|
|
130
|
+
print(f"Verifying SHA-256...")
|
|
131
|
+
if not verify_sha256(asset_path, expected_sha256):
|
|
132
|
+
print("Checksum mismatch!", file=sys.stderr)
|
|
133
|
+
sys.exit(1)
|
|
134
|
+
|
|
135
|
+
release_dir = INSTALL_PREFIX / "share" / "tamcoder" / "releases" / version
|
|
136
|
+
release_dir.mkdir(parents=True, exist_ok=True)
|
|
137
|
+
|
|
138
|
+
print(f"Extracting to {release_dir}...")
|
|
139
|
+
shutil.unpack_archive(asset_path, release_dir)
|
|
140
|
+
|
|
141
|
+
# Verify entrypoints
|
|
142
|
+
bin_path = release_dir / "app" / "bin" / "tamcoder"
|
|
143
|
+
main_path = release_dir / "app" / "dist" / "appServerMain.js"
|
|
144
|
+
if not bin_path.exists() or not bin_path.is_file():
|
|
145
|
+
print(f"Missing entrypoint: {bin_path}", file=sys.stderr)
|
|
146
|
+
sys.exit(1)
|
|
147
|
+
if not main_path.exists():
|
|
148
|
+
print(f"Missing server: {main_path}", file=sys.stderr)
|
|
149
|
+
sys.exit(1)
|
|
150
|
+
|
|
151
|
+
# Symlinks
|
|
152
|
+
bin_dir = INSTALL_PREFIX / "bin"
|
|
153
|
+
bin_dir.mkdir(parents=True, exist_ok=True)
|
|
154
|
+
for name in ("tamcoder", "tamcoder-bin"):
|
|
155
|
+
link = bin_dir / name
|
|
156
|
+
link.unlink(missing_ok=True)
|
|
157
|
+
link.symlink_to(bin_path)
|
|
158
|
+
|
|
159
|
+
# Artifact directories
|
|
160
|
+
ensure_artifact_directory(ARTIFACT_BASE, 0o755)
|
|
161
|
+
ensure_artifact_directory(ARTIFACT_ROOT, 0o1777)
|
|
162
|
+
ensure_sticky_mode(ARTIFACT_ROOT)
|
|
163
|
+
|
|
164
|
+
if not os.access(ARTIFACT_ROOT, os.W_OK):
|
|
165
|
+
print(f"{ARTIFACT_ROOT} is not writable; run 'sudo chmod 1777 {ARTIFACT_ROOT}'", file=sys.stderr)
|
|
166
|
+
sys.exit(1)
|
|
167
|
+
|
|
168
|
+
return release_dir
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def main() -> int:
|
|
172
|
+
"""Main entry point."""
|
|
173
|
+
# Handle update check flag
|
|
174
|
+
if os.environ.get("TAMCODER_UPDATE_CHECK") == "0":
|
|
175
|
+
pass # skip update check
|
|
176
|
+
|
|
177
|
+
# If called with --version, show PyPI shim version
|
|
178
|
+
if len(sys.argv) > 1 and sys.argv[1] in ("--version", "-V"):
|
|
179
|
+
from tamcoder import __version__
|
|
180
|
+
print(f"tamcoder (PyPI shim) {__version__}")
|
|
181
|
+
return 0
|
|
182
|
+
|
|
183
|
+
# If called with update, just re-run installation
|
|
184
|
+
if len(sys.argv) > 1 and sys.argv[1] == "update":
|
|
185
|
+
print("Checking for updates...")
|
|
186
|
+
# Falls through to normal install
|
|
187
|
+
|
|
188
|
+
check_node()
|
|
189
|
+
|
|
190
|
+
print("Fetching latest release info...")
|
|
191
|
+
latest = fetch_latest()
|
|
192
|
+
version = latest.get("version")
|
|
193
|
+
asset = latest.get("asset")
|
|
194
|
+
if not version or not asset:
|
|
195
|
+
print("Invalid release metadata", file=sys.stderr)
|
|
196
|
+
sys.exit(1)
|
|
197
|
+
|
|
198
|
+
release_dir = INSTALL_PREFIX / "share" / "tamcoder" / "releases" / version
|
|
199
|
+
if release_dir.exists() and (release_dir / "app" / "bin" / "tamcoder").exists():
|
|
200
|
+
# Already installed, just verify symlinks
|
|
201
|
+
bin_dir = INSTALL_PREFIX / "bin"
|
|
202
|
+
for name in ("tamcoder", "tamcoder-bin"):
|
|
203
|
+
link = bin_dir / name
|
|
204
|
+
target = release_dir / "app" / "bin" / "tamcoder"
|
|
205
|
+
if link.exists() and not link.is_symlink():
|
|
206
|
+
link.unlink()
|
|
207
|
+
link.unlink(missing_ok=True)
|
|
208
|
+
link.symlink_to(target)
|
|
209
|
+
print(f"Tamcoder {version} already installed at {bin_dir}/tamcoder")
|
|
210
|
+
else:
|
|
211
|
+
print(f"Installing Tamcoder {version}...")
|
|
212
|
+
install_release(version, asset)
|
|
213
|
+
print(f"Installed Tamcoder {version} to {INSTALL_PREFIX}/bin/tamcoder")
|
|
214
|
+
print(f"User artifacts will be stored under {ARTIFACT_ROOT}/<user-id-hash>")
|
|
215
|
+
|
|
216
|
+
# If invoked as tamcoder (not tamcoder-bin), forward to the real binary
|
|
217
|
+
if sys.argv[0].endswith("tamcoder") and not sys.argv[0].endswith("tamcoder-bin"):
|
|
218
|
+
real_bin = INSTALL_PREFIX / "bin" / "tamcoder"
|
|
219
|
+
if real_bin.exists():
|
|
220
|
+
os.execv(str(real_bin), [str(real_bin)] + sys.argv[1:])
|
|
221
|
+
|
|
222
|
+
return 0
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
if __name__ == "__main__":
|
|
226
|
+
sys.exit(main())
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"""Unit tests for the Tamcoder PyPI shim."""
|
|
2
|
+
|
|
3
|
+
import hashlib
|
|
4
|
+
import json
|
|
5
|
+
import os
|
|
6
|
+
import tempfile
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from unittest import mock
|
|
9
|
+
|
|
10
|
+
import pytest
|
|
11
|
+
|
|
12
|
+
from tamcoder.__main__ import verify_sha256, fetch_latest, install_release
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def make_test_archive(tmp_path: Path) -> Path:
|
|
16
|
+
"""Create a fake tamcoder tarball."""
|
|
17
|
+
app_dir = tmp_path / "app"
|
|
18
|
+
bin_dir = app_dir / "bin"
|
|
19
|
+
dist_dir = app_dir / "dist"
|
|
20
|
+
bin_dir.mkdir(parents=True)
|
|
21
|
+
dist_dir.mkdir(parents=True)
|
|
22
|
+
(bin_dir / "tamcoder").write_text("#!/bin/sh\necho fake tamcoder\n")
|
|
23
|
+
(bin_dir / "tamcoder").chmod(0o755)
|
|
24
|
+
(dist_dir / "appServerMain.js").write_text("console.log('ok')\n")
|
|
25
|
+
|
|
26
|
+
archive = tmp_path / "tamcoder-0.1.89-linux-x64.tar.gz"
|
|
27
|
+
import tarfile
|
|
28
|
+
with tarfile.open(archive, "w:gz") as tar:
|
|
29
|
+
tar.add(app_dir, arcname="app")
|
|
30
|
+
return archive
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def test_verify_sha256_ok():
|
|
34
|
+
with tempfile.NamedTemporaryFile(delete=False) as f:
|
|
35
|
+
f.write(b"hello")
|
|
36
|
+
path = Path(f.name)
|
|
37
|
+
expected = hashlib.sha256(b"hello").hexdigest()
|
|
38
|
+
assert verify_sha256(path, expected)
|
|
39
|
+
assert not verify_sha256(path, "0" * 64)
|
|
40
|
+
path.unlink()
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def test_fetch_latest_success(requests_mock):
|
|
44
|
+
requests_mock.get(
|
|
45
|
+
"https://gpt.tamfitronics.com/tamcoder/latest.json",
|
|
46
|
+
json={"version": "0.1.89", "asset": "tamcoder-0.1.89-linux-x64.tar.gz"},
|
|
47
|
+
)
|
|
48
|
+
data = fetch_latest()
|
|
49
|
+
assert data["version"] == "0.1.89"
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def test_fetch_latest_failure(requests_mock):
|
|
53
|
+
requests_mock.get("https://gpt.tamfitronics.com/tamcoder/latest.json", status_code=500)
|
|
54
|
+
with pytest.raises(Exception):
|
|
55
|
+
fetch_latest()
|
|
File without changes
|
|
File without changes
|